SlideShare a Scribd company logo
1 of 65
Download to read offline
ESGF 5IFM Q1 2012
Financial Econometric Models
  Vincent JEANNIN – ESGF 5IFM
            Q1 2012




                                vinzjeannin@hotmail.com
                                      1
ESGF 5IFM Q1 2012
Summary of the session

• R Step by Step
• Summary of last session
• OLS & Autocorrelation




                            vinzjeannin@hotmail.com
                                  2
R Step by Step
    Downloadable for free (open source)




                                          ESGF 4IFM Q1 2012
    http://www.r-project.org/




                                          vinzjeannin@hotmail.com
                                                3
Main screen




    vinzjeannin@hotmail.com   ESGF 4IFM Q1 2012
4
Menu: File / New Script




    vinzjeannin@hotmail.com   ESGF 4IFM Q1 2012
5
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




                                                                                6
DATA<-read.csv(file="C:/Users/vin/Desktop/DataFile.csv",header=T)
Run your instruction(s)




    vinzjeannin@hotmail.com   ESGF 4IFM Q1 2012
7
You can call variables anytime you want




                                          ESGF 4IFM Q1 2012
                                          vinzjeannin@hotmail.com
                                                8
vinzjeannin@hotmail.com   ESGF 4IFM Q1 2012
9
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.0710967

