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_LONG_DEBIT_CALL_SPREAD =
'long_debit_call_spread'- KIND_SHORT_DEBIT_PUT_SPREAD =
'short_debit_put_spread'- KINDS =
[ nil, KIND_COVERED_CALL, KIND_LONG_DEBIT_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)
- #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)
- #kind_short ⇒ Object
- #max_gain_covered_call(p) ⇒ Object
- #max_gain_long_debit_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_debit_put_spread(p) ⇒ Object
different.
- #net_amount_covered_call(p) ⇒ Object
- #net_amount_long_debit_call_spread(p) ⇒ Object (also: #net_amount_short_debit_put_spread)
- #to_s ⇒ Object
Class Method Details
.for_ticker(ticker) ⇒ Object
58 59 60 |
# File 'app/models/iro/strategy.rb', line 58 def self.for_ticker ticker where( ticker: ticker ) end |
.list(long_or_short = nil) ⇒ Object
204 205 206 207 |
# File 'app/models/iro/strategy.rb', line 204 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
102 103 104 |
# File 'app/models/iro/strategy.rb', line 102 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
105 106 107 |
# File 'app/models/iro/strategy.rb', line 105 def begin_delta_long_debit_call_spread p p.outer.begin_delta - p.inner.begin_delta end |
#breakeven_covered_call(p) ⇒ Object
62 63 64 |
# File 'app/models/iro/strategy.rb', line 62 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
65 66 67 |
# File 'app/models/iro/strategy.rb', line 65 def breakeven_long_debit_call_spread p p.inner.strike - p.max_gain end |
#calc_rollp_covered_call(p) ⇒ Object
decisions
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'app/models/iro/strategy.rb', line 124 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
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/iro/strategy.rb', line 148 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
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'app/models/iro/strategy.rb', line 175 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
110 111 112 |
# File 'app/models/iro/strategy.rb', line 110 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
113 114 115 |
# File 'app/models/iro/strategy.rb', line 113 def end_delta_long_debit_call_spread p p.outer.end_delta - p.inner.end_delta end |
#kind_short ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/iro/strategy.rb', line 33 def kind_short case kind when KIND_COVERED_CALL 'cc' when KIND_LONG_DEBIT_CALL_SPREAD 'long-spread' when KIND_SHORT_DEBIT_PUT_SPREAD 'short-spread' else '@TODO-zez' end end |
#max_gain_covered_call(p) ⇒ Object
70 71 72 |
# File 'app/models/iro/strategy.rb', line 70 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
73 74 75 76 |
# File 'app/models/iro/strategy.rb', line 73 def max_gain_long_debit_call_spread p ## 100 * disalloed for gameui ( p.inner.strike - p.outer.strike - p.outer.begin_price + p.inner.begin_price ) # - 2*0.66 end |
#max_gain_short_debit_put_spread(p) ⇒ Object
77 78 79 80 |
# File 'app/models/iro/strategy.rb', line 77 def max_gain_short_debit_put_spread p ## 100 * disalloed 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
92 93 94 |
# File 'app/models/iro/strategy.rb', line 92 def max_loss_covered_call p p.inner.begin_price*10 # just suppose 10,000% end |
#max_loss_long_debit_call_spread(p) ⇒ Object
95 96 97 |
# File 'app/models/iro/strategy.rb', line 95 def max_loss_long_debit_call_spread p out = p.outer.strike - p.inner.strike end |
#max_loss_short_debit_put_spread(p) ⇒ Object
different
98 99 100 |
# File 'app/models/iro/strategy.rb', line 98 def max_loss_short_debit_put_spread p # different out = p.inner.strike - p.outer.strike end |
#net_amount_covered_call(p) ⇒ Object
82 83 84 |
# File 'app/models/iro/strategy.rb', line 82 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_debit_put_spread
85 86 87 88 89 |
# File 'app/models/iro/strategy.rb', line 85 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 |
#to_s ⇒ Object
201 202 203 |
# File 'app/models/iro/strategy.rb', line 201 def to_s "#{stock} #{kind_short} #{slug}" end |