Class: OptionLab::Models::AmericanModelInputs

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/option_lab/models.rb

Overview

Bjerksund-Stensland model inputs for American options

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ AmericanModelInputs

Returns a new instance of AmericanModelInputs.



701
702
703
704
705
706
707
# File 'lib/option_lab/models.rb', line 701

def initialize(attributes = {})
  # Set defaults
  @option_type = 'call'
  @dividend_yield = 0.0

  super(attributes)
end

Instance Attribute Details

#dividend_yieldObject

Returns the value of attribute dividend_yield.



693
694
695
# File 'lib/option_lab/models.rb', line 693

def dividend_yield
  @dividend_yield
end

#interest_rateObject

Returns the value of attribute interest_rate.



693
694
695
# File 'lib/option_lab/models.rb', line 693

def interest_rate
  @interest_rate
end

#option_typeObject

Returns the value of attribute option_type.



693
694
695
# File 'lib/option_lab/models.rb', line 693

def option_type
  @option_type
end

#stock_priceObject

Returns the value of attribute stock_price.



693
694
695
# File 'lib/option_lab/models.rb', line 693

def stock_price
  @stock_price
end

#strikeObject

Returns the value of attribute strike.



693
694
695
# File 'lib/option_lab/models.rb', line 693

def strike
  @strike
end

#volatilityObject

Returns the value of attribute volatility.



693
694
695
# File 'lib/option_lab/models.rb', line 693

def volatility
  @volatility
end

#years_to_maturityObject

Returns the value of attribute years_to_maturity.



693
694
695
# File 'lib/option_lab/models.rb', line 693

def years_to_maturity
  @years_to_maturity
end

Instance Method Details

#greeksObject



731
732
733
734
735
736
737
738
739
740
741
# File 'lib/option_lab/models.rb', line 731

def greeks
  OptionLab.get_american_greeks(
    option_type,
    stock_price,
    strike,
    interest_rate,
    volatility,
    years_to_maturity,
    dividend_yield,
  )
end

#priceObject



719
720
721
722
723
724
725
726
727
728
729
# File 'lib/option_lab/models.rb', line 719

def price
  OptionLab.price_american(
    option_type,
    stock_price,
    strike,
    interest_rate,
    volatility,
    years_to_maturity,
    dividend_yield,
  )
end

#validate!Object

Raises:

  • (ArgumentError)


709
710
711
712
713
714
715
716
717
# File 'lib/option_lab/models.rb', line 709

def validate!
  raise ArgumentError, "option_type must be 'call' or 'put'" unless OPTION_TYPES.include?(option_type)
  raise ArgumentError, 'stock_price must be positive' unless stock_price.is_a?(Numeric) && stock_price.positive?
  raise ArgumentError, 'strike must be positive' unless strike.is_a?(Numeric) && strike.positive?
  raise ArgumentError, 'interest_rate must be non-negative' unless interest_rate.is_a?(Numeric) && interest_rate >= 0
  raise ArgumentError, 'volatility must be positive' unless volatility.is_a?(Numeric) && volatility.positive?
  raise ArgumentError, 'years_to_maturity must be non-negative' unless years_to_maturity.is_a?(Numeric) && years_to_maturity >= 0
  raise ArgumentError, 'dividend_yield must be non-negative' unless dividend_yield.is_a?(Numeric) && dividend_yield >= 0
end