http://demonstrations.wolfram.com/MaximizingABermudanPutWithTwoEarlyExerciseTemporalPoints/
右侧 有一个preview 我打开preview后 看到的是图片 但是上面有代码 我把计算部分的代码(不包括 搭建图形的代码 )自己手写复制了遍 ,令T S0 X r等变量不同值,发现总是运行不出结果。求各位大侠帮忙。代码如下
T = 0.5;
S0 = 100;
X = 90;
r = 0.03;
div = 0.00;
sig = 0.2;
a = 0.2
d1[y_, z_] := (Log[S0/y] + (r - div + sig sig/2) z)/(sig*Sqrt[z]);
d2[y_, z_] := d1[y, z] - sig Sqrt[z];
p3[x1_, x2_, t1_, t2_] :=
X (Exp[-r t1] CDF[NormalDistribution[], -d2[x1, t1]] +
Exp[-r t2] CDF[MultinormalDistribution[{0, 0},
{{1, -Sqrt[t1/t2]}, {-Sqrt[t1/t2], 1}}], {d2[x1,
t1], -d2[x2, t2]}] +
Exp[-r*T] CDF[MultinormalDistribution[{0, 0, 0},
{{1, Sqrt[t1/t2], -Sqrt[t1/T]}, {Sqrt[t1/t2], 1, -Sqrt[t2/T]},
{-Sqrt[t1/T], -Sqrt[t2/T], 1}}], {d2[x1, t1],
d2[x2, t2], -d2[X, T]}]) -
S0 (Exp[-div t1 ] CDF[NormalDistribution[], -d1[x1, t1]] +
Exp[-div t2] CDF[MultinormalDistribution[{0, 0},
{{1, -Sqrt[t1/t2]}, {-Sqrt[t1/t2], 1}}], {d1[x1,
t1], -d1[x2, t2]}] +
Exp[-div*T] CDF[MultinormalDistribution[{0, 0, 0},
{{1, Sqrt[t1/t2], -Sqrt[t1/T]}, {Sqrt[t1/t2], 1, -Sqrt[t2/T]},
{-Sqrt[t1/T], -Sqrt[t2/T], 1}}], {d1[x1, t1],
d1[x2, t2], -d1[X, T]}]);
cr0 = FinancialDerivative[{"American", "Put"}, {"StrikePrice" -> X,
"Expiration" -> T},
{"InterestRate" -> r, "Volatility" -> sig, "CurrentPrice" -> S0,
"Dividend" -> div},
"CriticalValue", "GridSize" -> {10000, Automatic}];
p = Reap[FindMaximum[{p3[x1, x2, t1, t2], cr0 < x1 < x2 < X,
0 < t1 < t2 < T},
{{x1, cr0}, {x2, X}, {t1, a*T}, {t2, (1 - a) T}},
PrecisionGoal -> 20,
AccuracyGoal -> 5, StepMonitor -> Sow[{t1, t2}]]];
p3max = p[[1, 1]]
scr1 = p[[1, 2, 1, 2]]
scr2 = p[[1, 2, 2, 2]]
tscr1 = p[[1, 2, 3, 2]]
tscr2 = p[[1, 2, 4, 2]]
右侧 有一个preview 我打开preview后 看到的是图片 但是上面有代码 我把计算部分的代码(不包括 搭建图形的代码 )自己手写复制了遍 ,令T S0 X r等变量不同值,发现总是运行不出结果。求各位大侠帮忙。代码如下
T = 0.5;
S0 = 100;
X = 90;
r = 0.03;
div = 0.00;
sig = 0.2;
a = 0.2
d1[y_, z_] := (Log[S0/y] + (r - div + sig sig/2) z)/(sig*Sqrt[z]);
d2[y_, z_] := d1[y, z] - sig Sqrt[z];
p3[x1_, x2_, t1_, t2_] :=
X (Exp[-r t1] CDF[NormalDistribution[], -d2[x1, t1]] +
Exp[-r t2] CDF[MultinormalDistribution[{0, 0},
{{1, -Sqrt[t1/t2]}, {-Sqrt[t1/t2], 1}}], {d2[x1,
t1], -d2[x2, t2]}] +
Exp[-r*T] CDF[MultinormalDistribution[{0, 0, 0},
{{1, Sqrt[t1/t2], -Sqrt[t1/T]}, {Sqrt[t1/t2], 1, -Sqrt[t2/T]},
{-Sqrt[t1/T], -Sqrt[t2/T], 1}}], {d2[x1, t1],
d2[x2, t2], -d2[X, T]}]) -
S0 (Exp[-div t1 ] CDF[NormalDistribution[], -d1[x1, t1]] +
Exp[-div t2] CDF[MultinormalDistribution[{0, 0},
{{1, -Sqrt[t1/t2]}, {-Sqrt[t1/t2], 1}}], {d1[x1,
t1], -d1[x2, t2]}] +
Exp[-div*T] CDF[MultinormalDistribution[{0, 0, 0},
{{1, Sqrt[t1/t2], -Sqrt[t1/T]}, {Sqrt[t1/t2], 1, -Sqrt[t2/T]},
{-Sqrt[t1/T], -Sqrt[t2/T], 1}}], {d1[x1, t1],
d1[x2, t2], -d1[X, T]}]);
cr0 = FinancialDerivative[{"American", "Put"}, {"StrikePrice" -> X,
"Expiration" -> T},
{"InterestRate" -> r, "Volatility" -> sig, "CurrentPrice" -> S0,
"Dividend" -> div},
"CriticalValue", "GridSize" -> {10000, Automatic}];
p = Reap[FindMaximum[{p3[x1, x2, t1, t2], cr0 < x1 < x2 < X,
0 < t1 < t2 < T},
{{x1, cr0}, {x2, X}, {t1, a*T}, {t2, (1 - a) T}},
PrecisionGoal -> 20,
AccuracyGoal -> 5, StepMonitor -> Sow[{t1, t2}]]];
p3max = p[[1, 1]]
scr1 = p[[1, 2, 1, 2]]
scr2 = p[[1, 2, 2, 2]]
tscr1 = p[[1, 2, 3, 2]]
tscr2 = p[[1, 2, 4, 2]]