Needs["Histograms`"];
Needs["StatisticalPlots`"];
Needs["LinearRegression`"];
Needs["StableM`"];
(*LNN and StableM are available on the Software Page*)
Needs["LNN`","C:\\Mathematica 6\\LogNormalStable\\LNN.m"];

Lognormally Scaled Normal Distribution

The lognormally scaled normal distribution is a normal mixture distribution in which the scale parameter is a random variable with a lognormal distribution.  The distribution properties are discussed and an example of maximum likelihood fitting is shown for financial logarithmic returns.  Mathematica code for and the maximum likelihood fit is contained in the downloadable notebook.

The idea of using a lognormally scaled stable distribution for market data arose while we were studying daily stock market volatility using the scale parameter, γ, of a stable distribution based on intra-day minute return data.  We noticed that the although γ showed a strong serial dependent structure on a day to day basis, a series of these parameters were well fit by the lognormal distribution.  It also appeared that the daily volume traded for the security was directly proportional to this parameter for daily data observed between July 2007 and June 2008.  Figure 1 shows a plot of this relationship for the exchange traded fund, SPY, with volume on the same scale as the γ parameter.  Fits of the calculated scale parameter to a lognormal distribution and a gamma distribution for 45 securities traded in U.S. showed that the lognormal fit was superior to the gamma distribution fit for this data.  In all cases quantile-quantile (Q-Q) plots showed the lognormal fit to be quite good.  Figure 2 shows the Q-Q plot for the γ scale factor for the data displayed in the first figure.

