iron_warbler 2.0.7.26 → 2.0.7.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/iron_warbler/purses.scss +31 -0
  3. data/app/assets/stylesheets/iron_warbler/utils.scss +28 -3
  4. data/app/controllers/iro/api/stocks_controller.rb +7 -4
  5. data/app/controllers/iro/positions_controller.rb +27 -21
  6. data/app/controllers/iro/stocks_controller.rb +20 -0
  7. data/app/models/iro/datapoint.rb +1 -1
  8. data/app/models/iro/option.rb +23 -11
  9. data/app/models/iro/position.rb +51 -53
  10. data/app/models/iro/{price_item.rb → priceitem.rb} +5 -1
  11. data/app/models/iro/purse.rb +9 -2
  12. data/app/models/iro/stock.rb +2 -0
  13. data/app/models/iro/strategy.rb +87 -50
  14. data/app/models/tda/option.rb +10 -4
  15. data/app/models/tda/stock.rb +13 -7
  16. data/app/views/iro/_main_header.haml +4 -3
  17. data/app/views/iro/api/stocks/index.json.jbuilder +5 -0
  18. data/app/views/iro/api/stocks/show.json.jbuilder +11 -0
  19. data/app/views/iro/api/stocks/show.json.jbuilder-bk +12 -0
  20. data/app/views/iro/positions/_form.haml +4 -2
  21. data/app/views/iro/positions/_gameui_short_credit_call_spread.haml +38 -0
  22. data/app/views/iro/positions/_header_short_credit_call_spread.haml +50 -0
  23. data/app/views/iro/positions/_new.haml +23 -0
  24. data/app/views/iro/positions/_prepare_short_credit_call_spread.haml +1 -0
  25. data/app/views/iro/purses/_form_extra_fields.haml +18 -22
  26. data/app/views/iro/purses/_header.haml +8 -17
  27. data/app/views/iro/purses/show.haml +3 -2
  28. data/app/views/iro/stocks/_form.haml +4 -3
  29. data/app/views/iro/stocks/edit.haml +4 -0
  30. data/app/views/iro/stocks/index.haml +21 -6
  31. data/app/views/iro/stocks/show.haml +5 -0
  32. data/app/views/iro/strategies/_form.haml +14 -11
  33. data/app/views/iro/strategies/_show.haml +1 -1
  34. data/config/routes.rb +2 -1
  35. data/lib/iro/engine.rb +1 -0
  36. data/lib/iron_warbler.rb +0 -2
  37. data/lib/tasks/iro_tasks.rake +2 -2
  38. metadata +13 -4
  39. data/app/views/iro/api/stocks/show.jbuilder +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4afc65383198cc16143683cc82db6ee65604f14a8d13d4d7bc262210ceb14940
4
- data.tar.gz: 04c7d9a3585dd1036c8f227a1cbbe38fbc6e7d71f68977f3183ac07bdbaba3cf
3
+ metadata.gz: b7ca7e6c0657dbafd3a3e9149fbf05f7a0e0aa275b39d183e145d8802cadc175
4
+ data.tar.gz: c67d4ee07b9646761ed2de0d1291e68d36d7a794ed6b4db58a2d7f2428d72944
5
5
  SHA512:
