# The following are pieces of code leading up to a simulation # mimicking TIAA-CREF's Equity Index fund. # Data is available from # http://www.tiaa-cref.org/performance/retirement/#crefvariableannuities # Using EXCEL, we found that the mean daily percent change was # 0.0354144% with a standard deviation of 0.010852361. We also found # that the average annualized return since inception is about 8%. # The following piece of code generates a sample of size 1 # from a normal random variable. X represents the random # variable - it's not a number, it's more like a function. # Y is an array of numbers sampled from X. Below, it is an array # of length 1 and we are pulling out the first (and only) entry with(Statistics): X := RandomVariable(Normal(0.000354144, 0.010852361)): Y := Sample(X, 1)[1]; # We want to simulate 3753 days worth of returns. The initial # price was $25.1713. We don't really need to keep track of # the daily price inbetween inception and yesterday so we won't # store anything until yesterday's price is reached via simulation. # Then we histogram the results. with(Statistics): X := RandomVariable(Normal(0.000354144, 0.010852361)): Ending_Value := Array(1..1000): for j from 1 to 1000 by 1 do P := 25.1713; for i from 1 to 3753 by 1 do Y := Sample(X, 1)[1]; P := P*(1 + Y); end do: Ending_Value[j] := P; end do: # Then we histogram the results. with(stats[statplots]): histogram(convert(Ending_Value, list)); # And store the results to a file. The results above took a little over # half and hour to create # REMEMBER: If you use code like this, you will have to change the path # to reflect your folders rather than mine. writedata("C://Users//Elizabeth Housworth//Desktop//StockMarketOutput.txt", convert(Ending_Value, list)); fclose("C://Users//Elizabeth Housworth//Desktop//StockMarketOutput.txt"); # we can also compute the average annualized returns and # histogram them and write them to a file Average_Returns := Array(1..1000): for j from 1 to 1000 by 1 do Average_Return[j] := ((Ending_Value[j]/25.1713)^(1/14.5) - 1); end do: with(stats[statplots]): histogram(convert(Average_Return, list)); writedata("C://Users//Elizabeth Housworth//Desktop//StockMarketOutput2.txt", convert(Average_Return, list)); fclose("C://Users//Elizabeth Housworth//Desktop//StockMarketOutput2.txt");