Class: IB::OptionDetail

Inherits:
Model show all
Includes:
BaseProperties
Defined in:
lib/models/ib/option_detail.rb

Overview

Additional Option properties and Option-Calculations

Instance Method Summary collapse

Methods included from BaseProperties

#==, #as_table, #content_attributes, #default_attributes, #invariant_attributes, #set_attribute_defaults, #update_missing

Instance Method Details

#complete?Boolean

returns true if all datafields are filled with reasonal data

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
# File 'lib/models/ib/option_detail.rb', line 25

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

#greeks?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'lib/models/ib/option_detail.rb', line 34

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

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

end

#ivObject



47
48
49
# File 'lib/models/ib/option_detail.rb', line 47

def iv
	implied_volatility
end

#prices?Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/models/ib/option_detail.rb', line 42

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

#spreadObject



51
52
53
# File 'lib/models/ib/option_detail.rb', line 51

def spread
	bid_price - ask_price
end

#table_headerObject



70
71
72
# File 'lib/models/ib/option_detail.rb', line 70

def table_header
  [ 'Greeks', 'price',  'impl. vola', 'dividend', 'delta','gamma', 'vega' , 'theta']
end

#table_rowObject



74
75
76
77
78
79
80
81
# File 'lib/models/ib/option_detail.rb', line 74

def table_row
  outstr= ->( item ) { { value: item.nil? ? "--" : sprintf("%g" , item) , alignment: :right } } 
  outprice= ->( item ) { { value: item.nil? ? "--" : sprintf("%7.2f" , item) , alignment: :right } } 
  option_short = ->{"#{option.right}  #{option.symbol}#{ "/"+ option.trading_class unless option.trading_class == option.symbol } #{option.expiry}  #{option.strike}"}
  [ option_short[], outprice[ option_price ], outprice[ implied_volatility ],
    outprice[ pv_dividend ], 
    outprice[ delta ], outprice[ gamma ], outprice[ vega ] , outprice[ theta ] ]
end

#to_humanObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/models/ib/option_detail.rb', line 55

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