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.
27 28 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 |
# File 'lib/quant/asset.rb', line 27 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.
25 26 27 |
# File 'lib/quant/asset.rb', line 25 def asset_class @asset_class end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
25 26 27 |
# File 'lib/quant/asset.rb', line 25 def created_at @created_at end |
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
25 26 27 |
# File 'lib/quant/asset.rb', line 25 def exchange @exchange end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
25 26 27 |
# File 'lib/quant/asset.rb', line 25 def id @id end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
25 26 27 |
# File 'lib/quant/asset.rb', line 25 def @meta end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/quant/asset.rb', line 25 def name @name end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
25 26 27 |
# File 'lib/quant/asset.rb', line 25 def source @source end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
25 26 27 |
# File 'lib/quant/asset.rb', line 25 def symbol @symbol end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
25 26 27 |
# File 'lib/quant/asset.rb', line 25 def updated_at @updated_at end |
Instance Method Details
#active? ⇒ Boolean
55 56 57 |
# File 'lib/quant/asset.rb', line 55 def active? !!@active end |
#to_h(full: false) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/quant/asset.rb', line 69 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
82 83 84 |
# File 'lib/quant/asset.rb', line 82 def to_json(*args, full: false) Oj.dump(to_h(full:), *args) end |
#tradeable? ⇒ Boolean
59 60 61 |
# File 'lib/quant/asset.rb', line 59 def tradeable? !!@tradeable end |