Class: IB::OptionDetail
Overview
Additional Option properties and Option-Calculations
Instance Method Summary
collapse
#==, #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
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
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
|
47
48
49
|
# File 'lib/models/ib/option_detail.rb', line 47
def iv
implied_volatility
end
|
#prices? ⇒ 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
|
51
52
53
|
# File 'lib/models/ib/option_detail.rb', line 51
def spread
bid_price - ask_price
end
|
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
|