hw1 Wenbo Zhang

download hw1 Wenbo Zhang

of 13

Transcript of hw1 Wenbo Zhang

  • 8/7/2019 hw1 Wenbo Zhang

    1/13

    FinancialEconometricsHomework1

    Dr.Cai

    WenboZhang

  • 8/7/2019 hw1 Wenbo Zhang

    2/13

    FINN6219 Homework1 WenboZhang

    2

    1.DownloadweeklypricedataforIBMandMicrosoftstock.IBM(P1t)01/02/6201/15/08

    MSFT(P2t)03/13/8601/15/08

    a) CreateatimeseriesofcontinuouslycompoundedweeklyreturnsforIBMandMicrosoft.

    Usetheequation: ,wecangetthereturnsseries.

    b) Use the constructedweekly returns toconstruct a series ofmonthlyreturns. Youmayassumeforsimplicitythatonemonthconsistsoffourweeks.

    Use the equation: mi,k = ri,tt=4( k1)+1t=4( k1)+4

    , where i =1,2, k=1,2,3, , we can get the

    returnsseries.

    c) Constructagraphofstockpriceseries(P1t,P2t)andreturnsseries(r1t,r2t).

    Time

    p1t

    0 500 1000 1500 2000

    1

    00

    200

    300

    400

    500

    600

    Time

    p2t

    0 200 400 600 800 1000

    50

    100

    150

  • 8/7/2019 hw1 Wenbo Zhang

    3/13

  • 8/7/2019 hw1 Wenbo Zhang

    4/13

    FINN6219 Homework1 WenboZhang

    4

    Time

    p1rv

    0 500 1000 1500 2000

    0

    5000

    10000

    15000

    20000

    Time

    p2rv

    0 200 400 600 800 1000

    0

    500

    1000

    1500

    Time

    r1rm

    0 500 1000 1500 2000

    0.00

    0.05

    0.10

    Time

    r2rm

    0 200 400 600 800 1000

    -0.06

    -0

    .04

    -0.02

    0.00

    0.02

    0.04

    0.06

    0.08

  • 8/7/2019 hw1 Wenbo Zhang

    5/13

    FINN6219 Homework1 WenboZhang

    5

    e) What is the definition of a stationary stochastic process? Do prices look likestationaryprocess?Why?Doreturnslooklikeastationaryprocess?Why?

    Definition of a stationary stochastic process: In the mathematical sciences, a

    stationaryprocessisastochasticprocesswhosejointprobabilitydistributiondoes

    notchangewhenshiftedintimeorspace.Asaresult,parameterssuchasthemean

    andvariance,iftheyexist,alsodonotchangeovertimeorposition.Asanexample,

    whitenoiseisstationary.

    Fromtheobservationofthegraphsabove,pricesforbothstocksarenotstationaryprocesssincetherollingmeanischangingovertimeandrollingvarianceincludes

    severalhighvalues.

    However, the rollingmeanofreturn processes doesnt appear any obvious trend

    overtime.Butthebignumbersinvariancedeterminethatreturnprocessesarenot

    stationaryeither.

    f) Computeautocorrelationcoefficientskfor1k5forpricesandreturnsseries.

    P1t[,1]

    [1,] 1.0000000

    [2,] 0.9952586

    [3,] 0.9905095

    [4,] 0.9856203

    [5,] 0.9807094

    [6,] 0.9760011

    Time

    r1rv

    0 500 1000 1500 2000

    0.00

    0.05

    0.10

    0.15

    Time

    r2rv

    0 200 400 600 800 1000

    0.00

    0.01

    0.02

    0.03

    0.04

  • 8/7/2019 hw1 Wenbo Zhang

    6/13

    FINN6219 Homework1 WenboZhang

    6

    P2t

    [,1]

    [1,] 1.0000000

    [2,] 0.9808425

    [3,] 0.9619482

    [4,] 0.9441063[5,] 0.9262671

    [6,] 0.9107144

    r1t

    [,1]

    [1,] 1.000000000

    [2,] -0.003720422

    [3,] 0.020920001

    [4,] 0.015134049

    [5,] -0.035417986

    [6,] -0.063093877

    r2t

    [,1]

    [1,] 1.000000000

    [2,] -0.002964954

    [3,] -0.012364290

    [4,] 0.015955982

    [5,] -0.024635205

    [6,] -0.060960500

    0 1 2 3 4 5

    0.0

    0.2

    0.4

    0.6

    0.8

    1.0

    Lag

    ACF

    Series p1t

    0 1 2 3 4 5

    0.0

    0.2

    0.4

    0.6

    0.8

    1.0

    Lag

    ACF

    Series p2t

  • 8/7/2019 hw1 Wenbo Zhang

    7/13

    FINN6219 Homework1 WenboZhang

    7

    g) BasedonthecomputedautocorrelationsforIBMandMSFTstockpricesandreturns,whatcanyousayaboutcorrelationbetweenstockpricesfordifferentdays?What

    canyousayaboutcorrelationbetweenstockreturnsfordifferentdays?

    Fromthegraphin(f),wecanseethatthestockpricesseriesarehighlycorrelated,

    since the correlationcoefficients are very close to1. So, the correlationbetween

    stockpricesfordifferentdaysisverystrong.But,thestockreturnsseriesareweakly

    correlated,sincethecorrelationcoefficientsareverycloseto0.So,thecorrelation

    betweenstockreturnsfordifferentdaysisveryweak.

    h) UsingyourstockreturnsforIBMandMSFT,rit,i=1,2,constructfourmoreseriesyit=|rit|,i=1,2and=1,2.Computeautocorrelationcoefficientskfor1k5forthe

    newlyconstructedseries.Comparethecomputedcorrelationsfor| rit|,=1,2,and

    |rit|.Areresultsasyouexpected?

    0 1 2 3 4 5

    0.0

    0.2

    0.4

    0.6

    0.8

    1.0

    Lag

    ACF

    Series r1t

    0 1 2 3 4 5

    0.0

    0.2

    0.4

    0.6

    0.8

    1.0

    Lag

    ACF

    Series r2t

  • 8/7/2019 hw1 Wenbo Zhang

    8/13

    FINN6219 Homework1 WenboZhang

    8

    Theresultsareasexpected.

    i) UsetheJarque-Beratest(seeJarqueandBera(1980,1987))totesttheassumptionofreturnnormalityforIBMandMSFTstockreturns.

    JarqueBeraTest

    data:r1t

    X-squared=6966470,df=2,p-value

  • 8/7/2019 hw1 Wenbo Zhang

    9/13

    FINN6219 Homework1 WenboZhang

    9

    2.UseRprogramtoestimatetheprobabilitydensityfunctionofstandardizedIBMand

    MSFTstockreturns.

    (a)EstimateandconstructagraphoftheestimatedprobabilitydensityfunctionforIBM

    andMSFTstockreturns.

    -3 -2 -1 0 1 2 3

    0.0

    0.2

    0.4

    0.6

  • 8/7/2019 hw1 Wenbo Zhang

    10/13

    FINN6219 Homework1 WenboZhang

    10

    (b) Onthe same graphwith the empiricaldensity, construct a graphof the standard

    normaldensityfunction.Commentyourresults.

    Comparedtothestandardnormaldistribution,whichisthegreencurveinthis

    graph,thetwoempiricaldistributionshaveahigherpeakandheavy-tail,whichis

    normalaccordingtothetextbook.

    -3 -2 -1 0 1 2 3

    0.0

    0.2

    0.4

    0.6

  • 8/7/2019 hw1 Wenbo Zhang

    11/13

    FINN6219 Homework1 WenboZhang

    11

    (c)ConstructQQ-plotforstandardizedIBMandMSFTreturns.YoumayusetheR

    commandforthis.Commentyourresults.

    AccordingtothetwoQQplotgraphsabove,itsonlysimilartostandardnormal

    distributionfrom-2to1.5forIBMstockreturn.Andits-1.5to1.5forMSFTstock

    return.

    -3 -2 -1 0 1 2 3

    0

    5

    10

    15

    20

    25

    Normal Q-Q Plot

    Theoretical Quantiles

    SampleQuantiles

    -3 -2 -1 0 1 2 3

    -2

    0

    2

    4

    6

    8

    10

    Normal Q-Q Plot

    Theoretical Quantiles

    SampleQuantiles

  • 8/7/2019 hw1 Wenbo Zhang

    12/13

    FINN6219 Homework1 WenboZhang

    12

    Rcodes

    Problem1

    library(fTrading)

    library(tseries)

    IBM=read.csv(file="/Users/brianzwb/Documents/Financial

    Econometrics/IBM.csv",header=T,skip=1)

    MSFT=read.csv(file="/Users/brianzwb/Documents/Financial

    Econometrics/MSFT.csv",header=T,skip=1)

    IBMprice=IBM[,5]

    IBMreturn=diff(log(IBMprice))

    MSFTprice=MSFT[,5]

    MSFTreturn=diff(log(MSFTprice))

    MSFTreturn

    r1t=IBMreturn

    r2t=MSFTreturn

    dim(r1t)=c(4,length(r1t)/4)

    monthly1=colSums(r1t)

    r1t=IBMreturn

    dim(r2t)=c(4,length(r2t)/4)

    r2t=r2t[1:1136]

    dim(r2t)=c(4,length(r2t)/4)

    monthly2=colSums(r2t)

    r2t=MSFTreturn

    p1t=IBMprice

    p2t=MSFTpricets.plot(p1t)

    ts.plot(p2t)

    ts.plot(r1t)

    ts.plot(r2t)

    p1rm=rollMean(p1t,13)

    p1rv=rollVar(p1t,13)

    p2rm=rollMean(p2t,13)

    p2rv=rollVar(p2t,13)

    r1rm=rollMean(r1t,13)

    r1rv=rollVar(r1t,13)r2rm=rollMean(r2t,13)

    r2rv=rollVar(r2t,13)

    ts.plot(p1rm)

    ts.plot(p2rm)

    ts.plot(p1rv)

    ts.plot(p2rv)

    ts.plot(t1rm)

  • 8/7/2019 hw1 Wenbo Zhang

    13/13

    FINN6219 Homework1 WenboZhang

    13

    ts.plot(r1rm)

    ts.plot(r2rm)

    ts.plot(r1rv)

    ts.plot(r2rv)

    acf(p1t,5)$acfacf(p2t,5)$acf

    acf(r1t,5)$acf

    acf(r2t,5)$acf

    absr1t=abs(r1t)

    absr2t=abs(r2t)

    absqr1t=r1t^2

    absqr2t=r2t^2

    acf(absr1t)$acf

    acf(absr1t,5)$acf

    acf(absr2t,5)$acfacf(absqr1t,5)$acf

    acf(absqr2t,5)$acf

    jarque.bera.test(r1t)

    jarque.bera.test(r2t)

    Problem2

    d1={r1t-mean(r1t)}/sd(r1t)

    d2={r2t-mean(r2t)}/sd(r2t)

    x0=seq(-3,3,length=100)

    y0=density(d1,n=100,from=-3,to=3)

    y1=y0$y

    qqnorm(d1)

    qqline(d1,col=2)

    y2=density(d2,n=100,from=-3,to=3)

    y3=y2$y

    qqnorm(d2)

    qqline(d2,col=2)

    matplot(x0,cbind(y1,y3),type="l",lty=1:3,xlab="",ylab="")

    matplot(x0,cbind(y1,y3,dnorm(x0)),type="l",lty=c(1,2),xlab="",ylab="")