6
- metadata.gz: a905e844e0542aa1f7500c1c1bc25a234f2698bc8bfb1e75d83fb7ab2ba24dcc28ed261a876f1add4d9dec80decb32cb84ed1694ac3b8e3657be48f8a36b86bc
7
- data.tar.gz: d9478f1d454dbcbee3b6fc703233f7d72049ac128f1ad2e550e38286483ccc51a863e8ace598511c2c28a6ce8a26240215d97ff2d524e5a3e03dcbdc5fb1eb40
6
+ metadata.gz: ad587c8488a2a3a1f7a269c32129ba879c3fde5fb54e2a32a7e2a2f45132995e7d2566a492e002c9ee72d83cfb40fdbc1c81dc5f7a536cd5b368cdb95bb2a038
7
+ data.tar.gz: 4c08a09952620d5339e9f76e5b29ebf5d1134fe0fd20b774f3b7123cd6fe28683b7f517388ac08f1af6142df4edda686d36ab304ff8816c954ce368bdf5a22db
@@ -0,0 +1,31 @@
1
+
2
+ .purses--form-extra-fields {
3
+ background: rgba(255,255,255, 0.5);
4
+ padding: 0.3em 0;
5
+ margin-bottom: 0.5em;
6
+
7
+ line-height: 1.5em;
8
+ input {
9
+ height: 1.5em;
10
+ }
11
+
12
+ > div {
13
+ margin-bottom: 0.3em;
14
+ }
15
+
16
+ .unit {
17
+ min-width: 5em;
18
+ padding-left: 0.3em;
19
+ }
20
+
21
+ label {
22
+ min-width: 9em;
23
+ text-align: right;
24
+ padding-right: 0.3em;
25
+ }
26
+
27
+ input {
28
+ width: 4em;
29
+ }
30
+
31
+ }
@@ -32,6 +32,11 @@
32
32
 
33
33
  /* F */
34
34
 
35
+ .field {
36
+ min-width: 100px;
37
+ margin-right: 1em;
38
+ }
39
+
35
40
  .flex-row {
36
41
  display: flex;
37
42
  margin-bottom: 0.4em;
@@ -43,11 +48,23 @@
43
48
  position: relative;
44
49
  background: white;
45
50
  }
46
- .field {
47
- min-width: 100px;
48
- margin-right: 1em;
51
+
52
+ /**
53
+ * 2024-05-09
54
+ * label tightly above input
55
+ **/
56
+ .formrow-v1 {
57
+ display: flex;
58
+ align-items: flex-end;
59
+ label {
60
+ margin-bottom: 0;
61
+ }
62
+ > * {
63
+ margin-right: 0.3em;
64
+ }
49
65
  }
50
66
 
67
+
51
68
  /* H */
52
69
 
53
70
  /* M */
@@ -78,6 +95,14 @@
78
95
 
79
96
  }
80
97
 
98
+ /* P */
99
+
100
+ table.padded {
101
+ td {
102
+ padding: 0.5em;
103
+ }
104
+ }
105
+
81
106
 
82
107
 
83
108
  /* W */
@@ -3,12 +3,12 @@ class Iro::Api::StocksController < Iro::ApiController
3
3
  before_action :set_stock, only: [:show, :edit, :update, :destroy]
4
4
 
5
5
  def index
6
+ @stocks = Iro::Stock.active
6
7
  authorize! :index, Iro::Stock
7
8
 
8
9
  respond_to do |format|
9
- format.json do
10
- render
11
- end
10
+ format.html
11
+ format.json
12
12
  end
13
13
  end
14
14
 
@@ -16,6 +16,7 @@ class Iro::Api::StocksController < Iro::ApiController
16
16
  authorize! :show, @stock
17
17
  end_on = Time.now.to_date.in_time_zone('UTC')
18
18
 
19
+ begin_on = ( Time.now - 1.year ).to_date.in_time_zone('UTC')
19
20
  begin_on = params[:begin_on].to_date.in_time_zone('UTC') if params[:begin_on]
20
21
  end_on = params[:end_on].to_date.in_time_zone('UTC') if params[:end_on]
21
22
 
@@ -29,12 +30,14 @@ class Iro::Api::StocksController < Iro::ApiController
29
30
  when '1-yr'
30
31
  begin_on = ( Time.now - 1.year ).to_date.in_time_zone('UTC')
31
32
  # end_on = Time.now.to_date.in_time_zone('UTC')
33
+ when '5-yr'
34
+ begin_on = ( Time.now - 5.years ).to_date.in_time_zone('UTC')
32
35
  end
33
36
 
34
37
  @datapoints = Iro::Datapoint.where({
35
38
  :quote_at.gte => begin_on,
36
39
  :quote_at.lte => end_on,
37
- symbol: params[:ticker],
40
+ symbol: params[:ticker],
38
41
  }).order_by({ quote_at: :asc })
