Class: Quant::SecurityClass

Inherits:
Object
  • Object
show all
Defined in:
lib/quant/security_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) ⇒ SecurityClass

Returns a new instance of SecurityClass.



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

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

  @security_class = from_alternate(name.to_s.downcase.to_sym) unless name.nil?
  raise_unknown_security_class_error(name) unless security_class
end

Instance Attribute Details

#security_classObject (readonly)

Returns the value of attribute security_class.



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

def security_class
  @security_class
end

Instance Method Details

#==(other) ⇒ Object



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

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

#raise_unknown_security_class_error(name) ⇒ Object

Raises:



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

def raise_unknown_security_class_error(name)
  raise SecurityClassError, "Unknown security class: #{name.inspect}"
end

#to_hObject



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

def to_h
  { "sc" => security_class }
end

#to_json(*args) ⇒ Object



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

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

#to_sObject



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

def to_s
  security_class.to_s
end