returning a value - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# returning a value

Posts: 71Member
i have this code to return a value, but the value returned is not a recognisable number...here is my code, could u see whether i have made any mistakes and u could explain why my code is not returning a numeric value

Code:

Function OptionValue(Asset As Double, Strike As Double, Expiry As Double, Volatility As Double, Intrate As Double, param As Integer, NoAssetSteps)

Dim Vold(0 To 100) As Double
Dim VNew(0 To 100) As Double
Dim Delta(0 To 100) As Double
Dim Gamma(0 To 100) As Double
Dim Theta(0 To 100) As Double
Dim S(0 To 100) As Double
Dim Ssqd(0 To 100) As Double

halfvolsqd = 0.5 * Volatility * Volatility
AssetStep = 2 * Strike / NoAssetSteps
NearesyGridPt = Int(Asset / AssetSteps)
dummy = (AssetStep - NearestGridPt * AssetStep) / AssetStep
Timestep = AssetStep * AssetStep / Volatility / _
Volatility / (4 * Strike * Strike)
NoTimes = Int(Expiry / Timestep) + 1
Timestep = Expiry / NoTimesteps
For i = 0 To NoAssetSteps
S(i) = i * AssetStep
Ssqd(i) = S(i) * S(i)
Vold(i) = Application.Max(S(i) - Strike, 0)

Next i

For j = 1 To NoTimesteps
For i = 1 To NoAssetSteps - 1
Delta(i) = (Vold(i + 1) - Vold(i - 1)) / _
(2 * AssetStep)
Gamma(i) = (Vold(i + 1) - 2 * Vold(i) _
+ Vold(i - 1)) / (AssetStep * AssetStep)
VNew(i) = Vold(i) + Timestep * (halfvolsqd * _
Ssqd(i) * Gamma(i) + Intrate * S(i) * _
Delta(i) - InRate * Vold(i))

Next i
VNew(0) = 0
VNew(NoAssetSteps) = 2 * _
VNew(NoAssetSteps - 1) _
- VNew(NoAssetSteps - 2)

For i = 0 To NoAssetSteps
Theta(i) = (Vold(i) - VNew(i)) / Timestep
Vold(i) = VNew(i)

Next i
Next j

For i = 1 To NoAssetSteps - 1
Delta(i) = (Vold(i + 1) - Vold(i - 1)) / _
(2 * AssetStep)

Gamma(i) = (Vold(i + 1) - 2 * Vold(i) + _
Vold(i - 1)) / (AssetStep * AssetStep)

Next i
If param = 0 Then OptionValue = (1 - dummy) * Vold(NearestGridPt) + dummy * Vold(NearestGridPt + 1)

End Function