PDA

View Full Version : Solved: User defined function not appearing



ray444
11-07-2012, 08:08 AM
Hello everyone,

I just typed a function on VBE but it is not appearing on my functions is it normal?

Here is the code Function getcallprice(spot_, strike_, maturity_, pricing_date_, divyield, rate_, vol_)
If IsEmpty(vol_) Or vol_ = 0 Then vol_ = 0.25
maturity_ = maturity_ - pricing_date_
If maturity_ < 0 Then
getcallprice = 0
Exit Function
End If
maturity_ = Application.Max(maturity_ / 365, 1 / 365)
d1 = 1 / (vol_ * Sqr(maturity_)) * (Log(spot_ / strike_) + (rate_ - divyield_ + 1 / 2 * vol_ ^ 2) * maturity_)
d2 = d1 - vol_ * Sqr(maturity_)
Nd1 = Application.NormSDist(d1)
Nd2 = Application.NormSDist(d2)
getcallprice = Nd1 * spot_ * Exp(-divyield_ * maturity_) - Nd2 * strike_ * Exp(-rate_ * maturity)
End Function

Thanks a lot!

REgards

Kenneth Hobs
11-07-2012, 08:38 AM
Did you put it in a Module and looked in User Defined Functions category?

You can add descriptive text by Application.MacroOptions.

I recommend using
Option Explicit
as first line of code in a Module.

Please use VBA code tags for pasted code.

ray444
11-07-2012, 08:52 AM
Thanks a lot Kenneth sorry for that
Do you know if there is an option for "unexplicit"?
Because in this case I don't want to specify
Regards thanks again

Kenneth Hobs
11-07-2012, 09:42 AM
Just don't add that line if you don't want to bother using Dim or setting variable types as Off is the default.

I can only recommend, it is up to you to decide whether you take my advice or not. Some others feel the same:
http://www.cpearson.com/excel/declaringvariables.aspx
http://effectivemsofficesolutions.com/VBA/VBABestPractices.html
http://www.fmsinc.com/free/NewTips/VBA/Option/index.html
http://www.fincad.com/pdfs/vba_coding.pdf

Setting Option Explicit Off and On:
http://msdn.microsoft.com/en-us/library/y9341s4f.aspx