[R-sig-finance] Using data from yahooImport (fBasics)

Diethelm Wuertz wuertz at itp.phys.ethz.ch
Fri Apr 7 11:08:07 CEST 2006


Ajay Narottam Shah wrote:

>>require(fMultivar)
>>myFinCenter = "GMT"
>>
>># Download -> Data Slot -> As Time Series -> Close
>># GET Closing Prices: 2005-06-01 until now - see help(yahooImport)
>>query = "s=^GDAXI&a=5&b=1&c=2005&d=0&q=31&f=2009&z=^GDAXI&x=.csv"
>>DAX.CLOSE = as.timeSeries(yahooImport(query)@data)[,"Close"]
>>query = "s=DCX.DE&a=5&b=1&c=2005&d=0&q=31&f=2009&z=DCX.DE&x=.csv"
>>DCX.CLOSE = as.timeSeries(yahooImport(query)@data)[,"Close"]
>>
>># Align to daily dates: --- So both time series will have afterwards the 
>>same time stamps
>># Consult help(timeSeries)
>>DAX.ALIGNED = alignDailySeries(DAX.CLOSE, method = "interp")
>>DCX.ALIGNED = alignDailySeries(DCX.CLOSE, method = "interp")
>>
>># Cut Common Piece from each:  --- help(timeDate)
>>START = modify(c(start(DAX.ALIGNED), start(DCX.ALIGNED)), "sort")[2]
>>END = modify(c(end(DAX.ALIGNED), end(DCX.ALIGNED)), "sort")[1]
>>DAX.CUTTED = cutSeries(DAX.ALIGNED, from = START, to = END)
>>DCX.CUTTED = cutSeries(DCX.ALIGNED, from = START, to = END)
>>
>># Merge the two Series:
>>DCXDAX = mergeSeries(DCX.CUTTED, DAX.CUTTED at Data, units = c("DCX", "DAX"))
>>
>># Compute Return Series:
>>DCXDAX.RET = as.data.frame(returnSeries(DCXDAX))
>>
>># Compute Beta: --- linear Modelling:
>>c(Beta = lm(formula = DCX ~ DAX, data = DCXDAX.RET)$coef[2])
>>
>>Beta.DAX
>>1.320997
>>    
>>
>
>This looks like hard work! It's easier using R + zoo:
>  
>
Come On!!!!
If it is really so easy in R+zoo, be fair enough and show us how we can 
do it in 10 or less lines!
I'm waiting for it ...

Thanks Diethelm

>       http://www.mayin.org/ajayshah/KB/R/html/o6.html
>       http://www.mayin.org/ajayshah/KB/R/html/o5.html
>
>  
>



More information about the R-sig-finance mailing list