confidence interval

58
FinM 331/Stat 339 Financial Data Analysis, Winter 2010 Floyd B. Hanson, Visiting Professor Email: [email protected] Master of Science in Financial Mathematics Program University of Chicago Lecture 5 6:30-9:30 pm, 01 February 2010, Ryerson 251 in Chicago 7:30-10:30 pm, 01 February 2010 2010 at UBS in Stamford 7:30-10:30 am, 02 February 2010 at Spring in Singapore FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page1 Floyd B. Hanson

Upload: mtoqeer

Post on 09-Nov-2015

30 views

Category:

Documents


1 download

DESCRIPTION

Statistics

TRANSCRIPT

  • FinM 331/Stat 339 Financial Data Analysis,

    Winter 2010

    Floyd B. Hanson, Visiting Professor

    Email: [email protected]

    Master of Science in Financial Mathematics ProgramUniversity of Chicago

    Lecture 56:30-9:30 pm, 01 February 2010, Ryerson 251 in Chicago

    7:30-10:30 pm, 01 February 2010 2010 at UBS in Stamford

    7:30-10:30 am, 02 February 2010 at Spring in Singapore

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page1 Floyd B. Hanson

  • 5. Regression and Maximum Likelihood Tools:5.1 Parametric Regression:a

    Parametric regression involves fitting to the sample data a smallnumber of parameters, e. g., mean and variance 2, while by contrastnonparametric regression involving fitting on more of the localproperties of the data with much data preparation to smooth fittedcurves. In addition, there are many flavors of parametric regression. Somedo not rely on random properties much, like the simple least squaresrelating a response data vector analogous to an dependent variable to amodel depending on a few predictors or regressors analogous toindependent variables and a few unknown parameters or coefficientsthat are to be estimated. Other regression methods, such as maximumlikelihood estimation, as the name implies, rely on more probabilisticmethods, but then so do stochastic models in finance.

    aSee Rice (2007) Chapt. 14 or Carmona (2004) Chapt. 3 for more information or Weis-berg (2005) Chapts. 1-4 for even more details on both statistical and computational errors.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page2 Floyd B. Hanson

  • 5.2 Ordinary or Simple Least Squares Regression forUnivariate Linear Models:Given a sample of n observations of responses ~Y = [Yi]n1 that appearto satisfy a nearly linear relationship with respect to the same size sampleof observations ~X = [Xi]n1 called predictors or regressors. Thenearly linear relationship could be suggested by plotting ~Y against ~Xby using MATLABs scatter(Y,X); scatter plot function andeyeballing the plotted points. Least squares suggests that our cost functionbe the square the deviations from the linear model y=(x)b+mx,wherem is the slope and b is the intercept and minimize or find the leastvalue of the sum of the squares of the deviation of the data from thestraight line, i.e., our objective is the quadratic cost function,

    L2(b,m) =ni=1

    (Yi bmXi)2. (5.1)The observations will not likely satisfy the model (x), instead there willbe an error Yi=b+mXi+ei or eiYibmXi andL2(b,m) =

    ni=1 e

    2i = (n 1)2e .

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page3 Floyd B. Hanson

  • Alternatively, the sum of the absolute deviations,

    L1(m, b) =ni=1

    |Yi m Xi b|, (5.2)

    but the cost model does not have such nice and justifiable properties.

    The minimum can be found by searching for the critical points withrespect to the unknown parameter set (b,m), soL2b

    (m, b)=2ni=1

    (YimXi b)=2n(Y mXb) =0,(5.3)

    yielding the implicit optimal intercept estimation,b = b = Y m X , where (X,Y ) is the usual sample mean vectorof the coordinates. Next,

    L2m

    (m, b)=2ni=1(YimXib)Xi=2n(XY mX2bX) =0,

    (5.4)

    yielding the least squares solution,

    m = m =XY X YX2 (X)2 =

    x,y

    2xif 2x > 0. (5.5)

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page4 Floyd B. Hanson

  • Hence, the estimated slope m is given as the ratio of the data samplecovariance to the variance of the predictor ~X , both being biased orunbiased quadratic moments. However, this estimated slope formulahas possibly small differences in numerator and denominator, so itscomputation should be handled with care due to CatastrophicCancellations. These are cancellations where significant digits are lostin subtractions.

    The estimated intercept b is usually calculated once the estimated slopem is calculated since it serves no numerical purpose to eliminate the slopefrom the intercept formula, but could lead to a less precise calculation.

    The observation error ~e between observed residual using the modelcomes with statistical conditions: E[~e ] = ~0 since otherwise there will bebias so any non-zero value should be in the model and not in the noise andCov[~e, ~e>] = 2eIn for constant sigma e or else will interferewith the least squares fit.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page5 Floyd B. Hanson

  • The quality of the linear regression is just by how close the notedcoefficient of determinationR2 value is to one and is defined byformula,

    R2 1 SSETSS

    = 1 (n 2)2e

    (n 1)2y, (5.6)

    {Almost Total Correction!},where theSSE = RSS

    ni=1

    (Yi Yi)2 ni=1

    e2i = (n 2)2e (5.7)

    is the sum of squared errors (SSE) or residual sum of squares (RSS),with YimXi+b is the ith estimated response, with the 2 less degreesof freedom due to parameters accounting for the factor n2. The

    TSS ni=1

    (Yi Y )2 = (n 1)2y (5.8)

    is the total sum of squares (TSS) of the deviation.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page6 Floyd B. Hanson

  • Linear Regression Translation to Linear Algebra & MATLAB:Translating the linear regression to matrix-vector form, combine theparameters into a parameter vector be ~p=[b,m]>, then the independentvariable (n1) ~X is extended to the (n2)-matrixA=[ones(n, 1), ~X], so that the usual linear algebraic equationA ~x = ~b is equivalent to the formA~p= ~Y with the correspondence~b= ~Y is the known RHS and ~x=~p is the unknown. Th linear regression,least squares problem is the find the minimum of the scalar quadraticform:S(~x)

    (A~x~b

    )>(A~x~b

    )=~x>A>A~x2~x>A>~b+~b>~b, (5.9)

    after transpose algebra ((AB)>=B>A>). Since if ~V is a fixed, thenx[~x>~V ]=x[~V >~x]= ~V (5.10)

    andx[S](~x)=2

    (A>A~xA>~b

    ) = ~0, (5.11)at a critical point ~x if it exists, where the least squares solution is

    ~p=~x=(A>A

    )1A>~b. (5.12)

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page7 Floyd B. Hanson

  • Ordinary Least Squares for Simple Linear Fit Example:

    0 0.2 0.4 0.6 0.8 10.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    1.2

    1.4

    1.6

    Ordinary Least Square Linear Example:

    x

    y

    scatter plot True y=m+bx lscov fit backslash fit

    Figure 5.1: Ordinary least squares fit using indistinguishable MATLABlscov and A\b backslashmethods, with similar results for a simple,straight line fit with scatterplot data.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page8 Floyd B. Hanson

  • MATLAB Code for Simple Ordinary Least Squares Application:function LStest

    clc

    fprintf(\nLStest Output (%s):,datestr(now));m = 1; b = 0.25; % True parm values;

    fprintf(\nTrue: b = %7.4f; m = %7.4f;,b,m);

    ptrue = [b;m];n = 100;

    x = rand(n,1); % Simulated Uniform x-data;

    sigma_e = 0.25;

    err = 0.25*randn(n,1); % Simulated Normal Mean-Zero Error;fprintf(\nsigma_e = %7.4f;,sigma_e);

    y = b+m*x+err; % Simulated y-data with linear model;

    TSS = (n-1)*var(y);fprintf(\nTSS = %9.3e,TSS);

    A = [ones(n,1) x];

    fprintf(\nsize(A)=[%i,%i]; size(y)=[%i,%i];,size(A),size(y));[preg,sep,mse] = lscov(A,y); % Least Sqs Method, No Cov input

    pbsl = A\y; % BackSlash (BS) Method (fast);

    breg = preg(1); mreg = preg(2);yhatreg = breg+mreg*x;

    yhatbsl = pbsl(1)+pbsl(2)*x;

    SSEreg = sum((y-yhatreg).2); % Also, RSS=ResSumSqs

    SSEbsl = sum((y-yhatbsl).2);

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page9 Floyd B. Hanson

  • fprintf(\nRSS=SSEreg = %9.3e; SSEbsl = %9.3e;,SSEreg,SSEbsl);

    fprintf(\nRelResreg = %9.3e;,sqrt(norm(y-yhatreg)/norm(y)));

    fprintf(\nRelResbsl = %9.3e;,sqrt(norm(y-yhatbsl)/norm(y)));

    Rsqreg = 1-SSEreg/TSS; Rsqbsl = 1-SSEbsl/TSS;

    fprintf(\nRsqreg = %9.3e; Rsqbsl = %9.3e;,Rsqreg,Rsqbsl);

    fprintf(\nTrue: b =%7.4f; m =%7.4f;,b,m);

    fprintf(\nlscov: b = %7.4f; m = %7.4f;,breg,mreg);

    fprintf(\nbkslh: b = %7.4f; m = %7.4f;,pbsl(1),pbsl(2));

    fprintf(\nsqrt(norm(preg-ptrue)/norm(ptrue)) =%7.4f; ...

    ,sqrt(norm(preg-ptrue)/norm(ptrue)));

    fprintf(\nsqrt(norm(pbsl-ptrue)/norm(ptrue)) =%7.4f; ...

    ,sqrt(norm(pbsl-ptrue)/norm(ptrue)));

    fprintf(\nsqrt(norm(preg-pbsl)/norm(pbsl)) =%7.4f; ...

    ,sqrt(norm(preg-pbsl)/norm(pbsl)));

    fprintf(\nlscov: sep = [%9.3e,%9.3e];,sep);

    fprintf(\nlscov: mse = %9.3e;,mse); % Caution: different scaling

    xg = 0:0.1:1;

    ytrue = b+m*xg;

    yhatregp = breg+mreg*xg;

    yhatbslp = pbsl(1)+pbsl(2)*xg;

    %

    figure(1); nfig = 1;

    scrsize = get(0,ScreenSize); % figure spacing for target screen

    ss = [5.0,4.5,4.0,3.5]; % figure spacing factors

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page10 Floyd B. Hanson

  • scatter(x,y,8); hold on;

    plot(xg,ytrue,-g,xg,yhatregp,-.k,xg,yhatbslp,--r,LineWidth,2);

    axis tight; hold off;title(Ordinary Least Square Linear Example:...

    ,Fontsize,24,FontWeight,Bold);

    xlabel(x,Fontsize,24,FontWeight,Bold);

    ylabel(y,Fontsize,24,FontWeight,Bold);legend(scatter plot, True y=m+bx, lscov fit, backslash fit ...

    ,Location,NorthWest);

    set(gca,Fontsize,20,FontWeight,Bold,LineWidth,3);set(gcf,Color,White,Position ...

    ,[scrsize(3)/ss(nfig) 60 scrsize(3)*0.60 scrsize(4)*0.80]); %[l,b,w,h]

    fprintf(\n );

    ============= LStest Output =========================

    LStest Output (30-Jan-2010 14:34:46):

    True: b = 0.2500; m = 1.0000;

    sigma_e = 0.2500;

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page11 Floyd B. Hanson

  • TSS = 1.659e+01

    RSS=SSEreg = 6.494e+00; SSEbsl = 6.494e+00;

    RelResreg = 5.403e-01;

    RelResbsl = 5.403e-01;

    Rsqreg = 6.085e-01; Rsqbsl = 6.085e-01;

    True: b = 0.2500; m = 1.0000;

    lscov: b = 0.2253; m = 1.0873;

    bkslh: b = 0.2253; m = 1.0873;

    sqrt(norm(preg-ptrue)/norm(ptrue)) = 0.2967;

    sqrt(norm(pbsl-ptrue)/norm(ptrue)) = 0.2967;

    sqrt(norm(preg-pbsl)/norm(pbsl)) = 0.0000;

    lscov: sep = [5.125e-02,8.809e-02];

    lscov: mse = 6.627e-02;

    >>

    Remark: Some scaling differences mean variables like mse, supposedmean square error, are quite different, say from the Relative ResidualRelRes=sqrt(norm(y-yhat)/norm(y)).

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page12 Floyd B. Hanson

  • 5.3 Multiple Linear Regressor Models with a UnivariateResponse:Generalizing the prior univariate predictor variable, assuming againunivariate response sample data, ~Y = [Yi]n1, consider the linearrelationship tom-dimensional multivariate predictor with sample dataarrayX = [Xi,j]nm and ~1 [1]n1,

    ~Y ' p0~1 +X~p (5.13)with predictor-independent coefficient p0 and linear predictor coefficientor parameter vector ~p = [pi]m1. Define the linear error in themodel to be

    ~e=[ei]n1 ~Y p0~1X~p. (5.14)Next we absorb the p0 parameter by defining extended linear parameterand model basis arrays with the constant vector ~X0=[Xi,0]n1~1,

    ~pex [pi1](m+1)1 &A [~1, X]=[Xi,j1]n(m+1), (5.15)yielding themultivariate linear model in compact form,

    ~Y =A~pex+~e. (5.16)

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page13 Floyd B. Hanson

  • Multiple Linear (Multilinear) Least Squares Regression:aThe least squares objective corresponds to minimizing the quadratic costsor residual sum of squares in 2-norm form,

    L(~pex)=RSS(~pex)=(~Y A~pex

    )>(~Y A~pex

    )=~Y A~pex2.(5.17)

    In order to find the multivariate critical points with respect to theunknown parameter vector ~pex, we expand the quadratic form into moreelementary products

    L(~pex) = ~Y >~Y 2~pex>A>~Y + ~pex>A>A~pex, (5.18)where the reverse product transpose identity (AB)> = B>A> has been

    used. Next the gradient peel theoremb,~p[~p>~Y

    ]= ~Y , with three

    applications, implies the critical point conditions,~pex [L(~pex)] = 2A>~Y + 2A>A~pex = ~0(m+1)1. (5.19)

    aMATAB reserves multivariate linear regression for a vector system of multiple linearregressor models of responses ~y and a array of predictorsX , as in a portfolio application.

    bHanson 07, Online Appendix B Preliminaries: Probability and Analysis Results, p. B45,http://www.math.uic.edu/ hanson/pub/SIAMbook/bk0BprelimAppendfinal.pdf

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page14 Floyd B. Hanson

  • This leads to the optimal parameter estimate, provided that the(m+1) (m+1) square matrix (A>A) is invertible,

    pex = ~pex =(A>A

    )1A>~Y , (5.20)

    but the non-squareA will not be invertible in the ordinary sense, theA>A may not be positive definite form>1, and there are possiblecatatrophic cancellation problems with estimated parameter formula.The optimum, i.e., minimum, pex, of the parameter vector depends ontechnical conditions, the most important is the objective quadratic form,the parameter vector is linear in the response observation vector ~Y .This estimate is unbiased conditional onA, with E[~e ] = ~0 andCov[~e, ~e>] = 2eIn from the usual assumptions, is that~edist= N (~0, 2eIn) , also it is assumed that E[e2i |Xi] is constant, so

    E[pex |A] =(A>A

    )1A>E[~Y |A]

    =(A>A

    )1A>E[A~pex + ~e |A]

    =(A>A

    )1A>A~pex = ~pex,

    (5.21)

    which we take as the true parameter value.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page15 Floyd B. Hanson

  • In general,A>A may not be positive definite due to negativeX-correlations. Testing for positive definiteness, using~X 1

    n[n

    k=1Xk,i]m1 andX>X 1n [n

    k=1Xk,iXk,j]mm,

    1n~p>exA

    >A~pex=[p0 ~p

    >] 1 ~X>~X X>X

    p0~p

    = p20+p0

    ~X>~p+~p>X>X~p

    =p0+ ~X>~p2+~p>Cov[X>, X] ~p,

    (5.22)

    where the completing the square technique was used andCov

    [X>, X

    ] 1n[n

    k=1(Xk,iXi)(Xk,jXi)]mm. So, whenm=1 predictor variable with a sum of squares and semi-positivedefiniteness, but form>1 definiteness may not be true if there arenegative elements of variable covariance. Care must be taken in choosingstatistical software.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page16 Floyd B. Hanson

  • The least squares parameter solution has a geometric interpretationthat the least squares residual ~Res = ~Y Apex must be orthogonal tothe predictorApex. This follows from some linear algebra starting withthe scalar product orthogonal test:

    (Apex)> ~Res= p>exA>(~Y Apex)

    = p>ex(A>~Y A>Apex)

    = p>ex~0(m+1)1=0,

    (5.23)

    by Eq. (5.19). Hence, the residual ~Res, the response observations ~Y andoptimal predicted responseApex form a right triangle with ~Y on thehypotenuse.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page17 Floyd B. Hanson

  • The estimated parameter covariance matrix is similarly given by

    bpex|A=E[(pex~pex)(pex~pex)>

    A]=(A>A

    )1A>E

    [~e~e>

    ]A(A>A

    )1= 2e

    (A>A

    )1.

    (5.24)

    The estimated response vector is defined by

    Y Apex=A(A>A

    )1A>~Y H~Y , (5.25)

    whereHA(A>A)1A>=[Hi,j]nn is called the hat orprediction matrix and note that it is a square symmetric matrix. Thismatrix enters into the raw residuals or errors as e ~Y Y =(InH)~Ywith mean E[e|A]=~0 and covariance be|A=2e(InH), obviouslycorrelated due to the (InH).

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page18 Floyd B. Hanson

  • The minimum residual sum of squares is given on page 6 byRSS = ||e||2||~Y Y ||2 and the unbiased variance associated withthis residual sum of squares, when n>m+1, is2be= ||e||2/(nm1), where the number of degrees of freedomhave been reduced by the number of parameters, (m+1). Thestandardized residuals are given approximately by

    e(std)i ' ei/(be1Hi,i). (5.26)

    The F-test can be used for a test of normality, such that

    F =SSreg2e

    =TSSRSS

    2e, (5.27)

    where SSreg is the sum of squares due to the regression. (Notesimilarity toR2).

    In computational statistics, the relative residual,RelResy = ||~Y Y ||/||~Y || (5.28)

    is often used since it is readily calculated once the parameter estimate isavailable.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page19 Floyd B. Hanson

  • MATLAB Functions for Least Squares:MATLAB contains a large amount of functions for linear regression andits variations, but only a few are listed here.1. Back Slash Method or Left Matrix Division (\ or mldivide): remember

    the statement thatA did not have a ordinary inverse, well it has a generalized

    inverse such that bp=A\~Y (read this from right to left forA divided into~Y , as you would read ~Y/A in the reverse order) producing a least square

    approximation solution,a the method depending on input. The mldivide

    uses many methods depending on A. The more general regress function

    uses powerful backslash technique, but produces added statistics.2. [phat,stdp,mse]=lscov(A,Y); produces the least square solution to

    A~x=~b by solving (A~p~Y )(A~p~Y ) for (m1) phat from (nm)A and (n1) Y (in our notation, (n,m)(n,m+1) and (A, Y, p) (A, ~Y , ~pex)). The extra output are estimated standard errors in stdp ofphat and mean squared error in mse. See the examples in help lscov .

    aD. & N. Higham 05, MATLAB Guide, pp.126-127, say that it actually performs fasterand more accurately than some other methods.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page20 Floyd B. Hanson

  • 3. [phat,pbci,r,rci,stats]=regress(X,Y,alpha);primary produces the the `1 estimated linear parameter coefficient arrayphat= bp for the responses in univariate Y from multilinear regression on`n predictor data X and n1 response data y. (Caution: If a constantparameter p0, then the first column of X is a column of ones and`=m+1.) The bci is a `1 array for estimated parameter confidenceintervals in each of ` parameters using an out of confidence parameteralpha, r is the n1 linear fit residuals or errors, rci is a n1 residualconfidence intervals for outlier diagnosis, an outlier being outside the

    100(1-alpha)% residual confidence interval, and stats is an 14statistics row vector containing

    [R2statistic, Fstatistic, Pvalue of F, b2e ]. See Helpregress for an example application for ` = 4, where

    A=[ones(size(x1)),x1,x2,x1.*x2], the fourth linear term is a

    data cross product x1.x2, and a scatter3 scatterplot of the y vs.(x1, x2) results. Note, multilinear only means a linear combination of

    functions of data and are also called basis functions.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page21 Floyd B. Hanson

  • 4. stats=regstats(y,x,model,whichstats); producessimiler linear regression results like regress, but make possible aricher set of statistical diagnostic tests and allows linear combinationsof both linear and quadratic functions of ~x. The option model can belinear,purequadratic,interaction,quadratic,

    the latter is a general quadratic function. The option whichstatsallows many statistical tests and measures with output in the outputstructure stats and using all gives all, but if the outputstructure is omitted, then which statistics can be selected on a easierto use GUI menu.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page22 Floyd B. Hanson

  • 5. [b,stats]=robustfit(x,y,wfun,tune); primaryproduces the weighted least square or linear regression for

    the p1 estimated linear parameter coefficient array b= p for theresponses in univariate y from multilinear regression on `npredictor data x and n1 response data y (Caution: If a constantparameter p0 is in the model, then robustfit automaticallyadds ones to the first column of x and `=m at input, so do NOTadd ones. Also, the input order for x,y in robustfit is opposite tothe tmbty,x in regress and regstats.) See Helprobustfit for a long list of options. If the options wfun,tune,are omitted the bi-square weight function and its tuning constant areused.

    {Note: The robustfit weighting can be used for identifyingdata outliers, so in traditional practice can be discarded orlessened by weighting or could be enhanced if value at risk was aserious concern. See also recoplot, the residual order plot.}

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page23 Floyd B. Hanson

  • 6. [p,S,mu]=polyfit(x,y,n); finds the fit for vector y as a polynomialp of degree n in standardized vector variable bx=(x-mu(1))/mu(2) (i.e.,note m=1), a highly recommended centering and scaling of data toimprove any method computation, where mu=[mean(x),std(x)];.Also S is the structure that gives extra information (see Help) reading the

    output by [y,delta]=polyval(p,x,S,mu); where ydelta givesthe error supposedly within 50% confidence.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page24 Floyd B. Hanson

  • 7. [U,V,D]=svd(x,0); produces the singular valuedecomposition (SVD) of the nm array x where U is an nnorthogonal array (i.e., transpose is the inverse), V is anmmorthogonal array and D is generally a nm diagonal array, but thesecond 0 input option reduces it to the necessarymm, whennm, but in our notation nm+1 with the added constantcolumn, so for svd then m=m+1.a SVD used to be one of a set ofmethods used by the backslash method.

    aSee D. & N. Higham 05, MATLAB Guide, pp.130-131. In general, the least squaresproblem is susceptible to ill-conditioning due to possible problems in catastrophic cancel-lation, but SVD was developed as a robust method for this problem. See also G. Forsythe,M. Malcolm and C. Moler, Computer Methods for Mathematical Computations, 1977, forpre-MATLAB background by Moler and his mentor Forsythe. Note, mathematical infiniteprecision is unrealistic compared to the computational finite precision in practice.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page25 Floyd B. Hanson

  • 5.4 Weighted Least Squares :Since outliers or extreme rare events happen, there may be a desirableto reduce their bias if the objective is equilibrium type models or if theinterest is the larger value at risk the analyst may want to enhance theeffect to compensate for the bias of regression to average out theoutliers.

    LetW =[wii,j]nn be a diagonal matrix of constant positive weightswi, soW1=[i,j/wi]nn,W 1/2=

    W =[

    wii,j]nn and

    W>=W . Next, the observational error or residual ~e is replaced by aweighted version ~ew=~e/

    W , so that the basic statistics are

    E[~ew]=~0n and Cov[~ew, ~e>w ]=2eInW

    1.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page26 Floyd B. Hanson

  • The residual is then~Res= ~Y A~pex=~e/

    W (5.29)

    with extended observations arrayA=[~1, ~X] and the residual sum ofsquares is

    RSS(~pex)=~e>~e=(~Y A~pex)>W (~Y A~pex), (5.30)so the theoretical least squares estimate is

    pex=(A>WA

    )1A>W ~Y . (5.31)

    The implementation of weighted least square (WLS), see MATLABsrobustfit, begins with scaling the predictor observations by letting

    MWA=

    [wiXi,j1

    ]n(m+1) , (5.32)

    recalling that ~X0=~1, and the response observations by letting~Z

    W ~Y =

    [wiYi

    ]n1 , (5.33)

    so the least squares parameter estimate becomes

    pex=(M>M

    )1M>~Z. (5.34)

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page27 Floyd B. Hanson

  • Ordinary and Weighted Least Squares for Simple Linear Fit Examplewith Normal-Poisson Error:

    0 0.2 0.4 0.6 0.8 1

    0

    0.5

    1

    1.5

    2

    2.5Ordinary & Weighted Least Square Linear Example:

    x

    y

    scatter plot True y=m+bx Regress fit Robustfit

    Figure 5.2: Ordinary least squares fit using MATLABs regress andweighted least squares robustfit methods, with dissimilar results fora straight line fit with scatterplot data from combined normal andPoisson jump random error.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page28 Floyd B. Hanson

  • MATLAB Code for Ordinary & Weighted Least Squares Applicationwith Normal-Poisson Error:function RegRobtestclc

    fprintf(\nRegRobtest Output (%s):,datestr(now));

    m = 1; b = 0.25; % True parm values;fprintf(\nTrue: b = %7.4f; m = %7.4f;,b,m);

    ptrue = [b;m];

    n = 100;x = rand(n,1); % Simulated Uniform x-data;

    sigma_e = 0.30; nu_e = 1.5; Lambda_e = 0.05;

    % JD-Simulation Zero-Mean error:err = sigma_e*randn(n,1) ...

    + nu_e*(poissrnd(Lambda_e,n,1)-Lambda_e*ones(n,1));

    fprintf(\nsigma_e = %7.4f; nu_e = %7.4f; Lambda_e = %7.4f;...

    ,sigma_e,nu_e,Lambda_e);y = b+m*x+err; % Simulated y-data with linear model;

    TSS = (n-1)*var(y);

    fprintf(\nTSS = %9.3e,TSS);A = [ones(n,1) x];

    fprintf(\nsize(A)=[%i,%i]; size(y)=[%i,%i];,size(A),size(y));

    [preg,pci,res,resci,statreg] = Regress(y,A); % Multlinear Regression;breg = preg(1); mreg = preg(2);

    yhatreg = breg+mreg*x;

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page29 Floyd B. Hanson

  • fprintf(\nRelResReg =%9.3e;,sqrt(norm(y-yhatreg)/norm(y)));

    [prob,statrob] = robustfit(x,y); % Weighted Least Sqs Method;

    yhatrob = prob(1)+prob(2)*x;

    fprintf(\nRelResRob =%9.3e;,sqrt(norm(y-yhatrob)/norm(y)));

    fprintf(\nTrue: b =%7.4f; m =%7.4f;,b,m);

    fprintf(\nRegress: b =%7.4f; m =%7.4f;,breg,mreg);

    fprintf(\nRobustfit: b =%7.4f; m =%7.4f;,prob(1),prob(2));

    fprintf(\nsqrt(norm(preg-ptrue)/norm(ptrue)) =%7.4f; ...

    ,sqrt(norm(preg-ptrue)/norm(ptrue)));

    fprintf(\nsqrt(norm(prob-ptrue)/norm(ptrue)) =%7.4f; ...

    ,sqrt(norm(prob-ptrue)/norm(ptrue)));

    fprintf(\nsqrt(norm(preg-prob)/norm(prob)) =%7.4f; ...

    ,sqrt(norm(preg-prob)/norm(prob)));

    SSEreg = sum((y-yhatreg).2); % Also, RSS=ResSumSqs

    SSErob = sum((y-yhatrob).2); % Also, RSS=ResSumSqs

    fprintf(\nRSS: SSEreg =%9.3e; SSErob =%9.3e;,SSEreg,SSErob);

    Rsqreg = 1-SSEreg/TSS; Rsqrob = 1-SSErob/TSS;

    fprintf(\nRsqreg =%9.3e; Rsqrob =%9.3e;,Rsqreg,Rsqrob);

    fprintf(\nstatreg: R2 =%7.4f; F = %7.4f; ...

    ,statreg(1,1),statreg(1,2));

    fprintf( P-value)(F) =%7.4f; Var(error) =%7.4f; ...

    ,statreg(1,1),statreg(1,1));

    fprintf(\nstatrob Sigmas: OLS_s=%7.4f; Robust_s=%7.4f; ...

    ,statrob.ols_s,statrob.robust_s);

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page30 Floyd B. Hanson

  • fprintf( MAD_s=%7.4f; final_s=%7.4f; ...

    ,statrob.mad_s,statrob.s);

    fprintf(\nstatrob: SE_p = [%7.4f; %7.4f];,statrob.se);

    fprintf(\nstatrob: Corr_ps=[%7.4f, %7.4f; %7.4f, %7.4f]; ...

    ,statrob.coeffcorr);

    statrob,

    %

    xg = 0:0.1:1;

    ytrue = b+m*xg;

    yhatregg = breg+mreg*xg;

    yhatrobg = prob(1)+prob(2)*xg;

    %

    figure(1); nfig = 1;

    scrsize = get(0,ScreenSize); % figure spacing for target screen

    ss = [5.0,4.5,4.0,3.5]; % figure spacing factors

    scatter(x,y,8); hold on;

    plot(xg,ytrue,-g,xg,yhatregg,:k,xg,yhatrobg,--r,LineWidth,2);

    axis tight; hold off;

    title(Ordinary & Weighted Least Square Linear Example:...

    ,Fontsize,24,FontWeight,Bold);

    xlabel(x,Fontsize,24,FontWeight,Bold);

    ylabel(y,Fontsize,24,FontWeight,Bold);

    legend(scatter plot, True y=m+bx, Regress fit, Robustfit ...

    ,Location,NorthWest);

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page31 Floyd B. Hanson

  • set(gca,Fontsize,20,FontWeight,Bold,LineWidth,3);

    set(gcf,Color,White,Position ...

    ,[scrsize(3)/ss(nfig) 60 scrsize(3)*0.60 scrsize(4)*0.80]); %[l,b,w,h]

    fprintf(\n );

    =========== CORRECTED Output ====================

    RegRobtest Output (30-Jan-2010 14:04:30):

    b = 0.2500; m = 1.0000;

    sigma_e = 0.3000; nu_e = 1.5000; Lambda_e = 0.0500;

    TSS = 3.247e+01

    size(A)=[100,2]; size(y)=[100,1];

    RelResReg =7.140e-01;

    RelResRob =7.229e-01;

    True: b = 0.2500; m = 1.0000;

    Regress: b = 0.2241; m = 1.0794;

    Robustfit: b = 0.1434; m = 1.0245;

    sqrt(norm(preg-ptrue)/norm(ptrue)) = 0.2846;

    sqrt(norm(prob-ptrue)/norm(ptrue)) = 0.3258;

    sqrt(norm(preg-prob)/norm(prob)) = 0.3072;

    RSS: SSEreg =2.372e+01; SSErob =2.492e+01;

    Rsqreg =2.695e-01; Rsqrob =2.326e-01;

    statreg: R2 = 0.2695; F = 36.1469; P-value)(F) = 0.2695;

    Var(error) = 0.2695;

    statrob Sigmas: OLS_s= 0.4920; Robust_s= 0.3220; MAD_s= 0.2732;

    final_s= 0.3302;

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page32 Floyd B. Hanson

  • statrob: SE_p = [ 0.0690; 0.1205];

    statrob: Corr_ps=[ 1.0000, -0.8780; -0.8780, 1.0000];

    statrob =

    ols_s: 0.4920

    robust_s: 0.3220

    mad_s: 0.2732

    s: 0.3302

    resid: [100x1 double]

    rstud: [100x1 double]

    se: [2x1 double]

    covb: [2x2 double]

    coeffcorr: [2x2 double]

    t: [2x1 double]

    p: [2x1 double]

    w: [100x1 double]

    R: [2x2 double]

    dfe: 98

    h: [100x1 double]

    >>

    Remark: Some differences with reasonable intercept (b) but poor slope(m), the parameter RMS difference being 0.3072. The OLS-sigma ismuch greater than the Robust-sigma or Final-sigma.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page33 Floyd B. Hanson

  • 5.5 General Linear Least Squares (GLLS) Method forGeneral Linear Model (GLM):The use of only linear predictor variables is highly restrictive andunrealistic, since the model should depend on the available sciencemodels and not on the modelers limited toolbox of models. In thegeneral least squares method a general linear model is assumed thatthe response variable Y is a linear combination of functions of thepredictor variable ~X that includes linear and nonlinear ones, but themodel must be a linear in the parameters, ~c = [ci]p1, which happen tobe the coefficients,

    y =p

    k=1

    ckk(~x), (5.35)

    where the k(~x) are the general nonlinear fit functions. An example isk(~x)=1, the constant function, k(~x)=xi, the linear in componentxi, or k(~x)=xixj , the interactive function if i 6=j and pure quadraticif i=j.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page34 Floyd B. Hanson

  • Unfortunately, this excludes parameters in the function like k(~x; ~),such as when trying to fit multi-parameter densities where the parameterscannot be formed into a linear combinations coefficient.

    Hence, we need to fit the response-predictor data to determine acoefficient parameter p-vector c with respect to the corresponding fitbasis function p-vector ~(~x)=[i(~x)]p1. The objective is tominimize the GLLS chi-square function:

    2(~c)=ni=1

    (Yi

    pk=1

    ckk( ~Xi)

    )2/2i , (5.36)

    where the wi = 1/2i are the weight constants or functions fori=1:m. For simplicity, it is assumed that 2i =

    2y,i is a variance

    associated with the response variable Yi, so that for the time being,2x,i 0, i.e., we have precise ~Xi or ~Xi 0.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page35 Floyd B. Hanson

  • Here, the array

    A = [Ai,j]npW>(X)

    [j( ~Xi)/i

    ]np

    , (5.37)

    is called the design matrix, where ~Xi=[Xi,j]1m,m is the number ofpredictor variables, for i=1:n predictor observations, whileX=[Xi,j]nm is the array of all predictor observations andW =[wii,j]nn is the diagonal weight matrix. Further, let~Y =[Yi]n1 is the vector of observed responses with assigned variancevector ~ [i]n1 .It is reasonable to assume that np, that there is much more data thenthere are parameters, so that the system of equations in severelyover-determined and an averaged solution is necessary. The moreover-determined the system is, the better it is for the statistics. Thenumber of degrees of freedom (DOF) is DOF=n-p>0. Let the scaledoutput be ~Z=[Zi]n1 [Yi/i]n1

    W [Yi]n1.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page36 Floyd B. Hanson

  • Thus, Eq. (5.54) can be written in matrix-vector form,

    2(~c)=(~Z A~c)>(~Z A~c)>. (5.38)The optimal critical condition for the coefficient parameters is

    ~0p=c[2](~c)=2(A>~ZA>A~c), (5.39)

    yielding the least squares normal equation for the parameter vectorA>A~c=A>~Z (5.40)

    and the estimate,

    c=~c=(A>A)1A>~Z. (5.41)This is essentially the same form obtained for either ordinary or weightedleast squares regression. In fact, there is an example in the MATLABhelp for the OLS regress function,

    A=[ones(size(x1)),x1,x2,x1.*x2], (5.42)that show how you can include simple GLLS basis functions into OLSvariables. In a sense, the raw data [x1, x2] is formed into substitutevectors, as long as still independent,

    [X1,X2,X3,X4]=[ones(size(x1)),x1,x2,x1.*x2]. (5.43)

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page37 Floyd B. Hanson

  • Singular Value Decomposition (SVD):Although, the product matrixA>A is symmetric and is usuallyinvertible, it contains no more information thanA itself and it is desirableto work just withA. The singular value decomposition are an ideal wayof doing this for the least squares design matrixA. SVD forA has theform,

    A = UDV >, (5.44)

    where U=[Ui,j]nn is the same size asA and is column othogonal,U>U=In or

    nk=1Uk,iUk,j=i,j= ~U

    (col)i ~U (col)j , V =[Vi,j]pp

    is square and row or column orthogonal, V >V =Ip=V V >, andD=[sii,j]np is a diagonal matrix with singular values si along thediagonal and measuring the effect ofA on a vector with respect to a norm,such thatmini(si)||A~u||/||~u||maxi(si), ||~u|| 6=0. Thus,

    D=InDIn=U>UDV >V =U>AV. (5.45)

    The SV problem (SVP) isAV =sU . See MATLABs svd function.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page38 Floyd B. Hanson

  • For GLLS, ifA has an SVD, i.e.,A = UDV >, then using the transposereversed product algebra, i.e., (AB)>=B>A>,

    A>=(UDV >

    )>=(V >

    )>D>U>=V D>U>, (5.46)

    since the transpose of transpose does nothing to a matrix and noting that anon-square the diagonal is not symmetric soD>6= D. The desiredproductA>A decomposes as

    A>A=V D>U>UDV >=V D>InDV >=V D>DV >, (5.47)

    whereD>D=[s2i i,j]pp, which is square and genuinely symmetric.Next, applying the SVD (5.46) and (5.47) to the normal equation (5.40)for the parameter vector,

    V D>DV >~c=V D>U>~Z (5.48)

    and inverting the coefficients V, (D>D) and V >of ~c one by one yields

    c = ~c=V DU>~Z, (5.49)

    where D=(D>D)1D>=[i,j/si]pn, would be D1 ifinvertible, butD is almost always not square.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page39 Floyd B. Hanson

  • SVD Parameter Solution:Hence, the least squares solution is, given SVD matrices forA, is reducedto matrix-vector multiplication, a big advantage for a matrixcomputational system like MATLAB. However, by expanding by matrixelements the multiplications can be reduced to partial matrixmultiplication:

    ~c= [ci ]p1=[p

    j=1 Vi,jp

    k=11sjj,k

    n`=1 Uk,`Z`

    ]p1

    =[p

    j=1 Vi,j1sj

    n`=1 Uj,`Z`

    ]p1

    =p

    j=1

    1

    sj

    ((~U(col)j

    )>~Z

    )~V(col)j ,

    (5.50)

    where the column vectors are ~U (col)j [Ui,j]p1 and~V(col)j [Vi,j]n1. Note that ((~U (col)j )>~Z)) is a scalar product, so the

    vector-orientation of ~c comes mainly from ~V (col)j .

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page40 Floyd B. Hanson

  • SVD Parameter Sensitivities:The vector-form of SVD parameter solution is also useful for determiningthe parameter sensitivities to the output responses, e.g., the sensitivity ofparameter cj to the original response Yi=iZi is

    cjYi

    =p

    k=1

    1

    sk

    ((~U(col)k

    )> ~ZYi

    )Vj,k=

    1

    i

    pk=1

    1

    skUi,kVj,k. (5.51)

    This sensitivity can be used to estimate the variance of cj , under restoredresponse weighting,

    2cj=

    ni=1

    2i

    (cjYi

    )2=

    ni=1

    pk=1

    1

    skUi,kVj,k

    p`=1

    1

    s`Ui,`Vj,`

    =p

    k=1

    1

    s2kV 2j,k,

    (5.52)

    using the column othogonalityn

    i=1 Ui,kUi,`=`,k. Similarly, theestimated covariance is cov(ci , c

    j )=

    pk=1Vi,kVj,k/s

    2k.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page41 Floyd B. Hanson

  • Fitting General Nonlinear Models (GNLM):Given a general nonlinear model y=f(x;~c), beyond the linearcombination form y=

    pj=1 cjj(x), the primary technique is to

    transform the GNLM, if possible, to a form suitable for least squares. Dueto complexity, the GNLM can be numerically ill-conditioned, i.e.,difficult to compute. Some examples:1. Exponential-like Density: y=f(x;~c)=c2 exp(c1x). Letz=ln(y)=c1x+ln(c2), so letting z=

    2j=1 bjj(x) with

    1(x)=1, 2(x)=x, b1=ln(c2) and b2=c1. Problem is thatfor the single parameter exponential distribution c1=c2=1/, soleast square errors are likely to lead to inconsistencies.

    2. Normal-like Density: y=f(x;~c)= exp((xc1)2/(2c2))

    2pic2. Let

    z=ln(y)=(xc1)2/(2c2)ln(2pic2), so lettingz=

    P3j=1 bjj(x) with 1(x)=1, 2(x)=x, 3(x)=x

    2,

    b1=c21/(2c2)ln(2pic2), b2=c1/c2 and

    b3=1/(2c2). Problem is that for the two parameter normaldistribution leads to three related coefficients and inconsistencies.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page42 Floyd B. Hanson

  • General Nonlinear Least Square Fit Methods:Let the nonlinear objective be

    2(~c)=2( ~X, ~Y , ~;~c)=ni=1

    (Yi f(Xi;~c))22i

    . (5.53)

    Searching for critical points in p-dimensions,

    2

    cj(~c)=2

    ni=1

    (Yi f(Xi;~c))2i

    f

    cj(Xi;~c)

    =0 (5.54)

    for j=1:p and where ~c = min~c

    [2(~c)

    ]. Difficulties are there is no

    closed-form linear normal equation there is no SVD or similar methodsand the optimization may be ill-conditioned with local minima hiding aglobal minima.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page43 Floyd B. Hanson

  • General Nonlinear Least Square Fit Functions in MATLAB:The nonlinear least squares is the kind of method needed to find themarket distribution for assets or other financial instruments. Derivativeoptimization methods like methods of steepest descents and variations ofNewtons method may be time-consuming and for complicateddistribution models that derivative formulas may be quite complex. Forgeneral users, it may be desirable to use direct methods which bydefinition do not use derivatives or derivative methods for which the codeasks only for an input of the function 2 and an initial value of theparameter ~c0. Some of these in MATLAB, listed in the simplest or next tosimplest form:

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page44 Floyd B. Hanson

  • 1. c=fminsearch(chi2,c0): The chi2 is a function handle forthe objective function assumed to include the nonlinear fit function f,c0 is an input starting vector value and c is the output answer. Thisis the granddaddy of direct search and uses Nelder-Meads (1994)down-hill simplex method which employs flexible super-triangles inthe parameter space to search for unconstrained minima. It is fast andfairly robust, but is is just a basic minimization method. Relatedfunction fminunc is an unconstrained derivative minimum searchmethod in the Optimization Toolbox. Functions fminbndand fmincon treat constrained minima, the first by direct search andthe second by derivative search. See MATLAB helpfor moreinformation.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page45 Floyd B. Hanson

  • Figure 5.3: MATLAB Down-Hill Simplex Algorithm Illustration:Fminsearch Algorithm, Unconstrained Nonlinear Optimization page, Op-timization Toolbox, 2008. Triangular with (x(1), x(2), x(n+ 1) x(3)).

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page46 Floyd B. Hanson

  • 2. [c,Res,Cov,mse]=nlinfit(X,Y,f,c0): This is anonlinear regression function, where X is the input predictor, Y isthe input response, f is the function handle for the nonlinear fitfunction, c0 is an input starting vector value and c is the outputanswer. Extra output is residual Res. Jacobian J, covariance matrixCov and an error term mse. It is similar to robustfit multilinearweighted least squares, but nlinfit also uses the Jacobian ofderivatives fot f. Also, nlinfit has several auxiliary functions anda GUI tool:

    cci=nlparci(c,Res,covar,Cov):This gives 95% confidence intervals cci for the output parameterc,Res,Cov of nlinfit, else insert the input option pair{,alpha,alpha}. The covar is the parameter labelfor Cov.

    [ypred,delta]=nlpredci(f,X,c,Res,covar,Cov):This gives predicted values ypred for 95% CI half-widths delta.It also uses the output parameters c,Res,Cov of nlinfit.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page47 Floyd B. Hanson

  • nlintool(X,Y,f,c0,alpha,Xname,Yname): This isthe graphical user interface for nlinfit, can take optionalarguments like the complementary CI parameter alpha and plotXY-labels Xname,Yname.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page48 Floyd B. Hanson

  • 5.6 Maximum Likelihood Estimation Method:Maximum likelihood estimation methods are a form of regression wherethe objective is derived from maximum of the likelihood, i.e., the mostprobable state of the distribution. The maximum probability occurs at themaximum of the density, called the mode. For example, the normaldistribution density is

    f(n)Z (z;,

    2)=exp((z )2/(22))/2pi2 (5.55)

    and checking for critical points,

    0 =(f (n)Z )(z;, 2)=2(z

    )2

    f(n)Z (z

    ;, 2), (5.56)

    we find the critical point and mode to be at the mean z = since thatcan be the only interior critical point, the density only vanishing atinfinity. Note that we effectively computed the logarithmic derivatived ln(f (n)Z )/dz=(f

    (n)Z )

    /f (n)Z . Often, the log-likelihood using thelogarithm of the density rather than the density itself for the maximumlikelihood to avoid the over-dominance of exponentials.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page49 Floyd B. Hanson

  • Often we are looking for a multidimensional mode (the value of thevariate where the maximum probability occurs) and in analogy with thenormal density and it is easier to look at the exponent by using thelogarithm than at the exponential itself. Since if the kernel or mostimportant part of the distribution is of the formK(x) = exp((x))then ln(K(x)) = (x) and

    K(x) = (x)K(x) = (log(K))(x)K(x), (5.57)

    so the determination of the maximum likelihood location or mode bycritical point analysis of this simple kernel is related to the simpler criticalpoint analysis of the logarithm of the kernel, i.e., zeros of the logarithmicderivative of the kernel, assumed unimodal.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page50 Floyd B. Hanson

  • A Probabilistic Introduction to Maximum Log-Likelihood (MLE)for Financial, Exploratory Data Analysis Applications:a

    Let us return to the geometric Brownian motion or linear diffusion withconstant coefficients model for an asset priceA(t), where

    dA(t) = A(t)(dt+ dW (t)), (5.58)where the statistics (, ) are constant andW (t) is the theoretical modelfor Brownian motion. Since the equation is linear in the asset price, it isconvenient to transform to log-pricing using the stochastic dt precisionchain rule to to get the arithmetic Brownian motion,

    d log(A(t)) = ( 2/2)dt+ dW (t). (5.59)Further, since our financial data is discrete and assuming the time-steptis sufficiently small, the equation is converted to asset log-return form,

    LRi = log(Ai) = m` +v`Zi (5.60)

    where, simplifying,m` ( 2/2)t and v` 2t > 0 arelog-coefficients from usingWi =

    tZi with Zi

    dist=IID

    N (0, 1) i .aSee Carmona 04, p. 124ff; Hull 06, p. 567ff; Hanson 01-08 computational finance

    papers, http://www.math.uic.edu/ hanson/compfinpapers.html.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page51 Floyd B. Hanson

  • The log-return distribution for each i, withX = LRi, is given bydefinition,

    FX(xi) Prob[X xi] = Prob[m` +v`Zi xi]alg= Prob[Zi (xi m`)/v`]N= F (n)Z ((xi m`)/

    v`; 0, 1) .

    (5.61)

    Thus, upon differentiation, the ith likelihood function is the densityfunction,

    LHi(m`, v`) = fX(xi) = 1v`f(n)Z ((xi m`)/

    v`; 0, 1)

    N= 12piv`

    exp(0.5(xi m`)2/v`) . (5.62)

    Further, the Zi are IID normal, so the total density is the product of allthe individual density for the log-return data count for i=1:n.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page52 Floyd B. Hanson

  • Hence,LH(n)(m`, v`) = f ~X(~x)

    IID=ni=1

    fX(xi)

    = 1(v`)n

    ni=1

    f(n)Z ((xi m`)/v`; 0, 1)

    N= 1(2piv`)n

    ni=1

    exp(0.5(xi m`)2/v`) .

    (5.63)

    For further simplicity, we take logarithms, turning the products into sums,to get the log-likelihood function (the natural logarithm, here log ln),LLH(n)(m`, v`) = log

    (f ~X(~x)

    )=

    ni=1

    log(fX(xi))

    = 12v`

    ni=1

    (xi m`)2 n

    2log(2piv`),

    (5.64)

    ending up with the negative of the least squares objective. Although oftenthe log-likelihood function is multiplied by a minus sign since mostoptimal solvers are written as minimizers,

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page53 Floyd B. Hanson

  • The system bias in linear regression is that they are natural for normallydistributed randomness. There are several variants of maximumlikelihood estimation based on other distributions, e.g., multinomialmaximum likelihood estimationa and MATLABs generic maximumlikelihood function mle specialized to 17 named distribution optionsusing the response data. Seeking critical points,

    LLH(n)m`

    (m`, v`) =1

    v`

    ni=1

    (xi m`) = 0, (5.65)and

    LLH(n)v`

    (m`, v`) =1

    2v2`

    ni=1

    (xi m`)2 n

    2v`

    = 0, (5.66)

    gives the simultaneous estimates,

    m`=m`=1

    n

    ni=1

    xix & v`=v` =1

    n

    ni=1

    (xi m` )2 2x. (5.67)This justifies using the mean and variance directly from the log-return data.

    aFor instance, Hanson with Westman and Zhu 04a and 04b, computational finance pa-pers, http://www.math.uic.edu/ hanson/compfinpapers.html.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page54 Floyd B. Hanson

  • This is essentially what one would expect and could have been obtainedfrom mean(LR) and var(LR). Often, practitioners may a prior setm`=0, assuming that the mean log-return is usually small anyway.Finally, we need to convert back to standard model coefficient, assumingthatt, usually one trading day in years, is known,

    =xt

    & =x+ 2x/2

    t, (5.68)

    the latter form seems to contradict the practice of throwing out the meanm` since 2x/2 > 0.

    One advantage of maximum likelihood estimation (MLE), it that allproblems are not forced into one template objective such as least squaresfor the normal noise model, but yield an objective that is more natural forthe target problem and its distribution.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page55 Floyd B. Hanson

  • (not presented) Using Subsamples to Get Some Estimate of Time Dependence ofModel Coefficients:

    If the sample size it sample size n is sufficiently large, then subsamplescan be used to get an estimate of time dependence of the modelcoefficients. Since the sample index i is associated with a trading day,picking i = k for some trading day ti, marking a log-return between i andi+ 1, and then a half bandwidth iw, then our MLE estimates would be

    m`,k =1

    n

    k+iwi=kiw

    xi xk (5.69)

    and

    v`,k =1

    n

    k+iwi=kiw

    (xi m`,k)2 2x,k, (5.70)

    where k iw 1 and k + iw n. The index k represents the centerof a moving window in time.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page56 Floyd B. Hanson

  • (not presented) General Maximum Likelihood Function in MATLAB:[chat,cci]=mle(Y,distribution,DistName,alpha,alpha): This is a maximum likelihood estimator for a large number ofspecialized distributions. The required input is data Y, but the optionalinput is the distribution parameter paired with the name valueDistName which can be bernoulli, bernoulli,exponential, generalized pareto, lognormal,normal (default), poisson, uniform and others. The outputis the estimated parameters chat and the parameter confidence intervalcci at complementary level alpha, but if pair alpha, alpha isomitted then the CI is at the MATLAB default of 0.05 or 95% CI. Manyof the mle special distributions are prepackaged, such as binofit orpoissfit. The auxiliary function mlecov with similar argumentsoutputs the parameter estimate covariance matrix.

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page57 Floyd B. Hanson

  • * Reminder: Lecture 5 Homework Posted in Chalk Assignments,due by Lecture 6 in Chalk Assignments!

    * Summary of Lecture 5:

    1. Ordinary Least Squares or Linear Regression

    2. Multilinear Regression

    3. Weighted Least Squares

    4. General Linear Least Squares

    5. Maximum Likelihood Estimation Method (part 1)

    FINM 331/Stat 339 W10 Financial Data Analysis Lecture5-page58 Floyd B. Hanson