Statistical learning for sectoral equity allocation #
This notebook offers the necessary code to replicate the research findings discussed in the Macrosynergy research post “Statistical learning for sectoral equity allocation”. Its primary objective is to inspire readers to explore and conduct additional investigations whilst also providing a foundation for testing their own unique ideas.
On the back of our initial exploration of the relationship between macroeconomic trends and sectoral equity indices , we continue the analysis of sectoral rotation signals using macro trends as well as macro and financial conditions. We take advantage of previous data ingestion and transformations of JPMaQS macro quantamental indicators, as shown in Sectoral equity indicators , structuring the notebook as follows:
-
Get Packages and JPMaQS Data: This section is responsible for installing and importing the necessary Python packages used throughout the analysis, as well as loading all the required data
-
Feature filtering and imputation: We apply common sense in determining which categories should be part of the panel in the learning exercise. We look for consistency of feature availability across cross sections, as well as maximum coverage. Therefore we opt to discard some categories while imputing others in specific cross sections in the early period.
-
Sectoral signals and naive PnLs: We proceed with statistical learning on vol-targeted relative returns, using common pipeline across sectors. This combines a feature selection mechanism based upon LARS and linear models, as we opt for simplicity.
It is important to note that while the notebook covers a selection of indicators and strategies used for the post’s main findings, users can explore countless other possible indicators and approaches. Users can modify the code to test different hypotheses and strategies based on their research and ideas. Best of luck with your research!
Get packages and JPMaQS data #
Packages #
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from macrosynergy.download import JPMaQSDownload
import macrosynergy.management as msm
import macrosynergy.panel as msp
import macrosynergy.pnl as msn
import macrosynergy.signal as mss
import macrosynergy.learning as msl
import macrosynergy.visuals as msv
from sklearn.linear_model import LinearRegression
from sklearn.pipeline import Pipeline
from sklearn.metrics import make_scorer
from timeit import default_timer as timer
from datetime import timedelta, date, datetime
import warnings
from IPython.display import HTML
warnings.filterwarnings("ignore")
Previously prepared quantamental categories #
# Import data from csv file created preparation notebook
# https://macrosynergy.com/academy/notebooks/sectoral-equity-indicators/
INPUT_PATH = os.path.join(os.getcwd(), r"../../../equity_sectoral_notebook_data.csv")
df_csv = pd.read_csv(INPUT_PATH, index_col=0)
df_csv["real_date"] = pd.to_datetime(df_csv["real_date"]).dt.date
df_csv = msm.utils.standardise_dataframe(df_csv)
df_csv = df_csv.sort_values(["cid", "xcat", "real_date"])
# Equity sector labels and cross sections
sector_labels = {
"ALL": "All sectors",
"COD": "Cons. discretionary",
"COS": "Cons. staples",
"CSR": "Communication services",
"ENR": "Energy",
"FIN": "Financials",
"HLC": "Healthcare",
"IND": "Industrials",
"ITE": "Information tech",
"MAT": "Materials",
"REL": "Real estate",
"UTL": "Utilities",
}
cids_secs = list(sector_labels.keys())
# Equity countries cross sections
cids_eq = [
"AUD",
"CAD",
"CHF",
"EUR",
"GBP",
"ILS",
"JPY",
"NOK",
"NZD",
"SEK",
"SGD",
"USD",
]
# Base category tickes of quantamental categories created by data preparation notebook:
# https://macrosynergy.com/academy/notebooks/sectoral-equity-indicators/
output_growth = [
# industrial prod
"XIP_SA_P1M1ML12_3MMA",
"XIP_SA_P1M1ML12_3MMA_WG",
# construction
"XCSTR_SA_P1M1ML12_3MMA",
"XCSTR_SA_P1M1ML12_3MMA_WG",
# Excess GDP growth
"XRGDPTECH_SA_P1M1ML12_3MMA",
"XRGDPTECH_SA_P1M1ML12_3MMA_WG",
]
private_consumption = [
# Consumer surveys
"CCSCORE_SA",
"CCSCORE_SA_D3M3ML3",
"CCSCORE_SA_WG",
"CCSCORE_SA_D3M3ML3_WG",
"XNRSALES_SA_P1M1ML12_3MMA",
"XRRSALES_SA_P1M1ML12_3MMA",
"XNRSALES_SA_P1M1ML12_3MMA_WG",
"XRRSALES_SA_P1M1ML12_3MMA_WG",
"XRPCONS_SA_P1M1ML12_3MMA",
"XRPCONS_SA_P1M1ML12_3MMA_WG",
]
export = [
"XEXPORTS_SA_P1M1ML12_3MMA",
]
labour_market = [
"UNEMPLRATE_NSA_3MMA_D1M1ML12",
"UNEMPLRATE_SA_3MMAv5YMA",
"UNEMPLRATE_NSA_3MMA_D1M1ML12_WG",
"UNEMPLRATE_SA_3MMAv5YMA_WG",
"XEMPL_NSA_P1M1ML12_3MMA",
"XEMPL_NSA_P1M1ML12_3MMA_WG",
"XRWAGES_NSA_P1M1ML12",
]
business_surveys = [
# Manufacturing
"MBCSCORE_SA",
"MBCSCORE_SA_D3M3ML3",
"MBCSCORE_SA_WG",
"MBCSCORE_SA_D3M3ML3_WG",
# Services
"SBCSCORE_SA",
"SBCSCORE_SA_D3M3ML3",
"SBCSCORE_SA_WG",
"SBCSCORE_SA_D3M3ML3_WG",
# Construction
"CBCSCORE_SA",
"CBCSCORE_SA_D3M3ML3",
"CBCSCORE_SA_WG",
"CBCSCORE_SA_D3M3ML3_WG",
]
private_credit = [
"XPCREDITBN_SJA_P1M1ML12",
"XPCREDITBN_SJA_P1M1ML12_WG",
# liquidity conditions
"INTLIQGDP_NSA_D1M1ML1",
"INTLIQGDP_NSA_D1M1ML6",
]
broad_inflation = [
# Inflation
"XCPIC_SA_P1M1ML12",
"XCPIH_SA_P1M1ML12",
"XPPIH_NSA_P1M1ML12",
]
specific_inflation = [
"XCPIE_SA_P1M1ML12",
"XCPIF_SA_P1M1ML12",
"XCPIE_SA_P1M1ML12_WG",
"XCPIF_SA_P1M1ML12_WG",
]
private_and_public_debt = [
"HHINTNETGDP_SA_D1M1ML12",
"HHINTNETGDP_SA_D1M1ML12_WG",
"CORPINTNETGDP_SA_D1Q1QL4",
"CORPINTNETGDP_SA_D1Q1QL4_WG",
"XGGDGDPRATIOX10_NSA",
]
commodity_inventories = [
"BMLXINVCSCORE_SA",
"REFIXINVCSCORE_SA",
"BASEXINVCSCORE_SA",
]
commodity_markets = [
"BMLCOCRY_SAVT10_21DMA",
"COXR_VT10vWTI_21DMA"
]
real_appreciation_tot = [
"CXPI_NSA_P1M12ML1",
"CMPI_NSA_P1M12ML1",
"CTOT_NSA_P1M12ML1",
"REEROADJ_NSA_P1M12ML1",
]
interest_rates = [
"RIR_NSA",
"RYLDIRS02Y_NSA",
"RYLDIRS05Y_NSA",
"RSLOPEMIDDLE_NSA",
]
# All economic categories
ecos = output_growth + private_consumption + export + labour_market + business_surveys + private_credit + broad_inflation + specific_inflation + private_and_public_debt + commodity_inventories + commodity_markets + real_appreciation_tot + interest_rates
# Equity categories
eqrets = [
"EQC" + sec + ret for sec in cids_secs for ret in ["XR_NSA", "R_NSAvALL", "R_VT10vALL"]
]
# All categories
all_xcats = [x + suff for x in ecos + ecos for suff in ["_ZN", "_ZN_NEG"]] + eqrets
# Resultant tickers
tickers = [cid + "_" + xcat for cid in cids_eq for xcat in all_xcats]
print(f"Maximum number of tickers is {len(tickers)}")
Maximum number of tickers is 3552
Download additional data from JPMaQS #
# Additional tickers for download from JPMaQS
untradeable = [
"EQCCODUNTRADABLE_NSA",
"EQCCOSUNTRADABLE_NSA",
"EQCCSRUNTRADABLE_NSA",
"EQCENRUNTRADABLE_NSA",
"EQCFINUNTRADABLE_NSA",
"EQCHLCUNTRADABLE_NSA",
"EQCINDUNTRADABLE_NSA",
"EQCITEUNTRADABLE_NSA",
"EQCMATUNTRADABLE_NSA",
"EQCRELUNTRADABLE_NSA",
"EQCUTLUNTRADABLE_NSA",
] # dummy variables for dates where certain sectors were untradeable
bmrs = [
"USD_EQXR_NSA",
"USD_EQXR_VT10"
] # U.S. equity returns for correlation analysis
xtickers = [cid + "_" + xcat for cid in cids_eq for xcat in untradeable] + bmrs
print(f"Maximum number of tickers is {len(xtickers)}")
Maximum number of tickers is 134
# Download series from J.P. Morgan DataQuery by tickers
start_date = "2000-01-01"
# Retrieve credentials
client_id: str = os.getenv("DQ_CLIENT_ID")
client_secret: str = os.getenv("DQ_CLIENT_SECRET")
# Download from DataQuery
with JPMaQSDownload(client_id=client_id, client_secret=client_secret) as downloader:
start = timer()
assert downloader.check_connection()
df_jpmaqs = downloader.download(
tickers=xtickers,
start_date=start_date,
metrics=["value"],
suppress_warning=True,
show_progress=True,
)
end = timer()
print("Download time from DQ: " + str(timedelta(seconds=end - start)))
Downloading data from JPMaQS.
Timestamp UTC: 2024-09-03 14:44:19
Connection successful!
Requesting data: 100%|███████████████████████████████████████████████████████████████████| 7/7 [00:01<00:00, 4.70it/s]
Downloading data: 100%|██████████████████████████████████████████████████████████████████| 7/7 [00:07<00:00, 1.09s/it]
Some expressions are missing from the downloaded data. Check logger output for complete list.
1 out of 134 expressions are missing. To download the catalogue of all available expressions and filter the unavailable expressions, set `get_catalogue=True` in the call to `JPMaQSDownload.download()`.
Some dates are missing from the downloaded data.
3 out of 6439 dates are missing.
Download time from DQ: 0:00:11.832393
df = msm.update_df(df_csv, df_jpmaqs)
# Dictionary of featire category labels
cat_labels = {
"BASEXINVCSCORE_SA_ZN": {
"Group": "Commodity inventories",
"Label": "Excess crude inventory score",
"Description": "Crude oil excess inventory z-score, seasonally adjusted",
"Geography": "global",
},
"BMLCOCRY_SAVT10_21DMA_ZN": {
"Group": "Market metrics",
"Label": "Base metals carry",
"Description": "Nominal carry for base metals basket, seasonally and vol-adjusted, 21 days moving average",
"Geography": "global",
},
"BMLXINVCSCORE_SA_ZN": {
"Group": "Commodity inventories",
"Label": "Excess metal inventory score",
"Description": "Base metal excess inventory z-score, seasonally adjusted",
"Geography": "global",
},
"CBCSCORE_SA_D3M3ML3_WG_ZN": {
"Group": "Business surveys",
"Label": "Construction confidence, q/q",
"Description": "Construction business confidence score, seas. adjusted, change q/q",
"Geography": "weighted",
},
"CBCSCORE_SA_D3M3ML3_ZN": {
"Group": "Business surveys",
"Label": "Construction confidence, q/q",
"Description": "Construction business confidence score, seas. adjusted, change q/q",
"Geography": "local",
},
"CBCSCORE_SA_WG_ZN": {
"Group": "Business surveys",
"Label": "Construction confidence",
"Description": "Construction business confidence score, seas. adjusted",
"Geography": "weighted",
},
"CBCSCORE_SA_ZN": {
"Group": "Business surveys",
"Label": "Construction confidence",
"Description": "Construction business confidence score, seas. adjusted",
"Geography": "local",
},
"CCSCORE_SA_D3M3ML3_WG_ZN": {
"Group": "Private consumption",
"Label": "Consumer confidence, q/q",
"Description": "Consumer confidence score, seasonally adjusted, change q/q",
"Geography": "weighted",
},
"CCSCORE_SA_D3M3ML3_ZN": {
"Group": "Private consumption",
"Label": "Consumer confidence, q/q",
"Description": "Consumer confidence score, seasonally adjusted, change q/q",
"Geography": "local",
},
"CCSCORE_SA_WG_ZN": {
"Group": "Private consumption",
"Label": "Consumer confidence",
"Description": "Consumer confidence score, seasonally adjusted",
"Geography": "weighted",
},
"CCSCORE_SA_ZN": {
"Group": "Private consumption",
"Label": "Consumer confidence",
"Description": "Consumer confidence score, seasonally adjusted",
"Geography": "local",
},
"CMPI_NSA_P1M12ML1_ZN": {
"Group": "Real appreciation",
"Label": "Import prices, %oya",
"Description": "Commodity-based import price index, %oya",
"Geography": "local",
},
"CTOT_NSA_P1M12ML1_ZN": {
"Group": "Real appreciation",
"Label": "Terms-of-trade, %oya",
"Description": "Commodity-based terms-of-trade, %oya",
"Geography": "local",
},
"CXPI_NSA_P1M12ML1_ZN": {
"Group": "Real appreciation",
"Label": "Export prices, %oya",
"Description": "Commodity-based export price index, %oya",
"Geography": "local",
},
"COXR_VT10vWTI_21DMA_ZN": {
"Group": "Market metrics",
"Label": "Refined vs crude oil returns",
"Description": "Refined oil products vs crude oil vol-targeted return differential, 21 days moving average",
"Geography": "global",
},
"INTLIQGDP_NSA_D1M1ML1_ZN": {
"Group": "Private credit",
"Label": "Intervention liquidity, diff m/m",
"Description": "Intervention liquidity to GDP ratio, change over the last month",
"Geography": "local",
},
"INTLIQGDP_NSA_D1M1ML6_ZN": {
"Group": "Private credit",
"Label": "Intervention liquidity, diff 6m",
"Description": "Intervention liquidity to GDP ratio, change overlast 6 months",
"Geography": "local",
},
"MBCSCORE_SA_D3M3ML3_WG_ZN": {
"Group": "Business surveys",
"Label": "Manufacturing confidence, q/q",
"Description": "Manufacturing business confidence score, seas. adj., change q/q",
"Geography": "weighted",
},
"MBCSCORE_SA_D3M3ML3_ZN": {
"Group": "Business surveys",
"Label": "Manufacturing confidence, q/q",
"Description": "Manufacturing business confidence score, seas. adj., change q/q",
"Geography": "local",
},
"MBCSCORE_SA_WG_ZN": {
"Group": "Business surveys",
"Label": "Manufacturing confidence",
"Description": "Manufacturing business confidence score, seasonally adjusted",
"Geography": "weighted",
},
"MBCSCORE_SA_ZN": {
"Group": "Business surveys",
"Label": "Manufacturing confidence",
"Description": "Manufacturing business confidence score, seasonally adjusted",
"Geography": "local",
},
"REEROADJ_NSA_P1M12ML1_ZN": {
"Group": "Real appreciation",
"Label": "Open-adj REER, %oya",
"Description": "Openness-adjusted real effective exchange rate, %oya",
"Geography": "local",
},
"REFIXINVCSCORE_SA_ZN": {
"Group": "Commodity inventories",
"Label": "Excess refined oil inventory score",
"Description": "Refined oil product excess inventory z-score, seas. adjusted",
"Geography": "global",
},
"RIR_NSA_ZN": {
"Group": "Market metrics",
"Label": "Real 1-month rate",
"Description": "Real 1-month interest rate",
"Geography": "local",
},
"RSLOPEMIDDLE_NSA_ZN": {
"Group": "Market metrics",
"Label": "Real 5y-2y yield",
"Description": "Real IRS yield differentials, 5-years versus 2-years",
"Geography": "local",
},
"RYLDIRS02Y_NSA_ZN": {
"Group": "Market metrics",
"Label": "Real 2-year yield",
"Description": "Real 2-year IRS yield",
"Geography": "local",
},
"RYLDIRS05Y_NSA_ZN": {
"Group": "Market metrics",
"Label": "Real 5-year yield",
"Description": "Real 5-year IRS yield",
"Geography": "local",
},
"SBCSCORE_SA_D3M3ML3_WG_ZN": {
"Group": "Business surveys",
"Label": "Service confidence, q/q",
"Description": "Services business confidence score, seas. adjusted, change q/q",
"Geography": "weighted",
},
"SBCSCORE_SA_D3M3ML3_ZN": {
"Group": "Business surveys",
"Label": "Service confidence, q/q",
"Description": "Services business confidence score, seas. adjusted, change q/q",
"Geography": "local",
},
"SBCSCORE_SA_WG_ZN": {
"Group": "Business surveys",
"Label": "Service confidence",
"Description": "Services business confidence score, seasonally adjusted",
"Geography": "weighted",
},
"SBCSCORE_SA_ZN": {
"Group": "Business surveys",
"Label": "Service confidence",
"Description": "Services business confidence score, seasonally adjusted",
"Geography": "local",
},
"UNEMPLRATE_NSA_3MMA_D1M1ML12_WG_ZN": {
"Group": "Labour market",
"Label": "Unemployment rate, diff oya",
"Description": "Unemployment rate, change oya",
"Geography": "weighted",
},
"UNEMPLRATE_NSA_3MMA_D1M1ML12_ZN": {
"Group": "Labour market",
"Label": "Unemployment rate, diff oya",
"Description": "Unemployment rate, change oya",
"Geography": "local",
},
"UNEMPLRATE_SA_3MMAv5YMA_WG_ZN": {
"Group": "Labour market",
"Label": "Unemployment rate, diff vs 5yma",
"Description": "Unemployment rate, difference vs 5-year moving average",
"Geography": "weighted",
},
"UNEMPLRATE_SA_3MMAv5YMA_ZN": {
"Group": "Labour market",
"Label": "Unemployment rate, diff vs 5yma",
"Description": "Unemployment rate, difference vs 5-year moving average",
"Geography": "local",
},
"XCPIC_SA_P1M1ML12_ZN": {
"Group": "Inflation - broad",
"Label": "Excess core CPI, %oya",
"Description": "Core CPI, %oya, in excess of effective inflation target",
"Geography": "local",
},
"XCPIE_SA_P1M1ML12_WG_ZN": {
"Group": "Inflation - specific",
"Label": "Excess energy CPI, %oya",
"Description": "Energy CPI, %oya, in excess of effective inflation target",
"Geography": "weighted",
},
"XCPIE_SA_P1M1ML12_ZN": {
"Group": "Inflation - specific",
"Label": "Excess energy CPI, %oya",
"Description": "Energy CPI, %oya, in excess of effective inflation target",
"Geography": "local",
},
"XCPIF_SA_P1M1ML12_WG_ZN": {
"Group": "Inflation - specific",
"Label": "Excess food CPI, %oya",
"Description": "Food CPI, %oya, in excess of effective inflation target",
"Geography": "weighted",
},
"XCPIF_SA_P1M1ML12_ZN": {
"Group": "Inflation - specific",
"Label": "Excess food CPI, %oya",
"Description": "Food CPI, %oya, in excess of effective inflation target",
"Geography": "local",
},
"XCPIH_SA_P1M1ML12_ZN": {
"Group": "Inflation - broad",
"Label": "Excess headline CPI, %oya",
"Description": "Headline CPI, %oya, in excess of effective inflation target",
"Geography": "local",
},
"XCSTR_SA_P1M1ML12_3MMA_WG_ZN": {
"Group": "Output growth",
"Label": "Excess construction growth",
"Description": "Construction output, %oya, 3mma, in excess of 5-y median GDP growth",
"Geography": "weighted",
},
"XCSTR_SA_P1M1ML12_3MMA_ZN": {
"Group": "Output growth",
"Label": "Excess construction growth",
"Description": "Construction output, %oya, 3mma, in excess of 5-y median GDP growth",
"Geography": "local",
},
"XEMPL_NSA_P1M1ML12_3MMA_WG_ZN": {
"Group": "Labour market",
"Label": "Excess employment growth",
"Description": "Employment growth, %oya, 3mma, in excess of population growth",
"Geography": "weighted",
},
"XEMPL_NSA_P1M1ML12_3MMA_ZN": {
"Group": "Labour market",
"Label": "Excess employment growth",
"Description": "Employment growth, %oya, 3mma, in excess of population growth",
"Geography": "local",
},
"XEXPORTS_SA_P1M1ML12_3MMA_ZN": {
"Group": "Exports",
"Label": "Excess export growth",
"Description": "Exports growth, %oya, 3mma, in excess of 5-year median GDP growth",
"Geography": "local",
},
"XGGDGDPRATIOX10_NSA_ZN": {
"Group": "Debt",
"Label": "Excess projected gov. debt",
"Description": "Government debt-to-GDP ratio proj. in 10 years, in excess of 100%",
"Geography": "local",
},
"CORPINTNETGDP_SA_D1Q1QL4_WG_ZN": {
"Group": "Debt",
"Label": "Corporate debt servicing, %oya",
"Description": "Corporate net debt servicing-to-GDP ratio, seasonally-adjusted, %oya",
"Geography": "weighted",
},
"CORPINTNETGDP_SA_D1Q1QL4_ZN": {
"Group": "Debt",
"Label": "Corporate debt servicing, %oya",
"Description": "Corporate net debt servicing-to-GDP ratio, seasonally-adjusted, %oya",
"Geography": "local",
},
"HHINTNETGDP_SA_D1M1ML12_WG_ZN": {
"Group": "Debt",
"Label": "Households debt servicing, %oya",
"Description": "Households net debt servicing-to-GDP ratio, seasonally-adjusted, %oya",
"Geography": "weighted",
},
"HHINTNETGDP_SA_D1M1ML12_ZN": {
"Group": "Debt",
"Label": "Households debt servicing, %oya",
"Description": "Households net debt servicing-to-GDP ratio, seasonally-adjusted, %oya",
"Geography": "local",
},
"XIP_SA_P1M1ML12_3MMA_WG_ZN": {
"Group": "Output growth",
"Label": "Excess industry growth",
"Description": "Industrial output, %oya, 3mma, in excess of 5-y median GDP growth",
"Geography": "weighted",
},
"XIP_SA_P1M1ML12_3MMA_ZN": {
"Group": "Output growth",
"Label": "Excess industry growth",
"Description": "Industrial output, %oya, 3mma, in excess of 5-y median GDP growth",
"Geography": "local",
},
"XNRSALES_SA_P1M1ML12_3MMA_WG_ZN": {
"Group": "Private consumption",
"Label": "Excess retail sales growth",
"Description": "Nominal retail sales, %oya, 3mma, in excess of 5-y median GDP growth",
"Geography": "weighted",
},
"XNRSALES_SA_P1M1ML12_3MMA_ZN": {
"Group": "Private consumption",
"Label": "Excess retail sales growth",
"Description": "Nominal retail sales, %oya, 3mma, in excess of 5-y median GDP growth",
"Geography": "local",
},
"XRRSALES_SA_P1M1ML12_3MMA_WG_ZN": {
"Group": "Private consumption",
"Label": "Excess real retail growth",
"Description": "Real retail sales, %oya, 3mma, in excess of 5-y median GDP growth",
"Geography": "weighted",
},
"XRRSALES_SA_P1M1ML12_3MMA_ZN": {
"Group": "Private consumption",
"Label": "Excess real retail growth",
"Description": "Real retail sales, %oya, 3mma, in excess of 5-y median GDP growth",
"Geography": "local",
},
"XPCREDITBN_SJA_P1M1ML12_WG_ZN": {
"Group": "Private credit",
"Label": "Excess credit growth",
"Description": "Private credit, %oya, 3mma, in excess of 5-y median GDP growth",
"Geography": "weighted",
},
"XPCREDITBN_SJA_P1M1ML12_ZN": {
"Group": "Private credit",
"Label": "Excess credit growth",
"Description": "Private credit, %oya, 3mma, in excess of 5-y median GDP growth",
"Geography": "local",
},
"XPPIH_NSA_P1M1ML12_ZN": {
"Group": "Inflation - broad",
"Label": "Excess PPI, %oya",
"Description": "Producer price inflation, %oya, in excess of eff. inflation target",
"Geography": "local",
},
"XRGDPTECH_SA_P1M1ML12_3MMA_WG_ZN": {
"Group": "Output growth",
"Label": "Excess GDP growth",
"Description": "Real GDP, %oya, 3mma, using HF data, in excess of 5-y med. GDP growth",
"Geography": "weighted",
},
"XRGDPTECH_SA_P1M1ML12_3MMA_ZN": {
"Group": "Output growth",
"Label": "Excess GDP growth",
"Description": "Real GDP, %oya, 3mma, using HF data, in excess of 5-y med. GDP growth",
"Geography": "local",
},
"XRPCONS_SA_P1M1ML12_3MMA_WG_ZN": {
"Group": "Private consumption",
"Label": "Excess consumption growth",
"Description": "Real private consumption, %oya, 3mma, in excess of 5-y median GDP growth",
"Geography": "weighted",
},
"XRPCONS_SA_P1M1ML12_3MMA_ZN": {
"Group": "Private consumption",
"Label": "Excess real consum growth",
"Description": "Real private consumption, %oya, 3mma, in excess of 5-y median GDP growth",
"Geography": "local",
},
"XRWAGES_NSA_P1M1ML12_ZN": {
"Group": "Labour market",
"Label": "Excess real wage growth",
"Description": "Real wage growth, %oya, in excess of medium-term productivity growth",
"Geography": "local",
},
}
cat_labels = pd.DataFrame(cat_labels).T
cat_alllabel_dict = cat_labels[["Label", "Geography"]].agg(", ".join, axis=1).to_dict()
cat_labels = (
cat_labels
.reset_index(drop=False)
.rename(columns={"index": "Category"})
.set_index(["Group", "Category"])
.sort_index()
)
cat_groups_count = (
cat_labels.index.to_frame()
.reset_index(drop=True)
.groupby("Group")["Category"].count()
.sort_values(ascending=True)
)
fig = cat_groups_count.plot.barh(
ylabel="",
fontsize=11
)
fig.set_title(label="Number of categories by aggregate macro group", pad=20)
fig.title.set_size(16)
plt.plot()
[]
Feature filtering and imputation #
Cross-section availability requirement #
# All normalized macroeconomic categories
all_macroz = [x + "_ZN" for x in ecos]
# Identify categories with less than 10 cross sections
df_macro = df[df["xcat"].isin(all_macroz)]
cid_counts = df_macro.groupby('xcat')['cid'].nunique()
xcatx_low_cid = cid_counts[cid_counts < 10].index.tolist()
print("Categories with less than 10 cross sections:\n")
for xcat in xcatx_low_cid:
print(xcat)
# Remove categories with less than 10 cross sections
macroz = [x for x in all_macroz if not x in xcatx_low_cid]
# Identify categories that have short history
df_macro = df[df["xcat"].isin(macroz)]
cutoff_date = pd.Timestamp("2003-01-01")
min_dates = df_macro.groupby('xcat')['real_date'].min()
xcatx_late_start = min_dates[min_dates >= cutoff_date].index.tolist()
print("\nCategories that start after 2002:\n")
for xcat in xcatx_late_start:
print(xcat)
# Remove categories that start late
macroz = [x for x in macroz if not x in xcatx_late_start]
Categories with less than 10 cross sections:
CBCSCORE_SA_D3M3ML3_WG_ZN
CBCSCORE_SA_D3M3ML3_ZN
CBCSCORE_SA_WG_ZN
CBCSCORE_SA_ZN
CORPINTNETGDP_SA_D1Q1QL4_WG_ZN
CORPINTNETGDP_SA_D1Q1QL4_ZN
HHINTNETGDP_SA_D1M1ML12_WG_ZN
HHINTNETGDP_SA_D1M1ML12_ZN
Categories that start after 2002:
COXR_VT10vWTI_21DMA_ZN
# Reduce label dictionary
cat_label_dict = {k:v for k, v in cat_alllabel_dict.items() if k in macroz}
# Visualize remaining macroeconomic categories
msm.check_availability(df, xcats=macroz, cids=cids_eq, missing_recent=False)
Conditional imputation of missing cross-sections #
# Impute cross-sectional values if majority of cross sections are available
# Set parameters
impute_missing_cids = True
min_ratio_cids = 0.4
# Exclude categories than cannot logically be imputed
non_imputables = [
"CXPI_NSA_P1M12ML1_ZN",
"CMPI_NSA_P1M12ML1_ZN",
"CTOT_NSA_P1M12ML1_ZN",
"REEROADJ_NSA_P1M12ML1_ZN",
]
imputables = list(set(macroz) - set(non_imputables))
if impute_missing_cids:
df_impute = msp.impute_panel(
df=df, xcats=imputables, cids=cids_eq, threshold=min_ratio_cids
)
dfx = msm.update_df(df, df_impute)
else:
dfx = df.copy()
# Visualize imputed macroeconomic categories
msm.check_availability(dfx, xcats=macroz, cids=cids_eq, missing_recent=False)
Equity sectoral return blacklisting #
sector_blacklist = {}
for sec in list(set(cids_secs) - {"ALL"}):
dfb = df[df["xcat"] == f"EQC{sec}UNTRADABLE_NSA"].loc[:, ["cid", "xcat", "real_date", "value"]]
dfba = (
dfb.groupby(["cid", "real_date"])
.aggregate(value=pd.NamedAgg(column="value", aggfunc="max"))
.reset_index()
)
dfba["xcat"] = f"EQC{sec}BLACK"
sector_blacklist[sec] = msp.make_blacklist(dfba, f"EQC{sec}BLACK")
Visualize target availability #
targets = [
x for x in eqrets if x.endswith(("R_NSAvALL", "R_VT10vALL"))
]
msm.check_availability(dfx, targets, missing_recent=False)
Sectoral signals and naive PnLs #
Common pipeline for all sectors #
default_target_type = "R_VT10vALL"
default_splitter = msl.ExpandingKFoldPanelSplit()
default_metric = make_scorer(msl.sharpe_ratio, greater_is_better=True)
# Model dictionary
default_models = {
"ols": Pipeline(
[
("selector", msl.LarsSelector()),
("predictor", msl.ModifiedLinearRegression(method = "analytic")),
]
),
"swls": Pipeline(
[
("selector", msl.LarsSelector()),
("predictor", msl.ModifiedSignWeightedLinearRegression(method = "analytic")),
]
),
"twls": Pipeline(
[
("selector", msl.LarsSelector()),
("predictor", msl.ModifiedTimeWeightedLinearRegression(method = "analytic")),
]
),
}
# Hyperparameter grid
default_hparam_grid = {
"ols": {
"selector__n_factors": [3, 5, 10],
"predictor__fit_intercept": [True, False]
},
"swls": {
"selector__n_factors": [3, 5, 10],
"predictor__fit_intercept": [True, False]
},
"twls": {
"selector__n_factors": [3, 5, 10],
"predictor__fit_intercept": [True, False],
"predictor__half_life": [12, 24, 36, 60],
},
}
# Default parameters
default_test_size = 3 # retraining interval in months
default_min_cids = 2 # minimum number of cids to start predicting
default_min_periods = 24 # minimum number of periods to start predicting
default_threshold_ndates = 24 # number of rebalancing dates to pass before incrementing the number of CV splits
default_initial_nsplits = 3 # initial number of cross-validation splits
default_start_date = "2003-01-31" # start date for the analysis
Energy #
Factor selection and signal generation #
sector = "ENR"
enr_dict = {
"sector_name": sector_labels[sector],
"signal_name": f"{sector}SOL",
"pnl_name": f"{sector_labels[sector]} learning-based signal",
"xcatx": macroz,
"cidx": list(set(cids_eq)-set(["CHF"])), # CHF has no energy companies
"ret": f"EQC{sector}{default_target_type}",
"freq": "M",
"black": sector_blacklist[sector],
"srr": None,
"pnls": None,
}
# Converted selected features and targets to scikit-learn format
xcatx = enr_dict["xcatx"] + [enr_dict["ret"]]
cidx = enr_dict["cidx"]
dfw_enr = msm.categories_df(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=enr_dict["freq"],
blacklist=enr_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
).sort_index().dropna()
X_enr = dfw_enr.iloc[:, :-1]
y_enr = dfw_enr.iloc[:, -1]
secname = enr_dict["sector_name"]
signal_name = enr_dict["signal_name"]
so_enr = msl.SignalOptimizer(
inner_splitter=default_splitter,
X=X_enr,
y=y_enr,
threshold_ndates = default_threshold_ndates,
initial_nsplits = default_initial_nsplits,
)
so_enr.calculate_predictions(
name=signal_name,
models=default_models,
metric=default_metric,
hparam_grid=default_hparam_grid,
test_size=default_test_size,
min_cids=default_min_cids,
min_periods=default_min_periods,
n_jobs=-1,
)
so_enr.models_heatmap(
signal_name,
cap=10,
title=f"{secname} sector: model selection heatmap",
)
# Store signals
dfa = so_enr.get_optimized_signals()
dfx = msm.update_df(dfx, dfa)
xcatx = enr_dict["signal_name"]
secname = enr_dict["sector_name"]
so_enr.feature_selection_heatmap(
xcatx,
remove_blanks=True,
title=f"{secname} sector: feature selection heatmap",
ftrs_renamed=cat_label_dict,
figsize=(12, 10),
)
xcatx = enr_dict["signal_name"]
secname = enr_dict["sector_name"]
so_enr.coefs_stackedbarplot(
name=xcatx,
ftrs_renamed=cat_label_dict,
title=f"{secname} sector: annual averages of most important feature coefficients",
)
Signal quality check #
xcatx = [enr_dict["signal_name"], enr_dict["ret"]]
cidx = enr_dict["cidx"]
secname = enr_dict["sector_name"]
cr_enr = msp.CategoryRelations(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=enr_dict["freq"],
lag=1,
blacklist = enr_dict["black"],
xcat_aggs=["last", "sum"],
slip=1,
xcat_trims=[30, 30], # trim dodgy data point
)
cr_enr.reg_scatter(
title=f"{secname} sector: learning-based signal and subsequent returns",
labels=False,
prob_est="map",
xlab=f"{secname} signal, end-of-month, based on concurrent best model",
ylab=f"Relative return of {secname.lower()} sector (vol-targeted), next month, %",
coef_box="upper left",
size=(12, 8),
)
xcatx = [enr_dict["signal_name"]]
cidx = enr_dict["cidx"]
secname = enr_dict["sector_name"]
pnl_enr = msn.NaivePnL(
df=dfx,
ret=enr_dict["ret"],
sigs=xcatx,
cids=cidx,
start=default_start_date,
blacklist=enr_dict["black"],
bms=["USD_EQXR_NSA"],
)
for xcat in xcatx:
pnl_enr.make_pnl(
sig=xcat,
sig_op="zn_score_pan",
rebal_freq="monthly",
neutral="zero",
rebal_slip=1,
vol_scale = None,
thresh=3,
pnl_name=enr_dict["pnl_name"],
)
pnl_enr.make_long_pnl(
vol_scale=None, label=f"{secname} always long versus all-sector basket"
)
pnl_enr.plot_pnls(
pnl_cats=pnl_enr.pnl_names,
title=f"{secname} sector: naive PnLs of positions versus all-sector basket",
title_fontsize=14
)
enr_dict["pnls"] = pnl_enr
pnl_enr.evaluate_pnls(pnl_cats=pnl_enr.pnl_names)
xcat | Energy always long versus all-sector basket | Energy learning-based signal |
---|---|---|
Return % | -17.329838 | 45.240855 |
St. Dev. % | 53.003341 | 69.428418 |
Sharpe Ratio | -0.326957 | 0.651619 |
Sortino Ratio | -0.450023 | 0.974416 |
Max 21-Day Draw % | -78.404808 | -134.900713 |
Max 6-Month Draw % | -186.69396 | -113.815095 |
Peak to Trough Draw % | -837.214078 | -174.119478 |
Top 5% Monthly PnL Share | -1.452358 | 0.822625 |
USD_EQXR_NSA correl | -0.046569 | -0.096442 |
Traded Months | 259 | 259 |
secname = enr_dict["sector_name"]
pnl_enr.signal_heatmap(
pnl_name=enr_dict["pnl_name"],
figsize=(12, 3),
title=f"{secname} sector: signal heatmap",
)
Materials #
Factor selection and signal generation #
sector = "MAT"
mat_dict = {
"sector_name": sector_labels[sector],
"signal_name": f"{sector}SOL",
"pnl_name": f"{sector_labels[sector]} learning-based signal",
"xcatx": macroz,
"cidx": cids_eq,
"ret": f"EQC{sector}{default_target_type}",
"freq": "M",
"black": sector_blacklist[sector],
"srr": None,
"pnls": None,
}
# Converted selected features and targets to scikit-learn format
xcatx = mat_dict["xcatx"] + [mat_dict["ret"]]
cidx = mat_dict["cidx"]
dfw_mat = msm.categories_df(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=mat_dict["freq"],
blacklist=mat_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
).dropna()
X_mat = dfw_mat.iloc[:, :-1]
y_mat = dfw_mat.iloc[:, -1]
secname = mat_dict["sector_name"]
signal_name = mat_dict["signal_name"]
so_mat = msl.SignalOptimizer(
inner_splitter=default_splitter,
X=X_mat,
y=y_mat,
threshold_ndates=default_threshold_ndates,
initial_nsplits=default_initial_nsplits,
)
so_mat.calculate_predictions(
name=signal_name,
models=default_models,
metric=default_metric,
hparam_grid=default_hparam_grid,
test_size=default_test_size,
min_cids=default_min_cids,
min_periods=default_min_periods,
n_jobs=-1,
)
so_mat.models_heatmap(
signal_name,
cap=10,
title=f"{secname} sector: model selection heatmap",
)
# Store signals
dfa = so_mat.get_optimized_signals()
dfx = msm.update_df(dfx, dfa)
xcatx = mat_dict["signal_name"]
secname = mat_dict["sector_name"]
so_mat.feature_selection_heatmap(
xcatx,
remove_blanks=True,
title=f"{secname} sector: feature selection heatmap",
ftrs_renamed=cat_label_dict,
figsize=(12, 10),
)
xcatx = mat_dict["signal_name"]
secname = mat_dict["sector_name"]
so_mat.coefs_stackedbarplot(
name=xcatx,
ftrs_renamed=cat_label_dict,
title=f"{secname} sector: annual averages of most important feature coefficients",
)
Signal quality check #
xcatx = [mat_dict["signal_name"], mat_dict["ret"]]
cidx = mat_dict["cidx"]
secname = mat_dict["sector_name"]
cr_mat = msp.CategoryRelations(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=mat_dict["freq"],
blacklist=mat_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
slip=1,
)
cr_mat.reg_scatter(
title=f"{secname} sector: learning-based signal and subsequent returns",
labels=False,
prob_est="map",
xlab=f"{secname} signal, end-of-month, based on concurrent best model",
ylab=f"Relative return of {secname.lower()} sector (vol-targeted), next month, %",
coef_box="upper left",
size=(12, 8),
)
xcatx = [mat_dict["signal_name"]]
cidx = mat_dict["cidx"]
secname = mat_dict["sector_name"]
pnl_name=mat_dict["pnl_name"]
pnl_mat = msn.NaivePnL(
df=dfx,
ret=mat_dict["ret"],
sigs=xcatx,
cids=cidx,
start=default_start_date,
blacklist=mat_dict["black"],
bms=["USD_EQXR_NSA"],
)
for xcat in xcatx:
pnl_mat.make_pnl(
sig=xcat,
sig_op="zn_score_pan",
rebal_freq="monthly",
neutral="zero",
rebal_slip=1,
vol_scale=None,
thresh=3,
pnl_name=pnl_name,
)
pnl_mat.make_long_pnl(
vol_scale=None, label=f"{secname} always long versus all-sector basket"
)
pnl_mat.plot_pnls(
pnl_cats=pnl_mat.pnl_names,
title=f"{secname} sector: naive PnLs of positions versus all-sector basket",
title_fontsize=14
)
mat_dict["pnls"] = pnl_mat
pnl_mat.evaluate_pnls(pnl_cats=pnl_mat.pnl_names)
xcat | Materials always long versus all-sector basket | Materials learning-based signal |
---|---|---|
Return % | -22.344101 | 28.04184 |
St. Dev. % | 39.907352 | 46.623586 |
Sharpe Ratio | -0.559899 | 0.601452 |
Sortino Ratio | -0.767954 | 0.852735 |
Max 21-Day Draw % | -61.657388 | -95.041086 |
Max 6-Month Draw % | -152.838949 | -70.278055 |
Peak to Trough Draw % | -689.542867 | -131.513106 |
Top 5% Monthly PnL Share | -0.700612 | 0.877869 |
USD_EQXR_NSA correl | 0.023979 | 0.002989 |
Traded Months | 259 | 259 |
secname = mat_dict["sector_name"]
xcatx = mat_dict["signal_name"]
pnl_mat.signal_heatmap(
pnl_name=f"{secname} learning-based signal",
figsize=(12, 3),
title=f"{secname} sector: signal heatmap",
)
Industrials #
Factor selection and signal generation #
sector = "IND"
ind_dict = {
"sector_name": sector_labels[sector],
"signal_name": f"{sector}SOL",
"pnl_name": f"{sector_labels[sector]} learning-based signal",
"xcatx": macroz,
"cidx": cids_eq,
"ret": f"EQC{sector}{default_target_type}",
"freq": "M",
"black": sector_blacklist[sector],
"srr": None,
"pnls": None,
}
# Converted selected features and targets to scikit-learn format
xcatx = ind_dict["xcatx"] + [ind_dict["ret"]]
cidx = ind_dict["cidx"]
dfw_ind = msm.categories_df(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=ind_dict["freq"],
blacklist=ind_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
).sort_index().dropna()
X_ind = dfw_ind.iloc[:, :-1]
y_ind = dfw_ind.iloc[:, -1]
secname = ind_dict["sector_name"]
signal_name = ind_dict["signal_name"]
so_ind = msl.SignalOptimizer(
inner_splitter=default_splitter,
X=X_ind,
y=y_ind,
threshold_ndates = default_threshold_ndates,
initial_nsplits = default_initial_nsplits,
)
so_ind.calculate_predictions(
name=signal_name,
models=default_models,
metric=default_metric,
hparam_grid=default_hparam_grid,
test_size=default_test_size,
min_cids=default_min_cids,
min_periods=default_min_periods,
n_jobs=-1,
)
so_ind.models_heatmap(
signal_name,
cap=10,
title=f"{secname} sector: model selection heatmap",
)
# Store signals
dfa = so_ind.get_optimized_signals()
dfx = msm.update_df(dfx, dfa)
secname = ind_dict["sector_name"]
xcatx = ind_dict["signal_name"]
so_ind.feature_selection_heatmap(
xcatx,
remove_blanks=True,
title=f"{secname} sector: feature selection heatmap",
ftrs_renamed=cat_label_dict,
figsize=(12, 10),
)
secname = ind_dict["sector_name"]
xcatx = ind_dict["signal_name"]
so_ind.coefs_stackedbarplot(
name=xcatx,
ftrs_renamed=cat_label_dict,
title=f"{secname} sector: annual averages of most important feature coefficients",
)
Signal quality check #
xcatx = [ind_dict["signal_name"], ind_dict["ret"]]
cidx = ind_dict["cidx"]
secname = ind_dict["sector_name"]
cr_ind = msp.CategoryRelations(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=ind_dict["freq"],
blacklist=ind_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
slip=1,
)
cr_ind.reg_scatter(
title=f"{secname} sector: learning-based signal and subsequent returns",
labels=False,
prob_est="map",
xlab=f"{secname} signal, end-of-month, based on concurrent best model",
ylab=f"Relative return of {secname.lower()} sector (vol-targeted), next month, %",
coef_box="upper left",
size=(12, 8),
)
xcatx = [ind_dict["signal_name"]]
cidx = ind_dict["cidx"]
secname = ind_dict["sector_name"]
pnl_name = ind_dict["pnl_name"]
pnl_ind = msn.NaivePnL(
df=dfx,
ret=ind_dict["ret"],
sigs=xcatx,
cids=cidx,
start=default_start_date,
bms=["USD_EQXR_NSA"],
blacklist = ind_dict["black"],
)
for xcat in xcatx:
pnl_ind.make_pnl(
sig=xcat,
sig_op="zn_score_pan",
rebal_freq="monthly",
neutral="zero",
rebal_slip=1,
vol_scale = None,
thresh=3,
pnl_name=pnl_name,
)
pnl_ind.make_long_pnl(
vol_scale=None, label=f"{secname} always long versus all-sector basket"
)
pnl_ind.plot_pnls(
pnl_cats=pnl_ind.pnl_names,
title=f"{secname} sector: naive PnLs of positions versus all-sector basket",
title_fontsize=14
)
ind_dict["pnls"] = pnl_ind
pnl_ind.evaluate_pnls(pnl_cats=pnl_ind.pnl_names)
xcat | Industrials always long versus all-sector basket | Industrials learning-based signal |
---|---|---|
Return % | 16.094063 | 8.127747 |
St. Dev. % | 31.542136 | 29.801776 |
Sharpe Ratio | 0.51024 | 0.272727 |
Sortino Ratio | 0.724523 | 0.392091 |
Max 21-Day Draw % | -54.172009 | -41.230626 |
Max 6-Month Draw % | -63.203195 | -54.192114 |
Peak to Trough Draw % | -91.886853 | -90.747758 |
Top 5% Monthly PnL Share | 0.877142 | 1.918922 |
USD_EQXR_NSA correl | 0.264486 | 0.016377 |
Traded Months | 259 | 259 |
xcatx = ind_dict["signal_name"]
pnl_ind.signal_heatmap(
pnl_name=f"{secname} learning-based signal",
figsize=(12, 3),
title=f"{secname} sector: signal heatmap",
)
Consumer discretionary #
Factor selection and signal generation #
sector = "COD"
cod_dict = {
"sector_name": sector_labels[sector],
"signal_name": f"{sector}SOL",
"pnl_name": f"{sector_labels[sector]} learning-based signal",
"xcatx": macroz,
"cidx": cids_eq,
"ret": f"EQC{sector}{default_target_type}",
"freq": "M",
"black": sector_blacklist[sector],
"srr": None,
"pnls": None,
}
# Converted selected features and targets to scikit-learn format
xcatx = cod_dict["xcatx"] + [cod_dict["ret"]]
cidx = cod_dict["cidx"]
dfw_cod = msm.categories_df(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=cod_dict["freq"],
blacklist=cod_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
).sort_index().dropna()
X_cod = dfw_cod.iloc[:, :-1]
y_cod = dfw_cod.iloc[:, -1]
secname = cod_dict["sector_name"]
signal_name = cod_dict["signal_name"]
so_cod = msl.SignalOptimizer(
inner_splitter=default_splitter,
X=X_cod,
y=y_cod,
threshold_ndates = default_threshold_ndates,
initial_nsplits = default_initial_nsplits,
)
so_cod.calculate_predictions(
name=signal_name,
models=default_models,
metric=default_metric,
hparam_grid=default_hparam_grid,
test_size=default_test_size,
min_cids=default_min_cids,
min_periods=default_min_periods,
n_jobs=-1,
)
so_cod.models_heatmap(
signal_name,
cap=10,
title=f"{secname} sector: model selection heatmap",
)
# Store signals
dfa = so_cod.get_optimized_signals()
dfx = msm.update_df(dfx, dfa)
xcatx = cod_dict["signal_name"]
secname = cod_dict["sector_name"]
so_cod.feature_selection_heatmap(
xcatx,
remove_blanks=True,
title=f"{secname} sector: feature selection heatmap",
ftrs_renamed=cat_label_dict,
figsize=(12, 10),
)
xcatx = cod_dict["signal_name"]
secname = cod_dict["sector_name"]
so_cod.coefs_stackedbarplot(
name=xcatx,
ftrs_renamed=cat_label_dict,
title=f"{secname} sector: annual averages of most important feature coefficients",
)
Signal quality check #
xcatx = [cod_dict["signal_name"], cod_dict["ret"]]
cidx = cod_dict["cidx"]
signal_name = cod_dict["signal_name"]
cr_cod = msp.CategoryRelations(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=cod_dict["freq"],
blacklist = cod_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
slip=1,
)
cr_cod.reg_scatter(
title=f"{secname} sector: learning-based signal and subsequent returns",
labels=False,
prob_est="map",
xlab=f"{secname} signal, end-of-month, based on concurrent best model",
ylab=f"Relative return of {secname.lower()} sector (vol-targeted), next month, %",
coef_box="upper left",
size=(12, 8),
)
xcatx = [cod_dict["signal_name"]]
cidx = cod_dict["cidx"]
secname = cod_dict["sector_name"]
signal_name = cod_dict["signal_name"]
pnl_name = cod_dict["pnl_name"]
pnl_cod = msn.NaivePnL(
df=dfx,
ret=cod_dict["ret"],
sigs=xcatx,
cids=cidx,
start=default_start_date,
blacklist = cod_dict["black"],
bms=["USD_EQXR_NSA"],
)
for xcat in xcatx:
pnl_cod.make_pnl(
sig=xcat,
sig_op="zn_score_pan",
rebal_freq="monthly",
neutral="zero",
rebal_slip=1,
vol_scale = None,
thresh=3,
pnl_name=pnl_name,
)
pnl_cod.make_long_pnl(
vol_scale=None, label=f"{secname} always long versus all-sector basket"
)
pnl_cod.plot_pnls(
pnl_cats=pnl_cod.pnl_names,
title=f"{secname} sector: naive PnLs of positions versus all-sector basket",
title_fontsize=14
)
cod_dict["pnls"] = pnl_cod
pnl_cod.evaluate_pnls(pnl_cats=pnl_cod.pnl_names)
xcat | Cons. discretionary always long versus all-sector basket | Cons. discretionary learning-based signal |
---|---|---|
Return % | -15.31235 | 15.463861 |
St. Dev. % | 31.222662 | 32.068285 |
Sharpe Ratio | -0.490424 | 0.482217 |
Sortino Ratio | -0.677743 | 0.700718 |
Max 21-Day Draw % | -68.480798 | -46.080215 |
Max 6-Month Draw % | -96.076731 | -56.362704 |
Peak to Trough Draw % | -348.545916 | -80.91694 |
Top 5% Monthly PnL Share | -0.735885 | 0.95454 |
USD_EQXR_NSA correl | 0.095412 | -0.025281 |
Traded Months | 259 | 259 |
pnl_name = cod_dict["pnl_name"]
secname = cod_dict["sector_name"]
pnl_cod.signal_heatmap(
pnl_name=f"{secname} learning-based signal",
figsize=(12, 3),
title=f"{secname} sector: signal heatmap",
)
Consumer staples #
Factor selection and signal generation #
sector = "COS"
cos_dict = {
"sector_name": sector_labels[sector],
"signal_name": f"{sector}SOL",
"pnl_name": f"{sector_labels[sector]} learning-based signal",
"xcatx": macroz,
"cidx": cids_eq,
"ret": f"EQC{sector}{default_target_type}",
"freq": "M",
"black": sector_blacklist[sector],
"srr": None,
"pnls": None,
}
# Converted selected features and targets to scikit-learn format
xcatx = cos_dict["xcatx"] + [cos_dict["ret"]]
cidx = cos_dict["cidx"]
dfw_cos = msm.categories_df(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=cos_dict["freq"],
blacklist = cos_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
).sort_index().dropna()
X_cos = dfw_cos.iloc[:, :-1]
y_cos = dfw_cos.iloc[:, -1]
secname = cos_dict["sector_name"]
signal_name = cos_dict["signal_name"]
so_cos = msl.SignalOptimizer(
inner_splitter=default_splitter,
X=X_cos,
y=y_cos,
threshold_ndates = default_threshold_ndates,
initial_nsplits = default_initial_nsplits,
)
so_cos.calculate_predictions(
name=signal_name,
models=default_models,
metric=default_metric,
hparam_grid=default_hparam_grid,
test_size=default_test_size,
min_cids=default_min_cids,
min_periods=default_min_periods,
n_jobs=-1,
)
so_cos.models_heatmap(
signal_name,
cap=10,
title=f"{secname} sector: model selection heatmap",
)
# Store signals
dfa = so_cos.get_optimized_signals()
dfx = msm.update_df(dfx, dfa)
xcatx = cos_dict["signal_name"]
secname = cos_dict["sector_name"]
so_cos.feature_selection_heatmap(
xcatx,
remove_blanks=True,
title=f"{secname} sector: feature selection heatmap",
ftrs_renamed=cat_label_dict,
figsize=(12, 10),
)
xcatx = cos_dict["signal_name"]
secname = cos_dict["sector_name"]
so_cos.coefs_stackedbarplot(
name=xcatx,
ftrs_renamed=cat_label_dict,
title=f"{secname} sector: annual averages of most important feature coefficients",
)
Signal quality check #
xcatx = [cos_dict["signal_name"], cos_dict["ret"]]
cidx = cos_dict["cidx"]
secname = cos_dict["sector_name"]
cr_cos = msp.CategoryRelations(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=cos_dict["freq"],
blacklist = cos_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
slip=1,
)
cr_cos.reg_scatter(
title=f"{secname} sector: learning-based signal and subsequent returns",
labels=False,
prob_est="map",
xlab=f"{secname} signal, end-of-month, based on concurrent best model",
ylab=f"Relative return of {secname.lower()} sector (vol-targeted), next month, %",
coef_box="upper left",
size=(12, 8),
)
xcatx = [cos_dict["signal_name"]]
cidx = cos_dict["cidx"]
secname = cos_dict["sector_name"]
signal_name = cos_dict["signal_name"]
pnl_name = cos_dict["pnl_name"]
pnl_cos = msn.NaivePnL(
df=dfx,
ret=cos_dict["ret"],
sigs=xcatx,
cids=cidx,
start=default_start_date,
blacklist = cos_dict["black"],
bms=["USD_EQXR_NSA"],
)
for xcat in xcatx:
pnl_cos.make_pnl(
sig=xcat,
sig_op="zn_score_pan",
rebal_freq="monthly",
neutral="zero",
rebal_slip=1,
vol_scale = None,
thresh=3,
pnl_name=pnl_name,
)
pnl_cos.make_long_pnl(
vol_scale=None, label=f"{secname} always long versus all-sector basket"
)
pnl_cos.plot_pnls(
pnl_cats=pnl_cos.pnl_names,
title=f"{secname} sector: naive PnLs of positions versus all-sector basket",
title_fontsize=14
)
cos_dict["pnls"] = pnl_cos
pnl_cos.evaluate_pnls(pnl_cats=pnl_cos.pnl_names)
xcat | Cons. staples always long versus all-sector basket | Cons. staples learning-based signal |
---|---|---|
Return % | 7.593452 | 19.203292 |
St. Dev. % | 37.489304 | 34.446072 |
Sharpe Ratio | 0.20255 | 0.557489 |
Sortino Ratio | 0.290393 | 0.823897 |
Max 21-Day Draw % | -33.681565 | -51.713239 |
Max 6-Month Draw % | -93.828486 | -59.198678 |
Peak to Trough Draw % | -188.904198 | -97.037594 |
Top 5% Monthly PnL Share | 2.193531 | 0.999179 |
USD_EQXR_NSA correl | -0.132772 | -0.027091 |
Traded Months | 259 | 259 |
pnl_name = cos_dict["pnl_name"]
secname = cos_dict["sector_name"]
pnl_cos.signal_heatmap(
pnl_name=pnl_name,
figsize=(12, 3),
title=f"{secname} sector: signal heatmap",
)
Healthcare #
Factor selection and signal generation #
sector = "HLC"
hlc_dict = {
"sector_name": sector_labels[sector],
"signal_name": f"{sector}SOL",
"pnl_name": f"{sector_labels[sector]} learning-based signal",
"xcatx": macroz,
"cidx": cids_eq,
"ret": f"EQC{sector}{default_target_type}",
"freq": "M",
"black": sector_blacklist[sector],
"srr": None,
"pnls": None,
}
# Converted selected features and targets to scikit-learn format
xcatx = hlc_dict["xcatx"] + [hlc_dict["ret"]]
cidx = hlc_dict["cidx"]
dfw_hlc = msm.categories_df(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=hlc_dict["freq"],
blacklist=hlc_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
).sort_index().dropna()
X_hlc = dfw_hlc.iloc[:, :-1]
y_hlc = dfw_hlc.iloc[:, -1]
secname = hlc_dict["sector_name"]
signal_name = hlc_dict["signal_name"]
so_hlc = msl.SignalOptimizer(
inner_splitter=default_splitter,
X=X_hlc,
y=y_hlc,
threshold_ndates = default_threshold_ndates,
initial_nsplits = default_initial_nsplits,
)
so_hlc.calculate_predictions(
name=signal_name,
models=default_models,
metric=default_metric,
hparam_grid=default_hparam_grid,
test_size=default_test_size,
min_cids=default_min_cids,
min_periods=default_min_periods,
n_jobs=-1,
)
so_hlc.models_heatmap(
signal_name,
cap=10,
title=f"{secname} sector: model selection heatmap",
)
# Store signals
dfa = so_hlc.get_optimized_signals()
dfx = msm.update_df(dfx, dfa)
xcatx = hlc_dict["signal_name"]
so_hlc.feature_selection_heatmap(
xcatx,
remove_blanks=True,
title="Feature selection heatmap, healthcare sector",
ftrs_renamed=cat_label_dict,
figsize=(12, 10),
)
xcatx = hlc_dict["signal_name"]
signal_name = hlc_dict["signal_name"]
so_hlc.coefs_stackedbarplot(
name=xcatx,
ftrs_renamed=cat_label_dict,
title=f"{secname} sector: annual averages of most important feature coefficients",
)
Signal quality check #
xcatx = [hlc_dict["signal_name"], hlc_dict["ret"]]
cidx = hlc_dict["cidx"]
secname = hlc_dict["sector_name"]
cr_hlc = msp.CategoryRelations(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=hlc_dict["freq"],
blacklist = hlc_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
slip=1,
)
cr_hlc.reg_scatter(
title=f"{secname} sector: learning-based signal and subsequent returns",
labels=False,
prob_est="map",
xlab=f"{secname} signal, end-of-month, based on concurrent best model",
ylab=f"Relative return of {secname.lower()} sector (vol-targeted), next month, %",
coef_box="upper left",
size=(12, 8),
)
xcatx = [hlc_dict["signal_name"]]
cidx = hlc_dict["cidx"]
secname = hlc_dict["sector_name"]
signal_name = hlc_dict["signal_name"]
pnl_name = hlc_dict["pnl_name"]
pnl_hlc = msn.NaivePnL(
df=dfx,
ret=hlc_dict["ret"],
sigs=xcatx,
cids=cidx,
start=default_start_date,
blacklist = hlc_dict["black"],
bms=["USD_EQXR_NSA"],
)
for xcat in xcatx:
pnl_hlc.make_pnl(
sig=xcat,
sig_op="zn_score_pan",
rebal_freq="monthly",
neutral="zero",
rebal_slip=1,
vol_scale = None,
thresh=3,
pnl_name=pnl_name,
)
pnl_hlc.make_long_pnl(
vol_scale=None, label=f"{secname} always long versus all-sector basket"
)
pnl_hlc.plot_pnls(
pnl_cats=pnl_hlc.pnl_names,
title=f"{secname} sector: naive PnLs of positions versus all-sector basket",
title_fontsize=14
)
hlc_dict["pnls"] = pnl_hlc
pnl_hlc.evaluate_pnls(pnl_cats=pnl_hlc.pnl_names)
xcat | Healthcare always long versus all-sector basket | Healthcare learning-based signal |
---|---|---|
Return % | -2.636272 | 6.570015 |
St. Dev. % | 38.515166 | 40.975564 |
Sharpe Ratio | -0.068448 | 0.16034 |
Sortino Ratio | -0.09828 | 0.227905 |
Max 21-Day Draw % | -47.409795 | -88.317844 |
Max 6-Month Draw % | -93.207315 | -90.456598 |
Peak to Trough Draw % | -263.887278 | -198.493241 |
Top 5% Monthly PnL Share | -6.221331 | 2.783057 |
USD_EQXR_NSA correl | -0.159854 | 0.046437 |
Traded Months | 259 | 259 |
pnl_name = hlc_dict["pnl_name"]
secname = hlc_dict["sector_name"]
pnl_hlc.signal_heatmap(
pnl_name=pnl_name,
figsize=(12, 3),
title=f"{secname} sector: signal heatmap",
)
Financials #
Factor selection and signal generation #
sector = "FIN"
fin_dict = {
"sector_name": sector_labels[sector],
"signal_name": f"{sector}SOL",
"pnl_name": f"{sector_labels[sector]} learning-based signal",
"xcatx": macroz,
"cidx": cids_eq,
"ret": f"EQC{sector}{default_target_type}",
"freq": "M",
"black": sector_blacklist[sector],
"srr": None,
"pnls": None,
}
# Converted selected features and targets to scikit-learn format
xcatx = fin_dict["xcatx"] + [fin_dict["ret"]]
cidx = fin_dict["cidx"]
dfw_fin = msm.categories_df(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=fin_dict["freq"],
blacklist=fin_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
).sort_index().dropna()
X_fin = dfw_fin.iloc[:, :-1]
y_fin = dfw_fin.iloc[:, -1]
secname = fin_dict["sector_name"]
signal_name = fin_dict["signal_name"]
so_fin = msl.SignalOptimizer(
inner_splitter=default_splitter,
X=X_fin,
y=y_fin,
threshold_ndates = default_threshold_ndates,
initial_nsplits = default_initial_nsplits,
)
so_fin.calculate_predictions(
name=signal_name,
models=default_models,
metric=default_metric,
hparam_grid=default_hparam_grid,
test_size=default_test_size,
min_cids=default_min_cids,
min_periods=default_min_periods,
n_jobs=-1,
)
so_fin.models_heatmap(
signal_name,
cap=10,
title=f"{secname} sector: model selection heatmap",
)
# Store signals
dfa = so_fin.get_optimized_signals()
dfx = msm.update_df(dfx, dfa)
xcatx = fin_dict["signal_name"]
secname = fin_dict["sector_name"]
so_fin.feature_selection_heatmap(
xcatx,
remove_blanks=True,
title=f"{secname} sector: feature selection heatmap",
ftrs_renamed=cat_label_dict,
figsize=(12, 10),
)
xcatx = fin_dict["signal_name"]
secname = fin_dict["sector_name"]
so_fin.coefs_stackedbarplot(
name=xcatx,
ftrs_renamed=cat_label_dict,
title=f"{secname} sector: annual averages of most important feature coefficients",
)
Signal quality check #
xcatx = [fin_dict["signal_name"], fin_dict["ret"]]
cidx = fin_dict["cidx"]
secname = fin_dict["sector_name"]
cr_fin = msp.CategoryRelations(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=fin_dict["freq"],
blacklist = fin_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
slip=1,
)
cr_fin.reg_scatter(
title=f"{secname} sector: learning-based signal and subsequent returns",
labels=False,
prob_est="map",
xlab=f"{secname} signal, end-of-month, based on concurrent best model",
ylab=f"Relative return of {secname.lower()} sector (vol-targeted), next month, %",
coef_box="upper left",
size=(12, 8),
)
xcatx = [fin_dict["signal_name"]]
cidx = fin_dict["cidx"]
secname = fin_dict["sector_name"]
signal_name = fin_dict["signal_name"]
pnl_name = fin_dict["pnl_name"]
pnl_fin = msn.NaivePnL(
df=dfx,
ret=fin_dict["ret"],
sigs=xcatx,
cids=cidx,
start=default_start_date,
blacklist = fin_dict["black"],
bms=["USD_EQXR_NSA"],
)
for xcat in xcatx:
pnl_fin.make_pnl(
sig=xcat,
sig_op="zn_score_pan",
rebal_freq="monthly",
neutral="zero",
rebal_slip=1,
vol_scale = None,
thresh=3,
pnl_name=pnl_name,
)
pnl_fin.make_long_pnl(
vol_scale=None, label=f"{secname} always long versus all-sector basket"
)
pnl_fin.plot_pnls(
pnl_cats=pnl_fin.pnl_names,
title=f"{secname} sector: naive PnLs of positions versus all-sector basket",
title_fontsize=14
)
fin_dict["pnls"] = pnl_fin
pnl_fin.evaluate_pnls(pnl_cats=pnl_fin.pnl_names)
xcat | Financials always long versus all-sector basket | Financials learning-based signal |
---|---|---|
Return % | 0.356038 | 1.348195 |
St. Dev. % | 37.914126 | 44.050302 |
Sharpe Ratio | 0.009391 | 0.030606 |
Sortino Ratio | 0.013681 | 0.044084 |
Max 21-Day Draw % | -76.126375 | -98.35711 |
Max 6-Month Draw % | -96.122679 | -178.935643 |
Peak to Trough Draw % | -332.744644 | -260.907163 |
Top 5% Monthly PnL Share | 51.811272 | 18.061715 |
USD_EQXR_NSA correl | 0.216566 | -0.115434 |
Traded Months | 259 | 259 |
xcatx = fin_dict["signal_name"]
pnl_name = fin_dict["pnl_name"]
secname = fin_dict["sector_name"]
pnl_fin.signal_heatmap(
pnl_name=pnl_name,
figsize=(12, 3),
title=f"{secname} sector: signal heatmap",
)
Technology #
Factor selection and signal generation #
sector = "ITE"
ite_dict = {
"sector_name": sector_labels[sector],
"signal_name": f"{sector}SOL",
"pnl_name": f"{sector_labels[sector]} learning-based signal",
"xcatx": macroz,
"cidx": cids_eq,
"ret": f"EQC{sector}{default_target_type}",
"freq": "M",
"black": sector_blacklist[sector],
"srr": None,
"pnls": None,
}
# Converted selected features and targets to scikit-learn format
xcatx = ite_dict["xcatx"] + [ite_dict["ret"]]
cidx = ite_dict["cidx"]
dfw_ite = msm.categories_df(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=ite_dict["freq"],
blacklist = ite_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
).sort_index().dropna()
X_ite = dfw_ite.iloc[:, :-1]
y_ite = dfw_ite.iloc[:, -1]
secname = ite_dict["sector_name"]
signal_name = ite_dict["signal_name"]
so_ite = msl.SignalOptimizer(
inner_splitter=default_splitter,
X=X_ite,
y=y_ite,
threshold_ndates = default_threshold_ndates,
initial_nsplits = default_initial_nsplits,
)
so_ite.calculate_predictions(
name=signal_name,
models=default_models,
metric=default_metric,
hparam_grid=default_hparam_grid,
test_size=default_test_size,
min_cids=default_min_cids,
min_periods=default_min_periods,
n_jobs=-1,
)
so_ite.models_heatmap(
signal_name,
cap=10,
title=f"{secname} sector: model selection heatmap",
)
# Store signals
dfa = so_ite.get_optimized_signals()
dfx = msm.update_df(dfx, dfa)
xcatx = ite_dict["signal_name"]
secname = ite_dict["sector_name"]
so_ite.feature_selection_heatmap(
xcatx,
remove_blanks=True,
title=f"{secname} sector: feature selection heatmap",
ftrs_renamed=cat_label_dict,
figsize=(12, 10),
)
xcatx = ite_dict["signal_name"]
secname = ite_dict["sector_name"]
so_ite.coefs_stackedbarplot(
name=xcatx,
ftrs_renamed=cat_label_dict,
title=f"{secname} sector: annual averages of most important feature coefficients",
)
Signal quality check #
xcatx = [ite_dict["signal_name"], ite_dict["ret"]]
cidx = ite_dict["cidx"]
secname = ite_dict["sector_name"]
cr_ite = msp.CategoryRelations(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=ite_dict["freq"],
blacklist = ite_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
slip=1,
)
cr_ite.reg_scatter(
title=f"{secname} sector: learning-based signal and subsequent returns",
labels=False,
prob_est="map",
xlab=f"{secname} signal, end-of-month, based on concurrent best model",
ylab=f"Relative return of {secname.lower()} sector (vol-targeted), next month, %",
coef_box="upper left",
size=(12, 8),
)
xcatx = [ite_dict["signal_name"]]
cidx = ite_dict["cidx"]
secname = ite_dict["sector_name"]
signal_name = ite_dict["signal_name"]
pnl_name = ite_dict["pnl_name"]
pnl_ite = msn.NaivePnL(
df=dfx,
ret=ite_dict["ret"],
sigs=xcatx,
cids=cidx,
start=default_start_date,
blacklist=ite_dict["black"],
bms=["USD_EQXR_NSA"],
)
for xcat in xcatx:
pnl_ite.make_pnl(
sig=xcat,
sig_op="zn_score_pan",
rebal_freq="monthly",
neutral="zero",
rebal_slip=1,
vol_scale = None,
thresh=3,
pnl_name=pnl_name,
)
pnl_ite.make_long_pnl(
vol_scale=None, label=f"{secname} always long versus all-sector basket"
)
pnl_ite.plot_pnls(
pnl_cats=pnl_ite.pnl_names,
title=f"{secname} sector: naive PnLs of positions versus all-sector basket",
title_fontsize=14,
)
ite_dict["pnls"] = pnl_ite
pnl_ite.evaluate_pnls(pnl_cats=pnl_ite.pnl_names)
xcat | Information tech always long versus all-sector basket | Information tech learning-based signal |
---|---|---|
Return % | -6.037478 | 8.042235 |
St. Dev. % | 37.37468 | 37.787246 |
Sharpe Ratio | -0.161539 | 0.212829 |
Sortino Ratio | -0.223487 | 0.299029 |
Max 21-Day Draw % | -43.579705 | -53.583944 |
Max 6-Month Draw % | -116.166222 | -79.099934 |
Peak to Trough Draw % | -404.663283 | -207.638985 |
Top 5% Monthly PnL Share | -2.636402 | 2.500706 |
USD_EQXR_NSA correl | 0.025743 | -0.001081 |
Traded Months | 259 | 259 |
pnl_name = ite_dict["pnl_name"]
secname = ite_dict["sector_name"]
pnl_ite.signal_heatmap(
pnl_name=pnl_name,
figsize=(12, 3),
title=f"{secname} sector: signal heatmap",
)
Communication #
Factor selection and signal generation #
sector = "CSR"
csr_dict = {
"sector_name": sector_labels[sector],
"signal_name": f"{sector}SOL",
"pnl_name": f"{sector_labels[sector]} learning-based signal",
"xcatx": macroz,
"cidx": cids_eq,
"ret": f"EQC{sector}{default_target_type}",
"freq": "M",
"black": sector_blacklist[sector],
"srr": None,
"pnls": None,
}
# Converted selected features and targets to scikit-learn format
xcatx = csr_dict["xcatx"] + [csr_dict["ret"]]
cidx = csr_dict["cidx"]
dfw_csr = msm.categories_df(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=csr_dict["freq"],
blacklist=csr_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
).sort_index().dropna()
X_csr = dfw_csr.iloc[:, :-1]
y_csr = dfw_csr.iloc[:, -1]
secname = csr_dict["sector_name"]
signal_name = csr_dict["signal_name"]
so_csr = msl.SignalOptimizer(
inner_splitter=default_splitter,
X=X_csr,
y=y_csr,
threshold_ndates = default_threshold_ndates,
initial_nsplits = default_initial_nsplits,
)
so_csr.calculate_predictions(
name=signal_name,
models=default_models,
metric=default_metric,
hparam_grid=default_hparam_grid,
test_size=default_test_size,
min_cids=default_min_cids,
min_periods=default_min_periods,
n_jobs=-1,
)
so_csr.models_heatmap(
signal_name,
cap=10,
title=f"{secname} sector: model selection heatmap",
)
# Store signals
dfa = so_csr.get_optimized_signals()
dfx = msm.update_df(dfx, dfa)
xcatx = csr_dict["signal_name"]
secname = csr_dict["sector_name"]
so_csr.feature_selection_heatmap(
xcatx,
remove_blanks=True,
title=f"{secname} sector: feature selection heatmap",
ftrs_renamed=cat_label_dict,
figsize=(12, 10),
)
xcatx = csr_dict["signal_name"]
secname = csr_dict["sector_name"]
so_csr.coefs_stackedbarplot(
name=xcatx,
ftrs_renamed=cat_label_dict,
title=f"{secname} sector: annual averages of most important feature coefficients",
)
Signal quality check #
xcatx = [csr_dict["signal_name"], csr_dict["ret"]]
cidx = csr_dict["cidx"]
secname = csr_dict["sector_name"]
cr_csr = msp.CategoryRelations(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=csr_dict["freq"],
blacklist = csr_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
slip=1,
)
cr_csr.reg_scatter(
title=f"{secname} sector: learning-based signal and subsequent returns",
labels=False,
prob_est="map",
xlab=f"{secname} signal, end-of-month, based on concurrent best model",
ylab=f"Relative return of {secname.lower()} sector (vol-targeted), next month, %",
coef_box="upper left",
size=(12, 8),
)
xcatx = [csr_dict["signal_name"]]
cidx = csr_dict["cidx"]
secname = csr_dict["sector_name"]
signal_name = csr_dict["signal_name"]
pnl_name = csr_dict["pnl_name"]
pnl_csr = msn.NaivePnL(
df=dfx,
ret=csr_dict["ret"],
sigs=xcatx,
cids=cidx,
start=default_start_date,
blacklist = csr_dict["black"],
bms=["USD_EQXR_NSA"],
)
for xcat in xcatx:
pnl_csr.make_pnl(
sig=xcat,
sig_op="zn_score_pan",
rebal_freq="monthly",
neutral="zero",
rebal_slip=1,
vol_scale = None,
thresh=3,
pnl_name=pnl_name,
)
pnl_csr.make_long_pnl(
vol_scale=None, label=f"{secname} always long versus all-sector basket"
)
pnl_csr.plot_pnls(
pnl_cats=pnl_csr.pnl_names,
title=f"{secname} sector: naive PnLs of positions versus all-sector basket",
title_fontsize=14
)
csr_dict["pnls"] = pnl_csr
pnl_csr.evaluate_pnls(pnl_cats=pnl_csr.pnl_names)
xcat | Communication services always long versus all-sector basket | Communication services learning-based signal |
---|---|---|
Return % | -12.009305 | 10.040176 |
St. Dev. % | 35.601175 | 31.47881 |
Sharpe Ratio | -0.337329 | 0.31895 |
Sortino Ratio | -0.477247 | 0.446419 |
Max 21-Day Draw % | -41.34344 | -95.403352 |
Max 6-Month Draw % | -110.518234 | -159.358749 |
Peak to Trough Draw % | -322.986005 | -213.150624 |
Top 5% Monthly PnL Share | -1.199733 | 1.71775 |
USD_EQXR_NSA correl | -0.036372 | 0.01053 |
Traded Months | 259 | 259 |
pnl_name = csr_dict["pnl_name"]
secname = csr_dict["sector_name"]
pnl_csr.signal_heatmap(
pnl_name=pnl_name,
figsize=(12, 3),
title=f"{secname} sector: signal heatmap",
)
Utilities #
Factor selection and signal generation #
sector = "UTL"
utl_dict = {
"sector_name": sector_labels[sector],
"signal_name": f"{sector}SOL",
"pnl_name": f"{sector_labels[sector]} learning-based signal",
"xcatx": macroz,
"cidx": cids_eq,
"ret": f"EQC{sector}{default_target_type}",
"freq": "M",
"black": sector_blacklist[sector],
"srr": None,
"pnls": None,
}
# Converted selected features and targets to scikit-learn format
xcatx = utl_dict["xcatx"] + [utl_dict["ret"]]
cidx = utl_dict["cidx"]
dfw_utl = msm.categories_df(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=utl_dict["freq"],
blacklist=utl_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
).sort_index().dropna()
X_utl = dfw_utl.iloc[:, :-1]
y_utl = dfw_utl.iloc[:, -1]
secname = utl_dict["sector_name"]
signal_name = utl_dict["signal_name"]
so_utl = msl.SignalOptimizer(
inner_splitter=default_splitter,
X=X_utl,
y=y_utl,
threshold_ndates = default_threshold_ndates,
initial_nsplits = default_initial_nsplits,
)
so_utl.calculate_predictions(
name=signal_name,
models=default_models,
metric=default_metric,
hparam_grid=default_hparam_grid,
test_size=default_test_size,
min_cids=default_min_cids,
min_periods=default_min_periods,
n_jobs=-1,
)
so_utl.models_heatmap(
signal_name,
cap=10,
title=f"{secname} sector: model selection heatmap",
)
# Store signals
dfa = so_utl.get_optimized_signals()
dfx = msm.update_df(dfx, dfa)
xcatx = utl_dict["signal_name"]
secname = utl_dict["sector_name"]
so_utl.feature_selection_heatmap(
xcatx,
remove_blanks=True,
title=f"{secname} sector: feature selection heatmap",
ftrs_renamed=cat_label_dict,
figsize=(12, 10),
)
xcatx = utl_dict["signal_name"]
secname = utl_dict["sector_name"]
so_utl.coefs_stackedbarplot(
name=xcatx,
ftrs_renamed=cat_label_dict,
title=f"{secname} sector: annual averages of most important feature coefficients",
)
Signal quality check #
xcatx = [utl_dict["signal_name"], utl_dict["ret"]]
cidx = utl_dict["cidx"]
secname = utl_dict["sector_name"]
cr_utl = msp.CategoryRelations(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=utl_dict["freq"],
blacklist=utl_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
slip=1,
)
cr_utl.reg_scatter(
title=f"{secname} sector: learning-based signal and subsequent returns",
labels=False,
prob_est="map",
xlab=f"{secname} signal, end-of-month, based on concurrent best model",
ylab=f"Relative return of {secname.lower()} sector (vol-targeted), next month, %",
coef_box="upper left",
size=(12, 8),
)
xcatx = [utl_dict["signal_name"]]
cidx = utl_dict["cidx"]
secname = utl_dict["sector_name"]
signal_name = utl_dict["signal_name"]
pnl_name = utl_dict["pnl_name"]
pnl_utl = msn.NaivePnL(
df=dfx,
ret=utl_dict["ret"],
sigs=xcatx,
cids=cidx,
start=default_start_date,
blacklist = utl_dict["black"],
bms=["USD_EQXR_NSA"],
)
for xcat in xcatx:
pnl_utl.make_pnl(
sig=xcat,
sig_op="zn_score_pan",
rebal_freq="monthly",
neutral="zero",
rebal_slip=1,
vol_scale = None,
thresh=3,
pnl_name=pnl_name,
)
pnl_utl.make_long_pnl(
vol_scale=None, label=f"{secname} always long versus all-sector basket"
)
pnl_utl.plot_pnls(
pnl_cats=pnl_utl.pnl_names,
title=f"{secname} sector: naive PnLs of positions versus all-sector basket",
title_fontsize=14
)
utl_dict["pnls"] = pnl_utl
pnl_utl.evaluate_pnls(pnl_cats=pnl_utl.pnl_names)
xcat | Utilities always long versus all-sector basket | Utilities learning-based signal |
---|---|---|
Return % | 11.253423 | 18.179652 |
St. Dev. % | 39.290727 | 41.618768 |
Sharpe Ratio | 0.286414 | 0.436814 |
Sortino Ratio | 0.419205 | 0.639079 |
Max 21-Day Draw % | -45.235513 | -102.238062 |
Max 6-Month Draw % | -93.980448 | -112.403374 |
Peak to Trough Draw % | -272.563373 | -145.008647 |
Top 5% Monthly PnL Share | 1.634651 | 1.13979 |
USD_EQXR_NSA correl | -0.194839 | -0.037821 |
Traded Months | 259 | 259 |
pnl_name = utl_dict["pnl_name"]
secname = utl_dict["sector_name"]
pnl_utl.signal_heatmap(
pnl_name=pnl_name,
figsize=(12, 3),
title=f"{secname} sector: signal heatmap",
)
Real estate #
Factor selection and signal generation #
sector = "REL"
rel_dict = {
"sector_name": sector_labels[sector],
"signal_name": f"{sector}SOL",
"pnl_name": f"{sector_labels[sector]} learning-based signal",
"xcatx": macroz,
"cidx": cids_eq,
"ret": f"EQC{sector}{default_target_type}",
"freq": "M",
"black": sector_blacklist[sector],
"srr": None,
"pnls": None,
}
# Converted selected features and targets to scikit-learn format
xcatx = rel_dict["xcatx"] + [rel_dict["ret"]]
cidx = rel_dict["cidx"]
dfw_rel = msm.categories_df(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=rel_dict["freq"],
blacklist=rel_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
).sort_index().dropna()
X_rel = dfw_rel.iloc[:, :-1]
y_rel = dfw_rel.iloc[:, -1]
secname = rel_dict["sector_name"]
signal_name = rel_dict["signal_name"]
so_rel = msl.SignalOptimizer(
inner_splitter=default_splitter,
X=X_rel,
y=y_rel,
threshold_ndates = default_threshold_ndates,
initial_nsplits = default_initial_nsplits,
)
so_rel.calculate_predictions(
name=signal_name,
models=default_models,
metric=default_metric,
hparam_grid=default_hparam_grid,
test_size=default_test_size,
min_cids=default_min_cids,
min_periods=default_min_periods,
n_jobs=-1,
)
so_rel.models_heatmap(
signal_name,
cap=10,
title=f"{secname} sector: model selection heatmap",
)
# Store signals
dfa = so_rel.get_optimized_signals()
dfx = msm.update_df(dfx, dfa)
xcatx = rel_dict["signal_name"]
secname = rel_dict["sector_name"]
so_rel.feature_selection_heatmap(
xcatx,
remove_blanks=True,
title=f"{secname} sector: feature selection heatmap",
ftrs_renamed=cat_label_dict,
figsize=(12, 10),
)
xcatx = rel_dict["signal_name"]
secname = rel_dict["sector_name"]
so_rel.coefs_stackedbarplot(
name=xcatx,
ftrs_renamed=cat_label_dict,
title=f"{secname} sector: annual averages of most important feature coefficients",
)
Signal quality check #
xcatx = [rel_dict["signal_name"], rel_dict["ret"]]
cidx = rel_dict["cidx"]
secname = rel_dict["sector_name"]
cr_rel = msp.CategoryRelations(
df=dfx,
xcats=xcatx,
cids=cidx,
freq=rel_dict["freq"],
blacklist=rel_dict["black"],
lag=1,
xcat_aggs=["last", "sum"],
slip=1,
)
cr_rel.reg_scatter(
title=f"{secname} sector: learning-based signal and subsequent returns",
labels=False,
prob_est="map",
xlab=f"{secname} signal, end-of-month, based on concurrent best model",
ylab=f"Relative return of {secname.lower()} sector (vol-targeted), next month, %",
coef_box="upper left",
size=(12, 8),
)
xcatx = [rel_dict["signal_name"]]
cidx = rel_dict["cidx"]
secname = rel_dict["sector_name"]
signal_name = rel_dict["signal_name"]
pnl_name = rel_dict["pnl_name"]
pnl_rel = msn.NaivePnL(
df=dfx,
ret=rel_dict["ret"],
sigs=xcatx,
cids=cidx,
start=default_start_date,
blacklist = rel_dict["black"],
bms=["USD_EQXR_NSA"],
)
for xcat in xcatx:
pnl_rel.make_pnl(
sig=xcat,
sig_op="zn_score_pan",
rebal_freq="monthly",
neutral="zero",
rebal_slip=1,
vol_scale = None,
thresh=3,
pnl_name=pnl_name,
)
pnl_rel.make_long_pnl(vol_scale=None, label=f"{secname} always long versus all-sector basket")
pnl_rel.plot_pnls(
pnl_cats=pnl_rel.pnl_names,
title=f"{secname} sector: naive PnLs of positions versus all-sector basket",
title_fontsize=14
)
rel_dict["pnls"] = pnl_rel
pnl_rel.evaluate_pnls(pnl_cats=pnl_rel.pnl_names)
xcat | Real estate always long versus all-sector basket | Real estate learning-based signal |
---|---|---|
Return % | 26.176755 | 25.443448 |
St. Dev. % | 42.426817 | 43.198466 |
Sharpe Ratio | 0.616986 | 0.58899 |
Sortino Ratio | 0.880151 | 0.827925 |
Max 21-Day Draw % | -107.121602 | -149.320882 |
Max 6-Month Draw % | -123.928869 | -129.817585 |
Peak to Trough Draw % | -228.650393 | -210.989102 |
Top 5% Monthly PnL Share | 0.855974 | 1.028567 |
USD_EQXR_NSA correl | -0.052294 | -0.038074 |
Traded Months | 259 | 259 |
pnl_name = rel_dict["pnl_name"]
secname = rel_dict["sector_name"]
pnl_rel.signal_heatmap(
pnl_name=pnl_name,
figsize=(12, 3),
title=f"{secname} sector: signal heatmap",
)
Summary #
Sector-specific signals and returns #
sec_catregs = {
"enr": cr_enr,
"mat": cr_mat,
"ind": cr_ind,
"cod": cr_cod,
"cos": cr_cos,
"hlc": cr_hlc,
"fin": cr_fin,
"ite": cr_ite,
"csr": cr_csr,
"utl": cr_utl,
"rel": cr_rel,
}
msv.multiple_reg_scatter(
cat_rels=list(sec_catregs.values()),
ncol=3,
nrow=4,
figsize=(15, 15),
title="Statistical macro signals and subsequent sectoral equity returns, 11 currency areas, since 2003",
title_xadj=0.5,
title_yadj=0.99,
title_fontsize=20,
xlab="Sector-specific statistical signal",
ylab="Sector return versus equal weighted local index (all vol-targeted), next month %",
coef_box="lower right",
prob_est="map",
single_chart=True,
subplot_titles=[sector_labels[sector.upper()] for sector in sec_catregs.keys()],
)
Combined cross-sector trading PnL #
sec_pnls = {
"enr": pnl_enr,
"mat": pnl_mat,
"ind": pnl_ind,
"cod": pnl_cod,
"cos": pnl_cos,
"hlc": pnl_hlc,
"fin": pnl_fin,
"ite": pnl_ite,
"csr": pnl_csr,
"utl": pnl_utl,
"rel": pnl_rel,
}
ma_pnl = msn.MultiPnL()
for sec, pnl in sec_pnls.items():
ma_pnl.add_pnl(pnl, pnl_xcats=[f"{sector_labels[sec.upper()]} learning-based signal"])
ma_pnl.plot_pnls(
pnl_xcats=[
f"{sector_labels[sec.upper()]} learning-based signal" for sec in sec_pnls.keys()
],
title="Naive PnLs for relative sector strategies",
xcat_labels=[sector_labels[sec.upper()] for sec in sec_pnls.keys()],
)
cpname = "Simple average PnL of relative sector strategies based on statistical learning and macro signals"
macro_sector_pnl = ma_pnl.combine_pnls(
pnl_xcats=[f"{sector_labels[sec.upper()]} learning-based signal" for sec in sec_pnls.keys()],
composite_pnl_xcat=cpname,
weights=None,
)
ma_pnl.plot_pnls(
[cpname],
title="Cumulative naive PnL value of cross-sectoral equity allocation",
)
tbr = ma_pnl.evaluate_pnls()
tbr = tbr.rename(columns={
**{
f"{sector_labels[sec.upper()]} learning-based signal/EQC{sec.upper()}R_VT10vALL": f"{sector_labels[sec.upper()]}"
for sec in sec_pnls.keys()
},
**{
"Simple average PnL of relative sector strategies based on statistical learning and macro signals": "Simple average"
}
})
selected_rows = ["Return %", "St. Dev. %", "Sharpe Ratio", "Sortino Ratio", "USD_EQXR_NSA correl"]
selected_columns = ["Simple average"] + [sector_labels[sec.upper()] for sec in sec_pnls.keys()]
selected_pnl_stats = tbr.loc[selected_rows, selected_columns].T
display(selected_pnl_stats.style.format("{:.2f}"))
Return % | St. Dev. % | Sharpe Ratio | Sortino Ratio | USD_EQXR_NSA correl | |
---|---|---|---|---|---|
Simple average | 19.06 | 16.01 | 1.19 | 1.76 | nan |
Energy | 45.24 | 69.43 | 0.65 | 0.97 | -0.10 |
Materials | 28.04 | 46.62 | 0.60 | 0.85 | 0.00 |
Industrials | 8.13 | 29.80 | 0.27 | 0.39 | 0.02 |
Cons. discretionary | 15.46 | 32.07 | 0.48 | 0.70 | -0.03 |
Cons. staples | 19.20 | 34.45 | 0.56 | 0.82 | -0.03 |
Healthcare | 6.57 | 40.98 | 0.16 | 0.23 | 0.05 |
Financials | 1.35 | 44.05 | 0.03 | 0.04 | -0.12 |
Information tech | 8.04 | 37.79 | 0.21 | 0.30 | -0.00 |
Communication services | 10.04 | 31.48 | 0.32 | 0.45 | 0.01 |
Utilities | 18.18 | 41.62 | 0.44 | 0.64 | -0.04 |
Real estate | 25.44 | 43.20 | 0.59 | 0.83 | -0.04 |
Appendix #
Appendix 1 - Macro quantamental indicators description #
# Convert the dictionary to an HTML table with custom inline CSS
html_table = cat_labels.to_html(index=True, table_id="custom_table")
# Inject CSS to align text to the left and reduce font size
css = """
<style>
#custom_table th, #custom_table td {
text-align: left;
font-size: 12px; /* Adjust the font size as needed */
}
</style>
"""
# Display the styled HTML table
HTML(css + html_table)
Label | Description | Geography | ||
---|---|---|---|---|
Group | Category | |||
Business surveys | CBCSCORE_SA_D3M3ML3_WG_ZN | Construction confidence, q/q | Construction business confidence score, seas. adjusted, change q/q | weighted |
CBCSCORE_SA_D3M3ML3_ZN | Construction confidence, q/q | Construction business confidence score, seas. adjusted, change q/q | local | |
CBCSCORE_SA_WG_ZN | Construction confidence | Construction business confidence score, seas. adjusted | weighted | |
CBCSCORE_SA_ZN | Construction confidence | Construction business confidence score, seas. adjusted | local | |
MBCSCORE_SA_D3M3ML3_WG_ZN | Manufacturing confidence, q/q | Manufacturing business confidence score, seas. adj., change q/q | weighted | |
MBCSCORE_SA_D3M3ML3_ZN | Manufacturing confidence, q/q | Manufacturing business confidence score, seas. adj., change q/q | local | |
MBCSCORE_SA_WG_ZN | Manufacturing confidence | Manufacturing business confidence score, seasonally adjusted | weighted | |
MBCSCORE_SA_ZN | Manufacturing confidence | Manufacturing business confidence score, seasonally adjusted | local | |
SBCSCORE_SA_D3M3ML3_WG_ZN | Service confidence, q/q | Services business confidence score, seas. adjusted, change q/q | weighted | |
SBCSCORE_SA_D3M3ML3_ZN | Service confidence, q/q | Services business confidence score, seas. adjusted, change q/q | local | |
SBCSCORE_SA_WG_ZN | Service confidence | Services business confidence score, seasonally adjusted | weighted | |
SBCSCORE_SA_ZN | Service confidence | Services business confidence score, seasonally adjusted | local | |
Commodity inventories | BASEXINVCSCORE_SA_ZN | Excess crude inventory score | Crude oil excess inventory z-score, seasonally adjusted | global |
BMLXINVCSCORE_SA_ZN | Excess metal inventory score | Base metal excess inventory z-score, seasonally adjusted | global | |
REFIXINVCSCORE_SA_ZN | Excess refined oil inventory score | Refined oil product excess inventory z-score, seas. adjusted | global | |
Debt | CORPINTNETGDP_SA_D1Q1QL4_WG_ZN | Corporate debt servicing, %oya | Corporate net debt servicing-to-GDP ratio, seasonally-adjusted, %oya | weighted |
CORPINTNETGDP_SA_D1Q1QL4_ZN | Corporate debt servicing, %oya | Corporate net debt servicing-to-GDP ratio, seasonally-adjusted, %oya | local | |
HHINTNETGDP_SA_D1M1ML12_WG_ZN | Households debt servicing, %oya | Households net debt servicing-to-GDP ratio, seasonally-adjusted, %oya | weighted | |
HHINTNETGDP_SA_D1M1ML12_ZN | Households debt servicing, %oya | Households net debt servicing-to-GDP ratio, seasonally-adjusted, %oya | local | |
XGGDGDPRATIOX10_NSA_ZN | Excess projected gov. debt | Government debt-to-GDP ratio proj. in 10 years, in excess of 100% | local | |
Exports | XEXPORTS_SA_P1M1ML12_3MMA_ZN | Excess export growth | Exports growth, %oya, 3mma, in excess of 5-year median GDP growth | local |
Inflation - broad | XCPIC_SA_P1M1ML12_ZN | Excess core CPI, %oya | Core CPI, %oya, in excess of effective inflation target | local |
XCPIH_SA_P1M1ML12_ZN | Excess headline CPI, %oya | Headline CPI, %oya, in excess of effective inflation target | local | |
XPPIH_NSA_P1M1ML12_ZN | Excess PPI, %oya | Producer price inflation, %oya, in excess of eff. inflation target | local | |
Inflation - specific | XCPIE_SA_P1M1ML12_WG_ZN | Excess energy CPI, %oya | Energy CPI, %oya, in excess of effective inflation target | weighted |
XCPIE_SA_P1M1ML12_ZN | Excess energy CPI, %oya | Energy CPI, %oya, in excess of effective inflation target | local | |
XCPIF_SA_P1M1ML12_WG_ZN | Excess food CPI, %oya | Food CPI, %oya, in excess of effective inflation target | weighted | |
XCPIF_SA_P1M1ML12_ZN | Excess food CPI, %oya | Food CPI, %oya, in excess of effective inflation target | local | |
Labour market | UNEMPLRATE_NSA_3MMA_D1M1ML12_WG_ZN | Unemployment rate, diff oya | Unemployment rate, change oya | weighted |
UNEMPLRATE_NSA_3MMA_D1M1ML12_ZN | Unemployment rate, diff oya | Unemployment rate, change oya | local | |
UNEMPLRATE_SA_3MMAv5YMA_WG_ZN | Unemployment rate, diff vs 5yma | Unemployment rate, difference vs 5-year moving average | weighted | |
UNEMPLRATE_SA_3MMAv5YMA_ZN | Unemployment rate, diff vs 5yma | Unemployment rate, difference vs 5-year moving average | local | |
XEMPL_NSA_P1M1ML12_3MMA_WG_ZN | Excess employment growth | Employment growth, %oya, 3mma, in excess of population growth | weighted | |
XEMPL_NSA_P1M1ML12_3MMA_ZN | Excess employment growth | Employment growth, %oya, 3mma, in excess of population growth | local | |
XRWAGES_NSA_P1M1ML12_ZN | Excess real wage growth | Real wage growth, %oya, in excess of medium-term productivity growth | local | |
Market metrics | BMLCOCRY_SAVT10_21DMA_ZN | Base metals carry | Nominal carry for base metals basket, seasonally and vol-adjusted, 21 days moving average | global |
COXR_VT10vWTI_21DMA_ZN | Refined vs crude oil returns | Refined oil products vs crude oil vol-targeted return differential, 21 days moving average | global | |
RIR_NSA_ZN | Real 1-month rate | Real 1-month interest rate | local | |
RSLOPEMIDDLE_NSA_ZN | Real 5y-2y yield | Real IRS yield differentials, 5-years versus 2-years | local | |
RYLDIRS02Y_NSA_ZN | Real 2-year yield | Real 2-year IRS yield | local | |
RYLDIRS05Y_NSA_ZN | Real 5-year yield | Real 5-year IRS yield | local | |
Output growth | XCSTR_SA_P1M1ML12_3MMA_WG_ZN | Excess construction growth | Construction output, %oya, 3mma, in excess of 5-y median GDP growth | weighted |
XCSTR_SA_P1M1ML12_3MMA_ZN | Excess construction growth | Construction output, %oya, 3mma, in excess of 5-y median GDP growth | local | |
XIP_SA_P1M1ML12_3MMA_WG_ZN | Excess industry growth | Industrial output, %oya, 3mma, in excess of 5-y median GDP growth | weighted | |
XIP_SA_P1M1ML12_3MMA_ZN | Excess industry growth | Industrial output, %oya, 3mma, in excess of 5-y median GDP growth | local | |
XRGDPTECH_SA_P1M1ML12_3MMA_WG_ZN | Excess GDP growth | Real GDP, %oya, 3mma, using HF data, in excess of 5-y med. GDP growth | weighted | |
XRGDPTECH_SA_P1M1ML12_3MMA_ZN | Excess GDP growth | Real GDP, %oya, 3mma, using HF data, in excess of 5-y med. GDP growth | local | |
Private consumption | CCSCORE_SA_D3M3ML3_WG_ZN | Consumer confidence, q/q | Consumer confidence score, seasonally adjusted, change q/q | weighted |
CCSCORE_SA_D3M3ML3_ZN | Consumer confidence, q/q | Consumer confidence score, seasonally adjusted, change q/q | local | |
CCSCORE_SA_WG_ZN | Consumer confidence | Consumer confidence score, seasonally adjusted | weighted | |
CCSCORE_SA_ZN | Consumer confidence | Consumer confidence score, seasonally adjusted | local | |
XNRSALES_SA_P1M1ML12_3MMA_WG_ZN | Excess retail sales growth | Nominal retail sales, %oya, 3mma, in excess of 5-y median GDP growth | weighted | |
XNRSALES_SA_P1M1ML12_3MMA_ZN | Excess retail sales growth | Nominal retail sales, %oya, 3mma, in excess of 5-y median GDP growth | local | |
XRPCONS_SA_P1M1ML12_3MMA_WG_ZN | Excess consumption growth | Real private consumption, %oya, 3mma, in excess of 5-y median GDP growth | weighted | |
XRPCONS_SA_P1M1ML12_3MMA_ZN | Excess real consum growth | Real private consumption, %oya, 3mma, in excess of 5-y median GDP growth | local | |
XRRSALES_SA_P1M1ML12_3MMA_WG_ZN | Excess real retail growth | Real retail sales, %oya, 3mma, in excess of 5-y median GDP growth | weighted | |
XRRSALES_SA_P1M1ML12_3MMA_ZN | Excess real retail growth | Real retail sales, %oya, 3mma, in excess of 5-y median GDP growth | local | |
Private credit | INTLIQGDP_NSA_D1M1ML1_ZN | Intervention liquidity, diff m/m | Intervention liquidity to GDP ratio, change over the last month | local |
INTLIQGDP_NSA_D1M1ML6_ZN | Intervention liquidity, diff 6m | Intervention liquidity to GDP ratio, change overlast 6 months | local | |
XPCREDITBN_SJA_P1M1ML12_WG_ZN | Excess credit growth | Private credit, %oya, 3mma, in excess of 5-y median GDP growth | weighted | |
XPCREDITBN_SJA_P1M1ML12_ZN | Excess credit growth | Private credit, %oya, 3mma, in excess of 5-y median GDP growth | local | |
Real appreciation | CMPI_NSA_P1M12ML1_ZN | Import prices, %oya | Commodity-based import price index, %oya | local |
CTOT_NSA_P1M12ML1_ZN | Terms-of-trade, %oya | Commodity-based terms-of-trade, %oya | local | |
CXPI_NSA_P1M12ML1_ZN | Export prices, %oya | Commodity-based export price index, %oya | local | |
REEROADJ_NSA_P1M12ML1_ZN | Open-adj REER, %oya | Openness-adjusted real effective exchange rate, %oya | local |