{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d273a5e0",
   "metadata": {},
   "source": [
    "# Factor Construction and Composite Signal\n",
    "\n",
    "## Purpose\n",
    "\n",
    "Notebook 02 suggested that momentum is the only price-based signal worth carrying forward. This notebook turns that raw momentum rank into the traded signal used by the backtest.\n",
    "\n",
    "The goals are:\n",
    "1. Winsorize and z-score each factor cross-section so outliers do not dominate.\n",
    "2. Neutralize the signal against sector membership by projecting out sector effects.\n",
    "3. Compare momentum-only against a simple four-factor composite.\n",
    "4. Save the sector-neutralized momentum signal for notebook 04.\n",
    "\n",
    "### Terms used in this notebook\n",
    "\n",
    "| Term | Meaning |\n",
    "|------|---------|\n",
    "| **Winsorization** | Clip extreme values at a threshold instead of dropping them |\n",
    "| **Z-scoring** | Center to mean 0 and scale to standard deviation 1 |\n",
    "| **Neutralization** | Regress a signal on unwanted exposures and keep the residual |\n",
    "| **Composite signal** | A linear combination $c_t = \\sum_k w_k f_{k,\\perp}$ |\n",
    "| **Sector matrix** | $D \\in \\{0,1\\}^{N \\times K}$, a one-hot sector-membership matrix |\n",
    "| **Projection** | The linear algebra operation behind neutralization |\n",
    "| **Information coefficient (IC)** ↻ | Spearman rank correlation used to compare candidate signals |\n",
    "| **Return panel** $R$ ↻ | The monthly return matrix from notebook 01 |\n",
    "\n",
    "## Outputs\n",
    "\n",
    "- `momentum_signal.csv`: sector-neutralized momentum, the signal used in the backtest\n",
    "- `composite_4factor.csv`: a simple four-factor composite kept for comparison\n",
    "- `factor_*_neutralized.csv`: neutralized versions of the individual factors\n",
    "\n",
    "## Notebook Structure\n",
    "1. [Setup and Imports](#setup-and-imports)\n",
    "2. [Winsorization and Z-Scoring](#winsorization-and-z-scoring)\n",
    "3. [Sector Neutralization](#sector-neutralization)\n",
    "4. [Composite Assembly and Comparison](#composite-assembly-and-comparison)\n",
    "5. [IC Comparison: Momentum vs. Composite](#ic-comparison-momentum-vs-composite)\n",
    "6. [Conclusion](#conclusion)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "75cbb165",
   "metadata": {},
   "source": [
    "\n",
    "## Setup and Imports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c72adc67",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-07-31T11:08:52.187310Z",
     "iopub.status.busy": "2026-07-31T11:08:52.186272Z",
     "iopub.status.idle": "2026-07-31T11:08:53.251453Z",
     "shell.execute_reply": "2026-07-31T11:08:53.250854Z"
    }
   },
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "==================================\n",
    "Setup and imports\n",
    "==================================\n",
    "\"\"\"\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import os\n",
    "from scipy.stats import spearmanr\n",
    "\n",
    "pd.set_option('display.max_columns', None)\n",
    "pd.set_option('display.max_rows', 100)\n",
    "\n",
    "palette = ['steelblue', 'coral', 'seagreen']\n",
    "\n",
    "os.makedirs('../data/processed', exist_ok=True)\n",
    "os.makedirs('../images/03_factor_construction', exist_ok=True)\n",
    "\n",
    "RANDOM_STATE = 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0090dab7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-07-31T11:08:53.253326Z",
     "iopub.status.busy": "2026-07-31T11:08:53.253053Z",
     "iopub.status.idle": "2026-07-31T11:08:53.408971Z",
     "shell.execute_reply": "2026-07-31T11:08:53.408532Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loaded 4 factors\n",
      "Returns: (251, 501)\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "==================================\n",
    "Load factor exposures, returns, sectors\n",
    "==================================\n",
    "\"\"\"\n",
    "factor_names = ['momentum', 'value', 'quality', 'lowvol']\n",
    "factor_dict = {n: pd.read_csv(f'../data/processed/factor_{n}.csv', index_col=0, parse_dates=True) for n in factor_names}\n",
    "df_returns = pd.read_csv('../data/processed/returns_monthly.csv', index_col=0, parse_dates=True)\n",
    "df_sector = pd.read_csv('../data/processed/sector_mapping.csv')\n",
    "\n",
    "# Build sector lookup\n",
    "sector_map = dict(zip(df_sector['ticker'], df_sector['sector']))\n",
    "\n",
    "print(f\"Loaded {len(factor_names)} factors\")\n",
    "print(f\"Returns: {df_returns.shape}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46a37025",
   "metadata": {},
   "source": [
    "## Winsorization and Z-Scoring\n",
    "\n",
    "Raw factor values can contain large outliers. Winsorization clips those extremes rather than dropping the stock entirely. Here we cap each monthly cross-section at $\\pm 3$ standard deviations around its mean.\n",
    "\n",
    "After clipping, we z-score within each date:\n",
    "\n",
    "$$\\tilde f_{t,i}=\\frac{f_{t,i}-\\bar f_t}{\\mathrm{std}(f_t)}.$$\n",
    "\n",
    "This gives each factor row mean 0 and standard deviation 1, so later comparisons are not driven by arbitrary units."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "83a54dbc",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-07-31T11:08:53.410714Z",
     "iopub.status.busy": "2026-07-31T11:08:53.410441Z",
     "iopub.status.idle": "2026-07-31T11:08:54.165454Z",
     "shell.execute_reply": "2026-07-31T11:08:54.164580Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "momentum: z-scores, shape=(251, 501)\n",
      "value: z-scores, shape=(251, 501)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "quality: z-scores, shape=(251, 501)\n",
      "lowvol: z-scores, shape=(251, 501)\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "==================================\n",
    "Winsorize and z-score\n",
    "==================================\n",
    "\"\"\"\n",
    "def winsorize(series, sigma=3):\n",
    "    \"\"\"Clip at ±sigma standard deviations around the mean.\"\"\"\n",
    "    mu = series.mean()\n",
    "    s = series.std()\n",
    "    if s == 0 or pd.isna(s):\n",
    "        return series\n",
    "    return series.clip(lower=mu - sigma*s, upper=mu + sigma * s)\n",
    "\n",
    "def zscore(series):\n",
    "    \"\"\"Cross-sectional z-score.\"\"\"\n",
    "    mu = series.mean()\n",
    "    s = series.std()\n",
    "    if s == 0 or pd.isna(s):\n",
    "        return series * 0\n",
    "    return (series - mu)/s\n",
    "\n",
    "factor_z = {}\n",
    "for name, df_f in factor_dict.items():\n",
    "    df_w = df_f.apply(winsorize, axis=1)\n",
    "    df_z = df_w.apply(zscore, axis=1)\n",
    "    factor_z[name] = df_z\n",
    "    print(f\"{name}: z-scores, shape={df_z.shape}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "112a7744",
   "metadata": {},
   "source": [
    "## Sector Neutralization\n",
    "\n",
    "A raw momentum score may contain sector bets. For example, if Technology had a strong year, a momentum portfolio might become mostly a Technology portfolio. That may be a valid trade, but it is not a clean test of stock selection within sectors.\n",
    "\n",
    "To neutralize sectors, create a sector dummy matrix\n",
    "\n",
    "$$D \\in \\{0,1\\}^{N \\times K}.$$\n",
    "\n",
    "For one factor vector $f \\in \\mathbb{R}^N$, the projection onto the sector span is\n",
    "\n",
    "$$P_D f = D(D^\\top D)^{-1}D^\\top f.$$\n",
    "\n",
    "The sector-neutralized signal is the residual:\n",
    "\n",
    "$$f_\\perp = (I-P_D)f.$$\n",
    "\n",
    "This is the same as running a cross-sectional OLS regression of the factor on sector dummies and keeping the residuals. The residual has zero linear exposure to the sector dummy columns used in the regression.\n",
    "\n",
    "The code also mentions size, but with this dataset we only have a weak price-based size proxy. I would not interpret it as a true market-cap neutralization without real shares-outstanding data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b7ce2018",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-07-31T11:08:54.167456Z",
     "iopub.status.busy": "2026-07-31T11:08:54.167259Z",
     "iopub.status.idle": "2026-07-31T11:08:56.142616Z",
     "shell.execute_reply": "2026-07-31T11:08:56.141776Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Neutralizing momentum...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Neutralizing value...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Neutralizing quality...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Neutralizing lowvol...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sector neutralization complete.\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "==================================\n",
    "Sector neutralization via cross-sectional regression on dummies\n",
    "==================================\n",
    "\"\"\"\n",
    "def neutralize_against_sector(factor_row, sector_map):\n",
    "    \"\"\"Regress factor on sector dummies, return residuals.\"\"\"\n",
    "    tickers = factor_row.index\n",
    "    sectors = pd.Series([sector_map.get(t, 'Unknown') for t in tickers], index=tickers)\n",
    "\n",
    "    # One-hot encode\n",
    "    indicators = pd.get_dummies(sectors, drop_first=True).astype(float)\n",
    "    indicators['intercept'] = 1.0\n",
    "\n",
    "    # Mask valid\n",
    "    mask = factor_row.notna()\n",
    "    if mask.sum() < 30:\n",
    "        return factor_row\n",
    "\n",
    "    y = factor_row[mask].values\n",
    "    X = indicators.loc[mask].values\n",
    "\n",
    "    # OLS via least squares\n",
    "    beta, _, _, _ = np.linalg.lstsq(X,y)\n",
    "    resid = y - X @ beta\n",
    "\n",
    "    out = pd.Series(np.nan, index=factor_row.index)\n",
    "    out[mask] = resid\n",
    "    return out\n",
    "\n",
    "factor_neut = {}\n",
    "for name, df_z in factor_z.items():\n",
    "    print(f\"Neutralizing {name}...\")\n",
    "    df_neut = df_z.apply(lambda row: neutralize_against_sector(row, sector_map), axis=1)\n",
    "    # Re-z-score the residuals so they're back on a common scale\n",
    "    df_neut = df_neut.apply(zscore, axis=1)\n",
    "    factor_neut[name] = df_neut\n",
    "\n",
    "print(\"Sector neutralization complete.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9740141a",
   "metadata": {},
   "source": [
    "As in notebook 02, we use a sample-size guardrail. If fewer than 30 stocks have valid data in a month, we skip neutralization for that row rather than fit a noisy cross-sectional regression. This mostly affects early or sparse parts of the panel."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b4204816",
   "metadata": {},
   "source": [
    "## Composite Assembly and Comparison\n",
    "\n",
    "We compare two candidate signals:\n",
    "\n",
    "1. **Momentum-only:** the sector-neutralized momentum residual $f_{m,\\perp}$, re-z-scored. This is the signal passed to the backtest.\n",
    "2. **Four-factor composite:** an equal-weight average of the neutralized factor vectors,\n",
    "\n",
    "$$c_t = \\frac{1}{4}\\sum_{k=1}^4 f_{k,\\perp}(t).$$\n",
    "\n",
    "This is a useful sanity check. If the composite improves IC, the extra factors are helping. If it gets worse, the added factors are diluting momentum rather than diversifying it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "792e547e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-07-31T11:08:56.144507Z",
     "iopub.status.busy": "2026-07-31T11:08:56.144304Z",
     "iopub.status.idle": "2026-07-31T11:08:56.350858Z",
     "shell.execute_reply": "2026-07-31T11:08:56.350129Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Momentum-only signal: (251, 501)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4-factor composite: (251, 501)\n",
      "\n",
      "Our main signal will be momentum-only. The 4-factor composite is kept for comparison.\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "==================================\n",
    "Build momentum-only signal and 4-factor composite\n",
    "==================================\n",
    "\"\"\"\n",
    "# Momentum only\n",
    "df_momentum_signal = factor_neut['momentum'].apply(zscore, axis=1)\n",
    "print(f\"Momentum-only signal: {df_momentum_signal.shape}\")\n",
    "\n",
    "# 4-factor equal-weight composite\n",
    "common_dates = factor_neut['momentum'].index\n",
    "common_tickers = factor_neut['momentum'].columns\n",
    "\n",
    "for name in factor_names:\n",
    "    common_dates = common_dates.intersection(factor_neut[name].index)\n",
    "    common_tickers = common_tickers.intersection(factor_neut[name].columns)\n",
    "\n",
    "df_composite_4f = pd.DataFrame(0.0, index=common_dates, columns=common_tickers)\n",
    "count_df = pd.DataFrame(0, index=common_dates, columns=common_tickers)\n",
    "\n",
    "for name in factor_names:\n",
    "    df_f = factor_neut[name].loc[common_dates, common_tickers]\n",
    "    df_composite_4f = df_composite_4f.add(df_f.fillna(0))\n",
    "    count_df = count_df.add(df_f.notna().astype(int))\n",
    "\n",
    "df_composite_4f = df_composite_4f / count_df.replace(0, np.nan)\n",
    "df_composite_4f[count_df < 3] = np.nan\n",
    "df_composite_4f = df_composite_4f.apply(zscore, axis=1)\n",
    "\n",
    "print(f\"4-factor composite: {df_composite_4f.shape}\")\n",
    "print(f\"\\nOur main signal will be momentum-only. The 4-factor composite is kept for comparison.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f8809b2e",
   "metadata": {},
   "source": [
    "## Composite vs. Single Factors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "25e7a046",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-07-31T11:08:56.353026Z",
     "iopub.status.busy": "2026-07-31T11:08:56.352756Z",
     "iopub.status.idle": "2026-07-31T11:08:58.700588Z",
     "shell.execute_reply": "2026-07-31T11:08:58.699933Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "IC Comparison: Neutralized Factors, Momentum-Only, and 4-Factor Composite\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>mean</th>\n",
       "      <th>std</th>\n",
       "      <th>ic_ir</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>momentum</th>\n",
       "      <td>0.0068</td>\n",
       "      <td>0.1576</td>\n",
       "      <td>0.1505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>value</th>\n",
       "      <td>-0.0198</td>\n",
       "      <td>0.1344</td>\n",
       "      <td>-0.5111</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>quality</th>\n",
       "      <td>0.0013</td>\n",
       "      <td>0.1597</td>\n",
       "      <td>0.0282</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>lowvol</th>\n",
       "      <td>-0.0169</td>\n",
       "      <td>0.1772</td>\n",
       "      <td>-0.3298</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>momentum_only</th>\n",
       "      <td>0.0068</td>\n",
       "      <td>0.1576</td>\n",
       "      <td>0.1505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4factor_composite</th>\n",
       "      <td>-0.0078</td>\n",
       "      <td>0.1688</td>\n",
       "      <td>-0.1593</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     mean     std   ic_ir\n",
       "momentum           0.0068  0.1576  0.1505\n",
       "value             -0.0198  0.1344 -0.5111\n",
       "quality            0.0013  0.1597  0.0282\n",
       "lowvol            -0.0169  0.1772 -0.3298\n",
       "momentum_only      0.0068  0.1576  0.1505\n",
       "4factor_composite -0.0078  0.1688 -0.1593"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 40352 characters]",
      "text/plain": [
       "<Figure size 1000x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\"\"\"\n",
    "==================================\n",
    "Compare IC: momentum-only vs. 4-factor composite vs. individual factors\n",
    "==================================\n",
    "\"\"\"\n",
    "def compute_monthly_ic(factor_df, return_df):\n",
    "    common_dates = factor_df.index.intersection(return_df.index)\n",
    "    common_tickers = factor_df.columns.intersection(return_df.columns)\n",
    "    ic_series = []\n",
    "    for date in common_dates:\n",
    "        f = factor_df.loc[date, common_tickers]\n",
    "        r = return_df.loc[date, common_tickers]\n",
    "        mask = f.notna() & r.notna()\n",
    "        if mask.sum() < 20:\n",
    "            ic_series.append(np.nan)\n",
    "            continue\n",
    "        ic, _ = spearmanr(f[mask], r[mask])\n",
    "        ic_series.append(ic)\n",
    "    return pd.Series(ic_series, index=common_dates)\n",
    "\n",
    "# Compute IC for all signals\n",
    "ic_compare = {}\n",
    "for name in factor_names:\n",
    "    ic_compare[name] = compute_monthly_ic(factor_neut[name], df_returns)\n",
    "ic_compare['momentum_only'] = compute_monthly_ic(df_momentum_signal, df_returns)\n",
    "ic_compare['4factor_composite'] = compute_monthly_ic(df_composite_4f, df_returns)\n",
    "\n",
    "df_ic_compare = pd.DataFrame(ic_compare)\n",
    "\n",
    "summary = df_ic_compare.describe().T[['mean', 'std']]\n",
    "summary['ic_ir'] = summary['mean'] / summary['std'] * np.sqrt(12)\n",
    "summary = summary.round(4)\n",
    "\n",
    "print(\"IC Comparison: Neutralized Factors, Momentum-Only, and 4-Factor Composite\\n\")\n",
    "display(summary)\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(10, 6))\n",
    "colors = ['coral', 'goldenrod', 'seagreen', 'purple', 'steelblue', 'coral']\n",
    "summary['mean'].plot(kind='bar', ax=ax, color=['coral', 'goldenrod', 'seagreen', 'purple', 'steelblue', 'coral'])\n",
    "ax.set_ylabel('Mean Monthly IC')\n",
    "ax.set_title('Mean IC: Momentum-Only vs. Composite vs. Individual Factors')\n",
    "ax.axhline(y=0, color='black', linewidth=0.5)\n",
    "ax.grid(alpha=0.3, axis='y')\n",
    "\n",
    "plt.tight_layout()\n",
    "plt.savefig('../images/03_factor_construction/composite_vs_single_ic.png', dpi=150, bbox_inches='tight')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "9c9cc628",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-07-31T11:08:58.702363Z",
     "iopub.status.busy": "2026-07-31T11:08:58.702180Z",
     "iopub.status.idle": "2026-07-31T11:08:59.630835Z",
     "shell.execute_reply": "2026-07-31T11:08:59.630226Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved:\n",
      "  - momentum_signal.csv          (momentum-only, sector-neutralized)\n",
      "  - composite_4factor.csv         (4-factor equal-weight — comparison only)\n",
      "  - factor_momentum_neutralized.csv\n",
      "  - factor_value_neutralized.csv\n",
      "  - factor_quality_neutralized.csv\n",
      "  - factor_lowvol_neutralized.csv\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "==================================\n",
    "Save signals and neutralized factors\n",
    "==================================\n",
    "\"\"\"\n",
    "# The headline signal: momentum-only, sector-neutralized\n",
    "df_momentum_signal.to_csv('../data/processed/momentum_signal.csv')\n",
    "\n",
    "# The 4-factor composite: kept for comparison\n",
    "df_composite_4f.to_csv('../data/processed/composite_4factor.csv')\n",
    "\n",
    "# Individual neutralized factors\n",
    "for name in factor_names:\n",
    "    factor_neut[name].to_csv(f'../data/processed/factor_{name}_neutralized.csv')\n",
    "\n",
    "print(\"Saved:\")\n",
    "print(\"  - momentum_signal.csv          (momentum-only, sector-neutralized)\")\n",
    "print(\"  - composite_4factor.csv         (4-factor equal-weight — comparison only)\")\n",
    "for name in factor_names:\n",
    "    print(f\"  - factor_{name}_neutralized.csv\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "daab87e7",
   "metadata": {},
   "source": [
    "## Conclusion\n",
    "\n",
    "The comparison supports a simple choice: use **momentum-only, sector-neutralized** as the headline signal.\n",
    "\n",
    "- Sector neutralization slightly improves the momentum IC.\n",
    "- The equal-weight four-factor composite is worse, because it mixes momentum with weak or negative proxy signals.\n",
    "- The result is also easier to explain: rank stocks by momentum within a sector-neutral framework, then trade the top decile.\n",
    "\n",
    "Notebook 04 turns this signal into portfolio weights and asks whether it produces returns net of transaction costs."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
