class Ish::IronCondor

c.update_attributes( call_sell_strike: 242, call_buy_strike: 243, put_sell_strike: 229, put_buy_strike: 228 )

Constants

STATUSES

Public Class Methods

all_filled() click to toggle source
# File lib/ish/iron_condor.rb, line 28
def self.all_filled
  where( status: :filled )
end

Public Instance Methods

buysell_spread() click to toggle source
# File lib/ish/iron_condor.rb, line 56
def buysell_spread
  1 # $1 for QQQ
end
created_on() click to toggle source

Internal, below

# File lib/ish/iron_condor.rb, line 26
def created_on; created_at.to_date; end
get_call_buy_strike() click to toggle source
# File lib/ish/iron_condor.rb, line 64
def get_call_buy_strike
  call_sell_strike + buysell_spread
end
get_call_sell_strike() click to toggle source
# File lib/ish/iron_condor.rb, line 60
def get_call_sell_strike
  result = enter_price * ( 1 - period_iv/100 )
  result = result.ceil
end
get_put_buy_strike() click to toggle source
# File lib/ish/iron_condor.rb, line 72
def get_put_buy_strike
  put_sell_strike - buysell_spread
end
get_put_sell_strike() click to toggle source
# File lib/ish/iron_condor.rb, line 68
def get_put_sell_strike
  result = enter_price * ( 1 - period_iv/100 )
  result = result.floor
end
iv_period() click to toggle source
# File lib/ish/iron_condor.rb, line 45
def iv_period
  n_days = created_on.business_days_until expires_on
  result = iv_annual.to_f / Math.sqrt(252/n_days)
end
Also aliased as: period_iv
lower_panic_threshold() click to toggle source
# File lib/ish/iron_condor.rb, line 80
def lower_panic_threshold
  result = put_sell_strike * ( 1 + panic_percentage )
end
new_multileg_order_example_done() click to toggle source
# File lib/ish/iron_condor.rb, line 84
  def new_multileg_order_example_done
    ticker = 'QQQ'
    px = 0.08
    account_id = ALLY_CREDS[:account_id]
    n_contracts = 1
    sell_strike = 237.0
    buy_strike = 237.5
    expiration = '2020-02-21'.to_date

    tmpl = <<~AOL
    <FIXML xmlns="http://www.fixprotocol.org/FIXML-5-0-SP2">
      <NewOrdMleg TmInForce="0" Px="#{px}" OrdTyp="2" Acct="#{account_id}">
        <Ord OrdQty="#{n_contracts}" PosEfct="O">
          <Leg Side="2" Strk="#{sell_strike}" 
            Mat="#{expiration.strftime('%Y-%m-%d')}T00:00:00.000-05:00" MMY="#{expiration.strftime('%y%m')}" 
            SecTyp="OPT" CFI="OC" Sym="#{ticker}"/>
        </Ord>
        <Ord OrdQty="#{n_contracts}" PosEfct="O">
          <Leg Side="1" Strk="#{buy_strike}" 
            Mat="#{expiration.strftime('%Y-%m-%d')}T00:00:00.000-05:00" MMY="#{expiration.strftime('%y%m')}" 
            SecTyp="OPT" CFI="OC" Sym="#{ticker}"/>
        </Ord>
      </NewOrdMleg>
    </FIXML>
    AOL
  end
new_purchase_trash() click to toggle source
# File lib/ish/iron_condor.rb, line 111
  def new_purchase_trash
    ticker = 'AXU'
    px = 2.06
    account_id = ALLY_CREDS[:account_id]
    n_contracts = 1
    strike = 2.06

    xml = <<~AOL
      <FIXML xmlns="http://www.fixprotocol.org/FIXML-5-0-SP2">
        <Order TmInForce="0" Typ="1" Side="1" Acct="#{account_id}">
          <Instrmt SecTyp="CS" Sym="#{ticker}"/>
          <OrdQty Qty="1"/>
        </Order>
      </FIXML>
    AOL
  end
panic_percentage() click to toggle source

how close to a sell leg I need to be to take followup action

# File lib/ish/iron_condor.rb, line 52
def panic_percentage
  0.01 # 1% for QQQ
