app/models/iro/position.rb in iron_warbler-2.0.7.32 vs app/models/iro/position.rb in iron_warbler-2.0.7.33
- old
+ new
@@ -136,11 +136,10 @@
self.rollp = out[0]
self.next_reasons.push out[1]
save
end
- ## @TODO: herehere 2024-05-09
def calc_nxt
pos = self
## 7 days ahead - not configurable so far
outs = Tda::Option.get_quotes({
@@ -152,10 +151,16 @@
outs = outs.select do |out|
out[:bidSize] + out[:askSize] > 0
end
+ if 'CALL' == pos.put_call
+ ;
+ elsif 'PUT' == pos.put_call
+ outs = outs.reverse
+ end
+
## next_inner_strike
outs = outs.select do |out|
if Iro::Strategy::SHORT == pos.long_or_short
out[:strikePrice] >= strategy.next_inner_strike
elsif Iro::Strategy::LONG == pos.long_or_short
@@ -163,10 +168,11 @@
else
raise 'zz3 - this cannot happen'
end
end
puts! outs[0][:strikePrice], 'after calc next_inner_strike'
+ puts! outs, 'outs'
## next_buffer_above_water
outs = outs.select do |out|
if Iro::Strategy::SHORT == pos.long_or_short
out[:strikePrice] > strategy.next_buffer_above_water + strategy.stock.last
@@ -175,20 +181,33 @@
else
raise 'zz4 - this cannot happen'
end
end
puts! outs[0][:strikePrice], 'after calc next_buffer_above_water'
+ puts! outs, 'outs'
## next_inner_delta
outs = outs.select do |out|
- out_delta = out[:delta].abs rescue 0
- out_delta >= strategy.next_inner_delta.abs
+ if 'CALL' == pos.put_call
+ out_delta = out[:delta] rescue 1
+ out_delta <= strategy.next_inner_delta
+ elsif 'PUT' == pos.put_call
+ out_delta = out[:delta] rescue 0
+ out_delta <= strategy.next_inner_delta
+ else
+ raise 'zz5 - this cannot happen'
+ end
end
puts! outs[0][:strikePrice], 'after calc next_inner_delta'
+ puts! outs, 'outs'
inner = outs[0]
outs = outs.select do |out|
- out[:strikePrice] >= inner[:strikePrice].to_f + strategy.next_spread_amount
+ if 'CALL' == pos.put_call
+ out[:strikePrice] >= inner[:strikePrice].to_f + strategy.next_spread_amount
+ elsif 'PUT' == pos.put_call
+ out[:strikePrice] <= inner[:strikePrice].to_f - strategy.next_spread_amount
+ end
end
outer = outs[0]
if inner && outer
o_attrs = {