Turning Trade P&L into Returns for PerformanceAnalytics
Summary
The note explains how to use trade-level profits with PerformanceAnalytics, whose functions generally expect return data rather than a raw list of trade P&L values. One suggested workflow is to record transactions in the blotter package, calculate cash P&L, then use trade statistics for trade-level analysis or portfolio returns to derive each symbol's contribution to total account equity returns. Those returns can then be supplied to PerformanceAnalytics functions.
A simpler illustration starts with an initial equity balance and applies each trade outcome sequentially to build an equity series; period returns can then be calculated from that series. This conversion makes the input meaningful as portfolio performance, including when profits and losses occur. The note does not specify how to handle trade timing, capital allocation, overlapping positions, or multiple instruments, so those choices matter when constructing a representative return series.
Key ideas
- PerformanceAnalytics functions generally expect returns rather than raw trade profits or prices.
- The blotter workflow records transactions and computes cash P&L before deriving portfolio returns.
- Trade-level statistics and portfolio contribution returns serve different analysis needs.
- An equity curve can be built by applying sequential trade outcomes to starting equity, then calculating returns.
- Timing, allocation, and multi-instrument accounting choices affect the resulting return series.
Tags
Full text
# Use Trades as Input for PerformanceAnalytics # Use Trades as Input for PerformanceAnalytics I'd like to use the PerformanceAnalytics R package to view various metrics from a list of trades with profit values. From looking at the documentation from the PerformanceAnalytics package that most functions are set up to use a time series of prices rather than an array of profit values (which of course can be negative). Can PerformanceAnalytics be used on an array of profit values (from a backtest that might have several instruments in it for example)? If not, is there a way to convert the profit values to a format that makes sense to input into most PerformanceAnalytics functions? ## Answer by Brian G. Peterson (score 8) https://quant.stackexchange.com/a/1538 If you've got a list of trades, I would first suggest using the blotter package to enter those transactions and compute your cash P&L. Then you can use the `tradeStats` function to see trade related statistics, or the `portfReturns` function to extract percent returns for your portfolio of symbols as a contribution to total account equity returns. After calling portfReturns, all the functions in PerformanceAnalytics will have the inputs that they expect. ## Answer by babelproofreader (score 0) https://quant.stackexchange.com/a/1537 > ...is there a way to convert the profit values to a format that makes sense to input into most PerformanceAnalytics functions? Assume trade outcomes of 10, -5, 15,... for example, and starting equity of 100, then your equity time series will be 100, 110, 105, 120,... from which returns can be calculated. Taken from the link you gave "In general, this library requires return (rather than price) data."
Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.