summary(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
Easy to show histogram




                                                                       ESGF 4IFM Q1 2012
                                                                       vinzjeannin@hotmail.com
hist(DATA$SPXr, breaks=25, main="Distribution of SPXr", ylab="Freq",   11
                      xlab="SPXr", col="blue")
Obvious Excess Kurtosis




                                                                    ESGF 4IFM Q1 2012
                                          Obvious Asymmetry




                                                                    vinzjeannin@hotmail.com
Functions doesn’t exists directly in R…

However some VNP (Very Nice Programmer) built and shared add-in


              Package Moments                                       12
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
ESGF 4IFM Q1 2012
Once installed, you can load them with the
following instructions:
   require(moments)
   library(moments)




                                             vinzjeannin@hotmail.com
         New functions can now be used!




                                             14
> 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     AMEX
2.411177 5.671254 2.078366 5.770583




                                              vinzjeannin@hotmail.com
Btw, you can store any result in a variable




   > Kur<-kurtosis(DATA$SPXr)
   > Kur
   [1] 5.671254


                                              15
Lost?

Call the help!   help(kurtosis)




                                                            ESGF 4IFM Q1 2012
                            Reminds you the package




                                                            vinzjeannin@hotmail.com
                                   Syntax



                                     Arguments definition

                                                            16
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 histogram
hist(DATA$SPXr, breaks=25,main="S&P Returns / Normal                     Package graphics
Distribution",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
ESGF 4IFM Q1 2012
                                           vinzjeannin@hotmail.com
                                           18

Positive Excess Kurtosis & Negative Skew
Let’s build a spread   Spd<-DATA$SPXr-DATA$AMEX




What 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
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
Portf<-0.5*DATA$SPXr+0.5*DATA$AMEX

plot(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 2012
points(sd(Portf),mean(Portf),col="green")




                                                                              vinzjeannin@hotmail.com
                                                                              21
The efficient frontier




     vinzjeannin@hotmail.com   ESGF 4IFM Q1 2012
22
points(sd(0.1*DATA$SPXr+0.9*DATA$AMEX),mean(0.1*DATA$SPXr+0.9*DATA$AMEX),c
ol="green")

points(sd(0.2*DATA$SPXr+0.8*DATA$AMEX),mean(0.2*DATA$SPXr+0.8*DATA$AMEX),c
ol="green")




                                                                             ESGF 4IFM Q1 2012
points(sd(0.3*DATA$SPXr+0.7*DATA$AMEX),mean(0.3*DATA$SPXr+0.7*DATA$AMEX),c
ol="green")

points(sd(0.4*DATA$SPXr+0.6*DATA$AMEX),mean(0.4*DATA$SPXr+0.6*DATA$AMEX),c
ol="green")




                                                                             vinzjeannin@hotmail.com
points(sd(0.6*DATA$SPXr+0.4*DATA$AMEX),mean(0.6*DATA$SPXr+0.4*DATA$AMEX),c
ol="green")

points(sd(0.7*DATA$SPXr+0.3*DATA$AMEX),mean(0.7*DATA$SPXr+0.3*DATA$AMEX),c
ol="green")

points(sd(0.8*DATA$SPXr+0.2*DATA$AMEX),mean(0.8*DATA$SPXr+0.2*DATA$AMEX),c
ol="green")

points(sd(0.9*DATA$SPXr+0.1*DATA$AMEX),mean(0.9*DATA$SPXr+0.1*DATA$AMEX),c
ol="green")
                                                                             23
plot(DATA$AMEX,DATA$SPXr)
abline(lm(DATA$AMEX~DATA$SPXr), col="blue")




                                              ESGF 4IFM Q1 2012
                                              vinzjeannin@hotmail.com
                                              24
LM stands for Linear Models


> lm(DATA$AMEX~DATA$SPXr)




                                                       ESGF 4IFM Q1 2012
Call:
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
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 a
coin 100 times",xlab="Result of the
trial",ylab="Occurence")
> sum(toss)
[1] 52
                                                                                         26
                     Let’s test the fairness
Density of a binomial distribution

                                     ������ + 1 ! ℎ
             ������ ������ ������ = ℎ, ������ = ������ =         ������ (1 − ������)������
                                      ℎ! ������!




                                                             ESGF 4IFM Q1 2012
               Let’s plot this density with

                 â„Ž = 52
                 ������ = 48




                                                             vinzjeannin@hotmail.com
                 ������ = 100
N<-100
h<-52
t<-48
r<-seq(0,1,length=500)
y<-
(factorial(N+1)/(factorial(h)*factori
al(t)))*r^h*(1-r)^t
plot(r,y,type="l",col="red",main="Pro
bability density to have 52 head out
100 flips")
                                                             27
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?
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 a
coin 100 times",xlab="Result of the
trial",ylab="Occurence")
> sum(toss)
[1] 72
                                                                                         29

                  Let’s test the fairness (assuming you don’t know it’s a trick)
If the probability between 45% and 55% is significant we’ll accept the fairness
N<-100
h<-72
t<-28
r<-seq(0.2,0.8,length=500)
y<-(factorial(N+1)/(factorial(h)*factorial(t)))*r^h*(1-r)^t




                                                                                   ESGF 4IFM Q1 2012
plot(r,y,type="l",col="red",main="Probability density or r given 72
head out 100 flips")




                                                                                   vinzjeannin@hotmail.com
                                                            Trick coin!



                                                                                   30
Summary of the last session
                                                 ������ = ������ ������ = ������������ + ������




                                                                          ESGF 5IFM Q1 2012
                                                    Residual ε




                                                                          vinzjeannin@hotmail.com
               ������                ������

       ������ =          ������������ 2 =          ������������ − ������������������ + ������   2

              ������=1              ������=1



                                                                          31
������                ������                                                 ������

������ =            ������������ 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
������������
       Leads easily to the intercept
������������


                       ������                     ������

               ������ ∗          ������������ + ������������ =          ������������




                                                           ESGF 5IFM Q1 2012
                      ������=1                   ������=1




               ������������������ + ������������ = ������������




                                                           vinzjeannin@hotmail.com
              ������������ + ������ = ������




              ������ = ������ − ������������


                                                           33
������ = ������ − ������������               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
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(������������ −������ )
������                                       Covariance
       ������=1(������������ − ������ )(������������ −   ������)
������ =        ������               2
            ������=1(������������ − ������ )                    Variance




                                                                            ESGF 5IFM Q1 2012
                                              ������������������������������
                                       ������ =
                                                ������2������




                                                                            vinzjeannin@hotmail.com
                                       ������ = ������ − ������������




         ������������������������������                                 Dispersion Regression
  ������ =                                  ������2 =
          ������������ ������������                                    Total Dispersion
                                                                            36
Residuals need to be analysed




                                vinzjeannin@hotmail.com   ESGF 5IFM Q1 2012
                     37
3
                     ������ − ������               ������ ������ − ������ 3
������������������������ ������ = ������                       =
                        ������               ������ ������ − ������ 2 3/2




                                                            ESGF 5IFM Q1 2012
                                                            vinzjeannin@hotmail.com
                                   4
                      ������ − ������              ������ ������ − ������ 4
  ������������������������ ������ = ������                      =
                         ������               ������ ������ − ������ 2 2




                                                            38
Too
Many
Outliers!




                                                     ESGF 5IFM Q1 2012
There should be 2 max
To be normal




                                                     vinzjeannin@hotmail.com
Fatter tails than the
normal distribution

                        Excess kurtosis obvious



                                                     39
                           Fatter and longer tails
ESGF 5IFM Q1 2012
                                                                     vinzjeannin@hotmail.com
Resid<-resid(Reg)
ks.test(Resid, "pnorm")
                                                      Fatter tails

 One-sample Kolmogorov-Smirnov test

data: Resid                                                          40
D = 0.4889, p-value < 2.2e-16         Reject H0 (Normality)
alternative hypothesis: two-sided
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
������                  ������

������ =           ������������ 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?
Simply…   lm(Val$AMEX~Val$SPX-1)



Call:
lm(formula = Val$AMEX ~ Val$SPX - 1)




                                       ESGF 5IFM Q1 2012
Coefficients:
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
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




                                                                           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.com
H0 rejected


Not much better


It’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!
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 2012
But 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…
ESGF 5IFM Q1 2012
                                 vinzjeannin@hotmail.com
Perfect linear dependence

Excellent R-Squared
                                 47
Residuals are a white noise

      What’s the problem then?
ESGF 5IFM Q1 2012
                                                          vinzjeannin@hotmail.com
Do you really think fresh lemon reduces car fatalities?
                                                          48
vinzjeannin@hotmail.com   ESGF 5IFM Q1 2012
49
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.com
The time is easily predictable, isn't it?




                                                            50
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
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
vinzjeannin@hotmail.com   ESGF 5IFM Q1 2012
53
eps<-resid(TReg)
ks.test(eps, "pnorm")
layout(matrix(1:4,2,2))
plot(TReg)




                          ESGF 5IFM Q1 2012
                          vinzjeannin@hotmail.com
                          54
One-sample Kolmogorov-Smirnov test

data: eps
D = 0.1333, p-value = 0.001578
alternative hypothesis: two-sided




                                      ESGF 5IFM Q1 2012
Normality rejected




                                      vinzjeannin@hotmail.com
Regression rejected




What would be the next step?


        Mistake in methodology?
                                      55

        What else could we regress?
lag.plot(Spread$Spark, 9, do.lines=FALSE)




                                            ESGF 5IFM Q1 2012
                                            vinzjeannin@hotmail.com
                                            56

            What is this?
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
ESGF 5IFM Q1 2012
                                               vinzjeannin@hotmail.com
ACF is decreasing slowly

Propagation of autocorrelation due to step 1
                                               58
Main character of non stationary time series

Heteroscedasticity
Need some differentiation


The series has three components

     • Trend




                                             ESGF 5IFM Q1 2012
     • Seasonality
     • Residual

 First order differentiation may be useful




                                             vinzjeannin@hotmail.com
plot(diff(Spread$Spark), type="l")




                             Stationary?


                             Seasonality?    59
No more seasonality




     vinzjeannin@hotmail.com   ESGF 5IFM Q1 2012
60
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
Let’s go back to the stage one of the OLS


         Differentiation can happen before the OLS

NonLin<-




                                                                     ESGF 5IFM Q1 2012
read.csv(file="C:/Users/Vinz/Desktop/ExExp.csv",head=TRUE,sep=",")
plot(NonLin$X,NonLin$VarEp)




                                                                     vinzjeannin@hotmail.com
                                                                     62
         What do you suggest?
Let’s create a new variable


   ������������������������������ = ln(������)




                                        ESGF 5IFM Q1 2012
Lin<-log(NonLin$VarEp)
plot(NonLin$X,Lin)




                                        vinzjeannin@hotmail.com
                               Magic!




                                        63
> 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
Conclusion
        R




                             ESGF 5IFM Q1 2012
        OLS


        Autocorrelation




                             vinzjeannin@hotmail.com
        Residuals


        Normality


        Heteroscedasticity

                             65

More Related Content

Recently uploaded

Solution Manual for Financial Accounting, 11th Edition by Robert Libby, Patri...
Solution Manual for Financial Accounting, 11th Edition by Robert Libby, Patri...Solution Manual for Financial Accounting, 11th Edition by Robert Libby, Patri...
Solution Manual for Financial Accounting, 11th Edition by Robert Libby, Patri...ssifa0344
 
Basic concepts related to Financial modelling
Basic concepts related to Financial modellingBasic concepts related to Financial modelling
Basic concepts related to Financial modellingbaijup5
 
The Economic History of the U.S. Lecture 20.pdf
The Economic History of the U.S. Lecture 20.pdfThe Economic History of the U.S. Lecture 20.pdf
The Economic History of the U.S. Lecture 20.pdfGale Pooley
 
(DIYA) Bhumkar Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(DIYA) Bhumkar Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(DIYA) Bhumkar Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(DIYA) Bhumkar Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
The Economic History of the U.S. Lecture 22.pdf
The Economic History of the U.S. Lecture 22.pdfThe Economic History of the U.S. Lecture 22.pdf
The Economic History of the U.S. Lecture 22.pdfGale Pooley
 
Call Girls Service Nagpur Maya Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Maya Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Maya Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Maya Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
WhatsApp 📞 Call : 9892124323 ✅Call Girls In Chembur ( Mumbai ) secure service
WhatsApp 📞 Call : 9892124323  ✅Call Girls In Chembur ( Mumbai ) secure serviceWhatsApp 📞 Call : 9892124323  ✅Call Girls In Chembur ( Mumbai ) secure service
WhatsApp 📞 Call : 9892124323 ✅Call Girls In Chembur ( Mumbai ) secure servicePooja Nehwal
 
High Class Call Girls Nashik Maya 7001305949 Independent Escort Service Nashik
High Class Call Girls Nashik Maya 7001305949 Independent Escort Service NashikHigh Class Call Girls Nashik Maya 7001305949 Independent Escort Service Nashik
High Class Call Girls Nashik Maya 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
The Economic History of the U.S. Lecture 30.pdf
The Economic History of the U.S. Lecture 30.pdfThe Economic History of the U.S. Lecture 30.pdf
The Economic History of the U.S. Lecture 30.pdfGale Pooley
 
The Economic History of the U.S. Lecture 23.pdf
The Economic History of the U.S. Lecture 23.pdfThe Economic History of the U.S. Lecture 23.pdf
The Economic History of the U.S. Lecture 23.pdfGale Pooley
 
20240429 Calibre April 2024 Investor Presentation.pdf
20240429 Calibre April 2024 Investor Presentation.pdf20240429 Calibre April 2024 Investor Presentation.pdf
20240429 Calibre April 2024 Investor Presentation.pdfAdnet Communications
 
Best VIP Call Girls Noida Sector 18 Call Me: 8448380779
Best VIP Call Girls Noida Sector 18 Call Me: 8448380779Best VIP Call Girls Noida Sector 18 Call Me: 8448380779
Best VIP Call Girls Noida Sector 18 Call Me: 8448380779Delhi Call girls
 
Independent Call Girl Number in Kurla Mumbai📲 Pooja Nehwal 9892124323 💞 Full ...
Independent Call Girl Number in Kurla Mumbai📲 Pooja Nehwal 9892124323 💞 Full ...Independent Call Girl Number in Kurla Mumbai📲 Pooja Nehwal 9892124323 💞 Full ...
Independent Call Girl Number in Kurla Mumbai📲 Pooja Nehwal 9892124323 💞 Full ...Pooja Nehwal
 
Solution Manual for Principles of Corporate Finance 14th Edition by Richard B...
Solution Manual for Principles of Corporate Finance 14th Edition by Richard B...Solution Manual for Principles of Corporate Finance 14th Edition by Richard B...
Solution Manual for Principles of Corporate Finance 14th Edition by Richard B...ssifa0344
 
Pooja 9892124323 : Call Girl in Juhu Escorts Service Free Home Delivery
Pooja 9892124323 : Call Girl in Juhu Escorts Service Free Home DeliveryPooja 9892124323 : Call Girl in Juhu Escorts Service Free Home Delivery
Pooja 9892124323 : Call Girl in Juhu Escorts Service Free Home DeliveryPooja Nehwal
 
03_Emmanuel Ndiaye_Degroof Petercam.pptx
03_Emmanuel Ndiaye_Degroof Petercam.pptx03_Emmanuel Ndiaye_Degroof Petercam.pptx
03_Emmanuel Ndiaye_Degroof Petercam.pptxFinTech Belgium
 
Vip Call US 📞 7738631006 ✅Call Girls In Sakinaka ( Mumbai )
Vip Call US 📞 7738631006 ✅Call Girls In Sakinaka ( Mumbai )Vip Call US 📞 7738631006 ✅Call Girls In Sakinaka ( Mumbai )
Vip Call US 📞 7738631006 ✅Call Girls In Sakinaka ( Mumbai )Pooja Nehwal
 

Recently uploaded (20)

Solution Manual for Financial Accounting, 11th Edition by Robert Libby, Patri...
Solution Manual for Financial Accounting, 11th Edition by Robert Libby, Patri...Solution Manual for Financial Accounting, 11th Edition by Robert Libby, Patri...
Solution Manual for Financial Accounting, 11th Edition by Robert Libby, Patri...
 
Basic concepts related to Financial modelling
Basic concepts related to Financial modellingBasic concepts related to Financial modelling
Basic concepts related to Financial modelling
 
The Economic History of the U.S. Lecture 20.pdf
The Economic History of the U.S. Lecture 20.pdfThe Economic History of the U.S. Lecture 20.pdf
The Economic History of the U.S. Lecture 20.pdf
 
VIP Independent Call Girls in Bandra West 🌹 9920725232 ( Call Me ) Mumbai Esc...
VIP Independent Call Girls in Bandra West 🌹 9920725232 ( Call Me ) Mumbai Esc...VIP Independent Call Girls in Bandra West 🌹 9920725232 ( Call Me ) Mumbai Esc...
VIP Independent Call Girls in Bandra West 🌹 9920725232 ( Call Me ) Mumbai Esc...
 
(DIYA) Bhumkar Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(DIYA) Bhumkar Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(DIYA) Bhumkar Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(DIYA) Bhumkar Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
VIP Independent Call Girls in Andheri 🌹 9920725232 ( Call Me ) Mumbai Escorts...
VIP Independent Call Girls in Andheri 🌹 9920725232 ( Call Me ) Mumbai Escorts...VIP Independent Call Girls in Andheri 🌹 9920725232 ( Call Me ) Mumbai Escorts...
VIP Independent Call Girls in Andheri 🌹 9920725232 ( Call Me ) Mumbai Escorts...
 
The Economic History of the U.S. Lecture 22.pdf
The Economic History of the U.S. Lecture 22.pdfThe Economic History of the U.S. Lecture 22.pdf
The Economic History of the U.S. Lecture 22.pdf
 
Call Girls Service Nagpur Maya Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Maya Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Maya Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Maya Call 7001035870 Meet With Nagpur Escorts
 
WhatsApp 📞 Call : 9892124323 ✅Call Girls In Chembur ( Mumbai ) secure service
WhatsApp 📞 Call : 9892124323  ✅Call Girls In Chembur ( Mumbai ) secure serviceWhatsApp 📞 Call : 9892124323  ✅Call Girls In Chembur ( Mumbai ) secure service
WhatsApp 📞 Call : 9892124323 ✅Call Girls In Chembur ( Mumbai ) secure service
 
High Class Call Girls Nashik Maya 7001305949 Independent Escort Service Nashik
High Class Call Girls Nashik Maya 7001305949 Independent Escort Service NashikHigh Class Call Girls Nashik Maya 7001305949 Independent Escort Service Nashik
High Class Call Girls Nashik Maya 7001305949 Independent Escort Service Nashik
 
VIP Call Girl Service Andheri West âš¡ 9920725232 What It Takes To Be The Best ...
VIP Call Girl Service Andheri West âš¡ 9920725232 What It Takes To Be The Best ...VIP Call Girl Service Andheri West âš¡ 9920725232 What It Takes To Be The Best ...
VIP Call Girl Service Andheri West âš¡ 9920725232 What It Takes To Be The Best ...
 
The Economic History of the U.S. Lecture 30.pdf
The Economic History of the U.S. Lecture 30.pdfThe Economic History of the U.S. Lecture 30.pdf
The Economic History of the U.S. Lecture 30.pdf
 
The Economic History of the U.S. Lecture 23.pdf
The Economic History of the U.S. Lecture 23.pdfThe Economic History of the U.S. Lecture 23.pdf
The Economic History of the U.S. Lecture 23.pdf
 
20240429 Calibre April 2024 Investor Presentation.pdf
20240429 Calibre April 2024 Investor Presentation.pdf20240429 Calibre April 2024 Investor Presentation.pdf
20240429 Calibre April 2024 Investor Presentation.pdf
 
Best VIP Call Girls Noida Sector 18 Call Me: 8448380779
Best VIP Call Girls Noida Sector 18 Call Me: 8448380779Best VIP Call Girls Noida Sector 18 Call Me: 8448380779
Best VIP Call Girls Noida Sector 18 Call Me: 8448380779
 
Independent Call Girl Number in Kurla Mumbai📲 Pooja Nehwal 9892124323 💞 Full ...
Independent Call Girl Number in Kurla Mumbai📲 Pooja Nehwal 9892124323 💞 Full ...Independent Call Girl Number in Kurla Mumbai📲 Pooja Nehwal 9892124323 💞 Full ...
Independent Call Girl Number in Kurla Mumbai📲 Pooja Nehwal 9892124323 💞 Full ...
 
Solution Manual for Principles of Corporate Finance 14th Edition by Richard B...
Solution Manual for Principles of Corporate Finance 14th Edition by Richard B...Solution Manual for Principles of Corporate Finance 14th Edition by Richard B...
Solution Manual for Principles of Corporate Finance 14th Edition by Richard B...
 
Pooja 9892124323 : Call Girl in Juhu Escorts Service Free Home Delivery
Pooja 9892124323 : Call Girl in Juhu Escorts Service Free Home DeliveryPooja 9892124323 : Call Girl in Juhu Escorts Service Free Home Delivery
Pooja 9892124323 : Call Girl in Juhu Escorts Service Free Home Delivery
 
03_Emmanuel Ndiaye_Degroof Petercam.pptx
03_Emmanuel Ndiaye_Degroof Petercam.pptx03_Emmanuel Ndiaye_Degroof Petercam.pptx
03_Emmanuel Ndiaye_Degroof Petercam.pptx
 
Vip Call US 📞 7738631006 ✅Call Girls In Sakinaka ( Mumbai )
Vip Call US 📞 7738631006 ✅Call Girls In Sakinaka ( Mumbai )Vip Call US 📞 7738631006 ✅Call Girls In Sakinaka ( Mumbai )
Vip Call US 📞 7738631006 ✅Call Girls In Sakinaka ( Mumbai )
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data ScienceChristy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

ESGF Financial Models R Session

  • 1. ESGF 5IFM Q1 2012 Financial Econometric Models Vincent JEANNIN – ESGF 5IFM Q1 2012 vinzjeannin@hotmail.com 1
  • 2. ESGF 5IFM Q1 2012 Summary of the session • R Step by Step • Summary of last session • OLS & Autocorrelation vinzjeannin@hotmail.com 2
  • 3. R Step by Step Downloadable for free (open source) ESGF 4IFM Q1 2012 http://www.r-project.org/ vinzjeannin@hotmail.com 3
  • 4. Main screen vinzjeannin@hotmail.com ESGF 4IFM Q1 2012 4
  • 5. Menu: File / New Script vinzjeannin@hotmail.com ESGF 4IFM Q1 2012 5
  • 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 6 DATA<-read.csv(file="C:/Users/vin/Desktop/DataFile.csv",header=T)
  • 7. Run your instruction(s) vinzjeannin@hotmail.com ESGF 4IFM Q1 2012 7
  • 8. You can call variables anytime you want ESGF 4IFM Q1 2012 vinzjeannin@hotmail.com 8
  • 9. vinzjeannin@hotmail.com ESGF 4IFM Q1 2012 9
  • 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.0710967 summary(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. Easy to show histogram ESGF 4IFM Q1 2012 vinzjeannin@hotmail.com hist(DATA$SPXr, breaks=25, main="Distribution of SPXr", ylab="Freq", 11 xlab="SPXr", col="blue")
  • 12. Obvious Excess Kurtosis ESGF 4IFM Q1 2012 Obvious Asymmetry vinzjeannin@hotmail.com Functions doesn’t exists directly in R… However some VNP (Very Nice Programmer) built and shared add-in Package Moments 12
  • 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. ESGF 4IFM Q1 2012 Once installed, you can load them with the following instructions: require(moments) library(moments) vinzjeannin@hotmail.com New functions can now be used! 14
  • 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 AMEX 2.411177 5.671254 2.078366 5.770583 vinzjeannin@hotmail.com Btw, you can store any result in a variable > Kur<-kurtosis(DATA$SPXr) > Kur [1] 5.671254 15
  • 16. Lost? Call the help! help(kurtosis) ESGF 4IFM Q1 2012 Reminds you the package vinzjeannin@hotmail.com Syntax Arguments definition 16
  • 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 histogram hist(DATA$SPXr, breaks=25,main="S&P Returns / Normal Package graphics Distribution",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. ESGF 4IFM Q1 2012 vinzjeannin@hotmail.com 18 Positive Excess Kurtosis & Negative Skew
  • 19. Let’s build a spread Spd<-DATA$SPXr-DATA$AMEX What 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. 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
  • 22. The efficient frontier vinzjeannin@hotmail.com ESGF 4IFM Q1 2012 22
  • 23. points(sd(0.1*DATA$SPXr+0.9*DATA$AMEX),mean(0.1*DATA$SPXr+0.9*DATA$AMEX),c ol="green") points(sd(0.2*DATA$SPXr+0.8*DATA$AMEX),mean(0.2*DATA$SPXr+0.8*DATA$AMEX),c ol="green") ESGF 4IFM Q1 2012 points(sd(0.3*DATA$SPXr+0.7*DATA$AMEX),mean(0.3*DATA$SPXr+0.7*DATA$AMEX),c ol="green") points(sd(0.4*DATA$SPXr+0.6*DATA$AMEX),mean(0.4*DATA$SPXr+0.6*DATA$AMEX),c ol="green") vinzjeannin@hotmail.com points(sd(0.6*DATA$SPXr+0.4*DATA$AMEX),mean(0.6*DATA$SPXr+0.4*DATA$AMEX),c ol="green") points(sd(0.7*DATA$SPXr+0.3*DATA$AMEX),mean(0.7*DATA$SPXr+0.3*DATA$AMEX),c ol="green") points(sd(0.8*DATA$SPXr+0.2*DATA$AMEX),mean(0.8*DATA$SPXr+0.2*DATA$AMEX),c ol="green") points(sd(0.9*DATA$SPXr+0.1*DATA$AMEX),mean(0.9*DATA$SPXr+0.1*DATA$AMEX),c ol="green") 23
  • 24. plot(DATA$AMEX,DATA$SPXr) abline(lm(DATA$AMEX~DATA$SPXr), col="blue") ESGF 4IFM Q1 2012 vinzjeannin@hotmail.com 24
  • 25. LM stands for Linear Models > lm(DATA$AMEX~DATA$SPXr) ESGF 4IFM Q1 2012 Call: 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. 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 a coin 100 times",xlab="Result of the trial",ylab="Occurence") > sum(toss) [1] 52 26 Let’s test the fairness
  • 27. Density of a binomial distribution ������ + 1 ! â„Ž ������ ������ ������ = â„Ž, ������ = ������ = ������ (1 − ������)������ â„Ž! ������! ESGF 4IFM Q1 2012 Let’s plot this density with â„Ž = 52 ������ = 48 vinzjeannin@hotmail.com ������ = 100 N<-100 h<-52 t<-48 r<-seq(0,1,length=500) y<- (factorial(N+1)/(factorial(h)*factori al(t)))*r^h*(1-r)^t plot(r,y,type="l",col="red",main="Pro bability density to have 52 head out 100 flips") 27
  • 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. 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 a coin 100 times",xlab="Result of the trial",ylab="Occurence") > sum(toss) [1] 72 29 Let’s test the fairness (assuming you don’t know it’s a trick)
  • 30. If the probability between 45% and 55% is significant we’ll accept the fairness N<-100 h<-72 t<-28 r<-seq(0.2,0.8,length=500) y<-(factorial(N+1)/(factorial(h)*factorial(t)))*r^h*(1-r)^t ESGF 4IFM Q1 2012 plot(r,y,type="l",col="red",main="Probability density or r given 72 head out 100 flips") vinzjeannin@hotmail.com Trick coin! 30
  • 31. Summary of the last session ������ = ������ ������ = ������������ + ������ ESGF 5IFM Q1 2012 Residual ε vinzjeannin@hotmail.com ������ ������ ������ = ������������ 2 = ������������ − ������������������ + ������ 2 ������=1 ������=1 31
  • 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. ������������ Leads easily to the intercept ������������ ������ ������ ������ ∗ ������������ + ������������ = ������������ ESGF 5IFM Q1 2012 ������=1 ������=1 ������������������ + ������������ = ������������ vinzjeannin@hotmail.com ������������ + ������ = ������ ������ = ������ − ������������ 33
  • 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. 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. ������ Covariance ������=1(������������ − ������ )(������������ − ������) ������ = ������ 2 ������=1(������������ − ������ ) Variance ESGF 5IFM Q1 2012 ������������������������������ ������ = ������2������ vinzjeannin@hotmail.com ������ = ������ − ������������ ������������������������������ Dispersion Regression ������ = ������2 = ������������ ������������ Total Dispersion 36
  • 37. Residuals need to be analysed vinzjeannin@hotmail.com ESGF 5IFM Q1 2012 37
  • 38. 3 ������ − ������ ������ ������ − ������ 3 ������������������������ ������ = ������ = ������ ������ ������ − ������ 2 3/2 ESGF 5IFM Q1 2012 vinzjeannin@hotmail.com 4 ������ − ������ ������ ������ − ������ 4 ������������������������ ������ = ������ = ������ ������ ������ − ������ 2 2 38
  • 39. Too Many Outliers! ESGF 5IFM Q1 2012 There should be 2 max To be normal vinzjeannin@hotmail.com Fatter tails than the normal distribution Excess kurtosis obvious 39 Fatter and longer tails
  • 40. ESGF 5IFM Q1 2012 vinzjeannin@hotmail.com Resid<-resid(Reg) ks.test(Resid, "pnorm") Fatter tails One-sample Kolmogorov-Smirnov test data: Resid 40 D = 0.4889, p-value < 2.2e-16 Reject H0 (Normality) alternative hypothesis: two-sided
  • 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. ������ ������ ������ = ������������ 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. Simply… lm(Val$AMEX~Val$SPX-1) Call: lm(formula = Val$AMEX ~ Val$SPX - 1) ESGF 5IFM Q1 2012 Coefficients: 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. Not much better… vinzjeannin@hotmail.com ESGF 5IFM Q1 2012 44
  • 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.com H0 rejected Not much better It’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. 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 2012 But 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. ESGF 5IFM Q1 2012 vinzjeannin@hotmail.com Perfect linear dependence Excellent R-Squared 47 Residuals are a white noise What’s the problem then?
  • 48. ESGF 5IFM Q1 2012 vinzjeannin@hotmail.com Do you really think fresh lemon reduces car fatalities? 48
  • 49. vinzjeannin@hotmail.com ESGF 5IFM Q1 2012 49
  • 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.com The time is easily predictable, isn't it? 50
  • 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. 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. vinzjeannin@hotmail.com ESGF 5IFM Q1 2012 53
  • 55. One-sample Kolmogorov-Smirnov test data: eps D = 0.1333, p-value = 0.001578 alternative hypothesis: two-sided ESGF 5IFM Q1 2012 Normality rejected vinzjeannin@hotmail.com Regression rejected What would be the next step? Mistake in methodology? 55 What else could we regress?
  • 56. lag.plot(Spread$Spark, 9, do.lines=FALSE) ESGF 5IFM Q1 2012 vinzjeannin@hotmail.com 56 What is this?
  • 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. ESGF 5IFM Q1 2012 vinzjeannin@hotmail.com ACF is decreasing slowly Propagation of autocorrelation due to step 1 58 Main character of non stationary time series Heteroscedasticity
  • 59. Need some differentiation The series has three components • Trend ESGF 5IFM Q1 2012 • Seasonality • Residual First order differentiation may be useful vinzjeannin@hotmail.com plot(diff(Spread$Spark), type="l") Stationary? Seasonality? 59
  • 60. No more seasonality vinzjeannin@hotmail.com ESGF 5IFM Q1 2012 60
  • 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. Let’s go back to the stage one of the OLS Differentiation can happen before the OLS NonLin<- ESGF 5IFM Q1 2012 read.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. Let’s create a new variable ������������������������������ = ln(������) ESGF 5IFM Q1 2012 Lin<-log(NonLin$VarEp) plot(NonLin$X,Lin) vinzjeannin@hotmail.com Magic! 63
  • 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. Conclusion R ESGF 5IFM Q1 2012 OLS Autocorrelation vinzjeannin@hotmail.com Residuals Normality Heteroscedasticity 65