Stable Fit to Rescaled Data

This is an in depth look at a non-stationary model of a stable distribution with varying scale factor, which has serial dependence.

This notebook develops an approach to fitting distribution by adjusting the data.  In general modifying data is a bad idea, especially when the assumptions are not known to be true, so these methods are not recommended for fitting financial data.  The goal rather is to look at how well the idea performs, before pursuing other methods such as a mixture distribution.  The hypothesis is to consider the possibility that the underlying market distribution is a stable distribution with a scale factor, γ, which varies every day, and attempt to modify the data to standardize the scale.  The time-series is the same that is demonstrated in detail in MarketReturnDistribution.

data= FinancialData["SP500",All];
CellPrint[TextCell["Start ... "<>DateString[First[data][[1]],"Date"],"Text"]]
CellPrint[TextCell["End ... "<>DateString[Last[data][[1]],"Date"],"Text"]]
lp= Log[data[[All,2]]];
lr=Differences[lp];

Start ... Tuesday 3 January 1950

End ... Friday 25 October 2013

Below is a graph of the daily changes in log returns for the S&P 500 series since 1950.  Epochs of high and low volatility tend to cluster together.  The strategy is to use this dependent structure to determine the scale factor for the data in small blocks; in this case the time-series is divided into 63 market day or about 3 month blocks.

dt=Rest[data[[All,1]]];
DateListPlot[Transpose[{dt,lr}],Filling-> 0,FillingStyle-> Darker[Red],PlotStyle-> {Darker[Red],PointSize[0]},PlotRange->All,PlotLabel->"SP 500 Log Returns" ]

What is needed next is a reasonably accurate method to estimate the stable scale factor on a small sample.  There is a method based on the stable characteristic function which is independent of other parameters.  It is outlined below.

The stable characteristic function, ϕ, may be written in polar coordinate form, r (e^(i θ)).

ϕ(t)=(e^(-(γ^α) ((Abs[t])^α))) (e^(i (β sgn(t) (γ^α) tan(((π α)/2)) ((Abs[t])^α)+t δ)))

The absolute value of the characteristic function, |ϕ(t)|, the r factor, is the symmetric strictly stable characteristic function, where β = 0 and δ = 0.

(Abs[ϕ(t)])=(e^(-(γ^α) ((Abs[t])^α)))

