Stocks, volatility, and diversification

(Sethna, “Entropy, Order Parameters, and Complexity”, ex. 2.11)

Read in the file of Standard and Poor’s average stock price (SP) in constant dollars (corrected for inflation), versus time t. You’ll need to change directories to the directory where the file is located.

SetDirectory["/Users/sethna/Teaching/6562/Mathematica"];
SPvsT = Import["SandPConstantDollars.dat", "Table"]

Plot SP versus t
Note 9/11/01 is day 6903: is it the cause for the post-2000 drop?”
Zoom in and see: did the terrorist attach on the World Trade Center trigger the stock market downturn, or was it just a small extra dip in an overall pattern?

ListPlot[..., Joined->True]

ListPlot[..., PlotRange->{{...,...}, {540,680}}]

Define a function P[lag] giving the percentage change after a ‘lag’ of trading days.

percentChange[tradingDay_, lag_] := ... (SPvsT[[tradingDay+lag,2]]/ ... - ...)

P[lag_] := Table[percentChange[...],{tradingDay, Length[SPvsT]-lag}]

Plot a normed histogram using bins of size 0.5 for daily, weekly, and yearly percentage changes.
Which of the three represents a reasonable time to stay invested in the Standard and Poor’s index (during which you have a mean percentage growth larger than a tiny fraction of the fluctuations)? Why do the yearly changes look so much more complicated than the other distributions?

Histogram[{P[252],...}, {0.5}, "ProbabilityDensity", PlotRange->All]

Some of the distributions you found above should look quite Gaussian, as predicted from our Green’s function analysis of random walks (or more generally, to the central limit theorem). Here the random walk is in the percentage return -- in the logarithm of the fractional price change. The logarithm of a Gaussian distribution is an inverted parabola. Do a log plot of the histogram of weekly price changes:

    Histogram[..., ScalingFunctions->{“Log”, “Linear”}]

Are there ‘fat tails’ (more large changes than predicted by the inverted parabola you would expect from a Gaussian)?

hist = Histogram[..., ScalingFunctions->"Log"]
σ = ...;
x0 = ...;
Show[hist, Plot[Log[(1/Sqrt[...) Exp[-(x-x0)^2/...]],{x,-7,7}]]

Make a table of the volatilities for each lag time using StandardDeviation. Plot volatility and volatility squared versus lag.

volatility = Table[StandardDeviation[...],{lag,1,100}];
ListPlot[...]
...