不工作一个VBA函数,这是一个简单的股票价格变动的代码 我的代码是函数(参数)运行按下按钮在EXCELL
Function VanillaCall(S0 As Single, Exercise As Single, Mean As Single, sigma As Single, _
Interest As Single, Time As Single, Divisions As Integer, Runs As Integer) As Single
deltat = Time/Divisions
interestdelta = Exp(Interest * deltat)
up = Exp(Mean * deltat + sigma * Sqr(deltat))
down = Exp(Mean * deltat - sigma * Sqr(deltat))
pathlength = Int(Time/deltat)
piup = (interestdelta - down)/(up - down)
pidown = 1 - piup
Temp = 0
For Index = 1 To Runs
upcounter = 0
For j = 1 To pathlength
If Rnd > pidown Then upcounter = upcounter + 1
Next j
callvalue = Application.Max(S0 * (up^upcounter) * (down^(pathlength - upcounter)) - Exercise, 0)/(interestdelta^pathlength)
Temp = Temp + callvalue
Next Index
VanillaCall = Temp/Runs
End Function
参数从细胞在Excel中通过。 我想从按钮单击执行此功能,并显示单元格返回值说b12。 我已经尝试把代码里面的按钮子,但它不工作,呼吁vanillacall子内太不工作。 如..
private sub button1_click()
call vanillacall
end sub
当您在button1_click()中调用函数vanillacall时,必须传递所有必要的参数。 – Mrig
我不认为这会起作用,因为您必须将'= VanillaCall()'放在单元格中并传递必要的参数。您可以通过从宏调用该函数来传递参数,但是您必须定义要在宏中输出结果的位置。 – newguy
但我的参数来自excell中的单元格,这些单元格在运行函数 – user2997767