quantiles of per-trade stats


The quantiles of your trade statistics get to the heart of quantitatively setting rational stops and possibly even profit taking targets for a trading strategy or system. When applied to theoretical trades from a backtest, they may help to adjust parameters prior to trying the strategy with real money. When applied to real historical trades, they should help in examining what is working and where there is room for improvement in a trading system or strategy.


tradeQuantiles(Portfolio, Symbol, ..., scale = c("cash", "percent", "tick"),
  probs = c(0.5, 0.75, 0.9, 0.95, 0.99, 1))



string identifying the portfolio


string identifying the symbol to examin trades for. If missing, the first symbol found in the Portfolio portfolio will be used


string specifying 'cash', or 'percent' for percentage of investment, or 'tick'


vector of probabilities for quantile


any other passthrough parameters


This function will use the quantile function to calculate quantiles of per-trade net P&L, MAE, and MFE using the output from perTradeStats. These quantiles are chosen by the probs parameter and will be calculated for one or all of 'cash','percent',or 'tick', controlled by the scale argument. Quantiles will be calculated separately for trades that end positive (gains) and trades that end negative (losses), and will be denoted 'pos' and 'neg',respectively.

Additionally, this function will return the MAE with respect to the maximum cumulative P&L achieved for each scale you request. Tomasini&Jaekle recommend plotting MAE or MFE with respect to cumulative P&L and choosing a stop or profit target in the 'stable region'. The reported max should help the user to locate the stable region, perhaps mechanically. There is room for improvement here, but this should give the user information to work with in addition to the raw quantiles. For example, it may make more sense to use the max of a loess or kernel or other non-linear fit as the target point.


Brian G. Peterson


Tomasini, E. and Jaekle, U. Trading Systems - A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)

See Also


Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker. Vote for new features on Trello.

comments powered by Disqus