Class: Option
Instance Attribute Summary collapse
-
#current_date ⇒ Object
Returns the value of attribute current_date.
-
#expires ⇒ Object
Returns the value of attribute expires.
-
#price ⇒ Object
Returns the value of attribute price.
-
#stock ⇒ Object
Returns the value of attribute stock.
-
#strike ⇒ Object
Returns the value of attribute strike.
-
#symbol ⇒ Object
Returns the value of attribute symbol.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#at_the_money? ⇒ Boolean
A specific sub state of being out the money.
- #call? ⇒ Boolean
- #days_to_expiry(opening_date = current_date) ⇒ Object
- #expired? ⇒ Boolean
- #in_the_money? ⇒ Boolean
-
#initialize(args = {}) ⇒ Option
constructor
A new instance of Option.
- #out_the_money? ⇒ Boolean
- #put? ⇒ Boolean
- #to_s ⇒ Object
- #to_ticker_s ⇒ Object
Methods included from ArgumentProcessor
Constructor Details
Instance Attribute Details
#current_date ⇒ Object
Returns the value of attribute current_date.
4 5 6 |
# File 'lib/option.rb', line 4 def current_date @current_date end |
#expires ⇒ Object
Returns the value of attribute expires.
4 5 6 |
# File 'lib/option.rb', line 4 def expires @expires end |
#price ⇒ Object
Returns the value of attribute price.
4 5 6 |
# File 'lib/option.rb', line 4 def price @price end |
#stock ⇒ Object
Returns the value of attribute stock.
4 5 6 |
# File 'lib/option.rb', line 4 def stock @stock end |
#strike ⇒ Object
Returns the value of attribute strike.
4 5 6 |
# File 'lib/option.rb', line 4 def strike @strike end |
#symbol ⇒ Object
Returns the value of attribute symbol.
4 5 6 |
# File 'lib/option.rb', line 4 def symbol @symbol end |
Instance Method Details
#==(other) ⇒ Object
64 65 66 67 68 |
# File 'lib/option.rb', line 64 def ==(other) other.stock == stock && other.strike == strike && other.expires == expires end |
#at_the_money? ⇒ Boolean
A specific sub state of being out the money.
44 45 46 |
# File 'lib/option.rb', line 44 def at_the_money? stock.price == strike end |
#call? ⇒ Boolean
27 28 29 |
# File 'lib/option.rb', line 27 def call? false end |
#days_to_expiry(opening_date = current_date) ⇒ Object
14 15 16 |
# File 'lib/option.rb', line 14 def days_to_expiry(opening_date = current_date) [0, (expires - opening_date).to_i].max end |
#expired? ⇒ Boolean
18 19 20 |
# File 'lib/option.rb', line 18 def expired? expires < current_date end |
#in_the_money? ⇒ Boolean
35 36 37 |
# File 'lib/option.rb', line 35 def in_the_money? raise NotImplementedError end |
#out_the_money? ⇒ Boolean
39 40 41 |
# File 'lib/option.rb', line 39 def out_the_money? !in_the_money? end |
#put? ⇒ Boolean
31 32 33 |
# File 'lib/option.rb', line 31 def put? false end |
#to_s ⇒ Object
48 49 50 51 |
# File 'lib/option.rb', line 48 def to_s [stock.symbol, float_if_needed(strike), expires.strftime("%b %y").upcase, self.class.name.upcase].join(" ") end |
#to_ticker_s ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/option.rb', line 53 def to_ticker_s return symbol if symbol call_or_put = call? ? "C" : "P" dollar = (strike.to_i / 100).to_s.rjust(5, "0") decimal = (strike.to_i % 100).to_s.ljust(3, "0") [stock.symbol, expires.strftime("%y%m%d"), call_or_put, dollar, decimal].join.upcase end |