Class: Iro::Option
- Inherits:
-
Object
- Object
- Iro::Option
- Includes:
- OptionBlackScholes, Mongoid::Document, Mongoid::Paranoia, Mongoid::Timestamps
- Defined in:
- app/models/iro/option.rb
Instance Attribute Summary collapse
-
#recompute ⇒ Object
Returns the value of attribute recompute.
Class Method Summary collapse
Instance Method Summary collapse
-
#put_call ⇒ Object
each option can be a leg in a position, no uniqueness validates :symbol, uniqueness: true, presence: true.
-
#symbol ⇒ Object
for TDA.
-
#sync ⇒ Object
do not sync in test.
- #ticker ⇒ Object
Methods included from OptionBlackScholes
#call_price, #d1, #d2, #put_price, rate_annual, rate_daily, #stdev, #t
Instance Attribute Details
#recompute ⇒ Object
Returns the value of attribute recompute.
9 10 11 |
# File 'app/models/iro/option.rb', line 9 def recompute @recompute end |
Class Method Details
.expirations_list(full: false, n: 5) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/iro/option.rb', line 30 def self.expirations_list full: false, n: 5 out = [[nil,nil]] day = Date.today - 5.days n.times do next_exp = day.next_occurring(:thursday).next_occurring(:friday) if !next_exp.workday? next_exp = Time.previous_business_day( next_exp ) end out.push([ next_exp.strftime('%b %e'), next_exp.strftime('%Y-%m-%d') ]) day = next_exp end return out # [ # [ nil, nil ], # [ 'Mar 22', '2024-03-22'.to_date ], # [ 'Mar 28', '2024-03-28'.to_date ], # [ 'Apr 5', '2024-04-05'.to_date ], # [ 'Mar 12', '2024-03-12'.to_date ], # [ 'Mar 19', '2024-03-19'.to_date ], # ] end |
Instance Method Details
#put_call ⇒ Object
each option can be a leg in a position, no uniqueness validates :symbol, uniqueness: true, presence: true
20 |
# File 'app/models/iro/option.rb', line 20 field :put_call, type: :string |
#symbol ⇒ Object
for TDA
65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/iro/option.rb', line 65 def symbol if !self[:symbol] p_c_ = put_call == 'PUT' ? 'P' : 'C' strike_ = strike.to_i == strike ? strike.to_i : strike sym = "#{stock.ticker}_#{expires_on.strftime("%m%d%y")}#{p_c_}#{strike_}" # XYZ_011819P45 self[:symbol] = sym save end self[:symbol] end |
#sync ⇒ Object
do not sync in test
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/models/iro/option.rb', line 89 def sync out = Tda::Option.get_quote({ contractType: put_call, strike: strike, expirationDate: expires_on, ticker: ticker, }) puts! out, 'option sync' self.end_price = ( out.bid + out.ask ) / 2 rescue 0 self.end_delta = out.delta if out.delta # self.save end |
#ticker ⇒ Object
12 |
# File 'app/models/iro/option.rb', line 12 def ticker; stock.ticker; end |