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[source]#

Bases: object

Manages 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’.

Parameters:
  • pnl (NaivePnL) – NaivePnL object.

  • pnl_xcats (List[str]) – List of PnLs to add from the NaivePnL object.

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=14, xcat_labels=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.

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

  • Traded Months

  • Correlation with benchmarks (if available)

Note

The evaluation metrics are calculated in a manner similar to NaivePnL’s evaluate_pnls().

Benchmark correlation is not currently supported for combined PnLs.

Parameters:

pnl_xcats (List[str]) – List of PnLs to evaluate. If None, all PnLs are evaluated. Must be in the format ‘xcat’, or ‘xcat/return_xcat’.

Returns:

DataFrame containing evaluation metrics for the specified PnLs.

Return type:

DataFrame

get_pnls(pnl_xcats=None)[source]#

Returns a DataFrame containing specified PnLs.

Parameters:

pnl_xcats (List[str]) – List of PnLs to return. If None, all PnLs are returned. Must be in the format ‘xcat’, or ‘xcat/return_xcat’.

Returns:

DataFrame containing the specified PnLs.

Return type:

DataFrame

property pnl_xcats#

List of all unique PnL categories stored in the MultiPnL object.

Returns:

A list of unique category names from the “xcat” column in pnls_df.

Return type:

List[str]

property return_xcats#

List of all unique return categories associated with PnLs.

Returns:

A list of unique return category names derived from the xcat_to_ret mapping.

Return type:

List[str]