Sha256: 63bdb75fad2833e1e9a7a76e71b125c9ca464e436196fd00f6ffb2d6ce9b9371

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

module IB
  class Option
    # helper method to roll an existing option
    #
    # Arguments are strike and expiry of the target-option.
    #
    # Example:  ge= Symbols::Options.ge.verify.first.roll( strike: 13 )  
    #           ge.to_human
    #  => " added <Option: GE 20210917 call 7.0 SMART USD> added <Option: GE 20210917 call 13.0 SMART USD>" 
# 
    #   rolls the Option to another strike

    def roll **args
      error "specify strike and expiry to roll option" if args.empty?
      args[:to] = args[:expiry] if args[:expiry].present?  && args[:expiry] =~ /[mwMW]$/
      args[:expiry]= IB::Spread.transform_distance( expiry, args.delete(:to  )) if args[:to].present?
      
      new_option =  merge( **args ).verify.first
      myself =  con_id.to_i.zero? ? self.verify.first  : self
      error "Cannot roll option; target is no IB::Contract" unless new_option.is_a? IB::Option
      error "Cannot roll option; Option cannot be verified" unless myself.is_a? IB::Option
      target = IB::Spread.new exchange: exchange, symbol: symbol, currency: currency
      target.add_leg myself, action:  :buy
      target.add_leg new_option, action: :sell
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ib-extensions-1.3.1 lib/ib/models/option.rb
ib-extensions-1.3 lib/ib/models/option.rb