Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions posts/mean-reversion-strategy-2/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
"#| code-fold: true\n",
"#| code-summary: \"Show simulation code\"\n",
"#| label: fig-terminal-pnl\n",
"#| fig-cap: \"Terminal PnL distributions widen with bias (left). The standard deviation of $Y_T$ matches the closed-form $\\sqrt{M^2 s_T^2 + s_T^4/2}$ (right).\"\n",
"#| fig-cap: 'Terminal PnL distributions widen with bias (left). The standard deviation of $Y_T$ matches the closed-form $\\sqrt{M^2 s_T^2 + s_T^4/2}$ (right).'\n",
"# --- Simulation: terminal PnL distribution for different M ---\n",
"theta, sigma, T, dt = 1.0, 0.10, 10, 1 / 252\n",
"n_paths = 20_000\n",
Expand Down Expand Up @@ -461,7 +461,7 @@
"#| code-fold: true\n",
"#| code-summary: \"Show simulation code\"\n",
"#| label: fig-sr-theta-bias\n",
"#| fig-cap: \"Asymptotic Sharpe ratio vs mean-reversion speed $\\theta$ for different biases. Lines are the closed-form formula; dots are Monte Carlo estimates.\"\n",
"#| fig-cap: 'Asymptotic Sharpe ratio vs mean-reversion speed $\\theta$ for different biases. Lines are the closed-form formula; dots are Monte Carlo estimates.'\n",
"# --- Simulation: Asymptotic Sharpe Ratio vs theta for different M ---\n",
"\n",
"def sr_asymptotic(theta, sigma, M):\n",
Expand Down Expand Up @@ -544,7 +544,7 @@
"#| code-fold: true\n",
"#| code-summary: \"Show simulation code\"\n",
"#| label: fig-sr-penalty-heatmap\n",
"#| fig-cap: \"SR penalty factor $(1 + 2\\theta M^2/\\sigma^2)^{-1/2}$ over the $(\\theta, |M|/\\sigma)$ plane. Green regions indicate low penalty; red regions indicate large penalty.\"\n",
"#| fig-cap: 'SR penalty factor $(1 + 2\\theta M^2/\\sigma^2)^{-1/2}$ over the $(\\theta, |M|/\\sigma)$ plane. Green regions indicate low penalty; red regions indicate large penalty.'\n",
"# --- Heatmap: SR penalty factor as function of (theta, M/sigma) ---\n",
"\n",
"theta_grid = np.linspace(0.1, 5.0, 200)\n",
Expand Down Expand Up @@ -592,7 +592,7 @@
"#| code-fold: true\n",
"#| code-summary: \"Show simulation code\"\n",
"#| label: fig-sr-horizon-bias\n",
"#| fig-cap: \"Finite-horizon Sharpe ratio $\\mathrm{SR}_t$ as a function of trading horizon for different biases $M$. All curves converge to their asymptotic limits (dots = MC).\"\n",
"#| fig-cap: 'Finite-horizon Sharpe ratio $\\mathrm{SR}_t$ as a function of trading horizon for different biases $M$. All curves converge to their asymptotic limits (dots = MC).'\n",
"# --- Finite-horizon SR_t vs t for different M ---\n",
"\n",
"theta, sigma = 1.0, 0.10\n",
Expand Down
8 changes: 4 additions & 4 deletions posts/mean-reversion-strategy-3/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
"#| code-fold: true\n",
"#| code-summary: \"Show simulation code\"\n",
"#| label: fig-random-bias\n",
"#| fig-cap: \"Random independent bias. Expected PnL is invariant to bias uncertainty (left). SR degrades with $\\sigma_M$ following the same penalty formula as the constant-bias case (right).\"\n",
"#| fig-cap: 'Random independent bias. Expected PnL is invariant to bias uncertainty (left). SR degrades with $\\sigma_M$ following the same penalty formula as the constant-bias case (right).'\n",
"# --- Simulation: SR with random independent bias ---\n",
"theta, sigma, T, dt = 1.0, 0.10, 100, 1 / 252\n",
"n_paths = 3_000\n",
Expand Down Expand Up @@ -412,7 +412,7 @@
"#| code-fold: true\n",
"#| code-summary: \"Show simulation code\"\n",
"#| label: fig-ema-cov-pnl\n",
"#| fig-cap: \"Stationary covariance $\\Sigma_{XM}$ (left) and mean annualised PnL (right) vs EMA decay rate $\\lambda$. Faster EMA tracking increases correlation and reduces expected PnL.\"\n",
"#| fig-cap: 'Stationary covariance $\\Sigma_{XM}$ (left) and mean annualised PnL (right) vs EMA decay rate $\\lambda$. Faster EMA tracking increases correlation and reduces expected PnL.'\n",
"# --- EMA: stationary covariance and mean PnL rate vs lambda ---\n",
"theta, sigma = 1.0, 0.10\n",
"T, dt, n_paths = 30, 1 / 252, 3_000\n",
Expand Down Expand Up @@ -478,7 +478,7 @@
"#| code-fold: true\n",
"#| code-summary: \"Show simulation code\"\n",
"#| label: fig-sr-ema\n",
"#| fig-cap: \"Sharpe ratio vs $\\theta$ for different EMA decay rates. Lines are the closed-form $\\theta/\\sqrt{2(\\theta+\\lambda)}$; dots are Monte Carlo estimates.\"\n",
"#| fig-cap: 'Sharpe ratio vs $\\theta$ for different EMA decay rates. Lines are the closed-form $\\theta/\\sqrt{2(\\theta+\\lambda)}$; dots are Monte Carlo estimates.'\n",
"# --- SR vs theta for different EMA speeds ---\n",
"sigma = 0.10\n",
"T, dt, n_paths = 100, 1 / 252, 1_000\n",
Expand Down Expand Up @@ -554,7 +554,7 @@
"#| code-fold: true\n",
"#| code-summary: \"Show simulation code\"\n",
"#| label: fig-ema-penalty\n",
"#| fig-cap: \"Universal penalty curve $1/\\sqrt{1+\\lambda/\\theta}$ (left) and absolute SR heatmap over the $(\\theta, \\lambda)$ plane (right).\"\n",
"#| fig-cap: 'Universal penalty curve $1/\\sqrt{1+\\lambda/\\theta}$ (left) and absolute SR heatmap over the $(\\theta, \\lambda)$ plane (right).'\n",
"# --- Penalty curve and 2-D SR heatmap ---\n",
"fig, axes = plt.subplots(1, 2, figsize=(14, 5))\n",
"\n",
Expand Down
8 changes: 4 additions & 4 deletions posts/mean-reversion-strategy-4/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
"#| code-fold: true\n",
"#| code-summary: \"Show simulation code\"\n",
"#| label: fig-mle-bias\n",
"#| fig-cap: \"Finite-sample distributions of MLE estimates $\\\\hat\\\\theta$ (top) and $\\\\hat\\\\mu$ (bottom) for calibration windows of 2, 5, 10, and 20 years ($\\\\theta=1, \\\\sigma=1, \\\\mu=0$). The upward bias in $\\\\hat\\\\theta$ and the high variance of $\\\\hat\\\\mu$ diminish as the calibration window lengthens.\"\n",
"#| fig-cap: 'Finite-sample distributions of MLE estimates $\\\\hat\\\\theta$ (top) and $\\\\hat\\\\mu$ (bottom) for calibration windows of 2, 5, 10, and 20 years ($\\\\theta=1, \\\\sigma=1, \\\\mu=0$). The upward bias in $\\\\hat\\\\theta$ and the high variance of $\\\\hat\\\\mu$ diminish as the calibration window lengthens.'\n",
"# --- Finite-sample bias in MLE estimates ---\n",
"theta_true, sigma_true, mu_true = 1.0, 1.0, 0.0\n",
"dt = 1 / 252\n",
Expand Down Expand Up @@ -335,7 +335,7 @@
"#| code-fold: true\n",
"#| code-summary: \"Show simulation code\"\n",
"#| label: fig-sr-estimation\n",
"#| fig-cap: \"Estimation penalty on Sharpe ratio vs calibration length $\\\\theta T_{\\\\mathrm{est}}$. Left: penalty factor. Right: absolute SR. Monte Carlo dots closely track the theoretical curve $(1 + 2/\\\\theta T_{\\\\mathrm{est}})^{-1/2}$.\"\n",
"#| fig-cap: 'Estimation penalty on Sharpe ratio vs calibration length $\\\\theta T_{\\\\mathrm{est}}$. Left: penalty factor. Right: absolute SR. Monte Carlo dots closely track the theoretical curve $(1 + 2/\\\\theta T_{\\\\mathrm{est}})^{-1/2}$.'\n",
"# --- SR vs estimation window: theory + MC ---\n",
"theta_true, sigma_true, mu_true = 1.0, 1.0, 0.0\n",
"dt = 1 / 252\n",
Expand Down Expand Up @@ -493,7 +493,7 @@
"#| code-fold: true\n",
"#| code-summary: \"Show simulation code\"\n",
"#| label: fig-rolling-estimation\n",
"#| fig-cap: \"Rolling SMA penalty vs window length. Left: MC penalty factor for rolling SMA against the theoretical curve $(1+2/\\\\theta W)^{-1/2}$. Right: one-shot and rolling penalties overlaid on the same curve, confirming they share identical functional form.\"\n",
"#| fig-cap: 'Rolling SMA penalty vs window length. Left: MC penalty factor for rolling SMA against the theoretical curve $(1+2/\\\\theta W)^{-1/2}$. Right: one-shot and rolling penalties overlaid on the same curve, confirming they share identical functional form.'\n",
"# --- Rolling estimation: SMA bias simulation ---\n",
"theta_true, sigma_true = 1.0, 1.0\n",
"dt = 1 / 252\n",
Expand Down Expand Up @@ -620,7 +620,7 @@
"#| code-fold: true\n",
"#| code-summary: \"Show simulation code\"\n",
"#| label: fig-overconfidence\n",
"#| fig-cap: \"Distribution of predicted SR $\\\\sqrt{\\\\hat\\\\theta/2}$ vs true and realised SR for calibration lengths of 2, 5, 10, and 20 years. The median prediction systematically exceeds realised SR, with the gap narrowing as the calibration window lengthens.\"\n",
"#| fig-cap: 'Distribution of predicted SR $\\\\sqrt{\\\\hat\\\\theta/2}$ vs true and realised SR for calibration lengths of 2, 5, 10, and 20 years. The median prediction systematically exceeds realised SR, with the gap narrowing as the calibration window lengthens.'\n",
"# --- Overconfidence: predicted vs realised SR ---\n",
"theta_true, sigma_true = 1.0, 1.0\n",
"dt = 1 / 252\n",
Expand Down