Fast R Backtesting with Target Weights and Trade Buffers
Summary
The article introduces rsims, an R package for fast portfolio backtests that emphasizes translating target weights into trades while accounting for costs and constraints. It describes a threshold rule: trade toward a target only when the current weight moves beyond a buffer around that target. The examples show how to reshape price and target-weight data into wide matrices, run a cash-based simulation, and summarize portfolio value and trading activity.
The walkthrough also demonstrates adding a fixed commission rate and comparing Sharpe ratios across candidate buffer sizes. This illustrates how a buffer can reduce turnover and affect measured performance, but selecting it by maximizing in-sample Sharpe does not establish out-of-sample robustness. The engine relies on carefully aligned inputs and performs only limited checks, so incorrect data can still produce completed but misleading simulations. The cost model is simple, and the article identifies richer cost models and constrained optimization as areas for further development.
Key ideas
- The simulator converts target portfolio weights into trades and reports positions, values, and trade costs.
- A trade buffer avoids small adjustments when current weights remain near target weights.
- Wide matrices align timestamp, asset prices, and target weights for simulation.
- Testing buffer values with historical Sharpe ratios illustrates a tuning process but risks in-sample overfitting.
- Input alignment and data correctness are critical because the engine performs limited validation.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.