class FinanceEngine::Black_Scholes
Attributes
call_price[RW]
current_stock_price[RW]
d1[RW]
d2[RW]
put_price[RW]
risk_free_rate[RW]
strike_price[RW]
time[RW]
volatility[RW]
Public Class Methods
new(hash)
click to toggle source
# File lib/finance_engine/optionpricing.rb, line 5 def initialize(hash) @current_stock_price = hash[:price] @strike_price = hash[:strike] @time = hash[:time] @risk_free_rate = hash[:riskfree] @volatility = hash[:volatility] @distr_normal = Distribution::Normal::Ruby_ end
Public Instance Methods
build_options()
click to toggle source
# File lib/finance_engine/optionpricing.rb, line 26 def build_options build_call_premium build_put_premium end
check_attr()
click to toggle source
# File lib/finance_engine/optionpricing.rb, line 14 def check_attr msg = '' msg += "Stock price is missing. " if @current_stock_price.nil? msg += "Time period is missing. " if @time.nil? msg += "Strike Price is missing. " if @strike_price.nil? msg += "Risk free rate is missing. " if @risk_free_rate.nil? msg += "Volatility rate is missing. " if @volatility.nil? inputs = "{price: (Dollar Value), strike: (Dollar Value), time: (In Years), riskfree: (RF rate in decimal form (0.05)), volatility: (Volatility Percentage in decimal form (0.20))}" # puts inputs if msg.length > 0 puts msg if msg.length > 0 end
output()
click to toggle source
# File lib/finance_engine/optionpricing.rb, line 41 def output puts "Stock Call Price #{@call_price.round(4)}" puts "Stock Put Price #{@put_price.round(4)}" puts "Stock Price #{@current_stock_price}" puts "Time #{@time}" puts "Stock Strike Price #{@strike_price}" puts "Stock Risk Free Rate #{@risk_free_rate}" puts "Stock Volatility #{@volatility}" end