Class: Quant::Asset
- Inherits:
-
Object
- Object
- Quant::Asset
- Defined in:
- lib/quant/asset.rb
Overview
A Asset is a representation of a financial instrument such as a stock, option, future, or currency. It is used to represent the instrument that is being traded, analyzed, or managed.
Not all data sources have a rich set of attributes for their assets or securities. The Asset is designed to be flexible and to support a wide variety of data sources and use-cases. The most common use-cases are supported while allowing for additional attributes to be added via the meta attribute, which is tyipically just a Hash, but can be any object that can hold useful information about the asset such as currency formatting, precision, etc.
Instance Attribute Summary collapse
-
#asset_class ⇒ Object
readonly
Returns the value of attribute asset_class.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#exchange ⇒ Object
readonly
Returns the value of attribute exchange.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#initialize(symbol:, name: nil, id: nil, active: true, tradeable: true, exchange: nil, source: nil, asset_class: nil, created_at: Quant.current_time, updated_at: Quant.current_time, meta: {}) ⇒ Asset
constructor
A new instance of Asset.
- #to_h(full: false) ⇒ Object
- #to_json(*args, full: false) ⇒ Object
- #tradeable? ⇒ Boolean
Constructor Details
#initialize(symbol:, name: nil, id: nil, active: true, tradeable: true, exchange: nil, source: nil, asset_class: nil, created_at: Quant.current_time, updated_at: Quant.current_time, meta: {}) ⇒ Asset
Returns a new instance of Asset.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/quant/asset.rb', line 29 def initialize( symbol:, name: nil, id: nil, active: true, tradeable: true, exchange: nil, source: nil, asset_class: nil, created_at: Quant.current_time, updated_at: Quant.current_time, meta: {} ) raise ArgumentError, "symbol is required" unless symbol @symbol = symbol.to_s.upcase @name = name @id = id @tradeable = tradeable @active = active @exchange = exchange @source = source @asset_class = AssetClass.new(asset_class) @created_at = created_at @updated_at = updated_at @meta = end |
Instance Attribute Details
#asset_class ⇒ Object (readonly)
Returns the value of attribute asset_class.
27 28 29 |
# File 'lib/quant/asset.rb', line 27 def asset_class @asset_class end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
27 28 29 |
# File 'lib/quant/asset.rb', line 27 def created_at @created_at end |
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
27 28 29 |
# File 'lib/quant/asset.rb', line 27 def exchange @exchange end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
27 28 29 |
# File 'lib/quant/asset.rb', line 27 def id @id end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
27 28 29 |
# File 'lib/quant/asset.rb', line 27 def @meta end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/quant/asset.rb', line 27 def name @name end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
27 28 29 |
# File 'lib/quant/asset.rb', line 27 def source @source end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
27 28 29 |
# File 'lib/quant/asset.rb', line 27 def symbol @symbol end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
27 28 29 |
# File 'lib/quant/asset.rb', line 27 def updated_at @updated_at end |
Instance Method Details
#active? ⇒ Boolean
57 58 59 |
# File 'lib/quant/asset.rb', line 57 def active? !!@active end |
#to_h(full: false) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/quant/asset.rb', line 71 def to_h(full: false) return { "s" => symbol } unless full { "s" => symbol, "n" => name, "id" => id, "t" => tradeable?, "a" => active?, "x" => exchange, "sc" => asset_class.to_s, "src" => source.to_s } end |
#to_json(*args, full: false) ⇒ Object
84 85 86 |
# File 'lib/quant/asset.rb', line 84 def to_json(*args, full: false) Oj.dump(to_h(full: full), *args) end |
#tradeable? ⇒ Boolean
61 62 63 |
# File 'lib/quant/asset.rb', line 61 def tradeable? !!@tradeable end |