Is it possible to do heavy financial/math functions in SQL?
I have an excel function
Function BlackScholes(Underlying, Strike, RiskFree, expTime, Volatility)
d1 = (Log(Underlying / Strike) + RiskFree * expTime) / (Volatility * Sqr(expTime)) + _
0.5 * Volatility * Sqr(expTime)
BlackScholes = Underlying * Application.NormSDist(d1) - Strike * Exp(-expTime * RiskFree) * _
Application.NormSDist(d1 - Volatility * Sqr(expTime))
passing in 48,50,0.06,0.25,0.25 I get back a value of 1.847038
So I tried to recreate it in SQL (realizing that I have no idea how to recreate Application.NormSDist atm)
select@underlying = 48,
@strike = 50,
@RiskFree = 0.06,
@expTime = 0.25,
@vol = 0.25
select @d1 = (Log(@underlying / @strike) + @RiskFree * @expTime) / (@vol * SQRT(@expTime)) + 0.5 * @vol * SQRT(@expTime)
select @blackscholes = (@underlying * @d1 - @strike * Exp(-@expTime * @RiskFree)) * (@d1 - @vol * SQRT(@expTime))
Starting with the first select @d1 line. I get a domain error because Log(48/50) is invalid.
I always thought Log was a Log, how can Excel do it and not SQL? Anyone know of a workaround? I figure onec I get that squared away (no pun intended), I can figure how to do the standard/normal distribution.