39
42
  end
40
43
 
@@ -4,14 +4,15 @@ class Iro::PositionsController < Iro::ApplicationController
4
4
 
5
5
  def create
6
6
  pos = @position = Iro::Position.new pos_params
7
+ authorize! :create, @position
8
+
7
9
  o_attrs = {
8
10
  expires_on: pos.expires_on,
9
- put_call: pos.put_call,
11
+ put_call: pos.put_call, # I need this. _vp_ 2024-04-26
10
12
  stock_id: pos.stock_id,
11
13
  }
12
14
  pos.inner = Iro::Option.new params[:inner].permit!.merge( o_attrs )
13
15
  pos.outer = Iro::Option.new params[:outer].permit!.merge( o_attrs )
14
- authorize! :create, @position
15
16
 
16
17
  if @position.save
17
18
  flash_notice @position
@@ -36,22 +37,25 @@ class Iro::PositionsController < Iro::ApplicationController
36
37
  end
37
38
 
38
39
  def new
39
- strategy = Iro::Strategy.find params[:position][:strategy_id]
40
- @position = Iro::Position.new( params[:position].permit!.merge({
41
- status: :active,
42
- inner: Iro::Option.new,
43
- outer: Iro::Option.new,
44
- stock_id: strategy.stock_id,
40
+ strategy = Iro::Strategy.find params[:position][:strategy_id]
41
+ @position = strategy.next_position
42
+ @position ||= Iro::Position.new( params[:position].permit!.merge({
43
+ status: Iro::Position::STATUS_PROPOSED,
44
+ # inner: Iro::Option.new,
45
+ # outer: Iro::Option.new,
46
+ stock_id: strategy.stock_id,
45
47
  }) )
46
48
  authorize! :new, @posision
47
49
 
48
- if params[:id]
49
- old = Iro::Position.find params[:id]
50
- old = old.attributes
51
- old.delete :_id
52
- puts! old, 'old'
53
- @position = Iro::Position.new old
54
- end
50
+ @position.calc_nxt
51
+
52
+ # if params[:id]
53
+ # old = Iro::Position.find params[:id]
54
+ # old = old.attributes
55
+ # old.delete :_id
56
+ # puts! old, 'old'
57
+ # @position = Iro::Position.new old
58
+ # end
55
59
  end
56
60
 
57
61
  def prepare
@@ -67,7 +71,7 @@ class Iro::PositionsController < Iro::ApplicationController
67
71
  while true
68
72
  @nn = ( @position.purse.n_next_positions/2 ).ceil
69
73
  upper = Tda::Option.get_quote({
70
- contractType: @position.put_call,
74
+ contractType: @position.inner.put_call,
71
75
  strike: @prev.inner.strike + @nn*@stock.options_price_increment,
72
76
  expirationDate: @prev.next_expires_on,
73
77
  ticker: @stock.ticker,
@@ -81,7 +85,7 @@ class Iro::PositionsController < Iro::ApplicationController
81
85
  next
82
86
  end
83
87
  lower = Tda::Option.get_quote({
84
- contractType: @position.put_call,
88
+ contractType: @position.inner.put_call,
85
89
  strike: @prev.inner.strike - @nn*@stock.options_price_increment,
86
90
  expirationDate: @prev.next_expires_on,
87
91
  ticker: @stock.ticker,
@@ -246,6 +250,7 @@ class Iro::PositionsController < Iro::ApplicationController
246
250
  @positions = @positions.reverse
247
251
  end
248
252
  alias_method :_prepare_short_debit_put_spread, :_prepare_long_debit_call_spread
253
+ alias_method :_prepare_short_credit_call_spread, :_prepare_long_debit_call_spread
249
254
 
250
255
 
251
256
  def sync
@@ -271,8 +276,6 @@ class Iro::PositionsController < Iro::ApplicationController
271
276
  if @position.update pos_params
272
277
  o_attrs = {
273
278
  expires_on: pos.expires_on,
274
- put_call: pos.put_call,
275
- stock_id: pos.stock_id,
276
279
  }
277
280
  pos.inner.update params[:inner].permit!.merge( o_attrs )
278
281
  pos.outer.update params[:outer].permit!.merge( o_attrs )
@@ -293,9 +296,12 @@ class Iro::PositionsController < Iro::ApplicationController
293
296
  private
294
297
 
295
298
  def pos_params
296
- params[:position].permit( :purse_id, :status, :stock_id,
297
- :strategy_id, :expires_on, :quantity, :begin_on,
299
+ params[:position].permit( :begin_on,
300
+ :expires_on,
298
301
  :long_or_short,
302
+ :purse_id,
303
+ :quantity,
304
+ :status, :stock_id, :strategy_id,
299
305
  )
300
306
  end
301
307
 
@@ -20,11 +20,19 @@ class Iro::StocksController < Iro::ApplicationController
20
20
  end
21
21
 
22
22
  def edit
23
+ authorize! :edit, @stock
23
24
  end
24
25
 
25
26
  def index
26
27
  @stocks = Iro::Stock.all
27
28
  authorize! :index, Iro::Stock
29
+
30
+ respond_to do |format|
31
+ format.html
32
+ format.json do
33
+ render layout: false
34
+ end
35
+ end
28
36
  end
29
37
 
30
38
  def new
@@ -44,6 +52,18 @@ class Iro::StocksController < Iro::ApplicationController
44
52
  end
45
53
 
46
54
  def show
55
+ authorize! :show, @stock
56
+
57
+ @priceitems = ::Iro::Priceitem.where({
58
+ ticker: @stock.ticker,
59
+ })
60
+
61
+ respond_to do |format|
62
+ format.html
63
+ format.json do
64
+ render layout: false
65
+ end
66
+ end
47
67
  end
48
68
 
49
69
  def update
@@ -9,7 +9,7 @@ class Iro::Datapoint
9
9
  validates :kind, presence: true
10
10
  index({ kind: -1 })
11
11
 
12
- field :symbol ## ticker, but use 'symbol' ONLY
12
+ field :symbol ## ticker, but use 'symbol' here
13
13
 
14
14
  field :date, type: Date ## @obsolete, use quote_at
15
15
  index({ kind: -1, date: -1 })
@@ -27,15 +27,27 @@ class Iro::Option
27
27
 
28
28
  field :expires_on, type: :date
29
29
  validates :expires_on, presence: true
30
- def self.expirations_list full: false
31
- [
32
- [ nil, nil ],
33
- [ 'Mar 22', '2024-03-22'.to_date ],
34
- [ 'Mar 28', '2024-03-28'.to_date ],
35
- [ 'Apr 5', '2024-04-05'.to_date ],
36
- [ 'Mar 12', '2024-03-12'.to_date ],
37
- [ 'Mar 19', '2024-03-19'.to_date ],
38
- ]
30
+ def self.expirations_list full: false, n: 5
31
+ out = [[nil,nil]]
32
+ day = Date.today - 5.days
33
+ n.times do
34
+ next_exp = day.next_occurring(:thursday).next_occurring(:friday)
35
+ if !next_exp.workday?
36
+ next_exp = Time.previous_business_day( next_exp )
37
+ end
38
+
39
+ out.push([ next_exp.strftime('%b %e'), next_exp.strftime('%Y-%m-%d') ])
40
+ day = next_exp
41
+ end
42
+ return out
43
+ # [
44
+ # [ nil, nil ],
45
+ # [ 'Mar 22', '2024-03-22'.to_date ],
46
+ # [ 'Mar 28', '2024-03-28'.to_date ],
47
+ # [ 'Apr 5', '2024-04-05'.to_date ],
48
+ # [ 'Mar 12', '2024-03-12'.to_date ],
49
+ # [ 'Mar 19', '2024-03-19'.to_date ],
50
+ # ]
39
51
  end
40
52
 
41
53
  field :begin_price, type: :float
@@ -70,10 +82,10 @@ class Iro::Option
70
82
  })
71
83
  puts! out, 'option sync'
72
84
  self.end_price = ( out.bid + out.ask ) / 2 rescue 0
73
- self.end_delta = out.delta
85
+ self.end_delta = out.delta if out.delta
74
86
  # self.save
75
87
  end
76
88
 
77
- before_save :sync
89
+ before_save :sync, if: ->() { !Rails.env.test? } ## do not sync in test
78
90
 
79
91
  end
@@ -12,11 +12,13 @@ class Iro::Position
12
12
  out += inner.begin_price - outer.begin_price
13
13
  end
14
14
 
15
+
15
16
  STATUS_ACTIVE = 'active'
16
- STATUS_PROPOSED = 'proposed'
17
17
  STATUS_CLOSED = 'closed'
18
- STATUS_PENDING = 'pending'
19
- STATUSES = [ nil, STATUS_ACTIVE, STATUS_PROPOSED, STATUS_CLOSED, STATUS_PENDING ]
18
+ STATUS_PROPOSED = 'proposed'
19
+ ## one more, 'selected' after proposed?
20
+ STATUS_PENDING = 'pending' ## 'working'
21
+ STATUSES = [ nil, STATUS_CLOSED, STATUS_ACTIVE, STATUS_PROPOSED, STATUS_PENDING ]
20
22
  field :status
21
23
  validates :status, presence: true
22
24
  scope :active, ->{ where( status: 'active' ) }
@@ -28,29 +30,26 @@ class Iro::Position
28
30
  delegate :ticker, to: :stock
29
31
 
30
32
  belongs_to :strategy, class_name: 'Iro::Strategy', inverse_of: :positions
31
- field :long_or_short
32
-
33
- def put_call
34
- case strategy.kind
35
- when Iro::Strategy::KIND_LONG_DEBIT_CALL_SPREAD
36
- put_call = 'CALL'
37
- when Iro::Strategy::KIND_SHORT_DEBIT_PUT_SPREAD
38
- put_call = 'PUT'
39
- when Iro::Strategy::KIND_COVERED_CALL
40
- put_call = 'CALL'
41
- end
42
- end
33
+ delegate :put_call, to: :strategy
34
+ delegate :long_or_short, to: :strategy
35
+
36
+ belongs_to :next_strategy, class_name: 'Iro::Strategy', inverse_of: :next_position, optional: true
43
37
 
44
- belongs_to :prev, class_name: 'Iro::Position', inverse_of: :nxt, optional: true
38
+
39
+ belongs_to :prev, class_name: 'Iro::Position', inverse_of: :nxts, optional: true
45
40
  belongs_to :autoprev, class_name: 'Iro::Position', inverse_of: :autonxt, optional: true
46
41
  ## there are many of these, for viewing on the 'roll' view
47
- has_many :nxt, class_name: 'Iro::Position', inverse_of: :prev
42
+ has_many :nxts, class_name: 'Iro::Position', inverse_of: :prev
48
43
  has_one :autonxt, class_name: 'Iro::Position', inverse_of: :autoprev
49
44
 
50
45
  ## Options
51
46
 
52
47
  belongs_to :inner, class_name: 'Iro::Option', inverse_of: :inner
48
+ validates_associated :inner
49
+
53
50
  belongs_to :outer, class_name: 'Iro::Option', inverse_of: :outer
51
+ validates_associated :outer
52
+
54
53
  accepts_nested_attributes_for :inner, :outer
55
54
 
56
55
  field :outer_strike, type: :float
@@ -139,6 +138,7 @@ class Iro::Position
139
138
  save
140
139
  end
141
140
 
141
+ ## @TODO: herehere 2024-05-09
142
142
  def calc_nxt
143
143
  pos = self
144
144
 
@@ -150,37 +150,37 @@ class Iro::Position
150
150
  })
151
151
  outs_bk = outs.dup
152
152
 
153
- # byebug
154
-
155
- ## strike price
156
153
  outs = outs.select do |out|
157
- out[:bidSize]+out[:askSize] > 0
154
+ out[:bidSize] + out[:askSize] > 0
158
155
  end
156
+
157
+ ## next_inner_strike
159
158
  outs = outs.select do |out|
160
159
  if Iro::Strategy::SHORT == pos.long_or_short
161
- out[:strikePrice] > strategy.next_buffer_above_water + strategy.stock.last
160
+ out[:strikePrice] >= strategy.next_inner_strike
162
161
  elsif Iro::Strategy::LONG == pos.long_or_short
163
- out[:strikePrice] < strategy.stock.last - strategy.next_buffer_above_water
162
+ out[:strikePrice] <= strategy.next_inner_strike
164
163
  else
165
- throw 'zz4 - this cannot happen'
164
+ raise 'zz3 - this cannot happen'
166
165
  end
167
166
  end
168
- puts! outs[0][:strikePrice], 'after calc next_buffer_above_water'
167
+ puts! outs[0][:strikePrice], 'after calc next_inner_strike'
169
168
 
169
+ ## next_buffer_above_water
170
170
  outs = outs.select do |out|
171
171
  if Iro::Strategy::SHORT == pos.long_or_short
172
- out[:strikePrice] > strategy.next_inner_strike
172
+ out[:strikePrice] > strategy.next_buffer_above_water + strategy.stock.last
173
173
  elsif Iro::Strategy::LONG == pos.long_or_short
174
- out[:strikePrice] < strategy.next_inner_strike
174
+ out[:strikePrice] < strategy.stock.last - strategy.next_buffer_above_water
175
175
  else
176
- throw 'zz3 - this cannot happen'
176
+ raise 'zz4 - this cannot happen'
177
177
  end
178
178
  end
179
- puts! outs[0][:strikePrice], 'after calc next_inner_strike'
179
+ puts! outs[0][:strikePrice], 'after calc next_buffer_above_water'
180
180
 
181
- ## delta
181
+ ## next_inner_delta
182
182
  outs = outs.select do |out|
183
- out_delta = out[:delta].abs rescue 0
183
+ out_delta = out[:delta].abs rescue 0
184
184
  out_delta >= strategy.next_inner_delta.abs
185
185
  end
186
186
  puts! outs[0][:strikePrice], 'after calc next_inner_delta'
@@ -191,8 +191,6 @@ class Iro::Position
191
191
  end
192
192
  outer = outs[0]
193
193
 
194
- # byebug
195
-
196
194
  if inner && outer
197
195
  o_attrs = {
198
196
  expires_on: next_expires_on,
@@ -203,37 +201,37 @@ class Iro::Position
203
201
  strike: inner[:strikePrice],
204
202
  begin_price: ( inner[:bid] + inner[:ask] )/2,
205
203
  begin_delta: inner[:delta],
206
- end_price: ( inner[:bid] + inner[:ask] )/2,
207
- end_delta: inner[:delta],
204
+ end_price: ( inner[:bid] + inner[:ask] )/2,
205
+ end_delta: inner[:delta],
208
206
  }))
209
207
  outer_ = Iro::Option.new(o_attrs.merge({
210
208
  strike: outer[:strikePrice],
211
209
  begin_price: ( outer[:bid] + outer[:ask] )/2,
212
210
  begin_delta: outer[:delta],
213
- end_price: ( outer[:bid] + outer[:ask] )/2,
214
- end_delta: outer[:delta],
211
+ end_price: ( outer[:bid] + outer[:ask] )/2,
212
+ end_delta: outer[:delta],
215
213
  }))
216
214
  pos.autonxt ||= Iro::Position.new
217
215
  pos.autonxt.update({
218
216
  prev_gain_loss_amount: 'a',
219
- status: 'proposed',
220
- stock: strategy.stock,
221
- inner: inner_,
222
- outer: outer_,
217
+ status: 'proposed',
218
+ stock: strategy.stock,
219
+ inner: inner_,
220
+ outer: outer_,
223
221
  inner_strike: inner_.strike,
224
222
  outer_strike: outer_.strike,
225
- begin_on: Time.now.to_date,
226
- expires_on: next_expires_on,
227
- purse: purse,
228
- strategy: strategy,
229
- quantity: 1,
230
- autoprev: pos,
223
+ begin_on: Time.now.to_date,
224
+ expires_on: next_expires_on,
225
+ purse: purse,
226
+ strategy: strategy,
227
+ quantity: 1,
228
+ autoprev: pos,
231
229
  })
232
230
 
233
- # byebug
234
-
235
- autonxt.sync
236
- autonxt.save!
231
+ pos.autonxt.sync
232
+ pos.autonxt.save!
233
+ pos.save
234
+ return pos
237
235
 
238
236
  else
239
237
  throw 'zmq - should not happen'
@@ -246,7 +244,7 @@ class Iro::Position
246
244
  def next_expires_on
247
245
  out = expires_on.to_datetime.next_occurring(:monday).next_occurring(:friday)
248
246
  if !out.workday?
249
- out = Time.previous_business_day(out )
247
+ out = Time.previous_business_day(out)
250
248
  end
251
249
  return out
252
250
  end
@@ -262,7 +260,7 @@ class Iro::Position
262
260
  end
263
261
 
264
262
  def to_s
265
- out = "#{stock} (#{q}) #{expires_on.to_datetime.strftime('%b %d')} #{strategy.kind_short} ["
263
+ out = "#{stock} (#{q}) #{expires_on.to_datetime.strftime('%b %d')} #{strategy.long_or_short} ["
266
264
  if Iro::Strategy::LONG == long_or_short
267
265
  if outer.strike
268
266
  out = out + "$#{outer.strike}->"
@@ -1,5 +1,8 @@
1
1
 
2
- class Iro::PriceItem
2
+ ##
3
+ ## specifically Option or Stock priceitem?
4
+ ##
5
+ class Iro::Priceitem
3
6
  include Mongoid::Document
4
7
  include Mongoid::Timestamps
5
8
  store_in collection: 'iro_price_items'
@@ -8,6 +11,7 @@ class Iro::PriceItem
8
11
  field :putCall, type: String
9
12
  field :symbol, type: String
10
13
  field :ticker, type: String
14
+ # belongs_to :stock, inverse_of: :priceitems
11
15
 
12
16
  field :bid, type: Float
13
17
  field :bidSize, type: Integer
@@ -30,6 +30,13 @@ class Iro::Purse
30
30
  field :n_next_positions, type: :integer, default: 5
31
31
 
32
32
  field :available_amount, type: :float
33
+ def available
34
+ available_amount
35
+ end
36
+
37
+ def balance
38
+ 0.01
39
+ end
33
40
 
34
41
  def delta_wt_avg( begin_end, long_short, inner_outer )
35
42
  max_loss_total = 0
@@ -38,9 +45,9 @@ class Iro::Purse
38
45
  max_loss_total += pos.max_loss * pos.q
39
46
  pos.max_loss * pos.q * pos.send( inner_outer ).send( "#{begin_end}_delta" )
40
47
  end
41
- puts! out, 'delta_wt_avg 1'
48
+ # puts! out, 'delta_wt_avg 1'
42
49
  out = out.reduce( &:+ ) / max_loss_total rescue 0
43
- puts! out, 'delta_wt_avg 2'
50
+ # puts! out, 'delta_wt_avg 2'
44
51
  return out
45
52
  end
46
53
  ## delta to plot percentage
@@ -28,7 +28,9 @@ class Iro::Stock
28
28
  has_many :strategies, class_name: 'Iro::Strategy', inverse_of: :stock
29
29
  has_many :purses, class_name: 'Iro::Purse', inverse_of: :stock
30
30
  has_many :options, class_name: 'Iro::Option', inverse_of: :stock
31
+ has_many :priceitems, inverse_of: :stock
31
32
 
33
+ ## my_find
32
34
  def self.f ticker
33
35
  self.find_by ticker: ticker
34
36
  end