Class: Iro::Strategy

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

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



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

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

#breakeven(p) ⇒ Object



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

def breakeven p
  p.inner_strike - p.begin_outer_price + p.begin_inner_price
end

#kind_shortObject



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



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

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



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

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



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

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



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

def max_loss_covered_call p
  return 'infinity'
end

#max_loss_long_debit_call_spread(p) ⇒ Object



79
80
81
# File 'app/models/iro/strategy.rb', line 79

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



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

def max_loss_short_debit_put_spread p
  out = -100 * ( p.outer_strike - p.inner_strike )
end

#net_amount_covered_call(p) ⇒ Object



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

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

#net_amount_long_debit_call_spread(p) ⇒ Object



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

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_spreadObject



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

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_sObject



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

def to_s
  slug
end