Class: Iro::Strategy

Inherits:
Object
  • Object
show all
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

Class Method Details

.for_ticker(ticker) ⇒ Object



56
57
58
# File 'app/models/iro/strategy.rb', line 56

def self.for_ticker ticker
  where( ticker: ticker )
end

.list(long_or_short = nil) ⇒ Object



203
204
205
206
# File 'app/models/iro/strategy.rb', line 203

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



101
102
103
# File 'app/models/iro/strategy.rb', line 101

def begin_delta_covered_call p
  p.begin_inner_delta
end

#begin_delta_long_debit_call_spread(p) ⇒ Object Also known as: begin_delta_short_debit_put_spread



104
105
106
# File 'app/models/iro/strategy.rb', line 104

def begin_delta_long_debit_call_spread p
  p.begin_outer_delta - p.begin_inner_delta
end

#breakeven_covered_call(p) ⇒ Object



60
61
62
# File 'app/models/iro/strategy.rb', line 60

def breakeven_covered_call p
  p.inner_strike + p.begin_inner_price
end

#breakeven_long_debit_call_spread(p) ⇒ Object Also known as: breakeven_short_debit_put_spread



63
64
65
# File 'app/models/iro/strategy.rb', line 63

def breakeven_long_debit_call_spread p
  p.inner_strike - p.max_gain # p.begin_outer_price + p.begin_inner_price
end

#calc_rollp_covered_call(p) ⇒ Object

decisions



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'app/models/iro/strategy.rb', line 123

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.end_inner_delta < threshold_delta
    return [ 0.61, "Delta #{p.end_inner_delta} is lower than #{threshold_delta} threshold." ]
  end

  if 1 - p.end_inner_price/p.begin_inner_price > threshold_netp
    return [ 0.51, "made enough #{'%.0f' % [(1 - p.end_inner_price/p.begin_inner_price )*100]}% profit" ]
  end

  return [ 0.33, '-' ]
end

#calc_rollp_long_debit_call_spread(p) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'app/models/iro/strategy.rb', line 147

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.end_inner_delta < threshold_delta
    return [ 0.79, "Delta #{p.end_inner_delta} is lower than #{threshold_delta} threshold." ]
  end

  if 1 - p.end_inner_price/p.begin_inner_price > threshold_netp
    return [ 0.51, "made enough #{'%.0f' % [(1 - p.end_inner_price/p.begin_inner_price )*100]}% profit" ]
  end

  return [ 0.33, '-' ]
end

#calc_rollp_short_debit_put_spread(p) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'app/models/iro/strategy.rb', line 174

def calc_rollp_short_debit_put_spread 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' % [stock.last - p.inner_strike - buffer_above_water]} " +
        "above #{'%.2f' % [p.inner_strike + buffer_above_water]} water" ]
  end

  if p.end_inner_delta < threshold_delta
    return [ 0.79, "Delta #{p.end_inner_delta} is lower than #{threshold_delta} threshold." ]
  end

  if 1 - p.end_inner_price/p.begin_inner_price > threshold_netp
    return [ 0.51, "made enough #{'%.0f' % [(1 - p.end_inner_price/p.begin_inner_price )*100]}% profit" ]
  end

  return [ 0.33, '-' ]
end

#end_delta_covered_call(p) ⇒ Object



109
110
111
# File 'app/models/iro/strategy.rb', line 109

def end_delta_covered_call p
  p.end_inner_delta
end

#end_delta_long_debit_call_spread(p) ⇒ Object Also known as: end_delta_short_debit_put_spread



112
113
114
# File 'app/models/iro/strategy.rb', line 112

def end_delta_long_debit_call_spread p
  p.end_outer_delta - p.end_inner_delta
end

#kind_shortObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/iro/strategy.rb', line 32

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



68
69
70
71
# File 'app/models/iro/strategy.rb', line 68

def max_gain_covered_call p
  # return p.begin_inner_price
  p.begin_inner_price * 100 - 0.66 # @TODO: is this *100 really?
end

#max_gain_long_debit_call_spread(p) ⇒ Object

@TODO: is this *100 really?



72
73
74
75
# File 'app/models/iro/strategy.rb', line 72

def max_gain_long_debit_call_spread p
  ## 100 * disalloed for gameui
  ( p.inner_strike - p.outer_strike - p.begin_outer_price + p.begin_inner_price ) # - 2*0.66
end

#max_gain_short_debit_put_spread(p) ⇒ Object



76
77
78
79
# File 'app/models/iro/strategy.rb', line 76

def max_gain_short_debit_put_spread p
  ## 100 * disalloed for gameui
  ( p.outer_strike - p.inner_strike - p.begin_outer_price + p.begin_inner_price ) # - 2*0.66
end

#max_loss_covered_call(p) ⇒ Object



91
92
93
# File 'app/models/iro/strategy.rb', line 91

def max_loss_covered_call p
  p.begin_inner_price*10 # just suppose 10,000%
end

#max_loss_long_debit_call_spread(p) ⇒ Object



94
95
96
# File 'app/models/iro/strategy.rb', line 94

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



97
98
99
# File 'app/models/iro/strategy.rb', line 97

def max_loss_short_debit_put_spread p # different
  out = p.inner_strike - p.outer_strike
end

#net_amount_covered_call(p) ⇒ Object



81
82
83
# File 'app/models/iro/strategy.rb', line 81

def net_amount_covered_call p
  ( p.begin_inner_price - p.end_inner_price )
end

#net_amount_long_debit_call_spread(p) ⇒ Object Also known as: net_amount_short_debit_put_spread



84
85
86
87
88
# File 'app/models/iro/strategy.rb', line 84

def net_amount_long_debit_call_spread p
  outer = p.end_outer_price - p.begin_outer_price
  inner = p.begin_inner_price - p.end_inner_price
  out = ( outer + inner )
end

#to_sObject



200
201
202
# File 'app/models/iro/strategy.rb', line 200

def to_s
  "#{stock} #{kind_short} #{slug}"
end