macrosynergy.pnl.multi_pnl#
The MultiPnL class allows for the visualization and analysis of PnLs across multiple return categories. It also provides functionality to calculate a weighted aggregate PnL based on user-defined weights for each PnL.
- class MultiPnL(df=None, bms=None)[source]#
Bases:
objectManages multiple NaivePnL instances, enabling combined PnL analysis and visualization.
- add_pnl(pnl, pnl_xcats)[source]#
Add PnL(s) from a NaivePnL object. PnL categories will be ingested into the MultiPnL object as ‘pnl_xcat/return’.
- combine_pnls(pnl_xcats, composite_pnl_xcat, weights=None)[source]#
Combine PnLs with optional weighting.
- Parameters:
pnl_xcats (List[str]) – List of PnLs to combine. Must be in the format ‘xcat/return’ and added using add_pnl().
composite_pnl_xcat (str) – xcat for the combined PnL.
weights (Optional[Dict[str, float]]) – Weights for each PnL, by default None. Must be in the format {‘xcat’: weight} or {‘xcat/return’: weight}.
- plot_pnls(pnl_xcats=None, title=None, title_fontsize=20, xcat_labels=None, figsize=(12, 7), tick_fontsize=12, label_fontsize=12, legend_fontsize=None)[source]#
Creates a plot of PnLs from added NaivePnL objects and/or combined PnLs created with combine_pnls().
- Parameters:
pnl_xcats (List[str]) – List of PnLs to plot. If None, all PnLs are plotted. Must be in the format ‘xcat’, or ‘xcat/return_xcat’.
title (str) – Title of the plot.
title_fontsize (int) – font size for the title. Default is 20.
xcat_labels (Union[List[str], dict]) – custom labels to be used for the PnLs.
figsize (Tuple) – tuple of plot width and height. Default is (12, 7).
tick_fontsize (int) – font size for the tick labels. Default is 12.
label_fontsize (int) – font size for the axis labels. Default is 12.
legend_fontsize (int) – font size for the legend. Default is None (uses matplotlib default).
- evaluate_pnls(pnl_xcats=None)[source]#
Returns a DataFrame containing the following evaluation metrics for specified PnLs:
Return %
St. Dev. %
Sharpe Ratio
Sortino Ratio
Max 21-Day Draw %
Max 6-Month Draw %
Peak to Trough Draw %
Top 5% Monthly PnL Share
Correlation with benchmarks (if available)
Sharpe Stability Ratio - HAC-robust t-stat for the mean rolling Sharpe ratio (see
sharpe_stability_ratio()); accounts for sample size and serial dependenceTraded Months
Note
The evaluation metrics are calculated in a manner similar to NaivePnL’s evaluate_pnls().
Benchmark correlations are included when
dfandbmsare passed to theMultiPnLconstructor. They apply uniformly to all PnLs in the table, including composite PnLs.