在绘制用户定义的函数时,Mathematica Plot3D不生成绘图?

时间:2012-03-18 18:00:01

标签: wolfram-mathematica finance

我正在编写一个简单的Mathematica实现black-scholes模型,并使用Plot3D绘制定价表面。但是,当我运行此代码时,不会生成任何绘图。我的callput函数在单独运行时生成正确的值,但不生成绘图。代码:

Clear[d1, d2, call, put, stockPrice, strikePrice, riskFreeRate, timeToExp, volatility]

d1[stockPrice_, strikePrice_, riskFreeRate_, timeToExp_, volatility_] := (Log[stockPrice / strikePrice] + (riskFreeRate + 0.5*volatility^2)*timeToExp) / (volatility * Sqrt[timeToExp])

d2[stockPrice_, strikePrice_, riskFreeRate_, timeToExp_, volatility_] := d1[stockPrice, strikePrice, riskFreeRate, timeToExp, volatility] - volatility*Sqrt[timeToExp]

call[stockPrice_, strikePrice_, riskFreeRate_, timeToExp_, 
  volatility_] := stockPrice * CDF[NormalDistribution[0, 1], d1[stockPrice, strikePrice, riskFreeRate, timeToExp, volatility]] - strikePrice * Exp[-riskFreeRate*timeToExp] *CDF[NormalDistribution[0, 1], d2[stockPrice, strikePrice, riskFreeRate, timeToExp, volatility]]

Plot3D[call[stockPrice, 500, 0.0030, timeToExp, 0.39], {stockPrice, 
  10, 1000}, {timeToExp, 0.0833333, 5}]

其他情节,如参考样本中的样本,确实有效。

Plot3D[{x^2 + y^2, -x^2 - y^2}, {x, -2, 2}, {y, -2, 2}, 
 RegionFunction -> Function[{x, y, z}, x^2 + y^2 <= 4], 
 BoxRatios -> Automatic]

1 个答案:

答案 0 :(得分:1)

您在绘图范围的规范中只有timeToExp call[]timetoExp(小写t)。