end
period_iv()
Alias for: iv_period
rolldown_xml(access_token=nil, natural=nil) click to toggle source
# File lib/ish/iron_condor.rb, line 230
  def rolldown_xml access_token=nil, natural=nil
    @access_token ||= access_token

    new_put_sell_strike = ( natural * ( 1 - period_iv ) ).floor
    new_put_buy_strike = new_put_sell_strike - buysell_spread

    # get the costs of the option first, to compute `Px`
    ymd = expires_on.strftime('%y%m%d')
    price8 = (new_put_sell_strike*1000).to_i.to_s.rjust(8, '0')
    path = "/v1/market/ext/quotes.json?symbols=#{ticker}#{ymd}C#{price8}"
    puts! path, 'path sell'
    response = @access_token.post(path, {'Accept' => 'application/json'})
    json_sell = JSON.parse( response.body ).deep_symbolize_keys
    json_sell_bid = json_sell[:response][:quotes][:quote][:bid].to_f
    json_sell_ask = json_sell[:response][:quotes][:quote][:ask].to_f
    json_puts! json_sell, 'json_sell'

    price8 = (new_put_buy_strike*1000).to_s.rjust(8, '0')
    path = "/v1/market/ext/quotes.json?symbols=#{ticker}#{ymd}C#{price8}"
    puts! path, 'path buy'
    response = @access_token.post(path, {'Accept' => 'application/json'})
    json_buy = JSON.parse( response.body ).deep_symbolize_keys
    json_buy_bid = json_buy[:response][:quotes][:quote][:bid].to_f
    json_buy_ask = json_buy[:response][:quotes][:quote][:ask].to_f
    json_puts! json_buy, 'json_buy'

    px_sell = ( json_sell_bid.to_f + json_sell_ask ) / 2
    px_sell = px_sell # .round 2
    px_buy = ( json_buy_bid + json_buy_ask )/ 2
    px_buy = px_buy # .round 2
    px = px_sell - px_buy
    px = ( px * 20 ).round.to_f / 20 # down to nearest 0.05
    puts! px, 'px'

=begin
    update( status: :rolling_down, 
      new_put_sell_strike: new_put_sell_strike, 
      new_put_buy_strike: new_put_buy_strike )
=end

    rollup_tmpl =<<~AOL
      <?xml version="1.0" encoding="UTF-8"?>
      <FIXML xmlns="http://www.fixprotocol.org/FIXML-5-0-SP2">
        <NewOrdMleg
          OrdTyp="2"
          Px="#{px}"
          Acct="#{ALLY_CREDS[:account_id]}" 
          TmInForce="0"
        >
          <Ord OrdQty="#{n_contracts}" PosEfct="C" >
            <Leg 
              AcctTyp="5" 
              Side="1" 
              Strk="#{put_sell_strike}" 
              Mat="#{expires_on.strftime('%Y-%m-%d')}T00:00:00.000‐05:00"
              MMY="#{expires_on.strftime('%Y%m')}"
              SecTyp="OPT"
              CFI="OP"
              Sym="#{ticker}" />
          </Ord>
          <Ord OrdQty="#{n_contracts}" PosEfct="C" >
            <Leg 
              Side="2" 
              Strk="#{put_buy_strike}" 
              Mat="#{expires_on.strftime('%Y-%m-%d')}T00:00:00.000‐05:00" 
              MMY="#{expires_on.strftime('%Y%m')}" 
              SecTyp="OPT" 
              CFI="OP" 
              Sym="#{ticker}" />
          </Ord>
          <Ord OrdQty="#{n_contracts}" PosEfct="O" >
            <Leg 
              Side="2" 
              Strk="#{new_put_sell_strike}" 
              Mat="#{expires_on.strftime('%Y-%m-%d')}T00:00:00.000‐05:00" 
              MMY="#{expires_on.strftime('%Y%m')}" 
              SecTyp="OPT" 
              CFI="OP" 
              Sym="#{ticker}" />
          </Ord>
          <Ord OrdQty="#{n_contracts}" PosEfct="O" >
            <Leg 
              Side="1" 
              Strk="#{new_put_buy_strike}" 
              Mat="#{expires_on.strftime('%Y-%m-%d')}T00:00:00.000‐05:00" 
              MMY="#{expires_on.strftime('%Y%m')}" 
              SecTyp="OPT" 
              CFI="OP" 
              Sym="#{ticker}" />
          </Ord>
        </NewOrdMleg>
      </FIXML>
    AOL
  end
rollup_xml(access_token=nil, natural=nil) click to toggle source

www.ally.com/api/invest/documentation/fixml/ www.ally.com/api/invest/documentation/trading/ follow up, roll up buy call to close sell call to close sell call to open buy call to open

