Class: Quant::AssetClass

Inherits:
Object
  • Object
show all
Defined in:
lib/quant/asset_class.rb

Overview

Foreign Exchange (Forex): The market where currencies are traded. Investors can buy and sell currencies to profit from changes in exchange rates.

Constant Summary collapse

CLASSES =
%i(
  bond
  commodity
  cryptocurrency
  etf
  forex
  future
  mbs
  mutual_fund
  option
  preferred_stock
  reit
  stock
  treasury_note
).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ AssetClass

Returns a new instance of AssetClass.



62
63
64
65
66
67
# File 'lib/quant/asset_class.rb', line 62

def initialize(name)
  return if @asset_class = from_standard(name)

  @asset_class = from_alternate(name.to_s.downcase.to_sym) unless name.nil?
  raise_unknown_asset_class_error(name) unless asset_class
end

Instance Attribute Details

#asset_classObject (readonly)

Returns the value of attribute asset_class.



60
61
62
# File 'lib/quant/asset_class.rb', line 60

def asset_class
  @asset_class
end

Instance Method Details

#==(other) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/quant/asset_class.rb', line 91

def ==(other)
  case other
  when String then from_alternate(other.to_sym) == asset_class
  when Symbol then from_alternate(other) == asset_class
  when AssetClass then other.asset_class == asset_class
  else
    false
  end
end

#raise_unknown_asset_class_error(name) ⇒ Object



75
76
77
# File 'lib/quant/asset_class.rb', line 75

def raise_unknown_asset_class_error(name)
  raise Errors::AssetClassError, "Unknown asset class: #{name.inspect}"
end

#to_hObject



83
84
85
# File 'lib/quant/asset_class.rb', line 83

def to_h
  { "sc" => asset_class }
end

#to_json(*args) ⇒ Object



87
88
89
# File 'lib/quant/asset_class.rb', line 87

def to_json(*args)
  Oj.dump(to_h, *args)
end

#to_sObject



79
80
81
# File 'lib/quant/asset_class.rb', line 79

def to_s
  asset_class.to_s
end