macrosynergy.pnl.proxy_pnl#
Implementation of the ProxyPnL class.
- class ProxyPnL(df, transaction_costs_object, start=None, end=None, blacklist=None, rstring='XR', portfolio_name='GLB', sname='STRAT', pname='POS')[source]#
Bases:
object
The purpose of this class is to facilitate PnL estimation under the consideration of AUM, volatility targeting or leverage, and transaction costs. The class is designed to be used in a step-by-step manner, where the user first contracts signals, then calculates notional positions, and finally calculates the proxy PnL.
The steps for generating the PnL are as follows: - Contract signals: Contract signals for the given contracts and contract types. - Notional positions: Calculate notional (dollar) positions for the given contract
signals.
- Proxy PnL calculation: Calculate the proxy PnL and transaction costs for the given
notional positions.
- Parameters:
df (QuantamentalDataFrame) – DataFrame containing the data to be used in the PnL estimation. Initially, this DataFrame should contain the data used to contract signals (i.e. raw signals).
transaction_costs_object (TransactionCosts) – Object containing the transaction costs data.
start (str, optional) – Start date for the PnL estimation. If not provided, the minimum date in the DataFrame is used.
end (str, optional) – End date for the PnL estimation. If not provided, the maximum date in the DataFrame is used.
blacklist (dict, optional) – The blacklist dictionary to be applied to the input data.
rstring (str, optional) – A string used to specify the returns to be used in the PnL estimation.
portfolio_name (str, optional) – The name given to the (current) portfolio. In the return outputs, the portfolio name is used to identify and aggregate the PnL and transaction costs.
sname (str, optional) – The name given to the strategy,
pname (str, optional) – The name given to the positions.
- contract_signals(sig, cids, ctypes, cscales=None, csigns=None, hbasket=None, hscales=None, hratios=None, blacklist=None, *args, **kwargs)[source]#
Contract signals for the given contracts and contract types. The method uses the same dataframe as the one used to initialize the class. The function stores the contract signals DataFrame as an attribute of the class (self.cs_df), and also returns the same DataFrame for convenience.
See
macrosynergy.pnl.contract_signals()
for more information on the other parameters.- Return type:
- notional_positions(df=None, sname=None, fids=None, aum=100, dollar_per_signal=1.0, slip=1, leverage=None, vol_target=None, nan_tolerance=0.25, remove_zeros=True, rebal_freq='m', lback_meth='ma', est_freqs=['D', 'W', 'M'], est_weights=[1, 1, 1], lback_periods=[-1, -1, -1], half_life=[11, 5, 6], rstring=None, start=None, end=None, blacklist=None, pname='POS')[source]#
Calculate notional positions for the given contract signals. The method uses the contract signals calculated in the previous step. The user may additionally provide more data that may be used as a new dataframe.
The method stores the notional positions DataFrame, the portfolio volatility DataFrame, and the variance-covariance matrix DataFrame as attributes of the class (self.npos_df, self.pvol_df, and self.vcv_df, respectively). It also returns the notional positions DataFrame for convenience.
See
macrosynergy.pnl.notional_positions()
for more information on the other parameters.- Returns:
The notional positions DataFrame
- Return type:
- proxy_pnl_calc(spos=None, portfolio_name=None, df=None, roll_freqs=None, rstring=None, pnl_name='PNL', tc_name='TCOST')[source]#
Calculate the proxy PnL and transaction costs for the given notional positions. The method uses the notional positions calculated in the previous step. The user may additionally provide more data that may be used as a new dataframe.
The method stores the proxy PnL DataFrame, the transaction costs DataFrame, and the proxy PnL excluding costs DataFrame as attributes of the class (self.proxy_pnl, self.txn_costs_df, and self.pnl_excl_costs, respectively). It also returns the proxy PnL DataFrame for convenience.
See
macrosynergy.pnl.proxy_pnl_calc()
for more information on the other parameters.- Returns:
The proxy PnL DataFrame.
- Return type:
- plot_pnl(title='Proxy PnL', cumsum=True, **kwargs)[source]#
Plot the proxy PnL DataFrame. The method uses the proxy PnL calculated in the previous step.
- Parameters:
title (str, optional) – Title of the plot.
cumsum (bool, optional) – Whether to plot the cumulative sum of the proxy PnL.
kwargs – Additional keyword arguments to be passed to the timelines function. See
macrosynergy.visuals.timelines()
for more information.