Class: Iro::Strategy
- Inherits:
-
Object
- Object
- Iro::Strategy
- Includes:
- Mongoid::Document, Mongoid::Paranoia, Mongoid::Timestamps
- Defined in:
- app/models/iro/strategy.rb
Constant Summary collapse
- LONG =
'is_long'- SHORT =
'is_short'- KIND_COVERED_CALL =
'covered_call'- KIND_IRON_CONDOR =
'iron_condor'- KIND_LONG_CREDIT_PUT_SPREAD =
'long_credit_put_spread'- KIND_LONG_DEBIT_CALL_SPREAD =
'long_debit_call_spread'- KIND_SHORT_CREDIT_CALL_SPREAD =
'short_credit_call_spread'- KIND_SHORT_DEBIT_PUT_SPREAD =
'short_debit_put_spread'- KINDS =
[ nil, KIND_COVERED_CALL, KIND_IRON_CONDOR, KIND_LONG_CREDIT_PUT_SPREAD, KIND_LONG_DEBIT_CALL_SPREAD, KIND_SHORT_CREDIT_CALL_SPREAD, KIND_SHORT_DEBIT_PUT_SPREAD, ]
Class Method Summary collapse
Instance Method Summary collapse
- #begin_delta_covered_call(p) ⇒ Object
- #begin_delta_long_debit_call_spread(p) ⇒ Object (also: #begin_delta_short_debit_put_spread, #begin_delta_short_credit_call_spread)
- #breakeven_covered_call(p) ⇒ Object
- #breakeven_long_debit_call_spread(p) ⇒ Object (also: #breakeven_short_debit_put_spread)
-
#calc_rollp_covered_call(p) ⇒ Object
decisions.
- #calc_rollp_long_debit_call_spread(p) ⇒ Object
- #calc_rollp_short_debit_put_spread(p) ⇒ Object
- #end_delta_covered_call(p) ⇒ Object
- #end_delta_long_debit_call_spread(p) ⇒ Object (also: #end_delta_short_debit_put_spread, #end_delta_short_credit_call_spread)
- #max_gain_covered_call(p) ⇒ Object
- #max_gain_long_debit_call_spread(p) ⇒ Object
- #max_gain_short_credit_call_spread(p) ⇒ Object
- #max_gain_short_debit_put_spread(p) ⇒ Object
- #max_loss_covered_call(p) ⇒ Object
- #max_loss_long_debit_call_spread(p) ⇒ Object
- #max_loss_short_credit_call_spread(p) ⇒ Object
-
#max_loss_short_debit_put_spread(p) ⇒ Object
different.
- #net_amount_covered_call(p) ⇒ Object
- #net_amount_long_debit_call_spread(p) ⇒ Object (also: #net_amount_short_credit_call_spread, #net_amount_short_debit_put_spread)
-
#next_inner_strike_on(expires_on) ⇒ Object
2024-05-09 @TODO.
- #put_call ⇒ Object
- #to_s ⇒ Object
Class Method Details
.for_ticker(ticker) ⇒ Object
scopes
233 234 235 |
# File 'app/models/iro/strategy.rb', line 233 def self.for_ticker ticker where( ticker: ticker ) end |
.list(long_or_short = nil) ⇒ Object
241 242 243 244 |
# File 'app/models/iro/strategy.rb', line 241 def self.list long_or_short = nil these = long_or_short ? where( long_or_short: long_or_short ) : all [[nil,nil]] + these.map { |ttt| [ ttt, ttt.id ] } end |
Instance Method Details
#begin_delta_covered_call(p) ⇒ Object
70 71 72 |
# File 'app/models/iro/strategy.rb', line 70 def begin_delta_covered_call p p.inner.begin_delta end |
#begin_delta_long_debit_call_spread(p) ⇒ Object Also known as: begin_delta_short_debit_put_spread, begin_delta_short_credit_call_spread
73 74 75 |
# File 'app/models/iro/strategy.rb', line 73 def begin_delta_long_debit_call_spread p p.outer.begin_delta - p.inner.begin_delta end |
#breakeven_covered_call(p) ⇒ Object
80 81 82 |
# File 'app/models/iro/strategy.rb', line 80 def breakeven_covered_call p p.inner.strike + p.inner.begin_price end |
#breakeven_long_debit_call_spread(p) ⇒ Object Also known as: breakeven_short_debit_put_spread
83 84 85 |
# File 'app/models/iro/strategy.rb', line 83 def breakeven_long_debit_call_spread p p.inner.strike - p.max_gain end |
#calc_rollp_covered_call(p) ⇒ Object
decisions
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'app/models/iro/strategy.rb', line 156 def calc_rollp_covered_call p if ( p.expires_on.to_date - Time.now.to_date ).to_i < 1 return [ 0.99, '0 DTE, must exit' ] end if ( stock.last - buffer_above_water ) < p.inner.strike return [ 0.98, "Last #{'%.2f' % stock.last} is " + "#{'%.2f' % [p.inner.strike + buffer_above_water - stock.last]} " + "below #{'%.2f' % [p.inner.strike + buffer_above_water]} water" ] end if p.inner.end_delta < threshold_delta return [ 0.61, "Delta #{p.inner.end_delta} is lower than #{threshold_delta} threshold." ] end if 1 - p.inner.end_price/p.inner.begin_price > threshold_netp return [ 0.51, "made enough #{'%.02f' % [(1.0 - p.inner.end_price/p.inner.begin_price )*100]}% profit." ] end return [ 0.33, '-' ] end |
#calc_rollp_long_debit_call_spread(p) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'app/models/iro/strategy.rb', line 180 def calc_rollp_long_debit_call_spread p if ( p.expires_on.to_date - Time.now.to_date ).to_i < 1 return [ 0.99, '0 DTE, must exit' ] end if ( p.expires_on.to_date - Time.now.to_date ).to_i < 2 return [ 0.99, '1 DTE, must exit' ] end if ( stock.last - buffer_above_water ) < p.inner.strike return [ 0.95, "Last #{'%.2f' % stock.last} is " + "#{'%.2f' % [stock.last - p.inner.strike - buffer_above_water]} " + "below #{'%.2f' % [p.inner.strike + buffer_above_water]} water" ] end if p.inner.end_delta < threshold_delta return [ 0.79, "Delta #{p.inner.end_delta} is lower than #{threshold_delta} threshold." ] end if 1 - p.inner.end_price/p.inner.begin_price > threshold_netp return [ 0.51, "made enough #{'%.02f' % [(1.0 - p.inner.end_price/p.inner.begin_price )*100]}% profit^" ] end return [ 0.33, '-' ] end |
#calc_rollp_short_debit_put_spread(p) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'app/models/iro/strategy.rb', line 207 def calc_rollp_short_debit_put_spread p if ( p.expires_on.to_date - Time.now.to_date ).to_i <= min_dte return [ 0.99, "< #{min_dte}DTE, must exit" ] end if stock.last + buffer_above_water > p.inner.strike return [ 0.98, "Last #{'%.2f' % stock.last} is " + "#{'%.2f' % [stock.last + buffer_above_water - p.inner.strike]} " + "above #{'%.2f' % [p.inner.strike - buffer_above_water]} water" ] end if p.inner.end_delta.abs < threshold_delta.abs return [ 0.79, "Delta #{p.inner.end_delta} is lower than #{threshold_delta} threshold." ] end if p.net_percent > threshold_netp return [ 0.51, "made enough #{'%.0f' % [p.net_percent*100]}% > #{"%.2f" % [threshold_netp*100]}% profit," ] end return [ 0.33, '-' ] end |
#end_delta_covered_call(p) ⇒ Object
89 90 91 |
# File 'app/models/iro/strategy.rb', line 89 def end_delta_covered_call p p.inner.end_delta end |
#end_delta_long_debit_call_spread(p) ⇒ Object Also known as: end_delta_short_debit_put_spread, end_delta_short_credit_call_spread
92 93 94 |
# File 'app/models/iro/strategy.rb', line 92 def end_delta_long_debit_call_spread p p.outer.end_delta - p.inner.end_delta end |
#max_gain_covered_call(p) ⇒ Object
99 100 101 |
# File 'app/models/iro/strategy.rb', line 99 def max_gain_covered_call p p.inner.begin_price * 100 - 0.66 # @TODO: is this *100 really? end |
#max_gain_long_debit_call_spread(p) ⇒ Object
102 103 104 105 |
# File 'app/models/iro/strategy.rb', line 102 def max_gain_long_debit_call_spread p ## 100 * disallowed for gameui ( p.inner.strike - p.outer.strike - p.outer.begin_price + p.inner.begin_price ) # - 2*0.66 end |
#max_gain_short_credit_call_spread(p) ⇒ Object
106 107 108 |
# File 'app/models/iro/strategy.rb', line 106 def max_gain_short_credit_call_spread p p.inner.begin_price - p.outer.begin_price end |
#max_gain_short_debit_put_spread(p) ⇒ Object
109 110 111 112 |
# File 'app/models/iro/strategy.rb', line 109 def max_gain_short_debit_put_spread p ## 100 * disallowed for gameui ( p.outer.strike - p.inner.strike - p.outer.begin_price + p.inner.begin_price ) # - 2*0.66 end |
#max_loss_covered_call(p) ⇒ Object
115 116 117 |
# File 'app/models/iro/strategy.rb', line 115 def max_loss_covered_call p p.inner.begin_price*10 # just suppose 10,000% end |
#max_loss_long_debit_call_spread(p) ⇒ Object
118 119 120 |
# File 'app/models/iro/strategy.rb', line 118 def max_loss_long_debit_call_spread p out = p.outer.strike - p.inner.strike end |
#max_loss_short_credit_call_spread(p) ⇒ Object
124 125 126 |
# File 'app/models/iro/strategy.rb', line 124 def max_loss_short_credit_call_spread p out = p.outer.strike - p.inner.strike end |
#max_loss_short_debit_put_spread(p) ⇒ Object
different
121 122 123 |
# File 'app/models/iro/strategy.rb', line 121 def max_loss_short_debit_put_spread p # different out = p.inner.strike - p.outer.strike end |
#net_amount_covered_call(p) ⇒ Object
129 130 131 |
# File 'app/models/iro/strategy.rb', line 129 def net_amount_covered_call p ( p.inner.begin_price - p.inner.end_price ) end |
#net_amount_long_debit_call_spread(p) ⇒ Object Also known as: net_amount_short_credit_call_spread, net_amount_short_debit_put_spread
132 133 134 135 136 |
# File 'app/models/iro/strategy.rb', line 132 def net_amount_long_debit_call_spread p outer = p.outer.end_price - p.outer.begin_price inner = p.inner.begin_price - p.inner.end_price out = ( outer + inner ) end |
#next_inner_strike_on(expires_on) ⇒ Object
2024-05-09 @TODO
142 143 144 145 146 147 148 |
# File 'app/models/iro/strategy.rb', line 142 def next_inner_strike_on expires_on outs = Tda::Option.get_quotes({ contractType: put_call, expirationDate: expires_on, ticker: stock.ticker, }) end |
#put_call ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/iro/strategy.rb', line 40 def put_call case kind when Iro::Strategy::KIND_LONG_DEBIT_CALL_SPREAD put_call = 'CALL' when Iro::Strategy::KIND_SHORT_CREDIT_CALL_SPREAD put_call = 'CALL' when Iro::Strategy::KIND_SHORT_DEBIT_PUT_SPREAD put_call = 'PUT' when Iro::Strategy::KIND_COVERED_CALL put_call = 'CALL' end end |
#to_s ⇒ Object
238 239 240 |
# File 'app/models/iro/strategy.rb', line 238 def to_s slug end |