symbol="SPY";
data=Uncompress[Import["http://www.mathestate.com/tools/Financial/data/spy.dat","Text"]];
LogReturn[data_]:=Differences[Log[N[data]]];
lri=LogReturn[data[[All,5]]];
dtt=Rest[data[[All,1]]];
dtlr=Transpose[{dtt,lri}];
day=Union[Take[#,3]&/@dtt];
SelFn=Function[{dw},Select[dtlr,#[[1]][[;;3]]==dw&]];
lrp=SelFn[#][[All,2]]&/@day;
scl=QkScale/@lrp;
vol= FinancialData[symbol,"Volume",{First[day],Last[day]}];

vol=FinancialData["SPY","Volume",{First[day],Last[day]}];
vold=Log[N[vol[[All,2]]]];

vold1=Regress[vold,t,t,RegressionReport->{FitResiduals}][[1]][[2]];
scllri=QkScale[lri];
CellPrint[TextCell["Figure 1","Text",FontSize->14]];
DateListPlot[{Transpose[{day,scl}],Transpose[{vol[[All,1]],Exp[vold1] scllri}]},Joined->True,Frame-> True,PlotLabel-> "SPY Stable γ - Blue\nScaled Volume - Red",PlotRange->All]

Figure 1

mnscl=Mean[Log[scl]];
sdscl=StandardDeviation[Log[scl]];
CellPrint[TextCell["Figure 2","Text",FontSize->14]];
QuantilePlot[RandomReal[LogNormalDistribution[mnscl,sdscl],1000000],scl,Frame->True,PlotLabel->"Q-Q Plot\nLognormal Fit to Daily Stable γ",FrameLabel-> {"Theoretical"," Empirical "}]

Figure 2

We constructed the mixture distribution originally to scale a stable distribution but found that the fit to a stable distribution with the shape parameter, α = 2 (the normal distribution) was excellent.  We retained the notation from stable distributions, for the normal distribution part of the mixture, because the scale parameter, γ, behaves in a more natural way and the scaling will also be consistent with other stable distributions.  This parameterization of the normal distribution has a characteristic function shown in equation (1).

ϕ(t,γ,δ)=(e^(i t δ-(γ^2)  (t^2)))

In this parameterization, δ is equivalent to μ in the standard normal distribution and the usual σ is equivalent to (Sqrt[2]) γ.  At the point on the function, t = 1 and γ = 1, the absolute value of the characteristic function is always equal to (1/e).  We use this fact to estimate the value of γ using the empirical characteristic function by rescaling t.  This estimate also works for any stable distribution.  The Mathematica algorithm is given on the CFFit page.  In this representation δ remains the expectation of the distribution.  The normal density function f(x, γ, δ) in this parameterization scales by γ and shifts by δ, in the same natural way that the parameters σ and μ do in the normal distribution.

f(x,γ,δ)=((e^(-((((x-δ))^2)/(4 (γ^2)))))/(2 (Sqrt[π]) γ))

The lognormal density λ(x, μ, σ) is shown below.  For our mixture distribution we substitute log(γ) for μ.

λ(x,μ,σ)=((e^(-((((log(x)-μ))^2)/(2 (σ^2)))))/((Sqrt[2 π]) x σ))

The density function, lnnf, of the mixture distribution is obtained by integration where the integration parameter, s, represents the scale parameter, γ, as a random variable.

lnnf(x,γ,σ,δ)=(∫_0^∞)f(x,s,δ)  λ(s,log(γ),σ)ds

The final result gives us a three parameter distribution that will still shift and scale in a natural way.

lnnf(x,γ,σ,δ)=((lnnf(((x-δ)/γ),1,σ,0))/γ)

Figure 3 shows a plot of the standardized lnnf(x, 1, σ, 0) in three dimensions.  We have made an interpolation of this standardized plot to rapidly calculate the lnnf density for maximum likelihood fitting of all the parameters.  The distribution would be defective at σ = 0, but it can be defined as the base normal distribution at this point.  Simulation of the distribution is simple as it is simply the product of an appropriately scaled normal and a lognormal random variable.  The distribution function is obtained similarly to the lnnf, by replacing f(x, γ, σ, δ) in equation (4) with the parameter adjusted normal distribution function.  The integrals can be computed numerically.

CellPrint[TextCell["Figure 3", "Text", FontSize -> 14]];
Plot3D[LNNQkPDF[x,1,ss,0],{x,-5,5},{ss,0,1},AxesLabel->{"x","σ","   density"},PlotLabel-> "Lognormal Normal Distribution"]

Figure 3

Figure 4 shows the histogram and lognormal normal density fit to ten years of daily logarithmic returns from the exchange traded fund, SPY.  The parameters shown are the maximum likelihood parameter estimates using the interpolated function shown in Figure 3.

ticker="SPY";
data=FinancialData[ticker,"Close",Take[DateList[],3]-{10,0,0}];
lr= LogReturn[data[[All,2]]];
pp=LNNFit[lr];
ps=SFit[lr];
g1=Histogram[lr,HistogramScale->1];
g2=Plot[{LNNPDF[x,pp[[1]],pp[[2]],pp[[3]]],SPDF[x,ps]},{x,Min[lr],Max[lr]},PlotStyle->{{Darker[Red],Thickness[0.005]},{Darker[Blue],Thickness[0.005]}},PlotRange->All];
CellPrint[TextCell["Figure 4", "Text", FontSize -> 14]];
CellPrint[TextCell["Parameters {γ, σ, δ} = "<>ToString[pp], "Text"]];
CellPrint[TextCell["Stable Parameters {α, β, γ, δ} = "<>ToString[ps], "Text"]];
Show[g1,g2,Frame->True,PlotLabel-> "SPY - Ten Years Daily Log Returns\nLognormal Normal Fit - Red\nStable Fit -Blue"]

Figure 4

Parameters {γ, σ, δ} = {0.00684701, 0.454287, 0.000406056}

Stable Parameters {α, β, γ, δ} = {1.69558, -0.173265, 0.00686641, -0.000137597}

The distribution is symmetric and thus will not characterize any skewness in the data, but the Q-Q plot (Figure 5) shows that the fit is surprisingly good, especially in the tails where most attempts to fit financial market data do poorly.  When we do the parameter fitting, it is important to have starting points for the estimates.  The mean of the data gives a suitable estimate of δ.  The QkScale routine in the LNN software package provides an estimate of the scale parameter of a stable distribution to the data.  The scale factor obtained by this method will be close to the maximum likelihood estimated scale factor and the estimate will also be very close to the estimate provided by a stable distribution fit to the data.  Attempts to estimate γ from the standard deviation of the returns divided by (Sqrt[2 ]) will fail, because extreme returns from the heavy tailed data distort the estimate.

CellPrint[TextCell["Figure 5", "Text", FontSize -> 14]];QuantilePlot[LNNRV[100000,pp[[1]],pp[[2]],pp[[3]]],lr,Frame -> True, FrameLabel -> {"Theoretical ", 
  "Empirical "}, PlotLabel -> "QQ Plot Lognormal Normal Fit"]

Figure 5

A good starting point for the estimate of σ is about 0.5.  To achieve convergence, it may be necessary to estimate σ first with the other parameters fixed with the initial guesses.  The estimate of σ obtained by this method will then be a starting point to estimate the three parameters simultaneously.  If our theory is correct that a varying scale parameter is a measure of volatility and that volatility is lognormally fit, then σ gives us some information about the shape of the volatility distribution of the data that we have fit.  Thus all three parameters have meaning in terms of market behavior.

δ is the expectation of the distribution, estimated by its mean.

γ is the geometric mean of a scaling random variable.

σ is shape parameter of the distribution of a scaling random variable, a volatility measure.

Log[γ] and σ are the parameters of a lognormal distribution that tells something about the volatility of the security.  Figure 6 shows this plot of the distribution of γ, giving us an idea of how the scale factor might vary on a daily basis.

CellPrint[TextCell["Figure 6", "Text", FontSize -> 14]];Plot[PDF[LogNormalDistribution[Log[pp[[1]]],pp[[2]]],x],{x,0,0.03},PlotRange->All,Frame->True,FrameLabel->{"Scale",None},PlotLabel-> "LogNormalDsitribution[Log[γ], σ]\nγ = "<>ToString[pp[[1]]]"\nσ = "<>ToString[pp[[2]]]]

Figure 6

We are continuing to work on extending the distribution to the full range of stable distributions, but computation is much more difficult than for the normal case.  We were surprised by the quality of the fits of market return data to the lognormal normal mixture, especially at the tails, and thought that others might want to try this distribution.

txcolor=RGBColor[181/255,18/255,27/255];
t1 = Graphics[Text[Hyperlink[Framed[Style["Financial Home", {txcolor, Bold, Larger}]], "../map/Overview.html"], {-5, 0}]];
t2 = Graphics[Text[Hyperlink[Framed[Style["Next", {txcolor, Bold, Larger}]],  "../lnn1/LNNRisk.html"], {0, -0.5}]];
t3 = Graphics[Text[Hyperlink[Framed[Style["Download Notebook", {txcolor, Bold, Larger}]], "../lnn0/LognormalNormal.nb"], {5, 0}]];
t4 = Graphics[Text[Hyperlink[Framed[Style["Previous", {txcolor, Bold, Larger}]], "../s11/LNSProperties.html"], {0, 0.5}]];

Show[ t1, t2, t3,t4, ImageSize -> 500]
CellPrint[TextCell["\n\n© Copyright " <>ToString[DateList[][[1]]]<>" mathestate    "<>DateString[DateList[],"DateShort"], "Text"]]

© Copyright 2008 mathestate    Sun 9 Nov 2008