[R-SIG-Finance] Computation on xts

me at censix.com me at censix.com
Sat Apr 30 07:39:48 CEST 2011


> Hi,
>
> I have the following time series in xts
>
>> getSymbols("SBUX");
> [1] "SBUX"
> Warning message:
> In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :
>   downloaded length 53650 != reported length 200
>
> Then I tried to compute something row-wise. In my below example, I
> simple compute daily notional using close price. I want to add the
> result back as a new column in my existing time series. But it doesn't
> seem to work. I'm not sure if I have missed anything. Thank you.
>
>>SBUX[,"TurnOver"] <- SBUX[,"SBUX.Close"]*SBUX[,"SBUX.Volume"]
> Error in NextMethod(.Generic) : subscript out of bounds
>
> Cheers,
>
> Robert
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>

Hi,

I guess one way to do it would be

   SBUX <-cbind(SBUX, SBUX[,"SBUX.Close"]*SBUX[,"SBUX.Volume"])

and then you can rename the new column using colnames

   colnames(SBUX) <- c("SBUX.Open" , "SBUX.High"  ,   "SBUX.Low" ,  
"SBUX.Close" , "SBUX.Volume" ,  "SBUX.Adjusted", "TurnOver" )


Cheers

Soren

-- 
http://censix.com



More information about the R-SIG-Finance mailing list