macrosynergy.pnl.contract_signals#
Module for calculating contract signals based on cross-section-specific signals, and hedging them with a basket of contracts. Main function is contract_signals.
- contract_signals(df, sig, cids, ctypes, cscales=None, csigns=None, hbasket=None, hscales=None, hratios=None, relative_value=False, start=None, end=None, rebal_freq='M', blacklist=None, sname='STRAT', *args, **kwargs)[source]#
Calculate contract-specific signals based on cross section-specific signals. Each contract signal a product of the cross-section-specific signal, a scaling factor or category, and a sign (+-1). Optionally, the contract signals can be hedged with a basket of contracts. The hedge ratios are determined by a cross-section-specific category. When hedging, the hedged signals are added to the contract signals; thus yielding a single contract signal per financial contract.
- Parameters:
df (pd.DataFrame) –
standardized JPMaQS DataFrame with the necessary columns: ‘cid’, ‘xcat’, ‘real_date’ and ‘value’. This dataframe must contain the cross-section-specific signals and possibly
[1] categories for changing scale factors of the main contracts, [2] contracts of a hedging basket, and [3] cross-section specific hedge ratios
sig (str) – the cross section-specific signal that serves as the basis of contract signals.
cids (List[str]) – list of cross-sections whose signal is to be used.
ctypes (List[str]) – list of identifiers for the contract types that are to be traded. They typically correspond to the contract type acronyms that are used in JPMaQS for generic returns, carry and volatility, such as “FX” for FX forwards or “EQ” for equity index futures. If n contracts are traded per cross sections ctypes must contain n arguments. N.B. Overall a contract is identified by the combination of its cross- section and its contract type “<cid>_<ctype>”.
cscales (List[str|float]) – list of scaling factors for the contract signals. These can be either a list of floats or a list of category tickers that serve as basis of translation. The former are fixed across time, the latter variable. The list cscales must be of the same length as the list ctypes.
csigns (List[int]) – list of signs that determine the direction of the contract signals. Contract signal is sign x cross section signal. The signs must be either 1 or -1. The list csigns must be of the same length as ctypes and cscales.
hbasket (List[str]) – list of contract identifiers in the format “<cid>_<ctype>” that serve as constituents of a hedging basket, if one is used.
hscales (List[str|float]) – list of scaling factors (weights) for the basket. These can be either a list of floats or a list of category tickers that serve as basis of translation. The former are fixed across time, the latter variable.
hratios (str) – category name for cross-section-specific hedge ratios. The values of this category determine direction and size of the hedge basket per unit of the cross section-specific signal.
relative_value (bool) – If False (default), no relative value is calculated. If True boolean, relative value is calculated for all cids in the strategy. # TODO split above relative_value argument into two: relative_value and relative_value_cids?
start (str) – earliest date in ISO format. Default is None and earliest date in df is used.
end (str) – latest date in ISO format. Default is None and latest date in df is used.
blacklist (dict) – cross-sections with date ranges that should be excluded from the calculation of contract signals.
sname (str) – name of the strategy. Default is “STRAT”.
- Returns:
with the contract signals for all traded contracts and the specified strategy. It has the standard JPMaQS DataFrame. The contract signals have the following format “<cid>_<ctype>_<sname>_CSIG”.
- Return type:
pd.DataFrame
- multi_signal_contract_signals(df, contract_dicts, common_args)[source]#
Calculate contract signals for multiple signal specifications. Each signal specification is a dictionary with arguments for a call to contract_signals(). The common arguments are passed to all calls. The dataframe is passed to all calls, and should not be included in the dictionaries, or common arguments. Please see the documentation for contract_signals() for more information on the arguments. Note: when two (or more) of the arguments produce a series with the same name, each new series will overwrite the previous one.
- Parameters:
df (pd.DataFrame) – standardized JPMaQS DataFrame with the necessary columns: ‘cid’, ‘xcat’, ‘real_date’ and ‘value’.
contract_dicts (dict[str, dict[str, Any]]) – dictionary of dictionaries with arguments for each call to contract_signals(). The keys are the names of the signal specifications.
common_args (dict[str, Any]) – dictionary with common arguments for all calls to contract_signals(). These are passed to all calls, and should not be included in the dictionaries in contract_dicts.
- Returns:
dataframe with the contract signals for all traded contracts and the specified strategies. It has the standard JPMaQS DataFrame. The contract signals have the following format “<cid>_<ctype>_<sname>_CSIG”.
- Return type: