jroberts1
04-15-2015, 12:19 PM
I have a few functions that use the same variables, but would like to consolidate them into one function or sub. Here's an example of a few that I'm using...
Function dONE(stock, exercise, time, interest, sigma)
dONE = (Log(stock / exercise) + interest * time) / (sigma * Sqr(time)) + 0.5 * sigma * Sqr(time)
End Function
Function dTWO(stock, exercise, time, interest, sigma)
dTWO = dONE(stock, exercise, time, interest, sigma) - sigma * Sqr(time)
End Function
Function BSCall(stock, exercise, time, interest, sigma)
BSCall = stock * Application.NormSDist(dONE(stock, exercise, time, interest, sigma)) - exercise * Exp(-time * interest) * Application.NormSDist(dTWO(stock, exercise, time, interest, sigma))
End Function
Function bsput(stock, exercise, time, interest, sigma)
bsput = BSCall(stock, exercise, time, interest, sigma) + exercise * Exp(-interest * time) - stock
End Function
Function deltaput(stock, exercise, time, interest, sigma)
deltaput2 = Application.NormSDist(dONE(stock, exercise, time, interest, sigma)) - 1
End Function
So I was wondering if I could do something like...
"Sub FIN(stock, exercise, time, interest, sigma, keyword)"
and then having the keyword call on the appropriate function, or perhaps reference the function within the coding below it. Any suggestions?
Function dONE(stock, exercise, time, interest, sigma)
dONE = (Log(stock / exercise) + interest * time) / (sigma * Sqr(time)) + 0.5 * sigma * Sqr(time)
End Function
Function dTWO(stock, exercise, time, interest, sigma)
dTWO = dONE(stock, exercise, time, interest, sigma) - sigma * Sqr(time)
End Function
Function BSCall(stock, exercise, time, interest, sigma)
BSCall = stock * Application.NormSDist(dONE(stock, exercise, time, interest, sigma)) - exercise * Exp(-time * interest) * Application.NormSDist(dTWO(stock, exercise, time, interest, sigma))
End Function
Function bsput(stock, exercise, time, interest, sigma)
bsput = BSCall(stock, exercise, time, interest, sigma) + exercise * Exp(-interest * time) - stock
End Function
Function deltaput(stock, exercise, time, interest, sigma)
deltaput2 = Application.NormSDist(dONE(stock, exercise, time, interest, sigma)) - 1
End Function
So I was wondering if I could do something like...
"Sub FIN(stock, exercise, time, interest, sigma, keyword)"
and then having the keyword call on the appropriate function, or perhaps reference the function within the coding below it. Any suggestions?