Sha256: a21bad052ea5ec60c424db54986ba542dfe6767c852dc42edc93c8601dd07ccf

Contents?: true

Size: 1.85 KB

Versions: 6

Compression:

Stored size: 1.85 KB

Contents

module IB

  # Additional Option properties and Option-Calculations
  class OptionDetail < IB::Model
    include BaseProperties

    prop :delta,  :gamma, :vega, :theta, # greeks
         :implied_volatility,
	 :pv_dividend, # anticipated Dividend
	 :under_price,  # price of the Underlying
	 :option_price,
	 :close_price,
	 :open_tick,
	 :bid_price,
	 :ask_price,
	 :prev_strike,
	 :next_strike,
	 :prev_expiry,
	 :next_expiry,
	 :option_price,
	 :updated_at
    belongs_to :option

    # returns true if all datafields are filled with reasonal data
    def complete?
     fields= [ :delta,  :gamma, :vega, :theta,
         :implied_volatility, :pv_dividend, :open_tick,
	 :under_price, :option_price, :close_price, :bid_price, :ask_price]

      !fields.detect{|y| self.send(y).nil?}

    end

    def greeks?
     fields= [ :delta,  :gamma, :vega, :theta,
         :implied_volatility]

      !fields.detect{|y| self.send(y).nil?}

    end

		def prices?
			fields = [:implied_volatility, :under_price, :option_price]
      !fields.detect{|y| self.send(y).nil?}
		end

		def iv
			implied_volatility
		end

		def spread
			bid_price - ask_price
		end 

    def to_human
      outstr= ->( item ) { if item.nil? then "--" else  sprintf("%g" , item)  end  }
      att = " optionPrice: #{ outstr[ option_price ]}, UnderlyingPrice: #{ outstr[ under_price] } impl.Vola: #{ outstr[ implied_volatility ]} ; dividend: #{ outstr[ pv_dividend ]}; "
      greeks = "Greeks::  delta:  #{ outstr[ delta ] }; gamma: #{ outstr[ gamma ]}, vega: #{ outstr[ vega ] }; theta: #{ outstr[ theta ]}" 
      prices= " close: #{ outstr[ close_price ]}; bid: #{ outstr[ bid_price ]}; ask: #{ outstr[ ask_price ]} "
      if	complete?
				"< "+ prices + "\n" + att + "\n" + greeks + " >"
			elsif prices?
				"< " + att + greeks + " >"
      else
	"< " + greeks + " >"
      end

    end

  end  # class
end # module

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ib-api-972.5 lib/models/ib/option_detail.rb
ib-api-972.4 lib/models/ib/option_detail.rb
ib-api-972.3.1 lib/models/ib/option_detail.rb
ib-api-972.3 lib/models/ib/option_detail.rb
ib-api-972.2 lib/models/ib/option_detail.rb
ib-api-972.1 lib/models/ib/option_detail.rb