module Iro::OptionBlackScholes

def self.rate_annual

def self.rate_annual
  0.05
end

def self.rate_daily

def self.rate_daily
  n = 250.0 # days
  # n = 12 # months
  out = (1.0+self.rate_annual)**(1.0/n) - 1.0
  puts! out, 'rate_daily'
  return out
end

def call_price

def call_price
  last   = stock.last
  r      = self.class.rate_annual
  out = N.cdf( d1 ) * last - N.cdf( d2 ) * strike * Math::E**( -1 * r * t )
  return out
end

def d1

def d1
  last   = stock.last
  r      = self.class.rate_annual
  out = Math.log( last / strike ) + ( r + stdev**2 / 2 ) * t
  out = out /( stdev * Math.sqrt(t) )
  return out
end

def d2

def d2
  last   = stock.last
  r      = self.class.rate_annual
  out = d1 - stdev * Math.sqrt( t )
  return out
end

def put_price

def put_price
  last   = stock.last
  r      = self.class.rate_annual
  out = N.cdf(-d2) * strike * exp(-r*t) - N.cdf(-d1) * last
  return out
end

def stdev

def stdev
  recompute = nil
  stock.stdev( recompute: recompute )
end

def t

def t
  # t      = 1.0 / 365 * Date.today.business_days_until( expires_on )
  t      = 1.0 / 365 * (expires_on - Date.today).to_i
end