iron_warbler 2.0.7.26 → 2.0.7.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/iron_warbler/purses.scss +31 -0
- data/app/assets/stylesheets/iron_warbler/utils.scss +28 -3
- data/app/controllers/iro/api/stocks_controller.rb +7 -4
- data/app/controllers/iro/positions_controller.rb +27 -21
- data/app/controllers/iro/stocks_controller.rb +19 -0
- data/app/models/iro/datapoint.rb +1 -1
- data/app/models/iro/option.rb +23 -11
- data/app/models/iro/position.rb +51 -53
- data/app/models/iro/{price_item.rb → priceitem.rb} +5 -1
- data/app/models/iro/purse.rb +9 -2
- data/app/models/iro/stock.rb +2 -0
- data/app/models/iro/strategy.rb +87 -50
- data/app/models/tda/option.rb +1 -1
- data/app/models/tda/stock.rb +1 -1
- data/app/views/iro/_main_header.haml +4 -3
- data/app/views/iro/api/stocks/index.json.jbuilder +5 -0
- data/app/views/iro/api/stocks/show.json.jbuilder +11 -0
- data/app/views/iro/api/stocks/show.json.jbuilder-bk +12 -0
- data/app/views/iro/positions/_form.haml +4 -2
- data/app/views/iro/positions/_gameui_short_credit_call_spread.haml +38 -0
- data/app/views/iro/positions/_header_short_credit_call_spread.haml +50 -0
- data/app/views/iro/positions/_new.haml +23 -0
- data/app/views/iro/positions/_prepare_short_credit_call_spread.haml +1 -0
- data/app/views/iro/purses/_form_extra_fields.haml +18 -22
- data/app/views/iro/purses/_header.haml +8 -17
- data/app/views/iro/purses/show.haml +3 -2
- data/app/views/iro/stocks/_form.haml +4 -3
- data/app/views/iro/stocks/edit.haml +4 -0
- data/app/views/iro/stocks/index.haml +21 -6
- data/app/views/iro/strategies/_form.haml +14 -11
- data/app/views/iro/strategies/_show.haml +1 -1
- data/config/routes.rb +2 -1
- data/lib/iro/engine.rb +1 -0
- data/lib/iron_warbler.rb +0 -2
- data/lib/tasks/iro_tasks.rake +2 -2
- metadata +12 -4
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 817fe321c59fe077810b34daaf097462c339ccbf7a2944845f1f460f3bff72cc
|
4
|
+
data.tar.gz: 10a0379b148bd595b730d63ab5b63cf624c4c3039c5586309981f840ad0869bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 015ce7410f643ea640082ccfc7f231009d527b287a24206eb5b3340a1571b477c95f2da9a9eaed8e7b2f0a1d0162a59f553029a57746a324be560083cbf92f5a
|
7
|
+
data.tar.gz: cabc439b34662c94886d6893138a51c4be2ace1b8a97fdc7a8fa0859bbea4178fca944043c50365a5b04093269688a95d1d8ce3e1e3c8d52293dac12d3f345c0
|
@@ -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
|
-
|
47
|
-
|
48
|
-
|
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.
|
10
|
-
|
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:
|
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
|
40
|
-
@position
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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( :
|
297
|
-
:
|
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,17 @@ 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.json do
|
63
|
+
render layout: false
|
64
|
+
end
|
65
|
+
end
|
47
66
|
end
|
48
67
|
|
49
68
|
def update
|
data/app/models/iro/datapoint.rb
CHANGED
@@ -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'
|
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 })
|
data/app/models/iro/option.rb
CHANGED
@@ -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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
data/app/models/iro/position.rb
CHANGED
@@ -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
|
-
|
19
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
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 :
|
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]
|
160
|
+
out[:strikePrice] >= strategy.next_inner_strike
|
162
161
|
elsif Iro::Strategy::LONG == pos.long_or_short
|
163
|
-
out[:strikePrice]
|
162
|
+
out[:strikePrice] <= strategy.next_inner_strike
|
164
163
|
else
|
165
|
-
|
164
|
+
raise 'zz3 - this cannot happen'
|
166
165
|
end
|
167
166
|
end
|
168
|
-
puts! outs[0][:strikePrice], 'after calc
|
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.
|
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.
|
174
|
+
out[:strikePrice] < strategy.stock.last - strategy.next_buffer_above_water
|
175
175
|
else
|
176
|
-
|
176
|
+
raise 'zz4 - this cannot happen'
|
177
177
|
end
|
178
178
|
end
|
179
|
-
puts! outs[0][:strikePrice], 'after calc
|
179
|
+
puts! outs[0][:strikePrice], 'after calc next_buffer_above_water'
|
180
180
|
|
181
|
-
##
|
181
|
+
## next_inner_delta
|
182
182
|
outs = outs.select do |out|
|
183
|
-
out_delta
|
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:
|
207
|
-
end_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:
|
214
|
-
end_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:
|
220
|
-
stock:
|
221
|
-
inner:
|
222
|
-
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:
|
226
|
-
expires_on:
|
227
|
-
purse:
|
228
|
-
strategy:
|
229
|
-
quantity:
|
230
|
-
autoprev:
|
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
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
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.
|
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
|
-
|
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
|
data/app/models/iro/purse.rb
CHANGED
@@ -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
|
data/app/models/iro/stock.rb
CHANGED
@@ -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
|