| Author |
Comment/Response |
yehuda
|
12/28/12 4:05pm
In Response To 'Loop doesn't work' --------- This is rather simple matter.
In the first case Pension was not effected by the calculation so all started from the same initial value of 1,000,000
In the second case you wrote pension = pension... inside the Do loop. It does not effect the first round but the remaining 99 values are each start from a different initial value (which is the final value if the first iteration)
This code changes that, and also avoids Do loop (use Nest)
yehuda
pension = 1000000;
Risky = 0.6;
Riskless = 0.4;
riskfree = 0.04;
mu = 0.12;
sigma = 0.3;
draw = 150000;
temp := Nest[#*(Risky*
Exp[mu + sigma*RandomVariate[NormalDistribution[]]] +
Riskless*Exp[riskfree]) - draw &, pension, 10];
Count[{Table[temp, {100}]}, _?NonNegative, 2]/100.0
URL: , |
|