[R-SIG-Finance] Guy Yollin's blotter.pdf Example
Brian G. Peterson
brian at braverock.com
Tue Sep 16 21:25:50 CEST 2014
On 09/16/2014 11:52 AM, stergios marinopoulos wrote:
> The example is a loop over each period of data where the trading rules are
> applied. At the very end of the loop the three blotter functions named
> updatePortf(), updateAcct(), and updateEndEq() are called. Here it is
> briefly:
>
> for( i in 1:nrow(SPY) ) {
>
> // Trading Rules Omitted
>
> updatePortf(b.strategy,Dates=CurrentDate)
> updateAcct(b.strategy,Dates=CurrentDate)
> updateEndEq(b.strategy,CurrentDate)
>
> }
>
>
> My question is "could we hoist those last 3 functions out of the loop, and
> place them afterwards with an expanded date range to cover all dates?"
> Doing so dramatically speeds up processing. A downside to doing so is not
> having the current equity available for use in trade sizing. Of course,
> there may be a loss of clarity in the example as well. Are there other
> important reasons for keeping the functions inside the loop?
Only to update portfolio equity.
It is also possible to approximate by taking the last mark plus any
realized gains plus the mark to market difference in any open position.
> Perhaps those functions could be called inside the loop only when a
> position is closed out, or when rebalancing needs to occur?
Correct.
blotter isn't really designed for writing trading strategies. It is
designed to do portfolio accounting. We use it mostly as either a
backend behind quantstrat (which is designed for strategy backtests) or
for post-trade analysis on production trades.
In the first case (backtesting), performance is obviously important, so
you would want to minimize how often you call the update* functions,
perhaps using secondary calculations instead of marking the entire
portfolio. There's no point in marking the portfolio every tick, or
every second, even if you only call it once at the end. We often mark
the portfolio hourly, even if we ran a backtest on tick.
In the post-trade analysis case, you would typically call the update*
functions only once, at the end, and performance is not really an issue,
because even a giant portfolio across very long periods of time takes
only seconds to mark.
Regards,
Brian
--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock
More information about the R-SIG-Finance
mailing list