Thanks for the feedback Guy & Brian. -- sm Stergios Marinopoulos
On Tue, Sep 16, 2014 at 12:25 PM, Brian G. Peterson <[email protected]> wrote: > > > 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 > > > _______________________________________________ > [email protected] 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]] _______________________________________________ [email protected] 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.
