[R-SIG-Finance] how to grow XTS series in R dynamically ? And Quickly!

Mark Leeds m@rk|eed@2 @end|ng |rom gm@||@com
Fri Sep 6 14:32:58 CEST 2019


Hi Vladimir: I can tell that  you tried to explain your problem clearly but
you'd get more
replies if you actually showed the R code that you wrote. Minimal,
reproducible examples
get a lot more responses.  Good luck.
                                                                      Mark

On Fri, Sep 6, 2019 at 12:05 AM Vladimir Morozov <vmorozov2006 using gmail.com>
wrote:

> did some googling on my question
> general wisdom on the internet seems to be - it's SLOW to grow R lists in a
> loop. Must Pre-allocate First.
>
> Question: is there a feature in XTS that allows to pre-allocate space for
> growing XTS series?
> thanks again!
>
> On Fri, Sep 6, 2019 at 11:51 AM Vladimir Morozov <vmorozov2006 using gmail.com>
> wrote:
>
> > Dear xts experts
> >
> > I use R and XTS to store dynamically growing price time-series for
> > currency pair rates (e.g. time series of EUR/USD, EUR/JPY, etc growing
> with
> > each new incoming market price - say, one per second).
> >
> > I want to speed up my R function that generates and rbinds a few new rows
> > to multiple Global XTS objects. This function us called often (sometimes
> > once per second) and takes a lot of time.
> >
> > Specifically, I have a function add.newRate.EUR(POSIXct Time, float Rate)
> > This function performs some time-consuming manipulations, then modifies
> > (global objects) XTS series1 through XTS seriesN. Specifically, I rbind
> > some new rows to each of series1 through seriesN in global environment.
> > (specific example - a new Rate for EUR/USD comes into the function. This
> > function needs to rbind new point to EUR.USD xts object, but it also
> needs
> > to calculate new value for cross-currency pairs, like EUR/JPY, EUR/GPB,
> > EUR/CHF, EUR/CAD, EUR/AUD, EUR/NZD, and rbind new point to those XTS
> series
> > as well)
> >
> > it all happens quite slowly in R. How do I accelerate it?
> >
> > To avoid copying XTS series between the function and the global
> > environment, the function attempts to modify the seriesX in the global
> > environment, and not return XTS on function return.
> > The structure of my project is such that my other tasks in R need to
> > access these XTS series1 through seriesN in Global Environment.
> > Still, this whole set-up is rather slow.
> >
> > Do you think using Rcpp to move cross-currency rate calculations to C++
> > could help?
> > E.g. I want to write add.newRate.EUR.RCPP(int Time, float Rate) in C++. I
> > think it will perform internal manipulations of time T and value X a
> little
> > faster.
> >
> > Second idea for speed up:  doing rbind in C++ using package RcppXts.
> > I plan to use the following function in RcppXts package:
> >     function("xtsRbind",
> >              &xtsRbind,
> >              List::create(Named("x"), Named("y"), Named("dup")),
> >              "Combine two xts objects row-wise");
> > Then I want to use Rcpp function assign( name, x ) to assign the created
> > object back to GlobalEnvironment.
> >
> > Do you think the above way is a good way to grow dynamical XTS series
> inside
> > Rcpp?
> > Do you think using Rcpp and RcppXts will provide significant acceleration
> > compared to pure R ?
> >
> > Thank you
> > Vlad
> >
> >
> >
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance using 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.
>

	[[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list