# File lib/ish/iron_condor.rb, line 135
  def rollup_xml access_token=nil, natural=nil
    @access_token ||= access_token

    new_call_sell_strike = ( natural * ( 1 + period_iv ) ).ceil
    new_call_buy_strike = new_call_sell_strike + buysell_spread

    # get the costs of the option first, to compute `Px`
    ymd = expires_on.strftime('%y%m%d')
    price8 = (new_call_sell_strike*1000).to_i.to_s.rjust(8, '0')
    path = "/v1/market/ext/quotes.json?symbols=#{ticker}#{ymd}C#{price8}"
    puts! path, 'path sell'
    response = @access_token.post(path, {'Accept' => 'application/json'})
    json_sell = JSON.parse( response.body ).deep_symbolize_keys
    json_sell_bid = json_sell[:response][:quotes][:quote][:bid].to_f
    json_sell_ask = json_sell[:response][:quotes][:quote][:ask].to_f
    
    price8 = (new_call_buy_strike*1000).to_s.rjust(8, '0')
    path = "/v1/market/ext/quotes.json?symbols=#{ticker}#{ymd}C#{price8}"
    response = @access_token.post(path, {'Accept' => 'application/json'})
    json_buy = JSON.parse( response.body ).deep_symbolize_keys
    json_buy_bid = json_buy[:response][:quotes][:quote][:bid].to_f
    json_buy_ask = json_buy[:response][:quotes][:quote][:ask].to_f

    px_sell = ( json_sell_bid.to_f + json_sell_ask ) / 2
    px_sell = px_sell # .round 2
    px_buy = ( json_buy_bid + json_buy_ask )/ 2
    px_buy = px_buy # .round 2
    px = px_sell - px_buy
    px = ( px * 20 ).round.to_f / 20 # down to nearest 0.05
    
    json_puts! json_sell, 'json_sell'
    json_puts! json_buy, 'json_buy'
    puts! px, '^00 - px'

=begin
    update( status: :rolling_up, 
      new_call_sell_strike: new_call_sell_strike, 
      new_call_buy_strike: new_call_buy_strike )
=end

    rollup_tmpl =<<~AOL
      <?xml version="1.0" encoding="UTF-8"?>
      <FIXML xmlns="http://www.fixprotocol.org/FIXML-5-0-SP2">
        <NewOrdMleg
          OrdTyp="2"
          Px="#{px}"
          Acct="#{ALLY_CREDS[:account_id]}" 
          TmInForce="0"
        >
          <Ord OrdQty="#{n_contracts}" PosEfct="C" >
            <Leg 
              AcctTyp="5" 
              Side="1" 
              Strk="#{call_sell_strike}" 
              Mat="#{expires_on.strftime('%Y-%m-%d')}T00:00:00.000‐05:00"
              MMY="#{expires_on.strftime('%Y%m')}"
              SecTyp="OPT"
              CFI="OC"
              Sym="#{ticker}" />
          </Ord>
          <Ord OrdQty="#{n_contracts}" PosEfct="C" >
            <Leg 
              Side="2" 
              Strk="#{call_buy_strike}" 
              Mat="#{expires_on.strftime('%Y-%m-%d')}T00:00:00.000‐05:00" 
              MMY="#{expires_on.strftime('%Y%m')}" 
              SecTyp="OPT" 
              CFI="OC" 
              Sym="#{ticker}" />
          </Ord>
          <Ord OrdQty="#{n_contracts}" PosEfct="O" >
            <Leg 
              Side="2" 
              Strk="#{new_call_sell_strike}" 
              Mat="#{expires_on.strftime('%Y-%m-%d')}T00:00:00.000‐05:00" 
              MMY="#{expires_on.strftime('%Y%m')}" 
              SecTyp="OPT" 
              CFI="OC" 
              Sym="#{ticker}" />
          </Ord>
          <Ord OrdQty="#{n_contracts}" PosEfct="O" >
            <Leg 
              Side="1" 
              Strk="#{new_call_buy_strike}" 
              Mat="#{expires_on.strftime('%Y-%m-%d')}T00:00:00.000‐05:00" 
              MMY="#{expires_on.strftime('%Y%m')}" 
              SecTyp="OPT" 
              CFI="OC" 
              Sym="#{ticker}" />
          </Ord>
        </NewOrdMleg>
      </FIXML>
    AOL
  end
upper_panic_threshold() click to toggle source
# File lib/ish/iron_condor.rb, line 76
def upper_panic_threshold
  result = call_sell_strike * ( 1 - panic_percentage )
end