Class: Option::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/options_library/option_model.rb

Direct Known Subclasses

Call, Put

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

Instance Method Summary collapse

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.underlying = 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

#dividendObject

Returns the value of attribute dividend.



16
17
18
# File 'lib/options_library/option_model.rb', line 16

def dividend
  @dividend
end

#interestObject

Returns the value of attribute interest.



16
17
18
# File 'lib/options_library/option_model.rb', line 16

def interest
  @interest
end

#option_typeObject

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

#sigmaObject

Returns the value of attribute sigma.



16
17
18
# File 'lib/options_library/option_model.rb', line 16

def sigma
  @sigma
end

#strikeObject

Returns the value of attribute strike.



16
17
18
# File 'lib/options_library/option_model.rb', line 16

def strike
  @strike
end

#timeObject

Returns the value of attribute time.



16
17
18
# File 'lib/options_library/option_model.rb', line 16

def time
  @time
end

#underlyingObject

Returns the value of attribute underlying.



16
17
18
# File 'lib/options_library/option_model.rb', line 16

def underlying
  @underlying
end

Instance Method Details

#calc_deltaObject



33
34
35
# File 'lib/options_library/option_model.rb', line 33

def calc_delta
  CALC_DELTA_METHODS[option_type].call(underlying, strike, time, interest, sigma, dividend)
end

#calc_gammaObject



37
38
39
# File 'lib/options_library/option_model.rb', line 37

def calc_gamma
  Calculator.gamma(underlying, 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(underlying, strike, time, interest, target_price, dividend)
end

#calc_priceObject



29
30
31
# File 'lib/options_library/option_model.rb', line 29

def calc_price
  CALC_PRICE_METHODS[option_type].call(underlying, strike, time, interest, sigma, dividend)
end

#calc_vegaObject



41
42
43
# File 'lib/options_library/option_model.rb', line 41

def calc_vega
  Calculator.vega(underlying, strike, time, interest, sigma, dividend)
end