Class: Option::Model
- Inherits:
-
Object
- Object
- Option::Model
- Defined in:
- lib/options_library/option_model.rb
Constant Summary collapse
- KNOWN_OPTION_TYPES =
The two known option types, Call and Put
[:call, :put]
- CALC_PRICE_METHODS =
A map to define methods to call based on option_type
{ :call=>Calculator.method('price_call'), :put=>Calculator.method('price_put') }
- CALC_DELTA_METHODS =
{ :call=>Calculator.method('delta_call'), :put=>Calculator.method('delta_put') }
- IMPLIED_VOL_METHODS =
{ :call=>Calculator.method('implied_vol_call'), :put=>Calculator.method('implied_vol_put') }
Instance Attribute Summary collapse
-
#dividend ⇒ Object
Returns the value of attribute dividend.
-
#interest ⇒ Object
Returns the value of attribute interest.
-
#option_type ⇒ Object
Returns the value of attribute option_type.
-
#sigma ⇒ Object
Returns the value of attribute sigma.
-
#strike ⇒ Object
Returns the value of attribute strike.
-
#time ⇒ Object
Returns the value of attribute time.
-
#underlying ⇒ Object
Returns the value of attribute underlying.
Instance Method Summary collapse
- #calc_delta ⇒ Object
- #calc_gamma ⇒ Object
- #calc_implied_vol(target_price) ⇒ Object
- #calc_price ⇒ Object
- #calc_vega ⇒ Object
-
#initialize(option_type) ⇒ Model
constructor
A new instance of Model.
Constructor Details
#initialize(option_type) ⇒ Model
Returns a new instance of Model.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/options_library/option_model.rb', line 18 def initialize(option_type) self.option_type = option_type self. = 0.0 self.strike = 0.0 self.time = 0.0 self.interest = 0.0 self.sigma = 0.0 self.dividend = 0.0 raise 'Unknown option_type' unless KNOWN_OPTION_TYPES.include?(option_type) end |
Instance Attribute Details
#dividend ⇒ Object
Returns the value of attribute dividend.
16 17 18 |
# File 'lib/options_library/option_model.rb', line 16 def dividend @dividend end |
#interest ⇒ Object
Returns the value of attribute interest.
16 17 18 |
# File 'lib/options_library/option_model.rb', line 16 def interest @interest end |
#option_type ⇒ Object
Returns the value of attribute option_type.
16 17 18 |
# File 'lib/options_library/option_model.rb', line 16 def option_type @option_type end |
#sigma ⇒ Object
Returns the value of attribute sigma.
16 17 18 |
# File 'lib/options_library/option_model.rb', line 16 def sigma @sigma end |
#strike ⇒ Object
Returns the value of attribute strike.
16 17 18 |
# File 'lib/options_library/option_model.rb', line 16 def strike @strike end |
#time ⇒ Object
Returns the value of attribute time.
16 17 18 |
# File 'lib/options_library/option_model.rb', line 16 def time @time end |
#underlying ⇒ Object
Returns the value of attribute underlying.
16 17 18 |
# File 'lib/options_library/option_model.rb', line 16 def @underlying end |
Instance Method Details
#calc_delta ⇒ Object
33 34 35 |
# File 'lib/options_library/option_model.rb', line 33 def calc_delta CALC_DELTA_METHODS[option_type].call(, strike, time, interest, sigma, dividend) end |
#calc_gamma ⇒ Object
37 38 39 |
# File 'lib/options_library/option_model.rb', line 37 def calc_gamma Calculator.gamma(, strike, time, interest, sigma, dividend) end |
#calc_implied_vol(target_price) ⇒ Object
45 46 47 |
# File 'lib/options_library/option_model.rb', line 45 def calc_implied_vol(target_price) IMPLIED_VOL_METHODS[option_type].call(, strike, time, interest, target_price, dividend) end |
#calc_price ⇒ Object
29 30 31 |
# File 'lib/options_library/option_model.rb', line 29 def calc_price CALC_PRICE_METHODS[option_type].call(, strike, time, interest, sigma, dividend) end |
#calc_vega ⇒ Object
41 42 43 |
# File 'lib/options_library/option_model.rb', line 41 def calc_vega Calculator.vega(, strike, time, interest, sigma, dividend) end |