Class: OptionLab::Models::BlackScholesModelInputs

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

Overview

Black-Scholes model inputs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ BlackScholesModelInputs

Returns a new instance of BlackScholesModelInputs.



507
508
509
510
511
512
513
514
515
516
# File 'lib/option_lab/models.rb', line 507

def initialize(attributes = {})
  # Set defaults
  @interest_rate = 0.0
  @dividend_yield = 0.0
  @model = 'black-scholes'

  super(attributes)

  validate!
end

Instance Attribute Details

#dividend_yieldObject

Returns the value of attribute dividend_yield.



500
501
502
# File 'lib/option_lab/models.rb', line 500

def dividend_yield
  @dividend_yield
end

#interest_rateObject

Returns the value of attribute interest_rate.



500
501
502
# File 'lib/option_lab/models.rb', line 500

def interest_rate
  @interest_rate
end

#modelObject

Returns the value of attribute model.



500
501
502
# File 'lib/option_lab/models.rb', line 500

def model
  @model
end

#stock_priceObject

Returns the value of attribute stock_price.



500
501
502
# File 'lib/option_lab/models.rb', line 500

def stock_price
  @stock_price
end

#volatilityObject

Returns the value of attribute volatility.



500
501
502
# File 'lib/option_lab/models.rb', line 500

def volatility
  @volatility
end

#years_to_target_dateObject

Returns the value of attribute years_to_target_date.



500
501
502
# File 'lib/option_lab/models.rb', line 500

def years_to_target_date
  @years_to_target_date
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



522
523
524
525
526
527
528
529
530
531
# File 'lib/option_lab/models.rb', line 522

def ==(other)
  return false unless other.is_a?(BlackScholesModelInputs)

  stock_price == other.stock_price &&
    volatility == other.volatility &&
    years_to_target_date == other.years_to_target_date &&
    interest_rate == other.interest_rate &&
    dividend_yield == other.dividend_yield &&
    model == other.model
end

#hashObject



535
536
537
# File 'lib/option_lab/models.rb', line 535

def hash
  [stock_price, volatility, years_to_target_date, interest_rate, dividend_yield, model].hash
end

#validate!Object

Raises:

  • (ArgumentError)


518
519
520
# File 'lib/option_lab/models.rb', line 518

def validate!
  raise ArgumentError, "model must be 'black-scholes' or 'normal'" unless ['black-scholes', 'normal'].include?(model)
end