[R-SIG-Finance] Blotter example by kafka from R-bloggers

Brian G. Peterson brian at braverock.com
Tue Dec 28 21:18:06 CET 2010


On 12/28/2010 01:28 PM, Stephen Choularton wrote:
> My apologies.
>
> I did not realize the script worked so slowly.  I reduced the time scale
> it covered so it commenced at the beginning of the year and it did run
> to completion.  I will try the full term and see if it produces the same
> graphs as the original example.
 >
> I'm always a bit worried about warnings as they often mean something is
> going wrong and it might be useful if kafta had warned one not to worry
> about them.  Mind you I think he did say it all took a long time ;-)


The reason this script runs slowly is that it is calling updatePortf, 
updateAcct, and updateEndEq after each and every observation to do order 
sizing.

As a matter of practice, if you can 'cheat' and say 'I've got $1000000 
to invest, and I don't mind being a little leveraged', you don't need to 
do that, and things are *much* faster.  For example, we can typically 
run a strategy backtest on *tick* data (millions of observations) in 
less than a minute per day.

The reason for this divergent length of time is that the blotter update* 
functions do a *lot* of calculations, and all of those take time, even 
though they are vectorized where possible.

Perhaps a middle ground would be to call the update* functions monthly, 
or something similar.

I found his example script to be slower than I am used to, but not 
unbearable, and believe that it finished in a couple minutes, though its 
been a while since I ran it...


> I can assure you I do try and read man before I ask for help but dealing
> with other people's code is not always easy particularly when working
> with a programming system that uses a different paradigm like R with its
> emphasis on operations on vectors and the like. and the extensive use of
> calls to functions each of which often require a wet towel and cup of
> coffee to understand.
>
> I added the parameter definitions you suggest:
>
> currency("USD")
> stock("SPY",currency="USD",multiplier=1)
>
> and the warnings reduced to one:

Good.

> Warning messages:
> 1: In updatePortf(ltportfolio, Dates = currentDate) :
>    Incompatible methods ("Ops.Date", "Ops.POSIXt") for ">="
<...>

> "Ops.Date", "Ops.POSIXt" don't appear in the function call so they must
> be somewhere deeper.  I'm afraid I'm currently a windows user so grep is
> not available and the windows native text search didn't reveal much.
> However, I did find some references in the documentation (Date-Time
> Classes, Operators on the Date Class & S3 Group Generic Functions) but
> Ops.POSIXt doesn't appear therein only POSIXlt and Ops.POSIXct.  Is
> there a typo somewhere ?

It's likely not a typo, but rather an incompatible index between one 
time series and another.  You'd need to check the indices of each of the 
input series, or of the custom order sizing function from the script to 
see what's going on.  If the output from your run and the blog post 
agree, I wouldn't bother.

> It would be nice to get rid of the warnings.


-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list