[R-SIG-Finance] Regression & quantmod

Jeff Ryan jeff.a.ryan at gmail.com
Mon Dec 14 18:12:23 CET 2009


The likely problem is the dimensions inherent to xts.

as.numeric is a good approach, but you can also play with the quantmod
specifyModel tools.

An example working directly on your data:

> m <- specifyModel(ClCl(DTE.DE) ~ ClCl(GDAXI))

> periodicity(ClCl(DTE.DE))
Daily periodicity from 2007-01-02 to 2009-12-09

> mb <- buildModel(m,method="lm",training.per=c('2007-01-02','2009-12-09'))
> mb

quantmod object:   lm1260810442.68897   Build date:  2009-12-14 11:07:22

Model Specified:
     ClCl(DTE.DE) ~ ClCl(GDAXI)

Model Target:  ClCl.DTE.DE               Product:  DTE.DE
Model Inputs:  ClCl.GDAXI

Fitted Model:

        Modelling procedure:  lm
        Training window:  723  observations from  2007-01-03 to 2009-12-07

Call:
lm(formula = quantmod at model.formula, data = training.data)

Coefficients:
(Intercept)   ClCl.GDAXI
  3.889e-05    6.515e-01

> summary(mb)

quantmod object:   lm1260810442.68897   Build date:  2009-12-14 11:07:22

Model Specified:
     ClCl(DTE.DE) ~ ClCl(GDAXI)

Model Target:  ClCl.DTE.DE               Product:  DTE.DE
Model Inputs:  ClCl.GDAXI

Fitted Model:

        Modelling procedure:  lm
        Training window:  723  observations from  2007-01-03 to 2009-12-07

Call:
lm(formula = quantmod at model.formula, data = training.data)

Residuals:
       Min         1Q     Median         3Q        Max
-0.0892824 -0.0074720 -0.0002732  0.0070752  0.1521019

Coefficients:
             Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.889e-05  6.033e-04   0.064    0.949
ClCl.GDAXI  6.515e-01  3.302e-02  19.732   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.01622 on 721 degrees of freedom
Multiple R-squared: 0.3507,     Adjusted R-squared: 0.3498
F-statistic: 389.4 on 1 and 721 DF,  p-value: < 2.2e-16


The method= can be (from the docs):

Details:

     Currently available methods include:

     lm, glm, loess, step, ppr, rpart[rpart], tree[tree],
     randomForest[randomForest], mars[mda], polymars[polspline],
     lars[lars], rq[quantreg], lqs[MASS], rlm[MASS], svm[e1071], and
     nnet[nnet].

It is quite experimental still, as its general use is often limited,
but for what you are looking at it may help.

Best,
Jeff

On Mon, Dec 14, 2009 at 10:55 AM, Thomas Etheber <etheber at gmx.de> wrote:
> Hi all,
>
> I just wanted to estimate a single index model using the quotes derived from
> the quantmod-package as pasted below.
>
> Does somebody know why the first regression is not working as expected? Why
> do I have to cast the xts series to the datatype numeric or what am I
> missing?
>
> Best regards,
> Thomas
>
> <<<<<<<<<<<<<<
>
> require("quantmod")
> getSymbols( "DTE.DE")
> getSymbols( "^GDAXI")
> dteReturns <- ClCl( DTE.DE )
> daxReturns <- ClCl(GDAXI)
> dteReturn <- merge( dteReturn, daxReturn, all=FALSE)[,1]
> daxReturn <- merge( dteReturn, daxReturn, all=FALSE)[,2]
> m <- lm ( dteReturn ~ daxReturn )
> summary(m)
>
> Call:
> lm(formula = dteReturn ~ daxReturn)
>
> Residuals:
> Fehler in dimnames(x) <- dn :
> Länge von 'dimnames' [2] ungleich der Arrayausdehnung
>
>> m <- lm ( as.numeric(dteReturn) ~ as.numeric( daxReturn ) )
>> summary(m)
>
> Call:
> lm(formula = as.numeric(dteReturn) ~ as.numeric(daxReturn))
>
> Residuals:
> Min 1Q Median 3Q Max
> -9.411e-02 -7.405e-03 2.835e-05 7.409e-03 1.524e-01
>
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> (Intercept) -0.0002645 0.0006123 -0.432 0.666
> as.numeric(daxReturn) 0.6378738 0.0334159 19.089 <2e-16 ***
> ---
> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> Residual standard error: 0.01661 on 734 degrees of freedom
> (1 observation deleted due to missingness)
> Multiple R-squared: 0.3317, Adjusted R-squared: 0.3308
> F-statistic: 364.4 on 1 and 734 DF, p-value: < 2.2e-16
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list