The characteristic function can be approximated from a data sample, using the formula for the empirical characteristic function, ecf, where (Subscript[X, k]), {k ∈ {1, ..., n}, are the sample random variables.

ecf(t)=(1/n) (∑_(k=1)^n)(e^(i t (Subscript[X, k])))

Equation (2) offers the possibility of quickly approximating γ at the point t = 1, by scaling the set of random variables so that γ = 1 and the characteristic function at this point = (1/e).  Equation (4) may be solved numerically for γ.

(1/n)(Abs[(∑_(k=1)^n)(e^((i (Subscript[X, k]))/γ))])=(1/e)

The method is less accurate than maximum likelihood fitting, but the methods are comparably bad for small sample sizes.  The idea is that the method doesn’t have to be too precise, because the day to day variation in the magnitude of the log returns is large.

absecf0 = Compile[{t, {s, _Real, 1}}, Abs[Mean[Exp[I t s]]] - 1/E];
ABSECF0[t_?NumericQ, s_] := absecf0[t, s];

SScale[s_?VectorQ] := Module[{cc, c0, c1},
   c1 = MeanDeviation[s];
   (*generally this loop should not be entered*)
   While[absecf0[1/c1, s] < 0, c1 = 2 c1; Print["Upper Bound Loop"]];
   c0 = c1;
   While[absecf0[1/c0, s] > 0, c1 = c0; 
    c0 = c0/2];(*bracket solution from above*)
   cc /. FindRoot[ABSECF0[1/cc, s], {cc,  c0, c1}, Method -> "Brent"]
   ];
nn=63;(*Block size, market days*)
mnn=Mod[Length[lr],nn];
lrp=Partition[Drop[lr,mnn],nn];
dtm=Median/@Partition[AbsoluteTime/@Drop[dt,mnn],nn];
scl=SScale/@lrp;
p1=DateListPlot[Transpose[{dtm,scl}],Filling-> 0,FillingStyle-> Darker[Green],PlotStyle-> {Darker[Green],PointSize[0]},PlotRange->All,PlotLabel->"SP 500 Stable Scale Factor" ]

The variation in the method is also comparable to another method of measuring scale, the second L Moment.  The stable scale factor, γ, can be derived from the second L Moment, (Subscript[λ, 2]) by the following linear relationship.

(Subscript[λ, 2])=(((2^(1/α)) γ (Gamma[((α-1)/α)]))/π)

This relationship requires the assumption that the tail exponent, α, of the stable distribution remains stationary, but also can serve to substantiate the accuracy of the method, although neither method could be considered a gold standard for measuring the scale factor of a stable distribution over a small sample size.

LMoment=Statistics`Library`LMoment;
lmom=LMoment[#,2]&/@lrp;
p2=DateListPlot[Transpose[{dtm,lmom}],Filling-> 0,FillingStyle-> Darker[Green],PlotStyle-> {Darker[Green],PointSize[0]},PlotRange->All,PlotLabel->"SP 500 Second L Moment" ]

The graph below shows the linear regression between the two methods for determining a stable scale factor.

lmf=LinearModelFit[Transpose[{scl,lmom}],x,x];
fit=lmf["BestFitParameters"];
Show[ListPlot[Transpose[{scl,lmom}],PlotRange->All],Plot[lmf[x],{x,Min[scl],Max[scl]},PlotStyle->{Darker[Red],Thick}],Frame->True,FrameLabel-> {"γ","(Subscript[λ, 2])"},PlotLabel->"Linear Regression (Subscript[λ, 2]) as a function of γ"]

From the slope of the fit with the assumption that α is stationary, we can derive and estimate for α.

FindRoot[2^(1/α) Gamma[(α-1)/α]/Pi==fit[[2]],{α,1.5}]

The ANOVA table and the RSquared calculation from the linear regression are below.

lmf["ANOVATable"]

lmf["RSquared"];
CellPrint[TextCell["R Squared "<>ToString[lmf["RSquared"]],TextAlignment->Center]]

The graph below shows the rescaled returns, which were derived by dividing each block of returns by the estimated scale factor for that block.  This division should have the effect of bringing the scale factor, γ, of the adjusted returns to 1.0.

lr1=Flatten[lrp/scl];
DateListPlot[Transpose[{Drop[dt,mnn],Median[scl] lr1}],Filling-> 0,FillingStyle-> Darker[Blue],PlotStyle-> {Darker[Blue],PointSize[0]},PlotLabel->"SP 500 Rescaled Log Returns\nEstimated γ = "<>ToString[SScale[lr1]] ,PlotRange->All]

The autocorrelation functions of the absolute value of the raw returns and the absolute value of the rescaled returns shows that most of the serial dependence has been eliminated by the rescaling.

ListPlot[{CorrelationFunction[Abs[Median[scl] lr1],{500}],CorrelationFunction[Abs[Flatten[lrp]],{500}]},PlotStyle-> {Darker[Blue],Darker[Red]},Joined ->True,PlotLabel-> "Autocorrelation\nRaw Abs[Returns] - Red\nAbs[Rescaled Returns] - Blue",Frame->True]

The log log plot of the tail fit shows that a stable fit to the rescaled returns still has a heavier tail in the data, but the tails break away further out on each tail.

lr1=Flatten[lrp/scl];
ed=EmpiricalDistribution[lr1];
sd=EstimatedDistribution[lr1,StableDistribution[α,β,γ,δ]];
parm1={sd[[2]],sd[[3]],sd[[5]],sd[[4]]};
LogLogPlot[{CDF[ed,-x],1-CDF[ed,x],CDF[sd,-x],1-CDF[sd,x]},{x,0.01,Max[Abs[lr1]]},PlotRange->All,PlotStyle->{Darker[Blue],Darker[Red],Darker[Blue],Darker[Red]}, PerformanceGoal->"Speed",Frame->True,GridLines->Automatic,PlotLabel-> "Log Log Distribution Function\nStable Fit"]
CellPrint[TextCell["Stable Parameters, {α, β, γ, δ}: "<>ToString[parm1],TextAlignment->Center]]

It can be seen that the fit of the rescaled data is much better on the tails and α is considerably higher than the fit to the same data in the MarketReturnDistribution notebook.  Ultimately, however, rescaling the data does not change the extreme tail behavior of a data set.  The extreme tail is still lighter than the stable fit, with the fit tail breaking away from the data tails at the p = {0.004, 0.996} tail level, so a large central part of the distribution is better fit by a stable distribution.  

The charts below estimate the tail exponents for the rescaled log returns using the same method shown in MarketReturnDistribution notebook.  And α is still well above the stable regime.

n=Floor[0.01 Length[lr1]];
rt=Take[Sort[lr],-n];
qqp=QuantilePlot[Log[rt],ExponentialDistribution[1],Method->{"ReferenceLineMethod"->"Fit"},PlotRange->All,PlotLabel-> "Quantile Plot Log Right Tail Data vs. ExponentialDistribution[1]"]
eplog=Cases[Cases[qqp,Rule[Epilog,x_]-> x,∞],Line[xx_]->xx,∞];
#1/#2&@@@Differences[eplog[[1]]];
alpha=%[[1]];
lmf=LinearModelFit[Cases[qqp,Point[x_]->x,∞][[1]],t,t];
lmf["BestFitParameters"];
CellPrint[TextCell["Right Tail exponent, α = "<>ToString[1/%[[2]]],TextAlignment->Center]]
CellPrint[TextCell["",TextAlignment->Center]]
CellPrint[TextCell["Fit ANOVA Table",TextAlignment->Center]]
lmf["ANOVATable"]
CellPrint[TextCell["R Squared "<>ToString[lmf["RSquared"]],TextAlignment->Center]]

lt=-Take[Sort[lr1],n];
qqp=QuantilePlot[Log[lt],ExponentialDistribution[1],Method->{"ReferenceLineMethod"->"Fit"},PlotRange->All,PlotLabel-> "Quantile Plot Log Left Tail Data vs. ExponentialDistribution[1]"]
eplog=Cases[Cases[qqp,Rule[Epilog,x_]-> x,∞],Line[xx_]->xx,∞];
#1/#2&@@@Differences[eplog[[1]]];
alpha=%[[1]];
lmf=LinearModelFit[Cases[qqp,Point[x_]->x,∞][[1]],t,t];
lmf["BestFitParameters"];
CellPrint[TextCell["Left Tail exponent, α = "<>ToString[1/%[[2]]],TextAlignment->Center]]
CellPrint[TextCell["",TextAlignment->Center]]
CellPrint[TextCell["Fit ANOVA Table",TextAlignment->Center]]
lmf["ANOVATable"]
CellPrint[TextCell["R Squared "<>ToString[lmf["RSquared"]],TextAlignment->Center]]

What does all this mean?  Probably not very much, but it seems clear that rescaling the data does not eliminate distal power tail behavior which is lighter than supported by a stable distribution.  The theoretical implications are the most important.  Stable distributions evolve from the summation of identically distributed, independent random variables, which have a tail exponent, α < 2.  If α ≥ 2, the distribution should have finite variance and the generalized central limit theorem should eventually lead to a normal distribution behavior.  The rescaling method did seem to remove the serial dependent structure shown in the autocorrelation of absolute returns.  

Consequently the idea that price formation arises from the sums of many very small differences in price or log returns seems not to be probable as this index is currently derived from hundreds of millions of transactions daily.  Mathematica users may download the notebook and substitute the log return data for a set of stable random variables multiplied by a slowly varying scale function and demonstrate that the initial stable distribution parameters can indeed be recovered by the methods shown here.  

When intraday price data are examined closely a lot more structure is revealed; there is a serial dependent structure which evolves through the day with higher scale factor and volume per minute near the open and close of trading, compared with the transactions in the middle of the day.  Yet when the tail behavior of the intraday data is examined, it also shows a power tail structure with a tail exponent, α, greater than 2.

Financial Data Analysis Home

CellPrint[TextCell["\n\n© Copyright " <> ToString[DateList[][[1]]] <> " Robert H. Rimmer, Jr.    " <> DateString[DateList[], "DateShort"], "Text"]]

© Copyright 2013 Robert H. Rimmer, Jr.    Sun 27 Oct 2013