ESGF 5IFM Q1 2012Financial Econometric Models  Vincent JEANNIN – ESGF 5IFM            Q1 2012                             ...
ESGF 5IFM Q1 2012Summary of the session• R Step by Step• Summary of last session• OLS & Autocorrelation                   ...
R Step by Step    Downloadable for free (open source)                                          ESGF 4IFM Q1 2012    http:/...
Main screen    vinzjeannin@hotmail.com   ESGF 4IFM Q1 20124
Menu: File / New Script    vinzjeannin@hotmail.com   ESGF 4IFM Q1 20125
Step 1, upload your data       Excel CSV file easy to import                                                              ...
Run your instruction(s)    vinzjeannin@hotmail.com   ESGF 4IFM Q1 20127
You can call variables anytime you want                                          ESGF 4IFM Q1 2012                        ...
vinzjeannin@hotmail.com   ESGF 4IFM Q1 20129
summary(DATA)           Shows a quick summary of the distribution of all variables  SPX               SPXr                ...
Easy to show histogram                                                                       ESGF 4IFM Q1 2012            ...
Obvious Excess Kurtosis                                                                    ESGF 4IFM Q1 2012              ...
Menu: Packages / Install Package(s)                                                      ESGF 4IFM Q1 2012                ...
ESGF 4IFM Q1 2012Once installed, you can load them with thefollowing instructions:   require(moments)   library(moments)  ...
> require(moments)> library(moments)> skewness(DATA)       SPX       SPXr      AMEXr      AMEX-0.6358029 -0.4178701 0.1876...
Lost?Call the help!   help(kurtosis)                                                            ESGF 4IFM Q1 2012         ...
Let’s store a few values                   SPMean<-mean(DATA$SPXr)                   SPSD<-sd(DATA$SPXr)                  ...
ESGF 4IFM Q1 2012                                           vinzjeannin@hotmail.com                                       ...
Let’s build a spread   Spd<-DATA$SPXr-DATA$AMEXWhat is the mean?                                                          ...
What is the standard deviation?                    Is standard deviation linear?                                          ...
Portf-0.5*DATA$SPXr+0.5*DATA$AMEXplot(sd(DATA$SPXr),mean(DATA$SPXr),col=blue,ylim=c(0,0.0008),xlim=c(0.012,0.022),ylab=Ret...
The efficient frontier     vinzjeannin@hotmail.com   ESGF 4IFM Q1 201222
points(sd(0.1*DATA$SPXr+0.9*DATA$AMEX),mean(0.1*DATA$SPXr+0.9*DATA$AMEX),col=green)points(sd(0.2*DATA$SPXr+0.8*DATA$AMEX),...
plot(DATA$AMEX,DATA$SPXr)abline(lm(DATA$AMEX~DATA$SPXr), col=blue)                                              ESGF 4IFM ...
LM stands for Linear Models lm(DATA$AMEX~DATA$SPXr)                                                       ESGF 4IFM Q1 201...
Do you remember what is the most platykurtic distribution in the nature?                                  Toss         Hea...
Density of a binomial distribution                                      + 1 ! ℎ                = ℎ,  =  =          (1 − ) ...
If the probability between 45% and 55% is significant we’ll accept the fairness                                           ...
What is the problem with this coin?                                 Obvious fake! Assuming the probability of head is 0.7 ...
If the probability between 45% and 55% is significant we’ll accept the fairnessN-100h-72t-28r-seq(0.2,0.8,length=500)y-(fa...
Summary of the last session                                                  =   =  +                                     ...
=             2 =              −  +                2   =           −  −       2         =1              =1                ...
Leads easily to the intercept                                                            ∗           +  =                 ...
=  −                y =  +  −                                       y −  = ( −  )                                         ...
We have                                                                    ( −  −   −  ) = 0       and                (  −...
Covariance       =1( −  )( −   ) =                       2            =1( −  )                    Variance                ...
Residuals need to be analysed                                vinzjeannin@hotmail.com   ESGF 5IFM Q1 2012                  ...
3                      −                  −  3  =                        =                                         −  2 3/...
TooManyOutliers!                                                     ESGF 5IFM Q1 2012There should be 2 maxTo be normal   ...
ESGF 5IFM Q1 2012                                                                     vinzjeannin@hotmail.comResid-resid(R...
OLS  Autocorrelation     New idea… No intercept                                                                   ESGF 5IF...
=            2 =               −    2        =1                =1                   Quick high school reminder if necessar...
Simply…   lm(Val$AMEX~Val$SPX-1)Call:lm(formula = Val$AMEX ~ Val$SPX - 1)                                       ESGF 5IFM ...
Not much better…                        vinzjeannin@hotmail.com   ESGF 5IFM Q1 2012                   44
ks.test(resid(lm(Val$AMEX~Val$SPX-1)), pnorm)              One-sample Kolmogorov-Smirnov test                             ...
The purpose was to see if the market as effect an effect on a particular stock    The dependence is obvious but residuals ...
ESGF 5IFM Q1 2012                                 vinzjeannin@hotmail.comPerfect linear dependenceExcellent R-Squared     ...
ESGF 5IFM Q1 2012                                                          vinzjeannin@hotmail.comDo you really think fres...
vinzjeannin@hotmail.com   ESGF 5IFM Q1 201249
How to use OLS to make predictions?                                                            ESGF 5IFM Q1 2012      Not ...
Spread-read.csv(file=C:/Users/Vin/Desktop/SparkSpd.csv,head=TRUE,sep=,)plot(Spread$Nb,Spread$Spark, main=Spark Spread Aug0...
plot(Spread$Nb,Spread$Spark, main=Spark Spread Aug07-Aug08, xlab=Time,ylab=Dirty Spark Spread, col=red)TReg-lm(Spread$Spar...
vinzjeannin@hotmail.com   ESGF 5IFM Q1 201253
eps-resid(TReg)ks.test(eps, pnorm)layout(matrix(1:4,2,2))plot(TReg)                          ESGF 5IFM Q1 2012            ...
One-sample Kolmogorov-Smirnov testdata: epsD = 0.1333, p-value = 0.001578alternative hypothesis: two-sided                ...
lag.plot(Spread$Spark, 9, do.lines=FALSE)                                            ESGF 5IFM Q1 2012                    ...
Lag Plots!                                Maybe the series is auto-correlated to itself…                                Se...
ESGF 5IFM Q1 2012                                               vinzjeannin@hotmail.comACF is decreasing slowlyPropagation...
Need some differentiationThe series has three components     • Trend                                             ESGF 5IFM...
No more seasonality     vinzjeannin@hotmail.com   ESGF 5IFM Q1 201260
Differentiation bring new horizons…                                                           ESGF 5IFM Q1 2012           ...
Let’s go back to the stage one of the OLS         Differentiation can happen before the OLSNonLin-                        ...
Let’s create a new variable    = ln()                                        ESGF 5IFM Q1 2012Lin-log(NonLin$VarEp)plot(No...
lm(Lin~NonLin$X)Call:lm(formula = Lin ~ NonLin$X)                               layout(matrix(1:4,2,2))Coefficients:      ...
Conclusion        R                             ESGF 5IFM Q1 2012        OLS        Autocorrelation                       ...
Upcoming SlideShare
Loading in...5
×

Financial Econometric Models II

479

Published on

Financial Econometric Models, course II, Busines School MSc level

Published in: Economy & Finance
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
479
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
18
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Financial Econometric Models II

  1. 1. ESGF 5IFM Q1 2012Financial Econometric Models Vincent JEANNIN – ESGF 5IFM Q1 2012 vinzjeannin@hotmail.com 1
  2. 2. ESGF 5IFM Q1 2012Summary of the session• R Step by Step• Summary of last session• OLS & Autocorrelation vinzjeannin@hotmail.com 2
  3. 3. R Step by Step Downloadable for free (open source) ESGF 4IFM Q1 2012 http://www.r-project.org/ vinzjeannin@hotmail.com 3
  4. 4. Main screen vinzjeannin@hotmail.com ESGF 4IFM Q1 20124
  5. 5. Menu: File / New Script vinzjeannin@hotmail.com ESGF 4IFM Q1 20125
  6. 6. Step 1, upload your data Excel CSV file easy to import ESGF 4IFM Q1 2012 Path C:UsersvinDesktop vinzjeannin@hotmail.com Note: 4 columns with headers 6DATA<-read.csv(file="C:/Users/vin/Desktop/DataFile.csv",header=T)
  7. 7. Run your instruction(s) vinzjeannin@hotmail.com ESGF 4IFM Q1 20127
  8. 8. You can call variables anytime you want ESGF 4IFM Q1 2012 vinzjeannin@hotmail.com 8
  9. 9. vinzjeannin@hotmail.com ESGF 4IFM Q1 20129
  10. 10. summary(DATA) Shows a quick summary of the distribution of all variables SPX SPXr AMEXr AMEX Min. : 86.43 Min. :-0.0666344 Min. : 97.6 Min. :-0.0883287 1st Qu.: 95.70 1st Qu.:-0.0069082 1st Qu.:104.7 1st Qu.:-0.0094580 Median :100.79 Median : 0.0010016 Median :108.8 Median : 0.0013007 ESGF 4IFM Q1 2012 Mean : 99.67 Mean : 0.0001249 Mean :109.4 Mean : 0.0005891 3rd Qu.:103.75 3rd Qu.: 0.0075235 3rd Qu.:114.1 3rd Qu.: 0.0102923 Max. :107.21 Max. : 0.0474068 Max. :123.5 Max. : 0.0710967summary(DATA$SPX) Shows a quick summary of the distribution of one variable vinzjeannin@hotmail.com Min. 1st Qu. Median Mean 3rd Qu. Max. 86.43 95.70 100.80 99.67 103.80 107.20 min(DATA) Careful using the following instructions max(DATA) > min(DATA) [1] -0.08832874 This will consider DATA as one variable > max(DATA) [1] 123.4793 > sd(DATA) SPX SPXr AMEXr AMEX 4.92763551 0.01468776 6.03035318 0.01915489 10 Mean & SD > mean(DATA) SPX SPXr AMEXr AMEX 9.967046e+01 1.249283e-04 1.093951e+02 5.890780e-04
  11. 11. Easy to show histogram ESGF 4IFM Q1 2012 vinzjeannin@hotmail.comhist(DATA$SPXr, breaks=25, main="Distribution of SPXr", ylab="Freq", 11 xlab="SPXr", col="blue")
  12. 12. Obvious Excess Kurtosis ESGF 4IFM Q1 2012 Obvious Asymmetry vinzjeannin@hotmail.comFunctions doesn’t exists directly in R…However some VNP (Very Nice Programmer) built and shared add-in Package Moments 12
  13. 13. Menu: Packages / Install Package(s) ESGF 4IFM Q1 2012 vinzjeannin@hotmail.com• Choose whatever mirror (server) you want• Usually France (Toulouse) is very good as it’s a University Server with all the packages available 13
  14. 14. ESGF 4IFM Q1 2012Once installed, you can load them with thefollowing instructions: require(moments) library(moments) vinzjeannin@hotmail.com New functions can now be used! 14
  15. 15. > require(moments)> library(moments)> skewness(DATA) SPX SPXr AMEXr AMEX-0.6358029 -0.4178701 0.1876994 -0.2453693 ESGF 4IFM Q1 2012> kurtosis(DATA) SPX SPXr AMEXr AMEX2.411177 5.671254 2.078366 5.770583 vinzjeannin@hotmail.comBtw, you can store any result in a variable > Kur<-kurtosis(DATA$SPXr) > Kur [1] 5.671254 15
  16. 16. Lost?Call the help! help(kurtosis) ESGF 4IFM Q1 2012 Reminds you the package vinzjeannin@hotmail.com Syntax Arguments definition 16
  17. 17. Let’s store a few values SPMean<-mean(DATA$SPXr) SPSD<-sd(DATA$SPXr) Package Stats Build a sequence, the x axis ESGF 4IFM Q1 2012 x<-seq(from=SPMean-4*SPSD,to=SPMean+4*SPSD,length=500) Build a normal density on these x vinzjeannin@hotmail.com Y1<-dnorm(x,mean=SPMean,sd=SPSD) Package Stats Display the histogramhist(DATA$SPXr, breaks=25,main="S&P Returns / Normal Package graphicsDistribution",xlab="Returns",ylab="Occurences", col="blue") Display on top of it the normal density lines(x,y1,type="l",lwd=3,col="red") Package graphics 17
  18. 18. ESGF 4IFM Q1 2012 vinzjeannin@hotmail.com 18Positive Excess Kurtosis & Negative Skew
  19. 19. Let’s build a spread Spd<-DATA$SPXr-DATA$AMEXWhat is the mean? ESGF 4IFM Q1 2012 Mean is linear + = + () − = − () vinzjeannin@hotmail.com Let’s verify mean(DATA$SPXr)-mean(DATA$AMEX)-mean(Spd)[1] 0 19
  20. 20. What is the standard deviation? Is standard deviation linear? NO! ESGF 4IFM Q1 2012 VAR + = 2 + 2 + 2(, ) (var(DATA$SPXr)+var(DATA$AMEX)-2*cov(DATA$SPXr,DATA$AMEX))^0.5 vinzjeannin@hotmail.com[1] 0.01019212 sd(Spd)[1] 0.01019212 Let’s show the implication in a proper manner Let’s create a portfolio containing half of each stocks 20
  21. 21. Portf-0.5*DATA$SPXr+0.5*DATA$AMEXplot(sd(DATA$SPXr),mean(DATA$SPXr),col=blue,ylim=c(0,0.0008),xlim=c(0.012,0.022),ylab=Return,xlab=Vol)points(sd(DATA$AMEX),mean(DATA$AMEX),col=red) ESGF 4IFM Q1 2012points(sd(Portf),mean(Portf),col=green) vinzjeannin@hotmail.com 21
  22. 22. The efficient frontier vinzjeannin@hotmail.com ESGF 4IFM Q1 201222
  23. 23. points(sd(0.1*DATA$SPXr+0.9*DATA$AMEX),mean(0.1*DATA$SPXr+0.9*DATA$AMEX),col=green)points(sd(0.2*DATA$SPXr+0.8*DATA$AMEX),mean(0.2*DATA$SPXr+0.8*DATA$AMEX),col=green) ESGF 4IFM Q1 2012points(sd(0.3*DATA$SPXr+0.7*DATA$AMEX),mean(0.3*DATA$SPXr+0.7*DATA$AMEX),col=green)points(sd(0.4*DATA$SPXr+0.6*DATA$AMEX),mean(0.4*DATA$SPXr+0.6*DATA$AMEX),col=green) vinzjeannin@hotmail.compoints(sd(0.6*DATA$SPXr+0.4*DATA$AMEX),mean(0.6*DATA$SPXr+0.4*DATA$AMEX),col=green)points(sd(0.7*DATA$SPXr+0.3*DATA$AMEX),mean(0.7*DATA$SPXr+0.3*DATA$AMEX),col=green)points(sd(0.8*DATA$SPXr+0.2*DATA$AMEX),mean(0.8*DATA$SPXr+0.2*DATA$AMEX),col=green)points(sd(0.9*DATA$SPXr+0.1*DATA$AMEX),mean(0.9*DATA$SPXr+0.1*DATA$AMEX),col=green) 23
  24. 24. plot(DATA$AMEX,DATA$SPXr)abline(lm(DATA$AMEX~DATA$SPXr), col=blue) ESGF 4IFM Q1 2012 vinzjeannin@hotmail.com 24
  25. 25. LM stands for Linear Models lm(DATA$AMEX~DATA$SPXr) ESGF 4IFM Q1 2012Call:lm(formula = DATA$AMEX ~ DATA$SPXr)Coefficients:(Intercept) DATA$SPXr 0.0004505 1.1096287 vinzjeannin@hotmail.com = 1.1096 + 0.04%Will be used later for linear regression and hedging 25
  26. 26. Do you remember what is the most platykurtic distribution in the nature? Toss Head = Success = 1 / Tail = Failure = 0 ESGF 4IFM Q1 2012 100 toss… Else memory issue… require(moments)Loading required package: moments library(moments) vinzjeannin@hotmail.com toss-rbinom(100,1,0.5) mean(toss)[1] 0.52 kurtosis(toss)[1] 1.006410 kurtosis(toss)-3[1] -1.993590 hist(toss, breaks=10,main=Tossing acoin 100 times,xlab=Result of thetrial,ylab=Occurence) sum(toss)[1] 52 26 Let’s test the fairness
  27. 27. Density of a binomial distribution + 1 ! ℎ = ℎ, = = (1 − ) ℎ! ! ESGF 4IFM Q1 2012 Let’s plot this density with ℎ = 52 = 48 vinzjeannin@hotmail.com = 100N-100h-52t-48r-seq(0,1,length=500)y-(factorial(N+1)/(factorial(h)*factorial(t)))*r^h*(1-r)^tplot(r,y,type=l,col=red,main=Probability density to have 52 head out100 flips) 27
  28. 28. If the probability between 45% and 55% is significant we’ll accept the fairness ESGF 4IFM Q1 2012 vinzjeannin@hotmail.com 28 What do you think?
  29. 29. What is the problem with this coin? Obvious fake! Assuming the probability of head is 0.7 Toss it! Head = Success = 1 / Tail = Failure = 0 ESGF 4IFM Q1 2012 100 toss require(moments)Loading required package: moments library(moments) vinzjeannin@hotmail.com toss-rbinom(100,1,0.7) mean(toss)[1] 0.72 kurtosis(toss)[1] 1.960317 kurtosis(toss)-3[1] -1.039683 hist(toss, breaks=10,main=Tossing acoin 100 times,xlab=Result of thetrial,ylab=Occurence) sum(toss)[1] 72 29 Let’s test the fairness (assuming you don’t know it’s a trick)
  30. 30. If the probability between 45% and 55% is significant we’ll accept the fairnessN-100h-72t-28r-seq(0.2,0.8,length=500)y-(factorial(N+1)/(factorial(h)*factorial(t)))*r^h*(1-r)^t ESGF 4IFM Q1 2012plot(r,y,type=l,col=red,main=Probability density or r given 72head out 100 flips) vinzjeannin@hotmail.com Trick coin! 30
  31. 31. Summary of the last session = = + ESGF 5IFM Q1 2012 Residual ε vinzjeannin@hotmail.com = 2 = − + 2 =1 =1 31
  32. 32. = 2 = − + 2 = − − 2 =1 =1 =1 Quick high school reminder if necessary… ESGF 5IFM Q1 2012 − − 2 = 2 − 2 − 2 + 2 2 + 2 + 2 vinzjeannin@hotmail.com = −2 + 2 2 + 2 = 0 = −2 + 2 + 2 = 0 =1 =1 − + 2 + = 0 − + + = 0=1 =1 ∗ 2 + ∗ = ∗ + = =1 =1 =1 =1 =1 32
  33. 33. Leads easily to the intercept ∗ + = ESGF 5IFM Q1 2012 =1 =1 + = vinzjeannin@hotmail.com + = = − 33
  34. 34. = − y = + − y − = ( − ) ESGF 5IFM Q1 2012 = −2 + 2 2 + 2 = 0 = −2 + 2 + 2 = 0 =1 =1 vinzjeannin@hotmail.com − − = 0 − − = 0 =1 =1 − − + = 0 =1 − + − = 0 =1 ( − − − ) = 0 ( − ) − ( − ) = 0 =1 =1 34 ( − − − ) = 0 =1
  35. 35. We have ( − − − ) = 0 and ( − − − ) = 0=1 =1 ESGF 5IFM Q1 2012 ( − − − ) = ( − − − ) =1 =1 vinzjeannin@hotmail.com ( − − − ) − − − − =0 =1 =1 ( − )( − − − ) = 0 =1 Finally… =1( − )( − ) 35 = 2 =1( − )
  36. 36. Covariance =1( − )( − ) = 2 =1( − ) Variance ESGF 5IFM Q1 2012 = 2 vinzjeannin@hotmail.com = − Dispersion Regression = 2 = Total Dispersion 36
  37. 37. Residuals need to be analysed vinzjeannin@hotmail.com ESGF 5IFM Q1 2012 37
  38. 38. 3 − − 3 = = − 2 3/2 ESGF 5IFM Q1 2012 vinzjeannin@hotmail.com 4 − − 4 = = − 2 2 38
  39. 39. TooManyOutliers! ESGF 5IFM Q1 2012There should be 2 maxTo be normal vinzjeannin@hotmail.comFatter tails than thenormal distribution Excess kurtosis obvious 39 Fatter and longer tails
  40. 40. ESGF 5IFM Q1 2012 vinzjeannin@hotmail.comResid-resid(Reg)ks.test(Resid, pnorm) Fatter tails One-sample Kolmogorov-Smirnov testdata: Resid 40D = 0.4889, p-value 2.2e-16 Reject H0 (Normality)alternative hypothesis: two-sided
  41. 41. OLS Autocorrelation New idea… No intercept ESGF 5IFM Q1 2012 Only one parameters to estimate: • Slope β Minimising residuals vinzjeannin@hotmail.com = 2 = − 2 =1 =1 When E is minimal? 41 When partial derivatives i.r.w. a is 0
  42. 42. = 2 = − 2 =1 =1 Quick high school reminder if necessary… ESGF 5IFM Q1 2012 − 2 = 2 − 2 + 2 2 vinzjeannin@hotmail.com = −2 + 2 2 = 0 =1 =1 − 2 = 0 = 2 =1 =1 ∗ =2 = 2 =1 =1 42 Any better?
  43. 43. Simply… lm(Val$AMEX~Val$SPX-1)Call:lm(formula = Val$AMEX ~ Val$SPX - 1) ESGF 5IFM Q1 2012Coefficients:Val$SPX 1.11 vinzjeannin@hotmail.com Let’s follow the same process layout(matrix(1:4,2,2)) plot(lm(Val$AMEX~Val$SPX-1)) 43
  44. 44. Not much better… vinzjeannin@hotmail.com ESGF 5IFM Q1 2012 44
  45. 45. ks.test(resid(lm(Val$AMEX~Val$SPX-1)), pnorm) One-sample Kolmogorov-Smirnov test ESGF 5IFM Q1 2012 data: resid(lm(Val$AMEX ~ Val$SPX - 1)) D = 0.4887, p-value 2.2e-16 alternative hypothesis: two-sided vinzjeannin@hotmail.comH0 rejectedNot much betterIt’s the way statistics are… You look for, but sometimes you don’t find! 45 However you can now regress without intercept and that’s great!
  46. 46. The purpose was to see if the market as effect an effect on a particular stock The dependence is obvious but residuals too volatile for any stable application ESGF 5IFM Q1 2012But attention! We are looking for causation, not correlation! Causation implies correlation vinzjeannin@hotmail.com Reciprocity is not true! DON’T BE FOOLED BY PRETTY NUMBERS 46 Let prove this…
  47. 47. ESGF 5IFM Q1 2012 vinzjeannin@hotmail.comPerfect linear dependenceExcellent R-Squared 47Residuals are a white noise What’s the problem then?
  48. 48. ESGF 5IFM Q1 2012 vinzjeannin@hotmail.comDo you really think fresh lemon reduces car fatalities? 48
  49. 49. vinzjeannin@hotmail.com ESGF 5IFM Q1 201249
  50. 50. How to use OLS to make predictions? ESGF 5IFM Q1 2012 Not possible with 2 random variables Need to find a variable with any future value known That would leave the randomness to only 1 variable vinzjeannin@hotmail.comThe time is easily predictable, isnt it? 50
  51. 51. Spread-read.csv(file=C:/Users/Vin/Desktop/SparkSpd.csv,head=TRUE,sep=,)plot(Spread$Nb,Spread$Spark, main=Spark Spread Aug07-Aug08,xlab=Time, ylab=Dirty Spark Spread, col=red, type=l) ESGF 5IFM Q1 2012 vinzjeannin@hotmail.com 51 Clear trend with seasonality
  52. 52. plot(Spread$Nb,Spread$Spark, main=Spark Spread Aug07-Aug08, xlab=Time,ylab=Dirty Spark Spread, col=red)TReg-lm(Spread$Spark~Spread$Nb)summary(TReg)abline(TReg, col=blue) Call: ESGF 5IFM Q1 2012 lm(formula = Spread$Spark ~ Spread$Nb) Residuals: Min 1Q Median 3Q Max -1.19775 -0.51046 0.01431 0.50554 1.44953 vinzjeannin@hotmail.com Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 1.137e+01 8.873e-02 128.19 2e-16 *** Spread$Nb 2.173e-02 7.618e-04 28.53 2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.6266 on 199 degrees of freedom Multiple R-squared: 0.8035, Adjusted R-squared: 0.8025 F-statistic: 813.9 on 1 and 199 DF, p-value: 2.2e-16 52
  53. 53. vinzjeannin@hotmail.com ESGF 5IFM Q1 201253
  54. 54. eps-resid(TReg)ks.test(eps, pnorm)layout(matrix(1:4,2,2))plot(TReg) ESGF 5IFM Q1 2012 vinzjeannin@hotmail.com 54
  55. 55. One-sample Kolmogorov-Smirnov testdata: epsD = 0.1333, p-value = 0.001578alternative hypothesis: two-sided ESGF 5IFM Q1 2012Normality rejected vinzjeannin@hotmail.comRegression rejectedWhat would be the next step? Mistake in methodology? 55 What else could we regress?
  56. 56. lag.plot(Spread$Spark, 9, do.lines=FALSE) ESGF 5IFM Q1 2012 vinzjeannin@hotmail.com 56 What is this?
  57. 57. Lag Plots! Maybe the series is auto-correlated to itself… Seems the case with 1 to 6 lags ESGF 5IFM Q1 2012 par(mfrow=c(2,1)) acf(Spread$Spark,20) pacf(Spread$Spark,20) vinzjeannin@hotmail.com This will show correlogram (ACF) = ( − − ) Correlation between pairs of values of {Yt}, separated by an interval of length k. This will show the partial auto-correlation (PACF) Correlation between the current value and the value k periods ago, after controlling for observations at intermediate lags (identifying intermediate lag effects) 57
  58. 58. ESGF 5IFM Q1 2012 vinzjeannin@hotmail.comACF is decreasing slowlyPropagation of autocorrelation due to step 1 58Main character of non stationary time seriesHeteroscedasticity
  59. 59. Need some differentiationThe series has three components • Trend ESGF 5IFM Q1 2012 • Seasonality • Residual First order differentiation may be useful vinzjeannin@hotmail.complot(diff(Spread$Spark), type=l) Stationary? Seasonality? 59
  60. 60. No more seasonality vinzjeannin@hotmail.com ESGF 5IFM Q1 201260
  61. 61. Differentiation bring new horizons… ESGF 5IFM Q1 2012 vinzjeannin@hotmail.com The whole point is to show you the methodology Step by steps… Sometimes unsuccessfully (bad results) 61
  62. 62. Let’s go back to the stage one of the OLS Differentiation can happen before the OLSNonLin- ESGF 5IFM Q1 2012read.csv(file=C:/Users/Vinz/Desktop/ExExp.csv,head=TRUE,sep=,)plot(NonLin$X,NonLin$VarEp) vinzjeannin@hotmail.com 62 What do you suggest?
  63. 63. Let’s create a new variable = ln() ESGF 5IFM Q1 2012Lin-log(NonLin$VarEp)plot(NonLin$X,Lin) vinzjeannin@hotmail.com Magic! 63
  64. 64. lm(Lin~NonLin$X)Call:lm(formula = Lin ~ NonLin$X) layout(matrix(1:4,2,2))Coefficients: plot(lm(Lin~NonLin$X)) ESGF 5IFM Q1 2012(Intercept) NonLin$X -4.605 1.000 vinzjeannin@hotmail.com Do not hesitate to transform 64
  65. 65. Conclusion R ESGF 5IFM Q1 2012 OLS Autocorrelation vinzjeannin@hotmail.com Residuals Normality Heteroscedasticity 65
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×