Class: Iro::Strategy
- Inherits:
-
Object
- Object
- Iro::Strategy
- Includes:
- Mongoid::Document, 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 =
'long_debit_call_spread'- KINDS =
[ nil, KIND_COVERED_CALL, KIND_LONG_DEBIT_CALL_SPREAD, KIND_SHORT_DEBIT_PUT_SPREAD, ]
Class Method Summary collapse
Instance Method Summary collapse
- #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
- #net_amount_covered_call(p) ⇒ Object
- #net_amount_long_debit_call_spread(p) ⇒ Object
- #net_amount_short_debit_put_spread ⇒ Object
- #to_s ⇒ Object
Class Method Details
.for_ticker(ticker) ⇒ Object
51 52 53 |
# File 'app/models/iro/strategy.rb', line 51 def self.for_ticker ticker where( ticker: ticker ) end |
.list(long_or_short = nil) ⇒ Object
100 101 102 103 |
# File 'app/models/iro/strategy.rb', line 100 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.slug, ttt.id ] } end |
Instance Method Details
#kind_short ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/iro/strategy.rb', line 31 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
55 56 57 58 |
# File 'app/models/iro/strategy.rb', line 55 def max_gain_covered_call p # return p.begin_inner_price p.begin_inner_price * 100 - 0.66 end |
#max_gain_long_debit_call_spread(p) ⇒ Object
59 60 61 62 |
# File 'app/models/iro/strategy.rb', line 59 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
63 64 65 66 |
# File 'app/models/iro/strategy.rb', line 63 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
68 69 70 |
# File 'app/models/iro/strategy.rb', line 68 def max_loss_covered_call p return 'inf' end |
#max_loss_long_debit_call_spread(p) ⇒ Object
71 72 73 |
# File 'app/models/iro/strategy.rb', line 71 def max_loss_long_debit_call_spread p out = 100 * ( p.outer_strike - p.inner_strike ) end |
#max_loss_short_debit_put_spread(p) ⇒ Object
74 75 76 |
# File 'app/models/iro/strategy.rb', line 74 def max_loss_short_debit_put_spread p out = -100 * ( p.outer_strike - p.inner_strike ) end |
#net_amount_covered_call(p) ⇒ Object
78 79 80 |
# File 'app/models/iro/strategy.rb', line 78 def net_amount_covered_call p ( p.begin_inner_price - p.end_inner_price ) * 100 end |
#net_amount_long_debit_call_spread(p) ⇒ Object
81 82 83 84 85 |
# File 'app/models/iro/strategy.rb', line 81 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 ) * 100 end |
#net_amount_short_debit_put_spread ⇒ Object
86 87 88 89 90 |
# File 'app/models/iro/strategy.rb', line 86 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 ) * 100 end |
#to_s ⇒ Object
97 98 99 |
# File 'app/models/iro/strategy.rb', line 97 def to_s slug end |