[R-SIG-Finance] Finding price difference of a time series

Joshua Ulrich josh.m.ulrich at gmail.com
Tue Jul 23 13:47:50 CEST 2013


Veepsirtt,

You must use `coredata` on at least one of the objects because xts/zoo
align by index before performing any Ops-style functions.

Best,
--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com


On Tue, Jul 23, 2013 at 1:31 AM, veepsirtt <veepsirtt at gmail.com> wrote:
> Hi R users,
>
> #  How to find price difference of a-b and c-d ?.
>
>
> require(quantmod)
>
> require_symbol <- function(symbol, envir = parent.frame()) {
>   if (is.null(envir[[symbol]])) {
>     envir[[symbol]] <- getSymbols(symbol, auto.assign = FALSE)
>   }
>
>   envir[[symbol]]
> }
>
>
>
> # Create an environment for storing data
> symbol_env <- new.env()
>
> s1="SPY"
> s2="GOOG"
>
> A<- require_symbol(s1, symbol_env)
> B<- require_symbol(s2, symbol_env)
>
> x1=A[,6]
> x2=B[,6]
>
> a=head(x1,1)
> b=tail(x1,1)
> c=head(x2,1)
> d=tail(x2,1)
>
> J=a-b
>
> I got the following messages.
>
>> J
> Data:
>   numeric(0)
>
> Index:
>   numeric(0)
>> str(J)
> An 'xts' object of zero-width
>
> with regards.
> veepsirtt
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Finding-price-difference-of-a-time-series-tp4672099.html
> Sent from the Rmetrics mailing list archive at Nabble.com.
>
> _______________________________________________
> 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.



More information about the R-SIG-Finance mailing list