Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Loop doesn't work' topicStudent Support Forum > General > "Loop doesn't work"

Next Comment >Help | Reply To Topic
Author Comment/Response
Student0002012
12/22/12 07:46am

[superset of http://forums.wolfram.com/student-support/topics/180541 ?? -FM]


Hello again,
im very sorry, if you already get my question, but i have some internet issues and i don't know if the page get my request.

jf helped me a lot with his answers.

It's just one problem left (all details in the mathematica .nb)

If i want to shorten the computation part with the mathematica function Do[] then mathematica just uses one solution for the Count[{Table[pension, {100}....
but mathematica should calculate 100 "pensions" and then count it

Thank you in advance! And sorry that i have to bother you again.


Code:
Short-Version doesn't work:
pension = 1000000; Risky = 0.6; Riskless = 0.4; riskfree = 0.04; mu = \
0.12; sigma = 0.3; draw = 150000;
Do[pension =
pension*(Risky*
Exp[mu + sigma*RandomReal[NormalDistribution[0, 1]]] +
Riskless*Exp[riskfree]) - draw, {10}]
Print[pension]
Count[{Table[pension, {100}]}, _?NonNegative, 2]/100 // N

Long-Version Works:
Pension = 1000000; Risky = 0.6; Riskless = 0.4; riskfree = 0.04; mu = \
0.12; sigma = 0.3; draw = 150000;
year1 := Pension*(Risky*
Exp[mu + sigma*RandomReal[NormalDistribution[0, 1]]] +
Riskless*Exp[riskfree]) - draw;
year2 := year1*(Risky*
Exp[mu + sigma*RandomReal[NormalDistribution[0, 1]]] +
Riskless*Exp[riskfree]) - draw;
year3 := year2*(Risky*
Exp[mu + sigma*RandomReal[NormalDistribution[0, 1]]] +
Riskless*Exp[riskfree]) - draw;
year4 := year3*(Risky*
Exp[mu + sigma*RandomReal[NormalDistribution[0, 1]]] +
Riskless*Exp[riskfree]) - draw;
year5 := year4*(Risky*
Exp[mu + sigma*RandomReal[NormalDistribution[0, 1]]] +
Riskless*Exp[riskfree]) - draw;
year6 := year5*(Risky*
Exp[mu + sigma*RandomReal[NormalDistribution[0, 1]]] +
Riskless*Exp[riskfree]) - draw;
year7 := year6*(Risky*
Exp[mu + sigma*RandomReal[NormalDistribution[0, 1]]] +
Riskless*Exp[riskfree]) - draw;
year8 := year7*(Risky*
Exp[mu + sigma*RandomReal[NormalDistribution[0, 1]]] +
Riskless*Exp[riskfree]) - draw;
year9 := year8*(Risky*
Exp[mu + sigma*RandomReal[NormalDistribution[0, 1]]] +
Riskless*Exp[riskfree]) - draw;
year10 :=
year9*(Risky*Exp[mu + sigma*RandomReal[NormalDistribution[0, 1]]] +
Riskless*Exp[riskfree]) - draw;
Count[{Table[year10, {100}]}, _?NonNegative, 2]/100 // N




Attachment: basic-new.nb, URL: ,

Subject (listing for 'Loop doesn't work')
Author Date Posted
Loop doesn't work Student0002012 12/22/12 07:46am
Re: Loop doesn't work Student0002012 12/22/12 10:15pm
Re: Loop doesn't work Bill Simpson 12/22/12 10:55pm
Next Comment >Help | Reply To Topic