diff --git a/LeanPool/MathFin.lean b/LeanPool/MathFin.lean new file mode 100644 index 0000000000..3fc67aa385 --- /dev/null +++ b/LeanPool/MathFin.lean @@ -0,0 +1,29 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.FTAP.MarketFTAP +public import LeanPool.MathFin.Models.Binomial.Market +public import LeanPool.MathFin.Models.ModelFree.RoperConverse +public import LeanPool.MathFin.Models.Rates.VasicekMarket +public import LeanPool.MathFin.Risk.AcceptanceSet +public import LeanPool.MathFin.Risk.WorstCaseRisk + +/-! +# Pricing measures, market models and coherent risk + +Source: arxiv:2606.01356, url:https://github.com/formal-applied-math/formal-mathfin/tree/55e29a93e75f10b40f61f45c78a6058b2938045f +Authors: Raphael Coelho, Robert Martin, Yang Ye, Alfredo Garcia, Aleksey Salkutsan +Status: verified +Main declarations: `MathFin.Market.noArbitrage_iff_exists_isPricingMeasure_of_finite`, + `MathFin.Contracts.Binomial.price_pay_eq_binomialPrice_of_isPricingMeasure`, + `MathFin.exists_market_of_isNormalizedCallPrice`, `MathFin.Rates.price_pay_vasicekMarket`, + `MathFin.coherentRisk_isLUB` +Tags: mathematical-finance, discrete-time-martingales, asset-pricing, risk-measures +MSC: 91G20, 91G70, 60G44 +-/ diff --git a/LeanPool/MathFin/Choice/Performance/BetSizeSigmoid.lean b/LeanPool/MathFin/Choice/Performance/BetSizeSigmoid.lean new file mode 100644 index 0000000000..00e84ae3cd --- /dev/null +++ b/LeanPool/MathFin/Choice/Performance/BetSizeSigmoid.lean @@ -0,0 +1,135 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Performance.Ratios + +/-! +# Sigmoid bet-sizing function + +López de Prado (*Advances in Financial Machine Learning*, Wiley 2018, ch. 10) sizes +a bet from the divergence `x = f - p` between the forecast price `f` and the +current market price `p` via the sigmoid `m(x) = x / √(w + x²)` (`w > 0` a width +parameter), rather than a hard threshold. + +This file proves the three structural properties that justify using `m` as a +bet-sizing map: it is odd, bounded in `(-1,1)`, and strictly increasing in `x` +whenever `w > 0`. It also ties `m` to the Kelly criterion: fed the z-statistic +`z = (p − ½)/√(p(1 − p))` of a predicted win probability `p` (scaled by `√w`), the +sigmoid returns exactly `2p − 1`, the Kelly fraction of an even-money bet +(`kellyFraction p 1`, `Choice/Performance/Ratios.lean`). López de Prado's probability-based size +`2Φ(z) − 1` (ch. 10) is a different map and is not treated here. + +## Main definitions + +* `betSize`: the bet-sizing sigmoid `m(x) = x / √(w + x²)` with width parameter `w`. + +## Main results + +* `betSize_odd`: `m w (-x) = -m w x`. +* `betSize_mem_Ioo`: `m w x ∈ (-1, 1)` for `w > 0`. +* `betSize_strictMono`: `w > 0 → StrictMono (m w ·)`. +* `betSize_sqrt_mul_zScore`: `m w (√w · z) = kellyFraction p 1 = 2p − 1` for `0 < p < 1`. + +## References + +* [J. L. Kelly, *A new interpretation of information rate*][Kelly1956] +* [López de Prado, *Advances in Financial Machine Learning*][LopezDePrado2018], ch. 10 + +## Tags + +bet sizing, López de Prado, sigmoid, Kelly criterion, machine learning for finance, MSC 91G10, +JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +/-- The bet-sizing sigmoid `m(x) = x / √(w + x²)`. -/ +noncomputable def betSize (w x : ℝ) : ℝ := x / Real.sqrt (w + x ^ 2) + +theorem betSize_odd (w x : ℝ) : betSize w (-x) = -betSize w x := by + simp [betSize, neg_div] + +theorem betSize_mem_Ioo {w : ℝ} (hw : 0 < w) (x : ℝ) : betSize w x ∈ Set.Ioo (-1 : ℝ) 1 := by + have hpos : 0 < w + x ^ 2 := by positivity + have hsqrt_pos : 0 < Real.sqrt (w + x ^ 2) := Real.sqrt_pos.mpr hpos + have habs : |x| < Real.sqrt (w + x ^ 2) := by + rw [← Real.sqrt_sq_eq_abs] + exact Real.sqrt_lt_sqrt (by positivity) (by linarith) + have hm_abs : |betSize w x| < 1 := by + rw [betSize, abs_div, abs_of_pos hsqrt_pos, div_lt_one hsqrt_pos] + exact habs + exact abs_lt.mp hm_abs + +/-- Core monotonicity step: for `0 ≤ p < q` and `w > 0`, +`p · √(w+q²) < q · √(w+p²)`. -/ +theorem mul_sqrt_add_sq_lt_of_nonneg {w : ℝ} (hw : 0 < w) {p q : ℝ} (hp : 0 ≤ p) (hpq : p < q) : + p * Real.sqrt (w + q ^ 2) < q * Real.sqrt (w + p ^ 2) := by + have hq : 0 < q := lt_of_le_of_lt hp hpq + have hs1pos : 0 < Real.sqrt (w + p ^ 2) := Real.sqrt_pos.mpr (by positivity) + have hsqlt : (p * Real.sqrt (w + q ^ 2)) ^ 2 < (q * Real.sqrt (w + p ^ 2)) ^ 2 := by + rw [mul_pow, mul_pow, Real.sq_sqrt (by positivity : (0:ℝ) ≤ w + q ^ 2), + Real.sq_sqrt (by positivity : (0:ℝ) ≤ w + p ^ 2)] + have hsq : p ^ 2 < q ^ 2 := sq_lt_sq' (by linarith) hpq + nlinarith [mul_lt_mul_of_pos_right hsq hw] + exact lt_of_pow_lt_pow_left₀ 2 (mul_pos hq hs1pos).le hsqlt + +/-- The key cross-multiplied inequality behind strict monotonicity, for any +reals `a < b` (not just nonnegative ones). -/ +theorem mul_sqrt_add_sq_lt {w : ℝ} (hw : 0 < w) {a b : ℝ} (hab : a < b) : + a * Real.sqrt (w + b ^ 2) < b * Real.sqrt (w + a ^ 2) := by + rcases le_total 0 a with ha | ha + · exact mul_sqrt_add_sq_lt_of_nonneg hw ha hab + · rcases le_total b 0 with hb | hb + · have := mul_sqrt_add_sq_lt_of_nonneg hw (by linarith : (0:ℝ) ≤ -b) (by linarith : -b < -a) + have ha2 : (-a) ^ 2 = a ^ 2 := by ring + have hb2 : (-b) ^ 2 = b ^ 2 := by ring + rw [ha2, hb2] at this + linarith + · have hs1pos : 0 < Real.sqrt (w + a ^ 2) := Real.sqrt_pos.mpr (by positivity) + have hs2pos : 0 < Real.sqrt (w + b ^ 2) := Real.sqrt_pos.mpr (by positivity) + have h1 : a * Real.sqrt (w + b ^ 2) ≤ 0 := mul_nonpos_of_nonpos_of_nonneg ha hs2pos.le + rcases eq_or_lt_of_le ha with ha0 | ha0 + · have hb0 : 0 < b := by rw [ha0] at hab; exact hab + have h2 : 0 < b * Real.sqrt (w + a ^ 2) := mul_pos hb0 hs1pos + linarith + · have h2 : a * Real.sqrt (w + b ^ 2) < 0 := mul_neg_of_neg_of_pos ha0 hs2pos + have h3 : 0 ≤ b * Real.sqrt (w + a ^ 2) := mul_nonneg hb hs1pos.le + linarith + +theorem betSize_strictMono {w : ℝ} (hw : 0 < w) : StrictMono (betSize w) := by + intro a b hab + have hs1pos : 0 < Real.sqrt (w + a ^ 2) := Real.sqrt_pos.mpr (by positivity) + have hs2pos : 0 < Real.sqrt (w + b ^ 2) := Real.sqrt_pos.mpr (by positivity) + rw [betSize, betSize, div_lt_div_iff₀ hs1pos hs2pos] + exact mul_sqrt_add_sq_lt hw hab + +/-- **The sigmoid of the probability z-score is the even-money Kelly fraction.** For a +predicted win probability `0 < p < 1`, let `z = (p − ½)/√(p(1 − p))` be the z-statistic of +`p` against `½`. For every width `w > 0`, `m w (√w · z) = 2p − 1 = kellyFraction p 1`, the +Kelly fraction of an even-money bet (`Choice/Performance/Ratios.lean`). The width only rescales +the argument, and `w + w z² = w / (4 p (1 − p))`, so `√w·z / √(w + w z²) = 2p − 1`. -/ +theorem betSize_sqrt_mul_zScore {w p : ℝ} (hw : 0 < w) (hp₀ : 0 < p) (hp₁ : p < 1) : + betSize w (√w * ((p - 1 / 2) / √(p * (1 - p)))) = kellyFraction p 1 := by + have hpq : 0 < p * (1 - p) := mul_pos hp₀ (sub_pos.2 hp₁) + have hp0 : p ≠ 0 := hp₀.ne' + have hq0 : 1 - p ≠ 0 := (sub_pos.2 hp₁).ne' + have hs0 : √(p * (1 - p)) ≠ 0 := (Real.sqrt_pos.2 hpq).ne' + have hw0 : √w ≠ 0 := (Real.sqrt_pos.2 hw).ne' + have hrad : w + (√w * ((p - 1 / 2) / √(p * (1 - p)))) ^ 2 = + (√w / (2 * √(p * (1 - p)))) ^ 2 := by + rw [mul_pow, div_pow, div_pow, mul_pow, Real.sq_sqrt hw.le, Real.sq_sqrt hpq.le] + field_simp + ring + rw [betSize, hrad, Real.sqrt_sq (by positivity), kellyFraction] + field_simp + ring + +end MathFin diff --git a/LeanPool/MathFin/Choice/Performance/DownsideMetrics.lean b/LeanPool/MathFin/Choice/Performance/DownsideMetrics.lean new file mode 100644 index 0000000000..ce720c4ee5 --- /dev/null +++ b/LeanPool/MathFin/Choice/Performance/DownsideMetrics.lean @@ -0,0 +1,211 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Aleksey Salkutsan, Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Performance.Ratios + +/-! +# Downside performance metrics + +Finite-state Omega ratio, maximum drawdown of a finite price path, and the +positive-scaling invariance of the Calmar ratio. + +## Main definitions + +* `FiniteReturnModel`: a finite return model, nonnegative probability weights of total mass one. +* `finiteExpectedReturn`: the expected return of a finite return model. +* `omegaUpside`, `omegaDownside`: the expected gain above and the expected shortfall below a + threshold. +* `omegaRatio`: the Omega ratio at a threshold in a finite state space. +* `maximumDrawdown`: the largest decline of a finite price path below its running peak. +* `calmarRatio`: the annual return divided by the maximum drawdown. + +## Main results + +* `omega_upside_sub_downside`: expected upside minus expected downside is the mean excess return. +* `omegaRatio_nonneg`: the finite-state Omega ratio is nonnegative. +* `omegaRatio_threshold_identity`: when the expected downside is nonzero, + `omegaRatio − 1 = (𝔼[R] − threshold) / omegaDownside`. +* `sub_le_maximumDrawdown`: every chronological peak-to-trough decline `E s − E t`, `s ≤ t`, is at + most `maximumDrawdown E`. +* `maximumDrawdown_nonneg`, `maximumDrawdown_scale`: nonnegativity, and positive homogeneity for + scaling by `c ≥ 0`. +* `calmarRatio_scale_invariant`: the Calmar ratio is unchanged by a common scaling `c > 0`. +* `downsideMetrics_bundle`: one conjunction collecting the Omega, drawdown and Calmar facts. + +## References + +* [Keating and Shadwick (2002)][KeatingShadwick2002] +* [Young (1991)][Young1991] + +## Tags + +Omega ratio, maximum drawdown, Calmar ratio, downside risk, performance measurement, MSC 91G10, +JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +open scoped BigOperators + +/-- A finite return model with nonnegative probability weights of total mass one. -/ +structure FiniteReturnModel (ι : Type*) [Fintype ι] where + /-- Probability weight assigned to a state. -/ + weight : ι → ℝ + /-- Return realized in a state. -/ + outcome : ι → ℝ + weight_nonneg : ∀ i, 0 ≤ weight i + weight_sum_one : ∑ i, weight i = 1 + +/-- Expected return of a finite return model. -/ +def finiteExpectedReturn {ι : Type*} [Fintype ι] (m : FiniteReturnModel ι) : ℝ := + ∑ i, m.weight i * m.outcome i + +/-- Expected gain above a threshold. -/ +def omegaUpside {ι : Type*} [Fintype ι] (m : FiniteReturnModel ι) (threshold : ℝ) : ℝ := + ∑ i, m.weight i * max (m.outcome i - threshold) 0 + +/-- Expected shortfall below a threshold. -/ +def omegaDownside {ι : Type*} [Fintype ι] + (m : FiniteReturnModel ι) (threshold : ℝ) : ℝ := + ∑ i, m.weight i * max (threshold - m.outcome i) 0 + +/-- Omega ratio at a threshold in a finite state space. -/ +noncomputable def omegaRatio {ι : Type*} [Fintype ι] + (m : FiniteReturnModel ι) (threshold : ℝ) : ℝ := + omegaUpside m threshold / omegaDownside m threshold + +/-- Expected upside minus expected downside equals mean excess return. -/ +theorem omega_upside_sub_downside {ι : Type*} [Fintype ι] + (m : FiniteReturnModel ι) (threshold : ℝ) : + omegaUpside m threshold - omegaDownside m threshold = + finiteExpectedReturn m - threshold := by + unfold omegaUpside omegaDownside finiteExpectedReturn + rw [← Finset.sum_sub_distrib] + calc + (∑ i, (m.weight i * max (m.outcome i - threshold) 0 - + m.weight i * max (threshold - m.outcome i) 0)) = + ∑ i, m.weight i * (m.outcome i - threshold) := by + apply Finset.sum_congr rfl + intro i _ + rw [← mul_sub] + congr 1 + simpa only [neg_sub] using max_zero_sub_max_neg_zero_eq_self (m.outcome i - threshold) + _ = ∑ i, (m.weight i * m.outcome i - threshold * m.weight i) := by + apply Finset.sum_congr rfl + intro i _ + ring + _ = (∑ i, m.weight i * m.outcome i) - threshold * (∑ i, m.weight i) := by + rw [Finset.sum_sub_distrib, Finset.mul_sum] + _ = (∑ i, m.weight i * m.outcome i) - threshold := by + rw [m.weight_sum_one, mul_one] + +/-- The finite-state Omega ratio is nonnegative. -/ +theorem omegaRatio_nonneg {ι : Type*} [Fintype ι] + (m : FiniteReturnModel ι) (threshold : ℝ) : + 0 ≤ omegaRatio m threshold := by + unfold omegaRatio omegaUpside omegaDownside + apply div_nonneg + · exact Finset.sum_nonneg fun i _ => + mul_nonneg (m.weight_nonneg i) (le_max_right _ _) + · exact Finset.sum_nonneg fun i _ => + mul_nonneg (m.weight_nonneg i) (le_max_right _ _) + +/-- Threshold identity for the Omega ratio when expected downside is nonzero. -/ +theorem omegaRatio_threshold_identity {ι : Type*} [Fintype ι] + (m : FiniteReturnModel ι) (threshold : ℝ) + (hdown : omegaDownside m threshold ≠ 0) : + omegaRatio m threshold - 1 = + (finiteExpectedReturn m - threshold) / omegaDownside m threshold := by + calc + omegaRatio m threshold - 1 = + (omegaUpside m threshold - omegaDownside m threshold) / + omegaDownside m threshold := by + unfold omegaRatio + field_simp [hdown] + _ = (finiteExpectedReturn m - threshold) / omegaDownside m threshold := by + rw [omega_upside_sub_downside] + +/-- The running peak is positively homogeneous: multiplication by `c > 0` is an order +isomorphism, so it commutes with the finite suprema defining `partialSups`. This is the +group-with-zero version of Mathlib's `[Group α]` lemma `partialSups_const_mul`. -/ +theorem partialSups_const_mul₀ {ι : Type*} [Preorder ι] [LocallyFiniteOrderBot ι] + {G₀ : Type*} [GroupWithZero G₀] [SemilatticeSup G₀] [PosMulReflectLT G₀] {c : G₀} + (hc : 0 < c) (E : ι → G₀) (t : ι) : + partialSups (fun s ↦ c * E s) t = c * partialSups E t := + map_partialSups (OrderIso.mulLeft₀ c hc) E t + +/-- **Maximum drawdown** of a finite price path: the largest decline `max_{s ≤ t} E s − E t` of +the path below its running peak (Mathlib's `partialSups`), which is the largest chronological +peak-to-trough loss `E s − E t`, `s ≤ t` (`sub_le_maximumDrawdown`). The empty path has drawdown +`0`. -/ +noncomputable def maximumDrawdown {n : ℕ} (price : Fin n → ℝ) : ℝ := + ⨆ t, partialSups price t - price t + +/-- The decline below the running peak at any date is at most the maximum drawdown. -/ +theorem partialSups_sub_le_maximumDrawdown {n : ℕ} (price : Fin n → ℝ) (t : Fin n) : + partialSups price t - price t ≤ maximumDrawdown price := + le_ciSup (f := fun t ↦ partialSups price t - price t) (Set.finite_range _).bddAbove t + +/-- Every chronological peak-to-trough decline `E s − E t` (`s ≤ t`) of a finite path is at +most its `maximumDrawdown`. -/ +theorem sub_le_maximumDrawdown {n : ℕ} (E : Fin n → ℝ) {s t : Fin n} (hst : s ≤ t) : + E s - E t ≤ maximumDrawdown E := + (sub_le_sub_right (le_partialSups_of_le E hst) _).trans (partialSups_sub_le_maximumDrawdown E t) + +/-- Maximum drawdown is nonnegative, including for an empty path. -/ +theorem maximumDrawdown_nonneg {n : ℕ} (price : Fin n → ℝ) : + 0 ≤ maximumDrawdown price := + Real.iSup_nonneg fun t ↦ sub_nonneg.2 (le_partialSups_of_le price (le_refl t)) + +/-- Maximum drawdown is positively homogeneous for nonnegative scaling. -/ +theorem maximumDrawdown_scale {n : ℕ} (price : Fin n → ℝ) (c : ℝ) (hc : 0 ≤ c) : + maximumDrawdown (fun i => c * price i) = c * maximumDrawdown price := by + rcases hc.eq_or_lt with rfl | hc + · have h0 (t : Fin n) : partialSups (fun _ : Fin n ↦ (0 : ℝ)) t = 0 := + le_antisymm (partialSups_le _ _ _ fun _ _ ↦ le_rfl) + (le_partialSups_of_le (fun _ : Fin n ↦ (0 : ℝ)) (le_refl t)) + simp [maximumDrawdown, h0] + · rw [maximumDrawdown, maximumDrawdown, Real.mul_iSup_of_nonneg hc.le] + refine iSup_congr fun t ↦ ?_ + rw [partialSups_const_mul₀ hc] + ring + +/-- Calmar ratio: annual return divided by maximum drawdown. -/ +noncomputable def calmarRatio (annualReturn maxDrawdown : ℝ) : ℝ := + annualReturn / maxDrawdown + +/-- Calmar ratio is invariant under strictly positive common scaling. -/ +theorem calmarRatio_scale_invariant (annualReturn maxDrawdown c : ℝ) (hc : 0 < c) : + calmarRatio (c * annualReturn) (c * maxDrawdown) = + calmarRatio annualReturn maxDrawdown := by + simpa [calmarRatio] using + (diff_div_scale_invariant (c := c) hc.ne' annualReturn 0 maxDrawdown) + +/-- One acceptance bundle covering Omega, maximum drawdown, and Calmar. -/ +theorem downsideMetrics_bundle {ι : Type*} [Fintype ι] + (m : FiniteReturnModel ι) (threshold : ℝ) + (hdown : omegaDownside m threshold ≠ 0) + {n : ℕ} (price : Fin n → ℝ) (annualReturn c : ℝ) (hc : 0 < c) : + (0 ≤ omegaRatio m threshold ∧ + omegaRatio m threshold - 1 = + (finiteExpectedReturn m - threshold) / omegaDownside m threshold) ∧ + (0 ≤ maximumDrawdown price ∧ + maximumDrawdown (fun i => c * price i) = c * maximumDrawdown price) ∧ + calmarRatio (c * annualReturn) (c * maximumDrawdown price) = + calmarRatio annualReturn (maximumDrawdown price) := by + exact + ⟨⟨omegaRatio_nonneg m threshold, + omegaRatio_threshold_identity m threshold hdown⟩, + ⟨maximumDrawdown_nonneg price, + maximumDrawdown_scale price c hc.le⟩, + calmarRatio_scale_invariant annualReturn (maximumDrawdown price) c hc⟩ + +end MathFin diff --git a/LeanPool/MathFin/Choice/Performance/FracDiffWeights.lean b/LeanPool/MathFin/Choice/Performance/FracDiffWeights.lean new file mode 100644 index 0000000000..cb56568443 --- /dev/null +++ b/LeanPool/MathFin/Choice/Performance/FracDiffWeights.lean @@ -0,0 +1,205 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Laws.Estimation +public import Mathlib.Analysis.Analytic.Binomial + +/-! +# Fractional-differentiation weight recursion + +López de Prado (*Advances in Financial Machine Learning*, ch. 5) builds the +fractionally-differenced series `(1-B)^d X` from a weight sequence computed by +the recursion `w_0 = 1`, `w_k = -w_{k-1}·(d-k+1)/k`, the binomial-series +coefficients of `(1-B)^d` for real exponent `d`. + +This file states the recursion as `fracDiffWeight` and proves it agrees with +the closed-form alternating product `(-1)^k · ∏_{i -1` is not proved here, and no decay +statement is. + +The expanding-window differenced series `fracDiff d X t = ∑_{k ≤ t} wₖ X_{t-k}` is defined; +for an integer `d = n` the weights are `(-1)^k C(n, k)` and vanish beyond `n`, so `d = 1` +gives the first difference `X_{t+1} - X_t`. Applied to `X_t = μt + σB_t` with `B` a +pre-Brownian motion, observed on an equally spaced grid of `[0, T]`, the drift estimator +built from these first differences telescopes to the endpoint estimator of +`Probability/Laws/Estimation.lean`, so its law is `N(μ, σ²/T)` for every number of observations +(`hasLaw_fracDiff_one_driftEstimator`). Only the case `d = 1` enters there. + +## Main definitions + +* `fracDiffWeight`: the fractional-differentiation weights `w₀ = 1`, `w_{k+1} = −w_k (d − k)/(k+1)`. +* `fracDiff`: the expanding-window fractionally differenced series `∑_{k ≤ t} wₖ X_{t−k}`. + +## Main results + +* `fracDiffWeight_eq_prod`: `fracDiffWeight d k = (-1)^k * ∏ i ∈ range k, (d-i)/(i+1)`. +* `fracDiffWeight_eq_choose`: `fracDiffWeight d k = (-1)^k * Ring.choose d k`. +* `hasSum_fracDiffWeight_mul_pow`: `∑ₖ fracDiffWeight d k * x^k = (1 - x)^d` for `|x| < 1`. +* `abs_fracDiffWeight_succ`: `|fracDiffWeight d (k+1)| = |fracDiffWeight d k| * |d-k| / (k+1)`, + the per-step magnitude ratio between consecutive weights. +* `fracDiffWeight_natCast`, `fracDiff_one_succ`: integer orders; `d = 1` is the first + difference. +* `hasLaw_fracDiff_one_driftEstimator`: the first-difference drift estimator of a Brownian + motion with drift has law `N(μ, σ²/T)`, whatever the sampling frequency. + +## References + +* [Hosking, *Fractional differencing*][Hosking1981] +* [López de Prado, *Advances in Financial Machine Learning*][LopezDePrado2018], ch. 5; ch. 5, §5.4 +* [R. C. Merton, *On estimating the expected return on the market*][Merton1980], §I + +## Tags + +fractional differentiation, binomial series, López de Prado, stationarity, drift estimator, +long memory, MSC 62M10, MSC 60G22, JEL C22 +-/ + +@[expose] public section + +namespace MathFin + +open scoped NNReal + +/-- The fractional-differentiation weight recursion: `w_0 = 1`, +`w_{k+1} = -w_k · (d-k)/(k+1)` (i.e. `w_k = -w_{k-1}·(d-k+1)/k` for `k ≥ 1`). -/ +noncomputable def fracDiffWeight (d : ℝ) : ℕ → ℝ + | 0 => 1 + | k + 1 => -fracDiffWeight d k * (d - k) / (k + 1) + +@[simp] theorem fracDiffWeight_zero (d : ℝ) : fracDiffWeight d 0 = 1 := rfl + +theorem fracDiffWeight_succ (d : ℝ) (k : ℕ) : + fracDiffWeight d (k + 1) = -fracDiffWeight d k * (d - k) / (k + 1) := rfl + +/-- Closed form: `w_k` is the alternating product `(-1)^k · ∏_{i simp + | succ n ih => + rw [fracDiffWeight_succ, ih, Finset.prod_range_succ] + ring + +/-- Per-step magnitude ratio: `|w_{k+1}| = |w_k| · |d-k| / (k+1)`. -/ +theorem abs_fracDiffWeight_succ (d : ℝ) (k : ℕ) : + |fracDiffWeight d (k + 1)| = |fracDiffWeight d k| * |d - k| / (k + 1) := by + rw [fracDiffWeight_succ, abs_div, abs_mul, abs_neg, + abs_of_pos (show (0 : ℝ) < (k : ℝ) + 1 by positivity)] + +/-- `(k + 1) · C(d, k + 1) = C(d, k) · (d - k)`: the ratio recursion of Mathlib's +generalized binomial coefficient, the case `n = k + 1` of `Ring.choose_smul_choose`. -/ +lemma succ_mul_ringChoose_succ (d : ℝ) (k : ℕ) : + ((k : ℝ) + 1) * Ring.choose d (k + 1) = Ring.choose d k * (d - k) := by + have h := Ring.choose_smul_choose d (Nat.le_add_right k 1) + rw [Nat.choose_succ_self_right, Nat.add_sub_cancel_left, Ring.choose_one_right, + nsmul_eq_mul] at h + push_cast at h + exact h + +/-- **The weights are signed generalized binomial coefficients**: +`fracDiffWeight d k = (-1)^k * Ring.choose d k`, with Mathlib's `Ring.choose`. -/ +theorem fracDiffWeight_eq_choose (d : ℝ) (k : ℕ) : + fracDiffWeight d k = (-1) ^ k * Ring.choose d k := by + induction k with + | zero => simp + | succ k ih => + have h : Ring.choose d (k + 1) = Ring.choose d k * (d - k) / (k + 1) := by + rw [eq_div_iff (by positivity)] + linear_combination succ_mul_ringChoose_succ d k + rw [fracDiffWeight_succ, ih, h] + ring + +/-- **The weights are the binomial series of `(1 - x)^d`**: for `|x| < 1`, +`∑ₖ fracDiffWeight d k * x^k = (1 - x)^d`. From Mathlib's binomial series +`Real.one_add_rpow_hasFPowerSeriesOnBall_zero` at `-x` and `fracDiffWeight_eq_choose`. -/ +theorem hasSum_fracDiffWeight_mul_pow (d : ℝ) {x : ℝ} (hx : |x| < 1) : + HasSum (fun k ↦ fracDiffWeight d k * x ^ k) ((1 - x) ^ d) := by + have h := (Real.one_add_rpow_hasFPowerSeriesOnBall_zero (a := d)).hasSum (y := -x) + (by rw [mem_eball_zero_iff, Real.eNorm_eq_ofReal_abs, abs_neg, ENNReal.ofReal_lt_one] + exact hx) + simp only [zero_add, binomialSeries_apply, List.ofFn_const, List.prod_replicate, + smul_eq_mul] at h + have hfun : (fun k ↦ fracDiffWeight d k * x ^ k) = fun k ↦ Ring.choose d k * (-x) ^ k := by + funext k + rw [fracDiffWeight_eq_choose, neg_pow] + ring + rw [hfun, sub_eq_add_neg] + exact h + +/-- **Integer orders**: for `d = n ∈ ℕ` the weights are `(-1)^k C(n, k)`, so they vanish +for `k > n` and `(1 - B)^n` is a finite difference. -/ +theorem fracDiffWeight_natCast (n k : ℕ) : + fracDiffWeight n k = (-1) ^ k * (n.choose k : ℝ) := by + rw [fracDiffWeight_eq_choose, Ring.choose_natCast] + +/-- The expanding-window fractionally differenced series (López de Prado, ch. 5): +`fracDiff d X t = ∑_{k ≤ t} wₖ X_{t-k}`, the binomial series of `(1 - B)^d` applied to `X` +and truncated at the start of the sample. -/ +noncomputable def fracDiff (d : ℝ) (X : ℕ → ℝ) (t : ℕ) : ℝ := + ∑ k ∈ Finset.range (t + 1), fracDiffWeight d k * X (t - k) + +/-- **`d = 1` is the first difference**: `fracDiff 1 X (t + 1) = X (t + 1) - X t`, since +`w₀ = 1`, `w₁ = -1` and `wₖ = 0` for `k ≥ 2` (`fracDiffWeight_natCast`). -/ +theorem fracDiff_one_succ (X : ℕ → ℝ) (t : ℕ) : fracDiff 1 X (t + 1) = X (t + 1) - X t := by + have h1 : fracDiffWeight 1 1 = -1 := by + have h := fracDiffWeight_natCast 1 1 + norm_num at h + exact h + have h2 (k : ℕ) : fracDiffWeight 1 (k + 1 + 1) = 0 := by + have h := fracDiffWeight_natCast 1 (k + 1 + 1) + rw [Nat.cast_one, Nat.choose_eq_zero_of_lt (show 1 < k + 1 + 1 by omega), Nat.cast_zero, + mul_zero] at h + exact h + rw [fracDiff, Finset.sum_range_succ', Finset.sum_range_succ'] + simp only [h2, zero_mul, Finset.sum_const_zero, zero_add, h1, fracDiffWeight_zero, + Nat.add_sub_cancel, Nat.sub_zero] + ring + +open MeasureTheory ProbabilityTheory in +/-- **The first-difference drift estimator sees only the endpoints.** Let `X_t = μt + σB_t` +with `B` a pre-Brownian motion, observed at the `n ≥ 1` equally spaced times +`tₖ = kT/n` of `[0, T]`. The drift estimator `(1/T) ∑_{i 0` (no all-in bet + except in the degenerate `p = 1` case). +* **`kellyFraction = 0 iff break-even`**: `f* = 0` iff `p(b+1) = 1`. +* **`kellyFraction > 0 iff favorable bet`**: `f* > 0` iff `p(b+1) > 1`. + +## Main definitions + +* `kellyReturnMeasure`: one Kelly period's wealth-multiplier law, `1 + f·b` with probability `p` + and `1 − f` with probability `1 − p`. + +## Main results + +* `integral_log_kellyReturnMeasure`: one period's expected log-multiplier is + exactly `kellyGrowth p b f`. +* `kellyGrowth_n_periods`: over `n` iid periods the expected total log-growth + is `n · kellyGrowth p b f` — linearity of expectation over the actual + product model, via the measure-preserving coordinate evaluations of + `Measure.pi`. +* `kelly_n_periods_deriv_at_kelly`: first-order optimality for `n · kellyGrowth` + vanishes at the single-period `kellyFraction p b`. +* `kellyFraction_lt_one`, `kellyFraction_eq_zero_iff`, `kellyFraction_pos_iff`: + bounds and sign analysis of the Kelly fraction. + +## References + +* [J. L. Kelly, *A new interpretation of information rate*][Kelly1956] +* [MacLean, Thorp and Ziemba (2010)][MacLeanThorpZiemba2010] +* [Thorp (2006)][Thorp2006] + +## Tags + +Kelly criterion, growth-optimal, log utility, expected log-wealth, myopic investment, +optimal bet size, MSC 91G10, MSC 91B16, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +open Real MeasureTheory + +/-- One Kelly period's wealth-multiplier law: the bet at fraction `f` pays +odds `b` with probability `p` (multiplier `1 + f·b`) and loses the stake with +probability `1 - p` (multiplier `1 - f`). A two-point Borel measure on `ℝ`. -/ +noncomputable def kellyReturnMeasure (p b f : ℝ) : Measure ℝ := + ENNReal.ofReal p • Measure.dirac (1 + f * b) + + ENNReal.ofReal (1 - p) • Measure.dirac (1 - f) + +lemma kellyReturnMeasure_isProbability {p : ℝ} (hp : 0 ≤ p) (hp1 : p ≤ 1) + (b f : ℝ) : IsProbabilityMeasure (kellyReturnMeasure p b f) := by + constructor + have hq : (0 : ℝ) ≤ 1 - p := by linarith + unfold kellyReturnMeasure + rw [add_apply, smul_apply, smul_apply, + Measure.dirac_apply_of_mem (Set.mem_univ _), + Measure.dirac_apply_of_mem (Set.mem_univ _), smul_eq_mul, smul_eq_mul, + mul_one, mul_one, ← ENNReal.ofReal_add hp hq, + show p + (1 - p) = 1 by ring, ENNReal.ofReal_one] + +/-- `log` is integrable against the one-period law (a two-point measure). -/ +lemma integrable_log_kellyReturnMeasure (p b f : ℝ) : + Integrable Real.log (kellyReturnMeasure p b f) := + ((integrable_dirac eNorm_lt_top).smul_measure ENNReal.ofReal_ne_top).add_measure + ((integrable_dirac eNorm_lt_top).smul_measure ENNReal.ofReal_ne_top) + +/-- **One-period expected log-growth**: the expectation of `log` under the +one-period wealth-multiplier law is exactly `kellyGrowth p b f`. -/ +lemma integral_log_kellyReturnMeasure {p : ℝ} (hp : 0 ≤ p) (hp1 : p ≤ 1) + (b f : ℝ) : + ∫ x, Real.log x ∂(kellyReturnMeasure p b f) = kellyGrowth p b f := by + have hq : (0 : ℝ) ≤ 1 - p := by linarith + unfold kellyReturnMeasure + rw [integral_add_measure + ((integrable_dirac eNorm_lt_top).smul_measure ENNReal.ofReal_ne_top) + ((integrable_dirac eNorm_lt_top).smul_measure ENNReal.ofReal_ne_top), + integral_smul_measure, integral_smul_measure, integral_dirac, integral_dirac, + ENNReal.toReal_ofReal hp, ENNReal.toReal_ofReal hq] + simp [kellyGrowth, smul_eq_mul] + +/-- **Multi-period Kelly log-growth linearity**: over `n` iid periods, each +period's wealth multiplier distributed as `kellyReturnMeasure p b f`, the +expected total log-growth `E[log(R₁⋯R_n)] = E[∑ i, log Rᵢ]` equals +`n · kellyGrowth p b f`. This is linearity of expectation over the actual +`n`-period product model: each coordinate evaluation of `Measure.pi` is +measure-preserving onto the one-period law, whose log-expectation is +`kellyGrowth p b f`. -/ +theorem kellyGrowth_n_periods (n : ℕ) {p : ℝ} (hp : 0 ≤ p) (hp1 : p ≤ 1) + (b f : ℝ) : + ∫ R : Fin n → ℝ, ∑ i, Real.log (R i) + ∂(Measure.pi fun _ : Fin n ↦ kellyReturnMeasure p b f) + = (n : ℝ) * kellyGrowth p b f := by + have : IsProbabilityMeasure (kellyReturnMeasure p b f) := + kellyReturnMeasure_isProbability hp hp1 b f + -- each coordinate evaluation is measure-preserving onto the one-period law + have hmp : ∀ i : Fin n, MeasurePreserving (Function.eval i) + (Measure.pi fun _ : Fin n ↦ kellyReturnMeasure p b f) + (kellyReturnMeasure p b f) := fun i ↦ measurePreserving_eval _ i + -- linearity of expectation: integrability of each coordinate's log + have hint : ∀ i ∈ Finset.univ (α := Fin n), + Integrable (fun R : Fin n → ℝ ↦ Real.log (R i)) + (Measure.pi fun _ : Fin n ↦ kellyReturnMeasure p b f) := fun i _ ↦ + ((hmp i).integrable_comp Real.measurable_log.aestronglyMeasurable).mpr + (integrable_log_kellyReturnMeasure p b f) + rw [integral_finsetSum _ hint] + -- each marginal integral is the one-period expected log-growth + have hi : ∀ i : Fin n, + ∫ R : Fin n → ℝ, Real.log (R i) + ∂(Measure.pi fun _ : Fin n ↦ kellyReturnMeasure p b f) + = kellyGrowth p b f := by + intro i + have hmap := (hmp i).map_eq + calc ∫ R : Fin n → ℝ, Real.log (R i) + ∂(Measure.pi fun _ : Fin n ↦ kellyReturnMeasure p b f) + = ∫ x, Real.log x ∂(kellyReturnMeasure p b f) := by + conv_rhs => rw [← hmap] + rw [integral_map (measurable_pi_apply i).aemeasurable + Real.measurable_log.aestronglyMeasurable] + _ = kellyGrowth p b f := integral_log_kellyReturnMeasure hp hp1 b f + simp_rw [hi] + rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + +/-- **Multi-period Kelly first-order condition**: the optimal fraction is +independent of the horizon `n` — maximizing `n · kellyGrowth` is the same +single-period problem, so Kelly is myopic. -/ +lemma kelly_n_periods_deriv_at_kelly (n : ℕ) {p b : ℝ} + (hp : 0 < p) (hp1 : p < 1) (hb : 0 < b) : + HasDerivAt (fun f ↦ (n : ℝ) * kellyGrowth p b f) 0 (kellyFraction p b) := by + have h := kellyGrowth_deriv_at_kelly hp hp1 hb + have h_mul := h.const_mul (n : ℝ) + simpa using h_mul + +/-- **Kelly fraction < 1** for proper probabilities and positive payoff. -/ +lemma kellyFraction_lt_one {p b : ℝ} (hp : p < 1) (hb : 0 < b) : + kellyFraction p b < 1 := by + unfold kellyFraction + rw [div_lt_one hb] + nlinarith + +/-- **Kelly fraction = 0 iff break-even bet** (`p · (b + 1) = 1`). -/ +lemma kellyFraction_eq_zero_iff (p : ℝ) {b : ℝ} (hb : b ≠ 0) : + kellyFraction p b = 0 ↔ p * (b + 1) = 1 := by + unfold kellyFraction + rw [div_eq_zero_iff] + refine ⟨?_, ?_⟩ + · rintro (h | h) + · linarith + · exact absurd h hb + · intro h; left; linarith + +/-- **Kelly fraction > 0 iff favorable bet** (`p · (b + 1) > 1`). -/ +lemma kellyFraction_pos_iff (p : ℝ) {b : ℝ} (hb : 0 < b) : + 0 < kellyFraction p b ↔ 1 < p * (b + 1) := by + unfold kellyFraction + rw [lt_div_iff₀ hb] + refine ⟨?_, ?_⟩ <;> intro h <;> linarith + +end MathFin diff --git a/LeanPool/MathFin/Choice/Performance/LabelUniqueness.lean b/LeanPool/MathFin/Choice/Performance/LabelUniqueness.lean new file mode 100644 index 0000000000..8ad2c0c7a0 --- /dev/null +++ b/LeanPool/MathFin/Choice/Performance/LabelUniqueness.lean @@ -0,0 +1,96 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Order.BigOperators.Group.Finset +public import Mathlib.Data.Fintype.BigOperators +public import Mathlib.Basic.Real.Basic +public import Mathlib.Tactic.NormNum.Ineq + +/-! +# Per-observation uniqueness bound for overlapping-label samples + +López de Prado (*Advances in Financial Machine Learning*, ch. 4) measures how +much an overlapping-label observation `i` (with span `[t0 i, t1 i]`) overlaps +its peers via the concurrency `c_t = Σᵢ 1[t ∈ [t0 i, t1 i]]` and the +per-observation uniqueness `u_{t,i} = 1[t ∈ span i] / c_t`. + +This file states both over a finite index type `ι` and proves the basic bound +used to justify uniqueness-weighted sampling: whenever `i`'s span actually +contains `t`, `u_{t,i} ∈ (0, 1]`. The average uniqueness of observation `i` (the +mean of `u_{t,i}` over `i`'s span) is not defined here. + +## Main definitions + +* `concurrency`: the number of observations whose span `[t0 i, t1 i]` contains `t`. +* `uniqueness`: the per-observation uniqueness at `t`, `1 / c_t` if the span of `i` contains `t` + and `0` otherwise. + +## Main results + +* `concurrency_pos`: `c_t > 0` whenever some span contains `t`. +* `uniqueness_mem_Ioc`: `u_{t,i} ∈ (0, 1]` whenever `t ∈ span i`. +* `concurrency_sumElim`: the concurrency of a pooled sample `ι ⊕ κ` is the sum of the two + samples' concurrencies (used by `Choice/Performance/PurgedCV.lean`). + +## Tags + +overlapping labels, sample uniqueness, concurrency, López de Prado, sample weights, MSC 62M10, +JEL C58 +-/ + +@[expose] public section + +namespace MathFin + +variable {ι : Type*} [Fintype ι] + +/-- Concurrency at time `t`: the number of observations whose span +`[t0 i, t1 i]` contains `t`. -/ +noncomputable def concurrency (t0 t1 : ι → ℝ) (t : ℝ) : ℝ := + ∑ i, if t ∈ Set.Icc (t0 i) (t1 i) then (1 : ℝ) else 0 + +/-- Per-observation uniqueness at time `t`: `1 / c_t` if `i`'s span contains +`t`, else `0`. -/ +noncomputable def uniqueness (t0 t1 : ι → ℝ) (t : ℝ) (i : ι) : ℝ := + (if t ∈ Set.Icc (t0 i) (t1 i) then (1 : ℝ) else 0) / concurrency t0 t1 t + +theorem one_le_concurrency (t0 t1 : ι → ℝ) {t : ℝ} {i : ι} + (hi : t ∈ Set.Icc (t0 i) (t1 i)) : 1 ≤ concurrency t0 t1 t := by + have h := Finset.single_le_sum + (f := fun j ↦ if t ∈ Set.Icc (t0 j) (t1 j) then (1 : ℝ) else 0) + (fun j _ ↦ by split <;> norm_num) (Finset.mem_univ i) + rwa [ite_eq_left hi] at h + +theorem concurrency_pos (t0 t1 : ι → ℝ) {t : ℝ} {i : ι} + (hi : t ∈ Set.Icc (t0 i) (t1 i)) : 0 < concurrency t0 t1 t := + zero_lt_one.trans_le (one_le_concurrency t0 t1 hi) + +/-- The headline bound: an observation whose span contains `t` has uniqueness +strictly positive and at most `1`. -/ +theorem uniqueness_mem_Ioc (t0 t1 : ι → ℝ) {t : ℝ} {i : ι} + (hi : t ∈ Set.Icc (t0 i) (t1 i)) : uniqueness t0 t1 t i ∈ Set.Ioc (0 : ℝ) 1 := by + have hpos := concurrency_pos t0 t1 hi + refine ⟨?_, ?_⟩ + · rw [uniqueness, ite_eq_left hi] + exact div_pos one_pos hpos + · rw [uniqueness, ite_eq_left hi, div_le_one hpos] + exact one_le_concurrency t0 t1 hi + +/-- **Concurrency of a pooled sample**: the labels of `ι ⊕ κ` active at `t` are those of `ι` +and those of `κ`, so the concurrencies add. -/ +theorem concurrency_sumElim {κ : Type*} [Fintype κ] (t0 t1 : ι → ℝ) (t0' t1' : κ → ℝ) + (t : ℝ) : + concurrency (Sum.elim t0 t0') (Sum.elim t1 t1') t = + concurrency t0 t1 t + concurrency t0' t1' t := by + unfold concurrency + rw [Fintype.sum_sum_type] + rfl + +end MathFin diff --git a/LeanPool/MathFin/Choice/Performance/PurgedCV.lean b/LeanPool/MathFin/Choice/Performance/PurgedCV.lean new file mode 100644 index 0000000000..e2b1f5d4c0 --- /dev/null +++ b/LeanPool/MathFin/Choice/Performance/PurgedCV.lean @@ -0,0 +1,192 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Performance.LabelUniqueness +public import Mathlib.Order.CompletePartialOrder +public import Mathlib.Probability.BrownianMotion.Basic + +/-! +# Purged train/test interval disjointness + +López de Prado (*Advances in Financial Machine Learning*, ch. 7) purges a +training interval `[t0 i, t1 i]` from a cross-validation fold whenever it +overlaps a test interval `[t0' j, t1' j]`: it starts inside the test interval, +ends inside it, or envelops it. This file states that three-way overlap +predicate literally as given (for times in any linear order) and proves the +combinatorial payoff: any training interval surviving purging against every +test interval is genuinely disjoint from each of them, and in fact ends +strictly before it starts or starts strictly after it ends. + +**Why purging works.** When each label is a measurable function of the increments +of a pre-Brownian motion over its own nonempty span (`IsSpanLabel`), a surviving training +label and any test label sit on separated spans, so the weak Markov property of +Brownian motion (`IsPreBrownianReal.indepFun_shift`: the increments after a time are +independent of the path before it) makes them independent +(`indepFun_of_purged`): no single test label carries information about a surviving +training label. The statement is pairwise; joint independence of the whole test +fold from the whole surviving training set is not proved. On the sample-weight side, +a surviving label's uniqueness (`Choice/Performance/LabelUniqueness.lean`) is the same +whether computed on the training sample alone or on the pooled sample +(`uniqueness_pooled_eq_of_purged`). + +## Main definitions + +* `overlapsTest`: the purge trigger, training interval `i` starts inside, ends inside, or + envelops test interval `j`. +* `IsSpanLabel`: a label determined by the increments of `X` over a span `[a, b]`. + +## Main results + +* `overlapsTest_of_mem_of_mem`: if some point lies in both a training and a test + interval, the overlap predicate holds between them (the interval-arithmetic + heart of the result). +* `purged_disjoint`: a training interval `i` purging leaves untouched (no + test interval triggers the overlap predicate against it) is disjoint from + every test interval. +* `lt_or_lt_of_not_overlapsTest`: for nonempty spans, surviving purging means the + two spans are strictly separated. +* `IsSpanLabel.indepFun_of_le`, `indepFun_of_purged`: labels determined by + the increments of a pre-Brownian motion over separated spans are independent; after + purging, every test label is independent of every surviving training label. +* `uniqueness_pooled_eq_of_purged`: purging keeps test labels out of a surviving training + label's uniqueness. + +## References + +* [I. Karatzas and S. E. Shreve, *Brownian Motion and Stochastic Calculus*][KaratzasShreve1991], + §2.1 +* [López de Prado, *Advances in Financial Machine Learning*][LopezDePrado2018], ch. 7, §7.4 + +## Tags + +purged cross-validation, overlapping labels, information leakage, weak Markov property, +López de Prado, time series validation, MSC 60J65, MSC 62M10, JEL C58 +-/ + +@[expose] public section + +namespace MathFin + +variable {ι κ T : Type*} [LinearOrder T] + +/-- The purge-trigger predicate: training interval `i` starts inside, ends +inside, or envelops test interval `j`. -/ +def overlapsTest (lo hi : ι → T) (lo' hi' : κ → T) (i : ι) (j : κ) : Prop := + (lo' j ≤ lo i ∧ lo i ≤ hi' j) ∨ (lo' j ≤ hi i ∧ hi i ≤ hi' j) ∨ (lo i ≤ lo' j ∧ hi' j ≤ hi i) + +/-- If a point lies in both intervals, the overlap predicate holds between +them: comparing `lo' j` with `lo i`, and then `hi i` with `hi' j`, picks which +of the three overlap cases applies. -/ +theorem overlapsTest_of_mem_of_mem (lo hi : ι → T) (lo' hi' : κ → T) {i : ι} {j : κ} {t : T} + (ht : t ∈ Set.Icc (lo i) (hi i)) (ht' : t ∈ Set.Icc (lo' j) (hi' j)) : + overlapsTest lo hi lo' hi' i j := by + obtain ⟨hlo, hhi⟩ := ht + obtain ⟨hlo', hhi'⟩ := ht' + rcases le_total (lo' j) (lo i) with h1 | h1 + · exact Or.inl ⟨h1, hlo.trans hhi'⟩ + · rcases le_total (hi i) (hi' j) with h2 | h2 + · exact Or.inr (Or.inl ⟨hlo'.trans hhi, h2⟩) + · exact Or.inr (Or.inr ⟨h1, h2⟩) + +/-- The disjointness invariant: a training interval `i` that no test interval +`j` triggers the purge predicate on is disjoint from every test interval. -/ +theorem purged_disjoint (lo hi : ι → T) (lo' hi' : κ → T) {i : ι} + (hret : ∀ j, ¬ overlapsTest lo hi lo' hi' i j) (j : κ) : + Disjoint (Set.Icc (lo i) (hi i)) (Set.Icc (lo' j) (hi' j)) := by + rw [Set.disjoint_left] + intro t ht ht' + exact hret j (overlapsTest_of_mem_of_mem lo hi lo' hi' ht ht') + +/-- **Surviving purging separates the spans strictly**: if training span `[lo i, hi i]` and +test span `[lo' j, hi' j]` are nonempty and do not trigger the overlap predicate, one ends +strictly before the other starts. (Otherwise `max (lo i) (lo' j)` lies in both.) -/ +theorem lt_or_lt_of_not_overlapsTest {lo hi : ι → T} {lo' hi' : κ → T} {i : ι} {j : κ} + (hspan : lo i ≤ hi i) (hspan' : lo' j ≤ hi' j) (h : ¬ overlapsTest lo hi lo' hi' i j) : + hi i < lo' j ∨ hi' j < lo i := by + by_contra! hc + exact h (overlapsTest_of_mem_of_mem lo hi lo' hi' (t := max (lo i) (lo' j)) + ⟨le_max_left _ _, max_le hspan hc.1⟩ ⟨le_max_right _ _, max_le hc.2 hspan'⟩) + +/-- **Purging keeps test labels out of a surviving training label's uniqueness.** If training +label `i` survives purging against every test label, then at every time `t` of its span no test +label is active, so its uniqueness computed on the pooled sample (training ⊕ test) equals its +uniqueness computed on the training sample alone. -/ +theorem uniqueness_pooled_eq_of_purged [Fintype ι] [Fintype κ] (lo hi : ι → ℝ) + (lo' hi' : κ → ℝ) {i : ι} (hret : ∀ j, ¬ overlapsTest lo hi lo' hi' i j) {t : ℝ} + (ht : t ∈ Set.Icc (lo i) (hi i)) : + uniqueness (Sum.elim lo lo') (Sum.elim hi hi') t (Sum.inl i) = uniqueness lo hi t i := by + have h0 : concurrency lo' hi' t = 0 := + Finset.sum_eq_zero fun j _ ↦ + ite_eq_right fun ht' ↦ hret j (overlapsTest_of_mem_of_mem lo hi lo' hi' ht ht') + unfold uniqueness + rw [concurrency_sumElim, h0, add_zero] + rfl + +section Brownian + +open MeasureTheory ProbabilityTheory +open scoped NNReal + +variable {Ω E E' : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + [MeasurableSpace E] [MeasurableSpace E'] + +/-- A label **determined by the increments of `X` over its span `[a, b]`**: a measurable +function of the increment family `(X u - X s)_{s, u ∈ [a, b]}`. For instance, with `X` the +log-price, López de Prado's fixed-horizon label (the sign of the return `X b - X a` over the +span) is of this form. -/ +def IsSpanLabel (X : ℝ≥0 → Ω → ℝ) (a b : ℝ≥0) (L : Ω → E) : Prop := + ∃ F : (Set.Icc a b × Set.Icc a b → ℝ) → E, Measurable F ∧ + L = fun ω ↦ F fun p ↦ X p.2 ω - X p.1 ω + +/-- **Labels on ordered spans of a pre-Brownian motion are independent.** If `L` is determined +by the increments of `B` over `[a, b]`, `L'` by those over `[c, d]`, and `b ≤ c`, then `L` and +`L'` are independent: `L` is a measurable function of the path up to time `c`, `L'` of the +increments after `c`, and these are independent by the weak Markov property +`IsPreBrownianReal.indepFun_shift`. -/ +theorem IsSpanLabel.indepFun_of_le {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B P) + {a b c d : ℝ≥0} (hbc : b ≤ c) {L : Ω → E} {L' : Ω → E'} + (hL : IsSpanLabel B a b L) (hL' : IsSpanLabel B c d L') : + IndepFun L L' P := by + obtain ⟨F, hF, rfl⟩ := hL + obtain ⟨G, hG, rfl⟩ := hL' + have hφ : Measurable fun x : Set.Iic c → ℝ ↦ + F fun p : Set.Icc a b × Set.Icc a b ↦ + x ⟨p.2, p.2.2.2.trans hbc⟩ - x ⟨p.1, p.1.2.2.trans hbc⟩ := + hF.comp (.of_eval fun _ ↦ (measurable_pi_apply _).sub (measurable_pi_apply _)) + have hψ : Measurable fun y : ℝ≥0 → ℝ ↦ + G fun p : Set.Icc c d × Set.Icc c d ↦ y (p.2 - c) - y (p.1 - c) := + hG.comp (.of_eval fun _ ↦ (measurable_pi_apply _).sub (measurable_pi_apply _)) + refine ((hB.indepFun_shift c).symm.comp hφ hψ).congr (ae_of_all _ fun ω ↦ rfl) + (ae_of_all _ fun ω ↦ ?_) + simp only [Function.comp_apply] + congr 1 + funext p + rw [add_tsub_cancel_of_le p.2.2.1, add_tsub_cancel_of_le p.1.2.1] + abel + +/-- **After purging, test labels are independent of surviving training labels.** Let every +label be determined by the increments of a pre-Brownian motion `B` over its own nonempty span +(`IsSpanLabel`). If training label `i` survives purging — no test span triggers the overlap +predicate against it — then it is independent of every test label `j`. The spans are strictly +separated (`lt_or_lt_of_not_overlapsTest`), and `IsSpanLabel.indepFun_of_le` applies in +whichever order they come. -/ +theorem indepFun_of_purged {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B P) + {lo hi : ι → ℝ≥0} {lo' hi' : κ → ℝ≥0} (hspan : ∀ i, lo i ≤ hi i) + (hspan' : ∀ j, lo' j ≤ hi' j) {L : ι → Ω → E} {L' : κ → Ω → E'} + (hL : ∀ i, IsSpanLabel B (lo i) (hi i) (L i)) + (hL' : ∀ j, IsSpanLabel B (lo' j) (hi' j) (L' j)) {i : ι} + (hret : ∀ j, ¬ overlapsTest lo hi lo' hi' i j) (j : κ) : + IndepFun (L i) (L' j) P := by + rcases lt_or_lt_of_not_overlapsTest (hspan i) (hspan' j) (hret j) with h | h + · exact (hL i).indepFun_of_le hB h.le (hL' j) + · exact ((hL' j).indepFun_of_le hB h.le (hL i)).symm + +end Brownian + +end MathFin diff --git a/LeanPool/MathFin/Choice/Performance/Ratios.lean b/LeanPool/MathFin/Choice/Performance/Ratios.lean new file mode 100644 index 0000000000..afd9ae3cd7 --- /dev/null +++ b/LeanPool/MathFin/Choice/Performance/Ratios.lean @@ -0,0 +1,204 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Basic.Real.Sign +public import Mathlib.Analysis.InnerProductSpace.Basic +public import Mathlib.Analysis.SpecialFunctions.Log.Deriv +public import Mathlib.Topology.Algebra.Module.ModuleTopology + +/-! +# Sharpe ratio and Kelly criterion + +Two classical performance and money-management identities: + +* **Sharpe ratio** `S(μ, r_f, σ) = (μ - r_f) / σ` measures excess return per unit + of risk. Under iid time aggregation, `L_T ~ N(T·μ, T·σ²)`, so the Sharpe ratio + scales as `√T`. +* **Kelly fraction** `f*(p, b) = (p·b - q) / b` (with `q = 1 - p`) is the + *critical point* (`g'(f*) = 0`, the first-order condition — what is proved + here as `kellyGrowth_deriv_at_kelly`) of the expected log-growth + `g(f) = p · log(1 + f·b) + q · log(1 - f)` under a binary bet with + win-probability `p` and payoff ratio `b`. It is the maximizer because `g` is + concave — concavity is not formalized here. + +## Main definitions + +* `sharpeRatio`: the Sharpe ratio `(μ − r_f) / σ`. +* `kellyFraction`: the Kelly fraction `f* = (p·b − (1 − p)) / b`. +* `kellyGrowth`: the expected log-growth of a binary bet at fraction `f`, + `p · log(1 + f·b) + (1 − p) · log(1 − f)`. + +## Main results + +* `sharpeRatio_scale_invariant`: `S(λμ, λr_f, λσ) = S(μ, r_f, σ)` for `λ ≠ 0`. +* `sharpeRatio_translation_invariant`: shift cancels in the excess return. +* `sharpeRatio_affine_invariant`: full affine invariance, scale + shift. +* `sharpeRatio_affine_signed`: with `|c|`-volatility convention, the Sharpe + ratio picks up `sign(c)` under `X ↦ c·X + d`. +* `sharpeRatio_scaleT`: `S_T = √T · S_1` for iid time aggregation. +* `kellyGrowth_deriv_at_kelly`: first-order optimality `g'(f*) = 0`. + +## References + +* [K. Bodie and Marcus, *Investments*][BodieKaneMarcus], Ch 10; Ch 5.5 +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], Ch 14 +* [J. L. Kelly, *A new interpretation of information rate*][Kelly1956] +* [Sharpe (1966)][Sharpe1966] +* [Thorp (2006)][Thorp2006] + +## Tags + +Sharpe ratio, Kelly criterion, excess return per risk, time aggregation, money management, +log-growth, MSC 91G10, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- **The "ratio scale invariance" algebraic master**: `(c·a − c·b) / (c·d) = +(a − b) / d` for `c ≠ 0`. + +The same identity drives the scale invariance of every "difference-over-stdev" +performance ratio: `Sharpe`, `Sortino`, `Treynor`, `Information ratio` are +all instances. Naming the algebraic fact factors the work — each ratio's +`*_scale_invariant` lemma is a one-line application. -/ +lemma diff_div_scale_invariant {c : ℝ} (hc : c ≠ 0) (a b d : ℝ) : + (c * a - c * b) / (c * d) = (a - b) / d := by + by_cases hd : d = 0 + · subst hd; simp + · field_simp + +/-- Sharpe ratio `(μ - r_f) / σ`. -/ +noncomputable def sharpeRatio (μ r_f σ : ℝ) : ℝ := (μ - r_f) / σ + +/-- **Scale invariance**: the Sharpe ratio is invariant under uniform scaling +of mean, risk-free rate, and volatility. One-line consequence of the +`diff_div_scale_invariant` master. -/ +lemma sharpeRatio_scale_invariant {c : ℝ} (hc : c ≠ 0) (μ r_f σ : ℝ) : + sharpeRatio (c * μ) (c * r_f) (c * σ) = sharpeRatio μ r_f σ := by + unfold sharpeRatio + exact diff_div_scale_invariant hc μ r_f σ + +/-- **The "affine ratio invariance" algebraic master**: the ratio +`(c·a + d − (c·b + d)) / (c·e)` collapses to `(a − b) / e` for `c ≠ 0`. +The shift `d` cancels in the numerator; the scale `c` cancels between +numerator and denominator. -/ +lemma diff_div_affine_invariant {c : ℝ} (hc : c ≠ 0) (a b d e : ℝ) : + (c * a + d - (c * b + d)) / (c * e) = (a - b) / e := by + rw [show c * a + d - (c * b + d) = c * a - c * b from by ring] + exact diff_div_scale_invariant hc a b e + +/-- **Signed affine invariance algebraic master**: when the denominator +scales as `|c|` (the natural scaling of a standard deviation under +`X ↦ c·X + d`, since `Var(cX + d) = c² · Var(X)`), the ratio picks up +`sign(c)`. -/ +lemma diff_div_affine_signed {c : ℝ} (hc : c ≠ 0) (a b d e : ℝ) : + (c * a + d - (c * b + d)) / (|c| * e) = Real.sign c * ((a - b) / e) := by + rw [show c * a + d - (c * b + d) = c * (a - b) from by ring] + by_cases he : e = 0 + · subst he; simp + · rcases lt_trichotomy c 0 with hc_neg | hc_zero | hc_pos + · rw [abs_of_neg hc_neg, Real.sign_of_neg hc_neg] + field_simp + · exact absurd hc_zero hc + · rw [abs_of_pos hc_pos, Real.sign_of_pos hc_pos] + field_simp + +/-- **Translation invariance of the Sharpe ratio**: shifting the mean and +risk-free rate by the same additive constant preserves `S = (μ − r_f)/σ`, +since the shift cancels in the excess return. -/ +lemma sharpeRatio_translation_invariant (μ r_f σ b : ℝ) : + sharpeRatio (μ + b) (r_f + b) σ = sharpeRatio μ r_f σ := by + unfold sharpeRatio; ring_nf + +/-- **Full affine invariance of the Sharpe ratio (signed-σ convention)**: +under the joint substitution `μ → c·μ + d`, `r_f → c·r_f + d`, `σ → c·σ`, +the Sharpe ratio is invariant for any `c ≠ 0`. The shift cancels in the +excess, and the scale cancels in the ratio. -/ +lemma sharpeRatio_affine_invariant {c : ℝ} (hc : c ≠ 0) (μ r_f σ d : ℝ) : + sharpeRatio (c * μ + d) (c * r_f + d) (c * σ) = sharpeRatio μ r_f σ := by + unfold sharpeRatio + exact diff_div_affine_invariant hc μ r_f d σ + +/-- **Sign-aware affine invariance** (natural `|c|`-volatility convention): +since `StDev(cX + d) = |c| · StDev(X)`, the Sharpe ratio under the joint +substitution flips sign when `c < 0`. -/ +lemma sharpeRatio_affine_signed {c : ℝ} (hc : c ≠ 0) (μ r_f σ d : ℝ) : + sharpeRatio (c * μ + d) (c * r_f + d) (|c| * σ) = + Real.sign c * sharpeRatio μ r_f σ := by + unfold sharpeRatio + exact diff_div_affine_signed hc μ r_f d σ + +/-- **Sharpe `√T`-scaling**: under iid time aggregation, `L_T ~ N(T·μ, T·σ²)`, +so the Sharpe ratio at horizon `T` equals `√T` times the unit-horizon Sharpe +ratio. -/ +lemma sharpeRatio_scaleT {μ r_f σ T : ℝ} (hT : 0 < T) (hσ : σ ≠ 0) : + sharpeRatio (T * μ) (T * r_f) (σ * Real.sqrt T) = + Real.sqrt T * sharpeRatio μ r_f σ := by + unfold sharpeRatio + have h_sqrtT_pos : 0 < Real.sqrt T := Real.sqrt_pos.mpr hT + have h_sqrtT_ne : Real.sqrt T ≠ 0 := h_sqrtT_pos.ne' + have h_T_eq : T = Real.sqrt T * Real.sqrt T := by + rw [← Real.sqrt_mul hT.le, Real.sqrt_mul_self hT.le] + -- Rewrite the LHS numerator using T = √T · √T + rw [show T * μ - T * r_f = + Real.sqrt T * Real.sqrt T * (μ - r_f) from by rw [← h_T_eq]; ring] + field_simp + +/-- Kelly fraction `f* = (p·b - q) / b`, where `q = 1 - p`. -/ +noncomputable def kellyFraction (p b : ℝ) : ℝ := (p * b - (1 - p)) / b + +/-- Expected log-growth of a binary bet at fraction `f`: +`p · log(1 + f·b) + (1 - p) · log(1 - f)`. -/ +noncomputable def kellyGrowth (p b f : ℝ) : ℝ := + p * Real.log (1 + f * b) + (1 - p) * Real.log (1 - f) + +/-- **Kelly first-order condition**: at the Kelly fraction `f* = (p·b − q)/b`, +the derivative of the expected log-growth vanishes. -/ +lemma kellyGrowth_deriv_at_kelly {p b : ℝ} + (hp : 0 < p) (hp1 : p < 1) (hb : 0 < b) : + HasDerivAt (fun f ↦ kellyGrowth p b f) 0 (kellyFraction p b) := by + unfold kellyGrowth kellyFraction + set f₀ : ℝ := (p * b - (1 - p)) / b with hf₀_def + have hb_ne : b ≠ 0 := hb.ne' + -- 1 + f₀·b = p·(b + 1) + have h_1_add : 1 + f₀ * b = p * (b + 1) := by + rw [hf₀_def]; field_simp; ring + -- 1 - f₀ = (1 - p)·(b + 1)/b + have h_1_sub : 1 - f₀ = (1 - p) * (b + 1) / b := by + rw [hf₀_def]; field_simp; ring + have h_b1_pos : 0 < b + 1 := by linarith + have h_q : 0 < 1 - p := by linarith + have h_1_add_pos : 0 < 1 + f₀ * b := by rw [h_1_add]; positivity + have h_1_add_ne : 1 + f₀ * b ≠ 0 := h_1_add_pos.ne' + have h_1_sub_pos : 0 < 1 - f₀ := by rw [h_1_sub]; positivity + have h_1_sub_ne : 1 - f₀ ≠ 0 := h_1_sub_pos.ne' + -- Derivative of f ↦ log(1 + f·b) at f₀: b / (1 + f₀·b) + have h1 : HasDerivAt (fun f ↦ Real.log (1 + f * b)) + (b / (1 + f₀ * b)) f₀ := by + have hbase : HasDerivAt (fun f : ℝ ↦ 1 + f * b) b f₀ := by + have := (hasDerivAt_id f₀).mul_const b + simpa using this.const_add 1 + simpa [div_eq_mul_inv] using hbase.log h_1_add_ne + -- Derivative of f ↦ log(1 - f) at f₀: -1 / (1 - f₀) + have h2 : HasDerivAt (fun f ↦ Real.log (1 - f)) + (-1 / (1 - f₀)) f₀ := by + have hbase : HasDerivAt (fun f : ℝ ↦ 1 - f) (-1) f₀ := by + simpa using (hasDerivAt_id f₀).const_sub 1 + simpa [div_eq_mul_inv] using hbase.log h_1_sub_ne + -- Combine + have h := (h1.const_mul p).add (h2.const_mul (1 - p)) + have h_bp_ne : b + 1 ≠ 0 := h_b1_pos.ne' + convert h using 1; rw [h_1_add, h_1_sub]; field_simp; ring + +end MathFin diff --git a/LeanPool/MathFin/Choice/Performance/RatiosExtended.lean b/LeanPool/MathFin/Choice/Performance/RatiosExtended.lean new file mode 100644 index 0000000000..5d9c58be7d --- /dev/null +++ b/LeanPool/MathFin/Choice/Performance/RatiosExtended.lean @@ -0,0 +1,230 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Performance.Ratios +public import LeanPool.MathFin.Choice.Portfolio.CAPM +public import Mathlib.Probability.Moments.Variance + +/-! +# Extended performance ratios: Sortino, Treynor, Information, gain-to-pain, upside capture + +Standard quant performance metrics beyond the basic Sharpe ratio: + +* **Sortino ratio** `S = (μ - target) / σ_down`, with `σ_down` the downside + semi-deviation. Like Sharpe but penalises only downside variation. +* **Treynor ratio** `T = (μ - r_f) / β`, with `β = Cov(R, R_m) / Var(R_m)` the + systematic risk. The market-model analogue of Sharpe. +* **Information ratio** `IR = (μ_p - μ_b) / σ_active`, with `σ_active` the + tracking error (std-dev of `R_p − R_b`). Measures active management skill. +* **Tracking error squared** `trackingErrorSq := σ_p² − 2·cov + σ_b²` — the + `Var(R_p − R_b)` expansion in terms of the input moments, tied to the variance of + the active return by `trackingErrorSq_eq_variance_sub`. + +Sortino, Treynor, and IR are all instances of `(a − b)/d`. Their +*scale-invariance* lemmas are one-line consequences of the algebraic master +`diff_div_scale_invariant` in `Choice.Performance.Ratios`. (The same master also +handles the Sharpe scale invariance — proving that the master is load-bearing +across all four ratios in the library.) + +The last two are *realised* ratios: they aggregate a return path over a finite +period set rather than combining summary moments. + +* **Gain-to-pain ratio** `(∑ r⁺) / (∑ r⁻)`, total gains over total losses + (Schwager). Written with Mathlib's positive/negative parts `r⁺ = max r 0`, + `r⁻ = max (-r) 0`, so `posPart_sub_negPart` supplies the decomposition + `∑ r⁺ − ∑ r⁻ = ∑ r` that turns "ratio ≥ 1" into "the period was profitable". +* **Upside-capture ratio** `(∑_{up} p) / (∑_{up} b)`, portfolio gains over + benchmark gains on the up-market periods (Morningstar). + +Both are quotients, and in Lean `x / 0 = 0`; the nonnegativity and homogeneity +statements below therefore need **no** nonvanishing side condition — the +degenerate no-loss / flat-benchmark case is covered by the same statement. The +one place a hypothesis is genuinely load-bearing is +`one_le_gainToPain_iff`, where `0 < ∑ r⁻` is what makes the quotient +comparable to `1` at all. + +## Main definitions + +* `sortinoRatio`: `(μ − target) / σ_down`, with `σ_down` the downside semi-deviation. +* `treynorRatio`: `(μ − r_f) / β`. +* `informationRatio`: `(μ_p − μ_b) / σ_active`, with `σ_active` the tracking error. +* `trackingErrorSq`: `σ_p² − 2·cov + σ_b²`. +* `gainToPain`: over a finite period set, the total of the positive parts of the returns over the + total of the negative parts. +* `upCapture`: over the up-market periods, the portfolio gains `∑ p` over the benchmark gains + `∑ b`. + +## Main results + +* `sortinoRatio_scale_invariant`, `sortinoRatio_translation`. +* `treynorRatio_scale_invariant`, `treynorRatio_eq_sharpeRatio_mul` (Treynor + is Sharpe rescaled by `σ / β`) and `treynorRatio_eq_of_jensenAlpha_eq_zero` (on the security + market line every asset has the market's Treynor ratio). +* `informationRatio_scale_invariant`. +* `trackingErrorSq_self`, `trackingErrorSq_ge_diff_sq`, + `trackingErrorSq_eq_variance_sub`. +* `gainToPain_nonneg`, `one_le_gainToPain_iff`. +* `upCapture_smul`. + +## References + +* [K. Bodie and Marcus, *Investments*][BodieKaneMarcus], Ch 10 +* [Grinold and Kahn, *Active Portfolio Management*][GrinoldKahn1999] +* [Sortino and van der Meer (1991)][SortinoVanDerMeer1991] +* [Treynor (1965)][Treynor1965] + +## Tags + +Sortino ratio, Treynor ratio, information ratio, tracking error, gain-to-pain ratio, upside capture, +performance attribution, MSC 91G10, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +open Real MeasureTheory ProbabilityTheory + +/-- **Sortino ratio** `(μ - target) / σ_down`. Inputs are the mean, the target +return, and the downside semi-deviation. -/ +noncomputable def sortinoRatio (μ target σ_down : ℝ) : ℝ := + (μ - target) / σ_down + +/-- Sortino is invariant under uniform rescaling. One-line consequence of +`diff_div_scale_invariant`. -/ +lemma sortinoRatio_scale_invariant {c : ℝ} (hc : c ≠ 0) + (μ target σ_down : ℝ) : + sortinoRatio (c * μ) (c * target) (c * σ_down) = + sortinoRatio μ target σ_down := by + unfold sortinoRatio + exact diff_div_scale_invariant hc μ target σ_down + +/-- Sortino is translation-invariant in the additive shift of both mean and +target. -/ +lemma sortinoRatio_translation (μ target σ_down shift : ℝ) : + sortinoRatio (μ + shift) (target + shift) σ_down = + sortinoRatio μ target σ_down := by + unfold sortinoRatio + ring_nf + +/-- **Treynor ratio** `(μ - r_f) / β`, with `β` the systematic-risk coefficient. -/ +noncomputable def treynorRatio (μ r_f β : ℝ) : ℝ := (μ - r_f) / β + +/-- Treynor is invariant under uniform rescaling. One-line consequence of +`diff_div_scale_invariant`. -/ +lemma treynorRatio_scale_invariant {c : ℝ} (hc : c ≠ 0) (μ r_f β : ℝ) : + treynorRatio (c * μ) (c * r_f) (c * β) = treynorRatio μ r_f β := by + unfold treynorRatio + exact diff_div_scale_invariant hc μ r_f β + +/-- **Treynor is Sharpe rescaled**: for a nonzero beta and a nonzero volatility `σ`, +`T = S · σ / β`, with `S = sharpeRatio μ r_f σ`. With `β = Cov(R, R_m) / Var(R_m)` +(`MathFin.beta`) and `σ = √Var(R)` the factor `σ / β` is `σ_m / ρ`, the market volatility over +the correlation. -/ +lemma treynorRatio_eq_sharpeRatio_mul {σ β : ℝ} (hσ : σ ≠ 0) (hβ : β ≠ 0) (μ r_f : ℝ) : + treynorRatio μ r_f β = sharpeRatio μ r_f σ * (σ / β) := by + unfold treynorRatio sharpeRatio + field_simp + +/-- **On the security market line every asset has the market's Treynor ratio**: if Jensen's alpha +vanishes (`MathFin.jensenAlpha`) and the beta is nonzero, the Treynor ratio of the asset is the +market risk premium `E[R_m] − r_f`. -/ +lemma treynorRatio_eq_of_jensenAlpha_eq_zero {eR rf β eRm : ℝ} + (h : jensenAlpha eR rf β eRm = 0) (hβ : β ≠ 0) : treynorRatio eR rf β = eRm - rf := by + rw [jensenAlpha_eq_zero_iff] at h + unfold treynorRatio + rw [h, securityMarketLine] + field_simp + ring + +/-- **Information ratio** `(μ_p - μ_b) / σ_active`, with `σ_active` the +tracking error. -/ +noncomputable def informationRatio (μ_p μ_b σ_active : ℝ) : ℝ := + (μ_p - μ_b) / σ_active + +/-- Information ratio is invariant under uniform rescaling. One-line +consequence of `diff_div_scale_invariant`. -/ +lemma informationRatio_scale_invariant {c : ℝ} (hc : c ≠ 0) + (μ_p μ_b σ_active : ℝ) : + informationRatio (c * μ_p) (c * μ_b) (c * σ_active) = + informationRatio μ_p μ_b σ_active := by + unfold informationRatio + exact diff_div_scale_invariant hc μ_p μ_b σ_active + +/-- **Tracking error squared**, defined as `σ_p² − 2·cov + σ_b²` — the +familiar expansion of `Var(R_p − R_b)` in terms of the input moments. Its inputs are bare +reals; `trackingErrorSq_eq_variance_sub` ties it to the variance of the active return. -/ +noncomputable def trackingErrorSq (σ_p σ_b cov : ℝ) : ℝ := + σ_p ^ 2 - 2 * cov + σ_b ^ 2 + +/-- **Tracking error squared is the variance of the active return**: for square-integrable +returns `R_p`, `R_b` of a portfolio and its benchmark, with `σ_p = √Var(R_p)`, +`σ_b = √Var(R_b)` and `cov = Cov(R_p, R_b)`, `trackingErrorSq σ_p σ_b cov = Var(R_p − R_b)`. +The tracking error `σ_active` of `informationRatio` is the square root of this. -/ +theorem trackingErrorSq_eq_variance_sub {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + [IsFiniteMeasure P] {R_p R_b : Ω → ℝ} (hp : MemLp R_p 2 P) (hb : MemLp R_b 2 P) : + trackingErrorSq √(Var[R_p; P]) √(Var[R_b; P]) cov[R_p, R_b; P] + = Var[fun ω ↦ R_p ω - R_b ω; P] := by + have h := variance_fun_add hp (hb.const_mul (-1)) + rw [variance_const_mul, covariance_const_mul_right] at h + rw [show (fun ω ↦ R_p ω - R_b ω) = fun ω ↦ R_p ω + -1 * R_b ω by ext; ring, h, + trackingErrorSq, Real.sq_sqrt (variance_nonneg _ _), Real.sq_sqrt (variance_nonneg _ _)] + ring + +/-- **Self-benchmark vanishing**: when the benchmark equals the portfolio +(`σ_p = σ_b` and `cov = σ_p²`), the tracking error vanishes. -/ +lemma trackingErrorSq_self (σ_p : ℝ) : + trackingErrorSq σ_p σ_p (σ_p ^ 2) = 0 := by + unfold trackingErrorSq + ring + +/-- **Tracking error non-negativity** when `cov ≤ σ_p · σ_b` (Cauchy-Schwarz +bound): `σ_active² ≥ (σ_p - σ_b)²`. -/ +lemma trackingErrorSq_ge_diff_sq (σ_p σ_b cov : ℝ) (h_cs : cov ≤ σ_p * σ_b) : + (σ_p - σ_b) ^ 2 ≤ trackingErrorSq σ_p σ_b cov := by + unfold trackingErrorSq + nlinarith [h_cs] + +variable {ι : Type*} + +/-- **Gain-to-pain ratio** over a finite period set `s` with returns `r`: total +gains `∑ r⁺` over total losses `∑ r⁻` (Schwager). -/ +noncomputable def gainToPain (s : Finset ι) (r : ι → ℝ) : ℝ := + (∑ i ∈ s, (r i)⁺) / (∑ i ∈ s, (r i)⁻) + +/-- **Gain-to-pain is nonnegative**: both legs are sums of positive/negative +parts. Unconditionally — with no losses the denominator is `0` and the ratio is +`0`, which the statement already covers. -/ +lemma gainToPain_nonneg (s : Finset ι) (r : ι → ℝ) : 0 ≤ gainToPain s r := + div_nonneg (Finset.sum_nonneg fun _ _ ↦ posPart_nonneg _) + (Finset.sum_nonneg fun _ _ ↦ negPart_nonneg _) + +/-- **Gain-to-pain exceeds one exactly on a profitable period set**: since +`r⁺ - r⁻ = r` summand-wise, `∑ r⁺ ≥ ∑ r⁻` says precisely `∑ r ≥ 0`. Here the +positive-pain hypothesis is load-bearing — it is what makes the quotient +comparable to `1`. -/ +lemma one_le_gainToPain_iff (s : Finset ι) (r : ι → ℝ) + (h : 0 < ∑ i ∈ s, (r i)⁻) : + 1 ≤ gainToPain s r ↔ 0 ≤ ∑ i ∈ s, r i := by + rw [gainToPain, one_le_div h, ← sub_nonneg, ← Finset.sum_sub_distrib] + simp [posPart_sub_negPart] + +/-- **Upside-capture ratio** over the up-market periods `up`: portfolio gains +`∑ p` over benchmark gains `∑ b` (Morningstar). -/ +noncomputable def upCapture (up : Finset ι) (p b : ι → ℝ) : ℝ := + (∑ i ∈ up, p i) / (∑ i ∈ up, b i) + +/-- **Upside capture is homogeneous of degree one in the portfolio leg**: the +scalar factors out of the numerator sum, and `mul_div_assoc` carries it past the +benchmark leg with no nonvanishing condition. -/ +lemma upCapture_smul (up : Finset ι) (p b : ι → ℝ) (c : ℝ) : + upCapture up (c • p) b = c * upCapture up p b := by + simp [upCapture, ← Finset.mul_sum, mul_div_assoc] + +end MathFin diff --git a/LeanPool/MathFin/Choice/Performance/RelativeDrawdown.lean b/LeanPool/MathFin/Choice/Performance/RelativeDrawdown.lean new file mode 100644 index 0000000000..996cf19880 --- /dev/null +++ b/LeanPool/MathFin/Choice/Performance/RelativeDrawdown.lean @@ -0,0 +1,92 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Performance.DownsideMetrics + +/-! +# Relative drawdown is scale invariant + +The **relative drawdown** of an equity curve `E` at time `t` is the fraction of the running +peak lost, `1 − E t / max_{s ≤ t} E s`. The running peak is Mathlib's `partialSups E`. + +`MathFin.maximumDrawdown` (`Choice/Performance/DownsideMetrics.lean`) measures the largest +*absolute* decline, and is positively homogeneous: scaling the curve by `c > 0` scales it by +`c` (`maximumDrawdown_scale`). The relative drawdown is instead *invariant* under +`E ↦ c E`: a fund ten times the size, run with the same strategy, has the same relative +drawdown at every date. This is why relative drawdown, not absolute drawdown, compares +portfolios of different sizes, or denominated in different currencies at a fixed conversion +rate. + +The identity holds for every `E`; the value is a drawdown fraction only where the running peak +is positive. + +## Main definitions + +* `relativeDrawdown`: `1 − E t / max_{s ≤ t} E s`, the fraction of the running peak lost by time + `t`, with the peak `partialSups E`. +* `maxRelativeDrawdown`: the largest relative drawdown at any `s ≤ t`. + +## Main results + +* `relativeDrawdown_const_mul`: for `c > 0`, the relative drawdown of `c E` equals that of `E`. +* `maxRelativeDrawdown_const_mul`: hence so does the maximum relative drawdown up to any time. +* `partialSups_mul_relativeDrawdown_le_maximumDrawdown`: on a finite path the two notions are + tied: the relative drawdown at `t`, scaled back up by the running peak `partialSups E t`, is + at most `maximumDrawdown E`. + +## References + +* [C. Bacon, *Practical Portfolio Performance Measurement and Attribution*][Bacon2008] +* [Young (1991)][Young1991] + +## Tags + +relative drawdown, running peak, scale invariance, equity curve, drawdown, MSC 91G10, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +variable {ι : Type*} [Preorder ι] [LocallyFiniteOrderBot ι] + +/-- Relative drawdown `1 − E t / max_{s ≤ t} E s` of an equity curve `E` at time `t`: the +fraction of the running peak lost by time `t`. It is a drawdown fraction only where +`partialSups E t > 0`; elsewhere the value is junk. -/ +noncomputable def relativeDrawdown (E : ι → ℝ) (t : ι) : ℝ := 1 - E t / partialSups E t + +/-- Maximum relative drawdown up to time `t`: the largest relative drawdown at any `s ≤ t`. -/ +noncomputable def maxRelativeDrawdown (E : ι → ℝ) (t : ι) : ℝ := + partialSups (relativeDrawdown E) t + +/-- **Relative drawdown is scale invariant**: scaling the equity curve by `c > 0` leaves the +relative drawdown unchanged at every time — unlike the absolute `maximumDrawdown`, which +scales by `c`. -/ +theorem relativeDrawdown_const_mul {c : ℝ} (hc : 0 < c) (E : ι → ℝ) : + relativeDrawdown (fun s ↦ c * E s) = relativeDrawdown E := by + funext t + simp only [relativeDrawdown, partialSups_const_mul₀ hc, mul_div_mul_left _ _ hc.ne'] + +/-- The maximum relative drawdown up to any time is scale invariant. -/ +theorem maxRelativeDrawdown_const_mul {c : ℝ} (hc : 0 < c) (E : ι → ℝ) : + maxRelativeDrawdown (fun s ↦ c * E s) = maxRelativeDrawdown E := + congrArg (fun f t ↦ partialSups f t) (relativeDrawdown_const_mul hc E) + +/-- **Relative drawdown, rescaled by the running peak, is bounded by the absolute maximum +drawdown**: for a nonzero running peak, `(max_{s ≤ t} E s) · relativeDrawdown E t` is the +absolute decline `max_{s ≤ t} E s − E t`, which `maximumDrawdown E` dominates. At a zero running +peak the left side is `0`, and `maximumDrawdown` is nonnegative. -/ +theorem partialSups_mul_relativeDrawdown_le_maximumDrawdown {n : ℕ} (E : Fin n → ℝ) + (t : Fin n) : partialSups E t * relativeDrawdown E t ≤ maximumDrawdown E := by + rcases eq_or_ne (partialSups E t) 0 with h | h + · simpa [h] using maximumDrawdown_nonneg E + rw [relativeDrawdown, mul_sub, mul_one, mul_div_cancel₀ _ h] + exact partialSups_sub_le_maximumDrawdown E t + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/BlackLitterman.lean b/LeanPool/MathFin/Choice/Portfolio/BlackLitterman.lean new file mode 100644 index 0000000000..11c75745fa --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/BlackLitterman.lean @@ -0,0 +1,105 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Tactic.Positivity.Basic -- shake: keep (positivity extensions) +public import Mathlib.Basic.Real.Basic +public import Mathlib.Tactic.FieldSimp +public import Mathlib.Tactic.Ring.RingNF + +/-! +# Black-Litterman one-dimensional Bayesian update + +In the Black-Litterman framework, expected returns `μ` are updated from a +prior `μ ~ N(π, τΣ)` by combining with views `P μ = Q + ε`, `ε ~ N(0, Ω)`. The +posterior is a precision-weighted Gaussian. In one dimension (single asset, +single view directly on `μ`) this reduces to the classical +Gaussian-conjugate update: + + `posterior_mean = (s1sq π + s0sq Q) / (s0sq + s1sq)`, + `posterior_var = s0sq s1sq / (s0sq + s1sq)`, + +where `s0sq` is the prior variance and `s1sq` the view's observation noise. The +result is the harmonic mean of variances; equivalently, the precision +(`1/σ²`) is additive. Both extreme limits behave correctly: + +* `s1sq → 0` (perfect view): posterior_mean → `Q`, +* `s1sq → ∞` (uninformative view): posterior_mean → `π`. + +## Main definitions + +* `posteriorMean1d`: the one-dimensional Black-Litterman posterior mean + `(s1sq·π + s0sq·Q) / (s0sq + s1sq)`. +* `posteriorVariance1d`: the posterior variance `s0sq·s1sq / (s0sq + s1sq)`. + +## Main results + +* `blackLitterman_mean_eq_precision_weighted`: for positive variances, equivalence of the + precision-weighted form with the symmetric form. +* `blackLitterman_var_eq_inv_sum_precision`: for positive variances, equivalence with the + inverse-sum-of-precisions form. + +## References + +* [Black and Litterman, *Global portfolio optimization*][BlackLitterman1992] + +## Tags + +Black-Litterman model, Bayesian update, posterior mean, investor views, precision weighting, +Gaussian conjugate, MSC 91G10, MSC 62F10, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +/-- One-dimensional Black-Litterman posterior mean. -/ +noncomputable def posteriorMean1d (π Q s0sq s1sq : ℝ) : ℝ := + (s1sq * π + s0sq * Q) / (s0sq + s1sq) + +/-- One-dimensional Black-Litterman posterior variance. -/ +noncomputable def posteriorVariance1d (s0sq s1sq : ℝ) : ℝ := + s0sq * s1sq / (s0sq + s1sq) + +/-- **Posterior mean is precision-weighted**: equivalence of the symmetric +form `(s1sqπ + s0sqQ)/(s0sq + s1sq)` with the standard precision-weighted form +`(π/s0sq + Q/s1sq)/(1/s0sq + 1/s1sq)`. -/ +theorem blackLitterman_mean_eq_precision_weighted + (π Q s0sq s1sq : ℝ) (h₀ : 0 < s0sq) (h₁ : 0 < s1sq) : + posteriorMean1d π Q s0sq s1sq = + (π / s0sq + Q / s1sq) / (1 / s0sq + 1 / s1sq) := by + unfold posteriorMean1d + have h₀_ne : s0sq ≠ 0 := h₀.ne' + have h₁_ne : s1sq ≠ 0 := h₁.ne' + have hsum : s0sq + s1sq ≠ 0 := by positivity + field_simp + ring + +/-- **Posterior variance is harmonic combination of inputs**: equivalence +`s0sqs1sq/(s0sq+s1sq) = 1/(1/s0sq + 1/s1sq)`, i.e. precision is additive. -/ +theorem blackLitterman_var_eq_inv_sum_precision + (s0sq s1sq : ℝ) (h₀ : 0 < s0sq) (h₁ : 0 < s1sq) : + posteriorVariance1d s0sq s1sq = 1 / (1 / s0sq + 1 / s1sq) := by + unfold posteriorVariance1d + have h₀_ne : s0sq ≠ 0 := h₀.ne' + have h₁_ne : s1sq ≠ 0 := h₁.ne' + field_simp + ring + +/-- **Convex combination form**: posterior mean lies between the prior `π` +and the view `Q`, with weights `λ := s0sq/(s0sq+s1sq)` and `1−λ`. -/ +theorem blackLitterman_mean_convex_combination + (π Q s0sq s1sq : ℝ) (h_sum : s0sq + s1sq ≠ 0) : + posteriorMean1d π Q s0sq s1sq = + (1 - s0sq / (s0sq + s1sq)) * π + (s0sq / (s0sq + s1sq)) * Q := by + unfold posteriorMean1d + field_simp + ring + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/BlackLittermanND.lean b/LeanPool/MathFin/Choice/Portfolio/BlackLittermanND.lean new file mode 100644 index 0000000000..54dfdd8f3b --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/BlackLittermanND.lean @@ -0,0 +1,264 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Portfolio.BlackLitterman +public import LeanPool.MathFin.Choice.Portfolio.ConvexQPKKT +public import Mathlib.Logic.Equiv.PartialEquiv + +/-! +# N-dimensional Black-Litterman posterior (matrix form) + +The pre-existing `Choice/Portfolio/BlackLitterman.lean` derives the 1-D Bayesian +update for a single asset with a single direct view. This file extends to +the **N-asset / m-view matrix** formulation, the standard form used in +production. + +## Setup + +* `π : Fin n → ℝ` — prior mean of expected returns. +* `Sg_inv : Matrix (Fin n) (Fin n) ℝ` — prior *precision* (inverse covariance). +* `Q : Fin m → ℝ` — view vector (target values). +* `P : Matrix (Fin m) (Fin n) ℝ` — view-selection matrix (which linear + combinations of `μ` the views talk about). +* `Om_inv : Matrix (Fin m) (Fin m) ℝ` — view *precision* (inverse covariance + of view noise). + +## Posterior identities + +In the Gaussian prior/view model, the Bayesian-conjugate update gives + + `posterior_precision = Sg_inv + Pᵀ · Om_inv · P`, (additive precision) + `posterior_precision · μ_post = Sg_inv · π + Pᵀ · Om_inv · Q`. (normal equation) + +The Gaussian conditioning behind these identities is not formalized: this file takes +the normal equation as the definition of the posterior mean (`IsBLPosteriorMean`). +When posterior precision is invertible, the posterior mean has the explicit +form + + `μ_post = (posterior_precision)⁻¹ · (Sg_inv · π + Pᵀ · Om_inv · Q)`. + +This file proves: (a) the explicit form satisfies the normal equation, +(b) the solution to the normal equation is *unique* (when precision is +invertible), and (c) for positive semidefinite precisions, every solution of the +normal equation minimises the **mixed-estimation loss** of Theil and Goldberger, + + `½ (μ − π)ᵀ Sg_inv (μ − π) + ½ (Pμ − Q)ᵀ Om_inv (Pμ − Q)`, + +the generalized-least-squares fit of `μ` to the prior and the views together — by +the KKT sufficiency theorem of `Choice/Portfolio/ConvexQPKKT.lean` with no constraints. + +## Characterisations + +The 1-D `BlackLitterman.lean` stated the posterior as a closed form and +verified three equivalent forms (symmetric, precision-weighted, harmonic- +variance). This file characterises the N-dim posterior as the **unique solution +of a linear system** — the natural way to characterise it without ad-hoc +inverses, and the way it is used in practice (LU/Cholesky solve rather +than explicit inversion) — and as a **minimiser of the mixed-estimation loss**. + +## Connection to the 1-D module + +At `n = 1`, `m = 1`, `P = (1)`, `Sg_inv = (1/s0sq)`, `Om_inv = (1/s1sq)` the +normal equation below reduces to the scalar Bayesian update behind +`posteriorMean1d` (`Choice/Portfolio/BlackLitterman.lean`); `isBLPosteriorMean_one_dim` +makes this precise (the scalar `posteriorMean1d` is the BL posterior mean at +`n = 1`), and the matrix form here is its N-asset generalisation. + +## Main definitions + +* `blPosteriorPrecision`: the posterior precision `Sg_inv + Pᵀ·Om_inv·P`. +* `blPrecisionWeightedMean`: the right-hand side `Sg_inv·π + Pᵀ·Om_inv·Q` of the normal equation. +* `IsBLPosteriorMean`: `μ_post` solves the Black-Litterman normal equation. +* `blPosteriorMean`: the explicit solution, the inverse of the posterior precision applied to + the precision-weighted mean (when the posterior precision is invertible). +* `blLoss`: the Theil-Goldberger mixed-estimation loss, half the prior-precision-weighted squared + distance from `π` plus half the view-precision-weighted squared distance of `P·μ` from `Q`. + +## Main results + +* `blPosteriorMean_satisfies_normal_eq`: when the posterior precision is invertible, the explicit + form `blPosteriorMean` satisfies the normal equation `IsBLPosteriorMean`. +* `IsBLPosteriorMean.unique`: solution to the normal equation is unique + (when posterior precision is invertible); dot-notation `h.unique`. +* `blLoss_eq_qpObj`: for symmetric `Sg_inv` and `Om_inv`, the mixed-estimation loss `blLoss` is + the convex QP objective `qpObj` with Hessian the posterior precision, up to a constant. +* `IsBLPosteriorMean.blLoss_le`: a solution of the normal equation minimises `blLoss` + when `Sg_inv` and `Om_inv` are positive semidefinite. + +## References + +* [Black and Litterman, *Global portfolio optimization*][BlackLitterman1992] +* [Theil and Goldberger, *On pure and mixed statistical estimation in + economics*][TheilGoldberger1961] + +## Tags + +Black-Litterman model, posterior precision, mixed estimation, Theil-Goldberger, normal equation, +investor views, generalized least squares, MSC 91G10, MSC 62F10, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +open Matrix + +/-- **N-dim BL posterior precision**: additive Bayesian update of precision. +`posterior_precision = prior_precision + view_precision`, where the view +precision is `Pᵀ · Om_inv · P` (the information about `μ` provided by the +linear views). -/ +def blPosteriorPrecision {n m : ℕ} + (Sg_inv : Matrix (Fin n) (Fin n) ℝ) + (P : Matrix (Fin m) (Fin n) ℝ) + (Om_inv : Matrix (Fin m) (Fin m) ℝ) : + Matrix (Fin n) (Fin n) ℝ := + Sg_inv + Pᵀ * Om_inv * P + +/-- **N-dim BL precision-weighted mean RHS**: `Sg_inv · π + Pᵀ · Om_inv · Q`. +This is the RHS of the BL normal equation. -/ +def blPrecisionWeightedMean {n m : ℕ} + (π : Fin n → ℝ) (Q : Fin m → ℝ) + (Sg_inv : Matrix (Fin n) (Fin n) ℝ) + (P : Matrix (Fin m) (Fin n) ℝ) + (Om_inv : Matrix (Fin m) (Fin m) ℝ) : + Fin n → ℝ := + Sg_inv *ᵥ π + (Pᵀ * Om_inv) *ᵥ Q + +/-- **N-dim BL posterior mean as the normal-equation solution** (variational +characterisation). A vector `μ_post : Fin n → ℝ` is a BL posterior mean iff +it satisfies + + `(Sg_inv + Pᵀ · Om_inv · P) · μ_post = Sg_inv · π + Pᵀ · Om_inv · Q`. + +This characterisation does not require the precision to be invertible — it +is well-defined for any precision (the existence of a solution requires +the RHS to be in the column span of the LHS; uniqueness requires +invertibility). -/ +def IsBLPosteriorMean {n m : ℕ} + (μ_post π : Fin n → ℝ) (Q : Fin m → ℝ) + (Sg_inv : Matrix (Fin n) (Fin n) ℝ) + (P : Matrix (Fin m) (Fin n) ℝ) + (Om_inv : Matrix (Fin m) (Fin m) ℝ) : Prop := + (blPosteriorPrecision Sg_inv P Om_inv).mulVec μ_post = + blPrecisionWeightedMean π Q Sg_inv P Om_inv + +/-- **Explicit form of the N-dim BL posterior mean** (when posterior +precision is invertible): apply the inverse to the precision-weighted mean. -/ +noncomputable def blPosteriorMean {n m : ℕ} + (π : Fin n → ℝ) (Q : Fin m → ℝ) + (Sg_inv : Matrix (Fin n) (Fin n) ℝ) + (P : Matrix (Fin m) (Fin n) ℝ) + (Om_inv : Matrix (Fin m) (Fin m) ℝ) : + Fin n → ℝ := + (blPosteriorPrecision Sg_inv P Om_inv)⁻¹ *ᵥ + blPrecisionWeightedMean π Q Sg_inv P Om_inv + +/-- **Explicit form satisfies the normal equation** (when posterior precision +is invertible). -/ +theorem blPosteriorMean_satisfies_normal_eq {n m : ℕ} + (π : Fin n → ℝ) (Q : Fin m → ℝ) + (Sg_inv : Matrix (Fin n) (Fin n) ℝ) + (P : Matrix (Fin m) (Fin n) ℝ) + (Om_inv : Matrix (Fin m) (Fin m) ℝ) + [Invertible (blPosteriorPrecision Sg_inv P Om_inv)] : + IsBLPosteriorMean (blPosteriorMean π Q Sg_inv P Om_inv) π Q Sg_inv P Om_inv := by + unfold IsBLPosteriorMean blPosteriorMean + rw [Matrix.mulVec_mulVec] + rw [Matrix.mul_inv_of_invertible] + rw [Matrix.one_mulVec] + +/-- **Uniqueness of the BL posterior mean** (when posterior precision is +invertible): any solution to the normal equation equals the explicit form. -/ +theorem IsBLPosteriorMean.unique {n m : ℕ} + {μ_post π : Fin n → ℝ} {Q : Fin m → ℝ} + {Sg_inv : Matrix (Fin n) (Fin n) ℝ} + {P : Matrix (Fin m) (Fin n) ℝ} + {Om_inv : Matrix (Fin m) (Fin m) ℝ} + [Invertible (blPosteriorPrecision Sg_inv P Om_inv)] + (h : IsBLPosteriorMean μ_post π Q Sg_inv P Om_inv) : + μ_post = blPosteriorMean π Q Sg_inv P Om_inv := by + unfold IsBLPosteriorMean at h + unfold blPosteriorMean + rw [← h] + rw [Matrix.mulVec_mulVec] + rw [Matrix.inv_mul_of_invertible] + rw [Matrix.one_mulVec] + +/-- **n = 1 recovers the scalar posterior**: at `n = m = 1`, `P = 1`, +`Sg_inv = (1/s0sq)`, `Om_inv = (1/s1sq)`, the scalar `posteriorMean1d` is the +BL posterior mean — the 1-D case of the matrix normal equation, showing the +N-asset form specialises to `Choice/Portfolio/BlackLitterman`. -/ +theorem isBLPosteriorMean_one_dim (π₀ Q₀ s0sq s1sq : ℝ) (h₀ : 0 < s0sq) (h₁ : 0 < s1sq) : + IsBLPosteriorMean ![posteriorMean1d π₀ Q₀ s0sq s1sq] ![π₀] ![Q₀] + (!![1 / s0sq]) (1 : Matrix (Fin 1) (Fin 1) ℝ) (!![1 / s1sq]) := by + have h₀' : s0sq ≠ 0 := h₀.ne' + have h₁' : s1sq ≠ 0 := h₁.ne' + unfold IsBLPosteriorMean blPosteriorPrecision blPrecisionWeightedMean posteriorMean1d + funext i + fin_cases i + simp [Matrix.mulVec, dotProduct, Matrix.add_apply, Matrix.transpose_one, + Matrix.cons_val_fin_one, Matrix.of_apply] + field_simp + ring + +/-- **Black–Litterman mixed-estimation loss** (Theil–Goldberger): half the +prior-precision-weighted squared distance of `μ` from the prior mean `π`, plus half the +view-precision-weighted squared residual of the views `P μ − Q`. -/ +noncomputable def blLoss {n m : ℕ} (π : Fin n → ℝ) (Q : Fin m → ℝ) + (Sg_inv : Matrix (Fin n) (Fin n) ℝ) (P : Matrix (Fin m) (Fin n) ℝ) + (Om_inv : Matrix (Fin m) (Fin m) ℝ) (μ : Fin n → ℝ) : ℝ := + (1 / 2) * ((μ - π) ⬝ᵥ (Sg_inv *ᵥ (μ - π))) + + (1 / 2) * ((P *ᵥ μ - Q) ⬝ᵥ (Om_inv *ᵥ (P *ᵥ μ - Q))) + +/-- For symmetric precisions, the mixed-estimation loss is the convex QP objective +`qpObj` with linear term `−(Sg_inv π + Pᵀ Om_inv Q)` and Hessian the posterior precision +`Sg_inv + Pᵀ Om_inv P`, plus a constant: expanding the two quadratics, the cross terms +are collected by symmetry and `(Pμ) ⬝ (Om_inv x) = μ ⬝ (Pᵀ Om_inv x)`. -/ +lemma blLoss_eq_qpObj {n m : ℕ} (π : Fin n → ℝ) (Q : Fin m → ℝ) + {Sg_inv : Matrix (Fin n) (Fin n) ℝ} (hS : Sg_inv.IsSymm) (P : Matrix (Fin m) (Fin n) ℝ) + {Om_inv : Matrix (Fin m) (Fin m) ℝ} (hO : Om_inv.IsSymm) (μ : Fin n → ℝ) : + blLoss π Q Sg_inv P Om_inv μ = + qpObj (-blPrecisionWeightedMean π Q Sg_inv P Om_inv) + (blPosteriorPrecision Sg_inv P Om_inv) μ + + ((1 / 2) * (π ⬝ᵥ (Sg_inv *ᵥ π)) + (1 / 2) * (Q ⬝ᵥ (Om_inv *ᵥ Q))) := by + have hPOP : (P *ᵥ μ) ⬝ᵥ (Om_inv *ᵥ (P *ᵥ μ)) = μ ⬝ᵥ ((Pᵀ * Om_inv * P) *ᵥ μ) := by + rw [← mulVec_mulVec, ← mulVec_mulVec, dotProduct_mulVec μ Pᵀ, vecMul_transpose] + have hPOQ : (P *ᵥ μ) ⬝ᵥ (Om_inv *ᵥ Q) = ((Pᵀ * Om_inv) *ᵥ Q) ⬝ᵥ μ := by + rw [← mulVec_mulVec, dotProduct_comm _ μ, dotProduct_mulVec μ Pᵀ, vecMul_transpose] + simp only [blLoss, qpObj, blPrecisionWeightedMean, blPosteriorPrecision, mulVec_sub, + sub_dotProduct, dotProduct_sub, add_mulVec, dotProduct_add, add_dotProduct, neg_dotProduct] + rw [dotProduct_mulVec_symm_comm hO Q (P *ᵥ μ), hPOQ, hPOP, + dotProduct_mulVec_symm_comm hS π μ, dotProduct_comm (Sg_inv *ᵥ π) μ] + ring + +/-- **The Black–Litterman posterior mean minimises the mixed-estimation loss.** If +`μ_post` solves the normal equation and the prior and view precisions are positive +semidefinite, then `blLoss μ_post ≤ blLoss μ` for every `μ`: the posterior mean is the +generalized-least-squares fit of `μ` to the prior and the views (Theil–Goldberger mixed +estimation). Proof: `blLoss_eq_qpObj` and the unconstrained case (`κ = Fin 0`) of +`kkt_sufficient_of_eq`, whose stationarity condition is the normal equation; the +posterior precision `Sg_inv + Pᵀ Om_inv P` is positive semidefinite as a sum of +positive semidefinite matrices. -/ +theorem IsBLPosteriorMean.blLoss_le {n m : ℕ} {μ_post π : Fin n → ℝ} {Q : Fin m → ℝ} + {Sg_inv : Matrix (Fin n) (Fin n) ℝ} {P : Matrix (Fin m) (Fin n) ℝ} + {Om_inv : Matrix (Fin m) (Fin m) ℝ} (h : IsBLPosteriorMean μ_post π Q Sg_inv P Om_inv) + (hS : Sg_inv.PosSemidef) (hO : Om_inv.PosSemidef) (μ : Fin n → ℝ) : + blLoss π Q Sg_inv P Om_inv μ_post ≤ blLoss π Q Sg_inv P Om_inv μ := by + have hS' : Sg_inv.IsSymm := isHermitian_iff_isSymm.mp hS.isHermitian + have hO' : Om_inv.IsSymm := isHermitian_iff_isSymm.mp hO.isHermitian + have hA : (blPosteriorPrecision Sg_inv P Om_inv).PosSemidef := by + simpa [blPosteriorPrecision, conjTranspose_eq_transpose_of_trivial] using + hS.add (hO.conjTranspose_mul_mul_same P) + rw [blLoss_eq_qpObj π Q hS' P hO', blLoss_eq_qpObj π Q hS' P hO', add_le_add_iff_right] + refine kkt_sufficient_of_eq (a := fun _ : Fin 0 ↦ 0) (b := fun _ ↦ 0) (ν := fun _ ↦ 0) hA + (fun k ↦ k.elim0) ?_ μ fun k ↦ k.elim0 + simp only [Finset.univ_eq_empty, Finset.sum_empty, neg_add_eq_zero] + exact Eq.symm h + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/CAPM.lean b/LeanPool/MathFin/Choice/Portfolio/CAPM.lean new file mode 100644 index 0000000000..69f340db73 --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/CAPM.lean @@ -0,0 +1,114 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.BigOperators.Field +public import Mathlib.Basic.Real.Basic +public import Mathlib.Tactic.FieldSimp + +/-! +# Capital Asset Pricing Model (CAPM) + +CAPM at the algebraic / definitional level. Returns are modelled by their first +two moments (`E[R_i]`, `Cov(R_i, R_M)`, `Var(R_M)`) — the same primitives used +in the Markowitz file. This is the standard textbook treatment. + +## Main definitions + +* `beta`: the CAPM beta `Cov(R, R_M) / Var(R_M)`, defined as a ratio of its two inputs. +* `securityMarketLine`: `R_f + β (E[R_M] − R_f)`. +* `jensenAlpha`: the excess of the expected return over the security market line, + `E[R] − (R_f + β (E[R_M] − R_f))`. + +## Main results + +* `jensenAlpha_eq_zero_iff`: the CAPM pricing identity `E[R_i] = SML` ↔ `α_i = 0` + (Mathlib's `sub_eq_zero`). +* `beta_linearity_two` / `beta_linearity_finset`: a portfolio's beta is the + weighted sum of its components' betas, `β_p = ∑ w_i β_i`, by bilinearity of + covariance (axiomatized at the algebraic level). +* `beta_market`: the market's beta is `1` (for nonzero market variance). +* `beta_of_riskFree`: the risk-free asset's beta is `0` (zero covariance with the market). + +## References + +* [K. Bodie and Marcus, *Investments*][BodieKaneMarcus], Ch 9.3 +* [Sharpe, *Capital asset prices*][Sharpe1964] + +## Tags + +capital asset pricing model, security market line, beta, Jensen's alpha, systematic risk, MSC 91G10, +JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +/-- CAPM beta: `β = Cov(R, R_M) / Var(R_M)`. Defined algebraically as a ratio. -/ +noncomputable def beta (covRRm varRm : ℝ) : ℝ := covRRm / varRm + +/-- Security Market Line: the CAPM equilibrium expected return as a function of beta. -/ +noncomputable def securityMarketLine (rf β eRm : ℝ) : ℝ := rf + β * (eRm - rf) + +/-- **Jensen's alpha**: the excess of the expected return over the SML +prediction, `α = E[R] − (R_f + β (E[R_M] − R_f))`. The CAPM pricing +identity is precisely `α = 0`. -/ +noncomputable def jensenAlpha (eR rf β eRm : ℝ) : ℝ := + eR - securityMarketLine rf β eRm + +/-- The CAPM pricing identity `E[R] = R_f + β (E[R_M] − R_f)` holds iff +Jensen's alpha vanishes — Mathlib's `sub_eq_zero` through the `jensenAlpha` +definition. -/ +lemma jensenAlpha_eq_zero_iff (eR rf β eRm : ℝ) : + jensenAlpha eR rf β eRm = 0 ↔ eR = securityMarketLine rf β eRm := + sub_eq_zero + +/-- A risk-free asset (zero covariance with the market) has beta zero. -/ +lemma beta_of_riskFree (varRm : ℝ) : + beta 0 varRm = 0 := by + unfold beta + exact zero_div varRm + +/-- The market portfolio's beta is one: when `R_i = R_M`, `Cov(R_M, R_M) = Var(R_M)` +so `β_M = 1`. -/ +lemma beta_market {varRm : ℝ} (hVar : varRm ≠ 0) : + beta varRm varRm = 1 := by + unfold beta + exact div_self hVar + +/-- **Beta linearity** for a two-asset portfolio: the portfolio's beta is the +weight-sum of the component betas. + +For a portfolio `R_p = w_1 R_1 + w_2 R_2`, bilinearity of covariance gives +`Cov(R_p, R_M) = w_1 Cov(R_1, R_M) + w_2 Cov(R_2, R_M)`, so dividing by +`Var(R_M)` yields the result. -/ +lemma beta_linearity_two + {varRm : ℝ} (hVar : varRm ≠ 0) + (w₁ w₂ covR₁Rm covR₂Rm : ℝ) : + beta (w₁ * covR₁Rm + w₂ * covR₂Rm) varRm = + w₁ * beta covR₁Rm varRm + w₂ * beta covR₂Rm varRm := by + unfold beta + field_simp + +/-- **Beta linearity** for a finite-index portfolio: the portfolio's beta is the +weight-sum of the component betas. + +For weights `w : ι → ℝ` and component covariances `c : ι → ℝ`, bilinearity of +covariance gives `Cov(∑ w_i R_i, R_M) = ∑ w_i Cov(R_i, R_M)`. -/ +lemma beta_linearity_finset + {ι : Type*} (s : Finset ι) (w c : ι → ℝ) (varRm : ℝ) : + beta (∑ i ∈ s, w i * c i) varRm = ∑ i ∈ s, w i * beta (c i) varRm := by + unfold beta + rw [Finset.sum_div] + refine Finset.sum_congr rfl ?_ + intro i _ + rw [mul_div_assoc] + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/CAPMEquilibrium.lean b/LeanPool/MathFin/Choice/Portfolio/CAPMEquilibrium.lean new file mode 100644 index 0000000000..9f8bf9e5a2 --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/CAPMEquilibrium.lean @@ -0,0 +1,191 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Portfolio.CAPM +public import LeanPool.MathFin.Choice.Portfolio.MarkowitzNAsset + +/-! +# CAPM from market equilibrium (first-principles derivation) + +The pre-existing `Choice.Portfolio.CAPM` defines `β_i = Cov(R_i, R_M) / Var(R_M)` +and the Security Market Line `SML(β) = R_f + β (E[R_M] − R_f)`, and proves +that the CAPM pricing identity `E[R_i] = SML(β_i)` is equivalent to `α_i = 0`. +It treats CAPM as a definitional algebraic statement. + +This file closes the equilibrium-derivation gap. CAPM is *derived* from the +fact that the market portfolio satisfies the tangent-portfolio cross-product +FOC (i.e., in equilibrium, every investor holds the tangent portfolio, so +aggregating gives the market portfolio = tangent portfolio). + +## Setup + +* `s : Finset ι` — assets in the universe. +* `w_M : ι → ℝ` — market portfolio weights. +* `μ_excess : ι → ℝ` — excess expected returns (over the risk-free rate). +* `Sg : ι → ι → ℝ` — covariance matrix. +* `marginalVariance` — `(Σw)_i = ∑_k Sg(i,k) · w(k)` (= `Cov(R_i, R_M)`). +* `portfolioVarN_eq_sum_mul_marginalVariance` — `Var(R_M) = w_M · (Σw_M)`. +* `portfolioReturn` — `μ_M = w_M · μ_excess` (market excess return). + +## The equilibrium hypothesis + +`h_FOC`: `∀ j k ∈ s, μ_excess(k) · (Σw_M)_j = μ_excess(j) · (Σw_M)_k`. + +This is exactly the tangent-portfolio cross-product FOC `IsTangentPortfolioN` +from `Choice.Portfolio.TangentPortfolio`, evaluated at `w = w_M`. The economic +content: in equilibrium, the market portfolio satisfies the tangent FOC. + +## The CAPM identity (derived, not assumed) + +`theorem CAPM_from_market_equilibrium`: + + `μ_excess(i) = β_i · μ_excess(M)`, + +where `β_i = (Σw_M)_i / Var(R_M)`. This is the *operational* form of CAPM: +an asset's expected excess return is its beta times the market's expected +excess return. + +## Why this is "first principles" + +Existing CAPM library content stated the SML and proved consistency +relations (`jensenAlpha_eq_zero_iff`, beta linearity). It did +not derive the SML from a market-equilibrium argument. This file does: +given the equilibrium hypothesis (`h_FOC`, which itself follows from +optimal portfolio choice via `Choice.Portfolio.TangentPortfolio`), the CAPM +pricing identity is a *consequence*, not a definition. + +## Main definitions + +* `marginalVariance`: the marginal variance contribution `(Σw)_i = ∑_k Sg(i, k)·w(k)`. +* `portfolioVarN_eq_sum_mul_marginalVariance`: the portfolio variance `portfolioVarN` is `w · (Σw)`. +* `portfolioReturn`: `w · μ = ∑_i w(i)·μ(i)`. + +## Main results + +* `CAPM_from_market_equilibrium`: if `w_M` satisfies the tangent-portfolio cross-product + condition `μ_excess k · (Σw_M)_j = μ_excess j · (Σw_M)_k` on `s` and its variance is nonzero, + then `μ_excess i = ((Σw_M)_i / Var(R_M)) · μ_M`. +* `expectedReturn_eq_SML_from_equilibrium`: with weights summing to one, the same condition for + `μ − r_f` gives `μ i = securityMarketLine r_f β_i (∑ w_M k · μ k)` with + `β_i = (Σw_M)_i / Var(R_M)`. + +## Tags + +capital asset pricing model, market equilibrium, tangent portfolio, security market line, +market portfolio, beta pricing, MSC 91G10, JEL G12, JEL D53 +-/ + +@[expose] public section + +namespace MathFin + +/-- Marginal variance contribution of asset `i` in portfolio `w` under +covariance matrix `Sg`: `(Σw)_i = ∑_k Sg(i,k) · w(k)`. For the market +portfolio this equals `Cov(R_i, R_M)`. -/ +def marginalVariance {ι : Type*} (s : Finset ι) (Sg : ι → ι → ℝ) + (w : ι → ℝ) (i : ι) : ℝ := + ∑ k ∈ s, Sg i k * w k + +/-- **The portfolio variance is `w · (Σw)`**: the Markowitz double sum `portfolioVarN` +is `∑ₖ wₖ (Σw)ₖ`, the `w`-weighted sum of the marginal variances. -/ +lemma portfolioVarN_eq_sum_mul_marginalVariance {ι : Type*} (s : Finset ι) (Sg : ι → ι → ℝ) + (w : ι → ℝ) : portfolioVarN s w Sg = ∑ k ∈ s, w k * marginalVariance s Sg w k := by + unfold portfolioVarN marginalVariance + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [Finset.mul_sum] + exact Finset.sum_congr rfl fun j _ ↦ by ring + +/-- Portfolio expected return: `μ_w = w · μ = ∑_i w(i) · μ(i)`. -/ +def portfolioReturn {ι : Type*} (s : Finset ι) (w μ : ι → ℝ) : ℝ := + ∑ k ∈ s, w k * μ k + +/-- **CAPM from market equilibrium**: under the equilibrium hypothesis that +the market portfolio satisfies the tangent-portfolio cross-product FOC, +every asset's excess return is its beta times the market excess return. + +The proof is a discrete-Lagrangian argument: + +1. From `h_FOC i j` (with `i` fixed): `μ_excess(j) · (Σw_M)_i = μ_excess(i) · (Σw_M)_j`. +2. Multiply both sides by `w_M(j)` and sum over `j ∈ s`. +3. LHS becomes `(∑_j w_M(j) μ_excess(j)) · (Σw_M)_i = μ_M · (Σw_M)_i`. +4. RHS becomes `μ_excess(i) · (∑_j w_M(j) (Σw_M)_j) = μ_excess(i) · Var(R_M)`. +5. So `μ_M · (Σw_M)_i = μ_excess(i) · Var(R_M)`, and dividing by `Var(R_M) ≠ 0` + yields `μ_excess(i) = (Σw_M)_i / Var(R_M) · μ_M = β_i · μ_M`. -/ +theorem CAPM_from_market_equilibrium + {ι : Type*} (s : Finset ι) (w_M : ι → ℝ) (μ_excess : ι → ℝ) + (Sg : ι → ι → ℝ) (i : ι) (hi : i ∈ s) + (h_var : portfolioVarN s w_M Sg ≠ 0) + (h_FOC : ∀ j ∈ s, ∀ k ∈ s, + μ_excess k * marginalVariance s Sg w_M j = + μ_excess j * marginalVariance s Sg w_M k) : + μ_excess i = + beta (marginalVariance s Sg w_M i) (portfolioVarN s w_M Sg) * + portfolioReturn s w_M μ_excess := by + -- Sum w_M(j) · (h_FOC i j) over j ∈ s + have h_sum : + ∑ j ∈ s, w_M j * (μ_excess i * marginalVariance s Sg w_M j) = + ∑ j ∈ s, w_M j * (μ_excess j * marginalVariance s Sg w_M i) := by + refine Finset.sum_congr rfl ?_ + intro j hj + -- h_FOC i hi j hj: μ_excess j * (Σw_M)_i = μ_excess i * (Σw_M)_j + rw [h_FOC i hi j hj] + -- LHS = μ_excess i · Var(R_M) + have h_LHS : + ∑ j ∈ s, w_M j * (μ_excess i * marginalVariance s Sg w_M j) = + μ_excess i * portfolioVarN s w_M Sg := by + rw [portfolioVarN_eq_sum_mul_marginalVariance, Finset.mul_sum] + refine Finset.sum_congr rfl (fun j _ ↦ by ring) + -- RHS = μ_M · (Σw_M)_i + have h_RHS : + ∑ j ∈ s, w_M j * (μ_excess j * marginalVariance s Sg w_M i) = + portfolioReturn s w_M μ_excess * marginalVariance s Sg w_M i := by + unfold portfolioReturn + rw [Finset.sum_mul] + refine Finset.sum_congr rfl (fun j _ ↦ by ring) + rw [h_LHS, h_RHS] at h_sum + -- h_sum: μ_excess i * Var(R_M) = μ_M * (Σw_M)_i + -- Divide both sides by Var(R_M) + rw [beta, div_mul_eq_mul_div, eq_div_iff h_var] + linarith + +/-- **CAPM equilibrium ⟹ Security Market Line**: the equilibrium CAPM +identity in the standard SML form `E[R_i] = R_f + β_i (E[R_M] − R_f)`. + +This packages `CAPM_from_market_equilibrium` together with the relations +`μ_excess(i) = E[R_i] − R_f` and `μ_excess(M) = E[R_M] − R_f`. -/ +theorem expectedReturn_eq_SML_from_equilibrium + {ι : Type*} (s : Finset ι) (w_M : ι → ℝ) (μ : ι → ℝ) (rf : ℝ) + (Sg : ι → ι → ℝ) (i : ι) (hi : i ∈ s) + (h_weights : ∑ k ∈ s, w_M k = 1) + (h_var : portfolioVarN s w_M Sg ≠ 0) + (h_FOC : ∀ j ∈ s, ∀ k ∈ s, + (μ k - rf) * marginalVariance s Sg w_M j = + (μ j - rf) * marginalVariance s Sg w_M k) : + μ i = securityMarketLine rf + (beta (marginalVariance s Sg w_M i) (portfolioVarN s w_M Sg)) + (∑ k ∈ s, w_M k * μ k) := by + unfold securityMarketLine + have h := CAPM_from_market_equilibrium s w_M (fun k ↦ μ k - rf) Sg i hi h_var h_FOC + -- h: μ i - rf = β_i · (∑ k w_M(k) (μ k - rf)) + -- We want: μ i = rf + β_i · ((∑ k w_M(k) μ k) - rf) + unfold portfolioReturn at h + have h_mu_M : ∑ k ∈ s, w_M k * (μ k - rf) = + (∑ k ∈ s, w_M k * μ k) - rf := by + have h_aux : ∑ k ∈ s, w_M k * (μ k - rf) = + (∑ k ∈ s, w_M k * μ k) - (∑ k ∈ s, rf * w_M k) := by + rw [← Finset.sum_sub_distrib] + refine Finset.sum_congr rfl ?_ + intros k _ + ring + rw [h_aux, ← Finset.mul_sum, h_weights] + ring + rw [h_mu_M] at h + linarith + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/ConvexQPKKT.lean b/LeanPool/MathFin/Choice/Portfolio/ConvexQPKKT.lean new file mode 100644 index 0000000000..ccc3288d0d --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/ConvexQPKKT.lean @@ -0,0 +1,291 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.LinearAlgebra.Matrix.PosDef + +/-! +# KKT conditions for a convex QP with linear inequality constraints + +For `min c ⬝ᵥ x + ½ x ⬝ᵥ (C *ᵥ x)` subject to `a k ⬝ᵥ x ≤ b k` (`k` ranging over a +finite index set), with `C` symmetric positive semidefinite: we prove the +**sufficiency** half of the Karush-Kuhn-Tucker theorem (a feasible point +satisfying stationarity, dual feasibility and complementary slackness is a +global minimizer), and the **uniqueness** of a feasible KKT point when `C` is +positive definite. + +## Scope actually proved (read before citing as "the KKT theorem") + +Not proved here: KKT necessity, a separate mixed equality/inequality +statement, and uniqueness of the multipliers under linearly independent +active constraints. We prove: + +* **Sufficiency** (`kkt_sufficient`): stationarity + dual feasibility + + complementary slackness implies global optimality over the feasible set + for every feasible competitor (so `x0` itself is a global minimizer + whenever it is feasible). This is the direction actually used to *certify* + a candidate solution, and it follows directly from convexity — no + constraint qualification is needed. +* **Uniqueness under `C` positive definite** (`kkt_point_unique_of_posDef`): + any two feasible points each satisfying a sufficient-KKT system (possibly + with different multipliers) for the same `c, C, a, b` coincide. A minimizer + not known to be a KKT point is not covered, since necessity is not proved. + +We do **not** prove KKT **necessity** (optimal implies multipliers exist) +here. Necessity for inequality-constrained optimization is a genuine theorem +of the alternative (Farkas'/Gordan's lemma applied to the active-constraint +gradients, under a constraint qualification such as LICQ or Slater). Mathlib +has the general cone-separation form of Farkas' lemma +(`ProperCone.hyperplane_separation` in `Mathlib.Analysis.Convex.Cone.Dual`), +but turning it into "the negative gradient lies in the cone generated by the +active constraint gradients" for a finitely-generated real polyhedral cone +is a separate, substantial development (closedness of a finitely-generated +cone, the finite-dimensional Farkas transposition theorem in coordinates) +that is out of scope here. Uniqueness of the multipliers when the active +constraint gradients are linearly independent (a linear-algebra consequence +of stationarity and complementary slackness) is not stated either. + +**Equality constraints** (`kkt_sufficient_of_eq`): an equality constraint +`a ⬝ᵥ x = b` is exactly the pair of opposed inequalities `a ⬝ᵥ x ≤ b` and +`-a ⬝ᵥ x ≤ -b`, and a free multiplier is the difference of two nonnegative ones, +so sufficiency for the equality-constrained QP is `kkt_sufficient` applied to +that pair. A mixed equality/inequality statement is not stated separately. + +We also prove the ratio-test **feasible step size** lemma +(`feasible_step_preserved`): for a feasible `x0` and direction `d`, stepping +to `x0 + σ • d` preserves every constraint `a k ⬝ᵥ x ≤ b k` for every +`σ ∈ [0, σ̂]`, where `σ̂` is any lower bound for the step length at which a +constraint with `a k ⬝ᵥ d > 0` would first become binding. We use the sign +convention "`a k ⬝ᵥ d > 0`" for the direction that can make an upper-bound +constraint `a k ⬝ᵥ x ≤ b k` newly binding: for a `≤`-constraint, increasing +`σ` only threatens feasibility along directions where `a k ⬝ᵥ d` is +*positive* (it increases `a k ⬝ᵥ x`), so that is the sign under which the +stated feasibility-preservation claim is actually a theorem. That the smallest +such ratio is the *maximum* feasible step (a longer step leaves the feasible +set) is not proved. + +## Main definitions + +* `qpObj`: the convex QP objective `f(x) = c ⬝ᵥ x + ½ x ⬝ᵥ (C *ᵥ x)`. + +## Main results + +* `qp_grad_expansion`: the exact quadratic expansion + `qpObj c C y - qpObj c C x = (y-x) ⬝ᵥ (c + C *ᵥ x) + ½ (y-x) ⬝ᵥ (C *ᵥ (y-x))` + — the algebraic core of convexity, valid for any symmetric `C`. +* `kkt_sufficient`: KKT sufficiency for the inequality-constrained convex QP. +* `kkt_sufficient_of_eq`: KKT sufficiency for the equality-constrained convex QP, with + multipliers of either sign. +* `kkt_point_unique_of_posDef`: uniqueness of the feasible KKT point under `C ≻ 0`. +* `feasible_step_preserved`: the ratio-test feasibility-preservation lemma. + +## Tags + +Karush-Kuhn-Tucker, KKT conditions, convex quadratic programming, complementary slackness, +constrained optimization, global optimality, MSC 90C25, JEL C61 +-/ + +@[expose] public section + +namespace MathFin + +open Matrix + +variable {ι κ : Type*} [Fintype ι] [Fintype κ] + +/-- The convex QP objective `f(x) = c ⬝ᵥ x + ½ · x ⬝ᵥ (C *ᵥ x)`. -/ +noncomputable def qpObj (c : ι → ℝ) (C : Matrix ι ι ℝ) (x : ι → ℝ) : ℝ := + c ⬝ᵥ x + (1 / 2) * (x ⬝ᵥ (C *ᵥ x)) + +/-- A symmetric matrix's quadratic form is self-adjoint across the dot product: +`u ⬝ᵥ (C *ᵥ v) = v ⬝ᵥ (C *ᵥ u)`. -/ +lemma dotProduct_mulVec_symm_comm {C : Matrix ι ι ℝ} (hC : C.IsSymm) (u v : ι → ℝ) : + u ⬝ᵥ (C *ᵥ v) = v ⬝ᵥ (C *ᵥ u) := by + calc u ⬝ᵥ (C *ᵥ v) = u ᵥ* C ⬝ᵥ v := dotProduct_mulVec u C v + _ = u ᵥ* Cᵀ ⬝ᵥ v := by rw [hC.eq] + _ = (C *ᵥ u) ⬝ᵥ v := by rw [vecMul_transpose] + _ = v ⬝ᵥ (C *ᵥ u) := dotProduct_comm _ _ + +/-- **Exact quadratic expansion**: for symmetric `C`, +`f(y) - f(x) = (y-x) ⬝ᵥ (c + C *ᵥ x) + ½ (y-x) ⬝ᵥ (C *ᵥ (y-x))`. + +This is the algebraic content of convexity of `f`: the last term is `½` the +quadratic form of `C` at `d = y - x`, so it is `≥ 0` whenever `C` is positive +semidefinite, giving the first-order convexity inequality +`f(y) ≥ f(x) + d ⬝ᵥ ∇f(x)`. -/ +theorem qp_grad_expansion (c : ι → ℝ) {C : Matrix ι ι ℝ} (hC : C.IsSymm) (x y : ι → ℝ) : + qpObj c C y - qpObj c C x = + (y - x) ⬝ᵥ (c + C *ᵥ x) + (1 / 2) * ((y - x) ⬝ᵥ (C *ᵥ (y - x))) := by + have hCy : C *ᵥ y = C *ᵥ x + C *ᵥ (y - x) := by + rw [← mulVec_add]; congr 1; abel + have hxy : x ⬝ᵥ (C *ᵥ (y - x)) = (y - x) ⬝ᵥ (C *ᵥ x) := + dotProduct_mulVec_symm_comm hC x (y - x) + have step2 : y ⬝ᵥ (C *ᵥ x) = x ⬝ᵥ (C *ᵥ x) + (y - x) ⬝ᵥ (C *ᵥ x) := by + rw [← add_dotProduct]; congr 1; abel + have step3 : y ⬝ᵥ (C *ᵥ (y - x)) = + x ⬝ᵥ (C *ᵥ (y - x)) + (y - x) ⬝ᵥ (C *ᵥ (y - x)) := by + rw [← add_dotProduct]; congr 1; abel + have hy_split : y ⬝ᵥ (C *ᵥ y) = + x ⬝ᵥ (C *ᵥ x) + 2 * ((y - x) ⬝ᵥ (C *ᵥ x)) + (y - x) ⬝ᵥ (C *ᵥ (y - x)) := by + rw [hCy, dotProduct_add, step2, step3, hxy] + ring + have hd_c : (y - x) ⬝ᵥ (c + C *ᵥ x) = c ⬝ᵥ (y - x) + (y - x) ⬝ᵥ (C *ᵥ x) := by + rw [dotProduct_add, dotProduct_comm c (y - x)] + unfold qpObj + rw [hd_c, dotProduct_sub, hy_split] + ring + +/-- The complementary-slackness linear term is nonnegative at any feasible +competitor `y`: `0 ≤ ∑ k, u k * (a k ⬝ᵥ x0 - a k ⬝ᵥ y)`. The per-term bound is +`u k * (a k ⬝ᵥ x0 - a k ⬝ᵥ y) = u k * (a k ⬝ᵥ x0 - b k) + u k * (b k - a k ⬝ᵥ y)`, +whose first summand vanishes by complementary slackness and whose second is a +product of two nonnegatives. -/ +lemma kkt_complementary_term_nonneg {a : κ → ι → ℝ} {b : κ → ℝ} {u : κ → ℝ} + (hu_nonneg : ∀ k, 0 ≤ u k) {x0 : ι → ℝ} (hcs : ∀ k, u k * (a k ⬝ᵥ x0 - b k) = 0) + {y : ι → ℝ} (hfeasy : ∀ k, a k ⬝ᵥ y ≤ b k) : + 0 ≤ ∑ k, u k * (a k ⬝ᵥ x0 - a k ⬝ᵥ y) := + Finset.sum_nonneg fun k _ ↦ by nlinarith [hu_nonneg k, hfeasy k, hcs k] + +/-- **KKT sufficiency** for the convex QP `min c ⬝ᵥ x + ½ x ⬝ᵥ (C *ᵥ x)` subject to +`∀ k, a k ⬝ᵥ x ≤ b k`: a point `x0` satisfying + +* stationarity: `c + C *ᵥ x0 = -∑ k, u k • a k` (`u` the multipliers), +* dual feasibility: `u k ≥ 0`, +* complementary slackness: `u k * (a k ⬝ᵥ x0 - b k) = 0`, + +satisfies `qpObj c C x0 ≤ qpObj c C y` for every feasible `y` (so `x0` is a +global minimizer over the feasible set whenever it is itself feasible), +provided `C` is positive semidefinite. No constraint qualification is +needed. Note `x0`'s own feasibility is *not* assumed: complementary +slackness alone already forces `u k = 0` at every `k` where +`a k ⬝ᵥ x0 > b k`, so the hypotheses above are in fact slightly more general +than "`x0` is a feasible KKT point" — the usual application has `x0` +feasible, but the proof never needs that fact. -/ +theorem kkt_sufficient {c : ι → ℝ} {C : Matrix ι ι ℝ} (hpsd : C.PosSemidef) + {a : κ → ι → ℝ} {b : κ → ℝ} {x0 : ι → ℝ} {u : κ → ℝ} (hu_nonneg : ∀ k, 0 ≤ u k) + (hstat : c + C *ᵥ x0 = -∑ k, u k • a k) + (hcs : ∀ k, u k * (a k ⬝ᵥ x0 - b k) = 0) : + ∀ y, (∀ k, a k ⬝ᵥ y ≤ b k) → qpObj c C x0 ≤ qpObj c C y := by + have hC : C.IsSymm := isHermitian_iff_isSymm.mp hpsd.isHermitian + intro y hfeasy + have hexp := qp_grad_expansion c hC x0 y + have hquad_nonneg : 0 ≤ (y - x0) ⬝ᵥ (C *ᵥ (y - x0)) := by + simpa using hpsd.dotProduct_mulVec_nonneg (y - x0) + have hlin : (y - x0) ⬝ᵥ (c + C *ᵥ x0) = ∑ k, u k * (a k ⬝ᵥ x0 - a k ⬝ᵥ y) := by + rw [hstat, dotProduct_neg, dotProduct_sum, ← Finset.sum_neg_distrib] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + rw [dotProduct_smul, smul_eq_mul, dotProduct_comm (y - x0) (a k), dotProduct_sub] + ring + have hlin_nonneg := kkt_complementary_term_nonneg hu_nonneg hcs hfeasy + have : 0 ≤ qpObj c C y - qpObj c C x0 := by + rw [hexp, hlin] + linarith + linarith + +/-- **Uniqueness of the KKT point under `C ≻ 0`**: if `x0` and `x1` each +satisfy a sufficient-KKT system (feasibility, stationarity, dual feasibility, +complementary slackness) for the *same* objective `c, C` and constraints +`a, b`, possibly with *different* multipliers `u0, u1`, then `x0 = x1`. Both +points are assumed to be KKT points; a minimizer not known to be one is not +covered. -/ +theorem kkt_point_unique_of_posDef {c : ι → ℝ} {C : Matrix ι ι ℝ} + (hpd : C.PosDef) {a : κ → ι → ℝ} {b : κ → ℝ} + {x0 x1 : ι → ℝ} (hfeas0 : ∀ k, a k ⬝ᵥ x0 ≤ b k) (hfeas1 : ∀ k, a k ⬝ᵥ x1 ≤ b k) + {u0 : κ → ℝ} (hu0_nonneg : ∀ k, 0 ≤ u0 k) + (hstat0 : c + C *ᵥ x0 = -∑ k, u0 k • a k) (hcs0 : ∀ k, u0 k * (a k ⬝ᵥ x0 - b k) = 0) + {u1 : κ → ℝ} (hu1_nonneg : ∀ k, 0 ≤ u1 k) + (hstat1 : c + C *ᵥ x1 = -∑ k, u1 k • a k) (hcs1 : ∀ k, u1 k * (a k ⬝ᵥ x1 - b k) = 0) : + x0 = x1 := by + have hpsd := hpd.posSemidef + have hC : C.IsSymm := isHermitian_iff_isSymm.mp hpsd.isHermitian + have hle01 : qpObj c C x0 ≤ qpObj c C x1 := + kkt_sufficient hpsd hu0_nonneg hstat0 hcs0 x1 hfeas1 + have hle10 : qpObj c C x1 ≤ qpObj c C x0 := + kkt_sufficient hpsd hu1_nonneg hstat1 hcs1 x0 hfeas0 + have heq : qpObj c C x1 - qpObj c C x0 = 0 := by linarith + have hexp := qp_grad_expansion c hC x0 x1 + have hlin : (x1 - x0) ⬝ᵥ (c + C *ᵥ x0) = ∑ k, u0 k * (a k ⬝ᵥ x0 - a k ⬝ᵥ x1) := by + rw [hstat0, dotProduct_neg, dotProduct_sum, ← Finset.sum_neg_distrib] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + rw [dotProduct_smul, smul_eq_mul, dotProduct_comm (x1 - x0) (a k), dotProduct_sub] + ring + have hlin_nonneg := kkt_complementary_term_nonneg hu0_nonneg hcs0 hfeas1 + have hquad_nonneg : 0 ≤ (x1 - x0) ⬝ᵥ (C *ᵥ (x1 - x0)) := by + simpa using hpsd.dotProduct_mulVec_nonneg (x1 - x0) + -- `heq`, `hexp`, `hlin` force both the linear term and the quadratic term to + -- vanish, since they are nonnegative and sum to `0`. + have hquad_zero : (x1 - x0) ⬝ᵥ (C *ᵥ (x1 - x0)) = 0 := by + rw [hlin] at hexp + linarith [hexp, heq, hlin_nonneg, hquad_nonneg] + by_contra hne + have hd_ne : x1 - x0 ≠ 0 := sub_ne_zero.mpr fun h ↦ hne h.symm + have := hpd.dotProduct_mulVec_pos hd_ne + simp only [star_trivial] at this + linarith [hquad_zero] + +/-- **KKT sufficiency with equality constraints**: for the convex QP +`min c ⬝ᵥ x + ½ x ⬝ᵥ (C *ᵥ x)` subject to `∀ k, a k ⬝ᵥ x = b k`, a feasible point `x0` +satisfying stationarity `c + C *ᵥ x0 = ∑ k, ν k • a k` for some multipliers `ν` (of +either sign) satisfies `qpObj c C x0 ≤ qpObj c C y` for every feasible `y`, provided `C` +is positive semidefinite. + +This is `kkt_sufficient` for the inequality system `a k ⬝ᵥ x ≤ b k`, `-a k ⬝ᵥ x ≤ -b k` +indexed by `κ ⊕ κ`, with the free multiplier `ν k` split into the nonnegative pair +`max (-ν k) 0`, `max (ν k) 0`. Complementary slackness holds because `x0` is feasible. -/ +theorem kkt_sufficient_of_eq {c : ι → ℝ} {C : Matrix ι ι ℝ} (hpsd : C.PosSemidef) + {a : κ → ι → ℝ} {b : κ → ℝ} {x0 : ι → ℝ} (hfeas : ∀ k, a k ⬝ᵥ x0 = b k) + {ν : κ → ℝ} (hstat : c + C *ᵥ x0 = ∑ k, ν k • a k) : + ∀ y, (∀ k, a k ⬝ᵥ y = b k) → qpObj c C x0 ≤ qpObj c C y := by + intro y hy + refine kkt_sufficient hpsd (a := Sum.elim a (-a)) (b := Sum.elim b (-b)) + (u := Sum.elim (fun k ↦ max (-ν k) 0) fun k ↦ max (ν k) 0) + (fun k ↦ by cases k <;> simp) ?_ (fun k ↦ by cases k <;> simp [hfeas]) y + fun k ↦ by cases k <;> simp [hy] + rw [hstat, Fintype.sum_sum_type, ← Finset.sum_add_distrib, ← Finset.sum_neg_distrib] + refine Finset.sum_congr rfl fun k _ ↦ ?_ + simp only [Sum.elim_inl, Sum.elim_inr, Pi.neg_apply, smul_neg] + rw [show ν k • a k = (max (ν k) 0 - max (-ν k) 0) • a k by + rw [max_zero_sub_max_neg_zero_eq_self], + sub_smul] + abel + +omit [Fintype κ] in +/-- **Feasible step size (ratio test)**: let `x0` be feasible and `d` +a direction. If `σ̂` is a lower bound for the ratio at which each +`a k ⬝ᵥ d > 0` constraint becomes binding (i.e. +`σ̂ * (a k ⬝ᵥ d) ≤ b k - a k ⬝ᵥ x0` for every such `k`), then every step +`σ ∈ [0, σ̂]` keeps `x0 + σ • d` feasible. In particular this holds for +`σ0 = min σ̂ 1` whenever `σ̂ ≥ 0`. -/ +theorem feasible_step_preserved {a : κ → ι → ℝ} {b : κ → ℝ} {x0 d : ι → ℝ} + (hfeas0 : ∀ k, a k ⬝ᵥ x0 ≤ b k) {σhat : ℝ} + (hub : ∀ k, 0 < a k ⬝ᵥ d → σhat * (a k ⬝ᵥ d) ≤ b k - a k ⬝ᵥ x0) + {σ : ℝ} (hσ_nonneg : 0 ≤ σ) (hσ_le : σ ≤ σhat) : + ∀ k, a k ⬝ᵥ (x0 + σ • d) ≤ b k := by + intro k + have hstep : a k ⬝ᵥ (x0 + σ • d) = a k ⬝ᵥ x0 + σ * (a k ⬝ᵥ d) := by + rw [dotProduct_add, dotProduct_smul, smul_eq_mul] + rw [hstep] + by_cases hd : 0 < a k ⬝ᵥ d + · have := hub k hd + nlinarith [this] + · push Not at hd + nlinarith [hfeas0 k] + +omit [Fintype κ] in +/-- Corollary: the step size `σ0 = min σ̂ 1` preserves feasibility (useful +when the direction `d` is only trusted to be a feasible direction up to unit +length). -/ +theorem feasible_step_preserved_min_one {a : κ → ι → ℝ} {b : κ → ℝ} {x0 d : ι → ℝ} + (hfeas0 : ∀ k, a k ⬝ᵥ x0 ≤ b k) {σhat : ℝ} (hσhat_nonneg : 0 ≤ σhat) + (hub : ∀ k, 0 < a k ⬝ᵥ d → σhat * (a k ⬝ᵥ d) ≤ b k - a k ⬝ᵥ x0) : + ∀ k, a k ⬝ᵥ (x0 + (min σhat 1) • d) ≤ b k := + feasible_step_preserved hfeas0 hub (le_min hσhat_nonneg zero_le_one) (min_le_left _ _) + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/CovariancePSD.lean b/LeanPool/MathFin/Choice/Portfolio/CovariancePSD.lean new file mode 100644 index 0000000000..d80c2b5d8e --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/CovariancePSD.lean @@ -0,0 +1,104 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Portfolio.MarkowitzNAsset +public import Mathlib.Probability.Moments.Variance + +/-! +# Covariance kernels are positive semidefinite (the self-dot variance identity) + +`MarkowitzNAsset.lean` proves `portfolioVarN_nonneg_of_psd` *given* a PSD +hypothesis on the kernel. This file discharges that hypothesis from first +principles for the kernel that finance actually uses: the covariance kernel +`σ_{ij} = cov(R_i, R_j)` of genuine square-integrable random returns. + +The whole argument is the **self-dot identity**: Mathlib's `variance_sum'` +("the variance of a sum is the double sum of covariances") read backwards, +with `covariance_smul_left`/`covariance_smul_right` peeling the weights, +collapses the Markowitz double sum onto a single variance, + + `∑_{i,j} w_i w_j · cov(R_i, R_j) = cov(∑ w_i R_i, ∑ w_j R_j) = Var(∑ w_i R_i)`, + +and a variance is non-negative. The quadratic form is non-negative *because it +IS a variance* — that is why covariance matrices are PSD. + +## Main results + +* `portfolioVarN_covariance_eq_variance`: the Markowitz quadratic form with the + genuine covariance kernel equals the variance of the portfolio return. +* `covariance_kernel_psd`: the covariance kernel satisfies the PSD hypothesis + of `portfolioVarN_nonneg_of_psd` — derived, not assumed. +* `portfolioVarN_covariance_nonneg`: the capstone non-negativity. + +## References + +* [K. Bodie and Marcus, *Investments*][BodieKaneMarcus], Ch 7 +* [H. Markowitz, *Portfolio selection*][Markowitz1952] + +## Tags + +covariance matrix, positive semidefinite, portfolio variance, Markowitz, variance of a sum, +quadratic form, MSC 91G10, MSC 62H05, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsFiniteMeasure μ] + {ι : Type*} + +/-- **Self-dot variance identity**: the n-asset Markowitz quadratic form, evaluated +at the *genuine* covariance kernel `σ_{ij} = cov(R_i, R_j)` of square-integrable +random returns, is exactly the variance of the portfolio return `∑ wᵢ Rᵢ`: + + `portfolioVarN s w (cov(R_·, R_·)) = Var[∑ i ∈ s, wᵢ • Rᵢ]`. + +Mathlib's `variance_sum'` unfolds the portfolio variance into the double sum +of covariances; the `smul` lemmas peel the weights. No PSD assumption appears +anywhere. -/ +theorem portfolioVarN_covariance_eq_variance + (s : Finset ι) (w : ι → ℝ) (R : ι → Ω → ℝ) + (hR : ∀ i ∈ s, MemLp (R i) 2 μ) : + portfolioVarN s w (fun i j ↦ cov[R i, R j; μ]) = + Var[∑ i ∈ s, w i • R i; μ] := by + have hwR : ∀ i ∈ s, MemLp (w i • R i) 2 μ := fun i hi ↦ (hR i hi).const_smul (w i) + rw [variance_sum' hwR] + unfold portfolioVarN + refine Finset.sum_congr rfl fun i hi ↦ ?_ + refine Finset.sum_congr rfl fun j hj ↦ ?_ + rw [covariance_smul_left, covariance_smul_right] + ring + +/-- **Covariance kernels are PSD** — the hypothesis of +`portfolioVarN_nonneg_of_psd`, discharged from first principles: for any +weights `v`, the quadratic form `∑∑ vᵢ vⱼ cov(Rᵢ, Rⱼ)` is the variance of +`∑ vᵢ Rᵢ`, hence non-negative. -/ +theorem covariance_kernel_psd + (s : Finset ι) (R : ι → Ω → ℝ) + (hR : ∀ i ∈ s, MemLp (R i) 2 μ) : + ∀ v : ι → ℝ, 0 ≤ ∑ i ∈ s, ∑ j ∈ s, v i * v j * cov[R i, R j; μ] := by + intro v + have h := portfolioVarN_covariance_eq_variance s v R hR + unfold portfolioVarN at h + rw [h] + exact variance_nonneg _ μ + +/-- **N-asset portfolio variance non-negativity from random returns**: with the +genuine covariance kernel of square-integrable returns, the Markowitz portfolio +variance is non-negative — because it *is* the variance `Var[∑ wᵢ Rᵢ] ≥ 0`. -/ +theorem portfolioVarN_covariance_nonneg + (s : Finset ι) (w : ι → ℝ) (R : ι → Ω → ℝ) + (hR : ∀ i ∈ s, MemLp (R i) 2 μ) : + 0 ≤ portfolioVarN s w (fun i j ↦ cov[R i, R j; μ]) := + portfolioVarN_nonneg_of_psd s w _ (covariance_kernel_psd s R hR) + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/Equicorrelation.lean b/LeanPool/MathFin/Choice/Portfolio/Equicorrelation.lean new file mode 100644 index 0000000000..39782ca643 --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/Equicorrelation.lean @@ -0,0 +1,199 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Portfolio.CovariancePSD +public import Mathlib.Algebra.Order.Chebyshev + +/-! +# The equicorrelation matrix: when is a common correlation admissible? + +The `d × d` **equicorrelation matrix** has ones on the diagonal and a common correlation `ρ` +everywhere else (`equicorrelationMatrix`). It is the correlation matrix of every exchangeable +model: equally rated obligors in a credit portfolio, the assets of a single-factor model, the +daily losses behind the square-root-of-time rule. The question of QRM Exercise 6.26 is which `ρ` +can occur at all. The answer is + + `(1 − ρ)·I + ρ·J` is positive semidefinite `↔ −1/(d − 1) ≤ ρ ≤ 1` + +(`posSemidef_equicorrelationMatrix_iff`). Perfect positive dependence is always admissible, but +perfect negative dependence is not: in three or more dimensions, three variables cannot be +pairwise perfectly anticorrelated. + +The proof reads the quadratic form as a Markowitz portfolio variance. For weights `w`, +`wᵀ (equicorrelation) w = (1 − ρ) ∑ wᵢ² + ρ (∑ wᵢ)²` (`portfolioVarN_equicorrelation`). + +* Sufficiency is the Cauchy–Schwarz bound `(∑ wᵢ)² ≤ d ∑ wᵢ²`, the same inequality behind the + Herfindahl lower bound. +* Necessity tests two portfolios. The equal-weight portfolio gives `d (1 + (d − 1) ρ) ≥ 0`. The + long–short pair `eᵢ − eⱼ` gives `2 (1 − ρ) ≥ 0`. + +Mathlib's `Matrix.PosSemidef` quadratic form `x ⬝ᵥ (M *ᵥ x)` and the library's sum-form +`portfolioVarN` are identified by `dotProduct_mulVec_eq_portfolioVarN`, so the matrix statement +and the portfolio statement are the same theorem. + +The probabilistic reading (`neg_inv_le_and_le_one_of_covariance`) follows from +`Choice/Portfolio/CovariancePSD.lean`. Square-integrable variables with a common positive variance +and a common pairwise covariance `ρ σ²` have a PSD covariance kernel, and that kernel is `σ²` times +the equicorrelation matrix. So their common correlation satisfies `−1/(d − 1) ≤ ρ ≤ 1`. + +## Main definitions + +* `equicorrelationMatrix`: the `n × n` matrix with `1` on the diagonal and the common + correlation `ρ` off it, `(1 − ρ)·I + ρ·J`. + +## Main results + +* `dotProduct_mulVec_eq_portfolioVarN`: Mathlib's matrix quadratic form is the Markowitz double + sum. +* `portfolioVarN_equicorrelation`: `wᵀ E w = (1 − ρ) ∑ wᵢ² + ρ (∑ wᵢ)²`. +* `posSemidef_equicorrelationMatrix_iff`: for `d ≥ 2`, PSD `↔ −1/(d − 1) ≤ ρ ≤ 1` (QRM Ex. 6.26). +* `portfolioVarN_equicorrelation_equal_weights`: the equal-weight variance `ρ + (1 − ρ)/d`, the + diversification floor of QRM Ex. 6.16. +* `portfolioVarN_covariance_eq_mul_equicorrelation`: an equicorrelated covariance kernel is `σ²` + times the equicorrelation matrix. +* `neg_inv_le_and_le_one_of_covariance`: the bound for a common correlation of random variables. + +## References + +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 6.26 + +## Tags + +equicorrelation matrix, common correlation, exchangeable model, admissible correlation, +positive semidefinite, diversification, MSC 91G10, MSC 62H05, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +open Finset Matrix MeasureTheory ProbabilityTheory + +variable {n : Type*} [Fintype n] [DecidableEq n] {ρ : ℝ} + +/-- The **equicorrelation matrix**: `1` on the diagonal and the common correlation `ρ` off it, +i.e. `(1 − ρ)·I + ρ·J`. -/ +def equicorrelationMatrix (n : Type*) [DecidableEq n] (ρ : ℝ) : Matrix n n ℝ := + Matrix.of fun i j ↦ if i = j then 1 else ρ + +omit [Fintype n] in +/-- The equicorrelation matrix is symmetric, hence Hermitian over `ℝ`. -/ +lemma isHermitian_equicorrelationMatrix : (equicorrelationMatrix n ρ).IsHermitian := + IsHermitian.ext fun i j ↦ by simp [equicorrelationMatrix, eq_comm] + +omit [DecidableEq n] in +/-- Mathlib's matrix quadratic form `x ⬝ᵥ (M *ᵥ x)` is the Markowitz double sum +`portfolioVarN univ x M = ∑ᵢ ∑ⱼ xᵢ xⱼ Mᵢⱼ`. -/ +lemma dotProduct_mulVec_eq_portfolioVarN (M : Matrix n n ℝ) (x : n → ℝ) : + x ⬝ᵥ (M *ᵥ x) = portfolioVarN univ x M := by + simp only [dotProduct, mulVec, portfolioVarN, mul_sum] + exact sum_congr rfl fun i _ ↦ sum_congr rfl fun j _ ↦ by ring + +/-- **Portfolio variance against an equicorrelated kernel**: +`∑ᵢ ∑ⱼ wᵢ wⱼ Eᵢⱼ = (1 − ρ) ∑ wᵢ² + ρ (∑ wᵢ)²`. -/ +lemma portfolioVarN_equicorrelation (w : n → ℝ) : + portfolioVarN univ w (equicorrelationMatrix n ρ) = + (1 - ρ) * ∑ i, w i ^ 2 + ρ * (∑ i, w i) ^ 2 := by + have hterm (i j : n) : w i * w j * equicorrelationMatrix n ρ i j = + ρ * (w i * w j) + (1 - ρ) * (if i = j then w i * w j else 0) := by + by_cases hij : i = j <;> simp [equicorrelationMatrix, hij] <;> ring + simp only [portfolioVarN, hterm, sum_add_distrib, ← mul_sum, sum_ite_eq, mem_univ, ite_true, + sq, sum_mul_sum] + ring + +/-- **Admissible common correlations** (QRM Exercise 6.26): for `d ≥ 2` the equicorrelation +matrix is positive semidefinite exactly when `−1/(d − 1) ≤ ρ ≤ 1`. -/ +theorem posSemidef_equicorrelationMatrix_iff (hn : 2 ≤ Fintype.card n) : + (equicorrelationMatrix n ρ).PosSemidef ↔ -1 / ((Fintype.card n : ℝ) - 1) ≤ ρ ∧ ρ ≤ 1 := by + set d : ℝ := (Fintype.card n : ℝ) + have hd : 1 < d := by simp only [d]; exact_mod_cast hn + have hform (x : n → ℝ) : star x ⬝ᵥ (equicorrelationMatrix n ρ *ᵥ x) = + (1 - ρ) * ∑ i, x i ^ 2 + ρ * (∑ i, x i) ^ 2 := by + rw [star_trivial, dotProduct_mulVec_eq_portfolioVarN, portfolioVarN_equicorrelation] + rw [posSemidef_iff_dotProduct_mulVec, div_le_iff₀ (by linarith)] + simp only [hform, isHermitian_equicorrelationMatrix, true_and] + constructor + · intro h + obtain ⟨i, j, hij⟩ := Fintype.exists_pair_of_one_lt_card (α := n) (by omega) + -- the equal-weight portfolio: `d (1 + (d − 1) ρ) ≥ 0` + have h1 := h fun _ ↦ 1 + -- the long–short pair `eᵢ − eⱼ`: `2 (1 − ρ) ≥ 0` + have h2 := h (Pi.single i 1 - Pi.single j 1) + have hsq : ∑ k, (Pi.single i 1 - Pi.single j 1 : n → ℝ) k ^ 2 = 2 := by + have hk (k : n) : (Pi.single i 1 - Pi.single j 1 : n → ℝ) k ^ 2 = + (Pi.single i 1 : n → ℝ) k + (Pi.single j 1 : n → ℝ) k := by + by_cases hki : k = i <;> by_cases hkj : k = j <;> simp_all [Pi.single_apply] + simp only [hk, sum_add_distrib, sum_pi_single', mem_univ, ite_true] + norm_num + simp only [one_pow, sum_const, card_univ, nsmul_eq_mul, mul_one] at h1 + rw [hsq] at h2 + simp only [Pi.sub_apply, sum_sub_distrib, sum_pi_single', mem_univ, ite_true, sub_self, + ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, zero_pow, mul_zero, add_zero] at h2 + change 0 ≤ (1 - ρ) * d + ρ * d ^ 2 at h1 + refine ⟨?_, by linarith⟩ + nlinarith + · rintro ⟨h1, h2⟩ x + have hcs : (∑ i, x i) ^ 2 ≤ d * ∑ i, x i ^ 2 := by + simpa [d] using sq_sum_le_card_mul_sum_sq (s := univ) (f := x) + have hsq : 0 ≤ ∑ i, x i ^ 2 := sum_nonneg fun i _ ↦ sq_nonneg (x i) + rcases le_or_gt 0 ρ with hρ | hρ + · exact add_nonneg (mul_nonneg (by linarith) hsq) (mul_nonneg hρ (sq_nonneg _)) + · nlinarith [mul_le_mul_of_nonpos_left hcs hρ.le, + mul_nonneg (by linarith : 0 ≤ 1 + ρ * (d - 1)) hsq] + +/-- **The diversification floor** (QRM Exercise 6.16): with a common correlation `ρ`, the equally +weighted portfolio of `d` assets has kernel variance `ρ + (1 − ρ)/d`. Adding assets removes only +the idiosyncratic part `(1 − ρ)/d`; the common part `ρ` stays. -/ +lemma portfolioVarN_equicorrelation_equal_weights [Nonempty n] : + portfolioVarN univ (fun _ ↦ (Fintype.card n : ℝ)⁻¹) (equicorrelationMatrix n ρ) = + ρ + (1 - ρ) / Fintype.card n := by + have hd : (Fintype.card n : ℝ) ≠ 0 := Nat.cast_ne_zero.2 Fintype.card_ne_zero + rw [portfolioVarN_equicorrelation] + simp only [sum_const, card_univ, nsmul_eq_mul] + field_simp + ring + +/-- A covariance kernel with a common variance `σ²` and a common pairwise covariance `ρ σ²` is +`σ²` times the equicorrelation matrix, so its Markowitz form is `σ²` times the equicorrelation +form. -/ +lemma portfolioVarN_covariance_eq_mul_equicorrelation {Ω : Type*} {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} (X : n → Ω → ℝ) (hX : ∀ i, AEMeasurable (X i) μ) {σ2 : ℝ} + (hvar : ∀ i, Var[X i; μ] = σ2) (hcov : ∀ i j, i ≠ j → cov[X i, X j; μ] = ρ * σ2) + (w : n → ℝ) : + portfolioVarN univ w (fun i j ↦ cov[X i, X j; μ]) = + σ2 * portfolioVarN univ w (equicorrelationMatrix n ρ) := by + have hkernel (i j : n) : cov[X i, X j; μ] = σ2 * equicorrelationMatrix n ρ i j := by + by_cases hij : i = j + · subst hij + simp [equicorrelationMatrix, covariance_self, hX, hvar] + · simp [equicorrelationMatrix, hij, hcov i j hij, mul_comm] + simp only [hkernel, portfolioVarN, mul_sum] + exact sum_congr rfl fun i _ ↦ sum_congr rfl fun j _ ↦ by ring + +omit [DecidableEq n] in +/-- **A common correlation of random variables obeys the equicorrelation bound**: if +square-integrable `X₁, …, X_d` (`d ≥ 2`) have a common variance `σ² > 0` and a common pairwise +covariance `ρ σ²`, then `−1/(d − 1) ≤ ρ ≤ 1`. Their covariance kernel is `σ²` times the +equicorrelation matrix, and a covariance kernel is PSD (`covariance_kernel_psd`). -/ +theorem neg_inv_le_and_le_one_of_covariance {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsFiniteMeasure μ] (X : n → Ω → ℝ) (hX : ∀ i, MemLp (X i) 2 μ) {σ2 : ℝ} (hσ2 : 0 < σ2) + (hvar : ∀ i, Var[X i; μ] = σ2) (hcov : ∀ i j, i ≠ j → cov[X i, X j; μ] = ρ * σ2) + (hn : 2 ≤ Fintype.card n) : + -1 / ((Fintype.card n : ℝ) - 1) ≤ ρ ∧ ρ ≤ 1 := by + classical + refine (posSemidef_equicorrelationMatrix_iff hn).1 <| + posSemidef_iff_dotProduct_mulVec.2 ⟨isHermitian_equicorrelationMatrix, fun x ↦ ?_⟩ + have hpsd : 0 ≤ portfolioVarN univ x fun i j ↦ cov[X i, X j; μ] := + covariance_kernel_psd univ X (fun i _ ↦ hX i) x + rw [portfolioVarN_covariance_eq_mul_equicorrelation X + (fun i ↦ (hX i).aestronglyMeasurable.aemeasurable) hvar hcov] at hpsd + rw [star_trivial, dotProduct_mulVec_eq_portfolioVarN] + exact (mul_nonneg_iff_of_pos_left hσ2).1 hpsd + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/Markowitz.lean b/LeanPool/MathFin/Choice/Portfolio/Markowitz.lean new file mode 100644 index 0000000000..f9c4ca84ce --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/Markowitz.lean @@ -0,0 +1,146 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.LinearAlgebra.Matrix.Notation + +/-! +# Markowitz two-asset portfolio theory + +Closed-form results for the two-asset minimum-variance problem. Returns are +modelled by their first two moments only (`σ_1`, `σ_2`, `ρ`) — the classical +mean-variance setting where the covariance matrix is the primitive. That the formula +below is the variance of the random portfolio return `w R₁ + (1 − w) R₂` is proved in +`Choice/Portfolio/MarkowitzLagrangian.lean` (`portfolioVarTwo_eq_variance`), together with the +first-order condition the minimum-variance weight satisfies there +(`marginalVariance_minVarWeightTwo`). + +For a two-asset portfolio with weight `w` on asset 1 and `1 - w` on asset 2: + + `Var(w) = w² σ_1² + (1 - w)² σ_2² + 2 w (1 - w) ρ σ_1 σ_2`. + +The "completing-the-square" identity + + `Var(w) = D · (w − w*)² + V_min` + +with `D = σ_1² − 2 ρ σ_1 σ_2 + σ_2²`, +`w* = (σ_2² − ρ σ_1 σ_2) / D`, +`V_min = σ_1² σ_2² (1 − ρ²) / D`, + +makes both the location of the minimum (at `w*`) and its value (`V_min`) +immediate, and avoids any explicit calculus. + +## Main definitions + +* `portfolioVarTwo`: the variance `w² σ₁² + (1 − w)² σ₂² + 2 w (1 − w) ρ σ₁ σ₂` of the mix with + weight `w` on asset 1 and `1 − w` on asset 2. +* `covTwo`: the two-asset covariance matrix `!![σ₁², ρσ₁σ₂; ρσ₁σ₂, σ₂²]`. +* `minVarDenom`, `minVarWeightTwo`, `minPortfolioVarTwo`: the denominator + `D = σ₁² − 2ρσ₁σ₂ + σ₂²`, the weight `w* = (σ₂² − ρσ₁σ₂) / D` and the value + `V_min = σ₁²σ₂²(1 − ρ²) / D`. + +## Main results + +* `portfolioVarTwo_eq_dotProduct`: `Var(w)` as the quadratic form of `covTwo` at the weights + `(w, 1 − w)`. +* `portfolioVarTwo_eq_quad`: for `D ≠ 0`, `Var(w) = D (w − w*)² + V_min`. +* `portfolioVarTwo_at_minVarWeight`: for `D ≠ 0`, `Var(w*) = V_min`. +* `portfolioVarTwo_ge_min`: `Var(w) ≥ V_min` for every `w`, given `D > 0`. +* `minPortfolioVarTwo_perfect_anticorr`: at `ρ = -1` the closed form `V_min` + is zero (by `portfolioVarTwo_ge_min` it is the minimum variance whenever `D > 0`: a perfect + hedge). + +## References + +* [K. Bodie and Marcus, *Investments*][BodieKaneMarcus], Ch 7 + +## Tags + +Markowitz, mean-variance, minimum variance portfolio, two-asset portfolio, efficient frontier, +diversification, MSC 91G10, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +open Matrix + +/-- Portfolio variance for a two-asset mix with weight `w` on asset 1 and +`1 - w` on asset 2. -/ +noncomputable def portfolioVarTwo (σ₁ σ₂ ρ : ℝ) (w : ℝ) : ℝ := + w ^ 2 * σ₁ ^ 2 + (1 - w) ^ 2 * σ₂ ^ 2 + 2 * w * (1 - w) * ρ * σ₁ * σ₂ + +/-- The two-asset covariance matrix `!![σ₁², ρσ₁σ₂; ρσ₁σ₂, σ₂²]` for volatilities +`σ₁, σ₂` and correlation `ρ`. -/ +noncomputable def covTwo (σ₁ σ₂ ρ : ℝ) : Matrix (Fin 2) (Fin 2) ℝ := + !![σ₁ ^ 2, ρ * σ₁ * σ₂; ρ * σ₁ * σ₂, σ₂ ^ 2] + +/-- `portfolioVarTwo` is the quadratic form of `covTwo` at the weights `(w, 1 − w)`. -/ +lemma portfolioVarTwo_eq_dotProduct (σ₁ σ₂ ρ w : ℝ) : + portfolioVarTwo σ₁ σ₂ ρ w = ![w, 1 - w] ⬝ᵥ (covTwo σ₁ σ₂ ρ *ᵥ ![w, 1 - w]) := by + simp [portfolioVarTwo, covTwo, mulVec, dotProduct, Fin.sum_univ_two] + ring + +/-- Denominator of the min-variance weight: `D = σ_1² − 2 ρ σ_1 σ_2 + σ_2²`. -/ +noncomputable def minVarDenom (σ₁ σ₂ ρ : ℝ) : ℝ := + σ₁ ^ 2 - 2 * ρ * σ₁ * σ₂ + σ₂ ^ 2 + +/-- Closed-form minimum-variance weight: +`w* = (σ_2² − ρ σ_1 σ_2) / D`. -/ +noncomputable def minVarWeightTwo (σ₁ σ₂ ρ : ℝ) : ℝ := + (σ₂ ^ 2 - ρ * σ₁ * σ₂) / minVarDenom σ₁ σ₂ ρ + +/-- Minimum portfolio variance: `V_min = σ_1² σ_2² (1 − ρ²) / D`. -/ +noncomputable def minPortfolioVarTwo (σ₁ σ₂ ρ : ℝ) : ℝ := + σ₁ ^ 2 * σ₂ ^ 2 * (1 - ρ ^ 2) / minVarDenom σ₁ σ₂ ρ + +/-- Two-asset portfolio variance has the closed-form factorization +`Var(w) = D · (w − w*)² + V_min`. -/ +lemma portfolioVarTwo_eq_quad {σ₁ σ₂ ρ : ℝ} + (hD : minVarDenom σ₁ σ₂ ρ ≠ 0) (w : ℝ) : + portfolioVarTwo σ₁ σ₂ ρ w = + minVarDenom σ₁ σ₂ ρ * (w - minVarWeightTwo σ₁ σ₂ ρ) ^ 2 + + minPortfolioVarTwo σ₁ σ₂ ρ := by + unfold portfolioVarTwo minVarWeightTwo minPortfolioVarTwo + field_simp + unfold minVarDenom + ring + +/-- Two-asset portfolio variance attains the explicit minimum `V_min` at `w = w*`. -/ +lemma portfolioVarTwo_at_minVarWeight {σ₁ σ₂ ρ : ℝ} + (hD : minVarDenom σ₁ σ₂ ρ ≠ 0) : + portfolioVarTwo σ₁ σ₂ ρ (minVarWeightTwo σ₁ σ₂ ρ) = + minPortfolioVarTwo σ₁ σ₂ ρ := by + rw [portfolioVarTwo_eq_quad hD] + simp [sub_self] + +/-- For any weight, the portfolio variance is at least `V_min`, provided the +denominator `D` is positive (the standard non-degeneracy condition). -/ +lemma portfolioVarTwo_ge_min {σ₁ σ₂ ρ : ℝ} + (hD : 0 < minVarDenom σ₁ σ₂ ρ) (w : ℝ) : + minPortfolioVarTwo σ₁ σ₂ ρ ≤ portfolioVarTwo σ₁ σ₂ ρ w := by + rw [portfolioVarTwo_eq_quad hD.ne' w] + have h_sq : 0 ≤ (w - minVarWeightTwo σ₁ σ₂ ρ) ^ 2 := sq_nonneg _ + have h_term : 0 ≤ minVarDenom σ₁ σ₂ ρ * (w - minVarWeightTwo σ₁ σ₂ ρ) ^ 2 := + mul_nonneg hD.le h_sq + linarith + +/-- **Perfect-hedge corollary**: at `ρ = -1` the closed form `V_min` is zero, for any +`σ₁, σ₂`. It is the minimum portfolio variance when `D = (σ₁ + σ₂)² > 0` +(`portfolioVarTwo_ge_min`, `portfolioVarTwo_at_minVarWeight`). -/ +lemma minPortfolioVarTwo_perfect_anticorr (σ₁ σ₂ : ℝ) : + minPortfolioVarTwo σ₁ σ₂ (-1) = 0 := by + unfold minPortfolioVarTwo + have h : (1 : ℝ) - (-1) ^ 2 = 0 := by ring + rw [h] + ring + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/MarkowitzLagrangian.lean b/LeanPool/MathFin/Choice/Portfolio/MarkowitzLagrangian.lean new file mode 100644 index 0000000000..c66d41ba89 --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/MarkowitzLagrangian.lean @@ -0,0 +1,422 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Portfolio.CAPMEquilibrium +public import LeanPool.MathFin.Choice.Portfolio.ConvexQPKKT +public import LeanPool.MathFin.Choice.Portfolio.CovariancePSD +public import LeanPool.MathFin.Choice.Portfolio.TangentPortfolio + +/-! +# N-asset Markowitz from constrained-variance Lagrangian (first principles) + +The 2-asset Sharpe-ratio file (`Choice/Portfolio/SharpeFOCDerivation.lean`) +derives the cross-product FOC `r₂(Σw)₁ = r₁(Σw)₂` from `d(Sh²)/dw = 0`. +This file extends the first-principles derivation to N assets, but for the +*constrained variance minimization* formulation — +which is the textbook Markowitz statement and gives the canonical +Lagrangian FOC `Σw = lam_1 · 1 + lam_2 · μ`. + +## The problem + +Minimize `(1/2) · w^T Σ w` (portfolio variance) subject to + + * `1^T w = 1` (budget constraint), + * `μ^T w = m` (expected-return target). + +## The Lagrangian + +`L(w, lam_1, lam_2) := (1/2) · w^T Σ w − lam_1 · (1^T w − 1) − lam_2 · (μ^T w − m)`. + +## The FOC (textbook derivation) + +`∂L/∂w_i = (Σw)_i − lam_1 − lam_2 · μ_i = 0`, i.e., `Σw = lam_1 · 1 + lam_2 · μ`. + +This says the marginal variance vector lies in the 2-d span of the +constraint normals — the canonical "two-fund separation" structural fact. + +## Variational characterisation + +A portfolio `w` is a **constrained variance critical point** if for every +admissible perturbation `δw` (orthogonal to budget and expected-return +normals, i.e., `1^T δw = 0` and `μ^T δw = 0`), + + `(Σw)^T δw = 0`. + +For symmetric `Σ` this is the vanishing of `d/dt [(1/2) (w + t δw)^T Σ (w + t δw)] |_{t=0}`: +`quadratic_form_perturb_linear_coeff` identifies `(Σw)^T δw` as the linear coefficient of +that polynomial in `t` (no derivative statement is proved). + +## Main definitions + +* `IsConstrainedVarianceCriticalPoint`: `w` is a critical point of `(1/2) wᵀ Σ w` under the + budget constraint `1ᵀ w = 1` and the return constraint `μᵀ w = m`, in the variational form: + `(Σw)ᵀ δw = 0` for every perturbation `δw` orthogonal to `1` and `μ`. + +## Main results + +* `isCriticalPoint_of_lagrangian_FOC` (forward direction): if `Σw = lam_1 · + 1 + lam_2 · μ` componentwise, then `w` is a constrained-variance critical + point. *Proof*: direct algebra — substitute the FOC, use the + perturbation's orthogonality to the constraint normals. +* `variance_objective_eq_self_dot` / `quadratic_form_perturb_linear_coeff`: + the variance objective as a self-dot, and the explicit linear coefficient + `(Σw) · δw` of a perturbation of `(1/2) wᵀΣw` for symmetric `Σ` — the + directional-derivative content underlying the FOC. +* `portfolioVarN_le_of_lagrangian_FOC`: for positive semidefinite `Σ`, a portfolio + meeting both constraints and the Lagrangian FOC has the least variance among all + portfolios meeting the same constraints — the KKT sufficiency theorem + `kkt_sufficient_of_eq` (`Choice/Portfolio/ConvexQPKKT.lean`) for the QP `min ½ wᵀΣw`. +* `posSemidef_covariance`, `variance_le_of_lagrangian_FOC`: the same for the covariance + matrix of square-integrable random returns, whose positive semidefiniteness is derived + (`covariance_kernel_psd`), stated for the variance of the portfolio return itself. +* `isTangentPortfolioN_and_portfolioVarN_le`: a portfolio with `Σw = λ(μ − r_f)` is a tangent + portfolio and has the least variance at its budget and expected return. +* `portfolioVarN_minVarWeightTwo_le`: the closed-form two-asset weight minimises `portfolioVarN`. +* Two assets: `portfolioVarN_covTwo` and `portfolioVarTwo_eq_variance` identify the closed form + `portfolioVarTwo` (`Choice/Portfolio/Markowitz.lean`) with the quadratic form `portfolioVarN` and + with + `Var[w R₁ + (1 − w) R₂]`; `marginalVariance_minVarWeightTwo` shows that at the minimum-variance + weight each asset's marginal variance equals `V_min` (for `D ≠ 0`), so + (`isConstrainedVarianceCriticalPoint_minVarWeightTwo`) that weight satisfies the budget-only + Lagrangian FOC with multiplier `V_min`. + +## What is *not* in this file + +Necessity — "every constrained minimiser (or critical point) satisfies the Lagrangian +FOC for some multipliers" — is not proved. It requires showing `Σw ∈ span{1, μ}`, which by +the orthogonal-complement characterization is equivalent to +`Σw ⊥ {δw : 1·δw = 0 ∧ μ·δw = 0}`; in finite dimensions this needs +`Submodule.orthogonalComplement` machinery. The file proves the converse direction: every +weight satisfying the Lagrangian equations is a critical point and, for positive +semidefinite `Σ`, a global minimiser. + +## Why this is "first principles" + +`Choice/Portfolio/Markowitz.lean` states the two-asset minimum-variance weight in closed form and +`Choice/Portfolio/MarkowitzNAsset.lean` the n-asset variance identities. This file derives the +optimality of Lagrangian-FOC weights from the constrained variance-minimization problem, +for N assets with budget and target-return constraints (the standard textbook setup). + +## References + +* [K. Bodie and Marcus, *Investments*][BodieKaneMarcus], ch. 7 +* [Boyd and Vandenberghe, *Convex Optimization*][BoydVandenberghe2004], §5.5.3 +* [H. Markowitz, *Portfolio selection*][Markowitz1952] +* [R. C. Merton, *An analytic derivation of the efficient portfolio frontier*][Merton1972], §II + +## Tags + +Markowitz, mean-variance optimization, Lagrangian, first-order condition, two-fund separation, +minimum variance, constrained optimization, MSC 91G10, MSC 90C25, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +open Finset + +/-- **Constrained-variance critical-point property** (variational form): +`w` is a critical point of `(1/2) w^T Σ w` subject to `1^T w = 1` and +`μ^T w = m` if, for every admissible perturbation `δw` (orthogonal to +both constraint normals), the directional derivative `(Σw) · δw` vanishes. -/ +def IsConstrainedVarianceCriticalPoint {ι : Type*} (s : Finset ι) + (Sg : ι → ι → ℝ) (μ w : ι → ℝ) : Prop := + ∀ δw : ι → ℝ, + (∑ i ∈ s, δw i) = 0 → + (∑ i ∈ s, μ i * δw i) = 0 → + (∑ i ∈ s, marginalVariance s Sg w i * δw i) = 0 + +/-- **Forward direction of the Lagrangian FOC characterisation**: if there +exist scalars `lam_1, lam_2` such that `(Σw)_i = lam_1 + lam_2 · μ_i` for every +asset `i ∈ s`, then `w` is a constrained-variance critical point. + +The "Lagrangian FOC" `Σw = lam_1 · 1 + lam_2 · μ` is the textbook +characterisation of efficient portfolios. Only this direction (FOC ⟹ critical +point) is proved here, together with FOC ⟹ global minimum for positive +semidefinite `Σ` (`portfolioVarN_le_of_lagrangian_FOC`); that every +variance-minimising portfolio satisfies the FOC is not proved. + +Proof: substitute the FOC into the directional-derivative sum and use the +perturbation's orthogonality to the constraint normals (`∑ δw = 0` kills +the `lam_1` term, `∑ μ δw = 0` kills the `lam_2 μ` term). -/ +theorem isCriticalPoint_of_lagrangian_FOC + {ι : Type*} (s : Finset ι) (Sg : ι → ι → ℝ) (μ w : ι → ℝ) + (lam_1 lam_2 : ℝ) + (h_FOC : ∀ i ∈ s, marginalVariance s Sg w i = lam_1 + lam_2 * μ i) : + IsConstrainedVarianceCriticalPoint s Sg μ w := by + intro δw h_sum_zero h_mu_zero + -- ∑ (Σw)_i · δw_i = ∑ (lam_1 + lam_2 μ_i) · δw_i + -- = lam_1 · ∑ δw_i + lam_2 · ∑ μ_i δw_i + -- = lam_1 · 0 + lam_2 · 0 = 0 + have h_subst : ∑ i ∈ s, marginalVariance s Sg w i * δw i = + ∑ i ∈ s, (lam_1 + lam_2 * μ i) * δw i := by + refine Finset.sum_congr rfl ?_ + intros i hi + rw [h_FOC i hi] + rw [h_subst] + -- ∑ (lam_1 + lam_2 μ i) · δw i = lam_1 · ∑ δw + lam_2 · ∑ μ δw + have h_split : ∑ i ∈ s, (lam_1 + lam_2 * μ i) * δw i = + lam_1 * (∑ i ∈ s, δw i) + lam_2 * (∑ i ∈ s, μ i * δw i) := by + rw [Finset.mul_sum, Finset.mul_sum] + rw [← Finset.sum_add_distrib] + refine Finset.sum_congr rfl (fun i _ ↦ by ring) + rw [h_split, h_sum_zero, h_mu_zero] + ring + +/-- **Self-dot identity for the variance objective**: `(1/2) w^T Σ w` (the +variance objective, up to constant 1/2) equals `(1/2) · ∑_i w_i · (Σw)_i`. +This is the same self-dot identity used in `Choice/Portfolio/SharpeFOCDerivation.lean`, +restated for N assets. -/ +lemma variance_objective_eq_self_dot + {ι : Type*} (s : Finset ι) (Sg : ι → ι → ℝ) (w : ι → ℝ) : + (1 / 2 : ℝ) * portfolioVarN s w Sg = + (1 / 2 : ℝ) * ∑ i ∈ s, w i * marginalVariance s Sg w i := by + rw [portfolioVarN_eq_sum_mul_marginalVariance] + +/-- **Directional derivative of the variance objective at `w` in direction +`δw`**, for *symmetric* `Sg`: + + `d/dt [(1/2) (w + t δw)^T Σ (w + t δw)] |_{t=0} = (Σw)^T δw`. + +This is the calculus content underlying the FOC. Proof: expand the +quadratic in `t`, the linear coefficient is `(1/2) · [(δw)^T Σ w + w^T Σ δw]`, +which for symmetric `Σ` equals `(Σw)^T δw`. + +(No `HasDerivAt` statement is proved: the identity below is the linear +coefficient of the polynomial `t ↦ ½ (w + t δw)ᵀ Σ (w + t δw)`, stated +algebraically.) -/ +lemma quadratic_form_perturb_linear_coeff + {ι : Type*} (s : Finset ι) (Sg : ι → ι → ℝ) (w δw : ι → ℝ) + (h_symm : ∀ i ∈ s, ∀ j ∈ s, Sg i j = Sg j i) : + (1 / 2 : ℝ) * + ((∑ i ∈ s, ∑ j ∈ s, Sg i j * δw i * w j) + + (∑ i ∈ s, ∑ j ∈ s, Sg i j * w i * δw j)) = + ∑ i ∈ s, marginalVariance s Sg w i * δw i := by + -- The cross-terms: ∑_{ij} Sg(i,j) (δw_i w_j + w_i δw_j) + -- By symmetry Sg(i,j) = Sg(j,i), this equals 2 ∑_{ij} Sg(i,j) δw_i w_j + -- (after relabelling). Then (1/2) · 2 = 1, giving ∑_i δw_i (Σw)_i. + have h_swap : ∑ i ∈ s, ∑ j ∈ s, Sg i j * w i * δw j = + ∑ i ∈ s, ∑ j ∈ s, Sg i j * δw i * w j := by + -- Swap the indices using symmetry of Sg + rw [Finset.sum_comm] + refine Finset.sum_congr rfl ?_ + intros i hi + refine Finset.sum_congr rfl ?_ + intros j hj + rw [h_symm i hi j hj] + ring + rw [h_swap] + unfold marginalVariance + rw [show (1 / 2 : ℝ) * ((∑ i ∈ s, ∑ j ∈ s, Sg i j * δw i * w j) + + (∑ i ∈ s, ∑ j ∈ s, Sg i j * δw i * w j)) = + ∑ i ∈ s, ∑ j ∈ s, Sg i j * δw i * w j from by ring] + -- ∑_i ∑_j Sg(i,j) δw_i w_j = ∑_i δw_i · (∑_j Sg(i,j) w_j) = ∑_i δw_i · (Σw)_i + rw [show ∑ i ∈ s, ∑ j ∈ s, Sg i j * δw i * w j = + ∑ i ∈ s, δw i * (∑ j ∈ s, Sg i j * w j) from + Finset.sum_congr rfl (fun i _ ↦ by + rw [Finset.mul_sum] + refine Finset.sum_congr rfl (fun j _ ↦ by ring))] + refine Finset.sum_congr rfl (fun i _ ↦ by ring) + +/-- **Sufficient condition for tangency from the Lagrangian FOC**: +specialising to the case `lam_1 = 0` (no budget constraint, only expected- +return constraint), the FOC becomes `Σw = lam_2 · μ`, recovering the +cross-product tangent characterisation `IsTangentPortfolioN` from +`Choice/Portfolio/TangentPortfolio.lean`. -/ +theorem isTangent_of_lagrangian_no_budget + {ι : Type*} (s : Finset ι) (μ w : ι → ℝ) (Sg : ι → ι → ℝ) + (lam_2 : ℝ) + (h : ∀ i ∈ s, marginalVariance s Sg w i = lam_2 * μ i) : + IsTangentPortfolioN s μ Sg w := by + intro i hi j hj + unfold marginalVariance at h + rw [h i hi, h j hj] + ring + +/-! ### Global optimality of the Lagrangian FOC (KKT sufficiency) -/ + +section Global + +open Matrix MeasureTheory ProbabilityTheory + +variable {ι : Type*} [Fintype ι] + +/-- On a finite asset set the marginal-variance vector is the matrix–vector product. -/ +lemma marginalVariance_univ (Sg : Matrix ι ι ℝ) (w : ι → ℝ) : + marginalVariance Finset.univ Sg w = Sg *ᵥ w := rfl + +/-- On a finite asset set the portfolio variance is the quadratic form `w ⬝ᵥ (Σ *ᵥ w)`. -/ +lemma portfolioVarN_univ (Sg : Matrix ι ι ℝ) (w : ι → ℝ) : + portfolioVarN Finset.univ w Sg = w ⬝ᵥ (Sg *ᵥ w) := + portfolioVarN_eq_sum_mul_marginalVariance Finset.univ Sg w + +/-- **The Lagrangian FOC is sufficient for minimum variance.** Let `Σ` be positive +semidefinite and let `w` meet the budget `∑ wᵢ = 1` and the return target `∑ wᵢ μᵢ = m`. +If `(Σw)ᵢ = λ₁ + λ₂ μᵢ` for every asset, then `w` has the least variance among all +portfolios meeting the same two constraints. + +This is `kkt_sufficient_of_eq` for the QP `min ½ wᵀΣw` with the equality constraints +`1 ⬝ᵥ w = 1`, `μ ⬝ᵥ w = m` and multipliers `(λ₁, λ₂)`. Only sufficiency is proved: that +every minimiser satisfies the FOC is not. -/ +theorem portfolioVarN_le_of_lagrangian_FOC {Sg : Matrix ι ι ℝ} (hSg : Sg.PosSemidef) + {μ w : ι → ℝ} {m lam₁ lam₂ : ℝ} + (hw₁ : ∑ i, w i = 1) (hwμ : portfolioReturn Finset.univ w μ = m) + (h_FOC : ∀ i, marginalVariance Finset.univ Sg w i = lam₁ + lam₂ * μ i) + {v : ι → ℝ} (hv₁ : ∑ i, v i = 1) (hvμ : portfolioReturn Finset.univ v μ = m) : + portfolioVarN Finset.univ w Sg ≤ portfolioVarN Finset.univ v Sg := by + have hfeas (x : ι → ℝ) (h₁ : ∑ i, x i = 1) (hμ : portfolioReturn Finset.univ x μ = m) : + ∀ k, ![fun _ ↦ (1 : ℝ), μ] k ⬝ᵥ x = ![1, m] k := by + intro k + fin_cases k + · simpa [dotProduct] using h₁ + · simpa [dotProduct, portfolioReturn, mul_comm] using hμ + have hstat : 0 + Sg *ᵥ w = ∑ k, ![lam₁, lam₂] k • ![fun _ ↦ (1 : ℝ), μ] k := by + rw [zero_add, ← marginalVariance_univ] + funext i + simp [Finset.sum_apply, Fin.sum_univ_two, h_FOC] + have key := kkt_sufficient_of_eq hSg (hfeas w hw₁ hwμ) hstat v (hfeas v hv₁ hvμ) + simp only [qpObj, zero_dotProduct, zero_add] at key + rw [portfolioVarN_univ, portfolioVarN_univ] + linarith + +omit [Fintype ι] in +/-- **Covariance matrices are positive semidefinite** (in Mathlib's `Matrix.PosSemidef` +sense): the covariance matrix of square-integrable returns is symmetric +(`covariance_comm`) and its quadratic form is the variance of `∑ vᵢ Rᵢ` +(`covariance_kernel_psd`). -/ +theorem posSemidef_covariance [Finite ι] {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + [IsFiniteMeasure P] (R : ι → Ω → ℝ) (hR : ∀ i, MemLp (R i) 2 P) : + (Matrix.of fun i j ↦ cov[R i, R j; P]).PosSemidef := by + cases nonempty_fintype ι + refine PosSemidef.of_dotProduct_mulVec_nonneg (IsHermitian.ext fun i j ↦ by + simp only [of_apply, star_trivial]; exact covariance_comm _ _) fun v ↦ ?_ + refine (covariance_kernel_psd Finset.univ R (fun i _ ↦ hR i) v).trans_eq ?_ + simp only [Pi.star_apply, star_trivial, dotProduct, mulVec, of_apply, Finset.mul_sum] + exact Finset.sum_congr rfl fun i _ ↦ Finset.sum_congr rfl fun j _ ↦ by ring + +/-- **Markowitz for random returns.** For square-integrable returns `R`, a portfolio `w` +meeting the budget and the return target whose covariances with the assets satisfy the +Lagrangian FOC `∑ⱼ cov(Rᵢ, Rⱼ) wⱼ = λ₁ + λ₂ μᵢ` minimises the variance of the portfolio +return `∑ wᵢ Rᵢ` among all portfolios meeting the same constraints. The positive +semidefiniteness that `portfolioVarN_le_of_lagrangian_FOC` needs is derived +(`posSemidef_covariance`), not assumed. Sufficiency only. -/ +theorem variance_le_of_lagrangian_FOC {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + [IsFiniteMeasure P] (R : ι → Ω → ℝ) (hR : ∀ i, MemLp (R i) 2 P) + {μ w : ι → ℝ} {m lam₁ lam₂ : ℝ} + (hw₁ : ∑ i, w i = 1) (hwμ : portfolioReturn Finset.univ w μ = m) + (h_FOC : ∀ i, marginalVariance Finset.univ (fun i j ↦ cov[R i, R j; P]) w i = + lam₁ + lam₂ * μ i) + {v : ι → ℝ} (hv₁ : ∑ i, v i = 1) (hvμ : portfolioReturn Finset.univ v μ = m) : + Var[∑ i, w i • R i; P] ≤ Var[∑ i, v i • R i; P] := by + have hR' : ∀ i ∈ Finset.univ, MemLp (R i) 2 P := fun i _ ↦ hR i + rw [← portfolioVarN_covariance_eq_variance _ w R hR', + ← portfolioVarN_covariance_eq_variance _ v R hR'] + exact portfolioVarN_le_of_lagrangian_FOC (posSemidef_covariance R hR) hw₁ hwμ h_FOC + hv₁ hvμ + +/-- **The tangent portfolio is mean–variance efficient.** If `Σw = λ(μ − r_f)` and `∑ wᵢ = 1`, +then `w` is a tangent portfolio, and it has the least variance among the portfolios with the same +budget and expected return: the tangency condition is the Lagrangian condition with multipliers +`(−λ r_f, λ)`. Positive semidefiniteness of `Σ` is a hypothesis. -/ +theorem isTangentPortfolioN_and_portfolioVarN_le {Sg : Matrix ι ι ℝ} (hSg : Sg.PosSemidef) + {μ w : ι → ℝ} {rf lam : ℝ} (hw₁ : ∑ i, w i = 1) + (h : ∀ i, marginalVariance Finset.univ Sg w i = lam * (μ i - rf)) : + IsTangentPortfolioN Finset.univ (fun i ↦ μ i - rf) Sg w ∧ + ∀ v : ι → ℝ, ∑ i, v i = 1 → + portfolioReturn Finset.univ v μ = portfolioReturn Finset.univ w μ → + portfolioVarN Finset.univ w Sg ≤ portfolioVarN Finset.univ v Sg := + ⟨isTangent_of_proportional _ _ _ _ lam fun i _ ↦ h i, + fun _ hv₁ hvμ ↦ portfolioVarN_le_of_lagrangian_FOC (lam₁ := -(lam * rf)) (lam₂ := lam) + hSg hw₁ rfl (fun i ↦ by rw [h i]; ring) hv₁ hvμ⟩ + +end Global + +/-! ### Two assets: the closed form as an instance -/ + +section TwoAsset + +open Matrix MeasureTheory ProbabilityTheory + +/-- The two-asset `portfolioVarN` with the covariance matrix `covTwo` and weights +`(w, 1 − w)` is the closed form `portfolioVarTwo` of `Choice/Portfolio/Markowitz.lean`. -/ +lemma portfolioVarN_covTwo (σ₁ σ₂ ρ w : ℝ) : + portfolioVarN Finset.univ ![w, 1 - w] (covTwo σ₁ σ₂ ρ) = portfolioVarTwo σ₁ σ₂ ρ w := by + rw [portfolioVarN_univ, portfolioVarTwo_eq_dotProduct] + +/-- **The two-asset variance formula is the variance of the portfolio return.** For +square-integrable returns with `Var[R₁] = σ₁²`, `Var[R₂] = σ₂²` and `cov[R₁, R₂] = ρσ₁σ₂`, +`portfolioVarTwo σ₁ σ₂ ρ w = Var[w R₁ + (1 − w) R₂]`: the closed form of +`Choice/Portfolio/Markowitz.lean` is derived from the covariance kernel +(`portfolioVarN_covariance_eq_variance`), not posited. -/ +theorem portfolioVarTwo_eq_variance {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + [IsFiniteMeasure P] {R₁ R₂ : Ω → ℝ} (h₁ : MemLp R₁ 2 P) (h₂ : MemLp R₂ 2 P) + {σ₁ σ₂ ρ : ℝ} (hv₁ : Var[R₁; P] = σ₁ ^ 2) (hv₂ : Var[R₂; P] = σ₂ ^ 2) + (hc : cov[R₁, R₂; P] = ρ * σ₁ * σ₂) (w : ℝ) : + portfolioVarTwo σ₁ σ₂ ρ w = Var[w • R₁ + (1 - w) • R₂; P] := by + have hR : ∀ i ∈ (Finset.univ : Finset (Fin 2)), MemLp (![R₁, R₂] i) 2 P := by + intro i _ + fin_cases i + · exact h₁ + · exact h₂ + have h := portfolioVarN_covariance_eq_variance Finset.univ ![w, 1 - w] ![R₁, R₂] hR + simp only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one] at h + rw [← h, portfolioVarN, portfolioVarTwo] + simp only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, + covariance_self h₁.aestronglyMeasurable.aemeasurable, + covariance_self h₂.aestronglyMeasurable.aemeasurable, covariance_comm R₂ R₁, hv₁, hv₂, hc] + ring + +/-- **The minimum-variance mix equalises marginal variances.** At the two-asset +minimum-variance weight `w* = minVarWeightTwo`, each asset's marginal variance `(Σw*)ᵢ` — +its covariance with the portfolio — equals the minimum variance `V_min`. -/ +theorem marginalVariance_minVarWeightTwo {σ₁ σ₂ ρ : ℝ} (hD : minVarDenom σ₁ σ₂ ρ ≠ 0) + (i : Fin 2) : + marginalVariance Finset.univ (covTwo σ₁ σ₂ ρ) + ![minVarWeightTwo σ₁ σ₂ ρ, 1 - minVarWeightTwo σ₁ σ₂ ρ] i = + minPortfolioVarTwo σ₁ σ₂ ρ := by + have hw : minVarWeightTwo σ₁ σ₂ ρ * minVarDenom σ₁ σ₂ ρ = σ₂ ^ 2 - ρ * σ₁ * σ₂ := + div_mul_cancel₀ _ hD + have hV : minPortfolioVarTwo σ₁ σ₂ ρ * minVarDenom σ₁ σ₂ ρ = + σ₁ ^ 2 * σ₂ ^ 2 * (1 - ρ ^ 2) := + div_mul_cancel₀ _ hD + have hDdef : minVarDenom σ₁ σ₂ ρ = σ₁ ^ 2 - 2 * ρ * σ₁ * σ₂ + σ₂ ^ 2 := rfl + rw [marginalVariance_univ] + fin_cases i + · simp only [mulVec, dotProduct, covTwo, Fin.zero_eta, Fin.isValue, of_apply, + cons_val', cons_val_fin_one, cons_val_zero, Fin.sum_univ_two, cons_val_one] + refine mul_right_cancel₀ hD ?_ + linear_combination (σ₁ ^ 2 - ρ * σ₁ * σ₂) * hw + ρ * σ₁ * σ₂ * hDdef - hV + · simp only [mulVec, dotProduct, covTwo, Fin.mk_one, Fin.isValue, of_apply, + cons_val', cons_val_fin_one, cons_val_one, Fin.sum_univ_two, cons_val_zero] + refine mul_right_cancel₀ hD ?_ + linear_combination (ρ * σ₁ * σ₂ - σ₂ ^ 2) * hw + σ₂ ^ 2 * hDdef - hV + +/-- **The two-asset minimum-variance weight satisfies the Lagrangian FOC** with budget +multiplier `V_min` (and no return constraint, `μ = 0`), so it is a critical point of the +variance under the budget constraint (`isCriticalPoint_of_lagrangian_FOC`). -/ +theorem isConstrainedVarianceCriticalPoint_minVarWeightTwo {σ₁ σ₂ ρ : ℝ} + (hD : minVarDenom σ₁ σ₂ ρ ≠ 0) : + IsConstrainedVarianceCriticalPoint Finset.univ (covTwo σ₁ σ₂ ρ) 0 + ![minVarWeightTwo σ₁ σ₂ ρ, 1 - minVarWeightTwo σ₁ σ₂ ρ] := + isCriticalPoint_of_lagrangian_FOC _ _ 0 _ (minPortfolioVarTwo σ₁ σ₂ ρ) 0 fun i _ ↦ by + rw [marginalVariance_minVarWeightTwo hD, zero_mul, add_zero] + +/-- **The closed-form two-asset weight minimises the portfolio variance.** When +`D = σ₁² − 2ρσ₁σ₂ + σ₂² > 0`, the weights `(w*, 1 − w*)` have the least `portfolioVarN` under +`covTwo` among all two-asset budgets `(w, 1 − w)`. -/ +theorem portfolioVarN_minVarWeightTwo_le {σ₁ σ₂ ρ : ℝ} (hD : 0 < minVarDenom σ₁ σ₂ ρ) (w : ℝ) : + portfolioVarN Finset.univ ![minVarWeightTwo σ₁ σ₂ ρ, 1 - minVarWeightTwo σ₁ σ₂ ρ] + (covTwo σ₁ σ₂ ρ) ≤ portfolioVarN Finset.univ ![w, 1 - w] (covTwo σ₁ σ₂ ρ) := by + rw [portfolioVarN_covTwo, portfolioVarN_covTwo, portfolioVarTwo_at_minVarWeight hD.ne'] + exact portfolioVarTwo_ge_min hD w + +end TwoAsset + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/MarkowitzNAsset.lean b/LeanPool/MathFin/Choice/Portfolio/MarkowitzNAsset.lean new file mode 100644 index 0000000000..5e233e3e43 --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/MarkowitzNAsset.lean @@ -0,0 +1,134 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Portfolio.Markowitz +public import Mathlib.Logic.Equiv.PartialEquiv + +/-! +# N-asset Markowitz portfolio variance (sum form) + +Closed-form algebraic identities for the n-asset portfolio variance as an +explicit Finset double sum: + + `Var(w) = ∑_{i, j ∈ s} w_i · w_j · σ_{ij}`. + +We avoid the matrix-algebra layer (`Matrix.mulVec`, `Matrix.PosDef`) and work +directly with sums — this keeps the file lightweight while still covering the +core textbook identities. + +## Main definitions + +* `portfolioVarN`: the `n`-asset portfolio variance `∑_{i,j ∈ s} wᵢ wⱼ σᵢⱼ`, a double sum over a + finite index set `s` against a kernel `σ`. + +## Main results + +* `portfolioVarN_smul`: scaling `Var(c · w) = c² · Var(w)`. +* `portfolioVarN_diag`: when `σ` is diagonal (`σ_{ij} = 0` for `i ≠ j`), + `Var(w) = ∑ w_i² · σ_{ii}`. +* `portfolioVarN_equal_weights_iid`: equal-weights / iid case gives + `Var(c · 1) = c² · n · σ²` (a diversification scaling identity). +* `portfolioVarN_nonneg_of_psd`: if the kernel `σ` defines a non-negative + quadratic form, then `Var(w) ≥ 0`. +* `portfolioVarN_two_asset_compat`: when the index set has cardinality 2, + the double sum is the two-asset `portfolioVarTwo` of `Markowitz.lean`. + +## References + +* [K. Bodie and Marcus, *Investments*][BodieKaneMarcus], Ch 7; Ch 7.2; Ch 7.3; Ch 7.4 + +## Tags + +Markowitz, portfolio variance, covariance matrix, n-asset portfolio, diversification, MSC 91G10, +JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +/-- N-asset portfolio variance: `Var(w) = ∑_{i,j} w_i · w_j · σ_{ij}`. -/ +noncomputable def portfolioVarN + {ι : Type*} (s : Finset ι) (w : ι → ℝ) (σ : ι → ι → ℝ) : ℝ := + ∑ i ∈ s, ∑ j ∈ s, w i * w j * σ i j + +/-- **Quadratic scaling**: `Var(c · w) = c² · Var(w)`. -/ +lemma portfolioVarN_smul {ι : Type*} (s : Finset ι) + (w : ι → ℝ) (σ : ι → ι → ℝ) (c : ℝ) : + portfolioVarN s (fun i ↦ c * w i) σ = c ^ 2 * portfolioVarN s w σ := by + unfold portfolioVarN + rw [Finset.mul_sum] + refine Finset.sum_congr rfl ?_ + intro i _ + rw [Finset.mul_sum] + refine Finset.sum_congr rfl ?_ + intro j _ + ring + +/-- **Diagonal covariance**: when `σ_{ij} = 0` for `i ≠ j`, the portfolio +variance collapses to `∑ w_i² · σ_{ii}`. -/ +lemma portfolioVarN_diag {ι : Type*} (s : Finset ι) + (w : ι → ℝ) (σ : ι → ι → ℝ) + (h_diag : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → σ i j = 0) : + portfolioVarN s w σ = ∑ i ∈ s, w i ^ 2 * σ i i := by + classical + unfold portfolioVarN + refine Finset.sum_congr rfl ?_ + intro i hi + have h_inner : ∀ j ∈ s, w i * w j * σ i j = + if j = i then w i ^ 2 * σ i i else 0 := by + intro j hj + by_cases hij : j = i + · subst hij; simp [sq] + · have : σ i j = 0 := h_diag i hi j hj (fun h ↦ hij h.symm) + rw [this]; simp [hij] + rw [Finset.sum_congr rfl h_inner] + rw [Finset.sum_ite_eq' s i] + simp [hi] + +/-- **Diversification under iid assets**: equal weights `c` across an index set +`s` of cardinality `n`, with zero cross-covariances and common variance `σ²`, +gives `Var(c · 1) = c² · n · σ²`. -/ +lemma portfolioVarN_equal_weights_iid {ι : Type*} + (s : Finset ι) (c σ_sq : ℝ) + (kernel : ι → ι → ℝ) + (h_diag : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → kernel i j = 0) + (h_var : ∀ i ∈ s, kernel i i = σ_sq) : + portfolioVarN s (fun _ ↦ c) kernel = c ^ 2 * s.card * σ_sq := by + rw [portfolioVarN_diag s _ kernel h_diag] + have h_eq : ∀ i ∈ s, c ^ 2 * kernel i i = c ^ 2 * σ_sq := + fun i hi ↦ by rw [h_var i hi] + rw [Finset.sum_congr rfl h_eq, Finset.sum_const, nsmul_eq_mul] + ring + +/-- **Non-negativity from PSD kernel**: if `σ` defines a non-negative quadratic +form (`∀ v, ∑∑ v_i v_j σ_{ij} ≥ 0`), then `Var(w) ≥ 0`. -/ +lemma portfolioVarN_nonneg_of_psd + {ι : Type*} (s : Finset ι) (w : ι → ℝ) (σ : ι → ι → ℝ) + (h_psd : ∀ v : ι → ℝ, 0 ≤ ∑ i ∈ s, ∑ j ∈ s, v i * v j * σ i j) : + 0 ≤ portfolioVarN s w σ := h_psd w + +/-- **Two-asset compatibility**: for an index set `{0, 1} ⊆ Fin 2` with weights +`w 0 = w` and `w 1 = 1 − w` and the covariance kernel +`σ 0 0 = σ₁², σ 1 1 = σ₂², σ 0 1 = σ 1 0 = ρ · σ₁ · σ₂`, the n-asset variance +is the two-asset `portfolioVarTwo σ₁ σ₂ ρ w` of `Markowitz.lean`. -/ +lemma portfolioVarN_two_asset_compat (w σ₁ σ₂ ρ : ℝ) : + portfolioVarN (Finset.univ : Finset (Fin 2)) + (fun i ↦ if i = 0 then w else 1 - w) + (fun i j ↦ + if i = 0 ∧ j = 0 then σ₁ ^ 2 + else if i = 1 ∧ j = 1 then σ₂ ^ 2 + else ρ * σ₁ * σ₂) = + portfolioVarTwo σ₁ σ₂ ρ w := by + unfold portfolioVarN portfolioVarTwo + rw [show (Finset.univ : Finset (Fin 2)) = {0, 1} from rfl] + simp [Finset.sum_insert, Finset.mem_singleton, Finset.sum_singleton] + ring + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/PosSemidefCauchySchwarz.lean b/LeanPool/MathFin/Choice/Portfolio/PosSemidefCauchySchwarz.lean new file mode 100644 index 0000000000..484c65a4ca --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/PosSemidefCauchySchwarz.lean @@ -0,0 +1,165 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Portfolio.ConvexQPKKT + +/-! +# Cauchy–Schwarz for positive semidefinite forms, and the mean–standard-deviation tradeoff + +The Cauchy–Schwarz inequality for the semi-inner product `⟨u, v⟩ = u ⬝ᵥ (Sig *ᵥ v)` induced by +a positive semidefinite matrix `Sig` over `ι → ℝ`, and its application to the tradeoff form of +the Markowitz mean–variance problem. + +* `posSemidef_cauchySchwarz`: for `Sig` positive semidefinite, + `|x ⬝ᵥ (Sig *ᵥ y)| ≤ √(x ⬝ᵥ (Sig *ᵥ x)) · √(y ⬝ᵥ (Sig *ᵥ y))`. The form is degenerate when + `Sig` is singular, and the bound holds all the same. It is Mathlib's + Cauchy–Schwarz for bilinear forms nonnegative on the diagonal, applied to `Matrix.toBilin'`. +* `pricedReturn_le_of_kkt`: if `x1` satisfies the KKT stationarity, dual-feasibility and + complementary-slackness conditions of the risk-penalized QP + `min -μ ⬝ᵥ x + (t₁/2) · x ⬝ᵥ (Sig *ᵥ x)` (with `Sig` PSD and `t₁ ≥ 0`; the KKT machinery is + that of `MathFin.Choice.Portfolio.ConvexQPKKT`), then `x1` maximizes the mean–standard-deviation + objective `μ ⬝ᵥ y - t₁·√(x1 ⬝ᵥ (Sig *ᵥ x1)) · √(y ⬝ᵥ (Sig *ᵥ y))` over every feasible `y`. + Stationarity, rearranged to `μ = t₁ • Sig *ᵥ x1 + ∑ u k • a k`, turns the return gap into + `t₁ · (Q - X)` plus the complementary-slackness terms (nonpositive at any feasible `y`, by + `kkt_complementary_term_nonneg`), and Cauchy–Schwarz bounds the bilinear term `Q`. + +KKT necessity (that an optimal solution is a KKT point) is not proved; the module certifies +candidates, as `MathFin.Choice.Portfolio.ConvexQPKKT` does. + +## Main definitions + +* `pricedReturn`: the return `μ ⬝ᵥ y` minus the charge + `t₁ · √(x1 ⬝ᵥ (Sig *ᵥ x1)) · √(y ⬝ᵥ (Sig *ᵥ y))`, with the price of risk calibrated on the + benchmark `x1`. + +## Main results + +* `posSemidef_cauchySchwarz`: for a positive semidefinite matrix `Sig`, + `|x ⬝ᵥ (Sig *ᵥ y)| ≤ √(x ⬝ᵥ (Sig *ᵥ x)) · √(y ⬝ᵥ (Sig *ᵥ y))`. +* `pricedReturn_le_of_kkt`: a point `x1` satisfying the KKT stationarity, dual-feasibility and + complementary-slackness conditions of the risk-penalized quadratic program (with `Sig` + positive semidefinite and `t₁ ≥ 0`) maximizes `pricedReturn` over every feasible `y`. It + certifies a candidate; KKT necessity is not proved. + +## References + +* [Boyd and Vandenberghe, *Convex Optimization*][BoydVandenberghe2004] +* [H. Markowitz, *Portfolio selection*][Markowitz1952] + +## Tags + +Cauchy-Schwarz inequality, mean-standard deviation tradeoff, positive semidefinite form, Markowitz, +KKT conditions, risk aversion, MSC 91G10, MSC 90C25, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +open Matrix + +variable {ι : Type*} [Fintype ι] {Sig : Matrix ι ι ℝ} + +/-- **Cauchy–Schwarz for a positive semidefinite bilinear form**: for `Sig` PSD, + +`|x ⬝ᵥ (Sig *ᵥ y)| ≤ √(x ⬝ᵥ (Sig *ᵥ x)) · √(y ⬝ᵥ (Sig *ᵥ y))`. + +The form `⟨u, v⟩ = u ⬝ᵥ (Sig *ᵥ v)` is a semi-inner product only (degenerate when `Sig` is +singular). This is Mathlib's Cauchy–Schwarz for a bilinear form that is nonnegative on the +diagonal (`LinearMap.BilinForm.apply_mul_apply_le_of_forall_zero_le`), applied to +`Matrix.toBilin' Sig`, with symmetry of `Sig` matching the two cross terms. -/ +theorem posSemidef_cauchySchwarz (hpsd : Sig.PosSemidef) (x y : ι → ℝ) : + |x ⬝ᵥ (Sig *ᵥ y)| ≤ + Real.sqrt (x ⬝ᵥ (Sig *ᵥ x)) * Real.sqrt (y ⬝ᵥ (Sig *ᵥ y)) := by + classical + have hB (u v : ι → ℝ) : Matrix.toBilin' Sig u v = u ⬝ᵥ (Sig *ᵥ v) := + Matrix.toBilin'_apply' Sig u v + have hs (u : ι → ℝ) : 0 ≤ Matrix.toBilin' Sig u u := by + rw [hB]; simpa using hpsd.dotProduct_mulVec_nonneg u + have hCS := LinearMap.BilinForm.apply_mul_apply_le_of_forall_zero_le (Matrix.toBilin' Sig) hs x y + rw [hB, hB, hB, hB, + dotProduct_mulVec_symm_comm (isHermitian_iff_isSymm.mp hpsd.isHermitian) y x] at hCS + rw [← Real.sqrt_mul (hs x |>.trans_eq (hB x x)), ← Real.sqrt_sq_eq_abs] + exact Real.sqrt_le_sqrt (by nlinarith [hCS]) + +/-- The **priced return** of `y` at the price of risk `t₁ · √(x1 ⬝ᵥ (Sig *ᵥ x1))` +calibrated on the benchmark `x1`: the return `μ ⬝ᵥ y` minus the charge +`t₁ · √(x1 ⬝ᵥ (Sig *ᵥ x1)) · √(y ⬝ᵥ (Sig *ᵥ y))` — the price `t₁ · √(x1 ⬝ᵥ (Sig *ᵥ x1))` +per unit of the holder's own risk `√(y ⬝ᵥ (Sig *ᵥ y))`. Maximizing it over a +feasible set is the risk-adjusted (tradeoff) form of portfolio selection. -/ +noncomputable def pricedReturn (μ : ι → ℝ) (t₁ : ℝ) (Sig : Matrix ι ι ℝ) + (x1 y : ι → ℝ) : ℝ := + μ ⬝ᵥ y - t₁ * Real.sqrt (x1 ⬝ᵥ (Sig *ᵥ x1)) * Real.sqrt (y ⬝ᵥ (Sig *ᵥ y)) + +/-- **A mean–variance KKT point maximizes the mean–standard-deviation objective** at the price of +risk `t₁·√(x1'Σx1)`: if `x1` satisfies the KKT stationarity, dual feasibility and +complementary-slackness conditions of the risk-penalized QP +`min −μ ⬝ᵥ x + (t₁/2) · x ⬝ᵥ (Sig *ᵥ x)`, with `Sig` positive semidefinite and `t₁ ≥ 0`, then +for every feasible competitor `y` + +`pricedReturn μ t₁ Sig x1 y ≤ pricedReturn μ t₁ Sig x1 x1`. + +Stationarity, rearranged to `μ = t₁ • Sig *ᵥ x1 + ∑ u k • a k`, turns the return gap into +`t₁ · (Q − X)` plus the complementary-slackness terms (nonpositive at any feasible `y`), and +Cauchy–Schwarz for the PSD form bounds `Q`. `x1`'s own primal feasibility is not assumed: +complementary slackness alone forces `u k = 0` at every `k` where `a k ⬝ᵥ x1 > b k`, as for +`kkt_sufficient` in `MathFin.Choice.Portfolio.ConvexQPKKT`. -/ +theorem pricedReturn_le_of_kkt {κ : Type*} [Fintype κ] + {μ : ι → ℝ} (hpsd : Sig.PosSemidef) {t₁ : ℝ} (ht₁ : 0 ≤ t₁) + {a : κ → ι → ℝ} {b : κ → ℝ} {x1 : ι → ℝ} {u : κ → ℝ} + (hu_nonneg : ∀ k, 0 ≤ u k) + (hstat : -μ + t₁ • Sig *ᵥ x1 = -∑ k, u k • a k) + (hcs : ∀ k, u k * (a k ⬝ᵥ x1 - b k) = 0) + {y : ι → ℝ} (hfeasy : ∀ k, a k ⬝ᵥ y ≤ b k) : + pricedReturn μ t₁ Sig x1 y ≤ pricedReturn μ t₁ Sig x1 x1 := by + have hC : Sig.IsSymm := isHermitian_iff_isSymm.mp hpsd.isHermitian + have hX : 0 ≤ x1 ⬝ᵥ (Sig *ᵥ x1) := by + simpa using hpsd.dotProduct_mulVec_nonneg x1 + -- unfold the priced returns; at the benchmark itself the charge is `t₁ · X` + simp only [pricedReturn] + conv_rhs => rw [mul_assoc] + rw [Real.mul_self_sqrt hX] + -- stationarity dot-product identity against any vector `z` + have hstatdot : ∀ z : ι → ℝ, + μ ⬝ᵥ z = t₁ * (x1 ⬝ᵥ (Sig *ᵥ z)) + ∑ k, u k * (a k ⬝ᵥ z) := by + intro z + have h2 : z ⬝ᵥ (-μ + t₁ • Sig *ᵥ x1) = z ⬝ᵥ (-∑ k, u k • a k) := by rw [hstat] + rw [dotProduct_add, dotProduct_neg, dotProduct_comm z μ, dotProduct_smul, + dotProduct_mulVec_symm_comm hC z x1, dotProduct_neg, dotProduct_sum] at h2 + have h3 : ∀ k, z ⬝ᵥ (u k • a k) = u k * (a k ⬝ᵥ z) := by + intro k + rw [dotProduct_smul, dotProduct_comm z (a k)] + simp only [smul_eq_mul] + simp only [h3, smul_eq_mul] at h2 + linarith + have hstaty := hstatdot y + have hstatx := hstatdot x1 + -- return gap = t₁ (Q − X) + the complementary-slackness terms + have hgap : μ ⬝ᵥ y - μ ⬝ᵥ x1 + = t₁ * (x1 ⬝ᵥ (Sig *ᵥ y) - x1 ⬝ᵥ (Sig *ᵥ x1)) + + (∑ k, u k * (a k ⬝ᵥ y) - ∑ k, u k * (a k ⬝ᵥ x1)) := by + rw [hstaty, hstatx] + ring + have hcsle : 0 ≤ ∑ k, u k * (a k ⬝ᵥ x1 - a k ⬝ᵥ y) := + kkt_complementary_term_nonneg hu_nonneg hcs hfeasy + have hsumsplit : ∑ k, u k * (a k ⬝ᵥ y) - ∑ k, u k * (a k ⬝ᵥ x1) + = -∑ k, u k * (a k ⬝ᵥ x1 - a k ⬝ᵥ y) := by + rw [← Finset.sum_neg_distrib, ← Finset.sum_sub_distrib] + exact Finset.sum_congr rfl fun k _ ↦ by ring + -- Cauchy–Schwarz bounds the bilinear term; assemble + have hQle : x1 ⬝ᵥ (Sig *ᵥ y) + ≤ Real.sqrt (x1 ⬝ᵥ (Sig *ᵥ x1)) * Real.sqrt (y ⬝ᵥ (Sig *ᵥ y)) := + (le_abs_self _).trans (posSemidef_cauchySchwarz hpsd x1 y) + have e1 : t₁ * (x1 ⬝ᵥ (Sig *ᵥ y)) ≤ t₁ * (Real.sqrt (x1 ⬝ᵥ (Sig *ᵥ x1)) + * Real.sqrt (y ⬝ᵥ (Sig *ᵥ y))) := mul_le_mul_of_nonneg_left hQle ht₁ + have e3 : t₁ * (x1 ⬝ᵥ (Sig *ᵥ y) - x1 ⬝ᵥ (Sig *ᵥ x1)) + = t₁ * (x1 ⬝ᵥ (Sig *ᵥ y)) - t₁ * (x1 ⬝ᵥ (Sig *ᵥ x1)) := by ring + linarith [hgap, hsumsplit, hcsle, e1, e3] + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/RiskParity.lean b/LeanPool/MathFin/Choice/Portfolio/RiskParity.lean new file mode 100644 index 0000000000..5a80e31e5d --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/RiskParity.lean @@ -0,0 +1,110 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Portfolio.RiskParityFOC + +/-! +# Risk parity portfolio (two-asset closed form) + +A risk-parity portfolio sets each asset's *contribution to variance* +`wᵢ (Σw)ᵢ` equal across assets. For two assets with positive volatilities `σ₁, σ₂` +and correlation `ρ`, the risk-parity weights under the budget constraint +`w₁ + w₂ = 1` with `w₁, w₂ > 0` are independent of `ρ`: + + `w₁^RP = σ₂ / (σ₁ + σ₂)`, + `w₂^RP = σ₁ / (σ₁ + σ₂)`. + +The independence from correlation is the surprising feature: only the +relative volatilities matter for equal-risk allocation. + +## Main definitions + +* `riskParityWeightTwo`: the two-asset risk-parity weight `σ₂ / (σ₁ + σ₂)` on asset 1. + +## Main results + +* `risk_parity_equal_contribution`: at the RP weights, the two assets' + contributions to portfolio variance are equal. +* `isRiskParity_two_iff`: with the covariance matrix `covTwo` (`Choice/Portfolio/Markowitz.lean`) + and the risk-parity predicate `IsRiskParity` (`Choice/Portfolio/RiskParityFOC.lean`), a long-only + budget portfolio has equal risk contributions iff `w₁ = σ₂ / (σ₁ + σ₂)`, for every `ρ`: + the closed form is the only long-only two-asset risk-parity portfolio (not formalised: when + `σ₁ ≠ σ₂`, a budget portfolio with a short leg, `w₁σ₁ = −w₂σ₂`, also equalises contributions). + +## References + +* [Maillard, Roncalli and Te"iletche, *The properties of equally weighted risk contribution + portfolios*][MaillardRoncalliTeiletche2010], §2 + +## Tags + +risk parity, equal risk contribution, inverse volatility weights, two-asset portfolio, +variance contribution, MSC 91G10, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +/-- Risk-parity weight on asset 1 in the two-asset case. The other asset gets +the complementary weight `σ₁ / (σ₁ + σ₂)`. -/ +noncomputable def riskParityWeightTwo (σ₁ σ₂ : ℝ) : ℝ := + σ₂ / (σ₁ + σ₂) + +/-- **Risk-parity equal-contribution identity** for two assets: at +`w₁ = σ₂/(σ₁+σ₂)`, `w₂ = σ₁/(σ₁+σ₂)`, asset 1 and asset 2 contribute +identically to portfolio variance regardless of correlation `ρ`. The +contribution of asset `i` is `w_i · (Σ·w)_i = w_i · (w_i σ_i² + w_j ρ σ_i σ_j)`. -/ +theorem risk_parity_equal_contribution (σ₁ σ₂ ρ : ℝ) + (hσ : σ₁ + σ₂ ≠ 0) : + let w₁ := riskParityWeightTwo σ₁ σ₂ + let w₂ := riskParityWeightTwo σ₂ σ₁ + w₁ * (w₁ * σ₁^2 + w₂ * ρ * σ₁ * σ₂) = + w₂ * (w₁ * ρ * σ₁ * σ₂ + w₂ * σ₂^2) := by + unfold riskParityWeightTwo + rw [show σ₂ + σ₁ = σ₁ + σ₂ from by ring] + field_simp + ring + +/-- **Risk-parity weights sum to one**: `w₁ + w₂ = 1`. -/ +lemma riskParity_weights_sum_one (σ₁ σ₂ : ℝ) (hσ : σ₁ + σ₂ ≠ 0) : + riskParityWeightTwo σ₁ σ₂ + riskParityWeightTwo σ₂ σ₁ = 1 := by + unfold riskParityWeightTwo + rw [show σ₂ + σ₁ = σ₁ + σ₂ from by ring] + field_simp + ring + +/-- **The two-asset risk-parity portfolio is unique.** For two assets with positive +volatilities and any correlation `ρ`, a long-only budget portfolio `(w₁, w₂)` +(`w₁, w₂ > 0`, `w₁ + w₂ = 1`) has equal risk contributions under `covTwo σ₁ σ₂ ρ` +(`IsRiskParity`) iff `w₁ = σ₂ / (σ₁ + σ₂)`. The reason is the factorisation +`RC₁ − RC₂ = (w₁σ₁ − w₂σ₂)(w₁σ₁ + w₂σ₂)`, in which the correlation terms cancel and the +second factor is positive. -/ +theorem isRiskParity_two_iff {σ₁ σ₂ w₁ w₂ : ℝ} (hσ₁ : 0 < σ₁) (hσ₂ : 0 < σ₂) (hw₁ : 0 < w₁) + (hw₂ : 0 < w₂) (hsum : w₁ + w₂ = 1) (ρ : ℝ) : + IsRiskParity Finset.univ (covTwo σ₁ σ₂ ρ) ![w₁, w₂] ↔ w₁ = riskParityWeightTwo σ₁ σ₂ := by + have hRC : riskContribution Finset.univ (covTwo σ₁ σ₂ ρ) ![w₁, w₂] 0 - + riskContribution Finset.univ (covTwo σ₁ σ₂ ρ) ![w₁, w₂] 1 = + (w₁ * σ₁ - w₂ * σ₂) * (w₁ * σ₁ + w₂ * σ₂) := by + simp [riskContribution, marginalVariance, covTwo, Fin.sum_univ_two] + ring + have hpos : w₁ * σ₁ + w₂ * σ₂ ≠ 0 := (add_pos (mul_pos hw₁ hσ₁) (mul_pos hw₂ hσ₂)).ne' + rw [riskParityWeightTwo, eq_div_iff (add_pos hσ₁ hσ₂).ne'] + constructor + · intro h + have h0 := (mul_eq_zero.1 (hRC.symm.trans (sub_eq_zero.2 + (h 0 (Finset.mem_univ _) 1 (Finset.mem_univ _))))).resolve_right hpos + linear_combination h0 + σ₂ * hsum + · intro h i _ j _ + have h01 := sub_eq_zero.1 (hRC.trans (by + rw [show w₁ * σ₁ - w₂ * σ₂ = 0 by linear_combination h - σ₂ * hsum, zero_mul])) + fin_cases i <;> fin_cases j + exacts [rfl, h01, h01.symm, rfl] + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/RiskParityFOC.lean b/LeanPool/MathFin/Choice/Portfolio/RiskParityFOC.lean new file mode 100644 index 0000000000..ed338320d2 --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/RiskParityFOC.lean @@ -0,0 +1,329 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Portfolio.CAPMEquilibrium +public import Mathlib.Analysis.InnerProductSpace.Basic +public import Mathlib.Analysis.SpecialFunctions.Log.Deriv +public import Mathlib.Topology.Algebra.Module.ModuleTopology + +/-! +# Risk-parity portfolios from the log-barrier Lagrangian (first-principles) + +The pre-existing `Choice/Portfolio/RiskParity.lean` states the 2-asset closed form +`w_1^{RP} = σ_2 / (σ_1 + σ_2)` and verifies the equal-risk-contribution +identity algebraically (no derivation from a variational principle). + +This file derives the N-asset risk-parity / risk-budget conditions from the +first-order condition of the canonical convex programme used in the +risk-parity literature (Roncalli 2014, Maillard-Roncalli-Teïletche 2010): + + `min_w (1/2) · w^T Σ w − ∑_i b_i · log(w_i)`, `w_i > 0`. + +The FOC is + + `(Σw)_i = b_i / w_i`, for every `i`, + +equivalently `w_i · (Σw)_i = b_i` (risk contribution `RC_i` equals the +prescribed risk budget `b_i`). Risk parity is the special case `b_i = c` +constant — all assets contribute equally to variance. + +## Why this is "first principles" + +Risk parity was previously stated as an algebraic identity at closed-form +weights. This file shows it as the *output of an optimisation*: critical +points of the log-barrier-regularised variance minimisation satisfy the +risk-budget property. The 2-asset closed form `σ_2 / (σ_1 + σ_2)` has equal +risk contributions (`RiskParity.lean`; `isRiskParity_two_iff` shows it is the +only long-only budget portfolio that does), so it satisfies this FOC with the +uniform budget `b_i = RC_i = Var(w)/2`. For the budget `b_i = 1/N` the solution +is that portfolio rescaled, since `RC_i(t·w) = t²·RC_i(w)`; the rescaling is not +formalized here. + +## Main definitions + +* `riskContribution`: the contribution `wᵢ (Σw)ᵢ` of asset `i` to the portfolio variance. +* `IsRiskParity`: all assets have the same risk contribution. +* `IsRiskBudgetPortfolio`: each asset's risk contribution equals a prescribed budget `bᵢ`. +* `logBarrierObj`: the log-barrier objective `(1/2) wᵀ Σ w − ∑ᵢ bᵢ log wᵢ` whose critical points + are the risk-budget portfolios. + +## Main results + +* `sum_riskContribution_eq_variance`: `∑ RC_i = w^T Σ w`. +* `isRiskBudget_of_log_barrier_FOC` (forward derivation): FOC `(Σw)_i = + b_i / w_i` ⟹ risk-budget property. +* `isRiskParity_of_uniform_log_barrier_FOC`: specialisation with uniform + budget ⟹ risk parity. +* `isRiskParity_iff_cross_product`: equivalent cross-product + characterisation. + +## Tags + +risk parity, risk budgeting, log-barrier, equal risk contribution, Roncalli, first-order condition, +convex programme, MSC 91G10, MSC 90C25, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +open Finset + +/-- **Risk contribution of asset `i`** in portfolio `w` under covariance +matrix `Sg`: `RC_i := w_i · (Σw)_i`. The sum of risk contributions equals +the portfolio variance. -/ +def riskContribution {ι : Type*} (s : Finset ι) (Sg : ι → ι → ℝ) + (w : ι → ℝ) (i : ι) : ℝ := + w i * marginalVariance s Sg w i + +/-- **Sum-of-risk-contributions identity**: `∑_i RC_i = Var(w) = w · (Σw)`. -/ +lemma sum_riskContribution_eq_variance + {ι : Type*} (s : Finset ι) (Sg : ι → ι → ℝ) (w : ι → ℝ) : + ∑ i ∈ s, riskContribution s Sg w i = portfolioVarN s w Sg := by + rw [portfolioVarN_eq_sum_mul_marginalVariance] + rfl + +/-- **Equal-risk-contribution property ("risk parity")**: all assets +contribute the same amount of risk to portfolio variance, i.e., `RC_i = RC_j` +for every pair `(i, j) ∈ s × s`. -/ +def IsRiskParity {ι : Type*} (s : Finset ι) (Sg : ι → ι → ℝ) + (w : ι → ℝ) : Prop := + ∀ i ∈ s, ∀ j ∈ s, + riskContribution s Sg w i = riskContribution s Sg w j + +/-- **Risk-budget portfolio**: each asset's risk contribution matches a +prescribed budget `b_i`. Risk parity is the uniform-budget specialisation. -/ +def IsRiskBudgetPortfolio {ι : Type*} (s : Finset ι) (Sg : ι → ι → ℝ) + (w b : ι → ℝ) : Prop := + ∀ i ∈ s, riskContribution s Sg w i = b i + +/-- **Forward derivation: risk-budget property from log-barrier Lagrangian +FOC**. The critical-point condition + + `(Σw)_i = b_i / w_i` for all `i ∈ s` with `w_i ≠ 0`, + +(which is the FOC of `(1/2) w^T Σ w − ∑_i b_i log(w_i)`) implies the +risk-budget identity `w_i · (Σw)_i = b_i`. -/ +theorem isRiskBudget_of_log_barrier_FOC + {ι : Type*} (s : Finset ι) (Sg : ι → ι → ℝ) + (w b : ι → ℝ) + (h_pos : ∀ i ∈ s, w i ≠ 0) + (h_FOC : ∀ i ∈ s, marginalVariance s Sg w i = b i / w i) : + IsRiskBudgetPortfolio s Sg w b := by + intro i hi + unfold riskContribution + rw [h_FOC i hi, mul_div_assoc', mul_comm, mul_div_assoc, div_self (h_pos i hi), mul_one] + +/-- **Risk parity from uniform-budget log-barrier FOC**: if the FOC holds +with the *same* constant `c` for every asset (uniform risk budget), then +the portfolio satisfies the equal-risk-contribution property. -/ +theorem isRiskParity_of_uniform_log_barrier_FOC + {ι : Type*} (s : Finset ι) (Sg : ι → ι → ℝ) + (w : ι → ℝ) (c : ℝ) + (h_pos : ∀ i ∈ s, w i ≠ 0) + (h_FOC : ∀ i ∈ s, marginalVariance s Sg w i = c / w i) : + IsRiskParity s Sg w := by + intro i hi j hj + unfold riskContribution + rw [h_FOC i hi, h_FOC j hj, + mul_div_assoc', mul_comm (w i) c, mul_div_assoc, div_self (h_pos i hi), mul_one, + mul_div_assoc', mul_comm (w j) c, mul_div_assoc, div_self (h_pos j hj), mul_one] + +/-- **Cross-product characterisation of risk parity**: `RC_i = RC_j` is +literally `w_i · (Σw)_i = w_j · (Σw)_j`. This is the form used in numerical +solvers (project onto the equal-contribution hyperplane). -/ +theorem isRiskParity_iff_cross_product + {ι : Type*} (s : Finset ι) (Sg : ι → ι → ℝ) (w : ι → ℝ) : + IsRiskParity s Sg w ↔ + ∀ i ∈ s, ∀ j ∈ s, + w i * marginalVariance s Sg w i = w j * marginalVariance s Sg w j := by + unfold IsRiskParity riskContribution + rfl + +/-- **Risk parity implies each `RC_i = Var(w) / |s|`**: at a risk-parity +portfolio, every asset contributes `1/N`-th of the total variance. -/ +theorem riskContribution_eq_variance_div_card_of_riskParity + {ι : Type*} (s : Finset ι) (Sg : ι → ι → ℝ) + (w : ι → ℝ) (i : ι) (hi : i ∈ s) (hs : s.Nonempty) + (h_RP : IsRiskParity s Sg w) : + riskContribution s Sg w i = + portfolioVarN s w Sg / (s.card : ℝ) := by + have h_card_pos : 0 < (s.card : ℝ) := by exact_mod_cast s.card_pos.mpr hs + have h_card_ne : (s.card : ℝ) ≠ 0 := h_card_pos.ne' + -- ∑ RC_j = card · RC_i (since all are equal) + have h_sum : ∑ j ∈ s, riskContribution s Sg w j = + (s.card : ℝ) * riskContribution s Sg w i := by + have h_all_eq : ∀ j ∈ s, + riskContribution s Sg w j = riskContribution s Sg w i := fun j hj ↦ h_RP j hj i hi + rw [Finset.sum_congr rfl h_all_eq, Finset.sum_const, nsmul_eq_mul] + rw [sum_riskContribution_eq_variance] at h_sum + field_simp + linarith + +/-- **Log-barrier risk-parity objective**. The canonical convex programme whose +critical points are the risk-budget portfolios: + + `L(w) = (1/2) · wᵀ Σ w − ∑_i b_i · log(w_i)`. + +Minimising `L` subject to `w > 0` is the standard risk-parity formulation +(Maillard–Roncalli–Teïletche 2010, Roncalli 2014). -/ +noncomputable def logBarrierObj {ι : Type*} (s : Finset ι) (Sg : ι → ι → ℝ) + (b w : ι → ℝ) : ℝ := + (1 / 2 : ℝ) * portfolioVarN s w Sg - ∑ i ∈ s, b i * Real.log (w i) + +/-- **Directional derivative of the log-barrier objective** along coordinate +`j`. Freezing all weights except `w_j` and differentiating `L` in `w_j` at the +base point yields + + `∂L/∂w_j = (Σw)_j − b_j / w_j`. + +The quadratic term contributes `(Σw)_j` (its `w_j`-gradient is `2·(Σw)_j` by +symmetry of `Σ`, halved), and the log-barrier term contributes `− b_j / w_j`. -/ +theorem hasDerivAt_logBarrierObj_update + {ι : Type*} [DecidableEq ι] (s : Finset ι) (Sg : ι → ι → ℝ) (b w : ι → ℝ) + (j : ι) (hj : j ∈ s) (hSg : ∀ a c, Sg a c = Sg c a) (hwj : w j ≠ 0) : + HasDerivAt (fun x ↦ logBarrierObj s Sg b (Function.update w j x)) + (marginalVariance s Sg w j - b j / w j) (w j) := by + -- === derivative of the quadratic term === + -- coordinate factor: d/dx (update w j x) k = [k = j] + have hu : ∀ k, HasDerivAt (fun x ↦ Function.update w j x k) + (if k = j then (1 : ℝ) else 0) (w j) := by + intro k + by_cases hk : k = j + · rw [ite_eq_left hk] + have hfun : (fun x ↦ Function.update w j x k) = fun x ↦ x := by + funext x; rw [hk, Function.update_self] + rw [hfun]; exact hasDerivAt_id (w j) + · rw [ite_eq_right hk] + have hfun : (fun x ↦ Function.update w j x k) = fun _ ↦ w k := by + funext x; rw [Function.update_of_ne hk] + rw [hfun]; exact hasDerivAt_const (w j) (w k) + -- inner marginal factor: d/dx ∑_l Sg k l · (update w j x) l = Sg k j + have hv : ∀ k, HasDerivAt (fun x ↦ ∑ l ∈ s, Sg k l * Function.update w j x l) + (Sg k j) (w j) := by + intro k + have hterm : ∀ l, HasDerivAt (fun x ↦ Sg k l * Function.update w j x l) + (if l = j then Sg k j else 0) (w j) := by + intro l + by_cases hl : l = j + · rw [ite_eq_left hl] + have hfun : (fun x ↦ Sg k l * Function.update w j x l) + = fun x ↦ Sg k l * x := by funext x; rw [hl, Function.update_self] + rw [hfun, hl] + simpa using (hasDerivAt_id (w j)).const_mul (Sg k j) + · rw [ite_eq_right hl] + have hfun : (fun x ↦ Sg k l * Function.update w j x l) + = fun _ ↦ Sg k l * w l := by funext x; rw [Function.update_of_ne hl] + rw [hfun]; exact hasDerivAt_const (w j) (Sg k l * w l) + have hsum : HasDerivAt (fun x ↦ ∑ l ∈ s, Sg k l * Function.update w j x l) + (∑ l ∈ s, if l = j then Sg k j else 0) (w j) := + HasDerivAt.fun_sum (fun l (_ : l ∈ s) ↦ hterm l) + rw [Finset.sum_ite_eq' s j, ite_eq_left hj] at hsum + exact hsum + -- product rule per outer index k + have hF : ∀ k, HasDerivAt + (fun x ↦ Function.update w j x k * ∑ l ∈ s, Sg k l * Function.update w j x l) + ((if k = j then (1 : ℝ) else 0) + * (∑ l ∈ s, Sg k l * Function.update w j (w j) l) + + Function.update w j (w j) k * Sg k j) (w j) := + fun k ↦ (hu k).mul (hv k) + -- sum over k: derivative of the whole quadratic (pre-simplification) + have hsum : HasDerivAt + (fun x ↦ ∑ k ∈ s, + Function.update w j x k * ∑ l ∈ s, Sg k l * Function.update w j x l) + (∑ k ∈ s, ((if k = j then (1 : ℝ) else 0) + * (∑ l ∈ s, Sg k l * Function.update w j (w j) l) + + Function.update w j (w j) k * Sg k j)) (w j) := + HasDerivAt.fun_sum (fun k (_ : k ∈ s) ↦ hF k) + -- identify that sum with `portfolioVarN ∘ update` + have hfun : (fun x ↦ portfolioVarN s (Function.update w j x) Sg) + = (fun x ↦ ∑ k ∈ s, + Function.update w j x k * ∑ l ∈ s, Sg k l * Function.update w j x l) := by + funext x; rw [portfolioVarN_eq_sum_mul_marginalVariance]; rfl + -- simplify the derivative sum to `2 · (Σw)_j` + have hderiv_eq : + (∑ k ∈ s, ((if k = j then (1 : ℝ) else 0) + * (∑ l ∈ s, Sg k l * Function.update w j (w j) l) + + Function.update w j (w j) k * Sg k j)) + = 2 * marginalVariance s Sg w j := by + simp only [Function.update_eq_self] + rw [Finset.sum_add_distrib] + have h1 : (∑ k ∈ s, (if k = j then (1 : ℝ) else 0) * ∑ l ∈ s, Sg k l * w l) + = marginalVariance s Sg w j := by + have hcongr : ∀ k ∈ s, + (if k = j then (1 : ℝ) else 0) * (∑ l ∈ s, Sg k l * w l) + = if k = j then (∑ l ∈ s, Sg k l * w l) else 0 := by + intro k _; by_cases hk : k = j <;> simp [hk] + rw [Finset.sum_congr rfl hcongr, Finset.sum_ite_eq' s j, ite_eq_left hj] + rfl + have h2 : (∑ k ∈ s, w k * Sg k j) = marginalVariance s Sg w j := by + unfold marginalVariance + refine Finset.sum_congr rfl (fun k _ ↦ ?_) + rw [hSg k j]; ring + rw [h1, h2]; ring + -- assemble: half the quadratic derivative + have hPV : HasDerivAt (fun x ↦ portfolioVarN s (Function.update w j x) Sg) + (2 * marginalVariance s Sg w j) (w j) := by + rw [hfun, ← hderiv_eq]; exact hsum + have hHalf : HasDerivAt + (fun x ↦ (1 / 2 : ℝ) * portfolioVarN s (Function.update w j x) Sg) + (marginalVariance s Sg w j) (w j) := by + have h := hPV.const_mul (1 / 2 : ℝ) + have he : (1 / 2 : ℝ) * (2 * marginalVariance s Sg w j) + = marginalVariance s Sg w j := by ring + rwa [he] at h + -- === derivative of the log-barrier term === + have hLog : HasDerivAt + (fun x ↦ ∑ i ∈ s, b i * Real.log (Function.update w j x i)) + (b j / w j) (w j) := by + have hterm : ∀ i, HasDerivAt (fun x ↦ b i * Real.log (Function.update w j x i)) + (if i = j then b j / w j else 0) (w j) := by + intro i + by_cases hi : i = j + · rw [ite_eq_left hi] + have hfun : (fun x ↦ b i * Real.log (Function.update w j x i)) + = fun x ↦ b i * Real.log x := by + funext x; rw [hi, Function.update_self] + rw [hfun, hi, div_eq_mul_inv] + exact (Real.hasDerivAt_log hwj).const_mul (b j) + · rw [ite_eq_right hi] + have hfun : (fun x ↦ b i * Real.log (Function.update w j x i)) + = fun _ ↦ b i * Real.log (w i) := by + funext x; rw [Function.update_of_ne hi] + rw [hfun]; exact hasDerivAt_const (w j) (b i * Real.log (w i)) + have hsumLog : HasDerivAt + (fun x ↦ ∑ i ∈ s, b i * Real.log (Function.update w j x i)) + (∑ i ∈ s, if i = j then b j / w j else 0) (w j) := + HasDerivAt.fun_sum (fun i (_ : i ∈ s) ↦ hterm i) + rw [Finset.sum_ite_eq' s j, ite_eq_left hj] at hsumLog + exact hsumLog + -- === combine === + unfold logBarrierObj + exact hHalf.sub hLog + +/-- **Critical-point characterisation of risk budgeting**: the log-barrier +objective is stationary in the `w_j`-direction (`HasDerivAt … 0`) *iff* the +risk-parity FOC `(Σw)_j = b_j / w_j` holds. This is the first-principles +statement — the FOC *assumed* in `isRiskBudget_of_log_barrier_FOC` is exactly +the condition for `w` to be a critical point of `L`. -/ +theorem logBarrierObj_critical_iff_FOC + {ι : Type*} [DecidableEq ι] (s : Finset ι) (Sg : ι → ι → ℝ) (b w : ι → ℝ) + (j : ι) (hj : j ∈ s) (hSg : ∀ a c, Sg a c = Sg c a) (hwj : w j ≠ 0) : + HasDerivAt (fun x ↦ logBarrierObj s Sg b (Function.update w j x)) 0 (w j) ↔ + marginalVariance s Sg w j = b j / w j := by + have hd := hasDerivAt_logBarrierObj_update s Sg b w j hj hSg hwj + constructor + · intro h0 + have h := hd.unique h0 + linarith [h] + · intro hfoc + have hz : marginalVariance s Sg w j - b j / w j = 0 := by rw [hfoc]; ring + rwa [hz] at hd + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/SharpeFOCDerivation.lean b/LeanPool/MathFin/Choice/Portfolio/SharpeFOCDerivation.lean new file mode 100644 index 0000000000..4bad8dd7ac --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/SharpeFOCDerivation.lean @@ -0,0 +1,250 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Portfolio.Markowitz +public import LeanPool.MathFin.Choice.Performance.Ratios +public import Mathlib.Algebra.Ring.IsFormallyReal + +/-! +# Markowitz cross-product FOC derived from Sharpe-ratio maximization + +The pre-existing `tangentTwo_satisfies_FOC` in `Choice.Portfolio.TangentPortfolio` +verifies that the closed-form weight `tangentWeightTwo` satisfies the +cross-product FOC `r₂ · (Σw)₁ = r₁ · (Σw)₂` by direct algebra (`ring`). It +does **not derive** that FOC from a maximization problem. + +This file closes that gap. It + +1. defines the two-asset Sharpe-ratio-squared + `Sh²(w) = E(w)² / V(w)` where `E(w) = w r₁ + (1 − w) r₂`, + `V(w) = w² σ₁² + (1 − w)² σ₂² + 2 w (1 − w) ρ σ₁ σ₂`; +2. proves `HasDerivAt` of `Sh²` with the textbook formula + `Sh²'(w) = (2 E E' V − E² V') / V²`; +3. shows the numerator factors as + `2 E E' V − E² V' = 2 E · (r₁ · (Σw)₂ − r₂ · (Σw)₁)`; +4. concludes that the critical points of `Sh²` (where `E ≠ 0`, `V > 0`) + are precisely the points where the cross-product FOC holds. + +## Why this is "first principles" + +The existing infrastructure stops at "the closed form satisfies the FOC". +This file derives the FOC itself from a maximization problem — closing the +loop between the optimization-theoretic and algebraic perspectives. + +## Main definitions + +* `expectedReturnTwo`: the two-asset expected return `w r₁ + (1 − w) r₂`. +* `varianceTwo`: the two-asset variance as a function of the weight `w` on asset 1 + (`portfolioVarTwo` of `Choice/Portfolio/Markowitz.lean` with the weight as first argument). +* `marginalVarOne`, `marginalVarTwo`: the components `(Σw)₁`, `(Σw)₂` of the marginal variance. +* `sharpeSqTwo`: the squared Sharpe ratio `E(w)² / V(w)` as a function of `w`. + +## Main results + +* `sharpeSqTwo_eq_sharpeRatio_sq`: for `V(w) ≥ 0`, `Sh²(w)` is the squared `sharpeRatio` of the + portfolio return (zero risk-free rate) at volatility `√V(w)`. +* `varianceTwo_eq_w_dot_Sigma_w`: `V = w · (Σw)₁ + (1 − w) · (Σw)₂` (the + self-dot identity). +* `hasDerivAt_varianceTwo`: `V'(w) = 2 · ((Σw)₁ − (Σw)₂)`. +* `sharpeSqTwo_deriv_numerator_factored`: the derivative numerator + factors through `r₁ (Σw)₂ − r₂ (Σw)₁`. +* `sharpeSqTwo_critical_iff_crossProduct_FOC`: critical-point + characterisation (`E ≠ 0, V > 0` regime). + +## References + +* [H. Markowitz, *Portfolio selection*][Markowitz1952] +* [Sharpe, *Capital asset prices*][Sharpe1964] + +## Tags + +Sharpe ratio maximization, tangent portfolio, first-order condition, Markowitz, +maximum Sharpe portfolio, MSC 91G10, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +/-- Two-asset expected excess return parameterised by weight `w` on asset 1 +(with `1 − w` on asset 2). -/ +noncomputable def expectedReturnTwo (w r₁ r₂ : ℝ) : ℝ := w * r₁ + (1 - w) * r₂ + +/-- Two-asset portfolio variance as a function of the weight `w`: the library's +`portfolioVarTwo` (`Choice/Portfolio/Markowitz.lean`) with the weight as first argument. -/ +noncomputable def varianceTwo (w σ₁ σ₂ ρ : ℝ) : ℝ := + portfolioVarTwo σ₁ σ₂ ρ w + +/-- Marginal variance contribution of asset 1: `(Σw)₁ = w σ₁² + (1−w) ρ σ₁ σ₂`. -/ +noncomputable def marginalVarOne (w σ₁ σ₂ ρ : ℝ) : ℝ := + w * σ₁^2 + (1 - w) * ρ * σ₁ * σ₂ + +/-- Marginal variance contribution of asset 2: `(Σw)₂ = w ρ σ₁ σ₂ + (1−w) σ₂²`. -/ +noncomputable def marginalVarTwo (w σ₁ σ₂ ρ : ℝ) : ℝ := + w * ρ * σ₁ * σ₂ + (1 - w) * σ₂^2 + +/-- Two-asset Sharpe-ratio squared as a function of weight `w`. -/ +noncomputable def sharpeSqTwo (w r₁ r₂ σ₁ σ₂ ρ : ℝ) : ℝ := + (expectedReturnTwo w r₁ r₂)^2 / (varianceTwo w σ₁ σ₂ ρ) + +/-- **The two-asset Sharpe ratio squared is the squared Sharpe ratio** of the portfolio return +with zero risk-free rate (`returns` are excess returns): `Sh²(w) = sharpeRatio E(w) 0 σ(w) ^ 2`, +with `σ(w) = √V(w)` the portfolio volatility. `V(w)` is the variance of `w R₁ + (1 − w) R₂` +(`portfolioVarTwo_eq_variance`, `Choice/Portfolio/MarkowitzLagrangian.lean`). -/ +theorem sharpeSqTwo_eq_sharpeRatio_sq (w r₁ r₂ σ₁ σ₂ ρ : ℝ) (hV : 0 ≤ varianceTwo w σ₁ σ₂ ρ) : + sharpeSqTwo w r₁ r₂ σ₁ σ₂ ρ + = sharpeRatio (expectedReturnTwo w r₁ r₂) 0 (√(varianceTwo w σ₁ σ₂ ρ)) ^ 2 := by + rw [sharpeSqTwo, sharpeRatio, sub_zero, div_pow, Real.sq_sqrt hV] + +/-- **Self-dot identity for V**: `V(w) = w · (Σw)₁ + (1 − w) · (Σw)₂`. -/ +lemma varianceTwo_eq_w_dot_Sigma_w (w σ₁ σ₂ ρ : ℝ) : + varianceTwo w σ₁ σ₂ ρ = + w * marginalVarOne w σ₁ σ₂ ρ + (1 - w) * marginalVarTwo w σ₁ σ₂ ρ := by + unfold varianceTwo portfolioVarTwo marginalVarOne marginalVarTwo + ring + +/-- **Derivative of `E(w) = w r₁ + (1 − w) r₂`** is `r₁ − r₂`. -/ +lemma hasDerivAt_expectedReturnTwo (w r₁ r₂ : ℝ) : + HasDerivAt (fun w' ↦ expectedReturnTwo w' r₁ r₂) (r₁ - r₂) w := by + unfold expectedReturnTwo + have h1 : HasDerivAt (fun w' : ℝ ↦ w' * r₁) r₁ w := by + simpa using (hasDerivAt_id w).mul_const r₁ + have h_sub : HasDerivAt (fun w' : ℝ ↦ (1 : ℝ) - w') (-1) w := by + simpa using (hasDerivAt_id w).const_sub 1 + have h2 : HasDerivAt (fun w' : ℝ ↦ (1 - w') * r₂) (-r₂) w := by + have := h_sub.mul_const r₂ + simpa using this + have h := h1.add h2 + convert h using 1 + +/-- **Derivative of `V(w) = w² σ₁² + (1−w)² σ₂² + 2 w (1−w) ρ σ₁ σ₂`** is +`V'(w) = 2 · ((Σw)₁ − (Σw)₂)`. Proof: polynomial rewrite of `V` in the form +`A w² + B w + C`, then `(A w² + B w + C)' = 2 A w + B`. -/ +lemma hasDerivAt_varianceTwo (w σ₁ σ₂ ρ : ℝ) : + HasDerivAt (fun w' ↦ varianceTwo w' σ₁ σ₂ ρ) + (2 * (marginalVarOne w σ₁ σ₂ ρ - marginalVarTwo w σ₁ σ₂ ρ)) w := by + -- Rewrite V as A w² + B w + C + have h_v_poly : (fun w' : ℝ ↦ varianceTwo w' σ₁ σ₂ ρ) = + (fun w' ↦ (σ₁^2 + σ₂^2 - 2*ρ*σ₁*σ₂) * w'^2 + + (-2*σ₂^2 + 2*ρ*σ₁*σ₂) * w' + σ₂^2) := by + funext w' + unfold varianceTwo portfolioVarTwo + ring + rw [h_v_poly] + have h_sq : HasDerivAt (fun w' : ℝ ↦ w'^2) (2*w) w := by + have := hasDerivAt_pow 2 w + convert this using 1; push_cast; ring + have h_term1 := h_sq.const_mul (σ₁^2 + σ₂^2 - 2*ρ*σ₁*σ₂) + have h_term2 := (hasDerivAt_id w).const_mul (-2*σ₂^2 + 2*ρ*σ₁*σ₂) + have h_term3 : HasDerivAt (fun _ : ℝ ↦ (σ₂^2 : ℝ)) 0 w := hasDerivAt_const w _ + have h := (h_term1.add h_term2).add h_term3 + convert h using 1 <;> first | rfl | (unfold marginalVarOne marginalVarTwo; ring) + +/-- **Derivative of `E²(w)`** is `2 E (r₁ − r₂)`. -/ +lemma hasDerivAt_expectedReturnTwo_sq (w r₁ r₂ : ℝ) : + HasDerivAt (fun w' ↦ (expectedReturnTwo w' r₁ r₂)^2) + (2 * expectedReturnTwo w r₁ r₂ * (r₁ - r₂)) w := by + have h := (hasDerivAt_expectedReturnTwo w r₁ r₂).pow 2 + convert h using 1; push_cast; ring + +/-- **Derivative of `Sh²(w) = E²/V`**: textbook formula `Sh²'(w) = (2EE'V − E²V')/V²`. -/ +theorem hasDerivAt_sharpeSqTwo (w r₁ r₂ σ₁ σ₂ ρ : ℝ) + (hV : varianceTwo w σ₁ σ₂ ρ ≠ 0) : + HasDerivAt (fun w' ↦ sharpeSqTwo w' r₁ r₂ σ₁ σ₂ ρ) + ((2 * expectedReturnTwo w r₁ r₂ * (r₁ - r₂) * + varianceTwo w σ₁ σ₂ ρ - + (expectedReturnTwo w r₁ r₂)^2 * + (2 * (marginalVarOne w σ₁ σ₂ ρ - marginalVarTwo w σ₁ σ₂ ρ))) / + (varianceTwo w σ₁ σ₂ ρ)^2) w := by + unfold sharpeSqTwo + exact (hasDerivAt_expectedReturnTwo_sq w r₁ r₂).div + (hasDerivAt_varianceTwo w σ₁ σ₂ ρ) hV + +/-- **Algebraic factorization of the Sh² derivative numerator**: + + `2 E E' V − E² V' = 2 E · (r₁ (Σw)₂ − r₂ (Σw)₁)`. + +This factorization is the algebraic content of the cross-product FOC: setting +the numerator to zero (with `E ≠ 0`) reduces to `r₁ (Σw)₂ = r₂ (Σw)₁`. + +The identity is proved by `ring` after unfolding all definitions; the +non-trivial cancellation is that `(r₁ − r₂) V − E ((Σw)₁ − (Σw)₂)` simplifies +exactly to `r₁ (Σw)₂ − r₂ (Σw)₁`. -/ +theorem sharpeSqTwo_deriv_numerator_factored (w r₁ r₂ σ₁ σ₂ ρ : ℝ) : + 2 * expectedReturnTwo w r₁ r₂ * (r₁ - r₂) * varianceTwo w σ₁ σ₂ ρ - + (expectedReturnTwo w r₁ r₂)^2 * + (2 * (marginalVarOne w σ₁ σ₂ ρ - marginalVarTwo w σ₁ σ₂ ρ)) = + 2 * expectedReturnTwo w r₁ r₂ * + (r₁ * marginalVarTwo w σ₁ σ₂ ρ - r₂ * marginalVarOne w σ₁ σ₂ ρ) := by + unfold expectedReturnTwo varianceTwo portfolioVarTwo marginalVarOne marginalVarTwo + ring + +/-- **Critical-point characterisation**: in the `E ≠ 0`, `V > 0` regime, the +Sharpe-ratio squared has a critical point at `w` (i.e., `HasDerivAt Sh² 0 w`) +*if and only if* the cross-product FOC `r₂ (Σw)₁ = r₁ (Σw)₂` holds. + +This is the first-principles derivation: the FOC arises as the +critical-point condition of a real maximization problem, not as a stated +algebraic identity. -/ +theorem sharpeSqTwo_critical_iff_crossProduct_FOC + (w r₁ r₂ σ₁ σ₂ ρ : ℝ) (hV : varianceTwo w σ₁ σ₂ ρ ≠ 0) + (hE : expectedReturnTwo w r₁ r₂ ≠ 0) : + HasDerivAt (fun w' ↦ sharpeSqTwo w' r₁ r₂ σ₁ σ₂ ρ) 0 w ↔ + r₂ * marginalVarOne w σ₁ σ₂ ρ = r₁ * marginalVarTwo w σ₁ σ₂ ρ := by + -- (a) The derivative computed above is unique; if HasDerivAt f 0 w, then + -- the computed expression equals 0. + have h_deriv := hasDerivAt_sharpeSqTwo w r₁ r₂ σ₁ σ₂ ρ hV + constructor + · intro h_zero + -- Uniqueness of HasDerivAt: both derivatives must agree + have h_eq : (2 * expectedReturnTwo w r₁ r₂ * (r₁ - r₂) * + varianceTwo w σ₁ σ₂ ρ - + (expectedReturnTwo w r₁ r₂)^2 * + (2 * (marginalVarOne w σ₁ σ₂ ρ - marginalVarTwo w σ₁ σ₂ ρ))) / + (varianceTwo w σ₁ σ₂ ρ)^2 = 0 := h_deriv.unique h_zero + have hV_sq : (varianceTwo w σ₁ σ₂ ρ)^2 ≠ 0 := pow_ne_zero _ hV + -- Division-by-nonzero is zero implies numerator is zero + have h_num : 2 * expectedReturnTwo w r₁ r₂ * (r₁ - r₂) * + varianceTwo w σ₁ σ₂ ρ - + (expectedReturnTwo w r₁ r₂)^2 * + (2 * (marginalVarOne w σ₁ σ₂ ρ - marginalVarTwo w σ₁ σ₂ ρ)) = 0 := + (div_eq_zero_iff.mp h_eq).resolve_right hV_sq + -- Apply the algebraic factorization + rw [sharpeSqTwo_deriv_numerator_factored] at h_num + -- 2 * E * (r₁·(Σw)₂ - r₂·(Σw)₁) = 0 + have : r₁ * marginalVarTwo w σ₁ σ₂ ρ - r₂ * marginalVarOne w σ₁ σ₂ ρ = 0 := by + have h2E_ne : (2 * expectedReturnTwo w r₁ r₂) ≠ 0 := by + simp [hE] + have : (2 * expectedReturnTwo w r₁ r₂) * + (r₁ * marginalVarTwo w σ₁ σ₂ ρ - r₂ * marginalVarOne w σ₁ σ₂ ρ) = 0 := h_num + rcases mul_eq_zero.mp this with h | h + · exact absurd h h2E_ne + · exact h + linarith + · intro h_foc + -- r₂ (Σw)₁ = r₁ (Σw)₂ ⟹ derivative is 0 + -- Use the factorization: 2EE'V - E²V' = 2E(r₁(Σw)₂ - r₂(Σw)₁) = 2E·0 = 0 + have h_diff_zero : r₁ * marginalVarTwo w σ₁ σ₂ ρ - + r₂ * marginalVarOne w σ₁ σ₂ ρ = 0 := by linarith + have h_num_zero : 2 * expectedReturnTwo w r₁ r₂ * (r₁ - r₂) * + varianceTwo w σ₁ σ₂ ρ - + (expectedReturnTwo w r₁ r₂)^2 * + (2 * (marginalVarOne w σ₁ σ₂ ρ - marginalVarTwo w σ₁ σ₂ ρ)) = 0 := by + rw [sharpeSqTwo_deriv_numerator_factored] + rw [h_diff_zero]; ring + have h_zero_div : (2 * expectedReturnTwo w r₁ r₂ * (r₁ - r₂) * + varianceTwo w σ₁ σ₂ ρ - + (expectedReturnTwo w r₁ r₂)^2 * + (2 * (marginalVarOne w σ₁ σ₂ ρ - marginalVarTwo w σ₁ σ₂ ρ))) / + (varianceTwo w σ₁ σ₂ ρ)^2 = 0 := by + rw [h_num_zero]; simp + rw [← h_zero_div] + exact h_deriv + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/SingleIndexModel.lean b/LeanPool/MathFin/Choice/Portfolio/SingleIndexModel.lean new file mode 100644 index 0000000000..3cdd08b185 --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/SingleIndexModel.lean @@ -0,0 +1,203 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Portfolio.MarkowitzNAsset +public import LeanPool.MathFin.Choice.Portfolio.CovariancePSD +public import LeanPool.MathFin.Choice.Portfolio.CAPM + +/-! +# Single-index covariance structure and its large-`N` limit + +Sharpe's single-index model writes each asset's return as `Rᵢ = βᵢ·R_M + εᵢ`, with idiosyncratic +shocks `εᵢ` uncorrelated across assets and with the market. The implied covariance kernel is +`Σ = ββ'σ_M² + D_ε` (`D_ε` diagonal). The passage from the return model to this kernel is +`covariance_singleIndex`: for square-integrable `R_M` and `εᵢ`, with the shocks uncorrelated with +the market and with each other, `cov(Rᵢ, Rⱼ)` is the kernel with `D_ε(i) = Var[εᵢ]`, by +bilinearity of covariance. With the self-dot identity of `Choice/Portfolio/CovariancePSD.lean` this +gives +the variance of the random portfolio return (`variance_singleIndex_portfolio`), and the loading +`βᵢ` is the CAPM beta `cov(Rᵢ, R_M)/Var[R_M]` of `Choice/Portfolio/CAPM.lean` (`beta_singleIndex`). +On the kernel itself, with `Choice/Portfolio/MarkowitzNAsset.lean`'s sum-form portfolio variance: + + `Var(Rp) = (w'β)² σ_M² + w'D_εw`, + +in which, for nonnegative, uniformly bounded idiosyncratic variances and the equal-weight +portfolio, the idiosyncratic term tends to `0` as `n → ∞`: idiosyncratic risk diversifies away. +The limit is stated for the idiosyncratic term alone; that `Var(Rp)` minus the systematic term +`(β_p σ_M)²` tends to `0` follows with `portfolioVarN_singleIndex_eq` but is not stated. + +## Main definitions + +* `singleIndexKernel`: the single-index covariance kernel + `σᵢⱼ = βᵢβⱼσ_M² + 1[i=j]·D_ε(i)`. + +## Main results + +* `portfolioVarN_singleIndex_eq`: `Var(Rp) = (∑ wᵢβᵢ)² σ_M² + ∑ wᵢ² D_ε(i)`. +* `idiosyncraticTerm_equalWeight_le`: for equal weights `1/n` and idiosyncratic variances + bounded by `M`, the idiosyncratic term is at most `M / n`. +* `tendsto_idiosyncraticTerm_equalWeight_zero`: hence, for nonnegative variances bounded by `M`, + it tends to `0` as `n → ∞` (idiosyncratic risk diversifies away under equal weighting). +* `covariance_singleIndex`: the covariance of the return model is `singleIndexKernel`. +* `variance_singleIndex_portfolio`: `Var[∑ wᵢRᵢ] = (∑ wᵢβᵢ)² Var[R_M] + ∑ wᵢ² Var[εᵢ]`. +* `beta_singleIndex`: the CAPM beta of asset `i` is `βᵢ`. + +## References + +* [Sharpe, *A simplified model for portfolio analysis*][Sharpe1963] +* [Sharpe, *Capital asset prices*][Sharpe1964] + +## Tags + +single-index model, Sharpe's index model, idiosyncratic risk, systematic risk, diversification, +market model, beta, MSC 91G10, MSC 62P05, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +open Filter Topology + +variable {ι : Type*} (s : Finset ι) (w β : ι → ℝ) (σM : ℝ) (Dε : ι → ℝ) + +/-- The single-index covariance kernel `σᵢⱼ = βᵢβⱼσ_M² + 1[i=j]·D_ε(i)`. -/ +def singleIndexKernel [DecidableEq ι] (i j : ι) : ℝ := + β i * β j * σM ^ 2 + if i = j then Dε i else 0 + +/-- `portfolioVarN` is additive in the covariance kernel: `Var` of a sum-kernel is the sum of the +`Var`s. Pure linearity of the double `Finset.sum`. -/ +lemma portfolioVarN_add_kernel (f g : ι → ι → ℝ) : + portfolioVarN s w (fun i j ↦ f i j + g i j) = portfolioVarN s w f + portfolioVarN s w g := by + unfold portfolioVarN + rw [← Finset.sum_add_distrib] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [← Finset.sum_add_distrib] + exact Finset.sum_congr rfl fun j _ ↦ by ring + +/-- The rank-one ("market") kernel's portfolio variance is `σ_M² · (∑ wᵢβᵢ)²`: the double sum over +a rank-one kernel `βᵢβⱼ` factors into the product of two copies of the same single sum. -/ +lemma portfolioVarN_rankOne_eq : + portfolioVarN s w (fun i j ↦ β i * β j * σM ^ 2) = σM ^ 2 * (∑ i ∈ s, w i * β i) ^ 2 := by + unfold portfolioVarN + have heq : ∑ i ∈ s, ∑ j ∈ s, w i * w j * (β i * β j * σM ^ 2) = + (∑ i ∈ s, w i * β i * σM) * ∑ j ∈ s, w j * β j * σM := + (Finset.sum_congr rfl fun i _ ↦ Finset.sum_congr rfl fun j _ ↦ show + w i * w j * (β i * β j * σM ^ 2) = (w i * β i * σM) * (w j * β j * σM) by ring).trans + (Finset.sum_mul_sum s s (fun i ↦ w i * β i * σM) (fun j ↦ w j * β j * σM)).symm + have hX : (∑ i ∈ s, w i * β i * σM) = σM * ∑ i ∈ s, w i * β i := by + rw [Finset.mul_sum]; exact Finset.sum_congr rfl fun i _ ↦ by ring + rw [heq, hX] + ring + +/-- **Single-index portfolio variance**: `Var(Rp) = (∑ wᵢβᵢ)² σ_M² + ∑ wᵢ² D_ε(i)`. -/ +theorem portfolioVarN_singleIndex_eq [DecidableEq ι] : + portfolioVarN s w (singleIndexKernel β σM Dε) = + (∑ i ∈ s, w i * β i) ^ 2 * σM ^ 2 + ∑ i ∈ s, w i ^ 2 * Dε i := by + unfold singleIndexKernel + rw [portfolioVarN_add_kernel s w, portfolioVarN_rankOne_eq, + portfolioVarN_diag s w _ fun i _ j _ hij ↦ ite_eq_right hij] + simp + ring + +/-- **Idiosyncratic-term bound under equal weighting**: with weights `1/n` on an index set of +cardinality `n` and idiosyncratic variances bounded by `M`, the idiosyncratic term is at most +`M / n`. -/ +lemma idiosyncraticTerm_equalWeight_le {n : ℕ} (M : ℝ) + (hM : ∀ i ∈ s, Dε i ≤ M) (hcard : s.card = n) : + ∑ i ∈ s, ((1 : ℝ) / n) ^ 2 * Dε i ≤ M / n := by + have hbound : ∑ i ∈ s, ((1 : ℝ) / n) ^ 2 * Dε i ≤ ∑ _i ∈ s, ((1 : ℝ) / n) ^ 2 * M := + Finset.sum_le_sum fun i hi ↦ + mul_le_mul_of_nonneg_left (hM i hi) (sq_nonneg _) + have heq : ∑ _i ∈ s, ((1 : ℝ) / n) ^ 2 * M = M / n := by + rw [Finset.sum_const, hcard, nsmul_eq_mul] + field_simp + rwa [heq] at hbound + +/-- **Diversification**: the idiosyncratic term under equal weighting on an index set of +cardinality `n` tends to `0` as `n → ∞`, for nonnegative idiosyncratic variances uniformly bounded +by `M` — idiosyncratic risk diversifies away. The statement is about the idiosyncratic term +alone; the systematic term `(β_p σ_M)²` that remains in `portfolioVarN_singleIndex_eq` does not +enter it. -/ +theorem tendsto_idiosyncraticTerm_equalWeight_zero + (t : ℕ → Finset ι) (D : ℕ → ι → ℝ) (M : ℝ) + (hM : ∀ n, ∀ i ∈ t n, D n i ≤ M) (hMnn : ∀ n, ∀ i ∈ t n, 0 ≤ D n i) + (hcard : ∀ n, (t n).card = n) : + Tendsto (fun n ↦ ∑ i ∈ t n, ((1 : ℝ) / n) ^ 2 * D n i) atTop (𝓝 0) := by + have hlo (n : ℕ) : 0 ≤ ∑ i ∈ t n, ((1 : ℝ) / n) ^ 2 * D n i := + Finset.sum_nonneg fun i hi ↦ mul_nonneg (sq_nonneg _) (hMnn n i hi) + have hhi (n : ℕ) : ∑ i ∈ t n, ((1 : ℝ) / n) ^ 2 * D n i ≤ M / n := + idiosyncraticTerm_equalWeight_le (t n) (D n) M (hM n) (hcard n) + exact squeeze_zero hlo hhi (tendsto_const_div_atTop_nhds_zero_nat M) + +/-! ### From the return model to the kernel -/ + +section ReturnModel + +open MeasureTheory ProbabilityTheory + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsFiniteMeasure P] + {RM : Ω → ℝ} {ε : ι → Ω → ℝ} + +/-- **The single-index kernel is the covariance of the return model.** Let +`Rᵢ = βᵢ R_M + εᵢ` with square-integrable market return `R_M` and shocks `εᵢ`, the shocks +uncorrelated with the market and with each other, and `Var[R_M] = σ_M²`. Then +`cov(Rᵢ, Rⱼ) = βᵢβⱼσ_M² + 1[i = j]·Var[εᵢ]`: the kernel `singleIndexKernel` with the shock +variances on the diagonal. Bilinearity of covariance (`covariance_add_left`, +`covariance_smul_left`, …) and the zero cross-covariances. -/ +theorem covariance_singleIndex [DecidableEq ι] (hRM : MemLp RM 2 P) + (hε : ∀ i, MemLp (ε i) 2 P) (hRMε : ∀ i, cov[RM, ε i; P] = 0) + (hεε : ∀ i j, i ≠ j → cov[ε i, ε j; P] = 0) (hσM : Var[RM; P] = σM ^ 2) (i j : ι) : + cov[β i • RM + ε i, β j • RM + ε j; P] = + singleIndexKernel β σM (fun k ↦ Var[ε k; P]) i j := by + rw [covariance_add_left (hRM.const_smul _) (hε i) ((hRM.const_smul _).add (hε j)), + covariance_add_right (hRM.const_smul _) (hRM.const_smul _) (hε j), + covariance_add_right (hε i) (hRM.const_smul _) (hε j)] + simp only [covariance_smul_left, covariance_smul_right, + covariance_self hRM.aestronglyMeasurable.aemeasurable, hσM, hRMε, + covariance_comm (ε i) RM] + simp only [singleIndexKernel] + split_ifs with hij + · subst hij + rw [covariance_self (hε i).aestronglyMeasurable.aemeasurable] + ring + · rw [hεε i j hij] + ring + +/-- **Single-index portfolio variance from the return model.** Under the hypotheses of +`covariance_singleIndex`, the variance of the portfolio return `∑ wᵢ Rᵢ` is +`(∑ wᵢβᵢ)² σ_M² + ∑ wᵢ² Var[εᵢ]`. The self-dot identity +`portfolioVarN_covariance_eq_variance` turns the variance into the quadratic form of the +covariance kernel, which `covariance_singleIndex` identifies and +`portfolioVarN_singleIndex_eq` evaluates. -/ +theorem variance_singleIndex_portfolio (hRM : MemLp RM 2 P) + (hε : ∀ i, MemLp (ε i) 2 P) (hRMε : ∀ i, cov[RM, ε i; P] = 0) + (hεε : ∀ i j, i ≠ j → cov[ε i, ε j; P] = 0) (hσM : Var[RM; P] = σM ^ 2) : + Var[∑ i ∈ s, w i • (β i • RM + ε i); P] = + (∑ i ∈ s, w i * β i) ^ 2 * σM ^ 2 + ∑ i ∈ s, w i ^ 2 * Var[ε i; P] := by + classical + rw [← portfolioVarN_covariance_eq_variance s w (fun i ↦ β i • RM + ε i) + fun i _ ↦ (hRM.const_smul _).add (hε i)] + simp_rw [covariance_singleIndex β σM hRM hε hRMε hεε hσM] + exact portfolioVarN_singleIndex_eq s w β σM _ + +/-- **The single-index loading is the CAPM beta.** Under the return model, the CAPM beta +`cov(Rᵢ, R_M) / Var[R_M]` (`beta`, `Choice/Portfolio/CAPM.lean`) of asset `i` is its loading `βᵢ`, +provided the market variance is nonzero. -/ +theorem beta_singleIndex (hRM : MemLp RM 2 P) (hε : ∀ i, MemLp (ε i) 2 P) + (hRMε : ∀ i, cov[RM, ε i; P] = 0) (hvar : Var[RM; P] ≠ 0) (i : ι) : + MathFin.beta cov[β i • RM + ε i, RM; P] Var[RM; P] = β i := by + unfold MathFin.beta + rw [covariance_add_left (hRM.const_smul _) (hε i) hRM, covariance_smul_left, + covariance_self hRM.aestronglyMeasurable.aemeasurable, covariance_comm (ε i) RM, hRMε, + add_zero, mul_div_assoc, div_self hvar, mul_one] + +end ReturnModel + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/TangentPortfolio.lean b/LeanPool/MathFin/Choice/Portfolio/TangentPortfolio.lean new file mode 100644 index 0000000000..f4eac61eff --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/TangentPortfolio.lean @@ -0,0 +1,123 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Basic.Real.Basic +public import Mathlib.LinearAlgebra.Matrix.Notation +public import Mathlib.Tactic.Ring.RingNF + +/-! +# Tangent portfolio (two-asset closed form, FOC) + +With two risky assets having excess returns `r₁, r₂`, volatilities `σ₁, σ₂`, +and correlation `ρ`, the *tangent portfolio* (the Sharpe-ratio-maximizing +portfolio under the budget constraint `w₁ + w₂ = 1`) has closed-form weight + + `w₁^T = (σ₂² r₁ − ρ σ₁ σ₂ r₂) / D`, + `D = σ₂² r₁ + σ₁² r₂ − ρ σ₁ σ₂ (r₁ + r₂)`. + +The first-order condition for Sharpe maximization is + + `r₂ · (Σ·w)₁ = r₁ · (Σ·w)₂`, + +i.e. the marginal variance contributions are proportional to the marginal +excess returns. We verify the closed-form `w^T` satisfies this FOC by direct +algebra. + +## Main definitions + +* `tangentWeightTwo`: the closed-form two-asset tangent weight + `(σ₂² r₁ − ρσ₁σ₂ r₂) / (σ₂² r₁ + σ₁² r₂ − ρσ₁σ₂ (r₁ + r₂))` on asset 1. +* `IsTangentPortfolioN`: the `n`-asset cross-product first-order condition, in which the + marginal-variance vector `Σw` is parallel to the excess-return vector. + +## Main results + +* `tangentTwo_satisfies_FOC`: the FOC identity at the tangent weight. + +## References + +* [H. Markowitz, *Portfolio selection*][Markowitz1952] +* [Sharpe, *Capital asset prices*][Sharpe1964] + +## Tags + +tangent portfolio, maximum Sharpe ratio, two-asset portfolio, first-order condition, +optimal risky portfolio, MSC 91G10, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +/-- Two-asset tangent portfolio weight on asset 1. + +`w₁^T = (σ₂² r₁ − ρ σ₁ σ₂ r₂) / (σ₂² r₁ + σ₁² r₂ − ρ σ₁ σ₂ (r₁ + r₂))`. -/ +noncomputable def tangentWeightTwo (r₁ r₂ σ₁ σ₂ ρ : ℝ) : ℝ := + (σ₂^2 * r₁ - ρ * σ₁ * σ₂ * r₂) / + (σ₂^2 * r₁ + σ₁^2 * r₂ - ρ * σ₁ * σ₂ * (r₁ + r₂)) + +/-- **Tangent portfolio FOC**: at the closed-form weight `w = w₁^T`, +`D · [r₂ · (w σ₁² + (1 − w) ρ σ₁ σ₂)] = D · [r₁ · (w ρ σ₁ σ₂ + (1 − w) σ₂²)]` +i.e. multiplying both sides by `D` we get a polynomial identity. Stated as +the cross-product form `r₂ · D · ((Σw)_1) = r₁ · D · ((Σw)_2)` to avoid the +division. -/ +theorem tangentTwo_satisfies_FOC (r₁ r₂ σ₁ σ₂ ρ : ℝ) : + -- `D` is the common denominator `σ₂² r₁ + σ₁² r₂ − ρ σ₁ σ₂ (r₁ + r₂)` — + -- not referenced in the statement itself (the FOC is stated in + -- multiplied-out cross-product form, so the division by `D` cancels). + let w_num := σ₂^2 * r₁ - ρ * σ₁ * σ₂ * r₂ -- D · w + let one_sub_w_num := σ₁^2 * r₂ - ρ * σ₁ * σ₂ * r₁ -- D · (1 - w) + r₂ * (w_num * σ₁^2 + one_sub_w_num * ρ * σ₁ * σ₂) = + r₁ * (w_num * ρ * σ₁ * σ₂ + one_sub_w_num * σ₂^2) := by + ring + +/-! ## N-asset extension (folded from `TangentPortfolioN.lean`) + +For `N` risky assets, the tangent portfolio satisfies the cross-product FOC +`μ_excess(j) · (Σw)_i = μ_excess(i) · (Σw)_j` for all `i, j`. The two-asset +case above is the `i = 1, j = 2` instance written out. -/ + +/-- **N-asset tangent portfolio cross-product FOC**: the marginal-variance +vector `(Σw)_i = ∑_k Σ_{i,k} w_k` is parallel to the excess-return vector +`μ_excess`. -/ +def IsTangentPortfolioN {ι : Type*} (s : Finset ι) (μ_excess : ι → ℝ) + (Sg : ι → ι → ℝ) (w : ι → ℝ) : Prop := + ∀ i ∈ s, ∀ j ∈ s, + μ_excess j * (∑ k ∈ s, Sg i k * w k) = + μ_excess i * (∑ k ∈ s, Sg j k * w k) + +/-- **Sufficient condition for tangency**: if `Σw = λ · μ_excess` for some +scalar `λ`, then `w` is a tangent portfolio. Captures the matrix-inverse +characterisation `w ∝ Σ⁻¹ · μ_excess` without requiring matrix machinery. -/ +theorem isTangent_of_proportional {ι : Type*} (s : Finset ι) (μ_excess : ι → ℝ) + (Sg : ι → ι → ℝ) (w : ι → ℝ) (lam : ℝ) + (h : ∀ i ∈ s, (∑ k ∈ s, Sg i k * w k) = lam * μ_excess i) : + IsTangentPortfolioN s μ_excess Sg w := by + intro i hi j hj + rw [h i hi, h j hj] + ring + +/-- **The two-asset FOC is the `N = 2` instance of `IsTangentPortfolioN`** — the +coherence the module docstring asserts, now proved rather than narrated. Feeding +the excess returns `![r₁, r₂]`, the covariance kernel `!![σ₁², ρσ₁σ₂; ρσ₁σ₂, σ₂²]`, +and the (denominator-scaled, since the predicate is homogeneous in `w`) tangent +weights `![Dw, D(1−w)]` into the general cross-product FOC recovers exactly +`tangentTwo_satisfies_FOC`. So the bespoke two-asset result is not a parallel +tower: it is `IsTangentPortfolioN` written out. -/ +theorem tangentTwo_isTangentPortfolioN (r₁ r₂ σ₁ σ₂ ρ : ℝ) : + IsTangentPortfolioN (Finset.univ : Finset (Fin 2)) + ![r₁, r₂] + (fun i j ↦ ![![σ₁ ^ 2, ρ * σ₁ * σ₂], ![ρ * σ₁ * σ₂, σ₂ ^ 2]] i j) + ![σ₂ ^ 2 * r₁ - ρ * σ₁ * σ₂ * r₂, σ₁ ^ 2 * r₂ - ρ * σ₁ * σ₂ * r₁] := by + intro i _ j _ + fin_cases i <;> fin_cases j <;> + simp [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one] <;> ring + +end MathFin diff --git a/LeanPool/MathFin/Choice/Portfolio/TwoFundSeparation.lean b/LeanPool/MathFin/Choice/Portfolio/TwoFundSeparation.lean new file mode 100644 index 0000000000..c0d74c6ccf --- /dev/null +++ b/LeanPool/MathFin/Choice/Portfolio/TwoFundSeparation.lean @@ -0,0 +1,112 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Performance.Ratios + +/-! +# Capital Market Line and two-fund separation (algebraic) + +In the presence of a risk-free asset with rate `r_f` and a Sharpe-optimal +"tangent" portfolio with mean `μ_t` and standard deviation `σ_t > 0`, every +combined portfolio formed as `α · tangent + (1 − α) · risk-free` satisfies: + +* **CML equation**: `μ_combined = r_f + α · σ_t · Sharpe_t`, i.e. the (mean, std) + pairs trace the line `μ = r_f + Sharpe_t · σ` through `(0, r_f)`. +* **Sharpe invariance**: the Sharpe ratio of any CML portfolio equals the + tangent Sharpe ratio (for `α > 0`, `σ_t > 0`). +* **Decomposition**: any `(μ_p, σ_p)` lying on the CML decomposes uniquely as + `α = σ_p / σ_t` units of the tangent fund plus `1 − α` units of risk-free. + +These are the algebraic content of Tobin's two-fund separation theorem. + +## Main definitions + +* `cmlMean`: the expected return `α μ_t + (1 − α) r_f` of the mix of the tangent portfolio at + weight `α` and the risk-free asset. +* `cmlStdev`: the standard deviation `α σ_t` of that mix. + +## Main results + +* `cml_equation`: `μ_combined = r_f + Sharpe_t · σ_combined` on the CML. +* `cml_sharpeRatio_invariant`: Sharpe is preserved along the CML. +* `cml_weight_recovers_stdev` / `cml_weight_unique`: the weight + `α = σ_p / σ_t` reproduces `σ_p`, and any weight attaining `σ_p` equals + it — existence and uniqueness of the decomposition weight. +* `cml_mean_at_stdev`: mean recovery `μ_p = r_f + σ_p · Sharpe_t` at that weight. + +## References + +* [K. Bodie and Marcus, *Investments*][BodieKaneMarcus], Ch 9.2 +* [Tobin (1958)][Tobin1958] + +## Tags + +capital market line, two-fund separation, Tobin separation, tangent portfolio, risk-free asset, +Sharpe ratio, MSC 91G10, JEL G11, JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- CML portfolio expected return at tangent weight `α`. -/ +noncomputable def cmlMean (μ_t r_f α : ℝ) : ℝ := α * μ_t + (1 - α) * r_f + +/-- CML portfolio standard deviation at tangent weight `α`. -/ +noncomputable def cmlStdev (σ_t α : ℝ) : ℝ := α * σ_t + +/-- **CML equation**: `μ_combined = r_f + σ_combined · Sharpe_t`. -/ +lemma cml_equation (μ_t σ_t r_f α : ℝ) (hσ_t : σ_t ≠ 0) : + cmlMean μ_t r_f α = + r_f + cmlStdev σ_t α * sharpeRatio μ_t r_f σ_t := by + unfold cmlMean cmlStdev sharpeRatio + field_simp + ring + +/-- **Sharpe invariance along the CML**: for `α ≠ 0` and `σ_t ≠ 0`, any +CML portfolio has the same Sharpe ratio as the tangent portfolio. -/ +lemma cml_sharpeRatio_invariant (μ_t σ_t r_f α : ℝ) + (hα : α ≠ 0) (hσ_t : σ_t ≠ 0) : + sharpeRatio (cmlMean μ_t r_f α) r_f (cmlStdev σ_t α) = + sharpeRatio μ_t r_f σ_t := by + unfold cmlMean cmlStdev sharpeRatio + have hασt_ne : α * σ_t ≠ 0 := mul_ne_zero hα hσ_t + field_simp + ring + +/-- **CML decomposition — weight recovery**: the tangent-fund weight +`α = σ_p / σ_t` reproduces the target standard deviation, +`cmlStdev σ_t (σ_p/σ_t) = σ_p`. This is the decomposition step of two-fund +separation: the weight is read off the target stdev (the statement is the +recovery identity; it does not itself assert uniqueness). -/ +lemma cml_weight_recovers_stdev (σ_t σ_p : ℝ) (hσ_t : σ_t ≠ 0) : + cmlStdev σ_t (σ_p / σ_t) = σ_p := by + unfold cmlStdev + field_simp + +/-- **CML decomposition — weight uniqueness**: any weight attaining the +target stdev is the canonical one, `cmlStdev σ_t α = σ_p ⟹ α = σ_p / σ_t` +(Mathlib's `eq_div_iff`). Together with `cml_weight_recovers_stdev` this is +the full unique-weight statement of the decomposition. -/ +lemma cml_weight_unique (σ_t α σ_p : ℝ) (hσ_t : σ_t ≠ 0) + (h : cmlStdev σ_t α = σ_p) : α = σ_p / σ_t := + (eq_div_iff hσ_t).mpr h + +/-- **Mean recovery on the CML**: a portfolio with std deviation `σ_p` on the +CML through `r_f` with tangent slope `Sharpe_t` has expected return +`μ_p = r_f + σ_p · Sharpe_t`. -/ +lemma cml_mean_at_stdev (μ_t σ_t r_f σ_p : ℝ) (hσ_t : σ_t ≠ 0) : + cmlMean μ_t r_f (σ_p / σ_t) = r_f + σ_p * sharpeRatio μ_t r_f σ_t := by + unfold cmlMean sharpeRatio + field_simp + ring + +end MathFin diff --git a/LeanPool/MathFin/Choice/Utility/VonNeumannMorgenstern.lean b/LeanPool/MathFin/Choice/Utility/VonNeumannMorgenstern.lean new file mode 100644 index 0000000000..24a6645074 --- /dev/null +++ b/LeanPool/MathFin/Choice/Utility/VonNeumannMorgenstern.lean @@ -0,0 +1,328 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Laws.FiniteWeights + +/-! +# von Neumann–Morgenstern lotteries and the expected-utility functional + +`Risk.UtilityDerivation` defines the acceptance set of an expected-utility +agent through `expectedUtility` and shows that a concave utility makes it convex and +an increasing one makes it closed under adding cash. Such a set need not be a cone, +so it need not be the acceptance set of a coherent risk measure +(`not_exists_isCoherentRiskMeasure_log_acceptance`). This file supplies the layer +underneath: the mixture algebra of lotteries, the affinity of expected utility in +that mixture, and the verification that an expected-utility preference satisfies +the von Neumann–Morgenstern axioms. + +## Setup + +A **lottery** over a finite outcome index `ι` is a probability vector +`p : ι → ℝ` supported on a `Finset ι` — nonnegative, summing to one. Following +the house convention in `UtilityDerivation`, the two conditions travel as +explicit hypotheses rather than in a bundled subtype: every theorem below states +exactly the conditions its proof consumes, and most of the mixture algebra needs +neither. + +* `mix α p q` — the compound lottery `α p + (1 − α) q`. +* `expectedUtility s u p` — `∑ i ∈ s, p i * u i`. +* `prefersEU s u p q` — `p` is weakly preferred to `q`, i.e. `EU q ≤ EU p`. + +## The mixture algebra + +`mix_one`, `mix_zero`, `mix_self`, `mix_comm` and `mix_compound` are the +"fundamental claims about mixture lotteries" that any vNM development needs +before the axioms can even be stated. `mix_nonneg` and `sum_mix` are the +closure facts: a mixture of lotteries is a lottery. + +## The pivot + +`expectedUtility_mix` — expected utility is **affine in the mixture**: +`EU(α p + (1−α) q) = α EU(p) + (1−α) EU(q)`. + +Everything else in this file is a corollary of that single identity. It is the +formal content of the claim that expected utility "respects compounding", and it +is precisely what fails for the non-linear functionals (rank-dependent utility, +prospect theory) that were invented to explain the Allais paradox. + +## The axioms, verified + +`prefersEU` is shown to be complete (`prefersEU_total`), transitive, reflexive, +and to satisfy **independence** (`prefersEU_independence`, and the strict form) +and **continuity** (`prefersEU_continuity`, the Archimedean property: given +`p ≻ q ≻ r` there is a mixture of `p` and `r` indifferent to `q`, exhibited +explicitly as `(EU q − EU r)/(EU p − EU r)`). + +## Uniqueness + +`expectedUtility_affine` and `prefersEU_affine_invariant` give the direction of +the vNM uniqueness theorem that is constructive: a positive affine +transformation `u ↦ a·u + b` (`a > 0`) transforms the expected-utility +functional the same way and leaves the induced preference **exactly** +unchanged. This is why utility is "cardinal up to origin and scale", and why no +economic content may be attached to the units of `u`. + +## What is *not* in this file + +The **representation theorem itself** — the converse direction, that any +preference satisfying the four axioms *is* `prefersEU s u` for some `u`. That +proof calibrates each outcome against a best/worst pair, and needs a +strict-monotonicity lemma for `mix` along `α` plus the Archimedean axiom to +extract the calibrating scalar. It is a substantially longer development and is +deliberately left for its own module; this file is its prerequisite layer, and +supplies the soundness half (`prefersEU` satisfies the axioms) against which +that construction will be checked. + +Likewise the converse of `prefersEU_affine_invariant` — that two utilities +representing the same preference *must* differ by a positive affine map — needs +the same calibration argument and belongs with it. + +## Main definitions + +* `mix`: the compound lottery `α p + (1 − α) q`. +* `expectedUtility`: the expected utility `∑ i ∈ s, p i * u i` of the lottery `p` over the support + `s`. +* `prefersEU`: `p` is weakly preferred to `q` when `EU(q) ≤ EU(p)`. + +## Main results + +* `expectedUtility_eq_integral`, `expectedUtility_univ_real_eq_integral`: expected utility is the + integral of the utility against the lottery as a measure (`Measure.ofWeights`). +* `expectedUtility_mix`: expected utility is affine in the mixture, + `EU(α p + (1 − α) q) = α EU(p) + (1 − α) EU(q)`. +* `prefersEU_total`, `prefersEU_trans`, `prefersEU_refl`: the expected-utility preference is + complete, transitive and reflexive. +* `prefersEU_independence`, `prefersEU_strict_independence`: mixing a common lottery into both + sides preserves a weak preference at any weight `α ≥ 0`, and a strict one at any `α > 0`. +* `prefersEU_continuity`: if `p ≻ q ≻ r` some strict mixture of `p` and `r` has the same + expected utility as `q`. +* `prefersEU_affine_invariant`: for probability vectors the preference is unchanged by a + positive affine rescaling `a u + b` of the utility. + +## References + +* [von Neumann and Morgenstern, *Theory of Games and Economic Behavior*][VonNeumannMorgenstern1944] +* [H. Föllmer and A. Schied, *Stochastic Finance: An Introduction in Discrete Time*][FollmerSchied], + §1.1 + +## Tags + +von Neumann-Morgenstern, expected utility, lotteries, independence axiom, Archimedean axiom, +utility uniqueness, preference axioms, MSC 91B16, MSC 91B06, JEL D81 +-/ + +@[expose] public section + +namespace MathFin + +variable {ι : Type*} + +/-- The **compound lottery** `α p + (1 − α) q`: with probability `α` you face +lottery `p`, otherwise `q`. -/ +def mix (α : ℝ) (p q : ι → ℝ) : ι → ℝ := fun i ↦ α * p i + (1 - α) * q i + +/-- **Expected utility** of the lottery `p` under the utility `u`, over the +support `s`. -/ +def expectedUtility (s : Finset ι) (u : ι → ℝ) (p : ι → ℝ) : ℝ := + ∑ i ∈ s, p i * u i + +open MeasureTheory in +/-- **Expected utility is an integral**: for non-negative weights `p`, `expectedUtility s u p` is +`∫ u ∂(∑ i ∈ s, p i • δ_i)`, the integral of the utility against the lottery as a measure. -/ +theorem expectedUtility_eq_integral [MeasurableSpace ι] [MeasurableSingletonClass ι] + (s : Finset ι) {p : ι → ℝ} (hp : ∀ i ∈ s, 0 ≤ p i) (u : ι → ℝ) : + expectedUtility s u p = ∫ i, u i ∂Measure.ofWeights s p := + (Measure.integral_ofWeights s hp u).symm + +open MeasureTheory in +/-- **The expected utility of a finite measure's point masses is its integral**: +`∑ i, μ {i} * u i = ∫ u ∂μ` on a finite type with measurable singletons. -/ +theorem expectedUtility_univ_real_eq_integral [Fintype ι] [MeasurableSpace ι] + [MeasurableSingletonClass ι] (μ : Measure ι) [IsFiniteMeasure μ] (u : ι → ℝ) : + expectedUtility Finset.univ u (fun i ↦ μ.real {i}) = ∫ i, u i ∂μ := by + rw [expectedUtility_eq_integral _ fun i _ ↦ measureReal_nonneg, + Measure.ofWeights_univ_real_singleton] + +/-- `p` is **weakly preferred** to `q` under expected utility. -/ +def prefersEU (s : Finset ι) (u : ι → ℝ) (p q : ι → ℝ) : Prop := + expectedUtility s u q ≤ expectedUtility s u p + +/-! ### The mixture algebra -/ + +/-- Mixing with certainty on the first lottery returns it. -/ +theorem mix_one (p q : ι → ℝ) : mix 1 p q = p := by + funext i + simp [mix] + +/-- Mixing with certainty on the second lottery returns it. -/ +theorem mix_zero (p q : ι → ℝ) : mix 0 p q = q := by + funext i + simp [mix] + +/-- Mixing a lottery with itself is a no-op, at any weight. -/ +theorem mix_self (α : ℝ) (p : ι → ℝ) : mix α p p = p := by + funext i + change α * p i + (1 - α) * p i = p i + ring + +/-- Swapping the two lotteries complements the weight. -/ +theorem mix_comm (α : ℝ) (p q : ι → ℝ) : mix α p q = mix (1 - α) q p := by + funext i + change α * p i + (1 - α) * q i = (1 - α) * q i + (1 - (1 - α)) * p i + ring + +/-- **Reduction of compound lotteries**: mixing `q` into a mixture of `p` and +`q` just rescales the weight on `p`. The formal content of the "only the +resulting distribution matters" assumption. -/ +theorem mix_compound (α β : ℝ) (p q : ι → ℝ) : + mix α (mix β p q) q = mix (α * β) p q := by + funext i + change α * (β * p i + (1 - β) * q i) + (1 - α) * q i + = α * β * p i + (1 - α * β) * q i + ring + +/-- A mixture of nonnegative vectors at a weight in `[0, 1]` is nonnegative. -/ +theorem mix_nonneg {α : ℝ} (hα : 0 ≤ α) (hα1 : α ≤ 1) {p q : ι → ℝ} + (hp : ∀ i, 0 ≤ p i) (hq : ∀ i, 0 ≤ q i) (i : ι) : + 0 ≤ mix α p q i := by + change 0 ≤ α * p i + (1 - α) * q i + exact add_nonneg (mul_nonneg hα (hp i)) (mul_nonneg (by linarith) (hq i)) + +/-- A mixture of probability vectors is a probability vector. Together with +`mix_nonneg`, this is the closure of lotteries under mixing. -/ +theorem sum_mix (s : Finset ι) (α : ℝ) {p q : ι → ℝ} + (hp : ∑ i ∈ s, p i = 1) (hq : ∑ i ∈ s, q i = 1) : + ∑ i ∈ s, mix α p q i = 1 := by + have hsplit : ∑ i ∈ s, mix α p q i + = α * (∑ i ∈ s, p i) + (1 - α) * ∑ i ∈ s, q i := by + simp only [mix] + rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib] + rw [hsplit, hp, hq] + ring + +/-! ### The pivot: expected utility is affine in the mixture -/ + +/-- **Expected utility is affine in the mixture**: +`EU(α p + (1 − α) q) = α EU(p) + (1 − α) EU(q)`. + +Every axiom verified below is a corollary of this one identity. Note it needs +*no* hypothesis on `p`, `q` or `α` — it is linearity of the sum, not a fact +about probabilities. -/ +theorem expectedUtility_mix (s : Finset ι) (u : ι → ℝ) (α : ℝ) (p q : ι → ℝ) : + expectedUtility s u (mix α p q) + = α * expectedUtility s u p + (1 - α) * expectedUtility s u q := by + simp only [expectedUtility, mix] + rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib] + exact Finset.sum_congr rfl (fun i _ ↦ by ring) + +/-! ### The von Neumann–Morgenstern axioms, verified for `prefersEU` -/ + +/-- **Completeness**: any two lotteries are comparable. -/ +theorem prefersEU_total (s : Finset ι) (u : ι → ℝ) (p q : ι → ℝ) : + prefersEU s u p q ∨ prefersEU s u q p := + le_total _ _ + +/-- **Transitivity**. -/ +theorem prefersEU_trans (s : Finset ι) (u : ι → ℝ) {p q r : ι → ℝ} + (hpq : prefersEU s u p q) (hqr : prefersEU s u q r) : prefersEU s u p r := + le_trans hqr hpq + +/-- **Reflexivity**. -/ +theorem prefersEU_refl (s : Finset ι) (u : ι → ℝ) (p : ι → ℝ) : + prefersEU s u p p := + le_refl _ + +/-- **Independence**: mixing a common lottery `r` into both sides preserves the +preference, at any nonnegative weight. + +This is the axiom the Allais paradox violates, and the one that forces the +expected-utility form. It is immediate from `expectedUtility_mix`: the `r` +term enters both sides identically and cancels. -/ +theorem prefersEU_independence (s : Finset ι) (u : ι → ℝ) {α : ℝ} (hα : 0 ≤ α) + {p q r : ι → ℝ} (h : prefersEU s u p q) : + prefersEU s u (mix α p r) (mix α q r) := by + unfold prefersEU at h ⊢ + rw [expectedUtility_mix, expectedUtility_mix] + exact add_le_add (mul_le_mul_of_nonneg_left h hα) le_rfl + +/-- **Strict independence**: a strict preference survives mixing with a common +lottery, at any *positive* weight. -/ +theorem prefersEU_strict_independence (s : Finset ι) (u : ι → ℝ) {α : ℝ} + (hα : 0 < α) {p q r : ι → ℝ} + (h : expectedUtility s u q < expectedUtility s u p) : + expectedUtility s u (mix α q r) < expectedUtility s u (mix α p r) := by + rw [expectedUtility_mix, expectedUtility_mix] + exact add_lt_add_of_lt_of_le (mul_lt_mul_of_pos_left h hα) le_rfl + +/-- The scalar behind the Archimedean axiom: for reals `R < Q < P` there is a +strict convex weight placing `Q` between `R` and `P`, namely `Q`'s position on +the interval `[R, P]`. Stated on plain reals because that is all it is — the +lottery content of continuity is entirely in `expectedUtility_mix`. -/ +theorem exists_mix_weight {P Q R : ℝ} (hpq : Q < P) (hqr : R < Q) : + ∃ α : ℝ, 0 < α ∧ α < 1 ∧ α * P + (1 - α) * R = Q := by + have hPR : 0 < P - R := by linarith + have hne : P - R ≠ 0 := ne_of_gt hPR + refine ⟨(Q - R) / (P - R), div_pos (by linarith) hPR, ?_, ?_⟩ + · rw [div_lt_one hPR] + linarith + · have key : (Q - R) / (P - R) * (P - R) = Q - R := by + field_simp + linear_combination key + +/-- **Continuity (the Archimedean axiom)**: if `p ≻ q ≻ r`, some strict mixture +of the best and worst is exactly indifferent to the middle lottery. + +The witness is exhibited rather than obtained from a limit: the indifference +weight is the position of `q` on the utility interval `[EU r, EU p]`, which is +the calibration scalar the full representation theorem will read off. -/ +theorem prefersEU_continuity (s : Finset ι) (u : ι → ℝ) {p q r : ι → ℝ} + (hpq : expectedUtility s u q < expectedUtility s u p) + (hqr : expectedUtility s u r < expectedUtility s u q) : + ∃ α : ℝ, 0 < α ∧ α < 1 ∧ + expectedUtility s u (mix α p r) = expectedUtility s u q := by + obtain ⟨α, hα0, hα1, hα⟩ := exists_mix_weight hpq hqr + refine ⟨α, hα0, hα1, ?_⟩ + rw [expectedUtility_mix] + exact hα + +/-! ### Uniqueness up to a positive affine transformation -/ + +/-- A positive affine transformation of the utility transforms expected utility +the same way: `EU_{a u + b}(p) = a EU_u(p) + b`. + +The `∑ p = 1` hypothesis is exactly what turns the constant `b` into itself +rather than into `b · ∑ p` — this is where the lottery's normalisation, unused +by the mixture algebra above, finally does work. -/ +theorem expectedUtility_affine (s : Finset ι) (u : ι → ℝ) (a b : ℝ) {p : ι → ℝ} + (hp : ∑ i ∈ s, p i = 1) : + expectedUtility s (fun i ↦ a * u i + b) p + = a * expectedUtility s u p + b := by + simp only [expectedUtility] + have hsplit : ∑ i ∈ s, p i * (a * u i + b) + = a * (∑ i ∈ s, p i * u i) + b * ∑ i ∈ s, p i := by + rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib] + exact Finset.sum_congr rfl (fun i _ ↦ by ring) + rw [hsplit, hp] + ring + +/-- **The preference is invariant under positive affine rescaling of utility**. + +The vNM utility is cardinal only up to origin and scale: `u` and `a·u + b` with +`a > 0` induce the *same* preference relation, so no economic meaning attaches +to the units of `u`. (Comparisons of utility *differences* do survive, which is +what distinguishes vNM utility from the ordinal utility of consumer theory.) -/ +theorem prefersEU_affine_invariant (s : Finset ι) (u : ι → ℝ) {a b : ℝ} + (ha : 0 < a) {p q : ι → ℝ} + (hp : ∑ i ∈ s, p i = 1) (hq : ∑ i ∈ s, q i = 1) : + prefersEU s (fun i ↦ a * u i + b) p q ↔ prefersEU s u p q := by + unfold prefersEU + rw [expectedUtility_affine s u a b hp, expectedUtility_affine s u a b hq, + add_le_add_iff_right, mul_le_mul_iff_of_pos_left ha] + +end MathFin diff --git a/LeanPool/MathFin/Contracts/Adapted.lean b/LeanPool/MathFin/Contracts/Adapted.lean new file mode 100644 index 0000000000..978d864826 --- /dev/null +++ b/LeanPool/MathFin/Contracts/Adapted.lean @@ -0,0 +1,265 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Contracts.Core + +/-! +# A payoff is measurable, adapted to its observation times, and integrable in a bounded model + +A `Payoff` is data, not yet a random variable: `Payoff.eval` only produces one +once it is applied to a `Scenario`. This file supplies the missing link — +substitute a genuinely stochastic model `X : ι → ℝ≥0 → Ω → ℝ` for the +`Scenario`, and `fun ω ↦ e.eval (fun i t ↦ X i t ω)` is measurable +(`Payoff.measurable_eval`), and moreover `𝓕 u`-measurable as soon as every +observation the payoff makes is dated no later than `u` +(`Payoff.measurable_eval_of_obsList_le`). That second fact is what will make a +`Payoff` a legitimate stochastic-integral integrand: it is the adaptedness +hypothesis a future integral rung against a filtered probability space will +need. **`measurable_eval_of_obsList_le` has no consumer yet** — +`Pricing/Value.lean` integrates only against a fixed measure `Q`, never +against a filtration, so it has no adaptedness hypothesis to discharge with +this file's results. + +`Payoff.aemeasurable_eval` weakens `measurable_eval`'s hypothesis from +`Measurable` to `AEMeasurable` — the strength the tower's own pricing +hypotheses actually supply (`BSCallHyp`'s `Z_law : HasLaw Z (gaussianReal 0 1) +Q` gives only `AEMeasurable Z`, never `Measurable Z`). It has no consumer +now either: the integrability lemmas of `Models/BlackScholes/BlackScholes.lean` build each +reified payoff from integrable pieces (`Integrable.pos_part`, `.sub`, +`.const_mul`), which carry their own measurability. + +`Contract.integrable_pathPV_of_bounded` is the consumer `measurable_eval` was waiting for: in a +model whose every coordinate is bounded, the discounted payoff of every contract that pays at fixed +dates (`Contract.FixedDated`) is integrable against any finite measure. Measurability comes from +`measurable_eval`, and the bound from `Payoff.exists_bound_eval`, a structural induction like the +others. A finite-state model such as +the binomial tree is bounded, so there `Contract.value_both` needs no per-instrument +integrability lemma (`Models/Binomial/Binomial.lean`). + +## Main results + +* `Payoff.measurable_eval` — evaluating a payoff against a jointly-measurable + model is measurable, unconditionally. +* `Contract.measurable_pathPV` — a fixed-dated contract's present value under a measurable + stochastic discount factor is measurable. +* `Payoff.measurable_eval_of_obsList_le` — if every date in `e.obsList` (the syntactic list of + observations `Contracts/Core.lean` defines; an over-approximation, so the criterion is + sufficient, not necessary: `Payoff.mul (.const 0) (.obs i t)` lists `t` though its value does + not depend on it) is `≤ u` and each `X i t` is `𝓕 t`-measurable, then evaluating `e` against `X` + is `𝓕 u`-measurable. The filtration's monotonicity (`𝓕.mono`) does the work + in the `obs` leaf; the six binary constructors combine two adapted pieces + into one by the corresponding `Measurable.add`/`.sub`/`.mul`/`.max`/`.min` + lemma, or `Measurable.ite` composed with `measurableSet_lt` for + `indicatorLt`; `rpow` keeps the adapted piece under `Measurable.pow_const`. +* `Payoff.aemeasurable_eval` — the same conclusion as `measurable_eval`, from + the weaker hypothesis that each `X i t` is only `AEMeasurable`. Built from + `measurable_eval` applied to measurable representatives `(hX i t).mk (X i + t)`, transported across the a.e. equality `e.eval X =ᵐ[μ] e.eval X'` proved + by a second structural induction (each `obs` leaf contributes + `AEMeasurable.ae_eq_mk`; the six binary constructors combine two a.e. facts + by `filter_upwards`, and `rpow` from the one) — not a direct induction into + `AEMeasurable`, whose `indicatorLt` case would need a `NullMeasurableSet` this route avoids + producing. +* `Payoff.exists_bound_eval` — against a model with bounded coordinates, a payoff is bounded + (a nonnegative power by `Real.abs_rpow_le_abs_rpow`). +* `Contract.integrable_pathPV_of_bounded` — against a finite measure and a measurable, bounded + model, the discounted payoff of every fixed-date contract is integrable. + +## Source + +The layered separation of contract semantics from pricing semantics, and the +framing "the contract is not the model", are due to Paul Bilokon, +*The Contract Is Not the Model: Proof-Carrying Exotic Derivatives and the +Economics of Model Risk* (working paper, 9 August 2026; Mathematical +Finance, Imperial College London), with code at + (Apache-2.0). That paper in +turn builds on the compositional contract-DSL of +Peyton Jones, Eber and Seward (2000) and the certified-contract work of Bahr, +Berthold and Elsman (2015) and Annenkov (2018). + +Bilokon's `Contract.observationTimes` exists to feed a syntactic chronology +check discharged `by decide`; the same function here carries content, as the +hypothesis of an adaptedness theorem. The measurability and adaptedness +results have no counterpart in the source. + +No code is copied from `lean_contracts`; every definition and proof here is +written for this library. See `docs/specs/2026-08-16-contracts-tower-design.md` +§6 for the full credit line. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], ch. 3-4 + +## Tags + +payoff measurability, adapted payoff, filtration, observation times, integrability, MSC 91G20, +MSC 60G07, JEL G13 +-/ + +@[expose] public section + +open MeasureTheory +open scoped NNReal + +namespace MathFin.Contracts + +variable {ι Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- Evaluating a payoff against a jointly-measurable model is measurable. -/ +theorem Payoff.measurable_eval (e : Payoff ι) (X : ι → ℝ≥0 → Ω → ℝ) + (hX : ∀ i t, Measurable (X i t)) : + Measurable fun ω ↦ e.eval (fun i t ↦ X i t ω) := by + induction e with + | const c => exact measurable_const + | obs i t => exact hX i t + | add a b ha hb => exact ha.add hb + | sub a b ha hb => exact ha.sub hb + | mul a b ha hb => exact ha.mul hb + | max a b ha hb => exact ha.max hb + | min a b ha hb => exact ha.min hb + | indicatorLt a b ha hb => + exact Measurable.ite (measurableSet_lt ha hb) measurable_const measurable_const + | rpow a p ha => exact ha.pow_const _ + +/-- **A fixed-dated contract's deflated present value is measurable** for a measurable model and +a measurable stochastic discount factor `D : ℝ≥0 → Ω → ℝ`. -/ +theorem Contract.measurable_pathPV {c : Contract ι} (hc : c.FixedDated) {D : ℝ≥0 → Ω → ℝ} + (hD : ∀ t, Measurable (D t)) {X : ι → ℝ≥0 → Ω → ℝ} (hX : ∀ i t, Measurable (X i t)) : + Measurable fun ω ↦ c.pathPV (fun t ↦ D t ω) (fun i t ↦ X i t ω) := by + induction c with + | zero => + simp only [Contract.pathPV, Contract.cashflows, List.map_nil, List.sum_nil] + exact measurable_const + | pay t a => + simp only [Contract.pathPV, Contract.cashflows, List.map_cons, List.map_nil, List.sum_cons, + List.sum_nil, add_zero] + exact (hD t).mul (a.measurable_eval X hX) + | payAtHit _ _ _ => exact hc.elim + | both a b ha hb => + simp only [Contract.pathPV_both] + exact (ha hc.1).add (hb hc.2) + | scale r a ha => + simp only [Contract.pathPV_scale] + exact (ha hc).const_mul r + +/-- Evaluating a payoff against an a.e.-measurable model is a.e.-measurable: the strength a +consumer whose model only satisfies `AEMeasurable` (e.g. `HasLaw.aemeasurable`, never +`Measurable`) actually has. Built from `measurable_eval` on each model coordinate's measurable +representative `(hX i t).mk (X i t)`, transported across its a.e. equality with the original — +not a second induction into `AEMeasurable`, whose `indicatorLt` case wants a +`NullMeasurableSet` awkward to produce here. -/ +theorem Payoff.aemeasurable_eval {μ : Measure Ω} (e : Payoff ι) (X : ι → ℝ≥0 → Ω → ℝ) + (hX : ∀ i t, AEMeasurable (X i t) μ) : + AEMeasurable (fun ω ↦ e.eval (fun i t ↦ X i t ω)) μ := by + let X' : ι → ℝ≥0 → Ω → ℝ := fun i t ↦ (hX i t).mk (X i t) + have heq (e : Payoff ι) : (fun ω ↦ e.eval (fun i t ↦ X i t ω)) + =ᵐ[μ] fun ω ↦ e.eval (fun i t ↦ X' i t ω) := by + induction e with + | const c => exact .of_forall fun _ ↦ rfl + | obs i t => exact (hX i t).ae_eq_mk + | add a b ha hb => filter_upwards [ha, hb] with ω hae hbe; simp only [Payoff.eval, hae, hbe] + | sub a b ha hb => filter_upwards [ha, hb] with ω hae hbe; simp only [Payoff.eval, hae, hbe] + | mul a b ha hb => filter_upwards [ha, hb] with ω hae hbe; simp only [Payoff.eval, hae, hbe] + | max a b ha hb => filter_upwards [ha, hb] with ω hae hbe; simp only [Payoff.eval, hae, hbe] + | min a b ha hb => filter_upwards [ha, hb] with ω hae hbe; simp only [Payoff.eval, hae, hbe] + | indicatorLt a b ha hb => + filter_upwards [ha, hb] with ω hae hbe; simp only [Payoff.eval, hae, hbe] + | rpow a p ha => filter_upwards [ha] with ω hae; simp only [Payoff.eval, hae] + have hX'meas : ∀ i t, Measurable (X' i t) := fun i t ↦ (hX i t).measurable_mk + exact (Payoff.measurable_eval e X' hX'meas).aemeasurable.congr (heq e).symm + +/-- Evaluating a payoff against a filtration-adapted model `X` is adapted to +`𝓕 u`, as soon as every time the payoff observes is dated no later than `u`. +This is the theorem that will make a `Payoff` a legitimate stochastic-integral +integrand — the adaptedness hypothesis a future integral rung will need. +Still has no consumer: `Pricing/Value.lean` integrates against a fixed +measure, not a filtration, and unlike `measurable_eval`'s a.e. counterpart +above, no `Payoff` in the tower yet needs an argument observed before a fixed +time rather than a fixed measure. -/ +theorem Payoff.measurable_eval_of_obsList_le + {𝓕 : Filtration ℝ≥0 mΩ} {u : ℝ≥0} (e : Payoff ι) (X : ι → ℝ≥0 → Ω → ℝ) + (hX : ∀ i t, Measurable[𝓕 t] (X i t)) + (hle : ∀ p ∈ e.obsList, p.2 ≤ u) : + Measurable[𝓕 u] fun ω ↦ e.eval (fun i t ↦ X i t ω) := by + induction e generalizing u with + | const c => exact measurable_const + | obs i t => exact (hX i t).mono (𝓕.mono (hle (i, t) (by simp [Payoff.obsList]))) le_rfl + | add a b ha hb => + obtain ⟨hl, hr⟩ := List.forall_mem_append.1 hle; exact (ha hl).add (hb hr) + | sub a b ha hb => + obtain ⟨hl, hr⟩ := List.forall_mem_append.1 hle; exact (ha hl).sub (hb hr) + | mul a b ha hb => + obtain ⟨hl, hr⟩ := List.forall_mem_append.1 hle; exact (ha hl).mul (hb hr) + | max a b ha hb => + obtain ⟨hl, hr⟩ := List.forall_mem_append.1 hle; exact (ha hl).max (hb hr) + | min a b ha hb => + obtain ⟨hl, hr⟩ := List.forall_mem_append.1 hle; exact (ha hl).min (hb hr) + | indicatorLt a b ha hb => + obtain ⟨hl, hr⟩ := List.forall_mem_append.1 hle + exact Measurable.ite (measurableSet_lt (ha hl) (hb hr)) measurable_const measurable_const + | rpow a p ha => exact (ha hle).pow_const _ + +/-- Evaluating a payoff against a model whose every coordinate is bounded is bounded: each +constructor combines its bounds into one, an indicator is bounded by `1`, and a nonnegative power +by the power of the bound (`Real.abs_rpow_le_abs_rpow`). -/ +theorem Payoff.exists_bound_eval (e : Payoff ι) {X : ι → ℝ≥0 → Ω → ℝ} + (hX : ∀ i t, ∃ C, ∀ ω, |X i t ω| ≤ C) : ∃ C, ∀ ω, |e.eval (fun i t ↦ X i t ω)| ≤ C := by + induction e with + | const c => exact ⟨|c|, fun _ ↦ le_rfl⟩ + | obs i t => exact hX i t + | add a b ha hb => + obtain ⟨⟨Ca, ha⟩, ⟨Cb, hb⟩⟩ := And.intro ha hb + exact ⟨Ca + Cb, fun ω ↦ (abs_add_le _ _).trans (add_le_add (ha ω) (hb ω))⟩ + | sub a b ha hb => + obtain ⟨⟨Ca, ha⟩, ⟨Cb, hb⟩⟩ := And.intro ha hb + exact ⟨Ca + Cb, fun ω ↦ (abs_sub _ _).trans (add_le_add (ha ω) (hb ω))⟩ + | mul a b ha hb => + obtain ⟨⟨Ca, ha⟩, ⟨Cb, hb⟩⟩ := And.intro ha hb + exact ⟨Ca * Cb, fun ω ↦ (abs_mul _ _).trans_le + (mul_le_mul (ha ω) (hb ω) (abs_nonneg _) ((abs_nonneg _).trans (ha ω)))⟩ + | max a b ha hb => + obtain ⟨⟨Ca, ha⟩, ⟨Cb, hb⟩⟩ := And.intro ha hb + exact ⟨Max.max Ca Cb, fun ω ↦ abs_max_le_max_abs_abs.trans (max_le_max (ha ω) (hb ω))⟩ + | min a b ha hb => + obtain ⟨⟨Ca, ha⟩, ⟨Cb, hb⟩⟩ := And.intro ha hb + exact ⟨Max.max Ca Cb, fun ω ↦ abs_min_le_max_abs_abs.trans (max_le_max (ha ω) (hb ω))⟩ + | indicatorLt a b _ _ => exact ⟨1, fun ω ↦ by simp only [Payoff.eval]; split_ifs <;> simp⟩ + | rpow a p ha => + obtain ⟨C, hC⟩ := ha + exact ⟨C ^ (p : ℝ), fun ω ↦ (Real.abs_rpow_le_abs_rpow _ _).trans + (Real.rpow_le_rpow (abs_nonneg _) (hC ω) p.2)⟩ + +/-- **A bounded model prices every fixed-date contract.** Against a finite measure and a measurable +model whose every coordinate is bounded, every contract that pays at fixed dates +(`Contract.FixedDated`) has an integrable discounted payoff, so `Contract.value_both` applies to +any two of them with no further hypothesis. A finite-state model such as the binomial tree is +bounded; a lognormal one is not, and there each instrument's integrability is proved on its own +(`Models/BlackScholes/BlackScholes.lean`). A `payAtHit` is excluded: the hitting time of a +measurable process need not be measurable, and an unbounded discount factor evaluated at a random +date need not be integrable. -/ +theorem Contract.integrable_pathPV_of_bounded {Q : Measure Ω} [IsFiniteMeasure Q] + (D : ℝ≥0 → ℝ) {X : ι → ℝ≥0 → Ω → ℝ} (hXm : ∀ i t, Measurable (X i t)) + (hXb : ∀ i t, ∃ C, ∀ ω, |X i t ω| ≤ C) {c : Contract ι} (hc : c.FixedDated) : + Integrable (fun ω ↦ c.pathPV D (fun i t ↦ X i t ω)) Q := by + induction c with + | zero => simp [Contract.pathPV, Contract.cashflows] + | pay t a => + obtain ⟨C, hC⟩ := a.exists_bound_eval hXb + simp only [Contract.pathPV, Contract.cashflows, List.map_cons, List.map_nil, + List.sum_cons, List.sum_nil, add_zero] + exact (Integrable.of_bound (a.measurable_eval X hXm).aestronglyMeasurable C + (.of_forall hC)).const_mul _ + | payAtHit i A a => exact hc.elim + | both a b ha hb => + simp only [Contract.pathPV_both] + exact (ha hc.1).add (hb hc.2) + | scale r a ha => simpa only [Contract.pathPV_scale] using (ha hc).const_mul r + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Contracts/Core.lean b/LeanPool/MathFin/Contracts/Core.lean new file mode 100644 index 0000000000..1d5ae64363 --- /dev/null +++ b/LeanPool/MathFin/Contracts/Core.lean @@ -0,0 +1,303 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Process.HittingTime + +/-! +# A reified payoff language + +`Payoff ι` and `Contract ι` represent *what an instrument pays*, independently of +any stochastic model. Market outcomes enter through `Scenario ι = ι → ℝ≥0 → ℝ`; +a stochastic model is a law on that type, and appears only from +`Pricing/Value.lean` onward. + +Every other payoff in this library — `Models/BlackScholes/Call.lean`, `Digital.lean`, +`CappedCall.lean` — is written inline as a lambda inside the integral that prices +it, so the payoff and the model are the same syntactic object. This file +separates them, which is what lets `Models/BlackScholes/BlackScholes.lean` price a capped +call by *composing* two European call values rather than by evaluating a third +integral. + +## Payments at a random date + +`Contract.pay` fixes its date. `Contract.payAtHit i A amount` pays at the first time the observed +underlying `i` enters the set `A` (`Scenario.hitTime`, Mathlib's `hittingAfter` of the observed +path), which is how a payment at a default time is written: the underlying is the default +indicator `1{τ ≤ u}` and `A = [1, ∞)`. The model-free results below hold for every contract; the +integrability theorem of `Contracts/Adapted.lean` is for `Contract.FixedDated` ones, since a +hitting time of an arbitrary path is not measurable and an unbounded discount factor evaluated at +it need not be integrable. + +## Deliberately absent + +Branching contracts (`ifThen`), currency, and the lifecycle layer (outstanding +notional, termination, partial redemption). Each is additive and each waits for +the corpus entry that forces it; see +`docs/specs/2026-08-16-contracts-tower-design.md` §2.3. + +## Main definitions + +* `Scenario ι`: a market scenario `ι → ℝ≥0 → ℝ`, the realized value of each underlying at each + time. +* `Payoff ι`: payoff formulas as data (constants, observations, `add`, `sub`, `mul`, `max`, `min`, + `indicatorLt`, and `rpow` with an `ℝ≥0` exponent); `Payoff.eval` interprets one against a + scenario. +* `Payoff.obsList`: the `(underlying, date)` observations a payoff reads, found syntactically. +* `Contract.obsList`: the observations a contract's payoffs read. +* `Scenario.hitTime`: the first time the observed underlying `i` lies in `A`, as Mathlib's + `hittingAfter` of the observed path. +* `Contract ι`: contracts built from `zero`, `pay t amount`, `payAtHit i A amount`, `both` and + `scale`. +* `Contract.cashflows`: the list of `(time, amount)` cashflows of a contract along a scenario. +* `Contract.FixedDated`: the contract contains no `payAtHit`. +* `Contract.dates`: the payment dates of a contract's `pay` nodes. +* `Contract.pathPV`: the present value of a contract along one scenario path, for a discount + function `D : ℝ≥0 → ℝ`. + +## Main results + +* `Contract.pathPV_both`, `Contract.pathPV_scale` — `pathPV` is additive over + `both` and homogeneous over `scale`. These are what `Pricing/Value.lean` + integrates to get linearity of `value`. +* `Contract.pathPV_const` — a constant discount factor comes out of `pathPV`. +* `Payoff.eval_congr`, `Contract.cashflows_congr` — a payoff, and a fixed-dated contract's cash + flows, are the same on two scenarios that agree at the observations they read + (`Payoff.obsList`, `Contract.obsList`). `Pricing/Value.lean` lifts this to models that agree + almost surely (`Contract.value_congr_ae`). +* `Contract.pathPV_congr` — a fixed-dated contract's present value depends on the scenario only + at `c.obsList` and on the discount factor only at `c.dates`. `Pricing/Value.lean` lifts this to + models whose observations have one law (`Contract.value_eq_of_map_observation_eq`). + +## Source + +The layered separation of contract semantics from pricing semantics, and the +framing "the contract is not the model", are due to Paul Bilokon, +*The Contract Is Not the Model: Proof-Carrying Exotic Derivatives and the +Economics of Model Risk* (working paper, 9 August 2026; Mathematical +Finance, Imperial College London), with code at + (Apache-2.0). That paper in +turn builds on the compositional contract-DSL of +Peyton Jones, Eber and Seward (2000) and the certified-contract work of Bahr, +Berthold and Elsman (2015) and Annenkov (2018). + +This file takes his separation of the payoff object from the probability law. +The type design is ours: a typed underlying index rather than `String` keys, a +single inductive rather than a mutual `NumExpr` / `BoolExpr` pair, and `ℝ≥0` time +matching `Filtration ℝ≥0 mΩ`. + +No code is copied from `lean_contracts`; every definition and proof here is +written for this library. See `docs/specs/2026-08-16-contracts-tower-design.md` +§6 for the full credit line. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [S. Peyton Jones, J. M. Eber and J. Seward, *Composing contracts*][PeytonJonesEberSeward2000] + +## Tags + +contract language, reified payoff, contract DSL, Bilokon, Peyton Jones, payment at default time, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +open scoped NNReal + +namespace MathFin.Contracts + +variable {ι : Type*} + +/-- A market scenario: for each underlying `i : ι` and time `t : ℝ≥0`, its +realized value. A stochastic model is a probability law on this type. -/ +abbrev Scenario (ι : Type*) := ι → ℝ≥0 → ℝ + +/-- A payoff formula, reified as data rather than written inline as a lambda. +Independent of any scenario until `Payoff.eval` interprets it against one. -/ +inductive Payoff (ι : Type*) where + | const (c : ℝ) + | obs (i : ι) (t : ℝ≥0) + | add (a b : Payoff ι) + | sub (a b : Payoff ι) + | mul (a b : Payoff ι) + | max (a b : Payoff ι) + | min (a b : Payoff ι) + | indicatorLt (a b : Payoff ι) + /-- A nonnegative real power. The exponent is an `ℝ≥0`, so `eval` stays continuous in the + observations and bounded on bounded scenarios; there is no `exp` or `log` node, since `log` is + unbounded near `0`. Meaningful on nonnegative observations: at a negative base `Real.rpow` is + the junk value `|x|^p cos(pπ)`, which no model theorem here reaches (spots are positive). -/ + | rpow (a : Payoff ι) (p : ℝ≥0) + +/-- Interpret a `Payoff` against a `Scenario`, producing its realized value. -/ +noncomputable def Payoff.eval (s : Scenario ι) : Payoff ι → ℝ + | .const c => c + | .obs i t => s i t + | .add a b => eval s a + eval s b + | .sub a b => eval s a - eval s b + | .mul a b => eval s a * eval s b + | .max a b => Max.max (eval s a) (eval s b) + | .min a b => Min.min (eval s a) (eval s b) + | .indicatorLt a b => if eval s a < eval s b then 1 else 0 + | .rpow a p => eval s a ^ (p : ℝ) + +/-- The `(underlying, date)` observations a `Payoff` reads, found syntactically. An +over-approximation: `Payoff.mul (.const 0) (.obs i t)` evaluates to `0` on every scenario, yet +lists `(i, t)`. -/ +def Payoff.obsList : Payoff ι → List (ι × ℝ≥0) + | .const _ => [] + | .obs i t => [(i, t)] + | .add a b | .sub a b | .mul a b | .max a b | .min a b | .indicatorLt a b => + a.obsList ++ b.obsList + | .rpow a _ => a.obsList + +/-- The first time the observed underlying `i` of a scenario lies in `A`: Mathlib's +`hittingAfter` of the process `u ↦ s i u` at time `0`, which is `⊤` if it never does. It is the +infimum of the times at which the observation is in `A`, so it is attained when the path is right +continuous and `A` closed. -/ +noncomputable def Scenario.hitTime (s : Scenario ι) (i : ι) (A : Set ℝ) : WithTop ℝ≥0 := + MeasureTheory.hittingAfter (fun u (s : Scenario ι) ↦ s i u) A 0 s + +/-- A contract: what gets paid, when, built from `Payoff`s by combination. -/ +inductive Contract (ι : Type*) where + | zero + | pay (t : ℝ≥0) (amount : Payoff ι) + /-- A payment at a random date: `amount` is paid at the first time the observed underlying `i` + lies in `A` (`Scenario.hitTime`), and nothing is paid if it never does. After the `when` of + Peyton Jones, Eber and Seward (2000), with the event reduced to an observed underlying entering a + set. `amount` is observed at its own fixed dates, as in `pay`. That the date is a stopping time + of a model's filtration is not asserted here. -/ + | payAtHit (i : ι) (A : Set ℝ) (amount : Payoff ι) + | both (a b : Contract ι) + | scale (c : ℝ) (a : Contract ι) + +/-- The list of `(time, amount)` cashflows a `Contract` generates along a +given `Scenario`. -/ +noncomputable def Contract.cashflows (s : Scenario ι) : + Contract ι → List (ℝ≥0 × ℝ) + | .zero => [] + | .pay t a => [(t, a.eval s)] + | .payAtHit i A a => + WithTop.recTopCoe (C := fun _ ↦ List (ℝ≥0 × ℝ)) [] (fun τ ↦ [(τ, a.eval s)]) + (s.hitTime i A) + | .both a b => cashflows s a ++ cashflows s b + | .scale c a => (cashflows s a).map fun p ↦ (p.1, c * p.2) + +/-- A contract **pays at fixed dates** if it contains no `payAtHit`: the dates of its cashflows +are then the same in every scenario. -/ +def Contract.FixedDated : Contract ι → Prop + | .zero => True + | .pay _ _ => True + | .payAtHit _ _ _ => False + | .both a b => a.FixedDated ∧ b.FixedDated + | .scale _ a => a.FixedDated + +/-- The present value of a `Contract` along one scenario path, given a +discount factor `D : ℝ≥0 → ℝ`. -/ +noncomputable def Contract.pathPV (D : ℝ≥0 → ℝ) (s : Scenario ι) + (c : Contract ι) : ℝ := + ((c.cashflows s).map fun p ↦ D p.1 * p.2).sum + +/-- **A payment at the hitting time**, when the underlying does hit `A`, at the time `τ`: the +discounted amount at `τ`. -/ +theorem Contract.pathPV_payAtHit_of_eq (D : ℝ≥0 → ℝ) (s : Scenario ι) {i : ι} {A : Set ℝ} + {τ : ℝ≥0} (a : Payoff ι) (h : s.hitTime i A = τ) : + (Contract.payAtHit i A a).pathPV D s = D τ * a.eval s := by + simp only [pathPV, cashflows, h] + change (([(τ, a.eval s)] : List (ℝ≥0 × ℝ)).map fun p ↦ D p.1 * p.2).sum = _ + simp + +/-- **A payment at the hitting time is nothing** if the underlying never hits `A`. -/ +theorem Contract.pathPV_payAtHit_of_eq_top (D : ℝ≥0 → ℝ) (s : Scenario ι) {i : ι} {A : Set ℝ} + (a : Payoff ι) (h : s.hitTime i A = ⊤) : (Contract.payAtHit i A a).pathPV D s = 0 := by + simp [pathPV, cashflows, h] + +theorem Contract.pathPV_both (D : ℝ≥0 → ℝ) (s : Scenario ι) + (a b : Contract ι) : + (Contract.both a b).pathPV D s = a.pathPV D s + b.pathPV D s := by + simp [pathPV, cashflows] + +theorem Contract.pathPV_scale (D : ℝ≥0 → ℝ) (s : Scenario ι) + (c : ℝ) (a : Contract ι) : + (Contract.scale c a).pathPV D s = c * a.pathPV D s := by + simp only [pathPV, cashflows, List.map_map] + rw [← List.sum_map_mul_left] + exact congrArg List.sum (List.map_congr_left fun p _ ↦ by simp; ring) + +/-- A constant discount factor comes out of `pathPV`: discounting every cashflow by `a` is +discounting the undiscounted present value by `a`. -/ +theorem Contract.pathPV_const (a : ℝ) (s : Scenario ι) (c : Contract ι) : + c.pathPV (fun _ ↦ a) s = a * c.pathPV (fun _ ↦ 1) s := by + simp [pathPV, List.sum_map_mul_left] + +/-! ### Two scenarios that agree where the contract looks -/ + +/-- A payoff evaluates the same on two scenarios that agree at the observations it reads. -/ +theorem Payoff.eval_congr {s s' : Scenario ι} (a : Payoff ι) + (h : ∀ p ∈ a.obsList, s p.1 p.2 = s' p.1 p.2) : a.eval s = a.eval s' := by + induction a with + | const _ => rfl + | obs i t => exact h (i, t) (List.mem_singleton_self _) + | add a b ha hb | sub a b ha hb | mul a b ha hb | max a b ha hb | min a b ha hb + | indicatorLt a b ha hb => + obtain ⟨hl, hr⟩ := List.forall_mem_append.1 h + simp only [Payoff.eval, ha hl, hb hr] + | rpow a _ ha => simp only [Payoff.eval, ha h] + +/-- The `(underlying, date)` observations a `Contract` reads (those of its payoffs; the dates of +a `payAtHit` are not listed, which is why the congruence below asks for `FixedDated`). -/ +def Contract.obsList : Contract ι → List (ι × ℝ≥0) + | .zero => [] + | .pay _ a => a.obsList + | .payAtHit _ _ a => a.obsList + | .both a b => a.obsList ++ b.obsList + | .scale _ a => a.obsList + +/-- A fixed-dated contract generates the same cash flows along two scenarios that agree at the +observations it reads. -/ +theorem Contract.cashflows_congr {s s' : Scenario ι} (c : Contract ι) (hc : c.FixedDated) + (h : ∀ p ∈ c.obsList, s p.1 p.2 = s' p.1 p.2) : c.cashflows s = c.cashflows s' := by + induction c with + | zero => rfl + | pay t a => simp only [Contract.cashflows, Payoff.eval_congr a h] + | payAtHit _ _ _ => exact hc.elim + | both a b ha hb => + obtain ⟨hl, hr⟩ := List.forall_mem_append.1 h + simp only [Contract.cashflows, ha hc.1 hl, hb hc.2 hr] + | scale _ a ha => simp only [Contract.cashflows, ha hc h] + +/-- The payment dates of a contract: the dates of its `pay` nodes. A `payAtHit` pays at a date the +scenario decides and lists none, which is why the congruence below asks for `FixedDated`. -/ +def Contract.dates : Contract ι → List ℝ≥0 + | .zero => [] + | .pay t _ => [t] + | .payAtHit _ _ _ => [] + | .both a b => a.dates ++ b.dates + | .scale _ a => a.dates + +/-- **A fixed-dated contract reads a scenario only at its observations and a discount factor only +at its payment dates**: two discount factors that agree on `c.dates`, along two scenarios that +agree on `c.obsList`, give the same present value. -/ +theorem Contract.pathPV_congr {D D' : ℝ≥0 → ℝ} {s s' : Scenario ι} (c : Contract ι) + (hc : c.FixedDated) (hD : ∀ t ∈ c.dates, D t = D' t) + (hs : ∀ p ∈ c.obsList, s p.1 p.2 = s' p.1 p.2) : c.pathPV D s = c.pathPV D' s' := by + induction c with + | zero => rfl + | pay t a => + simp only [pathPV, cashflows, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, + hD t (List.mem_singleton_self t), Payoff.eval_congr a hs] + | payAtHit _ _ _ => exact hc.elim + | both a b ha hb => + obtain ⟨hDa, hDb⟩ := List.forall_mem_append.1 hD + obtain ⟨hsa, hsb⟩ := List.forall_mem_append.1 hs + rw [pathPV_both, pathPV_both, ha hc.1 hDa hsa, hb hc.2 hDb hsb] + | scale _ a ha => rw [pathPV_scale, pathPV_scale, ha hc hD hs] + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Contracts/Instruments/CallPayoff.lean b/LeanPool/MathFin/Contracts/Instruments/CallPayoff.lean new file mode 100644 index 0000000000..9578690d00 --- /dev/null +++ b/LeanPool/MathFin/Contracts/Instruments/CallPayoff.lean @@ -0,0 +1,103 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Basic.Real.Basic +public import Mathlib.Tactic.Linarith.Frontend +public import Mathlib.Analysis.Convex.Function + +/-! +# Call payoffs in the strike + +The call payoff `K ↦ max(S − K, 0)`, as a function of the strike, is convex and antitone. These are +facts about the payoff, before any model: the static no-arbitrage relations of option prices +(convexity in the strike, butterflies, the implied density) are these facts carried to prices by +the pricing functional (`Pricing/ConvexPricingFunctional.lean`, and under an arbitrary law +`Models/BlackScholes/StrikeConvexity.lean`). + +A capped call with strikes `K₁ ≤ K₂` pays `min(max(S − K₁, 0), K₂ − K₁)`. Below `K₁` the payoff is +`0`; between `K₁` and `K₂` it tracks `S − K₁`; above `K₂` it is capped at `K₂ − K₁`. That is the +bull-call spread `max(S − K₁, 0) − max(S − K₂, 0)`, so a capped call is a long call at `K₁` and a +short call at `K₂` (`Contracts/Instruments/Options.lean` builds it that way). + +## Main results + +* `convexOn_call_payoff`: `K ↦ max(S − K, 0)` is convex. +* `antitone_call_payoff`: `K ↦ max(S − K, 0)` is antitone. +* `cappedCall_eq_bull_spread`: the capped call is the bull-call spread. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 11.2 +* [R. C. Merton, *Theory of rational option pricing*][Merton1973] + +## Tags + +call payoff, strike convexity, capped call, bull call spread, payoff decomposition, static +replication, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +/-- The affine function `K ↦ a − K` is convex on `Set.univ`. Affine +functions are simultaneously convex and concave; the inequality holds +with equality. -/ +lemma convexOn_sub_const_id (a : ℝ) : + ConvexOn ℝ Set.univ (fun K : ℝ ↦ a - K) := by + refine ⟨convex_univ, fun K₁ _ K₂ _ s t _ _ hst ↦ ?_⟩ + change a - (s • K₁ + t • K₂) ≤ s • (a - K₁) + t • (a - K₂) + simp only [smul_eq_mul] + -- Equality (affine functions are tight): `s·a + t·a = a` via `s + t = 1`. + have h_sa_ta : s * a + t * a = a := by linear_combination a * hst + linarith + +/-- **Call payoff is convex in the strike**: `K ↦ max(S − K, 0)` is convex. + +This is the structural spine of static option-price no-arbitrage relations. +Butterfly non-negativity and Breeden-Litzenberger PDF positivity are +discrete and infinitesimal consequences (respectively) of this single fact, +after passing through risk-neutral expectation. -/ +lemma convexOn_call_payoff (S : ℝ) : + ConvexOn ℝ Set.univ (fun K : ℝ ↦ max (S - K) 0) := + (convexOn_sub_const_id S).sup (convexOn_const (0 : ℝ) convex_univ) + +/-- **Call payoff is antitone in the strike**: higher strikes pay less. + +Equivalent to monotonicity of `max(·, 0)` composed with `K ↦ S − K` (which +is itself antitone). The single-line consequence of monotonicity of `max`. -/ +lemma antitone_call_payoff (S : ℝ) : + Antitone (fun K : ℝ ↦ max (S - K) 0) := + fun _ _ h ↦ max_le_max (by linarith) le_rfl + + +/-- **Capped call as a bull call spread**: for `K₁ ≤ K₂`, +`min(max(S − K₁, 0), K₂ − K₁) = max(S − K₁, 0) − max(S − K₂, 0)`. -/ +lemma cappedCall_eq_bull_spread (S K₁ K₂ : ℝ) (h : K₁ ≤ K₂) : + min (max (S - K₁) 0) (K₂ - K₁) = + max (S - K₁) 0 - max (S - K₂) 0 := by + by_cases h1 : S ≤ K₁ + · have e1 : max (S - K₁) 0 = 0 := max_eq_right (by linarith) + have e2 : max (S - K₂) 0 = 0 := max_eq_right (by linarith) + rw [e1, e2] + rw [min_eq_left (by linarith : (0:ℝ) ≤ K₂ - K₁)]; ring + push Not at h1 + by_cases h2 : S ≤ K₂ + · have e1 : max (S - K₁) 0 = S - K₁ := max_eq_left (by linarith) + have e2 : max (S - K₂) 0 = 0 := max_eq_right (by linarith) + rw [e1, e2] + rw [min_eq_left (by linarith : S - K₁ ≤ K₂ - K₁)]; ring + · push Not at h2 + have e1 : max (S - K₁) 0 = S - K₁ := max_eq_left (by linarith) + have e2 : max (S - K₂) 0 = S - K₂ := max_eq_left (by linarith) + rw [e1, e2] + rw [min_eq_right (by linarith : K₂ - K₁ ≤ S - K₁)]; ring + +end MathFin diff --git a/LeanPool/MathFin/Contracts/Instruments/Credit.lean b/LeanPool/MathFin/Contracts/Instruments/Credit.lean new file mode 100644 index 0000000000..e757b5cd70 --- /dev/null +++ b/LeanPool/MathFin/Contracts/Instruments/Credit.lean @@ -0,0 +1,100 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Contracts.Instruments.FixedIncome + +/-! +# A credit default swap, as a contract + +The credit event is observed through the default indicator process `N u = 1{τ ≤ u}`, the single +underlying `()` of the scenario (`Models/Credit/DefaultTime.lean` supplies it from a default +time `τ`). `N` enters `[1, ∞)` exactly at `τ`, and `Contract.payAtHit` pays at the first time an +observed underlying enters a set, so a payment at the default time is a contract: + +* the **protection leg paid at the default time** pays the loss `1 − R` at `τ` if `τ ≤ T` + (`cdsProtectionAtDefault`), the contract whose value under the Cox default time, at a flat + rate, is `Cox.protectionLeg`. + +The tower otherwise pays at fixed dates, so the CDS is also written on a payment grid +`t 0 ≤ t 1 ≤ … ≤ t n`: + +* the **premium leg** pays the spread `s` on each accrual period `[tᵢ, tᵢ₊₁]` if the name has + survived to the payment date, `s · (tᵢ₊₁ − tᵢ) · (1 − N tᵢ₊₁)` at `tᵢ₊₁` (`cdsPremiumLeg`); + no premium accrued between the last payment and a default is paid; +* the **protection leg** pays the loss `1 − R` at the end of the period in which default + happens, `(1 − R) · (N tᵢ₊₁ − N tᵢ)` at `tᵢ₊₁` (`cdsProtectionLeg`); +* the **protection buyer** receives the protection leg and pays the premium leg (`cdsBuyer`). + +The grid legs are `payFlows`, so their path value is a finite sum (`pathPV_cdsPremiumLeg`, +`pathPV_cdsProtectionLeg`). Default is paid at the end of its period, not at `τ`: the grid +protection leg is the discretisation of `cdsProtectionAtDefault` +(`Models/Credit/DefaultTimeMesh.lean` proves the limit). There is no continuous premium +stream in the tower, so the premium leg exists only on the grid. + +## Main definitions + +* `cdsProtectionAtDefault`, `cdsPremiumLeg`, `cdsProtectionLeg`, `cdsBuyer`. + +## Main results + +* `pathPV_cdsPremiumLeg`, `pathPV_cdsProtectionLeg`. + +## Tags + +credit default swap, CDS premium leg, protection leg, default indicator, accrual grid, MSC 91G40, +JEL G12, JEL G33 +-/ + +@[expose] public section + +open scoped NNReal + +namespace MathFin.Contracts + +/-- The **protection leg paid at the default time**: `(1 − R)·N_T` is paid at the first time the +default indicator `N` reaches `1`, that is at `τ`, and nothing if the name never defaults. +`N_T = 1{τ ≤ T}`, so the loss `1 − R` is paid at `τ` exactly when default happens by `T`. -/ +noncomputable def cdsProtectionAtDefault (T : ℝ≥0) (R : ℝ) : Contract Unit := + .payAtHit () (Set.Ici 1) (.mul (.const (1 - R)) (.obs () T)) + +/-- The **premium leg** of a CDS at spread `s` on the grid `t`: at `t (i + 1)`, for `i < n`, pay +`s · (t (i + 1) − t i)` if no default has happened by then, i.e. times `1 − N (t (i + 1))` +for the default indicator `N`. -/ +noncomputable def cdsPremiumLeg (t : ℕ → ℝ≥0) (s : ℝ) (n : ℕ) : Contract Unit := + payFlows (fun i ↦ t (i + 1)) + (fun i ↦ .mul (.const (s * ((t (i + 1) : ℝ) - t i))) (.sub (.const 1) (.obs () (t (i + 1))))) n + +/-- The **protection leg** of a CDS with recovery `R` on the grid `t`: at `t (i + 1)`, for +`i < n`, pay `(1 − R) · (N (t (i + 1)) − N (t i))`, the loss given default if default happened +during `(t i, t (i + 1)]`. -/ +noncomputable def cdsProtectionLeg (t : ℕ → ℝ≥0) (R : ℝ) (n : ℕ) : Contract Unit := + payFlows (fun i ↦ t (i + 1)) + (fun i ↦ .mul (.const (1 - R)) (.sub (.obs () (t (i + 1))) (.obs () (t i)))) n + +/-- The **protection buyer's** CDS: receive the protection leg, pay the premium leg. -/ +noncomputable def cdsBuyer (t : ℕ → ℝ≥0) (s R : ℝ) (n : ℕ) : Contract Unit := + .both (cdsProtectionLeg t R n) (.scale (-1) (cdsPremiumLeg t s n)) + +/-- Along a scenario `σ` whose observation at `u` is the default indicator `σ () u`, the premium +leg is worth `∑ D(tᵢ₊₁) · s (tᵢ₊₁ − tᵢ) (1 − σ () tᵢ₊₁)`. -/ +theorem pathPV_cdsPremiumLeg (D : ℝ≥0 → ℝ) (σ : Scenario Unit) (t : ℕ → ℝ≥0) (s : ℝ) (n : ℕ) : + (cdsPremiumLeg t s n).pathPV D σ + = ∑ i ∈ Finset.range n, D (t (i + 1)) * + (s * ((t (i + 1) : ℝ) - t i) * (1 - σ () (t (i + 1)))) := by + simp [cdsPremiumLeg, pathPV_payFlows, Payoff.eval] + +/-- Along a scenario `σ` whose observation at `u` is the default indicator `σ () u`, the +protection leg is worth `∑ D(tᵢ₊₁) · (1 − R) (σ () tᵢ₊₁ − σ () tᵢ)`. -/ +theorem pathPV_cdsProtectionLeg (D : ℝ≥0 → ℝ) (σ : Scenario Unit) (t : ℕ → ℝ≥0) (R : ℝ) + (n : ℕ) : + (cdsProtectionLeg t R n).pathPV D σ + = ∑ i ∈ Finset.range n, D (t (i + 1)) * ((1 - R) * (σ () (t (i + 1)) - σ () (t i))) := by + simp [cdsProtectionLeg, pathPV_payFlows, Payoff.eval] + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Contracts/Instruments/FixedIncome.lean b/LeanPool/MathFin/Contracts/Instruments/FixedIncome.lean new file mode 100644 index 0000000000..79c7c6dca9 --- /dev/null +++ b/LeanPool/MathFin/Contracts/Instruments/FixedIncome.lean @@ -0,0 +1,89 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Contracts.Core + +/-! +# Schedules of payments, as contracts + +A schedule of payments is a contract: `payFlows t a n` pays the payoff `a i` at `t i` for each +`i < n`, and along a scenario it is worth `∑ D(tᵢ) · aᵢ` (`pathPV_payFlows`); `fixedFlows t c n` +is the case of constant payoffs, `c i` at `t i`, worth `∑ D(tᵢ) cᵢ` (`pathPV_fixedFlows`). These +are the legs of bonds, annuities, swaps and credit default swaps. Nothing here assumes a model or +a pricing measure: the value of a schedule in every model is `value_fixedFlows_deterministic` +(`Pricing/Value.lean`), and the bonds and swaps of a deterministic curve are in +`Models/Rates/DeterministicCurve.lean`. + +## Main definitions + +* `payFlows` — a schedule of payments; `fixedFlows` — the schedule of fixed cash flows. + +## Main results + +* `pathPV_payFlows`, `pathPV_fixedFlows` — what a schedule pays along a scenario. + +## Source + +The layered separation of contract semantics from pricing semantics, and the +framing "the contract is not the model", are due to Paul Bilokon, +*The Contract Is Not the Model: Proof-Carrying Exotic Derivatives and the +Economics of Model Risk* (working paper, 9 August 2026; Mathematical +Finance, Imperial College London), with code at + (Apache-2.0). That paper in +turn builds on the compositional contract-DSL of +Peyton Jones, Eber and Seward (2000) and the certified-contract work of Bahr, +Berthold and Elsman (2015) and Annenkov (2018). + +No code is copied from `lean_contracts`; every definition and proof here is +written for this library. See `docs/specs/2026-08-16-contracts-tower-design.md` +§6 for the full credit line. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], ch. 7 + +## Tags + +schedule of payments, fixed cash flows, coupon, annuity, payoff language, MSC 91G30, JEL G12 +-/ + +@[expose] public section + +open scoped NNReal + +namespace MathFin.Contracts + +variable {ι : Type*} + +/-- A **schedule of payments**: for each `i < n`, pay the payoff `a i` at time `t i`. -/ +noncomputable def payFlows (t : ℕ → ℝ≥0) (a : ℕ → Payoff ι) : ℕ → Contract ι + | 0 => .zero + | n + 1 => .both (payFlows t a n) (.pay (t n) (a n)) + +/-- Along every scenario, a schedule of payments is worth `∑ D(tᵢ) · aᵢ`. -/ +theorem pathPV_payFlows (D : ℝ≥0 → ℝ) (s : Scenario ι) (t : ℕ → ℝ≥0) (a : ℕ → Payoff ι) + (n : ℕ) : + (payFlows t a n).pathPV D s = ∑ i ∈ Finset.range n, D (t i) * (a i).eval s := by + induction n with + | zero => simp [payFlows, Contract.pathPV, Contract.cashflows] + | succ n ih => + rw [payFlows, Contract.pathPV_both, ih, Finset.sum_range_succ] + simp [Contract.pathPV, Contract.cashflows] + +/-- A **schedule of fixed cash flows**: for each `i < n`, pay `c i` at time `t i`. -/ +noncomputable def fixedFlows (t : ℕ → ℝ≥0) (c : ℕ → ℝ) (n : ℕ) : Contract ι := + payFlows t (fun i ↦ .const (c i)) n + +/-- Along every scenario, a schedule of fixed cash flows is worth `∑ D(tᵢ) cᵢ`. -/ +theorem pathPV_fixedFlows (D : ℝ≥0 → ℝ) (s : Scenario ι) (t : ℕ → ℝ≥0) (c : ℕ → ℝ) (n : ℕ) : + (fixedFlows t c n : Contract ι).pathPV D s = ∑ i ∈ Finset.range n, D (t i) * c i := by + simp [fixedFlows, pathPV_payFlows, Payoff.eval] + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Contracts/Instruments/Options.lean b/LeanPool/MathFin/Contracts/Instruments/Options.lean new file mode 100644 index 0000000000..e5b0e86190 --- /dev/null +++ b/LeanPool/MathFin/Contracts/Instruments/Options.lean @@ -0,0 +1,179 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Contracts.Core +public import LeanPool.MathFin.Contracts.Instruments.CallPayoff + +/-! +# Options, as contracts + +The instruments: the European call and put, the cash-or-nothing digital, the forward, the capped +call and the power call, each a `Contract Unit` written in the payoff language of +`Contracts/Core.lean`; the exchange option is a `Contract (Fin 2)` on two underlyings. Nothing here +assumes a model or a pricing measure. What is proved is what the instruments pay, along every +scenario. What follows for their values in every model, through the linearity of +`Contract.value`, is in `Pricing/Parity.lean`, and their prices in a particular model live in that +model's file (`Models/BlackScholes/BlackScholes.lean`). + +The capped call is *defined* by composition, as a long call at `K₁` and a short call at `K₂`; +`cappedCall_payoff_eq` is what earns it the name: for `K₁ ≤ K₂` it pays +`min(max(S − K₁, 0), K₂ − K₁)` (`MathFin.cappedCall_eq_bull_spread`). + +## Main definitions + +* `europeanCallPayoff` — the call's payoff on its own. +* `europeanCall`, `europeanPut`, `digitalCall`, `forward` — the single-maturity instruments. +* `cappedCall` — a long `europeanCall K₁ T` combined with a short `europeanCall K₂ T`. +* `powerCall` — the call on `S_T ^ a`, the power being the payoff language's `rpow` node. +* `geomAsianCall` — the call on the geometric average of the underlying over `n` dates, from + `Payoff.obsProd` and `rpow` at `1/n`. +* `chooser` — the chooser option as the static portfolio of a call and a put at the chooser date. +* `exchangeOption` — pays `max (S¹_T − S²_T) 0`. + +## Main results + +* `pathPV_europeanCall_eq_put_add_forward` — a call pays a put plus a forward on every path. +* `cappedCall_payoff_eq` — for `K₁ ≤ K₂`, `cappedCall K₁ K₂ T` pays the capped payoff. + +## Source + +The layered separation of contract semantics from pricing semantics, and the +framing "the contract is not the model", are due to Paul Bilokon, +*The Contract Is Not the Model: Proof-Carrying Exotic Derivatives and the +Economics of Model Risk* (working paper, 9 August 2026; Mathematical +Finance, Imperial College London), with code at + (Apache-2.0). That paper in +turn builds on the compositional contract-DSL of +Peyton Jones, Eber and Seward (2000) and the certified-contract work of Bahr, +Berthold and Elsman (2015) and Annenkov (2018). + +Compositional contract construction — building an instrument from simpler ones +and pricing it by composition — is the core of Bilokon's DSL and of Peyton +Jones, Eber and Seward before him; what is added here is that the composition +is priced through the library's own closed forms rather than left as a +denotational identity. + +No code is copied from `lean_contracts`; every definition and proof here is +written for this library. See `docs/specs/2026-08-16-contracts-tower-design.md` +§6 for the full credit line. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 12.3 + +## Tags + +European option, digital option, capped call, chooser option, power call, exchange option, +geometric Asian, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +open MeasureTheory +open scoped NNReal + +namespace MathFin.Contracts + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- The European call payoff `max (S_T - K) 0`, on its own so that every consumer builds against +the same term rather than re-spelling it. -/ +noncomputable def europeanCallPayoff (K : ℝ) (T : ℝ≥0) : Payoff Unit := + .max (.sub (.obs () T) (.const K)) (.const 0) + +/-- The reified European call: pays `max (S_T - K) 0` at maturity `T`. -/ +noncomputable def europeanCall (K : ℝ) (T : ℝ≥0) : Contract Unit := + .pay T (europeanCallPayoff K T) + +/-- The reified European put: pays `max (K - S_T) 0` at maturity `T`. -/ +noncomputable def europeanPut (K : ℝ) (T : ℝ≥0) : Contract Unit := + .pay T (.max (.sub (.const K) (.obs () T)) (.const 0)) + +/-- The reified cash-or-nothing digital call: pays `1` at maturity `T` iff `S_T > K`. -/ +noncomputable def digitalCall (K : ℝ) (T : ℝ≥0) : Contract Unit := + .pay T (.indicatorLt (.const K) (.obs () T)) + +/-- The reified power call: pays `max (S_T ^ a - K) 0` at maturity `T`, the power being the +payoff language's `rpow` node at the natural exponent `a`. -/ +noncomputable def powerCall (a : ℕ) (K : ℝ) (T : ℝ≥0) : Contract Unit := + .pay T (.max (.sub (.rpow (.obs () T) a) (.const K)) (.const 0)) + +/-- The product of the observations of underlying `i` at the dates `ts`, built from `Payoff.mul`. -/ +def Payoff.obsProd {ι : Type*} (i : ι) : List ℝ≥0 → Payoff ι + | [] => .const 1 + | t :: ts => .mul (.obs i t) (obsProd i ts) + +/-- Evaluating `Payoff.obsProd` is the product of the observed values. -/ +theorem Payoff.eval_obsProd {ι : Type*} (s : Scenario ι) (i : ι) (ts : List ℝ≥0) : + (Payoff.obsProd i ts).eval s = (ts.map (s i)).prod := by + induction ts with + | nil => simp [Payoff.obsProd, Payoff.eval] + | cons t ts ih => simp [Payoff.obsProd, Payoff.eval, ih] + +/-- The reified geometric-average Asian call over the `n` averaging dates `τ`: pays +`max ((∏ᵢ S_{τᵢ}) ^ (1/n) - K) 0` at maturity `T`, the geometric average being `Payoff.obsProd` +under the `rpow` node at the exponent `1/n`. -/ +noncomputable def geomAsianCall (K : ℝ) (T : ℝ≥0) {n : ℕ} (τ : Fin n → ℝ≥0) : Contract Unit := + .pay T (.max (.sub (.rpow (.obsProd () (List.ofFn τ)) (n : ℝ≥0)⁻¹) (.const K)) (.const 0)) + +/-- The reified simple chooser option, by static replication. At the chooser date `t₁ ≤ T` the +holder takes the more valuable of the call and the put, `max (C_{t₁}, P_{t₁})`; put–call parity at +`t₁` (`MathFin.chooserPayoff_decompose_BS`) writes that as +`C_{t₁} + max (K e^{−r(T−t₁)} − S_{t₁}, 0)`. The first term is what a call struck at `K` maturing at +`T` is worth at `t₁`, the second pays at `t₁`, so the chooser is the call at `K, T` together with a +put maturing at `t₁` struck at `K e^{−r(T−t₁)}`. The payoff language has no node for the conditional +value at `t₁`, so this is the replicating portfolio, not the holder's choice written as a payoff; +the rate `r` enters only through the put's strike. -/ +noncomputable def chooser (K r : ℝ) (T t₁ : ℝ≥0) : Contract Unit := + .both (europeanCall K T) (europeanPut (K * Real.exp (-(r * ((T : ℝ) - t₁)))) t₁) + +/-- The reified exchange option (Margrabe) on two underlyings indexed by `Fin 2`: pays +`max (S¹_T - S²_T) 0` at maturity `T`. -/ +noncomputable def exchangeOption (T : ℝ≥0) : Contract (Fin 2) := + .pay T (.max (.sub (.obs 0 T) (.obs 1 T)) (.const 0)) + +/-- The reified forward struck at `K`: pays `S_T − K` at maturity `T`. -/ +noncomputable def forward (K : ℝ) (T : ℝ≥0) : Contract Unit := + .pay T (.sub (.obs () T) (.const K)) + +/-- A capped call struck at `K₁` and capped at `K₂`, built as a long call at `K₁` and a +short call at `K₂`. `cappedCall_payoff_eq` proves this composed object really does pay +`min (max (S - K₁) 0) (K₂ - K₁)`. -/ +noncomputable def cappedCall (K₁ K₂ : ℝ) (T : ℝ≥0) : Contract Unit := + .both (europeanCall K₁ T) (.scale (-1) (europeanCall K₂ T)) + +/-- **The capped call really pays the capped payoff.** For `K₁ ≤ K₂`, `cappedCall K₁ K₂ T`, +the composed long-call/short-call contract, pays exactly `min(max(S − K₁, 0), K₂ − K₁)` along +any scenario — the identity `MathFin.cappedCall_eq_bull_spread` transported from a pointwise +real equation to the contract's own `pathPV`. This is what earns the definition its name. -/ +theorem cappedCall_payoff_eq {K₁ K₂ : ℝ} (h : K₁ ≤ K₂) {T : ℝ≥0} + (s : Scenario Unit) : + (cappedCall K₁ K₂ T).pathPV (fun _ ↦ 1) s + = min (max (s () T - K₁) 0) (K₂ - K₁) := by + simp only [cappedCall, Contract.pathPV, Contract.cashflows, europeanCall, europeanCallPayoff, + Payoff.eval, List.map_append, List.map_cons, List.map_nil, List.sum_append, + List.sum_cons, List.sum_nil, one_mul, add_zero] + linarith [MathFin.cappedCall_eq_bull_spread (s () T) K₁ K₂ h] + +/-- **A call is a put plus a forward, on every path.** Along any scenario and for any discount, +the call struck at `K` pays what the put struck at `K` and the forward struck at `K` pay together: +`max (S_T − K) 0 = max (K − S_T) 0 + (S_T − K)`. No model is involved. -/ +theorem pathPV_europeanCall_eq_put_add_forward (D : ℝ≥0 → ℝ) (s : Scenario Unit) (K : ℝ) + (T : ℝ≥0) : + (europeanCall K T).pathPV D s + = (Contract.both (europeanPut K T) (forward K T)).pathPV D s := by + simp only [europeanCall, europeanCallPayoff, europeanPut, forward, Contract.pathPV, + Contract.cashflows, Payoff.eval, List.map_append, List.map_cons, List.map_nil, + List.sum_append, List.sum_cons, List.sum_nil, add_zero, ← mul_add] + have h := max_zero_sub_max_neg_zero_eq_self (s () T - K) + rw [neg_sub] at h + linear_combination D T * h + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Imports.lean b/LeanPool/MathFin/Imports.lean new file mode 100644 index 0000000000..1b7fc7c736 --- /dev/null +++ b/LeanPool/MathFin/Imports.lean @@ -0,0 +1,486 @@ +/- +Copyright (c) 2026 Lean Pool contributors. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Lean Pool contributors +-/ +module -- shake: keep-all --deprecated_module: ignore + +-- Generated project imports; run `lake exe mk_all`. +public import LeanPool.MathFin +public import LeanPool.MathFin.Choice.Performance.BetSizeSigmoid +public import LeanPool.MathFin.Choice.Performance.DownsideMetrics +public import LeanPool.MathFin.Choice.Performance.FracDiffWeights +public import LeanPool.MathFin.Choice.Performance.Kelly +public import LeanPool.MathFin.Choice.Performance.LabelUniqueness +public import LeanPool.MathFin.Choice.Performance.PurgedCV +public import LeanPool.MathFin.Choice.Performance.Ratios +public import LeanPool.MathFin.Choice.Performance.RatiosExtended +public import LeanPool.MathFin.Choice.Performance.RelativeDrawdown +public import LeanPool.MathFin.Choice.Portfolio.BlackLitterman +public import LeanPool.MathFin.Choice.Portfolio.BlackLittermanND +public import LeanPool.MathFin.Choice.Portfolio.CAPM +public import LeanPool.MathFin.Choice.Portfolio.CAPMEquilibrium +public import LeanPool.MathFin.Choice.Portfolio.ConvexQPKKT +public import LeanPool.MathFin.Choice.Portfolio.CovariancePSD +public import LeanPool.MathFin.Choice.Portfolio.Equicorrelation +public import LeanPool.MathFin.Choice.Portfolio.Markowitz +public import LeanPool.MathFin.Choice.Portfolio.MarkowitzLagrangian +public import LeanPool.MathFin.Choice.Portfolio.MarkowitzNAsset +public import LeanPool.MathFin.Choice.Portfolio.PosSemidefCauchySchwarz +public import LeanPool.MathFin.Choice.Portfolio.RiskParity +public import LeanPool.MathFin.Choice.Portfolio.RiskParityFOC +public import LeanPool.MathFin.Choice.Portfolio.SharpeFOCDerivation +public import LeanPool.MathFin.Choice.Portfolio.SingleIndexModel +public import LeanPool.MathFin.Choice.Portfolio.TangentPortfolio +public import LeanPool.MathFin.Choice.Portfolio.TwoFundSeparation +public import LeanPool.MathFin.Choice.Utility.VonNeumannMorgenstern +public import LeanPool.MathFin.Contracts.Adapted +public import LeanPool.MathFin.Contracts.Core +public import LeanPool.MathFin.Contracts.Instruments.CallPayoff +public import LeanPool.MathFin.Contracts.Instruments.Credit +public import LeanPool.MathFin.Contracts.Instruments.FixedIncome +public import LeanPool.MathFin.Contracts.Instruments.Options +public import LeanPool.MathFin.Init +public import LeanPool.MathFin.Insurance.ActuarialInsurance +public import LeanPool.MathFin.Insurance.AnnuityValue +public import LeanPool.MathFin.Insurance.EsscherPremium +public import LeanPool.MathFin.Insurance.Insurance +public import LeanPool.MathFin.Insurance.Mortality +public import LeanPool.MathFin.Insurance.StandardDeviationPrinciple +public import LeanPool.MathFin.Insurance.SurvivalModel +public import LeanPool.MathFin.Insurance.SurvivalUnification +public import LeanPool.MathFin.Markets.DeFi.Aave +public import LeanPool.MathFin.Markets.DeFi.Compound +public import LeanPool.MathFin.Markets.DeFi.Dai +public import LeanPool.MathFin.Markets.DeFi.LiquidationAsStructuralDefault +public import LeanPool.MathFin.Markets.Execution.AlmgrenChriss +public import LeanPool.MathFin.Markets.Microstructure.GlostenMilgrom +public import LeanPool.MathFin.Markets.Microstructure.GlostenMilgromCondExp +public import LeanPool.MathFin.Markets.Microstructure.GlostenMilgromMarket +public import LeanPool.MathFin.Markets.Microstructure.GlostenMilgromModel +public import LeanPool.MathFin.Markets.Microstructure.MarketMakingRiccati +public import LeanPool.MathFin.Markets.Microstructure.MatrixMarketMakingRiccati +public import LeanPool.MathFin.Markets.Microstructure.RollSpread +public import LeanPool.MathFin.Models.Bachelier.Bachelier +public import LeanPool.MathFin.Models.Bachelier.BachelierGreeks +public import LeanPool.MathFin.Models.Binomial.American +public import LeanPool.MathFin.Models.Binomial.BarrierReflection +public import LeanPool.MathFin.Models.Binomial.Bermudan +public import LeanPool.MathFin.Models.Binomial.Binomial +public import LeanPool.MathFin.Models.Binomial.BinomialCompleteMarket +public import LeanPool.MathFin.Models.Binomial.BinomialLimit +public import LeanPool.MathFin.Models.Binomial.CRRCharFun +public import LeanPool.MathFin.Models.Binomial.CRRClosedForm +public import LeanPool.MathFin.Models.Binomial.CRRConvergence +public import LeanPool.MathFin.Models.Binomial.CRRDiscreteIto +public import LeanPool.MathFin.Models.Binomial.DriftLimit +public import LeanPool.MathFin.Models.Binomial.EuropeanReplication +public import LeanPool.MathFin.Models.Binomial.FlipPaths +public import LeanPool.MathFin.Models.Binomial.Girsanov +public import LeanPool.MathFin.Models.Binomial.Market +public import LeanPool.MathFin.Models.Binomial.MartingaleRepresentation +public import LeanPool.MathFin.Models.Binomial.MertonAmericanCallTree +public import LeanPool.MathFin.Models.Binomial.Model +public import LeanPool.MathFin.Models.Binomial.MultiPeriodFTAP +public import LeanPool.MathFin.Models.Binomial.PathMeasure +public import LeanPool.MathFin.Models.Binomial.PathReflection +public import LeanPool.MathFin.Models.Binomial.ReplicatingUniqueness +public import LeanPool.MathFin.Models.Binomial.SecondFTAP +public import LeanPool.MathFin.Models.Binomial.SnellEnvelope +public import LeanPool.MathFin.Models.BlackScholes.American.AmericanQDPlusLimits +public import LeanPool.MathFin.Models.BlackScholes.American.JuZhongZeroRateLimit +public import LeanPool.MathFin.Models.BlackScholes.American.Stopping.PlanePartial +public import LeanPool.MathFin.Models.BlackScholes.AsianGeometric +public import LeanPool.MathFin.Models.BlackScholes.AsianGeometricN +public import LeanPool.MathFin.Models.BlackScholes.AsianInequality +public import LeanPool.MathFin.Models.BlackScholes.BSCallHypFromBrownian +public import LeanPool.MathFin.Models.BlackScholes.BarrierParity +public import LeanPool.MathFin.Models.BlackScholes.BasketMomentMatching +public import LeanPool.MathFin.Models.BlackScholes.BinaryBarrierOption +public import LeanPool.MathFin.Models.BlackScholes.BisectionIV +public import LeanPool.MathFin.Models.BlackScholes.BlackScholes +public import LeanPool.MathFin.Models.BlackScholes.BlackScholesAsian +public import LeanPool.MathFin.Models.BlackScholes.BlackScholesExchange +public import LeanPool.MathFin.Models.BlackScholes.Call +public import LeanPool.MathFin.Models.BlackScholes.Chooser +public import LeanPool.MathFin.Models.BlackScholes.Digital +public import LeanPool.MathFin.Models.BlackScholes.DigitalGreeks +public import LeanPool.MathFin.Models.BlackScholes.Dividends +public import LeanPool.MathFin.Models.BlackScholes.DividendsGreeks +public import LeanPool.MathFin.Models.BlackScholes.ExchangeOption +public import LeanPool.MathFin.Models.BlackScholes.Forward +public import LeanPool.MathFin.Models.BlackScholes.GarmanNormalForm +public import LeanPool.MathFin.Models.BlackScholes.GaussianGirsanov +public import LeanPool.MathFin.Models.BlackScholes.GaussianSmoothing +public import LeanPool.MathFin.Models.BlackScholes.GreekSigns +public import LeanPool.MathFin.Models.BlackScholes.HeynenKatTwoAssetBarrier +public import LeanPool.MathFin.Models.BlackScholes.HigherGreeks +public import LeanPool.MathFin.Models.BlackScholes.ImpliedVolatility +public import LeanPool.MathFin.Models.BlackScholes.KirkSpreadApproximation +public import LeanPool.MathFin.Models.BlackScholes.LognormalMoments +public import LeanPool.MathFin.Models.BlackScholes.Lookback +public import LeanPool.MathFin.Models.BlackScholes.MargrabeGrounding +public import LeanPool.MathFin.Models.BlackScholes.MonteCarloPricer +public import LeanPool.MathFin.Models.BlackScholes.NewtonConvergence +public import LeanPool.MathFin.Models.BlackScholes.PDE +public import LeanPool.MathFin.Models.BlackScholes.PDEFromFeynmanKac +public import LeanPool.MathFin.Models.BlackScholes.PartialTimeBarrierOption +public import LeanPool.MathFin.Models.BlackScholes.PowerCall +public import LeanPool.MathFin.Models.BlackScholes.PowerOption +public import LeanPool.MathFin.Models.BlackScholes.PricingFromBrownian +public import LeanPool.MathFin.Models.BlackScholes.Put +public import LeanPool.MathFin.Models.BlackScholes.PutGreeks +public import LeanPool.MathFin.Models.BlackScholes.PutStrikeConvexity +public import LeanPool.MathFin.Models.BlackScholes.QuantoGrounding +public import LeanPool.MathFin.Models.BlackScholes.RiskNeutralProbabilities +public import LeanPool.MathFin.Models.BlackScholes.SpotConvexity +public import LeanPool.MathFin.Models.BlackScholes.StockNumeraire +public import LeanPool.MathFin.Models.BlackScholes.StrikeConvexity +public import LeanPool.MathFin.Models.BlackScholes.StrikeGreeks +public import LeanPool.MathFin.Models.BlackScholes.StulzTwoAssetRainbow +public import LeanPool.MathFin.Models.Credit.CDSTimeVarying +public import LeanPool.MathFin.Models.Credit.CVA +public import LeanPool.MathFin.Models.Credit.Cox +public import LeanPool.MathFin.Models.Credit.Credit +public import LeanPool.MathFin.Models.Credit.DVA +public import LeanPool.MathFin.Models.Credit.DefaultDensity +public import LeanPool.MathFin.Models.Credit.DefaultTime +public import LeanPool.MathFin.Models.Credit.DefaultTimeMesh +public import LeanPool.MathFin.Models.Credit.FirstToDefault +public import LeanPool.MathFin.Models.Credit.HazardCurve +public import LeanPool.MathFin.Models.Credit.KMVMerton +public import LeanPool.MathFin.Models.Credit.KMVMertonStructural +public import LeanPool.MathFin.Models.Forwards.AR1OUCalibration +public import LeanPool.MathFin.Models.Forwards.Black76 +public import LeanPool.MathFin.Models.Forwards.Black76Greeks +public import LeanPool.MathFin.Models.Forwards.FisherSraffaOwnRate +public import LeanPool.MathFin.Models.Forwards.FxForwardParity +public import LeanPool.MathFin.Models.Forwards.SchwartzOneFactor +public import LeanPool.MathFin.Models.Forwards.TheoryOfStorage +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionCanonical +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionDensity +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionExponent +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionIdentifiability +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionMerton +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionMixing +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionMoments +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionOptionPrices +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionProcess +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionThinning +public import LeanPool.MathFin.Models.Jumps.JumpImpliedVol +public import LeanPool.MathFin.Models.Jumps.MertonClassicDisplay +public import LeanPool.MathFin.Models.Jumps.MertonDominance +public import LeanPool.MathFin.Models.Jumps.MertonGreeks +public import LeanPool.MathFin.Models.Jumps.MertonJumpDiffusion +public import LeanPool.MathFin.Models.Jumps.MertonStrikeGreeks +public import LeanPool.MathFin.Models.LocalVol.ForwardSmile +public import LeanPool.MathFin.Models.ModelFree.BreedenLitzenberger +public import LeanPool.MathFin.Models.ModelFree.CalendarArbitrage +public import LeanPool.MathFin.Models.ModelFree.CallPriceFunction +public import LeanPool.MathFin.Models.ModelFree.CallSpreadDigital +public import LeanPool.MathFin.Models.ModelFree.CarrMadan +public import LeanPool.MathFin.Models.ModelFree.MarketCallPrice +public import LeanPool.MathFin.Models.ModelFree.PriceBounds +public import LeanPool.MathFin.Models.ModelFree.RoperConverse +public import LeanPool.MathFin.Models.ModelFree.SVI.Admissibility +public import LeanPool.MathFin.Models.ModelFree.SVI.Assembly +public import LeanPool.MathFin.Models.ModelFree.SVI.AssociatedTrace +public import LeanPool.MathFin.Models.ModelFree.SVI.BlackScholesBridge +public import LeanPool.MathFin.Models.ModelFree.SVI.BlackSmile +public import LeanPool.MathFin.Models.ModelFree.SVI.CallConvexity +public import LeanPool.MathFin.Models.ModelFree.SVI.ClearedSignature +public import LeanPool.MathFin.Models.ModelFree.SVI.Companion +public import LeanPool.MathFin.Models.ModelFree.SVI.ConvexKink +public import LeanPool.MathFin.Models.ModelFree.SVI.CriticalPoints +public import LeanPool.MathFin.Models.ModelFree.SVI.DegreeProgram +public import LeanPool.MathFin.Models.ModelFree.SVI.Denominators +public import LeanPool.MathFin.Models.ModelFree.SVI.Derivatives +public import LeanPool.MathFin.Models.ModelFree.SVI.DomainFormula +public import LeanPool.MathFin.Models.ModelFree.SVI.ExtendedFormula +public import LeanPool.MathFin.Models.ModelFree.SVI.FiniteCertificate +public import LeanPool.MathFin.Models.ModelFree.SVI.HermiteIdentity +public import LeanPool.MathFin.Models.ModelFree.SVI.ImaginaryTraceSignature +public import LeanPool.MathFin.Models.ModelFree.SVI.MarketRealisation +public import LeanPool.MathFin.Models.ModelFree.SVI.Matrices +public import LeanPool.MathFin.Models.ModelFree.SVI.MatrixCertificate +public import LeanPool.MathFin.Models.ModelFree.SVI.MatrixSignature +public import LeanPool.MathFin.Models.ModelFree.SVI.NilpotentSquareRoot +public import LeanPool.MathFin.Models.ModelFree.SVI.ParameterPolynomials +public import LeanPool.MathFin.Models.ModelFree.SVI.Polynomial +public import LeanPool.MathFin.Models.ModelFree.SVI.PolynomialCertificate +public import LeanPool.MathFin.Models.ModelFree.SVI.ProductSignature +public import LeanPool.MathFin.Models.ModelFree.SVI.QuadraticRay +public import LeanPool.MathFin.Models.ModelFree.SVI.QuadraticRootSignature +public import LeanPool.MathFin.Models.ModelFree.SVI.QuotientProduct +public import LeanPool.MathFin.Models.ModelFree.SVI.RankOneSignature +public import LeanPool.MathFin.Models.ModelFree.SVI.RealIrreducibles +public import LeanPool.MathFin.Models.ModelFree.SVI.RealRootSignature +public import LeanPool.MathFin.Models.ModelFree.SVI.RealRootTrace +public import LeanPool.MathFin.Models.ModelFree.SVI.Reduction +public import LeanPool.MathFin.Models.ModelFree.SVI.SigmaZeroCertificate +public import LeanPool.MathFin.Models.ModelFree.SVI.SigmaZeroConvexity +public import LeanPool.MathFin.Models.ModelFree.SVI.SigmaZeroDerivatives +public import LeanPool.MathFin.Models.ModelFree.SVI.SignFormula +public import LeanPool.MathFin.Models.ModelFree.SVI.SignVariations +public import LeanPool.MathFin.Models.ModelFree.SVI.SignatureProgram +public import LeanPool.MathFin.Models.ModelFree.SVI.TailCondition +public import LeanPool.MathFin.Models.ModelFree.SVI.TraceForm +public import LeanPool.MathFin.Models.ModelFree.SVI.TraceSignature +public import LeanPool.MathFin.Models.ModelFree.Spreads +public import LeanPool.MathFin.Models.ModelFree.VarianceSwap +public import LeanPool.MathFin.Models.ModelFree.VarianceSwapDriftImmunity +public import LeanPool.MathFin.Models.ModelFree.VarianceSwapEquipartition +public import LeanPool.MathFin.Models.ModelFree.VarianceSwapEquivalence +public import LeanPool.MathFin.Models.ModelFree.VarianceSwapFromQV +public import LeanPool.MathFin.Models.ModelFree.VarianceSwapLimit +public import LeanPool.MathFin.Models.Rates.ABCDBlack76 +public import LeanPool.MathFin.Models.Rates.ABCDVolatility +public import LeanPool.MathFin.Models.Rates.AffineTermStructurePDE +public import LeanPool.MathFin.Models.Rates.BondForward +public import LeanPool.MathFin.Models.Rates.Bootstrapping +public import LeanPool.MathFin.Models.Rates.CIRRiccati +public import LeanPool.MathFin.Models.Rates.CIRSquaredOU +public import LeanPool.MathFin.Models.Rates.CMS +public import LeanPool.MathFin.Models.Rates.CMSContract +public import LeanPool.MathFin.Models.Rates.Caplet +public import LeanPool.MathFin.Models.Rates.CleanPriceAccrued +public import LeanPool.MathFin.Models.Rates.ConvexityImmunization +public import LeanPool.MathFin.Models.Rates.ConvexitySensitivity +public import LeanPool.MathFin.Models.Rates.CouponBonds +public import LeanPool.MathFin.Models.Rates.DeterministicCurve +public import LeanPool.MathFin.Models.Rates.DeterministicMarket +public import LeanPool.MathFin.Models.Rates.DurationSensitivity +public import LeanPool.MathFin.Models.Rates.FRA +public import LeanPool.MathFin.Models.Rates.ForwardMeasure +public import LeanPool.MathFin.Models.Rates.ForwardRate +public import LeanPool.MathFin.Models.Rates.GSRBond +public import LeanPool.MathFin.Models.Rates.GSRBondPriceAt +public import LeanPool.MathFin.Models.Rates.GSRPiecewiseVol +public import LeanPool.MathFin.Models.Rates.HJM +public import LeanPool.MathFin.Models.Rates.HJMBond +public import LeanPool.MathFin.Models.Rates.HullWhiteBond +public import LeanPool.MathFin.Models.Rates.HullWhiteBondPriceAt +public import LeanPool.MathFin.Models.Rates.HullWhiteCalibration +public import LeanPool.MathFin.Models.Rates.Immunization +public import LeanPool.MathFin.Models.Rates.Inflation +public import LeanPool.MathFin.Models.Rates.InterestRateSwap +public import LeanPool.MathFin.Models.Rates.Jamshidian +public import LeanPool.MathFin.Models.Rates.KeyRateDuration +public import LeanPool.MathFin.Models.Rates.LoanAmortization +public import LeanPool.MathFin.Models.Rates.MacaulayModified +public import LeanPool.MathFin.Models.Rates.NelsonSiegelSvensson +public import LeanPool.MathFin.Models.Rates.OUHermiteVasicek +public import LeanPool.MathFin.Models.Rates.PeriodicCompounding +public import LeanPool.MathFin.Models.Rates.ShortRate +public import LeanPool.MathFin.Models.Rates.TimingAdjustment +public import LeanPool.MathFin.Models.Rates.Vasicek +public import LeanPool.MathFin.Models.Rates.VasicekBond +public import LeanPool.MathFin.Models.Rates.VasicekBondPrice +public import LeanPool.MathFin.Models.Rates.VasicekBondPriceAt +public import LeanPool.MathFin.Models.Rates.VasicekMarket +public import LeanPool.MathFin.Models.Rates.VasicekMarketPriceOfRisk +public import LeanPool.MathFin.Models.Rates.VasicekSDE +public import LeanPool.MathFin.Models.Rates.VasicekSDEGaussian +public import LeanPool.MathFin.Models.Rates.VasicekYieldNelsonSiegel +public import LeanPool.MathFin.Models.Rates.VasicekZeroMeanReversionLimit +public import LeanPool.MathFin.Models.Rates.YieldCurve +public import LeanPool.MathFin.Models.Rates.ZCB +public import LeanPool.MathFin.Models.StochVol.Heston +public import LeanPool.MathFin.Models.StochVol.HestonSmallVolOfVol +public import LeanPool.MathFin.Models.StochVol.LSVLeverage +public import LeanPool.MathFin.Models.StochVol.SABRFlochKennedyLimits +public import LeanPool.MathFin.Models.StochVol.SABRImpliedVol +public import LeanPool.MathFin.Pricing.ContinuousMarket +public import LeanPool.MathFin.Pricing.ConvexPricingFunctional +public import LeanPool.MathFin.Pricing.DiscreteMarket +public import LeanPool.MathFin.Pricing.Duality.ConvexDuality +public import LeanPool.MathFin.Pricing.Duality.ConvexSeparation +public import LeanPool.MathFin.Pricing.EquivMartingaleMeasure +public import LeanPool.MathFin.Pricing.FTAP.ContinuousFTAP +public import LeanPool.MathFin.Pricing.FTAP.DalangMortonWillinger +public import LeanPool.MathFin.Pricing.FTAP.DensityPasting +public import LeanPool.MathFin.Pricing.FTAP.FTAP +public import LeanPool.MathFin.Pricing.FTAP.FTAPComplete +public import LeanPool.MathFin.Pricing.FTAP.FTAPDiscrete +public import LeanPool.MathFin.Pricing.FTAP.FTAPOnePeriod +public import LeanPool.MathFin.Pricing.FTAP.FTAPOnePeriodVector +public import LeanPool.MathFin.Pricing.FTAP.MarketFTAP +public import LeanPool.MathFin.Pricing.FTAP.NoArbitrageLocal +public import LeanPool.MathFin.Pricing.ForwardMeasure +public import LeanPool.MathFin.Pricing.Girsanov +public import LeanPool.MathFin.Pricing.Market +public import LeanPool.MathFin.Pricing.NoArbitrageCore +public import LeanPool.MathFin.Pricing.NoArbitrageDerivations +public import LeanPool.MathFin.Pricing.Numeraire +public import LeanPool.MathFin.Pricing.OneDateMarket +public import LeanPool.MathFin.Pricing.Parity +public import LeanPool.MathFin.Pricing.ReplicationPricing +public import LeanPool.MathFin.Pricing.StatePrices +public import LeanPool.MathFin.Pricing.Value +public import LeanPool.MathFin.Pricing.WienerIntegralForwardMeasure +public import LeanPool.MathFin.Probability.Analysis.AffineMinorant +public import LeanPool.MathFin.Probability.Analysis.Bisection +public import LeanPool.MathFin.Probability.Analysis.DerivOfDeriv +public import LeanPool.MathFin.Probability.Analysis.ExponentialDiscount +public import LeanPool.MathFin.Probability.Analysis.ExtendOfNormIsometry +public import LeanPool.MathFin.Probability.Analysis.FiniteMeasureCauchySchwarz +public import LeanPool.MathFin.Probability.Analysis.IndepFreezing +public import LeanPool.MathFin.Probability.Analysis.IndepIsometryKernel +public import LeanPool.MathFin.Probability.Analysis.LpMulIsometry +public import LeanPool.MathFin.Probability.Analysis.StdSimplexProd +public import LeanPool.MathFin.Probability.Brownian.BrownianCylinderGeneration +public import LeanPool.MathFin.Probability.Brownian.BrownianExpMoment +public import LeanPool.MathFin.Probability.Brownian.BrownianMarkov +public import LeanPool.MathFin.Probability.Brownian.BrownianMartingale +public import LeanPool.MathFin.Probability.Brownian.BrownianQuadraticVariation +public import LeanPool.MathFin.Probability.Brownian.ExpMartingaleBrownian +public import LeanPool.MathFin.Probability.Brownian.ExpMartingaleQBrownian +public import LeanPool.MathFin.Probability.Brownian.Girsanov.GirsanovConstantTheta +public import LeanPool.MathFin.Probability.Brownian.Girsanov.GirsanovSimpleDoleansMoments +public import LeanPool.MathFin.Probability.Brownian.Girsanov.GirsanovSimpleTheta +public import LeanPool.MathFin.Probability.Brownian.Girsanov.PredictableDensityGeneral +public import LeanPool.MathFin.Probability.Brownian.Girsanov.SimpleDoleansExponential +public import LeanPool.MathFin.Probability.Brownian.Girsanov.WienerIntegralGirsanov +public import LeanPool.MathFin.Probability.Brownian.Ito.AdaptedProcessToLp +public import LeanPool.MathFin.Probability.Brownian.Ito.DriftProcessModification +public import LeanPool.MathFin.Probability.Brownian.Ito.DriftProcessPredictable +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralCLM +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralCovariation +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralHorizonDense +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralL2 +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralL2Dense +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcess +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessContinuousModification +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessGeneral +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessIsometry +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessL2Inf +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessL2Infinite +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessLocalMartingale +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessLocalMartingaleGeneral +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessLocalMartingaleInfinite +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessMartingale +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIsometryAdapted +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoProcessPredictable +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoProcessQV +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoRiemannSum +public import LeanPool.MathFin.Probability.Brownian.Ito.StochasticFubini +public import LeanPool.MathFin.Probability.Brownian.Ito.StochasticFubiniIto +public import LeanPool.MathFin.Probability.Brownian.QuadraticVariationL2 +public import LeanPool.MathFin.Probability.Brownian.SDE.OUSpectral +public import LeanPool.MathFin.Probability.Brownian.SDE.SDEExistence +public import LeanPool.MathFin.Probability.Brownian.SDE.SDEPathwise +public import LeanPool.MathFin.Probability.Brownian.SDE.SDEUniqueness +public import LeanPool.MathFin.Probability.Brownian.UnifPart +public import LeanPool.MathFin.Probability.Brownian.WeightedQuadraticVariation +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralExpMoment +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralFiltration +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralGaussian +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralIndicator +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralIto +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralL2 +public import LeanPool.MathFin.Probability.Dependence.Copula +public import LeanPool.MathFin.Probability.Dependence.CopulaFamilies +public import LeanPool.MathFin.Probability.Dependence.CorrelationFallacies +public import LeanPool.MathFin.Probability.Dependence.GaussianCopula +public import LeanPool.MathFin.Probability.Dependence.HoeffdingCovariance +public import LeanPool.MathFin.Probability.Dependence.MarshallOlkin +public import LeanPool.MathFin.Probability.Dependence.Sklar +public import LeanPool.MathFin.Probability.Discrete.DoobDecomposition +public import LeanPool.MathFin.Probability.Discrete.L2MartingaleConvergence +public import LeanPool.MathFin.Probability.Discrete.MarkovPathMeasure +public import LeanPool.MathFin.Probability.Discrete.MartingaleDominator +public import LeanPool.MathFin.Probability.Discrete.MartingaleTransform +public import LeanPool.MathFin.Probability.Discrete.OptionalSamplingInequality +public import LeanPool.MathFin.Probability.Discrete.SnellDoobDecomposition +public import LeanPool.MathFin.Probability.Discrete.SnellEnvelope +public import LeanPool.MathFin.Probability.Gaussian.BivariateGaussian +public import LeanPool.MathFin.Probability.Gaussian.BivariateNormalCDF +public import LeanPool.MathFin.Probability.Gaussian.FeynmanKacHeatEquation +public import LeanPool.MathFin.Probability.Gaussian.GaussianCDFDeriv +public import LeanPool.MathFin.Probability.Gaussian.GaussianMoments +public import LeanPool.MathFin.Probability.Gaussian.GaussianPairLinearLaw +public import LeanPool.MathFin.Probability.Gaussian.GaussianPartialMoments +public import LeanPool.MathFin.Probability.Gaussian.NormalQuantile +public import LeanPool.MathFin.Probability.Gaussian.NormalTail +public import LeanPool.MathFin.Probability.Gaussian.StandardGaussianMGF +public import LeanPool.MathFin.Probability.Gaussian.StandardNormal +public import LeanPool.MathFin.Probability.Gaussian.WeakForwardUniqueness +public import LeanPool.MathFin.Probability.Jumps.CompoundPoissonMGF +public import LeanPool.MathFin.Probability.Jumps.ExpMartingaleIndepIncrements +public import LeanPool.MathFin.Probability.Jumps.PoissonCompensatedBilinear +public import LeanPool.MathFin.Probability.Jumps.PoissonCompensatedIntegralL2 +public import LeanPool.MathFin.Probability.Jumps.PoissonCompensatedIntegralL2Dense +public import LeanPool.MathFin.Probability.Jumps.PoissonCompensatedIntegralOperator +public import LeanPool.MathFin.Probability.Jumps.PoissonCompensatedIsometryAdapted +public import LeanPool.MathFin.Probability.Jumps.PoissonCompensatedSimpleIntegrand +public import LeanPool.MathFin.Probability.Jumps.PoissonCounting +public import LeanPool.MathFin.Probability.Jumps.PoissonInterarrival +public import LeanPool.MathFin.Probability.Jumps.PoissonMaxima +public import LeanPool.MathFin.Probability.Jumps.PoissonPgf +public import LeanPool.MathFin.Probability.Jumps.PoissonRandomMeasure +public import LeanPool.MathFin.Probability.Jumps.PoissonSuperposition +public import LeanPool.MathFin.Probability.Jumps.PoissonThinning +public import LeanPool.MathFin.Probability.Laws.ErlangSum +public import LeanPool.MathFin.Probability.Laws.Esscher +public import LeanPool.MathFin.Probability.Laws.Estimation +public import LeanPool.MathFin.Probability.Laws.ExpMin +public import LeanPool.MathFin.Probability.Laws.ExtremeValue +public import LeanPool.MathFin.Probability.Laws.FiniteWeights +public import LeanPool.MathFin.Probability.Laws.GammaPoissonMixturePgf +public import LeanPool.MathFin.Probability.Laws.GeneralizedPareto +public import LeanPool.MathFin.Probability.Laws.Quantile +public import LeanPool.MathFin.Probability.Laws.QuantileConvergence +public import LeanPool.MathFin.Probability.Laws.StudentT +public import LeanPool.MathFin.Probability.Martingales.BoundedLocalMartingale +public import LeanPool.MathFin.Probability.Martingales.ChangeOfMeasure +public import LeanPool.MathFin.Probability.Martingales.EquivMeasure +public import LeanPool.MathFin.Probability.Martingales.LocalisationInMeasure +public import LeanPool.MathFin.Probability.Martingales.LpContinuousMartingaleConvergence +public import LeanPool.MathFin.Probability.Martingales.MartingaleFrozen +public import LeanPool.MathFin.Probability.Martingales.MartingaleSetIntegral +public import LeanPool.MathFin.Probability.Martingales.StoppedProcessPaths +public import LeanPool.MathFin.Probability.Martingales.TimeChange +public import LeanPool.MathFin.Probability.Martingales.UnifIntegrableL2 +public import LeanPool.MathFin.Probability.Support.DoobContinuous +public import LeanPool.MathFin.Probability.Support.LocalMartingale +public import LeanPool.MathFin.Risk.AcceptanceSet +public import LeanPool.MathFin.Risk.Additivity +public import LeanPool.MathFin.Risk.Coherent +public import LeanPool.MathFin.Risk.CoherentAxioms +public import LeanPool.MathFin.Risk.CollateralizedExposureBrownian +public import LeanPool.MathFin.Risk.ComponentVaR +public import LeanPool.MathFin.Risk.CompoundPoissonCVaR +public import LeanPool.MathFin.Risk.Concentration +public import LeanPool.MathFin.Risk.ConcentrationVariance +public import LeanPool.MathFin.Risk.ContractRisk +public import LeanPool.MathFin.Risk.Credit.BernoulliMixture +public import LeanPool.MathFin.Risk.Credit.CreditMetrics +public import LeanPool.MathFin.Risk.Credit.CreditRiskPlus +public import LeanPool.MathFin.Risk.Credit.OneFactorCopula +public import LeanPool.MathFin.Risk.Credit.TrancheLeg +public import LeanPool.MathFin.Risk.Credit.TrancheLoss +public import LeanPool.MathFin.Risk.Credit.VasicekIRB +public import LeanPool.MathFin.Risk.DiscreteVaR +public import LeanPool.MathFin.Risk.Elicitability +public import LeanPool.MathFin.Risk.EntropicRisk +public import LeanPool.MathFin.Risk.EquicorrelationConcentration +public import LeanPool.MathFin.Risk.ExpectedShortfall +public import LeanPool.MathFin.Risk.Expectile +public import LeanPool.MathFin.Risk.ExposureMeasures +public import LeanPool.MathFin.Risk.Gaussian +public import LeanPool.MathFin.Risk.GaussianExpectedShortfall +public import LeanPool.MathFin.Risk.GaussianRiskMarkowitz +public import LeanPool.MathFin.Risk.GaussianValueAtRisk +public import LeanPool.MathFin.Risk.JointElicitability +public import LeanPool.MathFin.Risk.LawInvariance +public import LeanPool.MathFin.Risk.PositionsConvention +public import LeanPool.MathFin.Risk.RiskClosedForms +public import LeanPool.MathFin.Risk.RockafellarUryasev +public import LeanPool.MathFin.Risk.SACCRExposure +public import LeanPool.MathFin.Risk.Spectral +public import LeanPool.MathFin.Risk.StudentTValueAtRisk +public import LeanPool.MathFin.Risk.UtilityDerivation +public import LeanPool.MathFin.Risk.VaRSuperadditivity +public import LeanPool.MathFin.Risk.ValueAtRisk +public import LeanPool.MathFin.Risk.ValueAtRiskBisection +public import LeanPool.MathFin.Risk.WorstCaseRisk diff --git a/LeanPool/MathFin/Init.lean b/LeanPool/MathFin/Init.lean new file mode 100644 index 0000000000..aaf24646d1 --- /dev/null +++ b/LeanPool/MathFin/Init.lean @@ -0,0 +1,45 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module -- shake: keep-downstream + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import Lean.Meta.Tactic.Grind.RegisterCommand + +/-! +# Library conventions + +Every MathFin module imports this file: a module that imports no other library module imports +it directly, and the rest see it through their imports (`tests/test_architecture.py`). It holds +the library's Lean-level conventions, so a new one reaches every module without a sweep +(`docs/specs/2026-11-05-library-practices-design.md` §5; CSLib's `Cslib.Init`). + +The conventions it does not hold are written down in `docs/design.md` §5. Notation is `scoped` in +the namespace of the object it writes, or `local`, and never global; an abstraction comes with +the automation its users need. + +## Main definitions + +* `pricing`: the library's grind set for pricing identities: put–call parity on the closed + forms and the risk-neutral probabilities of the trees. Tag a lemma `@[pricing =]` (or with + any other grind modifier) and close goals with `grind [pricing]`. Kept separate from the + global `grind` set so that a finance identity never slows an unrelated `grind` call. + `MathFinTest/Automation.lean` pins what it closes. + +## References + +* [CSLib][CSLib], `Cslib/Init.lean` (the conventions module every file imports). + +## Tags + +conventions, grind set, attributes, automation +-/ + +@[expose] public section + +/-- The library's grind set for pricing identities (put–call parity, the risk-neutral +probabilities of the trees): `grind [pricing]`. -/ +register_grind_attr pricing diff --git a/LeanPool/MathFin/Insurance/ActuarialInsurance.lean b/LeanPool/MathFin/Insurance/ActuarialInsurance.lean new file mode 100644 index 0000000000..10062e216b --- /dev/null +++ b/LeanPool/MathFin/Insurance/ActuarialInsurance.lean @@ -0,0 +1,90 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Basic.Real.Basic + +-- pointers: MathFin/Insurance/Insurance.lean +-- main-module: MathFin/Insurance/ActuarialInsurance.lean +-- benchmark: benchmarks/mathematical_finance.json +-- benchmark-id: mf-insurance-premium-principles +-- source-issue: 85 +-- new-defs: expectedValuePremium, variancePremium, stdDevPremium + +/-! +# Loaded premium principles + +Classical loaded premium principles — expected-value `(1 + θ)·μ`, variance +`μ + α·σ²`, standard-deviation `μ + β·σ` — and their nonnegative-loading +bound: each principle prices at or above the pure premium `μ`, the mean loss. +The principles take the mean `μ`, the variance `σ²` and the standard deviation +`σ` as numbers. For a random loss `X`, `stdDevPrinciple` of +`Insurance/StandardDeviationPrinciple.lean` is `stdDevPremium` at the mean and +standard deviation of `X`. + +## Main definitions + +* `expectedValuePremium`: the expected-value principle `(1 + θ) · μ` with loading `θ`. +* `variancePremium`: the variance principle `μ + α · σ²` with loading `α` on the variance. +* `stdDevPremium`: the standard-deviation principle `μ + β · σ` with loading `β`. + +## Main results + +* `expectedValuePremium_ge_mean`: for `0 ≤ θ` and `0 ≤ μ`, the expected-value premium is at + least `μ`. +* `variancePremium_ge_mean`: for `0 ≤ α` and `0 ≤ σ²`, the variance premium is at least `μ`. +* `stdDevPremium_ge_mean`: for `0 ≤ β` and `0 ≤ σ`, the standard-deviation premium is at least `μ`. + +## Tags + +premium principle, expected value principle, variance principle, standard deviation principle, +pure premium, loading, MSC 91G05, JEL G22 +-/ + + +@[expose] public section + +namespace MathFin + +/-- Expected-value premium principle with loading `θ`: `(1 + θ) · μ`. -/ +def expectedValuePremium (θ μ : ℝ) : ℝ := (1 + θ) * μ + +/-- Variance premium principle with loading `α` on the variance `σ²`: +`μ + α · σ²`. -/ +def variancePremium (α μ σ2 : ℝ) : ℝ := μ + α * σ2 + +/-- Standard-deviation premium principle with loading `β`: `μ + β · σ`. -/ +def stdDevPremium (β μ σ : ℝ) : ℝ := μ + β * σ + +/-- A nonnegative loading prices at or above the mean: expected-value principle. -/ +theorem expectedValuePremium_ge_mean {θ μ : ℝ} (hθ : 0 ≤ θ) (hμ : 0 ≤ μ) : + expectedValuePremium θ μ ≥ μ := + le_mul_of_one_le_left hμ (le_add_of_nonneg_right hθ) + +/-- A nonnegative loading prices at or above the mean: variance principle. -/ +theorem variancePremium_ge_mean {α σ2 : ℝ} (μ : ℝ) (hα : 0 ≤ α) (hσ2 : 0 ≤ σ2) : + variancePremium α μ σ2 ≥ μ := + le_add_of_nonneg_right (mul_nonneg hα hσ2) + +/-- A nonnegative loading prices at or above the mean: standard-deviation +principle. -/ +theorem stdDevPremium_ge_mean {β σ : ℝ} (μ : ℝ) (hβ : 0 ≤ β) (hσ : 0 ≤ σ) : + stdDevPremium β μ σ ≥ μ := + le_add_of_nonneg_right (mul_nonneg hβ hσ) + +/-- All three classical premium principles with nonnegative loadings price at +or above the pure premium. -/ +theorem premium_ge_mean (μ σ2 σ θ α β : ℝ) (hμ : 0 ≤ μ) (hσ2 : 0 ≤ σ2) + (hσ : 0 ≤ σ) (hθ : 0 ≤ θ) (hα : 0 ≤ α) (hβ : 0 ≤ β) : + expectedValuePremium θ μ ≥ μ ∧ variancePremium α μ σ2 ≥ μ ∧ + stdDevPremium β μ σ ≥ μ := + ⟨expectedValuePremium_ge_mean hθ hμ, variancePremium_ge_mean μ hα hσ2, + stdDevPremium_ge_mean μ hβ hσ⟩ + +end MathFin diff --git a/LeanPool/MathFin/Insurance/AnnuityValue.lean b/LeanPool/MathFin/Insurance/AnnuityValue.lean new file mode 100644 index 0000000000..fa9257061d --- /dev/null +++ b/LeanPool/MathFin/Insurance/AnnuityValue.lean @@ -0,0 +1,87 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Insurance.Insurance +public import LeanPool.MathFin.Insurance.SurvivalModel +public import LeanPool.MathFin.Models.Credit.DefaultTime + +/-! +# The life annuity-due is a contract value + +A net premium is the value of a survival-contingent contract. The life annuity-due +(`lifeAnnuityDue`), which `Insurance/Insurance.lean` writes directly as the sum +`∑_{k 0`, the `h'`-tilt prices the market + quoting the `h`-premium exactly when the two premiums agree. + +## References + +* [H. U. Gerber and E. S. W. Shiu, *Option pricing by Esscher transforms*][GerberShiu1994] +* [F. Esscher, *On the probability function in the collective theory of risk*][Esscher1932] + +## Tags + +Esscher premium, premium principle, exponential tilting, pricing measure, insured market, +MSC 91G05, MSC 91G20, JEL G22 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory MathFin.Contracts +open scoped NNReal + +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] + +/-- **The Esscher premium** of a loss `X` under `P` with parameter `h`: +`𝔼[X e^{hX}] / 𝔼[e^{hX}]`, the mean of `X` under the Esscher tilt `P.tilted (h * X)` of `P` +(`integral_tilted_eq_esscherPremium`). It is the junk value `0` where `e^{hX}` is not +`P`-integrable. -/ +noncomputable def esscherPremium (P : Measure Ω) (X : Ω → ℝ) (h : ℝ) : ℝ := + (∫ ω, X ω * Real.exp (h * X ω) ∂P) / ∫ ω, Real.exp (h * X ω) ∂P + +/-- **The Esscher premium is the mean of the loss under the Esscher tilt**: the tilt has density +`e^{hX}/𝔼[e^{hX}]` with respect to `P`. -/ +theorem integral_tilted_eq_esscherPremium (P : Measure Ω) (X : Ω → ℝ) (h : ℝ) : + ∫ ω, X ω ∂(P.tilted fun ω ↦ h * X ω) = esscherPremium P X h := by + rw [integral_tilted, esscherPremium, ← integral_div] + refine integral_congr_ae (.of_forall fun ω ↦ ?_) + simp only [smul_eq_mul] + ring + +/-- **The Esscher premium is the price under the Esscher tilt.** In a market with the unit +numéraire, the claim paying the asset at `T` is worth, under the Esscher tilt of the reference +measure with parameter `h`, the Esscher premium of the asset at `T`: the price is the contract +value (`Market.price`), the discount is `1`, and the mean of the asset under the tilt is the +premium (`integral_tilted_eq_esscherPremium`). -/ +theorem esscherPremium_eq_price (M : Market Unit Ω) (hN : ∀ t ω, M.numeraire t ω = 1) (T : ℝ≥0) + (h : ℝ) : + M.price (M.P.tilted fun ω ↦ h * M.asset () T ω) (.pay T (.obs () T)) + = esscherPremium M.P (M.asset () T) h := by + rw [← integral_tilted_eq_esscherPremium, Market.price, Contract.value_pay] + refine integral_congr_ae (.of_forall fun ω ↦ ?_) + simp [Market.deflator, hN, Payoff.eval, scenarioAt] + +/-- **The insured market**: the one-date market (`Market.oneDate`) of the loss `X` with the unit +numéraire, quoted at its Esscher premium until the date `T` and equal to `X` at `T`. -/ +noncomputable def insuredMarket (P : Measure Ω) {X : Ω → ℝ} (hX : Measurable X) (h : ℝ) + (T : ℝ≥0) : Market Unit Ω := + Market.oneDate P hX (esscherPremium P X h) 0 T + +variable {P : Measure Ω} {X : Ω → ℝ} {h : ℝ} + +/-- **The Esscher tilt is a pricing measure of the insured market.** For a probability measure `P` +and a measurable loss `X` with `e^{hX}` and `X e^{hX}` integrable, the Esscher tilt +`P.tilted (h * X)` is a probability measure equivalent to `P` +(`tilted_absolutelyContinuous`, `absolutelyContinuous_tilted`) under which `X` is integrable with +mean the Esscher premium (`integral_tilted_eq_esscherPremium`), the market's quote +(`Market.isPricingMeasure_oneDate`). -/ +theorem isPricingMeasure_insuredMarket_tilted [IsProbabilityMeasure P] (hX : Measurable X) + (hexp : Integrable (fun ω ↦ Real.exp (h * X ω)) P) + (hXexp : Integrable (fun ω ↦ X ω * Real.exp (h * X ω)) P) (T : ℝ≥0) : + (insuredMarket P hX h T).IsPricingMeasure T (P.tilted fun ω ↦ h * X ω) := by + have : IsProbabilityMeasure (P.tilted fun ω ↦ h * X ω) := isProbabilityMeasure_tilted hexp + refine Market.isPricingMeasure_oneDate (tilted_absolutelyContinuous _ _) + (absolutelyContinuous_tilted hexp) ?_ ?_ + · rw [integrable_tilted_iff hexp] + refine hXexp.congr (.of_forall fun ω ↦ ?_) + simp only [smul_eq_mul] + exact mul_comm _ _ + · rw [integral_tilted_eq_esscherPremium] + simp + +/-- **Under the Esscher tilt the loss is worth the Esscher premium**: in the insured market the +claim paying the loss at `T` is priced by the Esscher tilt at the premium that the market +quotes. -/ +theorem price_insuredMarket_tilted (hX : Measurable X) (T : ℝ≥0) : + (insuredMarket P hX h T).price (P.tilted fun ω ↦ h * X ω) (.pay T (.obs () T)) + = esscherPremium P X h := by + rw [insuredMarket, Market.price_pay_obs_oneDate] + simp only [neg_zero, zero_mul, Real.exp_zero, one_mul] + exact integral_tilted_eq_esscherPremium P X h + +/-- **Which Esscher tilts price the insured market.** For a date `T > 0`, the `h'`-tilt of `P` is a +pricing measure of the insured market `insuredMarket P hX h T`, the one that quotes the loss at the +`h`-premium, exactly when the `h'`-premium is that quote, +`esscherPremium P X h' = esscherPremium P X h`. +The tilts of the other parameters price the market only through that coincidence: the pricing +measure fixes the premium, not the parameter (`Market.isPricingMeasure_oneDate` and its converse +`Market.integral_eq_of_isPricingMeasure_oneDate`). That the premium is strictly increasing in the +parameter for a non-degenerate loss, so that `h' = h` follows, is not proved here. -/ +theorem isPricingMeasure_insuredMarket_tilted_iff [IsProbabilityMeasure P] (hX : Measurable X) + {T : ℝ≥0} (hT : 0 < T) {h' : ℝ} (hexp : Integrable (fun ω ↦ Real.exp (h' * X ω)) P) + (hXexp : Integrable (fun ω ↦ X ω * Real.exp (h' * X ω)) P) : + (insuredMarket P hX h T).IsPricingMeasure T (P.tilted fun ω ↦ h' * X ω) + ↔ esscherPremium P X h' = esscherPremium P X h := by + constructor + · intro hp + have hp' : (Market.oneDate P hX (esscherPremium P X h) 0 T).IsPricingMeasure T + (P.tilted fun ω ↦ h' * X ω) := hp + have hmean := (Market.integral_eq_of_isPricingMeasure_oneDate hT hp').2 + rw [integral_tilted_eq_esscherPremium] at hmean + simpa using hmean + · intro heq + have : IsProbabilityMeasure (P.tilted fun ω ↦ h' * X ω) := isProbabilityMeasure_tilted hexp + refine Market.isPricingMeasure_oneDate (tilted_absolutelyContinuous _ _) + (absolutelyContinuous_tilted hexp) ?_ ?_ + · rw [integrable_tilted_iff hexp] + refine hXexp.congr (.of_forall fun ω ↦ ?_) + simp only [smul_eq_mul] + exact mul_comm _ _ + · rw [integral_tilted_eq_esscherPremium, heq] + simp + +end MathFin diff --git a/LeanPool/MathFin/Insurance/Insurance.lean b/LeanPool/MathFin/Insurance/Insurance.lean new file mode 100644 index 0000000000..f63f04d85e --- /dev/null +++ b/LeanPool/MathFin/Insurance/Insurance.lean @@ -0,0 +1,112 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Insurance.Mortality +public import LeanPool.MathFin.Models.Rates.ZCB + +/-! +# Net premium principle and the life annuity-due + +The **net premium principle** sets the periodic premium `P` of an insurance +contract by equating the present value of the premiums with the present value of +the benefits: + + `P · annuityFactor = benefitPV`, + +so `P = benefitPV / annuityFactor` (`net_premium_principle`, Mathlib's `eq_div_iff`). + +The annuity factor of `n` payments at the start of each period is the +**annuity-due** `ä_n = ∑_{k t)` where `T` is the time of death). The **force of mortality** +at age `t` is + + `μ(t) := -S'(t) / S(t) = -d/dt log S(t)`, + +so survival reconstructs from the force as + + `S(t) = exp(-∫₀^t μ(u) du)`. + +Under a **Gompertz** mortality law `μ(t) = B · e^{c·t}`: + + `∫₀^t μ(u) du = (B/c) · (e^{c·t} - 1)`, + +so `S(t) = exp(-(B/c)·(e^{c·t} - 1))`. The structural identity in this file is +the FTC connection between cumulative force and survival. + +We mirror `Models/Credit/HazardCurve.lean` (which formalizes the same exponential +identity for credit hazard) — the actuarial and credit terminologies share the +same calculus. + +## Main definitions + +* `forceCumulative`: the cumulative force of mortality `∫₀^t μ(u) du`. +* `survivalFromForce`: the survival probability `exp(−∫₀^t μ(u) du)` built from the force `μ`. +* `IsLundbergAdjustmentCoefficient`: the adjustment-coefficient equation + `λ · (M(R) − 1) − c · R = 0`. + +## Main results + +* `survivalFromForce_at_zero`: `S(0) = 1`. +* `survivalFromForce_pos`: positivity. +* `gompertz_cumulative_force`: for `c ≠ 0`, `∫₀^t B·e^{c·u} du = (B/c)·(e^{c·t} − 1)`. + +## References + +* [Bowers and others, *Actuarial Mathematics*][BowersEtAl] + +## Tags + +force of mortality, hazard rate, Gompertz law, survival function, mortality law, cumulative hazard, +MSC 91G05, JEL G22 +-/ + +@[expose] public section + +namespace MathFin + +open Real MeasureTheory intervalIntegral + +/-- Cumulative force of mortality `∫₀^t μ(u) du` — the mortality instance of the +shared `cumulativeIntensity` (`Probability/Analysis/ExponentialDiscount`). -/ +noncomputable def forceCumulative (μ : ℝ → ℝ) (t : ℝ) : ℝ := + cumulativeIntensity μ t + +/-- Survival probability from the force of mortality `S(t) = exp(-∫₀^t μ(u) du)` — +the mortality instance of the shared `survivalFromIntensity`. -/ +noncomputable def survivalFromForce (μ : ℝ → ℝ) (t : ℝ) : ℝ := + survivalFromIntensity μ t + +/-- `S(0) = 1` (no mortality before age `0`). -/ +lemma survivalFromForce_at_zero (μ : ℝ → ℝ) : + survivalFromForce μ 0 = 1 := + survivalFromIntensity_zero μ + +/-- Survival is strictly positive (an instance of the `ExponentialDiscount` +principle `discount_pos`). -/ +lemma survivalFromForce_pos (μ : ℝ → ℝ) (t : ℝ) : + 0 < survivalFromForce μ t := discount_pos _ + +/-- **Force of mortality as the negative log-derivative of survival** — the +recovery direction `μ(t) = −d/dt log S(t)` that the classical definition +`μ(t) = −S'(t)/S(t)` encodes: for continuous `μ`, the mortality instance of +`hasDerivAt_neg_log_survivalFromIntensity`. -/ +theorem force_eq_neg_log_deriv_survival {μ : ℝ → ℝ} (t : ℝ) + (hμ : Continuous μ) : + HasDerivAt (fun s ↦ -(Real.log (survivalFromForce μ s))) (μ t) t := + hasDerivAt_neg_log_survivalFromIntensity hμ t + +/-- **Gompertz cumulative force** in closed form: +`∫₀^t B · e^{c u} du = (B/c) · (e^{c t} − 1)` for `c ≠ 0`. -/ +theorem gompertz_cumulative_force (B c t : ℝ) (hc : c ≠ 0) : + ∫ u in (0:ℝ)..t, B * Real.exp (c * u) = + (B / c) * (Real.exp (c * t) - 1) := by + -- Antiderivative: (B/c) e^{c u}. Use FTC for HasDerivAt. + have h_anti : ∀ u, HasDerivAt (fun u ↦ (B / c) * Real.exp (c * u)) + (B * Real.exp (c * u)) u := by + intro u + have h_cu : HasDerivAt (fun u : ℝ ↦ c * u) c u := by + have := (hasDerivAt_id u).const_mul c + simpa using this + have h_exp : HasDerivAt (fun u ↦ Real.exp (c * u)) + (Real.exp (c * u) * c) u := h_cu.exp + have h := h_exp.const_mul (B / c) + rw [show B * Real.exp (c * u) = B / c * (Real.exp (c * u) * c) from by field_simp] + exact h + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt (fun u _ ↦ h_anti u) + (Continuous.intervalIntegrable (by fun_prop) _ _)] + simp [Real.exp_zero] + ring + +/-! ## Compound Poisson MGF (folded from `CompoundPoisson.lean`) + +For `N ~ Poisson(λ)` with iid claim sizes `X_i` of MGF `M_X`, the compound +Poisson aggregate `S = ∑_{i=1}^N X_i` has MGF `exp(λ · (M_X(t) − 1))`. +The algebraic core is `e^{−λ} · e^{λ M} = e^{λ(M − 1)}`. The Lundberg +adjustment coefficient solves `λ · (M(R) − 1) − c · R = 0`. -/ + +/-- **Compound Poisson MGF algebraic core**: `e^{−λ} · e^{λ M} = e^{λ(M − 1)}`. -/ +theorem compoundPoisson_mgf_identity (lam M : ℝ) : + Real.exp (-lam) * Real.exp (lam * M) = Real.exp (lam * (M - 1)) := by + rw [← Real.exp_add] + congr 1; ring + +/-- **Lundberg adjustment-coefficient equation**: `λ · (M(R) − 1) − c · R = 0`. -/ +def IsLundbergAdjustmentCoefficient (lam c R : ℝ) (M : ℝ → ℝ) : Prop := + lam * (M R - 1) - c * R = 0 + +/-- **Trivial root at zero**: `R = 0` always satisfies the adjustment equation +when `M 0 = 1` (which holds for any MGF). -/ +theorem lundberg_zero_at_zero (lam c : ℝ) (M : ℝ → ℝ) (hM0 : M 0 = 1) : + IsLundbergAdjustmentCoefficient lam c 0 M := by + unfold IsLundbergAdjustmentCoefficient + rw [hM0] + ring + +end MathFin diff --git a/LeanPool/MathFin/Insurance/StandardDeviationPrinciple.lean b/LeanPool/MathFin/Insurance/StandardDeviationPrinciple.lean new file mode 100644 index 0000000000..8c8f130e7b --- /dev/null +++ b/LeanPool/MathFin/Insurance/StandardDeviationPrinciple.lean @@ -0,0 +1,186 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Insurance.ActuarialInsurance +public import LeanPool.MathFin.Probability.Analysis.FiniteMeasureCauchySchwarz +public import LeanPool.MathFin.Risk.GaussianExpectedShortfall +public import LeanPool.MathFin.Risk.GaussianValueAtRisk + +/-! +# The standard-deviation principle: everything but monotonicity + +The **standard-deviation principle** prices a loss `X` with finite variance by +`ρ(X) = E[X] + k·sd(X)` for a loading `k ≥ 0` (`stdDevPrinciple`). It is the premium principle +`stdDevPremium` of `Insurance/ActuarialInsurance.lean` evaluated at the mean and standard deviation +of `X`, so a nonnegative loading prices at or above the mean (`integral_le_stdDevPrinciple`). It +satisfies three of the four coherence axioms of `Risk/ExpectedShortfall.lean`, and fails +the fourth (QRM Exercise Book, Exercises 2.19 and 8.11). + +* **Translation invariance** (`stdDevPrinciple_add_const`): shifting by cash shifts the mean and + leaves the standard deviation alone. The standard deviation alone is *not* translation + invariant (`sqrt_variance_add_const`), which is why the mean term is there. +* **Positive homogeneity** (`stdDevPrinciple_const_mul`). +* **Subadditivity** (`stdDevPrinciple_add_le`): the standard deviation is subadditive because + covariance obeys the Cauchy–Schwarz inequality `cov(X, Y) ≤ sd(X) sd(Y)` + (`covariance_le_sqrt_mul_sqrt`, in `Probability/Analysis/FiniteMeasureCauchySchwarz.lean`). +* **Monotonicity fails** (`stdDevPrinciple_not_monotone`): a loss `B ≤ 0` that equals `−1` with a + small probability `q` and `0` otherwise has `ρ(B) > 0 = ρ(0)` once `q(1 + k²) < k²`. Its rare + gains inflate the standard deviation more than they lower the mean. This is the counterexample + of QRM Exercise 8.11. + +On Gaussian losses the two standard risk measures are standard-deviation principles. For +`X ~ N(m, v)` and `α ∈ (0, 1)`, `VaR_α(X)` is the principle with loading `Φ⁻¹(α)` +(`stdDevPrinciple_eq_valueAtRisk_of_hasLaw_gaussianReal`), and for `v ≠ 0` `ES_α(X)` is the +principle with loading `ϕ(Φ⁻¹(α))/(1 − α)`, where `ϕ` is the standard normal density +(`stdDevPrinciple_eq_expectedShortfall_of_hasLaw_gaussianReal`). Both follow from the Gaussian +closed forms `valueAtRisk_of_hasLaw_gaussianReal` and `expectedShortfall_of_hasLaw_gaussianReal`, +with the mean and variance of the law. + +## Main definitions + +* `stdDevPrinciple`: the standard-deviation principle `ρ(X) = E[X] + k·sd(X)` with loading `k`. + +## Main results + +* `stdDevPrinciple_add_const`, `stdDevPrinciple_const_mul`, `stdDevPrinciple_add_le`. +* `stdDevPrinciple_not_monotone`: the principle is not monotone: for a loading `k ≥ 0`, a loss + `B ≤ 0` valued in `{−1, 0}` with `P{B = −1} = q`, `q (1 + k²) < k²`, has `ρ(0) < ρ(B)`. +* `integral_le_stdDevPrinciple`: a nonnegative loading prices at or above the mean. +* `stdDevPrinciple_eq_valueAtRisk_of_hasLaw_gaussianReal`, + `stdDevPrinciple_eq_expectedShortfall_of_hasLaw_gaussianReal`: on Gaussian losses VaR and ES are + standard-deviation principles, with loadings `Φ⁻¹(α)` and `ϕ(Φ⁻¹(α))/(1 − α)` (for ES, positive + variance). + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Examples 2.11 and 2.14 +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 8.11; Ex. 8.11, 2.19 + +## Tags + +standard deviation principle, premium principle, mean plus standard deviation, monotonicity failure, +coherence axioms, safety loading, MSC 91G70, MSC 91G05, JEL G22, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set +open scoped NNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + {X Y : Ω → ℝ} + +/-- The standard deviation is unchanged by a cash shift, so it is not translation invariant on +its own: `sd(X + m) = sd(X)`. -/ +lemma sqrt_variance_add_const (hX : AEStronglyMeasurable X P) (m : ℝ) : + √Var[fun ω ↦ X ω + m; P] = √Var[X; P] := by + rw [variance_add_const hX] + +/-- The **standard-deviation principle** with loading `k`: `ρ(X) = E[X] + k·sd(X)`, the premium +principle `stdDevPremium` at the mean and standard deviation of `X`. -/ +noncomputable def stdDevPrinciple (k : ℝ) (X : Ω → ℝ) (P : Measure Ω) : ℝ := + stdDevPremium k P[X] √Var[X; P] + +omit [IsProbabilityMeasure P] in +/-- **A nonnegative loading prices at or above the mean**: `E[X] ≤ E[X] + k·sd(X)` for `k ≥ 0`. +This is `stdDevPremium_ge_mean` at the mean and standard deviation of `X`. -/ +theorem integral_le_stdDevPrinciple {k : ℝ} (hk : 0 ≤ k) : P[X] ≤ stdDevPrinciple k X P := + stdDevPremium_ge_mean _ hk (Real.sqrt_nonneg _) + +/-- **Translation invariance**: `ρ(X + m) = ρ(X) + m`. -/ +theorem stdDevPrinciple_add_const (k : ℝ) (hX : MemLp X 2 P) (m : ℝ) : + stdDevPrinciple k (fun ω ↦ X ω + m) P = stdDevPrinciple k X P + m := by + unfold stdDevPrinciple stdDevPremium + rw [integral_add (hX.integrable one_le_two) (integrable_const m), integral_const, + sqrt_variance_add_const hX.aestronglyMeasurable] + simp only [probReal_univ, one_smul] + ring + +omit [IsProbabilityMeasure P] in +/-- **Positive homogeneity**: `ρ(cX) = c ρ(X)` for `c ≥ 0`. -/ +theorem stdDevPrinciple_const_mul (k : ℝ) (X : Ω → ℝ) {c : ℝ} (hc : 0 ≤ c) : + stdDevPrinciple k (fun ω ↦ c * X ω) P = c * stdDevPrinciple k X P := by + unfold stdDevPrinciple stdDevPremium + rw [integral_const_mul, variance_const_mul, Real.sqrt_mul (sq_nonneg c), Real.sqrt_sq hc] + ring + +/-- **Subadditivity**: `ρ(X + Y) ≤ ρ(X) + ρ(Y)` for a nonnegative loading. -/ +theorem stdDevPrinciple_add_le {k : ℝ} (hk : 0 ≤ k) (hX : MemLp X 2 P) (hY : MemLp Y 2 P) : + stdDevPrinciple k (fun ω ↦ X ω + Y ω) P ≤ stdDevPrinciple k X P + stdDevPrinciple k Y P := by + unfold stdDevPrinciple stdDevPremium + rw [integral_add (hX.integrable one_le_two) (hY.integrable one_le_two)] + nlinarith [mul_le_mul_of_nonneg_left (sqrt_variance_add_le hX hY) hk] + +/-- **The standard-deviation principle is not monotone** (QRM Exercise 8.11). Let `B ≤ 0` take +the value `−1` with probability `q > 0` and `0` otherwise. If `q (1 + k²) < k²` then +`ρ(B) > 0 = ρ(0)`, although `B ≤ 0` pointwise. -/ +theorem stdDevPrinciple_not_monotone {k : ℝ} (hk : 0 ≤ k) {B : Ω → ℝ} (hBm : Measurable B) + (hB : ∀ ω, B ω = -1 ∨ B ω = 0) {q : ℝ} (hq : P.real {ω | B ω = -1} = q) (hq0 : 0 < q) + (hqk : q * (1 + k ^ 2) < k ^ 2) : + (∀ ω, B ω ≤ 0) ∧ stdDevPrinciple k (fun _ ↦ (0 : ℝ)) P < stdDevPrinciple k B P := by + set A := {ω | B ω = -1} + have hA : MeasurableSet A := hBm (measurableSet_singleton (-1)) + have hBeq : B = fun ω ↦ -A.indicator 1 ω := by + ext ω + rcases hB ω with h | h + · simp [A, h] + · simp [A, h] + have hB2 : MemLp B 2 P := + hBeq ▸ (memLp_indicator_const 2 hA.nullMeasurableSet 1 (Or.inr (measure_ne_top _ _))).neg + have hmean : P[B] = -q := by + rw [hBeq, integral_neg, integral_indicator_one hA, hq] + have hsq : P[B ^ 2] = q := by + have : B ^ 2 = A.indicator 1 := by + ext ω + rcases hB ω with h | h + · simp [A, h] + · simp [A, h] + rw [this, integral_indicator_one hA, hq] + have hvar : Var[B; P] = q * (1 - q) := by + rw [variance_eq_sub hB2, hsq, hmean] + ring + have hq1 : q < 1 := by nlinarith + refine ⟨fun ω ↦ (hB ω).elim (fun h ↦ h ▸ by norm_num) (fun h ↦ h.le), ?_⟩ + unfold stdDevPrinciple stdDevPremium + rw [hmean, hvar] + have h0 : Var[fun _ ↦ (0 : ℝ); P] = 0 := by simpa using variance_const_mul 0 B P + simp only [integral_const, smul_zero, h0, Real.sqrt_zero, mul_zero, add_zero] + -- `q < k √(q(1 − q))` because `q² < k² q (1 − q)` + have hpos : 0 < q * (1 - q) := mul_pos hq0 (by linarith) + have hlt : q < k * √(q * (1 - q)) := by + have hx : (k * √(q * (1 - q))) ^ 2 = k ^ 2 * (q * (1 - q)) := by + rw [mul_pow, Real.sq_sqrt hpos.le] + exact lt_of_pow_lt_pow_left₀ 2 (by positivity) (by rw [hx]; nlinarith) + linarith + +/-! ### Gaussian losses -/ + +omit [IsProbabilityMeasure P] in +/-- **On a Gaussian loss VaR is a standard-deviation principle**: for `X ~ N(m, v)` and +`α ∈ (0, 1)`, `E[X] + Φ⁻¹(α)·sd(X) = m + √v Φ⁻¹(α) = VaR_α(X)`. -/ +theorem stdDevPrinciple_eq_valueAtRisk_of_hasLaw_gaussianReal {m : ℝ} {v : ℝ≥0} + (hX : HasLaw X (gaussianReal m v) P) {α : ℝ} (hα : α ∈ Ioo 0 1) : + stdDevPrinciple (PhiInv α) X P = valueAtRisk X P α := by + rw [valueAtRisk_of_hasLaw_gaussianReal hX hα, gaussianVaR, stdDevPrinciple, stdDevPremium, + hX.integral_eq, integral_id_gaussianReal, hX.variance_eq, variance_id_gaussianReal, mul_comm] + +/-- **On a Gaussian loss ES is a standard-deviation principle**: for `X ~ N(m, v)` with `v ≠ 0` +and `α ∈ (0, 1)`, `E[X] + (ϕ(Φ⁻¹(α))/(1 − α))·sd(X) = ES_α(X)`, where `ϕ` is the standard normal +density. -/ +theorem stdDevPrinciple_eq_expectedShortfall_of_hasLaw_gaussianReal {m : ℝ} {v : ℝ≥0} + (hv : v ≠ 0) (hX : HasLaw X (gaussianReal m v) P) {α : ℝ} (hα : α ∈ Ioo 0 1) : + stdDevPrinciple (gaussianPDFReal 0 1 (PhiInv α) / (1 - α)) X P = expectedShortfall X P α := by + rw [expectedShortfall_of_hasLaw_gaussianReal hv hX hα, gaussianCVaR, stdDevPrinciple, + stdDevPremium, hX.integral_eq, integral_id_gaussianReal, hX.variance_eq, + variance_id_gaussianReal, mul_comm] + +end MathFin diff --git a/LeanPool/MathFin/Insurance/SurvivalModel.lean b/LeanPool/MathFin/Insurance/SurvivalModel.lean new file mode 100644 index 0000000000..ed94a9c243 --- /dev/null +++ b/LeanPool/MathFin/Insurance/SurvivalModel.lean @@ -0,0 +1,158 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ + +/- +The definitions and proofs here are our own, following this library's conventions: Mathlib's +`MeasureTheory`/`ProbabilityTheory`, a concrete complementary-CDF survival function, and the +conditional measure `cond`. Yosuke Ito's Isabelle/HOL AFP entry "Actuarial Mathematics" +(https://isa-afp.org/entries/Actuarial_Mathematics.html, BSD License) — in particular its +`Survival_Model` theory — was consulted as a source for the classical result set, and is cited +here with thanks and with the author's kind permission. +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.Normed.Order.Lattice +public import Mathlib.MeasureTheory.Constructions.BorelSpace.Order +public import Mathlib.Probability.ConditionalProbability + +/-! +# The survival model: age-at-death random variable and conditional survival + +The probabilistic foundation of life-contingent actuarial mathematics. A life is described by a +random variable `X : Ω → ℝ`, its **age at death**, on a probability space `(Ω, P)`, with `X > 0` +almost surely. Everything else is derived from the **survival function** (complementary CDF) +`S_X(t) = P(X > t)`. + +The design is ours (see the file header); the classical statements were cross-checked against +Yosuke Ito's AFP `Survival_Model`, cited as a source. + +The future lifetime of a life aged `x` is `T(x) = X − x`, defined on the event `alive x = {X > x}` +that the life reaches age `x`. Its survival function is the conditional probability +`tpₓ = P(X > x + t ∣ X > x)`, which for `t ≥ 0` collapses to the survival ratio +`tpₓ = S_X(x + t) / S_X(x)` — the keystone of the theory. + +## Correspondence with the AFP source (cross-reference only) + +For readers coming from the AFP entry, our declarations line up with its `Survival_Model` names: +`alive`↔`alive`, `futureLifetime`↔`futr_life`, `survivalFunction`↔`ccdf (distr 𝔐 borel X)`, +`survive`↔`survive` (`$p_{t&x}`), `die`↔`die` (`$q_{t&x}`), `survivalFunction_zero`↔`ccdfX_0_1`, +`survive_zero`↔`ccdfTx_0_1`, `survive_eq_survivalFunction_ratio`↔`ccdfTx_ccdfX`. + +## Main definitions + +* `alive`: the event `{X > x}` that a life with age at death `X` reaches age `x`. +* `futureLifetime`: the future lifetime `T(x) = X − x` of a life aged `x`. +* `survivalFunction`: the survival function `S_X(t) = P(X > t)`. +* `survive`: the probability `tpₓ = P(X > x + t ∣ X > x)` that a life aged `x` survives `t` more + years. +* `die`: the probability `tqₓ = 1 − tpₓ` that a life aged `x` dies within `t` years. + +## Main results + +* `survivalFunction_zero` — `S_X(0) = 1` (`X > 0` a.e.). +* `survivalFunction_antitone`, `survivalFunction_le_one` — the survival function decreases in + `[0, 1]`. +* `survive_zero` — `₀pₓ = 1` for a life alive at `x`. +* `survive_eq_survivalFunction_ratio` — `tpₓ = S_X(x+t) / S_X(x)` for `t ≥ 0`, the survival-ratio + keystone: the conditional-probability definition of `survive` collapses to the ratio. + +## References + +* [Y. Ito, *AFP Actuarial Mathematics*][ItoAFPActuarial] + +## Tags + +age at death, future lifetime, survival function, life table, conditional survival, life-contingent, +MSC 91G05, MSC 62P05, JEL G22 +-/ + +@[expose] public section + +namespace MathFin.SurvivalModel + +open MeasureTheory ProbabilityTheory + +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {X : Ω → ℝ} + +/-- `alive x` — the event that a life reaches age `x`, i.e. `{ω | x < X ω}`. AFP: `alive`. -/ +def alive (X : Ω → ℝ) (x : ℝ) : Set Ω := {ω | x < X ω} + +/-- The future lifetime `T(x) = X − x` of a life aged `x`. AFP: `futr_life` (`T`). -/ +def futureLifetime (X : Ω → ℝ) (x : ℝ) : Ω → ℝ := fun ω ↦ X ω - x + +/-- The **survival function** `S_X(t) = P(X > t)` — the complementary CDF of the age at death. +AFP: `ccdf (distr 𝔐 borel X)`. -/ +noncomputable def survivalFunction (P : Measure Ω) (X : Ω → ℝ) (t : ℝ) : ℝ := + (P (alive X t)).toReal + +/-- `tpₓ` — the probability `P(X > x + t ∣ X > x)` that a life aged `x` survives a further `t` +years. AFP: `survive` — the ccdf of the future lifetime `T(x)` under the measure conditioned on +`alive x`. -/ +noncomputable def survive (P : Measure Ω) (X : Ω → ℝ) (t x : ℝ) : ℝ := + ((P[|alive X x]) (alive X (x + t))).toReal + +/-- `tqₓ = 1 − tpₓ` — the probability that a life aged `x` dies within `t` years. AFP: `die`. -/ +noncomputable def die (P : Measure Ω) (X : Ω → ℝ) (t x : ℝ) : ℝ := + 1 - survive P X t x + +lemma measurableSet_alive (hX : Measurable X) (x : ℝ) : MeasurableSet (alive X x) := + measurableSet_lt measurable_const hX + +omit [MeasurableSpace Ω] in +/-- `alive x` shrinks as `x` grows: reaching a later age is a sub-event. -/ +lemma alive_subset_alive {x y : ℝ} (hxy : x ≤ y) : alive X y ⊆ alive X x := + fun _ hω ↦ lt_of_le_of_lt hxy hω + +/-- `S_X(0) = 1`: everyone is alive at age `0`, since `X > 0` almost surely. AFP: `ccdfX_0_1`. -/ +lemma survivalFunction_zero [IsProbabilityMeasure P] (hpos : ∀ᵐ ω ∂P, 0 < X ω) : + survivalFunction P X 0 = 1 := by + have hcompl : P (alive X 0)ᶜ = 0 := measure_mono_null (fun _ hω ↦ hω) (ae_iff.mp hpos) + have h1 : P (alive X 0) = 1 := by + rw [← measure_univ (μ := P)] + exact measure_congr (ae_eq_univ.mpr hcompl) + rw [survivalFunction, h1, ENNReal.toReal_one] + +/-- The survival function is bounded by `1`. -/ +lemma survivalFunction_le_one [IsProbabilityMeasure P] (t : ℝ) : + survivalFunction P X t ≤ 1 := by + rw [survivalFunction, ← ENNReal.toReal_one] + exact ENNReal.toReal_mono ENNReal.one_ne_top prob_le_one + +/-- The survival function is nonnegative. -/ +lemma survivalFunction_nonneg (t : ℝ) : 0 ≤ survivalFunction P X t := + ENNReal.toReal_nonneg + +/-- The survival function is nonincreasing in age. -/ +lemma survivalFunction_antitone [IsProbabilityMeasure P] : Antitone (survivalFunction P X) := by + intro x y hxy + exact ENNReal.toReal_mono (measure_ne_top P _) (measure_mono (alive_subset_alive hxy)) + +/-- `₀pₓ = 1`: a life alive at age `x` survives `0` further years with certainty. AFP: `ccdfTx_0_1`. +-/ +lemma survive_zero [IsProbabilityMeasure P] (hX : Measurable X) (x : ℝ) + (hx : P (alive X x) ≠ 0) : survive P X 0 x = 1 := by + rw [survive, add_zero, cond_apply (measurableSet_alive hX x), Set.inter_self, + ENNReal.inv_mul_cancel hx (measure_ne_top P _), ENNReal.toReal_one] + +/-- **The survival ratio** `tpₓ = S_X(x+t) / S_X(x)` for `t ≥ 0` — the survival-ratio keystone (AFP: +`ccdfTx_ccdfX`). Conditioning on survival to age `x`, a further `t` years of survival has +probability the ratio of the two unconditional survival probabilities. -/ +lemma survive_eq_survivalFunction_ratio (hX : Measurable X) (x : ℝ) + {t : ℝ} (ht : 0 ≤ t) : + survive P X t x = survivalFunction P X (x + t) / survivalFunction P X x := by + have hsub : alive X (x + t) ⊆ alive X x := alive_subset_alive (le_add_of_nonneg_right ht) + rw [survive, survivalFunction, survivalFunction, cond_apply (measurableSet_alive hX x), + Set.inter_eq_self_of_subset_right hsub, ENNReal.toReal_mul, ENNReal.toReal_inv] + ring + +/-- `tpₓ + tqₓ = 1` — the survival/death dichotomy. -/ +lemma survive_add_die (t x : ℝ) : survive P X t x + die P X t x = 1 := by + rw [die]; ring + +end MathFin.SurvivalModel diff --git a/LeanPool/MathFin/Insurance/SurvivalUnification.lean b/LeanPool/MathFin/Insurance/SurvivalUnification.lean new file mode 100644 index 0000000000..ed18e43363 --- /dev/null +++ b/LeanPool/MathFin/Insurance/SurvivalUnification.lean @@ -0,0 +1,158 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Insurance.Mortality +public import LeanPool.MathFin.Insurance.SurvivalModel +public import LeanPool.MathFin.Models.Credit.DefaultDensity + +/-! +# Actuarial survival ≡ reduced-form credit survival + +The actuarial survival function built from a force of mortality `μ` (`survivalFromForce`, +`Insurance/Mortality.lean`) and the reduced-form credit survival curve built from a hazard rate `h` +(`hazardSurvival`, `Models/Credit/HazardCurve.lean`) are both *defined* as +`survivalFromIntensity = exp(−∫₀ᵗ ·)` (`Probability/Analysis/ExponentialDiscount.lean`), so +`survivalFromForce_eq_hazardSurvival` is `rfl`: it records that the two names denote one function, +not a theorem about either. + +The probabilistic content is the link to a random lifetime. The survival model of +`Insurance/SurvivalModel.lean` starts from an age-at-death random variable `X` and its survival +function `S_X(t) = P(X > t)`. Take for `X` a random time `τ` whose law has the hazard `h`, in the +form the credit layer uses: `P(τ ≤ a) = 1 − exp(−∫₀ᵃ h)` for `a ≥ 0` (the hypothesis of +`DefaultDensity.map_eq_withDensity`), with `h` continuous and nonnegative. Then + +* `survivalFunction_eq_hazardSurvival`: `S_τ(t) = hazardSurvival h t` for `t ≥ 0`; +* `survive_eq_exp_neg_integral`: `ₜpₓ = P(τ > x + t ∣ τ > x) = exp(−∫ₓ^{x+t} h)` for `x, t ≥ 0`; +* `hasDerivAt_survivalFunction`: `S_τ' = −h · S_τ` on `t > 0`, so `h` is the force of mortality + `−S_τ'/S_τ` of the lifetime; +* `survive_coxDefaultTime`: the hypotheses hold for the Cox default time of `Models/Credit/Cox.lean` + (a unit-exponential clock inverted through `∫₀ᵗ h`, for `h` continuous and positive with + `∫₀ᵗ h → ∞`), so they are satisfiable. + +The single exponential holds for a deterministic intensity only. With a stochastic intensity `Λ` +the survival probability is the mixture `E[exp(−Λ_t)]` (`Cox.cox_mixing_survival`), which is not +`exp(−E[Λ_t])` in general; that case is not covered here. + +## Main results + +* `survivalFromForce_eq_hazardSurvival`: `survivalFromForce μ t = hazardSurvival μ t`, by `rfl`; + the two names denote one function. +* `gompertz_cumHazard`: for `c ≠ 0`, the cumulative hazard of `u ↦ B * exp (c * u)` is + `(B/c) * (exp (c * t) - 1)`. +* `survivalFunction_eq_hazardSurvival`: if a measurable lifetime `τ` has + `P(τ ≤ a) = 1 - hazardSurvival h a` for `a ≥ 0` with `h ≥ 0`, its actuarial survival function + equals `hazardSurvival h` for `t ≥ 0`. +* `survive_eq_exp_neg_integral`: under those hypotheses and `h` continuous, `ₜpₓ` of `τ` is + `exp (-∫ s in x..x + t, h s)` for `x, t ≥ 0`. +* `hasDerivAt_survivalFunction`: under the same hypotheses, the survival function has derivative + `-(h t * survivalFunction P τ t)` at `t > 0`. +* `survive_coxDefaultTime`: for `h` continuous and positive with cumulative hazard tending to + `∞`, and `ξ` unit exponential, the Cox default time has `ₜpₓ = exp (-∫ s in x..x + t, h s)`. + +## References + +* [D. C. M. Dickson, M. R. Hardy and H. R. Waters, *Actuarial Mathematics for Life Contingent + Risks*][DicksonHardyWaters2013], §§2.3–2.4 + +## Tags + +force of mortality, hazard rate, survival function, reduced-form credit, Cox default time, +life table, MSC 91G40, MSC 91G05, JEL G22 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Filter Topology + +/-- **The two survival curves are one definition.** The actuarial `survivalFromForce` and the +credit `hazardSurvival` both unfold to `survivalFromIntensity`, so this is `rfl`: it identifies two +names, and it says nothing about a random lifetime (see `survivalFunction_eq_hazardSurvival`). -/ +theorem survivalFromForce_eq_hazardSurvival (μ : ℝ → ℝ) (t : ℝ) : + survivalFromForce μ t = hazardSurvival μ t := rfl + +/-- **Gompertz law as a credit hazard curve.** A Gompertz-shaped intensity +`h(u) = B · e^{c u}` has cumulative hazard `(B/c) · (e^{c t} − 1)` — the actuarial +Gompertz cumulative force, reused as a reduced-form credit term structure. -/ +theorem gompertz_cumHazard (B c t : ℝ) (hc : c ≠ 0) : + cumHazard (fun u ↦ B * Real.exp (c * u)) t = (B / c) * (Real.exp (c * t) - 1) := by + unfold cumHazard + exact gompertz_cumulative_force B c t hc + +/-! ### A lifetime with a hazard rate -/ + +section Lifetime + +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P] + {h : ℝ → ℝ} {τ : Ω → ℝ} + +/-- **The actuarial survival function of a lifetime with hazard `h` is the credit survival +curve**: if `P(τ ≤ a) = 1 − exp(−∫₀ᵃ h)` for `a ≥ 0`, with `h ≥ 0`, then +`S_τ(t) = P(τ > t) = hazardSurvival h t` for `t ≥ 0`. -/ +theorem survivalFunction_eq_hazardSurvival (hnn : ∀ s, 0 ≤ h s) (hτ : Measurable τ) + (hcdf : ∀ a, 0 ≤ a → P {ω | τ ω ≤ a} = 1 - ENNReal.ofReal (hazardSurvival h a)) {t : ℝ} + (ht : 0 ≤ t) : SurvivalModel.survivalFunction P τ t = hazardSurvival h t := by + have hQ : hazardSurvival h t ≤ 1 := by + change Real.exp (-∫ u in (0 : ℝ)..t, h u) ≤ 1 + exact Real.exp_le_one_iff.2 (neg_nonpos.2 (intervalIntegral.integral_nonneg ht fun s _ ↦ hnn s)) + have hcompl : SurvivalModel.alive τ t = {ω | τ ω ≤ t}ᶜ := by + ext ω + simp [SurvivalModel.alive] + rw [SurvivalModel.survivalFunction, hcompl, + measure_compl (measurableSet_le hτ measurable_const) (measure_ne_top _ _), measure_univ, + hcdf t ht, ENNReal.sub_sub_cancel ENNReal.one_ne_top (ENNReal.ofReal_le_one.2 hQ), + ENNReal.toReal_ofReal (hazardSurvival_pos h t).le] + +/-- **The actuarial `ₜpₓ` of a lifetime with hazard `h`**: under the hypotheses of +`survivalFunction_eq_hazardSurvival` with `h` continuous, a life aged `x ≥ 0` survives a further +`t ≥ 0` years with probability `ₜpₓ = exp(−∫ₓ^{x+t} h)`. -/ +theorem survive_eq_exp_neg_integral (hh : Continuous h) (hnn : ∀ s, 0 ≤ h s) (hτ : Measurable τ) + (hcdf : ∀ a, 0 ≤ a → P {ω | τ ω ≤ a} = 1 - ENNReal.ofReal (hazardSurvival h a)) {x t : ℝ} + (hx : 0 ≤ x) (ht : 0 ≤ t) : + SurvivalModel.survive P τ t x = Real.exp (-∫ s in x..x + t, h s) := by + rw [SurvivalModel.survive_eq_survivalFunction_ratio hτ x ht, + survivalFunction_eq_hazardSurvival hnn hτ hcdf (add_nonneg hx ht), + survivalFunction_eq_hazardSurvival hnn hτ hcdf hx] + simp only [hazardSurvival, survivalFromIntensity, cumulativeIntensity] + rw [← Real.exp_sub] + congr 1 + rw [← intervalIntegral.integral_interval_sub_left (hh.intervalIntegrable 0 (x + t)) + (hh.intervalIntegrable 0 x)] + ring + +/-- **The hazard is the force of mortality of the lifetime**: under the hypotheses of +`survivalFunction_eq_hazardSurvival` with `h` continuous, `S_τ' = −h · S_τ` at every `t > 0`, +that is `h(t) = −S_τ'(t) / S_τ(t)`. -/ +theorem hasDerivAt_survivalFunction (hh : Continuous h) (hnn : ∀ s, 0 ≤ h s) (hτ : Measurable τ) + (hcdf : ∀ a, 0 ≤ a → P {ω | τ ω ≤ a} = 1 - ENNReal.ofReal (hazardSurvival h a)) {t : ℝ} + (ht : 0 < t) : + HasDerivAt (SurvivalModel.survivalFunction P τ) + (-(h t * SurvivalModel.survivalFunction P τ t)) t := by + have hev : SurvivalModel.survivalFunction P τ =ᶠ[𝓝 t] hazardSurvival h := + eventually_of_mem (Ioi_mem_nhds ht) fun s hs ↦ + survivalFunction_eq_hazardSurvival hnn hτ hcdf (le_of_lt hs) + rw [survivalFunction_eq_hazardSurvival hnn hτ hcdf ht.le] + exact (DefaultDensity.hasDerivAt_hazardSurvival hh.locallyIntegrable + hh.continuousAt).congr_of_eventuallyEq hev + +/-- **The Cox default time is a lifetime with hazard `h`**: for `h` continuous and positive with +`∫₀ᵗ h → ∞`, and `τ` the unit-exponential clock `ξ` inverted through `∫₀ᵗ h` +(`Cox.coxDefaultTime`), `ₜpₓ = exp(−∫ₓ^{x+t} h)` for `x, t ≥ 0`. -/ +theorem survive_coxDefaultTime (hh : Continuous h) (hpos : ∀ s, 0 < h s) + (hdiv : Tendsto (cumHazard h) atTop atTop) {ξ : Ω → ℝ} (hξmeas : Measurable ξ) + (hξlaw : P.map ξ = expMeasure 1) {x t : ℝ} (hx : 0 ≤ x) (ht : 0 ≤ t) : + SurvivalModel.survive P (Cox.coxDefaultTime h ξ) t x = Real.exp (-∫ s in x..x + t, h s) := + survive_eq_exp_neg_integral hh (fun s ↦ (hpos s).le) + (Cox.measurable_coxDefaultTime hh hpos hξmeas) + (fun _ ha ↦ Cox.cox_cdf_timeVarying hh hpos hdiv hξmeas hξlaw ha) hx ht + +end Lifetime + +end MathFin diff --git a/LeanPool/MathFin/Markets/DeFi/Aave.lean b/LeanPool/MathFin/Markets/DeFi/Aave.lean new file mode 100644 index 0000000000..860babaabc --- /dev/null +++ b/LeanPool/MathFin/Markets/DeFi/Aave.lean @@ -0,0 +1,263 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.PeriodicCompounding +public import Mathlib.Algebra.Order.Star.Real + +/-! +# Aave v2: kinked interest-rate model, health factor, liquidity index + +Adapted from the Aave v2 whitepaper (Aave, "Aave Protocol V2", 2020, +), +§5 ("Formal Definitions"), which states the kinked borrow-rate model and the +health factor; the liquidity-index recurrence is §3.1 ("aTokens"). + +## Main definitions + +* `kinkedRate`: the piecewise-linear Aave v2 borrow rate in the utilization `U`, with optimal + utilization `Uopt` and slopes `slope1`, `slope2`. +* `healthFactorV1`: the single-asset health factor + `collateral * liquidationThreshold / (borrows + fees)`. +* `healthFactorV2`: the multi-asset health factor summed over `i ∈ s`. +* `liquidityIndexStep`: the per-period growth factor `R * U * ΔT / Tyear + 1` of the liquidity + index. +* `stableRateUpdate`: the stable-rate weighted average after a new stable-rate borrow. + +## Main results + +* `kinkedRate_apply_optimal`: the rate at the kink is `R₀ + slope1`, for + `Uopt ≠ 0` (the value of the `U ≤ Uopt` branch). +* `kinkedRate_eq_affine_add_hinge`: for `Uopt ≠ 0` the kinked curve is an affine rate plus + `(slope2/(1 − Uopt) − slope1/Uopt) · max (U − Uopt) 0`, a call payoff on utilization struck + at the kink; hence `continuous_kinkedRate`, the curve is continuous (at the kink included). +* `kinkedRate_monotone`: the curve is monotone nondecreasing on `[0, 1]` + when `0 < Uopt < 1` and both slopes are nonnegative. +* `healthFactorV1`, `healthFactorV2`: the single-asset and multi-asset + (summed) health-factor definitions; `healthFactorV1_lt_one_iff`, the liquidation criterion + `Hf < 1 ↔ collateral · LT < debt` (whitepaper §5: below `1` the loan "can be liquidated"). + The probability of `Hf < 1` at a horizon, for lognormal collateral, is + `prob_healthFactorV1_lt_one_eq_kmvPD` in + `MathFin/Markets/DeFi/LiquidationAsStructuralDefault.lean`. +* `liquidityIndexStep`, `liquidityIndex_eq_prod_mul`: the linear recurrence + `LI_t = (R_t·U_t·ΔT/T_year + 1)·LI_{t-1}` + and its closed-form (product) solution, matching the whitepaper's + `LiquidityRate_t = BorrowRate_t·U_t` exactly (`R` here stands for + `BorrowRate`). **Scope disclosure**: the deployed + `DefaultReserveInterestRateStrategy` contract additionally multiplies by + `(1 − reserveFactor)`, a refinement not in the whitepaper and not modeled + here (equivalently, the `reserveFactor = 0` simplification relative to the + on-chain contract). +* `liquidityIndex_eq_pow_mul`, `tendsto_liquidityIndexStep_pow`: at a constant borrow rate and + utilization the index grows by a power of one step factor, and splitting a horizon into `n` + equal update intervals, that power tends to `1 / zcb (R·U) 0 (T/Tyear)` — continuous + compounding at the liquidity rate, the library's zero-coupon bond + (`Models/Rates/PeriodicCompounding.lean`). Time-varying rates are not covered by the limit. +* `stableRateUpdate`, `stableRateUpdate_mem_interval`: the weighted-average new + stable rate, shown to lie in `[SRprev, SRnew]` when the new borrower's rate is + at least the pool's prior average, the prior stable debt is nonnegative and + the new borrow is positive. + +## Tags + +Aave protocol, lending pool, borrow rate, utilization, health factor, liquidation, liquidity index, +MSC 91G80, JEL G23 +-/ + +@[expose] public section + +namespace MathFin + +open Filter Topology + +namespace DeFi + +namespace Aave + +/-- **Aave v2 kinked borrow-rate model** (whitepaper §5, Formal Definitions): below the optimal +utilization `U_opt`, the rate rises linearly from `R₀` with slope `slope1/U_opt`; +above it, it rises linearly from `R₀ + slope1` with slope `slope2/(1-U_opt)`. +`U_opt ∈ (0,1)` is the kink location. -/ +noncomputable def kinkedRate (R₀ slope1 slope2 Uopt U : ℝ) : ℝ := + if U ≤ Uopt then R₀ + U / Uopt * slope1 + else R₀ + slope1 + (U - Uopt) / (1 - Uopt) * slope2 + +/-- **The rate at the kink** is `R₀ + slope1` — the value the `U ≤ Uopt` +branch takes at `U = Uopt`. That the `else` branch approaches the same value is +`continuous_kinkedRate`. -/ +theorem kinkedRate_apply_optimal (R₀ slope1 slope2 Uopt : ℝ) (hU : Uopt ≠ 0) : + kinkedRate R₀ slope1 slope2 Uopt Uopt = R₀ + slope1 := by + unfold kinkedRate + rw [ite_eq_left le_rfl, div_self hU, one_mul] + +/-- **The kinked rate is an affine rate plus a call on utilization.** For `Uopt ≠ 0`, + + `kinkedRate R₀ slope1 slope2 Uopt U = R₀ + (slope1/Uopt)·U + c · max (U − Uopt) 0`, + +with `c = slope2/(1−Uopt) − slope1/Uopt` the jump in slope at the kink. Below the kink only the +affine part is active; above it the hinge `max (U − Uopt) 0`, the payoff of a call on +utilization struck at `Uopt`, adds the jump. -/ +theorem kinkedRate_eq_affine_add_hinge (R₀ slope1 slope2 : ℝ) {Uopt : ℝ} (hU : Uopt ≠ 0) + (U : ℝ) : + kinkedRate R₀ slope1 slope2 Uopt U + = R₀ + slope1 / Uopt * U + (slope2 / (1 - Uopt) - slope1 / Uopt) * max (U - Uopt) 0 := by + unfold kinkedRate + split_ifs with h + · rw [max_eq_right (sub_nonpos.mpr h)] + ring + · rw [max_eq_left (sub_nonneg.mpr (not_le.mp h).le)] + linear_combination -div_mul_cancel₀ slope1 hU + +/-- **The kinked rate is continuous** for `Uopt ≠ 0`, at the kink included: by +`kinkedRate_eq_affine_add_hinge` it is an affine function plus a multiple of +`max (U − Uopt) 0`. -/ +theorem continuous_kinkedRate (R₀ slope1 slope2 : ℝ) {Uopt : ℝ} (hU : Uopt ≠ 0) : + Continuous (kinkedRate R₀ slope1 slope2 Uopt) := by + rw [funext (kinkedRate_eq_affine_add_hinge R₀ slope1 slope2 hU)] + fun_prop + +/-- **Monotonicity on `[0,1]`**: if `0 < Uopt < 1` and both slopes are +nonnegative, the kinked rate is monotone nondecreasing in utilization `U`. -/ +theorem kinkedRate_monotone {R₀ slope1 slope2 Uopt : ℝ} + (hUopt0 : 0 < Uopt) (hUopt1 : Uopt < 1) + (hs1 : 0 ≤ slope1) (hs2 : 0 ≤ slope2) : + MonotoneOn (kinkedRate R₀ slope1 slope2 Uopt) (Set.Icc 0 1) := by + intro U hU V hV hUV + simp only [Set.mem_Icc] at hU hV + unfold kinkedRate + have h1mUopt : 0 < 1 - Uopt := by linarith + by_cases hUle : U ≤ Uopt <;> by_cases hVle : V ≤ Uopt + · rw [ite_eq_left hUle, ite_eq_left hVle] + gcongr + · rw [ite_eq_left hUle, ite_eq_right hVle] + have h1 : U / Uopt * slope1 ≤ slope1 := + mul_le_of_le_one_left hs1 ((div_le_one hUopt0).mpr hUle) + have h2 : 0 ≤ (V - Uopt) / (1 - Uopt) * slope2 := + mul_nonneg (div_nonneg (by linarith [not_le.mp hVle]) h1mUopt.le) hs2 + linarith + · exact absurd ((not_le.mp hUle).trans_le (hUV.trans hVle)) (lt_irrefl _) + · rw [ite_eq_right hUle, ite_eq_right hVle] + have : (U - Uopt) / (1 - Uopt) ≤ (V - Uopt) / (1 - Uopt) := + (div_le_div_iff_of_pos_right h1mUopt).mpr (by linarith) + nlinarith [mul_le_mul_of_nonneg_right this hs2] + +/-- **Aave v1/v2 single-asset health factor**: collateral weighted by its +liquidation threshold, over total debt (borrows plus accrued fees). Values +`> 1` indicate a safe position. -/ +noncomputable def healthFactorV1 (collateral liquidationThreshold borrows fees : ℝ) : ℝ := + collateral * liquidationThreshold / (borrows + fees) + +/-- **Health factor safety criterion**: `1 < Hf ↔ debt < collateral·LT`, when +total debt is positive. -/ +theorem one_lt_healthFactorV1_iff + {collateral liquidationThreshold borrows fees : ℝ} (hdebt : 0 < borrows + fees) : + 1 < healthFactorV1 collateral liquidationThreshold borrows fees ↔ + borrows + fees < collateral * liquidationThreshold := by + unfold healthFactorV1 + rw [lt_div_iff₀ hdebt, one_mul] + +/-- **Liquidation criterion**: `Hf < 1 ↔ collateral·LT < debt`, when total debt is positive. +The Aave v2 whitepaper (§5, Formal Definitions) calls a loan with `Hf < 1` undercollateralised +and liquidatable. -/ +theorem healthFactorV1_lt_one_iff + {collateral liquidationThreshold borrows fees : ℝ} (hdebt : 0 < borrows + fees) : + healthFactorV1 collateral liquidationThreshold borrows fees < 1 ↔ + collateral * liquidationThreshold < borrows + fees := by + rw [healthFactorV1, div_lt_one hdebt] + +/-- **Aave v2 multi-asset health factor**: summed over the borrower's +assets `i ∈ s`, collateral weighted by each asset's liquidation threshold +over total borrows across assets. -/ +noncomputable def healthFactorV2 {ι : Type*} (s : Finset ι) + (collateral liquidationThreshold borrows : ι → ℝ) : ℝ := + (∑ i ∈ s, collateral i * liquidationThreshold i) / ∑ i ∈ s, borrows i + +/-- **Multi-asset health factor safety criterion**, the `healthFactorV2` +analogue of `one_lt_healthFactorV1_iff`. -/ +theorem one_lt_healthFactorV2_iff {ι : Type*} {s : Finset ι} + {collateral liquidationThreshold borrows : ι → ℝ} + (hdebt : 0 < ∑ i ∈ s, borrows i) : + 1 < healthFactorV2 s collateral liquidationThreshold borrows ↔ + ∑ i ∈ s, borrows i < ∑ i ∈ s, collateral i * liquidationThreshold i := by + unfold healthFactorV2 + rw [lt_div_iff₀ hdebt, one_mul] + +/-- **Aave v2 liquidity-index recurrence** (whitepaper §3.1, aTokens): the +index accrues each period by the per-period yield `R · U · ΔT / T_year`, +where `R` stands for the borrow rate, matching the whitepaper's +`LiquidityRate_t = BorrowRate_t·U_t` exactly. **Scope disclosure**: the +deployed `DefaultReserveInterestRateStrategy` contract additionally +multiplies by `(1 − reserveFactor)`, a refinement not in the whitepaper and +not modeled here. -/ +noncomputable def liquidityIndexStep (R U ΔT Tyear : ℝ) : ℝ := + R * U * ΔT / Tyear + 1 + +/-- **Closed form of the liquidity-index recurrence**: given a sequence +`LI` satisfying `LI (n+1) = liquidityIndexStep (R (n+1)) (U (n+1)) ΔT Tyear * LI n` +for every step, the index after `n` steps equals the initial index times the +product of all per-step growth factors. Proved by induction on `n`. -/ +theorem liquidityIndex_eq_prod_mul + (LI R U : ℕ → ℝ) (ΔT Tyear : ℝ) + (hrec : ∀ n, LI (n + 1) = liquidityIndexStep (R (n + 1)) (U (n + 1)) ΔT Tyear * LI n) : + ∀ n, LI n = (∏ t ∈ Finset.range n, liquidityIndexStep (R (t + 1)) (U (t + 1)) ΔT Tyear) * LI 0 + | 0 => by simp + | (n + 1) => by + rw [hrec n, liquidityIndex_eq_prod_mul LI R U ΔT Tyear hrec n, + Finset.prod_range_succ] + ring + +/-- **Constant rates: the index grows by a power of one step factor.** If the borrow rate `R` +and utilization `U` do not change, `liquidityIndex_eq_prod_mul` collapses to +`LI n = liquidityIndexStep R U ΔT Tyear ^ n · LI 0`. -/ +theorem liquidityIndex_eq_pow_mul (LI : ℕ → ℝ) (R U ΔT Tyear : ℝ) + (hrec : ∀ n, LI (n + 1) = liquidityIndexStep R U ΔT Tyear * LI n) (n : ℕ) : + LI n = liquidityIndexStep R U ΔT Tyear ^ n * LI 0 := by + simpa using liquidityIndex_eq_prod_mul LI (fun _ ↦ R) (fun _ ↦ U) ΔT Tyear hrec n + +/-- **Frequent updates converge to continuous compounding at the liquidity rate.** At a constant +borrow rate `R` and utilization `U`, splitting a horizon `T` into `n` equal update intervals +`T / n` gives the index growth `liquidityIndexStep R U (T / n) Tyear ^ n`, which tends to +`1 / zcb (R·U) 0 (T / Tyear) = exp (R·U·T/Tyear)` as `n → ∞`. Each step accrues linear +interest; the limit is the zero-coupon bond's continuous compounding. -/ +theorem tendsto_liquidityIndexStep_pow (R U T Tyear : ℝ) : + Tendsto (fun n : ℕ ↦ liquidityIndexStep R U (T / n) Tyear ^ n) atTop + (𝓝 (zcb (R * U) 0 (T / Tyear))⁻¹) := by + have h (n : ℕ) : liquidityIndexStep R U (T / n) Tyear = 1 + R * U * (T / Tyear) / n := by + unfold liquidityIndexStep + ring + simpa only [h] using tendsto_one_add_div_pow_inv_zcb (R * U) (T / Tyear) + +/-- **Aave v2 stable-rate weighted average** (whitepaper §3.4): when a new +stable-rate borrow of size `SBnew` at rate `SRnew` joins an existing stable +debt pool `SDprev` at average rate `SRprev`, the new pool average is the +debt-weighted mean of the two rates. -/ +noncomputable def stableRateUpdate (SRprev SDprev SRnew SBnew : ℝ) : ℝ := + (SRprev * SDprev + SRnew * SBnew) / (SDprev + SBnew) + +/-- **The updated stable rate lies between** the previous average and the new +borrower's rate **when the new borrower's rate is at least the prior average** +(`hle : SRprev ≤ SRnew`), the prior stable debt is nonnegative and the new borrow +is positive. It is a weighted average with nonnegative weights and positive total +weight, so it cannot exceed (resp. fall below) the larger (resp. smaller) of the +two inputs. -/ +theorem stableRateUpdate_mem_interval + {SRprev SDprev SRnew SBnew : ℝ} + (hSDprev : 0 ≤ SDprev) (hSBnew : 0 < SBnew) (hle : SRprev ≤ SRnew) : + SRprev ≤ stableRateUpdate SRprev SDprev SRnew SBnew ∧ + stableRateUpdate SRprev SDprev SRnew SBnew ≤ SRnew := by + unfold stableRateUpdate + have hden : 0 < SDprev + SBnew := by linarith + constructor + · rw [le_div_iff₀ hden]; nlinarith + · rw [div_le_iff₀ hden]; nlinarith + +end Aave + +end DeFi + +end MathFin diff --git a/LeanPool/MathFin/Markets/DeFi/Compound.lean b/LeanPool/MathFin/Markets/DeFi/Compound.lean new file mode 100644 index 0000000000..a66c406a41 --- /dev/null +++ b/LeanPool/MathFin/Markets/DeFi/Compound.lean @@ -0,0 +1,149 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.PeriodicCompounding + +/-! +# Compound: utilization, affine borrow rate, cToken exchange-rate monotonicity + +Adapted from the Compound whitepaper (R. Leshner and G. Hayes, "Compound: The Money +Market Protocol", v1.0, February 2019): §2.3 Interest Rate Model (utilization, +affine borrow rate), §3.1 cToken Contracts (exchange rate) and §3.2.1 Market Dynamics +(interest-rate index, reserve-factor accrual). + +## Main definitions + +* `utilization`: `borrows / (cash + borrows)`. +* `borrowRate`: the affine rate `base + slope * U`. +* `exchangeRate`: the cToken rate `(cash + borrows - reserves) / totalSupply`. + +## Main results + +* `utilization_mem_Icc`: for nonnegative cash and borrows, `U ∈ [0, 1]`. +* `borrowRate`, `borrowRate_monotone`: the affine rate `r = base + slope · U`, + monotone in `U` when `slope ≥ 0`. +* `exchangeRate_mono`: over one accrual period, with cash and a positive total + supply unchanged, the exchange rate does not decrease, **under the explicit + hypothesis that the reserve-factor cut does not exceed the accrued + interest** (`reservesAdded ≤ interest`) — the whitepaper's reserve-factor + accrual equations give this (`reservesAdded = interest · reserveFactor` with + `reserveFactor ∈ [0,1]` and `interest ≥ 0`), but it is stated as a standalone + hypothesis on the accrued amounts rather than re-derived from `reserveFactor`. +* `borrowIndex_eq_mul_pow`, `borrowIndex_le_inv_zcb`, `tendsto_borrowIndex`: the interest-rate + index of §3.2.1, `Index_n = Index_{n−1} · (1 + r·t)` at a per-block rate `r` over periods of + length `t`, against the library's zero-coupon bond (`Models/Rates/PeriodicCompounding.lean`): + at a constant rate it is `Index_0 · (1 + r t)^n`, never above continuous compounding + `Index_0 / zcb r 0 (n t)`, and accruing a horizon `T` in `n` equal periods converges to + `Index_0 / zcb r 0 T`. Rates that change between periods are not covered. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], §4.2 +* [R. Leshner and G. Hayes, *Compound: The Money Market Protocol*][LeshnerHayes2019], §3.2.1 + +## Tags + +Compound protocol, money market, utilization rate, cToken, exchange rate, borrow index, lending, +MSC 91G80, JEL G23 +-/ + +@[expose] public section + +namespace MathFin + +open Filter Topology + +namespace DeFi + +namespace Compound + +/-- **Compound utilization rate**: the fraction of the pool's assets +(cash + outstanding borrows) that is currently borrowed out, per the +whitepaper's §2.3 definition. (The deployed interest-rate-model contract +additionally nets reserves out of the denominator; that refinement is not +formalized here.) -/ +noncomputable def utilization (cash borrows : ℝ) : ℝ := + borrows / (cash + borrows) + +/-- For nonnegative cash and borrows the utilization lies in `[0, 1]` (it is `0` for an +empty pool, by the `x / 0 = 0` convention). -/ +theorem utilization_mem_Icc {cash borrows : ℝ} (hcash : 0 ≤ cash) (hborrows : 0 ≤ borrows) : + utilization cash borrows ∈ Set.Icc 0 1 := + ⟨div_nonneg hborrows (add_nonneg hcash hborrows), + div_le_one_of_le₀ (by linarith) (add_nonneg hcash hborrows)⟩ + +/-- **Compound affine borrow-rate model**: `r(U) = base + slope · U`. Takes +`U` directly (rather than `cash`/`borrows`) so it applies uniformly whether +`U` comes from `utilization` or from the on-chain reserves-netted refinement +noted on `utilization`. -/ +def borrowRate (base slope U : ℝ) : ℝ := + base + slope * U + +/-- **Borrow rate is monotone nondecreasing in utilization** when the +slope is nonnegative. -/ +theorem borrowRate_monotone {base slope : ℝ} (hslope : 0 ≤ slope) : + Monotone (borrowRate base slope) := by + intro U V hUV + unfold borrowRate + gcongr + +/-- **Compound cToken exchange rate**: the redeemable-underlying-per-cToken +rate `(Cash + Borrows − Reserves) / TotalSupply`. -/ +noncomputable def exchangeRate (cash borrows reserves totalSupply : ℝ) : ℝ := + (cash + borrows - reserves) / totalSupply + +/-- **cToken exchange-rate monotonicity under interest accrual.** +Suppose a period accrues `interest` of new borrows, of which +`reservesAdded` is cut to reserves. **Explicit hypothesis** +`reservesAdded ≤ interest` — the whitepaper's reserve-factor accrual equations give +this (`reservesAdded = interest · reserveFactor` with `reserveFactor ∈ [0,1]` and +`interest ≥ 0`), but we state it as a standalone hypothesis on the +accrued amounts rather than re-deriving it from `reserveFactor` here. Under +it, with cash and supply unchanged and `totalSupply > 0`, the exchange rate after +accrual is at least the rate before. -/ +theorem exchangeRate_mono + {cash borrows reserves totalSupply interest reservesAdded : ℝ} + (htotalSupply : 0 < totalSupply) + (hreservesAdded : reservesAdded ≤ interest) : + exchangeRate cash borrows reserves totalSupply ≤ + exchangeRate cash (borrows + interest) (reserves + reservesAdded) totalSupply := by + unfold exchangeRate + rw [div_le_div_iff_of_pos_right htotalSupply] + linarith + +/-- **Compound interest-rate index** (whitepaper §3.2.1, Market Dynamics): each transaction +compounds the index by the interest for the period, `Index_n = Index_{n−1} · (1 + r·t)`. At a +constant per-block rate `r` and period length `t`, the index is `Index_0 · (1 + r t)^n`. -/ +theorem borrowIndex_eq_mul_pow (index : ℕ → ℝ) (r t : ℝ) + (hrec : ∀ n, index (n + 1) = index n * (1 + r * t)) (n : ℕ) : + index n = index 0 * (1 + r * t) ^ n := + eq_mul_pow_of_succ hrec n + +/-- **Per-period accrual never exceeds continuous compounding at the same rate.** At a constant +rate `r` with `r t ≥ −1` and a nonnegative initial index, after `n` periods of length `t` the +index is at most `Index_0 / zcb r 0 (n t) = Index_0 · exp (r · n t)`. -/ +theorem borrowIndex_le_inv_zcb (index : ℕ → ℝ) {r t : ℝ} (h0 : 0 ≤ index 0) (hrt : -1 ≤ r * t) + (hrec : ∀ n, index (n + 1) = index n * (1 + r * t)) (n : ℕ) : + index n ≤ index 0 * (zcb r 0 (n * t))⁻¹ := by + rw [borrowIndex_eq_mul_pow index r t hrec n] + exact mul_le_mul_of_nonneg_left (one_add_mul_pow_le_inv_zcb hrt n) h0 + +/-- **Accruing ever more often converges to continuous compounding.** Splitting a horizon `T` +into `n` equal accrual periods at the constant rate `r`, the index `Index_0 · (1 + r (T/n))^n` +tends to `Index_0 / zcb r 0 T = Index_0 · exp (r T)`. -/ +theorem tendsto_borrowIndex (index₀ r T : ℝ) : + Tendsto (fun n : ℕ ↦ index₀ * (1 + r * (T / n)) ^ n) atTop + (𝓝 (index₀ * (zcb r 0 T)⁻¹)) := by + simpa only [mul_div_assoc] using (tendsto_one_add_div_pow_inv_zcb r T).const_mul index₀ + +end Compound + +end DeFi + +end MathFin diff --git a/LeanPool/MathFin/Markets/DeFi/Dai.lean b/LeanPool/MathFin/Markets/DeFi/Dai.lean new file mode 100644 index 0000000000..fb0d423a33 --- /dev/null +++ b/LeanPool/MathFin/Markets/DeFi/Dai.lean @@ -0,0 +1,102 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.PeriodicCompounding + +/-! +# Dai (MakerDAO): liquidation inequality and stability-fee compounding + +Adapted from the MakerDAO whitepaper (Maker, "The Maker Protocol: +MakerDAO's Multi-Collateral Dai (MCD) System", 2020, +): the collateralization / +liquidation criterion from the "Liquidation of Risky Maker Vaults" section, +and the "Liquidation Ratio" / "Stability Fee" parameter entries under +"Risk Parameters Controlled by Maker Governance" (these are named +parameter entries, not sub-sections of the paper). + +## Main definitions + +* `isLiquidatable`: the predicate `collateral / debt < liquidationRatio` on a vault. + +## Main results + +* `isLiquidatable_iff_mul`: cross-multiplied equivalent form (no division), for + `debt > 0`. +* `debt_eq_debt_zero_mul_pow`: the compounding recurrence + `debt (n+1) = debt n · (1 + fee)` has closed form `debt n = debt 0 · (1+fee)^n` + (the library's `eq_mul_pow_of_succ`, `Models/Rates/PeriodicCompounding.lean`). +* `debt_mul_zcb_log_eq`: per-period stability-fee compounding *is* continuous compounding at + the rate `log (1 + fee)`: discounting the debt after `n` periods by the zero-coupon bond + `zcb (log (1 + fee)) 0 n` returns the initial debt, for `fee > −1`. The Multi-Collateral Dai + `Jug` compounds its per-second rate (`duty`) over the elapsed seconds, so a period here is a + second and `log (1 + fee)` is the continuously compounded per-second rate. + +The probability that a vault with lognormal collateral is liquidatable at a horizon is in +`MathFin/Markets/DeFi/LiquidationAsStructuralDefault.lean` (`prob_isLiquidatable_eq_kmvPD`). + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], §4.2 +* [MakerDAO, *The Maker Protocol: MakerDAO's Multi-Collateral Dai (MCD) System*][MakerDAO2020] +* [MakerDAO, *MakerDAO technical documentation*][MakerDAOTechDocs], Rates Module + +## Tags + +MakerDAO, stablecoin, vault liquidation, collateralization ratio, stability fee, compounding, +MSC 91G80, JEL G23 +-/ + +@[expose] public section + +namespace MathFin + +namespace DeFi + +namespace Dai + +/-- **Dai liquidation predicate**: a vault is liquidatable once its +collateralization ratio `collateral / debt` falls below the protocol's +liquidation ratio. -/ +noncomputable def isLiquidatable (collateral debt liquidationRatio : ℝ) : Prop := + collateral / debt < liquidationRatio + +/-- **Division-free equivalent** of the liquidation predicate, valid when +debt is positive: `collateral / debt < LR ↔ collateral < LR · debt`. -/ +theorem isLiquidatable_iff_mul + {collateral debt liquidationRatio : ℝ} (hdebt : 0 < debt) : + isLiquidatable collateral debt liquidationRatio ↔ collateral < liquidationRatio * debt := by + unfold isLiquidatable + rw [div_lt_iff₀ hdebt] + +/-- **Dai stability-fee compounding**: given a vault-debt sequence +satisfying `debt (n+1) = debt n · (1 + fee)` at every step, the debt after +`n` periods equals the initial debt compounded at the per-period stability +fee, `debt n = debt 0 · (1 + fee)^n`: the closed form of a per-period accrual index, +`eq_mul_pow_of_succ`. -/ +theorem debt_eq_debt_zero_mul_pow + (debt : ℕ → ℝ) (fee : ℝ) + (hrec : ∀ n, debt (n + 1) = debt n * (1 + fee)) : + ∀ n, debt n = debt 0 * (1 + fee) ^ n := + eq_mul_pow_of_succ hrec + +/-- **Stability-fee compounding is continuous compounding at the rate `log (1 + fee)`.** If the +vault debt compounds at the per-period fee `fee > −1`, then discounting the debt after `n` +periods by the zero-coupon bond at the continuously compounded rate `log (1 + fee)` (time in +periods) returns the initial debt: `debt n · zcb (log (1 + fee)) 0 n = debt 0`. -/ +theorem debt_mul_zcb_log_eq (debt : ℕ → ℝ) {fee : ℝ} (hfee : -1 < fee) + (hrec : ∀ n, debt (n + 1) = debt n * (1 + fee)) (n : ℕ) : + debt n * zcb (Real.log (1 + fee)) 0 n = debt 0 := by + rw [debt_eq_debt_zero_mul_pow debt fee hrec n, mul_assoc, one_add_pow_mul_zcb_log hfee n, + mul_one] + +end Dai + +end DeFi + +end MathFin diff --git a/LeanPool/MathFin/Markets/DeFi/LiquidationAsStructuralDefault.lean b/LeanPool/MathFin/Markets/DeFi/LiquidationAsStructuralDefault.lean new file mode 100644 index 0000000000..0b38eab884 --- /dev/null +++ b/LeanPool/MathFin/Markets/DeFi/LiquidationAsStructuralDefault.lean @@ -0,0 +1,121 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Markets.DeFi.Aave +public import LeanPool.MathFin.Markets.DeFi.Dai +public import LeanPool.MathFin.Models.Credit.KMVMerton + +/-! +# Lending-protocol liquidation as Merton structural default + +A collateralised loan in a lending protocol is liquidatable once the collateral value falls +below a multiple of the debt: a Dai vault once `collateral / debt < LR` (`Dai.isLiquidatable`), +an Aave position once its health factor `collateral · LT / debt` drops below `1`. With the +collateral value lognormal and the debt fixed, "liquidatable at the horizon `T`" is exactly +Merton's (1974) default event `V_T < F` with default barrier `F = LR · debt`, respectively +`F = debt / LT`. Its probability is the library's KMV default probability +`kmvPD = Φ(−d₂)` (`Models/Credit/KMVMerton.lean`). + +The lognormal hypothesis is the library's `BSCallHyp Q C₀ F μ σ T Z`: `Z` is standard normal +under `Q` and the collateral value at `T` is `bsTerminal C₀ μ σ T (Z ·)`. Its rate slot `μ` is +used as the collateral's drift, so `Q` may be the physical measure (drift `μ`) or the +risk-neutral one (`μ = r`). The strike slot carries the barrier. + +## Main results + +* `bsTerminal_lt_iff`: the shortfall region `S_T(z) < K ↔ z < −d₂`, the strict mirror of + `bsTerminal_gt_K_iff`. +* `prob_bsTerminal_lt_eq_kmvPD`: `Q(S_T < K) = kmvPD S₀ K μ σ T = Φ(−d₂)`. +* `prob_isLiquidatable_eq_kmvPD`: the probability that a Dai vault is liquidatable at `T`. +* `prob_healthFactorV1_lt_one_eq_kmvPD`: the probability that an Aave single-asset health factor + is below `1` at `T`. + +## Scope + +The event is checked at the single date `T`. Protocols liquidate at the first time the threshold +is crossed, a first-passage event before `T` whose probability this file does not compute. The +debt is a fixed number at `T` (accrue it first, e.g. with +`Dai.debt_mul_zcb_log_eq`); only one collateral asset is risky. + +## References + +* [Aave, *Aave Protocol V2 whitepaper*][Aave2020], §5 +* [R. C. Merton, *On the pricing of corporate debt: the risk structure of interest + rates*][Merton1974] + +## Tags + +Merton structural model, default probability, DeFi lending, liquidation, health factor, KMV, +MSC 91G40, MSC 91G80, JEL G33 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory + +/-- **Shortfall-region identification**: `S_T(z) < K ↔ z < −d₂`, the strict mirror of +`bsTerminal_gt_K_iff`. -/ +lemma bsTerminal_lt_iff {S_0 K r σ T : ℝ} (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) + (hT : 0 < T) (z : ℝ) : + bsTerminal S_0 r σ T z < K ↔ z < -bsd2 S_0 K r σ T := by + have hb : 0 < σ * Real.sqrt T := mul_pos hσ (Real.sqrt_pos.mpr hT) + have hcore : bsTerminal S_0 r σ T z < K ↔ + (r - σ ^ 2 / 2) * T + σ * Real.sqrt T * z < Real.log (K / S_0) := by + rw [bsTerminal, mul_comm S_0, ← lt_div_iff₀ hS_0] + exact (Real.lt_log_iff_exp_lt (div_pos hK hS_0)).symm + rw [hcore, bsd2_eq hσ hT, ← neg_div, lt_div_iff₀ hb, + show Real.log (K / S_0) = -Real.log (S_0 / K) by + rw [Real.log_div hK.ne' hS_0.ne', Real.log_div hS_0.ne' hK.ne']; ring] + constructor <;> intro h <;> linarith + +/-- **The lognormal shortfall probability is the Merton–KMV default probability**: under +`BSCallHyp`, `Q(S_T < K) = kmvPD S₀ K μ σ T = Φ(−d₂)`. The strict and non-strict events have the +same probability because the standard normal law has no atoms. -/ +theorem prob_bsTerminal_lt_eq_kmvPD {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} + [IsProbabilityMeasure Q] {S_0 K μ σ T : ℝ} {Z : Ω → ℝ} (h : BSCallHyp Q S_0 K μ σ T Z) : + (Q {ω | bsTerminal S_0 μ σ T (Z ω) < K}).toReal = kmvPD S_0 K μ σ T := by + obtain ⟨hS_0, hK, hσ, hT, hZ⟩ := h + have hset : {ω | bsTerminal S_0 μ σ T (Z ω) < K} = Z ⁻¹' Set.Iio (-bsd2 S_0 K μ σ T) := by + ext ω + simp only [Set.mem_ofPred_eq, Set.mem_preimage, Set.mem_Iio] + exact bsTerminal_lt_iff hS_0 hK hσ hT (Z ω) + have : NullSingletonClass (gaussianReal (0 : ℝ) 1) := nullSingletonClass_gaussianReal one_ne_zero + rw [hset, ← Measure.map_apply_of_aemeasurable hZ.aemeasurable measurableSet_Iio, hZ.map_eq, + measure_congr (Iio_ae_eq_Iic (μ := gaussianReal 0 1)), ← Phi_def, kmvPD, + kmvDistanceToDefault_eq_bsd2 _ _ _ _ _ hS_0 hK] + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} [IsProbabilityMeasure Q] + +/-- **Probability that a Dai vault is liquidatable at the horizon.** With collateral value +`bsTerminal C₀ μ σ T (Z ·)` (lognormal, `BSCallHyp`), debt `D > 0` at `T` and liquidation ratio +`LR`, the probability that `collateral / debt < LR` at `T` is the Merton–KMV default probability +with barrier `LR · D`: `Φ(−d₂(C₀, LR·D, μ, σ, T))`. A check at `T` only, not the first passage +before `T`. -/ +theorem prob_isLiquidatable_eq_kmvPD {C_0 D LR μ σ T : ℝ} {Z : Ω → ℝ} (hD : 0 < D) + (h : BSCallHyp Q C_0 (LR * D) μ σ T Z) : + (Q {ω | DeFi.Dai.isLiquidatable (bsTerminal C_0 μ σ T (Z ω)) D LR}).toReal + = kmvPD C_0 (LR * D) μ σ T := by + simp_rw [DeFi.Dai.isLiquidatable_iff_mul hD] + exact prob_bsTerminal_lt_eq_kmvPD h + +/-- **Probability that an Aave health factor is below `1` at the horizon.** With collateral value +`bsTerminal C₀ μ σ T (Z ·)` (lognormal, `BSCallHyp`), liquidation threshold `LT > 0` and total debt +`B + F > 0` at `T`, the probability that `healthFactorV1 < 1` (the whitepaper's liquidation +criterion) is the Merton–KMV default probability with barrier `(B + F) / LT`. A check at `T` only, +not the first passage before `T`. -/ +theorem prob_healthFactorV1_lt_one_eq_kmvPD {C_0 LT B F μ σ T : ℝ} {Z : Ω → ℝ} + (hdebt : 0 < B + F) (hLT : 0 < LT) (h : BSCallHyp Q C_0 ((B + F) / LT) μ σ T Z) : + (Q {ω | DeFi.Aave.healthFactorV1 (bsTerminal C_0 μ σ T (Z ω)) LT B F < 1}).toReal + = kmvPD C_0 ((B + F) / LT) μ σ T := by + simp_rw [DeFi.Aave.healthFactorV1_lt_one_iff hdebt, ← lt_div_iff₀ hLT] + exact prob_bsTerminal_lt_eq_kmvPD h + +end MathFin diff --git a/LeanPool/MathFin/Markets/Execution/AlmgrenChriss.lean b/LeanPool/MathFin/Markets/Execution/AlmgrenChriss.lean new file mode 100644 index 0000000000..eefcf5e14d --- /dev/null +++ b/LeanPool/MathFin/Markets/Execution/AlmgrenChriss.lean @@ -0,0 +1,121 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Analysis.DerivOfDeriv +public import Mathlib.Analysis.SpecialFunctions.Trigonometric.DerivHyp +public import Mathlib.Topology.Algebra.Module.ModuleTopology + +/-! +# Almgren-Chriss optimal execution (deterministic closed form) + +Liquidating `X_0` units of an asset over horizon `T` with linear temporary +impact (coefficient `η`) and price-variance risk aversion (coefficient `λ`), +the optimal trajectory `X(t)` (remaining inventory) minimises the +deterministic cost functional + + `∫_0^T (σ² λ · X(t)² + η · X'(t)²) dt` + +subject to `X(0) = X_0` and `X(T) = 0`. The Euler-Lagrange equation reduces +to + + `X''(t) = κ² · X(t)`, `κ² := σ² λ / η`, + +a linear ODE with hyperbolic-cosine/sinh solutions. The boundary-condition- +satisfying solution is + + `X(t) = X_0 · sinh(κ · (T − t)) / sinh(κ · T)`. + +We verify the closed form satisfies: +- the initial condition `X(0) = X_0`, +- the terminal condition `X(T) = 0`, +- the EL equation `X''(t) = κ² · X(t)`. + +The full minimisation theorem (this closed form is optimal among all +admissible trajectories) is a calculus-of-variations claim that requires +function-space machinery beyond Mathlib's current pin. + +## Main definitions + +* `almgrenChrissPath`: the closed-form trajectory `X(t) = X_0 · sinh (κ (T − t)) / sinh (κ T)`. + +## Main results + +* `almgrenChrissPath_at_zero`: `X(0) = X_0`. +* `almgrenChrissPath_at_terminal`: `X(T) = 0`. +* `hasDerivAt_almgrenChrissPath`: first derivative. +* `almgrenChrissPath_satisfies_EL`: `X''(t) = κ² · X(t)`. + +Neither derivative needs `sinh(κT) ≠ 0`: under Lean's `x / 0 = 0` the degenerate +closed form is the zero path, which satisfies both. Only the initial condition +uses it. + +## References + +* [Almgren and Chriss (2000)][AlmgrenChriss2000] + +## Tags + +optimal execution, market impact, liquidation, calculus of variations, Euler–Lagrange equation, +inventory, JEL G11, MSC 91G80, MSC 49L20 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- **Almgren-Chriss optimal-execution trajectory**: +`X(t) = X_0 · sinh(κ (T − t)) / sinh(κ T)`. Liquidation rate `−X'(t)` is +slow at the start and accelerates near `T`. -/ +noncomputable def almgrenChrissPath (X_0 κ T t : ℝ) : ℝ := + X_0 * Real.sinh (κ * (T - t)) / Real.sinh (κ * T) + +/-- **Initial condition**: `X(0) = X_0`. -/ +theorem almgrenChrissPath_at_zero (X_0 κ T : ℝ) (hT : Real.sinh (κ * T) ≠ 0) : + almgrenChrissPath X_0 κ T 0 = X_0 := by + unfold almgrenChrissPath + rw [sub_zero] + field_simp + +/-- **Terminal condition**: `X(T) = 0`. -/ +theorem almgrenChrissPath_at_terminal (X_0 κ T : ℝ) : + almgrenChrissPath X_0 κ T T = 0 := by + unfold almgrenChrissPath + rw [sub_self, mul_zero, Real.sinh_zero] + simp + +/-- **First derivative**: `X'(t) = −X_0 · κ · cosh(κ (T − t)) / sinh(κ T)`. -/ +theorem hasDerivAt_almgrenChrissPath (X_0 κ T t : ℝ) : + HasDerivAt (almgrenChrissPath X_0 κ T) + (-(X_0 * κ * Real.cosh (κ * (T - t)) / Real.sinh (κ * T))) t := by + have hd : HasDerivAt (fun t : ℝ ↦ κ * (T - t)) (-κ) t := by + simpa using ((hasDerivAt_id t).const_sub T).const_mul κ + unfold almgrenChrissPath + convert (hd.sinh.const_mul X_0).div_const (Real.sinh (κ * T)) using 1; ring + +/-- The t-derivative of the first-derivative formula `−X₀ κ cosh(κ (T − t)) / sinh(κ T)` is +`κ² · X(t)`: the same `sinh(κ (T − t))` shape, multiplied by `κ²`. -/ +private lemma hasDerivAt_almgrenChrissPath_deriv_formula (X_0 κ T t : ℝ) : + HasDerivAt (fun s : ℝ ↦ -(X_0 * κ * Real.cosh (κ * (T - s)) / Real.sinh (κ * T))) + (κ ^ 2 * almgrenChrissPath X_0 κ T t) t := by + have hd : HasDerivAt (fun t : ℝ ↦ κ * (T - t)) (-κ) t := by + simpa using ((hasDerivAt_id t).const_sub T).const_mul κ + unfold almgrenChrissPath + convert ((hd.cosh.const_mul (X_0 * κ)).div_const (Real.sinh (κ * T))).neg using 1; ring + +/-- **Almgren-Chriss EL equation**: the closed-form trajectory satisfies `X''(t) = κ² · X(t)`, +the Euler-Lagrange equation of the cost functional: `hasDerivAt_almgrenChrissPath` gives `X'` +at every `t`, and the derivative of that formula is `κ² · X(t)`. -/ +theorem almgrenChrissPath_satisfies_EL (X_0 κ T t : ℝ) : + HasDerivAt (deriv (almgrenChrissPath X_0 κ T)) (κ ^ 2 * almgrenChrissPath X_0 κ T t) t := + hasDerivAt_deriv_of_eventually (.of_forall (hasDerivAt_almgrenChrissPath X_0 κ T)) + (hasDerivAt_almgrenChrissPath_deriv_formula X_0 κ T t) + +end MathFin diff --git a/LeanPool/MathFin/Markets/Microstructure/GlostenMilgrom.lean b/LeanPool/MathFin/Markets/Microstructure/GlostenMilgrom.lean new file mode 100644 index 0000000000..12397662d1 --- /dev/null +++ b/LeanPool/MathFin/Markets/Microstructure/GlostenMilgrom.lean @@ -0,0 +1,496 @@ +/- +Copyright (c) 2026 Alfredo Garcia. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Alfredo Garcia +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.MeasureTheory.Function.ConditionalExpectation.Basic + +/-! +# Glosten-Milgrom adverse-selection bid-ask spread + +Glosten and Milgrom (1985) derive the bid-ask spread from adverse selection +alone. A fraction `p` of arriving traders know a binary asset value +`V ∈ {V_L, V_H}`; the rest trade at random. A competitive market maker quotes + + `ask = E[V | buy]`, `bid = E[V | sell]`, + +updating by Bayes on the direction of the order. The spread is what is left. + +Two modelling conventions, both visible in the statements. The sell event is +`Bᶜ`: every arriving trader either buys or sells, so there is no no-trade +outcome, and `bid = E[V | Bᶜ]`. And the quotes are *posited* to be those +conditional expectations — Glosten-Milgrom's derivation of them from a +competitive market maker's zero expected profit is not formalized here. + +The four stages below are marked by section headers. The fourth is what makes +the other three a single theorem rather than three separate ones: +`cond_toReal_eq` is Bayes pushed through `.toReal`, and that is what identifies +the model's posterior `μ[H | B]` with the real function `postBuy` stage 3 +reasons about. `toReal` sends `∞ ↦ 0` and `x/0 ↦ 0`, so every conversion below +carries its `≠ ∞` side condition. + +The `ℝ≥0∞` stages state the trade probabilities *additively* — `2·P = 1 + p`, +`2·P + p = 1` — so that no step ever forms a difference in a type where +subtraction truncates. The textbook form does follow from the additive one +(`ENNReal.eq_sub_of_add_eq`, given `p ≠ ∞`); it is the *proofs*, not the +statements, that the additive form buys. + +## The hypothesis `0 < θ < 1` + +The usual statement of the result omits it. It is not a technical convenience, +and the two endpoints fail for different reasons. + +With `p < 1` a degenerate prior leaves nothing to be adversely selected: both +posteriors coincide, the spread is exactly `0`, and `ask - bid > 0` is false. + +A degenerate prior with `p = 1` is worse, in two ways both machine-checked here. +One of the two trade events becomes null, and `quote_eq_zero_of_null` shows what +`cond` then returns: not a bad price but the zero measure, whose integral is `0`. +And `spread_junk_at_corner` evaluates the closed form at `θ = 1, p = 1` — it +returns the *entire* `V_H - V_L`, the largest spread there could be, at the one +point where the true spread is `0`, because `0/0 = 0`. Nothing errors in either +case. Excluding the endpoints excludes both at once. + +The derivation demands the hypothesis independently: `two_mul_cond_buy_high` +needs `μ H ≠ 0` and `two_mul_cond_buy_low_add` needs `μ Hᶜ ≠ 0`, so their +hypotheses cannot be jointly satisfied without `0 < θ < 1`. + +A model satisfying all of them — so the theorem is not vacuous — is in +`MathFin.Markets.Microstructure.GlostenMilgromModel`. + +## Main definitions + +* `payoff`: the two-valued asset, `VL + indicator H (VH - VL)`, equal to `VH` on the high event + `H` and `VL` off it. +* `postBuy`, `postSell`: the posterior probability that the value is high after a buy, + `(1 + p) θ / (1 + p (2θ - 1))`, and after a sell, `(1 - p) θ / (1 - p (2θ - 1))`. + +## Main results + +* `two_mul_cond_buy_high`, `two_mul_cond_buy_low_add`: the trade probabilities, + derived from the trader mix. +* `payoff`, `spread_eq`: the quotes as integrals, and the payoff cancelling. +* `postBuy`, `postSell`, `post_sub_post`: the posteriors and the closed form + `4pθ(1-θ) / (1 - p²(2θ-1)²)`. +* `cond_toReal_eq`: Bayes in `ℝ` — the seam. +* `postBuy_eq`, `postSell_eq`: the model's posteriors *are* `postBuy`/`postSell`. +* `spread_pos_of_model`: `∫ V ∂μ[|buy] > ∫ V ∂μ[|sell]`, from the model's own + primitives. +* `quote_eq_zero_of_null`, `spread_junk_at_corner`: what the excluded endpoints + actually do — a quote that is not a quote, and a closed form returning the + whole value range. + +## References + +* [L. R. Glosten and P. R. Milgrom, *Bid, ask and transaction prices in a + specialist market with heterogeneously informed traders*][GlostenMilgrom1985]. + +## Tags + +Glosten–Milgrom model, bid–ask spread, adverse selection, market maker, informed trader, +market microstructure, Bayesian updating, MSC 91B26, JEL D82, JEL G14 +-/ + +@[expose] public section + +namespace MathFin.Execution + +open MeasureTheory ProbabilityTheory +open scoped ENNReal + +variable {Ω : Type*} + +/-! ## Stage 1 — the trade probabilities, derived from the trader mix -/ + +/-- **The informed half.** On the high-value event, every informed trader buys, +so the buy-and-informed mass is exactly the informed mass. -/ +theorem inter_informed (H B I : Set Ω) (hbuy : B ∩ I = H ∩ I) : + H ∩ B ∩ I = H ∩ I := by + rw [Set.inter_assoc, hbuy, ← Set.inter_assoc, Set.inter_self] + +/-- **The informed half, low value.** An informed trader facing a low value sells, +so the buy-and-informed mass on `Hᶜ` is empty. Derived from the same primitive — +no extra hypothesis. -/ +theorem inter_informed_low (H B I : Set Ω) (hbuy : B ∩ I = H ∩ I) : + Hᶜ ∩ B ∩ I = ∅ := by + rw [Set.inter_assoc, hbuy, ← Set.inter_assoc, Set.compl_inter_self, Set.empty_inter] + +variable [MeasurableSpace Ω] (μ : Measure Ω) + +/-- **The trade probability, derived.** Doubling clears the uninformed `1/2` +without ever subtracting: `2·μ(H ∩ B) = (1 + p)·θ`. -/ +theorem two_mul_inter_high_buy (H B I : Set Ω) (hI : MeasurableSet I) {θ p : ℝ≥0∞} + (hbuy : B ∩ I = H ∩ I) + (hindep : μ (H ∩ I) = p * θ) + (hH : μ H = θ) + (huninf : 2 * μ ((H ∩ B) \ I) = μ (H \ I)) : + 2 * μ (H ∩ B) = (1 + p) * θ := by + have hsplitB : μ (H ∩ B ∩ I) + μ ((H ∩ B) \ I) = μ (H ∩ B) := + measure_inter_add_sdiff (H ∩ B) hI + have hsplitH : μ (H ∩ I) + μ (H \ I) = μ H := measure_inter_add_sdiff H hI + calc 2 * μ (H ∩ B) + = 2 * μ (H ∩ B ∩ I) + 2 * μ ((H ∩ B) \ I) := by rw [← hsplitB, mul_add] + _ = 2 * μ (H ∩ I) + μ (H \ I) := by rw [inter_informed H B I hbuy, huninf] + _ = μ (H ∩ I) + (μ (H ∩ I) + μ (H \ I)) := by rw [two_mul, add_assoc] + _ = p * θ + θ := by rw [hsplitH, hindep, hH] + _ = (1 + p) * θ := by rw [add_mul, one_mul, add_comm] + +/-- **`P(buy | V_H)`, subtraction- and division-free.** The additive form +`2·P = 1 + p` is the one `ℝ≥0∞` actually likes. -/ +theorem two_mul_cond_buy_high (H B I : Set Ω) (hH' : MeasurableSet H) (hI : MeasurableSet I) + {θ p : ℝ≥0∞} (hθ0 : θ ≠ 0) (hθtop : θ ≠ ∞) + (hbuy : B ∩ I = H ∩ I) (hindep : μ (H ∩ I) = p * θ) (hH : μ H = θ) + (huninf : 2 * μ ((H ∩ B) \ I) = μ (H \ I)) : + 2 * μ[B | H] = 1 + p := by + have h2 : 2 * μ (H ∩ B) = (1 + p) * θ := + two_mul_inter_high_buy μ H B I hI hbuy hindep hH huninf + calc 2 * μ[B | H] + = 2 * (θ⁻¹ * μ (H ∩ B)) := by rw [cond_apply hH', hH] + _ = θ⁻¹ * (2 * μ (H ∩ B)) := by rw [mul_left_comm] + _ = θ⁻¹ * ((1 + p) * θ) := by rw [h2] + _ = 1 + p := by + rw [mul_comm (1 + p) θ, ← mul_assoc, ENNReal.inv_mul_cancel hθ0 hθtop, one_mul] + +/-- **`P(buy | V_L) = (1 − p)/2`, stated additively as `2·P + p = 1`** — because +`1 - p` truncates in `ℝ≥0∞` and this form does not. + +And note which hypothesis the proof demands: `μ Hᶜ ≠ 0`, i.e. `θ ≠ 1`. Together +with `θ ≠ 0` from the high-value case, **the model itself forces `0 < θ < 1`** — +exactly the hypothesis the issue is missing. It is not an extra condition imposed +on the theorem; it is what the derivation needs in order to exist. -/ +theorem two_mul_cond_buy_low_add (H B I : Set Ω) (hHc : MeasurableSet Hᶜ) + (hI : MeasurableSet I) {θ' p : ℝ≥0∞} (hθ0 : θ' ≠ 0) (hθtop : θ' ≠ ∞) + (hbuy : B ∩ I = H ∩ I) + (hindep : μ (Hᶜ ∩ I) = p * θ') + (hHc' : μ Hᶜ = θ') + (huninf : 2 * μ ((Hᶜ ∩ B) \ I) = μ (Hᶜ \ I)) : + 2 * μ[B | Hᶜ] + p = 1 := by + have hz : μ (Hᶜ ∩ B ∩ I) = 0 := by + rw [inter_informed_low H B I hbuy]; exact measure_empty + have hsplitB : μ (Hᶜ ∩ B ∩ I) + μ ((Hᶜ ∩ B) \ I) = μ (Hᶜ ∩ B) := + measure_inter_add_sdiff (Hᶜ ∩ B) hI + have hBmass : 2 * μ (Hᶜ ∩ B) = μ (Hᶜ \ I) := by + rw [← hsplitB, hz, zero_add]; exact huninf + have hsplitH : μ (Hᶜ ∩ I) + μ (Hᶜ \ I) = μ Hᶜ := measure_inter_add_sdiff Hᶜ hI + have hp : p = θ'⁻¹ * (p * θ') := by + rw [mul_comm p θ', ← mul_assoc, ENNReal.inv_mul_cancel hθ0 hθtop, one_mul] + calc 2 * μ[B | Hᶜ] + p + = 2 * (θ'⁻¹ * μ (Hᶜ ∩ B)) + p := by rw [cond_apply hHc, hHc'] + _ = θ'⁻¹ * (2 * μ (Hᶜ ∩ B)) + p := by rw [mul_left_comm] + _ = θ'⁻¹ * μ (Hᶜ \ I) + θ'⁻¹ * μ (Hᶜ ∩ I) := by rw [hBmass, hindep, ← hp] + _ = θ'⁻¹ * (μ (Hᶜ ∩ I) + μ (Hᶜ \ I)) := by rw [← mul_add, add_comm] + _ = θ'⁻¹ * θ' := by rw [hsplitH, hHc'] + _ = 1 := ENNReal.inv_mul_cancel hθ0 hθtop + + +/-! ## Stage 2 — the quotes as Bochner integrals -/ + +/-- The two-valued asset: `V_H` on the high event `H`, `V_L` off it. Written as +a constant plus an indicator, which is what makes it integrable for free. -/ +noncomputable def payoff (H : Set Ω) (VL VH : ℝ) : Ω → ℝ := + fun ω => VL + Set.indicator H (fun _ => VH - VL) ω + +/-- **The expectation of a two-valued payoff.** Against any probability measure, +`E[V] = V_L + P(H)·(V_H − V_L)`. -/ +theorem integral_payoff (ν : Measure Ω) [IsProbabilityMeasure ν] (H : Set Ω) + (hH : MeasurableSet H) (VL VH : ℝ) : + ∫ ω, payoff H VL VH ω ∂ν = VL + (ν H).toReal * (VH - VL) := by + unfold payoff + rw [integral_add (integrable_const VL) ((integrable_const (VH - VL)).indicator hH), + integral_const, integral_indicator_const _ hH] + simp [measureReal_def] + +/-- **The quote.** `E[V | E]` for a conditioning event of positive probability — +this is `ask` when `E` is a buy and `bid` when `E` is a sell. -/ +theorem integral_payoff_cond [IsFiniteMeasure μ] (E H : Set Ω) (hH : MeasurableSet H) + (hE0 : μ E ≠ 0) (VL VH : ℝ) : + ∫ ω, payoff H VL VH ω ∂(μ[|E]) = VL + (μ[H | E]).toReal * (VH - VL) := by + have : IsProbabilityMeasure (μ[|E]) := cond_isProbabilityMeasure hE0 + exact integral_payoff (μ[|E]) H hH VL VH + +/-- **The spread, reduced to the posteriors.** Every trace of the payoff cancels +except the scale `V_H − V_L`; what is left is exactly how much a buy moves the +belief relative to a sell. Adverse selection, and nothing else, sets the spread. -/ +theorem spread_eq [IsFiniteMeasure μ] (B S H : Set Ω) (hH : MeasurableSet H) + (hB0 : μ B ≠ 0) (hS0 : μ S ≠ 0) (VL VH : ℝ) : + (∫ ω, payoff H VL VH ω ∂(μ[|B])) - (∫ ω, payoff H VL VH ω ∂(μ[|S])) + = (VH - VL) * ((μ[H | B]).toReal - (μ[H | S]).toReal) := by + rw [integral_payoff_cond μ B H hH hB0 VL VH, integral_payoff_cond μ S H hH hS0 VL VH] + ring + +/-- **A null trade event does not give a bad quote — it gives no quote.** +`cond` on a null set is the *zero measure*, so the "price" integrates to `0` +whatever the asset is worth. This is what a degenerate prior can do to a quote: +at `θ = 1, p = 1` every arriving trader buys, so `Bᶜ` is null and the "bid" is +not a bad price but no price at all. `p = 1` alone is harmless and is *not* +excluded — `spread_pos_of_model` derives `p ≤ 1` rather than assuming it, and at +`p = 1` with `0 < θ < 1` both trade events still carry positive mass. It is the +prior's endpoints that have to go. -/ +theorem quote_eq_zero_of_null (H B : Set Ω) (VL VH : ℝ) (hB : μ B = 0) : + ∫ ω, payoff H VL VH ω ∂(μ[|B]) = 0 := by + rw [cond_eq_zero_of_meas_eq_zero hB]; simp + +/-! ## Stage 3 — the closed form and strict positivity, in `ℝ` -/ + +/-- Posterior that the value is high, after a buy: `θ(1+p) / (1 + p(2θ−1))`. -/ +noncomputable def postBuy (θ p : ℝ) : ℝ := (1 + p) * θ / (1 + p * (2 * θ - 1)) + +/-- Posterior that the value is high, after a sell: `θ(1−p) / (1 − p(2θ−1))`. -/ +noncomputable def postSell (θ p : ℝ) : ℝ := (1 - p) * θ / (1 - p * (2 * θ - 1)) + +/-- The buy denominator is positive. Note `1 + p(2θ−1)` is *twice* `P(buy)` +(see `hBreal` in `spread_pos_of_model`), not `P(buy)` itself. Positivity holds +because it equals `(1−p) + 2pθ`, two non-negative terms with the second strictly +positive — which is the hint `nlinarith` is given, so no case split on the sign +of `2θ−1` is needed. -/ +theorem buy_denom_pos {θ p : ℝ} (hθ0 : 0 < θ) (hp0 : 0 ≤ p) (hp1 : p ≤ 1) : + 0 < 1 + p * (2 * θ - 1) := by + rcases hp1.lt_or_eq with h | h + · nlinarith [mul_nonneg hp0 hθ0.le] + · subst h; linarith + +/-- The sell denominator is positive — likewise *twice* `P(sell)` — by the mirror +identity `1 − p(2θ−1) = (1−p) + 2p(1−θ)`. -/ +theorem sell_denom_pos {θ p : ℝ} (hθ1 : θ < 1) (hp0 : 0 ≤ p) (hp1 : p ≤ 1) : + 0 < 1 - p * (2 * θ - 1) := by + rcases hp1.lt_or_eq with h | h + · nlinarith [mul_nonneg hp0 (sub_pos.mpr hθ1).le] + · subst h; linarith + +/-- **The closed form of the spread's belief term** — the formula the issue's +`## Task` states, now derived: +`postBuy − postSell = 4pθ(1−θ) / (1 − p²(2θ−1)²)`. + +The `θ(1−θ)` in the numerator is the whole point: it is what the acceptance +criterion forgets, and it vanishes exactly at `θ ∈ {0,1}`. -/ +theorem post_sub_post {θ p : ℝ} (hθ0 : 0 < θ) (hθ1 : θ < 1) (hp0 : 0 < p) + (hp1 : p ≤ 1) : + postBuy θ p - postSell θ p + = 4 * p * θ * (1 - θ) / (1 - p ^ 2 * (2 * θ - 1) ^ 2) := by + have h1 := (buy_denom_pos hθ0 hp0.le hp1).ne' + have h2 := (sell_denom_pos hθ1 hp0.le hp1).ne' + have h3 : (1 : ℝ) - p ^ 2 * (2 * θ - 1) ^ 2 + = (1 + p * (2 * θ - 1)) * (1 - p * (2 * θ - 1)) := by ring + have hD : (1 : ℝ) - p ^ 2 * (2 * θ - 1) ^ 2 ≠ 0 := by rw [h3]; exact mul_ne_zero h1 h2 + unfold postBuy postSell + rw [div_sub_div _ _ h1 h2, div_eq_div_iff (mul_ne_zero h1 h2) hD] + ring + +/-- **A buy moves the belief strictly more than a sell does.** This is the whole +economic content: the order's direction is informative, so the two quotes cannot +coincide. -/ +theorem postSell_lt_postBuy {θ p : ℝ} (hθ0 : 0 < θ) (hθ1 : θ < 1) (hp0 : 0 < p) + (hp1 : p ≤ 1) : postSell θ p < postBuy θ p := by + have h1 := buy_denom_pos hθ0 hp0.le hp1 + have h2 := sell_denom_pos hθ1 hp0.le hp1 + have hdiff : 0 < postBuy θ p - postSell θ p := by + rw [post_sub_post hθ0 hθ1 hp0 hp1] + apply div_pos + · nlinarith [mul_pos (mul_pos hp0 hθ0) (sub_pos.mpr hθ1)] + · nlinarith + linarith + +/-- **The theorem the issue asks for**, with the hypotheses it is missing: +`ask − bid > 0` whenever `V_L < V_H`, `0 < p ≤ 1` **and `0 < θ < 1`** — where +`ask − bid = (V_H − V_L)·(postBuy − postSell)` is exactly Stage 2's `spread_eq`. -/ +theorem spread_pos {θ p VL VH : ℝ} (hθ0 : 0 < θ) (hθ1 : θ < 1) (hp0 : 0 < p) + (hp1 : p ≤ 1) (hV : VL < VH) : + 0 < (VH - VL) * (postBuy θ p - postSell θ p) := + mul_pos (sub_pos.mpr hV) (sub_pos.mpr (postSell_lt_postBuy hθ0 hθ1 hp0 hp1)) + +/-- `postSell 1 1 = 0/0`, which Lean evaluates to `0` rather than rejecting. -/ +theorem postSell_one_one : postSell 1 1 = 0 := by unfold postSell; norm_num + +/-- `postBuy 1 1 = 1`: after a buy the value is certainly high — which is true, +and is exactly why the *difference* below is the whole value range. -/ +theorem postBuy_one_one : postBuy 1 1 = 1 := by unfold postBuy; norm_num + +/-- **The punchline.** At `θ = 1, p = 1` the closed form hands back the *entire +value range* as the spread — the largest it could conceivably be — at exactly the +point where the value is common knowledge and the true spread is `0`. Nothing +errors, nothing is flagged; `0/0 = 0` does it all. A `full` entry quantified over +`p ≤ 1` and unconstrained `θ` would carry this inside it. -/ +theorem spread_junk_at_corner (VL VH : ℝ) : + (VH - VL) * (postBuy 1 1 - postSell 1 1) = VH - VL := by + rw [postSell_one_one, postBuy_one_one]; ring + +/-! ## Stage 4 — the seam -/ + +/-- **The unconditional probability of `E`, in `ℝ`.** The law of total +probability, converted once. -/ +theorem measure_toReal_of_likelihoods [IsProbabilityMeasure μ] (E H : Set Ω) (hH : MeasurableSet H) + {a c t : ℝ} (ha : (μ[E | H]).toReal = a) (hc : (μ[E | Hᶜ]).toReal = c) + (ht : (μ H).toReal = t) : + (μ E).toReal = a * t + c * (1 - t) := by + have hcompl : (μ Hᶜ).toReal = 1 - t := by + rw [← measureReal_def, probReal_compl_eq_one_sub hH, measureReal_def, ht] + have h := congrArg ENNReal.toReal (cond_add_cond_compl_eq (μ := μ) (t := E) hH) + rw [ENNReal.toReal_add + (ENNReal.mul_ne_top (measure_ne_top _ E) (measure_ne_top _ _)) + (ENNReal.mul_ne_top (measure_ne_top _ E) (measure_ne_top _ _)), + ENNReal.toReal_mul, ENNReal.toReal_mul, ha, hc, ht, hcompl] at h + exact h.symm + +/-- **THE SEAM.** Bayes' theorem, pushed through `.toReal`: the posterior on `H` +after observing `E` is the Bayes ratio of the two likelihoods against the prior. + +This is what makes the stages one argument rather than three. Stage 2 hands back +`(μ[H | E]).toReal`; Stage 3 reasons about a ratio of real numbers; this says they +are the same number. No hypothesis that the denominator is nonzero is needed — +in the degenerate case both sides are `0`, which is precisely the behaviour the +issue's statement must not be allowed to hide. -/ +theorem cond_toReal_eq [IsProbabilityMeasure μ] (E H : Set Ω) (hE : MeasurableSet E) + (hH : MeasurableSet H) + {a c t : ℝ} (ha : (μ[E | H]).toReal = a) (hc : (μ[E | Hᶜ]).toReal = c) + (ht : (μ H).toReal = t) : + (μ[H | E]).toReal = a * t / (a * t + c * (1 - t)) := by + rw [cond_eq_inv_mul_cond_mul hE hH μ, ENNReal.toReal_mul, ENNReal.toReal_mul, + ENNReal.toReal_inv, measure_toReal_of_likelihoods μ E H hH ha hc ht, ha, ht, + div_eq_inv_mul] + ring + +/-- **The complementary likelihood.** `P(Eᶜ | F) = 1 − P(E | F)`, in `ℝ`, given +that `F` is not null — the hypothesis the model already forces. -/ +theorem cond_compl_toReal [IsFiniteMeasure μ] (E F : Set Ω) (hE : MeasurableSet E) + (hF0 : μ F ≠ 0) : + (μ[Eᶜ | F]).toReal = 1 - (μ[E | F]).toReal := by + have : IsProbabilityMeasure (μ[|F]) := cond_isProbabilityMeasure hF0 + rw [← measureReal_def, probReal_compl_eq_one_sub hE, measureReal_def] + +/-- `P(buy | V_H) = (1+p)/2`, converted from Stage 1's additive form. -/ +theorem cond_buy_high_toReal (H B : Set Ω) {p : ℝ} (hp0 : 0 ≤ p) + (hhigh : 2 * μ[B | H] = 1 + ENNReal.ofReal p) : + (μ[B | H]).toReal = (1 + p) / 2 := by + have h := congrArg ENNReal.toReal hhigh + rw [ENNReal.toReal_mul, ENNReal.toReal_add ENNReal.one_ne_top ENNReal.ofReal_ne_top, + ENNReal.toReal_ofReal hp0] at h + simp only [ENNReal.toReal_ofNat, ENNReal.toReal_one] at h + linarith + +/-- `P(buy | V_L) = (1−p)/2`, converted from Stage 1's additive form. -/ +theorem cond_buy_low_toReal (H B : Set Ω) {p : ℝ} (hp0 : 0 ≤ p) + (hlow : 2 * μ[B | Hᶜ] + ENNReal.ofReal p = 1) : + (μ[B | Hᶜ]).toReal = (1 - p) / 2 := by + have h := congrArg ENNReal.toReal hlow + rw [ENNReal.toReal_add + (ENNReal.mul_ne_top (by simp) (measure_ne_top _ B)) ENNReal.ofReal_ne_top, + ENNReal.toReal_mul, ENNReal.toReal_ofReal hp0] at h + simp only [ENNReal.toReal_ofNat, ENNReal.toReal_one] at h + linarith + +/-- **The posterior after a buy is exactly `postBuy`.** Stage 3's `postBuy` was a +real function of two real numbers with no measure in sight; this is the theorem +that makes it the model's posterior. -/ +theorem postBuy_eq [IsProbabilityMeasure μ] (H B : Set Ω) (hB : MeasurableSet B) + (hH : MeasurableSet H) + {θ p : ℝ} (hp0 : 0 ≤ p) (ht : (μ H).toReal = θ) + (hhigh : 2 * μ[B | H] = 1 + ENNReal.ofReal p) + (hlow : 2 * μ[B | Hᶜ] + ENNReal.ofReal p = 1) : + (μ[H | B]).toReal = postBuy θ p := by + rw [cond_toReal_eq μ B H hB hH (cond_buy_high_toReal μ H B hp0 hhigh) + (cond_buy_low_toReal μ H B hp0 hlow) ht, postBuy, + show (1 + p) / 2 * θ + (1 - p) / 2 * (1 - θ) = (1 + p * (2 * θ - 1)) / 2 by ring, + show (1 + p) / 2 * θ = (1 + p) * θ / 2 by ring] + exact div_div_div_cancel_right₀ two_ne_zero _ _ + +/-- **The posterior after a sell is exactly `postSell`.** The sell event is +`Bᶜ` — every arriving trader either buys or sells — so the likelihoods are the +buy ones swapped, and the same seam lemma does the work. + +Only `μ Hᶜ ≠ 0` (that is, `θ ≠ 1`) is taken as a hypothesis. Its mirror +`μ H ≠ 0` is *derived*: at a degenerate prior `cond` collapses to the zero +measure, so `hhigh` would read `0 = 1 + p`. -/ +theorem postSell_eq [IsProbabilityMeasure μ] (H B : Set Ω) (hB : MeasurableSet B) + (hH : MeasurableSet H) + {θ p : ℝ} (hp0 : 0 ≤ p) (ht : (μ H).toReal = θ) (hHc0 : μ Hᶜ ≠ 0) + (hhigh : 2 * μ[B | H] = 1 + ENNReal.ofReal p) + (hlow : 2 * μ[B | Hᶜ] + ENNReal.ofReal p = 1) : + (μ[H | Bᶜ]).toReal = postSell θ p := by + have hH0 : μ H ≠ 0 := by + intro h + have hz : (0 : ℝ≥0∞) = 1 + ENNReal.ofReal p := by + rw [← hhigh, cond_eq_zero_of_meas_eq_zero h]; simp + exact absurd hz.symm (by simp) + have hsa : (μ[Bᶜ | H]).toReal = (1 - p) / 2 := by + rw [cond_compl_toReal μ B H hB hH0, cond_buy_high_toReal μ H B hp0 hhigh]; ring + have hsc : (μ[Bᶜ | Hᶜ]).toReal = (1 + p) / 2 := by + rw [cond_compl_toReal μ B Hᶜ hB hHc0, cond_buy_low_toReal μ H B hp0 hlow]; ring + rw [cond_toReal_eq μ Bᶜ H hB.compl hH hsa hsc ht, postSell, + show (1 - p) / 2 * θ + (1 + p) / 2 * (1 - θ) = (1 - p * (2 * θ - 1)) / 2 by ring, + show (1 - p) / 2 * θ = (1 - p) * θ / 2 by ring] + exact div_div_div_cancel_right₀ two_ne_zero _ _ + +/-- **Glosten–Milgrom: the spread is strictly positive.** The market maker's ask +and bid are `∫ V ∂μ[|buy]` and `∫ V ∂μ[|sell]`, and the first strictly exceeds +the second whenever `V_L < V_H`, `0 < p ≤ 1` **and `0 < θ < 1`**. + +This is the issue's `## Acceptance criteria`, with the hypothesis it omits. The +chain is: Stage 1 derives the trade probabilities from the trader mix; Stage 4 +converts them and applies Bayes to get the posteriors; Stage 2 turns the quotes +into those posteriors; Stage 3 supplies the strict inequality. -/ +theorem spread_pos_of_model [IsProbabilityMeasure μ] (H B I : Set Ω) + (hH : MeasurableSet H) (hB : MeasurableSet B) (hI : MeasurableSet I) + {θ p VL VH : ℝ} + (hθ0 : 0 < θ) (hθ1 : θ < 1) (hp0 : 0 < p) (hV : VL < VH) + (hprior : μ H = ENNReal.ofReal θ) + (hbuy : B ∩ I = H ∩ I) + (hindepH : μ (H ∩ I) = ENNReal.ofReal p * ENNReal.ofReal θ) + (hindepHc : μ (Hᶜ ∩ I) = ENNReal.ofReal p * ENNReal.ofReal (1 - θ)) + (huninfH : 2 * μ ((H ∩ B) \ I) = μ (H \ I)) + (huninfHc : 2 * μ ((Hᶜ ∩ B) \ I) = μ (Hᶜ \ I)) : + 0 < (∫ ω, payoff H VL VH ω ∂(μ[|B])) - (∫ ω, payoff H VL VH ω ∂(μ[|Bᶜ])) := by + have hθ0' : (0:ℝ) ≤ θ := hθ0.le + -- `p ≤ 1` is not a hypothesis: the informed mass cannot exceed the prior. + have hp1 : p ≤ 1 := by + have h := measure_mono (μ := μ) (Set.inter_subset_left (s := H) (t := I)) + rw [hindepH, hprior, ← ENNReal.ofReal_mul hp0.le, + ENNReal.ofReal_le_ofReal_iff hθ0'] at h + nlinarith + have hoθ0 : ENNReal.ofReal θ ≠ 0 := by rw [Ne, ENNReal.ofReal_eq_zero]; linarith + have hoθc0 : ENNReal.ofReal (1 - θ) ≠ 0 := by rw [Ne, ENNReal.ofReal_eq_zero]; linarith + have hpriorc : μ Hᶜ = ENNReal.ofReal (1 - θ) := by + rw [prob_compl_eq_one_sub hH, hprior, ENNReal.ofReal_sub 1 hθ0', ENNReal.ofReal_one] + have ht : (μ H).toReal = θ := by rw [hprior]; exact ENNReal.toReal_ofReal hθ0' + have hH0 : μ H ≠ 0 := by rw [hprior]; exact hoθ0 + have hHc0 : μ Hᶜ ≠ 0 := by rw [hpriorc]; exact hoθc0 + -- Stage 1: the trade probabilities, derived from the trader mix + have hhigh : 2 * μ[B | H] = 1 + ENNReal.ofReal p := + two_mul_cond_buy_high μ H B I hH hI hoθ0 + ENNReal.ofReal_ne_top hbuy hindepH hprior huninfH + have hlow : 2 * μ[B | Hᶜ] + ENNReal.ofReal p = 1 := + two_mul_cond_buy_low_add μ H B I hH.compl hI hoθc0 + ENNReal.ofReal_ne_top hbuy hindepHc hpriorc huninfHc + -- both trade events have positive probability, so neither conditioning is vacuous + have ha := cond_buy_high_toReal μ H B hp0.le hhigh + have hc := cond_buy_low_toReal μ H B hp0.le hlow + have hsa : (μ[Bᶜ | H]).toReal = (1 - p) / 2 := by + rw [cond_compl_toReal μ B H hB hH0, ha]; ring + have hsc : (μ[Bᶜ | Hᶜ]).toReal = (1 + p) / 2 := by + rw [cond_compl_toReal μ B Hᶜ hB hHc0, hc]; ring + have hBreal : (μ B).toReal = (1 + p * (2 * θ - 1)) / 2 := by + rw [measure_toReal_of_likelihoods μ B H hH ha hc ht]; ring + have hBcreal : (μ Bᶜ).toReal = (1 - p * (2 * θ - 1)) / 2 := by + rw [measure_toReal_of_likelihoods μ Bᶜ H hH hsa hsc ht]; ring + have hB0 : μ B ≠ 0 := by + intro h + rw [h] at hBreal + simp only [ENNReal.toReal_zero] at hBreal + linarith [buy_denom_pos hθ0 hp0.le hp1] + have hBc0 : μ Bᶜ ≠ 0 := by + intro h + rw [h] at hBcreal + simp only [ENNReal.toReal_zero] at hBcreal + linarith [sell_denom_pos hθ1 hp0.le hp1] + -- Stage 2 reduces the quotes to the posteriors; Stage 4 names them; Stage 3 closes + rw [spread_eq μ B Bᶜ H hH hB0 hBc0 VL VH, + postBuy_eq μ H B hB hH hp0.le ht hhigh hlow, + postSell_eq μ H B hB hH hp0.le ht hHc0 hhigh hlow] + exact spread_pos hθ0 hθ1 hp0 hp1 hV + +end MathFin.Execution diff --git a/LeanPool/MathFin/Markets/Microstructure/GlostenMilgromCondExp.lean b/LeanPool/MathFin/Markets/Microstructure/GlostenMilgromCondExp.lean new file mode 100644 index 0000000000..efbe341895 --- /dev/null +++ b/LeanPool/MathFin/Markets/Microstructure/GlostenMilgromCondExp.lean @@ -0,0 +1,113 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Markets.Microstructure.GlostenMilgrom +public import Mathlib.Probability.Kernel.Condexp + +/-! +# Glosten–Milgrom quotes as conditional expectations + +`MathFin.Markets.Microstructure.GlostenMilgrom` writes the market maker's quotes as integrals +against +conditioned measures: the ask is `∫ V ∂μ[|B]` on the buy event `B`, the bid `∫ V ∂μ[|Bᶜ]` on the +sell event. This file identifies the quote process with Mathlib's conditional expectation +given the σ-algebra the trade direction generates, `σ(B) = generateFrom {B}`, and reads off the +martingale property of one trade. + +## Main results + +* `generateFrom_singleton_compl`: a set and its complement generate the same σ-algebra. +* `condExp_payoff_eq_quote`: `μ[V | σ(B)]` is, `μ`-a.e., the ask on `B` and the bid on `Bᶜ`. + The two posited quotes are exactly the conditional expectation of the value given the order's + direction (Mathlib's `ProbabilityTheory.condExp_generateFrom_singleton`). +* `measureReal_mul_ask_add_measureReal_mul_bid`: `P(B) · ask + P(Bᶜ) · bid = E[V]`. The + expected transaction price equals the expected value: the one-trade martingale property, from + the tower property `integral_condExp`. +* `buyProb_mul_postBuy_add_sellProb_mul_postSell`: the same statement for the closed-form + posteriors of `GlostenMilgrom`: weighting `postBuy` and `postSell` by the probabilities of a + buy and a sell, `(1 ± p(2θ − 1))/2`, returns the prior `θ`. + +## Scope + +One trade. The quotes are posited as the conditioned integrals (as in `GlostenMilgrom`); the +zero-profit derivation of the competitive market maker, and the sequence of trades along which +Glosten–Milgrom prices form a martingale, are not formalized. + +## References + +* [L. R. Glosten and P. R. Milgrom, *Bid, ask and transaction prices in a specialist market with + heterogeneously informed traders*][GlostenMilgrom1985] + +## Tags + +Glosten–Milgrom model, market maker quotes, conditional expectation, bid–ask spread, +adverse selection, martingale, MSC 91B26, MSC 60G42, JEL D82 +-/ + +@[expose] public section + +namespace MathFin.Execution + +open MeasureTheory ProbabilityTheory MeasurableSpace + +variable {Ω : Type*} + +/-- **A set and its complement generate the same σ-algebra**: observing a sell is observing +that there was no buy. -/ +theorem generateFrom_singleton_compl (B : Set Ω) : + generateFrom {Bᶜ} = generateFrom ({B} : Set (Set Ω)) := by + refine le_antisymm (generateFrom_le fun t ht ↦ ?_) (generateFrom_le fun t ht ↦ ?_) <;> + rw [Set.mem_singleton_iff.mp ht] + · exact (measurableSet_generateFrom (Set.mem_singleton B)).compl + · simpa using (measurableSet_generateFrom (Set.mem_singleton Bᶜ)).compl + +variable [MeasurableSpace Ω] (μ : Measure Ω) + +/-- **The quote is the conditional expectation given the trade direction.** For a finite +measure, `μ[V | σ(B)]` agrees `μ`-a.e. with the quote process: the ask `∫ V ∂μ[|B]` on the buy +event and the bid `∫ V ∂μ[|Bᶜ]` on the sell event. -/ +theorem condExp_payoff_eq_quote [IsFiniteMeasure μ] {H B : Set Ω} [DecidablePred (· ∈ B)] + (hH : MeasurableSet H) (hB : MeasurableSet B) (VL VH : ℝ) : + μ[payoff H VL VH | generateFrom {B}] =ᵐ[μ] + B.piecewise (fun _ ↦ ∫ ω, payoff H VL VH ω ∂μ[|B]) + (fun _ ↦ ∫ ω, payoff H VL VH ω ∂μ[|Bᶜ]) := by + have hint : Integrable (payoff H VL VH) μ := + (integrable_const VL).add ((integrable_const (VH - VL)).indicator hH) + have hsell := condExp_generateFrom_singleton hB.compl hint + rw [generateFrom_singleton_compl] at hsell + refine ae_of_ae_restrict_of_ae_restrict_compl B ?_ ?_ + · filter_upwards [condExp_generateFrom_singleton hB hint, ae_restrict_mem hB] with ω h hω + rw [h, Set.piecewise_eq_of_mem _ _ _ hω] + · filter_upwards [hsell, ae_restrict_mem hB.compl] with ω h hω + rw [h, Set.piecewise_eq_of_notMem _ _ _ hω] + +/-- **The expected transaction price is the expected value.** For a finite measure, +`P(B) · ask + P(Bᶜ) · bid = E[V]`: averaging the quote over the trade direction returns the +unconditional mean, the tower property of `condExp_payoff_eq_quote`. -/ +theorem measureReal_mul_ask_add_measureReal_mul_bid [IsFiniteMeasure μ] {H B : Set Ω} + (hH : MeasurableSet H) (hB : MeasurableSet B) (VL VH : ℝ) : + μ.real B * ∫ ω, payoff H VL VH ω ∂μ[|B] + μ.real Bᶜ * ∫ ω, payoff H VL VH ω ∂μ[|Bᶜ] + = ∫ ω, payoff H VL VH ω ∂μ := by + classical + rw [← integral_condExp (μ := μ) (f := payoff H VL VH) (generateFrom_singleton_le hB), + integral_congr_ae (condExp_payoff_eq_quote μ hH hB VL VH), + integral_piecewise hB (integrable_const _).integrableOn (integrable_const _).integrableOn, + setIntegral_const, setIntegral_const, smul_eq_mul, smul_eq_mul] + +/-- **One-step martingale identity for beliefs, in closed form.** Weighting the posterior after a +buy and after a sell by the probabilities of a buy and of a sell, `(1 + p(2θ − 1))/2` and +`(1 − p(2θ − 1))/2` (`spread_pos_of_model` derives these), returns the prior `θ`. -/ +theorem buyProb_mul_postBuy_add_sellProb_mul_postSell {θ p : ℝ} (hb : 1 + p * (2 * θ - 1) ≠ 0) + (hs : 1 - p * (2 * θ - 1) ≠ 0) : + (1 + p * (2 * θ - 1)) / 2 * postBuy θ p + (1 - p * (2 * θ - 1)) / 2 * postSell θ p = θ := by + rw [postBuy, postSell, div_mul_div_comm, div_mul_div_comm, mul_comm (1 + p * (2 * θ - 1)), + mul_comm (1 - p * (2 * θ - 1)), mul_div_mul_right _ _ hb, mul_div_mul_right _ _ hs] + ring + +end MathFin.Execution diff --git a/LeanPool/MathFin/Markets/Microstructure/GlostenMilgromMarket.lean b/LeanPool/MathFin/Markets/Microstructure/GlostenMilgromMarket.lean new file mode 100644 index 0000000000..fbc045c553 --- /dev/null +++ b/LeanPool/MathFin/Markets/Microstructure/GlostenMilgromMarket.lean @@ -0,0 +1,64 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Markets.Microstructure.GlostenMilgromCondExp +public import LeanPool.MathFin.Pricing.DiscreteMarket + +/-! +# A quote process is priced by its own measure + +A market maker who quotes the conditional expectation of the asset's value given the public +information `𝓖 n` (the Glosten–Milgrom zero-profit quote, `condExp_payoff_eq_quote` for one trade) +posts the price process `n ↦ P[V | 𝓖 n]`. This file reads that process as a market: it is the +discrete `Market` (`toMarket`) with the unit numéraire, and the measure `P` that defines the +quotes is a pricing measure of it, since a conditional expectation process is a `P`-martingale +(Mathlib's `martingale_condExp`). + +## Main results + +* `isPricingMeasure_toMarket_condExp`: for any probability measure `P` and filtration `𝓖`, `P` + prices the market whose asset is `n ↦ P[V | 𝓖 n]`. + +## Scope + +The value `V` and the information `𝓖` are arbitrary; that the quotes of the Glosten–Milgrom +dealer along a sequence of trades are these conditional expectations is not shown here (one +trade is `condExp_payoff_eq_quote`). + +## References + +* [L. R. Glosten and P. R. Milgrom, *Bid, ask and transaction prices in a specialist market with + heterogeneously informed traders*][GlostenMilgrom1985] + +## Tags + +Glosten–Milgrom model, market maker quotes, pricing measure, Doob martingale, conditional +expectation, MSC 91B26, MSC 60G42, JEL D82 +-/ + +@[expose] public section + +open MeasureTheory + +namespace MathFin.Execution + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- **The measure that defines the quotes prices them.** For a probability measure `P`, a +filtration `𝓖` and a value `V`, `P` is a pricing measure, at every horizon `T`, of the discrete +market whose asset is the quote process `n ↦ P[V | 𝓖 n]`: a conditional expectation process is a +`P`-martingale. -/ +theorem isPricingMeasure_toMarket_condExp (P : Measure Ω) [IsProbabilityMeasure P] + (𝓖 : Filtration ℕ mΩ) (V : Ω → ℝ) (T : ℕ) : + (Contracts.DiscreteMarket.toMarket P 𝓖 (fun n ↦ P[V | 𝓖 n]) T + fun _ _ ↦ stronglyMeasurable_condExp).IsPricingMeasure T P := + Contracts.DiscreteMarket.isPricingMeasure_toMarket_of_isEMM + (.of_martingale (martingale_condExp V 𝓖 P) .rfl .rfl T) + +end MathFin.Execution diff --git a/LeanPool/MathFin/Markets/Microstructure/GlostenMilgromModel.lean b/LeanPool/MathFin/Markets/Microstructure/GlostenMilgromModel.lean new file mode 100644 index 0000000000..18d72ae008 --- /dev/null +++ b/LeanPool/MathFin/Markets/Microstructure/GlostenMilgromModel.lean @@ -0,0 +1,184 @@ +/- +Copyright (c) 2026 Alfredo Garcia. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Alfredo Garcia +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Markets.Microstructure.GlostenMilgrom +public import LeanPool.MathFin.Probability.Laws.FiniteWeights + +/-! +# A model satisfying the Glosten-Milgrom hypotheses + +`MathFin.Execution.spread_pos_of_model` quantifies over a probability space and +three events tied together by four equations. If nothing satisfies those +equations the theorem is vacuously true and says nothing — which is the same +failure mode the module it belongs to exists to warn about, one level up. + +This file removes the doubt by exhibiting the model. Six outcomes: the value is +high or low, the arriving trader is informed or not, and an uninformed trader +tosses a coin. + +| `i` | value | trader | acts | mass | +|-----|-------|------------|------|----------------| +| `0` | high | informed | buy | `θp` | +| `1` | high | uninformed | buy | `θ(1-p)/2` | +| `2` | high | uninformed | sell | `θ(1-p)/2` | +| `3` | low | informed | sell | `(1-θ)p` | +| `4` | low | uninformed | buy | `(1-θ)(1-p)/2` | +| `5` | low | uninformed | sell | `(1-θ)(1-p)/2` | + +The witness is symbolic: it works for *every* `0 < θ < 1` and `0 < p ≤ 1`, not +at one convenient point. + +## Main definitions + +* `gmWeight`: the masses of the six outcomes (value high or low, trader informed or not, and an + uninformed trader's coin). +* `gmMeasure`: the measure on `Fin 6` with those masses. +* `gmHigh`, `gmBuy`, `gmInformed`: the events that the value is high, that the trader buys, and + that the trader is informed. + +## Main results + +* `gm_buy_inter_inf`: an informed trader buys exactly when the value is high — + on this space, a set identity. +* `gmMeasure_univ_eq_one`: the six masses add to one. +* `spread_pos_witness`: the spread is strictly positive, with no + measure-theoretic hypothesis left in front of it. + +## References + +* [L. R. Glosten and P. R. Milgrom, *Bid, ask and transaction prices in a specialist market with + heterogeneously informed traders*][GlostenMilgrom1985] + +## Tags + +Glosten–Milgrom model, bid–ask spread, adverse selection, finite probability space, informed trader, +market maker, MSC 91B26, JEL D82 +-/ + +@[expose] public section + +namespace MathFin.Execution + +open MeasureTheory ProbabilityTheory +open scoped ENNReal + +/-- The six outcome masses. -/ +noncomputable def gmWeight (θ p : ℝ) : Fin 6 → ℝ := + ![θ * p, θ * (1 - p) / 2, θ * (1 - p) / 2, + (1 - θ) * p, (1 - θ) * (1 - p) / 2, (1 - θ) * (1 - p) / 2] + +/-- The model measure: the six masses on the six outcomes. -/ +noncomputable def gmMeasure (θ p : ℝ) : Measure (Fin 6) := + Measure.ofWeights Finset.univ (gmWeight θ p) + +/-- The value is high. -/ +def gmHigh : Set (Fin 6) := {0, 1, 2} +/-- The arriving trader buys. -/ +def gmBuy : Set (Fin 6) := {0, 1, 4} +/-- The arriving trader is informed. -/ +def gmInformed : Set (Fin 6) := {0, 3} + +/-- Every set's measure is the sum of the masses it contains. -/ +theorem gmMeasure_apply (θ p : ℝ) (s : Set (Fin 6)) : + gmMeasure θ p s + = ∑ i, Set.indicator s (fun j => ENNReal.ofReal (gmWeight θ p j)) i := by + have h : gmMeasure θ p + = Measure.sum fun i => ENNReal.ofReal (gmWeight θ p i) • Measure.dirac i := by + rw [gmMeasure, Measure.ofWeights, Measure.sum_fintype] + rw [h, Measure.sum_apply _ MeasurableSet.of_discrete, tsum_fintype] + refine Finset.sum_congr rfl fun i _ => ?_ + rw [smul_apply, Measure.dirac_apply' i MeasurableSet.of_discrete, smul_eq_mul] + by_cases h : i ∈ s <;> simp [h] + +/-- On the parameter range that matters, every mass is nonnegative. -/ +theorem gmWeight_nonneg {θ p : ℝ} (hθ0 : 0 ≤ θ) (hθ1 : θ ≤ 1) (hp0 : 0 ≤ p) (hp1 : p ≤ 1) : + ∀ i, 0 ≤ gmWeight θ p i := by + intro i; fin_cases i <;> simp [gmWeight] <;> nlinarith + +/-- The measure of a set, as one real number. -/ +theorem gmMeasure_eq_ofReal {θ p : ℝ} (hnn : ∀ i, 0 ≤ gmWeight θ p i) (s : Set (Fin 6)) : + gmMeasure θ p s = ENNReal.ofReal (∑ i, Set.indicator s (gmWeight θ p) i) := by + rw [gmMeasure_apply, ENNReal.ofReal_sum_of_nonneg] + · refine Finset.sum_congr rfl fun i _ => ?_ + by_cases hi : i ∈ s <;> simp [hi] + · intro i _; by_cases hi : i ∈ s <;> simp [hi, hnn i] + +/-! ## The masses of the sets the model constrains -/ + +section Values +variable {θ p : ℝ} (hnn : ∀ i, 0 ≤ gmWeight θ p i) +include hnn + +theorem gmMeasure_univ_eq_one : gmMeasure θ p Set.univ = 1 := by + rw [gmMeasure_eq_ofReal hnn, show (1 : ℝ≥0∞) = ENNReal.ofReal 1 by simp] + congr 1 + simp [gmWeight, Fin.sum_univ_six]; ring + +theorem gmMeasure_high_eq : gmMeasure θ p gmHigh = ENNReal.ofReal θ := by + rw [gmMeasure_eq_ofReal hnn]; congr 1 + simp [gmHigh, gmWeight, Fin.sum_univ_six]; ring + +theorem gmMeasure_high_compl_eq : gmMeasure θ p gmHighᶜ = ENNReal.ofReal (1 - θ) := by + rw [gmMeasure_eq_ofReal hnn]; congr 1 + simp [gmHigh, gmWeight, Fin.sum_univ_six]; ring + +theorem gmMeasure_high_inter_inf (hp0 : 0 ≤ p) : + gmMeasure θ p (gmHigh ∩ gmInformed) = ENNReal.ofReal p * ENNReal.ofReal θ := by + rw [gmMeasure_eq_ofReal hnn, ← ENNReal.ofReal_mul hp0]; congr 1 + simp [gmHigh, gmInformed, gmWeight, Fin.sum_univ_six]; ring + +theorem gmMeasure_low_inter_inf (hp0 : 0 ≤ p) : + gmMeasure θ p (gmHighᶜ ∩ gmInformed) = ENNReal.ofReal p * ENNReal.ofReal (1 - θ) := by + rw [gmMeasure_eq_ofReal hnn, ← ENNReal.ofReal_mul hp0]; congr 1 + simp [gmHigh, gmInformed, gmWeight, Fin.sum_univ_six]; ring + +theorem gmMeasure_uninformed_high : + 2 * gmMeasure θ p ((gmHigh ∩ gmBuy) \ gmInformed) = gmMeasure θ p (gmHigh \ gmInformed) := by + rw [gmMeasure_eq_ofReal hnn, gmMeasure_eq_ofReal hnn, + show (2 : ℝ≥0∞) = ENNReal.ofReal 2 by simp, ← ENNReal.ofReal_mul (by norm_num)] + congr 1 + simp [gmHigh, gmBuy, gmInformed, gmWeight, Fin.sum_univ_six]; ring + +theorem gmMeasure_uninformed_low : + 2 * gmMeasure θ p ((gmHighᶜ ∩ gmBuy) \ gmInformed) = gmMeasure θ p (gmHighᶜ \ gmInformed) := by + rw [gmMeasure_eq_ofReal hnn, gmMeasure_eq_ofReal hnn, + show (2 : ℝ≥0∞) = ENNReal.ofReal 2 by simp, ← ENNReal.ofReal_mul (by norm_num)] + congr 1 + simp [gmHigh, gmBuy, gmInformed, gmWeight, Fin.sum_univ_six]; ring + +end Values + +/-- **An informed trader buys exactly when the value is high.** The one +behavioural primitive, and on this space it is a set identity. -/ +theorem gm_buy_inter_inf : gmBuy ∩ gmInformed = gmHigh ∩ gmInformed := by + ext i; fin_cases i <;> simp [gmBuy, gmInformed, gmHigh] + +/-- The six masses add to one. -/ +theorem gmMeasure_isProbabilityMeasure {θ p : ℝ} (hnn : ∀ i, 0 ≤ gmWeight θ p i) : + IsProbabilityMeasure (gmMeasure θ p) := + ⟨gmMeasure_univ_eq_one hnn⟩ + +/-- **The model exists, so the theorem is not vacuous.** Every hypothesis of +`spread_pos_of_model` is discharged by the six-point space, for *every* +`0 < θ < 1` and `0 < p ≤ 1` — not merely at one lucky point. What is left is the +conclusion, with no measure-theoretic hypothesis in front of it: the ask strictly +exceeds the bid. -/ +theorem spread_pos_witness {θ p VL VH : ℝ} + (hθ0 : 0 < θ) (hθ1 : θ < 1) (hp0 : 0 < p) (hp1 : p ≤ 1) (hV : VL < VH) : + 0 < (∫ ω, payoff gmHigh VL VH ω ∂((gmMeasure θ p)[|gmBuy])) + - (∫ ω, payoff gmHigh VL VH ω ∂((gmMeasure θ p)[|gmBuyᶜ])) := by + have hnn := gmWeight_nonneg hθ0.le hθ1.le hp0.le hp1 + have := gmMeasure_isProbabilityMeasure hnn + exact spread_pos_of_model (gmMeasure θ p) gmHigh gmBuy gmInformed + MeasurableSet.of_discrete MeasurableSet.of_discrete MeasurableSet.of_discrete + hθ0 hθ1 hp0 hV (gmMeasure_high_eq hnn) gm_buy_inter_inf + (gmMeasure_high_inter_inf hnn hp0.le) (gmMeasure_low_inter_inf hnn hp0.le) + (gmMeasure_uninformed_high hnn) (gmMeasure_uninformed_low hnn) + +end MathFin.Execution diff --git a/LeanPool/MathFin/Markets/Microstructure/MarketMakingRiccati.lean b/LeanPool/MathFin/Markets/Microstructure/MarketMakingRiccati.lean new file mode 100644 index 0000000000..c0f4d783aa --- /dev/null +++ b/LeanPool/MathFin/Markets/Microstructure/MarketMakingRiccati.lean @@ -0,0 +1,206 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.SpecialFunctions.Trigonometric.DerivHyp +public import Mathlib.Analysis.InnerProductSpace.Basic +public import Mathlib.Analysis.SpecialFunctions.Log.Basic +public import Mathlib.Topology.Algebra.Module.ModuleTopology + +/-! +# Single-asset market making — closed-form (Riccati) approximation + +The multi-asset Avellaneda–Stoikov market-making problem of Bergault, Evangelista, Guéant +and Vieira (*Closed-form approximations in multi-asset market making*, arXiv:1810.04383) +reduces, via a quadratic (LQ) approximation of the trade-intensity Hamiltonians, to a +Riccati system whose solution is a closed-form proxy for the value function `θ(t, q)`. + +This Riccati is the LQ-**approximation** view, not the fundamental structure: for exponential +intensities the exact single-asset problem is *linearisable* by a Hopf–Cole change of variables into +a linear ODE system (Guéant–Lehalle–Fernandez-Tapia), the deeper and more faithful target (not +formalised here; the matrix-exponential derivative it needs is Mathlib's +`hasDerivAt_exp_smul_const`). We formalise the tractable approximate closed form (see +`MatrixMarketMakingRiccati` for the multi-asset analogue and the full landscape note). + +Specialised here to a **single asset** (`d = 1`), we verify, in three layers: + +* **Riccati coefficient** — `a(t) =  · tanh ( · (T − t))` solves `a' = a² − ²` with `a(T) = 0` + (the `tanh` derivative is derived locally — Mathlib carries none at this pin; the `T → ∞` ergodic + limit `a(0) → Â` is a deferred follow-up). +* **Value function** — the quadratic ansatz `θ_check(t, q) = −A(t) q² − B(t) q − C(t)` solves the + approximate Hamilton–Jacobi equation (the paper's Eq. 9) whenever `(A, B, C)` solve the + Riccati/linear ODE system, with `A` the Riccati coefficient. +* **Quotes** — with the known exponential-intensity quote map `δ_tilde_ξ(p) = p + c`, the greedy + bid/ask give a **constant** half-spread and an **inventory-linear** skew, for both the CARA + (Model A) and risk-adjusted (Model B) objectives. + +## Scope (mirroring `AlmgrenChriss.lean`) + +We verify the closed-form solution of the **approximate** (quadratic-Hamiltonian) HJ equation. Out +of scope: the stochastic optimal-control substrate (existence/uniqueness of the true value function +solving the exact HJ equation, and the verification theorem linking `θ` to optimal quotes — +controlled marked-point-process control beyond the current pin); that the approximate value function +approximates the true one (justified numerically in the paper); the exact Hopf–Cole linearisation +(the fundamental structure; Mathlib's `hasDerivAt_exp_smul_const` covers the matrix-exponential +calculus it needs, so what is missing is the construction itself); and deriving `δ_tilde_ξ` from the +intensity sup (it is defined by its known closed form from Guéant [18] / +Guéant–Lehalle–Fernandez-Tapia [20]). The multi-asset **approximate** matrix Riccati is now +discharged in `MatrixMarketMakingRiccati`. + +## Main definitions + +* `riccatiCoeff`: the scalar Riccati coefficient `a(t) =  · tanh ( · (T − t))`. +* `expIntensityQuote`: the exponential-intensity quote map `δ_tilde(p) = p + c`. +* `quoteConstA`, `quoteConstB`: the constants `c = log (1 + γ z / k) / (γ z)` (CARA objective) and + `c = 1 / k` (risk-adjusted objective). +* `mmQuoteBid`, `mmQuoteAsk`: the greedy bid and ask quotes `δ_tilde(2A(t)q + A(t)z + B(t))` and + `δ_tilde(−2A(t)q + A(t)z − B(t))`. + +## Main results + +* `hasDerivAt_tanh`: `tanh' x = 1 − tanh² x`. +* `riccatiCoeff_terminal`, `hasDerivAt_riccatiCoeff`: `a(T) = 0` and `a' = a² − ²`. +* `valueFunction_satisfies_approxHJ`: if `A`, `B`, `C` have the stated derivatives, the quadratic + ansatz `−A(s) q² − B(s) q − C(s)` has time-derivative equal to the approximate + Hamilton–Jacobi right-hand side, for `z > 0`. +* `mmHalfSpread_const`: `(δ_checkᵃ + δ_checkᵇ)/2 = A(t)·z + c`, independent of the inventory `q`. +* `mmSkew_linear`: `(δ_checkᵃ − δ_checkᵇ)/2 = −2·A(t)·q − B(t)`. + +## References + +* [Bergault et al., *Closed-form approximations in multi-asset market + making*][BergaultEtAlMarketMaking], Prop. 1; §3.3.3 +* [Guéant, Lehalle and Fernandez-Tapia][GueantLehalleFernandezTapia] + +## Tags + +Avellaneda–Stoikov, market making, Riccati equation, Hamilton–Jacobi–Bellman, optimal quotes, +inventory risk, bid-ask spread, MSC 91G80, MSC 49L20, JEL G14 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-! ## §1 Abstract scalar Riccati coefficient -/ + +/-- **Derivative of `tanh`** — `tanh'(x) = 1 − tanh² x` — derived from `tanh = sinh / cosh` and the + quotient rule (Mathlib carries no `HasDerivAt` lemma for `tanh` at this pin). -/ +theorem hasDerivAt_tanh (x : ℝ) : HasDerivAt Real.tanh (1 - Real.tanh x ^ 2) x := by + have hc : Real.cosh x ≠ 0 := (Real.cosh_pos x).ne' + have hsinh : HasDerivAt Real.sinh (Real.cosh x) x := by simpa using (hasDerivAt_id x).sinh + have hcosh : HasDerivAt Real.cosh (Real.sinh x) x := by simpa using (hasDerivAt_id x).cosh + have hfun : Real.tanh = Real.sinh / Real.cosh := by + funext y; simp [Real.tanh_eq_sinh_div_cosh] + have hval : (1 : ℝ) - Real.tanh x ^ 2 + = (Real.cosh x * Real.cosh x - Real.sinh x * Real.sinh x) / Real.cosh x ^ 2 := by + rw [Real.tanh_eq_sinh_div_cosh]; field_simp + rw [hval, hfun] + exact hsinh.div hcosh hc + +/-- **Scalar Riccati coefficient** `a(t) =  · tanh ( · (T − t))` — the closed-form solution of the + normalised Riccati equation `a' = a² − ²` with terminal value `a(T) = 0`. In the market-making + instance, ` = σ · √(γ · (α₂ᵇ + α₂ᵃ) · z)` and the value-function coefficient is + `A(t) = riccatiCoeff  T t / (2 · (α₂ᵇ + α₂ᵃ) · z)`. -/ +noncomputable def riccatiCoeff ( T t : ℝ) : ℝ :=  * Real.tanh ( * (T - t)) + +/-- **Terminal condition**: `a(T) = 0`. -/ +theorem riccatiCoeff_terminal ( T : ℝ) : riccatiCoeff  T T = 0 := by + unfold riccatiCoeff + rw [sub_self, mul_zero, Real.tanh_zero, mul_zero] + +/-- **Riccati ODE**: `a'(t) = a(t)² − ²`. -/ +theorem hasDerivAt_riccatiCoeff ( T t : ℝ) : + HasDerivAt (riccatiCoeff  T) (riccatiCoeff  T t ^ 2 -  ^ 2) t := by + unfold riccatiCoeff + have h_inner : HasDerivAt (fun s : ℝ =>  * (T - s)) (-Â) t := by + have h_id : HasDerivAt (fun s : ℝ => T - s) (-1) t := by + simpa using (hasDerivAt_id t).const_sub T + simpa using h_id.const_mul  + have h := ((hasDerivAt_tanh ( * (T - t))).comp t h_inner).const_mul  + simp only [Function.comp_def] at h + rw [show ( * Real.tanh ( * (T - t))) ^ 2 -  ^ 2 + =  * ((1 - Real.tanh ( * (T - t)) ^ 2) * -Â) by ring] + exact h + +/-! ## §2 Value-function verification of the approximate Hamilton–Jacobi equation (d = 1) -/ + +/-- **Value-function verification (Prop. 1, `d = 1`).** The quadratic ansatz + `θ_check(t, q) = −A(t) q² − B(t) q − C(t)` has time-derivative equal to the + algebraic right-hand side of the approximate Hamilton–Jacobi equation + (the paper's Eq. 9, `Q = ∞`) whenever `(A, B, C)` + solve the scalar reduction of the ODE system (Eq. 11) — `A` the Riccati coefficient + (` = σ · √(γ · (α₂ᵇ + α₂ᵃ) · z)`). The `B`/`C` ODE right-hand sides are pinned by the `ring` + closure below (self-certifying). -/ +theorem valueFunction_satisfies_approxHJ + (γ σ z α₀b α₁b α₂b α₀a α₁a α₂a : ℝ) (hz : 0 < z) + (A B C : ℝ → ℝ) (t q : ℝ) + (hA : HasDerivAt A (2 * z * (α₂b + α₂a) * A t ^ 2 - γ * σ ^ 2 / 2) t) + (hB : HasDerivAt B (2 * z * (α₁b - α₁a) * A t + 2 * z ^ 2 * (α₂b - α₂a) * A t ^ 2 + + 2 * z * (α₂b + α₂a) * A t * B t) t) + (hC : HasDerivAt C (z * (α₀b + α₀a) + z ^ 2 * (α₁b + α₁a) * A t + z * (α₁b - α₁a) * B t + + z ^ 3 * (α₂b + α₂a) * A t ^ 2 / 2 + z * (α₂b + α₂a) * B t ^ 2 / 2 + + z ^ 2 * (α₂b - α₂a) * A t * B t) t) : + HasDerivAt (fun s => -(A s) * q ^ 2 - B s * q - C s) + (γ * σ ^ 2 / 2 * q ^ 2 - z * (α₀b + α₀a) + - α₁b * (2 * A t * q * z + A t * z ^ 2 + B t * z) + - α₁a * (-2 * A t * q * z + A t * z ^ 2 - B t * z) + - (1 / (2 * z)) * (α₂b * (2 * A t * q * z + A t * z ^ 2 + B t * z) ^ 2 + + α₂a * (-2 * A t * q * z + A t * z ^ 2 - B t * z) ^ 2)) t := by + have hz' : z ≠ 0 := hz.ne' + have h2z : (2 : ℝ) * z ≠ 0 := by positivity + have hθ : HasDerivAt (fun s => -(A s) * q ^ 2 - B s * q - C s) + (-(2 * z * (α₂b + α₂a) * A t ^ 2 - γ * σ ^ 2 / 2) * q ^ 2 + - (2 * z * (α₁b - α₁a) * A t + 2 * z ^ 2 * (α₂b - α₂a) * A t ^ 2 + + 2 * z * (α₂b + α₂a) * A t * B t) * q + - (z * (α₀b + α₀a) + z ^ 2 * (α₁b + α₁a) * A t + z * (α₁b - α₁a) * B t + + z ^ 3 * (α₂b + α₂a) * A t ^ 2 / 2 + z * (α₂b + α₂a) * B t ^ 2 / 2 + + z ^ 2 * (α₂b - α₂a) * A t * B t)) t := + ((hA.neg.mul_const (q ^ 2)).sub (hB.mul_const q)).sub hC + convert hθ using 1 + field_simp + ring + +/-! ## §3 Closed-form quotes — constant spread + inventory-linear skew (Models A & B) -/ + +/-- **Exponential-intensity quote map** `δ_tilde_ξ(p) = p + c` (Guéant [18] / GLFT [20]); `c` is the +model + constant (`quoteConstA`/`quoteConstB`). Defined, not re-derived from the intensity sup. -/ +noncomputable def expIntensityQuote (c p : ℝ) : ℝ := p + c + +/-- **Model-A (CARA, `ξ = γ`) quote constant** `c = (1 / (γ z)) · log (1 + γ z / k)`. -/ +noncomputable def quoteConstA (γ z k : ℝ) : ℝ := 1 / (γ * z) * Real.log (1 + γ * z / k) + +/-- **Model-B (risk-adjusted, `ξ = 0`) quote constant** `c = 1 / k`. -/ +noncomputable def quoteConstB (k : ℝ) : ℝ := 1 / k + +/-- **Greedy bid quote** `δ_checkᵇ = δ_tilde(2 A(t) q + A(t) z + B(t))` (from `Δ⁺ / z`). -/ +noncomputable def mmQuoteBid (A B : ℝ → ℝ) (z c t q : ℝ) : ℝ := + expIntensityQuote c (2 * A t * q + A t * z + B t) + +/-- **Greedy ask quote** `δ_checkᵃ = δ_tilde(−2 A(t) q + A(t) z − B(t))` (from `Δ⁻ / z`). -/ +noncomputable def mmQuoteAsk (A B : ℝ → ℝ) (z c t q : ℝ) : ℝ := + expIntensityQuote c (-2 * A t * q + A t * z - B t) + +/-- **Constant half-spread**: `(δ_checkᵃ + δ_checkᵇ) / 2 = A(t) · z + c`, + independent of inventory `q`. This holds for both models via the constant `c` + (`quoteConstA` for Model A, `quoteConstB` for Model B). -/ +theorem mmHalfSpread_const (A B : ℝ → ℝ) (z c t q : ℝ) : + (mmQuoteAsk A B z c t q + mmQuoteBid A B z c t q) / 2 = A t * z + c := by + unfold mmQuoteAsk mmQuoteBid expIntensityQuote; ring + +/-- **Inventory-linear skew**: `(δ_checkᵃ − δ_checkᵇ) / 2 = −2 · A(t) · q − B(t)` + (the constant `c` cancels). -/ +theorem mmSkew_linear (A B : ℝ → ℝ) (z c t q : ℝ) : + (mmQuoteAsk A B z c t q - mmQuoteBid A B z c t q) / 2 = -2 * A t * q - B t := by + unfold mmQuoteAsk mmQuoteBid expIntensityQuote; ring + +end MathFin diff --git a/LeanPool/MathFin/Markets/Microstructure/MatrixMarketMakingRiccati.lean b/LeanPool/MathFin/Markets/Microstructure/MatrixMarketMakingRiccati.lean new file mode 100644 index 0000000000..716a39dc9f --- /dev/null +++ b/LeanPool/MathFin/Markets/Microstructure/MatrixMarketMakingRiccati.lean @@ -0,0 +1,277 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Markets.Microstructure.MarketMakingRiccati +public import Mathlib.Algebra.Order.Archimedean.Real.Hom +public import Mathlib.Analysis.Calculus.Deriv.Prod +public import Mathlib.Analysis.Matrix.Normed +public import Mathlib.Analysis.Matrix.Spectrum + +/-! +# Multi-asset market making — the matrix Riccati closed form + +The multi-asset Avellaneda–Stoikov market-making problem of Bergault, Evangelista, Guéant and +Vieira (*Closed-form approximations in multi-asset market making*, arXiv:1810.04383) reduces, via +a quadratic (LQ) approximation of the trade-intensity Hamiltonians, to a **matrix** Riccati +system (their Proposition 2). Its closed-form solution is the matrix analogue of the scalar +`a(t) =  · tanh ( (T − t))` verified in `MathFin.Markets.Microstructure.MarketMakingRiccati`. + +We work by **spectral reduction**: for a real symmetric (Hermitian) matrix `Â` with +eigendecomposition ` = U · diag(λ) · Uᴴ` (`U = hÂ.eigenvectorUnitary`, `λ = hÂ.eigenvalues`), we +*define* the matrix Riccati coefficient in already-diagonalised form using the scalar +`riccatiCoeff`. This is the construction behind Mathlib's functional calculus for Hermitian +matrices, `Matrix.IsHermitian.cfc`, applied to `riccatiCoeff`; it is spelled out here rather than +taken from `cfc`: + +`matrixRiccatiCoeff h T t = U · diag (fun i ↦ riccatiCoeff (λ i) T t) · Uᴴ`. + +This equals ` · tanh ( (T − t))` spectrally without ever constructing a matrix `tanh`, and the +matrix Riccati ODE `a' = a·a − ·Â` reduces, on each eigenvalue, to the scalar identity +`hasDerivAt_riccatiCoeff` already proven. + +## Where this sits (the Riccati is one, approximate, view) + +The Riccati is the **LQ-approximation** view of optimal market making, not the fundamental +structure. For exponential order-arrival intensities the single-asset Avellaneda–Stoikov HJB +equation is *exactly* linearisable — a Hopf–Cole change of variables turns it into a **linear** ODE +system (Guéant–Lehalle–Fernandez-Tapia), i.e. a matrix-exponential object with no approximation. The +exact *multi-asset* problem has no closed form, which is precisely why BEGV quadratically +approximate the Hamiltonians to recover a solvable Riccati. So this module formalises the tractable +approximate closed form (the spectral route below); the **exact linearisation is the deeper, more +faithful target** (not formalised here; the matrix-exponential derivative it needs is Mathlib's +`hasDerivAt_exp_smul_const`). Read the result as "this closed form solves this approximate Riccati", +not as "optimal market making, mechanised". + +We verify, in two layers: + +* **§1 Abstract matrix Riccati** — `matrixRiccatiCoeff` solves `a'(t) = a(t)·a(t) − ·Â` with + `a(T) = 0` (matrix-valued `HasDerivAt`, taken under the `L∞` operator norm — MathFin's committed + instance; since `n` is finite the space is finite-dimensional, all norms are equivalent, and the + derivative statement is norm-independent), for every Hermitian `Â`. This is the genuine + multi-asset matrix `tanh`-Riccati closed form (an identification with `·tanh(Â(T−t))` made in + prose under the Hermitian functional calculus — no matrix `tanh` is built here, though Mathlib's + `hÂ.cfc Real.tanh` would give one). +* **§2 Market-making instantiation** — with a positive diagonal `D₊` and a symmetric `Σ`, and `Â` + the Hermitian square root scale `· = γ • (D₊^{½} Σ D₊^{½})`, the coefficient + `A(t) = ½ • (D₊^{-½} · matrixRiccatiCoeff h T t · D₊^{-½})` solves the market-making matrix + Riccati `A'(t) = 2 • (A(t) D₊ A(t)) − (γ/2) • Σ` with `A(T) = 0` (the paper's Eq. 11 in matrix + form). + +## Scope (mirroring `MarketMakingRiccati.lean`) + +We verify the closed-form solution of the **approximate** (quadratic-Hamiltonian) matrix Riccati +system. Out of scope: the stochastic optimal-control substrate (existence/uniqueness of the true +value function and the verification theorem linking it to optimal quotes); the `B(t)`/`C(t)` closed +forms (matrix variation-of-parameters / integrals) and the general-`d` value-function verification; +that the approximate value function approximates the true one; and the construction of `Â` as a +matrix square root (in §2 `Â` enters by its defining relation `· = γ • (D₊^{½}ΣD₊^{½})`, so the +content is the change of variables, not matrix-square-root existence). + +## Main definitions + +* `matrixRiccatiCoeff`: for a Hermitian ` = U diag(λ) Uᴴ`, the matrix + `U · diag (riccatiCoeff (λᵢ) T t) · Uᴴ`. +* `mmMatrixValueCoeff`: the matrix `½ • (D₊^{-½} · a(t) · D₊^{-½})` with `D₊ = diagonal d` and + `a = matrixRiccatiCoeff`. + +## Main results + +* `matrixRiccatiCoeff_terminal`, `matrixRiccatiCoeff_isHermitian`: `a(T) = 0`, and `a(t)` is + Hermitian. +* `hasDerivAt_matrixRiccatiCoeff`: `a' = a·a − ·Â`. +* `matrixRiccatiCoeff_spectral_sq`: ` ·  = U · diag (λᵢ²) · Uᴴ`. +* `mmMatrixValueCoeff_terminal`: `A(T) = 0`. +* `hasDerivAt_mmMatrixValueCoeff`: for `d > 0`, any matrix `cov` and ` · Â` equal to + `γ • (√D₊ · cov · √D₊)`, the coefficient satisfies `A' = 2 • (A · D₊ · A) − (γ/2) • cov`. + +## References + +* [Bergault et al., *Closed-form approximations in multi-asset market + making*][BergaultEtAlMarketMaking], Proposition 2, Eq. 11 + +## Tags + +multi-asset market making, matrix Riccati equation, Avellaneda–Stoikov, spectral reduction, +Hermitian functional calculus, inventory risk, MSC 91G80, MSC 49L20, JEL G14 +-/ + +@[expose] public section + +namespace MathFin + +open Real Matrix +open scoped Matrix.Norms.Operator + +variable {n : Type*} [Fintype n] [DecidableEq n] + +/-! ## §1 Abstract matrix Riccati closed form (spectral reduction) -/ + +/-- **Matrix Riccati coefficient** `a(t) = U · diag (riccatiCoeff (λᵢ) T t) · Uᴴ`, the spectral +closed form of the normalised matrix Riccati equation `a' = a·a − ·Â` with terminal value +`a(T) = 0`. Here `U = hÂ.eigenvectorUnitary` and `λ = hÂ.eigenvalues` diagonalise the Hermitian +`Â`, and `riccatiCoeff` is the scalar `Âᵢ · tanh (Âᵢ (T − t))`. -/ +noncomputable def matrixRiccatiCoeff { : Matrix n n ℝ} (h : Â.IsHermitian) (T t : ℝ) : + Matrix n n ℝ := + (hÂ.eigenvectorUnitary : Matrix n n ℝ) * + diagonal (fun i => riccatiCoeff (hÂ.eigenvalues i) T t) * + star (hÂ.eigenvectorUnitary : Matrix n n ℝ) + +/-- **Terminal condition**: `a(T) = 0`. -/ +theorem matrixRiccatiCoeff_terminal { : Matrix n n ℝ} (h : Â.IsHermitian) (T : ℝ) : + matrixRiccatiCoeff h T T = 0 := by + unfold matrixRiccatiCoeff + simp [riccatiCoeff_terminal] + +/-- **Spectral form of `²`**: ` ·  = U · diag (λᵢ²) · Uᴴ`. The conjugation `M ↦ U · M · Uᴴ` is a +`⋆`-algebra homomorphism, so ` ·  = (U · diag λ · Uᴴ)² = U · diag λ² · Uᴴ` by `map_mul`. -/ +theorem matrixRiccatiCoeff_spectral_sq { : Matrix n n ℝ} (h : Â.IsHermitian) : +  *  = (hÂ.eigenvectorUnitary : Matrix n n ℝ) * + diagonal (fun i => (hÂ.eigenvalues i) ^ 2) * + star (hÂ.eigenvectorUnitary : Matrix n n ℝ) := by + conv_lhs => rw [hÂ.spectral_theorem] + rw [← map_mul, diagonal_mul_diagonal, Unitary.conjStarAlgAut_apply] + congr 2 + funext i + simp [Function.comp, sq] + +/-- **Symmetry**: the matrix Riccati coefficient is Hermitian (its diagonal core is real, and +conjugation by a unitary preserves Hermitian-ness) — the value function's Hessian is symmetric. -/ +theorem matrixRiccatiCoeff_isHermitian { : Matrix n n ℝ} (h : Â.IsHermitian) (T t : ℝ) : + (matrixRiccatiCoeff h T t).IsHermitian := by + unfold matrixRiccatiCoeff + rw [star_eq_conjTranspose] + exact isHermitian_mul_mul_conjTranspose _ (isHermitian_diagonal _) + +/-- **Matrix Riccati ODE**: `a'(t) = a(t)·a(t) − ·Â` (matrix-valued derivative under the `L∞` +operator norm). The `t`-dependence lives entirely in the diagonal core; its derivative is +`diag (riccatiCoeff (λᵢ)² − λᵢ²)` by the scalar `hasDerivAt_riccatiCoeff`, and conjugating by the +constant `U`, `Uᴴ` and re-collapsing (`star U · U = 1`, `map_mul`) turns +`U · diag(riccatiCoeff² − λ²) · Uᴴ` into `a·a − ·Â`. -/ +theorem hasDerivAt_matrixRiccatiCoeff { : Matrix n n ℝ} (h : Â.IsHermitian) (T t : ℝ) : + HasDerivAt (matrixRiccatiCoeff h T) + (matrixRiccatiCoeff h T t * matrixRiccatiCoeff h T t -  * Â) t := by + set U : Matrix n n ℝ := (hÂ.eigenvectorUnitary : Matrix n n ℝ) with hU + -- derivative of the diagonal core (Pi-derivative lifted through `diagonalLinearMap`) + have hD : HasDerivAt (fun s => diagonal (fun i => riccatiCoeff (hÂ.eigenvalues i) T s)) + (diagonal (fun i => riccatiCoeff (hÂ.eigenvalues i) T t ^ 2 - (hÂ.eigenvalues i) ^ 2)) t := by + have hpi : HasDerivAt (fun s => (fun i => riccatiCoeff (hÂ.eigenvalues i) T s : n → ℝ)) + (fun i => riccatiCoeff (hÂ.eigenvalues i) T t ^ 2 - (hÂ.eigenvalues i) ^ 2) t := + hasDerivAt_pi.2 (fun i => hasDerivAt_riccatiCoeff (hÂ.eigenvalues i) T t) + have hL := + (Matrix.diagonalLinearMap (R := ℝ) (n := n) (α := ℝ)).toContinuousLinearMap.hasFDerivAt + (x := (fun i => riccatiCoeff (hÂ.eigenvalues i) T t : n → ℝ)) + -- `exact` (not `simpa`) bridges the operator-norm `AddCommGroup`, defeq to the default instance + have h2 := hL.comp_hasDerivAt t hpi + simp only [Function.comp_def] at h2 + exact h2 + -- conjugate by the constant unitary; derivative is `U · diag(riccatiCoeff² − λ²) · Uᴴ` + have hderiv : HasDerivAt (matrixRiccatiCoeff h T) + (U * diagonal (fun i => riccatiCoeff (hÂ.eigenvalues i) T t ^ 2 - (hÂ.eigenvalues i) ^ 2) + * star U) t := + (hD.const_mul U).mul_const (star U) + -- rewrite the target derivative into that spectral form + have hsq : matrixRiccatiCoeff h T t * matrixRiccatiCoeff h T t + = U * diagonal (fun i => riccatiCoeff (hÂ.eigenvalues i) T t ^ 2) * star U := by + have e1 : matrixRiccatiCoeff h T t + = Unitary.conjStarAlgAut ℝ (Matrix n n ℝ) hÂ.eigenvectorUnitary + (diagonal (fun i => riccatiCoeff (hÂ.eigenvalues i) T t)) := rfl + have hfg : (fun i => riccatiCoeff (hÂ.eigenvalues i) T t * riccatiCoeff (hÂ.eigenvalues i) T t) + = fun i => riccatiCoeff (hÂ.eigenvalues i) T t ^ 2 := + funext fun i => (pow_two (riccatiCoeff (hÂ.eigenvalues i) T t)).symm + rw [e1, ← map_mul, diagonal_mul_diagonal, Unitary.conjStarAlgAut_apply, hfg] + rw [show matrixRiccatiCoeff h T t * matrixRiccatiCoeff h T t -  *  + = U * diagonal (fun i => riccatiCoeff (hÂ.eigenvalues i) T t ^ 2 - (hÂ.eigenvalues i) ^ 2) + * star U from ?_] + · exact hderiv + · rw [hsq, matrixRiccatiCoeff_spectral_sq hÂ, ← hU, ← sub_mul, ← mul_sub, ← diagonal_sub] + +/-! ## §2 Market-making instantiation (the paper's matrix Riccati, Eq. 11) -/ + +/-- **Market-making matrix value coefficient** `A(t) = ½ • (D₊^{-½} · a(t) · D₊^{-½})`, the change +of variables that turns the normalised matrix Riccati `a` (`matrixRiccatiCoeff`) into the solution +of the market-making matrix Riccati `A' = 2 A D₊ A − (γ/2) Σ`. Here `D₊ = diagonal d` is the +positive diagonal `(α₂ᵢᵇ + α₂ᵢᵃ)zⁱ` and `D₊^{-½} = diagonal (√dᵢ)⁻¹`. -/ +noncomputable def mmMatrixValueCoeff (d : n → ℝ) { : Matrix n n ℝ} (h : Â.IsHermitian) + (T t : ℝ) : Matrix n n ℝ := + (1 / 2 : ℝ) • (diagonal (fun i => (Real.sqrt (d i))⁻¹) * matrixRiccatiCoeff h T t + * diagonal (fun i => (Real.sqrt (d i))⁻¹)) + +/-- **Terminal condition**: `A(T) = 0`. -/ +theorem mmMatrixValueCoeff_terminal (d : n → ℝ) { : Matrix n n ℝ} (h : Â.IsHermitian) (T : ℝ) : + mmMatrixValueCoeff d h T T = 0 := by + unfold mmMatrixValueCoeff + rw [matrixRiccatiCoeff_terminal] + simp + +/-- **Market-making matrix Riccati ODE**: `A'(t) = 2 • (A(t) D₊ A(t)) − (γ/2) • Σ`, with `D₊ = +diagonal d` positive and `Â` the Hermitian generator scale `· = γ • (D₊^{½} Σ D₊^{½})` (the +paper's ` = √γ (D₊^{½}ΣD₊^{½})^{½}`). The change of variables collapses because +`D₊^{-½} D₊ D₊^{-½} = 1` and `D₊^{-½} ² D₊^{-½} = γ Σ`, reducing everything to the abstract matrix +Riccati ODE `hasDerivAt_matrixRiccatiCoeff`. -/ +theorem hasDerivAt_mmMatrixValueCoeff + (d : n → ℝ) (hd : ∀ i, 0 < d i) (cov : Matrix n n ℝ) (γ : ℝ) + { : Matrix n n ℝ} (h : Â.IsHermitian) + (hÂsq :  *  = γ • (diagonal (fun i => Real.sqrt (d i)) * cov + * diagonal (fun i => Real.sqrt (d i)))) (T t : ℝ) : + HasDerivAt (mmMatrixValueCoeff d h T) + ((2 : ℝ) • (mmMatrixValueCoeff d h T t * diagonal d * mmMatrixValueCoeff d h T t) + - (γ / 2) • cov) t := by + set S : Matrix n n ℝ := diagonal (fun i => Real.sqrt (d i)) with hS + set Dm : Matrix n n ℝ := diagonal (fun i => (Real.sqrt (d i))⁻¹) with hDm + have hpos : ∀ i, Real.sqrt (d i) ≠ 0 := fun i => Real.sqrt_ne_zero'.2 (hd i) + have hDmS : Dm * S = 1 := by + rw [hDm, hS, diagonal_mul_diagonal, + show (fun i => (Real.sqrt (d i))⁻¹ * Real.sqrt (d i)) = (fun _ => (1 : ℝ)) from + funext fun i => inv_mul_cancel₀ (hpos i), diagonal_one] + have hSDm : S * Dm = 1 := by + rw [hDm, hS, diagonal_mul_diagonal, + show (fun i => Real.sqrt (d i) * (Real.sqrt (d i))⁻¹) = (fun _ => (1 : ℝ)) from + funext fun i => mul_inv_cancel₀ (hpos i), diagonal_one] + have hDmDDm : Dm * diagonal d * Dm = 1 := by + rw [hDm, diagonal_mul_diagonal, diagonal_mul_diagonal, + show (fun i => (Real.sqrt (d i))⁻¹ * d i * (Real.sqrt (d i))⁻¹) = (fun _ => (1 : ℝ)) from ?_, + diagonal_one] + funext i + have h := hpos i + field_simp + rw [Real.sq_sqrt (hd i).le] + have hconjCov : Dm * (S * cov * S) * Dm = cov := by + rw [Matrix.mul_assoc S cov S, ← Matrix.mul_assoc Dm S (cov * S), hDmS, Matrix.one_mul, + Matrix.mul_assoc cov S Dm, hSDm, Matrix.mul_one] + -- derivative from M1, conjugated by the constant `Dm` and scaled by ½ + have hderiv : HasDerivAt (mmMatrixValueCoeff d h T) + ((1 / 2 : ℝ) • (Dm * + (matrixRiccatiCoeff h T t * matrixRiccatiCoeff h T t -  * Â) * Dm)) t := + (((hasDerivAt_matrixRiccatiCoeff h T t).const_mul Dm).mul_const Dm).const_smul (1 / 2 : ℝ) + convert hderiv using 1 + -- derivative equality; unfold `A t`, then collapse both sides to `½•(Dm (a·a) Dm) − (γ/2)•cov` + have hA : mmMatrixValueCoeff d h T t + = (1 / 2 : ℝ) • (Dm * matrixRiccatiCoeff h T t * Dm) := by + rw [mmMatrixValueCoeff, ← hDm] + set a : Matrix n n ℝ := matrixRiccatiCoeff h T t + rw [hA, hÂsq] + -- RHS collapse + have hRHS : (1 / 2 : ℝ) • (Dm * (a * a - γ • (S * cov * S)) * Dm) + = (1 / 2 : ℝ) • (Dm * (a * a) * Dm) - (γ / 2) • cov := by + rw [mul_sub, sub_mul, smul_sub, mul_smul_comm, smul_mul_assoc, hconjCov, smul_smul] + congr 2 + ring + -- LHS collapse: first the matrix core, then the scalars + have hmat : (Dm * a * Dm) * diagonal d * (Dm * a * Dm) = Dm * (a * a) * Dm := by + rw [show (Dm * a * Dm) * diagonal d * (Dm * a * Dm) + = Dm * a * (Dm * diagonal d * Dm) * a * Dm from by simp only [Matrix.mul_assoc], + hDmDDm, Matrix.mul_one, + show Dm * a * a * Dm = Dm * (a * a) * Dm from by simp only [Matrix.mul_assoc]] + have hLHS : (2 : ℝ) • ((1 / 2 : ℝ) • (Dm * a * Dm) * diagonal d * ((1 / 2 : ℝ) • (Dm * a * Dm))) + = (1 / 2 : ℝ) • (Dm * (a * a) * Dm) := by + rw [smul_mul_assoc, smul_mul_assoc, mul_smul_comm, hmat, smul_smul, smul_smul] + norm_num + rw [hLHS, hRHS] + +end MathFin diff --git a/LeanPool/MathFin/Markets/Microstructure/RollSpread.lean b/LeanPool/MathFin/Markets/Microstructure/RollSpread.lean new file mode 100644 index 0000000000..e292c6f477 --- /dev/null +++ b/LeanPool/MathFin/Markets/Microstructure/RollSpread.lean @@ -0,0 +1,176 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Dependence.CorrelationFallacies + +/-! +# Roll (1984): the bid-ask bounce spread estimator + +Roll's model of a mid-price `m_t` contaminated by bid-ask bounce: the observed trade price is + +`P_t = m_t + (s/2) * q_t`, + +where `s ≥ 0` is the (constant) bid-ask spread and `q_t ∈ {-1, +1}` is the trade-direction +indicator (buy/sell), modelled as a fair random sign (`rademacher`, from +`MathFin.Probability.Dependence.CorrelationFallacies`). Roll's economic assumptions — stated here as +explicit, named hypotheses, since the original note leaves them implicit — are: + +* the signs `q_t` have the `rademacher` law (pairwise independent fair coin flips across time — + joint independence is never used); +* every pair of the five variables drawn from the two consecutive price changes that *splits + across* the two changes (one variable feeding `ΔP_t`, the other `ΔP_{t-1}`) is independent, + *except* the sign shared by the two changes with itself; independence *within* a single price + change is not assumed. + +The mid-price increments are also assumed square-integrable, so that the covariances exist. +Under these hypotheses the first-order autocovariance of the *trade-price change* +`ΔP_t = P_t - P_{t-1}` is `-(s/2)²`, nonpositive and strictly negative whenever `s ≠ 0`: + +`Cov(ΔP_t, ΔP_{t-1}) = -(s/2)²`. + +This is `covariance_rollPriceChange`. Covariance is bilinear and translation-invariant, so the +mean of the mid-price increments plays no role; only independence matters. Expanding the product and +discarding every covariance between independent variables leaves exactly one surviving term: the +own-covariance (variance) of the sign `q_{t-1}` shared between the two consecutive price changes, +whose variance is `1` (`variance_one_of_hasLaw_rademacher`). The identity is usually inverted into +the **Roll estimator** `s_hat = 2 √(-γ̂₁)` of the spread from the sample first-order autocovariance +`γ̂₁` of observed price changes; `rollSpread_eq_two_mul_sqrt` records the inversion at the level of +the model's covariance (`s = 2 √(-γ)` whenever `γ = -(s/2)²` and `s ≥ 0`). No sample +autocovariance, and no property of `s_hat` as an estimator, is formalized. + +We state the result for three consecutive sign variables `q0 q1 q2` (representing +`q_{t-2}, q_{t-1}, q_t`) and two increments `dm1 dm2` (`Δm_{t-1}, Δm_t`), rather than threading a +time index through a stochastic process, since only these five variables and their pairwise +independence ever enter the computation. + +The inversion is only meaningful when the sample autocovariance `γ̂₁` is nonpositive, as the model +predicts. If `γ̂₁ > 0` — which real data can and does produce, since the model is an +approximation — no `s` satisfies the hypothesis `γ = -(s/2)²` of `rollSpread_eq_two_mul_sqrt`, and +`Real.sqrt` of the negative argument `-γ̂₁` returns `0` by Mathlib's junk-value convention, so +naively evaluating `2 * Real.sqrt (-γ̂₁)` at `γ̂₁ > 0` silently yields a spread estimate of `0` +rather than signalling that the estimator is undefined there. + +## Main definitions + +* `rollPriceChange`: the Roll trade-price change `dm + (s/2) qNow - (s/2) qPrev` from a mid-price + increment `dm`, a spread `s` and two consecutive trade-direction signs. + +## Main results + +* `variance_id_rademacher`, `variance_one_of_hasLaw_rademacher`: a fair random sign has variance + `1`. +* `covariance_rollPriceChange`: `Cov(ΔP_t, ΔP_{t-1}) = -(s/2)²` under the stated law, + integrability and independence hypotheses. +* `rollSpread_eq_two_mul_sqrt`: the algebraic inversion `s = 2 * √(-γ)` for `s ≥ 0` and any real + `γ = -(s/2)²`; with `covariance_rollPriceChange` it gives `s = 2 * √(-Cov(ΔP_t, ΔP_{t-1}))`. + +## References + +* [R. Roll, *A simple implicit measure of the effective bid-ask spread in an efficient + market*][Roll1984]. + +## Tags + +Roll model, bid–ask bounce, effective spread, serial covariance, spread estimator, +market microstructure, MSC 62P05, MSC 91G70, JEL G14 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped ENNReal + +/-- **A fair random sign has variance `1`.** -/ +lemma variance_id_rademacher : Var[id; rademacher] = 1 := by + have hmean : rademacher[id] = 0 := by simpa using integral_id_rademacher + rw [variance_of_integral_eq_zero aemeasurable_id hmean] + have hsq : ∀ᵐ x ∂rademacher, (id x : ℝ) ^ 2 = 1 := by + filter_upwards [ae_rademacher] with x hx; rcases hx with h | h <;> simp [h] + rw [integral_congr_ae hsq] + simp + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + +/-- **A fair random sign lies in every `L^p`**: it is bounded by `1`. -/ +lemma memLp_id_rademacher (p : ℝ≥0∞) : MemLp id p rademacher := + MemLp.of_bound aestronglyMeasurable_id 1 + (by filter_upwards [ae_rademacher] with x hx; rcases hx with h | h <;> simp [h]) + +omit [IsProbabilityMeasure P] in +/-- **A fair random sign has variance `1`, transported along its law.** -/ +lemma variance_one_of_hasLaw_rademacher {X : Ω → ℝ} (hX : HasLaw X rademacher P) : + Var[X; P] = 1 := by + rw [hX.variance_eq, variance_id_rademacher] + +variable {q0 q1 q2 dm1 dm2 : Ω → ℝ} {s : ℝ} + +/-- The Roll trade-price change built from a mid-price increment `dm` (`Δm_t`) and two +consecutive trade signs `qPrev qNow` (`q_{t-1}, q_t`), following `P_t = m_t + (s/2) q_t`. -/ +noncomputable def rollPriceChange (dm qPrev qNow : Ω → ℝ) (s : ℝ) : Ω → ℝ := + dm + (fun ω ↦ s / 2 * qNow ω) - fun ω ↦ s / 2 * qPrev ω + +/-- **Roll's (1984) autocovariance identity.** Under the explicitly-stated hypotheses — +`q0, q1, q2` are fair random signs (`rademacher` law), `dm1, dm2` are square-integrable, and +every pair drawn from the five variables `{q0, q1, q2, dm1, dm2}` that is *split across the two +consecutive price changes* (one variable feeding `ΔP_t`, the other `ΔP_{t-1}`) is independent, +except `q1` with itself — the lag-one autocovariance of the trade-price change is `-(s/2)²`: the +own-covariance of the shared sign `q1` is the only surviving term. Independence *within* a single +price change (e.g. `dm2` with `q2`, or `dm1` with `q0`) is never used and so is not assumed: those +pairs never get multiplied together by the covariance expansion. -/ +theorem covariance_rollPriceChange + (hq0 : HasLaw q0 rademacher P) (hq1 : HasLaw q1 rademacher P) (hq2 : HasLaw q2 rademacher P) + (hdm1 : MemLp dm1 2 P) (hdm2 : MemLp dm2 2 P) + (h_q2q1 : q2 ⟂ᵢ[P] q1) (h_q2q0 : q2 ⟂ᵢ[P] q0) (h_q1q0 : q1 ⟂ᵢ[P] q0) + (h_dm2dm1 : dm2 ⟂ᵢ[P] dm1) + (h_dm2q0 : dm2 ⟂ᵢ[P] q0) (h_dm2q1 : dm2 ⟂ᵢ[P] q1) + (h_dm1q1 : dm1 ⟂ᵢ[P] q1) (h_dm1q2 : dm1 ⟂ᵢ[P] q2) : + cov[rollPriceChange dm2 q1 q2 s, rollPriceChange dm1 q0 q1 s; P] = -(s / 2) ^ 2 := by + have hq0' := hq0.memLp (memLp_id_rademacher 2) + have hq1' := hq1.memLp (memLp_id_rademacher 2) + have hq2' := hq2.memLp (memLp_id_rademacher 2) + have hsq0 : MemLp (fun ω ↦ s / 2 * q0 ω) 2 P := hq0'.const_mul _ + have hsq1 : MemLp (fun ω ↦ s / 2 * q1 ω) 2 P := hq1'.const_mul _ + have hsq2 : MemLp (fun ω ↦ s / 2 * q2 ω) 2 P := hq2'.const_mul _ + rw [rollPriceChange, rollPriceChange, + covariance_sub_sub (hdm2.add hsq2) hsq1 (hdm1.add hsq1) hsq0, + covariance_add_left hdm2 hsq2 (hdm1.add hsq1), covariance_add_left hdm2 hsq2 hsq0, + covariance_add_right hdm2 hdm1 hsq1, covariance_add_right hsq2 hdm1 hsq1, + covariance_add_right hsq1 hdm1 hsq1, + covariance_const_mul_right (X := dm2) (Y := q1) (s / 2), + covariance_const_mul_left (X := q2) (Y := dm1) (s / 2), + covariance_const_mul_left (X := q2) (Y := fun ω ↦ s / 2 * q1 ω) (s / 2), + covariance_const_mul_right (X := q2) (Y := q1) (s / 2), + covariance_const_mul_right (X := dm2) (Y := q0) (s / 2), + covariance_const_mul_left (X := q2) (Y := fun ω ↦ s / 2 * q0 ω) (s / 2), + covariance_const_mul_right (X := q2) (Y := q0) (s / 2), + covariance_const_mul_left (X := q1) (Y := dm1) (s / 2), + covariance_const_mul_left (X := q1) (Y := fun ω ↦ s / 2 * q1 ω) (s / 2), + covariance_const_mul_right (X := q1) (Y := q1) (s / 2), + covariance_const_mul_left (X := q1) (Y := fun ω ↦ s / 2 * q0 ω) (s / 2), + covariance_const_mul_right (X := q1) (Y := q0) (s / 2), + h_dm2dm1.covariance_eq_zero hdm2 hdm1, h_dm2q1.covariance_eq_zero hdm2 hq1', + h_dm1q2.symm.covariance_eq_zero hq2' hdm1, h_q2q1.covariance_eq_zero hq2' hq1', + h_dm2q0.covariance_eq_zero hdm2 hq0', h_q2q0.covariance_eq_zero hq2' hq0', + h_dm1q1.symm.covariance_eq_zero hq1' hdm1, + covariance_self hq1'.aemeasurable, variance_one_of_hasLaw_rademacher hq1, + h_q1q0.covariance_eq_zero hq1' hq0'] + ring + +/-- **Roll's (1984) spread estimator**: inverting the covariance identity algebraically gives +`s = 2 √(-Cov(ΔP_t, ΔP_{t-1}))` for `s ≥ 0`. Stated directly from the covariance value (rather +than re-deriving it from the independence hypotheses) since the inversion is pure algebra on a +real number `γ` standing for `cov[ΔP_t, ΔP_{t-1}; P]`. -/ +theorem rollSpread_eq_two_mul_sqrt {γ : ℝ} (hs : 0 ≤ s) (hγ : γ = -(s / 2) ^ 2) : + s = 2 * Real.sqrt (-γ) := by + rw [hγ, neg_neg, Real.sqrt_sq (by positivity)] + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/Bachelier/Bachelier.lean b/LeanPool/MathFin/Models/Bachelier/Bachelier.lean new file mode 100644 index 0000000000..22be369532 --- /dev/null +++ b/LeanPool/MathFin/Models/Bachelier/Bachelier.lean @@ -0,0 +1,125 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Gaussian.GaussianPartialMoments + +/-! +# Bachelier model option pricing + +The Bachelier (1900) model is the historical predecessor of Black-Scholes: +asset prices follow an **arithmetic** Brownian motion `S_T = S_0 + σ · W_T` +(no exponential, no log-normality). Used today for short-tenor / negative-rate +markets where lognormality is inappropriate. + +Under `BachelierHyp`, the discounted call price is + + V_bach = (S_0 - K) · Φ(d) + σ √T · ϕ(d), + +where `d = (S_0 - K) / (σ √T)`, `Φ` and `ϕ` are the standard normal CDF and +PDF. The proof is a HasLaw transfer to the standard normal, where the payoff is +`σ √T · (z + d)⁺`, followed by the standard-normal stop-loss transform +`integral_max_sub_mul_gaussianPDFReal` in `Probability/Gaussian/GaussianPartialMoments`. + +## Main definitions + +* `BachelierHyp`: the Bachelier risk-neutral hypothesis: `0 < K`, `0 < σ`, `0 < T` and `Z` standard + normal under `Q` (the terminal price is then `bachelierTerminal S_0 σ T (Z ω)`). +* `bachelierD`: the dimensionless distance to the strike `d = (S_0 - K) / (σ √T)`. +* `bachelierTerminal`: the terminal price as a function of the driver, `S_0 + σ √T · z`. + +## Main results + +* `bachelier_call_formula`: under `BachelierHyp`, the expected European call payoff + `E_Q[max (S_T - K) 0]` equals `(S_0 - K) * Φ d + σ * √T * ϕ d` with `d = bachelierD S_0 K σ T`. + +## References + +* [Bachelier (1900)][Bachelier1900] +* [F. Black, *The pricing of commodity contracts*][Black1976] +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006] + +## Tags + +Bachelier model, arithmetic Brownian motion, normal model, negative rates, call price, +stop-loss transform, MSC 91G20, MSC 60J65, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real Filter +open scoped NNReal ENNReal Topology + +/-! ### Bachelier model hypothesis -/ + +/-- Bachelier model risk-neutral hypothesis: the terminal price `S_T = S_0 + σ √T · Z` +with `Z ~ N(0, 1)`. The asset follows arithmetic Brownian motion (no exponential). -/ +structure BachelierHyp {Ω : Type*} {mΩ : MeasurableSpace Ω} + (Q : Measure Ω) [IsProbabilityMeasure Q] + (S_0 K σ T : ℝ) (Z : Ω → ℝ) : Prop where + K_pos : 0 < K + σ_pos : 0 < σ + T_pos : 0 < T + Z_law : HasLaw Z (gaussianReal 0 1) Q + +/-- Bachelier `d`: dimensionless distance to the strike. -/ +noncomputable def bachelierD (S_0 K σ T : ℝ) : ℝ := + (S_0 - K) / (σ * Real.sqrt T) + +/-- Bachelier terminal price `S_T(z) = S_0 + σ √T · z`. -/ +noncomputable def bachelierTerminal (S_0 σ T : ℝ) (z : ℝ) : ℝ := + S_0 + σ * Real.sqrt T * z + +/-! ### Bachelier call pricing formula -/ + +/-- **Bachelier European call pricing formula.** + +For an asset whose risk-neutral dynamics are arithmetic Brownian motion +(`bachelierTerminal(z) = S_0 + σ √T · z` with `Z ~ N(0, 1)`), +the expected payoff of the European call `max(S_T - K, 0)` is + + E_Q[max(S_T - K, 0)] = (S_0 - K) · Φ(d) + σ √T · ϕ(d), + +where `d = (S_0 - K) / (σ √T)`. + +Derivation: HasLaw transfer to the standard normal, where +`max(S_T - K, 0) = σ √T · max(z + d, 0)`, so the integral is `σ √T` times the standard-normal +stop-loss transform `integral_max_sub_mul_gaussianPDFReal` at `-d`. -/ +theorem bachelier_call_formula {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K σ T : ℝ} {Z : Ω → ℝ} + (h : BachelierHyp Q S_0 K σ T Z) : + ∫ ω, max (bachelierTerminal S_0 σ T (Z ω) - K) 0 ∂Q + = (S_0 - K) * Phi (bachelierD S_0 K σ T) + + σ * Real.sqrt T * gaussianPDFReal 0 1 (bachelierD S_0 K σ T) := by + obtain ⟨_, hσ, hT, hZ⟩ := h + set d : ℝ := bachelierD S_0 K σ T + have hc : 0 < σ * Real.sqrt T := mul_pos hσ (Real.sqrt_pos.mpr hT) + have hcd : σ * Real.sqrt T * d = S_0 - K := by + simp only [d, bachelierD]; field_simp + have h_payoff_meas : Measurable fun z : ℝ ↦ max (bachelierTerminal S_0 σ T z - K) 0 := by + unfold bachelierTerminal; fun_prop + -- The payoff is `σ√T · (z + d)⁺`, so the integral is `σ√T` times the stop-loss transform. + have hpt (z : ℝ) : gaussianPDFReal 0 1 z • max (bachelierTerminal S_0 σ T z - K) 0 + = σ * Real.sqrt T * (max (z - -d) 0 * gaussianPDFReal 0 1 z) := by + have h : bachelierTerminal S_0 σ T z - K = σ * Real.sqrt T * (z - -d) := by + unfold bachelierTerminal; linear_combination -hcd + have hmax := mul_max_of_nonneg (z - -d) 0 hc.le + rw [mul_zero] at hmax + rw [smul_eq_mul, h, ← hmax]; ring + rw [show (fun ω ↦ max (bachelierTerminal S_0 σ T (Z ω) - K) 0) + = (fun z ↦ max (bachelierTerminal S_0 σ T z - K) 0) ∘ Z from rfl, + hZ.integral_comp h_payoff_meas.aestronglyMeasurable, + integral_gaussianReal_eq_integral_smul (one_ne_zero : (1 : ℝ≥0) ≠ 0), + integral_congr_ae (Filter.Eventually.of_forall hpt), integral_const_mul, + integral_max_sub_mul_gaussianPDFReal, gaussianPDFReal_zero_one_neg, Phi_neg] + linear_combination Phi d * hcd + +end MathFin diff --git a/LeanPool/MathFin/Models/Bachelier/BachelierGreeks.lean b/LeanPool/MathFin/Models/Bachelier/BachelierGreeks.lean new file mode 100644 index 0000000000..7d39633b7e --- /dev/null +++ b/LeanPool/MathFin/Models/Bachelier/BachelierGreeks.lean @@ -0,0 +1,206 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Bachelier.Bachelier +public import LeanPool.MathFin.Probability.Analysis.DerivOfDeriv +public import Mathlib.Analysis.SpecialFunctions.Sqrt + +/-! +# Bachelier model Greeks + +For the Bachelier call price `V_bach(S, σ, T) = (S − K) Φ(d) + σ √T ϕ(d)` +where `d = (S − K)/(σ √T)`, we derive four Greeks: + +* **Delta**: `∂V/∂S = Φ(d)`. +* **Gamma**: `∂²V/∂S² = ϕ(d) / (σ √T)`. +* **Vega**: `∂V/∂σ = √T · ϕ(d)`. +* **Theta**: `∂V/∂T = σ · ϕ(d) / (2 √T)`. + +These parallel the Black–Scholes Greeks but with much simpler algebra +(no exponential, no log). All cancellation goes through the identity +`(S − K)/(σ √T) = d`. + +## Main definitions + +* `bachelierV`: the Bachelier call price `(S - K) Φ d + σ √T ϕ d` with `d = (S - K) / (σ √T)`, as a + function of the spot `S`. + +## Main results + +* `hasDerivAt_bachelierV_S`: delta, `∂V/∂S = Φ d`, for `0 < σ` and `0 < T`. +* `hasDerivAt_deriv_bachelierV_S`: gamma, `∂²V/∂S² = ϕ d / (σ √T)`, for `0 < σ` and `0 < T`. +* `hasDerivAt_bachelierV_sigma`: vega, `∂V/∂σ = √T · ϕ d`, for `0 < T` and `0 < σ`. +* `hasDerivAt_bachelierV_T`: theta, `∂V/∂T = σ · ϕ d / (2 √T)`, for `0 < σ` and `0 < T`. + +## Tags + +Bachelier model, Greeks, delta, gamma, vega, theta, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- The Bachelier call price as a function of `(S, σ)`: +`V_bach = (S − K) Φ(d) + σ √T ϕ(d)` where `d = (S − K)/(σ √T)`. -/ +noncomputable def bachelierV (K σ T : ℝ) (S : ℝ) : ℝ := + (S - K) * Phi (bachelierD S K σ T) + + σ * Real.sqrt T * gaussianPDFReal 0 1 (bachelierD S K σ T) + +/-- `∂_S [bachelierD S K σ T] = 1 / (σ √T)`. -/ +private lemma hasDerivAt_bachelierD_S {K σ T : ℝ} (hσ : 0 < σ) (hT : 0 < T) (S : ℝ) : + HasDerivAt (fun s ↦ bachelierD s K σ T) (1 / (σ * Real.sqrt T)) S := by + have h_sqrt_pos : 0 < Real.sqrt T := Real.sqrt_pos.mpr hT + have h_στ_pos : 0 < σ * Real.sqrt T := mul_pos hσ h_sqrt_pos + have h_num : HasDerivAt (fun s : ℝ ↦ s - K) 1 S := by + convert (hasDerivAt_id S).sub_const K using 1; rfl + exact h_num.div_const (σ * Real.sqrt T) + +/-- **Bachelier delta**: `∂V/∂S = Φ(d)`. -/ +lemma hasDerivAt_bachelierV_S {K σ T : ℝ} (hσ : 0 < σ) (hT : 0 < T) (S : ℝ) : + HasDerivAt (fun s ↦ bachelierV K σ T s) (Phi (bachelierD S K σ T)) S := by + have h_sqrt_pos : 0 < Real.sqrt T := Real.sqrt_pos.mpr hT + have h_sqrt_ne : Real.sqrt T ≠ 0 := h_sqrt_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have h_d_S := hasDerivAt_bachelierD_S (K := K) hσ hT S + -- Chain rule: ∂_S Φ(d(S)) = ϕ(d) · ∂_S d + have h_Phi_chain := (hasDerivAt_Phi (bachelierD S K σ T)).comp S h_d_S + -- Chain rule: ∂_S ϕ(d(S)) = -d · ϕ(d) · ∂_S d + have h_pdf_chain := (hasDerivAt_gaussianPDFReal_zero_one (bachelierD S K σ T)).comp S h_d_S + -- ∂_S [(S - K)] = 1 + have h_S_sub : HasDerivAt (fun s : ℝ ↦ s - K) 1 S := by + convert (hasDerivAt_id S).sub_const K using 1; rfl + -- ∂_S [(S-K) · Φ(d(S))] = Φ(d) + (S-K) · ϕ(d) · ∂_S d + have h_term1 := h_S_sub.mul h_Phi_chain + -- ∂_S [σ √T · ϕ(d(S))] = σ √T · (-d ϕ(d)) · ∂_S d + have h_term2 := h_pdf_chain.const_mul (σ * Real.sqrt T) + have h_full := h_term1.add h_term2 + unfold bachelierV + convert h_full using 1 <;> try rfl + -- Value match: (S - K) ϕ(d) · 1/(σ√T) - σ√T · d · ϕ(d) · 1/(σ√T) + -- = ϕ(d) · [(S-K)/(σ√T) - d] = ϕ(d) · [d - d] = 0 + -- so Φ(d) = Φ(d) + 0. trivially. + simp only [Function.comp] + change Phi (bachelierD S K σ T) = + (1 * Phi (bachelierD S K σ T) + (S - K) * + (gaussianPDFReal 0 1 (bachelierD S K σ T) * (1 / (σ * Real.sqrt T)))) + + σ * Real.sqrt T * + (-(bachelierD S K σ T * gaussianPDFReal 0 1 (bachelierD S K σ T)) * (1 / (σ * Real.sqrt T))) + rw [bachelierD] + field_simp + ring + +/-- **Bachelier vega**: `∂V/∂σ = √T · ϕ(d)`. -/ +lemma hasDerivAt_bachelierV_sigma {K T : ℝ} (hT : 0 < T) + {S σ : ℝ} (hσ : 0 < σ) : + HasDerivAt (fun s ↦ bachelierV K s T S) + (Real.sqrt T * gaussianPDFReal 0 1 (bachelierD S K σ T)) σ := by + have h_sqrt_pos : 0 < Real.sqrt T := Real.sqrt_pos.mpr hT + have h_sqrt_ne : Real.sqrt T ≠ 0 := h_sqrt_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + -- ∂_σ [bachelierD] = -(S - K) / (σ² √T) = -d/σ + have h_d_σ : HasDerivAt (fun s ↦ bachelierD S K s T) + (-((S - K) / (σ^2 * Real.sqrt T))) σ := by + have h_quot : HasDerivAt (fun s : ℝ ↦ (S - K) / (s * Real.sqrt T)) + ((0 * (σ * Real.sqrt T) - (S - K) * (1 * Real.sqrt T)) / (σ * Real.sqrt T)^2) σ := by + have h_const : HasDerivAt (fun _ : ℝ ↦ (S - K)) 0 σ := hasDerivAt_const _ _ + have h_denom : HasDerivAt (fun s : ℝ ↦ s * Real.sqrt T) (1 * Real.sqrt T) σ := by + convert (hasDerivAt_id σ).mul_const (Real.sqrt T) using 1; rfl + exact h_const.div h_denom (mul_pos hσ h_sqrt_pos).ne' + convert h_quot using 1 <;> try rfl + field_simp + ring + -- Chain rules + have h_Phi_chain := (hasDerivAt_Phi (bachelierD S K σ T)).comp σ h_d_σ + have h_pdf_chain := (hasDerivAt_gaussianPDFReal_zero_one (bachelierD S K σ T)).comp σ h_d_σ + -- ∂_σ [(S-K) Φ(d(σ))] = (S-K) ϕ(d) · ∂_σ d + have h_term1 := h_Phi_chain.const_mul (S - K) + -- ∂_σ [σ √T] = √T + have h_σ_sqrt : HasDerivAt (fun s : ℝ ↦ s * Real.sqrt T) (Real.sqrt T) σ := by + convert (hasDerivAt_id σ).mul_const (Real.sqrt T) using 1 <;> first | rfl | ring + -- ∂_σ [σ √T · ϕ(d(σ))] = √T · ϕ(d) + σ √T · (-d ϕ(d)) · ∂_σ d + have h_term2 := h_σ_sqrt.mul h_pdf_chain + have h_full := h_term1.add h_term2 + unfold bachelierV + convert h_full using 1 <;> try rfl + simp only [Function.comp] + rw [bachelierD] + field_simp + ring + +/-- **The Bachelier gamma formula**: the S-derivative of the delta `Φ(d(S))` is +`ϕ(d) / (σ √T)`, by the chain rule. The second derivative of the price itself is +`hasDerivAt_deriv_bachelierV_S`. -/ +private lemma hasDerivAt_bachelierV_SS {K σ T : ℝ} (hσ : 0 < σ) (hT : 0 < T) (S : ℝ) : + HasDerivAt (fun s ↦ Phi (bachelierD s K σ T)) + (gaussianPDFReal 0 1 (bachelierD S K σ T) / (σ * Real.sqrt T)) S := by + -- `S` is `bachelierD`'s first argument, so the chain rule is elaborated before its target + have h := (hasDerivAt_Phi (bachelierD S K σ T)).comp S (hasDerivAt_bachelierD_S (K := K) hσ hT S) + exact h.congr_deriv (mul_one_div _ _) + +/-- **Bachelier gamma**: `∂²V/∂S² = ϕ(d) / (σ √T)`, for the price itself: the delta `Φ(d)` is +`∂V/∂S` at every spot (`hasDerivAt_bachelierV_S`), and its derivative is the gamma formula +(`hasDerivAt_bachelierV_SS`). -/ +theorem hasDerivAt_deriv_bachelierV_S {K σ T : ℝ} (hσ : 0 < σ) (hT : 0 < T) (S : ℝ) : + HasDerivAt (deriv fun s ↦ bachelierV K σ T s) + (gaussianPDFReal 0 1 (bachelierD S K σ T) / (σ * Real.sqrt T)) S := + hasDerivAt_deriv_of_eventually + (.of_forall (hasDerivAt_bachelierV_S hσ hT)) + (hasDerivAt_bachelierV_SS hσ hT S) + +/-- **Bachelier theta**: `∂V/∂T = σ · ϕ(d) / (2 √T)`. + +Chain-rule contributions through `d` cancel via `(S − K) · d / √T = σ · d²`. -/ +lemma hasDerivAt_bachelierV_T {K σ : ℝ} (hσ : 0 < σ) {S T : ℝ} (hT : 0 < T) : + HasDerivAt (fun t ↦ bachelierV K σ t S) + (σ * gaussianPDFReal 0 1 (bachelierD S K σ T) / (2 * Real.sqrt T)) T := by + have h_sqrt_pos : 0 < Real.sqrt T := Real.sqrt_pos.mpr hT + have h_sqrt_ne : Real.sqrt T ≠ 0 := h_sqrt_pos.ne' + have hT_ne : T ≠ 0 := hT.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have h_sqrt_sq : Real.sqrt T ^ 2 = T := Real.sq_sqrt hT.le + -- ∂_T [bachelierD] = -(S - K) / (2 σ T^(3/2)) = -d / (2 T) + have h_d_T : HasDerivAt (fun t ↦ bachelierD S K σ t) + (-((S - K) / (2 * σ * T * Real.sqrt T))) T := by + have h_const : HasDerivAt (fun _ : ℝ ↦ (S - K)) 0 T := hasDerivAt_const _ _ + have h_sqrt : HasDerivAt Real.sqrt (1 / (2 * Real.sqrt T)) T := Real.hasDerivAt_sqrt hT.ne' + have h_σsqrt : HasDerivAt (fun t : ℝ ↦ σ * Real.sqrt t) (σ / (2 * Real.sqrt T)) T := by + have := h_sqrt.const_mul σ + convert this using 1 + field_simp + have h_quot : HasDerivAt (fun t : ℝ ↦ (S - K) / (σ * Real.sqrt t)) + ((0 * (σ * Real.sqrt T) - (S - K) * (σ / (2 * Real.sqrt T))) / (σ * Real.sqrt T)^2) T := by + exact h_const.div h_σsqrt (mul_pos hσ h_sqrt_pos).ne' + convert h_quot using 1 <;> try rfl + field_simp + rw [show Real.sqrt T ^ 2 = T from h_sqrt_sq] + ring + -- Chain rules + have h_Phi := (hasDerivAt_Phi (bachelierD S K σ T)).comp T h_d_T + have h_pdf := (hasDerivAt_gaussianPDFReal_zero_one (bachelierD S K σ T)).comp T h_d_T + -- ∂_T [(S - K) Φ(d(T))] = (S - K) · ϕ(d) · ∂_T d + have h_term1 := h_Phi.const_mul (S - K) + -- ∂_T [σ √T] = σ / (2√T) + have h_σsqrt' : HasDerivAt (fun t : ℝ ↦ σ * Real.sqrt t) (σ / (2 * Real.sqrt T)) T := by + have h := (Real.hasDerivAt_sqrt hT.ne').const_mul σ + convert h using 1 + field_simp + -- ∂_T [σ √T · ϕ(d(T))] = (σ/(2√T)) · ϕ(d) + σ √T · (-d ϕ(d)) · ∂_T d + have h_term2 := h_σsqrt'.mul h_pdf + have h_full := h_term1.add h_term2 + unfold bachelierV + convert h_full using 1 <;> try rfl + simp only [Function.comp] + rw [bachelierD] + field_simp + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/American.lean b/LeanPool/MathFin/Models/Binomial/American.lean new file mode 100644 index 0000000000..635af23122 --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/American.lean @@ -0,0 +1,108 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.PathMeasure + +/-! +# American option pricing in the binomial tree + +For a binomial tree with up-factor `u`, down-factor `d`, per-step rate `r`, +under the no-arbitrage condition `d < e^r < u`, an American option with +intrinsic payoff `g : ℝ → ℝ` (e.g. `S ↦ max(S − K, 0)` for a call) has price + + `V_n(S) = max(g(S), e^{-r} · (p · V_{n-1}(uS) + (1 − p) · V_{n-1}(dS)))` + +with `V_0(S) = g(S)`, where `p = crrUpProb u d r`. `n` counts steps remaining. + +This is the exercise-everywhere case of the tree's one recursion `bermudanPrice` +(`Models/Binomial/Model.lean`); its dominance and supermartingale clauses +(`le_bermudanPrice`, `bermudanPrice_supermartingale`), its Snell-envelope characterization +(`Models/Binomial/SnellEnvelope.lean`) and its monotonicity in the exercise set, hence the +European ≤ American ordering (`Models/Binomial/Bermudan.lean`), all apply to it. + +This file defines `americanPrice`, with the one-step Bellman equation `americanPrice_succ`, and +identifies it with the Snell envelope. Under the risk-neutral coin flips `coinFlipMeasure q`, with +`q = crrUpProb u d ρ`, the price is the time-`0` value of the library's Snell envelope +`snellEnvelope` (`Probability/Discrete/SnellEnvelope.lean`, Mathlib's conditional expectation on +the flip filtration) of the discounted intrinsic value `e^{−ρn} g(Sₙ)` along the spot path, with +every date an exercise date: the exercise-everywhere case of +`snellEnvelope_discounted_bermudanPrice` at time `0`. + +Not proved here: the envelope as a supremum over stopping times, or any statement about the +price at a later time. + +## Main definitions + +* `americanPrice`: the American option price in the binomial tree, the Bellman recursion taking + at each step the larger of the intrinsic payoff and the discounted risk-neutral continuation. + +## Main results + +* `americanPrice_zero`: with no steps remaining, the price is the intrinsic payoff `g S`. +* `americanPrice_succ`: one-step Bellman equation `V_{n+1}(S) = max(g(S), continuation)`. +* `americanPrice_eq_snellEnvelope`: almost surely under `coinFlipMeasure q`, the Snell envelope at + time `0` of the discounted intrinsic value is `americanPrice u d ρ g N S₀`. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 21.5 +* [S. E. Shreve, *Stochastic Calculus for Finance I: The Binomial Asset Pricing Model*][ShreveSCFI], + 4.4 + +## Tags + +American option, early exercise, Bellman equation, binomial tree, dynamic programming, +optimal exercise, Snell envelope, optimal stopping, MSC 91G20, MSC 49L20, MSC 60G40, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Real MeasureTheory +open scoped NNReal + +/-- American option price in the binomial tree: the Bellman recursion taking, at each +step, the maximum of immediate exercise (`g S`) and the discounted expected continuation, +i.e. `bermudanPrice` with early exercise at every step. `n` counts steps remaining; `g` is +the intrinsic payoff function. -/ +noncomputable def americanPrice (u d r : ℝ) (g : ℝ → ℝ) : ℕ → ℝ → ℝ := + bermudanPrice Set.univ u d r g + +/-- At maturity (`n = 0`), the American price equals the intrinsic payoff. -/ +@[simp] +lemma americanPrice_zero (u d r : ℝ) (g : ℝ → ℝ) (S : ℝ) : + americanPrice u d r g 0 S = g S := rfl + +/-- One-step Bellman: `V_{n+1}(S) = max(g(S), one-period continuation)`. -/ +lemma americanPrice_succ (u d r : ℝ) (g : ℝ → ℝ) (n : ℕ) (S : ℝ) : + americanPrice u d r g (n + 1) S = max (g S) + (binomialOptionPriceOnePeriod u d r + (americanPrice u d r g n (S * u)) + (americanPrice u d r g n (S * d))) := + bermudanPrice_succ_of_mem (Set.mem_univ _) u d r g S + +/-- **The binomial American price is the Snell envelope.** Under the risk-neutral coin flips +(`crrUpProb u d ρ = q`), the Snell envelope of the discounted intrinsic value `e^{−ρn} g(Sₙ)` +along the spot path, for the flip filtration, horizon `N` and exercise at every date, is at time +`0` almost surely `americanPrice u d ρ g N S₀`. -/ +theorem americanPrice_eq_snellEnvelope {u d ρ : ℝ} {q : ℝ≥0} (hq : q ≤ 1) + (hqcrr : crrUpProb u d ρ = q) (g : ℝ → ℝ) (S₀ : ℝ) (N : ℕ) : + ∀ᵐ ω ∂coinFlipMeasure q hq, + snellEnvelope (coinFlipMeasure q hq) flipFiltration Set.univ + (fun n ω ↦ Real.exp (-ρ * n) * g (spotPath S₀ u d n ω)) N 0 ω + = americanPrice u d ρ g N S₀ := by + have h := snellEnvelope_discounted_bermudanPrice (E := Set.univ) hq u d ρ g S₀ hqcrr + (N := N) (k := 0) (Nat.zero_le N) + simp only [Set.mem_univ, Set.ofPred_true] at h + filter_upwards [h] with ω hω + rw [hω] + simp [americanPrice, spotPath] + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/BarrierReflection.lean b/LeanPool/MathFin/Models/Binomial/BarrierReflection.lean new file mode 100644 index 0000000000..21ab31eab3 --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/BarrierReflection.lean @@ -0,0 +1,170 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.PathReflection +public import Mathlib.Basic.Real.Basic +public import Mathlib.SetTheory.Cardinal.Finite + +/-! +# Barrier-option counting via the reflection principle + +`Models/Binomial/PathReflection.lean` builds André's reflection bijection +`reflectionPrincipleEquivBelow : {ω // hit a ∧ end = b} ≃ {ω // end = 2a − b}` (for +`0 < a`, `b ≤ a`) and notes that *"the `Fintype.card` identity is their immediate corollary +and is not separately stated here."* This file states it — the counting backbone of +binomial barrier-option pricing — and derives the **maximal-distribution identity**, the +running-maximum law that prices the knock-in. + +## Main definitions + +* `reflectHitLtGt`: the equivalence between paths that hit `a` and end below `a`, and paths that + hit `a` and end above `a`. +* `hitAboveEquiv`: for `0 < a`, paths that hit `a` and end above `a` are in bijection with paths + ending above `a`. +* `hitAtEquiv`: for `0 < a`, paths that hit `a` and end at `a` are in bijection with paths + ending at `a`. + +## Main results + +* `reflection_principle_card` — for `0 < a`, `b ≤ a`, `#{hit a, end b} = #{end 2a−b}` (the + counting form of the bijection), and its finance reading `barrierDigital_knockIn_reflection`: + under the symmetric tree, a cash-or-nothing up-and-in digital at terminal `b ≤ a` equals the + vanilla digital at the reflected level. +* `binomial_maximal_distribution_card` — the running-maximum distribution + `#{ω : max ≥ a} = 2·#{end > a} + #{end = a}` (`a > 0`), the discrete + `P(max ≥ a) = 2P(S_n > a) + P(S_n = a)` — obtained by trichotomising the hit-set and + reflecting the below-barrier endpoints onto the above-barrier ones. + +## References + +* [André (1887)][Andre1887] + +## Tags + +barrier option, reflection principle, running maximum, knock-in, André reflection, lattice paths, +MSC 91G20, MSC 60G50, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Finset + +variable {n : ℕ} + +/-- **Counting form of André's reflection principle.** For a barrier `0 < a` and terminal +`b ≤ a`, the number of `n`-step ±1 paths that touch `a` and finish at `b` equals the number +that finish at `2a − b`. Immediate from `reflectionPrincipleEquivBelow`. -/ +theorem reflection_principle_card (a b : ℤ) (ha : 0 < a) (hb : b ≤ a) : + Nat.card {ω : Fin n → Bool // HitsLevel a ω ∧ walkPos ω n = b} + = Nat.card {ω : Fin n → Bool // walkPos ω n = 2 * a - b} := + Nat.card_congr (reflectionPrincipleEquivBelow a b ha hb) + +/-- **Barrier cash-or-nothing knock-in = vanilla digital at the reflected level** (symmetric +tree). Under the symmetric `q = 1/2` binomial measure (each path weight `2⁻ⁿ`), the up-and-in +digital paying `1` on `{touch a, finish b}` (with `b ≤ a`) has the same price as the vanilla +digital paying `1` on `{finish 2a − b}`. -/ +theorem barrierDigital_knockIn_reflection (a b : ℤ) (ha : 0 < a) (hb : b ≤ a) : + (Nat.card {ω : Fin n → Bool // HitsLevel a ω ∧ walkPos ω n = b} : ℝ) / 2 ^ n + = (Nat.card {ω : Fin n → Bool // walkPos ω n = 2 * a - b} : ℝ) / 2 ^ n := by + rw [reflection_principle_card a b ha hb] + +/-- Reflection swaps below-barrier and above-barrier endpoints on the hit-set: +`{hit a, end < a} ≃ {hit a, end > a}` via reflection at the first hit. -/ +noncomputable def reflectHitLtGt (a : ℤ) : + {ω : Fin n → Bool // HitsLevel a ω ∧ walkPos ω n < a} ≃ + {ω : Fin n → Bool // HitsLevel a ω ∧ a < walkPos ω n} where + toFun ω := ⟨reflectAtFirstHit a ω.1, by + refine ⟨?_, ?_⟩ + · rw [reflectAtFirstHit, dite_eq_left ω.2.1] + exact HitsLevel.reflectAfter_firstHit ω.1 a ω.2.1 + · have h := walkPos_reflectAtFirstHit_endpoint ω.1 a (walkPos ω.1 n) ω.2.1 rfl + have := ω.2.2; rw [h]; linarith⟩ + invFun ω := ⟨reflectAtFirstHit a ω.1, by + refine ⟨?_, ?_⟩ + · rw [reflectAtFirstHit, dite_eq_left ω.2.1] + exact HitsLevel.reflectAfter_firstHit ω.1 a ω.2.1 + · have h := walkPos_reflectAtFirstHit_endpoint ω.1 a (walkPos ω.1 n) ω.2.1 rfl + have := ω.2.2; rw [h]; linarith⟩ + left_inv ω := Subtype.ext (reflectAtFirstHit_involutive a ω.1) + right_inv ω := Subtype.ext (reflectAtFirstHit_involutive a ω.1) + +/-- Above a positive barrier the hit condition is automatic (discrete IVT): +`{hit a, end > a} ≃ {end > a}`. -/ +noncomputable def hitAboveEquiv (a : ℤ) (ha : 0 < a) : + {ω : Fin n → Bool // HitsLevel a ω ∧ a < walkPos ω n} ≃ + {ω : Fin n → Bool // a < walkPos ω n} where + toFun ω := ⟨ω.1, ω.2.2⟩ + invFun ω := ⟨ω.1, HitsLevel_of_endpoint_gt (le_of_lt ha) ω.2, ω.2⟩ + left_inv _ := rfl + right_inv _ := rfl + +/-- At a positive barrier the hit condition is automatic: `{hit a, end = a} ≃ {end = a}`. -/ +noncomputable def hitAtEquiv (a : ℤ) (ha : 0 < a) : + {ω : Fin n → Bool // HitsLevel a ω ∧ walkPos ω n = a} ≃ + {ω : Fin n → Bool // walkPos ω n = a} where + toFun ω := ⟨ω.1, ω.2.2⟩ + invFun ω := ⟨ω.1, HitsLevel_of_walkPos_endpoint_ge ω.1 a (le_of_lt ha) ω.2.ge, ω.2⟩ + left_inv _ := rfl + right_inv _ := rfl + +/-- **The binomial maximal-distribution identity** (running-maximum law). For a barrier +`0 < a`, the number of `n`-step ±1 paths whose running maximum reaches `a` (i.e. that hit `a`) +is `2·#{end > a} + #{end = a}` — the discrete `P(max ≥ a) = 2·P(S_n > a) + P(S_n = a)`. + +Proof: trichotomise the hit-set by the terminal position. Paths ending `> a` or `= a` hit `a` +automatically (`hitAboveEquiv`, `hitAtEquiv`, discrete IVT), and reflection at the first hit +(`reflectHitLtGt`) bijects the below-barrier endpoints onto the above-barrier ones, so +`#{hit a, end < a} = #{end > a}`. -/ +theorem binomial_maximal_distribution_card (a : ℤ) (ha : 0 < a) : + Nat.card {ω : Fin n → Bool // HitsLevel a ω} + = 2 * Nat.card {ω : Fin n → Bool // a < walkPos ω n} + + Nat.card {ω : Fin n → Bool // walkPos ω n = a} := by + classical + simp only [Nat.card_eq_fintype_card, Fintype.card_subtype] + -- The three hit-set slices, with the ≥-barrier slices' hit condition dissolved by IVT. + have e1 : (univ.filter (fun ω : Fin n → Bool ↦ HitsLevel a ω ∧ a < walkPos ω n)).card + = (univ.filter (fun ω : Fin n → Bool ↦ a < walkPos ω n)).card := by + rw [← Fintype.card_subtype, ← Fintype.card_subtype]; exact Fintype.card_congr + (hitAboveEquiv a ha) + have e2 : (univ.filter (fun ω : Fin n → Bool ↦ HitsLevel a ω ∧ walkPos ω n = a)).card + = (univ.filter (fun ω : Fin n → Bool ↦ walkPos ω n = a)).card := by + rw [← Fintype.card_subtype, ← Fintype.card_subtype]; exact Fintype.card_congr (hitAtEquiv a ha) + have e3 : (univ.filter (fun ω : Fin n → Bool ↦ HitsLevel a ω ∧ walkPos ω n < a)).card + = (univ.filter (fun ω : Fin n → Bool ↦ HitsLevel a ω ∧ a < walkPos ω n)).card := by + rw [← Fintype.card_subtype, ← Fintype.card_subtype]; exact Fintype.card_congr (reflectHitLtGt a) + -- Trichotomy partition of the hit-set by the terminal position. + have hunion : (univ.filter (fun ω : Fin n → Bool ↦ HitsLevel a ω)) + = (univ.filter (fun ω ↦ HitsLevel a ω ∧ a < walkPos ω n)) + ∪ (univ.filter (fun ω ↦ HitsLevel a ω ∧ walkPos ω n = a)) + ∪ (univ.filter (fun ω ↦ HitsLevel a ω ∧ walkPos ω n < a)) := by + ext ω + simp only [mem_filter, mem_union, mem_univ, true_and] + constructor + · intro h + rcases lt_trichotomy (walkPos ω n) a with h1 | h1 | h1 + · exact Or.inr ⟨h, h1⟩ + · exact Or.inl (Or.inr ⟨h, h1⟩) + · exact Or.inl (Or.inl ⟨h, h1⟩) + · rintro ((⟨h, _⟩ | ⟨h, _⟩) | ⟨h, _⟩) <;> exact h + have hd12 : Disjoint (univ.filter (fun ω : Fin n → Bool ↦ HitsLevel a ω ∧ a < walkPos ω n)) + (univ.filter (fun ω ↦ HitsLevel a ω ∧ walkPos ω n = a)) := + disjoint_filter.2 (fun ω _ hp hq ↦ by omega) + have hd3 : Disjoint ((univ.filter (fun ω : Fin n → Bool ↦ HitsLevel a ω ∧ a < walkPos ω n)) + ∪ (univ.filter (fun ω ↦ HitsLevel a ω ∧ walkPos ω n = a))) + (univ.filter (fun ω ↦ HitsLevel a ω ∧ walkPos ω n < a)) := by + rw [disjoint_union_left] + exact ⟨disjoint_filter.2 (fun ω _ hp hq ↦ by omega), + disjoint_filter.2 (fun ω _ hp hq ↦ by omega)⟩ + rw [hunion, card_union_of_disjoint hd3, card_union_of_disjoint hd12, e3] + simp only [e1, e2] + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/Bermudan.lean b/LeanPool/MathFin/Models/Binomial/Bermudan.lean new file mode 100644 index 0000000000..d99b23891b --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/Bermudan.lean @@ -0,0 +1,101 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.American + +/-! +# Bermudan sandwich: European ≤ Bermudan ≤ American + +A Bermudan option's exercise set sits between the European (only at maturity) +and American (any time) exercise sets. As a stopping problem its value is the +maximum over admissible exercise times of the discounted exercise value, and +the maximum is monotone in the exercise set. + +The clean abstract statement: for a value function `v : ι → ℝ` and exercise +sets `Eur ⊆ Berm ⊆ Amer`, `sup_Eur v ≤ sup_Berm v ≤ sup_Amer v`. We give the +discrete-time finite version using `Finset.sup'`, which is what the binomial +tree directly produces. + +## Main results + +* `bermudan_sandwich`: `Eur ⊆ Berm ⊆ Amer ⇒ sup_Eur ≤ sup_Berm ≤ sup_Amer` (`Eur` nonempty) + (both inequalities, via `Finset.sup'_mono`) — the abstract optimal-stopping form. +* `bermudanPrice_mono`: under `BinomialNoArb`, the genuine CRR-tree price `bermudanPrice E` + (`Models/Binomial/Model.lean`, the one recursion with `E = ∅` European and `E = univ` American) is + monotone in the early-exercise step set `E`, as an instance of Snell minimality. +* `binomialPrice_le_bermudanPrice_le_americanPrice`: under `BinomialNoArb`, the sandwich as an + actual discounted-expectation price ordering (not an abstract `sup'` over a free value). + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 11.5; 26.6 +* [Rogers and Williams][RogersWilliams], Vol 2 +* [S. E. Shreve, *Stochastic Calculus for Finance I: The Binomial Asset Pricing Model*][ShreveSCFI], + 4.4 + +## Tags + +Bermudan option, exercise dates, European American ordering, optimal stopping, Snell envelope, +option price bounds, MSC 91G20, MSC 60G40, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Finset + +variable {ι : Type*} {v : ι → ℝ} + +open scoped Classical in +/-- **Bermudan sandwich**: `Eur ⊆ Berm ⊆ Amer` ⇒ the optimal-stopping values +are ordered `European ≤ Bermudan ≤ American` — enlarging the exercise set never +lowers the value. The financial content is the monotonicity of `Finset.sup'` +over the exercise set (`Finset.sup'_mono`); we state the full two-step ordering +directly rather than via single-`sup'_mono` wrapper lemmas. -/ +lemma bermudan_sandwich + {Eur Berm Amer : Finset ι} + (hEB : Eur ⊆ Berm) (hBA : Berm ⊆ Amer) (hEurNE : Eur.Nonempty) + (v : ι → ℝ) : + Eur.sup' hEurNE v ≤ Berm.sup' (hEurNE.mono hEB) v ∧ + Berm.sup' (hEurNE.mono hEB) v ≤ Amer.sup' (hEurNE.mono (hEB.trans hBA)) v := + ⟨sup'_mono v hEB hEurNE, + sup'_mono v hBA (hEurNE.mono hEB)⟩ + +/-! ## The genuine price-tree Bermudan sandwich + +`bermudan_sandwich` above is the abstract optimal-stopping monotonicity on a free +value function. Here is the honest CRR-tree instance: the one recursion `bermudanPrice E`, +with `E = ∅` the European price `binomialPrice` and `E = univ` the American price +`americanPrice`, is monotone in the early-exercise step set `E ⊆ ℕ` — an instance of Snell +minimality — and the sandwich is a genuine price ordering. -/ + +/-- **Monotone in the exercise set**: enlarging the admissible early-exercise set +never lowers the price. The larger-set price is a supermartingale dominating the payoff at +every exercise date of the smaller set, so it dominates the smaller-set price by Snell +minimality (`bermudanPrice_le_of_supermartingale_dominating`). -/ +lemma bermudanPrice_mono {u d r : ℝ} (h : BinomialNoArb u d r) (g : ℝ → ℝ) + {E₁ E₂ : Set ℕ} (hE : E₁ ⊆ E₂) (n : ℕ) (S : ℝ) : + bermudanPrice E₁ u d r g n S ≤ bermudanPrice E₂ u d r g n S := + bermudanPrice_le_of_supermartingale_dominating h E₁ g (bermudanPrice E₂ u d r g) + (fun _ hn S ↦ le_bermudanPrice (hn.imp_right (@hE _)) u d r g S) + (bermudanPrice_supermartingale E₂ u d r g) n S + +/-- **Bermudan sandwich (genuine price-tree form)**: `European ≤ Bermudan ≤ +American` for any admissible early-exercise set `E`, at every step and spot — +the three legs are the actual discounted-expectation CRR recursions, not an +abstract `Finset.sup'` over a free value function. -/ +theorem binomialPrice_le_bermudanPrice_le_americanPrice {u d r : ℝ} + (h : BinomialNoArb u d r) (g : ℝ → ℝ) (E : Set ℕ) (n : ℕ) (S : ℝ) : + binomialPrice u d r g n S ≤ bermudanPrice E u d r g n S ∧ + bermudanPrice E u d r g n S ≤ americanPrice u d r g n S := + ⟨bermudanPrice_mono h g (Set.empty_subset E) n S, + bermudanPrice_mono h g (Set.subset_univ E) n S⟩ + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/Binomial.lean b/LeanPool/MathFin/Models/Binomial/Binomial.lean new file mode 100644 index 0000000000..b985e9b29c --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/Binomial.lean @@ -0,0 +1,225 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.Parity +public import LeanPool.MathFin.Models.Binomial.PathMeasure +public import LeanPool.MathFin.Models.Binomial.MartingaleRepresentation + +/-! +# The contracts priced in the binomial model + +The second model for the instruments of `Contracts/Instruments/Options.lean`, after +`Models/BlackScholes/BlackScholes.lean`. The instruments are the same terms; only the model changes. + +The binomial market with step length `h` is a model map on coin-flip paths `ω : ℕ → Bool`: at +time `t` the underlying is the spot after the `⌊t / h⌋` flips made by then, +`spotPath S₀ u d ⌊t / h⌋ ω`. Unlike `BlackScholes.assets` it is a genuine path, not a terminal +value read at every time, so a path-dependent instrument already has the model it needs. Cash +is discounted at `ρ` per step, and paths are drawn from `coinFlipMeasure q` with +`q = crrUpProb u d ρ`: i.i.d. flips, up with the risk-neutral probability. Everything about the +tree itself (the path measure, the spot's measurability and bound, the CRR sequence) lives in +`MathFin/Binomial/`; this file is only the translation of contracts into it. + +A single cash flow paying `g` of the spot at a maturity `T` that falls on step `N` is worth the +backward-induction price `binomialPrice u d ρ g N S₀` (`value_pay_eq_binomialPrice`); this is +`binomialPrice_eq_integral_coinFlipMeasure`, which writes the tree price as an expectation over +paths. Every fixed-date contract is integrable here, because the spot after finitely many flips +is bounded +(`integrable_pathPV`), so a composed instrument is priced by composition with no integrability +side conditions to prove. + +The value is also a price in the sense of replication. Under no-arbitrage, a European contract's +discounted payoff is, on every path, its value plus the gains of a predictable strategy in the +discounted spot (`pathPV_eq_value_add_gains`). The strategy comes from the tree +(`binomialPrice_replication`, `Models/Binomial/MartingaleRepresentation.lean`). + +## Main definitions + +* `Binomial.assets` — the binomial market with step `h` as a model map. +* `Binomial.discount` — discounting at `ρ` per step. + +## Main results + +* `Binomial.value_pay_eq_binomialPrice` — a European payoff is worth its tree price. +* `Binomial.integrable_pathPV` — every fixed-date contract's discounted payoff is integrable. +* `Binomial.value_europeanCall`, `value_europeanPut`, `value_digitalCall` — each is the tree + price of its payoff. +* `Binomial.value_forward` — under no-arbitrage the forward is worth `S₀ − K e^{−ρN}`. +* `Binomial.value_cappedCall` — the capped call is worth the difference of two call values. +* `Binomial.pathPV_eq_value_add_gains` — a European contract's value is the cost of its hedge: on + every path its discounted payoff is its value plus the gains of a predictable strategy in the + discounted spot. + +## Source + +The layered separation of contract semantics from pricing semantics, and the +framing "the contract is not the model", are due to Paul Bilokon, +*The Contract Is Not the Model: Proof-Carrying Exotic Derivatives and the +Economics of Model Risk* (working paper, 9 August 2026; Mathematical +Finance, Imperial College London), with code at + (Apache-2.0). That paper in +turn builds on the compositional contract-DSL of +Peyton Jones, Eber and Seward (2000) and the certified-contract work of Bahr, +Berthold and Elsman (2015) and Annenkov (2018). + +No code is copied from `lean_contracts`; every definition and proof here is +written for this library. See `docs/specs/2026-08-16-contracts-tower-design.md` +§6 for the full credit line. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [J. C. Cox, S. A. Ross and M. Rubinstein, *Option pricing: a simplified + approach*][CoxRossRubinstein1979] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 12.3 +* [S. E. Shreve, *Stochastic Calculus for Finance I: The Binomial Asset Pricing Model*][ShreveSCFI], + Theorem 1.2.2; ch. 1-2 + +## Tags + +binomial tree, Cox–Ross–Rubinstein, replicating strategy, risk-neutral probability, coin-flip paths, +MSC 91G20, MSC 60G42, JEL G13 +-/ + +@[expose] public section + +open MeasureTheory +open scoped NNReal + +namespace MathFin.Contracts.Binomial + +/-- The binomial market with step length `h` as a model map: at time `t` the underlying is the +spot after the `⌊t / h⌋` flips made by then. -/ +noncomputable def assets (S₀ u d h : ℝ) : Unit → ℝ≥0 → (ℕ → Bool) → ℝ := + fun _ t ω ↦ spotPath S₀ u d ⌊(t : ℝ) / h⌋₊ ω + +/-- Discounting at `ρ` per step of length `h`: a cash flow at time `t` is worth `e^{−ρ t / h}` of +one paid today. -/ +noncomputable def discount (ρ h : ℝ) : ℝ≥0 → ℝ := fun t ↦ Real.exp (-(ρ * (t / h))) + +variable {u d ρ h : ℝ} {q : ℝ≥0} (hq : q ≤ 1) + +/-- **A European payoff is worth its tree price.** Under the law of i.i.d. flips that go up with +the risk-neutral probability `crrUpProb u d ρ`, if a cash flow at `T` pays `g` of the underlying +at `T`, whatever the scenario, and `T` falls on step `N`, its binomial value is the +backward-induction price `binomialPrice u d ρ g N S₀`. -/ +theorem value_pay_eq_binomialPrice (hqcrr : crrUpProb u d ρ = q) (S₀ : ℝ) {T : ℝ≥0} {N : ℕ} + (hTN : (T : ℝ) / h = N) {a : Payoff Unit} {g : ℝ → ℝ} + (hg : ∀ s : Scenario Unit, a.eval s = g (s () T)) : + (Contract.pay T a).value (coinFlipMeasure q hq) (fun t _ ↦ discount ρ h t) (assets S₀ u d h) + = binomialPrice u d ρ g N S₀ := by + rw [Contract.value_pay, binomialPrice_eq_integral_coinFlipMeasure u d ρ g hq hqcrr N S₀] + simp only [hg, scenarioAt, assets, discount, hTN, Nat.floor_natCast] + exact integral_const_mul _ _ + +/-- **Every fixed-date contract is integrable in the binomial model**, under any law of the flips: +the spot after finitely many flips is measurable and bounded (`measurable_spotPath`, +`abs_spotPath_le`), so `Contract.integrable_pathPV_of_bounded` applies. -/ +theorem integrable_pathPV (S₀ u d h : ℝ) (D : ℝ≥0 → ℝ) {c : Contract Unit} (hc : c.FixedDated) : + Integrable (fun ω ↦ c.pathPV D (scenarioAt (assets S₀ u d h) ω)) (coinFlipMeasure q hq) := + Contract.integrable_pathPV_of_bounded D (fun _ _ ↦ measurable_spotPath ..) + (fun _ t ↦ ⟨_, abs_spotPath_le S₀ u d ⌊(t : ℝ) / h⌋₊⟩) hc + +variable (hqcrr : crrUpProb u d ρ = q) (S₀ K : ℝ) {T : ℝ≥0} {N : ℕ} (hTN : (T : ℝ) / h = N) +include hqcrr hTN + +/-- The European call's binomial value is the tree price of `max (S − K) 0`. -/ +theorem value_europeanCall : + (europeanCall K T).value (coinFlipMeasure q hq) (fun t _ ↦ discount ρ h t) (assets S₀ u d h) + = binomialPrice u d ρ (fun S ↦ max (S - K) 0) N S₀ := + value_pay_eq_binomialPrice hq hqcrr S₀ hTN fun _ ↦ rfl + +/-- The European put's binomial value is the tree price of `max (K − S) 0`. -/ +theorem value_europeanPut : + (europeanPut K T).value (coinFlipMeasure q hq) (fun t _ ↦ discount ρ h t) (assets S₀ u d h) + = binomialPrice u d ρ (fun S ↦ max (K - S) 0) N S₀ := + value_pay_eq_binomialPrice hq hqcrr S₀ hTN fun _ ↦ rfl + +/-- The cash-or-nothing digital call's binomial value is the tree price of `𝟙{S > K}`. -/ +theorem value_digitalCall : + (digitalCall K T).value (coinFlipMeasure q hq) (fun t _ ↦ discount ρ h t) (assets S₀ u d h) + = binomialPrice u d ρ (fun S ↦ if K < S then 1 else 0) N S₀ := + value_pay_eq_binomialPrice hq hqcrr S₀ hTN fun _ ↦ rfl + +/-- **The forward's binomial value** is `S₀ − K e^{−ρN}` under no-arbitrage: the discounted spot +is a martingale (`binomialPrice_id`) and cash is discounted at `ρ` per step +(`binomialPrice_const`). -/ +theorem value_forward (hna : BinomialNoArb u d ρ) : + (forward K T).value (coinFlipMeasure q hq) (fun t _ ↦ discount ρ h t) (assets S₀ u d h) + = S₀ - K * Real.exp (-(ρ * N)) := by + rw [forward, value_pay_eq_binomialPrice hq hqcrr S₀ hTN (g := fun S ↦ S + -K) + fun _ ↦ sub_eq_add_neg _ _, + binomialPrice_add u d ρ (fun S ↦ S) (fun _ ↦ -K), binomialPrice_id u d ρ hna, + binomialPrice_const u d ρ _ hna, show -(N : ℝ) * ρ = -(ρ * N) by ring] + ring + +/-- **The capped call's binomial value, by composition**: the difference of two call values. +Unlike its Black–Scholes counterpart it needs no integrability argument, since every fixed-date +contract is integrable in this model (`integrable_pathPV`). -/ +theorem value_cappedCall (K₂ : ℝ) : + (cappedCall K K₂ T).value (coinFlipMeasure q hq) (fun t _ ↦ discount ρ h t) (assets S₀ u d h) + = binomialPrice u d ρ (fun S ↦ max (S - K) 0) N S₀ + - binomialPrice u d ρ (fun S ↦ max (S - K₂) 0) N S₀ := by + rw [cappedCall, Contract.value_both _ _ _ _ _ + (integrable_pathPV hq S₀ u d h _ (c := europeanCall K T) trivial) + (integrable_pathPV hq S₀ u d h _ (c := .scale (-1) (europeanCall K₂ T)) trivial), + Contract.value_scale, + value_europeanCall hq hqcrr S₀ K hTN, value_europeanCall hq hqcrr S₀ K₂ hTN] + ring + +/-- **A European contract's binomial value is the cost of its hedge.** Under no-arbitrage, with +paths drawn under the risk-neutral up-probability and `S₀ ≠ 0`, there is a predictable strategy +`H` (`H_{k+1}` is `ℱₖ`-strongly measurable for `flipFiltration`: it depends only on the first `k` +flips) such that, on every path, the contract's +discounted payoff is its value plus the strategy's gains in the discounted spot +`S_tilde_k = e^{−ρk} S_k`, its `martingaleTransform`: + + `pathPV = value + ∑_{k 0`, `q = crrUpProb u d ρ` and `T / h = N`, for + the European contract `Contract.pay T a` with `a.eval s = g (s () T)` and each `p ∈ (0, 1)`, there + is a bounded predictable strategy `φ` in `horizonSpot N` such that the discounted payoff equals, + almost surely under `horizonMeasure N p`, `Contract.value` under `coinFlipMeasure q` plus the + martingale transform of `φ`. The strategy comes from completeness and is not given in closed form; + only its capital is identified, as the contract's value. + +## References + +* [J. M. Harrison and S. R. Pliska, *Martingales and stochastic integrals in the theory of + continuous trading*][HarrisonPliska1981] +* [S. E. Shreve, *Stochastic Calculus for Finance I: The Binomial Asset Pricing Model*][ShreveSCFI], + Section 5.4 + +## Tags + +complete market, second fundamental theorem, replication, hedging portfolio, +martingale representation, MSC 91G20, MSC 60G42, JEL G13 +-/ + +@[expose] public section + +namespace MathFin.Contracts.Binomial + +open MeasureTheory +open scoped NNReal + +variable {S₀ u d ρ h : ℝ} {q : ℝ≥0} + +/-- **In the complete tree the hedge's capital is the contract's value.** Under no-arbitrage and +`S₀ > 0`, take a European contract that pays `g` of the underlying at a time `T` falling on step +`N` (`T / h = N`). Its discounted payoff, as a claim on the first `N` flips (the path padded by +`false`, `padFlips`), is replicated, almost surely under any real-world law of i.i.d. +`Bernoulli(p)` flips with `0 < p < 1`, by a bounded predictable strategy `φ` in the discounted +spot `horizonSpot N`, from the initial capital `Contract.value` under the risk-neutral flips +`coinFlipMeasure q`, `q = crrUpProb u d ρ`. The strategy is not given in closed form: it comes +from the completeness of the market (`isCompleteMarket_horizonSpot`), and only its capital is +identified. -/ +theorem exists_hedge_eq_value (hS₀ : 0 < S₀) (hna : BinomialNoArb u d ρ) {p : ℝ≥0} (hp0 : 0 < p) + (hp1 : p < 1) (hq : q ≤ 1) (hqcrr : crrUpProb u d ρ = q) {T : ℝ≥0} {N : ℕ} + (hTN : (T : ℝ) / h = N) {a : Payoff Unit} {g : ℝ → ℝ} + (hg : ∀ s : Scenario Unit, a.eval s = g (s () T)) : + ∃ φ : ℕ → (Fin N → Bool) → ℝ, + (∀ t < N, StronglyMeasurable[horizonFiltration N t] (φ (t + 1))) ∧ + (∃ K : ℝ, ∀ n ≤ N, ∀ x, ‖φ n x‖ ≤ K) ∧ + (fun x ↦ (Contract.pay T a).pathPV (discount ρ h) + (scenarioAt (assets S₀ u d h) (padFlips N x))) + =ᵐ[horizonMeasure N p hp1.le] fun x ↦ + (Contract.pay T a).value (coinFlipMeasure q hq) (fun t _ ↦ discount ρ h t) + (assets S₀ u d h) + + martingaleTransform φ (horizonSpot N S₀ u d ρ) N x := by + set H : (Fin N → Bool) → ℝ := fun x ↦ (Contract.pay T a).pathPV (discount ρ h) + (scenarioAt (assets S₀ u d h) (padFlips N x)) with hH + -- the claim is the contract's discounted payoff, a function of the first `N` flips + have hflips (ω : ℕ → Bool) : H (flips N ω) = (Contract.pay T a).pathPV (discount ρ h) + (scenarioAt (assets S₀ u d h) ω) := by + simp only [hH, Contract.pathPV, Contract.cashflows, hg, scenarioAt, assets, hTN, + Nat.floor_natCast, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, add_zero] + rw [pathAdaptedAt_spotPath S₀ u d N (padFlips N (flips N ω)) ω fun i hi ↦ by + simp [padFlips, flips, hi]] + obtain ⟨x, φ, hpred, hbdd, hrep⟩ := isCompleteMarket_horizonSpot hS₀ hna hp0 hp1 H + (by rw [horizonFiltration_horizon]; exact (measurable_of_countable H).stronglyMeasurable) + (let ⟨C, hC⟩ := (Set.finite_range fun x ↦ |H x|).bddAbove; ⟨C, fun ω ↦ hC ⟨ω, rfl⟩⟩) + refine ⟨φ, hpred, hbdd, ?_⟩ + -- the risk-neutral law prices the gains at zero, so the capital is `∫ H` there, the value + have hQ := isEMM_horizonSpot (T := N) hna S₀ hp0 hp1 hq hqcrr + have hQ' := (hQ.integrable_and_integral_gains (martingaleTransform_mem_tradedGains hpred hbdd)) + have hx : (Contract.pay T a).value (coinFlipMeasure q hq) (fun t _ ↦ discount ρ h t) + (assets S₀ u d h) = x := by + have := hQ.isProb + rw [← integral_eq_of_replicates hQ.ac hQ'.1 hQ'.2 hrep, horizonMeasure, + integral_map (measurable_flips N).aemeasurable Integrable.of_finite.aestronglyMeasurable] + exact integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ (hflips ω).symm) + exact hx ▸ hrep + +end MathFin.Contracts.Binomial diff --git a/LeanPool/MathFin/Models/Binomial/BinomialLimit.lean b/LeanPool/MathFin/Models/Binomial/BinomialLimit.lean new file mode 100644 index 0000000000..7966f56d49 --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/BinomialLimit.lean @@ -0,0 +1,82 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.Binomial +public import LeanPool.MathFin.Models.BlackScholes.BlackScholes +public import LeanPool.MathFin.Models.Binomial.CRRClosedForm + +/-! +# One contract in two models: the tree's value converges to the Black–Scholes value + +`europeanCall K T` is one term. Priced in the `n`-step Cox–Ross–Rubinstein tree over `[0, T]` +(`Models/Binomial/Binomial.lean`) it has one value for each `n`; priced in the Black–Scholes +model (`Models/BlackScholes/BlackScholes.lean`) it has another. This file proves the first converges +to the second. + +The tree has step `T / n` (`crrStep`), per-step rate `r T / n` (`crrPerStepRate`), up and down +factors `e^{±σ √(T/n)}` (`crrUp`, `crrDown`), and flips that go up with probability +`crrProb r σ T n`. That probability is in `[0, 1]` for every `n` once `|r| √T < σ` +(`binomialNoArb_crr`, `crrProb_mem_Icc`), which is the one hypothesis added to the +Black–Scholes ones. + +Nothing about the limit is proved here. Each tree value is the tree price +(`Binomial.value_europeanCall`), and the tree prices converge to the Black–Scholes closed form +(`binomialPrice_call_tendsto_bs_closed`, proved in `Models/Binomial/CRRCharFun.lean` and +`Models/Binomial/CRRClosedForm.lean`). That closed form is the Black–Scholes value of the same +contract (`BlackScholes.value_europeanCall`). This file only composes the three. + +## Main results + +* `tendsto_binomial_value_europeanCall` — the call's value in the `n`-step CRR tree tends to its + Black–Scholes value. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [J. C. Cox, S. A. Ross and M. Rubinstein, *Option pricing: a simplified + approach*][CoxRossRubinstein1979] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], ch. 13 + +## Tags + +binomial convergence, Cox–Ross–Rubinstein limit, Black–Scholes limit, tree approximation, MSC 91G60, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +open MeasureTheory Filter +open scoped NNReal Topology + +namespace MathFin.Contracts + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- **The tree's value of a European call converges to its Black–Scholes value.** The contract +`europeanCall K T` priced in the `n`-step CRR tree over `[0, T]` tends, as `n → ∞`, to the same +contract priced in the Black–Scholes model, provided the volatility dominates the drift over the +horizon (`|r| √T < σ`), which makes every tree with `n ≥ 1` arbitrage-free. -/ +theorem tendsto_binomial_value_europeanCall {Q : Measure Ω} [IsProbabilityMeasure Q] + {S₀ K r σ : ℝ} {T : ℝ≥0} {Z : Ω → ℝ} (hbs : BSCallHyp Q S₀ K r σ T Z) + (hrT : |r| * Real.sqrt T < σ) : + Tendsto (fun n : ℕ ↦ (europeanCall K T).value + (coinFlipMeasure (crrProb r σ T n).toNNReal (Real.toNNReal_le_one.mpr + (crrProb_mem_Icc (fun _ hn ↦ binomialNoArb_crr hbs.T_pos hrT hn) n).2)) + (fun t _ ↦ Binomial.discount (crrPerStepRate r T n) (crrStep T n) t) + (Binomial.assets S₀ (crrUp σ T n) (crrDown σ T n) (crrStep T n))) atTop + (𝓝 ((europeanCall K T).value Q (fun _ _ ↦ Real.exp (-r * T)) + (BlackScholes.assets S₀ r σ T Z))) := by + have hna (n : ℕ) (hn : 0 < n) := binomialNoArb_crr hbs.T_pos hrT hn + have hTN (n : ℕ) : (T : ℝ) / crrStep T n = n := div_div_cancel₀ hbs.T_pos.ne' + rw [BlackScholes.value_europeanCall hbs, neg_mul] + exact (binomialPrice_call_tendsto_bs_closed hbs.σ_pos hbs.T_pos hbs.S_0_pos hbs.K_pos hna).congr + fun n ↦ (Binomial.value_europeanCall _ + (Real.coe_toNNReal _ (crrProb_mem_Icc hna n).1).symm S₀ K (hTN n)).symm + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Models/Binomial/CRRCharFun.lean b/LeanPool/MathFin/Models/Binomial/CRRCharFun.lean new file mode 100644 index 0000000000..ec726fa901 --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/CRRCharFun.lean @@ -0,0 +1,594 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.DriftLimit +public import LeanPool.MathFin.Models.Binomial.Binomial +public import Mathlib.Algebra.Order.Archimedean.Real.Hom +public import Mathlib.Analysis.CStarAlgebra.Classes +public import Mathlib.MeasureTheory.Measure.LevyConvergence +public import Mathlib.Probability.Distributions.Gaussian.Real +public import Mathlib.Topology.UniformSpace.Uniformizable + +/-! +# CRR characteristic-function convergence (the CLT heart of CRR → Black–Scholes) + +The deterministic-analytic correspondence in `CRRConvergence.lean` / +`DriftLimit.lean` (`crrProb_tendsto_half`, `crr_drift_limit_n`) pins down the +mean and variance of one CRR log-return increment. This file converts those +moment limits into the **distributional** statement that drives CRR → BS: the +characteristic function of the `n`-step risk-neutral log-return, + + `φₙ(t)ⁿ` where `φₙ(t) = pₙ e^{i (σ√Δt) t} + (1−pₙ) e^{i(−σ√Δt) t}`, + +converges pointwise to the Gaussian characteristic function +`exp(i t (r − σ²/2) T − ½ t² σ² T)`, i.e. the charFun of +`N((r − σ²/2)T, σ²T)`. + +The crux is `crr_charFun_pow_tendsto`. The argument: + +* Since the per-step value `±σ√Δt` is real, `φₙ(t) = cos θₙ + i (2pₙ−1) sin θₙ` + with `θₙ = σ √(T/n) · t` real (`crrStepCharFun_eq`). +* `n (φₙ − 1) → i t (r−σ²/2)T − ½ t²σ²T =: L`, splitting real/imag parts: + - real: `n (cos θₙ − 1) = ((cos θₙ−1)/θₙ²)·(n θₙ²) → (−½)·σ²t²T`, since + `n θₙ² = σ² t² T` exactly and `(cos u−1)/u² → −½`; + - imag: `n (2pₙ−1) sin θₙ = [n(2pₙ−1)σ√(T/n)]·t·(sin θₙ/θₙ) → (r−σ²/2)T·t`, + feeding `crr_drift_limit_n` and `sin u/u → 1`. +* `φₙ(t)ⁿ = (1 + (φₙ−1))ⁿ → exp L` via Mathlib's + `Complex.tendsto_one_add_pow_exp_of_tendsto`. + +Both real trig limits reduce to `sin u / u → 1` (the half-angle identity +`1 − cos u = 2 sin²(u/2)` handles the cosine). + +## Relationship to Mathlib's `Probability/CentralLimitTheorem.lean` + +Mathlib's CLT (`ProbabilityTheory.tendstoInDistribution_inv_sqrt_mul_sum_sub`) is the +*classic fixed-i.i.d.* one-dimensional theorem: for a single fixed law shared by every +`Xₖ` (`iIndepFun` + `IdentDistrib (X i) (X 0)`), `(√n)⁻¹·∑ₖ(Xₖ − μ) ⇒ N(0, v)`. CRR is a +**triangular array** — the step law `crrStepMeasure r σ T n` *depends on `n`* (support +`±σ√(T/n)`, probability `pₙ` carrying the risk-neutral drift), so it is not the sum of a +fixed i.i.d. sequence and the upstream CLT does not apply. Mathlib (pin `c5ea003`) has no +triangular-array / Lindeberg CLT and no measure-convolution power, so this CRR limit is a +genuinely distinct result, not a re-proof. It *does* consume the shared characteristic- +function layer the upstream CLT is itself built on: `charFun`, `charFun_conv`, +`charFun_dirac`, `charFun_gaussianReal`, Lévy continuity +(`ProbabilityMeasure.tendsto_of_tendsto_charFun`), and `tendsto_one_add_pow_exp_of_tendsto` +(the same `(1+aₙ)ⁿ → exp` lemma Mathlib's own `Poisson/PoissonLimitThm` uses). + +## Main definitions + +* `crrStepCharFun`: the characteristic function of one CRR risk-neutral log-return increment. +* `convPow`: the `n`-fold additive convolution power of a measure on `ℝ`. +* `crrStepMeasure`: the law of one CRR risk-neutral log-return increment, mass `pₙ` at `+σ√Δt` + and `1 − pₙ` at `−σ√Δt`. +* `crrRowProbMeasure`: the `n`-step CRR log-return law, the `n`-fold convolution of + `crrStepMeasure`, as a `ProbabilityMeasure`. +* `bsLimitProbMeasure`: the Gaussian `N((r − σ²/2)T, σ²T)` as a `ProbabilityMeasure`. + +## Main results + +* `crr_charFun_pow_tendsto`: for `σ, T > 0`, `crrStepCharFun r σ T n t ^ n` converges to + `exp(i t (r − σ²/2) T − ½ t² σ² T)`; `crr_charFun_pow_tendsto_gaussian` states the limit as + the characteristic function of the Gaussian. +* `charFun_convPow`: the characteristic function of `convPow ν n` is the `n`-th power of that + of `ν`. +* `crr_tendsto_gaussian_inDistribution`: for `σ, T > 0` and `crrProb` a probability for every + `n`, the `n`-step CRR log-return laws converge weakly to the Gaussian + `N((r − σ²/2)T, σ²T)`. +* `binomialPrice_eq_integral_convPow`: for `0 ≤ crrProb ≤ 1` and `S > 0`, the `k`-step binomial + price of a measurable payoff bounded on `(0, ∞)` is the discounted integral of the payoff at + `S · eˣ` against `convPow (crrStepMeasure …) k`. +* `binomialPrice_call_tendsto_bs`: for `σ, T, S₀ > 0` and no-arbitrage at every step, the `n`-step + CRR call price tends to `e^{−rT} · E[(K − S₀eˣ)₊] + (S₀ − K e^{−rT})`, the expectation under + `N((r − σ²/2)T, σ²T)`. + +## References + +* [J. C. Cox, S. A. Ross and M. Rubinstein, *Option pricing: a simplified + approach*][CoxRossRubinstein1979] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 21.1 +* [S. E. Shreve, *Stochastic Calculus for Finance I: The Binomial Asset Pricing Model*][ShreveSCFI], + 3.2 + +## Tags + +Cox–Ross–Rubinstein, characteristic function, Lévy continuity, central limit theorem, +binomial to Black–Scholes, triangular array, MSC 91G20, MSC 60F05, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Filter Complex +open scoped Topology + +/-! ### Real second-order trig limits at `0` -/ + +/-- `sin u / u → 1` as `u → 0` (`u ≠ 0`): the value at `0` of Mathlib's continuous +`Real.sinc` (`sinc u = sin u / u` off `0`, `sinc 0 = 1`). -/ +lemma tendsto_sin_div_one : + Tendsto (fun u : ℝ ↦ Real.sin u / u) (𝓝[≠] 0) (𝓝 1) := by + have h : Tendsto Real.sinc (𝓝[≠] (0 : ℝ)) (𝓝 (Real.sinc 0)) := + (Real.continuous_sinc.tendsto 0).mono_left nhdsWithin_le_nhds + rw [Real.sinc_zero] at h + refine h.congr' ?_ + filter_upwards [self_mem_nhdsWithin] with u hu + exact Real.sinc_of_ne_zero hu + +/-- `(1 − cos u)/u² → 1/2` as `u → 0` (`u ≠ 0`), via the half-angle identity +`1 − cos u = 2 sin²(u/2)` and `sin v / v → 1`. -/ +lemma tendsto_one_sub_cos_div_sq : + Tendsto (fun u : ℝ ↦ (1 - Real.cos u) / u ^ 2) (𝓝[≠] 0) (𝓝 (1 / 2)) := by + have h_half : Tendsto (fun u : ℝ ↦ u / 2) (𝓝[≠] 0) (𝓝[≠] 0) := by + refine tendsto_nhdsWithin_iff.mpr ⟨?_, ?_⟩ + · have h0 : Tendsto (fun u : ℝ ↦ u / 2) (𝓝 0) (𝓝 0) := by + simpa using (continuous_id.div_const (2 : ℝ)).tendsto 0 + exact h0.mono_left nhdsWithin_le_nhds + · filter_upwards [self_mem_nhdsWithin] with u hu + exact div_ne_zero hu (by norm_num) + have h_s : Tendsto (fun u : ℝ ↦ Real.sin (u / 2) / (u / 2)) (𝓝[≠] 0) (𝓝 1) := + tendsto_sin_div_one.comp h_half + have h_sq : Tendsto (fun u : ℝ ↦ (1 / 2) * (Real.sin (u / 2) / (u / 2)) ^ 2) + (𝓝[≠] 0) (𝓝 ((1 / 2) * 1 ^ 2)) := (h_s.pow 2).const_mul (1 / 2) + rw [show ((1 : ℝ) / 2 * 1 ^ 2) = 1 / 2 from by norm_num] at h_sq + refine h_sq.congr' ?_ + filter_upwards [self_mem_nhdsWithin] with u hu + have hu_ne : u ≠ 0 := hu + have hid : 1 - Real.cos u = 2 * Real.sin (u / 2) ^ 2 := by + have h2 : Real.cos u = 2 * Real.cos (u / 2) ^ 2 - 1 := by + have := Real.cos_two_mul (u / 2) + rwa [show 2 * (u / 2) = u from by ring] at this + have h3 : Real.sin (u / 2) ^ 2 + Real.cos (u / 2) ^ 2 = 1 := Real.sin_sq_add_cos_sq (u / 2) + nlinarith [h2, h3] + rw [hid] + have h2ne : u / 2 ≠ 0 := div_ne_zero hu_ne (by norm_num) + field_simp + +/-! ### The per-step CRR characteristic function -/ + +/-- The characteristic function of one CRR risk-neutral log-return increment, +evaluated at `t`: `φₙ(t) = pₙ e^{i (σ√Δt) t} + (1−pₙ) e^{i (−σ√Δt) t}`, +with `Δt = T/n` and `pₙ = crrProb`. -/ +noncomputable def crrStepCharFun (r σ T : ℝ) (n : ℕ) (t : ℝ) : ℂ := + (crrProb r σ T n : ℂ) * Complex.exp (I * ↑(σ * Real.sqrt (T / n) * t)) + + (1 - (crrProb r σ T n : ℂ)) * Complex.exp (I * ↑(-(σ * Real.sqrt (T / n)) * t)) + +/-- **Real/imaginary form of the per-step charFun**: since the increment takes +the real values `±σ√Δt`, `φₙ(t) = cos θₙ + i (2pₙ−1) sin θₙ` with +`θₙ = σ √(T/n) · t`. -/ +lemma crrStepCharFun_eq (r σ T : ℝ) (n : ℕ) (t : ℝ) : + crrStepCharFun r σ T n t + = ↑(Real.cos (σ * Real.sqrt (T / n) * t)) + + ↑((2 * crrProb r σ T n - 1) * Real.sin (σ * Real.sqrt (T / n) * t)) * I := by + unfold crrStepCharFun + rw [mul_comm I (↑(σ * Real.sqrt (T / n) * t)), + mul_comm I (↑(-(σ * Real.sqrt (T / n)) * t)), + Complex.exp_mul_I, Complex.exp_mul_I, ← Complex.ofReal_cos, ← Complex.ofReal_cos, + ← Complex.ofReal_sin, ← Complex.ofReal_sin, + show (-(σ * Real.sqrt (T / n)) * t) = -(σ * Real.sqrt (T / n) * t) from by ring, + Real.cos_neg, Real.sin_neg] + push_cast + ring + +/-! ### The two scalar limits feeding the exponent `L` -/ + +variable {σ T r : ℝ} + +/-- For `t ≠ 0`, the rescaled angle `θₙ = σ √(T/n) · t` tends to `0` through +nonzero values — so it can feed the punctured-neighbourhood trig limits. -/ +lemma tendsto_crrAngle_punctured (hσ : 0 < σ) (hT : 0 < T) {t : ℝ} (ht : t ≠ 0) : + Tendsto (fun n : ℕ ↦ σ * Real.sqrt (T / n) * t) atTop (𝓝[≠] 0) := by + refine tendsto_nhdsWithin_iff.mpr ⟨?_, ?_⟩ + · have h0 : Tendsto (fun n : ℕ ↦ Real.sqrt (T / n)) atTop (𝓝 0) := by + simpa [crrStep] using tendsto_sqrt_crrStep_zero T + have h1 : Tendsto (fun n : ℕ ↦ σ * Real.sqrt (T / n) * t) atTop (𝓝 (σ * 0 * t)) := + (h0.const_mul σ).mul_const t + simpa using h1 + · filter_upwards [Filter.eventually_ge_atTop 1] with n hn + have hn_pos : (0 : ℝ) < n := by exact_mod_cast hn + have h_sqrt_pos : 0 < Real.sqrt (T / n) := Real.sqrt_pos.mpr (div_pos hT hn_pos) + exact mul_ne_zero (mul_ne_zero hσ.ne' h_sqrt_pos.ne') ht + +/-- **Real part of `n(φₙ−1)`**: `n (cos θₙ − 1) → −½ σ² t² T`, with +`θₙ = σ√(T/n) t`. Uses `n θₙ² = σ² t² T` (exact, `n ≥ 1`) and `(1−cos u)/u² → ½`. -/ +lemma tendsto_n_mul_cos_sub_one (hσ : 0 < σ) (hT : 0 < T) {t : ℝ} (ht : t ≠ 0) : + Tendsto (fun n : ℕ ↦ (n : ℝ) * (Real.cos (σ * Real.sqrt (T / n) * t) - 1)) + atTop (𝓝 (-(σ ^ 2 * t ^ 2 * T) / 2)) := by + have hθ := tendsto_crrAngle_punctured hσ hT ht + have h_cos : Tendsto (fun n : ℕ ↦ + (1 - Real.cos (σ * Real.sqrt (T / n) * t)) / (σ * Real.sqrt (T / n) * t) ^ 2) + atTop (𝓝 (1 / 2)) := tendsto_one_sub_cos_div_sq.comp hθ + have h_main : Tendsto (fun n : ℕ ↦ + -((1 - Real.cos (σ * Real.sqrt (T / n) * t)) / (σ * Real.sqrt (T / n) * t) ^ 2 + * (σ ^ 2 * t ^ 2 * T))) + atTop (𝓝 (-(1 / 2 * (σ ^ 2 * t ^ 2 * T)))) := (h_cos.mul_const (σ ^ 2 * t ^ 2 * T)).neg + rw [show -(1 / 2 * (σ ^ 2 * t ^ 2 * T)) = -(σ ^ 2 * t ^ 2 * T) / 2 from by ring] at h_main + refine h_main.congr' ?_ + filter_upwards [Filter.eventually_ge_atTop 1] with n hn + have hn_pos : (0 : ℝ) < n := by exact_mod_cast hn + have hn_ne : (n : ℝ) ≠ 0 := hn_pos.ne' + have h_step_pos : 0 < T / n := div_pos hT hn_pos + have h_sqrt_sq : Real.sqrt (T / n) ^ 2 = T / n := Real.sq_sqrt h_step_pos.le + have hθsq : (σ * Real.sqrt (T / n) * t) ^ 2 = σ ^ 2 * (T / n) * t ^ 2 := by + rw [mul_pow, mul_pow, h_sqrt_sq] + rw [hθsq] + field_simp + ring + +/-- **Imaginary part of `n(φₙ−1)`**: `n (2pₙ−1) sin θₙ → (r − σ²/2) T t`, with +`θₙ = σ√(T/n) t`. Feeds `crr_drift_limit_n` and `sin u/u → 1`. -/ +private lemma tendsto_n_mul_two_p_sub_one_mul_sin + (hσ : 0 < σ) (hT : 0 < T) {t : ℝ} (ht : t ≠ 0) : + Tendsto (fun n : ℕ ↦ + (n : ℝ) * (2 * crrProb r σ T n - 1) * Real.sin (σ * Real.sqrt (T / n) * t)) + atTop (𝓝 ((r - σ ^ 2 / 2) * T * t)) := by + have hθ := tendsto_crrAngle_punctured hσ hT ht + have h_sin : Tendsto (fun n : ℕ ↦ + Real.sin (σ * Real.sqrt (T / n) * t) / (σ * Real.sqrt (T / n) * t)) + atTop (𝓝 1) := tendsto_sin_div_one.comp hθ + have h_dt : Tendsto (fun n : ℕ ↦ + (n : ℝ) * (2 * crrProb r σ T n - 1) * σ * Real.sqrt (T / n) * t) + atTop (𝓝 ((r - σ ^ 2 / 2) * T * t)) := (crr_drift_limit_n (r := r) hσ hT).mul_const t + have h_prod := h_dt.mul h_sin + rw [mul_one] at h_prod + refine h_prod.congr' ?_ + filter_upwards [Filter.eventually_ge_atTop 1] with n hn + have hn_pos : (0 : ℝ) < n := by exact_mod_cast hn + have h_sqrt_pos : 0 < Real.sqrt (T / n) := Real.sqrt_pos.mpr (div_pos hT hn_pos) + have hθ_ne : σ * Real.sqrt (T / n) * t ≠ 0 := + mul_ne_zero (mul_ne_zero hσ.ne' h_sqrt_pos.ne') ht + field_simp + +/-! ### The characteristic-function convergence -/ + +/-- **CRR → BS characteristic-function convergence.** For `σ, T > 0`, the +characteristic function of the `n`-step CRR risk-neutral log-return, +`crrStepCharFun r σ T n t ^ n`, converges to the Gaussian characteristic +function `exp(i t (r − σ²/2) T − ½ t² σ² T)` — the charFun of +`N((r − σ²/2) T, σ² T)`. This is the distributional heart of the +Cox–Ross–Rubinstein → Black–Scholes convergence theorem. + +The increment is real-valued (`±σ√Δt`), so `φₙ = cos θₙ + i (2pₙ−1) sin θₙ`; +`n (φₙ − 1) → L := i t (r−σ²/2)T − ½ t²σ²T` (real and imaginary parts via the +two scalar limits above), and `φₙⁿ = (1 + (φₙ−1))ⁿ → exp L` by Mathlib's +`Complex.tendsto_one_add_pow_exp_of_tendsto`. -/ +theorem crr_charFun_pow_tendsto (hσ : 0 < σ) (hT : 0 < T) (t : ℝ) : + Tendsto (fun n : ℕ ↦ crrStepCharFun r σ T n t ^ n) atTop + (𝓝 (Complex.exp (I * Complex.ofReal ((r - σ ^ 2 / 2) * T) * Complex.ofReal t + - Complex.ofReal (σ ^ 2 * T) * Complex.ofReal t ^ 2 / 2))) := by + rcases eq_or_ne t 0 with rfl | ht + · -- `t = 0`: `φₙ = 1` and the exponent is `0`, so both sides are the constant `1`. + have hφ1 : ∀ n : ℕ, crrStepCharFun r σ T n 0 = 1 := by + intro n; rw [crrStepCharFun_eq]; simp + have h0 : I * Complex.ofReal ((r - σ ^ 2 / 2) * T) * Complex.ofReal (0 : ℝ) + - Complex.ofReal (σ ^ 2 * T) * Complex.ofReal (0 : ℝ) ^ 2 / 2 = 0 := by simp + simp only [hφ1, one_pow, h0, Complex.exp_zero] + exact tendsto_const_nhds + · -- `t ≠ 0`: `n (φₙ − 1) → L := i t (r−σ²/2)T − ½ t²σ²T`, then `(1 + (φₙ−1))ⁿ → exp L`. + have hA := tendsto_n_mul_cos_sub_one hσ hT ht + have hB := tendsto_n_mul_two_p_sub_one_mul_sin (r := r) hσ hT ht + have h_ng : Tendsto (fun n : ℕ ↦ (n : ℂ) * (crrStepCharFun r σ T n t - 1)) atTop + (𝓝 (I * Complex.ofReal ((r - σ ^ 2 / 2) * T) * Complex.ofReal t + - Complex.ofReal (σ ^ 2 * T) * Complex.ofReal t ^ 2 / 2)) := by + have h_sum := ((Complex.continuous_ofReal.tendsto _).comp hA).add + (((Complex.continuous_ofReal.tendsto _).comp hB).mul_const I) + rw [show (Complex.ofReal (-(σ ^ 2 * t ^ 2 * T) / 2) + + Complex.ofReal ((r - σ ^ 2 / 2) * T * t) * I) + = I * Complex.ofReal ((r - σ ^ 2 / 2) * T) * Complex.ofReal t + - Complex.ofReal (σ ^ 2 * T) * Complex.ofReal t ^ 2 / 2 + from by push_cast; ring] at h_sum + refine h_sum.congr' (Eventually.of_forall fun n ↦ ?_) + simp only [Function.comp_apply, crrStepCharFun_eq] + push_cast [-Complex.ofReal_cos, -Complex.ofReal_sin] + ring + have h_pow := Complex.tendsto_one_add_pow_exp_of_tendsto + (g := fun n ↦ crrStepCharFun r σ T n t - 1) h_ng + refine h_pow.congr (fun n ↦ ?_) + show (1 + (crrStepCharFun r σ T n t - 1)) ^ n = crrStepCharFun r σ T n t ^ n + rw [show (1 : ℂ) + (crrStepCharFun r σ T n t - 1) = crrStepCharFun r σ T n t from by ring] + +/-- **CRR → BS, Gaussian-characteristic-function form.** The same limit as +`crr_charFun_pow_tendsto`, with the target written explicitly as the characteristic +function of the Black–Scholes Gaussian `N((r − σ²/2)T, σ²T)` +(`MeasureTheory.charFun (gaussianReal ((r−σ²/2)T) (σ²T))`). + +This is the precise hypothesis Lévy's continuity theorem consumes: once the `n`-step +CRR log-return law is identified as the `n`-fold convolution of the step law — whose +characteristic function is `crrStepCharFun`, so the convolution's is `crrStepCharFun ^ n` +(`MeasureTheory.charFun_conv`) — `ProbabilityMeasure.tendsto_of_tendsto_charFun` +upgrades this pointwise charFun convergence to convergence in distribution, i.e. the +CRR risk-neutral log-return converges in law to the Black–Scholes normal. -/ +theorem crr_charFun_pow_tendsto_gaussian (hσ : 0 < σ) (hT : 0 < T) (t : ℝ) : + Tendsto (fun n : ℕ ↦ crrStepCharFun r σ T n t ^ n) atTop + (𝓝 (MeasureTheory.charFun + (ProbabilityTheory.gaussianReal ((r - σ ^ 2 / 2) * T) (σ ^ 2 * T).toNNReal) t)) := by + have hgauss : MeasureTheory.charFun + (ProbabilityTheory.gaussianReal ((r - σ ^ 2 / 2) * T) (σ ^ 2 * T).toNNReal) t + = Complex.exp (I * Complex.ofReal ((r - σ ^ 2 / 2) * T) * Complex.ofReal t + - Complex.ofReal (σ ^ 2 * T) * Complex.ofReal t ^ 2 / 2) := by + rw [ProbabilityTheory.charFun_gaussianReal, + Real.coe_toNNReal (σ ^ 2 * T) (mul_nonneg (sq_nonneg σ) hT.le)] + congr 1 + push_cast + ring + rw [hgauss] + exact crr_charFun_pow_tendsto hσ hT t + +/-! ### Convergence in distribution to the Black–Scholes Gaussian -/ + +section Distributional + +open MeasureTheory ProbabilityTheory + +/-- `n`-fold additive convolution of `ν` with itself: `convPow ν 0 = δ₀`, +`convPow ν (n+1) = convPow ν n ∗ ν`. This is the law of `∑_{k < n} Xₖ` for +`Xₖ` i.i.d. `∼ ν` — in particular the law of an `n`-step sum of i.i.d. increments. -/ +noncomputable def convPow (ν : Measure ℝ) : ℕ → Measure ℝ + | 0 => Measure.dirac 0 + | n + 1 => convPow ν n ∗ ν + +/-- A convolution power of a probability measure is a probability measure. -/ +lemma convPow_isProbabilityMeasure (ν : Measure ℝ) [IsProbabilityMeasure ν] : + ∀ n, IsProbabilityMeasure (convPow ν n) + | 0 => by unfold convPow; infer_instance + | n + 1 => by + unfold convPow + have := convPow_isProbabilityMeasure ν n + infer_instance + +/-- **The characteristic function of an `n`-fold convolution is the `n`-th power** +of the characteristic function — the measure-level statement that the charFun of a +sum of `n` i.i.d. variables is `(charFun)ⁿ`. -/ +lemma charFun_convPow (ν : Measure ℝ) [IsProbabilityMeasure ν] (n : ℕ) (t : ℝ) : + charFun (convPow ν n) t = (charFun ν t) ^ n := by + induction n with + | zero => simp [convPow, charFun_dirac] + | succ k ih => + have := convPow_isProbabilityMeasure ν k + rw [convPow, charFun_conv, ih, pow_succ] + +/-- The law of one CRR risk-neutral log-return increment: mass `pₙ` at the up-move +`+σ√Δt` and `1−pₙ` at the down-move `−σ√Δt` (`pₙ = crrProb`, `Δt = T/n`). -/ +noncomputable def crrStepMeasure (r σ T : ℝ) (n : ℕ) : Measure ℝ := + ENNReal.ofReal (crrProb r σ T n) • Measure.dirac (σ * Real.sqrt (T / n)) + + ENNReal.ofReal (1 - crrProb r σ T n) • Measure.dirac (-(σ * Real.sqrt (T / n))) + +/-- `crrStepMeasure` is a probability measure exactly when the step is arbitrage-free +(`0 ≤ pₙ ≤ 1`). -/ +lemma isProbabilityMeasure_crrStepMeasure {r σ T : ℝ} {n : ℕ} + (hp0 : 0 ≤ crrProb r σ T n) (hp1 : crrProb r σ T n ≤ 1) : + IsProbabilityMeasure (crrStepMeasure r σ T n) := by + refine ⟨?_⟩ + unfold crrStepMeasure + simp only [FunLike.coe_add, FunLike.coe_smul, Pi.add_apply, Pi.smul_apply, smul_eq_mul, + measure_univ, mul_one] + rw [← ENNReal.ofReal_add hp0 (by linarith), show crrProb r σ T n + (1 - crrProb r σ T n) = 1 + from by ring, ENNReal.ofReal_one] + +/-- **`crrStepCharFun` is the characteristic function of `crrStepMeasure`** (the +actual CRR per-step log-return law), under no-arbitrage `0 ≤ pₙ ≤ 1`. -/ +lemma charFun_crrStepMeasure {r σ T : ℝ} {n : ℕ} (t : ℝ) + (hp0 : 0 ≤ crrProb r σ T n) (hp1 : crrProb r σ T n ≤ 1) : + charFun (crrStepMeasure r σ T n) t = crrStepCharFun r σ T n t := by + unfold crrStepMeasure + rw [charFun_apply, + integral_add_measure ((integrable_dirac (by finiteness)).smul_measure (by finiteness)) + ((integrable_dirac (by finiteness)).smul_measure (by finiteness)), + integral_smul_measure, integral_smul_measure, integral_dirac, integral_dirac, + ENNReal.toReal_ofReal hp0, ENNReal.toReal_ofReal (by linarith)] + unfold crrStepCharFun + simp only [RCLike.inner_apply', conj_trivial, Complex.real_smul, mul_comm Complex.I] + push_cast + ring + +/-- The `n`-step CRR risk-neutral log-return law (the `n`-fold convolution of the +per-step law), bundled as a `ProbabilityMeasure` — needs no-arbitrage `0 ≤ pₙ ≤ 1`. -/ +noncomputable def crrRowProbMeasure (r σ T : ℝ) (n : ℕ) + (h0 : 0 ≤ crrProb r σ T n) (h1 : crrProb r σ T n ≤ 1) : ProbabilityMeasure ℝ := + haveI := isProbabilityMeasure_crrStepMeasure h0 h1 + haveI := convPow_isProbabilityMeasure (crrStepMeasure r σ T n) n + ⟨convPow (crrStepMeasure r σ T n) n, inferInstance⟩ + +/-- The Black–Scholes limiting normal `N((r−σ²/2)T, σ²T)`, bundled as a +`ProbabilityMeasure`. -/ +noncomputable def bsLimitProbMeasure (r σ T : ℝ) : ProbabilityMeasure ℝ := + ⟨gaussianReal ((r - σ ^ 2 / 2) * T) (σ ^ 2 * T).toNNReal, inferInstance⟩ + +/-- **Cox–Ross–Rubinstein → Black–Scholes, convergence in distribution.** Under +no-arbitrage at every step (`0 ≤ pₙ ≤ 1`), the law of the `n`-step CRR risk-neutral +log-return converges weakly to the Black–Scholes normal `N((r − σ²/2)T, σ²T)`. + +This is the genuine distributional CLT for the binomial tree: the charFun-power +convergence `crr_charFun_pow_tendsto_gaussian` is upgraded to weak convergence of +probability measures by Lévy's continuity theorem +(`ProbabilityMeasure.tendsto_of_tendsto_charFun`), using +`charFun (convPow ν n) = (charFun ν)ⁿ` and `charFun (crrStepMeasure) = crrStepCharFun`. -/ +theorem crr_tendsto_gaussian_inDistribution {r σ T : ℝ} (hσ : 0 < σ) (hT : 0 < T) + (hp : ∀ n, 0 ≤ crrProb r σ T n ∧ crrProb r σ T n ≤ 1) : + Tendsto (fun n : ℕ ↦ crrRowProbMeasure r σ T n (hp n).1 (hp n).2) atTop + (𝓝 (bsLimitProbMeasure r σ T)) := by + refine ProbabilityMeasure.tendsto_of_tendsto_charFun (fun t ↦ ?_) + have heq : (fun n : ℕ ↦ charFun (convPow (crrStepMeasure r σ T n) n) t) + = (fun n ↦ crrStepCharFun r σ T n t ^ n) := by + funext n + have := isProbabilityMeasure_crrStepMeasure (hp n).1 (hp n).2 + rw [charFun_convPow, charFun_crrStepMeasure t (hp n).1 (hp n).2] + change Tendsto (fun n : ℕ ↦ charFun (convPow (crrStepMeasure r σ T n) n) t) atTop + (𝓝 (charFun (gaussianReal ((r - σ ^ 2 / 2) * T) (σ ^ 2 * T).toNNReal) t)) + rw [heq] + exact crr_charFun_pow_tendsto_gaussian hσ hT t + +/-! ### CRR → BS price convergence (`binomialPrice → bs_call_price`) -/ + +/-- A measurable payoff bounded on `(0,∞)`, composed with `x ↦ a·eˣ` for `a > 0` +(so the argument stays positive), is integrable against any finite measure. -/ +lemma integrable_comp_exp_of_bdd {μ : Measure ℝ} [IsFiniteMeasure μ] {g : ℝ → ℝ} + (hg : Measurable g) {C : ℝ} {a : ℝ} (ha : 0 < a) (hC : ∀ y, 0 < y → |g y| ≤ C) : + Integrable (fun x ↦ g (a * Real.exp x)) μ := + Integrable.of_bound ((hg.comp (by fun_prop)).aestronglyMeasurable) C + (ae_of_all _ fun x ↦ by rw [Real.norm_eq_abs]; exact hC _ (mul_pos ha (Real.exp_pos x))) + +/-- **Two-point integral against the CRR step law** (real-valued): for any `h`, +`∫ h ∂(crrStepMeasure) = pₙ·h(σ√Δt) + (1−pₙ)·h(−σ√Δt)` under no-arbitrage `0 ≤ pₙ ≤ 1`. -/ +lemma integral_crrStepMeasure {r σ T : ℝ} {n : ℕ} + (hp0 : 0 ≤ crrProb r σ T n) (hp1 : crrProb r σ T n ≤ 1) (h : ℝ → ℝ) : + ∫ z, h z ∂(crrStepMeasure r σ T n) + = crrProb r σ T n * h (σ * Real.sqrt (T / n)) + + (1 - crrProb r σ T n) * h (-(σ * Real.sqrt (T / n))) := by + unfold crrStepMeasure + rw [integral_add_measure ((integrable_dirac (by finiteness)).smul_measure (by finiteness)) + ((integrable_dirac (by finiteness)).smul_measure (by finiteness)), + integral_smul_measure, integral_smul_measure, integral_dirac, integral_dirac, + ENNReal.toReal_ofReal hp0, ENNReal.toReal_ofReal (by linarith)] + simp [smul_eq_mul] + +/-- **The binomial price is the discounted risk-neutral expectation** (the bridge from +the backward-recursion pricer to the probabilistic row-law form). For a bounded +measurable payoff `g`, the `k`-step CRR binomial price of `g` equals `e^{−r'k}` times +the expectation of `g(S·eˣ)` over the `k`-fold convolution of the per-step log-return +law (`r' = crrPerStepRate`). Proof: induction on `k`, the recursion step matched to one +convolution via `integral_conv` + the two-point step integral. -/ +lemma binomialPrice_eq_integral_convPow {r σ T : ℝ} {n : ℕ} + (hp0 : 0 ≤ crrProb r σ T n) (hp1 : crrProb r σ T n ≤ 1) + {g : ℝ → ℝ} (hg : Measurable g) {C : ℝ} (hC : ∀ y, 0 < y → |g y| ≤ C) : + ∀ (k : ℕ) (S : ℝ), 0 < S → + binomialPrice (crrUp σ T n) (crrDown σ T n) (crrPerStepRate r T n) g k S + = Real.exp (-(crrPerStepRate r T n) * k) * + ∫ x, g (S * Real.exp x) ∂(convPow (crrStepMeasure r σ T n) k) := by + have : IsProbabilityMeasure (crrStepMeasure r σ T n) := + isProbabilityMeasure_crrStepMeasure hp0 hp1 + have hcrrUp : (0 : ℝ) < crrUp σ T n := crrUp_pos σ T n + have hcrrDown : (0 : ℝ) < crrDown σ T n := crrDown_pos σ T n + intro k + induction k with + | zero => + intro S _ + simp only [binomialPrice_zero, Nat.cast_zero, mul_zero, Real.exp_zero, one_mul, + convPow, integral_dirac, mul_one] + | succ k ih => + intro S hS + have : IsProbabilityMeasure (convPow (crrStepMeasure r σ T n) k) := + convPow_isProbabilityMeasure _ k + have hprob : crrUpProb (crrUp σ T n) (crrDown σ T n) (crrPerStepRate r T n) + = crrProb r σ T n := rfl + have hinner : ∀ x : ℝ, (∫ z, g (S * Real.exp (x + z)) ∂(crrStepMeasure r σ T n)) + = crrProb r σ T n * g (S * crrUp σ T n * Real.exp x) + + (1 - crrProb r σ T n) * g (S * crrDown σ T n * Real.exp x) := by + intro x + rw [integral_crrStepMeasure hp0 hp1 (fun z ↦ g (S * Real.exp (x + z))), + show S * Real.exp (x + σ * Real.sqrt (T / n)) = S * crrUp σ T n * Real.exp x from by + rw [Real.exp_add, crrUp, crrStep]; ring, + show S * Real.exp (x + -(σ * Real.sqrt (T / n))) = S * crrDown σ T n * Real.exp x from by + rw [Real.exp_add, crrDown, crrStep]; ring] + rw [binomialPrice_succ, hprob, ih (S * crrUp σ T n) (mul_pos hS hcrrUp), + ih (S * crrDown σ T n) (mul_pos hS hcrrDown), convPow, + integral_conv (integrable_comp_exp_of_bdd hg hS hC)] + simp_rw [hinner] + rw [integral_add ((integrable_comp_exp_of_bdd hg (mul_pos hS hcrrUp) hC).const_mul _) + ((integrable_comp_exp_of_bdd hg (mul_pos hS hcrrDown) hC).const_mul _), + integral_const_mul, integral_const_mul] + have hexp : Real.exp (-(crrPerStepRate r T n) * (↑(k + 1) : ℝ)) + = Real.exp (-(crrPerStepRate r T n)) * Real.exp (-(crrPerStepRate r T n) * (k : ℝ)) := by + rw [← Real.exp_add]; congr 1; push_cast; ring + rw [hexp] + ring + +/-- **Stock-price MGF under the BS Gaussian**: `∫ S₀·eˣ d N((r−σ²/2)T, σ²T) = S₀·e^{rT}` +(the martingale/forward identity for the discounted stock). -/ +lemma integral_const_mul_exp_gaussian {r σ T S₀ : ℝ} (hT : 0 < T) : + ∫ x, S₀ * Real.exp x ∂(gaussianReal ((r - σ ^ 2 / 2) * T) (σ ^ 2 * T).toNNReal) + = S₀ * Real.exp (r * T) := by + rw [integral_const_mul] + have hmgf := congr_fun (mgf_id_gaussianReal (μ := (r - σ ^ 2 / 2) * T) + (v := (σ ^ 2 * T).toNNReal)) 1 + rw [mgf] at hmgf + simp only [one_mul, id_eq] at hmgf + rw [hmgf, + show ((σ ^ 2 * T).toNNReal : ℝ) = σ ^ 2 * T from + Real.coe_toNNReal _ (mul_nonneg (sq_nonneg σ) hT.le), + show (r - σ ^ 2 / 2) * T * 1 + σ ^ 2 * T * 1 ^ 2 / 2 = r * T from by ring] + +/-- **The CRR put expectation converges weakly to the BS put expectation.** Since the +put payoff `x ↦ max(K − S₀eˣ, 0)` is bounded and continuous, this is immediate from +the convergence in distribution `crr_tendsto_gaussian_inDistribution`. -/ +lemma tendsto_integral_put {r σ T S₀ K : ℝ} (hσ : 0 < σ) (hT : 0 < T) (hS₀ : 0 < S₀) + (hna : ∀ n, 0 < n → BinomialNoArb (crrUp σ T n) (crrDown σ T n) (crrPerStepRate r T n)) : + Tendsto (fun n : ℕ ↦ ∫ x, max (K - S₀ * Real.exp x) 0 + ∂(convPow (crrStepMeasure r σ T n) n)) atTop + (𝓝 (∫ x, max (K - S₀ * Real.exp x) 0 + ∂(gaussianReal ((r - σ ^ 2 / 2) * T) (σ ^ 2 * T).toNNReal))) := by + have hp (n : ℕ) : 0 ≤ crrProb r σ T n ∧ crrProb r σ T n ≤ 1 := crrProb_mem_Icc hna n + have hcont : Continuous (fun x : ℝ ↦ max (K - S₀ * Real.exp x) 0) := by fun_prop + have hbound : ∀ x : ℝ, ‖max (K - S₀ * Real.exp x) 0‖ ≤ |K| := fun x ↦ by + rw [Real.norm_eq_abs, abs_of_nonneg (le_max_right _ _)] + calc max (K - S₀ * Real.exp x) 0 + ≤ max K 0 := max_le_max (by nlinarith [mul_pos hS₀ (Real.exp_pos x)]) le_rfl + _ ≤ |K| := max_le (le_abs_self K) (abs_nonneg K) + have hconv := (ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mp + (crr_tendsto_gaussian_inDistribution hσ hT hp)) + (BoundedContinuousFunction.ofNormedAddCommGroup _ hcont _ hbound) + simpa only [BoundedContinuousFunction.coe_ofNormedAddCommGroup, crrRowProbMeasure, + bsLimitProbMeasure, MeasureTheory.ProbabilityMeasure.coe_mk] using hconv + +/-- **Cox–Ross–Rubinstein → Black–Scholes, the call-price convergence.** Under +no-arbitrage at every step with `n ≥ 1` — a hypothesis `binomialNoArb_crr` +discharges whenever `|r|·√T < σ`, and one that must exclude `n = 0`, where the +step degenerates to `u = d = 1` and no-arbitrage is impossible — the `n`-step +CRR binomial price of a European call +converges to the Black–Scholes call price, written in put-call-parity form as +`e^{−rT}·E[(K − S_T)₊] + (S₀ − K e^{−rT})` — the discounted put expectation plus the +forward, with `S_T = S₀ e^X`, `X ∼ N((r − σ²/2)T, σ²T)`. + +No uniform integrability is needed: the *put* payoff is bounded, so the binomial put +price equals a discounted expectation (`binomialPrice_eq_integral_convPow`) that +converges weakly (`tendsto_integral_put`); binomial put-call parity +(`binomialPrice_callPut_parity`) lifts this to the (unbounded) call. -/ +theorem binomialPrice_call_tendsto_bs {r σ T S₀ K : ℝ} (hσ : 0 < σ) (hT : 0 < T) (hS₀ : 0 < S₀) + (hna : ∀ n, 0 < n → BinomialNoArb (crrUp σ T n) (crrDown σ T n) (crrPerStepRate r T n)) : + Tendsto (fun n : ℕ ↦ binomialPrice (crrUp σ T n) (crrDown σ T n) (crrPerStepRate r T n) + (fun x ↦ max (x - K) 0) n S₀) atTop + (𝓝 (Real.exp (-(r * T)) * ∫ x, max (K - S₀ * Real.exp x) 0 + ∂(gaussianReal ((r - σ ^ 2 / 2) * T) (σ ^ 2 * T).toNNReal) + + (S₀ - K * Real.exp (-(r * T))))) := by + have hp (n : ℕ) : 0 ≤ crrProb r σ T n ∧ crrProb r σ T n ≤ 1 := crrProb_mem_Icc hna n + -- Put payoff: measurable, and bounded on `(0,∞)` by `|K|` (since `S₀eˣ > 0`). + have hmeas : Measurable (fun y : ℝ ↦ max (K - y) 0) := by fun_prop + have hbd : ∀ y : ℝ, 0 < y → |max (K - y) 0| ≤ |K| := fun y hy ↦ by + rw [abs_of_nonneg (le_max_right _ _)] + exact (max_le_max (by linarith) le_rfl).trans (max_le (le_abs_self K) (abs_nonneg K)) + -- Eventually (`n ≥ 1`) the total discount `n · crrPerStepRate = rT`. + have hdisc : ∀ n : ℕ, 1 ≤ n → (n : ℝ) * crrPerStepRate r T n = r * T := fun n hn ↦ by + have hn0 : (n : ℝ) ≠ 0 := by positivity + unfold crrPerStepRate crrStep; field_simp + -- The binomial put price converges to `e^{−rT}·∫ put` over the BS gaussian. + have hput : Tendsto (fun n : ℕ ↦ + binomialPrice (crrUp σ T n) (crrDown σ T n) (crrPerStepRate r T n) + (fun x ↦ max (K - x) 0) n S₀) atTop + (𝓝 (Real.exp (-(r * T)) * ∫ x, max (K - S₀ * Real.exp x) 0 + ∂(gaussianReal ((r - σ ^ 2 / 2) * T) (σ ^ 2 * T).toNNReal))) := by + refine ((tendsto_integral_put hσ hT hS₀ hna).const_mul (Real.exp (-(r * T)))).congr' + (Filter.eventually_atTop.mpr ⟨1, fun n hn ↦ ?_⟩) + change Real.exp (-(r * T)) * (∫ x, max (K - S₀ * Real.exp x) 0 + ∂(convPow (crrStepMeasure r σ T n) n)) + = binomialPrice (crrUp σ T n) (crrDown σ T n) (crrPerStepRate r T n) + (fun x ↦ max (K - x) 0) n S₀ + rw [binomialPrice_eq_integral_convPow (hp n).1 (hp n).2 hmeas hbd n S₀ hS₀, + neg_mul, mul_comm (crrPerStepRate r T n) (n : ℝ), hdisc n hn] + -- Binomial put-call parity (eventually) lifts the convergence to the call. + refine (hput.add_const (S₀ - K * Real.exp (-(r * T)))).congr' + (Filter.eventually_atTop.mpr ⟨1, fun n hn ↦ ?_⟩) + change binomialPrice (crrUp σ T n) (crrDown σ T n) (crrPerStepRate r T n) + (fun x ↦ max (K - x) 0) n S₀ + (S₀ - K * Real.exp (-(r * T))) + = binomialPrice (crrUp σ T n) (crrDown σ T n) (crrPerStepRate r T n) + (fun x ↦ max (x - K) 0) n S₀ + rw [binomialPrice_callPut_parity (hna n hn) n S₀, neg_mul, hdisc n hn] + +end Distributional + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/CRRClosedForm.lean b/LeanPool/MathFin/Models/Binomial/CRRClosedForm.lean new file mode 100644 index 0000000000..7fec35ab84 --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/CRRClosedForm.lean @@ -0,0 +1,129 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.CRRCharFun +public import LeanPool.MathFin.Models.BlackScholes.Put + +/-! +# CRR → Black–Scholes call price, in closed form + +`binomialPrice_call_tendsto_bs` lands the binomial call-price limit in the +put-call-parity *integral* form `e^{−rT}·E[(K − S_T)₊] + (S₀ − K e^{−rT})`. +This file chains it to the literal Black–Scholes closed form +`S₀·Φ(d₁) − K·e^{−rT}·Φ(d₂)`, via the BS put formula (`bs_put_formula`, +instantiated on the terminal law `N((r−σ²/2)T, σ²T)` through the standardisation +`Z = (· − (r−σ²/2)T)/(σ√T)`) and the CDF symmetry `Φ(−x) = 1 − Φ(x)`. + +## Main results + +* `exp_neg_mul_integral_put_gaussian_eq`: for `σ, T, S₀, K > 0`, the discounted put expectation + under `N((r − σ²/2)T, σ²T)` equals the Black–Scholes put value. +* `binomialPrice_call_tendsto_bs_closed`: for `σ, T, S₀, K > 0`, if the CRR tree is + arbitrage-free for every size `n > 0`, its `n`-step call price tends to + `S₀ · Φ(d₁) − K · e^{−rT} · Φ(d₂)`. + +## References + +* [J. C. Cox, S. A. Ross and M. Rubinstein, *Option pricing: a simplified + approach*][CoxRossRubinstein1979] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 21.1 +* [S. E. Shreve, *Stochastic Calculus for Finance I: The Binomial Asset Pricing Model*][ShreveSCFI], + 3.2 + +## Tags + +Cox–Ross–Rubinstein, Black–Scholes formula, put–call parity, binomial convergence, call price limit, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real Filter +open scoped Topology + +/-- The discounted put expectation over the BS terminal law `N((r−σ²/2)T, σ²T)` +equals the Black–Scholes put price `K e^{−rT} Φ(−d₂) − S₀ Φ(−d₁)`. Proved by +instantiating `bs_put_formula` on that gaussian with the standardisation +`Z = (· − (r−σ²/2)T)/(σ√T)` (which has `N(0,1)` law), under which the BS +terminal `bsTerminal S₀ r σ T (Z x)` collapses to `S₀·eˣ`. -/ +lemma exp_neg_mul_integral_put_gaussian_eq {r σ T S₀ K : ℝ} + (hσ : 0 < σ) (hT : 0 < T) (hS₀ : 0 < S₀) (hK : 0 < K) : + Real.exp (-(r * T)) * ∫ x, max (K - S₀ * Real.exp x) 0 + ∂(gaussianReal ((r - σ ^ 2 / 2) * T) (σ ^ 2 * T).toNNReal) + = K * Real.exp (-(r * T)) * Phi (-(bsd2 S₀ K r σ T)) + - S₀ * Phi (-(bsd1 S₀ K r σ T)) := by + set μ_bs : ℝ := (r - σ ^ 2 / 2) * T with hμ + set ν : ℝ := σ * Real.sqrt T with hν + have hν_pos : 0 < ν := mul_pos hσ (Real.sqrt_pos.mpr hT) + have hσ2T_pos : 0 < σ ^ 2 * T := by positivity + -- Standardisation `Z = (· − μ_bs)/ν` has `N(0,1)` law under the BS gaussian. + have hlaw : HasLaw (fun x ↦ (x - μ_bs) / ν) (gaussianReal 0 1) + (gaussianReal μ_bs (σ ^ 2 * T).toNNReal) := by + have h1 := gaussianReal_sub_const + (HasLaw.id (μ := gaussianReal μ_bs (σ ^ 2 * T).toNNReal)) μ_bs + have h2 := gaussianReal_div_const h1 ν + have hmk : NNReal.mk (ν ^ 2) (sq_nonneg _) = (σ ^ 2 * T).toNNReal := by + apply NNReal.eq + simp only [NNReal.coe_mk] + rw [hν, mul_pow, Real.sq_sqrt hT.le] + exact (Real.coe_toNNReal _ hσ2T_pos.le).symm + have hvar : ((σ ^ 2 * T).toNNReal / NNReal.mk (ν ^ 2) (sq_nonneg _)) = 1 := by + rw [hmk]; exact div_self (Real.toNNReal_pos.mpr hσ2T_pos).ne' + simp only [id_eq] at h2 + convert h2 using 2 + · rw [sub_self, zero_div] + · rw [hvar] + have hbs : BSCallHyp (gaussianReal μ_bs (σ ^ 2 * T).toNNReal) S₀ K r σ T + (fun x ↦ (x - μ_bs) / ν) := ⟨hS₀, hK, hσ, hT, hlaw⟩ + have hpf := bs_put_formula hbs + -- `bsTerminal S₀ r σ T ((x − μ_bs)/ν) = S₀ · eˣ`. + have hterm : (fun x : ℝ ↦ Real.exp (-r * T) * + max (K - bsTerminal S₀ r σ T ((x - μ_bs) / ν)) 0) + = (fun x : ℝ ↦ Real.exp (-r * T) * max (K - S₀ * Real.exp x) 0) := by + funext x + have hb : bsTerminal S₀ r σ T ((x - μ_bs) / ν) = S₀ * Real.exp x := by + rw [bsTerminal] + congr 2 + rw [hμ, hν] + field_simp + ring + rw [hb] + rw [hterm] at hpf + rw [← integral_const_mul, show Real.exp (-(r * T)) = Real.exp (-r * T) from by + rw [neg_mul]] + exact hpf + +/-- **Cox–Ross–Rubinstein → Black–Scholes, closed form.** Under no-arbitrage at +every step with `n ≥ 1`, the `n`-step CRR binomial call price converges to the *literal* +Black–Scholes call price `S₀·Φ(d₁) − K·e^{−rT}·Φ(d₂)`. + +This is `binomialPrice_call_tendsto_bs` with its put-call-parity integral limit +chained, via `exp_neg_mul_integral_put_gaussian_eq` + `Phi_neg`, onto the closed +`Φ`-form. -/ +theorem binomialPrice_call_tendsto_bs_closed {r σ T S₀ K : ℝ} + (hσ : 0 < σ) (hT : 0 < T) (hS₀ : 0 < S₀) (hK : 0 < K) + (hna : ∀ n, 0 < n → BinomialNoArb (crrUp σ T n) (crrDown σ T n) (crrPerStepRate r T n)) : + Tendsto (fun n : ℕ ↦ binomialPrice (crrUp σ T n) (crrDown σ T n) (crrPerStepRate r T n) + (fun x ↦ max (x - K) 0) n S₀) atTop + (𝓝 (S₀ * Phi (bsd1 S₀ K r σ T) + - K * Real.exp (-(r * T)) * Phi (bsd2 S₀ K r σ T))) := by + have h := binomialPrice_call_tendsto_bs (K := K) hσ hT hS₀ hna + have hkey : Real.exp (-(r * T)) * ∫ x, max (K - S₀ * Real.exp x) 0 + ∂(gaussianReal ((r - σ ^ 2 / 2) * T) (σ ^ 2 * T).toNNReal) + + (S₀ - K * Real.exp (-(r * T))) + = S₀ * Phi (bsd1 S₀ K r σ T) + - K * Real.exp (-(r * T)) * Phi (bsd2 S₀ K r σ T) := by + rw [exp_neg_mul_integral_put_gaussian_eq hσ hT hS₀ hK, + Phi_neg (bsd2 S₀ K r σ T), Phi_neg (bsd1 S₀ K r σ T)] + ring + rwa [hkey] at h + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/CRRConvergence.lean b/LeanPool/MathFin/Models/Binomial/CRRConvergence.lean new file mode 100644 index 0000000000..77d58d9a01 --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/CRRConvergence.lean @@ -0,0 +1,430 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.Model +public import Mathlib.Algebra.Ring.IsFormallyReal +public import Mathlib.Analysis.InnerProductSpace.Basic +public import Mathlib.Analysis.SpecialFunctions.ExpDeriv +public import Mathlib.Topology.Algebra.Module.ModuleTopology + +/-! +# Cox-Ross-Rubinstein convergence to Black-Scholes + +We formalize the **CRR parameterization** of the binomial tree: +with `Δt = T/n`, `u_n = e^{σ √Δt}`, `d_n = e^{-σ √Δt}`, +the n-step risk-neutral up-probability is + + `p_n = (e^{r Δt} − d_n) / (u_n − d_n).` + +This file proves: +1. **One-step risk-neutral martingale identity** (exact, algebraic): + `p_n · u_n + (1 − p_n) · d_n = e^{r Δt}`. +2. **Exponential-difference-quotient limits** at 0 used throughout the proof: + * `(e^{c x} − 1) / x → c` as `x → 0` (first-order Taylor of exp at 0). + * `(e^{c h²} − 1) / h² → c` (composition with `h ↦ h²`). + * `(e^{σ h} − e^{-σ h}) / h → 2σ` (sinh-derivative at 0). +3. **CRR probability limit**: `p_n → 1/2` as `n → ∞`. This implies + `4 p_n (1 − p_n) → 1`, which gives the variance limit + `n · σ² Δt · 4 p_n (1 − p_n) → σ² T`. +4. **`p_n` is a probability at every `n`** (`crrProb_mem_Icc`), given no-arbitrage at each + `n ≥ 1` — which `binomialNoArb_crr` supplies when `|r| √T < σ`. + +## Scope + +The **full pricing convergence** + + `binomialPrice (u_n) (d_n) (rΔt) (max(· − K, 0)) n S_0 → bs_call_price` + +is **proved** in `Models/Binomial/CRRCharFun.lean` (`binomialPrice_call_tendsto_bs`): +a characteristic-function + Lévy-continuity route gives convergence in +distribution, and a put-call-parity argument sidesteps the triangular-array +CLT and the uniform-integrability/Vitali step entirely (the put payoff is +bounded, so weak convergence applies directly; parity lifts it to the call). + +What this file provides is the **classical analytic CRR↔BS correspondence** +on the mean and variance of one log-return increment — the substantive +textbook computations feeding that limit. + +## Main definitions + +* `crrStep`: the step size `Δt = T / n`. +* `crrUp`, `crrDown`: the up- and down-factors `exp(±σ √(T/n))`. +* `crrPerStepRate`: the per-step rate `r · T / n`. +* `crrProb`: the CRR risk-neutral up-probability `(e^{rΔt} − d_n) / (u_n − d_n)`. + +## Main results + +* `binomialNoArb_crr`: if `|r| · √T < σ` and `T > 0`, the CRR parameters satisfy + `BinomialNoArb` for every `n > 0`. +* `crrProb_mem_Icc`: given no-arbitrage at every step `n > 0`, `crrProb r σ T n ∈ [0, 1]` for + every `n`. +* `crr_one_step_martingale`: when `d_n < u_n`, `p_n · u_n + (1 − p_n) · d_n = e^{rΔt}`. +* `crrProb_tendsto_half`: for `σ, T > 0`, `crrProb r σ T n → 1/2`. +* `crr_variance_limit`: for `σ, T > 0`, `4 σ² T · p_n (1 − p_n) → σ² T`. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 21.1 +* [S. E. Shreve, *Stochastic Calculus for Finance I: The Binomial Asset Pricing Model*][ShreveSCFI], + 1.2; 3.2 + +## Tags + +Cox–Ross–Rubinstein, Black–Scholes limit, risk-neutral probability, up-down factors, +binomial convergence, variance limit, MSC 91G20, MSC 60F05, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Filter +open scoped Topology + +/-! ### CRR parameterization -/ + +/-- CRR step size: `Δt = T / n`. -/ +noncomputable def crrStep (T : ℝ) (n : ℕ) : ℝ := T / n + +/-- CRR up-factor: `u_n = exp(σ √(T/n))`. -/ +noncomputable def crrUp (σ T : ℝ) (n : ℕ) : ℝ := Real.exp (σ * Real.sqrt (crrStep T n)) + +/-- CRR down-factor: `d_n = exp(-σ √(T/n))`. -/ +noncomputable def crrDown (σ T : ℝ) (n : ℕ) : ℝ := Real.exp (-(σ * Real.sqrt (crrStep T n))) + +/-- CRR per-step continuously-compounded rate: `r · Δt = r T / n`. -/ +noncomputable def crrPerStepRate (r T : ℝ) (n : ℕ) : ℝ := r * crrStep T n + +/-- CRR risk-neutral up-probability. -/ +noncomputable def crrProb (r σ T : ℝ) (n : ℕ) : ℝ := + (Real.exp (crrPerStepRate r T n) - crrDown σ T n) / (crrUp σ T n - crrDown σ T n) + +/-! ### Positivity and basic facts -/ + +/-- The CRR up-factor `u = exp(σ√(T/n))` is positive. -/ +lemma crrUp_pos (σ T : ℝ) (n : ℕ) : 0 < crrUp σ T n := Real.exp_pos _ + +/-- The CRR down-factor `d = exp(-σ√(T/n))` is positive. -/ +lemma crrDown_pos (σ T : ℝ) (n : ℕ) : 0 < crrDown σ T n := Real.exp_pos _ + +/-- Under `σ > 0, T > 0, n ≥ 1`, the up-factor exceeds the down-factor. -/ +lemma crrDown_lt_crrUp {σ T : ℝ} (hσ : 0 < σ) (hT : 0 < T) {n : ℕ} (hn : 1 ≤ n) : + crrDown σ T n < crrUp σ T n := by + have h_n_pos : (0 : ℝ) < n := by exact_mod_cast hn + have h_step_pos : 0 < crrStep T n := div_pos hT h_n_pos + have h_sqrt_pos : 0 < Real.sqrt (crrStep T n) := Real.sqrt_pos.mpr h_step_pos + unfold crrDown crrUp + rw [Real.exp_lt_exp] + linarith [mul_pos hσ h_sqrt_pos] + +/-- At `n = 0` the CRR step degenerates: `crrStep T 0 = T / 0 = 0`, so `u = d = 1` +and the risk-neutral probability is the junk value `0 / 0 = 0`. + +This is why the no-arbitrage hypothesis of the convergence theorems is stated for +`0 < n`. `BinomialNoArb 1 1 0` is *false* — it demands `Real.exp 0 < 1` — so a +hypothesis quantified over every `n` is unsatisfiable and the theorem carrying it +says nothing. The `0 ≤ p ≤ 1` bound the limit actually consumes survives at +`n = 0` regardless, which is what makes the restricted hypothesis enough. -/ +@[simp] +lemma crrProb_zero (r σ T : ℝ) : crrProb r σ T 0 = 0 := by + simp [crrProb, crrUp, crrDown, crrPerStepRate, crrStep] + +/-- **The CRR no-arbitrage condition is satisfiable, and generically so.** If the +volatility dominates the drift over the horizon (`|r|·√T < σ`), then every CRR +step with `n ≥ 1` is arbitrage-free. + +Some restriction is unavoidable in both directions: `n = 0` is degenerate +(`crrProb_zero`), and for a fixed `n` a large enough `|r|` pushes `e^{rΔt}` +outside `[d, u]`. Since `√(T/n) ≤ √T` for `n ≥ 1`, the single bound `|r|·√T < σ` +covers every step at once — so this discharges the hypothesis of +`binomialPrice_call_tendsto_bs_closed` on a nonempty set of parameters. -/ +lemma binomialNoArb_crr {r σ T : ℝ} (hT : 0 < T) (hrT : |r| * Real.sqrt T < σ) + {n : ℕ} (hn : 0 < n) : + BinomialNoArb (crrUp σ T n) (crrDown σ T n) (crrPerStepRate r T n) := by + have hn1 : (1 : ℕ) ≤ n := hn + have hnR : (1 : ℝ) ≤ n := by exact_mod_cast hn1 + have hstep : 0 < crrStep T n := div_pos hT (by linarith) + have hsqrt : 0 < Real.sqrt (crrStep T n) := Real.sqrt_pos.mpr hstep + -- `√Δt ≤ √T`, so the single bound `|r|·√T < σ` bounds every step. + have hmono : Real.sqrt (crrStep T n) ≤ Real.sqrt T := + Real.sqrt_le_sqrt (by rw [crrStep]; exact div_le_self hT.le hnR) + have hkey : |r| * Real.sqrt (crrStep T n) < σ := + lt_of_le_of_lt (mul_le_mul_of_nonneg_left hmono (abs_nonneg r)) hrT + -- hence `|r·Δt| < σ·√Δt`, which is exactly `d < e^{rΔt} < u`. + have hsq : crrStep T n = Real.sqrt (crrStep T n) * Real.sqrt (crrStep T n) := + (Real.mul_self_sqrt hstep.le).symm + have hbound : |r * crrStep T n| < σ * Real.sqrt (crrStep T n) := by + calc |r * crrStep T n| = |r| * crrStep T n := by rw [abs_mul, abs_of_pos hstep] + _ = |r| * Real.sqrt (crrStep T n) * Real.sqrt (crrStep T n) := by + rw [mul_assoc, ← hsq] + _ < σ * Real.sqrt (crrStep T n) := mul_lt_mul_of_pos_right hkey hsqrt + rw [abs_lt] at hbound + refine ⟨Real.exp_pos _, ?_, ?_⟩ + · change Real.exp (-(σ * Real.sqrt (crrStep T n))) < Real.exp (r * crrStep T n) + exact Real.exp_lt_exp.mpr hbound.1 + · change Real.exp (r * crrStep T n) < Real.exp (σ * Real.sqrt (crrStep T n)) + exact Real.exp_lt_exp.mpr hbound.2 + +/-- **The CRR up-probability is a probability at every `n`**: by no-arbitrage for `n ≥ 1`, and at +the degenerate `n = 0`, where no-arbitrage fails, because the up-probability is `0` there +(`crrProb_zero`). -/ +lemma crrProb_mem_Icc {r σ T : ℝ} + (hna : ∀ n, 0 < n → BinomialNoArb (crrUp σ T n) (crrDown σ T n) (crrPerStepRate r T n)) + (n : ℕ) : crrProb r σ T n ∈ Set.Icc 0 1 := by + rcases Nat.eq_zero_or_pos n with rfl | hn + · simp [crrProb_zero] + · exact Set.Ioo_subset_Icc_self (crrUpProb_mem_Ioo (hna n hn)) + +/-! ### One-step risk-neutral martingale identity (algebraic, exact) -/ + +/-- **CRR one-step martingale identity** (exact, not asymptotic): + `p · u + (1 − p) · d = e^{r Δt}`. The discrete-time risk-neutral measure makes + the one-step discounted asset price a martingale. + + Requires the no-arbitrage condition `d < e^{rΔt}` (implied by `d < u` when + we're between them, but explicit here so this works in either parameterization). -/ +theorem crr_one_step_martingale {σ T r : ℝ} {n : ℕ} + (h_du : crrDown σ T n < crrUp σ T n) : + crrProb r σ T n * crrUp σ T n + (1 - crrProb r σ T n) * crrDown σ T n + = Real.exp (crrPerStepRate r T n) := by + have h_ud : 0 < crrUp σ T n - crrDown σ T n := sub_pos.mpr h_du + have h_ud_ne : crrUp σ T n - crrDown σ T n ≠ 0 := h_ud.ne' + unfold crrProb + field_simp + ring + +/-! ### Step-size limits -/ + +/-- The CRR step `Δt = T/n` tends to 0 as `n → ∞`. -/ +lemma tendsto_crrStep_zero (T : ℝ) : Tendsto (crrStep T) atTop (𝓝 0) := by + unfold crrStep + exact Tendsto.div_atTop tendsto_const_nhds (tendsto_natCast_atTop_atTop (R := ℝ)) + +/-- `√(T/n) → 0` as `n → ∞`. -/ +lemma tendsto_sqrt_crrStep_zero (T : ℝ) : + Tendsto (fun n ↦ Real.sqrt (crrStep T n)) atTop (𝓝 0) := by + rw [show (0 : ℝ) = Real.sqrt 0 from Real.sqrt_zero.symm] + exact (Real.continuous_sqrt.tendsto 0).comp (tendsto_crrStep_zero T) + +/-! ### Exponential difference quotients (first-order Taylor at 0) -/ + +/-- **Difference quotient of `exp` at 0**: `(e^{c x} − 1) / x → c` as `x → 0` (`x ≠ 0`). + Just `HasDerivAt (fun x ↦ e^{cx}) c 0` unpacked via `hasDerivAt_iff_tendsto_slope`. -/ +lemma tendsto_exp_sub_one_div (c : ℝ) : + Tendsto (fun x : ℝ ↦ (Real.exp (c * x) - 1) / x) (𝓝[≠] 0) (𝓝 c) := by + have h_deriv : HasDerivAt (fun x : ℝ ↦ Real.exp (c * x)) c 0 := by + have h_lin : HasDerivAt (fun x : ℝ ↦ c * x) c 0 := by + simpa using (hasDerivAt_id (0 : ℝ)).const_mul c + have := h_lin.exp + simpa using this + have h_slope := h_deriv.tendsto_slope + have h_eq : ∀ x : ℝ, + slope (fun x : ℝ ↦ Real.exp (c * x)) 0 x = (Real.exp (c * x) - 1) / x := by + intro x + rw [slope_def_field] + simp [Real.exp_zero] + exact h_slope.congr' (Eventually.of_forall h_eq) + +/-- Squaring maps punctured neighbourhoods of `0` into punctured neighbourhoods of `0`. -/ +lemma tendsto_sq_nhdsNE_zero : + Tendsto (fun h : ℝ ↦ h^2) (𝓝[≠] 0) (𝓝[≠] 0) := by + refine tendsto_nhdsWithin_iff.mpr ⟨?_, ?_⟩ + · have h_cont : Continuous (fun h : ℝ ↦ h^2) := by continuity + have h_tendsto_nhds : Tendsto (fun h : ℝ ↦ h^2) (𝓝 0) (𝓝 0) := by + have := h_cont.tendsto 0 + simpa using this + exact h_tendsto_nhds.mono_left nhdsWithin_le_nhds + · filter_upwards [self_mem_nhdsWithin] with h hh + exact pow_ne_zero 2 hh + +/-- `(e^{c · h²} − 1) / h² → c` as `h → 0` (`h ≠ 0`). + Composition of `tendsto_exp_sub_one_div` with `h ↦ h²`. -/ +lemma tendsto_exp_sq_sub_one_div_sq (c : ℝ) : + Tendsto (fun h : ℝ ↦ (Real.exp (c * h^2) - 1) / h^2) (𝓝[≠] 0) (𝓝 c) := + (tendsto_exp_sub_one_div c).comp tendsto_sq_nhdsNE_zero + +/-- `(e^{c · h²} − 1) / h → 0` as `h → 0` (`h ≠ 0`). + Equals `h · ((e^{c·h²} − 1)/h²) → 0 · c = 0`. -/ +lemma tendsto_exp_sq_sub_one_div_h (c : ℝ) : + Tendsto (fun h : ℝ ↦ (Real.exp (c * h^2) - 1) / h) (𝓝[≠] 0) (𝓝 0) := by + have h_id : Tendsto (fun h : ℝ ↦ h) (𝓝[≠] 0) (𝓝 0) := + tendsto_id.mono_left nhdsWithin_le_nhds + have h_sq := tendsto_exp_sq_sub_one_div_sq c + have h_mul := h_id.mul h_sq + -- h_mul : Tendsto (fun h ↦ h * ((exp(c·h²)-1)/h²)) (𝓝[≠] 0) (𝓝 (0 * c)) + have h_target_eq : (0 : ℝ) * c = 0 := zero_mul c + rw [h_target_eq] at h_mul + refine h_mul.congr' ?_ + filter_upwards [self_mem_nhdsWithin] with h hh + have hh_ne : h ≠ 0 := hh + have h_sq_ne : h^2 ≠ 0 := pow_ne_zero 2 hh_ne + field_simp + +/-- `(e^{σ h} − e^{-σ h}) / h → 2σ` as `h → 0` (`h ≠ 0`). -/ +lemma tendsto_sinh_div (σ : ℝ) : + Tendsto (fun h : ℝ ↦ (Real.exp (σ * h) - Real.exp (-(σ * h))) / h) + (𝓝[≠] 0) (𝓝 (2 * σ)) := by + have h_pos : Tendsto (fun h : ℝ ↦ (Real.exp (σ * h) - 1) / h) (𝓝[≠] 0) (𝓝 σ) := + tendsto_exp_sub_one_div σ + have h_neg : Tendsto (fun h : ℝ ↦ (Real.exp (-(σ * h)) - 1) / h) (𝓝[≠] 0) (𝓝 (-σ)) := by + refine (tendsto_exp_sub_one_div (-σ)).congr' ?_ + filter_upwards with h + rw [show -σ * h = -(σ * h) from by ring] + have h_diff := h_pos.sub h_neg + have h_target : (σ - (-σ) : ℝ) = 2 * σ := by ring + rw [h_target] at h_diff + refine h_diff.congr' ?_ + filter_upwards with h + ring + +/-! ### CRR probability limit: `p_n → 1/2` -/ + +/-- **CRR probability limit**: `p_n → 1/2` as `n → ∞`. + +The intuition: as `Δt = T/n → 0`, both `e^{rΔt} - e^{-σ√Δt}` and `e^{σ√Δt} - e^{-σ√Δt}` +tend to 0, but they share the leading `σ√Δt` term, so the ratio tends to `1/2`. + +Formally: substitute `h_n = √(T/n)`. Then + `p_n = (e^{r·h_n²} - e^{-σ·h_n}) / (e^{σ·h_n} - e^{-σ·h_n})`. + +Multiply numerator and denominator by `1/h_n`: + `p_n = N / D` with `N = (e^{r·h_n²} - 1)/h_n − (e^{-σ·h_n} − 1)/h_n` and + `D = (e^{σ·h_n} − 1)/h_n − (e^{-σ·h_n} − 1)/h_n`. + +As `h_n → 0`: + - `(e^{r h_n²} − 1)/h_n → 0` + - `(e^{σ h_n} − 1)/h_n → σ` + - `(e^{-σ h_n} − 1)/h_n → −σ` + +Hence `p_n → (0 − (−σ)) / (σ − (−σ)) = σ / (2σ) = 1/2`. -/ +theorem crrProb_tendsto_half {σ T r : ℝ} (hσ : 0 < σ) (hT : 0 < T) : + Tendsto (fun n : ℕ ↦ crrProb r σ T n) atTop (𝓝 (1/2)) := by + -- Step 1: define the per-h probability function and prove p(h) → 1/2 as h → 0 (h ≠ 0). + -- p(h) = (e^{r·h²} - e^{-σh}) / (e^{σh} - e^{-σh}) + -- = [(e^{r·h²}-1)/h - (e^{-σh}-1)/h] / [(e^{σh}-1)/h - (e^{-σh}-1)/h] (for h ≠ 0) + -- Numerator → σ, denominator → 2σ, so p(h) → σ/(2σ) = 1/2. + -- Denominator is nonzero for h ≠ 0 (since σ > 0). + have h_denom_ne : ∀ h : ℝ, h ≠ 0 → Real.exp (σ * h) - Real.exp (-(σ * h)) ≠ 0 := by + intro h hh h_eq + rw [sub_eq_zero, Real.exp_eq_exp] at h_eq + have h_zero : σ * h = 0 := by linarith + rcases mul_eq_zero.mp h_zero with hσ0 | hh0 + · exact absurd hσ0 hσ.ne' + · exact absurd hh0 hh + -- Limits of numerator and denominator (working with the difference-quotient form): + have h_neg_div : Tendsto (fun h : ℝ ↦ (Real.exp (-(σ * h)) - 1) / h) (𝓝[≠] 0) (𝓝 (-σ)) := by + refine (tendsto_exp_sub_one_div (-σ)).congr' ?_ + filter_upwards with h + rw [show -σ * h = -(σ * h) from by ring] + have h_num_tendsto : Tendsto + (fun h : ℝ ↦ (Real.exp (r * h^2) - 1) / h - (Real.exp (-(σ * h)) - 1) / h) + (𝓝[≠] 0) (𝓝 σ) := by + have h_sub := (tendsto_exp_sq_sub_one_div_h r).sub h_neg_div + have h_target : ((0 : ℝ) - (-σ)) = σ := by ring + rwa [h_target] at h_sub + have h_denom_tendsto : Tendsto + (fun h : ℝ ↦ (Real.exp (σ * h) - 1) / h - (Real.exp (-(σ * h)) - 1) / h) + (𝓝[≠] 0) (𝓝 (2 * σ)) := by + have h_sub := (tendsto_exp_sub_one_div σ).sub h_neg_div + have h_target : ((σ - (-σ)) : ℝ) = 2 * σ := by ring + rwa [h_target] at h_sub + -- Quotient: p_h → σ / (2σ) = 1/2 + have h_2σ_ne : (2 * σ : ℝ) ≠ 0 := by positivity + have h_p_tendsto : + Tendsto (fun h : ℝ ↦ + ((Real.exp (r * h^2) - 1) / h - (Real.exp (-(σ * h)) - 1) / h) + / ((Real.exp (σ * h) - 1) / h - (Real.exp (-(σ * h)) - 1) / h)) + (𝓝[≠] 0) (𝓝 (σ / (2 * σ))) := + h_num_tendsto.div h_denom_tendsto h_2σ_ne + have h_half : σ / (2 * σ) = 1/2 := by field_simp + rw [h_half] at h_p_tendsto + -- Step 2: equate p_h to the closed form p(h) for h ≠ 0 + have h_p_form : ∀ h : ℝ, h ≠ 0 → + ((Real.exp (r * h^2) - 1) / h - (Real.exp (-(σ * h)) - 1) / h) + / ((Real.exp (σ * h) - 1) / h - (Real.exp (-(σ * h)) - 1) / h) + = (Real.exp (r * h^2) - Real.exp (-(σ * h))) / + (Real.exp (σ * h) - Real.exp (-(σ * h))) := by + intro h hh + have hd_ne := h_denom_ne h hh + have h_num_eq : (Real.exp (r * h^2) - 1) / h - (Real.exp (-(σ * h)) - 1) / h + = (Real.exp (r * h^2) - Real.exp (-(σ * h))) / h := by + rw [← sub_div] + congr 1; ring + have h_den_eq : (Real.exp (σ * h) - 1) / h - (Real.exp (-(σ * h)) - 1) / h + = (Real.exp (σ * h) - Real.exp (-(σ * h))) / h := by ring + rw [h_num_eq, h_den_eq] + field_simp + -- Step 3: compose with h_n = √(T/n) → 0+ + have h_h_n_tendsto : Tendsto (fun n : ℕ ↦ Real.sqrt (crrStep T n)) atTop (𝓝[≠] 0) := by + refine tendsto_nhdsWithin_iff.mpr ⟨tendsto_sqrt_crrStep_zero T, ?_⟩ + filter_upwards [Filter.eventually_ge_atTop 1] with n hn + have h_n_pos : (0 : ℝ) < n := by exact_mod_cast hn + have h_step_pos : 0 < crrStep T n := div_pos hT h_n_pos + exact (Real.sqrt_pos.mpr h_step_pos).ne' + have h_comp := h_p_tendsto.comp h_h_n_tendsto + -- Step 4: Show crrProb r σ T n = (the composed expression at √(T/n)) for n ≥ 1 + refine h_comp.congr' ?_ + filter_upwards [Filter.eventually_ge_atTop 1] with n hn + have h_n_pos : (0 : ℝ) < n := by exact_mod_cast hn + have h_step_pos : 0 < crrStep T n := div_pos hT h_n_pos + have h_sqrt_pos : 0 < Real.sqrt (crrStep T n) := Real.sqrt_pos.mpr h_step_pos + have h_sqrt_ne : Real.sqrt (crrStep T n) ≠ 0 := h_sqrt_pos.ne' + have h_sqrt_sq : Real.sqrt (crrStep T n) ^ 2 = crrStep T n := + Real.sq_sqrt h_step_pos.le + -- Show: crrProb r σ T n = [the composition output] + -- Compose pulls back through `h_p_form` once we identify rT/n with r·(√(T/n))² etc. + change ((fun h : ℝ ↦ + ((Real.exp (r * h^2) - 1) / h - (Real.exp (-(σ * h)) - 1) / h) + / ((Real.exp (σ * h) - 1) / h - (Real.exp (-(σ * h)) - 1) / h)) + ∘ fun n : ℕ ↦ Real.sqrt (crrStep T n)) n = crrProb r σ T n + simp only [Function.comp_apply] + rw [h_p_form (Real.sqrt (crrStep T n)) h_sqrt_ne] + unfold crrProb crrUp crrDown crrPerStepRate + congr 2 + rw [h_sqrt_sq] + +/-! ### Variance limit -/ + +/-- **Variance limit**: `n · σ² · (T/n) · 4 p_n (1 − p_n) → σ² T` as `n → ∞`. + +Equivalently, the per-step variance of the log-return matches the BS variance to +leading order. Follows directly from `crrProb_tendsto_half` and limit arithmetic. + +The formula simplifies: `n · σ² · (T/n) · 4 p_n (1 − p_n) = 4 σ² T · p_n (1 − p_n)`. -/ +theorem crr_variance_limit {σ T r : ℝ} (hσ : 0 < σ) (hT : 0 < T) : + Tendsto (fun n : ℕ ↦ 4 * σ^2 * T * (crrProb r σ T n) * (1 - crrProb r σ T n)) + atTop (𝓝 (σ^2 * T)) := by + have h_p := crrProb_tendsto_half (r := r) hσ hT + have h_1_minus_p : Tendsto (fun n : ℕ ↦ 1 - crrProb r σ T n) atTop (𝓝 (1/2)) := by + have h_const : Tendsto (fun _ : ℕ ↦ (1 : ℝ)) atTop (𝓝 1) := tendsto_const_nhds + have := h_const.sub h_p + have h_target : (1 - 1/2 : ℝ) = 1/2 := by norm_num + rwa [h_target] at this + have h_prod := h_p.mul h_1_minus_p + -- h_prod : Tendsto (p_n * (1 - p_n)) atTop (𝓝 ((1/2) * (1/2))) = (𝓝 (1/4)) + have h_const_mul : Tendsto + (fun n : ℕ ↦ 4 * σ^2 * T * (crrProb r σ T n * (1 - crrProb r σ T n))) + atTop (𝓝 (4 * σ^2 * T * (1/2 * (1/2)))) := h_prod.const_mul _ + have h_target_eq : (4 * σ^2 * T * (1/2 * (1/2)) : ℝ) = σ^2 * T := by ring + rw [h_target_eq] at h_const_mul + refine h_const_mul.congr' ?_ + filter_upwards with n + ring + +/-! ### Full pricing convergence (done elsewhere) + +The `binomialPrice → bs_call_price` convergence is **proved** in +`Models/Binomial/CRRCharFun.lean` (`binomialPrice_call_tendsto_bs`) via a +characteristic-function/Lévy route plus put-call parity — no triangular-array +CLT needed. The drift limit `n · (2 p_n − 1) · σ √Δt → (r − σ²/2) T` is proved +in `Models/Binomial/DriftLimit.lean` (`crr_drift_limit_n`); the variance limit +`crr_variance_limit` is above. Together they pin the matched BS log-return +moments feeding that convergence. -/ + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/CRRDiscreteIto.lean b/LeanPool/MathFin/Models/Binomial/CRRDiscreteIto.lean new file mode 100644 index 0000000000..acd43ffc17 --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/CRRDiscreteIto.lean @@ -0,0 +1,225 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.CRRCharFun +public import Mathlib.MeasureTheory.Order.Group.Lattice + +/-! +# Mean and variance of the CRR log-return law, and their Black–Scholes limits + +`Models/Binomial/CRRCharFun.lean` defines the law of one CRR risk-neutral log-return step, +`crrStepMeasure r σ T n` (mass `pₙ = crrProb r σ T n` at `+σ√(T/n)` and `1 − pₙ` at +`−σ√(T/n)`), takes the law of the `n`-step log-return to be its `n`-fold convolution +`convPow (crrStepMeasure r σ T n) n`, and proves that this law converges weakly to the +Black–Scholes normal `N((r − σ²/2)T, σ²T)` (`crr_tendsto_gaussian_inDistribution`). Weak +convergence does not by itself carry moments along. This file proves that the first two do +converge: the mean and the variance of the `n`-step law tend to `(r − σ²/2)T` and `σ²T`, the +mean and variance of the limit law (`crrRowLaw_moments_tendsto`). + +The route is general first. For a probability law `ν` on `ℝ` carried by a bounded interval, +bounded support propagates through convolution (`ae_abs_le_convPow`), so polynomials are +integrable, and the `k`-fold convolution has mean `k·E_ν[X]` and variance `k·Var_ν(X)` +(`integral_id_convPow`, `variance_convPow`, from `integral_conv`). For the CRR step these are +`(2pₙ − 1)σ√(T/n)` and `4pₙ(1 − pₙ)σ²T/n` (`integral_id_crrStepMeasure`, +`variance_id_crrStepMeasure`), so the `n`-step moments are `n(2pₙ − 1)σ√(T/n)` and +`4σ²T·pₙ(1 − pₙ)`, whose limits are `crr_drift_limit_n` and `crr_variance_limit`. + +## Main results + +* `integrable_of_continuous_of_ae_abs_le`, `ae_abs_le_conv`, `ae_abs_le_convPow`: bounded + support and integrability through convolution powers. +* `integral_id_convPow`, `variance_convPow`: mean and variance of a convolution power. +* `integral_id_crrStepMeasure`, `variance_id_crrStepMeasure`: mean and variance of the CRR step. +* `crrRowLaw_moments_tendsto`: mean and variance of the `n`-step CRR log-return law converge to + those of `N((r − σ²/2)T, σ²T)`. + +## References + +* [J. C. Cox, S. A. Ross and M. Rubinstein, *Option pricing: a simplified + approach*][CoxRossRubinstein1979] + +## Tags + +log-return moments, convolution power, mean and variance, Cox–Ross–Rubinstein, weak convergence, +moment convergence, MSC 91G20, MSC 60F05, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Filter +open scoped Topology + +/-! ### Moments of convolution powers of a boundedly supported law -/ + +section ConvolutionMoments + +/-- A continuous function is integrable against a finite measure carried by a bounded +interval. -/ +lemma integrable_of_continuous_of_ae_abs_le {μ : Measure ℝ} [IsFiniteMeasure μ] {c : ℝ} + (hμ : ∀ᵐ x ∂μ, |x| ≤ c) {g : ℝ → ℝ} (hg : Continuous g) : Integrable g μ := by + obtain ⟨C, hC⟩ := (isCompact_Icc (a := -c) (b := c)).exists_bound_of_continuousOn + hg.continuousOn + exact Integrable.of_bound hg.aestronglyMeasurable C (hμ.mono fun x hx ↦ hC x (abs_le.mp hx)) + +/-- Bounded support adds under convolution: if `|x| ≤ c` `μ`-a.e. and `|y| ≤ a` `ν`-a.e., then +`|z| ≤ c + a` `(μ ∗ ν)`-a.e. -/ +lemma ae_abs_le_conv {μ ν : Measure ℝ} {c a : ℝ} (hμ : ∀ᵐ x ∂μ, |x| ≤ c) + (hν : ∀ᵐ y ∂ν, |y| ≤ a) : ∀ᵐ z ∂(μ ∗ ν), |z| ≤ c + a := by + refine (ae_map_iff (by fun_prop) (measurableSet_le (by fun_prop) (by fun_prop))).2 ?_ + filter_upwards [(Measure.quasiMeasurePreserving_fst (μ := μ) (ν := ν)).ae hμ, + (Measure.quasiMeasurePreserving_snd (μ := μ) (ν := ν)).ae hν] with p h₁ h₂ + exact (abs_add_le _ _).trans (add_le_add h₁ h₂) + +/-- Bounded support propagates through convolution powers: if `|y| ≤ a` `ν`-a.e., then +`|x| ≤ k·a` almost everywhere for `convPow ν k`. -/ +lemma ae_abs_le_convPow {ν : Measure ℝ} {a : ℝ} (hν : ∀ᵐ y ∂ν, |y| ≤ a) : + ∀ k : ℕ, ∀ᵐ x ∂(convPow ν k), |x| ≤ k * a + | 0 => by simp [convPow, ae_dirac_eq] + | k + 1 => by + rw [convPow] + exact (ae_abs_le_conv (ae_abs_le_convPow hν k) hν).mono fun x hx ↦ by + rwa [Nat.cast_succ, add_one_mul] + +variable {ν : Measure ℝ} [IsProbabilityMeasure ν] {a : ℝ} + +/-- One convolution step against a boundedly supported law: the means add, and the second +moment picks up the cross term `2·E_μ[X]·E_ν[Y]`. -/ +lemma integral_id_and_sq_conv {μ : Measure ℝ} [IsProbabilityMeasure μ] {c : ℝ} + (hμ : ∀ᵐ x ∂μ, |x| ≤ c) (hν : ∀ᵐ y ∂ν, |y| ≤ a) : + ∫ z, z ∂(μ ∗ ν) = ∫ x, x ∂μ + ∫ y, y ∂ν ∧ + ∫ z, z ^ 2 ∂(μ ∗ ν) + = ∫ x, x ^ 2 ∂μ + 2 * (∫ x, x ∂μ) * (∫ y, y ∂ν) + ∫ y, y ^ 2 ∂ν := by + have hconv := ae_abs_le_conv hμ hν + have hμ1 := integrable_of_continuous_of_ae_abs_le hμ continuous_id' + have hμ2 := integrable_of_continuous_of_ae_abs_le hμ (continuous_pow 2) + have hν1 := integrable_of_continuous_of_ae_abs_le hν continuous_id' + have hν2 := integrable_of_continuous_of_ae_abs_le hν (continuous_pow 2) + constructor + · rw [integral_conv (integrable_of_continuous_of_ae_abs_le hconv continuous_id')] + have hin (x : ℝ) : ∫ y, (x + y) ∂ν = x + ∫ y, y ∂ν := by + rw [integral_add (integrable_const x) hν1, integral_const, probReal_univ, one_smul] + simp_rw [hin] + rw [integral_add hμ1 (integrable_const _), integral_const, probReal_univ, one_smul] + · rw [integral_conv (integrable_of_continuous_of_ae_abs_le hconv (continuous_pow 2))] + have hin (x : ℝ) : + ∫ y, (x + y) ^ 2 ∂ν = x ^ 2 + 2 * x * ∫ y, y ∂ν + ∫ y, y ^ 2 ∂ν := by + rw [show (fun y ↦ (x + y) ^ 2) = fun y ↦ (x ^ 2 + 2 * x * y) + y ^ 2 from + funext fun y ↦ by ring, + integral_add (show Integrable (fun y ↦ x ^ 2 + 2 * x * y) ν from + (integrable_const (x ^ 2)).add (hν1.const_mul (2 * x))) hν2, + integral_add (integrable_const (x ^ 2)) (hν1.const_mul (2 * x)), integral_const_mul, + integral_const, probReal_univ, one_smul] + simp_rw [hin] + have hμ1' : Integrable (fun x ↦ 2 * x * ∫ y, y ∂ν) μ := (hμ1.const_mul 2).mul_const _ + rw [integral_add (show Integrable (fun x ↦ x ^ 2 + 2 * x * ∫ y, y ∂ν) μ from + hμ2.add hμ1') (integrable_const _), + integral_add hμ2 hμ1', integral_mul_const, integral_const_mul, integral_const, + probReal_univ, one_smul] + +/-- **Mean and variance of a convolution power**, in moment form: for a probability law `ν` +carried by a bounded interval, `E[X] = k·E_ν[X]` and `E[X²] − E[X]² = k·(E_ν[X²] − E_ν[X]²)` +under `convPow ν k`. -/ +lemma convPow_moments (hν : ∀ᵐ y ∂ν, |y| ≤ a) : + ∀ k : ℕ, ∫ x, x ∂(convPow ν k) = k * ∫ y, y ∂ν ∧ + ∫ x, x ^ 2 ∂(convPow ν k) - (∫ x, x ∂(convPow ν k)) ^ 2 + = k * (∫ y, y ^ 2 ∂ν - (∫ y, y ∂ν) ^ 2) + | 0 => by simp [convPow] + | k + 1 => by + have := convPow_isProbabilityMeasure ν k + obtain ⟨h1, h2⟩ := convPow_moments hν k + obtain ⟨c1, c2⟩ := integral_id_and_sq_conv (ae_abs_le_convPow hν k) hν + rw [h1] at h2 + rw [convPow, c1, c2, h1] + push_cast + exact ⟨by ring, by linear_combination h2⟩ + +/-- **The mean of a convolution power**: `E[X] = k·E_ν[X]` under `convPow ν k`, for a +probability law `ν` carried by a bounded interval. -/ +lemma integral_id_convPow (hν : ∀ᵐ y ∂ν, |y| ≤ a) (k : ℕ) : + ∫ x, x ∂(convPow ν k) = k * ∫ y, y ∂ν := + (convPow_moments hν k).1 + +/-- The variance of a law carried by a bounded interval, in moment form. -/ +lemma variance_id_eq_of_ae_abs_le {μ : Measure ℝ} [IsProbabilityMeasure μ] {c : ℝ} + (hμ : ∀ᵐ x ∂μ, |x| ≤ c) : + variance id μ = ∫ x, x ^ 2 ∂μ - (∫ x, x ∂μ) ^ 2 := by + rw [variance_eq_sub (MemLp.of_bound continuous_id.aestronglyMeasurable c + (hμ.mono fun x hx ↦ by simpa [Real.norm_eq_abs] using hx))] + rfl + +/-- **The variance of a convolution power**: `Var(convPow ν k) = k·Var(ν)`, for a probability +law `ν` carried by a bounded interval. -/ +lemma variance_convPow (hν : ∀ᵐ y ∂ν, |y| ≤ a) (k : ℕ) : + variance id (convPow ν k) = k * variance id ν := by + have := convPow_isProbabilityMeasure ν k + rw [variance_id_eq_of_ae_abs_le (ae_abs_le_convPow hν k), variance_id_eq_of_ae_abs_le hν] + exact (convPow_moments hν k).2 + +end ConvolutionMoments + +/-! ### The CRR step law and its `n`-step convolution -/ + +/-- The CRR step law is carried by `[−|σ√(T/n)|, |σ√(T/n)|]`. -/ +lemma crrStepMeasure_ae_abs_le (r σ T : ℝ) (n : ℕ) : + ∀ᵐ x ∂(crrStepMeasure r σ T n), |x| ≤ |σ * Real.sqrt (T / n)| := by + rw [crrStepMeasure, ae_add_measure_iff] + exact ⟨Measure.ae_smul_measure (by simp [ae_dirac_eq]) _, + Measure.ae_smul_measure (by simp [ae_dirac_eq]) _⟩ + +/-- **The mean of one CRR log-return step**: `(2pₙ − 1)·σ√(T/n)`, for `0 ≤ pₙ ≤ 1`. -/ +lemma integral_id_crrStepMeasure {r σ T : ℝ} {n : ℕ} (hp0 : 0 ≤ crrProb r σ T n) + (hp1 : crrProb r σ T n ≤ 1) : + ∫ x, x ∂(crrStepMeasure r σ T n) = (2 * crrProb r σ T n - 1) * (σ * Real.sqrt (T / n)) := by + rw [integral_crrStepMeasure hp0 hp1 fun x ↦ x] + ring + +/-- **The variance of one CRR log-return step**: `4pₙ(1 − pₙ)·(σ√(T/n))²`, for `0 ≤ pₙ ≤ 1`. -/ +lemma variance_id_crrStepMeasure {r σ T : ℝ} {n : ℕ} (hp0 : 0 ≤ crrProb r σ T n) + (hp1 : crrProb r σ T n ≤ 1) : + variance id (crrStepMeasure r σ T n) + = 4 * crrProb r σ T n * (1 - crrProb r σ T n) * (σ * Real.sqrt (T / n)) ^ 2 := by + have := isProbabilityMeasure_crrStepMeasure hp0 hp1 + rw [variance_id_eq_of_ae_abs_le (crrStepMeasure_ae_abs_le r σ T n), + integral_crrStepMeasure hp0 hp1 fun x ↦ x ^ 2, integral_id_crrStepMeasure hp0 hp1] + ring + +/-- **Mean and variance of the `n`-step CRR log-return law converge to those of the +Black–Scholes limit.** For `σ, T > 0`, as `n → ∞` the mean and the variance of +`convPow (crrStepMeasure r σ T n) n` converge to the mean `(r − σ²/2)T` and the variance `σ²T` +of `N((r − σ²/2)T, σ²T)` (`bsLimitProbMeasure`), the weak limit of the same laws +(`crr_tendsto_gaussian_inDistribution`). No no-arbitrage hypothesis is needed: `pₙ → 1/2` +(`crrProb_tendsto_half`), so the step law is a probability measure for all large `n`. -/ +theorem crrRowLaw_moments_tendsto {r σ T : ℝ} (hσ : 0 < σ) (hT : 0 < T) : + Tendsto (fun n : ℕ ↦ ∫ x, x ∂(convPow (crrStepMeasure r σ T n) n)) atTop + (𝓝 (∫ x, x ∂(gaussianReal ((r - σ ^ 2 / 2) * T) (σ ^ 2 * T).toNNReal))) ∧ + Tendsto (fun n : ℕ ↦ variance id (convPow (crrStepMeasure r σ T n) n)) atTop + (𝓝 (variance id (gaussianReal ((r - σ ^ 2 / 2) * T) (σ ^ 2 * T).toNNReal))) := by + rw [integral_id_gaussianReal, variance_id_gaussianReal, + Real.coe_toNNReal _ (mul_nonneg (sq_nonneg σ) hT.le)] + have hp : ∀ᶠ n : ℕ in atTop, crrProb r σ T n ∈ Set.Ioo 0 1 := + (crrProb_tendsto_half (r := r) hσ hT).eventually_mem (Ioo_mem_nhds (by norm_num) (by norm_num)) + constructor + · refine (crr_drift_limit_n hσ hT).congr' ?_ + filter_upwards [hp] with n hn + have := isProbabilityMeasure_crrStepMeasure hn.1.le hn.2.le + rw [integral_id_convPow (crrStepMeasure_ae_abs_le r σ T n) n, + integral_id_crrStepMeasure hn.1.le hn.2.le] + ring + · refine (crr_variance_limit (r := r) hσ hT).congr' ?_ + filter_upwards [hp, eventually_gt_atTop 0] with n hn hn0 + have := isProbabilityMeasure_crrStepMeasure hn.1.le hn.2.le + have hcancel : (n : ℝ) * (T / n) = T := mul_div_cancel₀ T (Nat.cast_ne_zero.mpr hn0.ne') + rw [variance_convPow (crrStepMeasure_ae_abs_le r σ T n) n, + variance_id_crrStepMeasure hn.1.le hn.2.le, mul_pow, + Real.sq_sqrt (div_nonneg hT.le n.cast_nonneg)] + linear_combination (-(4 * σ ^ 2 * crrProb r σ T n * (1 - crrProb r σ T n))) * hcancel + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/DriftLimit.lean b/LeanPool/MathFin/Models/Binomial/DriftLimit.lean new file mode 100644 index 0000000000..6d1add7266 --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/DriftLimit.lean @@ -0,0 +1,216 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.CRRConvergence +public import Mathlib.Algebra.Order.Ring.Star + +/-! +# CRR drift limit (Phase 3 closeout) + +This file proves the second classical-analytic step of the CRR-to-BS +correspondence (the variance step `crr_variance_limit` is already in +`BinomialCRRConvergence.lean`): + + `n · (2 p_n − 1) · σ √(T/n) → (r − σ² / 2) T` as `n → ∞`. + +This combined with `crrProb_tendsto_half` and `crr_variance_limit` pins down +the BS log-return moments matched by the CRR tree. Full distributional +convergence `binomialPrice → bs_call_price` is proved in +`Models/Binomial/CRRCharFun.lean` (`binomialPrice_call_tendsto_bs`), via a +characteristic-function/Lévy route plus put-call parity. + +## Main results + +* `tendsto_exp_sym_sub_two_div_sq`: `(e^{σh} + e^{-σh} − 2) / h² → σ²` + as `h → 0`. Uses the algebraic identity + `e^{σh} + e^{-σh} − 2 = e^{−σh} · (e^{σh} − 1)²` to reduce to existing + `tendsto_exp_sub_one_div`. +* `tendsto_crr_drift_quotient` / `crr_drift_limit_n`: the headline + `n · (2 p_n − 1) · σ √(T/n) → (r − σ²/2) T`, in `h`-parametrised and + `n`-indexed form. + +## References + +* [J. C. Cox, S. A. Ross and M. Rubinstein, *Option pricing: a simplified + approach*][CoxRossRubinstein1979] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 13.4; 21.1 +* [S. E. Shreve, *Stochastic Calculus for Finance I: The Binomial Asset Pricing Model*][ShreveSCFI], + 3.2 + +## Tags + +Cox–Ross–Rubinstein, drift limit, risk-neutral drift, binomial to Black–Scholes, log-return mean, +MSC 91G20, MSC 60F05, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Real Filter +open scoped Topology + +/-- **The cosh-like difference**: `(e^{σh} + e^{−σh} − 2) / h² → σ²` as `h → 0`. + +Algebraic identity `e^{σh} + e^{−σh} − 2 = e^{−σh} · (e^{σh} − 1)²` reduces this +to a product of three existing limits: `e^{−σh} → 1`, `(e^{σh} − 1)/h → σ`, +and squaring is continuous. -/ +lemma tendsto_exp_sym_sub_two_div_sq (σ : ℝ) : + Tendsto (fun h : ℝ ↦ (Real.exp (σ * h) + Real.exp (-(σ * h)) - 2) / h^2) + (𝓝[≠] 0) (𝓝 (σ^2)) := by + -- Building blocks. + have h_exp_neg : Tendsto (fun h : ℝ ↦ Real.exp (-(σ * h))) (𝓝[≠] 0) (𝓝 1) := by + have h_cont : Continuous (fun h : ℝ ↦ Real.exp (-(σ * h))) := by continuity + have h_at_zero : Real.exp (-(σ * 0)) = 1 := by simp [Real.exp_zero] + have h_tendsto : Tendsto (fun h : ℝ ↦ Real.exp (-(σ * h))) (𝓝 0) (𝓝 1) := by + rw [show (1 : ℝ) = Real.exp (-(σ * 0)) from h_at_zero.symm] + exact h_cont.tendsto 0 + exact h_tendsto.mono_left nhdsWithin_le_nhds + have h_exp_diff : Tendsto (fun h : ℝ ↦ (Real.exp (σ * h) - 1) / h) (𝓝[≠] 0) (𝓝 σ) := + tendsto_exp_sub_one_div σ + have h_exp_diff_sq : Tendsto (fun h : ℝ ↦ ((Real.exp (σ * h) - 1) / h)^2) + (𝓝[≠] 0) (𝓝 (σ^2)) := h_exp_diff.pow 2 + have h_prod := h_exp_neg.mul h_exp_diff_sq + have h_target : (1 : ℝ) * σ^2 = σ^2 := one_mul _ + rw [h_target] at h_prod + -- Now show pointwise that `e^{-σh} · ((e^{σh}-1)/h)² = (e^{σh} + e^{-σh} - 2)/h²`. + refine h_prod.congr' ?_ + filter_upwards [self_mem_nhdsWithin] with h hh + have hh_ne : h ≠ 0 := hh + have h_sq_ne : h^2 ≠ 0 := pow_ne_zero 2 hh_ne + -- (e^{σh}-1)/h squared = (e^{σh}-1)² / h² + -- Goal: (e^σh + e^{-σh} - 2)/h² = e^{-σh} · ((e^σh - 1)/h)² + rw [div_pow, mul_div_assoc'] + rw [div_eq_div_iff h_sq_ne h_sq_ne] + -- Goal after div_eq_div_iff: (e^σh + e^{-σh} - 2) · h² = e^{-σh} · (e^σh - 1)² · h² + -- The h² factors cancel, leaving the algebraic identity. + have h_exp_id : Real.exp (-(σ * h)) * Real.exp (σ * h) = 1 := by + rw [← Real.exp_add, neg_add_cancel, Real.exp_zero] + -- Move h² to one side then linear_combination handles the rest. + have h_alg : Real.exp (σ * h) + Real.exp (-(σ * h)) - 2 + = Real.exp (-(σ * h)) * (Real.exp (σ * h) - 1)^2 := by + linear_combination -(Real.exp (σ * h) - 2) * h_exp_id + rw [h_alg] + +/-- **Numerator-of-`2p−1` limit**: `(2 e^{rh²} − e^{σh} − e^{−σh}) / h² → 2r − σ²`. + +Combines `tendsto_exp_sq_sub_one_div_sq r` (gives `(e^{rh²}-1)/h² → r`) with +`tendsto_exp_sym_sub_two_div_sq σ` (gives `(e^{σh}+e^{-σh}-2)/h² → σ²`). -/ +lemma tendsto_crr_numerator_div_sq (σ r : ℝ) : + Tendsto (fun h : ℝ ↦ + (2 * Real.exp (r * h^2) - Real.exp (σ * h) - Real.exp (-(σ * h))) / h^2) + (𝓝[≠] 0) (𝓝 (2 * r - σ^2)) := by + have h_exp_sq := tendsto_exp_sq_sub_one_div_sq r + -- 2 · (e^{rh²} - 1)/h² → 2r + have h_2exp_sq : Tendsto (fun h : ℝ ↦ 2 * ((Real.exp (r * h^2) - 1) / h^2)) + (𝓝[≠] 0) (𝓝 (2 * r)) := h_exp_sq.const_mul 2 + have h_sym := tendsto_exp_sym_sub_two_div_sq σ + have h_diff := h_2exp_sq.sub h_sym + refine h_diff.congr' ?_ + filter_upwards [self_mem_nhdsWithin] with h hh + have hh_ne : h ≠ 0 := hh + have h_sq_ne : h^2 ≠ 0 := pow_ne_zero 2 hh_ne + field_simp + ring + +/-- **Drift-quotient limit (continuous form)**: as `h → 0` (`h ≠ 0`), +`(2 e^{rh²} − e^{σh} − e^{−σh}) / (h · (e^{σh} − e^{−σh})) → (r − σ²/2) / σ`. + +Quotient of `tendsto_crr_numerator_div_sq r` and `tendsto_sinh_div σ`. -/ +lemma tendsto_crr_drift_quotient {σ : ℝ} (hσ : σ ≠ 0) (r : ℝ) : + Tendsto (fun h : ℝ ↦ + (2 * Real.exp (r * h^2) - Real.exp (σ * h) - Real.exp (-(σ * h))) + / (h * (Real.exp (σ * h) - Real.exp (-(σ * h))))) + (𝓝[≠] 0) (𝓝 ((r - σ^2 / 2) / σ)) := by + have h_num := tendsto_crr_numerator_div_sq σ r + have h_den := tendsto_sinh_div σ + have h_2σ : (2 * σ : ℝ) ≠ 0 := by + intro h; apply hσ; linarith + have h_quot := h_num.div h_den h_2σ + -- h_quot : Tendsto (fun h ↦ (Num/h²) / ((e^{σh}-e^{-σh})/h)) (𝓝[≠] 0) (𝓝 ((2r-σ²)/(2σ))) + have h_target : (2 * r - σ^2) / (2 * σ) = (r - σ^2 / 2) / σ := by + field_simp + rw [h_target] at h_quot + refine h_quot.congr' ?_ + filter_upwards [self_mem_nhdsWithin] with h hh + have hh_ne : h ≠ 0 := hh + have h_sq_ne : h^2 ≠ 0 := pow_ne_zero 2 hh_ne + -- Goal: ((Num h / h²) / ((sinh-like)/h)) = Num h / (h · (sinh-like)) + change (2 * Real.exp (r * h^2) - Real.exp (σ * h) - Real.exp (-(σ * h))) / h^2 + / ((Real.exp (σ * h) - Real.exp (-(σ * h))) / h) + = _ + rcases eq_or_ne (Real.exp (σ * h) - Real.exp (-(σ * h))) 0 with hden0 | hden0 + · simp [hden0] + · field_simp + +/-- **CRR drift limit (textbook n-form)**: as `n → ∞`, +`n · (2 p_n − 1) · σ · √(T/n) → (r − σ²/2) · T`. + +The substitution `h_n = √(T/n)` reduces this to `tendsto_crr_drift_quotient` scaled by +`σ T`, using the algebraic identity `n · (√(T/n))² = T`. -/ +theorem crr_drift_limit_n {σ T r : ℝ} (hσ : 0 < σ) (hT : 0 < T) : + Tendsto (fun n : ℕ ↦ + (n : ℝ) * (2 * crrProb r σ T n - 1) * σ * Real.sqrt (T / n)) + atTop (𝓝 ((r - σ^2 / 2) * T)) := by + have h_sqrt_step : Tendsto (fun n : ℕ ↦ Real.sqrt (crrStep T n)) atTop (𝓝[≠] 0) := by + have h_to_zero : Tendsto (fun n : ℕ ↦ Real.sqrt (crrStep T n)) atTop (𝓝 0) := + tendsto_sqrt_crrStep_zero T + refine tendsto_nhdsWithin_iff.mpr ⟨h_to_zero, ?_⟩ + rw [eventually_atTop] + refine ⟨1, fun n hn ↦ ?_⟩ + have h_step_pos : 0 < crrStep T n := by + unfold crrStep + exact div_pos hT (by exact_mod_cast (Nat.lt_of_lt_of_le Nat.zero_lt_one hn)) + have h_sqrt_pos : 0 < Real.sqrt (crrStep T n) := Real.sqrt_pos.mpr h_step_pos + exact h_sqrt_pos.ne' + have h_drift_h := tendsto_crr_drift_quotient (hσ.ne') r + have h_comp := h_drift_h.comp h_sqrt_step + have h_σT : Tendsto (fun n : ℕ ↦ + σ * T * ((2 * Real.exp (r * (Real.sqrt (crrStep T n))^2) + - Real.exp (σ * Real.sqrt (crrStep T n)) + - Real.exp (-(σ * Real.sqrt (crrStep T n)))) + / (Real.sqrt (crrStep T n) + * (Real.exp (σ * Real.sqrt (crrStep T n)) + - Real.exp (-(σ * Real.sqrt (crrStep T n))))))) + atTop (𝓝 (σ * T * ((r - σ^2 / 2) / σ))) := h_comp.const_mul (σ * T) + have h_target : σ * T * ((r - σ^2 / 2) / σ) = (r - σ^2 / 2) * T := by + field_simp + rw [h_target] at h_σT + refine h_σT.congr' ?_ + filter_upwards [Filter.eventually_ge_atTop 1] with n hn + have hn_pos : 0 < (n : ℝ) := by exact_mod_cast (Nat.lt_of_lt_of_le Nat.zero_lt_one hn) + have hn_ne : (n : ℝ) ≠ 0 := hn_pos.ne' + have h_step_pos : 0 < crrStep T n := div_pos hT hn_pos + have h_step_eq : crrStep T n = T / n := rfl + have h_sqrt_sq : Real.sqrt (crrStep T n) ^ 2 = crrStep T n := Real.sq_sqrt h_step_pos.le + have h_sqrt_pos : 0 < Real.sqrt (crrStep T n) := Real.sqrt_pos.mpr h_step_pos + have h_sqrt_ne : Real.sqrt (crrStep T n) ≠ 0 := h_sqrt_pos.ne' + have h_inner_lt : -(σ * Real.sqrt (crrStep T n)) < σ * Real.sqrt (crrStep T n) := by + have h_pos : 0 < σ * Real.sqrt (crrStep T n) := mul_pos hσ h_sqrt_pos + linarith + have hden_pos : + 0 < Real.exp (σ * Real.sqrt (crrStep T n)) + - Real.exp (-(σ * Real.sqrt (crrStep T n))) := + sub_pos.mpr (Real.exp_lt_exp.mpr h_inner_lt) + have hden_ne : + Real.exp (σ * Real.sqrt (crrStep T n)) + - Real.exp (-(σ * Real.sqrt (crrStep T n))) ≠ 0 := hden_pos.ne' + have h_sqrt_eq : Real.sqrt (T / n) = Real.sqrt (crrStep T n) := by + rw [h_step_eq] + unfold crrProb crrUp crrDown crrPerStepRate + rw [h_sqrt_eq] + have h_n_step : (n : ℝ) * crrStep T n = T := by + rw [h_step_eq]; field_simp + field_simp + rw [h_sqrt_sq] + linear_combination + -(2 * Real.exp (r * crrStep T n) - Real.exp (σ * Real.sqrt (crrStep T n)) + - Real.exp (-(σ * Real.sqrt (crrStep T n)))) * h_n_step + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/EuropeanReplication.lean b/LeanPool/MathFin/Models/Binomial/EuropeanReplication.lean new file mode 100644 index 0000000000..45bda40830 --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/EuropeanReplication.lean @@ -0,0 +1,126 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.SnellEnvelope +public import Mathlib.Analysis.Normed.Field.Basic + +/-! +# The discounted tree value and the discounted spot, as one-step martingales + +`binomialPrice u d r g N S₀` is the backward-induction price of the claim that pays `g(S_N)` +after `N` steps. Along a coin-flip path, the **discounted tree value** `discountedTreeValue` +(the tree price with the steps left, at the spot reached, discounted and stopped at `N`) and the +**discounted spot** `discountedSpot` `S_tilde_k = e^{−rk} S_k` are one-step martingales under +the risk-neutral up-probability: the node average `q X_{n+1}(↑) + (1 − q) X_{n+1}(↓)` is `X_n`. +The first is the backward recursion `binomialPrice_succ`, the second is `crrUpProb_mul_up_add`. + +These are the two inputs of the replication theorem `binomialPrice_replication` +(`Models/Binomial/MartingaleRepresentation.lean`): under no-arbitrage the claim's discounted payoff +is its tree price plus the gains of a predictable strategy in the discounted spot. + +## Main definitions + +* `discountedTreeValue` — the discounted tree price of the claim along a path, stopped at `N`. +* `discountedSpot` — the discounted spot `e^{−rk} S_k`. + +## Main results + +* `discountedTreeValue_step`, `discountedSpot_step` — both are one-step martingales under the + risk-neutral up-probability (the node-average identity; `discountedSpot_step` needs + `BinomialNoArb`). +* `discountedSpot_update_ne` — under no-arbitrage and `S₀ ≠ 0` the two children of a node have + different discounted spots (the non-degeneracy the hedge ratio divides by). + +## Tags + +discounted price martingale, backward induction, replicating strategy, risk-neutral probability, +binomial tree, delta hedging, MSC 91G20, MSC 60G42, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +/-- The spot after `k` flips does not see the `n`-th flip, for `k ≤ n`. -/ +lemma spotPath_update_of_le {k n : ℕ} (hkn : k ≤ n) (S₀ u d : ℝ) (ω : ℕ → Bool) (b : Bool) : + spotPath S₀ u d k (Function.update ω n b) = spotPath S₀ u d k ω := + pathAdaptedAt_spotPath S₀ u d k _ _ fun _ hi ↦ Function.update_of_ne (hi.trans_le hkn).ne _ _ + +@[simp] +lemma spotPath_zero (S₀ u d : ℝ) (ω : ℕ → Bool) : spotPath S₀ u d 0 ω = S₀ := by + simp [spotPath] + +/-- The **discounted tree value** of the claim `g(S_N)` along a path, stopped at `N`: at step `n` +it is `e^{−r(n ∧ N)}` times the tree price with `N − n` steps left, at the spot reached by step +`n ∧ N`. -/ +noncomputable def discountedTreeValue (u d r : ℝ) (g : ℝ → ℝ) (N : ℕ) (S₀ : ℝ) (n : ℕ) + (ω : ℕ → Bool) : ℝ := + Real.exp (-(r * (min n N : ℕ))) * binomialPrice u d r g (N - n) (spotPath S₀ u d (min n N) ω) + +/-- The **discounted spot** `S_tilde_n = e^{−rn} S_n`. -/ +noncomputable def discountedSpot (S₀ u d r : ℝ) (n : ℕ) (ω : ℕ → Bool) : ℝ := + Real.exp (-(r * n)) * spotPath S₀ u d n ω + +lemma pathAdaptedAt_discountedTreeValue (u d r : ℝ) (g : ℝ → ℝ) (N : ℕ) (S₀ : ℝ) (n : ℕ) : + PathAdaptedAt n (discountedTreeValue u d r g N S₀ n) := fun ω ω' hω ↦ by + rw [discountedTreeValue, discountedTreeValue, + ((pathAdaptedAt_spotPath S₀ u d _).mono (min_le_left n N)) ω ω' hω] + +lemma pathAdaptedAt_discountedSpot (S₀ u d r : ℝ) (n : ℕ) : + PathAdaptedAt n (discountedSpot S₀ u d r n) := fun ω ω' hω ↦ by + rw [discountedSpot, discountedSpot, pathAdaptedAt_spotPath S₀ u d n ω ω' hω] + +/-- **The discounted tree value is a one-step martingale** under the risk-neutral +up-probability: before `N` this is the backward recursion `binomialPrice_succ`, and from `N` on +the process is frozen. No no-arbitrage hypothesis is needed. -/ +theorem discountedTreeValue_step (u d r : ℝ) (g : ℝ → ℝ) (N : ℕ) (S₀ : ℝ) (n : ℕ) + (ω : ℕ → Bool) : + crrUpProb u d r * discountedTreeValue u d r g N S₀ (n + 1) (Function.update ω n true) + + (1 - crrUpProb u d r) + * discountedTreeValue u d r g N S₀ (n + 1) (Function.update ω n false) + = discountedTreeValue u d r g N S₀ n ω := by + rcases lt_or_ge n N with hn | hn + · obtain ⟨k, rfl⟩ : ∃ k, N = n + 1 + k := ⟨N - (n + 1), by omega⟩ + simp only [discountedTreeValue, show min (n + 1) (n + 1 + k) = n + 1 by omega, + show min n (n + 1 + k) = n by omega, show n + 1 + k - n = k + 1 by omega, + show n + 1 + k - (n + 1) = k by omega, spotPath_update_succ_true, + spotPath_update_succ_false, binomialPrice_succ] + rw [show -(r * ((n + 1 : ℕ) : ℝ)) = -(r * n) + -r by push_cast; ring, Real.exp_add] + ring + · simp only [discountedTreeValue, show min (n + 1) N = N by omega, show min n N = N by omega, + show N - n = 0 by omega, show N - (n + 1) = 0 by omega, spotPath_update_of_le hn] + ring + +/-- **The discounted spot is a one-step martingale** under the risk-neutral up-probability: +`q u + (1 − q) d = eʳ` (`crrUpProb_mul_up_add`). -/ +theorem discountedSpot_step {u d r : ℝ} (h : BinomialNoArb u d r) (S₀ : ℝ) (n : ℕ) + (ω : ℕ → Bool) : + crrUpProb u d r * discountedSpot S₀ u d r (n + 1) (Function.update ω n true) + + (1 - crrUpProb u d r) * discountedSpot S₀ u d r (n + 1) (Function.update ω n false) + = discountedSpot S₀ u d r n ω := by + simp only [discountedSpot, spotPath_update_succ_true, spotPath_update_succ_false] + rw [show -(r * ((n + 1 : ℕ) : ℝ)) = -(r * n) + -r by push_cast; ring, Real.exp_add] + have he : Real.exp (-r) * Real.exp r = 1 := by rw [← Real.exp_add]; simp + linear_combination Real.exp (-(r * n)) * Real.exp (-r) * spotPath S₀ u d n ω + * crrUpProb_mul_up_add u d r h + Real.exp (-(r * n)) * spotPath S₀ u d n ω * he + +/-- Under no-arbitrage and `S₀ ≠ 0`, the two children of a node have different discounted spots. -/ +lemma discountedSpot_update_ne {u d r : ℝ} (h : BinomialNoArb u d r) {S₀ : ℝ} (hS₀ : S₀ ≠ 0) + (n : ℕ) (ω : ℕ → Bool) : + discountedSpot S₀ u d r (n + 1) (Function.update ω n true) + ≠ discountedSpot S₀ u d r (n + 1) (Function.update ω n false) := by + have hS : spotPath S₀ u d n ω ≠ 0 := + mul_ne_zero hS₀ (Finset.prod_ne_zero_iff.2 fun i _ ↦ by + split_ifs + exacts [h.u_pos.ne', h.d_pos.ne']) + simp only [discountedSpot, spotPath_update_succ_true, spotPath_update_succ_false] + intro heq + exact h.d_lt_u.ne' (mul_left_cancel₀ hS (mul_left_cancel₀ (Real.exp_pos _).ne' heq)) + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/FlipPaths.lean b/LeanPool/MathFin/Models/Binomial/FlipPaths.lean new file mode 100644 index 0000000000..583e157b7f --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/FlipPaths.lean @@ -0,0 +1,117 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Basic.Real.Basic +public import Mathlib.Tactic.FieldSimp +public import Mathlib.Tactic.Ring.RingNF + +/-! +# The pathwise language of the binomial tree + +Coin-flip paths `ω : ℕ → Bool`, processes `X : ℕ → (ℕ → Bool) → ℝ`, and the **node average** +`q·X_{n+1}(…,↑) + (1 − q)·X_{n+1}(…,↓)` over the two children of a node, the explicit form of the +conditional expectation for the binomial filtration. This file is the measure-free layer: + +* `PathAdaptedAt n X` — `X` depends only on the first `n` flips. It is the concrete face of + Mathlib's `StronglyMeasurable[flipFiltration n]` (`stronglyMeasurable_flipFiltration_iff`, + `Models/Binomial/PathMeasure.lean`), which is what theorems about martingales state. +* `hedgeRatio M S n ω` — the node-wise delta `ΔM_{n+1} / ΔS_{n+1}` across the two children, and + `repr_one_step`, the one-period delta hedge: under the node-average condition for `M` and `S`, + `M_{n+1} − M_n = hedgeRatio · (S_{n+1} − S_n)` on every path. The argument is purely algebraic. + +The martingale representation theorem built from it, for Mathlib's `Martingale` of the flip +filtration, is `binomial_martingale_representation` +(`Models/Binomial/MartingaleRepresentation.lean`). + +## Main definitions + +* `PathAdaptedAt`: a function of a coin-flip path `ω : ℕ → Bool` is `n`-adapted when it depends + only on the first `n` flips. +* `hedgeRatio`: the node-wise hedge ratio of `M` against `S`, the change in `M` over the change + in `S` across the two children of a node. + +## Main results + +* `PathAdaptedAt.fixFlip`: fixing the `n`-th flip of an `(n + 1)`-adapted function leaves an + `n`-adapted function. +* `PathAdaptedAt.mono`: an `m`-adapted function is `n`-adapted for `m ≤ n`. +* `repr_one_step`: if `M` and `S` satisfy the node-average condition with weight `q` and `S` is + nondegenerate at every node, then `M_{n+1} − M_n = hedgeRatio M S n ω · (S_{n+1} − S_n)`. + +## Tags + +coin-flip paths, node average, delta hedge, binomial filtration, one-period hedge, +conditional expectation on a tree, MSC 91G20, MSC 60G42, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +/-- A real function of an infinite coin-flip path is **`n`-adapted** when it depends only on the +first `n` flips `ω 0, …, ω (n−1)`. -/ +def PathAdaptedAt (n : ℕ) (X : (ℕ → Bool) → ℝ) : Prop := + ∀ ω ω' : ℕ → Bool, (∀ i, i < n → ω i = ω' i) → X ω = X ω' + +/-- Fixing the `n`-th flip of a function of the first `n + 1` flips leaves a function of the +first `n`. -/ +lemma PathAdaptedAt.fixFlip {n : ℕ} {f : (ℕ → Bool) → ℝ} (hf : PathAdaptedAt (n + 1) f) + (b : Bool) : + PathAdaptedAt n fun ω ↦ f (Function.update ω n b) := fun ω ω' h ↦ + hf _ _ fun i hi ↦ by + rcases eq_or_ne i n with rfl | hin + · simp + · rw [Function.update_of_ne hin, Function.update_of_ne hin] + exact h i (by omega) + +/-- A function of the first `m` flips is a function of the first `n`, for `m ≤ n`. -/ +lemma PathAdaptedAt.mono {m n : ℕ} {X : (ℕ → Bool) → ℝ} (h : PathAdaptedAt m X) + (hmn : m ≤ n) : PathAdaptedAt n X := + fun ω ω' hω ↦ h ω ω' fun i hi ↦ hω i (hi.trans_le hmn) + +variable {q : ℝ} {M S : ℕ → (ℕ → Bool) → ℝ} + +/-- The **node-wise hedge ratio** (discrete delta): the change in `M` over the change in `S` +across the up/down children of the level-`n` node carrying path `ω`. -/ +noncomputable def hedgeRatio (M S : ℕ → (ℕ → Bool) → ℝ) (n : ℕ) (ω : ℕ → Bool) : ℝ := + (M (n + 1) (Function.update ω n true) - M (n + 1) (Function.update ω n false)) / + (S (n + 1) (Function.update ω n true) - S (n + 1) (Function.update ω n false)) + +/-- **One-step representation (the node-wise delta hedge).** Under the risk-neutral one-step +condition for `M` and `S` and non-degeneracy of `S`'s branching, the one-period change in `M` +equals the hedge ratio times the one-period change in `S`, on every path. -/ +theorem repr_one_step + (hM_mart : ∀ n ω, q * M (n + 1) (Function.update ω n true) + + (1 - q) * M (n + 1) (Function.update ω n false) = M n ω) + (hS_mart : ∀ n ω, q * S (n + 1) (Function.update ω n true) + + (1 - q) * S (n + 1) (Function.update ω n false) = S n ω) + (hS_nondeg : ∀ n ω, S (n + 1) (Function.update ω n true) + ≠ S (n + 1) (Function.update ω n false)) + (n : ℕ) (ω : ℕ → Bool) : + M (n + 1) ω - M n ω = hedgeRatio M S n ω * (S (n + 1) ω - S n ω) := by + have hne : S (n + 1) (Function.update ω n true) - S (n + 1) (Function.update ω n false) ≠ 0 := + sub_ne_zero.mpr (hS_nondeg n ω) + rw [hedgeRatio, ← hM_mart n ω, ← hS_mart n ω] + by_cases hb : ω n = true + · have hωeq : Function.update ω n true = ω := by + conv_rhs => rw [← Function.update_eq_self n ω] + rw [hb] + rw [hωeq] at hne ⊢ + field_simp + ring + · have hbf : ω n = false := by simpa using hb + have hωeq : Function.update ω n false = ω := by + conv_rhs => rw [← Function.update_eq_self n ω] + rw [hbf] + rw [hωeq] at hne ⊢ + field_simp + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/Girsanov.lean b/LeanPool/MathFin/Models/Binomial/Girsanov.lean new file mode 100644 index 0000000000..1be2e36334 --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/Girsanov.lean @@ -0,0 +1,283 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.PathMeasure +public import LeanPool.MathFin.Probability.Martingales.EquivMeasure + +/-! +# Discrete Girsanov: measure change in the binomial tree + +The continuous-time Girsanov theorem has a transparent discrete-time +counterpart in the binomial model. The one-flip algebra comes first; the same weights, multiplied +over the first `n` flips, are the Radon–Nikodym density between the two coin-flip measures. + +Given physical up-probability `p` and risk-neutral up-probability `q`, the +**Radon-Nikodym derivative** `dQ/dP` takes only two values: + + `Z_up = q / p`, `Z_down = (1 − q) / (1 − p)`. + +The key invariant: `E^P[Z] = 1` (the change of measure preserves total mass). +Plugging in: + + `p · (q/p) + (1 − p) · ((1 − q)/(1 − p)) = q + (1 − q) = 1`. + +This is the *cleanest possible* instance of Girsanov: a finite, two-point +measure change with explicit RN derivative. + +## Why this matters + +Every continuous-time risk-neutral pricing argument is `E^Q[X] = E^P[Z · X]` +for the appropriate `Z = dQ/dP`. In the binomial model the same identity +holds with `Z` as above, and the risk-neutral pricing formula + + `V_0 = e^{−r} · E^Q[V_T] = e^{−r} · E^P[Z · V_T]` + +is just two-state algebra. We make this discrete Girsanov-machinery explicit. + +## Main definitions + +* `binomialRN`: the one-flip Radon–Nikodym derivative `dQ/dP`, equal to `q / p` on an up-flip and + `(1 − q) / (1 − p)` on a down-flip. +* `binomialDensity`: the density process `Z_n(ω) = ∏_{i q / p + | false => (1 - q) / (1 - p) + +/-- **The one-flip change of measure**: the `P`-probability of a flip outcome times the density +is its `Q`-probability, `P(b) · Z(b) = Q(b)`. Every identity in this file is this one, summed over +the two outcomes (`binomialRN_expectation_one`, `binomial_riskNeutral_via_RN`) or multiplied +over the flips (`map_flips_coinFlipMeasure_eq_withDensity`). -/ +lemma weight_mul_binomialRN {p q : ℝ} (hp : p ≠ 0) (hp1 : p ≠ 1) (b : Bool) : + (if b then p else 1 - p) * binomialRN p q b = if b then q else 1 - q := by + have h1p : 1 - p ≠ 0 := sub_ne_zero.mpr (Ne.symm hp1) + cases b + · simp only [binomialRN, Bool.false_eq_true, ↓reduceIte] + field_simp + · simp only [binomialRN, ↓reduceIte] + field_simp + +lemma binomialRN_nonneg {p q : ℝ} (hp : 0 ≤ p) (hp1 : p < 1) (hq : 0 ≤ q) (hq1 : q ≤ 1) + (b : Bool) : 0 ≤ binomialRN p q b := by + cases b + · exact div_nonneg (sub_nonneg.2 hq1) (sub_nonneg.2 hp1.le) + · exact div_nonneg hq hp + +lemma binomialRN_pos {p q : ℝ} (hp : 0 < p) (hp1 : p < 1) (hq : 0 < q) (hq1 : q < 1) (b : Bool) : + 0 < binomialRN p q b := by + cases b + · exact div_pos (sub_pos.2 hq1) (sub_pos.2 hp1) + · exact div_pos hq hp + +/-- **RN normalisation**: `E^P[Z] = 1`, i.e. +`p · (q/p) + (1 − p) · ((1 − q)/(1 − p)) = 1`. + +This is the universal "the change of measure preserves total mass" +property, here in two-state form. -/ +theorem binomialRN_expectation_one (p q : ℝ) + (hp : p ≠ 0) (hp1 : p ≠ 1) : + p * binomialRN p q true + (1 - p) * binomialRN p q false = 1 := by + have h1 := weight_mul_binomialRN (q := q) hp hp1 true + have h0 := weight_mul_binomialRN (q := q) hp hp1 false + simp only [↓reduceIte, Bool.false_eq_true] at h1 h0 + linear_combination h1 + h0 + +/-- **Discrete Girsanov pricing identity**: under the binomial measure change, +the `Q`-expectation of any payoff equals the `P`-expectation of `Z · payoff`, +where `Z = dQ/dP`: + + `E^Q[V] = q · V_u + (1−q) · V_d = E^P[Z · V] = p · (q/p) · V_u + (1−p) · ((1−q)/(1−p)) · V_d`. + +(Both sides simplify to `q · V_u + (1 − q) · V_d`.) -/ +theorem binomial_riskNeutral_via_RN (p q V_u V_d : ℝ) + (hp : p ≠ 0) (hp1 : p ≠ 1) : + q * V_u + (1 - q) * V_d = + p * binomialRN p q true * V_u + (1 - p) * binomialRN p q false * V_d := by + have h1 := weight_mul_binomialRN (q := q) hp hp1 true + have h0 := weight_mul_binomialRN (q := q) hp hp1 false + simp only [↓reduceIte, Bool.false_eq_true] at h1 h0 + linear_combination (-V_u) * h1 + (-V_d) * h0 + +/-- The **density process** `Z_n(ω) = ∏_{i simp [hq1r] + have hwp (b : Bool) : 0 ≤ if b then (p : ℝ) else 1 - p := by cases b <;> simp [hp1r.le] + have hprod : 0 ≤ ∏ i, binomialRN p q (x i) := + prod_nonneg fun i _ ↦ binomialRN_nonneg p.2 hp1r q.2 hq1r (x i) + rw [← ENNReal.ofReal_prod_of_nonneg fun i _ ↦ hwq (x i), + ← ENNReal.ofReal_prod_of_nonneg fun i _ ↦ hwp (x i), ← ENNReal.ofReal_mul hprod] + congr 1 + rw [← prod_mul_distrib] + exact prod_congr rfl fun i _ ↦ + ((weight_mul_binomialRN (q := q) hp0' hp1' (x i)).symm.trans (mul_comm _ _)) + +/-- **Equivalence of the two coin-flip laws on `n` flips.** For `0 < p < 1` and `0 < q < 1` the +density `∏ᵢ binomialRN p q (xᵢ)` is strictly positive, so the laws of the first `n` flips under +`Bernoulli(q)` and `Bernoulli(p)` are mutually absolutely continuous. -/ +theorem map_flips_coinFlipMeasure_equiv (hp0 : 0 < p) (hp : p < 1) (hq0 : 0 < q) (hq : q < 1) + (n : ℕ) : + (coinFlipMeasure q hq.le).map (flips n) ≪ (coinFlipMeasure p hp.le).map (flips n) ∧ + (coinFlipMeasure p hp.le).map (flips n) ≪ (coinFlipMeasure q hq.le).map (flips n) := by + rw [map_flips_coinFlipMeasure_eq_withDensity hp0 hp hq.le n] + exact ⟨withDensity_absolutelyContinuous _ _, + absolutelyContinuous_withDensity_ofReal _ (measurable_of_countable _).aemeasurable + (ae_of_all _ fun x ↦ prod_pos fun i _ ↦ + binomialRN_pos (NNReal.coe_pos.2 hp0) (NNReal.coe_lt_one.2 hp) (NNReal.coe_pos.2 hq0) + (NNReal.coe_lt_one.2 hq) (x i))⟩ + +/-- **The two coin-flip laws are equivalent on the information `ℱₙ`** of the first `n` flips, for +`0 < p, q < 1`: an event known by time `n` is the preimage of a set of `n`-flip patterns, null under +one law exactly when under the other (`map_flips_coinFlipMeasure_equiv`). (On the whole path space +the two laws are mutually singular when `p ≠ q`, by the strong law of large numbers; that is not +proved here.) -/ +theorem coinFlipMeasure_trim_equiv (hp0 : 0 < p) (hp : p < 1) (hq0 : 0 < q) (hq : q < 1) + (n : ℕ) : + (coinFlipMeasure q hq.le).trim (flipFiltration.le n) + ≪ (coinFlipMeasure p hp.le).trim (flipFiltration.le n) ∧ + (coinFlipMeasure p hp.le).trim (flipFiltration.le n) + ≪ (coinFlipMeasure q hq.le).trim (flipFiltration.le n) := by + have key {μ ν : Measure (ℕ → Bool)} (h : μ.map (flips n) ≪ ν.map (flips n)) : + μ.trim (flipFiltration.le n) ≪ ν.trim (flipFiltration.le n) := by + refine Measure.AbsolutelyContinuous.mk fun A hA h0 ↦ ?_ + obtain ⟨S, hS, rfl⟩ := MeasurableSpace.measurableSet_comap.1 hA + rw [trim_measurableSet_eq _ hA, ← Measure.map_apply (measurable_flips n) hS] at h0 + rw [trim_measurableSet_eq _ hA, ← Measure.map_apply (measurable_flips n) hS] + exact h h0 + obtain ⟨h₁, h₂⟩ := map_flips_coinFlipMeasure_equiv hp0 hp hq0 hq n + exact ⟨key h₁, key h₂⟩ + +/-- **The Radon–Nikodym derivative on `ℱₙ`.** Under the hypotheses of +`map_flips_coinFlipMeasure_eq_withDensity`, the `Bernoulli(q)` probability of an event known by +time `n` is the `Bernoulli(p)` integral of the density process `Zₙ = ∏_{i 0`, `0 < d < u` and at least one step, the market has a + pricing measure exactly when `d < e^ρ < u` (`exists_isPricingMeasure_iff`): a pricing measure + rules out the one-period arbitrage of `binomialNoArb_of_noArbitrage`. + +## Main definitions + +* `Binomial.market`: the binomial tree with step `h` as a `Market`. + +## Main results + +* `Binomial.isPricingMeasure_coinFlipMeasure`: the risk-neutral law of the flips is a pricing + measure, for every physical law of i.i.d. flips. +* `Binomial.price_market`: on grid dates the market's price is the binomial value. +* `Binomial.price_market_pay_eq_binomialPrice`: the price of a European payoff is its tree price. +* `Binomial.trim_eq_of_isPricingMeasure`: every pricing measure is the risk-neutral law on the flips + made by the horizon. +* `Binomial.price_pay_eq_binomialPrice_of_isPricingMeasure`: every pricing measure gives the tree + price. +* `Binomial.exists_isPricingMeasure_iff`: a pricing measure exists iff `d < e^ρ < u`. + +## References + +* [J. M. Harrison and S. R. Pliska, *Martingales and stochastic integrals in the theory of + continuous trading*][HarrisonPliska1981] +* [J. C. Cox, S. A. Ross and M. Rubinstein, *Option pricing: a simplified + approach*][CoxRossRubinstein1979] +* [S. E. Shreve, *Stochastic Calculus for Finance I: The Binomial Asset Pricing Model*][ShreveSCFI], + ch. 2 + +## Tags + +binomial tree, Cox–Ross–Rubinstein, market, numéraire, pricing measure, risk-neutral probability, +money market, fundamental theorem of asset pricing, unique pricing measure, MSC 91G20, MSC 60G42, +JEL G13 +-/ + +@[expose] public section + +open MeasureTheory +open scoped NNReal + +namespace MathFin.Contracts.Binomial + +variable {u d ρ h : ℝ} + +/-- The step count `t ↦ ⌊t / h⌋₊` is monotone for a step `h ≥ 0`. -/ +theorem monotone_floor_div (hh : 0 ≤ h) : Monotone fun t : ℝ≥0 ↦ ⌊(t : ℝ) / h⌋₊ := + fun _ _ hst ↦ Nat.floor_mono (div_le_div_of_nonneg_right (NNReal.coe_le_coe.2 hst) hh) + +/-- **The binomial market** with step `h ≥ 0`, under a physical law `P` of the flips: the +information of the flips made by `t`, the spot after them, and the money market `e^{ρ n}` after +`n` steps as numéraire. -/ +noncomputable def market (P : Measure (ℕ → Bool)) (S₀ u d ρ : ℝ) (hh : 0 ≤ h) : + Market Unit (ℕ → Bool) where + P := P + 𝓕 := flipFiltration.comp (monotone_floor_div hh) + asset := assets S₀ u d h + numeraire t _ := Real.exp (ρ * ⌊(t : ℝ) / h⌋₊) + numeraire_pos _ _ := Real.exp_pos _ + asset_adapted _ t := by + change StronglyMeasurable[(flipFiltration.comp (monotone_floor_div hh)) t] + (spotPath S₀ u d ⌊(t : ℝ) / h⌋₊) + rw [Filtration.comp_apply] + exact stronglyMeasurable_flipFiltration_iff.2 (pathAdaptedAt_spotPath S₀ u d _) + numeraire_adapted _ := stronglyMeasurable_const + +/-- The deflated spot of the binomial market is the discounted spot after the steps made. -/ +theorem deflated_market (P : Measure (ℕ → Bool)) (S₀ : ℝ) (hh : 0 ≤ h) (t : ℝ≥0) : + (market P S₀ u d ρ hh).deflated () t = discountedSpot S₀ u d ρ ⌊(t : ℝ) / h⌋₊ := by + funext ω + simp only [Market.deflated, market, assets, discountedSpot, Real.exp_neg, div_eq_inv_mul] + +variable {q : ℝ≥0} (hq : q ≤ 1) + +/-- **The risk-neutral law of the flips prices the binomial market.** Under no-arbitrage, i.i.d. +flips that go up with the probability `crrUpProb u d ρ` are a pricing measure at every horizon, +for the physical law of i.i.d. flips going up with any probability `0 < p < 1`: the deflated spot is +the discounted spot after the steps made, a martingale for the flip filtration +(`martingale_discountedSpot`) and so for its time change along the step count, and the two laws are +equivalent on the flips made by the horizon (`coinFlipMeasure_trim_equiv`). -/ +theorem isPricingMeasure_coinFlipMeasure (hna : BinomialNoArb u d ρ) + (hqcrr : crrUpProb u d ρ = q) (S₀ : ℝ) (hh : 0 ≤ h) {p : ℝ≥0} (hp0 : 0 < p) (hp : p < 1) + (T : ℝ≥0) : + (market (coinFlipMeasure p hp.le) S₀ u d ρ hh).IsPricingMeasure T (coinFlipMeasure q hq) := by + have hq01 : 0 < q ∧ q < 1 := by + have := crrUpProb_mem_Ioo hna + rw [hqcrr] at this + exact ⟨by exact_mod_cast this.1, by exact_mod_cast this.2⟩ + have hM : Martingale (fun t ↦ (market (coinFlipMeasure p hp.le) S₀ u d ρ hh).deflated () t) + (market (coinFlipMeasure p hp.le) S₀ u d ρ hh).𝓕 (coinFlipMeasure q hq) := by + simp only [deflated_market] + exact (martingale_discountedSpot hna S₀ hq hqcrr).comp (monotone_floor_div hh) + obtain ⟨hac, hac'⟩ := coinFlipMeasure_trim_equiv hp0 hp hq01.1 hq01.2 ⌊(T : ℝ) / h⌋₊ + have liftTrim {Q₁ Q₂ : Measure (ℕ → Bool)} + (hQR : Q₁.trim (flipFiltration.le ⌊(T : ℝ) / h⌋₊) ≪ + Q₂.trim (flipFiltration.le ⌊(T : ℝ) / h⌋₊)) : + Q₁.trim ((market (coinFlipMeasure p hp.le) S₀ u d ρ hh).𝓕.le T) ≪ + Q₂.trim ((market (coinFlipMeasure p hp.le) S₀ u d ρ hh).𝓕.le T) := by + refine Measure.AbsolutelyContinuous.mk fun s hs hz ↦ ?_ + rw [trim_measurableSet_eq _ hs] at hz ⊢ + have hsf : MeasurableSet[flipFiltration ⌊(T : ℝ) / h⌋₊] s := by + change MeasurableSet[(flipFiltration.comp (monotone_floor_div hh)) T] s at hs + rwa [Filtration.comp_apply] at hs + rw [← trim_measurableSet_eq _ hsf] + exact hQR (by rw [trim_measurableSet_eq _ hsf]; exact hz) + exact ⟨inferInstance, liftTrim hac, liftTrim hac', fun ⟨⟩ ↦ martingale_min_of_martingale hM T⟩ + +/-- **On grid dates the binomial market's price is the binomial value**: for a fixed-dated +contract paying only at whole numbers of steps, the deflator `e^{−ρ ⌊t/h⌋}` is the discount +`e^{−ρ t/h}` of `Binomial.lean`, under any measure `Q`. -/ +theorem price_market (P Q : Measure (ℕ → Bool)) (S₀ : ℝ) (hh : 0 ≤ h) {c : Contract Unit} + (hc : c.FixedDated) (hgrid : ∀ t ∈ c.dates, ∃ n : ℕ, (t : ℝ) / h = n) : + (market P S₀ u d ρ hh).price Q c + = c.value Q (fun t _ ↦ discount ρ h t) (assets S₀ u d h) := by + simp only [Market.price, Contract.value] + refine integral_congr_ae (.of_forall fun ω ↦ c.pathPV_congr hc (fun t ht ↦ ?_) fun _ _ ↦ rfl) + obtain ⟨n, hn⟩ := hgrid t ht + simp [Market.deflator, market, discount, hn, Real.exp_neg] + +/-- **The price of a European payoff in the binomial market is its tree price.** Under the +risk-neutral law, a cash flow at `T`, on step `N`, paying `g` of the spot at `T`, is priced at the +backward-induction price `binomialPrice u d ρ g N S₀`. -/ +theorem price_market_pay_eq_binomialPrice (hqcrr : crrUpProb u d ρ = q) (P : Measure (ℕ → Bool)) + (S₀ : ℝ) (hh : 0 ≤ h) {T : ℝ≥0} {N : ℕ} (hTN : (T : ℝ) / h = N) {a : Payoff Unit} + {g : ℝ → ℝ} (hg : ∀ s : Scenario Unit, a.eval s = g (s () T)) : + (market P S₀ u d ρ hh).price (coinFlipMeasure q hq) (.pay T a) + = binomialPrice u d ρ g N S₀ := by + rw [price_market P _ S₀ hh (c := .pay T a) trivial fun t ht ↦ + ⟨N, by rw [show t = T by simpa [Contract.dates] using ht]; exact hTN⟩] + exact value_pay_eq_binomialPrice hq hqcrr S₀ hTN hg + +/-! ### Every pricing measure is the risk-neutral one -/ + +/-- At a horizon of `N` steps the deflated spot frozen at the horizon is the discounted spot frozen +at step `N`. -/ +theorem deflated_market_min (P : Measure (ℕ → Bool)) (S₀ : ℝ) (hh : 0 ≤ h) {T : ℝ≥0} {N : ℕ} + (hTN : ⌊(T : ℝ) / h⌋₊ = N) (t : ℝ≥0) : + (market P S₀ u d ρ hh).deflated () (min t T) + = discountedSpot S₀ u d ρ (min ⌊(t : ℝ) / h⌋₊ N) := by + rw [deflated_market, ← hTN] + congr 1 + exact (monotone_floor_div hh).map_min + +variable {P Q : Measure (ℕ → Bool)} {S₀ : ℝ} {T : ℝ≥0} {N : ℕ} + +/-- **Under a pricing measure the discounted spot frozen at the horizon is a martingale for the +flip filtration**: the deflated spot is one along the step count, and the step count has the right +inverse `n ↦ n h` (`Martingale.of_comp`). -/ +theorem martingale_discountedSpot_of_isPricingMeasure (hh : 0 < h) (hTN : ⌊(T : ℝ) / h⌋₊ = N) + (hQ : (market P S₀ u d ρ hh.le).IsPricingMeasure T Q) : + Martingale (fun n ↦ discountedSpot S₀ u d ρ (min n N)) flipFiltration Q := by + have hM := hQ.martingale () + simp only [deflated_market_min P S₀ hh.le hTN] at hM + refine Martingale.of_comp (f := fun n ↦ discountedSpot S₀ u d ρ (min n N)) + (monotone_floor_div hh.le) (ψ := fun n : ℕ ↦ ⟨n * h, by positivity⟩) + (fun a b hab ↦ NNReal.coe_le_coe.1 (mul_le_mul_of_nonneg_right (Nat.cast_le.2 hab) hh.le)) + (fun n ↦ ?_) hM + change ⌊(n : ℝ) * h / h⌋₊ = n + rw [mul_div_cancel_right₀ _ hh.ne', Nat.floor_natCast] + +/-- Under a pricing measure at a horizon of `N` steps, the laws of the first `N` flips under the +pricing measure and under the physical law are equivalent. -/ +theorem map_flips_equiv_of_isPricingMeasure (hh : 0 < h) (hTN : ⌊(T : ℝ) / h⌋₊ = N) + (hQ : (market P S₀ u d ρ hh.le).IsPricingMeasure T Q) : + Q.map (flips N) ≪ P.map (flips N) ∧ P.map (flips N) ≪ Q.map (flips N) := by + have hmeas {S : Set (Fin N → Bool)} (hS : MeasurableSet S) : + MeasurableSet[(market P S₀ u d ρ hh.le).𝓕 T] (flips N ⁻¹' S) := by + change MeasurableSet[(flipFiltration.comp (monotone_floor_div hh.le)) T] _ + rw [Filtration.comp_apply, hTN] + exact MeasurableSpace.measurableSet_comap.2 ⟨S, hS, rfl⟩ + refine ⟨Measure.AbsolutelyContinuous.mk fun S hS h0 ↦ ?_, + Measure.AbsolutelyContinuous.mk fun S hS h0 ↦ ?_⟩ + · rw [Measure.map_apply (measurable_flips N) hS] at h0 ⊢ + rw [← trim_measurableSet_eq ((market P S₀ u d ρ hh.le).𝓕.le T) (hmeas hS)] at h0 ⊢ + exact hQ.ac h0 + · rw [Measure.map_apply (measurable_flips N) hS] at h0 ⊢ + rw [← trim_measurableSet_eq ((market P S₀ u d ρ hh.le).𝓕.le T) (hmeas hS)] at h0 ⊢ + exact hQ.ac' h0 + +/-- **Every pricing measure is the risk-neutral law on the flips made by the horizon.** For +`S₀ > 0` under no-arbitrage, a pricing measure of the binomial market at a horizon of `N` steps +agrees with i.i.d. flips going up with probability `crrUpProb u d ρ` on the first `N` flips: the law +of those flips under it is an equivalent martingale measure of the `N`-period tree +(`isEMM_horizonSpot_map`), which is unique (`IsEMM.eq_horizonMeasure`). -/ +theorem trim_eq_of_isPricingMeasure (hS₀ : 0 < S₀) (hna : BinomialNoArb u d ρ) + (hqcrr : crrUpProb u d ρ = q) (hh : 0 < h) (hTN : ⌊(T : ℝ) / h⌋₊ = N) + (hQ : (market P S₀ u d ρ hh.le).IsPricingMeasure T Q) : + Q.trim (flipFiltration.le N) = (coinFlipMeasure q hq).trim (flipFiltration.le N) := by + have := hQ.isProb + have hmap : Q.map (flips N) = horizonMeasure N q hq := + (isEMM_horizonSpot_map (P := Q.map (flips N)) ⟨inferInstance, .rfl, .rfl⟩ + (martingale_discountedSpot_of_isPricingMeasure hh hTN hQ)).eq_horizonMeasure hS₀ hna hq hqcrr + refine @Measure.ext _ (flipFiltration N) _ _ fun A hA ↦ ?_ + obtain ⟨S, hS, rfl⟩ := MeasurableSpace.measurableSet_comap.1 hA + rw [trim_measurableSet_eq _ hA, trim_measurableSet_eq _ hA, + ← Measure.map_apply (measurable_flips N) hS, hmap, horizonMeasure, + Measure.map_apply (measurable_flips N) hS] + +/-- **Every pricing measure gives a European payoff its tree price.** For `S₀ > 0` under +no-arbitrage, a cash flow at `T`, on step `N`, paying `g` of the spot at `T`, has the price +`binomialPrice u d ρ g N S₀` under every pricing measure of the binomial market at the horizon `T`, +whatever the physical law: the discounted payoff depends on the first `N` flips only, on which every +pricing measure is the risk-neutral law (`trim_eq_of_isPricingMeasure`). -/ +theorem price_pay_eq_binomialPrice_of_isPricingMeasure (hS₀ : 0 < S₀) (hna : BinomialNoArb u d ρ) + (hqcrr : crrUpProb u d ρ = q) (hh : 0 < h) (hTN : (T : ℝ) / h = N) {a : Payoff Unit} + {g : ℝ → ℝ} (hg : ∀ s : Scenario Unit, a.eval s = g (s () T)) + (hQ : (market P S₀ u d ρ hh.le).IsPricingMeasure T Q) : + (market P S₀ u d ρ hh.le).price Q (.pay T a) = binomialPrice u d ρ g N S₀ := by + have hq : q ≤ 1 := by + have := (crrUpProb_mem_Ioo hna).2 + rw [hqcrr] at this + exact_mod_cast this.le + have hfl : ⌊(T : ℝ) / h⌋₊ = N := by rw [hTN, Nat.floor_natCast] + have hgrid : ∀ t ∈ (Contract.pay T a).dates, ∃ n : ℕ, (t : ℝ) / h = n := fun t ht ↦ + ⟨N, by rw [show t = T by simpa [Contract.dates] using ht]; exact hTN⟩ + have hF : StronglyMeasurable[flipFiltration N] + fun ω ↦ discount ρ h T * a.eval (scenarioAt (assets S₀ u d h) ω) := by + refine stronglyMeasurable_flipFiltration_iff.2 fun ω ω' hω ↦ ?_ + simp only [hg, scenarioAt, assets, hfl] + rw [pathAdaptedAt_spotPath S₀ u d N ω ω' hω] + calc (market P S₀ u d ρ hh.le).price Q (.pay T a) + = ∫ ω, discount ρ h T * a.eval (scenarioAt (assets S₀ u d h) ω) ∂Q := by + rw [price_market P Q S₀ hh.le (c := .pay T a) trivial hgrid, Contract.value_pay] + _ = ∫ ω, discount ρ h T * a.eval (scenarioAt (assets S₀ u d h) ω) ∂coinFlipMeasure q hq := by + rw [integral_trim (flipFiltration.le N) hF, integral_trim (flipFiltration.le N) hF, + trim_eq_of_isPricingMeasure hq hS₀ hna hqcrr hh hfl hQ] + _ = binomialPrice u d ρ g N S₀ := by + rw [← value_pay_eq_binomialPrice hq hqcrr S₀ hTN hg, Contract.value_pay] + +/-- **The fundamental theorem of asset pricing for the binomial market.** For `S₀ > 0`, +`0 < d < u`, a step `h > 0` and a horizon of `N ≥ 1` steps, under the physical law of i.i.d. flips +going up with any probability `0 < p < 1`, the market has a pricing measure exactly when +`d < e^ρ < u`. A pricing measure maps to an equivalent martingale measure of the `N`-period tree, +which rules out the one-period arbitrage of `binomialNoArb_of_noArbitrage`; conversely the +risk-neutral law is one (`isPricingMeasure_coinFlipMeasure`). -/ +theorem exists_isPricingMeasure_iff (hS₀ : 0 < S₀) (hd : 0 < d) (hdu : d < u) (hh : 0 < h) + {p : ℝ≥0} (hp0 : 0 < p) (hp : p < 1) (hN : 0 < N) (hTN : (T : ℝ) / h = N) : + (∃ Q, (market (coinFlipMeasure p hp.le) S₀ u d ρ hh.le).IsPricingMeasure T Q) + ↔ BinomialNoArb u d ρ := by + have hfl : ⌊(T : ℝ) / h⌋₊ = N := by rw [hTN, Nat.floor_natCast] + refine ⟨fun ⟨Q, hQ⟩ ↦ ?_, fun hna ↦ ?_⟩ + · have := hQ.isProb + obtain ⟨h₁, h₂⟩ := map_flips_equiv_of_isPricingMeasure hh hfl hQ + exact binomialNoArb_of_noArbitrage hS₀ hd hdu hN hp0 hp + (isEMM_horizonSpot_map (P := horizonMeasure N p hp.le) ⟨inferInstance, h₁, h₂⟩ + (martingale_discountedSpot_of_isPricingMeasure hh hfl hQ)).noArbitrage + · obtain ⟨q, hq, hqcrr⟩ := hna.exists_nnreal_crrUpProb + exact ⟨_, isPricingMeasure_coinFlipMeasure hq hna hqcrr S₀ hh.le hp0 hp T⟩ + +end MathFin.Contracts.Binomial diff --git a/LeanPool/MathFin/Models/Binomial/MartingaleRepresentation.lean b/LeanPool/MathFin/Models/Binomial/MartingaleRepresentation.lean new file mode 100644 index 0000000000..124f6b1fac --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/MartingaleRepresentation.lean @@ -0,0 +1,132 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.PathMeasure +public import LeanPool.MathFin.Probability.Discrete.MartingaleTransform + +/-! +# Binomial martingale representation (completeness of the binomial market) + +On the binomial tree, with the coin flips i.i.d. `Bernoulli(q)` for `0 < q < 1` +(`coinFlipMeasure q`) and Mathlib's filtration of the flips `flipFiltration` (`ℱₙ = σ(ω₀, …, +ω_{n−1})`, the pullback on `[0, T]` of `horizonFiltration T`), every `Martingale M` is the discrete +stochastic integral of a **predictable** strategy `A` against any non-degenerate martingale `S`: + + `M_N = M_0 + (A · S)_N` (`binomial_martingale_representation`), + +where `(A · S)_N(ω) = ∑_{k simp + | succ N ih => + rw [martingaleTransform_real] at ih ⊢ + rw [Finset.sum_range_succ, ← add_assoc, ← ih, Nat.add_sub_cancel, + ← repr_one_step (oneStep_of_martingale hq0 hq1 hM) (oneStep_of_martingale hq0 hq1 hS) + hS_nondeg N ω] + ring + +/-- **The tree price is the cost of a hedge.** Under no-arbitrage and `S₀ ≠ 0`, for every payoff +`g` and horizon `N` there is a predictable strategy `H` (`H_{k+1}` is `ℱₖ`-strongly measurable, +it depends only on the first `k` flips) whose `martingaleTransform` against the discounted spot, +added to the tree price, is the discounted payoff on every path: + + `e^{−rN} g(S_N) = binomialPrice u d r g N S₀ + ∑_{k 0` and + no-arbitrage at every step `n ≥ 1`, the `n`-step American call price converges to the + Black–Scholes European call price `S₀·Φ(d₁) − K·e^{−rT}·Φ(d₂)` (the equality above, transported + along `binomialPrice_call_tendsto_bs_closed`). + +## References + +* [J. C. Cox, S. A. Ross and M. Rubinstein, *Option pricing: a simplified + approach*][CoxRossRubinstein1979] +* [R. C. Merton, *Theory of rational option pricing*][Merton1973] +* [S. E. Shreve, *Stochastic Calculus for Finance I: The Binomial Asset Pricing Model*][ShreveSCFI], + §4.5 + +## Tags + +Merton no early exercise, American call, non-dividend call, early exercise premium, binomial tree, +American equals European, MSC 91G20, MSC 60G40, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- **Convexity inequality for the positive part `max(·, 0)`**: for any +real `a, b` and convex-combination weights `q, 1 − q` with `q ∈ [0, 1]`, + + `max(q · a + (1 − q) · b, 0) ≤ q · max(a, 0) + (1 − q) · max(b, 0)`. + +This is Jensen's inequality for the convex function `x ↦ max(x, 0)`, +which is convex as the maximum of the affine `x` and the constant `0`. -/ +lemma weighted_max_zero_ge {q a b : ℝ} (hq : 0 ≤ q) (h1q : q ≤ 1) : + max (q * a + (1 - q) * b) 0 ≤ q * max a 0 + (1 - q) * max b 0 := by + have h1q_nn : 0 ≤ 1 - q := by linarith + -- Jensen for the convex `x ↦ max x 0` (`= id ⊔ const 0`), evaluated at `a, b`. + have hconv : ConvexOn ℝ Set.univ (fun x : ℝ ↦ max x 0) := + (convexOn_id convex_univ).sup (convexOn_const 0 convex_univ) + simpa using hconv.2 (Set.mem_univ a) (Set.mem_univ b) hq h1q_nn (by ring) + +/-- **Algebraic identity**: `e^{−r} · max(S · e^r − K, 0) = max(S − K · e^{−r}, 0)`. + +`max(·, 0)` is positively homogeneous: `c · max(x, 0) = max(c · x, 0)` for +`c ≥ 0`. Combined with `e^{−r} · e^r = 1`, this gives the discount-shift +identity. -/ +lemma exp_neg_mul_max_call_payoff (S K r : ℝ) : + Real.exp (-r) * max (S * Real.exp r - K) 0 = max (S - K * Real.exp (-r)) 0 := by + have h_exp_pos : 0 < Real.exp (-r) := Real.exp_pos _ + have h_exp_inv : Real.exp (-r) * Real.exp r = 1 := by + rw [← Real.exp_add]; simp + by_cases h : 0 ≤ S * Real.exp r - K + · rw [max_eq_left h] + have h_lhs_nn : 0 ≤ S - K * Real.exp (-r) := by + have h1 : Real.exp (-r) * K ≤ Real.exp (-r) * (S * Real.exp r) := + mul_le_mul_of_nonneg_left (by linarith) h_exp_pos.le + have h2 : Real.exp (-r) * (S * Real.exp r) = S := by + rw [show Real.exp (-r) * (S * Real.exp r) = + S * (Real.exp (-r) * Real.exp r) from by ring, + h_exp_inv, mul_one] + have h3 : Real.exp (-r) * K = K * Real.exp (-r) := mul_comm _ _ + linarith + rw [max_eq_left h_lhs_nn] + calc Real.exp (-r) * (S * Real.exp r - K) + = S * (Real.exp (-r) * Real.exp r) - K * Real.exp (-r) := by ring + _ = S * 1 - K * Real.exp (-r) := by rw [h_exp_inv] + _ = S - K * Real.exp (-r) := by ring + · have h' : S * Real.exp r - K < 0 := not_le.mp h + rw [max_eq_right h'.le, mul_zero] + have h_lhs_le : S - K * Real.exp (-r) ≤ 0 := by + have h1 : Real.exp (-r) * (S * Real.exp r) ≤ Real.exp (-r) * K := + mul_le_mul_of_nonneg_left (by linarith : S * Real.exp r ≤ K) h_exp_pos.le + have h2 : Real.exp (-r) * (S * Real.exp r) = S := by + rw [show Real.exp (-r) * (S * Real.exp r) = + S * (Real.exp (-r) * Real.exp r) from by ring, + h_exp_inv, mul_one] + have h3 : Real.exp (-r) * K = K * Real.exp (-r) := mul_comm _ _ + linarith + rw [max_eq_right h_lhs_le] + +/-- **Continuation dominates the forward-discounted intrinsic** in the +single-period binomial. For the call payoff `g(S) = max(S − K, 0)`, + + `max(S − K · e^{−r}, 0) + ≤ e^{−r} · (q · max(uS − K, 0) + (1 − q) · max(dS − K, 0)) + = continuation`. + +Combines `weighted_max_zero_ge` (Jensen for max-zero), the martingale identity +(`qu + (1 − q)d = e^r`), and the discount-shift identity. -/ +theorem call_one_period_continuation_ge_forward + {u d r K S : ℝ} (h : BinomialNoArb u d r) : + max (S - K * Real.exp (-r)) 0 ≤ + binomialOptionPriceOnePeriod u d r + (max (S * u - K) 0) (max (S * d - K) 0) := by + set q := crrUpProb u d r with q_def + have h_q : q ∈ Set.Ioo 0 1 := crrUpProb_mem_Ioo h + have h_q_pos : 0 < q := h_q.1 + have h_q_lt_one : q < 1 := h_q.2 + have h_exp_pos : 0 < Real.exp (-r) := Real.exp_pos _ + -- Step 1: martingale identity gives q · u + (1 − q) · d = e^r. + have h_mart : q * u + (1 - q) * d = Real.exp r := crrUpProb_mul_up_add u d r h + -- Step 2: Jensen for max-zero, with a = uS − K, b = dS − K. + have h_conv : + max (q * (S * u - K) + (1 - q) * (S * d - K)) 0 ≤ + q * max (S * u - K) 0 + (1 - q) * max (S * d - K) 0 := + weighted_max_zero_ge h_q_pos.le h_q_lt_one.le + -- The linear combination collapses via the martingale identity: + -- q · (uS − K) + (1 − q) · (dS − K) = S · (qu + (1 − q)d) − K = S · e^r − K. + have h_lin : + q * (S * u - K) + (1 - q) * (S * d - K) = S * Real.exp r - K := by + have : q * (S * u - K) + (1 - q) * (S * d - K) = + S * (q * u + (1 - q) * d) - K := by ring + rw [this, h_mart] + rw [h_lin] at h_conv + -- h_conv: max(S e^r − K, 0) ≤ q · max(uS − K, 0) + (1 − q) · max(dS − K, 0). + -- Multiply by e^{−r} ≥ 0: + have h_mul := mul_le_mul_of_nonneg_left h_conv h_exp_pos.le + -- LHS simplifies via exp_neg_mul_max_call_payoff: + rw [exp_neg_mul_max_call_payoff S K r] at h_mul + -- Goal RHS is the binomialOptionPriceOnePeriod unfolded: + unfold binomialOptionPriceOnePeriod + rw [← q_def] + exact h_mul + +/-- **Continuation dominates intrinsic for `r ≥ 0`**: combines +`call_one_period_continuation_ge_forward` with the forward-discount +inequality `max(S − K · e^{−r}, 0) ≥ max(S − K, 0)` (for `r ≥ 0`, `K ≥ 0`). + +The inequality need not be strict, even for `r > 0` and `K > 0`: when the call is out of the +money in both daughter states (`S·u ≤ K`), both sides are `0`. -/ +theorem call_one_period_continuation_dominates_intrinsic + {u d r K S : ℝ} (h : BinomialNoArb u d r) (hr : 0 ≤ r) (hK : 0 ≤ K) : + max (S - K) 0 ≤ + binomialOptionPriceOnePeriod u d r + (max (S * u - K) 0) (max (S * d - K) 0) := by + have h_step1 := call_one_period_continuation_ge_forward (K := K) (S := S) h + -- max(S − K, 0) ≤ max(S − K · e^{−r}, 0) when K · e^{−r} ≤ K (i.e. r ≥ 0, K ≥ 0). + have h_exp_le_one : Real.exp (-r) ≤ 1 := by + rw [show (1 : ℝ) = Real.exp 0 from (Real.exp_zero).symm] + exact Real.exp_le_exp.mpr (by linarith) + have h_K_disc_le : K * Real.exp (-r) ≤ K := by + have := mul_le_mul_of_nonneg_left h_exp_le_one hK + simpa using this + have h_step2 : max (S - K) 0 ≤ max (S - K * Real.exp (-r)) 0 := by + apply max_le_max + · linarith + · exact le_refl _ + linarith + +/-! ## Multi-step Merton 1973 + +The one-period dominance `call_one_period_continuation_dominates_intrinsic` +extends to arbitrary horizons by induction, which puts the intrinsic payoff below the European +price at every step (`call_intrinsic_le_binomialPrice`). The European price process is then a +martingale dominating the payoff, and `americanPrice` is the smallest supermartingale doing so +(the Snell envelope, `bermudanPrice_le_of_supermartingale_dominating`), which gives +American ≤ European. + +The reverse inequality `binomialPrice ≤ americanPrice` is `Models.Binomial.Bermudan`'s +`bermudanPrice_mono` for the exercise sets `∅ ⊆ univ` (the European price is a +supermartingale dominating the payoff at maturity, so it is above the smaller envelope). +Together they give equality. -/ + +/-- **Intrinsic ≤ European binomial price** (multi-step) for the call payoff +with `r ≥ 0, K ≥ 0`. + +This is the substantive content of Merton 1973 at multi-step horizons: the +one-period continuation dominance lifts to every step by induction. -/ +theorem call_intrinsic_le_binomialPrice {u d r K : ℝ} (h : BinomialNoArb u d r) + (hr : 0 ≤ r) (hK : 0 ≤ K) : + ∀ (n : ℕ) (S : ℝ), + max (S - K) 0 ≤ binomialPrice u d r (fun S' ↦ max (S' - K) 0) n S := by + intro n + induction n with + | zero => intro S; simp + | succ n ih => + intro S + -- Step 1: one-period dominance bounds the intrinsic by the one-period + -- continuation of the *payoff* values at the daughter nodes. + have h_one_step := + call_one_period_continuation_dominates_intrinsic + (u := u) (d := d) (r := r) (K := K) (S := S) h hr hK + -- Step 2: by induction at the daughter nodes, the payoff values + -- max(uS - K, 0), max(dS - K, 0) are bounded by the European binomial + -- prices binomialPrice n (uS), binomialPrice n (dS). + have h_mono := binomialOptionPriceOnePeriod_mono (h := h) + (ih (S * u)) (ih (S * d)) + -- Step 3: the one-step European recursion at S equals exactly that + -- one-period continuation of binomialPrice n at the daughter nodes. + have h_succ := binomialPrice_succ_eq_onePeriod u d r + (fun S' ↦ max (S' - K) 0) n S + linarith + +/-- **Merton 1973 (multi-step): no exercise date adds value to the call.** For every exercise set +`E` (any Bermudan schedule), the `E`-exercise tree price of the call equals the European binomial +price, for `r ≥ 0, K ≥ 0`. + +The European price process is a martingale (the one-period recursion +`binomialPrice_succ_eq_onePeriod`) that dominates the intrinsic payoff +(`call_intrinsic_le_binomialPrice`), so it dominates the smallest such process, the Snell envelope +`bermudanPrice E` (`bermudanPrice_le_of_supermartingale_dominating`); the reverse inequality is +`bermudanPrice_mono` for `∅ ⊆ E`. -/ +theorem bermudanCallPrice_eq_binomialPrice {u d r K : ℝ} (h : BinomialNoArb u d r) + (hr : 0 ≤ r) (hK : 0 ≤ K) (E : Set ℕ) (n : ℕ) (S : ℝ) : + bermudanPrice E u d r (fun S' ↦ max (S' - K) 0) n S = + binomialPrice u d r (fun S' ↦ max (S' - K) 0) n S := + le_antisymm + (bermudanPrice_le_of_supermartingale_dominating h E _ (binomialPrice u d r _) + (fun n _ S ↦ call_intrinsic_le_binomialPrice h hr hK n S) + (fun n S ↦ (binomialPrice_succ_eq_onePeriod u d r _ n S).ge) n S) + (bermudanPrice_mono h _ (Set.empty_subset E) n S) + +/-- **Merton 1973 (multi-step, equality form)**: the American call price equals +the European call price at every step in the no-dividend binomial tree, for +`r ≥ 0, K ≥ 0` (the case `E = univ` of `bermudanCallPrice_eq_binomialPrice`). -/ +theorem americanCallPrice_eq_binomialPrice {u d r K : ℝ} (h : BinomialNoArb u d r) + (hr : 0 ≤ r) (hK : 0 ≤ K) (n : ℕ) (S : ℝ) : + americanPrice u d r (fun S' ↦ max (S' - K) 0) n S = + binomialPrice u d r (fun S' ↦ max (S' - K) 0) n S := + bermudanCallPrice_eq_binomialPrice h hr hK Set.univ n S + +/-! ## The CRR American call converges to the Black–Scholes call -/ + +section CRRLimit + +open Filter +open scoped Topology + +/-- **The CRR American call converges to the Black–Scholes European call.** On the +Cox–Ross–Rubinstein tree (`u = e^{σ√(T/n)}`, `d = e^{−σ√(T/n)}`, per-step rate `rT/n`) with +`r ≥ 0`, `σ, T, S₀, K > 0` and no-arbitrage at every step `n ≥ 1`, the `n`-step American call +price converges to `S₀·Φ(d₁) − K·e^{−rT}·Φ(d₂)` as `n → ∞`. At each `n ≥ 1` the American and +European tree prices coincide (`americanCallPrice_eq_binomialPrice`, the per-step rate +`rT/n` being nonnegative), and the European prices converge +(`binomialPrice_call_tendsto_bs_closed`). -/ +theorem crr_americanCall_tendsto_bs {r σ T S₀ K : ℝ} (hr : 0 ≤ r) (hσ : 0 < σ) (hT : 0 < T) + (hS₀ : 0 < S₀) (hK : 0 < K) + (hna : ∀ n, 0 < n → BinomialNoArb (crrUp σ T n) (crrDown σ T n) (crrPerStepRate r T n)) : + Tendsto (fun n : ℕ ↦ americanPrice (crrUp σ T n) (crrDown σ T n) (crrPerStepRate r T n) + (fun x ↦ max (x - K) 0) n S₀) atTop + (𝓝 (S₀ * Phi (bsd1 S₀ K r σ T) - K * Real.exp (-(r * T)) * Phi (bsd2 S₀ K r σ T))) := + (binomialPrice_call_tendsto_bs_closed hσ hT hS₀ hK hna).congr' + (eventually_atTop.mpr ⟨1, fun n hn ↦ (americanCallPrice_eq_binomialPrice (hna n hn) + (mul_nonneg hr (div_nonneg hT.le n.cast_nonneg)) hK.le n S₀).symm⟩) + +end CRRLimit + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/Model.lean b/LeanPool/MathFin/Models/Binomial/Model.lean new file mode 100644 index 0000000000..6bf7795742 --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/Model.lean @@ -0,0 +1,371 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.CharP.Defs +public import Mathlib.Analysis.Complex.Exponential +public import Mathlib.Tactic.LinearCombination + +/-! +# Binomial-tree option pricing (Cox-Ross-Rubinstein style) + +We formalize **discrete-time European option pricing on a binomial tree**. + +At each time step, the asset price moves up by factor `u` or down by factor +`d`. Risk-free continuously-compounded rate per step is `r`. Under no-arbitrage +(`d < e^r < u`), there is a unique risk-neutral probability + + q = (e^r - d) / (u - d) ∈ (0, 1), + +and the no-arbitrage price of a single-period contingent claim with payoffs +`V_u` (up state) and `V_d` (down state) is + + V_0 = e^{-r} (q · V_u + (1 - q) · V_d). + +This file contains: +1. Risk-neutral probability `crrUpProb` and its `(0, 1)`-range bound. +2. Single-period option pricing formula `binomialOptionPriceOnePeriod`. +3. **No-arbitrage replication theorem**: cost of the replicating portfolio + equals `binomialOptionPriceOnePeriod`. +4. The multi-period (`N`-step) backward-induction price with early exercise on a step set + `E` (`bermudanPrice`), and its European case `binomialPrice` (`E = ∅`). + +The bridge to Black-Scholes (CRR convergence) is proved in +`Models/Binomial/CRRCharFun.lean` (`binomialPrice_call_tendsto_bs`). + +## Main definitions + +* `crrUpProb`: the risk-neutral up-probability `q = (e^r − d) / (u − d)`. +* `BinomialNoArb`: the no-arbitrage condition `0 < d < e^r < u`. +* `binomialOptionPriceOnePeriod`: the one-period price `e^{−r} (q · V_u + (1 − q) · V_d)`. +* `bermudanPrice`: the tree price by backward induction with early exercise at the steps in a + set `E`. +* `binomialPrice`: the European tree price, `bermudanPrice` with no exercise dates. + +## Main results + +* `crrUpProb_mem_Ioo`: under `BinomialNoArb`, `crrUpProb u d r ∈ (0, 1)`. +* `crrUpProb_mul_up_add`: under `BinomialNoArb`, `q · u + (1 − q) · d = e^r`. +* `replicating_portfolio_cost`: for `S₀ > 0` and `BinomialNoArb`, the portfolio with `Δ` shares + and bond holding `B` that matches `V_u`, `V_d` costs `binomialOptionPriceOnePeriod u d r V_u V_d`; + `replicating_payoff_up` and `replicating_payoff_down` give its payoffs in the two states. +* `le_bermudanPrice`: at maturity and at every exercise date the price is at least the payoff. +* `bermudanPrice_supermartingale`: the one-period continuation of `bermudanPrice` is at most the + price. +* `binomialPrice_succ_eq_onePeriod`: the `(n + 1)`-step price is the one-period price of the two + `n`-step prices at `S · u` and `S · d`. +* `binomialPrice_add`, `binomialPrice_smul`: the price is linear in the payoff. +* `binomialPrice_const`: a constant payoff `c` has price `e^{−n r} · c`. +* `binomialPrice_id`: under `BinomialNoArb`, the payoff `S ↦ S` has price `S` at every `n`. + +## References + +* [J. C. Cox, S. A. Ross and M. Rubinstein, *Option pricing: a simplified + approach*][CoxRossRubinstein1979] +* [S. E. Shreve, *Stochastic Calculus for Finance I: The Binomial Asset Pricing Model*][ShreveSCFI], + 1.2 + +## Tags + +Cox–Ross–Rubinstein, binomial tree, risk-neutral probability, replicating portfolio, +backward induction, one-period pricing, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +/-! ### Risk-neutral up-probability -/ + +/-- The risk-neutral up-probability `q = (e^r - d) / (u - d)`. -/ +noncomputable def crrUpProb (u d r : ℝ) : ℝ := + (Real.exp r - d) / (u - d) + +/-- No-arbitrage condition for the binomial single-period model: +`d < e^r < u` (and `d > 0`). -/ +structure BinomialNoArb (u d r : ℝ) : Prop where + d_pos : 0 < d + d_lt : d < Real.exp r + lt_u : Real.exp r < u + +/-- Under no-arbitrage, `u > d`. -/ +lemma BinomialNoArb.d_lt_u {u d r : ℝ} (h : BinomialNoArb u d r) : d < u := + lt_trans h.d_lt h.lt_u + +/-- Under no-arbitrage, `u > 0`. -/ +lemma BinomialNoArb.u_pos {u d r : ℝ} (h : BinomialNoArb u d r) : 0 < u := + lt_trans h.d_pos h.d_lt_u + +/-- Under no-arbitrage, the risk-neutral up-probability is in `(0, 1)`. -/ +lemma crrUpProb_mem_Ioo {u d r : ℝ} (h : BinomialNoArb u d r) : + crrUpProb u d r ∈ Set.Ioo 0 1 := by + have h_ud : 0 < u - d := by linarith [h.d_lt_u] + refine ⟨?_, ?_⟩ + · unfold crrUpProb + exact div_pos (by linarith [h.d_lt]) h_ud + · unfold crrUpProb + rw [div_lt_one h_ud]; linarith [h.lt_u] + +/-- Under no-arbitrage the risk-neutral up-probability `crrUpProb u d r` is a probability in +`ℝ≥0`: the form the `ℝ≥0`-parametrised flip laws (`coinFlipMeasure`, `horizonMeasure`) take. -/ +lemma BinomialNoArb.exists_nnreal_crrUpProb {u d r : ℝ} (h : BinomialNoArb u d r) : + ∃ q : NNReal, q ≤ 1 ∧ crrUpProb u d r = q := + ⟨(crrUpProb u d r).toNNReal, Real.toNNReal_le_one.2 (crrUpProb_mem_Ioo h).2.le, + (Real.coe_toNNReal _ (crrUpProb_mem_Ioo h).1.le).symm⟩ + +/-- The probability `1 - q = (u - e^r) / (u - d)`. -/ +@[pricing =] +lemma one_sub_crrUpProb {u d r : ℝ} (h : BinomialNoArb u d r) : + 1 - crrUpProb u d r = (u - Real.exp r) / (u - d) := by + unfold crrUpProb + have h_ud : 0 < u - d := by linarith [h.d_lt_u] + field_simp + ring + +/-! ### Single-period option pricing -/ + +/-- Single-period European option price via the risk-neutral expectation: +`V_0 = e^{-r}(q · V_u + (1-q) · V_d)`. -/ +noncomputable def binomialOptionPriceOnePeriod (u d r V_u V_d : ℝ) : ℝ := + Real.exp (-r) * + (crrUpProb u d r * V_u + (1 - crrUpProb u d r) * V_d) + +/-- Monotonicity of the one-period continuation: if `V_u ≤ V_u'` and +`V_d ≤ V_d'`, then the one-period prices satisfy the same ordering. -/ +lemma binomialOptionPriceOnePeriod_mono {u d r V_u V_u' V_d V_d' : ℝ} + (h : BinomialNoArb u d r) (hu : V_u ≤ V_u') (hd : V_d ≤ V_d') : + binomialOptionPriceOnePeriod u d r V_u V_d + ≤ binomialOptionPriceOnePeriod u d r V_u' V_d' := by + have hp := crrUpProb_mem_Ioo h + have : 0 ≤ 1 - crrUpProb u d r := by linarith [hp.2] + unfold binomialOptionPriceOnePeriod + gcongr + exact hp.1.le + +/-- **No-arbitrage single-period replication.** For an asset with spot `S_0` +and `BinomialNoArb u d r`, any contingent claim with payoffs `V_u` (in the up +state `S_0 · u`) and `V_d` (down state `S_0 · d`) is replicated by + + Δ = (V_u - V_d) / (S_0 (u - d)) shares of stock, + B = e^{-r}(u · V_d - d · V_u) / (u - d) in bonds (at time 0 value). + +The cost of this replicating portfolio at time 0 equals +`binomialOptionPriceOnePeriod`. -/ +theorem replicating_portfolio_cost {S_0 u d r V_u V_d : ℝ} + (hS_0 : 0 < S_0) (h : BinomialNoArb u d r) : + let Δ : ℝ := (V_u - V_d) / (S_0 * (u - d)) + let B : ℝ := Real.exp (-r) * (u * V_d - d * V_u) / (u - d) + Δ * S_0 + B = binomialOptionPriceOnePeriod u d r V_u V_d := by + have h_ud : 0 < u - d := by linarith [h.d_lt_u] + have h_ud_ne : u - d ≠ 0 := h_ud.ne' + have hS_0_ne : S_0 ≠ 0 := hS_0.ne' + have h_exp_id : Real.exp (-r) * Real.exp r = 1 := by + rw [← Real.exp_add, neg_add_cancel, Real.exp_zero] + unfold binomialOptionPriceOnePeriod crrUpProb + simp only + field_simp + linear_combination -(V_u - V_d) * h_exp_id + +/-- **Replication payoff: up state.** The replicating portfolio pays `V_u` +when the asset goes up. -/ +theorem replicating_payoff_up {S_0 u d r V_u V_d : ℝ} + (hS_0 : 0 < S_0) (h : BinomialNoArb u d r) : + let Δ : ℝ := (V_u - V_d) / (S_0 * (u - d)) + let B : ℝ := Real.exp (-r) * (u * V_d - d * V_u) / (u - d) + Δ * (S_0 * u) + B * Real.exp r = V_u := by + have h_ud : 0 < u - d := by linarith [h.d_lt_u] + have h_ud_ne : u - d ≠ 0 := h_ud.ne' + have hS_0_ne : S_0 ≠ 0 := hS_0.ne' + have h_exp_ne : Real.exp r ≠ 0 := (Real.exp_pos r).ne' + have h_exp_inv : Real.exp (-r) * Real.exp r = 1 := by + rw [← Real.exp_add, neg_add_cancel, Real.exp_zero] + simp only + field_simp + linear_combination (u * V_d - d * V_u) * h_exp_inv + +/-- **Replication payoff: down state.** The replicating portfolio pays `V_d` +when the asset goes down. -/ +theorem replicating_payoff_down {S_0 u d r V_u V_d : ℝ} + (hS_0 : 0 < S_0) (h : BinomialNoArb u d r) : + let Δ : ℝ := (V_u - V_d) / (S_0 * (u - d)) + let B : ℝ := Real.exp (-r) * (u * V_d - d * V_u) / (u - d) + Δ * (S_0 * d) + B * Real.exp r = V_d := by + have h_ud : 0 < u - d := by linarith [h.d_lt_u] + have h_ud_ne : u - d ≠ 0 := h_ud.ne' + have hS_0_ne : S_0 ≠ 0 := hS_0.ne' + have h_exp_ne : Real.exp r ≠ 0 := (Real.exp_pos r).ne' + have h_exp_inv : Real.exp (-r) * Real.exp r = 1 := by + rw [← Real.exp_add, neg_add_cancel, Real.exp_zero] + simp only + field_simp + linear_combination (u * V_d - d * V_u) * h_exp_inv + +/-! ### Multi-period (N-step) backward-induction pricing -/ + +open scoped Classical in +/-- **The binomial tree price with early exercise at the steps in `E`.** + +`bermudanPrice E u d r g n S` is the time-0 value with `n` time steps remaining, current +asset price `S`, and payoff `g` (applied at maturity, and at any step with `k` steps remaining +for `k ∈ E`). The Bellman recursion takes `max(intrinsic, continuation)` exactly at the +steps in `E` and the bare discounted risk-neutral continuation otherwise. This is the one +recursion of the tree: `E = ∅` is the European price (`binomialPrice`) and `E = univ` the +American price (`americanPrice`). -/ +noncomputable def bermudanPrice (E : Set ℕ) (u d r : ℝ) (g : ℝ → ℝ) : ℕ → ℝ → ℝ + | 0, S => g S + | n + 1, S => + if (n + 1) ∈ E then + max (g S) (binomialOptionPriceOnePeriod u d r + (bermudanPrice E u d r g n (S * u)) (bermudanPrice E u d r g n (S * d))) + else + binomialOptionPriceOnePeriod u d r + (bermudanPrice E u d r g n (S * u)) (bermudanPrice E u d r g n (S * d)) + +/-- At maturity (`n = 0`) the price is the payoff `g S`. -/ +@[simp] +lemma bermudanPrice_zero (E : Set ℕ) (u d r : ℝ) (g : ℝ → ℝ) (S : ℝ) : + bermudanPrice E u d r g 0 S = g S := rfl + +/-- Bellman step at an exercise date (`n + 1 ∈ E`): the max of intrinsic value and +continuation. -/ +lemma bermudanPrice_succ_of_mem {E : Set ℕ} {n : ℕ} (hn : n + 1 ∈ E) (u d r : ℝ) (g : ℝ → ℝ) + (S : ℝ) : + bermudanPrice E u d r g (n + 1) S = max (g S) (binomialOptionPriceOnePeriod u d r + (bermudanPrice E u d r g n (S * u)) (bermudanPrice E u d r g n (S * d))) := by + rw [bermudanPrice, ite_eq_left hn] + +/-- Bellman step off the exercise set (`n + 1 ∉ E`): the bare continuation. -/ +lemma bermudanPrice_succ_of_notMem {E : Set ℕ} {n : ℕ} (hn : n + 1 ∉ E) (u d r : ℝ) + (g : ℝ → ℝ) (S : ℝ) : + bermudanPrice E u d r g (n + 1) S = binomialOptionPriceOnePeriod u d r + (bermudanPrice E u d r g n (S * u)) (bermudanPrice E u d r g n (S * d)) := by + rw [bermudanPrice, ite_eq_right hn] + +/-- **Supermartingale clause**: the one-period continuation never exceeds the price. -/ +lemma bermudanPrice_supermartingale (E : Set ℕ) (u d r : ℝ) (g : ℝ → ℝ) (n : ℕ) (S : ℝ) : + binomialOptionPriceOnePeriod u d r (bermudanPrice E u d r g n (S * u)) + (bermudanPrice E u d r g n (S * d)) ≤ bermudanPrice E u d r g (n + 1) S := by + by_cases hn : n + 1 ∈ E + · rw [bermudanPrice_succ_of_mem hn]; exact le_max_right _ _ + · rw [bermudanPrice_succ_of_notMem hn] + +/-- **Dominance clause**: at maturity and at every exercise date the price dominates the +intrinsic value. -/ +lemma le_bermudanPrice {E : Set ℕ} {n : ℕ} (hn : n = 0 ∨ n ∈ E) (u d r : ℝ) (g : ℝ → ℝ) + (S : ℝ) : g S ≤ bermudanPrice E u d r g n S := by + cases n with + | zero => exact le_rfl + | succ m => + rw [bermudanPrice_succ_of_mem (hn.resolve_left (Nat.succ_ne_zero m))] + exact le_max_left _ _ + +/-- Backward-induction binomial tree price: the European price, never exercising early +(`bermudanPrice ∅`). + +`binomialPrice u d r g n S` returns the time-0 option value with `n` time steps +remaining, current asset price `S`, and payoff function `g : ℝ → ℝ` (applied at +maturity). At each step, the price is the risk-neutral expectation discounted +by `e^{-r}`. -/ +noncomputable def binomialPrice (u d r : ℝ) (g : ℝ → ℝ) : ℕ → ℝ → ℝ := + bermudanPrice ∅ u d r g + +/-- At maturity (`n = 0`) the binomial price is the payoff `g S`. -/ +@[simp] +lemma binomialPrice_zero (u d r : ℝ) (g : ℝ → ℝ) (S : ℝ) : + binomialPrice u d r g 0 S = g S := rfl + +/-- **One-step consistency**: `binomialPrice u d r g (n+1) S` equals +`binomialOptionPriceOnePeriod u d r V_u V_d` where `V_u, V_d` are the +sub-tree prices for `n` more steps starting from `S·u` and `S·d`. -/ +theorem binomialPrice_succ_eq_onePeriod (u d r : ℝ) (g : ℝ → ℝ) (n : ℕ) (S : ℝ) : + binomialPrice u d r g (n + 1) S = + binomialOptionPriceOnePeriod u d r + (binomialPrice u d r g n (S * u)) + (binomialPrice u d r g n (S * d)) := + bermudanPrice_succ_of_notMem (Set.notMem_empty _) u d r g S + +/-- One-step backward recursion: the price at `n+1` is the discounted risk-neutral +average of the prices at the up/down successors. -/ +lemma binomialPrice_succ (u d r : ℝ) (g : ℝ → ℝ) (n : ℕ) (S : ℝ) : + binomialPrice u d r g (n + 1) S = + Real.exp (-r) * + (crrUpProb u d r * binomialPrice u d r g n (S * u) + + (1 - crrUpProb u d r) * binomialPrice u d r g n (S * d)) := + binomialPrice_succ_eq_onePeriod u d r g n S + +/-- **Linearity of the binomial price** in the payoff function. -/ +lemma binomialPrice_add (u d r : ℝ) (g h : ℝ → ℝ) (n : ℕ) (S : ℝ) : + binomialPrice u d r (fun x ↦ g x + h x) n S = + binomialPrice u d r g n S + binomialPrice u d r h n S := by + induction n generalizing S with + | zero => rfl + | succ n ih => + rw [binomialPrice_succ, binomialPrice_succ, binomialPrice_succ] + rw [ih (S * u), ih (S * d)] + ring + +/-- **Scalar homogeneity of the binomial price** in the payoff function. -/ +lemma binomialPrice_smul (u d r c : ℝ) (g : ℝ → ℝ) (n : ℕ) (S : ℝ) : + binomialPrice u d r (fun x ↦ c * g x) n S = c * binomialPrice u d r g n S := by + induction n generalizing S with + | zero => rfl + | succ n ih => + rw [binomialPrice_succ, binomialPrice_succ] + rw [ih (S * u), ih (S * d)] + ring + +/-- **Constant-payoff price**: a deterministic payoff `c` at maturity has time-0 +price `e^{-rn} · c` for `n` steps. -/ +theorem binomialPrice_const (u d r c : ℝ) (_h : BinomialNoArb u d r) (n : ℕ) (S : ℝ) : + binomialPrice u d r (fun _ ↦ c) n S = Real.exp (-(n : ℝ) * r) * c := by + induction n generalizing S with + | zero => simp + | succ n ih => + rw [binomialPrice_succ, ih (S * u), ih (S * d)] + have h_q_complement : crrUpProb u d r + (1 - crrUpProb u d r) = 1 := by ring + have h_factor : Real.exp (-r) * Real.exp (-(n : ℝ) * r) = + Real.exp (-((n + 1 : ℕ) : ℝ) * r) := by + rw [← Real.exp_add] + congr 1 + push_cast + ring + calc Real.exp (-r) * + (crrUpProb u d r * (Real.exp (-(n : ℝ) * r) * c) + + (1 - crrUpProb u d r) * (Real.exp (-(n : ℝ) * r) * c)) + = Real.exp (-r) * Real.exp (-(n : ℝ) * r) * c * + (crrUpProb u d r + (1 - crrUpProb u d r)) := by ring + _ = Real.exp (-r) * Real.exp (-(n : ℝ) * r) * c * 1 := by rw [h_q_complement] + _ = Real.exp (-((n + 1 : ℕ) : ℝ) * r) * c := by rw [mul_one, h_factor] + +/-- **One-step risk-neutral martingale identity** for the binomial up-probability: +`p · u + (1 − p) · d = eʳ`. -/ +@[pricing =] +lemma crrUpProb_mul_up_add (u d r : ℝ) (h : BinomialNoArb u d r) : + crrUpProb u d r * u + (1 - crrUpProb u d r) * d = Real.exp r := by + have hud : u - d ≠ 0 := sub_ne_zero.mpr h.d_lt_u.ne' + rw [crrUpProb] + field_simp + ring + +/-- **Stock-price martingale value**: pricing the payoff `g(S) = S` (the underlying +itself) returns `S` — the discounted stock price is a martingale under the +risk-neutral probability. -/ +theorem binomialPrice_id (u d r : ℝ) (h : BinomialNoArb u d r) (n : ℕ) (S : ℝ) : + binomialPrice u d r (fun x ↦ x) n S = S := by + have hmart := crrUpProb_mul_up_add u d r h + induction n generalizing S with + | zero => rfl + | succ n ih => + rw [binomialPrice_succ, ih (S * u), ih (S * d), + show crrUpProb u d r * (S * u) + (1 - crrUpProb u d r) * (S * d) + = S * (crrUpProb u d r * u + (1 - crrUpProb u d r) * d) from by ring, hmart, + show Real.exp (-r) * (S * Real.exp r) = S * (Real.exp (-r) * Real.exp r) from by ring, + ← Real.exp_add, neg_add_cancel, Real.exp_zero, mul_one] + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/MultiPeriodFTAP.lean b/LeanPool/MathFin/Models/Binomial/MultiPeriodFTAP.lean new file mode 100644 index 0000000000..8cf16b9c31 --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/MultiPeriodFTAP.lean @@ -0,0 +1,605 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.PathMeasure +public import LeanPool.MathFin.Pricing.FTAP.FTAPComplete + +/-! +# Multi-period binomial no-arbitrage through the discrete FTAP + +`Pricing/FTAP/FTAPDiscrete.lean` proves the Harrison–Pliska theorem on a finite probability space +with a filtration: `NoArbitrage ↔ ∃ Q, IsEMM Q`. Here the `T`-period CRR tree is an instance. + +* The sample space is `Fin T → Bool`, the first `T` coin flips, with the real-world measure + `horizonMeasure T p = (coinFlipMeasure p).map (flips T)`: it has full support when `0 < p < 1` + (`horizonMeasure_pos`), by `coinFlipMeasure_flips_preimage_pos`. +* The filtration is `horizonFiltration T`: `ℱₙ` is generated by the first `n` flips, frozen + from time `T` on. Its pullback under `flips T` is the path-space `flipFiltration` + (`comap_flips_horizonFiltration`), so the two are one notion on `[0, T]`. +* The discounted price is `horizonSpot T`: the discounted CRR spot `discountedSpot`, frozen + at `T`. + +The martingale property of `discountedSpot` under `coinFlipMeasure (crrUpProb u d r)` +(`martingale_discountedSpot`) transports along `flips T` to `IsEMM` for the finite market +(`isEMM_horizonSpot`), so `ftap_discrete` gives no arbitrage (`noArbitrage_horizonSpot`). The +converse is explicit: if `e^r ≤ d` or `u ≤ e^r`, holding `±1` unit over the first period is an +arbitrage (`binomialNoArb_of_noArbitrage`). Together: +`NoArbitrage ↔ BinomialNoArb u d r` for the multi-period tree (`noArbitrage_horizonSpot_iff`). + +The martingale measure is unique (`IsEMM.eq_horizonMeasure`, `existsUnique_isEMM_horizonSpot`), +and so, by the Second FTAP (`ftap_two`, `Pricing/FTAP/FTAPComplete.lean`), the market is complete +(`isCompleteMarket_horizonSpot`): every claim on the paths is replicated by a predictable strategy +in the discounted spot. That strategy's capital is the contract's value when the claim is a European +contract's (`Models/Binomial/BinomialCompleteMarket.lean`). +Node by node, on the atom `{y | y agrees with x on the first t flips}` of `ℱₜ` +(`horizonAtom`), the martingale property in set-integral form gives +`∫_A (S_{t+1} − S_t) dQ = 0`; on `A` the increment is `S_t(x) (e^{-r} u − 1)` or +`S_t(x) (e^{-r} d − 1)` according to flip `t`, which forces the conditional up-probability to +`crrUpProb` (`IsEMM.real_atom_flip`). Induction on the prefix length gives every atom its product +probability (`IsEMM.real_horizonAtom`), and at `t = T` the atoms are the paths, so `Q` is +`horizonMeasure T (crrUpProb u d r)` (`horizonMeasure_singleton`). + +## Main definitions + +* `horizonFiltration`: the filtration of the `T`-period market on `Fin T → Bool`, `ℱₙ` generated + by the first `n` flips and frozen from time `T`. +* `horizonMeasure`: the real-world measure, the law of the first `T` i.i.d. `Bernoulli(q)` flips. +* `horizonSpot`: the discounted price process of the `T`-period tree. +* `horizonAtom`: the atom of `ℱₜ` through a path `x`, the paths agreeing with `x` on the first `t` + flips. + +## Main results + +* `comap_flips_horizonFiltration` — at times `t ≤ T`, `flipFiltration t` is the pullback of + `horizonFiltration T t` along `flips T`. +* `isEMM_horizonSpot_map` — a measure on the paths making the frozen discounted spot a martingale + maps to an equivalent martingale measure of the `T`-period tree. +* `isEMM_horizonSpot` — under `BinomialNoArb`, `horizonMeasure (crrUpProb)` is an equivalent + martingale measure for every real-world `horizonMeasure p`, `0 < p < 1`. +* `noArbitrage_horizonSpot_iff` — `NoArbitrage ↔ BinomialNoArb u d r` (for `S₀ > 0`, `0 < d < u`, + at least one period). +* `IsEMM.eq_horizonMeasure` — under `BinomialNoArb` and `S₀ > 0`, every `IsEMM` of the market is + `horizonMeasure T (crrUpProb u d r)`; `existsUnique_isEMM_horizonSpot` packages existence and + uniqueness. +* `isCompleteMarket_horizonSpot_iff` — the Second FTAP for the tree: under `BinomialNoArb` the + market is complete iff it has exactly one equivalent martingale measure. +* `isCompleteMarket_horizonSpot` — for `S₀ > 0` both hold: the market is complete. + +## References + +* [J. M. Harrison and S. R. Pliska, *Martingales and stochastic integrals in the theory of + continuous trading*][HarrisonPliska1981] +* [S. E. Shreve, *Stochastic Calculus for Finance I: The Binomial Asset Pricing Model*][ShreveSCFI], + Section 5.4 + +## Tags + +fundamental theorem of asset pricing, equivalent martingale measure, no arbitrage, +market completeness, Harrison–Pliska, multi-period binomial, MSC 91G20, MSC 60G42, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Finset +open scoped ENNReal NNReal + +section Market + +variable (T : ℕ) + +/-- The path `x` with every flip from time `n` on blanked (set to `false`). -/ +def revealed (n : ℕ) (x : Fin T → Bool) : Fin T → Bool := + fun i ↦ if (i : ℕ) < n then x i else false + +lemma measurable_revealed (n : ℕ) : Measurable (revealed T n) := measurable_of_countable _ + +/-- The **filtration of the `T`-period coin-flip market**: `ℱₙ = σ(ω₀, …, ω_{n−1})` on +`Fin T → Bool`, constant (the whole path) from time `T` on. -/ +def horizonFiltration : Filtration ℕ (inferInstance : MeasurableSpace (Fin T → Bool)) where + seq n := MeasurableSpace.comap (revealed T n) inferInstance + mono' m n hmn := by + have : revealed T m = revealed T m ∘ revealed T n := by + funext x i + simp only [revealed, Function.comp] + split_ifs <;> first | rfl | omega + dsimp only + rw [this, ← MeasurableSpace.comap_comp] + exact MeasurableSpace.comap_mono (Measurable.comap_le (measurable_revealed T m)) + le' n := (measurable_revealed T n).comap_le + +/-- The first `T` flips as a path of length `T`, extended by `false`: a right inverse of +`flips T`. -/ +def padFlips (x : Fin T → Bool) : ℕ → Bool := fun k ↦ if h : k < T then x ⟨k, h⟩ else false + +lemma flips_padFlips (x : Fin T → Bool) : flips T (padFlips T x) = x := + funext fun i ↦ by simp [flips, padFlips, i.2] + +/-- **The pullback of the finite-horizon filtration is the path-space filtration.** On `[0, T]` +the natural flip filtration `flipFiltration` of `ℕ → Bool` is the preimage under `flips T` of +`horizonFiltration T`. -/ +theorem comap_flips_horizonFiltration {t : ℕ} (ht : t ≤ T) : + MeasurableSpace.comap (flips T) (horizonFiltration T t) = flipFiltration t := by + refine le_antisymm ?_ ?_ + · -- `revealed t ∘ flips T` is a function of `flips t` + change MeasurableSpace.comap (flips T) (MeasurableSpace.comap (revealed T t) _) ≤ + MeasurableSpace.comap (flips t) _ + rw [MeasurableSpace.comap_comp] + have : revealed T t ∘ flips T = + (fun y : Fin t → Bool ↦ fun i : Fin T ↦ if h : (i : ℕ) < t then y ⟨i, h⟩ else false) ∘ + flips t := by + funext ω i + by_cases h : (i : ℕ) < t <;> simp [revealed, flips, h] + rw [this, ← MeasurableSpace.comap_comp] + exact MeasurableSpace.comap_mono (Measurable.comap_le (measurable_of_countable _)) + · -- `flips t` is a function of `revealed t ∘ flips T` + change MeasurableSpace.comap (flips t) _ ≤ + MeasurableSpace.comap (flips T) (MeasurableSpace.comap (revealed T t) _) + rw [MeasurableSpace.comap_comp] + have : flips t = (fun z : Fin T → Bool ↦ fun i : Fin t ↦ z ⟨i, lt_of_lt_of_le i.2 ht⟩) ∘ + (revealed T t ∘ flips T) := by + funext ω i + simp [revealed, flips, i.2] + rw [this, ← MeasurableSpace.comap_comp] + exact MeasurableSpace.comap_mono (Measurable.comap_le (measurable_of_countable _)) + +/-- The **real-world measure** of the `T`-period market: the law of the first `T` i.i.d. +`Bernoulli(q)` flips. -/ +noncomputable def horizonMeasure (q : ℝ≥0) (hq : q ≤ 1) : Measure (Fin T → Bool) := + (coinFlipMeasure q hq).map (flips T) + +instance (q : ℝ≥0) (hq : q ≤ 1) : IsProbabilityMeasure (horizonMeasure T q hq) := + inferInstanceAs (IsProbabilityMeasure ((coinFlipMeasure q hq).map (flips T))) + +lemma horizonMeasure_singleton (q : ℝ≥0) (hq : q ≤ 1) (x : Fin T → Bool) : + horizonMeasure T q hq {x} = ∏ i, if x i then (q : ℝ≥0∞) else 1 - q := by + rw [horizonMeasure, Measure.map_apply (measurable_flips T) (measurableSet_singleton x), + coinFlipMeasure_flips_preimage] + +/-- **Full support.** For `0 < q < 1` every path of the `T`-period market has positive +probability. -/ +theorem horizonMeasure_pos {q : ℝ≥0} (hq0 : 0 < q) (hq1 : q < 1) (x : Fin T → Bool) : + 0 < horizonMeasure T q hq1.le {x} := by + rw [horizonMeasure, Measure.map_apply (measurable_flips T) (measurableSet_singleton x)] + exact coinFlipMeasure_flips_preimage_pos hq0 hq1 T x + +/-- The **discounted price** of the `T`-period market: the discounted CRR spot after `n ∧ T` +flips, the path extended by `false` beyond the horizon (which it does not read). -/ +noncomputable def horizonSpot (S₀ u d r : ℝ) (n : ℕ) (x : Fin T → Bool) : ℝ := + discountedSpot S₀ u d r (min n T) (padFlips T x) + +variable {T} {S₀ u d r : ℝ} + +/-- Up to the horizon, the market price pulled back along `flips T` is the path-space price. -/ +lemma horizonSpot_flips {n : ℕ} (hn : n ≤ T) (ω : ℕ → Bool) : + horizonSpot T S₀ u d r n (flips T ω) = discountedSpot S₀ u d r n ω := by + rw [horizonSpot, min_eq_left hn] + exact pathAdaptedAt_discountedSpot S₀ u d r n _ _ fun i hi ↦ by + simp [padFlips, flips, lt_of_lt_of_le hi hn] + +lemma horizonSpot_revealed (n : ℕ) (x : Fin T → Bool) : + horizonSpot T S₀ u d r n (revealed T n x) = horizonSpot T S₀ u d r n x := + pathAdaptedAt_discountedSpot S₀ u d r (min n T) _ _ fun i hi ↦ by + have hiT : i < T := lt_of_lt_of_le hi (min_le_right n T) + have hin : i < n := lt_of_lt_of_le hi (min_le_left n T) + simp [padFlips, revealed, hiT, hin] + +/-- The market price is adapted to `horizonFiltration`. -/ +lemma stronglyAdapted_horizonSpot : + StronglyAdapted (horizonFiltration T) (horizonSpot T S₀ u d r) := + fun n ↦ by + have : horizonSpot T S₀ u d r n = horizonSpot T S₀ u d r n ∘ revealed T n := + funext fun x ↦ (horizonSpot_revealed n x).symm + rw [this] + exact ((measurable_of_countable _).comp + (comap_measurable (revealed T n))).stronglyMeasurable + +end Market + +section NoArbitrage + +variable {T : ℕ} {S₀ u d r : ℝ} + +/-- On a full-support space, a.e. equality is pointwise equality. -/ +lemma eq_of_ae_eq_of_pos {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} (hμ : ∀ x, 0 < μ {x}) {f g : Ω → ℝ} (h : f =ᵐ[μ] g) (x : Ω) : + f x = g x := by + by_contra hx + exact (hμ x).not_ge ((measure_mono (show {x} ⊆ {y | ¬ f y = g y} by simpa)).trans_eq + (ae_iff.1 h)) + +/-- **A martingale measure on the paths gives one on the first `T` flips.** If the discounted spot +frozen at `T` is a `Q`-martingale for the flip filtration, the law of the first `T` flips under `Q` +is an equivalent martingale measure, in the sense of `MathFin.IsEMM`, for the `T`-period tree, +against any reference measure equivalent to it: the set integrals over the events of `ℱₜ` transport +along `flips T` (`comap_flips_horizonFiltration`). -/ +theorem isEMM_horizonSpot_map {Q : Measure (ℕ → Bool)} [IsProbabilityMeasure Q] + {P : Measure (Fin T → Bool)} (hQP : IsEquivProbMeasure P (Q.map (flips T))) + (hM : Martingale (fun n ↦ discountedSpot S₀ u d r (min n T)) flipFiltration Q) : + IsEMM (horizonFiltration T) P (horizonSpot T S₀ u d r) T (Q.map (flips T)) := by + refine .of_condExp_succ hQP (fun t _ ↦ stronglyAdapted_horizonSpot t) + (fun t _ ↦ Integrable.of_finite) fun t ht ↦ ?_ + refine ae_eq_condExp_of_forall_setIntegral_eq ((horizonFiltration T).le t) Integrable.of_finite + (fun s _ _ ↦ Integrable.of_finite.integrableOn) (fun s hs _ ↦ ?_) + (stronglyAdapted_horizonSpot t).aestronglyMeasurable + have hs' : MeasurableSet[flipFiltration t] (flips T ⁻¹' s) := by + rw [← comap_flips_horizonFiltration T ht.le] + exact ⟨s, hs, rfl⟩ + have hsm : MeasurableSet s := (horizonFiltration T).le t s hs + rw [setIntegral_map hsm Integrable.of_finite.aestronglyMeasurable + (measurable_flips T).aemeasurable, + setIntegral_map hsm Integrable.of_finite.aestronglyMeasurable (measurable_flips T).aemeasurable] + simp_rw [horizonSpot_flips ht.le, horizonSpot_flips (Nat.succ_le_of_lt ht)] + simpa only [min_eq_left ht.le, min_eq_left (Nat.succ_le_of_lt ht)] using + hM.setIntegral_eq (Nat.le_succ t) hs' + +/-- **An equivalent martingale measure for the `T`-period tree.** Under `BinomialNoArb u d r`, +the law of the first `T` i.i.d. `Bernoulli(q)` flips with `q = crrUpProb u d r` is an equivalent +martingale measure, in the sense of `MathFin.IsEMM`, for the discounted spot, against the +real-world law of i.i.d. `Bernoulli(p)` flips, any `0 < p < 1`: the martingale property +`martingale_discountedSpot` transports along `flips T` (`isEMM_horizonSpot_map`). -/ +theorem isEMM_horizonSpot (h : BinomialNoArb u d r) (S₀ : ℝ) {p q : ℝ≥0} (hp0 : 0 < p) + (hp1 : p < 1) (hq1 : q ≤ 1) (hqcrr : crrUpProb u d r = q) : + IsEMM (horizonFiltration T) (horizonMeasure T p hp1.le) (horizonSpot T S₀ u d r) T + (horizonMeasure T q hq1) := by + have hq0 : 0 < q := by + have := (crrUpProb_mem_Ioo h).1 + rw [hqcrr] at this + exact_mod_cast this + have hq1' : q < 1 := by + have := (crrUpProb_mem_Ioo h).2 + rw [hqcrr] at this + exact_mod_cast this + exact isEMM_horizonSpot_map (Q := coinFlipMeasure q hq1) + ⟨inferInstance, + fun s hs ↦ by + rw [eq_empty_of_pos_singleton (horizonMeasure_pos T hp0 hp1) hs, measure_empty], + fun s hs ↦ by + rw [eq_empty_of_pos_singleton (horizonMeasure_pos T hq0 hq1') hs, measure_empty]⟩ + (martingale_min_of_martingale (martingale_discountedSpot h S₀ hq1 hqcrr) T) + +/-- **Multi-period binomial no-arbitrage, through the discrete FTAP.** Under +`BinomialNoArb u d r`, the `T`-period CRR market (discounted spot, flip filtration, real-world +law of i.i.d. `Bernoulli(p)` flips, `0 < p < 1`) admits no arbitrage: `isEMM_horizonSpot` and +the easy direction of `ftap_discrete`. -/ +theorem noArbitrage_horizonSpot (h : BinomialNoArb u d r) (S₀ : ℝ) {p : ℝ≥0} (hp0 : 0 < p) + (hp1 : p < 1) : + NoArbitrage (horizonFiltration T) (horizonMeasure T p hp1.le) (horizonSpot T S₀ u d r) T := by + obtain ⟨q, hq1, hqcrr⟩ := h.exists_nnreal_crrUpProb + exact (ftap_discrete _ _ _ _ stronglyAdapted_horizonSpot (horizonMeasure_pos T hp0 hp1)).2 + ⟨_, isEMM_horizonSpot h S₀ hp0 hp1 hq1 hqcrr⟩ + +lemma horizonSpot_zero (x : Fin T → Bool) : horizonSpot T S₀ u d r 0 x = S₀ := by + simp [horizonSpot, discountedSpot, spotPath] + +lemma horizonSpot_one (hT : 0 < T) (x : Fin T → Bool) : + horizonSpot T S₀ u d r 1 x = Real.exp (-r) * (S₀ * if x ⟨0, hT⟩ then u else d) := by + simp [horizonSpot, discountedSpot, spotPath, padFlips, hT, min_eq_left (Nat.succ_le_of_lt hT)] + +/-- Holding `c` units over the first period only has gain `c · (S₁ − S₀)`. -/ +lemma martingaleTransform_holdFirst (c : ℝ) (hT : 0 < T) (x : Fin T → Bool) : + martingaleTransform (fun s _ ↦ if s = 1 then c else 0) (horizonSpot T S₀ u d r) T x + = c * (horizonSpot T S₀ u d r 1 x - horizonSpot T S₀ u d r 0 x) := by + rw [martingaleTransform, Finset.sum_eq_single 0] + · simp [mul_comm] + · intro k _ hk + simp [hk] + · intro h0 + exact absurd (Finset.mem_range.2 hT) h0 + +/-- **A one-period arbitrage if the tree is not arbitrage-free.** For `S₀ > 0`, `0 < d < u` and at +least one period, no arbitrage in the `T`-period market forces `d < e^r < u`: if `e^r ≤ d`, holding +one unit over the first period is a sure gain, and if `u ≤ e^r`, so is holding minus one. -/ +theorem binomialNoArb_of_noArbitrage (hS₀ : 0 < S₀) (hd : 0 < d) (hdu : d < u) (hT : 0 < T) + {p : ℝ≥0} (hp0 : 0 < p) (hp1 : p < 1) + (hNA : NoArbitrage (horizonFiltration T) (horizonMeasure T p hp1.le) + (horizonSpot T S₀ u d r) T) : + BinomialNoArb u d r := by + have hpos := horizonMeasure_pos T hp0 hp1 + have he : Real.exp (-r) * Real.exp r = 1 := by rw [← Real.exp_add]; simp + have hden : 0 < S₀ * Real.exp (-r) := mul_pos hS₀ (Real.exp_pos _) + -- the first-period excess gain, node by node + have hgain (x : Fin T → Bool) : horizonSpot T S₀ u d r 1 x - horizonSpot T S₀ u d r 0 x + = S₀ * Real.exp (-r) * ((if x ⟨0, hT⟩ then u else d) - Real.exp r) := by + rw [horizonSpot_one hT, horizonSpot_zero] + linear_combination S₀ * he + -- a sure first-period gain is no gain at all + have noarb (c : ℝ) (hnn : ∀ x : Fin T → Bool, + 0 ≤ c * (S₀ * Real.exp (-r) * ((if x ⟨0, hT⟩ then u else d) - Real.exp r))) + (x : Fin T → Bool) : + c * (S₀ * Real.exp (-r) * ((if x ⟨0, hT⟩ then u else d) - Real.exp r)) = 0 := by + have h := hNA (fun s _ ↦ if s = 1 then c else 0) (fun _ _ ↦ stronglyMeasurable_const) + ⟨|c|, fun n _ _ ↦ by by_cases h : n = 1 <;> simp [h]⟩ + (Filter.Eventually.of_forall fun x ↦ by + simpa only [Pi.zero_apply, martingaleTransform_holdFirst c hT, hgain] using hnn x) + simpa only [Pi.zero_apply, martingaleTransform_holdFirst c hT, hgain] using + eq_of_ae_eq_of_pos hpos h x + refine ⟨hd, ?_, ?_⟩ + · by_contra hle + have hle := not_lt.1 hle + have := noarb 1 (fun x ↦ by + split_ifs <;> exact mul_nonneg (by norm_num) (mul_nonneg hden.le (by linarith))) fun _ ↦ true + beta_reduce at this + rw [ite_eq_left rfl, one_mul] at this + exact (mul_pos hden (by linarith)).ne' this + · by_contra hle + have hle := not_lt.1 hle + have := noarb (-1) (fun x ↦ by + split_ifs <;> exact (by nlinarith [mul_nonneg hden.le (sub_nonneg.2 hle)])) fun _ ↦ false + beta_reduce at this + rw [ite_eq_right (by decide)] at this + nlinarith [mul_pos hden (show 0 < Real.exp r - d by linarith)] + +/-- **No arbitrage in the multi-period binomial tree iff `d < e^r < u`.** For `S₀ > 0`, +`0 < d < u`, at least one period and a real-world law of i.i.d. `Bernoulli(p)` flips, `0 < p < 1`, +the `T`-period CRR market has no arbitrage (`FTAPDiscrete.NoArbitrage`) exactly when +`BinomialNoArb u d r` holds. -/ +theorem noArbitrage_horizonSpot_iff (hS₀ : 0 < S₀) (hd : 0 < d) (hdu : d < u) (hT : 0 < T) + {p : ℝ≥0} (hp0 : 0 < p) (hp1 : p < 1) : + NoArbitrage (horizonFiltration T) (horizonMeasure T p hp1.le) (horizonSpot T S₀ u d r) T + ↔ BinomialNoArb u d r := + ⟨binomialNoArb_of_noArbitrage hS₀ hd hdu hT hp0 hp1, fun h ↦ noArbitrage_horizonSpot h S₀ hp0 hp1⟩ + +end NoArbitrage + +section Uniqueness + +variable {T : ℕ} {S₀ u d r : ℝ} + +/-- One period of the market price: `S_{t+1} = S_t · e^{-r} · (u or d)` according to flip `t`. -/ +lemma horizonSpot_succ {t : ℕ} (ht : t < T) (y : Fin T → Bool) : + horizonSpot T S₀ u d r (t + 1) y + = horizonSpot T S₀ u d r t y * (Real.exp (-r) * if y ⟨t, ht⟩ then u else d) := by + have h1 : min (t + 1) T = t + 1 := min_eq_left ht + have h2 : min t T = t := min_eq_left ht.le + simp only [horizonSpot, discountedSpot, spotPath, h1, h2, Finset.prod_range_succ, + padFlips, dite_eq_left ht] + rw [show -(r * ((t + 1 : ℕ) : ℝ)) = -(r * t) + -r by push_cast; ring, Real.exp_add] + ring + +lemma horizonSpot_pos (hS₀ : 0 < S₀) (hd : 0 < d) (hu : 0 < u) (n : ℕ) (y : Fin T → Bool) : + 0 < horizonSpot T S₀ u d r n y := by + unfold horizonSpot discountedSpot spotPath + refine mul_pos (Real.exp_pos _) (mul_pos hS₀ (Finset.prod_pos fun i _ ↦ ?_)) + split_ifs <;> assumption + +/-- The **atom of `ℱₜ` through `x`**: the paths that agree with `x` on the first `t` flips. -/ +def horizonAtom (T t : ℕ) (x : Fin T → Bool) : Set (Fin T → Bool) := + revealed T t ⁻¹' {revealed T t x} + +lemma measurableSet_horizonAtom (t : ℕ) (x : Fin T → Bool) : + MeasurableSet[horizonFiltration T t] (horizonAtom T t x) := + ⟨{revealed T t x}, measurableSet_singleton _, rfl⟩ + +lemma mem_horizonAtom {t : ℕ} {x y : Fin T → Bool} : + y ∈ horizonAtom T t x ↔ ∀ i : Fin T, (i : ℕ) < t → y i = x i := by + simp only [horizonAtom, Set.mem_preimage, Set.mem_singleton_iff, revealed, funext_iff] + refine forall_congr' fun i ↦ ?_ + by_cases h : (i : ℕ) < t <;> simp [h] + +lemma horizonAtom_zero (x : Fin T → Bool) : horizonAtom T 0 x = Set.univ := + Set.eq_univ_of_forall fun _ ↦ mem_horizonAtom.2 fun _ hi ↦ absurd hi (Nat.not_lt_zero _) + +lemma horizonAtom_horizon (x : Fin T → Bool) : horizonAtom T T x = {x} := + Set.ext fun y ↦ by simp [mem_horizonAtom, funext_iff] + +lemma horizonAtom_succ {t : ℕ} (ht : t < T) (x : Fin T → Bool) : + horizonAtom T (t + 1) x = horizonAtom T t x ∩ {y | y ⟨t, ht⟩ = x ⟨t, ht⟩} := by + ext y + simp only [mem_horizonAtom, Set.mem_inter_iff, Set.mem_ofPred_eq] + refine ⟨fun h ↦ ⟨fun i hi ↦ h i (by omega), h _ (Nat.lt_succ_self t)⟩, fun ⟨h, h'⟩ i hi ↦ ?_⟩ + rcases Nat.lt_succ_iff_lt_or_eq.1 hi with hi | hi + · exact h i hi + · have : i = ⟨t, ht⟩ := Fin.ext hi + rw [this]; exact h' + +lemma horizonSpot_eq_of_mem_horizonAtom {t : ℕ} {x y : Fin T → Bool} (hy : y ∈ horizonAtom T t x) : + horizonSpot T S₀ u d r t y = horizonSpot T S₀ u d r t x := by + rw [← horizonSpot_revealed t y, ← horizonSpot_revealed t x] + exact congrArg _ hy + +variable {P Q : Measure (Fin T → Bool)} + +/-- **The conditional up-probability of an equivalent martingale measure is `crrUpProb`.** If +`Q` makes the discounted spot a martingale, then `Q` gives the up-flip at time `t` probability +`crrUpProb` *conditionally on every history atom* of `ℱₜ`: the martingale property in set-integral +form on the atom `A`, `∫_A (S_{t+1} − S_t) dQ = 0`, reads +`S_t(x) · (e^{-r}(u · Q(A ∩ up) + d · Q(A ∩ down)) − Q(A)) = 0`, which together with +`Q(A) = Q(A ∩ up) + Q(A ∩ down)` pins `Q(A ∩ up)/Q(A)` to `(e^r − d)/(u − d)`. -/ +theorem IsEMM.real_atom_up (hS₀ : 0 < S₀) (h : BinomialNoArb u d r) + (hQ : IsEMM (horizonFiltration T) P (horizonSpot T S₀ u d r) T Q) {t : ℕ} (ht : t < T) + (x : Fin T → Bool) : + Q.real (horizonAtom T t x ∩ {y | y ⟨t, ht⟩ = true}) + = crrUpProb u d r * Q.real (horizonAtom T t x) := by + have := hQ.isProb + set A := horizonAtom T t x + set U : Set (Fin T → Bool) := {y | y ⟨t, ht⟩ = true} + have hA : MeasurableSet A := (horizonFiltration T).le t _ (measurableSet_horizonAtom t x) + have hU : MeasurableSet U := MeasurableSet.of_discrete + have hspot : ∫ y in A, horizonSpot T S₀ u d r (t + 1) y ∂Q + = ∫ y in A, horizonSpot T S₀ u d r t y ∂Q := by + rw [← setIntegral_condExp ((horizonFiltration T).le t) Integrable.of_finite + (measurableSet_horizonAtom t x)] + exact setIntegral_congr_ae hA + (by filter_upwards [hQ.condExp_eq t.le_succ (Nat.succ_le_of_lt ht)] with y hy _ using hy) + set s := horizonSpot T S₀ u d r t x + have hs : 0 < s := horizonSpot_pos hS₀ h.d_pos (h.d_pos.trans h.d_lt_u) t x + -- split the atom along the next flip + have hsplit (F : (Fin T → Bool) → ℝ) : ∫ y in A, F y ∂Q + = ∫ y in A ∩ U, F y ∂Q + ∫ y in A \ U, F y ∂Q := + (integral_inter_add_sdiff hU Integrable.of_finite.integrableOn).symm + -- on each half the increment is a constant multiple of `s` + have hup : ∫ y in A ∩ U, horizonSpot T S₀ u d r (t + 1) y ∂Q + = Q.real (A ∩ U) * (s * (Real.exp (-r) * u)) := by + rw [setIntegral_congr_fun (hA.inter hU) fun y hy ↦ by + rw [horizonSpot_succ ht, horizonSpot_eq_of_mem_horizonAtom hy.1, + ite_eq_left (show y ⟨t, ht⟩ = true from hy.2)], + setIntegral_const, smul_eq_mul] + have hdown : ∫ y in A \ U, horizonSpot T S₀ u d r (t + 1) y ∂Q + = Q.real (A \ U) * (s * (Real.exp (-r) * d)) := by + rw [setIntegral_congr_fun (hA.diff hU) fun y hy ↦ by + rw [horizonSpot_succ ht, horizonSpot_eq_of_mem_horizonAtom hy.1, + ite_eq_right (show ¬ y ⟨t, ht⟩ = true from hy.2)], + setIntegral_const, smul_eq_mul] + have hnow : ∫ y in A, horizonSpot T S₀ u d r t y ∂Q = Q.real A * s := by + rw [setIntegral_congr_fun hA fun y hy ↦ horizonSpot_eq_of_mem_horizonAtom hy, + setIntegral_const, smul_eq_mul] + rw [hsplit, hup, hdown, hnow, ← measureReal_inter_add_sdiff (s := A) hU] at hspot + have he : Real.exp (-r) * Real.exp r = 1 := by rw [← Real.exp_add]; simp + have hud : u - d ≠ 0 := (sub_pos.2 h.d_lt_u).ne' + have key : (Real.exp (-r) * u - 1) * Q.real (A ∩ U) + (Real.exp (-r) * d - 1) * Q.real (A \ U) + = 0 := by + refine mul_left_cancel₀ hs.ne' ?_ + linear_combination hspot + rw [crrUpProb, div_mul_eq_mul_div, eq_div_iff hud, ← measureReal_inter_add_sdiff (s := A) hU] + linear_combination Real.exp r * key - (u * Q.real (A ∩ U) + d * Q.real (A \ U)) * he + +/-- The conditional probability of either flip at time `t`, given a history atom: `crrUpProb` for +up and `1 - crrUpProb` for down. -/ +theorem IsEMM.real_atom_flip (hS₀ : 0 < S₀) (h : BinomialNoArb u d r) + (hQ : IsEMM (horizonFiltration T) P (horizonSpot T S₀ u d r) T Q) {t : ℕ} (ht : t < T) + (x : Fin T → Bool) (b : Bool) : + Q.real (horizonAtom T t x ∩ {y | y ⟨t, ht⟩ = b}) + = (if b then crrUpProb u d r else 1 - crrUpProb u d r) * Q.real (horizonAtom T t x) := by + have hup := IsEMM.real_atom_up hS₀ h hQ ht x + cases b + · have := hQ.isProb + have hU : MeasurableSet {y : Fin T → Bool | y ⟨t, ht⟩ = true} := MeasurableSet.of_discrete + have hsum := measureReal_inter_add_sdiff (μ := Q) (s := horizonAtom T t x) hU + have hset : horizonAtom T t x ∩ {y | y ⟨t, ht⟩ = false} + = horizonAtom T t x \ {y | y ⟨t, ht⟩ = true} := by + ext y; simp + rw [hset, ite_eq_right Bool.false_ne_true] + linear_combination hsum - hup + · simpa using hup + +/-- **Every history atom has the product-form probability.** Under an equivalent martingale +measure `Q`, the paths agreeing with `x` on the first `t ≤ T` flips have probability +`∏_{i + have := hQ.isProb + intro _ + simp [horizonAtom_zero] + | succ t ih => + intro ht + have ht' : t < T := ht + rw [horizonAtom_succ ht', IsEMM.real_atom_flip hS₀ h hQ ht' x (x ⟨t, ht'⟩), ih ht'.le, mul_comm] + have hpt (i : Fin T) : (if (i : ℕ) < t + 1 then + (if x i then crrUpProb u d r else 1 - crrUpProb u d r) else 1) + = (if (i : ℕ) < t then (if x i then crrUpProb u d r else 1 - crrUpProb u d r) else 1) + * (if i = ⟨t, ht'⟩ then (if x i then crrUpProb u d r else 1 - crrUpProb u d r) + else 1) := by + by_cases h1 : (i : ℕ) < t + · have : i ≠ ⟨t, ht'⟩ := fun e ↦ by simp [e] at h1 + simp [h1, this, show (i : ℕ) < t + 1 by omega] + · by_cases h2 : i = ⟨t, ht'⟩ + · subst h2; simp + · have : ¬ (i : ℕ) < t + 1 := by + have := Fin.val_ne_of_ne h2 + simp only at this + omega + simp [h1, h2, this] + rw [Finset.prod_congr rfl fun i _ ↦ hpt i, Finset.prod_mul_distrib, Finset.prod_ite_eq'] + simp + +lemma horizonMeasure_real_singleton (q : ℝ≥0) (hq : q ≤ 1) (x : Fin T → Bool) : + (horizonMeasure T q hq).real {x} = ∏ i, if x i then (q : ℝ) else 1 - q := by + rw [measureReal_def, horizonMeasure_singleton, ENNReal.toReal_prod] + refine Finset.prod_congr rfl fun i _ ↦ ?_ + cases x i with + | false => + simp only [Bool.false_eq_true, ↓reduceIte] + rw [ENNReal.toReal_sub_of_le (ENNReal.coe_le_one_iff.mpr hq) ENNReal.one_ne_top] + simp + | true => simp + +/-- **The equivalent martingale measure of the multi-period tree is unique.** Under +`BinomialNoArb u d r` and `S₀ > 0`, every probability measure `Q` that makes the discounted spot +a martingale for the filtration of the first `n` flips (`IsEMM`, for any reference measure `P`) +is the law of `T` i.i.d. `Bernoulli(q)` flips with `q = crrUpProb u d r`. Node by node, +`Q` gives the next flip conditional probability `q` on every history atom +(`IsEMM.real_atom_flip`), so it gives each path the product probability +(`IsEMM.real_horizonAtom` at `t = T`), which is `horizonMeasure_singleton`. -/ +theorem IsEMM.eq_horizonMeasure (hS₀ : 0 < S₀) (h : BinomialNoArb u d r) + (hQ : IsEMM (horizonFiltration T) P (horizonSpot T S₀ u d r) T Q) {q : ℝ≥0} (hq1 : q ≤ 1) + (hqcrr : crrUpProb u d r = q) : Q = horizonMeasure T q hq1 := by + have := hQ.isProb + refine Measure.ext_iff_singleton.2 fun x ↦ ?_ + refine (ENNReal.toReal_eq_toReal_iff' (measure_ne_top _ _) (measure_ne_top _ _)).1 ?_ + change Q.real {x} = (horizonMeasure T q hq1).real {x} + rw [horizonMeasure_real_singleton, ← horizonAtom_horizon, + hQ.real_horizonAtom hS₀ h x T le_rfl] + refine Finset.prod_congr rfl fun i _ ↦ ?_ + simp [i.2, hqcrr] + +/-- **The multi-period binomial market has a unique equivalent martingale measure.** Under +`BinomialNoArb u d r` and `S₀ > 0`, for every real-world law of i.i.d. `Bernoulli(p)` flips, +`0 < p < 1`, the `T`-period CRR market has exactly one `MathFin.IsEMM`, the i.i.d. +`Bernoulli(crrUpProb u d r)` law of the flips: existence is `isEMM_horizonSpot` and uniqueness +`IsEMM.eq_horizonMeasure`. Uniqueness of the equivalent martingale measure is what the second +fundamental theorem equates with completeness (`isCompleteMarket_horizonSpot_iff`). -/ +theorem existsUnique_isEMM_horizonSpot (hS₀ : 0 < S₀) (h : BinomialNoArb u d r) {p q : ℝ≥0} + (hp0 : 0 < p) (hp1 : p < 1) (hq1 : q ≤ 1) (hqcrr : crrUpProb u d r = q) : + ∃! Q, IsEMM (horizonFiltration T) (horizonMeasure T p hp1.le) (horizonSpot T S₀ u d r) T Q := + ⟨horizonMeasure T q hq1, isEMM_horizonSpot h S₀ hp0 hp1 hq1 hqcrr, + fun _ hQ ↦ hQ.eq_horizonMeasure hS₀ h hq1 hqcrr⟩ + +end Uniqueness + +section Complete + +variable {T : ℕ} {S₀ u d r : ℝ} + +/-- At the horizon the whole path is known: `horizonFiltration T T` is the full σ-algebra of +`Fin T → Bool`. -/ +lemma horizonFiltration_horizon : + horizonFiltration T T = (inferInstance : MeasurableSpace (Fin T → Bool)) := by + change MeasurableSpace.comap (revealed T T) _ = _ + rw [show revealed T T = id from funext fun x ↦ funext fun i ↦ by simp [revealed, i.2], + MeasurableSpace.comap_id] + +/-- **The Second Fundamental Theorem for the multi-period binomial tree.** Under +`BinomialNoArb u d r`, the `T`-period CRR market is complete (`IsCompleteMarket`: every claim on +the paths is the terminal wealth of a predictable strategy in the discounted spot, from some +initial wealth) exactly when its equivalent martingale measure is unique. This is `ftap_two` for +the market of this file; that the measure is unique, so that both sides hold, needs `S₀ > 0` and +is `existsUnique_isEMM_horizonSpot`. -/ +theorem isCompleteMarket_horizonSpot_iff (h : BinomialNoArb u d r) (S₀ : ℝ) {p : ℝ≥0} + (hp0 : 0 < p) (hp1 : p < 1) : + IsCompleteMarket (horizonFiltration T) (horizonMeasure T p hp1.le) (horizonSpot T S₀ u d r) T + ↔ ∃! Q, IsEMM (horizonFiltration T) (horizonMeasure T p hp1.le) + (horizonSpot T S₀ u d r) T Q := + ftap_two _ _ _ _ stronglyAdapted_horizonSpot (horizonMeasure_pos T hp0 hp1) + horizonFiltration_horizon (noArbitrage_horizonSpot h S₀ hp0 hp1) + +/-- **The multi-period binomial market is complete.** Under `BinomialNoArb u d r` and `S₀ > 0`, +every claim on the `T` flips is replicated by a predictable strategy in the discounted spot from +some initial wealth: the unique equivalent martingale measure +(`existsUnique_isEMM_horizonSpot`) makes the market complete +(`isCompleteMarket_horizonSpot_iff`). -/ +theorem isCompleteMarket_horizonSpot (hS₀ : 0 < S₀) (h : BinomialNoArb u d r) {p : ℝ≥0} + (hp0 : 0 < p) (hp1 : p < 1) : + IsCompleteMarket (horizonFiltration T) (horizonMeasure T p hp1.le) + (horizonSpot T S₀ u d r) T := by + obtain ⟨q, hq1, hqcrr⟩ := h.exists_nnreal_crrUpProb + exact (isCompleteMarket_horizonSpot_iff h S₀ hp0 hp1).2 + (existsUnique_isEMM_horizonSpot hS₀ h hp0 hp1 hq1 hqcrr) + +end Complete + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/PathMeasure.lean b/LeanPool/MathFin/Models/Binomial/PathMeasure.lean new file mode 100644 index 0000000000..02d8c9f290 --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/PathMeasure.lean @@ -0,0 +1,540 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.EuropeanReplication +public import LeanPool.MathFin.Probability.Discrete.SnellEnvelope +public import LeanPool.MathFin.Probability.Discrete.MarkovPathMeasure +public import Mathlib.Probability.ConditionalExpectation +public import Mathlib.Probability.Distributions.Bernoulli +public import Mathlib.Probability.Independence.InfinitePi +public import Mathlib.Topology.Separation.CompletelyRegular + +/-! +# The binomial price as an expectation over coin-flip paths + +`binomialPrice u d r g N S₀` (`Models/Binomial/Model.lean`) is the backward-induction price of the +`N`-step CRR tree, and `Models/Binomial/SnellEnvelope.lean` works on coin-flip paths `ω : ℕ → Bool` +with the spot `spotPath S₀ u d N ω = S₀ · ∏_{i + have huniv : flips 0 ⁻¹' {x} = Set.univ := + Set.eq_univ_of_forall fun ω ↦ Subsingleton.elim (flips 0 ω) x + rw [huniv, measure_univ, Finset.univ_eq_empty, prod_empty] + | succ n => + rw [flips_preimage_singleton, coinFlipMeasure_cylinder, ← Fin.prod_univ_eq_prod_range] + exact prod_congr rfl fun i _ ↦ by simp [i.isLt] + +/-- **Full support on cylinders.** For `0 < q < 1`, every finite flip sequence has positive +probability. -/ +theorem coinFlipMeasure_flips_preimage_pos {q : ℝ≥0} (hq0 : 0 < q) (hq1 : q < 1) (N : ℕ) + (x : Fin N → Bool) : 0 < coinFlipMeasure q hq1.le (flips N ⁻¹' {x}) := by + rw [coinFlipMeasure_flips_preimage, pos_iff_ne_zero, Finset.prod_ne_zero_iff] + intro i _ + split_ifs + · exact_mod_cast hq0.ne' + · exact (tsub_pos_iff_lt.2 (by exact_mod_cast hq1)).ne' + +/-- **Almost-sure equality of functions of finitely many flips is pointwise equality**, for +`0 < q < 1`: the cylinder through every path has positive probability. -/ +theorem PathAdaptedAt.eq_of_ae_eq {q : ℝ≥0} (hq0 : 0 < q) (hq1 : q < 1) {n : ℕ} + {f g : (ℕ → Bool) → ℝ} (hf : PathAdaptedAt n f) (hg : PathAdaptedAt n g) + (h : f =ᵐ[coinFlipMeasure q hq1.le] g) (ω : ℕ → Bool) : f ω = g ω := by + by_contra hne + refine (coinFlipMeasure_flips_preimage_pos hq0 hq1 n (flips n ω)).ne' ?_ + refine measure_mono_null (fun ω' (hω' : flips n ω' = flips n ω) ↦ ?_) (ae_iff.1 h) + have hagree : ∀ i, i < n → ω' i = ω i := fun i hi ↦ congrFun hω' ⟨i, hi⟩ + change ¬ f ω' = g ω' + rw [hf ω' ω hagree, hg ω' ω hagree] + exact hne + +/-- **Integrals of functions of finitely many flips are finite sums.** For any +`F : (Fin N → Bool) → ℝ`, the expectation of `F` of the first `N` flips is the sum over the +`2^N` flip sequences `x` of `F x` weighted by `∏ᵢ Bernoulli(q)(xᵢ)`. -/ +theorem integral_comp_flips (q : ℝ≥0) (hq : q ≤ 1) (N : ℕ) (F : (Fin N → Bool) → ℝ) : + ∫ ω, F (flips N ω) ∂coinFlipMeasure q hq + = ∑ x, (∏ i, if x i then (q : ℝ) else 1 - q) * F x := by + rw [← integral_map (measurable_flips N).aemeasurable + (measurable_of_countable F).aestronglyMeasurable, integral_fintype Integrable.of_finite] + refine sum_congr rfl fun x _ ↦ ?_ + rw [smul_eq_mul, measureReal_def, Measure.map_apply (measurable_flips N) + (measurableSet_singleton x), coinFlipMeasure_flips_preimage, ENNReal.toReal_prod] + congr 1 + refine prod_congr rfl fun i _ ↦ ?_ + cases x i with + | false => + simp only [Bool.false_eq_true, ↓reduceIte] + rw [ENNReal.toReal_sub_of_le (ENNReal.coe_le_one_iff.mpr hq) ENNReal.one_ne_top] + simp + | true => simp + +/-- **The backward recursion unrolled.** For `q = crrUpProb u d r`, the `N`-step binomial +price is `e^{−rN}` times the sum over the `2^N` up/down sequences `x` of +`(∏ᵢ (q if xᵢ else 1 − q)) · g(S · ∏ᵢ (u if xᵢ else d))`. -/ +theorem binomialPrice_eq_sum (u d r q : ℝ) (hq : crrUpProb u d r = q) (g : ℝ → ℝ) (N : ℕ) + (S : ℝ) : + binomialPrice u d r g N S = Real.exp (-(r * N)) * + ∑ x : Fin N → Bool, (∏ i, if x i then q else 1 - q) * g (S * ∏ i, if x i then u else d) := by + induction N generalizing S with + | zero => simp + | succ n ih => + have hsplit : ∑ x : Fin (n + 1) → Bool, + (∏ i, if x i then q else 1 - q) * g (S * ∏ i, if x i then u else d) + = q * ∑ y : Fin n → Bool, + (∏ i, if y i then q else 1 - q) * g (S * u * ∏ i, if y i then u else d) + + (1 - q) * ∑ y : Fin n → Bool, + (∏ i, if y i then q else 1 - q) * g (S * d * ∏ i, if y i then u else d) := by + rw [← (Fin.consEquiv fun _ : Fin (n + 1) ↦ Bool).sum_comp, Fintype.sum_prod_type, + Fintype.sum_bool, + mul_sum, mul_sum] + simp only [Fin.consEquiv, Equiv.coe_fn_mk, Fin.prod_univ_succ, Fin.cons_zero, + Fin.cons_succ, Bool.false_eq_true, ↓reduceIte, mul_assoc] + rw [binomialPrice_succ, hq, ih, ih, hsplit, + show -(r * ((n + 1 : ℕ) : ℝ)) = -r + -(r * n) by push_cast; ring, Real.exp_add] + ring + +/-- **The binomial price is an expectation over coin-flip paths.** If the CRR +risk-neutral up-probability `crrUpProb u d r` is `q ∈ [0, 1]`, then for every payoff `g`, +horizon `N` and spot `S₀`, + + `binomialPrice u d r g N S₀ = e^{−rN} · ∫ g(spotPath S₀ u d N ω) d(coinFlipMeasure q)(ω)`, + +where `coinFlipMeasure q` is the infinite product measure of i.i.d. `Bernoulli(q)` flips +on `ℕ → Bool`. -/ +theorem binomialPrice_eq_integral_coinFlipMeasure (u d r : ℝ) (g : ℝ → ℝ) {q : ℝ≥0} + (hq : q ≤ 1) (hqcrr : crrUpProb u d r = q) (N : ℕ) (S₀ : ℝ) : + binomialPrice u d r g N S₀ + = Real.exp (-(r * N)) * ∫ ω, g (spotPath S₀ u d N ω) ∂coinFlipMeasure q hq := by + have hspot (ω : ℕ → Bool) : + g (spotPath S₀ u d N ω) = g (S₀ * ∏ i, if flips N ω i then u else d) := by + rw [spotPath, ← Fin.prod_univ_eq_prod_range] + rfl + rw [binomialPrice_eq_sum u d r (q : ℝ) hqcrr g N S₀] + congr 1 + rw [integral_congr_ae (ae_of_all _ hspot), integral_comp_flips q hq N + fun x ↦ g (S₀ * ∏ i, if x i then u else d)] + +/-- The spot after `k` flips is a measurable function of the path. -/ +theorem measurable_spotPath (S₀ u d : ℝ) (k : ℕ) : Measurable (spotPath S₀ u d k) := + measurable_const.mul (Finset.measurable_prod _ fun i _ ↦ + (measurable_of_countable fun b : Bool ↦ if b then u else d).comp (measurable_pi_apply i)) + +/-- The spot after `k` flips is at most `|S₀| · max(|u|, |d|)ᵏ` in absolute value, along every +path. -/ +theorem abs_spotPath_le (S₀ u d : ℝ) (k : ℕ) (ω : ℕ → Bool) : + |spotPath S₀ u d k ω| ≤ |S₀| * max |u| |d| ^ k := by + rw [spotPath, abs_mul, abs_prod] + gcongr + calc ∏ i ∈ range k, |if ω i then u else d| ≤ ∏ _i ∈ range k, max |u| |d| := + prod_le_prod₀ (fun _ _ ↦ abs_nonneg _) fun i _ ↦ by split_ifs <;> simp + _ = max |u| |d| ^ k := by simp + +section Martingale + +variable {q : ℝ≥0} (hq : q ≤ 1) + +/-- **The conditional expectation of a function of `n + 1` flips is its node average.** For `f` +depending only on the first `n + 1` flips, `E[f | ℱₙ](ω) = q f(ω, flip n up) + (1 − q) f(ω, flip n +down)` almost surely, because the next flip is independent of the past +(`indep_flip_flipFiltration`, from `iIndepFun_infinitePi`). -/ +theorem condExp_flipFiltration_succ {n : ℕ} {f : (ℕ → Bool) → ℝ} (hf : PathAdaptedAt (n + 1) f) : + (coinFlipMeasure q hq)[f | flipFiltration n] =ᵐ[coinFlipMeasure q hq] + fun ω ↦ (q : ℝ) * f (Function.update ω n true) + (1 - q) * f (Function.update ω n false) := by + set μ := coinFlipMeasure q hq + set A : (ℕ → Bool) → ℝ := fun ω ↦ f (Function.update ω n true) + set B : (ℕ → Bool) → ℝ := fun ω ↦ f (Function.update ω n false) + set ind : (ℕ → Bool) → ℝ := fun ω ↦ if ω n then 1 else 0 + have hA := hf.fixFlip (n := n) true + have hB := hf.fixFlip (n := n) false + have hdecomp : f = B + (A - B) * ind := by + funext ω + have e := Function.update_eq_self n ω + cases hω : ω n + · rw [hω] at e + simp [A, B, ind, hω, e] + · rw [hω] at e + simp [A, B, ind, hω, e] + have hind_sm : StronglyMeasurable[MeasurableSpace.comap (fun ω : ℕ → Bool ↦ ω n) inferInstance] + ind := + ((measurable_of_countable fun b : Bool ↦ if b then (1 : ℝ) else 0).comp + (comap_measurable fun ω : ℕ → Bool ↦ ω n)).stronglyMeasurable + have hind_int : Integrable ind μ := + Integrable.of_finite.comp_measurable (g := fun b : Bool ↦ if b then (1 : ℝ) else 0) + (measurable_pi_apply n) + have hAB_sm : StronglyMeasurable[flipFiltration n] (A - B) := + (stronglyMeasurable_flipFiltration_iff.2 hA).sub (stronglyMeasurable_flipFiltration_iff.2 hB) + have hBint : Integrable B μ := hB.integrable hq + have hmul_int : Integrable ((A - B) * ind) μ := by + have : (A - B) * ind = f - B := by rw [hdecomp]; ring + rw [this] + exact (hf.integrable hq).sub hBint + have hind_cond : μ[ind | flipFiltration n] =ᵐ[μ] fun _ ↦ (q : ℝ) := + (condExp_indep_eq (measurable_pi_apply n).comap_le (flipFiltration.le n) hind_sm + (indep_flip_flipFiltration hq n)).trans (by rw [integral_flip_indicator hq]) + have h1 := condExp_add hBint hmul_int (flipFiltration n) (μ := μ) + have hc : μ[f | flipFiltration n] = μ[B + (A - B) * ind | flipFiltration n] := by + rw [← hdecomp] + rw [hc] + filter_upwards [h1, condExp_mul_of_stronglyMeasurable_left hAB_sm hmul_int hind_int + (m := flipFiltration n), hind_cond] with ω h1 h2 h3 + rw [Pi.add_apply] at h1 + rw [h1, h2, condExp_of_stronglyMeasurable (flipFiltration.le n) + (stronglyMeasurable_flipFiltration_iff.2 hB) hBint, Pi.mul_apply, h3] + simp only [Pi.sub_apply, A, B] + ring + +/-- **One-step node averages make a martingale.** A path process `M` adapted to the flips +(`Mₙ` depends only on the first `n` flips) whose node averages close up, +`q Mₙ₊₁(ω, flip n up) + (1 − q) Mₙ₊₁(ω, flip n down) = Mₙ(ω)`, is a Mathlib `Martingale` for +the natural flip filtration under i.i.d. `Bernoulli(q)` flips +(`condExp_flipFiltration_succ`). -/ +theorem martingale_of_oneStep {M : ℕ → (ℕ → Bool) → ℝ} (hM : ∀ n, PathAdaptedAt n (M n)) + (hstep : ∀ n ω, (q : ℝ) * M (n + 1) (Function.update ω n true) + + (1 - q) * M (n + 1) (Function.update ω n false) = M n ω) : + Martingale M flipFiltration (coinFlipMeasure q hq) := + martingale_nat (fun n ↦ stronglyMeasurable_flipFiltration_iff.2 (hM n)) + (fun n ↦ (hM n).integrable hq) fun n ↦ + ((condExp_flipFiltration_succ hq (hM (n + 1))).trans (ae_of_all _ (hstep n))).symm + +/-- **A process adapted to the flips is a martingale exactly when its node averages close up**, +for `0 < q < 1` (every node has positive probability, so the almost-sure identity holds at +every path). The converse of `martingale_of_oneStep`. -/ +theorem oneStep_of_martingale (hq0 : 0 < q) (hq1 : q < 1) {M : ℕ → (ℕ → Bool) → ℝ} + (hM : Martingale M flipFiltration (coinFlipMeasure q hq1.le)) (n : ℕ) (ω : ℕ → Bool) : + (q : ℝ) * M (n + 1) (Function.update ω n true) + + (1 - q) * M (n + 1) (Function.update ω n false) = M n ω := by + have hn1 : PathAdaptedAt (n + 1) (M (n + 1)) := + stronglyMeasurable_flipFiltration_iff.1 (hM.stronglyAdapted (n + 1)) + have hn : PathAdaptedAt n (M n) := stronglyMeasurable_flipFiltration_iff.1 (hM.stronglyAdapted n) + have hae := (condExp_flipFiltration_succ hq1.le hn1).symm.trans + (hM.2 n (n + 1) n.le_succ) + refine PathAdaptedAt.eq_of_ae_eq hq0 hq1 (fun ω ω' h ↦ ?_) hn hae ω + have h1 := hn1.fixFlip true ω ω' h + have h2 := hn1.fixFlip false ω ω' h + simp only at h1 h2 + rw [h1, h2] + +end Martingale + +/-- **The discounted CRR spot is a martingale** under i.i.d. `Bernoulli(crrUpProb)` flips, +for the natural flip filtration: the Mathlib `Martingale` form of `discountedSpot_step`. -/ +theorem martingale_discountedSpot {u d r : ℝ} (h : BinomialNoArb u d r) (S₀ : ℝ) {q : ℝ≥0} + (hq : q ≤ 1) (hqcrr : crrUpProb u d r = q) : + Martingale (discountedSpot S₀ u d r) flipFiltration (coinFlipMeasure q hq) := + martingale_of_oneStep hq (pathAdaptedAt_discountedSpot S₀ u d r) fun n ω ↦ by + simpa [hqcrr] using discountedSpot_step h S₀ n ω + +/-- **The discounted tree price of a European claim is a martingale** under i.i.d. +`Bernoulli(crrUpProb)` flips: the Mathlib `Martingale` form of `discountedTreeValue_step`. -/ +theorem martingale_discountedTreeValue (u d r : ℝ) (g : ℝ → ℝ) (N : ℕ) (S₀ : ℝ) {q : ℝ≥0} + (hq : q ≤ 1) (hqcrr : crrUpProb u d r = q) : + Martingale (discountedTreeValue u d r g N S₀) flipFiltration (coinFlipMeasure q hq) := + martingale_of_oneStep hq (pathAdaptedAt_discountedTreeValue u d r g N S₀) fun n ω ↦ by + simpa [hqcrr] using discountedTreeValue_step u d r g N S₀ n ω + +section Snell + +variable {q : ℝ≥0} (hq : q ≤ 1) {E : Set ℕ} {Z : ℕ → (ℕ → Bool) → ℝ} + +/-- **The pathwise Snell envelope is the Snell envelope, with `j` steps left from time `k`.** For a +payoff process adapted to the flips, `snellAux E q Z j k` agrees almost surely under +`coinFlipMeasure q` with `snellEnvelopeAux` for the flip filtration, whose exercise times are those +`i` with `N - i ∈ E` (`N = k + j` the horizon): the conditional expectation of the recursion is the +node average (`condExp_flipFiltration_succ`). -/ +theorem snellAux_ae_eq_snellEnvelopeAux (hZ : ∀ n, PathAdaptedAt n (Z n)) (N : ℕ) : + ∀ j k, k + j = N → snellAux E (q : ℝ) Z j k =ᵐ[coinFlipMeasure q hq] + snellEnvelopeAux (coinFlipMeasure q hq) flipFiltration {i | N - i ∈ E} Z j k := by + intro j + induction j with + | zero => exact fun k _ ↦ Filter.EventuallyEq.rfl + | succ j ih => + intro k hk + have hnode := condExp_flipFiltration_succ hq + (pathAdaptedAt_snellAux (E := E) (q := (q : ℝ)) hZ j (k + 1)) + have hcongr := condExp_congr_ae (m := flipFiltration k) (ih (k + 1) (by omega)).symm + have hkX : k ∈ {i | N - i ∈ E} ↔ j + 1 ∈ E := by + change N - k ∈ E ↔ _ + rw [show N - k = j + 1 by omega] + by_cases hj : j + 1 ∈ E + · filter_upwards [hnode, hcongr] with ω h1 h2 + rw [snellAux_succ_of_mem hj, snellEnvelopeAux_succ_of_mem (hkX.2 hj)] + beta_reduce + rw [h2, h1] + · filter_upwards [hnode, hcongr] with ω h1 h2 + rw [snellAux_succ_of_notMem hj, snellEnvelopeAux_succ_of_notMem (mt hkX.1 hj), h2, h1] + +/-- **The tree's Snell envelope is an instance of the library's.** For a payoff process adapted to +the flips, `snell E q Z N k` is, almost surely under `coinFlipMeasure q` and for `k ≤ N`, the Snell +envelope `snellEnvelope` of `Z` for the flip filtration with horizon `N`, exercisable at the times +`i` with `N - i ∈ E` (`E` counts the steps still to go). `snell` is its explicit form: the +conditional expectations are node averages, which is what makes the pathwise minimality +`snellAux_le_of_supermartingale_of_ge` hold at every path. -/ +theorem snell_ae_eq_snellEnvelope (hZ : ∀ n, PathAdaptedAt n (Z n)) {N k : ℕ} (hk : k ≤ N) : + snell E (q : ℝ) Z N k =ᵐ[coinFlipMeasure q hq] + snellEnvelope (coinFlipMeasure q hq) flipFiltration {i | N - i ∈ E} Z N k := by + rw [snellEnvelope, min_eq_left hk] + exact snellAux_ae_eq_snellEnvelopeAux hq hZ N (N - k) k (by omega) + +/-- **The tree's Snell envelope is a Mathlib supermartingale.** For a payoff process adapted to the +flips, `k ↦ snell E q Z N (min k N)`, the pathwise envelope frozen at the horizon `N`, is a +`Supermartingale` for `flipFiltration` under `coinFlipMeasure q`: it is almost surely the library's +`snellEnvelope` at every time (`snell_ae_eq_snellEnvelope`), which is one +(`snellEnvelope_supermartingale`), and it is adapted and integrable because it depends only on the +first `k` flips. Past `N` the pathwise `snell` is the payoff again, so the freezing is needed. -/ +theorem supermartingale_snell (hZ : ∀ n, PathAdaptedAt n (Z n)) (N : ℕ) : + Supermartingale (fun k ↦ snell E (q : ℝ) Z N (min k N)) flipFiltration + (coinFlipMeasure q hq) := by + have hZ' : ∀ i, Integrable (Z i) (coinFlipMeasure q hq) := fun i ↦ (hZ i).integrable hq + have key (k : ℕ) : snell E (q : ℝ) Z N (min k N) =ᵐ[coinFlipMeasure q hq] + snellEnvelope (coinFlipMeasure q hq) flipFiltration {i | N - i ∈ E} Z N k := by + rcases le_total k N with hk | hk + · rw [min_eq_left hk] + exact snell_ae_eq_snellEnvelope hq hZ hk + · rw [min_eq_right hk, snellEnvelope_after_horizon hk] + simpa only [snellEnvelope_after_horizon le_rfl] using + snell_ae_eq_snellEnvelope hq (E := E) hZ le_rfl + have hsuper := snellEnvelope_supermartingale (P := coinFlipMeasure q hq) + (𝓕 := flipFiltration) (X := {i | N - i ∈ E}) + (fun n ↦ (stronglyMeasurable_flipFiltration_iff.2 (hZ n)).measurable) hZ' N + refine ⟨fun k ↦ stronglyMeasurable_flipFiltration_iff.2 ?_, fun i j hij ↦ ?_, fun k ↦ ?_⟩ + · exact (pathAdaptedAt_snellAux (E := E) (q := (q : ℝ)) hZ (N - min k N) (min k N)).mono + (min_le_left k N) + · exact (condExp_congr_ae (key j)).trans_le ((hsuper.2.1 i j hij).trans_eq (key i).symm) + · exact (hsuper.integrable k).congr (key k).symm + +/-- **The Bermudan price is the Snell envelope of the discounted payoff.** Under i.i.d. +`Bernoulli(crrUpProb u d r)` flips, the Snell envelope (`snellEnvelope`) of the discounted +payoff `e^{−rn} g(Sₙ)` for the flip filtration, exercisable at the times `i` with `N - i ∈ E`, is +at time `k ≤ N` the discounted `bermudanPrice E` with `N - k` steps to go at the spot `S_k`. -/ +theorem snellEnvelope_discounted_bermudanPrice (u d r : ℝ) (g : ℝ → ℝ) (S₀ : ℝ) + (hqcrr : crrUpProb u d r = q) {N k : ℕ} (hk : k ≤ N) : + snellEnvelope (coinFlipMeasure q hq) flipFiltration {i | N - i ∈ E} + (fun n ω ↦ Real.exp (-r * n) * g (spotPath S₀ u d n ω)) N k + =ᵐ[coinFlipMeasure q hq] fun ω ↦ + Real.exp (-r * k) * bermudanPrice E u d r g (N - k) (spotPath S₀ u d k ω) := by + have hZ (n : ℕ) : PathAdaptedAt n fun ω ↦ Real.exp (-r * n) * g (spotPath S₀ u d n ω) := + fun ω ω' h ↦ by simp only [pathAdaptedAt_spotPath S₀ u d n ω ω' h] + refine (snell_ae_eq_snellEnvelope hq (E := E) hZ hk).symm.trans (ae_of_all _ fun ω ↦ ?_) + rw [snell, ← hqcrr, snellAux_eq_discounted_bermudanPrice] + +end Snell + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/PathReflection.lean b/LeanPool/MathFin/Models/Binomial/PathReflection.lean new file mode 100644 index 0000000000..2e97a9d79c --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/PathReflection.lean @@ -0,0 +1,592 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Order.Ring.Star +public import Mathlib.Algebra.Order.Star.Int +public import Mathlib.Algebra.BigOperators.Group.Finset.Basic +public import Mathlib.Algebra.Order.Ring.Int +public import Mathlib.Data.Finset.Max +public import Mathlib.Order.SuccPred.Nat +public import Mathlib.Tactic.Linarith.Frontend +public import Mathlib.Tactic.Ring.RingNF + +/-! +# Path-level reflection identity for ±1 walks (André 1887, algebraic core) + +For paths `ω : Fin n → Bool` (each entry: `+1` if `true`, `−1` if `false`), +**reflection after time `τ`** is the path that agrees with `ω` strictly +before time `τ` and *negates* every step from time `τ` onwards. + +The algebraic core of André's reflection principle is the position identity + + **For any `τ ≤ k`,** + `walkPos (reflectAfter τ ω) k = 2 · walkPos ω τ − walkPos ω k`. + +Equivalently: the trajectory after time `τ` of the reflected path is the +mirror image of the original trajectory through the horizontal line at +height `walkPos ω τ`. + +Combined with a hitting-time argument (the first `τ` with `walkPos ω τ = a` +when `ω` reaches level `a`), this identity yields the bijection between +*paths that touch level `a` and end at `b ≤ a`* and *paths that end at +`2a − b`*. That bijection is the counting backbone of barrier-option +pricing in the binomial tree. + +This file formalises **both halves**: the algebraic core (the +path-position identity and involution) *and* the hitting-time bijection +itself (`reflectionPrincipleEquiv`, `reflectionPrincipleEquivBelow`), with +the discrete IVT (`HitsLevel_of_walkPos_endpoint_ge`) discharging the +redundant hitting condition on the reflected side. The counting form is +wired to the corpus as `mf-reflection-principle-counting`. + +## Why this is more than algebra + +The identity is non-trivial because reflection *changes* the path at every +position from `τ` onwards. The proof requires splitting each path sum into +a prefix (`< τ`) — preserved by reflection — and a suffix (`τ ≤ · < k`) — +negated step-by-step by reflection. The prefix contributes `walkPos ω τ` +to both sides, and the suffix-sign-flip is what produces the +`2 · walkPos ω τ − walkPos ω k` form. + +## Main definitions + +* `walkStep`, `walkPos`: the step `±1` of a flip and the position of the walk at time `k`, the sum + of the first `k` steps. +* `reflectAfter`: the path that agrees with `ω` before time `τ` and flips every step from `τ` on. +* `hittingSet`, `HitsLevel`: the times `k ≤ n` at which the walk is at level `a`, and the + predicate that this set is nonempty. +* `firstHit`: the first hitting time of level `a` on a path that hits it. +* `reflectAtFirstHit`: reflection after the first hitting time of `a`. +* `reflectionPrincipleEquiv`: the bijection between paths that hit `a` and end at `b`, and paths + that hit `a` and end at `2a − b`, given by `reflectAtFirstHit a`. +* `hitsLevelEquivAbove`: for `0 < a ≤ b`, the paths that hit `a` and end at `b` are in + bijection with the paths that end at `b`. +* `reflectionPrincipleEquivBelow`: for `0 < a` and `b ≤ a`, the paths that hit `a` and end at + `b` are in bijection with the paths that end at `2a − b`. + +## Main results + +* `reflectAfter_involutive`: reflection at fixed `τ` is its own inverse. +* `walkPos_reflectAfter_le`: positions at `k ≤ τ` are unchanged. +* `walkPos_reflectAfter_ge`: positions at `k ≥ τ` reflect through + `walkPos ω τ`. +* `walkPos_reflectAfter_endpoint`: endpoint statement: if the original + hits `a` at `τ` and ends at `b`, the reflected ends at `2a − b`. +* `reflectAtFirstHit_involutive`: reflection at the first hit is its own inverse. +* `HitsLevel_of_walkPos_endpoint_ge`: discrete IVT — a walk ending at or + above a level `a ≥ 0` has hit `a`. + +## References + +* [André (1887)][Andre1887] + +## Tags + +reflection principle, André, random walk, first hitting time, barrier option, ballot problem, +MSC 60G50, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +variable {n : ℕ} + +/-- Step value: `+1` if `true` (up), `−1` if `false` (down). -/ +def walkStep (b : Bool) : ℤ := if b then 1 else -1 + +/-- **Step-value negation under boolean flip**: `walkStep !b = -walkStep b`. -/ +lemma walkStep_not (b : Bool) : walkStep (!b) = -walkStep b := by + unfold walkStep + cases b <;> simp + +/-- Position of the walk at time `k`: sum of the first `k` steps. + +For `k = 0` the sum is empty and the position is `0`. For `k ≥ n` all +steps are included. -/ +def walkPos (ω : Fin n → Bool) (k : ℕ) : ℤ := + ∑ i ∈ (Finset.univ : Finset (Fin n)).filter (fun (i : Fin n) ↦ i.val < k), + walkStep (ω i) + +@[simp] +lemma walkPos_zero (ω : Fin n → Bool) : walkPos ω 0 = 0 := by + unfold walkPos + simp + +/-- **Reflection after time `τ`**: flip every step at index `≥ τ`. -/ +def reflectAfter (τ : ℕ) (ω : Fin n → Bool) : Fin n → Bool := + fun (i : Fin n) ↦ if i.val < τ then ω i else !(ω i) + +/-- **Reflection at fixed `τ` is involutive**: applying it twice recovers the +original path. -/ +lemma reflectAfter_involutive (τ : ℕ) : + Function.Involutive (reflectAfter τ : (Fin n → Bool) → Fin n → Bool) := by + intro ω + funext i + unfold reflectAfter + by_cases h : i.val < τ + · simp [h] + · simp [h] + +/-- **Positions before `τ` are unchanged**: for `k ≤ τ`, the reflected walk's +position equals the original's. (The flip only takes effect from index `τ` +onwards.) -/ +lemma walkPos_reflectAfter_le (τ : ℕ) (ω : Fin n → Bool) {k : ℕ} (hk : k ≤ τ) : + walkPos (reflectAfter τ ω) k = walkPos ω k := by + unfold walkPos + apply Finset.sum_congr rfl + intro i hi + simp only [Finset.mem_filter] at hi + have h_i_lt_τ : i.val < τ := lt_of_lt_of_le hi.2 hk + unfold reflectAfter + rw [ite_eq_left h_i_lt_τ] + +/-- **Position-reflection identity** (the algebraic core of André's principle). + +For any `τ ≤ k`: + + `walkPos (reflectAfter τ ω) k = 2 · walkPos ω τ − walkPos ω k`. + +Proof: decompose each path sum into the prefix `{i.val < τ}` (preserved by +reflection, contributing `walkPos ω τ`) and the suffix `{τ ≤ i.val < k}` +(negated step-by-step by reflection). Combining + + `walkPos (reflect) k = (prefix) − (suffix of ω)` + `walkPos ω k = (prefix) + (suffix of ω)` + `walkPos ω τ = (prefix)` + +gives `walkPos (reflect) k = 2·walkPos ω τ − walkPos ω k`. -/ +lemma walkPos_reflectAfter_ge (τ : ℕ) (ω : Fin n → Bool) {k : ℕ} (hτk : τ ≤ k) : + walkPos (reflectAfter τ ω) k = 2 * walkPos ω τ - walkPos ω k := by + let Pτ : Finset (Fin n) := Finset.univ.filter (fun (i : Fin n) ↦ i.val < τ) + let Pτk : Finset (Fin n) := + Finset.univ.filter (fun (i : Fin n) ↦ τ ≤ i.val ∧ i.val < k) + let Pk : Finset (Fin n) := Finset.univ.filter (fun (i : Fin n) ↦ i.val < k) + have h_disj : Disjoint Pτ Pτk := by + rw [Finset.disjoint_filter] + intros i _ hi1 hi2 + exact absurd hi1 (not_lt.mpr hi2.1) + have h_union : Pk = Pτ ∪ Pτk := by + ext i + simp only [Pk, Pτ, Pτk, Finset.mem_filter, Finset.mem_union] + constructor + · rintro ⟨_, h_ik⟩ + by_cases h_iτ : i.val < τ + · exact Or.inl ⟨Finset.mem_univ _, h_iτ⟩ + · exact Or.inr ⟨Finset.mem_univ _, not_lt.mp h_iτ, h_ik⟩ + · rintro (⟨_, h1⟩ | ⟨_, h2, h3⟩) + · exact ⟨Finset.mem_univ _, lt_of_lt_of_le h1 hτk⟩ + · exact ⟨Finset.mem_univ _, h3⟩ + have h_split_σ : walkPos (reflectAfter τ ω) k = + (∑ i ∈ Pτ, walkStep (reflectAfter τ ω i)) + + (∑ i ∈ Pτk, walkStep (reflectAfter τ ω i)) := by + unfold walkPos + change ∑ i ∈ Pk, walkStep (reflectAfter τ ω i) = _ + rw [h_union, Finset.sum_union h_disj] + have h_split_ω : walkPos ω k = + (∑ i ∈ Pτ, walkStep (ω i)) + (∑ i ∈ Pτk, walkStep (ω i)) := by + unfold walkPos + change ∑ i ∈ Pk, walkStep (ω i) = _ + rw [h_union, Finset.sum_union h_disj] + have h_τ_eq : walkPos ω τ = ∑ i ∈ Pτ, walkStep (ω i) := rfl + have h_prefix : + (∑ i ∈ Pτ, walkStep (reflectAfter τ ω i)) = ∑ i ∈ Pτ, walkStep (ω i) := by + apply Finset.sum_congr rfl + intro i hi + simp only [Pτ, Finset.mem_filter] at hi + unfold reflectAfter + rw [ite_eq_left hi.2] + have h_suffix : + (∑ i ∈ Pτk, walkStep (reflectAfter τ ω i)) = -∑ i ∈ Pτk, walkStep (ω i) := by + rw [← Finset.sum_neg_distrib] + apply Finset.sum_congr rfl + intro i hi + simp only [Pτk, Finset.mem_filter] at hi + unfold reflectAfter + rw [ite_eq_right (not_lt.mpr hi.2.1), walkStep_not] + rw [h_split_σ, h_prefix, h_suffix, h_split_ω, h_τ_eq] + ring + +/-- **Endpoint statement of the reflection identity**: if `ω` hits level `a` at +time `τ` (`walkPos ω τ = a`) and ends at `b` (`walkPos ω n = b`), then the +reflected path ends at `2a − b`. + +This statement drives the counting argument in barrier-option pricing: a +path-to-`b`-touching-`a` and a path-to-`(2a−b)` are in bijection via +reflection at the first hitting time of `a`. -/ +theorem walkPos_reflectAfter_endpoint (τ : ℕ) (ω : Fin n → Bool) (hτ : τ ≤ n) + (a b : ℤ) (h_hit : walkPos ω τ = a) (h_end : walkPos ω n = b) : + walkPos (reflectAfter τ ω) n = 2 * a - b := by + rw [walkPos_reflectAfter_ge τ ω hτ, h_hit, h_end] + +/-! ## Hitting time and the counting bijection + +The reflection identity above is the algebraic spine. To turn it into a +counting statement we choose a canonical `τ` — the **first time** the walk +hits a given level `a` — and reflect there. The bijection is then between +paths that hit `a` and end at one level and paths that hit `a` and end at +its mirror image. + +The construction: + +1. `hittingSet ω a`: the (finite) set of times `k ∈ {0,…,n}` with + `walkPos ω k = a`. +2. `HitsLevel`: the predicate that `hittingSet` is nonempty. +3. `firstHit ω a h`: the smallest hit time on a hit-path. +4. `reflectAtFirstHit a`: the partial map `ω ↦ reflectAfter (firstHit ω a h) ω` + (defaulting to identity when `ω` doesn't hit `a`). +5. **Key invariance**: `firstHit (reflectAtFirstHit ω) a = firstHit ω a`, + because reflection preserves positions on `[0, τ]`, hence both hits at τ + (and doesn't hit earlier). +6. **Involution**: applying reflection twice at the same `τ` is identity, + so `reflectAtFirstHit` is an involution on `{ω : HitsLevel ω a}`. +7. **Endpoint flip**: combining with `walkPos_reflectAfter_endpoint`, + reflection maps `{ω : hits a, ends at b}` to + `{ω : hits a, ends at 2a − b}` bijectively. +-/ + +variable {a : ℤ} + +/-- The (finite) set of times `k ∈ {0, …, n}` at which the walk hits level `a`. -/ +def hittingSet (ω : Fin n → Bool) (a : ℤ) : Finset ℕ := + (Finset.range (n + 1)).filter (fun k ↦ walkPos ω k = a) + +/-- A path **hits level `a`** if `hittingSet` is nonempty. -/ +abbrev HitsLevel (a : ℤ) (ω : Fin n → Bool) : Prop := (hittingSet ω a).Nonempty + +/-- First hitting time of level `a` on a hit-path. -/ +noncomputable def firstHit (ω : Fin n → Bool) (a : ℤ) (h : HitsLevel a ω) : ℕ := + (hittingSet ω a).min' h + +lemma firstHit_mem_hittingSet (ω : Fin n → Bool) (a : ℤ) (h : HitsLevel a ω) : + firstHit ω a h ∈ hittingSet ω a := + (hittingSet ω a).min'_mem h + +lemma firstHit_le (ω : Fin n → Bool) (a : ℤ) (h : HitsLevel a ω) : + firstHit ω a h ≤ n := by + have h_lt : firstHit ω a h < n + 1 := + Finset.mem_range.mp (Finset.mem_filter.mp (firstHit_mem_hittingSet ω a h)).1 + omega + +lemma walkPos_firstHit (ω : Fin n → Bool) (a : ℤ) (h : HitsLevel a ω) : + walkPos ω (firstHit ω a h) = a := + (Finset.mem_filter.mp (firstHit_mem_hittingSet ω a h)).2 + +/-- **Minimality of the first hit**: any `k ≤ n` with `walkPos ω k = a` is at +least `firstHit ω a`. -/ +lemma firstHit_le_of_hit (ω : Fin n → Bool) (a : ℤ) (h : HitsLevel a ω) + {k : ℕ} (hk : k ≤ n) (h_eq : walkPos ω k = a) : firstHit ω a h ≤ k := by + apply Finset.min'_le + rw [hittingSet, Finset.mem_filter, Finset.mem_range] + exact ⟨by omega, h_eq⟩ + +/-- **Reflected path hits level `a`** when the original does. The reflected +hits at the same `firstHit` time (proven separately below). -/ +lemma HitsLevel.reflectAfter_firstHit (ω : Fin n → Bool) (a : ℤ) (h : HitsLevel a ω) : + HitsLevel a (reflectAfter (firstHit ω a h) ω) := by + refine ⟨firstHit ω a h, ?_⟩ + unfold hittingSet + rw [Finset.mem_filter, Finset.mem_range] + refine ⟨by have := firstHit_le ω a h; omega, ?_⟩ + rw [walkPos_reflectAfter_le _ _ (le_refl _)] + exact walkPos_firstHit ω a h + +/-- **First hit is invariant under reflection at the first hit time.** Crucial +for the involution property of `reflectAtFirstHit`. + +Proof: both bounds. +* `firstHit σ a ≤ τ` because `σ` hits `a` at `τ` (positions agree up to `τ`). +* `firstHit σ a ≥ τ` because positions on `[0, τ)` agree with `ω`, where `ω` + doesn't hit `a` (minimality of `τ`). -/ +theorem firstHit_reflectAfter_firstHit (ω : Fin n → Bool) (a : ℤ) (h : HitsLevel a ω) : + firstHit (reflectAfter (firstHit ω a h) ω) a + (HitsLevel.reflectAfter_firstHit ω a h) = firstHit ω a h := by + let hσ := HitsLevel.reflectAfter_firstHit ω a h + apply le_antisymm + · -- τσ ≤ τ: σ hits a at τ (positions agree up to τ). + apply firstHit_le_of_hit _ a hσ (firstHit_le ω a h) + rw [walkPos_reflectAfter_le _ _ (le_refl _)] + exact walkPos_firstHit ω a h + · -- τ ≤ τσ: if τσ < τ, positions agree there with ω; ω doesn't hit a before τ. + by_contra h_ge_not + have h_lt : firstHit (reflectAfter (firstHit ω a h) ω) a hσ < firstHit ω a h := + not_le.mp h_ge_not + have h_τσ_le_n : firstHit (reflectAfter (firstHit ω a h) ω) a hσ ≤ n := + firstHit_le _ _ _ + have h_walkPos_σ : + walkPos (reflectAfter (firstHit ω a h) ω) + (firstHit (reflectAfter (firstHit ω a h) ω) a hσ) = a := + walkPos_firstHit _ _ _ + have h_walkPos_ω : + walkPos ω (firstHit (reflectAfter (firstHit ω a h) ω) a hσ) = a := by + rw [← walkPos_reflectAfter_le (firstHit ω a h) ω (le_of_lt h_lt)] + exact h_walkPos_σ + have h_ge : firstHit ω a h ≤ firstHit (reflectAfter (firstHit ω a h) ω) a hσ := + firstHit_le_of_hit ω a h h_τσ_le_n h_walkPos_ω + exact absurd h_ge (not_le.mpr h_lt) + +/-- **Reflection at the first hitting time of `a`**: the path-level map that +reflects every step after `firstHit ω a`. Defaulted to identity off the +hit-set. -/ +noncomputable def reflectAtFirstHit (a : ℤ) (ω : Fin n → Bool) : Fin n → Bool := + if h : HitsLevel a ω then reflectAfter (firstHit ω a h) ω else ω + +/-- **Involution**: reflecting twice at the (preserved) first hit recovers +the original path. + +Proof: on the hit-set, `firstHit` is invariant under reflection +(`firstHit_reflectAfter_firstHit`), and `reflectAfter τ` is involutive +(`reflectAfter_involutive`). Off the hit-set, the map is identity. -/ +theorem reflectAtFirstHit_involutive (a : ℤ) : + Function.Involutive (reflectAtFirstHit (n := n) a) := by + intro ω + by_cases h1 : HitsLevel a ω + · -- ω hits a. + have h2 : HitsLevel a (reflectAfter (firstHit ω a h1) ω) := + HitsLevel.reflectAfter_firstHit ω a h1 + have h_τ_eq : firstHit (reflectAfter (firstHit ω a h1) ω) a h2 = firstHit ω a h1 := + firstHit_reflectAfter_firstHit ω a h1 + change reflectAtFirstHit a (reflectAtFirstHit a ω) = ω + unfold reflectAtFirstHit + rw [dite_eq_left h1] + rw [dite_eq_left h2] + rw [h_τ_eq] + exact reflectAfter_involutive (firstHit ω a h1) ω + · -- ω doesn't hit a; reflectAtFirstHit acts as identity. + show reflectAtFirstHit a (reflectAtFirstHit a ω) = ω + unfold reflectAtFirstHit + rw [dite_eq_right h1, dite_eq_right h1] + +/-- **Endpoint flip under reflection at first hit**: if `ω` hits `a` and ends +at `b`, then `reflectAtFirstHit a ω` ends at `2a − b`. -/ +theorem walkPos_reflectAtFirstHit_endpoint (ω : Fin n → Bool) (a b : ℤ) + (h : HitsLevel a ω) (h_end : walkPos ω n = b) : + walkPos (reflectAtFirstHit a ω) n = 2 * a - b := by + unfold reflectAtFirstHit + rw [dite_eq_left h] + exact walkPos_reflectAfter_endpoint (firstHit ω a h) ω (firstHit_le ω a h) + a b (walkPos_firstHit ω a h) h_end + +/-! ## Discrete intermediate value theorem and the maximal distribution + +The reflection principle's *counting* statement, in its cleanest form, drops +the `HitsLevel` hypothesis on one side: any path that *ends* above level `a` +automatically *hits* level `a`. This is the discrete intermediate value +theorem for ±1 walks. Combined with the bijection above, it gives the +classical maximal-distribution counting identity + + `|{ω : HitsLevel a ω}| = 2 · |{ω : a ≤ walkPos ω n}| − |{ω : walkPos ω n = a}|` + +for `a ≥ 0`. The bijection above together with the discrete intermediate value +theorem *reduces* this maximal-distribution identity to the endpoint +distribution — the mechanism behind barrier-option pricing. This file delivers +that bijection (`reflectionPrincipleEquiv`) and the IVT direction +(`walkPos_reflectAfter_endpoint`); the `Fintype.card` identity is their +immediate corollary and is not separately stated here. +-/ + +/-- **Step relation**: the walk's position at time `k + 1` equals the position +at `k` plus the step value at index `k`. -/ +lemma walkPos_succ (ω : Fin n → Bool) {k : ℕ} (hk : k < n) : + walkPos ω (k + 1) = walkPos ω k + walkStep (ω ⟨k, hk⟩) := by + unfold walkPos + have h_split : + (Finset.univ.filter (fun (i : Fin n) ↦ i.val < k + 1)) = + (Finset.univ.filter (fun (i : Fin n) ↦ i.val < k)) ∪ {⟨k, hk⟩} := by + ext i + simp only [Finset.mem_filter, Finset.mem_univ, Finset.mem_union, + Finset.mem_singleton, true_and] + constructor + · intro h_lt_succ + by_cases h_eq : i.val = k + · exact Or.inr (Fin.ext h_eq) + · exact Or.inl (by omega) + · rintro (h_lt | h_eq) + · omega + · simp [h_eq] + have h_disj : Disjoint + (Finset.univ.filter (fun (i : Fin n) ↦ i.val < k)) + ({⟨k, hk⟩} : Finset (Fin n)) := by + rw [Finset.disjoint_singleton_right, Finset.mem_filter] + intro h + exact Nat.lt_irrefl k h.2 + rw [h_split, Finset.sum_union h_disj, Finset.sum_singleton] + +/-- **Discrete intermediate value theorem for ±1 walks**: if the walk +ends at or above level `a ≥ 0`, it hits level `a` at some time `k ≤ n`. + +Proof: take `τ` = smallest `k ≤ n` with `walkPos ω k ≥ a`. Either `τ = 0` +(so `walkPos ω 0 = 0 ≥ a ≥ 0`, hence `a = 0` and we hit at 0), or `τ > 0` +with `walkPos ω (τ−1) < a` (minimality) and `walkPos ω τ ≥ a`. Since each +step is `±1`, `walkPos τ = walkPos (τ−1) ± 1`; the `-1` case would give +`walkPos τ < a`, contradicting `≥ a`; the `+1` case gives +`walkPos τ = walkPos (τ−1) + 1 ≤ a`, combined with `≥ a` gives `= a`. -/ +theorem HitsLevel_of_walkPos_endpoint_ge (ω : Fin n → Bool) (a : ℤ) + (ha : 0 ≤ a) (h_end : a ≤ walkPos ω n) : HitsLevel a ω := by + -- Use Finset.min' on the set of k ≤ n with walkPos ω k ≥ a. + let S : Finset ℕ := + (Finset.range (n + 1)).filter (fun k ↦ a ≤ walkPos ω k) + have h_n_mem : n ∈ S := by + show n ∈ S + rw [show S = _ from rfl, Finset.mem_filter, Finset.mem_range] + exact ⟨Nat.lt_succ_self n, h_end⟩ + have hS_nonempty : S.Nonempty := ⟨n, h_n_mem⟩ + let τ := S.min' hS_nonempty + have h_τ_mem_filter : + τ ∈ (Finset.range (n + 1)).filter (fun k ↦ a ≤ walkPos ω k) := + S.min'_mem hS_nonempty + have h_τ_lt : τ < n + 1 := + Finset.mem_range.mp (Finset.mem_filter.mp h_τ_mem_filter).1 + have h_τ_le_n : τ ≤ n := by omega + have h_τ_ge : a ≤ walkPos ω τ := (Finset.mem_filter.mp h_τ_mem_filter).2 + have h_min : ∀ k < τ, ¬ (a ≤ walkPos ω k) := by + intro k hk h_ge + have h_k_in : k ∈ S := by + show k ∈ S + rw [show S = _ from rfl, Finset.mem_filter, Finset.mem_range] + exact ⟨by omega, h_ge⟩ + have : τ ≤ k := S.min'_le k h_k_in + omega + -- Show walkPos ω τ = a. + have h_eq : walkPos ω τ = a := by + rcases Nat.eq_zero_or_pos τ with hτ_zero | hτ_pos + · have h_walkPos_zero : walkPos ω τ = 0 := by rw [hτ_zero]; exact walkPos_zero ω + rw [h_walkPos_zero] at h_τ_ge + rw [h_walkPos_zero] + omega + · obtain ⟨m, h_eq_m⟩ := Nat.exists_eq_succ_of_ne_zero hτ_pos.ne' + have h_m_lt_n : m < n := by rw [h_eq_m] at h_τ_le_n; omega + have h_walkPos_m_lt : walkPos ω m < a := by + by_contra h_ge + have h_ge' : a ≤ walkPos ω m := not_lt.mp h_ge + have h_m_lt_τ : m < τ := by rw [h_eq_m]; omega + exact h_min m h_m_lt_τ h_ge' + have h_succ := walkPos_succ ω h_m_lt_n + have h_walkPos_τ_eq : walkPos ω τ = walkPos ω (m + 1) := by rw [h_eq_m] + rw [h_walkPos_τ_eq] at h_τ_ge + rw [h_walkPos_τ_eq] + have h_step_or : walkStep (ω ⟨m, h_m_lt_n⟩) = 1 ∨ + walkStep (ω ⟨m, h_m_lt_n⟩) = -1 := by + unfold walkStep + by_cases hb : ω ⟨m, h_m_lt_n⟩ + · left; simp [hb] + · right; simp [hb] + rcases h_step_or with h_up | h_down + · rw [h_up] at h_succ; omega + · rw [h_down] at h_succ; omega + refine ⟨τ, ?_⟩ + rw [hittingSet, Finset.mem_filter, Finset.mem_range] + exact ⟨by omega, h_eq⟩ + +/-- **Endpoint-above-barrier ⟹ hits barrier** (alias / corollary). +Same as `HitsLevel_of_walkPos_endpoint_ge`, stated as a one-line use. -/ +lemma HitsLevel_of_endpoint_gt {ω : Fin n → Bool} {a : ℤ} (ha : 0 ≤ a) + (h : a < walkPos ω n) : HitsLevel a ω := + HitsLevel_of_walkPos_endpoint_ge ω a ha (le_of_lt h) + +/-- **The reflection-principle bijection** (André 1887, counting form). + +For any `a, b : ℤ`, the set of paths that hit level `a` and end at `b` is in +bijection with the set of paths that hit level `a` and end at `2a − b`, +via `reflectAtFirstHit a`. + +The bijection is an involution (when applied twice, recovers the original +path). -/ +noncomputable def reflectionPrincipleEquiv (a b : ℤ) : + {ω : Fin n → Bool // HitsLevel a ω ∧ walkPos ω n = b} ≃ + {ω : Fin n → Bool // HitsLevel a ω ∧ walkPos ω n = 2 * a - b} where + toFun ω := + ⟨reflectAtFirstHit a ω.val, + by + constructor + · -- Reflected hits a. + unfold reflectAtFirstHit + rw [dite_eq_left ω.property.1] + exact HitsLevel.reflectAfter_firstHit ω.val a ω.property.1 + · exact walkPos_reflectAtFirstHit_endpoint ω.val a b ω.property.1 ω.property.2⟩ + invFun ω := + ⟨reflectAtFirstHit a ω.val, + by + constructor + · unfold reflectAtFirstHit + rw [dite_eq_left ω.property.1] + exact HitsLevel.reflectAfter_firstHit ω.val a ω.property.1 + · -- Reflected ends at 2a - (2a - b) = b. + have h := walkPos_reflectAtFirstHit_endpoint ω.val a (2 * a - b) + ω.property.1 ω.property.2 + linarith⟩ + left_inv ω := Subtype.ext (reflectAtFirstHit_involutive a ω.val) + right_inv ω := Subtype.ext (reflectAtFirstHit_involutive a ω.val) + +/-- **Endpoint-above-`a` implies `HitsLevel`** — packaged as an `Equiv` +between `{ω : hits a, ends at b}` and `{ω : ends at b}` for `b ≥ a > 0`. + +By the IVT, `walkPos ω n = b ≥ a > 0` automatically implies `HitsLevel a ω`, +so the `HitsLevel` condition is redundant. -/ +noncomputable def hitsLevelEquivAbove (a b : ℤ) (ha : 0 < a) (hb : a ≤ b) : + {ω : Fin n → Bool // HitsLevel a ω ∧ walkPos ω n = b} ≃ + {ω : Fin n → Bool // walkPos ω n = b} where + toFun ω := ⟨ω.val, ω.property.2⟩ + invFun ω := + ⟨ω.val, + HitsLevel_of_walkPos_endpoint_ge ω.val a (le_of_lt ha) + (by rw [ω.property]; exact hb), + ω.property⟩ + left_inv _ := rfl + right_inv _ := rfl + +/-- **Reflection bijection (below-the-barrier form)** — clean counting Equiv +between paths-touching-`a`-ending-at-`b` (with `b ≤ a`) and paths-ending- +at-`(2a − b)` (no hitting condition on the right, by IVT, since `2a − b ≥ a`). + +This is the form actually used in barrier-option pricing: the LHS is "paths +that touch the barrier and end at `b`," the RHS is the simple endpoint +distribution at `2a − b`. -/ +noncomputable def reflectionPrincipleEquivBelow + (a b : ℤ) (ha : 0 < a) (hb : b ≤ a) : + {ω : Fin n → Bool // HitsLevel a ω ∧ walkPos ω n = b} ≃ + {ω : Fin n → Bool // walkPos ω n = 2 * a - b} := + (reflectionPrincipleEquiv (n := n) a b).trans + (hitsLevelEquivAbove a (2 * a - b) ha (by linarith)) + +/-! ## `firstHit?` (Option-returning) for ergonomic downstream use + +The `firstHit` function requires a `HitsLevel a ω` proof as input. For +downstream barrier-option code that doesn't have the hit hypothesis upfront +(e.g. computing over all paths and discriminating by hit/no-hit at runtime), +the `Option`-returning variant is cleaner. -/ + +/-- **First hitting time (Option-returning)**: `some τ` if the path hits +level `a` (with `τ` the first hit time), else `none`. -/ +noncomputable def firstHit? (ω : Fin n → Bool) (a : ℤ) : Option ℕ := + if h : HitsLevel a ω then some (firstHit ω a h) else none + +lemma firstHit?_eq_some_of_hitsLevel (ω : Fin n → Bool) (a : ℤ) + (h : HitsLevel a ω) : firstHit? ω a = some (firstHit ω a h) := by + unfold firstHit?; rw [dite_eq_left h] + +lemma firstHit?_eq_none_iff_not_hitsLevel (ω : Fin n → Bool) (a : ℤ) : + firstHit? ω a = none ↔ ¬ HitsLevel a ω := by + refine ⟨fun h h_hit ↦ ?_, fun h_not_hit ↦ ?_⟩ + · unfold firstHit? at h + rw [dite_eq_left h_hit] at h + exact Option.some_ne_none _ h + · unfold firstHit?; exact dite_eq_right h_not_hit + +lemma firstHit?_isSome_iff (ω : Fin n → Bool) (a : ℤ) : + (firstHit? ω a).isSome ↔ HitsLevel a ω := by + refine ⟨fun h ↦ ?_, fun h_hit ↦ ?_⟩ + · by_contra h_not_hit + unfold firstHit? at h + rw [dite_eq_right h_not_hit] at h + exact Bool.false_ne_true h + · unfold firstHit?; rw [dite_eq_left h_hit]; rfl + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/ReplicatingUniqueness.lean b/LeanPool/MathFin/Models/Binomial/ReplicatingUniqueness.lean new file mode 100644 index 0000000000..b561c38536 --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/ReplicatingUniqueness.lean @@ -0,0 +1,101 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.Model +public import Mathlib.Analysis.Normed.Field.Basic + +/-! +# Uniqueness of the binomial replicating portfolio, and the law of one price + +`Models.Binomial.Model` exhibits a single-period replicating portfolio + + `Δ = (V_u − V_d) / (S₀ · (u − d))`, `B = e^{−r} · (u · V_d − d · V_u) / (u − d)`, + +which pays `V_u` in the up-state and `V_d` in the down-state (`replicating_payoff_up`, +`replicating_payoff_down`) and costs the risk-neutral price +`binomialOptionPriceOnePeriod u d r V_u V_d` (`replicating_portfolio_cost`). This file proves +that it is the only one: under no-arbitrage (`d < e^r < u`, so `u ≠ d`) and `S₀ > 0`, the +linear system + + `Δ · (S₀ · u) + B · e^r = V_u`, `Δ · (S₀ · d) + B · e^r = V_d` + +has exactly one solution, its determinant being `S₀ · (u − d) · e^r ≠ 0`. Consequently every +portfolio that replicates the claim costs the risk-neutral price: the law of one price in the +one-period binomial market. + +Scope: one period, two states. The multi-period tree and the equivalence between uniqueness +of the martingale measure and completeness are not stated here (`Models.Binomial.SecondFTAP` proves +the one-period uniqueness of `q`; `Models.Binomial.BinomialFromFTAP` identifies the price with the +FTAP pricing kernel). + +## Main results + +* `binomial_replicatingPortfolio_unique`: the replicating portfolio `(Δ, B)` is uniquely + determined by the target payoffs `(V_u, V_d)`. +* `binomial_replication_cost_eq_price`: any portfolio replicating `(V_u, V_d)` costs + `binomialOptionPriceOnePeriod u d r V_u V_d`. + +## Tags + +replicating portfolio, law of one price, delta and bond, no arbitrage, one-period binomial, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +/-- **Uniqueness of the single-period binomial replicating portfolio**. + +Under no-arbitrage (`d < e^r < u`, hence `u > d`) with positive spot `S₀ > 0`, the linear system + + `Δ · (S₀ · u) + B · e^r = V_u`, + `Δ · (S₀ · d) + B · e^r = V_d` + +has a unique solution `(Δ, B)`: the portfolio of `Models.Binomial.Model`, +`Δ = (V_u − V_d) / (S₀ · (u − d))`, `B = e^{−r} · (u · V_d − d · V_u) / (u − d)`. +Subtracting the equations gives `Δ · S₀ · (u − d) = V_u − V_d`, and `u · (down) − d · (up)` +gives `B · e^r · (u − d) = u · V_d − d · V_u`. -/ +theorem binomial_replicatingPortfolio_unique + {S₀ u d r V_u V_d : ℝ} (hS₀ : 0 < S₀) (h : BinomialNoArb u d r) : + ∃! p : ℝ × ℝ, + p.1 * (S₀ * u) + p.2 * Real.exp r = V_u ∧ + p.1 * (S₀ * d) + p.2 * Real.exp r = V_d := by + refine ⟨((V_u - V_d) / (S₀ * (u - d)), Real.exp (-r) * (u * V_d - d * V_u) / (u - d)), + ⟨replicating_payoff_up hS₀ h, replicating_payoff_down hS₀ h⟩, ?_⟩ + rintro ⟨Δ, B⟩ hp + obtain ⟨h_up, h_down⟩ : Δ * (S₀ * u) + B * Real.exp r = V_u ∧ + Δ * (S₀ * d) + B * Real.exp r = V_d := hp + have hud : u - d ≠ 0 := (sub_pos.mpr h.d_lt_u).ne' + have hexp : Real.exp (-r) * Real.exp r = 1 := by + rw [← Real.exp_add, neg_add_cancel, Real.exp_zero] + refine Prod.ext ?_ ?_ + · change Δ = (V_u - V_d) / (S₀ * (u - d)) + rw [eq_div_iff (mul_ne_zero hS₀.ne' hud)] + linear_combination h_up - h_down + · change B = Real.exp (-r) * (u * V_d - d * V_u) / (u - d) + rw [eq_div_iff hud] + linear_combination Real.exp (-r) * (u * h_down - d * h_up) - B * (u - d) * hexp + +/-- **Law of one price in the one-period binomial market.** Under no-arbitrage and `S₀ > 0`, +every portfolio `(Δ, B)` that pays `V_u` in the up-state and `V_d` in the down-state costs +`Δ · S₀ + B = e^{−r} · (q · V_u + (1 − q) · V_d)`, the risk-neutral price. By uniqueness +(`binomial_replicatingPortfolio_unique`) it is the portfolio of `Models.Binomial.Model`, whose cost +is `replicating_portfolio_cost`. -/ +theorem binomial_replication_cost_eq_price {S₀ u d r V_u V_d Δ B : ℝ} (hS₀ : 0 < S₀) + (h : BinomialNoArb u d r) (h_up : Δ * (S₀ * u) + B * Real.exp r = V_u) + (h_down : Δ * (S₀ * d) + B * Real.exp r = V_d) : + Δ * S₀ + B = binomialOptionPriceOnePeriod u d r V_u V_d := by + obtain ⟨p, -, hp⟩ := binomial_replicatingPortfolio_unique (V_u := V_u) (V_d := V_d) hS₀ h + obtain ⟨rfl, rfl⟩ := Prod.mk.inj <| (hp (Δ, B) ⟨h_up, h_down⟩).trans + (hp ((V_u - V_d) / (S₀ * (u - d)), Real.exp (-r) * (u * V_d - d * V_u) / (u - d)) + ⟨replicating_payoff_up hS₀ h, replicating_payoff_down hS₀ h⟩).symm + exact replicating_portfolio_cost hS₀ h + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/SecondFTAP.lean b/LeanPool/MathFin/Models/Binomial/SecondFTAP.lean new file mode 100644 index 0000000000..f020cce8ca --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/SecondFTAP.lean @@ -0,0 +1,76 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.Model + +/-! +# Second Fundamental Theorem of Asset Pricing (single-period binomial form) + +The First FTAP (existence of an equivalent martingale measure ↔ no-arbitrage) +has a corresponding **Second FTAP**: the EMM is *unique* if and only if the +market is *complete*. + +In the single-period binomial model the second FTAP collapses to a clean +algebraic fact: + +* **Completeness is automatic**: every contingent claim `(V_u, V_d)` is + replicated by an explicit Δ/B portfolio (`replicating_portfolio_cost` in + `Models.Binomial.Model`). +* **Uniqueness of the EMM**: the martingale condition `q·u + (1−q)·d = e^r` + is a single linear equation in `q`, uniquely solvable when `u ≠ d`. Under + no-arbitrage (`d < e^r < u`), the unique solution is the risk-neutral + up-probability `crrUpProb u d r = (e^r − d) / (u − d)`. + +So in the single-period binomial, no-arbitrage gives a unique EMM (`second_FTAP_single_period`) +and every claim is replicated (`replicating_portfolio_cost`). + +## Main results + +* `second_FTAP_single_period`: under `BinomialNoArb u d r`, the risk-neutral + up-probability `q` is uniquely determined. + +## References + +* [J. M. Harrison and S. R. Pliska, *Martingales and stochastic integrals in the theory of + continuous trading*][HarrisonPliska1981] + +## Tags + +second fundamental theorem, market completeness, unique martingale measure, +risk-neutral probability, replication, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- **Second FTAP (single-period binomial form)**: under no-arbitrage +(`d < e^r < u`), the risk-neutral measure is uniquely characterised by the +martingale condition `q · u + (1 − q) · d = e^r`. The unique solution is +`crrUpProb u d r = (e^r − d) / (u − d)`. -/ +theorem second_FTAP_single_period {u d r : ℝ} (h : BinomialNoArb u d r) : + ∃! q : ℝ, q * u + (1 - q) * d = Real.exp r := by + have h_ud : 0 < u - d := sub_pos.mpr h.d_lt_u + have h_ud_ne : u - d ≠ 0 := h_ud.ne' + refine ⟨crrUpProb u d r, ?_, ?_⟩ + · -- Existence: `crrUpProb` solves the equation. + unfold crrUpProb + field_simp + ring + · -- Uniqueness: any solution must equal `crrUpProb`. + intro q hq + -- `hq : q · u + (1−q) · d = e^r` ↔ `q · (u − d) = e^r − d` ↔ `q = (e^r − d)/(u − d)`. + have h_solve : q * (u - d) = Real.exp r - d := by linarith + unfold crrUpProb + rw [eq_div_iff h_ud_ne] + exact h_solve + +end MathFin diff --git a/LeanPool/MathFin/Models/Binomial/SnellEnvelope.lean b/LeanPool/MathFin/Models/Binomial/SnellEnvelope.lean new file mode 100644 index 0000000000..5cbd6e6491 --- /dev/null +++ b/LeanPool/MathFin/Models/Binomial/SnellEnvelope.lean @@ -0,0 +1,453 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Binomial.Model +public import LeanPool.MathFin.Models.Binomial.FlipPaths +public meta import Lean.Meta.Tactic.NormCast + +/-! +# Snell envelope characterization of `bermudanPrice` — scalar and path-space + +In the discrete-time binomial tree, the price with early exercise on a step set `E` +(`bermudanPrice E`; `E = univ` is the American price) is the **Snell envelope** of the +payoff `g`: the *smallest* process satisfying intrinsic dominance at the exercise dates and +the one-step supermartingale property. This file proves the characterization at **two +levels**. + +**Scalar (Markov) level.** The smallest function `V : ℕ → ℝ → ℝ` with + +1. **Intrinsic dominance**: `V n S ≥ g S` at maturity and at every exercise date `n ∈ E`; +2. **One-step supermartingale**: `V (n+1) S ≥ e^{-r}·(q·V n (uS) + (1−q)·V n (dS))` + +is `bermudanPrice E` (`bermudanPrice_is_snell_envelope`, with minimality from +`bermudanPrice_le_of_supermartingale_dominating`, which is derived below from the path-space +minimality). + +**Path-space level.** On coin-flip paths `ω : ℕ → Bool` — the same pathwise +language as `Models/Binomial/FlipPaths.lean`, where the conditional +expectation w.r.t. the binomial filtration is the explicit node average +`E[X_{k+1} | ℱ_k](ω) = q·X_{k+1}(up child) + (1−q)·X_{k+1}(down child)` — +the envelope `snellAux E q Z j k` of a payoff *process* `Z` is defined by the +backward Bellman recursion (the max with the payoff taken exactly when the number of +steps to go lies in the exercise set `E`), and the four clauses of the Snell theorem are +each proved: payoff dominance (`snellAux_ge_payoff`), the supermartingale +property (`snellAux_supermartingale`), adaptedness — the filtration content +(`pathAdaptedAt_snellAux`) — and **minimality over arbitrary path-processes** +(`snellAux_le_of_supermartingale_of_ge`), a strictly larger competitor class +than the scalar form's Markov candidates. + +The **identification theorem** (`snellAux_eq_discounted_bermudanPrice`) +closes the loop: for the discounted intrinsic payoff +`Z_k(ω) = e^{−rk}·g(S_k(ω))` along the spot path +`S_k(ω) = S₀·∏_{i Z k ω + | j + 1, k, ω => + if (j + 1) ∈ E then + max (Z k ω) + (q * snellAux E q Z j (k + 1) (Function.update ω k true) + + (1 - q) * snellAux E q Z j (k + 1) (Function.update ω k false)) + else + q * snellAux E q Z j (k + 1) (Function.update ω k true) + + (1 - q) * snellAux E q Z j (k + 1) (Function.update ω k false) + +/-- The **Snell envelope** of the payoff process `Z` over horizon `N`, +indexed by absolute time `k`. -/ +noncomputable def snell (E : Set ℕ) (q : ℝ) (Z : ℕ → (ℕ → Bool) → ℝ) (N k : ℕ) + (ω : ℕ → Bool) : ℝ := + snellAux E q Z (N - k) k ω + +/-- Envelope step at an exercise date: the max of the payoff and the node-average +continuation. -/ +lemma snellAux_succ_of_mem {j : ℕ} (hj : j + 1 ∈ E) (q : ℝ) (Z : ℕ → (ℕ → Bool) → ℝ) (k : ℕ) + (ω : ℕ → Bool) : + snellAux E q Z (j + 1) k ω = max (Z k ω) + (q * snellAux E q Z j (k + 1) (Function.update ω k true) + + (1 - q) * snellAux E q Z j (k + 1) (Function.update ω k false)) := by + rw [snellAux, ite_eq_left hj] + +/-- Envelope step off the exercise set: the bare node-average continuation. -/ +lemma snellAux_succ_of_notMem {j : ℕ} (hj : j + 1 ∉ E) (q : ℝ) (Z : ℕ → (ℕ → Bool) → ℝ) (k : ℕ) + (ω : ℕ → Bool) : + snellAux E q Z (j + 1) k ω = + q * snellAux E q Z j (k + 1) (Function.update ω k true) + + (1 - q) * snellAux E q Z j (k + 1) (Function.update ω k false) := by + rw [snellAux, ite_eq_right hj] + +/-- **Dominance clause**: at the horizon and at every exercise date the envelope dominates +the payoff. -/ +theorem snellAux_ge_payoff {j : ℕ} (hj : j = 0 ∨ j ∈ E) (q : ℝ) (Z : ℕ → (ℕ → Bool) → ℝ) + (k : ℕ) (ω : ℕ → Bool) : Z k ω ≤ snellAux E q Z j k ω := by + cases j with + | zero => exact le_rfl + | succ j => + rw [snellAux_succ_of_mem (hj.resolve_left (Nat.succ_ne_zero j))] + exact le_max_left _ _ + +/-- **Supermartingale clause**: the node-average of the next-step envelope is +at most the current envelope — `E[V_{k+1} | ℱ_k] ≤ V_k` in node-average form. -/ +theorem snellAux_supermartingale (E : Set ℕ) (q : ℝ) (Z : ℕ → (ℕ → Bool) → ℝ) (j k : ℕ) + (ω : ℕ → Bool) : + q * snellAux E q Z j (k + 1) (Function.update ω k true) + + (1 - q) * snellAux E q Z j (k + 1) (Function.update ω k false) + ≤ snellAux E q Z (j + 1) k ω := by + by_cases hj : j + 1 ∈ E + · rw [snellAux_succ_of_mem hj]; exact le_max_right _ _ + · rw [snellAux_succ_of_notMem hj] + +/-- **Adaptedness clause**: the envelope at time `k` depends only on the first +`k` flips — it is `ℱ_k`-measurable, the filtration content of the Snell +theorem. -/ +theorem pathAdaptedAt_snellAux (hZ : ∀ n, PathAdaptedAt n (Z n)) : + ∀ j k, PathAdaptedAt k (snellAux E q Z j k) := by + intro j + induction j with + | zero => exact fun k ↦ hZ k + | succ j ih => + intro k ω ω' hω + have h_child : ∀ b : Bool, + snellAux E q Z j (k + 1) (Function.update ω k b) + = snellAux E q Z j (k + 1) (Function.update ω' k b) := by + intro b + refine ih (k + 1) _ _ fun i hi ↦ ?_ + rcases eq_or_ne i k with rfl | hi' + · simp + · rw [Function.update_of_ne hi', Function.update_of_ne hi'] + exact hω i (by omega) + by_cases hj : j + 1 ∈ E + · rw [snellAux_succ_of_mem hj, snellAux_succ_of_mem hj, hZ k ω ω' hω, h_child true, + h_child false] + · rw [snellAux_succ_of_notMem hj, snellAux_succ_of_notMem hj, h_child true, h_child false] + +/-- **Minimality clause (Snell)**: any pathwise supermartingale `U` dominating +the payoff at the exercise dates dominates the envelope — over *arbitrary* +path-processes, a strictly larger competitor class than the scalar (Markov) form. +Backward induction from the horizon `H`: at the horizon the envelope is the payoff; at a +step, the continuation is squeezed by the inductive hypothesis averaged through the node +(convexity: `q ∈ [0,1]`) plus `U`'s own supermartingale property, and at an exercise +date the Bellman max is squeezed because `U` also beats the payoff directly. Only the +supermartingale steps `k < H` before the horizon are used, and the exercise dates are the +times `k` with `H - k` steps to go in `E`. +(Adaptedness of `U` is not needed for the bound — only for reading the node +average as a conditional expectation.) -/ +theorem snellAux_le_of_supermartingale_of_ge {H : ℕ} (hq0 : 0 ≤ q) (hq1 : q ≤ 1) + (hU_super : ∀ k < H, ∀ ω, q * U (k + 1) (Function.update ω k true) + + (1 - q) * U (k + 1) (Function.update ω k false) ≤ U k ω) + (hU_ge : ∀ k ≤ H, (H - k = 0 ∨ H - k ∈ E) → ∀ ω, Z k ω ≤ U k ω) : + ∀ j k ω, k + j = H → snellAux E q Z j k ω ≤ U k ω := by + intro j + induction j with + | zero => exact fun k ω hk ↦ hU_ge k (by omega) (Or.inl (by omega)) ω + | succ j ih => + intro k ω hkj + have hcont : q * snellAux E q Z j (k + 1) (Function.update ω k true) + + (1 - q) * snellAux E q Z j (k + 1) (Function.update ω k false) ≤ U k ω := + calc _ ≤ q * U (k + 1) (Function.update ω k true) + + (1 - q) * U (k + 1) (Function.update ω k false) := + add_le_add (mul_le_mul_of_nonneg_left (ih _ _ (by omega)) hq0) + (mul_le_mul_of_nonneg_left (ih _ _ (by omega)) (by linarith)) + _ ≤ U k ω := hU_super k (by omega) ω + by_cases hj : j + 1 ∈ E + · rw [snellAux_succ_of_mem hj] + exact max_le (hU_ge k (by omega) (Or.inr (by rwa [show H - k = j + 1 by omega])) ω) hcont + · rwa [snellAux_succ_of_notMem hj] + +/-- **One node of the discounted tree**: discounting the two children at `e^{-r(k+1)}` and +averaging with the risk-neutral weights is `e^{-rk}` times the one-period price. -/ +lemma crrUpProb_average_discounted (u d r : ℝ) (k : ℕ) (a b : ℝ) : + crrUpProb u d r * (Real.exp (-r * (k + 1 : ℕ)) * a) + + (1 - crrUpProb u d r) * (Real.exp (-r * (k + 1 : ℕ)) * b) + = Real.exp (-r * k) * binomialOptionPriceOnePeriod u d r a b := by + unfold binomialOptionPriceOnePeriod + have hexp : Real.exp (-r * ((k : ℕ) + 1 : ℕ)) = Real.exp (-r * k) * Real.exp (-r) := by + rw [← Real.exp_add] + congr 1 + push_cast + ring + rw [hexp] + ring + +/-- **Identification with the scalar Bellman recursion**: for the discounted +intrinsic payoff `Z_n(ω) = e^{−rn}·g(S_n(ω))` and risk-neutral +`q = crrUpProb u d r`, the path-space Snell envelope *is* the discounted +scalar price with early exercise on `E`: + + `snellAux E q Z j k ω = e^{−rk} · bermudanPrice E u d r g j (S_k(ω))`. + +Induction on remaining steps; the discount factors recombine +(`e^{−rk}·e^{−r} = e^{−r(k+1)}`) and the positive factor `e^{−rk}` passes +through the Bellman `max`. -/ +theorem snellAux_eq_discounted_bermudanPrice (E : Set ℕ) (u d r : ℝ) (g : ℝ → ℝ) (S₀ : ℝ) : + ∀ j k ω, + snellAux E (crrUpProb u d r) + (fun n ω ↦ Real.exp (-r * n) * g (spotPath S₀ u d n ω)) j k ω + = Real.exp (-r * k) * bermudanPrice E u d r g j (spotPath S₀ u d k ω) := by + intro j + induction j with + | zero => intro k ω; rfl + | succ j ih => + intro k ω + have h_cont : crrUpProb u d r * snellAux E (crrUpProb u d r) + (fun n ω ↦ Real.exp (-r * n) * g (spotPath S₀ u d n ω)) j (k + 1) + (Function.update ω k true) + + (1 - crrUpProb u d r) * snellAux E (crrUpProb u d r) + (fun n ω ↦ Real.exp (-r * n) * g (spotPath S₀ u d n ω)) j (k + 1) + (Function.update ω k false) + = Real.exp (-r * k) * binomialOptionPriceOnePeriod u d r + (bermudanPrice E u d r g j (spotPath S₀ u d k ω * u)) + (bermudanPrice E u d r g j (spotPath S₀ u d k ω * d)) := by + rw [ih (k + 1) (Function.update ω k true), ih (k + 1) (Function.update ω k false), + spotPath_update_succ_true, spotPath_update_succ_false, crrUpProb_average_discounted] + by_cases hj : j + 1 ∈ E + · rw [snellAux_succ_of_mem hj, bermudanPrice_succ_of_mem hj, + mul_max_of_nonneg _ _ (Real.exp_pos (-r * (k : ℝ))).le] + exact congrArg₂ max rfl h_cont + · rw [snellAux_succ_of_notMem hj, bermudanPrice_succ_of_notMem hj] + exact h_cont + +/-- **Snell envelope upper bound (Markov form)**: any function `V : ℕ → ℝ → ℝ` that dominates +the payoff at maturity and at the exercise dates (`hV_g`) and satisfies the one-step +supermartingale condition (`hV_super`) is bounded below by `bermudanPrice E` at every step +and spot. + +Combined with `le_bermudanPrice` and `bermudanPrice_supermartingale` (which show +`bermudanPrice E` itself satisfies both conditions), this gives the **Snell envelope +characterization**: `bermudanPrice E` is the smallest such `V`. It is the pathwise minimality +(`snellAux_le_of_supermartingale_of_ge`) for the discounted process +`U_k(ω) = e^{−rk}·V_{n−k}(S_k(ω))` along the spot path from `S`, whose supermartingale step is +`hV_super` at the node (`crrUpProb_average_discounted`), against the discounted intrinsic payoff; +by the identification theorem its envelope at time `0` is `bermudanPrice E n S`. -/ +theorem bermudanPrice_le_of_supermartingale_dominating + {u d r : ℝ} (h : BinomialNoArb u d r) (E : Set ℕ) (g : ℝ → ℝ) (V : ℕ → ℝ → ℝ) + (hV_g : ∀ n, (n = 0 ∨ n ∈ E) → ∀ S, g S ≤ V n S) + (hV_super : ∀ n S, + binomialOptionPriceOnePeriod u d r (V n (S * u)) (V n (S * d)) ≤ + V (n + 1) S) : + ∀ n S, bermudanPrice E u d r g n S ≤ V n S := by + intro n S + have key := snellAux_le_of_supermartingale_of_ge (E := E) (q := crrUpProb u d r) (H := n) + (Z := fun m ω ↦ Real.exp (-r * m) * g (spotPath S u d m ω)) + (U := fun k ω ↦ Real.exp (-r * k) * V (n - k) (spotPath S u d k ω)) + (crrUpProb_mem_Ioo h).1.le (crrUpProb_mem_Ioo h).2.le + (fun k hk ω ↦ by + rw [spotPath_update_succ_true, spotPath_update_succ_false, crrUpProb_average_discounted, + show n - k = (n - (k + 1)) + 1 by omega] + exact mul_le_mul_of_nonneg_left (hV_super _ _) (Real.exp_pos _).le) + (fun k _ hk ω ↦ mul_le_mul_of_nonneg_left (hV_g _ hk _) (Real.exp_pos _).le) + n 0 (fun _ ↦ true) (by omega) + rwa [snellAux_eq_discounted_bermudanPrice, Nat.cast_zero, mul_zero, Real.exp_zero, one_mul, + Nat.sub_zero, one_mul, spotPath, Finset.prod_range_zero, mul_one] at key + +/-- **Snell envelope theorem (packaged form)**: `bermudanPrice E u d r g` is +the smallest function `V : ℕ → ℝ → ℝ` that simultaneously dominates the +payoff at maturity and at the exercise dates and satisfies the one-step supermartingale +property. + +The statement makes the universal characterization visible: for *any* V +satisfying the two properties, `bermudanPrice E ≤ V`. -/ +theorem bermudanPrice_is_snell_envelope + {u d r : ℝ} (h : BinomialNoArb u d r) (E : Set ℕ) (g : ℝ → ℝ) : + (∀ n, (n = 0 ∨ n ∈ E) → ∀ S, g S ≤ bermudanPrice E u d r g n S) ∧ + (∀ n S, + binomialOptionPriceOnePeriod u d r + (bermudanPrice E u d r g n (S * u)) (bermudanPrice E u d r g n (S * d)) ≤ + bermudanPrice E u d r g (n + 1) S) ∧ + (∀ (V : ℕ → ℝ → ℝ), + (∀ n, (n = 0 ∨ n ∈ E) → ∀ S, g S ≤ V n S) → + (∀ n S, + binomialOptionPriceOnePeriod u d r (V n (S * u)) (V n (S * d)) ≤ + V (n + 1) S) → + ∀ n S, bermudanPrice E u d r g n S ≤ V n S) := + ⟨fun _ hn S ↦ le_bermudanPrice hn u d r g S, + bermudanPrice_supermartingale E u d r g, + bermudanPrice_le_of_supermartingale_dominating h E g⟩ + +/-- **The discounted price process is a supermartingale** along every +path: for `k < N`, the risk-neutral node-average of the next-step discounted +value is at most the current discounted value — + + `q·X_{k+1}(up) + (1−q)·X_{k+1}(down) ≤ X_k`, `X_k(ω) = e^{−rk}·V_{N−k}(S_k(ω))`, + +for the price `V = bermudanPrice E` with early exercise on any step set `E`. This is the +genuine path-process, conditional-expectation form behind the scalar Bellman-max +dominance. -/ +theorem discounted_bermudanPrice_supermartingale (E : Set ℕ) (u d r : ℝ) (g : ℝ → ℝ) (S₀ : ℝ) + {N k : ℕ} (hk : k < N) (ω : ℕ → Bool) : + crrUpProb u d r * (Real.exp (-r * (k + 1 : ℕ)) * + bermudanPrice E u d r g (N - (k + 1)) + (spotPath S₀ u d (k + 1) (Function.update ω k true))) + + (1 - crrUpProb u d r) * (Real.exp (-r * (k + 1 : ℕ)) * + bermudanPrice E u d r g (N - (k + 1)) + (spotPath S₀ u d (k + 1) (Function.update ω k false))) + ≤ Real.exp (-r * k) * bermudanPrice E u d r g (N - k) (spotPath S₀ u d k ω) := by + have hjk : N - k = (N - (k + 1)) + 1 := by omega + calc crrUpProb u d r * (Real.exp (-r * (k + 1 : ℕ)) * + bermudanPrice E u d r g (N - (k + 1)) + (spotPath S₀ u d (k + 1) (Function.update ω k true))) + + (1 - crrUpProb u d r) * (Real.exp (-r * (k + 1 : ℕ)) * + bermudanPrice E u d r g (N - (k + 1)) + (spotPath S₀ u d (k + 1) (Function.update ω k false))) + = crrUpProb u d r * snellAux E (crrUpProb u d r) + (fun n ω ↦ Real.exp (-r * n) * g (spotPath S₀ u d n ω)) (N - (k + 1)) (k + 1) + (Function.update ω k true) + + (1 - crrUpProb u d r) * snellAux E (crrUpProb u d r) + (fun n ω ↦ Real.exp (-r * n) * g (spotPath S₀ u d n ω)) (N - (k + 1)) (k + 1) + (Function.update ω k false) := by + rw [snellAux_eq_discounted_bermudanPrice, snellAux_eq_discounted_bermudanPrice] + _ ≤ snellAux E (crrUpProb u d r) + (fun n ω ↦ Real.exp (-r * n) * g (spotPath S₀ u d n ω)) ((N - (k + 1)) + 1) k ω := + snellAux_supermartingale _ _ _ _ _ _ + _ = Real.exp (-r * k) * bermudanPrice E u d r g (N - k) (spotPath S₀ u d k ω) := by + rw [← hjk, snellAux_eq_discounted_bermudanPrice] + +/-- **The discounted intrinsic payoff is dominated by the discounted price +process** along every path, at the maturity and at every exercise date — the dominance +clause of the Snell characterization, evaluated at the scalar Bellman recursion. -/ +theorem discounted_intrinsic_le_bermudanPrice (E : Set ℕ) (u d r : ℝ) (g : ℝ → ℝ) (S₀ : ℝ) + {N k : ℕ} (hNk : N - k = 0 ∨ N - k ∈ E) (ω : ℕ → Bool) : + Real.exp (-r * k) * g (spotPath S₀ u d k ω) + ≤ Real.exp (-r * k) * bermudanPrice E u d r g (N - k) (spotPath S₀ u d k ω) := by + rw [← snellAux_eq_discounted_bermudanPrice] + exact snellAux_ge_payoff hNk (crrUpProb u d r) + (fun n ω ↦ Real.exp (-r * n) * g (spotPath S₀ u d n ω)) k ω + +/-- **Snell minimality at the price**: any pathwise supermartingale +`U` (w.r.t. the risk-neutral node average, up to the horizon `N`) dominating the discounted +intrinsic payoff at the exercise dates dominates the discounted price along every path. +Together with `discounted_bermudanPrice_supermartingale` and +`discounted_intrinsic_le_bermudanPrice`, this characterizes the value +process as the **smallest supermartingale above the discounted payoff** — the +Snell envelope — over arbitrary path-processes. -/ +theorem bermudanPrice_snell_minimal (E : Set ℕ) (u d r : ℝ) (g : ℝ → ℝ) (S₀ : ℝ) + (hna : BinomialNoArb u d r) {N : ℕ} {U : ℕ → (ℕ → Bool) → ℝ} + (hU_super : ∀ k < N, ∀ ω : ℕ → Bool, + crrUpProb u d r * U (k + 1) (Function.update ω k true) + + (1 - crrUpProb u d r) * U (k + 1) (Function.update ω k false) ≤ U k ω) + (hU_ge : ∀ k ≤ N, (N - k = 0 ∨ N - k ∈ E) → ∀ ω : ℕ → Bool, + Real.exp (-r * k) * g (spotPath S₀ u d k ω) ≤ U k ω) + {k : ℕ} (hk : k ≤ N) (ω : ℕ → Bool) : + Real.exp (-r * k) * bermudanPrice E u d r g (N - k) (spotPath S₀ u d k ω) ≤ U k ω := by + rw [← snellAux_eq_discounted_bermudanPrice] + exact snellAux_le_of_supermartingale_of_ge (crrUpProb_mem_Ioo hna).1.le + (crrUpProb_mem_Ioo hna).2.le hU_super hU_ge _ k ω (by omega) + +/-- **Adaptedness of the discounted value process**: the discounted +value at time `k` depends only on the first `k` flips — its +`ℱ_k`-measurability, the filtration clause of the Snell characterization at +the price. -/ +lemma pathAdaptedAt_discounted_bermudanPrice (E : Set ℕ) (u d r : ℝ) (g : ℝ → ℝ) (S₀ : ℝ) + (N k : ℕ) : + PathAdaptedAt k (fun ω ↦ Real.exp (-r * k) * + bermudanPrice E u d r g (N - k) (spotPath S₀ u d k ω)) := fun ω ω' h ↦ by + change Real.exp (-r * k) * bermudanPrice E u d r g (N - k) (spotPath S₀ u d k ω) + = Real.exp (-r * k) * bermudanPrice E u d r g (N - k) (spotPath S₀ u d k ω') + rw [pathAdaptedAt_spotPath S₀ u d k ω ω' h] + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/American/AmericanQDPlusLimits.lean b/LeanPool/MathFin/Models/BlackScholes/American/AmericanQDPlusLimits.lean new file mode 100644 index 0000000000..1e39ccbc85 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/American/AmericanQDPlusLimits.lean @@ -0,0 +1,449 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Gaussian.NormalTail +public import LeanPool.MathFin.Models.BlackScholes.Call +public import Mathlib.Algebra.Ring.IsFormallyReal + +/-! # Endpoint limits of the QD+ fixed-point integrands + +The fixed-point scheme of Andersen, Lake and Offengenden (QD+) for the American put exercise +boundary integrates, at a collocation node `τ` with trial boundary value `b`, explicit +integrands built from an interpolated boundary `B`. Here `B` is an arbitrary real function: the +integrands below are not tied to the American put's exercise boundary, and nothing in this file +connects them to it. With +`d₊(t, z) = bsd1 z 1 (r - q) σ t` and `d₋(t, z) = bsd2 z 1 (r - q) σ t`, they are + +* equation A, after the substitution `m = τ (1 + y)² / 4`, `y ∈ [-1, 1]`: + `K₁₂(y) = e^{q(τ-m)} (½ τ (1 + y) Φ(d₊(m, b/B(τ-m))) + (√τ/σ) φ(d₊(m, b/B(τ-m))))` and + `K₃(y) = (√τ/σ) e^{r(τ-m)} φ(d₋(m, b/B(τ-m)))`; +* equation B, on `u ∈ [0, τ]`: + `nᵢ(u) = e^{r u} Φ(d₋(τ-u, b/B(u)))` and `dᵢ(u) = e^{q u} Φ(d₊(τ-u, b/B(u)))`. + +These are transcribed from QuantLib's `qdfpamericanengine.cpp`. At the endpoint `y = -1` +(respectively `u = τ`) the time argument vanishes, so `d±` is a `0/0` form when `b = B τ`. +A Gauss–Lobatto rule samples this endpoint, so it needs the one-sided limit. This file +computes it over an abstract boundary `B`, with no fixed-point or pricing content. + +## Main definitions + +* `qdfpK12`: fixed-point equation A, the `K₁ + K₂` integrand after the substitution + `m = τ (1 + y)² / 4`, built from an arbitrary real function `B`. +* `qdfpK3`: fixed-point equation A, the `K₃` integrand after the same substitution. +* `qdfpNi`, `qdfpDi`: fixed-point equation B, the numerator and denominator integrands. + +## Main results + +* `b = B τ`, `B` differentiable at `τ` with `0 < B τ`: `K₁₂ → e^{qτ} (√τ/σ)/√(2π)`, + `K₃ → e^{rτ} (√τ/σ)/√(2π)`, `nᵢ → ½ e^{rτ}`, `dᵢ → ½ e^{qτ}` + (`tendsto_qdfpK12_endpoint` and siblings). +* `b ≠ B τ`, `B` only continuous at `τ`: `K₁₂, K₃ → 0`, and `nᵢ, dᵢ` tend to `e^{rτ}`, + `e^{qτ}` when `B τ < b` and to `0` when `b < B τ` (`tendsto_qdfpK12_endpoint_ne` and + siblings). The endpoint value is therefore discontinuous in `b` at `b = B τ`. +* Differentiability is sufficient for the limit above, but continuity alone is not: for the + continuous boundary `B s = b e^{-c √(τ-s)}`, which has `B τ = b` and + `log (b / B(τ - m)) = c √m`, `K₁₂ → e^{qτ} (√τ/σ) φ(c/σ)`, which differs from the value + above when `c ≠ 0` (`tendsto_qdfpK12_endpoint_holder`, `not_tendsto_qdfpK12_endpoint_holder`). + This counterexample is nondifferentiable at `τ`, so it shows continuity alone does not pin + down the differentiable-case limit; it does not show differentiability is necessary for + convergence as such. + +## References + +* [J. Healy, *Pricing American options under negative rates*][Healy2021], §5.1 + (restates the fixed-point equations and the substitution `y = -1 + 2 √((τ - u)/τ)`). +* [Andersen, Lake and Offengenden, *High-performance American option + pricing*][AndersenLakeOffengenden2016] + +## Tags + +QD+ method, American put, exercise boundary, fixed-point integral equation, Gauss–Lobatto, +negative rates, MSC 91G60, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Filter Set ProbabilityTheory +open scoped Topology Real + +/-- Fixed-point equation A, the `K₁ + K₂` integrand after the substitution +`m = τ (1 + y)² / 4`. -/ +noncomputable def qdfpK12 (B : ℝ → ℝ) (r q σ τ b y : ℝ) : ℝ := + Real.exp (q * (τ - τ * (1 + y) ^ 2 / 4)) * + (τ * (1 + y) / 2 * Phi (bsd1 (b / B (τ - τ * (1 + y) ^ 2 / 4)) 1 (r - q) σ + (τ * (1 + y) ^ 2 / 4)) + + Real.sqrt τ / σ * gaussianPDFReal 0 1 (bsd1 (b / B (τ - τ * (1 + y) ^ 2 / 4)) 1 + (r - q) σ (τ * (1 + y) ^ 2 / 4))) + +/-- Fixed-point equation A, the `K₃` integrand after the substitution `m = τ (1 + y)² / 4`. -/ +noncomputable def qdfpK3 (B : ℝ → ℝ) (r q σ τ b y : ℝ) : ℝ := + Real.sqrt τ / σ * Real.exp (r * (τ - τ * (1 + y) ^ 2 / 4)) * + gaussianPDFReal 0 1 (bsd2 (b / B (τ - τ * (1 + y) ^ 2 / 4)) 1 (r - q) σ + (τ * (1 + y) ^ 2 / 4)) + +/-- Fixed-point equation B, the numerator integrand. -/ +noncomputable def qdfpNi (B : ℝ → ℝ) (r q σ τ b u : ℝ) : ℝ := + Real.exp (r * u) * Phi (bsd2 (b / B u) 1 (r - q) σ (τ - u)) + +/-- Fixed-point equation B, the denominator integrand. -/ +noncomputable def qdfpDi (B : ℝ → ℝ) (r q σ τ b u : ℝ) : ℝ := + Real.exp (q * u) * Phi (bsd1 (b / B u) 1 (r - q) σ (τ - u)) + +/-! ### The standard normal density at the origin and at infinity -/ + +theorem gaussianPDFReal_zero_one_zero : gaussianPDFReal 0 1 0 = 1 / Real.sqrt (2 * π) := by + simp [gaussianPDFReal] + +theorem tendsto_gaussianPDFReal_zero_one_atTop : + Tendsto (gaussianPDFReal 0 1) atTop (𝓝 0) := by + have h : Tendsto (fun x : ℝ ↦ -(x - 0) ^ 2 / (2 * ((1 : NNReal) : ℝ))) atTop atBot := by + have : Tendsto (fun x : ℝ ↦ x ^ 2) atTop atTop := tendsto_pow_atTop two_ne_zero + simpa [neg_div] using (tendsto_neg_atTop_atBot.comp this).atBot_div_const two_pos + have := (Real.tendsto_exp_atBot.comp h).const_mul (Real.sqrt (2 * π * ((1 : NNReal) : ℝ)))⁻¹ + rw [mul_zero] at this + exact this + +theorem tendsto_gaussianPDFReal_zero_one_atBot : + Tendsto (gaussianPDFReal 0 1) atBot (𝓝 0) := by + have := tendsto_gaussianPDFReal_zero_one_atTop.comp tendsto_neg_atBot_atTop + simpa [Function.comp_def, gaussianPDFReal_zero_one_neg] using this + +theorem gaussianPDFReal_zero_one_ne_zero_point {x : ℝ} (hx : x ≠ 0) : + gaussianPDFReal 0 1 x ≠ gaussianPDFReal 0 1 0 := by + intro h + simp only [gaussianPDFReal, sub_zero, NNReal.coe_one, mul_one, + zero_pow two_ne_zero, neg_zero, zero_div, Real.exp_zero] at h + have h2 : Real.exp (-x ^ 2 / 2) = 1 := by + have hc : (Real.sqrt (2 * π))⁻¹ ≠ 0 := by positivity + exact mul_left_cancel₀ hc (h.trans (mul_one _).symm) + have : -x ^ 2 / 2 = 0 := by simpa using h2 + exact hx (by nlinarith [sq_nonneg x]) + +/-! ### The `d±` arguments near the endpoint -/ + +/-- The time change `m = τ (1 + y)² / 4` maps `y → -1⁺` to `m → 0⁺`. -/ +theorem tendsto_qdfpTimeChange {τ : ℝ} (hτ : 0 < τ) : + Tendsto (fun y : ℝ ↦ τ * (1 + y) ^ 2 / 4) (𝓝[>] (-1)) (𝓝[>] 0) := by + refine tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ?_ ?_ + · have : Tendsto (fun y : ℝ ↦ τ * (1 + y) ^ 2 / 4) (𝓝 (-1)) (𝓝 (τ * (1 + -1) ^ 2 / 4)) := + (by fun_prop : Continuous fun y : ℝ ↦ τ * (1 + y) ^ 2 / 4).tendsto _ + simpa using this.mono_left nhdsWithin_le_nhds + · filter_upwards [self_mem_nhdsWithin] with y (hy : -1 < y) + have : 0 < 1 + y := by linarith + exact (by positivity : 0 < τ * (1 + y) ^ 2 / 4) + +/-- `u ↦ τ - u` maps `u → τ⁻` to `m → 0⁺`. -/ +theorem tendsto_sub_nhdsLT_nhdsGT_zero (τ : ℝ) : + Tendsto (fun u : ℝ ↦ τ - u) (𝓝[<] τ) (𝓝[>] 0) := by + refine tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ?_ ?_ + · have : Tendsto (fun u : ℝ ↦ τ - u) (𝓝 τ) (𝓝 (τ - τ)) := + (by fun_prop : Continuous fun u : ℝ ↦ τ - u).tendsto _ + simpa using this.mono_left nhdsWithin_le_nhds + · filter_upwards [self_mem_nhdsWithin] with u (hu : u < τ) + exact sub_pos.mpr hu + +theorem tendsto_sqrt_nhdsGT_zero : Tendsto Real.sqrt (𝓝[>] 0) (𝓝 0) := by + simpa using (Real.continuous_sqrt.tendsto 0).mono_left nhdsWithin_le_nhds + +/-- On the diagonal `b = B τ`, with `B` differentiable at `τ` and `0 < B τ`, +`d₊(m, B τ / B(τ - m)) → 0` as `m → 0⁺`. -/ +theorem tendsto_bsd1_boundaryRatio_of_eq {B : ℝ → ℝ} {a σ τ : ℝ} + (hB : DifferentiableAt ℝ B τ) (hBpos : 0 < B τ) (hσ : 0 < σ) : + Tendsto (fun m ↦ bsd1 (B τ / B (τ - m)) 1 a σ m) (𝓝[>] 0) (𝓝 0) := by + set g : ℝ → ℝ := fun s ↦ Real.log (B s) + have hg : HasDerivAt g (deriv B τ / B τ) τ := hB.hasDerivAt.log hBpos.ne' + -- the left difference quotient of `log ∘ B` at `τ` + have hneg : Tendsto (fun m : ℝ ↦ -m) (𝓝[>] 0) (𝓝[≠] 0) := by + refine tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ?_ ?_ + · simpa using ((continuous_neg.tendsto (0 : ℝ)).mono_left nhdsWithin_le_nhds) + · filter_upwards [self_mem_nhdsWithin] with m (hm : 0 < m) + exact neg_ne_zero.mpr hm.ne' + have hslope := hg.tendsto_slope_zero.comp hneg + -- `B (τ - m)` is eventually positive + have hBτ : Tendsto (fun m ↦ B (τ - m)) (𝓝[>] 0) (𝓝 (B τ)) := by + have : Tendsto (fun m : ℝ ↦ τ - m) (𝓝[>] 0) (𝓝 τ) := by + simpa using ((by fun_prop : Continuous fun m : ℝ ↦ τ - m).tendsto 0).mono_left + nhdsWithin_le_nhds + exact hB.continuousAt.tendsto.comp this + have hpos : ∀ᶠ m in 𝓝[>] (0 : ℝ), 0 < B (τ - m) := hBτ.eventually (lt_mem_nhds hBpos) + have hlim : Tendsto (fun m : ℝ ↦ + ((-m)⁻¹ • (g (τ + -m) - g τ)) * (Real.sqrt m / σ) + (a + σ ^ 2 / 2) * (Real.sqrt m / σ)) + (𝓝[>] 0) (𝓝 ((deriv B τ / B τ) * (0 / σ) + (a + σ ^ 2 / 2) * (0 / σ))) := + (hslope.mul (tendsto_sqrt_nhdsGT_zero.div_const σ)).add + ((tendsto_sqrt_nhdsGT_zero.div_const σ).const_mul _) + simp only [zero_div, mul_zero, add_zero] at hlim + refine hlim.congr' ?_ + filter_upwards [self_mem_nhdsWithin, hpos] with m (hm : 0 < m) hBm + simp only [g, bsd1, div_one, smul_eq_mul, ← sub_eq_add_neg] + rw [Real.log_div hBpos.ne' hBm.ne'] + obtain ⟨s, hs0, rfl⟩ : ∃ s, 0 < s ∧ m = s ^ 2 := + ⟨Real.sqrt m, Real.sqrt_pos.mpr hm, (Real.sq_sqrt hm.le).symm⟩ + rw [Real.sqrt_sq hs0.le] + field_simp + ring + +/-- The same as `tendsto_bsd1_boundaryRatio_of_eq` for `d₋ = d₊ - σ √m`. -/ +theorem tendsto_bsd2_boundaryRatio_of_eq {B : ℝ → ℝ} {a σ τ : ℝ} + (hB : DifferentiableAt ℝ B τ) (hBpos : 0 < B τ) (hσ : 0 < σ) : + Tendsto (fun m ↦ bsd2 (B τ / B (τ - m)) 1 a σ m) (𝓝[>] 0) (𝓝 0) := by + simpa [bsd2] using + (tendsto_bsd1_boundaryRatio_of_eq (a := a) hB hBpos hσ).sub + (tendsto_sqrt_nhdsGT_zero.const_mul σ) + +/-- Off the diagonal, with `B` continuous at `τ` and `0 < B τ`, `d₊(m, b / B(τ - m))` +tends to `+∞` when `B τ < b` and to `-∞` when `b < B τ`, as `m → 0⁺`. -/ +theorem tendsto_bsd1_boundaryRatio_of_ne {B : ℝ → ℝ} {a σ τ b : ℝ} + (hB : ContinuousAt B τ) (hBpos : 0 < B τ) (hb : 0 < b) (hσ : 0 < σ) : + (B τ < b → Tendsto (fun m ↦ bsd1 (b / B (τ - m)) 1 a σ m) (𝓝[>] 0) atTop) ∧ + (b < B τ → Tendsto (fun m ↦ bsd1 (b / B (τ - m)) 1 a σ m) (𝓝[>] 0) atBot) := by + have hBτ : Tendsto (fun m ↦ B (τ - m)) (𝓝[>] 0) (𝓝 (B τ)) := by + have : Tendsto (fun m : ℝ ↦ τ - m) (𝓝[>] 0) (𝓝 τ) := by + simpa using ((by fun_prop : Continuous fun m : ℝ ↦ τ - m).tendsto 0).mono_left + nhdsWithin_le_nhds + exact hB.tendsto.comp this + have hnum : Tendsto (fun m ↦ Real.log (b / B (τ - m) / 1) + (a + σ ^ 2 / 2) * m) (𝓝[>] 0) + (𝓝 (Real.log (b / B τ))) := by + have hlog := ((Real.continuousAt_log (div_pos hb hBpos).ne').tendsto.comp + ((tendsto_const_nhds (x := b)).div hBτ hBpos.ne')) + have hm : Tendsto (fun m : ℝ ↦ m) (𝓝[>] 0) (𝓝 0) := nhdsWithin_le_nhds + simpa [Function.comp_def] using hlog.add (hm.const_mul (a + σ ^ 2 / 2)) + have hden : Tendsto (fun m ↦ (σ * Real.sqrt m)⁻¹) (𝓝[>] 0) atTop := by + refine tendsto_inv_nhdsGT_zero.comp + (tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ?_ ?_) + · simpa using tendsto_sqrt_nhdsGT_zero.const_mul σ + · filter_upwards [self_mem_nhdsWithin] with m (hm : 0 < m) + exact mul_pos hσ (Real.sqrt_pos.mpr hm) + constructor + · intro hlt + have hc : 0 < Real.log (b / B τ) := Real.log_pos ((one_lt_div hBpos).mpr hlt) + simpa [bsd1, div_eq_mul_inv] using hnum.pos_mul_atTop hc hden + · intro hlt + have hc : Real.log (b / B τ) < 0 := + Real.log_neg (div_pos hb hBpos) ((div_lt_one hBpos).mpr hlt) + simpa [bsd1, div_eq_mul_inv] using hnum.neg_mul_atTop hc hden + +/-- The same as `tendsto_bsd1_boundaryRatio_of_ne` for `d₋ = d₊ - σ √m`. -/ +theorem tendsto_bsd2_boundaryRatio_of_ne {B : ℝ → ℝ} {a σ τ b : ℝ} + (hB : ContinuousAt B τ) (hBpos : 0 < B τ) (hb : 0 < b) (hσ : 0 < σ) : + (B τ < b → Tendsto (fun m ↦ bsd2 (b / B (τ - m)) 1 a σ m) (𝓝[>] 0) atTop) ∧ + (b < B τ → Tendsto (fun m ↦ bsd2 (b / B (τ - m)) 1 a σ m) (𝓝[>] 0) atBot) := by + obtain ⟨h1, h2⟩ := tendsto_bsd1_boundaryRatio_of_ne (a := a) hB hBpos hb hσ + have hs : Tendsto (fun m ↦ -(σ * Real.sqrt m)) (𝓝[>] 0) (𝓝 0) := by + simpa using (tendsto_sqrt_nhdsGT_zero.const_mul σ).neg + refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ + · simpa [bsd2, sub_eq_add_neg] using (h1 h).atTop_add hs + · simpa [bsd2, sub_eq_add_neg] using (h2 h).atBot_add hs + +/-! ### Equation A at `y = -1` -/ + +theorem tendsto_qdfpTimeChange_nhds {τ : ℝ} (hτ : 0 < τ) : + Tendsto (fun y : ℝ ↦ τ * (1 + y) ^ 2 / 4) (𝓝[>] (-1)) (𝓝 0) := + tendsto_nhds_of_tendsto_nhdsWithin (tendsto_qdfpTimeChange hτ) + +theorem tendsto_qdfpHalfJacobian (τ : ℝ) : + Tendsto (fun y : ℝ ↦ τ * (1 + y) / 2) (𝓝[>] (-1)) (𝓝 0) := by + simpa using ((by fun_prop : Continuous fun y : ℝ ↦ τ * (1 + y) / 2).tendsto (-1)).mono_left + nhdsWithin_le_nhds + +theorem tendsto_exp_qdfpDiscount (c : ℝ) {τ : ℝ} (hτ : 0 < τ) : + Tendsto (fun y : ℝ ↦ Real.exp (c * (τ - τ * (1 + y) ^ 2 / 4))) (𝓝[>] (-1)) + (𝓝 (Real.exp (c * τ))) := by + simpa [Function.comp_def] using (Real.continuous_exp.tendsto _).comp + (((tendsto_qdfpTimeChange_nhds hτ).const_sub τ).const_mul c) + +/-- **Equation A, `K₁₂` at `y = -1`, on the diagonal.** With `b = B τ` and `B` differentiable +at `τ`, the integrand tends to `e^{qτ} (√τ/σ)/√(2π)`. -/ +theorem tendsto_qdfpK12_endpoint {B : ℝ → ℝ} {r q σ τ : ℝ} (hσ : 0 < σ) (hτ : 0 < τ) + (hB : DifferentiableAt ℝ B τ) (hBpos : 0 < B τ) : + Tendsto (qdfpK12 B r q σ τ (B τ)) (𝓝[>] (-1)) + (𝓝 (Real.exp (q * τ) * (Real.sqrt τ / σ) / Real.sqrt (2 * π))) := by + have hd := (tendsto_bsd1_boundaryRatio_of_eq (a := r - q) hB hBpos hσ).comp + (tendsto_qdfpTimeChange hτ) + have := (tendsto_exp_qdfpDiscount q hτ).mul + (((tendsto_qdfpHalfJacobian τ).mul ((continuous_Phi.tendsto 0).comp hd)).add + (((continuous_gaussianPDFReal 0 1).tendsto 0).comp + hd |>.const_mul (Real.sqrt τ / σ))) + rw [gaussianPDFReal_zero_one_zero] at this + convert this using 2 <;> first | rfl | ring + +/-- **Equation A, `K₃` at `y = -1`, on the diagonal.** -/ +theorem tendsto_qdfpK3_endpoint {B : ℝ → ℝ} {r q σ τ : ℝ} (hσ : 0 < σ) (hτ : 0 < τ) + (hB : DifferentiableAt ℝ B τ) (hBpos : 0 < B τ) : + Tendsto (qdfpK3 B r q σ τ (B τ)) (𝓝[>] (-1)) + (𝓝 (Real.exp (r * τ) * (Real.sqrt τ / σ) / Real.sqrt (2 * π))) := by + have hd := (tendsto_bsd2_boundaryRatio_of_eq (a := r - q) hB hBpos hσ).comp + (tendsto_qdfpTimeChange hτ) + have := ((tendsto_exp_qdfpDiscount r hτ).const_mul (Real.sqrt τ / σ)).mul + (((continuous_gaussianPDFReal 0 1).tendsto 0).comp hd) + rw [gaussianPDFReal_zero_one_zero] at this + convert this using 2 <;> first | rfl | ring + +/-- **Equation A, `K₁₂` at `y = -1`, off the diagonal.** With `b ≠ B τ` and `B` only +continuous at `τ`, the integrand tends to `0`. -/ +theorem tendsto_qdfpK12_endpoint_ne {B : ℝ → ℝ} {r q σ τ b : ℝ} (hσ : 0 < σ) (hτ : 0 < τ) + (hB : ContinuousAt B τ) (hBpos : 0 < B τ) (hb : 0 < b) (hne : b ≠ B τ) : + Tendsto (qdfpK12 B r q σ τ b) (𝓝[>] (-1)) (𝓝 0) := by + obtain ⟨hup, hdown⟩ := tendsto_bsd1_boundaryRatio_of_ne (a := r - q) hB hBpos hb hσ + have hpdf : Tendsto (fun y : ℝ ↦ gaussianPDFReal 0 1 (bsd1 (b / B (τ - τ * (1 + y) ^ 2 / 4)) + 1 (r - q) σ (τ * (1 + y) ^ 2 / 4))) (𝓝[>] (-1)) (𝓝 0) := by + rcases hne.lt_or_gt with h | h + · exact tendsto_gaussianPDFReal_zero_one_atBot.comp ((hdown h).comp + (tendsto_qdfpTimeChange hτ)) + · exact tendsto_gaussianPDFReal_zero_one_atTop.comp ((hup h).comp + (tendsto_qdfpTimeChange hτ)) + have hPhi : Tendsto (fun y : ℝ ↦ τ * (1 + y) / 2 * Phi (bsd1 (b / B (τ - τ * (1 + y) ^ 2 / 4)) + 1 (r - q) σ (τ * (1 + y) ^ 2 / 4))) (𝓝[>] (-1)) (𝓝 0) := + (tendsto_qdfpHalfJacobian τ).zero_mul_isBoundedUnder_le + (isBoundedUnder_of ⟨1, fun y ↦ by + simpa [abs_of_nonneg (Phi_nonneg _)] using Phi_le_one _⟩) + have := (tendsto_exp_qdfpDiscount q hτ).mul (hPhi.add (hpdf.const_mul (Real.sqrt τ / σ))) + rw [mul_zero, add_zero, mul_zero] at this + exact this + +/-- **Equation A, `K₃` at `y = -1`, off the diagonal.** -/ +theorem tendsto_qdfpK3_endpoint_ne {B : ℝ → ℝ} {r q σ τ b : ℝ} (hσ : 0 < σ) (hτ : 0 < τ) + (hB : ContinuousAt B τ) (hBpos : 0 < B τ) (hb : 0 < b) (hne : b ≠ B τ) : + Tendsto (qdfpK3 B r q σ τ b) (𝓝[>] (-1)) (𝓝 0) := by + obtain ⟨hup, hdown⟩ := tendsto_bsd2_boundaryRatio_of_ne (a := r - q) hB hBpos hb hσ + have hpdf : Tendsto (fun y : ℝ ↦ gaussianPDFReal 0 1 (bsd2 (b / B (τ - τ * (1 + y) ^ 2 / 4)) + 1 (r - q) σ (τ * (1 + y) ^ 2 / 4))) (𝓝[>] (-1)) (𝓝 0) := by + rcases hne.lt_or_gt with h | h + · exact tendsto_gaussianPDFReal_zero_one_atBot.comp ((hdown h).comp + (tendsto_qdfpTimeChange hτ)) + · exact tendsto_gaussianPDFReal_zero_one_atTop.comp ((hup h).comp + (tendsto_qdfpTimeChange hτ)) + have := ((tendsto_exp_qdfpDiscount r hτ).const_mul (Real.sqrt τ / σ)).mul hpdf + rw [mul_zero] at this + exact this + +/-! ### Equation B at `u = τ` -/ + +theorem tendsto_exp_mul_nhdsLT (c τ : ℝ) : + Tendsto (fun u : ℝ ↦ Real.exp (c * u)) (𝓝[<] τ) (𝓝 (Real.exp (c * τ))) := + ((by fun_prop : Continuous fun u : ℝ ↦ Real.exp (c * u)).tendsto τ).mono_left + nhdsWithin_le_nhds + +/-- **Equation B, `nᵢ` at `u = τ`, on the diagonal.** -/ +theorem tendsto_qdfpNi_endpoint {B : ℝ → ℝ} {r q σ τ : ℝ} (hσ : 0 < σ) + (hB : DifferentiableAt ℝ B τ) (hBpos : 0 < B τ) : + Tendsto (qdfpNi B r q σ τ (B τ)) (𝓝[<] τ) (𝓝 (Real.exp (r * τ) / 2)) := by + have hd : Tendsto (fun u ↦ bsd2 (B τ / B u) 1 (r - q) σ (τ - u)) (𝓝[<] τ) (𝓝 0) := by + simpa [Function.comp_def, sub_sub_cancel] using + (tendsto_bsd2_boundaryRatio_of_eq (a := r - q) hB hBpos hσ).comp + (tendsto_sub_nhdsLT_nhdsGT_zero τ) + have := (tendsto_exp_mul_nhdsLT r τ).mul ((continuous_Phi.tendsto 0).comp hd) + rw [Phi_zero, ← div_eq_mul_one_div] at this + exact this + +/-- **Equation B, `dᵢ` at `u = τ`, on the diagonal.** -/ +theorem tendsto_qdfpDi_endpoint {B : ℝ → ℝ} {r q σ τ : ℝ} (hσ : 0 < σ) + (hB : DifferentiableAt ℝ B τ) (hBpos : 0 < B τ) : + Tendsto (qdfpDi B r q σ τ (B τ)) (𝓝[<] τ) (𝓝 (Real.exp (q * τ) / 2)) := by + have hd : Tendsto (fun u ↦ bsd1 (B τ / B u) 1 (r - q) σ (τ - u)) (𝓝[<] τ) (𝓝 0) := by + simpa [Function.comp_def, sub_sub_cancel] using + (tendsto_bsd1_boundaryRatio_of_eq (a := r - q) hB hBpos hσ).comp + (tendsto_sub_nhdsLT_nhdsGT_zero τ) + have := (tendsto_exp_mul_nhdsLT q τ).mul ((continuous_Phi.tendsto 0).comp hd) + rw [Phi_zero, ← div_eq_mul_one_div] at this + exact this + +/-- **Equation B, `nᵢ` at `u = τ`, off the diagonal.** The limit is `e^{rτ}` above the +boundary and `0` below it. -/ +theorem tendsto_qdfpNi_endpoint_ne {B : ℝ → ℝ} {r q σ τ b : ℝ} (hσ : 0 < σ) + (hB : ContinuousAt B τ) (hBpos : 0 < B τ) (hb : 0 < b) (hne : b ≠ B τ) : + Tendsto (qdfpNi B r q σ τ b) (𝓝[<] τ) + (𝓝 (if B τ < b then Real.exp (r * τ) else 0)) := by + obtain ⟨hup, hdown⟩ := tendsto_bsd2_boundaryRatio_of_ne (a := r - q) hB hBpos hb hσ + have hcomp := tendsto_sub_nhdsLT_nhdsGT_zero τ + split_ifs with h + · have hd : Tendsto (fun u ↦ bsd2 (b / B u) 1 (r - q) σ (τ - u)) (𝓝[<] τ) atTop := by + simpa [Function.comp_def, sub_sub_cancel] using (hup h).comp hcomp + have := (tendsto_exp_mul_nhdsLT r τ).mul (tendsto_Phi_atTop.comp hd) + rw [mul_one] at this + exact this + · have hd : Tendsto (fun u ↦ bsd2 (b / B u) 1 (r - q) σ (τ - u)) (𝓝[<] τ) atBot := by + simpa [Function.comp_def, sub_sub_cancel] using + (hdown (lt_of_le_of_ne (not_lt.mp h) hne)).comp hcomp + have := (tendsto_exp_mul_nhdsLT r τ).mul (tendsto_Phi_atBot.comp hd) + rw [mul_zero] at this + exact this + +/-- **Equation B, `dᵢ` at `u = τ`, off the diagonal.** -/ +theorem tendsto_qdfpDi_endpoint_ne {B : ℝ → ℝ} {r q σ τ b : ℝ} (hσ : 0 < σ) + (hB : ContinuousAt B τ) (hBpos : 0 < B τ) (hb : 0 < b) (hne : b ≠ B τ) : + Tendsto (qdfpDi B r q σ τ b) (𝓝[<] τ) + (𝓝 (if B τ < b then Real.exp (q * τ) else 0)) := by + obtain ⟨hup, hdown⟩ := tendsto_bsd1_boundaryRatio_of_ne (a := r - q) hB hBpos hb hσ + have hcomp := tendsto_sub_nhdsLT_nhdsGT_zero τ + split_ifs with h + · have hd : Tendsto (fun u ↦ bsd1 (b / B u) 1 (r - q) σ (τ - u)) (𝓝[<] τ) atTop := by + simpa [Function.comp_def, sub_sub_cancel] using (hup h).comp hcomp + have := (tendsto_exp_mul_nhdsLT q τ).mul (tendsto_Phi_atTop.comp hd) + rw [mul_one] at this + exact this + · have hd : Tendsto (fun u ↦ bsd1 (b / B u) 1 (r - q) σ (τ - u)) (𝓝[<] τ) atBot := by + simpa [Function.comp_def, sub_sub_cancel] using + (hdown (lt_of_le_of_ne (not_lt.mp h) hne)).comp hcomp + have := (tendsto_exp_mul_nhdsLT q τ).mul (tendsto_Phi_atBot.comp hd) + rw [mul_zero] at this + exact this + +/-! ### Continuity alone does not pin down the differentiable-case limit -/ + +/-- The boundary `B s = b e^{-c √(τ - s)}` used in `tendsto_qdfpK12_endpoint_holder` is +continuous. -/ +theorem continuous_qdfpHolderBoundary (b c τ : ℝ) : + Continuous fun s : ℝ ↦ b * Real.exp (-(c * Real.sqrt (τ - s))) := by + fun_prop + +/-- For the ½-Hölder boundary `B s = b e^{-c √(τ - s)}` (so `B τ = b`), the `K₁₂` endpoint +limit is `e^{qτ} (√τ/σ) φ(c/σ)`. -/ +theorem tendsto_qdfpK12_endpoint_holder {r q σ τ b c : ℝ} (hσ : 0 < σ) (hτ : 0 < τ) + (hb : 0 < b) : + Tendsto (qdfpK12 (fun s ↦ b * Real.exp (-(c * Real.sqrt (τ - s)))) r q σ τ b) (𝓝[>] (-1)) + (𝓝 (Real.exp (q * τ) * (Real.sqrt τ / σ) * gaussianPDFReal 0 1 (c / σ))) := by + have hcore : Tendsto (fun m ↦ bsd1 (b / (b * Real.exp (-(c * Real.sqrt (τ - (τ - m)))))) + 1 (r - q) σ m) (𝓝[>] 0) (𝓝 (c / σ)) := by + have hlim : Tendsto (fun m ↦ c / σ + (r - q + σ ^ 2 / 2) * (Real.sqrt m / σ)) (𝓝[>] 0) + (𝓝 (c / σ + (r - q + σ ^ 2 / 2) * (0 / σ))) := + tendsto_const_nhds.add ((tendsto_sqrt_nhdsGT_zero.div_const σ).const_mul _) + rw [zero_div, mul_zero, add_zero] at hlim + refine hlim.congr' ?_ + filter_upwards [self_mem_nhdsWithin] with m (hm : 0 < m) + obtain ⟨s, hs0, rfl⟩ : ∃ s, 0 < s ∧ m = s ^ 2 := + ⟨Real.sqrt m, Real.sqrt_pos.mpr hm, (Real.sq_sqrt hm.le).symm⟩ + rw [sub_sub_cancel, Real.sqrt_sq hs0.le, bsd1, div_one, div_mul_cancel_left₀ hb.ne', + ← Real.exp_neg, neg_neg, Real.log_exp, Real.sqrt_sq hs0.le] + field_simp + have hd := hcore.comp (tendsto_qdfpTimeChange hτ) + have := (tendsto_exp_qdfpDiscount q hτ).mul + (((tendsto_qdfpHalfJacobian τ).mul ((continuous_Phi.tendsto _).comp hd)).add + (((continuous_gaussianPDFReal 0 1).tendsto _).comp + hd |>.const_mul (Real.sqrt τ / σ))) + convert this using 2 <;> first | rfl | ring + +/-- **The endpoint value needs more than continuity.** For the continuous, ½-Hölder boundary +`B s = b e^{-c √(τ - s)}` with `c ≠ 0`, the `K₁₂` integrand on the diagonal `b = B τ` does +not tend to the value `e^{qτ} (√τ/σ)/√(2π)` of `tendsto_qdfpK12_endpoint`. -/ +theorem not_tendsto_qdfpK12_endpoint_holder {r q σ τ b c : ℝ} (hσ : 0 < σ) (hτ : 0 < τ) + (hb : 0 < b) (hc : c ≠ 0) : + ¬ Tendsto (qdfpK12 (fun s ↦ b * Real.exp (-(c * Real.sqrt (τ - s)))) r q σ τ b) (𝓝[>] (-1)) + (𝓝 (Real.exp (q * τ) * (Real.sqrt τ / σ) / Real.sqrt (2 * π))) := by + intro h + have heq := tendsto_nhds_unique (tendsto_qdfpK12_endpoint_holder (r := r) (c := c) hσ hτ hb) h + rw [div_eq_mul_one_div _ (Real.sqrt (2 * π)), ← gaussianPDFReal_zero_one_zero] at heq + have hpos : Real.exp (q * τ) * (Real.sqrt τ / σ) ≠ 0 := by + have := Real.sqrt_pos.mpr hτ + positivity + exact gaussianPDFReal_zero_one_ne_zero_point (div_ne_zero hc hσ.ne') + (mul_left_cancel₀ hpos heq) + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/American/JuZhongZeroRateLimit.lean b/LeanPool/MathFin/Models/BlackScholes/American/JuZhongZeroRateLimit.lean new file mode 100644 index 0000000000..53a29c2396 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/American/JuZhongZeroRateLimit.lean @@ -0,0 +1,470 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.DividendsGreeks +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionMixing +public import LeanPool.MathFin.Models.Rates.VasicekZeroMeanReversionLimit + +/-! +# The Ju–Zhong quadratic approximation at zero interest rate + +The Ju–Zhong (1999) modified quadratic approximation prices an American option as +`V_E(S) + hA·(S/S*)^{q_QD}/(1 − χ)` with `χ = x(bx + c)`, `x = log(S/S*)`, where `S*` is the +Barone-Adesi–Whaley critical price. Its coefficients involve `α = 2r/σ²`, `h = 1 − e^{−rT}`, +`α/h`, `q_QD′(h)`, `1/h` and `∂V_E/∂h`. At `r = 0` the ratio `α/h` is `0/0` and the last three +are `O(1/r)`, but they only ever enter multiplied by `α = O(r)`. QuantLib's limit-stable rewrite +of `juquadraticengine.cpp` (the fix for a NaN at `r = 0`) computes `ρ = α/h`, extended by +`ρ(0) = 2/(σ²T)`, together with `α·q_QD′` and `α·∂V_E/∂h`, and adds a put early exit +(`DR ≥ 1 ∧ DR ≥ DQ` ⇒ European price). The formulas here are transcribed from that file and +from the source equations; `φ = 1` is a call, `φ = −1` a put. + +## Main definitions + +* `juAlpha`, `juBeta`, `juH`: `α = 2r/σ²`, `N = 2(r − q)/σ²` and `h = 1 − e^{−rT}`. +* `juRho`: `ρ = α/h`, extended at `r = 0` by its limit `2/(σ²T)`. +* `juRoot`, `juLambda`: `√((N − 1)² + 4ρ)` and `q_QD = (−(N − 1) + φ√((N − 1)² + 4ρ))/2`, with + `φ = 1` for a call and `φ = −1` for a put. +* `juVE`: the European price `φ (S e^{−qT} Φ(φd₁) − K e^{−rT} Φ(φd₂))`; `juVE_one` and + `juVE_neg_one` identify it with `bsVDiv` and `bsPDiv`. +* `juHA`: `hA = φ (S* − K) − V_E(S*)`. +* `juValueRaw`: the pre-fix Ju–Zhong price on the continuation region, with `α/h` computed + directly; its coefficients are `juRootRaw`, `juLambdaRaw`, `juLambdaPrime`, `juVEhRaw`, + `juBRaw`, `juCRaw`, `juChiRaw`. +* `juValue`: the post-fix, limit-stable price `V_E(S) + hA (S/S*)^{q_QD} / (1 − χ)`; its + coefficients are `juAlphaLambdaPrime`, `juAlphaVEh`, `juB`, `juC`, `juChi`. + +## Main results + +* `tendsto_juAlpha_div_juH_zero_rate`, `continuousAt_juRho_zero` — the removable singularity + `α/h → 2/(σ²T)` as `r → 0` (two-sided). `α/h = (2/σ²)/vasicekBondB r T` + (`juAlpha_div_juH_eq`), and `vasicekBondB r T → T` + (`tendsto_vasicekBondB_zero_meanReversion`). +* `juValueRaw_eq_juValue` — the fix preserves semantics: for every `r ≠ 0` the pre-fix price + `juValueRaw` and the post-fix price `juValue` are equal, identically in `S*` and `S`. +* `tendsto_juValueRaw_zero_rate` — the headline, **conditional**: if `S*(r) → S*₀ > 0` as + `r → 0⁺`, `hA(0, S*₀) ≠ 0` and `1 − χ(0, S*₀, S) ≠ 0`, the pre-fix price tends to the + post-fix value at `r = 0`. The critical price and both nonvanishing conditions are + hypotheses. +* `put_intrinsic_le_parityBound` — the pointwise half of the put exit: under `DR ≥ 1`, + `DR ≥ DQ`, `0 < S ≤ K`, `K − S ≤ K·DR − S·DQ ≤ bsPDiv`. +* `bawPut_no_positive_root_zero_rate`, `bawPut_criticalPrice_eq_zero_zero_rate` — at `r = 0` + with `q ≥ 0` the BAW put critical-price equation (as transcribed here) has no root `S > 0`: + any `S* ≥ 0` solving it is `S* = 0`. This excludes a positive root of the `r = 0` equation; + it does not assert that `S* = 0` solves it, and it does not show that the limit of the + critical prices of the `r > 0` problems is such a root (that limit is not studied). +* `juVE_one`, `juVE_neg_one` — the European leg is `bsVDiv` / `bsPDiv`. + +## Scoped out + +* The BAW critical price as a function of `r`: existence, uniqueness and continuity of the + Newton fixed point are not formalized; `S*` is an input. +* The put limit `r → 0⁺` when `q ≥ 0`: the behaviour of the critical prices `S*(r)` and of + `hA` as `r → 0⁺`, and hence of the early-exercise premium, is not addressed. +* Any accuracy claim for the approximation, the derivation of its trial-solution ODE, and the + identification of `juVEhRaw` with `∂V_E/∂h`: these are transcribed, not derived. +* The statement that American and European puts agree when `r ≤ 0` and `r ≤ q` (optional + stopping). +* Floating point: QuantLib's `close(DR, 1, 1000)` switch is replaced by the exact branch + `r = 0`, and nothing is stated about the raw formula *at* `r = 0`, where Lean's `x/0 = 0` + makes it a junk value rather than NaN (so `juValueRaw_eq_juValue` compares two Lean + transcriptions for `r ≠ 0`, not QuantLib's code). + +## References + +* [N. Ju and R. Zhong, *An approximate formula for pricing American options*][JuZhong1999]. +* [G. Barone-Adesi and R. E. Whaley, *Efficient analytic approximation of American option + values*][BaroneAdesiWhaley1987] (the critical-price equation). +* [M. Li, *Analytical approximations for the critical stock prices of American options: a + performance comparison*][Li2009], §II.B, eqs. (27)–(34) with the notation of + eqs. (1)–(13). This restatement is the one used for the formulas here. +* [QuantLib, `ql/pricingengines/vanilla/juquadraticengine.cpp`][QuantLibJuQuadratic]. + +## Tags + +Ju–Zhong, quadratic approximation, American option approximation, Barone-Adesi–Whaley, +zero interest rate limit, MSC 91G20, MSC 35R35, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Filter Topology ProbabilityTheory + +/-! ### The closed-form scaffolding -/ + +/-- `M = 2r/σ²` (Li eq. (6); QuantLib's `alpha`). -/ +noncomputable def juAlpha (σ r : ℝ) : ℝ := 2 * r / σ ^ 2 + +/-- `N = 2(r − q)/σ²` (Li eq. (6); QuantLib's `beta`). -/ +noncomputable def juBeta (q σ r : ℝ) : ℝ := 2 * (r - q) / σ ^ 2 + +/-- `h = 1 − e^{−rT}` (QuantLib's `h = 1 − DR`). -/ +noncomputable def juH (T r : ℝ) : ℝ := 1 - Real.exp (-(r * T)) + +/-- QuantLib's `alphaOverH`: `ρ = α/h`, extended at `r = 0` by its limit `2/(σ²T)` +(`tendsto_juAlpha_div_juH_zero_rate`). QuantLib switches branches when `DR` is within +1000 ulps of 1; that floating-point switch is not modelled, the branch here is `r = 0`. -/ +noncomputable def juRho (σ T r : ℝ) : ℝ := + if r = 0 then 2 / (σ ^ 2 * T) else juAlpha σ r / juH T r + +/-- `√((N − 1)² + 4ρ)`, the square root in `q_QD` (Li eq. (10); QuantLib's `temp_root`). -/ +noncomputable def juRoot (q σ T r : ℝ) : ℝ := + Real.sqrt ((juBeta q σ r - 1) ^ 2 + 4 * juRho σ T r) + +/-- `q_QD = (−(N − 1) + φ·√((N − 1)² + 4ρ))/2` (Li eq. (10); QuantLib's `lambda`); +`φ = 1` for a call, `−1` for a put. -/ +noncomputable def juLambda (φ q σ T r : ℝ) : ℝ := + (-(juBeta q σ r - 1) + φ * juRoot q σ T r) / 2 + +/-- The pre-fix square root, with `α/h` computed directly (`0/0` at `r = 0`). -/ +noncomputable def juRootRaw (q σ T r : ℝ) : ℝ := + Real.sqrt ((juBeta q σ r - 1) ^ 2 + 4 * (juAlpha σ r / juH T r)) + +/-- The pre-fix `q_QD`, built on `juRootRaw`. -/ +noncomputable def juLambdaRaw (φ q σ T r : ℝ) : ℝ := + (-(juBeta q σ r - 1) + φ * juRootRaw q σ T r) / 2 + +/-- `q_QD′(h) = −φM/(h²√((N − 1)² + 4M/h))` (Li eq. (33); QuantLib's `lambda_prime`), +`O(1/r)` as `r → 0`. -/ +noncomputable def juLambdaPrime (φ q σ T r : ℝ) : ℝ := + -(φ * juAlpha σ r) / (juH T r ^ 2 * juRootRaw q σ T r) + +/-- The forward at the critical price, `F* = S*·DQ/DR` (QuantLib's `forwardSk`). -/ +noncomputable def juFwd (q T r Sk : ℝ) : ℝ := + Sk * Real.exp (-(q * T)) / Real.exp (-(r * T)) + +/-- The European price `V_E(S) = φ·(S·DQ·Φ(φd₁) − K·DR·Φ(φd₂))`, `d₁ = bsd1 S K (r − q) σ T` +(QuantLib's `blackFormula(…)·DR`). `juVE_one` and `juVE_neg_one` identify it with `bsVDiv` +and `bsPDiv`. -/ +noncomputable def juVE (φ K q σ T r S : ℝ) : ℝ := + φ * (S * Real.exp (-(q * T)) * Phi (φ * bsd1 S K (r - q) σ T) + - K * Real.exp (-(r * T)) * Phi (φ * bsd2 S K (r - q) σ T)) + +/-- `hA = φ(S* − K) − V_E(S*)` (QuantLib's `hA`). -/ +noncomputable def juHA (φ K q σ T r Sk : ℝ) : ℝ := + φ * (Sk - K) - juVE φ K q σ T r Sk + +/-- The pre-fix `V_E_h = ∂V_E/∂h` at `S*` (QuantLib's `part1 + part2 + part3`), with +`part1 = F*·n(d₁)/(α√(σ²T))` and `part2 = −φF*Φ(φd₁)·log DQ/log DR`; both are `O(1/r)`. -/ +noncomputable def juVEhRaw (φ K q σ T r Sk : ℝ) : ℝ := + juFwd q T r Sk * gaussianPDFReal 0 1 (bsd1 Sk K (r - q) σ T) + / (juAlpha σ r * Real.sqrt (σ ^ 2 * T)) + - φ * juFwd q T r Sk * Phi (φ * bsd1 Sk K (r - q) σ T) * Real.log (Real.exp (-(q * T))) + / Real.log (Real.exp (-(r * T))) + + φ * K * Phi (φ * bsd2 Sk K (r - q) σ T) + +/-- The pre-fix `b = (1 − h)·M·q_QD′/(2(2q_QD + N − 1))` (Li eq. (30)). -/ +noncomputable def juBRaw (φ q σ T r : ℝ) : ℝ := + (1 - juH T r) * juAlpha σ r * juLambdaPrime φ q σ T r + / (2 * (2 * juLambdaRaw φ q σ T r + juBeta q σ r - 1)) + +/-- The pre-fix `c = −(1 − h)M/(2q_QD + N − 1)·[V_E_h/hA + 1/h + q_QD′/(2q_QD + N − 1)]` +(Li eq. (32), `c₀`, with QuantLib's `V_E_h/hA` in place of Li's Θ-term). -/ +noncomputable def juCRaw (φ K q σ T r Sk : ℝ) : ℝ := + -((1 - juH T r) * juAlpha σ r / (2 * juLambdaRaw φ q σ T r + juBeta q σ r - 1)) + * (juVEhRaw φ K q σ T r Sk / juHA φ K q σ T r Sk + 1 / juH T r + + juLambdaPrime φ q σ T r / (2 * juLambdaRaw φ q σ T r + juBeta q σ r - 1)) + +/-- The pre-fix `χ = x(bx + c)`, `x = log(S/S*)`. -/ +noncomputable def juChiRaw (φ K q σ T r Sk S : ℝ) : ℝ := + Real.log (S / Sk) * (juBRaw φ q σ T r * Real.log (S / Sk) + juCRaw φ K q σ T r Sk) + +/-- The pre-fix Ju–Zhong price on the continuation region (Li eq. (29)): +`V_E(S) + hA·(S/S*)^{q_QD}/(1 − χ)`. -/ +noncomputable def juValueRaw (φ K q σ T r Sk S : ℝ) : ℝ := + juVE φ K q σ T r S + + juHA φ K q σ T r Sk * (S / Sk) ^ juLambdaRaw φ q σ T r / (1 - juChiRaw φ K q σ T r Sk S) + +/-- The post-fix `α·λ′ = −φρ²/√((N − 1)² + 4ρ)`. -/ +noncomputable def juAlphaLambdaPrime (φ q σ T r : ℝ) : ℝ := + -(φ * juRho σ T r ^ 2) / juRoot q σ T r + +/-- The post-fix `α·V_E_h = F*n(d₁)/√(σ²T) + 2φF*Φ(φd₁)·log DQ/(σ²T) + φαKΦ(φd₂)`. -/ +noncomputable def juAlphaVEh (φ K q σ T r Sk : ℝ) : ℝ := + juFwd q T r Sk * gaussianPDFReal 0 1 (bsd1 Sk K (r - q) σ T) / Real.sqrt (σ ^ 2 * T) + + 2 * φ * juFwd q T r Sk * Phi (φ * bsd1 Sk K (r - q) σ T) * Real.log (Real.exp (-(q * T))) + / (σ ^ 2 * T) + + φ * juAlpha σ r * K * Phi (φ * bsd2 Sk K (r - q) σ T) + +/-- The post-fix `b = (1 − h)·(αλ′)/(2(2λ + N − 1))`. -/ +noncomputable def juB (φ q σ T r : ℝ) : ℝ := + (1 - juH T r) * juAlphaLambdaPrime φ q σ T r + / (2 * (2 * juLambda φ q σ T r + juBeta q σ r - 1)) + +/-- The post-fix `c = −(1 − h)/(2λ + N − 1)·[αV_E_h/hA + ρ + αλ′/(2λ + N − 1)]`. -/ +noncomputable def juC (φ K q σ T r Sk : ℝ) : ℝ := + -((1 - juH T r) / (2 * juLambda φ q σ T r + juBeta q σ r - 1)) + * (juAlphaVEh φ K q σ T r Sk / juHA φ K q σ T r Sk + juRho σ T r + + juAlphaLambdaPrime φ q σ T r / (2 * juLambda φ q σ T r + juBeta q σ r - 1)) + +/-- The post-fix `χ = x(bx + c)`, `x = log(S/S*)`. -/ +noncomputable def juChi (φ K q σ T r Sk S : ℝ) : ℝ := + Real.log (S / Sk) * (juB φ q σ T r * Real.log (S / Sk) + juC φ K q σ T r Sk) + +/-- The post-fix Ju–Zhong price on the continuation region. -/ +noncomputable def juValue (φ K q σ T r Sk S : ℝ) : ℝ := + juVE φ K q σ T r S + + juHA φ K q σ T r Sk * (S / Sk) ^ juLambda φ q σ T r / (1 - juChi φ K q σ T r Sk S) + +/-! ### The removable singularity `α/h → 2/(σ²T)` -/ + +/-- `α/h = (2/σ²)/B(r, T)`, the Vasicek bond coefficient at speed `r`. -/ +lemma juAlpha_div_juH_eq (σ T r : ℝ) (hr : r ≠ 0) : + juAlpha σ r / juH T r = 2 / σ ^ 2 / vasicekBondB r T := by + rw [juAlpha, juH, vasicekBondB] + field_simp + +/-- **The removable singularity** (QuantLib's `alphaOverH` limit): `α/h → 2/(σ²T)` as +`r → 0`, from either side. -/ +theorem tendsto_juAlpha_div_juH_zero_rate {σ T : ℝ} (hT : T ≠ 0) : + Tendsto (fun r ↦ juAlpha σ r / juH T r) (𝓝[≠] 0) (𝓝 (2 / (σ ^ 2 * T))) := by + have := (tendsto_const_nhds (x := 2 / σ ^ 2)).div + (tendsto_vasicekBondB_zero_meanReversion T) hT + rw [div_div] at this + refine this.congr' ?_ + filter_upwards [self_mem_nhdsWithin] with r hr + exact (juAlpha_div_juH_eq σ T r hr).symm + +/-- `ρ` is continuous at `r = 0`: the extension `ρ(0) = 2/(σ²T)` is the limit. -/ +theorem continuousAt_juRho_zero {σ T : ℝ} (hT : T ≠ 0) : ContinuousAt (juRho σ T) 0 := by + rw [← continuousWithinAt_compl_self, ContinuousWithinAt, juRho, ite_eq_left rfl] + refine (tendsto_juAlpha_div_juH_zero_rate hT).congr' ?_ + filter_upwards [self_mem_nhdsWithin] with r (hr : r ≠ 0) + rw [juRho, ite_eq_right hr] + +/-! ### The fix preserves semantics: raw = stable for `r ≠ 0` -/ + +lemma juRootRaw_eq (q σ T : ℝ) {r : ℝ} (hr : r ≠ 0) : juRootRaw q σ T r = juRoot q σ T r := by + rw [juRootRaw, juRoot, juRho, ite_eq_right hr] + +lemma juLambdaRaw_eq (φ q σ T : ℝ) {r : ℝ} (hr : r ≠ 0) : + juLambdaRaw φ q σ T r = juLambda φ q σ T r := by + rw [juLambdaRaw, juLambda, juRootRaw_eq q σ T hr] + +/-- `α·λ′ = −φρ²/√((N − 1)² + 4ρ)`: the `O(1/r)` factor `λ′` times `α = O(r)`. -/ +lemma juAlpha_mul_juLambdaPrime (φ q σ T : ℝ) {r : ℝ} (hr : r ≠ 0) : + juAlpha σ r * juLambdaPrime φ q σ T r = juAlphaLambdaPrime φ q σ T r := by + rw [juLambdaPrime, juAlphaLambdaPrime, juRootRaw_eq q σ T hr, juRho, ite_eq_right hr] + ring + +/-- `α·V_E_h` in the stable form: `α·part1` cancels the `1/α`, and `α/log DR = −2/(σ²T)`. -/ +lemma juAlpha_mul_juVEhRaw (φ K q : ℝ) {σ T r : ℝ} (hσ : σ ≠ 0) (hT : T ≠ 0) (hr : r ≠ 0) + (Sk : ℝ) : juAlpha σ r * juVEhRaw φ K q σ T r Sk = juAlphaVEh φ K q σ T r Sk := by + rw [juVEhRaw, juAlphaVEh, Real.log_exp (-(r * T)), juAlpha] + field_simp + ring + +lemma juBRaw_eq (φ q σ T : ℝ) {r : ℝ} (hr : r ≠ 0) : juBRaw φ q σ T r = juB φ q σ T r := by + rw [juBRaw, juB, juLambdaRaw_eq φ q σ T hr, ← juAlpha_mul_juLambdaPrime φ q σ T hr] + ring + +lemma juCRaw_eq (φ K q : ℝ) {σ T r : ℝ} (hσ : σ ≠ 0) (hT : T ≠ 0) (hr : r ≠ 0) (Sk : ℝ) : + juCRaw φ K q σ T r Sk = juC φ K q σ T r Sk := by + rw [juCRaw, juC, juLambdaRaw_eq φ q σ T hr, ← juAlpha_mul_juLambdaPrime φ q σ T hr, + ← juAlpha_mul_juVEhRaw φ K q hσ hT hr, juRho, ite_eq_right hr] + ring + +/-- **The fix preserves semantics.** For every `σ ≠ 0`, `T ≠ 0` and `r ≠ 0` the post-fix +(limit-stable) Ju–Zhong price equals the pre-fix one, identically in `S*` and `S`. Pure +algebra: `α·(X/hA) = (αX)/hA` holds in Lean even when `hA = 0`, so no hypothesis on `hA` or +`1 − χ` is needed. This is an identity between the two Lean transcriptions `juValueRaw` and +`juValue`; it is not tied to an American option price or to QuantLib's code. -/ +theorem juValueRaw_eq_juValue (φ K q : ℝ) {σ T r : ℝ} (hσ : σ ≠ 0) (hT : T ≠ 0) (hr : r ≠ 0) + (Sk S : ℝ) : juValueRaw φ K q σ T r Sk S = juValue φ K q σ T r Sk S := by + rw [juValueRaw, juValue, juChiRaw, juChi, juBRaw_eq φ q σ T hr, juCRaw_eq φ K q hσ hT hr, + juLambdaRaw_eq φ q σ T hr] + +/-! ### Continuity of the stable form at `r = 0`, and the headline limit -/ + +/-- `2q_QD + N − 1 = φ·√((N − 1)² + 4ρ)`: the denominator of `b` and `c` vanishes only with the +root. -/ +lemma two_mul_juLambda_add_juBeta_sub_one (φ q σ T r : ℝ) : + 2 * juLambda φ q σ T r + juBeta q σ r - 1 = φ * juRoot q σ T r := by + rw [juLambda]; ring + +lemma juRoot_zero_pos (q : ℝ) {σ T : ℝ} (hσ : 0 < σ) (hT : 0 < T) : 0 < juRoot q σ T 0 := by + rw [juRoot, juRho, ite_eq_left rfl] + exact Real.sqrt_pos.2 (by positivity) + +/-- **Headline: the pre-fix price tends to the post-fix price at `r = 0`** — conditionally. +Let `S*(r)` be *any* critical-price function with `S*(r) → S*₀ > 0` as `r → 0⁺`. If the two +side conditions `hA(0, S*₀) ≠ 0` and `1 − χ(0, S*₀, S) ≠ 0` hold, the pre-fix Ju–Zhong price +`juValueRaw` along `(r, S*(r))` tends to the post-fix value `juValue` at `(0, S*₀)`. + +The critical price is a black box: its existence, uniqueness and continuity in `r` (the BAW +Newton fixed point) are hypotheses here, not derived. The two nonvanishing conditions are +hypotheses as well. `bawPut_no_positive_root_zero_rate` excludes a positive root of the `r = 0` +put critical-price equation for `q ≥ 0`; whether the limit `S*₀` of the critical prices of the +`r > 0` problems is such a root is not proved here. -/ +theorem tendsto_juValueRaw_zero_rate {φ K q σ T S S₀ : ℝ} {Sk : ℝ → ℝ} + (hφ : φ = 1 ∨ φ = -1) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (hS : 0 < S) + (hSk : Tendsto Sk (𝓝[>] 0) (𝓝 S₀)) (hS₀ : 0 < S₀) + (hA₀ : juHA φ K q σ T 0 S₀ ≠ 0) (hχ₀ : 1 - juChi φ K q σ T 0 S₀ S ≠ 0) : + Tendsto (fun r ↦ juValueRaw φ K q σ T r (Sk r) S) (𝓝[>] 0) + (𝓝 (juValue φ K q σ T 0 S₀ S)) := by + set L : Filter ℝ := 𝓝[>] 0 + have hφ0 : φ ≠ 0 := by rcases hφ with h | h <;> simp [h] + refine Tendsto.congr' ?_ (show Tendsto (fun r ↦ juValue φ K q σ T r (Sk r) S) L _ from ?_) + · filter_upwards [self_mem_nhdsWithin] with r (hr : 0 < r) + exact (juValueRaw_eq_juValue φ K q hσ.ne' hT.ne' hr.ne' _ _).symm + have hr : Tendsto (fun r : ℝ ↦ r) L (𝓝 0) := tendsto_id.mono_left nhdsWithin_le_nhds + have hcont : ∀ f : ℝ → ℝ, ContinuousAt f 0 → Tendsto f L (𝓝 (f 0)) := + fun f hf ↦ hf.tendsto.mono_left nhdsWithin_le_nhds + have hα := hcont (juAlpha σ) (by unfold juAlpha; fun_prop) + have hβ := hcont (juBeta q σ) (by unfold juBeta; fun_prop) + have hh := hcont (juH T) (by unfold juH; fun_prop) + have hρ := hcont (juRho σ T) (continuousAt_juRho_zero hT.ne') + have hroot0 := juRoot_zero_pos q hσ hT + have hroot : Tendsto (fun r ↦ juRoot q σ T r) L (𝓝 (juRoot q σ T 0)) := by + simp only [juRoot]; exact (((hβ.sub_const 1).pow 2).add (hρ.const_mul 4)).sqrt + have hlam : Tendsto (fun r ↦ juLambda φ q σ T r) L (𝓝 (juLambda φ q σ T 0)) := by + simp only [juLambda]; exact ((hβ.sub_const 1).neg.add (hroot.const_mul φ)).div_const 2 + have hD0 : 2 * juLambda φ q σ T 0 + juBeta q σ 0 - 1 ≠ 0 := by + rw [two_mul_juLambda_add_juBeta_sub_one]; exact mul_ne_zero hφ0 hroot0.ne' + have hD := ((hlam.const_mul 2).add hβ).sub_const 1 + have hd1 : ∀ {s : ℝ → ℝ} {s₀ : ℝ}, Tendsto s L (𝓝 s₀) → 0 < s₀ → + Tendsto (fun r ↦ bsd1 (s r) K (r - q) σ T) L (𝓝 (bsd1 s₀ K (0 - q) σ T)) := by + intro s s₀ hs hs₀ + simp only [bsd1] + exact (((hs.div_const K).log (by positivity)).add + (((hr.sub_const q).add_const _).mul_const T)).div_const _ + have hd2 : ∀ {s : ℝ → ℝ} {s₀ : ℝ}, Tendsto s L (𝓝 s₀) → 0 < s₀ → + Tendsto (fun r ↦ bsd2 (s r) K (r - q) σ T) L (𝓝 (bsd2 s₀ K (0 - q) σ T)) := + fun hs hs₀ ↦ (hd1 hs hs₀).sub_const _ + have hΦ : ∀ {f : ℝ → ℝ} {x : ℝ}, Tendsto f L (𝓝 x) → + Tendsto (fun r ↦ Phi (φ * f r)) L (𝓝 (Phi (φ * x))) := + fun hf ↦ (continuous_Phi.tendsto _).comp (hf.const_mul φ) + have hDR := (hr.mul_const T).neg.rexp + have hVE : ∀ {s : ℝ → ℝ} {s₀ : ℝ}, Tendsto s L (𝓝 s₀) → 0 < s₀ → + Tendsto (fun r ↦ juVE φ K q σ T r (s r)) L (𝓝 (juVE φ K q σ T 0 s₀)) := by + intro s s₀ hs hs₀ + simp only [juVE] + exact (((hs.mul_const _).mul (hΦ (hd1 hs hs₀))).sub + ((tendsto_const_nhds.mul hDR).mul (hΦ (hd2 hs hs₀)))).const_mul φ + have hHA : Tendsto (fun r ↦ juHA φ K q σ T r (Sk r)) L (𝓝 (juHA φ K q σ T 0 S₀)) := by + simp only [juHA]; exact ((hSk.sub_const K).const_mul φ).sub (hVE hSk hS₀) + have hF : Tendsto (fun r ↦ juFwd q T r (Sk r)) L (𝓝 (juFwd q T 0 S₀)) := by + simp only [juFwd]; exact (hSk.mul_const _).div hDR (Real.exp_pos _).ne' + have hαVEh : Tendsto (fun r ↦ juAlphaVEh φ K q σ T r (Sk r)) L + (𝓝 (juAlphaVEh φ K q σ T 0 S₀)) := by + simp only [juAlphaVEh] + exact (((hF.mul (((continuous_gaussianPDFReal 0 1).tendsto _).comp + (hd1 hSk hS₀))).div_const _).add + ((((hF.const_mul (2 * φ)).mul (hΦ (hd1 hSk hS₀))).mul_const _).div_const _)).add + (((hα.const_mul φ).mul_const K).mul (hΦ (hd2 hSk hS₀))) + have hαlp : Tendsto (fun r ↦ juAlphaLambdaPrime φ q σ T r) L + (𝓝 (juAlphaLambdaPrime φ q σ T 0)) := by + simp only [juAlphaLambdaPrime]; exact ((hρ.pow 2).const_mul φ).neg.div hroot hroot0.ne' + have hB : Tendsto (fun r ↦ juB φ q σ T r) L (𝓝 (juB φ q σ T 0)) := by + simp only [juB] + exact ((tendsto_const_nhds.sub hh).mul hαlp).div (hD.const_mul 2) + (mul_ne_zero two_ne_zero hD0) + have hC : Tendsto (fun r ↦ juC φ K q σ T r (Sk r)) L (𝓝 (juC φ K q σ T 0 S₀)) := by + simp only [juC] + exact ((tendsto_const_nhds.sub hh).div hD hD0).neg.mul + (((hαVEh.div hHA hA₀).add hρ).add (hαlp.div hD hD0)) + have hratio : Tendsto (fun r ↦ S / Sk r) L (𝓝 (S / S₀)) := + tendsto_const_nhds.div hSk hS₀.ne' + have hx := hratio.log (by positivity) + have hχ : Tendsto (fun r ↦ juChi φ K q σ T r (Sk r) S) L (𝓝 (juChi φ K q σ T 0 S₀ S)) := by + simp only [juChi]; exact hx.mul ((hB.mul hx).add hC) + simp only [juValue] + exact (hVE tendsto_const_nhds hS).add ((hHA.mul (hratio.rpow hlam (Or.inl (by positivity)))).div + (tendsto_const_nhds.sub hχ) hχ₀) + +/-! ### `V_E` is the Black–Scholes–Merton price -/ + +/-- The call (`φ = 1`) European price is `bsVDiv`. -/ +lemma juVE_one (K q σ T r S : ℝ) : juVE 1 K q σ T r S = bsVDiv K r q σ S T := by + have hd : Real.exp (-(q * T)) * Real.exp (-((r - q) * T)) = Real.exp (-(r * T)) := by + rw [← Real.exp_add]; ring_nf + rw [juVE, bsVDiv, bsV, ← hd] + ring_nf + +/-- The put (`φ = −1`) European price is `bsPDiv`. -/ +lemma juVE_neg_one (K q σ T r S : ℝ) : juVE (-1) K q σ T r S = bsPDiv K r q σ S T := by + have hd : Real.exp (-(q * T)) * Real.exp (-((r - q) * T)) = Real.exp (-(r * T)) := by + rw [← Real.exp_add]; ring_nf + rw [juVE, bsPDiv, bsP, ← hd] + simp only [neg_one_mul] + ring + +/-! ### The put side at `r = 0` -/ + +/-- **The pointwise half of the put "no early exercise" exit.** If `DR = e^{−rT} ≥ 1` and +`DR ≥ DQ = e^{−qT}`, then for `0 < S ≤ K` the intrinsic value is below the parity bound +`K·DR − S·DQ`, which is below the European put `bsPDiv`. This is the inequality behind +QuantLib's comment in `juquadraticengine.cpp` that holding is worth at least `K·DR − S·DQ`; +the optional-stopping half (American = European) is not formalized. -/ +theorem put_intrinsic_le_parityBound {K r q σ S T : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) + (hS : 0 < S) (hSK : S ≤ K) (hDR : 1 ≤ Real.exp (-(r * T))) + (hDRQ : Real.exp (-(q * T)) ≤ Real.exp (-(r * T))) : + K - S ≤ K * Real.exp (-(r * T)) - S * Real.exp (-(q * T)) ∧ + K * Real.exp (-(r * T)) - S * Real.exp (-(q * T)) ≤ bsPDiv K r q σ S T := by + refine ⟨?_, ?_⟩ + · rcases le_or_gt (Real.exp (-(q * T))) 1 with h | h <;> nlinarith + · have := mul_nonneg (Real.exp_pos (-(q * T))).le (bsV_nonneg_of_pos hS hK hσ hT (r := r - q)) + rw [bsPDiv_eq_bsVDiv, bsVDiv] + linarith + +/-- At `r = 0` the put's `q_QD` (`φ = −1`) is negative, whatever `q`. -/ +lemma juLambda_neg_one_zero_neg (q : ℝ) {σ T : ℝ} (hσ : 0 < σ) (hT : 0 < T) : + juLambda (-1) q σ T 0 < 0 := by + have h4 : 0 < 4 * juRho σ T 0 := by rw [juRho, ite_eq_left rfl]; positivity + have : -(juBeta q σ 0 - 1) < juRoot q σ T 0 := by + calc -(juBeta q σ 0 - 1) ≤ |juBeta q σ 0 - 1| := neg_le_abs _ + _ = Real.sqrt ((juBeta q σ 0 - 1) ^ 2) := (Real.sqrt_sq_eq_abs _).symm + _ < juRoot q σ T 0 := Real.sqrt_lt_sqrt (sq_nonneg _) (by linarith) + rw [juLambda] + linarith + +/-- **At `r = 0` with `q ≥ 0`, the BAW put critical-price equation has no positive root.** +The equation (Li eq. (9), with `q_QD` at its `r = 0` value `juLambda (-1) q σ T 0`) is +`K − S − p(S) = −S(1 − e^{−qT}Φ(−d₁(S)))/q_QD`. Its left side is `≤ 0` (parity at `r = 0` and +a nonnegative call give `p(S) ≥ K − S·e^{−qT} ≥ K − S`); its right side is `> 0` +(`q_QD < 0` and `1 − e^{−qT}Φ(−d₁) ≥ Φ(d₁) > 0`). This excludes a positive root; it does not +establish that `S = 0` itself solves the equation or that `hA = 0` there. -/ +theorem bawPut_no_positive_root_zero_rate {K q σ T S : ℝ} (hK : 0 < K) (hσ : 0 < σ) + (hT : 0 < T) (hq : 0 ≤ q) (hS : 0 < S) : + K - S - bsPDiv K 0 q σ S T ≠ + -S * (1 - Real.exp (-(q * T)) * Phi (-bsd1 S K (0 - q) σ T)) / juLambda (-1) q σ T 0 := by + have hDQ : Real.exp (-(q * T)) ≤ 1 := Real.exp_le_one_iff.2 (by nlinarith) + have hlhs : K - S - bsPDiv K 0 q σ S T ≤ 0 := by + have := mul_nonneg (Real.exp_pos (-(q * T))).le + (bsV_nonneg_of_pos hS hK hσ hT (r := 0 - q)) + rw [bsPDiv_eq_bsVDiv, bsVDiv] + simp only [zero_mul, neg_zero, Real.exp_zero, mul_one] + nlinarith + have hΦ : 0 < Phi (bsd1 S K (0 - q) σ T) := by positivity + have hnum : 0 < 1 - Real.exp (-(q * T)) * Phi (-bsd1 S K (0 - q) σ T) := by + have h0 := Phi_nonneg (-bsd1 S K (0 - q) σ T) + rw [Phi_neg] at h0 ⊢ + nlinarith + have hrhs : 0 < -S * (1 - Real.exp (-(q * T)) * Phi (-bsd1 S K (0 - q) σ T)) / + juLambda (-1) q σ T 0 := + div_pos_of_neg_of_neg (by nlinarith) (juLambda_neg_one_zero_neg q hσ hT) + intro h + linarith + +/-- **Corollary: a positive put critical price at `r = 0`, `q ≥ 0` is excluded.** Any `S* ≥ 0` +solving the BAW put equation is `S* = 0` — this excludes a positive root, not asserts that +`S* = 0` itself solves the equation. Whether the limit of the critical prices of the `r > 0` +problems is such a root is not proved, so this does not by itself refute the hypothesis +`0 < S*₀` of `tendsto_juValueRaw_zero_rate` for such puts. -/ +theorem bawPut_criticalPrice_eq_zero_zero_rate {K q σ T Sstar : ℝ} (hK : 0 < K) (hσ : 0 < σ) + (hT : 0 < T) (hq : 0 ≤ q) (hSstar : 0 ≤ Sstar) + (heq : K - Sstar - bsPDiv K 0 q σ Sstar T = + -Sstar * (1 - Real.exp (-(q * T)) * Phi (-bsd1 Sstar K (0 - q) σ T)) / + juLambda (-1) q σ T 0) : + Sstar = 0 := + hSstar.eq_or_lt.elim Eq.symm fun h ↦ + absurd heq (bawPut_no_positive_root_zero_rate hK hσ hT hq h) + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/American/Stopping/PlanePartial.lean b/LeanPool/MathFin/Models/BlackScholes/American/Stopping/PlanePartial.lean new file mode 100644 index 0000000000..03f5ddfda6 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/American/Stopping/PlanePartial.lean @@ -0,0 +1,77 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.Calculus.Deriv.Prod +public import Mathlib.Order.CompletePartialOrder +public import Mathlib.Analysis.Calculus.ContDiff.Comp +public import Mathlib.Analysis.Calculus.Deriv.Comp +public import Mathlib.Analysis.InnerProductSpace.Basic +public import Mathlib.Topology.Algebra.Module.ModuleTopology + +/-! +# Directional derivatives of plane functions + +The directional derivative `planePartial G v z = fderiv ℝ G z v` of a function on the `(t, x)` +plane, with its smoothness and its reading as the ordinary time and space derivatives. Shared by +the heat-boundary equation (`HeatBoundaryEquation`) and Itô's formula for plane functions +(`PlaneIto`). + +## Main definitions + +* `planePartial`: the directional derivative `fderiv ℝ G z v` of a plane function `G` at `z` along + `v`. + +## Main results + +* `planePartial_contDiff`: if `G` is `C^(n+1)`, each directional derivative `planePartial G v` + is `C^n`. +* `planePartial_smoothAt`: if `G` is `C^∞` at `z`, so is `planePartial G v`. +* `planePartial_hasDeriv_time`, `planePartial_hasDeriv_space`: if `G` is differentiable at + `(t,w)`, its partial in the direction `(1,0)` (resp. `(0,1)`) is the ordinary derivative of + `s ↦ G (s,w)` (resp. `y ↦ G (t,y)`). + +## Tags + +directional derivative, partial derivatives, plane function, space-time derivative, +Fréchet derivative, MSC 35R35, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin.BlackScholes.AmericanPut.Stopping + +open scoped ContDiff + +/-- The directional derivative `fderiv ℝ G z v` of a plane function `G` at `z` along `v`. -/ +noncomputable def planePartial (G : ℝ × ℝ → ℝ) (v : ℝ × ℝ) (z : ℝ × ℝ) : ℝ := + fderiv ℝ G z v + +theorem planePartial_contDiff {G : ℝ × ℝ → ℝ} {n : ℕ} (hG : ContDiff ℝ (n + 1) G) + (v : ℝ × ℝ) : ContDiff ℝ n (planePartial G v) := + (hG.fderiv_right (m := n) (by norm_cast)).clm_apply contDiff_const + +theorem planePartial_smoothAt {G : ℝ × ℝ → ℝ} {z : ℝ × ℝ} + (hG : ContDiffAt ℝ ∞ G z) (v : ℝ × ℝ) : + ContDiffAt ℝ ∞ (planePartial G v) z := + (hG.fderiv_right (by simp)).clm_apply contDiffAt_const + +theorem planePartial_hasDeriv_time {G : ℝ × ℝ → ℝ} {t w : ℝ} + (hG : DifferentiableAt ℝ G (t, w)) : + HasDerivAt (fun s => G (s,w)) (planePartial G (1,0) (t,w)) t := by + simpa only [Function.comp_def,id_eq,planePartial] using hG.hasFDerivAt.comp_hasDerivAt t + ((hasDerivAt_id t).prodMk (hasDerivAt_const t w)) + +theorem planePartial_hasDeriv_space {G : ℝ × ℝ → ℝ} {t w : ℝ} + (hG : DifferentiableAt ℝ G (t, w)) : + HasDerivAt (fun y => G (t,y)) (planePartial G (0,1) (t,w)) w := by + simpa only [Function.comp_def,id_eq,planePartial] using hG.hasFDerivAt.comp_hasDerivAt w + ((hasDerivAt_const w t).prodMk (hasDerivAt_id w)) + +end MathFin.BlackScholes.AmericanPut.Stopping diff --git a/LeanPool/MathFin/Models/BlackScholes/AsianGeometric.lean b/LeanPool/MathFin/Models/BlackScholes/AsianGeometric.lean new file mode 100644 index 0000000000..5fd88ce06f --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/AsianGeometric.lean @@ -0,0 +1,67 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.AsianGeometricN + +/-! +# The geometric-average Asian option: the two-date effective variance + +`Models/BlackScholes/AsianInequality.lean` bounds the geometric-average Asian payoff above by the +arithmetic one (AM–GM). This file supplies the distributional content that turns the +geometric average into a *priceable* lognormal: for a Black–Scholes GBM +`S_u = S₀·exp((r − σ²/2)u + σ B_u)` sampled at two dates `s ≤ t`, the geometric average +`√(S_s·S_t)` is lognormal, because its log-driver — the **average of the Brownian values** +`(B_s + B_t)/2` — is Gaussian with the covariance-sum variance + + `Var((B_s + B_t)/2) = (s + 2·min(s,t) + t)/4 = (3s + t)/4` (for `s ≤ t`). + +The law is the two-date case of the `n`-date driver `geomAsianN_driver_hasLaw` +(`Models/BlackScholes/AsianGeometricN.lean`), which reads the average of Brownian values as a Wiener +integral of a step kernel; here the dates are `![s, t]` and the covariance sum is `3s + t`. + +## Main results + +* `asianGeom_driver_hasLaw` — `(B_s + B_t)/2 ~ N(0, (3s+t)/4)` for `s ≤ t`. + +## Tags + +geometric Asian option, average price option, Wiener integral, lognormal, Gaussian average, +effective variance, MSC 91G20, MSC 60J65, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real Set +open scoped NNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-- **The two-date geometric-Asian log-driver is Gaussian.** For a pre-Brownian motion `B` +and sampling dates `s ≤ t ≤ T`, the average of the Brownian values `(B_s + B_t)/2` — the +Gaussian part of the log geometric average `log √(S_s·S_t)` — has the centred Gaussian law +`N(0, (3s+t)/4)`, the variance coming from the Brownian covariance `∫ B_s·B_t = min(s,t)`. -/ +theorem asianGeom_driver_hasLaw (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + {s t : ℝ≥0} (hst : s ≤ t) (hsT : s ≤ T) (htT : t ≤ T) : + HasLaw (fun ω ↦ (B s ω + B t ω) / 2) + (gaussianReal 0 ((3 * (s : ℝ) + t) / 4).toNNReal) μ := by + have h := geomAsianN_driver_hasLaw hB T (n := 2) two_pos ![s, t] + (fun i ↦ by fin_cases i <;> simpa) + have hst' : (s : ℝ) ≤ t := hst + have hf : (fun ω ↦ (∑ i, B (![s, t] i) ω) / ((2 : ℕ) : ℝ)) = fun ω ↦ (B s ω + B t ω) / 2 := by + funext ω; simp [Fin.sum_univ_two] + have hv : (∑ i, ∑ j, min ((![s, t] i : ℝ≥0) : ℝ) ((![s, t] j : ℝ≥0) : ℝ)) / ((2 : ℕ) : ℝ) ^ 2 + = (3 * (s : ℝ) + t) / 4 := by + simp [Fin.sum_univ_two, min_eq_left hst', min_eq_right hst']; ring + rw [hf, hv] at h + exact h + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/AsianGeometricN.lean b/LeanPool/MathFin/Models/BlackScholes/AsianGeometricN.lean new file mode 100644 index 0000000000..4404551115 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/AsianGeometricN.lean @@ -0,0 +1,250 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralIndicator +public import LeanPool.MathFin.Models.BlackScholes.Call +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralGaussian + +/-! +# The geometric-average Asian option: `n` averaging dates, closed-form price + +`Models/BlackScholes/AsianGeometric.lean` proves the *two-date* geometric-Asian log-driver +`(B_s + B_t)/2` Gaussian. This file lifts that to an arbitrary number `n` of averaging +dates `τ₁, …, τₙ` and cashes the resulting lognormality into a **closed-form price**. + +The log-driver of the geometric average `(∏ᵢ S_{τᵢ})^{1/n}` of a Black–Scholes GBM +`S_u = S₀·exp((r − σ²/2)u + σ B_u)` is the **average of the Brownian values** +`D = (1/n) ∑ᵢ B_{τᵢ}`. Read as a single Wiener integral of the step kernel +`f = (1/n) ∑ᵢ 𝟙_{(0,τᵢ]}` (via `wienerIntegralLp_stepIndicator`), it is centred Gaussian +with variance the `L²`-norm of `f`, evaluated on the Ω-side through the Brownian covariance +`∫ B_u·B_v = min(u,v)`: + + `Var(D) = (1/n²) ∑ᵢ ∑ⱼ min(τᵢ, τⱼ) =: Vₙ`. + +So the geometric average is lognormal, `(∏ᵢ S_{τᵢ})^{1/n} = S₀·exp((r − σ²/2)·t_bar + σ·D)` +with `t_bar = (1/n) ∑ τᵢ`, and matches a vanilla Black–Scholes terminal `bsTerminal S_hat₀ r σ_G T` +under the standardized driver `Z = D/√Vₙ ~ N(0,1)`, with effective spot +`S_hat₀ = S₀·exp((r − σ²/2)t_bar + σ²Vₙ/2 − rT)` and effective volatility `σ_G = σ·√(Vₙ/T)` +(so `σ_G√T = σ√Vₙ`). Feeding that into `bs_call_formula` gives the geometric-Asian +call price in closed form — the same "reduce to one effective BS driver" move as Margrabe. + +## Main definitions + +* `geomAsianTbar`: the average of the sampling dates, `t_bar = (1/n) ∑ τᵢ`. +* `geomAsianVar`: the geometric-Asian log-driver variance `Vₙ = (1/n²) ∑ᵢ∑ⱼ min(τᵢ,τⱼ)`. +* `geomAsianEffVol`: the effective volatility `σ_G = σ·√(Vₙ/T)` reducing the geometric-Asian call to + a vanilla call. +* `geomAsianEffSpot`: the effective spot `S_hat₀ = S₀·exp((r-σ²/2)t_bar + σ²Vₙ/2 - rT)` reducing the + geometric-Asian call to a vanilla call. + +## Main results + +* `geomAsianN_driver_hasLaw` — `(1/n) ∑ᵢ B_{τᵢ} ~ N(0, (1/n²) ∑ᵢ∑ⱼ min(τᵢ,τⱼ))`. + +## References + +* [A. G. Z. Kemna and A. C. F. Vorst, *A pricing method for options based on average asset + values*][KemnaVorst1990] + +## Tags + +geometric Asian option, average price option, closed-form price, effective volatility, +Wiener integral, lognormal, MSC 91G20, MSC 60J65, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real Set +open scoped NNReal +open WienerIntegralL2 + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-- **The `n`-date geometric-Asian log-driver is Gaussian.** For a pre-Brownian motion `B` +and averaging dates `τ : Fin n → ℝ≥0` all `≤ T`, the average of the Brownian values +`(1/n) ∑ᵢ B_{τᵢ}` — the Gaussian part of the log geometric average — has the centred +Gaussian law `N(0, (1/n²) ∑ᵢ∑ⱼ min(τᵢ,τⱼ))`, the variance coming from the Brownian +covariance `∫ B_u·B_v = min(u,v)`. `asianGeom_driver_hasLaw` is its `n = 2` case. -/ +theorem geomAsianN_driver_hasLaw (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + {n : ℕ} (hn : 0 < n) (τ : Fin n → ℝ≥0) (hτT : ∀ i, τ i ≤ T) : + HasLaw (fun ω ↦ (∑ i, B (τ i) ω) / n) + (gaussianReal 0 ((∑ i, ∑ j, min (τ i : ℝ) (τ j)) / (n : ℝ) ^ 2).toNNReal) μ := by + classical + have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + -- The step indices `(0, τ i]` and the kernel `f = (1/n) ∑ᵢ 𝟙_{(0,τᵢ]}`. + set idx : Fin n → StepIndex T := fun i ↦ ⟨(0, τ i), ⟨zero_le, hτT i⟩⟩ with hidx + set f : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := + (n : ℝ)⁻¹ • ∑ i, stepIndicatorLp T (idx i) with hf + -- Its Wiener integral is `(1/n) ∑ᵢ wInc(0,τᵢ]`. + have hf_eq : wienerIntegralLp B hB T f + = (n : ℝ)⁻¹ • ∑ i, wienerIncrementLp B hB (idx i) := by + rw [hf]; simp only [map_smul, map_sum, wienerIntegralLp_stepIndicator] + -- The memberships and per-index increment coeFns. + have hmem : ∀ i, MemLp (B (τ i)) 2 μ := fun i ↦ + (hB.isGaussianProcess.hasGaussianLaw_eval (τ i)).memLp_two + have hincr : ∀ i, (wienerIncrementLp B hB (idx i) : Ω → ℝ) + =ᵐ[μ] fun ω ↦ B (τ i) ω - B 0 ω := fun i ↦ + (memLp_increment hB (idx i).1.1 (idx i).1.2).coeFn_toLp + -- The Wiener integral's coeFn is `(1/n) ∑ᵢ B_{τᵢ}` a.e. (zero start). + have hD : (fun ω ↦ wienerIntegralLp B hB T f ω) =ᵐ[μ] fun ω ↦ (∑ i, B (τ i) ω) / n := by + rw [hf_eq] + have hsmul := Lp.coeFn_smul (n : ℝ)⁻¹ (∑ i, wienerIncrementLp B hB (idx i)) + have hsum := Lp.coeFn_finsetSum (Finset.univ) (fun i ↦ wienerIncrementLp B hB (idx i)) + filter_upwards [hsmul, hsum, hB.eval_zero_ae_eq_zero, ae_all_iff.mpr hincr] + with ω h1 h2 hz hincrω + simp only [Pi.smul_apply, smul_eq_mul] at h1 + rw [h1, h2, Finset.sum_apply] + rw [div_eq_inv_mul] + congr 1 + refine Finset.sum_congr rfl (fun i _ ↦ ?_) + rw [hincrω i, hz, sub_zero] + -- The variance `∫ f² = (∑ᵢ∑ⱼ min)/n²`, computed on the Ω-side via `∫ B_u·B_v = min`. + have hvar : (∫ s in Set.Ioc (0 : ℝ) (T : ℝ), (f s) ^ 2 ∂volume) + = (∑ i, ∑ j, min (τ i : ℝ) (τ j)) / (n : ℝ) ^ 2 := by + rw [← wienerIntegralLp_integral_sq hB T f] + have hsq : (fun ω ↦ (wienerIntegralLp B hB T f ω) ^ 2) + =ᵐ[μ] fun ω ↦ (n : ℝ)⁻¹ ^ 2 * ∑ i, ∑ j, (B (τ i) ω * B (τ j) ω) := by + filter_upwards [hD] with ω hω + rw [hω, div_pow, pow_two (∑ i, B (τ i) ω), Finset.sum_mul_sum] + ring + rw [integral_congr_ae hsq] + have hintij : ∀ i j, Integrable (fun ω ↦ B (τ i) ω * B (τ j) ω) μ := fun i j ↦ + (hmem i).integrable_mul (hmem j) + have hinti : ∀ i, Integrable (fun ω ↦ ∑ j, (B (τ i) ω * B (τ j) ω)) μ := fun i ↦ + integrable_finsetSum _ (fun j _ ↦ hintij i j) + rw [integral_const_mul, integral_finsetSum _ (fun i _ ↦ hinti i)] + have hji : ∀ i, (∫ ω, ∑ j, (B (τ i) ω * B (τ j) ω) ∂μ) = ∑ j, min (τ i : ℝ) (τ j) := by + intro i + rw [integral_finsetSum _ (fun j _ ↦ hintij i j)] + exact Finset.sum_congr rfl (fun j _ ↦ integral_mul_eval hB (τ i) (τ j)) + simp_rw [hji] + ring + -- Assemble the Gaussian law and transfer along the a.e. equality. + have h0 := wienerIntegralLp_hasLaw_gaussian hB T f + rw [hvar] at h0 + exact ⟨h0.aemeasurable.congr hD, (Measure.map_congr hD).symm.trans h0.map_eq⟩ + +/-! ### The closed-form geometric-Asian call price -/ + +/-- The average of the sampling dates, `t_bar = (1/n) ∑ τᵢ`. -/ +noncomputable def geomAsianTbar {n : ℕ} (τ : Fin n → ℝ≥0) : ℝ := (∑ i, (τ i : ℝ)) / n + +/-- The geometric-Asian log-driver variance `Vₙ = (1/n²) ∑ᵢ∑ⱼ min(τᵢ,τⱼ)`. -/ +noncomputable def geomAsianVar {n : ℕ} (τ : Fin n → ℝ≥0) : ℝ := + (∑ i, ∑ j, min (τ i : ℝ) (τ j)) / (n : ℝ) ^ 2 + +/-- Effective Black–Scholes volatility `σ_G = σ·√(Vₙ/T)` reducing the geometric-Asian +call to a vanilla call. -/ +noncomputable def geomAsianEffVol (σ Tmat : ℝ) {n : ℕ} (τ : Fin n → ℝ≥0) : ℝ := + σ * Real.sqrt (geomAsianVar τ / Tmat) + +/-- Effective Black–Scholes spot `S_hat₀ = S₀·exp((r−σ²/2)t_bar + σ²Vₙ/2 − rT)` reducing the +geometric-Asian call to a vanilla call. -/ +noncomputable def geomAsianEffSpot (S₀ r σ Tmat : ℝ) {n : ℕ} (τ : Fin n → ℝ≥0) : ℝ := + S₀ * Real.exp ((r - σ ^ 2 / 2) * geomAsianTbar τ + σ ^ 2 * geomAsianVar τ / 2 - r * Tmat) + +/-- **The geometric average of GBM prices is one lognormal factor.** For a positive spot +`S₀` and any log-increments `a : Fin n → ℝ`, +`∏ᵢ (S₀·exp(aᵢ))^{1/n} = S₀·exp((∑ᵢ aᵢ)/n)`. -/ +lemma prod_mul_exp_rpow_inv_eq {n : ℕ} (hn : 0 < n) (S₀ : ℝ) (hS₀ : 0 < S₀) (a : Fin n → ℝ) : + (∏ i, (S₀ * Real.exp (a i)) ^ ((n : ℝ)⁻¹)) = S₀ * Real.exp ((∑ i, a i) / n) := by + have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + have hexp_rpow : ∀ x y : ℝ, (Real.exp x) ^ y = Real.exp (x * y) := fun x y ↦ by + rw [Real.rpow_def_of_pos (Real.exp_pos x), Real.log_exp] + have hfac : ∀ i, (S₀ * Real.exp (a i)) ^ ((n : ℝ)⁻¹) + = S₀ ^ ((n : ℝ)⁻¹) * Real.exp (a i * (n : ℝ)⁻¹) := fun i ↦ by + rw [Real.mul_rpow hS₀.le (Real.exp_pos _).le, hexp_rpow] + simp_rw [hfac] + rw [Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ, Fintype.card_fin, + ← Real.rpow_natCast (S₀ ^ (n : ℝ)⁻¹) n, ← Real.rpow_mul hS₀.le, inv_mul_cancel₀ hn0, + Real.rpow_one, ← Real.exp_sum] + congr 2 + rw [← Finset.sum_mul, ← div_eq_mul_inv] + +/-- **The effective-BS reduction.** The geometric-average lognormal `S₀·exp((r−σ²/2)t_bar + σ·d)` +is exactly the vanilla Black–Scholes terminal `bsTerminal S_hat₀ r σ_G T` at the standardized +driver `z = d/√Vₙ`, with `S_hat₀ = S₀·exp((r−σ²/2)t_bar + σ²Vₙ/2 − rT)` and `σ_G = σ√(Vₙ/T)`. -/ +private lemma bsTerminal_geomAsian_eq {S₀ r σ Tmat V tbar d : ℝ} + (hTmat : 0 < Tmat) (hV : 0 < V) : + bsTerminal (S₀ * Real.exp ((r - σ ^ 2 / 2) * tbar + σ ^ 2 * V / 2 - r * Tmat)) r + (σ * Real.sqrt (V / Tmat)) Tmat (d / Real.sqrt V) + = S₀ * Real.exp ((r - σ ^ 2 / 2) * tbar + σ * d) := by + have hsV : (0 : ℝ) < Real.sqrt V := Real.sqrt_pos.mpr hV + have hVT : (0 : ℝ) ≤ V / Tmat := by positivity + have key1 : σ * Real.sqrt (V / Tmat) * Real.sqrt Tmat = σ * Real.sqrt V := by + rw [mul_assoc, ← Real.sqrt_mul hVT, div_mul_cancel₀ _ hTmat.ne'] + have key2 : (σ * Real.sqrt (V / Tmat)) ^ 2 = σ ^ 2 * (V / Tmat) := by + rw [mul_pow, Real.sq_sqrt hVT] + have key3 : σ * Real.sqrt (V / Tmat) * Real.sqrt Tmat * (d / Real.sqrt V) = σ * d := by + rw [key1]; field_simp + unfold bsTerminal + rw [mul_assoc, ← Real.exp_add, key2, key3] + congr 2 + field_simp + ring + +/-- **The `n`-date geometric-Asian call price in closed form.** For a Black–Scholes GBM +`S_u = S₀·exp((r − σ²/2)u + σ B_u)` sampled at dates `τ : Fin n → ℝ≥0` (all `≤ T`), with a +non-degenerate log-driver variance `Vₙ > 0`, the discounted expected geometric-Asian call +payoff `e^{−rT}·𝔼[max((∏ᵢ S_{τᵢ})^{1/n} − K, 0)]` equals the Black–Scholes call price with +effective spot `S_hat₀` and volatility `σ_G` — the same "reduce to one effective BS driver" +move as Margrabe, here with the geometric-average forward carrying the `σ²Vₙ/2` convexity. -/ +theorem geomAsianN_call_price (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + {n : ℕ} (hn : 0 < n) (τ : Fin n → ℝ≥0) (hτT : ∀ i, τ i ≤ T) + (S₀ K r σ Tmat : ℝ) (hS₀ : 0 < S₀) (hK : 0 < K) (hσ : 0 < σ) (hTmat : 0 < Tmat) + (hV : 0 < geomAsianVar τ) : + ∫ ω, Real.exp (-r * Tmat) * + max ((∏ i, (S₀ * Real.exp ((r - σ ^ 2 / 2) * (τ i : ℝ) + σ * B (τ i) ω)) ^ ((n : ℝ)⁻¹)) + - K) 0 ∂μ + = geomAsianEffSpot S₀ r σ Tmat τ * + Phi (bsd1 (geomAsianEffSpot S₀ r σ Tmat τ) K r (geomAsianEffVol σ Tmat τ) Tmat) + - K * Real.exp (-r * Tmat) * + Phi (bsd2 (geomAsianEffSpot S₀ r σ Tmat τ) K r (geomAsianEffVol σ Tmat τ) Tmat) := by + -- Unfold the effective-parameter defs everywhere, then name the raw variance/mean. + simp only [geomAsianEffSpot, geomAsianEffVol, geomAsianVar, geomAsianTbar] at hV ⊢ + set V : ℝ := (∑ i, ∑ j, min (τ i : ℝ) (τ j)) / (n : ℝ) ^ 2 with hVdef + set tb : ℝ := (∑ i, (τ i : ℝ)) / n with htb + have hsV : (0 : ℝ) < Real.sqrt V := Real.sqrt_pos.mpr hV + -- The driver `D = (1/n) ∑ B_{τᵢ}` has law `N(0, V)`; standardize to `Z = D/√V ~ N(0,1)`. + have hD_law : HasLaw (fun ω ↦ (∑ i, B (τ i) ω) / n) (gaussianReal 0 V.toNNReal) μ := + geomAsianN_driver_hasLaw hB T hn τ hτT + have hZ_law : HasLaw (fun ω ↦ (∑ i, B (τ i) ω) / n / Real.sqrt V) (gaussianReal 0 1) μ := by + have h := gaussianReal_const_mul hD_law (Real.sqrt V)⁻¹ + have hfun : (fun ω ↦ (Real.sqrt V)⁻¹ * ((∑ i, B (τ i) ω) / n)) + = fun ω ↦ (∑ i, B (τ i) ω) / n / Real.sqrt V := by funext ω; ring + rw [hfun] at h + have hvar1 : (Real.sqrt V)⁻¹ ^ 2 * (V.toNNReal : ℝ) = 1 := by + rw [Real.coe_toNNReal V hV.le, inv_pow, Real.sq_sqrt hV.le, inv_mul_cancel₀ hV.ne'] + convert h using 2 + · rw [mul_zero] + · refine NNReal.coe_injective ?_ + rw [NNReal.coe_one, NNReal.coe_mul, NNReal.coe_mk] + exact hvar1.symm + -- Name the effective spot/vol (now in terms of the raw `V`, `tb`), positivity, price formula. + set S_hat : ℝ := S₀ * Real.exp ((r - σ ^ 2 / 2) * tb + σ ^ 2 * V / 2 - r * Tmat) with hS_hat + set σG : ℝ := σ * Real.sqrt (V / Tmat) with hσG + have hS_hatpos : 0 < S_hat := by rw [hS_hat]; positivity + have hσGpos : 0 < σG := by rw [hσG]; positivity + have hbs := bs_call_formula (Q := μ) (S_0 := S_hat) (K := K) (r := r) (σ := σG) (T := Tmat) + (Z := fun ω ↦ (∑ i, B (τ i) ω) / n / Real.sqrt V) ⟨hS_hatpos, hK, hσGpos, hTmat, hZ_law⟩ + -- Rewrite the vanilla terminal into the geometric average, pointwise. + have hterm : ∀ ω, bsTerminal S_hat r σG Tmat ((∑ i, B (τ i) ω) / n / Real.sqrt V) + = ∏ i, (S₀ * Real.exp ((r - σ ^ 2 / 2) * (τ i : ℝ) + σ * B (τ i) ω)) ^ ((n : ℝ)⁻¹) := by + intro ω + rw [prod_mul_exp_rpow_inv_eq hn S₀ hS₀, hS_hat, hσG, bsTerminal_geomAsian_eq hTmat hV] + congr 2 + rw [htb, Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum] + ring + simp_rw [hterm] at hbs + exact hbs + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/AsianInequality.lean b/LeanPool/MathFin/Models/BlackScholes/AsianInequality.lean new file mode 100644 index 0000000000..83fa254a30 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/AsianInequality.lean @@ -0,0 +1,189 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.AsianGeometricN +public import LeanPool.MathFin.Models.BlackScholes.PDE + +/-! +# Geometric vs arithmetic Asian options + +The geometric Asian option's payoff is bounded above by the arithmetic Asian +option's payoff at every state, because the geometric mean of positive numbers +is at most their arithmetic mean (AM-GM). + +For prices `S_{t_1}, …, S_{t_n} ≥ 0`: + + `(∏ S_{t_i})^{1/n} ≤ (1/n) ∑ S_{t_i}`. + +Since `x ↦ max(x − K, 0)` is monotone non-decreasing: + + `max(geomMean − K, 0) ≤ max(arithMean − K, 0)`. + +Integrating over the pricing measure preserves this pointwise inequality. In the +Black–Scholes model with a Brownian driver the geometric Asian price has a closed +form, the Black–Scholes call `bsV` at an effective spot and volatility +(`geomAsianN_call_price`, `Models/BlackScholes/AsianGeometricN.lean`), so the arithmetic Asian +call, which has no closed form, is bounded below by that `bsV` value. + +## Main results + +* `am_gm_two`: `√(a · b) ≤ (a + b) / 2` for `a, b ≥ 0` — Mathlib's + `Real.geom_mean_le_arith_mean2_weighted` at weights `1/2`, bridged from + `rpow` to `sqrt`. +* `geom_mean_le_arith_mean_n`: weighted AM-GM specialized to equal weights + `1/n` (Mathlib's `Real.geom_mean_le_arith_mean_weighted`). +* `asian_payoff_geom_le_arith_two`, `asian_payoff_geom_le_arith_n`: the geometric + Asian payoff is bounded above by the arithmetic Asian payoff (two and `n` dates). +* `geomAsianN_bsV_le_arith`: the price-level bound — the closed-form geometric-Asian + price `bsV K r σ_G S_hat₀ T` is at most the discounted expected arithmetic-Asian payoff + of the Black–Scholes GBM sampled at the same dates. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], Ch 26.13 +* [A. G. Z. Kemna and A. C. F. Vorst, *A pricing method for options based on average asset + values*][KemnaVorst1990] + +## Tags + +Asian option, arithmetic average, geometric average, AM–GM inequality, price bound, +average price option, MSC 91G20, MSC 60E15, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- **Two-element AM-GM**: `√(a · b) ≤ (a + b) / 2` for `a, b ≥ 0`. Mathlib's +weighted two-element AM-GM `Real.geom_mean_le_arith_mean2_weighted` at weights +`w₁ = w₂ = 1/2`, with `√x = x^(1/2)` bridging `sqrt` to `rpow`. -/ +lemma am_gm_two (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) : + Real.sqrt (a * b) ≤ (a + b) / 2 := by + have h := Real.geom_mean_le_arith_mean2_weighted + (by norm_num : (0:ℝ) ≤ 1/2) (by norm_num : (0:ℝ) ≤ 1/2) ha hb + (by norm_num : (1:ℝ)/2 + 1/2 = 1) + calc Real.sqrt (a * b) = (a * b) ^ ((1:ℝ)/2) := Real.sqrt_eq_rpow _ + _ = a ^ ((1:ℝ)/2) * b ^ ((1:ℝ)/2) := Real.mul_rpow ha hb + _ ≤ 1/2 * a + 1/2 * b := h + _ = (a + b) / 2 := by ring + +/-- **Two-time-point geometric vs arithmetic Asian payoff**: for positive +prices `S₁, S₂` and any strike `K`, the geometric-Asian-call payoff is +bounded above by the arithmetic-Asian-call payoff. -/ +lemma asian_payoff_geom_le_arith_two (S₁ S₂ K : ℝ) (h₁ : 0 ≤ S₁) (h₂ : 0 ≤ S₂) : + max (Real.sqrt (S₁ * S₂) - K) 0 ≤ max ((S₁ + S₂) / 2 - K) 0 := by + have h_mean := am_gm_two S₁ S₂ h₁ h₂ + -- max is monotone in the first argument: x ≤ y ⟹ max(x - K, 0) ≤ max(y - K, 0) + have h_sub : Real.sqrt (S₁ * S₂) - K ≤ (S₁ + S₂) / 2 - K := by linarith + exact max_le_max h_sub le_rfl + +/-- **Weighted AM-GM, n-element equal-weight form**: +`n · ∏ f_i^{1/n} ≤ ∑ f_i` for non-negative `f : Fin n → ℝ` and `n > 0`. -/ +lemma geom_mean_le_arith_mean_n {n : ℕ} (f : Fin n → ℝ) + (h_nn : ∀ i, 0 ≤ f i) (hn : 0 < n) : + (n : ℝ) * (∏ i : Fin n, f i ^ ((n : ℝ)⁻¹)) ≤ ∑ i : Fin n, f i := by + have hn_pos : 0 < (n : ℝ) := Nat.cast_pos.mpr hn + have hn_ne : (n : ℝ) ≠ 0 := hn_pos.ne' + have hn_inv_nn : 0 ≤ ((n : ℝ))⁻¹ := inv_nonneg.mpr hn_pos.le + set w : Fin n → ℝ := fun _ ↦ ((n : ℝ))⁻¹ + have h_w_nn : ∀ i ∈ Finset.univ, 0 ≤ w i := fun _ _ ↦ hn_inv_nn + have h_f_nn : ∀ i ∈ Finset.univ, 0 ≤ f i := fun i _ ↦ h_nn i + have h_sum_w : ∑ i ∈ Finset.univ, w i = 1 := by + change ∑ _ : Fin n, ((n : ℝ))⁻¹ = 1 + rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + field_simp + -- Apply Mathlib weighted AM-GM with `w` and `z := f`. + have h := Real.geom_mean_le_arith_mean_weighted (s := Finset.univ) + w f h_w_nn h_sum_w h_f_nn + -- `h : ∏ i, f i ^ (1/n) ≤ ∑ i, (1/n) * f i` + -- Multiply both sides by `n ≥ 0`. + have h_mul := mul_le_mul_of_nonneg_left h hn_pos.le + -- Now LHS: n * ∏, RHS: n * ∑ (1/n) * f = ∑ f. + have h_rhs_simp : (n : ℝ) * ∑ i : Fin n, w i * f i = ∑ i : Fin n, f i := by + change (n : ℝ) * ∑ i : Fin n, ((n : ℝ))⁻¹ * f i = ∑ i : Fin n, f i + rw [← Finset.mul_sum, ← mul_assoc, mul_inv_cancel₀ hn_ne, one_mul] + rw [h_rhs_simp] at h_mul + exact h_mul + +/-- **n-date geometric vs arithmetic Asian payoff**: the geometric-mean Asian +call payoff is bounded above by the arithmetic-mean one, for any number `n` of +averaging dates — the `n`-date extension of `asian_payoff_geom_le_arith_two`, +a one-line `max_le_max` over the already-proved AM-GM `geom_mean_le_arith_mean_n`. -/ +lemma asian_payoff_geom_le_arith_n {n : ℕ} (S : Fin n → ℝ) + (h_nn : ∀ i, 0 ≤ S i) (hn : 0 < n) (K : ℝ) : + max ((∏ i, S i ^ ((n : ℝ)⁻¹)) - K) 0 ≤ max ((∑ i, S i) / n - K) 0 := by + have hn_pos : (0 : ℝ) < n := Nat.cast_pos.mpr hn + have h := geom_mean_le_arith_mean_n S h_nn hn + have h_div : (∏ i, S i ^ ((n : ℝ)⁻¹)) ≤ (∑ i, S i) / n := by + rw [le_div_iff₀ hn_pos, mul_comm]; exact h + exact max_le_max (by linarith) le_rfl + +/-! ### The price-level bound in the Black–Scholes model -/ + +section PriceBound + +open MeasureTheory ProbabilityTheory +open scoped NNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-- The arithmetic-average Asian call payoff of a Black–Scholes GBM sampled at dates `τ` is +integrable: it is the positive part of a finite sum of lognormals minus a constant. -/ +lemma integrable_arithAsian_payoff (hB : IsPreBrownianReal B μ) {n : ℕ} (τ : Fin n → ℝ≥0) + (S₀ K r σ : ℝ) : + Integrable (fun ω ↦ max ((∑ i, S₀ * Real.exp ((r - σ ^ 2 / 2) * (τ i : ℝ) + σ * B (τ i) ω)) + / n - K) 0) μ := by + have hS (i : Fin n) : Integrable + (fun ω ↦ S₀ * Real.exp ((r - σ ^ 2 / 2) * (τ i : ℝ) + σ * B (τ i) ω)) μ := by + have h : Integrable (fun ω ↦ Real.exp (σ * B (τ i) ω)) μ := by + rw [show (fun ω ↦ Real.exp (σ * B (τ i) ω)) = (fun x ↦ Real.exp (σ * x)) ∘ B (τ i) + from rfl] + refine Integrable.comp_aemeasurable ?_ (hB.aemeasurable _) + rw [(hB.hasLaw_eval (τ i)).map_eq] + exact integrable_exp_mul_gaussianReal σ + refine (h.const_mul (S₀ * Real.exp ((r - σ ^ 2 / 2) * (τ i : ℝ)))).congr + (ae_of_all _ fun ω ↦ ?_) + simp only [Real.exp_add] + ring + exact (((integrable_finsetSum _ fun i _ ↦ hS i).div_const _).sub' + (integrable_const K)).pos_part + +/-- **The geometric-Asian closed form bounds the arithmetic Asian call from below.** For a +Black–Scholes GBM `S_u = S₀·exp((r − σ²/2)u + σB_u)` sampled at dates `τ : Fin n → ℝ≥0` +(all `≤ T`, non-degenerate log-driver variance), the Black–Scholes call at the geometric +average's effective spot `S_hat₀` and volatility `σ_G` — which is the geometric-Asian price, +`geomAsianN_call_price` — is at most the discounted expected arithmetic-Asian call payoff +`e^{−rT}·𝔼[max((1/n)∑ᵢ S_{τᵢ} − K, 0)]`. The proof integrates the pointwise AM–GM payoff +bound `asian_payoff_geom_le_arith_n`. -/ +theorem geomAsianN_bsV_le_arith (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + {n : ℕ} (hn : 0 < n) (τ : Fin n → ℝ≥0) (hτT : ∀ i, τ i ≤ T) + (S₀ K r σ Tmat : ℝ) (hS₀ : 0 < S₀) (hK : 0 < K) (hσ : 0 < σ) (hTmat : 0 < Tmat) + (hV : 0 < geomAsianVar τ) : + bsV K r (geomAsianEffVol σ Tmat τ) (geomAsianEffSpot S₀ r σ Tmat τ) Tmat ≤ + ∫ ω, Real.exp (-r * Tmat) * + max ((∑ i, S₀ * Real.exp ((r - σ ^ 2 / 2) * (τ i : ℝ) + σ * B (τ i) ω)) / n - K) 0 + ∂μ := by + calc bsV K r (geomAsianEffVol σ Tmat τ) (geomAsianEffSpot S₀ r σ Tmat τ) Tmat + = ∫ ω, Real.exp (-r * Tmat) * + max ((∏ i, (S₀ * Real.exp ((r - σ ^ 2 / 2) * (τ i : ℝ) + σ * B (τ i) ω)) + ^ ((n : ℝ)⁻¹)) - K) 0 ∂μ := by + rw [geomAsianN_call_price hB T hn τ hτT S₀ K r σ Tmat hS₀ hK hσ hTmat hV, bsV, + neg_mul] + _ ≤ _ := integral_mono_of_nonneg + (ae_of_all _ fun ω ↦ mul_nonneg (Real.exp_pos _).le (le_max_right _ _)) + ((integrable_arithAsian_payoff hB τ S₀ K r σ).const_mul _) + (ae_of_all _ fun ω ↦ mul_le_mul_of_nonneg_left + (asian_payoff_geom_le_arith_n _ (fun i ↦ by positivity) hn K) (Real.exp_pos _).le) + +end PriceBound + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/BSCallHypFromBrownian.lean b/LeanPool/MathFin/Models/BlackScholes/BSCallHypFromBrownian.lean new file mode 100644 index 0000000000..9f6eaa5273 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/BSCallHypFromBrownian.lean @@ -0,0 +1,162 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Call +public import LeanPool.MathFin.Models.Bachelier.Bachelier +public import Mathlib.Probability.BrownianMotion.Basic + +/-! +# `BSCallHyp` / `BachelierHyp` from a Brownian motion + +The existing `BSCallHyp` and `BachelierHyp` hypotheses are stated at the +**marginal level**: `Z ~ N(0, 1)` under `Q` with `S_T = bsTerminal …(Z ω)` +(BS) or `S_T = S_0 + σ √T · Z(ω)` (Bachelier). This file shows that both +hypotheses are *consequences* of having a pre-Brownian motion `W : ℝ≥0 → Ω → +ℝ` (Mathlib's `IsPreBrownianReal W Q`), by setting + + `Z := W T.toNNReal / √T`, + +which has `gaussianReal 0 1` law by Gaussian-scaling. This binds the BS / +Bachelier models to actual continuous-time process structure without +requiring any change to the existing closed-form pricing theorems, which +continue to consume the marginal hypothesis directly. + +## Bridge content + +The substantive new fact is `scaled_isPreBrownian_eval_law`: + + `IsPreBrownianReal W Q ⟹ HasLaw (fun ω ↦ W T.toNNReal ω / √T) (gaussianReal 0 1) Q`. + +It combines `IsPreBrownianReal.hasLaw_eval` (Brownian marginal `W_T ~ N(0, T)`) +with `Mathlib`'s `gaussianReal_div_const` (Gaussian scaling under `· / c`). +The variance arithmetic `T.toNNReal / NNReal.mk((√T)², _) = 1` collapses via +`Real.sq_sqrt` and `NNReal.div_self`. + +The two `of_isPreBrownian` constructors are then one-line wrappers. + +## Why this is a "bridge" + +The `Foundations/` BM machinery (`BrownianMotion.Gaussian.BrownianMotion`, +`MathFin.Probability.Brownian.BrownianMartingale`, etc.) was previously +**structurally disconnected** from the pricing modules: pricing took +`Z ~ N(0,1)` as axiom and never invoked the BM construction. This file +makes the connection explicit — any BM construction (via `IsPreBrownianReal`) +discharges the BS / Bachelier hypothesis automatically. + +## Main results + +* `scaled_isPreBrownian_eval_law`: the core scaling identity for pre- + Brownian motion under `· / √T`. +* `BSCallHyp.of_isPreBrownian`: BS hypothesis from a pre-Brownian motion. +* `BachelierHyp.of_isPreBrownian`: Bachelier hypothesis from a pre-Brownian + motion (same scaled `Z`). + +## Tags + +Brownian motion, Gaussian scaling, Black–Scholes hypothesis, Bachelier model, pre-Brownian motion, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal + +/-- **Core scaling identity**: if `W` is a pre-Brownian motion under `Q`, +then for any positive `T : ℝ`, the rescaled time-`T` value +`W T.toNNReal / √T` has `gaussianReal 0 1` law. + +Combines `IsPreBrownianReal.hasLaw_eval` (BM marginal `W_T ~ N(0, T.toNNReal)`) +with `gaussianReal_div_const` (Gaussian scaling under `· / c`). The +variance computation `T.toNNReal / NNReal.mk((√T)², _) = 1` reduces to +`Real.sq_sqrt` + `NNReal.div_self`. -/ +lemma scaled_isPreBrownian_eval_law + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} + (W : ℝ≥0 → Ω → ℝ) (hW : IsPreBrownianReal W Q) + {T : ℝ} (hT : 0 < T) : + HasLaw (fun ω ↦ W T.toNNReal ω / Real.sqrt T) (gaussianReal 0 1) Q := by + have h_eval : HasLaw (W T.toNNReal) (gaussianReal 0 T.toNNReal) Q := + hW.hasLaw_eval T.toNNReal + have h_div := gaussianReal_div_const h_eval (Real.sqrt T) + convert h_div using 2 + · rw [zero_div] + · -- Variance: T.toNNReal / NNReal.mk((√T)², _) = 1 + have h_sqrt_sq : + (NNReal.mk ((Real.sqrt T) ^ 2) (sq_nonneg _) : ℝ≥0) = T.toNNReal := by + apply NNReal.eq + simp only [NNReal.coe_mk] + rw [Real.sq_sqrt hT.le] + exact (Real.coe_toNNReal T hT.le).symm + rw [h_sqrt_sq] + exact (div_self (Real.toNNReal_pos.mpr hT).ne').symm + +/-- **`BSCallHyp` from a pre-Brownian motion**. Given a pre-Brownian +process `W` under `Q` and positive parameters `(S_0, K, σ, T)`, the +rescaled `Z := W T.toNNReal / √T` satisfies the BS risk-neutral lognormal +hypothesis. -/ +theorem BSCallHyp.of_isPreBrownian + {Ω : Type*} {mΩ : MeasurableSpace Ω} + (Q : Measure Ω) [IsProbabilityMeasure Q] + (W : ℝ≥0 → Ω → ℝ) (hW : IsPreBrownianReal W Q) + {S_0 K r σ T : ℝ} + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + BSCallHyp Q S_0 K r σ T (fun ω ↦ W T.toNNReal ω / Real.sqrt T) := + ⟨hS_0, hK, hσ, hT, scaled_isPreBrownian_eval_law W hW hT⟩ + +/-- **`BachelierHyp` from a pre-Brownian motion**. Same scaled `Z := W +T.toNNReal / √T` works for the Bachelier arithmetic-BM model (no +exponential), since both hypotheses share `Z_law : HasLaw Z (gaussianReal +0 1) Q`. -/ +theorem BachelierHyp.of_isPreBrownian + {Ω : Type*} {mΩ : MeasurableSpace Ω} + (Q : Measure Ω) [IsProbabilityMeasure Q] + (W : ℝ≥0 → Ω → ℝ) (hW : IsPreBrownianReal W Q) + {S_0 K σ T : ℝ} + (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + BachelierHyp Q S_0 K σ T (fun ω ↦ W T.toNNReal ω / Real.sqrt T) := + ⟨hK, hσ, hT, scaled_isPreBrownian_eval_law W hW hT⟩ + +/-- **`bsTerminal` expressed in terms of Brownian motion**: substituting the +scaled `Z := W T.toNNReal / √T` into `bsTerminal` yields the *intrinsic* +GBM form + + `S_T(ω) = S_0 · exp((r − σ²/2) T + σ · W T.toNNReal(ω))`, + +with the `√T` factor cancelling. This is the form most textbooks state +directly — the BS-formula derivation uses the standard-normal Z marginal +because that's algebraically convenient, but the *meaning* is the BM +exponential. -/ +lemma bsTerminal_via_brownian + {Ω : Type*} (W : ℝ≥0 → Ω → ℝ) {S_0 r σ T : ℝ} (hT : 0 < T) (ω : Ω) : + bsTerminal S_0 r σ T (W T.toNNReal ω / Real.sqrt T) = + S_0 * Real.exp ((r - σ^2 / 2) * T + σ * W T.toNNReal ω) := by + unfold bsTerminal + have h_sqrt_pos : 0 < Real.sqrt T := Real.sqrt_pos.mpr hT + have h_sqrt_ne : Real.sqrt T ≠ 0 := h_sqrt_pos.ne' + congr 1 + field_simp + +/-- **Bachelier terminal expressed in terms of Brownian motion**: the +arithmetic-BM model has + + `S_T(ω) = S_0 + σ · W T.toNNReal(ω)` + +when `Z := W T.toNNReal / √T` is plugged into `S_0 + σ √T · Z`. -/ +lemma bachelierTerminal_via_brownian + {Ω : Type*} (W : ℝ≥0 → Ω → ℝ) {S_0 σ T : ℝ} (hT : 0 < T) (ω : Ω) : + S_0 + σ * Real.sqrt T * (W T.toNNReal ω / Real.sqrt T) = + S_0 + σ * W T.toNNReal ω := by + have h_sqrt_pos : 0 < Real.sqrt T := Real.sqrt_pos.mpr hT + have h_sqrt_ne : Real.sqrt T ≠ 0 := h_sqrt_pos.ne' + field_simp + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/BarrierParity.lean b/LeanPool/MathFin/Models/BlackScholes/BarrierParity.lean new file mode 100644 index 0000000000..0c517d1222 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/BarrierParity.lean @@ -0,0 +1,141 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.PDE +public import LeanPool.MathFin.Pricing.Value + +/-! +# Knock-in / knock-out barrier parity (in–out parity) + +A knock-**in** option pays the vanilla payoff `f` only if the underlying path +hits the barrier during the option's life; the matching knock-**out** pays `f` +only if it does *not*. The barrier-hit event `A` and its complement `Aᶜ` +partition every path, so the two discounted expected payoffs add back to the +vanilla price: + +`V_in + V_out = V_vanilla`. + +This needs **no** barrier density and no running-max law — it is a pure +linearity-of-expectation identity, in the register of +`Models/BlackScholes/ChooserComposition.lean`'s `chooser_integral_decomp`: a pathwise +payoff decomposition (`barrier_payoff_partition`) lifted through the integral. + +We first name the present-value functional the library had only ever written +inline — `discountedValue D Q g = D · E_Q[g]` — so the barrier values are thin, +honest specialisations of it and the parity reads as an identity about *values*. + +## Main definitions + +* `discountedValue`: the discounted risk-neutral value `D · E_Q[g]` of a payoff `g` under the + measure `Q` and discount factor `D`. +* `knockInValue`: the value of an option that pays `f` only on the barrier-hit event `A`. +* `knockOutValue`: the value of an option that pays `f` only off the barrier-hit event, that is on + the complement `Aᶜ`. +* `vanillaValue`: the discounted expected payoff `f`, paid on every path. + +## Main results + +* `discountedValue_eq_contract_value`: `discountedValue` is `Contract.value` of the contract that + pays the observed variable `g` at time `0`, so the barrier values are values in the contracts + tower. +* `barrier_payoff_partition`: the pathwise split `𝟙_A·f + 𝟙_{Aᶜ}·f = f`. +* `knockIn_add_knockOut_eq_vanilla`: in–out parity `V_in + V_out = V_vanilla`. +* `knockIn_add_knockOut_eq_bsV`: for a call under the Black–Scholes lognormal hypothesis, + the knock-in and knock-out values sum to the Black–Scholes price `bsV`, for any measurable + barrier event. So a closed form for either leg gives the other as `bsV` minus it; no + closed form for either leg is proved here. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull] +* [E. Reiner and M. Rubinstein, *Breaking down the barriers*][ReinerRubinstein1991] + +## Tags + +in–out parity, barrier option, knock-in, knock-out, vanilla decomposition, discounted value, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- **Discounted risk-neutral value** of a payoff `g` under pricing measure `Q` +and discount factor `D`: `D · E_Q[g]`. The present-value functional the pricing +files had been spelling out inline; named here so in–out parity is an identity +about values rather than raw integrals. -/ +noncomputable def discountedValue (D : ℝ) (Q : Measure Ω) (g : Ω → ℝ) : ℝ := + D * ∫ ω, g ω ∂Q + +/-- **`discountedValue` is `Contract.value`.** `D · E_Q[g]` is the value, under the pricing measure +`Q` and the constant discount factor `D`, of the contract that pays the observable `g` at time `0` +(`Contract.pay`, `Payoff.obs`), in the model whose single observable is `g`. The barrier values +below are this with `g` the knock-in, knock-out or vanilla payoff. -/ +theorem discountedValue_eq_contract_value (D : ℝ) (Q : Measure Ω) (g : Ω → ℝ) : + discountedValue D Q g + = (Contracts.Contract.pay 0 (Contracts.Payoff.obs () 0)).value Q (fun _ _ ↦ D) + (fun _ _ ↦ g) := by + simp only [discountedValue, Contracts.Contract.value_pay, Contracts.Payoff.eval, + Contracts.scenarioAt, integral_const_mul] + +/-- **Knock-in value**: the option pays the payoff `f` only on the barrier-hit +event `A`, so its value is the discounted expectation of `𝟙_A · f`. -/ +noncomputable def knockInValue (D : ℝ) (Q : Measure Ω) (A : Set Ω) (f : Ω → ℝ) : ℝ := + discountedValue D Q (A.indicator f) + +/-- **Knock-out value**: the option pays `f` only off the barrier-hit event, i.e. +on the complement `Aᶜ`, so its value is the discounted expectation of +`𝟙_{Aᶜ} · f = (1 − 𝟙_A) · f`. -/ +noncomputable def knockOutValue (D : ℝ) (Q : Measure Ω) (A : Set Ω) (f : Ω → ℝ) : ℝ := + discountedValue D Q (Aᶜ.indicator f) + +/-- **Vanilla value**: the discounted expected payoff `f`, paid on every path. -/ +noncomputable def vanillaValue (D : ℝ) (Q : Measure Ω) (f : Ω → ℝ) : ℝ := + discountedValue D Q f + +/-- **Barrier payoff partition** (pathwise): the knock-in payoff `𝟙_A · f` and the +knock-out payoff `𝟙_{Aᶜ} · f` sum to the vanilla payoff `f` on every path — each +path either hits the barrier (`ω ∈ A`) or does not (`ω ∈ Aᶜ`), and contributes +`f ω` to exactly one leg. -/ +theorem barrier_payoff_partition (A : Set Ω) (f : Ω → ℝ) : + A.indicator f + Aᶜ.indicator f = f := + Set.indicator_self_add_compl A f + +/-- **In–out barrier parity**: `V_in + V_out = V_vanilla`. The barrier-hit event +`A` and its complement partition the paths (`barrier_payoff_partition`), so the +discounted expected payoffs add to the vanilla price. Pure linearity of the +integral — no barrier density required. -/ +theorem knockIn_add_knockOut_eq_vanilla + (D : ℝ) (Q : Measure Ω) (A : Set Ω) (f : Ω → ℝ) + (hA : MeasurableSet A) (hf : Integrable f Q) : + knockInValue D Q A f + knockOutValue D Q A f = vanillaValue D Q f := by + unfold knockInValue knockOutValue vanillaValue discountedValue + rw [← mul_add, integral_indicator hA, integral_indicator hA.compl, + integral_add_compl hA hf] + +/-- **In–out parity for a Black–Scholes call.** Under `BSCallHyp`, for any measurable +barrier-hit event `A`, the knock-in and knock-out calls (payoff `max(S_T − K, 0)`, discount +`e^{−rT}`) sum to the Black–Scholes price: `V_in + V_out = bsV K r σ S₀ T`. This is +`knockIn_add_knockOut_eq_vanilla` with the vanilla leg priced by +`integral_bsCall_payoff_eq_bsV`. -/ +theorem knockIn_add_knockOut_eq_bsV {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} (h : BSCallHyp Q S_0 K r σ T Z) {A : Set Ω} + (hA : MeasurableSet A) : + knockInValue (Real.exp (-r * T)) Q A (fun ω ↦ max (bsTerminal S_0 r σ T (Z ω) - K) 0) + + knockOutValue (Real.exp (-r * T)) Q A (fun ω ↦ max (bsTerminal S_0 r σ T (Z ω) - K) 0) + = bsV K r σ S_0 T := by + rw [knockIn_add_knockOut_eq_vanilla _ _ _ _ hA + ((integrable_bsTerminal h.Z_law S_0 r σ T).sub' (integrable_const K)).pos_part, + vanillaValue, discountedValue, ← integral_const_mul, integral_bsCall_payoff_eq_bsV h] + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/BasketMomentMatching.lean b/LeanPool/MathFin/Models/BlackScholes/BasketMomentMatching.lean new file mode 100644 index 0000000000..d3fee11ca5 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/BasketMomentMatching.lean @@ -0,0 +1,287 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.GarmanNormalForm +public import LeanPool.MathFin.Probability.Gaussian.GaussianPairLinearLaw + +/-! +# Basket option pricing: the moment-matching approximation + +**This is an approximation, not an exact closed form.** A basket of +correlated lognormals `B_T = ∑ᵢ wᵢ Sᵢ_T` is *not* itself lognormal — the sum +of lognormals has no closed-form law. The standard market practice (the same +"replace the true law by a moment-matched lognormal" move as single-asset +Asian options, cf. Turnbull-Wakeman) is to match the first two moments of the +basket to a single lognormal and price that lognormal with the ordinary +Black-Scholes closed form. + +For forwards `Fᵢ = Sᵢ₀ · e^{rT}`, weights `wᵢ`, vols `σᵢ` and correlations +`ρᵢⱼ`, the basket's first two moments under a joint lognormal +model `Sᵢ_T = Fᵢ · e^{σᵢ√T·Wᵢ − σᵢ²T/2}` are + + `M₁ = ∑ᵢ wᵢ Fᵢ`, + `M₂ = ∑ᵢ ∑ⱼ wᵢ wⱼ Fᵢ Fⱼ · e^{ρᵢⱼ σᵢ σⱼ T}`, + +which this file proves (`integral_basket_eq_basketM1`, `integral_basket_sq_eq_basketM2`) +when each pair `(Wᵢ, Wⱼ)` of standard-normal drivers is jointly Gaussian with covariance +`ρᵢⱼ`. Then + +matching the lognormal moments `𝔼[X] = m`, `𝔼[X²] = m² e^{σ_eff² T}` forces +the **effective variance** `σ_eff² = log(M₂ / M₁²) / T`. Feeding `(M₁, +σ_eff)` into the Garman normal form (`GarmanNormalForm.lean`) at `A = DF·M₁` +gives the moment-matched basket price — literally the ordinary BS closed +form, parameterised by the matched moments, in the same spirit as Kirk's +spread approximation, which is BS parameterised by its pseudo-asset. + +## Main definitions + +* `basketM1`: the matched first moment `M₁ = ∑ᵢ wᵢ Fᵢ`, the basket forward's mean. +* `basketM2`: the matched second moment `M₂ = ∑ᵢ∑ⱼ wᵢwⱼFᵢFⱼ · e^{ρᵢⱼσᵢσⱼT}`. +* `basketEffVol`: the moment-matched effective volatility, solving `M₂ = M₁² · e^{σ_eff²T}` for + `σ_eff`. +* `basketMomentMatchPrice`: the moment-matching basket call price, an approximation: the + Black–Scholes closed form at `A = DF · M₁`, discount factor `DF` and the matched effective + volatility. +* `basketLognormalFactor`: the unit-mean lognormal factor `e^{σ√T·w - σ²T/2}` of one asset of the + basket at its standard-normal driver `w`. + +## Main results + +* `basketEffVol_single`: **consistency check** — with a single asset + (`n = 1`, weight `1`, self-correlation `1`; `F ≠ 0`, `T > 0`, `σ ≥ 0`), the + matched effective vol is exactly the asset's own vol `σ`. A one-asset basket + is lognormal, and the matching recovers its volatility. +* `basketMomentMatchPrice_single_eq_bsV`: with one asset, forward `F = S·e^{rT}` and + `DF = e^{−rT}`, the moment-matched price is the Black–Scholes call `bsV K r σ S T`; + `basketMomentMatchPrice_single_eq_integral` adds that, under `BSCallHyp`, this is the + discounted expected call payoff — so the approximation is exact for one asset. +* `integral_basket_eq_basketM1`, `integral_basket_sq_eq_basketM2`: `M₁` and `M₂` are the + first and second moments of the basket in the joint lognormal model above. That the + matched lognormal prices an `n ≥ 2` basket well is not claimed. + +## References + +* [D. Brigo et al., *Approximated moment-matching dynamics for basket-options + pricing*][BrigoMercurioRapisardaScotti2004] +* [M. Levy, *Pricing European average rate currency options*][Levy1992] + +## Tags + +basket option, moment matching, lognormal approximation, correlated assets, effective volatility, +sum of lognormals, MSC 91G20, MSC 91G60, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Real Finset MeasureTheory ProbabilityTheory + +/-- **The matched first moment**: `M₁ = ∑ᵢ wᵢ Fᵢ`, the basket forward's mean. -/ +noncomputable def basketM1 {n : ℕ} (w F : Fin n → ℝ) : ℝ := + ∑ i, w i * F i + +/-- **The matched second moment**: `M₂ = ∑ᵢ∑ⱼ wᵢwⱼFᵢFⱼ · e^{ρᵢⱼσᵢσⱼT}`, from the +pairwise lognormal cross-moments `𝔼[Sᵢ_T Sⱼ_T] = Fᵢ Fⱼ e^{ρᵢⱼσᵢσⱼT}`. That it is the second +moment of the basket in the joint lognormal model is `integral_basket_sq_eq_basketM2`. -/ +noncomputable def basketM2 {n : ℕ} (w F σ : Fin n → ℝ) (ρ : Fin n → Fin n → ℝ) (T : ℝ) : ℝ := + ∑ i, ∑ j, w i * w j * F i * F j * Real.exp (ρ i j * σ i * σ j * T) + +/-- **The moment-matched effective volatility**: solving +`M₂ = M₁² · e^{σ_eff²T}` for `σ_eff`. Meaningful when `M₂ ≥ M₁² > 0` and `T > 0` +(`M₂ ≥ M₁²` holds for a positive semidefinite correlation matrix and `T ≥ 0`, and +`M₁ > 0` for nonnegative weights and positive forwards with some weight positive; +neither is proved here). Otherwise the value comes from Mathlib's conventions for +`Real.log`, division and `Real.sqrt` and carries no meaning; it need not be `0` +(for example `M₂/M₁² < −1` with `T > 0` gives a positive value). -/ +noncomputable def basketEffVol {n : ℕ} (w F σ : Fin n → ℝ) (ρ : Fin n → Fin n → ℝ) (T : ℝ) : ℝ := + Real.sqrt (Real.log (basketM2 w F σ ρ T / (basketM1 w F) ^ 2) / T) + +/-- **The moment-matching basket call price**: the Garman-normal BS closed +form at `A = DF · M₁`, discount factor `DF`, and the matched effective +volatility. Documented as an **approximation**: the true basket law is not +lognormal, so this is not claimed to equal the discounted expected basket +payoff — only that it is literally the BS closed form at these matched +moments. -/ +noncomputable def basketMomentMatchPrice {n : ℕ} (w F σ : Fin n → ℝ) (ρ : Fin n → Fin n → ℝ) + (K DF T : ℝ) : ℝ := + bsVGarman (DF * basketM1 w F) K DF (basketEffVol w F σ ρ T) T + +/-- **Single-asset consistency check**: a "basket" of one asset with weight +`1` and (trivial) self-correlation `1` collapses the moment-matched +effective vol to exactly that asset's own volatility `σ`, for `F ≠ 0`, `T > 0` +and `σ ≥ 0`. A one-asset basket is lognormal, and the matching recovers its +volatility; the statement is about `basketEffVol`, not about the price. -/ +theorem basketEffVol_single (F σ T : ℝ) (hF : F ≠ 0) (hT : 0 < T) (hσ : 0 ≤ σ) : + basketEffVol (n := 1) (fun _ ↦ 1) (fun _ ↦ F) (fun _ ↦ σ) (fun _ _ ↦ 1) T = σ := by + unfold basketEffVol basketM2 basketM1 + simp only [Fin.sum_univ_one, one_mul, mul_one] + rw [show F * F * Real.exp (σ * σ * T) / F ^ 2 = Real.exp (σ * σ * T) by + field_simp] + rw [Real.log_exp, show σ * σ * T / T = σ ^ 2 by field_simp] + exact Real.sqrt_sq hσ + + +/-! ### One asset: the matched price is the Black–Scholes call -/ + +/-- **A one-asset basket is priced exactly by `bsV`.** With weight `1`, forward +`F = S·e^{rT}`, discount factor `e^{−rT}` and self-correlation `1`, the moment-matched price +is the Black–Scholes call `bsV K r σ S T`: the matched volatility is `σ` +(`basketEffVol_single`), `DF·M₁ = S`, and `bsV` is the Garman form at `DF = e^{−rT}` +(`bsV_eq_bsVGarman_standard`). -/ +theorem basketMomentMatchPrice_single_eq_bsV (S K r σ T : ℝ) (hS : 0 < S) (hK : 0 < K) + (hT : 0 < T) (hσ : 0 ≤ σ) : + basketMomentMatchPrice (n := 1) (fun _ ↦ 1) (fun _ ↦ S * Real.exp (r * T)) (fun _ ↦ σ) + (fun _ _ ↦ 1) K (Real.exp (-(r * T))) T = bsV K r σ S T := by + have hM1 : basketM1 (n := 1) (fun _ ↦ 1) (fun _ ↦ S * Real.exp (r * T)) + = S * Real.exp (r * T) := by + simp [basketM1] + have hA : Real.exp (-(r * T)) * (S * Real.exp (r * T)) = S := by + rw [mul_left_comm, ← Real.exp_add, neg_add_cancel, Real.exp_zero, mul_one] + unfold basketMomentMatchPrice + rw [basketEffVol_single _ σ T (mul_pos hS (Real.exp_pos _)).ne' hT hσ, hM1, hA, + bsV_eq_bsVGarman_standard K r σ S T hS hK] + +/-- **For one asset the moment-matching approximation is exact**: under the Black–Scholes +lognormal hypothesis, the one-asset moment-matched price equals the discounted expected call +payoff (`basketMomentMatchPrice_single_eq_bsV` and `integral_bsCall_payoff_eq_bsV`). -/ +theorem basketMomentMatchPrice_single_eq_integral {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] {S K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S K r σ T Z) : + basketMomentMatchPrice (n := 1) (fun _ ↦ 1) (fun _ ↦ S * Real.exp (r * T)) (fun _ ↦ σ) + (fun _ _ ↦ 1) K (Real.exp (-(r * T))) T + = ∫ ω, Real.exp (-r * T) * max (bsTerminal S r σ T (Z ω) - K) 0 ∂Q := by + rw [basketMomentMatchPrice_single_eq_bsV S K r σ T h.S_0_pos h.K_pos h.T_pos h.σ_pos.le, + integral_bsCall_payoff_eq_bsV h] + +/-! ### `M₁` and `M₂` are the basket's moments in the joint lognormal model -/ + +/-- The unit-mean lognormal factor `e^{σ√T·w − σ²T/2}` of one asset of the basket: the asset's +terminal value is its forward times this factor at its standard-normal driver `w`. -/ +noncomputable def basketLognormalFactor (σ T w : ℝ) : ℝ := + Real.exp (σ * Real.sqrt T * w - σ ^ 2 * T / 2) + +section Moments + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + +/-- The lognormal factor of a standard-normal driver has mean `1`: +`𝔼[e^{σ√T·W − σ²T/2}] = 1`, the standard-normal moment generating function. -/ +lemma integral_basketLognormalFactor {W : Ω → ℝ} (hW : HasLaw W (gaussianReal 0 1) P) + (σ : ℝ) {T : ℝ} (hT : 0 ≤ T) : + ∫ ω, basketLognormalFactor σ T (W ω) ∂P = 1 := by + have := hW.isProbabilityMeasure + have hmgf : ∫ ω, Real.exp (σ * Real.sqrt T * W ω) ∂P + = Real.exp ((σ * Real.sqrt T) ^ 2 / 2) := by + simpa [mgf] using mgf_gaussianReal hW (σ * Real.sqrt T) + have hfun : (fun ω ↦ basketLognormalFactor σ T (W ω)) + = fun ω ↦ Real.exp (-(σ ^ 2 * T / 2)) * Real.exp (σ * Real.sqrt T * W ω) := by + funext ω + simp only [basketLognormalFactor] + rw [← Real.exp_add] + congr 1 + ring + rw [hfun, integral_const_mul, hmgf, ← Real.exp_add, mul_pow, Real.sq_sqrt hT, neg_add_cancel, + Real.exp_zero] + +/-- The lognormal factor of a Gaussian driver is integrable. -/ +lemma integrable_basketLognormalFactor {W : Ω → ℝ} (hW : HasLaw W (gaussianReal 0 1) P) + (σ T : ℝ) : Integrable (fun ω ↦ basketLognormalFactor σ T (W ω)) P := by + have h := (gaussianReal_sub_const (gaussianReal_const_mul hW (σ * Real.sqrt T)) + (σ ^ 2 * T / 2)).integrable_fun_comp (integrable_exp_mul_gaussianReal 1) + simp only [one_mul] at h + exact h + +/-- **Cross-moment of two correlated lognormal factors**: for a jointly Gaussian pair of +standard normals with covariance `ρ`, `𝔼[e^{σ₁√T·U − σ₁²T/2} · e^{σ₂√T·V − σ₂²T/2}] = +e^{ρσ₁σ₂T}`. -/ +lemma integral_basketLognormalFactor_mul {U V : Ω → ℝ} {ρ : ℝ} + (hUV : HasGaussianLaw (fun ω ↦ (U ω, V ω)) P) + (hU : HasLaw U (gaussianReal 0 1) P) (hV : HasLaw V (gaussianReal 0 1) P) + (hcov : cov[U, V; P] = ρ) (σ₁ σ₂ : ℝ) {T : ℝ} (hT : 0 ≤ T) : + ∫ ω, basketLognormalFactor σ₁ T (U ω) * basketLognormalFactor σ₂ T (V ω) ∂P + = Real.exp (ρ * σ₁ * σ₂ * T) := by + have hfun : (fun ω ↦ basketLognormalFactor σ₁ T (U ω) * basketLognormalFactor σ₂ T (V ω)) + = fun ω ↦ Real.exp (-(σ₁ ^ 2 * T / 2 + σ₂ ^ 2 * T / 2)) * + Real.exp (σ₁ * Real.sqrt T * U ω + σ₂ * Real.sqrt T * V ω) := by + funext ω + simp only [basketLognormalFactor] + rw [← Real.exp_add, ← Real.exp_add] + congr 1 + ring + rw [hfun, integral_const_mul, + integral_exp_linear_gaussianPair hUV hU hV hcov (σ₁ * Real.sqrt T) (σ₂ * Real.sqrt T), + ← Real.exp_add] + congr 1 + linear_combination (σ₁ ^ 2 / 2 + σ₁ * σ₂ * ρ + σ₂ ^ 2 / 2) * Real.sq_sqrt hT + +/-- The product of two lognormal factors of a jointly Gaussian pair is integrable. -/ +lemma integrable_basketLognormalFactor_mul {U V : Ω → ℝ} {ρ : ℝ} + (hUV : HasGaussianLaw (fun ω ↦ (U ω, V ω)) P) + (hU : HasLaw U (gaussianReal 0 1) P) (hV : HasLaw V (gaussianReal 0 1) P) + (hcov : cov[U, V; P] = ρ) (σ₁ σ₂ T : ℝ) : + Integrable (fun ω ↦ basketLognormalFactor σ₁ T (U ω) * basketLognormalFactor σ₂ T (V ω)) + P := by + have h := (gaussianReal_sub_const + (hasLaw_linear_gaussianPair hUV hU hV hcov (σ₁ * Real.sqrt T) (σ₂ * Real.sqrt T)) + (σ₁ ^ 2 * T / 2 + σ₂ ^ 2 * T / 2)).integrable_fun_comp + (integrable_exp_mul_gaussianReal 1) + simp only [one_mul] at h + refine h.congr (ae_of_all _ fun ω ↦ ?_) + simp only [basketLognormalFactor] + rw [← Real.exp_add] + congr 1 + ring + +variable {n : ℕ} {W : Fin n → Ω → ℝ} + +/-- **`M₁` is the basket's mean.** If each driver `Wᵢ` is standard normal, the basket +`B_T = ∑ᵢ wᵢ Fᵢ e^{σᵢ√T·Wᵢ − σᵢ²T/2}` has mean `∑ᵢ wᵢ Fᵢ = basketM1 w F`. -/ +theorem integral_basket_eq_basketM1 (hstd : ∀ i, HasLaw (W i) (gaussianReal 0 1) P) + (w F σ : Fin n → ℝ) {T : ℝ} (hT : 0 ≤ T) : + ∫ ω, ∑ i, w i * (F i * basketLognormalFactor (σ i) T (W i ω)) ∂P = basketM1 w F := by + rw [integral_finsetSum _ fun i _ ↦ + ((integrable_basketLognormalFactor (hstd i) (σ i) T).const_mul (F i)).const_mul (w i)] + unfold basketM1 + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [integral_const_mul, integral_const_mul, integral_basketLognormalFactor (hstd i) (σ i) hT, + mul_one] + +/-- **`M₂` is the basket's second moment.** If each pair of drivers `(Wᵢ, Wⱼ)` is jointly +Gaussian with standard-normal margins and covariance `ρᵢⱼ`, the basket +`B_T = ∑ᵢ wᵢ Fᵢ e^{σᵢ√T·Wᵢ − σᵢ²T/2}` has `𝔼[B_T²] = ∑ᵢ∑ⱼ wᵢwⱼFᵢFⱼ e^{ρᵢⱼσᵢσⱼT} = +basketM2 w F σ ρ T`. -/ +theorem integral_basket_sq_eq_basketM2 {ρ : Fin n → Fin n → ℝ} + (hpair : ∀ i j, HasGaussianLaw (fun ω ↦ (W i ω, W j ω)) P) + (hstd : ∀ i, HasLaw (W i) (gaussianReal 0 1) P) + (hcorr : ∀ i j, cov[W i, W j; P] = ρ i j) + (w F σ : Fin n → ℝ) {T : ℝ} (hT : 0 ≤ T) : + ∫ ω, (∑ i, w i * (F i * basketLognormalFactor (σ i) T (W i ω))) ^ 2 ∂P + = basketM2 w F σ ρ T := by + have hint : ∀ i j, Integrable (fun ω ↦ basketLognormalFactor (σ i) T (W i ω) * + basketLognormalFactor (σ j) T (W j ω)) P := fun i j ↦ + integrable_basketLognormalFactor_mul (hpair i j) (hstd i) (hstd j) (hcorr i j) _ _ _ + have hexpand : ∀ ω, (∑ i, w i * (F i * basketLognormalFactor (σ i) T (W i ω))) ^ 2 + = ∑ i, ∑ j, w i * w j * F i * F j * + (basketLognormalFactor (σ i) T (W i ω) * basketLognormalFactor (σ j) T (W j ω)) := + fun ω ↦ by + rw [pow_two, Finset.sum_mul_sum] + exact Finset.sum_congr rfl fun i _ ↦ Finset.sum_congr rfl fun j _ ↦ by ring + simp_rw [hexpand] + rw [integral_finsetSum _ fun i _ ↦ integrable_finsetSum _ fun j _ ↦ (hint i j).const_mul _] + unfold basketM2 + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [integral_finsetSum _ fun j _ ↦ (hint i j).const_mul _] + refine Finset.sum_congr rfl fun j _ ↦ ?_ + rw [integral_const_mul, integral_basketLognormalFactor_mul (hpair i j) (hstd i) (hstd j) + (hcorr i j) _ _ hT] + +end Moments + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/BinaryBarrierOption.lean b/LeanPool/MathFin/Models/BlackScholes/BinaryBarrierOption.lean new file mode 100644 index 0000000000..0c0eac6e76 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/BinaryBarrierOption.lean @@ -0,0 +1,253 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.BlackScholes + +/-! +# Binary (digital) barrier options: Rubinstein & Reiner's closed form + +A digital (cash-or-nothing / asset-or-nothing) option that is additionally knocked in or +knocked out by a single barrier `H` (Rubinstein & Reiner, *Risk* 4(9) (1991); Haug, *The Complete +Guide to Option Pricing Formulas*, 2nd ed. (2007), ch. 4, "Binary Barrier Options"). Unlike the +two-asset barriers in +`HeynenKatTwoAssetBarrier.lean`, this is single-underlying, single-variable Black–Scholes +machinery — no bivariate normal CDF needed. + +Transcribed from QuantLib's +`ql/pricingengines/barrier/analyticbinarybarrierengine.cpp` +(`AnalyticBinaryBarrierEngine_helper::payoffAtExpiry`, upstream commit `6efc1ed`, 2026-09-23). +QuantLib computes a *drift* `mu` once (`mu = log(dividendDiscount/discount)/variance − 1/2`, +which for constant cost-of-carry `b = r − q` is `(b − σ²/2)/σ²`, i.e. the same `hkMu`-style +drift divided by `σ²`) and shares one formula shape between the **cash-or-nothing** payoff +(`K` = the fixed cash amount) and the **asset-or-nothing** payoff (`mu` shifted by `+1`, `K` = +the forward price `S·e^{bT}`, QuantLib's `spot·dividendDiscount/discount`). We keep `mu` an +explicit parameter rather than hard-wiring either case, exactly mirroring QuantLib's shared +code path — the docstrings below name which +`mu`/`K` substitution each payoff kind uses, but the lemmas hold for the shared formula shape +regardless of which substitution is made. + +With `stdDev = σ√T`, `η = 1` for `Down{In,Out}` / `η = −1` for `Up{In,Out}`, `φ = 1` for a call / +`φ = −1` for a put: + + `x₁ = φ(log(S/X)/stdDev + μ·stdDev)`, `x₂ = φ(log(S/H)/stdDev + μ·stdDev)`, + `y₁ = η(log(H²/(SX))/stdDev + μ·stdDev)`, `y₂ = η(log(H/S)/stdDev + μ·stdDev)`, + +and, with `(H/S)^{2μ}` written as `exp(2μ·log(H/S))` (algebraically identical for `S, H > 0`; +QuantLib's own overflow guard evaluates the product `(H/S)^{2μ}·Φ(y)` as a whole in logs, +`exp(2μ·log(H/S) + log Φ(y))`, rather than this factor alone), + + `B₁ = Φ(x₁)`, `B₂ = Φ(x₂)`, `B₃ = (H/S)^{2μ}·Φ(y₁)`, `B₄ = (H/S)^{2μ}·Φ(y₂)`. + +QuantLib's 16-branch `switch` (barrier type × call/put × strike-vs-barrier) selects one of +`B₁, B₂, B₃, B₄` and their `±` combinations per branch; the final price is `discount·K·α`. The +16 branches are transcribed verbatim below as `bboDownInAlpha`/`bboDownOutAlpha` (both share +`η = 1`) and `bboUpInAlpha`/`bboUpOutAlpha` (both share `η = −1`). + +## Main definitions + +* `bboPhiOf`: the sign `φ`, equal to `1` for a call and `-1` for a put. +* `bboX1`, `bboX2`, `bboY1`, `bboY2`: the exponents of the four terms, struck at `X` (`x₁`), at the + barrier `H` (`x₂`), at the reflected log `log (H²/(S X))` (`y₁`) and at `log (H/S)` (`y₂`). +* `bboHS2mu`: the factor `(H/S)^{2μ}`, written as `exp (2μ · log (H/S))`. +* `bboB1`, `bboB2`, `bboB3`, `bboB4`: the four building blocks `B₁` to `B₄` of the Rubinstein and + Reiner binary-barrier formulas. +* `bboDownInAlpha`, `bboDownOutAlpha`, `bboUpInAlpha`, `bboUpOutAlpha`: the knock-in and knock-out + `α`-factors for a down or up barrier (before the discount and payoff scale), each selected from + `B₁` to `B₄` by `isCall` and the strike-barrier comparison `xGeH`. + +## Main results + +* `bboDownIn_add_DownOut`: knock-in + knock-out, same direction/type/regime, collapses to the + vanilla digital α-factor `B₁` — the barrier-hit event and its complement partition the payoff + (the closed-form counterpart of `BarrierParity.lean`'s + `knockIn_add_knockOut_eq_vanilla`, checked on the literal 16-branch table; not derived from + it here). Checked for every `(isCall, xGeH)` combination by `decide`-free case split. +* `bboUpIn_add_UpOut`: the same parity for the up-barrier family (`η = −1`). +* `bboB1_eq_Phi_bsd2`: at the risk-neutral drift `μ = (r − σ²/2)/σ²` the vanilla exponent + `x₁` is Black–Scholes' `d₂` (`bsd2 S X r σ T`) — `B₁` is the standard-normal factor of the + cash-or-nothing digital. +* `value_digitalCall_eq_bboB1`: under `BSCallHyp`, the Black–Scholes value of the digital call + contract `Contracts.digitalCall K T` is the parity's vanilla leg `e^{−rT}·B₁` (call side), + through `Contracts.BlackScholes.value_digitalCall`. + +**Scope, disclosed honestly**: this is a transcription of the QuantLib closed form, not a +from-first-principles reflection-principle derivation of the barrier density. The in–out +identity here is the closed-form counterpart of the measure-theoretic parity +`knockIn_add_knockOut_eq_vanilla` (`BarrierParity.lean`): the barrier-hit event and its +complement partition the payoff, so knock-in + knock-out must equal the vanilla leg `B₁` — +and the 16-branch table satisfies it branch-by-branch (a misplaced `+`/`−` sign on any one of +the 14 sign-bearing QuantLib branches breaks it; the other two branches are the constant `0`), +though by pure term cancellation once the table is fixed. The vanilla leg alone is +grounded beyond transcription: `value_digitalCall_eq_bboB1` proves that, on the call side and +at the risk-neutral drift, `e^{−rT}·B₁` is the Black–Scholes value of the digital call contract. The +knock-in and knock-out terms are not proved to be prices. The `variance += 0` and `(H/S)^{2μ}` overflow edge cases QuantLib special-cases numerically, and the +already-knocked-in/knocked-out spot guards `AnalyticBinaryBarrierEngine::calculate()` applies +*before* calling `payoffAtExpiry` (a `DownOut`/`UpOut` priced at `0` once the spot has already +crossed the barrier, a `DownIn`/`UpIn` re-priced as a plain vanilla digital via +`AnalyticEuropeanEngine` once it has), are all out of scope — this file formalizes exactly +`payoffAtExpiry`'s own closed form, for a spot strictly on the live side of the barrier. + +## References + +* [Haug, *The Complete Guide to Option Pricing Formulas*][Haug2007], ch. 4 +* [Rubinstein and Reiner (1991)][RubinsteinReiner1991] + +## Tags + +digital barrier option, Rubinstein–Reiner, cash-or-nothing, knock-in knock-out, exotic option, +closed-form pricing, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory +open scoped NNReal + +/-- `φ(isCall) = 1` for a call, `−1` for a put (QuantLib's `phi`). -/ +noncomputable def bboPhiOf (isCall : Bool) : ℝ := if isCall then 1 else -1 + +/-- **`x₁`**: the `B₁`-side exponent for the payoff struck at `X`. -/ +noncomputable def bboX1 (S X mu σ T phi : ℝ) : ℝ := + phi * (Real.log (S / X) / (σ * Real.sqrt T) + mu * σ * Real.sqrt T) + +/-- **`x₂`**: the `B₂`-side exponent, struck at the barrier `H` instead of `X`. -/ +noncomputable def bboX2 (S H mu σ T phi : ℝ) : ℝ := + phi * (Real.log (S / H) / (σ * Real.sqrt T) + mu * σ * Real.sqrt T) + +/-- **`y₁`**: the `B₃`-side exponent, built from the reflected log `log(H²/(SX))`. -/ +noncomputable def bboY1 (S X H mu σ T eta : ℝ) : ℝ := + eta * (Real.log (H ^ 2 / (S * X)) / (σ * Real.sqrt T) + mu * σ * Real.sqrt T) + +/-- **`y₂`**: the `B₄`-side exponent, built from `log(H/S)`. -/ +noncomputable def bboY2 (S H mu σ T eta : ℝ) : ℝ := + eta * (Real.log (H / S) / (σ * Real.sqrt T) + mu * σ * Real.sqrt T) + +/-- **`(H/S)^{2μ}`**, written as `exp(2μ·log(H/S))` — algebraically the same value for +`S, H > 0`. QuantLib's own overflow guard evaluates this factor together with its `Φ(y)` +multiplier as one logged product, not this factor alone. -/ +noncomputable def bboHS2mu (S H mu : ℝ) : ℝ := Real.exp (2 * mu * Real.log (H / S)) + +/-- **`B₁`**: the vanilla (barrier-free) digital `α`-factor for the `isCall` side — cash-or-nothing +or asset-or-nothing depending on which `mu`/`K` substitution is made (see the module docstring); +the price itself is `discount·K·B₁`, not `B₁` alone. -/ +noncomputable def bboB1 (S X mu σ T : ℝ) (isCall : Bool) : ℝ := + Phi (bboX1 S X mu σ T (bboPhiOf isCall)) + +/-- **`B₂`**: `B₁` with the strike replaced by the barrier `H`. -/ +noncomputable def bboB2 (S H mu σ T : ℝ) (isCall : Bool) : ℝ := + Phi (bboX2 S H mu σ T (bboPhiOf isCall)) + +/-- **`B₃`**: the reflected term paired with `B₁` across the barrier. -/ +noncomputable def bboB3 (S X H mu σ T eta : ℝ) : ℝ := + bboHS2mu S H mu * Phi (bboY1 S X H mu σ T eta) + +/-- **`B₄`**: the reflected term paired with `B₂` across the barrier. -/ +noncomputable def bboB4 (S H mu σ T eta : ℝ) : ℝ := + bboHS2mu S H mu * Phi (bboY2 S H mu σ T eta) + +/-- **Down-barrier knock-in value** (`η = 1`), QuantLib's `DownIn` switch case: `B₃` when +`isCall` and the strike dominates the barrier (`xGeH`), `B₁ − B₂ + B₄` when `isCall` and +`X < H`, `B₂ − B₃ + B₄` for a put with `X ≥ H`, and `B₁` for a put with `X < H`. -/ +noncomputable def bboDownInAlpha (S X H mu σ T : ℝ) (isCall xGeH : Bool) : ℝ := + match isCall, xGeH with + | true, true => bboB3 S X H mu σ T 1 + | true, false => bboB1 S X mu σ T true - bboB2 S H mu σ T true + bboB4 S H mu σ T 1 + | false, true => bboB2 S H mu σ T false - bboB3 S X H mu σ T 1 + bboB4 S H mu σ T 1 + | false, false => bboB1 S X mu σ T false + +/-- **Down-barrier knock-out value** (`η = 1`), QuantLib's `DownOut` switch case: `B₁ − B₃`, +`B₂ − B₄`, `B₁ − B₂ + B₃ − B₄`, or `0`, selected the same way as `bboDownInAlpha`. -/ +noncomputable def bboDownOutAlpha (S X H mu σ T : ℝ) (isCall xGeH : Bool) : ℝ := + match isCall, xGeH with + | true, true => bboB1 S X mu σ T true - bboB3 S X H mu σ T 1 + | true, false => bboB2 S H mu σ T true - bboB4 S H mu σ T 1 + | false, true => + bboB1 S X mu σ T false - bboB2 S H mu σ T false + bboB3 S X H mu σ T 1 - bboB4 S H mu σ T 1 + | false, false => 0 + +/-- **Up-barrier knock-in value** (`η = −1`), QuantLib's `UpIn` switch case: `B₁`, `B₂ − B₃ + B₄`, +`B₁ − B₂ + B₄`, or `B₃`, selected the same way as `bboDownInAlpha` (note the branches swap +relative to `DownIn`: the `isCall ∧ xGeH` branch is `B₁` here, not `B₃`). -/ +noncomputable def bboUpInAlpha (S X H mu σ T : ℝ) (isCall xGeH : Bool) : ℝ := + match isCall, xGeH with + | true, true => bboB1 S X mu σ T true + | true, false => bboB2 S H mu σ T true - bboB3 S X H mu σ T (-1) + bboB4 S H mu σ T (-1) + | false, true => bboB1 S X mu σ T false - bboB2 S H mu σ T false + bboB4 S H mu σ T (-1) + | false, false => bboB3 S X H mu σ T (-1) + +/-- **Up-barrier knock-out value** (`η = −1`), QuantLib's `UpOut` switch case: `0`, +`B₁ − B₂ + B₃ − B₄`, `B₂ − B₄`, or `B₁ − B₃`. -/ +noncomputable def bboUpOutAlpha (S X H mu σ T : ℝ) (isCall xGeH : Bool) : ℝ := + match isCall, xGeH with + | true, true => 0 + | true, false => + bboB1 S X mu σ T true - bboB2 S H mu σ T true + bboB3 S X H mu σ T (-1) + - bboB4 S H mu σ T (-1) + | false, true => bboB2 S H mu σ T false - bboB4 S H mu σ T (-1) + | false, false => bboB1 S X mu σ T false - bboB3 S X H mu σ T (-1) + +/-- **In–out parity, down-barrier family**: for every call/put choice and every +strike-vs-barrier regime, the down-knock-in and down-knock-out values (QuantLib's `DownIn` and +`DownOut` switch cases, `η = 1` throughout) sum to the vanilla digital α-factor `B₁` — the +closed-form counterpart of `knockIn_add_knockOut_eq_vanilla`'s partition identity (not derived +from it here). Each of the +four `(isCall, xGeH)` branches cancels its `B₂, B₃, B₄` terms against the paired branch +independently (so a transposed sign on any one of the seven sign-bearing `Down*` branches +would break exactly that case; the eighth, the knock-out put with `X < H`, is the constant +`0`). On the call side, `value_digitalCall_eq_bboB1` identifies `e^{−rT}·B₁` with the value +of the digital call contract. -/ +theorem bboDownIn_add_DownOut (S X H mu σ T : ℝ) (isCall xGeH : Bool) : + bboDownInAlpha S X H mu σ T isCall xGeH + bboDownOutAlpha S X H mu σ T isCall xGeH + = bboB1 S X mu σ T isCall := by + cases isCall <;> cases xGeH <;> + simp only [bboDownInAlpha, bboDownOutAlpha] <;> ring + +/-- **In–out parity, up-barrier family**: the same parity for `UpIn`/`UpOut` (`η = −1` +throughout). -/ +theorem bboUpIn_add_UpOut (S X H mu σ T : ℝ) (isCall xGeH : Bool) : + bboUpInAlpha S X H mu σ T isCall xGeH + bboUpOutAlpha S X H mu σ T isCall xGeH + = bboB1 S X mu σ T isCall := by + cases isCall <;> cases xGeH <;> + simp only [bboUpInAlpha, bboUpOutAlpha] <;> ring + +/-- **The vanilla leg is Black–Scholes' cash-or-nothing factor.** At the risk-neutral drift +`μ = (r − σ²/2)/σ²`, the `B₁` exponent `x₁ = log(S/X)/(σ√T) + μσ√T` is exactly Black–Scholes' +`d₂` with the same strike/rate/vol (`bsd2 S X r σ T`, `Models/BlackScholes/Call.lean`): the two +disagree by `μσ²T − (r − σ²/2)T = 0`. -/ +theorem bboB1_eq_Phi_bsd2 (S X r σ T mu : ℝ) (hσ : σ ≠ 0) (hT : 0 < T) + (hmu : mu = (r - σ ^ 2 / 2) / σ ^ 2) : + bboB1 S X mu σ T true = Phi (bsd2 S X r σ T) := by + have hsqrt : σ * Real.sqrt T ≠ 0 := + mul_ne_zero hσ (ne_of_gt (Real.sqrt_pos.mpr hT)) + simp only [bboB1, bboX1, bboPhiOf, ite_true, one_mul, bsd2, bsd1] + congr 1 + rw [hmu] + field_simp + simp only [Real.sq_sqrt (le_of_lt hT)] + ring + +/-- **The parity's vanilla leg is the price of the digital call contract.** Under `BSCallHyp` +and at the risk-neutral drift `μ = (r − σ²/2)/σ²`, the value of the contract +`Contracts.digitalCall K T` (pay `1` at `T` if `S_T > K`) in the Black–Scholes model is the +discounted vanilla leg `e^{−rT}·B₁` (call side) of both parity theorems: +`Contracts.BlackScholes.value_digitalCall` prices it at `e^{−rT}·Φ(d₂)`, and +`bboB1_eq_Phi_bsd2` identifies `Φ(d₂)` with `B₁`. -/ +theorem value_digitalCall_eq_bboB1 {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] {S_0 K r σ mu : ℝ} {T : ℝ≥0} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) (hmu : mu = (r - σ ^ 2 / 2) / σ ^ 2) : + (Contracts.digitalCall K T).value Q (fun _ _ ↦ Real.exp (-r * T)) + (Contracts.BlackScholes.assets S_0 r σ T Z) + = Real.exp (-r * T) * bboB1 S_0 K mu σ T true := by + rw [Contracts.BlackScholes.value_digitalCall h, + bboB1_eq_Phi_bsd2 S_0 K r σ T mu h.σ_pos.ne' h.T_pos hmu] + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/BisectionIV.lean b/LeanPool/MathFin/Models/BlackScholes/BisectionIV.lean new file mode 100644 index 0000000000..42af82bd2b --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/BisectionIV.lean @@ -0,0 +1,88 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.ImpliedVolatility +public import LeanPool.MathFin.Probability.Analysis.Bisection + +/-! +# Implied volatility by bisection + +For `K, S, T > 0` the Black–Scholes call price is continuous and strictly +increasing in `σ > 0` (`bsV_continuousOn_sigma`, `bsV_strictMonoOn_sigma`). Take +a volatility bracket `0 < σ_lo < σ_hi` whose prices straddle a market price +`C_obs`. The intermediate value theorem puts an implied volatility `σ` strictly +inside the bracket, and strict monotonicity makes it the only positive one. It +also makes `σ` the threshold of the price against `C_obs`, which is all the +bisection method (`Probability/Analysis/Bisection.lean`) needs to converge to it. + +## Main results + +* `impliedVol_bracket_exists`: for `f` continuous and strictly increasing on + `[σ_lo, σ_hi]`, a target strictly between `f σ_lo` and `f σ_hi` is attained + at a unique `σ ∈ (σ_lo, σ_hi)`. +* `impliedVol_bisection_converges`: bisection on the BS call price converges to + the implied volatility, within `(σ_hi − σ_lo) / 2ⁿ⁺¹` after `n` steps. + +## References + +* [Burden and Faires, *Numerical Analysis*][BurdenFaires], §2.1 +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull] +* [Press and others, *Numerical Recipes*][PressEtAlNumericalRecipes], §9.1 + +## Tags + +implied volatility, bisection method, intermediate value, volatility bracket, root finding, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Filter Topology + +/-- **Bracket existence and uniqueness** (the existence half of bisection): for +`f` continuous and strictly increasing on `[σ_lo, σ_hi]`, any target strictly +between `f σ_lo` and `f σ_hi` is attained at a unique `σ ∈ (σ_lo, σ_hi)`. The +intermediate value theorem gives a root strictly inside the bracket; strict +monotonicity makes it unique. -/ +lemma impliedVol_bracket_exists + {f : ℝ → ℝ} {σ_lo σ_hi C_obs : ℝ} + (h_lo_lt_hi : σ_lo < σ_hi) + (h_cont : ContinuousOn f (Set.Icc σ_lo σ_hi)) + (h_mono : StrictMonoOn f (Set.Icc σ_lo σ_hi)) + (h_brkt : f σ_lo < C_obs ∧ C_obs < f σ_hi) : + ∃! σ : ℝ, σ ∈ Set.Ioo σ_lo σ_hi ∧ f σ = C_obs := by + obtain ⟨σ, hσ, rfl⟩ := intermediate_value_Ioo h_lo_lt_hi.le h_cont h_brkt + exact ⟨σ, ⟨hσ, rfl⟩, fun σ' ⟨hσ', h⟩ ↦ + h_mono.injOn (Set.Ioo_subset_Icc_self hσ') (Set.Ioo_subset_Icc_self hσ) h⟩ + +/-- **Bisection converges to the implied volatility.** For `K, S, T > 0`, any +rate `r`, and a bracket `0 < σ_lo < σ_hi` whose Black–Scholes call prices +straddle the market price `C_obs`, there is an implied volatility +`σ ∈ (σ_lo, σ_hi)`, it is the only positive one, and the bisection estimates +converge to it, within `(σ_hi − σ_lo) / 2ⁿ⁺¹` after `n` steps. -/ +theorem impliedVol_bisection_converges {K r T S σ_lo σ_hi C_obs : ℝ} + (hK : 0 < K) (hT : 0 < T) (hS : 0 < S) (h_lo : 0 < σ_lo) (h_lo_hi : σ_lo < σ_hi) + (h_brkt : bsV K r σ_lo S T < C_obs ∧ C_obs < bsV K r σ_hi S T) : + ∃ σ ∈ Set.Ioo σ_lo σ_hi, bsV K r σ S T = C_obs ∧ + (∀ σ' > 0, bsV K r σ' S T = C_obs → σ' = σ) ∧ + (∀ n, |bisectMid (fun v ↦ bsV K r v S T) C_obs σ_lo σ_hi n - σ| ≤ + (σ_hi - σ_lo) / 2 ^ (n + 1)) ∧ + Tendsto (bisectMid (fun v ↦ bsV K r v S T) C_obs σ_lo σ_hi) atTop (𝓝 σ) := by + have hpos : Set.Icc σ_lo σ_hi ⊆ Set.Ioi 0 := fun v hv ↦ h_lo.trans_le hv.1 + have hmono := (bsV_strictMonoOn_sigma (r := r) hK hT hS).mono hpos + obtain ⟨σ, ⟨hσ, rfl⟩, -⟩ := impliedVol_bracket_exists h_lo_hi + ((bsV_continuousOn_sigma hK hT hS).mono hpos) hmono h_brkt + have hσ' := Set.Ioo_subset_Icc_self hσ + have hC (x : ℝ) (hx : x ∈ Set.Icc σ_lo σ_hi) := hmono.lt_iff_lt hx hσ' + exact ⟨σ, hσ, rfl, fun σ' hσ'0 h ↦ implied_volatility_unique hK hT hS hσ'0 + (h_lo.trans hσ.1) h, abs_bisectMid_sub_le hC hσ', tendsto_bisectMid hC hσ'⟩ + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/BlackScholes.lean b/LeanPool/MathFin/Models/BlackScholes/BlackScholes.lean new file mode 100644 index 0000000000..20d65bb9a4 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/BlackScholes.lean @@ -0,0 +1,182 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.Parity +public import LeanPool.MathFin.Models.BlackScholes.Digital +public import LeanPool.MathFin.Models.BlackScholes.Put +public import LeanPool.MathFin.Models.BlackScholes.Forward +public import LeanPool.MathFin.Models.BlackScholes.PowerCall + +/-! +# The contracts priced in the Black–Scholes model + +`Contracts/Instruments/Options.lean` defines the instruments and says what they pay; this file +prices them in one model. `BlackScholes.assets` is the single-asset Black–Scholes market as a +model map, and each instrument's `Contract.value` under it is the closed form +`MathFin/BlackScholes/` already proves. Another model gets its own file of the same shape and its +own namespace (`Models/Binomial/Binomial.lean`, `Contracts.Binomial`); the instruments do not +change. + +`BlackScholes.assets` is constant in `t`: every instrument priced here observes the underlying +only at its maturity `T`, so the model's value at other times is irrelevant to what gets priced. A +path-dependent instrument needs the full path and is deferred. + +Nothing new is proved about Black–Scholes here. A single cash flow's value is the integral of +its discounted payoff (`Contract.value_pay`), which is exactly the integral `bs_call_formula`, +`bs_put_formula` and `bs_cash_or_nothing_formula` compute. The capped call is priced by +composition: `Contract.value_both` and `Contract.value_scale` reduce it to two call values, and +no third integral is evaluated. + +## Main definitions + +* `BlackScholes.assets` — the single-asset Black–Scholes model as a model map `Unit → ℝ≥0 → Ω → ℝ`, + constant in `t` and equal to `bsTerminal` at every time. + +## Main results + +* `value_europeanCall`, `value_europeanPut`, `value_digitalCall` — each instrument's value is + `bs_call_formula`, `bs_put_formula` and `bs_cash_or_nothing_formula` respectively. +* `value_forward` — the forward is worth `S₀ − K e^{−rT}`. +* `value_cappedCall` — the capped call is worth the difference of two call values. +* `value_powerCall` — the power call is `bs_power_call_formula`. + +## Source + +The layered separation of contract semantics from pricing semantics, and the +framing "the contract is not the model", are due to Paul Bilokon, +*The Contract Is Not the Model: Proof-Carrying Exotic Derivatives and the +Economics of Model Risk* (working paper, 9 August 2026; Mathematical +Finance, Imperial College London), with code at + (Apache-2.0). That paper in +turn builds on the compositional contract-DSL of +Peyton Jones, Eber and Seward (2000) and the certified-contract work of Bahr, +Berthold and Elsman (2015) and Annenkov (2018). + +The source paper's §"Pricing-model validation" lists proving contract cashflows +measurable and integrable, and connecting them to a concrete model, as future +work; this file does that reduction against closed forms the library already +proves. + +No code is copied from `lean_contracts`; every definition and proof here is +written for this library. See `docs/specs/2026-08-16-contracts-tower-design.md` +§6 for the full credit line. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 12.3; 15.6; 16.6; 26.4 +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], 4.5 +* [Zhang, *Exotic Options*][ZhangExoticOptions] + +## Tags + +Black–Scholes model, contract pricing, capped call, digital call, power call, lognormal, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal + +namespace MathFin.Contracts.BlackScholes + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- The single-asset Black–Scholes market as a model map. Every instrument in +this file observes only at `T`, so the value at other times is irrelevant; a +path-dependent instance needs the full GBM path and is deferred. -/ +noncomputable def assets (S_0 r σ T : ℝ) (Z : Ω → ℝ) : Unit → ℝ≥0 → Ω → ℝ := + fun _ _ ω ↦ bsTerminal S_0 r σ T (Z ω) + +/-- The reified European call prices to the Black–Scholes call formula: the value of +`europeanCall K T` under `BlackScholes.assets` is exactly `bs_call_formula`'s right-hand side. -/ +theorem value_europeanCall {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ : ℝ} {T : ℝ≥0} {Z : Ω → ℝ} (h : BSCallHyp Q S_0 K r σ T Z) : + (europeanCall K T).value Q (fun _ _ ↦ Real.exp (-r * T)) (assets S_0 r σ T Z) + = S_0 * Phi (bsd1 S_0 K r σ T) - K * Real.exp (-r * T) * Phi (bsd2 S_0 K r σ T) := by + rw [europeanCall, Contract.value_pay] + exact MathFin.bs_call_formula h + +/-- The reified cash-or-nothing digital call prices to the Black–Scholes +cash-or-nothing formula: the value of `digitalCall K T` under `BlackScholes.assets` is exactly +`bs_cash_or_nothing_formula`'s right-hand side. -/ +theorem value_digitalCall {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ : ℝ} {T : ℝ≥0} {Z : Ω → ℝ} (h : BSCallHyp Q S_0 K r σ T Z) : + (digitalCall K T).value Q (fun _ _ ↦ Real.exp (-r * T)) (assets S_0 r σ T Z) + = Real.exp (-r * T) * Phi (bsd2 S_0 K r σ T) := by + rw [digitalCall, Contract.value_pay] + have heq (ω : Ω) : Payoff.eval (scenarioAt (assets S_0 r σ T Z) ω) + ((Payoff.const K).indicatorLt (Payoff.obs () T)) + = (Set.Ioi K).indicator (fun _ ↦ (1 : ℝ)) (bsTerminal S_0 r σ T (Z ω)) := by + simp [Payoff.eval, scenarioAt, assets, Set.indicator_apply, Set.mem_Ioi] + congr 1 + simp only [heq] + exact MathFin.bs_cash_or_nothing_formula h + +/-- The reified European put prices to the Black–Scholes put formula: the value of +`europeanPut K T` under `BlackScholes.assets` is exactly `bs_put_formula`'s right-hand side. -/ +theorem value_europeanPut {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ : ℝ} {T : ℝ≥0} {Z : Ω → ℝ} (h : BSCallHyp Q S_0 K r σ T Z) : + (europeanPut K T).value Q (fun _ _ ↦ Real.exp (-r * T)) (assets S_0 r σ T Z) + = K * Real.exp (-r * T) * Phi (-(bsd2 S_0 K r σ T)) - S_0 * Phi (-(bsd1 S_0 K r σ T)) := by + rw [europeanPut, Contract.value_pay] + exact MathFin.bs_put_formula h + +/-- **The forward's Black–Scholes value** is `S₀ − K e^{−rT}`: the discounted terminal price has +mean `S₀` (`discounted_terminal_eq_S0`), so this is `value_forward_of_integral`. -/ +theorem value_forward {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ : ℝ} {T : ℝ≥0} {Z : Ω → ℝ} (h : BSCallHyp Q S_0 K r σ T Z) : + (forward K T).value Q (fun _ _ ↦ Real.exp (-r * T)) (assets S_0 r σ T Z) + = S_0 - K * Real.exp (-r * T) := + value_forward_of_integral ((integrable_bsTerminal h.Z_law S_0 r σ T).const_mul _) + (by simpa [assets, neg_mul] using discounted_terminal_eq_S0 h) + +/-- **The capped call's Black–Scholes value, by composition, not by a third integral.** +`cappedCall K₁ K₂ T`'s value under the single-asset Black–Scholes model is the difference +of the two `europeanCall` values `value_europeanCall` already supplies. The proof is +`Contract.value_both` and `Contract.value_scale` applied to `value_europeanCall` twice, +closed by `ring` — no unfolding of `Contract.value`, no integral touched here at all; that +is the entire point of having reified `cappedCall` as a composed `Contract` rather than as +one more inline payoff lambda. -/ +theorem value_cappedCall {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K₁ K₂ r σ : ℝ} {T : ℝ≥0} {Z : Ω → ℝ} + (h₁ : BSCallHyp Q S_0 K₁ r σ T Z) (h₂ : BSCallHyp Q S_0 K₂ r σ T Z) : + (cappedCall K₁ K₂ T).value Q (fun _ _ ↦ Real.exp (-r * T)) (assets S_0 r σ T Z) + = (S_0 * Phi (bsd1 S_0 K₁ r σ T) - K₁ * Real.exp (-r * T) * Phi (bsd2 S_0 K₁ r σ T)) + - (S_0 * Phi (bsd1 S_0 K₂ r σ T) - K₂ * Real.exp (-r * T) * Phi (bsd2 S_0 K₂ r σ T)) := by + have hX := (integrable_bsTerminal h₁.Z_law S_0 r σ T).const_mul (Real.exp (-r * T)) + have hi₁ : Integrable (fun ω ↦ (europeanCall K₁ T).pathPV (fun _ ↦ Real.exp (-r * T)) + (scenarioAt (assets S_0 r σ T Z) ω)) Q := integrable_europeanCall_pathPV hX + have hi₂ : Integrable (fun ω ↦ (Contract.scale (-1) (europeanCall K₂ T)).pathPV + (fun _ ↦ Real.exp (-r * T)) (scenarioAt (assets S_0 r σ T Z) ω)) Q := by + simp only [Contract.pathPV_scale] + exact (integrable_europeanCall_pathPV hX).const_mul _ + rw [cappedCall, Contract.value_both _ _ _ _ _ hi₁ hi₂, + Contract.value_scale, value_europeanCall h₁, value_europeanCall h₂] + ring + +/-- **The power call's Black–Scholes value** is the call price at the effective spot and +volatility of `bs_power_call_formula`: `S_T ^ a` is lognormal again, so the value of +`powerCall a K T` is `Š₀ Φ(d_tilde₁) − K e^{−rT} Φ(d_tilde₂)` with `Š₀ = bsPowerEffectiveSpot` and +volatility `aσ`. -/ +theorem value_powerCall {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ : ℝ} {T : ℝ≥0} {Z : Ω → ℝ} (a : ℕ) (ha : 0 < a) (hK : 0 < K) + (h : BSCallHyp Q S_0 K r σ T Z) : + (powerCall a K T).value Q (fun _ _ ↦ Real.exp (-r * T)) (assets S_0 r σ T Z) + = bsPowerEffectiveSpot S_0 r σ T a * + Phi (bsd1 (bsPowerEffectiveSpot S_0 r σ T a) K r ((a : ℝ) * σ) T) + - K * Real.exp (-r * T) * + Phi (bsd2 (bsPowerEffectiveSpot S_0 r σ T a) K r ((a : ℝ) * σ) T) := by + rw [powerCall, Contract.value_pay] + refine Eq.trans ?_ (bs_power_call_formula a ha hK h) + refine integral_congr_ae (.of_forall fun ω ↦ ?_) + simp [Payoff.eval, scenarioAt, assets, bsPowerTerminal] + +end MathFin.Contracts.BlackScholes diff --git a/LeanPool/MathFin/Models/BlackScholes/BlackScholesAsian.lean b/LeanPool/MathFin/Models/BlackScholes/BlackScholesAsian.lean new file mode 100644 index 0000000000..b4a4b5fe3b --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/BlackScholesAsian.lean @@ -0,0 +1,89 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Contracts.Instruments.Options +public import LeanPool.MathFin.Pricing.Value +public import LeanPool.MathFin.Models.BlackScholes.AsianGeometricN + +/-! +# The geometric Asian call priced along the Black–Scholes path + +`Models/BlackScholes/BlackScholes.lean` observes the underlying only at maturity, so its model map +is constant in time. A path-dependent instrument needs the price at several dates: +`BlackScholes.pathAssets` is the Black–Scholes market as a model map with the whole geometric +Brownian path, `S_u = S₀ exp((r − σ²/2)u + σ B_u)`, for a Brownian motion `B`. + +Nothing new is proved about the geometric Asian option. The contract's value is the discounted +expected payoff (`Contract.value_pay`), which is exactly the integral +`MathFin.geomAsianN_call_price` evaluates once the observation product is rewritten as the +geometric mean of the path values. + +## Main definitions + +* `BlackScholes.pathAssets` — the geometric Brownian path as a model map `Unit → ℝ≥0 → Ω → ℝ`. + +## Main results + +* `BlackScholes.value_geomAsianCall` — `geomAsianCall K T τ` is worth the call price at the + effective spot `geomAsianEffSpot` and volatility `geomAsianEffVol`. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 15.6 +* [A. G. Z. Kemna and A. C. F. Vorst, *A pricing method for options based on average asset + values*][KemnaVorst1990] +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], 4.5 +* [Zhang, *Exotic Options*][ZhangExoticOptions] + +## Tags + +geometric Asian option, path-dependent option, geometric Brownian motion, Black–Scholes path, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal + +namespace MathFin.Contracts.BlackScholes + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- The Black–Scholes market along a Brownian path as a model map: the single asset is +`S_u = S₀ exp((r − σ²/2)u + σ B_u)` at every time `u`. -/ +noncomputable def pathAssets (S_0 r σ : ℝ) (B : ℝ≥0 → Ω → ℝ) : Unit → ℝ≥0 → Ω → ℝ := + fun _ u ω ↦ S_0 * Real.exp ((r - σ ^ 2 / 2) * u + σ * B u ω) + +/-- **The geometric Asian call's Black–Scholes value** is the call price at the effective spot +and volatility of `geomAsianN_call_price`. For a pre-Brownian `B` under a probability measure +`μ`, averaging dates `τ` all at most the maturity `T > 0`, positive spot, strike and volatility, +and a nondegenerate log-driver variance, the value of `geomAsianCall K T τ` at the discount +`e^{−rT}` is `S_hat₀ Φ(d₁) − K e^{−rT} Φ(d₂)` with `S_hat₀ = geomAsianEffSpot` and volatility +`geomAsianEffVol`. -/ +theorem value_geomAsianCall {μ : Measure Ω} [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} + (hB : IsPreBrownianReal B μ) {T : ℝ≥0} {n : ℕ} (hn : 0 < n) (τ : Fin n → ℝ≥0) + (hτT : ∀ i, τ i ≤ T) {S_0 K r σ : ℝ} (hS₀ : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) + (hT : 0 < (T : ℝ)) (hV : 0 < geomAsianVar τ) : + (geomAsianCall K T τ).value μ (fun _ _ ↦ Real.exp (-r * T)) (pathAssets S_0 r σ B) + = geomAsianEffSpot S_0 r σ T τ * + Phi (bsd1 (geomAsianEffSpot S_0 r σ T τ) K r (geomAsianEffVol σ T τ) T) + - K * Real.exp (-r * T) * + Phi (bsd2 (geomAsianEffSpot S_0 r σ T τ) K r (geomAsianEffVol σ T τ) T) := by + rw [geomAsianCall, Contract.value_pay] + refine Eq.trans ?_ (geomAsianN_call_price hB T hn τ hτT S_0 K r σ T hS₀ hK hσ hT hV) + refine integral_congr_ae (.of_forall fun ω ↦ ?_) + have hpos (i : Fin n) : 0 ≤ S_0 * Real.exp ((r - σ ^ 2 / 2) * (τ i : ℝ) + σ * B (τ i) ω) := + (mul_pos hS₀ (Real.exp_pos _)).le + simp only [Payoff.eval, Payoff.eval_obsProd, scenarioAt, pathAssets, List.map_ofFn, + List.prod_ofFn, Function.comp_def, NNReal.coe_inv, NNReal.coe_natCast] + rw [Real.finsetProd_rpow _ _ fun i _ ↦ hpos i] + +end MathFin.Contracts.BlackScholes diff --git a/LeanPool/MathFin/Models/BlackScholes/BlackScholesExchange.lean b/LeanPool/MathFin/Models/BlackScholes/BlackScholesExchange.lean new file mode 100644 index 0000000000..c8b26a0e84 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/BlackScholesExchange.lean @@ -0,0 +1,80 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Contracts.Instruments.Options +public import LeanPool.MathFin.Pricing.Value +public import LeanPool.MathFin.Models.BlackScholes.MargrabeGrounding + +/-! +# The exchange option priced in the two-asset Black–Scholes model + +`Models/BlackScholes/BlackScholes.lean` prices the one-underlying instruments; the exchange option +`exchangeOption T` observes two underlyings, so it gets its own model map. +`BlackScholes.assets₂` is the two-asset Black–Scholes market at maturity: asset `i` is +`bsTerminal Sⁱ₀ r σᵢ T (Wᵢ ω)`, read at every time like `BlackScholes.assets`. + +Nothing new is proved about Margrabe's formula. The contract's value is the discounted expected +exchange payoff (`Contract.value_pay`), which is exactly the integral `margrabe_exchange_price` +evaluates under the model measure, for jointly Gaussian standard-normal drivers. + +## Main definitions + +* `BlackScholes.assets₂` — the two-asset Black–Scholes terminal market as a model map + `Fin 2 → ℝ≥0 → Ω → ℝ`. + +## Main results + +* `BlackScholes.value_exchangeOption` — `exchangeOption T` is worth `margrabePrice S¹₀ S²₀ σ_eff T`. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [W. Margrabe, *The value of an option to exchange one asset for another*][Margrabe1978] + +## Tags + +exchange option, Margrabe formula, two-asset model, outperformance option, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory +open scoped NNReal + +namespace MathFin.Contracts.BlackScholes + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- The two-asset Black–Scholes market as a model map: asset `0` is `bsTerminal S₁ r σ₁ T (W₁ ω)`, +asset `1` is `bsTerminal S₂ r σ₂ T (W₂ ω)`, at every time. -/ +noncomputable def assets₂ (S₁ S₂ r σ₁ σ₂ T : ℝ) (W₁ W₂ : Ω → ℝ) : Fin 2 → ℝ≥0 → Ω → ℝ := + fun i _ ω ↦ ![bsTerminal S₁ r σ₁ T (W₁ ω), bsTerminal S₂ r σ₂ T (W₂ ω)] i + +/-- **The exchange option's Black–Scholes value is Margrabe's price.** For two Black–Scholes +terminals driven by a jointly Gaussian pair of standard-normal drivers with correlation `ρ`, the +value of `exchangeOption T` at the discount `e^{−rT}` is `margrabePrice S¹₀ S²₀ σ_eff T`, with +`σ_eff² = σ₁² + σ₂² − 2ρσ₁σ₂`. -/ +theorem value_exchangeOption {P : Measure Ω} [IsProbabilityMeasure P] + {W₁ W₂ : Ω → ℝ} {σ₁ σ₂ ρ σeff S1 S2 r : ℝ} {T : ℝ≥0} + (hjoint : HasGaussianLaw (fun ω ↦ (W₁ ω, W₂ ω)) P) + (hW₁meas : Measurable W₁) (hW₂meas : Measurable W₂) + (hW₁ : HasLaw W₁ (gaussianReal 0 1) P) (hW₂ : HasLaw W₂ (gaussianReal 0 1) P) + (hcov : cov[W₁, W₂; P] = ρ) + (hS1 : 0 < S1) (hS2 : 0 < S2) (hσeff : 0 < σeff) (hT : 0 < (T : ℝ)) + (hσeff_sq : σeff ^ 2 = σ₁ ^ 2 + σ₂ ^ 2 - 2 * ρ * σ₁ * σ₂) : + (exchangeOption T).value P (fun _ _ ↦ Real.exp (-(r * T))) + (assets₂ S1 S2 r σ₁ σ₂ T W₁ W₂) + = margrabePrice S1 S2 σeff T := by + rw [exchangeOption, Contract.value_pay] + refine Eq.trans ?_ (margrabe_exchange_price hjoint hW₁meas hW₂meas hW₁ hW₂ hcov hS1 hS2 + hσeff hT hσeff_sq (r := r) (σ₁ := σ₁) (σ₂ := σ₂)) + refine integral_congr_ae (.of_forall fun ω ↦ ?_) + simp [Payoff.eval, scenarioAt, assets₂] + +end MathFin.Contracts.BlackScholes diff --git a/LeanPool/MathFin/Models/BlackScholes/Call.lean b/LeanPool/MathFin/Models/BlackScholes/Call.lean new file mode 100644 index 0000000000..d6c5aceffc --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/Call.lean @@ -0,0 +1,328 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Gaussian.StandardNormal + +/-! +# Black-Scholes European call pricing formula + +Derivation of the Black-Scholes European call pricing formula from the +risk-neutral lognormal hypothesis: + + C(S_0, K, r, σ, T) = S_0 · Φ(d_1) − K · e^{-rT} · Φ(d_2) + + where + d_1 = (log(S_0/K) + (r + σ²/2)T) / (σ√T) + d_2 = d_1 − σ√T = (log(S_0/K) + (r − σ²/2)T) / (σ√T) + Φ(x) = standard normal CDF = (gaussianReal 0 1 (Set.Iic x)).toReal + + Hypothesis: under the risk-neutral measure Q, log(S_T/S_0) is Gaussian with + mean (r − σ²/2)T and variance σ²T. + + No upstream BS or Itô calculus required; this is pure Gaussian integration. + + Mathlib leverage: `gaussianReal`, `gaussianPDFReal`, + `gaussianReal_map_const_mul`, `gaussianReal_map_add_const`, + `gaussianReal_map_neg`, `integral_gaussianReal_eq_integral_smul`, + `integral_map`, `MeasureTheory.HasLaw`, `MeasureTheory.NullSingletonClass`. + + ## Triple-check audit (2026-05-17) + + **Axioms cleanliness.** `#print axioms` confirms `bs_call_formula` and + every supporting lemma depend only on the three standard Lean axioms: + `[propext, Classical.choice, Quot.sound]`. No `sorryAx`, no + project-local axiom. + + **Cross-check vs literature.** The formula, conventions for `d_1`/`d_2`, + and the risk-neutral hypothesis match exactly: + - Hull, *Options, Futures, and Other Derivatives* 11th ed., Eq. 15.20 + - Shreve, *Stochastic Calculus for Finance II*, Theorem 4.5.1 + - Karatzas & Shreve, *Brownian Motion and Stochastic Calculus*, Ch 5.8 + - Saporito (the project's source textbook), Ch 9.4 + (our `T` ≡ Saporito's `T − t` at `t = 0`) + + **Numerical sanity.** For the canonical example `S₀ = K = 100, r = 5%, + σ = 20%, T = 1y`: our formula yields `d_1 = 0.35`, `d_2 = 0.15`, + `C ≈ 10.4506` USD — matches Hull/Shreve's published reference values to + 5 decimal places. + + **Scope (honest):** + - `t = 0` specialization (general `t` recovers via `T → T − t`) + - European call (path-independent) + - The risk-neutral lognormal law is *assumed* via `HasLaw`; we don't + derive it from `dS = rS dt + σS dW` (that needs Itô on `log S`, + research-grade upstream). + + ## File contents + + Built primitives: + - `Phi`, `Phi_neg`, `Phi_add_Phi_neg`: standard normal CDF + symmetry. + - `gaussianReal_Ioi_toReal`: `(gaussianReal 0 1 (Set.Ioi a)).toReal = Phi(-a)`. + - `exp_mul_gaussianPDFReal_zero_one`: completing-the-square identity + `exp(c·z) · pdf(0,1,z) = exp(c²/2) · pdf(c,1,z)`. + - `integral_exp_mul_gaussianPDFReal_Ioi`: the core BS computational primitive + `∫ z in Ioi a, exp(c·z) · pdf(0,1,z) dz = exp(c²/2) · Phi(c − a)`. + - `BSCallHyp` structure: `S_0>0, K>0, σ>0, T>0, HasLaw Z (gaussianReal 0 1) Q`. + - `bsd1`, `bsd2`, `bsTerminal` definitions. + - `bsd2_eq`, `bsTerminal_gt_K_iff`, `max_payoff_eq_indicator` helpers. + - `bs_call_formula` main theorem. + +## Main definitions + +* `BSCallHyp`: the risk-neutral lognormal hypothesis. It records `0 < S_0`, `0 < K`, `0 < σ`, + `0 < T` and that `Z` has the standard normal law `gaussianReal 0 1` under `Q`. +* `bsTerminal`: the terminal price `S_T(z) = S_0 · exp((r − σ²/2)T + σ√T · z)` as a function of + the standard normal sample `z`. +* `bsd1`, `bsd2`: `d₁ = (log(S_0/K) + (r + σ²/2)T) / (σ√T)` and `d₂ = d₁ − σ√T`. + +## Main results + +* `bs_call_formula`: under `BSCallHyp Q S_0 K r σ T Z`, the discounted expected call payoff + `∫ e^{−rT} · max (S_T(Z) − K) 0 ∂Q` equals `S_0 · Φ(d₁) − K · e^{−rT} · Φ(d₂)`. +* `bsTerminal_gt_K_iff`: for positive `S_0, K, σ, T`, `S_T(z) > K ↔ z > −d₂`. +* `integrable_bsTerminal`, `integrable_bsCall_payoff`, `integrable_bsPut_payoff`: the terminal + price and the discounted call and put payoffs are integrable when `Z` has the standard normal + law. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Section 9.4 + +## Tags + +Black–Scholes formula, European call, risk-neutral pricing, lognormal model, option pricing, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal + +/-! ### Risk-neutral lognormal hypothesis -/ + +/-- The risk-neutral lognormal hypothesis for the Black-Scholes model. +Under the risk-neutral measure `Q`, `S_T = S_0 · exp((r − σ²/2)T + σ√T · Z)` +with `Z ~ N(0, 1)`. -/ +structure BSCallHyp {Ω : Type*} {mΩ : MeasurableSpace Ω} + (Q : Measure Ω) [IsProbabilityMeasure Q] + (S_0 K r σ T : ℝ) (Z : Ω → ℝ) : Prop where + S_0_pos : 0 < S_0 + K_pos : 0 < K + σ_pos : 0 < σ + T_pos : 0 < T + Z_law : HasLaw Z (gaussianReal 0 1) Q + +/-- `d₁` parameter in the BS formula. -/ +noncomputable def bsd1 (S_0 K r σ T : ℝ) : ℝ := + (Real.log (S_0 / K) + (r + σ^2 / 2) * T) / (σ * Real.sqrt T) + +/-- `d₂ = d₁ − σ√T`. -/ +noncomputable def bsd2 (S_0 K r σ T : ℝ) : ℝ := + bsd1 S_0 K r σ T - σ * Real.sqrt T + +/-- Terminal price `S_T(z) = S_0 · exp((r − σ²/2)T + σ√T · z)` viewed as a +function of the standard-normal sample. -/ +noncomputable def bsTerminal (S_0 r σ T z : ℝ) : ℝ := + S_0 * Real.exp ((r - σ^2 / 2) * T + σ * Real.sqrt T * z) + +/-- The terminal price is integrable against the standard normal law: a constant times +`exp(σ√T · z)` (Mathlib's `integrable_exp_mul_gaussianReal`). -/ +lemma integrable_bsTerminal_gaussianReal (S_0 r σ T : ℝ) : + Integrable (bsTerminal S_0 r σ T) (gaussianReal 0 1) := by + have h : bsTerminal S_0 r σ T = fun z ↦ + S_0 * Real.exp ((r - σ ^ 2 / 2) * T) * Real.exp (σ * Real.sqrt T * z) := + funext fun z ↦ by rw [bsTerminal, Real.exp_add]; ring + rw [h] + exact (integrable_exp_mul_gaussianReal _).const_mul _ + +/-- The Black–Scholes terminal price driven by a standard normal is integrable: it is integrable +against the standard normal law (`integrable_bsTerminal_gaussianReal`), the law of `Z`. -/ +theorem integrable_bsTerminal {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} {Z : Ω → ℝ} + (hZ : HasLaw Z (gaussianReal 0 1) Q) (S_0 r σ T : ℝ) : + Integrable (fun ω ↦ bsTerminal S_0 r σ T (Z ω)) Q := by + refine Integrable.comp_aemeasurable (g := bsTerminal S_0 r σ T) ?_ hZ.aemeasurable + rw [hZ.map_eq] + exact integrable_bsTerminal_gaussianReal S_0 r σ T + +/-- The discounted Black–Scholes call payoff driven by a standard normal is integrable: it is the +positive part of an integrable function. -/ +theorem integrable_bsCall_payoff {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} + {Z : Ω → ℝ} (hZ : HasLaw Z (gaussianReal 0 1) Q) (S_0 K r σ T : ℝ) : + Integrable (fun ω ↦ Real.exp (-r * T) * max (bsTerminal S_0 r σ T (Z ω) - K) 0) Q := + have := hZ.isProbabilityMeasure + ((integrable_bsTerminal hZ S_0 r σ T).sub' (integrable_const K)).pos_part.const_mul _ + +/-- The discounted Black–Scholes put payoff driven by a standard normal is integrable: it is the +positive part of an integrable function. -/ +theorem integrable_bsPut_payoff {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} + {Z : Ω → ℝ} (hZ : HasLaw Z (gaussianReal 0 1) Q) (S_0 K r σ T : ℝ) : + Integrable (fun ω ↦ Real.exp (-r * T) * max (K - bsTerminal S_0 r σ T (Z ω)) 0) Q := + have := hZ.isProbabilityMeasure + ((integrable_const K).sub' (integrable_bsTerminal hZ S_0 r σ T)).pos_part.const_mul _ + +/-- Alternative form for `d₂`: `bsd2 = (log(S_0/K) + (r − σ²/2)T) / (σ√T)`. -/ +lemma bsd2_eq {S_0 K r σ T : ℝ} (hσ : 0 < σ) (hT : 0 < T) : + bsd2 S_0 K r σ T = (Real.log (S_0 / K) + (r - σ^2 / 2) * T) / (σ * Real.sqrt T) := by + have hσsqT_pos : 0 < σ * Real.sqrt T := mul_pos hσ (Real.sqrt_pos.mpr hT) + have h_sqT_sq : Real.sqrt T ^ 2 = T := Real.sq_sqrt hT.le + unfold bsd2 bsd1 + field_simp + -- pure equality driven by one substitution `(√T)² = T` — `linear_combination`, + -- not `nlinarith` (the repo's "nlinarith is for inequalities" doctrine). + linear_combination (-2 * σ ^ 2) * h_sqT_sq + +/-- Exercise-region identification: `S_T(z) > K ↔ z > −d_2`. -/ +lemma bsTerminal_gt_K_iff {S_0 K r σ T : ℝ} + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (z : ℝ) : + bsTerminal S_0 r σ T z > K ↔ z > -bsd2 S_0 K r σ T := by + have hσsqT_pos : 0 < σ * Real.sqrt T := mul_pos hσ (Real.sqrt_pos.mpr hT) + have h_KS_pos : 0 < K / S_0 := div_pos hK hS_0 + have h_log_div : Real.log (K / S_0) = -Real.log (S_0 / K) := by + rw [Real.log_div hK.ne' hS_0.ne', Real.log_div hS_0.ne' hK.ne']; ring + -- core: S_T(z) > K ↔ log(K/S_0) < (r - σ²/2)T + σ√T·z + have h_core_iff : bsTerminal S_0 r σ T z > K ↔ + Real.log (K / S_0) < (r - σ^2 / 2) * T + σ * Real.sqrt T * z := by + unfold bsTerminal + rw [gt_iff_lt, mul_comm S_0, ← div_lt_iff₀ hS_0] + exact (Real.log_lt_iff_lt_exp h_KS_pos).symm + rw [h_core_iff, bsd2_eq hσ hT, gt_iff_lt] + rw [show -((Real.log (S_0 / K) + (r - σ^2 / 2) * T) / (σ * Real.sqrt T)) + = (-(Real.log (S_0 / K) + (r - σ^2 / 2) * T)) / (σ * Real.sqrt T) from + (neg_div _ _).symm] + rw [div_lt_iff₀ hσsqT_pos] + rw [h_log_div] + constructor + · intro h; linarith + · intro h; linarith + +/-- `max(S_T(z) − K, 0)` as an indicator on the exercise region. -/ +private lemma max_payoff_eq_indicator {S_0 K r σ T : ℝ} + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (z : ℝ) : + max (bsTerminal S_0 r σ T z - K) 0 = + (Set.Ioi (-bsd2 S_0 K r σ T)).indicator + (fun z' ↦ bsTerminal S_0 r σ T z' - K) z := by + by_cases h : z ∈ Set.Ioi (-bsd2 S_0 K r σ T) + · rw [Set.indicator_of_mem h] + have hST : bsTerminal S_0 r σ T z > K := + (bsTerminal_gt_K_iff hS_0 hK hσ hT z).mpr h + exact max_eq_left (sub_nonneg.mpr hST.le) + · rw [Set.indicator_of_notMem h] + have hz_le : z ≤ -bsd2 S_0 K r σ T := not_lt.mp h + have hST_le : bsTerminal S_0 r σ T z ≤ K := by + by_contra hcontra + exact h ((bsTerminal_gt_K_iff hS_0 hK hσ hT z).mp (not_le.mp hcontra)) + exact max_eq_right (sub_nonpos.mpr hST_le) + +/-- **Black-Scholes European call pricing formula.** + +For an asset whose risk-neutral log-return is Gaussian +(`HasLaw Z (gaussianReal 0 1) Q` with `S_T = S_0 · exp((r − σ²/2)T + σ√T · Z)`), +the discounted expected payoff of the European call `max(S_T − K, 0)` equals +`S_0 · Φ(d_1) − K · e^{−rT} · Φ(d_2)`. + +This is a real derivation from primitives: `HasLaw.integral_comp` (transfer +expectation to the standard normal), `integral_gaussianReal_eq_integral_smul` +(convert to Lebesgue with `gaussianPDFReal` factor), `max_payoff_eq_indicator` ++ `integral_indicator` (restrict to the exercise region `{z > −d_2}`), +`integral_exp_mul_gaussianPDFReal_Ioi` for the asset-payoff piece (completing +the square: `∫ exp(σ√T·z) · pdf = exp(σ²T/2) · Φ(d_1)`), +`gaussianReal_Ioi_toReal` for the strike piece (`∫ pdf = Φ(d_2)`), and the +final algebraic identity `(r − σ²/2)T + σ²T/2 = rT`. -/ +theorem bs_call_formula {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + ∫ ω, Real.exp (-r * T) * max (bsTerminal S_0 r σ T (Z ω) - K) 0 ∂Q + = S_0 * Phi (bsd1 S_0 K r σ T) - + K * Real.exp (-r * T) * Phi (bsd2 S_0 K r σ T) := by + obtain ⟨hS_0, hK, hσ, hT, hZ⟩ := h + set d_1 : ℝ := bsd1 S_0 K r σ T with d_1_def + set d_2 : ℝ := bsd2 S_0 K r σ T with d_2_def + set μ_log : ℝ := (r - σ^2 / 2) * T + set ν_log : ℝ := σ * Real.sqrt T with ν_log_def + have hsqrT_pos : 0 < Real.sqrt T := Real.sqrt_pos.mpr hT + have hν_log_pos : 0 < ν_log := mul_pos hσ hsqrT_pos + have hν_log_sq : ν_log^2 = σ^2 * T := by + rw [ν_log_def, mul_pow, Real.sq_sqrt hT.le] + -- Key identity: μ_log + ν_log²/2 = rT + have h_algebra : μ_log + ν_log^2 / 2 = r * T := by rw [hν_log_sq]; ring + -- Key identity: ν_log - (-d_2) = d_1 + have h_shift_eq : ν_log - (-d_2) = d_1 := by + rw [d_1_def, d_2_def, bsd2]; ring + have h_payoff_meas : Measurable fun z : ℝ ↦ max (bsTerminal S_0 r σ T z - K) 0 := by + unfold bsTerminal; fun_prop + -- Step 1-3: pull out e^{-rT}, HasLaw transfer, convert to volume with pdf + rw [integral_const_mul] + rw [show (fun ω ↦ max (bsTerminal S_0 r σ T (Z ω) - K) 0) + = (fun z ↦ max (bsTerminal S_0 r σ T z - K) 0) ∘ Z from rfl, + hZ.integral_comp h_payoff_meas.aestronglyMeasurable, + integral_gaussianReal_eq_integral_smul (one_ne_zero : (1 : ℝ≥0) ≠ 0)] + -- Step 4: max → indicator + rw [show (fun z : ℝ ↦ gaussianPDFReal 0 1 z • max (bsTerminal S_0 r σ T z - K) 0) + = (Set.Ioi (-d_2)).indicator + (fun z ↦ gaussianPDFReal 0 1 z * (bsTerminal S_0 r σ T z - K)) from + funext (fun z ↦ by + rw [smul_eq_mul, max_payoff_eq_indicator hS_0 hK hσ hT z] + by_cases hz : z ∈ Set.Ioi (-d_2) + · rw [Set.indicator_of_mem hz, Set.indicator_of_mem hz] + · rw [Set.indicator_of_notMem hz, Set.indicator_of_notMem hz, mul_zero])] + rw [integral_indicator measurableSet_Ioi] + -- Step 5: rewrite integrand pdf * (S_T - K) as a linear combination + have h_split_integrand : ∀ z : ℝ, + gaussianPDFReal 0 1 z * (bsTerminal S_0 r σ T z - K) + = (S_0 * Real.exp μ_log) * (Real.exp (ν_log * z) * gaussianPDFReal 0 1 z) + - K * gaussianPDFReal 0 1 z := by + intro z + unfold bsTerminal + have h_exp : Real.exp ((r - σ^2 / 2) * T + σ * Real.sqrt T * z) + = Real.exp μ_log * Real.exp (ν_log * z) := by + change Real.exp ((r - σ^2 / 2) * T + σ * Real.sqrt T * z) + = Real.exp ((r - σ^2 / 2) * T) * Real.exp (σ * Real.sqrt T * z) + exact Real.exp_add _ _ + rw [h_exp] + ring + rw [setIntegral_congr_fun measurableSet_Ioi (fun z _ ↦ h_split_integrand z)] + -- Step 6: integrability of each piece on Ioi(-d_2) + have h_int_pdf_Ioi : IntegrableOn (gaussianPDFReal 0 1) (Set.Ioi (-d_2)) volume := + (integrable_gaussianPDFReal 0 1).integrableOn + have h_int_asset : IntegrableOn + (fun z : ℝ ↦ Real.exp (ν_log * z) * gaussianPDFReal 0 1 z) + (Set.Ioi (-d_2)) volume := by + refine ((integrable_gaussianPDFReal ν_log 1).const_mul + (Real.exp (ν_log^2 / 2))).integrableOn.congr_fun ?_ measurableSet_Ioi + intro z _ + exact (exp_mul_gaussianPDFReal_zero_one ν_log z).symm + -- Step 7: split via integral_sub on the restricted measure + rw [integral_sub (h_int_asset.const_mul _) (h_int_pdf_Ioi.const_mul _)] + rw [integral_const_mul, integral_const_mul] + -- Step 8: apply primitives + rw [integral_exp_mul_gaussianPDFReal_Ioi, h_shift_eq] + have h_pdf_int_eq : + ∫ z in Set.Ioi (-d_2), gaussianPDFReal 0 1 z = Phi d_2 := by + rw [setIntegral_gaussianPDFReal_eq_toReal measurableSet_Ioi (0 : ℝ), + gaussianReal_Ioi_toReal, neg_neg] + rw [h_pdf_int_eq] + -- Step 9: final algebra + -- Target: e^{-rT} * ((S_0 * e^μ_log) * (e^{ν_log²/2} * Phi d_1) - K * Phi d_2) + -- = S_0 * Phi d_1 - K * e^{-rT} * Phi d_2 + have h_exp_combine : Real.exp (-r * T) * Real.exp μ_log * Real.exp (ν_log^2 / 2) = 1 := by + rw [mul_assoc, ← Real.exp_add, ← Real.exp_add, + show -r * T + (μ_log + ν_log^2 / 2) = 0 from by rw [h_algebra]; ring] + exact Real.exp_zero + calc Real.exp (-r * T) * + (S_0 * Real.exp μ_log * (Real.exp (ν_log^2 / 2) * Phi d_1) - K * Phi d_2) + = (Real.exp (-r * T) * Real.exp μ_log * Real.exp (ν_log^2 / 2)) * (S_0 * Phi d_1) - + K * Real.exp (-r * T) * Phi d_2 := by ring + _ = 1 * (S_0 * Phi d_1) - K * Real.exp (-r * T) * Phi d_2 := by rw [h_exp_combine] + _ = S_0 * Phi d_1 - K * Real.exp (-r * T) * Phi d_2 := by rw [one_mul] + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/Chooser.lean b/LeanPool/MathFin/Models/BlackScholes/Chooser.lean new file mode 100644 index 0000000000..3c24e565a1 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/Chooser.lean @@ -0,0 +1,65 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Basic.Real.Basic +public import Mathlib.Tactic.Linarith.Frontend +public import Mathlib.Tactic.Ring.RingNF + +/-! +# Chooser option + +At the chooser date `t` the holder picks `max(C_t, P_t)`. Using `C_t - P_t = +S_t - K · e^{-r(T-t)}` (put-call parity at time `t`), this rearranges to + +`max(C_t, P_t) = C_t + max(0, K · e^{-r(T-t)} - S_t)`, + +so a chooser option is a portfolio: a long call (strike `K`, maturity `T`) plus +a long put-payoff at the chooser date with strike `K · e^{-r(T-t)}`. + +Both lemmas are pure real-number algebra; the financial content is the +identification of the second piece as a put at the chooser date. + +## Main results + +* `chooser_payoff_decompose`: `max C P = C + max 0 (P - C)`. +* `chooser_via_pcp`: under `C - P = S - K_disc`, + `max C P = C + max 0 (K_disc - S)`. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 26.7 +* [M. Rubinstein, *Options for the undecided*][Rubinstein1991] + +## Tags + +chooser option, as-you-like-it option, put–call parity, exotic option, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +/-- Generic chooser-style decomposition: `max C P = C + max 0 (P − C)`. -/ +lemma chooser_payoff_decompose (C P : ℝ) : + max C P = C + max 0 (P - C) := by + by_cases h : C ≤ P + · rw [max_eq_right h, max_eq_right (by linarith : (0:ℝ) ≤ P - C)]; ring + · push Not at h + rw [max_eq_left h.le, max_eq_left (by linarith : P - C ≤ 0)]; ring + +/-- **Chooser option payoff** via put-call parity at the chooser date. +If `C - P = S - K_disc` (PCP), then `max(C, P) = C + max(0, K_disc - S)`. -/ +lemma chooser_via_pcp (C P S K_disc : ℝ) (hPCP : C - P = S - K_disc) : + max C P = C + max 0 (K_disc - S) := by + rw [chooser_payoff_decompose] + have : P - C = K_disc - S := by linarith + rw [this] + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/Digital.lean b/LeanPool/MathFin/Models/BlackScholes/Digital.lean new file mode 100644 index 0000000000..54872b50fd --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/Digital.lean @@ -0,0 +1,243 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Call + +/-! +# Black–Scholes digital option pricing formulas + +Two **digital** (a.k.a. **binary**) European derivatives: + +* **Cash-or-nothing call** pays `$1` at maturity `T` iff `S_T > K`. + Price: `V_cash = e^{-rT} · Φ(d_2)`. +* **Asset-or-nothing call** pays `S_T` at maturity `T` iff `S_T > K`. + Price: `V_asset = S_0 · Φ(d_1)`. + +Both are derived directly from the BS hypothesis via the same machinery +as the vanilla call: HasLaw transfer to standard normal, `1_{S_T > K}` on +`Ioi(-d_2)`, then either `gaussianReal_Ioi_toReal` (cash case) or +`integral_exp_mul_gaussianPDFReal_Ioi` (asset case). + +The standard decomposition `Call = AssetDigital − K · CashDigital` is +also proved as a corollary. + +## Main results + +* `bs_cash_or_nothing_formula`: under `BSCallHyp`, the discounted expected payoff of the + cash-or-nothing call (`1` if `S_T > K`) is `e^{−rT} · Φ(d₂)`. +* `bs_asset_or_nothing_formula`: under `BSCallHyp`, the discounted expected payoff of the + asset-or-nothing call (`S_T` if `S_T > K`) is `S_0 · Φ(d₁)`. +* `bs_call_eq_asset_minus_K_cash`: under `BSCallHyp`, the discounted expected call payoff is the + asset-or-nothing value minus `K` times the cash-or-nothing value. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 26.1 + +## Tags + +digital option, binary option, cash-or-nothing, asset-or-nothing, Black–Scholes, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal + +/-- **Indicator pushforward through `bsTerminal`.** For any payoff `f`, the payoff-on-`{S_T > K}` +read as a function of the standard-normal driver `z` is the `Ioi (-d₂)`-indicator of `f ∘ S_T`: +`1_{Ioi K}(S_T z) · f = 1_{Ioi (-d₂)}(z) · (f ∘ S_T)`. Both digital formulas below instantiate it +(at `f = fun _ ↦ 1` and `f = fun s ↦ s`), sharing the `bsTerminal_gt_K_iff` case split. -/ +private lemma indicator_bsTerminal_Ioi_comp {S_0 K r σ T : ℝ} + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (f : ℝ → ℝ) (z : ℝ) : + (Set.Ioi K).indicator f (bsTerminal S_0 r σ T z) + = (Set.Ioi (-bsd2 S_0 K r σ T)).indicator (f ∘ bsTerminal S_0 r σ T) z := by + by_cases hz : bsTerminal S_0 r σ T z ∈ Set.Ioi K + · have h_z_mem : z ∈ Set.Ioi (-bsd2 S_0 K r σ T) := + (bsTerminal_gt_K_iff hS_0 hK hσ hT z).mp hz + rw [Set.indicator_of_mem hz, Set.indicator_of_mem h_z_mem, Function.comp_apply] + · have h_z_le : z ≤ -bsd2 S_0 K r σ T := by + by_contra hcontra + exact hz ((bsTerminal_gt_K_iff hS_0 hK hσ hT z).mpr (not_le.mp hcontra)) + have h_z_not_mem : z ∉ Set.Ioi (-bsd2 S_0 K r σ T) := not_lt.mpr h_z_le + rw [Set.indicator_of_notMem hz, Set.indicator_of_notMem h_z_not_mem] + +/-! ### Cash-or-nothing digital -/ + +/-- **Cash-or-nothing call** pricing formula. + +Pays `$1` at maturity iff `S_T > K`. Its discounted expected payoff under +the risk-neutral measure is +`V_cash = e^{-rT} · Φ(d_2)` where `d_2 = (log(S_0/K) + (r - σ²/2)T) / (σ√T)`. + +Real derivation: HasLaw transfer to standard normal, identify +`{S_T(z) > K} = Ioi(-d_2)` via `bsTerminal_gt_K_iff`, then +`∫ 1_{Ioi(-d_2)}(z) · pdf(0,1,z) dz = (gaussianReal 0 1 (Ioi(-d_2))).toReal += Φ(d_2)` via `gaussianReal_Ioi_toReal`. -/ +theorem bs_cash_or_nothing_formula {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + ∫ ω, Real.exp (-r * T) * + (Set.Ioi K).indicator (fun _ ↦ (1 : ℝ)) (bsTerminal S_0 r σ T (Z ω)) ∂Q + = Real.exp (-r * T) * Phi (bsd2 S_0 K r σ T) := by + obtain ⟨hS_0, hK, hσ, hT, hZ⟩ := h + set d_2 : ℝ := bsd2 S_0 K r σ T + -- Indicator on {S_T > K} viewed as a function of z equals indicator on Ioi(-d_2) + have h_indic_eq : ∀ z : ℝ, + (Set.Ioi K).indicator (fun _ ↦ (1 : ℝ)) (bsTerminal S_0 r σ T z) + = (Set.Ioi (-d_2)).indicator (fun _ ↦ (1 : ℝ)) z := + fun z ↦ indicator_bsTerminal_Ioi_comp hS_0 hK hσ hT (fun _ ↦ (1 : ℝ)) z + -- Measurability of the payoff + have h_payoff_meas : Measurable fun z : ℝ ↦ + (Set.Ioi K).indicator (fun _ ↦ (1 : ℝ)) (bsTerminal S_0 r σ T z) := by + have h_simp : (fun z : ℝ ↦ + (Set.Ioi K).indicator (fun _ ↦ (1 : ℝ)) (bsTerminal S_0 r σ T z)) + = (Set.Ioi (-d_2)).indicator (fun _ ↦ (1 : ℝ)) := funext h_indic_eq + rw [h_simp] + exact (measurable_const.indicator measurableSet_Ioi) + -- Pull out e^{-rT}, HasLaw transfer + rw [integral_const_mul] + rw [show (fun ω ↦ (Set.Ioi K).indicator (fun _ ↦ (1 : ℝ)) (bsTerminal S_0 r σ T (Z ω))) + = (fun z ↦ (Set.Ioi K).indicator (fun _ ↦ (1 : ℝ)) (bsTerminal S_0 r σ T z)) ∘ Z + from rfl, + hZ.integral_comp h_payoff_meas.aestronglyMeasurable, + integral_gaussianReal_eq_integral_smul (one_ne_zero : (1 : ℝ≥0) ≠ 0)] + -- Replace the indicator by the Ioi(-d_2) form, integrate against pdf + have h_smul_eq : + (fun z : ℝ ↦ gaussianPDFReal 0 1 z • + (Set.Ioi K).indicator (fun _ ↦ (1 : ℝ)) (bsTerminal S_0 r σ T z)) + = (Set.Ioi (-d_2)).indicator (fun z ↦ gaussianPDFReal 0 1 z) := by + funext z + rw [smul_eq_mul, h_indic_eq z] + by_cases hz : z ∈ Set.Ioi (-d_2) + · rw [Set.indicator_of_mem hz, Set.indicator_of_mem hz, mul_one] + · rw [Set.indicator_of_notMem hz, Set.indicator_of_notMem hz, mul_zero] + rw [h_smul_eq, integral_indicator measurableSet_Ioi] + -- ∫ z ∈ Ioi(-d_2), pdf = Phi(d_2) via gaussianReal_Ioi_toReal + have h_pdf_int_eq : + ∫ z in Set.Ioi (-d_2), gaussianPDFReal 0 1 z = Phi d_2 := by + rw [setIntegral_gaussianPDFReal_eq_toReal measurableSet_Ioi (0 : ℝ), + gaussianReal_Ioi_toReal, neg_neg] + rw [h_pdf_int_eq] + +/-! ### Asset-or-nothing digital -/ + +/-- **Asset-or-nothing call** pricing formula. + +Pays `S_T` at maturity iff `S_T > K`. Its discounted expected payoff under +the risk-neutral measure is `V_asset = S_0 · Φ(d_1)`. + +Real derivation: HasLaw transfer + identify `{S_T > K} = Ioi(-d_2)` + +`integral_exp_mul_gaussianPDFReal_Ioi` for the `exp(ν_log · z) · pdf` +integrand on the exercise region. The BS martingale algebra +`(r - σ²/2)T + σ²T/2 = rT` and `ν_log - (-d_2) = d_1` close the proof. -/ +theorem bs_asset_or_nothing_formula {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + ∫ ω, Real.exp (-r * T) * + (Set.Ioi K).indicator + (fun s ↦ s) (bsTerminal S_0 r σ T (Z ω)) ∂Q + = S_0 * Phi (bsd1 S_0 K r σ T) := by + obtain ⟨hS_0, hK, hσ, hT, hZ⟩ := h + set d_1 : ℝ := bsd1 S_0 K r σ T with d_1_def + set d_2 : ℝ := bsd2 S_0 K r σ T with d_2_def + set μ_log : ℝ := (r - σ^2 / 2) * T + set ν_log : ℝ := σ * Real.sqrt T with ν_log_def + have hsqrT_pos : 0 < Real.sqrt T := Real.sqrt_pos.mpr hT + have hν_log_pos : 0 < ν_log := mul_pos hσ hsqrT_pos + have hν_log_sq : ν_log^2 = σ^2 * T := by + rw [ν_log_def, mul_pow, Real.sq_sqrt hT.le] + have h_algebra : μ_log + ν_log^2 / 2 = r * T := by rw [hν_log_sq]; ring + have h_shift_eq : ν_log - (-d_2) = d_1 := by + rw [d_1_def, d_2_def, bsd2]; ring + -- payoff(z) = if S_T(z) > K then S_T(z) else 0 + -- = indicator(Ioi(-d_2), S_T)(z) + have h_indic_eq : ∀ z : ℝ, + (Set.Ioi K).indicator (fun s ↦ s) (bsTerminal S_0 r σ T z) + = (Set.Ioi (-d_2)).indicator (fun z' ↦ bsTerminal S_0 r σ T z') z := + fun z ↦ indicator_bsTerminal_Ioi_comp hS_0 hK hσ hT (fun s ↦ s) z + have h_payoff_meas : Measurable fun z : ℝ ↦ + (Set.Ioi K).indicator (fun s ↦ s) (bsTerminal S_0 r σ T z) := by + have h_simp : (fun z : ℝ ↦ + (Set.Ioi K).indicator (fun s ↦ s) (bsTerminal S_0 r σ T z)) + = (Set.Ioi (-d_2)).indicator + (fun z' ↦ bsTerminal S_0 r σ T z') := funext h_indic_eq + rw [h_simp] + exact Measurable.indicator (by unfold bsTerminal; fun_prop) measurableSet_Ioi + -- Pull out e^{-rT}, HasLaw transfer, convert to volume + rw [integral_const_mul] + rw [show (fun ω ↦ (Set.Ioi K).indicator (fun s ↦ s) (bsTerminal S_0 r σ T (Z ω))) + = (fun z ↦ (Set.Ioi K).indicator (fun s ↦ s) (bsTerminal S_0 r σ T z)) ∘ Z + from rfl, + hZ.integral_comp h_payoff_meas.aestronglyMeasurable, + integral_gaussianReal_eq_integral_smul (one_ne_zero : (1 : ℝ≥0) ≠ 0)] + have h_smul_eq : + (fun z : ℝ ↦ gaussianPDFReal 0 1 z • + (Set.Ioi K).indicator (fun s ↦ s) (bsTerminal S_0 r σ T z)) + = (Set.Ioi (-d_2)).indicator + (fun z ↦ gaussianPDFReal 0 1 z * bsTerminal S_0 r σ T z) := by + funext z + rw [smul_eq_mul, h_indic_eq z] + by_cases hz : z ∈ Set.Ioi (-d_2) + · rw [Set.indicator_of_mem hz, Set.indicator_of_mem hz] + · rw [Set.indicator_of_notMem hz, Set.indicator_of_notMem hz, mul_zero] + rw [h_smul_eq, integral_indicator measurableSet_Ioi] + -- Decompose: pdf · S_T(z) = S_0 · exp(μ_log) · (exp(ν_log z) · pdf) + have h_split_integrand : ∀ z : ℝ, + gaussianPDFReal 0 1 z * bsTerminal S_0 r σ T z + = (S_0 * Real.exp μ_log) * (Real.exp (ν_log * z) * gaussianPDFReal 0 1 z) := by + intro z + unfold bsTerminal + have h_exp : Real.exp ((r - σ^2 / 2) * T + σ * Real.sqrt T * z) + = Real.exp μ_log * Real.exp (ν_log * z) := by + change Real.exp ((r - σ^2 / 2) * T + σ * Real.sqrt T * z) + = Real.exp ((r - σ^2 / 2) * T) * Real.exp (σ * Real.sqrt T * z) + exact Real.exp_add _ _ + rw [h_exp]; ring + rw [setIntegral_congr_fun measurableSet_Ioi (fun z _ ↦ h_split_integrand z)] + rw [integral_const_mul, integral_exp_mul_gaussianPDFReal_Ioi, h_shift_eq] + -- Final algebra: e^{-rT} · S_0 · e^{μ_log} · e^{ν_log²/2} · Phi(d_1) = S_0 · Phi(d_1) + have h_exp_combine : Real.exp (-r * T) * Real.exp μ_log * Real.exp (ν_log^2 / 2) = 1 := by + rw [mul_assoc, ← Real.exp_add, ← Real.exp_add, + show -r * T + (μ_log + ν_log^2 / 2) = 0 from by rw [h_algebra]; ring] + exact Real.exp_zero + calc Real.exp (-r * T) * + (S_0 * Real.exp μ_log * (Real.exp (ν_log^2 / 2) * Phi d_1)) + = (Real.exp (-r * T) * Real.exp μ_log * Real.exp (ν_log^2 / 2)) * (S_0 * Phi d_1) := by + ring + _ = 1 * (S_0 * Phi d_1) := by rw [h_exp_combine] + _ = S_0 * Phi d_1 := by rw [one_mul] + +/-! ### Call decomposition into digitals -/ + +/-- The vanilla European call decomposes as `AssetDigital − K · CashDigital`: + `C = (S_0 · Φ(d_1)) − K · (e^{-rT} · Φ(d_2))`. + +A direct algebraic consequence of `bs_call_formula`, +`bs_asset_or_nothing_formula`, and `bs_cash_or_nothing_formula`. -/ +theorem bs_call_eq_asset_minus_K_cash {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + (∫ ω, Real.exp (-r * T) * max (bsTerminal S_0 r σ T (Z ω) - K) 0 ∂Q) + = + (∫ ω, Real.exp (-r * T) * + (Set.Ioi K).indicator + (fun s ↦ s) (bsTerminal S_0 r σ T (Z ω)) ∂Q) + - K * + (∫ ω, Real.exp (-r * T) * + (Set.Ioi K).indicator (fun _ ↦ (1 : ℝ)) (bsTerminal S_0 r σ T (Z ω)) ∂Q) := by + rw [bs_call_formula h, bs_asset_or_nothing_formula h, bs_cash_or_nothing_formula h] + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/DigitalGreeks.lean b/LeanPool/MathFin/Models/BlackScholes/DigitalGreeks.lean new file mode 100644 index 0000000000..439cc252c0 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/DigitalGreeks.lean @@ -0,0 +1,332 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.PDE + +/-! +# Black–Scholes digital option Greeks + +For the two digital (binary) European options: + +* **Cash-or-nothing** call price `V_cash(S, τ) = e^{-rτ} Φ(d₂)`. +* **Asset-or-nothing** call price `V_asset(S, τ) = S Φ(d₁)`. + +We derive their deltas and gammas: + +* `hasDerivAt_bsCashDigital_S` — δ_cash = e^{-rτ} ϕ(d₂) / (S σ √τ). +* `hasDerivAt_bsAssetDigital_S` — δ_asset = Φ(d₁) + ϕ(d₁) / (σ √τ). +* `hasDerivAt_deriv_bsAssetDigital_S` — γ_asset = -ϕ(d₁) · d₂ / (S σ² τ). +* `hasDerivAt_deriv_bsCashDigital_S` — γ_cash = -e^{-rτ} ϕ(d₂) · d₁ / (S² σ² τ). + +(δ_asset is the product rule on `S · Φ(d₁(S))`, with +`S · ϕ(d₁) · ∂_S d₁ = ϕ(d₁)/(σ√τ)`; γ_asset collapses via `σ√τ − d₁ = -d₂`, and +γ_cash via `d₂ + σ√τ = d₁`. Each gamma differentiates its delta's formula +(`hasDerivAt_bsAssetDigital_SS`, `hasDerivAt_bsCashDigital_SS`) before +`hasDerivAt_deriv_of_eventually` makes it a statement about the price.) + +The strike derivative of the cash digital, `−e^{-rτ} ϕ(d₂) / (K σ √τ)`, is +`hasDerivAt_bsCashDigital_K` in `StrikeGreeks.lean`. + +## Main definitions + +* `bsCashDigital`: the cash-or-nothing call price `e^{−rτ} Φ(d₂)` as a function of `(S, τ)`. +* `bsAssetDigital`: the asset-or-nothing call price `S Φ(d₁)` as a function of `(S, τ)`. + +## Main results + +* `hasDerivAt_bsCashDigital_S`, `hasDerivAt_bsAssetDigital_S`: the deltas + `e^{−rτ} ϕ(d₂) / (S σ √τ)` and `Φ(d₁) + ϕ(d₁) / (σ √τ)`, for positive `K, σ, S, τ`. +* `hasDerivAt_deriv_bsCashDigital_S`, `hasDerivAt_deriv_bsAssetDigital_S`: the gammas + `−e^{−rτ} ϕ(d₂) d₁ / (S² σ² τ)` and `−ϕ(d₁) d₂ / (S σ² τ)`, as derivatives of the delta. +* `hasDerivAt_bsCashDigital_sigma`, `hasDerivAt_bsAssetDigital_sigma`: the vegas + `−e^{−rτ} ϕ(d₂) d₁ / σ` and `−S ϕ(d₁) d₂ / σ`. +* `hasDerivAt_bsCashDigital_r`, `hasDerivAt_bsAssetDigital_r`: the rhos + `e^{−rτ} (ϕ(d₂) √τ/σ − τ Φ(d₂))` and `S ϕ(d₁) √τ/σ`. +* `hasDerivAt_bsCashDigital_tau`, `hasDerivAt_bsAssetDigital_tau`: the `τ`-derivatives (thetas + in the maturity variable) of the two prices. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 26.1 + +## Tags + +digital option, binary option Greeks, delta and gamma, cash-or-nothing, asset-or-nothing, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- Cash-or-nothing digital call price as a function of `(S, τ)`. -/ +noncomputable def bsCashDigital (K r σ : ℝ) (S τ : ℝ) : ℝ := + Real.exp (-(r * τ)) * Phi (bsd2 S K r σ τ) + +/-- Asset-or-nothing digital call price as a function of `(S, τ)`. -/ +noncomputable def bsAssetDigital (K r σ : ℝ) (S τ : ℝ) : ℝ := + S * Phi (bsd1 S K r σ τ) + +/-- **Cash-or-nothing delta**: `∂_S V_cash = e^{-rτ} ϕ(d₂) / (S σ √τ)`. + +Direct chain rule on `Φ ∘ d₂(S)`. -/ +lemma hasDerivAt_bsCashDigital_S {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ bsCashDigital K r σ s τ) + (Real.exp (-(r * τ)) * gaussianPDFReal 0 1 (bsd2 S K r σ τ) / (S * σ * Real.sqrt τ)) S := by + have h_d2_S := hasDerivAt_bsd2_S (r := r) hK hσ hτ hS + have h_Phi_d2 := (hasDerivAt_Phi (bsd2 S K r σ τ)).comp S h_d2_S + have h := h_Phi_d2.const_mul (Real.exp (-(r * τ))) + unfold bsCashDigital + convert h using 1 <;> try rfl + ring + +/-- **Asset-or-nothing delta**: `∂_S V_asset = Φ(d₁) + ϕ(d₁) / (σ √τ)`. + +The chain rule gives `Φ(d₁) + S · ϕ(d₁) · ∂_S d₁ = Φ(d₁) + S · ϕ(d₁) · 1/(S σ √τ) += Φ(d₁) + ϕ(d₁) / (σ √τ)`. -/ +lemma hasDerivAt_bsAssetDigital_S {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ bsAssetDigital K r σ s τ) + (Phi (bsd1 S K r σ τ) + gaussianPDFReal 0 1 (bsd1 S K r σ τ) / (σ * Real.sqrt τ)) S := by + have h_sqrt_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_ne : Real.sqrt τ ≠ 0 := h_sqrt_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have hS_ne : S ≠ 0 := hS.ne' + have h_d1_S := hasDerivAt_bsd1_S (r := r) hK hσ hτ hS + have h_Phi_d1 := (hasDerivAt_Phi (bsd1 S K r σ τ)).comp S h_d1_S + have h_id : HasDerivAt (fun s : ℝ ↦ s) 1 S := hasDerivAt_id S + have h := h_id.mul h_Phi_d1 + unfold bsAssetDigital + convert h using 1 <;> try rfl + simp only [Function.comp_apply] + field_simp + +/-- **The asset-or-nothing gamma formula**: the S-derivative of the delta +`δ_asset = Φ(d₁) + ϕ(d₁)/(σ√τ)` is `-ϕ(d₁) · d₂ / (S σ² τ)`. The second derivative of the +price itself is `hasDerivAt_deriv_bsAssetDigital_S`. + +Differentiating δ_asset: the Φ-term contributes +`ϕ(d₁) · ∂_S d₁ = ϕ(d₁)/(Sσ√τ)`, and the ϕ-term contributes +`-d₁ ϕ(d₁) · ∂_S d₁ / (σ√τ) = -d₁ ϕ(d₁)/(Sσ²τ)`. Sum via `σ√τ − d₁ = -d₂`. -/ +private lemma hasDerivAt_bsAssetDigital_SS {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt + (fun s ↦ Phi (bsd1 s K r σ τ) + + gaussianPDFReal 0 1 (bsd1 s K r σ τ) / (σ * Real.sqrt τ)) + (-(gaussianPDFReal 0 1 (bsd1 S K r σ τ) * + bsd2 S K r σ τ / (S * σ ^ 2 * τ))) S := by + have h_sqrt_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_ne : Real.sqrt τ ≠ 0 := h_sqrt_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have hS_ne : S ≠ 0 := hS.ne' + have h_sqrt_sq : Real.sqrt τ ^ 2 = τ := Real.sq_sqrt hτ.le + have h_d1_S := hasDerivAt_bsd1_S (r := r) hK hσ hτ hS + -- ∂_S Φ(d₁) = ϕ(d₁) · ∂_S d₁ + have h_Phi := (hasDerivAt_Phi (bsd1 S K r σ τ)).comp S h_d1_S + -- ∂_S ϕ(d₁) = -d₁ ϕ(d₁) · ∂_S d₁ + have h_pdf := (hasDerivAt_gaussianPDFReal_zero_one (bsd1 S K r σ τ)).comp S h_d1_S + -- ∂_S [ϕ(d₁) / (σ √τ)] = (∂_S ϕ(d₁)) / (σ √τ) + have h_pdf_div := h_pdf.div_const (σ * Real.sqrt τ) + have h_full := h_Phi.add h_pdf_div + convert h_full using 1 <;> try rfl + rw [show bsd2 S K r σ τ = bsd1 S K r σ τ - σ * Real.sqrt τ from by rw [bsd2]] + field_simp + rw [show Real.sqrt τ ^ 2 = τ from h_sqrt_sq] + ring + +/-- **Asset-or-nothing gamma**: `∂²V_asset/∂S² = -ϕ(d₁) · d₂ / (S σ² τ)`, for the price +itself: `δ_asset` is `∂V_asset/∂S` on all of `S > 0` (`hasDerivAt_bsAssetDigital_S`), and its +derivative is the gamma formula (`hasDerivAt_bsAssetDigital_SS`). -/ +theorem hasDerivAt_deriv_bsAssetDigital_S {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (deriv fun s ↦ bsAssetDigital K r σ s τ) + (-(gaussianPDFReal 0 1 (bsd1 S K r σ τ) * bsd2 S K r σ τ / (S * σ ^ 2 * τ))) S := + hasDerivAt_deriv_of_eventually + ((eventually_gt_nhds hS).mono fun _ hs ↦ hasDerivAt_bsAssetDigital_S hK hσ hs hτ) + (hasDerivAt_bsAssetDigital_SS hK hσ hS hτ) + +/-- **Asset-or-nothing theta**: `∂_τ V_asset = S · ϕ(d₁) · ∂_τ d₁`. + +Direct chain rule. The Lean form of `∂_τ d₁` is `((r + σ²/2)τ − log(S/K)) / (2 σ τ √τ)`; +this equals the textbook clean form `(r + σ²/2)/(σ√τ) − d₁/(2τ)` by algebraic +identity (left to the consumer). -/ +lemma hasDerivAt_bsAssetDigital_tau (S K r σ : ℝ) (hσ : 0 < σ) {τ : ℝ} (hτ : 0 < τ) : + HasDerivAt (fun t ↦ bsAssetDigital K r σ S t) + (S * gaussianPDFReal 0 1 (bsd1 S K r σ τ) * + (((r + σ^2/2) * τ - Real.log (S/K)) / (2 * σ * τ * Real.sqrt τ))) τ := by + have h_d1_τ := hasDerivAt_bsd1_tau S K r σ hσ hτ + have h_Phi := (hasDerivAt_Phi (bsd1 S K r σ τ)).comp τ h_d1_τ + have h := h_Phi.const_mul S + unfold bsAssetDigital + convert h using 1 <;> try rfl + ring + +/-- **Cash-or-nothing theta**: `∂_τ V_cash = -r · e^{-rτ} · Φ(d₂) + e^{-rτ} · ϕ(d₂) · ∂_τ d₂`. + +Product rule on `V_cash(τ) = e^{-rτ} · Φ(d₂(τ))`: +* `∂_τ e^{-rτ} = -r · e^{-rτ}` +* `∂_τ Φ(d₂(τ)) = ϕ(d₂) · ∂_τ d₂`. -/ +lemma hasDerivAt_bsCashDigital_tau (S K r σ : ℝ) (hσ : 0 < σ) {τ : ℝ} (hτ : 0 < τ) : + HasDerivAt (fun t ↦ bsCashDigital K r σ S t) + (-r * Real.exp (-(r * τ)) * Phi (bsd2 S K r σ τ) + + Real.exp (-(r * τ)) * gaussianPDFReal 0 1 (bsd2 S K r σ τ) * + (((r + σ^2/2) * τ - Real.log (S/K)) / (2 * σ * τ * Real.sqrt τ) + - σ / (2 * Real.sqrt τ))) τ := by + have h_d2_τ := hasDerivAt_bsd2_tau S K r σ hσ hτ + have h_Phi := (hasDerivAt_Phi (bsd2 S K r σ τ)).comp τ h_d2_τ + have h_neg : HasDerivAt (fun t : ℝ ↦ -(r * t)) (-r) τ := by + have h := (hasDerivAt_id τ).const_mul r + convert h.neg using 1 <;> first | rfl | ring + have h_exp : HasDerivAt (fun t : ℝ ↦ Real.exp (-(r * t))) + (Real.exp (-(r * τ)) * (-r)) τ := h_neg.exp + have h := h_exp.mul h_Phi + unfold bsCashDigital + convert h using 1 <;> try rfl + simp only [Function.comp_apply] + ring + +/-- **Asset-or-nothing vega**: `∂_σ V_asset = -S · ϕ(d₁) · d₂ / σ`. + +Chain rule on `Φ ∘ d₁`. The Lean form of `∂_σ d₁` is +`(σ²τ/2 − log(S/K) − rτ)/(σ²√τ)`, which equals `-d₂/σ` via `bsd2_eq`. -/ +lemma hasDerivAt_bsAssetDigital_sigma (S K r : ℝ) {σ τ : ℝ} (hσ : 0 < σ) (hτ : 0 < τ) : + HasDerivAt (fun σ' ↦ bsAssetDigital K r σ' S τ) + (-(S * gaussianPDFReal 0 1 (bsd1 S K r σ τ) * bsd2 S K r σ τ / σ)) σ := by + have h_sqrt_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_ne : Real.sqrt τ ≠ 0 := h_sqrt_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have h_sqrt_sq : Real.sqrt τ ^ 2 = τ := Real.sq_sqrt hτ.le + have h_d1_σ := hasDerivAt_bsd1_sigma S K r hσ hτ + have h_Phi := (hasDerivAt_Phi (bsd1 S K r σ τ)).comp σ h_d1_σ + have h := h_Phi.const_mul S + unfold bsAssetDigital + convert h using 1 <;> try rfl + rw [bsd2_eq hσ hτ] + field_simp + ring + +/-- **Cash-or-nothing vega**: `∂_σ V_cash = -e^{-rτ} · ϕ(d₂) · d₁ / σ`. + +Chain rule on `Φ ∘ d₂`. The Lean form of `∂_σ d₂ = ∂_σ d₁ − √τ` equals `-d₁/σ` +via `bsd2_eq` plus the identity `bsd2 + σ√τ = bsd1`. -/ +lemma hasDerivAt_bsCashDigital_sigma (S K : ℝ) {r σ τ : ℝ} (hσ : 0 < σ) (hτ : 0 < τ) : + HasDerivAt (fun σ' ↦ bsCashDigital K r σ' S τ) + (-(Real.exp (-(r * τ)) * gaussianPDFReal 0 1 (bsd2 S K r σ τ) * + bsd1 S K r σ τ / σ)) σ := by + have h_sqrt_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_ne : Real.sqrt τ ≠ 0 := h_sqrt_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have h_sqrt_sq : Real.sqrt τ ^ 2 = τ := Real.sq_sqrt hτ.le + have h_d2_σ := hasDerivAt_bsd2_sigma S K r hσ hτ + have h_Phi := (hasDerivAt_Phi (bsd2 S K r σ τ)).comp σ h_d2_σ + have h := h_Phi.const_mul (Real.exp (-(r * τ))) + unfold bsCashDigital + convert h using 1 <;> try rfl + rw [show bsd1 S K r σ τ = bsd2 S K r σ τ + σ * Real.sqrt τ from by + rw [bsd2]; ring] + rw [bsd2_eq hσ hτ] + field_simp + ring + +/-- **Asset-or-nothing rho**: `∂_r V_asset = S · ϕ(d₁) · √τ / σ`. + +Direct chain rule since `∂_r d₁ = √τ/σ` (the difference `d₁ − d₂` is `r`-independent). -/ +lemma hasDerivAt_bsAssetDigital_r (S K σ : ℝ) (hσ : 0 < σ) {τ : ℝ} (hτ : 0 < τ) (r : ℝ) : + HasDerivAt (fun r' ↦ bsAssetDigital K r' σ S τ) + (S * gaussianPDFReal 0 1 (bsd1 S K r σ τ) * (Real.sqrt τ / σ)) r := by + have h_d1_r := hasDerivAt_bsd1_r S K σ τ hσ hτ r + have h_Phi := (hasDerivAt_Phi (bsd1 S K r σ τ)).comp r h_d1_r + have h := h_Phi.const_mul S + unfold bsAssetDigital + convert h using 1 <;> try rfl + ring + +/-- **Cash-or-nothing rho**: `∂_r V_cash = e^{-rτ} · (ϕ(d₂) · √τ/σ − τ · Φ(d₂))`. + +Product rule on `V_cash(r) = e^{-rτ} · Φ(d₂(r))`: +* `∂_r e^{-rτ} = -τ · e^{-rτ}` +* `∂_r Φ(d₂(r)) = ϕ(d₂) · √τ/σ`. -/ +lemma hasDerivAt_bsCashDigital_r (S K σ : ℝ) (hσ : 0 < σ) {τ : ℝ} (hτ : 0 < τ) (r : ℝ) : + HasDerivAt (fun r' ↦ bsCashDigital K r' σ S τ) + (Real.exp (-(r * τ)) * + (gaussianPDFReal 0 1 (bsd2 S K r σ τ) * (Real.sqrt τ / σ) + - τ * Phi (bsd2 S K r σ τ))) r := by + have h_d2_r := hasDerivAt_bsd2_r S K σ τ hσ hτ r + have h_Phi := (hasDerivAt_Phi (bsd2 S K r σ τ)).comp r h_d2_r + have h_neg_r : HasDerivAt (fun r' : ℝ ↦ -(r' * τ)) (-τ) r := by + have h := (hasDerivAt_id r).mul_const τ + convert h.neg using 1 <;> first | rfl | ring + have h_exp : HasDerivAt (fun r' : ℝ ↦ Real.exp (-(r' * τ))) + (Real.exp (-(r * τ)) * (-τ)) r := h_neg_r.exp + have h := h_exp.mul h_Phi + unfold bsCashDigital + convert h using 1 <;> try rfl + simp only [Function.comp_apply] + ring + +/-- **The cash-or-nothing gamma formula**: the S-derivative of the delta +`δ_cash(s) = e^{-rτ} · ϕ(d₂(s)) / (s · σ · √τ)` is `-e^{-rτ} · ϕ(d₂) · d₁ / (S² σ² τ)`. The +second derivative of the price itself is `hasDerivAt_deriv_bsCashDigital_S`. + +Differentiating δ_cash as a quotient +`f(s)/g(s)` with `f(s) = e^{-rτ} · ϕ(d₂(s))` and `g(s) = s · σ · √τ`: +* `f'(S) = e^{-rτ} · (-d₂ · ϕ(d₂)) · (1/(S σ √τ))` +* `g'(S) = σ · √τ` +* `(f/g)'(S) = (f' · g − f · g') / g²` +* Numerator algebraically collapses via `d₂ + σ√τ = d₁`. -/ +private lemma hasDerivAt_bsCashDigital_SS {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt + (fun s ↦ Real.exp (-(r * τ)) * + gaussianPDFReal 0 1 (bsd2 s K r σ τ) / (s * σ * Real.sqrt τ)) + (-(Real.exp (-(r * τ)) * gaussianPDFReal 0 1 (bsd2 S K r σ τ) * + bsd1 S K r σ τ / (S ^ 2 * σ ^ 2 * τ))) S := by + have h_sqrt_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_ne : Real.sqrt τ ≠ 0 := h_sqrt_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have hS_ne : S ≠ 0 := hS.ne' + have h_sqrt_sq : Real.sqrt τ ^ 2 = τ := Real.sq_sqrt hτ.le + have h_denom_ne : S * σ * Real.sqrt τ ≠ 0 := + mul_ne_zero (mul_ne_zero hS_ne hσ_ne) h_sqrt_ne + have h_d2_S := hasDerivAt_bsd2_S (r := r) hK hσ hτ hS + have h_pdf := (hasDerivAt_gaussianPDFReal_zero_one (bsd2 S K r σ τ)).comp S h_d2_S + -- Numerator f(s) = e^{-rτ} · ϕ(d₂(s)). + have h_num := h_pdf.const_mul (Real.exp (-(r * τ))) + -- Denominator g(s) = s · σ · √τ. + have h_id : HasDerivAt (fun s : ℝ ↦ s) 1 S := hasDerivAt_id S + have h_denom : HasDerivAt (fun s : ℝ ↦ s * σ * Real.sqrt τ) (σ * Real.sqrt τ) S := by + have h := (h_id.mul_const σ).mul_const (Real.sqrt τ) + convert h using 1; ring + have h_div := h_num.div h_denom h_denom_ne + convert h_div using 1 + all_goals try rfl + have h_bsd1 : bsd1 S K r σ τ = bsd2 S K r σ τ + σ * Real.sqrt τ := by + rw [bsd2]; ring + rw [h_bsd1] + simp only [Function.comp_apply] + field_simp + rw [show Real.sqrt τ ^ 2 = τ from h_sqrt_sq] + ring + +/-- **Cash-or-nothing gamma**: `∂²V_cash/∂S² = -e^{-rτ} · ϕ(d₂) · d₁ / (S² σ² τ)`, for the +price itself: `δ_cash` is `∂V_cash/∂S` on all of `S > 0` (`hasDerivAt_bsCashDigital_S`), and +its derivative is the gamma formula (`hasDerivAt_bsCashDigital_SS`). -/ +theorem hasDerivAt_deriv_bsCashDigital_S {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (deriv fun s ↦ bsCashDigital K r σ s τ) + (-(Real.exp (-(r * τ)) * gaussianPDFReal 0 1 (bsd2 S K r σ τ) * bsd1 S K r σ τ / + (S ^ 2 * σ ^ 2 * τ))) S := + hasDerivAt_deriv_of_eventually + ((eventually_gt_nhds hS).mono fun _ hs ↦ hasDerivAt_bsCashDigital_S hK hσ hs hτ) + (hasDerivAt_bsCashDigital_SS hK hσ hS hτ) + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/Dividends.lean b/LeanPool/MathFin/Models/BlackScholes/Dividends.lean new file mode 100644 index 0000000000..761b193a35 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/Dividends.lean @@ -0,0 +1,142 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.GarmanNormalForm + +/-! +# Black-Scholes-Merton call price with continuous dividend yield + +Extension of `bs_call_formula` to an asset paying a continuous dividend yield +`q ≥ 0`. The risk-neutral dynamics become `S_T = S_0 · exp((r − q − σ²/2) T + σ √T Z)`, +i.e., the drift is the **effective rate** `r − q`. The discounted-payoff formula is + + `V_q = S_0 · e^{-qT} · Φ(d₁) − K · e^{-rT} · Φ(d₂)`, + +where `d₁ = (log(S_0/K) + (r − q + σ²/2) T) / (σ √T)` and `d₂ = d₁ − σ √T`, +i.e., `bsd1 / bsd2` evaluated at the effective rate `r − q`. + +Derivation: apply `bs_call_formula` with rate parameter `r − q`, then +multiply through by the additional discount `e^{-qT}` (since the discount on +the LHS uses the actual rate `r`, not the drift `r − q`). + +The **Garman–Kohlhagen** FX call is the same theorem read with `r = r_d` (domestic rate) and +`q = r_f` (foreign rate): the foreign currency accrues `r_f` to its holder as a dividend yield. + +## Main definitions + +* `quantoForward`: the quanto-adjusted forward `S_0 · exp((r_dom − ρ σ_S σ_FX) T)`. + +## Main results + +* `bs_dividends_call_formula`: under `BSCallHyp` at the effective rate `r − q`, the expected + discounted call payoff `∫ e^{−rT} · max (S_T − K) 0 ∂Q` equals + `S_0 e^{−qT} Φ(d₁) − K e^{−rT} Φ(d₂)`, with `d₁, d₂` evaluated at `r − q`. +* `bs_dividends_price_eq_bsVGarman`: the same expected payoff equals `bsVGarman` at spot + `S_0 e^{−qT}` and discount factor `e^{−rT}`. +* `quanto_correction_factor`: for `S_0 > 0`, + `quantoForward / (S_0 e^{r_dom T}) = exp(−ρ σ_S σ_FX T)`. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 17.1; 17.3; 31.4 +* [Reiner (1992)][Reiner1992] + +## Tags + +continuous dividend yield, Black–Scholes–Merton, effective rate, dividend-paying asset, +cost of carry, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- **Black-Scholes-Merton call** pricing formula with continuous dividend yield `q`. + +Given a risk-neutral hypothesis with effective drift `r − q` +(`BSCallHyp Q S_0 K (r − q) σ T Z`), the discounted (by the **actual rate** `r`) +expected payoff of the European call is + + `S_0 · e^{-qT} · Φ(d₁) − K · e^{-rT} · Φ(d₂)`, + +with `d_i = bsdi S_0 K (r − q) σ T`. + +At `r = r_d`, `q = r_f` it is the Garman–Kohlhagen FX call. + +Proof: factor `e^{-rT} = e^{-qT} · e^{-(r−q)T}` to apply `bs_call_formula`. -/ +theorem bs_dividends_call_formula {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r q σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K (r - q) σ T Z) : + ∫ ω, Real.exp (-r * T) * max (bsTerminal S_0 (r - q) σ T (Z ω) - K) 0 ∂Q + = S_0 * Real.exp (-(q * T)) * Phi (bsd1 S_0 K (r - q) σ T) + - K * Real.exp (-(r * T)) * Phi (bsd2 S_0 K (r - q) σ T) := by + have h_bs := bs_call_formula h + -- e^{-rT} = e^{-qT} · e^{-(r-q)T} + have h_factor : + (fun ω ↦ Real.exp (-r * T) * max (bsTerminal S_0 (r - q) σ T (Z ω) - K) 0) + = (fun ω ↦ Real.exp (-(q * T)) * + (Real.exp (-(r - q) * T) * max (bsTerminal S_0 (r - q) σ T (Z ω) - K) 0)) := by + funext ω + rw [← mul_assoc, ← Real.exp_add] + congr 2 + ring + rw [h_factor, integral_const_mul, h_bs] + have h_combine : Real.exp (-(q * T)) * Real.exp (-(r - q) * T) = Real.exp (-(r * T)) := by + rw [← Real.exp_add]; congr 1; ring + linear_combination -(K * Phi (bsd2 S_0 K (r - q) σ T)) * h_combine + +/-- **BS-Merton dividend price is a Garman-normal-form instance**: the +discounted expected dividend-adjusted call payoff equals `bsVGarman` at +`A = S₀ · e^{−qT}`, `DF = e^{−rT}` — the dividend-discounted-asset numéraire. +Routes `bs_dividends_call_formula` through +`Models/BlackScholes/GarmanNormalForm`'s `bs_dividends_RHS_eq_bsVGarman`, making the +unification load-bearing from the consumer side. -/ +theorem bs_dividends_price_eq_bsVGarman {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r q σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K (r - q) σ T Z) : + ∫ ω, Real.exp (-r * T) * max (bsTerminal S_0 (r - q) σ T (Z ω) - K) 0 ∂Q + = bsVGarman (S_0 * Real.exp (-(q * T))) K (Real.exp (-(r * T))) σ T := by + rw [bs_dividends_call_formula h] + exact bs_dividends_RHS_eq_bsVGarman S_0 K r q σ T h.S_0_pos h.K_pos + +/-! ## Quanto correction (folded from `Quanto.lean`) + +A **quanto** is a derivative paying a function of a foreign asset in domestic +currency. Under the domestic risk-neutral measure, the foreign asset acquires +a *quanto-adjusted drift* `μ^{quanto} = r_dom − ρ · σ_S · σ_FX`. The forward +becomes + + `F^{quanto} = S₀ · exp((r_dom − ρ σ_S σ_FX) · T)`, + +vs the unadjusted domestic forward `F^{dom} = S₀ · exp(r_dom T)`. The +correction factor is `exp(−ρ σ_S σ_FX T)`, the log-covariance term in the +joint MGF. -/ + +/-- **Quanto-adjusted forward**: foreign asset's forward under the domestic +risk-neutral measure with quanto drift adjustment `−ρ σ_S σ_FX`. -/ +noncomputable def quantoForward (S_0 r_dom ρ σ_S σ_FX T : ℝ) : ℝ := + S_0 * Real.exp ((r_dom - ρ * σ_S * σ_FX) * T) + +/-- **Quanto correction factor**: ratio of quanto-adjusted forward to +unadjusted domestic forward equals `exp(−ρ σ_S σ_FX T)`. -/ +theorem quanto_correction_factor (S_0 r_dom ρ σ_S σ_FX T : ℝ) (hS : 0 < S_0) : + quantoForward S_0 r_dom ρ σ_S σ_FX T / (S_0 * Real.exp (r_dom * T)) + = Real.exp (-(ρ * σ_S * σ_FX * T)) := by + unfold quantoForward + have hS_ne : S_0 ≠ 0 := hS.ne' + have h_exp_pos : 0 < Real.exp (r_dom * T) := Real.exp_pos _ + rw [mul_div_mul_left _ _ hS_ne, ← Real.exp_sub] + congr 1 + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/DividendsGreeks.lean b/LeanPool/MathFin/Models/BlackScholes/DividendsGreeks.lean new file mode 100644 index 0000000000..af58475947 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/DividendsGreeks.lean @@ -0,0 +1,277 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho, Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.PutGreeks + +/-! +# Black-Scholes-Merton (continuous dividends) Greeks + +For the dividends-adjusted call price `V_q(S, σ, T) = S e^{-qT} Φ(d₁') − K e^{-rT} Φ(d₂')` +with `d_i' = bsdi S K (r-q) σ T`, we identify `V_q = e^{-qT} · bsV(K, r-q, σ, S, T)` +and derive the Greeks via existing call Greeks at effective drift `r − q`. + +## Main definitions + +* `bsVDiv`: the dividend-adjusted call closed form `e^{−qτ} · bsV K (r − q) σ S τ`. +* `bsPDiv`: the dividend-adjusted put closed form `e^{−qτ} · bsP K (r − q) σ S τ`. + +## Main results + +* `hasDerivAt_bsVDiv_S` — δ_q = e^{-qT} · Φ(d₁'). +* `hasDerivAt_deriv_bsVDiv_S` — γ_q = e^{-qT} · ϕ(d₁') / (S σ √τ), from the + formula-level `hasDerivAt_bsVDiv_SS`. +* `hasDerivAt_bsVDiv_sigma` — vega_q = e^{-qT} · S · ϕ(d₁') · √τ. +* `bsVDiv_pde` — Hull eq. (19.4) with dividend yield: `Θ + (r−q) S Δ + ½ σ² S² Γ = r V`, + stated on the Greek formulas. +* `bsVDiv_psi_nonpos` — the psi formula `−S τ e^{-qτ} Φ(d₁')` of `hasDerivAt_bsVDiv_q` is `≤ 0` + for `S, τ ≥ 0`; `antitone_bsVDiv_q` — so, for `K, σ, τ, S > 0`, the call price is + non-increasing in the dividend yield. +* `bsPDiv`, `bsPDiv_eq_bsVDiv` — the dividend-adjusted put and put-call parity with yield `q` + (Hull §17.4): `P_q = V_q − S e^{-qτ} + K e^{-rτ}`. +* `hasDerivAt_bsPDiv_q`, `bsPDiv_psi_nonneg` — put psi `∂_q P_q = S τ e^{-qτ} Φ(−d₁')`, and + that formula is `≥ 0` for `S, τ ≥ 0`; `monotone_bsPDiv_q` — so, for `K, σ, τ, S > 0`, the put + price is non-decreasing in `q`. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 17.1 + +## Tags + +dividend yield, Black–Scholes–Merton, option Greeks, effective drift, sensitivities, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- Dividends-adjusted BS call price. Identity: `V_q = e^{-qT} · bsV(K, r-q, σ, S, T)`. -/ +noncomputable def bsVDiv (K r q σ : ℝ) (S τ : ℝ) : ℝ := + Real.exp (-(q * τ)) * bsV K (r - q) σ S τ + +/-- **BS-Merton delta**: `∂_S V_q = e^{-qT} · Φ(d₁')` where `d₁' = bsd1 S K (r-q) σ T`. -/ +lemma hasDerivAt_bsVDiv_S {K r q σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ bsVDiv K r q σ s τ) + (Real.exp (-(q * τ)) * Phi (bsd1 S K (r - q) σ τ)) S := + (hasDerivAt_bsV_S (r := r - q) hK hσ hS hτ).const_mul (Real.exp (-(q * τ))) + +/-- **The BS-Merton gamma formula**: the S-derivative of the delta `e^{-qτ} · Φ(d₁')` is +`e^{-qτ} · ϕ(d₁') / (S σ √τ)`. The second derivative of the price itself is +`hasDerivAt_deriv_bsVDiv_S`. -/ +private lemma hasDerivAt_bsVDiv_SS {K r q σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ Real.exp (-(q * τ)) * Phi (bsd1 s K (r - q) σ τ)) + (Real.exp (-(q * τ)) * gaussianPDFReal 0 1 (bsd1 S K (r - q) σ τ) + / (S * σ * Real.sqrt τ)) S := by + have h_bs := hasDerivAt_Phi_bsd1_S (r := r - q) hK hσ hS hτ + have h := h_bs.const_mul (Real.exp (-(q * τ))) + convert h using 1 + ring + +/-- **BS-Merton gamma**: `∂²V_q/∂S² = e^{-qτ} · ϕ(d₁') / (S σ √τ)`, for the price itself: +the delta `e^{-qτ} · Φ(d₁')` is `∂V_q/∂S` on all of `S > 0` (`hasDerivAt_bsVDiv_S`), and its +derivative is the gamma formula (`hasDerivAt_bsVDiv_SS`). -/ +theorem hasDerivAt_deriv_bsVDiv_S {K r q σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (deriv fun s ↦ bsVDiv K r q σ s τ) + (Real.exp (-(q * τ)) * gaussianPDFReal 0 1 (bsd1 S K (r - q) σ τ) + / (S * σ * Real.sqrt τ)) S := + hasDerivAt_deriv_of_eventually + ((eventually_gt_nhds hS).mono fun _ hs ↦ hasDerivAt_bsVDiv_S hK hσ hs hτ) + (hasDerivAt_bsVDiv_SS hK hσ hS hτ) + +/-- **BS-Merton vega**: `∂_σ V_q = e^{-qT} · S · ϕ(d₁') · √τ`. -/ +lemma hasDerivAt_bsVDiv_sigma {K r q : ℝ} (hK : 0 < K) + {S σ τ : ℝ} (hS : 0 < S) (hσ : 0 < σ) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ bsVDiv K r q s S τ) + (Real.exp (-(q * τ)) * S * gaussianPDFReal 0 1 (bsd1 S K (r - q) σ τ) + * Real.sqrt τ) σ := by + have h_bs := hasDerivAt_bsV_sigma (r := r - q) hK hS hσ hτ + have h := h_bs.const_mul (Real.exp (-(q * τ))) + convert h using 1 <;> try rfl + ring + +/-- **BS-Merton rho**: `∂_r V_q = K · τ · e^{-rτ} · Φ(d₂')`. + +`V_q = e^{-qT} · bsV(K, r-q, σ, S, T)`. Chain rule on `r-q` gives +`∂_r V_q = e^{-qT} · bsV_rho(K, r-q, σ, S, T) = e^{-qT} · K·τ·e^{-(r-q)τ}·Φ(d₂')`, +and `e^{-qT} · e^{-(r-q)τ} = e^{-rτ}`. -/ +lemma hasDerivAt_bsVDiv_r {K q σ τ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) + {S : ℝ} (hS : 0 < S) (r : ℝ) : + HasDerivAt (fun r' ↦ bsVDiv K r' q σ S τ) + (K * τ * Real.exp (-(r * τ)) * Phi (bsd2 S K (r - q) σ τ)) r := by + -- Chain rule on r' ↦ r' - q. + have h_sub_q : HasDerivAt (fun r' : ℝ ↦ r' - q) 1 r := by + simpa using (hasDerivAt_id r).sub_const q + have h_bsV_rho := hasDerivAt_bsV_r (σ := σ) (τ := τ) hK hσ hτ hS (r - q) + have h_comp := h_bsV_rho.comp r h_sub_q + have h_full := h_comp.const_mul (Real.exp (-(q * τ))) + unfold bsVDiv + convert h_full using 1 + all_goals try rfl + -- Value: e^{-qτ} · (K·τ·e^{-(r-q)τ}·Φ(d_2) · 1) = K·τ·e^{-rτ}·Φ(d_2) + have h_exp_combine : + Real.exp (-(q * τ)) * Real.exp (-((r - q) * τ)) = Real.exp (-(r * τ)) := by + rw [← Real.exp_add]; congr 1; ring + linear_combination + -(K * τ * Phi (bsd2 S K (r - q) σ τ)) * h_exp_combine + +/-- **BS-Merton psi** (dividend Greek): `∂_q V_q = -S · τ · e^{-qτ} · Φ(d₁')`. + +`V_q = e^{-qτ} · bsV(K, r-q, σ, S, τ)`. Product rule: +* `∂_q [e^{-qτ}] = -τ · e^{-qτ}` +* `∂_q [bsV(K, r-q, σ, S, τ)] = -bsV_rho(K, r-q, σ, S, τ) = -K·τ·e^{-(r-q)τ}·Φ(d₂')` + +Combining and using `S · e^{-qτ} · Φ(d₁') − K · e^{-rτ} · Φ(d₂') = V_q`, +the result collapses to `-S · τ · e^{-qτ} · Φ(d₁')`. -/ +lemma hasDerivAt_bsVDiv_q {K r σ τ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) + {S : ℝ} (hS : 0 < S) (q : ℝ) : + HasDerivAt (fun q' ↦ bsVDiv K r q' σ S τ) + (-(S * τ * Real.exp (-(q * τ)) * Phi (bsd1 S K (r - q) σ τ))) q := by + -- Setup: f(q') = e^{-q'τ}, g(q') = bsV(K, r-q', σ, S, τ). V_q = f·g. + -- ∂_q' f = -τ · e^{-q'τ} + have h_f : HasDerivAt (fun q' : ℝ ↦ Real.exp (-(q' * τ))) + (-τ * Real.exp (-(q * τ))) q := by + have h_neg : HasDerivAt (fun q' : ℝ ↦ -(q' * τ)) (-τ) q := by + have := (hasDerivAt_id q).mul_const τ + convert this.neg using 1 <;> first | rfl | ring + have h := h_neg.exp + convert h using 1 + ring + -- ∂_q' [bsV(K, r-q', σ, S, τ)] via chain rule on (r - q'). + have h_sub : HasDerivAt (fun q' : ℝ ↦ r - q') (-1) q := by + have := (hasDerivAt_id q).const_sub r + simpa using this + have h_bsV_rho := hasDerivAt_bsV_r (σ := σ) (τ := τ) hK hσ hτ hS (r - q) + have h_g := h_bsV_rho.comp q h_sub + -- h_g : HasDerivAt (fun q' ↦ bsV K (r - q') σ S τ) (K·τ·e^{-(r-q)τ}·Φ(d_2) · -1) q + -- Product: V_q' = f(q') · g(q'), derivative = f'(q)·g(q) + f(q)·g'(q). + have h_full := h_f.mul h_g + unfold bsVDiv + convert h_full using 1 <;> try rfl + simp only [Function.comp_apply] + unfold bsV + ring + +/-- **BS-Merton theta** (`∂_τ` form): `∂_τ V_q = -q · V_q + e^{-qτ} · (call_theta_at_drift_{r-q})`. + +Product rule on `V_q = e^{-qτ} · bsV(K, r-q, σ, S, τ)`. -/ +lemma hasDerivAt_bsVDiv_tau {K r q σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (fun t ↦ bsVDiv K r q σ S t) + (-(q * bsVDiv K r q σ S τ) + + Real.exp (-(q * τ)) * + (σ * S * gaussianPDFReal 0 1 (bsd1 S K (r - q) σ τ) / (2 * Real.sqrt τ) + + (r - q) * K * Real.exp (-((r - q) * τ)) * Phi (bsd2 S K (r - q) σ τ))) τ := by + -- f(t) = e^{-qt}, derivative -q · e^{-qt} + have h_f : HasDerivAt (fun t : ℝ ↦ Real.exp (-(q * t))) (-q * Real.exp (-(q * τ))) τ := by + have h_neg : HasDerivAt (fun t : ℝ ↦ -(q * t)) (-q) τ := by + have := (hasDerivAt_id τ).const_mul q + convert this.neg using 1 <;> first | rfl | ring + have h := h_neg.exp + convert h using 1 + ring + -- g(t) = bsV K (r-q) σ S t, derivative from hasDerivAt_bsV_tau + have h_g := hasDerivAt_bsV_tau (r := r - q) hK hσ hS hτ + -- Product + have h_full := h_f.mul h_g + unfold bsVDiv + convert h_full using 1 + ring + +/-- **Black–Scholes–Merton PDE with dividend yield** (Hull eq. 19.4 with `q`): writing +`Θ = −∂_τ V_q` (calendar theta, `hasDerivAt_bsVDiv_tau`), `Δ = e^{-qτ} Φ(d₁')` +(`hasDerivAt_bsVDiv_S`) and `Γ = e^{-qτ} ϕ(d₁')/(S σ √τ)` (`hasDerivAt_deriv_bsVDiv_S`), the +three formulas satisfy `Θ + (r − q) S Δ + ½ σ² S² Γ = r V_q` for `σ, S, τ > 0`. Stated on the +formulas, as `bs_pde_holds` is. -/ +theorem bsVDiv_pde {K r q σ : ℝ} (hσ : 0 < σ) {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + -(-(q * bsVDiv K r q σ S τ) + + Real.exp (-(q * τ)) * + (σ * S * gaussianPDFReal 0 1 (bsd1 S K (r - q) σ τ) / (2 * Real.sqrt τ) + + (r - q) * K * Real.exp (-((r - q) * τ)) * Phi (bsd2 S K (r - q) σ τ))) + + (r - q) * S * (Real.exp (-(q * τ)) * Phi (bsd1 S K (r - q) σ τ)) + + (1 / 2 : ℝ) * σ ^ 2 * S ^ 2 * + (Real.exp (-(q * τ)) * gaussianPDFReal 0 1 (bsd1 S K (r - q) σ τ) + / (S * σ * Real.sqrt τ)) = + r * bsVDiv K r q σ S τ := by + have h_sqrt_ne : Real.sqrt τ ≠ 0 := (Real.sqrt_pos.mpr hτ).ne' + have hS_ne : S ≠ 0 := hS.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + rw [bsVDiv, bsV] + field_simp + ring + +/-- **BS-Merton psi sign**: the psi formula `∂_q V_q = −S τ e^{-qτ} Φ(d₁')` of +`hasDerivAt_bsVDiv_q` is `≤ 0` for `S ≥ 0` and `τ ≥ 0`. -/ +theorem bsVDiv_psi_nonpos {S τ : ℝ} (hS : 0 ≤ S) (hτ : 0 ≤ τ) (K r q σ : ℝ) : + -(S * τ * Real.exp (-(q * τ)) * Phi (bsd1 S K (r - q) σ τ)) ≤ 0 := by + have := Phi_nonneg (bsd1 S K (r - q) σ τ) + exact neg_nonpos.mpr (by positivity) + +/-- **The call is worth no more under a higher dividend yield**: for `K, σ, τ, S > 0`, +`q ↦ V_q` is antitone (non-increasing; strictness is not stated), by the mean value theorem +from `hasDerivAt_bsVDiv_q` and the sign `bsVDiv_psi_nonpos`. -/ +theorem antitone_bsVDiv_q {K r σ τ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) + {S : ℝ} (hS : 0 < S) : + Antitone fun q ↦ bsVDiv K r q σ S τ := + antitone_of_hasDerivAt_nonpos (fun q ↦ hasDerivAt_bsVDiv_q hK hσ hτ hS q) + fun q ↦ bsVDiv_psi_nonpos hS.le hτ.le K r q σ + +/-- Dividends-adjusted BS put closed form, defined as `P_q = e^{-qτ} · bsP(K, r-q, σ, S, τ)`, +which unfolds to `K e^{-rτ} Φ(−d₂') − S e^{-qτ} Φ(−d₁')`. That it is a discounted expected +payoff is not stated here. -/ +noncomputable def bsPDiv (K r q σ : ℝ) (S τ : ℝ) : ℝ := + Real.exp (-(q * τ)) * bsP K (r - q) σ S τ + +/-- **Put-call parity with a continuous dividend yield**: +`P_q = V_q − S e^{-qτ} + K e^{-rτ}`. -/ +theorem bsPDiv_eq_bsVDiv (K r q σ S τ : ℝ) : + bsPDiv K r q σ S τ = bsVDiv K r q σ S τ - S * Real.exp (-(q * τ)) + + K * Real.exp (-(r * τ)) := by + have h : Real.exp (-(q * τ)) * Real.exp (-((r - q) * τ)) = Real.exp (-(r * τ)) := by + rw [← Real.exp_add]; congr 1; ring + rw [bsPDiv, bsVDiv, bsP_eq_bsV] + linear_combination K * h + +/-- **Put psi**: `∂_q P_q = S τ e^{-qτ} Φ(−d₁')`, via parity and `hasDerivAt_bsVDiv_q`. -/ +lemma hasDerivAt_bsPDiv_q {K r σ τ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) + {S : ℝ} (hS : 0 < S) (q : ℝ) : + HasDerivAt (fun q' ↦ bsPDiv K r q' σ S τ) + (S * τ * Real.exp (-(q * τ)) * Phi (-bsd1 S K (r - q) σ τ)) q := by + have h_eq : (fun q' : ℝ ↦ bsPDiv K r q' σ S τ) = fun q' ↦ + bsVDiv K r q' σ S τ - S * Real.exp (-(q' * τ)) + K * Real.exp (-(r * τ)) := + funext fun q' ↦ bsPDiv_eq_bsVDiv K r q' σ S τ + rw [h_eq] + have h_neg : HasDerivAt (fun q' : ℝ ↦ -(q' * τ)) (-τ) q := (hasDerivAt_mul_const τ).neg + have h := ((hasDerivAt_bsVDiv_q (r := r) hK hσ hτ hS q).sub (h_neg.exp.const_mul S)).add_const + (K * Real.exp (-(r * τ))) + convert h using 1 + linear_combination S * τ * Real.exp (-(q * τ)) * Phi_add_Phi_neg (bsd1 S K (r - q) σ τ) + +/-- **Put psi sign**: the put psi formula `∂_q P_q = S τ e^{-qτ} Φ(−d₁')` of +`hasDerivAt_bsPDiv_q` is `≥ 0` for `S ≥ 0` and `τ ≥ 0`. -/ +theorem bsPDiv_psi_nonneg {S τ : ℝ} (hS : 0 ≤ S) (hτ : 0 ≤ τ) (K r q σ : ℝ) : + 0 ≤ S * τ * Real.exp (-(q * τ)) * Phi (-bsd1 S K (r - q) σ τ) := by + have := Phi_nonneg (-bsd1 S K (r - q) σ τ) + positivity + +/-- **The put is worth no less under a higher dividend yield**: for `K, σ, τ, S > 0`, +`q ↦ P_q` is monotone (non-decreasing; strictness is not stated), by the mean value theorem +from `hasDerivAt_bsPDiv_q` and the sign `bsPDiv_psi_nonneg`. -/ +theorem monotone_bsPDiv_q {K r σ τ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) + {S : ℝ} (hS : 0 < S) : + Monotone fun q ↦ bsPDiv K r q σ S τ := + monotone_of_hasDerivAt_nonneg (fun q ↦ hasDerivAt_bsPDiv_q hK hσ hτ hS q) + fun q ↦ bsPDiv_psi_nonneg hS.le hτ.le K r q σ + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/ExchangeOption.lean b/LeanPool/MathFin/Models/BlackScholes/ExchangeOption.lean new file mode 100644 index 0000000000..85e3f29527 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/ExchangeOption.lean @@ -0,0 +1,268 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.GarmanNormalForm +public import LeanPool.MathFin.Pricing.Numeraire + +/-! +# Margrabe's exchange option: a two-asset option that is a one-asset BS problem + +The **exchange option** pays `max(S¹_T − S²_T, 0)` — the right to exchange +asset 2 for asset 1 at maturity. Its defining structural fact (Margrabe 1978) +is that it depends only on the *ratio* `S¹/S²`, which is itself lognormal +with an **effective volatility** + + `σ² = σ₁² + σ₂² − 2 ρ σ₁ σ₂`, + +so the two-asset problem collapses to a one-asset Black-Scholes problem at +that effective vol. This is the first genuinely multivariate result in the +library, and it reuses (rather than re-derives) the 1-D machinery — the same +"structural reduction" discipline as `PowerCall`. + +This file establishes the two pieces of the reduction: + +* `margrabe_variance_sub` / `margrabe_effective_variance` — the effective + variance of the log-spread, from covariance bilinearity. This is the first + consumer of the covariance machinery that `Probability/Gaussian/BivariateGaussian` + also uses, making that machinery load-bearing. +* `exchange_payoff_eq_ratio` — the payoff reduction `max(S¹ − S², 0) = S² · + max(S¹/S² − 1, 0)`, exhibiting the exchange option as a (numeraire-scaled) + vanilla call on the ratio. + +The price-level formula (`margrabe_price_via_call`) prices the exchange option +in the `S²`-numeraire as a vanilla `bs_call_formula` call on the ratio +`R = S¹/S²`. Its pricing primitive is `BSCallHyp` for the ratio — the same +abstraction `bs_call_formula` takes for any underlying. +`MathFin/Models/BlackScholes/MargrabeGrounding.lean` (`margrabe_bsCallHyp_of_gaussian`) constructs +that primitive from a joint two-GBM Gaussian model: under an Esscher tilt `Q` of the model +measure, a standard-normal driver drives the actual ratio `S¹_T/S²_T` (that `Q` is the +`S²`-numéraire measure is not proved). The same file proves the price-level statement directly +under the model measure: `margrabe_exchange_price` shows that `margrabePrice` is the +discounted expected exchange payoff. + +## Main definitions + +* `margrabeD1`, `margrabeD2`: `d₁ = (log(S¹₀/S²₀) + σ²T/2) / (σ√T)` and `d₂ = d₁ − σ√T`, with + `σ` the effective volatility of the log-spread. +* `margrabePrice`: the exchange-option price `S¹₀ · Φ(d₁) − S²₀ · Φ(d₂)`. + +## Main results + +* `margrabe_variance_sub`: `Var[L₁ − L₂] = Var L₁ + Var L₂ − 2·cov(L₁, L₂)`. +* `margrabe_effective_variance`: substituting `σ₁²T, σ₂²T, ρσ₁σ₂T` gives the + effective variance `(σ₁² + σ₂² − 2ρσ₁σ₂)·T`. +* `exchange_payoff_eq_ratio`: `max(a − b, 0) = b · max(a/b − 1, 0)` for `b > 0`. +* `margrabe_eq_bsVGarman`: Margrabe price is a `GarmanNormalForm` instance. +* `margrabe_parity`: `Margrabe(S¹,S²) − Margrabe(S²,S¹) = S¹ − S²`. +* `margrabe_price_via_call`: the exchange option is a `bs_call_formula` call + on the ratio (price-level reduction). + +## References + +* [H. Geman, N. El Karoui and J. C. Rochet, *Changes of numéraire, changes of probability measure + and option pricing*][GemanElKarouiRochet1995] +* [W. Margrabe, *The value of an option to exchange one asset for another*][Margrabe1978] + +## Tags + +Margrabe, exchange option, change of numeraire, effective volatility, two-asset option, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory + +/-- **Variance of a spread** via covariance bilinearity: for two L² +random variables, `Var[L₁ − L₂] = Var L₁ + Var L₂ − 2·cov(L₁, L₂)`. The +cross term carries the correlation — this is where the `−2ρσ₁σ₂` of the +Margrabe effective volatility comes from. -/ +theorem margrabe_variance_sub {Ω : Type*} {mΩ : MeasurableSpace Ω} + {P : Measure Ω} [IsProbabilityMeasure P] + {L₁ L₂ : Ω → ℝ} (h₁ : MemLp L₁ 2 P) (h₂ : MemLp L₂ 2 P) : + Var[L₁ - L₂; P] = Var[L₁; P] + Var[L₂; P] - 2 * cov[L₁, L₂; P] := by + rw [← covariance_self (h₁.sub h₂).aemeasurable, + covariance_sub_left h₁ h₂ (h₁.sub h₂), + covariance_sub_right h₁ h₁ h₂, covariance_sub_right h₂ h₁ h₂, + covariance_self h₁.aemeasurable, covariance_self h₂.aemeasurable, + covariance_comm L₂ L₁] + ring + +/-- **Margrabe effective variance**: with `Var L₁ = σ₁²T`, `Var L₂ = σ₂²T`, +and `cov(L₁, L₂) = ρσ₁σ₂T`, the log-spread variance is +`(σ₁² + σ₂² − 2ρσ₁σ₂)·T` — the effective variance at which the exchange +option prices as a one-asset Black-Scholes call. -/ +theorem margrabe_effective_variance {Ω : Type*} {mΩ : MeasurableSpace Ω} + {P : Measure Ω} [IsProbabilityMeasure P] + {L₁ L₂ : Ω → ℝ} {σ₁ σ₂ ρ T : ℝ} + (h₁ : MemLp L₁ 2 P) (h₂ : MemLp L₂ 2 P) + (hV₁ : Var[L₁; P] = σ₁ ^ 2 * T) (hV₂ : Var[L₂; P] = σ₂ ^ 2 * T) + (hcov : cov[L₁, L₂; P] = ρ * σ₁ * σ₂ * T) : + Var[L₁ - L₂; P] = (σ₁ ^ 2 + σ₂ ^ 2 - 2 * ρ * σ₁ * σ₂) * T := by + rw [margrabe_variance_sub h₁ h₂, hV₁, hV₂, hcov] + ring + +/-- **Exchange-option payoff reduction**: `max(a − b, 0) = b · max(a/b − 1, 0)` +for `b > 0`. The exchange payoff `max(S¹_T − S²_T, 0)` is `S²_T` times a +vanilla call payoff on the ratio `S¹_T/S²_T` struck at `1` — the algebraic +form of "use `S²` as numeraire." -/ +theorem exchange_payoff_eq_ratio (a b : ℝ) (hb : 0 < b) : + max (a - b) 0 = b * max (a / b - 1) 0 := by + rw [mul_max_of_nonneg _ _ hb.le, mul_zero, + show b * (a / b - 1) = a - b from by field_simp] + +/-! ## Margrabe price is a Garman-normal-form instance + +The exchange-option closed form is the *one* BS-family formula +`V = A·Φ(d₁) − K·DF·Φ(d₂)` at `A = S¹₀`, `K = S²₀`, `DF = 1` (the +S²-numeraire / forward measure carries no discounting), and effective vol +`σ = √(σ₁² + σ₂² − 2ρσ₁σ₂)`. So Margrabe joins Black-Scholes, Black-76, +BS-Merton, Garman-Kohlhagen, and KMV-Merton as instances of `bsVGarman`. -/ + +/-- **Margrabe `d₁`**: `(log(S¹₀/S²₀) + σ²T/2) / (σ√T)`, with `σ` the +effective volatility of the log-spread. -/ +noncomputable def margrabeD1 (S1 S2 σ T : ℝ) : ℝ := + (Real.log (S1 / S2) + σ ^ 2 * T / 2) / (σ * Real.sqrt T) + +/-- **Margrabe `d₂`**: `d₁ − σ√T`. -/ +noncomputable def margrabeD2 (S1 S2 σ T : ℝ) : ℝ := + margrabeD1 S1 S2 σ T - σ * Real.sqrt T + +/-- **Margrabe exchange-option price**: `S¹₀·Φ(d₁) − S²₀·Φ(d₂)`. -/ +noncomputable def margrabePrice (S1 S2 σ T : ℝ) : ℝ := + S1 * Phi (margrabeD1 S1 S2 σ T) - S2 * Phi (margrabeD2 S1 S2 σ T) + +/-- **Margrabe is a Garman-normal-form instance**: the exchange-option price +equals `bsVGarman` at `A = S¹₀`, `K = S²₀`, `DF = 1`, effective vol `σ`. The +second asset plays the role of the discounted strike and `DF = 1` because the +S²-numeraire measure carries no discounting. So a *multivariate* option is the +same closed form `V = A·Φ(d₁) − K·DF·Φ(d₂)` as every BS-family price — one +more consumer of the `GarmanNormalForm` principle. -/ +theorem margrabe_eq_bsVGarman (S1 S2 σ T : ℝ) : + margrabePrice S1 S2 σ T = bsVGarman S1 S2 1 σ T := by + have hd1 : margrabeD1 S1 S2 σ T = gbsd1 S1 S2 1 σ T := by + unfold margrabeD1 gbsd1; rw [mul_one] + unfold margrabePrice bsVGarman margrabeD2 gbsd2 + rw [hd1, mul_one] + +/-- **Exchange-option parity** — the analog of put-call parity. The option to +exchange asset 2 for asset 1 minus the option to exchange asset 1 for asset 2 +equals the forward on the spread: + + `Margrabe(S¹, S²) − Margrabe(S², S¹) = S¹ − S²`. + +Foundation-certain: swapping the two assets sends `d₁ ↦ −d₂` and `d₂ ↦ −d₁` +(the `σ²T/(σ√T) = σ√T` identity), and `Φ(x) + Φ(−x) = 1` (the same symmetry +`Phi_add_Phi_neg` that drives put-call parity) collapses the rest. No +probability machinery, no assumed moments — pure algebra on the closed form. -/ +theorem margrabe_parity (S1 S2 σ T : ℝ) + (hS1 : 0 < S1) (hS2 : 0 < S2) (hσ : σ ≠ 0) (hT : 0 < T) : + margrabePrice S1 S2 σ T - margrabePrice S2 S1 σ T = S1 - S2 := by + have hσT : σ * Real.sqrt T ≠ 0 := mul_ne_zero hσ (Real.sqrt_pos.mpr hT).ne' + -- The swapped d₁ and the original d₁ sum to σ√T. + have hsum : margrabeD1 S2 S1 σ T + margrabeD1 S1 S2 σ T = σ * Real.sqrt T := by + unfold margrabeD1 + rw [← add_div, Real.log_div hS2.ne' hS1.ne', Real.log_div hS1.ne' hS2.ne', + show (Real.log S2 - Real.log S1 + σ ^ 2 * T / 2) + + (Real.log S1 - Real.log S2 + σ ^ 2 * T / 2) = σ ^ 2 * T from by ring, + div_eq_iff hσT, + show σ * Real.sqrt T * (σ * Real.sqrt T) + = σ ^ 2 * (Real.sqrt T * Real.sqrt T) from by ring, + Real.mul_self_sqrt hT.le] + -- Swap symmetry of the d's. + have hd1 : margrabeD1 S2 S1 σ T = -(margrabeD2 S1 S2 σ T) := by + unfold margrabeD2; linarith [hsum] + have hd2 : margrabeD2 S2 S1 σ T = -(margrabeD1 S1 S2 σ T) := by + unfold margrabeD2; linarith [hsum] + unfold margrabePrice + rw [hd1, hd2, Phi_neg, Phi_neg] + ring + +/-! ## Price-level Margrabe: the exchange option is a call on the ratio + +This closes the price-level reduction. The exchange option, valued in the +`S²`-numeraire, is a vanilla Black-Scholes call on the ratio `R = S¹/S²` +struck at `1` with zero rate and effective vol `σ`. The pricing primitive is +`BSCallHyp` for the *ratio* — exactly the abstraction `bs_call_formula` takes +for any underlying; here the underlying is `R`. Its construction from a joint two-GBM +model, under an Esscher tilt not shown to be the `S²`-numeraire measure, is +`MargrabeGrounding.lean`. -/ + +/-- **Bridge**: standard BS `d₁` of the ratio `R₀ = S¹₀/S²₀` (strike `1`, +zero rate) is the Margrabe `d₁`. -/ +private lemma bsd1_ratio_eq_margrabeD1 (S1 S2 σ T : ℝ) : + bsd1 (S1 / S2) 1 0 σ T = margrabeD1 S1 S2 σ T := by + unfold bsd1 margrabeD1 + rw [div_one]; congr 1; ring + +/-- **Bridge** for `d₂`. -/ +private lemma bsd2_ratio_eq_margrabeD2 (S1 S2 σ T : ℝ) : + bsd2 (S1 / S2) 1 0 σ T = margrabeD2 S1 S2 σ T := by + unfold bsd2 margrabeD2 + rw [bsd1_ratio_eq_margrabeD1] + +/-- **Price-level Margrabe formula** (exchange option as a call on the ratio). +Given that the ratio `R = S¹/S²` is risk-neutral lognormal under the +`S²`-numeraire measure `Q` (`BSCallHyp Q (S¹₀/S²₀) 1 0 σ Z` — strike `1`, zero +rate, effective vol `σ`), the `S²`-numeraire value of the exchange payoff +`S²₀ · E_Q[max(R_T − 1, 0)]` equals the Margrabe price `margrabePrice`. This +is a one-line composition of `bs_call_formula` with the algebra `S²₀·R₀ = S¹₀` +and the `d`-bridges above — no new probability machinery. -/ +theorem margrabe_price_via_call + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S1 S2 σ T : ℝ} {Z : Ω → ℝ} (hS2 : 0 < S2) + (h : BSCallHyp Q (S1 / S2) 1 0 σ T Z) : + S2 * ∫ ω, max (bsTerminal (S1 / S2) 0 σ T (Z ω) - 1) 0 ∂Q + = margrabePrice S1 S2 σ T := by + have hbs := bs_call_formula h + simp only [neg_zero, zero_mul, Real.exp_zero, one_mul, mul_one] at hbs + rw [hbs, bsd1_ratio_eq_margrabeD1, bsd2_ratio_eq_margrabeD2] + unfold margrabePrice + field_simp + +/-! ## The S²-numéraire valuation is a change-of-numéraire instance + +`exchange_payoff_eq_ratio` says the exchange payoff is `S²_T` times a call on the +ratio; the general change of numéraire (`Foundations.Numeraire.changeOfNumeraire`) +turns that algebraic fact into a genuine measure statement — the option's value in the +`S²`-numéraire equals its value under the reference measure. This makes the informal +"value in the `S²`-numéraire" of `margrabe_price_via_call` an *instance* of the general +law, rather than a bespoke reduction. -/ + +/-- **Exchange option in the S²-numéraire — a change-of-numéraire instance.** With the +second asset `S²` as numéraire (`numeraireMeasure Q 1 S²_T 1 S²₀`, density +`dQ^(S²)/dQ = S²_T/S²₀`), the option's `S²`-numéraire value is its value under the +reference measure `Q`: + + `S²₀ · 𝔼^{Q^(S²)}[max(S¹_T/S²_T − 1, 0)] = 𝔼^Q[max(S¹_T − S²_T, 0)]`. + +This is `changeOfNumeraire` at `X = ` the exchange payoff, `N = S²`, `B ≡ 1`, composed +with `exchange_payoff_eq_ratio` (`max(S¹−S²,0) = S²·max(S¹/S²−1,0)`). No integrability +hypothesis is needed — only strict positivity of the numéraire `S²_T > 0`. -/ +theorem exchangeOption_numeraire_price + {Ω : Type*} {mΩ : MeasurableSpace Ω} + (Q : Measure Ω) (S1T S2T : Ω → ℝ) (S2_0 : ℝ) + (hS2meas : Measurable S2T) (hS2pos : ∀ ω, 0 < S2T ω) (hS20 : 0 < S2_0) : + S2_0 * ∫ ω, max (S1T ω / S2T ω - 1) 0 + ∂(numeraireMeasure Q (fun _ ↦ 1) S2T 1 S2_0) + = ∫ ω, max (S1T ω - S2T ω) 0 ∂Q := by + have hL : ∀ ω, max (S1T ω / S2T ω - 1) 0 = max (S1T ω - S2T ω) 0 / S2T ω := fun ω ↦ by + rw [exchange_payoff_eq_ratio (S1T ω) (S2T ω) (hS2pos ω), + mul_div_cancel_left₀ _ (hS2pos ω).ne'] + have hkey := changeOfNumeraire (Q := Q) (X := fun ω ↦ max (S1T ω - S2T ω) 0) + (BT := fun _ ↦ (1 : ℝ)) (NT := S2T) (B0 := (1 : ℝ)) (N0 := S2_0) + hS2meas measurable_const hS2pos (fun _ ↦ one_pos) zero_le_one hS20 + simp_rw [div_one, one_mul] at hkey + simp_rw [hL] + exact hkey + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/Forward.lean b/LeanPool/MathFin/Models/BlackScholes/Forward.lean new file mode 100644 index 0000000000..f6b5cb9146 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/Forward.lean @@ -0,0 +1,176 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Call +public import LeanPool.MathFin.Probability.Gaussian.StandardGaussianMGF + +/-! +# Forward and futures pricing under the BS lognormal hypothesis + +Under `BSCallHyp` (risk-neutral lognormal model), the risk-neutral +expectation of the terminal asset price equals the no-arbitrage forward +price: + + E_Q[S_T] = S_0 · e^{rT}. + +This is the classical no-arbitrage relation `F = S_0 · e^{rT}` derived as +a direct consequence of the Gaussian MGF identity. The discounted asset +price is automatically a Q-martingale (at maturity): + + E_Q[e^{-rT} · S_T] = S_0. + +No Itô calculus is required — pure Gaussian integration. + +## Interpretation as a no-arbitrage price + +A long forward contract pays `S_T − F` at maturity. The **forward price** +`F` is conventionally defined as the unique value making the contract +worth zero at inception. Under any risk-neutral measure `Q`, the zero-value +condition is + + 0 = E_Q[e^{-rT}(S_T − F)] = e^{-rT}(E_Q[S_T] − F), + +so `F = E_Q[S_T]`. Combined with `expected_terminal_eq_forward`, this gives +`F = S_0 · e^{rT}`. + +## Main results + +* `nthMoment_terminal`: under `BSCallHyp`, `E_Q[S_T^n] = S_0^n · exp(n r T + n(n − 1)/2 · σ²T)`. +* `expected_terminal_eq_forward`: under `BSCallHyp`, `E_Q[S_T] = S_0 · e^{rT}`. +* `discounted_terminal_eq_S0`: under `BSCallHyp`, `E_Q[e^{−rT} · S_T] = S_0`. +* `integral_bsTerminal_pow_gaussianReal`, `integral_bsTerminal_eq_forward`: the same moment and + forward identities as integrals against `gaussianReal 0 1`, for `0 ≤ T`. +* `integral_discounted_bsTerminal`: for `Z` with law `gaussianReal 0 1` under `Q` and `0 ≤ T`, + `∫ e^{−rT} · S_T(Z) ∂Q = S_0`. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 5.6 + +## Tags + +forward price, futures price, no-arbitrage forward, risk-neutral expectation, cost of carry, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal + +/-! ### Risk-neutral expectation of terminal asset price -/ + +/-- **`n`-th moment of the terminal price against the standard normal**: +`∫ (bsTerminal z)^n dN(0,1) = S_0^n · exp(n·r·T + n(n−1)/2 · σ²T)` for `0 ≤ T`. + +Direct instance of the affine-shifted standard-normal MGF: with `α = n(r − σ²/2)T` and +`β = nσ√T`, the integrand equals `S_0^n · exp(α + β·z)`, so the integral is +`S_0^n · exp(α + β²/2)`. -/ +theorem integral_bsTerminal_pow_gaussianReal (S_0 r σ T : ℝ) (n : ℕ) (hT : 0 ≤ T) : + ∫ z, (bsTerminal S_0 r σ T z)^n ∂(gaussianReal 0 1) = + S_0^n * + Real.exp ((n : ℝ) * r * T + (n : ℝ) * ((n : ℝ) - 1) / 2 * σ^2 * T) := by + set α : ℝ := (n : ℝ) * (r - σ^2 / 2) * T with α_def + set β : ℝ := (n : ℝ) * σ * Real.sqrt T with β_def + have h_β_sq : β^2 = (n : ℝ)^2 * σ^2 * T := by + rw [β_def]; ring_nf; rw [Real.sq_sqrt hT] + have h_algebra : + α + β^2 / 2 = + (n : ℝ) * r * T + (n : ℝ) * ((n : ℝ) - 1) / 2 * σ^2 * T := by + rw [h_β_sq]; ring + have h_pow : ∀ z : ℝ, + (bsTerminal S_0 r σ T z)^n = S_0^n * Real.exp (α + β * z) := by + intro z + unfold bsTerminal + rw [mul_pow, ← Real.exp_nat_mul] + congr 2 + rw [α_def, β_def]; ring + rw [integral_gaussianReal_eq_integral_smul (one_ne_zero : (1 : ℝ≥0) ≠ 0)] + simp_rw [smul_eq_mul, h_pow] + rw [show + (fun z : ℝ ↦ gaussianPDFReal 0 1 z * (S_0^n * Real.exp (α + β * z))) + = + (fun z ↦ S_0^n * (Real.exp (α + β * z) * gaussianPDFReal 0 1 z)) + from funext (fun z ↦ by ring)] + rw [integral_const_mul, integral_exp_affine_gaussianPDFReal_univ, h_algebra] + +/-- **`n`-th moment of the terminal asset price** under `BSCallHyp`: +`E_Q[S_T^n] = S_0^n · exp(n · r · T + n(n−1)/2 · σ²T)`, the HasLaw transfer of +`integral_bsTerminal_pow_gaussianReal`. -/ +theorem nthMoment_terminal + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} (n : ℕ) + (h : BSCallHyp Q S_0 K r σ T Z) : + ∫ ω, (bsTerminal S_0 r σ T (Z ω))^n ∂Q = + S_0^n * + Real.exp ((n : ℝ) * r * T + (n : ℝ) * ((n : ℝ) - 1) / 2 * σ^2 * T) := by + obtain ⟨_hS_0, _hK, _hσ, hT, hZ⟩ := h + have h_meas : Measurable fun z : ℝ ↦ (bsTerminal S_0 r σ T z)^n := by + unfold bsTerminal; fun_prop + rw [show (fun ω ↦ (bsTerminal S_0 r σ T (Z ω))^n) = + (fun z ↦ (bsTerminal S_0 r σ T z)^n) ∘ Z from rfl, + hZ.integral_comp h_meas.aestronglyMeasurable] + exact integral_bsTerminal_pow_gaussianReal S_0 r σ T n hT.le + +/-- **Terminal price is the forward in expectation** — the standard-normal-driver +form: `E[S_T] = F = S_0·e^{rT}`, the `n = 1` moment. -/ +lemma integral_bsTerminal_eq_forward (S_0 r σ T : ℝ) (hT : 0 ≤ T) : + ∫ z, S_0 * Real.exp ((r - σ ^ 2 / 2) * T + σ * Real.sqrt T * z) ∂(gaussianReal 0 1) + = S_0 * Real.exp (r * T) := by + simpa [bsTerminal] using integral_bsTerminal_pow_gaussianReal S_0 r σ T 1 hT + +/-- **No-arbitrage forward price**: under `BSCallHyp`, + `E_Q[S_T] = S_0 · e^{rT}`. + +This is the risk-neutral expectation of the terminal asset price, which is +the no-arbitrage forward price `F` for delivery at time `T`: the `n = 1` case of +`nthMoment_terminal`. -/ +theorem expected_terminal_eq_forward + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + ∫ ω, bsTerminal S_0 r σ T (Z ω) ∂Q = S_0 * Real.exp (r * T) := by + simpa using nthMoment_terminal 1 h + +/-! ### Discounted asset is a Q-martingale at maturity -/ + +/-- The discounted Black–Scholes terminal price driven by a standard normal has mean `S₀`: the +forward `𝔼[S_T] = S₀e^{rT}` (`integral_bsTerminal_eq_forward`), discounted. -/ +theorem integral_discounted_bsTerminal {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} + {Z : Ω → ℝ} (hZ : HasLaw Z (gaussianReal 0 1) Q) (S_0 r σ : ℝ) {T : ℝ} (hT : 0 ≤ T) : + ∫ ω, rexp (-r * T) * bsTerminal S_0 r σ T (Z ω) ∂Q = S_0 := by + have hmeas : Measurable (bsTerminal S_0 r σ T) := by + unfold bsTerminal + fun_prop + have hfwd : ∫ ω, bsTerminal S_0 r σ T (Z ω) ∂Q = S_0 * rexp (r * T) := + (hZ.integral_comp hmeas.aestronglyMeasurable).trans + (integral_bsTerminal_eq_forward S_0 r σ T hT) + rw [integral_const_mul, hfwd] + calc rexp (-r * T) * (S_0 * rexp (r * T)) = S_0 * rexp (-r * T + r * T) := by + rw [Real.exp_add] + ring + _ = S_0 := by rw [show -r * T + r * T = 0 by ring, Real.exp_zero, mul_one] + +/-- **Discounted terminal price equals spot**: under `BSCallHyp`, + `E_Q[e^{-rT} S_T] = S_0`. This is the integrated form of the + risk-neutral martingale property at maturity. -/ +theorem discounted_terminal_eq_S0 + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + ∫ ω, Real.exp (-(r * T)) * bsTerminal S_0 r σ T (Z ω) ∂Q = S_0 := by + obtain ⟨_, _, _, hT, hZ⟩ := h + simpa only [neg_mul] using integral_discounted_bsTerminal hZ S_0 r σ hT.le + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/GarmanNormalForm.lean b/LeanPool/MathFin/Models/BlackScholes/GarmanNormalForm.lean new file mode 100644 index 0000000000..dcf8c10501 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/GarmanNormalForm.lean @@ -0,0 +1,225 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.PDE + +/-! +# The Garman normal form: every BS-family closed form is one formula + +Every European-call closed form in the library has the shape + + `V = A · Φ(d_1) − K · DF · Φ(d_2)`, + `d_1 = log(A / (K · DF)) / (σ · √T) + σ · √T / 2`, + `d_2 = d_1 − σ · √T`, + +where `A` is the **present value of receiving one unit of the asset at +maturity** under the chosen numéraire and `DF` is the **discount factor for +cash received at maturity**. + +Specialisations: + +| Variant | `A` | `DF` | What changes | +|---|---|---|---| +| Standard BS (`bsV` in `PDE.lean`) | `S` | `e^{−rτ}` | (baseline) | +| Black-76 (`black_futures_formula`) | `F · e^{−rT}` | `e^{−rT}` | underlying is the *forward* | +| BS-Merton dividends | `S · e^{−qT}` | `e^{−rT}` | continuous dividend yield `q` | +| Garman-Kohlhagen FX | `S · e^{−r_f T}` | `e^{−r_d T}` | foreign-rate-discounted asset | +| KMV-Merton credit | `V` (firm) | `e^{−rT}` | strike = face debt; `d_2` = distance to default | +| Swaption (Black model) | `A_annuity · F` | `A_annuity` | annuity numéraire | +| Quanto-adjusted | drift-shifted | `e^{−r_dom T}` | correlation adjustment in drift | +| Margrabe exchange (`margrabe_eq_bsVGarman`) | `S¹₀` | `1` | 2nd asset is the strike (see below) | + +In the Margrabe row `σ` is the effective volatility `√(σ₁²+σ₂²−2ρσ₁σ₂)`, and there is no +discounting: the second asset is the numéraire. + +This is the **change-of-numéraire** principle in elementary form: BS pricing +is a single computation, parameterised by what the underlying and the +discount factor mean. + +## Why this is structural, not cosmetic + +This file is **load-bearing**: we prove the BS closed form `bsV` and the +Black-76 / BS-Merton closed-form right-hand sides are *equal* (as real +numbers) to `bsVGarman` at the appropriate `(A, DF)`. Each existing +specialisation file becomes a one-line corollary instead of a separate +chain-rule + integral derivation. + +This is what was missing in the previously-shipped `KMVMerton.lean`, +`Quanto.lean`, `Swaption.lean`: those files redefined the same formula in +new variable names. The honest content is "the formula is parameterised +by `(A, DF)`", which is exactly what this file says. + +## Main definitions + +* `gbsd1`, `gbsd2`: `d₁ = (log(A/(K·DF)) + σ²T/2) / (σ√T)` and `d₂ = d₁ − σ√T`. +* `bsVGarman`: the Garman-normalised call price `A · Φ(d₁) − K · DF · Φ(d₂)`, where `A` is the + present value of one unit of the asset at maturity and `DF` the discount factor for cash at + maturity. + +## Main results + +* `bsd1_eq_gbsd1_standard`, `bsd2_eq_gbsd2_standard`: standard BS d_1/d_2 + match the Garman form at `DF = e^{−rτ}`. +* `bsV_eq_bsVGarman_standard`: **`bsV` is `bsVGarman`** at the standard BS + parameters. This is the load-bearing instance. +* `black76_RHS_eq_bsVGarman`: the closed-form RHS of `black_futures_formula` + equals `bsVGarman` at `A = F · e^{−rT}`, `DF = e^{−rT}`. +* `bs_dividends_RHS_eq_bsVGarman`: the closed-form RHS of + `bs_dividends_call_formula` equals `bsVGarman` at `A = S · e^{−qT}`, + `DF = e^{−rT}`. + +## Tags + +Garman normal form, generalized Black–Scholes, cost of carry, unified closed form, discount factor, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-! ### Garman-normalised definitions -/ + +/-- **Garman-normalised `d_1`**: `d_1 = (log(A/(K·DF)) + σ²T/2) / (σ √T)`. -/ +noncomputable def gbsd1 (A K DF σ T : ℝ) : ℝ := + (Real.log (A / (K * DF)) + σ^2 * T / 2) / (σ * Real.sqrt T) + +/-- **Garman-normalised `d_2`**: `d_2 = d_1 − σ √T`. -/ +noncomputable def gbsd2 (A K DF σ T : ℝ) : ℝ := + gbsd1 A K DF σ T - σ * Real.sqrt T + +/-- **Garman-normalised BS call price**: `V = A · Φ(d_1) − K · DF · Φ(d_2)`. -/ +noncomputable def bsVGarman (A K DF σ T : ℝ) : ℝ := + A * Phi (gbsd1 A K DF σ T) - K * DF * Phi (gbsd2 A K DF σ T) + +/-! ### Standard BS is a Garman instance -/ + +/-- **Log-algebra bridge**: `log(S / (K · e^{−rτ})) = log(S/K) + rτ`. -/ +lemma log_div_mul_exp_neg (S K r τ : ℝ) (hS : 0 < S) (hK : 0 < K) : + Real.log (S / (K * Real.exp (-(r * τ)))) = Real.log (S / K) + r * τ := by + have hexp_ne : Real.exp (-(r * τ)) ≠ 0 := (Real.exp_pos _).ne' + rw [Real.log_div hS.ne' (mul_ne_zero hK.ne' hexp_ne)] + rw [Real.log_mul hK.ne' hexp_ne] + rw [Real.log_exp] + rw [Real.log_div hS.ne' hK.ne'] + ring + +/-- **Standard BS `bsd1` matches the Garman normal form** at `DF = e^{−rτ}`. -/ +lemma bsd1_eq_gbsd1_standard (S K r σ τ : ℝ) (hS : 0 < S) (hK : 0 < K) : + bsd1 S K r σ τ = gbsd1 S K (Real.exp (-(r * τ))) σ τ := by + unfold bsd1 gbsd1 + congr 1 + rw [log_div_mul_exp_neg S K r τ hS hK] + ring + +/-- **Standard BS `bsd2` matches the Garman normal form**. -/ +lemma bsd2_eq_gbsd2_standard (S K r σ τ : ℝ) (hS : 0 < S) (hK : 0 < K) : + bsd2 S K r σ τ = gbsd2 S K (Real.exp (-(r * τ))) σ τ := by + unfold bsd2 gbsd2 + rw [bsd1_eq_gbsd1_standard S K r σ τ hS hK] + +/-- **`bsV` is a Garman instance**: the standard BS call price equals +`bsVGarman S K (e^{−rτ}) σ τ`. This is the load-bearing fact that makes +the Garman form the actual structural object underlying BS pricing — not +just a cosmetic rename. -/ +theorem bsV_eq_bsVGarman_standard (K r σ S τ : ℝ) (hS : 0 < S) (hK : 0 < K) : + bsV K r σ S τ = bsVGarman S K (Real.exp (-(r * τ))) σ τ := by + unfold bsV bsVGarman + rw [bsd1_eq_gbsd1_standard S K r σ τ hS hK] + rw [bsd2_eq_gbsd2_standard S K r σ τ hS hK] + +/-! ### Black-76 is a Garman instance -/ + +/-- **Log-algebra bridge** for Black-76: `log((F·e^{−rT}) / (K·e^{−rT})) = log(F/K)`. -/ +lemma log_FDF_div_KDF (F K r T : ℝ) (hF : 0 < F) (hK : 0 < K) : + Real.log (F * Real.exp (-(r * T)) / (K * Real.exp (-(r * T)))) = + Real.log (F / K) := by + have hexp_ne : Real.exp (-(r * T)) ≠ 0 := (Real.exp_pos _).ne' + rw [show F * Real.exp (-(r * T)) / (K * Real.exp (-(r * T))) = F / K from by + field_simp] + +/-- **`bsd1 F K 0 σ T` matches Garman's `gbsd1`** at Black-76 parameters +`A = F · e^{−rT}`, `DF = e^{−rT}`. -/ +lemma bsd1_eq_gbsd1_black76 (F K r σ T : ℝ) (hF : 0 < F) (hK : 0 < K) : + bsd1 F K 0 σ T = + gbsd1 (F * Real.exp (-(r * T))) K (Real.exp (-(r * T))) σ T := by + unfold bsd1 gbsd1 + congr 1 + rw [log_FDF_div_KDF F K r T hF hK] + rw [Real.log_div hF.ne' hK.ne'] + ring + +/-- **`bsd2` Black-76 / Garman match**. -/ +lemma bsd2_eq_gbsd2_black76 (F K r σ T : ℝ) (hF : 0 < F) (hK : 0 < K) : + bsd2 F K 0 σ T = + gbsd2 (F * Real.exp (-(r * T))) K (Real.exp (-(r * T))) σ T := by + unfold bsd2 gbsd2 + rw [bsd1_eq_gbsd1_black76 F K r σ T hF hK] + +/-- **Black-76 closed form is a Garman instance**: the explicit RHS of +`black_futures_formula` equals `bsVGarman` at `A = F · e^{−rT}`, `DF = e^{−rT}`. + +So the Black-76 closed form is *not* a separate pricing theorem — it is the +same formula as standard BS, viewed through a different (forward) numéraire. -/ +theorem black76_RHS_eq_bsVGarman (F K r σ T : ℝ) (hF : 0 < F) (hK : 0 < K) : + Real.exp (-(r * T)) * + (F * Phi (bsd1 F K 0 σ T) - K * Phi (bsd2 F K 0 σ T)) = + bsVGarman (F * Real.exp (-(r * T))) K (Real.exp (-(r * T))) σ T := by + unfold bsVGarman + rw [← bsd1_eq_gbsd1_black76 F K r σ T hF hK, + ← bsd2_eq_gbsd2_black76 F K r σ T hF hK] + ring + +/-! ### BS-Merton (continuous dividends) is a Garman instance -/ + +/-- **Log-algebra bridge for BS-Merton**: `log((S·e^{−qT}) / (K·e^{−rT})) = +log(S/K) + (r − q)T`. -/ +lemma log_SexpNegQ_div_KexpNegR (S K r q T : ℝ) (hS : 0 < S) (hK : 0 < K) : + Real.log (S * Real.exp (-(q * T)) / (K * Real.exp (-(r * T)))) = + Real.log (S / K) + (r - q) * T := by + have hexpQ_ne : Real.exp (-(q * T)) ≠ 0 := (Real.exp_pos _).ne' + have hexpR_ne : Real.exp (-(r * T)) ≠ 0 := (Real.exp_pos _).ne' + rw [Real.log_div (mul_ne_zero hS.ne' hexpQ_ne) (mul_ne_zero hK.ne' hexpR_ne)] + rw [Real.log_mul hS.ne' hexpQ_ne, Real.log_mul hK.ne' hexpR_ne] + rw [Real.log_exp, Real.log_exp] + rw [Real.log_div hS.ne' hK.ne'] + ring + +/-- **`bsd1 S K (r-q) σ T` matches Garman's `gbsd1`** at BS-Merton dividend +parameters `A = S · e^{−qT}`, `DF = e^{−rT}`. -/ +lemma bsd1_eq_gbsd1_dividends (S K r q σ T : ℝ) (hS : 0 < S) (hK : 0 < K) : + bsd1 S K (r - q) σ T = + gbsd1 (S * Real.exp (-(q * T))) K (Real.exp (-(r * T))) σ T := by + unfold bsd1 gbsd1 + congr 1 + rw [log_SexpNegQ_div_KexpNegR S K r q T hS hK] + rw [Real.log_div hS.ne' hK.ne'] + ring + +/-- **`bsd2` BS-Merton / Garman match**. -/ +lemma bsd2_eq_gbsd2_dividends (S K r q σ T : ℝ) (hS : 0 < S) (hK : 0 < K) : + bsd2 S K (r - q) σ T = + gbsd2 (S * Real.exp (-(q * T))) K (Real.exp (-(r * T))) σ T := by + unfold bsd2 gbsd2 + rw [bsd1_eq_gbsd1_dividends S K r q σ T hS hK] + +/-- **BS-Merton dividend formula is a Garman instance**: the explicit RHS +of `bs_dividends_call_formula` equals `bsVGarman` at `A = S · e^{−qT}`, +`DF = e^{−rT}`. -/ +theorem bs_dividends_RHS_eq_bsVGarman (S K r q σ T : ℝ) (hS : 0 < S) (hK : 0 < K) : + S * Real.exp (-(q * T)) * Phi (bsd1 S K (r - q) σ T) - + K * Real.exp (-(r * T)) * Phi (bsd2 S K (r - q) σ T) = + bsVGarman (S * Real.exp (-(q * T))) K (Real.exp (-(r * T))) σ T := by + unfold bsVGarman + rw [← bsd1_eq_gbsd1_dividends S K r q σ T hS hK, + ← bsd2_eq_gbsd2_dividends S K r q σ T hS hK] + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/GaussianGirsanov.lean b/LeanPool/MathFin/Models/BlackScholes/GaussianGirsanov.lean new file mode 100644 index 0000000000..9262baa509 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/GaussianGirsanov.lean @@ -0,0 +1,306 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Call +public import LeanPool.MathFin.Models.BlackScholes.Forward +public import LeanPool.MathFin.Probability.Laws.Esscher +public import LeanPool.MathFin.Probability.Martingales.EquivMeasure + +/-! +# Static Girsanov: the risk-neutral measure as a Gaussian change of measure + +`BSCallHyp` — the lognormal risk-neutral hypothesis that 14 pricing files +take on faith — posits "the driver `Z` is standard normal under `Q`." This +file **derives** that hypothesis: it constructs the risk-neutral measure `Q` +from the physical measure `P` via an explicit Radon-Nikodym (Esscher) +density, and proves the recentred driver is standard normal under `Q`. The +EMM stops being an axiom. + +The deductive chain: + +1. `gaussianReal_withDensity_esscher` — measure level: tilting `N(0,1)` by + the Esscher density `exp(c·x − c²/2)` gives `N(c,1)` (mean-shift by `c`, + variance fixed). It is the case `N(0,1)` of the Gaussian Esscher transform + `gaussianReal_tilted_const_mul` (`Probability/Laws/Esscher.lean`), whose + normalizing constant is `𝔼[e^{cZ}] = e^{c²/2}`. +2. `map_withDensity_comp` — pushforward commutes with a density factoring + through the map (so the change of measure can be read at the level of the + driver's law). +3. `hasLaw_esscher_tilt` — static Girsanov for a random variable: if `W` is + standard normal under `P`, then under `Q := P.withDensity(exp(c·W−c²/2))` + the same `W` has law `N(c,1)`. +4. `hasLaw_sub_const` — recentring: `W − c ~ N(0,1)` under `Q`. +5. `BSCallHyp.exists_of_physical` — the capstone: `BSCallHyp` holds for `Q` and the + recentred driver, with `Q` and the driver both *constructed* from the + physical data. The economic instantiation is `c = (r − μ)·√T / σ`, i.e. + the market price of risk `θ = (μ − r)/σ` enters as `c = −θ√T`; then the + recentred driver `W − c = W + θ√T` is exactly the risk-neutral driver, + and `bsTerminal` driven by it reprices the *same* asset with drift `μ → r` + (see `bsTerminal_physical_eq_riskNeutral`). + +This is the static (single-Gaussian) Girsanov theorem, at one date. The +process-level Girsanov theorem, for constant, simple, bounded adapted and +bounded predictable `θ`, is in `Probability/Brownian/Girsanov/GirsanovConstantTheta.lean` +through `Probability/Brownian/Girsanov/GirsanovPredictableTheta.lean`. + +## Main results + +* `gaussianReal_withDensity_esscher`: tilting `N(0, 1)` by the density `exp (c x - c²/2)` gives + `N(c, 1)`. +* `map_withDensity_comp`: for measurable `W` and a density `g ∘ W` factoring through it, + `(P.withDensity (g ∘ W)).map W = (P.map W).withDensity g`. +* `hasLaw_esscher_tilt`: if `W` is `N(0, 1)` under `P`, it is `N(c, 1)` under `P` tilted by + `exp (c W - c²/2)`. +* `esscherTilt_isProbabilityMeasure`, `esscherTilt_isEquivProbMeasure`: the tilted measure is a + probability measure, and equivalent to `P`. +* `BSCallHyp.exists_of_physical`: for a standard normal driver `W` under `P`, the tilted measure + `Q` is a probability measure under which `W - c` satisfies `BSCallHyp`. +* `bsTerminal_physical_eq_riskNeutral`: for `σ ≠ 0` and `T ≥ 0`, the terminal value at drift `μ` + and driver `w` equals the terminal value at drift `r` and driver `w - (r - μ)√T/σ`. +* `discounted_terminal_eq_S0_of_physical`: for that `Q`, the discounted terminal value + `exp (-rT) * bsTerminal S_0 r σ T (W - c)` has `Q`-integral `S_0`. +* `bs_call_formula_of_physical`: for that `Q`, the discounted call payoff on + `bsTerminal S_0 r σ T (W - c)` has `Q`-integral `S_0 Φ(d₁) - K e^{-rT} Φ(d₂)`. +* `discounted_physical_terminal_eq_S0`: for `σ, T, S_0 > 0` and a standard normal driver `W`, + some probability measure `Q` gives the asset with physical drift `μ` discounted terminal + value with `Q`-integral `S_0` (the proof takes the shift `c = (r - μ)√T/σ`). + +## Tags + +Girsanov theorem, Esscher transform, risk-neutral measure, market price of risk, change of measure, +equivalent martingale measure, MSC 91G20, MSC 60H30, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal + +/-- **Gaussian Esscher change of measure** (measure level): tilting the +standard normal `N(0,1)` by the Radon-Nikodym density `exp(c·x − c²/2)` +produces exactly `N(c, 1)`. The mean shifts by the tilt parameter `c`; the +variance is unchanged. This is the static (single-Gaussian) Girsanov +theorem: the case `N(0, 1)` of the Gaussian Esscher transform +`gaussianReal_tilted_const_mul`, with the normalizing constant +`𝔼[e^{cZ}] = e^{c²/2}` written into the density. -/ +theorem gaussianReal_withDensity_esscher (c : ℝ) : + (gaussianReal 0 1).withDensity + (fun x ↦ ENNReal.ofReal (Real.exp (c * x - c ^ 2 / 2))) = gaussianReal c 1 := by + have hZ : ∫ x, rexp (c * x) ∂(gaussianReal 0 1) = rexp (c ^ 2 / 2) := by + simpa only [mgf, id_eq, zero_mul, zero_add, NNReal.coe_one, one_mul] using + congr_fun (mgf_id_gaussianReal (μ := 0) (v := 1)) c + have h := gaussianReal_tilted_const_mul 0 1 c + rw [Measure.tilted, hZ, NNReal.coe_one, mul_one, zero_add] at h + simpa only [← Real.exp_sub] using h + +/-- **Pushforward commutes with a density that factors through the map**: +for measurable `W : Ω → ℝ` and `g : ℝ → ℝ≥0∞`, the law of `W` under +`P.withDensity (g ∘ W)` is `(law of W under P).withDensity g`. This is the +plumbing that lets a change of measure defined on `Ω` (via a density in the +driver `W`) be read entirely at the level of `W`'s law. -/ +theorem map_withDensity_comp {Ω : Type*} {mΩ : MeasurableSpace Ω} + (P : Measure Ω) {W : Ω → ℝ} (hW : Measurable W) {g : ℝ → ℝ≥0∞} + (hg : Measurable g) : + (P.withDensity (g ∘ W)).map W = (P.map W).withDensity g := by + ext s hs + rw [Measure.map_apply hW hs, withDensity_apply _ (hW hs), + withDensity_apply _ hs, setLIntegral_map hs hg hW] + rfl + +/-- **Static Girsanov for a random variable**: if the driver `W` is standard +normal under the physical measure `P`, then under the Esscher-tilted measure +`Q := P.withDensity(exp(c·W − c²/2))`, the *same* `W` has law `N(c, 1)`. The +change of measure shifts the driver's mean by the tilt `c` and leaves the +variance fixed — exactly the static (single-Gaussian) Girsanov theorem, +stated at the level of the random variable. -/ +theorem hasLaw_esscher_tilt {Ω : Type*} {mΩ : MeasurableSpace Ω} + {P : Measure Ω} {W : Ω → ℝ} (c : ℝ) + (hWmeas : Measurable W) (hW : HasLaw W (gaussianReal 0 1) P) : + HasLaw W (gaussianReal c 1) + (P.withDensity (fun ω ↦ ENNReal.ofReal (Real.exp (c * W ω - c ^ 2 / 2)))) where + aemeasurable := hWmeas.aemeasurable + map_eq := by + rw [show (fun ω ↦ ENNReal.ofReal (Real.exp (c * W ω - c ^ 2 / 2))) + = (fun x ↦ ENNReal.ofReal (Real.exp (c * x - c ^ 2 / 2))) ∘ W from rfl, + map_withDensity_comp P hWmeas (by fun_prop), hW.map_eq, + gaussianReal_withDensity_esscher] + +/-- **Shifting a Gaussian driver**: if `W ~ N(m, 1)` then `W − c ~ N(m − c, 1)`. +Recentering by a constant translates the mean. -/ +theorem hasLaw_sub_const {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} {W : Ω → ℝ} (c m : ℝ) + (hWmeas : Measurable W) (hW : HasLaw W (gaussianReal m 1) Q) : + HasLaw (fun ω ↦ W ω - c) (gaussianReal (m - c) 1) Q where + aemeasurable := (hWmeas.sub_const c).aemeasurable + map_eq := by + rw [show (fun ω ↦ W ω - c) = (fun y : ℝ ↦ y - c) ∘ W from rfl, + ← Measure.map_map (show Measurable (fun y : ℝ ↦ y - c) by fun_prop) hWmeas, + hW.map_eq, + show (fun y : ℝ ↦ y - c) = (fun y ↦ y + (-c)) from by funext y; ring, + gaussianReal_map_add_const, sub_eq_add_neg] + +/-- **The Esscher-tilted measure is a probability measure.** Its total mass +is the standard-normal MGF evaluated to `1` (the Esscher density is +normalised), read off from the fact that `W` has a genuine law (`N(c,1)`) +under it. -/ +theorem esscherTilt_isProbabilityMeasure {Ω : Type*} {mΩ : MeasurableSpace Ω} + {P : Measure Ω} {W : Ω → ℝ} (c : ℝ) + (hWmeas : Measurable W) (hW : HasLaw W (gaussianReal 0 1) P) : + IsProbabilityMeasure + (P.withDensity (fun ω ↦ ENNReal.ofReal (Real.exp (c * W ω - c ^ 2 / 2)))) := by + constructor + rw [← Set.preimage_univ (f := W), + ← Measure.map_apply hWmeas MeasurableSet.univ, + (hasLaw_esscher_tilt c hWmeas hW).map_eq] + exact measure_univ + +/-- **The Esscher-tilted measure is equivalent to `P`.** It is a probability measure +(`esscherTilt_isProbabilityMeasure`), `Q ≪ P` as every density change is, and `P ≪ Q` because +the density `exp(c·W − c²/2)` is strictly positive (`absolutelyContinuous_withDensity_ofReal`): +the two measures have the same null sets. -/ +theorem esscherTilt_isEquivProbMeasure {Ω : Type*} {mΩ : MeasurableSpace Ω} + {P : Measure Ω} {W : Ω → ℝ} (c : ℝ) + (hWmeas : Measurable W) (hW : HasLaw W (gaussianReal 0 1) P) : + IsEquivProbMeasure P + (P.withDensity (fun ω ↦ ENNReal.ofReal (Real.exp (c * W ω - c ^ 2 / 2)))) := + isEquivProbMeasure_withDensity_of_isProbabilityMeasure P + (Real.measurable_exp.comp ((hWmeas.const_mul c).sub_const _)).aemeasurable + (ae_of_all _ fun _ ↦ Real.exp_pos _) (esscherTilt_isProbabilityMeasure c hWmeas hW) + +/-- **The risk-neutral measure, derived** (static Girsanov capstone). Given a +standard-normal physical driver `W` under `P`, there **exists** a probability +measure `Q` — explicitly the Esscher tilt `Q = P.withDensity(exp(c·W − c²/2))` +— under which the recentred driver `W − c` satisfies the risk-neutral +hypothesis `BSCallHyp`. The risk-neutral hypothesis is thus a *theorem*: every +BS-family price, Greek, and bound that consumes `BSCallHyp` is founded on a +constructed EMM rather than an assumed one. + +Economic instantiation: take `c = (r − μ)·√T / σ = −θ·√T` where `θ = (μ−r)/σ` +is the market price of risk; then `W − c = W + θ√T` is the risk-neutral +driver, and `Q` is the equivalent martingale measure — its martingale +property `E_Q[e^{−rT} S_T] = S_0` follows from the resulting `BSCallHyp` via +`discounted_terminal_eq_S0`. -/ +theorem BSCallHyp.exists_of_physical {Ω : Type*} {mΩ : MeasurableSpace Ω} + {P : Measure Ω} + {S_0 K r σ T : ℝ} {W : Ω → ℝ} (c : ℝ) + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) + (hWmeas : Measurable W) (hW : HasLaw W (gaussianReal 0 1) P) : + ∃ (Q : Measure Ω) (hQ : IsProbabilityMeasure Q), + Q = P.withDensity (fun ω ↦ ENNReal.ofReal (Real.exp (c * W ω - c ^ 2 / 2))) ∧ + @BSCallHyp _ _ Q hQ S_0 K r σ T (fun ω ↦ W ω - c) := by + have h_std : HasLaw (fun ω ↦ W ω - c) (gaussianReal 0 1) + (P.withDensity (fun ω ↦ ENNReal.ofReal (Real.exp (c * W ω - c ^ 2 / 2)))) := by + have h := hasLaw_sub_const c c hWmeas (hasLaw_esscher_tilt c hWmeas hW) + rwa [sub_self] at h + exact ⟨P.withDensity (fun ω ↦ ENNReal.ofReal (Real.exp (c * W ω - c ^ 2 / 2))), + esscherTilt_isProbabilityMeasure c hWmeas hW, rfl, + @BSCallHyp.mk _ _ _ (esscherTilt_isProbabilityMeasure c hWmeas hW) + _ _ _ _ _ _ hS_0 hK hσ hT h_std⟩ + +/-- **The change of measure reprices the same asset** — the conceptual heart +of risk-neutral valuation. The Girsanov shift `c = (r − μ)·√T / σ` is exactly +the recentring under which the physical terminal `S_0·exp((μ−σ²/2)T + σ√T·W)` +equals the risk-neutral terminal `S_0·exp((r−σ²/2)T + σ√T·(W − c))`. The asset +`S_T` is invariant; only its *drift* changes `μ → r`. This is *why* the +Esscher tilt of `BSCallHyp.exists_of_physical` is the right change of +measure: it is the one that turns the real-world drift into the risk-free +rate while leaving the random variable `S_T` untouched. -/ +theorem bsTerminal_physical_eq_riskNeutral + (S_0 μ r σ T w : ℝ) (hσ : σ ≠ 0) (hT : 0 ≤ T) : + bsTerminal S_0 μ σ T w + = bsTerminal S_0 r σ T (w - (r - μ) * Real.sqrt T / σ) := by + unfold bsTerminal + have hexp : (μ - σ ^ 2 / 2) * T + σ * Real.sqrt T * w + = (r - σ ^ 2 / 2) * T + σ * Real.sqrt T * (w - (r - μ) * Real.sqrt T / σ) := by + have h1 : σ * Real.sqrt T * (w - (r - μ) * Real.sqrt T / σ) + = σ * Real.sqrt T * w - (r - μ) * (Real.sqrt T * Real.sqrt T) := by + field_simp + rw [h1, Real.mul_self_sqrt hT]; ring + rw [hexp] + +/-! ## Wiring Girsanov into the pricing artifacts + +The two composites below make `GaussianGirsanov` load-bearing: they drive the +prior pricing results from the *physical* measure through the constructed +EMM, rather than from an assumed `BSCallHyp`. This is the genesis-cascade +spine `physical measure → Girsanov → Q → pricing`. -/ + +/-- **The constructed measure is an equivalent martingale measure** (derived +from the physical measure). For the Esscher-tilted `Q` of +`BSCallHyp.exists_of_physical`, the discounted terminal asset is a +`Q`-martingale: `E_Q[e^{−rT}·S_T] = S_0`. This is the *defining* property of +an EMM — so the construction yields a genuine risk-neutral measure, not +merely one under which the driver is standard normal. Composes +`exists_of_physical` with `discounted_terminal_eq_S0`. -/ +theorem discounted_terminal_eq_S0_of_physical {Ω : Type*} {mΩ : MeasurableSpace Ω} + {P : Measure Ω} + {S_0 K r σ T : ℝ} {W : Ω → ℝ} (c : ℝ) + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) + (hWmeas : Measurable W) (hW : HasLaw W (gaussianReal 0 1) P) : + ∃ (Q : Measure Ω) (_ : IsProbabilityMeasure Q), + Q = P.withDensity (fun ω ↦ ENNReal.ofReal (Real.exp (c * W ω - c ^ 2 / 2))) ∧ + ∫ ω, Real.exp (-(r * T)) * bsTerminal S_0 r σ T (W ω - c) ∂Q = S_0 := by + obtain ⟨Q, hQ, hQeq, hbs⟩ := + BSCallHyp.exists_of_physical (S_0 := S_0) (K := K) (r := r) (σ := σ) (T := T) + c hS_0 hK hσ hT hWmeas hW + have := hQ + exact ⟨Q, hQ, hQeq, discounted_terminal_eq_S0 hbs⟩ + +/-- **Black-Scholes call price from the physical measure** (full chain). For +the constructed EMM `Q`, the discounted expected payoff equals the +Black-Scholes closed form. Every other BS-family result composes the same +way; this one stands for the pipeline. Composes `exists_of_physical` with +`bs_call_formula`. -/ +theorem bs_call_formula_of_physical {Ω : Type*} {mΩ : MeasurableSpace Ω} + {P : Measure Ω} + {S_0 K r σ T : ℝ} {W : Ω → ℝ} (c : ℝ) + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) + (hWmeas : Measurable W) (hW : HasLaw W (gaussianReal 0 1) P) : + ∃ (Q : Measure Ω) (_ : IsProbabilityMeasure Q), + Q = P.withDensity (fun ω ↦ ENNReal.ofReal (Real.exp (c * W ω - c ^ 2 / 2))) ∧ + ∫ ω, Real.exp (-r * T) * max (bsTerminal S_0 r σ T (W ω - c) - K) 0 ∂Q + = S_0 * Phi (bsd1 S_0 K r σ T) + - K * Real.exp (-r * T) * Phi (bsd2 S_0 K r σ T) := by + obtain ⟨Q, hQ, hQeq, hbs⟩ := + BSCallHyp.exists_of_physical (S_0 := S_0) (K := K) (r := r) (σ := σ) (T := T) + c hS_0 hK hσ hT hWmeas hW + have := hQ + exact ⟨Q, hQ, hQeq, bs_call_formula hbs⟩ + +/-- **The physical-drift asset reprices to `S_0` under the constructed EMM** — +the `μ → r` drift elimination, *wired into the chain* (not merely asserted). +Instantiating the Girsanov shift at the market-price-of-risk value +`c = (r − μ)·√T/σ`, `bsTerminal_physical_eq_riskNeutral` identifies the physical +terminal `bsTerminal S_0 μ σ T W` (drift `μ`) with the risk-neutral one, and +`discounted_terminal_eq_S0_of_physical` supplies the martingale property — so +`E_Q[e^{−rT}·S_T] = S_0` holds for the asset carrying the *physical* drift `μ`. +This composes the previously-standalone drift-invariance identity into the EMM +pipeline, closing the `physical → EMM` step at the level of the physical model. -/ +theorem discounted_physical_terminal_eq_S0 {Ω : Type*} {mΩ : MeasurableSpace Ω} + {P : Measure Ω} + {S_0 r μ σ T : ℝ} {W : Ω → ℝ} + (hS_0 : 0 < S_0) (hσ : 0 < σ) (hT : 0 < T) + (hWmeas : Measurable W) (hW : HasLaw W (gaussianReal 0 1) P) : + ∃ (Q : Measure Ω) (_ : IsProbabilityMeasure Q), + ∫ ω, Real.exp (-(r * T)) * bsTerminal S_0 μ σ T (W ω) ∂Q = S_0 := by + obtain ⟨Q, hQ, _, hbs⟩ := + discounted_terminal_eq_S0_of_physical (K := S_0) (r := r) + ((r - μ) * Real.sqrt T / σ) hS_0 hS_0 hσ hT hWmeas hW + have := hQ + refine ⟨Q, hQ, ?_⟩ + have hfun : ∀ ω, Real.exp (-(r * T)) * bsTerminal S_0 μ σ T (W ω) + = Real.exp (-(r * T)) * bsTerminal S_0 r σ T (W ω - (r - μ) * Real.sqrt T / σ) := by + intro ω + rw [bsTerminal_physical_eq_riskNeutral S_0 μ r σ T (W ω) (ne_of_gt hσ) hT.le] + rw [integral_congr_ae (Filter.Eventually.of_forall hfun)] + exact hbs + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/GaussianSmoothing.lean b/LeanPool/MathFin/Models/BlackScholes/GaussianSmoothing.lean new file mode 100644 index 0000000000..38fc57f832 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/GaussianSmoothing.lean @@ -0,0 +1,138 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionMixing +public import LeanPool.MathFin.Probability.Gaussian.GaussianMoments + +/-! +# Gaussian smoothing of the Black–Scholes price + +Averaging the Black–Scholes call over a lognormal factor on the spot gives a Black–Scholes call. +For `G ∼ N(m, v)`, + + `𝔼[C_BS(Se^G; σ)] = C_BS(Se^{m + v/2}; σ')` with `σ'²T = σ²T + v`, + +at the same strike, rate and maturity `T`. The spot is multiplied by `𝔼[e^G] = e^{m + v/2}` and the +log-return variance `σ²T` gains the variance `v` of `G`. + +The proof reads the left side as a call. On `N(0, 1) ⊗ N(m, v)` with coordinates `Z` and `G`, the +mixing formula (`jumpDiffusion_call_eq_integral_bsV`) makes `𝔼[C_BS(Se^G; σ)]` the expected +discounted payoff of the terminal price `S·e^{(r − σ²/2)T + σ√T·Z + G}`. The total log-shock +`σ√T·Z + G` is `N(m, σ²T + v)` (`gaussianReal_conv_gaussianReal`), so this terminal price is a +Black–Scholes terminal price at the spot `Se^{m + v/2}` and the volatility `σ'`, driven by the +standardized shock. + +With `G` the sum of `n` of Merton's Gaussian log-jumps, this is the `n`-th term of Merton's +series (`Models/Jumps/JumpDiffusionMerton.lean`). + +## Main results + +* `integral_exp_gaussianReal`: the lognormal mean `∫ eˣ dN(m, v) = e^{m + v/2}`. +* `integral_bsV_mul_exp_gaussianReal_of_sq`: `∫ C_BS(Se^x; σ) dN(m, v) = C_BS(Se^{m + v/2}; σ')` + for any `σ' > 0` with `σ'²T = σ²T + v`. +* `integral_bsV_mul_exp_gaussianReal`: the same with `σ' = √(σ² + v/T)`. + +## References + +* [R. C. Merton, *Option pricing when underlying stock returns are discontinuous*][Merton1976] + +## Tags + +lognormal mixture, random volatility, averaging over spot, Gaussian convolution, +variance adjustment, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal + +/-- The exponential is integrable under a Gaussian law. -/ +lemma integrable_exp_gaussianReal (m : ℝ) (v : ℝ≥0) : Integrable rexp (gaussianReal m v) := by + simpa only [one_mul] using integrable_exp_mul_gaussianReal (μ := m) (v := v) 1 + +/-- **The lognormal mean**: `∫ eˣ dN(m, v) = e^{m + v/2}`, the moment generating function of +`N(m, v)` at `1`. -/ +lemma integral_exp_gaussianReal (m : ℝ) (v : ℝ≥0) : + ∫ x, rexp x ∂(gaussianReal m v) = rexp (m + v / 2) := by + have h := congrFun (mgf_fun_id_gaussianReal (μ := m) (v := v)) 1 + simp only [mgf, one_mul, mul_one, one_pow] at h + exact h + +/-- **Gaussian smoothing of the Black–Scholes price.** For `G ∼ N(m, v)` and a volatility `σ'` +with `σ'²T = σ²T + v`, the Black–Scholes call at the spot `Se^G` and volatility `σ`, averaged over +`G`, is the Black–Scholes call at the spot `Se^{m + v/2}` and volatility `σ'`. -/ +theorem integral_bsV_mul_exp_gaussianReal_of_sq {S K r σ σ' T : ℝ} (hS : 0 < S) (hK : 0 < K) + (hσ : 0 < σ) (hσ' : 0 < σ') (hT : 0 < T) (m : ℝ) {v : ℝ≥0} + (hvar : σ' ^ 2 * T = σ ^ 2 * T + v) : + ∫ x, bsV K r σ (S * rexp x) T ∂(gaussianReal m v) = bsV K r σ' (S * rexp (m + v / 2)) T := by + -- the diffusion sample `Z ∼ N(0, 1)` and `G ∼ N(m, v)`, independent, on the product space + have hZ : HasLaw (fun ω : ℝ × ℝ ↦ ω.1) (gaussianReal 0 1) + ((gaussianReal 0 1).prod (gaussianReal m v)) := + measurePreserving_fst.hasLaw + have hG : HasLaw (fun ω : ℝ × ℝ ↦ ω.2) (gaussianReal m v) + ((gaussianReal 0 1).prod (gaussianReal m v)) := + measurePreserving_snd.hasLaw + have hGZ : (fun ω : ℝ × ℝ ↦ ω.2) ⟂ᵢ[(gaussianReal 0 1).prod (gaussianReal m v)] + fun ω ↦ ω.1 := + (indepFun_prod (μ := gaussianReal 0 1) (ν := gaussianReal m v) measurable_id + measurable_id).symm + have hexp : Integrable (fun ω : ℝ × ℝ ↦ rexp ω.2) + ((gaussianReal 0 1).prod (gaussianReal m v)) := by + simpa only [one_mul] using hG.integrable_fun_comp (integrable_exp_mul_gaussianReal 1) + -- the total log-shock `σ√T·Z + G` is `N(m, σ²T + v)`, so standardized it is `N(0, 1)` + have hshock : HasLaw (fun ω : ℝ × ℝ ↦ σ * Real.sqrt T * ω.1 + ω.2) + (gaussianReal m (.mk ((σ * Real.sqrt T) ^ 2) (sq_nonneg _) * 1 + v)) + ((gaussianReal 0 1).prod (gaussianReal m v)) := by + have h := (indepFun_prod (μ := gaussianReal 0 1) (ν := gaussianReal m v) + (by fun_prop : Measurable fun z : ℝ ↦ σ * Real.sqrt T * z) measurable_id).hasLaw_fun_add + (gaussianReal_const_mul hZ (σ * Real.sqrt T)) hG + rwa [gaussianReal_conv_gaussianReal, mul_zero, zero_add] at h + have hs : 0 < σ' * Real.sqrt T := mul_pos hσ' (Real.sqrt_pos.2 hT) + have hW := hasLaw_sub_div_of_gaussianReal hshock hs (by + simp only [NNReal.coe_add, NNReal.coe_mul, NNReal.coe_mk, NNReal.coe_one] + linear_combination (σ ^ 2 - σ' ^ 2) * Real.sq_sqrt hT.le - hvar) + have hbs : Measurable fun x ↦ bsV K r σ (S * rexp x) T := + (measurable_bsV_spot K r σ T).comp (by fun_prop) + calc ∫ x, bsV K r σ (S * rexp x) T ∂(gaussianReal m v) + = ∫ ω, bsV K r σ (S * rexp ω.2) T ∂((gaussianReal 0 1).prod (gaussianReal m v)) := + (hG.integral_comp hbs.aestronglyMeasurable).symm + _ = ∫ ω, rexp (-r * T) * max (S * rexp ((r - σ ^ 2 / 2) * T + σ * Real.sqrt T * ω.1 + ω.2) + - K) 0 ∂((gaussianReal 0 1).prod (gaussianReal m v)) := + (jumpDiffusion_call_eq_integral_bsV hZ hG.aemeasurable hGZ hexp hS hK hσ hT).symm + _ = ∫ ω, rexp (-r * T) * max (bsTerminal (S * rexp (m + v / 2)) r σ' T + ((σ * Real.sqrt T * ω.1 + ω.2 - m) / (σ' * Real.sqrt T)) - K) 0 + ∂((gaussianReal 0 1).prod (gaussianReal m v)) := by + refine integral_congr_ae (ae_of_all _ fun ω ↦ ?_) + have hw : σ' * Real.sqrt T * ((σ * Real.sqrt T * ω.1 + ω.2 - m) / (σ' * Real.sqrt T)) + = σ * Real.sqrt T * ω.1 + ω.2 - m := + mul_div_cancel₀ _ hs.ne' + have hE : (r - σ ^ 2 / 2) * T + σ * Real.sqrt T * ω.1 + ω.2 + = m + v / 2 + ((r - σ' ^ 2 / 2) * T + (σ * Real.sqrt T * ω.1 + ω.2 - m)) := by + linear_combination (1 / 2 : ℝ) * hvar + change rexp (-r * T) * max (S * rexp ((r - σ ^ 2 / 2) * T + σ * Real.sqrt T * ω.1 + ω.2) + - K) 0 + = rexp (-r * T) * max (bsTerminal (S * rexp (m + v / 2)) r σ' T + ((σ * Real.sqrt T * ω.1 + ω.2 - m) / (σ' * Real.sqrt T)) - K) 0 + rw [hE, Real.exp_add (m + v / 2), ← mul_assoc, bsTerminal, hw] + _ = bsV K r σ' (S * rexp (m + v / 2)) T := + integral_bsCall_payoff_eq_bsV ⟨mul_pos hS (Real.exp_pos _), hK, hσ', hT, hW⟩ + +/-- **Gaussian smoothing of the Black–Scholes price**, with the smoothed volatility written out: +for `G ∼ N(m, v)`, `𝔼[C_BS(Se^G; σ)] = C_BS(Se^{m + v/2}; √(σ² + v/T))`. -/ +theorem integral_bsV_mul_exp_gaussianReal {S K r σ T : ℝ} (hS : 0 < S) (hK : 0 < K) + (hσ : 0 < σ) (hT : 0 < T) (m : ℝ) (v : ℝ≥0) : + ∫ x, bsV K r σ (S * rexp x) T ∂(gaussianReal m v) + = bsV K r (Real.sqrt (σ ^ 2 + v / T)) (S * rexp (m + v / 2)) T := + integral_bsV_mul_exp_gaussianReal_of_sq hS hK hσ (Real.sqrt_pos.2 (by positivity)) hT m (by + rw [Real.sq_sqrt (by positivity), add_mul, div_mul_cancel₀ _ hT.ne']) + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/GreekSigns.lean b/LeanPool/MathFin/Models/BlackScholes/GreekSigns.lean new file mode 100644 index 0000000000..001be8122e --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/GreekSigns.lean @@ -0,0 +1,161 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho, Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Call + +/-! +# Black-Scholes Greek sign constraints + +The signs of the BS Greeks are determined by the structure of the call +price formula and the positivity of the standard-normal PDF/CDF. They are +collected here as named lemmas — the library has the individual derivatives +scattered across `PDE.lean`, `StrikeGreeks.lean`, and `HigherGreeks.lean`, +but the sign constraints are not explicitly stated. + +The sign constraints are the *qualitative* content of the BS Greeks: a +trader can read each sign off the formula and the table below. + +| Greek | Sign for call | Reason | +|---|---|---| +| δ = ∂_S V | ≥ 0 | `Φ(d_1) ∈ [0, 1]` | +| γ = ∂²_S V | > 0 | `ϕ(d_1) > 0`, positive denominator | +| ν = ∂_σ V | > 0 | `S · ϕ(d_1) · √τ > 0` (already in ImpliedVolatility.lean) | +| ρ = ∂_r V | ≥ 0 | `K · τ · e^{−rτ} · Φ(d_2) ≥ 0` | +| ∂_K V | ≤ 0 | `−e^{−rτ} · Φ(d_2) ≤ 0` (call decreases in strike) | +| ∂²_K V | ≥ 0 | `e^{−rτ} · ϕ(d_2)/(K σ √τ) ≥ 0` (Breeden-Litzenberger) | + +Read through the mean value theorem, these signs say that a call is increasing and convex in +spot, increasing in vol, decreasing and convex in strike, and increasing in rate. This file +states only the signs of the formulas, each the derivative of the price by the lemma cited +below. Stated as properties of the price elsewhere: convexity in spot (`bsV_spot_convexOn`), +strict monotonicity in vol (`bsV_strictMonoOn_sigma`), convexity in strike +(`bsV_strike_convexOn`), and a call non-increasing in the dividend yield (`antitone_bsVDiv_q`, +`DividendsGreeks.lean`). Monotonicity in spot, strike and rate is not stated as such. + +## Main results + +* `bsV_delta_nonneg`, `bsV_delta_le_one`: `Φ(d_1) ∈ [0, 1]` (`∂_S V` by `hasDerivAt_bsV_S`). +* `bsV_gamma_pos`: the gamma formula, `∂²_S V` by `hasDerivAt_deriv_bsV_S`, is `> 0`. +* `bsV_rho_nonneg`: the rho formula, `∂_r V` by `hasDerivAt_bsV_r`, is `≥ 0`. +* `bsV_partial_K_nonpos`: the formula `∂_K V` of `hasDerivAt_bsV_K` is `≤ 0`. +* `bsV_partial_KK_nonneg`: the formula `∂²_K V` of `hasDerivAt_deriv_bsV_K` is `≥ 0`. +* `bsV_theta_tau_nonneg`: for `S, K, σ ≥ 0` and `r ≥ 0` the formula `∂_τ V` of + `hasDerivAt_bsV_tau` is `≥ 0` (calendar theta `Θ = −∂_τ V ≤ 0`, Hull §19.5). +* `bsP_delta_nonpos`, `bsP_rho_nonpos`: the put column of Hull Table 19.6 (put delta + `Φ(d₁) − 1 ≤ 0`, the formula of `hasDerivAt_bsP_S`; put rho `≤ 0` for `K, τ ≥ 0`, the formula + of `hasDerivAt_bsP_r`); put vega equals call vega (`hasDerivAt_bsP_sigma`), whose + sign is `bsV_vega_pos`. Put theta has no unconditional sign: for `r > 0` a deep + in-the-money put has positive calendar theta (`Θ_put → r K e^{−rτ}` as `S → 0`; not + formalized here). + +## Tags + +Greeks, delta gamma vega, sign of sensitivities, option sensitivities, monotonicity of price, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal + +/-! ## Delta sign constraints -/ + +/-- **Call delta is non-negative**: `0 ≤ Φ(d_1)`. -/ +theorem bsV_delta_nonneg (S K r σ τ : ℝ) : 0 ≤ Phi (bsd1 S K r σ τ) := + Phi_nonneg _ + +/-- **Call delta is at most 1**: `Φ(d_1) ≤ 1`. -/ +theorem bsV_delta_le_one (S K r σ τ : ℝ) : Phi (bsd1 S K r σ τ) ≤ 1 := + Phi_le_one _ + +/-! ## Gamma sign constraint -/ + +/-- **Call gamma is strictly positive**: the gamma formula `ϕ(d_1) / (S σ √τ)`, which is +`∂²_S V` by `hasDerivAt_deriv_bsV_S`, is positive for `S, σ, τ > 0`. Convexity in spot is +`bsV_spot_convexOn`, strict convexity `bsV_spot_strictConvexOn` (`SpotConvexity.lean`). -/ +theorem bsV_gamma_pos {K r σ : ℝ} (_hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + 0 < gaussianPDFReal 0 1 (bsd1 S K r σ τ) / (S * σ * Real.sqrt τ) := by + have h_pdf_pos : 0 < gaussianPDFReal 0 1 (bsd1 S K r σ τ) := + gaussianPDFReal_pos 0 1 _ (one_ne_zero : (1 : ℝ≥0) ≠ 0) + have h_den_pos : 0 < S * σ * Real.sqrt τ := + mul_pos (mul_pos hS hσ) (Real.sqrt_pos.mpr hτ) + exact div_pos h_pdf_pos h_den_pos + +/-! ## Rho sign constraint -/ + +/-- **Call rho is non-negative**: `∂_r V = K · τ · e^{−rτ} · Φ(d_2) ≥ 0` +for `K ≥ 0` and `τ ≥ 0` (the formula is `∂_r V` by `hasDerivAt_bsV_r`). Read through the mean +value theorem, the call price increases in the risk-free rate; that monotonicity is not stated. -/ +theorem bsV_rho_nonneg {K τ : ℝ} (hK : 0 ≤ K) (hτ : 0 ≤ τ) (S r σ : ℝ) : + 0 ≤ K * τ * Real.exp (-(r * τ)) * Phi (bsd2 S K r σ τ) := by + have h_exp_nn : 0 ≤ Real.exp (-(r * τ)) := (Real.exp_pos _).le + have h_Phi_nn : 0 ≤ Phi (bsd2 S K r σ τ) := Phi_nonneg _ + exact mul_nonneg (mul_nonneg (mul_nonneg hK hτ) h_exp_nn) h_Phi_nn + +/-! ## Strike-direction sign constraints -/ + +/-- **Partial in strike is non-positive**: `∂_K V = −e^{−rτ} · Φ(d_2) ≤ 0` (the formula is +`∂_K V` by `hasDerivAt_bsV_K`). Read through the mean value theorem, the call price decreases +in the strike; that monotonicity is not stated. -/ +theorem bsV_partial_K_nonpos (S K r σ τ : ℝ) : + -(Real.exp (-(r * τ)) * Phi (bsd2 S K r σ τ)) ≤ 0 := by + have h_exp_nn : 0 ≤ Real.exp (-(r * τ)) := (Real.exp_pos _).le + have h_Phi_nn : 0 ≤ Phi (bsd2 S K r σ τ) := Phi_nonneg _ + have := mul_nonneg h_exp_nn h_Phi_nn + linarith + +/-- **Second partial in strike is non-negative**: `∂²_K V = e^{−rτ} · ϕ(d_2) / +(K · σ · √τ) ≥ 0` for `K, σ, τ > 0`. This is the *infinitesimal* face of +butterfly non-negativity (`butterfly_payoff_nonneg`); via Breeden-Litzenberger +it equals `e^{−rτ}` times the implied PDF, which must be non-negative because +it *is* a probability density. -/ +theorem bsV_partial_KK_nonneg {K σ τ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) + (S r : ℝ) : + 0 ≤ Real.exp (-(r * τ)) * gaussianPDFReal 0 1 (bsd2 S K r σ τ) / + (K * σ * Real.sqrt τ) := by + have h_exp_nn : 0 ≤ Real.exp (-(r * τ)) := (Real.exp_pos _).le + have h_pdf_nn : 0 ≤ gaussianPDFReal 0 1 (bsd2 S K r σ τ) := + gaussianPDFReal_nonneg _ _ _ + have h_num_nn : 0 ≤ Real.exp (-(r * τ)) * gaussianPDFReal 0 1 (bsd2 S K r σ τ) := + mul_nonneg h_exp_nn h_pdf_nn + have h_den_pos : 0 < K * σ * Real.sqrt τ := + mul_pos (mul_pos hK hσ) (Real.sqrt_pos.mpr hτ) + exact div_nonneg h_num_nn h_den_pos.le + +/-! ## Theta and put-side sign constraints -/ + +/-- **Call theta sign**: for `S, K, σ ≥ 0` and `r ≥ 0` the formula +`σ S ϕ(d₁)/(2√τ) + r K e^{−rτ} Φ(d₂)`, which is `∂_τ V` by `hasDerivAt_bsV_tau` (for +`K, σ, S, τ > 0`), is `≥ 0`; i.e. the calendar theta `Θ = −∂_τ V` of a call on a +non-dividend-paying stock is `≤ 0`. -/ +theorem bsV_theta_tau_nonneg {S K r σ τ : ℝ} (hS : 0 ≤ S) (hK : 0 ≤ K) (hr : 0 ≤ r) + (hσ : 0 ≤ σ) : + 0 ≤ σ * S * gaussianPDFReal 0 1 (bsd1 S K r σ τ) / (2 * Real.sqrt τ) + + r * K * Real.exp (-(r * τ)) * Phi (bsd2 S K r σ τ) := by + have := gaussianPDFReal_nonneg 0 1 (bsd1 S K r σ τ) + have := Phi_nonneg (bsd2 S K r σ τ) + positivity + +/-- **Put delta is non-positive**: `Φ(d₁) − 1 ≤ 0`, the formula that is `∂_S P` by +`hasDerivAt_bsP_S`. -/ +theorem bsP_delta_nonpos (S K r σ τ : ℝ) : Phi (bsd1 S K r σ τ) - 1 ≤ 0 := + sub_nonpos.mpr (bsV_delta_le_one S K r σ τ) + +/-- **Put rho is non-positive**: `∂_r P = −K τ e^{−rτ} Φ(−d₂) ≤ 0` for `K ≥ 0` and `τ ≥ 0` +(the formula is `∂_r P` by `hasDerivAt_bsP_r`). -/ +theorem bsP_rho_nonpos {K τ : ℝ} (hK : 0 ≤ K) (hτ : 0 ≤ τ) (S r σ : ℝ) : + -(K * τ * Real.exp (-(r * τ)) * Phi (-bsd2 S K r σ τ)) ≤ 0 := by + have := Phi_nonneg (-bsd2 S K r σ τ) + exact neg_nonpos.mpr (by positivity) + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/HeynenKatTwoAssetBarrier.lean b/LeanPool/MathFin/Models/BlackScholes/HeynenKatTwoAssetBarrier.lean new file mode 100644 index 0000000000..7e4e209b25 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/HeynenKatTwoAssetBarrier.lean @@ -0,0 +1,259 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Gaussian.BivariateNormalCDF +public import LeanPool.MathFin.Models.BlackScholes.PutGreeks + +/-! +# Heynen & Kat two-asset barrier option: the closed form + +A barrier option on asset 1, struck at `X`, but **knocked out by asset 2** crossing a barrier +`H`: R. Heynen and H. Kat, "Crossing barriers", *Risk* 7(6) (1994), in the cost-of-carry form +of E. G. Haug, *The Complete Guide to Option Pricing Formulas*, 2nd ed., McGraw-Hill (2007). +Needs the bivariate normal CDF (same substrate as `StulzTwoAssetRainbow.lean`). + +With `μ(b, σ) = b − σ²/2` (`hkMu`) and, for asset 1 against strike `X` and asset 2 against +barrier `H`, + + `d₁ = (log(S₁/X) + (μ(b₁,σ₁) + σ₁²)T) / (σ₁√T)`, `d₂ = d₁ − σ₁√T`, + `d₃ = d₁ + 2ρ·log(H/S₂)/(σ₂√T)`, `d₄ = d₂ + 2ρ·log(H/S₂)/(σ₂√T)`, + `e₁ = (log(H/S₂) − (μ(b₂,σ₂) + ρσ₁σ₂)T) / (σ₂√T)`, `e₂ = e₁ + ρσ₁√T`, + `e₃ = e₁ − 2·log(H/S₂)/(σ₂√T)`, `e₄ = e₂ − 2·log(H/S₂)/(σ₂√T)`, + +(so `d₁` carries the drift `b₁ + σ₁²/2`, the standard Black–Scholes `d₁`), the knock-out value +(`heynenKatA`, `A(η, φ)`; `η = 1` call / `η = -1` put, `φ = -1` down / `φ = 1` up) is + + `A(η,φ) = ηS₁e^{(b₁−r)T}(N₂(ηd₁,φe₁;−ηφρ) − e^{2(μ(b₂,σ₂)+ρσ₁σ₂)log(H/S₂)/σ₂²}N₂(ηd₃,φe₃;−ηφρ))` + `− ηXe^{−rT}(N₂(ηd₂,φe₂;−ηφρ) − e^{2μ(b₂,σ₂)log(H/S₂)/σ₂²}N₂(ηd₄,φe₄;−ηφρ))`, + +and the four knock-out prices are `A(1,-1)` (down-out call), `A(1,1)` (up-out call), +`A(-1,-1)` (down-out put), `A(-1,1)` (up-out put). + +## Main definitions + +* `hkMu`: the risk-neutral log-drift `μ(b, σ) = b − σ²/2`. +* `hkD1`, `hkD2`, `hkD3`, `hkD4`, `hkE1`, `hkE2`, `hkE3`, `hkE4`: the arguments `d₁, …, d₄`, + `e₁, …, e₄` of the bivariate normal CDFs. `d₁, d₂` are the Black–Scholes arguments of asset 1 + against the strike `X`, and `d₃, d₄, e₃, e₄` carry the barrier-reflection shifts. +* `heynenKatA`: Heynen and Kat's knock-out value `A(η, φ)` of an option on asset 1 knocked out + when asset 2 crosses the barrier `H`, as a closed-form definition. That it is a discounted + expected payoff is not proved. + +## Main results + +* `heynenKatA_rho_zero`, the module's structural result: for independent assets (`ρ = 0`) every + `N₂` factors (`bivariateNormalCDF_zero`), and the knock-out value is the one-asset + Black–Scholes value of the option on `S¹` (cost-of-carry form) times the barrier factor + `Φ(φe₁) − e^{2μ(b₂,σ₂)log(H/S₂)/σ₂²} Φ(φe₃)` of `S²`. That factor is the single-asset + reflection-principle formula for the probability that `S²` does not cross `H`; the + probabilistic reading is not proved here, and the comparison with the one-asset formula + (which checks `e₁`, `e₃` and the reflection exponent) is by inspection — that formula is not + in the library. +* `heynenKatA_call_rho_zero_eq_bsV`, `heynenKatA_put_rho_zero_eq_bsP`: at `ρ = 0` and + `b₁ = r` (asset 1 pays no dividend), that one-asset factor is the library's Black–Scholes + call `bsV` (put `bsP`), since `hkD1`, `hkD2` are then `bsd1`, `bsd2`. So the independent + knock-out value is `bsV · (barrier factor)`; the barrier factor is still a transcription. +* `heynenKat_downOut_add_upOut`: for a fixed option type `η` (`η² = 1`) and `ρ² ≤ 1`, the + down-out and up-out values sum to a closed form with no `N₂` left: each pair + `N₂(ηdᵢ, φeᵢ; −ηφρ)`, `φ = ±1`, collapses via `bivariateNormalCDF_flip_snd` to `Φ(ηdᵢ)`. + It holds for any arguments `dᵢ, eᵢ`, so it + checks only that `φ` enters as `(φeᵢ, −ηφρ)`; and the sum has no payoff meaning, since the two + formulas apply to the disjoint regimes `S₂ > H` and `S₂ < H`. + +**Scope.** This module transcribes the closed form and proves the two identities above; it does +not derive the formula as a discounted expected payoff. That needs the joint law of one GBM and +the running extremum of a correlated second one, which the library does not have (the discrete +reflection principle is `Models/Binomial/BarrierReflection.lean`). Knock-in values are not stated: +they +follow from in–out parity (`knockIn_add_knockOut_eq_vanilla`, +`Models/BlackScholes/BarrierParity.lean`) +once `heynenKatA` is identified with a discounted expected payoff, which this module does not do. + +## References + +* [R. Heynen and H. Kat, *Crossing barriers*][HeynenKat1994a] + +## Tags + +two-asset barrier option, Heynen–Kat, bivariate normal, knock-out barrier, exotic option, +cost of carry, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- **Risk-neutral log-drift** `μ(b, σ) = b − σ²/2`. -/ +noncomputable def hkMu (b σ : ℝ) : ℝ := b - σ ^ 2 / 2 + +/-- **`d₁`**: the standard BS `d₁` of asset 1 against strike `X` at cost-of-carry `b₁`. -/ +noncomputable def hkD1 (S1 X b1 σ1 T : ℝ) : ℝ := + (Real.log (S1 / X) + (hkMu b1 σ1 + σ1 ^ 2) * T) / (σ1 * Real.sqrt T) + +/-- **`d₂` = `d₁ − σ₁√T`**. -/ +noncomputable def hkD2 (S1 X b1 σ1 T : ℝ) : ℝ := + hkD1 S1 X b1 σ1 T - σ1 * Real.sqrt T + +/-- **`d₃`**: `d₁` shifted by the asset-2/barrier correlation term. -/ +noncomputable def hkD3 (S1 X H S2 b1 σ1 σ2 ρ T : ℝ) : ℝ := + hkD1 S1 X b1 σ1 T + 2 * ρ * Real.log (H / S2) / (σ2 * Real.sqrt T) + +/-- **`d₄`**: `d₂` shifted by the same correlation term as `d₃`. -/ +noncomputable def hkD4 (S1 X H S2 b1 σ1 σ2 ρ T : ℝ) : ℝ := + hkD2 S1 X b1 σ1 T + 2 * ρ * Real.log (H / S2) / (σ2 * Real.sqrt T) + +/-- **`e₁`**: the "distance" of the barrier `H` from asset 2, at cost-of-carry `b₂`, correlation +`ρ` to asset 1. -/ +noncomputable def hkE1 (H S2 b2 σ1 σ2 ρ T : ℝ) : ℝ := + (Real.log (H / S2) - (hkMu b2 σ2 + ρ * σ1 * σ2) * T) / (σ2 * Real.sqrt T) + +/-- **`e₂` = `e₁ + ρσ₁√T`**. -/ +noncomputable def hkE2 (H S2 b2 σ1 σ2 ρ T : ℝ) : ℝ := + hkE1 H S2 b2 σ1 σ2 ρ T + ρ * σ1 * Real.sqrt T + +/-- **`e₃`**: `e₁` shifted by the barrier reflection term. -/ +noncomputable def hkE3 (H S2 b2 σ1 σ2 ρ T : ℝ) : ℝ := + hkE1 H S2 b2 σ1 σ2 ρ T - 2 * Real.log (H / S2) / (σ2 * Real.sqrt T) + +/-- **`e₄`**: `e₂` shifted by the same barrier reflection term as `e₃`. -/ +noncomputable def hkE4 (H S2 b2 σ1 σ2 ρ T : ℝ) : ℝ := + hkE2 H S2 b2 σ1 σ2 ρ T - 2 * Real.log (H / S2) / (σ2 * Real.sqrt T) + +/-- **Heynen & Kat's knock-out value `A(η, φ)`**, as a closed-form definition (that it is the +discounted expected payoff is not proved here). `η = 1` is a call on asset 1, `η = -1` a put; +`φ = -1` is a down-barrier (on asset 2), `φ = 1` an up-barrier. The four knock-out prices are +`A(1,-1)`, `A(1,1)`, `A(-1,-1)`, `A(-1,1)`. -/ +noncomputable def heynenKatA (eta phi S1 S2 X H T r b1 b2 σ1 σ2 ρ : ℝ) : ℝ := + let d1 := hkD1 S1 X b1 σ1 T + let d2 := hkD2 S1 X b1 σ1 T + let d3 := hkD3 S1 X H S2 b1 σ1 σ2 ρ T + let d4 := hkD4 S1 X H S2 b1 σ1 σ2 ρ T + let e1 := hkE1 H S2 b2 σ1 σ2 ρ T + let e2 := hkE2 H S2 b2 σ1 σ2 ρ T + let e3 := hkE3 H S2 b2 σ1 σ2 ρ T + let e4 := hkE4 H S2 b2 σ1 σ2 ρ T + let mu2 := hkMu b2 σ2 + eta * S1 * Real.exp ((b1 - r) * T) * + (bivariateNormalCDF (eta * d1) (phi * e1) (-eta * phi * ρ) - + Real.exp (2 * (mu2 + ρ * σ1 * σ2) * Real.log (H / S2) / σ2 ^ 2) * + bivariateNormalCDF (eta * d3) (phi * e3) (-eta * phi * ρ)) - + eta * X * Real.exp (-(r * T)) * + (bivariateNormalCDF (eta * d2) (phi * e2) (-eta * phi * ρ) - + Real.exp (2 * mu2 * Real.log (H / S2) / σ2 ^ 2) * + bivariateNormalCDF (eta * d4) (phi * e4) (-eta * phi * ρ)) + +/-- **Independent assets factor.** At `ρ = 0` every `N₂` in `A(η, φ)` factors +(`bivariateNormalCDF_zero`), the correlation shifts in `d₃`, `d₄`, `e₂` and the first exponent +vanish, and the knock-out value is the one-asset Black–Scholes value of the option on `S¹` +(cost-of-carry form) times the barrier factor `Φ(φe₁) − e^{2μ₂ log(H/S₂)/σ₂²} Φ(φe₃)` of `S²`, +the single-asset reflection-principle formula for the probability that `S²` does not cross `H` +(that probabilistic reading is not proved here). -/ +theorem heynenKatA_rho_zero (eta phi S1 S2 X H T r b1 b2 σ1 σ2 : ℝ) : + heynenKatA eta phi S1 S2 X H T r b1 b2 σ1 σ2 0 = + (eta * S1 * Real.exp ((b1 - r) * T) * Phi (eta * hkD1 S1 X b1 σ1 T) - + eta * X * Real.exp (-(r * T)) * Phi (eta * hkD2 S1 X b1 σ1 T)) * + (Phi (phi * hkE1 H S2 b2 σ1 σ2 0 T) - + Real.exp (2 * hkMu b2 σ2 * Real.log (H / S2) / σ2 ^ 2) * + Phi (phi * hkE3 H S2 b2 σ1 σ2 0 T)) := by + simp only [heynenKatA, hkD3, hkD4, hkE2, hkE3, hkE4, mul_zero, zero_mul, zero_div, add_zero, + bivariateNormalCDF_zero] + ring + +/-- **Down-out and up-out collapse to a bivariate-CDF-free form.** For a fixed option type +`η ∈ {-1,1}` and a correlation with `ρ² ≤ 1`, summing the down-barrier (`φ=-1`) and +up-barrier (`φ=1`) knock-out values pairs every `N₂(ηdᵢ,φeᵢ;−ηφρ)` with its `φ`-flipped +partner via `bivariateNormalCDF_flip_snd` +(`N₂(a,b;r)+N₂(a,-b;-r)=Φ(a)`, applied at `a = ηdᵢ`, `b = eᵢ`, `r = -ηρ`), collapsing all four +`N₂` pairs to `Φ(ηd₁), Φ(ηd₂), Φ(ηd₃), Φ(ηd₄)` simultaneously. It holds for any arguments +`dᵢ, eᵢ`: it checks only that `φ` enters as `(φeᵢ, −ηφρ)`, and the sum has no payoff meaning +(the two formulas apply to the disjoint regimes `S₂ > H` and `S₂ < H`). -/ +theorem heynenKat_downOut_add_upOut (S1 S2 X H T r b1 b2 σ1 σ2 : ℝ) {eta ρ : ℝ} + (heta : eta ^ 2 = 1) (hρ : ρ ^ 2 ≤ 1) : + heynenKatA eta (-1) S1 S2 X H T r b1 b2 σ1 σ2 ρ + + heynenKatA eta 1 S1 S2 X H T r b1 b2 σ1 σ2 ρ = + eta * S1 * Real.exp ((b1 - r) * T) * + (Phi (eta * hkD1 S1 X b1 σ1 T) - + Real.exp (2 * (hkMu b2 σ2 + ρ * σ1 * σ2) * Real.log (H / S2) / σ2 ^ 2) * + Phi (eta * hkD3 S1 X H S2 b1 σ1 σ2 ρ T)) - + eta * X * Real.exp (-(r * T)) * + (Phi (eta * hkD2 S1 X b1 σ1 T) - + Real.exp (2 * hkMu b2 σ2 * Real.log (H / S2) / σ2 ^ 2) * + Phi (eta * hkD4 S1 X H S2 b1 σ1 σ2 ρ T)) := by + have heρ : (-(eta * ρ)) ^ 2 ≤ 1 := by + rw [neg_sq, mul_pow, heta, one_mul]; exact hρ + set d1 := hkD1 S1 X b1 σ1 T with hd1 + set d2 := hkD2 S1 X b1 σ1 T with hd2 + set d3 := hkD3 S1 X H S2 b1 σ1 σ2 ρ T with hd3 + set d4 := hkD4 S1 X H S2 b1 σ1 σ2 ρ T with hd4 + set e1 := hkE1 H S2 b2 σ1 σ2 ρ T with he1 + set e2 := hkE2 H S2 b2 σ1 σ2 ρ T with he2 + set e3 := hkE3 H S2 b2 σ1 σ2 ρ T with he3 + set e4 := hkE4 H S2 b2 σ1 σ2 ρ T with he4 + have h1 := bivariateNormalCDF_flip_snd (eta * d1) e1 heρ + have h2 := bivariateNormalCDF_flip_snd (eta * d2) e2 heρ + have h3 := bivariateNormalCDF_flip_snd (eta * d3) e3 heρ + have h4 := bivariateNormalCDF_flip_snd (eta * d4) e4 heρ + simp only [neg_neg] at h1 h2 h3 h4 + -- Unfolding `heynenKatA` at the literal `phi := 1 / -1` substitutes `1 * e_i`, `-1 * e_i`, + -- `-eta * 1 * ρ`, `-eta * (-1) * ρ` for the bivariate-CDF arguments: these are only RING-equal + -- (not defeq) to the clean `e_i` / `-e_i` / `-(eta * ρ)` / `eta * ρ` forms in `h1`-`h4`, so the + -- explicit `← hd_i`/`← he_i` fold-back and sign-normalizing lemmas below are needed before + -- `linear_combination`'s atom matching can see the two sides as the same bivariate-CDF calls. + simp only [heynenKatA, ← hd1, ← he1, neg_mul, one_mul, mul_neg, mul_one, neg_neg, hkMu, ← hd3, + ← he3, ← hd2, ← he2, ← hd4, ← he4] + linear_combination (eta * S1 * Real.exp ((b1 - r) * T)) * h1 + + (-(eta * X * Real.exp (-(r * T)))) * h2 + + (-(eta * S1 * Real.exp ((b1 - r) * T) * + Real.exp (2 * (b2 - σ2 ^ 2 / 2 + ρ * σ1 * σ2) * Real.log (H / S2) / σ2 ^ 2))) * h3 + + (eta * X * Real.exp (-(r * T)) * + Real.exp (2 * (b2 - σ2 ^ 2 / 2) * Real.log (H / S2) / σ2 ^ 2)) * h4 + +/-! ### The independent case through the library's Black–Scholes prices -/ + +/-- At cost of carry `b₁ = r`, Heynen–Kat's `d₁` is the Black–Scholes `bsd1`. -/ +lemma hkD1_eq_bsd1 (S X r σ T : ℝ) : hkD1 S X r σ T = bsd1 S X r σ T := by + unfold hkD1 hkMu bsd1 + ring + +/-- At cost of carry `b₁ = r`, Heynen–Kat's `d₂` is the Black–Scholes `bsd2`. -/ +lemma hkD2_eq_bsd2 (S X r σ T : ℝ) : hkD2 S X r σ T = bsd2 S X r σ T := by + unfold hkD2 bsd2 + rw [hkD1_eq_bsd1] + +/-- **Independent assets, call: Black–Scholes call times barrier factor.** At `ρ = 0` and +`b₁ = r`, the Heynen–Kat knock-out call value is the Black–Scholes call `bsV X r σ₁ S₁ T` +on asset 1 times the closed-form barrier factor `Φ(φe₁) − e^{2μ₂ log(H/S₂)/σ₂²}Φ(φe₃)` of +asset 2 (`heynenKatA_rho_zero` with `hkD1_eq_bsd1`, `hkD2_eq_bsd2`). Neither side is shown to +be a discounted expected payoff. -/ +theorem heynenKatA_call_rho_zero_eq_bsV (phi S1 S2 X H T r b2 σ1 σ2 : ℝ) : + heynenKatA 1 phi S1 S2 X H T r r b2 σ1 σ2 0 = + bsV X r σ1 S1 T * + (Phi (phi * hkE1 H S2 b2 σ1 σ2 0 T) - + Real.exp (2 * hkMu b2 σ2 * Real.log (H / S2) / σ2 ^ 2) * + Phi (phi * hkE3 H S2 b2 σ1 σ2 0 T)) := by + rw [heynenKatA_rho_zero, hkD1_eq_bsd1, hkD2_eq_bsd2, bsV, sub_self, zero_mul, Real.exp_zero] + simp only [one_mul, mul_one] + +/-- **Independent assets, put: Black–Scholes put times barrier factor.** At `ρ = 0` and +`b₁ = r`, the Heynen–Kat knock-out put value is the Black–Scholes put `bsP X r σ₁ S₁ T` on +asset 1 times the same barrier factor of asset 2. Neither side is shown to be a discounted +expected payoff. -/ +theorem heynenKatA_put_rho_zero_eq_bsP (phi S1 S2 X H T r b2 σ1 σ2 : ℝ) : + heynenKatA (-1) phi S1 S2 X H T r r b2 σ1 σ2 0 = + bsP X r σ1 S1 T * + (Phi (phi * hkE1 H S2 b2 σ1 σ2 0 T) - + Real.exp (2 * hkMu b2 σ2 * Real.log (H / S2) / σ2 ^ 2) * + Phi (phi * hkE3 H S2 b2 σ1 σ2 0 T)) := by + rw [heynenKatA_rho_zero, hkD1_eq_bsd1, hkD2_eq_bsd2, bsP, sub_self, zero_mul, Real.exp_zero] + simp only [neg_mul, one_mul, mul_one] + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/HigherGreeks.lean b/LeanPool/MathFin/Models/BlackScholes/HigherGreeks.lean new file mode 100644 index 0000000000..b200b940fe --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/HigherGreeks.lean @@ -0,0 +1,218 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.PDE + +/-! +# Higher-order Black–Scholes Greeks + +For the European call price `V(S, σ, τ) = S Φ(d₁) − K e^{-rτ} Φ(d₂)`, the +second- and third-order Greeks, each stated for the price itself: + +* **Vanna**: `∂/∂S (∂V/∂σ) = -ϕ(d₁) · d₂ / σ` (`hasDerivAt_S_deriv_bsV_sigma`). +* **Volga (aka vomma)**: `∂²V/∂σ² = vega · d₁ · d₂ / σ` (`hasDerivAt_deriv_bsV_sigma`). +* **Charm**: `∂/∂τ (∂V/∂S) = ϕ(d₁) · ((r + σ²/2)τ − log(S/K)) / (2στ√τ)` + (`hasDerivAt_tau_deriv_bsV_S`). +* **Speed**: `∂³V/∂S³ = -ϕ(d₁) (d₁ + σ√τ) / (S² σ² τ)` (`hasDerivAt_deriv_deriv_bsV_S`). + +Each comes in two steps. A formula lemma (`hasDerivAt_bsV_vanna`, …) differentiates +the closed form of the lower-order Greek. `hasDerivAt_deriv_of_eventually` (volga, speed) +or its mixed-partial form `hasDerivAt_deriv_param_of_eventually` (vanna, charm) then makes +it a statement about the price, since that closed form is the lower-order derivative near +the point. + +With `ϕ'(z) = -z · ϕ(z)`, each formula is one chain rule plus one product, quotient or +scalar rule. Volga's uses the shortcut `∂_σ d₁ = -d₂/σ` (`hasDerivAt_bsd1_sigma_clean` +below), which compresses an otherwise messy quotient-rule expression; vanna's uses +`∂_S d₁` and collapses via `σ√τ − d₁ = -d₂`. + +## Main results + +All for `K, σ, S, τ > 0`. + +* `hasDerivAt_S_deriv_bsV_sigma`: vanna, `∂/∂S (∂V/∂σ) = −ϕ(d₁) d₂ / σ`. +* `hasDerivAt_deriv_bsV_sigma`: volga, `∂²V/∂σ² = S ϕ(d₁) √τ d₁ d₂ / σ`. +* `hasDerivAt_tau_deriv_bsV_S`: charm, `∂/∂τ (∂V/∂S) = ϕ(d₁) ((r + σ²/2)τ − log(S/K)) / (2στ√τ)`. +* `hasDerivAt_deriv_deriv_bsV_S`: speed, `∂³V/∂S³ = −ϕ(d₁) (d₁ + σ√τ) / (S² σ² τ)`. +* `hasDerivAt_bsV_SSS`: the `S`-derivative of the gamma formula `ϕ(d₁) / (S σ √τ)`, which is + the speed formula. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 19.4 +* [Wystup (2002)][Wystup2002] + +## Tags + +vanna, volga, vomma, speed, third-order Greeks, higher-order sensitivities, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- Clean form: `∂_σ d₁ = -d₂/σ`. Algebraic shortcut for the quotient-rule +expression in `hasDerivAt_bsd1_sigma`. Useful for higher-order Greeks. -/ +private lemma hasDerivAt_bsd1_sigma_clean (S K r : ℝ) {σ τ : ℝ} + (hσ : 0 < σ) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ bsd1 S K r s τ) (-(bsd2 S K r σ τ) / σ) σ := by + have h := hasDerivAt_bsd1_sigma S K r hσ hτ + convert h using 1 + have h_sqrt_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_ne : Real.sqrt τ ≠ 0 := h_sqrt_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have h_sqrt_sq : Real.sqrt τ ^ 2 = τ := Real.sq_sqrt hτ.le + rw [bsd2, bsd1] + field_simp + rw [show Real.sqrt τ ^ 2 = τ from h_sqrt_sq] + ring + +/-- **The vanna formula**: the S-derivative of the vega formula is `-ϕ(d₁) · d₂ / σ`. The +mixed partial of the price itself is `hasDerivAt_S_deriv_bsV_sigma`. + +Strategy: vega-as-function-of-S is `S · ϕ(d₁(S)) · √τ`. Product rule: +`d/dS = ϕ(d₁) √τ + S · ϕ'(d₁) · ∂_S d₁ · √τ`. With `ϕ'(d₁) = -d₁ ϕ(d₁)` and +`∂_S d₁ = 1/(S σ √τ)`, the S's cancel: +`= ϕ(d₁) √τ - d₁ ϕ(d₁) / σ = ϕ(d₁) (σ√τ − d₁) / σ = -ϕ(d₁) d₂ / σ`. -/ +private lemma hasDerivAt_bsV_vanna {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ s * gaussianPDFReal 0 1 (bsd1 s K r σ τ) * Real.sqrt τ) + (-(gaussianPDFReal 0 1 (bsd1 S K r σ τ) * bsd2 S K r σ τ / σ)) S := by + have h_sqrt_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_ne : Real.sqrt τ ≠ 0 := h_sqrt_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have hS_ne : S ≠ 0 := hS.ne' + have h_d1_S := hasDerivAt_bsd1_S (r := r) hK hσ hτ hS + have h_pdf_d1 := (hasDerivAt_gaussianPDFReal_zero_one (bsd1 S K r σ τ)).comp S h_d1_S + have h_id : HasDerivAt (fun s : ℝ ↦ s) 1 S := hasDerivAt_id S + have h_prod := h_id.mul h_pdf_d1 + have h_full := h_prod.mul_const (Real.sqrt τ) + convert h_full using 1 <;> try rfl + simp only [Function.comp] + rw [show bsd2 S K r σ τ = bsd1 S K r σ τ - σ * Real.sqrt τ from by rw [bsd2]] + field_simp + ring + +/-- **Vanna**: `∂/∂S (∂V/∂σ) = -ϕ(d₁) · d₂ / σ`, for the call price itself: vega +`S · ϕ(d₁) · √τ` is `∂V/∂σ` at every spot `S > 0` (`hasDerivAt_bsV_sigma`), and its +S-derivative is the vanna formula (`hasDerivAt_bsV_vanna`). -/ +theorem hasDerivAt_S_deriv_bsV_sigma {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ deriv (fun σ' ↦ bsV K r σ' s τ) σ) + (-(gaussianPDFReal 0 1 (bsd1 S K r σ τ) * bsd2 S K r σ τ / σ)) S := + hasDerivAt_deriv_param_of_eventually + ((eventually_gt_nhds hS).mono fun _ hs ↦ hasDerivAt_bsV_sigma hK hs hσ hτ) + (hasDerivAt_bsV_vanna hK hσ hS hτ) + +/-- **The volga (vomma) formula**: the σ-derivative of the vega formula is +`vega · d₁ · d₂ / σ`. The second σ-derivative of the price itself is +`hasDerivAt_deriv_bsV_sigma`. + +Strategy: vega-as-function-of-σ is `S · ϕ(d₁(σ)) · √τ`. Chain rule via the +clean derivative `∂_σ d₁ = -d₂/σ` (above) and `ϕ'(d₁) = -d₁ ϕ(d₁)`: +`d/dσ[ϕ(d₁(σ))] = -d₁ ϕ(d₁) · (-d₂/σ) = d₁ d₂ ϕ(d₁) / σ`. Multiply by +constants S and √τ. -/ +private lemma hasDerivAt_bsV_volga {K r S σ τ : ℝ} (hS : 0 < S) (hσ : 0 < σ) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ S * gaussianPDFReal 0 1 (bsd1 S K r s τ) * Real.sqrt τ) + (S * gaussianPDFReal 0 1 (bsd1 S K r σ τ) * Real.sqrt τ + * bsd1 S K r σ τ * bsd2 S K r σ τ / σ) σ := by + have hσ_ne : σ ≠ 0 := hσ.ne' + have h_d1_σ := hasDerivAt_bsd1_sigma_clean S K r hσ hτ + have h_pdf_d1 := (hasDerivAt_gaussianPDFReal_zero_one (bsd1 S K r σ τ)).comp σ h_d1_σ + have h_S := h_pdf_d1.const_mul S + have h_full := h_S.mul_const (Real.sqrt τ) + convert h_full using 1 <;> try rfl + field_simp + +/-- **Volga (vomma)**: `∂²V/∂σ² = vega · d₁ · d₂ / σ`, for the call price itself: vega is +`∂V/∂σ` at every volatility `σ > 0` (`hasDerivAt_bsV_sigma`), and its σ-derivative is the +volga formula (`hasDerivAt_bsV_volga`). -/ +theorem hasDerivAt_deriv_bsV_sigma {K r : ℝ} (hK : 0 < K) {S σ τ : ℝ} (hS : 0 < S) + (hσ : 0 < σ) (hτ : 0 < τ) : + HasDerivAt (deriv fun σ' ↦ bsV K r σ' S τ) + (S * gaussianPDFReal 0 1 (bsd1 S K r σ τ) * Real.sqrt τ * bsd1 S K r σ τ * + bsd2 S K r σ τ / σ) σ := + hasDerivAt_deriv_of_eventually + ((eventually_gt_nhds hσ).mono fun _ hσ' ↦ hasDerivAt_bsV_sigma hK hS hσ' hτ) + (hasDerivAt_bsV_volga hS hσ hτ) + +/-- **The charm formula**: the τ-derivative of the delta formula `Φ(d₁)` is +`ϕ(d₁) · ((r + σ²/2)τ − log(S/K)) / (2στ√τ)`, by the chain rule: `∂_τ d₁` already has a clean +closed form, so the magic identity is not needed. The mixed partial of the price itself is +`hasDerivAt_tau_deriv_bsV_S`. -/ +private lemma hasDerivAt_bsV_charm {K r σ : ℝ} (hσ : 0 < σ) + {S τ : ℝ} (hτ : 0 < τ) : + HasDerivAt (fun t ↦ Phi (bsd1 S K r σ t)) + (gaussianPDFReal 0 1 (bsd1 S K r σ τ) + * (((r + σ ^ 2 / 2) * τ - Real.log (S / K)) / (2 * σ * τ * Real.sqrt τ))) τ := + (hasDerivAt_Phi (bsd1 S K r σ τ)).comp τ (hasDerivAt_bsd1_tau S K r σ hσ hτ) + +/-- **Charm**: `∂/∂τ (∂V/∂S) = ϕ(d₁) · ((r + σ²/2)τ − log(S/K)) / (2στ√τ)`, for the call +price itself: the delta `Φ(d₁)` is `∂V/∂S` at every maturity `τ > 0` (`hasDerivAt_bsV_S`), +and its τ-derivative is the charm formula (`hasDerivAt_bsV_charm`). -/ +theorem hasDerivAt_tau_deriv_bsV_S {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (fun t ↦ deriv (fun s ↦ bsV K r σ s t) S) + (gaussianPDFReal 0 1 (bsd1 S K r σ τ) * + (((r + σ ^ 2 / 2) * τ - Real.log (S / K)) / (2 * σ * τ * Real.sqrt τ))) τ := + hasDerivAt_deriv_param_of_eventually + ((eventually_gt_nhds hτ).mono fun _ ht ↦ hasDerivAt_bsV_S hK hσ hS ht) + (hasDerivAt_bsV_charm hσ hτ) + +/-- **The speed formula**: the S-derivative of the gamma formula is +`-ϕ(d₁) (d₁ + σ√τ) / (S² σ² τ)`. The third derivative of the price itself is +`hasDerivAt_deriv_deriv_bsV_S`. + +Gamma is the quotient `ϕ(d₁(S)) / (S σ √τ)` (`hasDerivAt_deriv_bsV_S`), so speed is +one quotient rule away. Numerator derivative is `ϕ'(d₁) ∂_S d₁ = -d₁ ϕ(d₁)/(S σ √τ)`; +denominator derivative is the constant `σ √τ`. The two contributions carry `d₁` +and `σ√τ` respectively, which is where the `d₁ + σ√τ` numerator comes from — +and note the denominator is `S² σ² τ`, not `S² σ √τ`. -/ +lemma hasDerivAt_bsV_SSS {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ gaussianPDFReal 0 1 (bsd1 s K r σ τ) / (s * σ * Real.sqrt τ)) + (-(gaussianPDFReal 0 1 (bsd1 S K r σ τ) * (bsd1 S K r σ τ + σ * Real.sqrt τ) + / (S ^ 2 * σ ^ 2 * τ))) S := by + have h_sqrt_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_ne : Real.sqrt τ ≠ 0 := h_sqrt_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have hS_ne : S ≠ 0 := hS.ne' + have h_num := (hasDerivAt_gaussianPDFReal_zero_one (bsd1 S K r σ τ)).comp S + (hasDerivAt_bsd1_S (r := r) hK hσ hτ hS) + have h_den : HasDerivAt (fun s : ℝ ↦ s * σ * Real.sqrt τ) (σ * Real.sqrt τ) S := by + simpa using ((hasDerivAt_id S).mul_const σ).mul_const (Real.sqrt τ) + -- Pin the quotient's expected type so `.div` elaborates against the goal's + -- instances rather than handing back a Pi-`/` of functions. + have h : HasDerivAt (fun s ↦ gaussianPDFReal 0 1 (bsd1 s K r σ τ) / (s * σ * Real.sqrt τ)) + ((-(bsd1 S K r σ τ * gaussianPDFReal 0 1 (bsd1 S K r σ τ)) * (1 / (S * σ * Real.sqrt τ)) + * (S * σ * Real.sqrt τ) + - gaussianPDFReal 0 1 (bsd1 S K r σ τ) * (σ * Real.sqrt τ)) + / (S * σ * Real.sqrt τ) ^ 2) S := + h_num.div h_den (by positivity) + convert h using 1 + rw [show S ^ 2 * σ ^ 2 * τ = (S * σ * Real.sqrt τ) ^ 2 from by + rw [mul_pow, mul_pow, Real.sq_sqrt hτ.le]] + field_simp + ring + +/-- **Speed**: `∂³V/∂S³ = -ϕ(d₁) (d₁ + σ√τ) / (S² σ² τ)`, for the call price itself: the +genuine gamma `hasDerivAt_deriv_bsV_S` holds on all of `S > 0`, and the derivative of its +formula is `hasDerivAt_bsV_SSS`. -/ +theorem hasDerivAt_deriv_deriv_bsV_S {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (deriv (deriv fun s ↦ bsV K r σ s τ)) + (-(gaussianPDFReal 0 1 (bsd1 S K r σ τ) * (bsd1 S K r σ τ + σ * Real.sqrt τ) / + (S ^ 2 * σ ^ 2 * τ))) S := + hasDerivAt_deriv_of_eventually + ((eventually_gt_nhds hS).mono fun _ hs ↦ hasDerivAt_deriv_bsV_S hK hσ hs hτ) + (hasDerivAt_bsV_SSS hK hσ hS hτ) + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/ImpliedVolatility.lean b/LeanPool/MathFin/Models/BlackScholes/ImpliedVolatility.lean new file mode 100644 index 0000000000..b7cc29bdfe --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/ImpliedVolatility.lean @@ -0,0 +1,217 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho, Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.PutGreeks +public import LeanPool.MathFin.Probability.Gaussian.NormalTail +public import Mathlib.RingTheory.Flat.TorsionFree +public import Mathlib.RingTheory.Smooth.Flat + +/-! +# Implied volatility: uniqueness, and existence above a reference volatility + +The **implied volatility** of a market option price `c` is the value of `σ` +for which the Black–Scholes price equals `c`. Existence requires the option +price to lie in the no-arbitrage range; **uniqueness** follows from strict +monotonicity of the BS call price in `σ`. + +Strict monotonicity in `σ` follows from **positive vega**: by +`hasDerivAt_bsV_sigma`, `∂_σ V = S · ϕ(d_1) · √τ`. For `S > 0, T > 0`, this +is strictly positive (since `ϕ > 0`). A function with positive derivative +on an interval is strictly monotone there, hence injective. + +As `σ → ∞` the call price tends to the spot. So a price above the Black–Scholes +price at some `σ₀ > 0` and below the spot has an implied volatility, above `σ₀`. +This is the existence result `JumpImpliedVol.lean` needs. Existence for every +price in the no-arbitrage range would also need the `σ → 0` limit, which is not +proved. + +## Main definitions + +* `newtonStep`: the Newton–Raphson step `σ − f σ / f' σ`. + +## Main results + +* `bsV_strictMonoOn_sigma`: the BS call price `σ ↦ V(K, r, σ, S, T)` is + strictly monotone on `(0, ∞)` for `K, S, T > 0`. +* `implied_volatility_unique`: as a corollary, the implied volatility is + unique whenever it exists. +* `impliedVol_put_eq_call`: under put-call parity, put and call implied volatilities coincide. +* `tendsto_bsV_sigma_atTop`: the call price tends to the spot as `σ → ∞`. +* `exists_impliedVol_gt_of_bsV_lt`: a price strictly between the Black–Scholes + price at `σ₀ > 0` and the spot has a unique positive implied volatility, and it + exceeds `σ₀`. + +## References + +* [J. Gatheral, *The Volatility Surface: A Practitioner's Guide*][Gatheral2006] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 19.10 +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], 4.5 + +## Tags + +implied volatility, uniqueness of implied volatility, strict monotonicity in volatility, +Newton step, no-arbitrage price range, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Filter MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal Topology + +/-- **Vega is strictly positive** for `S > 0, T > 0` and any `σ > 0`. -/ +lemma bsV_vega_pos {K r : ℝ} (_hK : 0 < K) + {S σ T : ℝ} (hS : 0 < S) (_hσ : 0 < σ) (hT : 0 < T) : + 0 < S * gaussianPDFReal 0 1 (bsd1 S K r σ T) * Real.sqrt T := by + have h_pdf_pos : 0 < gaussianPDFReal 0 1 (bsd1 S K r σ T) := + gaussianPDFReal_pos 0 1 _ (one_ne_zero : (1 : ℝ≥0) ≠ 0) + positivity + +/-- **The BS call price is continuous in `σ`** on `(0, ∞)`: it is differentiable +there (`hasDerivAt_bsV_sigma`). -/ +theorem bsV_continuousOn_sigma {K r T : ℝ} (hK : 0 < K) (hT : 0 < T) + {S : ℝ} (hS : 0 < S) : + ContinuousOn (fun σ ↦ bsV K r σ S T) (Set.Ioi 0) := fun _ hσ ↦ + (hasDerivAt_bsV_sigma hK hS hσ hT).continuousAt.continuousWithinAt + +/-- **The BS call price is strictly monotone in `σ`** on `(0, ∞)`. + +A direct consequence of positive vega (`hasDerivAt_bsV_sigma` + `bsV_vega_pos`) +and the mean-value theorem (`strictMonoOn_of_deriv_pos`). -/ +theorem bsV_strictMonoOn_sigma {K r T : ℝ} (hK : 0 < K) (hT : 0 < T) + {S : ℝ} (hS : 0 < S) : + StrictMonoOn (fun σ ↦ bsV K r σ S T) (Set.Ioi 0) := by + apply strictMonoOn_of_deriv_pos (convex_Ioi 0) (bsV_continuousOn_sigma hK hT hS) + · intro σ hσ_int + rw [interior_Ioi] at hσ_int + have hσ_pos : 0 < σ := hσ_int + have h_deriv := hasDerivAt_bsV_sigma (r := r) hK hS hσ_pos hT + rw [h_deriv.deriv] + exact bsV_vega_pos hK hS hσ_pos hT + +/-- **Uniqueness of implied volatility.** If two volatilities `σ₁, σ₂ ∈ (0, ∞)` +give the same BS call price, then `σ₁ = σ₂`. Direct consequence of strict +monotonicity. -/ +theorem implied_volatility_unique {K r T : ℝ} (hK : 0 < K) (hT : 0 < T) + {S : ℝ} (hS : 0 < S) {σ₁ σ₂ : ℝ} (hσ₁ : 0 < σ₁) (hσ₂ : 0 < σ₂) + (h_eq : bsV K r σ₁ S T = bsV K r σ₂ S T) : + σ₁ = σ₂ := by + exact (bsV_strictMonoOn_sigma hK hT hS).injOn hσ₁ hσ₂ h_eq + +/-- **Put and call implied volatilities coincide** (Hull §20.1). If market prices `C` and `P` +satisfy put-call parity `C − P = S − K e^{−rT}`, the call is priced by Black–Scholes at `σ_c` +and the put at `σ_p`, then `σ_c = σ_p`: by `bsP_eq_bsV` the put price at `σ_p` determines the +call price at `σ_p`, which must be `C`, and implied volatility is unique. -/ +theorem impliedVol_put_eq_call {K r T : ℝ} (hK : 0 < K) (hT : 0 < T) + {S C P σc σp : ℝ} (hS : 0 < S) (hσc : 0 < σc) (hσp : 0 < σp) + (h_parity : C - P = S - K * Real.exp (-(r * T))) + (hC : bsV K r σc S T = C) (hP : bsP K r σp S T = P) : + σc = σp := by + refine implied_volatility_unique (r := r) hK hT hS hσc hσp ?_ + rw [bsP_eq_bsV] at hP + linarith + +/-! ## Existence above a reference volatility + +As `σ → ∞`, `d₁ = (log(S/K) + rT)/(σ√T) + σ√T/2 → ∞` and `d₂ = d₁ − σ√T → −∞`, so the call +price tends to the spot. A price strictly between the Black–Scholes price at some `σ₀ > 0` and +the spot is therefore attained at a volatility above `σ₀` (intermediate value theorem), and at no +other positive volatility (`implied_volatility_unique`). -/ + +/-- `d₁` with the volatility split out, at the maturity `s²`, where `√(s²) = s`. -/ +lemma bsd1_sq_eq (S K r : ℝ) {σ s : ℝ} (hσ : σ ≠ 0) (hs : 0 < s) : + bsd1 S K r σ (s ^ 2) = (Real.log (S / K) + r * s ^ 2) / s * σ⁻¹ + s / 2 * σ := by + have hs' : s ≠ 0 := hs.ne' + rw [bsd1, Real.sqrt_sq hs.le] + generalize Real.log (S / K) = L + field_simp + ring + +/-- `d₁ = (log(S/K) + rT)/√T · σ⁻¹ + √T/2 · σ`. -/ +lemma bsd1_eq_inv_add (S K r : ℝ) {σ T : ℝ} (hσ : σ ≠ 0) (hT : 0 < T) : + bsd1 S K r σ T = (Real.log (S / K) + r * T) / Real.sqrt T * σ⁻¹ + Real.sqrt T / 2 * σ := by + have h := bsd1_sq_eq S K r hσ (Real.sqrt_pos.2 hT) + rwa [Real.sq_sqrt hT.le] at h + +/-- `d₁ → ∞` as `σ → ∞`. -/ +lemma tendsto_bsd1_sigma_atTop (S K r : ℝ) {T : ℝ} (hT : 0 < T) : + Tendsto (fun σ ↦ bsd1 S K r σ T) atTop atTop := by + have h : Tendsto (fun σ : ℝ ↦ (Real.log (S / K) + r * T) / Real.sqrt T * σ⁻¹ + + Real.sqrt T / 2 * σ) atTop atTop := + (tendsto_inv_atTop_zero.const_mul _).add_atTop + (tendsto_id.const_mul_atTop (half_pos (Real.sqrt_pos.2 hT))) + refine h.congr' ?_ + filter_upwards [eventually_gt_atTop 0] with σ hσ + exact (bsd1_eq_inv_add S K r hσ.ne' hT).symm + +/-- `d₂ → −∞` as `σ → ∞`. -/ +lemma tendsto_bsd2_sigma_atTop (S K r : ℝ) {T : ℝ} (hT : 0 < T) : + Tendsto (fun σ ↦ bsd2 S K r σ T) atTop atBot := by + have h : Tendsto (fun σ : ℝ ↦ (Real.log (S / K) + r * T) / Real.sqrt T * σ⁻¹ + + -(Real.sqrt T / 2 * σ)) atTop atBot := + (tendsto_inv_atTop_zero.const_mul _).add_atBot (tendsto_neg_atTop_atBot.comp + (tendsto_id.const_mul_atTop (half_pos (Real.sqrt_pos.2 hT)))) + refine h.congr' ?_ + filter_upwards [eventually_gt_atTop 0] with σ hσ + rw [bsd2, bsd1_eq_inv_add S K r hσ.ne' hT] + ring + +/-- **The Black–Scholes call tends to the spot as `σ → ∞`**: `S·Φ(d₁) − Ke^{−rT}·Φ(d₂) → S`, +since `d₁ → ∞` and `d₂ → −∞`. -/ +theorem tendsto_bsV_sigma_atTop (S K r : ℝ) {T : ℝ} (hT : 0 < T) : + Tendsto (fun σ ↦ bsV K r σ S T) atTop (𝓝 S) := by + have h := ((tendsto_Phi_atTop.comp (tendsto_bsd1_sigma_atTop S K r hT)).const_mul S).sub + ((tendsto_Phi_atBot.comp (tendsto_bsd2_sigma_atTop S K r hT)).const_mul + (K * Real.exp (-(r * T)))) + rw [mul_one, mul_zero, sub_zero] at h + exact h + +/-- **Implied volatility above a reference volatility.** A price `C` strictly between the +Black–Scholes price at a volatility `σ₀ > 0` and the spot has an implied volatility `σ > σ₀`, +and no other positive volatility prices to `C`. -/ +theorem exists_impliedVol_gt_of_bsV_lt {K r T S σ₀ C : ℝ} (hK : 0 < K) (hT : 0 < T) + (hS : 0 < S) (hσ₀ : 0 < σ₀) (hlo : bsV K r σ₀ S T < C) (hhi : C < S) : + ∃ σ, σ₀ < σ ∧ bsV K r σ S T = C ∧ ∀ σ' > 0, bsV K r σ' S T = C → σ' = σ := by + obtain ⟨σ₁, hC, hσ₁⟩ := (((tendsto_bsV_sigma_atTop S K r hT).eventually + (lt_mem_nhds hhi)).and (eventually_gt_atTop σ₀)).exists + have hpos : Set.Icc σ₀ σ₁ ⊆ Set.Ioi 0 := fun v hv ↦ hσ₀.trans_le hv.1 + have hCmem : C ∈ Set.Ioo (bsV K r σ₀ S T) (bsV K r σ₁ S T) := ⟨hlo, hC⟩ + obtain ⟨σ, hσ, hσC⟩ := intermediate_value_Ioo hσ₁.le + ((bsV_continuousOn_sigma (r := r) hK hT hS).mono hpos) hCmem + exact ⟨σ, hσ.1, hσC, fun σ' hσ' h ↦ + implied_volatility_unique hK hT hS hσ' (hσ₀.trans hσ.1) (h.trans hσC.symm)⟩ + +/-! ## Newton-Raphson iteration (folded from `NewtonRaphsonIV.lean`) + +The Newton iteration `σ_{n+1} = σ_n − f(σ_n)/f'(σ_n)` for root-finding. In +the BS implied-vol setting, `f(σ) = bsV(σ) − C_obs` and `f'(σ) = vega(σ) > 0` +(positive by `bsV_vega_pos`), so the iteration is well-defined for `σ > 0`. + +Quadratic convergence requires bounding the residual via Taylor with +remainder; we record only the fixed-point-at-root and error-decomposition +identities. -/ + +/-- **Newton-Raphson iteration step**: `σ_{n+1} = σ_n − f(σ_n) / f'(σ_n)`. -/ +noncomputable def newtonStep (f f' : ℝ → ℝ) (σ : ℝ) : ℝ := σ - f σ / f' σ + +/-- **A root is a fixed point of the Newton iteration**. -/ +theorem newtonStep_fixed_at_root (f f' : ℝ → ℝ) {σ : ℝ} (h_root : f σ = 0) : + newtonStep f f' σ = σ := by + unfold newtonStep + rw [h_root, zero_div, sub_zero] + +/-- **Error decomposition for one Newton step** when `σ_*` is a root of `f`. -/ +theorem newtonStep_error_via_root + (f f' : ℝ → ℝ) {σ_star σ : ℝ} (_h_root : f σ_star = 0) : + newtonStep f f' σ - σ_star = (σ - σ_star) - f σ / f' σ := by + unfold newtonStep + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/KirkSpreadApproximation.lean b/LeanPool/MathFin/Models/BlackScholes/KirkSpreadApproximation.lean new file mode 100644 index 0000000000..c15e010085 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/KirkSpreadApproximation.lean @@ -0,0 +1,178 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.ExchangeOption +public import LeanPool.MathFin.Models.BlackScholes.MargrabeGrounding + +/-! +# Kirk's approximation for spread options (`K ≠ 0`) + +**This is an approximation, not an exact closed form.** The spread-option +payoff `max(S¹_T − S²_T − K, 0)` for `K ≠ 0` has no known exact Black–Scholes +closed form — unlike the `K = 0` case, which is the exact Margrabe exchange +option (`Models/BlackScholes/ExchangeOption.lean`). E. Kirk ("Correlation in the energy markets", +in *Managing Energy Price Risk*, Risk Publications, 1995, 71–78) prices it, in +forward terms, by treating `F² + K` as a single "pseudo-asset" and running +the Margrabe/Garman machinery on `F¹` vs. that pseudo-asset, approximating +the pseudo-asset's lognormal volatility by linearising `F²/(F² + K)` at its +initial value. Converting to spot via `Fⁱ = Sⁱ·e^{rT}` (no dividends), the +pseudo-strike becomes `S² + K·e^{-rT}` — only the cash strike `K` is +discounted, `S²` is already a present value — and the linearisation weight +becomes `w = S²₀/(S²₀ + K·e^{-rT})`. The resulting formula is a +Black-Scholes-style **undiscounted** spot price (`DF = 1`, since `S¹, S²` +already are present values) at an **effective volatility** + + `σ_eff² = σ₁² − 2ρσ₁σ₂ · w + σ₂² · w²`, `w = S²₀/(S²₀ + K·e^{-rT})`, + +which this file states and threads through the Garman normal form +(`GarmanNormalForm.lean`). It is a documented approximation (the +"pseudo-asset" is not actually lognormal), so for `K ≠ 0` no claim is made that +`kirkSpreadPrice` equals the true discounted expected payoff — only that it +is literally the standard BS closed form at this particular `(A, K', σ_eff)`. +At `K = 0` the discounted cash strike `K·e^{-rT}` is `0` for every `r`, so +the pseudo-asset reduces to `S²` itself for every `r`: both the +**effective-variance parameter** (`kirkEffectiveVariance_zero_eq_margrabe`) +and the **price itself** (`kirkSpreadPrice_zero_eq_margrabe`) collapse to +exactly Margrabe at `K = 0`, for every `r` (and `S²₀ ≠ 0`). Since Margrabe's formula is the +discounted expected exchange payoff in the two-GBM model (`margrabe_exchange_price`), Kirk's +price is exact at `K = 0` (`kirkSpreadPrice_zero_eq_expected`). + +## Main definitions + +* `kirkWeight`: the linearisation point `w = S²₀/(S²₀ + K)`. +* `kirkEffectiveVariance`: `σ₁² − 2ρσ₁σ₂·w + σ₂²·w²`, with `w = kirkWeight S2 K`. +* `kirkDiscountedStrike`: the discounted cash strike `K · e^{−rT}`. +* `kirkSpreadPrice`: Kirk's approximate spread-option price, the Black–Scholes closed form at the + exchange leg `S¹₀` with pseudo-strike `S²₀ + K·e^{−rT}` and the effective variance (an + approximation, shown exact at `K = 0`). + +## Main results + +* `kirk_variance_sub_weighted`: `Var[L₁ − w·L₂] = kirkEffectiveVariance · T` for log-prices + with variances `σᵢ²T` and covariance `ρσ₁σ₂T` — the variance identity that defines Kirk's + effective variance. +* `kirkEffectiveVariance_zero_eq_margrabe`: at `K' = 0` and `S²₀ ≠ 0` (so `w = 1`) Kirk's + effective variance is exactly the Margrabe effective variance + `σ₁² + σ₂² − 2ρσ₁σ₂`. +* `kirkSpreadPrice_zero_eq_margrabe`: at `K = 0`, for every `r` and `S²₀ ≠ 0`, + `kirkSpreadPrice` is exactly `margrabePrice` at the Margrabe volatility + `√(σ₁² + σ₂² − 2ρσ₁σ₂)` — a price-level equality, not just a variance-level one. +* `kirkSpreadPrice_zero_eq_expected`: in the two-GBM model of `margrabe_exchange_price` + (`MargrabeGrounding.lean`), Kirk's price at `K = 0` is the discounted expected spread + payoff — so the approximation is exact at zero strike. For `K ≠ 0` no accuracy statement + is made. + +## References + +* [E. Kirk, *Correlation in the energy markets*][Kirk1995] + +## Tags + +Kirk approximation, spread option, energy markets, crack spread, approximate closed form, MSC 91G20, +JEL G13, JEL Q02 +-/ + +@[expose] public section + +namespace MathFin + +open Real MeasureTheory ProbabilityTheory + +/-- **Kirk's weight**: the linearisation point `w = S²₀/(S²₀ + K)` at which the +pseudo-asset `S² + K`'s lognormal volatility is approximated by `σ₂ · w`. -/ +noncomputable def kirkWeight (S2 K : ℝ) : ℝ := S2 / (S2 + K) + +/-- **Kirk's effective variance**: `σ₁² − 2ρσ₁σ₂·w + σ₂²·w²`, with +`w = kirkWeight S2 K`. It is `Var[L₁ − w·L₂]/T` for log-prices with variances `σᵢ²T` and +correlation `ρ` (`kirk_variance_sub_weighted`, the bilinear expansion of +`margrabe_variance_sub` with `L₂` scaled by `w`), i.e. Kirk's approximation is "Margrabe +with `S²` shrunk by `w`." -/ +noncomputable def kirkEffectiveVariance (S2 K σ1 σ2 ρ : ℝ) : ℝ := + σ1 ^ 2 - 2 * ρ * σ1 * σ2 * kirkWeight S2 K + σ2 ^ 2 * kirkWeight S2 K ^ 2 + +/-- **Kirk's effective variance is a variance**: for square-integrable log-prices `L₁, L₂` with +`Var L₁ = σ₁²T`, `Var L₂ = σ₂²T` and `cov(L₁, L₂) = ρσ₁σ₂T`, the variance of `L₁ − w·L₂` at +Kirk's weight `w = kirkWeight S2 K` is `kirkEffectiveVariance S2 K σ₁ σ₂ ρ · T` +(`margrabe_variance_sub` applied to `L₁` and `w·L₂`). -/ +theorem kirk_variance_sub_weighted {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + [IsProbabilityMeasure P] {L₁ L₂ : Ω → ℝ} {S2 K σ1 σ2 ρ T : ℝ} + (h₁ : MemLp L₁ 2 P) (h₂ : MemLp L₂ 2 P) + (hV₁ : Var[L₁; P] = σ1 ^ 2 * T) (hV₂ : Var[L₂; P] = σ2 ^ 2 * T) + (hcov : cov[L₁, L₂; P] = ρ * σ1 * σ2 * T) : + Var[fun ω ↦ L₁ ω - kirkWeight S2 K * L₂ ω; P] = kirkEffectiveVariance S2 K σ1 σ2 ρ * T := by + have h := margrabe_variance_sub h₁ (h₂.const_mul (kirkWeight S2 K)) + rw [variance_const_mul, covariance_const_mul_right, hV₁, hV₂, hcov] at h + rw [show (fun ω ↦ L₁ ω - kirkWeight S2 K * L₂ ω) = L₁ - fun ω ↦ kirkWeight S2 K * L₂ ω + from rfl, h] + unfold kirkEffectiveVariance + ring + +/-- **Kirk reduces to Margrabe at `K = 0`**: for `S²₀ ≠ 0`, `kirkWeight S2 0 = 1`, so Kirk's +effective variance collapses to exactly the Margrabe effective variance +`σ₁² + σ₂² − 2ρσ₁σ₂` — the one point where the spread-option payoff +`max(S¹ − S² − K, 0)` is the *exact* exchange-option payoff. The price-level collapse to +`margrabePrice` is `kirkSpreadPrice_zero_eq_margrabe`. -/ +theorem kirkEffectiveVariance_zero_eq_margrabe (S2 σ1 σ2 ρ : ℝ) (hS2 : S2 ≠ 0) : + kirkEffectiveVariance S2 0 σ1 σ2 ρ = σ1 ^ 2 + σ2 ^ 2 - 2 * ρ * σ1 * σ2 := by + unfold kirkEffectiveVariance kirkWeight + rw [add_zero, div_self hS2] + ring + +/-- **Kirk's discounted cash strike** `K · e^{-rT}`: the only piece of the +pseudo-strike `S²₀ + K·e^{-rT}` that needs discounting, since `S²₀` is +already a spot (present-value) quantity while `K` is a cash amount paid +at `T`. -/ +noncomputable def kirkDiscountedStrike (K r T : ℝ) : ℝ := K * Real.exp (-(r * T)) + +/-- **Kirk's approximate spread-option price**: the Garman-normal BS closed +form at `A = S¹₀` (the exchange leg), pseudo-strike +`K' = S²₀ + K·e^{-rT}`, `DF = 1` (both `S¹₀` and the pseudo-strike are +already present-value spot quantities, so no further discounting applies), +and effective volatility `√(kirkEffectiveVariance S²₀ (K·e^{-rT}) σ₁ σ₂ ρ)`. +Documented as an **approximation**: this is Kirk's (1995) heuristic, not the +exact discounted expected payoff of `max(S¹_T − S²_T − K, 0)`. -/ +noncomputable def kirkSpreadPrice (S1 S2 K r σ1 σ2 ρ T : ℝ) : ℝ := + bsVGarman S1 (S2 + kirkDiscountedStrike K r T) 1 + (Real.sqrt (kirkEffectiveVariance S2 (kirkDiscountedStrike K r T) σ1 σ2 ρ)) T + +/-- **Kirk's price collapses to the Margrabe price at `K = 0`, for every `r`** (and `S²₀ ≠ 0`): the +discounted cash strike `kirkDiscountedStrike 0 r T` is `0` regardless of `r` (nothing to +discount), so the pseudo-asset is `S²₀` itself, the effective variance is Margrabe's +(`kirkEffectiveVariance_zero_eq_margrabe`), and `kirkSpreadPrice` is `margrabePrice` at the +Margrabe volatility `√(σ₁² + σ₂² − 2ρσ₁σ₂)` — the point where the spread payoff +`max(S¹ − S² − K, 0)` is the exchange-option payoff. -/ +theorem kirkSpreadPrice_zero_eq_margrabe (S1 r σ1 σ2 ρ T : ℝ) {S2 : ℝ} (hS2 : S2 ≠ 0) : + kirkSpreadPrice S1 S2 0 r σ1 σ2 ρ T = + margrabePrice S1 S2 (Real.sqrt (σ1 ^ 2 + σ2 ^ 2 - 2 * ρ * σ1 * σ2)) T := by + rw [← kirkEffectiveVariance_zero_eq_margrabe S2 σ1 σ2 ρ hS2] + unfold kirkSpreadPrice kirkDiscountedStrike + rw [zero_mul, add_zero] + exact (margrabe_eq_bsVGarman S1 S2 _ T).symm + +/-- **At zero strike Kirk's price is the expected spread payoff.** For two Black–Scholes +terminals driven by a jointly Gaussian pair of standard normals with covariance `ρ`, and a +non-degenerate spread variance `σ₁² + σ₂² − 2ρσ₁σ₂ > 0`, Kirk's approximate price at `K = 0` +equals `𝔼_P[e^{−rT}·max(S¹_T − S²_T − 0, 0)]` (`kirkSpreadPrice_zero_eq_margrabe` and +`margrabe_exchange_price`). -/ +theorem kirkSpreadPrice_zero_eq_expected {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + [IsProbabilityMeasure P] {W₁ W₂ : Ω → ℝ} {σ1 σ2 ρ S1 S2 r T : ℝ} + (hjoint : HasGaussianLaw (fun ω ↦ (W₁ ω, W₂ ω)) P) + (hW₁meas : Measurable W₁) (hW₂meas : Measurable W₂) + (hW₁ : HasLaw W₁ (gaussianReal 0 1) P) (hW₂ : HasLaw W₂ (gaussianReal 0 1) P) + (hcov : cov[W₁, W₂; P] = ρ) (hS1 : 0 < S1) (hS2 : 0 < S2) (hT : 0 < T) + (hv : 0 < σ1 ^ 2 + σ2 ^ 2 - 2 * ρ * σ1 * σ2) : + kirkSpreadPrice S1 S2 0 r σ1 σ2 ρ T + = ∫ ω, Real.exp (-(r * T)) * + max (bsTerminal S1 r σ1 T (W₁ ω) - bsTerminal S2 r σ2 T (W₂ ω) - 0) 0 ∂P := by + simp_rw [sub_zero] + rw [kirkSpreadPrice_zero_eq_margrabe S1 r σ1 σ2 ρ T hS2.ne', + margrabe_exchange_price hjoint hW₁meas hW₂meas hW₁ hW₂ hcov hS1 hS2 + (Real.sqrt_pos.mpr hv) hT (Real.sq_sqrt hv.le)] + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/LognormalMoments.lean b/LeanPool/MathFin/Models/BlackScholes/LognormalMoments.lean new file mode 100644 index 0000000000..77018dddf4 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/LognormalMoments.lean @@ -0,0 +1,92 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Call +public import LeanPool.MathFin.Models.BlackScholes.Forward + +/-! +# Second moment and variance of the terminal asset price + +Under `BSCallHyp` (risk-neutral lognormal model), + + `E_Q[S_T²] = S_0² · exp(2rT + σ²T)`, + `Var_Q[S_T] = S_0² · exp(2rT) · (exp(σ²T) − 1)`. + +The second-moment formula is `nthMoment_terminal 2 h` — the n=2 instance of +the general power-moment identity, which is itself an instance of the +affine-shifted standard-normal MGF. The variance follows from the second +moment minus the squared forward `E[S_T]² = S_0² · exp(2rT)`. + +This file used to duplicate the MGF computation. Following the principle +"one theorem, many corollaries", we now delegate `secondMoment_terminal` to +`nthMoment_terminal` and only do the n=2 algebraic simplification here. + +## Main results + +* `secondMoment_terminal`: `E_Q[S_T²] = S_0² · exp(2rT + σ²T)`. +* `variance_terminal`: `Var_Q[S_T] = S_0² · exp(2rT) · (exp(σ²T) − 1)`. + +## References + +* [K. Bodie and Marcus, *Investments*][BodieKaneMarcus], Ch 21 +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], Ch 14.7 + +## Tags + +lognormal distribution, second moment, variance of terminal price, geometric Brownian motion, +risk-neutral moments, MSC 60E05, MSC 91G20 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- **Second moment of the terminal asset price**: under `BSCallHyp`, +`E_Q[S_T²] = S_0² · exp(2 r T + σ² T)`. + +Instance of `nthMoment_terminal` at `n = 2`: the general formula gives +`S_0^2 · exp(2·r·T + 2·1/2·σ²T) = S_0^2 · exp(2rT + σ²T)`. -/ +theorem secondMoment_terminal + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + ∫ ω, (bsTerminal S_0 r σ T (Z ω))^2 ∂Q = + S_0^2 * Real.exp (2 * r * T + σ^2 * T) := by + have h_general := nthMoment_terminal 2 h + -- nthMoment_terminal at n=2 produces: + -- ∫ ... = S_0^2 * exp((↑(2:ℕ))·r·T + (↑(2:ℕ))·((↑(2:ℕ))-1)/2 · σ²·T) + -- which equals S_0^2 * exp(2·r·T + σ²·T) after pushing the cast and + -- simplifying `2·(2-1)/2 = 1`. + convert h_general using 3 + push_cast + ring + +/-- **Variance of the terminal asset price**: under `BSCallHyp`, +`Var_Q[S_T] = E_Q[S_T²] − (E_Q[S_T])² = S_0² · exp(2 r T) · (exp(σ² T) − 1)`. + +Combines `secondMoment_terminal` with `expected_terminal_eq_forward`. -/ +theorem variance_terminal + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + ∫ ω, (bsTerminal S_0 r σ T (Z ω))^2 ∂Q - + (∫ ω, bsTerminal S_0 r σ T (Z ω) ∂Q)^2 = + S_0^2 * Real.exp (2 * r * T) * (Real.exp (σ^2 * T) - 1) := by + rw [secondMoment_terminal h, expected_terminal_eq_forward h] + have h_exp_sq : (Real.exp (r * T))^2 = Real.exp (2 * r * T) := by + rw [pow_two, ← Real.exp_add]; congr 1; ring + have h_sq_exp : (S_0 * Real.exp (r * T))^2 = S_0^2 * Real.exp (2 * r * T) := by + rw [mul_pow, h_exp_sq] + rw [h_sq_exp, Real.exp_add]; ring + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/Lookback.lean b/LeanPool/MathFin/Models/BlackScholes/Lookback.lean new file mode 100644 index 0000000000..31d6f8ab2e --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/Lookback.lean @@ -0,0 +1,73 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.PDE +public import Mathlib.Algebra.Order.Star.Real + +/-! +# Lookback call lower bound + +The lookback call's payoff `max(M − K, 0)` (with `M = max_{t ∈ [0,T]} S_t`) +dominates the vanilla call payoff `max(S_T − K, 0)` because `S_T ≤ M`. +Discounted to today, this gives the static lower bound: + +`lookbackCall ≥ vanillaCall`. + +## Main results + +* `lookback_payoff_ge_vanilla`: `max(S − K, 0) ≤ max(M − K, 0)` when `S ≤ M`. +* `bsV_le_lookbackCall`: under the Black–Scholes lognormal hypothesis, the Black–Scholes + call `bsV K r σ S₀ T` is at most `e^{−rT}·𝔼[max(M − K, 0)]` for any random variable + `M ≥ S_T` (a.s.) whose call payoff is integrable — the running maximum is one such `M`. + The law of the running maximum is not used, and no closed form for the lookback is + claimed. + +## References + +* [M. B. Goldman, H. B. Sosin and M. A. Gatto, *Path dependent options: buy at the low, sell at the + high*][GoldmanSosinGatto1979] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 26.8 + +## Tags + +lookback option, running maximum, path-dependent option, static lower bound, exotic option, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory + +/-- **Lookback call payoff lower bound**: if `S ≤ M` (the running max), then +`max(S − K, 0) ≤ max(M − K, 0)`. -/ +lemma lookback_payoff_ge_vanilla (M S K : ℝ) (h : S ≤ M) : + max (S - K) 0 ≤ max (M - K) 0 := + max_le_max (by linarith) le_rfl + +/-- **The Black–Scholes call is a lower bound for the lookback call.** Under `BSCallHyp`, for +any random variable `M` dominating the terminal price `S_T = bsTerminal S₀ r σ T Z` almost +surely (the running maximum is one) and with an integrable call payoff, the Black–Scholes +call price is at most the discounted expected lookback payoff: +`bsV K r σ S₀ T ≤ e^{−rT}·𝔼[max(M − K, 0)]`. The integrability hypothesis is needed: without +it the Bochner integral on the right is `0`. -/ +theorem bsV_le_lookbackCall {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} + [IsProbabilityMeasure Q] {S_0 K r σ T : ℝ} {Z M : Ω → ℝ} (h : BSCallHyp Q S_0 K r σ T Z) + (hM : ∀ᵐ ω ∂Q, bsTerminal S_0 r σ T (Z ω) ≤ M ω) + (hint : Integrable (fun ω ↦ max (M ω - K) 0) Q) : + bsV K r σ S_0 T ≤ ∫ ω, Real.exp (-r * T) * max (M ω - K) 0 ∂Q := by + rw [← integral_bsCall_payoff_eq_bsV h] + refine integral_mono_ae + (((integrable_bsTerminal h.Z_law S_0 r σ T).sub' (integrable_const K)).pos_part.const_mul _) + (hint.const_mul _) ?_ + filter_upwards [hM] with ω hω + exact mul_le_mul_of_nonneg_left (lookback_payoff_ge_vanilla _ _ K hω) (Real.exp_pos _).le + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/MargrabeGrounding.lean b/LeanPool/MathFin/Models/BlackScholes/MargrabeGrounding.lean new file mode 100644 index 0000000000..5ccdf76e76 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/MargrabeGrounding.lean @@ -0,0 +1,409 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.ExchangeOption +public import LeanPool.MathFin.Models.BlackScholes.GaussianGirsanov +public import LeanPool.MathFin.Probability.Gaussian.GaussianPairLinearLaw +public import Mathlib.Algebra.Ring.IsFormallyReal +public import Mathlib.Probability.Independence.Integration + +/-! +# The Margrabe ratio from a joint two-GBM model + +`margrabe_price_via_call` (in `ExchangeOption.lean`) prices the exchange option +by *assuming* `BSCallHyp Q (S¹₀/S²₀) 1 0 σ T Z` — the ratio `R = S¹/S²` is +lognormal at the effective volatility `σ` with a standard-normal driver `Z` under some `Q`. +This file builds that hypothesis from a joint Gaussian model of the two assets' drivers, +and ties it to the actual ratio. + +The two terminal prices are Black–Scholes terminals, `Sⁱ_T = bsTerminal Sⁱ₀ r σᵢ T Wᵢ`, with +`(W₁, W₂)` jointly Gaussian, each `N(0, 1)`, with covariance `ρ`. Then: + +* the normalized log-spread driver `W := (σ₁·W₁ − σ₂·W₂)/σ_eff`, + `σ_eff² = σ₁² + σ₂² − 2ρσ₁σ₂`, is `N(0, 1)` (`normalizedSpread_hasLaw_std`): Gaussian as + a linear image of the pair, with variance `1` by covariance bilinearity + (`margrabe_effective_variance`); +* pathwise, the ratio is one Black–Scholes terminal at zero rate and volatility `σ_eff`, + driven by `W` shifted by `c = (ρσ₁σ₂ − σ₂²)√T/σ_eff` (`bsTerminal_div_bsTerminal`): + `S¹_T/S²_T = bsTerminal (S¹₀/S²₀) 0 σ_eff T (W − c)`; +* under the Esscher tilt `Q = P.withDensity(e^{cW − c²/2})`, `W − c` is `N(0, 1)` + (`BSCallHyp.exists_of_physical`, static Girsanov), so `BSCallHyp` holds for the ratio with + driver `W − c` (`margrabe_bsCallHyp_of_gaussian`), and the `S²`-scaled ratio call under `Q` + is the Margrabe price (`margrabe_price_of_gaussian`). + +**Scope.** `Q` is the Esscher tilt of `P` along the normalized spread; that it is the +`S²`-numéraire measure is not proved. The price-level statement is proved directly under `P` +instead: `margrabe_exchange_price` shows `𝔼_P[e^{−rT}max(S¹_T − S²_T, 0)] = margrabePrice`, by +splitting `W₂` into its regression on `W` and an independent residual (uncorrelated linear +images of a Gaussian pair are independent, `HasGaussianLaw.indepFun_of_covariance_eq_zero`). + +## Main results + +* `normalizedSpread_hasLaw_std` — the normalized log-spread driver + `(σ₁W₁ − σ₂W₂)/σ_eff` is `N(0,1)` (bivariate → univariate reduction). +* `bsTerminal_div_bsTerminal` — the ratio of two Black–Scholes terminals is a Black–Scholes + terminal of the ratio at the spread volatility. +* `margrabe_bsCallHyp_of_gaussian` — the Esscher tilt `Q` and the driver `W − c`, with + `BSCallHyp` for the ratio and the pathwise identity for the actual ratio. +* `margrabe_price_of_gaussian` — `S²₀·𝔼_Q[max(S¹_T/S²_T − 1, 0)] = margrabePrice`. +* `margrabe_exchange_price` — Margrabe's formula is the discounted expected exchange payoff + under the model measure `P`. +* `integral_betterOfTwo` — the better-of-two payoff `max(S¹_T, S²_T)` is worth + `S²₀ + margrabePrice`. + +## References + +* [W. Margrabe, *The value of an option to exchange one asset for another*][Margrabe1978] +* [R. M. Stulz, *Options on the minimum or the maximum of two risky assets: analysis and + applications*][Stulz1982] + +## Tags + +Margrabe formula, joint geometric Brownian motions, correlated assets, exchange option, +effective volatility, ratio of prices, MSC 91G20, MSC 60G15, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + +/-- **Bivariate → univariate reduction.** For a jointly-gaussian pair +`(W₁, W₂)` of standard-normal drivers with correlation `ρ`, the normalized +log-spread driver `(σ₁·W₁ − σ₂·W₂)/σ_eff` is standard normal, where +`σ_eff² = σ₁² + σ₂² − 2ρσ₁σ₂ > 0`. The variance is pinned to `1` by covariance +bilinearity (`margrabe_effective_variance`); gaussianity is preserved under the +linear map. -/ +theorem normalizedSpread_hasLaw_std + {W₁ W₂ : Ω → ℝ} {σ₁ σ₂ ρ σeff : ℝ} + (hjoint : HasGaussianLaw (fun ω ↦ (W₁ ω, W₂ ω)) P) + (hW₁meas : Measurable W₁) (hW₂meas : Measurable W₂) + (hW₁ : HasLaw W₁ (gaussianReal 0 1) P) (hW₂ : HasLaw W₂ (gaussianReal 0 1) P) + (hcov : cov[W₁, W₂; P] = ρ) (hσeff : 0 < σeff) + (hσeff_sq : σeff ^ 2 = σ₁ ^ 2 + σ₂ ^ 2 - 2 * ρ * σ₁ * σ₂) : + HasLaw (fun ω ↦ (σ₁ * W₁ ω - σ₂ * W₂ ω) / σeff) (gaussianReal 0 1) P := by + set W : Ω → ℝ := fun ω ↦ (σ₁ * W₁ ω - σ₂ * W₂ ω) / σeff with hW_def + have hWmeas : Measurable W := ((hW₁meas.const_mul σ₁).sub (hW₂meas.const_mul σ₂)).div_const _ + -- `W` is a continuous-linear image of the gaussian vector, hence gaussian. + have hWgl : HasGaussianLaw W P := by + let L : ℝ × ℝ →L[ℝ] ℝ := + (σeff⁻¹ • (σ₁ • ContinuousLinearMap.fst ℝ ℝ ℝ - σ₂ • ContinuousLinearMap.snd ℝ ℝ ℝ)) + have hcomp : W = L ∘ (fun ω ↦ (W₁ ω, W₂ ω)) := by + funext ω + simp only [hW_def, L, FunLike.coe_smul, FunLike.coe_sub, + ContinuousLinearMap.coe_fst', ContinuousLinearMap.coe_snd', Function.comp_apply, + Pi.smul_apply, Pi.sub_apply, smul_eq_mul] + rw [div_eq_inv_mul] + rw [hcomp] + exact hjoint.map_of_measurable L L.continuous.measurable + -- Mean zero and variance one. + have hmem₁ : MemLp W₁ 2 P := (hW₁.hasGaussianLaw).memLp_two + have hmem₂ : MemLp W₂ 2 P := (hW₂.hasGaussianLaw).memLp_two + have hint₁ : Integrable W₁ P := hmem₁.integrable (by norm_num) + have hint₂ : Integrable W₂ P := hmem₂.integrable (by norm_num) + have hmean₁ : ∫ ω, W₁ ω ∂P = 0 := by rw [hW₁.integral_eq, integral_id_gaussianReal] + have hmean₂ : ∫ ω, W₂ ω ∂P = 0 := by rw [hW₂.integral_eq, integral_id_gaussianReal] + have hvar₁ : Var[W₁; P] = 1 := by rw [hW₁.variance_eq, variance_id_gaussianReal]; norm_num + have hvar₂ : Var[W₂; P] = 1 := by rw [hW₂.variance_eq, variance_id_gaussianReal]; norm_num + have hWmean : ∫ ω, W ω ∂P = 0 := by + simp only [hW_def] + rw [integral_div, integral_sub (hint₁.const_mul σ₁) (hint₂.const_mul σ₂), + integral_const_mul, integral_const_mul, hmean₁, hmean₂] + simp + -- Var[W] = (1/σeff²)·Var[σ₁W₁ − σ₂W₂] = (1/σeff²)·σeff² = 1. + have hmemL₁ : MemLp (fun ω ↦ σ₁ * W₁ ω) 2 P := hmem₁.const_mul σ₁ + have hmemL₂ : MemLp (fun ω ↦ σ₂ * W₂ ω) 2 P := hmem₂.const_mul σ₂ + have hvarspread : Var[fun ω ↦ σ₁ * W₁ ω - σ₂ * W₂ ω; P] = σeff ^ 2 := by + have hV₁ : Var[fun ω ↦ σ₁ * W₁ ω; P] = σ₁ ^ 2 * 1 := by rw [variance_const_mul, hvar₁] + have hV₂ : Var[fun ω ↦ σ₂ * W₂ ω; P] = σ₂ ^ 2 * 1 := by rw [variance_const_mul, hvar₂] + have hC : cov[fun ω ↦ σ₁ * W₁ ω, fun ω ↦ σ₂ * W₂ ω; P] = ρ * σ₁ * σ₂ * 1 := by + rw [covariance_const_mul_left, covariance_const_mul_right, hcov]; ring + have hv := margrabe_effective_variance (T := 1) hmemL₁ hmemL₂ hV₁ hV₂ hC + rw [mul_one] at hv + rw [hσeff_sq] + exact hv + have hWvar : Var[W; P] = 1 := by + have hWeq : W = fun ω ↦ σeff⁻¹ * (σ₁ * W₁ ω - σ₂ * W₂ ω) := by + funext ω; simp only [hW_def]; rw [div_eq_inv_mul] + rw [hWeq, variance_const_mul, hvarspread] + field_simp + -- Pin the law from gaussianity + (mean, variance). + refine ⟨hWmeas.aemeasurable, ?_⟩ + have hg : IsGaussian (P.map W) := hWgl.isGaussian_map + have hmap_mean : (P.map W)[id] = 0 := by + rw [integral_map hWmeas.aemeasurable aestronglyMeasurable_id] + simpa using hWmean + have hmap_var : Var[id; P.map W] = 1 := by + rw [variance_map aemeasurable_id hWmeas.aemeasurable] + simpa using hWvar + rw [hg.eq_gaussianReal (P.map W), hmap_mean, hmap_var, Real.toNNReal_one] + +/-- **The ratio of two Black–Scholes terminals is a Black–Scholes terminal.** For spots +`S¹₀, S²₀ > 0`, a common rate `r` and volatilities `σ₁, σ₂`, with `σ_eff > 0`, +`σ_eff² = σ₁² + σ₂² − 2ρσ₁σ₂` and `T ≥ 0`: + + `bsTerminal S¹₀ r σ₁ T w₁ / bsTerminal S²₀ r σ₂ T w₂ + = bsTerminal (S¹₀/S²₀) 0 σ_eff T ((σ₁w₁ − σ₂w₂)/σ_eff − c)`, `c = (ρσ₁σ₂ − σ₂²)√T/σ_eff`. + +The rate cancels, and the drift `(σ₂² − σ₁²)T/2` of the log-ratio is the zero-rate drift +`−σ_eff²T/2` plus the shift `−σ_eff√T·c`. -/ +theorem bsTerminal_div_bsTerminal {S1 S2 r σ₁ σ₂ ρ σeff T : ℝ} (w₁ w₂ : ℝ) + (hσeff : 0 < σeff) (hT : 0 ≤ T) (hσeff_sq : σeff ^ 2 = σ₁ ^ 2 + σ₂ ^ 2 - 2 * ρ * σ₁ * σ₂) : + bsTerminal S1 r σ₁ T w₁ / bsTerminal S2 r σ₂ T w₂ + = bsTerminal (S1 / S2) 0 σeff T + ((σ₁ * w₁ - σ₂ * w₂) / σeff - (ρ * σ₁ * σ₂ - σ₂ ^ 2) * Real.sqrt T / σeff) := by + have hshift : σeff * Real.sqrt T * + ((σ₁ * w₁ - σ₂ * w₂) / σeff - (ρ * σ₁ * σ₂ - σ₂ ^ 2) * Real.sqrt T / σeff) + = Real.sqrt T * (σ₁ * w₁ - σ₂ * w₂) - (ρ * σ₁ * σ₂ - σ₂ ^ 2) * Real.sqrt T ^ 2 := by + field_simp + unfold bsTerminal + rw [mul_div_mul_comm, ← Real.exp_sub, hshift, Real.sq_sqrt hT] + congr 2 + linear_combination (T / 2) * hσeff_sq + +/-- **The Margrabe `BSCallHyp`, with its witnesses.** From a joint Gaussian model of the two +standard-normal drivers `(W₁, W₂)` with covariance `ρ`, take the normalized spread +`W = (σ₁W₁ − σ₂W₂)/σ_eff` and the shift `c = (ρσ₁σ₂ − σ₂²)√T/σ_eff` (`hc`). Then +`Q = P.withDensity(e^{cW − c²/2})` is a probability measure, the driver `Z = W − c` satisfies +`BSCallHyp Q (S¹₀/S²₀) 1 0 σ_eff T Z`, and `Z` drives the *actual* ratio of the two +Black–Scholes terminals: `S¹_T/S²_T = bsTerminal (S¹₀/S²₀) 0 σ_eff T Z` pointwise +(`bsTerminal_div_bsTerminal`). `Q` is not shown to be the `S²`-numéraire measure. -/ +theorem margrabe_bsCallHyp_of_gaussian + {W₁ W₂ : Ω → ℝ} {σ₁ σ₂ ρ σeff S1 S2 r T c : ℝ} + (hjoint : HasGaussianLaw (fun ω ↦ (W₁ ω, W₂ ω)) P) + (hW₁meas : Measurable W₁) (hW₂meas : Measurable W₂) + (hW₁ : HasLaw W₁ (gaussianReal 0 1) P) (hW₂ : HasLaw W₂ (gaussianReal 0 1) P) + (hcov : cov[W₁, W₂; P] = ρ) + (hS1 : 0 < S1) (hS2 : 0 < S2) (hσeff : 0 < σeff) (hT : 0 < T) + (hσeff_sq : σeff ^ 2 = σ₁ ^ 2 + σ₂ ^ 2 - 2 * ρ * σ₁ * σ₂) + (hc : c = (ρ * σ₁ * σ₂ - σ₂ ^ 2) * Real.sqrt T / σeff) : + ∃ (Q : Measure Ω) (hQ : IsProbabilityMeasure Q) (Z : Ω → ℝ), + Q = P.withDensity (fun ω ↦ + ENNReal.ofReal (Real.exp (c * ((σ₁ * W₁ ω - σ₂ * W₂ ω) / σeff) - c ^ 2 / 2))) ∧ + @BSCallHyp _ _ Q hQ (S1 / S2) 1 0 σeff T Z ∧ + ∀ ω, bsTerminal S1 r σ₁ T (W₁ ω) / bsTerminal S2 r σ₂ T (W₂ ω) + = bsTerminal (S1 / S2) 0 σeff T (Z ω) := by + have hW : HasLaw (fun ω ↦ (σ₁ * W₁ ω - σ₂ * W₂ ω) / σeff) (gaussianReal 0 1) P := + normalizedSpread_hasLaw_std hjoint hW₁meas hW₂meas hW₁ hW₂ hcov hσeff hσeff_sq + have hWmeas : Measurable (fun ω ↦ (σ₁ * W₁ ω - σ₂ * W₂ ω) / σeff) := + ((hW₁meas.const_mul σ₁).sub (hW₂meas.const_mul σ₂)).div_const _ + obtain ⟨Q, hQ, hQeq, hbs⟩ := + BSCallHyp.exists_of_physical c (div_pos hS1 hS2) one_pos hσeff hT hWmeas hW + refine ⟨Q, hQ, _, hQeq, hbs, fun ω ↦ ?_⟩ + subst hc + exact bsTerminal_div_bsTerminal (W₁ ω) (W₂ ω) hσeff hT.le hσeff_sq + +/-- **The ratio call under the tilted measure is the Margrabe price.** With the Esscher tilt +`Q` and shift `c` of `margrabe_bsCallHyp_of_gaussian`, the `S²₀`-scaled call on the actual +ratio of the two Black–Scholes terminals, struck at `1`, has value +`S²₀·𝔼_Q[max(S¹_T/S²_T − 1, 0)] = margrabePrice S¹₀ S²₀ σ_eff T` +(`margrabe_price_via_call`). `Q` is not shown to be the `S²`-numéraire measure; the +expected exchange payoff under `P` is `margrabe_exchange_price`. -/ +theorem margrabe_price_of_gaussian + {W₁ W₂ : Ω → ℝ} {σ₁ σ₂ ρ σeff S1 S2 r T c : ℝ} + (hjoint : HasGaussianLaw (fun ω ↦ (W₁ ω, W₂ ω)) P) + (hW₁meas : Measurable W₁) (hW₂meas : Measurable W₂) + (hW₁ : HasLaw W₁ (gaussianReal 0 1) P) (hW₂ : HasLaw W₂ (gaussianReal 0 1) P) + (hcov : cov[W₁, W₂; P] = ρ) + (hS1 : 0 < S1) (hS2 : 0 < S2) (hσeff : 0 < σeff) (hT : 0 < T) + (hσeff_sq : σeff ^ 2 = σ₁ ^ 2 + σ₂ ^ 2 - 2 * ρ * σ₁ * σ₂) + (hc : c = (ρ * σ₁ * σ₂ - σ₂ ^ 2) * Real.sqrt T / σeff) : + ∃ (Q : Measure Ω) (_ : IsProbabilityMeasure Q), + Q = P.withDensity (fun ω ↦ + ENNReal.ofReal (Real.exp (c * ((σ₁ * W₁ ω - σ₂ * W₂ ω) / σeff) - c ^ 2 / 2))) ∧ + S2 * ∫ ω, max (bsTerminal S1 r σ₁ T (W₁ ω) / bsTerminal S2 r σ₂ T (W₂ ω) - 1) 0 ∂Q + = margrabePrice S1 S2 σeff T := by + obtain ⟨Q, hQ, Z, hQeq, hbs, hratio⟩ := + margrabe_bsCallHyp_of_gaussian (r := r) hjoint hW₁meas hW₂meas hW₁ hW₂ hcov + hS1 hS2 hσeff hT hσeff_sq hc + refine ⟨Q, hQ, hQeq, ?_⟩ + simp_rw [hratio] + exact margrabe_price_via_call hS2 hbs + +/-! ### Margrabe's formula as the expected exchange payoff -/ + +/-- **Margrabe's formula is the discounted expected exchange payoff.** For two Black–Scholes +terminals `Sⁱ_T = bsTerminal Sⁱ₀ r σᵢ T Wᵢ` driven by a jointly Gaussian pair of standard +normals with covariance `ρ`, and `σ_eff > 0` with `σ_eff² = σ₁² + σ₂² − 2ρσ₁σ₂`, + + `𝔼_P[e^{−rT}·max(S¹_T − S²_T, 0)] = margrabePrice S¹₀ S²₀ σ_eff T`. + +The normalized spread `W = (σ₁W₁ − σ₂W₂)/σ_eff` and the residual `V = W₂ − κW`, +`κ = cov(W₂, W)`, are uncorrelated linear images of the Gaussian pair, hence independent +(`HasGaussianLaw.indepFun_of_covariance_eq_zero`). The discounted payoff factors as +`S²₀ · e^{σ₂√T·V − σ₂²T(1−κ²)/2} · e^{cW − c²/2}·max(S¹_T/S²_T − 1, 0)` with `c = σ₂√T·κ`; +the `V`-factor has mean `1`, and the `W`-factor is the ratio call under the Esscher tilt along +`W`, which is Margrabe's price (`margrabe_bsCallHyp_of_gaussian`, `margrabe_price_via_call`). -/ +theorem margrabe_exchange_price + {W₁ W₂ : Ω → ℝ} {σ₁ σ₂ ρ σeff S1 S2 r T : ℝ} + (hjoint : HasGaussianLaw (fun ω ↦ (W₁ ω, W₂ ω)) P) + (hW₁meas : Measurable W₁) (hW₂meas : Measurable W₂) + (hW₁ : HasLaw W₁ (gaussianReal 0 1) P) (hW₂ : HasLaw W₂ (gaussianReal 0 1) P) + (hcov : cov[W₁, W₂; P] = ρ) + (hS1 : 0 < S1) (hS2 : 0 < S2) (hσeff : 0 < σeff) (hT : 0 < T) + (hσeff_sq : σeff ^ 2 = σ₁ ^ 2 + σ₂ ^ 2 - 2 * ρ * σ₁ * σ₂) : + ∫ ω, Real.exp (-(r * T)) * + max (bsTerminal S1 r σ₁ T (W₁ ω) - bsTerminal S2 r σ₂ T (W₂ ω)) 0 ∂P + = margrabePrice S1 S2 σeff T := by + -- coefficients: `W = aW₁ + bW₂`, `κ = aρ + b = cov(W₂, W)`, `V = pW₁ + qW₂ = W₂ − κW`, + -- and the shift `c = σ₂√T·κ` + obtain ⟨a, ha⟩ : ∃ a : ℝ, a = σ₁ / σeff := ⟨_, rfl⟩ + obtain ⟨b, hb⟩ : ∃ b : ℝ, b = -σ₂ / σeff := ⟨_, rfl⟩ + obtain ⟨k, hk⟩ : ∃ k : ℝ, k = a * ρ + b := ⟨_, rfl⟩ + obtain ⟨p, hp⟩ : ∃ p : ℝ, p = -(k * a) := ⟨_, rfl⟩ + obtain ⟨q, hq⟩ : ∃ q : ℝ, q = 1 - k * b := ⟨_, rfl⟩ + obtain ⟨c, hcdef⟩ : ∃ c : ℝ, c = (ρ * σ₁ * σ₂ - σ₂ ^ 2) * Real.sqrt T / σeff := ⟨_, rfl⟩ + have hab : a ^ 2 + 2 * a * b * ρ + b ^ 2 = 1 := by + rw [ha, hb, show (σ₁ / σeff) ^ 2 + 2 * (σ₁ / σeff) * (-σ₂ / σeff) * ρ + (-σ₂ / σeff) ^ 2 + = (σ₁ ^ 2 + σ₂ ^ 2 - 2 * ρ * σ₁ * σ₂) / σeff ^ 2 by ring, ← hσeff_sq, + div_self (pow_ne_zero 2 hσeff.ne')] + have hc : c = σ₂ * Real.sqrt T * k := by + rw [hcdef, hk, ha, hb] + ring + have hcov0 : p * a + (p * b + q * a) * ρ + q * b = 0 := by + rw [hp, hq] + linear_combination (-k) * hab - hk + have hVvar : p ^ 2 + 2 * p * q * ρ + q ^ 2 = 1 - k ^ 2 := by + rw [hp, hq] + linear_combination k ^ 2 * hab + 2 * k * hk + have hWform (w₁ w₂ : ℝ) : a * w₁ + b * w₂ = (σ₁ * w₁ - σ₂ * w₂) / σeff := by + rw [ha, hb] + ring + -- laws, measurability, independence + have hU1 : Var[W₁; P] = 1 := by + rw [hW₁.variance_eq, variance_id_gaussianReal, NNReal.coe_one] + have hV1 : Var[W₂; P] = 1 := by + rw [hW₂.variance_eq, variance_id_gaussianReal, NNReal.coe_one] + have hWlaw : HasLaw (fun ω ↦ a * W₁ ω + b * W₂ ω) (gaussianReal 0 1) P := by + have h := hasLaw_linear_gaussianPair hjoint hW₁ hW₂ hcov a b + rwa [hab, Real.toNNReal_one] at h + have hWmeas : Measurable fun ω ↦ a * W₁ ω + b * W₂ ω := by fun_prop + have hVmeas : Measurable fun ω ↦ p * W₁ ω + q * W₂ ω := by fun_prop + have hVW : HasGaussianLaw (fun ω ↦ (p * W₁ ω + q * W₂ ω, a * W₁ ω + b * W₂ ω)) P := by + simpa only [ContinuousLinearMap.prod_apply, add_apply, smul_apply, ContinuousLinearMap.coe_fst', + ContinuousLinearMap.coe_snd', smul_eq_mul] using + hjoint.map_fun ((p • ContinuousLinearMap.fst ℝ ℝ ℝ + q • ContinuousLinearMap.snd ℝ ℝ ℝ).prod + (a • ContinuousLinearMap.fst ℝ ℝ ℝ + b • ContinuousLinearMap.snd ℝ ℝ ℝ)) + have hind : IndepFun (fun ω ↦ p * W₁ ω + q * W₂ ω) (fun ω ↦ a * W₁ ω + b * W₂ ω) P := by + refine hVW.indepFun_of_covariance_eq_zero ?_ + rw [covariance_linear_of_unit hW₁.hasGaussianLaw.memLp_two hW₂.hasGaussianLaw.memLp_two + hU1 hV1 hcov p q a b] + exact hcov0 + -- the Esscher tilt along `W` and the ratio call under it + obtain ⟨Q, hQ, hQeq, hbs⟩ := + BSCallHyp.exists_of_physical (K := 1) (r := 0) c (div_pos hS1 hS2) one_pos hσeff hT + hWmeas hWlaw + have hdens : Measurable fun ω ↦ Real.exp (c * (a * W₁ ω + b * W₂ ω) - c ^ 2 / 2) := by + fun_prop + -- the `V`-factor has mean `1` + have hfV : ∫ ω, Real.exp (σ₂ * Real.sqrt T * (p * W₁ ω + q * W₂ ω) + - σ₂ ^ 2 * T * (1 - k ^ 2) / 2) ∂P = 1 := by + have hfun : (fun ω ↦ Real.exp (σ₂ * Real.sqrt T * (p * W₁ ω + q * W₂ ω) + - σ₂ ^ 2 * T * (1 - k ^ 2) / 2)) + = fun ω ↦ Real.exp (-(σ₂ ^ 2 * T * (1 - k ^ 2) / 2)) * + Real.exp (σ₂ * Real.sqrt T * p * W₁ ω + σ₂ * Real.sqrt T * q * W₂ ω) := by + funext ω + rw [← Real.exp_add] + congr 1 + ring + rw [hfun, integral_const_mul, integral_exp_linear_gaussianPair hjoint hW₁ hW₂ hcov, + ← Real.exp_add] + rw [show -(σ₂ ^ 2 * T * (1 - k ^ 2) / 2) + ((σ₂ * Real.sqrt T * p) ^ 2 + + 2 * (σ₂ * Real.sqrt T * p) * (σ₂ * Real.sqrt T * q) * ρ + + (σ₂ * Real.sqrt T * q) ^ 2) / 2 = 0 by + linear_combination (σ₂ ^ 2 * Real.sqrt T ^ 2 / 2) * hVvar + + (σ₂ ^ 2 * (1 - k ^ 2) / 2) * Real.sq_sqrt hT.le] + exact Real.exp_zero + -- the `W`-factor is the ratio call under `Q` + have hgW : ∫ ω, Real.exp (c * (a * W₁ ω + b * W₂ ω) - c ^ 2 / 2) * + max (bsTerminal (S1 / S2) 0 σeff T (a * W₁ ω + b * W₂ ω - c) - 1) 0 ∂P + = ∫ ω, max (bsTerminal (S1 / S2) 0 σeff T (a * W₁ ω + b * W₂ ω - c) - 1) 0 ∂Q := by + rw [hQeq, integral_withDensity_eq_integral_toReal_smul hdens.ennreal_ofReal + (ae_of_all _ fun _ ↦ ENNReal.ofReal_lt_top)] + refine integral_congr_ae (ae_of_all _ fun ω ↦ ?_) + dsimp only + rw [ENNReal.toReal_ofReal (Real.exp_pos _).le, smul_eq_mul] + -- the payoff factors pointwise + have hpt (ω : Ω) : Real.exp (-(r * T)) * + max (bsTerminal S1 r σ₁ T (W₁ ω) - bsTerminal S2 r σ₂ T (W₂ ω)) 0 + = S2 * (Real.exp (σ₂ * Real.sqrt T * (p * W₁ ω + q * W₂ ω) + - σ₂ ^ 2 * T * (1 - k ^ 2) / 2) * + (Real.exp (c * (a * W₁ ω + b * W₂ ω) - c ^ 2 / 2) * + max (bsTerminal (S1 / S2) 0 σeff T (a * W₁ ω + b * W₂ ω - c) - 1) 0)) := by + have hs2 : 0 < bsTerminal S2 r σ₂ T (W₂ ω) := mul_pos hS2 (Real.exp_pos _) + have hratio : bsTerminal S1 r σ₁ T (W₁ ω) / bsTerminal S2 r σ₂ T (W₂ ω) + = bsTerminal (S1 / S2) 0 σeff T (a * W₁ ω + b * W₂ ω - c) := by + rw [bsTerminal_div_bsTerminal (W₁ ω) (W₂ ω) hσeff hT.le hσeff_sq, hWform, hcdef] + have hexp : Real.exp (-(r * T)) * bsTerminal S2 r σ₂ T (W₂ ω) + = S2 * (Real.exp (σ₂ * Real.sqrt T * (p * W₁ ω + q * W₂ ω) + - σ₂ ^ 2 * T * (1 - k ^ 2) / 2) * + Real.exp (c * (a * W₁ ω + b * W₂ ω) - c ^ 2 / 2)) := by + unfold bsTerminal + rw [mul_left_comm, ← Real.exp_add, ← Real.exp_add] + congr 2 + rw [hc, hp, hq] + linear_combination (σ₂ ^ 2 * k ^ 2 / 2) * Real.sq_sqrt hT.le + rw [exchange_payoff_eq_ratio _ _ hs2, hratio, ← mul_assoc, hexp] + ring + calc ∫ ω, Real.exp (-(r * T)) * + max (bsTerminal S1 r σ₁ T (W₁ ω) - bsTerminal S2 r σ₂ T (W₂ ω)) 0 ∂P + = S2 * ((∫ ω, Real.exp (σ₂ * Real.sqrt T * (p * W₁ ω + q * W₂ ω) + - σ₂ ^ 2 * T * (1 - k ^ 2) / 2) ∂P) * + ∫ ω, Real.exp (c * (a * W₁ ω + b * W₂ ω) - c ^ 2 / 2) * + max (bsTerminal (S1 / S2) 0 σeff T (a * W₁ ω + b * W₂ ω - c) - 1) 0 ∂P) := by + simp_rw [hpt] + rw [integral_const_mul] + congr 1 + exact hind.integral_fun_comp_mul_comp + (f := fun v ↦ Real.exp (σ₂ * Real.sqrt T * v - σ₂ ^ 2 * T * (1 - k ^ 2) / 2)) + (g := fun w ↦ Real.exp (c * w - c ^ 2 / 2) * + max (bsTerminal (S1 / S2) 0 σeff T (w - c) - 1) 0) + hVmeas.aemeasurable hWmeas.aemeasurable + (Continuous.aestronglyMeasurable (by fun_prop)) + (Continuous.aestronglyMeasurable (by unfold bsTerminal; fun_prop)) + _ = margrabePrice S1 S2 σeff T := by + rw [hfV, hgW, one_mul] + exact margrabe_price_via_call hS2 hbs + +/-- **The better-of-two option in the two-GBM model**: with the model of +`margrabe_exchange_price` and `σ₂ > 0`, +`𝔼_P[e^{−rT}·max(S¹_T, S²_T)] = S²₀ + margrabePrice S¹₀ S²₀ σ_eff T`, from +`max(x, y) = y + max(x − y, 0)`, `𝔼_P[e^{−rT}S²_T] = S²₀` (`discounted_terminal_eq_S0`) and +`margrabe_exchange_price`. -/ +theorem integral_betterOfTwo + {W₁ W₂ : Ω → ℝ} {σ₁ σ₂ ρ σeff S1 S2 r T : ℝ} + (hjoint : HasGaussianLaw (fun ω ↦ (W₁ ω, W₂ ω)) P) + (hW₁meas : Measurable W₁) (hW₂meas : Measurable W₂) + (hW₁ : HasLaw W₁ (gaussianReal 0 1) P) (hW₂ : HasLaw W₂ (gaussianReal 0 1) P) + (hcov : cov[W₁, W₂; P] = ρ) (hS1 : 0 < S1) (hS2 : 0 < S2) (hσ₂ : 0 < σ₂) + (hσeff : 0 < σeff) (hT : 0 < T) + (hσeff_sq : σeff ^ 2 = σ₁ ^ 2 + σ₂ ^ 2 - 2 * ρ * σ₁ * σ₂) : + ∫ ω, Real.exp (-(r * T)) * + max (bsTerminal S1 r σ₁ T (W₁ ω)) (bsTerminal S2 r σ₂ T (W₂ ω)) ∂P + = S2 + margrabePrice S1 S2 σeff T := by + have hsplit (ω : Ω) : Real.exp (-(r * T)) * + max (bsTerminal S1 r σ₁ T (W₁ ω)) (bsTerminal S2 r σ₂ T (W₂ ω)) + = Real.exp (-(r * T)) * bsTerminal S2 r σ₂ T (W₂ ω) + Real.exp (-(r * T)) * + max (bsTerminal S1 r σ₁ T (W₁ ω) - bsTerminal S2 r σ₂ T (W₂ ω)) 0 := by + rw [← mul_add] + congr 1 + rw [← max_add_add_left, add_sub_cancel, add_zero] + have h₁ : Integrable (fun ω ↦ bsTerminal S1 r σ₁ T (W₁ ω)) P := + integrable_bsTerminal hW₁ _ _ _ _ + have h₂ : Integrable (fun ω ↦ bsTerminal S2 r σ₂ T (W₂ ω)) P := + integrable_bsTerminal hW₂ _ _ _ _ + simp_rw [hsplit] + rw [integral_add (h₂.const_mul _) ((h₁.sub' h₂).pos_part.const_mul _), + discounted_terminal_eq_S0 (K := 1) ⟨hS2, one_pos, hσ₂, hT, hW₂⟩, + margrabe_exchange_price hjoint hW₁meas hW₂meas hW₁ hW₂ hcov hS1 hS2 hσeff hT hσeff_sq] + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/MonteCarloPricer.lean b/LeanPool/MathFin/Models/BlackScholes/MonteCarloPricer.lean new file mode 100644 index 0000000000..ebf08ddbfe --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/MonteCarloPricer.lean @@ -0,0 +1,1240 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Put +public import LeanPool.MathFin.Models.BlackScholes.PutGreeks +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.Probability.CentralLimitTheorem +public import Mathlib.Probability.Independence.InfinitePi +public import Mathlib.Probability.StrongLaw + +/-! +# Monte Carlo pricing of the European put + +The estimator theorem every desk prices by. For a standard-normal ensemble +`Z : ℕ → Ω → ℝ` and the discounted European put payoff + + `payoff z = e^{-rT} · max(K − S_T(z), 0)`, `S_T z = bsTerminal S₀ r σ T z`, + +this module proves, end to end: + +* **Consistency (strong law).** the sample-mean estimator converges almost surely to + `𝔼[payoff]` — which, by `bs_put_formula`, is exactly the Black–Scholes put price + `K·e^{-rT}·Φ(−d₂) − S₀·Φ(−d₁)`. The law used is Mathlib's Etemadi strong law + (`strong_law_ae_real`): only **pairwise** independence is hypothesised + (`consistency`); full independence gives the familiar specialization + (`consistency_iid`). Antithetic pairs `Z (2k+1) = −Z (2k)` are not pairwise + independent, so they are not covered. +* **Error bars (CLT).** `√n · (estimator n − P) ⇒ 𝓝(0, σ_H²)` in distribution via + Mathlib's `tendstoInDistribution_inv_sqrt_mul_sum_sub` (`clt`, library form + `clt_library`), with the limit variance **identified in closed form** (`variance`): + `σ_H² = e^{-2rT}·M₂ − P²`, where + + `M₂ = K²·Φ(−d₂) − 2·K·S₀·e^{μ+ν²/2}·Φ(−d₁) + S₀²·e^{2μ+2ν²}·Φ(−d₁−ν)`, + + with `μ = (r − σ²/2)T`, `ν = σ√T` — the truncated second moment of the lognormal + (`secondMoment_payoff`, computed from `integral_exp_mul_gaussianPDFReal_Iic`, the + same completing-the-square atom `Put.lean` prices with), discounted (`secondMoment`). +* **The BS bridge.** the mean of one sampled payoff is the put price itself + (`mean_eq_bsPut`), and the payoff is bounded (`0 ≤ payoff ≤ e^{-rT}·K`, + `payoff_le`), which licenses integrability (`integrable_payoff`) and `L²` + membership (`memLp2_payoff`) — exactly the strong-law and CLT hypotheses. + +Scope: the general theorems take the ensemble as a hypothesis — `consistency` takes +pairwise independence (`∀ i j, i ≠ j → Z i ⟂ᵢ[μ] Z j`) plus identical standard-normal +laws, `consistency_iid`/`clt` take the i.i.d. bundle `iIndepFun Z μ`. The last section +discharges these hypotheses on a canonical space: under Mathlib's countable product +`Measure.infinitePi` of standard normals on `ℕ → ℝ` (`canonicalEnsemble`) the coordinates +are i.i.d. `N(0, 1)`, and there, with no ensemble hypothesis, the put and call estimators +converge almost surely to the closed forms `bsP` and `bsV` (`consistency_canonical`, +`mc_call_consistency_canonical`) and the call estimator satisfies the CLT centred at `bsV` +(`mc_call_clt_canonical`). The multi-dimensional seed below +still hypothesizes its draws, `Measure.pi` giving only the law of one draw. Variance reduction +and multi-dimensional closed forms are future layers. + +## Main definitions + +* `payoff`: the discounted European put payoff `e^{−rT} · max(K − S_T(z), 0)` as a function of the + standard-normal draw `z`. +* `estimator`: the Monte Carlo estimator, the sample mean of `n` discounted put payoffs. +* `mcCallPayoff`: the discounted European call payoff `e^{−rT} · max(S_T(z) − K, 0)`. +* `mcCallMean`: the Monte Carlo estimator for the call, the sample mean of `n` discounted call + payoffs. +* `multiGauss`: the `d`-dimensional standard Gaussian, the product of `d` standard normals on + `Fin d → ℝ`. +* `canonicalEnsemble`: the canonical sample space of sequences `ℕ → ℝ` under the product of + countably many standard normals. + +## Main results + +Public API (all in `namespace MathFin.MonteCarlo`): + +* `payoff_le` — the discounted-strike pointwise bound `payoff ≤ e^{-rT}·K`; +* `integrable_payoff`, `memLp2_payoff` — the strong-law (`L¹`) and CLT (`L²`) + integrability of the sampled payoff; +* `mean_eq_bsPut` — the bridge: `𝔼[payoff] = K·e^{-rT}·Φ(−d₂) − S₀·Φ(−d₁)`; +* `consistency` — a.s. convergence of the estimator to the Black–Scholes put price + under **pairwise** independence (Etemadi's strong law); +* `consistency_iid` — the full-independence specialization; +* `clt_library` — the library-form CLT `(√n)⁻¹·(∑_{i −d₂}`, so the completing-the-square + atom is the `Ioi` sibling `integral_exp_mul_gaussianPDFReal_Ioi`, with + `gaussianReal_Ioi_toReal` for the strike piece. -/ + +/-- The discounted European call payoff as a function of the standard-normal draw: +`C(z) = e^{-rT} · max(S_T(z) − K, 0)`. -/ +noncomputable def mcCallPayoff (S_0 K r σ T z : ℝ) : ℝ := + Real.exp (-r * T) * max (bsTerminal S_0 r σ T z - K) 0 + +/-- The discounted call payoff is nonnegative. -/ +private lemma mcCallPayoff_nonneg (S_0 K r σ T z : ℝ) : + 0 ≤ mcCallPayoff S_0 K r σ T z := by + unfold mcCallPayoff + exact mul_nonneg (Real.exp_pos _).le (le_max_right _ _) + +/-- **The call payoff is dominated by the discounted terminal**: `C ≤ e^{-rT}·S_T`. +The unbounded-but-integrable envelope that replaces the put's constant bound. -/ +private lemma mcCallPayoff_le_terminal {S_0 K : ℝ} (hS_0 : 0 < S_0) (hK : 0 ≤ K) + (r σ T z : ℝ) : + mcCallPayoff S_0 K r σ T z ≤ Real.exp (-r * T) * bsTerminal S_0 r σ T z := by + unfold mcCallPayoff + refine mul_le_mul_of_nonneg_left ?_ (Real.exp_pos _).le + exact max_le (sub_le_self _ hK) (terminal_nonneg hS_0.le r σ T z) + +/-- The call payoff is a measurable (indeed continuous) function of the draw. -/ +private lemma measurable_mcCallPayoff (S_0 K r σ T : ℝ) : + Measurable (mcCallPayoff S_0 K r σ T) := by + unfold mcCallPayoff bsTerminal + fun_prop + +section CallDraw +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + +omit [IsProbabilityMeasure μ] in +/-- Law-transfer of a.e. strong measurability: if `Z` has law `ν` and `g` is a.e. +strongly measurable for `ν`, then `g ∘ Z` is a.e. strongly measurable. -/ +lemma aestronglyMeasurable_comp_of_hasLaw (hZ : HasLaw Z (gaussianReal 0 1) μ) + {g : ℝ → ℝ} (hg : AEStronglyMeasurable g (gaussianReal 0 1)) : + AEStronglyMeasurable (fun ω ↦ g (Z ω)) μ := + ((HasLaw.comp (Y := g) + (⟨hg.aemeasurable, rfl⟩ : + HasLaw g ((gaussianReal 0 1).map g) (gaussianReal 0 1)) + hZ).aemeasurable.aestronglyMeasurable) + +/-- Single draw: the sampled call payoff is a.e. strongly measurable. -/ +private theorem aestronglyMeasurable_mcCallPayoff (h : BSCallHyp μ S_0 K r σ T Z) : + AEStronglyMeasurable (fun ω ↦ mcCallPayoff S_0 K r σ T (Z ω)) μ := + aestronglyMeasurable_comp_of_hasLaw h.Z_law + (by unfold mcCallPayoff bsTerminal; fun_prop) + +/-- **Integrability of the squared terminal** — the L² envelope: `S_T²` is +integrable, being `S₀²·e^{2μ_log}·exp(2ν·Z)` with `exp(2ν·Z)` Gaussian-integrable. +(Facts not numbers: no closed form needed here — the closed form is +`secondMoment_terminal`.) -/ +theorem integrable_sq_terminal (h : BSCallHyp μ S_0 K r σ T Z) : + Integrable (fun ω ↦ (bsTerminal S_0 r σ T (Z ω)) ^ 2) μ := by + obtain ⟨hS_0, hK, hσ, hT, hZ⟩ := h + have hsrc : Integrable (fun x : ℝ ↦ S_0 ^ 2 * Real.exp (2 * (r - σ^2 / 2) * T) + * Real.exp ((2 * σ * Real.sqrt T) * x)) (μ.map Z) := by + rw [hZ.map_eq] + exact (integrable_exp_mul_gaussianReal (2 * σ * Real.sqrt T)).const_mul _ + have hcomp := (integrable_map_measure hsrc.aestronglyMeasurable hZ.aemeasurable).mp hsrc + have hpt : ∀ ω : Ω, (fun x : ℝ ↦ S_0 ^ 2 * Real.exp (2 * (r - σ^2 / 2) * T) + * Real.exp ((2 * σ * Real.sqrt T) * x)) (Z ω) + = (bsTerminal S_0 r σ T (Z ω)) ^ 2 := by + intro ω + have e1 : Real.exp (2 * (r - σ^2 / 2) * T + (2 * σ * Real.sqrt T) * Z ω) + = Real.exp (2 * (r - σ^2 / 2) * T) * Real.exp ((2 * σ * Real.sqrt T) * Z ω) := + Real.exp_add _ _ + have e2 : Real.exp (((r - σ^2 / 2) * T + σ * Real.sqrt T * Z ω) + + ((r - σ^2 / 2) * T + σ * Real.sqrt T * Z ω)) + = Real.exp ((r - σ^2 / 2) * T + σ * Real.sqrt T * Z ω) + * Real.exp ((r - σ^2 / 2) * T + σ * Real.sqrt T * Z ω) := + Real.exp_add _ _ + have e3 : ((r - σ^2 / 2) * T + σ * Real.sqrt T * Z ω) + + ((r - σ^2 / 2) * T + σ * Real.sqrt T * Z ω) + = 2 * (r - σ^2 / 2) * T + (2 * σ * Real.sqrt T) * Z ω := by ring + have e5 : Real.exp ((r - σ^2 / 2) * T + σ * Real.sqrt T * Z ω) ^ 2 + = Real.exp ((r - σ^2 / 2) * T + σ * Real.sqrt T * Z ω) + * Real.exp ((r - σ^2 / 2) * T + σ * Real.sqrt T * Z ω) := + pow_two _ + unfold bsTerminal + rw [mul_pow, e5, ← e2, e3, e1] + ring + have hae : (fun x : ℝ ↦ S_0 ^ 2 * Real.exp (2 * (r - σ^2 / 2) * T) + * Real.exp ((2 * σ * Real.sqrt T) * x)) ∘ Z + =ᵐ[μ] (fun ω ↦ (bsTerminal S_0 r σ T (Z ω)) ^ 2) := + Filter.Eventually.of_forall fun ω ↦ hpt ω + exact (integrable_congr hae).mp hcomp + +/-- **Integrability of the discounted terminal** — the domination envelope +`e^{-rT}·S_T` for the call payoff (the put used the constant `e^{-rT}·K`; the call's +envelope is genuinely unbounded). -/ +theorem integrable_discountedTerminal (h : BSCallHyp μ S_0 K r σ T Z) : + Integrable (fun ω ↦ Real.exp (-r * T) * bsTerminal S_0 r σ T (Z ω)) μ := + (integrable_bsTerminal h.Z_law S_0 r σ T).const_mul _ + +/-- **The discounted-forward identity**: `E[e^{-rT}·S_T] = S₀`. The risk-neutral +engine's spot-price identity, read off the same transfer that proves integrability: +`e^{-rT}·S₀·e^{(r−σ²/2)T}·e^{σ²T/2} = S₀`. -/ +theorem integral_discountedTerminal_eq (h : BSCallHyp μ S_0 K r σ T Z) : + ∫ ω, Real.exp (-r * T) * bsTerminal S_0 r σ T (Z ω) ∂μ = S_0 := by + obtain ⟨hS_0, hK, hσ, hT, hZ⟩ := h + have hmeas : AEStronglyMeasurable + (fun z : ℝ ↦ Real.exp (-r * T) * bsTerminal S_0 r σ T z) (gaussianReal 0 1) := by + unfold bsTerminal + fun_prop + rw [show (fun ω ↦ Real.exp (-r * T) * bsTerminal S_0 r σ T (Z ω)) + = (fun z ↦ Real.exp (-r * T) * bsTerminal S_0 r σ T z) ∘ Z from rfl, + hZ.integral_comp hmeas, + integral_gaussianReal_eq_integral_smul (one_ne_zero : (1 : ℝ≥0) ≠ 0)] + have hsplit : ∀ z : ℝ, + gaussianPDFReal 0 1 z • (Real.exp (-r * T) * bsTerminal S_0 r σ T z) + = (S_0 * (Real.exp ((r - σ^2 / 2) * T) * Real.exp (-r * T))) + * (Real.exp (σ * Real.sqrt T * z) * gaussianPDFReal 0 1 z) := by + intro z + unfold bsTerminal + rw [smul_eq_mul, Real.exp_add] + ring + rw [integral_congr_ae (Filter.Eventually.of_forall hsplit), integral_const_mul, + integral_exp_mul_gaussianPDFReal_univ] + have hν : (σ * Real.sqrt T) ^ 2 = σ ^ 2 * T := by + rw [mul_pow, Real.sq_sqrt hT.le] + have h0 : (r - σ^2 / 2) * T + -r * T + (σ * Real.sqrt T) ^ 2 / 2 = 0 := by + rw [hν]; ring + have hsplit2 : S_0 * (Real.exp ((r - σ^2 / 2) * T) * Real.exp (-r * T)) + * Real.exp ((σ * Real.sqrt T) ^ 2 / 2) = S_0 := by + rw [mul_assoc, ← Real.exp_add, ← Real.exp_add, h0, Real.exp_zero, mul_one] + rw [hsplit2] + +/-- **Call integrability**: the sampled call payoff is integrable (`integrable_bsCall_payoff`) — +the honest case, where boundedness fails. -/ +theorem integrable_mcCallPayoff (h : BSCallHyp μ S_0 K r σ T Z) : + Integrable (fun ω ↦ mcCallPayoff S_0 K r σ T (Z ω)) μ := + integrable_bsCall_payoff h.Z_law S_0 K r σ T + +/-- The sampled call payoff is in L² — the CLT hypothesis, proved by domination +`‖C‖² ≤ (e^{-rT}·S_T)²` with `S_T²` integrable (`memLp_two_iff_integrable_sq_norm` +is the bridge; no constant bound exists). -/ +theorem memLp2_mcCallPayoff (h : BSCallHyp μ S_0 K r σ T Z) : + MemLp (fun ω ↦ mcCallPayoff S_0 K r σ T (Z ω)) 2 μ := by + have hdom : Integrable + (fun ω ↦ (Real.exp (-r * T) * bsTerminal S_0 r σ T (Z ω)) ^ 2) μ := by + have h0 : Integrable + (fun ω ↦ Real.exp (-r * T) ^ 2 * (bsTerminal S_0 r σ T (Z ω)) ^ 2) μ := + (integrable_sq_terminal h).const_mul _ + refine (integrable_congr (Filter.Eventually.of_forall ?_)).mp h0 + intro ω + exact (mul_pow (Real.exp (-r * T)) (bsTerminal S_0 r σ T (Z ω)) 2).symm + have haes2 : AEStronglyMeasurable (fun x ↦ mcCallPayoff S_0 K r σ T (Z x) ^ 2) μ := + aestronglyMeasurable_comp_of_hasLaw + (g := fun z ↦ mcCallPayoff S_0 K r σ T z ^ 2) h.Z_law + (by unfold mcCallPayoff bsTerminal; fun_prop) + have hint2 : Integrable (fun x ↦ mcCallPayoff S_0 K r σ T (Z x) ^ 2) μ := by + refine hdom.mono' haes2 ?_ + filter_upwards with ω + have hpos : 0 ≤ Real.exp (-r * T) * bsTerminal S_0 r σ T (Z ω) := + mul_nonneg (Real.exp_pos _).le (terminal_nonneg h.S_0_pos.le r σ T _) + have habs : |mcCallPayoff S_0 K r σ T (Z ω)| + ≤ |Real.exp (-r * T) * bsTerminal S_0 r σ T (Z ω)| := by + rw [abs_of_nonneg (mcCallPayoff_nonneg S_0 K r σ T _), abs_of_nonneg hpos] + exact mcCallPayoff_le_terminal h.S_0_pos h.K_pos.le r σ T _ + rw [Real.norm_eq_abs, + abs_of_nonneg (sq_nonneg (mcCallPayoff S_0 K r σ T (Z ω)))] + exact sq_le_sq.2 habs + rw [memLp_two_iff_integrable_sq_norm (aestronglyMeasurable_mcCallPayoff h)] + refine (integrable_congr ?_).mp hint2 + filter_upwards with ω + change mcCallPayoff S_0 K r σ T (Z ω) ^ 2 = ‖mcCallPayoff S_0 K r σ T (Z ω)‖ ^ 2 + rw [Real.norm_eq_abs, sq_abs] + +/-- The mean of one sampled call payoff is the Black–Scholes call price: MathFin's +`bs_call_formula` — the expectation-form bridge, sibling of the put's. -/ +theorem mean_mcCallPayoff_eq_bsCall (h : BSCallHyp μ S_0 K r σ T Z) : + ∫ ω, mcCallPayoff S_0 K r σ T (Z ω) ∂μ + = S_0 * Phi (bsd1 S_0 K r σ T) + - K * Real.exp (-r * T) * Phi (bsd2 S_0 K r σ T) := by + simpa only [mcCallPayoff] using bs_call_formula h + +end CallDraw + +/-! ### The call ensemble: consistency (strong law) and error bars (CLT) -/ + +section CallEnsemble +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {S_0 K r σ T : ℝ} {Z : ℕ → Ω → ℝ} + +omit [IsProbabilityMeasure μ] in +/-- All sampled call payoffs have the same pushforward law. -/ +private theorem hasLaw_mcCallPayoff (hlaw : ∀ i : ℕ, HasLaw (Z i) (gaussianReal 0 1) μ) + (i : ℕ) : + HasLaw (fun ω ↦ mcCallPayoff S_0 K r σ T (Z i ω)) + ((gaussianReal 0 1).map (mcCallPayoff S_0 K r σ T)) μ := + HasLaw.comp (Y := mcCallPayoff S_0 K r σ T) + (⟨(measurable_mcCallPayoff S_0 K r σ T).aemeasurable, rfl⟩ : + HasLaw (mcCallPayoff S_0 K r σ T) ((gaussianReal 0 1).map (mcCallPayoff S_0 K r σ T)) + (gaussianReal 0 1)) + (hlaw i) + +omit [IsProbabilityMeasure μ] in +/-- The sampled call payoffs are identically distributed. -/ +private theorem identDistrib_mcCallPayoff + (hlaw : ∀ i : ℕ, HasLaw (Z i) (gaussianReal 0 1) μ) (i : ℕ) : + IdentDistrib (fun ω ↦ mcCallPayoff S_0 K r σ T (Z i ω)) + (fun ω ↦ mcCallPayoff S_0 K r σ T (Z 0 ω)) μ μ := + HasLaw.identDistrib (hasLaw_mcCallPayoff hlaw i) (hasLaw_mcCallPayoff hlaw 0) + +omit [IsProbabilityMeasure μ] in +/-- Full independence of the ensemble transfers through the call payoff map. -/ +private theorem iIndepFun_mcCallPayoff (hindep : iIndepFun Z μ) : + iIndepFun (fun i ↦ fun ω ↦ mcCallPayoff S_0 K r σ T (Z i ω)) μ := + hindep.comp (fun _ ↦ mcCallPayoff S_0 K r σ T) + (fun _ ↦ measurable_mcCallPayoff S_0 K r σ T) + +omit [IsProbabilityMeasure μ] in +/-- Pairwise independence of the ensemble transfers through the call payoff map — +the Etemadi hypothesis the strong law consumes. -/ +private theorem pairwise_mcCallPayoff (hindep : _root_.Pairwise ((· ⟂ᵢ[μ] ·) on Z)) : + ∀ i j : ℕ, i ≠ j → + (fun ω ↦ mcCallPayoff S_0 K r σ T (Z i ω)) ⟂ᵢ[μ] + (fun ω ↦ mcCallPayoff S_0 K r σ T (Z j ω)) := by + intro i j hij + exact (hindep hij).comp (measurable_mcCallPayoff S_0 K r σ T) + (measurable_mcCallPayoff S_0 K r σ T) + +/-- The Monte Carlo estimator for the call: the sample mean of `n` discounted call +payoffs. -/ +noncomputable def mcCallMean (S_0 K r σ T : ℝ) {Ω : Type*} (Z : ℕ → Ω → ℝ) (n : ℕ) + (ω : Ω) : ℝ := + (∑ i ∈ Finset.range n, mcCallPayoff S_0 K r σ T (Z i ω)) / (n : ℝ) + +/-- **Monte Carlo consistency for the call.** + +Under only **pairwise** independence of the standard-normal ensemble (Etemadi's +strong law; antithetic pairs, being dependent, are not covered) and the risk-neutral +lognormal model, the sample-mean estimator converges almost surely to the +Black–Scholes call price `S₀·Φ(d₁) − K·e^{-rT}·Φ(d₂)`. -/ +theorem mc_call_consistency (h : BSCallHyp μ S_0 K r σ T (Z 0)) + (hlaw : ∀ i : ℕ, HasLaw (Z i) (gaussianReal 0 1) μ) + (hindep : _root_.Pairwise ((· ⟂ᵢ[μ] ·) on Z)) : + ∀ᵐ ω ∂μ, Tendsto (fun n ↦ mcCallMean S_0 K r σ T Z n ω) atTop + (𝓝 (S_0 * Phi (bsd1 S_0 K r σ T) + - K * Real.exp (-r * T) * Phi (bsd2 S_0 K r σ T))) := by + have hint : Integrable (fun ω ↦ mcCallPayoff S_0 K r σ T (Z 0 ω)) μ := + integrable_mcCallPayoff h + have hslln := strong_law_ae_real + (X := fun i ↦ fun ω ↦ mcCallPayoff S_0 K r σ T (Z i ω)) + hint (pairwise_mcCallPayoff hindep) (fun i ↦ identDistrib_mcCallPayoff hlaw i) + filter_upwards [hslln] with ω hω + rw [← mean_mcCallPayoff_eq_bsCall (Z := Z 0) h] + exact hω.congr fun _ ↦ rfl + +/-- The i.i.d. specialization for the call: full independence gives the pairwise +hypothesis. -/ +theorem mc_call_consistency_iid (h : BSCallHyp μ S_0 K r σ T (Z 0)) + (hlaw : ∀ i : ℕ, HasLaw (Z i) (gaussianReal 0 1) μ) + (hindep : iIndepFun Z μ) : + ∀ᵐ ω ∂μ, Tendsto (fun n ↦ mcCallMean S_0 K r σ T Z n ω) atTop + (𝓝 (S_0 * Phi (bsd1 S_0 K r σ T) + - K * Real.exp (-r * T) * Phi (bsd2 S_0 K r σ T))) := by + refine mc_call_consistency h hlaw ?_ + intro i j hij + exact hindep.indepFun hij + +/-- **Monte Carlo error bars for the call** — the library-form CLT: +`(√n)⁻¹ · (∑_{i −d₂}` (the `Ioi` mirror of the put's `Iic` computation). -/ + +section CallMoments +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + +/-- **Truncated second moment of the lognormal, call side**: + + `𝔼[(S_T − K)⁺²] = S₀²·e^{2μ + 2ν²}·Φ(d₁ + ν) − 2·K·S₀·e^{μ + ν²/2}·Φ(d₁) + + K²·Φ(d₂)`, + +with `μ = (r − σ²/2)T`, `ν = σ√T`, computed from the `Ioi` completing-the-square +primitive `integral_exp_mul_gaussianPDFReal_Ioi` (the call's exercise region +`{z > −d₂}` is a right tail) and `gaussianReal_Ioi_toReal` for the strike piece. -/ +theorem secondMoment_callPayoff (h : BSCallHyp μ S_0 K r σ T Z) : + ∫ ω, (max (bsTerminal S_0 r σ T (Z ω) - K) 0) ^ 2 ∂μ + = S_0 ^ 2 * Real.exp (2 * (r - σ^2 / 2) * T + 2 * (σ * Real.sqrt T)^2) + * Phi (bsd1 S_0 K r σ T + σ * Real.sqrt T) + - 2 * K * (S_0 * Real.exp ((r - σ^2 / 2) * T + (σ * Real.sqrt T)^2 / 2)) + * Phi (bsd1 S_0 K r σ T) + + K ^ 2 * Phi (bsd2 S_0 K r σ T) := by + obtain ⟨hS_0, hK, hσ, hT, hZ⟩ := h + set d_2 := bsd2 S_0 K r σ T with d_2_def + set μ_log := (r - σ^2 / 2) * T with μ_log_def + set ν_log := σ * Real.sqrt T with ν_log_def + have hν_log_sq : ν_log ^ 2 = σ ^ 2 * T := by + rw [ν_log_def, mul_pow, Real.sq_sqrt hT.le] + have h_shift1 : ν_log - (-d_2) = bsd1 S_0 K r σ T := by + rw [ν_log_def, d_2_def, bsd2, bsd1] + ring + have h_shift2 : 2 * ν_log - (-d_2) = bsd1 S_0 K r σ T + ν_log := by + rw [ν_log_def, d_2_def, bsd2, bsd1] + ring + have hmeas : AEStronglyMeasurable + (fun z : ℝ ↦ (max (bsTerminal S_0 r σ T z - K) 0) ^ 2) (gaussianReal 0 1) := by + unfold bsTerminal + fun_prop + -- Step 1-2: transfer to the standard normal, convert to the density + rw [show (fun ω ↦ (max (bsTerminal S_0 r σ T (Z ω) - K) 0) ^ 2) + = (fun z ↦ (max (bsTerminal S_0 r σ T z - K) 0) ^ 2) ∘ Z from rfl, + hZ.integral_comp hmeas, + integral_gaussianReal_eq_integral_smul (one_ne_zero : (1 : ℝ≥0) ≠ 0)] + -- Step 3: the square lives on the exercise region `{z > −d₂}` + rw [show (fun z : ℝ ↦ gaussianPDFReal 0 1 z • (max (bsTerminal S_0 r σ T z - K) 0) ^ 2) + = (Set.Ioi (-d_2)).indicator + (fun z ↦ gaussianPDFReal 0 1 z * (bsTerminal S_0 r σ T z - K) ^ 2) from + funext fun z ↦ by + rw [smul_eq_mul] + by_cases hz : z ∈ Set.Ioi (-d_2) + · have h1 : K < bsTerminal S_0 r σ T z ↔ -d_2 < z := + bsTerminal_gt_K_iff hS_0 hK hσ hT z + have hST : K < bsTerminal S_0 r σ T z := h1.mpr hz + rw [Set.indicator_of_mem (by simpa using hz : z ∈ Set.Ioi (-d_2)), + max_eq_left (sub_nonneg.mpr (le_of_lt hST))] + · have h1 : K < bsTerminal S_0 r σ T z ↔ -d_2 < z := + bsTerminal_gt_K_iff hS_0 hK hσ hT z + have hST : bsTerminal S_0 r σ T z ≤ K := + le_of_not_gt fun hc ↦ hz (h1.mp hc) + rw [Set.indicator_of_notMem (by simpa using hz : z ∉ Set.Ioi (-d_2)), + max_eq_right (sub_nonpos.mpr hST), + zero_pow (by norm_num), mul_zero]] + rw [integral_indicator measurableSet_Ioi] + -- Step 4: expand the square inside the exercise region + have h_expand : ∀ z ∈ Set.Ioi (-d_2), + gaussianPDFReal 0 1 z * (bsTerminal S_0 r σ T z - K) ^ 2 + = (S_0 ^ 2 * Real.exp (2 * μ_log)) * (Real.exp (2 * ν_log * z) * gaussianPDFReal 0 1 z) + - (2 * K * (S_0 * Real.exp μ_log)) * (Real.exp (ν_log * z) * gaussianPDFReal 0 1 z) + + K ^ 2 * gaussianPDFReal 0 1 z := by + intro z _ + have hexp : Real.exp ((r - σ^2 / 2) * T + σ * Real.sqrt T * z) + = Real.exp μ_log * Real.exp (ν_log * z) := by + rw [μ_log_def, ν_log_def, Real.exp_add] + have hexp2 : Real.exp (2 * ν_log * z) + = Real.exp (ν_log * z) * Real.exp (ν_log * z) := by + rw [← Real.exp_add] + congr 1 + ring + have hexp3 : Real.exp (2 * μ_log) + = Real.exp μ_log * Real.exp μ_log := by + rw [← Real.exp_add] + congr 1 + ring + unfold bsTerminal + rw [hexp, hexp2, hexp3] + ring + rw [setIntegral_congr_fun measurableSet_Ioi h_expand] + -- Step 5: the three integrability pieces (the put's route, on `Ioi`) + have hint_pdf : IntegrableOn (gaussianPDFReal 0 1) (Set.Ioi (-d_2)) volume := + (integrable_gaussianPDFReal 0 1).integrableOn + have hint_eν : IntegrableOn + (fun z : ℝ ↦ Real.exp (ν_log * z) * gaussianPDFReal 0 1 z) (Set.Ioi (-d_2)) volume := by + refine (((integrable_gaussianPDFReal ν_log 1).const_mul + (Real.exp (ν_log ^ 2 / 2))).integrableOn).congr_fun ?_ measurableSet_Ioi + intro z _ + exact (exp_mul_gaussianPDFReal_zero_one ν_log z).symm + have hint_e2ν : IntegrableOn + (fun z : ℝ ↦ Real.exp (2 * ν_log * z) * gaussianPDFReal 0 1 z) + (Set.Ioi (-d_2)) volume := by + refine (((integrable_gaussianPDFReal (2 * ν_log) 1).const_mul + (Real.exp ((2 * ν_log) ^ 2 / 2))).integrableOn).congr_fun ?_ measurableSet_Ioi + intro z _ + exact (exp_mul_gaussianPDFReal_zero_one (2 * ν_log) z).symm + -- Step 6: linearity of the integral + rw [setIntegral_const_mul_sub_const_mul_add_const_mul hint_e2ν hint_eν hint_pdf + (S_0 ^ 2 * Real.exp (2 * μ_log)) (2 * K * (S_0 * Real.exp μ_log)) (K ^ 2)] + -- Step 7: the three Gaussian primitives — now the `Ioi` siblings + rw [show ∫ z in Set.Ioi (-d_2), Real.exp (2 * ν_log * z) * gaussianPDFReal 0 1 z + = Real.exp ((2 * ν_log) ^ 2 / 2) * Phi (2 * ν_log - (-d_2)) from + integral_exp_mul_gaussianPDFReal_Ioi _ _, + show ∫ z in Set.Ioi (-d_2), Real.exp (ν_log * z) * gaussianPDFReal 0 1 z + = Real.exp (ν_log ^ 2 / 2) * Phi (ν_log - (-d_2)) from + integral_exp_mul_gaussianPDFReal_Ioi _ _, + show ∫ z in Set.Ioi (-d_2), gaussianPDFReal 0 1 z = Phi d_2 from by + rw [setIntegral_gaussianPDFReal_eq_toReal measurableSet_Ioi (0 : ℝ), + gaussianReal_Ioi_toReal, neg_neg]] + rw [h_shift2, h_shift1, μ_log_def] + -- Step 8: final algebra — merge the exponentials + have h2ν : (2 * ν_log) ^ 2 / 2 = 2 * ν_log ^ 2 := by + have h4 : (2 * ν_log) ^ 2 = 4 * ν_log ^ 2 := by ring + rw [h4] + ring + have hm : Real.exp ((r - σ^2 / 2) * T) * Real.exp (ν_log ^ 2 / 2) + = Real.exp ((r - σ^2 / 2) * T + ν_log ^ 2 / 2) := (Real.exp_add _ _).symm + have hn : Real.exp (2 * (r - σ^2 / 2) * T) * Real.exp ((2 * ν_log) ^ 2 / 2) + = Real.exp (2 * (r - σ^2 / 2) * T + 2 * ν_log ^ 2) := by + rw [h2ν, Real.exp_add] + linear_combination (norm := ring_nf) + (S_0 ^ 2 * Phi (bsd1 S_0 K r σ T + ν_log)) * hn + - (2 * K * S_0 * Phi (bsd1 S_0 K r σ T)) * hm + +/-- **Discounted second moment** of the sampled call payoff: `𝔼[C²] = e^{-2rT}·M₂` +with `M₂` the call-side truncated second moment above. -/ +theorem secondMoment_mcCallPayoff (h : BSCallHyp μ S_0 K r σ T Z) : + ∫ ω, (mcCallPayoff S_0 K r σ T (Z ω)) ^ 2 ∂μ + = Real.exp (-2 * r * T) * + (S_0 ^ 2 * Real.exp (2 * (r - σ^2 / 2) * T + 2 * (σ * Real.sqrt T)^2) + * Phi (bsd1 S_0 K r σ T + σ * Real.sqrt T) + - 2 * K * (S_0 * Real.exp ((r - σ^2 / 2) * T + (σ * Real.sqrt T)^2 / 2)) + * Phi (bsd1 S_0 K r σ T) + + K ^ 2 * Phi (bsd2 S_0 K r σ T)) := by + have hexp2 : Real.exp (-r * T) ^ 2 = Real.exp (-2 * r * T) := by + rw [pow_two, ← Real.exp_add] + congr 1 + ring + have hsq : ∀ ω : Ω, (mcCallPayoff S_0 K r σ T (Z ω)) ^ 2 + = Real.exp (-2 * r * T) * (max (bsTerminal S_0 r σ T (Z ω) - K) 0) ^ 2 := by + intro ω + unfold mcCallPayoff + rw [mul_pow, hexp2] + rw [integral_congr_ae (Filter.Eventually.of_forall hsq), integral_const_mul, + secondMoment_callPayoff h] + +/-- **The CLT limit variance in closed form for the call**: +`σ_C² = e^{-2rT}·(call-side truncated second moment) − C_BS²`, composed from +`secondMoment_mcCallPayoff` (the truncated second moment) and `bs_call_formula` +(the price `C_BS`). -/ +theorem mc_call_variance (h : BSCallHyp μ S_0 K r σ T Z) : + Var[fun ω ↦ mcCallPayoff S_0 K r σ T (Z ω); μ] + = Real.exp (-2 * r * T) * + (S_0 ^ 2 * Real.exp (2 * (r - σ^2 / 2) * T + 2 * (σ * Real.sqrt T)^2) + * Phi (bsd1 S_0 K r σ T + σ * Real.sqrt T) + - 2 * K * (S_0 * Real.exp ((r - σ^2 / 2) * T + (σ * Real.sqrt T)^2 / 2)) + * Phi (bsd1 S_0 K r σ T) + + K ^ 2 * Phi (bsd2 S_0 K r σ T)) + - (S_0 * Phi (bsd1 S_0 K r σ T) + - K * Real.exp (-r * T) * Phi (bsd2 S_0 K r σ T)) ^ 2 := by + rw [variance_eq_sub (memLp2_mcCallPayoff h)] + change ∫ ω, mcCallPayoff S_0 K r σ T (Z ω) ^ 2 ∂μ + - (∫ ω, mcCallPayoff S_0 K r σ T (Z ω) ∂μ) ^ 2 = _ + rw [secondMoment_mcCallPayoff h, mean_mcCallPayoff_eq_bsCall h] + +end CallMoments + +/-! ### The multi-dimensional seed + +Mathlib's own product-measure layer carries the joint-vector bridge: +`Measure.pi` (finite products, `Mathlib/MeasureTheory/Constructions/Pi.lean`) and +`iIndepFun.hasLaw_pi` (`Mathlib/Probability/HasLaw.lean`): **the joint vector of d +independent scalars has the product law**. The seed theorem is the multi-D consistency +statement: pairwise-independent vector draws with law `multiGauss d`, any measurable +integrable payoff `H` of the whole vector, Etemadi strong law to `∫ H ∂(multiGauss d)`. +What it deliberately does NOT do: a closed-form multi-D price (the 1-D closed forms are +Gaussian-∫ specials; a multi-D closed form needs the multivariate-normal layer, which is +not bridged to `multiGauss` here) and a CLT for the multi-D estimator (for a scalar +payoff the 1-D CLT applies to `H ∘ W i` as in `clt_library`, not yet stated; a +vector-valued CLT would need the Cramér–Wold device, not coordinatewise limits). -/ + +/-- The `d`-dimensional standard Gaussian: the product of `d` standard normals on +`Fin d → ℝ` — the law of the joint vector of `d` independent standard normals +(`multiGauss_hasLaw_joint`). -/ +noncomputable def multiGauss (d : ℕ) : Measure (Fin d → ℝ) := + Measure.pi fun _ ↦ gaussianReal 0 1 + +instance multiGauss_instIsProbabilityMeasure (d : ℕ) : + IsProbabilityMeasure (multiGauss d) := by + unfold multiGauss + infer_instance + +section MultiD +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {d : ℕ} + +omit [IsProbabilityMeasure μ] in +/-- **The joint bridge**: the joint vector `(Z 0, …, Z (d−1))` of `d` independent +standard normals has the product law `multiGauss d` (Mathlib's `iIndepFun.hasLaw_pi`). -/ +theorem multiGauss_hasLaw_joint {Z : Fin d → Ω → ℝ} + (hlaw : ∀ j, HasLaw (Z j) (gaussianReal 0 1) μ) (hindep : iIndepFun Z μ) : + HasLaw (fun ω j ↦ Z j ω) (multiGauss d) μ := + hindep.hasLaw_pi hlaw + +omit [IsProbabilityMeasure μ] in +/-- **Multi-D consistency seed**: pairwise-independent draws `W i` with law +`multiGauss d` and any measurable integrable payoff `H` of the whole vector — +the sample mean converges almost surely to `∫ H ∂(multiGauss d)`. + +This is the same Etemadi route as the 1-D theorems, applied to the composed +variables `H ∘ W i`: integrability transfers through the law +(`integrable_map_measure`), pairwise independence through payoff measurability +(`IndepFun.comp`). The precise hypotheses for a full multi-D pricer: `H` +measurable + integrable against the product law (closed-form `∫ H` is a +multivariate-Gaussian computation, out of scope here), and independence in the +vector sense — `iIndepFun.hasLaw_pi`/`iIndepFun_iff_hasLaw_pi_pi` convert between +"d independent coordinates" and "one vector draw with product law". -/ +theorem multiD_consistency {W : ℕ → Ω → (Fin d → ℝ)} {H : (Fin d → ℝ) → ℝ} + (hHmeas : Measurable H) (hint : Integrable H (multiGauss d)) + (hlaw : ∀ i : ℕ, HasLaw (W i) (multiGauss d) μ) + (hindep : _root_.Pairwise ((· ⟂ᵢ[μ] ·) on W)) : + ∀ᵐ ω ∂μ, Tendsto (fun n : ℕ ↦ (∑ i ∈ Finset.range n, H (W i ω)) / (n : ℝ)) atTop + (𝓝 (∫ w, H w ∂(multiGauss d))) := by + have hint0 : Integrable (fun ω ↦ H (W 0 ω)) μ := by + have hl0 := hlaw 0 + have hmap : Integrable H (μ.map (W 0)) := by + rw [hl0.map_eq] + exact hint + exact (integrable_map_measure hmap.aestronglyMeasurable hl0.aemeasurable).mp hmap + have hpair : ∀ i j : ℕ, i ≠ j → + (fun ω ↦ H (W i ω)) ⟂ᵢ[μ] (fun ω ↦ H (W j ω)) := by + intro i j hij + exact (hindep hij).comp hHmeas hHmeas + have hident : ∀ i : ℕ, IdentDistrib (fun ω ↦ H (W i ω)) (fun ω ↦ H (W 0 ω)) μ μ := by + intro i + have hlawH : HasLaw H ((multiGauss d).map H) (multiGauss d) := + ⟨hHmeas.aemeasurable, rfl⟩ + exact HasLaw.identDistrib (hlawH.comp (hlaw i)) (hlawH.comp (hlaw 0)) + have hslln := strong_law_ae_real (fun i ↦ fun ω ↦ H (W i ω)) hint0 hpair hident + have heq : ∫ ω, H (W 0 ω) ∂μ = ∫ w, H w ∂(multiGauss d) := by + have hAESM : AEStronglyMeasurable H (μ.map (W 0)) := by + rw [(hlaw 0).map_eq] + exact hint.aestronglyMeasurable + rw [← integral_map (hlaw 0).aemeasurable hAESM, (hlaw 0).map_eq] + filter_upwards [hslln] with ω hω + have hω' : Tendsto (fun n : ℕ ↦ (∑ i ∈ Finset.range n, H (W i ω)) / (n : ℝ)) atTop + (𝓝 (∫ w, H w ∂(multiGauss d))) := by + rw [← heq] + exact hω + exact hω' + +omit [IsProbabilityMeasure μ] in +/-- The i.i.d. specialization of the multi-D seed. -/ +theorem multiD_consistency_iid {W : ℕ → Ω → (Fin d → ℝ)} {H : (Fin d → ℝ) → ℝ} + (hHmeas : Measurable H) (hint : Integrable H (multiGauss d)) + (hlaw : ∀ i : ℕ, HasLaw (W i) (multiGauss d) μ) + (hindep : iIndepFun W μ) : + ∀ᵐ ω ∂μ, Tendsto (fun n : ℕ ↦ (∑ i ∈ Finset.range n, H (W i ω)) / (n : ℝ)) atTop + (𝓝 (∫ w, H w ∂(multiGauss d))) := by + refine multiD_consistency hHmeas hint hlaw ?_ + intro i j hij + exact hindep.indepFun hij + +/-- The bounded-payoff instance of the seed's integrability hypothesis: any +a.e.-strongly-measurable payoff bounded by a constant (a **capped** claim — the +standard variance-reduction-friendly truncation of an unbounded payoff) is +integrable against the product law. -/ +theorem multiD_integrable_of_bounded {H : (Fin d → ℝ) → ℝ} + (hH : AEStronglyMeasurable H (multiGauss d)) (C : ℝ) + (hb : ∀ w : Fin d → ℝ, ‖H w‖ ≤ C) : Integrable H (multiGauss d) := + memLp_one_iff_integrable.1 (MemLp.of_bound hH C (Filter.Eventually.of_forall hb)) + +end MultiD + +/-! ### The canonical ensemble + +The ensemble theorems above hypothesize their draws. On the sequence space `ℕ → ℝ` under +Mathlib's countable product `Measure.infinitePi` of standard normals, the coordinate maps have +law `N(0, 1)` (`Measure.infinitePi_map_eval`) and are mutually independent +(`iIndepFun_infinitePi`), so every hypothesis is discharged. -/ + +section Canonical + +/-- The canonical Monte Carlo sample space: sequences `ω : ℕ → ℝ` under the product of +countably many standard normals (Mathlib's `Measure.infinitePi`); draw `i` is `ω i`. -/ +noncomputable def canonicalEnsemble : Measure (ℕ → ℝ) := + Measure.infinitePi fun _ ↦ gaussianReal 0 1 + +instance canonicalEnsemble_isProbabilityMeasure : IsProbabilityMeasure canonicalEnsemble := by + unfold canonicalEnsemble + infer_instance + +/-- Each canonical draw `ω ↦ ω i` is standard normal. -/ +theorem hasLaw_canonical (i : ℕ) : + HasLaw (fun ω : ℕ → ℝ ↦ ω i) (gaussianReal 0 1) canonicalEnsemble := + ⟨(measurable_pi_apply i).aemeasurable, Measure.infinitePi_map_eval _ i⟩ + +/-- The canonical draws are mutually independent. -/ +theorem iIndepFun_canonical : + iIndepFun (fun (i : ℕ) (ω : ℕ → ℝ) ↦ ω i) canonicalEnsemble := + iIndepFun_infinitePi (X := fun _ ↦ id) fun _ ↦ measurable_id + +variable {S_0 K r σ T : ℝ} + +/-- **Monte Carlo consistency for the put, on the canonical ensemble.** For `S₀, K, σ, T > 0`, +almost every sequence of i.i.d. standard-normal draws makes the sample mean of discounted put +payoffs converge to the Black–Scholes put `bsP K r σ S₀ T`. -/ +theorem consistency_canonical (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + ∀ᵐ ω ∂canonicalEnsemble, + Tendsto (fun n ↦ estimator S_0 K r σ T (fun i ω ↦ ω i) n ω) atTop + (𝓝 (bsP K r σ S_0 T)) := by + simpa only [bsP, neg_mul] using consistency_iid (μ := canonicalEnsemble) + (Z := fun i ω ↦ ω i) ⟨hS_0, hK, hσ, hT, hasLaw_canonical 0⟩ hasLaw_canonical + iIndepFun_canonical + +/-- **Monte Carlo consistency for the call, on the canonical ensemble.** For `S₀, K, σ, T > 0`, +almost every sequence of i.i.d. standard-normal draws makes the sample mean of discounted call +payoffs converge to the Black–Scholes call `bsV K r σ S₀ T`. -/ +theorem mc_call_consistency_canonical (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) + (hT : 0 < T) : + ∀ᵐ ω ∂canonicalEnsemble, + Tendsto (fun n ↦ mcCallMean S_0 K r σ T (fun i ω ↦ ω i) n ω) atTop + (𝓝 (bsV K r σ S_0 T)) := by + simpa only [bsV, neg_mul] using mc_call_consistency_iid (μ := canonicalEnsemble) + (Z := fun i ω ↦ ω i) ⟨hS_0, hK, hσ, hT, hasLaw_canonical 0⟩ hasLaw_canonical + iIndepFun_canonical + +/-- **Monte Carlo error bars for the call, on the canonical ensemble.** For `S₀, K, σ, T > 0`, +`√n·(mcCallMean n − bsV K r σ S₀ T) ⇒ 𝓝(0, Var(C))` in distribution, `C` the discounted call +payoff of one draw; `mc_call_variance` gives `Var(C)` in closed form. -/ +theorem mc_call_clt_canonical (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + TendstoInDistribution + (fun (n : ℕ) (ω : ℕ → ℝ) ↦ Real.sqrt (n : ℝ) * + (mcCallMean S_0 K r σ T (fun i ω ↦ ω i) n ω - bsV K r σ S_0 T)) + atTop (id : ℝ → ℝ) (fun _ ↦ canonicalEnsemble) + (gaussianReal 0 + (Var[fun ω ↦ mcCallPayoff S_0 K r σ T (ω 0); canonicalEnsemble]).toNNReal) := by + have h : BSCallHyp canonicalEnsemble S_0 K r σ T (fun ω ↦ ω 0) := + ⟨hS_0, hK, hσ, hT, hasLaw_canonical 0⟩ + have hclt := + mc_call_clt (Z := fun (i : ℕ) (ω : ℕ → ℝ) ↦ ω i) h hasLaw_canonical iIndepFun_canonical + rw [mean_mcCallPayoff_eq_bsCall h] at hclt + rw [bsV, ← neg_mul] + exact hclt + +end Canonical + +end MathFin.MonteCarlo diff --git a/LeanPool/MathFin/Models/BlackScholes/NewtonConvergence.lean b/LeanPool/MathFin/Models/BlackScholes/NewtonConvergence.lean new file mode 100644 index 0000000000..fb6b0d07d9 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/NewtonConvergence.lean @@ -0,0 +1,276 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.ImpliedVolatility + +/-! +# Newton–Raphson: local quadratic convergence + +`ImpliedVolatility.lean` records the Newton step `σ ↦ σ − f(σ)/f'(σ)` and its +fixed-point-at-root identity. This file proves the genuine numerical-analysis +content: **local quadratic convergence**. + +The hypotheses are the classical ones, phrased through the repo's +`HasDerivAt` idiom (no `ContDiff`/`iteratedDeriv` machinery): on a closed +interval `I = [r − δ, r + δ]` around a root `r`, + +* `f` has pointwise derivative `f'` on `I`, +* `f'` is `L`-Lipschitz on `I` (the honest substitute for a second-derivative + bound — `C²` implies it, but Lipschitz is exactly what the proof consumes), +* `|f'| ≥ m > 0` on `I` (the root is simple). + +**One step is quadratic, at the sharp constant** +(`newtonStep_quadratic_error`): + + `|x⁺ − r| ≤ (L/(2m))·(x − r)²`, `x⁺ := newtonStep f f' x`. + +The proof shows *why* Newton is quadratic: the next error is the Taylor +remainder of `f` at `x`, evaluated at the root, divided by `f' x`. The +remainder is the **integral of the derivative deviation** along the segment: +for the linearization-subtracted auxiliary `g(w) = f(w) − f'(x)·w` the FTC +gives `g(x) − g(r) = ∫_r^x (f'(t) − f'(x)) dt`, and the Lipschitz bound +`|f'(t) − f'(x)| ≤ L·|t − x|` is *linear* in the distance to `x`, so it +integrates to `(L/2)·(x − r)²` — the classical Newton–Kantorovich constant. +(A uniform mean-value bound would cost a factor `2`.) No second derivative +is ever mentioned. + +**Iterating converges** (`newtonSeq_tendsto_root`): inside the basin +`|x₀ − r| ≤ δ` with `L·δ ≤ m`, the quadratic bound gives the invariant +`|xₙ₊₁ − r| ≤ ½|xₙ − r|`, hence `|xₙ − r| ≤ (½)ⁿ·|x₀ − r| → 0` +(`newtonSeq_error_le_geometric`), and `xₙ → r`. + +In the implied-volatility application, `f(σ) = bsV(σ) − C_obs` has +`f' = vega > 0` (`bsV_vega_pos`), so `m` is a positive vega lower bound on the +bracketing interval and the simple-root hypothesis is automatic. + +## Main definitions + +* `newtonSeq`: the Newton–Raphson iterates, `x₀` and then `x_{n+1} = newtonStep f f' xₙ`. + +## Main results + +* `newtonStep_quadratic_error`: one-step quadratic error bound `(L/(2m))·e²`. +* `newtonSeq_error_le_geometric`: geometric error decay in the basin. +* `newtonSeq_tendsto_root`: convergence `xₙ → r`. + +## Tags + +Newton–Raphson, quadratic convergence, implied volatility solver, root finding, numerical analysis, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Filter Topology + +/-- The **Newton–Raphson iterates**: `x₀`, then `x_{n+1} = newtonStep f f' xₙ`. -/ +noncomputable def newtonSeq (f f' : ℝ → ℝ) (x₀ : ℝ) : ℕ → ℝ + | 0 => x₀ + | n + 1 => newtonStep f f' (newtonSeq f f' x₀ n) + +variable {f f' : ℝ → ℝ} {r δ m L x₀ : ℝ} + +/-- **One Newton step is quadratic, at the sharp constant**: if `r` is a root, +`f'` is the pointwise derivative of `f` on `I = [r − δ, r + δ]`, `f'` is +`L`-Lipschitz on `I`, and `|f'| ≥ m > 0` on `I`, then for `x ∈ I` + + `|newtonStep f f' x − r| ≤ (L/(2m)) · (x − r)²`. + +The next error is the Taylor remainder over `f' x`, computed in **integral +form** via the FTC for the linearization-subtracted auxiliary +`w ↦ f w − f' x · w`: its derivative `f' t − f' x` is Lipschitz-bounded by +`L·|t − x|` — *linear* in the distance to `x` — which integrates along +`[r, x]` to the sharp `(L/2)·(x − r)²`; `|f' x| ≥ m` divides it out. -/ +theorem newtonStep_quadratic_error + (hroot : f r = 0) (hm0 : 0 < m) (hL : 0 ≤ L) + (hd : ∀ y ∈ Set.Icc (r - δ) (r + δ), HasDerivAt f (f' y) y) + (hlip : ∀ y ∈ Set.Icc (r - δ) (r + δ), ∀ w ∈ Set.Icc (r - δ) (r + δ), + |f' y - f' w| ≤ L * |y - w|) + (hm : ∀ y ∈ Set.Icc (r - δ) (r + δ), m ≤ |f' y|) + {x : ℝ} (hx : x ∈ Set.Icc (r - δ) (r + δ)) : + |newtonStep f f' x - r| ≤ L / (2 * m) * (x - r) ^ 2 := by + have hδ : 0 ≤ δ := by + have h1 := hx.1; have h2 := hx.2; linarith + have hr : r ∈ Set.Icc (r - δ) (r + δ) := ⟨by linarith, by linarith⟩ + have hf'x_pos : 0 < |f' x| := lt_of_lt_of_le hm0 (hm x hx) + have hf'x_ne : f' x ≠ 0 := abs_pos.1 hf'x_pos + -- FTC for the linearization-subtracted auxiliary g(w) = f w − f' x · w: + -- g x − g r = ∫_r^x (f' t − f' x) dt + have hsub : Set.uIcc r x ⊆ Set.Icc (r - δ) (r + δ) := Set.uIcc_subset_Icc hr hx + have hg : ∀ t ∈ Set.uIcc r x, + HasDerivAt (fun w ↦ f w - f' x * w) (f' t - f' x) t := fun t ht ↦ + (hd t (hsub ht)).sub (by simpa using (hasDerivAt_id t).const_mul (f' x)) + have hcontI : ContinuousOn (fun t ↦ f' t - f' x) (Set.Icc (r - δ) (r + δ)) := by + have hlipOn : LipschitzOnWith (Real.toNNReal L) f' (Set.Icc (r - δ) (r + δ)) := + lipschitzOnWith_iff_dist_le_mul.2 fun y hy w hw ↦ by + rw [Real.dist_eq, Real.dist_eq] + simpa [Real.coe_toNNReal L hL] using hlip y hy w hw + exact hlipOn.continuousOn.sub continuousOn_const + have hftc : ∫ t in r..x, (f' t - f' x) + = (f x - f' x * x) - (f r - f' x * r) := + intervalIntegral.integral_eq_sub_of_hasDerivAt hg + ((hcontI.mono hsub).intervalIntegrable) + -- the linear Lipschitz bound integrates to the sharp (L/2)·(x − r)² + have h_num : |f' x * (x - r) - f x| ≤ L / 2 * (x - r) ^ 2 := by + have h_eq : f' x * (x - r) - f x + = -((f x - f' x * x) - (f r - f' x * r)) := by + rw [hroot]; ring + rw [h_eq, abs_neg, ← hftc] + rcases le_total r x with hrx | hxr + · have hb : ∀ t ∈ Set.Icc r x, |f' t - f' x| ≤ L * (x - t) := fun t ht ↦ by + have h := hlip t (hsub (by rw [Set.uIcc_of_le hrx]; exact ht)) x hx + rwa [abs_sub_comm t x, + abs_of_nonneg (by linarith [ht.2] : (0:ℝ) ≤ x - t)] at h + calc |∫ t in r..x, (f' t - f' x)| + ≤ ∫ t in r..x, |f' t - f' x| := + intervalIntegral.abs_integral_le_integral_abs hrx + _ ≤ ∫ t in r..x, L * (x - t) := + intervalIntegral.integral_mono_on hrx + (hcontI.mono hsub).abs.intervalIntegrable + ((continuous_const.mul + (continuous_const.sub continuous_id)).intervalIntegrable r x) + hb + _ = L / 2 * (x - r) ^ 2 := by + -- second FTC: the dominating integrand has explicit primitive + -- s ↦ L·(x·s − s²/2) + have hP : ∀ t ∈ Set.uIcc r x, + HasDerivAt (fun s ↦ L * (x * s - s ^ 2 / 2)) (L * (x - t)) t := by + intro t _ + have h2 : HasDerivAt (fun s : ℝ ↦ s ^ 2 / 2) t t := by + have h := (hasDerivAt_pow 2 t).div_const 2 + norm_num at h + exact h + have h1 : HasDerivAt (fun s : ℝ ↦ x * s) x t := by + simpa using (hasDerivAt_id t).const_mul x + simpa using (h1.sub h2).const_mul L + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hP + ((continuous_const.mul + (continuous_const.sub continuous_id)).intervalIntegrable r x)] + ring + · have hb : ∀ t ∈ Set.Icc x r, |f' t - f' x| ≤ L * (t - x) := fun t ht ↦ by + have h := hlip t + (Set.uIcc_subset_Icc hx hr (by rw [Set.uIcc_of_le hxr]; exact ht)) x hx + rwa [abs_of_nonneg (by linarith [ht.1] : (0:ℝ) ≤ t - x)] at h + rw [intervalIntegral.integral_symm, abs_neg] + calc |∫ t in x..r, (f' t - f' x)| + ≤ ∫ t in x..r, |f' t - f' x| := + intervalIntegral.abs_integral_le_integral_abs hxr + _ ≤ ∫ t in x..r, L * (t - x) := + intervalIntegral.integral_mono_on hxr + (hcontI.mono (Set.uIcc_subset_Icc hx hr)).abs.intervalIntegrable + ((continuous_const.mul + (continuous_id.sub continuous_const)).intervalIntegrable x r) + hb + _ = L / 2 * (x - r) ^ 2 := by + -- second FTC: the dominating integrand has explicit primitive + -- s ↦ L·(s²/2 − x·s) + have hP : ∀ t ∈ Set.uIcc x r, + HasDerivAt (fun s ↦ L * (s ^ 2 / 2 - x * s)) (L * (t - x)) t := by + intro t _ + have h2 : HasDerivAt (fun s : ℝ ↦ s ^ 2 / 2) t t := by + have h := (hasDerivAt_pow 2 t).div_const 2 + norm_num at h + exact h + have h1 : HasDerivAt (fun s : ℝ ↦ x * s) x t := by + simpa using (hasDerivAt_id t).const_mul x + simpa using (h2.sub h1).const_mul L + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hP + ((continuous_const.mul + (continuous_id.sub continuous_const)).intervalIntegrable x r)] + ring + -- error–times–derivative identity: (x⁺ − r)·f' x = f' x·(x − r) − f x + have h_prod : (newtonStep f f' x - r) * f' x = f' x * (x - r) - f x := by + unfold newtonStep + field_simp + ring + rw [show L / (2 * m) * (x - r) ^ 2 = L / 2 * (x - r) ^ 2 / m by ring, + le_div_iff₀ hm0] + calc |newtonStep f f' x - r| * m + ≤ |newtonStep f f' x - r| * |f' x| := + mul_le_mul_of_nonneg_left (hm x hx) (abs_nonneg _) + _ = |(newtonStep f f' x - r) * f' x| := (abs_mul _ _).symm + _ = |f' x * (x - r) - f x| := by rw [h_prod] + _ ≤ L / 2 * (x - r) ^ 2 := h_num + +/-- **Geometric error decay in the Newton basin**: if additionally +`|x₀ − r| ≤ δ` and `L·δ ≤ m`, then every iterate stays in the interval and + + `|xₙ − r| ≤ (½)ⁿ · |x₀ − r|`. + +The sharp quadratic bound `(L/(2m))·e²` turns into the halving `e/2` as soon +as `e ≤ δ ≤ m/L`, and halving preserves the basin — the induction +invariant. -/ +theorem newtonSeq_error_le_geometric + (hroot : f r = 0) (hm0 : 0 < m) (hL : 0 ≤ L) + (hd : ∀ y ∈ Set.Icc (r - δ) (r + δ), HasDerivAt f (f' y) y) + (hlip : ∀ y ∈ Set.Icc (r - δ) (r + δ), ∀ w ∈ Set.Icc (r - δ) (r + δ), + |f' y - f' w| ≤ L * |y - w|) + (hm : ∀ y ∈ Set.Icc (r - δ) (r + δ), m ≤ |f' y|) + (hx₀ : |x₀ - r| ≤ δ) (hbasin : L * δ ≤ m) : + ∀ n, |newtonSeq f f' x₀ n - r| ≤ (1 / 2) ^ n * |x₀ - r| := by + intro n + induction n with + | zero => simp [newtonSeq] + | succ n ih => + have h_en_le_δ : |newtonSeq f f' x₀ n - r| ≤ δ := by + refine ih.trans (le_trans ?_ hx₀) + calc (1 / 2 : ℝ) ^ n * |x₀ - r| + ≤ 1 * |x₀ - r| := + mul_le_mul_of_nonneg_right + (pow_le_one₀ (by norm_num) (by norm_num)) (abs_nonneg _) + _ = |x₀ - r| := one_mul _ + have h_mem : newtonSeq f f' x₀ n ∈ Set.Icc (r - δ) (r + δ) := by + have h := abs_le.1 h_en_le_δ + exact ⟨by linarith [h.1], by linarith [h.2]⟩ + have h_step := newtonStep_quadratic_error hroot hm0 hL hd hlip hm h_mem + have h_coeff : L / (2 * m) * δ ≤ 1 / 2 := by + rw [div_mul_eq_mul_div, div_le_iff₀ (by positivity : (0:ℝ) < 2 * m)] + linarith + have h_half : L / (2 * m) * (newtonSeq f f' x₀ n - r) ^ 2 + ≤ 1 / 2 * |newtonSeq f f' x₀ n - r| := by + calc L / (2 * m) * (newtonSeq f f' x₀ n - r) ^ 2 + = L / (2 * m) * |newtonSeq f f' x₀ n - r| * |newtonSeq f f' x₀ n - r| := by + rw [mul_assoc, abs_mul_abs_self, ← pow_two] + _ ≤ L / (2 * m) * δ * |newtonSeq f f' x₀ n - r| := + mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left h_en_le_δ + (div_nonneg hL (by positivity : (0:ℝ) ≤ 2 * m))) + (abs_nonneg _) + _ ≤ 1 / 2 * |newtonSeq f f' x₀ n - r| := + mul_le_mul_of_nonneg_right h_coeff (abs_nonneg _) + change |newtonStep f f' (newtonSeq f f' x₀ n) - r| ≤ (1 / 2) ^ (n + 1) * |x₀ - r| + calc |newtonStep f f' (newtonSeq f f' x₀ n) - r| + ≤ L / (2 * m) * (newtonSeq f f' x₀ n - r) ^ 2 := h_step + _ ≤ 1 / 2 * |newtonSeq f f' x₀ n - r| := h_half + _ ≤ 1 / 2 * ((1 / 2) ^ n * |x₀ - r|) := by linarith [ih] + _ = (1 / 2) ^ (n + 1) * |x₀ - r| := by ring + +/-- **Newton–Raphson converges** in the basin: under the quadratic-error +hypotheses with `|x₀ − r| ≤ δ` and `L·δ ≤ m`, the iterates tend to the root. +Squeeze of the geometric decay `(½)ⁿ·|x₀ − r| → 0`. -/ +theorem newtonSeq_tendsto_root + (hroot : f r = 0) (hm0 : 0 < m) (hL : 0 ≤ L) + (hd : ∀ y ∈ Set.Icc (r - δ) (r + δ), HasDerivAt f (f' y) y) + (hlip : ∀ y ∈ Set.Icc (r - δ) (r + δ), ∀ w ∈ Set.Icc (r - δ) (r + δ), + |f' y - f' w| ≤ L * |y - w|) + (hm : ∀ y ∈ Set.Icc (r - δ) (r + δ), m ≤ |f' y|) + (hx₀ : |x₀ - r| ≤ δ) (hbasin : L * δ ≤ m) : + Tendsto (newtonSeq f f' x₀) atTop (𝓝 r) := by + rw [tendsto_iff_dist_tendsto_zero] + have h_geo : Tendsto (fun n : ℕ ↦ (1 / 2 : ℝ) ^ n * |x₀ - r|) atTop (𝓝 0) := by + have h_pow : Tendsto (fun n : ℕ ↦ (1 / 2 : ℝ) ^ n) atTop (𝓝 0) := + tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num) (by norm_num) + simpa using h_pow.mul_const |x₀ - r| + refine squeeze_zero (fun n ↦ dist_nonneg) (fun n ↦ ?_) h_geo + rw [Real.dist_eq] + exact newtonSeq_error_le_geometric hroot hm0 hL hd hlip hm hx₀ hbasin n + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/PDE.lean b/LeanPool/MathFin/Models/BlackScholes/PDE.lean new file mode 100644 index 0000000000..de85592b31 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/PDE.lean @@ -0,0 +1,565 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Call +public import LeanPool.MathFin.Probability.Gaussian.GaussianCDFDeriv +public import LeanPool.MathFin.Probability.Analysis.DerivOfDeriv +public import Mathlib.Analysis.SpecialFunctions.Sqrt + +/-! +# Black–Scholes PDE — forward direction + +Given the BS call price `V(S, t) = S · Φ(d₁) − K · e^{-r(T−t)} · Φ(d₂)`, +this file shows `V` satisfies the Black–Scholes PDE + + `∂_t V + (1/2) σ² S² ∂²_S V + r S ∂_S V − r V = 0` + +for `0 < S, t < T, 0 < K, 0 < σ`. + +This is the FORWARD direction (uniqueness is left as upstream work). + +The proof leverages: +* `hasDerivAt_Phi` (FTC for `Φ' = ϕ`, proved in `GaussianCDFDeriv`), +* the "Black–Scholes identity" `S · ϕ(d₁) = K · e^{-r(T−t)} · ϕ(d₂)`, +* chain rule on `d₁, d₂` to compute `∂_S V`, `∂²_S V`, `∂_t V`. + +## Main definitions + +* `bsV`: the Black–Scholes call price as a function of the spot `S` and the time to maturity `τ`, + `V(S, τ) = S · Φ(d₁) − K · e^{−rτ} · Φ(d₂)`. + +## Main results + +* `bs_identity` — `S · ϕ(d₁) = K · e^{-r τ} · ϕ(d₂)`, +* `hasDerivAt_bsd1_S`, `hasDerivAt_bsd1_tau` — chain-rule pieces for d₁, +* `bs_pde_holds` — the BS price satisfies the BS PDE. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 19.3; 19.5 +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], 4.5 + +## Tags + +Black–Scholes PDE, parabolic equation, backward equation, option price PDE, Greeks identity, +MSC 91G20, MSC 35K10, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-! ### Black–Scholes identity: `S · ϕ(d₁) = K · e^{-r(T-t)} · ϕ(d₂)` -/ + +/-- The "Black–Scholes identity" — algebraic content of `S · ϕ(d₁) = K · e^{-rτ} · ϕ(d₂)`. + Substituting `d₂ = d₁ - σ√τ`, the ratio `ϕ(d₁)/ϕ(d₂)` simplifies to + `K · e^{-rτ} / S` via `exp(log(S/K) + rτ) = (S/K) · exp(rτ)`. + + We state it parametrically: for `S > 0, K > 0, σ > 0, τ > 0`, with + `d₁ = (log(S/K) + (r + σ²/2) τ) / (σ√τ)` and `d₂ = d₁ - σ√τ`, + `S · ϕ(d₁) = K · exp(-rτ) · ϕ(d₂)`. -/ +lemma bs_identity {S K r σ τ : ℝ} (hS : 0 < S) (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) : + S * gaussianPDFReal 0 1 (bsd1 S K r σ τ) + = K * Real.exp (-(r * τ)) * gaussianPDFReal 0 1 (bsd2 S K r σ τ) := by + set d₁ := bsd1 S K r σ τ with hd₁_def + set d₂ := bsd2 S K r σ τ with hd₂_def + have h_sqrt_τ_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_τ_ne : Real.sqrt τ ≠ 0 := h_sqrt_τ_pos.ne' + have h_στ : 0 < σ * Real.sqrt τ := mul_pos hσ h_sqrt_τ_pos + have h_στ_ne : σ * Real.sqrt τ ≠ 0 := h_στ.ne' + have h_sqrt_τ_sq : Real.sqrt τ ^ 2 = τ := Real.sq_sqrt hτ.le + -- d₁ - d₂ = σ √τ + have h_d₁_sub_d₂ : d₁ - d₂ = σ * Real.sqrt τ := by + rw [hd₂_def, bsd2]; ring + -- (d₁ - d₂)(d₁ + d₂) = d₁² - d₂², so d₂² - d₁² = -(d₁-d₂)(d₁+d₂) = -σ√τ · (d₁+d₂) + -- Compute d₁ + d₂ algebraically: + -- d₁ + d₂ = 2 d₁ - σ√τ + -- = 2(log(S/K) + (r + σ²/2)τ)/(σ√τ) - σ√τ + -- = (2 log(S/K) + 2rτ + σ²τ)/(σ√τ) - σ√τ + -- = (2 log(S/K) + 2rτ + σ²τ - σ²τ)/(σ√τ) + -- = (2 log(S/K) + 2rτ)/(σ√τ) + have h_d₁_plus_d₂ : d₁ + d₂ = 2 * (Real.log (S / K) + r * τ) / (σ * Real.sqrt τ) := by + rw [hd₁_def, hd₂_def, bsd2, bsd1] + field_simp + ring_nf + rw [show σ ^ 2 * τ = (σ * Real.sqrt τ) ^ 2 from by rw [mul_pow, h_sqrt_τ_sq]] + ring + -- Therefore d₁² - d₂² = (d₁ + d₂)(d₁ - d₂) = 2(log(S/K) + rτ) + have h_d₁_sq_sub : d₁ ^ 2 - d₂ ^ 2 = 2 * (Real.log (S / K) + r * τ) := by + have h_diff_sq : d₁ ^ 2 - d₂ ^ 2 = (d₁ + d₂) * (d₁ - d₂) := by ring + rw [h_diff_sq, h_d₁_plus_d₂, h_d₁_sub_d₂] + field_simp + -- ϕ(d₁) / ϕ(d₂) = exp((d₂² - d₁²) / 2) = exp(-(log(S/K) + rτ)) = K e^{-rτ} / S + -- So S · ϕ(d₁) = K e^{-rτ} · ϕ(d₂) + unfold gaussianPDFReal + simp only [NNReal.coe_one, mul_one, sub_zero] + -- Goal: S * ((√(2π))⁻¹ * exp(-d₁²/2)) = K * exp(-rτ) * ((√(2π))⁻¹ * exp(-d₂²/2)) + -- Strategy: combine all exponentials and use exp(log(S/K)) = S/K. + have hSK_pos : 0 < S / K := div_pos hS hK + have h_log : (d₁ ^ 2 - d₂ ^ 2) / 2 - r * τ = Real.log (S / K) := by + rw [h_d₁_sq_sub]; ring + -- Rewrite as `K * exp(...)` on both sides and equate exponents. + rw [show S = K * Real.exp (Real.log (S / K)) from by + rw [Real.exp_log hSK_pos]; field_simp] + rw [show K * Real.exp (Real.log (S / K)) * ((Real.sqrt (2 * π))⁻¹ * Real.exp (-d₁ ^ 2 / 2)) + = K * (Real.sqrt (2 * π))⁻¹ * Real.exp (Real.log (S / K) + (-d₁ ^ 2 / 2)) from by + rw [Real.exp_add]; ring] + rw [show K * Real.exp (-(r * τ)) * ((Real.sqrt (2 * π))⁻¹ * Real.exp (-d₂ ^ 2 / 2)) + = K * (Real.sqrt (2 * π))⁻¹ * Real.exp (-(r * τ) + (-d₂ ^ 2 / 2)) from by + rw [Real.exp_add]; ring] + congr 2 + -- Goal: log(S/K) + -d₁²/2 = -(r*τ) + -d₂²/2 + linear_combination -(1 / 2) * h_d₁_sq_sub + +/-! ### Partial derivatives of `bsd1`, `bsd2` w.r.t. `S` -/ + +/-- `∂_S d₁(S, K, r, σ, τ) = 1 / (S · σ · √τ)`. -/ +lemma hasDerivAt_bsd1_S {K r σ τ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) + {S : ℝ} (hS : 0 < S) : + HasDerivAt (fun s ↦ bsd1 s K r σ τ) (1 / (S * σ * Real.sqrt τ)) S := by + have h_sqrt_τ_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_τ_ne : Real.sqrt τ ≠ 0 := h_sqrt_τ_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have h_sK_pos : 0 < S / K := div_pos hS hK + -- s ↦ s/K: HasDerivAt _ (1/K) S + have h_div : HasDerivAt (fun s : ℝ ↦ s / K) (1 / K) S := by + have := (hasDerivAt_id S).div_const K + simpa using this + -- s ↦ log(s/K): HasDerivAt _ (1/S) S (chain rule) + have h_log : HasDerivAt (fun s : ℝ ↦ Real.log (s / K)) (1 / S) S := by + have := (Real.hasDerivAt_log h_sK_pos.ne').comp S h_div + convert this using 1 <;> try rfl + field_simp + -- s ↦ log(s/K) + (r + σ²/2)τ: same derivative + have h_num : HasDerivAt (fun s : ℝ ↦ Real.log (s / K) + (r + σ ^ 2 / 2) * τ) (1 / S) S := by + simpa using h_log.add_const ((r + σ ^ 2 / 2) * τ) + -- s ↦ (log(s/K) + (r + σ²/2)τ) / (σ √τ): derivative is (1/S) / (σ√τ) + have h_div_στ : HasDerivAt + (fun s : ℝ ↦ (Real.log (s / K) + (r + σ ^ 2 / 2) * τ) / (σ * Real.sqrt τ)) + ((1 / S) / (σ * Real.sqrt τ)) S := + h_num.div_const (σ * Real.sqrt τ) + have h_val_eq : (1 : ℝ) / (S * σ * Real.sqrt τ) = 1 / S / (σ * Real.sqrt τ) := by field_simp + rw [h_val_eq] + exact h_div_στ + +/-- `∂_S d₂(S, K, r, σ, τ) = 1 / (S · σ · √τ)` (same as `∂_S d₁` since `d₂ − d₁` is +`S`-independent). -/ +lemma hasDerivAt_bsd2_S {K r σ τ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) + {S : ℝ} (hS : 0 < S) : + HasDerivAt (fun s ↦ bsd2 s K r σ τ) (1 / (S * σ * Real.sqrt τ)) S := by + have h_diff := (hasDerivAt_bsd1_S (r := r) hK hσ hτ hS).sub_const (σ * Real.sqrt τ) + have h_fun_eq : (fun s : ℝ ↦ bsd1 s K r σ τ - σ * Real.sqrt τ) + = (fun s : ℝ ↦ bsd2 s K r σ τ) := by + funext s; rw [bsd2] + rw [← h_fun_eq] + exact h_diff + +/-! ### Partial derivatives of `bsd1`, `bsd2` w.r.t. `τ` -/ + +/-- `∂_τ d₁(S, K, r, σ, τ) = ((r + σ²/2)τ − log(S/K)) / (2 σ τ √τ)`. -/ +lemma hasDerivAt_bsd1_tau (S K r σ : ℝ) (hσ : 0 < σ) + {τ : ℝ} (hτ : 0 < τ) : + HasDerivAt (fun t ↦ bsd1 S K r σ t) + (((r + σ ^ 2 / 2) * τ - Real.log (S / K)) / (2 * σ * τ * Real.sqrt τ)) τ := by + have h_sqrt_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_ne : Real.sqrt τ ≠ 0 := h_sqrt_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have hτ_ne : τ ≠ 0 := hτ.ne' + have h_στ : 0 < σ * Real.sqrt τ := mul_pos hσ h_sqrt_pos + have h_στ_ne : σ * Real.sqrt τ ≠ 0 := h_στ.ne' + have h_sqrt_sq : Real.sqrt τ ^ 2 = τ := Real.sq_sqrt hτ.le + -- Numerator: f(τ) = log(S/K) + (r + σ²/2)τ → f' = r + σ²/2 + have h_f : HasDerivAt (fun t : ℝ ↦ Real.log (S / K) + (r + σ ^ 2 / 2) * t) + (r + σ ^ 2 / 2) τ := by + have h_lin : HasDerivAt (fun t : ℝ ↦ (r + σ ^ 2 / 2) * t) (r + σ ^ 2 / 2) τ := by + have := (hasDerivAt_id τ).const_mul (r + σ ^ 2 / 2) + simpa using this + exact h_lin.const_add (Real.log (S / K)) + -- Denominator: g(τ) = σ √τ → g' = σ/(2√τ) + have h_g : HasDerivAt (fun t : ℝ ↦ σ * Real.sqrt t) (σ / (2 * Real.sqrt τ)) τ := by + have h_sqrt_deriv : HasDerivAt Real.sqrt (1 / (2 * Real.sqrt τ)) τ := + Real.hasDerivAt_sqrt hτ.ne' + have := h_sqrt_deriv.const_mul σ + convert this using 1 + field_simp + -- Quotient rule + have h_quot := h_f.div h_g h_στ_ne + have h_fun_eq : (fun t : ℝ ↦ (Real.log (S / K) + (r + σ ^ 2 / 2) * t) / (σ * Real.sqrt t)) + = (fun t : ℝ ↦ bsd1 S K r σ t) := by + funext t; rfl + rw [← h_fun_eq] + convert h_quot using 1 + -- Value: ((r+σ²/2)τ - log(S/K))/(2 σ τ √τ) = ((r+σ²/2)(σ√τ) - (log + (r+σ²/2)τ)(σ/(2√τ))) / + -- (σ√τ)² + field_simp + rw [h_sqrt_sq] + ring + +/-- `∂_τ d₂(S, K, r, σ, τ) = ∂_τ d₁ − σ/(2√τ)`. -/ +lemma hasDerivAt_bsd2_tau (S K r σ : ℝ) (hσ : 0 < σ) + {τ : ℝ} (hτ : 0 < τ) : + HasDerivAt (fun t ↦ bsd2 S K r σ t) + (((r + σ ^ 2 / 2) * τ - Real.log (S / K)) / (2 * σ * τ * Real.sqrt τ) + - σ / (2 * Real.sqrt τ)) τ := by + have h_d1 := hasDerivAt_bsd1_tau S K r σ hσ hτ + have h_sqrt : HasDerivAt Real.sqrt (1 / (2 * Real.sqrt τ)) τ := Real.hasDerivAt_sqrt hτ.ne' + have h_const_mul := h_sqrt.const_mul σ + -- h_const_mul : HasDerivAt (fun t ↦ σ * sqrt t) (σ * (1/(2√τ))) τ + have h_diff := h_d1.sub h_const_mul + have h_fun_eq : (fun t : ℝ ↦ bsd1 S K r σ t - σ * Real.sqrt t) + = (fun t : ℝ ↦ bsd2 S K r σ t) := by + funext t; rw [bsd2] + rw [← h_fun_eq] + convert h_diff using 1 + field_simp + +/-! ### Partial derivatives of `bsd1`, `bsd2` w.r.t. `σ` -/ + +/-- `∂_σ d₁(S, K, r, σ, τ) = (σ²τ/2 − log(S/K) − rτ) / (σ²√τ)`. -/ +lemma hasDerivAt_bsd1_sigma (S K r : ℝ) {σ : ℝ} (hσ : 0 < σ) + {τ : ℝ} (hτ : 0 < τ) : + HasDerivAt (fun s ↦ bsd1 S K r s τ) + ((σ ^ 2 * τ / 2 - Real.log (S / K) - r * τ) / (σ ^ 2 * Real.sqrt τ)) σ := by + have h_sqrt_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_ne : Real.sqrt τ ≠ 0 := h_sqrt_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have hτ_ne : τ ≠ 0 := hτ.ne' + have h_στ : 0 < σ * Real.sqrt τ := mul_pos hσ h_sqrt_pos + have h_στ_ne : σ * Real.sqrt τ ≠ 0 := h_στ.ne' + have h_sqrt_sq : Real.sqrt τ ^ 2 = τ := Real.sq_sqrt hτ.le + -- N(σ) = log(S/K) + (r + σ²/2) τ; N'(σ) = στ + have h_sq : HasDerivAt (fun s : ℝ ↦ s ^ 2) (2 * σ) σ := by + simpa using hasDerivAt_pow 2 σ + have h_sq_div : HasDerivAt (fun s : ℝ ↦ s ^ 2 / 2) σ σ := by + have := h_sq.div_const 2; simpa using this + have h_inner : HasDerivAt (fun s : ℝ ↦ r + s ^ 2 / 2) σ σ := h_sq_div.const_add r + have h_inner_mul : HasDerivAt (fun s : ℝ ↦ (r + s ^ 2 / 2) * τ) (σ * τ) σ := by + have := h_inner.mul_const τ; simpa using this + have h_N : HasDerivAt (fun s : ℝ ↦ Real.log (S / K) + (r + s ^ 2 / 2) * τ) + (σ * τ) σ := h_inner_mul.const_add (Real.log (S / K)) + -- D(σ) = σ√τ; D'(σ) = √τ + have h_D : HasDerivAt (fun s : ℝ ↦ s * Real.sqrt τ) (Real.sqrt τ) σ := by + have := (hasDerivAt_id σ).mul_const (Real.sqrt τ); simpa using this + -- Quotient rule + have h_quot := h_N.div h_D h_στ_ne + have h_fun_eq : (fun s : ℝ ↦ (Real.log (S / K) + (r + s ^ 2 / 2) * τ) / (s * Real.sqrt τ)) + = (fun s : ℝ ↦ bsd1 S K r s τ) := by funext s; rfl + rw [← h_fun_eq] + convert h_quot using 1 + field_simp + ring + +/-- `∂_σ d₂ = ∂_σ d₁ − √τ` (since `d₂ = d₁ − σ√τ`). -/ +lemma hasDerivAt_bsd2_sigma (S K r : ℝ) {σ : ℝ} (hσ : 0 < σ) + {τ : ℝ} (hτ : 0 < τ) : + HasDerivAt (fun s ↦ bsd2 S K r s τ) + ((σ ^ 2 * τ / 2 - Real.log (S / K) - r * τ) / (σ ^ 2 * Real.sqrt τ) + - Real.sqrt τ) σ := by + have h_d1 := hasDerivAt_bsd1_sigma S K r hσ hτ + -- ∂_σ (σ √τ) = √τ + have h_σsqrt : HasDerivAt (fun s : ℝ ↦ s * Real.sqrt τ) (Real.sqrt τ) σ := by + have := (hasDerivAt_id σ).mul_const (Real.sqrt τ); simpa using this + have h_diff := h_d1.sub h_σsqrt + have h_fun_eq : (fun s : ℝ ↦ bsd1 S K r s τ - s * Real.sqrt τ) + = (fun s : ℝ ↦ bsd2 S K r s τ) := by funext s; rw [bsd2] + rw [← h_fun_eq] + exact h_diff + +/-! ### Partial derivatives of `bsd1`, `bsd2` w.r.t. `r` -/ + +/-- `∂_r d₁(S, K, r, σ, τ) = √τ / σ`. -/ +lemma hasDerivAt_bsd1_r (S K σ τ : ℝ) (hσ : 0 < σ) (hτ : 0 < τ) + (r : ℝ) : + HasDerivAt (fun r' ↦ bsd1 S K r' σ τ) (Real.sqrt τ / σ) r := by + have h_sqrt_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_ne : Real.sqrt τ ≠ 0 := h_sqrt_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + -- N(r) = log(S/K) + (r + σ²/2) τ; N'(r) = τ + have h_id : HasDerivAt (fun r' : ℝ ↦ r') 1 r := hasDerivAt_id r + have h_inner : HasDerivAt (fun r' : ℝ ↦ r' + σ ^ 2 / 2) 1 r := by + have := h_id.add_const (σ ^ 2 / 2); simpa using this + have h_inner_mul : HasDerivAt (fun r' : ℝ ↦ (r' + σ ^ 2 / 2) * τ) τ r := by + have := h_inner.mul_const τ; simpa using this + have h_N : HasDerivAt (fun r' : ℝ ↦ Real.log (S / K) + (r' + σ ^ 2 / 2) * τ) τ r := + h_inner_mul.const_add (Real.log (S / K)) + -- d_1(r) = N(r) / (σ √τ); D is constant, so ∂_r d_1 = N'(r) / (σ√τ) = τ/(σ√τ) = √τ/σ + have h_div : HasDerivAt + (fun r' : ℝ ↦ (Real.log (S / K) + (r' + σ ^ 2 / 2) * τ) / (σ * Real.sqrt τ)) + (τ / (σ * Real.sqrt τ)) r := h_N.div_const (σ * Real.sqrt τ) + have h_fun_eq : (fun r' : ℝ ↦ (Real.log (S / K) + (r' + σ ^ 2 / 2) * τ) / (σ * Real.sqrt τ)) + = (fun r' : ℝ ↦ bsd1 S K r' σ τ) := by funext r'; rfl + rw [← h_fun_eq] + convert h_div using 1 + -- τ/(σ√τ) = √τ/σ + have h_τ_eq : Real.sqrt τ * Real.sqrt τ = τ := Real.mul_self_sqrt hτ.le + field_simp + linarith [h_τ_eq] + +/-- `∂_r d₂ = ∂_r d₁ = √τ / σ` (since `d₂ − d₁` is `r`-independent). -/ +lemma hasDerivAt_bsd2_r (S K σ τ : ℝ) (hσ : 0 < σ) (hτ : 0 < τ) + (r : ℝ) : + HasDerivAt (fun r' ↦ bsd2 S K r' σ τ) (Real.sqrt τ / σ) r := by + have h_diff := (hasDerivAt_bsd1_r S K σ τ hσ hτ r).sub_const (σ * Real.sqrt τ) + have h_fun_eq : (fun r' : ℝ ↦ bsd1 S K r' σ τ - σ * Real.sqrt τ) + = (fun r' : ℝ ↦ bsd2 S K r' σ τ) := by funext r'; rw [bsd2] + rw [← h_fun_eq] + exact h_diff + +/-! ### Partial derivatives of the Black–Scholes call price `V` -/ + +/-- The Black–Scholes call price as a function of `(S, τ)` with `τ = T − t`: +`V(S, τ) = S · Φ(d₁) − K · e^{-rτ} · Φ(d₂)`. -/ +noncomputable def bsV (K r σ : ℝ) (S τ : ℝ) : ℝ := + S * Phi (bsd1 S K r σ τ) - K * Real.exp (-(r * τ)) * Phi (bsd2 S K r σ τ) + +/-- The Black–Scholes call price is the discounted expected call payoff: `bs_call_formula`, +stated for `bsV`. -/ +lemma integral_bsCall_payoff_eq_bsV {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} + [IsProbabilityMeasure Q] {S_0 K r σ T : ℝ} {Z : Ω → ℝ} (h : BSCallHyp Q S_0 K r σ T Z) : + ∫ ω, rexp (-r * T) * max (bsTerminal S_0 r σ T (Z ω) - K) 0 ∂Q = bsV K r σ S_0 T := by + rw [bs_call_formula h, bsV, neg_mul] + +/-- **Delta**: `∂_S V = Φ(d₁)` — the magic identity makes everything else cancel. -/ +lemma hasDerivAt_bsV_S {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ bsV K r σ s τ) (Phi (bsd1 S K r σ τ)) S := by + have h_sqrt_τ_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_τ_ne : Real.sqrt τ ≠ 0 := h_sqrt_τ_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have hS_ne : S ≠ 0 := hS.ne' + -- Pieces + have h_d1_S := hasDerivAt_bsd1_S (r := r) hK hσ hτ hS + have h_d2_S := hasDerivAt_bsd2_S (r := r) hK hσ hτ hS + have h_Phi_d1 := (hasDerivAt_Phi (bsd1 S K r σ τ)).comp S h_d1_S + have h_Phi_d2 := (hasDerivAt_Phi (bsd2 S K r σ τ)).comp S h_d2_S + -- d/dS [S · Φ(d₁)] = Φ(d₁) + S · pdf(d₁) · ∂_S d₁ + have h_id : HasDerivAt (fun s : ℝ ↦ s) 1 S := hasDerivAt_id S + have h_S_Phi_d1 := h_id.mul h_Phi_d1 + -- d/dS [K · exp(-rτ) · Φ(d₂)] = K · exp(-rτ) · pdf(d₂) · ∂_S d₂ + have h_K_exp_Phi_d2 := h_Phi_d2.const_mul (K * Real.exp (-(r * τ))) + have h_V := h_S_Phi_d1.sub h_K_exp_Phi_d2 + have h_fun_eq : (fun s : ℝ ↦ s * Phi (bsd1 s K r σ τ) - + K * Real.exp (-(r * τ)) * Phi (bsd2 s K r σ τ)) + = (fun s : ℝ ↦ bsV K r σ s τ) := by + funext s; rfl + rw [← h_fun_eq] + convert h_V using 1 <;> try rfl + -- Value simplification: cancel via magic identity + have h_bs := bs_identity (r := r) hS hK hσ hτ + simp only [Function.comp] + field_simp + linear_combination -h_bs + +/-- **The gamma formula**: the S-derivative of the delta `Φ(d₁(S))` is +`ϕ(d₁) / (S σ √τ)`, by the chain rule. This differentiates the delta's formula; the second +derivative of the price itself is `hasDerivAt_deriv_bsV_S`. -/ +lemma hasDerivAt_Phi_bsd1_S {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ Phi (bsd1 s K r σ τ)) + (gaussianPDFReal 0 1 (bsd1 S K r σ τ) / (S * σ * Real.sqrt τ)) S := by + -- `S` is `bsd1`'s first argument, so the chain rule is elaborated before its target + have h := (hasDerivAt_Phi (bsd1 S K r σ τ)).comp S (hasDerivAt_bsd1_S (r := r) hK hσ hτ hS) + exact h.congr_deriv (mul_one_div _ _) + +/-- **Gamma**: `∂²V/∂S² = ϕ(d₁) / (S σ √τ)`, for the call price itself. The delta `Φ(d₁)` is +`∂V/∂S` on all of `S > 0` (`hasDerivAt_bsV_S`), so near `S` the derivative of the price is the +delta formula, whose own derivative is the gamma formula (`hasDerivAt_Phi_bsd1_S`). -/ +theorem hasDerivAt_deriv_bsV_S {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (deriv fun s ↦ bsV K r σ s τ) + (gaussianPDFReal 0 1 (bsd1 S K r σ τ) / (S * σ * Real.sqrt τ)) S := + hasDerivAt_deriv_of_eventually + ((eventually_gt_nhds hS).mono fun _ hs ↦ hasDerivAt_bsV_S hK hσ hs hτ) + (hasDerivAt_Phi_bsd1_S hK hσ hS hτ) + +/-- **Theta (without τ → t sign flip)**: `∂_τ V = σ S ϕ(d₁) / (2 √τ) + r K e^{-rτ} Φ(d₂)`. +The combination of product/chain rules + the magic identity (`K e^{-rτ} ϕ(d₂) = S ϕ(d₁)`) +collapses the `pdf(d₂) ∂_τ d₂` term into `−S ϕ(d₁) ∂_τ d₂`, leaving +`S ϕ(d₁) (∂_τ d₁ − ∂_τ d₂) = S ϕ(d₁) · σ/(2√τ)`. -/ +lemma hasDerivAt_bsV_tau {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (fun t ↦ bsV K r σ S t) + (σ * S * gaussianPDFReal 0 1 (bsd1 S K r σ τ) / (2 * Real.sqrt τ) + + r * K * Real.exp (-(r * τ)) * Phi (bsd2 S K r σ τ)) τ := by + have h_sqrt_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_ne : Real.sqrt τ ≠ 0 := h_sqrt_pos.ne' + have hτ_ne : τ ≠ 0 := hτ.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have hS_ne : S ≠ 0 := hS.ne' + have hK_ne : K ≠ 0 := hK.ne' + -- Pieces + have h_d1_τ := hasDerivAt_bsd1_tau S K r σ hσ hτ + have h_d2_τ := hasDerivAt_bsd2_tau S K r σ hσ hτ + have h_Phi_d1 := (hasDerivAt_Phi (bsd1 S K r σ τ)).comp τ h_d1_τ + have h_Phi_d2 := (hasDerivAt_Phi (bsd2 S K r σ τ)).comp τ h_d2_τ + -- d/dτ[S · Phi(d₁(τ))] + have h_S_Phi_d1 := h_Phi_d1.const_mul S + -- d/dτ[exp(-rτ)] = -r exp(-rτ) + have h_neg_r : HasDerivAt (fun t : ℝ ↦ -(r * t)) (-r) τ := by + have h1 : HasDerivAt (fun t : ℝ ↦ r * t) r τ := by + simpa using (hasDerivAt_id τ).const_mul r + exact h1.neg + have h_exp : HasDerivAt (fun t : ℝ ↦ Real.exp (-(r * t))) + (Real.exp (-(r * τ)) * -r) τ := h_neg_r.exp + -- d/dτ[K · exp(-rτ)] = K · (-r) exp(-rτ) + have h_K_exp : HasDerivAt (fun t : ℝ ↦ K * Real.exp (-(r * t))) + (K * (Real.exp (-(r * τ)) * -r)) τ := h_exp.const_mul K + -- d/dτ[K · exp(-rτ) · Phi(d₂(τ))] = product rule + have h_K_exp_Phi_d2 := h_K_exp.mul h_Phi_d2 + have h_V := h_S_Phi_d1.sub h_K_exp_Phi_d2 + have h_fun_eq : (fun t : ℝ ↦ + S * (Phi ∘ fun t' ↦ bsd1 S K r σ t') t - + (fun y ↦ K * Real.exp (-(r * y)) * (Phi ∘ fun t' ↦ bsd2 S K r σ t') y) t) + = (fun t : ℝ ↦ bsV K r σ S t) := by + funext t; rfl + rw [← h_fun_eq] + convert h_V using 1 + -- Value match using magic identity (field_simp already absorbs √τ² = τ). + have h_bs := bs_identity (r := r) hS hK hσ hτ + simp only [Function.comp] + field_simp + linear_combination + (σ ^ 2 * τ - 2 * τ * r + 2 * Real.log (S / K)) * h_bs + +/-- **Theta**: `∂_t V = -∂_τ V` via the chain rule on `τ = T − t`. -/ +lemma hasDerivAt_bsV_t {K T r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S t : ℝ} (hS : 0 < S) (ht_T : t < T) : + HasDerivAt (fun t' ↦ bsV K r σ S (T - t')) + (-(σ * S * gaussianPDFReal 0 1 (bsd1 S K r σ (T - t)) / (2 * Real.sqrt (T - t)) + + r * K * Real.exp (-(r * (T - t))) * Phi (bsd2 S K r σ (T - t)))) t := by + have hτ : 0 < T - t := sub_pos.mpr ht_T + have h_τ_deriv : HasDerivAt (fun t' : ℝ ↦ T - t') (-1) t := by + have := (hasDerivAt_id t).const_sub T + simpa using this + have h_V_τ := hasDerivAt_bsV_tau (r := r) hK hσ hS hτ + have h_comp := h_V_τ.comp t h_τ_deriv + convert h_comp using 1 <;> try rfl + ring + +/-- **Theta in maturity form**: at a fixed calendar date `t`, `∂_T V(S, T − t) = ∂_τ V`, the +negative of the calendar theta `hasDerivAt_bsV_t` (`∂_t V = −∂_τ V`). Theta stated as `∂/∂τ` +or as `∂/∂T` is therefore the same number; theta stated as `∂/∂t` has the opposite sign. -/ +lemma hasDerivAt_bsV_maturity {K t r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S T : ℝ} (hS : 0 < S) (ht_T : t < T) : + HasDerivAt (fun T' ↦ bsV K r σ S (T' - t)) + (σ * S * gaussianPDFReal 0 1 (bsd1 S K r σ (T - t)) / (2 * Real.sqrt (T - t)) + + r * K * Real.exp (-(r * (T - t))) * Phi (bsd2 S K r σ (T - t))) T := by + have h := (hasDerivAt_bsV_tau (r := r) hK hσ hS (sub_pos.mpr ht_T)).comp T + ((hasDerivAt_id T).sub_const t) + rwa [mul_one] at h + +/-! ### Vega and Rho -/ + +/-- **Vega**: `∂_σ V = S · ϕ(d₁) · √τ`. + +The product/chain rules yield `S · pdf(d₁) · ∂_σ d₁ − K e^{-rτ} · pdf(d₂) · ∂_σ d₂`. +Since `d₂ = d₁ − σ√τ`, we have `∂_σ d₂ = ∂_σ d₁ − √τ`. After substitution the +`∂_σ d₁` terms collapse via the magic identity `S · ϕ(d₁) = K e^{-rτ} · ϕ(d₂)`, +leaving `K e^{-rτ} · ϕ(d₂) · √τ = S · ϕ(d₁) · √τ`. -/ +lemma hasDerivAt_bsV_sigma {K r : ℝ} (hK : 0 < K) + {S σ τ : ℝ} (hS : 0 < S) (hσ : 0 < σ) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ bsV K r s S τ) + (S * gaussianPDFReal 0 1 (bsd1 S K r σ τ) * Real.sqrt τ) σ := by + have h_sqrt_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_ne : Real.sqrt τ ≠ 0 := h_sqrt_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have hS_ne : S ≠ 0 := hS.ne' + have hK_ne : K ≠ 0 := hK.ne' + have h_d1_σ := hasDerivAt_bsd1_sigma S K r hσ hτ + have h_d2_σ := hasDerivAt_bsd2_sigma S K r hσ hτ + have h_Phi_d1 := (hasDerivAt_Phi (bsd1 S K r σ τ)).comp σ h_d1_σ + have h_Phi_d2 := (hasDerivAt_Phi (bsd2 S K r σ τ)).comp σ h_d2_σ + -- d/dσ [S · Phi(d₁(σ))] + have h_S_Phi_d1 := h_Phi_d1.const_mul S + -- d/dσ [K · exp(-rτ) · Phi(d₂(σ))] + have h_K_exp_Phi_d2 := h_Phi_d2.const_mul (K * Real.exp (-(r * τ))) + have h_V := h_S_Phi_d1.sub h_K_exp_Phi_d2 + have h_fun_eq : (fun s : ℝ ↦ + S * (Phi ∘ fun s' ↦ bsd1 S K r s' τ) s - + K * Real.exp (-(r * τ)) * (Phi ∘ fun s' ↦ bsd2 S K r s' τ) s) + = (fun s : ℝ ↦ bsV K r s S τ) := by funext s; rfl + rw [← h_fun_eq] + convert h_V using 1 + have h_bs := bs_identity (r := r) hS hK hσ hτ + have h_sq_sqrt : Real.sqrt τ ^ 2 = τ := Real.sq_sqrt hτ.le + field_simp + simp only [show (τ * r : ℝ) = r * τ from mul_comm τ r, h_sq_sqrt] + rw [h_bs] + ring + +/-- **Rho**: `∂_r V = K · τ · e^{-rτ} · Φ(d₂)`. + +Again the magic identity collapses the `∂_r d₁`, `∂_r d₂` chain-rule contributions, +because `∂_r d₁ = ∂_r d₂ = √τ/σ` (the difference `d₁ − d₂` is `r`-independent). +The remaining surviving term comes from `∂_r [exp(-rτ)] = −τ · exp(-rτ)`. -/ +lemma hasDerivAt_bsV_r {K σ τ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) + {S : ℝ} (hS : 0 < S) (r : ℝ) : + HasDerivAt (fun r' ↦ bsV K r' σ S τ) + (K * τ * Real.exp (-(r * τ)) * Phi (bsd2 S K r σ τ)) r := by + have h_sqrt_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_ne : Real.sqrt τ ≠ 0 := h_sqrt_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have hτ_ne : τ ≠ 0 := hτ.ne' + have hS_ne : S ≠ 0 := hS.ne' + have hK_ne : K ≠ 0 := hK.ne' + have h_d1_r := hasDerivAt_bsd1_r S K σ τ hσ hτ r + have h_d2_r := hasDerivAt_bsd2_r S K σ τ hσ hτ r + have h_Phi_d1 := (hasDerivAt_Phi (bsd1 S K r σ τ)).comp r h_d1_r + have h_Phi_d2 := (hasDerivAt_Phi (bsd2 S K r σ τ)).comp r h_d2_r + -- d/dr [S · Phi(d₁(r))] + have h_S_Phi_d1 := h_Phi_d1.const_mul S + -- d/dr [exp(-rτ)] = -τ · exp(-rτ) + have h_neg_r : HasDerivAt (fun r' : ℝ ↦ -(r' * τ)) (-τ) r := by + have h_lin : HasDerivAt (fun r' : ℝ ↦ r' * τ) τ r := by + have := (hasDerivAt_id r).mul_const τ; simpa using this + exact h_lin.neg + have h_exp : HasDerivAt (fun r' : ℝ ↦ Real.exp (-(r' * τ))) + (Real.exp (-(r * τ)) * -τ) r := h_neg_r.exp + -- d/dr [K · exp(-rτ)] = K · -τ · exp(-rτ) + have h_K_exp : HasDerivAt (fun r' : ℝ ↦ K * Real.exp (-(r' * τ))) + (K * (Real.exp (-(r * τ)) * -τ)) r := h_exp.const_mul K + -- d/dr [K · exp(-rτ) · Phi(d₂(r))] + have h_K_exp_Phi_d2 := h_K_exp.mul h_Phi_d2 + have h_V := h_S_Phi_d1.sub h_K_exp_Phi_d2 + have h_fun_eq : (fun r' : ℝ ↦ + S * (Phi ∘ fun r'' ↦ bsd1 S K r'' σ τ) r' - + (fun r'' ↦ K * Real.exp (-(r'' * τ)) * (Phi ∘ fun r''' ↦ bsd2 S K r''' σ τ) r'') r') + = (fun r' : ℝ ↦ bsV K r' σ S τ) := by funext r'; rfl + rw [← h_fun_eq] + convert h_V using 1 + have h_bs := bs_identity (r := r) hS hK hσ hτ + simp only [Function.comp_apply] + field_simp + simp only [show (τ * r : ℝ) = r * τ from mul_comm τ r] + rw [h_bs] + ring + +/-- **Black–Scholes PDE** (forward direction): the European call price +`V(S, t) = S · Φ(d₁) − K · e^{-r(T−t)} · Φ(d₂)` satisfies +`∂_t V + (1/2) σ² S² ∂²_S V + r S ∂_S V − r V = 0` for `0 < S, t < T, 0 < K, 0 < σ`. -/ +theorem bs_pde_holds {K T r σ : ℝ} (hσ : 0 < σ) + {S t : ℝ} (hS : 0 < S) (ht_T : t < T) : + -(σ * S * gaussianPDFReal 0 1 (bsd1 S K r σ (T - t)) / (2 * Real.sqrt (T - t)) + + r * K * Real.exp (-(r * (T - t))) * Phi (bsd2 S K r σ (T - t))) + + (1 / 2 : ℝ) * σ ^ 2 * S ^ 2 * + (gaussianPDFReal 0 1 (bsd1 S K r σ (T - t)) / (S * σ * Real.sqrt (T - t))) + + r * S * Phi (bsd1 S K r σ (T - t)) - + r * bsV K r σ S (T - t) = 0 := by + have hτ : 0 < T - t := sub_pos.mpr ht_T + have h_sqrt_pos : 0 < Real.sqrt (T - t) := Real.sqrt_pos.mpr hτ + have hS_ne : S ≠ 0 := hS.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have h_sqrt_ne : Real.sqrt (T - t) ≠ 0 := h_sqrt_pos.ne' + rw [bsV] + field_simp + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/PDEFromFeynmanKac.lean b/LeanPool/MathFin/Models/BlackScholes/PDEFromFeynmanKac.lean new file mode 100644 index 0000000000..b1e981dae2 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/PDEFromFeynmanKac.lean @@ -0,0 +1,362 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +-- `import Mathlib` comes transitively through `Models.BlackScholes.PDE` / +-- `Probability.Gaussian.FeynmanKacHeatEquation`. +public import LeanPool.MathFin.Probability.Gaussian.FeynmanKacHeatEquation +public import LeanPool.MathFin.Models.BlackScholes.PDE + +/-! +# The Black–Scholes PDE, derived from Feynman–Kac + +`Models/BlackScholes/PDE.lean` proves `bs_pde_holds` *backward*: it has the closed form +`bsV` and checks, by differentiating it, that it satisfies +`∂_t V + ½σ²S²∂_SS V + rS∂_S V − rV = 0`. `Models/BlackScholes/PDEFromIto.lean` records +the *algebraic* shape of the no-arbitrage relation but is explicit that the +continuous-time martingale step is deferred — its `… = 0` is a `ring` identity, +not a derivation. + +This file closes that gap from the **probabilistic** side. The Black–Scholes +value is a Gaussian convolution of the payoff — a Feynman–Kac representation — +and it satisfies the PDE *because* the heat kernel does. The deep machinery of +`Probability/Gaussian/FeynmanKacHeatEquation.lean` — previously an orphan, consumed by no +pricing result — is now load-bearing for pricing. + +## The program (four steps) + +1. **Kernel-side heat equation** *(in `Probability/Gaussian/FeynmanKacHeatEquation.lean`)*: + for `g` locally integrable with sub-Gaussian growth and `τ > 0`, + `u(τ, x) := feynmanU g τ x` is smooth and `∂_τ u = ½ ∂_xx u`. The derivatives + fall on the smooth, fast-decaying *kernel* (`∂_τ K = ½ ∂_yy K`, already + proved), so `g` needs no regularity — the call payoff's kink and exponential + growth are irrelevant. +2. **Feynman–Kac representation of the price** *(`bsV_eq_feynmanU`, below)*: + `bsV K r σ S τ = feynmanU (fun ξ ↦ e^{−rτ}·(e^ξ − K)⁺) (σ²τ) (log S + (r − σ²/2)τ)`. + This is the milestone that wires `feynmanU` into the pricing layer. +3. **Log-price + discount change of variables** `S = eˣ`, `t = T − τ`: transport + step 1's heat equation through the substitution onto the Black–Scholes + operator. +4. **`bsV` solves the BS PDE, via Feynman–Kac**: assemble 1–3 — an independent, + conceptually grounded derivation of `bs_pde_holds`. + +Step 1 is proved in `Probability/Gaussian/FeynmanKacHeatEquation`. This file establishes steps 2–4. +Step 2 is +`bsV_eq_feynmanU` with the discounted-heat-flow bridge `bsV_eq_discount_feynmanU` (the result that +makes `feynmanU` load-bearing for pricing). Step 3 is the three Greeks via Feynman–Kac: +`hasDerivAt_bsV_S_fk` (Delta — the `S`-derivative as a kernel moment), `hasDerivAt_bsV_tau_fk` +(Theta — the product rule on the discount `e^{−rτ'}` times the discounted heat flow, with *both* +kernel arguments `σ²τ'` and `log S + (r−σ²/2)τ'` moving with `τ'`), and `hasDerivAt_bsV_SS_fk` +(Gamma). The Theta consumes `hasDerivAt_feynmanU_comp` and through it the heat kernel's joint +Fréchet differentiability `hasFDerivAt_heatKernel`; the curve domination bounds the two +kernel-derivative terms separately (`curve_sq_ratio_le` / `curve_abs_ratio_le` + +`heatKernel_loc_le`), avoiding the single-mega-constant blow-up that defeated the brute force. + +Step 4 is the capstone `bsV_satisfies_bs_pde_via_feynmanKac`: the PDE assembly +`−V_τ + ½σ²S²V_SS + rSV_S − rV = e^{−rτ}σ²(½U_xx − U_t) = 0` via `feynmanU_heat_equation` and the +operator cancellation `−(r−σ²/2) − ½σ² + r = 0`, on top of the in-place Greeks above. Those three +derivatives are heat-kernel integrals; the theorem also identifies them with the closed-form Greeks +of `Models/BlackScholes/PDE.lean` (`hasDerivAt_bsV_tau`, `hasDerivAt_bsV_S`, +`hasDerivAt_deriv_bsV_S`), +by uniqueness of the derivative. The benchmark `sc-bs-pde-feynman-kac` re-exports it. + +## Main results + +* `bsV_eq_feynmanU`: for `S, K, σ, τ > 0`, the Black–Scholes call value is the Feynman–Kac heat flow + `feynmanU` of the payoff `e^{−rτ}(e^ξ − K)⁺` at time `σ²τ` and point + `log S + (r − σ²/2)τ`. +* `bsV_eq_discount_feynmanU`: the same value written as `e^{−rτ}` times the heat flow of + `(e^ξ − K)⁺`. +* `bsV_satisfies_bs_pde_via_feynmanKac`: the derivatives `V_τ`, `V_S`, `V_SS` of the call value + exist and satisfy `−V_τ + ½σ²S²·V_SS + rS·V_S − rV = 0`, derived through the heat equation. + +## Tags + +Feynman–Kac, Black–Scholes PDE, probabilistic representation, heat equation, diffusion generator, +MSC 91G20, MSC 60H30, MSC 35K10 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory + +namespace MathFin + +open FeynmanKacHeatEquation + +/-- **Step 2 — Feynman–Kac representation of the Black–Scholes call value.** -/ +theorem bsV_eq_feynmanU {K r σ S τ : ℝ} + (hS : 0 < S) (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) : + bsV K r σ S τ = + FeynmanKacHeatEquation.feynmanU + (fun ξ ↦ Real.exp (-(r * τ)) * max (Real.exp ξ - K) 0) + (σ ^ 2 * τ) + (Real.log S + (r - σ ^ 2 / 2) * τ) := by + have hvar : (0:ℝ) < σ ^ 2 * τ := by positivity + set g : ℝ → ℝ := fun ξ ↦ Real.exp (-(r * τ)) * max (Real.exp ξ - K) 0 with hg + have hg_cont : Continuous g := by + rw [hg] + exact continuous_const.mul + ((Real.continuous_exp.sub continuous_const).max continuous_const) + have hmap : Measure.map (fun ω ↦ σ * Real.sqrt τ * ω) (gaussianReal 0 1) + = gaussianReal 0 (σ ^ 2 * τ).toNNReal := by + rw [gaussianReal_map_const_mul (σ * Real.sqrt τ), mul_zero, mul_one] + congr 1 + apply NNReal.coe_injective + rw [NNReal.coe_mk, Real.coe_toNNReal _ hvar.le, mul_pow, Real.sq_sqrt hτ.le] + rw [FeynmanKacHeatEquation.feynmanU_eq_integral_of_map + (B := fun _ ω ↦ σ * Real.sqrt τ * ω) (μ := gaussianReal 0 1) + (measurable_const.mul measurable_id).aemeasurable hmap hg_cont hvar + (Real.log S + (r - σ ^ 2 / 2) * τ)] + have hpoint : ∀ ω : ℝ, + g (Real.log S + (r - σ ^ 2 / 2) * τ + σ * Real.sqrt τ * ω) + = Real.exp (-r * τ) * max (bsTerminal S r σ τ ω - K) 0 := by + intro ω + have hexp : Real.exp (Real.log S + (r - σ ^ 2 / 2) * τ + σ * Real.sqrt τ * ω) + = bsTerminal S r σ τ ω := by + simp only [bsTerminal] + rw [show Real.log S + (r - σ ^ 2 / 2) * τ + σ * Real.sqrt τ * ω + = Real.log S + ((r - σ ^ 2 / 2) * τ + σ * Real.sqrt τ * ω) from by ring, + Real.exp_add, Real.exp_log hS] + simp only [hg, hexp, neg_mul] + simp_rw [hpoint] + have hcf := bs_call_formula (Q := gaussianReal 0 1) (Z := (id : ℝ → ℝ)) + (S_0 := S) (K := K) (r := r) (σ := σ) (T := τ) ⟨hS, hK, hσ, hτ, HasLaw.id⟩ + simp only [id_eq] at hcf + rw [hcf, bsV, neg_mul] + +/-- For `0 < K`, `|max (exp z - K) 0| ≤ exp z`. -/ +lemma abs_max_exp_sub_zero_le_exp {K : ℝ} (hK : 0 < K) (z : ℝ) : + |max (Real.exp z - K) 0| ≤ Real.exp z := by + rw [abs_of_nonneg (le_max_right _ _)] + exact max_le (by linarith) (Real.exp_nonneg z) + +/-- **Step 3 (bridge) — the Black–Scholes value is a discounted heat flow.** -/ +theorem bsV_eq_discount_feynmanU {K r σ S τ : ℝ} + (hS : 0 < S) (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) : + bsV K r σ S τ = Real.exp (-(r * τ)) + * feynmanU (fun ξ ↦ max (Real.exp ξ - K) 0) (σ ^ 2 * τ) + (Real.log S + (r - σ ^ 2 / 2) * τ) := by + rw [bsV_eq_feynmanU hS hK hσ hτ] + simp only [feynmanU] + rw [← integral_const_mul] + congr 1 + ext z + ring + +/-- **Step 3 (Delta) — the `S`-derivative of `bsV`, via Feynman–Kac.** -/ +private lemma hasDerivAt_bsV_S_fk {K r σ τ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) + {S : ℝ} (hS : 0 < S) : + HasDerivAt (fun S' ↦ bsV K r σ S' τ) + (Real.exp (-(r * τ)) + * ((∫ z, max (Real.exp z - K) 0 + * ((z - (Real.log S + (r - σ ^ 2 / 2) * τ)) / (σ ^ 2 * τ) + * heatKernel (σ ^ 2 * τ) (z - (Real.log S + (r - σ ^ 2 / 2) * τ)))) + * S⁻¹)) S := by + have ht₀ : (0 : ℝ) < σ ^ 2 * τ := by positivity + have hchain := + (hasDerivAt_feynmanU_x ht₀ + (by fun_prop : Continuous (fun ξ : ℝ ↦ max (Real.exp ξ - K) 0)) + (abs_max_exp_sub_zero_le_exp hK) + (Real.log S + (r - σ ^ 2 / 2) * τ)).comp S + ((Real.hasDerivAt_log hS.ne').add_const ((r - σ ^ 2 / 2) * τ)) + refine (hchain.const_mul (Real.exp (-(r * τ)))).congr_of_eventuallyEq ?_ + filter_upwards [isOpen_Ioi.mem_nhds hS] with S' hS' + exact bsV_eq_discount_feynmanU hS' hK hσ hτ + +/-- **Step 3 (Theta) — the `τ`-derivative of `bsV`, via Feynman–Kac.** The price's time-decay, +derived from the heat kernel's curve derivative (`hasDerivAt_feynmanU_comp`): product rule on the +discount `e^{−rτ'}` and the discounted heat flow (both kernel arguments `σ²τ'` and +`log S + (r−σ²/2)τ'` move with `τ'`), with the bridge `bsV_eq_discount_feynmanU` for the `τ' > 0` +domain. This is the consumer that makes `hasDerivAt_feynmanU_comp` — and through it the heat +kernel's *joint* differentiability `hasFDerivAt_heatKernel` — load-bearing for the Black–Scholes +time-derivative. -/ +private lemma hasDerivAt_bsV_tau_fk {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S : ℝ} (hS : 0 < S) {τ : ℝ} (hτ : 0 < τ) : + HasDerivAt (fun τ' ↦ bsV K r σ S τ') + (-r * Real.exp (-(r * τ)) + * feynmanU (fun ξ ↦ max (Real.exp ξ - K) 0) (σ ^ 2 * τ) + (Real.log S + (r - σ ^ 2 / 2) * τ) + + Real.exp (-(r * τ)) + * (∫ z, max (Real.exp z - K) 0 + * (σ ^ 2 * (heatKernel (σ ^ 2 * τ) (z - (Real.log S + (r - σ ^ 2 / 2) * τ)) + * ((z - (Real.log S + (r - σ ^ 2 / 2) * τ)) ^ 2 - σ ^ 2 * τ) + / (2 * (σ ^ 2 * τ) ^ 2)) + + (r - σ ^ 2 / 2) * ((z - (Real.log S + (r - σ ^ 2 / 2) * τ)) / (σ ^ 2 * τ) + * heatKernel (σ ^ 2 * τ) (z - (Real.log S + (r - σ ^ 2 / 2) * τ)))) ∂volume)) + τ := by + have hσ2 : (0 : ℝ) < σ ^ 2 := by positivity + have hexp : HasDerivAt (fun τ' ↦ Real.exp (-(r * τ'))) (-r * Real.exp (-(r * τ))) τ := by + have h1 : HasDerivAt (fun τ' : ℝ ↦ -(r * τ')) (-r) τ := by + have h := (hasDerivAt_id τ).const_mul (-r) + simp only [neg_mul, mul_one] at h + exact h + have h2 := h1.exp + convert h2 using 1 + ring + have hfk := hasDerivAt_feynmanU_comp (h := fun ξ ↦ max (Real.exp ξ - K) 0) + (by fun_prop : Continuous (fun ξ : ℝ ↦ max (Real.exp ξ - K) 0)) + (abs_max_exp_sub_zero_le_exp hK) (α := σ ^ 2) + (β := r - σ ^ 2 / 2) + (x₀ := Real.log S) hσ2 hτ + refine (hexp.mul hfk).congr_of_eventuallyEq ?_ + filter_upwards [isOpen_Ioi.mem_nhds hτ] with τ' hτ' + exact bsV_eq_discount_feynmanU hS hK hσ hτ' + +/-- **Step 3 (Gamma) — the second `S`-derivative of `bsV`, via Feynman–Kac.** Differentiating the +Delta `e^{−rτ}·U_x·S⁻¹` (from `hasDerivAt_bsV_S_fk`) in `S`: the first space-derivative integral +`U_x` moves through `log S` (chain rule on `hasDerivAt_feynmanU_xx`, giving `U_xx·S⁻¹`) and the +`S⁻¹` factor contributes `−U_x·S⁻²`, so `∂_SS V = e^{−rτ}·(U_xx − U_x)/S²`. The third in-place +Greek-via-FK awaiting the step-4 PDE assembly. -/ +private lemma hasDerivAt_bsV_SS_fk {K r σ τ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) + {S : ℝ} (hS : 0 < S) : + HasDerivAt (fun S' ↦ Real.exp (-(r * τ)) + * ((∫ z, max (Real.exp z - K) 0 + * ((z - (Real.log S' + (r - σ ^ 2 / 2) * τ)) / (σ ^ 2 * τ) + * heatKernel (σ ^ 2 * τ) (z - (Real.log S' + (r - σ ^ 2 / 2) * τ)))) * S'⁻¹)) + (Real.exp (-(r * τ)) + * (((∫ z, max (Real.exp z - K) 0 + * (heatKernel (σ ^ 2 * τ) (z - (Real.log S + (r - σ ^ 2 / 2) * τ)) + * ((z - (Real.log S + (r - σ ^ 2 / 2) * τ)) ^ 2 - σ ^ 2 * τ) / (σ ^ 2 * τ) ^ 2)) + - (∫ z, max (Real.exp z - K) 0 + * ((z - (Real.log S + (r - σ ^ 2 / 2) * τ)) / (σ ^ 2 * τ) + * heatKernel (σ ^ 2 * τ) (z - (Real.log S + (r - σ ^ 2 / 2) * τ))))) / S ^ 2)) + S := by + have ht₀ : (0 : ℝ) < σ ^ 2 * τ := by positivity + have hg := (hasDerivAt_feynmanU_xx ht₀ + (by fun_prop : Continuous (fun ξ : ℝ ↦ max (Real.exp ξ - K) 0)) + (abs_max_exp_sub_zero_le_exp hK) (Real.log S + (r - σ ^ 2 / 2) * τ)).comp S + ((Real.hasDerivAt_log hS.ne').add_const ((r - σ ^ 2 / 2) * τ)) + have hprod := (hg.mul (hasDerivAt_inv hS.ne')).const_mul (Real.exp (-(r * τ))) + have hSne : S ≠ 0 := hS.ne' + set Uxx := ∫ z, max (Real.exp z - K) 0 + * (heatKernel (σ ^ 2 * τ) (z - (Real.log S + (r - σ ^ 2 / 2) * τ)) + * ((z - (Real.log S + (r - σ ^ 2 / 2) * τ)) ^ 2 - σ ^ 2 * τ) / (σ ^ 2 * τ) ^ 2) + set Ux := ∫ z, max (Real.exp z - K) 0 + * ((z - (Real.log S + (r - σ ^ 2 / 2) * τ)) / (σ ^ 2 * τ) + * heatKernel (σ ^ 2 * τ) (z - (Real.log S + (r - σ ^ 2 / 2) * τ))) + have hUx_eq : ((fun x' ↦ ∫ (z : ℝ), max (Real.exp z - K) 0 * ((z - x') / (σ ^ 2 * τ) + * heatKernel (σ ^ 2 * τ) (z - x'))) ∘ + fun x ↦ Real.log x + (r - σ ^ 2 / 2) * τ) S = Ux := by + simp only [Function.comp_def] + rfl + refine hprod.congr_deriv ?_ + rw [hUx_eq] + field_simp [hS.ne'] + ring + +/-- Integrability of the call payoff against the kernel's time-derivative integrand `h·∂_t K` +(`|h| ≤ eᶻ`), dominated by the sub-Gaussian envelope. Needed to split the combined `τ`-derivative +integral in the PDE assembly. -/ +private lemma integrable_payoff_mul_dtK {t : ℝ} (ht : 0 < t) {K : ℝ} (hK : 0 < K) (x : ℝ) : + Integrable (fun z ↦ max (Real.exp z - K) 0 + * (heatKernel t (z - x) * ((z - x) ^ 2 - t) / (2 * t ^ 2))) volume := by + apply ((integrable_exp_mul_poly_heatKernel ht x t).const_mul (1 / (2 * t ^ 2))).mono' + · exact ((by fun_prop : Continuous (fun ξ : ℝ ↦ max (Real.exp ξ - K) 0)).mul + (((continuous_heatKernel t).comp (continuous_id.sub continuous_const)).mul + (((continuous_id.sub continuous_const).pow 2).sub continuous_const) + |>.div_const _)).aestronglyMeasurable + · refine ae_of_all _ fun z ↦ ?_ + have hKnn := heatKernel_nonneg ht (z - x) + have hnorm : ‖max (Real.exp z - K) 0 * (heatKernel t (z - x) * ((z - x) ^ 2 - t) / (2 * t ^ 2))‖ + = 1 / (2 * t ^ 2) * + (|max (Real.exp z - K) 0| * (heatKernel t (z - x) * |(z - x) ^ 2 - t|)) := by + rw [Real.norm_eq_abs, abs_mul, abs_div, abs_mul, abs_of_nonneg hKnn, + abs_of_nonneg (by positivity : (0:ℝ) ≤ 2 * t ^ 2)]; ring + rw [hnorm] + have habs : |(z - x) ^ 2 - t| ≤ (z - x) ^ 2 + t := by + rw [abs_le]; constructor <;> nlinarith [sq_nonneg (z - x)] + apply mul_le_mul_of_nonneg_left _ (by positivity : (0:ℝ) ≤ 1 / (2 * t ^ 2)) + calc |max (Real.exp z - K) 0| * (heatKernel t (z - x) * |(z - x) ^ 2 - t|) + ≤ Real.exp z * (heatKernel t (z - x) * ((z - x) ^ 2 + t)) := by + refine mul_le_mul (abs_max_exp_sub_zero_le_exp hK z) ?_ (mul_nonneg hKnn (abs_nonneg _)) + (Real.exp_nonneg z) + exact mul_le_mul_of_nonneg_left habs hKnn + _ = Real.exp z * (((z - x) ^ 2 + t) * heatKernel t (z - x)) := by ring + +/-- Integrability of the call payoff against the kernel's space-derivative integrand `h·∂_x K`. -/ +private lemma integrable_payoff_mul_dxK {t : ℝ} (ht : 0 < t) {K : ℝ} (hK : 0 < K) (x : ℝ) : + Integrable (fun z ↦ max (Real.exp z - K) 0 + * ((z - x) / t * heatKernel t (z - x))) volume := by + apply ((integrable_exp_mul_poly_heatKernel ht x 1).const_mul (1 / t)).mono' + · exact ((by fun_prop : Continuous (fun ξ : ℝ ↦ max (Real.exp ξ - K) 0)).mul + (((continuous_id.sub continuous_const).div_const t).mul + ((continuous_heatKernel t).comp (continuous_id.sub continuous_const)))).aestronglyMeasurable + · refine ae_of_all _ fun z ↦ ?_ + have hKnn := heatKernel_nonneg ht (z - x) + have hnorm : ‖max (Real.exp z - K) 0 * ((z - x) / t * heatKernel t (z - x))‖ + = 1 / t * (|max (Real.exp z - K) 0| * (|z - x| * heatKernel t (z - x))) := by + rw [Real.norm_eq_abs, abs_mul, abs_mul, abs_div, abs_of_nonneg hKnn, + abs_of_nonneg ht.le]; ring + rw [hnorm] + have habs : |z - x| ≤ (z - x) ^ 2 + 1 := by + nlinarith [sq_nonneg (|z - x| - 1), sq_abs (z - x), abs_nonneg (z - x)] + apply mul_le_mul_of_nonneg_left _ (by positivity : (0:ℝ) ≤ 1 / t) + refine mul_le_mul (abs_max_exp_sub_zero_le_exp hK z) ?_ (mul_nonneg (abs_nonneg _) hKnn) + (Real.exp_nonneg z) + exact mul_le_mul_of_nonneg_right habs hKnn + +/-- **Step 4 — the Black–Scholes PDE, derived from Feynman–Kac.** The call value's actual +derivatives satisfy `−∂_τ V + ½σ²S²·∂_SS V + rS·∂_S V − rV = 0`. The three derivatives are the +Feynman–Kac Greeks (`hasDerivAt_bsV_{S,SS,tau}_fk`), each a heat-kernel integral; the operator +vanishes *because the heat kernel does*: the `U_x` drift terms cancel algebraically and +`∂_t U = ½ ∂_xx U` is the kernel heat equation (`feynmanU_heat_equation`). This is the independent, +probabilistically-grounded re-derivation of `bs_pde_holds` — closing the two-tower gap by making +`feynmanU` load-bearing for the PDE. (The hard differentiability work — uniform domination, +differentiation under the integral — already lives in `hasDerivAt_feynmanU_comp` and the Greeks; +`feynmanU_heat_equation` supplies only the algebraic kernel identity `∂_t K = ½ ∂_xx K`, and the +operator vanishing is then exact algebra.) The three derivatives, being derivatives of `bsV`, are +the closed-form theta, delta and gamma of `PDE.lean`; the last three conjuncts say so +(`HasDerivAt.unique`), so the Feynman–Kac Greeks and the closed-form ones are the same numbers. -/ +theorem bsV_satisfies_bs_pde_via_feynmanKac {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + ∃ Vτ VS VSS : ℝ, + HasDerivAt (fun τ' ↦ bsV K r σ S τ') Vτ τ ∧ + HasDerivAt (fun S' ↦ bsV K r σ S' τ) VS S ∧ + HasDerivAt (fun S' ↦ deriv (fun S'' ↦ bsV K r σ S'' τ) S') VSS S ∧ + -Vτ + (1 / 2) * σ ^ 2 * S ^ 2 * VSS + r * S * VS - r * bsV K r σ S τ = 0 ∧ + Vτ = σ * S * gaussianPDFReal 0 1 (bsd1 S K r σ τ) / (2 * Real.sqrt τ) + + r * K * Real.exp (-(r * τ)) * Phi (bsd2 S K r σ τ) ∧ + VS = Phi (bsd1 S K r σ τ) ∧ + VSS = gaussianPDFReal 0 1 (bsd1 S K r σ τ) / (S * σ * Real.sqrt τ) := by + have hVτ := hasDerivAt_bsV_tau_fk (r := r) hK hσ hS hτ + have hVS := hasDerivAt_bsV_S_fk (r := r) hK hσ hτ hS + have hVSS := hasDerivAt_deriv_of_eventually + ((eventually_gt_nhds hS).mono fun _ hS' ↦ hasDerivAt_bsV_S_fk (r := r) hK hσ hτ hS') + (hasDerivAt_bsV_SS_fk (r := r) hK hσ hτ hS) + refine ⟨_, _, _, hVτ, hVS, hVSS, ?_, hVτ.unique (hasDerivAt_bsV_tau hK hσ hS hτ), + hVS.unique (hasDerivAt_bsV_S hK hσ hS hτ), + hVSS.unique (hasDerivAt_deriv_bsV_S hK hσ hS hτ)⟩ + · have ht₀ : (0 : ℝ) < σ ^ 2 * τ := by positivity + have hSne : S ≠ 0 := hS.ne' + set c₀ : ℝ := Real.log S + (r - σ ^ 2 / 2) * τ + have hheat := feynmanU_heat_equation ht₀ (fun ξ ↦ max (Real.exp ξ - K) 0) c₀ + rw [bsV_eq_discount_feynmanU hS hK hσ hτ, + show (∫ z, max (Real.exp z - K) 0 + * (σ ^ 2 * (heatKernel (σ ^ 2 * τ) (z - c₀) + * ((z - c₀) ^ 2 - σ ^ 2 * τ) / (2 * (σ ^ 2 * τ) ^ 2)) + + (r - σ ^ 2 / 2) * ((z - c₀) / (σ ^ 2 * τ) * heatKernel (σ ^ 2 * τ) (z - c₀)))) + = σ ^ 2 * (∫ z, max (Real.exp z - K) 0 + * (heatKernel (σ ^ 2 * τ) (z - c₀) * ((z - c₀) ^ 2 - σ ^ 2 * τ) / + (2 * (σ ^ 2 * τ) ^ 2))) + + (r - σ ^ 2 / 2) * (∫ z, max (Real.exp z - K) 0 + * ((z - c₀) / (σ ^ 2 * τ) * heatKernel (σ ^ 2 * τ) (z - c₀))) from by + rw [← integral_const_mul, ← integral_const_mul, + ← integral_add ((integrable_payoff_mul_dtK ht₀ hK c₀).const_mul _) + ((integrable_payoff_mul_dxK ht₀ hK c₀).const_mul _)] + congr 1; ext z; ring, + hheat] + set U := feynmanU (fun ξ ↦ max (Real.exp ξ - K) 0) (σ ^ 2 * τ) c₀ + set Uxx := ∫ z, max (Real.exp z - K) 0 + * (heatKernel (σ ^ 2 * τ) (z - c₀) * ((z - c₀) ^ 2 - σ ^ 2 * τ) / (σ ^ 2 * τ) ^ 2) + set Ux := ∫ z, max (Real.exp z - K) 0 + * ((z - c₀) / (σ ^ 2 * τ) * heatKernel (σ ^ 2 * τ) (z - c₀)) + field_simp + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/PartialTimeBarrierOption.lean b/LeanPool/MathFin/Models/BlackScholes/PartialTimeBarrierOption.lean new file mode 100644 index 0000000000..2e6bb6360a --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/PartialTimeBarrierOption.lean @@ -0,0 +1,248 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.HeynenKatTwoAssetBarrier + +/-! +# Partial-time barrier options (start window, call): Haug's closed form + +A barrier that is monitored only on part of the option's life. This file covers the **start** +window, **call** side (QuantLib's `PartialBarrier::Start`, `Option::Call`): the barrier is live +on `[0, t₁]` and switched off for the remainder `(t₁, T]` of the option's life (Haug's +"Partial-Time Single-Asset Barrier Options", full citation below). Unlike the binary barrier +transcribed alongside this file, this genuinely needs the **bivariate** normal +CDF — the barrier-monitoring window `[0, t₁]` and the full life `[0, T]` are correlated +(correlation `ρ = √(t₁/T)`, the two Brownian increments share the `[0, t₁]` leg) — which is why +this file builds on the same `BivariateNormalCDF.lean` substrate (`bivariateNormalCDF`, +`bivariateNormalCDF_flip_snd`) as `HeynenKatTwoAssetBarrier.lean`. Sources for the closed +form: Heynen & Kat, "Partial barrier options", *Journal of Financial Engineering* 3 (1994); +Haug, *The Complete Guide to Option Pricing Formulas*, 2nd ed. (2007), ch. 4, "Partial-Time +Single-Asset Barrier Options" (the `A`-value table the engine's `CA` transcribes). + +**Scope, disclosed honestly**: QuantLib's `AnalyticPartialTimeBarrierOptionEngine` also prices +the **end**-window case (`PartialBarrier::EndB1`/`EndB2`, barrier live only on `(t₁, T]`) via +`CoB1`/`CoB2`, which are substantially more involved (each has its own strike-vs-barrier case +split with extra vanilla-minus-partial decompositions) and genuinely harder; this file formalizes +the **start**-window case (`CA`, QuantLib's simplest of the three) and leaves `EndB1`/`EndB2` out +of scope. **`CA` is also call-only**: QuantLib's `CA` is commented +`//Partial-Time-Start- OUT Call Option calculation`, and the engine prices a *put* in +`calculate()` via the put–call spot-reflection symmetry (strike `X ↦ S²/X`, barrier `H ↦ S²/H`, +barrier direction mirrored, the `CA`-call result on the transformed inputs scaled by `X/S`) rather +than a second closed form — that symmetry transform is not formalized here either. The knock-in +case (`CIA = vanilla − CA`) is in–out parity — the closed-form counterpart of +`BarrierParity.lean`'s `knockIn_add_knockOut_eq_vanilla` (the barrier-hit event and its +complement partition the payoff) — rather than an independent closed form, so it is not +separately formalized. + +Transcribed from QuantLib's +`ql/pricingengines/barrier/analyticpartialtimebarrieroptionengine.cpp` (`CA`, upstream commit +`5f4811e`, 2026-10-16; contributed 2014 by Polytech'Nice Sophia Antipolis). We adopt a single +constant volatility `σ` (QuantLib's engine reads a possibly term-structured Black vol evaluated +at `t₁` for `μ` and the `e`-terms and at `T` for the `d`/`f`-terms; Haug's original textbook +closed form, which this transcribes, uses one constant `σ` throughout — the flat-vol case +QuantLib's more general engine specializes to). + +With cost-of-carry `b = r − q`, `ρ = √(t₁/T)`, `μ = (b − σ²/2)/σ²`, and + + `d₁ = (log(S/X) + (b+σ²/2)T)/(σ√T)`, `d₂ = d₁ − σ√T`, + `e₁ = (log(S/H) + (b+σ²/2)t₁)/(σ√t₁)`, `e₂ = e₁ − σ√t₁`, + `e₃ = e₁ + 2log(H/S)/(σ√t₁)`, `e₄ = e₃ − σ√t₁`, + `f₁ = (log(S/X) + 2log(H/S) + (b+σ²/2)T)/(σ√T)`, `f₂ = f₁ − σ√T`, + +and `(H/S)^{2μ}`, `(H/S)^{2(μ+1)}` as `exp(·log·)` (as in `BinaryBarrierOption.lean` and +`HeynenKatTwoAssetBarrier.lean`), the +start-window out-barrier **call** value (`η = 1` down, `η = −1` up) is + + `CA(η) = S·e^{(b−r)T}·(N₂(d₁, ηe₁; ηρ) − (H/S)^{2(μ+1)}·N₂(f₁, ηe₃; ηρ))` + `− X·e^{−rT}·(N₂(d₂, ηe₂; ηρ) − (H/S)^{2μ}·N₂(f₂, ηe₄; ηρ))`. + +## Main definitions + +* `ptRho`: `ρ = √(t₁/T)`, the correlation between the barrier-window and full-life log-returns. +* `ptMu`: `μ = (b − σ²/2)/σ²`, the drift parameter of the barrier formulas. +* `ptD1`, `ptD2`: the Black–Scholes `d₁`, `d₂` with cost of carry `b` against the strike `X` over + the full life `T`. +* `ptE1`, `ptE2`, `ptE3`, `ptE4`: the corresponding quantities against the barrier `H` over the + monitoring window `t₁`, with `ptE3`, `ptE4` carrying the barrier reflection term. +* `ptF1`, `ptF2`: `d₁` and `d₂` shifted by the barrier reflection term over the full life `T`. +* `ptCA`: the partial-time-start barrier call closed form `CA(η)` (`η = 1` down, `η = −1` up), + Haug's expression with the barrier live on `[0, t₁]`; not proved to be a discounted expected + payoff. +* `ptDownOutCall`: the full-life down-and-out call closed form (Rubinstein–Reiner), as transcribed + in this file. + +## Main results + +* `ptCA_down_add_up`: **`CA(1) + CA(−1)` collapses to a closed form with no bivariate CDF left** + — every `N₂(a, ηb; ηρ)` pair (`η = ±1`) telescopes via `bivariateNormalCDF_flip_snd` to a + single `Φ(a)`, exactly the mechanism behind `HeynenKatTwoAssetBarrier.lean`'s + `heynenKat_downOut_add_upOut`. As there, the down/up window-start prices are mutually exclusive + regimes (down-monitored vs. up-monitored), so the sum itself is not a payoff decomposition; + what the identity shows is that the sum is `t₁`-free — it equals `ptDownOutCall`, the + transcribed full-life down-and-out call closed form (the `X ≥ H` branch), for every + `0 ≤ t₁ ≤ T`, not only in some limit. It verifies the `(ηe_i, ηρ)` sign pattern is + self-consistent across `η = ±1`, the same scope the Heynen–Kat file disclosed for its own + analogous check. + +* `ptCA_down_monitored_full_life`: **monitoring over the whole life gives the full-life + closed form** — at `t₁ = T` (with `X ≥ H`), the correlation `ρ = 1` degenerates each + `N₂(a, ηb; ηρ)` to + `Φ(min(a, ηb))` via `bivariateNormalCDF_one`, and `X ≥ H` orders every such pair so the `d`/`f` + term is the minimum, reducing `CA(1)` directly to `ptDownOutCall`, the closed form + `ptCA_down_add_up` reaches. + Both are identities between transcribed closed forms; neither is proved to be a price. + +## References + +* [Haug, *The Complete Guide to Option Pricing Formulas*][Haug2007], ch. 4 +* [Heynen and Kat, *Partial barrier options*][HeynenKat1994b] + +## Tags + +partial barrier option, Heynen–Kat, Haug closed form, barrier monitoring window, bivariate normal, +knock-out call, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +/-- **`ρ = √(t₁/T)`**, the correlation between the barrier-window and full-life log-returns. -/ +noncomputable def ptRho (t1 T : ℝ) : ℝ := Real.sqrt (t1 / T) + +/-- **`μ = (b − σ²/2)/σ²`** — `hkMu`'s drift (`HeynenKatTwoAssetBarrier.lean`) divided by +`σ²`, the same `hkMu`-style parameter the binary barrier's `mu` takes. -/ +noncomputable def ptMu (b σ : ℝ) : ℝ := hkMu b σ / σ ^ 2 + +/-- **`d₁`**: the standard BS `d₁` (`bsd1`, `Models/BlackScholes/Call.lean`) with the cost-of-carry +`b` in the rate slot, against strike `X` over the full life `T`. -/ +noncomputable def ptD1 (S X b σ T : ℝ) : ℝ := bsd1 S X b σ T + +/-- **`d₂`** = `bsd2 S X b σ T` — `d₁ − σ√T`. -/ +noncomputable def ptD2 (S X b σ T : ℝ) : ℝ := bsd2 S X b σ T + +/-- **`e₁`**: `bsd1` against the barrier `H` over the monitoring window `t₁`. -/ +noncomputable def ptE1 (S H b σ t1 : ℝ) : ℝ := bsd1 S H b σ t1 + +/-- **`e₂` = `e₁ − σ√t₁`** = `bsd2 S H b σ t₁`. -/ +noncomputable def ptE2 (S H b σ t1 : ℝ) : ℝ := bsd2 S H b σ t1 + +/-- **`e₃`**: `e₁` shifted by the barrier reflection term. -/ +noncomputable def ptE3 (S H b σ t1 : ℝ) : ℝ := + ptE1 S H b σ t1 + 2 * Real.log (H / S) / (σ * Real.sqrt t1) + +/-- **`e₄` = `e₃ − σ√t₁`**. -/ +noncomputable def ptE4 (S H b σ t1 : ℝ) : ℝ := ptE3 S H b σ t1 - σ * Real.sqrt t1 + +/-- **`f₁`**: `d₁` shifted by the barrier reflection term (over the full life `T`). -/ +noncomputable def ptF1 (S X H b σ T : ℝ) : ℝ := + (Real.log (S / X) + 2 * Real.log (H / S) + (b + σ ^ 2 / 2) * T) / (σ * Real.sqrt T) + +/-- **`f₂` = `f₁ − σ√T`**. -/ +noncomputable def ptF2 (S X H b σ T : ℝ) : ℝ := ptF1 S X H b σ T - σ * Real.sqrt T + +/-- **`(H/S)^{2μ}`**, written as `exp(·log·)`. -/ +noncomputable def ptHSmu (S H b σ : ℝ) : ℝ := Real.exp (2 * ptMu b σ * Real.log (H / S)) + +/-- **`(H/S)^{2(μ+1)}`**. -/ +noncomputable def ptHSmu1 (S H b σ : ℝ) : ℝ := Real.exp (2 * (ptMu b σ + 1) * Real.log (H / S)) + +/-- **Partial-time-start barrier call value** `CA(η)` (QuantLib's +`AnalyticPartialTimeBarrierOptionEngine::CA`; `η = 1` down, `η = −1` up; call-only — see the +module docstring's "Scope" paragraph for how QuantLib prices the put side instead). -/ +noncomputable def ptCA (eta S X H b r σ t1 T : ℝ) : ℝ := + S * Real.exp ((b - r) * T) * + (bivariateNormalCDF (ptD1 S X b σ T) (eta * ptE1 S H b σ t1) (eta * ptRho t1 T) + - ptHSmu1 S H b σ * + bivariateNormalCDF (ptF1 S X H b σ T) (eta * ptE3 S H b σ t1) (eta * ptRho t1 T)) + - X * Real.exp (-r * T) * + (bivariateNormalCDF (ptD2 S X b σ T) (eta * ptE2 S H b σ t1) (eta * ptRho t1 T) + - ptHSmu S H b σ * + bivariateNormalCDF (ptF2 S X H b σ T) (eta * ptE4 S H b σ t1) (eta * ptRho t1 T)) + +/-- **The full-life down-and-out call closed form** (Rubinstein & Reiner (1991); Haug (2007), +ch. 4, the `X ≥ H` branch), transcribed: the barrier monitored over all of `[0, T]`. It is a +closed-form expression here, not proved to be the expected discounted knock-out payoff. -/ +noncomputable def ptDownOutCall (S X H b r σ T : ℝ) : ℝ := + S * Real.exp ((b - r) * T) * + (Phi (ptD1 S X b σ T) - ptHSmu1 S H b σ * Phi (ptF1 S X H b σ T)) + - X * Real.exp (-r * T) * + (Phi (ptD2 S X b σ T) - ptHSmu S H b σ * Phi (ptF2 S X H b σ T)) + +/-- `ρ² ≤ 1` whenever `0 ≤ t₁ ≤ T` — the hypothesis `bivariateNormalCDF_flip_snd` needs, since +a monitoring window can only be a sub-interval of the option's life. -/ +theorem ptRho_sq_le_one {t1 T : ℝ} (ht1 : 0 ≤ t1) (hT : t1 ≤ T) : ptRho t1 T ^ 2 ≤ 1 := by + have hT0 : 0 ≤ T := ht1.trans hT + rw [ptRho, Real.sq_sqrt (div_nonneg ht1 hT0)] + exact div_le_one_of_le₀ hT hT0 + +/-- **Down-window plus up-window, same strike/barrier**: `CA(1) + CA(−1)` collapses to a closed +form with every bivariate CDF replaced by a single `Φ`, via `bivariateNormalCDF_flip_snd` applied +to each of the four `N₂` pairs (see the module docstring for the scope this checks). -/ +theorem ptCA_down_add_up (S X H b r σ t1 T : ℝ) (ht1 : 0 ≤ t1) (hT : t1 ≤ T) : + ptCA 1 S X H b r σ t1 T + ptCA (-1) S X H b r σ t1 T = ptDownOutCall S X H b r σ T := by + have hr : ptRho t1 T ^ 2 ≤ 1 := ptRho_sq_le_one ht1 hT + have hd1 := bivariateNormalCDF_flip_snd (ptD1 S X b σ T) (ptE1 S H b σ t1) hr + have hf1 := bivariateNormalCDF_flip_snd (ptF1 S X H b σ T) (ptE3 S H b σ t1) hr + have hd2 := bivariateNormalCDF_flip_snd (ptD2 S X b σ T) (ptE2 S H b σ t1) hr + have hf2 := bivariateNormalCDF_flip_snd (ptF2 S X H b σ T) (ptE4 S H b σ t1) hr + simp only [ptCA, ptDownOutCall, one_mul, neg_one_mul] + linear_combination S * Real.exp ((b - r) * T) * hd1 + - S * Real.exp ((b - r) * T) * ptHSmu1 S H b σ * hf1 + - X * Real.exp (-r * T) * hd2 + X * Real.exp (-r * T) * ptHSmu S H b σ * hf2 + +/-- **Monitoring over the whole life gives the full-life closed form.** With the barrier live on +`[0, T]` (i.e. `t₁ = T`) and the strike dominating the barrier (`X ≥ H`, the branch where the +down-and-out closed form holds without a min inside the payoff), the start-window value +`ptCA 1 … T T` reduces to `ptDownOutCall`, the transcribed full-life down-and-out call closed form — +the same `t₁`-free expression `ptCA_down_add_up` collapses to, here obtained directly: the +correlation `ptRho T T = 1`, so `bivariateNormalCDF_one` turns each `N₂(a, b; 1)` into +`Φ(min(a, b))`, and `X ≥ H` makes `d₁ ≤ e₁`, `f₁ ≤ e₃`, `d₂ ≤ e₂`, `f₂ ≤ e₄` (each pair differs +exactly by `log(S/X) ≤ log(S/H)` over the same positive denominator), so every min is the `d`/ `f` +term. -/ +theorem ptCA_down_monitored_full_life (S X H b r σ T : ℝ) (hS : 0 < S) (hX : 0 < X) + (hH : 0 < H) (hXH : H ≤ X) (hσ : 0 < σ) (hT : 0 < T) : + ptCA 1 S X H b r σ T T = ptDownOutCall S X H b r σ T := by + have hsqrt : 0 < σ * Real.sqrt T := mul_pos hσ (Real.sqrt_pos.mpr hT) + have hSdX : 0 < S / X := div_pos hS hX + have hSdH : 0 < S / H := div_pos hS hH + have hlog : Real.log (S / X) ≤ Real.log (S / H) := + (Real.log_le_log_iff hSdX hSdH).mpr (by field_simp; linarith) + -- every `(d/e, f/e)` pair differs exactly by `log(S/X) ≤ log(S/H)` over the same + -- positive denominator `σ√T` (with `X ≥ H`), so `div_le_iff₀` reduces each to `hlog` + have hd1e1 : ptD1 S X b σ T ≤ ptE1 S H b σ T := by + unfold ptD1 ptE1 bsd1 + rw [div_le_iff₀ hsqrt, div_mul_eq_mul_div, mul_div_cancel_right₀ _ hsqrt.ne'] + linarith + have hF1decomp : ptF1 S X H b σ T + = ptD1 S X b σ T + 2 * Real.log (H / S) / (σ * Real.sqrt T) := by + simp only [ptF1, ptD1, bsd1] + rw [add_div, add_div] + ring + have hf1e3 : ptF1 S X H b σ T ≤ ptE3 S H b σ T := by + rw [hF1decomp] + simp only [ptE3] + linarith [hd1e1] + have hd2e2 : ptD2 S X b σ T ≤ ptE2 S H b σ T := by + unfold ptD2 ptE2 + exact sub_le_sub_right hd1e1 _ + have hf2e4 : ptF2 S X H b σ T ≤ ptE4 S H b σ T := by + unfold ptF2 ptE4 + exact sub_le_sub_right hf1e3 _ + have hrho : ptRho T T = 1 := by + unfold ptRho + rw [div_self hT.ne', Real.sqrt_one] + have hD1 := bivariateNormalCDF_one (ptD1 S X b σ T) (ptE1 S H b σ T) + have hF1 := bivariateNormalCDF_one (ptF1 S X H b σ T) (ptE3 S H b σ T) + have hD2 := bivariateNormalCDF_one (ptD2 S X b σ T) (ptE2 S H b σ T) + have hF2 := bivariateNormalCDF_one (ptF2 S X H b σ T) (ptE4 S H b σ T) + simp only [ptCA, ptDownOutCall, one_mul, hrho, hD1, hF1, hD2, hF2, + min_eq_left hd1e1, min_eq_left hf1e3, min_eq_left hd2e2, min_eq_left hf2e4] + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/PowerCall.lean b/LeanPool/MathFin/Models/BlackScholes/PowerCall.lean new file mode 100644 index 0000000000..85426f5661 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/PowerCall.lean @@ -0,0 +1,168 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Call + +/-! +# Powered call option closed form (first-principles) + +The **powered call** with exponent `a : ℕ` pays `max((S_T)^a − K, 0)` at +maturity. Its risk-neutral discounted price has a closed form in the BS +lognormal model — derived here as a direct consequence of `bs_call_formula` +via the structural identity that **`(S_T)^a` is itself a BS terminal**, with +*effective spot* `S_0^a · exp((a−1)rT + a(a−1)/2 σ²T)` and *effective +volatility* `aσ`. No new integral is computed: the only new content is the +algebraic identity reducing the powered case to the standard case. + +## Mathematical content + +Starting from `S_T = S_0 · exp((r − σ²/2)T + σ√T·Z)`, + + `(S_T)^a = S_0^a · exp(a(r − σ²/2)T + aσ√T·Z)`. + +We want to write the RHS as `Š_0 · exp((r − σ_tilde²/2)T + σ_tilde√T·Z)` for some +effective spot `Š_0` and volatility `σ_tilde`. Setting `σ_tilde = aσ` gives `σ_tilde²T = +a²σ²T`, so + + `Š_0 = S_0^a · exp(a(r − σ²/2)T − (r − a²σ²/2)T)` + = `S_0^a · exp((a−1)rT + a(a−1)/2 σ²T)`. + +This `Š_0` is the **risk-neutral expected** value of `(S_T)^a` divided by +`e^{rT}` (a.k.a. the power-forward; see `PowerOption.powerForward_price`). + +## Why this is first-principles + +The pre-existing `PowerOption.lean` derives `E[(S_T)^a]` from the affine- +shifted standard-normal MGF (one direct integral). This file goes the next +step: it shows the *struck* payoff `max((S_T)^a − K, 0)` also has a closed +form, reducing it not by a new integral but by recognising that the +powered terminal is a standard BS terminal with adjusted spot and +volatility. The whole derivation goes via `bs_call_formula` with no +additional Gaussian work. + +## Main definitions + +* `bsPowerTerminal`: the powered terminal price `(S_T)^a` as a function of the standard-normal + sample. +* `bsPowerEffectiveSpot`: the effective spot `S₀^a · exp((a−1)rT + a(a−1)/2 · σ²T)`, the spot at + which `(S_T)^a` is a Black–Scholes terminal with volatility `aσ`. + +## Main results + +* `bsPowerTerminal_eq_bsTerminal_effective`: the structural reduction + identity. +* `bsCallHyp_powered`: lift of `BSCallHyp` to the effective-spot / + effective-volatility setup. +* `bs_power_call_formula`: the closed-form discounted price. + +## Tags + +powered call option, power option, effective spot, effective volatility, lognormal terminal, +Black–Scholes, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- **Powered terminal asset price**: `(S_T)^a` viewed as a function of the +standard-normal sample. -/ +noncomputable def bsPowerTerminal (S_0 r σ T : ℝ) (a : ℕ) (z : ℝ) : ℝ := + (bsTerminal S_0 r σ T z) ^ a + +/-- **Effective spot** for the power-call reduction: +`Š_0 = S_0^a · exp((a−1)rT + a(a−1)/2 σ²T)`. -/ +noncomputable def bsPowerEffectiveSpot (S_0 r σ T : ℝ) (a : ℕ) : ℝ := + S_0 ^ a * + Real.exp (((a : ℝ) - 1) * r * T + (a : ℝ) * ((a : ℝ) - 1) / 2 * σ ^ 2 * T) + +/-- **Structural reduction identity**: the powered terminal `(S_T)^a` *is* a +standard BS terminal, with effective spot `bsPowerEffectiveSpot` and +effective volatility `aσ`. This is the algebraic core that lets us reduce +power-option pricing to `bs_call_formula`. -/ +theorem bsPowerTerminal_eq_bsTerminal_effective + (S_0 r σ T : ℝ) (a : ℕ) (z : ℝ) : + bsPowerTerminal S_0 r σ T a z = + bsTerminal (bsPowerEffectiveSpot S_0 r σ T a) r ((a : ℝ) * σ) T z := by + unfold bsPowerTerminal bsTerminal bsPowerEffectiveSpot + rw [mul_pow, ← Real.exp_nat_mul] + rw [mul_assoc (S_0 ^ a), ← Real.exp_add] + congr 1 + congr 1 + ring + +/-- **`bsCallHyp` lifts to the powered setup**: if the standard BS hypothesis +holds for `(S_0, K, r, σ, T, Z)`, then it also holds for the effective-spot +and effective-volatility tuple `(Š_0, K', r, aσ, T, Z)` for any positive +strike `K'` and any positive exponent `a`. -/ +theorem bsCallHyp_powered {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} {K' : ℝ} + (a : ℕ) (ha : 0 < a) (hK' : 0 < K') + (h : BSCallHyp Q S_0 K r σ T Z) : + BSCallHyp Q (bsPowerEffectiveSpot S_0 r σ T a) K' r ((a : ℝ) * σ) T Z := by + obtain ⟨hS_0, _hK, hσ, hT, hZ⟩ := h + refine ⟨?_, hK', ?_, hT, hZ⟩ + · unfold bsPowerEffectiveSpot + exact mul_pos (pow_pos hS_0 a) (Real.exp_pos _) + · have ha_pos : (0 : ℝ) < (a : ℝ) := by exact_mod_cast ha + exact mul_pos ha_pos hσ + +/-- **Black-Scholes powered call pricing formula** (first-principles). +For the powered payoff `max((S_T)^a − K, 0)` under `BSCallHyp`, the discounted +risk-neutral expectation equals the standard BS call price evaluated at the +effective spot `Š_0` and effective volatility `aσ`: + + `e^{−rT} · E_Q[max((S_T)^a − K, 0)] + = Š_0 · Φ(d_tilde_1) − K · e^{−rT} · Φ(d_tilde_2)`, + +where `(d_tilde_1, d_tilde_2)` are `(bsd1, bsd2)` at `(Š_0, K, r, aσ, T)`. + +Proof: rewrite the integrand via `bsPowerTerminal_eq_bsTerminal_effective` +and apply `bs_call_formula` to the lifted hypothesis. -/ +theorem bs_power_call_formula + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (a : ℕ) (ha : 0 < a) (hK : 0 < K) + (h : BSCallHyp Q S_0 K r σ T Z) : + ∫ ω, Real.exp (-r * T) * + max (bsPowerTerminal S_0 r σ T a (Z ω) - K) 0 ∂Q = + bsPowerEffectiveSpot S_0 r σ T a * + Phi (bsd1 (bsPowerEffectiveSpot S_0 r σ T a) K r ((a : ℝ) * σ) T) - + K * Real.exp (-r * T) * + Phi (bsd2 (bsPowerEffectiveSpot S_0 r σ T a) K r ((a : ℝ) * σ) T) := by + have h' : + BSCallHyp Q (bsPowerEffectiveSpot S_0 r σ T a) K r ((a : ℝ) * σ) T Z := + bsCallHyp_powered a ha hK h + have h_int : + (fun ω ↦ Real.exp (-r * T) * + max (bsPowerTerminal S_0 r σ T a (Z ω) - K) 0) = + (fun ω ↦ Real.exp (-r * T) * + max (bsTerminal (bsPowerEffectiveSpot S_0 r σ T a) r + ((a : ℝ) * σ) T (Z ω) - K) 0) := by + funext ω + rw [bsPowerTerminal_eq_bsTerminal_effective] + rw [h_int] + exact bs_call_formula h' + +/-- **Specialisation `a = 1` recovers the standard BS call price** at the +level of effective spot: `Š_0 = S_0` when `a = 1`. -/ +lemma bsPowerEffectiveSpot_one (S_0 r σ T : ℝ) : + bsPowerEffectiveSpot S_0 r σ T 1 = S_0 := by + unfold bsPowerEffectiveSpot + have h_arg : + (((1 : ℕ) : ℝ) - 1) * r * T + + ((1 : ℕ) : ℝ) * (((1 : ℕ) : ℝ) - 1) / 2 * σ ^ 2 * T = 0 := by + push_cast; ring + rw [h_arg, Real.exp_zero, pow_one, mul_one] + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/PowerOption.lean b/LeanPool/MathFin/Models/BlackScholes/PowerOption.lean new file mode 100644 index 0000000000..b153f390fc --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/PowerOption.lean @@ -0,0 +1,76 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Call +public import LeanPool.MathFin.Models.BlackScholes.Forward + +/-! +# Power options under the BS lognormal hypothesis + +The `n`-th moment of `S_T` under `BSCallHyp` is + + `E_Q[S_T^n] = S_0^n · exp(n · r · T + n(n−1)/2 · σ²T)`, + +and its discounted form is the *power-forward price* + + `e^{−rT} · E_Q[S_T^n] = S_0^n · exp((n−1) · r · T + n(n−1)/2 · σ²T)`. + +Both are direct instances of the **affine-shifted standard-normal MGF** +`∫ exp(α + β · z) · pdf(0, 1, z) dz = exp(α + β²/2)` (proved in +`StandardGaussianMGF.lean`), with `α = n · (r − σ²/2) · T` and `β = n · σ · √T`. +The identity `α + β²/2 = n · r · T + n(n−1)/2 · σ²T` is the algebraic core; the +rest is the standard HasLaw transfer from `Z` to `gaussianReal 0 1`. + +The moment itself, `nthMoment_terminal`, lives in `Models/BlackScholes/Forward.lean` (its `n = 1` +case is the forward price); this file discounts it. + +## Main results + +* `powerForward_price`: discounted power-forward price. + +## References + +* [Heynen and Kat (1996)][HeynenKat1996] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 26.10 + +## Tags + +power option, power forward, lognormal moment, moment generating function, Gaussian MGF, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal + +/-- **Power-forward price**: discounted `n`-th moment equals +`S_0^n · exp((n−1) · r · T + n(n−1)/2 · σ²T)`. Specialises to: +* `n = 0`: `e^{−rT}` (a unit-payoff at maturity is a zero-coupon bond). +* `n = 1`: `S_0` (discounted spot is a martingale: `e^{−rT} · E[S_T] = S_0`). +* `n = 2`: `S_0² · exp(rT + σ²T)` (the variance-relevant moment after + subtracting the squared forward). -/ +theorem powerForward_price + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} (n : ℕ) + (h : BSCallHyp Q S_0 K r σ T Z) : + Real.exp (-(r * T)) * + (∫ ω, (bsTerminal S_0 r σ T (Z ω))^n ∂Q) = + S_0^n * + Real.exp (((n : ℝ) - 1) * r * T + + (n : ℝ) * ((n : ℝ) - 1) / 2 * σ^2 * T) := by + rw [nthMoment_terminal n h, ← mul_assoc, mul_comm (Real.exp _) (S_0^n), + mul_assoc, ← Real.exp_add] + congr 2 + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/PricingFromBrownian.lean b/LeanPool/MathFin/Models/BlackScholes/PricingFromBrownian.lean new file mode 100644 index 0000000000..dedb92a4df --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/PricingFromBrownian.lean @@ -0,0 +1,234 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.BSCallHypFromBrownian +public import LeanPool.MathFin.Models.BlackScholes.Put +public import LeanPool.MathFin.Models.BlackScholes.Digital +public import LeanPool.MathFin.Models.BlackScholes.PowerCall +public import LeanPool.MathFin.Models.BlackScholes.StockNumeraire +public import LeanPool.MathFin.Models.BlackScholes.Dividends +public import LeanPool.MathFin.Models.BlackScholes.DividendsGreeks +public import LeanPool.MathFin.Models.Credit.KMVMertonStructural + +/-! +# Pricing entry points from a pre-Brownian motion (phase 31) + +This file restates the Black–Scholes-family pricing formulas that are stated under the +marginal hypothesis `BSCallHyp` or `BachelierHyp` (call, put, put-call parity, the +Bachelier call, digitals, the power call, the call and put with a dividend yield, the +stock-numeraire exercise probability, KMV–Merton) with that hypothesis discharged by a +pre-Brownian motion `W : ℝ≥0 → Ω → ℝ` (`IsPreBrownianReal W Q` from the `BrownianMotion` +package). + +Each corollary composes an existing pricing formula with `BSCallHyp.of_isPreBrownian` (or +`BachelierHyp.of_isPreBrownian`): the scaled `Z := W T.toNNReal / √T` discharges the +marginal-Gaussian hypothesis. All but the dividend put are term-mode one-liners; the dividend +put also folds the discount `e^{−rT} = e^{−qT}·e^{−(r−q)T}` into the closed form `bsPDiv`. + +## Why this matters + +The pricing theorems take the marginal `Z ~ N(0, 1)` as a hypothesis. The scaling lemma +(`scaled_isPreBrownian_eval_law`) shows that this marginal comes from any pre-Brownian motion, +so each formula listed above holds for the terminal value of an actual Brownian model. Only +the time-`T` marginal is used: nothing here concerns the price process before `T`. + +## Main results + +* `bs_call_formula_via_brownian`: BS call price formula from BM. +* `bs_put_formula_via_brownian`: BS put price formula from BM. +* `bs_put_call_parity_via_brownian`: put-call parity from BM. +* `bachelier_call_formula_via_brownian`: Bachelier call price formula from BM. +* `bs_dividends_put_formula_via_brownian`: the Black–Scholes–Merton put with a continuous + dividend yield `q`, as the closed form `bsPDiv`, from BM. Consumed by + `Models/BlackScholes/American/AmericanPutEuropeanBound`, which bounds the American put value below + by it. + +## Tags + +Black–Scholes formula, Bachelier model, put–call parity, dividend yield, Brownian motion, +digital option, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal + +/-- **BS call pricing formula from a pre-Brownian motion**. Given a pre- +Brownian process `W` under `Q`, the BS call price formula + + `e^{−rT} · E[max(S_T − K, 0)] = S_0 · Φ(d_1) − K · e^{−rT} · Φ(d_2)` + +holds for `S_T := bsTerminal S_0 r σ T (W T.toNNReal · / √T)`. -/ +theorem bs_call_formula_via_brownian + {Ω : Type*} {mΩ : MeasurableSpace Ω} + (Q : Measure Ω) [IsProbabilityMeasure Q] + (W : ℝ≥0 → Ω → ℝ) (hW : IsPreBrownianReal W Q) + {S_0 K r σ T : ℝ} + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + ∫ ω, Real.exp (-r * T) * + max (bsTerminal S_0 r σ T (W T.toNNReal ω / Real.sqrt T) - K) 0 ∂Q + = S_0 * Phi (bsd1 S_0 K r σ T) - + K * Real.exp (-r * T) * Phi (bsd2 S_0 K r σ T) := + bs_call_formula (BSCallHyp.of_isPreBrownian Q W hW hS_0 hK hσ hT) + +/-- **BS put pricing formula from a pre-Brownian motion**. -/ +theorem bs_put_formula_via_brownian + {Ω : Type*} {mΩ : MeasurableSpace Ω} + (Q : Measure Ω) [IsProbabilityMeasure Q] + (W : ℝ≥0 → Ω → ℝ) (hW : IsPreBrownianReal W Q) + {S_0 K r σ T : ℝ} + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + ∫ ω, Real.exp (-r * T) * + max (K - bsTerminal S_0 r σ T (W T.toNNReal ω / Real.sqrt T)) 0 ∂Q + = K * Real.exp (-r * T) * Phi (-(bsd2 S_0 K r σ T)) - + S_0 * Phi (-(bsd1 S_0 K r σ T)) := + bs_put_formula (BSCallHyp.of_isPreBrownian Q W hW hS_0 hK hσ hT) + +/-- **Put-call parity from a pre-Brownian motion**. -/ +theorem bs_put_call_parity_via_brownian + {Ω : Type*} {mΩ : MeasurableSpace Ω} + (Q : Measure Ω) [IsProbabilityMeasure Q] + (W : ℝ≥0 → Ω → ℝ) (hW : IsPreBrownianReal W Q) + {S_0 K r σ T : ℝ} + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + (∫ ω, Real.exp (-r * T) * + max (bsTerminal S_0 r σ T (W T.toNNReal ω / Real.sqrt T) - K) 0 ∂Q) + - (∫ ω, Real.exp (-r * T) * + max (K - bsTerminal S_0 r σ T (W T.toNNReal ω / Real.sqrt T)) 0 ∂Q) + = S_0 - K * Real.exp (-r * T) := + bs_put_call_parity (BSCallHyp.of_isPreBrownian Q W hW hS_0 hK hσ hT) + +/-- **Bachelier call pricing formula from a pre-Brownian motion**. -/ +theorem bachelier_call_formula_via_brownian + {Ω : Type*} {mΩ : MeasurableSpace Ω} + (Q : Measure Ω) [IsProbabilityMeasure Q] + (W : ℝ≥0 → Ω → ℝ) (hW : IsPreBrownianReal W Q) + {S_0 K σ T : ℝ} + (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + ∫ ω, max (bachelierTerminal S_0 σ T + (W T.toNNReal ω / Real.sqrt T) - K) 0 ∂Q + = (S_0 - K) * Phi (bachelierD S_0 K σ T) + + σ * Real.sqrt T * + gaussianPDFReal 0 1 (bachelierD S_0 K σ T) := + bachelier_call_formula (BachelierHyp.of_isPreBrownian Q W hW hK hσ hT) + +/-- **Cash-or-nothing digital from a pre-Brownian motion**. -/ +theorem bs_cash_or_nothing_formula_via_brownian + {Ω : Type*} {mΩ : MeasurableSpace Ω} + (Q : Measure Ω) [IsProbabilityMeasure Q] + (W : ℝ≥0 → Ω → ℝ) (hW : IsPreBrownianReal W Q) + {S_0 K r σ T : ℝ} + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + ∫ ω, Real.exp (-r * T) * + (Set.Ioi K).indicator (fun _ ↦ (1 : ℝ)) + (bsTerminal S_0 r σ T (W T.toNNReal ω / Real.sqrt T)) ∂Q + = Real.exp (-r * T) * Phi (bsd2 S_0 K r σ T) := + bs_cash_or_nothing_formula (BSCallHyp.of_isPreBrownian Q W hW hS_0 hK hσ hT) + +/-- **Asset-or-nothing digital from a pre-Brownian motion**. -/ +theorem bs_asset_or_nothing_formula_via_brownian + {Ω : Type*} {mΩ : MeasurableSpace Ω} + (Q : Measure Ω) [IsProbabilityMeasure Q] + (W : ℝ≥0 → Ω → ℝ) (hW : IsPreBrownianReal W Q) + {S_0 K r σ T : ℝ} + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + ∫ ω, Real.exp (-r * T) * + (Set.Ioi K).indicator (fun s ↦ s) + (bsTerminal S_0 r σ T (W T.toNNReal ω / Real.sqrt T)) ∂Q + = S_0 * Phi (bsd1 S_0 K r σ T) := + bs_asset_or_nothing_formula (BSCallHyp.of_isPreBrownian Q W hW hS_0 hK hσ hT) + +/-- **Powered call from a pre-Brownian motion**. -/ +theorem bs_power_call_formula_via_brownian + {Ω : Type*} {mΩ : MeasurableSpace Ω} + (Q : Measure Ω) [IsProbabilityMeasure Q] + (W : ℝ≥0 → Ω → ℝ) (hW : IsPreBrownianReal W Q) + {S_0 K r σ T : ℝ} (a : ℕ) (ha : 0 < a) + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + ∫ ω, Real.exp (-r * T) * + max (bsPowerTerminal S_0 r σ T a + (W T.toNNReal ω / Real.sqrt T) - K) 0 ∂Q = + bsPowerEffectiveSpot S_0 r σ T a * + Phi (bsd1 (bsPowerEffectiveSpot S_0 r σ T a) K r ((a : ℝ) * σ) T) - + K * Real.exp (-r * T) * + Phi (bsd2 (bsPowerEffectiveSpot S_0 r σ T a) K r ((a : ℝ) * σ) T) := + bs_power_call_formula a ha hK (BSCallHyp.of_isPreBrownian Q W hW hS_0 hK hσ hT) + +/-- **BS-with-dividends call from a pre-Brownian motion**. The drift used +in the marginal hypothesis is `r − q`. -/ +theorem bs_dividends_call_formula_via_brownian + {Ω : Type*} {mΩ : MeasurableSpace Ω} + (Q : Measure Ω) [IsProbabilityMeasure Q] + (W : ℝ≥0 → Ω → ℝ) (hW : IsPreBrownianReal W Q) + {S_0 K r q σ T : ℝ} + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + ∫ ω, Real.exp (-r * T) * + max (bsTerminal S_0 (r - q) σ T + (W T.toNNReal ω / Real.sqrt T) - K) 0 ∂Q + = S_0 * Real.exp (-(q * T)) * Phi (bsd1 S_0 K (r - q) σ T) + - K * Real.exp (-(r * T)) * Phi (bsd2 S_0 K (r - q) σ T) := + bs_dividends_call_formula + (BSCallHyp.of_isPreBrownian (r := r - q) Q W hW hS_0 hK hσ hT) + +/-- **Black–Scholes–Merton put with a continuous dividend yield, from a pre-Brownian +motion.** With the stock drifting at `r − q` under `Q` and discounting at `r`, the discounted +expected put payoff is the closed form + + `bsPDiv K r q σ S_0 T = e^{−qT}·(K·e^{−(r−q)T}·Φ(−d₂) − S_0·Φ(−d₁))`, + +`d₁, d₂` taken at rate `r − q`. It is `bs_put_formula` at rate `r − q`, multiplied by +`e^{−qT}`: `e^{−rT} = e^{−qT}·e^{−(r−q)T}`. -/ +theorem bs_dividends_put_formula_via_brownian + {Ω : Type*} {mΩ : MeasurableSpace Ω} + (Q : Measure Ω) [IsProbabilityMeasure Q] + (W : ℝ≥0 → Ω → ℝ) (hW : IsPreBrownianReal W Q) + {S_0 K r q σ T : ℝ} + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + ∫ ω, Real.exp (-r * T) * + max (K - bsTerminal S_0 (r - q) σ T (W T.toNNReal ω / Real.sqrt T)) 0 ∂Q + = bsPDiv K r q σ S_0 T := by + rw [bsPDiv, bsP, ← neg_mul (r - q), + ← bs_put_formula (BSCallHyp.of_isPreBrownian (r := r - q) Q W hW hS_0 hK hσ hT), + ← integral_const_mul] + refine integral_congr_ae (ae_of_all _ fun ω ↦ ?_) + simp only [← mul_assoc, ← Real.exp_add] + congr 2 + ring + +/-- **Stock-numeraire exercise probability from a pre-Brownian motion**. -/ +theorem stockNumeraire_exercise_probability_via_brownian + {Ω : Type*} {mΩ : MeasurableSpace Ω} + (Q : Measure Ω) [IsProbabilityMeasure Q] + (W : ℝ≥0 → Ω → ℝ) (hW : IsPreBrownianReal W Q) + {S_0 K r σ T : ℝ} + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + (∫ ω, (Set.Ioi (-bsd2 S_0 K r σ T)).indicator + (fun z ↦ Real.exp (-r * T) * bsTerminal S_0 r σ T z / S_0) + (W T.toNNReal ω / Real.sqrt T) ∂Q) = + Phi (bsd1 S_0 K r σ T) := + stockNumeraire_exercise_probability + (BSCallHyp.of_isPreBrownian Q W hW hS_0 hK hσ hT) + +/-- **KMV-Merton default probability from a pre-Brownian motion**. -/ +theorem kmvPD_eq_one_sub_survival_probability_via_brownian + {Ω : Type*} {mΩ : MeasurableSpace Ω} + (Q : Measure Ω) [IsProbabilityMeasure Q] + (W : ℝ≥0 → Ω → ℝ) (hW : IsPreBrownianReal W Q) + {V_0 F r σ_V T : ℝ} + (hV : 0 < V_0) (hF : 0 < F) (hσ : 0 < σ_V) (hT : 0 < T) : + kmvPD V_0 F r σ_V T = + 1 - (Q {ω | bsTerminal V_0 r σ_V T + (W T.toNNReal ω / Real.sqrt T) > F}).toReal := + kmvPD_eq_one_sub_survival_probability hV hF + (BSCallHyp.of_isPreBrownian Q W hW hV hF hσ hT) + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/Put.lean b/LeanPool/MathFin/Models/BlackScholes/Put.lean new file mode 100644 index 0000000000..11abd7c7e1 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/Put.lean @@ -0,0 +1,221 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Call + +/-! +# Black–Scholes put pricing formula + +Derivation of the European put price under the risk-neutral lognormal +hypothesis: + + P(S_0, K, r, σ, T) = K · e^{-rT} · Φ(-d_2) − S_0 · Φ(-d_1) + +Built directly, parallel to `bs_call_formula`: HasLaw transfer to standard +normal, `max(K - S_T, 0)` as indicator on `{S_T < K} = Iic(-d_2)`, then +completing-the-square on the left-tail integral. + +We also derive **put-call parity** +`C − P = S_0 − K · e^{-rT}` as a corollary using the call formula and +`Phi_add_Phi_neg`. + +## Main results + +* `bs_put_formula`: under `BSCallHyp`, the discounted expected put payoff is + `K·e^{−rT}·Φ(−d₂) − S₀·Φ(−d₁)`. +* `bs_put_call_parity`: under `BSCallHyp`, `C − P = S₀ − K·e^{−rT}`. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 11.4; 16.6 +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], 4.5 + +## Tags + +European put, put–call parity, Black–Scholes put price, risk-neutral pricing, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal + +/-! ### Left-tail completing-the-square (Iic counterpart of `_Ioi` lemma) -/ + +/-- `Q(Iic a) = Φ(a)` for standard normal. Just `Phi_def` unfolded. -/ +lemma gaussianReal_Iic_toReal (a : ℝ) : + (gaussianReal 0 1 (Set.Iic a)).toReal = Phi a := rfl + +/-- The shifted Gaussian left-tail integral — the put-side BS computational +primitive: + `∫ z in Iic a, exp(c·z) · gaussianPDFReal 0 1 z dz = exp(c²/2) · Φ(a − c)`. + +Combines `exp_mul_gaussianPDFReal_zero_one` with `gaussianReal_map_add_const`. -/ +lemma integral_exp_mul_gaussianPDFReal_Iic (a c : ℝ) : + ∫ z in Set.Iic a, Real.exp (c * z) * gaussianPDFReal 0 1 z + = Real.exp (c^2 / 2) * Phi (a - c) := by + rw [setIntegral_congr_fun measurableSet_Iic + (fun z _ ↦ exp_mul_gaussianPDFReal_zero_one c z), integral_const_mul] + congr 1 + have h_int_eq : ∫ z in Set.Iic a, gaussianPDFReal c 1 z + = (gaussianReal c (1 : ℝ≥0) (Set.Iic a)).toReal := + setIntegral_gaussianPDFReal_eq_toReal measurableSet_Iic c + have h_shift : gaussianReal c (1 : ℝ≥0) (Set.Iic a) = + gaussianReal 0 1 (Set.Iic (a - c)) := by + have hmap : (gaussianReal (0 : ℝ) 1).map (fun y ↦ y + c) = gaussianReal c 1 := by + rw [gaussianReal_map_add_const, zero_add] + rw [← hmap, Measure.map_apply (by fun_prop) measurableSet_Iic] + congr 1; ext y; simp [Set.mem_Iic, le_sub_iff_add_le, add_comm] + rw [h_int_eq, h_shift]; rfl + +/-! ### Put payoff as an indicator -/ + +/-- `max(K − S_T(z), 0)` as an indicator on the exercise region `Iic(-d_2)`. -/ +private lemma max_put_payoff_eq_indicator {S_0 K r σ T : ℝ} + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (z : ℝ) : + max (K - bsTerminal S_0 r σ T z) 0 = + (Set.Iic (-bsd2 S_0 K r σ T)).indicator + (fun z' ↦ K - bsTerminal S_0 r σ T z') z := by + by_cases h : z ∈ Set.Iic (-bsd2 S_0 K r σ T) + · rw [Set.indicator_of_mem h] + have hz_le : z ≤ -bsd2 S_0 K r σ T := h + have hST_le : bsTerminal S_0 r σ T z ≤ K := by + by_contra hcontra + have h_gt : z > -bsd2 S_0 K r σ T := + (bsTerminal_gt_K_iff hS_0 hK hσ hT z).mp (not_le.mp hcontra) + linarith + exact max_eq_left (sub_nonneg.mpr hST_le) + · rw [Set.indicator_of_notMem h] + have hz_gt : -bsd2 S_0 K r σ T < z := not_le.mp h + have hST_gt : bsTerminal S_0 r σ T z > K := + (bsTerminal_gt_K_iff hS_0 hK hσ hT z).mpr hz_gt + exact max_eq_right (sub_nonpos.mpr hST_gt.le) + +/-! ### Put pricing formula -/ + +/-- **Black-Scholes European put pricing formula.** + +For an asset whose risk-neutral log-return is Gaussian (encoded by `BSCallHyp`), +the discounted expected payoff of the European put `max(K - S_T, 0)` equals +`K · e^{-rT} · Φ(-d_2) − S_0 · Φ(-d_1)`. + +Real derivation: HasLaw transfer + `max → indicator` on the exercise region +`{S_T(z) < K} = Iic(-d_2)` + `integral_exp_mul_gaussianPDFReal_Iic` on the +asset-side piece + `gaussianReal_Iic_toReal` on the strike-side piece + the +BS martingale algebra `(r - σ²/2)T + σ²T/2 = rT`. The identification +`-d_2 - σ√T = -d_1` (using `d_1 - d_2 = σ√T`) finishes the asset piece. -/ +theorem bs_put_formula {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + ∫ ω, Real.exp (-r * T) * max (K - bsTerminal S_0 r σ T (Z ω)) 0 ∂Q + = K * Real.exp (-r * T) * Phi (-(bsd2 S_0 K r σ T)) - + S_0 * Phi (-(bsd1 S_0 K r σ T)) := by + obtain ⟨hS_0, hK, hσ, hT, hZ⟩ := h + set d_1 : ℝ := bsd1 S_0 K r σ T with d_1_def + set d_2 : ℝ := bsd2 S_0 K r σ T with d_2_def + set μ_log : ℝ := (r - σ^2 / 2) * T + set ν_log : ℝ := σ * Real.sqrt T with ν_log_def + have hsqrT_pos : 0 < Real.sqrt T := Real.sqrt_pos.mpr hT + have hν_log_pos : 0 < ν_log := mul_pos hσ hsqrT_pos + have hν_log_sq : ν_log^2 = σ^2 * T := by + rw [ν_log_def, mul_pow, Real.sq_sqrt hT.le] + have h_algebra : μ_log + ν_log^2 / 2 = r * T := by rw [hν_log_sq]; ring + -- Key identity: -d_2 - ν_log = -d_1 + have h_shift_eq : (-d_2) - ν_log = -d_1 := by + rw [d_1_def, d_2_def, bsd2]; ring + have h_payoff_meas : Measurable fun z : ℝ ↦ max (K - bsTerminal S_0 r σ T z) 0 := by + unfold bsTerminal; fun_prop + -- Step 1-3: pull out e^{-rT}, HasLaw transfer, convert to volume with pdf + rw [integral_const_mul] + rw [show (fun ω ↦ max (K - bsTerminal S_0 r σ T (Z ω)) 0) + = (fun z ↦ max (K - bsTerminal S_0 r σ T z) 0) ∘ Z from rfl, + hZ.integral_comp h_payoff_meas.aestronglyMeasurable, + integral_gaussianReal_eq_integral_smul (one_ne_zero : (1 : ℝ≥0) ≠ 0)] + -- Step 4: max → indicator on Iic(-d_2) + rw [show (fun z : ℝ ↦ gaussianPDFReal 0 1 z • max (K - bsTerminal S_0 r σ T z) 0) + = (Set.Iic (-d_2)).indicator + (fun z ↦ gaussianPDFReal 0 1 z * (K - bsTerminal S_0 r σ T z)) from + funext (fun z ↦ by + rw [smul_eq_mul, max_put_payoff_eq_indicator hS_0 hK hσ hT z] + by_cases hz : z ∈ Set.Iic (-d_2) + · rw [Set.indicator_of_mem hz, Set.indicator_of_mem hz] + · rw [Set.indicator_of_notMem hz, Set.indicator_of_notMem hz, mul_zero])] + rw [integral_indicator measurableSet_Iic] + -- Step 5: rewrite pdf · (K - S_T) as a linear combination + have h_split_integrand : ∀ z : ℝ, + gaussianPDFReal 0 1 z * (K - bsTerminal S_0 r σ T z) + = K * gaussianPDFReal 0 1 z + - (S_0 * Real.exp μ_log) * (Real.exp (ν_log * z) * gaussianPDFReal 0 1 z) := by + intro z + unfold bsTerminal + have h_exp : Real.exp ((r - σ^2 / 2) * T + σ * Real.sqrt T * z) + = Real.exp μ_log * Real.exp (ν_log * z) := by + change Real.exp ((r - σ^2 / 2) * T + σ * Real.sqrt T * z) + = Real.exp ((r - σ^2 / 2) * T) * Real.exp (σ * Real.sqrt T * z) + exact Real.exp_add _ _ + rw [h_exp]; ring + rw [setIntegral_congr_fun measurableSet_Iic (fun z _ ↦ h_split_integrand z)] + -- Step 6: integrability of each piece on Iic(-d_2) + have h_int_pdf_Iic : IntegrableOn (gaussianPDFReal 0 1) (Set.Iic (-d_2)) volume := + (integrable_gaussianPDFReal 0 1).integrableOn + have h_int_asset : IntegrableOn + (fun z : ℝ ↦ Real.exp (ν_log * z) * gaussianPDFReal 0 1 z) + (Set.Iic (-d_2)) volume := by + refine ((integrable_gaussianPDFReal ν_log 1).const_mul + (Real.exp (ν_log^2 / 2))).integrableOn.congr_fun ?_ measurableSet_Iic + intro z _ + exact (exp_mul_gaussianPDFReal_zero_one ν_log z).symm + -- Step 7: split integral + rw [integral_sub (h_int_pdf_Iic.const_mul _) (h_int_asset.const_mul _)] + rw [integral_const_mul, integral_const_mul] + -- Step 8: apply primitives + have h_pdf_int_eq : + ∫ z in Set.Iic (-d_2), gaussianPDFReal 0 1 z = Phi (-d_2) := by + rw [setIntegral_gaussianPDFReal_eq_toReal measurableSet_Iic (0 : ℝ), + gaussianReal_Iic_toReal] + rw [h_pdf_int_eq, integral_exp_mul_gaussianPDFReal_Iic, h_shift_eq] + -- Step 9: final algebra + have h_exp_combine : Real.exp (-r * T) * Real.exp μ_log * Real.exp (ν_log^2 / 2) = 1 := by + rw [mul_assoc, ← Real.exp_add, ← Real.exp_add, + show -r * T + (μ_log + ν_log^2 / 2) = 0 from by rw [h_algebra]; ring] + exact Real.exp_zero + calc Real.exp (-r * T) * + (K * Phi (-d_2) - S_0 * Real.exp μ_log * (Real.exp (ν_log^2 / 2) * Phi (-d_1))) + = K * Real.exp (-r * T) * Phi (-d_2) - + (Real.exp (-r * T) * Real.exp μ_log * Real.exp (ν_log^2 / 2)) * (S_0 * Phi (-d_1)) := by + ring + _ = K * Real.exp (-r * T) * Phi (-d_2) - 1 * (S_0 * Phi (-d_1)) := by rw [h_exp_combine] + _ = K * Real.exp (-r * T) * Phi (-d_2) - S_0 * Phi (-d_1) := by rw [one_mul] + +/-! ### Put-call parity -/ + +/-- **Put-call parity** for the BS European call and put under the +risk-neutral lognormal hypothesis: + `C − P = S_0 − K · e^{-rT}`. + +A direct algebraic corollary of `bs_call_formula` + `bs_put_formula` + the +symmetry identity `Φ(x) + Φ(-x) = 1`. -/ +theorem bs_put_call_parity {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + (∫ ω, Real.exp (-r * T) * max (bsTerminal S_0 r σ T (Z ω) - K) 0 ∂Q) + - (∫ ω, Real.exp (-r * T) * max (K - bsTerminal S_0 r σ T (Z ω)) 0 ∂Q) + = S_0 - K * Real.exp (-r * T) := by + rw [bs_call_formula h, bs_put_formula h] + have h_d1 := Phi_add_Phi_neg (bsd1 S_0 K r σ T) + have h_d2 := Phi_add_Phi_neg (bsd2 S_0 K r σ T) + -- Phi(d_1) + Phi(-d_1) = 1, Phi(d_2) + Phi(-d_2) = 1. + -- C - P = S_0 (Phi(d_1) + Phi(-d_1)) - K e^{-rT} (Phi(d_2) + Phi(-d_2)) = S_0 - K e^{-rT} + linear_combination S_0 * h_d1 - K * Real.exp (-r * T) * h_d2 + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/PutGreeks.lean b/LeanPool/MathFin/Models/BlackScholes/PutGreeks.lean new file mode 100644 index 0000000000..096b1db9ae --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/PutGreeks.lean @@ -0,0 +1,172 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.PDE + +/-! +# Black–Scholes put Greeks + +For the European put price `P(S, τ) = K · e^{-rτ} · Φ(-d₂) − S · Φ(-d₁)`, we +derive the five standard Greeks. The strategy is **put-call parity**: + + `P = V − S + K · e^{-rτ}` + +(where `V` is the call price `bsV`). Each Greek is then a one-step Mathlib +derivative combinator applied to the corresponding call Greek + simple +constant/identity derivatives + put-call symmetry `Φ(d) + Φ(-d) = 1`. + +## Main definitions + +* `bsP`: the Black–Scholes European put price as a function of the spot `S` and the time to + maturity `τ`, `K · e^{−rτ} · Φ(−d₂) − S · Φ(−d₁)`. + +## Main results + +* `bsP_eq_bsV` — put-call parity for the price functions. +* `hasDerivAt_bsP_S` — δ_P = Φ(d₁) − 1. +* `hasDerivAt_deriv_bsP_S` — γ_P = ϕ(d₁) / (S σ √τ) (same as call gamma), from the + formula-level `hasDerivAt_bsP_SS`. +* `hasDerivAt_bsP_tau` — θ_P in `τ`-form. +* `hasDerivAt_bsP_sigma` — vega_P = S ϕ(d₁) √τ (same as call vega). +* `hasDerivAt_bsP_r` — ρ_P = -K τ e^{-rτ} Φ(-d₂). + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 19.4; 19.6; 19.7 + +## Tags + +put delta, put gamma, put theta, put vega, put rho, option sensitivities, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- Black–Scholes European put price as a function of `(S, τ)`. -/ +noncomputable def bsP (K r σ : ℝ) (S τ : ℝ) : ℝ := + K * Real.exp (-(r * τ)) * Phi (-bsd2 S K r σ τ) - S * Phi (-bsd1 S K r σ τ) + +/-- **Put-call parity** (price form): `bsP = bsV − S + K · e^{-rτ}`. -/ +@[pricing =] +lemma bsP_eq_bsV (K r σ S τ : ℝ) : + bsP K r σ S τ = bsV K r σ S τ - S + K * Real.exp (-(r * τ)) := by + unfold bsP bsV + have h_d1 := Phi_add_Phi_neg (bsd1 S K r σ τ) + have h_d2 := Phi_add_Phi_neg (bsd2 S K r σ τ) + linear_combination -S * h_d1 + K * Real.exp (-(r * τ)) * h_d2 + +/-- **Put delta**: `∂_S P = Φ(d₁) − 1`. -/ +lemma hasDerivAt_bsP_S {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ bsP K r σ s τ) (Phi (bsd1 S K r σ τ) - 1) S := by + have h_eq : (fun s : ℝ ↦ bsP K r σ s τ) + = fun s ↦ bsV K r σ s τ - s + K * Real.exp (-(r * τ)) := by + funext s; exact bsP_eq_bsV K r σ s τ + rw [h_eq] + have h_V := hasDerivAt_bsV_S (r := r) hK hσ hS hτ + have h_id : HasDerivAt (fun s : ℝ ↦ s) 1 S := hasDerivAt_id S + have h_const : HasDerivAt (fun _ : ℝ ↦ K * Real.exp (-(r * τ))) 0 S := hasDerivAt_const _ _ + have h := (h_V.sub h_id).add h_const + convert h using 1 + ring + +/-- **The put gamma formula**: the S-derivative of the put delta `Φ(d₁) − 1` is +`ϕ(d₁) / (S σ √τ)` — the call's gamma formula, since the two deltas differ by a constant. +The second derivative of the put price itself is `hasDerivAt_deriv_bsP_S`. -/ +private lemma hasDerivAt_bsP_SS {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ Phi (bsd1 s K r σ τ) - 1) + (gaussianPDFReal 0 1 (bsd1 S K r σ τ) / (S * σ * Real.sqrt τ)) S := + (hasDerivAt_Phi_bsd1_S (r := r) hK hσ hS hτ).sub_const 1 + +/-- **Put gamma**: `∂²P/∂S² = ϕ(d₁) / (S σ √τ)`, for the put price itself: the put delta +`Φ(d₁) − 1` is `∂P/∂S` on all of `S > 0` (`hasDerivAt_bsP_S`), and its derivative is the gamma +formula (`hasDerivAt_bsP_SS`). -/ +theorem hasDerivAt_deriv_bsP_S {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (deriv fun s ↦ bsP K r σ s τ) + (gaussianPDFReal 0 1 (bsd1 S K r σ τ) / (S * σ * Real.sqrt τ)) S := + hasDerivAt_deriv_of_eventually + ((eventually_gt_nhds hS).mono fun _ hs ↦ hasDerivAt_bsP_S hK hσ hs hτ) + (hasDerivAt_bsP_SS hK hσ hS hτ) + +/-- **Put theta** (`∂_τ` form): `∂_τ P = σ S ϕ(d₁) / (2 √τ) − r K e^{-rτ} Φ(-d₂)`. + +Via parity: `∂_τ P = ∂_τ V + ∂_τ (K e^{-rτ}) = (call theta) − r K e^{-rτ}`. +The `Φ(d₂) → Φ(-d₂)` rearrangement uses `Φ(d₂) + Φ(-d₂) = 1`. -/ +lemma hasDerivAt_bsP_tau {K r σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + {S τ : ℝ} (hS : 0 < S) (hτ : 0 < τ) : + HasDerivAt (fun t ↦ bsP K r σ S t) + (σ * S * gaussianPDFReal 0 1 (bsd1 S K r σ τ) / (2 * Real.sqrt τ) + - r * K * Real.exp (-(r * τ)) * Phi (-bsd2 S K r σ τ)) τ := by + have h_eq : (fun t : ℝ ↦ bsP K r σ S t) + = fun t ↦ bsV K r σ S t - S + K * Real.exp (-(r * t)) := by + funext t; exact bsP_eq_bsV K r σ S t + rw [h_eq] + have h_V := hasDerivAt_bsV_tau (r := r) hK hσ hS hτ + have h_const_S : HasDerivAt (fun _ : ℝ ↦ S) 0 τ := hasDerivAt_const _ _ + have h_neg_r : HasDerivAt (fun t : ℝ ↦ -(r * t)) (-r) τ := by + have h := (hasDerivAt_id τ).const_mul r + convert h.neg using 1 <;> first | rfl | ring + have h_exp : HasDerivAt (fun t : ℝ ↦ Real.exp (-(r * t))) + (Real.exp (-(r * τ)) * -r) τ := h_neg_r.exp + have h_K_exp : HasDerivAt (fun t : ℝ ↦ K * Real.exp (-(r * t))) + (K * (Real.exp (-(r * τ)) * -r)) τ := h_exp.const_mul K + have h := (h_V.sub h_const_S).add h_K_exp + convert h using 1 + have h_phi := Phi_add_Phi_neg (bsd2 S K r σ τ) + linear_combination -(r * K * Real.exp (-(r * τ))) * h_phi + +/-- **Put vega**: `∂_σ P = S · ϕ(d₁) · √τ` — same as call vega (the `−S + K e^{-rτ}` +correction is `σ`-independent). -/ +lemma hasDerivAt_bsP_sigma {K r : ℝ} (hK : 0 < K) + {S σ τ : ℝ} (hS : 0 < S) (hσ : 0 < σ) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ bsP K r s S τ) + (S * gaussianPDFReal 0 1 (bsd1 S K r σ τ) * Real.sqrt τ) σ := by + have h_eq : (fun s : ℝ ↦ bsP K r s S τ) + = fun s ↦ bsV K r s S τ - S + K * Real.exp (-(r * τ)) := by + funext s; exact bsP_eq_bsV K r s S τ + rw [h_eq] + have h_V := hasDerivAt_bsV_sigma (r := r) hK hS hσ hτ + have h_const_S : HasDerivAt (fun _ : ℝ ↦ S) 0 σ := hasDerivAt_const _ _ + have h_const_disc : HasDerivAt (fun _ : ℝ ↦ K * Real.exp (-(r * τ))) 0 σ := hasDerivAt_const _ _ + have h := (h_V.sub h_const_S).add h_const_disc + convert h using 1 + ring + +/-- **Put rho**: `∂_r P = -K · τ · e^{-rτ} · Φ(-d₂)`. + +Via parity: `∂_r P = ∂_r V + ∂_r (K e^{-rτ}) = K τ e^{-rτ} Φ(d₂) − K τ e^{-rτ}`, +and `Φ(d₂) − 1 = -Φ(-d₂)`. -/ +lemma hasDerivAt_bsP_r {K σ τ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) + {S : ℝ} (hS : 0 < S) (r : ℝ) : + HasDerivAt (fun r' ↦ bsP K r' σ S τ) + (-(K * τ * Real.exp (-(r * τ)) * Phi (-bsd2 S K r σ τ))) r := by + have h_eq : (fun r' : ℝ ↦ bsP K r' σ S τ) + = fun r' ↦ bsV K r' σ S τ - S + K * Real.exp (-(r' * τ)) := by + funext r'; exact bsP_eq_bsV K r' σ S τ + rw [h_eq] + have h_V := hasDerivAt_bsV_r hK hσ hτ hS r + have h_const_S : HasDerivAt (fun _ : ℝ ↦ S) 0 r := hasDerivAt_const _ _ + have h_neg : HasDerivAt (fun r' : ℝ ↦ -(r' * τ)) (-τ) r := by + have h := (hasDerivAt_id r).mul_const τ + convert h.neg using 1 <;> first | rfl | ring + have h_exp : HasDerivAt (fun r' : ℝ ↦ Real.exp (-(r' * τ))) + (Real.exp (-(r * τ)) * -τ) r := h_neg.exp + have h_K_exp : HasDerivAt (fun r' : ℝ ↦ K * Real.exp (-(r' * τ))) + (K * (Real.exp (-(r * τ)) * -τ)) r := h_exp.const_mul K + have h := (h_V.sub h_const_S).add h_K_exp + convert h using 1 + have h_phi := Phi_add_Phi_neg (bsd2 S K r σ τ) + linear_combination -(K * τ * Real.exp (-(r * τ))) * h_phi + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/PutStrikeConvexity.lean b/LeanPool/MathFin/Models/BlackScholes/PutStrikeConvexity.lean new file mode 100644 index 0000000000..1a03d1f629 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/PutStrikeConvexity.lean @@ -0,0 +1,86 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.PutGreeks +public import LeanPool.MathFin.Models.BlackScholes.StrikeGreeks + +/-! +# The put price's second strike-derivative + +The put price's second `K`-derivative matches the call's: + + `∂²_K bsP = e^{-rτ} · ϕ(d₂) / (K σ √τ)`, + +since `bsP(K) − bsV(K) = K · e^{-rτ} − S` is linear in `K`. A clean expression +of put-call symmetry at the strike-convexity level. + +## Main results + +* `hasDerivAt_bsP_KK`: the K-derivative of `e^{-rτ} · Φ(−d₂)` is + `e^{-rτ} · ϕ(d₂) / (K σ √τ)` (PDF evenness `gaussianPDFReal_zero_one_neg` now lives + in `Probability.Gaussian.StandardNormal`). +* `hasDerivAt_deriv_bsP_K`: `∂²_K bsP = e^{-rτ} · ϕ(d₂) / (K σ √τ)`, for the price + itself. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], Ch 12.8 + +## Tags + +strike convexity, Breeden–Litzenberger, put price second derivative, implied density, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Real ProbabilityTheory + +/-- **The put's second strike-derivative formula**: the K-derivative of +`∂_K bsP = e^{-rτ} · Φ(−d₂)` (from `Models.BlackScholes.StrikeGreeks`) is +`e^{-rτ} · ϕ(d₂) / (K σ √τ)`, +the call's value (`hasDerivAt_deriv_bsV_K`). The second derivative of the put price itself is +`hasDerivAt_deriv_bsP_K`. -/ +private lemma hasDerivAt_bsP_KK {S r σ : ℝ} (hS : 0 < S) (hσ : 0 < σ) + {K τ : ℝ} (hK : 0 < K) (hτ : 0 < τ) : + HasDerivAt (fun k ↦ Real.exp (-(r * τ)) * Phi (-bsd2 S k r σ τ)) + (Real.exp (-(r * τ)) * + gaussianPDFReal 0 1 (bsd2 S K r σ τ) / + (K * σ * Real.sqrt τ)) K := by + have h_d2_K := hasDerivAt_bsd2_K S r σ τ hS hσ hτ hK + have h_neg_d2 := h_d2_K.neg + have h_Phi_neg_d2 := (hasDerivAt_Phi (-bsd2 S K r σ τ)).comp K h_neg_d2 + have h := h_Phi_neg_d2.const_mul (Real.exp (-(r * τ))) + have h_pdf_sym : gaussianPDFReal 0 1 (-bsd2 S K r σ τ) = + gaussianPDFReal 0 1 (bsd2 S K r σ τ) := gaussianPDFReal_zero_one_neg _ + have h_sqrt_τ_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_τ_ne : Real.sqrt τ ≠ 0 := h_sqrt_τ_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have hK_ne : K ≠ 0 := hK.ne' + have h1 := h.congr_of_eventuallyEq + (f₁ := fun k ↦ Real.exp (-(r * τ)) * Phi (-bsd2 S k r σ τ)) + (Filter.Eventually.of_forall fun x ↦ by simp only [Function.comp_def, Pi.neg_apply]) + refine h1.congr_deriv ?_ + rw [h_pdf_sym] + field_simp + +/-- **Second strike-derivative of the put**: `∂²P/∂K² = e^{-rτ} · ϕ(d₂) / (K σ √τ)`, for the +price itself: `∂_K bsP = e^{-rτ} Φ(−d₂)` on all of `K > 0` (`hasDerivAt_bsP_K`), and its +derivative is the formula of `hasDerivAt_bsP_KK`. -/ +theorem hasDerivAt_deriv_bsP_K {S r σ : ℝ} (hS : 0 < S) (hσ : 0 < σ) + {K τ : ℝ} (hK : 0 < K) (hτ : 0 < τ) : + HasDerivAt (deriv fun k ↦ bsP k r σ S τ) + (Real.exp (-(r * τ)) * gaussianPDFReal 0 1 (bsd2 S K r σ τ) / (K * σ * Real.sqrt τ)) K := + hasDerivAt_deriv_of_eventually + ((eventually_gt_nhds hK).mono fun _ hk ↦ hasDerivAt_bsP_K hS hσ hk hτ) + (hasDerivAt_bsP_KK hS hσ hK hτ) + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/QuantoGrounding.lean b/LeanPool/MathFin/Models/BlackScholes/QuantoGrounding.lean new file mode 100644 index 0000000000..3b49081022 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/QuantoGrounding.lean @@ -0,0 +1,99 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho, Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Dividends +public import LeanPool.MathFin.Probability.Brownian.BrownianMartingale + +/-! +# The quanto correction, derived from a joint-Gaussian FX model + +`Models/BlackScholes/Dividends.quantoForward` *posits* the quanto-adjusted forward +`S_hat = S₀·exp((r_dom − ρ σ_S σ_FX)·T)` — the drift adjustment `−ρ σ_S σ_FX` is baked into the +definition. This file **derives** it: under the domestic risk-neutral measure the foreign +asset's forward picks up exactly the log-covariance term `−ρ σ_S σ_FX` from the change of +measure that converts the foreign numéraire to the domestic one. + +The domestic-measure expectation is the foreign-measure expectation weighted by the FX +Radon–Nikodym density `exp(−σ_FX√T·Z_FX − ½σ_FX²T)` (a Girsanov/Esscher tilt in the FX +driver). With the standard decomposition of the correlated FX driver into the asset driver +plus an independent component, `Z_FX = ρ Z_S + √(1−ρ²) Z_⊥`, the density-weighted expectation +factors through two independent Gaussian MGFs, and the cross-term `ρ σ_S σ_FX` emerges: + + `𝔼[S_T · exp(−σ_FX√T Z_FX − ½σ_FX²T)] = S₀·exp((r_dom − ρ σ_S σ_FX)·T) = quantoForward`. + +This is the multi-asset analogue of `MargrabeGrounding` — the correction is *earned* from the +correlation, not assumed. It consumes only the standard-normal MGF and the independence +factorisation of the expectation. + +## Main results + +* `quantoForward_of_gaussian` — the density-weighted foreign expectation of the foreign + terminal equals `quantoForward`, deriving the `−ρ σ_S σ_FX` drift adjustment. + +## References + +* [Reiner (1992)][Reiner1992] + +## Tags + +quanto option, quanto adjustment, foreign exchange correlation, change of measure, drift adjustment, +MSC 91G20, JEL G13, JEL F31 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + +omit [IsProbabilityMeasure μ] in +/-- **The quanto forward, derived from a joint-Gaussian FX model.** With the foreign terminal +`S_T = S₀·exp((r_dom − σ_S²/2)T + σ_S√T·Z_S)` and the correlated FX log-driver +`Z_FX = ρ Z_S + √(1−ρ²) Z_⊥` (`Z_S`, `Z_⊥` independent `N(0,1)`), the FX-density-weighted +foreign expectation equals the quanto-adjusted forward — the `−ρ σ_S σ_FX` drift adjustment is +the log-covariance produced by the change of measure, not an assumption. -/ +theorem quantoForward_of_gaussian + (S₀ r_dom σ_S σ_FX ρ T : ℝ) (hT : 0 ≤ T) (hρ : ρ ^ 2 ≤ 1) + {Z_S Z_perp : Ω → ℝ} + (hZS : HasLaw Z_S (gaussianReal 0 1) μ) (hZperp : HasLaw Z_perp (gaussianReal 0 1) μ) + (hZSm : Measurable Z_S) (hZperpm : Measurable Z_perp) + (hindep : IndepFun Z_S Z_perp μ) : + ∫ ω, (S₀ * Real.exp ((r_dom - σ_S ^ 2 / 2) * T + σ_S * Real.sqrt T * Z_S ω)) + * Real.exp (-(σ_FX * Real.sqrt T) + * (ρ * Z_S ω + Real.sqrt (1 - ρ ^ 2) * Z_perp ω) - σ_FX ^ 2 * T / 2) ∂μ + = quantoForward S₀ r_dom ρ σ_S σ_FX T := by + set E : ℝ := (r_dom - σ_S ^ 2 / 2) * T - σ_FX ^ 2 * T / 2 with hE + set a : ℝ := (σ_S - ρ * σ_FX) * Real.sqrt T with ha + set b : ℝ := -(σ_FX * Real.sqrt (1 - ρ ^ 2)) * Real.sqrt T with hb + -- Pointwise: the integrand is `S₀·exp(E + a·Z_S + b·Z_⊥)`, an exponential affine in the drivers. + have hpt : (fun ω ↦ (S₀ * Real.exp ((r_dom - σ_S ^ 2 / 2) * T + σ_S * Real.sqrt T * Z_S ω)) + * Real.exp (-(σ_FX * Real.sqrt T) + * (ρ * Z_S ω + Real.sqrt (1 - ρ ^ 2) * Z_perp ω) - σ_FX ^ 2 * T / 2)) + = fun ω ↦ S₀ * Real.exp (E + a * Z_S ω + b * Z_perp ω) := by + funext ω + rw [hE, ha, hb, mul_assoc, ← Real.exp_add] + congr 2 + ring + -- Factor the affine form in the two independent drivers via the shared MGF lemma. + rw [hpt, integral_const_mul, integral_exp_affine_indep hZS hZperp hZSm hZperpm hindep] + -- Final algebra: the cross-term `−ρ σ_S σ_FX` emerges from `a²`. + have ha2 : a ^ 2 = (σ_S - ρ * σ_FX) ^ 2 * T := by rw [ha, mul_pow, Real.sq_sqrt hT] + have hb2 : b ^ 2 = σ_FX ^ 2 * (1 - ρ ^ 2) * T := by + rw [hb, show (-(σ_FX * Real.sqrt (1 - ρ ^ 2)) * Real.sqrt T) ^ 2 + = σ_FX ^ 2 * (Real.sqrt (1 - ρ ^ 2)) ^ 2 * (Real.sqrt T) ^ 2 from by ring, + Real.sq_sqrt (by linarith : (0 : ℝ) ≤ 1 - ρ ^ 2), Real.sq_sqrt hT] + rw [quantoForward, ha2, hb2, hE, + show (r_dom - ρ * σ_S * σ_FX) * T + = ((r_dom - σ_S ^ 2 / 2) * T - σ_FX ^ 2 * T / 2) + + (σ_S - ρ * σ_FX) ^ 2 * T / 2 + σ_FX ^ 2 * (1 - ρ ^ 2) * T / 2 from by ring] + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/RiskNeutralProbabilities.lean b/LeanPool/MathFin/Models/BlackScholes/RiskNeutralProbabilities.lean new file mode 100644 index 0000000000..62c07824ca --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/RiskNeutralProbabilities.lean @@ -0,0 +1,99 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Call + +/-! +# Probabilistic interpretation of `bsd2`: the exercise-probability identity + +The BS formula `bsV = S · Φ(d_1) − K · e^{−rT} · Φ(d_2)` has two `Φ` values. +Each has a probabilistic meaning under the risk-neutral measure `Q`: + +* `Φ(d_2) = Q(S_T > K)` — the risk-neutral exercise probability. +* `Φ(d_1) = Q^{(S)}(S_T > K)` — the same probability under the + **stock-numeraire measure** (change of numeraire), formalised in the + companion `StockNumeraire.lean` (`stockNumeraire_exercise_probability`). + +This file formalises the simpler `Φ(d_2) = Q(S_T > K)` identity. It is the +probabilistic content of `bsd2`: a parameter that arises algebraically in +the BS formula is identified with the risk-neutral probability of finishing +in the money. + +## Why this is "first principles" + +Existing library content treats `bsd2` as a closed-form expression +(`d_2 := (log(S_0/K) + (r − σ²/2)T) / (σ√T)`). This file gives `bsd2` its +*probabilistic meaning*: it is the negative of the standardised +log-moneyness threshold, and `Φ(bsd2)` is the risk-neutral exercise +probability. + +The companion `Φ(d_1) = Q^{(S)}(S_T > K)` identity — via the change-of- +numeraire machinery (Radon-Nikodym derivative of the stock-numeraire +measure w.r.t. the risk-neutral measure) — is formalised in +`StockNumeraire.lean` (`stockNumeraire_exercise_probability`). + +## Building blocks (all pre-existing in `Models.BlackScholes.Call`) + +* `BSCallHyp` — the risk-neutral law specification: `Z ~ N(0, 1)` under `Q`, + `S_T = bsTerminal S_0 r σ T (Z ·)`. +* `bsTerminal_gt_K_iff` — exercise-region identification: + `S_T(z) > K ↔ z > −bsd2 S_0 K r σ T`. +* `gaussianReal_Ioi_toReal` — right-tail probability: + `(gaussianReal 0 1 (Ioi a)).toReal = Φ(−a)`. + +## Main results + +* `riskNeutralProb_S_T_gt_K`: `Q(S_T > K) = Φ(bsd2 S_0 K r σ T)`. The + probabilistic interpretation of `Φ(d_2)` in the BS formula. + +## Tags + +risk-neutral exercise probability, in-the-money probability, d2 interpretation, Black–Scholes, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- **Risk-neutral exercise probability identification**: under the risk- +neutral hypothesis `BSCallHyp`, the probability that the terminal asset +`S_T` exceeds the strike `K` equals `Φ(bsd2 S_0 K r σ T)`. + +Proof: the exercise region `{S_T(z) > K}` is identified with +`{z > −bsd2}` by `bsTerminal_gt_K_iff`. The risk-neutral probability of +this set is `Q(Z > −bsd2)`, which by `HasLaw` transfer equals +`(gaussianReal 0 1)(Ioi (−bsd2))`. By `gaussianReal_Ioi_toReal`, this is +`Φ(−(−bsd2)) = Φ(bsd2)`. -/ +theorem riskNeutralProb_S_T_gt_K + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + (Q {ω | bsTerminal S_0 r σ T (Z ω) > K}).toReal = + Phi (bsd2 S_0 K r σ T) := by + obtain ⟨hS_0, hK, hσ, hT, hZ⟩ := h + -- Identify the exercise region with {Z > -d_2}. + have h_set_eq : + {ω | bsTerminal S_0 r σ T (Z ω) > K} = Z ⁻¹' Set.Ioi (-bsd2 S_0 K r σ T) := by + ext ω + rw [Set.mem_ofPred_eq, Set.mem_preimage, Set.mem_Ioi] + exact bsTerminal_gt_K_iff hS_0 hK hσ hT (Z ω) + rw [h_set_eq] + -- HasLaw transfer: Q (Z ⁻¹' A) = (Q.map Z) A = (gaussianReal 0 1) A. + have h_meas : AEMeasurable Z Q := hZ.aemeasurable + rw [← Measure.map_apply_of_aemeasurable h_meas measurableSet_Ioi] + rw [hZ.map_eq] + -- (gaussianReal 0 1)(Ioi a).toReal = Φ(-a). With a = -d_2, Φ(-(-d_2)) = Φ(d_2). + rw [gaussianReal_Ioi_toReal] + congr 1; ring + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/SpotConvexity.lean b/LeanPool/MathFin/Models/BlackScholes/SpotConvexity.lean new file mode 100644 index 0000000000..f814037db3 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/SpotConvexity.lean @@ -0,0 +1,128 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.PDE +public import LeanPool.MathFin.Models.BlackScholes.GreekSigns +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.RingTheory.Flat.TorsionFree +public import Mathlib.RingTheory.Smooth.Flat + +/-! +# Spot-direction convexity of the Black–Scholes call + +`StrikeConvexity.lean` packages convexity-in-`K` at four scales; this file +is its spot-direction dual at the two scales that make sense for `S`: + +1. **Payoff level**, `S ↦ max(S − K, 0)`: the positive part of an affine + function is convex. +2. **Continuous price level**, `S ↦ bsV K r σ S τ`: strictly convex on `(0, ∞)` + by the second-derivative test — gamma is positive + (`hasDerivAt_deriv_bsV_S` + `strictConvexOn_of_deriv2_pos'`). + +Financially: pricing preserves the convexity of the payoff. Gamma-positivity +(`bsV_gamma_pos`) is the infinitesimal face of the same fact, and makes the +convexity strict. The supporting-tangent form below (`bsV_spot_tangent_le`, +slope = delta) is the workhorse for Jensen-type mixture bounds: +`MertonDominance.lean` and `JumpDiffusionMixing.lean` consume it to prove that a +jump-diffusion call dominates the Black–Scholes call, and `JumpImpliedVol.lean` +consumes the strict form (`bsV_spot_tangent_lt`) to make the domination strict. + +## Main results + +* `convexOn_call_payoff_spot`: `S ↦ max(S − K, 0)` is convex (payoff level). +* `bsV_spot_strictConvexOn`, `bsV_spot_convexOn`: `S ↦ bsV K r σ S τ` is strictly convex, hence + convex, on `(0, ∞)` (continuous price level). +* `bsV_spot_tangent_lt`, `bsV_spot_tangent_le`: the price lies above its tangent at any + `S₀ > 0`, with slope delta, `bsV(S₀) + Φ(d₁(S₀))·(s − S₀) ≤ bsV(s)`, strictly away from the + point of tangency. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull] +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], §4.5 + +## Tags + +gamma positivity, price convexity in spot, convex payoff, tangent bound, Jensen mixture, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Set Real ProbabilityTheory + +/-- **Call payoff is convex in the spot**: `S ↦ max(S − K, 0)` is the +positive part of an affine function. The spot-direction sibling of +`convexOn_call_payoff`. -/ +lemma convexOn_call_payoff_spot (K : ℝ) : + ConvexOn ℝ Set.univ (fun S : ℝ ↦ max (S - K) 0) := by + refine ConvexOn.sup ⟨convex_univ, fun a _ b _ s t _ _ hst ↦ ?_⟩ + (convexOn_const (0 : ℝ) convex_univ) + change s • a + t • b - K ≤ s • (a - K) + t • (b - K) + simp only [smul_eq_mul] + have h_kk : s * K + t * K = K := by linear_combination K * hst + linarith + +/-! ## The continuous-price face + +The proof is the second-derivative test; the strike side instead integrates the payoff against +the standard normal law (`bsV_strike_convexOn`): + +* `hasDerivAt_bsV_S`: `∂_S bsV = Φ(d₁)` (delta) exists at every `S > 0`. +* `hasDerivAt_deriv_bsV_S`: `∂²_S bsV = ϕ(d₁)/(S σ √τ)` (gamma) exists at every + `S > 0`, and it is positive (`bsV_gamma_pos`). -/ + +/-- **BS call price is strictly convex in the spot on `(0, ∞)`**: at every `S > 0` the gamma +`∂²_S bsV = ϕ(d₁)/(S σ √τ)` is positive (`bsV_gamma_pos`). -/ +theorem bsV_spot_strictConvexOn {K r σ τ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) : + StrictConvexOn ℝ (Set.Ioi (0 : ℝ)) (fun s ↦ bsV K r σ s τ) := + strictConvexOn_of_deriv2_pos' (convex_Ioi 0) + (fun _ hS ↦ (hasDerivAt_bsV_S hK hσ hS hτ).continuousAt.continuousWithinAt) + fun _ hS ↦ (bsV_gamma_pos (r := r) hK hσ hS hτ).trans_eq + (hasDerivAt_deriv_bsV_S hK hσ hS hτ).deriv.symm + +/-- **BS call price is convex in the spot on `(0, ∞)`** — the continuous-price face of +S-convexity; the strict form is `bsV_spot_strictConvexOn`. -/ +theorem bsV_spot_convexOn {K r σ τ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hτ : 0 < τ) : + ConvexOn ℝ (Set.Ioi (0 : ℝ)) (fun s ↦ bsV K r σ s τ) := + (bsV_spot_strictConvexOn hK hσ hτ).convexOn + +/-- **The price lies strictly above its tangent away from `S₀`**: for `s ≠ S₀`, +`bsV(S₀) + Φ(d₁(S₀))·(s − S₀) < bsV(s)`. Strict convexity (`bsV_spot_strictConvexOn`) plus the +closed-form delta (`hasDerivAt_bsV_S`), through the slope comparison lemmas. -/ +theorem bsV_spot_tangent_lt {K r σ τ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + (hτ : 0 < τ) {S₀ s : ℝ} (hS₀ : 0 < S₀) (hs : 0 < s) (hne : s ≠ S₀) : + bsV K r σ S₀ τ + Phi (bsd1 S₀ K r σ τ) * (s - S₀) < bsV K r σ s τ := by + have hconv := bsV_spot_strictConvexOn (K := K) (r := r) (σ := σ) (τ := τ) hK hσ hτ + have hder := hasDerivAt_bsV_S (K := K) (r := r) (σ := σ) hK hσ hS₀ hτ + rcases hne.lt_or_gt with hlt | hgt + · -- to the left of S₀: slope s S₀ < delta. + have h := hconv.slope_lt_of_hasDerivAt (Set.mem_Ioi.mpr hs) (Set.mem_Ioi.mpr hS₀) hlt hder + rw [slope_def_field] at h + have h' := (div_lt_iff₀ (sub_pos.mpr hlt)).mp h + linarith + · -- to the right of S₀: delta < slope S₀ s. + have h := hconv.lt_slope_of_hasDerivAt (Set.mem_Ioi.mpr hS₀) (Set.mem_Ioi.mpr hs) hgt hder + rw [slope_def_field] at h + have h' := (lt_div_iff₀ (sub_pos.mpr hgt)).mp h + linarith + +/-- **The price lies above its tangent at any `S₀ > 0`, with slope delta**: +`bsV(S₀) + Φ(d₁(S₀))·(s − S₀) ≤ bsV(s)`, the supporting-hyperplane form of `bsV_spot_convexOn`; +away from `S₀` it is `bsV_spot_tangent_lt`. -/ +theorem bsV_spot_tangent_le {K r σ τ : ℝ} (hK : 0 < K) (hσ : 0 < σ) + (hτ : 0 < τ) {S₀ s : ℝ} (hS₀ : 0 < S₀) (hs : 0 < s) : + bsV K r σ S₀ τ + Phi (bsd1 S₀ K r σ τ) * (s - S₀) ≤ bsV K r σ s τ := by + rcases eq_or_ne s S₀ with rfl | hne + · simp + · exact (bsV_spot_tangent_lt hK hσ hτ hS₀ hs hne).le + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/StockNumeraire.lean b/LeanPool/MathFin/Models/BlackScholes/StockNumeraire.lean new file mode 100644 index 0000000000..352e31af5b --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/StockNumeraire.lean @@ -0,0 +1,212 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Call + +/-! +# Delta as stock-numeraire probability: `Φ(d_1) = Q^(S)(S_T > K)` + +Under the risk-neutral measure `Q`, `Φ(d_2)` is the exercise probability +(formalised in `Models.BlackScholes.RiskNeutralProbabilities`). The other Φ in the +BS formula, `Φ(d_1)`, has a *different* probabilistic interpretation: it is +the exercise probability **under the stock-numeraire measure** `Q^(S)`, +the numéraire measure with Radon-Nikodym density + + `dQ^(S)/dQ := e^{−rT} · S_T / S_0`. + +This file derives that identification in two parts. + +## Part 1: asset-payoff integral identity + +`bsCall_asset_piece_integral`: the Q-integral of `S_T` on the exercise +region equals `S_0 · e^{rT} · Φ(d_1)`. This is the "Φ(d_1) piece" of the +BS formula, extracted as a standalone identity. + + `∫ ω, 1_{S_T(Z ω) > K} · S_T(Z ω) ∂Q = S_0 · e^{rT} · Φ(d_1)`. + +The proof mirrors `bs_call_formula`: HasLaw transfer, indicator on the +exercise region `{z > −d_2}`, `integral_exp_mul_gaussianPDFReal_Ioi` for +the completing-the-square step, and the BS algebraic identity +`(r − σ²/2)T + σ²T/2 = rT`. + +## Part 2: the identification + +The stock-numeraire measure is not a separate object: it is `Pricing.Numeraire`'s +`numeraireMeasure Q (fun _ ↦ e^{rT}) (fun ω ↦ S_T(Z ω)) 1 S_0`, the instance `B_T = e^{rT}`, +`B₀ = 1`, `N = S` of the general change of numéraire, whose density +`(N_T·B₀)/(N₀·B_T)` is `e^{−rT} · S_T / S_0`. + +`stockNumeraire_exercise_probability`: `∫ 1_{S_T(Z ω) > K} · e^{−rT} S_T(Z ω)/S_0 dQ = Φ(d_1)`, +the `Q^(S)`-probability of the exercise event, `Q^(S) = numeraireMeasure …` as above. + +This closes the structural narrative on the BS formula: + + * `bsV = S_0 · Φ(d_1) − K · e^{−rT} · Φ(d_2)` + * `Φ(d_2) = Q(S_T > K)` (risk-neutral exercise probability) + * `Φ(d_1) = Q^(S)(S_T > K)` (stock-numeraire exercise probability) + +Each Φ is now identified with the exercise probability under one of the +two natural numeraires (money market vs. stock). + +## Main results + +* `bsCall_asset_piece_integral`: under `BSCallHyp`, the `Q`-integral of `S_T` over the exercise + region `{z > -d₂}` is `S_0 * exp (r * T) * Φ(d₁)`. +* `stockNumeraire_exercise_probability`: under `BSCallHyp`, the `Q`-integral over the exercise + region of the density `exp (-r * T) * S_T / S_0` is `Φ(d₁)`; this is the exercise probability + under the measure with that density with respect to `Q`. + +## Tags + +stock numeraire, change of numeraire, delta as probability, Radon–Nikodym density, +exercise probability, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal + +/-! ## Part 1: the asset-payoff integral identity -/ + +/-- **Asset-payoff integral on the exercise region**: under the risk-neutral +hypothesis `BSCallHyp`, + + `∫ ω, 1_{S_T(Z ω) > K} · S_T(Z ω) ∂Q = S_0 · e^{rT} · Φ(d_1)`. + +The integral on the LHS is the Q-expectation of `S_T` restricted to the +exercise region. Combined with `riskNeutralProb_S_T_gt_K` +(`Q(S_T > K) = Φ(d_2)`), this gives the canonical decomposition of the +European call price + + `bsV = e^{−rT} · ∫ ω, max(S_T(Z ω) − K, 0) ∂Q + = e^{−rT} · ∫ ω, 1_{S_T(Z ω) > K} · S_T(Z ω) ∂Q + − K · e^{−rT} · Q({S_T > K}) + = S_0 · Φ(d_1) − K · e^{−rT} · Φ(d_2)`. -/ +theorem bsCall_asset_piece_integral + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + ∫ ω, (Set.Ioi (-bsd2 S_0 K r σ T)).indicator + (bsTerminal S_0 r σ T) (Z ω) ∂Q = + S_0 * Real.exp (r * T) * Phi (bsd1 S_0 K r σ T) := by + obtain ⟨hS_0, hK, hσ, hT, hZ⟩ := h + set d_1 : ℝ := bsd1 S_0 K r σ T with d_1_def + set d_2 : ℝ := bsd2 S_0 K r σ T with d_2_def + set μ_log : ℝ := (r - σ ^ 2 / 2) * T with μ_log_def + set ν_log : ℝ := σ * Real.sqrt T with ν_log_def + have hsqrT_pos : 0 < Real.sqrt T := Real.sqrt_pos.mpr hT + have hν_log_sq : ν_log ^ 2 = σ ^ 2 * T := by + rw [ν_log_def, mul_pow, Real.sq_sqrt hT.le] + have h_algebra : μ_log + ν_log ^ 2 / 2 = r * T := by rw [hν_log_sq]; ring + have h_shift_eq : ν_log - (-d_2) = d_1 := by rw [d_1_def, d_2_def, bsd2]; ring + have h_term_meas : Measurable fun z : ℝ ↦ bsTerminal S_0 r σ T z := by + unfold bsTerminal; fun_prop + have h_ind_meas : Measurable fun z : ℝ ↦ + (Set.Ioi (-d_2)).indicator (bsTerminal S_0 r σ T) z := + h_term_meas.indicator measurableSet_Ioi + -- Step 1: express as ∘ Z and apply HasLaw transfer + rw [show (fun ω ↦ (Set.Ioi (-d_2)).indicator (bsTerminal S_0 r σ T) (Z ω)) = + (fun z ↦ (Set.Ioi (-d_2)).indicator (bsTerminal S_0 r σ T) z) ∘ Z from rfl, + hZ.integral_comp h_ind_meas.aestronglyMeasurable, + integral_gaussianReal_eq_integral_smul (one_ne_zero : (1 : ℝ≥0) ≠ 0)] + -- Step 2: pdf · indicator (Ioi) bsTerminal = indicator (Ioi) (pdf · bsTerminal) + rw [show (fun z ↦ gaussianPDFReal 0 1 z • + (Set.Ioi (-d_2)).indicator (bsTerminal S_0 r σ T) z) + = (Set.Ioi (-d_2)).indicator + (fun z ↦ gaussianPDFReal 0 1 z • bsTerminal S_0 r σ T z) from + funext (fun z ↦ by + by_cases hz : z ∈ Set.Ioi (-d_2) + · rw [Set.indicator_of_mem hz, Set.indicator_of_mem hz] + · rw [Set.indicator_of_notMem hz, Set.indicator_of_notMem hz, smul_zero])] + rw [integral_indicator measurableSet_Ioi] + -- Step 3: rewrite pdf · bsTerminal in factored form + rw [setIntegral_congr_fun measurableSet_Ioi (fun z _ ↦ + show gaussianPDFReal 0 1 z • bsTerminal S_0 r σ T z = + S_0 * Real.exp μ_log * + (Real.exp (ν_log * z) * gaussianPDFReal 0 1 z) from by + unfold bsTerminal + have h_exp : Real.exp ((r - σ ^ 2 / 2) * T + σ * Real.sqrt T * z) + = Real.exp μ_log * Real.exp (ν_log * z) := by + change Real.exp ((r - σ ^ 2 / 2) * T + σ * Real.sqrt T * z) + = Real.exp ((r - σ ^ 2 / 2) * T) * Real.exp (σ * Real.sqrt T * z) + exact Real.exp_add _ _ + rw [smul_eq_mul, h_exp]; ring)] + -- Step 4: pull out S_0 · exp(μ_log) and apply integral_exp_mul_gaussianPDFReal_Ioi + rw [integral_const_mul, integral_exp_mul_gaussianPDFReal_Ioi, h_shift_eq] + -- Step 5: S_0 · exp(μ_log) · exp(ν_log²/2) · Φ(d_1) = S_0 · exp(rT) · Φ(d_1) + rw [show S_0 * Real.exp μ_log * (Real.exp (ν_log ^ 2 / 2) * Phi d_1) = + S_0 * (Real.exp μ_log * Real.exp (ν_log ^ 2 / 2)) * Phi d_1 from by ring, + ← Real.exp_add, h_algebra] + +/-! ## Part 2: the identification -/ + +/-- **Delta as stock-numeraire exercise probability**: under the risk-neutral +hypothesis `BSCallHyp`, + + `∫ 1_{S_T(Z ω) > K} · e^{−rT} S_T(Z ω) / S_0 ∂Q = Φ(d_1)`, + +the `Q^(S)`-probability of the exercise event for the stock-numeraire measure +`Q^(S) = Q.withDensity (e^{−rT} · S_T / S_0)`, that is `numeraireMeasure` at `B_T = e^{rT}`, +`B₀ = 1`, `N = S`. + +This is the companion to `riskNeutralProb_S_T_gt_K` +(`Q({S_T > K}) = Φ(d_2)`): under change of numeraire from money market to +stock, the same exercise event has probability `Φ(d_1)`, not `Φ(d_2)`. The +difference `Φ(d_1) − Φ(d_2)` measures the "value of optionality" beyond +pure expected payoff. -/ +theorem stockNumeraire_exercise_probability + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + (∫ ω, (Set.Ioi (-bsd2 S_0 K r σ T)).indicator + (fun z ↦ Real.exp (-r * T) * bsTerminal S_0 r σ T z / S_0) (Z ω) ∂Q) = + Phi (bsd1 S_0 K r σ T) := by + obtain ⟨hS_0, hK, hσ, hT, hZ⟩ := h + -- Rewrite the indicator integrand: + -- indicator (Ioi) (e^{-rT} · S_T / S_0) z = + -- e^{-rT} / S_0 · indicator (Ioi) S_T z + have h_factor : ∀ z : ℝ, + (Set.Ioi (-bsd2 S_0 K r σ T)).indicator + (fun z ↦ Real.exp (-r * T) * bsTerminal S_0 r σ T z / S_0) z = + (Real.exp (-r * T) / S_0) * + (Set.Ioi (-bsd2 S_0 K r σ T)).indicator + (bsTerminal S_0 r σ T) z := by + intro z + by_cases hz : z ∈ Set.Ioi (-bsd2 S_0 K r σ T) + · rw [Set.indicator_of_mem hz, Set.indicator_of_mem hz] + field_simp + · rw [Set.indicator_of_notMem hz, Set.indicator_of_notMem hz, mul_zero] + -- Pull the constant outside the integral + rw [show (fun ω ↦ (Set.Ioi (-bsd2 S_0 K r σ T)).indicator + (fun z ↦ Real.exp (-r * T) * bsTerminal S_0 r σ T z / S_0) (Z ω)) = + (fun ω ↦ (Real.exp (-r * T) / S_0) * + (Set.Ioi (-bsd2 S_0 K r σ T)).indicator + (bsTerminal S_0 r σ T) (Z ω)) from + funext (fun ω ↦ h_factor (Z ω))] + rw [integral_const_mul] + -- Apply the asset-payoff integral identity + rw [bsCall_asset_piece_integral + ⟨hS_0, hK, hσ, hT, hZ⟩] + -- Combine: (e^{-rT}/S_0) · S_0 · e^{rT} · Phi(d_1) = Phi(d_1) + have h_exp : Real.exp (-(r * T)) * Real.exp (r * T) = 1 := by + rw [← Real.exp_add, neg_add_cancel, Real.exp_zero] + rw [show Real.exp (-r * T) / S_0 * + (S_0 * Real.exp (r * T) * Phi (bsd1 S_0 K r σ T)) = + (Real.exp (-(r * T)) * Real.exp (r * T)) * (S_0 / S_0) * + Phi (bsd1 S_0 K r σ T) from by + rw [show Real.exp (-r * T) = Real.exp (-(r * T)) from by congr 1; ring] + field_simp] + rw [div_self hS_0.ne', mul_one, h_exp, one_mul] + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/StrikeConvexity.lean b/LeanPool/MathFin/Models/BlackScholes/StrikeConvexity.lean new file mode 100644 index 0000000000..207c976b19 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/StrikeConvexity.lean @@ -0,0 +1,196 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.PutGreeks +public import LeanPool.MathFin.Contracts.Instruments.CallPayoff +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.RingTheory.Flat.TorsionFree +public import Mathlib.RingTheory.Smooth.Flat + +/-! +# Strike-direction convexity at every scale + +The European call satisfies *the same* convexity-in-`K` fact at every scale of +resolution: + +1. **Payoff level**, `K ↦ max(S − K, 0)`. Convex because the positive + part of an affine function is convex (`ConvexOn.sup` on `(S − ·)` and + `0`). +2. **Price level, under any law**, `K ↦ ∫ (X − K)⁺ dμ`. Convex because + integration against a positive measure preserves the convexity of the + payoff (`convexOn_integral_call`, Mathlib's + `integral_convexOn_of_integrand_ae`). Strictly convex wherever the law + charges every interval of strikes (`strictConvexOn_integral_call`): a + butterfly spread with distinct strikes pays a positive amount when `X` + ends strictly between its outer strikes. +3. **Finite-state price level**, `K ↦ Σ q_i · max(S_i − K, 0)`. Convex + because non-negative linear combinations of convex functions are convex + (`ConvexPricingFunctional.callPrice_finiteState_convexOn_K`). +4. **Continuous BS price level**, `K ↦ bsV K r σ S τ`. Convex on `(0, ∞)` + for `S, σ, τ > 0`, as scale 2 for the standard normal law, the + Black–Scholes price being the discounted expected payoff + (`integral_bsCall_payoff_eq_bsV`). Strictly convex: the jump-diffusion + without jumps, `bsV_strike_strictConvexOn` in + `JumpDiffusionStrikeConvexity.lean`. + +The scales are one principle realised at different levels of integration: +scale 4 is scale 2 for the standard normal law, and scale 3, proved in +`ConvexPricingFunctional.lean` by summing convex functions, is scale 2 for a +finitely supported measure. + +## Downstream consequences (one principle, many faces) + +* **Bull spread** `V(K₁) ≥ V(K₂)` for `K₁ ≤ K₂` — `Antitone`-payoff after + pricing-functional preservation of monotonicity. +* **Butterfly non-negativity at payoff** (`butterfly_payoff_nonneg`) — + convex-payoff second-difference inequality. +* **Butterfly non-negativity at price** (`callPrice_finiteState_butterfly_nonneg`) — + pricing functional preserves convexity, hence the same second-difference + is non-negative at the price level. +* **Breeden-Litzenberger PDF positivity** + (`lognormalTerminalPDF_nonneg_via_strike_convexity`) — the infinitesimal + manifestation of price-level convexity, from `bsV_strike_convexOn` below via + `deriv_deriv_nonneg_of_convexOn`. That convexity comes from the payoff through + integration (`convexOn_integral_call`), not from the sign of the closed form, so + this derives the sign of the density from the convexity of the payoff and the + positivity of the standard normal law (used as `ϕ ≥ 0` inside + `bs_call_formula`). + +## Main results + +* `StrictConvexOn.smul`: a strictly convex function scaled by a positive + constant is strictly convex. +* `convexOn_integral_call`: `K ↦ ∫ (X − K)⁺ dμ` is convex, for any integrable + `X` under a finite measure. +* `strictConvexOn_integral_call`: it is strictly convex on a convex set of + strikes `s` when `μ {k₁ < X < k₂} ≠ 0` for all `k₁ < k₂` in `s`. +* `bsV_strike_convexOn`: `K ↦ bsV K r σ S τ` is convex on `(0, ∞)` + (continuous BS price level). + +## References + +* [Breeden and Litzenberger, *Prices of state-contingent claims implicit in option + prices*][BreedenLitzenberger1978] +* [R. C. Merton, *Theory of rational option pricing*][Merton1973] + +## Tags + +call price convexity, butterfly arbitrage, Breeden–Litzenberger, implied density, strike convexity, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +/-- A strictly convex function scaled by a positive constant is strictly convex: the strict +counterpart of Mathlib's `ConvexOn.smul`. -/ +theorem StrictConvexOn.smul {𝕜 E β : Type*} [CommSemiring 𝕜] [PartialOrder 𝕜] [AddCommMonoid E] + [AddCommMonoid β] [PartialOrder β] [SMul 𝕜 E] [Module 𝕜 β] [PosSMulStrictMono 𝕜 β] + {s : Set E} {f : E → β} {c : 𝕜} (hc : 0 < c) (hf : StrictConvexOn 𝕜 s f) : + StrictConvexOn 𝕜 s fun x ↦ c • f x := + ⟨hf.1, fun x hx y hy hxy a b ha hb hab ↦ + calc c • f (a • x + b • y) < c • (a • f x + b • f y) := + smul_lt_smul_of_pos_left (hf.2 hx hy hxy ha hb hab) hc + _ = a • c • f x + b • c • f y := by rw [smul_add, smul_comm c, smul_comm c]⟩ + +namespace MathFin + +open MeasureTheory Set Real ProbabilityTheory + +/-! ## The price under any law + +Integrating the convex payoff against a law keeps it convex, and a law that +charges every interval of strikes makes it strictly convex. Nothing about the +law is assumed beyond a finite mean. -/ + +/-- **The call price is convex in the strike, under any law.** For an integrable `X` under a finite +measure `μ`, `k ↦ ∫ (X − k)⁺ dμ` is convex: integration against a positive measure preserves the +convexity of the payoff (`convexOn_call_payoff`), which is Mathlib's +`integral_convexOn_of_integrand_ae`. -/ +theorem convexOn_integral_call {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsFiniteMeasure μ] {X : Ω → ℝ} (hX : Integrable X μ) : + ConvexOn ℝ univ fun k ↦ ∫ ω, max (X ω - k) 0 ∂μ := + integral_convexOn_of_integrand_ae convex_univ (ae_of_all _ fun ω ↦ convexOn_call_payoff (X ω)) + fun k _ ↦ (hX.sub (integrable_const k)).pos_part + +/-- **The call price is strictly convex in the strike wherever the law charges every interval.** For +an integrable `X` under a finite measure `μ` and a convex set `s` of strikes such that +`μ {k₁ < X < k₂} ≠ 0` whenever `k₁ < k₂` lie in `s`, `k ↦ ∫ (X − k)⁺ dμ` is strictly convex on `s`: +every butterfly spread `a C(k₁) + b C(k₂) − C(a k₁ + b k₂)` (`a, b > 0`, `a + b = 1`) with distinct +strikes `k₁ ≠ k₂` in `s` has a positive price. Its payoff is nonnegative (`convexOn_call_payoff`), +and positive when `k₁ < X < k₂`, where the call struck at `k₂` pays nothing. -/ +theorem strictConvexOn_integral_call {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsFiniteMeasure μ] {X : Ω → ℝ} (hX : Integrable X μ) {s : Set ℝ} (hs : Convex ℝ s) + (hμ : ∀ k₁ ∈ s, ∀ k₂ ∈ s, k₁ < k₂ → μ {ω | k₁ < X ω ∧ X ω < k₂} ≠ 0) : + StrictConvexOn ℝ s fun k ↦ ∫ ω, max (X ω - k) 0 ∂μ := by + have hcall (k : ℝ) : Integrable (fun ω ↦ max (X ω - k) 0) μ := + (hX.sub (integrable_const k)).pos_part + refine LinearOrder.strictConvexOn_of_lt hs fun k₁ hk₁ k₂ hk₂ hk a b ha hb hab ↦ ?_ + obtain rfl : b = 1 - a := by linarith + simp only [smul_eq_mul] + have hA : Integrable (fun ω ↦ a * max (X ω - k₁) 0 + (1 - a) * max (X ω - k₂) 0) μ := + ((hcall k₁).const_mul a).add ((hcall k₂).const_mul (1 - a)) + have hφ : Integrable (fun ω ↦ a * max (X ω - k₁) 0 + (1 - a) * max (X ω - k₂) 0 + - max (X ω - (a * k₁ + (1 - a) * k₂)) 0) μ := hA.sub (hcall _) + -- the butterfly payoff is nonnegative, and positive when `k₁ < X < k₂` + have h0 : 0 < ∫ ω, (a * max (X ω - k₁) 0 + (1 - a) * max (X ω - k₂) 0 + - max (X ω - (a * k₁ + (1 - a) * k₂)) 0) ∂μ := by + refine (integral_pos_iff_support_of_nonneg (fun ω ↦ ?_) hφ).2 + (pos_iff_ne_zero.2 fun h ↦ hμ k₁ hk₁ k₂ hk₂ hk (measure_mono_null (fun ω hω ↦ ?_) h)) + · exact sub_nonneg.2 (by simpa only [smul_eq_mul] using + (convexOn_call_payoff (X ω)).2 (mem_univ k₁) (mem_univ k₂) ha.le hb.le hab) + · obtain ⟨h₁, h₂⟩ := hω + simp only [Function.mem_support, max_eq_left (sub_pos.2 h₁).le, + max_eq_right (sub_nonpos.2 h₂.le), mul_zero, add_zero] + exact (sub_pos.2 (max_lt (by linarith [mul_pos hb (sub_pos.2 h₂)]) + (mul_pos ha (sub_pos.2 h₁)))).ne' + rw [integral_sub hA (hcall _), integral_add ((hcall k₁).const_mul a) + ((hcall k₂).const_mul (1 - a)), integral_const_mul, integral_const_mul] at h0 + linarith + +/-! ## The continuous-price face + +The Black–Scholes price is the discounted call payoff integrated against the +standard normal law (`integral_bsCall_payoff_eq_bsV`), so it inherits the +convexity of the payoff through `convexOn_integral_call`. The second strike +derivative `e^{-rτ} · ϕ(d_2) / (K σ √τ)` (`hasDerivAt_deriv_bsV_K`) is then +nonnegative as a consequence (`lognormalTerminalPDF_nonneg_via_strike_convexity`), +and also by its sign (`bsV_partial_KK_nonneg`). Both routes use the positivity of +the standard normal density: this one inside `bs_call_formula`. -/ + +/-- **BS call price is convex in the strike on `(0, ∞)`** — the continuous- +price face of the K-convexity principle. + +The Black–Scholes price is the discounted expected call payoff under the standard normal law +(`integral_bsCall_payoff_eq_bsV`), so this is `convexOn_integral_call` for that law. The sign of +the second strike derivative is not used. -/ +theorem bsV_strike_convexOn {S r σ τ : ℝ} (hS : 0 < S) (hσ : 0 < σ) (hτ : 0 < τ) : + ConvexOn ℝ (Set.Ioi (0 : ℝ)) (fun K ↦ bsV K r σ S τ) := + (((convexOn_integral_call (integrable_bsTerminal_gaussianReal S r σ τ)).subset + (subset_univ _) (convex_Ioi 0)).smul (Real.exp_pos (-r * τ)).le).congr fun K hK ↦ by + simp only [smul_eq_mul] + rw [← integral_const_mul] + exact integral_bsCall_payoff_eq_bsV (Q := gaussianReal 0 1) (Z := id) + ⟨hS, mem_Ioi.1 hK, hσ, hτ, HasLaw.id⟩ + +/-- **Put price is convex in the strike on `(0, ∞)`** — free from the call's +strike-convexity: `bsP = bsV + (K·e^{-rτ} − S)` differs from `bsV` by an affine +function of `K`, and convexity is preserved by adding an affine function. The +second-derivative apparatus of `PutStrikeConvexity` is not needed. -/ +theorem bsP_strike_convexOn {S r σ τ : ℝ} (hS : 0 < S) (hσ : 0 < σ) (hτ : 0 < τ) : + ConvexOn ℝ (Set.Ioi (0 : ℝ)) (fun K ↦ bsP K r σ S τ) := by + have h_eq : (fun K ↦ bsP K r σ S τ) + = (fun K ↦ bsV K r σ S τ) + (fun K ↦ K * Real.exp (-(r * τ)) - S) := by + funext K; simp only [Pi.add_apply]; rw [bsP_eq_bsV K r σ S τ]; ring + rw [h_eq] + refine (bsV_strike_convexOn hS hσ hτ).add ⟨convex_Ioi 0, fun K₁ _ K₂ _ s t _ _ hst ↦ ?_⟩ + dsimp only + simp only [smul_eq_mul] + nlinarith [show s * S + t * S = S from by linear_combination S * hst] + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/StrikeGreeks.lean b/LeanPool/MathFin/Models/BlackScholes/StrikeGreeks.lean new file mode 100644 index 0000000000..464ea62bc7 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/StrikeGreeks.lean @@ -0,0 +1,209 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.PutGreeks +public import LeanPool.MathFin.Models.BlackScholes.DigitalGreeks + +/-! +# Black-Scholes strike derivatives + +Standard derivative-Greek identities in the strike direction: + +* `∂_K bsV = -e^{-rτ} · Φ(d₂)`; its sign, `≤ 0`, is `bsV_partial_K_nonpos`. +* `∂_K bsP = e^{-rτ} · Φ(-d₂)`, via put-call parity `bsP = bsV - S + K · e^{-rτ}`. +* `∂²_K bsV = e^{-rτ} · ϕ(d₂) / (K σ √τ)`; its sign, `≥ 0`, is `bsV_partial_KK_nonneg`. The + convexity of the price in `K` (`StrikeConvexity.bsV_strike_convexOn`) is proved from the + payoff, not from this sign, and gives the sign back + (`lognormalTerminalPDF_nonneg_via_strike_convexity`). + +The clean closed forms come from the magic identity +`S · ϕ(d₁) = K · e^{-rτ} · ϕ(d₂)` (`bs_identity`) which collapses the +`d₁`-derivative contribution. + +## Main results + +* `hasDerivAt_bsd1_K`, `hasDerivAt_bsd2_K`: `∂_K d_i = −1/(K σ √τ)`. +* `hasDerivAt_bsV_K`: `∂_K bsV = −e^{-rτ} · Φ(d₂)`. +* `hasDerivAt_bsP_K`: `∂_K bsP = e^{-rτ} · Φ(-d₂)`. +* `hasDerivAt_bsCashDigital_K`: the strike derivative of the cash-or-nothing digital + `bsCashDigital = e^{-rτ} · Φ(d₂)` is `−e^{-rτ} · ϕ(d₂) / (K σ √τ)`. +* `hasDerivAt_deriv_bsV_K`: `∂²_K bsV = e^{-rτ} · ϕ(d₂) / (K σ √τ)`, for the price itself: the + first strike derivative is minus the digital. + +## References + +* [F. Black and M. Scholes, *The pricing of options and corporate liabilities*][BlackScholes1973] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 26.1; Ch 12.8; Ch 17 + +## Tags + +strike derivative, dual delta, implied density, digital option, Breeden–Litzenberger, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Real ProbabilityTheory + +/-- `∂_K d₁(S, K, r, σ, τ) = −1 / (K · σ · √τ)`. Mirror of `hasDerivAt_bsd1_S`. -/ +lemma hasDerivAt_bsd1_K (S r σ τ : ℝ) (hS : 0 < S) (hσ : 0 < σ) (hτ : 0 < τ) + {K : ℝ} (hK : 0 < K) : + HasDerivAt (fun k ↦ bsd1 S k r σ τ) (-(1 / (K * σ * Real.sqrt τ))) K := by + have h_sqrt_τ_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_τ_ne : Real.sqrt τ ≠ 0 := h_sqrt_τ_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have hK_ne : K ≠ 0 := hK.ne' + -- k ↦ log k has derivative 1/K at K. + have h_log : HasDerivAt Real.log (1 / K) K := by + rw [one_div]; exact Real.hasDerivAt_log hK_ne + -- k ↦ log S - log k has derivative -(1/K) at K. + have h_minus_log : HasDerivAt + (fun k : ℝ ↦ Real.log S - Real.log k) (-(1 / K)) K := by + have h_neg := h_log.neg + have h_add := h_neg.const_add (Real.log S) + have : (fun k : ℝ ↦ Real.log S - Real.log k) = fun x ↦ Real.log S + (-Real.log) x := by + funext x; simp [sub_eq_add_neg] + rw [this]; exact h_add + -- log(S/k) =ᶠ[𝓝 K] log S - log k (since K ≠ 0 in a nbhd). + have h_eventually : (fun k : ℝ ↦ Real.log (S / k)) =ᶠ[nhds K] + (fun k ↦ Real.log S - Real.log k) := by + filter_upwards [eventually_ne_nhds hK_ne] with k hk + exact Real.log_div hS.ne' hk + have h_log_div : HasDerivAt (fun k : ℝ ↦ Real.log (S / k)) (-(1 / K)) K := + h_minus_log.congr_of_eventuallyEq h_eventually + -- Add the constant `(r + σ²/2)τ`. + have h_num : HasDerivAt + (fun k : ℝ ↦ Real.log (S / k) + (r + σ ^ 2 / 2) * τ) (-(1 / K)) K := by + simpa using h_log_div.add_const ((r + σ ^ 2 / 2) * τ) + -- Divide by σ√τ. + have h_div_στ : HasDerivAt + (fun k : ℝ ↦ (Real.log (S / k) + (r + σ ^ 2 / 2) * τ) / (σ * Real.sqrt τ)) + (-(1 / K) / (σ * Real.sqrt τ)) K := + h_num.div_const (σ * Real.sqrt τ) + have h_val_eq : + -(1 / K) / (σ * Real.sqrt τ) = -(1 / (K * σ * Real.sqrt τ)) := by + field_simp + rw [h_val_eq] at h_div_στ + exact h_div_στ + +/-- `∂_K d₂(S, K, r, σ, τ) = −1 / (K · σ · √τ)` (same as `∂_K d_1` since `d_2 − d_1` +is `K`-independent). -/ +lemma hasDerivAt_bsd2_K (S r σ τ : ℝ) (hS : 0 < S) (hσ : 0 < σ) (hτ : 0 < τ) + {K : ℝ} (hK : 0 < K) : + HasDerivAt (fun k ↦ bsd2 S k r σ τ) (-(1 / (K * σ * Real.sqrt τ))) K := by + have h_diff := (hasDerivAt_bsd1_K S r σ τ hS hσ hτ hK).sub_const (σ * Real.sqrt τ) + have h_fun_eq : (fun k : ℝ ↦ bsd1 S k r σ τ - σ * Real.sqrt τ) + = (fun k : ℝ ↦ bsd2 S k r σ τ) := by + funext k; rw [bsd2] + rw [← h_fun_eq] + exact h_diff + +/-- **Strike-derivative of the call price**: `∂_K bsV = −e^{-rτ} · Φ(d₂)`. +The magic identity `S · ϕ(d₁) = K · e^{-rτ} · ϕ(d₂)` collapses the `d_1` +contribution. -/ +lemma hasDerivAt_bsV_K {S r σ : ℝ} (hS : 0 < S) (hσ : 0 < σ) + {K τ : ℝ} (hK : 0 < K) (hτ : 0 < τ) : + HasDerivAt (fun k ↦ bsV k r σ S τ) + (-(Real.exp (-(r * τ)) * Phi (bsd2 S K r σ τ))) K := by + have h_sqrt_τ_pos : 0 < Real.sqrt τ := Real.sqrt_pos.mpr hτ + have h_sqrt_τ_ne : Real.sqrt τ ≠ 0 := h_sqrt_τ_pos.ne' + have hσ_ne : σ ≠ 0 := hσ.ne' + have hK_ne : K ≠ 0 := hK.ne' + have hS_ne : S ≠ 0 := hS.ne' + -- Pieces + have h_d1_K := hasDerivAt_bsd1_K S r σ τ hS hσ hτ hK + have h_d2_K := hasDerivAt_bsd2_K S r σ τ hS hσ hτ hK + have h_Phi_d1 := (hasDerivAt_Phi (bsd1 S K r σ τ)).comp K h_d1_K + have h_Phi_d2 := (hasDerivAt_Phi (bsd2 S K r σ τ)).comp K h_d2_K + -- d/dK [S · Phi(d_1(K))] = S · ϕ(d_1) · ∂_K d_1 + have h_S_Phi_d1 := h_Phi_d1.const_mul S + -- d/dK [K · exp(-rτ) · Phi(d_2(K))] = exp(-rτ)·Phi(d_2) + K·exp(-rτ)·ϕ(d_2)·∂_K d_2 + have h_id : HasDerivAt (fun k : ℝ ↦ k) 1 K := hasDerivAt_id K + have h_K_Phi_d2 := h_id.mul h_Phi_d2 + have h_K_exp_Phi_d2 := h_K_Phi_d2.const_mul (Real.exp (-(r * τ))) + have h_V := h_S_Phi_d1.sub h_K_exp_Phi_d2 + have h_fun_eq : (fun k : ℝ ↦ + S * Phi (bsd1 S k r σ τ) - + Real.exp (-(r * τ)) * (k * Phi (bsd2 S k r σ τ))) = + (fun k : ℝ ↦ bsV k r σ S τ) := by + funext k + show S * Phi (bsd1 S k r σ τ) - + Real.exp (-(r * τ)) * (k * Phi (bsd2 S k r σ τ)) = + bsV k r σ S τ + unfold bsV + ring + rw [← h_fun_eq] + -- Value from h_V equals -(exp(-rτ)·Φ(d₂)) via magic identity + have h_bs := bs_identity (r := r) hS hK hσ hτ + have hKστ_ne : K * σ * Real.sqrt τ ≠ 0 := by positivity + refine h_V.congr_deriv ?_ + -- Goal: S*(g1*(-(1/(Kστ)))) - exp*(1*Φ2 + K*(g2*(-(1/(Kστ))))) = -(exp*Φ2) + -- by h_bs: S*g1 = K*exp*g2, so the extra terms cancel + simp only [Function.comp_apply] + have hKστ_pos : (0 : ℝ) < K * σ * Real.sqrt τ := by positivity + field_simp + linarith [h_bs] + +/-- **Strike-derivative of the put price**: `∂_K bsP = e^{-rτ} · Φ(-d₂)`. Follows +from put-call parity `bsP = bsV − S + K · e^{-rτ}`. -/ +lemma hasDerivAt_bsP_K {S r σ : ℝ} (hS : 0 < S) (hσ : 0 < σ) + {K τ : ℝ} (hK : 0 < K) (hτ : 0 < τ) : + HasDerivAt (fun k ↦ bsP k r σ S τ) + (Real.exp (-(r * τ)) * Phi (-bsd2 S K r σ τ)) K := by + have h_eq : (fun k : ℝ ↦ bsP k r σ S τ) = + fun k ↦ bsV k r σ S τ - S + k * Real.exp (-(r * τ)) := by + funext k; rw [bsP_eq_bsV k r σ S τ] + rw [h_eq] + have h_V := hasDerivAt_bsV_K (S := S) (r := r) (σ := σ) hS hσ hK hτ + have h_const : HasDerivAt (fun _ : ℝ ↦ S) 0 K := hasDerivAt_const K S + have h_lin : HasDerivAt (fun k : ℝ ↦ k * Real.exp (-(r * τ))) + (Real.exp (-(r * τ))) K := by + have := (hasDerivAt_id K).mul_const (Real.exp (-(r * τ))) + simpa using this + have h := (h_V.sub h_const).add h_lin + -- Adapt h's function and value to match the goal + have h_Phi := Phi_neg (bsd2 S K r σ τ) + -- Step 1: fix the function (regrouped form), keeping the same value + have h1 := h.congr_of_eventuallyEq (f₁ := fun k ↦ bsV k r σ S τ - S + k * Real.exp (-(r * τ))) + (Filter.Eventually.of_forall fun k ↦ by simp only [Pi.add_apply, Pi.sub_apply]) + -- Step 2: fix the value: -(exp*Φ(d2)) - 0 + exp = exp*Φ(-d2) + have hval : -(Real.exp (-(r * τ)) * Phi (bsd2 S K r σ τ)) - 0 + Real.exp (-(r * τ)) + = Real.exp (-(r * τ)) * Phi (-bsd2 S K r σ τ) := by + have : Real.exp (-(r * τ)) * Phi (-bsd2 S K r σ τ) = + Real.exp (-(r * τ)) * (1 - Phi (bsd2 S K r σ τ)) := by rw [h_Phi] + linarith [mul_comm (Real.exp (-(r * τ))) (Phi (bsd2 S K r σ τ))] + exact hval ▸ h1 + +/-- **Strike derivative of the cash-or-nothing digital**: `∂_K (e^{-rτ} Φ(d₂)) = +−e^{-rτ} · ϕ(d₂) / (K σ √τ)`, minus `e^{-rτ}` times the lognormal density formula +`lognormalTerminalPDF` at `K` (`BreedenLitzenberger.lean`). The digital is minus the strike +derivative of the call price (`hasDerivAt_bsV_K`), so this is minus the second strike derivative of +the call, and `≤ 0` by the convexity in `K` (`bsV_strike_convexOn`, proved from the payoff). -/ +lemma hasDerivAt_bsCashDigital_K {S r σ : ℝ} (hS : 0 < S) (hσ : 0 < σ) + {K τ : ℝ} (hK : 0 < K) (hτ : 0 < τ) : + HasDerivAt (fun k ↦ bsCashDigital k r σ S τ) + (-(Real.exp (-(r * τ)) * gaussianPDFReal 0 1 (bsd2 S K r σ τ) / + (K * σ * Real.sqrt τ))) K := + (((hasDerivAt_Phi (bsd2 S K r σ τ)).comp K (hasDerivAt_bsd2_K S r σ τ hS hσ hτ hK)).const_mul + (Real.exp (-(r * τ)))).congr_deriv (by ring) + +/-- **Second strike-derivative of the call**: `∂²C/∂K² = e^{-rτ} · ϕ(d₂) / (K σ √τ)`, for the +price itself: `∂_K bsV` is minus the digital on all of `K > 0` (`hasDerivAt_bsV_K`), and the +digital's strike derivative is `hasDerivAt_bsCashDigital_K`. -/ +theorem hasDerivAt_deriv_bsV_K {S r σ : ℝ} (hS : 0 < S) (hσ : 0 < σ) + {K τ : ℝ} (hK : 0 < K) (hτ : 0 < τ) : + HasDerivAt (deriv fun k ↦ bsV k r σ S τ) + (Real.exp (-(r * τ)) * gaussianPDFReal 0 1 (bsd2 S K r σ τ) / (K * σ * Real.sqrt τ)) K := + hasDerivAt_deriv_of_eventually + ((eventually_gt_nhds hK).mono fun _ hk ↦ hasDerivAt_bsV_K hS hσ hk hτ) + ((hasDerivAt_bsCashDigital_K (r := r) hS hσ hK hτ).fun_neg.congr_deriv (neg_neg _)) + +end MathFin diff --git a/LeanPool/MathFin/Models/BlackScholes/StulzTwoAssetRainbow.lean b/LeanPool/MathFin/Models/BlackScholes/StulzTwoAssetRainbow.lean new file mode 100644 index 0000000000..7439889c59 --- /dev/null +++ b/LeanPool/MathFin/Models/BlackScholes/StulzTwoAssetRainbow.lean @@ -0,0 +1,372 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.ExchangeOption +public import LeanPool.MathFin.Models.BlackScholes.MargrabeGrounding +public import LeanPool.MathFin.Probability.Gaussian.BivariateNormalCDF +public import Mathlib.Algebra.Order.Star.Real + +/-! +# Stulz (1982): the two-asset rainbow (max/min) closed form + +R. M. Stulz ("Options on the minimum or the maximum of two risky assets: analysis and +applications", *Journal of Financial Economics* 10 (1982), 161–185) prices a call on +`max(S¹_T, S²_T)` or `min(S¹_T, S²_T)` struck at `K` by a pair of bivariate-normal-CDF closed +forms. This module transcribes those closed forms; that they are the discounted expected payoffs +is Stulz's theorem and is not proved here (see **Scope**). Unlike `BasketMomentMatching.lean`'s +`n`-asset moment-matching approximation, Stulz's formula is exact, but only for `n = 2`. + +The formulas are those of E. G. Haug, *The Complete Guide to Option Pricing Formulas*, 2nd ed., +McGraw-Hill (2007), in the cost-of-carry convention `bᵢ` (`bᵢ = r` for a non-dividend asset, +`bᵢ = r - qᵢ` under a continuous yield `qᵢ`, `bᵢ = 0` for a futures-style asset). With + + `v = √(σ₁² + σ₂² − 2ρσ₁σ₂)` (`stulzEffVol`, the Margrabe spread vol) + `ρ₁ = (σ₁ − ρσ₂) / v`, `ρ₂ = (σ₂ − ρσ₁) / v` (`stulzRho1`, `stulzRho2`) + `yᵢ = (log(Sᵢ/K) + (bᵢ + σᵢ²/2)T) / (σᵢ√T)` (`stulzY1`, `stulzY2`) + `d = (log(S¹/S²) + (b₁ − b₂ + v²/2)T) / (v√T)` (`stulzD`) + +the call-on-the-max and call-on-the-min prices are + + `C_max = S¹e^{(b₁−r)T} N₂(y₁, d; ρ₁) + S²e^{(b₂−r)T} N₂(y₂, −d+v√T; ρ₂)` + `− Ke^{−rT}(1 − N₂(−y₁+σ₁√T, −y₂+σ₂√T; ρ))`, + `C_min = S¹e^{(b₁−r)T} N₂(y₁, −d; −ρ₁) + S²e^{(b₂−r)T} N₂(y₂, d−v√T; −ρ₂)` + `− Ke^{−rT} N₂(y₁−σ₁√T, y₂−σ₂√T; ρ)`. + +## Main definitions + +* `stulzEffVol`: the spread volatility `√(σ₁² + σ₂² - 2ρσ₁σ₂)`. +* `stulzRho1`, `stulzRho2`: the correlations `(σ₁ - ρσ₂)/v` and `(σ₂ - ρσ₁)/v` of each log-asset + with the log-spread. +* `stulzY1`, `stulzY2`: the Black-Scholes `d₁` of each asset against strike `K` at its + cost-of-carry. +* `stulzD`: the Margrabe-style `d₁` of the ratio `S¹/S²` at the spread volatility. +* `stulzCallMax`, `stulzCallMin`: the closed forms of Stulz (1982), as transcribed by Haug, for + calls on the maximum and the minimum of two assets. That they equal discounted expected + payoffs is not proved here. + +## Main results + +* `stulzRho1_sq_le_one`, `stulzRho2_sq_le_one`: `ρ₁, ρ₂` are genuine correlations (`ρᵢ² ≤ 1`) + whenever `ρ² ≤ 1` — an algebraic fact, unconditional on `v ≠ 0` (Lean's `0/0 = 0` convention + makes the degenerate `v = 0` case trivially satisfy it too). +* `stulz_max_min_payoff_parity`: the **payoff-level** identity behind Stulz's whole + construction, `max(max(a,b)−K,0) + max(min(a,b)−K,0) = max(a−K,0) + max(b−K,0)` — pure + algebra, no probability. +* `stulzCallMax_add_stulzCallMin`: the matching **price-level** identity, for `S¹, S², K > 0` + and `ρ² ≤ 1`: `C_max + C_min` equals the sum of two *ordinary* one-asset Black-Scholes calls + on `S¹` and `S²` (`bsVGarman`, `GarmanNormalForm.lean`). It is the price-level counterpart of + the payoff identity, but it is not derived from it: the proof consumes only + `bivariateNormalCDF_flip_snd` / `bivariateNormalCDF_neg_neg`, the two general bivariate-CDF + identities of `BivariateNormalCDF.lean`, with no separate probabilistic derivation. + +* `stulzD_eq_margrabeD1`: at equal costs of carry, Stulz's ratio argument `d` is Margrabe's + `d₁` at the spread volatility `v` (`ExchangeOption.lean`). +* `tendsto_stulzCallMax_zero_strike`: as the strike `K ↓ 0`, with `b₁ = b₂ = r`, the + call-on-the-max closed form tends to `S² + margrabePrice S¹ S² v T`, the closed-form price + of the better-of-two payoff `max(S¹_T, S²_T) = S²_T + max(S¹_T − S²_T, 0)`. The strike + terms `y₁, y₂ → ∞` and each `N₂(yᵢ, ·; ρᵢ)` tends to its second margin + (`tendsto_bivariateNormalCDF_atTop_fst`). This checks `stulzD` and `stulzEffVol` against + Margrabe's formula, which the parity identity below does not; it does not check `ρ₁`, `ρ₂`, + which drop out in the limit. +* `tendsto_stulzCallMax_zero_strike_betterOfTwo`: in the two-GBM model of + `MargrabeGrounding.lean`, that limit is the discounted expected better-of-two payoff + `𝔼_P[e^{−rT}max(S¹_T, S²_T)]` (`integral_betterOfTwo`). Stulz's formula itself, for `K > 0`, + is still not derived as an expected payoff. + +**Scope.** `stulzCallMax_add_stulzCallMin` is a partial consistency check on the closed forms. +Its proof uses only `ρ₁² ≤ 1` and `ρ₂² ≤ 1`, so it holds for any values of `d`, `v`, `ρ₁`, `ρ₂` +with those bounds: it checks the strike term, `y₁`, `y₂` and that `C_min`'s arguments are the +sign flips of `C_max`'s, but not `stulzD`, `stulzEffVol`, `stulzRho1` or `stulzRho2`. It is +not a from-first-principles derivation from a joint two-GBM model — the same scope +as `GarmanNormalForm.lean`'s own specializations, which take the one-asset BS closed form as +given rather than re-deriving it from Girsanov. Deriving `C_max` itself from a bivariate +lognormal expectation is a separate, harder project (the two-asset analogue of +`MargrabeGrounding.lean`). + +## References + +* [R. M. Stulz, *Options on the minimum or the maximum of two risky assets: analysis and + applications*][Stulz1982] + +## Tags + +rainbow option, Stulz formula, call on maximum, call on minimum, bivariate normal, Margrabe, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- **Effective spread volatility** `v = √(σ₁² + σ₂² − 2ρσ₁σ₂)` — the same quantity as the +Margrabe effective vol (the square root of `margrabe_effective_variance`'s log-spread variance +divided by `T`). -/ +noncomputable def stulzEffVol (σ1 σ2 ρ : ℝ) : ℝ := + √(σ1 ^ 2 + σ2 ^ 2 - 2 * ρ * σ1 * σ2) + +/-- **Correlation of `Y₁ = log S¹` with the log-spread**: `ρ₁ = (σ₁ − ρσ₂) / v`. -/ +noncomputable def stulzRho1 (σ1 σ2 ρ : ℝ) : ℝ := + (σ1 - ρ * σ2) / stulzEffVol σ1 σ2 ρ + +/-- **Correlation of `Y₂ = log S²` with the log-spread**: `ρ₂ = (σ₂ − ρσ₁) / v`. -/ +noncomputable def stulzRho2 (σ1 σ2 ρ : ℝ) : ℝ := + (σ2 - ρ * σ1) / stulzEffVol σ1 σ2 ρ + +/-- **`y₁`**: the standard BS `d₁` of asset 1 against strike `K` at cost-of-carry `b₁`. -/ +noncomputable def stulzY1 (S1 K b1 σ1 T : ℝ) : ℝ := + (Real.log (S1 / K) + (b1 + σ1 ^ 2 / 2) * T) / (σ1 * Real.sqrt T) + +/-- **`y₂`**: the standard BS `d₁` of asset 2 against strike `K` at cost-of-carry `b₂`. -/ +noncomputable def stulzY2 (S2 K b2 σ2 T : ℝ) : ℝ := + (Real.log (S2 / K) + (b2 + σ2 ^ 2 / 2) * T) / (σ2 * Real.sqrt T) + +/-- **`d`**: the Margrabe-style `d₁` of the ratio `S¹/S²` at the effective spread vol `v`. -/ +noncomputable def stulzD (S1 S2 b1 b2 σ1 σ2 ρ T : ℝ) : ℝ := + (Real.log (S1 / S2) + (b1 - b2 + stulzEffVol σ1 σ2 ρ ^ 2 / 2) * T) / + (stulzEffVol σ1 σ2 ρ * Real.sqrt T) + +/-- **Stulz's closed form for a call on the maximum of two assets**, struck at `K` — the +textbook interpretation is `𝔼[e^{−rT}max(max(S¹_T,S²_T)−K,0)]`, but that expectation identity is +not proved here (see the module docstring's "Scope" note); this `def` is only the closed-form +formula itself. -/ +noncomputable def stulzCallMax (S1 S2 K r b1 b2 σ1 σ2 ρ T : ℝ) : ℝ := + let v := stulzEffVol σ1 σ2 ρ + let ρ1 := stulzRho1 σ1 σ2 ρ + let ρ2 := stulzRho2 σ1 σ2 ρ + let y1 := stulzY1 S1 K b1 σ1 T + let y2 := stulzY2 S2 K b2 σ2 T + let d := stulzD S1 S2 b1 b2 σ1 σ2 ρ T + S1 * Real.exp ((b1 - r) * T) * bivariateNormalCDF y1 d ρ1 + + S2 * Real.exp ((b2 - r) * T) * bivariateNormalCDF y2 (-d + v * Real.sqrt T) ρ2 - + K * Real.exp (-(r * T)) * + (1 - bivariateNormalCDF (-y1 + σ1 * Real.sqrt T) (-y2 + σ2 * Real.sqrt T) ρ) + +/-- **Stulz's closed form for a call on the minimum of two assets**, struck at `K` — the +textbook interpretation is `𝔼[e^{−rT}max(min(S¹_T,S²_T)−K,0)]`, but that expectation identity is +not proved here (see the module docstring's "Scope" note); this `def` is only the closed-form +formula itself. -/ +noncomputable def stulzCallMin (S1 S2 K r b1 b2 σ1 σ2 ρ T : ℝ) : ℝ := + let v := stulzEffVol σ1 σ2 ρ + let ρ1 := stulzRho1 σ1 σ2 ρ + let ρ2 := stulzRho2 σ1 σ2 ρ + let y1 := stulzY1 S1 K b1 σ1 T + let y2 := stulzY2 S2 K b2 σ2 T + let d := stulzD S1 S2 b1 b2 σ1 σ2 ρ T + S1 * Real.exp ((b1 - r) * T) * bivariateNormalCDF y1 (-d) (-ρ1) + + S2 * Real.exp ((b2 - r) * T) * bivariateNormalCDF y2 (d - v * Real.sqrt T) (-ρ2) - + K * Real.exp (-(r * T)) * + bivariateNormalCDF (y1 - σ1 * Real.sqrt T) (y2 - σ2 * Real.sqrt T) ρ + +/-! ## `ρ₁`, `ρ₂` are genuine correlations -/ + +/-- **`ρ₁` is a genuine correlation**: `ρ₁² ≤ 1` whenever `ρ² ≤ 1`. Unconditional on +`v = stulzEffVol σ1 σ2 ρ ≠ 0`: at `v = 0`, `ρ1 = (σ1 - ρσ2) / 0 = 0` by Lean's division +convention, and `0 ≤ 1` trivially. -/ +theorem stulzRho1_sq_le_one (σ1 σ2 ρ : ℝ) (hρ : ρ ^ 2 ≤ 1) : stulzRho1 σ1 σ2 ρ ^ 2 ≤ 1 := by + unfold stulzRho1 stulzEffVol + have hnonneg : 0 ≤ σ1 ^ 2 + σ2 ^ 2 - 2 * ρ * σ1 * σ2 := by + nlinarith [sq_nonneg (σ1 - ρ * σ2), mul_nonneg (sq_nonneg σ2) (sub_nonneg.2 hρ)] + rcases hnonneg.lt_or_eq with hpos | heq + · rw [div_pow, Real.sq_sqrt hpos.le, div_le_one hpos] + nlinarith [mul_nonneg (sq_nonneg σ2) (sub_nonneg.2 hρ)] + · rw [← heq, Real.sqrt_zero, div_zero] + norm_num + +/-- **`ρ₂` is a genuine correlation**: `ρ₂² ≤ 1` whenever `ρ² ≤ 1`, by the same argument as +`stulzRho1_sq_le_one` with `σ1, σ2` exchanged. -/ +theorem stulzRho2_sq_le_one (σ1 σ2 ρ : ℝ) (hρ : ρ ^ 2 ≤ 1) : stulzRho2 σ1 σ2 ρ ^ 2 ≤ 1 := by + have h := stulzRho1_sq_le_one σ2 σ1 ρ hρ + unfold stulzRho1 stulzEffVol at h + unfold stulzRho2 stulzEffVol + rwa [show σ2 ^ 2 + σ1 ^ 2 - 2 * ρ * σ2 * σ1 = σ1 ^ 2 + σ2 ^ 2 - 2 * ρ * σ1 * σ2 from by ring] + at h + +/-! ## The payoff-level parity -/ + +/-- **The payoff identity behind Stulz's construction**: a call on the max plus a call on the +min, both struck at `K`, pays exactly what a plain call on `a` plus a plain call on `b` pays. +Pure algebra — `rcases le_total a b` collapses `max`/`min` on each side identically. -/ +theorem stulz_max_min_payoff_parity (a b K : ℝ) : + max (max a b - K) 0 + max (min a b - K) 0 = max (a - K) 0 + max (b - K) 0 := by + rcases le_total a b with h | h + · rw [max_eq_right h, min_eq_left h]; ring + · rw [max_eq_left h, min_eq_right h] + +/-! ## The price-level parity -/ + +/-- **Log-algebra bridge**: `stulzY1` matches `GarmanNormalForm`'s `gbsd1` at the cost-of-carry +parameters `A = S¹e^{(b₁−r)T}`, `DF = e^{−rT}`. Reuses `log_SexpNegQ_div_KexpNegR` (with +`q = r − b₁`, since `e^{(b₁-r)T} = e^{-((r-b₁)T)}`) rather than re-deriving the log algebra. -/ +private lemma stulzY1_eq_gbsd1 (S1 K b1 σ1 T r : ℝ) (hS1 : 0 < S1) (hK : 0 < K) : + stulzY1 S1 K b1 σ1 T = + gbsd1 (S1 * Real.exp ((b1 - r) * T)) K (Real.exp (-(r * T))) σ1 T := by + unfold stulzY1 gbsd1 + congr 1 + rw [show S1 * Real.exp ((b1 - r) * T) = S1 * Real.exp (-((r - b1) * T)) from by ring_nf, + log_SexpNegQ_div_KexpNegR S1 K r (r - b1) T hS1 hK] + ring + +/-- **Log-algebra bridge** for `stulzY2`, symmetric to `stulzY1_eq_gbsd1`. -/ +private lemma stulzY2_eq_gbsd1 (S2 K b2 σ2 T r : ℝ) (hS2 : 0 < S2) (hK : 0 < K) : + stulzY2 S2 K b2 σ2 T = + gbsd1 (S2 * Real.exp ((b2 - r) * T)) K (Real.exp (-(r * T))) σ2 T := by + unfold stulzY2 gbsd1 + congr 1 + rw [show S2 * Real.exp ((b2 - r) * T) = S2 * Real.exp (-((r - b2) * T)) from by ring_nf, + log_SexpNegQ_div_KexpNegR S2 K r (r - b2) T hS2 hK] + ring + +/-- **The price-level parity**: for `S¹, S², K > 0` and `ρ² ≤ 1`, `C_max + C_min` equals the +sum of two one-asset `bsVGarman` calls on `S¹` and `S²` at strike `K`, discount factor +`e^{−rT}`. The proof pairs each `N₂` term of `C_max` with its counterpart in `C_min` via +`bivariateNormalCDF_flip_snd` (asset terms) and `bivariateNormalCDF_neg_neg` (the strike term). +It is the price-level counterpart of `stulz_max_min_payoff_parity`, proved from the N₂ +identities, not from the payoff lemma. It uses only `ρ₁², ρ₂² ≤ 1` of `d`, `v`, `ρ₁`, `ρ₂`, so +it does not check `stulzD`, `stulzEffVol`, `stulzRho1` or `stulzRho2`. -/ +theorem stulzCallMax_add_stulzCallMin (S1 S2 K r b1 b2 σ1 σ2 T : ℝ) {ρ : ℝ} (hρ : ρ ^ 2 ≤ 1) + (hS1 : 0 < S1) (hS2 : 0 < S2) (hK : 0 < K) : + stulzCallMax S1 S2 K r b1 b2 σ1 σ2 ρ T + stulzCallMin S1 S2 K r b1 b2 σ1 σ2 ρ T = + bsVGarman (S1 * Real.exp ((b1 - r) * T)) K (Real.exp (-(r * T))) σ1 T + + bsVGarman (S2 * Real.exp ((b2 - r) * T)) K (Real.exp (-(r * T))) σ2 T := by + have hρ1sq := stulzRho1_sq_le_one σ1 σ2 ρ hρ + have hρ2sq := stulzRho2_sq_le_one σ1 σ2 ρ hρ + -- Abbreviations matching the `let`-bindings inside `stulzCallMax`/`stulzCallMin`. + set v := stulzEffVol σ1 σ2 ρ + set ρ1 := stulzRho1 σ1 σ2 ρ + set ρ2 := stulzRho2 σ1 σ2 ρ + set y1 := stulzY1 S1 K b1 σ1 T + set y2 := stulzY2 S2 K b2 σ2 T + set d := stulzD S1 S2 b1 b2 σ1 σ2 ρ T + -- The three bivariate-CDF identities that collapse `C_max + C_min` term by term. + have hasset1 : bivariateNormalCDF y1 d ρ1 + bivariateNormalCDF y1 (-d) (-ρ1) = Phi y1 := + bivariateNormalCDF_flip_snd y1 d hρ1sq + have hasset2 : bivariateNormalCDF y2 (-d + v * Real.sqrt T) ρ2 + + bivariateNormalCDF y2 (d - v * Real.sqrt T) (-ρ2) = Phi y2 := by + have h2 := bivariateNormalCDF_flip_snd y2 (-d + v * Real.sqrt T) hρ2sq + rwa [show -(-d + v * Real.sqrt T) = d - v * Real.sqrt T from by ring] at h2 + have hstrike : (1 - bivariateNormalCDF (-y1 + σ1 * Real.sqrt T) (-y2 + σ2 * Real.sqrt T) ρ) + + bivariateNormalCDF (y1 - σ1 * Real.sqrt T) (y2 - σ2 * Real.sqrt T) ρ = + Phi (y1 - σ1 * Real.sqrt T) + Phi (y2 - σ2 * Real.sqrt T) := by + have hnn := bivariateNormalCDF_neg_neg (y1 - σ1 * Real.sqrt T) (y2 - σ2 * Real.sqrt T) hρ + rw [show -(y1 - σ1 * Real.sqrt T) = -y1 + σ1 * Real.sqrt T from by ring, + show -(y2 - σ2 * Real.sqrt T) = -y2 + σ2 * Real.sqrt T from by ring] at hnn + linarith + -- The `gbsd1` bridge, so `bsVGarman`'s own `d₁` matches `y1`/`y2` exactly. + have hgbsd1 : gbsd1 (S1 * Real.exp ((b1 - r) * T)) K (Real.exp (-(r * T))) σ1 T = y1 := + (stulzY1_eq_gbsd1 S1 K b1 σ1 T r hS1 hK).symm + have hgbsd2 : gbsd1 (S2 * Real.exp ((b2 - r) * T)) K (Real.exp (-(r * T))) σ2 T = y2 := + (stulzY2_eq_gbsd1 S2 K b2 σ2 T r hS2 hK).symm + simp only [stulzCallMax, stulzCallMin, bsVGarman, gbsd2, hgbsd1, hgbsd2] + linear_combination (S1 * Real.exp ((b1 - r) * T)) * hasset1 + + (S2 * Real.exp ((b2 - r) * T)) * hasset2 - (K * Real.exp (-(r * T))) * hstrike + +/-! ## Zero strike: the better-of-two option through Margrabe -/ + +/-- **Stulz's `d` is Margrabe's `d₁`** at equal costs of carry `b₁ = b₂`, with the spread +volatility `v = stulzEffVol σ₁ σ₂ ρ`. -/ +lemma stulzD_eq_margrabeD1 (S1 S2 b σ1 σ2 ρ T : ℝ) : + stulzD S1 S2 b b σ1 σ2 ρ T = margrabeD1 S1 S2 (stulzEffVol σ1 σ2 ρ) T := by + unfold stulzD margrabeD1 + congr 1 + ring + +open Filter Topology in +/-- As the strike falls to `0`, `y₁ → +∞`: `log(S₁/K) → +∞`. -/ +lemma tendsto_stulzY1_zero_strike {S1 b1 σ1 T : ℝ} (hS1 : 0 < S1) (hσ1 : 0 < σ1) (hT : 0 < T) : + Tendsto (fun K ↦ stulzY1 S1 K b1 σ1 T) (𝓝[>] 0) atTop := by + have hlog : Tendsto (fun K ↦ Real.log (S1 / K)) (𝓝[>] 0) atTop := by + refine (tendsto_atTop_add_const_left _ (Real.log S1) + (tendsto_neg_atBot_atTop.comp Real.tendsto_log_nhdsGT_zero)).congr' ?_ + filter_upwards [self_mem_nhdsWithin] with K hK + rw [Function.comp_apply, Real.log_div hS1.ne' (Set.mem_Ioi.mp hK).ne', sub_eq_add_neg] + change Tendsto (fun K ↦ (Real.log (S1 / K) + (b1 + σ1 ^ 2 / 2) * T) / (σ1 * Real.sqrt T)) _ _ + exact (tendsto_atTop_add_const_right _ _ hlog).atTop_div_const + (mul_pos hσ1 (Real.sqrt_pos.mpr hT)) + +open Filter Topology in +/-- As the strike falls to `0`, `y₂ → +∞` (`y₂` has the shape of `y₁`). -/ +lemma tendsto_stulzY2_zero_strike {S2 b2 σ2 T : ℝ} (hS2 : 0 < S2) (hσ2 : 0 < σ2) (hT : 0 < T) : + Tendsto (fun K ↦ stulzY2 S2 K b2 σ2 T) (𝓝[>] 0) atTop := + tendsto_stulzY1_zero_strike (b1 := b2) hS2 hσ2 hT + +open Filter Topology in +/-- **Stulz's call on the maximum at zero strike is the better-of-two price.** With equal +costs of carry `b₁ = b₂ = r`, as `K ↓ 0` the closed form `stulzCallMax` tends to +`S² + margrabePrice S¹ S² v T`, `v = stulzEffVol σ₁ σ₂ ρ`: the closed-form price of +`max(S¹_T, S²_T) = S²_T + max(S¹_T − S²_T, 0)` (Margrabe's exchange option plus one unit of +`S²`). This is a statement about the closed forms; neither is derived here as an expected +payoff. -/ +theorem tendsto_stulzCallMax_zero_strike {S1 S2 r σ1 σ2 ρ T : ℝ} (hS1 : 0 < S1) (hS2 : 0 < S2) + (hσ1 : 0 < σ1) (hσ2 : 0 < σ2) (hT : 0 < T) : + Tendsto (fun K ↦ stulzCallMax S1 S2 K r r r σ1 σ2 ρ T) (𝓝[>] 0) + (𝓝 (S2 + margrabePrice S1 S2 (stulzEffVol σ1 σ2 ρ) T)) := by + -- the two asset terms: `N₂(yᵢ, ·; ρᵢ)` tends to its second margin as `yᵢ → ∞` + have h1 : Tendsto (fun K ↦ S1 * bivariateNormalCDF (stulzY1 S1 K r σ1 T) + (margrabeD1 S1 S2 (stulzEffVol σ1 σ2 ρ) T) (stulzRho1 σ1 σ2 ρ)) (𝓝[>] 0) + (𝓝 (S1 * Phi (margrabeD1 S1 S2 (stulzEffVol σ1 σ2 ρ) T))) := + ((tendsto_bivariateNormalCDF_atTop_fst _ _).comp + (tendsto_stulzY1_zero_strike hS1 hσ1 hT)).const_mul S1 + have h2 : Tendsto (fun K ↦ S2 * bivariateNormalCDF (stulzY2 S2 K r σ2 T) + (-margrabeD1 S1 S2 (stulzEffVol σ1 σ2 ρ) T + stulzEffVol σ1 σ2 ρ * Real.sqrt T) + (stulzRho2 σ1 σ2 ρ)) (𝓝[>] 0) + (𝓝 (S2 * Phi (-margrabeD1 S1 S2 (stulzEffVol σ1 σ2 ρ) T + + stulzEffVol σ1 σ2 ρ * Real.sqrt T))) := + ((tendsto_bivariateNormalCDF_atTop_fst _ _).comp + (tendsto_stulzY2_zero_strike hS2 hσ2 hT)).const_mul S2 + -- the strike term vanishes: `K e^{−rT}` times a number in `[0, 1]` + have hKe : Tendsto (fun K : ℝ ↦ K * Real.exp (-(r * T))) (𝓝[>] 0) (𝓝 0) := by + simpa using (tendsto_nhdsWithin_of_tendsto_nhds (s := Set.Ioi 0) + (tendsto_id : Tendsto id (𝓝 (0 : ℝ)) (𝓝 0))).mul_const (Real.exp (-(r * T))) + have h3 : Tendsto (fun K ↦ K * Real.exp (-(r * T)) * + (1 - bivariateNormalCDF (-stulzY1 S1 K r σ1 T + σ1 * Real.sqrt T) + (-stulzY2 S2 K r σ2 T + σ2 * Real.sqrt T) ρ)) (𝓝[>] 0) (𝓝 0) := by + refine squeeze_zero_norm' ?_ hKe + filter_upwards [self_mem_nhdsWithin] with K hK + have hK0 : 0 < K * Real.exp (-(r * T)) := mul_pos (Set.mem_Ioi.mp hK) (Real.exp_pos _) + have hN0 : 0 ≤ bivariateNormalCDF (-stulzY1 S1 K r σ1 T + σ1 * Real.sqrt T) + (-stulzY2 S2 K r σ2 T + σ2 * Real.sqrt T) ρ := MeasureTheory.measureReal_nonneg + have hN1 : bivariateNormalCDF (-stulzY1 S1 K r σ1 T + σ1 * Real.sqrt T) + (-stulzY2 S2 K r σ2 T + σ2 * Real.sqrt T) ρ ≤ 1 := MeasureTheory.measureReal_le_one + rw [Real.norm_eq_abs, abs_mul, abs_of_pos hK0, abs_of_nonneg (sub_nonneg.mpr hN1)] + exact mul_le_of_le_one_right hK0.le (sub_le_self _ hN0) + -- the limit `S¹Φ(d₁) + S²Φ(−d₁ + v√T)` is `S² + Margrabe`, since `−d₁ + v√T = −d₂` + have hlim : S1 * Phi (margrabeD1 S1 S2 (stulzEffVol σ1 σ2 ρ) T) + + S2 * Phi (-margrabeD1 S1 S2 (stulzEffVol σ1 σ2 ρ) T + stulzEffVol σ1 σ2 ρ * Real.sqrt T) + - 0 = S2 + margrabePrice S1 S2 (stulzEffVol σ1 σ2 ρ) T := by + rw [show -margrabeD1 S1 S2 (stulzEffVol σ1 σ2 ρ) T + stulzEffVol σ1 σ2 ρ * Real.sqrt T + = -margrabeD2 S1 S2 (stulzEffVol σ1 σ2 ρ) T by rw [margrabeD2]; ring, Phi_neg] + unfold margrabePrice + ring + rw [← hlim] + refine ((h1.add h2).sub h3).congr fun K ↦ ?_ + simp only [stulzCallMax, stulzD_eq_margrabeD1, sub_self, zero_mul, Real.exp_zero, mul_one] + +open Filter Topology MeasureTheory ProbabilityTheory in +/-- **Stulz's call on the maximum at zero strike is the expected better-of-two payoff.** For +two Black–Scholes terminals driven by a jointly Gaussian pair of standard normals with +covariance `ρ` and a non-degenerate spread variance, the closed form `stulzCallMax` with +`b₁ = b₂ = r` tends, as `K ↓ 0`, to `𝔼_P[e^{−rT}·max(S¹_T, S²_T)]` +(`tendsto_stulzCallMax_zero_strike` and `integral_betterOfTwo`). -/ +theorem tendsto_stulzCallMax_zero_strike_betterOfTwo {Ω : Type*} {mΩ : MeasurableSpace Ω} + {P : Measure Ω} [IsProbabilityMeasure P] {W₁ W₂ : Ω → ℝ} {S1 S2 r σ1 σ2 ρ T : ℝ} + (hjoint : HasGaussianLaw (fun ω ↦ (W₁ ω, W₂ ω)) P) + (hW₁meas : Measurable W₁) (hW₂meas : Measurable W₂) + (hW₁ : HasLaw W₁ (gaussianReal 0 1) P) (hW₂ : HasLaw W₂ (gaussianReal 0 1) P) + (hcov : cov[W₁, W₂; P] = ρ) (hS1 : 0 < S1) (hS2 : 0 < S2) (hσ1 : 0 < σ1) (hσ2 : 0 < σ2) + (hT : 0 < T) (hv : 0 < σ1 ^ 2 + σ2 ^ 2 - 2 * ρ * σ1 * σ2) : + Tendsto (fun K ↦ stulzCallMax S1 S2 K r r r σ1 σ2 ρ T) (𝓝[>] 0) + (𝓝 (∫ ω, Real.exp (-(r * T)) * + max (bsTerminal S1 r σ1 T (W₁ ω)) (bsTerminal S2 r σ2 T (W₂ ω)) ∂P)) := by + rw [integral_betterOfTwo hjoint hW₁meas hW₂meas hW₁ hW₂ hcov hS1 hS2 hσ2 + (Real.sqrt_pos.mpr hv) hT (Real.sq_sqrt hv.le)] + exact tendsto_stulzCallMax_zero_strike hS1 hS2 hσ1 hσ2 hT + +end MathFin diff --git a/LeanPool/MathFin/Models/Credit/CDSTimeVarying.lean b/LeanPool/MathFin/Models/Credit/CDSTimeVarying.lean new file mode 100644 index 0000000000..db54fc78fb --- /dev/null +++ b/LeanPool/MathFin/Models/Credit/CDSTimeVarying.lean @@ -0,0 +1,95 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.Complex.Exponential + +/-! +# CDS fair spread under time-varying hazard (first-principles) + +The pre-existing `Models/Credit/Credit.lean` derives the CDS fair spread +`c = h · (1 − R)` for *constant* hazard `h` via the `cds_leg_equality` +identity. The annuity factor cancels because both legs share it. + +This file extends to *time-varying* hazard `h : ℝ → ℝ`. The cash-flow +balance is + + `c · annuity(T) = (1 − R) · losses(T)`, + +where (with constant recovery `R` for simplicity) + + `annuity(T) = ∫_0^T S(s) · e^{−rs} ds`, + `losses(T) = ∫_0^T h(s) · S(s) · e^{−rs} ds`, + +and `S(s) = exp(−∫_0^s h(u) du)` is the survival from `HazardCurve.lean`. +Under no arbitrage, the fair spread is `c* = (1 − R) · losses(T) / +annuity(T)`. No integral is evaluated — the balance is stated at the cash- +flow level. + +The discrete piecewise-constant survival decomposition (multi-period +survival = exp of sum of hazard × duration) is a direct application of +`Real.exp_sum` and is recorded as `survival_product_eq_exp_sum` for the +finance-side narrative. + +## Why this is "first principles" + +The existing constant-hazard derivation specialises to a single rate `h` +for all time; this file gives the general cash-flow balance that holds for +any deterministic hazard curve. + +## Main results + +* `cdsFairSpread_TV_cash_flow_balance`: for a nonzero annuity, the balance equation + `c · annuity = (1 − R) · losses` solved for the spread; the hazard enters only through the two + legs (`Cox.cdsFairSpreadTV_balances` is the Cox-model instance). +* `survival_product_eq_exp_sum`: multi-period survival factorisation, + i.e. `∏ exp(−h_i Δt_i) = exp(−∑ h_i Δt_i)` (a direct `Real.exp_sum` + application stated in finance variables). + +## Tags + +credit default swap, CDS spread, hazard rate, protection leg, premium leg, fair spread, +survival probability, MSC 91G40, JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +open Real Finset + +/-- **CDS time-varying fair-spread cash-flow balance**. With time-varying +hazard `h : ℝ → ℝ`, constant recovery `R`, and discount rate `r`, the +premium leg (spread `c` collected per unit notional, weighted by survival +and discount) balances the protection leg (`1 − R` paid at default, +weighted by default density `h(s) · S(s)` and discount) iff + + `c · annuity(T) = (1 − R) · losses(T)`. + +For non-zero annuity, this is equivalent to the fair-spread formula +`c = (1 − R) · losses / annuity`. -/ +theorem cdsFairSpread_TV_cash_flow_balance + (c R annuity losses : ℝ) (h_annuity_ne : annuity ≠ 0) : + c * annuity = (1 - R) * losses ↔ c = (1 - R) * losses / annuity := by + rw [eq_div_iff h_annuity_ne] + +/-- **Multi-period survival from per-period hazards**: with hazard `h_i` on +period `i` of duration `Δt_i`, the cumulative survival is + + `∏_i exp(-h_i · Δt_i) = exp(-∑_i h_i · Δt_i)`. + +This is the discrete realisation of the continuous formula +`S(T) = exp(-∫_0^T h(u) du)` for step-constant `h`. -/ +theorem survival_product_eq_exp_sum (n : ℕ) (h Δt : Fin n → ℝ) : + (∏ i, Real.exp (-(h i * Δt i))) = Real.exp (-(∑ i, h i * Δt i)) := by + rw [← Real.exp_sum] + congr 1 + rw [Finset.sum_neg_distrib] + +end MathFin diff --git a/LeanPool/MathFin/Models/Credit/CVA.lean b/LeanPool/MathFin/Models/Credit/CVA.lean new file mode 100644 index 0000000000..09e4a21ffe --- /dev/null +++ b/LeanPool/MathFin/Models/Credit/CVA.lean @@ -0,0 +1,262 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Bachelier.Bachelier +public import LeanPool.MathFin.Models.Credit.DefaultDensity + +/-! +# CVA under independent exposure (no wrong-way risk) + +Hull, *Options, Futures, and Other Derivatives* (CVA, in its credit-risk chapter). With +exposure independent of the counterparty's default time, CVA is the CDS protection-leg +integral of Bagaria eq. 16.2 with the discount curve `P(0,·)` replaced by `D·EE`: + + `CVA = LGD · E[D(τ) · V_τ⁺ · 1{τ ≤ T}] = LGD · ∫₀ᵀ D(s) · EE(s) · λ(s) · Q(s) ds`, + +`EE(s) = E[V_s⁺]` the expected positive exposure. + +Independence uses the same two-factor product-space layout as `MathFin.Cox.cox_mixing_survival` +(`Models/Credit/Cox.lean`), though not its mixing construction: the exposure lives on +`(Ω₁, ν)`, the default time on `(Ω₂, μ)`, and the pricing measure is `ν.prod μ`, so τ is +independent of the exposure by the product measure itself, with no mixing against the first +factor's randomness. The Fubini step reduces the claim to the kernel +`MathFin.DefaultDensity.integral_indicator_Iic_eq` with discount curve `D · EE`. + +* `integral_exposure_eq` — the general reduction (joint integrability hypothesized). +* `expectedExposure_gaussian` — `E[(m + σ√s·Z)⁺] = m·Φ(m/(σ√s)) + σ√s·φ(m/(σ√s))` for + `σ, s > 0`, from `bachelier_call_formula` with the strike shifted to `K = 1`, `S₀ = m + 1`. +* `cva_gaussian` — headline: Gaussian exposure, bounded `D, m, σ`, `σ > 0`: CVA as a + one-dimensional time integral whose integrand (the expected exposure) is in closed form. +* `cva_one_eq_protectionLeg` — the CVA of a unit exposure discounted at a flat rate `r` is the CDS + protection leg `Cox.protectionLeg` (Bagaria eq. 16.2), for any default time whose CDF on + `[0, ∞)` is `1 − Q` (hypothesized, as above). +* `protectionLeg_eq_integral_coxDefaultTime` — for the Cox default time constructed in + `Models/Credit/Cox.lean` (a unit-exponential clock inverted through `∫₀ᵗ h`), the protection leg + is the expectation `(1 − R)·E[e^{−rτ}·1{τ ≤ T}]`; here the CDF is derived, not hypothesized. + +## Main definitions + +* `expectedExposure`: the expected positive exposure `EE(s) = E_ν[V_s⁺]`. +* `cva`: unilateral CVA on the product space, `LGD · E[1{τ ≤ T} · D(τ) · V_τ⁺]`, with the exposure + on the first factor and the default time on the second. + +## Main results + +* `integral_exposure_eq`: for exposure independent of a default time with continuous hazard + `h ≥ 0`, `E[1{τ ≤ T} D(τ) V_τ⁺] = ∫₀ᵀ D(s) · EE(s) · λ(s)Q(s) ds`, for measurable `D`, jointly + measurable `V`, `T ≥ 0` and a joint-integrability hypothesis. +* `expectedExposure_of_hasLaw_gaussianReal`: for `V_s ~ N(m, v)` with `v > 0`, + `EE(s) = m Φ(m/√v) + √v φ(m/√v)`, the same closed form read off the law. +* `expectedExposure_gaussian`: for `Z ~ N(0,1)` and `b, s > 0`, + `E[(a + b√s·Z)⁺] = a·Φ(d) + b√s·φ(d)` with `d = a/(b√s)`. +* `cva_gaussian`: CVA with Gaussian exposure `V_s = m(s) + σ(s)√s·Z` independent of the default + time, for measurable bounded `D`, `m`, `σ` with `σ > 0` and `T ≥ 0`; the value depends on `V` + only through `EE`. +* `cva_one_eq_protectionLeg`: the CVA of the constant unit exposure discounted by `e^{−rs}` equals + `Cox.protectionLeg R r h T`. +* `protectionLeg_eq_integral_coxDefaultTime`: for `h` continuous and positive with `∫₀ᵗ h → ∞`, + `Cox.protectionLeg R r h T = (1 − R)·E[e^{−rτ}·1{τ ≤ T}]` for the Cox default time `τ`. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull] (the credit-risk chapter: CVA). +* [S. Bagaria, *Notes on Fixed Income Derivative Pricing*][BagariaFIDP], ch. 16. +* [D. Lando, *Credit Risk Modeling*][Lando2004], ch. 5 + +## Tags + +credit valuation adjustment, expected exposure, counterparty risk, wrong-way risk, default time, +CDS protection leg, Gaussian exposure, MSC 91G40, JEL G32, JEL G33 +-/ + +@[expose] public section + +namespace MathFin.CVA + +open MeasureTheory ProbabilityTheory Real MathFin.DefaultDensity + +variable {Ω₁ Ω₂ : Type*} {m₁ : MeasurableSpace Ω₁} {m₂ : MeasurableSpace Ω₂} + {ν : Measure Ω₁} {μ : Measure Ω₂} + +/-- Expected positive exposure `EE(s) = E_ν[V_s⁺]`. -/ +noncomputable def expectedExposure (V : ℝ → Ω₁ → ℝ) (ν : Measure Ω₁) (s : ℝ) : ℝ := + ∫ ω, max (V s ω) 0 ∂ν + +/-- Unilateral CVA on the product space: `LGD · E[1{τ ≤ T} · D(τ) · V_τ⁺]`, exposure on the +first factor, default time on the second. -/ +noncomputable def cva (LGD : ℝ) (D : ℝ → ℝ) (V : ℝ → Ω₁ → ℝ) (τ : Ω₂ → ℝ) (T : ℝ) + (ν : Measure Ω₁) (μ : Measure Ω₂) : ℝ := + LGD * ∫ p, (Set.Iic T).indicator D (τ p.2) * max (V (τ p.2) p.1) 0 ∂(ν.prod μ) + +/-- `EE` is measurable in `s` when `V` is jointly measurable (Fubini measurability of the +inner integral). -/ +theorem measurable_expectedExposure [SFinite ν] {V : ℝ → Ω₁ → ℝ} + (hV : Measurable (Function.uncurry V)) : Measurable (expectedExposure V ν) := + (hV.max measurable_const).stronglyMeasurable.integral_prod_right'.measurable + +/-- **No-WWR reduction** (Hull's CVA; the protection-leg kernel of Bagaria eq. 16.2): +exposure independent of a default time with deterministic continuous hazard `h ≥ 0` gives +`E[1{τ ≤ T} D(τ) V_τ⁺] = ∫₀ᵀ D(s) · EE(s) · λ(s)Q(s) ds`, for measurable `D`, jointly +measurable `V`, `T ≥ 0`, and the left integrand jointly integrable (hypothesis `hint`). -/ +theorem integral_exposure_eq [IsProbabilityMeasure ν] [IsProbabilityMeasure μ] + {h : ℝ → ℝ} (hh : Continuous h) (hnn : ∀ s, 0 ≤ h s) {τ : Ω₂ → ℝ} (hτ : Measurable τ) + (hcdf : ∀ a, 0 ≤ a → μ {ω | τ ω ≤ a} = 1 - ENNReal.ofReal (hazardSurvival h a)) + {D : ℝ → ℝ} (hD : Measurable D) {V : ℝ → Ω₁ → ℝ} (hV : Measurable (Function.uncurry V)) + {T : ℝ} (hT : 0 ≤ T) + (hint : Integrable (fun p : Ω₁ × Ω₂ ↦ (Set.Iic T).indicator D (τ p.2) * max (V (τ p.2) p.1) 0) + (ν.prod μ)) : + ∫ p, (Set.Iic T).indicator D (τ p.2) * max (V (τ p.2) p.1) 0 ∂(ν.prod μ) + = ∫ s in (0:ℝ)..T, D s * expectedExposure V ν s * defaultDensity h s := by + rw [integral_prod_symm _ hint] + simp_rw [integral_const_mul] + refine (integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ ?_)).trans + (integral_indicator_Iic_eq hh hnn hτ.aemeasurable hcdf + (hD.mul (measurable_expectedExposure hV)) hT) + exact (Set.indicator_mul_left _ D (expectedExposure V ν)).symm + +/-- **Gaussian expected exposure**: for `Z ~ N(0,1)`, `s > 0`, `b > 0`, +`E[(a + b√s·Z)⁺] = a·Φ(d) + b√s·φ(d)` with `d = a/(b√s)`. The Bachelier call formula with +strike `K = 1` and spot `a + 1`, so no `K > 0` restriction is lost. -/ +theorem expectedExposure_gaussian [IsProbabilityMeasure ν] {Z : Ω₁ → ℝ} + (hZ : HasLaw Z (gaussianReal 0 1) ν) {a b s : ℝ} (hb : 0 < b) (hs : 0 < s) : + ∫ ω, max (a + b * √s * Z ω) 0 ∂ν + = a * Phi (a / (b * √s)) + b * √s * gaussianPDFReal 0 1 (a / (b * √s)) := by + have := bachelier_call_formula (S_0 := a + 1) ⟨one_pos, hb, hs, hZ⟩ + simp only [bachelierTerminal, bachelierD, add_sub_cancel_right] at this + simpa only [add_right_comm a 1, add_sub_cancel_right] using this + +open scoped NNReal in +/-- **Gaussian expected exposure at the law**: for `V_s ~ N(m, v)` with `v > 0`, +`EE(s) = m Φ(m/√v) + √v φ(m/√v)`. The law of `V_s` is that of `m + √v Z` for `Z ~ N(0,1)`, so +this is `CVA.expectedExposure_gaussian` at `b = √v`, `s = 1`, transported through the law. -/ +theorem expectedExposure_of_hasLaw_gaussianReal {V : ℝ → Ω₁ → ℝ} {s m : ℝ} {v : ℝ≥0} + (hV : HasLaw (V s) (gaussianReal m v) ν) (hv : 0 < v) : + expectedExposure V ν s + = m * Phi (m / √(v : ℝ)) + √(v : ℝ) * gaussianPDFReal 0 1 (m / √(v : ℝ)) := by + have hZ : HasLaw (fun z : ℝ ↦ z) (gaussianReal 0 1) (gaussianReal 0 1) := HasLaw.id + have hW : HasLaw (fun z : ℝ ↦ m + √(v : ℝ) * √1 * z) (gaussianReal m v) (gaussianReal 0 1) := by + convert gaussianReal_const_add (gaussianReal_const_mul hZ (√(v : ℝ) * √1)) m using 2 + · simp + · ext; simp + have h := expectedExposure_gaussian hZ (a := m) (Real.sqrt_pos.2 (NNReal.coe_pos.2 hv)) one_pos + have hf : AEStronglyMeasurable (fun x : ℝ ↦ max x 0) (gaussianReal m v) := by fun_prop + calc expectedExposure V ν s = ∫ x, max x 0 ∂gaussianReal m v := hV.integral_comp hf + _ = ∫ z, max (m + √(v : ℝ) * √1 * z) 0 ∂gaussianReal 0 1 := (hW.integral_comp hf).symm + _ = _ := by simpa using h + +/-- **CVA with Gaussian exposure, no wrong-way risk** (Hull's CVA; the protection-leg kernel +of Bagaria eq. 16.2). Exposure `V_s = m(s) + σ(s)√s·Z`, `Z ~ N(0,1)` on the exposure factor, +independent (product measure) of a default time with continuous hazard `h ≥ 0`; `D`, `m`, `σ` +measurable and bounded, `σ > 0`, `T ≥ 0`. By `integral_exposure_eq` a CVA under independence +depends on `V` only through `EE(s)`, so only the marginal laws `V_s ~ N(m(s), σ(s)²s)` enter +it and one driver `Z` for all `s` loses nothing for this value; no exposure dynamics are +modelled. Then + + `CVA = LGD · ∫₀ᵀ D(s) · [m(s)Φ(d_s) + σ(s)√s·φ(d_s)] · λ(s)Q(s) ds`, `d_s = m(s)/(σ(s)√s)`. -/ +theorem cva_gaussian [IsProbabilityMeasure ν] [IsProbabilityMeasure μ] + {h : ℝ → ℝ} (hh : Continuous h) (hnn : ∀ s, 0 ≤ h s) {τ : Ω₂ → ℝ} (hτ : Measurable τ) + (hcdf : ∀ a, 0 ≤ a → μ {ω | τ ω ≤ a} = 1 - ENNReal.ofReal (hazardSurvival h a)) + {D : ℝ → ℝ} (hD : Measurable D) {C : ℝ} (hDb : ∀ s, |D s| ≤ C) + {m σ : ℝ → ℝ} (hm : Measurable m) (hσ : Measurable σ) {M S : ℝ} (hmb : ∀ s, |m s| ≤ M) + (hσpos : ∀ s, 0 < σ s) (hσb : ∀ s, σ s ≤ S) + {Z : Ω₁ → ℝ} (hZm : Measurable Z) (hZ : HasLaw Z (gaussianReal 0 1) ν) (LGD : ℝ) + {T : ℝ} (hT : 0 ≤ T) : + cva LGD D (fun s ω ↦ m s + σ s * √s * Z ω) τ T ν μ + = LGD * ∫ s in (0:ℝ)..T, D s * (m s * Phi (m s / (σ s * √s)) + + σ s * √s * gaussianPDFReal 0 1 (m s / (σ s * √s))) * defaultDensity h s := by + have hV : Measurable (Function.uncurry fun s ω ↦ m s + σ s * √s * Z ω) := + (hm.comp measurable_fst).add (((hσ.comp measurable_fst).mul + (measurable_fst.sqrt)).mul (hZm.comp measurable_snd)) + have hZint : Integrable Z ν := hZ.integrable ((memLp_id_gaussianReal 1).integrable le_rfl) + have hC : 0 ≤ C := (abs_nonneg _).trans (hDb 0) + have hS : 0 ≤ S := (hσpos 0).le.trans (hσb 0) + have hg : ∀ x : ℝ, 0 ≤ M + S * √T * |x| := fun x ↦ + add_nonneg ((abs_nonneg _).trans (hmb 0)) (by positivity) + have hint : Integrable (fun p : Ω₁ × Ω₂ ↦ (Set.Iic T).indicator D (τ p.2) * + max (m (τ p.2) + σ (τ p.2) * √(τ p.2) * Z p.1) 0) (ν.prod μ) := by + refine Integrable.mono' ((((integrable_const M).add + (hZint.abs.const_mul (S * √T))).const_mul C).comp_fst μ) ?_ + (Filter.Eventually.of_forall fun p ↦ ?_) + · exact (((hD.indicator measurableSet_Iic).comp (hτ.comp measurable_snd)).mul + ((hV.comp ((hτ.comp measurable_snd).prodMk measurable_fst)).max + measurable_const)).aestronglyMeasurable + · simp only [Real.norm_eq_abs, abs_mul] + by_cases hs : τ p.2 ∈ Set.Iic T + · rw [Set.indicator_of_mem hs] + have hsq : √(τ p.2) ≤ √T := Real.sqrt_le_sqrt hs + have h1 : |max (m (τ p.2) + σ (τ p.2) * √(τ p.2) * Z p.1) 0| + ≤ M + S * √T * |Z p.1| := by + rw [abs_of_nonneg (le_max_right _ _)] + refine max_le ?_ (hg _) + -- `hσ0` is not referenced by name below: `gcongr`'s side-condition discharger + -- finds it in context to prove `0 ≤ σ (τ p.2)` for the `mul_le_mul'`-style step. + have hσ0 : 0 ≤ σ (τ p.2) := (hσpos (τ p.2)).le + have hσS : σ (τ p.2) ≤ S := hσb (τ p.2) + calc m (τ p.2) + σ (τ p.2) * √(τ p.2) * Z p.1 + ≤ |m (τ p.2)| + σ (τ p.2) * √(τ p.2) * |Z p.1| := by + rw [mul_assoc, mul_assoc] + gcongr + · exact le_abs_self _ + exact le_abs_self _ + _ ≤ M + S * √T * |Z p.1| := add_le_add (hmb _) + (mul_le_mul_of_nonneg_right (mul_le_mul hσS hsq (Real.sqrt_nonneg _) hS) + (abs_nonneg _)) + exact mul_le_mul (hDb _) h1 (abs_nonneg _) hC + · rw [Set.indicator_of_notMem hs, abs_zero, zero_mul] + exact mul_nonneg hC (hg _) + unfold cva + rw [integral_exposure_eq hh hnn hτ hcdf hD hV hT hint] + congr 1 + refine intervalIntegral.integral_congr_ae (Filter.Eventually.of_forall fun s hs ↦ ?_) + rw [Set.uIoc_of_le hT] at hs + simp only [expectedExposure] + rw [expectedExposure_gaussian hZ (hσpos s) hs.1] + +/-- **The protection leg is the CVA of a unit exposure.** For a default time `τ` with continuous +hazard `h ≥ 0` (CDF `1 − Q` on `[0, ∞)`, hypothesized), recovery `R`, flat rate `r` and `T ≥ 0`, +the CVA of the constant exposure `V ≡ 1` discounted by `e^{−rs}` is +`(1 − R)·E[e^{−rτ}·1{τ ≤ T}] = (1 − R)·∫₀ᵀ e^{−rs} h(s) Q(s) ds = Cox.protectionLeg R r h T`. -/ +theorem cva_one_eq_protectionLeg [IsProbabilityMeasure ν] [IsFiniteMeasure μ] {h : ℝ → ℝ} + (hh : Continuous h) (hnn : ∀ s, 0 ≤ h s) {τ : Ω₂ → ℝ} (hτ : AEMeasurable τ μ) + (hcdf : ∀ a, 0 ≤ a → μ {ω | τ ω ≤ a} = 1 - ENNReal.ofReal (hazardSurvival h a)) + (R r : ℝ) {T : ℝ} (hT : 0 ≤ T) : + cva (1 - R) (fun s ↦ rexp (-(r * s))) (fun _ _ ↦ 1) τ T ν μ = Cox.protectionLeg R r h T := by + simp only [cva, max_eq_left (zero_le_one : (0 : ℝ) ≤ 1), mul_one] + rw [integral_fun_snd (f := fun ω ↦ (Set.Iic T).indicator (fun s ↦ rexp (-(r * s))) (τ ω)), + probReal_univ, one_smul, + integral_indicator_Iic_eq hh hnn hτ hcdf (by fun_prop) hT, Cox.protectionLeg, Cox.cdsLosses] + congr 1 + refine intervalIntegral.integral_congr fun s _ ↦ ?_ + simp only [defaultDensity] + ring + +/-- **The Cox protection leg is an expectation over the constructed default time.** For `h` +continuous and positive with `∫₀ᵗ h → ∞`, `ξ` a unit-exponential clock and +`τ = Cox.coxDefaultTime h ξ` (the clock inverted through `∫₀ᵗ h`), the CDS protection leg +`(1 − R)·∫₀ᵀ e^{−rs} h(s) e^{−∫₀ˢ h} ds` (`Cox.protectionLeg`) equals +`(1 − R)·E[e^{−rτ}·1{τ ≤ T}]` for `T ≥ 0`. The CDF of `τ` is `Cox.cox_cdf_timeVarying` and its +measurability is `Cox.measurable_coxDefaultTime`. -/ +theorem protectionLeg_eq_integral_coxDefaultTime [IsFiniteMeasure μ] {h : ℝ → ℝ} + (hh : Continuous h) (hpos : ∀ s, 0 < h s) + (hdiv : Filter.Tendsto (cumHazard h) Filter.atTop Filter.atTop) {ξ : Ω₂ → ℝ} + (hξmeas : Measurable ξ) (hξlaw : μ.map ξ = ProbabilityTheory.expMeasure 1) (R r : ℝ) {T : ℝ} + (hT : 0 ≤ T) : + Cox.protectionLeg R r h T = + (1 - R) * ∫ ω, (Set.Iic T).indicator (fun s ↦ rexp (-(r * s))) + (Cox.coxDefaultTime h ξ ω) ∂μ := by + rw [integral_indicator_Iic_eq hh (fun s ↦ (hpos s).le) + (Cox.measurable_coxDefaultTime hh hpos hξmeas).aemeasurable + (fun _ ha ↦ Cox.cox_cdf_timeVarying hh hpos hdiv hξmeas hξlaw ha) (by fun_prop) hT, + Cox.protectionLeg, Cox.cdsLosses] + congr 1 + refine intervalIntegral.integral_congr fun s _ ↦ ?_ + simp only [defaultDensity] + ring + +end MathFin.CVA diff --git a/LeanPool/MathFin/Models/Credit/Cox.lean b/LeanPool/MathFin/Models/Credit/Cox.lean new file mode 100644 index 0000000000..d885a19b64 --- /dev/null +++ b/LeanPool/MathFin/Models/Credit/Cox.lean @@ -0,0 +1,657 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Jumps.PoissonInterarrival +public import LeanPool.MathFin.Models.Credit.HazardCurve +public import LeanPool.MathFin.Models.Credit.CDSTimeVarying +public import Mathlib.Topology.UniformSpace.Uniformizable + +/-! +# Cox-intensity credit: survival, default density, CDS legs and fair spread + +The Cox construction of a default time, for a deterministic intensity: for `h` +continuous and strictly positive on all of `ℝ`, with `Λ = cumHazard h → ∞`, the +time obtained by inverting a unit-exponential clock through `Λ` satisfies, for +`t, T ≥ 0`, the survival law `P(τ > t) = e^{−Λ(t)}` and the default-density +identity `P(τ ≤ T) = ∫₀ᵀ h(s)·e^{−Λ(s)} ds` (undiscounted; nothing is priced against +`τ`). The CDS legs are *defined* as the deterministic integrals `c·∫₀ᵀ e^{−rs}S(s) ds` (premium) and +`(1−R)·∫₀ᵀ e^{−rs}h(s)S(s) ds` (protection), and the fair spread is the algebraic solution of +`c·A = (1−R)·L` for `A > 0`. This file does not identify the legs with expectations over `τ`; +`Models/Credit/CVA.lean` proves that the protection leg is `(1 − R)·E[e^{−rτ}·1{τ ≤ T}]` for the +constructed `τ` (`CVA.protectionLeg_eq_integral_coxDefaultTime`), using the measurability of `τ` +proved here (`measurable_coxDefaultTime`). + +The module layers: + +* **The counting/first-arrival substrate in credit variables** — the + constant-intensity reading of the Poisson first-arrival laws + (`PoissonInterarrival.survival_eq`, + `PoissonInterarrival.map_firstArrival_eq_expMeasure`). +* **Constant intensity** — the two CDS legs in closed form: the risky annuity + `(1 − e^{−(r+λ)T})/(r+λ)`, the protection leg as hazard times the annuity, + and the leg balance realizing `cds_leg_equality` at the concrete integral + (fair spread `λ(1−R)`). +* **Deterministic time-varying intensity** — the Cox default time + `coxDefaultTime` (clock inversion through `Λ`), with the survival and CDF + identities. The mechanism is an a.e. set equality between the survival event + and the clock-tail event, so the identities need no regularity of the inverse. + The default time is measurable (`measurable_coxDefaultTime`): `Λ` is a continuous + injection, hence a measurable embedding, and `Function.invFun Λ` extends its inverse + by a constant off the range. +* **The CDS legs under `λ(t)`** — the risky annuity and default-density + integrals (`cdsAnnuity`, `cdsLosses`), the explicit legs (`premiumLeg`, + `protectionLeg`), the balance theorem `cdsFairSpreadTV_balances`, the + constant-`λ` case `cdsFairSpreadTV_const` (collapsing to `cdsFairSpread`), and the default + probability as the integral of the default density (undiscounted). +* **Restricted Cox mixing** — on the product of a path space with the clock + space, `(μ₁ ⊗ Exp(1)){Λ_t < ξ} = ∫ e^{−Λ_t} dμ₁` for any `Λ ≥ 0` with + measurable time sections; a default time enters only when hypothesized + (`cox_mixed_survival`). + +Faithfulness note: `cdsFairSpreadTV_balances` is a direct instantiation of the +cash-flow balance `cdsFairSpread_TV_cash_flow_balance` +(`Models/Credit/CDSTimeVarying.lean`) at the concrete integrals, with +annuity-positivity discharged by `cdsAnnuity_pos`; its own docstring discloses +this. + +## Main definitions + +* `riskyAnnuity`: the risky annuity `∫₀ᵀ e^{−rs} e^{−lam·s} ds` at constant intensity `lam` and + discount rate `r`. +* `coxDefaultTime`: the Cox default time, a unit-exponential clock inverted through the cumulative + hazard `Λ`. +* `cdsAnnuity`: the risky annuity `∫₀ᵀ e^{−rs} S(s) ds` under deterministic intensity `h`. +* `cdsLosses`: the default-density integral `∫₀ᵀ e^{−rs} h(s) S(s) ds` under deterministic + intensity `h`. +* `premiumLeg`, `protectionLeg`: the CDS premium leg at spread `c` and protection leg at + recovery `R`. +* `cdsFairSpreadTV`: the time-varying fair spread `(1−R) · losses / annuity`. + +## Main results + +* `defaultSurvival_const`: if `τ` is the first arrival of a counting process with Poisson + increments of rate `rate`, then `P(τ > t) = e^{−rate·t}` for `t ≥ 0`. +* `riskyAnnuity_eq`, `riskyAnnuity_pos`: the constant-intensity risky annuity equals + `(1 − e^{−(r+λ)T})/(r+λ)` when `r + λ ≠ 0`, and is positive for `T > 0`. +* `cdsLegs_balance_const`: for `T > 0`, premium and protection legs at constant intensity + balance if and only if `c = cdsFairSpread λ R`. +* `cumHazard_strictMono`, `cumHazard_surjOn_Ici`: for `h` continuous and positive, the cumulative + hazard is strictly increasing; if it also tends to `∞`, it takes every value `y ≥ 0` at some + `s ≥ 0`. +* `cox_survival_timeVarying`, `cox_cdf_timeVarying`: for `h` continuous, positive, with divergent + cumulative hazard and a unit-exponential `ξ`, the Cox time satisfies `P(τ > t) = e^{−Λ(t)}` + and `P(τ ≤ a) = 1 − e^{−Λ(a)}` for `t, a ≥ 0`. +* `measurable_coxDefaultTime`: for `h` continuous and positive and `ξ` measurable, the Cox + default time is measurable. +* `cox_defaultProb_density`: under the same hypotheses, `P(τ ≤ a) = ∫₀ᵃ h(s)·S(s) ds` for + `a ≥ 0` (undiscounted). +* `cdsAnnuity_pos`, `cdsFairSpreadTV_balances`: for `h` continuous and `T > 0`, the time-varying + annuity is positive, and the premium and protection legs balance if and only if + `c = cdsFairSpreadTV r h R T`. +* `cdsFairSpreadTV_const`: for `T > 0`, the time-varying fair spread at constant intensity `λ` + equals `cdsFairSpread λ R`. +* `cox_mixed_survival`: on the product of a path space with an `Exp(1)` clock, for a measurable + nonnegative `Λ` and a `τ` with `t < τ ↔ Λ_t < clock`, `P(τ > t) = ∫ e^{−Λ_t} dμ₁`. + +## Tags + +Cox process, intensity model, default time, reduced-form credit, hazard rate, CDS fair spread, +doubly stochastic, MSC 91G40, MSC 60G55, JEL G12 +-/ + +@[expose] public section + +namespace MathFin.Cox + +open MeasureTheory ProbabilityTheory Real MathFin +open scoped NNReal ENNReal + +/-! ### The counting/first-arrival substrate, in credit variables -/ + +section FirstArrival + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + +/-- **Survival of the default time under constant intensity** — the credit +reading of the first-arrival survival law: under a rate-`rate` Poisson +counting process, a default time `τ` characterized by `τ > t ↔ N_t = 0` has +`P(τ > t) = e^{−rate·t}`. Consumes `PoissonInterarrival.survival_eq`. -/ +theorem defaultSurvival_const {rate : ℝ≥0} {N : ℝ → Ω → ℕ} + (hmeas : ∀ t, Measurable (N t)) (hzero : ∀ ω, N 0 ω = 0) + (hincr : ∀ ⦃s t : ℝ⦄, 0 ≤ s → (hst : s ≤ t) → + Measure.map (fun ω ↦ N t ω - N s ω) μ + = poissonMeasure (rate * ⟨t - s, sub_nonneg.mpr hst⟩)) + {τ : Ω → ℝ} (hτfirst : ∀ ⦃t : ℝ⦄, 0 ≤ t → {ω | t < τ ω} = {ω | N t ω = 0}) + {t : ℝ} (ht : 0 ≤ t) : + μ {ω | t < τ ω} = ENNReal.ofReal (rexp (-((rate : ℝ) * t))) := by + rw [hτfirst ht] + exact PoissonInterarrival.survival_eq hmeas hzero hincr ht + +end FirstArrival + +/-! ### Constant intensity: the two CDS legs in closed form -/ + +/-- The **risky annuity** at constant intensity `lam` and discount rate `r`: +`∫₀ᵀ e^{−rs} e^{−lam·s} ds`. -/ +noncomputable def riskyAnnuity (r lam T : ℝ) : ℝ := + ∫ s in (0:ℝ)..T, rexp (-((r + lam) * s)) + +/-- Closed form: `∫₀ᵀ e^{−(r+lam)s} ds = (1 − e^{−(r+lam)T}) / (r+lam)`. -/ +theorem riskyAnnuity_eq (r lam T : ℝ) (hne : r + lam ≠ 0) : + riskyAnnuity r lam T = (1 - rexp (-((r + lam) * T))) / (r + lam) := by + have key : ∀ s : ℝ, HasDerivAt (fun u : ℝ ↦ -rexp (-((r + lam) * u)) / (r + lam)) + (rexp (-((r + lam) * s))) s := by + intro s + have h1 : HasDerivAt (fun u : ℝ ↦ (r + lam) * u) (r + lam) s := + by simpa using (hasDerivAt_id s).const_mul (r + lam) + have h2 : HasDerivAt (fun u : ℝ ↦ rexp (-((r + lam) * u))) + (rexp (-((r + lam) * s)) * -(r + lam)) s := (h1.neg).exp + have h2' := h2.neg + have hv : (-(rexp (-((r + lam) * s)) * -(r + lam))) + = rexp (-((r + lam) * s)) * (r + lam) := by ring + rw [hv] at h2' + have h4 := h2'.div_const (r + lam) + have hv3 : rexp (-((r + lam) * s)) * (r + lam) / (r + lam) = rexp (-((r + lam) * s)) := by + field_simp + rwa [hv3] at h4 + have hint : IntervalIntegrable (fun s ↦ rexp (-((r + lam) * s))) volume 0 T := + ((continuous_const.mul continuous_id).neg.rexp).intervalIntegrable 0 T + rw [riskyAnnuity, intervalIntegral.integral_eq_sub_of_hasDerivAt (fun s _ ↦ key s) hint, mul_zero] + simp only [neg_zero, Real.exp_zero] + field_simp + ring + +/-- The risky annuity is positive for positive maturity (the integrand is +strictly positive everywhere). -/ +theorem riskyAnnuity_pos (r lam T : ℝ) (hT : 0 < T) : 0 < riskyAnnuity r lam T := by + have hfc : ContinuousOn (fun s : ℝ ↦ rexp (-((r + lam) * s))) (Set.Icc 0 T) := + (continuous_const.mul continuous_id).neg.rexp.continuousOn + rw [riskyAnnuity] + exact intervalIntegral.integral_pos hT hfc (fun x _ ↦ le_of_lt (Real.exp_pos _)) + ⟨T / 2, ⟨by linarith, by linarith⟩, Real.exp_pos _⟩ + +/-- **Protection leg in closed form at constant intensity**: `(1−R) · ∫₀ᵀ e^{−rs} · +(lam e^{−lam·s}) ds = (1−R) · lam · riskyAnnuity` — the default density +`lam·e^{−lam·s}` is the hazard times the survival, and it shares the annuity's +kernel. -/ +theorem protectionLeg_const (r lam R T : ℝ) : + (1 - R) * ∫ s in (0:ℝ)..T, rexp (-(r * s)) * (lam * rexp (-(lam * s))) + = (1 - R) * lam * riskyAnnuity r lam T := by + have hpt : ∀ s : ℝ, rexp (-(r * s)) * (lam * rexp (-(lam * s))) + = lam * rexp (-((r + lam) * s)) := by + intro s + rw [mul_left_comm, ← Real.exp_add] + congr 1 + ring_nf + rw [intervalIntegral.integral_congr + (f := fun s : ℝ ↦ rexp (-(r * s)) * (lam * rexp (-(lam * s)))) + (g := fun s : ℝ ↦ lam * rexp (-((r + lam) * s))) (fun s _ ↦ hpt s), + intervalIntegral.integral_const_mul, riskyAnnuity] + ring + +/-- **Leg balance at constant intensity** — the abstract annuity-factor +characterization `MathFin.cds_leg_equality` realized at the concrete integral: +the premium leg `c · riskyAnnuity` equals the protection leg +`(1−R) · lam · riskyAnnuity` iff the spread is `cdsFairSpread lam R = lam(1−R)`. -/ +theorem cdsLegs_balance_const (r lam R T c : ℝ) (hT : 0 < T) : + c * riskyAnnuity r lam T = (1 - R) * lam * riskyAnnuity r lam T + ↔ c = cdsFairSpread lam R := + cds_leg_equality lam R (riskyAnnuity r lam T) c + (ne_of_gt (riskyAnnuity_pos r lam T hT)) + +/-- The fair spread balances the legs (the "if" direction of the balance, +checked against `cdsFairSpread`). -/ +theorem cdsFairSpread_const_balances (r lam R T : ℝ) (hT : 0 < T) : + cdsFairSpread lam R * riskyAnnuity r lam T = (1 - R) * lam * riskyAnnuity r lam T := by + rw [cdsLegs_balance_const r lam R T (cdsFairSpread lam R) hT] + +/-! ### Deterministic time-varying intensity: the survival identity + +All identities in this section hold for an arbitrary base measure `μ` (in the +credit model `μ` is a probability measure; nothing below needs it). The +exponential-clock facts carry their own `IsProbabilityMeasure (expMeasure 1)` +instances. -/ + +section TimeVarying + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + +/-- The survival function of the time-varying-hazard model is the exponential +of the (negative) cumulative hazard — `hazardSurvival` unfolds to it. -/ +private lemma hazardSurvival_eq_exp (h : ℝ → ℝ) (t : ℝ) : + hazardSurvival h t = rexp (-(cumHazard h t)) := rfl + +/-- The cumulative hazard vanishes at 0. -/ +private lemma cumHazard_zero (h : ℝ → ℝ) : cumHazard h 0 = 0 := by + exact intervalIntegral.integral_same + +/-- The cumulative hazard is nonnegative on the half-line under a positive +intensity. -/ +private lemma cumHazard_nonneg {h : ℝ → ℝ} (hpos : ∀ s, 0 < h s) {t : ℝ} (ht : 0 ≤ t) : + 0 ≤ cumHazard h t := + intervalIntegral.integral_nonneg ht fun s _ ↦ le_of_lt (hpos s) + +/-- Fundamental theorem of calculus for the cumulative hazard: `Λ' = h`. -/ +private theorem cumHazard_deriv {h : ℝ → ℝ} (hh : Continuous h) (s : ℝ) : + HasDerivAt (cumHazard h) (h s) s := + intervalIntegral.integral_hasDerivAt_right (hh.intervalIntegrable 0 s) + (hh.stronglyMeasurableAtFilter _ _) hh.continuousAt + +/-- Continuity of the cumulative hazard (via its differentiability). -/ +private theorem cumHazard_continuous {h : ℝ → ℝ} (hh : Continuous h) : Continuous (cumHazard h) := + Differentiable.continuous fun s ↦ (cumHazard_deriv hh s).differentiableAt + +/-- Under a continuous hazard intensity, strictly positive for all calendar time, +the cumulative hazard is strictly increasing. -/ +theorem cumHazard_strictMono {h : ℝ → ℝ} (hh : Continuous h) (hpos : ∀ s, 0 < h s) : + StrictMono (cumHazard h) := + strictMono_of_hasDerivAt_pos (fun s ↦ cumHazard_deriv hh s) hpos + +/-- Under a continuous, strictly positive intensity with divergent cumulative +hazard, `Λ` maps the half-line onto the half-line (IVT from `Λ 0 = 0` and +`Λ → ∞`). -/ +theorem cumHazard_surjOn_Ici {h : ℝ → ℝ} (hh : Continuous h) (hpos : ∀ s, 0 < h s) + (hdiv : Filter.Tendsto (cumHazard h) Filter.atTop Filter.atTop) (y : ℝ) (hy : 0 ≤ y) : + ∃ s : ℝ, 0 ≤ s ∧ cumHazard h s = y := by + have h0 := cumHazard_zero h + obtain ⟨T, hTy⟩ : ∃ T : ℝ, y ≤ cumHazard h T := + (Filter.Tendsto.eventually_ge_atTop hdiv y).exists + have hT0 : 0 ≤ T := by + by_contra hTneg + have hTneg' : T < 0 := not_le.mp hTneg + have hlt : cumHazard h T < cumHazard h 0 := cumHazard_strictMono hh hpos hTneg' + rw [cumHazard_zero] at hlt + linarith + have hIVT := intermediate_value_Icc (a := (0:ℝ)) (b := T) hT0 + (cumHazard_continuous hh).continuousOn + obtain ⟨s, hsIcc, hsΛ⟩ := hIVT ⟨by rw [h0]; exact hy, hTy⟩ + exact ⟨s, hsIcc.1, hsΛ⟩ + +/-- **CDF of the unit exponential clock**: for `ν = Exp(1)` and `x ≥ 0`, +`ν(−∞, x] = 1 − e^{−x}`. -/ +theorem expClock_Iic {x : ℝ} (hx : 0 ≤ x) : + expMeasure 1 (Set.Iic x) = ENNReal.ofReal (1 - rexp (-x)) := by + have : IsProbabilityMeasure (expMeasure 1) := isProbabilityMeasure_expMeasure one_pos + rw [← ENNReal.ofReal_toReal (measure_ne_top _ _), + show ENNReal.toReal (expMeasure 1 (Set.Iic x)) = cdf (expMeasure 1) x from by + rw [cdf_eq_real, measureReal_def], + cdf_expMeasure_eq one_pos x, ite_eq_left hx] + simp only [one_mul] + +/-- **Tail of the unit exponential clock**: for `ν = Exp(1)` and `x ≥ 0`, +`ν(x, ∞) = e^{−x}`. -/ +theorem expClock_Ioi {x : ℝ} (hx : 0 ≤ x) : + expMeasure 1 (Set.Ioi x) = ENNReal.ofReal (rexp (-x)) := by + have : IsProbabilityMeasure (expMeasure 1) := isProbabilityMeasure_expMeasure one_pos + have hset : Set.Ioi x = (Set.Iic x)ᶜ := by + ext y + simp only [Set.mem_Ioi, Set.mem_compl_iff, Set.mem_Iic, not_le] + have hnn : 0 ≤ 1 - rexp (-x) := by + have hle : rexp (-x) ≤ 1 := Real.exp_le_one_iff.mpr (by linarith) + linarith + rw [hset, measure_compl measurableSet_Iic (measure_ne_top _ _), measure_univ, + expClock_Iic hx, show ((1:ℝ≥0∞)) = ENNReal.ofReal 1 from ENNReal.ofReal_one.symm, + ← ENNReal.ofReal_sub 1 hnn] + congr 1 + ring + +/-- The unit exponential clock is almost surely nonnegative. -/ +theorem expClock_null_neg {ξ : Ω → ℝ} (hξmeas : Measurable ξ) + (hξlaw : Measure.map ξ μ = expMeasure 1) : μ {ω | ξ ω < 0} = 0 := by + have : IsProbabilityMeasure (expMeasure 1) := isProbabilityMeasure_expMeasure one_pos + rw [show {ω | ξ ω < 0} = ξ ⁻¹' Set.Iio 0 from rfl, + ← Measure.map_apply hξmeas measurableSet_Iio, hξlaw] + refine le_antisymm + (le_trans (measure_mono (show {y : ℝ | y < 0} ⊆ Set.Iic 0 from Set.Iio_subset_Iic_self)) ?_) + zero_le + rw [expClock_Iic le_rfl] + norm_num + +/-- Almost-sure nonnegativity of the clock. -/ +theorem expClock_nonneg_ae {ξ : Ω → ℝ} (hξmeas : Measurable ξ) + (hξlaw : Measure.map ξ μ = expMeasure 1) : ∀ᵐ ω ∂μ, 0 ≤ ξ ω := by + rw [ae_iff] + simp only [not_le] + exact expClock_null_neg hξmeas hξlaw + +/-- **The Cox default time (deterministic-intensity layer)**: invert a +unit-exponential clock through the cumulative hazard `Λ`. -/ +noncomputable def coxDefaultTime (h : ℝ → ℝ) (ξ : Ω → ℝ) : Ω → ℝ := + fun ω ↦ Function.invFun (cumHazard h) (ξ ω) + +/-- **The Cox default time is measurable.** `Λ = cumHazard h` is a continuous injection of `ℝ`, +hence a measurable embedding (`Continuous.measurableEmbedding`), and `Function.invFun Λ` is +`Function.extend Λ id` with a constant off the range of `Λ`, measurable by +`MeasurableEmbedding.measurable_extend`. Divergence of `Λ` is not needed. -/ +theorem measurable_coxDefaultTime {h : ℝ → ℝ} (hh : Continuous h) (hpos : ∀ s, 0 < h s) + {ξ : Ω → ℝ} (hξmeas : Measurable ξ) : Measurable (coxDefaultTime h ξ) := by + have hΛ : MeasurableEmbedding (cumHazard h) := + (cumHazard_continuous hh).measurableEmbedding (cumHazard_strictMono hh hpos).injective + have hinv : Measurable (Function.invFun (cumHazard h)) := by + rw [show Function.invFun (cumHazard h) = + Function.extend (cumHazard h) id fun _ ↦ Classical.arbitrary ℝ from rfl] + exact hΛ.measurable_extend measurable_id measurable_const + exact hinv.comp hξmeas + +/-- The inverse of `Λ` inverts exactly on the half-line, and lands there. -/ +private theorem invFun_on_halfline {h : ℝ → ℝ} (hh : Continuous h) (hpos : ∀ s, 0 < h s) + (hdiv : Filter.Tendsto (cumHazard h) Filter.atTop Filter.atTop) {y : ℝ} (hy : 0 ≤ y) : + cumHazard h (Function.invFun (cumHazard h) y) = y + ∧ 0 ≤ Function.invFun (cumHazard h) y := by + obtain ⟨s, hs0, hsΛ⟩ := cumHazard_surjOn_Ici hh hpos hdiv y hy + have heq : cumHazard h (Function.invFun (cumHazard h) y) = y := + Function.invFun_eq ⟨s, hsΛ⟩ + refine ⟨heq, ?_⟩ + by_contra hneg + have hneg' : Function.invFun (cumHazard h) y < 0 := not_le.mp hneg + have hlt : cumHazard h (Function.invFun (cumHazard h) y) < cumHazard h 0 := + cumHazard_strictMono hh hpos hneg' + rw [heq, cumHazard_zero] at hlt + linarith + +/-- The clock survival event, a.e.: `{τ > t} = {ξ > Λ t}` (for every `t`; the +pointwise equivalence needs no sign bound, only the global strict monotonicity +and the half-line inversion). -/ +private theorem coxDefaultTime_survSet {h : ℝ → ℝ} (hh : Continuous h) + (hpos : ∀ s, 0 < h s) (hdiv : Filter.Tendsto (cumHazard h) Filter.atTop Filter.atTop) + {ξ : Ω → ℝ} (hξmeas : Measurable ξ) (hξlaw : Measure.map ξ μ = expMeasure 1) + (t : ℝ) : + {ω | coxDefaultTime h ξ ω > t} =ᵐ[μ] {ω | cumHazard h t < ξ ω} := by + have hpt : ∀ ω : Ω, 0 ≤ ξ ω → (coxDefaultTime h ξ ω > t ↔ cumHazard h t < ξ ω) := by + intro ω hω + obtain ⟨hinv_eq, -⟩ := invFun_on_halfline hh hpos hdiv hω + unfold coxDefaultTime + constructor + · intro hgt + calc ξ ω = cumHazard h (Function.invFun (cumHazard h) (ξ ω)) := hinv_eq.symm + _ > cumHazard h t := cumHazard_strictMono hh hpos (by linarith) + · intro hlt + by_contra hcon + have hle : cumHazard h (Function.invFun (cumHazard h) (ξ ω)) ≤ cumHazard h t := + (cumHazard_strictMono hh hpos).monotone (by linarith) + rw [hinv_eq] at hle + linarith + filter_upwards [expClock_nonneg_ae hξmeas hξlaw] with ω hω + exact hpt ω hω + +/-- The clock CDF event, a.e.: `{τ ≤ a} = {ξ ≤ Λ a}` (for every `a`). -/ +private theorem coxDefaultTime_cdfSet {h : ℝ → ℝ} (hh : Continuous h) + (hpos : ∀ s, 0 < h s) (hdiv : Filter.Tendsto (cumHazard h) Filter.atTop Filter.atTop) + {ξ : Ω → ℝ} (hξmeas : Measurable ξ) (hξlaw : Measure.map ξ μ = expMeasure 1) + (a : ℝ) : + {ω | coxDefaultTime h ξ ω ≤ a} =ᵐ[μ] {ω | ξ ω ≤ cumHazard h a} := by + have hpt : ∀ ω : Ω, 0 ≤ ξ ω → (coxDefaultTime h ξ ω ≤ a ↔ ξ ω ≤ cumHazard h a) := by + intro ω hω + obtain ⟨hinv_eq, -⟩ := invFun_on_halfline hh hpos hdiv hω + unfold coxDefaultTime + constructor + · intro hle + rw [hinv_eq.symm] + exact (cumHazard_strictMono hh hpos).monotone hle + · intro hle + by_contra hcon + have hlt : cumHazard h (Function.invFun (cumHazard h) (ξ ω)) > cumHazard h a := + cumHazard_strictMono hh hpos (by linarith) + rw [hinv_eq] at hlt + linarith + filter_upwards [expClock_nonneg_ae hξmeas hξlaw] with ω hω + exact hpt ω hω + +/-- **The Cox survival identity, deterministic-intensity layer.** With `h` +continuous, strictly positive, and `∫₀ᵗ h → ∞`, the default time built by +inverting a unit-exponential clock through `Λ = cumHazard h` satisfies, for +`t ≥ 0`, `P(τ > t) = e^{−Λ(t)} = hazardSurvival h t` — the first-arrival survival +law at a deterministic time-varying intensity. -/ +theorem cox_survival_timeVarying {h : ℝ → ℝ} (hh : Continuous h) (hpos : ∀ s, 0 < h s) + (hdiv : Filter.Tendsto (cumHazard h) Filter.atTop Filter.atTop) + {ξ : Ω → ℝ} (hξmeas : Measurable ξ) (hξlaw : Measure.map ξ μ = expMeasure 1) + {t : ℝ} (ht : 0 ≤ t) : + μ {ω | coxDefaultTime h ξ ω > t} = ENNReal.ofReal (hazardSurvival h t) := by + have : IsProbabilityMeasure (expMeasure 1) := isProbabilityMeasure_expMeasure one_pos + have hΛt : 0 ≤ cumHazard h t := cumHazard_nonneg hpos ht + rw [measure_congr (coxDefaultTime_survSet hh hpos hdiv hξmeas hξlaw t), + show {ω | cumHazard h t < ξ ω} = ξ ⁻¹' Set.Ioi (cumHazard h t) from rfl, + ← Measure.map_apply hξmeas measurableSet_Ioi, hξlaw, expClock_Ioi hΛt] + rfl + +/-- **The Cox CDF identity, deterministic-intensity layer**: the same model +satisfies `P(τ ≤ a) = 1 − e^{−Λ(a)}` for `a ≥ 0`. -/ +theorem cox_cdf_timeVarying {h : ℝ → ℝ} (hh : Continuous h) (hpos : ∀ s, 0 < h s) + (hdiv : Filter.Tendsto (cumHazard h) Filter.atTop Filter.atTop) + {ξ : Ω → ℝ} (hξmeas : Measurable ξ) (hξlaw : Measure.map ξ μ = expMeasure 1) + {a : ℝ} (ha : 0 ≤ a) : + μ {ω | coxDefaultTime h ξ ω ≤ a} = 1 - ENNReal.ofReal (hazardSurvival h a) := by + have : IsProbabilityMeasure (expMeasure 1) := isProbabilityMeasure_expMeasure one_pos + have hΛa : 0 ≤ cumHazard h a := cumHazard_nonneg hpos ha + rw [measure_congr (coxDefaultTime_cdfSet hh hpos hdiv hξmeas hξlaw a), + show {ω | ξ ω ≤ cumHazard h a} = ξ ⁻¹' Set.Iic (cumHazard h a) from rfl, + ← Measure.map_apply hξmeas measurableSet_Iic, hξlaw, expClock_Iic hΛa, + show ((1:ℝ≥0∞)) = ENNReal.ofReal 1 from ENNReal.ofReal_one.symm, + ← ENNReal.ofReal_sub 1 (le_of_lt (hazardSurvival_pos h a))] + rfl + +end TimeVarying + +/-! ### CDS legs and fair spread under λ(t) -/ + +section CDSUpgrade + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + +/-- Continuity of the time-varying survival function (h continuous). -/ +private theorem hazardSurvival_continuous {h : ℝ → ℝ} (hh : Continuous h) : + Continuous (hazardSurvival h) := + (cumHazard_continuous hh).neg.rexp + +/-- The **risky annuity** (premium-leg kernel) under deterministic intensity +`h`: `∫₀ᵀ e^{−rs} S(s) ds` with `S = hazardSurvival h`. -/ +noncomputable def cdsAnnuity (r : ℝ) (h : ℝ → ℝ) (T : ℝ) : ℝ := + ∫ s in (0:ℝ)..T, rexp (-(r * s)) * hazardSurvival h s + +/-- The **default-density integral** (protection-leg kernel) under +deterministic intensity `h`: `∫₀ᵀ e^{−rs} h(s) S(s) ds`. -/ +noncomputable def cdsLosses (r : ℝ) (h : ℝ → ℝ) (T : ℝ) : ℝ := + ∫ s in (0:ℝ)..T, rexp (-(r * s)) * h s * hazardSurvival h s + +/-- The **premium leg** at spread `c`. -/ +noncomputable def premiumLeg (c r : ℝ) (h : ℝ → ℝ) (T : ℝ) : ℝ := c * cdsAnnuity r h T + +/-- The **protection leg** at recovery `R`. -/ +noncomputable def protectionLeg (R r : ℝ) (h : ℝ → ℝ) (T : ℝ) : ℝ := + (1 - R) * cdsLosses r h T + +/-- The **time-varying fair spread**: `(1−R) · losses / annuity`. -/ +noncomputable def cdsFairSpreadTV (r : ℝ) (h : ℝ → ℝ) (R T : ℝ) : ℝ := + (1 - R) * cdsLosses r h T / cdsAnnuity r h T + +/-- For continuous `h`, the risky annuity is positive for `T > 0` (discount × +survival is strictly positive; `S > 0` unconditionally by `hazardSurvival_pos`). -/ +theorem cdsAnnuity_pos {r : ℝ} {h : ℝ → ℝ} (hh : Continuous h) {T : ℝ} (hT : 0 < T) : + 0 < cdsAnnuity r h T := by + have hfc : ContinuousOn (fun s : ℝ ↦ rexp (-(r * s)) * hazardSurvival h s) + (Set.Icc 0 T) := + (((continuous_const.mul continuous_id).neg.rexp).mul + (hazardSurvival_continuous hh)).continuousOn + rw [cdsAnnuity] + exact intervalIntegral.integral_pos hT hfc + (fun x _ ↦ mul_nonneg (le_of_lt (Real.exp_pos _)) (le_of_lt (hazardSurvival_pos h x))) + ⟨0, ⟨le_refl 0, hT.le⟩, by rw [hazardSurvival_at_zero]; norm_num⟩ + +/-- **The default density integrates to the default probability** (pure +calculus): `∫₀^a h·S = 1 − S(a)` — the antiderivative of `h·S` is `−S`. -/ +theorem defaultDensity_antideriv {h : ℝ → ℝ} (hh : Continuous h) (a : ℝ) : + ∫ s in (0:ℝ)..a, h s * rexp (-(cumHazard h s)) = 1 - rexp (-(cumHazard h a)) := by + have key : ∀ s : ℝ, HasDerivAt (fun u : ℝ ↦ -rexp (-(cumHazard h u))) + (h s * rexp (-(cumHazard h s))) s := by + intro s + have h2 : HasDerivAt (fun u : ℝ ↦ rexp (-(cumHazard h u))) + (rexp (-(cumHazard h s)) * -(h s)) s := (cumHazard_deriv hh s).neg.exp + have h3 := h2.neg + have h4 : (-(rexp (-(cumHazard h s)) * -(h s))) + = h s * rexp (-(cumHazard h s)) := by ring + rwa [h4] at h3 + have hint : IntervalIntegrable (fun s : ℝ ↦ h s * rexp (-(cumHazard h s))) volume 0 a := + (hh.mul (hazardSurvival_continuous hh)).intervalIntegrable 0 a + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt (fun s _ ↦ key s) hint, cumHazard_zero] + norm_num [Real.exp_zero] + ring + +/-- **The clock-change identity**: `∫₀^{Λ(a)} e^{−y} dy = ∫₀^a h(s) e^{−Λ(s)} ds` +— the exponential-clock integral equals the default-density integral. FTC on +the shared antiderivative `−e^{−Λ}`; no change-of-variables lemma needed. -/ +theorem clockTail_eq_defaultDensity {h : ℝ → ℝ} (hh : Continuous h) (a : ℝ) : + ∫ y in (0:ℝ)..(cumHazard h a), rexp (-y) + = ∫ s in (0:ℝ)..a, h s * rexp (-(cumHazard h s)) := by + have key : ∀ y : ℝ, HasDerivAt (fun u : ℝ ↦ -rexp (-u)) (rexp (-y)) y := by + intro y + have h1 : HasDerivAt (fun u : ℝ ↦ -u) (-1) y := (hasDerivAt_id y).neg + have h2 := h1.exp + have hv : rexp (-y) * -1 = -rexp (-y) := by ring + rw [hv] at h2 + have h3 := h2.neg + rw [show (-(-rexp (-y))) = rexp (-y) from by ring] at h3 + exact h3 + have hint : IntervalIntegrable (fun y : ℝ ↦ rexp (-y)) volume 0 (cumHazard h a) := + ((continuous_id.neg).rexp).intervalIntegrable 0 (cumHazard h a) + rw [show (∫ y in (0:ℝ)..(cumHazard h a), rexp (-y)) = 1 - rexp (-(cumHazard h a)) from by + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt (fun y _ ↦ key y) hint] + norm_num [Real.exp_zero] + ring, + defaultDensity_antideriv hh a] + +/-- **Balance of the CDS legs under a time-varying intensity** (the headline): +the premium leg equals the protection leg iff the spread is the time-varying +fair spread `(1−R) · losses / annuity` — a direct instantiation of the +cash-flow balance `cdsFairSpread_TV_cash_flow_balance` at the concrete +integrals, with annuity-positivity discharged via `cdsAnnuity_pos`. -/ +theorem cdsFairSpreadTV_balances {r : ℝ} {h : ℝ → ℝ} (hh : Continuous h) {T : ℝ} + (hT : 0 < T) (c R : ℝ) : + premiumLeg c r h T = protectionLeg R r h T ↔ c = cdsFairSpreadTV r h R T := by + unfold premiumLeg protectionLeg cdsFairSpreadTV + exact cdsFairSpread_TV_cash_flow_balance c R _ _ (ne_of_gt (cdsAnnuity_pos hh hT)) + +/-- At constant intensity the time-varying annuity is the constant-intensity +risky annuity (the survival curve specializes via `hazardSurvival_eq_const_survival`). -/ +theorem cdsAnnuity_eq_riskyAnnuity (r lam T : ℝ) : + cdsAnnuity r (fun _ ↦ lam) T = riskyAnnuity r lam T := by + have hpt : ∀ s : ℝ, rexp (-(r * s)) * hazardSurvival (fun _ ↦ lam) s + = rexp (-((r + lam) * s)) := by + intro s + have hS : hazardSurvival (fun _ ↦ lam) s = rexp (-(lam * (s - 0))) := by + rw [hazardSurvival_eq_const_survival] + rfl + rw [hS, sub_zero, ← Real.exp_add] + congr 1 + ring + rw [cdsAnnuity, riskyAnnuity, intervalIntegral.integral_congr + (f := fun s : ℝ ↦ rexp (-(r * s)) * hazardSurvival (fun _ ↦ lam) s) + (g := fun s : ℝ ↦ rexp (-((r + lam) * s))) (fun s _ ↦ hpt s)] + +/-- At constant intensity the default-density integral is the hazard times the +annuity — the constant-intensity protection-leg closed form. -/ +theorem cdsLosses_eq_riskyAnnuity_mul (r lam T : ℝ) : + cdsLosses r (fun _ ↦ lam) T = lam * riskyAnnuity r lam T := by + have hpt : ∀ s : ℝ, rexp (-(r * s)) * (fun _ ↦ lam) s * hazardSurvival (fun _ ↦ lam) s + = lam * rexp (-((r + lam) * s)) := by + intro s + have hS : hazardSurvival (fun _ ↦ lam) s = rexp (-(lam * (s - 0))) := by + rw [hazardSurvival_eq_const_survival] + rfl + rw [hS, sub_zero] + change rexp (-(r * s)) * lam * rexp (-(lam * s)) = lam * rexp (-((r + lam) * s)) + rw [mul_comm (rexp (-(r * s))) lam, mul_assoc, ← Real.exp_add] + congr 1 + ring_nf + rw [cdsLosses, riskyAnnuity, intervalIntegral.integral_congr + (f := fun s : ℝ ↦ rexp (-(r * s)) * (fun _ ↦ lam) s * hazardSurvival (fun _ ↦ lam) s) + (g := fun s : ℝ ↦ lam * rexp (-((r + lam) * s))) (fun s _ ↦ hpt s), + intervalIntegral.integral_const_mul] + +/-- **The constant-`λ` case**: the time-varying fair spread at a +constant intensity collapses to the constant-hazard fair spread +`cdsFairSpread lam R = lam(1−R)`. -/ +theorem cdsFairSpreadTV_const (r lam R T : ℝ) (hT : 0 < T) : + cdsFairSpreadTV r (fun _ ↦ lam) R T = cdsFairSpread lam R := by + have hA : riskyAnnuity r lam T ≠ 0 := + ne_of_gt (riskyAnnuity_pos r lam T hT) + unfold cdsFairSpreadTV + rw [cdsAnnuity_eq_riskyAnnuity, cdsLosses_eq_riskyAnnuity_mul, + show cdsFairSpread lam R = lam * (1 - R) from rfl, div_eq_iff hA] + ring + +/-- **Default probability as the integral of the default density** +(deterministic-intensity Cox): for `a ≥ 0` the constructed default time satisfies +`P(τ ≤ a) = ∫₀^a h·S`. The discounted identity +`E[e^{−rτ}·1{τ ≤ a}] = ∫₀^a e^{−rs}h(s)S(s) ds` is `CVA.protectionLeg_eq_integral_coxDefaultTime` +(`Models/Credit/CVA.lean`). -/ +theorem cox_defaultProb_density {h : ℝ → ℝ} (hh : Continuous h) (hpos : ∀ s, 0 < h s) + (hdiv : Filter.Tendsto (cumHazard h) Filter.atTop Filter.atTop) + {ξ : Ω → ℝ} (hξmeas : Measurable ξ) (hξlaw : Measure.map ξ μ = expMeasure 1) + {a : ℝ} (ha : 0 ≤ a) : + μ {ω | coxDefaultTime h ξ ω ≤ a} + = ENNReal.ofReal (∫ s in (0:ℝ)..a, h s * hazardSurvival h s) := by + have : IsProbabilityMeasure (expMeasure 1) := isProbabilityMeasure_expMeasure one_pos + rw [cox_cdf_timeVarying hh hpos hdiv hξmeas hξlaw ha, + show ((1:ℝ≥0∞)) = ENNReal.ofReal 1 from ENNReal.ofReal_one.symm, + ← ENNReal.ofReal_sub 1 (le_of_lt (hazardSurvival_pos h a))] + congr 1 + exact (defaultDensity_antideriv hh a).symm + +end CDSUpgrade + +/-! ### Restricted Cox: the mixing identity -/ + +section Mixing + +variable {Ω₁ : Type*} {m₁ : MeasurableSpace Ω₁} {μ₁ : Measure Ω₁} + +/-- **The restricted-Cox mixing identity** — Fubini on the product of a path +space with the unit-exponential-clock space: +`(μ₁ ⊗ Exp(1)){(ω, ξ) : Λ_t(ω) < ξ} = ∫ e^{−Λ_t} dμ₁` (by `Measure.prod_apply`), +for any `Λ ≥ 0` with measurable time sections. No default time, intensity or path +regularity is involved; with `τ` hypothesized as the clock's crossing of `Λ`, it +is the mixed survival `P(τ > t) = E[e^{−Λ_t}]` (`cox_mixed_survival`). -/ +theorem cox_mixing_survival {Λ : ℝ → Ω₁ → ℝ} (hΛmeas : ∀ t, Measurable fun ω ↦ Λ t ω) + (hΛnn : ∀ t ω, 0 ≤ Λ t ω) (t : ℝ) : + (μ₁.prod (expMeasure 1)) {p : Ω₁ × ℝ | Λ t p.1 < p.2} + = ∫⁻ ω : Ω₁, ENNReal.ofReal (rexp (-(Λ t ω))) ∂μ₁ := by + have : IsProbabilityMeasure (expMeasure 1) := isProbabilityMeasure_expMeasure one_pos + have hmap : Measurable fun p : Ω₁ × ℝ ↦ (Λ t p.1, p.2) := + ((hΛmeas t).comp measurable_fst).prodMk measurable_snd + have hset : MeasurableSet {p : Ω₁ × ℝ | Λ t p.1 < p.2} := + hmap (measurableSet_lt measurable_fst measurable_snd) + rw [Measure.prod_apply hset] + refine lintegral_congr fun ω ↦ ?_ + have hpre : Prod.mk ω ⁻¹' {p : Ω₁ × ℝ | Λ t p.1 < p.2} = Set.Ioi (Λ t ω) := by + ext y + simp + rw [hpre] + exact expClock_Ioi (hΛnn t ω) + +/-- **Mixed survival of a restricted-Cox default time**: a `τ` on the product +space whose survival event at the single time `t` is the clock beating `Λ_t` +(hypothesis `hτ`) has survival `P(τ > t) = E[e^{−Λ_t}]` — `cox_mixing_survival` +rewritten by `hτ`. Constructing such a `τ` would need paths of `Λ` that are +continuous, strictly increasing and divergent with `Λ(0) = 0`; those are not +assumed, and the construction is not done here. -/ +theorem cox_mixed_survival {τ : Ω₁ × ℝ → ℝ} {Λ : ℝ → Ω₁ → ℝ} + (hΛmeas : ∀ t, Measurable fun ω ↦ Λ t ω) + (hΛnn : ∀ t ω, 0 ≤ Λ t ω) + {t : ℝ} (hτ : ∀ p : Ω₁ × ℝ, t < τ p ↔ Λ t p.1 < p.2) : + (μ₁.prod (expMeasure 1)) {p : Ω₁ × ℝ | t < τ p} + = ∫⁻ ω : Ω₁, ENNReal.ofReal (rexp (-(Λ t ω))) ∂μ₁ := by + have hset : {p : Ω₁ × ℝ | t < τ p} = {p : Ω₁ × ℝ | Λ t p.1 < p.2} := by + ext p + exact hτ p + rw [hset] + exact cox_mixing_survival hΛmeas hΛnn t + +end Mixing + +end MathFin.Cox diff --git a/LeanPool/MathFin/Models/Credit/Credit.lean b/LeanPool/MathFin/Models/Credit/Credit.lean new file mode 100644 index 0000000000..6e14adec96 --- /dev/null +++ b/LeanPool/MathFin/Models/Credit/Credit.lean @@ -0,0 +1,123 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.SpecialFunctions.Log.Basic + +/-! +# Reduced-form credit risk under constant hazard rate + +The simplest credit-risk model assumes a constant hazard (default-intensity) +rate `h ≥ 0`. The survival probability between `t` and `T` is + + `S(t, T) = exp(-(h · (T - t)))`, + +and the resulting credit spread (additional yield over the risk-free rate) +equals the hazard rate itself: + + `c(t, T) = -log(S(t, T)) / (T - t) = h`. + +This is structurally identical to the ZCB-yield identity in `ZCB.lean` +(`zcb_yield_eq_rate`), with the hazard `h` playing the role of the risk-free +rate. The continuous-time stochastic-intensity model (Cox process / doubly +stochastic Poisson) is gated on the Itô integral and is not formalized here. + +## Main definitions + +* `survivalProbability`: the survival probability `exp(-(h · (T - t)))` under a constant hazard + rate `h`. +* `cdsFairSpread`: the fair CDS spread `c = h · (1 − R)` under constant hazard with recovery `R`. + +## Main results + +* `survival_at_zero`: `S(T, T) = 1`. +* `survival_pos`: survival probability is positive. +* `creditSpread_eq_hazard`: under constant hazard, spread equals hazard. +* `survival_strictAnti_of_pos_hazard`: positive hazard → strictly decreasing + survival in horizon `T`. + +## References + +* [Duffie and Singleton (1999)][DuffieSingleton1999] +* [Jarrow and Turnbull][JarrowTurnbull] +* [D. Lando, *Credit Risk Modeling*][Lando2004], Ch 5 + +## Tags + +reduced-form credit risk, hazard rate, default intensity, credit spread, survival probability, +constant intensity, MSC 91G40, JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- Survival probability under a constant hazard rate `h`. -/ +noncomputable def survivalProbability (h t T : ℝ) : ℝ := + Real.exp (-(h * (T - t))) + +/-- At `T = t`, survival is 1 (no time elapsed). -/ +lemma survival_at_zero (h T : ℝ) : survivalProbability h T T = 1 := by + unfold survivalProbability + rw [sub_self, mul_zero, neg_zero, Real.exp_zero] + +/-- Survival probability is strictly positive. -/ +lemma survival_pos (h t T : ℝ) : 0 < survivalProbability h t T := Real.exp_pos _ + +/-- **Credit spread equals hazard rate** under constant hazard: +`-log(S(t, T)) / (T − t) = h`. -/ +lemma creditSpread_eq_hazard {h t T : ℝ} (htT : t < T) : + -Real.log (survivalProbability h t T) / (T - t) = h := by + unfold survivalProbability + rw [Real.log_exp, neg_neg] + have h_ne : T - t ≠ 0 := sub_ne_zero.mpr htT.ne' + field_simp + +/-- **Positive hazard ⇒ strictly decreasing survival in horizon `T`**. -/ +lemma survival_strictAnti_of_pos_hazard {h t : ℝ} (hh : 0 < h) : + StrictAntiOn (fun T ↦ survivalProbability h t T) (Set.Ici t) := by + intro T₁ _ T₂ _ hT + unfold survivalProbability + have h_arg : -(h * (T₂ - t)) < -(h * (T₁ - t)) := by + have : h * (T₁ - t) < h * (T₂ - t) := by + have : T₁ - t < T₂ - t := by linarith + exact mul_lt_mul_of_pos_left this hh + linarith + exact Real.exp_lt_exp.mpr h_arg + +/-! ## CDS fair spread with recovery (folded from `CDS.lean`) + +A CDS exchanges a periodic premium `c` for `(1 − R)` at default. Under +constant hazard `h` and risk-free rate `r`, both legs share the annuity +factor `(1 − e^{−(r+h) T}) / (r + h)`. Equating PVs gives the fair spread +`c = h · (1 − R)`. Specialises to `c = h` (the bare `creditSpread_eq_hazard`) +at zero recovery. -/ + +/-- **Fair CDS spread under constant hazard with recovery**: `c = h · (1 − R)`. -/ +noncomputable def cdsFairSpread (hh R : ℝ) : ℝ := hh * (1 - R) + +/-- **Zero recovery specialisation**: the fair spread equals the hazard rate. -/ +lemma cdsFairSpread_zero_recovery (hh : ℝ) : cdsFairSpread hh 0 = hh := by + unfold cdsFairSpread; ring + +/-- **Leg-equality characterisation**: with `factor` the common annuity factor, +the fair spread is the unique value equating premium and protection legs. -/ +theorem cds_leg_equality (hh R factor c : ℝ) (h_factor_ne : factor ≠ 0) : + c * factor = (1 - R) * hh * factor ↔ c = cdsFairSpread hh R := by + unfold cdsFairSpread + constructor + · intro heq + have := mul_right_cancel₀ h_factor_ne heq + linarith + · intro hc + rw [hc]; ring + +end MathFin diff --git a/LeanPool/MathFin/Models/Credit/DVA.lean b/LeanPool/MathFin/Models/Credit/DVA.lean new file mode 100644 index 0000000000..ad7fa301de --- /dev/null +++ b/LeanPool/MathFin/Models/Credit/DVA.lean @@ -0,0 +1,148 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Credit.CVA +public import Mathlib.Probability.Distributions.Gaussian.HasGaussianLaw.Basic + +/-! +# DVA as a CVA mirror + +Debt valuation adjustment is the counterparty's expected loss on the bank's *own* default, a gain +to the bank: `CVA.cva` applied to the bank's own default time and hazard and to the exposure seen +from the bank's side, `-V`. In `cva`'s convention `V > 0` means the counterparty owes the bank; the +bank owes the counterparty when `V < 0`, the regime `-V > 0`. On the bank's own default the +counterparty does not recover that liability in full, a loss to the counterparty booked as a gain +to the bank, whose liability is extinguished. The file defines `dva` from `cva` and derives its +integral and Gaussian forms from `cva`'s. + +`cva`'s independence hypothesis (the default time independent of the exposure, no wrong-way risk) +carries over unchanged, read as "the bank's own default is independent of the exposure". The +bank's and the counterparty's default times are not jointly modelled, so nothing is stated about a +correlated bilateral picture (both defaults together, wrong-way risk on either leg); that needs +their joint law and is out of scope. + +## Main definitions + +* `expectedNegativeExposure`: `ENE(s) = E_ν[(−V_s)⁺]`, the mirror of `CVA.expectedExposure`: the + expected exposure the counterparty has to the bank. +* `dva`: the bank's own-default mirror of `cva`, taken at the bank's own default time and hazard + with the exposure `-V` seen from the bank's side. + +## Main results + +* `expectedNegativeExposure_eq_sub_integral`: `ENE(s) = EE(s) − E[V_s]` for integrable `V_s`, from + the pointwise identity `(−x)⁺ = x⁺ − x`; `expectedNegativeExposure_gaussian` is its closed form + for `V_s = a + b√s Z` with `Z ~ N(0, 1)`, `b > 0` and `s > 0`. +* `dva_eq_integral_expectedNegativeExposure`: with the bank's default independent of the + exposure and a deterministic continuous hazard, + `DVA = LGD_B · ∫₀ᵀ D(s) · ENE(s) · λ(s)Q(s) ds`, the integral of the expected negative exposure + (`CVA.integral_exposure_eq` at `-V`). +* `dva_gaussian`: the Gaussian closed form, from `CVA.cva_gaussian` at the mirrored exposure + `-(m(s) + σ(s)√s Z) = -m(s) + σ(s)√s·(-Z)`, with `gaussianReal_neg` keeping the driver standard + normal. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull] (bilateral CVA/DVA). + +## Tags + +debt valuation adjustment, bilateral CVA, own default, expected negative exposure, +counterparty risk, credit adjustment, MSC 91G40, JEL G32 +-/ + +@[expose] public section + +namespace MathFin.CVA + +open MeasureTheory Real ProbabilityTheory MathFin.DefaultDensity + +variable {Ω₁ Ω₂ : Type*} {m₁ : MeasurableSpace Ω₁} {m₂ : MeasurableSpace Ω₂} + {ν : Measure Ω₁} {μ : Measure Ω₂} + +/-- Expected negative exposure `ENE(s) = E_ν[(-V_s)⁺]`, the mirror of `expectedExposure`. -/ +noncomputable def expectedNegativeExposure (V : ℝ → Ω₁ → ℝ) (ν : Measure Ω₁) (s : ℝ) : ℝ := + ∫ ω, max (-(V s ω)) 0 ∂ν + +/-- **ENE = EE − E[V]**: for `V_s` integrable, from `(-x)⁺ = x⁺ - x` pointwise and integral +linearity. -/ +theorem expectedNegativeExposure_eq_sub_integral {V : ℝ → Ω₁ → ℝ} {s : ℝ} + (hV : Integrable (V s) ν) : + expectedNegativeExposure V ν s = expectedExposure V ν s - ∫ ω, V s ω ∂ν := by + rw [expectedNegativeExposure, expectedExposure, ← integral_sub hV.pos_part hV] + congr with ω + linarith [max_zero_sub_max_neg_zero_eq_self (V s ω)] + +/-- **Gaussian expected negative exposure**: for `Z ~ N(0,1)`, `s > 0`, `b > 0`, +`E[(a + b√s Z)⁻] = E[(a+b√s Z)⁺] - a`, specializing `expectedNegativeExposure_eq_sub_integral` +to the exposure model of `CVA.expectedExposure_gaussian`, since `E[a + b√s Z] = a`. -/ +theorem expectedNegativeExposure_gaussian [IsProbabilityMeasure ν] {Z : Ω₁ → ℝ} + (hZ : HasLaw Z (gaussianReal 0 1) ν) {a b s : ℝ} (hb : 0 < b) (hs : 0 < s) : + expectedNegativeExposure (fun s ω ↦ a + b * √s * Z ω) ν s + = a * Phi (a / (b * √s)) + b * √s * gaussianPDFReal 0 1 (a / (b * √s)) - a := by + have hZi : Integrable Z ν := hZ.hasGaussianLaw.integrable + have hVi : Integrable (fun ω ↦ a + b * √s * Z ω) ν := + (integrable_const a).add (hZi.const_mul (b * √s)) + have hmean : ∫ ω, (a + b * √s * Z ω) ∂ν = a := by + rw [(gaussianReal_const_add (gaussianReal_const_mul hZ (b * √s)) a).integral_eq, + integral_id_gaussianReal] + ring + rw [expectedNegativeExposure_eq_sub_integral hVi, hmean, expectedExposure, + expectedExposure_gaussian hZ hb hs] + +/-- **DVA**: the bank's own-default mirror of `cva`, at the bank's own default time `τBank` and +the exposure `-V` seen from the bank's side. Default is independent of the exposure because `cva` +is an integral over the product measure `ν.prod μ`. -/ +noncomputable def dva (LGDBank : ℝ) (D : ℝ → ℝ) (V : ℝ → Ω₁ → ℝ) (τBank : Ω₂ → ℝ) (T : ℝ) + (ν : Measure Ω₁) (μ : Measure Ω₂) : ℝ := + cva LGDBank D (fun s ω ↦ -(V s ω)) τBank T ν μ + +/-- **DVA is the integral of the expected negative exposure**: with the bank's default time +`τBank` of deterministic continuous hazard `h ≥ 0` (CDF hypothesis `hcdf`), measurable `D`, +jointly measurable `V`, `T ≥ 0` and the integrand jointly integrable, +`DVA = LGD_B · ∫₀ᵀ D(s) · ENE(s) · λ(s)Q(s) ds`. This is `integral_exposure_eq` at `-V`, whose +expected exposure is `expectedNegativeExposure V`. -/ +theorem dva_eq_integral_expectedNegativeExposure [IsProbabilityMeasure ν] + [IsProbabilityMeasure μ] {h : ℝ → ℝ} (hh : Continuous h) (hnn : ∀ s, 0 ≤ h s) + {τBank : Ω₂ → ℝ} (hτ : Measurable τBank) + (hcdf : ∀ a, 0 ≤ a → μ {ω | τBank ω ≤ a} = 1 - ENNReal.ofReal (hazardSurvival h a)) + {D : ℝ → ℝ} (hD : Measurable D) {V : ℝ → Ω₁ → ℝ} (hV : Measurable (Function.uncurry V)) + (LGDBank : ℝ) {T : ℝ} (hT : 0 ≤ T) + (hint : Integrable (fun p : Ω₁ × Ω₂ ↦ + (Set.Iic T).indicator D (τBank p.2) * max (-V (τBank p.2) p.1) 0) (ν.prod μ)) : + dva LGDBank D V τBank T ν μ + = LGDBank * ∫ s in (0:ℝ)..T, D s * expectedNegativeExposure V ν s * defaultDensity h s := + congrArg (LGDBank * ·) + (integral_exposure_eq (V := fun s ω ↦ -(V s ω)) hh hnn hτ hcdf hD hV.neg hT hint) + +/-- **DVA with Gaussian exposure, no wrong-way risk**: `dva` equals `LGDBank · ∫₀..T D(s) · +[(-m(s))·Φ((-m(s))/(σ(s)√s)) + σ(s)√s·φ((-m(s))/(σ(s)√s))] · defaultDensity h s ds` — +`cva_gaussian`'s right-hand side with `m` replaced by `-m`, from `cva_gaussian` at the mirrored +exposure `-(m(s) + σ(s)√s Z) = -m(s) + σ(s)√s·(-Z)`; `gaussianReal_neg` keeps the driver `-Z` +standard normal. -/ +theorem dva_gaussian [IsProbabilityMeasure ν] [IsProbabilityMeasure μ] + {h : ℝ → ℝ} (hh : Continuous h) (hnn : ∀ s, 0 ≤ h s) {τBank : Ω₂ → ℝ} + (hτ : Measurable τBank) + (hcdf : ∀ a, 0 ≤ a → μ {ω | τBank ω ≤ a} = 1 - ENNReal.ofReal (hazardSurvival h a)) + {D : ℝ → ℝ} (hD : Measurable D) {C : ℝ} (hDb : ∀ s, |D s| ≤ C) {m σ : ℝ → ℝ} + (hm : Measurable m) (hσ : Measurable σ) {M S : ℝ} (hmb : ∀ s, |m s| ≤ M) + (hσpos : ∀ s, 0 < σ s) (hσb : ∀ s, σ s ≤ S) {Z : Ω₁ → ℝ} (hZm : Measurable Z) + (hZ : HasLaw Z (gaussianReal 0 1) ν) (LGDBank : ℝ) {T : ℝ} (hT : 0 ≤ T) : + dva LGDBank D (fun s ω ↦ m s + σ s * √s * Z ω) τBank T ν μ + = LGDBank * ∫ s in (0:ℝ)..T, D s * ((-m s) * Phi ((-m s) / (σ s * √s)) + + σ s * √s * gaussianPDFReal 0 1 ((-m s) / (σ s * √s))) * defaultDensity h s := by + have hZ' : HasLaw (fun ω ↦ -(Z ω)) (gaussianReal 0 1) ν := + (neg_zero : -(0:ℝ) = 0) ▸ gaussianReal_neg hZ + have heq : (fun s ω ↦ -(m s + σ s * √s * Z ω)) = fun s ω ↦ (-m s) + σ s * √s * (-(Z ω)) := by + funext s ω; ring + have hmb' : ∀ s, |(-m s)| ≤ M := fun s ↦ (abs_neg (m s)).le.trans (hmb s) + rw [dva, heq] + exact cva_gaussian hh hnn hτ hcdf hD hDb hm.neg hσ hmb' hσpos hσb hZm.neg hZ' LGDBank hT + +end MathFin.CVA diff --git a/LeanPool/MathFin/Models/Credit/DefaultDensity.lean b/LeanPool/MathFin/Models/Credit/DefaultDensity.lean new file mode 100644 index 0000000000..f2c167f0da --- /dev/null +++ b/LeanPool/MathFin/Models/Credit/DefaultDensity.lean @@ -0,0 +1,259 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Credit.HazardCurve +public import LeanPool.MathFin.Models.Credit.Cox + +/-! +# The default-time density of a deterministic hazard curve + +Bagaria ch. 16, Calculation 16.2 (eq. 16.2): the protection leg is +`(1 − R) ∫₀ᵀ P(0,t) λ_t Q(t) dt`, with the remark "`−dQ/dt = λ_t Q(t)`, so this is +the loss integrated against the density of the default time". Survival is (16.1), +`Q(t) = P(τ > t) = exp(−∫₀ᵗ λ_s ds)`, taken with `λ` deterministic as in §16.1. + +Here `Q = hazardSurvival h` (`Models/Credit/HazardCurve.lean`) and the density is +`defaultDensity h t = h t · hazardSurvival h t`. + +## Calculus layer (no probability) + +* `hasDerivAt_hazardSurvival` — `Q' = −λ·Q` at `t`, for `h` locally integrable and + continuous at `t`. +* `defaultDensity_nonneg` — `λ ≥ 0 ⇒ f ≥ 0`. +* `integral_defaultDensity` — `∫ₐᵇ f = Q(a) − Q(b)` for continuous `h`; + `integral_defaultDensity_zero` — `∫₀ᵀ f = 1 − Q(T)`. + +## Measure-theoretic layer (a true Lebesgue density of `τ`'s law) + +For a random time `τ` (a.e.-measurable, finite measure space) whose CDF on `[0, ∞)` is +`P(τ ≤ a) = 1 − Q(a)` — **hypothesized**, the shape of +`MathFin.Cox.cox_cdf_timeVarying` — with `h` continuous and `≥ 0`: + +* `map_eq_withDensity` — `Law(τ) = Leb.withDensity (1_{[0,∞)}·f)` (`lawDensity`). +* `integral_comp_eq` — `E[g(τ)] = ∫_{[0,∞)} f·g` for measurable `g`. +* `integral_indicator_Iic_eq` — `E[D(τ)·1{τ ≤ T}] = ∫₀ᵀ D·f`: the (16.2) protection-leg + kernel as an expectation, for any measurable discount curve `D`. +* `expMeasure_eq_withDensity` — constant-`λ` cross-check: `lawDensity` of the flat curve + is Mathlib's `expMeasure λ`. + +Scope: deterministic, *continuous* hazard (the bootstrapped piecewise-constant curve of +§16.4 is not covered); `τ` is not constructed here, and the stochastic-intensity (Cox +mixing) density is not treated. + +## Main definitions + +* `defaultDensity`: the default-time density `f(t) = λ(t)·Q(t) = λ(t)·exp(−∫₀ᵗ λ)` of a + deterministic hazard curve `h`. +* `lawDensity`: the density of the law of `τ` as an `ℝ≥0∞`-valued function, `f` on `[0, ∞)` and + zero on `(−∞, 0)`. + +## Main results + +* `hasDerivAt_hazardSurvival`: `−dQ/dt = λ·Q`, for a locally integrable hazard `h` continuous at + `t`. +* `integral_defaultDensity`, `integral_defaultDensity_zero`: `∫ₐᵇ f = Q(a) − Q(b)` and + `∫₀ᵀ f = 1 − Q(T)` for a continuous hazard. +* `map_eq_withDensity`: for a continuous nonnegative hazard `h` and an a.e.-measurable `τ` with CDF + `P(τ ≤ a) = 1 − Q(a)` on `[0, ∞)`, the law of `τ` is `volume.withDensity (lawDensity h)`. +* `integral_comp_eq`: under the same hypotheses, `E[g(τ)] = ∫_{[0,∞)} f(s)·g(s) ds` for + measurable `g`. +* `integral_indicator_Iic_eq`: under the same hypotheses, `E[D(τ)·1{τ ≤ T}] = ∫₀ᵀ D(s)·λ(s)·Q(s) ds` + for measurable `D` and `T ≥ 0`. +* `expMeasure_eq_withDensity`: for constant hazard `λ > 0`, `lawDensity` reproduces Mathlib's + exponential law. + +## References + +* [S. Bagaria, *Notes on Fixed Income Derivative Pricing*][BagariaFIDP], ch. 16. + +## Tags + +default density, hazard rate, survival function, protection leg, default time law, CDS pricing, +MSC 91G40, MSC 60E05, JEL G12 +-/ + +@[expose] public section + +namespace MathFin.DefaultDensity + +open MeasureTheory Real + +/-- The **default-time density** `f(t) = λ(t)·Q(t) = λ(t)·exp(−∫₀ᵗ λ)` of a deterministic +hazard curve `h` (Bagaria ch. 16, Calculation 16.2). As a function on all of `ℝ`; the law +of `τ` uses its restriction to `[0, ∞)` (see `map_eq_withDensity`). -/ +noncomputable def defaultDensity (h : ℝ → ℝ) (t : ℝ) : ℝ := h t * hazardSurvival h t + +/-- **`−dQ/dt = λ·Q`** (Bagaria ch. 16, Calc. 16.2): for a locally integrable hazard `h` +continuous at `t`, the survival curve has derivative `−f(t)` at `t`. FTC for +`∫₀ᵗ h` composed with `exp`. -/ +theorem hasDerivAt_hazardSurvival {h : ℝ → ℝ} (hloc : LocallyIntegrable h) {t : ℝ} + (ht : ContinuousAt h t) : + HasDerivAt (hazardSurvival h) (-defaultDensity h t) t := by + have hH : HasDerivAt (cumHazard h) (h t) t := + intervalIntegral.integral_hasDerivAt_right + ((hloc.integrableOn_isCompact isCompact_uIcc).intervalIntegrable) + (hloc.aestronglyMeasurable.stronglyMeasurableAtFilter) ht + have h2 : HasDerivAt (fun s ↦ rexp (-cumHazard h s)) (rexp (-cumHazard h t) * -h t) t := + hH.neg.exp + convert h2 using 1 + · rfl + · simp only [defaultDensity, hazardSurvival, survivalFromIntensity, cumHazard] + ring + +/-- The density is nonnegative under a nonnegative hazard (`Q > 0` always). -/ +theorem defaultDensity_nonneg {h : ℝ → ℝ} (hnn : ∀ s, 0 ≤ h s) (t : ℝ) : + 0 ≤ defaultDensity h t := + mul_nonneg (hnn t) (hazardSurvival_pos h t).le + +/-- The density is continuous for a continuous hazard. -/ +theorem continuous_defaultDensity {h : ℝ → ℝ} (hh : Continuous h) : + Continuous (defaultDensity h) := + hh.mul (continuous_iff_continuousAt.2 fun _ ↦ + (hasDerivAt_hazardSurvival hh.locallyIntegrable hh.continuousAt).continuousAt) + +/-- **Interval default probability**: `∫ₐᵇ f = Q(a) − Q(b)` for a continuous hazard. -/ +theorem integral_defaultDensity {h : ℝ → ℝ} (hh : Continuous h) (a b : ℝ) : + ∫ s in a..b, defaultDensity h s = hazardSurvival h a - hazardSurvival h b := by + have hd : ∀ s, HasDerivAt (fun u ↦ -hazardSurvival h u) (defaultDensity h s) s := fun s ↦ by + have := (hasDerivAt_hazardSurvival hh.locallyIntegrable hh.continuousAt (t := s)).neg + rw [neg_neg] at this + exact this + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt (fun s _ ↦ hd s) + ((continuous_defaultDensity hh).intervalIntegrable a b)] + ring + +/-- **Default probability by `T`**: `∫₀ᵀ f = 1 − Q(T)` (calculus identity; no `τ`). This is +`MathFin.Cox.defaultDensity_antideriv`, restated through `defaultDensity` and +`hazardSurvival`. -/ +theorem integral_defaultDensity_zero {h : ℝ → ℝ} (hh : Continuous h) (T : ℝ) : + ∫ s in (0:ℝ)..T, defaultDensity h s = 1 - hazardSurvival h T := + MathFin.Cox.defaultDensity_antideriv hh T + +/-! ### Measure-theoretic layer: `f` is the Lebesgue density of the law of `τ` -/ + +section Law + +open scoped ENNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + +/-- The density of `τ`'s law as an `ℝ≥0∞`-valued function: `f` on `[0, ∞)`, zero on +`(−∞, 0)`. -/ +noncomputable def lawDensity (h : ℝ → ℝ) : ℝ → ℝ≥0∞ := + (Set.Ici 0).indicator fun s ↦ ENNReal.ofReal (defaultDensity h s) + +/-- `lawDensity h` is measurable for a continuous hazard. -/ +theorem measurable_lawDensity {h : ℝ → ℝ} (hh : Continuous h) : Measurable (lawDensity h) := + ((continuous_defaultDensity hh).measurable.ennreal_ofReal).indicator measurableSet_Ici + +/-- Mass of `(−∞, a]` under `Leb.withDensity (lawDensity h)`, for `a ≥ 0`: `1 − Q(a)`. -/ +theorem withDensity_Iic {h : ℝ → ℝ} (hh : Continuous h) (hnn : ∀ s, 0 ≤ h s) {a : ℝ} + (ha : 0 ≤ a) : + volume.withDensity (lawDensity h) (Set.Iic a) = ENNReal.ofReal (1 - hazardSurvival h a) := by + rw [withDensity_apply _ measurableSet_Iic, lawDensity, + lintegral_indicator measurableSet_Ici, Measure.restrict_restrict measurableSet_Ici, + Set.Ici_inter_Iic, ← integral_defaultDensity_zero hh a, intervalIntegral.integral_of_le ha, + ← integral_Icc_eq_integral_Ioc, ofReal_integral_eq_lintegral_ofReal] + · exact (continuous_defaultDensity hh).continuousOn.integrableOn_Icc + · exact Filter.Eventually.of_forall fun s ↦ defaultDensity_nonneg hnn s + +/-- `Leb.withDensity (lawDensity h)` puts no mass on `(−∞, a]` for `a < 0`. -/ +theorem withDensity_Iic_neg (h : ℝ → ℝ) {a : ℝ} (ha : a < 0) : + volume.withDensity (lawDensity h) (Set.Iic a) = 0 := by + rw [withDensity_apply _ measurableSet_Iic, lawDensity, + lintegral_indicator measurableSet_Ici, Measure.restrict_restrict measurableSet_Ici, + Set.Ici_inter_Iic, Set.Icc_eq_empty (by linarith), Measure.restrict_empty, + lintegral_zero_measure] + +/-- **The default-time density, measure-theoretically.** Let `h` be a continuous, +nonnegative hazard curve and `τ` an a.e.-measurable random time on a finite measure space +whose CDF on `[0, ∞)` is `P(τ ≤ a) = 1 − Q(a)` (`Q = hazardSurvival h`). Then the law of +`τ` is absolutely continuous with Lebesgue density `f = λ·Q` on `[0, ∞)` (zero on +`(−∞, 0)`): + + `Law(τ) = Leb.withDensity (1_{[0,∞)} · ofReal (λ·Q))`. + +The CDF hypothesis has exactly the shape of the Cox-construction CDF identity +`MathFin.Cox.cox_cdf_timeVarying` (`Models/Credit/Cox.lean`); `τ` is hypothesized, +not constructed, here. -/ +theorem map_eq_withDensity [IsFiniteMeasure μ] {h : ℝ → ℝ} (hh : Continuous h) + (hnn : ∀ s, 0 ≤ h s) {τ : Ω → ℝ} (hτ : AEMeasurable τ μ) + (hcdf : ∀ a, 0 ≤ a → μ {ω | τ ω ≤ a} = 1 - ENNReal.ofReal (hazardSurvival h a)) : + μ.map τ = volume.withDensity (lawDensity h) := by + refine Measure.ext_of_Iic _ _ fun a ↦ ?_ + rw [Measure.map_apply_of_aemeasurable hτ measurableSet_Iic] + rcases lt_or_ge a 0 with ha | ha + · rw [withDensity_Iic_neg h ha] + refine nonpos_iff_eq_zero.mp ?_ + calc μ (τ ⁻¹' Set.Iic a) ≤ μ {ω | τ ω ≤ 0} := + measure_mono fun ω (hω : τ ω ≤ a) ↦ show τ ω ≤ 0 by linarith + _ = 0 := by rw [hcdf 0 le_rfl, hazardSurvival_at_zero, ENNReal.ofReal_one, tsub_self] + · rw [withDensity_Iic hh hnn ha, show τ ⁻¹' Set.Iic a = {ω | τ ω ≤ a} from rfl, hcdf a ha, + ENNReal.ofReal_sub _ (hazardSurvival_pos h a).le, ENNReal.ofReal_one] + +/-- **Expectations against the default time** (change of variables through the law): +for measurable `g`, `E[g(τ)] = ∫_{[0,∞)} f(s)·g(s) ds` — no integrability needed (both +sides are Bochner integrals, `0` together when non-integrable). -/ +theorem integral_comp_eq [IsFiniteMeasure μ] {h : ℝ → ℝ} (hh : Continuous h) + (hnn : ∀ s, 0 ≤ h s) {τ : Ω → ℝ} (hτ : AEMeasurable τ μ) + (hcdf : ∀ a, 0 ≤ a → μ {ω | τ ω ≤ a} = 1 - ENNReal.ofReal (hazardSurvival h a)) + {g : ℝ → ℝ} (hg : Measurable g) : + ∫ ω, g (τ ω) ∂μ = ∫ s in Set.Ici 0, defaultDensity h s * g s := by + rw [← integral_map hτ hg.aestronglyMeasurable, map_eq_withDensity hh hnn hτ hcdf, + integral_withDensity_eq_integral_toReal_smul (measurable_lawDensity hh) + (Filter.Eventually.of_forall fun s ↦ by + unfold lawDensity; by_cases hs : s ∈ Set.Ici (0:ℝ) <;> simp [hs]), + ← integral_indicator measurableSet_Ici] + congr 1 + funext s + by_cases hs : s ∈ Set.Ici (0:ℝ) + · simp [lawDensity, hs, ENNReal.toReal_ofReal (defaultDensity_nonneg hnn s)] + · simp [lawDensity, hs] + +/-- **The protection-leg kernel as an expectation** (Bagaria ch. 16, Calc. 16.2 / eq. 16.2, +undiscounted loss `1 − R` factored out): for any measurable discount curve `D` (e.g. +`D t = P(0,t)`) and `T ≥ 0`, + + `E[D(τ)·1{τ ≤ T}] = ∫₀ᵀ D(s)·λ(s)·Q(s) ds`. -/ +theorem integral_indicator_Iic_eq [IsFiniteMeasure μ] {h : ℝ → ℝ} (hh : Continuous h) + (hnn : ∀ s, 0 ≤ h s) {τ : Ω → ℝ} (hτ : AEMeasurable τ μ) + (hcdf : ∀ a, 0 ≤ a → μ {ω | τ ω ≤ a} = 1 - ENNReal.ofReal (hazardSurvival h a)) + {D : ℝ → ℝ} (hD : Measurable D) {T : ℝ} (hT : 0 ≤ T) : + ∫ ω, (Set.Iic T).indicator D (τ ω) ∂μ = ∫ s in (0:ℝ)..T, D s * defaultDensity h s := by + rw [integral_comp_eq hh hnn hτ hcdf (hD.indicator measurableSet_Iic), + intervalIntegral.integral_of_le hT, ← integral_Icc_eq_integral_Ioc, ← Set.Ici_inter_Iic, + Set.inter_comm, ← Measure.restrict_restrict measurableSet_Iic, + ← integral_indicator measurableSet_Iic] + congr 1 + funext s + by_cases hs : s ∈ Set.Iic T + · simp [hs, mul_comm] + · simp [hs] + +/-- **Cross-check against Mathlib's exponential law** (constant hazard `λ > 0`): the +`lawDensity` of the flat curve reproduces `expMeasure λ`, the law that +`MathFin.PoissonInterarrival.map_firstArrival_eq_expMeasure` +(`Probability/Jumps/PoissonInterarrival.lean`) assigns to the first arrival of a rate-`λ` Poisson +process. Obtained from `map_eq_withDensity` with `τ = id`. -/ +theorem expMeasure_eq_withDensity {r : ℝ} (hr : 0 < r) : + ProbabilityTheory.expMeasure r = volume.withDensity (lawDensity fun _ ↦ r) := by + have := ProbabilityTheory.isProbabilityMeasure_expMeasure hr + have hS : ∀ a, hazardSurvival (fun _ ↦ r) a = rexp (-(r * a)) := fun a ↦ by + unfold hazardSurvival survivalFromIntensity + rw [show cumulativeIntensity (fun _ ↦ r) a = r * a from cumHazard_const r a] + have := map_eq_withDensity (μ := ProbabilityTheory.expMeasure r) (τ := id) continuous_const + (fun _ ↦ hr.le) aemeasurable_id fun a ha ↦ by + rw [show {ω : ℝ | id ω ≤ a} = Set.Iic a from rfl, ← ProbabilityTheory.ofReal_cdf, + ProbabilityTheory.cdf_expMeasure_eq hr, ite_eq_left ha, hS, + ENNReal.ofReal_sub _ (Real.exp_pos _).le, ENNReal.ofReal_one] + rwa [Measure.map_id] at this + +end Law + +end MathFin.DefaultDensity diff --git a/LeanPool/MathFin/Models/Credit/DefaultTime.lean b/LeanPool/MathFin/Models/Credit/DefaultTime.lean new file mode 100644 index 0000000000..1dab086262 --- /dev/null +++ b/LeanPool/MathFin/Models/Credit/DefaultTime.lean @@ -0,0 +1,329 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Contracts.Instruments.Credit +public import LeanPool.MathFin.Pricing.Value +public import LeanPool.MathFin.Models.Credit.Cox +public import LeanPool.MathFin.Models.Credit.CVA + +/-! +# The credit default swap priced against a default time + +`Contracts/Instruments/Credit.lean` writes the CDS on a payment grid as a contract that observes +the default indicator `N u = 1{τ ≤ u}`. Here a default time `τ : Ω → ℝ` is the model: +`defaultIndicator τ` reads `N` off it, so each leg is a finite sum of discounted values +`𝔼[N u] = Q(τ ≤ u)`. Given the survival function `S` (`Q(τ ≤ u) = 1 − S u`) the legs are worth + +* the premium leg, `s` times the **grid annuity** `∑ D(tᵢ₊₁) (tᵢ₊₁ − tᵢ) S(tᵢ₊₁)` + (`cdsAnnuityGrid`, `value_cdsPremiumLeg`); +* the protection leg, `1 − R` times the **grid losses** `∑ D(tᵢ₊₁) (S tᵢ − S tᵢ₊₁)` + (`cdsLossesGrid`, `value_cdsProtectionLeg`); + +and the protection buyer's CDS is worth their difference (`value_cdsBuyer`), zero exactly at the +**grid par spread** `(1 − R) · losses / annuity` (`value_cdsBuyer_eq_zero_iff`). These are the +discrete analogues of `Cox.cdsAnnuity`, `Cox.cdsLosses` and `Cox.cdsFairSpreadTV`. + +The Cox default time of `Models/Credit/Cox.lean`, built by inverting a unit-exponential clock +through the cumulative hazard, has `S = hazardSurvival h` (`cox_cdf_timeVarying`), so under it the +CDS contract is worth the grid legs of the hazard curve (`value_cdsBuyer_coxDefaultTime`). The +protection leg paid at `τ` itself is the contract `cdsProtectionAtDefault` (`Contract.payAtHit` on +the default indicator): its value is `(1 − R)·𝔼[D(τ)·1{τ ≤ T}]` (`value_cdsProtectionAtDefault`), +which under the Cox default time at a flat rate is `Cox.protectionLeg` +(`value_cdsProtectionAtDefault_coxDefaultTime`, by `CVA.protectionLeg_eq_integral_coxDefaultTime`). +Against the continuous legs: with no discounting the grid losses on any grid from `0` to `T` +telescope to the default probability `1 − S(T)`, which is `Cox.cdsLosses 0 h T` +(`cdsLossesGrid_one_eq_cdsLosses`). With discounting the grid legs converge to the continuous ones +as the mesh goes to zero (`Models/Credit/DefaultTimeMesh.lean`). + +## Main definitions + +* `defaultIndicator` — the process `N u = 1{τ ≤ u}` as a model. +* `cdsAnnuityGrid`, `cdsLossesGrid`, `cdsParSpreadGrid`. + +## Main results + +* `value_cdsPremiumLeg`, `value_cdsProtectionLeg`, `value_cdsBuyer`, `value_cdsBuyer_eq_zero_iff`. +* `value_cdsBuyer_coxDefaultTime`, `cdsLossesGrid_one_eq_cdsLosses`. +* `hitTime_defaultIndicator`, `pathPV_cdsProtectionAtDefault`, `value_cdsProtectionAtDefault`, + `value_cdsProtectionAtDefault_coxDefaultTime` — the protection leg paid at the default time. + +## References + +* [S. Bagaria, *Notes on Fixed Income Derivative Pricing*][BagariaFIDP], ch. 16 +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [D. Lando, *Credit Risk Modeling*][Lando2004], ch. 5 +* [S. Peyton Jones, J. M. Eber and J. Seward, *Composing contracts*][PeytonJonesEberSeward2000] + +## Tags + +credit default swap, default time, survival probability, par spread, Cox process, hazard rate, +protection leg, MSC 91G40, JEL G12, JEL G33 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +namespace MathFin.Contracts + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- The default indicator process of a default time `τ`, `N u = 1{τ ≤ u}`, as the model of the +single underlying `()`. -/ +noncomputable def defaultIndicator (τ : Ω → ℝ) : Unit → ℝ≥0 → Ω → ℝ := + fun _ u ↦ {ω | τ ω ≤ u}.indicator 1 + +/-- The **grid annuity** (premium-leg kernel) of the survival function `S` on the grid `t`: +`∑ D(tᵢ₊₁) (tᵢ₊₁ − tᵢ) S(tᵢ₊₁)`. -/ +noncomputable def cdsAnnuityGrid (D : ℝ≥0 → ℝ) (S : ℝ → ℝ) (t : ℕ → ℝ≥0) (n : ℕ) : ℝ := + ∑ i ∈ Finset.range n, D (t (i + 1)) * (((t (i + 1) : ℝ) - t i) * S (t (i + 1))) + +/-- The **grid losses** (protection-leg kernel): `∑ D(tᵢ₊₁) (S tᵢ − S tᵢ₊₁)`, the discounted +probabilities of defaulting in each period. -/ +noncomputable def cdsLossesGrid (D : ℝ≥0 → ℝ) (S : ℝ → ℝ) (t : ℕ → ℝ≥0) (n : ℕ) : ℝ := + ∑ i ∈ Finset.range n, D (t (i + 1)) * (S (t i) - S (t (i + 1))) + +/-- The **grid par spread** `(1 − R) · losses / annuity`. -/ +noncomputable def cdsParSpreadGrid (D : ℝ≥0 → ℝ) (S : ℝ → ℝ) (t : ℕ → ℝ≥0) (R : ℝ) (n : ℕ) : ℝ := + (1 - R) * cdsLossesGrid D S t n / cdsAnnuityGrid D S t n + +section Value + +variable {Q : Measure Ω} [IsProbabilityMeasure Q] {τ : Ω → ℝ} {S : ℝ → ℝ} + +private theorem integrable_defaultIndicator (hτ : Measurable τ) (u : ℝ≥0) : + Integrable (defaultIndicator τ () u) Q := + (integrable_const (1 : ℝ)).indicator (measurableSet_le hτ measurable_const) + +private theorem integrable_one_sub_defaultIndicator (hτ : Measurable τ) (u : ℝ≥0) : + Integrable (fun ω ↦ 1 - defaultIndicator τ () u ω) Q := + (integrable_const (1 : ℝ)).sub (integrable_defaultIndicator hτ u) + +private theorem integrable_sub_defaultIndicator (hτ : Measurable τ) (u v : ℝ≥0) : + Integrable (fun ω ↦ defaultIndicator τ () u ω - defaultIndicator τ () v ω) Q := + (integrable_defaultIndicator hτ u).sub (integrable_defaultIndicator hτ v) + +omit [IsProbabilityMeasure Q] in +private theorem integral_defaultIndicator (hτ : Measurable τ) + (hS : ∀ u : ℝ≥0, Q.real {ω | τ ω ≤ u} = 1 - S u) (u : ℝ≥0) : + ∫ ω, defaultIndicator τ () u ω ∂Q = 1 - S u := by + rw [← hS u] + exact integral_indicator_one (measurableSet_le hτ measurable_const) + +/-- **The premium leg is `s` times the grid annuity.** Against a default time `τ` with survival +function `S` (`Q(τ ≤ u) = 1 − S u`), the premium leg of the CDS is worth `s` times +`cdsAnnuityGrid D S t n`. -/ +theorem value_cdsPremiumLeg (hτ : Measurable τ) (hS : ∀ u : ℝ≥0, Q.real {ω | τ ω ≤ u} = 1 - S u) + (D : ℝ≥0 → ℝ) (t : ℕ → ℝ≥0) (s : ℝ) (n : ℕ) : + (cdsPremiumLeg t s n).value Q (fun t _ ↦ D t) (defaultIndicator τ) + = s * cdsAnnuityGrid D S t n := by + simp only [Contract.value, pathPV_cdsPremiumLeg, scenarioAt, cdsAnnuityGrid, Finset.mul_sum] + rw [integral_finsetSum _ fun i _ ↦ + ((integrable_one_sub_defaultIndicator hτ (t (i + 1))).const_mul _).const_mul _] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [integral_const_mul, integral_const_mul, integral_sub (integrable_const 1) + (integrable_defaultIndicator hτ _), integral_defaultIndicator hτ hS] + simp + ring + +/-- **The protection leg is `1 − R` times the grid losses.** -/ +theorem value_cdsProtectionLeg (hτ : Measurable τ) + (hS : ∀ u : ℝ≥0, Q.real {ω | τ ω ≤ u} = 1 - S u) (D : ℝ≥0 → ℝ) (t : ℕ → ℝ≥0) (R : ℝ) + (n : ℕ) : + (cdsProtectionLeg t R n).value Q (fun t _ ↦ D t) (defaultIndicator τ) + = (1 - R) * cdsLossesGrid D S t n := by + simp only [Contract.value, pathPV_cdsProtectionLeg, scenarioAt, cdsLossesGrid, Finset.mul_sum] + rw [integral_finsetSum _ fun i _ ↦ + ((integrable_sub_defaultIndicator hτ (t (i + 1)) (t i)).const_mul _).const_mul _] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [integral_const_mul, integral_const_mul, integral_sub (integrable_defaultIndicator hτ _) + (integrable_defaultIndicator hτ _), integral_defaultIndicator hτ hS, + integral_defaultIndicator hτ hS] + ring + +private theorem integrable_pathPV_cdsPremiumLeg (hτ : Measurable τ) (D : ℝ≥0 → ℝ) + (t : ℕ → ℝ≥0) (s : ℝ) (n : ℕ) : + Integrable (fun ω ↦ (cdsPremiumLeg t s n).pathPV D (scenarioAt (defaultIndicator τ) ω)) Q := by + simp only [pathPV_cdsPremiumLeg] + exact integrable_finsetSum _ fun i _ ↦ + ((integrable_one_sub_defaultIndicator hτ _).const_mul _).const_mul _ + +private theorem integrable_pathPV_cdsProtectionLeg (hτ : Measurable τ) (D : ℝ≥0 → ℝ) + (t : ℕ → ℝ≥0) (R : ℝ) (n : ℕ) : + Integrable + (fun ω ↦ (cdsProtectionLeg t R n).pathPV D (scenarioAt (defaultIndicator τ) ω)) Q := by + simp only [pathPV_cdsProtectionLeg] + exact integrable_finsetSum _ fun i _ ↦ + ((integrable_sub_defaultIndicator hτ _ _).const_mul _).const_mul _ + +/-- **The protection buyer's CDS is worth protection less premium**: `(1 − R)` times the grid +losses minus `s` times the grid annuity. -/ +theorem value_cdsBuyer (hτ : Measurable τ) (hS : ∀ u : ℝ≥0, Q.real {ω | τ ω ≤ u} = 1 - S u) + (D : ℝ≥0 → ℝ) (t : ℕ → ℝ≥0) (s R : ℝ) (n : ℕ) : + (cdsBuyer t s R n).value Q (fun t _ ↦ D t) (defaultIndicator τ) + = (1 - R) * cdsLossesGrid D S t n - s * cdsAnnuityGrid D S t n := by + have hprem : Integrable (fun ω ↦ (Contract.scale (-1) (cdsPremiumLeg t s n)).pathPV D + (scenarioAt (defaultIndicator τ) ω)) Q := by + simp only [Contract.pathPV_scale] + exact (integrable_pathPV_cdsPremiumLeg hτ D t s n).const_mul _ + rw [cdsBuyer, Contract.value_both _ _ _ _ _ (integrable_pathPV_cdsProtectionLeg hτ D t R n) hprem, + Contract.value_scale, value_cdsProtectionLeg hτ hS, value_cdsPremiumLeg hτ hS] + ring + +/-- **The buyer's CDS is worth zero exactly at the grid par spread** (nonzero annuity). -/ +theorem value_cdsBuyer_eq_zero_iff (hτ : Measurable τ) + (hS : ∀ u : ℝ≥0, Q.real {ω | τ ω ≤ u} = 1 - S u) (D : ℝ≥0 → ℝ) (t : ℕ → ℝ≥0) (s R : ℝ) + (n : ℕ) (hA : cdsAnnuityGrid D S t n ≠ 0) : + (cdsBuyer t s R n).value Q (fun t _ ↦ D t) (defaultIndicator τ) = 0 + ↔ s = cdsParSpreadGrid D S t R n := by + rw [value_cdsBuyer hτ hS, cdsParSpreadGrid, eq_div_iff hA, sub_eq_zero, eq_comm] + +end Value + +/-! ### The protection leg paid at the default time -/ + +section AtDefault + +variable {μ : Measure Ω} + +private theorem defaultIndicator_mem_Ici (τ : Ω → ℝ) (ω : Ω) (u : ℝ≥0) : + defaultIndicator τ () u ω ∈ Set.Ici (1 : ℝ) ↔ τ ω ≤ u := by + by_cases h : τ ω ≤ u <;> norm_num [defaultIndicator, Set.indicator, h] + +/-- **The default indicator hits `[1, ∞)` at the default time**: the first time the observed +process `N u = 1{τ ≤ u}` reaches `1` is `τ`, or `0` if `τ` is negative. -/ +theorem hitTime_defaultIndicator (τ : Ω → ℝ) (ω : Ω) : + (scenarioAt (defaultIndicator τ) ω).hitTime () (Set.Ici 1) = ((τ ω).toNNReal : ℝ≥0) := by + have hset : {i : ℝ≥0 | 0 ≤ i ∧ scenarioAt (defaultIndicator τ) ω () i ∈ Set.Ici (1 : ℝ)} + = Set.Ici (τ ω).toNNReal := by + ext i + rw [Set.mem_ofPred_eq, scenarioAt, defaultIndicator_mem_Ici, Set.mem_Ici, + Real.toNNReal_le_iff_le_coe] + exact ⟨fun h ↦ h.2, fun h ↦ ⟨zero_le, h⟩⟩ + have hex : ∃ j : ℝ≥0, 0 ≤ j ∧ scenarioAt (defaultIndicator τ) ω () j ∈ Set.Ici (1 : ℝ) := + ⟨(τ ω).toNNReal, zero_le, (defaultIndicator_mem_Ici τ ω _).2 (Real.le_coe_toNNReal _)⟩ + rw [Scenario.hitTime, MeasureTheory.hittingAfter_def] + beta_reduce + simp only [hex, ↓reduceIte] + rw [hset, csInf_Ici] + +/-- **The path value of the protection leg paid at the default time**: `(1 − R)` discounted at +`τ`, if default happens by `T`. -/ +theorem pathPV_cdsProtectionAtDefault (D : ℝ≥0 → ℝ) (τ : Ω → ℝ) (T : ℝ≥0) (R : ℝ) (ω : Ω) : + (cdsProtectionAtDefault T R).pathPV D (scenarioAt (defaultIndicator τ) ω) + = D (τ ω).toNNReal * ((1 - R) * defaultIndicator τ () T ω) := by + rw [cdsProtectionAtDefault, + Contract.pathPV_payAtHit_of_eq _ _ _ (hitTime_defaultIndicator τ ω)] + simp [Payoff.eval, scenarioAt] + +/-- **The protection leg paid at the default time is worth `(1 − R)·𝔼[D(τ)·1{τ ≤ T}]`**, for any +pricing measure, default time and discount curve (`D` is read at `τ` made nonnegative). It is an +identity of Bochner integrals with no integrability assumed: when the integrand is not integrable +both sides are `0`. -/ +theorem value_cdsProtectionAtDefault (D : ℝ≥0 → ℝ) (τ : Ω → ℝ) (T : ℝ≥0) + (R : ℝ) : + (cdsProtectionAtDefault T R).value μ (fun t _ ↦ D t) (defaultIndicator τ) + = (1 - R) * ∫ ω, (Set.Iic (T : ℝ)).indicator (fun s ↦ D s.toNNReal) (τ ω) ∂μ := by + rw [Contract.value, ← integral_const_mul] + refine integral_congr_ae (ae_of_all _ fun ω ↦ ?_) + beta_reduce + rw [pathPV_cdsProtectionAtDefault] + by_cases h : τ ω ≤ T + · simp [defaultIndicator, Set.indicator, h] + ring + · simp [defaultIndicator, Set.indicator, h] + +end AtDefault + +section Cox + +open MathFin.Cox + +variable {μ : Measure Ω} [IsProbabilityMeasure μ] {h : ℝ → ℝ} + +omit [IsProbabilityMeasure μ] in +/-- **The Cox default time has survival function `hazardSurvival h`**, in the form the CDS +legs consume: `μ(τ ≤ u) = 1 − S u` for every date `u ≥ 0`. -/ +theorem measureReal_coxDefaultTime_le (hh : Continuous h) (hpos : ∀ s, 0 < h s) + (hdiv : Filter.Tendsto (cumHazard h) Filter.atTop Filter.atTop) {ξ : Ω → ℝ} + (hξmeas : Measurable ξ) (hξlaw : Measure.map ξ μ = expMeasure 1) (u : ℝ≥0) : + μ.real {ω | coxDefaultTime h ξ ω ≤ u} = 1 - hazardSurvival h u := by + have hS1 : hazardSurvival h u ≤ 1 := + Real.exp_le_one_iff.2 (neg_nonpos.2 (intervalIntegral.integral_nonneg u.coe_nonneg fun s _ ↦ + (hpos s).le)) + have hcdf := cox_cdf_timeVarying (μ := μ) hh hpos hdiv hξmeas hξlaw u.coe_nonneg + refine (congrArg ENNReal.toReal hcdf).trans ?_ + rw [ENNReal.toReal_sub_of_le (ENNReal.ofReal_le_one.2 hS1) ENNReal.one_ne_top, + ENNReal.toReal_ofReal (hazardSurvival_pos h u).le, ENNReal.toReal_one] + +/-- **The CDS contract under the Cox default time**: the protection buyer's CDS on the grid `t`, +priced against the default time built from a unit-exponential clock `ξ` by inverting the +cumulative hazard of a continuous positive intensity `h`, is worth `(1 − R)` times the grid losses +of the hazard curve less `s` times its grid annuity. -/ +theorem value_cdsBuyer_coxDefaultTime (hh : Continuous h) (hpos : ∀ s, 0 < h s) + (hdiv : Filter.Tendsto (cumHazard h) Filter.atTop Filter.atTop) {ξ : Ω → ℝ} + (hξmeas : Measurable ξ) (hξlaw : Measure.map ξ μ = expMeasure 1) (D : ℝ≥0 → ℝ) + (t : ℕ → ℝ≥0) (s R : ℝ) (n : ℕ) : + (cdsBuyer t s R n).value μ (fun t _ ↦ D t) (defaultIndicator (coxDefaultTime h ξ)) + = (1 - R) * cdsLossesGrid D (hazardSurvival h) t n + - s * cdsAnnuityGrid D (hazardSurvival h) t n := + value_cdsBuyer (measurable_coxDefaultTime hh hpos hξmeas) + (measureReal_coxDefaultTime_le hh hpos hdiv hξmeas hξlaw) D t s R n + +/-- Without discounting the grid losses telescope to the default probability, whatever the grid. -/ +theorem cdsLossesGrid_one (S : ℝ → ℝ) (t : ℕ → ℝ≥0) (n : ℕ) : + cdsLossesGrid (fun _ ↦ 1) S t n = S (t 0) - S (t n) := by + simpa [cdsLossesGrid] using Finset.sum_range_sub' (fun i ↦ S (t i)) n + +/-- **The undiscounted grid losses are the continuous ones**: on any grid from `t 0 = 0` to `t n`, +the undiscounted grid losses of the hazard curve equal `Cox.cdsLosses 0 h (t n)`, the integral +of the default density. -/ +theorem cdsLossesGrid_one_eq_cdsLosses (hh : Continuous h) (t : ℕ → ℝ≥0) (n : ℕ) + (h0 : t 0 = 0) : + cdsLossesGrid (fun _ ↦ 1) (hazardSurvival h) t n = cdsLosses 0 h (t n) := by + rw [cdsLossesGrid_one, h0, NNReal.coe_zero, hazardSurvival_at_zero, cdsLosses] + simp only [zero_mul, neg_zero, Real.exp_zero, one_mul] + exact (defaultDensity_antideriv hh _).symm + +/-! ### The protection leg paid at the Cox default time -/ + +omit [IsProbabilityMeasure μ] in +/-- **The Cox default time is a.s. positive**: its law has no atom at `0`, +`μ(τ ≤ 0) = 1 − S(0) = 0`. -/ +theorem ae_pos_coxDefaultTime (hh : Continuous h) (hpos : ∀ s, 0 < h s) + (hdiv : Filter.Tendsto (cumHazard h) Filter.atTop Filter.atTop) {ξ : Ω → ℝ} + (hξmeas : Measurable ξ) (hξlaw : Measure.map ξ μ = expMeasure 1) : + ∀ᵐ ω ∂μ, 0 < coxDefaultTime h ξ ω := by + have h0 := cox_cdf_timeVarying (μ := μ) hh hpos hdiv hξmeas hξlaw (le_refl (0 : ℝ)) + rw [hazardSurvival_at_zero, ENNReal.ofReal_one, tsub_self] at h0 + filter_upwards [measure_eq_zero_iff_ae_notMem.1 h0] with ω hω + exact not_le.1 hω + +/-- **The protection leg paid at the default time, under the Cox default time, is the continuous +protection leg `Cox.protectionLeg`**: for a continuous positive intensity `h` with divergent +cumulative hazard, the contract that pays `1 − R` at the first time the default indicator reaches +`1`, if that is by `T`, discounted at the flat rate `r` (`D u = e^{−ru}`), is worth +`(1 − R) ∫₀ᵀ e^{−rs} h(s) S(s) ds`. -/ +theorem value_cdsProtectionAtDefault_coxDefaultTime (hh : Continuous h) (hpos : ∀ s, 0 < h s) + (hdiv : Filter.Tendsto (cumHazard h) Filter.atTop Filter.atTop) {ξ : Ω → ℝ} + (hξmeas : Measurable ξ) (hξlaw : Measure.map ξ μ = expMeasure 1) (r R : ℝ) (T : ℝ≥0) : + (cdsProtectionAtDefault T R).value μ (fun (u : ℝ≥0) _ ↦ Real.exp (-(r * u))) + (defaultIndicator (coxDefaultTime h ξ)) + = protectionLeg R r h T := by + rw [value_cdsProtectionAtDefault, + CVA.protectionLeg_eq_integral_coxDefaultTime hh hpos hdiv hξmeas hξlaw R r T.coe_nonneg] + congr 1 + refine integral_congr_ae ?_ + filter_upwards [ae_pos_coxDefaultTime hh hpos hdiv hξmeas hξlaw] with ω hω + simp only [Set.indicator, Set.mem_Iic, Real.coe_toNNReal _ hω.le] + +end Cox + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Models/Credit/DefaultTimeMesh.lean b/LeanPool/MathFin/Models/Credit/DefaultTimeMesh.lean new file mode 100644 index 0000000000..8b07142a07 --- /dev/null +++ b/LeanPool/MathFin/Models/Credit/DefaultTimeMesh.lean @@ -0,0 +1,314 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Credit.DefaultTime + +/-! +# The CDS on a payment grid converges to the continuous legs + +`Models/Credit/DefaultTime.lean` prices the CDS on a payment grid against a default time: the +legs are the grid annuity `∑ D(tᵢ₊₁)(tᵢ₊₁ − tᵢ) S(tᵢ₊₁)` and the grid losses +`∑ D(tᵢ₊₁)(S tᵢ − S tᵢ₊₁)`. Here the grid is refined. For a continuous positive hazard rate `h` +(survival `S = hazardSurvival h`) and a flat rate `r`, `D u = e^{−ru}`, the grid legs converge to +the continuous legs of `Models/Credit/Cox.lean` as the mesh `max (tᵢ₊₁ − tᵢ)` goes to zero: + + `cdsAnnuityGrid D S t n → Cox.cdsAnnuity r h T`, `cdsLossesGrid D S t n → Cox.cdsLosses r h T`, + +and so the protection buyer's CDS contract converges to `Cox.protectionLeg − Cox.premiumLeg`, and +the grid par spread to `Cox.cdsFairSpreadTV`. + +The limit is taken in the numbers the grid contract is worth (`value_cdsBuyer_coxDefaultTime`). +The grid protection leg also converges to the *contract* that pays at the default time: its values +tend to the value of `cdsProtectionAtDefault` (`Contract.payAtHit`), which is `Cox.protectionLeg` +(`tendsto_value_cdsProtectionLeg_coxDefaultTime`). The premium leg has no such contract, since the +tower has no continuous payment stream. + +The core is deterministic: a right-endpoint Riemann–Stieltjes sum of a continuous `g` against a +continuous density `f` differs from `∫ g f` by at most `ε ∫ |f|` once `g` oscillates by at most +`ε` on each cell (`abs_sum_mul_integral_sub_integral_le`). + +## Main definitions + +* `IsGridOfMesh` — a grid of `[0, T]` with steps at most `δ`. + +## Main results + +* `abs_sum_mul_integral_sub_integral_le` — the Riemann–Stieltjes error bound. +* `exists_cdsLossesGrid_close`, `exists_cdsAnnuityGrid_close` — the ε–δ form: for every `ε` there is + a mesh bound `δ` under which every grid is within `ε` of the continuous leg. +* `tendsto_cdsLossesGrid`, `tendsto_cdsAnnuityGrid`, `tendsto_cdsParSpreadGrid`, + `tendsto_value_cdsBuyer_coxDefaultTime`, `tendsto_value_cdsProtectionLeg_coxDefaultTime` — the + limits along grids whose mesh tends to zero. + +## References + +* [S. Bagaria, *Notes on Fixed Income Derivative Pricing*][BagariaFIDP], ch. 16 +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [D. Lando, *Credit Risk Modeling*][Lando2004], ch. 5 +* [S. Peyton Jones, J. M. Eber and J. Seward, *Composing contracts*][PeytonJonesEberSeward2000] + +## Tags + +CDS discretization, Riemann–Stieltjes sum, hazard rate, par spread limit, continuous-time CDS, +MSC 91G40, JEL G12 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Filter Topology +open scoped NNReal + +namespace MathFin.Contracts + +/-! ### Riemann–Stieltjes sums -/ + +/-- **The Riemann–Stieltjes error bound.** Let `g` and `f` be continuous and `t` a monotone grid. +If `g` moves by at most `ε` between the right end of each cell `[tᵢ, tᵢ₊₁]` and any point of it, +then `∑ g(tᵢ₊₁) ∫_{tᵢ}^{tᵢ₊₁} f` is within `ε ∫ |f|` of `∫_{t₀}^{tₙ} g f`. -/ +lemma abs_sum_mul_integral_sub_integral_le {g f : ℝ → ℝ} (hg : Continuous g) (hf : Continuous f) + {t : ℕ → ℝ} (ht : Monotone t) (n : ℕ) {ε : ℝ} + (hε : ∀ i < n, ∀ s ∈ Set.Icc (t i) (t (i + 1)), |g (t (i + 1)) - g s| ≤ ε) : + |∑ i ∈ Finset.range n, g (t (i + 1)) * (∫ s in t i..t (i + 1), f s) + - ∫ s in t 0..t n, g s * f s| + ≤ ε * ∫ s in t 0..t n, |f s| := by + rw [← intervalIntegral.sum_integral_adjacent_intervals (a := t) (n := n) + (f := fun s ↦ g s * f s) fun i _ ↦ (hg.mul hf).intervalIntegrable _ _, + ← intervalIntegral.sum_integral_adjacent_intervals (a := t) (n := n) + (f := fun s ↦ |f s|) fun i _ ↦ hf.abs.intervalIntegrable _ _, + Finset.mul_sum] + simp only [← Finset.sum_sub_distrib] + refine (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum fun i hi ↦ ?_) + have hle := ht (Nat.le_succ i) + have h1 : IntervalIntegrable (fun x ↦ g (t (i + 1)) * f x) volume (t i) (t (i + 1)) := + (hf.const_mul _).intervalIntegrable _ _ + have h2 : IntervalIntegrable (fun x ↦ g x * f x) volume (t i) (t (i + 1)) := + (hg.mul hf).intervalIntegrable _ _ + rw [← intervalIntegral.integral_const_mul, ← intervalIntegral.integral_sub h1 h2, + ← intervalIntegral.integral_const_mul] + refine (intervalIntegral.abs_integral_le_integral_abs hle).trans + (intervalIntegral.integral_mono_on hle (h1.sub h2).abs + ((hf.abs.const_mul _).intervalIntegrable _ _) fun s hs ↦ ?_) + rw [← sub_mul, abs_mul] + exact mul_le_mul_of_nonneg_right (hε i (Finset.mem_range.1 hi) s hs) (abs_nonneg _) + +/-! ### Grids -/ + +/-- `t` is a **grid of `[0, T]` of mesh at most `δ`** with `n` cells: monotone, from `0` to `T`, +with every step at most `δ`. -/ +def IsGridOfMesh (t : ℕ → ℝ≥0) (n : ℕ) (T δ : ℝ) : Prop := + Monotone t ∧ t 0 = 0 ∧ (t n : ℝ) = T ∧ ∀ i < n, (t (i + 1) : ℝ) - t i ≤ δ + +lemma IsGridOfMesh.mono {t : ℕ → ℝ≥0} {n : ℕ} {T δ δ' : ℝ} (h : IsGridOfMesh t n T δ) + (hδ : δ ≤ δ') : IsGridOfMesh t n T δ' := + ⟨h.1, h.2.1, h.2.2.1, fun i hi ↦ (h.2.2.2 i hi).trans hδ⟩ + +/-- On a grid of mesh `≤ δ`, a function `g` uniformly continuous at scale `δ` on `[0, T]` moves by +at most `ε` between the right end of each cell and any point of it. -/ +private lemma IsGridOfMesh.oscillation {t : ℕ → ℝ≥0} {n : ℕ} {T δ : ℝ} (h : IsGridOfMesh t n T δ) + {g : ℝ → ℝ} {ε : ℝ} (hg : ∀ x ∈ Set.Icc (0 : ℝ) T, ∀ y ∈ Set.Icc (0 : ℝ) T, |x - y| ≤ δ → + |g x - g y| ≤ ε) {i : ℕ} (hi : i < n) (s : ℝ) (hs : s ∈ Set.Icc (t i : ℝ) (t (i + 1))) : + |g (t (i + 1)) - g s| ≤ ε := by + have hT : (t (i + 1) : ℝ) ≤ T := + h.2.2.1 ▸ NNReal.coe_le_coe.2 (h.1 (Nat.succ_le_of_lt hi)) + refine hg (t (i + 1) : ℝ) ⟨NNReal.coe_nonneg _, hT⟩ s + ⟨(NNReal.coe_nonneg _).trans hs.1, hs.2.trans hT⟩ ?_ + exact (abs_of_nonneg (sub_nonneg.2 hs.2)).trans_le (by linarith [h.2.2.2 i hi, hs.1]) + +/-- A continuous `g` oscillates by at most `ε` at some scale `δ > 0` on `[0, T]`: uniform continuity +on the compact interval. -/ +lemma exists_oscillation_le {g : ℝ → ℝ} (hg : Continuous g) (T : ℝ) {ε : ℝ} (hε : 0 < ε) : + ∃ δ > 0, ∀ x ∈ Set.Icc (0 : ℝ) T, ∀ y ∈ Set.Icc (0 : ℝ) T, |x - y| ≤ δ → |g x - g y| ≤ ε := by + obtain ⟨δ, hδ, H⟩ := Metric.uniformContinuousOn_iff.1 + (isCompact_Icc.uniformContinuousOn_of_continuous hg.continuousOn) ε hε + exact ⟨δ / 2, half_pos hδ, fun x hx y hy hxy ↦ (H x hx y hy (by + rw [Real.dist_eq]; linarith)).le⟩ + +/-- Convergence along grids of vanishing mesh from the ε–δ closeness: if every grid of mesh at most +`δ` is within `ε` of `L`, then along grids `t k` of mesh at most `δ k → 0` the values tend to +`L`. -/ +private lemma tendsto_of_close (Φ : (ℕ → ℝ≥0) → ℕ → ℝ) (L T : ℝ) + (hclose : ∀ ε > 0, ∃ δ > 0, ∀ t n, IsGridOfMesh t n T δ → |Φ t n - L| ≤ ε) + {t : ℕ → ℕ → ℝ≥0} {n : ℕ → ℕ} {δ : ℕ → ℝ} (hgrid : ∀ k, IsGridOfMesh (t k) (n k) T (δ k)) + (hδ : Tendsto δ atTop (𝓝 0)) : Tendsto (fun k ↦ Φ (t k) (n k)) atTop (𝓝 L) := by + rw [Metric.tendsto_atTop] + intro ε hε + obtain ⟨δ₀, hδ₀, H⟩ := hclose (ε / 2) (half_pos hε) + obtain ⟨N, hN⟩ := eventually_atTop.1 (hδ.eventually (gt_mem_nhds hδ₀)) + exact ⟨N, fun k hk ↦ lt_of_le_of_lt (H _ _ ((hgrid k).mono (hN k hk).le)) + (half_lt_self hε)⟩ + +/-! ### The legs -/ + +section Legs + +variable {h : ℝ → ℝ} + +/-- **The grid losses are close to the continuous losses.** For a continuous positive hazard `h`, a +rate `r` and a horizon `T`, every `ε > 0` has a mesh bound `δ > 0` such that every grid of `[0, T]` +of mesh at most `δ` has `|cdsLossesGrid D S t n − Cox.cdsLosses r h T| ≤ ε`, with `D u = e^{−ru}` +and `S = hazardSurvival h`. The error is at most `ε` times the default probability +`1 − S(T) ≤ 1`. -/ +theorem exists_cdsLossesGrid_close (hh : Continuous h) (hpos : ∀ s, 0 < h s) (r T : ℝ) + {ε : ℝ} (hε : 0 < ε) : + ∃ δ > 0, ∀ (t : ℕ → ℝ≥0) (n : ℕ), IsGridOfMesh t n T δ → + |cdsLossesGrid (fun u : ℝ≥0 ↦ Real.exp (-(r * u))) (hazardSurvival h) t n + - Cox.cdsLosses r h T| ≤ ε := by + obtain ⟨δ, hδ, hosc⟩ := exists_oscillation_le (g := fun s ↦ Real.exp (-(r * s))) + (by fun_prop) T hε + refine ⟨δ, hδ, fun t n hgrid ↦ ?_⟩ + have key := abs_sum_mul_integral_sub_integral_le (g := fun s ↦ Real.exp (-(r * s))) + (f := DefaultDensity.defaultDensity h) (by fun_prop) + (DefaultDensity.continuous_defaultDensity hh) + (t := fun i ↦ (t i : ℝ)) (fun i j hij ↦ NNReal.coe_le_coe.2 (hgrid.1 hij)) n + (fun i hi s hs ↦ hgrid.oscillation hosc hi s hs) + beta_reduce at key + rw [hgrid.2.1, hgrid.2.2.1, NNReal.coe_zero] at key + have hsum : ∑ i ∈ Finset.range n, Real.exp (-(r * (t (i + 1) : ℝ))) + * ∫ s in (t i : ℝ)..(t (i + 1) : ℝ), DefaultDensity.defaultDensity h s + = cdsLossesGrid (fun u : ℝ≥0 ↦ Real.exp (-(r * u))) (hazardSurvival h) t n := by + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [DefaultDensity.integral_defaultDensity hh] + have hint : ∫ s in (0 : ℝ)..T, Real.exp (-(r * s)) * DefaultDensity.defaultDensity h s + = Cox.cdsLosses r h T := by + refine intervalIntegral.integral_congr fun s _ ↦ ?_ + simp only [DefaultDensity.defaultDensity] + ring + have hbound : ∫ s in (0 : ℝ)..T, |DefaultDensity.defaultDensity h s| ≤ 1 := by + rw [intervalIntegral.integral_congr (g := DefaultDensity.defaultDensity h) fun s _ ↦ + abs_of_nonneg (DefaultDensity.defaultDensity_nonneg (fun s ↦ (hpos s).le) s), + DefaultDensity.integral_defaultDensity_zero hh] + linarith [hazardSurvival_pos h T] + refine (le_of_eq_of_le ?_ key).trans + ((mul_le_mul_of_nonneg_left hbound hε.le).trans_eq (mul_one ε)) + exact congrArg abs (congrArg₂ (· - ·) hsum.symm hint.symm) + +/-- **The grid annuity is close to the continuous annuity**, as `exists_cdsLossesGrid_close`: +every grid of `[0, T]` of mesh at most `δ` has +`|cdsAnnuityGrid D S t n − Cox.cdsAnnuity r h T| ≤ ε`. The error is at most `ε/(T + 1)` times +`T`. -/ +theorem exists_cdsAnnuityGrid_close (hh : Continuous h) (r : ℝ) {T : ℝ} (hT : 0 ≤ T) + {ε : ℝ} (hε : 0 < ε) : + ∃ δ > 0, ∀ (t : ℕ → ℝ≥0) (n : ℕ), IsGridOfMesh t n T δ → + |cdsAnnuityGrid (fun u : ℝ≥0 ↦ Real.exp (-(r * u))) (hazardSurvival h) t n + - Cox.cdsAnnuity r h T| ≤ ε := by + have hgc : Continuous fun s ↦ Real.exp (-(r * s)) * hazardSurvival h s := + (by fun_prop : Continuous fun s : ℝ ↦ Real.exp (-(r * s))).mul + (continuous_iff_continuousAt.2 fun _ ↦ + (DefaultDensity.hasDerivAt_hazardSurvival hh.locallyIntegrable + hh.continuousAt).continuousAt) + obtain ⟨δ, hδ, hosc⟩ := exists_oscillation_le hgc T (div_pos hε (by linarith : 0 < T + 1)) + refine ⟨δ, hδ, fun t n hgrid ↦ ?_⟩ + have key := abs_sum_mul_integral_sub_integral_le hgc (f := fun _ ↦ (1 : ℝ)) continuous_const + (t := fun i ↦ (t i : ℝ)) (fun i j hij ↦ NNReal.coe_le_coe.2 (hgrid.1 hij)) n + (fun i hi s hs ↦ hgrid.oscillation hosc hi s hs) + beta_reduce at key + rw [hgrid.2.1, hgrid.2.2.1, NNReal.coe_zero] at key + have hsum : ∑ i ∈ Finset.range n, Real.exp (-(r * (t (i + 1) : ℝ))) * hazardSurvival h (t (i + 1)) + * ∫ s in (t i : ℝ)..(t (i + 1) : ℝ), (1 : ℝ) + = cdsAnnuityGrid (fun u : ℝ≥0 ↦ Real.exp (-(r * u))) (hazardSurvival h) t n := by + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [intervalIntegral.integral_const, smul_eq_mul, mul_one] + ring + have hint : ∫ s in (0 : ℝ)..T, Real.exp (-(r * s)) * hazardSurvival h s * (1 : ℝ) + = Cox.cdsAnnuity r h T := by + simp only [mul_one, Cox.cdsAnnuity] + have hone : ∫ s in (0 : ℝ)..T, |(1 : ℝ)| = T := by simp + have hε' : 0 ≤ ε / (T + 1) := (div_pos hε (by linarith)).le + refine (le_of_eq_of_le ?_ key).trans + ((mul_le_mul_of_nonneg_left hone.le hε').trans ?_) + · exact congrArg abs (congrArg₂ (· - ·) hsum.symm hint.symm) + · rw [div_mul_eq_mul_div, div_le_iff₀ (by linarith)] + nlinarith + +/-- **The grid losses converge to the continuous losses** along grids of `[0, T]` whose mesh +tends to zero: `cdsLossesGrid D S (t k) (n k) → Cox.cdsLosses r h T`, `D u = e^{−ru}`. -/ +theorem tendsto_cdsLossesGrid (hh : Continuous h) (hpos : ∀ s, 0 < h s) (r T : ℝ) + {t : ℕ → ℕ → ℝ≥0} {n : ℕ → ℕ} {δ : ℕ → ℝ} (hgrid : ∀ k, IsGridOfMesh (t k) (n k) T (δ k)) + (hδ : Tendsto δ atTop (𝓝 0)) : + Tendsto (fun k ↦ cdsLossesGrid (fun u : ℝ≥0 ↦ Real.exp (-(r * u))) (hazardSurvival h) + (t k) (n k)) atTop (𝓝 (Cox.cdsLosses r h T)) := + tendsto_of_close + (fun t n ↦ cdsLossesGrid (fun u : ℝ≥0 ↦ Real.exp (-(r * u))) (hazardSurvival h) t n) + _ T (fun _ hε ↦ exists_cdsLossesGrid_close hh hpos r T hε) hgrid hδ + +/-- **The grid annuity converges to the continuous annuity** along grids of `[0, T]` whose mesh +tends to zero: `cdsAnnuityGrid D S (t k) (n k) → Cox.cdsAnnuity r h T`. -/ +theorem tendsto_cdsAnnuityGrid (hh : Continuous h) (r : ℝ) {T : ℝ} (hT : 0 ≤ T) + {t : ℕ → ℕ → ℝ≥0} {n : ℕ → ℕ} {δ : ℕ → ℝ} (hgrid : ∀ k, IsGridOfMesh (t k) (n k) T (δ k)) + (hδ : Tendsto δ atTop (𝓝 0)) : + Tendsto (fun k ↦ cdsAnnuityGrid (fun u : ℝ≥0 ↦ Real.exp (-(r * u))) (hazardSurvival h) + (t k) (n k)) atTop (𝓝 (Cox.cdsAnnuity r h T)) := + tendsto_of_close + (fun t n ↦ cdsAnnuityGrid (fun u : ℝ≥0 ↦ Real.exp (-(r * u))) (hazardSurvival h) t n) + _ T (fun _ hε ↦ exists_cdsAnnuityGrid_close hh r hT hε) hgrid hδ + +/-- **The grid par spread converges to the continuous fair spread** `Cox.cdsFairSpreadTV` along +grids of `(0, T]` whose mesh tends to zero: the ratio of the two limits, whose denominator +`Cox.cdsAnnuity` is positive. -/ +theorem tendsto_cdsParSpreadGrid (hh : Continuous h) (hpos : ∀ s, 0 < h s) (r R : ℝ) {T : ℝ} + (hT : 0 < T) {t : ℕ → ℕ → ℝ≥0} {n : ℕ → ℕ} {δ : ℕ → ℝ} + (hgrid : ∀ k, IsGridOfMesh (t k) (n k) T (δ k)) (hδ : Tendsto δ atTop (𝓝 0)) : + Tendsto (fun k ↦ cdsParSpreadGrid (fun u : ℝ≥0 ↦ Real.exp (-(r * u))) (hazardSurvival h) + (t k) R (n k)) atTop (𝓝 (Cox.cdsFairSpreadTV r h R T)) := + (((tendsto_cdsLossesGrid hh hpos r T hgrid hδ).const_mul (1 - R)).div + (tendsto_cdsAnnuityGrid hh r hT.le hgrid hδ) (Cox.cdsAnnuity_pos hh hT).ne') + +end Legs + +/-! ### The contract -/ + +section Contract + +open Cox + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {h : ℝ → ℝ} + +/-- **The CDS contract converges to the continuous legs.** Under the Cox default time of a +continuous positive intensity `h` (`hdiv`: the cumulative hazard diverges), the protection buyer's +CDS on the grids `t k` of `[0, T]`, discounted at the flat rate `r` (`D u = e^{−ru}`), is worth +`(1 − R)·cdsLossesGrid − s·cdsAnnuityGrid` (`value_cdsBuyer_coxDefaultTime`), which tends to +`Cox.protectionLeg R r h T − Cox.premiumLeg s r h T` as the mesh tends to zero. The limit is a +statement about the values, `Cox.protectionLeg` and `Cox.premiumLeg`: the first is the value of +`cdsProtectionAtDefault` (`tendsto_value_cdsProtectionLeg_coxDefaultTime`). -/ +theorem tendsto_value_cdsBuyer_coxDefaultTime (hh : Continuous h) (hpos : ∀ s, 0 < h s) + (hdiv : Filter.Tendsto (cumHazard h) Filter.atTop Filter.atTop) {ξ : Ω → ℝ} + (hξmeas : Measurable ξ) (hξlaw : Measure.map ξ μ = expMeasure 1) (r s R : ℝ) {T : ℝ} + (hT : 0 ≤ T) {t : ℕ → ℕ → ℝ≥0} {n : ℕ → ℕ} {δ : ℕ → ℝ} + (hgrid : ∀ k, IsGridOfMesh (t k) (n k) T (δ k)) (hδ : Tendsto δ atTop (𝓝 0)) : + Tendsto (fun k ↦ (cdsBuyer (t k) s R (n k)).value μ (fun (u : ℝ≥0) _ ↦ Real.exp (-(r * u))) + (defaultIndicator (coxDefaultTime h ξ))) atTop + (𝓝 (protectionLeg R r h T - premiumLeg s r h T)) := by + simp only [value_cdsBuyer_coxDefaultTime hh hpos hdiv hξmeas hξlaw, protectionLeg, premiumLeg] + exact ((tendsto_cdsLossesGrid hh hpos r T hgrid hδ).const_mul (1 - R)).sub + ((tendsto_cdsAnnuityGrid hh r hT hgrid hδ).const_mul s) + +/-- **The grid protection leg converges to the protection leg paid at the default time.** Under the +Cox default time, the values of the grid contracts `cdsProtectionLeg (t k) R (n k)`, each paying +`(1 − R)` at the end of the period in which default happens, tend to the value of the contract +`cdsProtectionAtDefault T R`, which pays `(1 − R)` at the default time itself, as the mesh of the +grids of `[0, T]` goes to zero. -/ +theorem tendsto_value_cdsProtectionLeg_coxDefaultTime (hh : Continuous h) (hpos : ∀ s, 0 < h s) + (hdiv : Filter.Tendsto (cumHazard h) Filter.atTop Filter.atTop) {ξ : Ω → ℝ} + (hξmeas : Measurable ξ) (hξlaw : Measure.map ξ μ = expMeasure 1) (r R : ℝ) {T : ℝ≥0} + {t : ℕ → ℕ → ℝ≥0} {n : ℕ → ℕ} {δ : ℕ → ℝ} + (hgrid : ∀ k, IsGridOfMesh (t k) (n k) T (δ k)) (hδ : Tendsto δ atTop (𝓝 0)) : + Tendsto (fun k ↦ (cdsProtectionLeg (t k) R (n k)).value μ + (fun (u : ℝ≥0) _ ↦ Real.exp (-(r * u))) + (defaultIndicator (coxDefaultTime h ξ))) atTop + (𝓝 ((cdsProtectionAtDefault T R).value μ (fun (u : ℝ≥0) _ ↦ Real.exp (-(r * u))) + (defaultIndicator (coxDefaultTime h ξ)))) := by + rw [value_cdsProtectionAtDefault_coxDefaultTime hh hpos hdiv hξmeas hξlaw, protectionLeg] + simp only [value_cdsProtectionLeg (measurable_coxDefaultTime hh hpos hξmeas) + (measureReal_coxDefaultTime_le hh hpos hdiv hξmeas hξlaw)] + exact (tendsto_cdsLossesGrid hh hpos r T hgrid hδ).const_mul (1 - R) + +end Contract + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Models/Credit/FirstToDefault.lean b/LeanPool/MathFin/Models/Credit/FirstToDefault.lean new file mode 100644 index 0000000000..3e7c8838f4 --- /dev/null +++ b/LeanPool/MathFin/Models/Credit/FirstToDefault.lean @@ -0,0 +1,109 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Laws.ExpMin +public import LeanPool.MathFin.Models.Credit.Credit + +/-! +# First-to-default: the basket intensity is the sum of single-name intensities + +In the reduced-form (intensity-based) credit model, each name `i` in a basket +defaults at an exponential time `τ_i ∼ Exp(rates i)` — the constant-hazard +survival law derived in `Probability/Jumps/PoissonInterarrival.lean` and assumed +calibrated per name. A *first-to-default* (FtD) instrument references the +basket's first default time `min_i τ_i`. + +This file is the finance reading of `Probability/Laws/ExpMin.minimum_survival` +(minimum of jointly independent exponentials is exponential at the summed +rate): it rewrites that probability statement in the credit vocabulary of +`Models/Credit/Credit.lean` and draws the desk-level consequence. + +* `firstToDefault_survival` — the basket survival probability *is* + `survivalProbability (∑ i, rates i) 0 t`: the FtD time has constant hazard + `∑ rates`, i.e. **basket intensity = sum of single-name intensities** + (under independence). +* `firstToDefault_spread_eq_sum_hazards` — consequently the FtD credit + spread, read directly off the measure of the survival event, equals + `∑ i, rates i`. Since single-name spreads equal single-name hazards + (`creditSpread_eq_hazard`), the fair FtD spread is the *sum of the + single-name spreads* — and with a common recovery `R` both sides scale by + `(1 − R)` (`cdsFairSpread`), so FtD CDS premia are additive across + independent names. Independence is the extremal case: default correlation + only lowers the FtD spread below this sum. + +The probabilistic content (joint independence → product of survivals → +exponential at the summed rate) lives upstream in `ExpMin.lean`; this file +deliberately adds *no* new measure theory, only the load-bearing bridge from +that law to the credit-pricing layer. + +## Main results + +* `firstToDefault_survival`: for jointly independent measurable default times `τ_i ∼ Exp(rates i)` + with positive rates and `t ≥ 0`, `P(min_i τ_i > t)` is the constant-hazard survival probability + at the summed intensity `∑ i, rates i`. +* `firstToDefault_spread_eq_sum_hazards`: under the same hypotheses and `t > 0`, the spread + `-log P(min_i τ_i > t) / t` equals `∑ i, rates i`. + +## References + +* [Duffie and Singleton (2003)][DuffieSingleton2003] +* [D. Lando, *Credit Risk Modeling*][Lando2004], Ch 5 + +## Tags + +first-to-default, basket default swap, minimum of exponentials, basket intensity, credit spread, +independent defaults, MSC 91G40, JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory + +variable {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} + {n : ℕ} {rates : Fin n → ℝ} {τ : Fin n → Ω → ℝ} + +/-- **First-to-default survival law.** For jointly independent exponential +default times `τ_i ∼ Exp(rates i)`, the probability that no name has +defaulted by `t` is the constant-hazard survival probability at the summed +intensity: `P(min_i τ_i > t) = survivalProbability (∑ i, rates i) 0 t`. -/ +theorem firstToDefault_survival + (hrates_pos : ∀ i, 0 < rates i) + (hexp_law : ∀ i, Measure.map (τ i) μ = expMeasure (rates i)) + (hindep : iIndepFun τ μ) + (hmeas : ∀ i, Measurable (τ i)) + (hn : 0 < n) {t : ℝ} (ht : 0 ≤ t) : + μ {ω | t < Finset.univ.inf' ⟨⟨0, hn⟩, Finset.mem_univ _⟩ + (fun i : Fin n ↦ τ i ω)} = + ENNReal.ofReal (survivalProbability (∑ i, rates i) 0 t) := by + rw [minimum_survival hrates_pos hexp_law hindep hmeas hn ht] + unfold survivalProbability + rw [sub_zero] + +/-- **First-to-default spread additivity.** The FtD credit spread — read +directly off the measure of the basket survival event — equals the sum of +the single-name hazard rates. By `creditSpread_eq_hazard` each summand is +the corresponding single-name spread, so under independence the fair +first-to-default spread is the sum of the single-name spreads. -/ +theorem firstToDefault_spread_eq_sum_hazards + (hrates_pos : ∀ i, 0 < rates i) + (hexp_law : ∀ i, Measure.map (τ i) μ = expMeasure (rates i)) + (hindep : iIndepFun τ μ) + (hmeas : ∀ i, Measurable (τ i)) + (hn : 0 < n) {t : ℝ} (ht : 0 < t) : + -Real.log ((μ {ω | t < Finset.univ.inf' ⟨⟨0, hn⟩, Finset.mem_univ _⟩ + (fun i : Fin n ↦ τ i ω)}).toReal) / t + = ∑ i, rates i := by + rw [firstToDefault_survival hrates_pos hexp_law hindep hmeas hn ht.le, + ENNReal.toReal_ofReal (survival_pos _ _ _).le] + simpa [sub_zero] using + creditSpread_eq_hazard (h := ∑ i, rates i) (t := 0) (T := t) ht + +end MathFin diff --git a/LeanPool/MathFin/Models/Credit/HazardCurve.lean b/LeanPool/MathFin/Models/Credit/HazardCurve.lean new file mode 100644 index 0000000000..e2f0f22e72 --- /dev/null +++ b/LeanPool/MathFin/Models/Credit/HazardCurve.lean @@ -0,0 +1,108 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Credit.Credit +public import LeanPool.MathFin.Probability.Analysis.ExponentialDiscount + +/-! +# Time-varying hazard credit curve + +Extension of `Credit.lean` to a deterministic time-varying hazard `h : ℝ → ℝ`. +The cumulative hazard is `H(t) = ∫₀^t h(u) du` and survival is + + `S(t) = exp(-H(t))`. + +When `h` is constant we recover the constant-hazard model. When `h` is +integrable the term-structure of credit spreads is the time-averaged hazard: + + `c(T) = -log(S(T)) / T = H(T) / T = (1/T) · ∫₀^T h(u) du`. + +## Main definitions + +* `cumHazard`: the cumulative hazard `H(t) = ∫₀^t h(u) du` of a deterministic hazard function `h`. +* `hazardSurvival`: the survival probability `S(t) = exp(-H(t))` under a time-varying hazard. + +## Main results + +* `hazardSurvival_at_zero`: `S(0) = 1`. +* `hazardSurvival_pos`: positive. +* `cumHazard_const`: `H(t) = h₀ · t` for constant `h`. +* `hazardSurvival_eq_const_survival`: matches `survivalProbability` for + constant `h`. +* `creditSpread_eq_time_avg_hazard`: `c(T) = H(T) / T`. + +## References + +* [D. Lando, *Credit Risk Modeling*][Lando2004] + +## Tags + +hazard curve, cumulative hazard, survival probability, time-varying intensity, +credit spread term structure, default intensity, MSC 91G40, JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +open Real MeasureTheory intervalIntegral + +/-- Cumulative hazard `H(t) = ∫₀^t h(u) du` for a deterministic hazard +function `h`. -/ +noncomputable def cumHazard (h : ℝ → ℝ) (t : ℝ) : ℝ := + cumulativeIntensity h t + +/-- Survival probability with time-varying hazard `S(t) = exp(-H(t))` — the credit +instance of the shared `survivalFromIntensity` (`Probability/Analysis/ExponentialDiscount`). +The same calculus as `Actuarial.survivalFromForce`. -/ +noncomputable def hazardSurvival (h : ℝ → ℝ) (t : ℝ) : ℝ := + survivalFromIntensity h t + +/-- `S(0) = 1`. -/ +lemma hazardSurvival_at_zero (h : ℝ → ℝ) : hazardSurvival h 0 = 1 := + survivalFromIntensity_zero h + +/-- Hazard survival is strictly positive (an instance of the +`ExponentialDiscount` principle `discount_pos`; holds regardless of hazard +sign / integrability). -/ +lemma hazardSurvival_pos (h : ℝ → ℝ) (t : ℝ) : 0 < hazardSurvival h t := + discount_pos _ + +/-- **Hazard intensity as the negative log-derivative of survival** — the +recovery direction `h(t) = −d/dt log S(t)`: for continuous `h`, the credit instance of +`hasDerivAt_neg_log_survivalFromIntensity`, as `force_eq_neg_log_deriv_survival` in +`Insurance/Mortality.lean` is the actuarial one. -/ +theorem hazard_eq_neg_log_deriv_survival {h : ℝ → ℝ} (t : ℝ) + (hh : Continuous h) : + HasDerivAt (fun s ↦ -(Real.log (hazardSurvival h s))) (h t) t := + hasDerivAt_neg_log_survivalFromIntensity hh t + +/-- For a constant hazard `h_0`, `H(t) = h_0 · t`. -/ +lemma cumHazard_const (h_0 t : ℝ) : + cumHazard (fun _ ↦ h_0) t = h_0 * t := by + unfold cumHazard cumulativeIntensity + rw [intervalIntegral.integral_const] + simp [mul_comm] + +/-- The time-varying model collapses to the constant-hazard `survivalProbability` +under `t = 0` and constant hazard. -/ +lemma hazardSurvival_eq_const_survival (h_0 T : ℝ) : + hazardSurvival (fun _ ↦ h_0) T = survivalProbability h_0 0 T := by + unfold hazardSurvival survivalFromIntensity survivalProbability + rw [show cumulativeIntensity (fun _ ↦ h_0) T = h_0 * T from cumHazard_const h_0 T] + congr 1; ring + +/-- **Credit spread as time-averaged hazard**: for `T > 0`, +`c(T) = -log(S(T)) / T = H(T) / T = (1/T) · ∫₀^T h(u) du`. -/ +lemma creditSpread_eq_time_avg_hazard {h : ℝ → ℝ} {T : ℝ} (_hT : 0 < T) : + -Real.log (hazardSurvival h T) / T = cumHazard h T / T := by + unfold hazardSurvival survivalFromIntensity cumHazard + rw [Real.log_exp, neg_neg] + +end MathFin diff --git a/LeanPool/MathFin/Models/Credit/KMVMerton.lean b/LeanPool/MathFin/Models/Credit/KMVMerton.lean new file mode 100644 index 0000000000..950a16f4d9 --- /dev/null +++ b/LeanPool/MathFin/Models/Credit/KMVMerton.lean @@ -0,0 +1,95 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.GarmanNormalForm + +/-! +# KMV-Merton structural credit (as a Garman-form specialisation) + +In the Merton (1974) / KMV structural credit-risk model, the firm's asset +value `V_t` follows the same lognormal dynamics as a Black-Scholes asset, +and default occurs at maturity `T` if `V_T < F` (face debt). Under the +risk-neutral measure, the **distance to default** at time `0` is the BS +`d_2` parameter with `V_0` as spot and `F` as strike, and the **risk-neutral +probability of default** is `Φ(−d_2)`. + +The structural insight: this is *not* a separate pricing model. Default-or- +not is the same Φ(d_2) that prices the cash-or-nothing digital option on +the firm's asset value. KMV-Merton is the **Garman normal form** of BS +applied with firm value as the asset and face debt as the strike: + + `Distance to default = gbsd2 V F (e^{−rT}) σ_V T`. + +This file used to alias `kmvDistanceToDefault := bsd2`, recording the same +fact under three different names. We now make the Garman connection +explicit (the unifying structural insight) and keep only the substantive +PD-as-probability bounds. + +## Main definitions + +* `kmvDistanceToDefault`: the distance to default in Garman normal form, + `d₂ = gbsd2 V F (e^{−rT}) σ_V T`, with the firm value as spot and the face debt as strike. +* `kmvPD`: the risk-neutral probability of default `Φ(−d₂)` at maturity `T`. + +## Main results + +* `kmvDistanceToDefault_eq_bsd2`: equivalence to the BS `bsd2` (this is + the *structural identity*, the same `d_2` from BS). +* `kmvPD_nonneg`, `kmvPD_le_one`: probability bounds. +* `kmv_survival_eq_Phi_d2`: `1 − PD = Φ(d_2)`. + +## Tags + +Merton model, KMV, distance to default, structural credit model, default probability, firm value, +MSC 91G40, JEL G33, JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- **Distance to default** in the KMV-Merton model, expressed in Garman normal +form: `d_2 = gbsd2 V F (e^{−rT}) σ_V T` with firm value `V` and face debt `F`. + +The Garman form makes the structural connection explicit: this is the *same* +`d_2` as the BS call formula, instantiated with credit-risk variables. -/ +noncomputable def kmvDistanceToDefault (V_0 F r σ_V T : ℝ) : ℝ := + gbsd2 V_0 F (Real.exp (-(r * T))) σ_V T + +/-- **The KMV distance-to-default equals the BS `d_2`** at the standard +parameters. This is *not* a new formula — it is the BS `d_2`, in different +variable names. -/ +theorem kmvDistanceToDefault_eq_bsd2 (V_0 F r σ_V T : ℝ) (hV : 0 < V_0) (hF : 0 < F) : + kmvDistanceToDefault V_0 F r σ_V T = bsd2 V_0 F r σ_V T := by + unfold kmvDistanceToDefault + rw [bsd2_eq_gbsd2_standard V_0 F r σ_V T hV hF] + +/-- **Risk-neutral probability of default** at maturity `T`. The same Φ(−d_2) +that prices the cash-or-nothing put on the firm value. -/ +noncomputable def kmvPD (V_0 F r σ_V T : ℝ) : ℝ := + Phi (-(kmvDistanceToDefault V_0 F r σ_V T)) + +/-- **PD ≥ 0** (Φ takes non-negative values). -/ +lemma kmvPD_nonneg (V_0 F r σ_V T : ℝ) : 0 ≤ kmvPD V_0 F r σ_V T := + Phi_nonneg _ + +/-- **PD ≤ 1** (`Φ` takes values in `[0,1]`; `Phi_le_one` from `StandardNormal`). -/ +lemma kmvPD_le_one (V_0 F r σ_V T : ℝ) : kmvPD V_0 F r σ_V T ≤ 1 := + Phi_le_one _ + +/-- **Survival = 1 − PD = Φ(d_2)**: the risk-neutral probability of no default. -/ +theorem kmv_survival_eq_Phi_d2 (V_0 F r σ_V T : ℝ) : + 1 - kmvPD V_0 F r σ_V T = Phi (kmvDistanceToDefault V_0 F r σ_V T) := by + unfold kmvPD + have := Phi_add_Phi_neg (kmvDistanceToDefault V_0 F r σ_V T) + linarith + +end MathFin diff --git a/LeanPool/MathFin/Models/Credit/KMVMertonStructural.lean b/LeanPool/MathFin/Models/Credit/KMVMertonStructural.lean new file mode 100644 index 0000000000..551f0ec306 --- /dev/null +++ b/LeanPool/MathFin/Models/Credit/KMVMertonStructural.lean @@ -0,0 +1,101 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Credit.KMVMerton +public import LeanPool.MathFin.Models.BlackScholes.RiskNeutralProbabilities + +/-! +# KMV-Merton structural model: probabilistic content of `kmvPD` + +The pre-existing `Models/Credit/KMVMerton.lean` defines `kmvPD := Phi(−kmvDD)` +and proves the algebraic survival identity `1 − kmvPD = Phi(kmvDD)`. The +*probabilistic content* — namely, that `kmvPD` is the actual risk-neutral +probability of default `Q({V_T ≤ F})` — was previously stated only in the +docstring. + +This file proves the connection rigorously using `riskNeutralProb_S_T_gt_K` +from `Models/BlackScholes/RiskNeutralProbabilities.lean`. With firm asset value +`V_T = bsTerminal V_0 r σ_V T (Z ·)` under the risk-neutral measure `Q` and +debt face `F`, the no-default probability is + + `Q({V_T > F}) = Phi(bsd2 V_0 F r σ_V T) = 1 − kmvPD`, + +so default probability `Q({V_T ≤ F}) = kmvPD = Phi(−bsd2)`. + +The structural identity **equity = call on firm assets** (Merton 1974) needs no theorem of its +own: limited liability makes the equity payoff `max(V_T − F, 0)`, so its discounted risk-neutral +value is `bs_call_formula` read with `(S_0, K, σ) ↦ (V_0, F, σ_V)`. + +## Main results + +* `kmvPD_eq_one_sub_survival_probability`: connects `kmvPD` to the actual + risk-neutral probability `Q({V_T > F})`. + +## References + +* [R. C. Merton, *On the pricing of corporate debt: the risk structure of interest + rates*][Merton1974] + +## Tags + +Merton model, KMV, risk-neutral default probability, structural credit model, equity as call option, +distance to default, MSC 91G40, MSC 91G20, JEL G33 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- **KMV-Merton default probability identification**: under the BS lognormal +hypothesis for firm asset value `V_T = bsTerminal V_0 r σ_V T (Z ·)`, + + `kmvPD V_0 F r σ_V T = 1 − Q({ω | V_T(ω) > F}).toReal`. + +The RHS is *one minus the risk-neutral survival probability*. Combined with +`riskNeutralProb_S_T_gt_K`, this gives `kmvPD` the genuine probabilistic +interpretation it was advertised to have. -/ +theorem kmvPD_eq_one_sub_survival_probability + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {V_0 F r σ_V T : ℝ} {Z : Ω → ℝ} + (hV : 0 < V_0) (hF : 0 < F) + (h : BSCallHyp Q V_0 F r σ_V T Z) : + kmvPD V_0 F r σ_V T = + 1 - (Q {ω | bsTerminal V_0 r σ_V T (Z ω) > F}).toReal := by + rw [riskNeutralProb_S_T_gt_K h] + rw [← kmvDistanceToDefault_eq_bsd2 V_0 F r σ_V T hV hF] + have := kmv_survival_eq_Phi_d2 V_0 F r σ_V T + linarith + +/-- **KMV-Merton survival probability closed form**: under the BS lognormal +hypothesis for the firm asset value `V_T = bsTerminal V_0 r σ_V T (Z ·)`, the +risk-neutral survival (no-default) probability *is* `Φ` of the distance to +default: + + `Q({ω | V_T(ω) > F}).toReal = Phi (kmvDistanceToDefault V_0 F r σ_V T)`. + +This is the genuinely probabilistic survival statement — it computes the +measure of the no-default event itself through the lognormal tail +(`riskNeutralProb_S_T_gt_K`), not merely the CDF symmetry +`1 − Φ(−DD) = Φ(DD)` recorded in `KMVMerton.lean`. Complements +`kmvPD_eq_one_sub_survival_probability` (the PD identification) with the +closed form on the survival side. -/ +theorem survival_probability_eq_Phi_distanceToDefault + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {V_0 F r σ_V T : ℝ} {Z : Ω → ℝ} + (hV : 0 < V_0) (hF : 0 < F) + (h : BSCallHyp Q V_0 F r σ_V T Z) : + (Q {ω | bsTerminal V_0 r σ_V T (Z ω) > F}).toReal = + Phi (kmvDistanceToDefault V_0 F r σ_V T) := by + rw [riskNeutralProb_S_T_gt_K h, kmvDistanceToDefault_eq_bsd2 V_0 F r σ_V T hV hF] + +end MathFin diff --git a/LeanPool/MathFin/Models/Forwards/AR1OUCalibration.lean b/LeanPool/MathFin/Models/Forwards/AR1OUCalibration.lean new file mode 100644 index 0000000000..33fb9941f9 --- /dev/null +++ b/LeanPool/MathFin/Models/Forwards/AR1OUCalibration.lean @@ -0,0 +1,173 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.VasicekSDEGaussian + +/-! +# AR(1) ↔ OU parameter inversion + +A discretely-sampled Ornstein-Uhlenbeck (Vasicek) process with long-run level +`θ`, observed on a grid of spacing `Δt`, is an AR(1) process +`x_{n+1} − θ = φ (x_n − θ) + ε_n`. One step of that statement is derived here from the +library's OU law (`vasicekShortRate_hasLaw_gaussian`, `Models/Rates/VasicekSDEGaussian.lean`): +from a deterministic start `r₀`, the residual `ε = (r_Δt − θ) − φ·(r₀ − θ)`, `φ = e^{−kΔt}`, +is Gaussian `N(0, vasicekSDEVariance σ k Δt)` (`ouStepResidual_hasLaw`), and the dictionary +below recovers `σ²` from its variance (`ouSigmaSqFromVar_variance_ouStepResidual`). The +multi-step statement — independent innovations along a path started from the random +previous state — needs the OU Markov transition law and is not formalized. This file +records the standard dictionary between the AR(1) fit `(φ, Var(resid))` and the +continuous-time OU parameters `(k, σ)`: + + `φ = e^{−kΔt}` (mean-reversion discount) + `k = −ln(φ)/Δt` (inverse: mean-reversion speed) + `σ² = 2k·Var(resid) / (1 − e^{−2kΔt})` (diffusion coefficient) + `half-life = ln 2 / k` + +The dictionary is algebra on the closed forms `vasicekSDEMean` and +`vasicekSDEVariance` of `Models/Rates/VasicekSDE.lean`: `ouPhiFromK` is literally the +decay factor appearing in `vasicekSDEMean`, and `ouSigmaSqFromVar` inverts +`vasicekSDEVariance` for `σ²` given an observed residual variance. The last section ties +it to the OU law. + +## Main definitions + +* `ouPhiFromK`: the AR(1) discount factor `φ = exp (-(k Δt))` from the OU speed `k`. +* `kFromPhi`: the OU speed `-log φ / Δt` from `φ`. +* `ouSigmaSqFromVar`: `σ² = 2k Var(resid) / (1 - exp (-2kΔt))` from the fitted residual variance. +* `ouStepResidual`: the AR(1) residual `(r_Δt - θ) - φ (r₀ - θ)` of one Vasicek/OU step from a + deterministic start `r₀`, with `φ = ouPhiFromK k Δt`. + +## Main results + +* `ouPhiFromK`, `kFromPhi` : the `φ ↔ k` dictionary: `kFromPhi ∘ ouPhiFromK` + is the identity for `Δt ≠ 0` (`kFromPhi_ouPhiFromK`), and `ouPhiFromK ∘ kFromPhi` + is the identity on `φ > 0` for `Δt ≠ 0` (`ouPhiFromK_kFromPhi`). +* `ouPhiFromK_halfLife` : the decay factor at `Models.Rates.Vasicek`'s existing + `meanReversionHalfLife` (`ln 2 / k`) is `1/2`, for `k ≠ 0`. +* `ouSigmaSqFromVar_vasicekSDEVariance` : `ouSigmaSqFromVar` recovers `σ²` from + `vasicekSDEVariance σ k Δt`, for `k ≠ 0` and `1 − e^{−2kΔt} ≠ 0` (one direction + of the round trip: recovering a residual variance from `ouSigmaSqFromVar` is not + stated). +* `ouStepResidual_hasLaw` : one OU step from `r₀` is an AR(1) step — the residual + `(r_Δt − θ) − ouPhiFromK k Δt · (r₀ − θ)` of the short rate in its Wiener representation + has law `N(0, vasicekSDEVariance σ k Δt)`, for `k > 0`. +* `ouSigmaSqFromVar_variance_ouStepResidual` : `ouSigmaSqFromVar` applied to the variance + of that residual returns `σ²`, for `k, Δt > 0`. + +## References + +* [P. Glasserman, *Monte Carlo Methods in Financial Engineering*][Glasserman2003], §3.3 + +## Tags + +AR(1) process, Ornstein–Uhlenbeck, mean reversion speed, half-life, parameter calibration, Vasicek, +MSC 62M10, MSC 91G30, JEL C22 +-/ + +@[expose] public section + +namespace MathFin + +/-! ### The `φ ↔ k` dictionary -/ + +/-- **AR(1) discount factor from OU speed**: `φ = e^{−kΔt}`. -/ +noncomputable def ouPhiFromK (k Δt : ℝ) : ℝ := Real.exp (-(k * Δt)) + +/-- **OU mean-reversion speed from AR(1) discount factor**: `k = −ln(φ)/Δt`. -/ +noncomputable def kFromPhi (φ Δt : ℝ) : ℝ := -Real.log φ / Δt + +/-- **Diffusion coefficient from fitted residual variance**: +`σ² = 2k·Var(resid) / (1 − e^{−2kΔt})`, inverting `vasicekSDEVariance` for +`σ²` given the AR(1) fit's residual variance at spacing `Δt`. -/ +noncomputable def ouSigmaSqFromVar (k residVar Δt : ℝ) : ℝ := + 2 * k * residVar / (1 - Real.exp (-(2 * k * Δt))) + +/-- **`ouSigmaSqFromVar` inverts `vasicekSDEVariance`**: feeding it the +closed-form Vasicek/OU variance at spacing `Δt` recovers the diffusion +coefficient `σ²` it came from, for `k ≠ 0` and `1 − e^{−2kΔt} ≠ 0` (e.g. +`k, Δt` both nonzero). -/ +theorem ouSigmaSqFromVar_vasicekSDEVariance (σ k Δt : ℝ) (hk : k ≠ 0) + (hden : 1 - Real.exp (-(2 * k * Δt)) ≠ 0) : + ouSigmaSqFromVar k (vasicekSDEVariance σ k Δt) Δt = σ ^ 2 := by + unfold ouSigmaSqFromVar vasicekSDEVariance + field_simp + +/-- Recovering `k` from the `φ` it generates: `kFromPhi (ouPhiFromK k Δt) Δt = k`, +for any `Δt ≠ 0`. -/ +theorem kFromPhi_ouPhiFromK (k Δt : ℝ) (hΔt : Δt ≠ 0) : + kFromPhi (ouPhiFromK k Δt) Δt = k := by + unfold kFromPhi ouPhiFromK + rw [Real.log_exp] + field_simp + +/-- Recovering `φ` from the `k` it generates: `ouPhiFromK (kFromPhi φ Δt) Δt = φ`, +for `φ > 0` and `Δt ≠ 0`. -/ +theorem ouPhiFromK_kFromPhi (φ Δt : ℝ) (hφ : 0 < φ) (hΔt : Δt ≠ 0) : + ouPhiFromK (kFromPhi φ Δt) Δt = φ := by + unfold ouPhiFromK kFromPhi + rw [neg_div, neg_mul, neg_neg, div_mul_cancel₀ _ hΔt, Real.exp_log hφ] + +/-- The decay factor at `Models.Rates.Vasicek`'s existing `meanReversionHalfLife` +is exactly `1/2`, for `k ≠ 0`. -/ +theorem ouPhiFromK_halfLife (k : ℝ) (hk : k ≠ 0) : + ouPhiFromK k (meanReversionHalfLife k) = 1 / 2 := by + unfold ouPhiFromK meanReversionHalfLife + rw [mul_div_cancel₀ _ hk, Real.exp_neg, Real.exp_log (by norm_num : (0:ℝ) < 2), one_div] + +/-! ### One OU step is an AR(1) step -/ + +section OneStep + +open MeasureTheory ProbabilityTheory +open scoped NNReal +open WienerIntegralL2 + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-- **The AR(1) residual of one OU step**: `ε = (r_Δt − θ) − φ·(r₀ − θ)` with +`φ = ouPhiFromK k Δt`, for the short rate after one step `Δt` from the deterministic start +`r₀`, carried in the Wiener representation of `vasicekShortRate_hasLaw_gaussian` +(`r_Δt = vasicekSDEMean r₀ θ k Δt + σ ∫₀^Δt e^{−k(Δt−s)} dB_s`). -/ +noncomputable def ouStepResidual (hB : IsPreBrownianReal B μ) (r₀ θ σ : ℝ) {k : ℝ} + (hk : 0 < k) (Δt : ℝ≥0) (ω : Ω) : ℝ := + (vasicekSDEMean r₀ θ k Δt + σ * wienerIntegralLp B hB Δt (vasicekKernelLp k hk.le Δt) ω - θ) + - ouPhiFromK k Δt * (r₀ - θ) + +/-- **One OU step is an AR(1) step.** The residual `(r_Δt − θ) − φ·(r₀ − θ)` of one OU step +from `r₀` is centred Gaussian with variance `vasicekSDEVariance σ k Δt`: the deterministic +part of `r_Δt − θ` is exactly `φ·(r₀ − θ)` (`vasicekSDEMean r₀ θ k Δt = θ + φ·(r₀ − θ)`), and +the rest is the Gaussian law of `vasicekShortRate_hasLaw_gaussian` shifted to mean zero. -/ +theorem ouStepResidual_hasLaw (hB : IsPreBrownianReal B μ) (r₀ θ σ : ℝ) {k : ℝ} + (hk : 0 < k) (Δt : ℝ≥0) : + HasLaw (ouStepResidual hB r₀ θ σ hk Δt) + (gaussianReal 0 (vasicekSDEVariance σ k Δt).toNNReal) μ := by + have h := gaussianReal_sub_const (vasicekShortRate_hasLaw_gaussian hB r₀ θ σ hk Δt) + (vasicekSDEMean r₀ θ k Δt) + rw [sub_self] at h + convert h using 1 + funext ω + simp only [ouStepResidual, vasicekSDEMean, ouPhiFromK] + ring + +/-- **The calibration dictionary recovers `σ²` from the residual's variance.** For `k > 0` +and `Δt > 0`, `ouSigmaSqFromVar k Var[ε] Δt = σ²`, where `ε` is the one-step residual of +`ouStepResidual_hasLaw`: its variance is `vasicekSDEVariance σ k Δt`, which +`ouSigmaSqFromVar_vasicekSDEVariance` inverts. -/ +theorem ouSigmaSqFromVar_variance_ouStepResidual (hB : IsPreBrownianReal B μ) + (r₀ θ σ : ℝ) {k : ℝ} (hk : 0 < k) {Δt : ℝ≥0} (hΔt : 0 < (Δt : ℝ)) : + ouSigmaSqFromVar k (Var[ouStepResidual hB r₀ θ σ hk Δt; μ]) Δt = σ ^ 2 := by + rw [(ouStepResidual_hasLaw hB r₀ θ σ hk Δt).variance_eq, variance_id_gaussianReal, + Real.coe_toNNReal _ (vasicekSDEVariance_nonneg σ hk hΔt.le)] + refine ouSigmaSqFromVar_vasicekSDEVariance σ k Δt hk.ne' (sub_pos.mpr ?_).ne' + exact Real.exp_lt_one_iff.mpr (neg_lt_zero.mpr (mul_pos (mul_pos two_pos hk) hΔt)) + +end OneStep + +end MathFin diff --git a/LeanPool/MathFin/Models/Forwards/Black76.lean b/LeanPool/MathFin/Models/Forwards/Black76.lean new file mode 100644 index 0000000000..e87f7e043f --- /dev/null +++ b/LeanPool/MathFin/Models/Forwards/Black76.lean @@ -0,0 +1,213 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho, Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.GarmanNormalForm + +/-! +# Black-76 formula for options on futures + +The **Black formula** (Black 1976) prices European options on futures +contracts. Under the risk-neutral measure, the futures price is a +martingale (zero drift), so + + F_T = F · exp(-σ²T/2 + σ √T · Z), Z ~ N(0, 1). + +The European call payoff `max(F_T − K, 0)` discounted gives + + V_Black = e^{−rT} · [F · Φ(d_1) − K · Φ(d_2)], + +where `d_1 = (log(F/K) + σ²T/2) / (σ √T)` and `d_2 = d_1 − σ √T`. + +This is identical to `bs_call_formula` specialized to `r = 0` in the +BS-drift, then post-discounted by `e^{-rT}` (the discount-rate is now +**independent** of the underlying's drift). The proof is therefore a +direct algebraic specialization. + +## Main definitions + +* `blackPayerSwaption`: `A · [F Φ(d₁) − K Φ(d₂)]` with `d_i = bsd_i F K 0 σ T`. +* `blackReceiverSwaption`: `A · [K Φ(−d₂) − F Φ(−d₁)]`. +* `blackCaplet`: `α · [F Φ(d₁) − K Φ(d₂)]`, the accrual-scaled Black-76 call on the forward + rate `F`. +* `blackFloorlet`: `α · [K Φ(−d₂) − F Φ(−d₁)]`, the put counterpart. + +## Main results + +* `black_futures_formula`: under `BSCallHyp Q F K 0 σ T Z`, the discounted expected futures-call + payoff is `e^{−rT}(F Φ(d₁) − K Φ(d₂))`. +* `black_futures_price_eq_bsVGarman`: that price is an instance of `bsVGarman`. +* `black_futures_formula_atm`: at `K = F` it equals `e^{−rT} F (2Φ(σ√T/2) − 1)`. +* `swaption_payer_receiver_parity`: `blackPayerSwaption − blackReceiverSwaption = A (F − K)`. +* `caplet_floorlet_parity`: `blackCaplet − blackFloorlet = α (F − K)`. +* `blackPayerSwaption_eq_bsVGarman`: for `A > 0`, the payer swaption is `bsVGarman (F·A) K A σ T`. +* `blackCaplet_eq_blackPayerSwaption`, `blackFloorlet_eq_blackReceiverSwaption`: the caplet and + floorlet are the payer and receiver swaption with the accrual `α` in place of the annuity. + +## References + +* [F. Black, *The pricing of commodity contracts*][Black1976] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 18.7; 29.2 + +## Tags + +Black-76, Black formula, options on futures, futures option pricing, lognormal futures, +European call on futures, MSC 91G20, JEL G13, JEL Q02 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- **Black-76 formula** for European call options on futures. + +Given the risk-neutral hypothesis `BSCallHyp Q F K 0 σ T Z` (i.e., the futures +price has zero drift under `Q`), the discounted expected payoff under an +**independent** discount rate `r` is + + e^{-rT} · [F · Φ(d_1) − K · Φ(d_2)], + +where `d_i = bsdi F K 0 σ T`. + +Real derivation: applies `bs_call_formula` with `r = 0` (no +intra-formula discounting) and multiplies through by the external +discount factor `e^{-rT}`. -/ +theorem black_futures_formula {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {F K σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q F K 0 σ T Z) (r : ℝ) : + ∫ ω, Real.exp (-r * T) * max (bsTerminal F 0 σ T (Z ω) - K) 0 ∂Q + = Real.exp (-r * T) * + (F * Phi (bsd1 F K 0 σ T) - K * Phi (bsd2 F K 0 σ T)) := by + rw [integral_const_mul] + have h_bs := bs_call_formula h + -- Specialize r=0 in bs_call_formula + simp only [neg_zero, zero_mul, Real.exp_zero, one_mul, mul_one] at h_bs + -- h_bs : ∫ ω, max (bsTerminal F 0 σ T (Z ω) - K) 0 ∂Q + -- = F * Phi (bsd1 F K 0 σ T) - K * Phi (bsd2 F K 0 σ T) + rw [h_bs] + +/-- **Black-76 price is a Garman-normal-form instance**: the discounted +expected futures-call payoff equals `bsVGarman` at `A = F · e^{−rT}`, +`DF = e^{−rT}` — the forward numéraire. Routes `black_futures_formula` +through `Models/BlackScholes/GarmanNormalForm`'s `black76_RHS_eq_bsVGarman`, making +the "Black-76 is the same formula as standard BS" unification load-bearing +from the consumer side. -/ +theorem black_futures_price_eq_bsVGarman {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {F K σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q F K 0 σ T Z) (r : ℝ) : + ∫ ω, Real.exp (-r * T) * max (bsTerminal F 0 σ T (Z ω) - K) 0 ∂Q + = bsVGarman (F * Real.exp (-(r * T))) K (Real.exp (-(r * T))) σ T := by + rw [black_futures_formula h r, neg_mul] + exact black76_RHS_eq_bsVGarman F K r σ T h.S_0_pos h.K_pos + +/-- **The at-the-money Black-76 call**: at strike `K = F`, `d₁ = σ√T/2 = −d₂`, so the +discounted expected futures-call payoff is `e^{−rT} · F · (2Φ(σ√T/2) − 1)`. Derived from +`black_futures_formula` and `Φ(x) + Φ(−x) = 1`. -/ +theorem black_futures_formula_atm {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {F σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q F F 0 σ T Z) (r : ℝ) : + ∫ ω, Real.exp (-r * T) * max (bsTerminal F 0 σ T (Z ω) - F) 0 ∂Q + = Real.exp (-r * T) * F * (2 * Phi (σ * Real.sqrt T / 2) - 1) := by + have hd1 : bsd1 F F 0 σ T = σ * Real.sqrt T / 2 := by + have hs : Real.sqrt T ≠ 0 := (Real.sqrt_pos.mpr h.T_pos).ne' + rw [bsd1, div_self h.S_0_pos.ne', Real.log_one, div_eq_iff (mul_ne_zero h.σ_pos.ne' hs)] + linear_combination (-(σ ^ 2) / 2) * Real.mul_self_sqrt h.T_pos.le + have hd2 : bsd2 F F 0 σ T = -(σ * Real.sqrt T / 2) := by rw [bsd2, hd1]; ring + rw [black_futures_formula h r, hd2, hd1] + linear_combination (-(Real.exp (-r * T) * F)) * Phi_add_Phi_neg (σ * Real.sqrt T / 2) + +/-! ## Black model for swaptions (folded from `Swaption.lean`) + +A swaption with strike `K`, forward swap rate `F`, annuity `A`, vol `σ`, +expiry `T` prices via the Black-76 formula scaled by the annuity numéraire. + +Payer-receiver parity `V^payer − V^receiver = A · (F − K)` is the swap-rate +analog of put-call parity, with the same one-line proof via `Φ` symmetry. -/ + +/-- **Payer swaption price under the Black model**: `A · [F · Φ(d_1) − K · Φ(d_2)]`. -/ +noncomputable def blackPayerSwaption (A F K σ T : ℝ) : ℝ := + A * (F * Phi (bsd1 F K 0 σ T) - K * Phi (bsd2 F K 0 σ T)) + +/-- **Receiver swaption price under the Black model**: +`A · [K · Φ(−d_2) − F · Φ(−d_1)]`. -/ +noncomputable def blackReceiverSwaption (A F K σ T : ℝ) : ℝ := + A * (K * Phi (-(bsd2 F K 0 σ T)) - F * Phi (-(bsd1 F K 0 σ T))) + +/-- **Payer-receiver swaption parity**: `V^payer − V^receiver = A · (F − K)`. +The same `Phi`-symmetry proof as put-call parity, scaled by the annuity. -/ +theorem swaption_payer_receiver_parity (A F K σ T : ℝ) : + blackPayerSwaption A F K σ T - blackReceiverSwaption A F K σ T = + A * (F - K) := by + unfold blackPayerSwaption blackReceiverSwaption + have h_d1 := Phi_add_Phi_neg (bsd1 F K 0 σ T) + have h_d2 := Phi_add_Phi_neg (bsd2 F K 0 σ T) + linear_combination A * F * h_d1 - A * K * h_d2 + +/-- **The payer swaption is a Garman normal form**: `blackPayerSwaption A F K σ T += bsVGarman (F·A) K A σ T`, the annuity `A` in the discount-factor slot and +`F·A` the asset. Makes explicit that `GarmanNormalForm`'s docstring earmark for +the swaption is a genuine instance (`A_annuity·F` asset, `A_annuity` discount), +so the payer/receiver parity above is the Garman-level parity in disguise. -/ +theorem blackPayerSwaption_eq_bsVGarman (A F K σ T : ℝ) (hA : 0 < A) : + blackPayerSwaption A F K σ T = bsVGarman (F * A) K A σ T := by + have hd1 : bsd1 F K 0 σ T = gbsd1 (F * A) K A σ T := by + unfold bsd1 gbsd1 + rw [mul_div_mul_right F K hA.ne'] + ring_nf + have hd2 : bsd2 F K 0 σ T = gbsd2 (F * A) K A σ T := by + unfold bsd2 gbsd2; rw [hd1] + unfold blackPayerSwaption bsVGarman + rw [hd1, hd2]; ring + +/-! ## Black-76 caplet and floorlet + +A **caplet** is a European call on a forward rate, scaled by the accrual factor +`α` over the accrual period; a **floorlet** is its put counterpart. Both follow +the same no-separate-discount convention as the swaption above — the forward +numéraire absorbs the drift, so the discount does not appear in the formula. + +Written out, the caplet is `α · [F Φ(d₁) − K Φ(d₂)]`, which is the payer +swaption's formula with the accrual factor sitting in the annuity slot. That is +not a coincidence worth hiding: `blackCaplet_eq_blackPayerSwaption` records it, +and caplet-floorlet parity is then the payer-receiver parity already proved +above, applied. -/ + +/-- **Black-76 caplet price**: `α · [F Φ(d₁) − K Φ(d₂)]`, the accrual-scaled +Black-76 call on the forward rate `F`, with `d_i = bsd_i F K 0 σ T`. -/ +noncomputable def blackCaplet (F K σ T α : ℝ) : ℝ := + α * (F * Phi (bsd1 F K 0 σ T) - K * Phi (bsd2 F K 0 σ T)) + +/-- **Black-76 floorlet price**: `α · [K Φ(−d₂) − F Φ(−d₁)]`, the put counterpart +of `blackCaplet`. -/ +noncomputable def blackFloorlet (F K σ T α : ℝ) : ℝ := + α * (K * Phi (-(bsd2 F K 0 σ T)) - F * Phi (-(bsd1 F K 0 σ T))) + +/-- **The caplet is a payer swaption in disguise**: same Black-76 shape, with the +accrual factor `α` where the swaption carries its annuity `A`. The two +instruments differ in their numéraire story, not in their formula. -/ +theorem blackCaplet_eq_blackPayerSwaption (F K σ T α : ℝ) : + blackCaplet F K σ T α = blackPayerSwaption α F K σ T := rfl + +/-- **The floorlet is a receiver swaption in disguise**, by the same reading. -/ +theorem blackFloorlet_eq_blackReceiverSwaption (F K σ T α : ℝ) : + blackFloorlet F K σ T α = blackReceiverSwaption α F K σ T := rfl + +/-- **Caplet-floorlet parity**: `V^caplet − V^floorlet = α · (F − K)`, the +forward-rate analogue of put-call parity. Given the structural identity above it +*is* payer-receiver parity, so it is that theorem applied rather than the same +`Phi`-symmetry argument run a second time. -/ +theorem caplet_floorlet_parity (F K σ T α : ℝ) : + blackCaplet F K σ T α - blackFloorlet F K σ T α = α * (F - K) := + swaption_payer_receiver_parity α F K σ T + +end MathFin diff --git a/LeanPool/MathFin/Models/Forwards/Black76Greeks.lean b/LeanPool/MathFin/Models/Forwards/Black76Greeks.lean new file mode 100644 index 0000000000..1394686b6f --- /dev/null +++ b/LeanPool/MathFin/Models/Forwards/Black76Greeks.lean @@ -0,0 +1,169 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.PDE +public import LeanPool.MathFin.Models.BlackScholes.HigherGreeks + +/-! +# Black-76 Greeks + +For the Black-76 futures call price `V_B(F, σ, T) = e^{-rT} · [F Φ(d₁) − K Φ(d₂)]` +with `d_i = bsdi F K 0 σ T` (i.e., zero drift), the Greeks are simply the BS +Greeks evaluated at `r = 0` and post-multiplied by the discount factor `e^{-rT}`: + +* `hasDerivAt_blackV_F` — δ = e^{-rT} · Φ(d₁). +* `hasDerivAt_deriv_blackV_F` — γ = e^{-rT} · ϕ(d₁) / (F σ √T), from the + formula-level `hasDerivAt_blackV_FF`. +* `hasDerivAt_deriv_deriv_blackV_F` — speed = e^{-rT} · (-ϕ(d₁) (d₁ + σ√T) / (F² σ² T)). +* `hasDerivAt_blackV_sigma` — vega = e^{-rT} · F · ϕ(d₁) · √T. + +## Main definitions + +* `blackV`: the Black-76 futures call price `e^{−rT}·bsV(K, 0, σ, F, T)` as a function of + `(F, σ, T)` and the discount rate `r`. + +## Main results + +* `hasDerivAt_blackV_F`: delta, `∂_F V_B = e^{−rT} Φ(d₁)`. +* `hasDerivAt_deriv_blackV_F`: gamma, `∂²_F V_B = e^{−rT} ϕ(d₁) / (F σ √T)`. +* `hasDerivAt_deriv_deriv_blackV_F`: speed, the third `F`-derivative of `V_B`. +* `hasDerivAt_blackV_sigma`: vega, `∂_σ V_B = e^{−rT} F ϕ(d₁) √T`. +* `hasDerivAt_blackV_r`: rho, `∂_r V_B = −T · V_B`. +* `hasDerivAt_blackV_T`: the `T`-derivative of `V_B`, `−r V_B + e^{−rT} σ F ϕ(d₁) / (2√T)`. + +These hold for `K, σ, F, T > 0` (rho for all reals). + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 17.6 + +## Tags + +Black-76 model, futures option, delta, gamma, vega, speed, option sensitivities, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- Black-76 futures call price as a function of `(F, σ, T)` plus discount rate `r`. +Specialization of `bsV` to zero drift, times an external discount `e^{-rT}`. -/ +noncomputable def blackV (K σ : ℝ) (r F T : ℝ) : ℝ := + Real.exp (-(r * T)) * bsV K 0 σ F T + +/-- **Black-76 delta**: `∂_F V_B = e^{-rT} · Φ(d₁)`. -/ +lemma hasDerivAt_blackV_F {K σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (r : ℝ) + {F T : ℝ} (hF : 0 < F) (hT : 0 < T) : + HasDerivAt (fun f ↦ blackV K σ r f T) (Real.exp (-(r * T)) * Phi (bsd1 F K 0 σ T)) F := + (hasDerivAt_bsV_S (r := 0) hK hσ hF hT).const_mul (Real.exp (-(r * T))) + +/-- **The Black-76 gamma formula**: the F-derivative of the delta `e^{-rT} · Φ(d₁)` is +`e^{-rT} · ϕ(d₁) / (F σ √T)`. The second derivative of the price itself is +`hasDerivAt_deriv_blackV_F`. -/ +private lemma hasDerivAt_blackV_FF {K σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (r : ℝ) + {F T : ℝ} (hF : 0 < F) (hT : 0 < T) : + HasDerivAt (fun f ↦ Real.exp (-(r * T)) * Phi (bsd1 f K 0 σ T)) + (Real.exp (-(r * T)) * gaussianPDFReal 0 1 (bsd1 F K 0 σ T) / (F * σ * Real.sqrt T)) F := by + have h_bs := hasDerivAt_Phi_bsd1_S (r := 0) hK hσ hF hT + have h := h_bs.const_mul (Real.exp (-(r * T))) + convert h using 1 + ring + +/-- **Black-76 gamma**: `∂²V_B/∂F² = e^{-rT} · ϕ(d₁) / (F σ √T)`, for the price itself: the +delta `e^{-rT} · Φ(d₁)` is `∂V_B/∂F` on all of `F > 0` (`hasDerivAt_blackV_F`), and its +derivative is the gamma formula (`hasDerivAt_blackV_FF`). -/ +theorem hasDerivAt_deriv_blackV_F {K σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (r : ℝ) + {F T : ℝ} (hF : 0 < F) (hT : 0 < T) : + HasDerivAt (deriv fun f ↦ blackV K σ r f T) + (Real.exp (-(r * T)) * gaussianPDFReal 0 1 (bsd1 F K 0 σ T) / (F * σ * Real.sqrt T)) F := + hasDerivAt_deriv_of_eventually + ((eventually_gt_nhds hF).mono fun _ hf ↦ hasDerivAt_blackV_F hK hσ r hf hT) + (hasDerivAt_blackV_FF hK hσ r hF hT) + +/-- **The Black-76 speed formula**: the F-derivative of the gamma formula is +`e^{-rT} · (-ϕ(d₁) (d₁ + σ√T) / (F² σ² T))`. The third derivative of the price itself is +`hasDerivAt_deriv_deriv_blackV_F`. + +Same shape as the other Black-76 Greeks: the discount factor does not depend on +`F`, so it rides through the differentiation as a constant multiplier on the +zero-drift BS speed. -/ +private lemma hasDerivAt_blackV_FFF {K σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (r : ℝ) + {F T : ℝ} (hF : 0 < F) (hT : 0 < T) : + HasDerivAt (fun f ↦ Real.exp (-(r * T)) * + (gaussianPDFReal 0 1 (bsd1 f K 0 σ T) / (f * σ * Real.sqrt T))) + (Real.exp (-(r * T)) * -(gaussianPDFReal 0 1 (bsd1 F K 0 σ T) * + (bsd1 F K 0 σ T + σ * Real.sqrt T) / (F ^ 2 * σ ^ 2 * T))) F := + (hasDerivAt_bsV_SSS (r := 0) hK hσ hF hT).const_mul (Real.exp (-(r * T))) + +/-- **Black-76 speed**: `∂³V_B/∂F³ = e^{-rT} · (-ϕ(d₁) (d₁ + σ√T) / (F² σ² T))`, for the +price itself: the genuine gamma `hasDerivAt_deriv_blackV_F` holds on all of `F > 0`, and the +derivative of its formula is `hasDerivAt_blackV_FFF`. -/ +theorem hasDerivAt_deriv_deriv_blackV_F {K σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (r : ℝ) + {F T : ℝ} (hF : 0 < F) (hT : 0 < T) : + HasDerivAt (deriv (deriv fun f ↦ blackV K σ r f T)) + (Real.exp (-(r * T)) * -(gaussianPDFReal 0 1 (bsd1 F K 0 σ T) * + (bsd1 F K 0 σ T + σ * Real.sqrt T) / (F ^ 2 * σ ^ 2 * T))) F := + hasDerivAt_deriv_of_eventually + ((eventually_gt_nhds hF).mono fun _ hf ↦ + (hasDerivAt_deriv_blackV_F hK hσ r hf hT).congr_deriv (mul_div_assoc _ _ _)) + (hasDerivAt_blackV_FFF hK hσ r hF hT) + +/-- **Black-76 vega**: `∂_σ V_B = e^{-rT} · F · ϕ(d₁) · √T`. -/ +lemma hasDerivAt_blackV_sigma {K : ℝ} (hK : 0 < K) (r : ℝ) + {F σ T : ℝ} (hF : 0 < F) (hσ : 0 < σ) (hT : 0 < T) : + HasDerivAt (fun s ↦ blackV K s r F T) + (Real.exp (-(r * T)) * F * gaussianPDFReal 0 1 (bsd1 F K 0 σ T) * Real.sqrt T) σ := by + have h_bs := hasDerivAt_bsV_sigma (r := 0) hK hF hσ hT + have h := h_bs.const_mul (Real.exp (-(r * T))) + convert h using 1 <;> try rfl + ring + +/-- **Black-76 rho**: `∂_r V_B = -T · V_B`. + +`V_B = e^{-rT} · bsV(K, 0, σ, F, T)`; the inner bsV is `r`-independent (zero-drift +futures setup), so only the discount factor contributes. Clean closed form. -/ +lemma hasDerivAt_blackV_r (K σ F T : ℝ) (r : ℝ) : + HasDerivAt (fun r' ↦ blackV K σ r' F T) + (-T * blackV K σ r F T) r := by + have h_neg : HasDerivAt (fun r' : ℝ ↦ -(r' * T)) (-T) r := by + have h := (hasDerivAt_id r).mul_const T + convert h.neg using 1 <;> first | rfl | ring + have h_exp : HasDerivAt (fun r' : ℝ ↦ Real.exp (-(r' * T))) + (Real.exp (-(r * T)) * (-T)) r := h_neg.exp + have h := h_exp.mul_const (bsV K 0 σ F T) + unfold blackV + convert h using 1 + ring + +/-- **Black-76 theta** (`∂_T` form): `∂_T V_B = -r · V_B + e^{-rT} · σ · F · ϕ(d₁) / (2√T)`. + +Product rule on `V_B = e^{-rT} · bsV(K, 0, σ, F, T)`: +* `∂_T e^{-rT} = -r · e^{-rT}` +* `∂_T bsV(K, 0, σ, F, T) = σ · F · ϕ(d₁) / (2√T)` from `hasDerivAt_bsV_tau` at `r = 0`. -/ +lemma hasDerivAt_blackV_T {K σ : ℝ} (hK : 0 < K) (hσ : 0 < σ) (r : ℝ) + {F T : ℝ} (hF : 0 < F) (hT : 0 < T) : + HasDerivAt (fun t ↦ blackV K σ r F t) + (-r * blackV K σ r F T + + Real.exp (-(r * T)) * + (σ * F * gaussianPDFReal 0 1 (bsd1 F K 0 σ T) / (2 * Real.sqrt T))) T := by + have h_neg : HasDerivAt (fun t : ℝ ↦ -(r * t)) (-r) T := by + have h := (hasDerivAt_id T).const_mul r + convert h.neg using 1 <;> first | rfl | ring + have h_exp : HasDerivAt (fun t : ℝ ↦ Real.exp (-(r * t))) + (Real.exp (-(r * T)) * (-r)) T := h_neg.exp + have h_bsV := hasDerivAt_bsV_tau (r := 0) hK hσ hF hT + have h := h_exp.mul h_bsV + unfold blackV + convert h using 1 + simp + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/Forwards/FisherSraffaOwnRate.lean b/LeanPool/MathFin/Models/Forwards/FisherSraffaOwnRate.lean new file mode 100644 index 0000000000..119945edac --- /dev/null +++ b/LeanPool/MathFin/Models/Forwards/FisherSraffaOwnRate.lean @@ -0,0 +1,151 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.NoArbitrageDerivations + +/-! +# Fisher/Sraffa own-rate-of-interest identity + +A commodity's **own rate of interest** `b` (Keynes, *General Theory* ch. 17; +Sraffa 1932) is the real return of holding and lending the commodity itself. +Fisher's exact identity relates `b` to the rate of change `i` of the commodity's +money price (the inflation rate, for the composite consumption good) and the +resulting **money (nominal) rate** `r`: + + `1 + r = (1 + b)(1 + i)`, + +and **Sraffa's implied own rate** is defined from a spot price `S`, forward +price `F`, financing rate `m` and maturity `T` as + + `b = ((1 + m)^T · S / F)^{1/T} − 1`; + +`sraffaOwnRate_spec` shows that this `b` solves the cost-of-carry equation +`(1 + b)^T = (1 + m)^T · S / F`. Conversely, `sraffaOwnRate_eq_of_no_arbitrage` derives +the forward from the library's no-arbitrage forward (`forward_price_from_no_arbitrage`, +`Pricing/NoArbitrageDerivations.lean`) and shows that Sraffa's formula returns the own +rate: in a finite-state market whose discount factor is `(1 + m)^{−T}` and in which a unit of +the commodity lent today returns `(1 + b)^T` units at `T` (priced at the spot `S₀`), the +zero-value forward `F` satisfies `sraffaOwnRate m S₀ F T = b`. + +Expanding the Fisher identity gives the familiar linear approximation +`r ≈ b + i`; its error term is exactly `b · i` — the identity is an exact +equality for real numbers, so the "approximation" enters only when `b · i` +is treated as second-order-small and dropped. + +## Main definitions + +* `fisherMoneyRate`: the money rate `(1 + b)(1 + i) - 1` from an own rate `b` and a price-change + rate `i`. +* `sraffaOwnRate`: Sraffa's implied own rate `((1 + m)^T * S / F)^(1/T) - 1` from the financing + rate `m`, spot `S`, forward `F` and maturity `T`. + +## Main results + +* `fisher_linear_approx_error`: `fisherMoneyRate b i − (b + i) = b * i`, the + exact statement underlying `r ≈ b + i` for small `b, i`. +* `sraffaOwnRate_spec`: `(1 + sraffaOwnRate m S F T)^T = (1+m)^T · S / F` + for `T ≠ 0` and `(1+m)^T · S / F ≥ 0`, the defining equation Sraffa's formula + inverts. +* `sraffaOwnRate_eq_of_no_arbitrage`: Sraffa's formula applied to the no-arbitrage + forward of a commodity with own rate `b` returns `b`. +* `fisherMoneyRate_sraffaOwnRate_one`: over one period, Fisher's identity holds with the + own rate implied by Sraffa's formula and the forward premium `F/S − 1` as the rate of + change of the money price: `fisherMoneyRate (sraffaOwnRate m S F 1) (F/S − 1) = m`. + +## References + +* [J. M. Keynes, *The General Theory of Employment, Interest and Money*][Keynes1936], ch. 17 +* [P. Sraffa, *Dr.~Hayek on money and capital*][Sraffa1932] + +## Tags + +own rate of interest, Fisher equation, Sraffa, Keynes, cost of carry, forward price, MSC 91G30, +JEL E43, JEL Q02 +-/ + +@[expose] public section + +namespace MathFin + +/-! ### Fisher's exact identity -/ + +/-- **Fisher money (nominal) rate**: `r = (1+b)(1+i) − 1`, exactly solving +`1 + r = (1+b)(1+i)` for the nominal rate `r` given a commodity's own rate of +interest `b` and the rate of change `i` of its money price. -/ +noncomputable def fisherMoneyRate (b i : ℝ) : ℝ := (1 + b) * (1 + i) - 1 + +/-- **Linear approximation error**: `r − (b+i) = b·i` exactly. The usual +first-order approximation `r ≈ b + i` drops this cross term, which is +genuinely second-order small when `b, i` are both small. -/ +theorem fisher_linear_approx_error (b i : ℝ) : + fisherMoneyRate b i - (b + i) = b * i := by + unfold fisherMoneyRate; ring + +/-! ### Sraffa's implied own rate -/ + +/-- **Sraffa's implied own rate**: `b = ((1+m)^T · S/F)^{1/T} − 1`, from the +financing rate `m`, spot price `S`, forward price `F` and maturity `T`: the +cost-of-carry relation `F = S·(1+m)^T / (1+b)^T` solved for `b`. -/ +noncomputable def sraffaOwnRate (m S F T : ℝ) : ℝ := + ((1 + m) ^ T * (S / F)) ^ (1 / T) - 1 + +/-- **Sraffa's defining equation**: `(1 + b)^T = (1+m)^T · S/F`, where +`b = sraffaOwnRate m S F T`. Requires `(1+m)^T · S/F ≥ 0` (holds e.g. for +`m ≥ -1`, `S, F > 0`) and `T ≠ 0` so the `1/T`-th root inverts the `T`-th +power. -/ +theorem sraffaOwnRate_spec (m S F T : ℝ) (hT : T ≠ 0) + (hpos : 0 ≤ (1 + m) ^ T * (S / F)) : + (1 + sraffaOwnRate m S F T) ^ T = (1 + m) ^ T * (S / F) := by + unfold sraffaOwnRate + have h1 : 1 + (((1 + m) ^ T * (S / F)) ^ (1 / T) - 1) + = ((1 + m) ^ T * (S / F)) ^ (1 / T) := by ring + rw [h1, ← Real.rpow_mul hpos, one_div, inv_mul_cancel₀ hT, Real.rpow_one] + +/-! ### Sraffa's own rate from the no-arbitrage forward -/ + +/-- **Sraffa's formula returns the own rate of the no-arbitrage forward.** In a finite-state +market with state prices `q`, discount factor `∑ q = (1 + m)^{−T}` (money rate `m`), and a +commodity whose loan in kind earns the own rate `b` — the claim on `(1 + b)^T` units at `T` +is priced at the spot `S₀`, `∑ q·(1 + b)^T·S_T = S₀` — the forward with zero value at strike +`F` (`∑ q·(S_T − F) = 0`) satisfies `sraffaOwnRate m S₀ F T = b`. The forward is the +library's `forward_price_from_no_arbitrage` applied to the in-kind claim: +`(1 + b)^T · F = S₀ · (1 + m)^T`. -/ +theorem sraffaOwnRate_eq_of_no_arbitrage {ι : Type*} (s : Finset ι) (q S : ι → ℝ) + (m b S₀ F T : ℝ) (hm : 0 < 1 + m) (hb : 0 < 1 + b) (hT : T ≠ 0) (hS₀ : 0 < S₀) + (h_bond : ∑ i ∈ s, q i = (1 + m) ^ (-T)) + (h_own : ∑ i ∈ s, q i * ((1 + b) ^ T * S i) = S₀) + (h_fwd : ∑ i ∈ s, q i * (S i - F) = 0) : + sraffaOwnRate m S₀ F T = b := by + have h0 : ∑ i ∈ s, q i * ((1 + b) ^ T * S i - (1 + b) ^ T * F) = 0 := by + rw [← mul_zero ((1 + b) ^ T), ← h_fwd, Finset.mul_sum] + exact Finset.sum_congr rfl fun i _ ↦ by ring + have hF' := (forward_price_from_no_arbitrage s q (fun i ↦ (1 + b) ^ T * S i) + ((1 + m) ^ (-T)) S₀ ((1 + b) ^ T * F) (Real.rpow_pos_of_pos hm _).ne' h_bond h_own).mp h0 + rw [Real.rpow_neg hm.le, div_inv_eq_mul] at hF' + have hF0 : F ≠ 0 := by + rintro rfl + rw [mul_zero] at hF' + exact (mul_pos hS₀ (Real.rpow_pos_of_pos hm T)).ne' hF'.symm + have key : (1 + m) ^ T * (S₀ / F) = (1 + b) ^ T := by + rw [mul_div_assoc', div_eq_iff hF0] + linear_combination -1 * hF' + rw [sraffaOwnRate, key, ← Real.rpow_mul hb.le, mul_one_div_cancel hT, Real.rpow_one, + add_sub_cancel_left] + +/-- **Fisher's identity at Sraffa's own rate.** Over one period, the money rate `m` +decomposes by Fisher's identity into the own rate implied by Sraffa's formula and the +forward premium `F/S − 1` (the rate of change of the commodity's money price read off the +forward): `fisherMoneyRate (sraffaOwnRate m S F 1) (F/S − 1) = m`, for `S, F ≠ 0`. -/ +theorem fisherMoneyRate_sraffaOwnRate_one (m S F : ℝ) (hS : S ≠ 0) (hF : F ≠ 0) : + fisherMoneyRate (sraffaOwnRate m S F 1) (F / S - 1) = m := by + have h : (1 + m) * (S / F) * (F / S) = 1 + m := by field_simp + simp only [fisherMoneyRate, sraffaOwnRate, Real.rpow_one, div_one] + linear_combination h + +end MathFin diff --git a/LeanPool/MathFin/Models/Forwards/FxForwardParity.lean b/LeanPool/MathFin/Models/Forwards/FxForwardParity.lean new file mode 100644 index 0000000000..9092f076a1 --- /dev/null +++ b/LeanPool/MathFin/Models/Forwards/FxForwardParity.lean @@ -0,0 +1,130 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Forward +public import LeanPool.MathFin.Pricing.NoArbitrageDerivations + +/-! +# FX forward: covered and uncovered interest parity + +**Covered interest parity (CIP)**: with continuously-compounded domestic and +foreign rates `r_d`, `r_f` and spot `S` (domestic per unit of foreign), the +no-arbitrage forward rate for maturity `T` is + + `F(0, T) = S · exp((r_d - r_f) · T)`. + +It is derived from `forward_price_from_no_arbitrage`: in a finite-state market +the forward contract paying `S_T - F` is priced by the same state prices as the +domestic zero-coupon bond (price `e^{-r_d T}`) and the foreign zero-coupon bond +held in domestic currency (price `S·e^{-r_f T}`: buy `e^{-r_f T}` units of +foreign currency at spot and invest them at `r_f`), and it is worth zero +exactly at `F = S·e^{-r_f T}/e^{-r_d T}` (`covered_interest_parity`). The +one-period discrete form is `F = S·(1 + r_d)/(1 + r_f)`. + +**Uncovered interest parity**, in its risk-neutral form: under the domestic +risk-neutral measure of the Garman–Kohlhagen model (the lognormal hypothesis +`BSCallHyp` with drift `r_d - r_f`, as in `bs_dividends_call_formula` at `q = r_f`), +the expected terminal spot is the same `S·e^{(r_d - r_f)T}` +(`uncovered_interest_parity`, from `expected_terminal_eq_forward`). This is a +statement about the pricing measure; the economists' UIP, the same equation +under the physical measure, is an empirical hypothesis and is not claimed +here. The two parities agree (`covered_eq_uncovered_interest_parity`): the +forward a static market prices to zero is the model's expected spot. + +## Main definitions + +* `fxForward`: the covered-interest-parity FX forward rate `F(0, T) = S · exp((r_d - r_f) · T)` + with continuous compounding. + +## Main results + +* `covered_interest_parity`: the zero-value forward is `fxForward`, derived + from `forward_price_from_no_arbitrage`; + `covered_interest_parity_discrete`: the one-period form + `S·(1 + r_d)/(1 + r_f)`. +* `uncovered_interest_parity`: `E_Q[S_T] = fxForward` under the + Garman–Kohlhagen risk-neutral hypothesis. +* `covered_eq_uncovered_interest_parity`: the CIP forward equals the + risk-neutral expected spot. + +## References + +* [Garman and Kohlhagen, *Foreign currency option values*][GarmanKohlhagen1983] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull] + +## Tags + +covered interest parity, uncovered interest parity, FX forward, Garman–Kohlhagen, foreign exchange, +interest rate differential, MSC 91G20, JEL F31, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory + +/-- Covered-interest-parity FX forward rate for maturity `T`, continuous +compounding: `F(0, T) = S · exp((r_d - r_f) · T)`. -/ +noncomputable def fxForward (S r_d r_f T : ℝ) : ℝ := S * Real.exp ((r_d - r_f) * T) + +/-- **Covered interest parity from no-arbitrage.** A finite-state market with +state prices `q` and terminal spot `S_T`, pricing the domestic zero-coupon bond +at `e^{-r_d T}` and the foreign zero-coupon bond, held in domestic currency, at +`S·e^{-r_f T}`. The forward contract paying `S_T - F` is worth zero iff +`F = S·e^{(r_d - r_f)T}`: `forward_price_from_no_arbitrage` with the foreign +bond as the asset. -/ +theorem covered_interest_parity {ι : Type*} (s : Finset ι) (q S_T : ι → ℝ) + (S r_d r_f T F : ℝ) + (h_dom : ∑ i ∈ s, q i = Real.exp (-(r_d * T))) + (h_for : ∑ i ∈ s, q i * S_T i = S * Real.exp (-(r_f * T))) : + ∑ i ∈ s, q i * (S_T i - F) = 0 ↔ F = fxForward S r_d r_f T := by + refine (forward_price_from_no_arbitrage s q S_T _ _ F (Real.exp_pos _).ne' h_dom h_for).trans ?_ + rw [fxForward, mul_div_assoc, ← Real.exp_sub, neg_sub_neg, ← sub_mul] + +/-- **Covered interest parity, one period, discrete compounding**: with the +domestic bond priced at `1/(1 + r_d)` (`1 + r_d ≠ 0`) and the foreign bond, in +domestic currency, at `S/(1 + r_f)`, the zero-value forward is +`S·(1 + r_d)/(1 + r_f)`. The foreign bond price `S/(1 + r_f)` is a price only for +`1 + r_f > 0`; the identity holds for every `r_f`. -/ +theorem covered_interest_parity_discrete {ι : Type*} (s : Finset ι) (q S_T : ι → ℝ) + (S r_d r_f F : ℝ) (hd : 1 + r_d ≠ 0) + (h_dom : ∑ i ∈ s, q i = 1 / (1 + r_d)) + (h_for : ∑ i ∈ s, q i * S_T i = S / (1 + r_f)) : + ∑ i ∈ s, q i * (S_T i - F) = 0 ↔ F = S * (1 + r_d) / (1 + r_f) := by + refine (forward_price_from_no_arbitrage s q S_T _ _ F (one_div_ne_zero hd) h_dom h_for).trans ?_ + rw [div_div_eq_mul_div, div_one, div_mul_eq_mul_div] + +/-- **Uncovered interest parity, risk-neutral form.** Under the Garman–Kohlhagen +hypothesis (lognormal terminal spot with domestic risk-neutral drift +`r_d - r_f`), the expected terminal spot is the CIP forward: +`E_Q[S_T] = S·e^{(r_d - r_f)T}`. This is `expected_terminal_eq_forward` at the +drift `r_d - r_f`; it is a statement about the pricing measure `Q`, not about +the physical one. -/ +theorem uncovered_interest_parity {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] {S K r_d r_f σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S K (r_d - r_f) σ T Z) : + ∫ ω, bsTerminal S (r_d - r_f) σ T (Z ω) ∂Q = fxForward S r_d r_f T := + expected_terminal_eq_forward h + +/-- **Covered and uncovered parity agree.** The forward that a finite-state +market prices to zero (`covered_interest_parity`) is the expected terminal spot +under the Garman–Kohlhagen risk-neutral measure with the same spot and rates +(`uncovered_interest_parity`). -/ +theorem covered_eq_uncovered_interest_parity {ι : Type*} (s : Finset ι) (q S_T : ι → ℝ) + {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} [IsProbabilityMeasure Q] + {S K r_d r_f σ T F : ℝ} {Z : Ω → ℝ} + (h_dom : ∑ i ∈ s, q i = Real.exp (-(r_d * T))) + (h_for : ∑ i ∈ s, q i * S_T i = S * Real.exp (-(r_f * T))) + (hF : ∑ i ∈ s, q i * (S_T i - F) = 0) (h : BSCallHyp Q S K (r_d - r_f) σ T Z) : + F = ∫ ω, bsTerminal S (r_d - r_f) σ T (Z ω) ∂Q := + ((covered_interest_parity s q S_T S r_d r_f T F h_dom h_for).mp hF).trans + (uncovered_interest_parity h).symm + +end MathFin diff --git a/LeanPool/MathFin/Models/Forwards/SchwartzOneFactor.lean b/LeanPool/MathFin/Models/Forwards/SchwartzOneFactor.lean new file mode 100644 index 0000000000..b30fb363d5 --- /dev/null +++ b/LeanPool/MathFin/Models/Forwards/SchwartzOneFactor.lean @@ -0,0 +1,114 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.VasicekSDEGaussian + +/-! +# Schwartz one-factor commodity futures + +In the Schwartz (1997) one-factor model the log spot price of a commodity is +mean-reverting under the pricing measure: + + `d ln S_t = κ(θ − ln S_t) dt + σ dB_t`. + +This is the Ornstein–Uhlenbeck dynamics of the Vasicek short rate, so, carrying +`ln S_T` in its Wiener representation (the SDE bridge is cited, not proven — see +`schwartzFuturesPrice_eq_integral`), it has the Gaussian law `N(m_T, v_T)` with +`m_T = vasicekSDEMean` and `v_T = vasicekSDEVariance` (`vasicekShortRate_hasLaw_gaussian`), +for `κ > 0`. The futures +price is `F(0,T) = E[S_T] = E[e^{ln S_T}]`, the Gaussian moment-generating +function at `1`: + + `F(0,T) = exp(m_T + v_T / 2)`. + +In the Lean, `E` is the expectation under an arbitrary probability measure `μ` carrying the +Brownian motion: `μ` is *read* as the pricing measure, and that the futures price is +`E^Q[S_T]` is the textbook identification, not proved here. `schwartzFuturesPrice` is the +closed form, defined; `schwartzFuturesPrice_eq_integral` proves it equals `E[S_T]`. + +As `T → ∞` (for `κ > 0`) the closed form flattens to `exp(θ + σ² / (4κ))`, independent of +the current spot. + +This formalizes only the constant-parameter Schwartz (1997) model; Hull's +time-dependent level `q(t)` (the Hull–White-form drift calibrated to the +quoted futures curve) is out of scope. + +## Main definitions + +* `schwartzFuturesPrice`: the Schwartz one-factor futures price, defined as the closed form + `exp(m_T + v_T / 2)` from the initial log spot `x₀`, long-run log level `θ`, speed `κ`, + volatility `σ` and maturity `T`. + +## Main results + +* `schwartzFuturesPrice_eq_integral` — it equals `E[S_T]` for the log spot in its + Wiener representation (the SDE bridge is cited, not proven). +* `tendsto_schwartzFuturesPrice_atTop` — for `κ > 0`, the long-maturity flattening limit + `exp(θ + σ²/(4κ))`. + +## References + +* [E. S. Schwartz, *The Stochastic Behavior of Commodity Prices: Implications for Valuation + and Hedging*][Schwartz1997]. +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull] (the time-dependent `q(t)` + extension). + +## Tags + +Schwartz model, commodity futures, mean-reverting spot, Ornstein-Uhlenbeck, convenience yield, +futures curve, MSC 91G20, MSC 60J60, JEL Q02 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real Filter Topology +open scoped NNReal +open WienerIntegralL2 + +/-- **Schwartz one-factor futures price** with initial log spot `x₀`, long-run +log level `θ`, mean-reversion speed `κ`, volatility `σ` and maturity `T`, defined as the +closed form `exp(m_T + v_T / 2)`; `schwartzFuturesPrice_eq_integral` proves it is the mean +`E[S_T]` of the terminal spot (for `κ > 0`, the log spot in its Wiener representation). -/ +noncomputable def schwartzFuturesPrice (x₀ θ κ σ T : ℝ) : ℝ := + Real.exp (vasicekSDEMean x₀ θ κ T + vasicekSDEVariance σ κ T / 2) + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-- **Schwartz futures price = expected terminal spot.** With the log spot +carried in its Wiener representation `ln S_T = m_T + σ ∫₀ᵀ e^{−κ(T−s)} dB_s` +(the OU solution representation of `vasicekShortRate_hasLaw_gaussian` — the +modelling bridge from the SDE is cited, not proven here) and `κ > 0`, `E[S_T] = +schwartzFuturesPrice`, the expectation taken under the given probability measure `μ`. -/ +theorem schwartzFuturesPrice_eq_integral (hB : IsPreBrownianReal B μ) + (x₀ θ σ : ℝ) {κ : ℝ} (hκ : 0 < κ) (T : ℝ≥0) : + ∫ ω, Real.exp (vasicekSDEMean x₀ θ κ (T : ℝ) + + σ * (wienerIntegralLp B hB T (vasicekKernelLp κ hκ.le T) ω)) ∂μ + = schwartzFuturesPrice x₀ θ κ σ T := by + have h := mgf_gaussianReal (vasicekShortRate_hasLaw_gaussian hB x₀ θ σ hκ T) 1 + simp only [mgf, one_mul, mul_one, one_pow] at h + rw [h, schwartzFuturesPrice, Real.coe_toNNReal _ (vasicekSDEVariance_nonneg σ hκ T.coe_nonneg)] + +/-- **Long-maturity flattening**: as `T → ∞` the Schwartz futures price tends +to `exp(θ + σ² / (4κ))`, independent of the initial spot. -/ +theorem tendsto_schwartzFuturesPrice_atTop (x₀ θ σ : ℝ) {κ : ℝ} (hκ : 0 < κ) : + Tendsto (schwartzFuturesPrice x₀ θ κ σ) atTop + (𝓝 (Real.exp (θ + σ ^ 2 / (4 * κ)))) := by + have hm : Tendsto (fun t ↦ vasicekSDEMean x₀ θ κ t) atTop (𝓝 θ) := + (vasicekDeterministic_tendsto_mean x₀ θ κ hκ).congr fun t ↦ + (vasicekSDEMean_eq_deterministic x₀ θ κ t).symm + have hv := tendsto_vasicekSDEVariance_atTop σ hκ + have hlim : θ + σ ^ 2 / (2 * κ) / 2 = θ + σ ^ 2 / (4 * κ) := by ring + rw [← hlim] + exact Real.continuous_exp.tendsto _ |>.comp (hm.add (hv.div_const 2)) + +end MathFin diff --git a/LeanPool/MathFin/Models/Forwards/TheoryOfStorage.lean b/LeanPool/MathFin/Models/Forwards/TheoryOfStorage.lean new file mode 100644 index 0000000000..eeb2970d0b --- /dev/null +++ b/LeanPool/MathFin/Models/Forwards/TheoryOfStorage.lean @@ -0,0 +1,195 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.NoArbitrageDerivations + +/-! +# Theory of storage: convenience yield and the canonical-storage price kink + +The **theory of storage** (Kaldor 1939, Working 1949) models the commodity spot +price as a kinked function of "availability" `A` (current stock plus expected +supply). For availability below the kink point `A*` (scarcity) the price tracks +the inverse demand-for-storage curve `f⁻¹(A)`, which falls as availability +rises; at and above `A*` storage is profitable and the market sits at the +investment-regime price floor `Sbar = E[S_{t+1}] − C`: + + `S(A) = max(Sbar, f⁻¹(A))` (canonical-storage price) + `Y(A) = max(f⁻¹(A) − Sbar, 0)` (convenience yield) + +By definition the convenience yield is positive exactly where `f⁻¹(A) > Sbar` +and zero elsewhere; for a decreasing `f⁻¹` that is where scarcity bites, below +the kink. The definitions here take any `f⁻¹ : ℝ → ℝ`: no monotonicity of `f⁻¹` +is assumed, and nothing is proved about `A` below or above `A*`. The two +functions are two faces of the same kink: `Y(A) = S(A) − Sbar` always. + +The forward is derived, not posited, from the library's no-arbitrage forward +(`forward_price_from_no_arbitrage`, `Pricing/NoArbitrageDerivations.lean`). In a +finite-state market with state prices `q` and discount factor `DF = ∑ q`, suppose holding one +unit of the stored commodity to the delivery date is priced at the spot `S₀`: it delivers +the commodity `S_T`, the convenience yield `Y`, and costs the storage `C`, both `Y` and `C` +deterministic and paid at delivery (`∑ q·(S_T − C + Y) = S₀`). Then the forward strike +with zero value is `F = S₀/DF + C − Y` (`storageForward_from_no_arbitrage`). With zero rates +(`DF = 1`), spot `S₀ = S(A)` and `Y = Y(A)`, this gives `F = Sbar + C` at every availability +(`storageForward_at_availability`), and the cost-of-carry identity — the spot price `S(A)` +plus the finance/storage cost `C` net of the convenience-yield benefit — is the kink +identity rearranged: + + `F − S(A) = C − Y(A)` + +(convenience yield *reduces* net carry cost — high-yield, near-backwardation +markets have `Y(A)` large relative to `C`. This is the standard sign +convention in the literature: convenience yield is a benefit to the holder +of physical stock, so it subtracts from the holder's net financing cost, +i.e. from `C`). + +For an isoelastic demand-for-storage curve +`f⁻¹(A) = p_ref · (a_ref / A) ^ ε` (flexibility `ε = −d ln p / d ln A`, +reference availability `a_ref`, reference price `p_ref`), a kink point `A*` +with `f⁻¹(A*) = Sbar` is + + `A* = a_ref · (p_ref / Sbar) ^ {1/ε}` + +for `a_ref, p_ref, Sbar > 0` and `ε ≠ 0` (`kinkPoint_spec`); that it is the +only crossing is not stated. + +## Main definitions + +* `storageSpotPrice`: the canonical-storage spot price `max Sbar (invDemand A)` at availability + `A`, for any `invDemand : ℝ → ℝ`. +* `convenienceYield`: `max (invDemand A - Sbar) 0`. +* `invDemandIsoelastic`: the isoelastic inverse demand for storage `p_ref * (a_ref/A)^ε`. +* `kinkPoint`: the availability at which the isoelastic curve meets the floor `Sbar`. + +## Main results + +* `convenienceYield_eq_storageSpotPrice_sub` : `Y(A) = S(A) − Sbar`. +* `carry_identity_at_availability` : `(Sbar + C) − S(A) = C − Y(A)`, the + cost-of-carry identity at the kink functions + (`convenienceYield_eq_storageSpotPrice_sub` rearranged). +* `storageForward_from_no_arbitrage` : in a finite-state market whose stored commodity + is priced with storage cost `C` and convenience yield `Y` paid at delivery, the + zero-value forward strike is `F = S₀/DF + C − Y`. +* `storageForward_at_availability` : with zero rates, spot `S(A)` and convenience + yield `Y(A)`, the zero-value forward strike is `Sbar + C` at every availability `A`. +* `invDemandIsoelastic`, `kinkPoint`, `kinkPoint_spec` : the isoelastic + demand-for-storage curve and a kink point solving `f⁻¹(A*) = Sbar`, for + `a_ref, p_ref, Sbar > 0` and `ε ≠ 0`. + +## References + +* [N. Kaldor, *Speculation and economic stability*][Kaldor1939]. +* [H. Working, *The theory of price of storage*][Working1949]. +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], ch. 5 + +## Tags + +theory of storage, convenience yield, Kaldor–Working, cost of carry, backwardation, +commodity forward, MSC 91G20, JEL Q02, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +/-! ### Canonical-storage spot price and convenience yield -/ + +/-- **Canonical-storage spot price**: the price sits at the investment-regime +floor `Sbar` when the inverse demand-for-storage curve `f⁻¹` would call for +less, else tracks it. -/ +noncomputable def storageSpotPrice (Sbar : ℝ) (invDemand : ℝ → ℝ) (A : ℝ) : ℝ := + max Sbar (invDemand A) + +/-- **Convenience yield**: positive exactly where scarcity pushes the +demand-for-storage price above the investment-regime floor (`f⁻¹(A) > Sbar`), +zero where it does not. -/ +noncomputable def convenienceYield (Sbar : ℝ) (invDemand : ℝ → ℝ) (A : ℝ) : ℝ := + max (invDemand A - Sbar) 0 + +/-- The convenience yield is exactly how far the canonical-storage price sits +above the floor `Sbar` — the two kinks are one and the same. -/ +theorem convenienceYield_eq_storageSpotPrice_sub (Sbar : ℝ) (invDemand : ℝ → ℝ) (A : ℝ) : + convenienceYield Sbar invDemand A = storageSpotPrice Sbar invDemand A - Sbar := by + unfold convenienceYield storageSpotPrice + rw [max_comm Sbar (invDemand A), ← max_sub_sub_right, sub_self] + +/-! ### Cost-of-carry identity -/ + +/-- **Carry identity at a given availability**: at the forward `F = Sbar + C` (cost of +carry off the investment-regime floor; derived from no-arbitrage in +`storageForward_at_availability`), the carry spread against the canonical-storage spot +price is exactly `C − Y(A)` — convenience yield subtracts from the carry cost `C`, the +standard theory-of-storage sign convention (convenience yield is a benefit to the holder of +physical stock). The identity is `convenienceYield_eq_storageSpotPrice_sub` rearranged. -/ +theorem carry_identity_at_availability (Sbar C : ℝ) (invDemand : ℝ → ℝ) (A : ℝ) : + (Sbar + C) - storageSpotPrice Sbar invDemand A = C - convenienceYield Sbar invDemand A := by + rw [convenienceYield_eq_storageSpotPrice_sub]; ring + +/-! ### The forward from no-arbitrage -/ + +/-- **Cost of carry with storage cost and convenience yield, from no-arbitrage.** In a +finite-state market with state prices `q`, discount factor `∑ q = DF ≠ 0`, terminal commodity +prices `S`, and the stored commodity priced at the spot `S₀` as the claim on +`S_T − C + Y` (the commodity, less the storage cost `C`, plus the convenience yield `Y`, both +deterministic and paid at delivery), the forward with strike `F` has zero value exactly when +`F = S₀/DF + C − Y`. The library's forward `forward_price_from_no_arbitrage` applied to the +stored-commodity claim, shifted by the deterministic carry `Y − C`. -/ +theorem storageForward_from_no_arbitrage {ι : Type*} (s : Finset ι) (q S : ι → ℝ) + (DF S₀ C Y F : ℝ) (hDF : DF ≠ 0) (h_bond : ∑ i ∈ s, q i = DF) + (h_carry : ∑ i ∈ s, q i * (S i - C + Y) = S₀) : + (∑ i ∈ s, q i * (S i - F) = 0) ↔ F = S₀ / DF + C - Y := by + have hsum : ∑ i ∈ s, q i * (S i - F) = ∑ i ∈ s, q i * ((S i - C + Y) - (F - C + Y)) := + Finset.sum_congr rfl fun i _ ↦ by ring + rw [hsum] + refine (forward_price_from_no_arbitrage s q (fun i ↦ S i - C + Y) DF S₀ (F - C + Y) hDF + h_bond h_carry).trans ?_ + constructor <;> intro h <;> linarith + +/-- **The forward does not see availability.** With zero rates (`∑ q = 1`), the spot at the +canonical-storage price `S(A)` and the convenience yield `Y(A)` of the same kink, the +zero-value forward strike is `Sbar + C` at every availability `A`: the convenience yield +offsets exactly the scarcity premium of the spot over the floor. This derives the forward +`F = Sbar + C` at which `carry_identity_at_availability` is stated. -/ +theorem storageForward_at_availability {ι : Type*} (s : Finset ι) (q S : ι → ℝ) + (Sbar C F : ℝ) (invDemand : ℝ → ℝ) (A : ℝ) (h_bond : ∑ i ∈ s, q i = 1) + (h_carry : ∑ i ∈ s, q i * (S i - C + convenienceYield Sbar invDemand A) + = storageSpotPrice Sbar invDemand A) : + (∑ i ∈ s, q i * (S i - F) = 0) ↔ F = Sbar + C := by + rw [storageForward_from_no_arbitrage s q S 1 _ C _ F one_ne_zero h_bond h_carry, + convenienceYield_eq_storageSpotPrice_sub, div_one] + constructor <;> intro h <;> linarith + +/-! ### Isoelastic demand for storage and its kink point -/ + +/-- **Isoelastic inverse demand for storage**: `f⁻¹(A) = p_ref · (a_ref/A)^ε`, +flexibility `ε = −d ln p / d ln A` against reference availability `a_ref` and +price `p_ref`. -/ +noncomputable def invDemandIsoelastic (a_ref p_ref ε A : ℝ) : ℝ := + p_ref * (a_ref / A) ^ ε + +/-- **Kink point**: the availability `A*` at which the isoelastic +demand-for-storage curve meets the investment-regime floor `Sbar`. -/ +noncomputable def kinkPoint (a_ref p_ref Sbar ε : ℝ) : ℝ := + a_ref * (p_ref / Sbar) ^ (1 / ε) + +/-- **Kink-point equation**: `f⁻¹(A*) = Sbar`, i.e. the isoelastic +demand-for-storage curve meets the floor at `kinkPoint` (uniqueness of the +crossing is not stated). -/ +theorem kinkPoint_spec (a_ref p_ref Sbar ε : ℝ) + (ha : 0 < a_ref) (hp : 0 < p_ref) (hS : 0 < Sbar) (hε : ε ≠ 0) : + invDemandIsoelastic a_ref p_ref ε (kinkPoint a_ref p_ref Sbar ε) = Sbar := by + unfold invDemandIsoelastic kinkPoint + have hx : (0:ℝ) ≤ p_ref / Sbar := le_of_lt (div_pos hp hS) + have step1 : a_ref / (a_ref * (p_ref / Sbar) ^ (1 / ε)) = (Sbar / p_ref) ^ (1 / ε) := by + rw [div_mul_eq_div_div, div_self (ne_of_gt ha), one_div, ← Real.inv_rpow hx, inv_div] + have step2 : ((Sbar / p_ref) ^ (1 / ε)) ^ ε = Sbar / p_ref := by + rw [← Real.rpow_mul (le_of_lt (div_pos hS hp)), one_div, inv_mul_cancel₀ hε, Real.rpow_one] + rw [step1, step2] + field_simp + +end MathFin diff --git a/LeanPool/MathFin/Models/Jumps/JumpDiffusionCanonical.lean b/LeanPool/MathFin/Models/Jumps/JumpDiffusionCanonical.lean new file mode 100644 index 0000000000..c7a876c2fd --- /dev/null +++ b/LeanPool/MathFin/Models/Jumps/JumpDiffusionCanonical.lean @@ -0,0 +1,184 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionMixing +public import Mathlib.Probability.Independence.InfinitePi + +/-! +# The canonical jump-diffusion model + +`JumpDiffusionHyp` lists what the jump-diffusion results assume of a probability space: a +standard normal diffusion sample `Z`, a jump count `N ∼ Poisson(Λ)` and i.i.d. log-jump sizes +`Jᵢ`, with the count independent of the diffusion sample and the sizes, and the diffusion sample +independent of the sizes. Here `Λ` is the expected number of jumps to maturity (`λT` for a jump +rate `λ`). This file shows that the assumptions can be met for every `Λ` and every jump law `ν`: +on `ℝ × ℕ × (ℕ → ℝ)` with the product of `N(0, 1)`, `Poisson(Λ)` and the infinite product `ν^ℕ` +(`jumpDiffusionMeasure`), the coordinates satisfy them (`jumpDiffusionHyp_canonical`). So the +`JumpDiffusionHyp` theorems are not vacuous; their remaining hypotheses on the model are +conditions on `Λ` and `ν`, such as `∫ eˣ dν < ∞` (`integrable_exp_canonical_jump`). With Gaussian +jumps the same model is Merton's (`JumpDiffusionHyp.call_eq_mertonCallPrice`). + +It also shows that the call depends on the model only through `Λ` and the law of the jumps. On +any probability space satisfying `JumpDiffusionHyp`, the jump sizes are i.i.d., so their sequence +has law `ν^ℕ`, with `ν` the law of `J₀`, and for `𝔼[e^{J₀}] < ∞` and `S₀, K, σ, T > 0` the call +is + + `∫ n, ∫ x, C_BS(S₀e^{−κ + ∑_{i 0`) the +law therefore has a density, the mixture of the normal densities (`jumpDiffusionDensity`). For +lognormal jumps this is the Poisson mixture of normal densities of Merton (1976), which the library +states in price form (`jumpDiffusionDensity_gaussian_div_eq_mertonTerminalPDF`; the log-return form +`f(y) = ∑ₙ wₙ φ(y; bτ + n(log(1 + k) − δ²/2), σ²τ + nδ²)` is not stated). Here the jump law is +arbitrary and needs no moment condition. + +* `jumpDiffusionIncrementLaw_eq_withDensity`: the law is `f(y) dy` (Tonelli). +* `continuous_jumpDiffusionDensity`: `f` is continuous, by dominated convergence, since a normal + density is at most `1/√(2πv)` (`gaussianPDFReal_le_inv_sqrt`). +* `nullSingletonClass_jumpDiffusionIncrementLaw`: so the law has no atoms (Mathlib's + `nullSingletonClass_withDensity`). +* `jumpDiffusionDensity_pos`: `f` is positive, and so the price charges every interval of + positive strikes (`jumpDiffusionIncrementLaw_price_mem_Ioo_ne_zero`), for any jump law. +* `ofReal_exp_le_jumpDiffusionIncrementLaw_singleton`: without a Gaussian part (`σ = 0`) the law + has an atom at `bτ`, of mass at least `e^{−Λτ}`, the probability of no jump. +* `hasDerivAt_measureReal_Ioi_withDensity`: for any law `f(y) dy` with `f ≥ 0` integrable, the tail + `x ↦ P(Y > x)` has derivative `−f(a)` at every `a` where `f` is continuous. +* `map_mul_exp_withDensity`: for any law `f(y) dy` and `S > 0`, the price `Seʸ` has on `(0, ∞)` the + density `K ↦ f(log(K/S))/K` (change of variables `K = Seʸ`, `dK = K dy`), and + `jumpDiffusionIncrementLaw_map_mul_exp` is the jump-diffusion case. A density obtained this way + integrates to one, the mass of a probability law (`lintegral_eq_one_of_map_eq_withDensity`). + +The option prices built on these facts are in `Models/Jumps/JumpDiffusionDigital.lean`: the strike +derivatives of the call and the digital, and Breeden–Litzenberger with jumps. + +## Main definitions + +* `jumpDiffusionDensity`: the density of the jump-diffusion log-return over `τ`, the mixture of + the normal densities `φ(y; bτ + ∑_{i 0` the law is + `jumpDiffusionDensity y dy`. +* `continuous_jumpDiffusionDensity`, `jumpDiffusionDensity_pos`: the density is continuous, and + positive when `σ ≠ 0` and `τ > 0`, for any jump law. +* `nullSingletonClass_jumpDiffusionIncrementLaw`: for `σ ≠ 0` and `τ > 0` the law has no atoms. +* `ofReal_exp_le_jumpDiffusionIncrementLaw_singleton`: at `σ = 0` the law has an atom at `bτ` of + mass at least `e^{−Λτ}`. +* `hasDerivAt_measureReal_Ioi_withDensity`: for a law `f(y) dy` with `f ≥ 0` integrable and + continuous at `a`, the tail `x ↦ P(Y > x)` has derivative `−f(a)` at `a`. +* `map_mul_exp_withDensity`: if `Y` has law `f(y) dy` and `S > 0`, then `S eʸ` has density + `f(log(K/S))/K` on `(0, ∞)`. +* `jumpDiffusionIncrementLaw_map_mul_exp`, `jumpDiffusionIncrementLaw_price_mem_Ioo_ne_zero`: + for `σ ≠ 0`, `τ > 0` and `S > 0`, the price `S eʸ` has density `f(log(K/S))/K` on `(0, ∞)`, + and charges every interval `(k₁, k₂)` with `0 ≤ k₁ < k₂`. + +## References + +* [Breeden and Litzenberger, *Prices of state-contingent claims implicit in option + prices*][BreedenLitzenberger1978] +* [Cont and Tankov, *Financial Modelling with Jump Processes*][ContTankov2004] +* [R. C. Merton, *Option pricing when underlying stock returns are discontinuous*][Merton1976] + +## Tags + +density of log-return, Gaussian mixture, Poisson mixture, jump-diffusion, Lévy process density, +MSC 60G51, MSC 91G20, MSC 60E05 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real Filter Set +open scoped NNReal ENNReal Topology + +/-- A Gaussian density is at most `1/√(2πv)`. -/ +lemma gaussianPDFReal_le_inv_sqrt (μ : ℝ) (v : ℝ≥0) (x : ℝ) : + gaussianPDFReal μ v x ≤ (√(2 * π * v))⁻¹ := by + rw [gaussianPDFReal] + refine mul_le_of_le_one_right (inv_nonneg.2 (Real.sqrt_nonneg _)) (Real.exp_le_one_iff.2 ?_) + rw [neg_div] + exact neg_nonpos.2 (by positivity) + +/-- **The density of the jump-diffusion log-return** over `τ`: the mixture, over the jump count `n` +and the jump sizes `j` (law `Poisson(Λτ) ⊗ ν^ℕ`), of the Gaussian densities +`φ(y; bτ + ∑_{i 0` it is the density of the log-return law +(`jumpDiffusionIncrementLaw_eq_withDensity`). -/ +noncomputable def jumpDiffusionDensity (b σ : ℝ) (Λ : ℝ≥0) (ν : Measure ℝ) (τ : ℝ≥0) (y : ℝ) : + ℝ := + ∫ ω, gaussianPDFReal (b * τ + ∑ i ∈ Finset.range ω.1, ω.2 i) (.mk (σ ^ 2) (sq_nonneg _) * τ) y + ∂((poissonMeasure (Λ * τ)).prod (Measure.infinitePi fun _ : ℕ ↦ ν)) + +lemma jumpDiffusionDensity_nonneg (b σ : ℝ) (Λ : ℝ≥0) (ν : Measure ℝ) (τ : ℝ≥0) (y : ℝ) : + 0 ≤ jumpDiffusionDensity b σ Λ ν τ y := + integral_nonneg fun _ ↦ gaussianPDFReal_nonneg _ _ _ + +/-- The mixed Gaussian densities are measurable in the jumps. -/ +lemma measurable_gaussianPDFReal_jumps (b : ℝ) (v : ℝ≥0) (τ : ℝ≥0) (y : ℝ) : + Measurable fun ω : ℕ × (ℕ → ℝ) ↦ + gaussianPDFReal (b * τ + ∑ i ∈ Finset.range ω.1, ω.2 i) v y := + measurable_uncurry_gaussianPDFReal.comp + ((measurable_const.add measurable_sum_range_prod).prodMk + (measurable_const.prodMk measurable_const)) + +/-- **The log-return law is a mixture of Gaussian laws**: given the jump count `n` and the jump +sizes `j`, the log-return is `N(bτ + ∑_{i 0`) the conditional variance `σ²τ` of the log-return given +the jumps is nonzero. -/ +lemma jumpDiffusionVariance_ne_zero {σ : ℝ} (hσ : σ ≠ 0) {τ : ℝ≥0} (hτ : 0 < τ) : + (.mk (σ ^ 2) (sq_nonneg _) * τ : ℝ≥0) ≠ 0 := + mul_ne_zero (NNReal.coe_ne_zero.1 (pow_ne_zero 2 hσ)) hτ.ne' + +/-- **The log-return law has the density `f`** when `σ ≠ 0` and `τ > 0`: each Gaussian law of the +mixture is `φ(y) dy`, and the mixture of the densities is the density of the mixture (Tonelli, +Mathlib's `lintegral_lintegral_swap`). -/ +theorem jumpDiffusionIncrementLaw_eq_withDensity (b : ℝ) {σ : ℝ} (hσ : σ ≠ 0) (Λ : ℝ≥0) + (ν : Measure ℝ) [IsProbabilityMeasure ν] {τ : ℝ≥0} (hτ : 0 < τ) : + jumpDiffusionIncrementLaw b σ Λ ν τ + = volume.withDensity fun y ↦ ENNReal.ofReal (jumpDiffusionDensity b σ Λ ν τ y) := by + have hv := jumpDiffusionVariance_ne_zero hσ hτ + ext A hA + have hmeas : AEMeasurable (Function.uncurry fun (ω : ℕ × (ℕ → ℝ)) (x : ℝ) ↦ + gaussianPDF (b * τ + ∑ i ∈ Finset.range ω.1, ω.2 i) (.mk (σ ^ 2) (sq_nonneg _) * τ) x) + (((poissonMeasure (Λ * τ)).prod (Measure.infinitePi fun _ : ℕ ↦ ν)).prod + (volume.restrict A)) := + (measurable_uncurry_gaussianPDF.comp + (((measurable_const.add measurable_sum_range_prod).comp measurable_fst).prodMk + (measurable_const.prodMk measurable_snd))).aemeasurable + rw [jumpDiffusionIncrementLaw_apply b σ Λ ν τ hA, withDensity_apply _ hA] + simp_rw [gaussianReal_apply _ hv A] + rw [lintegral_lintegral_swap hmeas] + refine lintegral_congr fun y ↦ ?_ + exact (ofReal_integral_eq_lintegral_ofReal (integrable_gaussianPDFReal_jumps b _ Λ ν τ y) + (ae_of_all _ fun _ ↦ gaussianPDFReal_nonneg _ _ _)).symm + +/-- **The density of the log-return is continuous**: dominated convergence, the Gaussian densities +being continuous in `y` and bounded by `1/√(2πσ²τ)`. -/ +theorem continuous_jumpDiffusionDensity (b σ : ℝ) (Λ : ℝ≥0) (ν : Measure ℝ) + [IsProbabilityMeasure ν] (τ : ℝ≥0) : Continuous (jumpDiffusionDensity b σ Λ ν τ) := + continuous_of_dominated + (bound := fun _ ↦ (√(2 * π * (.mk (σ ^ 2) (sq_nonneg _) * τ : ℝ≥0)))⁻¹) + (fun y ↦ (measurable_gaussianPDFReal_jumps b _ τ y).aestronglyMeasurable) + (fun y ↦ ae_of_all _ fun ω ↦ by + rw [Real.norm_of_nonneg (gaussianPDFReal_nonneg _ _ _)] + exact gaussianPDFReal_le_inv_sqrt _ _ _) + (integrable_const _) (ae_of_all _ fun ω ↦ continuous_gaussianPDFReal _ _) + +/-- **With a Gaussian part the density is positive**: each normal density of the mixture is +(`gaussianPDFReal_pos`), and the mixing law `Poisson(Λτ) ⊗ ν^ℕ` has mass one. -/ +lemma jumpDiffusionDensity_pos (b : ℝ) {σ : ℝ} (hσ : σ ≠ 0) (Λ : ℝ≥0) (ν : Measure ℝ) + [IsProbabilityMeasure ν] {τ : ℝ≥0} (hτ : 0 < τ) (y : ℝ) : + 0 < jumpDiffusionDensity b σ Λ ν τ y := by + refine (integral_pos_iff_support_of_nonneg ?_ (integrable_gaussianPDFReal_jumps b _ Λ ν τ y)).2 ?_ + · exact fun _ ↦ gaussianPDFReal_nonneg _ _ _ + have hsupp : Function.support (fun ω : ℕ × (ℕ → ℝ) ↦ + gaussianPDFReal (b * τ + ∑ i ∈ Finset.range ω.1, ω.2 i) (.mk (σ ^ 2) (sq_nonneg _) * τ) y) + = univ := + eq_univ_of_forall fun ω ↦ (gaussianPDFReal_pos (b * τ + ∑ i ∈ Finset.range ω.1, ω.2 i) _ y + (jumpDiffusionVariance_ne_zero hσ hτ)).ne' + rw [hsupp, measure_univ] + exact zero_lt_one + +/-- **With a Gaussian part the log-return law has no atoms**: it has a density +(`jumpDiffusionIncrementLaw_eq_withDensity`), and Lebesgue measure has none (Mathlib's +`nullSingletonClass_withDensity`). -/ +lemma nullSingletonClass_jumpDiffusionIncrementLaw (b : ℝ) {σ : ℝ} (hσ : σ ≠ 0) (Λ : ℝ≥0) + (ν : Measure ℝ) [IsProbabilityMeasure ν] {τ : ℝ≥0} (hτ : 0 < τ) : + NullSingletonClass (jumpDiffusionIncrementLaw b σ Λ ν τ) := by + rw [jumpDiffusionIncrementLaw_eq_withDensity b hσ Λ ν hτ] + infer_instance + +/-- **Without a Gaussian part the log-return law has an atom at `bτ`**: with `σ = 0` and no jump, +which has probability `e^{−Λτ}`, the log-return is `bτ`. Each Gaussian law of the mixture +(`jumpDiffusionIncrementLaw_apply`) is then a point mass (Mathlib's `gaussianReal_zero_var`), and +the one for the jump count `0` sits at `bτ`. -/ +lemma ofReal_exp_le_jumpDiffusionIncrementLaw_singleton (b : ℝ) (Λ : ℝ≥0) (ν : Measure ℝ) + [IsProbabilityMeasure ν] (τ : ℝ≥0) : + ENNReal.ofReal (rexp (-((Λ * τ : ℝ≥0) : ℝ))) ≤ jumpDiffusionIncrementLaw b 0 Λ ν τ {b * τ} := by + -- with `σ = 0` each Gaussian law of the mixture is a point mass + have hv (m : ℝ) : gaussianReal m (.mk ((0 : ℝ) ^ 2) (sq_nonneg _) * τ) = Measure.dirac m := by + rw [← gaussianReal_zero_var m] + congr 1 + ext + simp + rw [jumpDiffusionIncrementLaw_apply b 0 Λ ν τ (measurableSet_singleton _)] + simp_rw [hv] + calc ENNReal.ofReal (rexp (-((Λ * τ : ℝ≥0) : ℝ))) + = ((poissonMeasure (Λ * τ)).prod (Measure.infinitePi fun _ : ℕ ↦ ν)) ({0} ×ˢ univ) := by + rw [Measure.prod_prod, measure_univ, mul_one, poissonMeasure_singleton] + simp + _ = ∫⁻ ω, ({0} ×ˢ univ : Set (ℕ × (ℕ → ℝ))).indicator 1 ω + ∂((poissonMeasure (Λ * τ)).prod (Measure.infinitePi fun _ : ℕ ↦ ν)) := + (lintegral_indicator_one ((measurableSet_singleton 0).prod MeasurableSet.univ)).symm + _ ≤ _ := lintegral_mono fun ω ↦ ?_ + -- with no jump the point mass sits at `bτ` + by_cases hω : ω.1 = 0 + · have h0 : ω ∈ ({0} ×ˢ univ : Set (ℕ × (ℕ → ℝ))) := by simpa using hω + rw [indicator_of_mem h0, Pi.one_apply, hω, Finset.range_zero, Finset.sum_empty, add_zero] + exact (Measure.dirac_apply_of_mem (mem_singleton _)).symm.le + · have h0 : ω ∉ ({0} ×ˢ univ : Set (ℕ × (ℕ → ℝ))) := by simpa using hω + rw [indicator_of_notMem h0] + exact zero_le + +/-- The density integrates to `1`, so it is integrable. -/ +lemma integrable_jumpDiffusionDensity (b : ℝ) {σ : ℝ} (hσ : σ ≠ 0) (Λ : ℝ≥0) (ν : Measure ℝ) + [IsProbabilityMeasure ν] {τ : ℝ≥0} (hτ : 0 < τ) : + Integrable (jumpDiffusionDensity b σ Λ ν τ) := by + refine ⟨(continuous_jumpDiffusionDensity b σ Λ ν τ).aestronglyMeasurable, ?_⟩ + have h1 : (volume.withDensity fun y ↦ ENNReal.ofReal (jumpDiffusionDensity b σ Λ ν τ y)) + univ = 1 := by + rw [← jumpDiffusionIncrementLaw_eq_withDensity b hσ Λ ν hτ, measure_univ] + rw [withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ] at h1 + rw [hasFiniteIntegral_iff_ofReal (ae_of_all _ (jumpDiffusionDensity_nonneg b σ Λ ν τ)), h1] + exact ENNReal.one_lt_top + +/-- **The tail of a law with a density is differentiable where the density is continuous**: for +the law `f(y) dy`, with `f ≥ 0` integrable and continuous at `a`, `x ↦ P(Y > x)` has derivative +`−f(a)` at `a` (the fundamental theorem of calculus, Mathlib's +`intervalIntegral.integral_hasDerivAt_right`). -/ +theorem hasDerivAt_measureReal_Ioi_withDensity {f : ℝ → ℝ} (hf : Integrable f) + (hf0 : ∀ y, 0 ≤ f y) {a : ℝ} (hfa : ContinuousAt f a) : + HasDerivAt (fun x ↦ (volume.withDensity fun y ↦ ENNReal.ofReal (f y)).real (Ioi x)) + (-f a) a := by + -- the integrals of `f`, stated in the notation of the goal + have h1 (x : ℝ) : (∫ y in Iic x, f y) + ∫ y in Ioi x, f y = ∫ y, f y := by + rw [← compl_Iic] + exact integral_add_compl measurableSet_Iic hf + have h2 (x : ℝ) : (∫ y in Iic x, f y) - ∫ y in Iic a, f y = ∫ y in a..x, f y := + intervalIntegral.integral_Iic_sub_Iic hf.integrableOn hf.integrableOn + have hIoi (x : ℝ) : (volume.withDensity fun y ↦ ENNReal.ofReal (f y)).real (Ioi x) + = ((∫ y, f y) - ∫ y in Iic a, f y) - ∫ y in a..x, f y := by + have h3 : (volume.withDensity fun y ↦ ENNReal.ofReal (f y)).real (Ioi x) + = ∫ y in Ioi x, f y := by + rw [Measure.real, withDensity_apply _ measurableSet_Ioi, + ← ofReal_integral_eq_lintegral_ofReal hf.integrableOn (ae_of_all _ fun y ↦ hf0 y), + ENNReal.toReal_ofReal (setIntegral_nonneg measurableSet_Ioi fun y _ ↦ hf0 y)] + linarith [h1 x, h2 x] + have hii : IntervalIntegrable f volume a a := hf.intervalIntegrable + have hD : HasDerivAt (fun x ↦ ((∫ y, f y) - ∫ y in Iic a, f y) - ∫ y in a..x, f y) (-f a) a := + (intervalIntegral.integral_hasDerivAt_right hii + hf.aestronglyMeasurable.stronglyMeasurableAtFilter hfa).const_sub _ + exact hD.congr_of_eventuallyEq (Eventually.of_forall hIoi) + +/-- **The law of `Seʸ` when `Y` has a density.** If `Y` has the law `f(y) dy` and `S > 0`, the +price `Seʸ` has the law `f(log(K/S))/K dK` on `(0, ∞)`: the change of variables `K = Seʸ`, +`dK = K dy` (Mathlib's `lintegral_image_eq_lintegral_abs_deriv_mul`), `y ↦ Seʸ` being a bijection +of `ℝ` onto `(0, ∞)`. No sign or measurability condition on `f` is needed: `ENNReal.ofReal` reads +negative values as `0` on both sides. -/ +theorem map_mul_exp_withDensity (f : ℝ → ℝ) {S : ℝ} (hS : 0 < S) : + (volume.withDensity fun y ↦ ENNReal.ofReal (f y)).map (fun y ↦ S * rexp y) + = (volume.restrict (Ioi 0)).withDensity + fun K ↦ ENNReal.ofReal (f (Real.log (K / S)) / K) := by + have hg : Measurable fun y ↦ S * rexp y := by fun_prop + ext A hA + rw [Measure.map_apply hg hA, withDensity_apply _ (hg hA), withDensity_apply _ hA, + Measure.restrict_restrict hA] + -- `y ↦ Seʸ` maps the preimage of `A` onto `A ∩ (0, ∞)` + have himage : (fun y ↦ S * rexp y) '' ((fun y ↦ S * rexp y) ⁻¹' A) = A ∩ Ioi 0 := by + rw [image_preimage_eq_inter_range] + congr 1 + ext K + simp only [mem_range, mem_Ioi] + refine ⟨?_, fun hK ↦ ⟨Real.log (K / S), ?_⟩⟩ + · rintro ⟨y, rfl⟩ + positivity + · rw [Real.exp_log (div_pos hK hS), mul_div_cancel₀ _ hS.ne'] + rw [← himage, lintegral_image_eq_lintegral_abs_deriv_mul (hg hA) + (fun y _ ↦ ((Real.hasDerivAt_exp y).const_mul S).hasDerivWithinAt) + (fun y₁ _ y₂ _ h ↦ Real.exp_injective (mul_left_cancel₀ hS.ne' h))] + refine setLIntegral_congr_fun (hg hA) fun y _ ↦ ?_ + have hSy : 0 < S * rexp y := mul_pos hS (Real.exp_pos y) + rw [abs_of_pos hSy, ← ENNReal.ofReal_mul hSy.le, mul_div_cancel_left₀ _ hS.ne', Real.log_exp, + mul_div_cancel₀ _ hSy.ne'] + +/-- **The law of the jump-diffusion price.** With a Gaussian part (`σ ≠ 0`, `τ > 0`) and `S > 0`, +the price `Seʸ` has the law `f(log(K/S))/K dK` on `(0, ∞)`, with `f` the density of the log-return +(`jumpDiffusionIncrementLaw_eq_withDensity`, `map_mul_exp_withDensity`). -/ +theorem jumpDiffusionIncrementLaw_map_mul_exp (b : ℝ) {σ : ℝ} (hσ : σ ≠ 0) (Λ : ℝ≥0) + (ν : Measure ℝ) [IsProbabilityMeasure ν] {τ : ℝ≥0} (hτ : 0 < τ) {S : ℝ} (hS : 0 < S) : + (jumpDiffusionIncrementLaw b σ Λ ν τ).map (fun y ↦ S * rexp y) + = (volume.restrict (Ioi 0)).withDensity + fun K ↦ ENNReal.ofReal (jumpDiffusionDensity b σ Λ ν τ (Real.log (K / S)) / K) := by + rw [jumpDiffusionIncrementLaw_eq_withDensity b hσ Λ ν hτ] + exact map_mul_exp_withDensity _ hS + +/-- **With a Gaussian part the price charges every interval of strikes**: for `S > 0` and +`0 ≤ k₁ < k₂`, `P(k₁ < Seʸ < k₂) > 0`. The law of the price has the density `f(log(K/S))/K` on +`(0, ∞)` (`jumpDiffusionIncrementLaw_map_mul_exp`), positive there (`jumpDiffusionDensity_pos`). -/ +lemma jumpDiffusionIncrementLaw_price_mem_Ioo_ne_zero (b : ℝ) {σ : ℝ} (hσ : σ ≠ 0) (Λ : ℝ≥0) + (ν : Measure ℝ) [IsProbabilityMeasure ν] {τ : ℝ≥0} (hτ : 0 < τ) {S : ℝ} (hS : 0 < S) + {k₁ k₂ : ℝ} (hk₁ : 0 ≤ k₁) (hk : k₁ < k₂) : + jumpDiffusionIncrementLaw b σ Λ ν τ {y | k₁ < S * rexp y ∧ S * rexp y < k₂} ≠ 0 := by + have hf := (continuous_jumpDiffusionDensity b σ Λ ν τ).measurable + have hm : Measurable fun K ↦ + ENNReal.ofReal (jumpDiffusionDensity b σ Λ ν τ (Real.log (K / S)) / K) := by + fun_prop + have hsupp : Function.support (fun K ↦ + ENNReal.ofReal (jumpDiffusionDensity b σ Λ ν τ (Real.log (K / S)) / K)) ∩ Ioo k₁ k₂ + = Ioo k₁ k₂ := + inter_eq_right.2 fun K hK ↦ (ENNReal.ofReal_pos.2 (div_pos + (jumpDiffusionDensity_pos b hσ Λ ν hτ (Real.log (K / S))) (hk₁.trans_lt hK.1))).ne' + rw [show {y | k₁ < S * rexp y ∧ S * rexp y < k₂} = (fun y ↦ S * rexp y) ⁻¹' Ioo k₁ k₂ from rfl, + ← Measure.map_apply (by fun_prop) measurableSet_Ioo, + jumpDiffusionIncrementLaw_map_mul_exp b hσ Λ ν hτ hS, withDensity_apply _ measurableSet_Ioo, + Measure.restrict_restrict measurableSet_Ioo, + inter_eq_left.2 (Ioo_subset_Ioi_self.trans (Ioi_subset_Ioi hk₁))] + refine ((setLIntegral_pos_iff hm).2 ?_).ne' + rw [hsupp, Real.volume_Ioo] + exact ENNReal.ofReal_pos.2 (sub_pos.2 hk) + +/-- **The density of an image law integrates to one.** If a probability law `μ` is mapped by `g` +to `d · ν`, then `∫⁻ d dν = 1`: it is the mass of `μ`. -/ +lemma lintegral_eq_one_of_map_eq_withDensity {α β : Type*} {mα : MeasurableSpace α} + {mβ : MeasurableSpace β} {μ : Measure α} [IsProbabilityMeasure μ] {ν : Measure β} {g : α → β} + (hg : Measurable g) {d : β → ℝ≥0∞} (h : μ.map g = ν.withDensity d) : ∫⁻ x, d x ∂ν = 1 := by + rw [← setLIntegral_univ, ← withDensity_apply _ MeasurableSet.univ, ← h, + Measure.map_apply hg MeasurableSet.univ, preimage_univ, measure_univ] + +end MathFin diff --git a/LeanPool/MathFin/Models/Jumps/JumpDiffusionExponent.lean b/LeanPool/MathFin/Models/Jumps/JumpDiffusionExponent.lean new file mode 100644 index 0000000000..b58d389bb7 --- /dev/null +++ b/LeanPool/MathFin/Models/Jumps/JumpDiffusionExponent.lean @@ -0,0 +1,213 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionOptionPrices + +/-! +# Scaling a jump-diffusion; its exponential martingales + +`θ` times a jump-diffusion log-return over a time `τ` is again one, with drift `θb`, volatility +coefficient `θσ`, the same rate and every jump multiplied by `θ` +(`jumpDiffusionIncrementLaw_map_const_mul`). On the canonical model the drift and the Gaussian +coefficient scale inside the log-return, and multiplying the jumps by `θ` changes only the jump +law (`jumpDiffusionMeasure_map_jumps`). On the process, `θX` is a jump-diffusion +(`JumpDiffusionProcess.const_mul`). + +The Laplace exponent `κ(θ) = bθ + σ²θ²/2 + Λ(∫ e^{θx} dν − 1)` (`jumpDiffusionExponent`, the +cumulant generating function of the log-return per unit time where `∫ e^{θx} dν < ∞`, +`cgf_id_jumpDiffusionIncrementLaw`) then gives, for the price `S_t = S₀e^{X_t}`: + +* `JumpDiffusionProcess.martingale_exp_const_mul_sub`: `t ↦ e^{θX_t − κ(θ)t}` is a martingale for + every `θ` with `∫ e^{θx} dν < ∞`. It is the discounted price criterion + (`JumpDiffusionProcess.martingale_iff`) for `θX` at the rate `κ(θ)`. For `b = 0`, `σ = 1` and no + jumps `κ(θ) = θ²/2`, the exponent of the Wald martingales + (`IsFilteredPreBrownian.waldExponential_isMartingale`); both families rest on the exponential + martingale of independent increments (`martingale_exp_sub_of_indep_increments`). +* `JumpDiffusionProcess.martingale_iff_exponent_one`: the discounted price is a martingale if and + only if `κ(1) = r`. +* `JumpDiffusionProcess.condExp_rpow`, power claims at each date `t ≤ T`: given `𝓕_t`, the + discounted payoff `e^{−r(T−t)}S_T^p` has conditional expectation `S_t^p e^{(κ(p) − r)(T − t)}`, + almost surely. + +## Main results + +* `jumpDiffusionIncrementLaw_map_const_mul`: `θ` times a jump-diffusion log-return over `τ` is + one with drift `θb`, volatility coefficient `θσ`, the same rate and jump law `ν.map (θ * ·)`. +* `jumpDiffusionMeasure_map_jumps`: applying a measurable `g` to every jump size of the + canonical model gives the canonical model with jump law `ν.map g`. +* `JumpDiffusionProcess.const_mul`: `θX` is a jump-diffusion with drift `θb`, volatility + coefficient `θσ`, the same rate and jump law `ν.map (θ * ·)`. +* `JumpDiffusionProcess.martingale_exp_const_mul_sub`: if `∫ e^{θx} dν < ∞`, + `t ↦ e^{θX_t − κ(θ)t}` is a martingale, with `κ` the Laplace exponent + `jumpDiffusionExponent`. +* `JumpDiffusionProcess.martingale_iff_exponent_one`: for `∫ eˣ dν < ∞` and `S₀ ≠ 0`, the + discounted price `e^{−rt} S₀ e^{X_t}` is a martingale iff `κ(1) = r`. +* `JumpDiffusionProcess.condExp_rpow`: for `S₀ > 0`, `∫ e^{px} dν < ∞` and `t ≤ T`, the + conditional expectation of `e^{−r(T−t)} S_T^p` given `𝓕_t` is `S_t^p e^{(κ(p) − r)(T − t)}` + almost surely. + +## References + +* [Cont and Tankov, *Financial Modelling with Jump Processes*][ContTankov2004] + +## Tags + +exponential martingale, Laplace exponent, scaling of jump-diffusion, Lévy exponent, +compensated jumps, MSC 60G51, MSC 60G44, MSC 91G20 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal + +/-! ### Scaling the log-return -/ + +/-- `eˣ` is integrable under the jump law pushed forward by `x ↦ θx` when `e^{θx}` is integrable +under `ν`. -/ +lemma integrable_exp_map_const_mul {ν : Measure ℝ} {θ : ℝ} + (hν : Integrable (fun x ↦ rexp (θ * x)) ν) : Integrable rexp (ν.map (θ * ·)) := + (integrable_map_measure measurable_exp.aestronglyMeasurable + (measurable_const_mul θ).aemeasurable).2 hν + +/-- **Transforming the jumps of the canonical model.** Applying a measurable `g` to every log-jump +size of the canonical model gives the canonical model with jump law `ν.map g`: the diffusion +sample and the jump count are unchanged, and the sizes stay i.i.d. +(`Measure.infinitePi_map_pi`). -/ +lemma jumpDiffusionMeasure_map_jumps (Λ : ℝ≥0) (ν : Measure ℝ) [IsProbabilityMeasure ν] + {g : ℝ → ℝ} (hg : Measurable g) : + (jumpDiffusionMeasure Λ ν).map (Prod.map id (Prod.map id fun j i ↦ g (j i))) + = jumpDiffusionMeasure Λ (ν.map g) := by + have hj : Measurable fun (j : ℕ → ℝ) i ↦ g (j i) := + .of_eval fun i ↦ hg.comp (measurable_pi_apply i) + have hid (α : Type) [MeasurableSpace α] : Measurable (@id α) := measurable_id + unfold jumpDiffusionMeasure + rw [← Measure.map_prod_map _ _ (hid ℝ) ((hid ℕ).prodMap hj), + ← Measure.map_prod_map _ _ (hid ℕ) hj, Measure.map_id, Measure.map_id, + Measure.infinitePi_map_pi (fun _ : ℕ ↦ ν) fun _ ↦ hg] + +/-- `θ` times the log-return with drift `b` and volatility coefficient `σ` is the log-return with +drift `θb` and volatility coefficient `θσ` at the jump sizes multiplied by `θ`. -/ +lemma const_mul_jumpDiffusionLogReturn (θ b σ : ℝ) (τ : ℝ≥0) (ω : ℝ × ℕ × (ℕ → ℝ)) : + θ * jumpDiffusionLogReturn b σ τ ω + = jumpDiffusionLogReturn (θ * b) (θ * σ) τ + (Prod.map id (Prod.map id fun j i ↦ θ * j i) ω) := by + simp only [jumpDiffusionLogReturn, Prod.map_fst, Prod.map_snd, id_eq, ← Finset.mul_sum] + ring + +/-- **Scaling a jump-diffusion log-return.** If `Y` is a jump-diffusion log-return over `τ`, then +`θY` is one with drift `θb`, volatility coefficient `θσ`, the same rate, and the jump law `ν` +pushed forward by `x ↦ θx`. -/ +theorem jumpDiffusionIncrementLaw_map_const_mul (θ b σ : ℝ) (Λ : ℝ≥0) (ν : Measure ℝ) + [IsProbabilityMeasure ν] (τ : ℝ≥0) : + (jumpDiffusionIncrementLaw b σ Λ ν τ).map (θ * ·) + = jumpDiffusionIncrementLaw (θ * b) (θ * σ) Λ (ν.map (θ * ·)) τ := by + have hj : Measurable (Prod.map (@id ℝ) (Prod.map (@id ℕ) fun (j : ℕ → ℝ) i ↦ θ * j i)) := + measurable_id.prodMap (measurable_id.prodMap + (.of_eval fun i ↦ (measurable_const_mul θ).comp (measurable_pi_apply i))) + unfold jumpDiffusionIncrementLaw + rw [← jumpDiffusionMeasure_map_jumps (Λ * τ) ν (measurable_const_mul θ), + Measure.map_map (measurable_jumpDiffusionLogReturn (θ * b) (θ * σ) τ) hj, + Measure.map_map (measurable_const_mul θ) (measurable_jumpDiffusionLogReturn b σ τ)] + congr 1 + exact funext (const_mul_jumpDiffusionLogReturn θ b σ τ) + +/-! ### The process -/ + +namespace JumpDiffusionProcess + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} {𝓕 : Filtration ℝ≥0 mΩ} + {X : ℝ≥0 → Ω → ℝ} {b σ : ℝ} {Λ : ℝ≥0} {ν : Measure ℝ} + +/-- **Scaling the process.** For a jump-diffusion `X`, `θX` is a jump-diffusion with drift `θb`, +volatility coefficient `θσ`, the same rate and the jump law pushed forward by `x ↦ θx`: its +increments are `θ` times those of `X` (`jumpDiffusionIncrementLaw_map_const_mul`). -/ +theorem const_mul (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) [IsProbabilityMeasure ν] (θ : ℝ) : + JumpDiffusionProcess P 𝓕 (fun t ω ↦ θ * X t ω) (θ * b) (θ * σ) Λ (ν.map (θ * ·)) where + adapted t := (h.adapted t).const_mul θ + zero := h.zero.mono fun ω hω ↦ by simp [hω] + indep s t hst := indep_of_indep_of_le_left (h.indep s t hst) + (MeasurableSpace.comap_le_comap_of_eq_comp (θ * ·) (measurable_const_mul θ) + (funext fun ω ↦ (mul_sub θ (X t ω) (X s ω)).symm)) + law s t hst := by + have hθ : HasLaw (fun x : ℝ ↦ θ * x) + (jumpDiffusionIncrementLaw (θ * b) (θ * σ) Λ (ν.map (θ * ·)) (t - s)) + (jumpDiffusionIncrementLaw b σ Λ ν (t - s)) := + ⟨(measurable_const_mul θ).aemeasurable, jumpDiffusionIncrementLaw_map_const_mul θ b σ Λ ν _⟩ + exact (hθ.fun_comp (h.law s t hst)).congr + (ae_of_all _ fun ω ↦ (mul_sub θ (X t ω) (X s ω)).symm) + +/-- `e^{θX_t}` is integrable when `∫ e^{θx} dν < ∞`: `θX` is a jump-diffusion (`const_mul`). -/ +lemma integrable_exp_const_mul (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) [IsProbabilityMeasure ν] + {θ : ℝ} (hν : Integrable (fun x ↦ rexp (θ * x)) ν) (t : ℝ≥0) : + Integrable (fun ω ↦ rexp (θ * X t ω)) P := + (h.const_mul θ).integrable_exp (integrable_exp_map_const_mul hν) t + +/-- **The exponential martingales of a jump-diffusion.** For `θ` with `∫ e^{θx} dν < ∞`, +`t ↦ e^{θX_t − κ(θ)t}` is an `𝓕`-martingale, `κ` the Laplace exponent: the discounted price +martingale (`martingale_iff`) of the scaled process `θX` (`const_mul`) at the rate `κ(θ)`. -/ +theorem martingale_exp_const_mul_sub (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) + [IsProbabilityMeasure ν] {θ : ℝ} (hν : Integrable (fun x ↦ rexp (θ * x)) ν) : + Martingale (fun (t : ℝ≥0) ω ↦ rexp (θ * X t ω - jumpDiffusionExponent b σ Λ ν θ * t)) + 𝓕 P := by + have hM := ((h.const_mul θ).martingale_iff (integrable_exp_map_const_mul hν) one_ne_zero + (jumpDiffusionExponent b σ Λ ν θ)).2 (by + rw [integral_map (measurable_const_mul θ).aemeasurable measurable_exp.aestronglyMeasurable, + jumpDiffusionExponent] + ring) + convert hM using 1 + funext t ω + rw [one_mul, ← Real.exp_add] + congr 1 + ring + +/-- **The martingale condition is `κ(1) = r`.** The discounted price `e^{−rt}S₀e^{X_t}` (`S₀ ≠ 0`) +is a martingale if and only if the Laplace exponent at `1` is the rate: the drift criterion +`martingale_iff`, read through `compensated_iff_exponent_one`. -/ +theorem martingale_iff_exponent_one (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) + [IsProbabilityMeasure ν] (hν : Integrable rexp ν) {S_0 : ℝ} (hS_0 : S_0 ≠ 0) (r : ℝ) : + Martingale (fun (t : ℝ≥0) ω ↦ rexp (-r * t) * (S_0 * rexp (X t ω))) 𝓕 P ↔ + jumpDiffusionExponent b σ Λ ν 1 = r := + (h.martingale_iff hν hS_0 r).trans (compensated_iff_exponent_one b σ r Λ ν) + +/-- **Power claims at each date before maturity.** For `S₀ > 0`, `p` with `∫ e^{px} dν < ∞` and +`t ≤ T`, given `𝓕_t` the discounted payoff `e^{−r(T−t)}S_T^p` of the claim paying the `p`-th power +of the price `S_T = S₀e^{X_T}` has conditional expectation `S_t^p e^{(κ(p) − r)(T − t)}`, almost +surely: the payoff +averaged over the remaining log-return (`condExp_comp`), whose exponential moment at `p` is +`e^{κ(p)(T − t)}` (`integral_exp_const_mul_jumpDiffusionIncrementLaw`). -/ +theorem condExp_rpow (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) [IsProbabilityMeasure ν] + {p : ℝ} (hν : Integrable (fun x ↦ rexp (p * x)) ν) {S_0 : ℝ} (hS_0 : 0 < S_0) (r : ℝ) + {t T : ℝ≥0} (htT : t ≤ T) : + P[fun ω ↦ rexp (-r * (T - t : ℝ≥0)) * (S_0 * rexp (X T ω)) ^ p | 𝓕 t] + =ᵐ[P] fun ω ↦ (S_0 * rexp (X t ω)) ^ p + * rexp ((jumpDiffusionExponent b σ Λ ν p - r) * (T - t : ℝ≥0)) := by + have := h.isProbabilityMeasure + have hpow (y : ℝ) : (S_0 * rexp y) ^ p = S_0 ^ p * rexp (p * y) := by + rw [Real.mul_rpow hS_0.le (Real.exp_pos y).le, ← Real.exp_mul, mul_comm y p] + have hpow_add (x y : ℝ) : (S_0 * rexp (x + y)) ^ p = (S_0 * rexp x) ^ p * rexp (p * y) := by + rw [hpow, hpow, mul_add, Real.exp_add, mul_assoc] + have hint : Integrable (fun ω ↦ rexp (-r * (T - t : ℝ≥0)) * (S_0 * rexp (X T ω)) ^ p) P := + ((h.integrable_exp_const_mul hν T).const_mul (rexp (-r * (T - t : ℝ≥0)) * S_0 ^ p)).congr + (ae_of_all _ fun ω ↦ by beta_reduce; rw [hpow, mul_assoc]) + refine (h.condExp_comp (f := fun x ↦ rexp (-r * (T - t : ℝ≥0)) * (S_0 * rexp x) ^ p) + (measurable_const.mul ((measurable_const.mul measurable_exp).pow_const p)) htT hint).trans + (ae_of_all _ fun ω ↦ ?_) + beta_reduce + simp only [hpow_add (X t ω)] + rw [integral_const_mul, integral_const_mul, + integral_exp_const_mul_jumpDiffusionIncrementLaw b σ Λ hν, mul_left_comm, ← Real.exp_add] + congr 2 + ring + +end JumpDiffusionProcess + +end MathFin diff --git a/LeanPool/MathFin/Models/Jumps/JumpDiffusionIdentifiability.lean b/LeanPool/MathFin/Models/Jumps/JumpDiffusionIdentifiability.lean new file mode 100644 index 0000000000..ad98ba3ec8 --- /dev/null +++ b/LeanPool/MathFin/Models/Jumps/JumpDiffusionIdentifiability.lean @@ -0,0 +1,362 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionProcess +public import LeanPool.MathFin.Probability.Laws.Esscher +public import Mathlib.Algebra.Ring.IsFormallyReal +public import Mathlib.Analysis.SpecialFunctions.Trigonometric.DerivHyp + +/-! +# The law at one date determines the drift, the Gaussian variance and the Lévy measure + +When the jump laws' moment-generating functions are finite near `0`, the log-return law over a time +`τ > 0` of a jump-diffusion with drift `b`, volatility coefficient `σ`, jump rate `Λ` and jump law +`ν` (`jumpDiffusionIncrementLaw`) determines the drift `b`, the Gaussian variance `σ²` and the Lévy +measure `Λν` away from `0`. The sign of `σ` is not determined, since the Gaussian part is +symmetric, and the rate `Λ` and the jump law `ν` enter only through their product off `0`: jumps +of size `0` do not move the log-price. This is the uniqueness in the +Lévy–Khintchine representation for compound-Poisson jumps with exponential moments near `0`, read +off a single date. The full uniqueness needs no moment conditions. + +* `jumpDiffusionExponent_eq_levy`: `κ(u) = bu + σ²u²/2 + ∫ (e^{ux} − 1) Π(dx)` wherever + `∫ e^{ux} dν < ∞`, where `Π` is `Λν` restricted to `x ≠ 0`. The Laplace exponent sees the jumps + only through `Π`. +* `mgf_id_secondDifferenceMeasure`: where `ν` has the exponential moments of orders `u ± s` and + `u`, the second difference `κ(u + s) + κ(u − s) − 2κ(u)` is the moment-generating function at + `u` of the finite measure `σ²s²·δ₀ + 2(cosh(sx) − 1)·Λν` (`secondDifferenceMeasure`). Its atom + at `0` is the Gaussian part and off `0` it is the jumps, as in Kolmogorov's canonical measure + `σ²δ₀ + x²Π(dx)`. +* `jumpDiffusionIncrementLaw_eq_iff`: for jump laws whose moment-generating functions are finite + near `0`, two log-return laws at the same date `τ > 0` are equal iff their drifts agree, their + Gaussian variances agree and their Lévy measures agree off `0`. + +The proof reads `κ` off the law near `0` (`mgf_id_jumpDiffusionIncrementLaw`) and takes second +differences in `u`, which cancel the drift. Equal laws give second-difference measures with the +same moment-generating function near `0`, hence equal measures +(`measure_eq_of_mgf_id_eventuallyEq`). +Their atoms at `0` give `σ²`. Off `0`, dividing by `2(cosh(sx) − 1)`, which vanishes only at `0`, +gives `Π`. Then `κ` at one point gives `b`. + +## Main definitions + +* `coshKernel`: the second-difference kernel `2(cosh(sx) − 1)`, as a nonnegative real density. +* `secondDifferenceMeasure`: the measure `σ²s² · δ₀ + 2(cosh(sx) − 1) · Λν`, whose + moment-generating function at `u` is the second difference of the Laplace exponent with + step `s`. + +## Main results + +* `coshKernel_eq_zero_iff`: for `s ≠ 0` the kernel vanishes only at `0`. +* `jumpDiffusionExponent_eq_levy`: wherever `∫ e^{ux} dν < ∞`, + `κ(u) = bu + σ²u²/2 + ∫ (e^{ux} − 1) dΠ`, with `Π` the measure `Λν` restricted to `x ≠ 0`. +* `mgf_id_secondDifferenceMeasure`: where `ν` has the exponential moments of orders `u + s`, + `u − s` and `u`, `κ(u + s) + κ(u − s) − 2κ(u)` is the moment-generating function at `u` of + `secondDifferenceMeasure σ s Λ ν`. +* `secondDifferenceMeasure_singleton_zero`: its atom at `0` is `σ²s²`. +* `restrict_compl_zero_secondDifferenceMeasure`: off `0` it is the kernel times the Lévy + measure. +* `eventually_jumpDiffusionExponent_eq`: equal log-return laws at a date `τ > 0` have equal + Laplace exponents near `0`, when the jump laws have exponential moments near `0`. +* `jumpDiffusionIncrementLaw_eq_iff`: for jump laws with moment-generating functions finite + near `0` and `τ > 0`, two log-return laws agree iff the drifts agree, the Gaussian variances + `σ²` agree and the Lévy measures `Λν` agree off `0`. + +## References + +* [Cont and Tankov, *Financial Modelling with Jump Processes*][ContTankov2004] +* [Sato, *Lévy Processes and Infinitely Divisible Distributions*][Sato1999] + +## Tags + +identifiability, Lévy measure, calibration from one date, moment generating function, +drift and variance recovery, MSC 60G51, MSC 91G20, MSC 62F10 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real Filter Set +open scoped NNReal ENNReal Topology + +/-- The second-difference kernel `2(cosh(sx) − 1) = e^{sx} + e^{−sx} − 2`, as a density: the second +difference of `u ↦ e^{ux}` with step `s` is `e^{ux}` times it (`coshKernel_smul_exp`). -/ +noncomputable def coshKernel (s x : ℝ) : ℝ≥0 := Real.toNNReal (2 * (Real.cosh (s * x) - 1)) + +lemma coe_coshKernel (s x : ℝ) : (coshKernel s x : ℝ) = 2 * (Real.cosh (s * x) - 1) := + Real.coe_toNNReal _ (by linarith [Real.one_le_cosh (s * x)]) + +lemma measurable_coshKernel (s : ℝ) : Measurable (coshKernel s) := + (by fun_prop : Measurable fun x ↦ 2 * (Real.cosh (s * x) - 1)).real_toNNReal + +/-- For `s ≠ 0` the kernel vanishes only at `0`. -/ +lemma coshKernel_eq_zero_iff {s : ℝ} (hs : s ≠ 0) {x : ℝ} : coshKernel s x = 0 ↔ x = 0 := by + rw [coshKernel, Real.toNNReal_eq_zero] + refine ⟨fun h ↦ Classical.byContradiction fun hx ↦ ?_, fun hx ↦ by simp [hx]⟩ + linarith [Real.one_lt_cosh.2 (mul_ne_zero hs hx)] + +/-- The second difference of `u ↦ e^{ux}` with step `s`: +`2(cosh(sx) − 1)·e^{ux} = e^{(u+s)x} + e^{(u−s)x} − 2e^{ux}`. -/ +lemma coshKernel_smul_exp (s u x : ℝ) : + coshKernel s x • rexp (u * x) + = rexp ((u + s) * x) + rexp ((u - s) * x) - 2 * rexp (u * x) := by + rw [NNReal.smul_def, smul_eq_mul, coe_coshKernel, Real.cosh_eq, + show (u + s) * x = u * x + s * x by ring, show (u - s) * x = u * x + -(s * x) by ring, + Real.exp_add, Real.exp_add] + ring + +lemma integrable_coshKernel_smul_exp {ν : Measure ℝ} {s u : ℝ} + (hp : Integrable (fun x ↦ rexp ((u + s) * x)) ν) + (hm : Integrable (fun x ↦ rexp ((u - s) * x)) ν) (h0 : Integrable (fun x ↦ rexp (u * x)) ν) : + Integrable (fun x ↦ coshKernel s x • rexp (u * x)) ν := by + simp_rw [coshKernel_smul_exp] + exact (hp.add hm).sub (h0.const_mul 2) + +/-- **The kernel turns second differences of exponential moments into one integral**: +`∫ 2(cosh(sx) − 1)e^{ux} dν = ∫ e^{(u+s)x} dν + ∫ e^{(u−s)x} dν − 2∫ e^{ux} dν`. -/ +lemma integral_coshKernel_smul_exp {ν : Measure ℝ} {s u : ℝ} + (hp : Integrable (fun x ↦ rexp ((u + s) * x)) ν) + (hm : Integrable (fun x ↦ rexp ((u - s) * x)) ν) (h0 : Integrable (fun x ↦ rexp (u * x)) ν) : + ∫ x, coshKernel s x • rexp (u * x) ∂ν + = ∫ x, rexp ((u + s) * x) ∂ν + ∫ x, rexp ((u - s) * x) ∂ν - 2 * ∫ x, rexp (u * x) ∂ν := by + have hpm : Integrable (fun x ↦ rexp ((u + s) * x) + rexp ((u - s) * x)) ν := hp.add hm + simp_rw [coshKernel_smul_exp] + rw [integral_sub hpm (h0.const_mul 2), integral_add hp hm, integral_const_mul] + +/-- The kernel measure `2(cosh(sx) − 1)·Λν` has the exponential moment of order `u` when `ν` has +those of orders `u + s`, `u − s` and `u`. -/ +lemma integrable_exp_mul_withDensity_coshKernel (Λ : ℝ≥0) {ν : Measure ℝ} {s u : ℝ} + (hp : Integrable (fun x ↦ rexp ((u + s) * x)) ν) + (hm : Integrable (fun x ↦ rexp ((u - s) * x)) ν) (h0 : Integrable (fun x ↦ rexp (u * x)) ν) : + Integrable (fun x ↦ rexp (u * x)) ((Λ • ν).withDensity fun x ↦ coshKernel s x) := + (integrable_withDensity_iff_integrable_smul (measurable_coshKernel s)).2 + (integrable_coshKernel_smul_exp hp hm h0).smul_measure_nnreal + +/-- **The moment-generating function of the kernel measure** at `u` is `Λ` times the second +difference of the moment-generating function of `ν`, when `ν` has the exponential moments of +orders `u + s`, `u − s` and `u`. -/ +lemma mgf_id_withDensity_coshKernel (Λ : ℝ≥0) {ν : Measure ℝ} {s u : ℝ} + (hp : Integrable (fun x ↦ rexp ((u + s) * x)) ν) + (hm : Integrable (fun x ↦ rexp ((u - s) * x)) ν) (h0 : Integrable (fun x ↦ rexp (u * x)) ν) : + mgf id ((Λ • ν).withDensity fun x ↦ coshKernel s x) u + = Λ * (∫ x, rexp ((u + s) * x) ∂ν + ∫ x, rexp ((u - s) * x) ∂ν + - 2 * ∫ x, rexp (u * x) ∂ν) := by + change ∫ x, rexp (u * x) ∂((Λ • ν).withDensity fun x ↦ coshKernel s x) = _ + rw [integral_withDensity_eq_integral_smul (measurable_coshKernel s), + integral_smul_nnreal_measure, integral_coshKernel_smul_exp hp hm h0, NNReal.smul_def, + smul_eq_mul] + +/-- The kernel measure is finite when `ν` has the exponential moments of orders `s` and `−s`. -/ +lemma isFiniteMeasure_withDensity_coshKernel (Λ : ℝ≥0) {ν : Measure ℝ} [IsFiniteMeasure ν] + {s : ℝ} (hp : Integrable (fun x ↦ rexp (s * x)) ν) + (hm : Integrable (fun x ↦ rexp (-s * x)) ν) : + IsFiniteMeasure ((Λ • ν).withDensity fun x ↦ coshKernel s x) := by + have h := integrable_exp_mul_withDensity_coshKernel Λ (u := 0) (s := s) + (by simpa only [zero_add] using hp) (by simpa only [zero_sub] using hm) + (by simpa only [zero_mul, Real.exp_zero] using integrable_const (1 : ℝ)) + simp only [zero_mul, Real.exp_zero] at h + exact (integrable_const_iff.1 h).resolve_left one_ne_zero + +/-- Off `0` the kernel is positive and finite, so dividing the kernel measure by it gives back the +measure restricted to `x ≠ 0`. -/ +lemma restrict_compl_zero_eq_withDensity_inv {s : ℝ} (hs : s ≠ 0) (μ : Measure ℝ) : + μ.restrict {0}ᶜ = ((μ.withDensity fun x ↦ coshKernel s x).restrict {0}ᶜ).withDensity + fun x ↦ (coshKernel s x : ℝ≥0∞)⁻¹ := by + rw [restrict_withDensity (measurableSet_singleton (0 : ℝ)).compl, withDensity_inv_same + (measurable_coshKernel s).coe_nnreal_ennreal ?_ (ae_of_all _ fun _ ↦ ENNReal.coe_ne_top)] + filter_upwards [ae_restrict_mem (measurableSet_singleton (0 : ℝ)).compl] with x hx + exact ENNReal.coe_ne_zero.2 ((coshKernel_eq_zero_iff hs).not.2 (mem_compl_singleton_iff.1 hx)) + +/-- **The second-difference measure** `σ²s²·δ₀ + 2(cosh(sx) − 1)·Λν`. Its moment-generating +function at `u` is the second difference of the Laplace exponent with step `s`, where `ν` has the +exponential moments of orders `u ± s` and `u` (`mgf_id_secondDifferenceMeasure`). Its atom at `0` +is the Gaussian part `σ²s²` (`secondDifferenceMeasure_singleton_zero`), and off `0` it is the +kernel times the Lévy measure (`restrict_compl_zero_secondDifferenceMeasure`). -/ +noncomputable def secondDifferenceMeasure (σ s : ℝ) (Λ : ℝ≥0) (ν : Measure ℝ) : Measure ℝ := + (σ ^ 2 * s ^ 2).toNNReal • Measure.dirac 0 + (Λ • ν).withDensity fun x ↦ coshKernel s x + +/-- The second-difference measure is finite when `ν` has the exponential moments of orders `s` and +`−s`. -/ +lemma isFiniteMeasure_secondDifferenceMeasure (σ : ℝ) (Λ : ℝ≥0) {ν : Measure ℝ} + [IsFiniteMeasure ν] {s : ℝ} (hp : Integrable (fun x ↦ rexp (s * x)) ν) + (hm : Integrable (fun x ↦ rexp (-s * x)) ν) : + IsFiniteMeasure (secondDifferenceMeasure σ s Λ ν) := by + have := isFiniteMeasure_withDensity_coshKernel Λ hp hm + unfold secondDifferenceMeasure + infer_instance + +/-- The second-difference measure has the exponential moment of order `u` when `ν` has those of +orders `u + s`, `u − s` and `u`. -/ +lemma integrable_exp_mul_secondDifferenceMeasure (σ : ℝ) (Λ : ℝ≥0) {ν : Measure ℝ} {s u : ℝ} + (hp : Integrable (fun x ↦ rexp ((u + s) * x)) ν) + (hm : Integrable (fun x ↦ rexp ((u - s) * x)) ν) (h0 : Integrable (fun x ↦ rexp (u * x)) ν) : + Integrable (fun x ↦ rexp (u * x)) (secondDifferenceMeasure σ s Λ ν) := + (integrable_dirac (f := fun x : ℝ ↦ rexp (u * x)) (a := 0) eNorm_lt_top).smul_measure_nnreal + |>.add_measure (integrable_exp_mul_withDensity_coshKernel Λ hp hm h0) + +/-- **The second difference of the Laplace exponent is a moment-generating function**: +`κ(u + s) + κ(u − s) − 2κ(u) = σ²s² + Λ(m(u + s) + m(u − s) − 2m(u))`, the moment-generating +function at `u` of `σ²s²·δ₀ + 2(cosh(sx) − 1)·Λν`, when `ν` has the exponential moments of orders +`u + s`, `u − s` and `u`. The drift cancels. -/ +lemma mgf_id_secondDifferenceMeasure (b σ : ℝ) (Λ : ℝ≥0) {ν : Measure ℝ} {s u : ℝ} + (hp : Integrable (fun x ↦ rexp ((u + s) * x)) ν) + (hm : Integrable (fun x ↦ rexp ((u - s) * x)) ν) (h0 : Integrable (fun x ↦ rexp (u * x)) ν) : + mgf id (secondDifferenceMeasure σ s Λ ν) u + = jumpDiffusionExponent b σ Λ ν (u + s) + jumpDiffusionExponent b σ Λ ν (u - s) + - 2 * jumpDiffusionExponent b σ Λ ν u := by + have hW : ∫ x, rexp (u * x) ∂((Λ • ν).withDensity fun x ↦ coshKernel s x) + = Λ * (∫ x, rexp ((u + s) * x) ∂ν + ∫ x, rexp ((u - s) * x) ∂ν + - 2 * ∫ x, rexp (u * x) ∂ν) := + mgf_id_withDensity_coshKernel Λ hp hm h0 + change ∫ x, rexp (u * x) ∂(secondDifferenceMeasure σ s Λ ν) = _ + rw [secondDifferenceMeasure, integral_add_measure + (integrable_dirac (f := fun x : ℝ ↦ rexp (u * x)) (a := 0) eNorm_lt_top).smul_measure_nnreal + (integrable_exp_mul_withDensity_coshKernel Λ hp hm h0), + integral_smul_nnreal_measure, integral_dirac, hW, mul_zero, Real.exp_zero, NNReal.smul_def, + smul_eq_mul, mul_one, Real.coe_toNNReal _ (by positivity)] + simp only [jumpDiffusionExponent] + ring + +/-- **The atom of the second-difference measure at `0` is the Gaussian part** `σ²s²`: the kernel +vanishes at `0`. -/ +lemma secondDifferenceMeasure_singleton_zero (σ s : ℝ) (Λ : ℝ≥0) (ν : Measure ℝ) : + secondDifferenceMeasure σ s Λ ν {0} = ENNReal.ofReal (σ ^ 2 * s ^ 2) := by + have hW : ((Λ • ν).withDensity fun x ↦ coshKernel s x) {0} = 0 := by + rw [withDensity_apply_eq_zero (measurable_coshKernel s).coe_nnreal_ennreal] + refine measure_mono_null (fun x ⟨hx0, hx1⟩ ↦ ?_) measure_empty + rw [mem_singleton_iff.1 hx1] at hx0 + simp [coshKernel] at hx0 + rw [show ENNReal.ofReal (σ ^ 2 * s ^ 2) = ((σ ^ 2 * s ^ 2).toNNReal : ℝ≥0∞) from rfl, + secondDifferenceMeasure, add_apply, hW, add_zero, Measure.coe_nnreal_smul_apply, + Measure.dirac_apply_of_mem (mem_singleton (0 : ℝ)), mul_one] + +/-- **Off `0` the second-difference measure is the kernel times the Lévy measure**: the atom +lives at `0`. -/ +lemma restrict_compl_zero_secondDifferenceMeasure (σ s : ℝ) (Λ : ℝ≥0) (ν : Measure ℝ) : + (secondDifferenceMeasure σ s Λ ν).restrict {0}ᶜ + = ((Λ • ν).withDensity fun x ↦ coshKernel s x).restrict {0}ᶜ := by + have hδ : (Measure.dirac (0 : ℝ)).restrict {0}ᶜ = 0 := + Measure.restrict_eq_zero.2 ((dirac_eq_zero_iff_notMem (measurableSet_singleton 0).compl).2 + (by simp)) + rw [secondDifferenceMeasure, Measure.restrict_add, Measure.restrict_smul, hδ, smul_zero, + zero_add] + +/-- **The Lévy–Khintchine form of the Laplace exponent**: wherever `∫ e^{ux} dν < ∞`, +`κ(u) = bu + σ²u²/2 + ∫ (e^{ux} − 1) Π(dx)`, where `Π` is the Lévy measure `Λν` restricted to +`x ≠ 0`. Jumps of size `0` contribute nothing. -/ +lemma jumpDiffusionExponent_eq_levy (b σ : ℝ) (Λ : ℝ≥0) {ν : Measure ℝ} [IsProbabilityMeasure ν] + {u : ℝ} (hu : Integrable (fun x ↦ rexp (u * x)) ν) : + jumpDiffusionExponent b σ Λ ν u + = b * u + σ ^ 2 * u ^ 2 / 2 + ∫ x, (rexp (u * x) - 1) ∂((Λ • ν).restrict {0}ᶜ) := by + have hf : Integrable (fun x ↦ rexp (u * x) - 1) (Λ • ν) := + (hu.sub (integrable_const 1)).smul_measure_nnreal + have h0 : ∫ x in {0}, (rexp (u * x) - 1) ∂(Λ • ν) = 0 := + setIntegral_eq_zero_of_forall_eq_zero fun x hx ↦ by simp [mem_singleton_iff.1 hx] + have h := integral_add_compl (measurableSet_singleton (0 : ℝ)) hf + rw [h0, zero_add, integral_smul_nnreal_measure, integral_sub hu (integrable_const 1), + integral_const, probReal_univ, one_smul, NNReal.smul_def, smul_eq_mul] at h + rw [jumpDiffusionExponent, h] + +/-- Equal log-return laws at a date `τ > 0` have equal Laplace exponents near `0`, where the jump +laws have exponential moments. -/ +lemma eventually_jumpDiffusionExponent_eq {b₁ b₂ σ₁ σ₂ : ℝ} {Λ₁ Λ₂ : ℝ≥0} {ν₁ ν₂ : Measure ℝ} + [IsProbabilityMeasure ν₁] [IsProbabilityMeasure ν₂] + (h₁ : 0 ∈ interior (integrableExpSet id ν₁)) (h₂ : 0 ∈ interior (integrableExpSet id ν₂)) + {τ : ℝ≥0} (hτ : 0 < τ) + (h : jumpDiffusionIncrementLaw b₁ σ₁ Λ₁ ν₁ τ = jumpDiffusionIncrementLaw b₂ σ₂ Λ₂ ν₂ τ) : + ∀ᶠ u in 𝓝 (0 : ℝ), + jumpDiffusionExponent b₁ σ₁ Λ₁ ν₁ u = jumpDiffusionExponent b₂ σ₂ Λ₂ ν₂ u := by + filter_upwards [mem_interior_iff_mem_nhds.1 h₁, mem_interior_iff_mem_nhds.1 h₂] with u hu₁ hu₂ + have e : mgf id (jumpDiffusionIncrementLaw b₁ σ₁ Λ₁ ν₁ τ) u + = mgf id (jumpDiffusionIncrementLaw b₂ σ₂ Λ₂ ν₂ τ) u := by rw [h] + rw [mgf_id_jumpDiffusionIncrementLaw b₁ σ₁ Λ₁ + (hu₁ : Integrable (fun x ↦ rexp (u * x)) ν₁) τ, + mgf_id_jumpDiffusionIncrementLaw b₂ σ₂ Λ₂ (hu₂ : Integrable (fun x ↦ rexp (u * x)) ν₂) τ, + Real.exp_eq_exp] at e + exact mul_right_cancel₀ (NNReal.coe_ne_zero.2 hτ.ne') e + +/-- **The law at one date determines the drift, the Gaussian variance and the Lévy measure.** +For jump laws whose moment-generating functions are finite near `0`, two jump-diffusion log-return +laws at the same date `τ > 0` are equal iff their drifts agree, their Gaussian variances `σ²` agree +and their Lévy measures `Λν` agree off `0`. -/ +theorem jumpDiffusionIncrementLaw_eq_iff {b₁ b₂ σ₁ σ₂ : ℝ} {Λ₁ Λ₂ : ℝ≥0} {ν₁ ν₂ : Measure ℝ} + [IsProbabilityMeasure ν₁] [IsProbabilityMeasure ν₂] + (h₁ : 0 ∈ interior (integrableExpSet id ν₁)) (h₂ : 0 ∈ interior (integrableExpSet id ν₂)) + {τ : ℝ≥0} (hτ : 0 < τ) : + jumpDiffusionIncrementLaw b₁ σ₁ Λ₁ ν₁ τ = jumpDiffusionIncrementLaw b₂ σ₂ Λ₂ ν₂ τ ↔ + b₁ = b₂ ∧ σ₁ ^ 2 = σ₂ ^ 2 ∧ (Λ₁ • ν₁).restrict {0}ᶜ = (Λ₂ • ν₂).restrict {0}ᶜ := by + -- near `0` both jump laws have exponential moments + have hD₁ : ∀ᶠ u in 𝓝 (0 : ℝ), Integrable (fun x ↦ rexp (u * x)) ν₁ := + eventually_mem_set.2 (mem_interior_iff_mem_nhds.1 h₁) + have hD₂ : ∀ᶠ u in 𝓝 (0 : ℝ), Integrable (fun x ↦ rexp (u * x)) ν₂ := + eventually_mem_set.2 (mem_interior_iff_mem_nhds.1 h₂) + constructor + · intro h + obtain ⟨ε, hε, hball⟩ := Metric.eventually_nhds_iff_ball.1 + (hD₁.and (hD₂.and (eventually_jumpDiffusionExponent_eq h₁ h₂ hτ h))) + have hin (y : ℝ) (hy₁ : -ε < y) (hy₂ : y < ε) := hball y (by + rw [Metric.mem_ball, Real.dist_eq, sub_zero, abs_lt] + exact ⟨hy₁, hy₂⟩) + have hs : ε / 2 ≠ 0 := (half_pos hε).ne' + have := isFiniteMeasure_secondDifferenceMeasure σ₁ Λ₁ (s := ε / 2) + (hin (ε / 2) (by linarith) (by linarith)).1 (hin (-(ε / 2)) (by linarith) (by linarith)).1 + have := isFiniteMeasure_secondDifferenceMeasure σ₂ Λ₂ (s := ε / 2) + (hin (ε / 2) (by linarith) (by linarith)).2.1 + (hin (-(ε / 2)) (by linarith) (by linarith)).2.1 + -- the second-difference measures have the same moment-generating function on `(-ε/2, ε/2)` + have hM : secondDifferenceMeasure σ₁ (ε / 2) Λ₁ ν₁ + = secondDifferenceMeasure σ₂ (ε / 2) Λ₂ ν₂ := by + have hU : Metric.ball (0 : ℝ) (ε / 2) ∈ 𝓝 0 := Metric.ball_mem_nhds 0 (half_pos hε) + refine measure_eq_of_mgf_id_eventuallyEq + (mem_interior_iff_mem_nhds.2 (mem_of_superset hU fun u hu ↦ ?_)) + (eventually_of_mem hU fun u hu ↦ ?_) + all_goals + rw [Metric.mem_ball, Real.dist_eq, sub_zero, abs_lt] at hu + obtain ⟨hu₁, hu₂⟩ := hu + · exact integrable_exp_mul_secondDifferenceMeasure σ₁ Λ₁ + (hin (u + ε / 2) (by linarith) (by linarith)).1 + (hin (u - ε / 2) (by linarith) (by linarith)).1 (hin u (by linarith) (by linarith)).1 + · rw [mgf_id_secondDifferenceMeasure b₁ σ₁ Λ₁ (hin (u + ε / 2) (by linarith) (by linarith)).1 + (hin (u - ε / 2) (by linarith) (by linarith)).1 (hin u (by linarith) (by linarith)).1, + mgf_id_secondDifferenceMeasure b₂ σ₂ Λ₂ (hin (u + ε / 2) (by linarith) (by linarith)).2.1 + (hin (u - ε / 2) (by linarith) (by linarith)).2.1 + (hin u (by linarith) (by linarith)).2.1, + (hin (u + ε / 2) (by linarith) (by linarith)).2.2, + (hin (u - ε / 2) (by linarith) (by linarith)).2.2, + (hin u (by linarith) (by linarith)).2.2] + -- their atoms at `0` give `σ²` + have hσ : σ₁ ^ 2 = σ₂ ^ 2 := by + have h0 : secondDifferenceMeasure σ₁ (ε / 2) Λ₁ ν₁ {0} + = secondDifferenceMeasure σ₂ (ε / 2) Λ₂ ν₂ {0} := by rw [hM] + rw [secondDifferenceMeasure_singleton_zero, secondDifferenceMeasure_singleton_zero, + ENNReal.ofReal_eq_ofReal_iff (by positivity) (by positivity)] at h0 + exact mul_right_cancel₀ (pow_ne_zero 2 hs) h0 + -- off `0` they are the kernel times the Lévy measures, and dividing by the kernel gives those + have hLevy : (Λ₁ • ν₁).restrict {0}ᶜ = (Λ₂ • ν₂).restrict {0}ᶜ := by + rw [restrict_compl_zero_eq_withDensity_inv hs (Λ₁ • ν₁), + restrict_compl_zero_eq_withDensity_inv hs (Λ₂ • ν₂), + ← restrict_compl_zero_secondDifferenceMeasure σ₁ (ε / 2) Λ₁ ν₁, + ← restrict_compl_zero_secondDifferenceMeasure σ₂ (ε / 2) Λ₂ ν₂, hM] + -- and then `κ` gives the drift + refine ⟨?_, hσ, hLevy⟩ + have e := (hin (ε / 2) (by linarith) (by linarith)).2.2 + rw [jumpDiffusionExponent_eq_levy b₁ σ₁ Λ₁ (hin (ε / 2) (by linarith) (by linarith)).1, + jumpDiffusionExponent_eq_levy b₂ σ₂ Λ₂ (hin (ε / 2) (by linarith) (by linarith)).2.1, + hLevy] at e + have h2 : (b₁ - b₂) * (ε / 2) = 0 := by linear_combination e - (ε / 2) ^ 2 / 2 * hσ + exact sub_eq_zero.1 ((mul_eq_zero.1 h2).resolve_right hs) + · rintro ⟨hb, hσ, hLevy⟩ + refine measure_eq_of_mgf_id_eventuallyEq + (zero_mem_interior_integrableExpSet_jumpDiffusionIncrementLaw _ _ _ h₁ τ) + ((hD₁.and hD₂).mono fun u hu ↦ ?_) + rw [mgf_id_jumpDiffusionIncrementLaw _ _ _ hu.1, mgf_id_jumpDiffusionIncrementLaw _ _ _ hu.2, + jumpDiffusionExponent_eq_levy _ _ _ hu.1, jumpDiffusionExponent_eq_levy _ _ _ hu.2, hLevy, hb, + hσ] + +end MathFin diff --git a/LeanPool/MathFin/Models/Jumps/JumpDiffusionMerton.lean b/LeanPool/MathFin/Models/Jumps/JumpDiffusionMerton.lean new file mode 100644 index 0000000000..292b988baf --- /dev/null +++ b/LeanPool/MathFin/Models/Jumps/JumpDiffusionMerton.lean @@ -0,0 +1,275 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.GaussianSmoothing +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionOptionPrices +public import LeanPool.MathFin.Models.Jumps.MertonJumpDiffusion + +/-! +# Merton's formula from the general jump-diffusion + +Merton (1976) priced the call of a jump-diffusion with lognormal jumps as a Poisson series of +Black–Scholes prices (`mertonCallPrice`): given `n` jumps the log-return is Gaussian, so the call +is the Black–Scholes call at the jump-adjusted spot `S₀e^{−kΛ}(1 + k)ⁿ` and the volatility +`√(σ² + nδ²/T)`. This file derives it from the general jump-diffusion (`JumpDiffusionHyp`). With +log-jumps `N(log(1 + k) − δ²/2, δ²)`, whose multipliers `e^{Jᵢ}` have mean `1 + k`, Merton's +formula for a general jump law +(`JumpDiffusionHyp.call_poisson_mixture`) averages the Black–Scholes price over the sum of `n` +log-jumps, which is `N(n(log(1 + k) − δ²/2), nδ²)`. Gaussian smoothing +(`integral_bsV_mul_exp_gaussianReal_of_sq`) turns each average into the `n`-th term of the +series. + +The same computation prices the call in the price process. At the compensated drift the call +price function is the call of the canonical model (`jumpDiffusionCallPrice_eq_canonical`). With +Gaussian jumps it is therefore Merton's series, and the conditional value of the call at every +date before maturity is Merton's 1976 formula at the current price and the remaining maturity. + +## Main results + +* `JumpDiffusionHyp.call_eq_mertonCallPrice`: with Gaussian log-jumps and the compensator `kΛ`, + the call is `mertonCallPrice`. +* `JumpDiffusionHyp.put_eq_mertonPutPrice`: the put is `mertonPutPrice`, from the call by + put–call parity (`merton_put_call_parity`) at the terminal law. +* `JumpDiffusionHyp.discounted_terminal_merton`: with the compensator `kΛ` the discounted + terminal price has mean `S₀`. +* Merton's model exists: `jumpDiffusionHyp_canonical` at Merton's jump law + `N(log(1 + k) − δ²/2, δ²)`. +* `jumpDiffusionCallPrice_gaussian_eq_mertonCallPrice`: with Gaussian jumps and the compensated + drift `b = r − σ²/2 − Λk`, the call price function over `τ` is `mertonCallPrice` at the expected + jump count `Λτ`. +* `JumpDiffusionProcess.condExp_call_eq_mertonCallPrice`: for `t < T`, the conditional value of + the call given `𝓕_t` is `mertonCallPrice` at `S_t`, `T − t` and `Λ(T − t)`. +* `jumpDiffusionPutPrice_gaussian_eq_mertonPutPrice` and + `JumpDiffusionProcess.condExp_put_eq_mertonPutPrice`: the same for the put and `mertonPutPrice`, + through the two put–call parities. + +## References + +* [Cont and Tankov, *Financial Modelling with Jump Processes*][ContTankov2004] +* [R. C. Merton, *Option pricing when underlying stock returns are discontinuous*][Merton1976] + +## Tags + +Merton jump-diffusion, Poisson series, lognormal jumps, jump-adjusted volatility, +option pricing with jumps, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal + +/-- Merton's log-jump law `N(log(1 + k) − δ²/2, δ²)` has `𝔼[e^J] = 1 + k`: the jump multipliers +have mean `1 + k` (the lognormal mean, `integral_exp_gaussianReal`). -/ +lemma integral_exp_mertonJump {k : ℝ} (hk : -1 < k) (δ : ℝ) : + ∫ x, rexp x ∂(gaussianReal (Real.log (1 + k) - δ ^ 2 / 2) (δ ^ 2).toNNReal) = 1 + k := by + rw [integral_exp_gaussianReal, Real.coe_toNNReal _ (sq_nonneg δ), sub_add_cancel, + Real.exp_log (show (0 : ℝ) < 1 + k by linarith)] + +/-- With Merton's log-jumps the compensated drift `r − σ²/2 − Λ(𝔼[e^J] − 1)` is +`r − σ²/2 − Λk`. -/ +lemma mertonJump_compensated {k : ℝ} (hk : -1 < k) (δ : ℝ) {r b σ : ℝ} {Λ : ℝ≥0} + (hb : b = r - σ ^ 2 / 2 - Λ * k) : + b = r - σ ^ 2 / 2 - Λ * (∫ x, rexp x + ∂(gaussianReal (Real.log (1 + k) - δ ^ 2 / 2) (δ ^ 2).toNNReal) - 1) := by + rw [integral_exp_mertonJump hk δ, hb] + ring + +/-- **Put–call parity for discounted payoffs.** For an integrable terminal price `S` under a +probability measure, the discounted put payoff `D(K − S)⁺` has expectation +`𝔼[D(S − K)⁺] − 𝔼[D·S] + D·K`: pointwise the put payoff is the call payoff minus the forward plus +the strike (`max_zero_sub_max_neg_zero_eq_self`). -/ +lemma integral_discounted_put_payoff {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} + [IsProbabilityMeasure Q] {S : Ω → ℝ} (hS : Integrable S Q) (D K : ℝ) : + ∫ ω, D * max (K - S ω) 0 ∂Q + = ∫ ω, D * max (S ω - K) 0 ∂Q - ∫ ω, D * S ω ∂Q + D * K := by + have hcall : Integrable (fun ω ↦ D * max (S ω - K) 0) Q := + ((hS.sub' (integrable_const K)).pos_part).const_mul D + have hfwd : Integrable (fun ω ↦ D * S ω) Q := hS.const_mul D + have hpar (ω : Ω) : D * max (K - S ω) 0 + = D * max (S ω - K) 0 - (D * S ω - D * K) := by + have hx := max_zero_sub_max_neg_zero_eq_self (S ω - K) + rw [neg_sub] at hx + linear_combination -D * hx + have hfwd' : Integrable (fun ω ↦ D * S ω - D * K) Q := hfwd.sub (integrable_const _) + rw [integral_congr_ae (ae_of_all _ hpar), integral_sub hcall hfwd', + integral_sub hfwd (integrable_const (D * K)), integral_const, probReal_univ, one_smul] + ring + +namespace JumpDiffusionHyp + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} {Λ : ℝ≥0} {Z : Ω → ℝ} + {N : Ω → ℕ} {J : ℕ → Ω → ℝ} + +/-- **Merton's formula from the general jump-diffusion.** With log-jumps +`Jᵢ ∼ N(log(1 + k) − δ²/2, δ²)` and the compensator `κ = kΛ`, the call is Merton's series +`mertonCallPrice`. With `n` jumps the jump part is `N(n(log(1 + k) − δ²/2), nδ²)`, and Gaussian +smoothing of the Black–Scholes price gives the `n`-th term +(`integral_bsV_mul_exp_gaussianReal_of_sq`). -/ +theorem call_eq_mertonCallPrice (h : JumpDiffusionHyp Q Λ Z N J) {k δ : ℝ} (hk : -1 < k) + (hJ : HasLaw (J 0) (gaussianReal (Real.log (1 + k) - δ ^ 2 / 2) (δ ^ 2).toNNReal) Q) + {S_0 K r σ T : ℝ} (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + ∫ ω, rexp (-r * T) * max (jumpDiffusionTerminal S_0 r σ T (k * Λ) (Z ω) (N ω) + (fun i ↦ J i ω) - K) 0 ∂Q + = mertonCallPrice S_0 K r σ T k δ Λ := by + have hJexp : Integrable (fun ω ↦ rexp (J 0 ω)) Q := by + simpa only [one_mul] using hJ.integrable_fun_comp (integrable_exp_mul_gaussianReal 1) + have h1k : (0 : ℝ) < 1 + k := by linarith + rw [h.call_poisson_mixture hJexp hS_0 hK hσ hT (k * Λ), mertonCallPrice] + refine integral_congr_ae (ae_of_all _ fun n ↦ ?_) + -- with `n` jumps the jump part is Gaussian + have hsum : HasLaw (fun ω ↦ ∑ i ∈ Finset.range n, J i ω) + (gaussianReal (n * (Real.log (1 + k) - δ ^ 2 / 2)) (n * (δ ^ 2).toNNReal)) Q := + (hasLaw_sum_range_gaussianReal (fun i ↦ (h.J_ident i).symm.hasLaw hJ) h.J_indep n).congr + (ae_of_all _ fun ω ↦ (Finset.sum_apply ω _ _).symm) + have hvar : mertonVol σ δ T n ^ 2 * T = σ ^ 2 * T + ((n * (δ ^ 2).toNNReal : ℝ≥0) : ℝ) := by + rw [mertonVol_sq_mul σ δ hT n, NNReal.coe_mul, NNReal.coe_natCast, + Real.coe_toNNReal _ (sq_nonneg δ)] + have hbs : Measurable fun x ↦ bsV K r σ (S_0 * rexp (-(k * Λ)) * rexp x) T := + (measurable_bsV_spot K r σ T).comp (by fun_prop) + calc ∫ ω, bsV K r σ (S_0 * rexp (-(k * Λ) + ∑ i ∈ Finset.range n, J i ω)) T ∂Q + = ∫ ω, bsV K r σ (S_0 * rexp (-(k * Λ)) * rexp (∑ i ∈ Finset.range n, J i ω)) T ∂Q := by + simp only [Real.exp_add, mul_assoc] + _ = ∫ x, bsV K r σ (S_0 * rexp (-(k * Λ)) * rexp x) T + ∂(gaussianReal (n * (Real.log (1 + k) - δ ^ 2 / 2)) (n * (δ ^ 2).toNNReal)) := + hsum.integral_comp hbs.aestronglyMeasurable + _ = bsV K r (mertonVol σ δ T n) (S_0 * rexp (-(k * Λ)) + * rexp (n * (Real.log (1 + k) - δ ^ 2 / 2) + ((n * (δ ^ 2).toNNReal : ℝ≥0) : ℝ) / 2)) + T := + integral_bsV_mul_exp_gaussianReal_of_sq (mul_pos hS_0 (Real.exp_pos _)) hK hσ + (mertonVol_pos hσ hT n) hT _ hvar + _ = mertonCallTerm S_0 K r σ T k δ Λ n := by + rw [mertonCallTerm_eq_bsV, mertonSpot, NNReal.coe_mul, NNReal.coe_natCast, + Real.coe_toNNReal _ (sq_nonneg δ), + show (n : ℝ) * (Real.log (1 + k) - δ ^ 2 / 2) + n * δ ^ 2 / 2 = n * Real.log (1 + k) + by ring, + Real.exp_nat_mul, Real.exp_log h1k] + +/-- The discounted terminal price at the compensator `kΛ`, with Merton's Gaussian log-jumps, has +mean `S₀`: `𝔼[e^J] = 1 + k` (`integral_exp_mertonJump`), so the compensator of +`discounted_terminal_eq_iff` is `Λ(𝔼[e^J] − 1) = kΛ`. -/ +theorem discounted_terminal_merton (h : JumpDiffusionHyp Q Λ Z N J) {k δ : ℝ} (hk : -1 < k) + (hJ : HasLaw (J 0) (gaussianReal (Real.log (1 + k) - δ ^ 2 / 2) (δ ^ 2).toNNReal) Q) + (S_0 r σ : ℝ) {T : ℝ} (hT : 0 ≤ T) : + ∫ ω, rexp (-r * T) * jumpDiffusionTerminal S_0 r σ T (k * Λ) (Z ω) (N ω) + (fun i ↦ J i ω) ∂Q = S_0 := by + have hJexp : Integrable (fun ω ↦ rexp (J 0 ω)) Q := by + simpa only [one_mul] using hJ.integrable_fun_comp (integrable_exp_mul_gaussianReal 1) + have hmean : ∫ ω, rexp (J 0 ω) ∂Q = 1 + k := + (hJ.integral_comp (f := rexp) measurable_exp.aestronglyMeasurable).trans + (integral_exp_mertonJump hk δ) + rw [h.discounted_terminal hJexp S_0 r σ hT (k * Λ), hmean, + show -(k * (Λ : ℝ)) + Λ * (1 + k - 1) = 0 by ring, Real.exp_zero, mul_one] + +/-- **Merton's put formula from the general jump-diffusion.** With log-jumps +`Jᵢ ∼ N(log(1 + k) − δ²/2, δ²)` and the compensator `κ = kΛ`, the put is Merton's series +`mertonPutPrice`: the put payoff is the call payoff minus the forward and plus the strike +(`max_zero_sub_max_neg_zero_eq_self`), so the put is the call (`call_eq_mertonCallPrice`) +minus the discounted forward `S₀` (`discounted_terminal_merton`) plus `Ke^{−rT}`, which is +`mertonPutPrice` by `merton_put_call_parity`. -/ +theorem put_eq_mertonPutPrice (h : JumpDiffusionHyp Q Λ Z N J) {k δ : ℝ} (hk : -1 < k) + (hJ : HasLaw (J 0) (gaussianReal (Real.log (1 + k) - δ ^ 2 / 2) (δ ^ 2).toNNReal) Q) + {S_0 K r σ T : ℝ} (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + ∫ ω, rexp (-r * T) * max (K - jumpDiffusionTerminal S_0 r σ T (k * Λ) (Z ω) (N ω) + (fun i ↦ J i ω)) 0 ∂Q = mertonPutPrice S_0 K r σ T k δ Λ := by + have := h.J_indep.isProbabilityMeasure + have hJexp : Integrable (fun ω ↦ rexp (J 0 ω)) Q := by + simpa only [one_mul] using hJ.integrable_fun_comp (integrable_exp_mul_gaussianReal 1) + have hS : Integrable (fun ω ↦ jumpDiffusionTerminal S_0 r σ T (k * Λ) (Z ω) (N ω) + (fun i ↦ J i ω)) Q := by + simp_rw [jumpDiffusionTerminal_eq] + exact integrable_jumpDiffusion_terminal h.Z_law (h.indepFun_jumpPart _) + (h.integrable_exp_jumpPart hJexp _) + have hparity := merton_put_call_parity (r := r) δ Λ hS_0 hK hσ hT hk + have hcall := h.call_eq_mertonCallPrice hk hJ hS_0 hK hσ hT (r := r) + have hfwd := h.discounted_terminal_merton hk hJ S_0 r σ hT.le + rw [integral_discounted_put_payoff hS, hcall, hfwd] + linarith + +end JumpDiffusionHyp + +/-- **Merton's 1976 formula for the call price function.** With log-jumps +`N(log(1 + k) − δ²/2, δ²)` and the compensated drift `b = r − σ²/2 − Λk`, the call price +function over a time `τ > 0` is Merton's series `mertonCallPrice` at the expected jump count +`Λτ`: the price function is the call of the canonical model with that expected jump count +(`jumpDiffusionCallPrice_eq_canonical`), with `𝔼[e^J] = 1 + k` +(`integral_exp_mertonJump`). -/ +theorem jumpDiffusionCallPrice_gaussian_eq_mertonCallPrice {S K r b σ k δ : ℝ} (hS : 0 < S) + (hK : 0 < K) (hσ : 0 < σ) (hk : -1 < k) {Λ : ℝ≥0} (hb : b = r - σ ^ 2 / 2 - Λ * k) + {τ : ℝ≥0} (hτ : 0 < τ) : + jumpDiffusionCallPrice S K r b σ Λ + (gaussianReal (Real.log (1 + k) - δ ^ 2 / 2) (δ ^ 2).toNNReal) τ + = mertonCallPrice S K r σ τ k δ (Λ * τ) := by + obtain ⟨h, hJ⟩ := jumpDiffusionHyp_canonical (Λ * τ) + (gaussianReal (Real.log (1 + k) - δ ^ 2 / 2) (δ ^ 2).toNNReal) + rw [jumpDiffusionCallPrice_eq_canonical S K (mertonJump_compensated hk δ hb) τ, + integral_exp_mertonJump hk δ, + show (Λ : ℝ) * τ * (1 + k - 1) = k * (Λ * τ : ℝ≥0) by push_cast; ring] + exact h.call_eq_mertonCallPrice hk (hJ 0) hS hK hσ (NNReal.coe_pos.2 hτ) + +/-- **Merton's 1976 put formula for the put price function.** With log-jumps +`N(log(1 + k) − δ²/2, δ²)` and the compensated drift `b = r − σ²/2 − Λk`, the put price function +over a time `τ > 0` is Merton's put series `mertonPutPrice` at the expected jump count `Λτ`: both +satisfy put–call parity with the same right side `S − Ke^{−rτ}` +(`jumpDiffusionCallPrice_eq_of_compensated`, `merton_put_call_parity`), and the calls agree. -/ +theorem jumpDiffusionPutPrice_gaussian_eq_mertonPutPrice {S K r b σ k δ : ℝ} (hS : 0 < S) + (hK : 0 < K) (hσ : 0 < σ) (hk : -1 < k) {Λ : ℝ≥0} (hb : b = r - σ ^ 2 / 2 - Λ * k) + {τ : ℝ≥0} (hτ : 0 < τ) : + jumpDiffusionPutPrice S K r b σ Λ + (gaussianReal (Real.log (1 + k) - δ ^ 2 / 2) (δ ^ 2).toNNReal) τ + = mertonPutPrice S K r σ τ k δ (Λ * τ) := by + have hpar := jumpDiffusionCallPrice_eq_of_compensated (S := S) (K := K) + (integrable_exp_gaussianReal _ _) (mertonJump_compensated hk δ hb) τ + rw [jumpDiffusionCallPrice_gaussian_eq_mertonCallPrice hS hK hσ hk hb hτ] at hpar + linarith [merton_put_call_parity (r := r) δ (Λ * τ) hS hK hσ (NNReal.coe_pos.2 hτ) hk] + +namespace JumpDiffusionProcess + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} {𝓕 : Filtration ℝ≥0 mΩ} + {X : ℝ≥0 → Ω → ℝ} {b σ : ℝ} {Λ : ℝ≥0} + +/-- **Merton's 1976 formula at every date before maturity.** In a jump-diffusion with log-jumps +`N(log(1 + k) − δ²/2, δ²)` at the compensated drift `b = r − σ²/2 − Λk`, for `t < T` the +conditional value of the call given `𝓕_t` is Merton's series `mertonCallPrice` at the current +price `S_t = S₀e^{X_t}`, the remaining maturity `T − t` and the expected number of jumps +`Λ(T − t)` (`condExp_call`, `jumpDiffusionCallPrice_gaussian_eq_mertonCallPrice`). -/ +theorem condExp_call_eq_mertonCallPrice {k δ : ℝ} + (h : JumpDiffusionProcess P 𝓕 X b σ Λ + (gaussianReal (Real.log (1 + k) - δ ^ 2 / 2) (δ ^ 2).toNNReal)) + (hk : -1 < k) {r : ℝ} (hb : b = r - σ ^ 2 / 2 - Λ * k) + {S_0 K : ℝ} (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) {t T : ℝ≥0} (htT : t < T) : + P[fun ω ↦ rexp (-r * (T - t : ℝ≥0)) * max (S_0 * rexp (X T ω) - K) 0 | 𝓕 t] + =ᵐ[P] fun ω ↦ mertonCallPrice (S_0 * rexp (X t ω)) K r σ (T - t : ℝ≥0) k δ + (Λ * (T - t)) := + (h.condExp_call (integrable_exp_gaussianReal _ _) S_0 K r htT.le).trans <| + ae_of_all _ fun _ ↦ jumpDiffusionCallPrice_gaussian_eq_mertonCallPrice + (mul_pos hS_0 (Real.exp_pos _)) hK hσ hk hb (tsub_pos_of_lt htT) + +/-- **Merton's 1976 put formula at every date before maturity.** Under the hypotheses of +`condExp_call_eq_mertonCallPrice`, the conditional value of the put given `𝓕_t` is Merton's put +series `mertonPutPrice` at `S_t`, `T − t` and `Λ(T − t)` (`condExp_put`, +`jumpDiffusionPutPrice_gaussian_eq_mertonPutPrice`). -/ +theorem condExp_put_eq_mertonPutPrice {k δ : ℝ} + (h : JumpDiffusionProcess P 𝓕 X b σ Λ + (gaussianReal (Real.log (1 + k) - δ ^ 2 / 2) (δ ^ 2).toNNReal)) + (hk : -1 < k) {r : ℝ} (hb : b = r - σ ^ 2 / 2 - Λ * k) + {S_0 K : ℝ} (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) {t T : ℝ≥0} (htT : t < T) : + P[fun ω ↦ rexp (-r * (T - t : ℝ≥0)) * max (K - S_0 * rexp (X T ω)) 0 | 𝓕 t] + =ᵐ[P] fun ω ↦ mertonPutPrice (S_0 * rexp (X t ω)) K r σ (T - t : ℝ≥0) k δ + (Λ * (T - t)) := + have := h.isProbabilityMeasure + (h.condExp_put hS_0.le K r htT.le).trans <| + ae_of_all _ fun _ ↦ jumpDiffusionPutPrice_gaussian_eq_mertonPutPrice + (mul_pos hS_0 (Real.exp_pos _)) hK hσ hk hb (tsub_pos_of_lt htT) + +end JumpDiffusionProcess + +end MathFin diff --git a/LeanPool/MathFin/Models/Jumps/JumpDiffusionMixing.lean b/LeanPool/MathFin/Models/Jumps/JumpDiffusionMixing.lean new file mode 100644 index 0000000000..cddbb31184 --- /dev/null +++ b/LeanPool/MathFin/Models/Jumps/JumpDiffusionMixing.lean @@ -0,0 +1,429 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Jumps.CompoundPoissonMGF +public import LeanPool.MathFin.Models.BlackScholes.Forward +public import LeanPool.MathFin.Models.ModelFree.PriceBounds +public import LeanPool.MathFin.Models.BlackScholes.SpotConvexity +public import LeanPool.MathFin.Probability.Analysis.AffineMinorant +public import LeanPool.MathFin.Probability.Gaussian.NormalQuantile + +/-! +# Jump-diffusions with an arbitrary jump law + +Merton's jump-diffusion (`Models/Jumps/MertonJumpDiffusion.lean`) has Gaussian log-jumps, so that +with `n` jumps the terminal price is again a Black–Scholes terminal price. This file allows any +jump law. Under a probability measure `Q` the terminal price is + + `S_T = S₀ · exp((r − σ²/2)T − κ + σ√T·Z + ∑_{i 0` and a jump law + other than `δ₀`, `C(S, τ)` has a unique Black–Scholes implied volatility, above `σ`. +* `JumpDiffusionProcess.condExp_put`: `𝔼[e^{−r(T−t)}(K − S_T)⁺ | 𝓕_t] = P(S_t, T − t)`, for + `S₀ ≥ 0`. +* `JumpDiffusionProcess.condExp_call`: `𝔼[e^{−r(T−t)}(S_T − K)⁺ | 𝓕_t] = C(S_t, T − t)`, for + `𝔼[e^J] < ∞`. +* `JumpDiffusionProcess.condExp_call_eq_merton`: at the compensated drift and for `t < T`, the + conditional call value is Merton's formula at `S_t` and `T − t`. +* `JumpDiffusionProcess.condExp_call_impliedVol_gt`: under the same hypotheses as + `jumpDiffusionCallPrice_impliedVol_gt`, the conditional call value has, almost surely, a unique + implied volatility at `S_t` and `T − t`, above `σ`. + +## References + +* [Cont and Tankov, *Financial Modelling with Jump Processes*][ContTankov2004] +* [R. C. Merton, *Option pricing when underlying stock returns are discontinuous*][Merton1976] + +## Tags + +conditional expectation, Markov property, freezing lemma, option price at intermediate date, +jump-diffusion, MSC 91G20, MSC 60G51, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal + +/-- The jump-diffusion put price function: the discounted expected payoff `e^{−rτ}(K − Se^Y)⁺` +over a time `τ`, with `Y` a jump-diffusion log-return over `τ` (`jumpDiffusionIncrementLaw`). It +is an arbitrage-free price only at the compensated drift, where the discounted price is a +martingale (`JumpDiffusionProcess.martingale_iff`). -/ +noncomputable def jumpDiffusionPutPrice (S K r b σ : ℝ) (Λ : ℝ≥0) (ν : Measure ℝ) (τ : ℝ≥0) : + ℝ := + ∫ y, rexp (-r * τ) * max (K - S * rexp y) 0 ∂(jumpDiffusionIncrementLaw b σ Λ ν τ) + +/-- The jump-diffusion call price function: the discounted expected payoff `e^{−rτ}(Se^Y − K)⁺` +over a time `τ`, with `Y` a jump-diffusion log-return over `τ`. Like the put's, it is an +arbitrage-free price only at the compensated drift. -/ +noncomputable def jumpDiffusionCallPrice (S K r b σ : ℝ) (Λ : ℝ≥0) (ν : Measure ℝ) (τ : ℝ≥0) : + ℝ := + ∫ y, rexp (-r * τ) * max (S * rexp y - K) 0 ∂(jumpDiffusionIncrementLaw b σ Λ ν τ) + +/-- **Put–call parity for the price functions**: +`C(S, τ) = P(S, τ) + S·e^{(b + σ²/2 + Λ(𝔼[e^J] − 1) − r)τ} − Ke^{−rτ}`. The forward +`e^{−rτ}Se^Y` has mean `S·e^{(b + σ²/2 + Λ(𝔼[e^J] − 1) − r)τ}` +(`integral_exp_jumpDiffusionIncrementLaw`), which is `S` at the compensated drift; pointwise, the +call payoff is the put payoff plus the forward (`max_zero_sub_max_neg_zero_eq_self`). -/ +theorem jumpDiffusionCallPrice_eq (S K r b σ : ℝ) (Λ : ℝ≥0) {ν : Measure ℝ} + [IsProbabilityMeasure ν] (hν : Integrable rexp ν) (τ : ℝ≥0) : + jumpDiffusionCallPrice S K r b σ Λ ν τ + = jumpDiffusionPutPrice S K r b σ Λ ν τ + + S * rexp ((b + σ ^ 2 / 2 + Λ * (∫ x, rexp x ∂ν - 1) - r) * τ) + - K * rexp (-r * τ) := by + have hexp := integrable_exp_jumpDiffusionIncrementLaw b σ Λ hν τ + have hput : Integrable (fun y ↦ rexp (-r * τ) * max (K - S * rexp y) 0) + (jumpDiffusionIncrementLaw b σ Λ ν τ) := + ((integrable_const K).sub (hexp.const_mul S)).pos_part.const_mul _ + have hfwd : Integrable (fun y ↦ rexp (-r * τ) * (S * rexp y)) + (jumpDiffusionIncrementLaw b σ Λ ν τ) := + (hexp.const_mul S).const_mul _ + have hdiff : Integrable (fun y ↦ rexp (-r * τ) * (S * rexp y) - rexp (-r * τ) * K) + (jumpDiffusionIncrementLaw b σ Λ ν τ) := + hfwd.sub (integrable_const _) + have hfwdI : ∫ y, rexp (-r * τ) * (S * rexp y) ∂(jumpDiffusionIncrementLaw b σ Λ ν τ) + = S * rexp ((b + σ ^ 2 / 2 + Λ * (∫ x, rexp x ∂ν - 1) - r) * τ) := by + rw [integral_const_mul, integral_const_mul, + integral_exp_jumpDiffusionIncrementLaw b σ Λ hν τ, mul_left_comm, ← Real.exp_add] + congr 2 + ring + -- the call payoff is the put payoff plus the forward + have hpar (y : ℝ) : rexp (-r * τ) * max (S * rexp y - K) 0 + = rexp (-r * τ) * max (K - S * rexp y) 0 + + (rexp (-r * τ) * (S * rexp y) - rexp (-r * τ) * K) := by + have hx := max_zero_sub_max_neg_zero_eq_self (S * rexp y - K) + rw [neg_sub] at hx + linear_combination rexp (-r * τ) * hx + rw [jumpDiffusionCallPrice, jumpDiffusionPutPrice, integral_congr_ae (ae_of_all _ hpar), + integral_add hput hdiff, integral_sub hfwd (integrable_const _), hfwdI, integral_const, + probReal_univ, one_smul] + ring + +/-- **Put–call parity at the compensated drift**: when `b = r − σ²/2 − Λ(𝔼[e^J] − 1)` the +forward is worth `S`, and `C(S, τ) = P(S, τ) + S − Ke^{−rτ}`. -/ +theorem jumpDiffusionCallPrice_eq_of_compensated {S K r b σ : ℝ} {Λ : ℝ≥0} {ν : Measure ℝ} + [IsProbabilityMeasure ν] (hν : Integrable rexp ν) + (hb : b = r - σ ^ 2 / 2 - Λ * (∫ x, rexp x ∂ν - 1)) (τ : ℝ≥0) : + jumpDiffusionCallPrice S K r b σ Λ ν τ + = jumpDiffusionPutPrice S K r b σ Λ ν τ + S - K * rexp (-r * τ) := by + have h0 : (b + σ ^ 2 / 2 + Λ * (∫ x, rexp x ∂ν - 1) - r) * τ = 0 := by + rw [hb] + ring + rw [jumpDiffusionCallPrice_eq S K r b σ Λ hν τ, h0, Real.exp_zero, mul_one] + +/-- At the compensated drift the call price function is the call of the canonical model with +expected jump count `Λτ`: the log-return over `τ` (`jumpDiffusionLogReturn`) is the exponent of +`jumpDiffusionTerminal` with the compensator `κ = Λτ(𝔼[e^J] − 1)`. -/ +lemma jumpDiffusionCallPrice_eq_canonical (S K : ℝ) {r b σ : ℝ} {Λ : ℝ≥0} {ν : Measure ℝ} + (hb : b = r - σ ^ 2 / 2 - Λ * (∫ x, rexp x ∂ν - 1)) (τ : ℝ≥0) : + jumpDiffusionCallPrice S K r b σ Λ ν τ + = ∫ ω, rexp (-r * τ) * max (jumpDiffusionTerminal S r σ τ (Λ * τ * (∫ x, rexp x ∂ν - 1)) + ω.1 ω.2.1 (fun i ↦ ω.2.2 i) - K) 0 ∂(jumpDiffusionMeasure (Λ * τ) ν) := by + have hf : Measurable fun y : ℝ ↦ rexp (-r * τ) * max (S * rexp y - K) 0 := by fun_prop + rw [jumpDiffusionCallPrice, jumpDiffusionIncrementLaw, + integral_map (measurable_jumpDiffusionLogReturn b σ τ).aemeasurable hf.aestronglyMeasurable] + refine integral_congr_ae (ae_of_all _ fun ω ↦ ?_) + have hE : jumpDiffusionLogReturn b σ τ ω = (r - σ ^ 2 / 2) * τ - Λ * τ * (∫ x, rexp x ∂ν - 1) + + σ * Real.sqrt τ * ω.1 + ∑ i ∈ Finset.range ω.2.1, ω.2.2 i := by + rw [jumpDiffusionLogReturn, hb] + ring + simp only [hE, jumpDiffusionTerminal] + +/-- **Merton's formula for the call price function.** At the compensated drift +`b = r − σ²/2 − Λ(𝔼[e^J] − 1)`, the call price function is Merton's formula for the jump law `ν`: +the `Poisson(Λτ)` mixture, over the jump count `n`, of the Black–Scholes price at the spot +`Se^{−Λτ(𝔼[e^J] − 1) + ∑_{i 0`, `τ > 0`) and move the price (the jump law is not the point mass at `0`), +the call price function `C(S, τ)` is the Black–Scholes price at exactly one positive volatility, +and that volatility is above `σ`: `JumpDiffusionHyp.impliedVol_gt` on the canonical model with +expected jump count `Λτ`. -/ +theorem jumpDiffusionCallPrice_impliedVol_gt {S K r b σ : ℝ} (hS : 0 < S) (hK : 0 < K) + (hσ : 0 < σ) {Λ : ℝ≥0} (hΛ : 0 < Λ) {ν : Measure ℝ} [IsProbabilityMeasure ν] + (hν : Integrable rexp ν) (hν0 : ν ≠ Measure.dirac 0) + (hb : b = r - σ ^ 2 / 2 - Λ * (∫ x, rexp x ∂ν - 1)) {τ : ℝ≥0} (hτ : 0 < τ) : + ∃ σ_imp, σ < σ_imp ∧ bsV K r σ_imp S τ = jumpDiffusionCallPrice S K r b σ Λ ν τ ∧ + ∀ σ' > 0, bsV K r σ' S τ = jumpDiffusionCallPrice S K r b σ Λ ν τ → σ' = σ_imp := by + obtain ⟨h, hJ⟩ := jumpDiffusionHyp_canonical (Λ * τ) ν + -- the jumps move the price: the first jump size is not almost surely `0` + have hJ0 : ¬(fun ω : ℝ × ℕ × (ℕ → ℝ) ↦ ω.2.2 0) =ᵐ[jumpDiffusionMeasure (Λ * τ) ν] 0 := + fun h0 ↦ hν0 ((hJ 0).map_eq.symm.trans (hasLaw_dirac_of_ae_eq (x := 0) h0).map_eq) + have hcall : jumpDiffusionCallPrice S K r b σ Λ ν τ + = ∫ ω, rexp (-r * τ) * max (jumpDiffusionTerminal S r σ τ + ((Λ * τ : ℝ≥0) * (∫ ω', rexp (ω'.2.2 0) ∂(jumpDiffusionMeasure (Λ * τ) ν) - 1)) + ω.1 ω.2.1 (fun i ↦ ω.2.2 i) - K) 0 ∂(jumpDiffusionMeasure (Λ * τ) ν) := by + rw [jumpDiffusionCallPrice_eq_canonical S K hb τ, integral_exp_canonical_jump (Λ * τ) ν, + NNReal.coe_mul] + rw [hcall] + exact h.impliedVol_gt (integrable_exp_canonical_jump hν) (mul_pos hΛ hτ) hJ0 hS hK hσ + (NNReal.coe_pos.2 hτ) + +namespace JumpDiffusionProcess + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} {𝓕 : Filtration ℝ≥0 mΩ} + {X : ℝ≥0 → Ω → ℝ} {b σ : ℝ} {Λ : ℝ≥0} {ν : Measure ℝ} + +/-- **Payoffs of the current state and the increment.** Given `𝓕_t`, a payoff +`g(X_t, X_T − X_t)` at `T ≥ t`, with values in any Banach space, `g` strongly measurable and the +payoff integrable, has conditional expectation `∫ g(X_t, y) dμ(y)`, with `μ` the log-return law +over the remaining time `T − t` (`jumpDiffusionIncrementLaw`): the conditional freezing lemma +(`condExp_comp_prodMk_of_indep`) on the process, since `X_t` is known at `t` and the increment is +independent of `𝓕_t` with law `μ`. A payoff of the increment alone is a forward-start payoff. -/ +theorem condExp_comp_prodMk {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [CompleteSpace E] (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) [IsFiniteMeasure P] + {g : ℝ × ℝ → E} (hg : StronglyMeasurable g) {t T : ℝ≥0} (htT : t ≤ T) + (hgi : Integrable (fun ω ↦ g (X t ω, X T ω - X t ω)) P) : + P[fun ω ↦ g (X t ω, X T ω - X t ω) | 𝓕 t] + =ᵐ[P] fun ω ↦ ∫ y, g (X t ω, y) ∂(jumpDiffusionIncrementLaw b σ Λ ν (T - t)) := by + rw [← (h.law t T htT).map_eq] + exact condExp_comp_prodMk_of_indep (𝓕.le t) (h.adapted t).measurable + (h.law t T htT).aemeasurable (h.indep t T htT) hg hgi + +/-- **European payoffs at intermediate dates.** Given `𝓕_t`, a payoff `f(X_T)` at `T ≥ t`, with +`f` measurable and `f(X_T)` integrable, has conditional expectation `F(X_t)`, where +`F(x) = ∫ f(x + y) dμ(y)` averages over the log-return law `μ` over the remaining time `T − t` +(`jumpDiffusionIncrementLaw`): the case `g(x, y) = f(x + y)` of `condExp_comp_prodMk`. -/ +theorem condExp_comp (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) [IsFiniteMeasure P] {f : ℝ → ℝ} + (hf : Measurable f) {t T : ℝ≥0} (htT : t ≤ T) (hfi : Integrable (fun ω ↦ f (X T ω)) P) : + P[fun ω ↦ f (X T ω) | 𝓕 t] + =ᵐ[P] fun ω ↦ ∫ y, f (X t ω + y) ∂(jumpDiffusionIncrementLaw b σ Λ ν (T - t)) := by + simpa only [add_sub_cancel] using h.condExp_comp_prodMk (g := fun z : ℝ × ℝ ↦ f (z.1 + z.2)) + (hf.comp measurable_add).stronglyMeasurable htT (by simpa only [add_sub_cancel] using hfi) + +/-- **The put at an intermediate date.** Given `𝓕_t`, the discounted put payoff at `T` has +conditional expectation `P(S_t, T − t)`, the put price function at the current price and the +remaining maturity (`condExp_comp`). For `S₀ ≥ 0` the payoff is bounded by +`e^{−r(T−t)}·max K 0`, so no moment of the jumps is needed. -/ +theorem condExp_put (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) [IsFiniteMeasure P] {S_0 : ℝ} + (hS_0 : 0 ≤ S_0) (K r : ℝ) {t T : ℝ≥0} (htT : t ≤ T) : + P[fun ω ↦ rexp (-r * (T - t : ℝ≥0)) * max (K - S_0 * rexp (X T ω)) 0 | 𝓕 t] + =ᵐ[P] fun ω ↦ jumpDiffusionPutPrice (S_0 * rexp (X t ω)) K r b σ Λ ν (T - t) := by + have hf : Measurable fun x ↦ rexp (-r * (T - t : ℝ≥0)) * max (K - S_0 * rexp x) 0 := by + fun_prop + have hbd (x : ℝ) : ‖rexp (-r * (T - t : ℝ≥0)) * max (K - S_0 * rexp x) 0‖ + ≤ rexp (-r * (T - t : ℝ≥0)) * max K 0 := by + rw [Real.norm_of_nonneg (mul_nonneg (Real.exp_pos _).le (le_max_right _ _))] + exact mul_le_mul_of_nonneg_left + (max_le_max (sub_le_self K (mul_nonneg hS_0 (Real.exp_pos x).le)) le_rfl) + (Real.exp_pos _).le + refine (h.condExp_comp hf htT <| (integrable_const _).mono' + (hf.comp ((h.adapted T).mono (𝓕.le T)).measurable).aestronglyMeasurable + (ae_of_all _ fun ω ↦ hbd (X T ω))).trans (ae_of_all _ fun ω ↦ ?_) + simp only [jumpDiffusionPutPrice, Real.exp_add, mul_assoc] + +/-- **The call at an intermediate date.** Given `𝓕_t`, the discounted call payoff at `T` has +conditional expectation `C(S_t, T − t)`, the call price function at the current price and the +remaining maturity (`condExp_comp`). The payoff is integrable because `e^{X_T}` is, which needs +`𝔼[e^J] < ∞` under the jump law. -/ +theorem condExp_call (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) [IsProbabilityMeasure ν] + (hν : Integrable rexp ν) (S_0 K r : ℝ) {t T : ℝ≥0} (htT : t ≤ T) : + P[fun ω ↦ rexp (-r * (T - t : ℝ≥0)) * max (S_0 * rexp (X T ω) - K) 0 | 𝓕 t] + =ᵐ[P] fun ω ↦ jumpDiffusionCallPrice (S_0 * rexp (X t ω)) K r b σ Λ ν (T - t) := by + have := h.isProbabilityMeasure + refine (h.condExp_comp (f := fun x ↦ rexp (-r * (T - t : ℝ≥0)) * max (S_0 * rexp x - K) 0) + (by fun_prop) htT ((((h.integrable_exp hν T).const_mul S_0).sub + (integrable_const K)).pos_part.const_mul _)).trans (ae_of_all _ fun ω ↦ ?_) + simp only [jumpDiffusionCallPrice, Real.exp_add, mul_assoc] + +/-- **Merton's formula at intermediate dates.** At the compensated drift +`b = r − σ²/2 − Λ(𝔼[e^J] − 1)` and for `t < T`, the discounted call payoff at `T` has conditional +expectation given `𝓕_t` equal to Merton's formula for the jump law `ν` at the current price +`S_t = S₀e^{X_t}` and the remaining maturity `T − t` (`condExp_call`, +`jumpDiffusionCallPrice_eq_merton`). -/ +theorem condExp_call_eq_merton (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) + [IsProbabilityMeasure ν] (hν : Integrable rexp ν) {r : ℝ} + (hb : b = r - σ ^ 2 / 2 - Λ * (∫ x, rexp x ∂ν - 1)) {S_0 K : ℝ} (hS_0 : 0 < S_0) + (hK : 0 < K) (hσ : 0 < σ) {t T : ℝ≥0} (htT : t < T) : + P[fun ω ↦ rexp (-r * (T - t : ℝ≥0)) * max (S_0 * rexp (X T ω) - K) 0 | 𝓕 t] + =ᵐ[P] fun ω ↦ ∫ n, ∫ j, bsV K r σ (S_0 * rexp (X t ω) + * rexp (-(Λ * (T - t : ℝ≥0) * (∫ x, rexp x ∂ν - 1)) + ∑ i ∈ Finset.range n, j i)) + (T - t : ℝ≥0) ∂(Measure.infinitePi fun _ : ℕ ↦ ν) ∂(poissonMeasure (Λ * (T - t))) := + (h.condExp_call hν S_0 K r htT.le).trans <| ae_of_all _ fun _ ↦ + jumpDiffusionCallPrice_eq_merton (mul_pos hS_0 (Real.exp_pos _)) hK hσ hν hb + (tsub_pos_of_lt htT) + +/-- **Jumps lift the implied volatility at every date before maturity.** At the compensated drift, +if jumps occur (`Λ > 0`) and move the price (the jump law is not the point mass at `0`), then for +`t < T`, almost surely, the conditional value of the call given `𝓕_t` is the Black–Scholes price, +at the current price `S_t` and the remaining maturity `T − t`, of exactly one positive volatility, +and that volatility is above `σ` (`condExp_call`, `jumpDiffusionCallPrice_impliedVol_gt`). -/ +theorem condExp_call_impliedVol_gt (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) + [IsProbabilityMeasure ν] (hν : Integrable rexp ν) + (hν0 : ν ≠ Measure.dirac 0) (hΛ : 0 < Λ) {r : ℝ} + (hb : b = r - σ ^ 2 / 2 - Λ * (∫ x, rexp x ∂ν - 1)) {S_0 K : ℝ} (hS_0 : 0 < S_0) + (hK : 0 < K) (hσ : 0 < σ) {t T : ℝ≥0} (htT : t < T) : + ∀ᵐ ω ∂P, ∃ σ_imp, σ < σ_imp ∧ bsV K r σ_imp (S_0 * rexp (X t ω)) (T - t : ℝ≥0) + = P[fun ω' ↦ rexp (-r * (T - t : ℝ≥0)) * max (S_0 * rexp (X T ω') - K) 0 | 𝓕 t] ω ∧ + ∀ σ' > 0, bsV K r σ' (S_0 * rexp (X t ω)) (T - t : ℝ≥0) + = P[fun ω' ↦ rexp (-r * (T - t : ℝ≥0)) * max (S_0 * rexp (X T ω') - K) 0 | 𝓕 t] ω → + σ' = σ_imp := by + filter_upwards [h.condExp_call hν S_0 K r htT.le] with ω hω + obtain ⟨σ_imp, hlt, heq, huniq⟩ := jumpDiffusionCallPrice_impliedVol_gt + (mul_pos hS_0 (Real.exp_pos (X t ω))) hK hσ hΛ hν hν0 hb (tsub_pos_of_lt htT) + exact ⟨σ_imp, hlt, heq.trans hω.symm, fun σ' hσ' h' ↦ huniq σ' hσ' (h'.trans hω)⟩ + +end JumpDiffusionProcess + +end MathFin diff --git a/LeanPool/MathFin/Models/Jumps/JumpDiffusionProcess.lean b/LeanPool/MathFin/Models/Jumps/JumpDiffusionProcess.lean new file mode 100644 index 0000000000..79d51e2f9a --- /dev/null +++ b/LeanPool/MathFin/Models/Jumps/JumpDiffusionProcess.lean @@ -0,0 +1,395 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionCanonical +public import LeanPool.MathFin.Probability.Jumps.ExpMartingaleIndepIncrements + +/-! +# The jump-diffusion price process + +The other jump-diffusion files model only the price at maturity. Here the log-price is a process +`X` on `[0, ∞)`, adapted to a filtration `𝓕`, starting at `0`, whose increment `X_t − X_s` over +`[s, t]` is independent of `𝓕_s` and has the law of a jump-diffusion log-return over `t − s`: a +drift `b(t − s)`, a Gaussian part of variance `σ²(t − s)` and a compound-Poisson part with +`Poisson(Λ(t − s))` jumps of law `ν` (`JumpDiffusionProcess`); here `Λ` is a jump rate. The +increments are those of a Lévy process with these characteristics; no path regularity is assumed. +Without jumps, Brownian motion with drift is such a process +(`IsFilteredPreBrownian.jumpDiffusionProcess`); with jumps its existence is not proved. + +The log-return over `τ` has the moment-generating function `e^{κ(θ)τ}` at every `θ` with +`∫ e^{θx} dν < ∞`, where `κ(θ) = bθ + σ²θ²/2 + Λ(∫ e^{θx} dν − 1)` is the Laplace exponent +(`jumpDiffusionExponent`). On the canonical model it is the Gaussian moment-generating function +times the compound-Poisson one (`JumpDiffusionHyp.mgf_logReturn`, `compoundPoisson_mgf_of_indepFun` +from `Probability/Jumps/CompoundPoissonMGF.lean`), by independence; in Mathlib's terms `κ(θ)τ` is +the cumulant generating function (`cgf_id_jumpDiffusionIncrementLaw`). + +The price `S_t = S₀e^{X_t}` discounted at the rate `r` is a martingale exactly at the compensated +drift `b = r − σ²/2 − Λ(𝔼[e^J] − 1)` (`JumpDiffusionProcess.martingale_iff`). The increment's +exponential moment is `e^{(b + σ²/2 + Λ(𝔼[e^J] − 1))(t − s)}` +(`integral_exp_jumpDiffusionIncrementLaw`, the case `θ = 1`), so the exponential martingale of +independent increments (`martingale_exp_sub_of_indep_increments`) gives the "if"; conversely a +martingale has constant mean, and the mean at time `1` is `S₀e^{b + σ²/2 + Λ(𝔼[e^J] − 1) − r}`. + +## Main definitions + +* `jumpDiffusionLogReturn`: the log-return over a time `τ` on the canonical space + `ℝ × ℕ × (ℕ → ℝ)`, built from the drift `bτ`, the Gaussian part `σ√τ·ω₁` and the jumps. +* `jumpDiffusionIncrementLaw`: the law of that log-return over `τ`, with drift `b`, volatility `σ`, + jump rate `Λ` and jump law `ν`. +* `jumpDiffusionExponent`: the Laplace exponent `κ(θ) = bθ + σ²θ²/2 + Λ(∫ e^{θx} dν − 1)`. +* `JumpDiffusionProcess`: a log-price process adapted to a filtration, starting at `0`, whose + increment over `[s, t]` is independent of `𝓕_s` and has the jump-diffusion log-return law over + `t − s`. + +## Main results + +* `integral_exp_const_mul_jumpDiffusionIncrementLaw`, `mgf_id_jumpDiffusionIncrementLaw`, + `cgf_id_jumpDiffusionIncrementLaw`: for `θ` with `∫ e^{θx} dν < ∞`, its moment-generating + function is `e^{κ(θ)τ}`. +* `integrableExpSet_id_subset_jumpDiffusionIncrementLaw`, + `zero_mem_interior_integrableExpSet_jumpDiffusionIncrementLaw`, + `cgf_id_jumpDiffusionIncrementLaw_eventuallyEq`: the jumps' exponential moments pass to the + log-return, and near `0` its cumulant generating function is `κ(θ)τ`. +* `hasDerivAt_jumpDiffusionExponent`: `κ'(θ) = b + σ²θ + ΛM'(θ)`, with `M` the jump law's + moment-generating function. +* `integral_exp_jumpDiffusionIncrementLaw_of_compensated`: at the compensated drift the forward is + the mean, `∫ eʸ = e^{rτ}`. +* `JumpDiffusionProcess.hasLaw`: `X_t` has the log-return law over `t`. +* `JumpDiffusionProcess.martingale_iff`: for `S₀ ≠ 0` and integrable `e^J`, the discounted price + is a martingale if and only if the drift is compensated, `b = r − σ²/2 − Λ(𝔼[e^J] − 1)`. + +## References + +* [Cont and Tankov, *Financial Modelling with Jump Processes*][ContTankov2004] +* [R. C. Merton, *Option pricing when underlying stock returns are discontinuous*][Merton1976] + +## Tags + +jump-diffusion process, independent increments, Lévy process, filtered log-price, Merton model, +MSC 60G51, MSC 91G20 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal + +/-! ### The increment law -/ + +namespace JumpDiffusionHyp + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} {Λ : ℝ≥0} {Z : Ω → ℝ} + {N : Ω → ℕ} {J : ℕ → Ω → ℝ} + +/-- **The moment-generating function of a jump-diffusion log-return.** For `θ` with +`𝔼[e^{θJ}] < ∞`, `𝔼[e^{θ(bT + σ√T·Z + ∑_{i intro h <;> linarith + +/-! ### The process -/ + +/-- **A jump-diffusion log-price process.** `X` is adapted to the filtration `𝓕`, starts at `0`, +and each increment `X_t − X_s` (`s ≤ t`) is independent of `𝓕_s` and has the law of a +jump-diffusion log-return over `t − s` (`jumpDiffusionIncrementLaw`): drift `b(t − s)`, a +Gaussian part of variance `σ²(t − s)`, and a compound-Poisson part with `Poisson(Λ(t − s))` jumps +of law `ν`. The price is `S_t = S₀e^{X_t}`. The structure is a hypothesis: it is satisfied +without jumps (`IsFilteredPreBrownian.jumpDiffusionProcess`), and its existence with jumps is not +proved. -/ +structure JumpDiffusionProcess {Ω : Type*} {mΩ : MeasurableSpace Ω} (P : Measure Ω) + (𝓕 : Filtration ℝ≥0 mΩ) (X : ℝ≥0 → Ω → ℝ) (b σ : ℝ) (Λ : ℝ≥0) (ν : Measure ℝ) : Prop where + adapted : StronglyAdapted 𝓕 X + zero : ∀ᵐ ω ∂P, X 0 ω = 0 + indep : ∀ s t, s ≤ t → + Indep (MeasurableSpace.comap (fun ω ↦ X t ω - X s ω) inferInstance) (𝓕 s) P + law : ∀ s t, s ≤ t → + HasLaw (fun ω ↦ X t ω - X s ω) (jumpDiffusionIncrementLaw b σ Λ ν (t - s)) P + +namespace JumpDiffusionProcess + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} {𝓕 : Filtration ℝ≥0 mΩ} + {X : ℝ≥0 → Ω → ℝ} {b σ : ℝ} {Λ : ℝ≥0} {ν : Measure ℝ} + +/-- A jump-diffusion lives on a probability space: the law of each increment is a probability +measure. -/ +lemma isProbabilityMeasure (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) [IsProbabilityMeasure ν] : + IsProbabilityMeasure P := + (h.law 0 0 le_rfl).isProbabilityMeasure + +/-- The increment over `[s, t]` has exponential moment +`e^{(b + σ²/2 + Λ(𝔼[e^J] − 1))(t − s)}`. -/ +lemma integral_exp_increment (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) [IsProbabilityMeasure ν] + (hν : Integrable rexp ν) {s t : ℝ≥0} (hst : s ≤ t) : + ∫ ω, rexp (X t ω - X s ω) ∂P + = rexp ((b + σ ^ 2 / 2 + Λ * (∫ x, rexp x ∂ν - 1)) * (t - s : ℝ≥0)) := by + rw [← integral_exp_jumpDiffusionIncrementLaw b σ Λ hν (t - s)] + exact (h.law s t hst).integral_comp measurable_exp.aestronglyMeasurable + +/-- **The law of `X_t`** is the log-return law over `t`: `X_t = X_t − X_0` almost surely. -/ +lemma hasLaw (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) (t : ℝ≥0) : + HasLaw (X t) (jumpDiffusionIncrementLaw b σ Λ ν t) P := by + have h0 := h.law 0 t (zero_le : (0 : ℝ≥0) ≤ t) + rw [tsub_zero] at h0 + refine h0.congr ?_ + filter_upwards [h.zero] with ω hω + rw [hω, sub_zero] + +/-- `𝔼[e^{X_t}] = e^{(b + σ²/2 + Λ(𝔼[e^J] − 1))t}`, the exponential moment of the law of `X_t` +(`hasLaw`). -/ +lemma integral_exp (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) [IsProbabilityMeasure ν] + (hν : Integrable rexp ν) (t : ℝ≥0) : + ∫ ω, rexp (X t ω) ∂P = rexp ((b + σ ^ 2 / 2 + Λ * (∫ x, rexp x ∂ν - 1)) * t) := by + rw [← integral_exp_jumpDiffusionIncrementLaw b σ Λ hν t] + exact (h.hasLaw t).integral_comp measurable_exp.aestronglyMeasurable + +/-- `e^{X_t}` is integrable: its integral is positive (`integral_exp`). -/ +lemma integrable_exp (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) [IsProbabilityMeasure ν] + (hν : Integrable rexp ν) (t : ℝ≥0) : Integrable (fun ω ↦ rexp (X t ω)) P := + Integrable.of_integral_ne_zero (by rw [h.integral_exp hν t]; exact (Real.exp_pos _).ne') + +/-- **The discounted jump-diffusion price is a martingale exactly at the compensated drift.** For +a jump law with `𝔼[e^J] < ∞` and `S₀ ≠ 0`, `t ↦ e^{−rt}S₀e^{X_t}` is an `𝓕`-martingale if and +only if `b = r − σ²/2 − Λ(𝔼[e^J] − 1)`. -/ +theorem martingale_iff (h : JumpDiffusionProcess P 𝓕 X b σ Λ ν) [IsProbabilityMeasure ν] + (hν : Integrable rexp ν) {S_0 : ℝ} (hS_0 : S_0 ≠ 0) (r : ℝ) : + Martingale (fun (t : ℝ≥0) ω ↦ rexp (-r * t) * (S_0 * rexp (X t ω))) 𝓕 P ↔ + b = r - σ ^ 2 / 2 - Λ * (∫ x, rexp x ∂ν - 1) := by + have := h.isProbabilityMeasure + constructor + · -- a martingale has constant mean; at time `1` it is `S₀e^{b + σ²/2 + Λ(𝔼[e^J] − 1) − r}` + intro hM + have hmean : ∫ ω, rexp (-r * ((0 : ℝ≥0) : ℝ)) * (S_0 * rexp (X 0 ω)) ∂P + = ∫ ω, rexp (-r * ((1 : ℝ≥0) : ℝ)) * (S_0 * rexp (X 1 ω)) ∂P := + (integral_congr_ae (hM.condExp_ae_eq zero_le_one)).symm.trans (integral_condExp (𝓕.le 0)) + have h0 : ∫ ω, rexp (-r * ((0 : ℝ≥0) : ℝ)) * (S_0 * rexp (X 0 ω)) ∂P = S_0 := by + have hS : (fun ω ↦ rexp (-r * ((0 : ℝ≥0) : ℝ)) * (S_0 * rexp (X 0 ω))) =ᵐ[P] + fun _ ↦ S_0 := by + filter_upwards [h.zero] with ω hω + simp [hω] + rw [integral_congr_ae hS, integral_const, probReal_univ, one_smul] + have h1 : ∫ ω, rexp (-r * ((1 : ℝ≥0) : ℝ)) * (S_0 * rexp (X 1 ω)) ∂P + = S_0 * rexp (b + σ ^ 2 / 2 + Λ * (∫ x, rexp x ∂ν - 1) - r) := by + rw [integral_const_mul, integral_const_mul, h.integral_exp hν 1, mul_left_comm, + ← Real.exp_add, NNReal.coe_one] + congr 2 + ring + rw [h0, h1] at hmean + have := (Real.exp_eq_one_iff _).1 ((mul_eq_left₀ hS_0).1 hmean.symm) + linarith + · -- at the compensated drift the increment exponentials have mean `e^{r(t − s)}` + intro hb + have hfun : (fun (t : ℝ≥0) ω ↦ rexp (-r * t) * (S_0 * rexp (X t ω))) + = S_0 • fun (t : ℝ≥0) ω ↦ rexp (X t ω - r * t) := by + funext t ω + simp only [Pi.smul_apply, smul_eq_mul] + rw [mul_left_comm, ← Real.exp_add] + congr 2 + ring + rw [hfun] + refine Martingale.smul S_0 (martingale_exp_sub_of_indep_increments + (ψ := fun t : ℝ≥0 ↦ r * (t : ℝ)) h.adapted h.indep (h.integrable_exp hν) + fun s t hst ↦ ?_) + show ∫ ω, rexp (X t ω - X s ω) ∂P = rexp (r * t - r * s) + rw [h.integral_exp_increment hν hst, NNReal.coe_sub hst, hb] + congr 1 + ring + +end JumpDiffusionProcess + +end MathFin diff --git a/LeanPool/MathFin/Models/Jumps/JumpDiffusionThinning.lean b/LeanPool/MathFin/Models/Jumps/JumpDiffusionThinning.lean new file mode 100644 index 0000000000..1a039342b4 --- /dev/null +++ b/LeanPool/MathFin/Models/Jumps/JumpDiffusionThinning.lean @@ -0,0 +1,89 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionMixing +public import LeanPool.MathFin.Probability.Jumps.PoissonThinning + +/-! +# Thinning the jumps of a Merton-type jump-diffusion + +`JumpDiffusionHyp Q Λ Z N J` (`Models/Jumps/JumpDiffusionMixing.lean`) is a Merton-type +jump-diffusion at a fixed horizon (any i.i.d. jump law, Merton's Gaussian jumps among them): a +standard normal diffusion sample `Z`, a `Poisson(Λ)` jump count `N` and i.i.d. log-jump sizes +`J 0, J 1, …`, the count independent of the sizes. Sorting the jumps by a measurable set `A` of +sizes (for instance `A = (0, ∞)`, the up-jumps) is a thinning of the Poisson count by i.i.d. marks, +so `PoissonThinning.thinned_streams_of_iid_marks` applies: the number of jumps with size in `A` and +the number with size in `Aᶜ` are independent Poisson counts with means `Λ·P(J₀ ∈ A)` and +`Λ·P(J₀ ∉ A)`. + +## Main results + +* `JumpDiffusionHyp.jumpCounts_split` + +## References + +* [R. C. Merton, *Option pricing when underlying stock returns are discontinuous*][Merton1976] +* G. Last and M. Penrose, *Lectures on the Poisson Process*, Proposition 1.3, + for independence and the two Poisson laws of the counts at a fixed time. + +## Tags + +Poisson thinning, up-jumps and down-jumps, splitting a Poisson process, jump-diffusion, +independent Poisson counts, MSC 60G55, MSC 60G51, MSC 91G20 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} {Λ : ℝ≥0} {Z : Ω → ℝ} + {N : Ω → ℕ} {J : ℕ → Ω → ℝ} + +namespace JumpDiffusionHyp + +/-- **The jumps of a Merton-type jump-diffusion split into independent Poisson streams.** In the +model `JumpDiffusionHyp Q Λ Z N J` and for a measurable set `A` of jump sizes, with `p = Q(J₀ ∈ A)`, +the number of the `N` jumps whose size lies in `A` is `Poisson(p·Λ)`, the number whose size lies in +`Aᶜ` is `Poisson((1 − p)·Λ)`, and the two counts are independent. -/ +theorem jumpCounts_split (h : JumpDiffusionHyp Q Λ Z N J) {A : Set ℝ} (hA : MeasurableSet A) : + Q.map (fun ω ↦ PoissonThinning.marksIn J A (N ω) ω) + = poissonMeasure ((Q (J 0 ⁻¹' A)).toNNReal * Λ) ∧ + Q.map (fun ω ↦ PoissonThinning.marksIn J Aᶜ (N ω) ω) + = poissonMeasure ((1 - (Q (J 0 ⁻¹' A)).toNNReal) * Λ) ∧ + IndepFun (fun ω ↦ PoissonThinning.marksIn J A (N ω) ω) + (fun ω ↦ PoissonThinning.marksIn J Aᶜ (N ω) ω) Q := by + have := h.J_indep.isProbabilityMeasure + -- the thinning theorem wants measurable marks: replace the jump sizes by measurable versions + obtain ⟨J', hJ'm, hJJ'⟩ : ∃ J' : ℕ → Ω → ℝ, (∀ i, Measurable (J' i)) ∧ ∀ i, J i =ᵐ[Q] J' i := + ⟨fun i ↦ (h.aemeasurable_J i).mk (J i), fun i ↦ (h.aemeasurable_J i).measurable_mk, + fun i ↦ (h.aemeasurable_J i).ae_eq_mk⟩ + have hall : ∀ᵐ ω ∂Q, ∀ i, J i ω = J' i ω := ae_all_iff.2 hJJ' + have hmarks (B : Set ℝ) : (fun ω ↦ PoissonThinning.marksIn J B (N ω) ω) + =ᵐ[Q] fun ω ↦ PoissonThinning.marksIn J' B (N ω) ω := + hall.mono fun ω hω ↦ + congrArg Finset.card (Finset.ext fun i ↦ by simp only [Finset.mem_filter, hω]) + have hpre : Q (J 0 ⁻¹' A) = Q (J' 0 ⁻¹' A) := + measure_congr (Filter.eventuallyEqSet_iff.2 ((hJJ' 0).mono fun ω hω ↦ by + simp only [Set.mem_preimage, hω])) + have hid (i : ℕ) : IdentDistrib (J' i) (J' 0) Q Q := + (IdentDistrib.of_ae_eq (h.aemeasurable_J i) (hJJ' i)).symm.trans + ((h.J_ident i).trans (IdentDistrib.of_ae_eq (h.aemeasurable_J 0) (hJJ' 0))) + obtain ⟨h1, h2, h3⟩ := PoissonThinning.thinned_streams_of_iid_marks hA h.N_law hJ'm + ((iIndepFun_congr hJJ').1 h.J_indep) hid + (h.N_indep_J.congr Filter.EventuallyEq.rfl (hall.mono fun ω hω ↦ funext hω)) + exact ⟨by rw [Measure.map_congr (hmarks A), hpre]; exact h1, + by rw [Measure.map_congr (hmarks Aᶜ), hpre]; exact h2, + h3.congr (hmarks A).symm (hmarks Aᶜ).symm⟩ + +end JumpDiffusionHyp + +end MathFin diff --git a/LeanPool/MathFin/Models/Jumps/JumpImpliedVol.lean b/LeanPool/MathFin/Models/Jumps/JumpImpliedVol.lean new file mode 100644 index 0000000000..8906899276 --- /dev/null +++ b/LeanPool/MathFin/Models/Jumps/JumpImpliedVol.lean @@ -0,0 +1,183 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.ImpliedVolatility +public import LeanPool.MathFin.Models.Jumps.JumpDiffusionMixing + +/-! +# Jumps lift the implied volatility + +If the log-price is a Gaussian diffusion part plus an independent jump part `Y` with +`𝔼[e^Y] = 1`, the call is worth at least the Black–Scholes call at the diffusion volatility `σ` +(`bsV_le_jumpDiffusion_call`) and at most the spot. Here the lower bound is strict when `Y` is not +almost surely `0`, and the upper bound is strict for a positive strike. Read through the +Black–Scholes price as a function of the volatility, which increases strictly from below the call +price at `σ` towards the spot, the two bounds say that the call has a unique Black–Scholes implied +volatility and that it lies strictly above `σ`. This holds at every positive strike and maturity, +whatever the law of a compensated jump part that is not almost surely `0`. + +## Main results + +* `bsV_lt_jumpDiffusion_call`: `C_BS(S₀; σ) < C` when `𝔼[e^Y] = 1` and `Y` is not a.s. `0`. + The Black–Scholes price is strictly convex in the spot (`bsV_spot_tangent_lt`), and `S₀e^Y`, + whose mean is `S₀`, is not a.s. `S₀`, so Jensen's inequality is strict + (`lt_integral_of_affine_lt`). +* `jumpDiffusion_call_lt`: `C < S₀·𝔼[e^Y]` for a positive strike, since `(S_T − K)⁺ < S_T`. +* `jumpDiffusion_impliedVol_gt`: the call has a Black–Scholes implied volatility above `σ`, and + no other positive volatility prices to it (`exists_impliedVol_gt_of_bsV_lt`). +* `JumpDiffusionHyp.impliedVol_gt`: the same for the compound-Poisson model at the compensator + `κ = Λ(𝔼[e^J] − 1)`, when `𝔼[e^J] < ∞`, the expected jump count `Λ` is positive and the jump + law is not the + point mass at `0` (`JumpDiffusionHyp.not_jumpPart_ae_eq_zero`). + +## Scope + +Each statement concerns one strike and one maturity: the implied volatility exceeds `σ` at every +strike, but nothing is said about how it varies across strikes (the shape of the smile). + +## References + +* [Cont and Tankov, *Financial Modelling with Jump Processes*][ContTankov2004] +* [R. C. Merton, *Option pricing when underlying stock returns are discontinuous*][Merton1976] + +## Tags + +implied volatility with jumps, volatility lift, Black–Scholes lower bound, jump risk, +strict inequality, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} + +/-- **Jump risk is strictly priced.** If the jump part is compensated, `𝔼[e^Y] = 1`, and not +almost surely `0`, the jump-diffusion call is worth strictly more than the Black–Scholes call at +the diffusion volatility. The Black–Scholes price lies strictly above its tangent at `S₀` away +from `S₀` (`bsV_spot_tangent_lt`), and `S₀e^Y` has mean `S₀` but is not a.s. `S₀`. -/ +theorem bsV_lt_jumpDiffusion_call {S_0 K r σ T : ℝ} {Z Y : Ω → ℝ} + (hZ : HasLaw Z (gaussianReal 0 1) Q) (hY : AEMeasurable Y Q) (hYZ : IndepFun Y Z Q) + (hexp : Integrable (fun ω ↦ rexp (Y ω)) Q) (hmean : ∫ ω, rexp (Y ω) ∂Q = 1) + (hY0 : ¬Y =ᵐ[Q] 0) (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + bsV K r σ S_0 T < ∫ ω, rexp (-r * T) + * max (S_0 * rexp ((r - σ ^ 2 / 2) * T + σ * Real.sqrt T * Z ω + Y ω) - K) 0 ∂Q := by + have := hZ.isProbabilityMeasure + have hm : ∫ ω, S_0 * rexp (Y ω) ∂Q = S_0 := by rw [integral_const_mul, hmean, mul_one] + rw [jumpDiffusion_call_eq_integral_bsV hZ hY hYZ hexp hS_0 hK hσ hT] + refine lt_integral_of_affine_lt (f := fun s ↦ bsV K r σ s T) (c := Phi (bsd1 S_0 K r σ T)) + (hexp.const_mul S_0) hm (integrable_bsV_mul_exp hY hexp hS_0 hK hσ hT) + (ae_of_all _ fun ω hne ↦ + bsV_spot_tangent_lt hK hσ hT hS_0 (mul_pos hS_0 (Real.exp_pos _)) hne) fun hc ↦ hY0 ?_ + filter_upwards [hc] with ω hω + exact (Real.exp_eq_one_iff _).1 ((mul_eq_left₀ hS_0.ne').1 hω) + +/-- **The call is worth strictly less than `S₀·𝔼[e^Y]`** when the strike is positive: the payoff +`(S_T − K)⁺` is strictly below the terminal price `S_T > 0`, and the discounted terminal price +has mean `S₀·𝔼[e^Y]` (`jumpDiffusion_discounted_terminal`). -/ +theorem jumpDiffusion_call_lt {S_0 K r σ T : ℝ} {Z Y : Ω → ℝ} + (hZ : HasLaw Z (gaussianReal 0 1) Q) (hY : AEMeasurable Y Q) (hYZ : IndepFun Y Z Q) + (hexp : Integrable (fun ω ↦ rexp (Y ω)) Q) (hS_0 : 0 < S_0) (hK : 0 < K) (hT : 0 ≤ T) : + ∫ ω, rexp (-r * T) + * max (S_0 * rexp ((r - σ ^ 2 / 2) * T + σ * Real.sqrt T * Z ω + Y ω) - K) 0 ∂Q + < S_0 * ∫ ω, rexp (Y ω) ∂Q := by + have := hZ.isProbabilityMeasure + rw [← jumpDiffusion_discounted_terminal (r := r) (σ := σ) hZ hY hYZ hT] + have hf := integrable_jumpDiffusion_call_payoff (S_0 := S_0) (K := K) (r := r) (σ := σ) + (T := T) hZ hYZ hexp + have hg := (integrable_jumpDiffusion_terminal (S_0 := S_0) (r := r) (σ := σ) (T := T) hZ hYZ + hexp).const_mul (rexp (-r * T)) + have hlt (ω : Ω) : rexp (-r * T) + * max (S_0 * rexp ((r - σ ^ 2 / 2) * T + σ * Real.sqrt T * Z ω + Y ω) - K) 0 + < rexp (-r * T) * (S_0 * rexp ((r - σ ^ 2 / 2) * T + σ * Real.sqrt T * Z ω + Y ω)) := + mul_lt_mul_of_pos_left (max_lt (by linarith) (mul_pos hS_0 (Real.exp_pos _))) + (Real.exp_pos _) + refine integral_lt_integral_of_ae_le_of_not_ae_eq hf hg (ae_of_all _ fun ω ↦ (hlt ω).le) + fun h_eq ↦ ?_ + obtain ⟨ω, hω⟩ := Filter.Eventually.exists h_eq + exact (hlt ω).ne hω + +/-- **Jumps lift the implied volatility.** If the jump part is compensated, `𝔼[e^Y] = 1`, and +not almost surely `0`, the jump-diffusion call has a Black–Scholes implied volatility `σ_imp` +strictly above the diffusion volatility `σ`, and no other positive volatility gives the +Black–Scholes price equal to the call. The call lies strictly between the Black–Scholes price at +`σ` (`bsV_lt_jumpDiffusion_call`) and the spot (`jumpDiffusion_call_lt`). -/ +theorem jumpDiffusion_impliedVol_gt {S_0 K r σ T : ℝ} {Z Y : Ω → ℝ} + (hZ : HasLaw Z (gaussianReal 0 1) Q) (hY : AEMeasurable Y Q) (hYZ : IndepFun Y Z Q) + (hexp : Integrable (fun ω ↦ rexp (Y ω)) Q) (hmean : ∫ ω, rexp (Y ω) ∂Q = 1) + (hY0 : ¬Y =ᵐ[Q] 0) (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + ∃ σ_imp, σ < σ_imp ∧ bsV K r σ_imp S_0 T = ∫ ω, rexp (-r * T) + * max (S_0 * rexp ((r - σ ^ 2 / 2) * T + σ * Real.sqrt T * Z ω + Y ω) - K) 0 ∂Q ∧ + ∀ σ' > 0, bsV K r σ' S_0 T = ∫ ω, rexp (-r * T) + * max (S_0 * rexp ((r - σ ^ 2 / 2) * T + σ * Real.sqrt T * Z ω + Y ω) - K) 0 ∂Q → + σ' = σ_imp := + exists_impliedVol_gt_of_bsV_lt hK hT hS_0 hσ + (bsV_lt_jumpDiffusion_call hZ hY hYZ hexp hmean hY0 hS_0 hK hσ hT) + ((jumpDiffusion_call_lt hZ hY hYZ hexp hS_0 hK hT.le).trans_eq (by rw [hmean, mul_one])) + +namespace JumpDiffusionHyp + +variable {Λ : ℝ≥0} {Z : Ω → ℝ} {N : Ω → ℕ} {J : ℕ → Ω → ℝ} + +/-- **The jump part is not deterministic.** With a positive expected jump count and a jump law +that is not the point mass at `0`, the jump part `−κ + ∑_{i 0, bsV K r σ' S_0 T = ∫ ω, rexp (-r * T) * max (jumpDiffusionTerminal + S_0 r σ T (Λ * (∫ x, rexp (J 0 x) ∂Q - 1)) (Z ω) (N ω) (fun i ↦ J i ω) - K) 0 ∂Q → + σ' = σ_imp := by + simp_rw [jumpDiffusionTerminal_eq] + exact jumpDiffusion_impliedVol_gt h.Z_law (h.aemeasurable_jumpPart _) (h.indepFun_jumpPart _) + (h.integrable_exp_jumpPart hJ _) (h.integral_exp_compensatedJumpPart hJ) + (h.not_jumpPart_ae_eq_zero hΛ hJ0 _) hS_0 hK hσ hT + +end JumpDiffusionHyp + +end MathFin diff --git a/LeanPool/MathFin/Models/Jumps/MertonClassicDisplay.lean b/LeanPool/MathFin/Models/Jumps/MertonClassicDisplay.lean new file mode 100644 index 0000000000..3d49b0c0bb --- /dev/null +++ b/LeanPool/MathFin/Models/Jumps/MertonClassicDisplay.lean @@ -0,0 +1,147 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Jumps.MertonJumpDiffusion + +/-! +# The classic Merton display: `Λ′ = Λ(1+k)` + +`MertonJumpDiffusion.lean` states the price with jump-compensated +*conditional spots* `spot_n = S₀ e^{−kΛ}(1+k)^n` under plain Poisson +weights. The textbook display instead keeps the spot at `S₀` and absorbs +the jump factor `(1+k)^n` into an **adjusted intensity** `Λ′ = Λ(1+k)` and +a **shifted rate** `r_n = r − kΛ/T + n·log(1+k)/T`: + + `C_Merton = Σₙ e^{−Λ′} Λ′ⁿ/n! · C_BS(S₀, K, r_n, vol_n, T)`. + +The two forms are the same series regrouped, and the regrouping is driven +by one structural identity of the BS formula: + +* **Rate-shift identity** (`bsV_spot_exp_rate_shift`): spot growth `e^{cτ}` + trades for a discount-rate shift, + `bsV K r σ (S e^{cτ}) τ = e^{cτ} · bsV K (r+c) σ S τ` — the same + invariance that underlies forward/futures re-parametrizations. + +Applying it at `c_n = r_n − r` (so `e^{c_n T} = e^{−kΛ}(1+k)^n`, the +compensated jump growth) turns each conditional value into +`e^{−kΛ}(1+k)^n · C_BS(S₀, r_n, vol_n)`, and the weight algebra +`e^{−Λ}Λⁿ/n! · e^{−kΛ}(1+k)ⁿ = e^{−Λ′}Λ′ⁿ/n!` finishes the display. +No hypotheses beyond `S₀, K > 0`, `T > 0`, `k > −1` — in particular no +constraint on `σ`, `δ`, `r`. + +## Main definitions + +* `mertonRate`: the jump-adjusted rate `r_n = r − kΛ/T + n·log(1+k)/T` of the classic display. + +## Main results + +* `bsV_spot_exp_rate_shift` — the rate-shift identity. +* `mertonCallTerm_eq_classic` — per-term regrouping. +* `mertonCallPrice_eq_classic_tsum` — the classic Merton series. + +## References + +* [R. C. Merton, *Option pricing when underlying stock returns are discontinuous*][Merton1976], eq. + (16) + +## Tags + +Merton jump-diffusion, adjusted intensity, Poisson series, textbook form, jump compensator, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal Nat + +/-- The jump-adjusted rate of the classic display: +`r_n = r − kΛ/T + n·log(1+k)/T` — the `n`-conditional drift correction that +trades the jump-compensated spot for a rate shift. -/ +noncomputable def mertonRate (r k T : ℝ) (Λ : ℝ≥0) (n : ℕ) : ℝ := + r - k * (Λ : ℝ) / T + n * Real.log (1 + k) / T + +/-- `d₁` trades spot growth `e^{cτ}` for a rate shift `r ↦ r + c`. -/ +lemma bsd1_spot_exp_shift {S K : ℝ} (hS : 0 < S) (hK : 0 < K) + (r c σ τ : ℝ) : + bsd1 (S * rexp (c * τ)) K r σ τ = bsd1 S K (r + c) σ τ := by + unfold bsd1 + rw [show S * rexp (c * τ) / K = S / K * rexp (c * τ) from by ring, + Real.log_mul (by positivity) (Real.exp_pos _).ne', Real.log_exp] + ring + +/-- `d₂` inherits the same trade. -/ +lemma bsd2_spot_exp_shift {S K : ℝ} (hS : 0 < S) (hK : 0 < K) + (r c σ τ : ℝ) : + bsd2 (S * rexp (c * τ)) K r σ τ = bsd2 S K (r + c) σ τ := by + unfold bsd2 + rw [bsd1_spot_exp_shift hS hK] + +/-- **Rate-shift identity**: spot growth `e^{cτ}` trades for a discount-rate +shift, `bsV K r σ (S e^{cτ}) τ = e^{cτ} · bsV K (r+c) σ S τ`. The algebraic +engine of the classic Merton display. -/ +theorem bsV_spot_exp_rate_shift {S K : ℝ} (hS : 0 < S) (hK : 0 < K) + (r c σ τ : ℝ) : + bsV K r σ (S * rexp (c * τ)) τ = rexp (c * τ) * bsV K (r + c) σ S τ := by + unfold bsV + rw [bsd1_spot_exp_shift hS hK, bsd2_spot_exp_shift hS hK, + show -(r * τ) = c * τ + -((r + c) * τ) from by ring, Real.exp_add] + ring + +/-- The compensated spot as exponential growth at the shifted rate: +`mertonSpot S₀ k Λ n = S₀ · e^{(r_n − r)T}`. -/ +lemma mertonSpot_eq_spot_exp {k T : ℝ} (S_0 : ℝ) (hT : 0 < T) (hk : -1 < k) + (Λ : ℝ≥0) (r : ℝ) (n : ℕ) : + mertonSpot S_0 k Λ n = S_0 * rexp ((mertonRate r k T Λ n - r) * T) := by + have h1k : (0 : ℝ) < 1 + k := by linarith + unfold mertonSpot mertonRate + rw [show (r - k * (Λ : ℝ) / T + ↑n * Real.log (1 + k) / T - r) * T + = -(k * (Λ : ℝ)) + ↑n * Real.log (1 + k) from by + field_simp [hT.ne']; ring, + Real.exp_add, Real.exp_nat_mul, Real.exp_log h1k] + ring + +/-- **Per-term classic form**: each Merton term regroups as the compensated +jump growth times a Black–Scholes value at spot `S₀` and the shifted rate: +`term_n = e^{−kΛ}(1+k)^n · bsV K r_n vol_n S₀ T`. -/ +theorem mertonCallTerm_eq_classic {S_0 K k T : ℝ} (r σ δ : ℝ) (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hK : 0 < K) (hT : 0 < T) (hk : -1 < k) (n : ℕ) : + mertonCallTerm S_0 K r σ T k δ Λ n + = rexp (-(k * (Λ : ℝ))) * (1 + k) ^ n + * bsV K (mertonRate r k T Λ n) (mertonVol σ δ T n) S_0 T := by + have h1k : (0 : ℝ) < 1 + k := by linarith + rw [mertonCallTerm_eq_bsV, mertonSpot_eq_spot_exp S_0 hT hk Λ r n, + bsV_spot_exp_rate_shift hS_0 hK, + show r + (mertonRate r k T Λ n - r) = mertonRate r k T Λ n from by ring, + show (mertonRate r k T Λ n - r) * T + = -(k * (Λ : ℝ)) + ↑n * Real.log (1 + k) from by + unfold mertonRate; field_simp [hT.ne']; ring, + Real.exp_add, Real.exp_nat_mul, Real.exp_log h1k] + +/-- **The classic Merton (1976) display**: regrouping the jump factor +`(1+k)^n` into the Poisson weight gives the textbook series — weights at +the adjusted intensity `Λ′ = Λ(1+k)`, Black–Scholes values at spot `S₀`, +shifted rates `r_n`, conditional vols `vol_n`: + + `C_Merton = Σₙ e^{−Λ′} Λ′ⁿ/n! · C_BS(S₀, K, r_n, vol_n, T)`. -/ +theorem mertonCallPrice_eq_classic_tsum {S_0 K k T : ℝ} (r σ δ : ℝ) (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hK : 0 < K) (hT : 0 < T) (hk : -1 < k) : + mertonCallPrice S_0 K r σ T k δ Λ + = ∑' n : ℕ, rexp (-((Λ : ℝ) * (1 + k))) * ((Λ : ℝ) * (1 + k)) ^ n / n ! + * bsV K (mertonRate r k T Λ n) (mertonVol σ δ T n) S_0 T := by + rw [mertonCallPrice_eq_tsum] + refine tsum_congr fun n ↦ ?_ + rw [mertonCallTerm_eq_classic r σ δ Λ hS_0 hK hT hk n, + show -((Λ : ℝ) * (1 + k)) = -(Λ : ℝ) + -(k * (Λ : ℝ)) from by ring, + Real.exp_add, mul_pow] + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/Jumps/MertonDominance.lean b/LeanPool/MathFin/Models/Jumps/MertonDominance.lean new file mode 100644 index 0000000000..1b448bee66 --- /dev/null +++ b/LeanPool/MathFin/Models/Jumps/MertonDominance.lean @@ -0,0 +1,136 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Jumps.MertonJumpDiffusion +public import LeanPool.MathFin.Models.BlackScholes.SpotConvexity +public import LeanPool.MathFin.Models.BlackScholes.ImpliedVolatility +public import LeanPool.MathFin.Probability.Analysis.AffineMinorant + +/-! +# Merton dominance: jump risk is never free + +The Merton (1976) jump-diffusion call price dominates the Black–Scholes +price at the diffusion volatility: + + `C_BS(S₀, σ) ≤ C_Merton(S₀, σ, k, δ, Λ)` for every `Λ`, `δ`, `k > −1`. + +The proof decomposes jump risk into its two channels, each priced by a +structural fact of the library: + +1. **Jump-size uncertainty (vol channel)**: conditional vols satisfy + `σ ≤ vol_n`, and the BS value is increasing in vol + (`bsV_strictMonoOn_sigma`, vega positivity) — so the mixture at jump vol + `δ` dominates the mixture at `δ = 0` term by term. +2. **Jump-count uncertainty (spot channel)**: at `δ = 0` the mixture + averages BS values over the *spread* of compensated conditional spots. + The BS price is convex in the spot (`bsV_spot_convexOn`, gamma), so the + value lies above its tangent at `S₀` (`bsV_spot_tangent_le`), and the + linear tangent term integrates to **zero** by the compensation identity + `E[mertonSpot] = S₀` (`integral_mertonSpot`) — the Jensen floor. + +Financially: jumps add value through vega *and* through gamma, and the +compensator is exactly what makes the gamma channel a clean Jensen +argument. Both channels consume the existing structural layer (vega +positivity, gamma convexity, the pgf recombination identity); nothing new +is assumed. + +## Main results + +* `bsV_le_mertonCallPrice` : `bsV K r σ S₀ T ≤ mertonCallPrice S₀ K r σ T k δ Λ`. + +## References + +* [R. C. Merton, *Option pricing when underlying stock returns are discontinuous*][Merton1976] + +## Tags + +Merton jump-diffusion, jump risk, price dominance, Black–Scholes lower bound, +convexity of call price, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal Nat + +/-- With zero jump volatility the conditional vol collapses to the diffusion +vol: `mertonVol σ 0 T n = σ`. -/ +lemma mertonVol_delta_zero {σ : ℝ} (hσ : 0 ≤ σ) (T : ℝ) (n : ℕ) : + mertonVol σ 0 T n = σ := by + unfold mertonVol + simp [Real.sqrt_sq hσ] + +/-- Jump uncertainty only adds variance: `σ ≤ mertonVol σ δ T n`. -/ +lemma le_mertonVol {σ T : ℝ} (δ : ℝ) (hσ : 0 ≤ σ) (hT : 0 < T) (n : ℕ) : + σ ≤ mertonVol σ δ T n := by + unfold mertonVol + calc σ = Real.sqrt (σ ^ 2) := (Real.sqrt_sq hσ).symm + _ ≤ _ := Real.sqrt_le_sqrt (le_add_of_nonneg_right + (div_nonneg (by positivity) hT.le)) + +/-- **Per-term vol-monotonicity**: the zero-jump-vol conditional value lower- +bounds the conditional value at any jump vol `δ` — the BS value is increasing +in vol (vega) and jump variance only adds. -/ +lemma mertonCallTerm_delta_zero_le {S_0 K r σ T k : ℝ} (δ : ℝ) (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (hk : -1 < k) + (n : ℕ) : + mertonCallTerm S_0 K r σ T k 0 Λ n ≤ mertonCallTerm S_0 K r σ T k δ Λ n := by + rw [mertonCallTerm_eq_bsV, mertonCallTerm_eq_bsV, mertonVol_delta_zero hσ.le] + exact (bsV_strictMonoOn_sigma hK hT (mertonSpot_pos hS_0 hk Λ n)).monotoneOn + (Set.mem_Ioi.mpr hσ) (Set.mem_Ioi.mpr (mertonVol_pos hσ hT n)) + (le_mertonVol δ hσ.le hT n) + +/-- **Price-level vol-monotonicity**: the δ = 0 mixture lower-bounds the +Merton price. -/ +lemma mertonCallPrice_delta_zero_le {S_0 K r σ T k : ℝ} (δ : ℝ) (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (hk : -1 < k) : + mertonCallPrice S_0 K r σ T k 0 Λ ≤ mertonCallPrice S_0 K r σ T k δ Λ := by + unfold mertonCallPrice + exact integral_mono (integrable_mertonCallTerm 0 Λ hS_0 hK hσ hT hk) + (integrable_mertonCallTerm δ Λ hS_0 hK hσ hT hk) + (mertonCallTerm_delta_zero_le δ Λ hS_0 hK hσ hT hk) + +/-- **The Jensen floor at zero jump-vol**: spot convexity (tangent at `S₀`, +slope delta) plus the compensation identity `E[mertonSpot] = S₀` make the +δ = 0 mixture dominate the Black–Scholes value — the linear tangent term +integrates to zero *because* the conditional forwards recombine. -/ +lemma bsV_le_mertonCallPrice_delta_zero {S_0 K r σ T k : ℝ} (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (hk : -1 < k) : + bsV K r σ S_0 T ≤ mertonCallPrice S_0 K r σ T k 0 Λ := by + have hterm (n : ℕ) : + mertonCallTerm S_0 K r σ T k 0 Λ n = bsV K r σ (mertonSpot S_0 k Λ n) T := by + rw [mertonCallTerm_eq_bsV, mertonVol_delta_zero hσ.le] + calc bsV K r σ S_0 T + ≤ ∫ n, bsV K r σ (mertonSpot S_0 k Λ n) T ∂(poissonMeasure Λ) := + le_integral_of_affine_le (f := fun s ↦ bsV K r σ s T) (c := Phi (bsd1 S_0 K r σ T)) + (integrable_mertonSpot Λ hS_0 hk) (integral_mertonSpot S_0 k Λ) + ((integrable_mertonCallTerm 0 Λ hS_0 hK hσ hT hk).congr (ae_of_all _ hterm)) + (ae_of_all _ fun n ↦ bsV_spot_tangent_le hK hσ hT hS_0 (mertonSpot_pos hS_0 hk Λ n)) + _ = mertonCallPrice S_0 K r σ T k 0 Λ := (integral_congr_ae (ae_of_all _ hterm)).symm + +/-- **Merton dominance — jump risk is never free.** The Merton (1976) +jump-diffusion call price dominates the Black–Scholes price at the diffusion +volatility, for every jump intensity `Λ`, mean jump size `k > −1`, and jump +vol `δ`: + + `C_BS(S₀, σ) ≤ C_Merton(S₀, σ, k, δ, Λ)`. + +Chain: vol-monotonicity reduces to `δ = 0` +(`mertonCallPrice_delta_zero_le`, the vega channel), then spot convexity +plus the compensation identity give the Jensen floor +(`bsV_le_mertonCallPrice_delta_zero`, the gamma channel). -/ +theorem bsV_le_mertonCallPrice {S_0 K r σ T k : ℝ} (δ : ℝ) (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (hk : -1 < k) : + bsV K r σ S_0 T ≤ mertonCallPrice S_0 K r σ T k δ Λ := + (bsV_le_mertonCallPrice_delta_zero Λ hS_0 hK hσ hT hk).trans + (mertonCallPrice_delta_zero_le δ Λ hS_0 hK hσ hT hk) + +end MathFin diff --git a/LeanPool/MathFin/Models/Jumps/MertonGreeks.lean b/LeanPool/MathFin/Models/Jumps/MertonGreeks.lean new file mode 100644 index 0000000000..c1420d5afe --- /dev/null +++ b/LeanPool/MathFin/Models/Jumps/MertonGreeks.lean @@ -0,0 +1,484 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Jumps.MertonDominance +public import LeanPool.MathFin.Probability.Gaussian.NormalQuantile +public import Mathlib.Analysis.Calculus.SmoothSeries + +/-! +# The Merton jump-diffusion Greeks + +The Merton call price is a Poisson mixture of Black–Scholes prices, +`C(S) = ∑ₙ wₙ · C_BS(S·cₙ, σₙ)`, with Poisson weights `wₙ = e^{−Λ}Λⁿ/n!`, jump factors +`cₙ = e^{−kΛ}(1 + k)ⁿ` (the conditional spot is `mertonSpot S n = S·cₙ`) and conditional +volatilities `σₙ = mertonVol n = √(σ² + nδ²/T)`. Its Greeks are Poisson mixtures of the +Black–Scholes Greeks at the conditional spots and volatilities, each carrying its chain-rule +factor: `cₙ` per derivative in the spot, `σ/σₙ` for the volatility. The series can be +differentiated term by term because the Black–Scholes delta and the normal density are bounded +and the weights `wₙcₙ` sum to one, which is the compensation identity `E[mertonSpot(N)] = S` at +`S = 1`. + +## Main definitions + +* `mertonDelta`: `∑ₙ wₙ cₙ Φ(d₁ⁿ)`, the Poisson mixture of Black–Scholes deltas at the conditional + spots, each with its factor `cₙ`. +* `mertonGamma`: `∑ₙ wₙ cₙ ϕ(d₁ⁿ)/(S σₙ √T)`, the corresponding mixture of gammas. +* `mertonVega`: `∑ₙ wₙ S cₙ ϕ(d₁ⁿ) √T · σ/σₙ`, the corresponding mixture of vegas. + +## Main results + +* `hasDerivAt_mertonCallPrice_spot`: the delta is `mertonDelta = ∑ₙ wₙ cₙ Φ(d₁ⁿ)`, where `d₁ⁿ` + is the Black–Scholes `d₁` at the spot `S·cₙ` and the volatility `σₙ`. +* `mertonDelta_pos`, `mertonDelta_lt_one`: `0 < Δ < 1`. The upper bound is the compensation + identity `∑ₙ wₙcₙ = 1` together with `Φ < 1`. +* `hasDerivAt_deriv_mertonCallPrice_spot`, `mertonGamma_pos`: the gamma, the second derivative + of the price in the spot, is `mertonGamma = ∑ₙ wₙ cₙ ϕ(d₁ⁿ)/(S σₙ √T)`, and it is positive. The + delta series is differentiated term by term (`hasDerivAt_mertonDelta`), and it is the first + derivative of the price near the point. +* `hasDerivAt_mertonCallPrice_sigma`, `mertonVega_pos`: the vega is + `mertonVega = ∑ₙ wₙ S cₙ ϕ(d₁ⁿ) √T · σ/σₙ`, and it is positive. The factor `σ/σₙ` is the + derivative of `σₙ` in `σ`. +* `mertonCallPrice_strictMonoOn_spot`, `mertonCallPrice_strictConvexOn_spot`, + `mertonCallPrice_strictMonoOn_sigma`: the signs of the Greeks as the shape of the price. On + `(0, ∞)` the call price strictly increases and is strictly convex in the spot, and strictly + increases in the diffusion volatility. + +## References + +* [R. C. Merton, *Option pricing when underlying stock returns are discontinuous*][Merton1976] + +## Tags + +Merton jump-diffusion, delta and gamma, Poisson mixture, term-by-term differentiation, +Greeks with jumps, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Real Set Filter ProbabilityTheory +open scoped NNReal Nat + +variable {K r σ T k δ : ℝ} {Λ : ℝ≥0} + +/-! ### The jump factors -/ + +/-- The conditional spot is linear in the spot: `mertonSpot S n = S · mertonSpot 1 n`. -/ +lemma mertonSpot_eq_mul_one (S k : ℝ) (Λ : ℝ≥0) (n : ℕ) : + mertonSpot S k Λ n = S * mertonSpot 1 k Λ n := by + unfold mertonSpot + ring + +/-- **The jump factors average to one**: `∑ₙ wₙ e^{−kΛ}(1 + k)ⁿ = 1`, the compensation identity +`E[mertonSpot(N)] = S₀` at `S₀ = 1`. -/ +lemma hasSum_weights_mul_mertonSpot_one (k : ℝ) (Λ : ℝ≥0) : + HasSum (fun n : ℕ ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonSpot 1 k Λ n) 1 := by + have h := (PoissonPgf.hasSum_poisson_weights_mul_pow Λ (1 + k)).mul_left + (rexp (-(k * (Λ : ℝ)))) + rw [← Real.exp_add, show -(k * (Λ : ℝ)) + (Λ : ℝ) * (1 + k - 1) = 0 by ring, + Real.exp_zero] at h + have hfun : (fun n : ℕ ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonSpot 1 k Λ n) + = fun n ↦ rexp (-(k * (Λ : ℝ))) * (rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * (1 + k) ^ n) := by + funext n + unfold mertonSpot + ring + rw [hfun] + exact h + +/-- The Poisson-weighted call values form a convergent series: the call terms are integrable +against `Poisson(Λ)` (`integrable_mertonCallTerm`). -/ +lemma summable_weights_mul_mertonCallTerm {S : ℝ} (hS : 0 < S) (hK : 0 < K) (hσ : 0 < σ) + (hT : 0 < T) (hk : -1 < k) : + Summable fun n : ℕ ↦ + rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonCallTerm S K r σ T k δ Λ n := by + simpa only [smul_eq_mul] using + (hasSum_integral_poissonMeasure + (integrable_mertonCallTerm (r := r) δ Λ hS hK hσ hT hk)).summable + +/-! ### Delta -/ + +/-- **The Merton delta**: `∑ₙ wₙ cₙ Φ(d₁ⁿ)`, the Poisson mixture of the Black–Scholes deltas at +the conditional spots `S·cₙ`, each multiplied by `cₙ = ∂(S·cₙ)/∂S`. -/ +noncomputable def mertonDelta (S K r σ T k δ : ℝ) (Λ : ℝ≥0) : ℝ := + ∑' n : ℕ, rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot 1 k Λ n * Phi (bsd1 (mertonSpot S k Λ n) K r (mertonVol σ δ T n) T)) + +/-- The delta series converges: its terms lie in `[0, wₙcₙ]`. -/ +lemma summable_mertonDelta_terms (hk : -1 < k) (S : ℝ) : + Summable fun n : ℕ ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot 1 k Λ n * Phi (bsd1 (mertonSpot S k Λ n) K r (mertonVol σ δ T n) T)) := + Summable.of_nonneg_of_le + (fun n ↦ mul_nonneg (by positivity) + (mul_nonneg (mertonSpot_pos one_pos hk Λ n).le (Phi_nonneg _))) + (fun n ↦ mul_le_mul_of_nonneg_left + (mul_le_of_le_one_right (mertonSpot_pos one_pos hk Λ n).le (Phi_le_one _)) (by positivity)) + (hasSum_weights_mul_mertonSpot_one k Λ).summable + +/-- **Delta of the Merton call.** `∂C/∂S = ∑ₙ wₙ cₙ Φ(d₁ⁿ)`: the series of Black–Scholes prices +is differentiated term by term, each term's derivative being bounded by `wₙcₙ`. -/ +theorem hasDerivAt_mertonCallPrice_spot (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (hk : -1 < k) + {S : ℝ} (hS : 0 < S) : + HasDerivAt (fun s ↦ mertonCallPrice s K r σ T k δ Λ) (mertonDelta S K r σ T k δ Λ) S := by + have hc (n : ℕ) : 0 < mertonSpot 1 k Λ n := mertonSpot_pos one_pos hk Λ n + have hw (n : ℕ) : 0 ≤ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! := by positivity + have hterm (n : ℕ) (s : ℝ) (hs : s ∈ Ioi (0 : ℝ)) : + HasDerivAt + (fun y ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonCallTerm y K r σ T k δ Λ n) + (rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot 1 k Λ n * Phi (bsd1 (mertonSpot s k Λ n) K r (mertonVol σ δ T n) T))) s := by + have hs0 : 0 < s := hs + have hbs := (hasDerivAt_bsV_S (r := r) hK (mertonVol_pos (δ := δ) hσ hT n) + (mul_pos hs0 (hc n)) hT).comp s (hasDerivAt_mul_const (mertonSpot 1 k Λ n)) + have hfun : (fun y ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonCallTerm y K r σ T k δ Λ n) + = fun y ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! + * bsV K r (mertonVol σ δ T n) (y * mertonSpot 1 k Λ n) T := by + funext y + rw [mertonCallTerm_eq_bsV, mertonSpot_eq_mul_one y] + rw [hfun] + refine (hbs.const_mul (rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n !)).congr_deriv ?_ + rw [mertonSpot_eq_mul_one s] + ring + have hbound (n : ℕ) (s : ℝ) (_ : s ∈ Ioi (0 : ℝ)) : + ‖rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot 1 k Λ n * Phi (bsd1 (mertonSpot s k Λ n) K r (mertonVol σ δ T n) T))‖ + ≤ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonSpot 1 k Λ n := by + rw [Real.norm_of_nonneg (mul_nonneg (hw n) (mul_nonneg (hc n).le (Phi_nonneg _)))] + exact mul_le_mul_of_nonneg_left (mul_le_of_le_one_right (hc n).le (Phi_le_one _)) (hw n) + exact (hasDerivAt_tsum_of_isPreconnected (hasSum_weights_mul_mertonSpot_one k Λ).summable + isOpen_Ioi isPreconnected_Ioi hterm hbound hS + (summable_weights_mul_mertonCallTerm hS hK hσ hT hk) hS).congr_of_eventuallyEq + (Eventually.of_forall fun s ↦ mertonCallPrice_eq_tsum s K r σ T k δ Λ) + +/-- **The Merton delta is positive.** Every term is nonnegative and the no-jump term is +positive. -/ +theorem mertonDelta_pos (hk : -1 < k) (S : ℝ) : 0 < mertonDelta S K r σ T k δ Λ := by + refine (summable_mertonDelta_terms hk S).tsum_pos + (fun n ↦ mul_nonneg (by positivity) + (mul_nonneg (mertonSpot_pos one_pos hk Λ n).le (Phi_nonneg _))) 0 ?_ + rw [pow_zero, Nat.factorial_zero, Nat.cast_one, mul_one, div_one] + exact mul_pos (Real.exp_pos _) (mul_pos (mertonSpot_pos one_pos hk Λ 0) (Phi_mem_Ioo _).1) + +/-- **The Merton delta is below one.** `Δ = ∑ₙ wₙcₙΦ(d₁ⁿ) < ∑ₙ wₙcₙ = 1`: the compensation +identity bounds the delta exactly as the Black–Scholes bound `Φ < 1` bounds each term. -/ +theorem mertonDelta_lt_one (hk : -1 < k) (S : ℝ) : mertonDelta S K r σ T k δ Λ < 1 := by + have hc (n : ℕ) : 0 < mertonSpot 1 k Λ n := mertonSpot_pos one_pos hk Λ n + have hsum := hasSum_weights_mul_mertonSpot_one k Λ + rw [← hsum.tsum_eq] + refine Summable.tsum_lt_tsum (i := 0) (Pi.le_def.mpr fun n ↦ ?_) ?_ + (summable_mertonDelta_terms hk S) hsum.summable + · exact mul_le_mul_of_nonneg_left (mul_le_of_le_one_right (hc n).le (Phi_le_one _)) + (by positivity) + · exact mul_lt_mul_of_pos_left (mul_lt_of_lt_one_right (hc 0) (Phi_mem_Ioo _).2) + (by rw [pow_zero, Nat.factorial_zero, Nat.cast_one, mul_one, div_one]; exact Real.exp_pos _) + +/-! ### Gamma -/ + +/-- **The Merton gamma**: `∑ₙ wₙ cₙ ϕ(d₁ⁿ)/(S σₙ √T)`, the Poisson mixture of the Black–Scholes +gammas at the conditional spots, each multiplied by `cₙ²`. -/ +noncomputable def mertonGamma (S K r σ T k δ : ℝ) (Λ : ℝ≥0) : ℝ := + ∑' n : ℕ, rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot 1 k Λ n * gaussianPDFReal 0 1 (bsd1 (mertonSpot S k Λ n) K r (mertonVol σ δ T n) T) + / (S * mertonVol σ δ T n * Real.sqrt T)) + +/-- **The delta series has derivative `mertonGamma`.** Near `S`, on `(S/2, ∞)`, each term's +derivative is at most `wₙcₙ` times `1/((S/2) σ √T)`, since `ϕ ≤ 1` and `σₙ ≥ σ`, so the delta +series is differentiated term by term. -/ +theorem hasDerivAt_mertonDelta (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (hk : -1 < k) + {S : ℝ} (hS : 0 < S) : + HasDerivAt (fun s ↦ mertonDelta s K r σ T k δ Λ) (mertonGamma S K r σ T k δ Λ) S := by + have hc (n : ℕ) : 0 < mertonSpot 1 k Λ n := mertonSpot_pos one_pos hk Λ n + have hw (n : ℕ) : 0 ≤ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! := by positivity + have hv (n : ℕ) : 0 < mertonVol σ δ T n := mertonVol_pos hσ hT n + have hsT : 0 < Real.sqrt T := Real.sqrt_pos.mpr hT + have hS2 : 0 < S / 2 := half_pos hS + have hterm (n : ℕ) (s : ℝ) (hs : s ∈ Ioi (S / 2)) : + HasDerivAt (fun y ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot 1 k Λ n * Phi (bsd1 (mertonSpot y k Λ n) K r (mertonVol σ δ T n) T))) + (rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot 1 k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot s k Λ n) K r (mertonVol σ δ T n) T) + / (s * mertonVol σ δ T n * Real.sqrt T))) s := by + have hs0 : 0 < s := hS2.trans hs + have hphi := (hasDerivAt_Phi_bsd1_S (r := r) hK (hv n) (mul_pos hs0 (hc n)) hT).comp s + (hasDerivAt_mul_const (mertonSpot 1 k Λ n)) + have hfun : (fun y ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot 1 k Λ n * Phi (bsd1 (mertonSpot y k Λ n) K r (mertonVol σ δ T n) T))) + = fun y ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot 1 k Λ n * Phi (bsd1 (y * mertonSpot 1 k Λ n) K r (mertonVol σ δ T n) T)) := by + funext y + rw [mertonSpot_eq_mul_one y] + rw [hfun] + refine ((hphi.const_mul (mertonSpot 1 k Λ n)).const_mul + (rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n !)).congr_deriv ?_ + rw [mertonSpot_eq_mul_one s] + congr 1 + calc mertonSpot 1 k Λ n + * (gaussianPDFReal 0 1 (bsd1 (s * mertonSpot 1 k Λ n) K r (mertonVol σ δ T n) T) + / (s * mertonSpot 1 k Λ n * mertonVol σ δ T n * Real.sqrt T) * mertonSpot 1 k Λ n) + = mertonSpot 1 k Λ n + * (mertonSpot 1 k Λ n + * gaussianPDFReal 0 1 (bsd1 (s * mertonSpot 1 k Λ n) K r (mertonVol σ δ T n) T)) + / (mertonSpot 1 k Λ n * (s * mertonVol σ δ T n * Real.sqrt T)) := by + ring + _ = mertonSpot 1 k Λ n + * gaussianPDFReal 0 1 (bsd1 (s * mertonSpot 1 k Λ n) K r (mertonVol σ δ T n) T) + / (s * mertonVol σ δ T n * Real.sqrt T) := + mul_div_mul_left _ _ (hc n).ne' + have hbound (n : ℕ) (s : ℝ) (hs : s ∈ Ioi (S / 2)) : + ‖rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot 1 k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot s k Λ n) K r (mertonVol σ δ T n) T) + / (s * mertonVol σ δ T n * Real.sqrt T))‖ + ≤ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonSpot 1 k Λ n + * (S / 2 * σ * Real.sqrt T)⁻¹ := by + have hs' : S / 2 < s := hs + have hs0 : 0 < s := hS2.trans hs' + have hden : S / 2 * σ * Real.sqrt T ≤ s * mertonVol σ δ T n * Real.sqrt T := + mul_le_mul_of_nonneg_right (mul_le_mul hs'.le (le_mertonVol δ hσ.le hT n) hσ.le hs0.le) + hsT.le + have hfrac : mertonSpot 1 k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot s k Λ n) K r (mertonVol σ δ T n) T) + / (s * mertonVol σ δ T n * Real.sqrt T) + ≤ mertonSpot 1 k Λ n / (S / 2 * σ * Real.sqrt T) := + div_le_div₀ (hc n).le + (mul_le_of_le_one_right (hc n).le (gaussianPDFReal_zero_one_le_one _)) + (mul_pos (mul_pos hS2 hσ) hsT) hden + calc ‖rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot 1 k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot s k Λ n) K r (mertonVol σ δ T n) T) + / (s * mertonVol σ δ T n * Real.sqrt T))‖ + = rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot 1 k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot s k Λ n) K r (mertonVol σ δ T n) T) + / (s * mertonVol σ δ T n * Real.sqrt T)) := + Real.norm_of_nonneg (mul_nonneg (hw n) (div_nonneg + (mul_nonneg (hc n).le (gaussianPDFReal_nonneg 0 1 _)) + (mul_pos (mul_pos hs0 (hv n)) hsT).le)) + _ ≤ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * (mertonSpot 1 k Λ n / (S / 2 * σ * Real.sqrt T)) := + mul_le_mul_of_nonneg_left hfrac (hw n) + _ = rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonSpot 1 k Λ n + * (S / 2 * σ * Real.sqrt T)⁻¹ := by + ring + exact hasDerivAt_tsum_of_isPreconnected + ((hasSum_weights_mul_mertonSpot_one k Λ).summable.mul_right _) isOpen_Ioi isPreconnected_Ioi + hterm hbound (half_lt_self hS) (summable_mertonDelta_terms hk S) (half_lt_self hS) + +/-- **Gamma of the Merton call**, for the price itself: `∂²C/∂S² = mertonGamma`. The delta series +is `∂C/∂S` on all of `S > 0` (`hasDerivAt_mertonCallPrice_spot`), so near `S` the derivative of +the price is the delta series, whose derivative is the gamma series (`hasDerivAt_mertonDelta`). -/ +theorem hasDerivAt_deriv_mertonCallPrice_spot (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) + (hk : -1 < k) {S : ℝ} (hS : 0 < S) : + HasDerivAt (deriv fun s ↦ mertonCallPrice s K r σ T k δ Λ) (mertonGamma S K r σ T k δ Λ) S := + hasDerivAt_deriv_of_eventually + ((eventually_gt_nhds hS).mono fun _ hy ↦ hasDerivAt_mertonCallPrice_spot hK hσ hT hk hy) + (hasDerivAt_mertonDelta hK hσ hT hk hS) + +/-- **The Merton gamma is positive.** Every term is nonnegative and the no-jump term is +positive. -/ +theorem mertonGamma_pos (hσ : 0 < σ) (hT : 0 < T) (hk : -1 < k) {S : ℝ} (hS : 0 < S) : + 0 < mertonGamma S K r σ T k δ Λ := by + have hc (n : ℕ) : 0 < mertonSpot 1 k Λ n := mertonSpot_pos one_pos hk Λ n + have hden (n : ℕ) : 0 < S * mertonVol σ δ T n * Real.sqrt T := + mul_pos (mul_pos hS (mertonVol_pos hσ hT n)) (Real.sqrt_pos.mpr hT) + have hterm (n : ℕ) : 0 ≤ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot 1 k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot S k Λ n) K r (mertonVol σ δ T n) T) + / (S * mertonVol σ δ T n * Real.sqrt T)) := + mul_nonneg (by positivity) + (div_nonneg (mul_nonneg (hc n).le (gaussianPDFReal_nonneg 0 1 _)) (hden n).le) + have hsum : Summable fun n : ℕ ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot 1 k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot S k Λ n) K r (mertonVol σ δ T n) T) + / (S * mertonVol σ δ T n * Real.sqrt T)) := by + refine Summable.of_nonneg_of_le hterm (fun n ↦ ?_) + ((hasSum_weights_mul_mertonSpot_one k Λ).summable.mul_right (S * σ * Real.sqrt T)⁻¹) + calc rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot 1 k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot S k Λ n) K r (mertonVol σ δ T n) T) + / (S * mertonVol σ δ T n * Real.sqrt T)) + ≤ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * (mertonSpot 1 k Λ n / (S * σ * Real.sqrt T)) := + mul_le_mul_of_nonneg_left (div_le_div₀ (hc n).le + (mul_le_of_le_one_right (hc n).le (gaussianPDFReal_zero_one_le_one _)) + (mul_pos (mul_pos hS hσ) (Real.sqrt_pos.mpr hT)) + (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left (le_mertonVol δ hσ.le hT n) + hS.le) (Real.sqrt_nonneg T))) (by positivity) + _ = rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonSpot 1 k Λ n + * (S * σ * Real.sqrt T)⁻¹ := by + ring + refine hsum.tsum_pos hterm 0 ?_ + rw [pow_zero, Nat.factorial_zero, Nat.cast_one, mul_one, div_one] + exact mul_pos (Real.exp_pos _) + (div_pos (mul_pos (hc 0) (gaussianPDFReal_pos 0 1 _ one_ne_zero)) (hden 0)) + +/-! ### Vega -/ + +/-- The conditional volatility `σₙ = √(σ² + nδ²/T)` has `σ`-derivative `σ/σₙ`. -/ +lemma hasDerivAt_mertonVol_sigma (δ : ℝ) (hT : 0 < T) (n : ℕ) (hσ : 0 < σ) : + HasDerivAt (fun s ↦ mertonVol s δ T n) (σ / mertonVol σ δ T n) σ := by + have h0 : σ ^ 2 + (n : ℝ) * δ ^ 2 / T ≠ 0 := by positivity + have h := ((hasDerivAt_pow 2 σ).add_const ((n : ℝ) * δ ^ 2 / T)).sqrt h0 + unfold mertonVol + refine h.congr_deriv ?_ + rw [show ((2 : ℕ) : ℝ) * σ ^ (2 - 1) = 2 * σ by norm_num, mul_div_mul_left σ _ two_ne_zero] + +/-- **The Merton vega**: `∑ₙ wₙ S cₙ ϕ(d₁ⁿ) √T · σ/σₙ`, the Poisson mixture of the Black–Scholes +vegas at the conditional spots and volatilities, each multiplied by `∂σₙ/∂σ = σ/σₙ`. -/ +noncomputable def mertonVega (S K r σ T k δ : ℝ) (Λ : ℝ≥0) : ℝ := + ∑' n : ℕ, rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot S k Λ n * gaussianPDFReal 0 1 (bsd1 (mertonSpot S k Λ n) K r (mertonVol σ δ T n) T) + * Real.sqrt T * (σ / mertonVol σ δ T n)) + +/-- **Vega of the Merton call.** `∂C/∂σ = mertonVega = ∑ₙ wₙ S cₙ ϕ(d₁ⁿ) √T · σ/σₙ` at every +`σ > 0`. The series is differentiated term by term: each term's `σ`-derivative is at most +`wₙ · S cₙ √T`, since `ϕ ≤ 1` and `σ ≤ σₙ`, and those bounds sum to `S√T`. -/ +theorem hasDerivAt_mertonCallPrice_sigma {S : ℝ} (hS : 0 < S) (hK : 0 < K) (hT : 0 < T) + (hk : -1 < k) (hσ : 0 < σ) : + HasDerivAt (fun s ↦ mertonCallPrice S K r s T k δ Λ) (mertonVega S K r σ T k δ Λ) σ := by + have hw (n : ℕ) : 0 ≤ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! := by positivity + have hspot (n : ℕ) : 0 < mertonSpot S k Λ n := mertonSpot_pos hS hk Λ n + have hterm (n : ℕ) (s : ℝ) (hs : s ∈ Ioi (0 : ℝ)) : + HasDerivAt + (fun y ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonCallTerm S K r y T k δ Λ n) + (rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot S k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot S k Λ n) K r (mertonVol s δ T n) T) + * Real.sqrt T * (s / mertonVol s δ T n))) s := by + have hfun : (fun y ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonCallTerm S K r y T k δ Λ n) + = fun y ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! + * bsV K r (mertonVol y δ T n) (mertonSpot S k Λ n) T := by + funext y + rw [mertonCallTerm_eq_bsV] + rw [hfun] + exact ((hasDerivAt_bsV_sigma (r := r) hK (hspot n) (mertonVol_pos hs hT n) hT).comp s + (hasDerivAt_mertonVol_sigma δ hT n hs)).const_mul _ + have hbound (n : ℕ) (s : ℝ) (hs : s ∈ Ioi (0 : ℝ)) : + ‖rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot S k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot S k Λ n) K r (mertonVol s δ T n) T) + * Real.sqrt T * (s / mertonVol s δ T n))‖ + ≤ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonSpot S k Λ n * Real.sqrt T := by + have hs0 : 0 < s := hs + have hv : 0 < mertonVol s δ T n := mertonVol_pos hs0 hT n + have hq0 : 0 ≤ s / mertonVol s δ T n := div_nonneg hs0.le hv.le + have hq1 : s / mertonVol s δ T n ≤ 1 := (div_le_one hv).mpr (le_mertonVol δ hs0.le hT n) + have hphi := gaussianPDFReal_zero_one_le_one + (bsd1 (mertonSpot S k Λ n) K r (mertonVol s δ T n) T) + have hphi0 := gaussianPDFReal_nonneg 0 1 (bsd1 (mertonSpot S k Λ n) K r (mertonVol s δ T n) T) + have hinner : mertonSpot S k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot S k Λ n) K r (mertonVol s δ T n) T) + * Real.sqrt T * (s / mertonVol s δ T n) + ≤ mertonSpot S k Λ n * Real.sqrt T := by + calc mertonSpot S k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot S k Λ n) K r (mertonVol s δ T n) T) + * Real.sqrt T * (s / mertonVol s δ T n) + ≤ mertonSpot S k Λ n * 1 * Real.sqrt T * 1 := + mul_le_mul (mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left hphi (hspot n).le) (Real.sqrt_nonneg T)) hq1 hq0 + (mul_nonneg (mul_nonneg (hspot n).le zero_le_one) (Real.sqrt_nonneg T)) + _ = mertonSpot S k Λ n * Real.sqrt T := by ring + calc ‖rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot S k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot S k Λ n) K r (mertonVol s δ T n) T) + * Real.sqrt T * (s / mertonVol s δ T n))‖ + = rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot S k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot S k Λ n) K r (mertonVol s δ T n) T) + * Real.sqrt T * (s / mertonVol s δ T n)) := + Real.norm_of_nonneg (mul_nonneg (hw n) (mul_nonneg (mul_nonneg + (mul_nonneg (hspot n).le hphi0) (Real.sqrt_nonneg T)) hq0)) + _ ≤ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * (mertonSpot S k Λ n * Real.sqrt T) := + mul_le_mul_of_nonneg_left hinner (hw n) + _ = rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonSpot S k Λ n * Real.sqrt T := by ring + exact (hasDerivAt_tsum_of_isPreconnected + ((summable_weights_mul_mertonSpot S k Λ).mul_right (Real.sqrt T)) isOpen_Ioi + isPreconnected_Ioi hterm hbound hσ (summable_weights_mul_mertonCallTerm hS hK hσ hT hk) + hσ).congr_of_eventuallyEq + (Eventually.of_forall fun s ↦ mertonCallPrice_eq_tsum S K r s T k δ Λ) + +/-- **The Merton vega is positive.** Every term is nonnegative and the no-jump term is +positive. -/ +theorem mertonVega_pos {S : ℝ} (hS : 0 < S) (hT : 0 < T) (hk : -1 < k) (hσ : 0 < σ) : + 0 < mertonVega S K r σ T k δ Λ := by + have hspot (n : ℕ) : 0 < mertonSpot S k Λ n := mertonSpot_pos hS hk Λ n + have hterm (n : ℕ) : 0 ≤ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot S k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot S k Λ n) K r (mertonVol σ δ T n) T) + * Real.sqrt T * (σ / mertonVol σ δ T n)) := + mul_nonneg (by positivity) (mul_nonneg (mul_nonneg + (mul_nonneg (hspot n).le (gaussianPDFReal_nonneg 0 1 _)) (Real.sqrt_nonneg T)) + (div_nonneg hσ.le (mertonVol_pos hσ hT n).le)) + have hsum : Summable fun n : ℕ ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot S k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot S k Λ n) K r (mertonVol σ δ T n) T) + * Real.sqrt T * (σ / mertonVol σ δ T n)) := by + refine Summable.of_nonneg_of_le hterm (fun n ↦ ?_) + ((summable_weights_mul_mertonSpot S k Λ).mul_right (Real.sqrt T)) + have hv : 0 < mertonVol σ δ T n := mertonVol_pos hσ hT n + calc rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + (mertonSpot S k Λ n + * gaussianPDFReal 0 1 (bsd1 (mertonSpot S k Λ n) K r (mertonVol σ δ T n) T) + * Real.sqrt T * (σ / mertonVol σ δ T n)) + ≤ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * (mertonSpot S k Λ n * 1 * Real.sqrt T * 1) := + mul_le_mul_of_nonneg_left (mul_le_mul (mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (gaussianPDFReal_zero_one_le_one _) (hspot n).le) + (Real.sqrt_nonneg T)) ((div_le_one hv).mpr (le_mertonVol δ hσ.le hT n)) + (div_nonneg hσ.le hv.le) + (mul_nonneg (mul_nonneg (hspot n).le zero_le_one) (Real.sqrt_nonneg T))) + (by positivity) + _ = rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonSpot S k Λ n * Real.sqrt T := by ring + refine hsum.tsum_pos hterm 0 ?_ + rw [pow_zero, Nat.factorial_zero, Nat.cast_one, mul_one, div_one] + exact mul_pos (Real.exp_pos _) (mul_pos (mul_pos (mul_pos (hspot 0) + (gaussianPDFReal_pos 0 1 _ one_ne_zero)) (Real.sqrt_pos.mpr hT)) + (div_pos hσ (mertonVol_pos hσ hT 0))) + +/-! ### The shape of the price -/ + +/-- **The Merton call price strictly increases in the spot**, its delta being positive. -/ +theorem mertonCallPrice_strictMonoOn_spot (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) + (hk : -1 < k) : StrictMonoOn (fun s ↦ mertonCallPrice s K r σ T k δ Λ) (Ioi 0) := by + have h (s : ℝ) (hs : 0 < s) := + hasDerivAt_mertonCallPrice_spot (r := r) (δ := δ) (Λ := Λ) hK hσ hT hk hs + refine strictMonoOn_of_deriv_pos (convex_Ioi 0) + (fun s hs ↦ (h s hs).continuousAt.continuousWithinAt) fun s hs ↦ ?_ + rw [interior_Ioi] at hs + rw [(h s hs).deriv] + exact mertonDelta_pos hk s + +/-- **The Merton call price is strictly convex in the spot**: its delta strictly increases, the +gamma being positive. -/ +theorem mertonCallPrice_strictConvexOn_spot (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) + (hk : -1 < k) : StrictConvexOn ℝ (Ioi 0) fun s ↦ mertonCallPrice s K r σ T k δ Λ := by + have h (s : ℝ) (hs : 0 < s) := + hasDerivAt_mertonCallPrice_spot (r := r) (δ := δ) (Λ := Λ) hK hσ hT hk hs + have h2 (s : ℝ) (hs : 0 < s) := + hasDerivAt_deriv_mertonCallPrice_spot (r := r) (δ := δ) (Λ := Λ) hK hσ hT hk hs + refine StrictMonoOn.strictConvexOn_of_deriv (convex_Ioi 0) + (fun s hs ↦ (h s hs).continuousAt.continuousWithinAt) ?_ + rw [interior_Ioi] + refine strictMonoOn_of_deriv_pos (convex_Ioi 0) + (fun s hs ↦ (h2 s hs).continuousAt.continuousWithinAt) fun s hs ↦ ?_ + rw [interior_Ioi] at hs + rw [(h2 s hs).deriv] + exact mertonGamma_pos hσ hT hk hs + +/-- **The Merton call price strictly increases in the diffusion volatility**, its vega being +positive. -/ +theorem mertonCallPrice_strictMonoOn_sigma {S : ℝ} (hS : 0 < S) (hK : 0 < K) (hT : 0 < T) + (hk : -1 < k) : StrictMonoOn (fun s ↦ mertonCallPrice S K r s T k δ Λ) (Ioi 0) := by + have h (s : ℝ) (hs : 0 < s) := + hasDerivAt_mertonCallPrice_sigma (r := r) (δ := δ) (Λ := Λ) hS hK hT hk hs + refine strictMonoOn_of_deriv_pos (convex_Ioi 0) + (fun s hs ↦ (h s hs).continuousAt.continuousWithinAt) fun s hs ↦ ?_ + rw [interior_Ioi] at hs + rw [(h s hs).deriv] + exact mertonVega_pos hS hT hk hs + +end MathFin diff --git a/LeanPool/MathFin/Models/Jumps/MertonJumpDiffusion.lean b/LeanPool/MathFin/Models/Jumps/MertonJumpDiffusion.lean new file mode 100644 index 0000000000..bd4eb69532 --- /dev/null +++ b/LeanPool/MathFin/Models/Jumps/MertonJumpDiffusion.lean @@ -0,0 +1,357 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Put +public import LeanPool.MathFin.Probability.Jumps.PoissonPgf +public import LeanPool.MathFin.Models.BlackScholes.PDE +public import Mathlib.Algebra.Order.Star.Real + +/-! +# Merton (1976) jump-diffusion option pricing: the Poisson-mixture series + +Merton's jump-diffusion model prices a European option as a Poisson mixture +of Black–Scholes values: conditional on `n` jumps by maturity, the terminal +price is lognormal with a jump-adjusted spot and volatility, so + + `C_Merton = E_N[ C_BS(spot_N, vol_N) ], N ∼ Poisson(Λ)`. + +This file formalizes that *terminal mixture law*. With `k > −1` the mean +jump size (`E[Y] = 1 + k` for jump multiplier `Y`), `δ` the jump log-vol, +and `Λ` the expected number of jumps to maturity: + +* `mertonSpot S₀ k Λ n = S₀ e^{−kΛ} (1+k)^n` — the jump-*compensated* + conditional spot. The compensator `e^{−kΛ}` is Merton's risk-neutral + adjustment: jumps must not change the expected return. +* `mertonVol σ δ T n = √(σ² + n δ²/T)` — total conditional variance + `σ²T + nδ²` spread over `[0, T]`. +* `mertonCallPrice = ∫ n, mertonCallTerm n ∂(poissonMeasure Λ)` — the price + *is defined as the expectation over the jump count*; the textbook series + `∑ₙ e^{−Λ}Λⁿ/n! · C_BS(n)` is then a theorem (`mertonCallPrice_eq_tsum`), + not a definition. + +The classic display weights terms by the adjusted intensity `Λ' = Λ(1+k)` +with a shifted rate `r_n`; that form regroups the factor `(1+k)^n` from our +conditional spot into the weight — term-by-term the same series. + +## Main definitions + +* `mertonSpot`: the jump-compensated conditional spot after `n` jumps, `S₀ · e^{−kΛ} · (1+k)^n`. +* `mertonVol`: the conditional volatility given `n` jumps, `√(σ² + nδ²/T)`. +* `mertonCallTerm`, `mertonPutTerm`: the `n`-jump conditional Black–Scholes call and put values at + the conditional spot and volatility. +* `mertonCallPrice`, `mertonPutPrice`: the Merton (1976) call and put prices, the expectation of the + conditional values over the Poisson jump count. + +## Main results + +* `mertonCallTerm_eq_integral` / `mertonPutTerm_eq_integral` — each series + term *is* a discounted conditional expected payoff: `bs_call_formula` / + `bs_put_formula` instantiated on the canonical Gaussian space + `(ℝ, gaussianReal 0 1)` at the jump-adjusted parameters. This grounds the + mixture as an honest iterated expectation + (`mertonCallPrice_eq_iterated_expectation`). +* `integrable_mertonCallTerm` / `integrable_mertonPutTerm` — the mixture is + well-defined: conditional values are sandwiched in `[0, spot_n]` (resp. + `[0, Ke^{−rT}]`) and the weighted spots form a convergent exponential + series. +* `integral_mertonSpot` — **spot recombination (compensation identity)**: + `E[mertonSpot(N)] = S₀`. The Poisson pgf at `1 + k` makes the compensator + `e^{−kΛ}` exactly cancel the jump growth `E[(1+k)^N] = e^{kΛ}`: the + conditional forwards recombine to the true forward — the risk-neutral + consistency of Merton's decomposition. +* `merton_put_call_parity` — `C − P = S₀ − Ke^{−rT}`: parity survives jump + risk, *because* of the compensation identity. Term-wise BS parity gives + `∑ pmf(n)(spot_n − Ke^{−rT})`, and recombination collapses it. + +## Honest scope + +European pricing only needs the terminal law, and that is all this file +formalizes: the conditional-lognormal-given-Poisson-count mixture, exactly +parallel to how `BSCallHyp` *hypothesizes* the lognormal terminal law for +the diffusion-only model. The compound-Poisson *process* (jump SDE dynamics, +`S_t` as a càdlàg semimartingale) is upstream-gated and not claimed. + +## References + +* [R. C. Merton, *Option pricing when underlying stock returns are discontinuous*][Merton1976] + +## Tags + +Merton jump-diffusion, Poisson mixture, lognormal jumps, option pricing with jumps, +series of Black–Scholes prices, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal Nat + +/-! ### Conditional (given `n` jumps) Black–Scholes parameters -/ + +/-- Jump-compensated conditional spot after `n` jumps: +`S₀ · e^{−kΛ} · (1+k)^n`. The factor `e^{−kΛ}` is Merton's compensator — +the drift adjustment that keeps the expected return unchanged by jumps. -/ +noncomputable def mertonSpot (S_0 k : ℝ) (Λ : ℝ≥0) (n : ℕ) : ℝ := + S_0 * rexp (-(k * (Λ : ℝ))) * (1 + k) ^ n + +/-- Conditional volatility given `n` jumps: total log-variance +`σ²T + nδ²` spread over the horizon, `√(σ² + nδ²/T)`. -/ +noncomputable def mertonVol (σ δ T : ℝ) (n : ℕ) : ℝ := + Real.sqrt (σ ^ 2 + (n : ℝ) * δ ^ 2 / T) + +/-- The Merton jump-conditional spot is positive (`S₀`, the drift `exp`, and `(1+k)ⁿ` all positive). +-/ +lemma mertonSpot_pos {S_0 k : ℝ} (hS_0 : 0 < S_0) (hk : -1 < k) + (Λ : ℝ≥0) (n : ℕ) : 0 < mertonSpot S_0 k Λ n := by + have h1k : (0 : ℝ) < 1 + k := by linarith + exact mul_pos (mul_pos hS_0 (Real.exp_pos _)) (pow_pos h1k n) + +/-- The Merton jump-conditional volatility is positive (`σ > 0`; the radicand is a sum of +nonnegatives). -/ +lemma mertonVol_pos {σ δ T : ℝ} (hσ : 0 < σ) (hT : 0 < T) (n : ℕ) : + 0 < mertonVol σ δ T n := by + apply Real.sqrt_pos.mpr + have hσ2 : 0 < σ ^ 2 := pow_pos hσ 2 + have hnd : (0 : ℝ) ≤ (n : ℝ) * δ ^ 2 / T := + div_nonneg (mul_nonneg (Nat.cast_nonneg n) (sq_nonneg δ)) hT.le + linarith + +/-- `mertonVol n² · T = σ²T + nδ²`: the conditional log-variance over the horizon. -/ +lemma mertonVol_sq_mul (σ δ : ℝ) {T : ℝ} (hT : 0 < T) (n : ℕ) : + mertonVol σ δ T n ^ 2 * T = σ ^ 2 * T + n * δ ^ 2 := by + have h0 : 0 ≤ σ ^ 2 + (n : ℝ) * δ ^ 2 / T := by positivity + rw [mertonVol, Real.sq_sqrt h0, add_mul, div_mul_cancel₀ _ hT.ne'] + +/-! ### The conditional Black–Scholes values -/ + +/-- The `n`-jump conditional Black–Scholes call value +`spot_n Φ(d₁ⁿ) − K e^{−rT} Φ(d₂ⁿ)`. -/ +noncomputable def mertonCallTerm (S_0 K r σ T k δ : ℝ) (Λ : ℝ≥0) (n : ℕ) : ℝ := + mertonSpot S_0 k Λ n + * Phi (bsd1 (mertonSpot S_0 k Λ n) K r (mertonVol σ δ T n) T) + - K * rexp (-r * T) + * Phi (bsd2 (mertonSpot S_0 k Λ n) K r (mertonVol σ δ T n) T) + +/-- The `n`-jump conditional Black–Scholes put value +`K e^{−rT} Φ(−d₂ⁿ) − spot_n Φ(−d₁ⁿ)`. -/ +noncomputable def mertonPutTerm (S_0 K r σ T k δ : ℝ) (Λ : ℝ≥0) (n : ℕ) : ℝ := + K * rexp (-r * T) + * Phi (-(bsd2 (mertonSpot S_0 k Λ n) K r (mertonVol σ δ T n) T)) + - mertonSpot S_0 k Λ n + * Phi (-(bsd1 (mertonSpot S_0 k Λ n) K r (mertonVol σ δ T n) T)) + +/-- **Merton (1976) jump-diffusion call price**: the expectation, over the +Poisson jump count, of the conditional Black–Scholes call value. -/ +noncomputable def mertonCallPrice (S_0 K r σ T k δ : ℝ) (Λ : ℝ≥0) : ℝ := + ∫ n, mertonCallTerm S_0 K r σ T k δ Λ n ∂(poissonMeasure Λ) + +/-- **Merton (1976) jump-diffusion put price**. -/ +noncomputable def mertonPutPrice (S_0 K r σ T k δ : ℝ) (Λ : ℝ≥0) : ℝ := + ∫ n, mertonPutTerm S_0 K r σ T k δ Λ n ∂(poissonMeasure Λ) + +/-- Each conditional value *is* the Black–Scholes price function `bsV` at the +jump-adjusted spot and volatility: the Merton mixture averages genuine BS +prices. The bridge consumed by `MertonDominance` and `MertonClassicDisplay`. -/ +theorem mertonCallTerm_eq_bsV (S_0 K r σ T k δ : ℝ) (Λ : ℝ≥0) (n : ℕ) : + mertonCallTerm S_0 K r σ T k δ Λ n + = bsV K r (mertonVol σ δ T n) (mertonSpot S_0 k Λ n) T := by + unfold mertonCallTerm bsV + simp only [neg_mul] + +/-! ### Each term is an honest discounted expected payoff -/ + +/-- Each Merton call term is the discounted conditional expected payoff: +`bs_call_formula` on the canonical Gaussian space `(ℝ, gaussianReal 0 1)` +at the jump-adjusted spot and volatility. -/ +theorem mertonCallTerm_eq_integral {S_0 K r σ T k : ℝ} (δ : ℝ) (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (hk : -1 < k) + (n : ℕ) : + mertonCallTerm S_0 K r σ T k δ Λ n + = ∫ z, rexp (-r * T) * + max (bsTerminal (mertonSpot S_0 k Λ n) r (mertonVol σ δ T n) T z - K) 0 + ∂(gaussianReal 0 1) := + (bs_call_formula (Q := gaussianReal 0 1) (Z := id) + ⟨mertonSpot_pos hS_0 hk Λ n, hK, mertonVol_pos hσ hT n, hT, HasLaw.id⟩).symm + +/-- Each Merton put term is the discounted conditional expected payoff: +`bs_put_formula` at the jump-adjusted parameters. -/ +theorem mertonPutTerm_eq_integral {S_0 K r σ T k : ℝ} (δ : ℝ) (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (hk : -1 < k) + (n : ℕ) : + mertonPutTerm S_0 K r σ T k δ Λ n + = ∫ z, rexp (-r * T) * + max (K - bsTerminal (mertonSpot S_0 k Λ n) r (mertonVol σ δ T n) T z) 0 + ∂(gaussianReal 0 1) := + (bs_put_formula (Q := gaussianReal 0 1) (Z := id) + ⟨mertonSpot_pos hS_0 hk Λ n, hK, mertonVol_pos hσ hT n, hT, HasLaw.id⟩).symm + +/-! ### Sandwich bounds for the conditional values + +`Phi_nonneg` comes from `Probability/Gaussian/StandardNormal.lean`, `Phi_le_one` from +`Models/ModelFree/PriceBounds.lean` (non-public import above). -/ + +lemma mertonCallTerm_nonneg {S_0 K r σ T k : ℝ} (δ : ℝ) (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (hk : -1 < k) + (n : ℕ) : 0 ≤ mertonCallTerm S_0 K r σ T k δ Λ n := by + rw [mertonCallTerm_eq_integral δ Λ hS_0 hK hσ hT hk n] + exact integral_nonneg fun z ↦ + mul_nonneg (Real.exp_pos _).le (le_max_right _ _) + +lemma mertonCallTerm_le_spot {S_0 K r σ T k : ℝ} (δ : ℝ) (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hK : 0 < K) (hk : -1 < k) (n : ℕ) : + mertonCallTerm S_0 K r σ T k δ Λ n ≤ mertonSpot S_0 k Λ n := by + have hS := (mertonSpot_pos hS_0 hk Λ n).le + have hKr : 0 ≤ K * rexp (-r * T) + * Phi (bsd2 (mertonSpot S_0 k Λ n) K r (mertonVol σ δ T n) T) := + mul_nonneg (mul_nonneg hK.le (Real.exp_pos _).le) (Phi_nonneg _) + have hΦ := mul_le_of_le_one_right hS + (Phi_le_one (bsd1 (mertonSpot S_0 k Λ n) K r (mertonVol σ δ T n) T)) + unfold mertonCallTerm + linarith + +lemma mertonPutTerm_nonneg {S_0 K r σ T k : ℝ} (δ : ℝ) (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (hk : -1 < k) + (n : ℕ) : 0 ≤ mertonPutTerm S_0 K r σ T k δ Λ n := by + rw [mertonPutTerm_eq_integral δ Λ hS_0 hK hσ hT hk n] + exact integral_nonneg fun z ↦ + mul_nonneg (Real.exp_pos _).le (le_max_right _ _) + +lemma mertonPutTerm_le_strike {S_0 K r σ T k : ℝ} (δ : ℝ) (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hK : 0 < K) (hk : -1 < k) (n : ℕ) : + mertonPutTerm S_0 K r σ T k δ Λ n ≤ K * rexp (-r * T) := by + have hS0 : 0 ≤ mertonSpot S_0 k Λ n + * Phi (-(bsd1 (mertonSpot S_0 k Λ n) K r (mertonVol σ δ T n) T)) := + mul_nonneg (mertonSpot_pos hS_0 hk Λ n).le (Phi_nonneg _) + have hΦ := mul_le_of_le_one_right (mul_nonneg hK.le (Real.exp_pos (-r * T)).le) + (Phi_le_one (-(bsd2 (mertonSpot S_0 k Λ n) K r (mertonVol σ δ T n) T))) + unfold mertonPutTerm + linarith + +/-! ### Well-definedness: the mixture is integrable -/ + +/-- The Poisson-weighted conditional spots form a convergent (exponential) +series — the quantitative heart of the mixture's well-definedness. -/ +lemma summable_weights_mul_mertonSpot (S_0 k : ℝ) (Λ : ℝ≥0) : + Summable (fun n : ℕ ↦ + rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonSpot S_0 k Λ n) := by + refine ((PoissonPgf.hasSum_poisson_weights_mul_pow Λ (1 + k)).summable.mul_left + (S_0 * rexp (-(k * (Λ : ℝ))))).congr fun n ↦ ?_ + unfold mertonSpot + ring + +lemma integrable_mertonCallTerm {S_0 K r σ T k : ℝ} (δ : ℝ) (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (hk : -1 < k) : + Integrable (mertonCallTerm S_0 K r σ T k δ Λ) (poissonMeasure Λ) := by + rw [integrable_poissonMeasure_iff] + refine Summable.of_nonneg_of_le (fun n ↦ by positivity) (fun n ↦ ?_) + (summable_weights_mul_mertonSpot S_0 k Λ) + have hterm : ‖mertonCallTerm S_0 K r σ T k δ Λ n‖ + ≤ mertonSpot S_0 k Λ n := by + rw [Real.norm_eq_abs, + abs_of_nonneg (mertonCallTerm_nonneg δ Λ hS_0 hK hσ hT hk n)] + exact mertonCallTerm_le_spot δ Λ hS_0 hK hk n + exact mul_le_mul_of_nonneg_left hterm (by positivity) + +lemma integrable_mertonPutTerm {S_0 K r σ T k : ℝ} (δ : ℝ) (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (hk : -1 < k) : + Integrable (mertonPutTerm S_0 K r σ T k δ Λ) (poissonMeasure Λ) := by + rw [integrable_poissonMeasure_iff] + refine Summable.of_nonneg_of_le (fun n ↦ by positivity) (fun n ↦ ?_) + ((hasSum_one_poissonMeasure Λ).summable.mul_right (K * rexp (-r * T))) + have hterm : ‖mertonPutTerm S_0 K r σ T k δ Λ n‖ ≤ K * rexp (-r * T) := by + rw [Real.norm_eq_abs, + abs_of_nonneg (mertonPutTerm_nonneg δ Λ hS_0 hK hσ hT hk n)] + exact mertonPutTerm_le_strike δ Λ hS_0 hK hk n + exact mul_le_mul_of_nonneg_left hterm (by positivity) + +lemma integrable_mertonSpot {S_0 k : ℝ} (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hk : -1 < k) : + Integrable (mertonSpot S_0 k Λ) (poissonMeasure Λ) := by + rw [integrable_poissonMeasure_iff] + refine (summable_weights_mul_mertonSpot S_0 k Λ).congr fun n ↦ ?_ + rw [Real.norm_eq_abs, abs_of_nonneg (mertonSpot_pos hS_0 hk Λ n).le] + +/-! ### The textbook series, the iterated expectation, and the +compensation identity -/ + +/-- **The Merton series.** The price expands to the textbook Poisson-weighted +sum of conditional Black–Scholes values — no hypotheses needed: the integral +over `poissonMeasure` *is* the weighted series for real-valued integrands. -/ +theorem mertonCallPrice_eq_tsum (S_0 K r σ T k δ : ℝ) (Λ : ℝ≥0) : + mertonCallPrice S_0 K r σ T k δ Λ + = ∑' n : ℕ, rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! + * mertonCallTerm S_0 K r σ T k δ Λ n := by + unfold mertonCallPrice + rw [integral_poissonMeasure] + simp_rw [smul_eq_mul] + +/-- **The Merton price as an iterated expectation**: outer expectation over +the Poisson jump count, inner discounted expected payoff under the +conditional lognormal — the honest mixture-pricing form. -/ +theorem mertonCallPrice_eq_iterated_expectation {S_0 K r σ T k : ℝ} + (δ : ℝ) (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (hk : -1 < k) : + mertonCallPrice S_0 K r σ T k δ Λ + = ∫ n, (∫ z, rexp (-r * T) * + max (bsTerminal (mertonSpot S_0 k Λ n) r (mertonVol σ δ T n) T z - K) 0 + ∂(gaussianReal 0 1)) ∂(poissonMeasure Λ) := + integral_congr_ae (ae_of_all _ fun n ↦ + mertonCallTerm_eq_integral δ Λ hS_0 hK hσ hT hk n) + +/-- **Spot recombination (Merton's compensation identity)**: +`E[mertonSpot(N)] = S₀`. The compensator `e^{−kΛ}` exactly cancels the +expected jump growth `E[(1+k)^N] = e^{kΛ}` (the Poisson pgf at `1+k`): the +conditional forwards recombine to the true forward. No hypotheses — the +identity is exact for all `k` and `Λ`. -/ +theorem integral_mertonSpot (S_0 k : ℝ) (Λ : ℝ≥0) : + ∫ n, mertonSpot S_0 k Λ n ∂(poissonMeasure Λ) = S_0 := by + rw [integral_poissonMeasure] + simp_rw [smul_eq_mul] + rw [tsum_congr (fun n ↦ show + rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonSpot S_0 k Λ n + = (S_0 * rexp (-(k * (Λ : ℝ)))) + * (rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * (1 + k) ^ n) from by + unfold mertonSpot; ring), + tsum_mul_left, PoissonPgf.tsum_poisson_weights_mul_pow, + show (1 + k - 1 : ℝ) = k from by ring, + mul_assoc, ← Real.exp_add, + show -(k * (Λ : ℝ)) + (Λ : ℝ) * k = 0 from by ring, + Real.exp_zero, mul_one] + +/-- **Term-wise put–call parity** for the conditional values: pure +`Φ(x) + Φ(−x) = 1` algebra, no hypotheses. -/ +theorem mertonTerm_parity (S_0 K r σ T k δ : ℝ) (Λ : ℝ≥0) (n : ℕ) : + mertonCallTerm S_0 K r σ T k δ Λ n - mertonPutTerm S_0 K r σ T k δ Λ n + = mertonSpot S_0 k Λ n - K * rexp (-r * T) := by + unfold mertonCallTerm mertonPutTerm + linear_combination + mertonSpot S_0 k Λ n + * Phi_add_Phi_neg (bsd1 (mertonSpot S_0 k Λ n) K r (mertonVol σ δ T n) T) + - K * rexp (-r * T) + * Phi_add_Phi_neg (bsd2 (mertonSpot S_0 k Λ n) K r (mertonVol σ δ T n) T) + +/-- **Merton put–call parity**: `C − P = S₀ − K e^{−rT}`. Parity survives +jump risk *because of* the compensation identity: term-wise BS parity leaves +`E[mertonSpot(N)] − Ke^{−rT}`, and spot recombination collapses the +expectation to `S₀`. -/ +theorem merton_put_call_parity {S_0 K r σ T k : ℝ} (δ : ℝ) (Λ : ℝ≥0) + (hS_0 : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) (hk : -1 < k) : + mertonCallPrice S_0 K r σ T k δ Λ - mertonPutPrice S_0 K r σ T k δ Λ + = S_0 - K * rexp (-r * T) := by + unfold mertonCallPrice mertonPutPrice + rw [← integral_sub (integrable_mertonCallTerm δ Λ hS_0 hK hσ hT hk) + (integrable_mertonPutTerm δ Λ hS_0 hK hσ hT hk), + integral_congr_ae (ae_of_all _ fun n ↦ + mertonTerm_parity S_0 K r σ T k δ Λ n), + integral_sub (integrable_mertonSpot Λ hS_0 hk) (integrable_const _), + integral_mertonSpot, integral_const, probReal_univ, one_smul] + +end MathFin diff --git a/LeanPool/MathFin/Models/Jumps/MertonStrikeGreeks.lean b/LeanPool/MathFin/Models/Jumps/MertonStrikeGreeks.lean new file mode 100644 index 0000000000..b1ef56cfe5 --- /dev/null +++ b/LeanPool/MathFin/Models/Jumps/MertonStrikeGreeks.lean @@ -0,0 +1,198 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Jumps.MertonGreeks +public import LeanPool.MathFin.Models.ModelFree.BreedenLitzenberger + +/-! +# Merton's digital and Merton's density: the strike derivatives of Merton's series + +Merton's call price is a Poisson mixture of Black–Scholes prices, +`C(K) = ∑ₙ wₙ C_BS(S·cₙ, K, σₙ)` (`mertonCallPrice`; the weights `wₙ`, the jump factors `cₙ` and +the volatilities `σₙ` are those of `MertonGreeks.lean`). As in the spot, the series can be +differentiated term by term in the strike, and its strike derivatives are the Poisson mixtures of +the Black–Scholes ones. + +* `hasDerivAt_mertonCallPrice_strike`: `∂C/∂K = −D`, where `D = mertonDigitalPrice` is the + Poisson mixture `∑ₙ wₙ e^{−rT}Φ(d₂ⁿ)` of the Black–Scholes cash-or-nothing prices + `bsCashDigital` (term by term, `hasDerivAt_bsV_K`). Each term's derivative is at most + `wₙe^{−rT}`, and the weights sum to one. +* `hasDerivAt_mertonDigitalPrice_strike`: `∂D/∂K = −e^{−rT}·mertonTerminalPDF`, where + `mertonTerminalPDF = ∑ₙ wₙ·lognormalTerminalPDF(S·cₙ, r, σₙ, T, K)` is the Poisson mixture of + the lognormal density formulas (term by term, `hasDerivAt_bsCashDigital_K`). On `(K/2, ∞)` each + term's derivative is at most `wₙe^{−rT}/((K/2)σ√T)`, since `ϕ ≤ 1` and `σₙ ≥ σ`. +* `hasDerivAt_deriv_mertonCallPrice_strike`: Merton's Breeden–Litzenberger formula, + `∂²C/∂K² = e^{−rT}·mertonTerminalPDF`. + +With log-jumps `N(log(1 + k) − δ²/2, δ²)` at the compensated drift `b = r − σ²/2 − Λk`, the two +series at maturity `τ` and expected jump count `Λτ` are the digital price and the density of the +price of the jump-diffusion (`jumpDiffusionDigitalPrice_gaussian_eq_mertonDigitalPrice`, +`jumpDiffusionDensity_gaussian_div_eq_mertonTerminalPDF`, in +`Models/Jumps/JumpDiffusionDigital.lean`). + +## Main definitions + +* `mertonDigitalPrice`: `∑ₙ wₙ e^{−rT}Φ(d₂ⁿ)`, the Poisson mixture of Black–Scholes cash-or-nothing + prices at the conditional spots and volatilities. +* `mertonTerminalPDF`: `∑ₙ wₙ · lognormalTerminalPDF(S·cₙ, r, σₙ, T, K)`, the Poisson mixture of + the lognormal density formulas at the strike `K`. + +## Main results + +* `hasDerivAt_mertonCallPrice_strike`: for `S, σ, T, K > 0` and `k > −1`, the strike derivative of + Merton's call price is minus Merton's digital price. +* `hasDerivAt_mertonDigitalPrice_strike`: the strike derivative of Merton's digital price is minus + `e^{−rT}` times Merton's density `mertonTerminalPDF`. +* `hasDerivAt_deriv_mertonCallPrice_strike`: `∂²C/∂K² = e^{−rT} · mertonTerminalPDF` at every + `K > 0`. + +## References + +* [Breeden and Litzenberger, *Prices of state-contingent claims implicit in option + prices*][BreedenLitzenberger1978] +* [R. C. Merton, *Option pricing when underlying stock returns are discontinuous*][Merton1976] + +## Tags + +Merton digital, Merton density, strike derivatives, Breeden–Litzenberger, risk-neutral density, +jump-diffusion, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Real Set Filter ProbabilityTheory +open scoped NNReal Nat + +variable {K r σ T k δ : ℝ} {Λ : ℝ≥0} + +/-- **Merton's digital price**: `∑ₙ wₙ e^{−rT}Φ(d₂ⁿ)`, the Poisson mixture of the Black–Scholes +cash-or-nothing prices `bsCashDigital` at the conditional spots `S·cₙ` and volatilities `σₙ`. +With Gaussian log-jumps at the compensated drift it is the digital price of the jump-diffusion +(`jumpDiffusionDigitalPrice_gaussian_eq_mertonDigitalPrice`). -/ +noncomputable def mertonDigitalPrice (S K r σ T k δ : ℝ) (Λ : ℝ≥0) : ℝ := + ∑' n : ℕ, rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + bsCashDigital K r (mertonVol σ δ T n) (mertonSpot S k Λ n) T + +/-- **Merton's density** at the strike `K`: `∑ₙ wₙ·lognormalTerminalPDF(S·cₙ, r, σₙ, T, K)`, the +Poisson mixture of the lognormal density formulas at the conditional spots and volatilities. With +Gaussian log-jumps it is the density of the price at `K` +(`jumpDiffusionDensity_gaussian_div_eq_mertonTerminalPDF`). -/ +noncomputable def mertonTerminalPDF (S r σ T k δ : ℝ) (Λ : ℝ≥0) (K : ℝ) : ℝ := + ∑' n : ℕ, rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + lognormalTerminalPDF (mertonSpot S k Λ n) r (mertonVol σ δ T n) T K + +/-- Merton's density formula is nonnegative at `K > 0`: a Poisson mixture of the nonnegative +lognormal density formulas (`lognormalTerminalPDF_nonneg`). -/ +lemma mertonTerminalPDF_nonneg {S : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + 0 ≤ mertonTerminalPDF S r σ T k δ Λ K := + tsum_nonneg fun n ↦ mul_nonneg (by positivity) + (lognormalTerminalPDF_nonneg hK (mertonVol_pos hσ hT n) hT) + +/-- The digital series converges: its terms lie in `[0, wₙe^{−rT}]`. -/ +lemma summable_mertonDigitalPrice_terms (S K : ℝ) : + Summable fun n : ℕ ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + bsCashDigital K r (mertonVol σ δ T n) (mertonSpot S k Λ n) T := + Summable.of_nonneg_of_le + (fun n ↦ mul_nonneg (by positivity) (mul_nonneg (Real.exp_pos _).le (Phi_nonneg _))) + (fun n ↦ mul_le_mul_of_nonneg_left + (mul_le_of_le_one_right (Real.exp_pos _).le (Phi_le_one _)) (by positivity)) + ((hasSum_one_poissonMeasure Λ).summable.mul_right (rexp (-(r * T)))) + +/-- **The strike derivative of Merton's call price is minus Merton's digital price**: +`∂C/∂K = −∑ₙ wₙ e^{−rT}Φ(d₂ⁿ)`. The series of Black–Scholes prices is differentiated term by +term: each term's strike derivative is minus `wₙ` times a Black–Scholes digital +(`hasDerivAt_bsV_K`), at most `wₙe^{−rT}` in absolute value. -/ +theorem hasDerivAt_mertonCallPrice_strike {S : ℝ} (hS : 0 < S) (hσ : 0 < σ) (hT : 0 < T) + (hk : -1 < k) (hK : 0 < K) : + HasDerivAt (fun x ↦ mertonCallPrice S x r σ T k δ Λ) + (-mertonDigitalPrice S K r σ T k δ Λ) K := by + have hw (n : ℕ) : 0 ≤ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! := by positivity + have hterm (n : ℕ) (x : ℝ) (hx : x ∈ Ioi (0 : ℝ)) : + HasDerivAt (fun y ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * mertonCallTerm S y r σ T k δ Λ n) + (-(rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + bsCashDigital x r (mertonVol σ δ T n) (mertonSpot S k Λ n) T)) x := by + simp only [mertonCallTerm_eq_bsV] + exact ((hasDerivAt_bsV_K (r := r) (mertonSpot_pos hS hk Λ n) + (mertonVol_pos (δ := δ) hσ hT n) hx hT).const_mul _).congr_deriv (mul_neg _ _) + have hbound (n : ℕ) (x : ℝ) (_ : x ∈ Ioi (0 : ℝ)) : + ‖-(rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + bsCashDigital x r (mertonVol σ δ T n) (mertonSpot S k Λ n) T)‖ + ≤ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * rexp (-(r * T)) := by + have h0 : 0 ≤ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + bsCashDigital x r (mertonVol σ δ T n) (mertonSpot S k Λ n) T := + mul_nonneg (hw n) (mul_nonneg (Real.exp_pos _).le (Phi_nonneg _)) + rw [norm_neg, Real.norm_of_nonneg h0] + exact mul_le_mul_of_nonneg_left (mul_le_of_le_one_right (Real.exp_pos _).le (Phi_le_one _)) + (hw n) + exact ((hasDerivAt_tsum_of_isPreconnected ((hasSum_one_poissonMeasure Λ).summable.mul_right _) + isOpen_Ioi isPreconnected_Ioi hterm hbound hK + (summable_weights_mul_mertonCallTerm hS hK hσ hT hk) hK).congr_of_eventuallyEq + (Eventually.of_forall fun x ↦ mertonCallPrice_eq_tsum S x r σ T k δ Λ)).congr_deriv + (by rw [tsum_neg, mertonDigitalPrice]) + +/-- **The strike derivative of Merton's digital price is minus the discounted Merton density**: +`∂D/∂K = −e^{−rT}·∑ₙ wₙ·lognormalTerminalPDF(S·cₙ, r, σₙ, T, K)`, with `D = mertonDigitalPrice`. +Each term is a Black–Scholes digital, whose strike derivative is minus the discounted lognormal +density formula (`hasDerivAt_bsCashDigital_K`). On `(K/2, ∞)` each term's derivative is at most +`wₙe^{−rT}/((K/2)σ√T)` in absolute value, since `ϕ ≤ 1` and `σₙ ≥ σ`. -/ +theorem hasDerivAt_mertonDigitalPrice_strike {S : ℝ} (hS : 0 < S) (hσ : 0 < σ) (hT : 0 < T) + (hk : -1 < k) (hK : 0 < K) : + HasDerivAt (fun x ↦ mertonDigitalPrice S x r σ T k δ Λ) + (-(rexp (-(r * T)) * mertonTerminalPDF S r σ T k δ Λ K)) K := by + have hw (n : ℕ) : 0 ≤ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! := by positivity + have hsT : 0 < Real.sqrt T := Real.sqrt_pos.mpr hT + have hK2 : 0 < K / 2 := half_pos hK + have hterm (n : ℕ) (x : ℝ) (hx : x ∈ Ioi (K / 2)) : + HasDerivAt (fun y ↦ rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + bsCashDigital y r (mertonVol σ δ T n) (mertonSpot S k Λ n) T) + (-(rexp (-(r * T)) * (rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + lognormalTerminalPDF (mertonSpot S k Λ n) r (mertonVol σ δ T n) T x))) x := + ((hasDerivAt_bsCashDigital_K (r := r) (mertonSpot_pos hS hk Λ n) + (mertonVol_pos (δ := δ) hσ hT n) (hK2.trans hx) hT).const_mul _).congr_deriv + (by rw [lognormalTerminalPDF]; ring) + have hbound (n : ℕ) (x : ℝ) (hx : x ∈ Ioi (K / 2)) : + ‖-(rexp (-(r * T)) * (rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * + lognormalTerminalPDF (mertonSpot S k Λ n) r (mertonVol σ δ T n) T x))‖ + ≤ rexp (-(r * T)) * + (rexp (-(Λ : ℝ)) * (Λ : ℝ) ^ n / n ! * (K / 2 * σ * Real.sqrt T)⁻¹) := by + have hx' : K / 2 < x := hx + have hx0 : 0 < x := hK2.trans hx' + have hden : K / 2 * σ * Real.sqrt T ≤ x * mertonVol σ δ T n * Real.sqrt T := + mul_le_mul_of_nonneg_right (mul_le_mul hx'.le (le_mertonVol δ hσ.le hT n) hσ.le hx0.le) + hsT.le + have hL : lognormalTerminalPDF (mertonSpot S k Λ n) r (mertonVol σ δ T n) T x + ≤ (K / 2 * σ * Real.sqrt T)⁻¹ := + (div_le_div₀ zero_le_one (gaussianPDFReal_zero_one_le_one _) + (mul_pos (mul_pos hK2 hσ) hsT) hden).trans_eq (one_div _) + rw [norm_neg, Real.norm_of_nonneg (mul_nonneg (Real.exp_pos _).le (mul_nonneg (hw n) + (lognormalTerminalPDF_nonneg (S_0 := mertonSpot S k Λ n) (r := r) hx0 + (mertonVol_pos (δ := δ) hσ hT n) hT)))] + exact mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hL (hw n)) (Real.exp_pos _).le + exact (hasDerivAt_tsum_of_isPreconnected + (((hasSum_one_poissonMeasure Λ).summable.mul_right _).mul_left _) isOpen_Ioi + isPreconnected_Ioi hterm hbound (half_lt_self hK) (summable_mertonDigitalPrice_terms S K) + (half_lt_self hK)).congr_deriv (by rw [tsum_neg, tsum_mul_left, mertonTerminalPDF]) + +/-- **Merton's Breeden–Litzenberger formula**: `∂²C/∂K² = e^{−rT}·mertonTerminalPDF`, the +discounted Poisson mixture of lognormal density formulas. The strike derivative of the call price +is minus Merton's digital price on all of `K > 0` (`hasDerivAt_mertonCallPrice_strike`), and the +digital's strike derivative is minus the discounted density +(`hasDerivAt_mertonDigitalPrice_strike`). -/ +theorem hasDerivAt_deriv_mertonCallPrice_strike {S : ℝ} (hS : 0 < S) (hσ : 0 < σ) (hT : 0 < T) + (hk : -1 < k) (hK : 0 < K) : + HasDerivAt (deriv fun x ↦ mertonCallPrice S x r σ T k δ Λ) + (rexp (-(r * T)) * mertonTerminalPDF S r σ T k δ Λ K) K := + hasDerivAt_deriv_of_eventually + ((eventually_gt_nhds hK).mono fun _ hx ↦ hasDerivAt_mertonCallPrice_strike hS hσ hT hk hx) + ((hasDerivAt_mertonDigitalPrice_strike (r := r) (δ := δ) (Λ := Λ) hS hσ hT hk + hK).fun_neg.congr_deriv (neg_neg _)) + +end MathFin diff --git a/LeanPool/MathFin/Models/LocalVol/ForwardSmile.lean b/LeanPool/MathFin/Models/LocalVol/ForwardSmile.lean new file mode 100644 index 0000000000..10f3cffd87 --- /dev/null +++ b/LeanPool/MathFin/Models/LocalVol/ForwardSmile.lean @@ -0,0 +1,1103 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.PDE +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.Algebra.Ring.IsFormallyReal + +/-! +# Local-volatility skew of a tilted smile: Dupire's ratio and the rule of two (eq 10.8) + +Equation numbers are those of S. Bagaria, *Notes on Fixed Income Derivative Pricing* +(lecture notes), ch. 10. Dupire's ratio is B. Dupire, "Pricing with a smile", +*Risk* 7(1) (1994); its form in implied total variance is J. Gatheral, *The Volatility +Surface: A Practitioner's Guide*, Wiley (2006), ch. 1. No forward-start option, forward +smile or forward skew is modelled in this module. + +Setting: zero rates, one maturity axis `T`, log-moneyness `k = log(K/F)`, a fixed +forward `F > 0`. The smile surface of eq 10.7 is tilted by a parameter `ε` so that +first-order-in-ε readings extract the skew slope: + + `σ_BS(ε, k, T) = σ + ε·ψ₁·k/√(T+T₀)` (`smileSurface`; `σ > 0`, `T+T₀ > 0`) + +and the call prices on it are the `bsV` composites (`bsCallSmile`). Dupire's +zero-rates ratio + + `R(ε, k, T) = 2·∂_T C / (K²·∂²_K C)` (in `k`-form: `K²·∂²_K C = C_kk − C_k`) + +enters **as a definition** (`dupireRatio`) — the derivation of the ratio itself +from a local-vol model is not developed here. The headline results: + +* `dupireRatio_k_slope` — eq 10.8: for `F, σ, T, T₀ > 0`, the ATM k-slope of `R` has + ε-slope `2σψ₁·((3/2)T + 2T₀)/(T+T₀)^{3/2}` (with `(T+T₀)^{3/2}` rendered as + `(T+T₀)·√(T+T₀)`). The numerator `(3/2)T + 2T₀` is the one consistent with the + rule of two (`localSkew_zero`). +* `dupireRatio_sqrt_slope` — the σ_loc reading: the same slope for `√R` is + `localSkew ψ₁ T₀ T = ψ₁·((3/2)T + 2T₀)/(T+T₀)^{3/2}` — a first-order-in-ε reading of + the local-vol ATM skew implied by the surface (for `F, σ, T, T₀ > 0`), not the actual + skew of the `ε = 1` surface, which carries `O(ψ₁³)` corrections (not proved here). +* `localSkew_zero`, `tendsto_localSkew_nhds_zero`, `tendsto_localSkew_mul_sqrt_atTop` — + for `T₀ > 0` the closed form `localSkew` equals `2ψ₁/√T₀` at `T = 0`, twice the implied + ATM skew `ψ₁/√T₀` (the rule of two), tends to that value as `T → 0`, and behaves like + `(3/2)ψ₁/√T` as `T → ∞`. These are statements about the closed form; + `dupireRatio_sqrt_slope` identifies it with the skew of the surface only for `T > 0`. +* `smileSurface_skew_slope`, `dupireRatio_sqrt_slope_eq_mul_skew`, + `tendsto_dupireRatio_sqrt_slope_nhdsGT_zero` — the rule of two on the surface itself: the + first-order implied ATM skew is `ψ₁/√(T+T₀)`, the first-order local ATM skew is that times + `((3/2)T + 2T₀)/(T + T₀)` for every `T > 0`, and as `T → 0⁺` it tends to twice the implied + ATM skew at `T = 0`. All first order in ε, for this one-parameter family of surfaces. + +The notes' eq 10.9 reads a forward skew off `localSkew` as one half of it (the rule of two +run in reverse). That reading is a heuristic and is not formalized here. + +Method (no probability, no integration, no ODEs): everything is a one-variable +`HasDerivAt` chain rule through the Black form `Φ(d₊) − e^k·Φ(d₋)` in the +coordinates `(k, w)` with total variance `w = σ_tilde²T`. The key exact identity is +`dupireRatio_eq`: in these coordinates Dupire's ratio is the rational function +`w_T/(1 + δ)` with `δ = −k·w_k/w + w_k²·(k²−w−w²/4)/(4w²) + w_kk/2` — the +Gatheral form of the ratio specialized to this surface — after which the +ε/k-extraction is elementary calculus on explicit functions. The price is the +`bsV` of `MathFin.Models.BlackScholes.PDE`, with `bsd1`/`bsd2` unfolded to the `(k,w)` form +(`bsCallSmile_eq`). + +## Main definitions + +* `smileSurface`: the ε-tilted smile `σ_BS(ε, k, T) = σ + ε ψ₁ k / √(T + T₀)` in + log-moneyness `k = log(K/F)` at zero rates. +* `totalVar`: the total variance `smileSurface² · T` along the surface. +* `dpl`, `dmi`: `d₊ = (−k + w/2)/√w` and `d₋ = (−k − w/2)/√w` in `(k, w)` coordinates. +* `blackForm`: the forward-normalised zero-rate call `Φ(d₊) − e^k Φ(d₋)`. +* `bsCallSmile`: the call price `bsV` at strike `F e^k`, spot `F`, volatility `smileSurface` and + maturity `T`. +* `dupireRatio`: Dupire's zero-rate ratio `R = 2 C_T / (C_kk − C_k)` of `bsCallSmile`, taken as + a definition (it is not derived from a local-volatility model here). +* `wSlope`, `smileN`, `smileDelta`: the total-variance slope `∂_k w`, the numerator `w_T` and + the denominator deformation `δ` of the Gatheral form `R = w_T / (1 + δ)`. +* `localSkew`: the closed form `ψ₁ ((3/2) T + 2 T₀) / (T + T₀)^{3/2}`. + +## Main results + +* `bsCallSmile_eq`: for `F, T > 0` and a positive surface value, `bsCallSmile` equals + `F · blackForm k (totalVar …)`. +* `exp_mul_pdf_dmi`: for `w > 0`, `e^k ϕ(d₋) = ϕ(d₊)`. +* `dupireRatio_eq`: for `F, T, T + T₀ > 0` and a positive surface value, in `(k, w)` coordinates + `dupireRatio = smileN / (1 + smileDelta)`. +* `dupireRatio_k_slope`: for `F, σ, T, T₀ > 0`, the ε-derivative at `0` of the ATM `k`-slope of + `dupireRatio` is `2σψ₁ ((3/2)T + 2T₀) / ((T + T₀) √(T + T₀))`. +* `dupireRatio_sqrt_slope`: for `F, σ, T, T₀ > 0`, the same derivative for `√(dupireRatio)` is + `localSkew ψ₁ T₀ T`. +* `smileSurface_skew_slope`: the ε-derivative at `0` of the ATM `k`-slope of `smileSurface` is + `ψ₁ / √(T + T₀)`. +* `dupireRatio_sqrt_slope_eq_mul_skew`: the first-order local ATM skew is + `((3/2)T + 2T₀)/(T + T₀)` times the first-order implied ATM skew. +* `localSkew_zero`, `tendsto_localSkew_nhds_zero`: for `T₀ > 0`, `localSkew` at `T = 0`, and its + limit as `T → 0`, is `2 ψ₁ / √T₀`. +* `tendsto_dupireRatio_sqrt_slope_nhdsGT_zero`: as `T → 0⁺` the first-order local ATM skew tends + to twice the first-order implied ATM skew at `T = 0`. +* `tendsto_localSkew_mul_sqrt_atTop`: `localSkew ψ₁ T₀ T · √T → (3/2) ψ₁` as `T → ∞`. + +## References + +* [S. Bagaria, *Notes on Fixed Income Derivative Pricing*][BagariaFIDP], ch. 10 +* [B. Dupire, *Pricing with a smile*][Dupire1994] +* [J. Gatheral, *The Volatility Surface: A Practitioner's Guide*][Gatheral2006], ch. 1 + +## Tags + +local volatility skew, rule of two, Dupire ratio, volatility smile, total variance, skew, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + +namespace MathFin.ForwardSmile + +open ProbabilityTheory Real + +/-! ## The surface, the price, the ratio -/ + +/-- **Eq 10.7, ε-tilted**: the smile surface `σ_BS(ε,k,T) = σ + ε·ψ₁·k/√(T+T₀)` +in log-moneyness `k = log(K/F)` at zero rates, with the tilt parameter `ε` +inserted so first-order-in-ε readings extract the skew slope. At `ε = 0` (and at +`k = 0` for every `ε`) it is the ATM vol `σ`. -/ +noncomputable def smileSurface (σ ψ₁ T₀ ε k T : ℝ) : ℝ := σ + ε * ψ₁ * k / Real.sqrt (T + T₀) + +/-- The smile surface is positive whenever `T + T₀ > 0` and the tilt is smaller than the base: +`|ε·ψ₁·k| < σ·√(T+T₀)` (positivity cannot hold for arbitrary tilts — the surface +is negative once `ε·ψ₁·k < −σ·√(T+T₀)`). -/ +theorem smileSurface_pos {σ ψ₁ T₀ ε k T : ℝ} (hS : 0 < T + T₀) + (hb : |ε * ψ₁ * k| < σ * Real.sqrt (T + T₀)) : + 0 < smileSurface σ ψ₁ T₀ ε k T := by + have hs : 0 < Real.sqrt (T + T₀) := Real.sqrt_pos.mpr hS + rw [abs_lt] at hb + have hdiv : -σ < ε * ψ₁ * k / Real.sqrt (T + T₀) := by + rw [lt_div_iff₀ hs] + linarith [hb.1] + unfold smileSurface + linarith [hdiv] + +/-- At the money the tilt vanishes: the surface sits at the base vol `σ` for +every `ε`. -/ +theorem smileSurface_atm (σ ψ₁ T₀ ε T : ℝ) : smileSurface σ ψ₁ T₀ ε 0 T = σ := by + unfold smileSurface; norm_num + +/-- Total implied variance along the surface: `w = σ_BS²·T`. -/ +noncomputable def totalVar (σ ψ₁ T₀ ε k T : ℝ) : ℝ := smileSurface σ ψ₁ T₀ ε k T ^ 2 * T + +/-- The upper standardized normal argument in `(k, w)` coordinates: +`d₊ = (−k + w/2)/√w` (this is `bsd1 F (F·e^k) 0 σ_tilde T` at `w = σ_tilde²T`). -/ +noncomputable def dpl (k w : ℝ) : ℝ := (-k + w / 2) / Real.sqrt w + +/-- The lower standardized normal argument: `d₋ = (−k − w/2)/√w`. -/ +noncomputable def dmi (k w : ℝ) : ℝ := (-k - w / 2) / Real.sqrt w + +/-- `d₊ = −k/√w + √w/2`: the form in which `d₊` is written when `w` is a squared root variance +(for `w ≤ 0` both sides are `0`, as `√w = 0`). -/ +theorem dpl_eq (k w : ℝ) : dpl k w = -k / Real.sqrt w + Real.sqrt w / 2 := by + rw [dpl, add_div, div_right_comm, Real.div_sqrt] + +/-- `d₋ = −k/√w − √w/2`, as `dpl_eq`. -/ +theorem dmi_eq (k w : ℝ) : dmi k w = -k / Real.sqrt w - Real.sqrt w / 2 := by + rw [dmi, sub_div, div_right_comm, Real.div_sqrt] + +/-- The Black-76 call normalized by the forward: `c(k,w) = Φ(d₊) − e^k·Φ(d₋)`, +the zero-rates `bsV` in `(k, w)` coordinates. -/ +noncomputable def blackForm (k w : ℝ) : ℝ := Phi (dpl k w) - Real.exp k * Phi (dmi k w) + +/-- **The call price on the tilted surface**: the zero-rates +`bsV` at strike `K = F·e^k`, spot `S = F`, vol `σ_BS(ε,k,T)`, maturity `T`. -/ +noncomputable def bsCallSmile (F σ ψ₁ T₀ ε k T : ℝ) : ℝ := + bsV (F * Real.exp k) 0 (smileSurface σ ψ₁ T₀ ε k T) F T + +/-- **Dupire's zero-rates ratio in k-form** (the ratio as a +definition — its derivation from a local-vol model is not developed here): +`R = 2·C_T/(C_kk − C_k)`, using `K²·∂²_K C = C_kk − C_k` for +`K = F·e^k`. -/ +noncomputable def dupireRatio (F σ ψ₁ T₀ ε k T : ℝ) : ℝ := + 2 * deriv (fun t ↦ bsCallSmile F σ ψ₁ T₀ ε k t) T + / (deriv (fun x ↦ deriv (fun x ↦ bsCallSmile F σ ψ₁ T₀ ε x T) x) k + - deriv (fun x ↦ bsCallSmile F σ ψ₁ T₀ ε x T) k) + +/-! ## The `(k, w)` unfolding and the variance chains -/ + +/-- **The r=0, K=F·e^k magic identity**: `e^k·ϕ(d₋) = ϕ(d₊)` in `(k,w)` +coordinates — the k-form of the `bs_identity` at zero rates. It is +what makes every density term in the Dupire ratio collapse. -/ +theorem exp_mul_pdf_dmi {k w : ℝ} (hw : 0 < w) : + Real.exp k * gaussianPDFReal 0 1 (dmi k w) = gaussianPDFReal 0 1 (dpl k w) := by + have hsq : dpl k w ^ 2 - dmi k w ^ 2 = -(2 * k) := by + have hnum : (-k + w / 2) ^ 2 - (-k - w / 2) ^ 2 = -(2 * k) * w := by ring + have h1 : dpl k w ^ 2 = (-k + w / 2) ^ 2 / w := by + unfold dpl + rw [show ((-k + w / 2) / Real.sqrt w) ^ 2 = (-k + w / 2) ^ 2 / Real.sqrt w ^ 2 from by + ring, Real.sq_sqrt hw.le] + have h2 : dmi k w ^ 2 = (-k - w / 2) ^ 2 / w := by + unfold dmi + rw [show ((-k - w / 2) / Real.sqrt w) ^ 2 = (-k - w / 2) ^ 2 / Real.sqrt w ^ 2 from by + ring, Real.sq_sqrt hw.le] + rw [h1, h2, ← sub_div, hnum] + field_simp [hw.ne'] + unfold gaussianPDFReal + simp only [NNReal.coe_one, mul_one, sub_zero] + rw [← mul_assoc, mul_comm (Real.exp k) (Real.sqrt (2 * π))⁻¹, mul_assoc, + ← Real.exp_add, + show k + -(dmi k w) ^ 2 / 2 = -(dpl k w) ^ 2 / 2 from by linarith [hsq]] + +/-- **The `(k, w)` unfolding**: at zero rates with `K = F·e^k`, the `bsV` +composite on the tilted surface is the forward-normalized Black form at the +total variance `w = σ_BS²·T`. -/ +theorem bsCallSmile_eq {F σ ψ₁ T₀ ε k T : ℝ} (hF : 0 < F) (hT : 0 < T) + (hst : 0 < smileSurface σ ψ₁ T₀ ε k T) : + bsCallSmile F σ ψ₁ T₀ ε k T = F * blackForm k (totalVar σ ψ₁ T₀ ε k T) := by + have hlog : Real.log (F / (F * Real.exp k)) = -k := by + rw [show F / (F * Real.exp k) = (Real.exp k)⁻¹ by field_simp, Real.log_inv, Real.log_exp] + have hne : smileSurface σ ψ₁ T₀ ε k T * Real.sqrt T ≠ 0 := + mul_ne_zero hst.ne' (Real.sqrt_pos.mpr hT).ne' + have hsplit : Real.sqrt (smileSurface σ ψ₁ T₀ ε k T ^ 2 * T) + = smileSurface σ ψ₁ T₀ ε k T * Real.sqrt T := by + rw [Real.sqrt_mul (sq_nonneg _) T, Real.sqrt_sq hst.le] + have hbsd1 : bsd1 F (F * Real.exp k) 0 (smileSurface σ ψ₁ T₀ ε k T) T + = dpl k (totalVar σ ψ₁ T₀ ε k T) := by + unfold bsd1 dpl totalVar + rw [hlog, hsplit] + field_simp [hne] + ring + have hbsd2 : bsd2 F (F * Real.exp k) 0 (smileSurface σ ψ₁ T₀ ε k T) T + = dmi k (totalVar σ ψ₁ T₀ ε k T) := by + unfold bsd2 + rw [hbsd1] + unfold dmi dpl totalVar + rw [hsplit] + field_simp [hne] + rw [Real.sq_sqrt hT.le] + ring + unfold bsCallSmile bsV blackForm + rw [hbsd1, hbsd2] + norm_num [Real.exp_neg, Real.exp_zero] + ring + +/-- `∂_k σ_BS = ε·ψ₁/√(T+T₀)` — the surface is affine in `k`. -/ +private theorem hasDerivAt_smileSurface_k {σ ψ₁ T₀ ε T x : ℝ} : + HasDerivAt (fun y ↦ smileSurface σ ψ₁ T₀ ε y T) (ε * ψ₁ / Real.sqrt (T + T₀)) x := by + have h0 : HasDerivAt (fun y : ℝ ↦ σ + (ε * ψ₁ / Real.sqrt (T + T₀)) * y) + (ε * ψ₁ / Real.sqrt (T + T₀)) x := by + simpa using ((hasDerivAt_id x).const_mul (ε * ψ₁ / Real.sqrt (T + T₀))).add_const σ + refine h0.congr_of_eventuallyEq ?_ + filter_upwards with y + unfold smileSurface + field_simp + +/-- `∂_k w = 2·σ_tilde·(ε·ψ₁/√(T+T₀))·T` — the `k`-chain of the total variance. -/ +private theorem hasDerivAt_totalVar_k {σ ψ₁ T₀ ε T x : ℝ} : + HasDerivAt (fun y ↦ totalVar σ ψ₁ T₀ ε y T) + (2 * smileSurface σ ψ₁ T₀ ε x T * (ε * ψ₁ / Real.sqrt (T + T₀)) * T) x := + ((hasDerivAt_smileSurface_k.fun_pow 2).mul_const T).congr_deriv (by ring) + +/-- `∂_T w = σ_tilde² − σ_tilde·(ε·ψ₁·k)·T/(T+T₀)^{3/2}` — the `T`-chain of the total +variance (both `T`-channels of `w = σ_tilde²T` move: `σ_tilde` carries `√(T+T₀)` in the +denominator). `(T+T₀)^{3/2}` is rendered `(T+T₀)·√(T+T₀)`. -/ +private theorem hasDerivAt_totalVar_t {σ ψ₁ T₀ ε k T : ℝ} (hS : 0 < T + T₀) : + HasDerivAt (fun t ↦ totalVar σ ψ₁ T₀ ε k t) + (smileSurface σ ψ₁ T₀ ε k T ^ 2 + - smileSurface σ ψ₁ T₀ ε k T * (ε * ψ₁ * k) * T / ((T + T₀) * Real.sqrt (T + T₀))) T := by + have hs : Real.sqrt (T + T₀) ≠ 0 := (Real.sqrt_pos.mpr hS).ne' + have hT₀ne : T + T₀ ≠ 0 := by linarith + have hssq : Real.sqrt (T + T₀) ^ 2 = T + T₀ := Real.sq_sqrt hS.le + have h1 : HasDerivAt (fun t : ℝ ↦ t + T₀) 1 T := (hasDerivAt_id' T).add_const T₀ + have h2 : HasDerivAt (fun t : ℝ ↦ Real.sqrt (t + T₀)) (1 / (2 * Real.sqrt (T + T₀))) T := + h1.sqrt hT₀ne + have hinv : HasDerivAt (fun t : ℝ ↦ (Real.sqrt (t + T₀))⁻¹) + (-(Real.sqrt (T + T₀))⁻¹ ^ 2 * (1 / (2 * Real.sqrt (T + T₀)))) T := by + have h0 := h2.inv hs + refine h0.congr_deriv ?_ + field_simp [hssq] + have hsigt : HasDerivAt (fun t : ℝ ↦ σ + ε * ψ₁ * k * (Real.sqrt (t + T₀))⁻¹) + (ε * ψ₁ * k * (-(Real.sqrt (T + T₀))⁻¹ ^ 2 * (1 / (2 * Real.sqrt (T + T₀))))) T := by + have h0 := (hinv.const_mul (ε * ψ₁ * k)).add_const σ + refine h0.congr_of_eventuallyEq ?_ + filter_upwards with t + ring + have hsq : HasDerivAt (fun t : ℝ ↦ (σ + ε * ψ₁ * k * (Real.sqrt (t + T₀))⁻¹) ^ 2) + (2 * (σ + ε * ψ₁ * k * (Real.sqrt (T + T₀))⁻¹) + * (ε * ψ₁ * k * (-(Real.sqrt (T + T₀))⁻¹ ^ 2 * (1 / (2 * Real.sqrt (T + T₀)))))) T := + (hsigt.fun_pow 2).congr_deriv (by ring) + have hid : HasDerivAt (fun t : ℝ ↦ t) 1 T := hasDerivAt_id T + have hmul := hsq.mul hid + have hfun : (fun t : ℝ ↦ (σ + ε * ψ₁ * k * (Real.sqrt (t + T₀))⁻¹) ^ 2 * t) + = fun t ↦ totalVar σ ψ₁ T₀ ε k t := by + funext t + unfold totalVar smileSurface + field_simp + have hfin := hmul.congr_of_eventuallyEq (Filter.Eventually.of_forall (congrFun hfun)) + refine hfin.congr_deriv ?_ + have hne : (T + T₀) * Real.sqrt (T + T₀) ≠ 0 := mul_ne_zero hT₀ne hs + unfold smileSurface + field_simp [hne, hs] + simp only [hssq] + ring + +/-! ## The composite chains in `(k, w)`: an abstract inner function `u` -/ + +/-- The `k`-chain of `d₊` through a moving inner function `u` (the total +variance composite): `∂_k d₊(k, u(k)) = ∂_k d₊ + ∂_w d₊·u'` at `x`, with +`∂_k d₊ = −1/√w` and `∂_w d₊ = (k + w/2)/(2w^{3/2})`. -/ +private theorem hasDerivAt_dpl_comp {u : ℝ → ℝ} {x ub : ℝ} (hu : HasDerivAt u ub x) + (hpos : 0 < u x) : + HasDerivAt (fun y ↦ dpl y (u y)) + (-(1 / Real.sqrt (u x)) + (x + u x / 2) / (2 * u x * Real.sqrt (u x)) * ub) x := by + have hne : Real.sqrt (u x) ≠ 0 := (Real.sqrt_pos.mpr hpos).ne' + have hsq : Real.sqrt (u x) ^ 2 = u x := Real.sq_sqrt hpos.le + have hnum : HasDerivAt (fun y : ℝ ↦ -y + u y / 2) (-1 + ub / 2) x := + (hasDerivAt_id x).neg.add (hu.div_const 2) + have hden : HasDerivAt (fun y : ℝ ↦ Real.sqrt (u y)) (ub / (2 * Real.sqrt (u x))) x := + hu.sqrt hpos.ne' + have hq := hnum.div hden hne + unfold dpl + refine hq.congr_deriv ?_ + field_simp [hsq] + simp only [hsq] + ring + +/-- The `k`-chain of `d₋` through a moving `u` (mirror of `hasDerivAt_dpl_comp`: +`∂_w d₋ = (k − w/2)/(2w^{3/2})`). -/ +private theorem hasDerivAt_dmi_comp {u : ℝ → ℝ} {x ub : ℝ} (hu : HasDerivAt u ub x) + (hpos : 0 < u x) : + HasDerivAt (fun y ↦ dmi y (u y)) + (-(1 / Real.sqrt (u x)) + (x - u x / 2) / (2 * u x * Real.sqrt (u x)) * ub) x := by + have hne : Real.sqrt (u x) ≠ 0 := (Real.sqrt_pos.mpr hpos).ne' + have hsq : Real.sqrt (u x) ^ 2 = u x := Real.sq_sqrt hpos.le + have hnum : HasDerivAt (fun y : ℝ ↦ -y - u y / 2) (-1 - ub / 2) x := + (hasDerivAt_id x).neg.sub (hu.div_const 2) + have hden : HasDerivAt (fun y : ℝ ↦ Real.sqrt (u y)) (ub / (2 * Real.sqrt (u x))) x := + hu.sqrt hpos.ne' + have hq := hnum.div hden hne + unfold dmi + refine hq.congr_deriv ?_ + field_simp [hsq] + simp only [hsq] + ring + +/-- The `k`-chain of `e^k·Φ(d₋(k, u(k)))` through a moving `u` — the strike +side of the Black form. -/ +private theorem hasDerivAt_exp_Phi_dmi_comp {u : ℝ → ℝ} {x ub : ℝ} (hu : HasDerivAt u ub x) + (hpos : 0 < u x) : + HasDerivAt (fun y ↦ Real.exp y * Phi (dmi y (u y))) + (Real.exp x * Phi (dmi x (u x)) + + Real.exp x * (gaussianPDFReal 0 1 (dmi x (u x)) + * (-(1 / Real.sqrt (u x)) + (x - u x / 2) / (2 * u x * Real.sqrt (u x)) * ub))) x := by + have hdmi := hasDerivAt_dmi_comp hu hpos + have hPhi := (hasDerivAt_Phi (dmi x (u x))).comp x hdmi + rw [Function.comp_def] at hPhi + exact ((hasDerivAt_exp x).mul hPhi).congr_deriv (by ring) + +/-- The `k`-chain of the whole Black form through a moving `u`: +`C_k/F = ϕ(d₊)·∂_k d₊^{comp} − [e^k Φ(d₋) + e^k ϕ(d₋)·∂_k d₋^{comp}]`. -/ +private theorem hasDerivAt_blackForm_comp {u : ℝ → ℝ} {x ub : ℝ} (hu : HasDerivAt u ub x) + (hpos : 0 < u x) : + HasDerivAt (fun y ↦ blackForm y (u y)) + (gaussianPDFReal 0 1 (dpl x (u x)) + * (-(1 / Real.sqrt (u x)) + (x + u x / 2) / (2 * u x * Real.sqrt (u x)) * ub) + - (Real.exp x * Phi (dmi x (u x)) + + Real.exp x * (gaussianPDFReal 0 1 (dmi x (u x)) + * (-(1 / Real.sqrt (u x)) + (x - u x / 2) / (2 * u x * Real.sqrt (u x)) * ub)))) x := by + have hdpl := hasDerivAt_dpl_comp hu hpos + have hPhiP := (hasDerivAt_Phi (dpl x (u x))).comp x hdpl + rw [Function.comp_def] at hPhiP + have hex := hasDerivAt_exp_Phi_dmi_comp hu hpos + unfold blackForm + exact hPhiP.sub hex + +/-- The `w`-chain of the Black form at fixed `k` (single slot): `∂_w c = ϕ(d₊)/(2√w)`. -/ +private theorem hasDerivAt_blackForm_w {k w : ℝ} (hw : 0 < w) : + HasDerivAt (fun z ↦ blackForm k z) + (gaussianPDFReal 0 1 (dpl k w) / (2 * Real.sqrt w)) w := by + have hne : Real.sqrt w ≠ 0 := (Real.sqrt_pos.mpr hw).ne' + have hsq : Real.sqrt w ^ 2 = w := Real.sq_sqrt hw.le + have hden : HasDerivAt (fun z : ℝ ↦ Real.sqrt z) (1 / (2 * Real.sqrt w)) w := + Real.hasDerivAt_sqrt hw.ne' + have hnP : HasDerivAt (fun z : ℝ ↦ -k + z / 2) (1 / 2) w := + ((hasDerivAt_id' w).div_const 2).const_add (-k) + have hnM : HasDerivAt (fun z : ℝ ↦ -k - z / 2) (-(1 / 2)) w := by + have h1 : HasDerivAt (fun z : ℝ ↦ z / 2) (1 / 2) w := (hasDerivAt_id w).div_const 2 + exact h1.const_sub (-k) + have hdP := hnP.div hden hne + have hdM := hnM.div hden hne + have hPhiP := (hasDerivAt_Phi (dpl k w)).comp w hdP + rw [Function.comp_def] at hPhiP + have hPhiM := (hasDerivAt_Phi (dmi k w)).comp w hdM + rw [Function.comp_def] at hPhiM + have hexp := (hasDerivAt_const w (Real.exp k)).mul hPhiM + have hfull := hPhiP.sub hexp + refine (hfull.congr_of_eventuallyEq ?_).congr_deriv ?_ + · filter_upwards with z + unfold blackForm dpl dmi + simp only [Pi.sub_apply, Pi.mul_apply] + · rw [← exp_mul_pdf_dmi hw] + field_simp [hsq] + simp only [hsq] + ring + +/-- The `k`-chain of the vega-density quotient `ϕ(d₊(k,u(k)))/(2√(u(k)))` — the +B_w-value composite: its `k`-derivative is `B_wk + B_ww·u'` with +`B_wk = d₊ϕ(d₊)/(2w)` and `B_ww = ϕ(d₊)(k²−w−w²/4)/(4w^{5/2})`. -/ +private theorem hasDerivAt_Bw_comp {u : ℝ → ℝ} {x ub : ℝ} (hu : HasDerivAt u ub x) + (hpos : 0 < u x) : + HasDerivAt (fun y ↦ gaussianPDFReal 0 1 (dpl y (u y)) / (2 * Real.sqrt (u y))) + (dpl x (u x) * gaussianPDFReal 0 1 (dpl x (u x)) / (2 * u x) + + gaussianPDFReal 0 1 (dpl x (u x)) * (x ^ 2 - u x - u x ^ 2 / 4) + / (4 * u x ^ 2 * Real.sqrt (u x)) * ub) x := by + have hsq : Real.sqrt (u x) ^ 2 = u x := Real.sq_sqrt hpos.le + have hdpl := hasDerivAt_dpl_comp hu hpos + have hphi := (hasDerivAt_gaussianPDFReal_zero_one (dpl x (u x))).comp x hdpl + rw [Function.comp_def] at hphi + have hden : HasDerivAt (fun y : ℝ ↦ 2 * Real.sqrt (u y)) (ub / Real.sqrt (u x)) x := by + have hc := (Real.hasDerivAt_sqrt hpos.ne').comp x hu + rw [Function.comp_def] at hc + refine (hc.const_mul 2).congr_deriv ?_ + field_simp + have hdenne : 2 * Real.sqrt (u x) ≠ 0 := + (mul_pos two_pos (Real.sqrt_pos.mpr hpos)).ne' + refine (hphi.div hden hdenne).congr_deriv ?_ + unfold dpl + field_simp [hsq] + simp only [hsq] + ring + +/-! ## The call's own chains: `C_k`, `C_T`, `C_kk` -/ + +/-- The value of the `d₋` slope composite, `∂_k d₋ + ∂_w d₋·m` at total variance `w` +and variance slope `m`. -/ +private noncomputable def dminus (k w m : ℝ) : ℝ := + -(1 / Real.sqrt w) + (k - w / 2) / (2 * w * Real.sqrt w) * m + +/-- The smile surface is affine in `k`, so positivity at one point spreads to a +neighborhood. -/ +private theorem smileSurface_eventually_pos_k {σ ψ₁ T₀ ε T k : ℝ} + (hk : 0 < smileSurface σ ψ₁ T₀ ε k T) : + ∀ᶠ y in nhds k, 0 < smileSurface σ ψ₁ T₀ ε y T := by + have hcont : Continuous (fun y : ℝ ↦ smileSurface σ ψ₁ T₀ ε y T) := by + unfold smileSurface; fun_prop + exact hcont.continuousAt.eventually_const_lt hk + +/-- Same along the maturity axis: `σ_tilde(t) = σ + εψ₁k/√(t+T₀)` is continuous at +`T`, and `t > 0` holds eventually at `T > 0`. -/ +private theorem smileSurface_eventually_pos_t {σ ψ₁ T₀ ε k T : ℝ} (hT : 0 < T) + (hS : 0 < T + T₀) (hk : 0 < smileSurface σ ψ₁ T₀ ε k T) : + ∀ᶠ t in nhds T, 0 < smileSurface σ ψ₁ T₀ ε k t ∧ 0 < t := by + have hadd : ContinuousAt (fun t : ℝ ↦ t + T₀) T := + (continuous_id.add continuous_const).continuousAt + have hsca : ContinuousAt (fun t : ℝ ↦ Real.sqrt (t + T₀)) T := + (Real.continuous_sqrt.continuousAt).comp hadd + have hcst : ContinuousAt (fun _ : ℝ ↦ ε * ψ₁ * k) T := continuousAt_const + have hca : ContinuousAt (fun t : ℝ ↦ smileSurface σ ψ₁ T₀ ε k t) T := by + unfold smileSurface + exact continuousAt_const.add (hcst.div hsca (Real.sqrt_pos.mpr hS).ne') + filter_upwards [hca.eventually_const_lt hk, eventually_gt_nhds hT] with t h1t h2t + exact ⟨h1t, h2t⟩ + +/-- **The `k`-chain of the call price** (both `k`-channels: strike `F·e^k` and +surface tilt), from `hasDerivAt_blackForm_comp` at the variance composite. -/ +private theorem hasDerivAt_bsCallSmile_k {F σ ψ₁ T₀ ε k T : ℝ} (hF : 0 < F) (hT : 0 < T) + (hst : 0 < smileSurface σ ψ₁ T₀ ε k T) : + HasDerivAt (fun y ↦ bsCallSmile F σ ψ₁ T₀ ε y T) + (F * (gaussianPDFReal 0 1 (dpl k (totalVar σ ψ₁ T₀ ε k T)) + * (-(1 / Real.sqrt (totalVar σ ψ₁ T₀ ε k T)) + + (k + totalVar σ ψ₁ T₀ ε k T / 2) + / (2 * totalVar σ ψ₁ T₀ ε k T * Real.sqrt (totalVar σ ψ₁ T₀ ε k T)) + * (2 * smileSurface σ ψ₁ T₀ ε k T * (ε * ψ₁ / Real.sqrt (T + T₀)) * T)) + - (Real.exp k * Phi (dmi k (totalVar σ ψ₁ T₀ ε k T)) + + Real.exp k * (gaussianPDFReal 0 1 (dmi k (totalVar σ ψ₁ T₀ ε k T)) + * (-(1 / Real.sqrt (totalVar σ ψ₁ T₀ ε k T)) + + (k - totalVar σ ψ₁ T₀ ε k T / 2) + / (2 * totalVar σ ψ₁ T₀ ε k T * Real.sqrt (totalVar σ ψ₁ T₀ ε k T)) + * (2 * smileSurface σ ψ₁ T₀ ε k T * (ε * ψ₁ / Real.sqrt (T + T₀)) + * T)))))) k := by + have hwpos : 0 < totalVar σ ψ₁ T₀ ε k T := mul_pos (pow_pos hst 2) hT + have huc := hasDerivAt_totalVar_k (σ := σ) (ψ₁ := ψ₁) (T₀ := T₀) (ε := ε) (T := T) (x := k) + have hcore := hasDerivAt_blackForm_comp huc hwpos + refine (hcore.const_mul F).congr_of_eventuallyEq ?_ + filter_upwards [smileSurface_eventually_pos_k hst] with y hy + exact bsCallSmile_eq hF hT hy + +/-- **The `T`-chain of the call price** (single `(k,w)` slot: the maturity moves +only through `w`), from `hasDerivAt_blackForm_w` composed with the variance +`T`-chain. -/ +private theorem hasDerivAt_bsCallSmile_t {F σ ψ₁ T₀ ε k T : ℝ} (hF : 0 < F) (hT : 0 < T) + (hS : 0 < T + T₀) (hst : 0 < smileSurface σ ψ₁ T₀ ε k T) : + HasDerivAt (fun t ↦ bsCallSmile F σ ψ₁ T₀ ε k t) + (F * (gaussianPDFReal 0 1 (dpl k (totalVar σ ψ₁ T₀ ε k T)) + / (2 * Real.sqrt (totalVar σ ψ₁ T₀ ε k T))) + * (smileSurface σ ψ₁ T₀ ε k T ^ 2 + - smileSurface σ ψ₁ T₀ ε k T * (ε * ψ₁ * k) * T + / ((T + T₀) * Real.sqrt (T + T₀)))) T := by + have hwpos : 0 < totalVar σ ψ₁ T₀ ε k T := mul_pos (pow_pos hst 2) hT + have hwt := hasDerivAt_totalVar_t (σ := σ) (ψ₁ := ψ₁) (T₀ := T₀) (ε := ε) (k := k) hS + have hcomp := (hasDerivAt_blackForm_w (k := k) hwpos).comp T hwt + rw [Function.comp_def] at hcomp + refine ((hcomp.const_mul F).congr_of_eventuallyEq ?_).congr_deriv (by ring) + filter_upwards [smileSurface_eventually_pos_t hT hS hst] with t ht + exact bsCallSmile_eq hF ht.2 ht.1 + +/-- The variance slope `w_k(y) = 2σ_tilde(y)·(εψ₁/√(T+T₀))·T` of the total variance +`w = σ_tilde²T` along log-moneyness: `∂_k w` at `k = y` (affine in `y`). -/ +noncomputable def wSlope (σ ψ₁ T₀ ε T y : ℝ) : ℝ := + 2 * smileSurface σ ψ₁ T₀ ε y T * (ε * ψ₁ / Real.sqrt (T + T₀)) * T + +/-- Its chain: `w'' = 2·(εψ₁/√(T+T₀))²·T`, constant in `y`. -/ +private theorem hasDerivAt_wSlope {σ ψ₁ T₀ ε T k : ℝ} : + HasDerivAt (fun y ↦ wSlope σ ψ₁ T₀ ε T y) + (2 * (ε * ψ₁ / Real.sqrt (T + T₀)) ^ 2 * T) k := + (((hasDerivAt_smileSurface_k.const_mul 2).mul_const _).mul_const T).congr_deriv (by ring) + +/-! ## The second `k`-chain: `C_kk` and the Gatheral form of the ratio -/ + +/-- **The `k`-derivative of the call price, collapsed**: the spelled chain value of +`hasDerivAt_bsCallSmile_k` simplifies (via the magic identity `e^k·ϕ(d₋) = ϕ(d₊)`) to +`C_k = F·(B_w·m − e^k·Φ(d₋))` with `B_w = ϕ(d₊)/(2√w)` and `m = w'` — the vega-density +composite times the variance slope, minus the exercise side. -/ +private theorem deriv_bsCallSmile_k_value {F σ ψ₁ T₀ ε k T : ℝ} (hF : 0 < F) (hT : 0 < T) + (hS : 0 < T + T₀) (hst : 0 < smileSurface σ ψ₁ T₀ ε k T) : + deriv (fun x ↦ bsCallSmile F σ ψ₁ T₀ ε x T) k + = F * (gaussianPDFReal 0 1 (dpl k (totalVar σ ψ₁ T₀ ε k T)) + / (2 * Real.sqrt (totalVar σ ψ₁ T₀ ε k T)) * wSlope σ ψ₁ T₀ ε T k + - Real.exp k * Phi (dmi k (totalVar σ ψ₁ T₀ ε k T))) := by + have hw : 0 < totalVar σ ψ₁ T₀ ε k T := mul_pos (pow_pos hst 2) hT + rw [(hasDerivAt_bsCallSmile_k hF hT hst).deriv] + rw [show Real.exp k * (gaussianPDFReal 0 1 (dmi k (totalVar σ ψ₁ T₀ ε k T)) + * (-(1 / Real.sqrt (totalVar σ ψ₁ T₀ ε k T)) + + (k - totalVar σ ψ₁ T₀ ε k T / 2) + / (2 * totalVar σ ψ₁ T₀ ε k T * Real.sqrt (totalVar σ ψ₁ T₀ ε k T)) + * (2 * smileSurface σ ψ₁ T₀ ε k T * (ε * ψ₁ / Real.sqrt (T + T₀)) * T))) + = (Real.exp k * gaussianPDFReal 0 1 (dmi k (totalVar σ ψ₁ T₀ ε k T))) + * (-(1 / Real.sqrt (totalVar σ ψ₁ T₀ ε k T)) + + (k - totalVar σ ψ₁ T₀ ε k T / 2) + / (2 * totalVar σ ψ₁ T₀ ε k T * Real.sqrt (totalVar σ ψ₁ T₀ ε k T)) + * (2 * smileSurface σ ψ₁ T₀ ε k T * (ε * ψ₁ / Real.sqrt (T + T₀)) * T)) from + (mul_assoc _ _ _).symm, + exp_mul_pdf_dmi hw] + simp only [wSlope] + field_simp [hw.ne', (Real.sqrt_pos.mpr hw).ne', (Real.sqrt_pos.mpr hS).ne'] + ring + +/-- **The second `k`-chain `C_kk`** (the second `k`-derivative of the call +price, the remaining ingredient Dupire's ratio needs beyond `C_k`), assembled from the +`B_w` composite chain (`hasDerivAt_Bw_comp`), the variance-slope chain +(`hasDerivAt_wSlope`) and the exercise-side chain +(`hasDerivAt_exp_Phi_dmi_comp`) — each factor evaluated on the *collapsed* +first-derivative function of `deriv_bsCallSmile_k_value`, which closes the eventual +congruence directly. -/ +private theorem hasDerivAt_deriv_bsCallSmile_k {F σ ψ₁ T₀ ε k T : ℝ} (hF : 0 < F) (hT : 0 < T) + (hS : 0 < T + T₀) (hst : 0 < smileSurface σ ψ₁ T₀ ε k T) : + HasDerivAt (fun y ↦ deriv (fun x ↦ bsCallSmile F σ ψ₁ T₀ ε x T) y) + (F * ((dpl k (totalVar σ ψ₁ T₀ ε k T) + * gaussianPDFReal 0 1 (dpl k (totalVar σ ψ₁ T₀ ε k T)) + / (2 * totalVar σ ψ₁ T₀ ε k T) + + gaussianPDFReal 0 1 (dpl k (totalVar σ ψ₁ T₀ ε k T)) + * (k ^ 2 - totalVar σ ψ₁ T₀ ε k T - totalVar σ ψ₁ T₀ ε k T ^ 2 / 4) + / (4 * totalVar σ ψ₁ T₀ ε k T ^ 2 * Real.sqrt (totalVar σ ψ₁ T₀ ε k T)) + * wSlope σ ψ₁ T₀ ε T k) * wSlope σ ψ₁ T₀ ε T k + + gaussianPDFReal 0 1 (dpl k (totalVar σ ψ₁ T₀ ε k T)) + / (2 * Real.sqrt (totalVar σ ψ₁ T₀ ε k T)) + * (2 * (ε * ψ₁ / Real.sqrt (T + T₀)) ^ 2 * T) + - (Real.exp k * Phi (dmi k (totalVar σ ψ₁ T₀ ε k T)) + + Real.exp k * (gaussianPDFReal 0 1 (dmi k (totalVar σ ψ₁ T₀ ε k T)) + * dminus k (totalVar σ ψ₁ T₀ ε k T) (wSlope σ ψ₁ T₀ ε T k))))) k := by + have hwpos : 0 < totalVar σ ψ₁ T₀ ε k T := mul_pos (pow_pos hst 2) hT + have hu : HasDerivAt (fun y ↦ totalVar σ ψ₁ T₀ ε y T) (wSlope σ ψ₁ T₀ ε T k) k := + hasDerivAt_totalVar_k + have hBw := hasDerivAt_Bw_comp hu hwpos + have hm : HasDerivAt (fun y ↦ wSlope σ ψ₁ T₀ ε T y) + (2 * (ε * ψ₁ / Real.sqrt (T + T₀)) ^ 2 * T) k := hasDerivAt_wSlope + have hprod := hBw.mul hm + have hexp := hasDerivAt_exp_Phi_dmi_comp hu hwpos + refine ((hprod.sub hexp).const_mul F).congr_of_eventuallyEq ?_ + filter_upwards [smileSurface_eventually_pos_k hst] with y hy + exact deriv_bsCallSmile_k_value hF hT hS hy + +/-! ## The Gatheral form of the ratio -/ + +/-- **The numerator of Dupire's ratio** in `(k, w)` coordinates: the maturity slope of +the total variance, `w_T = σ_tilde² − σ_tilde·εψ₁k·T/(T+T₀)^{3/2}` (both `T`-channels of +`w = σ_tilde²T` move). -/ +noncomputable def smileN (σ ψ₁ T₀ ε k T : ℝ) : ℝ := + smileSurface σ ψ₁ T₀ ε k T ^ 2 + - smileSurface σ ψ₁ T₀ ε k T * (ε * ψ₁ * k) * T / ((T + T₀) * Real.sqrt (T + T₀)) + +/-- **The Gatheral denominator deformation** of Dupire's ratio, +`δ = −k·w_k/w + w_k²·(k²−w−w²/4)/(4w²) + w_kk/2`, specialized to this surface (so +`w_kk/2 = (εψ₁/√(T+T₀))²·T` is spelled out); Dupire's ratio is `w_T/(1 + δ)` +(`dupireRatio_eq`). `1 + smileDelta` has the algebraic form of Durrleman's function `g`, which +`MathFin.SVI.durrleman` (`SVI/Reduction.lean`) defines for the SVI variance: where the two have the +same total variance, slope and curvature they are equal (`SVI.durrleman_eq_one_add_smileDelta`). +The SVI development (`SVI/BlackSmile.lean`) uses `dpl`, `dmi`, `blackForm` and `exp_mul_pdf_dmi` +directly, at `w = SVI.variance p k`. -/ +noncomputable def smileDelta (σ ψ₁ T₀ ε k T : ℝ) : ℝ := + -k * wSlope σ ψ₁ T₀ ε T k / totalVar σ ψ₁ T₀ ε k T + + wSlope σ ψ₁ T₀ ε T k ^ 2 * (k ^ 2 - totalVar σ ψ₁ T₀ ε k T + - totalVar σ ψ₁ T₀ ε k T ^ 2 / 4) / (4 * totalVar σ ψ₁ T₀ ε k T ^ 2) + + (ε * ψ₁ / Real.sqrt (T + T₀)) ^ 2 * T + +/-- **`dupireRatio_eq`** — the exact identity behind the module: in `(k, w)` +coordinates, Dupire's zero-rates ratio on the tilted surface is the rational function +`R = w_T/(1 + δ)` (the Gatheral form). Everything downstream is calculus on the +explicit right-hand side. -/ +theorem dupireRatio_eq {F σ ψ₁ T₀ ε k T : ℝ} (hF : 0 < F) (hT : 0 < T) (hS : 0 < T + T₀) + (hst : 0 < smileSurface σ ψ₁ T₀ ε k T) : + dupireRatio F σ ψ₁ T₀ ε k T + = smileN σ ψ₁ T₀ ε k T / (1 + smileDelta σ ψ₁ T₀ ε k T) := by + have hw : 0 < totalVar σ ψ₁ T₀ ε k T := mul_pos (pow_pos hst 2) hT + have hsne : Real.sqrt (totalVar σ ψ₁ T₀ ε k T) ≠ 0 := (Real.sqrt_pos.mpr hw).ne' + have hI : + (F * ((dpl k (totalVar σ ψ₁ T₀ ε k T) + * gaussianPDFReal 0 1 (dpl k (totalVar σ ψ₁ T₀ ε k T)) + / (2 * totalVar σ ψ₁ T₀ ε k T) + + gaussianPDFReal 0 1 (dpl k (totalVar σ ψ₁ T₀ ε k T)) + * (k ^ 2 - totalVar σ ψ₁ T₀ ε k T - totalVar σ ψ₁ T₀ ε k T ^ 2 / 4) + / (4 * totalVar σ ψ₁ T₀ ε k T ^ 2 * Real.sqrt (totalVar σ ψ₁ T₀ ε k T)) + * wSlope σ ψ₁ T₀ ε T k) * wSlope σ ψ₁ T₀ ε T k + + gaussianPDFReal 0 1 (dpl k (totalVar σ ψ₁ T₀ ε k T)) + / (2 * Real.sqrt (totalVar σ ψ₁ T₀ ε k T)) + * (2 * (ε * ψ₁ / Real.sqrt (T + T₀)) ^ 2 * T) + - (Real.exp k * Phi (dmi k (totalVar σ ψ₁ T₀ ε k T)) + + Real.exp k * (gaussianPDFReal 0 1 (dmi k (totalVar σ ψ₁ T₀ ε k T)) + * dminus k (totalVar σ ψ₁ T₀ ε k T) (wSlope σ ψ₁ T₀ ε T k)))) + - F * (gaussianPDFReal 0 1 (dpl k (totalVar σ ψ₁ T₀ ε k T)) + / (2 * Real.sqrt (totalVar σ ψ₁ T₀ ε k T)) * wSlope σ ψ₁ T₀ ε T k + - Real.exp k * Phi (dmi k (totalVar σ ψ₁ T₀ ε k T)))) + = F * gaussianPDFReal 0 1 (dpl k (totalVar σ ψ₁ T₀ ε k T)) + / Real.sqrt (totalVar σ ψ₁ T₀ ε k T) * (1 + smileDelta σ ψ₁ T₀ ε k T) := by + have hexp : Real.exp k * (gaussianPDFReal 0 1 (dmi k (totalVar σ ψ₁ T₀ ε k T)) + * dminus k (totalVar σ ψ₁ T₀ ε k T) (wSlope σ ψ₁ T₀ ε T k)) + = gaussianPDFReal 0 1 (dpl k (totalVar σ ψ₁ T₀ ε k T)) + * dminus k (totalVar σ ψ₁ T₀ ε k T) (wSlope σ ψ₁ T₀ ε T k) := by + rw [← mul_assoc, exp_mul_pdf_dmi hw] + rw [hexp] + simp only [dminus, dpl] + unfold smileDelta + field_simp [hw.ne', hsne] + ring + unfold dupireRatio + rw [(hasDerivAt_bsCallSmile_t hF hT hS hst).deriv, deriv_bsCallSmile_k_value hF hT hS hst, + (hasDerivAt_deriv_bsCallSmile_k hF hT hS hst).deriv, hI] + have hA : F * gaussianPDFReal 0 1 (dpl k (totalVar σ ψ₁ T₀ ε k T)) + / Real.sqrt (totalVar σ ψ₁ T₀ ε k T) ≠ 0 := + div_ne_zero (mul_ne_zero hF.ne' (gaussianPDFReal_pos 0 1 _ one_ne_zero).ne') hsne + have htwo : 2 * (F * (gaussianPDFReal 0 1 (dpl k (totalVar σ ψ₁ T₀ ε k T)) + / (2 * Real.sqrt (totalVar σ ψ₁ T₀ ε k T))) + * (smileSurface σ ψ₁ T₀ ε k T ^ 2 + - smileSurface σ ψ₁ T₀ ε k T * (ε * ψ₁ * k) * T / ((T + T₀) * Real.sqrt (T + T₀)))) + = F * gaussianPDFReal 0 1 (dpl k (totalVar σ ψ₁ T₀ ε k T)) + / Real.sqrt (totalVar σ ψ₁ T₀ ε k T) * smileN σ ψ₁ T₀ ε k T := by + unfold smileN + field_simp + rw [htwo] + field_simp [hA, (gaussianPDFReal_pos 0 1 _ one_ne_zero).ne'] + +/-! ## The `k = 0` extraction -/ + +/-- At the money the total variance is `σ²T`, independent of the tilt. -/ +private theorem totalVar_zero (σ ψ₁ T₀ ε T : ℝ) : totalVar σ ψ₁ T₀ ε 0 T = σ ^ 2 * T := by + unfold totalVar + rw [smileSurface_atm] + +/-- At the money the variance slope is `m₀ = 2σ·(εψ₁/√(T+T₀))·T` — linear in `ε`. -/ +private theorem wSlope_zero (σ ψ₁ T₀ ε T : ℝ) : + wSlope σ ψ₁ T₀ ε T 0 = 2 * σ * (ε * ψ₁ / Real.sqrt (T + T₀)) * T := by + unfold wSlope + rw [smileSurface_atm] + +/-- The `T`-chain numerator at the money: `w_T(ε, 0) = σ²`, tilt-free. -/ +private theorem smileN_zero (σ ψ₁ T₀ ε T : ℝ) : smileN σ ψ₁ T₀ ε 0 T = σ ^ 2 := by + unfold smileN + rw [smileSurface_atm] + ring + +/-- The `k`-slope of the numerator at the money (the value of `hasDerivAt_smileN_k`). -/ +private noncomputable def smileNk (σ ψ₁ T₀ ε T : ℝ) : ℝ := + 2 * σ * (ε * ψ₁ / Real.sqrt (T + T₀)) + - σ * (ε * ψ₁) * T / ((T + T₀) * Real.sqrt (T + T₀)) + +private theorem smileNk_zero (σ ψ₁ T₀ T : ℝ) : smileNk σ ψ₁ T₀ 0 T = 0 := by + unfold smileNk + simp + +/-- The `k`-slope of the Gatheral deformation at the money (the value of +`hasDerivAt_smileDelta_k`). -/ +private noncomputable def smileDk (σ ψ₁ T₀ ε T : ℝ) : ℝ := + -(wSlope σ ψ₁ T₀ ε T 0 / totalVar σ ψ₁ T₀ ε 0 T) + + ((((-wSlope σ ψ₁ T₀ ε T 0 - totalVar σ ψ₁ T₀ ε 0 T * wSlope σ ψ₁ T₀ ε T 0 / 2) + * wSlope σ ψ₁ T₀ ε T 0 ^ 2 + + (-totalVar σ ψ₁ T₀ ε 0 T - totalVar σ ψ₁ T₀ ε 0 T ^ 2 / 4) + * (2 * wSlope σ ψ₁ T₀ ε T 0 * (2 * (ε * ψ₁ / Real.sqrt (T + T₀)) ^ 2 * T))) + * (4 * totalVar σ ψ₁ T₀ ε 0 T ^ 2) + - (-totalVar σ ψ₁ T₀ ε 0 T - totalVar σ ψ₁ T₀ ε 0 T ^ 2 / 4) + * wSlope σ ψ₁ T₀ ε T 0 ^ 2 * (4 * (2 * totalVar σ ψ₁ T₀ ε 0 T * wSlope σ ψ₁ T₀ ε T 0))) + / (4 * totalVar σ ψ₁ T₀ ε 0 T ^ 2) ^ 2) + +private theorem smileDelta_zero (σ ψ₁ T₀ T : ℝ) : smileDelta σ ψ₁ T₀ 0 0 T = 0 := by + unfold smileDelta + rw [totalVar_zero, wSlope_zero] + simp + +private theorem smileDk_zero (σ ψ₁ T₀ T : ℝ) : smileDk σ ψ₁ T₀ 0 T = 0 := by + unfold smileDk + rw [totalVar_zero, wSlope_zero] + simp + +/-- The numerator of the ATM `k`-slope of the ratio: quotient-rule value +`N'(0)·D(0) − N(0)·D'(0)` in the `(k = 0)` slice. -/ +private noncomputable def slopeNum (σ ψ₁ T₀ ε T : ℝ) : ℝ := + smileNk σ ψ₁ T₀ ε T * (1 + smileDelta σ ψ₁ T₀ ε 0 T) + - smileN σ ψ₁ T₀ ε 0 T * smileDk σ ψ₁ T₀ ε T + +private theorem slopeNum_zero (σ ψ₁ T₀ T : ℝ) : slopeNum σ ψ₁ T₀ 0 T = 0 := by + unfold slopeNum + rw [smileNk_zero, smileDelta_zero, smileN_zero, smileDk_zero] + simp + +/-- The `k`-chain of the numerator `w_T` at the money. -/ +private theorem hasDerivAt_smileN_k {σ ψ₁ T₀ ε T : ℝ} : + HasDerivAt (fun k ↦ smileN σ ψ₁ T₀ ε k T) (smileNk σ ψ₁ T₀ ε T) 0 := by + have hs : HasDerivAt (fun k ↦ smileSurface σ ψ₁ T₀ ε k T) (ε * ψ₁ / Real.sqrt (T + T₀)) 0 := + hasDerivAt_smileSurface_k + have hs2 : HasDerivAt (fun k ↦ smileSurface σ ψ₁ T₀ ε k T ^ 2) + (2 * smileSurface σ ψ₁ T₀ ε 0 T ^ (2 - 1) * (ε * ψ₁ / Real.sqrt (T + T₀))) 0 := + hs.fun_pow 2 + have hkm : HasDerivAt (fun k ↦ smileSurface σ ψ₁ T₀ ε k T * k) + ((ε * ψ₁ / Real.sqrt (T + T₀)) * 0 + smileSurface σ ψ₁ T₀ ε 0 T * 1) 0 := + hs.mul (hasDerivAt_id 0) + have hsub := hs2.sub (hkm.const_mul (ε * ψ₁ * T / ((T + T₀) * Real.sqrt (T + T₀)))) + refine (hsub.congr_of_eventuallyEq ?_).congr_deriv ?_ + · filter_upwards with k + simp only [Pi.sub_apply] + unfold smileN + ring + · rw [smileSurface_atm] + unfold smileNk + ring + +/-- The `k`-chain of the Gatheral deformation `δ` at the money. -/ +private theorem hasDerivAt_smileDelta_k {σ ψ₁ T₀ ε T : ℝ} (hσ : 0 < σ) (hT : 0 < T) : + HasDerivAt (fun k ↦ smileDelta σ ψ₁ T₀ ε k T) (smileDk σ ψ₁ T₀ ε T) 0 := by + have hw0 : 0 < totalVar σ ψ₁ T₀ ε 0 T := by rw [totalVar_zero]; positivity + have hw0ne := hw0.ne' + have hm : HasDerivAt (fun k ↦ wSlope σ ψ₁ T₀ ε T k) + (2 * (ε * ψ₁ / Real.sqrt (T + T₀)) ^ 2 * T) 0 := hasDerivAt_wSlope + have hw : HasDerivAt (fun k ↦ totalVar σ ψ₁ T₀ ε k T) (wSlope σ ψ₁ T₀ ε T 0) 0 := + hasDerivAt_totalVar_k + have hkm : HasDerivAt (fun k ↦ k * wSlope σ ψ₁ T₀ ε T k) + (1 * wSlope σ ψ₁ T₀ ε T 0 + 0 * (2 * (ε * ψ₁ / Real.sqrt (T + T₀)) ^ 2 * T)) 0 := + (hasDerivAt_id 0).mul hm + have ht1 := (hkm.div hw hw0ne).neg + have hk2 : HasDerivAt (fun k ↦ k ^ 2) ((2:ℝ) * 0 ^ (2 - 1)) 0 := hasDerivAt_pow 2 0 + have hc2 : HasDerivAt (fun k ↦ totalVar σ ψ₁ T₀ ε k T ^ 2) + (2 * totalVar σ ψ₁ T₀ ε 0 T ^ (2 - 1) * wSlope σ ψ₁ T₀ ε T 0) 0 := + hw.fun_pow 2 + have hA := (hk2.sub hw).sub (hc2.div_const 4) + have hm2 : HasDerivAt (fun k ↦ wSlope σ ψ₁ T₀ ε T k ^ 2) + (2 * wSlope σ ψ₁ T₀ ε T 0 ^ (2 - 1) * (2 * (ε * ψ₁ / Real.sqrt (T + T₀)) ^ 2 * T)) 0 := + hm.fun_pow 2 + have hAm := hA.mul hm2 + have h4 : HasDerivAt (fun k ↦ 4 * totalVar σ ψ₁ T₀ ε k T ^ 2) + (4 * (2 * totalVar σ ψ₁ T₀ ε 0 T ^ (2 - 1) * wSlope σ ψ₁ T₀ ε T 0)) 0 := hc2.const_mul 4 + have h4ne : 4 * totalVar σ ψ₁ T₀ ε 0 T ^ 2 ≠ 0 := by rw [totalVar_zero]; positivity + have ht2 := hAm.div h4 h4ne + have ht3 : HasDerivAt (fun k : ℝ ↦ (ε * ψ₁ / Real.sqrt (T + T₀)) ^ 2 * T) 0 0 := + hasDerivAt_const 0 ((ε * ψ₁ / Real.sqrt (T + T₀)) ^ 2 * T) + have hsum := ht1.add (ht2.add ht3) + refine (hsum.congr_of_eventuallyEq ?_).congr_deriv ?_ + · filter_upwards with k + unfold smileDelta + simp only [Pi.sub_apply, Pi.add_apply, Pi.mul_apply, Pi.neg_apply, Pi.div_apply] + ring + · unfold smileDk + simp only [Pi.sub_apply, Pi.mul_apply] + field_simp [hw0ne, h4ne] + ring + +/-- **The ATM `k`-chain of Dupire's ratio itself**: at every tilt `ε` with nondegenerate +denominator, `∂_k R(ε, ·, T)|₀ = slopeNum/(1 + δ₀)²` — the quotient rule on +`dupireRatio_eq`. -/ +private theorem hasDerivAt_dupireRatio_k_zero {F σ ψ₁ T₀ ε T : ℝ} (hF : 0 < F) (hσ : 0 < σ) + (hT : 0 < T) (hS : 0 < T + T₀) (hD0ne : 1 + smileDelta σ ψ₁ T₀ ε 0 T ≠ 0) : + HasDerivAt (fun k ↦ dupireRatio F σ ψ₁ T₀ ε k T) + (slopeNum σ ψ₁ T₀ ε T / (1 + smileDelta σ ψ₁ T₀ ε 0 T) ^ 2) 0 := by + have hst : 0 < smileSurface σ ψ₁ T₀ ε 0 T := by rwa [smileSurface_atm] + have hN : HasDerivAt (fun k ↦ smileN σ ψ₁ T₀ ε k T) (smileNk σ ψ₁ T₀ ε T) 0 := + hasDerivAt_smileN_k + have hD : HasDerivAt (fun k ↦ smileDelta σ ψ₁ T₀ ε k T) (smileDk σ ψ₁ T₀ ε T) 0 := + hasDerivAt_smileDelta_k hσ hT + have hD1 := hD.const_add 1 + have hQ := hN.div hD1 hD0ne + refine hQ.congr_of_eventuallyEq ?_ + filter_upwards [smileSurface_eventually_pos_k hst] with k hk + exact dupireRatio_eq hF hT hS hk + +/-! ## The `ε`-extraction at zero tilt -/ + +/-- The ATM Gatheral deformation is exactly quadratic in the tilt: +`δ(ε, 0) = ε²·d₂` with `d₂` tilt-free. -/ +private noncomputable def smileD2 (σ ψ₁ T₀ T : ℝ) : ℝ := + (2 * σ * (ψ₁ / Real.sqrt (T + T₀)) * T) ^ 2 + * (-(σ ^ 2 * T) - (σ ^ 2 * T) ^ 2 / 4) / (4 * (σ ^ 2 * T) ^ 2) + + (ψ₁ / Real.sqrt (T + T₀)) ^ 2 * T + +private theorem smileDelta_zero_fac {σ ψ₁ T₀ T : ℝ} (ε : ℝ) : + smileDelta σ ψ₁ T₀ ε 0 T = ε ^ 2 * smileD2 σ ψ₁ T₀ T := by + unfold smileDelta smileD2 + rw [totalVar_zero, wSlope_zero] + ring + +/-- Near zero tilt the deformed denominator stays nondegenerate. -/ +private theorem eventually_one_add_smileDelta_ne_zero {σ ψ₁ T₀ T : ℝ} : + ∀ᶠ ε in nhds 0, 1 + smileDelta σ ψ₁ T₀ ε 0 T ≠ 0 := by + have hc : Continuous fun ε : ℝ ↦ 1 + ε ^ 2 * smileD2 σ ψ₁ T₀ T := by fun_prop + have ht : Filter.Tendsto (fun ε : ℝ ↦ 1 + ε ^ 2 * smileD2 σ ψ₁ T₀ T) (nhds 0) (nhds 1) := by + simpa using hc.tendsto 0 + simpa only [smileDelta_zero_fac] using ht.eventually_ne one_ne_zero + +/-- The `ε`-chain of `N'(0; ε)` — linear in the tilt. -/ +private theorem hasDerivAt_smileNk_eps {σ ψ₁ T₀ T : ℝ} : + HasDerivAt (fun ε ↦ smileNk σ ψ₁ T₀ ε T) + (2 * σ * ψ₁ / Real.sqrt (T + T₀) - σ * ψ₁ * T / ((T + T₀) * Real.sqrt (T + T₀))) 0 := by + have hcore := (hasDerivAt_id 0).const_mul + (2 * σ * ψ₁ / Real.sqrt (T + T₀) - σ * ψ₁ * T / ((T + T₀) * Real.sqrt (T + T₀))) + refine (hcore.congr_of_eventuallyEq ?_).congr_deriv (by ring) + filter_upwards with ε + unfold smileNk + simp only [id_eq] + ring + +/-- The `ε`-chain of the ATM numerator `N(ε, 0) = σ²` — constant in the tilt. -/ +private theorem hasDerivAt_smileN_zero_eps {σ ψ₁ T₀ T : ℝ} : + HasDerivAt (fun ε ↦ smileN σ ψ₁ T₀ ε 0 T) 0 0 := by + refine (hasDerivAt_const 0 (σ ^ 2)).congr_of_eventuallyEq ?_ + filter_upwards with ε + exact smileN_zero σ ψ₁ T₀ ε T + +/-- The `ε`-chain of the deformed denominator `1 + δ(ε, 0) = 1 + ε²d₂`. -/ +private theorem hasDerivAt_one_add_smileDelta_eps {σ ψ₁ T₀ T : ℝ} : + HasDerivAt (fun ε ↦ 1 + smileDelta σ ψ₁ T₀ ε 0 T) 0 0 := by + have hcore := (hasDerivAt_const 0 (1 : ℝ)).add + ((hasDerivAt_pow 2 0).const_mul (smileD2 σ ψ₁ T₀ T)) + refine (hcore.congr_of_eventuallyEq ?_).congr_deriv (by ring) + filter_upwards with ε + simp only [Pi.add_apply] + rw [smileDelta_zero_fac] + ring + +/-- The `ε`-chain of the ATM deformation slope `δ'(0; ε)`: tilt-linear part from the +`−k·w_k/w` term; every other term is `O(ε²)` at the money. -/ +private theorem hasDerivAt_smileDk_eps {σ ψ₁ T₀ T : ℝ} (hσ : 0 < σ) (hT : 0 < T) : + HasDerivAt (fun ε ↦ smileDk σ ψ₁ T₀ ε T) + (-(2 * σ * (ψ₁ / Real.sqrt (T + T₀)) * T / (σ ^ 2 * T))) 0 := by + have hWne : σ ^ 2 * T ≠ 0 := mul_ne_zero (pow_ne_zero 2 hσ.ne') hT.ne' + have hDENne : (4 * (σ ^ 2 * T) ^ 2) ^ 2 ≠ 0 := by positivity + have hid : HasDerivAt (fun ε ↦ ε * ψ₁ / Real.sqrt (T + T₀)) + (ψ₁ / Real.sqrt (T + T₀)) 0 := + (((hasDerivAt_id' 0).mul_const ψ₁).div_const _).congr_deriv (by ring) + have hM := (hid.const_mul (2 * σ)).mul_const T + have hM2 := hM.fun_pow 2 + have hq := hid.fun_pow 2 + have hq2 := (hq.const_mul 2).const_mul T + have hW : HasDerivAt (fun _ : ℝ ↦ σ ^ 2 * T) 0 0 := hasDerivAt_const 0 (σ ^ 2 * T) + have hAp := ((hasDerivAt_const 0 (0 : ℝ)).sub hM).sub ((hW.mul hM).div_const 2) + have hA0 : HasDerivAt (fun _ : ℝ ↦ 0 ^ 2 - σ ^ 2 * T - (σ ^ 2 * T) ^ 2 / 4) 0 0 := + hasDerivAt_const 0 (0 ^ 2 - σ ^ 2 * T - (σ ^ 2 * T) ^ 2 / 4) + have hmid := (hAp.mul hM2).add (hA0.mul ((hM.mul hq2).const_mul 2)) + have hNUM := (hmid.mul (hasDerivAt_const 0 (4 * (σ ^ 2 * T) ^ 2))).sub + (hA0.mul (hM2.mul (((hW.mul hM).const_mul 4).const_mul 2))) + have hDENc : HasDerivAt (fun _ : ℝ ↦ (4 * (σ ^ 2 * T) ^ 2) ^ 2) 0 0 := + hasDerivAt_const 0 ((4 * (σ ^ 2 * T) ^ 2) ^ 2) + have hBIG := hNUM.div hDENc hDENne + have htot := (hM.div hW hWne).neg.add hBIG + refine (htot.congr_of_eventuallyEq ?_).congr_deriv ?_ + · filter_upwards with ε + unfold smileDk + rw [totalVar_zero, wSlope_zero] + simp only [Pi.sub_apply, Pi.add_apply, Pi.mul_apply, Pi.neg_apply, Pi.div_apply] + ring + · field_simp [hWne, hDENne] + ring + +/-- **The `ε`-chain of the ATM slope numerator**: `∂_ε[slopeNum]|₀ = +2σψ₁((3/2)T + 2T₀)/(T+T₀)^{3/2}`, the eq-10.8 coefficient. -/ +private theorem hasDerivAt_slopeNum {σ ψ₁ T₀ T : ℝ} (hσ : 0 < σ) (hT : 0 < T) + (hS : 0 < T + T₀) : + HasDerivAt (fun ε ↦ slopeNum σ ψ₁ T₀ ε T) + (2 * σ * ψ₁ * ((3 / 2) * T + 2 * T₀) / ((T + T₀) * Real.sqrt (T + T₀))) 0 := by + have h1 : HasDerivAt (fun ε ↦ smileNk σ ψ₁ T₀ ε T) + (2 * σ * ψ₁ / Real.sqrt (T + T₀) - σ * ψ₁ * T / ((T + T₀) * Real.sqrt (T + T₀))) 0 := + hasDerivAt_smileNk_eps + have h2 : HasDerivAt (fun ε ↦ 1 + smileDelta σ ψ₁ T₀ ε 0 T) 0 0 := + hasDerivAt_one_add_smileDelta_eps + have h3 : HasDerivAt (fun ε ↦ smileN σ ψ₁ T₀ ε 0 T) 0 0 := + hasDerivAt_smileN_zero_eps + have h4 : HasDerivAt (fun ε ↦ smileDk σ ψ₁ T₀ ε T) + (-(2 * σ * (ψ₁ / Real.sqrt (T + T₀)) * T / (σ ^ 2 * T))) 0 := + hasDerivAt_smileDk_eps hσ hT + have hcomb := (h1.mul h2).sub (h3.mul h4) + refine (hcomb.congr_of_eventuallyEq ?_).congr_deriv ?_ + · filter_upwards with ε + simp only [Pi.sub_apply, Pi.mul_apply] + unfold slopeNum + rfl + · rw [smileDelta_zero, smileNk_zero, smileN_zero] + field_simp [hσ.ne', hT.ne', (Real.sqrt_pos.mpr hS).ne'] + ring + +/-- **Eq 10.8**: for `F, σ, T, T₀ > 0`, the ATM `k`-slope of Dupire's ratio has ε-slope +`2σψ₁·((3/2)T + 2T₀)/(T+T₀)^{3/2}` — the first-order-in-ε coefficient of the local-variance +ATM skew implied by the tilted surface, reading `R` as `σ_loc²` (Dupire's ratio enters as a +definition). -/ +theorem dupireRatio_k_slope {F σ ψ₁ T₀ T : ℝ} (hF : 0 < F) (hσ : 0 < σ) (hT : 0 < T) + (h₀ : 0 < T₀) : + deriv (fun ε ↦ deriv (fun k ↦ dupireRatio F σ ψ₁ T₀ ε k T) 0) 0 + = 2 * σ * ψ₁ * ((3 / 2) * T + 2 * T₀) / ((T + T₀) * Real.sqrt (T + T₀)) := by + have hS : 0 < T + T₀ := by linarith + have hD2ε := + (hasDerivAt_one_add_smileDelta_eps (σ := σ) (ψ₁ := ψ₁) (T₀ := T₀) (T := T)).fun_pow 2 + have hD2ne : (1 + smileDelta σ ψ₁ T₀ 0 0 T) ^ 2 ≠ 0 := by + rw [smileDelta_zero]; norm_num + have hQ := (hasDerivAt_slopeNum (ψ₁ := ψ₁) hσ hT hS).div hD2ε hD2ne + rw [smileDelta_zero, slopeNum_zero] at hQ + refine (hasDerivAt_deriv_param_of_eventually + (eventually_one_add_smileDelta_ne_zero.mono fun ε hε ↦ + hasDerivAt_dupireRatio_k_zero hF hσ hT hS hε) (hQ.congr_deriv ?_)).deriv + norm_num + +/-! ## The `σ_loc` reading -/ + +/-- The closed form of the first-order-in-ε local-vol ATM skew of the tilted surface, +`ψ₁·((3/2)T + 2T₀)/(T+T₀)^{3/2}` (with `(T+T₀)^{3/2}` rendered as `(T+T₀)·√(T+T₀)`); +`dupireRatio_sqrt_slope` identifies it with the ε-slope of the ATM `k`-slope of `√R` for +`F, σ, T, T₀ > 0`. -/ +noncomputable def localSkew (ψ₁ T₀ T : ℝ) : ℝ := + ψ₁ * ((3 / 2) * T + 2 * T₀) / ((T + T₀) * Real.sqrt (T + T₀)) + +/-- **The local-vol ATM skew** (eq 10.8's square-root reading): the ε-slope of the +ATM `k`-slope of `√R` — a first-order-in-ε reading of the local vol implied by the +surface, not the actual skew of the `ε = 1` surface (which carries `O(ψ₁³)` +corrections, not proved here) — is `localSkew ψ₁ T₀ T` for every `T > 0`, given +`F, σ, T₀ > 0`. The closed form at `T = 0` is twice the implied ATM skew (`localSkew_zero`); +as `T → ∞` it behaves like `(3/2)ψ₁/√T` (`tendsto_localSkew_mul_sqrt_atTop`). -/ +theorem dupireRatio_sqrt_slope {F σ ψ₁ T₀ T : ℝ} (hF : 0 < F) (hσ : 0 < σ) (hT : 0 < T) + (h₀ : 0 < T₀) : + deriv (fun ε ↦ deriv (fun k ↦ Real.sqrt (dupireRatio F σ ψ₁ T₀ ε k T)) 0) 0 + = localSkew ψ₁ T₀ T := by + unfold localSkew + have hS : 0 < T + T₀ := by linarith + have hev : ∀ᶠ ε in nhds 0, 1 + smileDelta σ ψ₁ T₀ ε 0 T ≠ 0 := + eventually_one_add_smileDelta_ne_zero + have hR0ne (ε : ℝ) (hε : 1 + smileDelta σ ψ₁ T₀ ε 0 T ≠ 0) : + dupireRatio F σ ψ₁ T₀ ε 0 T ≠ 0 := by + have hst : 0 < smileSurface σ ψ₁ T₀ ε 0 T := by rwa [smileSurface_atm] + rw [dupireRatio_eq hF hT hS hst, smileN_zero] + exact div_ne_zero (pow_ne_zero 2 hσ.ne') hε + have hR0sq (ε : ℝ) : Real.sqrt (dupireRatio F σ ψ₁ T₀ ε 0 T) + = σ / Real.sqrt (1 + smileDelta σ ψ₁ T₀ ε 0 T) := by + have hst : 0 < smileSurface σ ψ₁ T₀ ε 0 T := by rwa [smileSurface_atm] + rw [dupireRatio_eq hF hT hS hst, smileN_zero, Real.sqrt_div (sq_nonneg σ), + Real.sqrt_sq hσ.le] + have hchain (ε : ℝ) (hε : 1 + smileDelta σ ψ₁ T₀ ε 0 T ≠ 0) : + deriv (fun k ↦ Real.sqrt (dupireRatio F σ ψ₁ T₀ ε k T)) 0 + = (1 / (2 * (σ / Real.sqrt (1 + smileDelta σ ψ₁ T₀ ε 0 T)))) + * (slopeNum σ ψ₁ T₀ ε T / (1 + smileDelta σ ψ₁ T₀ ε 0 T) ^ 2) := by + have hBigk := hasDerivAt_dupireRatio_k_zero hF hσ hT hS hε + have hsq := (Real.hasDerivAt_sqrt (hR0ne ε hε)).comp 0 hBigk + rw [Function.comp_def] at hsq + rw [hsq.deriv, hR0sq ε] + have hSn : HasDerivAt (fun ε ↦ slopeNum σ ψ₁ T₀ ε T) + (2 * σ * ψ₁ * ((3 / 2) * T + 2 * T₀) / ((T + T₀) * Real.sqrt (T + T₀))) 0 := + hasDerivAt_slopeNum hσ hT hS + have hD0ε : HasDerivAt (fun ε ↦ 1 + smileDelta σ ψ₁ T₀ ε 0 T) 0 0 := + hasDerivAt_one_add_smileDelta_eps + have hD0ne : (1 : ℝ) + smileDelta σ ψ₁ T₀ 0 0 T ≠ 0 := by rw [smileDelta_zero]; norm_num + have hsD0 := (Real.hasDerivAt_sqrt hD0ne).comp 0 hD0ε + rw [Function.comp_def] at hsD0 + have hD2ε := hD0ε.fun_pow 2 + have hD2ne : (1 + smileDelta σ ψ₁ T₀ 0 0 T) ^ 2 ≠ 0 := by + rw [smileDelta_zero]; norm_num + have hV := hSn.div hD2ε hD2ne + have hprod := hV.mul hsD0 + have h2σ : HasDerivAt (fun _ : ℝ ↦ 2 * σ) 0 0 := hasDerivAt_const 0 (2 * σ) + have hfin := hprod.div h2σ (mul_ne_zero two_pos.ne' hσ.ne') + refine (hfin.congr_deriv ?_).congr_of_eventuallyEq ?_ |>.deriv + · rw [show (1 : ℝ) + smileDelta σ ψ₁ T₀ 0 0 T = 1 from by rw [smileDelta_zero]; norm_num, + Real.sqrt_one, slopeNum_zero] + field_simp [hσ.ne', hT.ne', hS.ne', (Real.sqrt_pos.mpr hS).ne'] + ring + · filter_upwards [hev] with ε hε + rw [hchain ε hε] + simp only [Pi.mul_apply, Pi.div_apply] + by_cases hD : 0 < 1 + smileDelta σ ψ₁ T₀ ε 0 T + · have hs0 : Real.sqrt (1 + smileDelta σ ψ₁ T₀ ε 0 T) ≠ 0 := + ne_of_gt (Real.sqrt_pos.mpr hD) + have hD0 : 1 + smileDelta σ ψ₁ T₀ ε 0 T ≠ 0 := ne_of_gt hD + field_simp [hσ.ne', hs0, hD0] + · have hsq0 : Real.sqrt (1 + smileDelta σ ψ₁ T₀ ε 0 T) = 0 := + (Real.sqrt_eq_zero' (x := 1 + smileDelta σ ψ₁ T₀ ε 0 T)).mpr (not_lt.mp hD) + rw [hsq0] + simp + +/-! ## Corollaries -/ + +/-- **The rule of two, on the closed form**: for `T₀ > 0`, `localSkew` at `T = 0` is `2·(ψ₁/√T₀)`, +twice the implied ATM skew `ψ₁/√T₀`. An algebraic identity on the closed form; +`dupireRatio_sqrt_slope` identifies the closed form with the skew only for `T > 0`. -/ +theorem localSkew_zero (ψ₁ T₀ : ℝ) (h₀ : 0 < T₀) : + localSkew ψ₁ T₀ 0 = 2 * (ψ₁ / Real.sqrt T₀) := by + unfold localSkew + norm_num + field_simp [(Real.sqrt_pos.mpr h₀).ne'] + +/-- **The rule of two as a limit**: `localSkew` tends, as `T → 0`, to `2·(ψ₁/√T₀)`, the +value of `localSkew_zero` (continuity of the closed form at `0`). -/ +theorem tendsto_localSkew_nhds_zero (ψ₁ T₀ : ℝ) (h₀ : 0 < T₀) : + Filter.Tendsto (fun T ↦ localSkew ψ₁ T₀ T) (nhds 0) (nhds (2 * (ψ₁ / Real.sqrt T₀))) := by + have h : ContinuousAt (fun T ↦ localSkew ψ₁ T₀ T) 0 := by + change ContinuousAt (fun T : ℝ ↦ ψ₁ * ((3 / 2) * T + 2 * T₀) + / ((T + T₀) * Real.sqrt (T + T₀))) 0 + exact ContinuousAt.div (by fun_prop) (by fun_prop) (by simp only [zero_add]; positivity) + rw [← localSkew_zero ψ₁ T₀ h₀] + exact h.tendsto + +/-- **The calendar-time asymptotic** of the closed form: `localSkew ψ₁ T₀ T · √T` tends to +`(3/2)ψ₁` as `T → ∞`. -/ +theorem tendsto_localSkew_mul_sqrt_atTop (ψ₁ T₀ : ℝ) : + Filter.Tendsto (fun T ↦ localSkew ψ₁ T₀ T * Real.sqrt T) Filter.atTop + (nhds ((3 / 2) * ψ₁)) := by + unfold localSkew + have hinv : Filter.Tendsto (fun T : ℝ ↦ (T + T₀)⁻¹) Filter.atTop (nhds (0 : ℝ)) := + tendsto_inv_atTop_zero.comp (Filter.tendsto_atTop_add_const_right _ T₀ Filter.tendsto_id) + have hA : Filter.Tendsto (fun T : ℝ ↦ (3 / 2 : ℝ) + (T₀ / 2) * (T + T₀)⁻¹) + Filter.atTop (nhds ((3 / 2 : ℝ) + (T₀ / 2) * 0)) := + (tendsto_const_nhds (x := (3 / 2 : ℝ))).add ((tendsto_const_nhds (x := T₀ / 2)).mul hinv) + rw [show ((3 : ℝ) / 2 + (T₀ / 2) * 0) = 3 / 2 from by norm_num] at hA + have hM0 : Filter.Tendsto (fun T : ℝ ↦ 1 - T₀ * (T + T₀)⁻¹) Filter.atTop (nhds (1 : ℝ)) := by + simpa using ((tendsto_const_nhds (x := (1 : ℝ))).sub + ((tendsto_const_nhds (x := T₀)).mul hinv)) + have hM : Filter.Tendsto (fun T : ℝ ↦ Real.sqrt (1 - T₀ * (T + T₀)⁻¹)) Filter.atTop + (nhds (1 : ℝ)) := by + simpa using hM0.sqrt + have hfin := (tendsto_const_nhds (x := ψ₁)).mul (hA.mul hM) + rw [mul_one] at hfin + rw [show ψ₁ * ((3 : ℝ) / 2) = (3 / 2) * ψ₁ from by ring] at hfin + refine hfin.congr' ?_ + filter_upwards [Filter.eventually_gt_atTop (-T₀), Filter.eventually_ge_atTop 0] with T hT hT0 + have hne : T + T₀ ≠ 0 := by linarith + have hpos : 0 < T + T₀ := by linarith + have hinner : 1 - T₀ * (T + T₀)⁻¹ = T / (T + T₀) := by + field_simp [hne] + ring + rw [hinner, Real.sqrt_div hT0] + field_simp [hne, (Real.sqrt_pos.mpr hpos).ne'] + ring + +/-! ## The rule of two on the surface itself -/ + +/-- **The implied ATM skew, first order in ε**: the ε-slope at `ε = 0` of the ATM `k`-slope of +the implied-volatility surface is `ψ₁/√(T+T₀)` (the surface is affine in `k`). -/ +theorem smileSurface_skew_slope (σ ψ₁ T₀ T : ℝ) : + deriv (fun ε ↦ deriv (fun k ↦ smileSurface σ ψ₁ T₀ ε k T) 0) 0 + = ψ₁ / Real.sqrt (T + T₀) := by + have h : (fun ε ↦ deriv (fun k ↦ smileSurface σ ψ₁ T₀ ε k T) 0) + = fun ε ↦ ε * (ψ₁ / Real.sqrt (T + T₀)) := + funext fun ε ↦ (hasDerivAt_smileSurface_k (σ := σ) (ψ₁ := ψ₁) (T₀ := T₀) (ε := ε) + (T := T) (x := 0)).deriv.trans (mul_div_assoc ε ψ₁ _) + rw [h, (hasDerivAt_mul_const _).deriv] + +/-- **Local versus implied ATM skew, first order in ε.** For `F, σ, T₀ > 0` and every `T > 0`, +the ε-slope of the ATM `k`-slope of `√R` (Dupire's local volatility, `R` taken as its +definition) is the ε-slope of the implied ATM skew times `((3/2)T + 2T₀)/(T + T₀)`, a factor +that decreases from `2` (as `T → 0⁺`) to `3/2` (as `T → ∞`). -/ +theorem dupireRatio_sqrt_slope_eq_mul_skew {F σ ψ₁ T₀ T : ℝ} (hF : 0 < F) (hσ : 0 < σ) + (hT : 0 < T) (h₀ : 0 < T₀) : + deriv (fun ε ↦ deriv (fun k ↦ Real.sqrt (dupireRatio F σ ψ₁ T₀ ε k T)) 0) 0 + = ((3 / 2) * T + 2 * T₀) / (T + T₀) + * deriv (fun ε ↦ deriv (fun k ↦ smileSurface σ ψ₁ T₀ ε k T) 0) 0 := by + rw [dupireRatio_sqrt_slope hF hσ hT h₀, smileSurface_skew_slope, localSkew, + div_mul_div_comm, mul_comm ψ₁] + +/-- **The rule of two on the tilted surface.** For `F, σ, T₀ > 0`, as `T → 0⁺` the +first-order-in-ε local-volatility ATM skew (the ε-slope of the ATM `k`-slope of `√R`) tends to +twice the first-order implied ATM skew at `T = 0`, `2·ψ₁/√T₀`. The statement is about the Dupire +ratio of the surface for `T > 0` (`dupireRatio_sqrt_slope`), not only about the closed form +`localSkew`. -/ +theorem tendsto_dupireRatio_sqrt_slope_nhdsGT_zero {F σ ψ₁ T₀ : ℝ} (hF : 0 < F) + (hσ : 0 < σ) (h₀ : 0 < T₀) : + Filter.Tendsto + (fun T ↦ deriv (fun ε ↦ deriv (fun k ↦ Real.sqrt (dupireRatio F σ ψ₁ T₀ ε k T)) 0) 0) + (nhdsWithin 0 (Set.Ioi 0)) + (nhds (2 * deriv (fun ε ↦ deriv (fun k ↦ smileSurface σ ψ₁ T₀ ε k 0) 0) 0)) := by + rw [smileSurface_skew_slope, zero_add] + exact ((tendsto_localSkew_nhds_zero ψ₁ T₀ h₀).mono_left nhdsWithin_le_nhds).congr' + (eventually_nhdsWithin_of_forall fun T hT ↦ (dupireRatio_sqrt_slope hF hσ hT h₀).symm) + +end MathFin.ForwardSmile diff --git a/LeanPool/MathFin/Models/ModelFree/BreedenLitzenberger.lean b/LeanPool/MathFin/Models/ModelFree/BreedenLitzenberger.lean new file mode 100644 index 0000000000..95f5e6073b --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/BreedenLitzenberger.lean @@ -0,0 +1,181 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.StrikeGreeks +public import LeanPool.MathFin.Models.BlackScholes.StrikeConvexity + +/-! +# Breeden-Litzenberger: implied risk-neutral PDF from option prices + +The Breeden-Litzenberger identity says the risk-neutral PDF of the terminal +asset price `S_T`, evaluated at strike `K`, equals `e^{rT}` times the second +strike-derivative of the European call price: + + `f_{S_T}(K) = e^{rT} · ∂²_K C(K)`. + +Specialising to the BS model: `∂²_K bsV = e^{-rT} · ϕ(d_2)/(K σ √T)` +(`hasDerivAt_deriv_bsV_K` in `StrikeGreeks.lean`), so + + `f_{S_T}(K) = ϕ(d_2(K)) / (K σ √T)`, + +which is the lognormal density at `K` (parameters +`log S_0 + (r − σ²/2)T, σ² T`). This file defines `lognormalTerminalPDF` as that +formula. It proves neither that `S_T` has it as its density nor, beyond the +differential identity at the end, that it integrates to 1. Both are proved +downstream, for the Black–Scholes price (the jump-diffusion without jumps at the +drift `r − σ²/2`): the law of the price is `lognormalTerminalPDF(K) dK` on `(0, ∞)` +(`jumpDiffusionIncrementLaw_zero_map_mul_exp`) and the formula integrates to one +(`lintegral_lognormalTerminalPDF_eq_one`), in `JumpDiffusionDigital.lean`. Merton's +Poisson mixture of these formulas is `mertonTerminalPDF` (`MertonStrikeGreeks.lean`). + +## Structural connection: PDF positivity = strike-convexity of the price + +The non-negativity `0 ≤ f_{S_T}(K)` is *not* an independent fact. It is the +infinitesimal manifestation of a convexity chain: + +1. The call **payoff** is convex in `K` (`convexOn_call_payoff` in + `StrikeConvexity.lean`). +2. Risk-neutral expectation preserves convexity: integration against a positive + measure does, for any law with a finite mean (`convexOn_integral_call`; the + finite-state form is `callPrice_finiteState_convexOn_K`). +3. So the call **price** `K ↦ bsV K r σ S T` is convex in `K`. +4. So `∂²_K bsV ≥ 0`. +5. By Breeden-Litzenberger, `∂²_K bsV = e^{-rT} · f_{S_T}(K)`, so + `f_{S_T}(K) ≥ 0`. + +Every step is formal. Step 3 is step 2 for the standard normal law, the +Black–Scholes price being the discounted expected payoff (`bs_call_formula`, +`bsV_strike_convexOn`); it does not use the sign of the closed form. The +positivity of the standard normal law still enters, as `ϕ ≥ 0` inside +`bs_call_formula` (Mathlib's `integral_gaussianReal_eq_integral_smul`), and that +is also the fact `lognormalTerminalPDF_nonneg` uses. So the two proofs of the +sign of the density share their root: `lognormalTerminalPDF_nonneg` reads it off +the formula, and `lognormalTerminalPDF_nonneg_via_strike_convexity`, steps +3 → 4 → 5, explains it by the convexity of the payoff. + +## Main definitions + +* `lognormalTerminalPDF`: the lognormal density of `S_T` at strike `K`, written through the + Black–Scholes `d₂`: `ϕ(d₂(K)) / (K · σ · √T)`. + +## Main results + +* `breedenLitzenberger`: `∂²_K bsV(K) = e^{-rT} · lognormalTerminalPDF(K)`. +* `lognormalTerminalPDF_nonneg`: `0 ≤ lognormalTerminalPDF`, directly. +* `lognormalTerminalPDF_nonneg_via_strike_convexity`: the same, from the strike + convexity of the price. + +## References + +* [Breeden and Litzenberger, *Prices of state-contingent claims implicit in option + prices*][BreedenLitzenberger1978] + +## Tags + +risk-neutral density, implied distribution, second strike derivative, state price density, +option-implied PDF, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- **Lognormal PDF of `S_T`** at strike `K`, expressed via the BS `d_2` +parameter: `f(K) = ϕ(d_2(K)) / (K · σ · √T)`. -/ +noncomputable def lognormalTerminalPDF (S_0 r σ T K : ℝ) : ℝ := + gaussianPDFReal 0 1 (bsd2 S_0 K r σ T) / (K * σ * Real.sqrt T) + +/-- **Breeden-Litzenberger formula** under the Black-Scholes model: the second +strike-derivative of the call price is the discounted lognormal density, +`∂²C/∂K² = e^{-rT} · lognormalTerminalPDF(K)`. This is `hasDerivAt_deriv_bsV_K` with the value +read as a density, since `lognormalTerminalPDF` unfolds to `ϕ(d₂) / (K σ √T)`. -/ +theorem breedenLitzenberger {S_0 r σ : ℝ} (hS : 0 < S_0) (hσ : 0 < σ) + {K T : ℝ} (hK : 0 < K) (hT : 0 < T) : + HasDerivAt (deriv fun k ↦ bsV k r σ S_0 T) + (Real.exp (-(r * T)) * lognormalTerminalPDF S_0 r σ T K) K := + (hasDerivAt_deriv_bsV_K hS hσ hK hT).congr_deriv (mul_div_assoc _ _ _) + +/-- **Implied PDF non-negativity**, directly: `ϕ ≥ 0` and `K σ √T > 0`. The route through the +strike convexity of the price is `lognormalTerminalPDF_nonneg_via_strike_convexity`. That +`lognormalTerminalPDF` is a probability density is not proved here; it is +`lintegral_lognormalTerminalPDF_eq_one` (`JumpDiffusionDigital.lean`). -/ +theorem lognormalTerminalPDF_nonneg + {S_0 r σ T K : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + 0 ≤ lognormalTerminalPDF S_0 r σ T K := by + unfold lognormalTerminalPDF + have h_pdf_nn : 0 ≤ gaussianPDFReal 0 1 (bsd2 S_0 K r σ T) := + gaussianPDFReal_nonneg _ _ _ + have h_den_pos : 0 < K * σ * Real.sqrt T := + mul_pos (mul_pos hK hσ) (Real.sqrt_pos.mpr hT) + exact div_nonneg h_pdf_nn h_den_pos.le + +/-! ## PDF non-negativity ← strike convexity + +The proof of `lognormalTerminalPDF_nonneg` above uses direct positivity of the +gaussian PDF (one-line). This section records the **structural derivation** +through `bsV_strike_convexOn`, exhibiting PDF non-negativity as the +infinitesimal face of the K-convexity principle: convexity makes +`0 ≤ ∂²_K bsV` (`deriv_deriv_nonneg_of_convexOn`), and Breeden-Litzenberger +identifies `∂²_K bsV` with `e^{-rT} · PDF(K)`. -/ + +/-- **PDF non-negativity as a corollary of strike convexity**, the sign of the density derived +from the convexity of the payoff. + +The derivation chain made explicit: + +1. `bsV_strike_convexOn`: the BS call *price* is convex in K on `(0, ∞)`. +2. `deriv_deriv_nonneg_of_convexOn`: so `0 ≤ ∂²_K bsV` there, since its strike + derivative is monotone (`ConvexOn.monotoneOn_deriv`). +3. `breedenLitzenberger`: `∂²_K bsV = e^{-rT} · PDF`. +4. So `0 ≤ e^{-rT} · PDF`. Dividing by positive `e^{-rT}` gives the result. + +The complementary `lognormalTerminalPDF_nonneg` proof above is shorter +(direct gaussian-PDF positivity); this proof takes the sign from +`bsV`-convexity. `bsV_strike_convexOn` comes from the convexity of the +payoff integrated against the standard normal law (`convexOn_integral_call`, +`bs_call_formula`), not from the sign of the closed form. The positivity of that +law still enters: `bs_call_formula` evaluates the Gaussian integral through +Mathlib's `integral_gaussianReal_eq_integral_smul`, which uses `ϕ ≥ 0` +(`toReal_gaussianPDF`), the fact the direct proof uses. So the two routes share +their root; this one explains the sign rather than reading it off the formula. -/ +theorem lognormalTerminalPDF_nonneg_via_strike_convexity + {S_0 r σ T K : ℝ} (hS₀ : 0 < S_0) (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + 0 ≤ lognormalTerminalPDF S_0 r σ T K := by + have h := deriv_deriv_nonneg_of_convexOn (bsV_strike_convexOn (r := r) hS₀ hσ hT) isOpen_Ioi + (fun _ hk ↦ (hasDerivAt_bsV_K hS₀ hσ hk hT).differentiableAt) (Set.mem_Ioi.mpr hK) + rw [(breedenLitzenberger hS₀ hσ hK hT).deriv] at h + exact (mul_nonneg_iff_of_pos_left (Real.exp_pos _)).mp h + +/-! ## Change of variables to standard normal (folded from `LognormalCOV.lean`) + +The implied PDF and the standard-normal PDF are related by the substitution +`K ↦ z = −bsd2(K)`, whose Jacobian is `dz/dK = −1/(K σ √T)`. The +differential identity below packages this. + +The integration-to-1 claim is `lintegral_lognormalTerminalPDF_eq_one` +(`JumpDiffusionDigital.lean`), the mass of the law of the price, through the +measure-level change of variables `y ↦ Seʸ` (`map_mul_exp_withDensity`); this file +states only the differential. -/ + +/-- **Differential change-of-variables identity** between the lognormal PDF +of `S_T` and the standard-normal PDF: +`f(K) · K · σ · √T = ϕ(bsd2(K))`. -/ +theorem lognormalTerminalPDF_change_of_variables + {S_0 r σ T K : ℝ} (hK : 0 < K) (hσ : 0 < σ) (hT : 0 < T) : + lognormalTerminalPDF S_0 r σ T K * (K * σ * Real.sqrt T) = + gaussianPDFReal 0 1 (bsd2 S_0 K r σ T) := by + unfold lognormalTerminalPDF + have hsqrtT_pos : 0 < Real.sqrt T := Real.sqrt_pos.mpr hT + have h_den_ne : K * σ * Real.sqrt T ≠ 0 := + (mul_pos (mul_pos hK hσ) hsqrtT_pos).ne' + field_simp + +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/CalendarArbitrage.lean b/LeanPool/MathFin/Models/ModelFree/CalendarArbitrage.lean new file mode 100644 index 0000000000..d0d84e6cc8 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/CalendarArbitrage.lean @@ -0,0 +1,196 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.ImpliedVolatility +public import LeanPool.MathFin.Models.ModelFree.SVI.BlackScholesBridge +public import Mathlib.MeasureTheory.Function.ConditionalExpectation.CondJensen +public import Mathlib.Probability.Martingale.Basic + +/-! +# Calendar arbitrage: Gatheral–Jacquier Lemma 2.1 + +Gatheral and Jacquier, *Arbitrage-free SVI volatility surfaces* (Quantitative Finance 14(1), +2014), §2.1, Lemma 2.1: an implied total-variance surface `w(k, t)` is free of calendar spread +arbitrage iff `t ↦ w(k, t)` is non-decreasing for every log-moneyness `k`. The proof runs in two +steps, both proved here with zero rates, for maturities `t > 0`. + +1. **Martingale step.** If the (forward) price `X_t` is a martingale, then for every level `L` + the undiscounted call value `t ↦ E[(X_t − L)⁺]` is non-decreasing: by conditional Jensen, + `(X_s − L)⁺ = (E[X_t | ℱ_s] − L)⁺ ≤ E[(X_t − L)⁺ | ℱ_s]` for `s ≤ t`. +2. **Black–Scholes step.** With zero rates the Black–Scholes call depends on volatility and + maturity only through the total variance `w = σ²T` (for `σ, T > 0`; `totalVarianceCall` is + the call at unit maturity and volatility `√w`), and for strike and spot `K, S > 0` it is + strictly increasing in `w > 0` (positive vega, `bsV_strictMonoOn_sigma`). So call prices are + non-decreasing in maturity at every strike iff total variance is non-decreasing in maturity + at every log-moneyness. + +## Main definitions + +* `totalVarianceCall`: the zero-rate, unit-maturity Black–Scholes call `bsV K 0 (√w) S 1` at + strike `K` and spot (forward) `S`, parametrised by total variance `w = σ²T`. + +## Main results + +* `integral_posPart_sub_mono_of_martingale`: `s ≤ t → E[(X_s − L)⁺] ≤ E[(X_t − L)⁺]`. +* `deriv_integral_posPart_sub_nonneg`: the maturity derivative of that call value is + nonnegative (`∂_T C ≥ 0`, as a `deriv`). +* `bsV_eq_totalVarianceCall`: the zero-rate Black–Scholes call is a function of `σ²T`. +* `strictMonoOn_totalVarianceCall`: it is strictly increasing in total variance. +* `calendar_free_iff`: call prices non-decreasing in maturity on `t > 0` at every strike ↔ + `t ↦ w(k, t)` non-decreasing on `t > 0` at every `k` (the price form of Lemma 2.1). +* `monotone_totalVariance_of_martingale`: a total-variance surface whose Black–Scholes prices + are the call values of a martingale is non-decreasing in maturity on `t > 0`. +* `SVI.bsSmile_calendar_free_iff`: the same equivalence for a maturity-indexed family of raw + SVI slices, on the SVI library's `bsSmile` price. + +**Scope.** Rates and dividends are zero and the forward is the spot `S`. In the last three +results the total variance is assumed positive on maturities `t > 0` and the monotonicity is on +`t > 0` (`MonotoneOn … (Ioi 0)`); nothing is assumed at `t ≤ 0`, so surfaces with +`w(k, t) → 0` as `t → 0⁺`, such as the flat `w = σ²t`, are covered. The local-variance +characterisation (crossed total-variance lines ↔ negative local variance) is not formalised +here. + +## References + +* [Gatheral and Jacquier, *Arbitrage-free SVI volatility surfaces*][GatheralJacquier2014], Section + 2.1, Lemma 2.1 + +## Tags + +calendar spread arbitrage, total variance surface, Gatheral–Jacquier, SVI, +implied volatility surface, static arbitrage, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +open MeasureTheory Set + +/-! ### Martingale step -/ + +/-- **Calls on a martingale are non-decreasing in maturity** (Gatheral–Jacquier 2014, +Lemma 2.1, martingale half). For a real martingale `X` on a finite measure space and any level +`L`, `s ≤ t` implies `∫ (X_s − L)⁺ ≤ ∫ (X_t − L)⁺`. The proof is conditional Jensen +(`ConvexOn.map_condExp_le`) applied to the convex payoff `x ↦ (x − L)⁺`. -/ +theorem integral_posPart_sub_mono_of_martingale {Ω ι : Type*} [Preorder ι] {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} [IsFiniteMeasure μ] {ℱ : Filtration ι mΩ} {X : ι → Ω → ℝ} + (hX : Martingale X ℱ μ) (L : ℝ) {s t : ι} (hst : s ≤ t) : + ∫ ω, (X s ω - L)⁺ ∂μ ≤ ∫ ω, (X t ω - L)⁺ ∂μ := by + set φ : ℝ → ℝ := fun x ↦ (x - L)⁺ + have hφc : Continuous φ := by fun_prop + have hcvx : ConvexOn ℝ univ φ := + ((convexOn_id convex_univ).sub (concaveOn_const L convex_univ)).sup + (convexOn_const 0 convex_univ) + have hint : ∀ u, Integrable (X u) μ := fun u ↦ hX.integrable u + have hφint : ∀ u, Integrable (φ ∘ X u) μ := fun u ↦ + ((hint u).sub (integrable_const L)).pos_part + have hJ := hcvx.map_condExp_le (ℱ.le s) (hφc.lowerSemicontinuous.lowerSemicontinuousOn univ) + (by simp) isClosed_univ (hint t) (hφint t) + have heq : φ ∘ X s =ᵐ[μ] φ ∘ μ[X t | ℱ s] := by + filter_upwards [hX.2 s t hst] with ω hω + simp [Function.comp, hω] + calc ∫ ω, (X s ω - L)⁺ ∂μ = ∫ ω, (φ ∘ X s) ω ∂μ := rfl + _ = ∫ ω, (φ ∘ μ[X t | ℱ s]) ω ∂μ := integral_congr_ae heq + _ ≤ ∫ ω, (μ[φ ∘ X t | ℱ s]) ω ∂μ := + integral_mono_ae ((hφint s).congr heq) integrable_condExp hJ + _ = ∫ ω, (X t ω - L)⁺ ∂μ := integral_condExp (ℱ.le s) + +/-- **`∂_T C ≥ 0`**: the maturity derivative of the undiscounted call value on a real-indexed +martingale is nonnegative wherever it is taken (Mathlib's `deriv`, which is `0` where the +function is not differentiable). -/ +theorem deriv_integral_posPart_sub_nonneg {Ω : Type*} {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} [IsFiniteMeasure μ] {ℱ : Filtration ℝ mΩ} {X : ℝ → Ω → ℝ} + (hX : Martingale X ℱ μ) (L t : ℝ) : + 0 ≤ deriv (fun u ↦ ∫ ω, (X u ω - L)⁺ ∂μ) t := + Monotone.deriv_nonneg fun _ _ h ↦ integral_posPart_sub_mono_of_martingale hX L h + +/-! ### Black–Scholes step -/ + +/-- The zero-rate, unit-maturity Black–Scholes call at strike `K` and spot (forward) `S`, +parametrised by total variance `w = σ²T`. -/ +noncomputable def totalVarianceCall (K S w : ℝ) : ℝ := bsV K 0 (Real.sqrt w) S 1 + +/-- With zero rates the Black–Scholes call depends on `σ` and `T` only through the total +variance `σ²T`, for `σ > 0` and `T > 0`. -/ +theorem bsV_eq_totalVarianceCall {K S σ T : ℝ} (hσ : 0 < σ) (hT : 0 < T) : + bsV K 0 σ S T = totalVarianceCall K S (σ ^ 2 * T) := by + have hs : Real.sqrt (σ ^ 2 * T) = σ * Real.sqrt T := by + rw [Real.sqrt_mul (sq_nonneg σ), Real.sqrt_sq hσ.le] + have hsT : 0 < Real.sqrt T := Real.sqrt_pos.mpr hT + have hd1 : bsd1 S K 0 (σ * Real.sqrt T) 1 = bsd1 S K 0 σ T := by + simp only [bsd1, Real.sqrt_one, mul_one, zero_add, mul_pow, Real.sq_sqrt hT.le] + congr 1 + ring + unfold totalVarianceCall bsV + simp only [bsd2, hd1, hs, Real.sqrt_one, mul_one, zero_mul, neg_zero, Real.exp_zero] + +/-- The total-variance call is strictly increasing in total variance on `(0, ∞)`, for strike +and spot `K, S > 0`. -/ +theorem strictMonoOn_totalVarianceCall {K S : ℝ} (hK : 0 < K) (hS : 0 < S) : + StrictMonoOn (totalVarianceCall K S) (Ioi 0) := by + intro a ha b hb hab + exact bsV_strictMonoOn_sigma hK one_pos hS (Real.sqrt_pos.mpr ha) (Real.sqrt_pos.mpr hb) + (Real.sqrt_lt_sqrt (le_of_lt ha) hab) + +/-- **Gatheral–Jacquier 2014, Lemma 2.1 (price form).** Let `w(k, t) > 0` be a total-variance +surface over log-moneyness `k` and maturity `t > 0`, priced with zero rates at forward `S > 0`: +the call at strike `K > 0` and maturity `t` is `totalVarianceCall K S (w (log (K / S)) t)`. Call +prices are non-decreasing in maturity on `t > 0` at every strike iff `t ↦ w(k, t)` is +non-decreasing on `t > 0` at every `k`. Nothing is assumed about `w` at `t ≤ 0`, so the flat +surface `w = σ²t` is covered. -/ +theorem calendar_free_iff {S : ℝ} (hS : 0 < S) (w : ℝ → ℝ → ℝ) + (hw : ∀ k, ∀ t, 0 < t → 0 < w k t) : + (∀ K, 0 < K → + MonotoneOn (fun t ↦ totalVarianceCall K S (w (Real.log (K / S)) t)) (Ioi 0)) ↔ + ∀ k, MonotoneOn (w k) (Ioi 0) := by + constructor + · intro h k a ha b hb hab + have hK : 0 < S * Real.exp k := mul_pos hS (Real.exp_pos k) + have hk : Real.log (S * Real.exp k / S) = k := by + rw [mul_div_cancel_left₀ _ hS.ne', Real.log_exp] + have := h _ hK ha hb hab + simp only [hk] at this + exact ((strictMonoOn_totalVarianceCall hK hS).le_iff_le (hw k a ha) (hw k b hb)).mp this + · intro h K hK a ha b hb hab + exact ((strictMonoOn_totalVarianceCall hK hS).le_iff_le (hw _ a ha) (hw _ b hb)).mpr + (h _ ha hb hab) + +/-- **Gatheral–Jacquier 2014, Lemma 2.1 (martingale direction).** If, at every strike `K > 0` +and maturity `t > 0`, the zero-rate Black–Scholes price of a total-variance surface `w`, +positive on `t > 0`, is the call value `∫ (X_t − K)⁺` of a real-indexed martingale `X`, then +`t ↦ w(k, t)` is non-decreasing on `t > 0` at every log-moneyness `k`. -/ +theorem monotone_totalVariance_of_martingale {Ω : Type*} {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} [IsFiniteMeasure μ] {ℱ : Filtration ℝ mΩ} {X : ℝ → Ω → ℝ} + (hX : Martingale X ℱ μ) {S : ℝ} (hS : 0 < S) (w : ℝ → ℝ → ℝ) + (hw : ∀ k, ∀ t, 0 < t → 0 < w k t) + (hprice : ∀ K, 0 < K → ∀ t, 0 < t → + ∫ ω, (X t ω - K)⁺ ∂μ = totalVarianceCall K S (w (Real.log (K / S)) t)) : + ∀ k, MonotoneOn (w k) (Ioi 0) := + (calendar_free_iff hS w hw).mp fun K hK a ha b hb hab ↦ by + simpa only [hprice K hK a ha, hprice K hK b hb] using + integral_posPart_sub_mono_of_martingale hX K hab + +namespace SVI + +/-- **No calendar arbitrage for a family of raw SVI slices.** For raw SVI parameters `p t` +indexed by maturity `t > 0`, with positive variance, the SVI-smiled Black–Scholes price +`bsSmile` (spot, maturity and discount normalised to one) is non-decreasing in maturity on +`t > 0` at every strike iff the SVI total variance `t ↦ variance (p t) k` is non-decreasing on +`t > 0` at every log-moneyness `k` (Gatheral–Jacquier 2014, Lemma 2.1, specialised to the raw +SVI slices of their §3.1). -/ +theorem bsSmile_calendar_free_iff (p : ℝ → Params) + (hw : ∀ t, 0 < t → ∀ k, 0 < variance (p t) k) : + (∀ K, 0 < K → MonotoneOn (fun t ↦ bsSmile (p t) K) (Ioi 0)) ↔ + ∀ k, MonotoneOn (fun t ↦ variance (p t) k) (Ioi 0) := by + have := calendar_free_iff one_pos (fun k t ↦ variance (p t) k) fun k t ht ↦ hw t ht k + simpa only [div_one, totalVarianceCall, bsSmile, rootVariance] using this + +end SVI + +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/CallPriceFunction.lean b/LeanPool/MathFin/Models/ModelFree/CallPriceFunction.lean new file mode 100644 index 0000000000..053f92b6bc --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/CallPriceFunction.lean @@ -0,0 +1,123 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.Convex.Slope +public import Mathlib.Topology.Algebra.Ring.Real + +/-! # Call price functions + +The call prices `K ↦ 𝔼[(S − K)⁺]` of a nonnegative random variable `S` of mean one are convex in +the strike, lie between `(1 − K)⁺` and `1`, and tend to `0` at large strikes. These are the +single-maturity conditions of Roper, *Arbitrage free implied volatility surfaces* (2010), +Theorem 2.1, with the forward normalised to one; a function of the strike that satisfies them is +free of butterfly arbitrage. `IsNormalizedCallPrice` records them, with two consequences: +such a function is nonincreasing and tends to `1` at strike `0` +(`IsNormalizedCallPrice.of_convexOn`). + +Neither direction of the correspondence with random variables is proved here. Of the forward +direction, the convexity holds for any law with a finite mean (`convexOn_integral_call`, in +`StrikeConvexity.lean`). + +## Main definitions + +* `IsNormalizedCallPrice`: the single-maturity conditions on a function `C` of the strike, with + the forward normalised to one. `C` is convex and nonincreasing on `(0, ∞)`, satisfies + `max (1 − K) 0 ≤ C K ≤ 1`, tends to `1` at strike `0⁺` and to `0` at large strikes. + +## Main results + +* `ConvexOn.antitoneOn_Ioi_of_le`: a convex function on `Ioi a` that is bounded above is + nonincreasing. +* `IsNormalizedCallPrice.of_eqOn`: the conditions concern only the values on `(0, ∞)`. +* `IsNormalizedCallPrice.of_convexOn`: convexity on `(0, ∞)`, the bounds `max (1 − K) 0 ≤ C K ≤ 1` + and the limit `0` at infinity give `IsNormalizedCallPrice C`; monotonicity and the limit `1` + at strike `0⁺` are derived. + +## Tags + +call price in strike, convexity in strike, Roper, arbitrage-free surface, +implied volatility surface, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +open Filter Topology Set + +/-- **A convex function on a right-infinite interval that is bounded above is nonincreasing.** A +positive slope somewhere would persist, by convexity, and carry the function past its bound. -/ +theorem ConvexOn.antitoneOn_Ioi_of_le {f : ℝ → ℝ} {a B : ℝ} (hf : ConvexOn ℝ (Ioi a) f) + (hB : ∀ x ∈ Ioi a, f x ≤ B) : AntitoneOn f (Ioi a) := by + intro x hx y hy hxy + by_contra! hfxy + have hxy' : x < y := hxy.lt_of_ne (by rintro rfl; exact lt_irrefl _ hfxy) + set s := (f y - f x) / (y - x) + have hs : 0 < s := div_pos (sub_pos.2 hfxy) (sub_pos.2 hxy') + have hyz : y < y + (B - f y) / s + 1 := by + linarith [div_nonneg (sub_nonneg.2 (hB y hy)) hs.le] + have hz : y + (B - f y) / s + 1 ∈ Ioi a := lt_trans hy hyz + have h := (le_div_iff₀ (sub_pos.2 hyz)).1 (hf.slope_mono_adjacent hx hz hxy' hyz) + have e : s * (y + (B - f y) / s + 1 - y) = (B - f y) + s := by + field_simp + ring + linarith [hB _ hz] + +namespace MathFin + +/-- **A normalised call price function** on positive strikes: convex and nonincreasing, between +the intrinsic value `(1 − K)⁺` and the forward `1`, with limits `1` at strike `0` and `0` at +large strikes. Convexity, the two bounds and the large-strike limit are the single-maturity +conditions of Roper's Theorem 2.1 with the forward normalised to one; the other two fields follow +from them (`IsNormalizedCallPrice.of_convexOn`). -/ +structure IsNormalizedCallPrice (C : ℝ → ℝ) : Prop where + /-- Convex in the strike: no butterfly spread has a negative price. -/ + convexOn : ConvexOn ℝ (Ioi 0) C + /-- Nonincreasing in the strike: no call spread has a negative price. -/ + antitoneOn : AntitoneOn C (Ioi 0) + /-- At least the intrinsic value. -/ + intrinsic_le : ∀ K ∈ Ioi (0 : ℝ), max (1 - K) 0 ≤ C K + /-- At most the forward. -/ + le_one : ∀ K ∈ Ioi (0 : ℝ), C K ≤ 1 + /-- The price at strike `0` is the forward. -/ + tendsto_one : Tendsto C (𝓝[>] 0) (𝓝 1) + /-- The price vanishes at large strikes. -/ + tendsto_zero : Tendsto C atTop (𝓝 0) + +/-- Convexity, the two bounds and the large-strike limit make a normalised call price function: +monotonicity comes from convexity and the upper bound, the limit at strike `0` from the squeeze +`1 − K ≤ C(K) ≤ 1`. -/ +theorem IsNormalizedCallPrice.of_convexOn {C : ℝ → ℝ} (hC : ConvexOn ℝ (Ioi 0) C) + (hlow : ∀ K ∈ Ioi (0 : ℝ), max (1 - K) 0 ≤ C K) (hup : ∀ K ∈ Ioi (0 : ℝ), C K ≤ 1) + (h0 : Tendsto C atTop (𝓝 0)) : IsNormalizedCallPrice C where + convexOn := hC + antitoneOn := hC.antitoneOn_Ioi_of_le hup + intrinsic_le := hlow + le_one := hup + tendsto_one := + tendsto_of_tendsto_of_tendsto_of_le_of_le' + (((by fun_prop : Continuous fun K : ℝ ↦ 1 - K).tendsto' 0 1 (sub_zero 1)).mono_left + nhdsWithin_le_nhds) tendsto_const_nhds + (by filter_upwards [self_mem_nhdsWithin] with K hK using (le_max_left _ _).trans (hlow K hK)) + (by filter_upwards [self_mem_nhdsWithin] with K hK using hup K hK) + tendsto_zero := h0 + +/-- Call price functions are determined by their values on the positive strikes: every field of +`IsNormalizedCallPrice` concerns only `(0, ∞)`. -/ +theorem IsNormalizedCallPrice.of_eqOn {C C' : ℝ → ℝ} (h : IsNormalizedCallPrice C) + (he : EqOn C C' (Ioi 0)) : IsNormalizedCallPrice C' where + convexOn := h.convexOn.congr he + antitoneOn a ha b hb hab := by rw [← he ha, ← he hb]; exact h.antitoneOn ha hb hab + intrinsic_le K hK := by rw [← he hK]; exact h.intrinsic_le K hK + le_one K hK := by rw [← he hK]; exact h.le_one K hK + tendsto_one := h.tendsto_one.congr' + (by filter_upwards [self_mem_nhdsWithin] with K hK using he hK) + tendsto_zero := h.tendsto_zero.congr' + (by filter_upwards [eventually_gt_atTop 0] with K hK using he hK) + +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/CallSpreadDigital.lean b/LeanPool/MathFin/Models/ModelFree/CallSpreadDigital.lean new file mode 100644 index 0000000000..22ab01ed58 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/CallSpreadDigital.lean @@ -0,0 +1,264 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.Calculus.ParametricIntegral +public import Mathlib.Topology.Separation.CompletelyRegular +public import Mathlib.Topology.Algebra.Group.Order + +/-! +# Call spreads tend to the digital, so call prices determine the law + +A bull-call spread long `1/h` calls struck at `K` and short `1/h` calls struck at `K + h` pays +`((X − K)⁺ − (X − K − h)⁺)/h`. The payoff lies in `[0, 1]` (it is nonnegative because the call +payoff is antitone in the strike, `bull_call_spread_payoff_le`), and its absolute value is at most +`1` because the call payoff is `1`-Lipschitz in the strike (`abs_call_payoff_sub_le`). As `h ↓ 0` +it tends to the digital payoff `1_{X > K}`. So in any model, minus the right strike derivative of +the call price is the price of the event `X > K`, and the call prices at every strike determine +the law of the underlying. This is the first-order form of Breeden and Litzenberger (1978), for any +law with a finite mean, not only the lognormal one. + +* `abs_call_payoff_sub_le`: `|(x − k₁)⁺ − (x − k₂)⁺| ≤ |k₁ − k₂|`, the bound that dominates every + call spread and every strike difference quotient below. +* `tendsto_call_spread`: `(C(K) − C(K + h))/h → μ {X > K}` as `h ↓ 0`, where + `C(k) = ∫ (X − k)⁺ dμ`, for a measurable, integrable `X` under a finite measure `μ` (dominated + convergence). +* `measure_eq_of_integral_call_eq`: two probability laws of a log-return, each with `∫ eʸ < ∞`, + that give the same undiscounted call price `∫ (Seʸ − K)⁺` at every strike `K > 0` (for one + `S > 0`) are equal. The digital at the strike `Seᵃ` is the tail `P(Y > a)`. +* `hasDerivAt_integral_call`: where `X` has no atom at `K`, the call price is differentiable at + `K` and `C'(K) = −μ {X > K}` (Mathlib's `hasDerivAt_integral_of_dominated_loc_of_lip`). +* `tendsto_call_spread_left`: the spread just below the strike, `(C(K − h) − C(K))/h`, tends to + `μ {X ≥ K}`. So the left strike derivative is `−μ {X ≥ K}` and the right one `−μ {X > K}`. +* `differentiableAt_integral_call_iff`: the call price is differentiable at `K` iff `X` has no atom + at `K`. At an atom the two one-sided derivatives differ by its mass, and the call price has a + kink. + +In Black–Scholes the strike derivative is `−e^{−rτ}Φ(d₂)` (`hasDerivAt_bsV_K`), from the closed +form. The digital price `e^{−rτ}Φ(d₂)` follows from it through `hasDerivAt_integral_call` +(`jumpDiffusionDigitalPrice_zero`), the same value that `bs_cash_or_nothing_formula` computes as a +Gaussian integral. The second-order form, the lognormal density as the second strike derivative of +`bsV`, is in `Models/ModelFree/BreedenLitzenberger.lean`. + +## Main results + +* `abs_call_payoff_sub_le`: `|(x − k₁)⁺ − (x − k₂)⁺| ≤ |k₁ − k₂|`. +* `tendsto_call_spread`: for a measurable integrable `X` under a finite measure, the bull-call + spread `(C(K) − C(K + h))/h` tends to `μ {K < X}` as `h ↓ 0`. +* `tendsto_call_spread_left`: the spread `(C(K − h) − C(K))/h` tends to `μ {K ≤ X}` as `h ↓ 0`. +* `hasDerivAt_integral_call`: if `μ {X = K} = 0`, the call price `k ↦ ∫ (X − k)⁺` has derivative + `−μ {K < X}` at `K`. +* `differentiableAt_integral_call_iff`: the call price is differentiable at `K` iff + `μ {X = K} = 0`. +* `measure_eq_of_integral_call_eq`: two probability laws of a log-return, each with `∫ eʸ < ∞`, + whose call prices `∫ (S·eʸ − K)⁺` agree at every strike `K > 0`, are equal. + +## References + +* [Breeden and Litzenberger, *Prices of state-contingent claims implicit in option + prices*][BreedenLitzenberger1978] + +## Tags + +call spread, digital option, law from call prices, bull spread, strike derivative, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory Filter Set +open scoped Topology + +/-- **The call payoff is `1`-Lipschitz in the strike**: `|(x − k₁)⁺ − (x − k₂)⁺| ≤ |k₁ − k₂|` +(Mathlib's `abs_max_sub_max_le_abs`). -/ +lemma abs_call_payoff_sub_le (x k₁ k₂ : ℝ) : + |max (x - k₁) 0 - max (x - k₂) 0| ≤ |k₁ - k₂| := + (abs_max_sub_max_le_abs _ _ _).trans_eq (by rw [sub_sub_sub_cancel_left, abs_sub_comm]) + +/-- **A digital is a limit of call spreads.** For a measurable, integrable `X` under a finite +measure `μ`, the bull-call spread `(C(K) − C(K + h))/h`, where `C(k) = ∫ (X − k)⁺ dμ`, tends to +`μ {X > K}` as `h ↓ 0`: minus the right strike derivative of the undiscounted call price is the +price of the event `X > K`. The spread payoff is at most `1` in absolute value (the call payoff is +`1`-Lipschitz in the strike) and tends to `1_{X > K}` pointwise, so dominated convergence +applies. -/ +theorem tendsto_call_spread {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsFiniteMeasure μ] {X : Ω → ℝ} (hXm : Measurable X) (hX : Integrable X μ) (K : ℝ) : + Tendsto (fun h ↦ (∫ ω, max (X ω - K) 0 ∂μ - ∫ ω, max (X ω - (K + h)) 0 ∂μ) / h) (𝓝[>] 0) + (𝓝 (μ.real {ω | K < X ω})) := by + have hcall (k : ℝ) : Integrable (fun ω ↦ max (X ω - k) 0) μ := + (hX.sub (integrable_const k)).pos_part + have hspread : (fun h ↦ (∫ ω, max (X ω - K) 0 ∂μ - ∫ ω, max (X ω - (K + h)) 0 ∂μ) / h) + = fun h ↦ ∫ ω, (max (X ω - K) 0 - max (X ω - (K + h)) 0) / h ∂μ := by + funext h + rw [integral_div, integral_sub (hcall K) (hcall (K + h))] + rw [hspread, ← integral_indicator_one (measurableSet_lt measurable_const hXm)] + refine tendsto_integral_filter_of_dominated_convergence (fun _ ↦ 1) + (Eventually.of_forall fun h ↦ ?_) ?_ (integrable_const 1) (ae_of_all _ fun ω ↦ ?_) + · exact (by fun_prop : Measurable fun ω ↦ + (max (X ω - K) 0 - max (X ω - (K + h)) 0) / h).aestronglyMeasurable + · -- the call payoff is `1`-Lipschitz in the strike, so the spread payoff is at most `1` + filter_upwards [self_mem_nhdsWithin] with h hh + refine ae_of_all _ fun ω ↦ ?_ + have hh : 0 < h := hh + have hlip := abs_call_payoff_sub_le (X ω) K (K + h) + rw [sub_add_cancel_left, abs_neg, abs_of_pos hh] at hlip + change ‖(max (X ω - K) 0 - max (X ω - (K + h)) 0) / h‖ ≤ 1 + rwa [Real.norm_eq_abs, abs_div, abs_of_pos hh, div_le_one hh] + · -- and tends to the digital payoff `1_{X > K}` + by_cases hω : K < X ω + · rw [indicator_of_mem (show ω ∈ {ω | K < X ω} from hω), Pi.one_apply] + refine tendsto_const_nhds.congr' ?_ + filter_upwards [Ioo_mem_nhdsGT (sub_pos.2 hω)] with h hh + rw [max_eq_left (by linarith [hh.1, hh.2]), max_eq_left (by linarith [hh.1, hh.2]), + show X ω - K - (X ω - (K + h)) = h by ring, div_self hh.1.ne'] + · rw [indicator_of_notMem (show ω ∉ {ω | K < X ω} from hω)] + refine tendsto_const_nhds.congr' ?_ + filter_upwards [self_mem_nhdsWithin] with h hh + have hh : 0 < h := hh + rw [max_eq_right (by linarith [not_lt.1 hω]), max_eq_right (by linarith [not_lt.1 hω]), + sub_self, zero_div] + +/-- **Call prices at every strike determine the law** (Breeden–Litzenberger, first order). Two +probability laws of a log-return, each with `∫ eʸ < ∞`, that give the same undiscounted call +price `∫ (Seʸ − K)⁺` at every strike `K > 0` (for one `S > 0`) are equal. The call spreads at the +strike `Seᵃ` tend to the tail `P(Y > a)` under each law (`tendsto_call_spread`), so the tails +agree, and the tails fix the law (Mathlib's `Measure.ext_of_Iic`). -/ +theorem measure_eq_of_integral_call_eq {μ μ' : Measure ℝ} [IsProbabilityMeasure μ] + [IsProbabilityMeasure μ'] {S : ℝ} (hS : 0 < S) (hμ : Integrable Real.exp μ) + (hμ' : Integrable Real.exp μ') + (h : ∀ K, 0 < K → + ∫ y, max (S * Real.exp y - K) 0 ∂μ = ∫ y, max (S * Real.exp y - K) 0 ∂μ') : + μ = μ' := by + have hX : Measurable fun y ↦ S * Real.exp y := by fun_prop + have htail (a : ℝ) : μ (Ioi a) = μ' (Ioi a) := by + have hset : {y | S * Real.exp a < S * Real.exp y} = Ioi a := by + ext y + rw [mem_ofPred_eq, mem_Ioi, mul_lt_mul_iff_right₀ hS, Real.exp_lt_exp] + have hlim := tendsto_call_spread hX (hμ.const_mul S) (S * Real.exp a) + have hlim' := tendsto_call_spread hX (hμ'.const_mul S) (S * Real.exp a) + rw [hset] at hlim hlim' + have hK : 0 < S * Real.exp a := mul_pos hS (Real.exp_pos a) + refine (ENNReal.toReal_eq_toReal_iff' (measure_ne_top μ _) (measure_ne_top μ' _)).1 + (tendsto_nhds_unique hlim (hlim'.congr' ?_)) + filter_upwards [self_mem_nhdsWithin] with k hk + rw [h _ hK, h _ (add_pos hK hk)] + refine Measure.ext_of_Iic μ μ' fun a ↦ ?_ + rw [← compl_Ioi, prob_compl_eq_one_sub measurableSet_Ioi, + prob_compl_eq_one_sub measurableSet_Ioi, htail] + +/-- **The call spread below the strike tends to the digital at or above it.** For a measurable, +integrable `X` under a finite measure `μ`, `(C(K − h) − C(K))/h → μ {X ≥ K}` as `h ↓ 0`, where +`C(k) = ∫ (X − k)⁺ dμ`: minus the left strike derivative of the call price is the price of the +event `X ≥ K`. As in `tendsto_call_spread`, the spread payoff is at most `1` in absolute value; it +is `1` when `X ≥ K` and `0` once `h < K − X`. -/ +theorem tendsto_call_spread_left {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsFiniteMeasure μ] {X : Ω → ℝ} (hXm : Measurable X) (hX : Integrable X μ) (K : ℝ) : + Tendsto (fun h ↦ (∫ ω, max (X ω - (K - h)) 0 ∂μ - ∫ ω, max (X ω - K) 0 ∂μ) / h) (𝓝[>] 0) + (𝓝 (μ.real {ω | K ≤ X ω})) := by + have hcall (k : ℝ) : Integrable (fun ω ↦ max (X ω - k) 0) μ := + (hX.sub (integrable_const k)).pos_part + have hspread : (fun h ↦ (∫ ω, max (X ω - (K - h)) 0 ∂μ - ∫ ω, max (X ω - K) 0 ∂μ) / h) + = fun h ↦ ∫ ω, (max (X ω - (K - h)) 0 - max (X ω - K) 0) / h ∂μ := by + funext h + rw [integral_div, integral_sub (hcall (K - h)) (hcall K)] + rw [hspread, ← integral_indicator_one (measurableSet_le measurable_const hXm)] + refine tendsto_integral_filter_of_dominated_convergence (fun _ ↦ 1) + (Eventually.of_forall fun h ↦ ?_) ?_ (integrable_const 1) (ae_of_all _ fun ω ↦ ?_) + · exact (by fun_prop : Measurable fun ω ↦ + (max (X ω - (K - h)) 0 - max (X ω - K) 0) / h).aestronglyMeasurable + · -- the call payoff is `1`-Lipschitz in the strike, so the spread payoff is at most `1` + filter_upwards [self_mem_nhdsWithin] with h hh + refine ae_of_all _ fun ω ↦ ?_ + have hh : 0 < h := hh + have hlip := abs_call_payoff_sub_le (X ω) (K - h) K + rw [sub_sub_cancel_left, abs_neg, abs_of_pos hh] at hlip + change ‖(max (X ω - (K - h)) 0 - max (X ω - K) 0) / h‖ ≤ 1 + rwa [Real.norm_eq_abs, abs_div, abs_of_pos hh, div_le_one hh] + · -- and tends to the digital payoff `1_{X ≥ K}` + by_cases hω : K ≤ X ω + · rw [indicator_of_mem (show ω ∈ {ω | K ≤ X ω} from hω), Pi.one_apply] + refine tendsto_const_nhds.congr' ?_ + filter_upwards [self_mem_nhdsWithin] with h hh + have hh : 0 < h := hh + rw [max_eq_left (by linarith), max_eq_left (by linarith), + show X ω - (K - h) - (X ω - K) = h by ring, div_self hh.ne'] + · rw [indicator_of_notMem (show ω ∉ {ω | K ≤ X ω} from hω)] + refine tendsto_const_nhds.congr' ?_ + filter_upwards [Ioo_mem_nhdsGT (sub_pos.2 (not_le.1 hω))] with h hh + rw [max_eq_right (by linarith [hh.2, not_le.1 hω]), + max_eq_right (by linarith [hh.2, not_le.1 hω]), sub_self, zero_div] + +/-- **The strike derivative of the call price is minus the digital.** For a measurable, integrable +`X` under a finite measure `μ` with no atom at `K` (`μ {X = K} = 0`), the undiscounted call price +`C(k) = ∫ (X − k)⁺ dμ` is differentiable at `K` and `C'(K) = −μ {X > K}`. The call payoff is +`1`-Lipschitz in the strike and, off the atom, differentiable at `K` with derivative `−1_{X > K}`, +so Mathlib's `hasDerivAt_integral_of_dominated_loc_of_lip` applies. -/ +theorem hasDerivAt_integral_call {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsFiniteMeasure μ] {X : Ω → ℝ} (hXm : Measurable X) (hX : Integrable X μ) {K : ℝ} + (hK : μ {ω | X ω = K} = 0) : + HasDerivAt (fun k ↦ ∫ ω, max (X ω - k) 0 ∂μ) (-μ.real {ω | K < X ω}) K := by + have hset : MeasurableSet {ω | K < X ω} := measurableSet_lt measurable_const hXm + have hae : ∀ᵐ ω ∂μ, X ω ≠ K := ae_iff.2 (by simpa using hK) + rw [← integral_indicator_one hset, ← integral_neg] + refine (hasDerivAt_integral_of_dominated_loc_of_lip (F := fun k ω ↦ max (X ω - k) 0) + (F' := fun ω ↦ -{ω | K < X ω}.indicator 1 ω) (bound := fun _ ↦ 1) univ_mem + (Eventually.of_forall fun k ↦ ?_) (hX.sub (integrable_const K)).pos_part + (measurable_one.indicator hset).neg.aestronglyMeasurable + (ae_of_all _ fun ω ↦ (LipschitzWith.of_dist_le_mul fun k₁ k₂ ↦ ?_).lipschitzOnWith) + (integrable_const 1) ?_).2 + · exact (by fun_prop : Measurable fun ω ↦ max (X ω - k) 0).aestronglyMeasurable + · -- the call payoff is `1`-Lipschitz in the strike + simpa only [map_one, NNReal.coe_one, one_mul, Real.dist_eq] using + abs_call_payoff_sub_le (X ω) k₁ k₂ + · -- and, off the atom, differentiable at `K` with derivative `−1_{X > K}` + filter_upwards [hae] with ω hω + rcases hω.lt_or_gt with h | h + · rw [indicator_of_notMem (show ω ∉ {ω | K < X ω} from fun h' ↦ lt_asymm h h'), neg_zero] + refine (hasDerivAt_const K (0 : ℝ)).congr_of_eventuallyEq ?_ + filter_upwards [Ioi_mem_nhds h] with k hk + exact max_eq_right (by linarith [mem_Ioi.1 hk]) + · rw [indicator_of_mem (show ω ∈ {ω | K < X ω} from h), Pi.one_apply] + refine ((hasDerivAt_id' K).const_sub (X ω)).congr_of_eventuallyEq ?_ + filter_upwards [Iio_mem_nhds h] with k hk + exact max_eq_left (by linarith [mem_Iio.1 hk]) + +/-- **The call price is differentiable in the strike exactly off the atoms.** For a measurable, +integrable `X` under a finite measure `μ`, the call price `C(k) = ∫ (X − k)⁺ dμ` is +differentiable at `K` iff `X` has no atom at `K`. Off an atom this is `hasDerivAt_integral_call`. +Conversely the right slopes tend to `−μ {X > K}` (`tendsto_call_spread`) and the left ones to +`−μ {X ≥ K}` (`tendsto_call_spread_left`), so a derivative makes the two equal, and they differ by +`μ {X = K}`. -/ +theorem differentiableAt_integral_call_iff {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsFiniteMeasure μ] {X : Ω → ℝ} (hXm : Measurable X) (hX : Integrable X μ) (K : ℝ) : + DifferentiableAt ℝ (fun k ↦ ∫ ω, max (X ω - k) 0 ∂μ) K ↔ μ {ω | X ω = K} = 0 := by + refine ⟨fun hd ↦ ?_, fun hK ↦ (hasDerivAt_integral_call hXm hX hK).differentiableAt⟩ + have h := hd.hasDerivAt + have hneg : Tendsto (fun t : ℝ ↦ -t) (𝓝[>] 0) (𝓝[<] 0) := by + simpa only [neg_zero] using tendsto_neg_nhdsGT (a := (0 : ℝ)) + -- the right slopes tend to `−μ {X > K}`, the left ones to `−μ {X ≥ K}` + have hR := tendsto_nhds_unique h.tendsto_slope_zero_right + ((tendsto_call_spread hXm hX K).neg.congr' (Eventually.of_forall fun t ↦ by + simp only [smul_eq_mul] + ring)) + have hL := tendsto_nhds_unique (h.tendsto_slope_zero_left.comp hneg) + ((tendsto_call_spread_left hXm hX K).neg.congr' (Eventually.of_forall fun t ↦ by + simp only [Function.comp_apply, smul_eq_mul, ← sub_eq_add_neg] + ring)) + -- `{X ≥ K}` is `{X > K}` and the atom + have hunion : {ω | K ≤ X ω} = {ω | K < X ω} ∪ {ω | X ω = K} := + Set.ext fun ω ↦ (le_iff_lt_or_eq (a := K) (b := X ω)).trans (or_congr_right eq_comm) + have hsum := measureReal_union (μ := μ) (s₁ := {ω | K < X ω}) (s₂ := {ω | X ω = K}) + (Set.disjoint_left.2 fun ω (h₁ : K < X ω) (h₂ : X ω = K) ↦ h₁.ne' h₂) + (hXm (measurableSet_singleton K)) + rw [← hunion] at hsum + exact (measureReal_eq_zero_iff (measure_ne_top μ _)).1 (by linarith) + +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/CarrMadan.lean b/LeanPool/MathFin/Models/ModelFree/CarrMadan.lean new file mode 100644 index 0000000000..f1d46b9454 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/CarrMadan.lean @@ -0,0 +1,194 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Ring.IsFormallyReal +public import Mathlib.Analysis.SpecialFunctions.Log.Deriv +public import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts + +/-! +# Carr–Madan static replication (spanning formula) + +Any twice-differentiable European payoff `f` decomposes, around a reference level +`κ`, as cash + a forward + a static portfolio of out-of-the-money options: + + `f S = f κ + f' κ · (S − κ) + ∫_L^κ f''(K)·(K − S)⁺ dK + ∫_κ^U f''(K)·(S − K)⁺ dK`, + +the **Carr–Madan spanning formula** (`carrMadan_spanning`). The puts (strikes `K < κ`) +and calls (strikes `K > κ`) are weighted by the payoff convexity `f''`. We prove the +honest **compact strike-range** version on `[L, U]` (no improper integrals); the textbook +unbounded form is the `L = 0`, `U → ∞` limit, which needs separate integrability-at-`∞` +hypotheses. + +The proof is one integration by parts — the second-order Taylor remainder +`∫_κ^S (S − t) f''(t) dt = f S − f κ − f' κ (S − κ)` +(`secondOrder_remainder_eq_integral`) — followed by a case split on `S` vs `κ`: in each +case one option leg vanishes (its positive part is `0` over its strike range) and the other +reproduces the remainder. + +## Main results + +* `carrMadan_spanning`: for `f` twice differentiable on `[L, U]` with `f''` continuous there, and + `L ≤ κ ≤ U`, `S ∈ [L, U]`, + `f S = f κ + f' κ · (S − κ) + ∫_L^κ f''(K)·(K − S)⁺ dK + ∫_κ^U f''(K)·(S − K)⁺ dK`. + This is the compact strike-range form; no improper integral appears. +* `carrMadan_log_spanning`: the case `f = log` with `0 < L`, where the option weights are + `−1/K²`. + +## References + +* [Carr and Madan (2001)][CarrMadan2001] +* [Demeterfi et al., *More than you ever wanted to know about volatility + swaps*][DemeterfiDermanKamalZou1999] + +## Tags + +static replication, spanning formula, Carr–Madan formula, variance swap replication, +Taylor remainder, strip of options, JEL G13, MSC 91G20 +-/ + +@[expose] public section + +namespace MathFin + +/-- **Second-order Taylor remainder as an integral against `f''`.** For `f` twice +differentiable on `[[κ, S]]` with continuous `f''`, +`∫_κ^S (S − t) · f''(t) dt = f S − f κ − f' κ · (S − κ)`. One integration by parts +(`u = S − ·`, `v = f'`) plus the fundamental theorem of calculus. + +This is the `n = 1` case of Mathlib's `taylor_integral_remainder` (stated there via +`ContDiffOn` + `iteratedDerivWithin`); we keep this explicit-`HasDerivAt` form because the +spanning proof consumes `f'`, `f''` as named functions and the `iteratedDerivWithin` bridge +would be longer than the IBP proof itself. -/ +theorem secondOrder_remainder_eq_integral {f f' f'' : ℝ → ℝ} {κ S : ℝ} + (hf : ∀ t ∈ Set.uIcc κ S, HasDerivAt f (f' t) t) + (hf' : ∀ t ∈ Set.uIcc κ S, HasDerivAt f' (f'' t) t) + (hf'' : ContinuousOn f'' (Set.uIcc κ S)) : + ∫ t in κ..S, (S - t) * f'' t = f S - f κ - f' κ * (S - κ) := by + have hu : ∀ t ∈ Set.uIcc κ S, HasDerivAt (fun s ↦ S - s) (-1 : ℝ) t := + fun t _ ↦ by simpa using (hasDerivAt_id t).const_sub S + have hf'_cont : ContinuousOn f' (Set.uIcc κ S) := + fun t ht ↦ (hf' t ht).continuousAt.continuousWithinAt + have hf'_int : IntervalIntegrable f' MeasureTheory.volume κ S := hf'_cont.intervalIntegrable + have hf''_int : IntervalIntegrable f'' MeasureTheory.volume κ S := hf''.intervalIntegrable + have hconst_int : IntervalIntegrable (fun _ ↦ (-1 : ℝ)) MeasureTheory.volume κ S := + intervalIntegrable_const + have hibp := intervalIntegral.integral_mul_deriv_eq_deriv_mul hu hf' hconst_int hf''_int + have hftc : ∫ t in κ..S, f' t = f S - f κ := + intervalIntegral.integral_eq_sub_of_hasDerivAt hf hf'_int + calc ∫ t in κ..S, (S - t) * f'' t + = (S - S) * f' S - (S - κ) * f' κ - ∫ t in κ..S, (-1 : ℝ) * f' t := hibp + _ = (S - S) * f' S - (S - κ) * f' κ + ∫ t in κ..S, f' t := by + rw [intervalIntegral.integral_const_mul]; ring + _ = f S - f κ - f' κ * (S - κ) := by rw [hftc]; ring + +/-- **Carr–Madan static replication / spanning formula (compact strike range).** For a +twice-differentiable payoff `f` on `[L, U]` (pointwise derivatives `f'`, `f''`, with `f''` +continuous) and reference level `κ ∈ [L, U]`, every spot `S ∈ [L, U]` satisfies + + `f S = f κ + f' κ · (S − κ) + ∫_L^κ f''(K)·(K − S)⁺ dK + ∫_κ^U f''(K)·(S − K)⁺ dK`, + +i.e. the payoff is cash `f κ`, a forward position `f' κ` in `(S − κ)`, plus a static book of +puts (strikes `K ∈ [L, κ]`) and calls (strikes `K ∈ [κ, U]`) held in density `f''(K) dK`. +This is the honest compact-strike-range Carr–Madan formula; the textbook unbounded form is +the `L = 0`, `U → ∞` limit, needing separate integrability-at-`∞` hypotheses. -/ +theorem carrMadan_spanning {f f' f'' : ℝ → ℝ} {L U κ S : ℝ} + (hLκ : L ≤ κ) (hκU : κ ≤ U) (hS : S ∈ Set.Icc L U) + (hf : ∀ t ∈ Set.Icc L U, HasDerivAt f (f' t) t) + (hf' : ∀ t ∈ Set.Icc L U, HasDerivAt f' (f'' t) t) + (hf'' : ContinuousOn f'' (Set.Icc L U)) : + f S = f κ + f' κ * (S - κ) + + (∫ K in L..κ, f'' K * max (K - S) 0) + + (∫ K in κ..U, f'' K * max (S - K) 0) := by + have hκ : κ ∈ Set.Icc L U := ⟨hLκ, hκU⟩ + have hL : L ∈ Set.Icc L U := ⟨le_rfl, hLκ.trans hκU⟩ + have hU : U ∈ Set.Icc L U := ⟨hLκ.trans hκU, le_rfl⟩ + have hsub : Set.uIcc κ S ⊆ Set.Icc L U := Set.uIcc_subset_Icc hκ hS + have hcore : ∫ t in κ..S, (S - t) * f'' t = f S - f κ - f' κ * (S - κ) := + secondOrder_remainder_eq_integral (fun t ht ↦ hf t (hsub ht)) + (fun t ht ↦ hf' t (hsub ht)) (hf''.mono hsub) + have hcont_put : ContinuousOn (fun K ↦ f'' K * max (K - S) 0) (Set.Icc L U) := + hf''.mul (((continuous_id.sub continuous_const).max continuous_const).continuousOn) + have hcont_call : ContinuousOn (fun K ↦ f'' K * max (S - K) 0) (Set.Icc L U) := + hf''.mul (((continuous_const.sub continuous_id).max continuous_const).continuousOn) + rcases le_total κ S with h | h + · -- `κ ≤ S`: the put leg vanishes; the call leg is the remainder. + have hput0 : (∫ K in L..κ, f'' K * max (K - S) 0) = 0 := by + have h0 : Set.EqOn (fun K ↦ f'' K * max (K - S) 0) (fun _ ↦ (0 : ℝ)) (Set.uIcc L κ) := by + intro K hK + rw [Set.uIcc_of_le hLκ] at hK + simp only [max_eq_right (show K - S ≤ 0 by linarith [hK.2]), mul_zero] + rw [intervalIntegral.integral_congr h0]; simp + have hcall : (∫ K in κ..U, f'' K * max (S - K) 0) = f S - f κ - f' κ * (S - κ) := by + have hsplit : (∫ K in κ..U, f'' K * max (S - K) 0) + = (∫ K in κ..S, f'' K * max (S - K) 0) + (∫ K in S..U, f'' K * max (S - K) 0) := + (intervalIntegral.integral_add_adjacent_intervals + (hcont_call.mono (Set.uIcc_subset_Icc hκ hS)).intervalIntegrable + (hcont_call.mono (Set.uIcc_subset_Icc hS hU)).intervalIntegrable).symm + have hupper : (∫ K in S..U, f'' K * max (S - K) 0) = 0 := by + have h0 : Set.EqOn (fun K ↦ f'' K * max (S - K) 0) (fun _ ↦ (0 : ℝ)) (Set.uIcc S U) := by + intro K hK + rw [Set.uIcc_of_le hS.2] at hK + simp only [max_eq_right (show S - K ≤ 0 by linarith [hK.1]), mul_zero] + rw [intervalIntegral.integral_congr h0]; simp + have hlower : (∫ K in κ..S, f'' K * max (S - K) 0) = ∫ K in κ..S, (S - K) * f'' K := by + refine intervalIntegral.integral_congr fun K hK ↦ ?_ + rw [Set.uIcc_of_le h] at hK + rw [max_eq_left (show (0 : ℝ) ≤ S - K by linarith [hK.2])]; ring + rw [hsplit, hupper, hlower, add_zero, hcore] + rw [hput0, hcall]; ring + · -- `S ≤ κ`: the call leg vanishes; the put leg is the remainder. + have hcall0 : (∫ K in κ..U, f'' K * max (S - K) 0) = 0 := by + have h0 : Set.EqOn (fun K ↦ f'' K * max (S - K) 0) (fun _ ↦ (0 : ℝ)) (Set.uIcc κ U) := by + intro K hK + rw [Set.uIcc_of_le hκU] at hK + simp only [max_eq_right (show S - K ≤ 0 by linarith [hK.1]), mul_zero] + rw [intervalIntegral.integral_congr h0]; simp + have hput : (∫ K in L..κ, f'' K * max (K - S) 0) = f S - f κ - f' κ * (S - κ) := by + have hsplit : (∫ K in L..κ, f'' K * max (K - S) 0) + = (∫ K in L..S, f'' K * max (K - S) 0) + (∫ K in S..κ, f'' K * max (K - S) 0) := + (intervalIntegral.integral_add_adjacent_intervals + (hcont_put.mono (Set.uIcc_subset_Icc hL hS)).intervalIntegrable + (hcont_put.mono (Set.uIcc_subset_Icc hS hκ)).intervalIntegrable).symm + have hlowZero : (∫ K in L..S, f'' K * max (K - S) 0) = 0 := by + have h0 : Set.EqOn (fun K ↦ f'' K * max (K - S) 0) (fun _ ↦ (0 : ℝ)) (Set.uIcc L S) := by + intro K hK + rw [Set.uIcc_of_le hS.1] at hK + simp only [max_eq_right (show K - S ≤ 0 by linarith [hK.2]), mul_zero] + rw [intervalIntegral.integral_congr h0]; simp + have hhigh : (∫ K in S..κ, f'' K * max (K - S) 0) = ∫ K in S..κ, (K - S) * f'' K := by + refine intervalIntegral.integral_congr fun K hK ↦ ?_ + rw [Set.uIcc_of_le h] at hK + rw [max_eq_left (show (0 : ℝ) ≤ K - S by linarith [hK.1])]; ring + rw [hsplit, hlowZero, hhigh, zero_add, ← hcore, + intervalIntegral.integral_symm S κ, ← intervalIntegral.integral_neg] + refine intervalIntegral.integral_congr fun K _ ↦ ?_ + ring + rw [hcall0, hput]; ring + +/-- **Carr–Madan log-contract replication** — the variance-swap building block. On a positive +strike range `0 < L ≤ κ ≤ U`, the log payoff replicates as a forward position `κ⁻¹·(S − κ)` in +the underlying plus a static strip of out-of-the-money options weighted by `1/K²`: + + `log S = log κ + κ⁻¹·(S − κ) + ∫_L^κ −(K²)⁻¹·(K − S)⁺ dK + ∫_κ^U −(K²)⁻¹·(S − K)⁺ dK`. + +The `−1/K²` weight (the log payoff's convexity `f''`) is exactly the density of OTM puts and +calls a variance swap holds. Specialises `carrMadan_spanning` to `f = Real.log`. -/ +theorem carrMadan_log_spanning {L U κ S : ℝ} (hL : 0 < L) + (hLκ : L ≤ κ) (hκU : κ ≤ U) (hS : S ∈ Set.Icc L U) : + Real.log S = Real.log κ + κ⁻¹ * (S - κ) + + (∫ K in L..κ, -(K ^ 2)⁻¹ * max (K - S) 0) + + (∫ K in κ..U, -(K ^ 2)⁻¹ * max (S - K) 0) := by + have hpos : ∀ t ∈ Set.Icc L U, t ≠ 0 := fun t ht ↦ (lt_of_lt_of_le hL ht.1).ne' + exact carrMadan_spanning (f := Real.log) (f' := fun t ↦ t⁻¹) (f'' := fun K ↦ -(K ^ 2)⁻¹) + hLκ hκU hS (fun t ht ↦ Real.hasDerivAt_log (hpos t ht)) + (fun t ht ↦ by simpa using hasDerivAt_inv (hpos t ht)) + (((continuousOn_id.pow 2).inv₀ (fun K hK ↦ pow_ne_zero 2 (hpos K hK))).neg) + +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/MarketCallPrice.lean b/LeanPool/MathFin/Models/ModelFree/MarketCallPrice.lean new file mode 100644 index 0000000000..b269b0b497 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/MarketCallPrice.lean @@ -0,0 +1,118 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.Market +public import LeanPool.MathFin.Models.BlackScholes.StrikeConvexity +public import LeanPool.MathFin.Models.ModelFree.CallPriceFunction + +/-! +# A pricing measure gives a normalised call price function + +Call prices in the strike are the static face of the fundamental theorem. In a market with unit +numéraire and a positive asset, a pricing measure `Q` up to `T` makes the asset a `Q`-martingale, +so its forward `F` is its mean, and the calls at the strikes `k F`, priced in units of `F`, are the +call prices `k ↦ 𝔼[(X − k)⁺]` of the positive mean-one variable `X = S_T / F`. Those are a +normalised call price function (`IsNormalizedCallPrice`): this is the forward direction of Roper's +Theorem 2.1. The converse, a market with a nonnegative asset for every normalised call price +function, is `exists_market_of_isNormalizedCallPrice` (`RoperConverse.lean`). + +## Main results + +* `isNormalizedCallPrice_integral_call`: for a positive integrable `X` of mean one under a + probability measure, `k ↦ 𝔼[(X − k)⁺]` is a normalised call price function. +* `Market.IsPricingMeasure.isNormalizedCallPrice`: the same for the calls of a market with unit + numéraire and a positive asset under a pricing measure, in units of the forward. + +## References + +* [Roper, *Arbitrage free implied volatility surfaces*][Roper2010], Theorem 2.1 +* [Breeden and Litzenberger, *Prices of state-contingent claims implicit in option + prices*][BreedenLitzenberger1978] + +## Tags + +call price in strike, pricing measure, static no-arbitrage, butterfly spread, forward, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +open MeasureTheory Filter Topology Set MathFin.Contracts +open scoped NNReal + +namespace MathFin + +/-- **The call prices of a positive mean-one variable are a normalised call price function.** +Convexity is that of the payoff carried through the integral (`convexOn_integral_call`); the +intrinsic bound is `𝔼[(X − K)⁺] ≥ 𝔼[X − K] = 1 − K`; the upper bound is `(X − K)⁺ ≤ X`; and the +price vanishes at large strikes by dominated convergence. -/ +theorem isNormalizedCallPrice_integral_call {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsProbabilityMeasure μ] {X : Ω → ℝ} (hX : Integrable X μ) (hpos : ∀ ω, 0 < X ω) + (hmean : ∫ ω, X ω ∂μ = 1) : + IsNormalizedCallPrice fun k ↦ ∫ ω, max (X ω - k) 0 ∂μ := by + have hint (k : ℝ) : Integrable (fun ω ↦ max (X ω - k) 0) μ := + (hX.sub (integrable_const k)).pos_part + refine .of_convexOn ((convexOn_integral_call hX).subset (subset_univ _) (convex_Ioi 0)) + (fun K _ ↦ max_le ?_ (integral_nonneg fun ω ↦ le_max_right _ _)) + (fun K hK ↦ ?_) ?_ + · calc 1 - K = ∫ ω, (X ω - K) ∂μ := by rw [integral_sub hX (integrable_const K), hmean]; simp + _ ≤ _ := integral_mono (hX.sub (integrable_const K)) (hint K) fun ω ↦ le_max_left _ _ + · exact hmean ▸ integral_mono (hint K) hX fun ω ↦ + max_le (by linarith [Set.mem_Ioi.1 hK]) (hpos ω).le + · simpa using tendsto_integral_filter_of_dominated_convergence (l := atTop) (f := fun _ ↦ 0) X + (.of_forall fun k ↦ (hint k).1) + (by + filter_upwards [eventually_ge_atTop 0] with k hk + exact .of_forall fun ω ↦ by + rw [Real.norm_of_nonneg (le_max_right _ _)] + exact max_le (by linarith) (hpos ω).le) + hX + (.of_forall fun ω ↦ tendsto_const_nhds.congr' (by + filter_upwards [eventually_ge_atTop (X ω)] with k hk + exact (max_eq_right (by linarith)).symm)) + +namespace Market + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {M : Market Unit Ω} {T : ℝ≥0} {Q : Measure Ω} + +/-- **A pricing measure gives a normalised call price function.** In a market with unit numéraire +and a positive asset, priced at `T` by `Q`, the forward `F` of the asset is its price, and the +calls at the strikes `k F` priced in units of `F` are a normalised call price function: convex, +nonincreasing, between the intrinsic value and one, with limits one at strike `0` and zero at large +strikes. -/ +theorem IsPricingMeasure.isNormalizedCallPrice (hQ : M.IsPricingMeasure T Q) + (hN : ∀ t ω, M.numeraire t ω = 1) (hpos : ∀ ω, 0 < M.asset () T ω) {F : ℝ} + (hF : F = M.price Q (.pay T (.obs () T))) : + IsNormalizedCallPrice fun k ↦ M.price Q (europeanCall (k * F) T) / F := by + have := hQ.isProb + have hint : Integrable (M.asset () T) Q := + ((hQ.martingale ()).integrable T).congr (.of_forall fun ω ↦ by simp [deflated, hN]) + have hF' : F = ∫ ω, M.asset () T ω ∂Q := by + simp [hF, price, Contract.value_pay, Payoff.eval, scenarioAt, deflator, hN] + have hFpos : 0 < F := by + rw [hF'] + refine (integral_pos_iff_support_of_nonneg (fun ω ↦ (hpos ω).le) hint).2 ?_ + have hsupp : Function.support (M.asset () T) = univ := + eq_univ_of_forall fun ω ↦ (hpos ω).ne' + rw [hsupp, measure_univ] + exact one_pos + have key := isNormalizedCallPrice_integral_call (μ := Q) (X := fun ω ↦ M.asset () T ω / F) + (hint.div_const F) (fun ω ↦ div_pos (hpos ω) hFpos) + (by rw [integral_div, ← hF', div_self hFpos.ne']) + refine key.of_eqOn fun k _ ↦ ?_ + simp only [price_europeanCall_of_numeraire_eq_one hN, ← integral_div] + refine integral_congr_ae (.of_forall fun ω ↦ ?_) + change max (M.asset () T ω / F - k) 0 = max (M.asset () T ω - k * F) 0 / F + rw [← max_div_div_right hFpos.le, zero_div] + congr 1 + field_simp + +end Market + +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/PriceBounds.lean b/LeanPool/MathFin/Models/ModelFree/PriceBounds.lean new file mode 100644 index 0000000000..43ff7a8709 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/PriceBounds.lean @@ -0,0 +1,275 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Put +public import LeanPool.MathFin.Models.BlackScholes.PutGreeks +public import Mathlib.Algebra.Order.Star.Real + +/-! +# The no-arbitrage rectangle for European call/put prices + +Under the BS risk-neutral lognormal hypothesis, the call and put prices live +in a rectangle in the plane: + + `max(0, S₀ − K · e^{−rT}) ≤ bsV ≤ S₀`, + `max(0, K · e^{−rT} − S₀) ≤ bsP ≤ K · e^{−rT}`, + +and they are tied by put-call parity: + + `bsV − bsP = S₀ − K · e^{−rT}`. + +This rectangle is the *single* structural fact. The library previously stated +six independent bound theorems, each with its own proof; here we collect them +around three elementary facts: + +* **`bsV_nonneg`**: `0 ≤ bsV` (integrand `(S_T − K)⁺ ≥ 0`). +* **`bsP_nonneg`**: `0 ≤ bsP` (integrand `(K − S_T)⁺ ≥ 0`). +* **`bsP_eq_bsV`**: the parity identity (already proved in `PutGreeks.lean`). + +Plus the trivial Phi-bounds `0 ≤ Φ ≤ 1`. Every other static price-bound +theorem reduces to a one-liner. + +## Map of consequences + +| Theorem | Proof via | +|------------------------------------|----------------------------------------| +| `bsV_le_S` | `Phi ≤ 1` + `Phi ≥ 0` (direct) | +| `bsP_le_K_disc` | `Phi ≤ 1` + `Phi ≥ 0` (direct) | +| `bsV_ge_forward_lower_bound` | parity + `bsP_nonneg` | +| `bsP_ge_intrinsic_no_arb` | parity + `bsV_nonneg` | +| `bsV_strict_gt_immediate_exercise` | forward lb + `exp(-rT) < 1` for `rT>0` | +| `box_spread_identity` | subtract two parities | + +The last is Merton (1973) — the strict bound that proves American = European +for a non-dividend call (early exercise is never optimal). + +## Why this unification is the right one + +Each of the six bounds in the table can be (and was) proved independently +from the BS formula by hand. But the *meaning* of each — bsV ≤ S says "a +call costs less than the stock", bsP ≥ K · e^{−rT} − S says "a put costs at +least the discounted strike minus spot", etc. — sits on the rectangle. Naming +the rectangle makes the meaning explicit and the proofs trivial. + +## Main results + +* `noArbBox`: under `BSCallHyp`, the call and put prices lie in the rectangle + `max(0, S₀ − K·e^{−rT}) ≤ bsV ≤ S₀` and `max(0, K·e^{−rT} − S₀) ≤ bsP ≤ K·e^{−rT}`. +* `bsV_nonneg`, `bsP_nonneg`: the call and put prices are nonnegative under `BSCallHyp`. +* `bsV_le_S`, `bsP_le_K_disc`: for `S, K ≥ 0`, `bsV ≤ S` and `bsP ≤ K·e^{−rτ}`. +* `bsV_ge_forward_lower_bound`, `bsP_ge_intrinsic_no_arb`: `S − K·e^{−rτ} ≤ bsV` and + `K·e^{−rτ} − S ≤ bsP`. +* `box_spread_identity`: `(bsV(K₁) − bsP(K₁)) − (bsV(K₂) − bsP(K₂)) = (K₂ − K₁)·e^{−rτ}`. +* `bsV_strict_gt_immediate_exercise`: for `r > 0`, `S₀ − K < bsV`. + +## References + +* [Cohen (1985)][Cohen1985] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 11.3; Ch 11.2; Ch 12.8 +* [R. C. Merton, *Theory of rational option pricing*][Merton1973] +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], 4.5 + +## Tags + +no-arbitrage bounds, put–call parity, option price bounds, Merton early exercise, box spread, +intrinsic value, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-! ### Bridging the closed-form `bsV`/`bsP` definitions to integral forms -/ + +/-- Bridge from the closed-form `bsV` to the discounted risk-neutral expectation +`∫ e^{−rT} · (S_T − K)⁺ dQ`. Pure normalisation of `bs_call_formula` +(reconciles `Real.exp (-r * T)` with `Real.exp (-(r * T))`). -/ +private lemma bsV_eq_riskNeutralExpectation + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + bsV K r σ S_0 T = + ∫ ω, Real.exp (-(r * T)) * + max (bsTerminal S_0 r σ T (Z ω) - K) 0 ∂Q := by + have h_form := bs_call_formula h + have h_exp : Real.exp (-r * T) = Real.exp (-(r * T)) := by congr 1; ring + rw [h_exp] at h_form + -- Goal: bsV K r σ S_0 T = ∫ ... ∂Q + -- bsV's def matches h_form's RHS exactly after the normalisation above. + change S_0 * Phi (bsd1 S_0 K r σ T) - + K * Real.exp (-(r * T)) * Phi (bsd2 S_0 K r σ T) = _ + exact h_form.symm + +/-- Bridge from the closed-form `bsP` to `∫ e^{−rT} · (K − S_T)⁺ dQ`. -/ +private lemma bsP_eq_riskNeutralExpectation + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + bsP K r σ S_0 T = + ∫ ω, Real.exp (-(r * T)) * + max (K - bsTerminal S_0 r σ T (Z ω)) 0 ∂Q := by + have h_form := bs_put_formula h + have h_exp : Real.exp (-r * T) = Real.exp (-(r * T)) := by congr 1; ring + rw [h_exp] at h_form + change K * Real.exp (-(r * T)) * Phi (-bsd2 S_0 K r σ T) - + S_0 * Phi (-bsd1 S_0 K r σ T) = _ + exact h_form.symm + +/-! ### The three foundational facts (the two non-negativities + Phi ≤ 1) -/ + +/-- **Call price non-negativity**: `0 ≤ bsV`. Integrand `e^{−rT} · (S_T − K)⁺` +is non-negative pointwise (positive discount factor times the non-negative +positive-part). -/ +theorem bsV_nonneg + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + 0 ≤ bsV K r σ S_0 T := by + rw [bsV_eq_riskNeutralExpectation h] + exact integral_nonneg fun _ ↦ + mul_nonneg (Real.exp_pos _).le (le_max_right _ _) + +/-- **Put price non-negativity**: `0 ≤ bsP`. Same argument with `(K − S_T)⁺`. -/ +theorem bsP_nonneg + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + 0 ≤ bsP K r σ S_0 T := by + rw [bsP_eq_riskNeutralExpectation h] + exact integral_nonneg fun _ ↦ + mul_nonneg (Real.exp_pos _).le (le_max_right _ _) + +/-! ### The two formula-direct upper bounds (Phi-bounds path, no parity) + +`Phi_le_one` now lives in `Probability.Gaussian.StandardNormal` (pricing-free). -/ + +/-- **Call upper bound**: `bsV ≤ S` for non-negative spot/strike. By +`Phi ≤ 1`: the `S · Φ(d₁)` term is bounded by `S`, and the `−K · e^{−rτ} · +Φ(d₂)` term is non-positive. -/ +lemma bsV_le_S (K r σ : ℝ) (S τ : ℝ) (hS : 0 ≤ S) (hK : 0 ≤ K) : + bsV K r σ S τ ≤ S := by + unfold bsV + have h_Φd1 : Phi (bsd1 S K r σ τ) ≤ 1 := Phi_le_one _ + have h_Φd2 : 0 ≤ Phi (bsd2 S K r σ τ) := Phi_nonneg _ + have h_exp : 0 ≤ Real.exp (-(r * τ)) := (Real.exp_pos _).le + have h_S_term : S * Phi (bsd1 S K r σ τ) ≤ S := by + have := mul_le_mul_of_nonneg_left h_Φd1 hS + simpa using this + have h_K_term : 0 ≤ K * Real.exp (-(r * τ)) * Phi (bsd2 S K r σ τ) := by + positivity + linarith + +/-- **Put upper bound**: `bsP ≤ K · e^{−rτ}`. Symmetric to `bsV_le_S` via +`Φ(−d₂) ≤ 1`. -/ +lemma bsP_le_K_disc (K r σ : ℝ) (S τ : ℝ) (hS : 0 ≤ S) (hK : 0 ≤ K) : + bsP K r σ S τ ≤ K * Real.exp (-(r * τ)) := by + unfold bsP + have h_Φnegd2 : Phi (-bsd2 S K r σ τ) ≤ 1 := Phi_le_one _ + have h_Φnegd1 : 0 ≤ Phi (-bsd1 S K r σ τ) := Phi_nonneg _ + have h_exp : 0 ≤ Real.exp (-(r * τ)) := (Real.exp_pos _).le + have h_first : + K * Real.exp (-(r * τ)) * Phi (-bsd2 S K r σ τ) ≤ + K * Real.exp (-(r * τ)) := by + have h_factor_nn : 0 ≤ K * Real.exp (-(r * τ)) := mul_nonneg hK h_exp + have := mul_le_mul_of_nonneg_left h_Φnegd2 h_factor_nn + simpa using this + have h_second : 0 ≤ S * Phi (-bsd1 S K r σ τ) := mul_nonneg hS h_Φnegd1 + linarith + +/-! ### The four parity-driven corollaries (one-line proofs each) -/ + +/-- **Forward lower bound**: `S − K · e^{−rτ} ≤ bsV`. By parity +`bsV = bsP + S − K · e^{−rτ}` and `bsP ≥ 0`. -/ +theorem bsV_ge_forward_lower_bound + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + S_0 - K * Real.exp (-(r * T)) ≤ bsV K r σ S_0 T := by + have h_par := bsP_eq_bsV K r σ S_0 T + have h_pos := bsP_nonneg h + linarith + +/-- **Intrinsic-style put lower bound**: `K · e^{−rτ} − S ≤ bsP`. By parity +`bsP = bsV + K · e^{−rτ} − S` and `bsV ≥ 0`. The "dual" of the call's forward +lower bound. -/ +theorem bsP_ge_intrinsic_no_arb + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + K * Real.exp (-(r * T)) - S_0 ≤ bsP K r σ S_0 T := by + have h_par := bsP_eq_bsV K r σ S_0 T + have h_pos := bsV_nonneg h + linarith + +/-- **Box-spread identity**: `(bsV(K₁) − bsP(K₁)) − (bsV(K₂) − bsP(K₂)) = +(K₂ − K₁) · e^{−rτ}`. Two applications of put-call parity, subtracted. -/ +theorem box_spread_identity (K₁ K₂ r σ S τ : ℝ) : + (bsV K₁ r σ S τ - bsP K₁ r σ S τ) - + (bsV K₂ r σ S τ - bsP K₂ r σ S τ) = + (K₂ - K₁) * Real.exp (-(r * τ)) := by + grind [pricing] + +/-! ### Merton 1973: American non-dividend call equals European call -/ + +/-- **Merton 1973 strict dominance**: for `r > 0`, `S₀ − K < bsV`. Combined +with `bsV ≥ 0`, this strictly dominates the immediate-exercise payoff +`max(S₀ − K, 0)`, so early exercise is never optimal. American = European. + +Proof: `bsV ≥ S₀ − K · e^{−rT}` (forward lb) and `K · e^{−rT} < K` (because +`e^{−rT} < 1` for `r > 0` and `T > 0`, multiplied by `K > 0`). -/ +theorem bsV_strict_gt_immediate_exercise + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) (hr : 0 < r) : + S_0 - K < bsV K r σ S_0 T := by + have h_forward := bsV_ge_forward_lower_bound h + have hT := h.T_pos + have hK := h.K_pos + have h_exp_lt_one : Real.exp (-(r * T)) < 1 := by + rw [Real.exp_lt_one_iff]; linarith [mul_pos hr hT] + have h_K_strict : K * Real.exp (-(r * T)) < K := by + have := mul_lt_mul_of_pos_left h_exp_lt_one hK + simpa using this + linarith + +/-! ### Packaging: the no-arbitrage rectangle, in one theorem -/ + +/-- **The no-arbitrage rectangle**: under `BSCallHyp`, the call and put +prices satisfy + + `max(0, S₀ − K · e^{−rT}) ≤ bsV K r σ S₀ T ≤ S₀`, + `max(0, K · e^{−rT} − S₀) ≤ bsP K r σ S₀ T ≤ K · e^{−rT}`. + +Each of the four sides of the call rectangle (and put rectangle) is a named +theorem above; this packages them. -/ +theorem noArbBox + {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q S_0 K r σ T Z) : + max 0 (S_0 - K * Real.exp (-(r * T))) ≤ bsV K r σ S_0 T ∧ + bsV K r σ S_0 T ≤ S_0 ∧ + max 0 (K * Real.exp (-(r * T)) - S_0) ≤ bsP K r σ S_0 T ∧ + bsP K r σ S_0 T ≤ K * Real.exp (-(r * T)) := by + refine ⟨?_, ?_, ?_, ?_⟩ + · exact max_le (bsV_nonneg h) (bsV_ge_forward_lower_bound h) + · exact bsV_le_S K r σ S_0 T h.S_0_pos.le h.K_pos.le + · exact max_le (bsP_nonneg h) (bsP_ge_intrinsic_no_arb h) + · exact bsP_le_K_disc K r σ S_0 T h.S_0_pos.le h.K_pos.le + +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/RoperConverse.lean b/LeanPool/MathFin/Models/ModelFree/RoperConverse.lean new file mode 100644 index 0000000000..d3d451652a --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/RoperConverse.lean @@ -0,0 +1,362 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import Mathlib.Analysis.Convex.Continuous +public import Mathlib.Analysis.Convex.Deriv +public import Mathlib.MeasureTheory.Integral.Layercake +public import LeanPool.MathFin.Models.ModelFree.MarketCallPrice +public import LeanPool.MathFin.Pricing.OneDateMarket + +/-! +# Roper's converse: a market for every normalised call price function + +Every normalised call price function (`IsNormalizedCallPrice`) is the call price function of a +market. The first half builds the law (Breeden–Litzenberger): the right derivative `C'₊` of a +convex `C` is monotone and right-continuous, so `K ↦ 1 + C'₊ K` on `(0, ∞)`, extended by `0`, +is, up to its right limit at `0`, the distribution function of a probability measure `μ` on +`[0, ∞)` with `μ (Ioi K) = -C'₊ K`. The layer-cake formula and the fundamental theorem of +calculus for the right derivative give `∫ (x - K)⁺ dμ = C K`, and monotone convergence as +`K ↓ 0` gives the mean `∫ x dμ = 1`. The second half puts `μ` in the one-date market +(`Market.oneDate`) with unit numéraire and the asset `max ω 0` at time one, priced by `μ` itself. + +The asset is nonnegative, not positive: a call price function may carry an atom at `0` (for +`C K = max (1 - (1 - p) K) 0` with `p ∈ (0, 1)` the law has mass `p` at `0`), and no pricing +measure equivalent to the reference measure gives a strictly positive asset zero mass, so the +version with `0 < M.asset () 1 ω` is false. The forward direction, from a market with a positive +asset to a call price function, is `Market.IsPricingMeasure.isNormalizedCallPrice`. + +## Main results + +* `ConvexOn.continuousWithinAt_Ici_rightDeriv`: the right derivative of a convex function on an + open set is right-continuous. +* `IsNormalizedCallPrice.exists_measure`: a normalised call price function is `K ↦ ∫ (x - K)⁺ dμ` + for a probability measure `μ` on `[0, ∞)` of mean one. +* `exists_market_of_isNormalizedCallPrice`: **Roper's converse.** A market with unit numéraire, + a nonnegative asset of forward one at time one and a pricing measure, under which the claim + paying the asset is worth `1` and the call at every strike `K > 0` is worth `C K`. + +## References + +* [Roper, *Arbitrage free implied volatility surfaces*][Roper2010], Theorem 2.1 +* [Breeden and Litzenberger, *Prices of state-contingent claims implicit in option + prices*][BreedenLitzenberger1978] + +## Tags + +call price in strike, Breeden-Litzenberger, risk-neutral density, right derivative, +Stieltjes measure, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +open Set Filter Topology MeasureTheory + +namespace ConvexOn + +variable {S : Set ℝ} {f : ℝ → ℝ} + +/-- **The right derivative of a convex function on an open set is right-continuous.** Fix `b` +above `f'₊ x`: some slope `slope f x z` is below `b`, and `f'₊ y ≤ slope f y z`, which tends to +`slope f x z` as `y ↓ x`; the other bound is the monotonicity of `f'₊`. -/ +theorem continuousWithinAt_Ici_rightDeriv (hfc : ConvexOn ℝ S f) (hS : IsOpen S) {x : ℝ} + (hx : x ∈ S) : ContinuousWithinAt (fun y ↦ derivWithin f (Ioi y) y) (Ici x) x := by + rw [← continuousWithinAt_Ioi_iff_Ici] + have hxi : x ∈ interior S := hS.interior_eq.ge hx + have hS' : ∀ᶠ y in 𝓝[>] x, y ∈ S := nhdsWithin_le_nhds (hS.mem_nhds hx) + refine tendsto_order.2 ⟨fun a ha ↦ ?_, fun b hb ↦ ?_⟩ + · filter_upwards [self_mem_nhdsWithin, hS'] with y hy hyS + exact ha.trans_le (hfc.monotoneOn_rightDeriv hxi (hS.interior_eq.ge hyS) hy.le) + · obtain ⟨z₀, hz₀S, hz₀⟩ := (hS'.and self_mem_nhdsWithin).exists + replace hb : derivWithin f (Ioi x) x < b := hb + rw [hfc.rightDeriv_eq_sInf_slope_of_mem_interior hxi] at hb + obtain ⟨_, ⟨z, ⟨hzS, hxz⟩, rfl⟩, hzb⟩ := + exists_lt_of_csInf_lt (s := slope f x '' {y | y ∈ S ∧ x < y}) + ⟨_, z₀, ⟨hz₀S, hz₀⟩, rfl⟩ hb + have hlim : Tendsto (fun y ↦ slope f y z) (𝓝 x) (𝓝 (slope f x z)) := by + simp only [slope_def_field] + exact ((continuousAt_const.sub ((hfc.continuousOn hS).continuousAt (hS.mem_nhds hx))).div + (continuousAt_const.sub continuousAt_id) (sub_ne_zero.2 hxz.ne')).tendsto + filter_upwards [hlim.mono_left nhdsWithin_le_nhds |>.eventually (gt_mem_nhds hzb), hS', + nhdsWithin_le_nhds (eventually_lt_nhds hxz)] with y hy hyS hyz + exact (hfc.rightDeriv_le_slope_of_mem_interior (hS.interior_eq.ge hyS) hzS hyz).trans_lt hy + +end ConvexOn + +namespace MathFin.IsNormalizedCallPrice + +variable {C : ℝ → ℝ} (hC : IsNormalizedCallPrice C) +include hC + +/-- A secant slope of a normalised call price function is at most the right derivative at its +right end. -/ +theorem slope_le_rightDeriv {a x : ℝ} (ha : 0 < a) (hax : a < x) : + slope C a x ≤ derivWithin C (Ioi x) x := + (hC.convexOn.slope_le_leftDeriv_of_mem_interior ha (by simpa using ha.trans hax) hax).trans + (hC.convexOn.leftDeriv_le_rightDeriv_of_mem_interior (by simpa using ha.trans hax)) + +/-- A normalised call price function has nonpositive right derivative: it is nonincreasing. -/ +theorem rightDeriv_nonpos {x : ℝ} (hx : 0 < x) : derivWithin C (Ioi x) x ≤ 0 := by + have hy : x + 1 ∈ Ioi (0 : ℝ) := by simp; linarith + refine (hC.convexOn.rightDeriv_le_slope_of_mem_interior (by simpa using hx) hy + (lt_add_one x)).trans ?_ + rw [slope_def_field] + exact div_nonpos_of_nonpos_of_nonneg (sub_nonpos.2 (hC.antitoneOn hx hy (by simp))) + (by simp) + +/-- The right derivative of a normalised call price function is at least `-1`: the secant from +strike `0⁺`, where the price is `1`, to `x` has slope `(C x - 1) / x ≥ -1`. -/ +theorem neg_one_le_rightDeriv {x : ℝ} (hx : 0 < x) : -1 ≤ derivWithin C (Ioi x) x := by + have hlim : Tendsto (fun a ↦ slope C a x) (𝓝[>] 0) (𝓝 ((C x - 1) / (x - 0))) := by + simp only [slope_def_field] + exact (tendsto_const_nhds.sub hC.tendsto_one).div + ((tendsto_const_nhds.sub tendsto_id).mono_left nhdsWithin_le_nhds) (by simpa using hx.ne') + refine le_trans ?_ (le_of_tendsto hlim ?_) + · rw [sub_zero, le_div_iff₀ hx] + linarith [(le_max_left _ _).trans (hC.intrinsic_le x hx)] + · filter_upwards [Ioo_mem_nhdsGT hx] with a ha using hC.slope_le_rightDeriv ha.1 ha.2 + +/-- The right derivative of a normalised call price function tends to `0` at infinity: it lies +between `0` and the secant slope from strike `1`, which is at least `-C 1 / (x - 1)`. -/ +theorem tendsto_rightDeriv_atTop : Tendsto (fun x ↦ derivWithin C (Ioi x) x) atTop (𝓝 0) := by + have hl : Tendsto (fun x : ℝ ↦ -C 1 / (x - 1)) atTop (𝓝 0) := by + simpa [sub_eq_add_neg] using (tendsto_const_nhds (x := -C 1)).div_atTop + (tendsto_atTop_add_const_right atTop (-1) tendsto_id) + refine tendsto_of_tendsto_of_tendsto_of_le_of_le' hl tendsto_const_nhds ?_ ?_ + · filter_upwards [eventually_gt_atTop 1] with x hx + refine le_trans ?_ (hC.slope_le_rightDeriv one_pos hx) + rw [slope_def_field] + exact div_le_div_of_nonneg_right + (by linarith [(le_max_right _ _).trans (hC.intrinsic_le x (by simp; linarith))]) + (by linarith) + · filter_upwards [eventually_gt_atTop 0] with x hx using hC.rightDeriv_nonpos hx + +/-- The right derivative of a normalised call price function is monotone on `(0, ∞)`. -/ +theorem monotoneOn_rightDeriv : MonotoneOn (fun x ↦ derivWithin C (Ioi x) x) (Ioi 0) := by + simpa using hC.convexOn.monotoneOn_rightDeriv + +/-- The fundamental theorem of calculus for the right derivative of a normalised call price +function. -/ +theorem intervalIntegral_rightDeriv {K b : ℝ} (hK : 0 < K) (hKb : K ≤ b) : + ∫ y in K..b, derivWithin C (Ioi y) y = C b - C K := by + refine intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le hKb + ((hC.convexOn.continuousOn isOpen_Ioi).mono fun y hy ↦ hK.trans_le hy.1) + (fun x hx ↦ hC.convexOn.hasDerivWithinAt_rightDeriv_of_mem_interior + (by simpa using hK.trans hx.1)) ?_ + refine MonotoneOn.intervalIntegrable ?_ + rw [uIcc_of_le hKb] + exact hC.monotoneOn_rightDeriv.mono fun y hy ↦ hK.trans_le hy.1 + +/-- **The tail integral of the right derivative.** `-C'₊` is integrable on `(K, ∞)` with integral +`C K`, stated on `(0, ∞)` after the shift `t ↦ K + t`: the integral up to `b` is +`C K - C (K + b)`, and `C` tends to `0`. -/ +theorem integral_neg_rightDeriv {K : ℝ} (hK : 0 < K) : + IntegrableOn (fun t ↦ -derivWithin C (Ioi (K + t)) (K + t)) (Ioi 0) ∧ + ∫ t in Ioi 0, -derivWithin C (Ioi (K + t)) (K + t) = C K := by + set g : ℝ → ℝ := fun t ↦ -derivWithin C (Ioi (K + t)) (K + t) with hg + have hg0 {t : ℝ} (ht : 0 ≤ t) : 0 ≤ g t := neg_nonneg.2 (hC.rightDeriv_nonpos (by linarith)) + have hgint {b : ℝ} (hb : 0 ≤ b) : IntervalIntegrable g volume 0 b := by + refine AntitoneOn.intervalIntegrable ?_ + rw [uIcc_of_le hb] + intro s hs t ht hst + exact neg_le_neg (hC.monotoneOn_rightDeriv (by simp only [mem_Ioi]; linarith [hs.1]) + (by simp only [mem_Ioi]; linarith [ht.1]) (by linarith)) + have hFTC {b : ℝ} (hb : 0 ≤ b) : ∫ t in (0 : ℝ)..b, g t = C K - C (K + b) := by + have := intervalIntegral.integral_comp_add_left + (fun y ↦ derivWithin C (Ioi y) y) (a := 0) (b := b) K + simp only [hg, intervalIntegral.integral_neg, this, add_zero] + rw [hC.intervalIntegral_rightDeriv hK (by linarith)] + ring + have hint : IntegrableOn g (Ioi 0) := by + refine integrableOn_Ioi_of_intervalIntegral_norm_bounded (C K) 0 + (fun b ↦ ?_) (l := atTop) (b := id) tendsto_id ?_ + · change IntegrableOn g (Ioc 0 b) + by_cases hb : 0 ≤ b + · exact (intervalIntegrable_iff_integrableOn_Ioc_of_le hb).1 (hgint hb) + · rw [Ioc_eq_empty (not_lt.2 (not_le.1 hb).le)] + exact integrableOn_empty + · filter_upwards [eventually_ge_atTop 0] with i hi + change ∫ t in (0 : ℝ)..i, ‖g t‖ ≤ C K + have : ∫ t in (0 : ℝ)..i, ‖g t‖ = ∫ t in (0 : ℝ)..i, g t := + intervalIntegral.integral_congr fun t ht ↦ by + rw [uIcc_of_le hi] at ht + exact Real.norm_of_nonneg (hg0 ht.1) + rw [this, hFTC hi] + have := (le_max_right _ _).trans (hC.intrinsic_le (K + i) (by simp only [mem_Ioi]; linarith)) + linarith + refine ⟨hint, tendsto_nhds_unique + (intervalIntegral_tendsto_integral_Ioi 0 hint (tendsto_id : Tendsto id atTop atTop)) ?_⟩ + have h := tendsto_const_nhds (x := C K) |>.sub + (hC.tendsto_zero.comp (tendsto_atTop_add_const_left atTop K tendsto_id)) + rw [sub_zero] at h + refine h.congr' ?_ + filter_upwards [eventually_ge_atTop 0] with i hi + exact (hFTC hi).symm + +/-- **The Breeden–Litzenberger measure, by its tails.** A probability measure on `[0, ∞)` whose +upper tail at `y > 0` is `-C'₊ y`: the Stieltjes measure of the right limit of the monotone +function `K ↦ 1 + C'₊ K` on `(0, ∞)`, `0` elsewhere. -/ +theorem exists_measure_tail : + ∃ μ : Measure ℝ, IsProbabilityMeasure μ ∧ μ (Iio 0) = 0 ∧ + ∀ y > 0, μ (Ioi y) = ENNReal.ofReal (-derivWithin C (Ioi y) y) := by + set f : ℝ → ℝ := fun K ↦ if 0 < K then 1 + derivWithin C (Ioi K) K else 0 with hf + have hf0 (K : ℝ) : 0 ≤ f K := by + by_cases hK : 0 < K + · simp only [hf, hK, ↓reduceIte]; linarith [hC.neg_one_le_rightDeriv hK] + · simp [hf, hK] + have hmono : Monotone f := by + intro a b hab + by_cases ha : 0 < a + · have hb : 0 < b := ha.trans_le hab + simp only [hf, ha, hb, ↓reduceIte] + linarith [hC.monotoneOn_rightDeriv ha hb hab] + · rw [show f a = 0 by simp [hf, ha]] + exact hf0 b + set G := hmono.stieltjesFunction with hG + have hGf (x : ℝ) : f x ≤ G x := hmono.le_rightLim le_rfl + have hGpos {x : ℝ} (hx : 0 < x) : G x = 1 + derivWithin C (Ioi x) x := by + have hcont : ContinuousWithinAt f (Ioi x) x := by + refine (continuousWithinAt_const (b := (1 : ℝ)) |>.add + ((hC.convexOn.continuousWithinAt_Ici_rightDeriv isOpen_Ioi hx).mono + Ioi_subset_Ici_self)).congr_of_eventuallyEq ?_ (by simp [hf, hx]) + filter_upwards [eventually_gt_nhds hx |>.filter_mono nhdsWithin_le_nhds] with y hy + simp [hf, hy] + exact (hmono.continuousWithinAt_Ioi_iff_rightLim_eq.1 hcont).trans (by simp [hf, hx]) + have hGneg {x : ℝ} (hx : x < 0) : G x = 0 := by + refine rightLim_eq_of_tendsto ?_ + refine tendsto_const_nhds.congr' ?_ + filter_upwards [eventually_lt_nhds hx |>.filter_mono nhdsWithin_le_nhds] with y hy + simp [hf, not_lt.2 hy.le] + have hbot : Tendsto G atBot (𝓝 0) := + tendsto_const_nhds.congr' (by filter_upwards [eventually_lt_atBot 0] with x hx using + (hGneg hx).symm) + have htop : Tendsto G atTop (𝓝 1) := by + have := (tendsto_const_nhds (x := (1 : ℝ))).add hC.tendsto_rightDeriv_atTop + rw [add_zero] at this + exact this.congr' (by filter_upwards [eventually_gt_atTop 0] with x hx using + (hGpos hx).symm) + have : IsProbabilityMeasure G.measure := G.isProbabilityMeasure hbot htop + refine ⟨G.measure, this, ?_, fun y hy ↦ ?_⟩ + · have hleft : Function.leftLim G 0 = 0 := + leftLim_eq_of_tendsto (tendsto_const_nhds.congr' + (by filter_upwards [self_mem_nhdsWithin] with x (hx : x < 0) using (hGneg hx).symm)) + rw [G.measure_Iio hbot, hleft] + simp + · rw [G.measure_Ioi htop, hGpos hy] + congr 1 + ring + +/-- **Layer cake for the call.** A measure with upper tail `-C'₊` prices the call at `K > 0` at +`C K`: `μ {t < (x - K)⁺} = μ (Ioi (K + t)) = -C'₊ (K + t)`, integrated over `t > 0`. -/ +theorem lintegral_call_of_tail {μ : Measure ℝ} + (htail : ∀ y > 0, μ (Ioi y) = ENNReal.ofReal (-derivWithin C (Ioi y) y)) {K : ℝ} (hK : 0 < K) : + ∫⁻ x, ENNReal.ofReal (max (x - K) 0) ∂μ = ENNReal.ofReal (C K) := by + rw [lintegral_eq_lintegral_meas_lt μ (f := fun x : ℝ ↦ max (x - K) 0) + (ae_of_all _ fun x ↦ le_max_right _ _) + (by fun_prop : Measurable fun x : ℝ ↦ max (x - K) 0).aemeasurable] + have hset (t : ℝ) (ht : t ∈ Ioi (0 : ℝ)) : μ {a | t < max (a - K) 0} + = ENNReal.ofReal (-derivWithin C (Ioi (K + t)) (K + t)) := by + have ht' : 0 < t := ht + have : {a : ℝ | t < max (a - K) 0} = Ioi (K + t) := by + ext a + simp only [mem_ofPred_eq, mem_Ioi, lt_max_iff] + constructor + · rintro (h | h) <;> linarith + · intro h + exact .inl (by linarith) + rw [this, htail _ (by linarith)] + rw [setLIntegral_congr_fun measurableSet_Ioi hset] + obtain ⟨hint, hval⟩ := hC.integral_neg_rightDeriv hK + have hnn : 0 ≤ᵐ[volume.restrict (Ioi (0 : ℝ))] + fun t ↦ -derivWithin C (Ioi (K + t)) (K + t) := + (ae_restrict_iff' measurableSet_Ioi).2 (ae_of_all _ fun t ht ↦ + neg_nonneg.2 (hC.rightDeriv_nonpos (by have : 0 < t := ht; linarith))) + rw [← ofReal_integral_eq_lintegral_ofReal hint hnn, hval] + +/-- **Every normalised call price function is the call price function of a law.** There is a +probability measure `μ` on `[0, ∞)` with finite mean one such that `C K = ∫ (x - K)⁺ dμ` for +every `K > 0`. The mean is the limit of the calls at `K ↓ 0` (monotone convergence), and the law +need not be supported on `(0, ∞)`: it has an atom at `0` of mass `1 + C'₊ (0⁺)`. -/ +theorem exists_measure : + ∃ μ : Measure ℝ, IsProbabilityMeasure μ ∧ μ (Iio 0) = 0 ∧ Integrable id μ ∧ + ∫ x, x ∂μ = 1 ∧ ∀ K > 0, ∫ x, max (x - K) 0 ∂μ = C K := by + obtain ⟨μ, hprob, hneg, htail⟩ := hC.exists_measure_tail + have hae : 0 ≤ᵐ[μ] fun x : ℝ ↦ x := + (measure_eq_zero_iff_ae_notMem.1 hneg).mono fun x hx ↦ not_lt.1 hx + have hCnn {K : ℝ} (hK : 0 < K) : 0 ≤ C K := (le_max_right _ _).trans (hC.intrinsic_le K hK) + have hmean : ∫⁻ x, ENNReal.ofReal x ∂μ = 1 := by + have hlim : Tendsto (fun n : ℕ ↦ ∫⁻ x, ENNReal.ofReal (max (x - 1 / (n + 1)) 0) ∂μ) atTop + (𝓝 (∫⁻ x, ENNReal.ofReal x ∂μ)) := by + refine lintegral_tendsto_of_tendsto_of_monotone + (fun n ↦ (by fun_prop : Measurable fun x : ℝ ↦ + ENNReal.ofReal (max (x - 1 / (n + 1)) 0)).aemeasurable) ?_ ?_ + · refine ae_of_all _ fun x n m hnm ↦ ENNReal.ofReal_le_ofReal (max_le_max + (sub_le_sub_left (one_div_le_one_div_of_le (by positivity) ?_) x) le_rfl) + exact_mod_cast Nat.add_le_add_right hnm 1 + · filter_upwards [hae] with x hx + have := ENNReal.tendsto_ofReal ((tendsto_const_nhds (x := x)).sub + tendsto_one_div_add_atTop_nhds_zero_nat |>.max (tendsto_const_nhds (x := (0 : ℝ)))) + simpa [max_eq_left (show 0 ≤ x from hx)] using this + have hlim' : Tendsto (fun n : ℕ ↦ ∫⁻ x, ENNReal.ofReal (max (x - 1 / (n + 1)) 0) ∂μ) atTop + (𝓝 (ENNReal.ofReal 1)) := by + refine (ENNReal.tendsto_ofReal (hC.tendsto_one.comp (tendsto_nhdsWithin_iff.2 + ⟨tendsto_one_div_add_atTop_nhds_zero_nat, .of_forall fun n ↦ ?_⟩))).congr fun n ↦ ?_ + · exact (by positivity : (0 : ℝ) < 1 / (n + 1)) + · exact (hC.lintegral_call_of_tail htail (by positivity)).symm + rw [tendsto_nhds_unique hlim hlim', ENNReal.ofReal_one] + refine ⟨μ, hprob, hneg, ⟨aestronglyMeasurable_id, + (hasFiniteIntegral_iff_ofReal (f := fun x : ℝ ↦ x) hae).2 + (by rw [hmean]; exact ENNReal.one_lt_top)⟩, ?_, fun K hK ↦ ?_⟩ + · rw [integral_eq_lintegral_of_nonneg_ae hae aestronglyMeasurable_id, hmean] + simp + · rw [integral_eq_lintegral_of_nonneg_ae (f := fun x : ℝ ↦ max (x - K) 0) + (ae_of_all _ fun x ↦ le_max_right _ _) + (by fun_prop : Measurable fun x : ℝ ↦ max (x - K) 0).aestronglyMeasurable, + hC.lintegral_call_of_tail htail hK, ENNReal.toReal_ofReal (hCnn hK)] + +end MathFin.IsNormalizedCallPrice + +namespace MathFin + +open MathFin.Contracts +open scoped NNReal + +/-- **Roper's converse.** Every normalised call price function is the call price function of a +market with unit numéraire, a nonnegative asset of forward one at time one and a pricing measure: +the claim paying the asset is worth `1` and the call at every strike `k > 0` is worth `C k`. The +asset is `max ω 0` on `ℝ`, and the pricing measure is the law of +`IsNormalizedCallPrice.exists_measure`, which is also the reference measure. The asset can vanish: +the version with a strictly positive asset is false for a call price function with an atom +at `0`. -/ +theorem exists_market_of_isNormalizedCallPrice {C : ℝ → ℝ} (hC : IsNormalizedCallPrice C) : + ∃ (M : Market Unit ℝ) (Q : Measure ℝ), (∀ t ω, M.numeraire t ω = 1) ∧ + (∀ ω, 0 ≤ M.asset () 1 ω) ∧ M.IsPricingMeasure 1 Q ∧ + M.price Q (.pay 1 (.obs () 1)) = 1 ∧ ∀ k > 0, M.price Q (europeanCall k 1) = C k := by + obtain ⟨μ, hprob, hneg, hint, hmean, hcall⟩ := hC.exists_measure + have hX : Measurable fun ω : ℝ ↦ max ω 0 := by fun_prop + have hae : ∀ᵐ ω ∂μ, max ω 0 = ω := + (measure_eq_zero_iff_ae_notMem.1 hneg).mono fun x hx ↦ max_eq_left (not_lt.1 hx) + have hXint : Integrable (fun ω : ℝ ↦ max ω 0) μ := hint.pos_part + have hXmean : ∫ ω, max ω 0 ∂μ = 1 := by + rw [integral_congr_ae hae, hmean] + set M := Market.oneDate μ hX 1 0 1 with hM + have hnum : ∀ t ω, M.numeraire t ω = 1 := fun t ω ↦ by simp [hM, Market.oneDate] + refine ⟨M, μ, hnum, fun ω ↦ ?_, ?_, ?_, fun k hk ↦ ?_⟩ + · rw [hM, Market.asset_oneDate_self] + exact le_max_right _ _ + · exact Market.isPricingMeasure_oneDate Measure.AbsolutelyContinuous.rfl + Measure.AbsolutelyContinuous.rfl hXint (by simpa using hXmean) + · simpa [hM, Market.price_pay_obs_oneDate] using hXmean + · rw [hM, Market.price_europeanCall_oneDate, ← hcall k hk] + simp only [neg_zero, zero_mul, Real.exp_zero, one_mul] + refine integral_congr_ae (.of_forall fun ω ↦ ?_) + rcases le_total ω 0 with h | h + · simp [max_eq_right h, hk.le, h.trans hk.le] + · simp [max_eq_left h] + +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/Admissibility.lean b/LeanPool/MathFin/Models/ModelFree/SVI/Admissibility.lean new file mode 100644 index 0000000000..a94ed79d61 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/Admissibility.lean @@ -0,0 +1,128 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.Reduction + +/-! # Positive variance as a polynomial gate + +Part of the SVI polynomial-sign certificate (#174). + +`varianceGate`, a condition on signs of polynomials in the parameters, is equivalent to the SVI +variance being positive at every log-strike (`varianceGate_iff`), for `σ > 0`, `b ≥ 0`, +`ρ² ≤ 1`. The cases `b = 0` and `ρ = ±1` are included. + +## Main definitions + +* `varianceGate`: the polynomial positive-variance gate, `b = 0 ∧ 0 < a` or + `0 < b ∧ (0 ≤ a ∨ a² < b²σ²(1 − ρ²))`. + +## Main results + +* `quadratic_pos_iff`: for `α, γ ≥ 0` with `α + γ > 0`, `αt² + 2at + γ > 0` for all `t > 0` iff + `0 ≤ a` or `a² < αγ`. +* `variance_pos_iff_A_pos`: for `σ > 0`, the SVI variance is positive at every log-strike iff `A` + is positive at every `t > 0`. +* `varianceGate_iff`: for `σ > 0`, `b ≥ 0` and `ρ² ≤ 1`, `varianceGate` holds iff the variance is + positive at every log-strike. + +## Tags + +positive variance, raw SVI, polynomial sign gate, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI + +/-- Positivity of a quadratic on the open positive half-line. The strict +sum condition permits either endpoint coefficient to vanish. -/ +theorem quadratic_pos_iff (alpha gamma a : ℝ) (ha : 0 ≤ alpha) (hg : 0 ≤ gamma) + (hs : 0 < alpha + gamma) : + (∀ t : ℝ, 0 < t → 0 < alpha*t^2 + 2*a*t + gamma) ↔ + 0 ≤ a ∨ a^2 < alpha*gamma := by + constructor + · intro h + by_cases hapos : 0 ≤ a + · exact Or.inl hapos + have haneg : a < 0 := lt_of_not_ge hapos + have halpha : 0 < alpha := by + by_contra hn + have he : alpha = 0 := le_antisymm (le_of_not_gt hn) ha + subst alpha + have ht : 0 < (gamma + 1) / (-2*a) := div_pos (by linarith) (by nlinarith) + have hh := h _ ht + have hc : 2*a*((gamma+1)/(-2*a)) = -(gamma+1) := by + field_simp [ne_of_lt haneg] + rw [zero_mul, zero_add, hc] at hh + linarith + have ht : 0 < -a/alpha := div_pos (neg_pos.mpr haneg) halpha + have hh := h _ ht + have hm := mul_pos halpha hh + have he : alpha*(alpha*(-a/alpha)^2 + 2*a*(-a/alpha) + gamma) = + alpha*gamma-a^2 := by + field_simp + ring + rw [he] at hm + exact Or.inr (by linarith) + · rintro (hapos | hdisc) t ht + · have hsum : 0 < alpha*t^2 + gamma := by + by_cases hzero : alpha = 0 + · simp only [hzero, zero_mul, zero_add] + linarith + · have : 0 < alpha := lt_of_le_of_ne ha (Ne.symm hzero) + positivity + have : 0 ≤ 2*a*t := by positivity + linarith + · have halpha : 0 < alpha := by + by_contra hn + have hz : alpha = 0 := le_antisymm (le_of_not_gt hn) ha + rw [hz, zero_mul] at hdisc + nlinarith [sq_nonneg a] + by_contra hn + have hm := mul_nonpos_of_nonneg_of_nonpos ha (le_of_not_gt hn) + nlinarith [sq_nonneg (alpha*t+a)] + +/-- The entirely polynomial positive-variance gate from condition (A). -/ +def varianceGate (p : Params) : Prop := + (p.b = 0 ∧ 0 < p.a) ∨ + (0 < p.b ∧ (0 ≤ p.a ∨ p.a^2 < p.b^2*p.sigma^2*(1-p.rho^2))) + +theorem variance_pos_iff_A_pos (p : Params) (hs : 0 < p.sigma) : + (∀ k : ℝ, 0 < variance p k) ↔ (∀ t : ℝ, 0 < t → 0 < A p t) := by + constructor + · intro h t ht + have hh := h (strike p t) + rw [variance_at_strike p hs t ht] at hh + exact (div_pos_iff.mp hh).resolve_right (by intro hn; linarith [hn.2]) |>.1 + · intro h k + obtain ⟨t, ht, rfl⟩ := strike_surjective p hs k + rw [variance_at_strike p hs t ht] + exact div_pos (h t ht) (by positivity) + +/-- Exact admissibility, including b=0 and rho=±1 with a=0. -/ +theorem varianceGate_iff (p : Params) (hs : 0 < p.sigma) (hb : 0 ≤ p.b) + (hr : 0 ≤ 1 - p.rho ^ 2) : + varianceGate p ↔ ∀ k : ℝ, 0 < variance p k := by + by_cases hb0 : p.b = 0 + · simp [varianceGate, variance, hb0] + have hbpos : 0 < p.b := lt_of_le_of_ne hb (Ne.symm hb0) + have hrp : 0 ≤ 1+p.rho := by nlinarith [sq_nonneg (p.rho+1)] + have hrm : 0 ≤ 1-p.rho := by nlinarith [sq_nonneg (p.rho-1)] + rw [variance_pos_iff_A_pos p hs] + have hq := quadratic_pos_iff (p.b*p.sigma*(1+p.rho)) + (p.b*p.sigma*(1-p.rho)) p.a (by positivity) (by positivity) + (by nlinarith [mul_pos hbpos hs]) + have he : p.b*p.sigma*(1+p.rho)*(p.b*p.sigma*(1-p.rho)) = + p.b^2*p.sigma^2*(1-p.rho^2) := by ring + rw [he] at hq + simpa [varianceGate, hb0, hbpos, A] using hq.symm + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/Assembly.lean b/LeanPool/MathFin/Models/ModelFree/SVI/Assembly.lean new file mode 100644 index 0000000000..69e6e29ae8 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/Assembly.lean @@ -0,0 +1,129 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.Polynomial +public import LeanPool.MathFin.Models.ModelFree.SVI.CriticalPoints +public import LeanPool.MathFin.Models.ModelFree.SVI.Derivatives + +/-! # Durrleman's condition as a finite critical-point count + +Part of the SVI polynomial-sign certificate (#174). + +For `σ > 0`, positive variance and a nonconstant numerator polynomial (of degree at most ten), +`g(k) ≥ 0` for every `k` is equivalent to a positive leading coefficient, a nonnegative value at +`0`, and the absence of positive critical points at which the polynomial is negative +(`svi_finite_critical_criterion`). `four_query_count`: on any finite set, a signed combination of +four Tarski queries equals four times the number of points `c > 0` with `P c < 0`. + +## Main definitions + +* `tarskiQuery`: the Tarski query of `q` on a finite set of points, the sum of the signs of its + values. +* `criticalRoots`: the distinct critical points of a polynomial, `P.derivative.roots.toFinset`. +* `badCriticalCount`: the number of distinct critical points `c > 0` of `P` at which `P` is + negative. + +## Main results + +* `durrleman_eq_derivatives`: for `σ > 0`, `durrleman p k` is the expression built from the first + and second derivatives of the variance. +* `svi_critical_value_criterion`: for `σ > 0`, positive variance and a nonconstant numerator + polynomial, `durrleman p k ≥ 0` for all `k` iff the leading coefficient is positive, the value at + `0` is nonnegative and no positive critical point has a negative value. +* `four_query_count`: on any finite set, a signed combination of four Tarski queries equals + `4` times the number of points `c > 0` with `P c < 0`. +* `badCriticalCount_eq_zero_iff`: for `0 < deg P`, `badCriticalCount P = 0` iff no positive critical + point of `P` has a negative value. +* `svi_finite_critical_criterion`: the criterion of `svi_critical_value_criterion` with the last + condition replaced by `badCriticalCount (polynomial p) = 0`. + +## Tags + +Durrleman condition, critical points, Tarski query, SVI butterfly arbitrage, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI + +/-- Checked analytic/algebraic reduction through the critical-value criterion. +The remaining quantifier elimination is deliberately not assumed here. -/ +theorem svi_critical_value_criterion (p : Params) (hs : 0 < p.sigma) + (hw : ∀ k : ℝ, 0 < variance p k) (hd : 0 < (polynomial p).degree) : + (∀ k : ℝ, 0 ≤ durrleman p k) ↔ + 0 < (polynomial p).leadingCoeff ∧ 0 ≤ (polynomial p).eval 0 ∧ + ¬ ∃ c : ℝ, 0 < c ∧ (polynomial p).derivative.eval c = 0 ∧ + (polynomial p).eval c < 0 := by + rw [durrleman_nonneg_iff p hs hw] + simp_rw [← eval_polynomial] + exact polynomial_nonneg_criterion (polynomial p) hd + +/-- The expression is built from the actual first and second derivatives. -/ +theorem durrleman_eq_derivatives (p : Params) (hs : 0 < p.sigma) (k : ℝ) : + durrleman p k = + (1 - k * deriv (variance p) k / (2 * variance p k))^2 - + (deriv (variance p) k)^2 / 4 * (1 / variance p k + 1 / 4) + + deriv (deriv (variance p)) k / 2 := by + rw [deriv_variance p hs, deriv_slope p hs] + rfl + +open scoped BigOperators + +/-- The Tarski query of `q` on a finite set of points: the sum of the signs of its values. -/ +noncomputable def tarskiQuery (roots : Finset ℝ) (q : ℝ → ℝ) : ℤ := + ∑ c ∈ roots, sign (q c) + +/-- The four-query formula on any finite set, hence also on distinct critical +points. This theorem does not assume a trace/signature identity. -/ +theorem four_query_count (roots : Finset ℝ) (P : ℝ → ℝ) : + tarskiQuery roots (fun c ↦ c^2 * (P c)^2) + + tarskiQuery roots (fun c ↦ c * (P c)^2) - + tarskiQuery roots (fun c ↦ c^2 * P c) - + tarskiQuery roots (fun c ↦ c * P c) = + 4 * ((roots.filter (fun c ↦ 0 < c ∧ P c < 0)).card : ℤ) := by + classical + unfold tarskiQuery + rw [← Finset.sum_add_distrib, ← Finset.sum_sub_distrib, ← Finset.sum_sub_distrib] + simp_rw [four_sign_selector] + simp [← Finset.sum_filter, mul_comm] + +/-- Distinct critical points, obtained by removing root multiplicities. -/ +noncomputable def criticalRoots (P : Polynomial ℝ) : Finset ℝ := P.derivative.roots.toFinset + +/-- The number of distinct critical points `c > 0` of `P` at which `P` is negative. -/ +noncomputable def badCriticalCount (P : Polynomial ℝ) : ℕ := + ((criticalRoots P).filter (fun c ↦ 0 < c ∧ P.eval c < 0)).card + +theorem badCriticalCount_eq_zero_iff (P : Polynomial ℝ) (hd : 0 < P.degree) : + badCriticalCount P = 0 ↔ + ¬ ∃ c : ℝ, 0 < c ∧ P.derivative.eval c = 0 ∧ P.eval c < 0 := by + classical + have hf : P.derivative ≠ 0 := Polynomial.derivative_ne_zero.mpr + (ne_of_gt (Polynomial.natDegree_pos_iff_degree_pos.mpr hd)) + simp only [badCriticalCount, Finset.card_eq_zero, Finset.filter_eq_empty_iff, + criticalRoots, Multiset.mem_toFinset, Polynomial.mem_roots hf, Polynomial.IsRoot] + constructor + · intro h ⟨c, hc, hf, hn⟩ + exact h hf ⟨hc, hn⟩ + · intro h c hf ⟨hc, hn⟩ + exact h ⟨c, hc, hf, hn⟩ + +/-- Endpoint signs and the vanishing finite count are equivalent to the original +smooth SVI condition. Matrix evaluation of this count is the remaining bridge. -/ +theorem svi_finite_critical_criterion (p : Params) (hs : 0 < p.sigma) + (hw : ∀ k : ℝ, 0 < variance p k) (hd : 0 < (polynomial p).degree) : + (∀ k : ℝ, 0 ≤ durrleman p k) ↔ + 0 < (polynomial p).leadingCoeff ∧ 0 ≤ (polynomial p).eval 0 ∧ + badCriticalCount (polynomial p) = 0 := by + rw [badCriticalCount_eq_zero_iff _ hd] + exact svi_critical_value_criterion p hs hw hd + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/AssociatedTrace.lean b/LeanPool/MathFin/Models/ModelFree/SVI/AssociatedTrace.lean new file mode 100644 index 0000000000..0b81f1cd2b --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/AssociatedTrace.lean @@ -0,0 +1,60 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.ProductSignature +public import LeanPool.MathFin.Models.ModelFree.SVI.TraceForm +public import Mathlib.RingTheory.Trace.Basic + +/-! # Weighted trace forms of associated polynomials + +Part of the SVI polynomial-sign certificate (#174). + +Replacing the defining polynomial by an associate gives an equivalent weighted trace form, hence +the same signature. + +## Main results + +* `weightedTraceForm_associated_equivalent`: if `f` and `g` are associated, the weighted trace forms + of `f` and `g` against `q` are equivalent quadratic maps. +* `weightedTraceForm_associated_signature`: they have the same signature. + +## Tags + +Hermite trace form, associated polynomial, signature, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +/-- Changing the defining polynomial by a unit preserves the weighted trace +form, including its degenerate directions. -/ +theorem weightedTraceForm_associated_equivalent (f g q : ℝ[X]) + (h : Associated f g) : + QuadraticMap.Equivalent (weightedTraceForm f q).toQuadraticMap + (weightedTraceForm g q).toQuadraticMap := by + let e := AdjoinRoot.algEquivOfAssociated ℝ f g h + refine ⟨{ e.toLinearEquiv with map_app' := ?_ }⟩ + intro x + simp only [LinearMap.BilinMap.toQuadraticMap_apply, weightedTraceForm_apply] + rw [← Algebra.trace_eq_of_algEquiv e] + simp only [map_mul, ← aeval_algHom_apply] + simp only [e, AdjoinRoot.algEquivOfAssociated_root] + rfl + +theorem weightedTraceForm_associated_signature (f g q : ℝ[X]) + (h : Associated f g) : + formSignature (weightedTraceForm f q).toQuadraticMap = + formSignature (weightedTraceForm g q).toQuadraticMap := + formSignature_eq_of_equivalent (weightedTraceForm_associated_equivalent f g q h) + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/BlackScholesBridge.lean b/LeanPool/MathFin/Models/ModelFree/SVI/BlackScholesBridge.lean new file mode 100644 index 0000000000..80cabded46 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/BlackScholesBridge.lean @@ -0,0 +1,92 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.CallConvexity + +/-! # The certificate and MathFin's Black–Scholes price + +Part of the SVI polynomial-sign certificate (#174). + +`bsSmile` is `MathFin.bsV` with the SVI volatility substituted strike by strike, spot, maturity +and discount factor normalised to one. `fullCertificateFormula_iff_bsSmile_convex`: the finite +sign formula holds exactly when `σ > 0`, `b ≥ 0`, `ρ² ≤ 1`, the variance is positive, and that +price is convex in the strike. + +## Main definitions + +* `bsSmile`: `MathFin.bsV` with the SVI volatility substituted strike by strike, spot, maturity and + discount factor normalised to one. + +## Main results + +* `blackCall_eq_bsSmile`: for `K > 0` and positive variance at `log K`, the forward-normalised Black + call `blackCall p K` equals `bsSmile p K`. +* `bsSmile_convex_iff`: for `σ > 0` and positive variance, `bsSmile p` is convex on `(0, ∞)` iff + `durrleman p k ≥ 0` for all `k`. +* `fullCertificateFormula_iff_bsSmile_convex`: the finite sign formula holds iff `σ > 0`, `b ≥ 0`, + `ρ² ≤ 1`, the variance is positive and `bsSmile p` is convex on `(0, ∞)`. + +## Tags + +SVI smile, convex call price, butterfly arbitrage, Durrleman condition, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Real Set +open ForwardSmile (dpl dmi blackForm) + +/-- The SVI-smiled Black–Scholes price in MathFin's existing price API, +with spot, maturity and discount factor normalized to one. -/ +noncomputable def bsSmile (p : Params) (K : ℝ) : ℝ := + MathFin.bsV K 0 (rootVariance p (Real.log K)) 1 1 + +theorem blackCall_eq_bsSmile (p : Params) (K : ℝ) (hK : 0 < K) + (hw : 0 < variance p (Real.log K)) : blackCall p K = bsSmile p K := by + have hn := ne_of_gt (rootVariance_pos p (Real.log K) hw) + have hd1 : MathFin.bsd1 1 K 0 (rootVariance p (Real.log K)) 1 = + dpl (Real.log K) (variance p (Real.log K)) := by + simp only [MathFin.bsd1, dpl_eq_rootVariance, Real.sqrt_one, mul_one, zero_add, one_div, + Real.log_inv] + field_simp + have hd2 : MathFin.bsd2 1 K 0 (rootVariance p (Real.log K)) 1 = + dmi (Real.log K) (variance p (Real.log K)) := by + rw [MathFin.bsd2, hd1] + simp only [Real.sqrt_one, mul_one, dpl_eq_rootVariance, dmi_eq_rootVariance] + ring + simp [blackCall, ForwardSmile.blackForm, bsSmile, MathFin.bsV, hd1, hd2, Real.exp_log hK] + +/-- The certificate applies to the existing Black–Scholes function with SVI +volatility substituted strike by strike, not a constant-volatility derivative. -/ +theorem bsSmile_convex_iff (p : Params) (hs : 0 < p.sigma) + (hw : ∀ k : ℝ, 0 < variance p k) : + ConvexOn ℝ (Ioi 0) (bsSmile p) ↔ ∀ k : ℝ, 0 ≤ durrleman p k := by + have he : EqOn (blackCall p) (bsSmile p) (Ioi 0) := + fun K hK ↦ blackCall_eq_bsSmile p K hK (hw _) + constructor + · intro hc + exact (blackCall_convex_iff p hs hw).mp (hc.congr he.symm) + · intro hg + exact ((blackCall_convex_iff p hs hw).mpr hg).congr he + +theorem fullCertificateFormula_iff_bsSmile_convex (p : Params) : + fullCertificateFormula.eval p = true ↔ + 0 < p.sigma ∧ 0 ≤ p.b ∧ 0 ≤ 1-p.rho^2 ∧ + (∀ k : ℝ, 0 < variance p k) ∧ ConvexOn ℝ (Ioi 0) (bsSmile p) := by + rw [fullCertificateFormula_iff] + constructor + · rintro ⟨hs,hb,hr,hw,hg⟩ + exact ⟨hs,hb,hr,hw,(bsSmile_convex_iff p hs hw).mpr hg⟩ + · rintro ⟨hs,hb,hr,hw,hc⟩ + exact ⟨hs,hb,hr,hw,(bsSmile_convex_iff p hs hw).mp hc⟩ + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/BlackSmile.lean b/LeanPool/MathFin/Models/ModelFree/SVI/BlackSmile.lean new file mode 100644 index 0000000000..faea80e33d --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/BlackSmile.lean @@ -0,0 +1,176 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.LocalVol.ForwardSmile +public import LeanPool.MathFin.Models.ModelFree.SVI.Reduction + +/-! # The Black call with an SVI smile + +Part of the SVI polynomial-sign certificate (#174). + +The forward-normalised Black call as a function of log-strike and of strike, with total variance +given by raw SVI, and the derivatives of its `d₊`, `d₋` terms and of its delta +(`blackDelta_hasDerivAt`). + +The Black terms are the abstract-variance ones of `Models/LocalVol/ForwardSmile.lean` at the SVI +total +variance `w(k)`: `dpl k (w k)`, `dmi k (w k)` and `blackForm k (w k)` are used directly, and the +Gaussian density cancellation is `exp_mul_pdf_dmi` at `w(k)`. +`durrleman_eq_one_add_smileDelta` relates Durrleman's function to the denominator deformation +`1 + smileDelta` of Dupire's ratio. + +## Main definitions + +* `rootVariance`: the square root `√w(k)` of the SVI total variance. +* `dmiSlope`: the explicit derivative of `d₋` in log-strike. +* `blackDelta`: the derivative of the Black call `blackForm k (w k)` in log-strike divided by `eᵏ`, + the smile term minus `Φ(d₋)`. +* `blackCall`: the forward-normalised Black call as a function of the positive strike ratio. + +## Main results + +* `dpl_eq_rootVariance`, `dmi_eq_rootVariance`: `d₊ = −k/√w + √w/2` and `d₋ = −k/√w − √w/2` at the + SVI total variance `w`. +* `rootVariance_hasDerivAt`, `dmi_hasDerivAt`, `dpl_hasDerivAt`: the derivatives of `√w`, `d₋` and + `d₊` in log-strike, given the derivative of the variance and `w > 0`. +* `blackForm_hasDerivAt`: the log-strike derivative of the Black call `blackForm k (w k)` is + `eᵏ · blackDelta p k`. +* `blackDelta_hasDerivAt`: given the derivatives of the variance and of its slope and `w > 0`, the + derivative of `blackDelta` is the Gaussian factor `ϕ(d₋)/√w` times `durrleman p k`. +* `durrleman_eq_one_add_smileDelta`: where the SVI slice and the tilted surface of `ForwardSmile` + share total variance, slope and curvature, `durrleman p k = 1 + smileDelta σ ψ₁ T₀ ε k T`. + +## Tags + +SVI smile, Black call, Durrleman function, Dupire local volatility, total variance, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Real ProbabilityTheory +open ForwardSmile (dpl dmi blackForm) + +/-- The square root `√w(k)` of the SVI total variance. -/ +noncomputable def rootVariance (p : Params) (k : ℝ) : ℝ := Real.sqrt (variance p k) +/-- `d₊ = −k/√w + √w/2` at the SVI total variance, in terms of `rootVariance`. -/ +theorem dpl_eq_rootVariance (p : Params) (k : ℝ) : + dpl k (variance p k) = -k / rootVariance p k + rootVariance p k / 2 := + ForwardSmile.dpl_eq k _ + +/-- `d₋ = −k/√w − √w/2` at the SVI total variance, in terms of `rootVariance`. -/ +theorem dmi_eq_rootVariance (p : Params) (k : ℝ) : + dmi k (variance p k) = -k / rootVariance p k - rootVariance p k / 2 := + ForwardSmile.dmi_eq k _ + +/-- The explicit derivative of `d₋` in log-strike (`dmi_hasDerivAt`). -/ +noncomputable def dmiSlope (p : Params) (k : ℝ) : ℝ := + -1 / rootVariance p k + k*slope p k / (2*(rootVariance p k)^3) - slope p k / (4*rootVariance p k) + +/-- The explicit derivative of the Black call `blackForm k (w k)` in log-strike, divided by `eᵏ`: +the smile term minus `Φ(d₋)`. -/ +noncomputable def blackDelta (p : Params) (k : ℝ) : ℝ := + gaussianPDFReal 0 1 (dmi k (variance p k)) * slope p k / (2*rootVariance p k) - + MathFin.Phi (dmi k (variance p k)) + +/-- Forward-normalized Black call, as a function of positive strike ratio. -/ +noncomputable def blackCall (p : Params) (K : ℝ) : ℝ := + blackForm (Real.log K) (variance p (Real.log K)) + +theorem rootVariance_pos (p : Params) (k : ℝ) (hw : 0 < variance p k) : + 0 < rootVariance p k := Real.sqrt_pos.mpr hw + +theorem rootVariance_sq (p : Params) (k : ℝ) (hw : 0 ≤ variance p k) : + (rootVariance p k)^2 = variance p k := Real.sq_sqrt hw + +/-- The derivative of `√w`, given that of the SVI total variance `w`. -/ +theorem rootVariance_hasDerivAt (p : Params) (k : ℝ) + (hv : HasDerivAt (variance p) (slope p k) k) + (hw : 0 < variance p k) : + HasDerivAt (rootVariance p) (slope p k / (2*rootVariance p k)) k := + hv.sqrt (ne_of_gt hw) + +theorem dmi_hasDerivAt (p : Params) (k : ℝ) + (hv : HasDerivAt (variance p) (slope p k) k) + (hw : 0 < variance p k) : + HasDerivAt (fun k ↦ dmi k (variance p k)) (dmiSlope p k) k := by + have hr := rootVariance_hasDerivAt p k hv hw + have hn := ne_of_gt (rootVariance_pos p k hw) + have h := (((hasDerivAt_id k).neg).div hr hn).sub (hr.div_const 2) + simp only [dmi_eq_rootVariance] + convert h using 1 <;> try rfl + dsimp [dmiSlope] + field_simp + ring + +theorem dpl_hasDerivAt (p : Params) (k : ℝ) + (hv : HasDerivAt (variance p) (slope p k) k) + (hw : 0 < variance p k) : + HasDerivAt (fun k ↦ dpl k (variance p k)) + (dmiSlope p k + slope p k / (2*rootVariance p k)) k := by + have h := (dmi_hasDerivAt p k hv hw).add (rootVariance_hasDerivAt p k hv hw) + convert h using 1 + funext x + simp only [dpl_eq_rootVariance, dmi_eq_rootVariance, Pi.add_apply] + ring + +theorem blackForm_hasDerivAt (p : Params) (k : ℝ) + (hv : HasDerivAt (variance p) (slope p k) k) + (hw : 0 < variance p k) : + HasDerivAt (fun k ↦ blackForm k (variance p k)) (Real.exp k * blackDelta p k) k := by + have hp := (MathFin.hasDerivAt_Phi (dpl k (variance p k))).comp k (dpl_hasDerivAt p k hv hw) + have hm := (MathFin.hasDerivAt_Phi (dmi k (variance p k))).comp k (dmi_hasDerivAt p k hv hw) + have h := hp.sub ((Real.hasDerivAt_exp k).mul hm) + convert h using 1 <;> try rfl + rw [← ForwardSmile.exp_mul_pdf_dmi hw] + dsimp [blackDelta] + ring + +/-- The derivative of the strike delta is the positive Gaussian factor times +Durrleman's expression, given the derivatives of the total variance and of its slope (the +regime-specific input: `variance_hasDerivAt`, `slope_hasDerivAt` for `σ > 0`, and their +zero-scale counterparts off the kink). -/ +theorem blackDelta_hasDerivAt (p : Params) (k : ℝ) + (hv : HasDerivAt (variance p) (slope p k) k) + (hslope : HasDerivAt (slope p) (curvature p k) k) + (hw : 0 < variance p k) : + HasDerivAt (blackDelta p) + (gaussianPDFReal 0 1 (dmi k (variance p k)) / rootVariance p k * durrleman p k) k := by + have hm := dmi_hasDerivAt p k hv hw + have hp := (MathFin.hasDerivAt_gaussianPDFReal_zero_one (dmi k (variance p k))).comp k hm + have hc := (MathFin.hasDerivAt_Phi (dmi k (variance p k))).comp k hm + have hr := rootVariance_hasDerivAt p k hv hw + have hn := ne_of_gt (rootVariance_pos p k hw) + have h := ((hp.mul hslope).div (hr.const_mul 2) + (mul_ne_zero (by norm_num) hn)).sub hc + convert h using 1 <;> try rfl + simp only [durrleman, dmiSlope, dmi_eq_rootVariance, Function.comp_apply, Pi.mul_apply] + rw [← rootVariance_sq p k hw.le] + field_simp + ring + +/-- **`1 + smileDelta` is Durrleman's function.** The denominator deformation `1 + δ` of Dupire's +ratio on the tilted surface (`smileDelta`) has the algebraic form of Durrleman's `g`: at a +log-strike where the SVI slice and the tilted surface have the same total variance, slope and +curvature (`w'' = 2(εψ₁/√(T+T₀))²T`, the surface's constant `∂_kk w`), with the variance nonzero, +`durrleman p k = 1 + smileDelta σ ψ₁ T₀ ε k T`. -/ +theorem durrleman_eq_one_add_smileDelta (p : Params) {σ ψ₁ T₀ ε k T : ℝ} + (hw : variance p k = ForwardSmile.totalVar σ ψ₁ T₀ ε k T) + (hw0 : ForwardSmile.totalVar σ ψ₁ T₀ ε k T ≠ 0) + (hs : slope p k = ForwardSmile.wSlope σ ψ₁ T₀ ε T k) + (hc : curvature p k = 2 * ((ε * ψ₁ / Real.sqrt (T + T₀)) ^ 2 * T)) : + durrleman p k = 1 + ForwardSmile.smileDelta σ ψ₁ T₀ ε k T := by + rw [durrleman, hw, hs, hc, ForwardSmile.smileDelta] + field_simp + ring + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/CallConvexity.lean b/LeanPool/MathFin/Models/ModelFree/SVI/CallConvexity.lean new file mode 100644 index 0000000000..e0f3620bb9 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/CallConvexity.lean @@ -0,0 +1,147 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.BlackSmile +public import LeanPool.MathFin.Models.ModelFree.SVI.DomainFormula +public import Mathlib.RingTheory.Flat.TorsionFree +public import Mathlib.RingTheory.Smooth.Flat + +/-! # Durrleman's condition is convexity of the call in strike + +Part of the SVI polynomial-sign certificate (#174). + +The second strike derivative of the SVI-smiled Black call is computed (`blackCall_deriv2`), and +for `σ > 0` and positive variance its convexity on `(0, ∞)` is equivalent to `g(k) ≥ 0` for every +`k` (`blackCall_convex_iff`). + +## Main definitions + +* `strikeDelta`: the first strike derivative of `blackCall`, `blackDelta p (log K)`. +* `strikeDensity`: the second strike derivative of `blackCall`, a positive Gaussian factor times + Durrleman's function. + +## Main results + +* `blackCall_deriv2`: for `σ > 0` and positive variance, the second derivative of `blackCall p` in + strike `K > 0` equals `strikeDensity p K`. +* `strikeDensity_nonneg_iff`: `0 ≤ strikeDensity p K` iff `0 ≤ durrleman p (log K)`. +* `blackCall_convex_iff`: for `σ > 0` and positive variance, `blackCall p` is convex on `(0, ∞)` + iff `0 ≤ durrleman p k` for every `k`. +* `certificateFormula_iff_call_convex`: on `σ > 0`, `b ≥ 0`, `1 - ρ² ≥ 0` and the variance gate, + the finite sign formula `certificateFormula` holds iff `blackCall p` is convex on `(0, ∞)`. +* `fullCertificateFormula_iff_call_convex`: `fullCertificateFormula` holds iff the parameters + satisfy the domain conditions and `blackCall p` is convex on `(0, ∞)`. + +## Tags + +Durrleman condition, call convexity in strike, butterfly arbitrage, SVI smile, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Real ProbabilityTheory Set +open ForwardSmile (dpl dmi blackForm) + +/-- The first derivative of `blackCall` in strike (`blackCall_hasDerivAt`). -/ +noncomputable def strikeDelta (p : Params) (K : ℝ) : ℝ := blackDelta p (Real.log K) +/-- The second derivative of `blackCall` in strike: a positive Gaussian factor times Durrleman's +function (`strikeDelta_hasDerivAt`). -/ +noncomputable def strikeDensity (p : Params) (K : ℝ) : ℝ := + gaussianPDFReal 0 1 (dmi (Real.log K) (variance p (Real.log K))) / + (K*rootVariance p (Real.log K)) * durrleman p (Real.log K) + +theorem blackCall_hasDerivAt (p : Params) (hs : 0 < p.sigma) (K : ℝ) (hK : 0 < K) + (hw : 0 < variance p (Real.log K)) : + HasDerivAt (blackCall p) (strikeDelta p K) K := by + have h := (blackForm_hasDerivAt p (Real.log K) (variance_hasDerivAt p hs _) hw).comp K + (Real.hasDerivAt_log (ne_of_gt hK)) + convert h using 1 <;> try rfl + simp only [Real.exp_log hK, strikeDelta] + field_simp + +theorem strikeDelta_hasDerivAt (p : Params) (hs : 0 < p.sigma) (K : ℝ) (hK : 0 < K) + (hw : 0 < variance p (Real.log K)) : + HasDerivAt (strikeDelta p) (strikeDensity p K) K := by + have h := (blackDelta_hasDerivAt p (Real.log K) (variance_hasDerivAt p hs _) + (slope_hasDerivAt p hs _) hw).comp K + (Real.hasDerivAt_log (ne_of_gt hK)) + convert h using 1 <;> try rfl + dsimp [strikeDensity] + ring + +theorem strikeDensity_nonneg_iff (p : Params) (K : ℝ) (hK : 0 < K) + (hw : 0 < variance p (Real.log K)) : + 0 ≤ strikeDensity p K ↔ 0 ≤ durrleman p (Real.log K) := by + have hp := gaussianPDFReal_pos 0 1 (dmi (Real.log K) (variance p (Real.log K))) (by norm_num) + have hs := rootVariance_pos p (Real.log K) hw + exact mul_nonneg_iff_of_pos_left (div_pos hp (mul_pos hK hs)) + +/-- The actual second strike derivative, including the smile's first and +second variance derivatives. -/ +theorem blackCall_deriv2 (p : Params) (hs : 0 < p.sigma) + (hw : ∀ k : ℝ, 0 < variance p k) (K : ℝ) (hK : 0 < K) : + deriv (deriv (blackCall p)) K = strikeDensity p K := by + have he : deriv (blackCall p) =ᶠ[nhds K] strikeDelta p := by + filter_upwards [eventually_gt_nhds hK] with x hx + exact (blackCall_hasDerivAt p hs x hx (hw _)).deriv + exact ((strikeDelta_hasDerivAt p hs K hK (hw _)).congr_of_eventuallyEq he).deriv + +/-- Durrleman's condition is exactly convexity in positive strike ratio of +the forward-normalized Black call with this SVI total variance. -/ +theorem blackCall_convex_iff (p : Params) (hs : 0 < p.sigma) + (hw : ∀ k : ℝ, 0 < variance p k) : + ConvexOn ℝ (Ioi 0) (blackCall p) ↔ ∀ k : ℝ, 0 ≤ durrleman p k := by + have hfirst (K : ℝ) (hK : K ∈ Ioi (0 : ℝ)) := blackCall_hasDerivAt p hs K hK (hw _) + have hsecond (K : ℝ) (hK : K ∈ Ioi (0 : ℝ)) := strikeDelta_hasDerivAt p hs K hK (hw _) + constructor + · intro hc k + have hm := hc.monotoneOn_deriv (fun K hK ↦ (hfirst K hK).differentiableAt) + have hm' : MonotoneOn (strikeDelta p) (Ioi 0) := by + intro x hx y hy hxy + rw [← (hfirst x hx).deriv, ← (hfirst y hy).deriv] + exact hm hx hy hxy + have hh : 0 ≤ derivWithin (strikeDelta p) (Ioi 0) (Real.exp k) := hm'.derivWithin_nonneg + rw [(hsecond _ (Real.exp_pos k)).hasDerivWithinAt.derivWithin + (isOpen_Ioi.uniqueDiffOn _ (Real.exp_pos k))] at hh + have hg := (strikeDensity_nonneg_iff p _ (Real.exp_pos k) (hw _)).mp hh + simpa using hg + · intro hg + apply convexOn_of_hasDerivWithinAt2_nonneg (convex_Ioi (0 : ℝ)) + (fun K hK ↦ (hfirst K hK).continuousAt.continuousWithinAt) + (f' := strikeDelta p) (f'' := strikeDensity p) + · intro K hK + exact (hfirst K (interior_subset hK)).hasDerivWithinAt + · intro K hK + exact (hsecond K (interior_subset hK)).hasDerivWithinAt + · intro K hK + exact (strikeDensity_nonneg_iff p K (interior_subset hK) (hw _)).mpr (hg _) + +/-- The finite determinant formula characterizes call-price convexity on the +entire stated smooth positive-variance parameter domain. -/ +theorem certificateFormula_iff_call_convex (p : Params) (hs : 0 < p.sigma) + (hb : 0 ≤ p.b) (hr : 0 ≤ 1 - p.rho ^ 2) (hg : varianceGate p) : + certificateFormula.eval p = true ↔ ConvexOn ℝ (Ioi 0) (blackCall p) := by + rw [blackCall_convex_iff p hs ((varianceGate_iff p hs hb hr).mp hg)] + exact certificateFormula_iff p hs hb hr hg + +theorem fullCertificateFormula_iff_call_convex (p : Params) : + fullCertificateFormula.eval p = true ↔ + 0 < p.sigma ∧ 0 ≤ p.b ∧ 0 ≤ 1-p.rho^2 ∧ + (∀ k : ℝ, 0 < variance p k) ∧ ConvexOn ℝ (Ioi 0) (blackCall p) := by + rw [fullCertificateFormula_iff] + constructor + · rintro ⟨hs,hb,hr,hw,hg⟩ + exact ⟨hs,hb,hr,hw,(blackCall_convex_iff p hs hw).mpr hg⟩ + · rintro ⟨hs,hb,hr,hw,hc⟩ + exact ⟨hs,hb,hr,hw,(blackCall_convex_iff p hs hw).mp hc⟩ + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/ClearedSignature.lean b/LeanPool/MathFin/Models/ModelFree/SVI/ClearedSignature.lean new file mode 100644 index 0000000000..bb45bb1165 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/ClearedSignature.lean @@ -0,0 +1,85 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.Denominators +public import LeanPool.MathFin.Models.ModelFree.SVI.MatrixSignature + +/-! # The signature test survives clearing denominators + +Part of the SVI polynomial-sign certificate (#174). + +The Hermite matrices are symmetric. The cleared matrix, which is `leadingCoeff^38` (a positive +factor) times the Hermite matrix when `leadingCoeff ≠ 0`, the size is `n ≤ 9` and the weight has +degree at most `22`, has the same signature test (`clearedHermite_signature`). +`certificateMatrix_signature` specialises this to the four certificate matrices of a nonconstant +polynomial of degree at most ten. + +## Main results + +* `hermite_symmetric`: the Hermite matrix `hermite f q n` is symmetric. +* `clearedHermite_signature`: for `leadingCoeff ≠ 0`, `n ≤ 9` and `q.natDegree ≤ 22`, the cleared + matrix has the same `signatureTest` as `hermite f q n`. +* `derivative_size_bound`, `weight_size_bound`: for `natDegree ≤ 10`, the derivative has degree at + most `9` and the four weights have degree at most `22`. +* `certificateMatrix_signature`: for a nonconstant `P` of degree at most ten, each of the four + certificate matrices has the same `signatureTest` as the corresponding Hermite matrix. + +## Tags + +Hermite matrix, signature test, cleared denominators, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +theorem hermite_symmetric (f q : ℝ[X]) (n : ℕ) : (hermite f q n).IsSymm := by + ext i j + simp [hermite, Matrix.transpose_apply, Nat.add_comm] + +/-- Clearing all companion denominators preserves the exact signature test. -/ +theorem clearedHermite_signature (f q : ℝ[X]) (n : ℕ) + (hf : f.leadingCoeff ≠ 0) (hn : n ≤ 9) (hq : q.natDegree ≤ 22) : + signatureTest (clearedHermite f q n) = signatureTest (hermite f q n) := by + rw [clearedHermite_eq_smul f q n hf hn hq] + exact signatureTest_smul_pos _ (hermite_symmetric f q n) _ (clearing_factor_pos f hf) + +theorem derivative_size_bound (P : ℝ[X]) (hd : P.natDegree ≤ 10) : + P.derivative.natDegree ≤ 9 := by + have hh := natDegree_derivative_le P + omega + +theorem weight_size_bound (P : ℝ[X]) (hd : P.natDegree ≤ 10) (i : Fin 4) : + (![X^2*P^2, X*P^2, X^2*P, X*P] i).natDegree ≤ 22 := by + fin_cases i <;> dsimp + all_goals + have h1 := @natDegree_mul_le ℝ _ (X^2) (P^2) + have h2 := @natDegree_mul_le ℝ _ X (P^2) + have h3 := @natDegree_mul_le ℝ _ (X^2) P + have h4 := @natDegree_mul_le ℝ _ X P + have hp := @natDegree_pow_le ℝ _ P 2 + simp only [natDegree_X_pow, natDegree_X] at * + omega + +theorem certificateMatrix_signature (P : ℝ[X]) (hd : P.natDegree ≤ 10) + (hn : P.natDegree ≠ 0) (i : Fin 4) : + signatureTest (certificateMatrices P i) = + signatureTest (hermite P.derivative (![X^2*P^2, X*P^2, X^2*P, X*P] i) + P.derivative.natDegree) := by + have hf : P.derivative.leadingCoeff ≠ 0 := leadingCoeff_ne_zero.mpr + (derivative_ne_zero.mpr hn) + have hh := clearedHermite_signature P.derivative + (![X^2*P^2, X*P^2, X^2*P, X*P] i) P.derivative.natDegree hf + (derivative_size_bound P hd) (weight_size_bound P hd i) + fin_cases i <;> simpa [certificateMatrices] using hh + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/Companion.lean b/LeanPool/MathFin/Models/ModelFree/SVI/Companion.lean new file mode 100644 index 0000000000..c202c2d91b --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/Companion.lean @@ -0,0 +1,77 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.Denominators +public import Mathlib.LinearAlgebra.Matrix.Charpoly.Minpoly +public import Mathlib.RingTheory.AdjoinRoot +public import Mathlib.RingTheory.Trace.Defs + +/-! # The companion matrix is multiplication by the root + +Part of the SVI polynomial-sign certificate (#174). + +For `f ≠ 0`, `companion f f.natDegree` is the matrix of multiplication by the class of `X` in +`ℝ[X]/(f)`, in the power basis, with no irreducibility or squarefreeness assumed. Its +characteristic polynomial is `f` made monic, and traces of its powers are algebra traces. + +## Main results + +* `companion_eq_leftMulMatrix`: for `f ≠ 0`, `companion f f.natDegree` is the matrix of + multiplication by `AdjoinRoot.root f` in the power basis of `AdjoinRoot f`. +* `companion_charpoly`: its characteristic polynomial is `f * C f.leadingCoeff⁻¹`. +* `trace_companion_pow_eq_algebraTrace`: the trace of its `r`-th power is the algebra trace of + `(AdjoinRoot.root f)^r`. + +## Tags + +companion matrix, characteristic polynomial, trace of powers, quotient algebra, SVI, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +/-- The concrete companion matrix really is multiplication by the residue +class of X in the full quotient algebra. No irreducibility or squarefreeness +is imposed. -/ +theorem companion_eq_leftMulMatrix (f : ℝ[X]) (hf : f ≠ 0) : + companion f f.natDegree = + Algebra.leftMulMatrix (AdjoinRoot.powerBasis hf).basis (AdjoinRoot.root f) := by + have hl : f.leadingCoeff ≠ 0 := leadingCoeff_ne_zero.mpr hf + rw [show AdjoinRoot.root f = (AdjoinRoot.powerBasis hf).gen from rfl, + (AdjoinRoot.powerBasis hf).leftMulMatrix] + ext i j + simp only [companion, scaledCompanion, Matrix.smul_apply, smul_eq_mul, + PowerBasis.minpolyGen_eq, AdjoinRoot.minpoly_powerBasis_gen, + coeff_mul_C, AdjoinRoot.powerBasis_dim] + change _ = if (j : ℕ) + 1 = f.natDegree then _ else _ + split_ifs <;> simp [hl, mul_comm] + +theorem companion_charpoly (f : ℝ[X]) (hf : f ≠ 0) : + (companion f f.natDegree).charpoly = f * C f.leadingCoeff⁻¹ := by + rw [companion_eq_leftMulMatrix f hf] + exact (charpoly_leftMulMatrix (AdjoinRoot.powerBasis hf)).trans + (AdjoinRoot.minpoly_powerBasis_gen hf) + +/-- Every matrix power computes the trace of the corresponding quotient +algebra element, including nilpotent directions at multiple roots. -/ +theorem trace_companion_pow_eq_algebraTrace (f : ℝ[X]) (hf : f ≠ 0) (r : ℕ) : + Matrix.trace ((companion f f.natDegree)^r) = + Algebra.trace ℝ (AdjoinRoot f) ((AdjoinRoot.root f)^r) := by + rw [companion_eq_leftMulMatrix f hf] + change Matrix.trace (((Algebra.leftMulMatrix (AdjoinRoot.powerBasis hf).basis) + (AdjoinRoot.root f))^r) = _ + rw [← map_pow] + exact (Algebra.trace_eq_matrix_trace (AdjoinRoot.powerBasis hf).basis _).symm + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/ConvexKink.lean b/LeanPool/MathFin/Models/ModelFree/SVI/ConvexKink.lean new file mode 100644 index 0000000000..d23fbe91cd --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/ConvexKink.lean @@ -0,0 +1,98 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.Analysis.Convex.Deriv +public import Mathlib.RingTheory.Flat.TorsionFree +public import Mathlib.RingTheory.Smooth.Flat +public import Mathlib.Analysis.Convex.Slope +public import Mathlib.Analysis.InnerProductSpace.Basic +public import Mathlib.Topology.Algebra.Module.ModuleTopology + +/-! # Convexity across a kink + +Part of the SVI polynomial-sign certificate (#174). + +Two convex pieces whose one-sided derivatives jump upwards at the junction form a convex +function (`convexOn_Ioi_of_convex_pieces`). Used for the zero-scale SVI slice. + +## Main results + +* `convexOn_Ioi_of_convex_pieces`: if `f` is convex on `(0, J]` and on `[J, ∞)`, and the left + derivative `dl` at `J` is at most the right derivative `dr`, then `f` is convex on `(0, ∞)`. + +## Tags + +convexity across a kink, one-sided derivatives, convex pieces, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Set + +/-- If two adjacent secant slopes are both at least `L`, so is the joined secant slope. -/ +lemma secant_join_lower {f : ℝ → ℝ} {x y z L : ℝ} + (hxy : x < y) (hyz : y < z) + (h₁ : L ≤ (f y - f x) / (y - x)) (h₂ : L ≤ (f z - f y) / (z - y)) : + L ≤ (f z-f x)/(z-x) := by + rw [le_div_iff₀ (sub_pos.mpr hxy)] at h₁ + rw [le_div_iff₀ (sub_pos.mpr hyz)] at h₂ + rw [le_div_iff₀ (sub_pos.mpr (hxy.trans hyz))] + nlinarith + +/-- If two adjacent secant slopes are both at most `L`, so is the joined secant slope. -/ +lemma secant_join_upper {f : ℝ → ℝ} {x y z L : ℝ} + (hxy : x < y) (hyz : y < z) + (h₁ : (f y - f x) / (y - x) ≤ L) (h₂ : (f z - f y) / (z - y) ≤ L) : + (f z-f x)/(z-x) ≤ L := by + rw [div_le_iff₀ (sub_pos.mpr hxy)] at h₁ + rw [div_le_iff₀ (sub_pos.mpr hyz)] at h₂ + rw [div_le_iff₀ (sub_pos.mpr (hxy.trans hyz))] + nlinarith + +/-- Two convex pieces form a convex function if the derivative jumps upwards +at their shared endpoint. -/ +theorem convexOn_Ioi_of_convex_pieces {f : ℝ → ℝ} {J dl dr : ℝ} + (hJ : 0 < J) (hleft : ConvexOn ℝ (Ioc 0 J) f) + (hright : ConvexOn ℝ (Ici J) f) + (hdl : HasDerivWithinAt f dl (Iic J) J) + (hdr : HasDerivWithinAt f dr (Ici J) J) (hjump : dl ≤ dr) : + ConvexOn ℝ (Ioi 0) f := by + have hL {x : ℝ} (hx : 0 < x) (hxJ : x < J) : + (f J-f x)/(J-x) ≤ dl := by + simpa only [slope_def_field] using + hleft.slope_le_of_hasDerivWithinAt_Iio ⟨hx, hxJ.le⟩ ⟨hJ, le_rfl⟩ hxJ + (hdl.mono Iio_subset_Iic_self) + have hR {z : ℝ} (hJz : J < z) : dr ≤ (f z-f J)/(z-J) := by + simpa only [slope_def_field] using + hright.le_slope_of_hasDerivWithinAt_Ioi (show J ∈ Ici J from mem_Ici.mpr le_rfl) + hJz.le hJz (hdr.mono Ioi_subset_Ici_self) + apply convexOn_of_slope_mono_adjacent (convex_Ioi (0 : ℝ)) + intro x y z hx hz hxy hyz + have hy : 0 < y := lt_trans hx hxy + by_cases hzJ : z ≤ J + · exact hleft.slope_mono_adjacent ⟨hx, (hxy.trans hyz).le.trans hzJ⟩ ⟨hz, hzJ⟩ hxy hyz + by_cases hJx : J ≤ x + · exact hright.slope_mono_adjacent hJx (hJx.trans (hxy.trans hyz).le) hxy hyz + have hxJ : x < J := lt_of_not_ge hJx + have hJz : J < z := lt_of_not_ge hzJ + rcases lt_trichotomy y J with hyJ | rfl | hJy + · have hxyJ := hleft.slope_mono_adjacent ⟨hx, hxJ.le⟩ ⟨hJ, le_rfl⟩ hxy hyJ + exact secant_join_lower hyJ hJz hxyJ + (hxyJ.trans ((hL hy hyJ).trans (hjump.trans (hR hJz)))) + · exact (hL hx hxJ).trans (hjump.trans (hR hJz)) + · have hJyz := hright.slope_mono_adjacent (show J ∈ Ici J from mem_Ici.mpr le_rfl) hJz.le hJy hyz + exact secant_join_upper hxJ hJy + (((hL hx hxJ).trans (hjump.trans (hR hJy))).trans hJyz) hJyz + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/CriticalPoints.lean b/LeanPool/MathFin/Models/ModelFree/SVI/CriticalPoints.lean new file mode 100644 index 0000000000..f9c712f381 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/CriticalPoints.lean @@ -0,0 +1,132 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.Analysis.Calculus.Deriv.Polynomial +public import Mathlib.Analysis.Polynomial.Basic +public import Mathlib.Analysis.Calculus.LocalExtr.Basic +public import Mathlib.Topology.Algebra.Polynomial + +/-! # Nonnegativity of a polynomial on the positive half-line + +Part of the SVI polynomial-sign certificate (#174). + +A nonconstant real polynomial is nonnegative on `(0, ∞)` exactly when its leading coefficient is +positive, its constant term is nonnegative, and it has no critical point `c > 0` with a negative +value (`polynomial_nonneg_criterion`). `four_sign_selector` is the sign identity behind the four +Tarski queries. + +## Main definitions + +* `sign`: the sign of a real number as an integer, `1`, `-1` or `0`. + +## Main results + +* `exists_negative_critical`: a negative value of `P` at `x ∈ (0, R)`, with `P(0) ≥ 0` and + `P(R) ≥ 0`, forces a critical point `c ∈ (0, R)` with `P(c) < 0`. +* `nonneg_iff_no_negative_critical`: for positive leading coefficient and `P(0) ≥ 0`, `P` is + nonnegative on `(0, ∞)` iff it has no critical point `c > 0` with `P(c) < 0`. +* `polynomial_nonneg_criterion`: a nonconstant `P` is nonnegative on `(0, ∞)` iff its leading + coefficient is positive, `P(0) ≥ 0`, and it has no critical point `c > 0` with `P(c) < 0`. +* `four_sign_selector`: `sign (c²v²) + sign (cv²) - sign (c²v) - sign (cv)` is `4` if `c > 0` and + `v < 0`, and `0` otherwise. + +## Tags + +polynomial nonnegativity, critical point criterion, Tarski query, positive half-line, SVI, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Set Filter Polynomial + +/-- A negative value between nonnegative endpoints forces a negative interior +critical value. No simplicity or nondegeneracy assumption is used. -/ +theorem exists_negative_critical (P : ℝ[X]) (R x : ℝ) + (hx : 0 < x) (hxR : x < R) (h0 : 0 ≤ P.eval 0) + (hR : 0 ≤ P.eval R) (hxneg : P.eval x < 0) : + ∃ c : ℝ, 0 < c ∧ c < R ∧ P.derivative.eval c = 0 ∧ P.eval c < 0 := by + obtain ⟨c, hc, hmin⟩ := isCompact_Icc.exists_isMinOn + (show (Icc (0 : ℝ) R).Nonempty from ⟨x, hx.le, hxR.le⟩) P.continuous.continuousOn + have hneg : P.eval c < 0 := lt_of_le_of_lt (hmin ⟨hx.le, hxR.le⟩) hxneg + have hc0 : 0 < c := by + by_contra h + have : c = 0 := le_antisymm (le_of_not_gt h) hc.1 + subst c + linarith + have hcR : c < R := by + by_contra h + have : c = R := le_antisymm hc.2 (le_of_not_gt h) + subst c + linarith + refine ⟨c, hc0, hcR, ?_, hneg⟩ + have hlocal := hmin.isLocalMin (Icc_mem_nhds hc0 hcR) + simpa only [Polynomial.deriv] using hlocal.deriv_eq_zero + +/-- The critical-value criterion, assuming a positive leading coefficient. +This isolates the analytic part of the finite certificate. -/ +theorem nonneg_iff_no_negative_critical (P : ℝ[X]) (hd : 0 < P.degree) + (hl : 0 < P.leadingCoeff) (h0 : 0 ≤ P.eval 0) : + (∀ x : ℝ, 0 < x → 0 ≤ P.eval x) ↔ + ¬ ∃ c : ℝ, 0 < c ∧ P.derivative.eval c = 0 ∧ P.eval c < 0 := by + constructor + · intro h ⟨c, hc, _, hn⟩ + exact (not_lt_of_ge (h c hc)) hn + · intro h x hx + by_contra hn + have hxneg : P.eval x < 0 := lt_of_not_ge hn + obtain ⟨z, hz⟩ := Filter.Eventually.exists_forall_of_atTop + ((P.tendsto_atTop_of_leadingCoeff_nonneg hd hl.le).eventually_gt_atTop 0) + let R := max z (x + 1) + have hxR : x < R := lt_of_lt_of_le (by linarith) (le_max_right _ _) + have hR : 0 ≤ P.eval R := (hz R (le_max_left _ _)).le + obtain ⟨c, hc, _, hder, hneg⟩ := exists_negative_critical P R x hx hxR h0 hR hxneg + exact h ⟨c, hc, hder, hneg⟩ + +/-- The full nonconstant polynomial criterion, with both endpoint conditions. -/ +theorem polynomial_nonneg_criterion (P : ℝ[X]) (hd : 0 < P.degree) : + (∀ x : ℝ, 0 < x → 0 ≤ P.eval x) ↔ + 0 < P.leadingCoeff ∧ 0 ≤ P.eval 0 ∧ + ¬ ∃ c : ℝ, 0 < c ∧ P.derivative.eval c = 0 ∧ P.eval c < 0 := by + constructor + · intro h + have hl : 0 < P.leadingCoeff := by + by_contra hn + have ht := P.tendsto_atBot_of_leadingCoeff_nonpos hd (le_of_not_gt hn) + obtain ⟨x, hx, hneg⟩ := ((eventually_gt_atTop (0 : ℝ)).and + (ht.eventually_lt_atBot 0)).exists + exact (not_lt_of_ge (h x hx)) hneg + have h0 : 0 ≤ P.eval 0 := by + have hc : IsClosed {x : ℝ | 0 ≤ P.eval x} := isClosed_le continuous_const P.continuous + have hsub : Ioi (0 : ℝ) ⊆ {x : ℝ | 0 ≤ P.eval x} := fun x hx ↦ h x hx + have hh := closure_minimal hsub hc + apply hh + simp only [closure_Ioi, mem_Ici, le_refl] + exact ⟨hl, h0, (nonneg_iff_no_negative_critical P hd hl h0).mp h⟩ + · rintro ⟨hl, h0, hc⟩ + exact (nonneg_iff_no_negative_critical P hd hl h0).mpr hc + +/-- The local sign selector used in the four Tarski queries. -/ +noncomputable def sign (x : ℝ) : ℤ := if 0 < x then 1 else if x < 0 then -1 else 0 + +theorem four_sign_selector (c v : ℝ) : + sign (c^2*v^2) + sign (c*v^2) - sign (c^2*v) - sign (c*v) = + if 0 < c ∧ v < 0 then 4 else 0 := by + rcases lt_trichotomy c 0 with hc | rfl | hc <;> + rcases lt_trichotomy v 0 with hv | rfl | hv <;> + simp [sign, *, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg, + mul_pos_of_neg_of_neg, sq_pos_of_neg, + not_lt_of_ge, le_of_lt] + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/DegreeProgram.lean b/LeanPool/MathFin/Models/ModelFree/SVI/DegreeProgram.lean new file mode 100644 index 0000000000..a1b15a304f --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/DegreeProgram.lean @@ -0,0 +1,86 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.SignFormula + +/-! # Reading the degree by sign queries + +Part of the SVI polynomial-sign certificate (#174). + +A sign program that finds the degree and leading sign of the numerator polynomial from the signs +of its coefficients, as polynomials in the parameters (`degreeProgram_eval`). + +## Main definitions + +* `degreeProgram`: a sign program that scans the coefficients of `universalPolynomial` from index + `n` down and returns the first nonzero index with its sign. + +## Main results + +* `universalCoefficient_eval`: evaluating the `r`-th coefficient of `universalPolynomial` at the + parameters `p` gives `(polynomial p).coeff r`. +* `degreeProgram_eval`: if `(polynomial p).natDegree ≤ n`, then `degreeProgram n` evaluates at `p` + to the degree and the sign of the leading coefficient of `polynomial p`. + +## Tags + +sign program, polynomial degree, leading coefficient sign, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +/-- A sign program reading off, from the top coefficient down, the first index `≤ n` whose +coefficient of the universal polynomial is nonzero, with its sign; `(0, s)` with the sign of the +constant coefficient if none is. -/ +noncomputable def degreeProgram : ℕ → SignProgram (ℕ × SignType) + | 0 => (signQuery (universalPolynomial.coeff 0)).bind fun s ↦ .pure (0,s) + | n+1 => .query (universalPolynomial.coeff (n+1)) + (.pure (n+1,.neg)) (degreeProgram n) (.pure (n+1,.pos)) + +theorem universalCoefficient_eval (p : Params) (r : ℕ) : + parameterEval p (universalPolynomial.coeff r) = (polynomial p).coeff r := by + rw [← coeff_map, universalPolynomial_eval] + +theorem degreeProgram_eval (p : Params) (n : ℕ) (hn : (polynomial p).natDegree ≤ n) : + (degreeProgram n).eval p = + ((polynomial p).natDegree, SignType.sign (polynomial p).leadingCoeff) := by + induction n with + | zero => + have hd : (polynomial p).natDegree = 0 := Nat.eq_zero_of_le_zero hn + simp [degreeProgram, SignProgram.eval_bind, SignProgram.eval, + universalCoefficient_eval, leadingCoeff, hd] + | succ n ih => + simp only [degreeProgram, SignProgram.eval, universalCoefficient_eval] + cases hs : SignType.sign ((polynomial p).coeff (n+1)) with + | zero => + have hz : (polynomial p).coeff (n+1) = 0 := sign_eq_zero_iff.mp hs + have hd : (polynomial p).natDegree ≤ n := by + by_contra h + have he : (polynomial p).natDegree = n+1 := by omega + have hne : polynomial p ≠ 0 := by intro h; simp [h] at he + have hc : (polynomial p).coeff (n+1) ≠ 0 := by + rw [← he, coeff_natDegree] + exact leadingCoeff_ne_zero.mpr hne + exact hc hz + exact ih hd + | neg => + have hneg : (polynomial p).coeff (n+1) < 0 := sign_eq_neg_one_iff.mp hs + have hd := natDegree_eq_of_le_of_coeff_ne_zero hn (ne_of_lt hneg) + simp only [leadingCoeff, hd, hs] + | pos => + have hpos : 0 < (polynomial p).coeff (n+1) := sign_eq_one_iff.mp hs + have hd := natDegree_eq_of_le_of_coeff_ne_zero hn (ne_of_gt hpos) + simp only [leadingCoeff, hd, hs] + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/Denominators.lean b/LeanPool/MathFin/Models/ModelFree/SVI/Denominators.lean new file mode 100644 index 0000000000..bb9345e937 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/Denominators.lean @@ -0,0 +1,82 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.Matrices +public import Mathlib.Analysis.Normed.Field.Basic + +/-! # Companion and Hermite matrices, and their denominators + +Part of the SVI polynomial-sign certificate (#174). + +The companion matrix `companion f n`, the Hermite matrix `hermite f q n` of traces of +`q·Xⁱ⁺ʲ`, and the factor `leadingCoeff^38`, positive when the leading coefficient is nonzero, which +clears every denominator for `n ≤ 9` and `q.natDegree ≤ 22` (`clearedHermite_eq_smul`). + +## Main definitions + +* `companion`: the companion matrix of `f` at size `n`, normalised by the leading coefficient. +* `hermite`: the Hermite matrix of `f` with weight `q` at size `n`; entry `(i, j)` is + `∑ᵣ qᵣ·tr(Cⁱ⁺ʲ⁺ʳ)` for the companion matrix `C`. + +## Main results + +* `trace_companion_pow`: `tr(Cʳ) = leadingCoeff⁻¹ ^ r · tr(scaledCompanion ^ r)`. +* `clear_scalar_power`: for `ℓ ≠ 0` and `r ≤ 38`, `ℓ^38 · (ℓ⁻¹)^r = ℓ^(38 - r)`. +* `clearedHermite_eq_smul`: for `leadingCoeff ≠ 0`, `n ≤ 9` and `q.natDegree ≤ 22`, + `clearedHermite f q n = leadingCoeff^38 • hermite f q n`. +* `clearing_factor_pos`: `0 < leadingCoeff^38` when the leading coefficient is nonzero. + +## Tags + +Hermite matrix, companion matrix, clearing denominators, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +/-- The companion matrix of `f` at size `n`, normalised by the leading coefficient. -/ +noncomputable def companion (f : ℝ[X]) (n : ℕ) : Matrix (Fin n) (Fin n) ℝ := + f.leadingCoeff⁻¹ • scaledCompanion f n + +/-- The Hermite matrix of `f` with weight `q` at size `n`: entry `(i, j)` is `∑ᵣ qᵣ·tr(Cⁱ⁺ʲ⁺ʳ)` for +the companion matrix `C`. -/ +noncomputable def hermite (f q : ℝ[X]) (n : ℕ) : Matrix (Fin n) (Fin n) ℝ := + fun i j ↦ ∑ r ∈ q.support, + q.coeff r * Matrix.trace ((companion f n) ^ (i.val + j.val + r)) + +theorem trace_companion_pow (f : ℝ[X]) (n r : ℕ) : + Matrix.trace ((companion f n)^r) = + f.leadingCoeff⁻¹ ^ r * Matrix.trace ((scaledCompanion f n)^r) := by + simp [companion, _root_.smul_pow, Matrix.trace_smul] + +theorem clear_scalar_power (ell : ℝ) (he : ell ≠ 0) (r : ℕ) (hr : r ≤ 38) : + ell^38 * (ell⁻¹)^r = ell^(38-r) := by + rw [inv_pow, ← pow_sub₀ ell he hr] + +theorem clearedHermite_eq_smul (f q : ℝ[X]) (n : ℕ) + (hf : f.leadingCoeff ≠ 0) (hn : n ≤ 9) (hq : q.natDegree ≤ 22) : + clearedHermite f q n = f.leadingCoeff^38 • hermite f q n := by + ext i j + simp only [clearedHermite, hermite, Matrix.smul_apply, smul_eq_mul, + Finset.mul_sum, trace_companion_pow] + apply Finset.sum_congr rfl + intro r hr + have hb := exponent_bound n hn i j r ((le_natDegree_of_ne_zero + (mem_support_iff.mp hr)).trans hq) + rw [← clear_scalar_power f.leadingCoeff hf _ hb] + ring + +theorem clearing_factor_pos (f : ℝ[X]) (hf : f.leadingCoeff ≠ 0) : + 0 < f.leadingCoeff^38 := by positivity + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/Derivatives.lean b/LeanPool/MathFin/Models/ModelFree/SVI/Derivatives.lean new file mode 100644 index 0000000000..6c6fe96510 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/Derivatives.lean @@ -0,0 +1,76 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.Reduction +public import Mathlib.Analysis.SpecialFunctions.Sqrt +public import Mathlib.Analysis.Calculus.Deriv.Add +public import Mathlib.Analysis.Calculus.Deriv.Inv +public import Mathlib.Analysis.Calculus.Deriv.Mul +public import Mathlib.Analysis.InnerProductSpace.Basic +public import Mathlib.Topology.Algebra.Module.ModuleTopology + +/-! # The derivatives of raw SVI variance + +Part of the SVI polynomial-sign certificate (#174). + +For `σ > 0`, `slope` and `curvature` are the first and second derivatives of `variance` in +log-strike. + +## Main results + +* `variance_hasDerivAt`: for `σ > 0`, `slope p k` is the derivative of `variance p` at `k`. +* `slope_hasDerivAt`: for `σ > 0`, `curvature p k` is the derivative of `slope p` at `k`. +* `deriv_variance`, `deriv_slope`: the same statements as `deriv (variance p) = slope p` and + `deriv (slope p) = curvature p`. + +## Tags + +raw SVI, variance slope, variance curvature, log-strike derivative, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI + +theorem variance_hasDerivAt (p : Params) (hs : 0 < p.sigma) (k : ℝ) : + HasDerivAt (variance p) (slope p k) k := by + have hpos : 0 < (k - p.m)^2 + p.sigma^2 := by positivity + have hx := (hasDerivAt_id k).sub_const p.m + have hr := ((hx.pow 2).add_const (p.sigma^2)).sqrt (ne_of_gt hpos) + have h := ((hx.const_mul p.rho).add hr).const_mul p.b |>.const_add p.a + convert h using 1 <;> first | rfl | (dsimp [slope]; ring) + +theorem slope_hasDerivAt (p : Params) (hs : 0 < p.sigma) (k : ℝ) : + HasDerivAt (slope p) (curvature p k) k := by + have hpos : 0 < (k - p.m)^2 + p.sigma^2 := by positivity + have hroot : Real.sqrt ((k - p.m)^2 + p.sigma^2) ≠ 0 := + ne_of_gt (Real.sqrt_pos.mpr hpos) + have hx := (hasDerivAt_id k).sub_const p.m + have hr := ((hx.pow 2).add_const (p.sigma^2)).sqrt (ne_of_gt hpos) + have h := ((hx.div hr hroot).const_add p.rho).const_mul p.b + convert h using 1 <;> try rfl + · dsimp [curvature] + have he := Real.sq_sqrt hpos.le + field_simp + rw [he] + ring + +theorem deriv_variance (p : Params) (hs : 0 < p.sigma) : + deriv (variance p) = slope p := by + funext k + exact (variance_hasDerivAt p hs k).deriv + +theorem deriv_slope (p : Params) (hs : 0 < p.sigma) : + deriv (slope p) = curvature p := by + funext k + exact (slope_hasDerivAt p hs k).deriv + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/DomainFormula.lean b/LeanPool/MathFin/Models/ModelFree/SVI/DomainFormula.lean new file mode 100644 index 0000000000..3ac6f064f5 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/DomainFormula.lean @@ -0,0 +1,112 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.FiniteCertificate + +/-! # The finite sign formula for the smooth domain + +Part of the SVI polynomial-sign certificate (#174). + +`fullCertificateFormula`, a finite Boolean combination of signs of polynomials in the five +parameters, holds exactly when `σ > 0`, `b ≥ 0`, `ρ² ≤ 1`, the variance is positive at every +log-strike and `g(k) ≥ 0` for every `k` (`fullCertificateFormula_iff`). + +## Main definitions + +* `positiveAtom`, `nonnegativeAtom`: the sign formulas "`f` is positive" and "`f` is zero or + positive" for a parameter polynomial `f`. +* `domainFormula`: the sign formula for `σ > 0`, `b ≥ 0`, `ρ² ≤ 1` together with the variance gate. +* `fullCertificateFormula`: `domainFormula` conjoined with `certificateFormula`. + +## Main results + +* `positiveAtom_eval`, `nonnegativeAtom_eval`: the atoms evaluate to `0 < parameterEval p f` and + `0 ≤ parameterEval p f`. +* `domainFormula_iff`: `domainFormula` holds iff `0 < σ`, `0 ≤ b`, `0 ≤ 1 - ρ²` and + `varianceGate p`. +* `fullCertificateFormula_iff`: `fullCertificateFormula` holds iff `σ > 0`, `b ≥ 0`, `1 - ρ² ≥ 0`, + the variance is positive at every `k`, and `durrleman p k ≥ 0` for every `k`. + +## Tags + +raw SVI parameters, Durrleman condition, sign formula, quantifier elimination, butterfly arbitrage, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI + +/-- The atom "`f` is positive". -/ +noncomputable def positiveAtom (f : ParameterRing) : SignFormula := .atom f .pos +/-- The formula "`f` is zero or positive". -/ +noncomputable def nonnegativeAtom (f : ParameterRing) : SignFormula := + .or (.atom f .zero) (.atom f .pos) + +@[simp] theorem positiveAtom_eval (f : ParameterRing) (p : Params) : + (positiveAtom f).eval p = true ↔ 0 < parameterEval p f := by + simp [positiveAtom, SignFormula.eval, sign_eq_one_iff] + +@[simp] theorem nonnegativeAtom_eval (f : ParameterRing) (p : Params) : + (nonnegativeAtom f).eval p = true ↔ 0 ≤ parameterEval p f := by + simp only [nonnegativeAtom, SignFormula.eval, Bool.or_eq_true, decide_eq_true_eq] + change SignType.sign (parameterEval p f) = 0 ∨ SignType.sign (parameterEval p f) = 1 ↔ _ + rw [sign_eq_zero_iff, sign_eq_one_iff] + constructor + · rintro (h | h) <;> linarith + · intro h + rcases h.eq_or_lt with he | he + · exact Or.inl he.symm + · exact Or.inr he + +/-- The sign formula for the parameter domain `σ > 0`, `b ≥ 0`, `ρ² ≤ 1` together with the variance +gate (`domainFormula_iff`). -/ +noncomputable def domainFormula : SignFormula := + let a : ParameterRing := MvPolynomial.X (0 : Fin 5) + let b : ParameterRing := MvPolynomial.X (1 : Fin 5) + let rho : ParameterRing := MvPolynomial.X (2 : Fin 5) + let sigma : ParameterRing := MvPolynomial.X (4 : Fin 5) + .and (positiveAtom sigma) (.and (nonnegativeAtom b) (.and (nonnegativeAtom (1-rho^2)) + (.or (.and (.atom b .zero) (positiveAtom a)) + (.and (positiveAtom b) (.or (nonnegativeAtom a) + (positiveAtom (b^2*sigma^2*(1-rho^2)-a^2))))))) + +theorem domainFormula_iff (p : Params) : domainFormula.eval p = true ↔ + 0 < p.sigma ∧ 0 ≤ p.b ∧ 0 ≤ 1-p.rho^2 ∧ varianceGate p := by + have hnonneg (x : ℝ) : (x=0 ∨ 0 linarith + · intro h + rcases h.eq_or_lt with he | he + · exact Or.inl he.symm + · exact Or.inr he + simp only [domainFormula, positiveAtom, nonnegativeAtom, SignFormula.eval, + Bool.and_eq_true, Bool.or_eq_true, decide_eq_true_eq, + SignType.pos_eq_one, SignType.zero_eq_zero, sign_eq_one_iff, sign_eq_zero_iff, hnonneg] + simp [parameterEval, parameterValues, varianceGate, sub_pos] + +/-- The entire smooth positive-variance domain with nonnegative Durrleman +factor, represented as a finite Boolean combination of polynomial signs. -/ +noncomputable def fullCertificateFormula : SignFormula := .and domainFormula certificateFormula + +theorem fullCertificateFormula_iff (p : Params) : fullCertificateFormula.eval p = true ↔ + 0 < p.sigma ∧ 0 ≤ p.b ∧ 0 ≤ 1-p.rho^2 ∧ + (∀ k : ℝ, 0 < variance p k) ∧ (∀ k : ℝ, 0 ≤ durrleman p k) := by + simp only [fullCertificateFormula, SignFormula.eval, Bool.and_eq_true, domainFormula_iff] + constructor + · rintro ⟨⟨hs,hb,hr,hg⟩,hc⟩ + exact ⟨hs,hb,hr,(varianceGate_iff p hs hb hr).mp hg, + (certificateFormula_iff p hs hb hr hg).mp hc⟩ + · rintro ⟨hs,hb,hr,hw,hg⟩ + have hv := (varianceGate_iff p hs hb hr).mpr hw + exact ⟨⟨hs,hb,hr,hv⟩,(certificateFormula_iff p hs hb hr hv).mpr hg⟩ + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/ExtendedFormula.lean b/LeanPool/MathFin/Models/ModelFree/SVI/ExtendedFormula.lean new file mode 100644 index 0000000000..31fea41032 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/ExtendedFormula.lean @@ -0,0 +1,152 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.SigmaZeroCertificate +public import LeanPool.MathFin.Models.ModelFree.SVI.SigmaZeroConvexity + +/-! # The sign formula for every nonnegative scale + +Part of the SVI polynomial-sign certificate (#174). + +`extendedCertificateFormula` adds the zero-scale branch, two quadratic sign tests, to the smooth +formula. `extendedCertificateFormula_iff_bsSmile_convex`: it holds exactly when `σ ≥ 0`, `b ≥ 0`, +`ρ² ≤ 1`, the variance is positive, and the SVI-smiled Black–Scholes call is convex in strike. + +## Main definitions + +* `zeroAtom`: the sign formula "`f` is zero". +* `quadraticRayFormula`: a finite sign formula for a quadratic being nonnegative on a closed ray. +* `sigmaZeroBranchFormula`, `sigmaZeroFormula`: the sign formulas for one wing and for the + zero-scale slice `σ = 0`. +* `extendedCertificateFormula`: the smooth determinant branch together with the zero-scale + branch. + +## Main results + +* `zeroAtom_eval`, `quadraticRayFormula_eval`, `sigmaZeroBranchFormula_eval`: what each formula + evaluates to. +* `sigmaZeroFormula_eval`: `sigmaZeroFormula` holds iff `σ = 0`, `a > 0`, `b ≥ 0`, `1 - ρ² ≥ 0` and + `sigmaZeroCertificate p`. +* `sigmaZeroFormula_iff_bsSmile_convex`: `sigmaZeroFormula` holds iff `σ = 0`, `b ≥ 0`, + `1 - ρ² ≥ 0`, the variance is positive, and `bsSmile p` is convex on `(0, ∞)`. +* `extendedCertificateFormula_iff_bsSmile_convex`: `extendedCertificateFormula` holds iff + `σ ≥ 0`, `b ≥ 0`, `1 - ρ² ≥ 0`, the variance is positive, and `bsSmile p` is convex on + `(0, ∞)`. + +## References + +* [R. Martin, *A polynomial-sign certificate for butterfly-free raw SVI*][MartinButterflyFreeSVI] + +## Tags + +raw SVI, zero-scale branch, butterfly arbitrage, sign formula, convex call price, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI + +/-- The atom "`f` is zero". -/ +noncomputable def zeroAtom (f : ParameterRing) : SignFormula := .atom f .zero + +@[simp] theorem zeroAtom_eval (f : ParameterRing) (p : Params) : + (zeroAtom f).eval p = true ↔ parameterEval p f = 0 := by + simp [zeroAtom, SignFormula.eval, sign_eq_zero_iff] + +/-- Finite sign formula for a quadratic nonnegative on a closed ray. -/ +noncomputable def quadraticRayFormula (a u v z : ParameterRing) : SignFormula := + .and (nonnegativeAtom u) (.and (nonnegativeAtom (u*a^2+v*a+z)) + (.or (.and (zeroAtom u) (nonnegativeAtom v)) + (.and (positiveAtom u) (.or (nonnegativeAtom (v+2*u*a)) + (nonnegativeAtom (4*u*z-v^2)))))) + +theorem quadraticRayFormula_eval (a u v z : ParameterRing) (p : Params) : + (quadraticRayFormula a u v z).eval p = true ↔ + 0 ≤ parameterEval p u ∧ + 0 ≤ parameterEval p u * (parameterEval p a)^2 + + parameterEval p v * parameterEval p a + parameterEval p z ∧ + ((parameterEval p u = 0 ∧ 0 ≤ parameterEval p v) ∨ + (0 < parameterEval p u ∧ + (0 ≤ parameterEval p v + 2*parameterEval p u*parameterEval p a ∨ + 0 ≤ 4*parameterEval p u*parameterEval p z-(parameterEval p v)^2))) := by + simp only [quadraticRayFormula, SignFormula.eval, Bool.and_eq_true, + Bool.or_eq_true, nonnegativeAtom_eval, positiveAtom_eval, zeroAtom_eval, + map_add, map_mul, map_pow, map_sub, map_ofNat] + +/-- The sign formula for one wing of slope `s` at zero scale: its branch quadratic is nonnegative on +the ray `w ≥ a`. -/ +noncomputable def sigmaZeroBranchFormula (s : ParameterRing) : SignFormula := + let a : ParameterRing := MvPolynomial.X (0 : Fin 5) + let m : ParameterRing := MvPolynomial.X (3 : Fin 5) + quadraticRayFormula a (1-MvPolynomial.C (1/4 : ℝ)*s^2) + (2*(a-s*m)-s^2) ((a-s*m)^2) + +/-- The sign formula for the zero-scale slice: `σ = 0`, `b ≥ 0`, `ρ² ≤ 1`, `a > 0`, and both wing +conditions (`sigmaZeroFormula_eval`). -/ +noncomputable def sigmaZeroFormula : SignFormula := + let a : ParameterRing := MvPolynomial.X (0 : Fin 5) + let b : ParameterRing := MvPolynomial.X (1 : Fin 5) + let rho : ParameterRing := MvPolynomial.X (2 : Fin 5) + let sigma : ParameterRing := MvPolynomial.X (4 : Fin 5) + .and (zeroAtom sigma) (.and (positiveAtom a) (.and (nonnegativeAtom b) + (.and (nonnegativeAtom (1-rho^2)) + (.and (sigmaZeroBranchFormula (b*(rho-1))) + (sigmaZeroBranchFormula (b*(rho+1))))))) + +theorem sigmaZeroBranchFormula_eval (s : ParameterRing) (p : Params) : + (sigmaZeroBranchFormula s).eval p = true ↔ + sigmaZeroBranchCondition p (parameterEval p s) := by + rw [sigmaZeroBranchFormula, quadraticRayFormula_eval] + simp [sigmaZeroBranchCondition, parameterEval, parameterValues, div_eq_mul_inv, mul_comm] + +theorem sigmaZeroFormula_eval (p : Params) : sigmaZeroFormula.eval p = true ↔ + p.sigma = 0 ∧ 0 < p.a ∧ 0 ≤ p.b ∧ 0 ≤ 1-p.rho^2 ∧ sigmaZeroCertificate p := by + simp only [sigmaZeroFormula, SignFormula.eval, Bool.and_eq_true, + zeroAtom_eval, positiveAtom_eval, nonnegativeAtom_eval, sigmaZeroBranchFormula_eval] + simp [parameterEval, parameterValues, sigmaZeroCertificate, leftSlope, rightSlope] + +/-- Smooth determinant branch together with the piecewise-linear zero-scale branch. -/ +noncomputable def extendedCertificateFormula : SignFormula := + .or fullCertificateFormula sigmaZeroFormula + +theorem sigmaZeroFormula_iff_bsSmile_convex (p : Params) : + sigmaZeroFormula.eval p = true ↔ + p.sigma = 0 ∧ 0 ≤ p.b ∧ 0 ≤ 1-p.rho^2 ∧ + (∀ k : ℝ, 0 < variance p k) ∧ ConvexOn ℝ (Set.Ioi 0) (bsSmile p) := by + rw [sigmaZeroFormula_eval] + constructor + · rintro ⟨hs,ha,hb,hr,hc⟩ + have hw := (sigmaZero_variance_pos_iff p hs hb hr).mpr ha + exact ⟨hs,hb,hr,hw,(sigmaZero_bsSmile_convex_iff p hs hb hw).mpr + ((sigmaZeroCertificate_iff p hs hb hr ha).mp hc)⟩ + · rintro ⟨hs,hb,hr,hw,hc⟩ + have ha := (sigmaZero_variance_pos_iff p hs hb hr).mp hw + exact ⟨hs,ha,hb,hr,(sigmaZeroCertificate_iff p hs hb hr ha).mpr + ((sigmaZero_bsSmile_convex_iff p hs hb hw).mp hc)⟩ + +/-- Complete nonnegative-scale SVI domain, including the kinked zero-scale +case, as an explicit finite Boolean formula of parameter-polynomial signs. -/ +theorem extendedCertificateFormula_iff_bsSmile_convex (p : Params) : + extendedCertificateFormula.eval p = true ↔ + 0 ≤ p.sigma ∧ 0 ≤ p.b ∧ 0 ≤ 1-p.rho^2 ∧ + (∀ k : ℝ, 0 < variance p k) ∧ ConvexOn ℝ (Set.Ioi 0) (bsSmile p) := by + simp only [extendedCertificateFormula, SignFormula.eval, Bool.or_eq_true, + fullCertificateFormula_iff_bsSmile_convex, sigmaZeroFormula_iff_bsSmile_convex] + constructor + · rintro (⟨hs,h⟩ | ⟨hs,h⟩) + · exact ⟨hs.le,h⟩ + · exact ⟨by rw [hs],h⟩ + · rintro ⟨hs,h⟩ + rcases eq_or_lt_of_le hs with hz | hp + · exact Or.inr ⟨hz.symm,h⟩ + · exact Or.inl ⟨hp,h⟩ + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/FiniteCertificate.lean b/LeanPool/MathFin/Models/ModelFree/SVI/FiniteCertificate.lean new file mode 100644 index 0000000000..9ac43bddf3 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/FiniteCertificate.lean @@ -0,0 +1,103 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.DegreeProgram +public import LeanPool.MathFin.Models.ModelFree.SVI.SignatureProgram +public import LeanPool.MathFin.Models.ModelFree.SVI.MatrixCertificate + +/-! # The certificate as a fixed finite program + +Part of the SVI polynomial-sign certificate (#174). + +`certificateProgram` branches only on signs of parameter polynomials, and `certificateFormula` +is its expansion into a `SignFormula`. For `σ > 0`, `b ≥ 0`, `ρ² ≤ 1` and under the variance gate, +it is equivalent to `g(k) ≥ 0` for every `k` (`certificateFormula_iff`). + +## Main definitions + +* `certificateProgram`: a fixed finite sign program that branches only on signs of parameter + polynomials. +* `certificateFormula`: the expansion of `certificateProgram` into a `SignFormula`. + +## Main results + +* `certificateProgram_eval`: `certificateProgram` evaluates at `p` to + `decide (matrixCertificate (polynomial p))`. +* `certificateFormula_iff`: for `σ > 0`, `b ≥ 0`, `1 - ρ² ≥ 0` and `varianceGate p`, + `certificateFormula` holds iff `durrleman p k ≥ 0` for every `k`. + +## Tags + +sign program, Durrleman condition, raw SVI, certificate formula, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +open scoped Classical in +/-- A fixed finite program. All branching uses polynomial signs; no roots, +minima, eigenvalues, or real quantifiers occur in this definition. -/ +noncomputable def certificateProgram : SignProgram Bool := + (degreeProgram 10).bind fun ds ↦ + if ds.1 = 0 then .pure (decide (ds.2 ≠ .neg)) + else if ds.2 = .pos then + (signQuery (universalPolynomial.coeff 0)).bind fun s ↦ + if s = .neg then .pure false + else (countProgram (ds.1-1)).bind fun z ↦ .pure (decide (z=0)) + else .pure false + +open scoped Classical in +theorem certificateProgram_eval (p : Params) : + certificateProgram.eval p = decide (matrixCertificate (polynomial p)) := by + classical + simp only [certificateProgram, SignProgram.eval_bind, + degreeProgram_eval p 10 (degree_le_ten p)] + unfold matrixCertificate + by_cases hd : (polynomial p).natDegree = 0 + · simp only [hd, ↓reduceIte, SignProgram.eval] + have hc : (polynomial p).leadingCoeff = (polynomial p).coeff 0 := by + rw [leadingCoeff, hd] + simp only [hc, SignType.neg_eq_neg_one] + have hiff : (SignType.sign ((polynomial p).coeff 0) ≠ -1) ↔ + 0 ≤ (polynomial p).coeff 0 := (not_congr sign_eq_neg_one_iff).trans not_lt + simp only [hiff] + · simp only [hd, ↓reduceIte] + by_cases hl : SignType.sign (polynomial p).leadingCoeff = .pos + · have hlp : 0 < (polynomial p).leadingCoeff := sign_eq_one_iff.mp hl + simp only [hl, ↓reduceIte, SignProgram.eval_bind, signQuery_eval, universalCoefficient_eval] + by_cases h0 : SignType.sign ((polynomial p).coeff 0) = .neg + · have h0n : (polynomial p).coeff 0 < 0 := sign_eq_neg_one_iff.mp h0 + simp [h0, SignProgram.eval, not_le.mpr h0n] + · have h0p : 0 ≤ (polynomial p).coeff 0 := by + by_contra h + exact h0 (sign_eq_neg_one_iff.mpr (lt_of_not_ge h)) + simp only [h0, ↓reduceIte, SignProgram.eval_bind, ← natDegree_derivative, + countProgram_eval, SignProgram.eval] + simp [hlp, h0p] + · have hln : ¬ 0 < (polynomial p).leadingCoeff := by + intro h; exact hl (sign_eq_one_iff.mpr h) + rw [ite_eq_right hl] + simp [SignProgram.eval, hln] + +open scoped Classical in +/-- The expanded finite Boolean formula, kept compact as a structural definition. -/ +noncomputable def certificateFormula : SignFormula := certificateProgram.toFormula + +open scoped Classical in +theorem certificateFormula_iff (p : Params) (hs : 0 < p.sigma) + (hb : 0 ≤ p.b) (hr : 0 ≤ 1 - p.rho ^ 2) (hg : varianceGate p) : + certificateFormula.eval p = true ↔ ∀ k : ℝ, 0 ≤ durrleman p k := by + rw [certificateFormula, SignProgram.eval_toFormula, certificateProgram_eval, decide_eq_true_eq] + exact svi_matrixCertificate_iff p hs hb hr hg + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/HermiteIdentity.lean b/LeanPool/MathFin/Models/ModelFree/SVI/HermiteIdentity.lean new file mode 100644 index 0000000000..93fe7cc865 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/HermiteIdentity.lean @@ -0,0 +1,117 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.AssociatedTrace +public import LeanPool.MathFin.Models.ModelFree.SVI.RealIrreducibles +public import LeanPool.MathFin.Models.ModelFree.SVI.RealRootSignature +public import LeanPool.MathFin.Models.ModelFree.SVI.TraceSignature +public import LeanPool.MathFin.Models.ModelFree.SVI.QuotientProduct +public import Mathlib.RingTheory.UniqueFactorizationDomain.Multiplicative + +/-! # Hermite's trace-form identity + +Part of the SVI polynomial-sign certificate (#174). + +For `f ≠ 0`, the signature of the weighted trace form on `ℝ[X]/(f)` is the sum of `sign (q c)` +over the distinct real roots `c` of `f` (`weightedTraceForm_signature`), with no squarefreeness +assumed. `hermite_signature` is the same identity for the sign-variation test of the Hermite matrix +`hermite f q f.natDegree`. + +## Main results + +* `weightedTraceForm_signature`: for `f ≠ 0`, the signature of the weighted trace form on + `ℝ[X]/(f)` is `∑ c ∈ f.roots.toFinset, sign (q.eval c)`, the sum over distinct real roots. +* `hermite_signature`: for `f ≠ 0`, `signatureTest (hermite f q f.natDegree)` equals the same sum. + +## Tags + +Hermite quadratic form, real root counting, trace form signature, Sylvester inertia, SVI, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +private theorem unit_trace_signature (f q : ℝ[X]) (hf : IsUnit f) : + formSignature (weightedTraceForm f q).toQuadraticMap = 0 := by + have hf0 := hf.ne_zero + let : FiniteDimensional ℝ (AdjoinRoot f) := + Module.Finite.of_basis (AdjoinRoot.powerBasis hf0).basis + have hd : Module.finrank ℝ (AdjoinRoot f) = 0 := by + rw [(AdjoinRoot.powerBasis hf0).finrank, AdjoinRoot.powerBasis_dim] + exact natDegree_eq_zero_of_isUnit hf + have hp := sigPos_le_finrank (weightedTraceForm f q).toQuadraticMap + have hn := sigPos_le_finrank (-(weightedTraceForm f q).toQuadraticMap) + rw [hd] at hp hn + simp [formSignature, ← sigPos_neg, Nat.eq_zero_of_le_zero hp, Nat.eq_zero_of_le_zero hn] + +/-- A unit polynomial has no roots. -/ +theorem roots_eq_zero_of_isUnit (f : ℝ[X]) (hf : IsUnit f) : f.roots = 0 := by + apply Multiset.card_eq_zero.mp + exact Nat.eq_zero_of_le_zero ((card_roots' f).trans_eq (natDegree_eq_zero_of_isUnit hf)) + +private theorem positiveQuadratic_roots (a b : ℝ) (hb : b ≠ 0) : + (positiveQuadratic a b).roots = 0 := by + apply Multiset.eq_zero_iff_forall_notMem.mpr + intro c hc + have h := (mem_roots (by intro h; have := positiveQuadratic_degree a b; simp [h] at this)).mp hc + have he : (c-a)^2+b^2 = 0 := by simpa [IsRoot, positiveQuadratic] using h + nlinarith [sq_nonneg (c-a), sq_pos_of_ne_zero hb] + +/-- Hermite's trace-form identity, with distinct real roots and without any +squarefreeness hypothesis. -/ +theorem weightedTraceForm_signature (f q : ℝ[X]) (hf : f ≠ 0) : + formSignature (weightedTraceForm f q).toQuadraticMap = + ∑ c ∈ f.roots.toFinset, sign (q.eval c) := by + classical + induction f using UniqueFactorizationMonoid.induction_on_coprime with + | h0 => exact (hf rfl).elim + | @h1 f hu => simp [unit_trace_signature f q hu, roots_eq_zero_of_isUnit f hu] + | @hpr p r hp => + by_cases hr : r = 0 + · subst r + simp only [pow_zero, roots_one] + exact unit_trace_signature 1 q isUnit_one + have hrp : 0 < r := Nat.pos_of_ne_zero hr + have ha := (associated_normalize p).pow_pow (n := r) + rw [weightedTraceForm_associated_signature _ _ q ha, ha.roots_eq] + have hi : Irreducible (normalize p) := + (associated_normalize p).irreducible_iff.mp hp.irreducible + rcases monic_real_irreducible_cases (normalize p) (monic_normalize hp.ne_zero) hi with + ⟨c, hc⟩ | ⟨a,b,hb,hp⟩ + · rw [hc, weightedTraceForm_realRoot_signature c r hrp q] + simp [roots_pow, roots_X_sub_C, hr] + · rw [hp, weightedTraceForm_quadratic_signature a b hb r hrp q] + simp [roots_pow, positiveQuadratic_roots a b hb] + | @hcp f g hc ihf ihg => + have hf0 : f ≠ 0 := left_ne_zero_of_mul hf + have hg0 : g ≠ 0 := right_ne_zero_of_mul hf + rw [weightedTraceForm_prod_signature f g q hf0 hg0 hc.isCoprime, ihf hf0, ihg hg0, + roots_mul hf, Multiset.toFinset_add] + symm + apply Finset.sum_union + apply Finset.disjoint_left.mpr + intro c hcf hcg + have hcf := (mem_roots hf0).mp (Multiset.mem_toFinset.mp hcf) + have hcg := (mem_roots hg0).mp (Multiset.mem_toFinset.mp hcg) + obtain ⟨u,v,huv⟩ := hc.isCoprime + have hh := congrArg (eval c) huv + simp [hcf.eq_zero, hcg.eq_zero] at hh + +/-- Concrete companion-matrix form of the distinct-root identity. -/ +theorem hermite_signature (f q : ℝ[X]) (hf : f ≠ 0) : + signatureTest (hermite f q f.natDegree) = + ∑ c ∈ f.roots.toFinset, sign (q.eval c) := by + rw [hermite_signature_eq_trace_signature f q hf, weightedTraceForm_signature f q hf] + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/ImaginaryTraceSignature.lean b/LeanPool/MathFin/Models/ModelFree/SVI/ImaginaryTraceSignature.lean new file mode 100644 index 0000000000..c915b9573e --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/ImaginaryTraceSignature.lean @@ -0,0 +1,87 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.TraceForm +public import LeanPool.MathFin.Models.ModelFree.SVI.RankOneSignature + +/-! # A square root of −1 forces zero signature + +Part of the SVI polynomial-sign certificate (#174). + +A quadratic form equivalent to its negative has signature zero, so a quotient component +containing a square root of `−1` contributes nothing to the trace-form signature. + +## Main definitions + +* `imaginaryMulEquiv`: multiplication by `u` with `u² = -1`, as a real-linear equivalence of `A`. + +## Main results + +* `formSignature_eq_zero_of_equivalent_neg`: a real quadratic form equivalent to its negative has + signature `0`. +* `weightedTraceForm_signature_zero_of_imaginary`: if `AdjoinRoot f` contains `u` with + `u² = -1`, the signature of `weightedTraceForm f q` is `0`. + +## Tags + +trace form signature, complex roots, hyperbolic quadratic form, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI + +/-- Multiplication by a square root of -1 is an invertible real-linear map. -/ +noncomputable def imaginaryMulEquiv {A : Type*} [CommRing A] [Algebra ℝ A] + (u : A) (hu : u ^ 2 = -1) : A ≃ₗ[ℝ] A := + { Algebra.lmul ℝ A u with + invFun := fun x ↦ -u*x + left_inv := by + intro x + change -u*(u*x) = x + calc + -u*(u*x) = -(u^2)*x := by ring + _ = x := by rw [hu]; ring + right_inv := by + intro x + change u*(-u*x) = x + calc + u*(-u*x) = -(u^2)*x := by ring + _ = x := by rw [hu]; ring } + +theorem formSignature_eq_zero_of_equivalent_neg {V : Type*} + [AddCommGroup V] [Module ℝ V] (Q : QuadraticForm ℝ V) + (h : QuadraticMap.Equivalent Q (-Q)) : formSignature Q = 0 := by + have hh := h.sigPos_eq + rw [sigPos_neg] at hh + unfold formSignature + exact sub_eq_zero.mpr (congrArg (fun n : ℕ ↦ (n : ℤ)) hh) + +/-- Any quotient component containing a square root of -1 has zero trace-form +signature. Multiplication by that root exchanges positive and negative +subspaces, including when nilpotents make the form degenerate. -/ +theorem weightedTraceForm_signature_zero_of_imaginary (f q : Polynomial ℝ) + (u : AdjoinRoot f) (hu : u ^ 2 = -1) : + formSignature (weightedTraceForm f q).toQuadraticMap = 0 := by + apply formSignature_eq_zero_of_equivalent_neg + refine ⟨{ imaginaryMulEquiv u hu with map_app' := ?_ }⟩ + intro x + change -((weightedTraceForm f q).toQuadraticMap (u*x)) = + (weightedTraceForm f q).toQuadraticMap x + simp only [LinearMap.BilinMap.toQuadraticMap_apply, weightedTraceForm_apply] + have he : (Polynomial.aeval (AdjoinRoot.root f) q)*(u*x)*(u*x) = + -((Polynomial.aeval (AdjoinRoot.root f) q)*x*x) := by + calc + _ = u^2*((Polynomial.aeval (AdjoinRoot.root f) q)*x*x) := by ring + _ = _ := by rw [hu]; ring + rw [he, map_neg, neg_neg] + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/MarketRealisation.lean b/LeanPool/MathFin/Models/ModelFree/SVI/MarketRealisation.lean new file mode 100644 index 0000000000..70a588239c --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/MarketRealisation.lean @@ -0,0 +1,78 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.MarketCallPrice +public import LeanPool.MathFin.Models.ModelFree.RoperConverse +public import LeanPool.MathFin.Models.ModelFree.SVI.TailCondition + +/-! +# The SVI smile and the market: butterfly-free exactly when realised + +The static fundamental theorem meets the SVI sign formula in both directions. Forward +(`Market.IsPricingMeasure.isNormalizedCallPrice`): if the calls of a market with a pricing +measure, in units of the forward, are the SVI-smiled Black prices, and the parameters are +admissible, then `butterflyFreeFormula` holds. Converse (`exists_market_of_isNormalizedCallPrice`, +Roper's converse): a butterfly-free slice is the call price function, at maturity one, of a market +with unit numéraire, a nonnegative asset of forward one and a pricing measure. + +## Main results + +* `SVI.butterflyFreeFormula_of_isPricingMeasure`: a pricing measure whose normalised calls are the + SVI smile forces the finite sign formula `butterflyFreeFormula`. +* `SVI.exists_market_of_butterflyFreeFormula`: a butterfly-free slice is the call price function + of a market. + +## References + +* [Gatheral and Jacquier, *Arbitrage-free SVI volatility surfaces*][GatheralJacquier2014], Lemma 2.2 +* [Roper, *Arbitrage free implied volatility surfaces*][Roper2010], Theorem 2.1 + +## Tags + +SVI smile, pricing measure, butterfly arbitrage, no static arbitrage, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +open MeasureTheory MathFin.Contracts +open scoped NNReal + +namespace MathFin.SVI + +/-- **A market that prices the SVI smile makes the slice butterfly-free.** In a market with unit +numéraire and a positive asset, priced at `T` by `Q`, if the calls at the strikes `k F`, in units +of the forward `F`, have the SVI-smiled Black price at every `k > 0`, and the parameters satisfy +`σ ≥ 0`, `b ≥ 0`, `ρ² ≤ 1` with positive variance everywhere, then `butterflyFreeFormula` holds: +the call price function is convex and satisfies the tail condition. -/ +theorem butterflyFreeFormula_of_isPricingMeasure {Ω : Type*} {mΩ : MeasurableSpace Ω} + {M : Market Unit Ω} {T : ℝ≥0} {Q : Measure Ω} {p : Params} + (hp : 0 ≤ p.sigma ∧ 0 ≤ p.b ∧ 0 ≤ 1 - p.rho ^ 2 ∧ ∀ k, 0 < variance p k) + (hQ : M.IsPricingMeasure T Q) (hN : ∀ t ω, M.numeraire t ω = 1) + (hpos : ∀ ω, 0 < M.asset () T ω) {F : ℝ} (hF : F = M.price Q (.pay T (.obs () T))) + (hsmile : ∀ k > 0, M.price Q (europeanCall (k * F) T) / F = bsSmile p k) : + butterflyFreeFormula.eval p = true := + (butterflyFreeFormula_iff_isNormalizedCallPrice p).2 + ⟨hp.1, hp.2.1, hp.2.2.1, hp.2.2.2, + (hQ.isNormalizedCallPrice hN hpos hF).of_eqOn fun k hk ↦ hsmile k hk⟩ + +/-- **A butterfly-free SVI slice is the call price function of a market.** If the raw SVI +parameters satisfy `butterflyFreeFormula`, there is a market with unit numéraire, a nonnegative +asset of forward one at maturity one and a pricing measure, in which the call at every strike +`k > 0` is worth the SVI-smiled Black call `bsSmile p k`: the sign formula makes `bsSmile p` a +normalised call price function (`butterflyFreeFormula_iff_isNormalizedCallPrice`), and Roper's +converse realises it. -/ +theorem exists_market_of_butterflyFreeFormula {p : Params} + (h : butterflyFreeFormula.eval p = true) : + ∃ (M : Market Unit ℝ) (Q : Measure ℝ), (∀ t ω, M.numeraire t ω = 1) ∧ + (∀ ω, 0 ≤ M.asset () 1 ω) ∧ M.IsPricingMeasure 1 Q ∧ + M.price Q (.pay 1 (.obs () 1)) = 1 ∧ ∀ k > 0, M.price Q (europeanCall k 1) = bsSmile p k := + exists_market_of_isNormalizedCallPrice + ((butterflyFreeFormula_iff_isNormalizedCallPrice p).1 h).2.2.2.2 + +end MathFin.SVI diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/Matrices.lean b/LeanPool/MathFin/Models/ModelFree/SVI/Matrices.lean new file mode 100644 index 0000000000..dc3aa581a4 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/Matrices.lean @@ -0,0 +1,91 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Polynomial.RuleOfSigns +public import Mathlib.LinearAlgebra.Matrix.Charpoly.Basic +public import Mathlib.Algebra.Polynomial.Derivative +public import Mathlib.Basic.Real.Basic + +/-! # The certificate matrices + +Part of the SVI polynomial-sign certificate (#174). + +Explicit denominator-free matrix constructions. Their correctness as a +root-counting certificate is proved in MatrixCertificate.lean. + +## Main definitions + +* `scaledCompanion`: `ℓ` times the companion matrix of `f / ℓ`, with `ℓ = leadingCoeff f`. +* `clearedHermite`: the Hermite matrix of `f` with weight `q` built from `scaledCompanion` and + powers of the leading coefficient, so that no division by it occurs. +* `signatureTest`: the sign variations of `M.charpoly` minus those of `M.charpoly.comp (-X)`. +* `certificateMatrices`: the four cleared Hermite matrices of `P'` with weights `X²P²`, `XP²`, + `X²P`, `XP`. +* `matrixCountFour`: the signed combination of the four signature tests. + +## Main results + +* `clearedHermite_symmetric`: `clearedHermite f q n` is symmetric. +* `exponent_bound`: for `n ≤ 9`, `i, j < n` and `r ≤ 22`, `i + j + r ≤ 38`. + +## Tags + +Hermite matrices, root counting certificate, denominator-free, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +/-- ℓ times the companion matrix of f/ℓ, where ℓ = leadingCoeff f. +Intended dimension: n = natDegree f, positive. -/ +noncomputable def scaledCompanion (f : ℝ[X]) (n : ℕ) : Matrix (Fin n) (Fin n) ℝ := + fun i j ↦ if j.val + 1 = n then -f.coeff i.val + else if i.val = j.val + 1 then f.leadingCoeff else 0 + +/-- The finite-support version of formula (17). Correct denominator clearing +requires i+j+r ≤ 38 on q.support, proved below for the SVI size bounds. -/ +noncomputable def clearedHermite (f q : ℝ[X]) (n : ℕ) : Matrix (Fin n) (Fin n) ℝ := + fun i j ↦ ∑ r ∈ q.support, + q.coeff r * f.leadingCoeff ^ (38 - (i.val + j.val + r)) * + Matrix.trace ((scaledCompanion f n) ^ (i.val + j.val + r)) + +theorem clearedHermite_symmetric (f q : ℝ[X]) (n : ℕ) : + (clearedHermite f q n).IsSymm := by + ext i j + simp [clearedHermite, Matrix.transpose_apply, Nat.add_comm] + +theorem exponent_bound (n : ℕ) (hn : n ≤ 9) (i j : Fin n) (r : ℕ) (hr : r ≤ 22) : + i.val + j.val + r ≤ 38 := by omega + +/-- Characteristic coefficient sign rule. Its identification with spectral +signature, including singular matrices, is proved in MatrixSignature.lean. -/ +noncomputable def signatureTest {n : ℕ} (M : Matrix (Fin n) (Fin n) ℝ) : ℤ := + (M.charpoly.signVariations : ℤ) - ((M.charpoly.comp (-X)).signVariations : ℤ) + +/-- The four denominator-cleared Hermite matrices of `P'` with weights `X²P²`, `XP²`, `X²P`, `XP`. +-/ +noncomputable def certificateMatrices (P : ℝ[X]) : Fin 4 → + Matrix (Fin P.derivative.natDegree) (Fin P.derivative.natDegree) ℝ := + ![clearedHermite P.derivative (X^2*P^2) P.derivative.natDegree, + clearedHermite P.derivative (X*P^2) P.derivative.natDegree, + clearedHermite P.derivative (X^2*P) P.derivative.natDegree, + clearedHermite P.derivative (X*P) P.derivative.natDegree] + +/-- The signed combination of the four signature tests, which is four times `badCriticalCount` for a +nonconstant polynomial of degree at most ten (`matrixCountFour_eq`). -/ +noncomputable def matrixCountFour (P : ℝ[X]) : ℤ := + signatureTest (certificateMatrices P 0) + signatureTest (certificateMatrices P 1) - + signatureTest (certificateMatrices P 2) - signatureTest (certificateMatrices P 3) + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/MatrixCertificate.lean b/LeanPool/MathFin/Models/ModelFree/SVI/MatrixCertificate.lean new file mode 100644 index 0000000000..7856198585 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/MatrixCertificate.lean @@ -0,0 +1,88 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.HermiteIdentity +public import LeanPool.MathFin.Models.ModelFree.SVI.PolynomialCertificate + +/-! # The determinant certificate + +Part of the SVI polynomial-sign certificate (#174). + +For a nonconstant polynomial of degree at most ten, the signature combination of four explicit +denominator-free matrices equals four times the number of distinct positive critical points with +a negative value (`matrixCountFour_eq`). `matrixCertificate`, a root-free predicate covering every +degree branch, is equivalent to nonnegativity on `(0, ∞)` for degree at most ten +(`matrixCertificate_iff`). + +## Main definitions + +* `matrixCertificate`: for a real polynomial `P`, `0 ≤ P.coeff 0` if `P` is constant, and + otherwise `0 < P.leadingCoeff`, `0 ≤ P.coeff 0` and `matrixCountFour P = 0`. + +## Main results + +* `matrixCountFour_eq`: for `natDegree ≤ 10` and `natDegree ≠ 0`, `matrixCountFour P` equals + `4 * badCriticalCount P`. +* `matrixCertificate_iff_criticalCertificate`: for `natDegree ≤ 10`, `matrixCertificate P` iff + `criticalCertificate P`. +* `matrixCertificate_iff`: for `natDegree ≤ 10`, `matrixCertificate P` iff `P.eval t ≥ 0` for + every `t > 0`. +* `svi_matrixCertificate_iff`: for `σ > 0`, `b ≥ 0`, `1 - ρ² ≥ 0` and `varianceGate p`, + `matrixCertificate (polynomial p)` iff `durrleman p k ≥ 0` for every `k`. + +## Tags + +determinant certificate, critical point count, Hermite matrix, positivity on half-line, SVI, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +/-- The four explicit, denominator-free matrices count exactly the forbidden +positive critical points, including all multiplicity and tangency cases. -/ +theorem matrixCountFour_eq (P : ℝ[X]) (hd : P.natDegree ≤ 10) + (hn : P.natDegree ≠ 0) : matrixCountFour P = 4 * (badCriticalCount P : ℤ) := by + have hf : P.derivative ≠ 0 := derivative_ne_zero.mpr hn + unfold matrixCountFour + simp_rw [certificateMatrix_signature P hd hn, hermite_signature _ _ hf] + simpa [tarskiQuery, criticalRoots, badCriticalCount] using + four_query_count (criticalRoots P) P.eval + +/-- A root-free determinant predicate for all degree branches. For degree one +the matrices are empty and their signature combination is automatically zero. -/ +noncomputable def matrixCertificate (P : ℝ[X]) : Prop := + if P.natDegree = 0 then 0 ≤ P.coeff 0 + else 0 < P.leadingCoeff ∧ 0 ≤ P.coeff 0 ∧ matrixCountFour P = 0 + +theorem matrixCertificate_iff_criticalCertificate (P : ℝ[X]) (hd : P.natDegree ≤ 10) : + matrixCertificate P ↔ criticalCertificate P := by + unfold matrixCertificate criticalCertificate + split_ifs with hn + · rfl + · rw [matrixCountFour_eq P hd hn, coeff_zero_eq_eval_zero] + simp only [mul_eq_zero, OfNat.ofNat_ne_zero, false_or, Int.natCast_eq_zero] + +theorem matrixCertificate_iff (P : ℝ[X]) (hd : P.natDegree ≤ 10) : + matrixCertificate P ↔ ∀ t : ℝ, 0 < t → 0 ≤ P.eval t := by + rw [matrixCertificate_iff_criticalCertificate P hd, criticalCertificate_iff] + +/-- The full boundary-safe determinant certificate for the smooth, +positive-variance SVI Durrleman condition. -/ +theorem svi_matrixCertificate_iff (p : Params) (hs : 0 < p.sigma) + (hb : 0 ≤ p.b) (hr : 0 ≤ 1 - p.rho ^ 2) (hg : varianceGate p) : + matrixCertificate (polynomial p) ↔ ∀ k : ℝ, 0 ≤ durrleman p k := by + rw [matrixCertificate_iff_criticalCertificate _ (degree_le_ten p)] + exact svi_criticalCertificate_iff p hs hb hr hg + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/MatrixSignature.lean b/LeanPool/MathFin/Models/ModelFree/SVI/MatrixSignature.lean new file mode 100644 index 0000000000..3077c68bcb --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/MatrixSignature.lean @@ -0,0 +1,144 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.Matrices +public import LeanPool.MathFin.Models.ModelFree.SVI.SignVariations +public import Mathlib.LinearAlgebra.QuadraticForm.Signature + +/-! # Signature of a symmetric matrix from its characteristic polynomial + +Part of the SVI polynomial-sign certificate (#174). + +The sign variations of the characteristic coefficients compute the inertia signature of a real +symmetric matrix (`signatureTest_eq_matrixSignature`), and a positive scalar factor does not +change the test. + +## Main definitions + +* `matrixSignature`: the signature `sigPos - sigNeg` of the quadratic form of a real matrix. + +## Main results + +* `signatureTest_eq_matrixSignature`: for a symmetric real matrix `M`, `signatureTest M` equals + `matrixSignature M`, singular matrices included. +* `signatureTest_smul_pos`: for symmetric `M` and `c > 0`, `signatureTest (c • M)` equals + `signatureTest M`. + +## Tags + +matrix inertia, Descartes rule of signs, characteristic polynomial, symmetric matrix signature, SVI, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Matrix Polynomial + +/-- The signature `sigPos − sigNeg` of the quadratic form of a matrix. -/ +noncomputable def matrixSignature {n : ℕ} (M : Matrix (Fin n) (Fin n) ℝ) : ℤ := + (sigPos M.toQuadraticForm' : ℤ) - (sigNeg M.toQuadraticForm' : ℤ) + +/-- The quadratic form of a matrix evaluates as `x ⬝ᵥ M *ᵥ x`. -/ +theorem toQuadraticForm'_apply {n : ℕ} (M : Matrix (Fin n) (Fin n) ℝ) (x : Fin n → ℝ) : + M.toQuadraticForm' x = dotProduct x (M *ᵥ x) := by + simp [Matrix.toQuadraticForm', Matrix.toLinearMap₂'_apply'] + +/-- The quadratic form of a diagonal matrix is the weighted sum of squares. -/ +theorem toQuadraticForm'_diagonal {n : ℕ} (w : Fin n → ℝ) : + (diagonal w).toQuadraticForm' = QuadraticMap.weightedSumSquares ℝ w := by + ext x + simp only [toQuadraticForm'_apply, dotProduct, mulVec_diagonal, + QuadraticMap.weightedSumSquares_apply, smul_eq_mul] + apply Finset.sum_congr rfl + intro i hi + ring + +/-- The quadratic form of `Uᴴ * M * U` is that of `M` composed with `U`. -/ +theorem toQuadraticForm'_conj_unitary {n : ℕ} (M : Matrix (Fin n) (Fin n) ℝ) + (U : Matrix.unitaryGroup (Fin n) ℝ) : + ((star (U : Matrix (Fin n) (Fin n) ℝ)) * M * (U : Matrix (Fin n) (Fin n) ℝ)).toQuadraticForm' = + M.toQuadraticForm'.comp ((Matrix.UnitaryGroup.toLinearEquiv U).toLinearMap) := by + ext x + simp only [QuadraticMap.comp_apply, toQuadraticForm'_apply] + change dotProduct x + ((star (U : Matrix (Fin n) (Fin n) ℝ) * M * (U : Matrix (Fin n) (Fin n) ℝ)) *ᵥ x) = + dotProduct ((U : Matrix (Fin n) (Fin n) ℝ) *ᵥ x) + (M *ᵥ ((U : Matrix (Fin n) (Fin n) ℝ) *ᵥ x)) + rw [← mulVec_mulVec, ← mulVec_mulVec, dotProduct_mulVec] + change dotProduct (vecMul x (U : Matrix (Fin n) (Fin n) ℝ).conjTranspose) _ = _ + rw [vecMul_conjTranspose] + simp + +/-- Characteristic sign variations compute the inertia signature of the +associated real quadratic form, even for singular matrices. -/ +theorem signatureTest_eq_matrixSignature {n : ℕ} (M : Matrix (Fin n) (Fin n) ℝ) + (hM : M.IsSymm) : signatureTest M = matrixSignature M := by + have hh : M.IsHermitian := Matrix.isHermitian_iff_isSymm.mpr hM + have heq : (diagonal hh.eigenvalues).toQuadraticForm' = + M.toQuadraticForm'.comp + (Matrix.UnitaryGroup.toLinearEquiv hh.eigenvectorUnitary).toLinearMap := by + rw [← toQuadraticForm'_conj_unitary] + have hdiag := hh.conjStarAlgAut_star_eigenvectorUnitary + simpa [Unitary.conjStarAlgAut_star_apply, Function.comp_def] using + congrArg Matrix.toQuadraticForm' hdiag.symm + have he : QuadraticMap.Equivalent M.toQuadraticForm' + (QuadraticMap.weightedSumSquares ℝ hh.eigenvalues) := by + rw [← toQuadraticForm'_diagonal, heq] + exact ⟨QuadraticMap.isometryEquivOfCompLinearEquiv _ _⟩ + unfold signatureTest matrixSignature + rw [signatureTest_eq_root_counts M hM, he.sigPos_eq, he.sigNeg_eq, + QuadraticForm.sigPos_weightedSumSquares, QuadraticForm.sigNeg_weightedSumSquares, + hh.roots_charpoly_eq_eigenvalues] + simp only [Multiset.countP_map, RCLike.ofReal_real_eq_id, Function.comp_def] + simp only [id_eq, ← Finset.filter_val, ← Finset.card_def, + Set.ncard_eq_toFinset_card' , Set.toFinset_ofPred] + +/-- A positive scalar multiple of a quadratic form has the same positive index. -/ +theorem sigPos_smul_of_pos {n : ℕ} (Q : QuadraticForm ℝ (Fin n → ℝ)) + (c : ℝ) (hc : 0 < c) : sigPos (c • Q) = sigPos Q := by + have hpos (V : Submodule ℝ (Fin n → ℝ)) : + ((c • Q).restrict V).PosDef ↔ (Q.restrict V).PosDef := by + change (∀ x : V, x ≠ 0 → 0 < c * Q x) ↔ (∀ x : V, x ≠ 0 → 0 < Q x) + simp only [mul_pos_iff_of_pos_left hc] + apply le_antisymm + · obtain ⟨V, hv, hp⟩ := exists_finrank_eq_sigPos_and_posDef (c • Q) + rw [← hv] + exact le_sigPos_of_posDef Q ((hpos V).mp hp) + · obtain ⟨V, hv, hp⟩ := exists_finrank_eq_sigPos_and_posDef Q + rw [← hv] + exact le_sigPos_of_posDef (c • Q) ((hpos V).mpr hp) + +/-- A positive scalar multiple of a quadratic form has the same negative index. -/ +theorem sigNeg_smul_of_pos {n : ℕ} (Q : QuadraticForm ℝ (Fin n → ℝ)) + (c : ℝ) (hc : 0 < c) : sigNeg (c • Q) = sigNeg Q := by + have he : -(c • Q) = c • (-Q) := by + ext x + simp + rw [← sigPos_neg, he, sigPos_smul_of_pos _ c hc, sigPos_neg] + +/-- The quadratic form of a scalar multiple of a matrix is the scalar multiple. -/ +theorem toQuadraticForm'_smul {n : ℕ} (M : Matrix (Fin n) (Fin n) ℝ) (c : ℝ) : + (c • M).toQuadraticForm' = c • M.toQuadraticForm' := by + ext x + simp [toQuadraticForm'_apply, Matrix.smul_mulVec, dotProduct_smul] + +/-- A positive common denominator does not change the sign certificate. -/ +theorem signatureTest_smul_pos {n : ℕ} (M : Matrix (Fin n) (Fin n) ℝ) + (hM : M.IsSymm) (c : ℝ) (hc : 0 < c) : signatureTest (c • M) = signatureTest M := by + have hcs : (c • M).IsSymm := by + ext i j + simpa using congrArg (c * ·) (congrFun (congrFun hM i) j) + rw [signatureTest_eq_matrixSignature _ hcs, signatureTest_eq_matrixSignature _ hM] + unfold matrixSignature + rw [toQuadraticForm'_smul, sigPos_smul_of_pos _ c hc, sigNeg_smul_of_pos _ c hc] + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/NilpotentSquareRoot.lean b/LeanPool/MathFin/Models/ModelFree/SVI/NilpotentSquareRoot.lean new file mode 100644 index 0000000000..3047f0c1db --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/NilpotentSquareRoot.lean @@ -0,0 +1,59 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Tactic.LinearCombination + +/-! # Lifting a square root of −1 through a nilpotent + +Part of the SVI polynomial-sign certificate (#174). + +In a commutative ring in which `2` is invertible, if `x² + 1` is nilpotent then `−1` has an exact +square root (`exists_sq_neg_one_of_nilpotent`). + +## Main results + +* `exists_sq_neg_one_of_nilpotent`: in a nontrivial commutative ring with `2 * half = 1`, if + `x ^ 2 + 1` is nilpotent for some `x`, then there is `u` with `u ^ 2 = -1`. + +## Tags + +nilpotent lifting, square root of minus one, Hensel-type lifting, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI + +/-- Lift a square root of -1 through a nilpotent error. Each correction +squares the error, so the construction terminates after finitely many steps. +No reducedness assumption is needed. -/ +theorem exists_sq_neg_one_of_nilpotent {A : Type*} [CommRing A] [Nontrivial A] + (half : A) (hh : 2 * half = 1) (x : A) (hx : IsNilpotent (x ^ 2 + 1)) : + ∃ u : A, u^2 = -1 := by + obtain ⟨r, hr⟩ := hx + induction r using Nat.strong_induction_on generalizing x with + | ind r ih => + rcases r with _ | (_ | n) + · norm_num at hr + · exact ⟨x, by simpa only [Nat.zero_add, pow_one, add_eq_zero_iff_eq_neg] using hr⟩ + · let e := x^2+1 + let y := x*(1+e*half) + have he : y^2+1 = e^2*(e+3)*half^2 := by + dsimp [y, e] + linear_combination -(x^2+1+2*(x^2+1)^2*half) * hh + have hy : (y^2+1)^(n+1) = 0 := by + rw [he, mul_pow, mul_pow, ← pow_mul] + have hz : e^(2*(n+1)) = 0 := pow_eq_zero_of_le (by omega) hr + rw [hz, zero_mul, zero_mul] + exact ih (n+1) (by omega) y hy + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/ParameterPolynomials.lean b/LeanPool/MathFin/Models/ModelFree/SVI/ParameterPolynomials.lean new file mode 100644 index 0000000000..871d2ed275 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/ParameterPolynomials.lean @@ -0,0 +1,166 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.ClearedSignature +public import LeanPool.MathFin.Models.ModelFree.SVI.Polynomial + +/-! # The certificate over the ring of parameter polynomials + +Part of the SVI polynomial-sign certificate (#174). + +`ParameterRing` is `MvPolynomial (Fin 5) ℝ`. The numerator polynomial and the four weights are +defined with coefficients in it and map to their real counterparts at every parameter point. The +fixed-size denominator-cleared Hermite matrices of its derivative (`universalMatrices n i`) map to +`certificateMatrices (polynomial p) i` only on the degree branch +`n = (polynomial p).derivative.natDegree` (`universalMatrices_eval`), and likewise their +characteristic coefficients (`determinantCoefficient_eval`). + +## Main definitions + +* `ParameterRing`: the ring `ℝ[a, b, ρ, m, σ]`, `MvPolynomial (Fin 5) ℝ`. +* `parameterEval`: evaluation of a parameter polynomial at the parameters `p`. +* `universalPolynomial`: the numerator polynomial with coefficients in `ParameterRing`. +* `universalWeights`, `universalMatrices`: the four weights `X²P²`, `XP²`, `X²P`, `XP` and the + four fixed-size Hermite matrices of the derivative, with entries in `ParameterRing`. +* `fixedCompanion`, `fixedHermite`: companion and Hermite matrices of a fixed size `n` over any + commutative ring, with the leading coefficient read at index `n`. +* `determinantCoefficient`: the coefficients of the characteristic polynomials of + `universalMatrices`, as parameter polynomials. + +## Main results + +* `universalPolynomial_eval`: mapping `universalPolynomial` by `parameterEval p` gives + `polynomial p`. +* `fixedHermite_eq_cleared`: if `f.natDegree = n` and `q.natDegree ≤ 22`, then + `fixedHermite f q n = clearedHermite f q n`. +* `universalWeights_eval`: the weights map to `X²P²`, `XP²`, `X²P`, `XP` for `P = polynomial p`. +* `universalMatrices_eval`: at size `n = (polynomial p).derivative.natDegree`, the matrices map + to `certificateMatrices (polynomial p) i`. +* `determinantCoefficient_eval`: at that size, `determinantCoefficient` evaluates to the + coefficient `r` of the characteristic polynomial of `certificateMatrices (polynomial p) i`. + +## Tags + +multivariate polynomial ring, universal Hermite matrices, SVI parameter polynomials, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +/-- The ring `ℝ[a, b, ρ, m, σ]` of polynomials in the five SVI parameters. -/ +abbrev ParameterRing := MvPolynomial (Fin 5) ℝ + +/-- The parameter point of `p` as a valuation of the five variables. -/ +def parameterValues (p : Params) : Fin 5 → ℝ := ![p.a, p.b, p.rho, p.m, p.sigma] +/-- Evaluation of a parameter polynomial at the parameters `p`. -/ +noncomputable def parameterEval (p : Params) : ParameterRing →+* ℝ := + MvPolynomial.eval (parameterValues p) + +/-- The numerator polynomial with coefficients in the parameter ring; it specialises to +`polynomial p` (`universalPolynomial_eval`). -/ +noncomputable def universalPolynomial : Polynomial ParameterRing := + let a : ParameterRing := MvPolynomial.X (0 : Fin 5) + let b : ParameterRing := MvPolynomial.X (1 : Fin 5) + let rho : ParameterRing := MvPolynomial.X (2 : Fin 5) + let m : ParameterRing := MvPolynomial.X (3 : Fin 5) + let sigma : ParameterRing := MvPolynomial.X (4 : Fin 5) + let D : Polynomial ParameterRing := 1 + X^2 + let A := C (b*sigma*(1+rho))*X^2 + C (2*a)*X + C (b*sigma*(1-rho)) + let B := C b * (C (1+rho)*X^2 - C (1-rho)) + let K := C sigma*X^2 + C (2*m)*X - C sigma + C (4*sigma)*D*(2*A*D-K*B)^2 - C sigma*A*B^2*D*(A+C 8*X) + C (64*b)*X^3*A^2 + +theorem universalPolynomial_eval (p : Params) : + universalPolynomial.map (parameterEval p) = polynomial p := by + simp [universalPolynomial, parameterEval, parameterValues, polynomial, polyA, polyB, polyD, polyK] + +/-- Fixed-degree companion numerator: the leading coefficient is read at n, +so this is polynomial even before imposing the degree branch. -/ +noncomputable def fixedCompanion {R : Type*} [CommRing R] (f : R[X]) (n : ℕ) : + Matrix (Fin n) (Fin n) R := + fun i j ↦ if j.val+1=n then -f.coeff i.val + else if i.val=j.val+1 then f.coeff n else 0 + +/-- A fixed finite sum replaces support-dependent summation. -/ +noncomputable def fixedHermite {R : Type*} [CommRing R] (f q : R[X]) (n : ℕ) : + Matrix (Fin n) (Fin n) R := fun i j ↦ + ∑ r ∈ Finset.range 23, q.coeff r * (f.coeff n)^(38-(i.val+j.val+r)) * + Matrix.trace ((fixedCompanion f n)^(i.val+j.val+r)) + +theorem fixedCompanion_map {R S : Type*} [CommRing R] [CommRing S] + (h : R →+* S) (f : R[X]) (n : ℕ) : + (fixedCompanion f n).map h = fixedCompanion (f.map h) n := by + ext i j + simp [fixedCompanion, apply_ite h] + +theorem fixedHermite_map {R S : Type*} [CommRing R] [CommRing S] + (h : R →+* S) (f q : R[X]) (n : ℕ) : + (fixedHermite f q n).map h = fixedHermite (f.map h) (q.map h) n := by + ext i j + simp only [Matrix.map_apply, fixedHermite, map_sum, map_mul, map_pow, coeff_map] + apply Finset.sum_congr rfl + intro r hr + congr 1 + rw [AddMonoidHom.map_trace, Matrix.map_pow, fixedCompanion_map] + +theorem fixedHermite_eq_cleared (f q : ℝ[X]) (n : ℕ) (hn : f.natDegree = n) + (hq : q.natDegree ≤ 22) : fixedHermite f q n = clearedHermite f q n := by + classical + have hcomp : fixedCompanion f n = scaledCompanion f n := by + ext i j + simp [fixedCompanion, scaledCompanion, ← hn, coeff_natDegree] + ext i j + simp only [fixedHermite, clearedHermite, ← hn, coeff_natDegree, hcomp] + symm + apply Finset.sum_subset + · intro r hr + have := le_natDegree_of_ne_zero (mem_support_iff.mp hr) + simp only [Finset.mem_range] + omega + · intro r hr hnot + simp [notMem_support_iff.mp hnot] + +/-- The four weights `X²P²`, `XP²`, `X²P`, `XP` for the universal polynomial `P`. -/ +noncomputable def universalWeights : Fin 4 → Polynomial ParameterRing := + ![X^2*universalPolynomial^2, X*universalPolynomial^2, + X^2*universalPolynomial, X*universalPolynomial] + +/-- Four matrices with entries literally in the five-variable polynomial ring. -/ +noncomputable def universalMatrices (n : ℕ) (i : Fin 4) : Matrix (Fin n) (Fin n) ParameterRing := + fixedHermite universalPolynomial.derivative (universalWeights i) n + +theorem universalWeights_eval (p : Params) (i : Fin 4) : + (universalWeights i).map (parameterEval p) = + ![X^2*(polynomial p)^2, X*(polynomial p)^2, X^2*polynomial p, X*polynomial p] i := by + fin_cases i <;> simp [universalWeights, universalPolynomial_eval] + +theorem universalMatrices_eval (p : Params) (i : Fin 4) : + (universalMatrices (polynomial p).derivative.natDegree i).map (parameterEval p) = + certificateMatrices (polynomial p) i := by + rw [universalMatrices, fixedHermite_map, ← derivative_map, universalPolynomial_eval, + universalWeights_eval, fixedHermite_eq_cleared _ _ _ rfl + (weight_size_bound _ (degree_le_ten p) i)] + fin_cases i <;> rfl + +/-- Every coefficient tested by the determinant certificate is an explicitly +constructed polynomial in the original five parameters, on its degree branch. -/ +noncomputable def determinantCoefficient (n : ℕ) (i : Fin 4) (r : ℕ) : ParameterRing := + (universalMatrices n i).charpoly.coeff r + +theorem determinantCoefficient_eval (p : Params) (i : Fin 4) (r : ℕ) : + parameterEval p (determinantCoefficient (polynomial p).derivative.natDegree i r) = + (certificateMatrices (polynomial p) i).charpoly.coeff r := by + rw [determinantCoefficient, ← coeff_map, ← Matrix.charpoly_map, universalMatrices_eval] + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/Polynomial.lean b/LeanPool/MathFin/Models/ModelFree/SVI/Polynomial.lean new file mode 100644 index 0000000000..6eb9686dd4 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/Polynomial.lean @@ -0,0 +1,83 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.Reduction +public import Mathlib.Algebra.Order.Ring.Star +public import Mathlib.Tactic.ComputeDegree + +/-! # The numerator as a polynomial + +Part of the SVI polynomial-sign certificate (#174). + +`polynomial p` is a real polynomial of degree at most ten whose value at every real `t` is +`numerator p t`, with its coefficients of degree `0` and `10` computed (the latter may vanish). + +## Main definitions + +* `polyD`: the polynomial `1 + X²`. +* `polyA`, `polyB`, `polyK`: polynomials whose values are `A p`, `B p` and `K p`. +* `polynomial`: the rationalised Durrleman numerator as a real polynomial in `t`. + +## Main results + +* `eval_polynomial`: `(polynomial p).eval t = numerator p t` for every `t`. +* `degree_le_ten`: `(polynomial p).natDegree ≤ 10`. +* `coeff_zero`: `(polynomial p).coeff 0 = b²σ³(1-ρ)²(4 - b²(1-ρ)²)`. +* `coeff_ten`: `(polynomial p).coeff 10 = b²σ³(1+ρ)²(4 - b²(1+ρ)²)`. + +## Tags + +Durrleman numerator, SVI numerator polynomial, degree ten polynomial, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +/-- The polynomial `1 + X²`, with values `D`. -/ +noncomputable def polyD : ℝ[X] := 1 + X^2 +/-- The polynomial with values `A p`. -/ +noncomputable def polyA (p : Params) : ℝ[X] := + C (p.b*p.sigma*(1+p.rho))*X^2 + C (2*p.a)*X + C (p.b*p.sigma*(1-p.rho)) +/-- The polynomial with values `B p`. -/ +noncomputable def polyB (p : Params) : ℝ[X] := + C p.b * (C (1+p.rho)*X^2 - C (1-p.rho)) +/-- The polynomial with values `K p`. -/ +noncomputable def polyK (p : Params) : ℝ[X] := C p.sigma*X^2 + C (2*p.m)*X - C p.sigma +/-- The rationalised Durrleman numerator as a polynomial, with values `numerator p` +(`eval_polynomial`). -/ +noncomputable def polynomial (p : Params) : ℝ[X] := + C (4*p.sigma)*polyD*(2*polyA p*polyD - polyK p*polyB p)^2 - + C p.sigma*polyA p*(polyB p)^2*polyD*(polyA p + C 8*X) + + C (64*p.b)*X^3*(polyA p)^2 + +theorem eval_polynomial (p : Params) (t : ℝ) : + (polynomial p).eval t = numerator p t := by + simp [polynomial, polyD, polyA, polyB, polyK, numerator, D, A, B, K] + +theorem degree_le_ten (p : Params) : (polynomial p).natDegree ≤ 10 := by + unfold polynomial polyD polyA polyB polyK + compute_degree + +theorem coeff_zero (p : Params) : + (polynomial p).coeff 0 = p.b^2*p.sigma^3*(1-p.rho)^2*(4-p.b^2*(1-p.rho)^2) := by + rw [Polynomial.coeff_zero_eq_eval_zero, eval_polynomial] + unfold numerator A B K D + ring + +theorem coeff_ten (p : Params) : + (polynomial p).coeff 10 = p.b^2*p.sigma^3*(1+p.rho)^2*(4-p.b^2*(1+p.rho)^2) := by + unfold polynomial polyD polyA polyB polyK + compute_degree <;> norm_num + ring + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/PolynomialCertificate.lean b/LeanPool/MathFin/Models/ModelFree/SVI/PolynomialCertificate.lean new file mode 100644 index 0000000000..a7804dec0a --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/PolynomialCertificate.lean @@ -0,0 +1,69 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.Assembly +public import LeanPool.MathFin.Models.ModelFree.SVI.Admissibility + +/-! # The critical-point certificate, all degrees + +Part of the SVI polynomial-sign certificate (#174). + +`criticalCertificate` handles constant and nonconstant numerator polynomials alike. For `σ > 0`, +`b ≥ 0`, `ρ² ≤ 1` and under the variance gate, `criticalCertificate (polynomial p)` is equivalent to +`g(k) ≥ 0` for every `k` (`svi_criticalCertificate_iff`). + +## Main definitions + +* `criticalCertificate`: for a real polynomial `P`, `0 ≤ P.coeff 0` if `P` is constant, and + otherwise `0 < P.leadingCoeff`, `0 ≤ P.eval 0` and `badCriticalCount P = 0`. + +## Main results + +* `criticalCertificate_iff`: `criticalCertificate P` iff `0 ≤ P.eval t` for every `t > 0`. +* `svi_criticalCertificate_iff`: for `σ > 0`, `b ≥ 0`, `1 - ρ² ≥ 0` and `varianceGate p`, + `criticalCertificate (polynomial p)` iff `durrleman p k ≥ 0` for every `k`. + +## Tags + +critical point certificate, Durrleman condition, raw SVI, butterfly arbitrage, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +/-- The analytic finite-critical-point certificate, with the constant and +zero cases included. The determinant replacement is proved separately. -/ +noncomputable def criticalCertificate (P : ℝ[X]) : Prop := + if P.natDegree = 0 then 0 ≤ P.coeff 0 + else 0 < P.leadingCoeff ∧ 0 ≤ P.eval 0 ∧ badCriticalCount P = 0 + +theorem criticalCertificate_iff (P : ℝ[X]) : + criticalCertificate P ↔ ∀ t : ℝ, 0 < t → 0 ≤ P.eval t := by + unfold criticalCertificate + split_ifs with hd + · rw [eq_C_of_natDegree_eq_zero hd] + simp only [coeff_C_zero, eval_C] + exact ⟨fun h _ _ ↦ h, fun h ↦ h 1 (by norm_num)⟩ + · have hdeg : 0 < P.degree := natDegree_pos_iff_degree_pos.mp (Nat.pos_of_ne_zero hd) + rw [badCriticalCount_eq_zero_iff P hdeg] + exact (polynomial_nonneg_criterion P hdeg).symm + +/-- All SVI degree branches under the exact polynomial variance gate. -/ +theorem svi_criticalCertificate_iff (p : Params) (hs : 0 < p.sigma) + (hb : 0 ≤ p.b) (hr : 0 ≤ 1 - p.rho ^ 2) (hg : varianceGate p) : + criticalCertificate (polynomial p) ↔ ∀ k : ℝ, 0 ≤ durrleman p k := by + rw [criticalCertificate_iff, + durrleman_nonneg_iff p hs ((varianceGate_iff p hs hb hr).mp hg)] + simp only [eval_polynomial] + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/ProductSignature.lean b/LeanPool/MathFin/Models/ModelFree/SVI/ProductSignature.lean new file mode 100644 index 0000000000..371b51fd84 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/ProductSignature.lean @@ -0,0 +1,100 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.RankOneSignature + +/-! # Signature of an orthogonal product + +Part of the SVI polynomial-sign certificate (#174). + +The signature of a weighted sum of squares is the sum of the signs of its weights, equivalent +forms have equal signatures, and the signature is additive over orthogonal products, degenerate +forms included (`formSignature_prod`). + +## Main definitions + +* `formProd`: the orthogonal product of two quadratic forms, `(x, y) ↦ Q x + R y` on `V × W`. + +## Main results + +* `formSignature_weightedSumSquares`: the signature of `weightedSumSquares ℝ w` is + `∑ i, sign (w i)`. +* `formSignature_eq_of_equivalent`: equivalent real quadratic forms have equal signature. +* `formSignature_prod`: for finite-dimensional `V`, `W`, the signature of `formProd Q R` is the + sum of the signatures of `Q` and `R`, degenerate forms included. + +## Tags + +quadratic form signature, orthogonal product, sum of squares signature, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open scoped BigOperators + +private theorem sign_indicators (a : ℝ) : + sign a = (if 0 < a then (1 : ℤ) else 0) - (if a < 0 then 1 else 0) := by + rcases lt_trichotomy a 0 with h | rfl | h <;> simp [sign, *, not_lt_of_ge, le_of_lt] + +theorem formSignature_weightedSumSquares {ι : Type*} [Fintype ι] (w : ι → ℝ) : + formSignature (QuadraticMap.weightedSumSquares ℝ w) = ∑ i, sign (w i) := by + classical + unfold formSignature + rw [QuadraticForm.sigPos_weightedSumSquares, QuadraticForm.sigNeg_weightedSumSquares] + simp_rw [sign_indicators] + rw [Finset.sum_sub_distrib] + simp [Set.ncard_eq_toFinset_card'] + +theorem formSignature_eq_of_equivalent {V W : Type*} [AddCommGroup V] [Module ℝ V] + [AddCommGroup W] [Module ℝ W] {Q : QuadraticForm ℝ V} {R : QuadraticForm ℝ W} + (he : QuadraticMap.Equivalent Q R) : formSignature Q = formSignature R := by + unfold formSignature + rw [he.sigPos_eq, he.sigNeg_eq] + +/-- The orthogonal product of two quadratic forms on `V × W`. -/ +noncomputable def formProd {V W : Type*} [AddCommGroup V] [Module ℝ V] + [AddCommGroup W] [Module ℝ W] (Q : QuadraticForm ℝ V) (R : QuadraticForm ℝ W) : + QuadraticForm ℝ (V × W) := + Q.comp (LinearMap.fst ℝ V W) + R.comp (LinearMap.snd ℝ V W) + +@[simp] theorem formProd_apply {V W : Type*} [AddCommGroup V] [Module ℝ V] + [AddCommGroup W] [Module ℝ W] (Q : QuadraticForm ℝ V) (R : QuadraticForm ℝ W) + (x : V × W) : formProd Q R x = Q x.1 + R x.2 := rfl + +/-- Signature is additive under orthogonal products, including degenerate forms. -/ +theorem formSignature_prod {V W : Type*} [AddCommGroup V] [Module ℝ V] + [AddCommGroup W] [Module ℝ W] [FiniteDimensional ℝ V] [FiniteDimensional ℝ W] + (Q : QuadraticForm ℝ V) (R : QuadraticForm ℝ W) : + formSignature (formProd Q R) = formSignature Q + formSignature R := by + classical + obtain ⟨w, ⟨e⟩⟩ := QuadraticForm.equivalent_weightedSumSquares Q + obtain ⟨v, ⟨f⟩⟩ := QuadraticForm.equivalent_weightedSumSquares R + let E := (e.toLinearEquiv.prodCongr f.toLinearEquiv).trans + (LinearEquiv.sumArrowLequivProdArrow (Fin (Module.finrank ℝ V)) + (Fin (Module.finrank ℝ W)) ℝ ℝ).symm + have he : QuadraticMap.Equivalent (formProd Q R) + (QuadraticMap.weightedSumSquares ℝ (Sum.elim w v)) := by + refine ⟨{ E with map_app' := ?_ }⟩ + intro x + simp only [QuadraticMap.weightedSumSquares_apply, Fintype.sum_sum_type] + change (∑ i, w i * (e x.1 i * e x.1 i)) + + (∑ j, v j * (f x.2 j * f x.2 j)) = Q x.1 + R x.2 + have he := e.map_app x.1 + have hf := f.map_app x.2 + simp only [QuadraticMap.weightedSumSquares_apply, smul_eq_mul] at he hf + rw [he, hf] + rw [formSignature_eq_of_equivalent he, + formSignature_eq_of_equivalent (show QuadraticMap.Equivalent Q _ from ⟨e⟩), + formSignature_eq_of_equivalent (show QuadraticMap.Equivalent R _ from ⟨f⟩)] + simp [formSignature_weightedSumSquares, Fintype.sum_sum_type] + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/QuadraticRay.lean b/LeanPool/MathFin/Models/ModelFree/SVI/QuadraticRay.lean new file mode 100644 index 0000000000..e70bcd73ab --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/QuadraticRay.lean @@ -0,0 +1,130 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Order.Star.Real + +/-! # Nonnegativity of a quadratic on a ray + +Part of the SVI polynomial-sign certificate (#174). + +A real quadratic is nonnegative on a closed ray exactly when a finite list of polynomial sign +conditions on its coefficients holds (`quadratic_nonneg_ray_iff`). + +## Main results + +* `quadratic_nonneg_ray_zero_iff`: `u x² + v x + z ≥ 0` for all `x ≥ 0` iff `u ≥ 0`, `z ≥ 0` and + either `u = 0 ∧ v ≥ 0` or `u > 0` with `v ≥ 0` or `4uz - v² ≥ 0`. +* `quadratic_nonneg_ray_iff`: `u w² + v w + z ≥ 0` for all `w ≥ a` iff `u ≥ 0`, + `u a² + v a + z ≥ 0` and either `u = 0 ∧ v ≥ 0` or `u > 0` with `v + 2ua ≥ 0` or + `4uz - v² ≥ 0`. + +## Tags + +quadratic nonnegativity, closed ray, sign conditions, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI + +/-- A quadratic nonnegative on `[0, ∞)` has nonnegative leading coefficient. -/ +theorem quadratic_leading_nonneg (u v z : ℝ) + (h : ∀ x : ℝ, 0 ≤ x → 0 ≤ u*x^2+v*x+z) : 0 ≤ u := by + by_contra hu + have hu : u < 0 := lt_of_not_ge hu + let x : ℝ := (|v|+|z|+1)/(-u)+1 + have hx : 1 ≤ x := by + have hp : 0 ≤ (|v|+|z|+1)/(-u) := div_nonneg (by positivity) (by linarith) + dsimp [x]; linarith + have he : (-u)*(x-1) = |v|+|z|+1 := by + dsimp [x] + field_simp [ne_of_lt hu] + ring + have hh := h x (by linarith) + have hv := le_abs_self v + have hz := le_abs_self z + have hvx : v*x ≤ |v| * x := mul_le_mul_of_nonneg_right hv (by linarith) + have hzx : |z| ≤ |z| * x := by nlinarith [abs_nonneg z] + have hux : 0 ≤ (-u)*x := mul_nonneg (by linarith) (by linarith) + nlinarith + +/-- An affine function nonnegative on `[0, ∞)` has nonnegative slope. -/ +theorem affine_nonneg_slope (v z : ℝ) + (h : ∀ x : ℝ, 0 ≤ x → 0 ≤ v*x+z) : 0 ≤ v := by + by_contra hv + have hv : v < 0 := lt_of_not_ge hv + have hx : 0 ≤ (|z|+1)/(-v) := div_nonneg (by positivity) (by linarith) + have hh := h _ hx + have he : v*((|z|+1)/(-v)) = -(|z|+1) := by field_simp [ne_of_lt hv] + rw [he] at hh + have := le_abs_self z + linarith + +/-- Exact nonnegativity certificate for a real quadratic on the nonnegative ray. -/ +theorem quadratic_nonneg_ray_zero_iff (u v z : ℝ) : + (∀ x : ℝ, 0 ≤ x → 0 ≤ u*x^2+v*x+z) ↔ + 0 ≤ u ∧ 0 ≤ z ∧ + ((u=0 ∧ 0≤v) ∨ (0 rintro ⟨hu,hz,h⟩ <;> refine ⟨hu,hz,?_⟩ + · rcases h with ⟨he,hv⟩ | h + · exact Or.inl ⟨he,by simpa [he] using hv⟩ + · exact Or.inr h + · rcases h with ⟨he,hv⟩ | h + · exact Or.inl ⟨he,by simpa [he] using hv⟩ + · exact Or.inr h + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/QuadraticRootSignature.lean b/LeanPool/MathFin/Models/ModelFree/SVI/QuadraticRootSignature.lean new file mode 100644 index 0000000000..ffda6e5c11 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/QuadraticRootSignature.lean @@ -0,0 +1,94 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.NilpotentSquareRoot +public import LeanPool.MathFin.Models.ModelFree.SVI.ImaginaryTraceSignature + +/-! # A conjugate pair contributes zero signature + +Part of the SVI polynomial-sign certificate (#174). + +For a positive quadratic `(X − a)² + b²`, `b ≠ 0`, the quotient by any power contains a square +root of `−1`, so its weighted trace form has signature zero. + +## Main definitions + +* `positiveQuadratic`: the quadratic `(X - C a)² + C (b²)` over `ℝ`. + +## Main results + +* `positiveQuadratic_degree`: `positiveQuadratic a b` has `natDegree` `2`. +* `quadraticRoot_has_imaginary`: for `b ≠ 0` and `r > 0`, `AdjoinRoot ((positiveQuadratic a b)^r)` + contains `u` with `u ^ 2 = -1`. +* `weightedTraceForm_quadratic_signature`: for `b ≠ 0` and `r > 0`, the weighted trace form of + `(positiveQuadratic a b)^r` with any weight `q` has signature `0`. + +## Tags + +conjugate pair roots, trace form signature, irreducible quadratic, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +/-- The quadratic `(X − a)² + b²`. -/ +noncomputable def positiveQuadratic (a b : ℝ) : ℝ[X] := (X-C a)^2 + C (b^2) + +theorem positiveQuadratic_degree (a b : ℝ) : (positiveQuadratic a b).natDegree = 2 := by + unfold positiveQuadratic + compute_degree! + +/-- A power of a real quadratic with no real roots contains an exact square +root of -1, even when the power produces nilpotents. -/ +theorem quadraticRoot_has_imaginary (a b : ℝ) (hb : b ≠ 0) (r : ℕ) (hr : 0 < r) : + ∃ u : AdjoinRoot ((positiveQuadratic a b)^r), u^2 = -1 := by + let f := (positiveQuadratic a b)^r + let A := AdjoinRoot f + have hdeg : f.natDegree = 2*r := by + simp [f, natDegree_pow, positiveQuadratic_degree, Nat.mul_comm] + let : Nontrivial A := AdjoinRoot.nontrivial f + (ne_of_gt (natDegree_pos_iff_degree_pos.mp (by rw [hdeg]; omega))) + let z : A := AdjoinRoot.root f + let alpha : A := algebraMap ℝ A a + let beta : A := algebraMap ℝ A b + let ibeta : A := algebraMap ℝ A b⁻¹ + let x : A := (z-alpha)*ibeta + have hbi : ibeta^2*beta^2 = 1 := by + dsimp [ibeta, beta] + rw [← mul_pow, ← map_mul, inv_mul_cancel₀ hb, map_one, one_pow] + have he : x^2+1 = ibeta^2 * aeval z (positiveQuadratic a b) := by + calc + x^2+1 = ibeta^2*(z-alpha)^2+1 := by dsimp [x]; ring + _ = ibeta^2*(z-alpha)^2+ibeta^2*beta^2 := by rw [hbi] + _ = ibeta^2 * aeval z (positiveQuadratic a b) := by + simp only [positiveQuadratic, map_add, map_pow, map_sub, aeval_X, aeval_C] + dsimp [alpha, beta] + ring + have hnil : IsNilpotent (x^2+1) := by + refine ⟨r, ?_⟩ + rw [he, mul_pow, ← map_pow (aeval z) (positiveQuadratic a b) r] + change (ibeta^2)^r * aeval (AdjoinRoot.root f) f = 0 + rw [AdjoinRoot.aeval_eq, AdjoinRoot.mk_self, mul_zero] + have hhalf : (2 : A) * algebraMap ℝ A (1/2) = 1 := by + have hh : (2 : ℝ)*(1/2) = 1 := by norm_num + simpa only [map_mul, map_ofNat, map_one] using congrArg (algebraMap ℝ A) hh + exact exists_sq_neg_one_of_nilpotent _ hhalf x hnil + +/-- A conjugate pair, at any multiplicity, contributes zero net signature. -/ +theorem weightedTraceForm_quadratic_signature (a b : ℝ) (hb : b ≠ 0) + (r : ℕ) (hr : 0 < r) (q : ℝ[X]) : + formSignature (weightedTraceForm ((positiveQuadratic a b)^r) q).toQuadraticMap = 0 := by + obtain ⟨u, hu⟩ := quadraticRoot_has_imaginary a b hb r hr + exact weightedTraceForm_signature_zero_of_imaginary _ q u hu + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/QuotientProduct.lean b/LeanPool/MathFin/Models/ModelFree/SVI/QuotientProduct.lean new file mode 100644 index 0000000000..9f8d532ab2 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/QuotientProduct.lean @@ -0,0 +1,132 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.TraceForm +public import LeanPool.MathFin.Models.ModelFree.SVI.ProductSignature +public import Mathlib.RingTheory.Trace.Basic + +/-! # The Chinese remainder theorem for trace forms + +Part of the SVI polynomial-sign certificate (#174). + +For coprime `f`, `g`, `ℝ[X]/(fg)` is the product of the two quotients as algebras. If moreover +`f, g ≠ 0`, the weighted trace form splits as an orthogonal product, so signatures add. + +## Main definitions + +* `quotientProdHom`: the canonical algebra map `ℝ[X]/(fg) → ℝ[X]/(f) × ℝ[X]/(g)`. +* `quotientProdEquiv`: for coprime `f`, `g`, the same map as an algebra equivalence. + +## Main results + +* `quotientProdHom_bijective`: for coprime `f`, `g`, `quotientProdHom f g` is bijective. +* `quotientProdEquiv_mk`, `quotientProdEquiv_root`: `quotientProdEquiv` sends the class of `p` to + the pair of classes of `p`, and the root of `f * g` to the pair of roots. +* `weightedTraceForm_prod_equivalent`: for coprime nonzero `f`, `g`, `weightedTraceForm (f * g) q` + is equivalent to `formProd` of the weighted trace forms of `f` and `g`. +* `weightedTraceForm_prod_signature`: under the same hypotheses, the signature of + `weightedTraceForm (f * g) q` is the sum of the signatures for `f` and `g`. + +## Tags + +Chinese remainder theorem, coprime polynomials, trace form splitting, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +@[simp] theorem aeval_pair {A B : Type*} [CommRing A] [CommRing B] + [Algebra ℝ A] [Algebra ℝ B] (x : A) (y : B) (p : ℝ[X]) : + aeval (x, y) p = (aeval x p, aeval y p) := by + ext + · exact (aeval_algHom_apply (AlgHom.fst ℝ A B) (x, y) p).symm + · exact (aeval_algHom_apply (AlgHom.snd ℝ A B) (x, y) p).symm + +/-- The canonical map `ℝ[X]/(fg) → ℝ[X]/(f) × ℝ[X]/(g)`. -/ +noncomputable def quotientProdHom (f g : ℝ[X]) : + AdjoinRoot (f*g) →ₐ[ℝ] AdjoinRoot f × AdjoinRoot g := + (AdjoinRoot.algHomOfDvd ℝ (f*g) f (dvd_mul_right _ _)).prod + (AdjoinRoot.algHomOfDvd ℝ (f*g) g (dvd_mul_left _ _)) + +@[simp] theorem quotientProdHom_root (f g : ℝ[X]) : + quotientProdHom f g (AdjoinRoot.root (f*g)) = (AdjoinRoot.root f, AdjoinRoot.root g) := by + simp [quotientProdHom] + +@[simp] theorem quotientProdHom_mk (f g p : ℝ[X]) : + quotientProdHom f g (AdjoinRoot.mk (f*g) p) = + (AdjoinRoot.mk f p, AdjoinRoot.mk g p) := by + rw [← AdjoinRoot.aeval_eq, + ← aeval_algHom_apply, quotientProdHom_root] + simp [AdjoinRoot.aeval_eq] + +/-- The map `ℝ[X]/(fg) → ℝ[X]/(f) × ℝ[X]/(g)` is Mathlib's Chinese remainder isomorphism +`Ideal.quotientMulEquivQuotientProd` for the coprime ideals `(f)`, `(g)`, transported along +`(fg) = (f)(g)`. -/ +theorem quotientProdHom_bijective (f g : ℝ[X]) (hc : IsCoprime f g) : + Function.Bijective (quotientProdHom f g) := by + let e := (Ideal.quotEquivOfEq (Ideal.span_singleton_mul_span_singleton f g).symm).trans + (Ideal.quotientMulEquivQuotientProd _ _ ((Ideal.isCoprime_span_singleton_iff f g).2 hc)) + suffices ⇑(quotientProdHom f g) = e from this ▸ e.bijective + funext x + obtain ⟨p, rfl⟩ := AdjoinRoot.mk_surjective x + exact (quotientProdHom_mk f g p).trans (Prod.ext rfl rfl) + +/-- Chinese remainder decomposition at the algebra level, preserving the +residue class of every polynomial. -/ +noncomputable def quotientProdEquiv (f g : ℝ[X]) (hc : IsCoprime f g) : + AdjoinRoot (f*g) ≃ₐ[ℝ] AdjoinRoot f × AdjoinRoot g := + AlgEquiv.ofBijective (quotientProdHom f g) (quotientProdHom_bijective f g hc) + +@[simp] theorem quotientProdEquiv_mk (f g p : ℝ[X]) (hc : IsCoprime f g) : + quotientProdEquiv f g hc (AdjoinRoot.mk (f*g) p) = + (AdjoinRoot.mk f p, AdjoinRoot.mk g p) := quotientProdHom_mk f g p + +@[simp] theorem quotientProdEquiv_root (f g : ℝ[X]) (hc : IsCoprime f g) : + quotientProdEquiv f g hc (AdjoinRoot.root (f*g)) = + (AdjoinRoot.root f, AdjoinRoot.root g) := quotientProdHom_root f g + +/-- Coprime factors give an orthogonal product of their weighted trace forms. +The factors may themselves have arbitrarily repeated roots. -/ +theorem weightedTraceForm_prod_equivalent (f g q : ℝ[X]) (hf : f ≠ 0) (hg : g ≠ 0) + (hc : IsCoprime f g) : + QuadraticMap.Equivalent (weightedTraceForm (f*g) q).toQuadraticMap + (formProd (weightedTraceForm f q).toQuadraticMap + (weightedTraceForm g q).toQuadraticMap) := by + let : Module.Free ℝ (AdjoinRoot f) := Module.Free.of_basis (AdjoinRoot.powerBasis hf).basis + let : Module.Free ℝ (AdjoinRoot g) := Module.Free.of_basis (AdjoinRoot.powerBasis hg).basis + let : FiniteDimensional ℝ (AdjoinRoot f) := + Module.Finite.of_basis (AdjoinRoot.powerBasis hf).basis + let : FiniteDimensional ℝ (AdjoinRoot g) := + Module.Finite.of_basis (AdjoinRoot.powerBasis hg).basis + let e := quotientProdEquiv f g hc + refine ⟨{ e.toLinearEquiv with map_app' := ?_ }⟩ + intro x + simp only [formProd_apply, LinearMap.BilinMap.toQuadraticMap_apply, weightedTraceForm_apply] + rw [← Algebra.trace_eq_of_algEquiv e] + simp only [map_mul, ← aeval_algHom_apply, Algebra.trace_prod_apply] + simp only [e, quotientProdEquiv_root, aeval_pair, Prod.fst_mul, Prod.snd_mul] + rfl + +theorem weightedTraceForm_prod_signature (f g q : ℝ[X]) (hf : f ≠ 0) (hg : g ≠ 0) + (hc : IsCoprime f g) : + formSignature (weightedTraceForm (f*g) q).toQuadraticMap = + formSignature (weightedTraceForm f q).toQuadraticMap + + formSignature (weightedTraceForm g q).toQuadraticMap := by + let : FiniteDimensional ℝ (AdjoinRoot f) := + Module.Finite.of_basis (AdjoinRoot.powerBasis hf).basis + let : FiniteDimensional ℝ (AdjoinRoot g) := + Module.Finite.of_basis (AdjoinRoot.powerBasis hg).basis + rw [formSignature_eq_of_equivalent (weightedTraceForm_prod_equivalent f g q hf hg hc), + formSignature_prod] + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/RankOneSignature.lean b/LeanPool/MathFin/Models/ModelFree/SVI/RankOneSignature.lean new file mode 100644 index 0000000000..0d782691e3 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/RankOneSignature.lean @@ -0,0 +1,122 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.CriticalPoints +public import Mathlib.LinearAlgebra.QuadraticForm.Signature +public import Mathlib.Analysis.RCLike.Lemmas + +/-! # Signature of a rank-one form + +Part of the SVI polynomial-sign certificate (#174). + +`formSignature Q` is `sigPos Q − sigNeg Q`. If `Q x = a·(l x)²` for a nonzero linear form `l`, the +signature is the sign of `a` (`formSignature_rankOne`). + +## Main definitions + +* `formSignature`: the signature `sigPos Q - sigNeg Q` of a real quadratic form. + +## Main results + +* `sigPos_eq_zero_of_nonpos`, `one_le_sigPos_of_pos`: `sigPos Q = 0` if `Q ≤ 0` everywhere, and + `1 ≤ sigPos Q` if `Q v > 0` for some `v`. +* `sigPos_le_one_of_rankOne`: if `Q x = a * (l x)²` for a linear form `l`, then `sigPos Q ≤ 1`. +* `formSignature_rankOne`: if `Q x = a * (l x)²` and `l v ≠ 0` for some `v`, then + `formSignature Q = sign a`, with `a = 0` allowed. + +## Tags + +rank-one quadratic form, signature of a form, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI + +/-- The signature `sigPos − sigNeg` of a real quadratic form. -/ +noncomputable def formSignature {V : Type*} [AddCommGroup V] [Module ℝ V] + (Q : QuadraticForm ℝ V) : ℤ := (sigPos Q : ℤ) - (sigNeg Q : ℤ) + +theorem sigPos_eq_zero_of_nonpos {V : Type*} [AddCommGroup V] [Module ℝ V] + [FiniteDimensional ℝ V] (Q : QuadraticForm ℝ V) (hQ : ∀ x, Q x ≤ 0) : sigPos Q = 0 := by + obtain ⟨W, hW, hp⟩ := exists_finrank_eq_sigPos_and_posDef Q + have hbot : W = ⊥ := by + apply (Submodule.eq_bot_iff _).mpr + intro x hx + by_contra hn + have hh := hp ⟨x, hx⟩ (by simpa using hn) + exact (not_lt_of_ge (hQ x)) hh + rw [hbot, finrank_bot] at hW + exact hW.symm + +theorem one_le_sigPos_of_pos {V : Type*} [AddCommGroup V] [Module ℝ V] + [FiniteDimensional ℝ V] (Q : QuadraticForm ℝ V) (v : V) (hv : 0 < Q v) : + 1 ≤ sigPos Q := by + have hv0 : v ≠ 0 := by intro h; simp [h] at hv + have hp : (Q.restrict (ℝ ∙ v)).PosDef := by + intro x hx + obtain ⟨c, hc⟩ := Submodule.mem_span_singleton.mp x.property + have hc0 : c ≠ 0 := by + intro h + apply hx + apply Subtype.ext + simpa [h] using hc.symm + change 0 < Q (x : V) + rw [← hc, Q.map_smul] + simpa only [smul_eq_mul, pow_two] using mul_pos (sq_pos_of_ne_zero hc0) hv + have hh := le_sigPos_of_posDef Q hp + rw [finrank_span_singleton hv0] at hh + exact hh + +theorem sigPos_le_one_of_rankOne {V : Type*} [AddCommGroup V] [Module ℝ V] + [FiniteDimensional ℝ V] (Q : QuadraticForm ℝ V) (l : V →ₗ[ℝ] ℝ) + (a : ℝ) (hQ : ∀ x, Q x = a * (l x) ^ 2) : sigPos Q ≤ 1 := by + obtain ⟨W, hW, hp⟩ := exists_finrank_eq_sigPos_and_posDef Q + let L := l.comp W.subtype + have hinj : Function.Injective L := by + apply LinearMap.ker_eq_bot.mp + apply (Submodule.eq_bot_iff _).mpr + intro x hx + have hzero : l (x : V) = 0 := hx + by_contra hn + have hh := hp x hn + change 0 < Q (x : V) at hh + rw [hQ, hzero] at hh + norm_num at hh + have hh := LinearMap.finrank_le_finrank_of_injective hinj + simpa [hW] using hh + +/-- The signature of any nonzero linear evaluation squared is the sign of +its coefficient; a zero coefficient is allowed. -/ +theorem formSignature_rankOne {V : Type*} [AddCommGroup V] [Module ℝ V] + [FiniteDimensional ℝ V] (Q : QuadraticForm ℝ V) (l : V →ₗ[ℝ] ℝ) + (v : V) (hv : l v ≠ 0) (a : ℝ) (hQ : ∀ x, Q x = a * (l x) ^ 2) : + formSignature Q = sign a := by + have hneg : ∀ x, (-Q) x = (-a)*(l x)^2 := by intro x; simp [hQ] + rcases lt_trichotomy a 0 with ha | rfl | ha + · have hp : sigPos Q = 0 := sigPos_eq_zero_of_nonpos Q (by + intro x; rw [hQ]; exact mul_nonpos_of_nonpos_of_nonneg ha.le (sq_nonneg _)) + have hnp : 1 ≤ sigPos (-Q) := one_le_sigPos_of_pos (-Q) v (by + rw [hneg]; exact mul_pos (neg_pos.mpr ha) (sq_pos_of_ne_zero hv)) + have hnle := sigPos_le_one_of_rankOne (-Q) l (-a) hneg + have hn : sigPos (-Q) = 1 := by omega + simp [formSignature, ← sigPos_neg, hp, hn, sign, ha, not_lt_of_ge ha.le] + · have hp := sigPos_eq_zero_of_nonpos Q (by intro x; simp [hQ]) + have hn := sigPos_eq_zero_of_nonpos (-Q) (by intro x; simp [hneg]) + simp [formSignature, ← sigPos_neg, hp, hn, sign] + · have hn : sigPos (-Q) = 0 := sigPos_eq_zero_of_nonpos (-Q) (by + intro x; rw [hneg]; exact mul_nonpos_of_nonpos_of_nonneg (by linarith) (sq_nonneg _)) + have hpp := one_le_sigPos_of_pos Q v (by rw [hQ]; exact mul_pos ha (sq_pos_of_ne_zero hv)) + have hple := sigPos_le_one_of_rankOne Q l a hQ + have hp : sigPos Q = 1 := by omega + simp [formSignature, ← sigPos_neg, hp, hn, sign, ha] + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/RealIrreducibles.lean b/LeanPool/MathFin/Models/ModelFree/SVI/RealIrreducibles.lean new file mode 100644 index 0000000000..028bbc5e5c --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/RealIrreducibles.lean @@ -0,0 +1,73 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.QuadraticRootSignature +public import Mathlib.Analysis.Complex.Polynomial.Basic + +/-! # Monic irreducible real polynomials + +Part of the SVI polynomial-sign certificate (#174). + +A monic irreducible real polynomial is linear or a positive quadratic `(X − a)² + b²`. + +## Main results + +* `monic_real_irreducible_cases`: a monic irreducible `p : ℝ[X]` is either `X - C c` or + `positiveQuadratic a b` with `b ≠ 0`. + +## Tags + +irreducible real polynomials, fundamental theorem of algebra, linear or quadratic factors, SVI, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +/-- Every monic irreducible real polynomial is linear or a strictly positive +completed-square quadratic. -/ +theorem monic_real_irreducible_cases (p : ℝ[X]) (hm : p.Monic) (hi : Irreducible p) : + (∃ c : ℝ, p = X - C c) ∨ + ∃ a b : ℝ, b ≠ 0 ∧ p = positiveQuadratic a b := by + have hlo := hi.natDegree_pos + have hhi := hi.natDegree_le_two + have hd : p.natDegree = 1 ∨ p.natDegree = 2 := by omega + rcases hd with hd | hd + · left + exact ⟨-p.coeff 0, by simpa using hm.eq_X_add_C hd⟩ + · right + have hp : p = X^2 + C (p.coeff 1)*X + C (p.coeff 0) := by + have h := p.as_sum_range_C_mul_X_pow + have h2 : p.coeff 2 = 1 := by simpa [hd] using hm.coeff_natDegree + simpa [hd, Finset.sum_range_succ, h2, add_comm, add_left_comm, add_assoc] using h + let a := -p.coeff 1 / 2 + let s := p.coeff 0 - (p.coeff 1)^2 / 4 + have hs : 0 < s := by + by_contra hn + have hsn : 0 ≤ -s := by linarith + have hsq := Real.sq_sqrt hsn + have hroot : p.IsRoot (a + Real.sqrt (-s)) := by + rw [IsRoot, hp] + simp only [eval_add, eval_pow, eval_X, eval_mul, eval_C] + dsimp [a, s] at * + nlinarith + exact hi.not_isRoot_of_natDegree_ne_one (by omega) hroot + refine ⟨a, Real.sqrt s, ne_of_gt (Real.sqrt_pos.2 hs), ?_⟩ + rw [hp, positiveQuadratic, Real.sq_sqrt hs.le] + have haC := congrArg (C : ℝ → ℝ[X]) (show -2*a = p.coeff 1 by dsimp [a]; ring) + have hsC := congrArg (C : ℝ → ℝ[X]) (show a^2+s = p.coeff 0 by dsimp [a, s]; ring) + simp only [map_mul, map_neg, map_ofNat] at haC + simp only [map_add, map_pow] at hsC + linear_combination -X * haC - hsC + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/RealRootSignature.lean b/LeanPool/MathFin/Models/ModelFree/SVI/RealRootSignature.lean new file mode 100644 index 0000000000..b882672fe2 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/RealRootSignature.lean @@ -0,0 +1,68 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.RealRootTrace +public import LeanPool.MathFin.Models.ModelFree.SVI.RankOneSignature +public import LeanPool.MathFin.Models.ModelFree.SVI.TraceForm + +/-! # A repeated real root contributes one sign + +Part of the SVI polynomial-sign certificate (#174). + +On `ℝ[X]/((X − c)ʳ)` the weighted trace form has signature `sign (q c)`, whatever the +multiplicity `r`. + +## Main results + +* `realRootEval_aeval`: for `r > 0`, `realRootEval c r hr` sends the class of `q` in + `AdjoinRoot ((X - C c)^r)` to `q.eval c`. +* `weightedTraceForm_realRoot_signature`: for `r > 0`, the weighted trace form of `(X - C c)^r` + with weight `q` has signature `sign (q.eval c)`, whatever `r` is. + +## Tags + +repeated real root, trace form signature, multiplicity, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +theorem realRootEval_aeval (c : ℝ) (r : ℕ) (hr : 0 < r) (q : ℝ[X]) : + realRootEval c r hr (aeval (AdjoinRoot.root ((X-C c)^r)) q) = q.eval c := by + rw [AdjoinRoot.aeval_eq, realRootEval_mk] + +/-- A repeated real root contributes exactly sign(q(c)), not multiplicity + times that sign, to the weighted trace-form signature. -/ +theorem weightedTraceForm_realRoot_signature (c : ℝ) (r : ℕ) (hr : 0 < r) (q : ℝ[X]) : + formSignature (weightedTraceForm ((X-C c)^r) q).toQuadraticMap = sign (q.eval c) := by + have hf : (X-C c)^r ≠ (0 : ℝ[X]) := pow_ne_zero _ (X_sub_C_ne_zero c) + let pb := AdjoinRoot.powerBasis hf + let : FiniteDimensional ℝ (AdjoinRoot ((X-C c)^r)) := Module.Finite.of_basis pb.basis + have hQ (x : AdjoinRoot ((X-C c)^r)) : + (weightedTraceForm ((X-C c)^r) q).toQuadraticMap x = + ((r : ℝ)*q.eval c) * (realRootEval c r hr x)^2 := by + rw [LinearMap.BilinMap.toQuadraticMap_apply, weightedTraceForm_apply, + trace_realRoot_component c r hr] + simp only [map_mul, realRootEval_aeval] + ring + have hh := formSignature_rankOne (weightedTraceForm ((X-C c)^r) q).toQuadraticMap + (realRootEval c r hr).toLinearMap 1 (by simp) ((r : ℝ)*q.eval c) hQ + rw [hh] + have hrr : (0 : ℝ) < r := by exact_mod_cast hr + rcases lt_trichotomy (q.eval c) 0 with h | h | h + · simp [sign, h, not_lt_of_ge h.le, mul_neg_of_pos_of_neg hrr h, + not_lt_of_ge (mul_neg_of_pos_of_neg hrr h).le] + · simp [h, sign] + · simp [sign, h, mul_pos hrr h] + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/RealRootTrace.lean b/LeanPool/MathFin/Models/ModelFree/SVI/RealRootTrace.lean new file mode 100644 index 0000000000..6f160f5c82 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/RealRootTrace.lean @@ -0,0 +1,92 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Ring.IsFormallyReal +public import Mathlib.RingTheory.Trace.Basic +public import Mathlib.Analysis.Normed.Field.Basic + +/-! # Traces at a repeated real root + +Part of the SVI polynomial-sign certificate (#174). + +In `ℝ[X]/((X − c)ʳ)` every element differs from its value at `c` by a nilpotent, and its trace is +`r` times that value. + +## Main definitions + +* `realRootEval`: evaluation at `c`, as an `ℝ`-algebra map `AdjoinRoot ((X - C c)^r) → ℝ` for + `r > 0`. + +## Main results + +* `realRootEval_mk`: `realRootEval` sends the class of `p` to `p.eval c`. +* `realRoot_nilpotent_remainder`: every element of `AdjoinRoot ((X - C c)^r)` differs from the + image of its value at `c` by a nilpotent. +* `trace_realRoot_component`: the algebra trace of `x` in `AdjoinRoot ((X - C c)^r)` is + `r * realRootEval c r hr x`. + +## Tags + +repeated root, nilpotent trace, quotient ring trace, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +/-- Evaluation at `c` on `ℝ[X]/((X − c)ʳ)`, for `r > 0`. -/ +noncomputable def realRootEval (c : ℝ) (r : ℕ) (hr : 0 < r) : + AdjoinRoot ((X - C c)^r) →ₐ[ℝ] ℝ := + AdjoinRoot.liftAlgHom _ (Algebra.ofId ℝ ℝ) c (by simp [ne_of_gt hr]) + +theorem realRootEval_mk (c : ℝ) (r : ℕ) (hr : 0 < r) (p : ℝ[X]) : + realRootEval c r hr (AdjoinRoot.mk ((X-C c)^r) p) = p.eval c := by + simp [realRootEval, AdjoinRoot.liftAlgHom_mk] + +/-- In a repeated real-root component, every element differs from its value +at the root by a nilpotent. -/ +theorem realRoot_nilpotent_remainder (c : ℝ) (r : ℕ) (hr : 0 < r) + (x : AdjoinRoot ((X - C c) ^ r)) : + IsNilpotent (x - algebraMap ℝ _ (realRootEval c r hr x)) := by + induction x using AdjoinRoot.induction_on with + | ih p => + rw [realRootEval_mk] + have hnil : IsNilpotent (AdjoinRoot.mk ((X-C c)^r) (X-C c)) := by + refine ⟨r, ?_⟩ + rw [← map_pow, AdjoinRoot.mk_self] + have hdiv : X-C c ∣ p-C (p.eval c) := dvd_iff_isRoot.mpr (by simp [IsRoot]) + obtain ⟨q, hq⟩ := hdiv + have he : AdjoinRoot.mk ((X-C c)^r) p - algebraMap ℝ _ (p.eval c) = + AdjoinRoot.mk ((X-C c)^r) (p-C (p.eval c)) := by simp + rw [he, hq, map_mul] + obtain ⟨m, hm⟩ := hnil + exact ⟨m, by rw [mul_pow, hm, zero_mul]⟩ + +/-- A root of multiplicity r contributes r times its evaluation to the +algebra trace. This is the key boundary-safe multiplicity identity. -/ +theorem trace_realRoot_component (c : ℝ) (r : ℕ) (hr : 0 < r) + (x : AdjoinRoot ((X - C c) ^ r)) : + Algebra.trace ℝ _ x = (r : ℝ) * realRootEval c r hr x := by + have hf : (X-C c)^r ≠ (0 : ℝ[X]) := pow_ne_zero _ (X_sub_C_ne_zero c) + let pb := AdjoinRoot.powerBasis hf + let : Module.Free ℝ (AdjoinRoot ((X-C c)^r)) := Module.Free.of_basis pb.basis + have hz := (Algebra.isNilpotent_trace_of_isNilpotent + (R := ℝ) (realRoot_nilpotent_remainder c r hr x)).eq_zero + rw [map_sub, Algebra.trace_algebraMap] at hz + have hdim : Module.finrank ℝ (AdjoinRoot ((X-C c)^r)) = r := by + rw [pb.finrank] + simp [pb, AdjoinRoot.powerBasis_dim, natDegree_pow] + rw [hdim, nsmul_eq_mul] at hz + exact sub_eq_zero.mp hz + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/Reduction.lean b/LeanPool/MathFin/Models/ModelFree/SVI/Reduction.lean new file mode 100644 index 0000000000..f700f931ff --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/Reduction.lean @@ -0,0 +1,179 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Order.Star.Real + +/-! # Raw SVI and the rationalised Durrleman condition + +Part of the SVI polynomial-sign certificate (#174). + +Rationalization of the smooth raw-SVI Durrleman expression. +The first and second slope expressions are explicit; their identification with +analytic derivatives is proved in Derivatives.lean. + +## Main definitions + +* `Params`: the five raw SVI parameters `(a, b, ρ, m, σ)`, with no sign conditions built in. +* `variance`: raw SVI total variance `a + b(ρ(k - m) + √((k - m)² + σ²))` at log-strike `k`. +* `slope`, `curvature`: the explicit first and second derivatives of `variance`. +* `durrleman`: Durrleman's function `(1 - k w'/(2w))² - (w'²/4)(1/w + 1/4) + w''/2`. +* `strike`: the log-strike `K p t / (2t)` parametrised by `t > 0`. +* `numerator`: the rationalised Durrleman numerator, a polynomial in `t`. + +## Main results + +* `variance_at_strike`, `slope_at_strike`, `curvature_at_strike`: for `σ > 0` and `t > 0`, the + values of `variance`, `slope` and `curvature` at `strike p t`. +* `durrleman_at_strike`: for `σ > 0`, `t > 0` and `A p t ≠ 0`, + `durrleman p (strike p t) = numerator p t / (16σ (A p t)² (D t)³)`. +* `sign_at_strike`: for `σ > 0` and positive variance at `strike p t`, + `durrleman p (strike p t) ≥ 0` iff `numerator p t ≥ 0`. +* `strike_surjective`: for `σ > 0`, every `k` is `strike p t` for some `t > 0`. +* `durrleman_nonneg_iff`: for `σ > 0` and positive variance everywhere, `durrleman p k ≥ 0` for all + `k` iff `numerator p t ≥ 0` for all `t > 0`. + +## Tags + +raw SVI, Durrleman condition, rationalization, variance slope, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI + +/-- The five parameters `(a, b, ρ, m, σ)` of a raw SVI slice. No sign conditions are built in. -/ +structure Params where + /-- The level `a`. -/ + a : ℝ + /-- The wing scale `b`. -/ + b : ℝ + /-- The skew `ρ`. -/ + rho : ℝ + /-- The centre `m`. -/ + m : ℝ + /-- The curvature scale `σ`. -/ + sigma : ℝ + +/-- Raw SVI total variance `w(k) = a + b(ρ(k − m) + √((k − m)² + σ²))` at log-strike `k`. -/ +noncomputable def variance (p : Params) (k : ℝ) : ℝ := + p.a + p.b * (p.rho * (k - p.m) + Real.sqrt ((k - p.m)^2 + p.sigma^2)) +/-- The explicit first derivative `w'(k)` (`Derivatives.variance_hasDerivAt`, for `σ > 0`). -/ +noncomputable def slope (p : Params) (k : ℝ) : ℝ := + p.b * (p.rho + (k - p.m) / Real.sqrt ((k - p.m)^2 + p.sigma^2)) +/-- The explicit second derivative `w''(k)` (`Derivatives.slope_hasDerivAt`, for `σ > 0`). -/ +noncomputable def curvature (p : Params) (k : ℝ) : ℝ := + p.b * p.sigma^2 / (Real.sqrt ((k - p.m)^2 + p.sigma^2))^3 +/-- Durrleman's function `g = (1 − k w'/(2w))² − (w'²/4)(1/w + 1/4) + w''/2`. It is meaningful +only where `w(k) > 0`: division by zero is `0` in Lean. -/ +noncomputable def durrleman (p : Params) (k : ℝ) : ℝ := + (1 - k * slope p k / (2 * variance p k))^2 - + (slope p k)^2 / 4 * (1 / variance p k + 1 / 4) + curvature p k / 2 + +/-- The rationalising factor `1 + t²`. -/ +def D (t : ℝ) : ℝ := 1 + t^2 +/-- The numerator of the variance in the parameter `t`: `w = A/(2t)` at `strike p t`. -/ +def A (p : Params) (t : ℝ) : ℝ := + p.b * p.sigma * (1 + p.rho) * t^2 + 2 * p.a * t + p.b * p.sigma * (1 - p.rho) +/-- The numerator of the slope in the parameter `t`: `w' = B/D` at `strike p t`. -/ +def B (p : Params) (t : ℝ) : ℝ := + p.b * ((1 + p.rho) * t^2 - (1 - p.rho)) +/-- The numerator of the log-strike in the parameter `t`. -/ +def K (p : Params) (t : ℝ) : ℝ := p.sigma * t^2 + 2 * p.m * t - p.sigma +/-- The log-strike `K p t/(2t)` parametrised by `t > 0`. -/ +noncomputable def strike (p : Params) (t : ℝ) : ℝ := K p t / (2 * t) +/-- The rationalised Durrleman numerator, a polynomial in `t` with the sign of `g` at `strike p t` +(`sign_at_strike`). -/ +def numerator (p : Params) (t : ℝ) : ℝ := + 4 * p.sigma * D t * (2 * A p t * D t - K p t * B p t)^2 - + p.sigma * A p t * (B p t)^2 * D t * (A p t + 8*t) + + 64 * p.b * t^3 * (A p t)^2 + +theorem D_pos (t : ℝ) : 0 < D t := by unfold D; positivity + +theorem sqrt_at_strike (p : Params) (hs : 0 < p.sigma) (t : ℝ) (ht : 0 < t) : + Real.sqrt ((strike p t - p.m)^2 + p.sigma^2) = p.sigma * D t / (2*t) := by + apply (Real.sqrt_eq_iff_eq_sq (by positivity) + (le_of_lt (div_pos (mul_pos hs (D_pos t)) (by positivity)))).mpr + unfold strike K D + field_simp + ring + +theorem variance_at_strike (p : Params) (hs : 0 < p.sigma) (t : ℝ) (ht : 0 < t) : + variance p (strike p t) = A p t / (2*t) := by + unfold variance + rw [sqrt_at_strike p hs t ht] + unfold strike K D A + field_simp + ring + +theorem slope_at_strike (p : Params) (hs : 0 < p.sigma) (t : ℝ) (ht : 0 < t) : + slope p (strike p t) = B p t / D t := by + unfold slope + rw [sqrt_at_strike p hs t ht] + have hd := ne_of_gt (D_pos t) + unfold strike K B + field_simp [ne_of_gt hs, ne_of_gt ht, hd] + unfold D + ring + +theorem curvature_at_strike (p : Params) (hs : 0 < p.sigma) (t : ℝ) (ht : 0 < t) : + curvature p (strike p t) = 8 * p.b * t^3 / (p.sigma * (D t)^3) := by + unfold curvature + rw [sqrt_at_strike p hs t ht] + field_simp + ring + +theorem durrleman_at_strike (p : Params) (hs : 0 < p.sigma) (t : ℝ) + (ht : 0 < t) (ha : A p t ≠ 0) : + durrleman p (strike p t) = numerator p t / (16*p.sigma*(A p t)^2*(D t)^3) := by + unfold durrleman + rw [variance_at_strike p hs t ht, slope_at_strike p hs t ht, + curvature_at_strike p hs t ht] + unfold strike numerator + field_simp [ha, ne_of_gt ht, ne_of_gt hs, ne_of_gt (D_pos t)] + ring + +theorem sign_at_strike (p : Params) (hs : 0 < p.sigma) (t : ℝ) + (ht : 0 < t) (hw : 0 < variance p (strike p t)) : + 0 ≤ durrleman p (strike p t) ↔ 0 ≤ numerator p t := by + rw [variance_at_strike p hs t ht] at hw + have ha : 0 < A p t := (div_pos_iff.mp hw).resolve_right (by intro h; linarith [h.2]) |>.1 + rw [durrleman_at_strike p hs t ht (ne_of_gt ha)] + have hd := D_pos t + exact (le_div_iff₀ (by positivity)).trans (by simp) + +/-- Every finite strike is represented by a positive parameter. -/ +theorem strike_surjective (p : Params) (hs : 0 < p.sigma) (k : ℝ) : + ∃ t : ℝ, 0 < t ∧ strike p t = k := by + let y := (k - p.m) / p.sigma + let z := Real.sqrt (1 + y^2) + have hz : z^2 = 1 + y^2 := Real.sq_sqrt (by positivity) + have hz0 : 0 ≤ z := Real.sqrt_nonneg _ + have ht : 0 < y + z := by nlinarith + refine ⟨y + z, ht, ?_⟩ + have hy : p.sigma * y = k - p.m := by dsimp [y]; field_simp + unfold strike K + apply (div_eq_iff (by positivity : 2 * (y + z) ≠ 0)).mpr + nlinarith [sq_nonneg (y + z)] + +/-- The SVI-specific global reduction, including non-generic parameters. -/ +theorem durrleman_nonneg_iff (p : Params) (hs : 0 < p.sigma) + (hw : ∀ k : ℝ, 0 < variance p k) : + (∀ k : ℝ, 0 ≤ durrleman p k) ↔ (∀ t : ℝ, 0 < t → 0 ≤ numerator p t) := by + constructor + · intro h t ht + exact (sign_at_strike p hs t ht (hw _)).mp (h _) + · intro h k + obtain ⟨t, ht, rfl⟩ := strike_surjective p hs k + exact (sign_at_strike p hs t ht (hw _)).mpr (h t ht) + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/SigmaZeroCertificate.lean b/LeanPool/MathFin/Models/ModelFree/SVI/SigmaZeroCertificate.lean new file mode 100644 index 0000000000..75daaf28ca --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/SigmaZeroCertificate.lean @@ -0,0 +1,164 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.SigmaZeroDerivatives +public import LeanPool.MathFin.Models.ModelFree.SVI.QuadraticRay + +/-! # The zero-scale certificate + +Part of the SVI polynomial-sign certificate (#174). + +For `σ = 0`, `b ≥ 0`, `ρ² ≤ 1` and `a > 0` the slice is piecewise linear, and `g(k) ≥ 0` for +every `k ≠ m` is equivalent to two quadratics in the variance `w`, one per wing, being nonnegative +on the ray `w ≥ a` (`sigmaZeroCertificate_iff`). + +## Main definitions + +* `sigmaZeroBranchQuadratic`: the quadratic in the variance `w` whose sign is that of `g` on a + wing of slope `s` at zero scale. +* `sigmaZeroBranchCondition`: the sign conditions under which that quadratic is nonnegative on + the ray `w ≥ a`. +* `sigmaZeroCertificate`: the branch condition on both wings. + +## Main results + +* `sigmaZeroBranchCondition_iff`: `sigmaZeroBranchCondition p s` iff the branch quadratic is + nonnegative for all `w ≥ p.a`. +* `sigmaZeroBranchCondition_zero`: for `a > 0`, the condition holds for slope `0`. +* `sigmaZeroCertificate_iff`: for `σ = 0`, `b ≥ 0`, `1 - ρ² ≥ 0` and `a > 0`, + `sigmaZeroCertificate p` iff `durrleman p k ≥ 0` for every `k ≠ m`. + +## Tags + +zero-scale SVI, piecewise linear smile, Durrleman condition, butterfly arbitrage, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI + +/-- The quadratic in the variance `w` whose sign is that of `g` on a wing of slope `s` at zero +scale. -/ +noncomputable def sigmaZeroBranchQuadratic (p : Params) (s w : ℝ) : ℝ := + (1-s^2/4)*w^2+(2*(p.a-s*p.m)-s^2)*w+(p.a-s*p.m)^2 + +/-- The sign conditions under which the branch quadratic is nonnegative on the ray `w ≥ a` +(`sigmaZeroBranchCondition_iff`). -/ +noncomputable def sigmaZeroBranchCondition (p : Params) (s : ℝ) : Prop := + let u := 1-s^2/4 + let v := 2*(p.a-s*p.m)-s^2 + let z := (p.a-s*p.m)^2 + 0 ≤ u ∧ 0 ≤ u*p.a^2+v*p.a+z ∧ + ((u=0 ∧ 0≤v) ∨ (0 0`, the one-sided derivatives of `blackCall p` at `exp m` are + `branchDelta p (leftSlope p) m` and `branchDelta p (rightSlope p) m`. +* `sigmaZero_delta_jump`: the jump `branchDelta p (rightSlope p) m - branchDelta p (leftSlope p) m` + equals `gaussianPDFReal 0 1 (dmi m w) * b / rootVariance p m` with `w = variance p m`. +* `sigmaZero_delta_jump_nonneg`: for `b ≥ 0` and `variance p m > 0`, the jump is nonnegative. +* `sigmaZero_blackCall_convex_iff`: for `σ = 0`, `b ≥ 0` and `variance p k > 0` for all `k`, + `blackCall p` is convex on `(0, ∞)` iff `durrleman p k ≥ 0` for every `k ≠ m`. +* `sigmaZero_bsSmile_convex_iff`: the same equivalence for `bsSmile p`. + +## Tags + +zero-scale SVI, call convexity at kink, one-sided derivative jump, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Real ProbabilityTheory Set +open ForwardSmile (dpl dmi blackForm) + +theorem sigmaZero_blackCall_hasDerivAt (p : Params) (hs : p.sigma = 0) + (K : ℝ) (hK : 0 < K) (hk : Real.log K ≠ p.m) + (hw : 0 < variance p (Real.log K)) : + HasDerivAt (blackCall p) (strikeDelta p K) K := by + have h := (blackForm_hasDerivAt p (Real.log K) + (sigmaZero_variance_hasDerivAt p hs _ hk) hw).comp K (Real.hasDerivAt_log (ne_of_gt hK)) + convert h using 1 <;> try rfl + simp only [Real.exp_log hK, strikeDelta] + field_simp + +theorem sigmaZero_strikeDelta_hasDerivAt (p : Params) (hs : p.sigma = 0) + (K : ℝ) (hK : 0 < K) (hk : Real.log K ≠ p.m) + (hw : 0 < variance p (Real.log K)) : + HasDerivAt (strikeDelta p) (strikeDensity p K) K := by + have h := (blackDelta_hasDerivAt p (Real.log K) (sigmaZero_variance_hasDerivAt p hs _ hk) + (sigmaZero_slope_hasDerivAt p hs _ hk) hw).comp K + (Real.hasDerivAt_log (ne_of_gt hK)) + convert h using 1 <;> try rfl + dsimp [strikeDensity] + ring + +theorem sigmaZero_blackCall_hasDerivWithinAt_left (p : Params) (hs : p.sigma = 0) + (ha : 0 < p.a) : HasDerivWithinAt (blackCall p) + (branchDelta p (leftSlope p) p.m) (Iic (Real.exp p.m)) (Real.exp p.m) := by + have hw : 0 < variance p p.m := by rwa [sigmaZero_variance_at_m p hs] + have h := blackForm_hasDerivWithinAt p (leftSlope p) p.m (Iic p.m) hw + (sigmaZero_variance_hasDerivWithinAt_left p hs) + have hm : MapsTo Real.log (Iic (Real.exp p.m) ∩ Ioi 0) (Iic p.m) := by + intro x hx + exact (Real.log_le_iff_le_exp hx.2).mpr hx.1 + have hc := h.comp_of_eq (Real.exp p.m) + (Real.hasDerivAt_log (ne_of_gt (Real.exp_pos p.m))).hasDerivWithinAt hm + (Real.log_exp p.m).symm + have he : Real.exp p.m * branchDelta p (leftSlope p) p.m * (Real.exp p.m)⁻¹ = + branchDelta p (leftSlope p) p.m := by field_simp + rw [he] at hc + exact (hasDerivWithinAt_inter (Ioi_mem_nhds (Real.exp_pos p.m))).mp hc + +theorem sigmaZero_blackCall_hasDerivWithinAt_right (p : Params) (hs : p.sigma = 0) + (ha : 0 < p.a) : HasDerivWithinAt (blackCall p) + (branchDelta p (rightSlope p) p.m) (Ici (Real.exp p.m)) (Real.exp p.m) := by + have hw : 0 < variance p p.m := by rwa [sigmaZero_variance_at_m p hs] + have h := blackForm_hasDerivWithinAt p (rightSlope p) p.m (Ici p.m) hw + (sigmaZero_variance_hasDerivWithinAt_right p hs) + have hm : MapsTo Real.log (Ici (Real.exp p.m)) (Ici p.m) := by + intro x hx + exact (Real.le_log_iff_exp_le (lt_of_lt_of_le (Real.exp_pos _) hx)).mpr hx + have hc := h.comp_of_eq (Real.exp p.m) + (Real.hasDerivAt_log (ne_of_gt (Real.exp_pos p.m))).hasDerivWithinAt hm + (Real.log_exp p.m).symm + convert hc using 1 <;> first | rfl | field_simp + +theorem sigmaZero_delta_jump (p : Params) : + branchDelta p (rightSlope p) p.m - branchDelta p (leftSlope p) p.m = + gaussianPDFReal 0 1 (dmi p.m (variance p p.m)) * p.b / rootVariance p p.m := by + unfold branchDelta leftSlope rightSlope + ring + +theorem sigmaZero_delta_jump_nonneg (p : Params) (hb : 0 ≤ p.b) + (hw : 0 < variance p p.m) : + branchDelta p (leftSlope p) p.m ≤ branchDelta p (rightSlope p) p.m := by + have hp := (gaussianPDFReal_pos 0 1 (dmi p.m (variance p p.m)) (by norm_num)).le + have hr := (rootVariance_pos p p.m hw).le + have hs : leftSlope p ≤ rightSlope p := by unfold leftSlope rightSlope; nlinarith + unfold branchDelta + exact sub_le_sub_right (div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hs hp) + (mul_nonneg (by norm_num) hr)) _ + +theorem variance_continuous (p : Params) : Continuous (variance p) := by + unfold variance + fun_prop + +theorem blackCall_continuousOn (p : Params) (hw : ∀ k : ℝ, 0 < variance p k) : + ContinuousOn (blackCall p) (Ioi 0) := by + have hr : Continuous (rootVariance p) := (variance_continuous p).sqrt + have hn : ∀ k, rootVariance p k ≠ 0 := fun k ↦ ne_of_gt (rootVariance_pos p k (hw k)) + have hm : Continuous (fun k ↦ dmi k (variance p k)) := by + simp only [dmi_eq_rootVariance] + exact (continuous_id.neg.div hr hn).sub (hr.div_const 2) + have hp : Continuous (fun k ↦ dpl k (variance p k)) := by + simp only [dpl_eq_rootVariance] + exact (continuous_id.neg.div hr hn).add (hr.div_const 2) + have hphi : Continuous MathFin.Phi := continuous_iff_continuousAt.mpr + (fun x ↦ (MathFin.hasDerivAt_Phi x).continuousAt) + have hc : Continuous (fun k ↦ blackForm k (variance p k)) := (hphi.comp hp).sub + (Real.continuous_exp.mul (hphi.comp hm)) + exact hc.comp_continuousOn (Real.continuousOn_log.mono (fun x hx ↦ ne_of_gt hx)) + +/-- Convexity on either closed side follows from the ordinary density there. -/ +theorem sigmaZero_convexOn_of_nonneg (p : Params) (hs : p.sigma = 0) + (hw : ∀ k : ℝ, 0 < variance p k) (D : Set ℝ) (hD : Convex ℝ D) + (hpos : D ⊆ Ioi 0) (hk : ∀ K ∈ interior D, Real.log K ≠ p.m) + (hg : ∀ k : ℝ, k ≠ p.m → 0 ≤ durrleman p k) : + ConvexOn ℝ D (blackCall p) := by + apply convexOn_of_hasDerivWithinAt2_nonneg hD + ((blackCall_continuousOn p hw).mono hpos) + (f' := strikeDelta p) (f'' := strikeDensity p) + · intro K hK + exact (sigmaZero_blackCall_hasDerivAt p hs K (hpos (interior_subset hK)) + (hk K hK) (hw _)).hasDerivWithinAt + · intro K hK + exact (sigmaZero_strikeDelta_hasDerivAt p hs K (hpos (interior_subset hK)) + (hk K hK) (hw _)).hasDerivWithinAt + · intro K hK + exact (strikeDensity_nonneg_iff p K (hpos (interior_subset hK)) (hw _)).mpr + (hg _ (hk K hK)) + +/-- The density criterion on both open wings, with the automatically +nonnegative vega-weighted derivative jump at the kink, is exactly convexity. -/ +theorem sigmaZero_blackCall_convex_iff (p : Params) (hs : p.sigma = 0) + (hb : 0 ≤ p.b) (hw : ∀ k : ℝ, 0 < variance p k) : + ConvexOn ℝ (Ioi 0) (blackCall p) ↔ + ∀ k : ℝ, k ≠ p.m → 0 ≤ durrleman p k := by + constructor + · intro hc k hk + let D : Set ℝ := Ioi 0 ∩ {K | Real.log K ≠ p.m} + have hDopen : IsOpen D := by + have he : D = Ioi 0 \ {Real.exp p.m} := by + ext K + simp only [D, mem_inter_iff, mem_Ioi, mem_ofPred_eq, mem_sdiff, + mem_singleton_iff] + constructor + · rintro ⟨hK, hne⟩ + exact ⟨hK, fun hh ↦ hne (by rw [hh, Real.log_exp])⟩ + · rintro ⟨hK, hne⟩ + exact ⟨hK, fun hh ↦ hne (by rw [← hh, Real.exp_log hK])⟩ + rw [he] + exact isOpen_Ioi.sdiff isClosed_singleton + have hd (K : ℝ) (hK : K ∈ D) := + sigmaZero_blackCall_hasDerivAt p hs K hK.1 hK.2 (hw _) + have hm : MonotoneOn (strikeDelta p) D := by + intro x hx y hy hxy + rcases eq_or_lt_of_le hxy with rfl | hxy + · rfl + rw [← (hd x hx).deriv, ← (hd y hy).deriv] + exact (hc.deriv_le_slope hx.1 hy.1 hxy (hd x hx).differentiableAt).trans + (hc.slope_le_deriv hx.1 hy.1 hxy (hd y hy).differentiableAt) + have he : Real.exp k ∈ D := ⟨Real.exp_pos _, by simpa using hk⟩ + have hh : 0 ≤ derivWithin (strikeDelta p) D (Real.exp k) := hm.derivWithin_nonneg + rw [(sigmaZero_strikeDelta_hasDerivAt p hs _ he.1 he.2 (hw _)).hasDerivWithinAt.derivWithin + (hDopen.uniqueDiffOn _ he)] at hh + have hg := (strikeDensity_nonneg_iff p _ he.1 (hw _)).mp hh + simpa using hg + · intro hg + have ha : 0 < p.a := by simpa [sigmaZero_variance_at_m p hs] using hw p.m + apply convexOn_Ioi_of_convex_pieces (Real.exp_pos p.m) + · apply sigmaZero_convexOn_of_nonneg p hs hw (Ioc 0 (Real.exp p.m)) + (convex_Ioc _ _) (fun _ h ↦ h.1) _ hg + intro K hK + rw [interior_Ioc] at hK + exact ne_of_lt ((Real.log_lt_iff_lt_exp hK.1).mpr hK.2) + · apply sigmaZero_convexOn_of_nonneg p hs hw (Ici (Real.exp p.m)) + (convex_Ici _) (fun _ h ↦ lt_of_lt_of_le (Real.exp_pos _) h) _ hg + intro K hK + rw [interior_Ici] at hK + exact ne_of_gt ((Real.lt_log_iff_exp_lt (lt_trans (Real.exp_pos _) hK)).mpr hK) + · exact sigmaZero_blackCall_hasDerivWithinAt_left p hs ha + · exact sigmaZero_blackCall_hasDerivWithinAt_right p hs ha + · exact sigmaZero_delta_jump_nonneg p hb (hw _) + +theorem sigmaZero_bsSmile_convex_iff (p : Params) (hs : p.sigma = 0) + (hb : 0 ≤ p.b) (hw : ∀ k : ℝ, 0 < variance p k) : + ConvexOn ℝ (Ioi 0) (bsSmile p) ↔ + ∀ k : ℝ, k ≠ p.m → 0 ≤ durrleman p k := by + have he : EqOn (blackCall p) (bsSmile p) (Ioi 0) := + fun K hK ↦ blackCall_eq_bsSmile p K hK (hw _) + constructor + · intro hc + exact (sigmaZero_blackCall_convex_iff p hs hb hw).mp (hc.congr he.symm) + · intro hg + exact ((sigmaZero_blackCall_convex_iff p hs hb hw).mpr hg).congr he + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/SigmaZeroDerivatives.lean b/LeanPool/MathFin/Models/ModelFree/SVI/SigmaZeroDerivatives.lean new file mode 100644 index 0000000000..533955b2a0 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/SigmaZeroDerivatives.lean @@ -0,0 +1,192 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.BlackSmile + +/-! # The zero-scale slice and its derivatives + +Part of the SVI polynomial-sign certificate (#174). + +The piecewise-affine SVI variance at σ = 0: ordinary derivatives on +the two open wings and one-sided derivatives at their common endpoint. + +## Main definitions + +* `leftSlope`, `rightSlope`: the slopes `b(ρ - 1)` and `b(ρ + 1)` of the zero-scale variance left + and right of `m`. +* `branchDelta`: `blackDelta` with the variance slope replaced by a constant wing slope `s`. + +## Main results + +* `sigmaZero_variance_hasDerivAt`, `sigmaZero_slope_hasDerivAt`: at `σ = 0` and `k ≠ m`, `slope` + and `curvature` are the derivatives of `variance` and `slope`. +* `sigmaZero_variance_left`, `sigmaZero_variance_right`: at `σ = 0`, `variance p k` is + `a + leftSlope p * (k - m)` for `k ≤ m` and `a + rightSlope p * (k - m)` for `k ≥ m`. +* `leftSlope_nonpos`, `rightSlope_nonneg`: for `b ≥ 0` and `1 - ρ² ≥ 0`, `leftSlope p ≤ 0` and + `0 ≤ rightSlope p`. +* `sigmaZero_variance_ge`, `sigmaZero_variance_pos_iff`: under the same conditions at `σ = 0`, + `variance p k ≥ a`, and the variance is positive everywhere iff `a > 0`. +* `sigmaZero_variance_hasDerivWithinAt_left`, `sigmaZero_variance_hasDerivWithinAt_right`: the + one-sided derivatives of `variance p` at `m` are `leftSlope p` and `rightSlope p`. +* `blackForm_hasDerivWithinAt`: the log-price chain rule holds with a one-sided variance + derivative `s`, with derivative `exp k * branchDelta p s k`. + +## Tags + +zero-scale SVI, piecewise affine variance, one-sided derivatives, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Real ProbabilityTheory Set +open ForwardSmile (dpl dmi blackForm) + +theorem sigmaZero_variance_hasDerivAt (p : Params) (hs : p.sigma = 0) (k : ℝ) (hk : k ≠ p.m) : + HasDerivAt (variance p) (slope p k) k := by + have hpos : 0 < (k - p.m)^2 + + p.sigma^2 := by rw [hs]; simpa using sq_pos_of_ne_zero (sub_ne_zero.mpr hk) + have hx := (hasDerivAt_id k).sub_const p.m + have hr := ((hx.pow 2).add_const (p.sigma^2)).sqrt (ne_of_gt hpos) + have h := ((hx.const_mul p.rho).add hr).const_mul p.b |>.const_add p.a + convert h using 1 <;> first | rfl | (dsimp [slope]; ring) + +theorem sigmaZero_slope_hasDerivAt (p : Params) (hs : p.sigma = 0) (k : ℝ) (hk : k ≠ p.m) : + HasDerivAt (slope p) (curvature p k) k := by + have hpos : 0 < (k - p.m)^2 + + p.sigma^2 := by rw [hs]; simpa using sq_pos_of_ne_zero (sub_ne_zero.mpr hk) + have hroot : Real.sqrt ((k - p.m)^2 + p.sigma^2) ≠ 0 := + ne_of_gt (Real.sqrt_pos.mpr hpos) + have hx := (hasDerivAt_id k).sub_const p.m + have hr := ((hx.pow 2).add_const (p.sigma^2)).sqrt (ne_of_gt hpos) + have h := ((hx.div hr hroot).const_add p.rho).const_mul p.b + convert h using 1 <;> try rfl + · dsimp [curvature] + have he := Real.sq_sqrt hpos.le + field_simp + rw [he] + ring + +/-- The slope `b(ρ − 1)` of the zero-scale variance left of `m`. -/ +def leftSlope (p : Params) : ℝ := p.b * (p.rho - 1) +/-- The slope `b(ρ + 1)` of the zero-scale variance right of `m`. -/ +def rightSlope (p : Params) : ℝ := p.b * (p.rho + 1) + +theorem sigmaZero_variance_left (p : Params) (hs : p.sigma = 0) (k : ℝ) + (hk : k ≤ p.m) : variance p k = p.a + leftSlope p * (k-p.m) := by + simp only [variance, hs, sq, mul_zero, add_zero, Real.sqrt_mul_self_eq_abs, + abs_of_nonpos (sub_nonpos.mpr hk), leftSlope] + ring + +theorem sigmaZero_variance_right (p : Params) (hs : p.sigma = 0) (k : ℝ) + (hk : p.m ≤ k) : variance p k = p.a + rightSlope p * (k-p.m) := by + simp only [variance, hs, sq, mul_zero, add_zero, Real.sqrt_mul_self_eq_abs, + abs_of_nonneg (sub_nonneg.mpr hk), rightSlope] + ring + +theorem sigmaZero_variance_at_m (p : Params) (hs : p.sigma = 0) : + variance p p.m = p.a := by simp [variance, hs] + +theorem leftSlope_nonpos (p : Params) (hb : 0 ≤ p.b) (hr : 0 ≤ 1 - p.rho ^ 2) : + leftSlope p ≤ 0 := by + have : p.rho ≤ 1 := by nlinarith [sq_nonneg (p.rho-1)] + exact mul_nonpos_of_nonneg_of_nonpos hb (sub_nonpos.mpr this) + +theorem rightSlope_nonneg (p : Params) (hb : 0 ≤ p.b) (hr : 0 ≤ 1 - p.rho ^ 2) : + 0 ≤ rightSlope p := by + have : -1 ≤ p.rho := by nlinarith [sq_nonneg (p.rho+1)] + exact mul_nonneg hb (by linarith) + +theorem sigmaZero_variance_ge (p : Params) (hs : p.sigma = 0) + (hb : 0 ≤ p.b) (hr : 0 ≤ 1 - p.rho ^ 2) (k : ℝ) : p.a ≤ variance p k := by + rcases le_total k p.m with hk | hk + · rw [sigmaZero_variance_left p hs k hk] + have := mul_nonneg_of_nonpos_of_nonpos (leftSlope_nonpos p hb hr) (sub_nonpos.mpr hk) + linarith + · rw [sigmaZero_variance_right p hs k hk] + have := mul_nonneg (rightSlope_nonneg p hb hr) (sub_nonneg.mpr hk) + linarith + +theorem sigmaZero_variance_pos_iff (p : Params) (hs : p.sigma = 0) + (hb : 0 ≤ p.b) (hr : 0 ≤ 1 - p.rho ^ 2) : + (∀ k : ℝ, 0 < variance p k) ↔ 0 < p.a := by + constructor + · intro h + simpa [sigmaZero_variance_at_m p hs] using h p.m + · intro ha k + exact lt_of_lt_of_le ha (sigmaZero_variance_ge p hs hb hr k) + +theorem sigmaZero_slope_left (p : Params) (hs : p.sigma = 0) (k : ℝ) + (hk : k < p.m) : slope p k = leftSlope p := by + have hn : k-p.m ≠ 0 := sub_ne_zero.mpr (ne_of_lt hk) + simp only [slope, hs, sq, mul_zero, add_zero, Real.sqrt_mul_self_eq_abs, + abs_of_neg (sub_neg.mpr hk), div_neg, div_self hn, leftSlope] + ring + +theorem sigmaZero_slope_right (p : Params) (hs : p.sigma = 0) (k : ℝ) + (hk : p.m < k) : slope p k = rightSlope p := by + have hn : k-p.m ≠ 0 := sub_ne_zero.mpr (ne_of_gt hk) + simp only [slope, hs, sq, mul_zero, add_zero, Real.sqrt_mul_self_eq_abs, + abs_of_pos (sub_pos.mpr hk), div_self hn, rightSlope] + +theorem sigmaZero_curvature (p : Params) (hs : p.sigma = 0) (k : ℝ) : + curvature p k = 0 := by simp [curvature, hs] + +/-- `blackDelta` with the variance slope replaced by the constant slope `s` of a wing. -/ +noncomputable def branchDelta (p : Params) (s k : ℝ) : ℝ := + gaussianPDFReal 0 1 (dmi k (variance p k)) * s / (2*rootVariance p k) - + MathFin.Phi (dmi k (variance p k)) + +/-- The log-price chain rule only needs a one-sided variance derivative. -/ +theorem blackForm_hasDerivWithinAt (p : Params) (s k : ℝ) (S : Set ℝ) + (hw : 0 < variance p k) (hv : HasDerivWithinAt (variance p) s S k) : + HasDerivWithinAt (fun k ↦ blackForm k (variance p k)) (Real.exp k * branchDelta p s k) S + k := by + have hr : HasDerivWithinAt (rootVariance p) (s / (2*rootVariance p k)) S k := + hv.sqrt (ne_of_gt hw) + have hn := ne_of_gt (rootVariance_pos p k hw) + let dm := -1 / rootVariance p k + k*s / (2*(rootVariance p k)^3) - s / (4*rootVariance p k) + have hm : HasDerivWithinAt (fun k ↦ dmi k (variance p k)) dm S k := by + have h := (((hasDerivWithinAt_id k S).neg).div hr hn).sub (hr.div_const 2) + simp only [dmi_eq_rootVariance] + convert h using 1 <;> try rfl + dsimp [dm] + field_simp + ring + have hp : HasDerivWithinAt (fun k ↦ dpl k (variance p k)) (dm + s / (2*rootVariance p k)) S + k := by + convert hm.add hr using 1 + funext x + simp only [dpl_eq_rootVariance, dmi_eq_rootVariance, Pi.add_apply] + ring + have hp' := (MathFin.hasDerivAt_Phi (dpl k (variance p k))).comp_hasDerivWithinAt k hp + have hm' := (MathFin.hasDerivAt_Phi (dmi k (variance p k))).comp_hasDerivWithinAt k hm + have h := hp'.sub ((Real.hasDerivAt_exp k).hasDerivWithinAt.mul hm') + convert h using 1 <;> try rfl + rw [← ForwardSmile.exp_mul_pdf_dmi hw] + dsimp [branchDelta] + ring + +theorem sigmaZero_variance_hasDerivWithinAt_left (p : Params) (hs : p.sigma = 0) : + HasDerivWithinAt (variance p) (leftSlope p) (Iic p.m) p.m := by + have h := (((hasDerivAt_id p.m).sub_const p.m).const_mul (leftSlope p)).const_add p.a + simpa using (h.hasDerivWithinAt (s := Iic p.m)).congr + (fun k hk ↦ sigmaZero_variance_left p hs k hk) + (sigmaZero_variance_left p hs p.m le_rfl) + +theorem sigmaZero_variance_hasDerivWithinAt_right (p : Params) (hs : p.sigma = 0) : + HasDerivWithinAt (variance p) (rightSlope p) (Ici p.m) p.m := by + have h := (((hasDerivAt_id p.m).sub_const p.m).const_mul (rightSlope p)).const_add p.a + simpa using (h.hasDerivWithinAt (s := Ici p.m)).congr + (fun k hk ↦ sigmaZero_variance_right p hs k hk) + (sigmaZero_variance_right p hs p.m le_rfl) + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/SignFormula.lean b/LeanPool/MathFin/Models/ModelFree/SVI/SignFormula.lean new file mode 100644 index 0000000000..9be2f4c73f --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/SignFormula.lean @@ -0,0 +1,126 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.ParameterPolynomials + +/-! # Sign formulas and sign programs + +Part of the SVI polynomial-sign certificate (#174). + +`SignFormula` is a finite negation-free combination (and, or, constants) of atoms "the polynomial +`f` in the parameters has sign `s`". `SignProgram α` is a finite decision tree branching three ways +on such signs, with leaves in `α`; a Boolean program expands to a formula with the same value. + +## Main definitions + +* `SignFormula`: a finite combination (and, or, constants) of atoms "the parameter polynomial `f` + has sign `s`". +* `SignFormula.eval`: the truth value of a sign formula at the parameters `p`. +* `SignProgram α`: a finite decision tree that branches on signs of parameter polynomials, with + leaves in `α`. +* `SignProgram.bind`, `SignProgram.eval`: sequencing, and the result of running a program at `p`. +* `SignProgram.toFormula`: the sign formula with the same value as a Boolean sign program. +* `signQuery`, `signListProgram`: the programs returning the sign of one parameter polynomial and + the signs of a list of them. + +## Main results + +* `SignProgram.eval_bind`: `(s.bind k).eval p = (k (s.eval p)).eval p`. +* `SignProgram.eval_toFormula`: `s.toFormula.eval p = s.eval p` for a Boolean program `s`. +* `signQuery_eval`, `signListProgram_eval`: the programs evaluate to the signs of + `parameterEval p f`. + +## Tags + +sign formula, decision tree, sign program, semialgebraic condition, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI + +/-- A literal finite Boolean combination of parameter-polynomial sign atoms. -/ +inductive SignFormula where + | truth : Bool → SignFormula + | atom : ParameterRing → SignType → SignFormula + | and : SignFormula → SignFormula → SignFormula + | or : SignFormula → SignFormula → SignFormula + +/-- The truth value of a sign formula at the parameters `p`. -/ +noncomputable def SignFormula.eval (p : Params) : SignFormula → Bool + | .truth b => b + | .atom f s => decide (SignType.sign (parameterEval p f) = s) + | .and f g => f.eval p && g.eval p + | .or f g => f.eval p || g.eval p + +/-- A finite decision tree asking only signs of explicit parameter polynomials. -/ +inductive SignProgram (α : Type*) where + | pure : α → SignProgram α + | query : ParameterRing → SignProgram α → SignProgram α → SignProgram α → SignProgram α + +/-- Sequencing of sign programs. -/ +def SignProgram.bind {α β : Type*} : SignProgram α → (α → SignProgram β) → SignProgram β + | .pure a, k => k a + | .query f neg zero pos, k => .query f (neg.bind k) (zero.bind k) (pos.bind k) + +/-- The result of running a sign program at the parameters `p`. -/ +noncomputable def SignProgram.eval {α : Type*} (p : Params) : SignProgram α → α + | .pure a => a + | .query f neg zero pos => match SignType.sign (parameterEval p f) with + | .neg => neg.eval p + | .zero => zero.eval p + | .pos => pos.eval p + +@[simp] theorem SignProgram.eval_bind {α β : Type*} (p : Params) (s : SignProgram α) + (k : α → SignProgram β) : (s.bind k).eval p = (k (s.eval p)).eval p := by + induction s with + | pure a => rfl + | query f neg zero pos hn hz hp => + simp only [bind, eval] + cases SignType.sign (parameterEval p f) <;> simp_all + +/-- The sign formula with the same value as a Boolean sign program (`SignProgram.eval_toFormula`). +-/ +def SignProgram.toFormula : SignProgram Bool → SignFormula + | .pure b => .truth b + | .query f neg zero pos => + .or (.and (.atom f .neg) neg.toFormula) + (.or (.and (.atom f .zero) zero.toFormula) (.and (.atom f .pos) pos.toFormula)) + +@[simp] theorem SignProgram.eval_toFormula (p : Params) (s : SignProgram Bool) : + s.toFormula.eval p = s.eval p := by + induction s with + | pure b => rfl + | query f neg zero pos hn hz hp => + simp only [toFormula, SignFormula.eval, eval] + cases SignType.sign (parameterEval p f) <;> simp_all + +/-- The program returning the sign of `f`. -/ +def signQuery (f : ParameterRing) : SignProgram SignType := + .query f (.pure .neg) (.pure .zero) (.pure .pos) + +@[simp] theorem signQuery_eval (p : Params) (f : ParameterRing) : + (signQuery f).eval p = SignType.sign (parameterEval p f) := by + simp only [signQuery, SignProgram.eval] + cases SignType.sign (parameterEval p f) <;> rfl + +/-- The program returning the signs of a list of parameter polynomials. -/ +def signListProgram : List ParameterRing → SignProgram (List SignType) + | [] => .pure [] + | f :: fs => (signQuery f).bind fun s ↦ (signListProgram fs).bind fun ss ↦ .pure (s :: ss) + +@[simp] theorem signListProgram_eval (p : Params) (fs : List ParameterRing) : + (signListProgram fs).eval p = fs.map (fun f ↦ SignType.sign (parameterEval p f)) := by + induction fs with + | nil => rfl + | cons f fs ih => simp [signListProgram, SignProgram.eval_bind, ih, SignProgram.eval] + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/SignVariations.lean b/LeanPool/MathFin/Models/ModelFree/SVI/SignVariations.lean new file mode 100644 index 0000000000..8be92a28f5 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/SignVariations.lean @@ -0,0 +1,173 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Polynomial.RuleOfSigns +public import Mathlib.Algebra.Ring.IsFormallyReal +public import Mathlib.Analysis.Matrix.Spectrum + +/-! # Descartes' rule of signs when every root is real + +Part of the SVI polynomial-sign certificate (#174). + +For a real polynomial that splits, the number of sign variations equals the number of positive +roots with multiplicity (`signVariations_eq_pos_roots`). For a real symmetric matrix this gives the +number of positive minus the number of negative characteristic roots as the difference of the sign +variations of `charpoly` and `charpoly.comp (-X)` (`signatureTest_eq_root_counts`). + +## Main results + +* `signVariations_pair_bound`: + `P.signVariations + (P.comp (-X)).signVariations + P.natTrailingDegree ≤ P.natDegree`. +* `signVariations_eq_pos_roots`: if `P.Splits`, `P.signVariations` equals the number of positive + roots counted with multiplicity. +* `signatureTest_eq_root_counts`: for a symmetric real matrix, the sign variations of `charpoly` + minus those of `charpoly.comp (-X)` equal the number of positive minus the number of negative + characteristic roots. + +## Tags + +Descartes rule of signs, sign variations, positive roots, real-rooted polynomial, SVI, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + + +namespace MathFin +namespace SVI +open Polynomial + +/-- Substituting `-X` into a monomial multiplies its coefficient by `(-1)^n`. -/ +theorem monomial_comp_neg (n : ℕ) (a : ℝ) : + (monomial n a).comp (-X) = monomial n (a * (-1)^n) := by + rw [monomial_comp, ← C_mul_X_pow_eq_monomial] + rw [C_mul, C_pow] + simp only [C_neg, C_1] + rw [neg_pow] + ring + +/-- Erasing the leading term commutes with the substitution `X ↦ -X`. -/ +theorem eraseLead_comp_neg (P : ℝ[X]) : + (P.comp (-X)).eraseLead = P.eraseLead.comp (-X) := by + rw [← self_sub_monomial_natDegree_leadingCoeff, + ← self_sub_monomial_natDegree_leadingCoeff P, sub_comp, monomial_comp_neg] + simp only [natDegree_comp, natDegree_neg, natDegree_X, one_mul, + comp_neg_X_leadingCoeff_eq, mul_comm] + +/-- Erasing the leading term of a polynomial with nonzero remainder keeps its trailing degree. -/ +theorem natTrailingDegree_eraseLead (P : ℝ[X]) (h : P.eraseLead ≠ 0) : + P.eraseLead.natTrailingDegree = P.natTrailingDegree := by + have hd : P.eraseLead.natDegree < P.natDegree := + P.eraseLead_natDegree_lt_or_eraseLead_eq_zero.resolve_right h + have hcoef := coeff_natTrailingDegree_ne_zero.mpr h + have hle : P.natTrailingDegree ≤ P.eraseLead.natTrailingDegree := by + apply natTrailingDegree_le_of_ne_zero + rw [← eraseLead_coeff_of_ne _ (ne_of_lt + ((natTrailingDegree_le_natDegree P.eraseLead).trans_lt hd))] + exact hcoef + apply le_antisymm _ hle + apply natTrailingDegree_le_of_ne_zero + rw [eraseLead_coeff_of_ne _ (ne_of_lt (hle.trans_lt + ((natTrailingDegree_le_natDegree P.eraseLead).trans_lt hd)))] + apply coeff_natTrailingDegree_ne_zero.mpr + intro hp + simp [hp] at h + +/-- For nonzero `x`, `y`, `u`, exactly one of the sign-change tests for `(x, y)` and +`(-u*x, u*y)` holds. -/ +theorem sign_pair_step (x y u : ℝ) (hx : x ≠ 0) (hy : y ≠ 0) (hu : u ≠ 0) : + (if SignType.sign x = -SignType.sign y then 1 else 0) + + (if SignType.sign (-u*x) = -SignType.sign (u*y) then 1 else 0) = (1 : ℕ) := by + have hsx : SignType.sign x ≠ 0 := by simpa using hx + have hsy : SignType.sign y ≠ 0 := by simpa using hy + have hsu : SignType.sign u ≠ 0 := by simpa using hu + simp only [sign_mul, Left.sign_neg] + cases hxx : SignType.sign x <;> cases hyy : SignType.sign y <;> + cases huu : SignType.sign u <;> simp_all + +/-- The two Descartes counts cannot exceed the number of nonzero roots +available in a completely split polynomial. This bound itself needs no split +hypothesis. -/ +theorem signVariations_pair_bound (P : ℝ[X]) : + P.signVariations + (P.comp (-X)).signVariations + P.natTrailingDegree ≤ P.natDegree := by + induction hn : P.natDegree using Nat.strong_induction_on generalizing P with + | ind n ih => + by_cases hp : P = 0 + · simp [hp] + by_cases he : P.eraseLead = 0 + · have hm := P.eraseLead_add_monomial_natDegree_leadingCoeff + rw [he, zero_add] at hm + rw [← hm] + simp only [monomial_comp_neg, signVariations_monomial, + natTrailingDegree_monomial (leadingCoeff_ne_zero.mpr hp), zero_add] + exact hn.le + have hd : P.eraseLead.natDegree < P.natDegree := + P.eraseLead_natDegree_lt_or_eraseLead_eq_zero.resolve_right he + have hind := ih _ (hn ▸ hd) P.eraseLead rfl + rw [natTrailingDegree_eraseLead P he] at hind + have hpn : P.comp (-X) ≠ 0 := by simpa using hp + rw [signVariations_eq_eraseLead_add_ite hp, + signVariations_eq_eraseLead_add_ite hpn, eraseLead_comp_neg] + by_cases hgap : P.natDegree = P.eraseLead.natDegree + 1 + · have hstep := sign_pair_step P.leadingCoeff P.eraseLead.leadingCoeff + ((-1 : ℝ)^P.eraseLead.natDegree) (leadingCoeff_ne_zero.mpr hp) + (leadingCoeff_ne_zero.mpr he) (pow_ne_zero _ (by norm_num)) + simp only [comp_neg_X_leadingCoeff_eq] + rw [hgap, pow_succ] + have hh : (-1 : ℝ)^P.eraseLead.natDegree * -1 * P.leadingCoeff = + -((-1 : ℝ)^P.eraseLead.natDegree) * P.leadingCoeff := by ring + rw [hh] + omega + · have h1 : (if SignType.sign P.leadingCoeff = -SignType.sign P.eraseLead.leadingCoeff + then 1 else 0) ≤ (1 : ℕ) := by split <;> omega + have h2 : (if SignType.sign (P.comp (-X)).leadingCoeff = + -SignType.sign (P.eraseLead.comp (-X)).leadingCoeff then 1 else 0) ≤ (1 : ℕ) := + by split <;> omega + omega + +/-- A real multiset splits into its positive, negative and zero elements. -/ +theorem countP_pos_add_countP_neg_add_count_zero (s : Multiset ℝ) : + s.countP (0 < ·) + s.countP (· < 0) + s.count 0 = s.card := by + induction s using Multiset.induction_on with + | empty => simp + | cons a s ih => + rcases lt_trichotomy a 0 with ha | rfl | ha + · simp [ha, not_lt_of_ge ha.le, Ne.symm (ne_of_lt ha)] + omega + · simp + omega + · simp [ha, not_lt_of_ge ha.le, Ne.symm (ne_of_gt ha)] + omega + +/-- Descartes' rule is exact when all roots are real, with multiplicities and +zero roots handled without nondegeneracy assumptions. -/ +theorem signVariations_eq_pos_roots (P : ℝ[X]) (hs : P.Splits) : + P.signVariations = P.roots.countP (0 < ·) := by + have hpos := P.roots_countP_pos_le_signVariations + have hneg := (P.comp (-X)).roots_countP_pos_le_signVariations + simp only + [roots_comp_neg_X, Multiset.countP_map, neg_pos, ← Multiset.countP_eq_card_filter] at hneg + have hbound := signVariations_pair_bound P + have hsum := countP_pos_add_countP_neg_add_count_zero P.roots + rw [count_roots, rootMultiplicity_eq_natTrailingDegree', ← hs.natDegree_eq_card_roots] at hsum + omega + +/-- The exact characteristic-coefficient rule for any real symmetric matrix. -/ +theorem signatureTest_eq_root_counts {n : ℕ} (M : Matrix (Fin n) (Fin n) ℝ) + (hM : M.IsSymm) : + ((M.charpoly.signVariations : ℤ) - ((M.charpoly.comp (-X)).signVariations : ℤ)) = + (M.charpoly.roots.countP (0 < ·) : ℤ) - (M.charpoly.roots.countP (· < 0) : ℤ) := by + have hh : M.IsHermitian := Matrix.isHermitian_iff_isSymm.mpr hM + have hs := hh.splits_charpoly + rw [signVariations_eq_pos_roots _ hs, signVariations_eq_pos_roots _ hs.comp_neg_X] + simp only [roots_comp_neg_X, Multiset.countP_map, neg_pos, ← Multiset.countP_eq_card_filter] + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/SignatureProgram.lean b/LeanPool/MathFin/Models/ModelFree/SVI/SignatureProgram.lean new file mode 100644 index 0000000000..d89dc53e86 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/SignatureProgram.lean @@ -0,0 +1,103 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.SignFormula + +/-! # Signatures by sign queries + +Part of the SVI polynomial-sign certificate (#174). + +Sign programs computing the sign variations of a parameter polynomial whose specialisation has +degree exactly `n` (`variationProgram_eval`), the characteristic sign-variation difference +`signatureTest` of each of the four specialised universal matrices (`signatureProgram_eval`), and +their combination, which on the degree branch `n = (polynomial p).derivative.natDegree` evaluates +to `matrixCountFour (polynomial p)` (`countProgram_eval`). + +## Main definitions + +* `symbolicCoeffList`: the coefficients of a parameter-ring polynomial from degree `n` down to `0`. +* `variationProgram`: the sign program computing the sign variations of `Q` read at degree `n`. +* `signatureProgram`: the sign program computing the signature test of the `i`-th universal + matrix at size `n`. +* `countProgram`: the sign program combining the four signature tests as `a + b - c - d`. + +## Main results + +* `variationProgram_eval`: if the specialisation of `Q` at `p` has degree exactly `n`, the program + evaluates to its number of sign variations. +* `signatureProgram_eval`: `signatureProgram n i` evaluates at `p` to `signatureTest` of the + specialised universal matrix. +* `countProgram_eval`: at `n = (polynomial p).derivative.natDegree`, `countProgram n` evaluates at + `p` to `matrixCountFour (polynomial p)`. + +## Tags + +sign program, matrix signature, characteristic polynomial, Hermite matrices, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +/-- The coefficients of `Q` from degree `n` down to `0`. -/ +noncomputable def symbolicCoeffList (n : ℕ) (Q : Polynomial ParameterRing) : List ParameterRing := + (List.range (n+1)).reverse.map Q.coeff + +/-- The program computing the sign variations of `Q` read at degree `n` (`variationProgram_eval`). +-/ +noncomputable def variationProgram (n : ℕ) (Q : Polynomial ParameterRing) : SignProgram ℕ := + (signListProgram (symbolicCoeffList n Q)).bind fun ss ↦ .pure ss.signVariations + +theorem variationProgram_eval (p : Params) (n : ℕ) (Q : Polynomial ParameterRing) + (hd : (Q.map (parameterEval p)).degree = n) : + (variationProgram n Q).eval p = (Q.map (parameterEval p)).signVariations := by + have hc : (Q.map (parameterEval p)).coeff = fun r ↦ parameterEval p (Q.coeff r) := by + funext r + exact coeff_map _ _ + have hne : Q.map (parameterEval p) ≠ 0 := fun h0 ↦ by simp [h0] at hd + simp only [variationProgram, SignProgram.eval_bind, SignProgram.eval, symbolicCoeffList, + Polynomial.signVariations, coeffList_of_ne_zero hne, natDegree_eq_of_degree_eq_some hd, +hc] + refine Eq.trans ?_ (List.signVariations_map_sign _) + simp [List.map_reverse, List.map_map, Function.comp_def] + +/-- The program computing the signature test of the `i`-th universal matrix at size `n` +(`signatureProgram_eval`). -/ +noncomputable def signatureProgram (n : ℕ) (i : Fin 4) : SignProgram ℤ := + let Q := (universalMatrices n i).charpoly + (variationProgram n Q).bind fun v ↦ + (variationProgram n (Q.comp (-X))).bind fun w ↦ .pure ((v : ℤ) - (w : ℤ)) + +theorem signatureProgram_eval (p : Params) (n : ℕ) (i : Fin 4) : + (signatureProgram n i).eval p = + signatureTest ((universalMatrices n i).map (parameterEval p)) := by + have hd : ((universalMatrices n i).charpoly.map (parameterEval p)).degree = n := by + rw [← Matrix.charpoly_map, Matrix.charpoly_degree_eq_dim, Fintype.card_fin] + have hd' : (((universalMatrices n i).charpoly.comp (-X)).map (parameterEval p)).degree = n := by + simpa only [map_comp, Polynomial.map_neg, map_X, degree_comp_neg_X] using hd + simp only [signatureProgram, SignProgram.eval_bind, variationProgram_eval p n _ hd, + variationProgram_eval p n _ hd', SignProgram.eval, signatureTest, + Matrix.charpoly_map, map_comp, Polynomial.map_neg, map_X] + +/-- The program combining the four signature tests as `a + b − c − d` (`countProgram_eval`). -/ +noncomputable def countProgram (n : ℕ) : SignProgram ℤ := + (signatureProgram n 0).bind fun a ↦ + (signatureProgram n 1).bind fun b ↦ + (signatureProgram n 2).bind fun c ↦ + (signatureProgram n 3).bind fun d ↦ .pure (a+b-c-d) + +theorem countProgram_eval (p : Params) : + (countProgram (polynomial p).derivative.natDegree).eval p = matrixCountFour (polynomial p) := by + simp only [countProgram, SignProgram.eval_bind, signatureProgram_eval, universalMatrices_eval, + SignProgram.eval, matrixCountFour] + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/TailCondition.lean b/LeanPool/MathFin/Models/ModelFree/SVI/TailCondition.lean new file mode 100644 index 0000000000..04fa5aa45a --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/TailCondition.lean @@ -0,0 +1,323 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.ExtendedFormula +public import LeanPool.MathFin.Models.ModelFree.PriceBounds +public import LeanPool.MathFin.Models.ModelFree.CallPriceFunction +public import LeanPool.MathFin.Probability.Gaussian.NormalTail + +/-! # The tail condition for raw SVI, and butterfly-freeness + +The strike-convexity certificate of `ExtendedFormula` leaves out the large-strike behaviour. A +smile is free of butterfly arbitrage when its call prices, as a function of the strike, are convex, +lie between `(1 − K)⁺` and `1`, and tend to `0` at large strikes (`IsNormalizedCallPrice`, after +Roper's Theorem 2.1). The smiled call always satisfies the bounds, so for raw SVI with `b ≥ 0` +and positive variance what convexity leaves open is the large-strike limit. The right wing of the +variance has slope `b(1 + ρ)`, and + +* `tendsto_dpl_atBot_iff` — `d₊(k) → −∞` as `k → ∞`, the tail condition of + Gatheral–Jacquier, *Arbitrage-free SVI volatility surfaces*, Lemma 2.2, holds exactly when + `b(1 + ρ) < 2`; +* `tendsto_bsSmile_zero_iff` — the SVI-smiled call tends to `0` at large strikes exactly when + `b(1 + ρ) < 2`; +* `butterflyFreeFormula_iff_isNormalizedCallPrice` — the strike-convexity formula with one more + sign atom, `2 − b(1 + ρ) > 0`, holds exactly when `σ ≥ 0`, `b ≥ 0`, `ρ² ≤ 1`, the variance is + positive, and the SVI-smiled Black–Scholes call is a normalised call price function. + +The left wing gets no atom of its own: the bounds and the limit at strike `0` hold for any +positive variance, and whatever convexity asks of the left wing is already in the strike-convexity +formula. What is not here is the last step of Roper's theorem, the construction of the random +variable from such a function. + +## Main definitions + +* `butterflyFreeFormula`: the strike-convexity formula with the sign atom `2 - b(1 + ρ) > 0` of + the tail condition. + +## Main results + +* `asymptote_le_variance`: for `b ≥ 0`, `variance p k ≥ a + b(1 + ρ)(k - m)`. +* `tendsto_dpl_atBot_iff`: for `b ≥ 0` and positive variance, `d₊(k) → -∞` as `k → ∞` iff + `b(1 + ρ) < 2`. +* `blackCall_le_Phi_dpl`, `bsSmile_nonneg`, `one_sub_le_bsSmile`, `bsSmile_le_one`: for `K > 0` and + positive variance at `log K`, the smiled call is at most `Φ(d₊)`, nonnegative, at least + `1 - K` and at most `1`. +* `tendsto_bsSmile_zero_iff`: for `b ≥ 0` and positive variance, `bsSmile p` tends to `0` at + `∞` iff `b(1 + ρ) < 2`. +* `isNormalizedCallPrice_bsSmile_iff`: for `b ≥ 0` and positive variance, `bsSmile p` is a + normalised call price function iff it is convex on `(0, ∞)` and `b(1 + ρ) < 2`. +* `butterflyFreeFormula_iff_isNormalizedCallPrice`: `butterflyFreeFormula` holds iff `σ ≥ 0`, + `b ≥ 0`, `1 - ρ² ≥ 0`, the variance is positive, and `bsSmile p` is a normalised call price + function. + +## References + +* [Gatheral and Jacquier, *Arbitrage-free SVI volatility surfaces*][GatheralJacquier2014], Lemma 2.2 +* [Roper, *Arbitrage free implied volatility surfaces*][Roper2010], Theorem 2.1 + +## Tags + +SVI tail condition, butterfly arbitrage, Gatheral–Jacquier, Roper theorem, large-strike behaviour, +arbitrage-free SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI + +open Filter Topology Set ProbabilityTheory MeasureTheory +open scoped NNReal +open ForwardSmile (dpl dmi blackForm) + +/-! ### The right wing of the variance -/ + +/-- The variance lies above its right asymptote, of slope `b(1 + ρ)`. -/ +theorem asymptote_le_variance (p : Params) (hb : 0 ≤ p.b) (k : ℝ) : + p.a + p.b * (1 + p.rho) * (k - p.m) ≤ variance p k := by + have hu : k - p.m ≤ Real.sqrt ((k - p.m) ^ 2 + p.sigma ^ 2) := + Real.le_sqrt_of_sq_le (le_add_of_nonneg_right (sq_nonneg _)) + unfold variance + linarith [mul_le_mul_of_nonneg_left hu hb] + +/-- Right of `m`, the variance is within `b|σ|` of its asymptote. -/ +theorem variance_le_asymptote_add (p : Params) (hb : 0 ≤ p.b) {k : ℝ} (hk : p.m ≤ k) : + variance p k ≤ p.a + p.b * (1 + p.rho) * (k - p.m) + p.b * |p.sigma| := by + have hu : Real.sqrt ((k - p.m) ^ 2 + p.sigma ^ 2) ≤ (k - p.m) + |p.sigma| := + Real.sqrt_le_iff.2 ⟨by linarith [sub_nonneg.2 hk, abs_nonneg p.sigma], + by nlinarith [mul_nonneg (sub_nonneg.2 hk) (abs_nonneg p.sigma), sq_abs p.sigma]⟩ + unfold variance + linarith [mul_le_mul_of_nonneg_left hu hb] + +/-- `d₊ = (w − 2k)/(2√w)` where the variance is positive. -/ +theorem dpl_eq_div (p : Params) (k : ℝ) (hw : 0 < variance p k) : + dpl k (variance p k) = (variance p k - 2 * k) / (2 * rootVariance p k) := by + have hr := rootVariance_pos p k hw + rw [dpl_eq_rootVariance, ← rootVariance_sq p k hw.le] + field_simp + ring + +/-! ### The tail condition -/ + +/-- **A wing slope below `2` sends `d₊` to `−∞`.** With `r = √w`, `d₊ ≤ −M` is +`w + 2Mr ≤ 2k`. Young's inequality `2Mr ≤ qw + M²/q` reduces it to a linear bound on `w`, which +the asymptote supplies once `q` is small enough for `(1 + q)·slope < 2`. -/ +theorem tendsto_dpl_atBot (p : Params) (hb : 0 ≤ p.b) + (hw : ∀ k : ℝ, 0 < variance p k) (hc : p.b * (1 + p.rho) < 2) : + Tendsto (fun k ↦ dpl k (variance p k)) atTop atBot := by + refine tendsto_atBot.2 fun y ↦ ?_ + set c := p.b * (1 + p.rho) + set M := max (-y) 1 + set q := (2 - c) / 4 + have hq : 0 < q := div_pos (sub_pos.2 hc) four_pos + filter_upwards [eventually_ge_atTop (max p.m (max 0 + (2 * ((1 + q) * (p.a - c * p.m + p.b * |p.sigma|) + M ^ 2 / q) / (2 - c))))] with k hk + have hkm : p.m ≤ k := (le_max_left _ _).trans hk + have hk0 : 0 ≤ k := ((le_max_left _ _).trans (le_max_right _ _)).trans hk + have hkL : 2 * ((1 + q) * (p.a - c * p.m + p.b * |p.sigma|) + M ^ 2 / q) ≤ k * (2 - c) := + (div_le_iff₀ (sub_pos.2 hc)).1 (((le_max_right _ _).trans (le_max_right _ _)).trans hk) + have hr := rootVariance_pos p k (hw k) + have hr2 := rootVariance_sq p k (hw k).le + have hwle : (1 + q) * variance p k + ≤ (1 + q) * c * k + (1 + q) * (p.a - c * p.m + p.b * |p.sigma|) := by + have := mul_le_mul_of_nonneg_left (variance_le_asymptote_add p hb hkm) + (by linarith : 0 ≤ 1 + q) + simp only [c] + linarith + have hslope : (1 + q) * c * k ≤ (2 + c) / 2 * k := + mul_le_mul_of_nonneg_right (by simp only [q]; nlinarith [sq_nonneg (2 - c)]) hk0 + -- Young's inequality, from `(q r − M)² ≥ 0` + have hyoung : 2 * M * rootVariance p k - q * variance p k ≤ M ^ 2 / q := by + rw [← hr2, le_div_iff₀ hq] + nlinarith [sq_nonneg (q * rootVariance p k - M)] + rw [dpl_eq_div p k (hw k)] + exact ((div_le_iff₀ (by positivity)).2 + (by linarith : _ ≤ -M * (2 * rootVariance p k))).trans (neg_le.1 (le_max_left _ _)) + +/-- **A wing slope of at least `2` keeps `d₊` bounded below**, and sends the variance above any +level: eventually `d₊ ≥ −|a − 2m|/2` and `√w ≥ R`. -/ +theorem eventually_le_dpl (p : Params) (hb : 0 ≤ p.b) + (hw : ∀ k : ℝ, 0 < variance p k) (hc : 2 ≤ p.b * (1 + p.rho)) (R : ℝ) : + ∀ᶠ k in atTop, + -(|p.a - 2 * p.m| / 2) ≤ dpl k (variance p k) ∧ R ≤ rootVariance p k := by + filter_upwards [eventually_ge_atTop (max p.m (p.m + ((max R 1) ^ 2 - p.a) / 2))] with k hk + have hkm : p.m ≤ k := (le_max_left _ _).trans hk + have hk1 : p.m + ((max R 1) ^ 2 - p.a) / 2 ≤ k := (le_max_right _ _).trans hk + have hw2 : p.a + 2 * (k - p.m) ≤ variance p k := + le_trans (by nlinarith [sub_nonneg.2 hkm]) (asymptote_le_variance p hb k) + have hr := rootVariance_pos p k (hw k) + have hr2 := rootVariance_sq p k (hw k).le + have hRr : max R 1 ≤ rootVariance p k := Real.le_sqrt_of_sq_le (by linarith) + have hr1 : 1 ≤ rootVariance p k := (le_max_right _ _).trans hRr + refine ⟨?_, (le_max_left _ _).trans hRr⟩ + rw [dpl_eq_div p k (hw k), le_div_iff₀ (by positivity)] + nlinarith [abs_nonneg (p.a - 2 * p.m), neg_abs_le (p.a - 2 * p.m), + mul_nonneg (abs_nonneg (p.a - 2 * p.m)) (sub_nonneg.2 hr1)] + +/-- **The tail condition for raw SVI**: `d₊(k) → −∞` as `k → ∞` exactly when the right wing +slope `b(1 + ρ)` is below `2`. -/ +theorem tendsto_dpl_atBot_iff (p : Params) (hb : 0 ≤ p.b) + (hw : ∀ k : ℝ, 0 < variance p k) : + Tendsto (fun k ↦ dpl k (variance p k)) atTop atBot ↔ p.b * (1 + p.rho) < 2 := by + refine ⟨fun h ↦ not_le.1 fun hc ↦ ?_, tendsto_dpl_atBot p hb hw⟩ + obtain ⟨k, hlow, hk⟩ := ((tendsto_atBot.1 h (-(|p.a - 2 * p.m| / 2) - 1)).and + (eventually_le_dpl p hb hw hc 0)).exists + linarith [hk.1] + +/-! ### The call price at large and small strikes -/ + +/-- The SVI-smiled call is at most `Φ(d₊)`. -/ +theorem blackCall_le_Phi_dpl (p : Params) (K : ℝ) : + blackCall p K ≤ MathFin.Phi (dpl (Real.log K) (variance p (Real.log K))) := by + simp only [blackCall, ForwardSmile.blackForm] + linarith [mul_nonneg (Real.exp_pos (Real.log K)).le + (MathFin.Phi_nonneg (dmi (Real.log K) (variance p (Real.log K))))] + +/-- The Black–Scholes hypothesis at the smile's volatility, on the standard normal space. -/ +theorem bsCallHyp_smile (p : Params) {K : ℝ} (hK : 0 < K) (hw : 0 < variance p (Real.log K)) : + BSCallHyp (gaussianReal 0 1) 1 K 0 (rootVariance p (Real.log K)) 1 id := + ⟨one_pos, hK, rootVariance_pos p _ hw, one_pos, ⟨aemeasurable_id, Measure.map_id⟩⟩ + +/-- The SVI-smiled call is nonnegative: it is a Black–Scholes price at the smile's volatility. -/ +theorem bsSmile_nonneg (p : Params) {K : ℝ} (hK : 0 < K) (hw : 0 < variance p (Real.log K)) : + 0 ≤ bsSmile p K := + MathFin.bsV_nonneg (bsCallHyp_smile p hK hw) + +/-- The SVI-smiled call is at least the forward payoff `1 − K`. -/ +theorem one_sub_le_bsSmile (p : Params) {K : ℝ} (hK : 0 < K) + (hw : 0 < variance p (Real.log K)) : 1 - K ≤ bsSmile p K := by + simpa [bsSmile] using MathFin.bsV_ge_forward_lower_bound (bsCallHyp_smile p hK hw) + +/-- The SVI-smiled call is at most `1`. -/ +theorem bsSmile_le_one (p : Params) {K : ℝ} (hK : 0 < K) (hw : 0 < variance p (Real.log K)) : + bsSmile p K ≤ 1 := + (blackCall_eq_bsSmile p K hK hw).symm.trans_le + ((blackCall_le_Phi_dpl p K).trans (MathFin.Phi_le_one _)) + +/-- **Under the tail condition the call vanishes at large strikes**: it lies between `0` and +`Φ(d₊)`. -/ +theorem tendsto_bsSmile_zero (p : Params) (hb : 0 ≤ p.b) + (hw : ∀ k : ℝ, 0 < variance p k) (hc : p.b * (1 + p.rho) < 2) : + Tendsto (bsSmile p) atTop (𝓝 0) := by + have hΦ : Tendsto (fun K ↦ MathFin.Phi (dpl (Real.log K) (variance p (Real.log K)))) atTop + (𝓝 0) := + tendsto_Phi_atBot.comp ((tendsto_dpl_atBot p hb hw hc).comp Real.tendsto_log_atTop) + refine tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hΦ ?_ ?_ + · filter_upwards [eventually_gt_atTop 0] with K hK using bsSmile_nonneg p hK (hw _) + · filter_upwards [eventually_gt_atTop 0] with K hK + exact (blackCall_eq_bsSmile p K hK (hw _)).symm.trans_le (blackCall_le_Phi_dpl p K) + +/-- **With a wing slope of at least `2` the call does not vanish at large strikes.** Eventually +`Φ(d₊) ≥ δ := Φ(−|a − 2m|/2) > 0`, while by the Mills bound +`eᵏΦ(d₋) ≤ φ(d₊)/|d₋| ≤ 1/|d₋| ≤ 2/√w`, which is at most `δ/2` once `√w ≥ 4/δ`. -/ +theorem not_tendsto_bsSmile_zero (p : Params) (hb : 0 ≤ p.b) + (hw : ∀ k : ℝ, 0 < variance p k) (hc : 2 ≤ p.b * (1 + p.rho)) : + ¬ Tendsto (bsSmile p) atTop (𝓝 0) := by + intro h + set δ := MathFin.Phi (-(|p.a - 2 * p.m| / 2)) + have hδ : 0 < δ := (MathFin.Phi_mem_Ioo _).1 + obtain ⟨k, hsmall, ⟨hlow, hR⟩, hk0⟩ := + ((Real.tendsto_exp_atTop.eventually ((tendsto_order.1 h).2 (δ / 2) (half_pos hδ))).and + ((eventually_le_dpl p hb hw hc (4 / δ)).and (eventually_ge_atTop 0))).exists + have hr := rootVariance_pos p k (hw k) + rw [← blackCall_eq_bsSmile p _ (Real.exp_pos k) + (by rw [Real.log_exp]; exact hw k)] at hsmall + simp only [blackCall, ForwardSmile.blackForm, Real.log_exp] at hsmall + have hE : 0 ≤ Real.exp k * MathFin.Phi (dmi k (variance p k)) := + mul_nonneg (Real.exp_pos k).le (MathFin.Phi_nonneg _) + -- the Mills bound, transported by `eᵏφ(d₋) = φ(d₊)` + have hmills : + -dmi k (variance p k) * (Real.exp k * MathFin.Phi (dmi k (variance p k))) ≤ 1 := by + have := mul_le_mul_of_nonneg_left (neg_mul_Phi_le_gaussianPDFReal (dmi k (variance p k))) + (Real.exp_pos k).le + rw [ForwardSmile.exp_mul_pdf_dmi (hw k)] at this + linarith [gaussianPDFReal_zero_one_le_one (dpl k (variance p k))] + have hd : 2 / δ ≤ -dmi k (variance p k) := by + have h1 : 0 ≤ k / rootVariance p k := div_nonneg hk0 hr.le + have h2 : 4 / δ / 2 = 2 / δ := by ring + simp only [dmi_eq_rootVariance, neg_div] + linarith + have h3 := (mul_le_mul_of_nonneg_right hd hE).trans hmills + rw [div_mul_eq_mul_div, div_le_iff₀ hδ] at h3 + linarith [MathFin.strictMono_Phi.monotone hlow] + +/-- **The call price at large strikes**: the SVI-smiled call tends to `0` exactly when the right +wing slope `b(1 + ρ)` is below `2`. -/ +theorem tendsto_bsSmile_zero_iff (p : Params) (hb : 0 ≤ p.b) + (hw : ∀ k : ℝ, 0 < variance p k) : + Tendsto (bsSmile p) atTop (𝓝 0) ↔ p.b * (1 + p.rho) < 2 := + ⟨fun h ↦ not_le.1 fun hc ↦ not_tendsto_bsSmile_zero p hb hw hc h, tendsto_bsSmile_zero p hb hw⟩ + +/-! ### The call price function -/ + +/-- For a raw SVI smile with positive variance and `b ≥ 0`, the smiled call is a normalised call +price function exactly when it is convex in the strike and the right wing slope is below `2`. -/ +theorem isNormalizedCallPrice_bsSmile_iff (p : Params) (hb : 0 ≤ p.b) + (hw : ∀ k : ℝ, 0 < variance p k) : + IsNormalizedCallPrice (bsSmile p) ↔ + ConvexOn ℝ (Ioi 0) (bsSmile p) ∧ p.b * (1 + p.rho) < 2 := + ⟨fun h ↦ ⟨h.convexOn, (tendsto_bsSmile_zero_iff p hb hw).1 h.tendsto_zero⟩, fun h ↦ + .of_convexOn h.1 + (fun _ hK ↦ max_le (one_sub_le_bsSmile p hK (hw _)) (bsSmile_nonneg p hK (hw _))) + (fun _ hK ↦ bsSmile_le_one p hK (hw _)) (tendsto_bsSmile_zero p hb hw h.2)⟩ + +/-! ### The sign formula -/ + +/-- The strike-convexity formula together with the sign atom `2 − b(1 + ρ) > 0` of the tail +condition. -/ +noncomputable def butterflyFreeFormula : SignFormula := + .and extendedCertificateFormula + (positiveAtom (2 - MvPolynomial.X (1 : Fin 5) * (1 + MvPolynomial.X (2 : Fin 5)))) + +/-- `butterflyFreeFormula` holds exactly when the strike-convexity conditions do and the right +wing slope is below `2`. -/ +theorem butterflyFreeFormula_eval (p : Params) : + butterflyFreeFormula.eval p = true ↔ + (0 ≤ p.sigma ∧ 0 ≤ p.b ∧ 0 ≤ 1 - p.rho ^ 2 ∧ (∀ k : ℝ, 0 < variance p k) ∧ + ConvexOn ℝ (Ioi 0) (bsSmile p)) ∧ p.b * (1 + p.rho) < 2 := by + have he : parameterEval p (2 - MvPolynomial.X (1 : Fin 5) * (1 + MvPolynomial.X (2 : Fin 5))) + = 2 - p.b * (1 + p.rho) := by + simp [parameterEval, parameterValues] + simp only [butterflyFreeFormula, SignFormula.eval, Bool.and_eq_true, positiveAtom_eval, he, + extendedCertificateFormula_iff_bsSmile_convex, sub_pos] + +/-- **Convexity of the call and the tail condition as a finite sign formula.** +`butterflyFreeFormula` holds exactly when `σ ≥ 0`, `b ≥ 0`, `ρ² ≤ 1`, the variance is positive at +every log-strike, the SVI-smiled Black–Scholes call is convex in strike, and `d₊(k) → −∞` as +`k → ∞`. For `σ > 0` that convexity is Durrleman's condition (`bsSmile_convex_iff`), and these +are the two conditions of Gatheral–Jacquier's Lemma 2.2. -/ +theorem butterflyFreeFormula_iff (p : Params) : + butterflyFreeFormula.eval p = true ↔ + 0 ≤ p.sigma ∧ 0 ≤ p.b ∧ 0 ≤ 1 - p.rho ^ 2 ∧ (∀ k : ℝ, 0 < variance p k) ∧ + ConvexOn ℝ (Ioi 0) (bsSmile p) ∧ + Tendsto (fun k ↦ dpl k (variance p k)) atTop atBot := by + rw [butterflyFreeFormula_eval] + constructor + · rintro ⟨⟨hs, hb, hr, hw, hcv⟩, hc⟩ + exact ⟨hs, hb, hr, hw, hcv, tendsto_dpl_atBot p hb hw hc⟩ + · rintro ⟨hs, hb, hr, hw, hcv, ht⟩ + exact ⟨⟨hs, hb, hr, hw, hcv⟩, (tendsto_dpl_atBot_iff p hb hw).1 ht⟩ + +/-- **Butterfly-free raw SVI as a finite sign formula.** `butterflyFreeFormula` holds exactly +when `σ ≥ 0`, `b ≥ 0`, `ρ² ≤ 1`, the variance is positive at every log-strike, and the SVI-smiled +Black–Scholes call is a normalised call price function: convex and nonincreasing in the strike, +between `(1 − K)⁺` and `1`, tending to `1` at strike `0` and to `0` at large strikes. -/ +theorem butterflyFreeFormula_iff_isNormalizedCallPrice (p : Params) : + butterflyFreeFormula.eval p = true ↔ + 0 ≤ p.sigma ∧ 0 ≤ p.b ∧ 0 ≤ 1 - p.rho ^ 2 ∧ (∀ k : ℝ, 0 < variance p k) ∧ + IsNormalizedCallPrice (bsSmile p) := by + rw [butterflyFreeFormula_eval] + constructor + · rintro ⟨⟨hs, hb, hr, hw, hcv⟩, hc⟩ + exact ⟨hs, hb, hr, hw, (isNormalizedCallPrice_bsSmile_iff p hb hw).2 ⟨hcv, hc⟩⟩ + · rintro ⟨hs, hb, hr, hw, hC⟩ + exact ⟨⟨hs, hb, hr, hw, hC.convexOn⟩, ((isNormalizedCallPrice_bsSmile_iff p hb hw).1 hC).2⟩ + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/TraceForm.lean b/LeanPool/MathFin/Models/ModelFree/SVI/TraceForm.lean new file mode 100644 index 0000000000..f0ddaa2e0b --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/TraceForm.lean @@ -0,0 +1,85 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.Companion + +/-! # The weighted trace form + +Part of the SVI polynomial-sign certificate (#174). + +`weightedTraceForm f q` is `(x, y) ↦ tr(q·x·y)` on `ℝ[X]/(f)`, nilpotents included, and the +Hermite matrix is its matrix in the power basis. + +## Main definitions + +* `weightedTraceForm`: the bilinear form `(x, y) ↦ tr(q·x·y)` on `AdjoinRoot f`, nilpotents + included. + +## Main results + +* `weightedTraceForm_apply`: `weightedTraceForm f q x y` is the algebra trace of + `aeval (root f) q * x * y`. +* `hermite_entry_eq_trace`: for `f ≠ 0`, the `(i, j)` entry of `hermite f q f.natDegree` is the + algebra trace of `q(root f) * (root f)^(i + j)`. +* `hermite_eq_traceForm_matrix`: for `f ≠ 0`, `hermite f q f.natDegree` is the matrix of + `weightedTraceForm f q` in the power basis. + +## Tags + +weighted trace form, Hermite matrix, quotient algebra, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Polynomial + +/-- The matrix entries are those of the weighted quotient-algebra trace +pairing in its power basis. -/ +theorem hermite_entry_eq_trace (f q : ℝ[X]) (hf : f ≠ 0) + (i j : Fin f.natDegree) : + hermite f q f.natDegree i j = + Algebra.trace ℝ (AdjoinRoot f) + ((aeval (AdjoinRoot.root f) q) * (AdjoinRoot.root f)^(i.val+j.val)) := by + unfold hermite + simp_rw [trace_companion_pow_eq_algebraTrace f hf] + rw [aeval_def, eval₂_eq_sum, sum_def, Finset.sum_mul, map_sum] + apply Finset.sum_congr rfl + intro r hr + rw [mul_assoc, ← pow_add, ← Algebra.smul_def, map_smul, smul_eq_mul] + congr 2 + rw [Nat.add_comm] + +/-- Weighted trace bilinear form on the full quotient, including nilpotents. -/ +noncomputable def weightedTraceForm (f q : ℝ[X]) : + LinearMap.BilinForm ℝ (AdjoinRoot f) := + (Algebra.traceForm ℝ (AdjoinRoot f)).compl₁₂ + (Algebra.lmul ℝ (AdjoinRoot f) (aeval (AdjoinRoot.root f) q)) LinearMap.id + +theorem weightedTraceForm_apply (f q : ℝ[X]) (x y : AdjoinRoot f) : + weightedTraceForm f q x y = + Algebra.trace ℝ (AdjoinRoot f) (aeval (AdjoinRoot.root f) q * x * y) := by + simp [weightedTraceForm, Algebra.traceForm_apply] + +theorem hermite_eq_traceForm_matrix (f q : ℝ[X]) (hf : f ≠ 0) : + hermite f q f.natDegree = + (weightedTraceForm f q).toMatrix (AdjoinRoot.powerBasis hf).basis := by + ext i j + rw [hermite_entry_eq_trace f q hf] + have hb (k : Fin f.natDegree) : + (AdjoinRoot.powerBasis hf).basis k = AdjoinRoot.root f ^ (k : ℕ) := + (AdjoinRoot.powerBasis hf).basis_eq_pow k + refine Eq.trans ?_ (LinearMap.BilinForm.toMatrix_apply _ _ i j).symm + rw [weightedTraceForm_apply, pow_add, ← mul_assoc] + exact congrArg _ (congrArg₂ (fun x y ↦ aeval (AdjoinRoot.root f) q * x * y) + (hb i).symm (hb j).symm) + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/SVI/TraceSignature.lean b/LeanPool/MathFin/Models/ModelFree/SVI/TraceSignature.lean new file mode 100644 index 0000000000..7c1bf7f1e8 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/SVI/TraceSignature.lean @@ -0,0 +1,65 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.SVI.TraceForm +public import LeanPool.MathFin.Models.ModelFree.SVI.ClearedSignature +public import LeanPool.MathFin.Models.ModelFree.SVI.RankOneSignature + +/-! # The Hermite matrix and the trace form have the same signature + +Part of the SVI polynomial-sign certificate (#174). + +Taking the matrix of a form in any basis preserves its signature, so the Hermite matrix test +reduces to the trace form on the quotient. + +## Main results + +* `matrixSignature_toMatrix`: the matrix of a bilinear form in any basis `Fin n → V` has + `matrixSignature` equal to the `formSignature` of the form's quadratic map. +* `hermite_signature_eq_trace_signature`: for `f ≠ 0`, `signatureTest (hermite f q f.natDegree)` + equals the signature of `weightedTraceForm f q`. + +## Tags + +Hermite matrix, trace form, signature invariance, change of basis, SVI, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin +namespace SVI +open Matrix + +/-- Taking a matrix in any basis preserves the quadratic-form signature. -/ +theorem matrixSignature_toMatrix {V : Type*} [AddCommGroup V] [Module ℝ V] + {n : ℕ} (b : Module.Basis (Fin n) ℝ V) (B : LinearMap.BilinForm ℝ V) : + matrixSignature (B.toMatrix b) = formSignature B.toQuadraticMap := by + have hQ : (B.toMatrix b).toQuadraticForm' = B.toQuadraticMap.basisRepr b := by + ext x + simp only [Matrix.toQuadraticForm', LinearMap.BilinMap.toQuadraticMap_apply, + Matrix.toLinearMap₂'_apply'] + rw [B.dotProduct_toMatrix_mulVec b] + rfl + have he : QuadraticMap.Equivalent B.toQuadraticMap (B.toMatrix b).toQuadraticForm' := by + rw [hQ] + exact ⟨B.toQuadraticMap.isometryEquivBasisRepr b⟩ + unfold matrixSignature formSignature + rw [← he.sigPos_eq, ← he.sigNeg_eq] + +/-- The remaining Hermite--Tarski theorem can be proved on the quotient +trace form; every matrix and signature conversion is already checked. -/ +theorem hermite_signature_eq_trace_signature (f q : Polynomial ℝ) (hf : f ≠ 0) : + signatureTest (hermite f q f.natDegree) = + formSignature (weightedTraceForm f q).toQuadraticMap := by + rw [signatureTest_eq_matrixSignature _ (hermite_symmetric f q f.natDegree), + hermite_eq_traceForm_matrix f q hf] + exact matrixSignature_toMatrix (AdjoinRoot.powerBasis hf).basis (weightedTraceForm f q) + +end SVI +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/Spreads.lean b/LeanPool/MathFin/Models/ModelFree/Spreads.lean new file mode 100644 index 0000000000..88b116d6b7 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/Spreads.lean @@ -0,0 +1,82 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.StrikeConvexity + +/-! +# Static spread no-arbitrage relations (bull-call, butterfly) + +Two static no-arbitrage payoff inequalities at expiry, both expressing +*structural properties of the call payoff in the strike*: + +* **Bull-call spread** `max(S − K₂, 0) ≤ max(S − K₁, 0)` for `K₁ ≤ K₂`: + the payoff `K ↦ max(S − K, 0)` is *antitone* in `K`. +* **Butterfly spread** `0 ≤ max(S − K₁, 0) − 2 · max(S − (K₁+K₃)/2, 0) + + max(S − K₃, 0)`: the payoff is *convex* in `K`, so its discrete + second-difference at the midpoint is non-negative. + +These are not two independent theorems; they are the *antitone* and *convex* +faces of `K ↦ max(S − K, 0)`. Both structural facts are recorded in +`StrikeConvexity.lean` (`antitone_call_payoff` and `convexOn_call_payoff`). + +The same convexity, applied infinitesimally rather than discretely, yields +non-negativity of the second `K`-derivative of the European call price — +i.e. the Breeden-Litzenberger implied PDF. + +## Main results + +* `bull_call_spread_payoff_le`: for `K₁ ≤ K₂`, `max (S - K₂) 0 ≤ max (S - K₁) 0`. +* `butterfly_payoff_nonneg`: `0 ≤ max (S - K₁) 0 - 2 * max (S - (K₁ + K₃) / 2) 0 + max (S - K₃) 0`. + Both are payoff inequalities at expiry, not statements about prices. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 11.5 + +## Tags + +bull spread, butterfly spread, static arbitrage, call payoff, Breeden–Litzenberger, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +/-- **Bull-call spread payoff non-negativity**: for `K₁ ≤ K₂`, +`max(S − K₂, 0) ≤ max(S − K₁, 0)`. Antitone face of the call payoff in `K`. -/ +lemma bull_call_spread_payoff_le (S K₁ K₂ : ℝ) (h : K₁ ≤ K₂) : + max (S - K₂) 0 ≤ max (S - K₁) 0 := + antitone_call_payoff S h + +/-- **Butterfly spread payoff non-negativity**: for `K₂ = (K₁ + K₃)/2`, +`0 ≤ max(S − K₁, 0) − 2 · max(S − (K₁+K₃)/2, 0) + max(S − K₃, 0)`. + +The discrete second-difference of the convex function `K ↦ max(S − K, 0)` at +the midpoint of `K₁` and `K₃` is non-negative: this is Jensen's inequality +`f((K₁+K₃)/2) ≤ (f(K₁) + f(K₃))/2`, multiplied by 2 and rearranged. The +hypothesis `K₁ ≤ K₃` is retained for API stability but is not needed for +the inequality. -/ +lemma butterfly_payoff_nonneg (S K₁ K₃ : ℝ) (_h : K₁ ≤ K₃) : + 0 ≤ + max (S - K₁) 0 - + 2 * max (S - (K₁ + K₃) / 2) 0 + + max (S - K₃) 0 := by + -- Convexity inequality at α = β = 1/2 (midpoint convex combination). + have h_conv := (convexOn_call_payoff S).2 (Set.mem_univ K₁) (Set.mem_univ K₃) + (by norm_num : (0:ℝ) ≤ 1/2) + (by norm_num : (0:ℝ) ≤ 1/2) + (by norm_num : (1/2:ℝ) + 1/2 = 1) + simp only [smul_eq_mul] at h_conv + rw [show (1/2 * K₁ + 1/2 * K₃ : ℝ) = (K₁ + K₃) / 2 from by ring] at h_conv + -- h_conv: max(S − midpoint, 0) ≤ (1/2)·max(S−K₁, 0) + (1/2)·max(S−K₃, 0) + -- Multiply by 2 and rearrange. + linarith + +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/VarianceSwap.lean b/LeanPool/MathFin/Models/ModelFree/VarianceSwap.lean new file mode 100644 index 0000000000..b94cbc1cbc --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/VarianceSwap.lean @@ -0,0 +1,165 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Distributions.Gaussian.Real + +/-! +# Variance swap fair strike (Demeterfi-Derman-Kamal) + +Under the BS lognormal hypothesis, the fair strike of a variance swap with +log-payoff replication + + `(2/T) · E_Q[log(F/S_T) + (S_T - F)/F] = σ²`, + +where `F = S_0 · e^{rT}` is the forward price. The two terms are: + +* `E_Q[log(F/S_T)] = σ² T / 2`: the log-moment of the discount factor `F/S_T`. + Comes from `log(F/S_T) = σ² T / 2 − σ √T · Z` (after the `S_0` cancellation) + and `E_Q[Z] = 0`. +* `E_Q[(S_T - F)/F] = 0`: zero by `expected_terminal_eq_forward` (`E_Q[S_T] = F`). + +The log piece alone gives `(2/T)·σ²T/2 = σ²`. The whole identity +`(2/T) · E_Q[log(F/S_T) + (S_T − F)/F] = σ²` (`varianceSwap_fairStrike`) is the no-jump case of +`jumpDiffusion_logContract` and lives in `JumpDiffusionVarianceSwap.lean`, with `E_Q[S_T] = F` +from `expected_terminal_eq_forward` (`Forward.lean`). Under BS lognormal dynamics the fair +variance swap rate equals the squared volatility, which is the relationship that makes BS implied +volatility a "risk-neutral expected variance". + +## Main results + +* `log_forward_div_bsTerminal_eq`: `log(F/S_T) = σ² T / 2 − σ √T · z`. +* `integral_log_forward_div_bsTerminal_eq`: + `E_Q[log(F/S_T)] = σ² T / 2`. +* `varianceSwap_log_contribution`: the log-payoff piece + `(2/T) · E_Q[log(F/S_T)] = σ²`. + +Model-free, for any law of the log-return `Y` with `S_T = S_0e^Y`, `S_0 > 0`, `E|Y| < ∞` and +`E[e^Y] < ∞`: + +* `integral_logContract`: the expected payoff is + `E[log(F/S_T) + (S_T − F)/F] = rT − E[Y] + (e^{−rT}E[e^Y] − 1)`. +* `integral_logContract_of_integral_exp`: when the forward is the mean of `S_T`, it is the gap + `rT − E[Y] = log F − E[log S_T]`. In Black–Scholes that gap is half the variance of `Y`; for a + jump-diffusion at the compensated drift it differs from half the variance by + `ΛT·E[e^J − 1 − J − J²/2]` (`jumpDiffusion_logContract_sub_variance`, + `JumpDiffusionVarianceSwap.lean`). + +## References + +* [P. Carr and D. Madan, *Towards a theory of volatility trading*][CarrMadan1998] +* [Carr and Wu, *Variance risk premiums*][CarrWu2009] +* [Cont and Tankov, *Financial Modelling with Jump Processes*][ContTankov2004] +* [Demeterfi et al., *More than you ever wanted to know about volatility + swaps*][DemeterfiDermanKamalZou1999] + +## Tags + +variance swap, fair strike, log contract, Demeterfi–Derman–Kamal, static replication, MSC 91G20, +JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal + +/-- **The log contract under any law of the log-return.** For `S > 0`, the forward +`F = Se^{rτ}` and a law `μ` of the log-return `Y`, with `S_τ = Se^Y`, `𝔼|Y| < ∞` and +`𝔼[e^Y] < ∞`, the Demeterfi–Derman–Kamal–Zou log contract has the expected payoff +`𝔼[log(F/S_τ) + (S_τ − F)/F] = rτ − 𝔼[Y] + (e^{−rτ}𝔼[e^Y] − 1)`: pointwise, `log(F/S_τ) = rτ − Y` +and `(S_τ − F)/F = e^{Y − rτ} − 1`. -/ +lemma integral_logContract {μ : Measure ℝ} [IsProbabilityMeasure μ] {S : ℝ} (hS : 0 < S) + (r τ : ℝ) (hY : Integrable (fun y ↦ y) μ) (hE : Integrable rexp μ) : + ∫ y, (Real.log (S * rexp (r * τ) / (S * rexp y)) + + (S * rexp y - S * rexp (r * τ)) / (S * rexp (r * τ))) ∂μ + = r * τ - ∫ y, y ∂μ + (rexp (-(r * τ)) * ∫ y, rexp y ∂μ - 1) := by + have hlog (y : ℝ) : Real.log (S * rexp (r * τ) / (S * rexp y)) = r * τ - y := by + rw [mul_div_mul_left _ _ hS.ne', ← Real.exp_sub, Real.log_exp] + have hfwd (y : ℝ) : (S * rexp y - S * rexp (r * τ)) / (S * rexp (r * τ)) + = rexp (-(r * τ)) * rexp y - 1 := by + rw [sub_div, mul_div_mul_left _ _ hS.ne', div_self (mul_pos hS (Real.exp_pos _)).ne', + Real.exp_neg, inv_mul_eq_div] + have hA : Integrable (fun y ↦ r * τ - y) μ := (integrable_const _).sub hY + have hB : Integrable (fun y ↦ rexp (-(r * τ)) * rexp y - 1) μ := + (hE.const_mul _).sub (integrable_const _) + simp only [hlog, hfwd] + rw [integral_add hA hB, integral_sub (integrable_const _) hY, + integral_sub (hE.const_mul _) (integrable_const _), integral_const_mul (rexp (-(r * τ))) rexp] + simp + +/-- **When the forward is the mean, the log contract's expected payoff is the gap** `rτ − 𝔼[Y]`: if +`𝔼[e^Y] = e^{rτ}`, the forward `F = Se^{rτ}` is the mean of `S_τ = Se^Y`, and the expected payoff of +the log contract is `rτ − 𝔼[Y] = log F − 𝔼[log S_τ]` (`integral_logContract`). -/ +lemma integral_logContract_of_integral_exp {μ : Measure ℝ} [IsProbabilityMeasure μ] {S : ℝ} + (hS : 0 < S) (r τ : ℝ) (hY : Integrable (fun y ↦ y) μ) + (hF : ∫ y, rexp y ∂μ = rexp (r * τ)) : + ∫ y, (Real.log (S * rexp (r * τ) / (S * rexp y)) + + (S * rexp y - S * rexp (r * τ)) / (S * rexp (r * τ))) ∂μ = r * τ - ∫ y, y ∂μ := by + have hE : Integrable rexp μ := + Integrable.of_integral_ne_zero (by rw [hF]; exact (Real.exp_pos _).ne') + rw [integral_logContract hS r τ hY hE, hF, ← Real.exp_add, neg_add_cancel, Real.exp_zero, + sub_self, add_zero] + +/-- **Log-moment integrand identity**: after the `S_0` cancellation, +`log((S_0 · e^{rT}) / (S_0 · exp((r − σ²/2)T + σ√T·z))) = σ²T/2 − σ√T·z`. -/ +lemma log_forward_div_bsTerminal_eq {S_0 : ℝ} (hS : 0 < S_0) (r σ T z : ℝ) : + Real.log ((S_0 * Real.exp (r * T)) / + (S_0 * Real.exp ((r - σ^2/2) * T + σ * Real.sqrt T * z))) + = σ^2 * T / 2 - σ * Real.sqrt T * z := by + have hS_ne : S_0 ≠ 0 := hS.ne' + rw [mul_div_mul_left _ _ hS_ne] + rw [← Real.exp_sub, Real.log_exp] + ring + +/-- **Log-moment integral identity**: `∫ z, log(F/S_T(z)) ∂(gaussianReal 0 1) += σ² T / 2`. -/ +lemma integral_log_forward_div_bsTerminal_eq {S_0 : ℝ} (hS : 0 < S_0) + (r σ T : ℝ) : + ∫ z, Real.log ((S_0 * Real.exp (r * T)) / + (S_0 * Real.exp ((r - σ^2/2) * T + σ * Real.sqrt T * z))) + ∂(gaussianReal 0 1) = σ^2 * T / 2 := by + have h_integrand_eq : ∀ z : ℝ, + Real.log ((S_0 * Real.exp (r * T)) / + (S_0 * Real.exp ((r - σ^2/2) * T + σ * Real.sqrt T * z))) + = σ^2 * T / 2 - σ * Real.sqrt T * z := + fun z ↦ log_forward_div_bsTerminal_eq hS r σ T z + rw [show (fun z ↦ Real.log ((S_0 * Real.exp (r * T)) / + (S_0 * Real.exp ((r - σ^2/2) * T + σ * Real.sqrt T * z)))) + = (fun z ↦ σ^2 * T / 2 - σ * Real.sqrt T * z) from funext h_integrand_eq] + have h_const_integrable : + Integrable (fun _ : ℝ ↦ σ^2 * T / 2) (gaussianReal 0 1) := + integrable_const _ + have h_id_basic : Integrable (id : ℝ → ℝ) (gaussianReal 0 1) := + (memLp_id_gaussianReal (μ := 0) (v := 1) 1).integrable (by norm_cast) + have h_id_integrable : + Integrable (fun z : ℝ ↦ σ * Real.sqrt T * z) (gaussianReal 0 1) := + h_id_basic.const_mul (σ * Real.sqrt T) + rw [integral_sub h_const_integrable h_id_integrable] + rw [integral_const, integral_const_mul, integral_id_gaussianReal] + simp + +/-- **Variance swap fair strike (log-payoff contribution)**: the log-payoff +replication piece scales to give the squared volatility. + +`(2/T) · E[log(F/S_T)] = σ²` under the BS lognormal hypothesis (with +`F = S_0 · e^{rT}`). The whole log contract, with the zero excess-return term +`E[(S_T − F)/F] = 0`, is `varianceSwap_fairStrike` (`JumpDiffusionVarianceSwap.lean`). -/ +theorem varianceSwap_log_contribution {S_0 : ℝ} (hS : 0 < S_0) + (r σ T : ℝ) (hT : T ≠ 0) : + (2 / T) * + (∫ z, Real.log ((S_0 * Real.exp (r * T)) / + (S_0 * Real.exp ((r - σ^2/2) * T + σ * Real.sqrt T * z))) + ∂(gaussianReal 0 1)) = σ^2 := by + rw [integral_log_forward_div_bsTerminal_eq hS] + field_simp + +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/VarianceSwapDriftImmunity.lean b/LeanPool/MathFin/Models/ModelFree/VarianceSwapDriftImmunity.lean new file mode 100644 index 0000000000..1de19201b0 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/VarianceSwapDriftImmunity.lean @@ -0,0 +1,105 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoProcessQV + +/-! +# Variance-swap fair strike is drift-immune: L² realized variance of GBM + +A variance swap pays the realized variance of log-returns against a fixed +strike. Quoting the fair strike as `σ²` presupposes that the realized +variance of the price path identifies `σ²` — *and does so regardless of the +drift*, since the physical drift is unknown and the risk-neutral drift is a +modelling choice. This file proves exactly that, in the strong (mean-square) +sense: + +for a geometric Brownian motion price +`S_t = S₀ · exp((μd − σ²/2)·t + σ·B_t)` with **arbitrary** drift parameter +`μd`, the realized variance of log-returns along the uniform `n`-partition +of `[0, T]` converges in `L²` to `σ²·T`: + + `E[(∑_k (log S_{t_{k+1}} − log S_{t_k})² − σ²T)²] → 0`. + +The drift does not appear in the limit: realized variance is a +quadratic-variation functional, and `Probability/Brownian/Ito/ItoProcessQV.lean` shows the +(Lipschitz) drift contributes `O(1/n)` to it. Financially: the +variance-swap fair strike can be quoted as `σ²` without taking a stance on +the drift — the estimator the swap settles on concentrates at `σ²T` under +the physical measure and the risk-neutral measure alike. + +## Relation to the existing variance-swap chain + +* `Models/ModelFree/VarianceSwapLimit.lean` (phase 34) proves the + *expectation-level* limit `E[Σ (Δ log S)²] → σ²T` for the risk-neutral BS + log-price (drift pinned to `r − σ²/2`). This file strengthens it twice: + convergence of the estimator itself in `L²` (concentration, not just + unbiasedness in the limit), and for every drift. +* `Models/ModelFree/VarianceSwap.lean` proves the Demeterfi–Derman–Kamal + log-payoff replication `(2/T)·E[log(F/S_T)] = σ²` — the static-hedge leg. + Together: the floating leg the swap *measures* (here) and the option + portfolio that *replicates* its strike (there) identify the same `σ²`. + +## Main results + +* `tendsto_realizedVariance_gbm_L2` — realized variance of GBM log-returns + `→ σ²·T` in `L²` along the uniform partition, for every drift `μd`: the limit does not + depend on it. + +## References + +* [Demeterfi et al., *More than you ever wanted to know about volatility + swaps*][DemeterfiDermanKamalZou1999] + +## Tags + +variance swap, realized variance, fair strike, geometric Brownian motion, drift independence, +mean-square convergence, MSC 91G20, MSC 60J65, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory MathFin.QuadraticVariationL2 Filter +open scoped NNReal ENNReal Topology + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + {B : ℝ≥0 → Ω → ℝ} + +/-- **Variance-swap drift immunity.** For a GBM price +`S_t = S₀ · exp((μd − σ²/2)t + σ B_t)` with arbitrary drift `μd`, the +realized variance of log-returns along the uniform partition of `[0, T]` +converges in mean-square to `σ²·T`. The drift is absent from the limit: +the fair variance strike is a quadratic-variation functional, immune to +the (physical vs. risk-neutral) drift. -/ +theorem tendsto_realizedVariance_gbm_L2 (hB : IsPreBrownianReal B μ) + (hBmeas : ∀ t, Measurable (B t)) (T : ℝ≥0) + {S : ℝ≥0 → Ω → ℝ} {S₀ μd σ : ℝ} (hS₀ : 0 < S₀) + (hS : ∀ t ω, S t ω = S₀ * Real.exp ((μd - σ ^ 2 / 2) * (t : ℝ) + σ * B t ω)) : + Tendsto (fun n : ℕ ↦ ∫ ω, (∑ k ∈ Finset.range n, + (Real.log (S (unifPart T n (k + 1)) ω) - Real.log (S (unifPart T n k) ω)) ^ 2 + - σ ^ 2 * (T : ℝ)) ^ 2 ∂μ) + atTop (𝓝 0) := by + -- The log-price is an Itô process with constant-slope drift and diffusion σ·B. + have hlog : ∀ (t : ℝ≥0) (ω : Ω), Real.log (S t ω) + = (fun _ : Ω ↦ Real.log S₀) ω + + (fun (t : ℝ≥0) (_ : Ω) ↦ (μd - σ ^ 2 / 2) * (t : ℝ)) t ω + + σ * B t ω := by + intro t ω + rw [hS t ω, Real.log_mul hS₀.ne' (Real.exp_pos _).ne', Real.log_exp] + ring + exact ItoProcessQV.tendsto_qv_ito_process hB hBmeas T + (X := fun t ω ↦ Real.log (S t ω)) + (Ca := |μd - σ ^ 2 / 2|) (abs_nonneg _) hlog + (fun t ↦ measurable_const) + (fun s t hst ω ↦ by + have hts : (s : ℝ) ≤ (t : ℝ) := NNReal.coe_le_coe.mpr hst + rw [← mul_sub, abs_mul, abs_of_nonneg (sub_nonneg.mpr hts)]) + +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/VarianceSwapEquipartition.lean b/LeanPool/MathFin/Models/ModelFree/VarianceSwapEquipartition.lean new file mode 100644 index 0000000000..d5e022c534 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/VarianceSwapEquipartition.lean @@ -0,0 +1,134 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.VarianceSwapFromQV + +/-! +# Variance-swap equipartition sum from QV (phase 33) + +Extends Phase 32's per-increment QV identity to the full **equipartition +sum** over `[0, T]`. For BS log-price `X_t := log S_0 + (r − σ²/2)·t + +σ·B_t` and a partition of `[0, T]` into `n + 1` equal subintervals: + + `E[Σ_{k=0}^{n} (X_{(k+1)T/(n+1)} − X_{kT/(n+1)})²] + = σ²·T + (r − σ²/2)²·T²/(n+1)`. + +The drift contribution `(r − σ²/2)² · T² / (n + 1)` vanishes as `n → ∞`, +so + + `lim_n E[Σ (X-increments)²] = σ²·T`, + +the QV characterisation of the variance-swap fair strike. The limit +theorem proper requires `Filter.Tendsto` analysis and is left as a +follow-up; the finite-`n` closed form here makes the limit obvious. + +## Main results + +* `integrable_bsLogPrice_sq_increment`: integrability of each per- + subinterval squared increment (needed to swap sum and integral). +* `expected_bsLogPrice_equipartition_sum` (main theorem): closed-form + finite-`n` equipartition-sum identity. + +## Tags + +variance swap, realized variance, quadratic variation, log-price increments, equipartition sum, +fair strike, MSC 91G20, MSC 60J65, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} {B : ℝ → Ω → ℝ} + +/-- **Integrability of each squared log-price increment** under a finite +measure. Derived from the algebraic decomposition +`(X_t − X_s)² = a² + 2aσ(B_t − B_s) + σ²(B_t − B_s)²` (with `a = (r − +σ²/2)(t − s)`) and the integrability of constants, of `(B_t − B_s)`, and +of `(B_t − B_s)²`. -/ +theorem integrable_bsLogPrice_sq_increment + [IsFiniteMeasure μ] + (hB : BrownianQuadraticVariation μ B) (S_0 r σ : ℝ) + {s t : ℝ} (hs : 0 ≤ s) (hst : s ≤ t) : + Integrable (fun ω ↦ (bsLogPrice S_0 r σ B t ω - + bsLogPrice S_0 r σ B s ω) ^ 2) μ := by + set a : ℝ := (r - σ ^ 2 / 2) * (t - s) with a_def + have h_eq : (fun ω ↦ (bsLogPrice S_0 r σ B t ω - + bsLogPrice S_0 r σ B s ω) ^ 2) + = (fun ω ↦ a ^ 2 + 2 * a * σ * (B t ω - B s ω) + + σ ^ 2 * (B t ω - B s ω) ^ 2) := by + funext ω + unfold bsLogPrice + rw [a_def]; ring + rw [h_eq] + exact ((integrable_const _).add + ((hB.integrable_increment hs hst).const_mul _)).add + ((hB.integrable_sq_increment hs hst).const_mul _) + +/-- **Variance-swap equipartition sum identity** (phase 33, main theorem). +For BS log-price `X_t := log S_0 + (r − σ²/2)·t + σ·B_t` under +`BrownianQuadraticVariation` hypothesis on `B` and a probability measure +`μ`, the expectation of the sum of squared increments along the +equipartition of `[0, T]` into `n + 1` equal subintervals is + + `E[Σ_{k=0}^{n} (X_{(k+1)T/(n+1)} − X_{kT/(n+1)})²] + = σ²·T + (r − σ²/2)²·T²/(n+1)`. + +Proof: apply Phase 32's per-increment identity to each summand (length +`T/(n+1)`), sum `n+1` identical contributions, and arithmetic. + +The drift contribution vanishes as `n → ∞`, giving the QV characterisation +of the variance-swap fair strike (`lim_n (1/T) · E[Σ ...] = σ²`). -/ +theorem expected_bsLogPrice_equipartition_sum + [IsProbabilityMeasure μ] + (hB : BrownianQuadraticVariation μ B) (S_0 r σ : ℝ) + {T : ℝ} (hT : 0 ≤ T) (n : ℕ) : + ∫ ω, ∑ k ∈ Finset.range (n + 1), + (bsLogPrice S_0 r σ B (((k : ℝ) + 1) * T / ((n : ℝ) + 1)) ω - + bsLogPrice S_0 r σ B ((k : ℝ) * T / ((n : ℝ) + 1)) ω) ^ 2 ∂μ + = σ ^ 2 * T + (r - σ ^ 2 / 2) ^ 2 * T ^ 2 / ((n : ℝ) + 1) := by + have hn_pos : (0 : ℝ) < (n : ℝ) + 1 := by positivity + have hn_ne : ((n : ℝ) + 1) ≠ 0 := hn_pos.ne' + have h_start_nonneg : ∀ k : ℕ, (0 : ℝ) ≤ (k : ℝ) * T / ((n : ℝ) + 1) := + fun k ↦ div_nonneg (mul_nonneg (Nat.cast_nonneg k) hT) hn_pos.le + -- subinterval endpoint inequality + have h_endpt_le : ∀ k : ℕ, + (((k : ℝ) * T) / ((n : ℝ) + 1)) ≤ + ((((k : ℝ) + 1) * T) / ((n : ℝ) + 1)) := by + intro k + rw [div_le_div_iff_of_pos_right hn_pos] + nlinarith + -- subinterval length T/(n+1) + have h_len : ∀ k : ℕ, + (((k : ℝ) + 1) * T) / ((n : ℝ) + 1) - + ((k : ℝ) * T) / ((n : ℝ) + 1) = T / ((n : ℝ) + 1) := by + intro k + field_simp + ring + -- swap sum and integral + rw [integral_finsetSum _ (fun k _ ↦ + integrable_bsLogPrice_sq_increment hB S_0 r σ (h_start_nonneg k) (h_endpt_le k))] + -- per-summand QV identity + have h_each : ∀ k ∈ Finset.range (n + 1), + ∫ ω, (bsLogPrice S_0 r σ B (((k : ℝ) + 1) * T / ((n : ℝ) + 1)) ω - + bsLogPrice S_0 r σ B ((k : ℝ) * T / ((n : ℝ) + 1)) ω) ^ 2 ∂μ + = σ ^ 2 * (T / ((n : ℝ) + 1)) + + (r - σ ^ 2 / 2) ^ 2 * (T / ((n : ℝ) + 1)) ^ 2 := by + intro k _ + rw [expected_bsLogPrice_sq_increment hB S_0 r σ (h_start_nonneg k) (h_endpt_le k)] + rw [h_len k] + rw [Finset.sum_congr rfl h_each, Finset.sum_const, Finset.card_range, + nsmul_eq_mul] + -- (n+1) · (σ²·h + drift²·h²) = σ²·T + drift²·T²/(n+1), h = T/(n+1) + push_cast + field_simp + +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/VarianceSwapEquivalence.lean b/LeanPool/MathFin/Models/ModelFree/VarianceSwapEquivalence.lean new file mode 100644 index 0000000000..aeefaeb294 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/VarianceSwapEquivalence.lean @@ -0,0 +1,107 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.VarianceSwapLimit +public import LeanPool.MathFin.Models.ModelFree.VarianceSwap + +/-! +# Variance-swap form equivalence (phase 45) + +Two *functionals* of the BS price process both yield the variance-swap +fair strike `σ²`: + +1. **Log-payoff replication** (Demeterfi-Derman-Kamal 1999, pre-existing + `Models/ModelFree/VarianceSwap.lean` `varianceSwap_log_contribution`): + `(2/T) · E_Q[log(F/S_T)] = σ²`. + +2. **Realised-variance QV limit** (Phase 34 `tendsto_expected_bsLogPrice_equipartition_sum`): + `lim_n E_Q[Σ_k (log S_{(k+1)T/(n+1)} − log S_{kT/(n+1)})²] = σ²·T`. + +The two forms compute the same `σ²` from different *integrals* of the same +underlying BS dynamics. This file proves their *agreement* — both equal +`σ²` (which is the variance-swap fair strike). + +## Why this is a meaningful bridge + +The log-payoff form is the **static replication** characterisation +(Carr-Madan style): you can replicate a variance swap from a portfolio of +log payoffs `log S_T` plus dynamic delta-hedging. The QV form is the +**realised-variance estimator** characterisation: you can estimate σ² by +summing squared log-returns over a fine partition. + +Both being equal to σ² is a structural identity of the BS model: the +*model parameter* `σ²` (a single number characterising volatility) +agrees with *two distinct empirical / replication-based measurements* of +volatility. + +## Main results + +* `varianceSwap_log_eq_QV_limit_value`: the **genuine two-functional + agreement** — the log-payoff form equals `σ²` AND the realised-variance + QV-limit `lim_n E_Q[Σ_k (Δlog S)²] → σ²·T` (the actual equipartition + `Tendsto`, `tendsto_expected_bsLogPrice_equipartition_sum`), under a + Brownian-quadratic-variation hypothesis on the driver. + +The full equivalence at the *random-variable* level (showing both functionals +coincide on the path of `S_t`, not just on their values) would require the +continuous Itô-to-log identity, which is gated. + +## References + +* [Demeterfi et al., *More than you ever wanted to know about volatility + swaps*][DemeterfiDermanKamalZou1999] + +## Tags + +variance swap, realised variance, quadratic variation, log-payoff replication, fair variance strike, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- **The two variance-swap characterisations agree** — both genuinely +recover the model variance. For Brownian dynamics `B` (a +`BrownianQuadraticVariation`), the two *distinct functionals* of the BS +log-price both yield `σ²`: + +* the **log-payoff static-replication** integral equals `σ²` + (`varianceSwap_log_contribution`), and +* the **realised-variance QV limit** — the *actual* equipartition functional + `lim_n E_Q[Σ_k (Δlog S)²]` — converges to `σ²·T` + (`tendsto_expected_bsLogPrice_equipartition_sum`, Phase 34). + +Unlike a tautological `σ² = σ²` restatement, **both conjuncts here are the +genuine functionals**: the second is the honest `Tendsto` of the squared- +increment sum, not a placeholder. `hB` is load-bearing (it feeds the QV-limit +theorem), and `hT : 0 < T` feeds both conjuncts — its `≠ 0` half the log +form, its `≤` half the QV limit. This is the real model-level equivalence of +the static-replication and realised-variance characterisations of the fair +strike. -/ +theorem varianceSwap_log_eq_QV_limit_value + {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ → Ω → ℝ} (hB : BrownianQuadraticVariation μ B) + {S_0 : ℝ} (hS : 0 < S_0) (r σ : ℝ) {T : ℝ} (hT : 0 < T) : + -- Log-payoff (static-replication) form = σ² + (2 / T) * (∫ z, Real.log ((S_0 * Real.exp (r * T)) / + (S_0 * Real.exp ((r - σ^2/2) * T + σ * Real.sqrt T * z))) ∂(gaussianReal 0 1)) + = σ ^ 2 ∧ + -- Realised-variance QV-limit form → σ²·T (the genuine equipartition functional) + Filter.Tendsto + (fun n : ℕ ↦ ∫ ω, ∑ k ∈ Finset.range (n + 1), + (bsLogPrice S_0 r σ B (((k : ℝ) + 1) * T / ((n : ℝ) + 1)) ω - + bsLogPrice S_0 r σ B ((k : ℝ) * T / ((n : ℝ) + 1)) ω) ^ 2 ∂μ) + Filter.atTop (nhds (σ ^ 2 * T)) := + ⟨varianceSwap_log_contribution hS r σ T hT.ne', + tendsto_expected_bsLogPrice_equipartition_sum hB S_0 r σ hT.le⟩ + +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/VarianceSwapFromQV.lean b/LeanPool/MathFin/Models/ModelFree/VarianceSwapFromQV.lean new file mode 100644 index 0000000000..361a89fe9e --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/VarianceSwapFromQV.lean @@ -0,0 +1,145 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.BrownianQuadraticVariation + +/-! +# Variance-swap log-price increment from Brownian quadratic variation (phase 32) + +The pre-existing `Models/ModelFree/VarianceSwap.lean` proves the Demeterfi- +Derman-Kamal log-payoff identity `(2/T) · E[log(F/S_T)] = σ²` — the +*replicating-portfolio* characterisation of the variance-swap fair strike. + +This file provides the *quadratic-variation* characterisation: the +expected squared increment of the BS log-price `X_t := log S_0 + (r − +σ²/2)·t + σ · B_t` over a single sub-interval `[s, t]` is + + `E[(X_t − X_s)²] = σ² · (t − s) + (r − σ²/2)² · (t − s)²`, + +a direct algebraic consequence of `(X_t − X_s)² = σ²(B_t − B_s)² + +2σ(r−σ²/2)(t−s)(B_t − B_s) + (r−σ²/2)²(t−s)²`, integrating term by term +using + +* `BrownianQuadraticVariation.integral_increment`: `E[B_t − B_s] = 0`, +* `BrownianQuadraticVariation.integral_sq_increment`: `E[(B_t − B_s)²] = t − s`. + +In the limit of finer partitions of `[0, T]` (deferred to follow-up), the +drift contribution `(r−σ²/2)²·T²/(n+1)` vanishes and the realised +variance converges to `σ²·T`, matching the `varianceSwap_log_contribution` +result via a different functional of the same price process. + +## Why this is a "bridge" + +`Probability/Brownian/BrownianQuadraticVariation.lean` (L¹ QV identity for pure BM) +was previously **not consumed by any pricing module**. This file gives it +its first downstream use: deriving the per-increment expectation of the +*log-price* (with drift), the building block for the realised-variance / +QV-style derivation of the variance-swap fair strike. + +## Main definitions + +* `bsLogPrice`: the Black–Scholes log-price process `X_t = log S₀ + (r − σ²/2)·t + σ·B_t`. + +## Main results + +* `expected_bsLogPrice_sq_increment`: the per-increment QV identity for + BS log-price. + +## Tags + +variance swap, quadratic variation, log-price, Black–Scholes, fair strike, Demeterfi–Derman–Kamal, +MSC 91G20, MSC 60J65, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} {B : ℝ → Ω → ℝ} + +/-- BS log-price process: `X_t(ω) = log S_0 + (r − σ²/2)·t + σ · B_t(ω)`. -/ +noncomputable def bsLogPrice (S_0 r σ : ℝ) (B : ℝ → Ω → ℝ) (t : ℝ) (ω : Ω) : ℝ := + Real.log S_0 + (r - σ ^ 2 / 2) * t + σ * B t ω + +/-- **Variance-swap per-increment QV identity** (phase 32, main theorem). +Under the `BrownianQuadraticVariation` hypothesis on `B` and a probability +measure `μ`, the expected squared increment of the BS log-price equals + + `E[(X_t − X_s)²] = σ² · (t − s) + (r − σ²/2)² · (t − s)²`, + +for `s ≤ t`. Algebraically: +`(X_t − X_s)² = σ²(B_t − B_s)² + 2σ(r−σ²/2)(t−s)(B_t − B_s) + (r−σ²/2)²(t−s)²`, +and integrating term by term uses `integral_sq_increment` (E[X²] = t−s), +`integral_increment` (E[X] = 0), and the constancy of the drift² term. + +In the equipartition of `[0, T]` with `n + 1` subintervals, the drift +contribution sums to `(r − σ²/2)² · T² / (n + 1) → 0`, so + + `lim_n E[Σ (X_{t_{k+1}} − X_{t_k})²] = σ² · T`, + +the QV / realised-variance characterisation of the variance-swap fair +strike (deferred to a follow-up phase). -/ +theorem expected_bsLogPrice_sq_increment + [IsProbabilityMeasure μ] + (hB : BrownianQuadraticVariation μ B) + (S_0 r σ : ℝ) {s t : ℝ} (hs : 0 ≤ s) (hst : s ≤ t) : + ∫ ω, (bsLogPrice S_0 r σ B t ω - bsLogPrice S_0 r σ B s ω) ^ 2 ∂μ + = σ ^ 2 * (t - s) + (r - σ ^ 2 / 2) ^ 2 * (t - s) ^ 2 := by + -- Increment: X_t - X_s = (r-σ²/2)(t-s) + σ(B_t - B_s) + set a : ℝ := (r - σ ^ 2 / 2) * (t - s) with a_def + have h_inc : ∀ ω : Ω, + bsLogPrice S_0 r σ B t ω - bsLogPrice S_0 r σ B s ω = + a + σ * (B t ω - B s ω) := by + intro ω + unfold bsLogPrice + rw [a_def]; ring + -- Squared: (a + σX)² = a² + 2aσX + σ²X² + have h_sq : ∀ ω : Ω, + (bsLogPrice S_0 r σ B t ω - bsLogPrice S_0 r σ B s ω) ^ 2 = + a ^ 2 + 2 * a * σ * (B t ω - B s ω) + σ ^ 2 * (B t ω - B s ω) ^ 2 := by + intro ω + rw [h_inc]; ring + -- Integrate term by term using public BQV helpers + rw [show (fun ω ↦ (bsLogPrice S_0 r σ B t ω - bsLogPrice S_0 r σ B s ω) ^ 2) = + (fun ω ↦ a ^ 2 + 2 * a * σ * (B t ω - B s ω) + + σ ^ 2 * (B t ω - B s ω) ^ 2) from funext h_sq] + have h_int_const : Integrable (fun _ : Ω ↦ a ^ 2) μ := integrable_const _ + have h_int_lin : Integrable + (fun ω ↦ 2 * a * σ * (B t ω - B s ω)) μ := + (hB.integrable_increment hs hst).const_mul (2 * a * σ) + have h_int_sq : Integrable + (fun ω ↦ σ ^ 2 * (B t ω - B s ω) ^ 2) μ := + (hB.integrable_sq_increment hs hst).const_mul (σ ^ 2) + -- Split the three-term integral via two `integral_add` extractions (avoids + -- the syntactic-vs-definitional mismatch between `Integrable.add` Pi-form + -- and the literal lambda in the goal). + have h_split_outer : + ∫ ω, a ^ 2 + 2 * a * σ * (B t ω - B s ω) + + σ ^ 2 * (B t ω - B s ω) ^ 2 ∂μ + = (∫ ω, a ^ 2 + 2 * a * σ * (B t ω - B s ω) ∂μ) + + ∫ ω, σ ^ 2 * (B t ω - B s ω) ^ 2 ∂μ := + integral_add (h_int_const.add h_int_lin) h_int_sq + have h_split_inner : + ∫ ω, a ^ 2 + 2 * a * σ * (B t ω - B s ω) ∂μ + = (∫ ω, (a : ℝ) ^ 2 ∂μ) + + ∫ ω, 2 * a * σ * (B t ω - B s ω) ∂μ := + integral_add h_int_const h_int_lin + have h_const_int : ∫ _ω : Ω, (a : ℝ) ^ 2 ∂μ = a ^ 2 := by + rw [integral_const]; simp + have h_lin_int : ∫ ω, 2 * a * σ * (B t ω - B s ω) ∂μ = 0 := by + rw [integral_const_mul, hB.integral_increment hs hst, mul_zero] + have h_sq_int : ∫ ω, σ ^ 2 * (B t ω - B s ω) ^ 2 ∂μ = σ ^ 2 * (t - s) := by + rw [integral_const_mul, hB.integral_sq_increment hs hst] + rw [h_split_outer, h_split_inner, h_const_int, h_lin_int, h_sq_int] + rw [a_def] + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/ModelFree/VarianceSwapLimit.lean b/LeanPool/MathFin/Models/ModelFree/VarianceSwapLimit.lean new file mode 100644 index 0000000000..563d796a07 --- /dev/null +++ b/LeanPool/MathFin/Models/ModelFree/VarianceSwapLimit.lean @@ -0,0 +1,112 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.VarianceSwapEquipartition + +/-! +# Variance-swap QV limit theorem (phase 34) + +Closes the QV chain: Phase 32 gave the per-increment identity, Phase 33 +gave the finite-`n` equipartition-sum identity, and this file takes the +limit `n → ∞`: + + `lim_n E[Σ_{k=0}^{n} (X_{(k+1)T/(n+1)} − X_{kT/(n+1)})²] = σ²·T`, + +the QV / realised-variance characterisation of the variance-swap fair +strike. The drift contribution `(r − σ²/2)² · T² / (n + 1)` vanishes as +`n → ∞` by standard `Tendsto` analysis +(`tendsto_one_div_add_atTop_nhds_zero_nat`). + +## Main results + +* `tendsto_expected_bsLogPrice_equipartition_sum`: the realised-variance + expectation converges to `σ²·T` as the partition refines. + +## Companion: the log-payoff form + +The pre-existing `Models/ModelFree/VarianceSwap.lean` proves the Demeterfi- +Derman-Kamal log-payoff identity `(2/T) · E[log(F/S_T)] = σ²`. The two +characterisations of `σ²` (realised-variance / QV here, log-payoff +replication there) are different functionals of the same BS price process. + +## Tags + +variance swap, realized variance limit, quadratic variation, fair strike, partition refinement, +MSC 91G20, MSC 60J65, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real Filter + +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} {B : ℝ → Ω → ℝ} + +/-- **QV limit theorem** (phase 34): under `BrownianQuadraticVariation` +hypothesis on `B` and a probability measure `μ`, the expected sum of +squared BS-log-price increments along the equipartition of `[0, T]` +converges to `σ² · T` as the partition refines: + + `lim_n E[Σ_{k=0}^{n} (X_{(k+1)T/(n+1)} − X_{kT/(n+1)})²] = σ² · T`. + +Proof structure: +1. Build `Tendsto (fun _ ↦ σ²·T) atTop (𝓝 (σ²·T))` (constant). +2. Build `Tendsto (fun n ↦ drift² · T² / (n+1)) atTop (𝓝 0)` via + `tendsto_one_div_add_atTop_nhds_zero_nat` + scaling. +3. Add the two via `Tendsto.add` ⟹ `Tendsto (σ²·T + drift²·T²/(n+1)) + atTop (𝓝 (σ²·T + 0)) = (𝓝 (σ²·T))`. +4. Apply `.congr` with Phase 33's per-`n` closed form to convert to the + target functional. -/ +theorem tendsto_expected_bsLogPrice_equipartition_sum + [IsProbabilityMeasure μ] + (hB : BrownianQuadraticVariation μ B) (S_0 r σ : ℝ) + {T : ℝ} (hT : 0 ≤ T) : + Filter.Tendsto + (fun n : ℕ ↦ ∫ ω, ∑ k ∈ Finset.range (n + 1), + (bsLogPrice S_0 r σ B (((k : ℝ) + 1) * T / ((n : ℝ) + 1)) ω - + bsLogPrice S_0 r σ B ((k : ℝ) * T / ((n : ℝ) + 1)) ω) ^ 2 ∂μ) + Filter.atTop (nhds (σ ^ 2 * T)) := by + -- Step 1: drift contribution → 0 via 1/(n+1) → 0 + scaling. + have h_one_div : Filter.Tendsto (fun n : ℕ ↦ (1 : ℝ) / ((n : ℝ) + 1)) + Filter.atTop (nhds (0 : ℝ)) := + tendsto_one_div_add_atTop_nhds_zero_nat + have h_decay_mul : Filter.Tendsto + (fun n : ℕ ↦ (r - σ ^ 2 / 2) ^ 2 * T ^ 2 * ((1 : ℝ) / ((n : ℝ) + 1))) + Filter.atTop (nhds ((r - σ ^ 2 / 2) ^ 2 * T ^ 2 * 0)) := + h_one_div.const_mul _ + rw [mul_zero] at h_decay_mul + have h_decay : Filter.Tendsto + (fun n : ℕ ↦ (r - σ ^ 2 / 2) ^ 2 * T ^ 2 / ((n : ℝ) + 1)) + Filter.atTop (nhds (0 : ℝ)) := by + refine h_decay_mul.congr ?_ + intro n + rw [mul_one_div] + -- Step 2: constant Tendsto for σ²·T. + have h_const : Filter.Tendsto (fun _ : ℕ ↦ σ ^ 2 * T) + Filter.atTop (nhds (σ ^ 2 * T)) := + tendsto_const_nhds + -- Step 3: sum of two Tendsto, then simplify nhds(σ²·T + 0) = nhds(σ²·T). + have h_sum : + Filter.Tendsto + (fun n : ℕ ↦ σ ^ 2 * T + + (r - σ ^ 2 / 2) ^ 2 * T ^ 2 / ((n : ℝ) + 1)) + Filter.atTop (nhds (σ ^ 2 * T)) := by + have := h_const.add h_decay + rwa [add_zero] at this + -- Step 4: rewrite target via Phase 33's closed form per `n`. + have h_eq : ∀ n : ℕ, + ∫ ω, ∑ k ∈ Finset.range (n + 1), + (bsLogPrice S_0 r σ B (((k : ℝ) + 1) * T / ((n : ℝ) + 1)) ω - + bsLogPrice S_0 r σ B ((k : ℝ) * T / ((n : ℝ) + 1)) ω) ^ 2 ∂μ + = σ ^ 2 * T + (r - σ ^ 2 / 2) ^ 2 * T ^ 2 / ((n : ℝ) + 1) := + fun n ↦ expected_bsLogPrice_equipartition_sum hB S_0 r σ hT n + exact h_sum.congr (fun n ↦ (h_eq n).symm) + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/ABCDBlack76.lean b/LeanPool/MathFin/Models/Rates/ABCDBlack76.lean new file mode 100644 index 0000000000..bd41ed2570 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/ABCDBlack76.lean @@ -0,0 +1,183 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralGaussian +public import LeanPool.MathFin.Models.Rates.ABCDVolatility +public import LeanPool.MathFin.Models.Forwards.Black76 + +/-! +# ABCD volatility prices through Black-76 at its root-mean-square + +`Models/Rates/ABCDVolatility.lean` gives the ABCD instantaneous volatility +`f(τ) = (a + bτ)e^{−cτ} + d` of a forward rate as a function of its time to maturity `τ`, and +the closed form of its integrated variance `v(T) = ∫₀ᵀ f(τ)² dτ`. This file feeds that shape +to a forward and prices a call on it. + +The forward fixing at `T` has, at calendar time `u`, the volatility `f(T − u)`. Driftless and +lognormal (as under its own forward measure), it is, in solved form, + + `F_T = F₀ · exp(−v(T)/2 + ∫₀ᵀ f(T − u) dB_u)`. + +The stochastic integral is the Wiener integral of a deterministic integrand, so by +`wienerIntegralLp_hasLaw_gaussian` (`Probability/Brownian/Wiener/WienerIntegralGaussian.lean`) it is +centred Gaussian with variance `∫₀ᵀ f(T − u)² du = v(T)`, the ABCD closed form +(`abcdWienerIntegral_hasLaw`). Standardising it puts the forward in the Black–Scholes shape at +the volatility `σ_bar = √(v(T)/T)`, the root-mean-square of the instantaneous volatility over +`[0, T]`, and `black_futures_formula` (`Models/Forwards/Black76.lean`) prices the call: the +`e^{−rT}`-discounted call on `F_T` is the Black-76 price at `σ_bar` +(`abcdForward_call_eq_black76`). This is the computation behind quoting a caplet's Black +volatility as the root-mean-square of the instantaneous one (Rebonato); the caplet itself is not +modelled (see the scope note). + +**Scope.** The forward is taken in its solved form; the SDE `dF = F f(T − u) dB` it solves is +cited, not proved, as for the Vasicek short rate (`Models/Rates/VasicekSDEGaussian.lean`). The +expectation is under the probability measure carrying the Brownian motion, read as the +forward measure; no change of measure is built. The discounting is the factor `e^{−rT}` of +`black_futures_formula`; the caplet's accrual `δ` and payment-date discount factor +`P(0, T + δ)` are not modelled. + +## Main definitions + +* `abcdKernel`: the integrand `u ↦ abcdVol a b c d (T - u)` of the forward fixing at `T`. +* `abcdKernelLp`: `abcdKernel` as an element of `L²((0, T])`. +* `abcdTotalVar`: the ABCD total variance `v(T)`, in the closed form of `abcdVol_sq_integral_zero`. +* `abcdForward`: the forward fixing `F₀ * exp (-v(T)/2 + ∫₀ᵀ f(T - u) dB_u)`, for a pre-Brownian + motion `B`. +* `abcdRMSVol`: the root-mean-square volatility `√(v(T)/T)`. + +## Main results + +* `abcdKernel_integral_sq` — `∫_{(0,T]} f(T − u)² du = v(T)`, for `c ≠ 0`. +* `abcdWienerIntegral_hasLaw` — `∫₀ᵀ f(T − u) dB_u ~ N(0, v(T))`, for `c ≠ 0`. +* `abcdForward_call_eq_black76` — the discounted call on the ABCD forward is Black-76 at `σ_bar`. + +## References + +* [F. Black, *The pricing of commodity contracts*][Black1976] +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], ch. + 6 +* [R. Rebonato, *Modern Pricing of Interest-Rate Derivatives: The LIBOR Market Model and + Beyond*][Rebonato2002] + +## Tags + +ABCD volatility, Black-76, caplet volatility, Wiener integral, forward rate volatility, Rebonato, +MSC 91G30, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set +open scoped NNReal +open WienerIntegralL2 + +/-- The ABCD integrand of the forward fixing at `T`: at calendar time `u` its volatility is the +ABCD shape at the time to maturity `T − u`. -/ +noncomputable def abcdKernel (a b c d T : ℝ) : ℝ → ℝ := fun u ↦ abcdVol a b c d (T - u) + +/-- The ABCD integrand is in `L²((0, T])`: it is continuous, hence bounded on `[0, T]`. -/ +lemma abcdKernel_memLp (a b c d : ℝ) (T : ℝ≥0) : + MemLp (abcdKernel a b c d T) 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := by + have hcont : Continuous (abcdKernel a b c d T) := by + unfold abcdKernel abcdVol + fun_prop + obtain ⟨C, hC⟩ := (isCompact_Icc (a := (0 : ℝ)) (b := (T : ℝ))).exists_bound_of_continuousOn + hcont.continuousOn + refine (memLp_top_of_bound hcont.aestronglyMeasurable C ?_).mono_exponent le_top + exact (ae_restrict_iff' measurableSet_Ioc).mpr + (ae_of_all _ fun u hu ↦ hC u (Ioc_subset_Icc_self hu)) + +/-- The ABCD integrand as an element of `L²((0, T])`. -/ +noncomputable def abcdKernelLp (a b c d : ℝ) (T : ℝ≥0) : + Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := + (abcdKernel_memLp a b c d T).toLp _ + +/-- The total integrated variance `v(T) = ∫₀ᵀ f(τ)² dτ`, in the closed form of +`abcdVol_sq_integral_zero`. -/ +noncomputable def abcdTotalVar (a b c d T : ℝ) : ℝ := + abcdIntegratedVarAntideriv a b c d T - abcdIntegratedVarAntideriv a b c d 0 + +/-- **The integrand's square integrates to the ABCD total variance**: +`∫_{(0,T]} f(T − u)² du = v(T)`, for `c ≠ 0`, by the substitution `τ = T − u` and +`abcdVol_sq_integral_zero`. -/ +lemma abcdKernel_integral_sq (a b c d : ℝ) (hc : c ≠ 0) (T : ℝ≥0) : + ∫ u in Set.Ioc (0 : ℝ) (T : ℝ), (abcdKernel a b c d T u) ^ 2 ∂volume + = abcdTotalVar a b c d T := by + rw [← intervalIntegral.integral_of_le (NNReal.coe_nonneg T)] + simp only [abcdKernel] + rw [intervalIntegral.integral_comp_sub_left (fun τ ↦ abcdVol a b c d τ ^ 2), sub_self, + sub_zero] + exact abcdVol_sq_integral_zero a b c d T hc + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-- **The ABCD stochastic integral is Gaussian with the ABCD total variance**: +`∫₀ᵀ f(T − u) dB_u ~ N(0, v(T))`, for `c ≠ 0` — the Wiener integral of a deterministic +integrand (`wienerIntegralLp_hasLaw_gaussian`) with its variance in closed form. -/ +theorem abcdWienerIntegral_hasLaw (hB : IsPreBrownianReal B μ) (a b c d : ℝ) (hc : c ≠ 0) + (T : ℝ≥0) : + HasLaw (fun ω ↦ wienerIntegralLp B hB T (abcdKernelLp a b c d T) ω) + (gaussianReal 0 (abcdTotalVar a b c d T).toNNReal) μ := + wienerIntegralLp_hasLaw_gaussian_of_integral_sq hB T (abcdKernelLp a b c d T) + ((abcdKernel_memLp a b c d T).integral_sq_toLp.trans (abcdKernel_integral_sq a b c d hc T)) + +/-- The forward fixing at `T` under ABCD volatility, in solved form: +`F_T = F₀ · exp(−v(T)/2 + ∫₀ᵀ f(T − u) dB_u)`. -/ +noncomputable def abcdForward (hB : IsPreBrownianReal B μ) (F₀ a b c d : ℝ) (T : ℝ≥0) + (ω : Ω) : ℝ := + F₀ * Real.exp (-(abcdTotalVar a b c d T / 2) + wienerIntegralLp B hB T (abcdKernelLp a b c d T) ω) + +/-- The root-mean-square ABCD volatility over `[0, T]`: `σ_bar = √(v(T)/T)`. -/ +noncomputable def abcdRMSVol (a b c d T : ℝ) : ℝ := Real.sqrt (abcdTotalVar a b c d T / T) + +/-- **The discounted call on the ABCD forward is Black-76 at the root-mean-square volatility.** +For `F₀, K, T > 0`, `c ≠ 0` and a positive total variance `v(T)`, +`𝔼[e^{−rT}·(F_T − K)⁺] = e^{−rT}·(F₀Φ(d₁) − KΦ(d₂))` with `d₁, d₂` at `σ_bar = √(v(T)/T)`. The +standardised integral `(∫₀ᵀ f(T − u) dB_u)/√v(T)` is the standard normal of `BSCallHyp`, and +`black_futures_formula` prices the call. -/ +theorem abcdForward_call_eq_black76 (hB : IsPreBrownianReal B μ) {F₀ K : ℝ} (r a b c d : ℝ) + (hc : c ≠ 0) {T : ℝ≥0} (hF : 0 < F₀) (hK : 0 < K) (hT : 0 < (T : ℝ)) + (hv : 0 < abcdTotalVar a b c d T) : + ∫ ω, Real.exp (-r * T) * max (abcdForward hB F₀ a b c d T ω - K) 0 ∂μ + = Real.exp (-r * T) * (F₀ * Phi (bsd1 F₀ K 0 (abcdRMSVol a b c d T) T) + - K * Phi (bsd2 F₀ K 0 (abcdRMSVol a b c d T) T)) := by + have hsv : Real.sqrt (abcdTotalVar a b c d T) ≠ 0 := (Real.sqrt_pos.mpr hv).ne' + have hT0 : (T : ℝ) ≠ 0 := hT.ne' + have hZ : HasLaw (fun ω ↦ wienerIntegralLp B hB T (abcdKernelLp a b c d T) ω + / Real.sqrt (abcdTotalVar a b c d T)) (gaussianReal 0 1) μ := by + have h := gaussianReal_div_const (abcdWienerIntegral_hasLaw hB a b c d hc T) + (Real.sqrt (abcdTotalVar a b c d T)) + rw [zero_div] at h + convert h using 2 + refine NNReal.coe_injective ?_ + rw [NNReal.coe_one, NNReal.coe_div, NNReal.coe_mk, Real.sq_sqrt hv.le, + Real.coe_toNNReal _ hv.le, div_self hv.ne'] + have hhyp : BSCallHyp μ F₀ K 0 (abcdRMSVol a b c d T) T + (fun ω ↦ wienerIntegralLp B hB T (abcdKernelLp a b c d T) ω + / Real.sqrt (abcdTotalVar a b c d T)) := + ⟨hF, hK, Real.sqrt_pos.mpr (div_pos hv hT), hT, hZ⟩ + have hsq : abcdRMSVol a b c d T ^ 2 = abcdTotalVar a b c d T / T := + Real.sq_sqrt (div_pos hv hT).le + have hmul : abcdRMSVol a b c d T * Real.sqrt T = Real.sqrt (abcdTotalVar a b c d T) := by + rw [abcdRMSVol, ← Real.sqrt_mul (div_pos hv hT).le, div_mul_cancel₀ _ hT.ne'] + have hterm (ω : Ω) : bsTerminal F₀ 0 (abcdRMSVol a b c d T) T + (wienerIntegralLp B hB T (abcdKernelLp a b c d T) ω / Real.sqrt (abcdTotalVar a b c d T)) + = abcdForward hB F₀ a b c d T ω := by + rw [bsTerminal, abcdForward, hmul, hsq] + congr 2 + field_simp + ring + have h := black_futures_formula hhyp r + simp only [hterm] at h + exact h + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/ABCDVolatility.lean b/LeanPool/MathFin/Models/Rates/ABCDVolatility.lean new file mode 100644 index 0000000000..4cc06fc8b0 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/ABCDVolatility.lean @@ -0,0 +1,152 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.SpecialFunctions.ExpDeriv +public import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus + +/-! +# ABCD instantaneous volatility — closed-form integrated variance + +The **ABCD parametrization** (Rebonato) is the standard humped +instantaneous-volatility shape used for forward rates / caplets in LIBOR market +models, as a function of the time to maturity `τ`: + + `f(τ) = (a + b·τ) · e^{-c·τ} + d`. + +It is a decaying (for `c > 0`) term `(a+bτ)e^{-cτ}` — typically hump-shaped, +rising then decaying — superposed on a floor `d`. The quantity that feeds +cap/caplet and swaption pricing is the **integrated variance** over a window +`[T1, T2]`, + + `∫_{T1}^{T2} f(τ)² dτ`, + +an elementary integral of a (quadratic polynomial)×(exponential) plus linear +and constant cross terms. We give the closed-form antiderivative and the +resulting definite-integral formula via the FTC, the same explicit-antiderivative +FTC route as the Vasicek kernel variance integral +(`integral_vasicekIntegratedKernel_sq_eq_sub`, `Models/Rates/VasicekBondPrice.lean`). +Every result below assumes `c ≠ 0` (the antiderivative divides by `c`). + +## Main definitions + +* `abcdVol`: the ABCD instantaneous volatility `f(τ) = (a + b·τ) · e^{-c·τ} + d`. +* `abcdIntegratedVarAntideriv`: the closed-form antiderivative of `abcdVol a b c d τ ^ 2`. + +## Main results + +* `hasDerivAt_abcdIntegratedVarAntideriv` — the core calculus fact: its + derivative is `f(τ)²`, for `c ≠ 0`. +* `abcdVol_sq_integral` — the definite integral + `∫_{T1}^{T2} f(τ)² dτ = F(T2) - F(T1)` via FTC, for `c ≠ 0`. +* `abcdVol_sq_integral_zero` — the `[0, T]`-window specialization. + +## References + +* [R. Rebonato, *Modern Pricing of Interest-Rate Derivatives: The LIBOR Market Model and + Beyond*][Rebonato2002]. + +## Tags + +ABCD volatility, Rebonato, LIBOR market model, integrated variance, caplet volatility, +forward rate volatility, MSC 91G30, JEL E43 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- **ABCD instantaneous volatility**: `f(τ) = (a + b·τ) · e^{-c·τ} + d`. -/ +noncomputable def abcdVol (a b c d τ : ℝ) : ℝ := (a + b * τ) * Real.exp (-(c * τ)) + d + +/-- Closed-form antiderivative of `abcdVol a b c d τ ^ 2`, obtained by integrating +the three terms of `f² = (a+bτ)²e^{-2cτ} + 2d(a+bτ)e^{-cτ} + d²` separately: +the quadratic-times-exponential antiderivative `-(e^{-2cτ}/2c)·[(a+bτ)² + +b(a+bτ)/c + b²/2c²]`, the linear-times-exponential antiderivative +`-(2d·e^{-cτ}/c)·[(a+bτ) + b/c]`, and `d²τ`. -/ +noncomputable def abcdIntegratedVarAntideriv (a b c d τ : ℝ) : ℝ := + -(1 / (2 * c)) * (Real.exp (-(2 * c * τ)) * + ((a + b * τ) * (a + b * τ) + b * (a + b * τ) / c + b ^ 2 / (2 * c ^ 2))) + + -(2 * d / c) * (Real.exp (-(c * τ)) * ((a + b * τ) + b / c)) + + d ^ 2 * τ + +/-- **The core calculus fact**: the closed-form antiderivative differentiates +back to `abcdVol a b c d τ ^ 2`, for `c ≠ 0`. -/ +theorem hasDerivAt_abcdIntegratedVarAntideriv (a b c d τ : ℝ) (hc : c ≠ 0) : + HasDerivAt (abcdIntegratedVarAntideriv a b c d) (abcdVol a b c d τ ^ 2) τ := by + have h_lin : HasDerivAt (fun τ : ℝ ↦ a + b * τ) b τ := by + have hbτ : HasDerivAt (fun τ : ℝ ↦ b * τ) b τ := by + simpa using (hasDerivAt_id τ).const_mul b + simpa using hbτ.const_add a + have h_exp2c : HasDerivAt (fun τ : ℝ ↦ Real.exp (-(2 * c * τ))) + (Real.exp (-(2 * c * τ)) * -(2 * c)) τ := by + have h2cτ : HasDerivAt (fun τ : ℝ ↦ 2 * c * τ) (2 * c) τ := by + simpa using (hasDerivAt_id τ).const_mul (2 * c) + simpa using h2cτ.neg.exp + have h_expc : HasDerivAt (fun τ : ℝ ↦ Real.exp (-(c * τ))) + (Real.exp (-(c * τ)) * -c) τ := by + have hcτ : HasDerivAt (fun τ : ℝ ↦ c * τ) c τ := by + simpa using (hasDerivAt_id τ).const_mul c + simpa using hcτ.neg.exp + -- `P(τ) = (a+bτ)² + b(a+bτ)/c + b²/2c²`, the bracket of the quadratic term. + have h_P : HasDerivAt + (fun τ : ℝ ↦ (a + b * τ) * (a + b * τ) + b * (a + b * τ) / c + b ^ 2 / (2 * c ^ 2)) + (b * (a + b * τ) + (a + b * τ) * b + b * b / c) τ := by + have h1 : HasDerivAt (fun τ : ℝ ↦ (a + b * τ) * (a + b * τ)) + (b * (a + b * τ) + (a + b * τ) * b) τ := h_lin.mul h_lin + have h2 : HasDerivAt (fun τ : ℝ ↦ b * (a + b * τ) / c) (b * b / c) τ := + (h_lin.const_mul b).div_const c + exact (h1.add h2).add_const (b ^ 2 / (2 * c ^ 2)) + -- `Q(τ) = (a+bτ) + b/c`, the bracket of the linear term. + have h_Q : HasDerivAt (fun τ : ℝ ↦ (a + b * τ) + b / c) b τ := h_lin.add_const (b / c) + have h_prod1 : HasDerivAt + (fun τ : ℝ ↦ Real.exp (-(2 * c * τ)) * + ((a + b * τ) * (a + b * τ) + b * (a + b * τ) / c + b ^ 2 / (2 * c ^ 2))) + (Real.exp (-(2 * c * τ)) * -(2 * c) * + ((a + b * τ) * (a + b * τ) + b * (a + b * τ) / c + b ^ 2 / (2 * c ^ 2)) + + Real.exp (-(2 * c * τ)) * (b * (a + b * τ) + (a + b * τ) * b + b * b / c)) τ := + h_exp2c.mul h_P + have h_prod2 : HasDerivAt + (fun τ : ℝ ↦ Real.exp (-(c * τ)) * ((a + b * τ) + b / c)) + (Real.exp (-(c * τ)) * -c * ((a + b * τ) + b / c) + Real.exp (-(c * τ)) * b) τ := + h_expc.mul h_Q + have h_F1 := h_prod1.const_mul (-(1 / (2 * c))) + have h_F2 := h_prod2.const_mul (-(2 * d / c)) + have h_F3 : HasDerivAt (fun τ : ℝ ↦ d ^ 2 * τ) (d ^ 2) τ := by + simpa using (hasDerivAt_id τ).const_mul (d ^ 2) + have h_total := (h_F1.add h_F2).add h_F3 + refine h_total.congr_deriv ?_ + have he2 : Real.exp (-(2 * c * τ)) = Real.exp (-(c * τ)) * Real.exp (-(c * τ)) := by + rw [← Real.exp_add]; congr 1; ring + unfold abcdVol + rw [he2] + field_simp + ring + +/-- **ABCD integrated variance over `[T1, T2]`**, via the FTC, for `c ≠ 0`: +`∫_{T1}^{T2} f(τ)² dτ = F(T2) - F(T1)`, `F = abcdIntegratedVarAntideriv`. -/ +theorem abcdVol_sq_integral (a b c d T1 T2 : ℝ) (hc : c ≠ 0) : + ∫ τ in T1..T2, abcdVol a b c d τ ^ 2 + = abcdIntegratedVarAntideriv a b c d T2 - abcdIntegratedVarAntideriv a b c d T1 := by + apply intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun τ _ ↦ hasDerivAt_abcdIntegratedVarAntideriv a b c d τ hc) + apply Continuous.intervalIntegrable + unfold abcdVol + fun_prop + +/-- **The `[0, T]`-window specialization** (`c ≠ 0`), the usual "total integrated variance +to maturity `T`" used in caplet/swaption calibration. -/ +theorem abcdVol_sq_integral_zero (a b c d T : ℝ) (hc : c ≠ 0) : + ∫ τ in (0 : ℝ)..T, abcdVol a b c d τ ^ 2 + = abcdIntegratedVarAntideriv a b c d T - abcdIntegratedVarAntideriv a b c d 0 := + abcdVol_sq_integral a b c d 0 T hc + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/AffineTermStructurePDE.lean b/LeanPool/MathFin/Models/Rates/AffineTermStructurePDE.lean new file mode 100644 index 0000000000..adfdd33aca --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/AffineTermStructurePDE.lean @@ -0,0 +1,208 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.CIRRiccati +public import LeanPool.MathFin.Models.Rates.VasicekBondPrice + +/-! +# Affine bond prices solve the term-structure PDE + +In a one-factor affine short-rate model `dr = κ(θ − r) dt + √(α + β r) dW`, bond prices take +the form `P = exp(A(τ) − B(τ)·r)` in the time to maturity `τ`, with loadings solving the +Riccati system + + `B' = 1 − κB − ½βB²`, `A' = −κθB + ½αB²`, `A(0) = B(0) = 0` + +(Duffie–Kan; that general statement is not proved here). `affineBondPrice_solves_pde` proves +the step from the Riccati system to the pricing equation: whenever `A` and `B` satisfy the two +equations at `τ`, the function +`u(τ, r) = exp(A(τ) − B(τ)·r)` satisfies, at `(τ, r)`, the term-structure PDE + + `−∂_τ u + κ(θ − r)·∂_r u + ½(α + β r)·∂²_r u − r·u = 0`. + +Two models are instances: + +* **Cox–Ingersoll–Ross**, `(α, β) = (0, σ²)`: the closed-form loadings `cirBondA`, `cirBondB` + of `Models/Rates/CIRRiccati.lean` solve their Riccati equations there, so `exp(A − B·r)` + solves the CIR pricing PDE (`cirBondPrice_solves_pde`). That this closed form equals the + expectation `𝔼[exp(−∫₀ᵀ r_s ds)]` (Feynman–Kac for the CIR process) is not proved. +* **Vasicek**, `(α, β) = (σ², 0)`: the rate loading `vasicekBondB` solves `B' = 1 − κB` + (`hasDerivAt_vasicekBondB`), the variance `vasicekBondV` has derivative `B²` + (`hasDerivAt_vasicekBondV`), so `log vasicekBondA` solves `A' = −κθB + ½σ²B²` + (`hasDerivAt_log_vasicekBondA`), and `vasicekBondA·exp(−B·r)` solves the Vasicek pricing PDE + (`vasicekBondPrice_solves_pde`). Here the closed form is the expectation: + `vasicekBondPrice_affine` (`Models/Rates/VasicekBondPrice.lean`) derives + `𝔼[exp(−∫₀ᵀ r_s ds)] = vasicekBondA·exp(−B·r₀)` from the Gaussian law of the integrated rate. + +At zero volatility the two models coincide, and so do their rate loadings: +`cirBondB κ 0 = vasicekBondB κ` for `κ ≠ 0` (`cirBondB_zero_vol`). + +## Main results + +* `affineBondPrice_solves_pde` — the Riccati system implies the term-structure PDE. +* `cirBondPrice_solves_pde` — the CIR closed form solves the CIR PDE, for `σ ≠ 0`. +* `hasDerivAt_vasicekBondB`, `hasDerivAt_vasicekBondV`, `hasDerivAt_log_vasicekBondA` — the + Vasicek loadings solve their Riccati equations, for `κ ≠ 0`. +* `vasicekBondPrice_solves_pde` — the Vasicek affine price solves the Vasicek PDE, for `κ ≠ 0`. +* `cirBondB_zero_vol` — the CIR rate loading at `σ = 0` is the Vasicek rate loading. + +## References + +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + §3.2.3 +* [J. C. Cox, J. E. Ingersoll and S. A. Ross, *A theory of the term structure of interest + rates*][CoxIngersollRoss1985] +* [D. Duffie and R. Kan, *A yield-factor model of interest rates*][DuffieKan1996] +* [O. Vasicek, *An equilibrium characterization of the term structure*][Vasicek1977] + +## Tags + +term structure PDE, Riccati equation, affine short-rate model, Cox–Ingersoll–Ross, Vasicek model, +bond pricing equation, MSC 91G30, MSC 35K10, JEL E43 +-/ + +@[expose] public section + +namespace MathFin + +/-! ### The Riccati system implies the pricing PDE -/ + +/-- **Affine bond prices solve the term-structure PDE** (Duffie–Kan, one factor). If the +loadings satisfy the Riccati equations `A' = −κθB + ½αB²` and `B' = 1 − κB − ½βB²` at `τ`, then +`u(τ, r) = exp(A(τ) − B(τ)·r)` satisfies +`−∂_τ u + κ(θ − r)·∂_r u + ½(α + β r)·∂²_r u − r·u = 0` at `(τ, r)`: the drift `κ(θ − r)` and +the variance `α + βr` of the short rate `dr = κ(θ − r)dt + √(α + βr) dW`. -/ +theorem affineBondPrice_solves_pde {κ θ α β : ℝ} {A B : ℝ → ℝ} {τ : ℝ} + (hA : HasDerivAt A (-(κ * θ) * B τ + α / 2 * B τ ^ 2) τ) + (hB : HasDerivAt B (1 - κ * B τ - β / 2 * B τ ^ 2) τ) (r : ℝ) : + -deriv (fun t ↦ Real.exp (A t - B t * r)) τ + + κ * (θ - r) * deriv (fun x ↦ Real.exp (A τ - B τ * x)) r + + (α + β * r) / 2 * deriv (deriv fun x ↦ Real.exp (A τ - B τ * x)) r + - r * Real.exp (A τ - B τ * r) = 0 := by + have hτ : HasDerivAt (fun t ↦ Real.exp (A t - B t * r)) + (Real.exp (A τ - B τ * r) + * ((-(κ * θ) * B τ + α / 2 * B τ ^ 2) - (1 - κ * B τ - β / 2 * B τ ^ 2) * r)) τ := + (hA.sub (hB.mul_const r)).exp + have hx (x : ℝ) : HasDerivAt (fun y ↦ Real.exp (A τ - B τ * y)) + (Real.exp (A τ - B τ * x) * -B τ) x := + (((hasDerivAt_id' x).const_mul (B τ)).const_sub (A τ)).exp.congr_deriv (by ring) + have hxx : HasDerivAt (fun y ↦ Real.exp (A τ - B τ * y) * -B τ) + (Real.exp (A τ - B τ * r) * -B τ * -B τ) r := + (hx r).mul_const (-B τ) + rw [hτ.deriv, (hx r).deriv, show deriv (fun y ↦ Real.exp (A τ - B τ * y)) + = fun y ↦ Real.exp (A τ - B τ * y) * -B τ from funext fun y ↦ (hx y).deriv, hxx.deriv] + ring + +/-! ### Cox–Ingersoll–Ross -/ + +/-- **The CIR closed form solves the CIR pricing PDE.** For `σ ≠ 0`, the closed-form loadings +`cirBondA`, `cirBondB` make `u(τ, r) = exp(A(τ) − B(τ)·r)` a solution of +`−∂_τ u + κ(θ − r)·∂_r u + ½σ² r·∂²_r u − r·u = 0` (the affine PDE with `(α, β) = (0, σ²)`). +That `u` is the bond price `𝔼[exp(−∫₀ᵀ r_s ds)]` of the CIR process is not proved. -/ +theorem cirBondPrice_solves_pde (κ θ : ℝ) {σ : ℝ} (hσ : σ ≠ 0) (τ r : ℝ) : + -deriv (fun t ↦ Real.exp (cirBondA κ θ σ t - cirBondB κ σ t * r)) τ + + κ * (θ - r) * deriv (fun x ↦ Real.exp (cirBondA κ θ σ τ - cirBondB κ σ τ * x)) r + + σ ^ 2 * r / 2 * deriv (deriv fun x ↦ Real.exp (cirBondA κ θ σ τ - cirBondB κ σ τ * x)) r + - r * Real.exp (cirBondA κ θ σ τ - cirBondB κ σ τ * r) = 0 := by + have h := affineBondPrice_solves_pde (κ := κ) (θ := θ) (α := 0) (β := σ ^ 2) + ((hasDerivAt_cirBondA κ θ hσ τ).congr_deriv (by ring)) + (hasDerivAt_cirBondB (by positivity) τ) r + rwa [show (0 + σ ^ 2 * r) / 2 = σ ^ 2 * r / 2 by ring] at h + +/-! ### Vasicek -/ + +/-- **The Vasicek rate loading solves `B' = 1 − κB`** (the CIR Riccati equation without its +quadratic term), for `κ ≠ 0`: `B(T) = (1 − e^{−κT})/κ` has derivative `e^{−κT}`. -/ +theorem hasDerivAt_vasicekBondB {κ : ℝ} (hκ : κ ≠ 0) (T : ℝ) : + HasDerivAt (vasicekBondB κ) (1 - κ * vasicekBondB κ T) T := by + have he : HasDerivAt (fun t ↦ Real.exp (-(κ * t))) (Real.exp (-(κ * T)) * -κ) T := + ((hasDerivAt_id' T).const_mul κ).neg.exp.congr_deriv (by simp only [Pi.neg_apply, mul_one]) + refine ((he.const_sub 1).div_const κ).congr_deriv ?_ + rw [vasicekBondB] + field_simp + ring + +/-- **The Vasicek variance has derivative `B²`**: `V' = vasicekBondB²`, for `κ ≠ 0`, where +`V(T) = T/κ² − 2(1 − e^{−κT})/κ³ + (1 − e^{−2κT})/(2κ³)` is `vasicekBondV`. -/ +theorem hasDerivAt_vasicekBondV {κ : ℝ} (hκ : κ ≠ 0) (T : ℝ) : + HasDerivAt (vasicekBondV κ) (vasicekBondB κ T ^ 2) T := by + have e1 : HasDerivAt (fun t ↦ Real.exp (-(κ * t))) (Real.exp (-(κ * T)) * -κ) T := + ((hasDerivAt_id' T).const_mul κ).neg.exp.congr_deriv (by simp only [Pi.neg_apply, mul_one]) + have e2 : HasDerivAt (fun t ↦ Real.exp (-(2 * κ * t))) (Real.exp (-(2 * κ * T)) * -(2 * κ)) T := + ((hasDerivAt_id' T).const_mul (2 * κ)).neg.exp.congr_deriv + (by simp only [Pi.neg_apply, mul_one]) + have hE : Real.exp (-(2 * κ * T)) = Real.exp (-(κ * T)) ^ 2 := by + rw [← Real.exp_nat_mul] + congr 1 + push_cast + ring + refine ((((hasDerivAt_id' T).div_const (κ ^ 2)).sub + (((e1.const_sub 1).const_mul 2).div_const (κ ^ 3))).add + ((e2.const_sub 1).div_const (2 * κ ^ 3))).congr_deriv ?_ + rw [vasicekBondB, hE] + field_simp + ring + +/-- The Vasicek level loading in log form: `log A(T) = −θ(T − B(T)) + σ²V(T)/2`, where +`vasicekBondA` is the exponential of that expression. -/ +theorem log_vasicekBondA (θ σ κ T : ℝ) : + Real.log (vasicekBondA θ σ κ T) + = -(θ * (T - vasicekBondB κ T)) + σ ^ 2 * vasicekBondV κ T / 2 := + Real.log_exp _ + +/-- **The Vasicek level loading solves `A' = −κθB + ½σ²B²`** (log form), for `κ ≠ 0`: the +CIR level equation with the quadratic term moved from the rate loading to the level loading +(constant variance `σ²` instead of `σ² r`). -/ +theorem hasDerivAt_log_vasicekBondA (θ σ : ℝ) {κ : ℝ} (hκ : κ ≠ 0) (T : ℝ) : + HasDerivAt (fun t ↦ Real.log (vasicekBondA θ σ κ t)) + (-(κ * θ) * vasicekBondB κ T + σ ^ 2 / 2 * vasicekBondB κ T ^ 2) T := by + simp only [log_vasicekBondA] + exact ((((hasDerivAt_id' T).sub (hasDerivAt_vasicekBondB hκ T)).const_mul θ).neg.add + (((hasDerivAt_vasicekBondV hκ T).const_mul (σ ^ 2)).div_const 2)).congr_deriv (by ring) + +/-- **The Vasicek affine price solves the Vasicek pricing PDE.** For `κ ≠ 0`, +`u(τ, r) = vasicekBondA(τ)·exp(−vasicekBondB(τ)·r)` satisfies +`−∂_τ u + κ(θ − r)·∂_r u + ½σ²·∂²_r u − r·u = 0` (the affine PDE with `(α, β) = (σ², 0)`). +By `vasicekBondPrice_affine`, for `κ > 0` and `τ = T ≥ 0` this `u` is the bond price +`𝔼[exp(−∫₀ᵀ r_s ds)]` of the Vasicek short rate started at `r`. -/ +theorem vasicekBondPrice_solves_pde (θ σ : ℝ) {κ : ℝ} (hκ : κ ≠ 0) (τ r : ℝ) : + -deriv (fun t ↦ vasicekBondA θ σ κ t * Real.exp (-(vasicekBondB κ t * r))) τ + + κ * (θ - r) * deriv (fun x ↦ vasicekBondA θ σ κ τ * Real.exp (-(vasicekBondB κ τ * x))) r + + σ ^ 2 / 2 + * deriv (deriv fun x ↦ vasicekBondA θ σ κ τ * Real.exp (-(vasicekBondB κ τ * x))) r + - r * (vasicekBondA θ σ κ τ * Real.exp (-(vasicekBondB κ τ * r))) = 0 := by + have hfun (t x : ℝ) : vasicekBondA θ σ κ t * Real.exp (-(vasicekBondB κ t * x)) + = Real.exp (Real.log (vasicekBondA θ σ κ t) - vasicekBondB κ t * x) := by + rw [log_vasicekBondA, vasicekBondA, ← Real.exp_add] + rfl + simp only [hfun] + have h := affineBondPrice_solves_pde (κ := κ) (θ := θ) (α := σ ^ 2) (β := 0) + (hasDerivAt_log_vasicekBondA θ σ hκ τ) + ((hasDerivAt_vasicekBondB hκ τ).congr_deriv (by ring)) r + rwa [show (σ ^ 2 + 0 * r) / 2 = σ ^ 2 / 2 by ring] at h + +/-! ### Zero volatility -/ + +/-- **At zero volatility the CIR rate loading is the Vasicek rate loading**: +`cirBondB κ 0 T = vasicekBondB κ T = (1 − e^{−κT})/κ` for `κ ≠ 0`. Both models reduce to the +deterministic short rate `r' = κ(θ − r)`, and `γ = √(κ²) = |κ|`. -/ +theorem cirBondB_zero_vol {κ : ℝ} (hκ : κ ≠ 0) (T : ℝ) : cirBondB κ 0 T = vasicekBondB κ T := by + have hγ : cirGamma κ 0 = |κ| := by simp [cirGamma, Real.sqrt_sq_eq_abs] + rcases lt_or_gt_of_ne hκ with hneg | hpos + · rw [abs_of_neg hneg] at hγ + have hD : cirDenom κ 0 T = -(2 * κ) := by rw [cirDenom, hγ]; ring + rw [cirBondB, hD, hγ, vasicekBondB, neg_mul] + field_simp + ring + · rw [abs_of_pos hpos] at hγ + have hD : cirDenom κ 0 T = 2 * κ * Real.exp (κ * T) := by rw [cirDenom, hγ]; ring + rw [cirBondB, hD, hγ, vasicekBondB, Real.exp_neg] + field_simp + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/BondForward.lean b/LeanPool/MathFin/Models/Rates/BondForward.lean new file mode 100644 index 0000000000..4c65644440 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/BondForward.lean @@ -0,0 +1,85 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.NoArbitrageDerivations + +/-! +# Bond forward price from no-arbitrage + +A forward contract on a coupon bond, struck at forward price `X`, maturing at +the forward-expiry date `t_fe`, has zero time-0 value exactly when discounting +the strike `X` paid at `t_fe` back to today equals the bond's price net of the +discounted coupons it sheds before `t_fe`, + + `Df(t_fe) · X = P₀ - Σ_{t ≤ t_fe} Df(t) · CF(t)`, + +equivalently (the usual cash-and-carry forward-price statement: each coupon +`CF(t)` paid at `t ≤ t_fe` is kept along the way and is worth `Df(t) · CF(t)` +today) + + `X = (P₀ - Σ_{t ≤ t_fe} Df(t) · CF(t)) / Df(t_fe)`. + +Here `s` is the caller-supplied set of coupon dates in `(0, t_fe]`; nothing in +`Finset ι` itself enforces that range, so passing it correctly is the +caller's responsibility. The coupon-stripped spot `P₀ - Σ Df(t)·CF(t)` plays +the role of `S₀` in `forward_price_from_no_arbitrage` +(`MathFin/Pricing/NoArbitrageDerivations.lean`), and +`bondForwardPrice_from_no_arbitrage` derives the forward price from it: in a +finite-state market whose state prices price the bond as its pre-expiry coupons +plus its value at `t_fe`, the forward contract paying `B(t_fe) - X` is worth +zero exactly at `X = bondForwardPrice`. + +## Main definitions + +* `bondForwardPrice`: the no-arbitrage forward price `X = (P₀ - Σ Df(t)·CF(t)) / Df(t_fe)` of a + coupon bond, with the coupons paid before the forward expiry `t_fe` discounted out. + +## Main results + +* `bondForwardPrice_from_no_arbitrage`: the forward price derived from + `forward_price_from_no_arbitrage`, with the coupon-stripped bond as the asset. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull] + +## Tags + +bond forward price, cash-and-carry, coupon-bearing bond, forward contract, no-arbitrage pricing, +state prices, MSC 91G30, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +variable {ι : Type*} + +/-- The **bond forward price**: the no-arbitrage forward price +`X = (P₀ - Σ Df(t)·CF(t)) / Df(t_fe)`. -/ +noncomputable def bondForwardPrice (s : Finset ι) (Df : ι → ℝ) (CF : ι → ℝ) + (P0 Df_fe : ℝ) : ℝ := + (P0 - ∑ t ∈ s, Df t * CF t) / Df_fe + +/-- **Bond forward price from no-arbitrage.** A finite-state market with state +prices `q` on the states `Ω` at the forward-expiry date `t_fe`: the zero-coupon +bond to `t_fe` costs `Df_fe = Σ q ω` (`Df_fe ≠ 0`), and the bond, worth `B ω` +(ex-coupon) at `t_fe` in state `ω`, is priced as its coupons paid up to `t_fe` +plus its value then, `P₀ = Σ Df(t)·CF(t) + Σ q ω · B ω`. Then the forward +contract paying `B - X` at `t_fe` is worth zero iff `X = bondForwardPrice`: +this is `forward_price_from_no_arbitrage` with the coupon-stripped bond +`P₀ - Σ Df(t)·CF(t)` as the spot. -/ +theorem bondForwardPrice_from_no_arbitrage {Ω : Type*} (states : Finset Ω) (q B : Ω → ℝ) + (s : Finset ι) (Df CF : ι → ℝ) (P0 Df_fe X : ℝ) (hDf : Df_fe ≠ 0) + (h_zcb : ∑ ω ∈ states, q ω = Df_fe) + (h_bond : P0 = ∑ t ∈ s, Df t * CF t + ∑ ω ∈ states, q ω * B ω) : + ∑ ω ∈ states, q ω * (B ω - X) = 0 ↔ X = bondForwardPrice s Df CF P0 Df_fe := + forward_price_from_no_arbitrage states q B Df_fe _ X hDf h_zcb (eq_sub_of_add_eq' h_bond.symm) + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/Bootstrapping.lean b/LeanPool/MathFin/Models/Rates/Bootstrapping.lean new file mode 100644 index 0000000000..1126931594 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/Bootstrapping.lean @@ -0,0 +1,712 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Analysis.Bisection +public import LeanPool.MathFin.Models.Rates.FRA +public import LeanPool.MathFin.Models.Rates.InterestRateSwap +public import LeanPool.MathFin.Models.Rates.YieldCurve +public import Mathlib.Analysis.SpecialFunctions.Log.Base + +/-! +# Curve bootstrapping by bracketing search + +Every curve starts as instrument quotes and ends as discount factors; the +algorithm between is **bootstrapping** — solve one instrument at a time for +its new discount factor, with the already-solved factors held fixed. This +module connects the curve instruments (`fraValue`, `payerSwapValue` — both +carry `zero_iff` root conditions in `MathFin`) to a proved bisection +root-finder: each step reprices its instrument to tolerance, and the induction +`boot` carries that to every step under per-step hypotheses stated at the +prefix the recursion feeds in. + +The module layers: + +* **A bisection engine** — imported from `MathFin.Probability.Analysis.Bisection` (not + duplicated here): the iteration `bisectStep` / `bisect` / `bisectMid` with + its three facts — the bracket is invariant around the threshold, the error + is at most half the interval per step, and the estimates converge. +* **A threshold bridge** (private) — the engine's hypothesis + (`∀ x ∈ [lo, hi], f x < C ↔ x < σ`) is produced from an affine function with + positive slope (`mul_sub_lt_neg_iff`). +* **The affine bootstrap step** — `affineStep_err` / `affineStep_tendsto` / + `affineStep_value_err` / `affineStep_stepBudget`: bisection, from a bracket + containing the root `(a − c)/b`, of an increasing rearrangement `x ↦ b·x − a` + at level `−c` converges to that root; the instrument reprices to within + `b·(hi − lo)/2^{n+1}` of the quote, and some `n ≤ ⌈log₂ (b·(hi−lo)/ε)⌉` steps + achieve accuracy `ε`. +* **The FRA as an instrument** — with the earlier discount factor `p` fixed + and the later one `x ≠ 0` bootstrapped, the FRA value is `p − (1 + δ·K)·x` — + affine, covered when `1 + δ·K > 0`; strictly antitone, so the negated value is + an increasing solving function (`fraThreshold`), and + `fraValue_newUnknown_eq_quote_iff` is the root condition in the new unknown + (with `fraRoot_agrees_with_pin`, it recovers `fraValue_zcb_eq_zero_iff` on the + flat curve). +* **The payer swap as an instrument** — with the fixed schedule already + bootstrapped (annuity `A` constant in the new factor `x`), the value is + `(P0 − K·A) − x`: affine with slope `−1`, strictly antitone with **no** + positivity condition; at zero quote the fixed rate is par at the root + (`swapRoot_is_par`, consuming `payerSwapValue_eq_zero_iff`). + With one payment at the new maturity (annuity `A₀ + δ·x`), the value is + `(P0 − K·A₀) − (1 + K·δ)·x` — covered under `1 + K·δ > 0` + (`swapLastCouponThreshold`). +* **The swap is a par coupon bond** — the zero-value last-coupon swap at fixed rate `K` + is the coupon-bond pricing equation `couponBondPricingEq` of + `Models/Rates/YieldCurve.lean` with coupon `K·δ` and face `1` + (`payerSwapValue_lastCoupon_eq_zero_iff_couponBond`), so the closed-form bootstrap + `bootstrap_solve` names the swap's root, and bisection on the swap recovers the + discount factor of the coupon bond (`swapBootstrap_recovers_couponBondFactor`). +* **The induction** — `boot` builds the curve by structural recursion over + the instrument index: step `i` bisects instrument `i`'s solving function on + the prefix bootstrapped so far, so each step literally inherits the previous + factors. `boot_step_err` bounds every step, `boot_length` (proved by + induction) tracks the curve, and `boot_reprices_all` is the repricing + theorem over all instruments — with hypotheses stated at the fed-in prefix + (see the scope note). `fraChain` with `boot_reprices_fraChain` runs the + FRA strip through the induction (fixed rate `K i` per FRA; step `0` is the + spot deposit, anchored at the valuation-date factor `1`), and `swapChain` + with `boot_reprices_swapChain` does the same for the spot-starting swap + strip (fixed rate `K i` per maturity, last-coupon annuity over the prefix) + — both discharging every hypothesis of `boot_reprices_all` except the + per-step bracket condition, under the instrument layer's standing + conditions. +* **Flat-curve capstone** — `fraBootstrap_flatCurve`: if the fixed rate + equals the flat-curve forward rate, bisection at zero quote from any positive bracket + around the true later discount factor recovers it to within + `(hi − lo)/2^{n+1}`. + +Scope of the induction: the hypotheses of `boot_step_err` and +`boot_reprices_all` are stated at the prefix the recursion actually feeds the +step — `boot V c lo hi n i`, the factors the earlier steps produced — and, on +that prefix, on the step's own bracket `[lo i, hi i]` (bisection evaluates the +instrument nowhere else). Each step assumes only what it consumes: the +instrument's threshold shape and affine identity at the run's actual earlier +factors, and a bracket containing the root computed from them. The first two are +exactly the facts the instrument layers provide at any prefix — the FRA by +`fraValue_affine_of_newUnknown` + `fraThreshold` (under `δ ≠ 0`, `1 + δ·K > 0`, +on a positive bracket), the known-schedule swap by +`payerSwapValue_affine_of_newUnknown` + `swapThreshold` (no slope condition), +the last-coupon swap by `payerSwapValue_affine_lastCoupon` + +`swapLastCouponThreshold` (under `1 + K·δ > 0`) — and `boot_reprices_fraChain` / +`boot_reprices_swapChain` discharge every hypothesis of `boot_reprices_all` +except the bracket condition for `fraChain` / `swapChain`, the FRA and swap +strips as `boot` instruments, under those standing conditions. The bracket +condition stays a hypothesis: the root moves with the prefix, so which bracket +is adequate depends on the factors the run produced, and the theorems ask for +exactly that, at the step that uses it. The pointwise per-`n` error bound is the +curve-level statement (convergence of the factors as `n → ∞` would follow by +induction on `i` when the hypotheses hold for every `n` and each threshold is +continuous in the prefix — as for `fraChain` / `swapChain`, whose roots are +affine in it — but is not formalized). Excluded: instruments whose +*already-fixed* legs contain the new factor (forward-starting fixed/floating +exchanges — the value is still affine in the bracket but with a slope of unknown +sign, possibly zero, so no bracketing sign change is guaranteed), and joint +solves for several new factors at once. + +Boundary: `MathFin/Models/Rates/YieldCurve.lean` owns the closed-form +`bootstrap_solve*` names; this module owns the search-based bootstrap, and the swap layer +proves that bisection on the swap lands within `(hi − lo)/2^{n+1}` of the closed-form root, for a +bracket containing it (`swapBootstrap_recovers_couponBondFactor`). + +## Main definitions + +* `boot`: the bootstrapped curve, a list of discount factors after the first `i` instruments, the + head being the newest. +* `fraChain`: the FRA strip as a `boot` instrument, instrument `i` being the FRA with fixed rate + `K i` that reads the new discount factor `x`. +* `swapChain`: the swap strip as a `boot` instrument, instrument `i` being the spot-starting + payer swap maturing at the new discount factor. + +## Main results + +* `affineStep_err`: for `b > 0` and a root `(a − c)/b` in `[lo, hi]`, bisection on `b·x − a` + at target `−c` is within `(hi − lo)/2^{n+1}` of that root after `n` steps. +* `fraValue_affine_of_newUnknown`, `fraValue_newUnknown_eq_quote_iff`: for `δ ≠ 0`, the FRA value + at the bootstrapped forward rate is `p − (1 + δK)·x` (for `x ≠ 0`); for `x > 0` and + `1 + δK > 0` it equals the quote `c` if and only if `x = (p − c)/(1 + δK)`. +* `strictAntiOn_fraValue`, `fraStep_err`: for `δ ≠ 0` and `1 + δK > 0`, the FRA value is + strictly decreasing on `x > 0`, and bisection from a bracket `[lo, hi]` with `lo > 0` + containing `(p − c)/(1 + δK)` lands within `(hi − lo)/2^{n+1}` of it. +* `swapRoot_is_par`, `strictAnti_payerSwapValue`, `swapStep_err`: for `A ≠ 0` the root + `P0 − K·A` of the payer swap has par rate `K`; the swap value is strictly decreasing in the + new factor with no positivity condition, and bisection on it lands within `(hi − lo)/2^{n+1}` + of the root when a bracket contains it. +* `payerSwapValue_lastCoupon_eq_zero_iff_couponBond`: the last-coupon swap has zero value at `x` + if and only if `x` satisfies the coupon-bond pricing equation with coupon `K·δ` and face `1`. +* `swapBootstrap_recovers_couponBondFactor`: for `1 + K·δ > 0`, if `x` solves that + coupon-bond equation and lies in `[lo, hi]`, bisection on the last-coupon swap lands within + `(hi − lo)/2^{n+1}` of `x`. +* `boot_length`, `boot_step_err`: `boot` returns `i` factors after `i` instruments, and at step + `i` its new factor is within `(hi i − lo i)/2^{n+1}` of the threshold root `σ`, given the + threshold shape of the solving function on the bracket and `σ` in the bracket. +* `boot_reprices_all`: for `b > 0` and a solving function affine `a − b·x` on the bracket + with root in the bracket, the repriced instrument `i` is within `b·(hi i − lo i)/2^{n+1}` + of its quote `c i`. +* `boot_reprices_fraChain`, `boot_reprices_swapChain`: the same repricing bound for the FRA strip + (`δ ≠ 0`, `1 + δ·K i > 0`, `lo i > 0`) and the swap strip (`1 + K i·δ > 0`), each given that the + root lies in the step's bracket. +* `fraBootstrap_flatCurve`: for `δ ≠ 0`, a fixed rate equal to the flat-curve forward rate and + a bracket with `lo > 0` containing the true later discount factor, bisection at zero quote + recovers it within `(hi − lo)/2^{n+1}`. + +## References + +* [P. S. Hagan and G. West, *Interpolation methods for curve construction*][HaganWest2006], §2 +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], ch. 4 and ch. 7 + +## Tags + +curve bootstrapping, bisection, discount factors, FRA, swap rate, yield curve construction, +par swap, MSC 91G30, MSC 91G60, JEL E43 +-/ + + +@[expose] public section + +namespace MathFin.Bootstrapping + +open Filter Topology + +/-! ### Threshold bridge: from instrument shape to the engine's hypothesis -/ + +/-- The threshold property is *global* for an affine function with positive +slope: `b·x − a` crosses the level `−c` exactly at the root `x = (a − c)/b`. -/ +theorem mul_sub_lt_neg_iff (a b c x : ℝ) (hb : 0 < b) : + b * x - a < -c ↔ x < (a - c) / b := by + rw [lt_div_iff₀ hb, mul_comm x b] + constructor <;> intro h <;> linarith + +/-- The slope-weighted residual: for `b > 0`, `|a − b·m − c| = b · |m − (a − c)/b|`. -/ +theorem abs_sub_mul_sub_eq_mul_abs (a b c m : ℝ) (hb : 0 < b) : + |a - b * m - c| = b * |m - (a - c) / b| := by + have : a - b * m - c = b * ((a - c) / b - m) := by field_simp; ring + rw [this, abs_mul, abs_of_pos hb, abs_sub_comm] + +/-! ### The affine bootstrap step -/ + +/-- **Bootstrap step, affine form.** For a value function whose increasing +rearrangement is `x ↦ b·x − a` (`b > 0`) and quote `c`, bisection from a bracket +containing the root `(a − c)/b` lands within `(hi − lo)/2^{n+1}` of it. -/ +theorem affineStep_err (a b c lo hi : ℝ) (hb : 0 < b) (hσ : (a - c) / b ∈ Set.Icc lo hi) + (n : ℕ) : + |bisectMid (fun x : ℝ ↦ b * x - a) (-c) lo hi n - (a - c) / b| + ≤ (hi - lo) / 2 ^ (n + 1) := + abs_bisectMid_sub_le (fun x _ ↦ mul_sub_lt_neg_iff a b c x hb) hσ n + +/-- Convergence form of the affine bootstrap step. -/ +theorem affineStep_tendsto (a b c lo hi : ℝ) (hb : 0 < b) (hσ : (a - c) / b ∈ Set.Icc lo hi) : + Tendsto (bisectMid (fun x : ℝ ↦ b * x - a) (-c) lo hi) atTop (𝓝 ((a - c) / b)) := + tendsto_bisectMid (fun x _ ↦ mul_sub_lt_neg_iff a b c x hb) hσ + +/-- **Repricing bound.** The instrument value `a − b·x` at the bisection +estimate is within `b·(hi − lo)/2^{n+1}` of the quote `c` — the slope-weighed +half-interval. -/ +theorem affineStep_value_err (a b c lo hi : ℝ) (hb : 0 < b) + (hσ : (a - c) / b ∈ Set.Icc lo hi) (n : ℕ) : + |a - b * bisectMid (fun x : ℝ ↦ b * x - a) (-c) lo hi n - c| + ≤ b * ((hi - lo) / 2 ^ (n + 1)) := by + rw [abs_sub_mul_sub_eq_mul_abs _ _ _ _ hb] + exact mul_le_mul_of_nonneg_left (affineStep_err a b c lo hi hb hσ n) hb.le + +/-- **Step budget.** Some number `n ≤ ⌈log₂ (b·(hi − lo)/ε)⌉` of bisection steps +achieves repricing accuracy `ε`. `Real.logb 2` is `log₂`; Mathlib states the log ladder over +`Real.logb`. -/ +theorem affineStep_stepBudget (a b c lo hi ε : ℝ) (hb : 0 < b) + (hσ : (a - c) / b ∈ Set.Icc lo hi) (hε : 0 < ε) : + ∃ n : ℕ, + |a - b * bisectMid (fun x : ℝ ↦ b * x - a) (-c) lo hi n - c| ≤ ε ∧ + n ≤ Nat.ceil (Real.logb 2 (b * (hi - lo) / ε)) := by + refine ⟨Nat.ceil (Real.logb 2 (b * (hi - lo) / ε)), ?_, le_rfl⟩ + have hlohi : lo ≤ hi := hσ.1.trans hσ.2 + have hT0 : 0 ≤ b * (hi - lo) / ε := + div_nonneg (mul_nonneg hb.le (sub_nonneg.mpr hlohi)) hε.le + have hTle : b * (hi - lo) / ε + ≤ 2 ^ (Nat.ceil (Real.logb 2 (b * (hi - lo) / ε)) + 1) := by + rcases eq_or_lt_of_le hT0 with h0 | h0 + · rw [← h0] + exact pow_nonneg (by norm_num) _ + · have h1 : Real.logb 2 (b * (hi - lo) / ε) + ≤ (Nat.ceil (Real.logb 2 (b * (hi - lo) / ε)) : ℕ) := Nat.le_ceil _ + have h2 : Real.logb 2 (b * (hi - lo) / ε) + ≤ Real.logb 2 (2 ^ (Nat.ceil (Real.logb 2 (b * (hi - lo) / ε)) + 1)) := by + rw [Real.logb_pow 2 2 _, Real.logb_self_eq_one (by norm_num), mul_one, + Nat.cast_add] + linarith + exact (Real.logb_le_logb (by norm_num) h0 (by positivity)).mp h2 + have hmain := (div_le_iff₀ hε).mp hTle + calc |a - b * bisectMid (fun x : ℝ ↦ b * x - a) (-c) lo hi + (Nat.ceil (Real.logb 2 (b * (hi - lo) / ε))) - c| + ≤ b * ((hi - lo) / 2 ^ (Nat.ceil (Real.logb 2 (b * (hi - lo) / ε)) + 1)) := + affineStep_value_err a b c lo hi hb hσ _ + _ = (b * (hi - lo)) / 2 ^ (Nat.ceil (Real.logb 2 (b * (hi - lo) / ε)) + 1) := + mul_div_assoc' b (hi - lo) _ + _ ≤ ε := by + rw [div_le_iff₀ (pow_pos (by norm_num : (0 : ℝ) < 2) _), + mul_comm ε (2 ^ (Nat.ceil (Real.logb 2 (b * (hi - lo) / ε)) + 1))] + exact hmain + +/-! ### Instruments I: the FRA (new unknown = the later discount factor) -/ + +section Fra + +/-- **The FRA as an affine function of its new unknown.** With the earlier +discount factor `p` fixed and the later one `x` bootstrapped, the FRA value at +fixed rate `K` is `p − (1 + δ·K)·x` — consuming +`fraValue_forwardRate_eq_discount_difference`. -/ +theorem fraValue_affine_of_newUnknown (p δ K x : ℝ) (hδ : δ ≠ 0) (hx : x ≠ 0) : + fraValue δ x (fraForwardRate p x δ) K = p - (1 + δ * K) * x := by + have h := fraValue_forwardRate_eq_discount_difference p x δ K hδ hx + rw [h] + ring + +/-- **The FRA root condition** — the `zero_iff` layer in the new unknown. +For a positive candidate factor, the FRA reprices the quote exactly at +`x = (p − c)/(1 + δ·K)`. With `fraRoot_agrees_with_pin` it recovers +`fraValue_zcb_eq_zero_iff` at `c = 0` on the flat `zcb` curve, for `K` with +`1 + δ·K > 0`. -/ +theorem fraValue_newUnknown_eq_quote_iff (p δ K c x : ℝ) (hδ : δ ≠ 0) (hx : 0 < x) + (hpos : 0 < 1 + δ * K) : + fraValue δ x (fraForwardRate p x δ) K = c ↔ x = (p - c) / (1 + δ * K) := by + rw [fraValue_affine_of_newUnknown p δ K x hδ hx.ne', eq_div_iff hpos.ne'] + constructor <;> intro h + · rw [mul_comm] + linarith + · rw [mul_comm x (1 + δ * K)] at h + linarith + +/-- Consistency: on the flat `zcb` curve the affine identity reproduces +`fraValue_zcb_eq_discount_difference` (right side equal by `ring`). -/ +theorem fraValue_affine_zcb (r δ K T1 T2 : ℝ) (hδ : δ ≠ 0) : + fraValue δ (zcb r 0 T2) (fraForwardRate (zcb r 0 T1) (zcb r 0 T2) δ) K + = zcb r 0 T1 - (1 + δ * K) * zcb r 0 T2 := + fraValue_affine_of_newUnknown _ δ K _ hδ (zcb_pos r 0 T2).ne' + +/-- **FRA monotonicity** (the licensing fact for bracketing): in the new +discount factor, on positive factors, the FRA value is strictly antitone — affine with slope +`−(1 + δ·K)`, covered when `1 + δ·K > 0`. -/ +theorem strictAntiOn_fraValue (p δ K : ℝ) (hδ : δ ≠ 0) (hpos : 0 < 1 + δ * K) : + StrictAntiOn (fun x : ℝ ↦ fraValue δ x (fraForwardRate p x δ) K) (Set.Ioi 0) := by + intro x hx y hy hxy + change fraValue δ y (fraForwardRate p y δ) K < fraValue δ x (fraForwardRate p x δ) K + rw [fraValue_affine_of_newUnknown p δ K x hδ (ne_of_gt hx), + fraValue_affine_of_newUnknown p δ K y hδ (ne_of_gt hy)] + linarith [mul_lt_mul_of_pos_right hxy hpos] + +/-- **FRA threshold**: on a bracket of positive discount factors, the negated +FRA value at level `−c` is an increasing solving function with threshold +`(p − c)/(1 + δ·K)` — the exact hypothesis the engine's error bound +consumes. -/ +theorem fraThreshold (p δ K c lo hi : ℝ) (hδ : δ ≠ 0) (hpos : 0 < 1 + δ * K) + (hlo : 0 < lo) (x : ℝ) (hx : x ∈ Set.Icc lo hi) : + -(fraValue δ x (fraForwardRate p x δ) K) < -c ↔ x < (p - c) / (1 + δ * K) := by + have hx0 : x ≠ 0 := (lt_of_lt_of_le hlo hx.1).ne' + rw [fraValue_affine_of_newUnknown p δ K x hδ hx0, neg_sub] + exact mul_sub_lt_neg_iff p (1 + δ * K) c x hpos + +/-- **FRA bootstrap step.** Bisection of the negated FRA value at the negated +quote computes the later discount factor to within `(hi − lo)/2^{n+1}`. -/ +theorem fraStep_err (p δ K c lo hi : ℝ) (hδ : δ ≠ 0) (hpos : 0 < 1 + δ * K) + (hlo : 0 < lo) (hσ : (p - c) / (1 + δ * K) ∈ Set.Icc lo hi) (n : ℕ) : + |bisectMid (fun x : ℝ ↦ -(fraValue δ x (fraForwardRate p x δ) K)) (-c) lo hi n + - (p - c) / (1 + δ * K)| ≤ (hi - lo) / 2 ^ (n + 1) := + abs_bisectMid_sub_le (fraThreshold p δ K c lo hi hδ hpos hlo) hσ n + +/-- Convergence form of the FRA bootstrap step. -/ +theorem fraStep_tendsto (p δ K c lo hi : ℝ) (hδ : δ ≠ 0) (hpos : 0 < 1 + δ * K) + (hlo : 0 < lo) (hσ : (p - c) / (1 + δ * K) ∈ Set.Icc lo hi) : + Tendsto (bisectMid (fun x : ℝ ↦ -(fraValue δ x (fraForwardRate p x δ) K)) (-c) lo hi) + atTop (𝓝 ((p - c) / (1 + δ * K))) := + tendsto_bisectMid (fraThreshold p δ K c lo hi hδ hpos hlo) hσ + +/-- At the zero quote the FRA root makes the forward rate par: at the bootstrapped +factor `p/(1 + δ·K)` the simple forward rate equals the quoted fixed rate (one +direction; the equivalence on the flat curve is `fraRoot_agrees_with_pin`). -/ +theorem fraRoot_parForward (p δ K : ℝ) (hδ : δ ≠ 0) (hp : p ≠ 0) : + fraForwardRate p (p / (1 + δ * K)) δ = K := by + unfold fraForwardRate + field_simp + ring + +/-- The bridge to `fraValue_zcb_eq_zero_iff`: on the flat `zcb` curve the +bootstrap root `p/(1 + δ·K)` and the par-forward characterization +(`fraValue_zcb_eq_zero_iff`'s right side, `K = fraForwardRate p x δ`) describe +the same factor. -/ +theorem fraRoot_agrees_with_pin (r δ K T1 T2 : ℝ) (hδ : δ ≠ 0) : + zcb r 0 T2 = zcb r 0 T1 / (1 + δ * K) ↔ + K = fraForwardRate (zcb r 0 T1) (zcb r 0 T2) δ := by + have hp : zcb r 0 T1 ≠ 0 := (zcb_pos r 0 T1).ne' + have hx : zcb r 0 T2 ≠ 0 := (zcb_pos r 0 T2).ne' + unfold fraForwardRate + constructor <;> intro h + · rw [h] + field_simp + ring + · rw [h] + have h1 : (1 : ℝ) + δ * ((zcb r 0 T1 / zcb r 0 T2 - 1) / δ) + = zcb r 0 T1 / zcb r 0 T2 := by + field_simp + ring + rw [h1] + field_simp + +end Fra + +/-! ### Instruments II: the payer swap -/ + +section Swap + +/-- **Swap, fixed schedule known.** With the annuity `A` already bootstrapped +(every fixed payment sits at a maturity before the new one), the payer swap +value in the new factor `x` is `(P0 − K·A) − x`: affine with slope `−1`, hence +strictly decreasing with **no** positivity condition (`strictAnti_payerSwapValue`). -/ +theorem payerSwapValue_affine_of_newUnknown (P0 K A x : ℝ) : + payerSwapValue P0 x K A = (P0 - K * A) - 1 * x := by + change P0 - x - K * A = (P0 - K * A) - 1 * x + ring + +/-- Swap monotonicity, known schedule: strictly antitone on all of `ℝ`. -/ +theorem strictAnti_payerSwapValue (P0 K A : ℝ) : + StrictAnti (fun x : ℝ ↦ payerSwapValue P0 x K A) := by + intro x y hxy + change payerSwapValue P0 y K A < payerSwapValue P0 x K A + change P0 - y - K * A < P0 - x - K * A + linarith + +/-- **Swap threshold**, known schedule: the negated value at level `−c` has +threshold `P0 − K·A − c`. -/ +theorem swapThreshold (P0 K A c lo hi : ℝ) (x : ℝ) (_hx : x ∈ Set.Icc lo hi) : + -(payerSwapValue P0 x K A) < -c ↔ x < P0 - K * A - c := by + have h : payerSwapValue P0 x K A = P0 - K * A - x := by + change P0 - x - K * A = P0 - K * A - x + ring + rw [h, neg_sub] + simpa only [one_mul, div_one] using mul_sub_lt_neg_iff (P0 - K * A) 1 c x one_pos + +/-- **Swap bootstrap step**, known schedule: bisection of the negated value at +the negated quote computes the new discount factor to within +`(hi − lo)/2^{n+1}`. -/ +theorem swapStep_err (P0 K A c lo hi : ℝ) (hσ : P0 - K * A - c ∈ Set.Icc lo hi) (n : ℕ) : + |bisectMid (fun x : ℝ ↦ -(payerSwapValue P0 x K A)) (-c) lo hi n - (P0 - K * A - c)| + ≤ (hi - lo) / 2 ^ (n + 1) := + abs_bisectMid_sub_le (swapThreshold P0 K A c lo hi) hσ n + +/-- Convergence form of the swap bootstrap step. -/ +theorem swapStep_tendsto (P0 K A c lo hi : ℝ) (hσ : P0 - K * A - c ∈ Set.Icc lo hi) : + Tendsto (bisectMid (fun x : ℝ ↦ -(payerSwapValue P0 x K A)) (-c) lo hi) + atTop (𝓝 (P0 - K * A - c)) := + tendsto_bisectMid (swapThreshold P0 K A c lo hi) hσ + +/-- The par-rate interpretation of the swap root: at quote zero the fixed rate is par +at the bootstrapped factor `P0 − K·A` — consuming `payerSwapValue_eq_zero_iff`. -/ +theorem swapRoot_is_par (P0 K A : ℝ) (hA : A ≠ 0) : parSwapRate P0 (P0 - K * A) A = K := by + have h0 : payerSwapValue P0 (P0 - K * A) K A = 0 := by + change P0 - (P0 - K * A) - K * A = 0 + ring + exact ((payerSwapValue_eq_zero_iff P0 (P0 - K * A) K hA).mp h0).symm + +/-- **Swap with one payment at the new maturity.** The fixed leg's annuity is +`A₀ + δ·x` (`A₀ = annuity δ P s` over the already-bootstrapped schedule, plus +one accrual at the new factor): value `(P0 − K·A₀) − (1 + K·δ)·x` — affine, +covered when `1 + K·δ > 0`. -/ +theorem payerSwapValue_affine_lastCoupon (P0 K A₀ δ x : ℝ) : + payerSwapValue P0 x K (A₀ + δ * x) = (P0 - K * A₀) - (1 + K * δ) * x := by + change P0 - x - K * (A₀ + δ * x) = (P0 - K * A₀) - (1 + K * δ) * x + ring + +/-- Same, with the annuity in the `annuity δ P s` form. -/ +theorem payerSwapValue_affine_lastCoupon_annuity {ι : Type*} (P0 K δ x : ℝ) (P : ι → ℝ) + (s : Finset ι) : + payerSwapValue P0 x K (annuity δ P s + δ * x) + = (P0 - K * annuity δ P s) - (1 + K * δ) * x := + payerSwapValue_affine_lastCoupon P0 K (annuity δ P s) δ x + +/-- Monotonicity of the last-coupon swap: strictly antitone on all of `ℝ` under +the slope condition `1 + K·δ > 0`. -/ +theorem strictAnti_payerSwapValue_lastCoupon (P0 K A₀ δ : ℝ) (hpos : 0 < 1 + K * δ) : + StrictAnti (fun x : ℝ ↦ payerSwapValue P0 x K (A₀ + δ * x)) := by + intro x y hxy + change payerSwapValue P0 y K (A₀ + δ * y) < payerSwapValue P0 x K (A₀ + δ * x) + rw [payerSwapValue_affine_lastCoupon, payerSwapValue_affine_lastCoupon] + linarith [mul_lt_mul_of_pos_right hxy hpos] + +/-- Threshold of the last-coupon swap. -/ +theorem swapLastCouponThreshold (P0 K A₀ δ c lo hi : ℝ) (hpos : 0 < 1 + K * δ) (x : ℝ) + (_hx : x ∈ Set.Icc lo hi) : + -(payerSwapValue P0 x K (A₀ + δ * x)) < -c ↔ x < (P0 - K * A₀ - c) / (1 + K * δ) := by + rw [payerSwapValue_affine_lastCoupon, neg_sub] + exact mul_sub_lt_neg_iff _ _ _ x hpos + +/-- Bootstrap step for the last-coupon swap. -/ +theorem swapStep_lastCoupon_err (P0 K A₀ δ c lo hi : ℝ) (hpos : 0 < 1 + K * δ) + (hσ : (P0 - K * A₀ - c) / (1 + K * δ) ∈ Set.Icc lo hi) (n : ℕ) : + |bisectMid (fun x : ℝ ↦ -(payerSwapValue P0 x K (A₀ + δ * x))) (-c) lo hi n + - (P0 - K * A₀ - c) / (1 + K * δ)| ≤ (hi - lo) / 2 ^ (n + 1) := + abs_bisectMid_sub_le (swapLastCouponThreshold P0 K A₀ δ c lo hi hpos) hσ n + +/-- The coupons `K·δ` paid on the schedule `s`, discounted by `P`, are `K` times the annuity. -/ +private theorem sum_const_mul_eq_annuity {ι : Type*} (s : Finset ι) (P : ι → ℝ) (K δ : ℝ) : + ∑ i ∈ s, K * δ * P i = K * annuity δ P s := by + simp only [annuity, Finset.mul_sum, mul_assoc] + +/-- **A zero-value swap is a par coupon bond.** The last-coupon payer swap (floating leg +`P0 − x`, one fixed payment of `K·δ` at each date of `s` and at the new factor `x`) has +zero value exactly when the coupon bond paying `K·δ` at every date and face `1` at the last +prices at `P0`: the pricing equation `couponBondPricingEq` of `Models/Rates/YieldCurve.lean` +with coupon `K·δ` and face `1`. -/ +theorem payerSwapValue_lastCoupon_eq_zero_iff_couponBond {ι : Type*} (s : Finset ι) + (P : ι → ℝ) (P0 K δ x : ℝ) : + payerSwapValue P0 x K (annuity δ P s + δ * x) = 0 ↔ + couponBondPricingEq s (fun _ ↦ K * δ) P P0 (K * δ) 1 x := by + simp only [payerSwapValue, couponBondPricingEq, sum_const_mul_eq_annuity] + constructor <;> intro h <;> linear_combination h + +/-- **Swap bootstrapping recovers the coupon-bond discount factor.** If the new factor `x` +solves the par-coupon-bond pricing equation — coupon `K·δ` at every date of `s` and at the new +one, face `1`, price `P0` — then bisection on the zero-quote last-coupon swap, from any bracket +`[lo, hi]` containing `x`, lands within `(hi − lo)/2^{n+1}` of it (`1 + K·δ > 0`). The +closed-form bootstrap `bootstrap_solve` identifies `x` with the swap's bisection root +`(P0 − K·A₀)/(1 + K·δ)`. -/ +theorem swapBootstrap_recovers_couponBondFactor {ι : Type*} (s : Finset ι) (P : ι → ℝ) + (P0 K δ x lo hi : ℝ) (hpos : 0 < 1 + K * δ) + (hbond : couponBondPricingEq s (fun _ ↦ K * δ) P P0 (K * δ) 1 x) + (hx : x ∈ Set.Icc lo hi) (n : ℕ) : + |bisectMid (fun y : ℝ ↦ -(payerSwapValue P0 y K (annuity δ P s + δ * y))) 0 lo hi n - x| + ≤ (hi - lo) / 2 ^ (n + 1) := by + have hroot : x = (P0 - K * annuity δ P s - 0) / (1 + K * δ) := by + have h := bootstrap_solve s (fun _ ↦ K * δ) P P0 (K * δ) 1 x + (show (0 : ℝ) < K * δ + 1 by linarith).ne' hbond + simp only [sum_const_mul_eq_annuity] at h + rwa [sub_zero, add_comm 1 (K * δ)] + have h := swapStep_lastCoupon_err P0 K (annuity δ P s) δ 0 lo hi hpos + (by rw [← hroot]; exact hx) n + rwa [neg_zero, ← hroot] at h + +end Swap + +/-! ### The induction: the bootstrapped curve + +`boot` builds the discount curve by structural recursion over the instrument +index: step `i` bisects instrument `i`'s increasing rearrangement +`x ↦ −V i (x :: prefix)` at level `−c i` on the prefix bootstrapped so far — +each step literally inherits the previous factors. The step theorems below +state their hypotheses at exactly this fed-in prefix (`boot V c lo hi n i`), +not at every prefix list whatever: each step assumes only what it consumes. +The parameter `n` is the bisection step count used at *every* instrument +(uniform budget; a per-instrument budget `n : ℕ → ℕ` would need `boot` to +use `n i` at step `i` — not formalized). -/ + +/-- The **bootstrapped curve**: after the first `i` instruments, a list of +discount factors, the head being the newest. -/ +noncomputable def boot (V : ℕ → List ℝ → ℝ) (c lo hi : ℕ → ℝ) (n : ℕ) : ℕ → List ℝ + | 0 => [] + | i + 1 => + bisectMid (fun x : ℝ ↦ -(V i (x :: boot V c lo hi n i))) (-(c i)) (lo i) (hi i) n + :: boot V c lo hi n i + +/-- Length: after `i` instruments the curve holds `i` factors. -/ +theorem boot_length (V : ℕ → List ℝ → ℝ) (c lo hi : ℕ → ℝ) (n i : ℕ) : + (boot V c lo hi n i).length = i := by + induction i with + | zero => simp [boot] + | succ i ih => simp only [boot, List.length_cons, ih] + +/-- Definitional unfolding of the recursive step (the `i + 1` equation). -/ +private theorem boot_succ (V : ℕ → List ℝ → ℝ) (c lo hi : ℕ → ℝ) (n i : ℕ) : + boot V c lo hi n (i + 1) + = bisectMid (fun x : ℝ ↦ -(V i (x :: boot V c lo hi n i))) (-(c i)) (lo i) (hi i) n + :: boot V c lo hi n i := rfl + +/-- Every non-initial curve is nonempty, so its head is the newest factor. -/ +theorem boot_succ_ne_nil (V : ℕ → List ℝ → ℝ) (c lo hi : ℕ → ℝ) (n i : ℕ) : + boot V c lo hi n (i + 1) ≠ [] := by + rw [boot_succ] + exact List.cons_ne_nil _ _ + +/-- **The bootstrap step theorem, at the fed-in prefix.** For every instrument +`i`, the `i`-th bootstrapped factor (with `n` bisection steps per instrument) +is within `(hi i − lo i)/2^{n+1}` of that instrument's threshold `σ i p`, +where `p` is the prefix the recursion actually feeds step `i` — the factors +the earlier steps produced (`boot V c lo hi n i`), not an arbitrary list. The +threshold hypothesis and the root-in-bracket condition are assumed exactly +there: each step consumes only its own instrument's shape, on its own +bracket, at the factors the run produced. The prefix itself depends on `n`, +so the hypotheses are per-`n`: if they hold for every `n`, the gap to the +prefix-dependent threshold tends to `0` (not stated as a theorem); +convergence of the factors themselves is not stated either (it would follow +by induction on `i` when, in addition, each `σ i` is continuous in the +prefix). -/ +theorem boot_step_err (V : ℕ → List ℝ → ℝ) (c lo hi : ℕ → ℝ) (σ : ℕ → List ℝ → ℝ) + (i n : ℕ) + (hthr : ∀ x ∈ Set.Icc (lo i) (hi i), + -(V i (x :: boot V c lo hi n i)) < -(c i) ↔ x < σ i (boot V c lo hi n i)) + (hσ : σ i (boot V c lo hi n i) ∈ Set.Icc (lo i) (hi i)) : + |(boot V c lo hi n (i + 1)).head (boot_succ_ne_nil V c lo hi n i) + - σ i (boot V c lo hi n i)| ≤ (hi i - lo i) / 2 ^ (n + 1) := + abs_bisectMid_sub_le hthr hσ n + +/-- **The bootstrap repricing theorem, at the fed-in prefix.** Given +instrument `i`'s affine shape `V i (x :: p) = a i p − b i p · x` on the step's +own bracket (bisection evaluates the instrument only there), slope +`b i p > 0`, and the root `(a i p − c i)/b i p` in the bracket — all at the +prefix `p` the recursion feeds step `i` — the bootstrapped factor reprices +instrument `i`'s quote up to the slope-weighted half-interval +`b i p · (hi i − lo i)/2^{n+1}`. The shape and slope are exactly the facts the +instrument layers of this file provide at whatever prefix is fed in (FRA: +`fraValue_affine_of_newUnknown` + `fraThreshold`; known-schedule swap: +`payerSwapValue_affine_of_newUnknown` + `swapThreshold`; last-coupon swap: +`payerSwapValue_affine_lastCoupon` + `swapLastCouponThreshold`), so the only +run-dependent input left is the per-step bracket choice; +`boot_reprices_fraChain` / `boot_reprices_swapChain` discharge every +hypothesis but it for the FRA and swap strips, under the FRA / swap standing +conditions. -/ +theorem boot_reprices_all (V : ℕ → List ℝ → ℝ) (c lo hi : ℕ → ℝ) (a b : ℕ → List ℝ → ℝ) + (i n : ℕ) (hb : 0 < b i (boot V c lo hi n i)) + (hV : ∀ x ∈ Set.Icc (lo i) (hi i), + V i (x :: boot V c lo hi n i) + = a i (boot V c lo hi n i) - b i (boot V c lo hi n i) * x) + (hσ : (a i (boot V c lo hi n i) - c i) / b i (boot V c lo hi n i) + ∈ Set.Icc (lo i) (hi i)) : + |V i ((boot V c lo hi n (i + 1)).head (boot_succ_ne_nil V c lo hi n i) + :: boot V c lo hi n i) - c i| + ≤ b i (boot V c lo hi n i) * ((hi i - lo i) / 2 ^ (n + 1)) := by + simp only [boot_succ, List.head_cons] + set p := boot V c lo hi n i + have hthr : ∀ x ∈ Set.Icc (lo i) (hi i), + -(V i (x :: p)) < -(c i) ↔ x < (a i p - c i) / b i p := by + intro x hx + rw [hV x hx, neg_sub] + exact mul_sub_lt_neg_iff (a i p) (b i p) (c i) x hb + have hstep : |bisectMid (fun x : ℝ ↦ -(V i (x :: p))) (-(c i)) (lo i) (hi i) n + - (a i p - c i) / b i p| ≤ (hi i - lo i) / 2 ^ (n + 1) := + abs_bisectMid_sub_le hthr hσ n + rw [hV _ (bisectMid_mem_Icc hthr hσ n), abs_sub_mul_sub_eq_mul_abs _ _ _ _ hb] + exact mul_le_mul_of_nonneg_left hstep hb.le + +/-! #### The file's instruments inside the induction + +`fraChain` and `swapChain` are the instrument layers in `boot`'s list form: +the new factor `x` at the head of the fed-in list, the already-bootstrapped +factors behind it. Both are anchored at every step, including the first: the +discount factor at the valuation date is `1`, so step `0` of the FRA strip is +the spot deposit (an FRA whose earlier factor is `1`), and every swap step is a +spot-starting swap (`P0 = 1`). Each instrument `i` carries its own fixed rate +`K i`. They discharge every hypothesis of `boot_reprices_all` except the +bracket condition, which stays a hypothesis; what they add is only the +instrument layer's standing assumptions. -/ + +/-- The **FRA strip as a `boot` instrument**: instrument `i` is the FRA with +fixed rate `K i`, reading the new factor `x` and the previous factor off the +fed-in list; on the empty prefix (step `0`) the previous factor is the +valuation-date factor `1`, so the first instrument is the spot deposit. (The +`[]` branch is never fed by `boot`, which always passes `x :: prefix`.) -/ +noncomputable def fraChain (δ : ℝ) (K : ℕ → ℝ) : ℕ → List ℝ → ℝ := + fun i l ↦ + match l with + | x :: p => fraValue δ x (fraForwardRate (p.head?.getD 1) x δ) (K i) + | [] => 0 + +/-- The unfolding equation: on `x :: p` the strip instrument is the FRA value +function of the instrument layer, the earlier factor read off the head of `p` +(defaulting to the valuation-date factor `1` when `p` is empty, so on `[x]` it is +the spot deposit) — matching `swapChain_cons`'s general shape on the fed-in list. -/ +@[simp] +theorem fraChain_cons (δ : ℝ) (K : ℕ → ℝ) (x : ℝ) (p : List ℝ) (i : ℕ) : + fraChain δ K i (x :: p) = fraValue δ x (fraForwardRate (p.head?.getD 1) x δ) (K i) := rfl + +/-- **The FRA strip reprices inside the induction.** At every step `i` +(step `0` is the spot deposit, anchored at the valuation-date factor `1`), +under the FRA layer's standing conditions — `δ ≠ 0`, `1 + δ·K i > 0`, a +positive bracket — the only hypothesis left is the bracket condition at the +fed-in prefix: `[lo i, hi i]` must contain the root computed from the *actual* +previous factor `((boot (fraChain δ K) c lo hi n i).head?.getD 1 − c i) / +(1 + δ·K i)`. Then the bootstrapped factor reprices instrument `i`'s quote to +within `(1 + δ·K i)·(hi i − lo i)/2^{n+1}`. -/ +theorem boot_reprices_fraChain (δ : ℝ) (K c lo hi : ℕ → ℝ) (n i : ℕ) (hδ : δ ≠ 0) + (hpos : 0 < 1 + δ * K i) (hlo : 0 < lo i) + (hσ : ((boot (fraChain δ K) c lo hi n i).head?.getD 1 - c i) / (1 + δ * K i) + ∈ Set.Icc (lo i) (hi i)) : + |fraChain δ K i ((boot (fraChain δ K) c lo hi n (i + 1)).head + (boot_succ_ne_nil (fraChain δ K) c lo hi n i) + :: boot (fraChain δ K) c lo hi n i) - c i| + ≤ (1 + δ * K i) * ((hi i - lo i) / 2 ^ (n + 1)) := + boot_reprices_all (fraChain δ K) c lo hi (fun _ p ↦ p.head?.getD 1) + (fun j _ ↦ 1 + δ * K j) i n hpos + (fun x hx ↦ fraValue_affine_of_newUnknown _ δ (K i) x hδ (lt_of_lt_of_le hlo hx.1).ne') hσ + +/-- The **swap strip as a `boot` instrument**: instrument `i` is the +spot-starting payer swap (`P0 = 1`) maturing at the new factor `x`, with fixed +rate `K i` and one fixed payment (accrual `δ`) at each bootstrapped date and at +the new one — annuity `δ·(Σ prefix) + δ·x`, the last-coupon form of the swap +layer. Every step, including the first (empty prefix: the one-period swap), is +a genuine swap; the `[]` branch is never fed by `boot`. -/ +noncomputable def swapChain (δ : ℝ) (K : ℕ → ℝ) : ℕ → List ℝ → ℝ := + fun i l ↦ + match l with + | x :: p => payerSwapValue 1 x (K i) (δ * p.sum + δ * x) + | [] => 0 + +/-- The unfolding equation of the swap strip instrument. -/ +@[simp] +theorem swapChain_cons (δ : ℝ) (K : ℕ → ℝ) (x : ℝ) (p : List ℝ) (i : ℕ) : + swapChain δ K i (x :: p) = payerSwapValue 1 x (K i) (δ * p.sum + δ * x) := rfl + +/-- **The swap strip reprices inside the induction.** At every step `i`, under +the last-coupon slope condition `1 + K i·δ > 0` (no bracket positivity is +needed: the swap value is affine on all of `ℝ`), the only hypothesis left is +the bracket condition at the fed-in prefix: `[lo i, hi i]` must contain the +root `(1 − K i·δ·Σ prefix − c i)/(1 + K i·δ)` computed from the factors the run +actually produced. Then the bootstrapped factor reprices swap `i`'s quote +(`c i = 0` for a par-rate quote `K i`) to within +`(1 + K i·δ)·(hi i − lo i)/2^{n+1}`. -/ +theorem boot_reprices_swapChain (δ : ℝ) (K c lo hi : ℕ → ℝ) (n i : ℕ) + (hpos : 0 < 1 + K i * δ) + (hσ : (1 - K i * (δ * (boot (swapChain δ K) c lo hi n i).sum) - c i) / (1 + K i * δ) + ∈ Set.Icc (lo i) (hi i)) : + |swapChain δ K i ((boot (swapChain δ K) c lo hi n (i + 1)).head + (boot_succ_ne_nil (swapChain δ K) c lo hi n i) + :: boot (swapChain δ K) c lo hi n i) - c i| + ≤ (1 + K i * δ) * ((hi i - lo i) / 2 ^ (n + 1)) := + boot_reprices_all (swapChain δ K) c lo hi (fun j p ↦ 1 - K j * (δ * p.sum)) + (fun j _ ↦ 1 + K j * δ) i n hpos + (fun x _ ↦ payerSwapValue_affine_lastCoupon 1 (K i) _ δ x) hσ + +/-! ### Flat-curve capstone: the bootstrap recovers the flat-curve factor -/ + +/-- **Flat-curve capstone.** If the fixed rate equals the flat-curve forward +rate, the FRA's true later discount factor on the `zcb` curve *is* the root of +the solving function at zero quote (an algebraic identity), and bisection at zero quote +from any positive bracket around it recovers the factor to within `(hi − lo)/2^{n+1}`. -/ +theorem fraBootstrap_flatCurve (r δ K T1 T2 lo hi : ℝ) (hδ : δ ≠ 0) + (hK : K = fraForwardRate (zcb r 0 T1) (zcb r 0 T2) δ) + (hx : zcb r 0 T2 ∈ Set.Icc lo hi) (hlo : 0 < lo) (n : ℕ) : + |bisectMid (fun x : ℝ ↦ -(fraValue δ x (fraForwardRate (zcb r 0 T1) x δ) K)) 0 lo hi n + - zcb r 0 T2| ≤ (hi - lo) / 2 ^ (n + 1) := by + have h1 : δ * ((zcb r 0 T1 / zcb r 0 T2 - 1) / δ) + = zcb r 0 T1 / zcb r 0 T2 - 1 := by field_simp + have hpos : 0 < 1 + δ * K := by + simp only [hK, fraForwardRate, h1] + linarith [div_pos (zcb_pos r 0 T1) (zcb_pos r 0 T2)] + have hσeq : (zcb r 0 T1 - 0) / (1 + δ * K) = zcb r 0 T2 := by + rw [hK, sub_zero] + have hp : zcb r 0 T1 ≠ 0 := (zcb_pos r 0 T1).ne' + have hx : zcb r 0 T2 ≠ 0 := (zcb_pos r 0 T2).ne' + unfold fraForwardRate + rw [show (1 : ℝ) + δ * ((zcb r 0 T1 / zcb r 0 T2 - 1) / δ) + = zcb r 0 T1 / zcb r 0 T2 from by rw [h1]; ring, + div_eq_iff (div_ne_zero hp hx)] + field_simp + have hthr : ∀ x ∈ Set.Icc lo hi, + (fun x : ℝ ↦ -(fraValue δ x (fraForwardRate (zcb r 0 T1) x δ) K)) x < 0 + ↔ x < zcb r 0 T2 := by + intro x hx + have hthr' := fraThreshold (zcb r 0 T1) δ K 0 lo hi hδ hpos hlo x hx + simpa only [sub_zero, div_eq_div_iff, neg_zero, one_mul] using + hthr'.trans (by rw [hσeq]) + exact abs_bisectMid_sub_le hthr hx n + +end MathFin.Bootstrapping diff --git a/LeanPool/MathFin/Models/Rates/CIRRiccati.lean b/LeanPool/MathFin/Models/Rates/CIRRiccati.lean new file mode 100644 index 0000000000..756a39c1fc --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/CIRRiccati.lean @@ -0,0 +1,163 @@ +/- +Copyright (c) 2026 Alfredo Garcia. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Alfredo Garcia +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.Analysis.InnerProductSpace.Basic +public import Mathlib.Analysis.SpecialFunctions.Log.Deriv +public import Mathlib.Topology.Algebra.Module.ModuleTopology + +/-! +# The CIR loadings solve their term-structure equations + +The Cox–Ingersoll–Ross bond price has the affine form `P(0, T) = exp(A(T) − B(T) · r₀)`, so the +`A` here is the logarithm of the multiplicative factor that `vasicekBondA` and Brigo–Mercurio call +`A`. With `γ = √(κ² + 2σ²)` and `D(T) = (γ + κ)(e^{γT} − 1) + 2γ`, the closed form +`B(T) = 2(e^{γT} − 1) / D(T)` solves `B' = 1 − κB − ½σ²B²` with `B(0) = 0`. + +After differentiating the quotient, the equation is the identity +`D² − 2κ(e^{γT} − 1) D − 2σ²(e^{γT} − 1)² = 4γ² e^{γT}`, which holds because +`γ² = κ² + 2σ²`. The hypothesis `κ² + 2σ² > 0` is the weakest that keeps `γ > 0`; at +`κ = σ = 0` the denominator is identically zero. Since `|κ| ≤ γ`, `D(T) > 0` for every +real `T`, so no `T ≥ 0` hypothesis is needed. + +The level loading `A(T) = (2κθ/σ²) · log(2γ e^{(κ+γ)T/2} / D(T))` solves `A' = −κθB` with +`A(0) = 0`, for `σ ≠ 0`. Its equation reduces to +`(κ + γ) D / 2 − (γ + κ) γ e^{γT} = −σ² (e^{γT} − 1)`, again because `γ² = κ² + 2σ²`. + +Only these equations are proved. The bond price `𝔼[exp(−∫₀ᵀ r_s ds)]` needs the affine +(Feynman–Kac) framework, which is not formalized. + +## Main definitions + +* `cirGamma`: `γ = √(κ² + 2σ²)`. +* `cirDenom`: `D(T) = (γ + κ)(e^{γT} − 1) + 2γ`. +* `cirBondB`: the CIR rate loading `B(T) = 2(e^{γT} − 1) / D(T)`. +* `cirBondA`: the CIR level loading in log form, + `A(T) = (2κθ/σ²) · log(2γ e^{(κ+γ)T/2} / D(T))`. + +## Main results + +* `cirBondB_zero`: `B(0) = 0`. +* `hasDerivAt_cirBondB`: `B' = 1 − κB − ½σ²B²` at every `T`, for `κ² + 2σ² > 0`. +* `cirBondA_zero`: `A(0) = 0`. +* `hasDerivAt_cirBondA`: `A' = −κθB` at every `T`, for `σ ≠ 0`. + +## References + +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + §3.2.3 +* [J. C. Cox, J. E. Ingersoll and S. A. Ross, *A theory of the term structure of interest + rates*][CoxIngersollRoss1985] + +## Tags + +Cox–Ingersoll–Ross, CIR model, Riccati equation, affine bond price, square-root diffusion, +short rate, MSC 91G30, MSC 60J60, JEL E43 +-/ + +@[expose] public section + +namespace MathFin + +/-- `γ = √(κ² + 2σ²)`. -/ +noncomputable def cirGamma (κ σ : ℝ) : ℝ := Real.sqrt (κ ^ 2 + 2 * σ ^ 2) + +lemma cirGamma_sq (κ σ : ℝ) : cirGamma κ σ ^ 2 = κ ^ 2 + 2 * σ ^ 2 := + Real.sq_sqrt (by positivity) + +lemma cirGamma_pos {κ σ : ℝ} (h : 0 < κ ^ 2 + 2 * σ ^ 2) : 0 < cirGamma κ σ := + Real.sqrt_pos.mpr h + +/-- `D(T) = (γ + κ)(e^{γT} − 1) + 2γ`. -/ +noncomputable def cirDenom (κ σ T : ℝ) : ℝ := + (cirGamma κ σ + κ) * (Real.exp (cirGamma κ σ * T) - 1) + 2 * cirGamma κ σ + +/-- The CIR rate loading `B(T) = 2(e^{γT} − 1) / D(T)`. -/ +noncomputable def cirBondB (κ σ T : ℝ) : ℝ := + 2 * (Real.exp (cirGamma κ σ * T) - 1) / cirDenom κ σ T + +/-- `D(T) > 0` at every `T`, since `|κ| ≤ γ`. -/ +lemma cirDenom_pos {κ σ : ℝ} (h : 0 < κ ^ 2 + 2 * σ ^ 2) (T : ℝ) : 0 < cirDenom κ σ T := by + have hγ := cirGamma_pos h + have hκ : |κ| ≤ cirGamma κ σ := Real.abs_le_sqrt (by nlinarith [sq_nonneg σ]) + have hE := Real.exp_pos (cirGamma κ σ * T) + unfold cirDenom + nlinarith [le_abs_self κ, neg_abs_le κ, + mul_nonneg (by linarith [neg_abs_le κ] : 0 ≤ cirGamma κ σ + κ) hE.le] + +private lemma hasDerivAt_exp_cirGamma (κ σ T : ℝ) : + HasDerivAt (fun t ↦ Real.exp (cirGamma κ σ * t)) + (Real.exp (cirGamma κ σ * T) * cirGamma κ σ) T := by + simpa using ((hasDerivAt_id T).const_mul (cirGamma κ σ)).exp + +/-- `D'(T) = (γ + κ) γ e^{γT}`. -/ +lemma hasDerivAt_cirDenom (κ σ T : ℝ) : + HasDerivAt (cirDenom κ σ) + ((cirGamma κ σ + κ) * (Real.exp (cirGamma κ σ * T) * cirGamma κ σ)) T := + (((hasDerivAt_exp_cirGamma κ σ T).sub_const 1).const_mul (cirGamma κ σ + κ)).add_const + (2 * cirGamma κ σ) + +lemma cirBondB_zero (κ σ : ℝ) : cirBondB κ σ 0 = 0 := by + simp [cirBondB] + +/-- **The CIR rate loading solves the Riccati equation** `B' = 1 − κB − ½σ²B²`. The proof +reduces it to `D² − 2κ(e^{γT} − 1) D − 2σ²(e^{γT} − 1)² = 4γ² e^{γT}`, using `γ² = κ² + 2σ²`. -/ +theorem hasDerivAt_cirBondB {κ σ : ℝ} (h : 0 < κ ^ 2 + 2 * σ ^ 2) (T : ℝ) : + HasDerivAt (cirBondB κ σ) + (1 - κ * cirBondB κ σ T - σ ^ 2 / 2 * cirBondB κ σ T ^ 2) T := by + have hγ := cirGamma_sq κ σ + have hD := (cirDenom_pos h T).ne' + have hB := (((hasDerivAt_exp_cirGamma κ σ T).sub_const 1).const_mul 2).div + (hasDerivAt_cirDenom κ σ T) hD + have hfun : cirBondB κ σ = + (fun t ↦ 2 * (Real.exp (cirGamma κ σ * t) - 1)) / fun t ↦ cirDenom κ σ t := rfl + rw [hfun] + refine hB.congr_deriv ?_ + simp only [Pi.div_apply] + unfold cirDenom at * + field_simp + linear_combination -(Real.exp (cirGamma κ σ * T) - 1) ^ 2 * hγ + +/-- The CIR level loading in log form, `A(T) = (2κθ/σ²) · log(2γ e^{(κ+γ)T/2} / D(T))`: the +constant term of the exponent in `P = exp(A − B · r₀)`, so `A(0) = 0`. -/ +noncomputable def cirBondA (κ θ σ T : ℝ) : ℝ := + 2 * κ * θ / σ ^ 2 * + Real.log (2 * cirGamma κ σ * Real.exp ((κ + cirGamma κ σ) * T / 2) / cirDenom κ σ T) + +lemma cirBondA_zero (κ θ σ : ℝ) : cirBondA κ θ σ 0 = 0 := by + by_cases hγ : cirGamma κ σ = 0 <;> simp [cirBondA, cirDenom, hγ] + +/-- **The CIR level loading solves `A' = −κθB`.** The proof reduces it to +`(κ + γ) D / 2 − (γ + κ) γ e^{γT} = −σ² (e^{γT} − 1)`, using `γ² = κ² + 2σ²`. -/ +theorem hasDerivAt_cirBondA (κ θ : ℝ) {σ : ℝ} (hσ : σ ≠ 0) (T : ℝ) : + HasDerivAt (cirBondA κ θ σ) (-(κ * θ) * cirBondB κ σ T) T := by + have h : 0 < κ ^ 2 + 2 * σ ^ 2 := by positivity + have hγ := cirGamma_sq κ σ + have hγpos := cirGamma_pos h + have hD := cirDenom_pos h T + have hF : HasDerivAt (fun t ↦ 2 * cirGamma κ σ * Real.exp ((κ + cirGamma κ σ) * t / 2)) + (2 * cirGamma κ σ * + (Real.exp ((κ + cirGamma κ σ) * T / 2) * ((κ + cirGamma κ σ) / 2))) T := by + simpa using (((hasDerivAt_id T).const_mul (κ + cirGamma κ σ)).div_const 2).exp.const_mul + (2 * cirGamma κ σ) + have hg := hF.div (hasDerivAt_cirDenom κ σ T) hD.ne' + have hA := (hg.log (div_pos (by positivity) hD).ne').const_mul (2 * κ * θ / σ ^ 2) + have hfun : cirBondA κ θ σ = fun t ↦ 2 * κ * θ / σ ^ 2 * + Real.log (((fun t ↦ 2 * cirGamma κ σ * Real.exp ((κ + cirGamma κ σ) * t / 2)) / + fun t ↦ cirDenom κ σ t) t) := rfl + rw [hfun] + refine hA.congr_deriv ?_ + have hF0 := (Real.exp_pos ((κ + cirGamma κ σ) * T / 2)).ne' + simp only [Pi.div_apply, cirBondB] + unfold cirDenom at * + field_simp + linear_combination κ * θ * (1 - Real.exp (cirGamma κ σ * T)) * hγ + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/CIRSquaredOU.lean b/LeanPool/MathFin/Models/Rates/CIRSquaredOU.lean new file mode 100644 index 0000000000..b7d3d3e9b9 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/CIRSquaredOU.lean @@ -0,0 +1,145 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.VasicekSDEGaussian + +/-! +# The mean of a sum of two squared OU fluctuations (the Feller-borderline CIR mean) + +Each component is an Ornstein–Uhlenbeck fluctuation in its Wiener representation, + +`Xᵢ t := x_{i0} e^{−(k/2)t} + s ∫₀ᵗ e^{−(k/2)(t−u)} dBᵢ_u`, + +which is the Vasicek short rate of `Models/Rates/VasicekSDEGaussian` at mean level `0`, +speed `k/2` and volatility `s`; its law `N(x_{i0}e^{−(k/2)t}, (s²/k)(1 − e^{−kt}))` is +`vasicekShortRate_hasLaw_gaussian`. With `v₀ := x_{10}² + x_{20}²` and `θ := 2s²/k` +(so `2kθ = (2s)²`, the Feller-borderline parametrization of +`dV = k(θ − V) dt + 2s√V dW`), `V t := (X₁ t)² + (X₂ t)²` has mean +`𝔼[V t] = θ(1 − e^{−kt}) + v₀e^{−kt}` (`cirVariance_mean`), the mean of the CIR process +from `v₀`. + +The statements are per-time: `V t` is a random variable for each `t`. That `V` solves the +CIR SDE is not proved; it needs `B₁`, `B₂` independent (Lévy's characterization of the +driving Brownian motion of `√V`), which the mean computation does not use. + +## Main definitions + +* `ouProcess`: the Ornstein–Uhlenbeck fluctuation + `X_t = x₀e^{−(k/2)t} + s ∫₀ᵗ e^{−(k/2)(t−u)} dB_u` in its Wiener representation. +* `cirTheta`: the long-run level `θ := 2s²/k` of the Feller-borderline parametrization. +* `cirVariance`: the sum of squares `V_t = (X₁_t)² + (X₂_t)²` of two OU fluctuations. + +## Main results + +Public API (all in namespace `MathFin.CIRSquaredOU`): + +* `ouProcess`, `ouProcess_integral_sq` — the OU fluctuation and its second moment; +* `cirTheta`, `cirTheta_borderline`, `cirVariance`, `cirVariance_nonneg`, + `cirVariance_mean` — the long-run level, the sum of squares, its nonnegativity and + its mean. + +## References + +* [J. C. Cox, J. E. Ingersoll and S. A. Ross, *A theory of the term structure of interest + rates*][CoxIngersollRoss1985] + +## Tags + +CIR process, Ornstein–Uhlenbeck, squared Bessel, Feller condition, sum of squares, mean-reverting, +MSC 60J60, MSC 60G15, MSC 91G30 +-/ + +@[expose] public section + +namespace MathFin.CIRSquaredOU + +open MeasureTheory ProbabilityTheory +open scoped NNReal +open MathFin WienerIntegralL2 + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-- The OU fluctuation `X_t = x₀e^{−(k/2)t} + s ∫₀ᵗ e^{−(k/2)(t−u)} dB_u`: the Vasicek short +rate in its Wiener representation at mean level `0`, speed `k/2`, volatility `s`. -/ +noncomputable def ouProcess (hB : IsPreBrownianReal B μ) (k s x0 : ℝ) + (hk : 0 < k) (t : ℝ≥0) (ω : Ω) : ℝ := + vasicekSDEMean x0 0 (k / 2) t + + s * wienerIntegralLp B hB t (vasicekKernelLp (k / 2) (half_pos hk).le t) ω + +/-- The OU second moment `𝔼[X_t²] = x₀²e^{−kt} + (s²/k)(1 − e^{−kt})`, from the Gaussian +law `vasicekShortRate_hasLaw_gaussian`. -/ +theorem ouProcess_integral_sq (hB : IsPreBrownianReal B μ) {k : ℝ} (hk : 0 < k) + (s x0 : ℝ) (t : ℝ≥0) : + ∫ ω, (ouProcess hB k s x0 hk t ω) ^ 2 ∂μ + = x0 ^ 2 * Real.exp (-(k * (t : ℝ))) + + s ^ 2 / k * (1 - Real.exp (-(k * (t : ℝ)))) := by + have hlaw : HasLaw (fun ω ↦ ouProcess hB k s x0 hk t ω) _ μ := + vasicekShortRate_hasLaw_gaussian hB x0 0 s (half_pos hk) t + rw [integral_sq_of_hasLaw_gaussianReal hlaw, Real.coe_toNNReal _ + (vasicekSDEVariance_nonneg s (half_pos hk) (NNReal.coe_nonneg t))] + have he : Real.exp (-(k / 2 * (t : ℝ))) ^ 2 = Real.exp (-(k * (t : ℝ))) := by + rw [← Real.exp_nat_mul] + ring_nf + simp only [vasicekSDEMean, vasicekSDEVariance, zero_mul, add_zero, mul_pow, he] + field_simp + +/-- The OU fluctuation is square integrable: a constant plus a multiple of an `L²` element. -/ +theorem ouProcess_sq_integrable (hB : IsPreBrownianReal B μ) {k : ℝ} (hk : 0 < k) + (s x0 : ℝ) (t : ℝ≥0) : + Integrable (fun ω ↦ (ouProcess hB k s x0 hk t ω) ^ 2) μ := by + have h1 : MemLp (wienerIntegralLp B hB t (vasicekKernelLp (k / 2) (half_pos hk).le t)) 2 μ := + Lp.memLp _ + have h2 := (memLp_const (vasicekSDEMean x0 0 (k / 2) t)).add (h1.const_mul s) + exact h2.integrable_sq + +variable {B1 B2 : ℝ≥0 → Ω → ℝ} + +/-- The long-run level `θ := 2s²/k`, the Feller-borderline parametrization of +`dV = k(θ − V) dt + 2s√V dW`. -/ +noncomputable def cirTheta (s k : ℝ) : ℝ := 2 * s ^ 2 / k + +/-- The borderline identity `2kθ = (2s)²` (false at `k = 0`, where `θ = 0` by +Lean's `x/0 = 0`). -/ +theorem cirTheta_borderline (s k : ℝ) (hk : k ≠ 0) : + 2 * k * cirTheta s k = (2 * s) ^ 2 := by + rw [cirTheta] + field_simp + +/-- The sum of squares `V_t := (X₁_t)² + (X₂_t)²` of two OU fluctuations, `Xᵢ` driven by +`Bᵢ` from `x_{i0}`. -/ +noncomputable def cirVariance (hB1 : IsPreBrownianReal B1 μ) + (hB2 : IsPreBrownianReal B2 μ) (k s x10 x20 : ℝ) (hk : 0 < k) + (t : ℝ≥0) (ω : Ω) : ℝ := + (ouProcess hB1 k s x10 hk t ω) ^ 2 + (ouProcess hB2 k s x20 hk t ω) ^ 2 + +omit [IsProbabilityMeasure μ] in +/-- `V_t(ω) ≥ 0` for every `(t, ω)`. -/ +theorem cirVariance_nonneg (hB1 : IsPreBrownianReal B1 μ) + (hB2 : IsPreBrownianReal B2 μ) (k s x10 x20 : ℝ) (hk : 0 < k) + (t : ℝ≥0) (ω : Ω) : + 0 ≤ cirVariance hB1 hB2 k s x10 x20 hk t ω := + add_nonneg (sq_nonneg _) (sq_nonneg _) + +/-- The mean `𝔼[V_t] = θ(1 − e^{−kt}) + v₀e^{−kt}`, `θ = 2s²/k`, `v₀ = x_{10}² + x_{20}²`: +the sum of the two component second moments. Independence of `B₁`, `B₂` is not used. -/ +theorem cirVariance_mean (hB1 : IsPreBrownianReal B1 μ) + (hB2 : IsPreBrownianReal B2 μ) {k : ℝ} (hk : 0 < k) (s x10 x20 : ℝ) + (t : ℝ≥0) : + ∫ ω, cirVariance hB1 hB2 k s x10 x20 hk t ω ∂μ + = cirTheta s k * (1 - Real.exp (-(k * (t : ℝ)))) + + (x10 ^ 2 + x20 ^ 2) * Real.exp (-(k * (t : ℝ))) := by + simp only [cirVariance] + rw [integral_add (ouProcess_sq_integrable hB1 hk s x10 t) + (ouProcess_sq_integrable hB2 hk s x20 t), + ouProcess_integral_sq hB1 hk s x10 t, ouProcess_integral_sq hB2 hk s x20 t, cirTheta] + ring + +end MathFin.CIRSquaredOU diff --git a/LeanPool/MathFin/Models/Rates/CMS.lean b/LeanPool/MathFin/Models/Rates/CMS.lean new file mode 100644 index 0000000000..9df9031e25 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/CMS.lean @@ -0,0 +1,518 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.InterestRateSwap +public import LeanPool.MathFin.Models.ModelFree.CarrMadan +public import LeanPool.MathFin.Pricing.Numeraire +public import LeanPool.MathFin.Models.Rates.ConvexitySensitivity +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.Analysis.Convex.Integral + +/-! +# The CMS par-rate functional: convexity, the annuity measure, a Jensen gap + +A constant-maturity swap leg pays, at the fixing date `T`, the *then-prevailing* +par swap rate — a nonlinear functional of the curve state, discounted through an +annuity that is itself random; the gap between its value and today's par rate is +the **convexity adjustment**. This module formalizes ingredients of that +adjustment on the swap layer of `MathFin/Models/Rates/InterestRateSwap.lean` +(`payerSwapValue` / `parSwapRate` / `annuity`), but not the adjustment itself +(see the scope note below): + +* **The par-rate functional.** `cmsCurveRate P₀ δ C x = (P₀ − x)/(δ·(C + x))` — + the par rate of a curve whose final discount factor is `x`, other factors + fixed. Two bridges tie it to the swap layer: `annuity_update_eq` (the annuity + of an updated curve splits into fixed part + new factor) and + `parSwapRate_update_eq` / `payerSwapValue_update_eq_zero_iff` (the par + identity of `payerSwapValue_eq_zero_iff` transports verbatim). +* **Convexity in the discount factor.** `cmsCurveRate_convexOn`: on `[0, ∞)` + the rate is convex given `δ > 0`, `C > 0` and `0 ≤ P₀ + C` — via the + shifted-inverse engine + `convexOn_inv_shift` and the `ConvexOn.smul` / `.add_const` / `.congr` + combination pattern. First and second derivatives are landed explicitly + (`hasDerivAt_cmsCurveRate`, `hasDerivAt_cmsCurveRate'`): + `S''(x) = 2(P₀+C)/(δ(C+x)³)`, positive when `P₀ + C > 0`. +* **The annuity measure.** `annuityMeasure`: the change-of-numéraire measure + with the annuity `A_T` in the numéraire seat against the money market + `B = 1/D`, `D` the discount factor to the fixing date, random in general + (`D = e^{−rT}` is the deterministic money market) — an execution of + `MathFin.changeOfNumeraire` + (`Pricing/Numeraire.lean`), alongside the stock and the `T`-bond (the + forward measure of `Pricing/ForwardMeasure.lean`). `annuityMeasure_price` + proves `A₀·𝔼^{Qᴬ}[S] = 𝔼^Q[D·S·A_T]` — `Qᴬ`-expectations price + annuity-settled payoffs `S·A_T`; `annuityMeasure_isProbabilityMeasure` proves + `Qᴬ` is a probability *given the annuity repricing condition* + `𝔼^Q[D·A_T] = A₀` — that normalization is where the martingale content + enters, and it is taken as an explicit hypothesis (`Models/Rates/CMSContract.lean` derives it + from the tower property when the curve is the bond prices of `D`). +* **The headline.** `cmsCurveRate_jensenGap_nonneg`: Jensen under the annuity measure + (Mathlib's `ConvexOn.map_integral_le`) gives + + `S(x₀) ≤ 𝔼^{Qᴬ}[S(W)]` whenever `𝔼^{Qᴬ}[W] = x₀`, + + for every nonnegative `W` with `W` and `S ∘ W` `Qᴬ`-integrable: the Jensen gap + of the rate functional is nonnegative (`cmsCurveRate_jensenGap_sub_nonneg` states the + gap). `Qᴬ` enters only as a probability measure, `W` is not tied to the curve + `P` that defines `Qᴬ`, and `S(x₀)` is not shown to be today's par rate. +* **The replication seed.** `cmsCurveRate_spanning`: Carr–Madan static + replication of the rate functional — cash + forward + put strip + call strip + with weights `S''(K) = 2(P₀+C)/(δ(C+K)³)` (positive when `P₀ + C > 0`, which + the identity does not assume); `cmsCurveRate_strip_nonneg` turns it into the + tangent-line inequality: for `P₀ + C ≥ 0` the rate lies above its tangent at + the reference strike on `[L, U]`. +* **A bond-convexity sign.** `convexityNumerator_nonneg`: the bond convexity + numerator `convexityNumerator` of `ConvexitySensitivity` is nonnegative when + `1 + y > 0` and the cash flows are nonnegative. It is a standalone bond fact; + nothing here connects it to the CMS rate. + +Scope: what lands here is the convexity of the rate functional, the annuity measure, the Jensen gap +under it, and the compact-range replication identity. `Models/Rates/CMSContract.lean` prices CMS +contracts under the annuity measure with the curve tied to the bond prices of a stochastic discount +factor, and restates the Jensen gap for the swap rate. The convexity adjustment for a rate paid at a +later date — `𝔼^{T_p}[S_T] − S₀`, which needs the change of measure from `Qᴬ` to the payment-date +forward measure — is not formalized. The spanning is the compact-strike-range version +(`[L, U]` with `L > −C`); the unbounded-window passage (tail analysis) is not here either. The +swap-rate functional is *not* a log payoff, so the seed consumes `carrMadan_spanning` — the shared +core of which `carrMadan_log_spanning` is the log instance (its proof is one instantiation). + +## Main definitions + +* `cmsCurveRate`: the par swap rate of a curve whose final discount factor is `x`, all other + discount factors fixed. +* `annuityRandom`: the random annuity `A_T(ω) = δ · ∑_{i ∈ s} P(ω, T_i)` at the fixing date. +* `annuityMeasure`: the annuity measure `Qᴬ`, the change-of-numéraire measure with the annuity + `A_T` in the numéraire seat. + +## Main results + +* `parSwapRate_update_eq`, `payerSwapValue_update_eq_zero_iff`: for `n ∈ s`, the par rate of the + curve with factor `n` replaced by `x` is `cmsCurveRate`; for `δ > 0`, `x > 0` and positive + factors, the payer swap on that curve has zero value if and only if `K = cmsCurveRate ...`. +* `hasDerivAt_cmsCurveRate`, `cmsCurveRate_convexOn`: for `δ ≠ 0` and `C + x ≠ 0` the rate has + derivative `−(P₀+C)/(δ(C+x)²)` at `x`; for `δ > 0`, `C > 0` and `0 ≤ P₀ + C` it is convex on + `[0, ∞)`. +* `annuityMeasure_isProbabilityMeasure`: with positive `D`, `δ`, `A₀` and curve factors, and the + annuity repricing condition `𝔼^Q[D·A_T] = A₀` as a hypothesis, `Qᴬ` is a probability measure. +* `annuityMeasure_price`: with positive `D`, `δ`, `A₀` and curve factors, and a measurable + annuity, `A₀·𝔼^{Qᴬ}[S] = 𝔼^Q[D·S·A_T]` (the normalization is not needed for this identity). +* `cmsCurveRate_jensenGap_nonneg`, `cmsCurveRate_jensenGap_sub_nonneg`: under the positivity + hypotheses, the repricing condition and `δ > 0`, `C > 0`, `0 ≤ P₀ + C`, for any nonnegative `W` + with `W` and `S ∘ W` `Qᴬ`-integrable and `𝔼^{Qᴬ}[W] = x₀`, `S(x₀) ≤ 𝔼^{Qᴬ}[S(W)]`; `W` is + not tied to the curve and `S(x₀)` is not shown to be today's par rate. +* `cmsCurveRate_spanning`: for `δ > 0`, `−C < L ≤ κ ≤ U` and `S ∈ [L, U]`, the rate at `S` + equals its value at `κ`, plus the tangent term, plus put and call strips weighted by + `2(P₀+C)/(δ(C+K)³)` (Carr–Madan; no sign condition on `P₀ + C`). +* `cmsCurveRate_strip_nonneg`: with `δ > 0` and `0 ≤ P₀ + C`, the rate lies above its tangent at + `κ` on `[L, U]` (`−C < L ≤ κ ≤ U`). +* `convexityNumerator_nonneg`: for `1 + y > 0` and nonnegative cash flows, the bond convexity + numerator is nonnegative (a standalone bond fact, not linked to the CMS rate). + +## References + +* [P. Carr and D. Madan, *Towards a theory of volatility trading*][CarrMadan1998] +* [P. S. Hagan, *Convexity conundrums: pricing CMS swaps, caps, and floors*][Hagan2003] + +## Tags + +constant maturity swap, convexity adjustment, annuity measure, swap measure, Jensen gap, +par swap rate, Carr–Madan replication, MSC 91G30, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin.CMS + +open MeasureTheory Real MathFin + +/-! ### 1. The par-rate functional in the discount factor -/ + +/-- **The CMS curve rate**: the par swap rate of a curve whose final discount +factor is `x`, all other discount factors fixed. The floating leg is `P₀ − x`, +the annuity `δ·(C + x)` with `C` the sum of the remaining discount factors — +mirroring `MathFin.parSwapRate P₀ x (annuity δ P s)` for the curve `P` updated +at the final payment index (`parSwapRate_update_eq` below). -/ +noncomputable def cmsCurveRate (P0 δ C x : ℝ) : ℝ := (P0 - x) / (δ * (C + x)) + +/-- The annuity of an updated curve splits into the fixed part of the schedule +plus the new factor: `annuity δ (update P n x) s = δ·(∑_{i ≠ n} P i + x)`. -/ +private theorem annuity_update_eq {ι : Type*} [DecidableEq ι] (δ : ℝ) (P : ι → ℝ) + (s : Finset ι) {n : ι} (hn : n ∈ s) (x : ℝ) : + annuity δ (Function.update P n x) s = δ * ((∑ i ∈ s.erase n, P i) + x) := by + have hsum : ∑ i ∈ s.erase n, Function.update P n x i + Function.update P n x n + = ∑ i ∈ s, Function.update P n x i := Finset.sum_erase_add s _ hn + have hrest : ∑ i ∈ s.erase n, Function.update P n x i = ∑ i ∈ s.erase n, P i := + Finset.sum_congr rfl fun i hi ↦ Function.update_of_ne (Finset.ne_of_mem_erase hi) x P + change δ * ∑ i ∈ s, Function.update P n x i = δ * ((∑ i ∈ s.erase n, P i) + x) + rw [← hsum, hrest, Function.update_self] + +/-- **The bridge to the swap layer**: the par rate of the updated curve *is* +the CMS curve rate. -/ +theorem parSwapRate_update_eq {ι : Type*} [DecidableEq ι] (P0 δ x : ℝ) (P : ι → ℝ) + (s : Finset ι) {n : ι} (hn : n ∈ s) : + parSwapRate P0 (Function.update P n x n) + (annuity δ (Function.update P n x) s) + = cmsCurveRate P0 δ (∑ i ∈ s.erase n, P i) x := by + change (P0 - Function.update P n x n) / (annuity δ (Function.update P n x) s) + = cmsCurveRate P0 δ (∑ i ∈ s.erase n, P i) x + rw [Function.update_self, annuity_update_eq δ P s hn x] + rfl + +/-- **The par identity in curve form** — the CMS instantiation of +`payerSwapValue_eq_zero_iff`: the fixed rate zeroing the payer swap over the +updated curve is exactly the CMS curve rate. -/ +theorem payerSwapValue_update_eq_zero_iff {ι : Type*} [DecidableEq ι] (P0 δ K x : ℝ) + (P : ι → ℝ) (s : Finset ι) {n : ι} (hn : n ∈ s) (hδ : 0 < δ) (hx : 0 < x) + (hP : ∀ i ∈ s, 0 < P i) : + payerSwapValue P0 (Function.update P n x n) K (annuity δ (Function.update P n x) s) = 0 + ↔ K = cmsCurveRate P0 δ (∑ i ∈ s.erase n, P i) x := by + have hup : ∀ i ∈ s, 0 < Function.update P n x i := by + intro i hi + by_cases hIn : i = n + · rw [hIn, Function.update_self]; exact hx + · rw [Function.update_of_ne hIn x P] + exact hP i hi + have hA := annuity_pos hδ hup (⟨n, hn⟩ : s.Nonempty) + rw [payerSwapValue_eq_zero_iff P0 (Function.update P n x n) K hA.ne', + parSwapRate_update_eq P0 δ x P s hn] + +/-! ### 2. Derivatives and convexity of the rate functional -/ + +/-- Rewritten form (affine-in-inverse): with `a = P₀ + C`, +`S(x) = a/δ · (C + x)⁻¹ − 1/δ` — the one-line reason the rate is convex when +`P₀ + C ≥ 0` and has second derivative `2a/(δ(C+x)³)`. -/ +private theorem cmsCurveRate_eq (P0 δ C x : ℝ) (hx : C + x ≠ 0) (hδ : δ ≠ 0) : + cmsCurveRate P0 δ C x = (P0 + C) / δ * (C + x)⁻¹ - 1 / δ := by + rw [cmsCurveRate] + field_simp + ring + +/-- **First derivative**: `S'(x) = −(P₀ + C)/(δ(C + x)²)`. -/ +theorem hasDerivAt_cmsCurveRate (P0 δ C x : ℝ) (hx : C + x ≠ 0) (hδ : δ ≠ 0) : + HasDerivAt (cmsCurveRate P0 δ C) (-(P0 + C) / (δ * (C + x) ^ 2)) x := by + have hf : HasDerivAt (fun y : ℝ ↦ P0 - y) (-1 : ℝ) x := + HasDerivAt.const_sub P0 (hasDerivAt_id x) + have hd : HasDerivAt (fun y : ℝ ↦ δ * (y + C)) (δ * 1) x := + HasDerivAt.const_mul δ ((hasDerivAt_id x).add_const C) + have hdx : δ * (x + C) ≠ 0 := by + refine mul_ne_zero hδ ?_ + rw [add_comm] + exact hx + have hdiv : HasDerivAt (fun y : ℝ ↦ (P0 - y) / (δ * (y + C))) + (((-1 : ℝ) * (δ * (x + C)) - (P0 - x) * (δ * 1)) / (δ * (x + C)) ^ 2) x := + HasDerivAt.fun_div hf hd hdx + rw [show cmsCurveRate P0 δ C = fun y : ℝ ↦ (P0 - y) / (δ * (y + C)) from by + funext y + change (P0 - y) / (δ * (C + y)) = (P0 - y) / (δ * (y + C)) + rw [add_comm C y], + show (-(P0 + C) / (δ * (C + x) ^ 2)) + = (((-1 : ℝ) * (δ * (x + C)) - (P0 - x) * (δ * 1)) / (δ * (x + C)) ^ 2) from by + rw [div_eq_div_iff (mul_ne_zero hδ (pow_ne_zero 2 hx)) + (pow_ne_zero 2 (mul_ne_zero hδ (by rw [add_comm]; exact hx)))] + ring] + exact hdiv + +/-- **Second derivative**: `S''(x) = 2(P₀ + C)/(δ(C + x)³)` — positive where +`δ > 0`, `C + x > 0` and `P₀ + C > 0`. -/ +theorem hasDerivAt_cmsCurveRate' (P0 δ C t : ℝ) (ht : C + t ≠ 0) (hδ : δ ≠ 0) : + HasDerivAt (fun y : ℝ ↦ -(P0 + C) / (δ * (C + y) ^ 2)) + (2 * (P0 + C) / (δ * (C + t) ^ 3)) t := by + -- work in the `(y + C)` convention, then convert at the end + have hu : HasDerivAt (fun y : ℝ ↦ y + C) (1 : ℝ) t := (hasDerivAt_id t).add_const C + have htc : t + C ≠ 0 := by rw [add_comm]; exact ht + have hinv : HasDerivAt (fun y : ℝ ↦ (y + C)⁻¹) (-((t + C) ^ 2)⁻¹ * 1) t := + (hasDerivAt_inv htc).comp t hu + have hpow : HasDerivAt (fun y : ℝ ↦ (y + C)⁻¹ * (y + C)⁻¹) + (-((t + C) ^ 2)⁻¹ * 1 * (t + C)⁻¹ + (t + C)⁻¹ * (-((t + C) ^ 2)⁻¹ * 1)) t := + hinv.mul hinv + have hres := hpow.const_mul (-(P0 + C) / δ) + rw [show (fun y : ℝ ↦ (-(P0 + C) / δ) * ((y + C)⁻¹ * (y + C)⁻¹)) + = fun y : ℝ ↦ -(P0 + C) / (δ * (y + C) ^ 2) from by + funext y; field_simp, + show ((-(P0 + C) / δ) * (-((t + C) ^ 2)⁻¹ * 1 * (t + C)⁻¹ + + (t + C)⁻¹ * (-((t + C) ^ 2)⁻¹ * 1))) + = 2 * (P0 + C) / (δ * (t + C) ^ 3) from by + field_simp [mul_inv, inv_pow] + ring, + show (fun y : ℝ ↦ -(P0 + C) / (δ * (y + C) ^ 2)) + = fun y : ℝ ↦ -(P0 + C) / (δ * (C + y) ^ 2) from by funext y; ring, + show (2 * (P0 + C) / (δ * (t + C) ^ 3)) = 2 * (P0 + C) / (δ * (C + t) ^ 3) from by + rw [add_comm t C]] at hres + exact hres + +/-- Differentiability of the rate functional on the nonnegative half-line — +there the denominator stays `≥ C > 0`. -/ +private theorem differentiableOn_cmsCurveRate (P0 δ C : ℝ) (hδ : 0 < δ) (hC : 0 < C) : + DifferentiableOn ℝ (cmsCurveRate P0 δ C) (Set.Ici 0) := + fun x hx ↦ ((hasDerivAt_cmsCurveRate P0 δ C x + (ne_of_gt (show (0 : ℝ) < C + x by linarith [Set.mem_Ici.1 hx])) + hδ.ne').differentiableAt).differentiableWithinAt + +/-- Continuity on the nonnegative half-line — the regularity Jensen consumes. -/ +private theorem continuousOn_cmsCurveRate (P0 δ C : ℝ) (hδ : 0 < δ) (hC : 0 < C) : + ContinuousOn (cmsCurveRate P0 δ C) (Set.Ici 0) := + (differentiableOn_cmsCurveRate P0 δ C hδ hC).continuousOn + +/-- **Convexity of the shifted inverse** `x ↦ (C + x)⁻¹` on the nonnegative +half-line — the convexity engine behind the CMS rate's convexity. The two-point +inequality `(u(C+x)+v(C+y))⁻¹ ≤ u(C+x)⁻¹ + v(C+y)⁻¹` is the AM–GM identity +`(ua+vb)(u/a+v/b) − 1 = uv(a−b)²/(ab) ≥ 0` for `a, b > 0`, `u + v = 1`. -/ +theorem convexOn_inv_shift (C : ℝ) (hC : 0 < C) : + ConvexOn ℝ (Set.Ici (0 : ℝ)) (fun x : ℝ ↦ (C + x)⁻¹) := by + refine ⟨convex_Ici 0, fun x hx y hy u v hu hv huv ↦ ?_⟩ + change (C + (u * x + v * y))⁻¹ ≤ u * (C + x)⁻¹ + v * (C + y)⁻¹ + have hx0 : (0 : ℝ) ≤ x := Set.mem_Ici.1 hx + have hy0 : (0 : ℝ) ≤ y := Set.mem_Ici.1 hy + have hxa : 0 < C + x := by linarith + have hya : 0 < C + y := by linarith + have hxu : 0 ≤ u * x := mul_nonneg hu hx0 + have hxv : 0 ≤ v * y := mul_nonneg hv hy0 + have hcomb : C + (u * x + v * y) = u * (C + x) + v * (C + y) := by + have hCmul : u * C + v * C = C := by linear_combination C * huv + linarith + rw [hcomb] + have hA : 0 < u * (C + x) + v * (C + y) := by rw [← hcomb]; linarith + have hkey2 : (C + x) * (C + y) + ≤ (u * (C + x) + v * (C + y)) * (u * (C + y) + v * (C + x)) := by + have h1 : 0 ≤ u * v * (x - y) ^ 2 := mul_nonneg (mul_nonneg hu hv) (sq_nonneg _) + have h2 : 0 ≤ (C + x) * (C + y) * ((u + v) ^ 2 - 1) := by rw [huv]; simp + -- certificate: RHS − LHS = uv(x−y)² + (C+x)(C+y)·((u+v)² − 1), an identity + nlinarith [h1, h2] + have hkey : 1 ≤ (u * (C + x)⁻¹ + v * (C + y)⁻¹) * (u * (C + x) + v * (C + y)) := by + field_simp + nlinarith + -- last step: `A⁻¹ ≤ B ↔ 1 ≤ B * A`, avoiding the generic-lemma instance mismatch + rw [inv_eq_one_div, div_le_iff₀ hA] + exact hkey + +/-- **The CMS rate is convex in the discount factor on the nonnegative +half-line**. Hypotheses: `δ > 0` (daycount), +`C > 0` (the rate functional is defined on the whole half-line) and `P₀ + C ≥ 0` +(the convexity coefficient `S'' = 2(P₀+C)/(δ(C+x)³)` has the right sign; +economically `P₀` and every remaining discount factor are positive, so this is +free). -/ +theorem cmsCurveRate_convexOn (P0 δ C : ℝ) (hδ : 0 < δ) (hC : 0 < C) + (hPC : 0 ≤ P0 + C) : + ConvexOn ℝ (Set.Ici (0 : ℝ)) (cmsCurveRate P0 δ C) := by + have hcoef : (0 : ℝ) ≤ (P0 + C) / δ := div_nonneg hPC hδ.le + refine (ConvexOn.add_const ((convexOn_inv_shift C hC).smul hcoef) (-1 / δ)).congr ?_ + intro x hx + have hxne : C + x ≠ 0 := + ne_of_gt (show (0 : ℝ) < C + x by linarith [Set.mem_Ici.1 hx]) + simp only [Pi.add_apply, smul_eq_mul] + rw [cmsCurveRate_eq P0 δ C x hxne hδ.ne'] + ring + +/-! ### 3. The annuity measure -/ + +section Annuity + +variable {Ω ι : Type*} [MeasurableSpace Ω] + +omit [MeasurableSpace Ω] in +/-- The random annuity at the fixing date: `A_T(ω) = δ · ∑_{i ∈ s} P(ω, T_i)` — +the PVBP of the underlying swap along the curve state. -/ +noncomputable def annuityRandom (δ : ℝ) (P : Ω → ι → ℝ) (s : Finset ι) : Ω → ℝ := + fun ω ↦ annuity δ (P ω) s + +omit [MeasurableSpace Ω] in +/-- The annuity is strictly positive along every curve state with positive +discount factors. -/ +private theorem annuityRandom_pos {δ : ℝ} (hδ : 0 < δ) {P : Ω → ι → ℝ} {s : Finset ι} + (hs : s.Nonempty) (hP : ∀ ω i, i ∈ s → 0 < P ω i) (ω : Ω) : + 0 < annuityRandom δ P s ω := + annuity_pos hδ (fun i hi ↦ hP ω i hi) hs + +/-- **The annuity measure** `Qᴬ`: the change-of-numéraire measure with the +annuity `A_T` in the numéraire seat against the money market `B_T = 1/D`, `D` the (random) +discount factor to the fixing date — an execution of `MathFin.changeOfNumeraire`, alongside the +stock and the `T`-bond (the forward measure of `Pricing/ForwardMeasure.lean`). +Density: `dQᴬ/dQ = A_T·D/A₀`. A deterministic money market `e^{rT}` is `D = e^{−rT}`. -/ +noncomputable def annuityMeasure (Q : Measure Ω) (D : Ω → ℝ) (δ : ℝ) (P : Ω → ι → ℝ) + (s : Finset ι) (A0 : ℝ) : Measure Ω := + numeraireMeasure Q (fun ω ↦ (D ω)⁻¹) (annuityRandom δ P s) 1 A0 + +/-- **The annuity measure is a probability measure** under the annuity-repricing +condition `𝔼^Q[D·A_T] = A₀` — the numéraire engine's normalization +`𝔼^Q[N_T/B_T] = N₀/B₀` read with `N = A`, `B = 1/D` the money market. This hypothesis +is where the martingale content of the CMS construction enters; it is taken +explicitly. -/ +theorem annuityMeasure_isProbabilityMeasure {Q : Measure Ω} (D : Ω → ℝ) (δ : ℝ) + (P : Ω → ι → ℝ) (s : Finset ι) (A0 : ℝ) (hD : ∀ ω, 0 < D ω) (hδ : 0 < δ) + (hs : s.Nonempty) (hP : ∀ ω i, i ∈ s → 0 < P ω i) (hA0 : 0 < A0) + (hint : Integrable (fun ω ↦ annuityRandom δ P s ω * D ω) Q) + (hrepr : ∫ ω, annuityRandom δ P s ω * D ω ∂Q = A0) : + IsProbabilityMeasure (annuityMeasure Q D δ P s A0) := by + have hpos : ∀ ω, 0 < annuityRandom δ P s ω := fun ω ↦ annuityRandom_pos hδ hs hP ω + have hdiv : (fun ω : Ω ↦ annuityRandom δ P s ω / (D ω)⁻¹) + = fun ω ↦ annuityRandom δ P s ω * D ω := funext fun ω ↦ div_inv_eq_mul _ _ + exact numeraireMeasure_isProbabilityMeasure hpos (fun ω ↦ inv_pos.2 (hD ω)) one_pos hA0 + (by rw [hdiv]; exact hint) (by rw [hdiv, hrepr]; simp) + +/-- **The annuity-measure pricing identity** — the annuity in the numéraire seat. +For any `S`, + + `A₀ · 𝔼^{Qᴬ}[S] = 𝔼^Q[D · S · A_T]`, + +an execution of `changeOfNumeraire`: `Qᴬ`-expectations price the annuity-settled +payoff `S·A_T`. (A claim paying `S` itself at `T` would be priced through +`S/A_T`; the random `A_T` stays on the `Q` side.) -/ +theorem annuityMeasure_price {Q : Measure Ω} (D : Ω → ℝ) (δ : ℝ) (P : Ω → ι → ℝ) + (s : Finset ι) (A0 : ℝ) (S : Ω → ℝ) (hD : ∀ ω, 0 < D ω) (hDm : Measurable D) + (hδ : 0 < δ) (hs : s.Nonempty) (hP : ∀ ω i, i ∈ s → 0 < P ω i) (hA0 : 0 < A0) + (hAmeas : Measurable (annuityRandom δ P s)) : + A0 * ∫ ω, S ω ∂(annuityMeasure Q D δ P s A0) + = ∫ ω, D ω * (S ω * annuityRandom δ P s ω) ∂Q := by + have hpos : ∀ ω, 0 < annuityRandom δ P s ω := fun ω ↦ annuityRandom_pos hδ hs hP ω + have h := changeOfNumeraire (Q := Q) (BT := fun ω ↦ (D ω)⁻¹) + (NT := annuityRandom δ P s) (B0 := (1 : ℝ)) (N0 := A0) + (fun ω ↦ S ω * annuityRandom δ P s ω) hAmeas + hDm.inv hpos (fun ω ↦ inv_pos.2 (hD ω)) (by norm_num) hA0 + have hcongr : ∀ ω : Ω, annuityRandom δ P s ω ≠ 0 → + S ω * annuityRandom δ P s ω / annuityRandom δ P s ω = S ω := by + intro ω hY + simp [hY] + rw [integral_congr_ae (ae_of_all _ fun ω ↦ hcongr ω (ne_of_gt (hpos ω)))] at h + have h2 : 1 * ∫ ω, S ω * annuityRandom δ P s ω / (D ω)⁻¹ ∂Q + = ∫ ω, D ω * (S ω * annuityRandom δ P s ω) ∂Q := by + rw [one_mul] + exact integral_congr_ae (ae_of_all _ fun ω ↦ by + change S ω * annuityRandom δ P s ω / (D ω)⁻¹ = D ω * (S ω * annuityRandom δ P s ω) + rw [div_inv_eq_mul, mul_comm]) + rw [← h2] + exact h + +/-! ### 4. The headline: the Jensen gap under the annuity measure -/ + +-- the Jensen application carries heavy higher-order unification +/-- **The Jensen gap of the CMS rate functional under `Qᴬ`** (the headline). Let +`S = cmsCurveRate P₀ δ C`, with `P₀` and `C` deterministic; it is convex on +`[0, ∞)`. Every nonnegative `W` with `W` and `S ∘ W` integrable under the annuity +measure `Qᴬ` of the previous section satisfies `S(𝔼^{Qᴬ}[W]) ≤ 𝔼^{Qᴬ}[S(W)]`; +`hfwd` only names `x₀ = 𝔼^{Qᴬ}[W]`. `Qᴬ` is a probability measure by `hrepr` and +is used only as one; `W` is not linked to the curve `P` that defines `Qᴬ`, and no +martingale property is assumed. This is not the CMS convexity adjustment +`𝔼^{T_p}[S_T] − S₀`. -/ +theorem cmsCurveRate_jensenGap_nonneg {Q : Measure Ω} (D : Ω → ℝ) (δ P0 C A0 x₀ : ℝ) + (P : Ω → ι → ℝ) (s : Finset ι) (W : Ω → ℝ) (hD : ∀ ω, 0 < D ω) (hδ : 0 < δ) (hC : 0 < C) + (hPC : 0 ≤ P0 + C) (hs : s.Nonempty) (hP : ∀ ω i, i ∈ s → 0 < P ω i) + (hA0 : 0 < A0) + (hint : Integrable (fun ω ↦ annuityRandom δ P s ω * D ω) Q) + (hrepr : ∫ ω, annuityRandom δ P s ω * D ω ∂Q = A0) + (hWpos : ∀ ω, 0 ≤ W ω) + (hWint : Integrable W (annuityMeasure Q D δ P s A0)) + (hSint : Integrable (fun ω ↦ cmsCurveRate P0 δ C (W ω)) + (annuityMeasure Q D δ P s A0)) + (hfwd : ∫ ω, W ω ∂(annuityMeasure Q D δ P s A0) = x₀) : + cmsCurveRate P0 δ C x₀ + ≤ ∫ ω, cmsCurveRate P0 δ C (W ω) ∂(annuityMeasure Q D δ P s A0) := by + have hprob := annuityMeasure_isProbabilityMeasure D δ P s A0 hD hδ hs hP hA0 hint hrepr + have hfs : ∀ᵐ ω ∂(annuityMeasure Q D δ P s A0), W ω ∈ Set.Ici (0 : ℝ) := + ae_of_all _ fun ω ↦ Set.mem_Ici.2 (hWpos ω) + have hj := ConvexOn.map_integral_le (f := W) (g := cmsCurveRate P0 δ C) + (s := Set.Ici (0 : ℝ)) (cmsCurveRate_convexOn P0 δ C hδ hC hPC) + (continuousOn_cmsCurveRate P0 δ C hδ hC) isClosed_Ici hfs hWint hSint + rwa [hfwd] at hj + +/-- The Jensen gap itself: `𝔼^{Qᴬ}[S(W)] − S(𝔼^{Qᴬ}[W]) ≥ 0`. -/ +theorem cmsCurveRate_jensenGap_sub_nonneg {Q : Measure Ω} (D : Ω → ℝ) (δ P0 C A0 x₀ : ℝ) + (P : Ω → ι → ℝ) (s : Finset ι) (W : Ω → ℝ) (hD : ∀ ω, 0 < D ω) (hδ : 0 < δ) (hC : 0 < C) + (hPC : 0 ≤ P0 + C) (hs : s.Nonempty) (hP : ∀ ω i, i ∈ s → 0 < P ω i) + (hA0 : 0 < A0) + (hint : Integrable (fun ω ↦ annuityRandom δ P s ω * D ω) Q) + (hrepr : ∫ ω, annuityRandom δ P s ω * D ω ∂Q = A0) + (hWpos : ∀ ω, 0 ≤ W ω) + (hWint : Integrable W (annuityMeasure Q D δ P s A0)) + (hSint : Integrable (fun ω ↦ cmsCurveRate P0 δ C (W ω)) + (annuityMeasure Q D δ P s A0)) + (hfwd : ∫ ω, W ω ∂(annuityMeasure Q D δ P s A0) = x₀) : + 0 ≤ ∫ ω, cmsCurveRate P0 δ C (W ω) ∂(annuityMeasure Q D δ P s A0) + - cmsCurveRate P0 δ C x₀ := + sub_nonneg.2 (cmsCurveRate_jensenGap_nonneg D δ P0 C A0 x₀ P s W hD hδ hC hPC hs hP hA0 hint + hrepr hWpos hWint hSint hfwd) + +end Annuity + +/-! ### 5. The replication seed: Carr–Madan spanning of the rate functional -/ + +-- the Carr–Madan instantiation carries heavy higher-order unification +/-- **The replication seed**: the CMS rate functional spanned as cash + forward ++ static OTM option strips on the discount factor (Carr–Madan, compact strike +range `[L, U]` with `L > −C`). The strip weights are +`S''(K) = 2(P₀+C)/(δ(C+K)³)`, positive when `P₀ + C > 0` (not assumed here). The +swap-rate functional is not a log payoff, so this consumes +`carrMadan_spanning`, the shared core of which `carrMadan_log_spanning` is the +log instance. The unbounded-window limit (tail analysis) is outside the present +scope. -/ +theorem cmsCurveRate_spanning (P0 δ C : ℝ) (hδ : 0 < δ) + {L U κ S : ℝ} (hL : -C < L) (hLκ : L ≤ κ) (hκU : κ ≤ U) (hS : S ∈ Set.Icc L U) : + cmsCurveRate P0 δ C S = cmsCurveRate P0 δ C κ + + (-(P0 + C) / (δ * (C + κ) ^ 2)) * (S - κ) + + (∫ K in L..κ, (2 * (P0 + C) / (δ * (C + K) ^ 3)) * max (K - S) 0) + + (∫ K in κ..U, (2 * (P0 + C) / (δ * (C + K) ^ 3)) * max (S - K) 0) := by + have hCK : ∀ K ∈ Set.Icc L U, 0 < C + K := by + intro K hK + have h1 : -C < K := by have := hK.1; linarith + linarith + exact carrMadan_spanning (f := cmsCurveRate P0 δ C) + (f' := fun t ↦ -(P0 + C) / (δ * (C + t) ^ 2)) + (f'' := fun K ↦ 2 * (P0 + C) / (δ * (C + K) ^ 3)) hLκ hκU hS + (fun t ht ↦ hasDerivAt_cmsCurveRate P0 δ C t (ne_of_gt (hCK t ht)) hδ.ne') + (fun t ht ↦ hasDerivAt_cmsCurveRate' P0 δ C t (ne_of_gt (hCK t ht)) hδ.ne') + (show ContinuousOn (fun K : ℝ ↦ 2 * (P0 + C) / (δ * (C + K) ^ 3)) (Set.Icc L U) from + ContinuousOn.div continuousOn_const + (show ContinuousOn (fun K : ℝ ↦ δ * (C + K) ^ 3) (Set.Icc L U) from + (Continuous.mul continuous_const + ((continuous_const.add continuous_id).pow 3)).continuousOn) + fun K hK ↦ mul_ne_zero hδ.ne' (pow_ne_zero 3 (ne_of_gt (hCK K hK)))) + +/-- **The tangent-line inequality**: on `[L, U]` the CMS rate lies above its +tangent at `κ`, and the excess is exactly the option strips — nonnegative because +`S'' ≥ 0` (from `P₀ + C ≥ 0`). -/ +theorem cmsCurveRate_strip_nonneg (P0 δ C : ℝ) (hδ : 0 < δ) (hPC : 0 ≤ P0 + C) + {L U κ S : ℝ} (hL : -C < L) (hLκ : L ≤ κ) (hκU : κ ≤ U) (hS : S ∈ Set.Icc L U) : + 0 ≤ cmsCurveRate P0 δ C S - cmsCurveRate P0 δ C κ + - (-(P0 + C) / (δ * (C + κ) ^ 2)) * (S - κ) := by + have hspan := cmsCurveRate_spanning P0 δ C hδ hL hLκ hκU hS + have hCKpos : ∀ K ∈ Set.Icc L U, 0 < C + K := by + intro K hK + have h1 : -C < K := by have := hK.1; linarith + linarith + have hput : 0 ≤ ∫ K in L..κ, (2 * (P0 + C) / (δ * (C + K) ^ 3)) * max (K - S) 0 := + intervalIntegral.integral_nonneg hLκ fun K hK ↦ + mul_nonneg + (div_nonneg (mul_nonneg two_pos.le hPC) + (mul_nonneg hδ.le (pow_nonneg (le_of_lt (hCKpos K + ⟨hK.1, hK.2.trans hκU⟩)) 3))) + (le_max_right (K - S) (0 : ℝ)) + have hcall : 0 ≤ ∫ K in κ..U, (2 * (P0 + C) / (δ * (C + K) ^ 3)) * max (S - K) 0 := + intervalIntegral.integral_nonneg hκU fun K hK ↦ + mul_nonneg + (div_nonneg (mul_nonneg two_pos.le hPC) + (mul_nonneg hδ.le (pow_nonneg (le_of_lt (hCKpos K + ⟨hLκ.trans hK.1, hK.2⟩)) 3))) + (le_max_right (S - K) (0 : ℝ)) + linarith + +/-! ### 6. A bond-convexity sign -/ + +/-- **The bond convexity is nonnegative**: each cashflow contributes +`t_i(t_i+1)·c_i/(1+y)^{t_i+2} ≥ 0` for `y > −100%` and nonnegative coupons. +This is the sign of the `P''` exhibited by +`bondPriceDisc_secondDeriv_eq_convexity_times_price`; nothing here connects it +to the CMS rate. -/ +theorem convexityNumerator_nonneg {ι : Type*} (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) + {y : ℝ} (hy : 0 < 1 + y) (hc : ∀ i ∈ s, 0 ≤ c i) : + 0 ≤ convexityNumerator s t c y := by + refine Finset.sum_nonneg fun i hi ↦ ?_ + exact div_nonneg + (mul_nonneg (mul_nonneg (show (0 : ℝ) ≤ (t i : ℝ) from Nat.cast_nonneg (α := ℝ) (t i)) + (by linarith [Nat.cast_nonneg (α := ℝ) (t i)])) (hc i hi)) + (pow_nonneg hy.le (t i + 2)) + +end MathFin.CMS diff --git a/LeanPool/MathFin/Models/Rates/CMSContract.lean b/LeanPool/MathFin/Models/Rates/CMSContract.lean new file mode 100644 index 0000000000..c481da9a7e --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/CMSContract.lean @@ -0,0 +1,489 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.Caplet +public import LeanPool.MathFin.Models.Rates.CMS + +/-! +# CMS contracts, priced under the annuity measure + +A **constant-maturity swap** pays, at a fixing date `T₀`, the then-prevailing par swap rate +`S = (P(T₀, T₀) − P(T₀, Tₙ)) / A(T₀)` of a swap on the dates `T 1, …, T n`, with annuity +`A = δ Σᵢ P(T₀, Tᵢ)`. `S` is a quotient whose meaning needs a positive annuity, so `Payoff` has no +division node: the swap rate is an **observed underlying** `σ`, and `SwapModel` ties it to the bond +prices `P(T₀, Tᵢ)` (observed processes, versions of `bondPrice` of the stochastic discount factor) +and to the annuity, as `BondModel` does for the forward rate of a caplet. + +* The CMS caplet, floorlet and swaplet (`cmsCaplet`, `cmsFloorlet`, `cmsSwaplet`) are one-cash-flow + contracts on `σ`. +* **Annuity-measure pricing.** A payoff `g(S)` paid at `T₀` is worth `A(0) · 𝔼^A[g(S) / A(T₀)]` + (`value_pay_swapRate`), where `𝔼^A` is the annuity measure `swapAnnuityMeasure` and + `A(0) = δ Σ P(0, Tᵢ)` is the annuity of the zero curve. This is `annuityMeasure_price` + (`Models/Rates/CMS.lean`) for the discount factor `D (T 0)`. +* **The forward swap rate is the annuity-measure mean of the swap rate** + (`SwapModel.integral_swapRate`): `𝔼^A[S] = (P(0, T₀) − P(0, Tₙ)) / A(0)`, the par rate of the + zero curve. The annuity repricing condition `𝔼[D · A(T₀)] = A(0)` that makes `Qᴬ` a probability + is the tower property (`SwapModel.integral_annuity_mul`), not a hypothesis. + +## What is not here + +The swap rate is tied to the bond prices by a hypothesis (`rate_eq`) and the bond prices by +`hasBondPrice`; no term-structure model is asserted. Payments at `T₀` only: a CMS rate paid at a +later date `Tₚ` needs the change of measure to the `Tₚ`-forward measure. + +## Main definitions + +* `cmsCaplet`, `cmsFloorlet`, `cmsSwaplet`, `swapCurve`, `SwapModel`, `swapAnnuityMeasure`. + +## Main results + +* `SwapModel.integral_annuity_mul`, + `SwapModel.isProbabilityMeasure`, `value_pay_swapRate`, `value_cmsCaplet`, + `value_cmsFloorlet`, `value_cmsSwaplet`, `SwapModel.integral_swapRate`. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + sections 1.6 and 13.8 +* [P. S. Hagan, *Convexity conundrums: pricing CMS swaps, caps, and floors*][Hagan2003] +* [Musiela and Rutkowski, *Martingale Methods in Financial Modelling*][MusielaRutkowski], ch. 13 + +## Tags + +constant maturity swap, CMS caplet, annuity measure, swap measure, par swap rate, swaption, +MSC 91G30, JEL G12, JEL E43 +-/ + +@[expose] public section + +open MeasureTheory +open scoped NNReal + +namespace MathFin.Contracts + +variable {ι Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-! ### The contracts and the model -/ + +/-- A **CMS caplet**: pays `(S − K)⁺` at the fixing date `T₀`, where the underlying `σ` carries the +par swap rate `S`, observed at `T₀`. -/ +noncomputable def cmsCaplet (σ : ι) (T₀ : ℝ≥0) (K : ℝ) : Contract ι := + .pay T₀ (.max (.sub (.obs σ T₀) (.const K)) (.const 0)) + +/-- A **CMS floorlet**: pays `(K − S)⁺` at the fixing date `T₀`. -/ +noncomputable def cmsFloorlet (σ : ι) (T₀ : ℝ≥0) (K : ℝ) : Contract ι := + .pay T₀ (.max (.sub (.const K) (.obs σ T₀)) (.const 0)) + +/-- A **CMS swaplet**: pays the par swap rate `S` at the fixing date `T₀`. -/ +noncomputable def cmsSwaplet (σ : ι) (T₀ : ℝ≥0) : Contract ι := + .pay T₀ (.obs σ T₀) + +/-- The curve state at the fixing date: `ω ↦ (i ↦ P(T₀, Tᵢ))`, read off the observed bond prices +`b i`. -/ +def swapCurve (X : ι → ℝ≥0 → Ω → ℝ) (b : ℕ → ι) (T₀ : ℝ≥0) : Ω → ℕ → ℝ := + fun ω i ↦ X (b i) T₀ ω + +/-- **A model with a swap rate.** The underlying `b i` carries the bond price `P(T₀, Tᵢ)` at +`T₀ = T 0`, for the payment dates `i = 1, …, n`: a (positive, measurable) version of `bondPrice` +of the stochastic discount factor `D` (`HasBondPrice`), whose value at the fixing date is positive +and integrable. The underlying +`σ` carries the par swap rate at `T₀`, which is the par rate `(1 − P(T₀, Tₙ))/A` of the annuity +`A = δ Σᵢ P(T₀, Tᵢ)` (`parSwapRate`, `annuityRandom`) almost surely. -/ +structure SwapModel (Q : Measure Ω) (𝓕 : Filtration ℝ≥0 mΩ) (D : ℝ≥0 → Ω → ℝ) + (X : ι → ℝ≥0 → Ω → ℝ) (σ : ι) (b : ℕ → ι) (T : ℕ → ℝ≥0) (n : ℕ) (δ : ℝ) : Prop where + δ_pos : 0 < δ + n_pos : 0 < n + hasBondPrice : ∀ i ∈ Finset.Icc 1 n, HasBondPrice Q 𝓕 D X (b i) (T 0) (T i) + D_meas : Measurable (D (T 0)) + integrable_D0 : Integrable (D (T 0)) Q + bond_pos : ∀ ω, ∀ i ∈ Finset.Icc 1 n, 0 < X (b i) (T 0) ω + bond_meas : ∀ i ∈ Finset.Icc 1 n, Measurable (X (b i) (T 0)) + rate_eq : X σ (T 0) =ᵐ[Q] fun ω ↦ parSwapRate 1 (X (b n) (T 0) ω) + (CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω) + +/-- **The annuity measure of a swap model**: `CMS.annuityMeasure` for the discount factor `D (T 0)` +and the curve `P(T₀, ·)`, normalised by the annuity `A(0) = δ Σᵢ P(0, Tᵢ)` of the zero curve. -/ +noncomputable def swapAnnuityMeasure (Q : Measure Ω) (D : ℝ≥0 → Ω → ℝ) (X : ι → ℝ≥0 → Ω → ℝ) + (b : ℕ → ι) (T : ℕ → ℝ≥0) (n : ℕ) (δ : ℝ) : Measure Ω := + CMS.annuityMeasure Q (D (T 0)) δ (swapCurve X b (T 0)) (Finset.Icc 1 n) + (annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n)) + +variable {Q : Measure Ω} [IsProbabilityMeasure Q] {𝓕 : Filtration ℝ≥0 mΩ} {D : ℝ≥0 → Ω → ℝ} + {X : ι → ℝ≥0 → Ω → ℝ} {σ : ι} {b : ℕ → ι} {T : ℕ → ℝ≥0} {n : ℕ} {δ : ℝ} + +/-! ### The tower property, for the curve -/ + +omit [IsProbabilityMeasure Q] in +theorem SwapModel.D_pos (h : SwapModel Q 𝓕 D X σ b T n δ) (ω : Ω) : 0 < D (T 0) ω := + (h.hasBondPrice 1 (Finset.mem_Icc.2 ⟨le_rfl, h.n_pos⟩)).D_pos ω + +omit [IsProbabilityMeasure Q] in +theorem SwapModel.annuity_pos (h : SwapModel Q 𝓕 D X σ b T n δ) (ω : Ω) : + 0 < CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω := + MathFin.annuity_pos h.δ_pos (fun i hi ↦ h.bond_pos ω i hi) + ⟨1, Finset.mem_Icc.2 ⟨le_rfl, h.n_pos⟩⟩ + +omit [IsProbabilityMeasure Q] in +theorem SwapModel.annuity_meas (h : SwapModel Q 𝓕 D X σ b T n δ) : + Measurable (CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n)) := + (Finset.measurable_sum _ h.bond_meas).const_mul δ + +omit [IsProbabilityMeasure Q] in +theorem SwapModel.integrable_annuity_mul (h : SwapModel Q 𝓕 D X σ b T n δ) : + Integrable (fun ω ↦ CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω + * D (T 0) ω) Q := by + have := (integrable_finsetSum _ fun i hi ↦ + (h.hasBondPrice i hi).integrable_discount_mul).const_mul δ + refine this.congr (ae_of_all _ fun ω ↦ ?_) + simp only [CMS.annuityRandom, annuity, swapCurve] + rw [mul_assoc, Finset.sum_mul] + exact congrArg _ (Finset.sum_congr rfl fun i _ ↦ mul_comm _ _) + +/-- **The annuity repricing condition is the tower property**: `𝔼[D (T 0) · A(T₀)] = A(0)`, the +annuity `δ Σᵢ P(0, Tᵢ)` of the zero curve. -/ +theorem SwapModel.integral_annuity_mul (h : SwapModel Q 𝓕 D X σ b T n δ) : + ∫ ω, CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω * D (T 0) ω ∂Q + = annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n) := by + have e : ∀ ω, CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω * D (T 0) ω + = δ * ∑ i ∈ Finset.Icc 1 n, D (T 0) ω * X (b i) (T 0) ω := fun ω ↦ by + simp only [CMS.annuityRandom, annuity, swapCurve] + rw [mul_assoc, Finset.sum_mul] + exact congrArg _ (Finset.sum_congr rfl fun i _ ↦ mul_comm _ _) + simp_rw [e] + rw [integral_const_mul, integral_finsetSum _ fun i hi ↦ + (h.hasBondPrice i hi).integrable_discount_mul, + annuity] + exact congrArg _ (Finset.sum_congr rfl fun i hi ↦ (h.hasBondPrice i hi).integral_discount) + +theorem SwapModel.annuity0_pos (h : SwapModel Q 𝓕 D X σ b T n δ) : + 0 < annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n) := by + rw [← h.integral_annuity_mul] + refine (integral_pos_iff_support_of_nonneg (fun ω ↦ ?_) h.integrable_annuity_mul).2 ?_ + · exact (mul_pos (h.annuity_pos ω) (h.D_pos ω)).le + · rw [show Function.support _ = Set.univ from Set.eq_univ_of_forall fun ω ↦ + (mul_pos (h.annuity_pos ω) (h.D_pos ω)).ne'] + simp + +/-- **The annuity measure of a swap model is a probability measure.** -/ +theorem SwapModel.isProbabilityMeasure (h : SwapModel Q 𝓕 D X σ b T n δ) : + IsProbabilityMeasure (swapAnnuityMeasure Q D X b T n δ) := + CMS.annuityMeasure_isProbabilityMeasure (D (T 0)) δ _ _ _ h.D_pos h.δ_pos + ⟨1, Finset.mem_Icc.2 ⟨le_rfl, h.n_pos⟩⟩ h.bond_pos h.annuity0_pos h.integrable_annuity_mul + h.integral_annuity_mul + +/-! ### Annuity-measure pricing of a payoff on the swap rate -/ + +/-- **Annuity-measure pricing in a swap model**: `A(0) · 𝔼^A[S] = 𝔼[D (T 0) · S · A(T₀)]`, the +annuity-settled payoff `S · A(T₀)` (`annuityMeasure_price`). -/ +theorem SwapModel.annuity0_mul_integral (h : SwapModel Q 𝓕 D X σ b T n δ) (S : Ω → ℝ) : + annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n) + * ∫ ω, S ω ∂(swapAnnuityMeasure Q D X b T n δ) + = ∫ ω, D (T 0) ω + * (S ω * CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω) ∂Q := + CMS.annuityMeasure_price (D (T 0)) δ (swapCurve X b (T 0)) (Finset.Icc 1 n) _ S h.D_pos + h.D_meas h.δ_pos ⟨1, Finset.mem_Icc.2 ⟨le_rfl, h.n_pos⟩⟩ h.bond_pos h.annuity0_pos + h.annuity_meas + +/-- **A payoff on the swap rate, paid at the fixing date, is an annuity-measure expectation.** If +`φ` is `g` of the swap rate observed at `T₀`, the contract paying `φ` at `T₀` is worth +`A(0) · 𝔼^A[g(S) / A(T₀)]`: `annuityMeasure_price` with the annuity-settled payoff `g(S)`. -/ +theorem value_pay_swapRate (h : SwapModel Q 𝓕 D X σ b T n δ) {φ : Payoff ι} {g : ℝ → ℝ} + (hφ : ∀ s : Scenario ι, φ.eval s = g (s σ (T 0))) : + (Contract.pay (T 0) φ).value Q D X + = annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n) + * ∫ ω, g (X σ (T 0) ω) / CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω + ∂(swapAnnuityMeasure Q D X b T n δ) := by + rw [h.annuity0_mul_integral + (fun ω ↦ g (X σ (T 0) ω) / CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω), + Contract.value_pay] + refine integral_congr_ae (ae_of_all _ fun ω ↦ ?_) + beta_reduce + rw [hφ, div_mul_cancel₀ _ (h.annuity_pos ω).ne'] + rfl + +/-- **A CMS caplet is an annuity-measure call on the swap rate**: the caplet paying `(S − K)⁺` at +`T₀` is worth `A(0) · 𝔼^A[(S − K)⁺ / A(T₀)]`. -/ +theorem value_cmsCaplet (h : SwapModel Q 𝓕 D X σ b T n δ) (K : ℝ) : + (cmsCaplet σ (T 0) K).value Q D X + = annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n) + * ∫ ω, max (X σ (T 0) ω - K) 0 + / CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω + ∂(swapAnnuityMeasure Q D X b T n δ) := + value_pay_swapRate h (g := fun x ↦ max (x - K) 0) fun _ ↦ rfl + +/-- **A CMS floorlet is an annuity-measure put on the swap rate**: the floorlet paying `(K − S)⁺` +at `T₀` is worth `A(0) · 𝔼^A[(K − S)⁺ / A(T₀)]`. -/ +theorem value_cmsFloorlet (h : SwapModel Q 𝓕 D X σ b T n δ) (K : ℝ) : + (cmsFloorlet σ (T 0) K).value Q D X + = annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n) + * ∫ ω, max (K - X σ (T 0) ω) 0 + / CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω + ∂(swapAnnuityMeasure Q D X b T n δ) := + value_pay_swapRate h (g := fun x ↦ max (K - x) 0) fun _ ↦ rfl + +/-- **A CMS swaplet is worth `A(0) · 𝔼^A[S / A(T₀)]`.** -/ +theorem value_cmsSwaplet (h : SwapModel Q 𝓕 D X σ b T n δ) : + (cmsSwaplet σ (T 0)).value Q D X + = annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n) + * ∫ ω, X σ (T 0) ω / CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω + ∂(swapAnnuityMeasure Q D X b T n δ) := + value_pay_swapRate h (g := id) fun _ ↦ rfl + +/-! ### The forward swap rate -/ + +/-- **The forward swap rate is the annuity-measure mean of the swap rate**: +`𝔼^A[S] = (P(0, T₀) − P(0, Tₙ)) / A(0)`, the par swap rate of the zero curve (`parSwapRate`). +No adjustment at the fixing date: the `Qᴬ`-mean of the swap rate is the time-0 par rate. -/ +theorem SwapModel.integral_swapRate (h : SwapModel Q 𝓕 D X σ b T n δ) : + ∫ ω, X σ (T 0) ω ∂(swapAnnuityMeasure Q D X b T n δ) + = parSwapRate (zeroCurve Q D (T 0)) (zeroCurve Q D (T n)) + (annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n)) := by + have hn : n ∈ Finset.Icc 1 n := Finset.mem_Icc.2 ⟨h.n_pos, le_rfl⟩ + rw [parSwapRate, eq_div_iff h.annuity0_pos.ne', mul_comm, h.annuity0_mul_integral] + have e : ∀ᵐ ω ∂Q, D (T 0) ω * (X σ (T 0) ω + * CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω) + = D (T 0) ω - D (T 0) ω * X (b n) (T 0) ω := by + filter_upwards [h.rate_eq] with ω hω + rw [hω, parSwapRate, div_mul_cancel₀ _ (h.annuity_pos ω).ne'] + ring + rw [integral_congr_ae e, integral_sub (h.integrable_D0) + ((h.hasBondPrice n hn).integrable_discount_mul), (h.hasBondPrice n hn).integral_discount] + rfl + +/-! ### The convexity adjustment, for a rate paid at its fixing date -/ + +section Adjustment + +variable {c : ℕ → ℝ} + +omit [IsProbabilityMeasure Q] in +/-- When the bond prices other than the last are known constants `c i`, the annuity is +`δ (C + P(T₀, Tₙ))`, `C = Σ c i`. -/ +theorem SwapModel.annuity_ae_eq (h : SwapModel Q 𝓕 D X σ b T n δ) + (hc : ∀ i ∈ (Finset.Icc 1 n).erase n, ∀ᵐ ω ∂Q, X (b i) (T 0) ω = c i) : + CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) =ᵐ[Q] fun ω ↦ + δ * ((∑ i ∈ (Finset.Icc 1 n).erase n, c i) + X (b n) (T 0) ω) := by + have hn : n ∈ Finset.Icc 1 n := Finset.mem_Icc.2 ⟨h.n_pos, le_rfl⟩ + filter_upwards [(Filter.eventually_all_finset _).2 hc] with ω hω' + have hsum : ∑ i ∈ Finset.Icc 1 n, swapCurve X b (T 0) ω i + = (∑ i ∈ (Finset.Icc 1 n).erase n, c i) + X (b n) (T 0) ω := by + rw [← Finset.sum_erase_add _ _ hn] + exact congrArg (· + _) (Finset.sum_congr rfl hω') + simp only [CMS.annuityRandom, annuity, hsum] + +omit [IsProbabilityMeasure Q] in +/-- The swap rate is the `cmsCurveRate` of the last bond price when the other bond prices are +known constants: the bridge to the Jensen-gap results of `CMS.lean`. -/ +theorem SwapModel.rate_eq_cmsCurveRate (h : SwapModel Q 𝓕 D X σ b T n δ) + (hc : ∀ i ∈ (Finset.Icc 1 n).erase n, ∀ᵐ ω ∂Q, X (b i) (T 0) ω = c i) : + X σ (T 0) =ᵐ[Q] fun ω ↦ + CMS.cmsCurveRate 1 δ (∑ i ∈ (Finset.Icc 1 n).erase n, c i) (X (b n) (T 0) ω) := by + filter_upwards [h.rate_eq, h.annuity_ae_eq hc] with ω hω hA + rw [hω, parSwapRate, hA] + rfl + +/-- **The swap rate at the mean final bond price is at most the forward swap rate** (the Jensen +gap of the rate functional, for the contract's underlying). If the bond prices other than +`P(T₀, Tₙ)` are known constants `c i`, `C = Σ c i > 0`, then +`cmsCurveRate 1 δ C (𝔼^A[P(T₀, Tₙ)]) ≤ 𝔼^A[S] = (P(0, T₀) − P(0, Tₙ))/A(0)`: +`cmsCurveRate_jensenGap_nonneg` of `Models/Rates/CMS.lean` with `x₀` the annuity-measure mean. -/ +theorem SwapModel.cmsCurveRate_integral_le_forwardSwapRate (h : SwapModel Q 𝓕 D X σ b T n δ) + (hc : ∀ i ∈ (Finset.Icc 1 n).erase n, ∀ᵐ ω ∂Q, X (b i) (T 0) ω = c i) + (hC : 0 < ∑ i ∈ (Finset.Icc 1 n).erase n, c i) + (hW : Integrable (X (b n) (T 0)) (swapAnnuityMeasure Q D X b T n δ)) + (hS : Integrable (X σ (T 0)) (swapAnnuityMeasure Q D X b T n δ)) : + CMS.cmsCurveRate 1 δ (∑ i ∈ (Finset.Icc 1 n).erase n, c i) + (∫ ω, X (b n) (T 0) ω ∂(swapAnnuityMeasure Q D X b T n δ)) + ≤ parSwapRate (zeroCurve Q D (T 0)) (zeroCurve Q D (T n)) + (annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n)) := by + have := h.isProbabilityMeasure + have hn : n ∈ Finset.Icc 1 n := Finset.mem_Icc.2 ⟨h.n_pos, le_rfl⟩ + have hac : swapAnnuityMeasure Q D X b T n δ ≪ Q := withDensity_absolutelyContinuous _ _ + have hae := hac.ae_eq (h.rate_eq_cmsCurveRate hc) + have hj : CMS.cmsCurveRate 1 δ (∑ i ∈ (Finset.Icc 1 n).erase n, c i) + (∫ ω, X (b n) (T 0) ω ∂(swapAnnuityMeasure Q D X b T n δ)) + ≤ ∫ ω, CMS.cmsCurveRate 1 δ (∑ i ∈ (Finset.Icc 1 n).erase n, c i) (X (b n) (T 0) ω) + ∂(swapAnnuityMeasure Q D X b T n δ) := CMS.cmsCurveRate_jensenGap_nonneg (D (T 0)) δ 1 + (∑ i ∈ (Finset.Icc 1 n).erase n, c i) _ _ (swapCurve X b (T 0)) (Finset.Icc 1 n) + (X (b n) (T 0)) h.D_pos h.δ_pos hC (by linarith) ⟨1, Finset.mem_Icc.2 ⟨le_rfl, h.n_pos⟩⟩ + h.bond_pos h.annuity0_pos h.integrable_annuity_mul h.integral_annuity_mul + (fun ω ↦ (h.bond_pos ω n hn).le) hW (hS.congr hae) rfl + rwa [← integral_congr_ae hae, h.integral_swapRate] at hj + +/-- **The mean of the reciprocal annuity**: `A(0) · 𝔼^A[1 / A(T₀)] = P(0, T₀)`. -/ +theorem SwapModel.annuity0_mul_integral_inv (h : SwapModel Q 𝓕 D X σ b T n δ) : + annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n) + * ∫ ω, (CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω)⁻¹ + ∂(swapAnnuityMeasure Q D X b T n δ) = zeroCurve Q D (T 0) := by + rw [h.annuity0_mul_integral + (fun ω ↦ (CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω)⁻¹)] + exact integral_congr_ae (ae_of_all _ fun ω ↦ by + beta_reduce + rw [inv_mul_cancel₀ (h.annuity_pos ω).ne', mul_one]) + +/-- **The CMS swaplet, paid at its fixing date, is the forward swap rate plus a covariance.** +`value = P(0, T₀) · S₀ + A(0) · Cov^A(S, 1/A(T₀))`, with `S₀` the forward swap rate and the +covariance written out: the contract is worth `A(0) 𝔼^A[S/A]`, and `A(0) 𝔼^A[1/A] = P(0, T₀)`, +`𝔼^A[S] = S₀`. -/ +theorem SwapModel.value_cmsSwaplet_eq (h : SwapModel Q 𝓕 D X σ b T n δ) : + (cmsSwaplet σ (T 0)).value Q D X + = zeroCurve Q D (T 0) * parSwapRate (zeroCurve Q D (T 0)) (zeroCurve Q D (T n)) + (annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n)) + + annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n) + * (∫ ω, X σ (T 0) ω / CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω + ∂(swapAnnuityMeasure Q D X b T n δ) + - (∫ ω, X σ (T 0) ω ∂(swapAnnuityMeasure Q D X b T n δ)) + * ∫ ω, (CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω)⁻¹ + ∂(swapAnnuityMeasure Q D X b T n δ)) := by + rw [value_cmsSwaplet h, ← h.integral_swapRate, ← h.annuity0_mul_integral_inv] + ring + +/-- **The convexity adjustment of a CMS swaplet paid at its fixing date is nonnegative.** If the +bond prices other than `P(T₀, Tₙ)` are known constants, the swap rate is affine in the reciprocal +annuity, `S = (1 + C)/A − 1/δ` (`C = Σ c i`, `1 + C ≥ 0`), so +`Cov^A(S, 1/A) = (1 + C) Var^A(1/A) ≥ 0`: the swaplet is worth at least `P(0, T₀)` times the forward +swap rate. The reciprocal annuity is assumed square-integrable under the annuity measure. -/ +theorem SwapModel.zeroCurve_mul_forwardSwapRate_le_value_cmsSwaplet + (h : SwapModel Q 𝓕 D X σ b T n δ) + (hc : ∀ i ∈ (Finset.Icc 1 n).erase n, ∀ᵐ ω ∂Q, X (b i) (T 0) ω = c i) + (hC : 0 ≤ 1 + ∑ i ∈ (Finset.Icc 1 n).erase n, c i) + (hg : Integrable (fun ω ↦ + (CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω)⁻¹) + (swapAnnuityMeasure Q D X b T n δ)) + (hg2 : Integrable (fun ω ↦ + (CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω)⁻¹ ^ 2) + (swapAnnuityMeasure Q D X b T n δ)) : + zeroCurve Q D (T 0) * parSwapRate (zeroCurve Q D (T 0)) (zeroCurve Q D (T n)) + (annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n)) + ≤ (cmsSwaplet σ (T 0)).value Q D X := by + have := h.isProbabilityMeasure + set A := CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) with hA + set μ := swapAnnuityMeasure Q D X b T n δ with hμ + set C := ∑ i ∈ (Finset.Icc 1 n).erase n, c i + have hac : μ ≪ Q := withDensity_absolutelyContinuous _ _ + -- the swap rate is affine in `1/A` + have hS : X σ (T 0) =ᵐ[μ] fun ω ↦ (1 + C) * (A ω)⁻¹ - δ⁻¹ := by + refine hac.ae_eq ?_ + filter_upwards [h.rate_eq, h.annuity_ae_eq hc] with ω hω hAω + have hδ := h.δ_pos.ne' + have hAp : A ω ≠ 0 := (h.annuity_pos ω).ne' + rw [hω, parSwapRate] + change (1 - X (b n) (T 0) ω) / A ω = _ + have hW : X (b n) (T 0) ω = A ω / δ - C := by + field_simp + linarith [hAω] + rw [hW] + field_simp + ring + have hSA : (fun ω ↦ X σ (T 0) ω / A ω) =ᵐ[μ] fun ω ↦ (1 + C) * (A ω)⁻¹ ^ 2 - δ⁻¹ * (A ω)⁻¹ := by + filter_upwards [hS] with ω hω + rw [hω, div_eq_mul_inv] + ring + set I := ∫ ω, (A ω)⁻¹ ∂μ + have hJ : ∫ ω, X σ (T 0) ω ∂μ = (1 + C) * I - δ⁻¹ := by + rw [integral_congr_ae hS, integral_sub (hg.const_mul _) (integrable_const _), + integral_const_mul, integral_const, probReal_univ, one_smul] + have hK : ∫ ω, X σ (T 0) ω / A ω ∂μ = (1 + C) * ∫ ω, (A ω)⁻¹ ^ 2 ∂μ - δ⁻¹ * I := by + rw [integral_congr_ae hSA, integral_sub (hg2.const_mul _) (hg.const_mul _), + integral_const_mul, integral_const_mul] + have hvar : 0 ≤ ∫ ω, (A ω)⁻¹ ^ 2 ∂μ - I ^ 2 := by + have hm : MemLp (fun ω ↦ (A ω)⁻¹) 2 μ := + (memLp_two_iff_integrable_sq h.annuity_meas.inv.aestronglyMeasurable).2 hg2 + have := ProbabilityTheory.variance_nonneg (fun ω ↦ (A ω)⁻¹) μ + rwa [ProbabilityTheory.variance_eq_sub hm] at this + rw [h.value_cmsSwaplet_eq] + refine le_add_of_nonneg_right (mul_nonneg h.annuity0_pos.le ?_) + rw [hK, hJ] + nlinarith [mul_nonneg hC hvar] + +end Adjustment + +/-! ### The payer swaption, and Black's formula -/ + +/-- The sum `Σᵢ₌₁ⁿ` of the observations `b i` at time `t`, as a payoff. -/ +noncomputable def Payoff.obsSum (b : ℕ → ι) (t : ℝ≥0) : ℕ → Payoff ι + | 0 => .const 0 + | k + 1 => .add (obsSum b t k) (.obs (b (k + 1)) t) + +theorem Payoff.eval_obsSum (s : Scenario ι) (b : ℕ → ι) (t : ℝ≥0) (n : ℕ) : + (Payoff.obsSum b t n).eval s = ∑ i ∈ Finset.Icc 1 n, s (b i) t := by + induction n with + | zero => simp [Payoff.obsSum, Payoff.eval] + | succ k ih => + rw [Finset.sum_Icc_succ_top (by omega), ← ih] + simp [Payoff.obsSum, Payoff.eval] + +/-- A **payer swaption**: pays, at the expiry `T₀`, the positive part of the value of the payer +swap on the dates `T 1, …, T n` with fixed rate `K` and accrual `δ`, +`(1 − P(T₀, Tₙ) − K δ Σᵢ P(T₀, Tᵢ))⁺` (`payerSwapValue`), where `b i` carries `P(T₀, Tᵢ)`. -/ +noncomputable def payerSwaption (b : ℕ → ι) (T₀ : ℝ≥0) (n : ℕ) (δ K : ℝ) : Contract ι := + .pay T₀ (.max (.sub (.sub (.const 1) (.obs (b n) T₀)) + (.mul (.const (K * δ)) (Payoff.obsSum b T₀ n))) (.const 0)) + +/-- **A payer swaption is `A(0)` times an annuity-measure call on the swap rate**: +`value = A(0) · 𝔼^A[(S − K)⁺]`. The payoff is `A(T₀)(S − K)⁺`, the annuity-settled payoff of +`annuityMeasure_price`. -/ +theorem value_payerSwaption (h : SwapModel Q 𝓕 D X σ b T n δ) (K : ℝ) : + (payerSwaption b (T 0) n δ K).value Q D X + = annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n) + * ∫ ω, max (X σ (T 0) ω - K) 0 ∂(swapAnnuityMeasure Q D X b T n δ) := by + rw [h.annuity0_mul_integral (fun ω ↦ max (X σ (T 0) ω - K) 0)] + simp only [payerSwaption, Contract.value_pay, Payoff.eval, Payoff.eval_obsSum, scenarioAt] + refine integral_congr_ae ?_ + filter_upwards [h.rate_eq] with ω hω + have hA := h.annuity_pos ω + have hAe : CMS.annuityRandom δ (swapCurve X b (T 0)) (Finset.Icc 1 n) ω + = δ * ∑ i ∈ Finset.Icc 1 n, X (b i) (T 0) ω := rfl + congr 1 + rw [max_mul_of_nonneg _ _ hA.le, zero_mul] + congr 1 + rw [hω, parSwapRate, sub_mul, div_mul_cancel₀ _ hA.ne', hAe] + ring + +/-- **Black's swaption formula.** If the swap rate is lognormal under the annuity measure `Qᴬ`, +`S = bsTerminal F 0 σ' T' Z` with `Z` standard normal there, the payer swaption is worth +`blackPayerSwaption A(0) F K σ' T'`, `A(0) [F Φ(d₁) − K Φ(d₂)]`; `black_futures_formula` on `Qᴬ`. +The lognormality of the swap rate under its annuity measure is a hypothesis, the standard +assumption of Black's swaption model, and not derived from a term-structure model. -/ +theorem value_payerSwaption_black (h : SwapModel Q 𝓕 D X σ b T n δ) + {Q' : Measure Ω} [IsProbabilityMeasure Q'] + (hQ' : Q' = swapAnnuityMeasure Q D X b T n δ) {F K σ' T' : ℝ} {Z : Ω → ℝ} + (hZ : BSCallHyp Q' F K 0 σ' T' Z) + (hS : X σ (T 0) =ᵐ[Q'] fun ω ↦ bsTerminal F 0 σ' T' (Z ω)) : + (payerSwaption b (T 0) n δ K).value Q D X + = blackPayerSwaption (annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n)) + F K σ' T' := by + subst hQ' + have e : ∀ᵐ ω ∂swapAnnuityMeasure Q D X b T n δ, max (X σ (T 0) ω - K) 0 + = max (bsTerminal F 0 σ' T' (Z ω) - K) 0 := hS.mono fun ω hω ↦ by rw [hω] + rw [value_payerSwaption h, integral_congr_ae e, blackPayerSwaption] + simpa using congrArg (annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n) * ·) + (black_futures_formula hZ 0) + +/-- **Black's swaption formula, at the forward swap rate of the zero curve.** Under the +hypotheses of `value_payerSwaption_black`, `F` is the par swap rate of the zero curve, +`(P(0, T₀) − P(0, Tₙ))/A(0)`: the annuity-measure mean of a lognormal is its centre. -/ +theorem value_payerSwaption_black_forwardSwapRate (h : SwapModel Q 𝓕 D X σ b T n δ) + {Q' : Measure Ω} [IsProbabilityMeasure Q'] + (hQ' : Q' = swapAnnuityMeasure Q D X b T n δ) {K σ' T' F : ℝ} {Z : Ω → ℝ} + (hZ : BSCallHyp Q' F K 0 σ' T' Z) + (hS : X σ (T 0) =ᵐ[Q'] fun ω ↦ bsTerminal F 0 σ' T' (Z ω)) : + (payerSwaption b (T 0) n δ K).value Q D X + = blackPayerSwaption (annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n)) + (parSwapRate (zeroCurve Q D (T 0)) (zeroCurve Q D (T n)) + (annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n))) K σ' T' := by + have hF : F = parSwapRate (zeroCurve Q D (T 0)) (zeroCurve Q D (T n)) + (annuity δ (fun i ↦ zeroCurve Q D (T i)) (Finset.Icc 1 n)) := by + rw [← h.integral_swapRate, ← hQ', integral_congr_ae hS] + simpa using (discounted_terminal_eq_S0 hZ).symm + rw [← hF] + exact value_payerSwaption_black h hQ' hZ hS + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Models/Rates/Caplet.lean b/LeanPool/MathFin/Models/Rates/Caplet.lean new file mode 100644 index 0000000000..8a961e4729 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/Caplet.lean @@ -0,0 +1,326 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.Forward +public import LeanPool.MathFin.Models.Rates.ShortRate +public import LeanPool.MathFin.Models.Rates.FRA +public import LeanPool.MathFin.Pricing.ForwardMeasure +public import LeanPool.MathFin.Models.Forwards.Black76 +public import LeanPool.MathFin.Pricing.Market + +/-! +# Caplets and caps, on the bond prices of a stochastic discount factor + +`bondPrice Q 𝓕 D t T = 𝔼_Q[D T | 𝓕 t] / D t` is the zero-coupon bond price `P(t, T)` at time +`t`, for any stochastic discount factor `D`: the bond prices that floating payoffs need. A +model `X` carries them as observed processes. `BondModel` says the underlying `b` is +`P(T₀, T₁)` at `T₀` (a.e.) and `ℓ` is the simple forward rate it implies, +`L = (1/P − 1)/δ` (`fraForwardRate 1 P δ`), adapted to the information at `T₀`. + +* A **caplet** pays `δ (L(T₀, T₁) − K)⁺` at `T₁` (`caplet`, a one-cash-flow `Contract`). In + every `BondModel` it is worth `(1 + δK)` puts on `P(T₀, T₁)`, struck at `1/(1 + δK)` and + expiring at `T₀` (`value_caplet_eq_bondPut`): the tower property turns the discount factor + `D T₁` into `D T₀ · P(T₀, T₁)`, and `P · δ (L − K)⁺ = (1 − (1 + δK) P)⁺`. +* A **cap** is its schedule of caplets (`cap`), worth their sum (`value_cap`), hence + `(1 + δK)` times a strip of bond puts (`value_cap_eq_bondPuts`). +* **Black-76.** If `L(T₀, T₁)` is lognormal under the `T₁`-forward measure + (`forwardMeasure`), the caplet is worth `P(0, T₁) · blackCaplet F K σ T δ` + (`value_caplet_black76`), consuming `black_futures_formula` and the change of numéraire + `forwardMeasure_price`; with a `BondModel`, `F` is the forward rate of the zero curve + (`BondModel.integral_libor_forward`, `value_caplet_black76_forwardRate`). + +## What is not here + +Lognormality of `L` under the forward measure is a hypothesis here. It does not hold in the +Gaussian short-rate models (a remark, not a theorem here): the bond `P` is lognormal +(`bondPrice_vasicek`, `bondPrice_hullWhite`), so `L = (1/P − 1)/δ` is a shifted lognormal. There +the caplet is priced through the bond put, as a Black put on the lognormal bond +(`Models/Rates/Jamshidian.lean`), in the Vasicek, Hull–White and two-piece GSR models. CMS +rates and swaptions are in `Models/Rates/CMSContract.lean`: a swap rate is a ratio of bond-price +sums, +which `Payoff` cannot express, so it is an observed underlying tied to the bond prices by a model +hypothesis. + +## Main definitions + +* `bondPrice`, `HasBondPrice` (the bond price alone), `BondModel` (with the forward rate), + `capletPayoff`, `caplet`, `bondPut`, `cap`. + +## Main results + +* `integral_discount_mul_eq_forward` (pricing at the forward measure), + `HasBondPrice.integral_discount` and `HasBondPrice.integral_discount_mul` (the tower property), + `bond_mul_capletPayoff`, `value_caplet_eq_bondPut`, `value_cap`, + `value_cap_eq_bondPuts`, `value_caplet_black76`, `BondModel.integral_libor_forward`, + `value_caplet_black76_forwardRate`. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + sections 1.4 and 1.5 +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], ch. 29 +* [Musiela and Rutkowski, *Martingale Methods in Financial Modelling*][MusielaRutkowski], ch. 12 + +## Tags + +caplet, interest rate cap, LIBOR, Black-76, forward measure, bond put, forward rate, MSC 91G30, +JEL G13, JEL E43 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory +open scoped NNReal + +namespace MathFin.Contracts + +variable {ι Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-! ### The bond price at time `t`, and the caplet as a contract -/ + +/-- The **zero-coupon bond price at time `t`** under the stochastic discount factor `D`: +`P(t, T) = 𝔼_Q[D T | 𝓕 t] / D t`, the value at `t` of one unit paid at `T`. At `t = 0` with +`D 0 = 1` and a trivial `𝓕 0` it is the zero curve `zeroCurve Q D T`. -/ +noncomputable def bondPrice (Q : Measure Ω) (𝓕 : Filtration ℝ≥0 mΩ) (D : ℝ≥0 → Ω → ℝ) + (t T : ℝ≥0) : Ω → ℝ := + fun ω ↦ (Q[D T | 𝓕 t]) ω / D t ω + +/-- **The bond price is the price at `t` of one unit paid at `T`**: in a market whose deflator +`N 0 / N t` is the discount factor, `P(t, T)` is `Market.priceAt` of the payment of `1` at `T`. -/ +theorem bondPrice_deflator_eq_priceAt (M : Market ι Ω) (Q : Measure Ω) (t T : ℝ≥0) : + bondPrice Q M.𝓕 M.deflator t T = M.priceAt Q t (.pay T (.const 1)) := by + funext ω + simp [Market.priceAt, bondPrice, Contract.pathPV, Contract.cashflows, Payoff.eval] + +/-- The payoff of a **caplet**: `δ (L − K)⁺`, where the underlying `ℓ` carries the +simply-compounded forward rate `L(T₀, T₁)`, observed at its reset date `T₀`. -/ +noncomputable def capletPayoff (ℓ : ι) (T₀ : ℝ≥0) (δ K : ℝ) : Payoff ι := + .mul (.const δ) (.max (.sub (.obs ℓ T₀) (.const K)) (.const 0)) + +/-- A **caplet**: pays `δ (L(T₀, T₁) − K)⁺` at `T₁`, with accrual `δ` and rate `L` observed at +`T₀`. -/ +noncomputable def caplet (ℓ : ι) (T₀ T₁ : ℝ≥0) (δ K : ℝ) : Contract ι := + .pay T₁ (capletPayoff ℓ T₀ δ K) + +/-- A **put on a zero-coupon bond**: pays `(k − P(T, ·))⁺` at its expiry `T`, where the +underlying `b` carries the bond price observed at `T`. -/ +noncomputable def bondPut (b : ι) (T : ℝ≥0) (k : ℝ) : Contract ι := + .pay T (.max (.sub (.const k) (.obs b T)) (.const 0)) + +/-- A **cap**: the schedule of caplets with reset dates `T 0, …, T (n − 1)`, caplet `i` paying +`δ (Lᵢ − K)⁺` at `T (i + 1)`, where `ℓ i` carries the rate `L(T i, T (i + 1))`. -/ +noncomputable def cap (ℓ : ℕ → ι) (T : ℕ → ℝ≥0) (δ K : ℝ) (n : ℕ) : Contract ι := + payFlows (fun i ↦ T (i + 1)) (fun i ↦ capletPayoff (ℓ i) (T i) δ K) n + +/-- **A model with a bond price.** The underlying `b` carries the bond price `P(T₀, T₁)` at `T₀`, +the conditional expectation `bondPrice` of the stochastic discount factor `D` given the +information `𝓕`, as a process of the model `X`. -/ +structure HasBondPrice (Q : Measure Ω) (𝓕 : Filtration ℝ≥0 mΩ) (D : ℝ≥0 → Ω → ℝ) + (X : ι → ℝ≥0 → Ω → ℝ) (b : ι) (T₀ T₁ : ℝ≥0) : Prop where + D_pos : ∀ ω, 0 < D T₀ ω + integrable_D : Integrable (D T₁) Q + bond_eq : X b T₀ =ᵐ[Q] bondPrice Q 𝓕 D T₀ T₁ + +/-- **A model with bond prices and forward rates.** Besides the bond price `P(T₀, T₁)`, the +process `ℓ` carries the simply-compounded forward rate `L(T₀, T₁) = (1/P(T₀, T₁) − 1)/δ` it +implies, adapted to the information `𝓕 T₀`. -/ +structure BondModel (Q : Measure Ω) (𝓕 : Filtration ℝ≥0 mΩ) (D : ℝ≥0 → Ω → ℝ) + (X : ι → ℝ≥0 → Ω → ℝ) (b ℓ : ι) (T₀ T₁ : ℝ≥0) (δ : ℝ) : Prop + extends HasBondPrice Q 𝓕 D X b T₀ T₁ where + δ_pos : 0 < δ + bond_pos : ∀ᵐ ω ∂Q, 0 < X b T₀ ω + libor_eq : X ℓ T₀ =ᵐ[Q] fun ω ↦ fraForwardRate 1 (X b T₀ ω) δ + libor_meas : StronglyMeasurable[𝓕 T₀] (X ℓ T₀) + +variable {Q : Measure Ω} [IsProbabilityMeasure Q] {𝓕 : Filtration ℝ≥0 mΩ} {D : ℝ≥0 → Ω → ℝ} + {X : ι → ℝ≥0 → Ω → ℝ} {b ℓ : ι} {T₀ T₁ : ℝ≥0} {δ : ℝ} + +/-- **Pricing at the forward measure.** For a positive integrable discount factor `D₀`, its +expectation is positive, and `𝔼[D₀ · Y] = 𝔼[D₀]·𝔼^{Q^{D₀}}[Y]` for the forward measure +`forwardMeasure Q (1/D₀)`: the change of numéraire `forwardMeasure_price`, written for the +discount factor instead of the bank account. -/ +theorem integral_discount_mul_eq_forward {D₀ : Ω → ℝ} (hD : ∀ ω, 0 < D₀ ω) + (hDm : Measurable D₀) (hDi : Integrable D₀ Q) (Y : Ω → ℝ) : + 0 < ∫ ω, D₀ ω ∂Q ∧ (∫ ω, D₀ ω ∂Q) * ∫ ω, Y ω ∂(forwardMeasure Q fun ω ↦ 1 / D₀ ω) + = ∫ ω, D₀ ω * Y ω ∂Q := by + have hB : ∀ ω, 0 < 1 / D₀ ω := fun ω ↦ one_div_pos.2 (hD ω) + have e1 : ∫ ω, 1 / (1 / D₀ ω) ∂Q = ∫ ω, D₀ ω ∂Q := by simp + have hP0 := integral_one_div_pos (Q := Q) hB (by simpa using hDi) + rw [e1] at hP0 + have key := forwardMeasure_price (Q := Q) (B := fun ω ↦ 1 / D₀ ω) Y + (measurable_const.div hDm) hB (by simpa using hP0) + rw [e1] at key + refine ⟨hP0, key.trans (integral_congr_ae <| ae_of_all _ fun ω ↦ ?_)⟩ + field_simp [(hD ω).ne'] + +omit [IsProbabilityMeasure Q] in +/-- **A discounted bond price is the discount factor at the payment date, in expectation**: +`D T₀ · P(T₀, T₁)` is a version of `𝔼[D T₁ | 𝓕 T₀]`. -/ +theorem HasBondPrice.discount_mul_ae (h : HasBondPrice Q 𝓕 D X b T₀ T₁) : + (fun ω ↦ D T₀ ω * X b T₀ ω) =ᵐ[Q] Q[D T₁ | 𝓕 T₀] := by + filter_upwards [h.bond_eq] with ω hω + rw [hω, bondPrice] + field_simp [(h.D_pos ω).ne'] + +omit [IsProbabilityMeasure Q] in +theorem HasBondPrice.integrable_discount_mul (h : HasBondPrice Q 𝓕 D X b T₀ T₁) : + Integrable (fun ω ↦ D T₀ ω * X b T₀ ω) Q := + (integrable_condExp (m := 𝓕 T₀) (f := D T₁)).congr h.discount_mul_ae.symm + +/-- **The tower property**: `𝔼[D T₀ · P(T₀, T₁)] = P(0, T₁)`, the zero curve. -/ +theorem HasBondPrice.integral_discount (h : HasBondPrice Q 𝓕 D X b T₀ T₁) : + ∫ ω, D T₀ ω * X b T₀ ω ∂Q = zeroCurve Q D T₁ := by + rw [integral_congr_ae h.discount_mul_ae, integral_condExp (𝓕.le T₀)] + rfl + +/-- **The bond price turns `D T₁` into `D T₀`**: for an `𝓕 T₀`-measurable `Y`, +`𝔼[D T₁ · Y] = 𝔼[D T₀ · P(T₀, T₁) · Y]`. -/ +theorem HasBondPrice.integral_discount_mul (h : HasBondPrice Q 𝓕 D X b T₀ T₁) {Y : Ω → ℝ} + (hY : StronglyMeasurable[𝓕 T₀] Y) (hDY : Integrable (fun ω ↦ D T₁ ω * Y ω) Q) : + ∫ ω, D T₁ ω * Y ω ∂Q = ∫ ω, D T₀ ω * X b T₀ ω * Y ω ∂Q := by + have hcond : Q[fun ω ↦ Y ω * D T₁ ω | 𝓕 T₀] =ᵐ[Q] fun ω ↦ Y ω * (Q[D T₁ | 𝓕 T₀]) ω := + condExp_mul_of_stronglyMeasurable_left hY + (hDY.congr (ae_of_all _ fun ω ↦ mul_comm _ _)) h.integrable_D + calc ∫ ω, D T₁ ω * Y ω ∂Q = ∫ ω, Y ω * D T₁ ω ∂Q := by simp_rw [mul_comm] + _ = ∫ ω, (Q[fun ω ↦ Y ω * D T₁ ω | 𝓕 T₀]) ω ∂Q := (integral_condExp (𝓕.le T₀)).symm + _ = ∫ ω, Y ω * (Q[D T₁ | 𝓕 T₀]) ω ∂Q := integral_congr_ae hcond + _ = ∫ ω, D T₀ ω * X b T₀ ω * Y ω ∂Q := integral_congr_ae <| by + filter_upwards [h.discount_mul_ae] with ω hω + rw [hω]; ring + +/-- **The caplet payoff, valued at its reset date, is a bond put**: when `δ L = 1/P - 1`, +`P · δ (L - K)⁺ = (1 + δK) (1/(1 + δK) - P)⁺`. -/ +lemma bond_mul_capletPayoff {P δ K : ℝ} (hP : 0 < P) (hδ : 0 < δ) (hK : 0 < 1 + δ * K) : + P * (δ * max (fraForwardRate 1 P δ - K) 0) = (1 + δ * K) * max (1 / (1 + δ * K) - P) 0 := by + have h : P * (δ * (fraForwardRate 1 P δ - K)) = (1 + δ * K) * (1 / (1 + δ * K) - P) := by + unfold fraForwardRate + field_simp + ring + rw [mul_max_of_nonneg _ _ hδ.le, mul_max_of_nonneg _ _ hP.le, mul_max_of_nonneg _ _ hK.le] + simpa using congrArg (max · 0) h + +/-- **A caplet is a multiple of a put on the bond** (the caplet–bond-put identity). In a model with +bond prices, the caplet paying `δ (L(T₀, T₁) − K)⁺` at `T₁` is worth `(1 + δK)` puts on +`P(T₀, T₁)` struck at `1/(1 + δK)` and expiring at `T₀`: pay `P(T₀, T₁) · δ (L − K)⁺` at `T₀`, +which is `(1 − (1 + δK) P)⁺`, since `δ L = 1/P − 1`. The bond price `P(T₀, T₁)` is the +conditional expectation `bondPrice` of the discount factor, not a deterministic curve. -/ +theorem value_caplet_eq_bondPut (h : BondModel Q 𝓕 D X b ℓ T₀ T₁ δ) {K : ℝ} + (hK : 0 < 1 + δ * K) + (hint : Integrable (fun ω ↦ D T₁ ω * (δ * max (X ℓ T₀ ω - K) 0)) Q) : + (caplet ℓ T₀ T₁ δ K).value Q D X + = (1 + δ * K) * (bondPut b T₀ (1 / (1 + δ * K))).value Q D X := by + have hY : StronglyMeasurable[𝓕 T₀] fun ω ↦ δ * max (X ℓ T₀ ω - K) 0 := + (show Continuous fun x : ℝ ↦ δ * max (x - K) 0 by fun_prop).comp_stronglyMeasurable + h.libor_meas + simp only [caplet, bondPut, Contract.value_pay, capletPayoff, Payoff.eval, scenarioAt] + rw [h.integral_discount_mul hY hint, ← integral_const_mul] + refine integral_congr_ae ?_ + filter_upwards [h.libor_eq, h.bond_pos] with ω hL hP + rw [hL, mul_assoc, bond_mul_capletPayoff hP h.δ_pos hK] + ring + +/-! ### Caps, and the Black-76 caplet -/ + +omit [IsProbabilityMeasure Q] in +/-- **A cap is the sum of its caplets**, in every model in which each caplet's discounted payoff +is integrable. -/ +theorem value_cap (ℓ : ℕ → ι) (T : ℕ → ℝ≥0) (δ K : ℝ) (n : ℕ) + (hint : ∀ i < n, Integrable + (fun ω ↦ D (T (i + 1)) ω * (δ * max (X (ℓ i) (T i) ω - K) 0)) Q) : + (cap ℓ T δ K n).value Q D X + = ∑ i ∈ Finset.range n, (caplet (ℓ i) (T i) (T (i + 1)) δ K).value Q D X := + Contract.value_payFlows Q D X _ _ n fun i hi ↦ by + simpa [capletPayoff, Payoff.eval, scenarioAt] using hint i hi + +/-- **A cap is `(1 + δK)` times a strip of bond puts.** In a model with bond prices at each +reset date, the cap with accrual `δ` and strike `K` is worth `(1 + δK)` times the sum of the +puts on `P(Tᵢ, Tᵢ₊₁)` struck at `1/(1 + δK)` and expiring at `Tᵢ`. -/ +theorem value_cap_eq_bondPuts (b ℓ : ℕ → ι) (T : ℕ → ℝ≥0) {δ K : ℝ} (n : ℕ) + (h : ∀ i < n, BondModel Q 𝓕 D X (b i) (ℓ i) (T i) (T (i + 1)) δ) (hK : 0 < 1 + δ * K) + (hint : ∀ i < n, Integrable + (fun ω ↦ D (T (i + 1)) ω * (δ * max (X (ℓ i) (T i) ω - K) 0)) Q) : + (cap ℓ T δ K n).value Q D X + = (1 + δ * K) * ∑ i ∈ Finset.range n, + (bondPut (b i) (T i) (1 / (1 + δ * K))).value Q D X := by + rw [value_cap ℓ T δ K n hint, Finset.mul_sum] + exact Finset.sum_congr rfl fun i hi ↦ + value_caplet_eq_bondPut (h i (Finset.mem_range.1 hi)) hK (hint i (Finset.mem_range.1 hi)) + +/-- **The caplet is `P(0, T₁)` times a Black-76 call on the forward rate**, under the +`T₁`-forward measure `Q'` (`forwardMeasure` for the bank account `1/D T₁`). If the simple rate +`L(T₀, T₁)` is lognormal there, `L = bsTerminal F 0 σ T Z` with `Z` standard normal, then the +caplet is worth `P(0, T₁) · δ · [F Φ(d₁) − K Φ(d₂)]`, which is `blackCaplet` +(`Models/Forwards/Black76.lean`). The lognormality of `L` under `Q'` is a hypothesis, not derived +from a short-rate model, and `F` is the mean of `L` under `Q'`. -/ +theorem value_caplet_black76 {Q' : Measure Ω} [IsProbabilityMeasure Q'] + (hQ' : Q' = forwardMeasure Q fun ω ↦ 1 / D T₁ ω) (hD : ∀ ω, 0 < D T₁ ω) + (hDm : Measurable (D T₁)) (hDi : Integrable (D T₁) Q) {F K σ T : ℝ} {Z : Ω → ℝ} + (hZ : BSCallHyp Q' F K 0 σ T Z) + (hL : X ℓ T₀ =ᵐ[Q'] fun ω ↦ bsTerminal F 0 σ T (Z ω)) : + (caplet ℓ T₀ T₁ δ K).value Q D X = zeroCurve Q D T₁ * blackCaplet F K σ T δ := by + subst hQ' + obtain ⟨-, key⟩ := integral_discount_mul_eq_forward hD hDm hDi + (fun ω ↦ δ * max (X ℓ T₀ ω - K) 0) + have e3 : ∫ ω, δ * max (X ℓ T₀ ω - K) 0 ∂forwardMeasure Q (fun ω ↦ 1 / D T₁ ω) + = δ * (F * Phi (bsd1 F K 0 σ T) - K * Phi (bsd2 F K 0 σ T)) := by + rw [← show ∫ ω, max (bsTerminal F 0 σ T (Z ω) - K) 0 ∂forwardMeasure Q (fun ω ↦ 1 / D T₁ ω) + = F * Phi (bsd1 F K 0 σ T) - K * Phi (bsd2 F K 0 σ T) by + simpa using black_futures_formula hZ 0, ← integral_const_mul] + exact integral_congr_ae (hL.mono fun ω hω ↦ by simp only [hω]) + simp only [caplet, Contract.value_pay, capletPayoff, Payoff.eval, scenarioAt, blackCaplet] + rw [← key, e3] + rfl + +/-- **The forward rate has the forward rate of the zero curve as its mean at its own forward +measure**: `𝔼^{T₁}[L(T₀, T₁)] = (P(0, T₀)/P(0, T₁) − 1)/δ` (`fraForwardRate`). -/ +theorem BondModel.integral_libor_forward (h : BondModel Q 𝓕 D X b ℓ T₀ T₁ δ) + {Q' : Measure Ω} (hQ' : Q' = forwardMeasure Q fun ω ↦ 1 / D T₁ ω) (hD : ∀ ω, 0 < D T₁ ω) + (hDm : Measurable (D T₁)) (hD0 : Integrable (D T₀) Q) + (hint : Integrable (fun ω ↦ D T₁ ω * X ℓ T₀ ω) Q) : + ∫ ω, X ℓ T₀ ω ∂Q' = fraForwardRate (zeroCurve Q D T₀) (zeroCurve Q D T₁) δ := by + subst hQ' + have hδ := h.δ_pos + obtain ⟨hpos, key⟩ := integral_discount_mul_eq_forward hD hDm h.integrable_D (X ℓ T₀) + have e3 : ∫ ω, D T₁ ω * X ℓ T₀ ω ∂Q = (zeroCurve Q D T₀ - zeroCurve Q D T₁) / δ := by + rw [h.integral_discount_mul h.libor_meas hint] + rw [← h.integral_discount, zeroCurve, ← integral_sub hD0 h.integrable_discount_mul, + ← integral_div] + refine integral_congr_ae ?_ + filter_upwards [h.libor_eq, h.bond_pos] with ω hL hP + rw [hL, fraForwardRate] + field_simp [hP.ne', hδ.ne'] + rw [e3] at key + have hz : zeroCurve Q D T₁ = ∫ ω, D T₁ ω ∂Q := rfl + rw [hz] at key ⊢ + rw [fraForwardRate] + field_simp [hpos.ne', hδ.ne'] at key ⊢ + linear_combination key + +/-- **The Black-76 caplet formula, at the forward rate of the zero curve.** Under the hypotheses +of `value_caplet_black76` and a model with bond prices, the caplet is worth +`P(0, T₁) · blackCaplet F K σ T δ` with `F = (P(0, T₀)/P(0, T₁) − 1)/δ`, the forward rate of the +zero curve. -/ +theorem value_caplet_black76_forwardRate (h : BondModel Q 𝓕 D X b ℓ T₀ T₁ δ) + {Q' : Measure Ω} [IsProbabilityMeasure Q'] + (hQ' : Q' = forwardMeasure Q fun ω ↦ 1 / D T₁ ω) (hD : ∀ ω, 0 < D T₁ ω) + (hDm : Measurable (D T₁)) (hD0 : Integrable (D T₀) Q) + (hint : Integrable (fun ω ↦ D T₁ ω * X ℓ T₀ ω) Q) {K σ T : ℝ} {Z : Ω → ℝ} + {F : ℝ} (hZ : BSCallHyp Q' F K 0 σ T Z) + (hL : X ℓ T₀ =ᵐ[Q'] fun ω ↦ bsTerminal F 0 σ T (Z ω)) : + (caplet ℓ T₀ T₁ δ K).value Q D X + = zeroCurve Q D T₁ * blackCaplet + (fraForwardRate (zeroCurve Q D T₀) (zeroCurve Q D T₁) δ) K σ T δ := by + have hF : F = fraForwardRate (zeroCurve Q D T₀) (zeroCurve Q D T₁) δ := by + rw [← h.integral_libor_forward hQ' hD hDm hD0 hint, integral_congr_ae hL] + simpa using (discounted_terminal_eq_S0 hZ).symm + rw [← hF] + exact value_caplet_black76 hQ' hD hDm h.integrable_D hZ hL + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Models/Rates/CleanPriceAccrued.lean b/LeanPool/MathFin/Models/Rates/CleanPriceAccrued.lean new file mode 100644 index 0000000000..e5e71c70e1 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/CleanPriceAccrued.lean @@ -0,0 +1,175 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.MacaulayModified +public import Mathlib.Analysis.SpecialFunctions.Pow.Continuity + +/-! +# Clean price and accrued interest, on- and between-coupon dates + +A coupon bond's quoted **clean price** omits the interest that has accrued +since the last coupon date; the **dirty (invoiced) price** is what actually +changes hands. Writing `f ∈ [0, 1)` for the fraction of the current coupon +period elapsed since the last coupon date, the street-convention dirty price +is the flat-compounded present value of the remaining cashflows, carried +forward by `f` periods: + + `Dirty(y, f) = (1 + y)^f · Σ c_i / (1 + y)^{t_i}` (`bondPriceDisc` from + `MacaulayModified`, with `t_i` the number of whole periods from the *last* + coupon date to each cashflow, so the next coupon has `t_i = 1`): the + `(1 + y)^f` factor carries the last-coupon-date present value forward by + the elapsed fraction `f` of the period that has since run. `(1 + y)^f` + here is `Real.rpow`, a compound-interest carry only for `1 + y > 0`; for + `1 + y < 0` and `f ∈ (0, 1)` the value is junk. The on-coupon-date results + fix `f = 0`, where `Real.rpow_zero` gives `1` for every `y`; the + across-a-coupon-date limits assume `1 + y > 0`. + +Accrued interest on the next coupon (its amount supplied separately as +`c1`, since it is not tied to the cashflow map `c`) is the simple-interest +share of that coupon already earned, + + `Accrued(f) = f · c₁`, + +with **clean price** `Clean(y, f) = Dirty(y, f) - Accrued(f)`. On a coupon +date (`f = 0`) this collapses to the ordinary `bondPriceDisc` with zero +accrued interest — the two pricing conventions agree exactly where they must. + +## Main definitions + +* `dirtyPrice`: the flat-compounded present value of the remaining cashflows, carried forward by + the elapsed fraction `f` of the current coupon period. +* `accruedInterest`: the simple-interest share of the next coupon accrued over the fraction `f`. +* `cleanPrice`: the dirty price minus the accrued interest. + +## Main results + +* `cleanPrice_eq_dirty_sub_accrued`: `Clean = Dirty - Accrued` by definition. +* `dirtyPrice_on_coupon_date`: `Dirty(y, 0) = bondPriceDisc s t c y`. +* `accruedInterest_on_coupon_date`: `Accrued(0) = 0`. +* `cleanPrice_on_coupon_date`: on a coupon date, clean price equals + `bondPriceDisc` (equivalently, equals dirty price). + +## Across a coupon date + +At the end of a period (`f ↑ 1`) the next coupon `j ∈ s` (`t j = 1`) is paid and a +new period starts: the remaining cashflows are `s.erase j`, each one period +closer (`t i - 1`), and `f` restarts at `0`. With `1 + y > 0` and every +cashflow at least one period out (`∀ i ∈ s, 1 ≤ t i`, so `t i - 1` is the true +remaining tenor, not an `ℕ`-truncated `0`): + +* `dirtyPrice_one_eq`: at `f = 1` the dirty price is the new period's dirty + price plus `c j` (this one needs only `1 + y ≠ 0`). +* `tendsto_dirtyPrice_coupon_date`: the dirty price tends to the new period's + dirty price **plus the coupon** `c j` — it drops by exactly the coupon paid. +* `tendsto_cleanPrice_coupon_date`: the clean price, with accrued interest + on `c j`, tends to the new period's clean price — it is continuous across + the coupon date. The full accrued coupon is what the dirty price sheds. + +## References + +* [Fabozzi, *Bond Markets, Analysis and Strategies*][FabozziBMAS] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull] + +## Tags + +clean price, dirty price, accrued interest, coupon bond, bond quotation, day count fraction, +MSC 91G30, JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +open Filter Topology + +variable {ι : Type*} + +/-- Dirty price between coupon dates: the flat-compounded present value of +remaining cashflows, carried forward by the elapsed fraction `f` of the +current period. -/ +noncomputable def dirtyPrice (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) (y f : ℝ) : ℝ := + (1 + y) ^ f * bondPriceDisc s t c y + +/-- Accrued interest on the next coupon, as a simple-interest share of the +elapsed fraction `f` of the current period. `c1` is the next coupon's +amount, supplied directly by the caller rather than read off `c`. -/ +def accruedInterest (c1 f : ℝ) : ℝ := f * c1 + +/-- Clean (quoted) price: dirty price minus accrued interest. As with +`accruedInterest`, `c1` is caller-supplied and not tied to `c`. -/ +noncomputable def cleanPrice (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) (y f c1 : ℝ) : ℝ := + dirtyPrice s t c y f - accruedInterest c1 f + +/-- Clean price is dirty price minus accrued interest, by construction. -/ +theorem cleanPrice_eq_dirty_sub_accrued (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) (y f c1 : ℝ) : + cleanPrice s t c y f c1 = dirtyPrice s t c y f - accruedInterest c1 f := rfl + +/-- On a coupon date (`f = 0`), the dirty price collapses to the ordinary +discrete-compounding bond price. -/ +theorem dirtyPrice_on_coupon_date (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) (y : ℝ) : + dirtyPrice s t c y 0 = bondPriceDisc s t c y := by + rw [dirtyPrice, Real.rpow_zero, one_mul] + +/-- On a coupon date, no interest has accrued. -/ +theorem accruedInterest_on_coupon_date (c1 : ℝ) : accruedInterest c1 0 = 0 := + zero_mul c1 + +/-- On a coupon date, clean price equals dirty price (equivalently, equals +the ordinary `bondPriceDisc`): the two conventions agree exactly on coupon +dates, where there is nothing left to accrue. -/ +theorem cleanPrice_on_coupon_date (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) (y c1 : ℝ) : + cleanPrice s t c y 0 c1 = bondPriceDisc s t c y := by + rw [cleanPrice_eq_dirty_sub_accrued, dirtyPrice_on_coupon_date, + accruedInterest_on_coupon_date, sub_zero] + +/-- At the end of a period (`f = 1`), the dirty price is the new period's dirty +price plus the next coupon `c j` (`j ∈ s`) paid on that date: carrying the +last-coupon-date value one full period forward discounts every cashflow one +period less. -/ +theorem dirtyPrice_one_eq [DecidableEq ι] (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) {y : ℝ} + (hy : 1 + y ≠ 0) {j : ι} (hj : j ∈ s) (htj : t j = 1) (ht : ∀ i ∈ s, 1 ≤ t i) : + dirtyPrice s t c y 1 = dirtyPrice (s.erase j) (fun i ↦ t i - 1) c y 0 + c j := by + rw [dirtyPrice_on_coupon_date, dirtyPrice, Real.rpow_one, bondPriceDisc, Finset.mul_sum, + bondPriceDisc, ← Finset.add_sum_erase s _ hj, add_comm] + congr 1 + · refine Finset.sum_congr rfl fun i hi ↦ ?_ + obtain ⟨n, hn⟩ := Nat.exists_eq_add_of_le' (ht i (Finset.mem_of_mem_erase hi)) + rw [hn, Nat.add_sub_cancel, pow_succ] + field_simp + · rw [htj, pow_one] + field_simp + +/-- **The dirty price drops by the coupon at a coupon date.** As the elapsed +fraction `f` of the period rises to `1`, the dirty price tends to the new +period's dirty price (remaining cashflows `s.erase j`, each one period closer, +`f = 0`) plus the next coupon `c j` (`j ∈ s`) paid on the date. -/ +theorem tendsto_dirtyPrice_coupon_date [DecidableEq ι] (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) + {y : ℝ} (hy : 0 < 1 + y) {j : ι} (hj : j ∈ s) (htj : t j = 1) (ht : ∀ i ∈ s, 1 ≤ t i) : + Tendsto (fun f ↦ dirtyPrice s t c y f) (𝓝[<] 1) + (𝓝 (dirtyPrice (s.erase j) (fun i ↦ t i - 1) c y 0 + c j)) := by + rw [← dirtyPrice_one_eq s t c hy.ne' hj htj ht] + exact ((Real.continuousAt_const_rpow hy.ne').mul continuousAt_const).continuousWithinAt + +/-- **The clean price is continuous across a coupon date.** With accrued +interest on the next coupon `c j` (`j ∈ s`) being paid, the clean price tends, as `f ↑ 1`, to +the clean price at the start of the new period, whatever coupon `c1'` accrues +next: the coupon the dirty price sheds (`tendsto_dirtyPrice_coupon_date`) is +exactly the accrued interest that has built up to it. -/ +theorem tendsto_cleanPrice_coupon_date [DecidableEq ι] (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) + {y : ℝ} (hy : 0 < 1 + y) {j : ι} (hj : j ∈ s) (htj : t j = 1) (ht : ∀ i ∈ s, 1 ≤ t i) + (c1' : ℝ) : + Tendsto (fun f ↦ cleanPrice s t c y f (c j)) (𝓝[<] 1) + (𝓝 (cleanPrice (s.erase j) (fun i ↦ t i - 1) c y 0 c1')) := by + have hacc : Tendsto (fun f ↦ accruedInterest (c j) f) (𝓝[<] 1) (𝓝 (c j)) := by + simpa [accruedInterest] using + ((continuous_mul_const (c j)).tendsto 1).mono_left nhdsWithin_le_nhds + simpa [cleanPrice, accruedInterest_on_coupon_date] using + (tendsto_dirtyPrice_coupon_date s t c hy hj htj ht).sub hacc + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/ConvexityImmunization.lean b/LeanPool/MathFin/Models/Rates/ConvexityImmunization.lean new file mode 100644 index 0000000000..72de441006 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/ConvexityImmunization.lean @@ -0,0 +1,134 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.Immunization + +/-! +# Second-order bond portfolio immunization + +The first-order immunization in `Immunization.lean` only neutralizes +`∂(A - L)/∂r` at the current rate. Larger parallel rate shifts are picked up +by the second-order term `(1/2) ∂²(A - L)/∂r² · (Δr)²`, governed by the +**convexity** of the cash-flow stream. + +For each ZCB: `∂² B/∂r² = (T - t)² · B`. For a portfolio: + + `Conv_P · P = ∑_i w_i · (T_i - t)² · exp(-r(T_i - t))`, + +and the derivative `∂_r (-Dur_P · P) = Conv_P · P`. + +Second-order immunization: matching duration-times-value makes `∂(A − L)/∂r` +vanish (`Immunization.lean`), and matching convexity-times-value makes +`∂²(A − L)/∂r²` vanish, so together they leave the surplus flat to second order +at the current rate. + +## Main definitions + +* `bondPortfolioConv`: the convexity-times-value `Conv_P · P` of the bond portfolio, + `∑_i w_i · (T_i − t)² · exp(−r(T_i − t))`. + +## Main results + +* `hasDerivAt_bondPortfolioDur_r`: `∂_r (Dur_P · P) = −Conv_P · P`. +* `hasDerivAt_neg_bondPortfolioDur_r`: `∂_r (−Dur_P · P) = Conv_P · P`. +* `hasDerivAt_deriv_bondPortfolioValue_r`: `∂²P/∂r² = Conv_P · P`, for the value + itself. +* `bondPortfolio_immunization_second_order`: matching convexity-times-value gives + `∂² (A − L)/∂r² = 0`, for the surplus itself. + +## References + +* [Fabozzi, *Fixed Income Mathematics*][FabozziFIM], Ch 5 +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], Ch 4.11 + +## Tags + +second-order immunization, bond convexity, duration matching, asset–liability management, +bond portfolio, rate sensitivity, MSC 91G30, JEL G11, JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- Convexity-times-value `Conv_P · P` of the bond portfolio: +`∑_i w_i · (T_i − t)² · exp(−r(T_i − t))`. -/ +noncomputable def bondPortfolioConv + {ι : Type*} (s : Finset ι) (w T : ι → ℝ) (t r : ℝ) : ℝ := + ∑ i ∈ s, w i * (T i - t) ^ 2 * Real.exp (-(r * (T i - t))) + +/-- **Derivative of duration-times-value w.r.t. rate**: +`∂_r (Dur_P · P) = −Conv_P · P`. -/ +lemma hasDerivAt_bondPortfolioDur_r + {ι : Type*} (s : Finset ι) (w T : ι → ℝ) (t r : ℝ) : + HasDerivAt (fun r' ↦ bondPortfolioDur s w T t r') + (-bondPortfolioConv s w T t r) r := by + unfold bondPortfolioDur bondPortfolioConv + have h_each : ∀ i ∈ s, HasDerivAt + (fun r' ↦ w i * (T i - t) * Real.exp (-(r' * (T i - t)))) + (-(w i * (T i - t) ^ 2 * Real.exp (-(r * (T i - t))))) r := by + intro i _ + -- each summand's rate-derivative is the ZCB duration atom `ZCB.hasDerivAt_zcb_r` + -- scaled by the duration weight `w i · (T i − t)`. + have h := (hasDerivAt_zcb_r t (T i) r).const_mul (w i * (T i - t)) + simp only [zcb] at h + convert h using 1; ring + have h_raw := HasDerivAt.fun_sum h_each + rw [Finset.sum_neg_distrib] at h_raw + exact h_raw + +/-- **The second-derivative formula**: the r-derivative of `∂P/∂r = −Dur_P · P` is +`Conv_P · P`. The second derivative of the value itself is +`hasDerivAt_deriv_bondPortfolioValue_r`. -/ +lemma hasDerivAt_neg_bondPortfolioDur_r + {ι : Type*} (s : Finset ι) (w T : ι → ℝ) (t r : ℝ) : + HasDerivAt (fun r' ↦ -bondPortfolioDur s w T t r') + (bondPortfolioConv s w T t r) r := + (hasDerivAt_bondPortfolioDur_r s w T t r).neg.congr_deriv (neg_neg _) + +/-- **Second derivative of portfolio value**: `∂²P/∂r² = Conv_P · P`, for the value itself: +`∂P/∂r = −Dur_P · P` at every rate (`hasDerivAt_bondPortfolioValue_r`), and its derivative is +the formula of `hasDerivAt_neg_bondPortfolioDur_r`. -/ +theorem hasDerivAt_deriv_bondPortfolioValue_r {ι : Type*} (s : Finset ι) (w T : ι → ℝ) + (t r : ℝ) : + HasDerivAt (deriv fun r' ↦ bondPortfolioValue s w T t r') (bondPortfolioConv s w T t r) r := + hasDerivAt_deriv_of_eventually + (.of_forall (hasDerivAt_bondPortfolioValue_r s w T t)) + (hasDerivAt_neg_bondPortfolioDur_r s w T t r) + +/-- **Single-bond convexity**: a single-bond portfolio's convexity-times-value +equals `w · (T − t)² · exp(−r(T − t))`. -/ +lemma bondPortfolio_single_bond_conv + {ι : Type*} (i : ι) (w T : ι → ℝ) (t r : ℝ) : + bondPortfolioConv {i} w T t r = + w i * (T i - t) ^ 2 * Real.exp (-(r * (T i - t))) := by + unfold bondPortfolioConv + simp + +/-- **Second-order immunization**: matching convexity-times-value gives +`∂²(P_A − P_L)/∂r² = 0` at the current rate, for the surplus itself. The second derivative of +each side is its convexity-times-value (`hasDerivAt_neg_bondPortfolioDur_r`), so matching those +cancels it. Matching duration-times-value is the separate first-order condition, +`bondPortfolio_immunization_first_order`. -/ +theorem bondPortfolio_immunization_second_order {ι κ : Type*} (sA : Finset ι) + (wA TA : ι → ℝ) (sL : Finset κ) (wL TL : κ → ℝ) (t r : ℝ) + (h_match_conv : bondPortfolioConv sA wA TA t r = bondPortfolioConv sL wL TL t r) : + HasDerivAt + (deriv fun r' ↦ bondPortfolioValue sA wA TA t r' - bondPortfolioValue sL wL TL t r') 0 r := + hasDerivAt_deriv_of_eventually + (.of_forall fun r' ↦ + (hasDerivAt_bondPortfolioValue_r sA wA TA t r').sub + (hasDerivAt_bondPortfolioValue_r sL wL TL t r')) + (((hasDerivAt_neg_bondPortfolioDur_r sA wA TA t r).sub + (hasDerivAt_neg_bondPortfolioDur_r sL wL TL t r)).congr_deriv + (sub_eq_zero_of_eq h_match_conv)) + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/ConvexitySensitivity.lean b/LeanPool/MathFin/Models/Rates/ConvexitySensitivity.lean new file mode 100644 index 0000000000..0e37079e2d --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/ConvexitySensitivity.lean @@ -0,0 +1,130 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.DurationSensitivity +public import Mathlib.Analysis.Calculus.Deriv.Mul + +/-! +# Convexity as the second derivative of bond price (first-principles) + +For a coupon bond with discrete-compounded yield `y` and cashflows `c_i` at +integer times `t_i`, + + `P(y) = Σ c_i / (1 + y)^{t_i}`, + `P'(y) = −Σ t_i · c_i / (1 + y)^{t_i + 1} = −ModNum(y)` (`DurationSensitivity`), + `P''(y) = Σ t_i · (t_i + 1) · c_i / (1 + y)^{t_i + 2} =: ConvNum(y)`. + +The **convexity** is `C(y) := ConvNum(y) / P(y)` — the *percentage* second +derivative of price w.r.t. yield. Together with duration, it gives the +standard discrete yield Taylor expansion + + `ΔP/P ≈ −D_mod · Δy + ½ C · (Δy)²`. + +This file derives the second-derivative identity from the per-cashflow +second derivative `d²/dy² [c / (1+y)^n] = n · (n+1) · c / (1+y)^{n+2}`, +obtained by applying `hasDerivAt_coupon_term` from `DurationSensitivity` a +second time. + +## Why this is "first principles" + +Pre-existing `Models.Rates.MacaulayModified` defines duration numerators +algebraically. `Models.Rates.DurationSensitivity` (phase 21) derives +`dP/dy = −ModNum`. This file completes the discrete yield-Taylor expansion +by deriving `d²P/dy² = ConvNum` — i.e., bond convexity is *literally* the +second derivative of price, not a separately-defined moment. + +## Main definitions + +* `convexityNumerator`: the convexity numerator `∑ t_i · (t_i + 1) · c_i / (1 + y)^{t_i + 2}`. + +## Main results + +* `hasDerivAt_modifiedNumerator`: `d/dy [ModNum(y)] = −ConvNum(y)`. +* `hasDerivAt_bondPriceDisc_secondDeriv`: `d²P/dy² = ConvNum(y)` (stated as + the derivative of `P'(y) = −ModNum(y)`). + +## Tags + +bond convexity, second derivative of price, yield Taylor expansion, price–yield curve, coupon bond, +interest rate sensitivity, MSC 91G30, JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +open Finset + +variable {ι : Type*} + +/-- Convexity numerator: `∑ t_i · (t_i + 1) · c_i / (1 + y)^{t_i + 2}`. -/ +noncomputable def convexityNumerator (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) (y : ℝ) : ℝ := + ∑ i ∈ s, (t i : ℝ) * ((t i : ℝ) + 1) * c i / (1 + y) ^ (t i + 2) + +/-- **Derivative of `ModNum(y)`** is `−ConvNum(y)`. Proof: for each term +`(t_i : ℝ) · c_i / (1 + y')^(t_i + 1)`, the derivative is + + `d/dy [(t_i : ℝ) · c_i / (1 + y')^(t_i + 1)] + = (t_i : ℝ) · (−(t_i + 1) · c_i / (1 + y)^(t_i + 2)) + = −(t_i : ℝ) · ((t_i : ℝ) + 1) · c_i / (1 + y)^(t_i + 2)`. + +Summing over cashflows: `d/dy ModNum = −ConvNum`. -/ +theorem hasDerivAt_modifiedNumerator + (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) {y : ℝ} (hy : 1 + y ≠ 0) : + HasDerivAt (fun y' ↦ modifiedNumerator s t c y') + (-convexityNumerator s t c y) y := by + unfold modifiedNumerator convexityNumerator + rw [show -∑ i ∈ s, (t i : ℝ) * ((t i : ℝ) + 1) * c i / (1 + y) ^ (t i + 2) = + ∑ i ∈ s, (-((t i : ℝ) * ((t i : ℝ) + 1) * c i / (1 + y) ^ (t i + 2))) from by + rw [← Finset.sum_neg_distrib]] + apply HasDerivAt.fun_sum + intros i _ + have h_term : HasDerivAt (fun y' : ℝ ↦ c i / (1 + y') ^ (t i + 1)) + (-(((t i + 1 : ℕ) : ℝ) * c i / (1 + y) ^ (t i + 1 + 1))) y := + hasDerivAt_coupon_term (c i) (t i + 1) hy + have h_pulled := h_term.const_mul ((t i : ℝ)) + have h_func : + (fun y' : ℝ ↦ (t i : ℝ) * (c i / (1 + y') ^ (t i + 1))) = + (fun y' : ℝ ↦ (t i : ℝ) * c i / (1 + y') ^ (t i + 1)) := by + funext y'; ring + rw [h_func] at h_pulled + convert h_pulled using 1 + push_cast + have : t i + 1 + 1 = t i + 2 := by omega + rw [this] + ring + +/-- **Second derivative of bond price**: `P''(y) = ConvNum(y)`, stated as the +derivative of `P'(y) = −ModNum(y)`. + +Combined with `hasDerivAt_bondPriceDisc` (from `DurationSensitivity`), this +gives the full discrete yield Taylor expansion of the bond price: + + `P(y + Δy) ≈ P(y) − ModNum(y) · Δy + ½ · ConvNum(y) · (Δy)²`. -/ +theorem hasDerivAt_bondPriceDisc_secondDeriv + (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) {y : ℝ} (hy : 1 + y ≠ 0) : + HasDerivAt (fun y' ↦ -modifiedNumerator s t c y') + (convexityNumerator s t c y) y := by + have h := (hasDerivAt_modifiedNumerator s t c hy).neg + rw [neg_neg] at h + exact h + +/-- **Convexity-sensitivity identity**: `P''(y)/P(y) = C(y) = ConvNum/P`. The +percentage second derivative of price equals convexity, completing the +duration-convexity yield Taylor expansion. -/ +theorem bondPriceDisc_secondDeriv_eq_convexity_times_price + (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) {y : ℝ} + (hy : 1 + y ≠ 0) : + ∃ P'' : ℝ, HasDerivAt (fun y' ↦ -modifiedNumerator s t c y') P'' y ∧ + P'' / bondPriceDisc s t c y = + convexityNumerator s t c y / bondPriceDisc s t c y := by + refine ⟨convexityNumerator s t c y, + hasDerivAt_bondPriceDisc_secondDeriv s t c hy, rfl⟩ + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/CouponBonds.lean b/LeanPool/MathFin/Models/Rates/CouponBonds.lean new file mode 100644 index 0000000000..47cc244838 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/CouponBonds.lean @@ -0,0 +1,141 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.ZCB + +/-! +# Coupon bonds, annuities, and rate-curve identities + +Extensions of the deterministic-short-rate framework in `ZCB.lean`: + +* **Annuity closed form**: `A_n(c, r, Δt) = c · e^{-rΔt} · (1 − x^n) / (1 − x)`, + with `x = e^{-rΔt}`. Standard geometric-series identity. +* **Forward / spot rate consistency under a flat curve**: + `f(t, T) = -∂_T log B(t, T) = r` when `B(t, T) = e^{-r(T - t)}`. Under a flat + curve the instantaneous forward rate equals the spot rate at every horizon. +* **Coupon bond strict-monotonicity in `r`**: for positive coupons paid at + future times, the bond price is a strictly decreasing function of the yield, + giving the standard YTM-uniqueness property at the parameter-monotonicity + level. + +## Main definitions + +* `annuityValue`: the value of an annuity over `n` periods of length `Δt` with coupon `c` at rate + `r`. + +## Main results + +* `annuityValue`, `annuityValue_closed_form`: definition and geometric-series + closed form. +* `annuityValue_succ_mul_exp_sub`: one period of an annuity's value, + `A_{m+1}·e^{rΔt} - A = A_m`. +* `hasDerivAt_neg_log_zcb_T`: `-∂_T log B(t, T) = r` (forward = spot under flat + curve). +* `couponBondPrice_strictAnti`: bond price strictly decreasing in `r`, for + positive coupons at future times. + +## References + +* [Fabozzi, *Fixed Income Mathematics*][FabozziFIM], Ch 2; Ch 3 +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], Ch 4; Ch 4.5; Ch 4.7 + +## Tags + +annuity, coupon bond, yield to maturity, flat curve, forward rate, geometric series, present value, +MSC 91G30, JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- Annuity value over `n` periods of length `Δt`, coupon `c`, rate `r`. -/ +noncomputable def annuityValue (n : ℕ) (c r Δt : ℝ) : ℝ := + ∑ i ∈ Finset.range n, c * Real.exp (-(r * ((↑i + 1) * Δt))) + +/-- **Annuity closed form** via the geometric-series identity: +`A_n(c, r, Δt) = c · e^{-rΔt} · (1 − x^n) / (1 − x)`, with `x = e^{-rΔt}`. -/ +lemma annuityValue_closed_form (n : ℕ) (c r Δt : ℝ) + (h : Real.exp (-(r * Δt)) ≠ 1) : + annuityValue n c r Δt = + c * Real.exp (-(r * Δt)) * + (1 - Real.exp (-(r * Δt)) ^ n) / (1 - Real.exp (-(r * Δt))) := by + unfold annuityValue + -- Rewrite each term: c · exp(-r(i+1)Δt) = c · exp(-rΔt) · exp(-rΔt)^i. + have h_term : ∀ i ∈ Finset.range n, + c * Real.exp (-(r * ((↑i + 1) * Δt))) = + c * Real.exp (-(r * Δt)) * Real.exp (-(r * Δt)) ^ i := by + intro i _ + rw [show -(r * ((↑i + 1) * Δt)) = -(r * Δt) + ↑i * (-(r * Δt)) from by ring] + rw [Real.exp_add, Real.exp_nat_mul] + ring + rw [Finset.sum_congr rfl h_term] + rw [← Finset.mul_sum] + rw [geom_sum_eq h n] + have h_one_minus_ne : 1 - Real.exp (-(r * Δt)) ≠ 0 := + sub_ne_zero.mpr (Ne.symm h) + have h_x_minus_one_ne : Real.exp (-(r * Δt)) - 1 ≠ 0 := sub_ne_zero.mpr h + field_simp + ring + +/-- One period of an annuity: carrying the value of `m + 1` payments forward one +period and paying the first leaves the value of the other `m`, +`A_{m+1}·e^{rΔt} - A = A_m`. -/ +theorem annuityValue_succ_mul_exp_sub (m : ℕ) (A r Δt : ℝ) : + annuityValue (m + 1) A r Δt * Real.exp (r * Δt) - A = annuityValue m A r Δt := by + rw [annuityValue, annuityValue, Finset.sum_range_succ', add_mul, Finset.sum_mul, + mul_assoc A, ← Real.exp_add] + simp only [Nat.cast_zero, zero_add, one_mul, neg_add_cancel, Real.exp_zero, mul_one, + add_sub_cancel_right] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [mul_assoc, ← Real.exp_add] + congr 2 + push_cast + ring + +/-- **Forward = spot under a flat curve**: under a constant short rate `r`, the +instantaneous forward rate `-∂_T log B(t, T)` equals `r` at every horizon. -/ +lemma hasDerivAt_neg_log_zcb_T (r t T : ℝ) : + HasDerivAt (fun T' ↦ -Real.log (zcb r t T')) r T := by + have h_eq : ∀ T' : ℝ, -Real.log (zcb r t T') = r * (T' - t) := by + intro T' + change -Real.log (Real.exp (-(r * (T' - t)))) = r * (T' - t) + rw [Real.log_exp] + ring + have h_lin : HasDerivAt (fun T' : ℝ ↦ r * (T' - t)) r T := by + have h := ((hasDerivAt_id T).sub_const t).const_mul r + simpa using h + exact h_lin.congr_of_eventuallyEq (Filter.Eventually.of_forall h_eq) + +/-- **Coupon bond strict-monotonicity in `r`** at a fixed cash-flow schedule: +if all coupons are positive and all payment times are strictly in the future, +the bond price is strictly decreasing in the yield. This is the parameter +form of the YTM-uniqueness property — any positive price corresponds to at +most one yield. -/ +lemma couponBondPrice_strictAnti + {ι : Type*} (s : Finset ι) (c T : ι → ℝ) (t : ℝ) + (h_pos : ∀ i ∈ s, 0 < c i) + (h_future : ∀ i ∈ s, t < T i) + (h_nonempty : s.Nonempty) : + StrictAnti (fun r ↦ ∑ i ∈ s, c i * Real.exp (-(r * (T i - t)))) := by + intro r₁ r₂ hr + apply Finset.sum_lt_sum_of_nonempty h_nonempty + intro i hi + have h_diff : 0 < T i - t := sub_pos.mpr (h_future i hi) + have h_arg : -(r₂ * (T i - t)) < -(r₁ * (T i - t)) := by + have : r₁ * (T i - t) < r₂ * (T i - t) := by + exact mul_lt_mul_of_pos_right hr h_diff + linarith + have h_exp_lt : Real.exp (-(r₂ * (T i - t))) < Real.exp (-(r₁ * (T i - t))) := + Real.exp_lt_exp.mpr h_arg + exact mul_lt_mul_of_pos_left h_exp_lt (h_pos i hi) + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/DeterministicCurve.lean b/LeanPool/MathFin/Models/Rates/DeterministicCurve.lean new file mode 100644 index 0000000000..f722903a5b --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/DeterministicCurve.lean @@ -0,0 +1,169 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.Value +public import LeanPool.MathFin.Models.Rates.MacaulayModified +public import LeanPool.MathFin.Models.Rates.CouponBonds +public import LeanPool.MathFin.Models.Rates.InterestRateSwap +public import LeanPool.MathFin.Models.Rates.FRA + +/-! +# Bonds and swaps on a deterministic curve + +On a deterministic discount curve the library's fixed-income closed forms are the values of +contracts. A coupon bond is a schedule of fixed cash flows (`fixedFlows`, +`Contracts/Instruments/FixedIncome.lean`), and in every model it is worth the sum of its +discounted flows (`value_fixedFlows_deterministic`): + +* discounted at a yield `y`, with integer payment times, it is `bondPriceDisc` + (`pathPV_fixedFlows_yieldDiscount`), the price the durations and convexities of + `Models/Rates/` are taken of; +* `n` level payments on a grid of step `Δt`, discounted on the flat continuous curve `zcb r 0`, + are `annuityValue` (`pathPV_fixedFlows_zcb`). + +A swap on the curve `P` exchanges a fixed leg, `δK` at each payment date, for a floating leg that +pays the simple forward rate the curve implies for each accrual period, +`δ · fraForwardRate (P Tᵢ) (P Tᵢ₊₁) δ` at `Tᵢ₊₁`. The floating coupons are fixed by the curve, +which is what makes this the deterministic-rates model, where a floating rate is known in advance. +The floating leg telescopes to `P(T₀) − P(Tₙ)` (`pathPV_floatingLeg`), the fixed leg is `K` times +the annuity (`pathPV_fixedLeg`), so the payer swap is worth `payerSwapValue` (`value_payerSwap`), +and it is worth zero exactly at the par rate (`value_payerSwap_eq_zero_iff`). With one accrual +period the swap is a forward-rate agreement, worth `fraValue` (`value_payerSwap_one_eq_fraValue`). +With a stochastic discount the same contracts are priced in `Models/Rates/ShortRate.lean`. + +## Main definitions + +* `yieldDiscount` — discounting at a yield with annual compounding. +* `floatingLeg`, `fixedLeg`, `payerSwap` — the legs of a swap on a deterministic curve. + +## Main results + +* `pathPV_fixedFlows_yieldDiscount`, `pathPV_fixedFlows_zcb` — bonds and annuities. +* `pathPV_floatingLeg`, `pathPV_fixedLeg`, `value_payerSwap`, `value_payerSwap_eq_zero_iff`, + `value_payerSwap_one_eq_fraValue` — swaps and FRAs. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026], the contract layer these values + are read through +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + Section 1.5 +* [Fabozzi, *Bond Markets, Analysis and Strategies*][FabozziBMAS], ch. 2 +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], ch. 7 + +## Tags + +coupon bond, interest rate swap, par swap rate, forward rate agreement, annuity, floating leg, +deterministic curve, MSC 91G30, JEL E43, JEL G12 +-/ + +@[expose] public section + +open MeasureTheory +open scoped NNReal + +namespace MathFin.Contracts + +variable {ι Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- Discounting at a yield `y` with annual compounding, `(1 + y)^{−τ}`; a discount factor for +`1 + y > 0`. -/ +noncomputable def yieldDiscount (y : ℝ) : ℝ≥0 → ℝ := fun τ ↦ (1 + y) ^ (-(τ : ℝ)) + +/-- **A coupon bond at a yield is `bondPriceDisc`.** Discounted at the yield `y`, cash flows +`c i` at integer times `t i` are worth `∑ cᵢ / (1 + y)^{tᵢ}`. -/ +theorem pathPV_fixedFlows_yieldDiscount {y : ℝ} (hy : 0 ≤ 1 + y) (s : Scenario ι) (t : ℕ → ℕ) + (c : ℕ → ℝ) (n : ℕ) : + (fixedFlows (fun i ↦ (t i : ℝ≥0)) c n : Contract ι).pathPV (yieldDiscount y) s + = bondPriceDisc (Finset.range n) t c y := by + rw [pathPV_fixedFlows, bondPriceDisc] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [yieldDiscount, NNReal.coe_natCast, Real.rpow_neg hy, Real.rpow_natCast, div_eq_inv_mul] + +/-- **Level payments on the flat continuous curve are `annuityValue`.** `n` payments of `c` at +`Δt, 2Δt, …, nΔt`, discounted by `zcb r 0`, are worth `∑ c e^{−r(i+1)Δt}`. -/ +theorem pathPV_fixedFlows_zcb (s : Scenario ι) (n : ℕ) (c r : ℝ) (Δt : ℝ≥0) : + (fixedFlows (fun i ↦ (i + 1 : ℝ≥0) * Δt) (fun _ ↦ c) n : Contract ι).pathPV + (fun τ ↦ zcb r 0 τ) s = annuityValue n c r Δt := by + rw [pathPV_fixedFlows, annuityValue] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + simp only [zcb, sub_zero, NNReal.coe_mul, NNReal.coe_add, NNReal.coe_natCast, NNReal.coe_one] + ring + +variable (P : ℝ≥0 → ℝ) (T : ℕ → ℝ≥0) (δ : ℝ) (n : ℕ) + +/-- The **floating leg** of a swap on the deterministic discount curve `P`, with payment dates +`T 1, …, T n` and accrual `δ`: at `T (i + 1)` it pays `δ` times the simple forward rate the curve +implies for `[T i, T (i + 1)]`. -/ +noncomputable def floatingLeg : Contract ι := + fixedFlows (fun i ↦ T (i + 1)) (fun i ↦ δ * fraForwardRate (P (T i)) (P (T (i + 1))) δ) n + +/-- The **fixed leg** of a swap with fixed rate `K`: `δK` at each of `T 1, …, T n`. -/ +noncomputable def fixedLeg (K : ℝ) : Contract ι := fixedFlows (fun i ↦ T (i + 1)) (fun _ ↦ δ * K) n + +/-- The **payer swap**: receive the floating leg, pay the fixed leg. -/ +noncomputable def payerSwap (K : ℝ) : Contract ι := + .both (floatingLeg P T δ n) (.scale (-1) (fixedLeg T δ n K)) + +variable {P T δ} + +/-- **The floating leg telescopes.** Discounted on its own curve, each forward-rate coupon is +worth `P(Tᵢ) − P(Tᵢ₊₁)`, so the leg is worth `P(T₀) − P(Tₙ)`. -/ +theorem pathPV_floatingLeg (hδ : δ ≠ 0) (hP : ∀ i, P (T i) ≠ 0) (s : Scenario ι) : + (floatingLeg P T δ n : Contract ι).pathPV P s = P (T 0) - P (T n) := by + rw [floatingLeg, pathPV_fixedFlows] + induction n with + | zero => simp + | succ n ih => + rw [Finset.sum_range_succ, ih, fraForwardRate] + field_simp [hP (n + 1)] + ring + +/-- The fixed leg is worth `K` times the annuity of its payment dates. -/ +theorem pathPV_fixedLeg (K : ℝ) (s : Scenario ι) : + (fixedLeg T δ n K : Contract ι).pathPV P s + = K * annuity δ (fun i ↦ P (T (i + 1))) (Finset.range n) := by + rw [fixedLeg, pathPV_fixedFlows, annuity, Finset.mul_sum, Finset.mul_sum] + exact Finset.sum_congr rfl fun i _ ↦ by ring + +/-- **A payer swap on a deterministic curve is worth `payerSwapValue`** in every model: the +floating leg `P(T₀) − P(Tₙ)` less `K` times the annuity. -/ +theorem value_payerSwap {Q : Measure Ω} [IsProbabilityMeasure Q] (X : ι → ℝ≥0 → Ω → ℝ) + (hδ : δ ≠ 0) (hP : ∀ i, P (T i) ≠ 0) (K : ℝ) : + (payerSwap P T δ n K : Contract ι).value Q (fun t _ ↦ P t) X + = payerSwapValue (P (T 0)) (P (T n)) K (annuity δ (fun i ↦ P (T (i + 1))) (Finset.range n)) := + Contract.value_eq_of_pathPV_eq X fun _ ↦ by + rw [payerSwap, Contract.pathPV_both, Contract.pathPV_scale, pathPV_floatingLeg n hδ hP, + pathPV_fixedLeg, payerSwapValue] + ring + +/-- **A forward-rate agreement is a one-period payer swap.** With one accrual period `[T₀, T₁]` +the swap's floating coupon is the simple forward rate `fraForwardRate (P T₀) (P T₁) δ` and the +fixed coupon is `δK`, both paid at `T₁`; its value in every model is `fraValue` +(`Models/Rates/FRA.lean`): `δ · P(T₁) · (F − K)`. -/ +theorem value_payerSwap_one_eq_fraValue {Q : Measure Ω} [IsProbabilityMeasure Q] + (X : ι → ℝ≥0 → Ω → ℝ) (hδ : δ ≠ 0) (hP : ∀ i, P (T i) ≠ 0) (K : ℝ) : + (payerSwap P T δ 1 K : Contract ι).value Q (fun t _ ↦ P t) X + = fraValue δ (P (T 1)) (fraForwardRate (P (T 0)) (P (T 1)) δ) K := by + rw [value_payerSwap 1 X hδ hP, fraValue_forwardRate_eq_discount_difference _ _ _ _ hδ (hP 1), + payerSwapValue, annuity] + simp only [Finset.sum_range_one, zero_add] + ring + +/-- **A payer swap is worth zero exactly at the par swap rate.** -/ +theorem value_payerSwap_eq_zero_iff {Q : Measure Ω} [IsProbabilityMeasure Q] + (X : ι → ℝ≥0 → Ω → ℝ) (hδ : δ ≠ 0) (hP : ∀ i, P (T i) ≠ 0) + (hA : annuity δ (fun i ↦ P (T (i + 1))) (Finset.range n) ≠ 0) (K : ℝ) : + (payerSwap P T δ n K : Contract ι).value Q (fun t _ ↦ P t) X = 0 + ↔ K = parSwapRate (P (T 0)) (P (T n)) + (annuity δ (fun i ↦ P (T (i + 1))) (Finset.range n)) := by + rw [value_payerSwap n X hδ hP] + exact payerSwapValue_eq_zero_iff _ _ _ hA + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Models/Rates/DeterministicMarket.lean b/LeanPool/MathFin/Models/Rates/DeterministicMarket.lean new file mode 100644 index 0000000000..02a5d2fb07 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/DeterministicMarket.lean @@ -0,0 +1,173 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.Market +public import LeanPool.MathFin.Models.Rates.DeterministicCurve +public import LeanPool.MathFin.Models.Rates.Immunization + +/-! +# The deterministic-rates bond market + +The simplest term-structure model as a `Market`: a deterministic bank account `N` +(`N t = e^{rt}` for a flat rate) as numéraire, and zero-coupon bonds `P(t, τᵢ) = N t / N τᵢ` as +the traded assets (`deterministicMarket`). After its maturity a bond is worth what its proceeds +earn in the bank account, so the formula holds at every date and the bond is a self-financing +position. Nothing is random, so every probability measure is a pricing measure +(`isPricingMeasure_deterministicMarket`): the deflated bond `P(t, τᵢ) / N t = 1 / N τᵢ` is +constant. + +In any market with a deterministic numéraire a schedule of fixed cash flows is worth its flows +discounted by `N 0 / N` (`price_fixedFlows_deterministicMarket`), and the price of a unit payment +at `τᵢ` is the bond's price (`price_pay_deterministicMarket`). The first-order immunization and +the key-rate durations of `Models/Rates/` differentiate such a flat-rate value, and the value +of a zero-coupon portfolio is the price of its schedule when the numéraire is `e^{rt}`, and the +price of a coupon bond at an annually compounded yield `y` is the price of its schedule when the +numéraire is `(1 + y)^⌊t⌋` (`bondPortfolioValue_eq_price`). + +The stochastic short-rate models (`Models/Rates/ShortRate.lean`) price the same schedules through +their zero curve; that their bonds are martingales after deflation by the bank account is not +proved here. + +## Main definitions + +* `MathFin.Rates.deterministicMarket`: the market of a deterministic numéraire with zero-coupon + bonds of given maturities. + +## Main results + +* `MathFin.Rates.isPricingMeasure_deterministicMarket`: every probability measure prices the + deterministic bond market, at every horizon. +* `MathFin.Rates.price_pay_deterministicMarket`: the price of a unit payment at `τᵢ` is the + bond's market price `N 0 / N τᵢ`. +* `MathFin.Rates.price_fixedFlows_deterministicMarket`: a schedule of fixed cash flows is worth + its flows discounted by the numéraire. +* `MathFin.Rates.bondPortfolioValue_eq_price_exp`, `bondPriceDisc_eq_price`: the flat-rate value of + a zero-coupon portfolio (numéraire `e^{rt}`) and the annually compounded price of a coupon bond + (numéraire `(1 + y)^⌊t⌋`) are market prices. +* `MathFin.Rates.bondPortfolioValue_eq_price`: the two in one conjunction. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + Section 1.5 +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], ch. 4 + +## Tags + +term structure, zero-coupon bond, bank account, pricing measure, deterministic interest rates, +bond immunization, MSC 91G30, JEL E43, JEL G12 +-/ + +@[expose] public section + +open MeasureTheory MathFin.Contracts +open scoped NNReal + +namespace MathFin.Rates + +variable {ι Ω : Type*} [mΩ : MeasurableSpace Ω] + +/-- **The deterministic-rates bond market**: the physical measure `P`, the trivial filtration, +the deterministic numéraire `N` (the bank account), and for each `i` the zero-coupon bond of +maturity `τ i`, worth `N t / N (τ i)` at `t`. -/ +noncomputable def deterministicMarket (P : Measure Ω) (N : ℝ≥0 → ℝ) (hN : ∀ t, 0 < N t) + (τ : ι → ℝ≥0) : Market ι Ω where + P := P + 𝓕 := Filtration.const ℝ≥0 ⊥ bot_le + asset i t _ := N t / N (τ i) + numeraire t _ := N t + numeraire_pos t _ := hN t + asset_adapted _ _ := stronglyMeasurable_const + numeraire_adapted _ := stronglyMeasurable_const + +/-- **Every probability measure prices the deterministic bond market.** The deflated bond +`(N t / N τᵢ) / N t = 1 / N τᵢ` is constant in time and in the outcome, hence a martingale. -/ +theorem isPricingMeasure_deterministicMarket (P : Measure Ω) [IsProbabilityMeasure P] + (N : ℝ≥0 → ℝ) (hN : ∀ t, 0 < N t) (τ : ι → ℝ≥0) (T : ℝ≥0) : + (deterministicMarket P N hN τ).IsPricingMeasure T P := + ⟨inferInstance, Measure.AbsolutelyContinuous.refl _, Measure.AbsolutelyContinuous.refl _, + fun i ↦ by + have h : (fun t (ω : Ω) ↦ (deterministicMarket P N hN τ).deflated i (min t T) ω) + = fun _ _ ↦ 1 / N (τ i) := by + funext t ω + have := (hN (min t T)).ne' + simp only [Market.deflated, deterministicMarket] + field_simp + rw [h] + exact martingale_const _ _ _⟩ + +/-- **The price of a unit payment at `τᵢ` is the bond's price.** In the deterministic bond market +the unit payment at `τ i` is worth the bond's price `N 0 / N (τ i)` today, under any probability +measure. -/ +theorem price_pay_deterministicMarket (P : Measure Ω) (N : ℝ≥0 → ℝ) (hN : ∀ t, 0 < N t) + (τ : ι → ℝ≥0) (Q : Measure Ω) [IsProbabilityMeasure Q] (i : ι) (ω : Ω) : + (deterministicMarket P N hN τ).price Q (.pay (τ i) (.const 1)) + = (deterministicMarket P N hN τ).asset i 0 ω := by + rw [Market.price, Contract.value_pay] + simp [Payoff.eval, Market.deflator, deterministicMarket] + +/-- **A schedule of fixed cash flows is worth its flows discounted by the numéraire**: in the +deterministic bond market, `∑ cᵢ N 0 / N (tᵢ)`, under any probability measure. -/ +theorem price_fixedFlows_deterministicMarket (P : Measure Ω) (N : ℝ≥0 → ℝ) + (hN : ∀ t, 0 < N t) (τ : ι → ℝ≥0) (Q : Measure Ω) [IsProbabilityMeasure Q] + (t : ℕ → ℝ≥0) (c : ℕ → ℝ) (n : ℕ) : + (deterministicMarket P N hN τ).price Q (fixedFlows t c n) + = ∑ i ∈ Finset.range n, N 0 / N (t i) * c i := + value_fixedFlows_deterministic (fun s ↦ N 0 / N s) _ t c n + +/-- **The flat-rate value of a bond portfolio is a market price.** In any market with the money +market `e^{rt}` as numéraire, under any probability measure `Q`, the portfolio of zero-coupon +bonds of face `w i` and maturity `T i ≥ 0` (`bondPortfolioValue` at time `0`) is the price of the +schedule `fixedFlows`. -/ +theorem bondPortfolioValue_eq_price_exp (Q : Measure Ω) [IsProbabilityMeasure Q] (n : ℕ) + (w T : ℕ → ℝ) (hT : ∀ i, 0 ≤ T i) (M : Market ι Ω) (r : ℝ) + (hM : ∀ t ω, M.numeraire t ω = Real.exp (r * t)) : + MathFin.bondPortfolioValue (Finset.range n) w T 0 r = + M.price Q (fixedFlows (fun i ↦ (T i).toNNReal) w n) := by + have hD : M.deflator = fun (s : ℝ≥0) _ ↦ Real.exp (-(r * s)) := by + funext s ω + simp only [Market.deflator_of_numeraire_exp hM, neg_mul] + rw [Market.price, hD, value_fixedFlows_deterministic, MathFin.bondPortfolioValue] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + simp only [Real.coe_toNNReal _ (hT i), sub_zero] + ring + +/-- **The annually compounded price of a coupon bond is a market price.** In any market with the +numéraire `(1 + y)^⌊t⌋`, under any probability measure `Q`, the coupon bond at the annually +compounded yield `y` (`bondPriceDisc`) is the price of its cash flows. -/ +theorem bondPriceDisc_eq_price (Q : Measure Ω) [IsProbabilityMeasure Q] (n : ℕ) + (w : ℕ → ℝ) (M : Market ι Ω) (y : ℝ) (t : ℕ → ℕ) + (hM : ∀ s ω, M.numeraire s ω = (1 + y) ^ ⌊s⌋₊) : + MathFin.bondPriceDisc (Finset.range n) t w y = + M.price Q (fixedFlows (fun i ↦ ((t i : ℕ) : ℝ≥0)) w n) := by + have hD : M.deflator = fun (s : ℝ≥0) _ ↦ ((1 + y) ^ ⌊s⌋₊)⁻¹ := by + funext s ω + simp only [Market.deflator_of_numeraire hM, Nat.floor_zero, pow_zero, one_div] + rw [Market.price, hD, value_fixedFlows_deterministic, MathFin.bondPriceDisc] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + simp only [Nat.floor_natCast] + ring + +/-- **The flat-rate value of a bond portfolio and the discrete price of a coupon bond are market +prices** (`bondPortfolioValue_eq_price_exp`, `bondPriceDisc_eq_price`): the two facts in one +statement, one per numéraire, `e^{rt}` and `(1 + y)^⌊t⌋`. -/ +theorem bondPortfolioValue_eq_price (Q : Measure Ω) [IsProbabilityMeasure Q] (n : ℕ) + (w T : ℕ → ℝ) (hT : ∀ i, 0 ≤ T i) : + (∀ (M : Market ι Ω) (r : ℝ), (∀ t ω, M.numeraire t ω = Real.exp (r * t)) → + MathFin.bondPortfolioValue (Finset.range n) w T 0 r = + M.price Q (fixedFlows (fun i ↦ (T i).toNNReal) w n)) ∧ + (∀ (M : Market ι Ω) (y : ℝ) (t : ℕ → ℕ), + (∀ s ω, M.numeraire s ω = (1 + y) ^ ⌊s⌋₊) → + MathFin.bondPriceDisc (Finset.range n) t w y = + M.price Q (fixedFlows (fun i ↦ ((t i : ℕ) : ℝ≥0)) w n)) := + ⟨fun M r hM ↦ bondPortfolioValue_eq_price_exp Q n w T hT M r hM, + fun M y t hM ↦ bondPriceDisc_eq_price Q n w M y t hM⟩ + +end MathFin.Rates diff --git a/LeanPool/MathFin/Models/Rates/DurationSensitivity.lean b/LeanPool/MathFin/Models/Rates/DurationSensitivity.lean new file mode 100644 index 0000000000..554e7b9a80 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/DurationSensitivity.lean @@ -0,0 +1,131 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.MacaulayModified +public import Mathlib.Algebra.Ring.IsFormallyReal +public import Mathlib.Analysis.Calculus.Deriv.Add +public import Mathlib.Analysis.Calculus.Deriv.Inv +public import Mathlib.Analysis.Calculus.Deriv.Pow +public import Mathlib.Analysis.InnerProductSpace.Basic +public import Mathlib.Topology.Algebra.Module.ModuleTopology + +/-! +# Duration as price sensitivity (first-principles derivation) + +For a coupon bond with discrete-compounded yield `y` and cashflows `c_i` at +times `t_i ∈ ℕ`, + + `P(y) = Σ c_i / (1 + y)^{t_i}`. + +The **modified duration** is `D_mod(y) = ModNum(y) / P(y)` where +`ModNum(y) = Σ t_i · c_i / (1 + y)^{t_i + 1}`. + +The classical sensitivity identity states + + `dP/dy = -D_mod · P`, equivalently `P'(y) = -ModNum(y)`. + +Pre-existing content in `Models.Rates.MacaulayModified` defines `bondPriceDisc`, +`macaulayNumerator`, `modifiedNumerator`, and proves the algebraic relation +`ModNum = MacNum / (1 + y)`. It does **not** derive duration as the price +derivative — the connection between duration and price sensitivity is +exactly the first-principles claim formalized here. + +## Building blocks + +* `hasDerivAt_coupon_term`: per-cashflow derivative + `d/dy [c / (1+y)^n] = -n · c / (1+y)^(n+1)`. +* `hasDerivAt_bondPriceDisc`: sum over cashflows gives + `dP/dy = -ModNum(y)`. +* `bondPriceDisc_deriv_eq_neg_modified_duration_times_price`: the + duration-sensitivity identity in its usual form + `P'(y) / P(y) = -D_mod(y)` (for `P(y) ≠ 0`). + +## Main results + +* `hasDerivAt_coupon_term`: `d/dy [c / (1+y)^n] = -n · c / (1+y)^(n+1)`. +* `hasDerivAt_bondPriceDisc`: for `1 + y ≠ 0`, the bond price `P(y) = Σ c_i / (1 + y)^{t_i}` has + derivative `-ModNum(y)` at `y`. +* `bondPriceDisc_deriv_eq_neg_modified_duration_times_price`: for `1 + y ≠ 0`, the derivative `P'` + satisfies `P' / P(y) = -(ModNum(y) / P(y))`, i.e. `P'/P = -D_mod`. + +## Tags + +modified duration, price sensitivity, interest rate risk, bond duration, yield derivative, +coupon bond, MSC 91G30, JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +open Finset + +variable {ι : Type*} + +/-- **Per-cashflow derivative**: `d/dy [c / (1+y)^n] = -n · c / (1+y)^(n+1)`. + +Proof: chain rule via `HasDerivAt.pow` on `(1 + y')^n`, then `HasDerivAt.div` +with a constant numerator. The `n = 0` and `n ≥ 1` cases are bundled by the +final `field_simp + ring`. -/ +lemma hasDerivAt_coupon_term (c_val : ℝ) (n : ℕ) {y : ℝ} (hy : 1 + y ≠ 0) : + HasDerivAt (fun y' ↦ c_val / (1 + y') ^ n) + (-((n : ℝ) * c_val / (1 + y) ^ (n + 1))) y := by + have h_base : HasDerivAt (fun y' : ℝ ↦ (1 : ℝ) + y') 1 y := + (hasDerivAt_id y).const_add 1 + have h_pow : HasDerivAt (fun y' : ℝ ↦ (1 + y') ^ n) + ((n : ℝ) * (1 + y) ^ (n - 1) * 1) y := h_base.pow n + have h_pow_ne : (1 + y) ^ n ≠ 0 := pow_ne_zero _ hy + have h_const : HasDerivAt (fun _ : ℝ ↦ c_val) 0 y := hasDerivAt_const y c_val + have h_div := h_const.div h_pow h_pow_ne + rw [show (-((n : ℝ) * c_val / (1 + y) ^ (n + 1))) + = (0 * (1 + y) ^ n - c_val * ((n : ℝ) * (1 + y) ^ (n - 1) * 1)) / ((1 + y) ^ n) ^ 2 from by + cases n with + | zero => simp + | succ m => + simp only [Nat.add_sub_cancel] + have h_pow_m_ne : (1 + y) ^ m ≠ 0 := pow_ne_zero _ hy + field_simp + ring] + exact h_div + +/-- **Bond price has derivative `-ModNum(y)`**: the modified duration +numerator is the negative slope of the bond price. + +Proof: term-by-term derivative via `hasDerivAt_coupon_term`, summed over +the cashflow finset. The sum-of-functions vs function-of-sums identification +is handled by `Finset.sum_apply`. -/ +theorem hasDerivAt_bondPriceDisc + (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) {y : ℝ} (hy : 1 + y ≠ 0) : + HasDerivAt (bondPriceDisc s t c) + (-modifiedNumerator s t c y) y := by + unfold bondPriceDisc modifiedNumerator + rw [show -∑ i ∈ s, (t i : ℝ) * c i / (1 + y) ^ (t i + 1) = + ∑ i ∈ s, (-((t i : ℝ) * c i / (1 + y) ^ (t i + 1))) from by + rw [← Finset.sum_neg_distrib]] + apply HasDerivAt.fun_sum + intros i _ + exact hasDerivAt_coupon_term (c i) (t i) hy + +/-- **Duration-sensitivity identity**: `P'(y) / P(y) = -D_mod(y)`, where +`D_mod = ModNum / P` is the modified duration. + +This is the operational content of duration: it measures the *percentage* +sensitivity of bond price to yield. Combined with +`modifiedNumerator_eq_macaulayNumerator_div`, gives the standard +discrete-compounding identity `D_mod = D_Mac / (1 + y)`. -/ +theorem bondPriceDisc_deriv_eq_neg_modified_duration_times_price + (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) {y : ℝ} + (hy : 1 + y ≠ 0) : + ∃ P' : ℝ, HasDerivAt (bondPriceDisc s t c) P' y ∧ + P' / bondPriceDisc s t c y = + -(modifiedNumerator s t c y / bondPriceDisc s t c y) := by + refine ⟨-modifiedNumerator s t c y, hasDerivAt_bondPriceDisc s t c hy, ?_⟩ + rw [neg_div] + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/FRA.lean b/LeanPool/MathFin/Models/Rates/FRA.lean new file mode 100644 index 0000000000..25034dbc11 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/FRA.lean @@ -0,0 +1,92 @@ +/- +Copyright (c) 2026 Aleksey Salkutsan. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Aleksey Salkutsan +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.ZCB + +-- pointers: MathFin/Models/Rates/ZCB.lean +-- main-module: MathFin/Models/Rates/FRA.lean +-- benchmark: benchmarks/mathematical_finance.json +-- benchmark-id: mf-fixedincome-fra +-- source-issue: 67 +-- new-defs: fraForwardRate, fraValue + +/-! +# Forward-rate agreement + +The simple forward rate over one accrual period is + +`F = (P(0,T₁) / P(0,T₂) - 1) / δ`, + +and the time-zero value of the corresponding forward-rate agreement is + +`V = δ * P(0,T₂) * (F - K)`. + +## Main definitions + +* `fraForwardRate`: the simple forward rate implied by discount factors `P₁`, `P₂` over an accrual + period of length `δ`. +* `fraValue`: the time-zero value of a forward-rate agreement. + +## Main results + +* `fraValue_forwardRate_eq_discount_difference` expands the FRA value to + `P(0,T₁) - P(0,T₂) - δ * P(0,T₂) * K`. +* `fraValue_zcb_eq_discount_difference` instantiates that identity on the + library's zero-coupon-bond curve. +* `fraValue_zcb_eq_zero_iff` proves that the FRA has zero value exactly at the + simple forward rate, with denominator nonvanishing derived from `zcb_pos`. + +## Tags + +forward rate agreement, simple forward rate, FRA value, discount factor, zero-coupon curve, +MSC 91G30, JEL G13 +-/ + + +@[expose] public section + +namespace MathFin + +/-- Simple forward rate implied by discount factors `P₁`, `P₂` over an accrual +period of length `δ`. -/ +noncomputable def fraForwardRate (P1 P2 δ : ℝ) : ℝ := (P1 / P2 - 1) / δ + +/-- Time-zero value of a forward-rate agreement. -/ +def fraValue (δ P2 F K : ℝ) : ℝ := δ * P2 * (F - K) + +/-- Substituting the simple forward rate into the FRA value gives the +discount-factor difference net of the fixed payment. -/ +theorem fraValue_forwardRate_eq_discount_difference (P1 P2 δ K : ℝ) + (hδ : δ ≠ 0) (hP2 : P2 ≠ 0) : + fraValue δ P2 (fraForwardRate P1 P2 δ) K = P1 - P2 - δ * P2 * K := by + unfold fraValue fraForwardRate + field_simp + +/-- The FRA value identity on the deterministic zero-coupon-bond curve. -/ +theorem fraValue_zcb_eq_discount_difference (r δ K T1 T2 : ℝ) (hδ : δ ≠ 0) : + fraValue δ (zcb r 0 T2) (fraForwardRate (zcb r 0 T1) (zcb r 0 T2) δ) K = + zcb r 0 T1 - zcb r 0 T2 - δ * zcb r 0 T2 * K := + fraValue_forwardRate_eq_discount_difference _ _ _ _ hδ (zcb_pos r 0 T2).ne' + +/-- On the zero-coupon-bond curve, the FRA has zero value exactly when its +fixed rate is the simple forward rate. -/ +theorem fraValue_zcb_eq_zero_iff (r δ K T1 T2 : ℝ) (hδ : δ ≠ 0) : + fraValue δ (zcb r 0 T2) (fraForwardRate (zcb r 0 T1) (zcb r 0 T2) δ) K = 0 ↔ + K = fraForwardRate (zcb r 0 T1) (zcb r 0 T2) δ := by + unfold fraValue + have hscale : δ * zcb r 0 T2 ≠ 0 := mul_ne_zero hδ (zcb_pos r 0 T2).ne' + constructor + · intro h + rcases mul_eq_zero.mp h with h | h + · exact (hscale h).elim + · exact (sub_eq_zero.mp h).symm + · intro h + rw [h, sub_self, mul_zero] + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/ForwardMeasure.lean b/LeanPool/MathFin/Models/Rates/ForwardMeasure.lean new file mode 100644 index 0000000000..9b28866614 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/ForwardMeasure.lean @@ -0,0 +1,55 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.ForwardMeasure +public import LeanPool.MathFin.Models.BlackScholes.Forward + +/-! +# The Black–Scholes forward price under the T-forward measure + +The T-forward measure `forwardMeasure Q B` (the zero-coupon bond as numéraire, bank account `B`), +its probability and the bond-numéraire change of measure `forwardMeasure_price` are in +`Pricing/ForwardMeasure.lean`. In the **constant-rate** world the density `dQ^T/dQ` is `1` +and `Q^T = Q`; this file reads the forward price off the Black–Scholes terminal. + +## Main results + +* `forwardMeasure_bs_expected_terminal` — the concrete Black–Scholes instance: + `𝔼^{Q^T}[S_T] = S_0·e^{rT}`. + +## References + +* [H. Geman, N. El Karoui and J. C. Rochet, *Changes of numéraire, changes of probability measure + and option pricing*][GemanElKarouiRochet1995] + +## Tags + +T-forward measure, bond numéraire, change of numéraire, forward price, Black–Scholes, constant rate, +MSC 91G20, MSC 91G30, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +variable {Ω : Type*} [MeasurableSpace Ω] + +/-- **The Black–Scholes forward price under the T-forward measure**: for the +`BSCallHyp` lognormal terminal, `𝔼^{Q^T}[S_T] = S_0·e^{rT}`. Combines the +`Q^T`-expectation identity with the discounted-terminal EMM property +`discounted_terminal_eq_S0`. -/ +theorem forwardMeasure_bs_expected_terminal {Q : Measure Ω} [IsProbabilityMeasure Q] + {S_0 K r σ T : ℝ} {Z : Ω → ℝ} (h : BSCallHyp Q S_0 K r σ T Z) : + ∫ ω, bsTerminal S_0 r σ T (Z ω) ∂(forwardMeasure Q fun _ ↦ Real.exp (r * T)) + = S_0 * Real.exp (r * T) := + forwardMeasure_expected_spot S_0 r T _ (discounted_terminal_eq_S0 h) + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/ForwardRate.lean b/LeanPool/MathFin/Models/Rates/ForwardRate.lean new file mode 100644 index 0000000000..e94ecf86c6 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/ForwardRate.lean @@ -0,0 +1,82 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Analysis.ExponentialDiscount +public import Mathlib.Analysis.Calculus.Deriv.Mul + +/-! +# Forward rate from a non-flat spot-rate curve + +Given a continuously-compounded spot-rate curve `T ↦ R(T)` with `R'(T)`, the +zero-coupon bond price is `P(T) = exp(−T · R(T))`, so + + `forwardRate(T) := −d/dT log P(T) = d/dT [T · R(T)] = R(T) + T · R'(T)`. + +This generalizes the flat-curve case (`R(T) ≡ R₀ ⇒ forward = R₀`) covered by +`hasDerivAt_neg_log_zcb_T` in `CouponBonds.lean`. The non-flat case is purely +the product-rule chain rule applied to `T · R(T)`. + +This is an instance of the `Probability/Analysis/ExponentialDiscount` principle at +`H(T) = T · R(T)`: the forward rate is the negative log-derivative of the +discount factor `exp(−H(T))`. The calculus lemma `hasDerivAt_T_mul_spotRate` +supplies `H'`, and `forwardRate_eq_neg_log_discount` routes it through the +principle to express the result in terms of the actual bond price `P(T)`. + +## Main results + +* `hasDerivAt_T_mul_spotRate`: the forward-rate derivative formula + `d/dT (T·R(T)) = R(T) + T·R'(T)` — this *is* the non-flat-curve forward rate + in the `−log P` parametrisation. +* `forwardRate_eq_neg_log_discount`: forward rate as `−d/dT log P(T)` with the + actual discount factor `P(T) = exp(−T · R(T))`, via the + `ExponentialDiscount` principle. + +## References + +* [Fabozzi, *Fixed Income Mathematics*][FabozziFIM], 5.2 +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 4.7 + +## Tags + +instantaneous forward rate, spot rate curve, zero-coupon yield, term structure, +log-derivative of bond price, MSC 91G30, JEL E43 +-/ + +@[expose] public section + +namespace MathFin + +/-- **Forward-rate calculus identity** / **forward rate from a non-flat spot +curve**: `d/dT [T · R(T)] = R(T) + T · R'(T)` when `R` is differentiable at `T`. +Writing `F(T) := −log P(T) = T · R(T)` for a zero-coupon bond `P(T) = +exp(−T·R(T))`, the instantaneous forward rate at horizon `T` is exactly this +derivative `F'(T) = R(T) + T·R'(T)` — so this single lemma *is* the +non-flat-curve forward-rate formula (in the `−log P` parametrisation; the +version against the actual discount factor is `forwardRate_eq_neg_log_discount` +below). -/ +theorem hasDerivAt_T_mul_spotRate {R : ℝ → ℝ} {R'_T T : ℝ} + (hR : HasDerivAt R R'_T T) : + HasDerivAt (fun t ↦ t * R t) (R T + T * R'_T) T := by + have h_id : HasDerivAt (fun t : ℝ ↦ t) 1 T := hasDerivAt_id _ + have h_mul := h_id.mul hR + convert h_mul using 1; ring + +/-- **Forward rate as the negative log-derivative of the bond price** +(`Probability/Analysis/ExponentialDiscount`, instantiated at `H(T) = T · R(T)`). The +zero-coupon bond is `P(T) = exp(−T · R(T))`; the instantaneous forward rate +`−d/dT log P(T)` equals `R(T) + T · R'(T)`. Unlike `hasDerivAt_T_mul_spotRate`, +this states the result against the *actual* discount factor rather than the +`−log P` shortcut, by routing the calculus lemma through the +`rate_eq_neg_log_deriv` principle. -/ +theorem forwardRate_eq_neg_log_discount {R : ℝ → ℝ} {R'_T T : ℝ} + (hR : HasDerivAt R R'_T T) : + HasDerivAt (fun t ↦ -(Real.log (Real.exp (-(t * R t))))) (R T + T * R'_T) T := + rate_eq_neg_log_deriv (hasDerivAt_T_mul_spotRate hR) + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/GSRBond.lean b/LeanPool/MathFin/Models/Rates/GSRBond.lean new file mode 100644 index 0000000000..d24e15850d --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/GSRBond.lean @@ -0,0 +1,68 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.Caplet +public import LeanPool.MathFin.Models.Rates.GSRBondPriceAt + +/-! +# Bond prices at `t > 0` in the GSR model + +For the GSR discount factor `D t = exp(−∫₀ᵗ r)` (`gsrIntegratedRate`, two-piece volatility) and the +natural filtration of the driving Brownian motion, `bondPrice` is the affine form of +`gsrBondPrice_condExp` (`Models/Rates/HullWhiteBond.lean` and `VasicekBond.lean` are the +constant-volatility counterparts): + + `P(t, T) = A(t, T)·exp(−B(T − t)·r_t)`, `A = gsrBondA`. + +## Main results + +* `bondPrice_gsr` — `bondPrice` in the GSR model, almost surely. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + section 3.3.1 +* [J. Hull and A. White, *Pricing interest-rate-derivative securities*][HullWhite1990] +* [The QuantLib contributors, *QuantLib*][QuantLib], Gsr model + +## Tags + +Gaussian short rate, GSR model, affine bond price, zero-coupon bond, conditional expectation, +MSC 91G30, JEL E43, JEL G12 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory +open scoped NNReal + +namespace MathFin.Contracts + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-- **The GSR bond price at time `t`.** With `D t = exp(−∫₀ᵗ r)` along the GSR integrated rate +(volatility `σ₁` up to `T*`, `σ₂` after) and `𝓕` the natural filtration of the driving Brownian +motion, the price at `t` of one unit paid at `T ≥ T*` is `P(t, T) = A(t, T)·exp(−B(T − t)·r_t)` +almost surely, where `r_t` is the short rate in its Wiener representation (`gsrShortRate`), `B` is +Vasicek's coefficient and `A = gsrBondA`. The measure is read as the pricing measure. -/ +theorem bondPrice_gsr (hB : IsPreBrownianReal B μ) (hBm : ∀ s, Measurable (B s)) + (r₀ θ σ1 σ2 : ℝ) {κ : ℝ} (hκ : 0 < κ) {Tstar t T : ℝ≥0} (htT : t ≤ T) (hTstarT : Tstar ≤ T) : + bondPrice μ (Filtration.natural B fun s ↦ (hBm s).stronglyMeasurable) + (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) t T + =ᵐ[μ] fun ω ↦ gsrBondA θ κ σ1 σ2 (Tstar : ℝ) t T + * Real.exp (-(vasicekBondB κ ((T : ℝ) - t) + * gsrShortRate hB r₀ θ σ1 σ2 hκ Tstar t ω)) := by + filter_upwards [gsrBondPrice_condExp hB hBm r₀ θ σ1 σ2 hκ htT hTstarT] with ω h + change (μ[fun ω ↦ Real.exp (-gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar T ω) | _]) ω + / Real.exp (-gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar t ω) = _ + rw [h, mul_div_cancel_left₀ _ (Real.exp_pos _).ne'] + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Models/Rates/GSRBondPriceAt.lean b/LeanPool/MathFin/Models/Rates/GSRBondPriceAt.lean new file mode 100644 index 0000000000..6cb478e5e0 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/GSRBondPriceAt.lean @@ -0,0 +1,312 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.GSRPiecewiseVol +public import LeanPool.MathFin.Models.Rates.VasicekBondPriceAt +public import LeanPool.MathFin.Pricing.WienerIntegralForwardMeasure + +/-! +# The GSR bond price at a time `t > 0` + +`Models/Rates/GSRPiecewiseVol.lean` prices the zero-coupon bond at time `0` when the volatility is +`σ₁` up to the breakpoint `T*` and `σ₂` after it. This file prices it at a later time `t`, given +the information `𝓕_t = σ(B_s : s ≤ t)` of the driving Brownian motion: + + `𝔼[exp(−∫₀ᵀ r) | 𝓕_t] = exp(−∫₀ᵗ r)·A(t, T)·exp(−B(T − t)·r_t)` almost surely, + +with the Vasicek coefficient `B`, the short rate `r_t = m_t + ∫₀ᵗ σ(u) e^{−κ(t−u)} dB_u` +(`gsrShortRate`) and `A(t, T) = exp(−θ(τ − B(τ)) + Var_{(t,T]}/2)`, `τ = T − t`, where the +variance is that of the remainder `∫_t^T σ(u) g_T(u) dB_u` (`gsrBondVIoc`). Unlike the Vasicek and +Hull–White coefficients, `A` depends on `t` and `T` separately and not only on `T − t`, because +the volatility is not time-homogeneous. + +It is the instance of `condExp_exp_neg_wienerIntegralLp` (`Models/Rates/VasicekBondPriceAt.lean`) at +the GSR kernel: the Vasicek mean identity is unchanged, and the kernel seen from `t` splits as +`σ(u) g_T(u) = σ(u) g_t(u) + B(T − t)·σ(u) e^{−κ(t−u)}` on `(0, t]`. + +## Main definitions + +* `gsrShortKernel`, `gsrShortKernelLp`: the GSR short-rate kernel `u ↦ σ(u)·e^{−κ(t−u)}`, and + the same kernel as an element of `L²((0, t])`. +* `gsrShortRate`: the GSR short rate `r_t = m_t + ∫₀ᵗ σ(u) e^{−κ(t−u)} dB_u` in its Wiener + representation. +* `gsrBondA`: the GSR affine coefficient `A(t, T) = exp(−θ(τ − B(τ)) + Var_{(t,T]}/2)` with + `τ = T − t`. +* `gsrShortRateV`: the GSR short-rate variance `∫₀ᵗ σ(u)² e^{−2κ(t−u)} du` in closed form. + +## Main results + +* `kernelRestrict_gsrKernelLp` — the GSR kernel seen from `t`. +* `integral_sq_gsrKernelLp_Ioc` — the variance of the remainder. +* `gsrBondPrice_condExp` — the conditional discount factor, affine in `r_t`. +* `gsrShortRateV`, `gsrShortKernel_integral_sq_eq`, `gsrShortRateV_pos` — the variance + `∫₀ᵗ σ(u)² e^{−2κ(t−u)} du` of the short rate in closed form, and its positivity. +* `gsrShortRate_hasLaw_gaussian`, `gsrShortRate_hasLaw_forwardMeasure` — the law of `r_t`, under + the pricing measure and under the `t`-forward measure (the same variance, the mean shifted by + minus the covariance with `∫₀ᵗ r`): the input of the bond put + (`Models/Rates/Jamshidian.lean`). + +## References + +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + section 3.3.1 +* [J. Hull and A. White, *Pricing interest-rate-derivative securities*][HullWhite1990] +* [The QuantLib contributors, *QuantLib*][QuantLib], Gsr model + +## Tags + +Gaussian short rate, GSR model, conditional bond price, piecewise volatility, affine bond price, +forward measure, MSC 91G30, MSC 60G15, JEL E43 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal +open WienerIntegralL2 +open scoped InnerProductSpace + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + +/-! ### The short-rate kernel -/ + +/-- The **GSR short-rate kernel** `u ↦ σ(u)·e^{−κ(t−u)}`: the Vasicek kernel weighted by the +piecewise volatility, the integrand of the diffusion part of the short rate `r_t`. -/ +noncomputable def gsrShortKernel (σ1 σ2 Tstar κ t : ℝ) : ℝ → ℝ := + fun u ↦ gsrSigma σ1 σ2 Tstar u * vasicekKernel κ t u + +/-- The GSR short-rate kernel is in `L²((0, t])`: `|σ(u)| ≤ max |σ₁| |σ₂|` and +`0 < e^{−κ(t−u)} ≤ 1` on the window. -/ +lemma gsrShortKernel_memLp {κ : ℝ} (hκ : 0 ≤ κ) (σ1 σ2 Tstar : ℝ) (t : ℝ≥0) : + MemLp (gsrShortKernel σ1 σ2 Tstar κ t) 2 (volume.restrict (Set.Ioc (0 : ℝ) t)) := by + refine (memLp_top_of_bound + (by unfold gsrShortKernel vasicekKernel + exact ((gsrSigma_measurable σ1 σ2 Tstar).mul (by fun_prop)).aestronglyMeasurable) + (max |σ1| |σ2|) ?_).mono_exponent le_top + refine (ae_restrict_iff' measurableSet_Ioc).mpr (ae_of_all _ fun u hu ↦ ?_) + rw [gsrShortKernel, Real.norm_eq_abs, abs_mul, vasicekKernel, + abs_of_pos (Real.exp_pos _)] + have hσ : |gsrSigma σ1 σ2 Tstar u| ≤ max |σ1| |σ2| := by + unfold gsrSigma; split + · exact le_max_left _ _ + · exact le_max_right _ _ + have he : Real.exp (-(κ * ((t : ℝ) - u))) ≤ 1 := + Real.exp_le_one_iff.mpr (by nlinarith [mul_nonneg hκ (sub_nonneg.2 hu.2)]) + calc |gsrSigma σ1 σ2 Tstar u| * Real.exp (-(κ * ((t : ℝ) - u))) + ≤ max |σ1| |σ2| * 1 := + mul_le_mul hσ he (Real.exp_pos _).le ((abs_nonneg _).trans hσ) + _ = max |σ1| |σ2| := mul_one _ + +/-- The GSR short-rate kernel as an element of `L²((0, t])`. -/ +noncomputable def gsrShortKernelLp {κ : ℝ} (hκ : 0 ≤ κ) (σ1 σ2 Tstar : ℝ) (t : ℝ≥0) : + Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (t : ℝ))) := + (gsrShortKernel_memLp hκ σ1 σ2 Tstar t).toLp _ + +/-- **The GSR short rate** `r_t = m_t + ∫₀ᵗ σ(u) e^{−κ(t−u)} dB_u`, in its Wiener representation: +the Vasicek mean plus the Wiener integral of `gsrShortKernel`. That it is the solution of the GSR +short-rate SDE, and that `gsrIntegratedRate` is its integral, is the modelling bridge, cited, not +derived (as for `vasicekIntegratedRate`). -/ +noncomputable def gsrShortRate (hB : IsPreBrownianReal B μ) (r₀ θ σ1 σ2 : ℝ) {κ : ℝ} + (hκ : 0 < κ) (Tstar t : ℝ≥0) (ω : Ω) : ℝ := + vasicekSDEMean r₀ θ κ (t : ℝ) + + wienerIntegralLp B hB t (gsrShortKernelLp hκ.le σ1 σ2 (Tstar : ℝ) t) ω + +/-! ### The kernel seen from `t` -/ + +lemma gsrKernelLp_coeFn {κ : ℝ} (hκ : 0 < κ) (σ1 σ2 Tstar : ℝ) (T : ℝ≥0) : + gsrKernelLp hκ σ1 σ2 Tstar T =ᵐ[volume.restrict (Set.Ioc (0 : ℝ) T)] + gsrKernel σ1 σ2 Tstar κ T := + (gsrKernel_memLp hκ σ1 σ2 Tstar T).coeFn_toLp + +lemma gsrShortKernelLp_coeFn {κ : ℝ} (hκ : 0 ≤ κ) (σ1 σ2 Tstar : ℝ) (t : ℝ≥0) : + gsrShortKernelLp hκ σ1 σ2 Tstar t =ᵐ[volume.restrict (Set.Ioc (0 : ℝ) t)] + gsrShortKernel σ1 σ2 Tstar κ t := + (gsrShortKernel_memLp hκ σ1 σ2 Tstar t).coeFn_toLp + +/-- **The horizon-`T` GSR kernel seen from time `t`.** On `(0, t]`, +`σ(u) g_T(u) = σ(u) g_t(u) + B(T − t)·σ(u) e^{−κ(t−u)}`: the Vasicek splitting +(`kernelRestrict_vasicekIntegratedKernelLp`) weighted by the volatility. -/ +lemma kernelRestrict_gsrKernelLp {κ : ℝ} (hκ : 0 < κ) (σ1 σ2 Tstar : ℝ) {t T : ℝ≥0} + (htT : t ≤ T) : + kernelRestrict htT (gsrKernelLp hκ σ1 σ2 Tstar T) + = gsrKernelLp hκ σ1 σ2 Tstar t + + vasicekBondB κ ((T - t : ℝ≥0) : ℝ) • gsrShortKernelLp hκ.le σ1 σ2 Tstar t := by + refine Lp.ext ?_ + filter_upwards [kernelRestrict_coeFn htT (gsrKernelLp hκ σ1 σ2 Tstar T), + (gsrKernelLp_coeFn hκ σ1 σ2 Tstar T).filter_mono + (ae_mono (volume_restrict_Ioc_mono htT)), + Lp.coeFn_add (gsrKernelLp hκ σ1 σ2 Tstar t) + (vasicekBondB κ ((T - t : ℝ≥0) : ℝ) • gsrShortKernelLp hκ.le σ1 σ2 Tstar t), + Lp.coeFn_smul (vasicekBondB κ ((T - t : ℝ≥0) : ℝ)) (gsrShortKernelLp hκ.le σ1 σ2 Tstar t), + gsrKernelLp_coeFn hκ σ1 σ2 Tstar t, gsrShortKernelLp_coeFn hκ.le σ1 σ2 Tstar t] + with u h1 h2 h3 h4 h5 h6 + rw [h3, Pi.add_apply, h1, h4, Pi.smul_apply, h5, h6, h2] + simp only [gsrKernel, gsrShortKernel, vasicekIntegratedKernel, vasicekKernel, vasicekBondB, + smul_eq_mul, NNReal.coe_sub htT] + have : Real.exp (-(κ * ((T : ℝ) - u))) + = Real.exp (-(κ * ((t : ℝ) - u))) * Real.exp (-(κ * ((T : ℝ) - t))) := by + rw [← Real.exp_add]; congr 1; ring + rw [this] + field_simp + ring + +/-- **The variance of the remainder.** `∫_t^T (σ g_T)(u)² du = gsrBondVIoc` (`T* ≤ T`). -/ +lemma integral_sq_gsrKernelLp_Ioc {κ : ℝ} (hκ : 0 < κ) (σ1 σ2 : ℝ) {Tstar t T : ℝ≥0} + (htT : t ≤ T) (hTstarT : Tstar ≤ T) : + ∫ s in Set.Ioc (t : ℝ) T, (gsrKernelLp hκ σ1 σ2 (Tstar : ℝ) T s) ^ 2 + = gsrBondVIoc κ σ1 σ2 (Tstar : ℝ) t T := by + rw [integral_congr_ae (g := fun s ↦ (gsrKernel σ1 σ2 (Tstar : ℝ) κ T s) ^ 2) + (((gsrKernelLp_coeFn hκ σ1 σ2 (Tstar : ℝ) T).filter_mono (ae_mono + (Measure.restrict_mono (Set.Ioc_subset_Ioc_left t.coe_nonneg) le_rfl))).mono + fun u hu ↦ congrArg (· ^ 2) hu)] + exact gsrKernel_integral_sq_Ioc_eq hκ σ1 σ2 (Tstar : ℝ) t T (NNReal.coe_le_coe.2 htT) + (NNReal.coe_le_coe.2 hTstarT) + +/-! ### The bond price at `t` -/ + +/-- The GSR affine coefficient at `t` for maturity `T`: +`A(t, T) = exp(−θ(τ − B(τ)) + Var_{(t,T]}/2)`, `τ = T − t`. -/ +noncomputable def gsrBondA (θ κ σ1 σ2 Tstar t T : ℝ) : ℝ := + Real.exp (-(θ * ((T - t) - vasicekBondB κ (T - t))) + gsrBondVIoc κ σ1 σ2 Tstar t T / 2) + +/-- **The GSR bond price at time `t`.** Given the information `𝓕_t` of the driving Brownian motion +and the breakpoint `T* ≤ T`, the discount factor `exp(−∫₀ᵀ r)` along the GSR integrated rate has +conditional mean + + `𝔼[exp(−∫₀ᵀ r) | 𝓕_t] = exp(−∫₀ᵗ r)·A(t, T)·exp(−B(T − t)·r_t)` + +almost surely, with `r_t` the GSR short rate in its Wiener representation (`gsrShortRate`), `B` +Vasicek's coefficient and `A` as in `gsrBondA`. Dividing by the discount factor known at `t`, the +price at `t` of one unit paid at `T` is `A(t, T)·exp(−B(T − t)·r_t)`. The measure is read as the +pricing measure; mean reversion and the level `θ` are constant, only the volatility is piecewise. -/ +theorem gsrBondPrice_condExp [IsProbabilityMeasure μ] (hB : IsPreBrownianReal B μ) + (hBm : ∀ s, Measurable (B s)) (r₀ θ σ1 σ2 : ℝ) {κ : ℝ} (hκ : 0 < κ) {Tstar t T : ℝ≥0} + (htT : t ≤ T) (hTstarT : Tstar ≤ T) : + μ[fun ω ↦ Real.exp (-gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar T ω) + | Filtration.natural B (fun s ↦ (hBm s).stronglyMeasurable) t] + =ᵐ[μ] fun ω ↦ Real.exp (-gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar t ω) + * (gsrBondA θ κ σ1 σ2 (Tstar : ℝ) t T + * Real.exp (-(vasicekBondB κ ((T : ℝ) - t) + * gsrShortRate hB r₀ θ σ1 σ2 hκ Tstar t ω))) := by + have key := condExp_exp_neg_wienerIntegralLp hB hBm htT (gsrKernelLp hκ σ1 σ2 (Tstar : ℝ) T) + (gsrKernelLp hκ σ1 σ2 (Tstar : ℝ) t) (gsrShortKernelLp hκ.le σ1 σ2 (Tstar : ℝ) t) + (kernelRestrict_gsrKernelLp hκ σ1 σ2 (Tstar : ℝ) htT) + (integral_sq_gsrKernelLp_Ioc hκ σ1 σ2 htT hTstarT) + (vasicekIntegratedMean_sub r₀ θ hκ.ne' htT) + rw [NNReal.coe_sub htT] at key + simp only [gsrIntegratedRate, gsrShortRate, gsrBondA] + exact key + +/-! ### The short rate under the forward measure -/ + +/-- **The GSR short-rate variance** `∫₀ᵗ σ(u)² e^{−2κ(t−u)} du`, in closed form +`σ₁²·(G(m) − G(0)) + σ₂²·(G(t) − G(m))`, with `G(u) = e^{−2κ(t−u)}/(2κ)` and `m = min(T*, t)` the +end of the part of `(0, t]` before the breakpoint. -/ +noncomputable def gsrShortRateV (κ σ1 σ2 Tstar t : ℝ) : ℝ := + σ1 ^ 2 * (vasicekKernelSqAntideriv κ t (min Tstar t) - vasicekKernelSqAntideriv κ t 0) + + σ2 ^ 2 * (vasicekKernelSqAntideriv κ t t - vasicekKernelSqAntideriv κ t (min Tstar t)) + +/-- **The squared `L²` norm of the GSR short-rate kernel**: splitting `(0, t]` at `min T* t`, where +`gsrSigma` is `σ₁` before and `σ₂` after, and applying `integral_vasicekKernel_sq_eq_sub` on each +piece. -/ +theorem gsrShortKernel_integral_sq_eq {κ : ℝ} (hκ : κ ≠ 0) (σ1 σ2 : ℝ) {Tstar t : ℝ} + (hTstar : 0 ≤ Tstar) (ht : 0 ≤ t) : + ∫ u in Set.Ioc (0 : ℝ) t, (gsrShortKernel σ1 σ2 Tstar κ t u) ^ 2 ∂volume + = gsrShortRateV κ σ1 σ2 Tstar t := by + set m := min Tstar t with hm + have hm0 : 0 ≤ m := le_min hTstar ht + have hmt : m ≤ t := min_le_right _ _ + have heq1 : Set.EqOn (fun u ↦ (gsrShortKernel σ1 σ2 Tstar κ t u) ^ 2) + (fun u ↦ σ1 ^ 2 * vasicekKernel κ t u ^ 2) (Set.Ioc 0 m) := fun u hu ↦ by + simp only [gsrShortKernel, gsrSigma, ite_eq_left (hu.2.trans (min_le_left _ _))] + ring + have heq2 : Set.EqOn (fun u ↦ (gsrShortKernel σ1 σ2 Tstar κ t u) ^ 2) + (fun u ↦ σ2 ^ 2 * vasicekKernel κ t u ^ 2) (Set.Ioc m t) := fun u hu ↦ by + simp only [gsrShortKernel, gsrSigma, ite_eq_right fun h ↦ (not_le.2 hu.1) (le_min h hu.2)] + ring + have hcont (c : ℝ) {x y : ℝ} (hxy : x ≤ y) : IntegrableOn + (fun u ↦ c * vasicekKernel κ t u ^ 2) (Set.Ioc x y) volume := + (intervalIntegrable_iff_integrableOn_Ioc_of_le hxy).mp + (by apply Continuous.intervalIntegrable; unfold vasicekKernel; fun_prop) + have hdisj : Disjoint (Set.Ioc 0 m) (Set.Ioc m t) := + Set.disjoint_left.mpr fun x hx1 hx2 ↦ absurd hx2.1 (not_lt.mpr hx1.2) + rw [← Set.Ioc_union_Ioc_eq_Ioc hm0 hmt, setIntegral_union hdisj measurableSet_Ioc + ((hcont (σ1 ^ 2) hm0).congr_fun heq1.symm measurableSet_Ioc) + ((hcont (σ2 ^ 2) hmt).congr_fun heq2.symm measurableSet_Ioc), + setIntegral_congr_fun measurableSet_Ioc heq1, setIntegral_congr_fun measurableSet_Ioc heq2, + integral_const_mul, integral_const_mul, ← intervalIntegral.integral_of_le hm0, + ← intervalIntegral.integral_of_le hmt, integral_vasicekKernel_sq_eq_sub κ t 0 m hκ, + integral_vasicekKernel_sq_eq_sub κ t m t hκ, gsrShortRateV] + +/-- **The GSR short-rate variance is positive** for `t > 0` and nonzero volatilities: the two +pieces of `(0, t]` are weighted by `σ₁², σ₂² > 0` and one of them is nonempty. -/ +lemma gsrShortRateV_pos {κ : ℝ} (hκ : 0 < κ) {σ1 σ2 : ℝ} (hσ1 : σ1 ≠ 0) (hσ2 : σ2 ≠ 0) + {Tstar t : ℝ} (hTstar : 0 ≤ Tstar) (ht : 0 < t) : 0 < gsrShortRateV κ σ1 σ2 Tstar t := by + have hG {a b : ℝ} (hab : a < b) : + vasicekKernelSqAntideriv κ t a < vasicekKernelSqAntideriv κ t b := by + unfold vasicekKernelSqAntideriv + exact div_lt_div_of_pos_right (Real.exp_lt_exp.2 (by nlinarith)) (by positivity) + have hm0 : 0 ≤ min Tstar t := le_min hTstar ht.le + have hmt : min Tstar t ≤ t := min_le_right _ _ + have h1 := pow_pos (abs_pos.2 hσ1) 2 + have h2 := pow_pos (abs_pos.2 hσ2) 2 + rw [sq_abs] at h1 h2 + unfold gsrShortRateV + rcases hm0.eq_or_lt with h | h + · rw [← h] + linarith [mul_pos h2 (sub_pos.2 (hG ht))] + · have hle : vasicekKernelSqAntideriv κ t (min Tstar t) ≤ vasicekKernelSqAntideriv κ t t := by + rcases hmt.eq_or_lt with h | h + · rw [h] + · exact (hG h).le + linarith [mul_pos h1 (sub_pos.2 (hG h)), mul_nonneg h2.le (sub_nonneg.2 hle)] + +/-- **GSR with one volatility is Vasicek**: at `σ₁ = σ₂ = σ` the two pieces telescope and +`gsrShortRateV` is the Vasicek variance `σ²(1 − e^{−2κt})/(2κ)`. -/ +lemma gsrShortRateV_self (κ σ Tstar t : ℝ) : + gsrShortRateV κ σ σ Tstar t = vasicekSDEVariance σ κ t := by + simp only [gsrShortRateV, vasicekKernelSqAntideriv, vasicekSDEVariance, sub_self, sub_zero, + mul_zero, neg_zero, Real.exp_zero] + ring + +/-- **The GSR short rate is Gaussian**: `r_t ~ N(m_t, gsrShortRateV)`, `m_t` the Vasicek mean. -/ +theorem gsrShortRate_hasLaw_gaussian [IsProbabilityMeasure μ] (hB : IsPreBrownianReal B μ) + (r₀ θ σ1 σ2 : ℝ) {κ : ℝ} (hκ : 0 < κ) (Tstar t : ℝ≥0) : + HasLaw (gsrShortRate hB r₀ θ σ1 σ2 hκ Tstar t) + (gaussianReal (vasicekSDEMean r₀ θ κ (t : ℝ)) + (gsrShortRateV κ σ1 σ2 (Tstar : ℝ) (t : ℝ)).toNNReal) μ := by + have h := gaussianReal_const_add (wienerIntegralLp_hasLaw_gaussian_of_integral_sq hB t + (gsrShortKernelLp hκ.le σ1 σ2 (Tstar : ℝ) t) + ((gsrShortKernel_memLp hκ.le σ1 σ2 (Tstar : ℝ) t).integral_sq_toLp.trans + (gsrShortKernel_integral_sq_eq hκ.ne' σ1 σ2 Tstar.coe_nonneg t.coe_nonneg))) + (vasicekSDEMean r₀ θ κ (t : ℝ)) + rwa [zero_add] at h + +/-- **The GSR short rate under the `t`-forward measure.** With the forward measure of the bank +account `exp(∫₀ᵗ r)` (`gsrIntegratedRate`), `r_t` stays Gaussian with the same variance and its +mean shifted by minus the covariance with `∫₀ᵗ r` (`hasLaw_forwardMeasure_wienerIntegralLp`): + + `r_t ~ N(m_t − ⟪σ(·)e^{−κ(t−·)}, σ(·)g_t⟫, gsrShortRateV)` under `Q^t`. -/ +theorem gsrShortRate_hasLaw_forwardMeasure [IsProbabilityMeasure μ] (hB : IsPreBrownianReal B μ) + (r₀ θ σ1 σ2 : ℝ) {κ : ℝ} (hκ : 0 < κ) (Tstar t : ℝ≥0) : + HasLaw (gsrShortRate hB r₀ θ σ1 σ2 hκ Tstar t) + (gaussianReal (vasicekSDEMean r₀ θ κ (t : ℝ) + - ⟪gsrShortKernelLp hκ.le σ1 σ2 (Tstar : ℝ) t, gsrKernelLp hκ σ1 σ2 (Tstar : ℝ) t⟫_ℝ) + (gsrShortRateV κ σ1 σ2 (Tstar : ℝ) (t : ℝ)).toNNReal) + (forwardMeasure μ fun ω ↦ Real.exp (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar t ω)) := by + have h := hasLaw_forwardMeasure_wienerIntegralLp hB t (vasicekSDEMean r₀ θ κ (t : ℝ)) + (vasicekIntegratedMean r₀ θ κ (t : ℝ)) 1 1 (vasicekSDEMean r₀ θ κ (t : ℝ)) + (gsrShortKernelLp hκ.le σ1 σ2 (Tstar : ℝ) t) (gsrKernelLp hκ σ1 σ2 (Tstar : ℝ) t) + (by simp only [one_mul]; exact gsrShortRate_hasLaw_gaussian hB r₀ θ σ1 σ2 hκ Tstar t) + simp only [one_mul, mul_one] at h + exact h + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/GSRPiecewiseVol.lean b/LeanPool/MathFin/Models/Rates/GSRPiecewiseVol.lean new file mode 100644 index 0000000000..8cba83e294 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/GSRPiecewiseVol.lean @@ -0,0 +1,304 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.VasicekBondPrice +public import Mathlib.Order.CompletePartialOrder + +/-! +# GSR (Gaussian short rate) with two-piece piecewise-constant volatility + +The **GSR model** (QuantLib's `GsrProcess`/one-factor `Gsr` model) generalizes Vasicek/ +Hull-White by letting the diffusion coefficient be **piecewise constant in calendar +time** rather than a single scalar — the feature actually exercised in cap/swaption +calibration, where a term structure of volatility is bootstrapped bucket by bucket. +Mean reversion is kept constant here, matching common GSR calibration practice +(reversion is held fixed while volatility is bucketed); `θ` is likewise constant +(the time-varying-drift generalization is `Models/Rates/HullWhiteCalibration.lean`'s +separate contribution and composes with this one in principle, but is not combined +here). + +**Scope note**: this file proves +the **two-piece** case — volatility `σ₁` on `(0, T*]`, `σ₂` on `(T*, T]`, for a fixed +breakpoint `T* ∈ [0, T]` — not the general finitely-many-pieces GSR. The obstruction to +full generality is not conceptual (the argument below is already piece-count-agnostic +in spirit: split, apply FTC on each piece, sum variances) but mechanical: each +additional piece needs its own disjoint-union / interval-additivity bookkeeping, which +is better done once as an induction over a list of breakpoints than hand-duplicated. +Two pieces is the smallest case that is genuinely new (distinct from the +constant-`σ` Vasicek bond price `vasicekBondPrice_eq`) and already demonstrates the +mechanism in full. + +## Why this is still "the same Gaussian-moment substrate" + +Even with `σ` piecewise constant, the integrated short rate's diffusion part +`∫₀ᵀ σ(u)·g(u) dB_u` (`g` the Vasicek integrated kernel of `VasicekBondPrice.lean`) is +still the Wiener integral of a single **deterministic** `L²` integrand `u ↦ σ(u)·g(u)` — +piecewise-constant `σ` times a bounded kernel is still bounded, hence `L²` on the +finite-measure window. No new stochastic-integral machinery is needed: only a new +(elementary) variance integral, computed by splitting the integration domain at `T*` and +evaluating the antiderivative `vasicekIntegratedKernelSqAntideriv` of `g²` at the three +points `0, T*, T` (`integral_vasicekIntegratedKernel_sq_eq_sub`). + +As in `VasicekBondPrice`, the integrated short rate is *defined* by its Wiener +representation `M(T) + ∫₀ᵀ σ(u)·g(u) dB_u` (`gsrIntegratedRate`): that it is the integral +of the solution of the GSR short-rate SDE (the SDE solution plus the time-order swap) is the +modelling bridge, cited, not derived here. Everything downstream of the representation is +derived. + +## Main definitions + +* `gsrSigma`: the two-piece piecewise-constant volatility, `σ₁` on `(-∞, T*]` and `σ₂` on + `(T*, ∞)`. +* `gsrKernel`, `gsrKernelLp`: the Vasicek integrated kernel weighted by the piecewise volatility, + and the same kernel as an element of `L²((0, T])`. +* `gsrBondV`: the closed-form variance `σ₁²·(F(T*) - F(0)) + σ₂²·(F(T) - F(T*))`. +* `gsrBondVIoc`: the variance over a window `(a, T]`. +* `gsrIntegratedRate`: the integrated short rate, defined by its Wiener representation. + +## Main results + +* `gsrKernel_integral_sq_eq` — the core calculus fact: the kernel's squared `L²` norm + over `(0,T]` equals `gsrBondV` (`κ > 0`, `0 ≤ T* ≤ T`). +* `gsrIntegratedRate_hasLaw_gaussian` — the integrated short rate, in its Wiener + representation, is Gaussian with this variance. +* `gsrBondPrice_eq` — the exponential-Gaussian moment `𝔼_μ[exp(−∫₀ᵀ r_s ds)]`, the + zero-coupon bond price when `μ` is read as the pricing measure: the Wiener bond-price lemma + `integral_exp_neg_add_mul_wienerIntegralLp` at the GSR kernel. +* `gsrBondV_self`, `gsrIntegratedRate_self_ae` — **GSR with one volatility is Vasicek**: at + `σ₁ = σ₂ = σ` the variance is `σ²·vasicekBondV` and the integrated GSR rate is almost surely + the integrated Vasicek rate `vasicekIntegratedRate`. + +## References + +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + §3.3 +* [The QuantLib contributors, *QuantLib*][QuantLib], Gsr model + +## Tags + +Gaussian short rate, GSR model, piecewise-constant volatility, Hull–White, Vasicek model, +bond price, Wiener integral, MSC 91G30, MSC 60H05, JEL E43 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real Set +open scoped NNReal +open WienerIntegralL2 + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-! ### Two-piece piecewise-constant volatility -/ + +/-- **Two-piece piecewise-constant volatility**: `σ₁` on `(-∞, T*]`, `σ₂` on `(T*, ∞)`. -/ +noncomputable def gsrSigma (σ1 σ2 Tstar u : ℝ) : ℝ := if u ≤ Tstar then σ1 else σ2 + +/-- `gsrSigma` is measurable: it is an `ite` on the measurable set `{u | u ≤ Tstar}` with +constant branches. -/ +lemma gsrSigma_measurable (σ1 σ2 Tstar : ℝ) : Measurable (gsrSigma σ1 σ2 Tstar) := by + unfold gsrSigma + exact Measurable.ite measurableSet_Iic measurable_const measurable_const + +/-- The **GSR kernel**: the Vasicek integrated kernel `g` weighted by the piecewise +volatility — the deterministic integrand of the diffusion part `∫₀ᵀ σ(u)g(u) dB_u`. -/ +noncomputable def gsrKernel (σ1 σ2 Tstar κ T : ℝ) : ℝ → ℝ := + fun u ↦ gsrSigma σ1 σ2 Tstar u * vasicekIntegratedKernel κ T u + +/-! ### The GSR kernel is an `L²` integrand -/ + +/-- The GSR kernel is in `L²((0, T])`: `|σ(u)| ≤ max |σ₁| |σ₂|` and `0 ≤ g(u) ≤ 1/κ` +(for `κ > 0`), so the product is bounded by `max |σ₁| |σ₂| / κ`. -/ +lemma gsrKernel_memLp {κ : ℝ} (hκ : 0 < κ) (σ1 σ2 Tstar : ℝ) (T : ℝ≥0) : + MemLp (gsrKernel σ1 σ2 Tstar κ (T : ℝ)) 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := by + have hg_meas : Measurable (vasicekIntegratedKernel κ (T : ℝ)) := by + unfold vasicekIntegratedKernel; fun_prop + refine (memLp_top_of_bound + (by unfold gsrKernel + exact ((gsrSigma_measurable σ1 σ2 Tstar).mul hg_meas).aestronglyMeasurable) + (max |σ1| |σ2| / κ) ?_).mono_exponent le_top + refine (ae_restrict_iff' measurableSet_Ioc).mpr (ae_of_all _ ?_) + intro u hu + rw [gsrKernel, Real.norm_eq_abs, abs_mul] + have hexp_pos : 0 < Real.exp (-(κ * ((T : ℝ) - u))) := Real.exp_pos _ + have hTu : 0 ≤ (T : ℝ) - u := by linarith [hu.2] + have hexp_le : Real.exp (-(κ * ((T : ℝ) - u))) ≤ 1 := + Real.exp_le_one_iff.mpr (by nlinarith [mul_nonneg hκ.le hTu]) + have hg_nonneg : 0 ≤ vasicekIntegratedKernel κ (T : ℝ) u := by + rw [vasicekIntegratedKernel]; exact div_nonneg (by linarith) hκ.le + have hg_le : vasicekIntegratedKernel κ (T : ℝ) u ≤ 1 / κ := by + rw [vasicekIntegratedKernel] + exact (div_le_div_iff_of_pos_right hκ).mpr (by linarith) + have hσ_le : |gsrSigma σ1 σ2 Tstar u| ≤ max |σ1| |σ2| := by + unfold gsrSigma; split + · exact le_max_left _ _ + · exact le_max_right _ _ + calc |gsrSigma σ1 σ2 Tstar u| * |vasicekIntegratedKernel κ (T : ℝ) u| + ≤ max |σ1| |σ2| * (1 / κ) := + mul_le_mul hσ_le (by rw [abs_of_nonneg hg_nonneg]; exact hg_le) (abs_nonneg _) + (le_trans (abs_nonneg _) hσ_le) + _ = max |σ1| |σ2| / κ := by ring + +/-- The GSR kernel as an element of `L²((0, T])`. -/ +noncomputable def gsrKernelLp {κ : ℝ} (hκ : 0 < κ) (σ1 σ2 Tstar : ℝ) (T : ℝ≥0) : + Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := + (gsrKernel_memLp hκ σ1 σ2 Tstar T).toLp _ + +/-! ### The variance integral, by splitting at `T*` -/ + +/-- **The GSR closed-form variance**: `σ₁²·(F(T*) - F(0)) + σ₂²·(F(T) - F(T*))`, +`F = vasicekIntegratedKernelSqAntideriv κ T` (the antiderivative of `g²`). -/ +noncomputable def gsrBondV (κ σ1 σ2 Tstar T : ℝ) : ℝ := + σ1 ^ 2 * (vasicekIntegratedKernelSqAntideriv κ T Tstar + - vasicekIntegratedKernelSqAntideriv κ T 0) + + σ2 ^ 2 * (vasicekIntegratedKernelSqAntideriv κ T T + - vasicekIntegratedKernelSqAntideriv κ T Tstar) + +/-- **The GSR variance over a window `(a, T]`**: `σ₁²·(F(m) − F(a)) + σ₂²·(F(T) − F(m))` with +`m = max a T*` the part of the window before the breakpoint ending at `m` (empty when `a ≥ T*`); +`gsrBondV` is the window `(0, T]`. -/ +noncomputable def gsrBondVIoc (κ σ1 σ2 Tstar a T : ℝ) : ℝ := + σ1 ^ 2 * (vasicekIntegratedKernelSqAntideriv κ T (max a Tstar) + - vasicekIntegratedKernelSqAntideriv κ T a) + + σ2 ^ 2 * (vasicekIntegratedKernelSqAntideriv κ T T + - vasicekIntegratedKernelSqAntideriv κ T (max a Tstar)) + +lemma gsrBondVIoc_zero {Tstar : ℝ} (hTstar0 : 0 ≤ Tstar) (κ σ1 σ2 T : ℝ) : + gsrBondVIoc κ σ1 σ2 Tstar 0 T = gsrBondV κ σ1 σ2 Tstar T := by + rw [gsrBondVIoc, gsrBondV, max_eq_right hTstar0] + +/-- **The squared `L²` norm of the GSR kernel over a window `(a, T]`**, by splitting the window at +`max a T*` (`gsrKernel` is exactly `σ₁ · g` on the part before `T*` and `σ₂ · g` after it, a case +split on `gsrSigma`'s own definition) and applying `integral_vasicekIntegratedKernel_sq_eq_sub` +on each piece. -/ +theorem gsrKernel_integral_sq_Ioc_eq {κ : ℝ} (hκ : 0 < κ) (σ1 σ2 Tstar a T : ℝ) + (haT : a ≤ T) (hTstarT : Tstar ≤ T) : + ∫ u in Set.Ioc a T, (gsrKernel σ1 σ2 Tstar κ T u) ^ 2 ∂volume + = gsrBondVIoc κ σ1 σ2 Tstar a T := by + set m := max a Tstar with hm + have ham : a ≤ m := le_max_left _ _ + have hmT : m ≤ T := max_le haT hTstarT + have heq1 : Set.EqOn (fun u ↦ (gsrKernel σ1 σ2 Tstar κ T u) ^ 2) + (fun u ↦ σ1 ^ 2 * vasicekIntegratedKernel κ T u ^ 2) (Set.Ioc a m) := by + intro u hu + have : u ≤ Tstar := by + rcases le_total a Tstar with h | h + · exact (hu.2.trans_eq (max_eq_right h)) + · exact absurd (hu.2.trans_eq (max_eq_left h)) (not_le.2 hu.1) + simp only [gsrKernel, gsrSigma, ite_eq_left this] + ring + have heq2 : Set.EqOn (fun u ↦ (gsrKernel σ1 σ2 Tstar κ T u) ^ 2) + (fun u ↦ σ2 ^ 2 * vasicekIntegratedKernel κ T u ^ 2) (Set.Ioc m T) := by + intro u hu + simp only [gsrKernel, gsrSigma, + ite_eq_right (not_le.mpr (lt_of_le_of_lt (le_max_right _ _) hu.1))] + ring + have hcont (c : ℝ) {x y : ℝ} (hxy : x ≤ y) : IntegrableOn + (fun u ↦ c * vasicekIntegratedKernel κ T u ^ 2) (Set.Ioc x y) volume := + (intervalIntegrable_iff_integrableOn_Ioc_of_le hxy).mp + (by apply Continuous.intervalIntegrable; unfold vasicekIntegratedKernel; fun_prop) + have hmeas1 := (hcont (σ1 ^ 2) ham).congr_fun heq1.symm measurableSet_Ioc + have hmeas2 := (hcont (σ2 ^ 2) hmT).congr_fun heq2.symm measurableSet_Ioc + have hdisj : Disjoint (Set.Ioc a m) (Set.Ioc m T) := + Set.disjoint_left.mpr (fun x hx1 hx2 ↦ absurd hx2.1 (not_lt.mpr hx1.2)) + rw [← Set.Ioc_union_Ioc_eq_Ioc ham hmT, setIntegral_union hdisj measurableSet_Ioc hmeas1 hmeas2, + setIntegral_congr_fun measurableSet_Ioc heq1, setIntegral_congr_fun measurableSet_Ioc heq2, + integral_const_mul, integral_const_mul, ← intervalIntegral.integral_of_le ham, + ← intervalIntegral.integral_of_le hmT, + integral_vasicekIntegratedKernel_sq_eq_sub κ T a m hκ.ne', + integral_vasicekIntegratedKernel_sq_eq_sub κ T m T hκ.ne', gsrBondVIoc] + +/-- **The core calculus fact**: the `(0,T]`-window squared `L²` norm of the GSR kernel is +the closed-form `gsrBondV` (`gsrKernel_integral_sq_Ioc_eq` on the window `(0, T]`). -/ +theorem gsrKernel_integral_sq_eq {κ : ℝ} (hκ : 0 < κ) (σ1 σ2 Tstar T : ℝ) + (hTstar0 : 0 ≤ Tstar) (hTstarT : Tstar ≤ T) : + ∫ u in Set.Ioc (0 : ℝ) T, (gsrKernel σ1 σ2 Tstar κ T u) ^ 2 ∂volume + = gsrBondV κ σ1 σ2 Tstar T := + (gsrKernel_integral_sq_Ioc_eq hκ σ1 σ2 Tstar 0 T (hTstar0.trans hTstarT) hTstarT).trans + (gsrBondVIoc_zero hTstar0 κ σ1 σ2 T) + +/-! ### The GSR short rate and the bond price -/ + +/-- `∫₀ᵀ (gsrKernelLp)² = gsrBondV` for the `L²`-representative (a.e. equal to the +honest kernel). -/ +private lemma gsrKernelLp_integral_sq {κ : ℝ} (hκ : 0 < κ) (σ1 σ2 : ℝ) (Tstar T : ℝ≥0) + (hTstarT : (Tstar : ℝ) ≤ (T : ℝ)) : + (∫ u in Set.Ioc (0 : ℝ) (T : ℝ), (gsrKernelLp hκ σ1 σ2 (Tstar : ℝ) T u) ^ 2 ∂volume) + = gsrBondV κ σ1 σ2 (Tstar : ℝ) (T : ℝ) := by + exact (gsrKernel_memLp hκ σ1 σ2 (Tstar : ℝ) T).integral_sq_toLp.trans + (gsrKernel_integral_sq_eq hκ σ1 σ2 (Tstar : ℝ) (T : ℝ) Tstar.2 hTstarT) + +/-- **The GSR integrated short rate**, *defined* by its Wiener representation: deterministic +mean (the Vasicek mean, unchanged — only the volatility axis is piecewise here) plus the +Wiener integral of the piecewise-weighted kernel. That this is `∫₀ᵀ r_s ds` for the solution +of the GSR short-rate SDE is the modelling bridge (the SDE solution and the time-order swap), +cited, not derived, as for `vasicekIntegratedRate`. -/ +noncomputable def gsrIntegratedRate (hB : IsPreBrownianReal B μ) (r₀ θ σ1 σ2 : ℝ) {κ : ℝ} + (hκ : 0 < κ) (Tstar T : ℝ≥0) (ω : Ω) : ℝ := + vasicekIntegratedMean r₀ θ κ (T : ℝ) + + wienerIntegralLp B hB T (gsrKernelLp hκ σ1 σ2 (Tstar : ℝ) T) ω + +/-- **The GSR integrated short rate is Gaussian**: `N(M(T), gsrBondV κ σ₁ σ₂ T* T)`, +`M` the (unchanged) Vasicek mean. -/ +theorem gsrIntegratedRate_hasLaw_gaussian (hB : IsPreBrownianReal B μ) (r₀ θ σ1 σ2 : ℝ) + {κ : ℝ} (hκ : 0 < κ) (Tstar T : ℝ≥0) (hTstarT : (Tstar : ℝ) ≤ (T : ℝ)) : + HasLaw (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar T) + (gaussianReal (vasicekIntegratedMean r₀ θ κ (T : ℝ)) + (gsrBondV κ σ1 σ2 (Tstar : ℝ) (T : ℝ)).toNNReal) μ := by + have hW := wienerIntegralLp_hasLaw_gaussian_of_integral_sq hB T + (gsrKernelLp hκ σ1 σ2 (Tstar : ℝ) T) (gsrKernelLp_integral_sq hκ σ1 σ2 Tstar T hTstarT) + have hShift := gaussianReal_const_add hW (vasicekIntegratedMean r₀ θ κ (T : ℝ)) + convert hShift using 2 <;> first | rfl | ring + +/-- **The GSR zero-coupon bond price**: the exponential-Gaussian moment +`𝔼_μ[exp(−∫₀ᵀ r_s ds)] = exp(−M(T) + gsrBondV κ σ₁ σ₂ T* T / 2)`, with `∫₀ᵀ r_s ds` the +Wiener representation `gsrIntegratedRate`; it is `P(0,T)` when `μ` is read as the pricing +measure. The Wiener bond-price lemma `integral_exp_neg_add_mul_wienerIntegralLp` at `m = M(T)`, +`c = 1` and the GSR kernel, whose squared `L²`-norm is `gsrBondV` (`gsrKernel_integral_sq_eq`). -/ +theorem gsrBondPrice_eq (hB : IsPreBrownianReal B μ) (r₀ θ σ1 σ2 : ℝ) {κ : ℝ} (hκ : 0 < κ) + (Tstar T : ℝ≥0) (hTstarT : (Tstar : ℝ) ≤ (T : ℝ)) : + ∫ ω, Real.exp (-(gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar T ω)) ∂μ + = Real.exp (-(vasicekIntegratedMean r₀ θ κ (T : ℝ)) + + gsrBondV κ σ1 σ2 (Tstar : ℝ) (T : ℝ) / 2) := by + have h := integral_exp_neg_add_mul_wienerIntegralLp hB T (vasicekIntegratedMean r₀ θ κ (T : ℝ)) 1 + (gsrKernelLp hκ σ1 σ2 (Tstar : ℝ) T) + simp only [one_mul, one_pow] at h + rwa [gsrKernelLp_integral_sq hκ σ1 σ2 Tstar T hTstarT] at h + +/-! ### One volatility: GSR is Vasicek -/ + +/-- **The one-volatility GSR variance is Vasicek's**: `gsrBondV κ σ σ T* T = σ²·vasicekBondV κ T` +— with `σ₁ = σ₂` the two antiderivative differences telescope to `F(T) − F(0) = V(T)`. -/ +theorem gsrBondV_self (κ σ Tstar T : ℝ) : + gsrBondV κ σ σ Tstar T = σ ^ 2 * vasicekBondV κ T := by + simp only [gsrBondV, vasicekIntegratedKernelSqAntideriv, vasicekBondV, sub_self, mul_zero, + neg_zero, Real.exp_zero, sub_zero] + ring + +omit [IsProbabilityMeasure μ] in +/-- **GSR with one volatility is Vasicek**: at `σ₁ = σ₂ = σ` the GSR kernel is `σ` times the +Vasicek integrated kernel, so by linearity of the Wiener integral the integrated GSR rate is +almost surely the integrated Vasicek rate `vasicekIntegratedRate` (whatever the breakpoint). -/ +theorem gsrIntegratedRate_self_ae (hB : IsPreBrownianReal B μ) (r₀ θ σ : ℝ) {κ : ℝ} + (hκ : 0 < κ) (Tstar T : ℝ≥0) : + gsrIntegratedRate hB r₀ θ σ σ hκ Tstar T =ᵐ[μ] vasicekIntegratedRate hB r₀ θ σ hκ T := by + have hk : gsrKernelLp hκ σ σ (Tstar : ℝ) T = σ • vasicekIntegratedKernelLp hκ T := by + refine Lp.ext ?_ + filter_upwards [(gsrKernel_memLp hκ σ σ (Tstar : ℝ) T).coeFn_toLp, + Lp.coeFn_smul σ (vasicekIntegratedKernelLp hκ T), + (vasicekIntegratedKernel_memLp hκ T).coeFn_toLp] with u h₁ h₂ h₃ + rw [gsrKernelLp, h₁, h₂, Pi.smul_apply, vasicekIntegratedKernelLp, h₃] + simp only [gsrKernel, gsrSigma, ite_self, smul_eq_mul] + filter_upwards [wienerIntegralLp_smul_ae hB T σ (vasicekIntegratedKernelLp hκ T)] with ω hω + rw [gsrIntegratedRate, vasicekIntegratedRate, hk, hω] + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/HJM.lean b/LeanPool/MathFin/Models/Rates/HJM.lean new file mode 100644 index 0000000000..b4f356950e --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/HJM.lean @@ -0,0 +1,158 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.ZCB +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessGeneral + +/-! +# The Heath–Jarrow–Morton model bundle + +The HJM model describes the whole forward-rate curve `f(t,T)`, `t ≤ T`, as a family of Itô +processes in `t`, one for each fixed maturity `T`: +`f(t,T) = f(0,T) + ∫₀ᵗ α(s,T) ds + ∫₀ᵗ σ(s,T) dB_s`, driven by the Brownian motion `B` on +`[0,H]`. `HJMModel` is that data. The stochastic integral is the library's `itoProcessCLM` of the +`L²(trim_H)` realization `volLp T` of the volatility `σ(·,T)`, so the dynamics hold as an identity +of `L²(μ)` classes at each `t ≤ min T H`, and the drift is the pathwise `timeMeasure` integral +(as `driftPath`). + +The objects every later node of the HJM program consumes are defined from the bundle: the bond +`P(t,T) = exp(-∫_t^T f(t,u) du)`, the short rate `r(t) = f(t,t)`, the bank account +`B(t) = exp(∫₀ᵗ r)`, the discounted bond `P/B`, and the integrated coefficients +`α*(t,T) = ∫_t^T α(t,u) du`, `σ*(t,T) = ∫_t^T σ(t,u) du`. Only well-definedness is proved here +(`P(T,T) = 1`, positivity of `P` and `B`), and the seam into the library's constant-rate bond: +on a flat curve `f(t,·) ≡ r` the HJM bond is `zcb r t T`. + +No dynamics of `P`, no drift condition and no stochastic Fubini interchange is proved in this file. + +## Main definitions + +* `HJMModel`: the bundle (forward curve, drift, volatility, the `L²` realization of the volatility, + the Itô dynamics in `t` for each maturity, adaptedness, measurability, integrability of the + curve and of the short rate). +* `HJMModel.bond`, `HJMModel.shortRate`, `HJMModel.integratedRate`, + `HJMModel.bankAccount`, `HJMModel.discountedBond`, + `HJMModel.starDrift`, `HJMModel.starVol`: the derived objects. + +## Main results + +* `HJMModel.bond_self`: `P(T,T) = 1`. +* `HJMModel.bond_pos`, `HJMModel.bankAccount_pos`, `HJMModel.discountedBond_pos`: positivity. +* `HJMModel.bond_of_flat`: on a flat forward curve `f(t,·) ≡ r` the bond is `zcb r t T`. + +## References + +* [Heath–Jarrow–Morton, *Bond pricing and the term structure*][HeathJarrowMorton1992], §2 +* [D. Brigo, F. Mercurio, *Interest Rate Models*][BrigoMercurio2006], §5.1 + +## Tags + +Heath–Jarrow–Morton, forward rate curve, term structure, zero-coupon bond, short rate, +bank account, JEL E43, MSC 91G30 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory +open scoped NNReal + +namespace MathFin +namespace HJM + +open ItoIntegralL2 ItoIntegralCLM ItoIntegralProcessGeneral + +/-- **The HJM model bundle** on the horizon `[0,H]` over a Brownian motion `B`. +`fwd t T ω = f(t,T)(ω)`, `drift s T = α(s,T)`, `vol s T = σ(s,T)`; `volLp T` is the `L²(trim_H)` +class of `σ(·,T)` (the Itô-integrable realization), and `fwd_ito` is the dynamics +`f(t,T) = f(0,T) + ∫₀ᵗ α(s,T) ds + ∫₀ᵗ σ(s,T) dB_s` a.s., for `t ≤ T` and `t ≤ H`. -/ +structure HJMModel {Ω : Type*} {mΩ : MeasurableSpace Ω} (μ : Measure Ω) [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) (hBmeas : ∀ t, Measurable (B t)) + (H : ℝ≥0) where + /-- The forward-rate curve `f(t,T)`. -/ + fwd : ℝ≥0 → ℝ≥0 → Ω → ℝ + /-- The forward-rate drift `α(s,T)`. -/ + drift : ℝ≥0 → ℝ≥0 → Ω → ℝ + /-- The forward-rate volatility `σ(s,T)`. -/ + vol : ℝ≥0 → ℝ≥0 → Ω → ℝ + /-- The `L²(trim_H)` realization of the volatility `σ(·,T)` of maturity `T`. -/ + volLp : ℝ≥0 → Lp ℝ 2 (trimMeasure (μ := μ) H hBmeas) + volLp_ae : ∀ T, ⇑(volLp T) =ᵐ[trimMeasure (μ := μ) H hBmeas] fun z ↦ vol z.1 T z.2 + /-- `f(·,T)` is an Itô process: initial value, drift integral and Itô integral. -/ + fwd_ito : ∀ T t, t ≤ T → t ≤ H → fwd t T =ᵐ[μ] fun ω ↦ + fwd 0 T ω + ∫ s in Set.Ioc 0 t, drift s T ω ∂timeMeasure + + itoProcessCLM hB H t hBmeas (volLp T) ω + fwd_adapted : ∀ t T, + StronglyMeasurable[(natFiltration hBmeas t : MeasurableSpace Ω)] (fwd t T) + drift_meas : ∀ ω, Measurable fun p : ℝ≥0 × ℝ≥0 ↦ drift p.1 p.2 ω + vol_meas : ∀ ω, Measurable fun p : ℝ≥0 × ℝ≥0 ↦ vol p.1 p.2 ω + drift_integrable : ∀ T ω, IntegrableOn (fun s ↦ drift s T ω) (Set.Ioc 0 H) timeMeasure + fwd_integrable : ∀ t ω, IntegrableOn (fun u ↦ fwd t u ω) (Set.Ioc t H) timeMeasure + /-- The short rate `f(s,s)` is integrable on the horizon, so the bank account is not a junk + `exp 0`. -/ + shortRate_integrable : ∀ ω, IntegrableOn (fun s ↦ fwd s s ω) (Set.Ioc 0 H) timeMeasure + +namespace HJMModel + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} {hB : IsPreBrownianReal B μ} {hBmeas : ∀ t, Measurable (B t)} {H : ℝ≥0} + (M : HJMModel μ hB hBmeas H) + +/-- **The bond price** `P(t,T) = exp(-∫_t^T f(t,u) du)`. -/ +noncomputable def bond (t T : ℝ≥0) (ω : Ω) : ℝ := + Real.exp (-∫ u in Set.Ioc t T, M.fwd t u ω ∂timeMeasure) + +/-- **The short rate** `r(t) = f(t,t)`. -/ +def shortRate (t : ℝ≥0) (ω : Ω) : ℝ := M.fwd t t ω + +/-- **The integrated short rate** `∫₀ᵗ r(s) ds`. -/ +noncomputable def integratedRate (t : ℝ≥0) (ω : Ω) : ℝ := + ∫ s in Set.Ioc 0 t, M.shortRate s ω ∂timeMeasure + +/-- **The bank account** `B(t) = exp(∫₀ᵗ r(s) ds)`. -/ +noncomputable def bankAccount (t : ℝ≥0) (ω : Ω) : ℝ := Real.exp (M.integratedRate t ω) + +/-- **The discounted bond** `Z(t,T) = P(t,T) / B(t)`. -/ +noncomputable def discountedBond (t T : ℝ≥0) (ω : Ω) : ℝ := M.bond t T ω / M.bankAccount t ω + +/-- **The integrated drift** `α*(t,T) = ∫_t^T α(t,u) du`. -/ +noncomputable def starDrift (t T : ℝ≥0) (ω : Ω) : ℝ := + ∫ u in Set.Ioc t T, M.drift t u ω ∂timeMeasure + +/-- **The integrated volatility** `σ*(t,T) = ∫_t^T σ(t,u) du`. -/ +noncomputable def starVol (t T : ℝ≥0) (ω : Ω) : ℝ := + ∫ u in Set.Ioc t T, M.vol t u ω ∂timeMeasure + +/-- A bond is worth one at its own maturity: `P(T,T) = 1`. -/ +@[simp] lemma bond_self (T : ℝ≥0) (ω : Ω) : M.bond T T ω = 1 := by + simp [bond] + +lemma bond_pos (t T : ℝ≥0) (ω : Ω) : 0 < M.bond t T ω := Real.exp_pos _ + +lemma bankAccount_pos (t : ℝ≥0) (ω : Ω) : 0 < M.bankAccount t ω := Real.exp_pos _ + +/-- The bank account starts at one. -/ +@[simp] lemma bankAccount_zero (ω : Ω) : M.bankAccount 0 ω = 1 := by + simp [bankAccount, integratedRate] + +lemma discountedBond_pos (t T : ℝ≥0) (ω : Ω) : 0 < M.discountedBond t T ω := + div_pos (M.bond_pos t T ω) (M.bankAccount_pos t ω) + +/-- **On a flat forward curve the HJM bond is the constant-rate bond.** If `f(t,u) = r` for +`u ∈ (t,T]`, then `P(t,T) = zcb r t T = exp(-r (T - t))`. -/ +theorem bond_of_flat {r : ℝ} {t T : ℝ≥0} (ht : t ≤ T) {ω : Ω} + (h : ∀ u ∈ Set.Ioc t T, M.fwd t u ω = r) : M.bond t T ω = zcb r t T := by + have hint : ∫ u in Set.Ioc t T, M.fwd t u ω ∂timeMeasure = r * ((T : ℝ) - t) := by + rw [setIntegral_congr_fun measurableSet_Ioc (g := fun _ ↦ r) h, setIntegral_const, + Measure.real_def, timeMeasure_Ioc, + ENNReal.toReal_ofReal (sub_nonneg.2 (NNReal.coe_le_coe.2 ht)), smul_eq_mul, mul_comm] + rw [bond, hint, zcb] + +end HJMModel + +end HJM +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/HJMBond.lean b/LeanPool/MathFin/Models/Rates/HJMBond.lean new file mode 100644 index 0000000000..43644c115f --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/HJMBond.lean @@ -0,0 +1,114 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.ShortRate +public import LeanPool.MathFin.Models.Rates.HJM + +/-! +# Fixed cash flows in the Heath–Jarrow–Morton model + +An `HJM.HJMModel` has a short rate `r(t) = f(t,t)` and so a stochastic discount factor +`D t = exp(-∫₀ᵗ r)`, the inverse of its bank account. `HJMModel.discount` is that factor as +`shortRateDiscount` of the integrated short rate, the object the contracts layer already prices +with (`Contract.value`), and `HJMModel.discount_eq_inv_bankAccount` identifies it with +`(bankAccount)⁻¹`. + +A schedule of fixed cash flows sees the model only through the zero curve `𝔼[D tᵢ]` +(`value_fixedFlows_of_zeroCurve_eq`). Two results: + +* `value_fixedFlows_hjm`: **conditional on the pricing hypothesis** `𝔼[D tᵢ] = P(0, tᵢ)`, + where `P(0,·)` is the initial bond curve, assumed deterministic (`hdet`), the schedule is worth + `∑ P(0, tᵢ) cᵢ`. That hypothesis is what the HJM drift condition delivers (the discounted bonds + are martingales); it is *not* proved here and is an explicit hypothesis of the statement. +* `value_fixedFlows_hjm_flat`: unconditionally, for a deterministic flat forward curve + `f(s,u) = r` (`s ≤ u`), the schedule is worth `∑ zcb r 0 tᵢ · cᵢ`. + +## Main definitions + +* `HJMModel.discount`: the stochastic discount factor `exp(-∫₀ᵗ f(s,s) ds)` of an HJM model. + +## Main results + +* `HJMModel.discount_eq_inv_bankAccount`: `discount t ω = (bankAccount t ω)⁻¹`. +* `value_fixedFlows_hjm`: fixed flows are worth `∑ P(0,tᵢ) cᵢ` given `𝔼[D tᵢ] = P(0,tᵢ)`. +* `value_fixedFlows_hjm_flat`: on a flat deterministic curve, they are worth `∑ zcb r 0 tᵢ cᵢ`. + +## References + +* [Heath–Jarrow–Morton, *Bond pricing and the term structure*][HeathJarrowMorton1992], §2 +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + sec. 5.1 +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] + +## Tags + +Heath–Jarrow–Morton, stochastic discount factor, zero curve, coupon bond pricing, +contract valuation, MSC 91G30, JEL E43 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory +open scoped NNReal + +namespace MathFin.Contracts + +open ItoIntegralL2 ItoIntegralCLM HJM + +variable {ι Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} {hB : IsPreBrownianReal B μ} {hBmeas : ∀ t, Measurable (B t)} {H : ℝ≥0} + +/-- **The stochastic discount factor of an HJM model**: `D t = exp(-∫₀ᵗ f(s,s) ds)`, the +`shortRateDiscount` of the integrated short rate. -/ +noncomputable def _root_.MathFin.HJM.HJMModel.discount (M : HJMModel μ hB hBmeas H) : ℝ≥0 → Ω → ℝ := + shortRateDiscount M.integratedRate + +/-- The HJM discount factor is the inverse of the bank account. -/ +theorem _root_.MathFin.HJM.HJMModel.discount_eq_inv_bankAccount (M : HJMModel μ hB hBmeas H) + (t : ℝ≥0) (ω : Ω) : + M.discount t ω = (M.bankAccount t ω)⁻¹ := by + rw [HJMModel.discount, shortRateDiscount, HJMModel.bankAccount, Real.exp_neg] + +/-- **Fixed cash flows in the HJM model, given the pricing hypothesis.** Let `P` be the initial +bond curve: `P(0, tᵢ) = bond 0 tᵢ` for every outcome (the time-`0` curve is deterministic). If the +discount factor prices each bond at its curve value, `𝔼[D tᵢ] = P(0, tᵢ)` (`hprice`: the +discounted-bond martingale property that the HJM drift condition delivers, which is **not** +proved here), then a schedule paying `cᵢ` at `tᵢ` is worth `∑ P(0, tᵢ) cᵢ`. -/ +theorem value_fixedFlows_hjm (M : HJMModel μ hB hBmeas H) (X : ι → ℝ≥0 → Ω → ℝ) + (t : ℕ → ℝ≥0) (c : ℕ → ℝ) (n : ℕ) {P : ℝ≥0 → ℝ} + (hdet : ∀ i < n, ∀ ω, M.bond 0 (t i) ω = P (t i)) + (hprice : ∀ i < n, ∫ ω, M.discount (t i) ω ∂μ = P (t i)) : + (fixedFlows t c n : Contract ι).value μ M.discount X + = ∑ i ∈ Finset.range n, P (t i) * c i := by + obtain ⟨ω₀⟩ := nonempty_of_isProbabilityMeasure μ + refine value_fixedFlows_of_zeroCurve_eq X t c n hprice fun i hi ↦ ?_ + have h := M.bond_pos 0 (t i) ω₀ + rw [hdet i hi ω₀] at h + exact h.ne' + +/-- **Fixed cash flows on a flat deterministic HJM curve.** If `f(s,u) = r` for all `s ≤ u` and +outcomes, the discount factor is the deterministic `zcb r 0 t = exp(-r t)` and a schedule paying +`cᵢ` at `tᵢ` is worth `∑ zcb r 0 tᵢ · cᵢ`. Unconditional. -/ +theorem value_fixedFlows_hjm_flat (M : HJMModel μ hB hBmeas H) {r : ℝ} + (hflat : ∀ s u ω, s ≤ u → M.fwd s u ω = r) (X : ι → ℝ≥0 → Ω → ℝ) (t : ℕ → ℝ≥0) + (c : ℕ → ℝ) (n : ℕ) : + (fixedFlows t c n : Contract ι).value μ M.discount X + = ∑ i ∈ Finset.range n, zcb r 0 (t i) * c i := by + have hD (s : ℝ≥0) (ω : Ω) : M.discount s ω = zcb r 0 s := by + have hint : M.integratedRate s ω = r * (s : ℝ) := by + rw [HJMModel.integratedRate, + setIntegral_congr_fun measurableSet_Ioc (f := fun u ↦ M.shortRate u ω) (g := fun _ ↦ r) + (fun u _ ↦ hflat u u ω le_rfl), setIntegral_const, Measure.real_def, timeMeasure_Ioc, + ENNReal.toReal_ofReal (by simp), smul_eq_mul, mul_comm]; simp + rw [HJM.HJMModel.discount, shortRateDiscount, hint, zcb] + simp + exact value_fixedFlows_of_zeroCurve_eq (P := fun s ↦ zcb r 0 s) X t c n + (fun i _ ↦ by simp [zeroCurve, hD]) fun i _ ↦ (zcb_pos r 0 (t i)).ne' + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Models/Rates/HullWhiteBond.lean b/LeanPool/MathFin/Models/Rates/HullWhiteBond.lean new file mode 100644 index 0000000000..7539ce196e --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/HullWhiteBond.lean @@ -0,0 +1,73 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.Caplet +public import LeanPool.MathFin.Models.Rates.HullWhiteBondPriceAt + +/-! +# Bond prices at `t > 0` in the Hull–White model + +For the Hull–White discount factor `D t = exp(−∫₀ᵗ r)` (`HullWhite.bondRate`, continuous forcing +`θ`) and the natural filtration of the driving Brownian motion, `bondPrice` is the affine form of +the time-`0` price of the forcing seen from `t`, at the remaining maturity (`bondPrice_hullWhite`), +read off the conditional Laplace transform of the Wiener integral +(`HullWhite.bondRate_condExp`): + + `P(t, T) = A_t(T − t)·exp(−B(T − t)·r_t)`, `A_t = bondA (θ(t + ·))`. + +It is the Hull–White counterpart of `bondPrice_vasicek` (`Models/Rates/VasicekBond.lean`), +with the same proof; Vasicek is the constant forcing (`HullWhite.bondRate_const`). + +## Main results + +* `bondPrice_hullWhite` — `bondPrice` in the Hull–White model, almost surely. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + section 3.3.1 +* [J. Hull and A. White, *Pricing interest-rate-derivative securities*][HullWhite1990] + +## Tags + +Hull–White model, zero-coupon bond price, affine term structure, short rate, Wiener integral, +MSC 91G30, JEL E43, JEL G12 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory +open scoped NNReal + +namespace MathFin.Contracts + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-- **The Hull–White bond price at time `t`.** With `D t = exp(−∫₀ᵗ r)` along the integrated +Hull–White rate for continuous forcing `θ` and `𝓕` the natural filtration of the driving Brownian +motion, the price at `t` of one unit paid at `T` is `P(t, T) = A_t(T − t)·exp(−B(T − t)·r_t)` +almost surely, where `r_t` is the short rate in its Wiener representation, `B` is Vasicek's +coefficient and `A_t = bondA (θ(t + ·))` is the coefficient of the time-`0` price +(`HullWhite.bondPrice_affine`) of the forcing shifted to `t`. The measure is read as the pricing +measure. -/ +theorem bondPrice_hullWhite (hB : IsPreBrownianReal B μ) (hBm : ∀ s, Measurable (B s)) + {θ : ℝ → ℝ} (hθ : Continuous θ) (κ σ r₀ : ℝ) (hκ : 0 < κ) {t T : ℝ≥0} (htT : t ≤ T) : + bondPrice μ (Filtration.natural B fun s ↦ (hBm s).stronglyMeasurable) + (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) t T + =ᵐ[μ] fun ω ↦ HullWhite.bondA (fun s ↦ θ ((t : ℝ) + s)) σ κ ((T - t : ℝ≥0) : ℝ) + * Real.exp (-(vasicekBondB κ ((T - t : ℝ≥0) : ℝ) + * HullWhite.integratedRate hB θ κ σ r₀ hκ t ω)) := by + filter_upwards [HullWhite.bondRate_condExp hB hBm hθ κ σ r₀ hκ htT] with ω h + change (μ[fun ω ↦ Real.exp (-HullWhite.bondRate hB θ κ σ r₀ hκ T ω) | _]) ω + / Real.exp (-HullWhite.bondRate hB θ κ σ r₀ hκ t ω) = _ + rw [h, mul_div_cancel_left₀ _ (Real.exp_pos _).ne'] + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Models/Rates/HullWhiteBondPriceAt.lean b/LeanPool/MathFin/Models/Rates/HullWhiteBondPriceAt.lean new file mode 100644 index 0000000000..dfd1942047 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/HullWhiteBondPriceAt.lean @@ -0,0 +1,164 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.HullWhiteCalibration +public import LeanPool.MathFin.Models.Rates.VasicekBondPriceAt + +/-! +# The Hull–White bond price at a time `t > 0` + +`Models/Rates/HullWhiteCalibration.lean` prices the zero-coupon bond at time `0`, +`P(0, T) = A(T)·exp(−B(T) r₀)` with the forcing `θ` in `A`. This file prices it at a later time +`t`, given the information `𝓕_t = σ(B_s : s ≤ t)` of the driving Brownian motion: + + `𝔼[exp(−∫₀ᵀ r) | 𝓕_t] = exp(−∫₀ᵗ r)·A_t(T − t)·exp(−B(T − t)·r_t)` almost surely, + +where `A_t = bondA (θ(t + ·))` is the time-`0` coefficient of the forcing seen from `t`. It is the +proof of `vasicekBondPrice_condExp` with a different mean identity: both are instances of +`condExp_exp_neg_integratedRate`, which takes the identity +`M(t) − M(T) = −c − B(T − t)·m` between the deterministic parts as its only model input. For the +Hull–White model it is `integratedMean_sub`: + + `∫₀ᵀ α − ∫₀ᵗ α = B(T − t)·α(t) + ∫_t^T θ(s) B(T − s) ds`, + +from the splitting `B(T − s) = B(t − s) + e^{−κ(t−s)} B(T − t)` of the integrated kernel. + +## Main results + +* `integratedMean_sub` — the increment of the integrated deterministic part. +* `bondA_shift` — the coefficient `A_t` is `exp(−∫_t^T θ(s) B(T − s) ds + σ²V(T − t)/2)`. +* `bondRate_condExp` — the conditional discount factor, affine in `r_t`. + +## References + +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + section 3.3.1 +* [J. Hull and A. White, *Pricing interest-rate-derivative securities*][HullWhite1990] + +## Tags + +Hull–White model, conditional bond price, affine term structure, time-dependent drift, short rate, +zero-coupon bond, MSC 91G30, JEL E43 +-/ + +@[expose] public section + +namespace MathFin.HullWhite + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal +open WienerIntegralL2 + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + +private lemma continuous_theta_bondB (θ : ℝ → ℝ) (hθ : Continuous θ) (κ T : ℝ) : + Continuous fun s : ℝ ↦ θ s * vasicekBondB κ (T - s) := by + unfold vasicekBondB; fun_prop + +/-- **The increment of the integrated deterministic part.** From `t` to `T`, the integrated mean +grows by the mean sensitivity `B(T − t)` times the short-rate mean `α(t)` at `t`, plus the forcing +`θ` seen over `[t, T]`: `∫₀ᵀ α − ∫₀ᵗ α = B(T − t)·α(t) + ∫_t^T θ(s) B(T − s) ds`. -/ +lemma integratedMean_sub (θ : ℝ → ℝ) (hθ : Continuous θ) (κ r₀ t T : ℝ) (hκ : κ ≠ 0) : + integratedMean θ κ r₀ T - integratedMean θ κ r₀ t + = vasicekBondB κ (T - t) * deterministic θ κ r₀ t + + ∫ s in t..T, θ s * vasicekBondB κ (T - s) := by + have hexp (s : ℝ) : Real.exp (-(κ * (T - s))) + = Real.exp (-(κ * (t - s))) * Real.exp (-(κ * (T - t))) := by + rw [← Real.exp_add]; congr 1; ring + have hpt (s : ℝ) : θ s * vasicekBondB κ (T - s) = θ s * vasicekBondB κ (t - s) + + (vasicekBondB κ (T - t) * Real.exp (-(κ * t))) * (Real.exp (κ * s) * θ s) := by + have h2 : Real.exp (-(κ * (t - s))) = Real.exp (-(κ * t)) * Real.exp (κ * s) := by + rw [← Real.exp_add]; congr 1; ring + simp only [vasicekBondB, hexp s, h2] + field_simp + ring + have hcont : Continuous fun s : ℝ ↦ Real.exp (κ * s) * θ s := by fun_prop + have h0 : ∫ s in (0 : ℝ)..t, θ s * vasicekBondB κ (T - s) + = (∫ s in (0 : ℝ)..t, θ s * vasicekBondB κ (t - s)) + + (vasicekBondB κ (T - t) * Real.exp (-(κ * t))) + * ∫ s in (0 : ℝ)..t, Real.exp (κ * s) * θ s := by + rw [intervalIntegral.integral_congr (fun s _ ↦ hpt s), + intervalIntegral.integral_add ((continuous_theta_bondB θ hθ κ t).intervalIntegrable 0 t) + ((hcont.const_mul _).intervalIntegrable 0 t), + intervalIntegral.integral_const_mul] + have hT : Real.exp (-(κ * T)) = Real.exp (-(κ * t)) * Real.exp (-(κ * (T - t))) := by + rw [← Real.exp_add]; congr 1; ring + have hBT : vasicekBondB κ T - vasicekBondB κ t + = Real.exp (-(κ * t)) * vasicekBondB κ (T - t) := by + simp only [vasicekBondB, hT]; field_simp; ring + rw [integratedMean_eq θ hθ κ r₀ T hκ, integratedMean_eq θ hθ κ r₀ t hκ, + ← intervalIntegral.integral_add_adjacent_intervals + ((continuous_theta_bondB θ hθ κ T).intervalIntegrable 0 t) + ((continuous_theta_bondB θ hθ κ T).intervalIntegrable t T), h0] + simp only [deterministic] + linear_combination r₀ * hBT + +/-- **The coefficient `A` seen from `t`.** The time-`0` coefficient `A` of the forcing shifted to +start at `t`, at the remaining maturity `T − t`, is the exponent of the forcing over `[t, T]`. -/ +lemma bondA_shift (θ : ℝ → ℝ) (σ κ t T : ℝ) : + bondA (fun s ↦ θ (t + s)) σ κ (T - t) + = Real.exp (-(∫ s in t..T, θ s * vasicekBondB κ (T - s)) + + σ ^ 2 * vasicekBondV κ (T - t) / 2) := by + have h := intervalIntegral.integral_comp_add_left (a := 0) (b := T - t) + (fun s ↦ θ s * vasicekBondB κ (T - s)) t + rw [add_zero, add_sub_cancel] at h + rw [bondA] + simp only [sub_sub] + rw [h] + +variable [IsProbabilityMeasure μ] + +/-- **The Hull–White bond price at time `t`.** Given the information `𝓕_t` of the driving Brownian +motion, for continuous forcing `θ` the discount factor `exp(−∫₀ᵀ r)` along the integrated +Hull–White rate has conditional mean + + `𝔼[exp(−∫₀ᵀ r) | 𝓕_t] = exp(−∫₀ᵗ r)·A_t(T − t)·exp(−B(T − t)·r_t)` + +almost surely, with `r_t` the short rate in its Wiener representation (`integratedRate`) and +`A_t = bondA (θ(t + ·))`, the coefficient of the time-`0` price (`bondPrice_affine`) of the forcing +shifted to `t`, at the remaining maturity. The measure is read as the pricing measure. -/ +theorem bondRate_condExp (hB : IsPreBrownianReal B μ) (hBm : ∀ s, Measurable (B s)) + {θ : ℝ → ℝ} (hθ : Continuous θ) (κ σ r₀ : ℝ) (hκ : 0 < κ) {t T : ℝ≥0} (htT : t ≤ T) : + μ[fun ω ↦ Real.exp (-bondRate hB θ κ σ r₀ hκ T ω) + | Filtration.natural B (fun s ↦ (hBm s).stronglyMeasurable) t] + =ᵐ[μ] fun ω ↦ Real.exp (-bondRate hB θ κ σ r₀ hκ t ω) + * (bondA (fun s ↦ θ ((t : ℝ) + s)) σ κ (((T - t : ℝ≥0) : ℝ)) + * Real.exp (-(vasicekBondB κ ((T - t : ℝ≥0) : ℝ) + * integratedRate hB θ κ σ r₀ hκ t ω))) := by + have hm := integratedMean_sub θ hθ κ r₀ t T hκ.ne' + have key := condExp_exp_neg_integratedRate hB hBm σ hκ htT + (M_t := integratedMean θ κ r₀ t) (M_T := integratedMean θ κ r₀ T) + (c := ∫ s in (t : ℝ)..T, θ s * vasicekBondB κ (T - s)) (m := deterministic θ κ r₀ t) + (by rw [NNReal.coe_sub htT]; linear_combination -hm) + rw [NNReal.coe_sub htT] at key ⊢ + rw [bondA_shift] + exact key + +/-- **The Hull–White coefficient at constant forcing is Vasicek's**: with `θ ≡ κ·θ_v` the affine +coefficient `A(τ) = exp(−∫₀^τ θ B(τ − s) ds + σ²V(τ)/2)` is `vasicekBondA θ_v σ κ τ`, since +`∫₀^τ B(τ − s) ds = (τ − B(τ))/κ` (`integral_vasicekIntegratedKernel`). -/ +lemma bondA_const (θ σ : ℝ) {κ : ℝ} (hκ : κ ≠ 0) (τ : ℝ) : + bondA (fun _ ↦ κ * θ) σ κ τ = vasicekBondA θ σ κ τ := by + have hmass : ∫ s in (0 : ℝ)..τ, vasicekBondB κ (τ - s) = (τ - vasicekBondB κ τ) / κ := + integral_vasicekIntegratedKernel κ τ hκ + rw [bondA, vasicekBondA, intervalIntegral.integral_const_mul, hmass] + congr 2 + field_simp + +omit [IsProbabilityMeasure μ] in +/-- **The Hull–White short rate at constant forcing is Vasicek's**: with `θ ≡ κ·θ_v` the short rate +`α(t) + σ∫₀ᵗ e^{−κ(t−u)} dB_u` is the Vasicek one, `vasicekSDEMean + vasicekDiffusionTerm`. -/ +lemma integratedRate_const (hB : IsPreBrownianReal B μ) (r₀ θ σ : ℝ) {κ : ℝ} (hκ : 0 < κ) + (t : ℝ≥0) (ω : Ω) : + integratedRate hB (fun _ ↦ κ * θ) κ σ r₀ hκ t ω + = vasicekSDEMean r₀ θ κ t + vasicekDiffusionTerm hB κ σ hκ.le t ω := by + rw [integratedRate, vasicekDiffusionTerm, deterministic_const _ _ _ _ hκ.ne', + mul_div_cancel_left₀ _ hκ.ne', vasicekSDEMean_eq_deterministic] + +end MathFin.HullWhite diff --git a/LeanPool/MathFin/Models/Rates/HullWhiteCalibration.lean b/LeanPool/MathFin/Models/Rates/HullWhiteCalibration.lean new file mode 100644 index 0000000000..04aa47010f --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/HullWhiteCalibration.lean @@ -0,0 +1,719 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.VasicekBondPrice +public import LeanPool.MathFin.Models.Rates.VasicekSDEGaussian + +/-! +# Hull–White short rates: deterministic part, Gaussian law, affine bonds, calibration + +The Hull–White model `dr_t = (θ(t) − κ·r_t) dt + σ·dB_t` with `κ > 0` and deterministic +`θ` (continuity hypotheses stated where the FTC needs them), obtained by generalizing the +proved Vasicek template of `MathFin/Models/Rates/VasicekBondPrice.lean`. + +Scope, as in that template: the short rate and its time integral are carried in their +Wiener representations — `integratedRate` and `bondRate` are definitions. That +`integratedRate` solves the SDE above, and that `bondRate T = ∫₀ᵀ integratedRate s ds` +(the time-order swap), are the modelling bridges; neither is proved here. Everything below +is derived from those representations. + +* **The deterministic part** — `deterministic` is the particular solution + `α(t) = e^{−κt}·(r₀ + ∫₀ᵗ e^{κs}·θ(s) ds)` with `α(0) = r₀`. The ODE lemma + `deterministic_solves_ODE` generalizes `vasicekDeterministic_solves_ODE`; constant `θ` + reduces to Vasicek verbatim (`deterministic_const`); uniqueness of the ODE solution + (`deterministic_eq_of_solves_ODE`) writes the deterministic part through any other + solution `α` as `α(t) + (r₀ − α(0))·e^{−κt}` (`deterministic_eq_add_exp_of_solves_ODE`). It + is the centre of the law of `r_t` (`integratedRate_hasLaw_gaussian`). +* **The short rate in Wiener representation** — `integratedRate` (= `deterministic` + + `σ·`Wiener integral of the kernel `e^{−κ(t−u)}`) is Gaussian with the Vasicek variance + `(σ²/2κ)·(1 − e^{−2κt})` — `θ` shifts means, never variances + (`integratedRate_hasLaw_gaussian`). +* **The affine bond price** — the integrated rate reuses the Vasicek integrated kernel + `vasicekIntegratedKernelLp` verbatim (integrating the diffusion kernel over + `s ∈ [u, T]` is model-independent), so `bondPrice_eq` is the Wiener bond-price lemma + `integral_exp_neg_add_mul_wienerIntegralLp` with variance `vasicekBondV` again; `bondA` gains + the `θ`-forcing integral and `bondPrice_affine` gives the time-0 affine form + `A(T)·e^{−B(T)·r₀}`, `A` independent of `r₀` and `B = vasicekBondB` reused verbatim. + `P(t,T)` for `t > 0` is not formalized. +* **Constant forcing is Vasicek** — with `θ ≡ κθ_v` the integrated mean is Vasicek's + `r₀B(T) + θ_v(T − B(T))` (`integratedMean_const`), so the integrated HW rate *is* the + integrated Vasicek rate `vasicekIntegratedRate` at level `θ_v` (`bondRate_const`). +* **Calibration** — `theta` is the calibration formula + `θ(t) = ∂_t f(0,t) + κ·f(0,t) + (σ²/2κ)·(1 − e^{−2κt})`; `calibAlpha_solves_ODE` + verifies by differentiation that the closed form + `β(t) = f(0,t) + (σ²/2κ²)·(1 − e^{−κt})²` solves the HW ODE under this `θ`, uniqueness + (`deterministic_eq_of_solves_ODE`) makes it the calibrated deterministic part + (`mean_eq_forward`; the expected short rate is `calibMean_eq_forward`), and the + calibration integral lemma `∫₀ᵀ α = ∫₀ᵀ f0 + σ²V/2` (`calibIntegratedMean`, via the + kernel reflection `var_eq_interval`) makes `reprices_curve` exact: for `f0 ∈ C¹`, + `κ > 0` and the rate started at `r₀ = f(0,0)`, + `𝔼[exp(−bondRate T)] = exp(−∫₀ᵀ f(0,s) ds)`. + +Structural note: the `θ`-forcing integral lives on the triangle `0 ≤ u ≤ s ≤ t`; rather +than rewrite it over a rectangle for an interval-integral Fubini swap, it is proved by an +antiderivative (`beta_integral`: `G(s) = +(1/κ)·(∫₀ˢ θ − e^{−κs}·∫₀ˢ e^{κu}θ)` has `G' = e^{−κs}·I(s)`, `G(0) = 0`) plus a +pointwise expansion of `θ(s)·B(t−s)` (`integral_theta_B`) — no Fubini anywhere, only +pointwise congruences, linearity, and one `intervalIntegral.integral_comp_sub_left` +reflection. + +## Main definitions + +* `deterministic`: the Hull–White deterministic solution + `α(t) = e^{−κt}·(r₀ + ∫₀ᵗ e^{κs} θ(s) ds)` with `α(0) = r₀`. +* `integratedRate`: the Hull–White short rate in its Wiener representation. +* `integratedMean`, `bondRate`: the deterministic part `∫₀ᵗ α(s) ds` of the integrated short rate, + and the integrated short rate `∫₀ᵗ α + σ·∫₀ᵗ g(u) dB_u` in Wiener representation. +* `bondA`: the affine coefficient `A(T) = exp(−∫₀ᵀ θ(s)·B(T−s) ds + σ²·V(T)/2)`. +* `theta`: the calibrated drift `θ(t)`, given by the calibration formula. +* `calibAlpha`: the closed form `β(t) = f(0,t) + (σ²/2κ²)·(1 − e^{−κt})²`, the initial forward + plus the convexity correction. + +## Main results + +* `deterministic_solves_ODE`, `deterministic_eq_of_solves_ODE`: for continuous `θ`, the + deterministic part solves `α' = θ − κα`, and any everywhere-differentiable solution `α` of that + ODE coincides with `deterministic θ κ (α 0)`. +* `integratedRate_hasLaw_gaussian`: for `κ > 0`, the integrated short rate at time `t` has the + Gaussian law with mean `deterministic θ κ r₀ t` and the Vasicek variance. +* `bondPrice_eq`, `bondPrice_affine`: for `κ > 0`, `𝔼[exp(−bondRate T)]` equals + `exp(−integratedMean T + σ²·vasicekBondV κ T/2)`, which for continuous `θ` is the affine form + `bondA·exp(−B(T)·r₀)`. +* `integratedMean_const`, `bondRate_const`: for `κ ≠ 0` (respectively `κ > 0`), constant forcing + `κθ` gives the Vasicek integrated mean (respectively the Vasicek integrated rate). +* `calibAlpha_solves_ODE`, `mean_eq_forward`: for `f0` of class `C¹` and `κ ≠ 0`, `calibAlpha` + solves the Hull–White ODE under `theta f0 κ σ`, and the deterministic part started at + `f0 0` equals `f0(t) + (σ²/2κ²)(1 − e^{−κt})²`. +* `calibMean_eq_forward`: for `κ > 0`, the expected short rate under `theta` equals + `f0(t) + (σ²/2κ²)(1 − e^{−κt})²`. +* `calibIntegratedMean`: for `κ > 0`, the integrated mean under `theta` equals + `∫₀ᵀ f0 + (σ²/2)·vasicekBondV κ T`. +* `reprices_curve`: for `f0` of class `C¹`, `κ > 0` and `r₀ = f0 0`, + `𝔼[exp(−bondRate T)] = exp(−∫₀ᵀ f0)`. + +## References + +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + §3.3 +* [J. Hull and A. White, *Pricing interest-rate-derivative securities*][HullWhite1990] + +## Tags + +Hull–White model, curve calibration, extended Vasicek, forward rate curve, mean reversion, +Gaussian short rate, affine bond price, MSC 91G30, MSC 60H10, JEL E43 +-/ + +@[expose] public section + +namespace MathFin.HullWhite + +open MeasureTheory ProbabilityTheory Real Set +open scoped NNReal +open MathFin WienerIntegralL2 + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-! ### The deterministic part -/ + +/-- **Hull–White deterministic (particular) solution** with `α(0) = r₀`: +`α(t) = e^{−κt}·(r₀ + ∫₀ᵗ e^{κs} θ(s) ds)`. For non-integrable `θ` the integral is +junk; every meaningful statement below states its hypotheses on `θ` explicitly. -/ +noncomputable def deterministic (θ : ℝ → ℝ) (κ r₀ t : ℝ) : ℝ := + Real.exp (-(κ * t)) * (r₀ + ∫ s in (0 : ℝ)..t, Real.exp (κ * s) * θ s) + +/-- **Initial condition**: `α(0) = r₀` (no hypotheses — the empty integral is 0). -/ +lemma deterministic_at_zero (θ : ℝ → ℝ) (κ r₀ : ℝ) : + deterministic θ κ r₀ 0 = r₀ := by + simp [deterministic, intervalIntegral.integral_same] + +/-- **The HW ODE lemma** (generalizes `vasicekDeterministic_solves_ODE`): with θ +continuous, the particular solution satisfies `α'(t) = θ(t) − κ·α(t)` at every +point. Proof: FTC (`integral_hasDerivAt_right`) for the integral term + product +rule; `e^{−κt}·e^{κt} = 1` collapses the forcing term. -/ +theorem deterministic_solves_ODE (θ : ℝ → ℝ) (hθ : Continuous θ) (κ r₀ t : ℝ) : + HasDerivAt (deterministic θ κ r₀) (θ t - κ * deterministic θ κ r₀ t) t := by + have hfc : Continuous (fun s : ℝ ↦ Real.exp (κ * s) * θ s) := by fun_prop + have hI : HasDerivAt (fun x : ℝ ↦ ∫ s in (0 : ℝ)..x, Real.exp (κ * s) * θ s) + (Real.exp (κ * t) * θ t) t := + intervalIntegral.integral_hasDerivAt_right (hfc.intervalIntegrable 0 t) + (hfc.stronglyMeasurableAtFilter volume (nhds t)) hfc.continuousAt + have hexp1 : HasDerivAt (fun x : ℝ ↦ Real.exp (-(κ * x))) + (Real.exp (-(κ * t)) * (-κ)) t := by + have hk : HasDerivAt (fun x : ℝ ↦ κ * x) κ t := by + simpa using (hasDerivAt_id t).const_mul κ + exact hk.neg.exp + have hprod := hexp1.mul (hI.const_add r₀) + have hexpmul : Real.exp (-(κ * t)) * Real.exp (κ * t) = 1 := by + rw [← Real.exp_add]; simp + have hval : (θ t - κ * deterministic θ κ r₀ t) + = Real.exp (-(κ * t)) * (-κ) * (r₀ + ∫ s in (0 : ℝ)..t, Real.exp (κ * s) * θ s) + + Real.exp (-(κ * t)) * (Real.exp (κ * t) * θ t) := by + have hsplit : Real.exp (-(κ * t)) * (Real.exp (κ * t) * θ t) = θ t := by + rw [← mul_assoc, hexpmul, one_mul] + simp only [deterministic, hsplit] + ring + rw [hval] + exact hprod + +/-- Scalar integral: `∫₀ᵗ e^{κs}·Θ ds = Θ·(e^{κt} − 1)/κ`. -/ +lemma integral_exp_pos_const (Θ κ t : ℝ) (hκ : κ ≠ 0) : + ∫ s in (0 : ℝ)..t, Real.exp (κ * s) * Θ = Θ * (Real.exp (κ * t) - 1) / κ := by + have hF : ∀ s ∈ Set.uIcc (0 : ℝ) t, + HasDerivAt (fun s : ℝ ↦ Θ * Real.exp (κ * s) / κ) (Real.exp (κ * s) * Θ) s := by + intro s _ + have hk : HasDerivAt (fun s : ℝ ↦ κ * s) κ s := by + simpa using (hasDerivAt_id s).const_mul κ + have h := ((hk.exp).const_mul Θ).div_const κ + have hval : (Θ * (Real.exp (κ * s) * κ)) / κ = Real.exp (κ * s) * Θ := by + field_simp + rw [hval] at h + exact h + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hF + (by apply Continuous.intervalIntegrable; fun_prop)] + simp only [mul_zero, Real.exp_zero, mul_one] + field_simp + +/-- **Constant θ reduces to Vasicek**: `deterministic (fun _ ↦ Θ) κ r₀ t = +vasicekDeterministic r₀ (Θ/κ) κ t` — the HW drift `Θ − κr` is Vasicek's +`κ(θ_v − r)` with `θ_v = Θ/κ`, so every proved Vasicek result transfers. -/ +lemma deterministic_const (Θ κ r₀ t : ℝ) (hκ : κ ≠ 0) : + deterministic (fun _ ↦ Θ) κ r₀ t = vasicekDeterministic r₀ (Θ / κ) κ t := by + have hint : ∫ s in (0 : ℝ)..t, Real.exp (κ * s) * Θ + = Θ * (Real.exp (κ * t) - 1) / κ := integral_exp_pos_const Θ κ t hκ + have hexpmul : Real.exp (-(κ * t)) * Real.exp (κ * t) = 1 := by + rw [← Real.exp_add]; simp + simp only [deterministic, hint, vasicekDeterministic] + field_simp [hexpmul] + linear_combination Θ * hexpmul + +/-- **Vasicek's closed form for constant θ**: `deterministic (fun _ ↦ Θ) κ r₀ t += Θ/κ + (r₀ − Θ/κ)·e^{−κt}` — the mean-reversion solution to level `θ_v = Θ/κ` +in explicit form (reached through the bridge `deterministic_const`; +`vasicekDeterministic`'s definition body): constant HW forcing `Θ` is Vasicek +with long-run mean `Θ/κ` — *not* HW forcing `Θ/κ`, which would be Vasicek with +mean `Θ/κ²`. -/ +theorem deterministic_const_closed_form (Θ κ r₀ t : ℝ) (hκ : κ ≠ 0) : + deterministic (fun _ ↦ Θ) κ r₀ t = Θ / κ + (r₀ - Θ / κ) * Real.exp (-(κ * t)) := by + rw [deterministic_const Θ κ r₀ t hκ] + rfl + +/-- **Mean reversion for constant θ**: the deterministic part tends to `Θ/κ`, +mirroring `vasicekDeterministic_tendsto_mean`. -/ +theorem deterministic_const_tendsto (Θ κ r₀ : ℝ) (hκ : 0 < κ) : + Filter.Tendsto (deterministic (fun _ ↦ Θ) κ r₀) Filter.atTop (nhds (Θ / κ)) := by + have h : deterministic (fun _ ↦ Θ) κ r₀ = vasicekDeterministic r₀ (Θ / κ) κ := by + funext t + exact deterministic_const Θ κ r₀ t hκ.ne' + rw [h] + exact vasicekDeterministic_tendsto_mean r₀ (Θ / κ) κ hκ + +/-- Linearity of the particular solution in the initial condition: raising the +initial rate by `a` shifts `α(t)` by `a·e^{−κt}` for every `t`. -/ +lemma deterministic_add_exponential (θ : ℝ → ℝ) (κ r₀ a t : ℝ) : + deterministic θ κ (r₀ + a) t + = deterministic θ κ r₀ t + a * Real.exp (-(κ * t)) := by + simp only [deterministic] + ring + +/-- **Uniqueness of the ODE solution**: any `α` satisfying `α'(s) = θ(s) − κ·α(s)` +at every point (θ continuous) with `α(0) = r₀` equals `deterministic θ κ r₀`. +Proof: `F(s) = e^{κs}(α(s) − α_det(s))` has `F' = 0` everywhere, hence `F ≡ 0`. -/ +theorem deterministic_eq_of_solves_ODE (θ : ℝ → ℝ) (hθ : Continuous θ) (κ : ℝ) + (α : ℝ → ℝ) (hα : ∀ s, HasDerivAt α (θ s - κ * α s) s) (t : ℝ) : + deterministic θ κ (α 0) t = α t := by + have hhwd : ∀ s : ℝ, HasDerivAt (deterministic θ κ (α 0)) + (θ s - κ * deterministic θ κ (α 0) s) s := fun s ↦ + deterministic_solves_ODE θ hθ κ (α 0) s + have hgap : ∀ s : ℝ, HasDerivAt (fun x : ℝ ↦ α x - deterministic θ κ (α 0) x) + (-(κ * (α s - deterministic θ κ (α 0) s))) s := by + intro s + have h := (hα s).sub (hhwd s) + rw [show (θ s - κ * α s) - (θ s - κ * deterministic θ κ (α 0) s) + = -(κ * (α s - deterministic θ κ (α 0) s)) from by ring] at h + exact h + have hF : ∀ s : ℝ, HasDerivAt + (fun x : ℝ ↦ Real.exp (κ * x) * (α x - deterministic θ κ (α 0) x)) 0 s := by + intro s + have hk : HasDerivAt (fun x : ℝ ↦ κ * x) κ s := by + simpa using (hasDerivAt_id s).const_mul κ + have h := (hk.exp).mul (hgap s) + rw [show Real.exp (κ * s) * κ * (α s - deterministic θ κ (α 0) s) + + Real.exp (κ * s) * (-(κ * (α s - deterministic θ κ (α 0) s))) = 0 from by + ring] at h + exact h + have hint : IntervalIntegrable (fun _ : ℝ ↦ (0 : ℝ)) volume 0 t := by + apply Continuous.intervalIntegrable + fun_prop + have hsub := intervalIntegral.integral_eq_sub_of_hasDerivAt (fun s _ ↦ hF s) hint + rw [intervalIntegral.integral_const] at hsub + simp only [sub_zero, smul_zero, mul_zero, Real.exp_zero, one_mul] at hsub + have hF0 : α 0 - deterministic θ κ (α 0) 0 = 0 := by + rw [deterministic_at_zero]; ring + rw [hF0, sub_zero] at hsub + have hgap : α t - deterministic θ κ (α 0) t = 0 := by + refine mul_left_cancel₀ (Real.exp_ne_zero (κ * t)) ?_ + rw [mul_zero] + exact hsub.symm + exact (eq_of_sub_eq_zero hgap).symm + +/-- **The deterministic part through any ODE solution**: with any `α` solving +`α' = θ − κα` pointwise (θ continuous), the deterministic part of the HW short rate is +`α(t) + (r₀ − α(0))·e^{−κt}` — the particular solution plus the exponentially decaying +initial gap. It is the centre of the law of `r_t` (`integratedRate_hasLaw_gaussian`); +the expectation itself is stated under calibration, `calibMean_eq_forward`. -/ +theorem deterministic_eq_add_exp_of_solves_ODE (θ : ℝ → ℝ) (κ : ℝ) (α : ℝ → ℝ) + (hα : ∀ s, HasDerivAt α (θ s - κ * α s) s) (hθ : Continuous θ) (r₀ t : ℝ) : + deterministic θ κ r₀ t = α t + (r₀ - α 0) * Real.exp (-(κ * t)) := by + have hsplit : α 0 + (r₀ - α 0) = r₀ := by ring + rw [show r₀ = α 0 + (r₀ - α 0) from hsplit.symm, deterministic_add_exponential, + deterministic_eq_of_solves_ODE θ hθ κ α hα] + ring + +/-! ### The short rate and its Gaussian law -/ + +/- The HW diffusion kernel `e^{−κ(t−u)}` — the deterministic integrand of the +short rate's Wiener part `σ∫₀ᵗ e^{−κ(t−u)} dB_u` — is the Vasicek kernel +`vasicekKernel` of `Models/Rates/VasicekSDEGaussian` verbatim, and is used through its +`L²` element `vasicekKernelLp` there; nothing kernel-specific is redefined here. -/ + +/-- **The HW short rate in Wiener representation** (the counterpart of the Vasicek +short rate of `VasicekSDEGaussian`), defined as `r_t = α(t) + σ·∫₀ᵗ e^{−κ(t−u)} dB_u` +with `α` the particular solution `deterministic θ κ r₀` and the diffusion kernel the +Vasicek `vasicekKernelLp` reused verbatim. That it solves the HW SDE is +the modelling bridge, not proved here. -/ +noncomputable def integratedRate (hB : IsPreBrownianReal B μ) (θ : ℝ → ℝ) + (κ σ r₀ : ℝ) (hκ : 0 < κ) (t : ℝ≥0) (ω : Ω) : ℝ := + deterministic θ κ r₀ (t : ℝ) + + σ * (wienerIntegralLp B hB t (vasicekKernelLp κ hκ.le t) ω) + +/-- **The HW short rate is Gaussian**: `r_t ~ N(α(t), σ²(1 − e^{−2κt})/(2κ))` — +θ(t) shifted the mean and left the Vasicek variance untouched: the zero-mean Vasicek law +(`vasicekShortRate_hasLaw_gaussian` at `r₀ = θ = 0`) shifted by `α(t)`. -/ +theorem integratedRate_hasLaw_gaussian (hB : IsPreBrownianReal B μ) (θ : ℝ → ℝ) + (κ σ r₀ : ℝ) (hκ : 0 < κ) (t : ℝ≥0) : + HasLaw (integratedRate hB θ κ σ r₀ hκ t) + (gaussianReal (deterministic θ κ r₀ (t : ℝ)) + ((vasicekSDEVariance σ κ (t : ℝ)).toNNReal)) μ := by + unfold integratedRate + simpa only [vasicekSDEMean, zero_mul, zero_add, add_zero] using + gaussianReal_const_add (vasicekShortRate_hasLaw_gaussian hB 0 0 σ hκ t) + (deterministic θ κ r₀ (t : ℝ)) + +/-! ### The affine bond price -/ + +/-- The deterministic part `∫₀ᵗ α(s) ds` of the integrated HW short rate (`bondRate`). -/ +noncomputable def integratedMean (θ : ℝ → ℝ) (κ r₀ t : ℝ) : ℝ := + ∫ s in (0 : ℝ)..t, deterministic θ κ r₀ s + +/-- The Vasicek affine coefficient is the integrated diffusion kernel: +`∫₀ᵗ e^{−κs} ds = (1 − e^{−κt})/κ = vasicekBondB κ t` — the identity that makes +`B` carry over from Vasicek to HW verbatim. -/ +lemma integral_exp_neg_eq_bondB (κ t : ℝ) (hκ : κ ≠ 0) : + ∫ s in (0 : ℝ)..t, Real.exp (-(κ * s)) = vasicekBondB κ t := by + have hF : ∀ s ∈ Set.uIcc (0 : ℝ) t, + HasDerivAt (fun s : ℝ ↦ -Real.exp (-(κ * s)) / κ) (Real.exp (-(κ * s))) s := by + intro s _ + have hk : HasDerivAt (fun s : ℝ ↦ κ * s) κ s := by + simpa using (hasDerivAt_id s).const_mul κ + have hexpneg : HasDerivAt (fun x : ℝ ↦ Real.exp (-(κ * x))) + (Real.exp (-(κ * s)) * (-κ)) s := by + simpa using hk.neg.exp + have h := hexpneg.neg.div_const κ + have hval : -((Real.exp (-(κ * s)) * -κ)) / κ = Real.exp (-(κ * s)) := by + field_simp + rw [hval] at h + exact h + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hF + (by apply Continuous.intervalIntegrable; fun_prop)] + simp only [mul_zero, neg_zero, Real.exp_zero] + rw [vasicekBondB] + field_simp + ring + +/-- **The forcing integral** (the antiderivative route; the integral lives on the +triangle `0 ≤ u ≤ s ≤ t`): +`∫₀ᵗ e^{−κs}·(∫₀ˢ e^{κu}θ(u) du) ds = (1/κ)·(∫₀ᵗ θ − e^{−κt}·∫₀ᵗ e^{κu}θ(u) du)`. +`G(s) = (1/κ)(∫₀ˢ θ − e^{−κs}·∫₀ˢ e^{κu}θ)` satisfies `G' = e^{−κs}·I(s)`, +`G(0) = 0`. -/ +lemma beta_integral (θ : ℝ → ℝ) (hθ : Continuous θ) (κ t : ℝ) (hκ : κ ≠ 0) : + ∫ s in (0 : ℝ)..t, Real.exp (-(κ * s)) * (∫ u in (0 : ℝ)..s, Real.exp (κ * u) * θ u) + = (1 / κ) * ((∫ s in (0 : ℝ)..t, θ s) + - Real.exp (-(κ * t)) * (∫ s in (0 : ℝ)..t, Real.exp (κ * s) * θ s)) := by + have hI : ∀ s : ℝ, HasDerivAt (fun x : ℝ ↦ ∫ u in (0 : ℝ)..x, Real.exp (κ * u) * θ u) + (Real.exp (κ * s) * θ s) s := by + intro s + have hfc : Continuous (fun u : ℝ ↦ Real.exp (κ * u) * θ u) := by fun_prop + exact intervalIntegral.integral_hasDerivAt_right (hfc.intervalIntegrable 0 s) + (hfc.stronglyMeasurableAtFilter volume (nhds s)) hfc.continuousAt + have hD : ∀ s : ℝ, HasDerivAt (fun x : ℝ ↦ ∫ u in (0 : ℝ)..x, θ u) (θ s) s := by + intro s + exact intervalIntegral.integral_hasDerivAt_right (hθ.intervalIntegrable 0 s) + (hθ.stronglyMeasurableAtFilter volume (nhds s)) hθ.continuousAt + have hE : ∀ s : ℝ, HasDerivAt (fun x : ℝ ↦ Real.exp (-(κ * x))) + (Real.exp (-(κ * s)) * (-κ)) s := by + intro s + have hk : HasDerivAt (fun x : ℝ ↦ κ * x) κ s := by + simpa using (hasDerivAt_id s).const_mul κ + exact hk.neg.exp + have hG : ∀ s : ℝ, HasDerivAt + (fun x : ℝ ↦ (1 / κ) * ((∫ u in (0 : ℝ)..x, θ u) + - Real.exp (-(κ * x)) * (∫ u in (0 : ℝ)..x, Real.exp (κ * u) * θ u))) + (Real.exp (-(κ * s)) * (∫ u in (0 : ℝ)..s, Real.exp (κ * u) * θ u)) s := by + intro s + have hexpmul : Real.exp (-(κ * s)) * Real.exp (κ * s) = 1 := by + rw [← Real.exp_add]; simp + have h := ((hD s).sub ((hE s).mul (hI s))).const_mul (1 / κ) + rw [← mul_assoc (Real.exp (-(κ * s))) (Real.exp (κ * s)) (θ s), hexpmul, one_mul] at h + have hval : (1 / κ) * (θ s + - (Real.exp (-(κ * s)) * -κ * (∫ u in (0 : ℝ)..s, Real.exp (κ * u) * θ u) + θ s)) + = Real.exp (-(κ * s)) * (∫ u in (0 : ℝ)..s, Real.exp (κ * u) * θ u) := by + field_simp + ring + rw [hval] at h + exact h + have hint : IntervalIntegrable + (fun s : ℝ ↦ Real.exp (-(κ * s)) + * (∫ u in (0 : ℝ)..s, Real.exp (κ * u) * θ u)) volume 0 t := by + have hfc : Continuous (fun u : ℝ ↦ Real.exp (κ * u) * θ u) := by fun_prop + apply Continuous.intervalIntegrable + exact (by fun_prop : Continuous (fun x : ℝ ↦ Real.exp (-(κ * x)))).mul + (intervalIntegral.continuous_primitive (fun a b ↦ hfc.intervalIntegrable a b) 0) + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt (fun s _ ↦ hG s) hint] + have h0 : (1 / κ) * ((∫ u in (0 : ℝ)..0, θ u) + - Real.exp (-(κ * 0)) * (∫ u in (0 : ℝ)..0, Real.exp (κ * u) * θ u)) = 0 := by + simp [intervalIntegral.integral_same] + rw [h0, sub_zero] + +/-- The A-integral in split form: `∫₀ᵗ θ(s)·B(t−s) ds = +(1/κ)·(∫₀ᵗ θ − e^{−κt}·∫₀ᵗ e^{κs}θ(s) ds)` — pure pointwise algebra on +`B(τ) = (1 − e^{−κτ})/κ`, no Fubini. -/ +lemma integral_theta_B (θ : ℝ → ℝ) (κ t : ℝ) (hθ : Continuous θ) (hκ : κ ≠ 0) : + ∫ s in (0 : ℝ)..t, θ s * vasicekBondB κ (t - s) + = (1 / κ) * ((∫ s in (0 : ℝ)..t, θ s) + - Real.exp (-(κ * t)) * (∫ s in (0 : ℝ)..t, Real.exp (κ * s) * θ s)) := by + have hpt : ∀ s : ℝ, θ s * vasicekBondB κ (t - s) + = (1 / κ) * θ s - (1 / κ) * (Real.exp (-(κ * t)) * (Real.exp (κ * s) * θ s)) := by + intro s + rw [vasicekBondB] + have hrw : Real.exp (-(κ * (t - s))) = Real.exp (-(κ * t)) * Real.exp (κ * s) := by + rw [← Real.exp_add]; congr 1; ring + rw [hrw] + field_simp + rw [intervalIntegral.integral_congr + (show EqOn (fun s : ℝ ↦ θ s * vasicekBondB κ (t - s)) + (fun s : ℝ ↦ (1 / κ) * θ s - (1 / κ) * (Real.exp (-(κ * t)) * (Real.exp (κ * s) * θ s))) + (Set.uIcc (0 : ℝ) t) from fun s _ ↦ hpt s)] + rw [intervalIntegral.integral_sub + ((by fun_prop : Continuous (fun s : ℝ ↦ (1 / κ) * θ s)).intervalIntegrable 0 t) + ((by fun_prop : Continuous (fun s : ℝ ↦ (1 / κ) * (Real.exp (-(κ * t)) + * (Real.exp (κ * s) * θ s)))).intervalIntegrable 0 t)] + simp only [intervalIntegral.integral_const_mul] + ring + +/-- **Mean of the integrated HW rate in B-form**: `∫₀ᵗ α(s) ds = r₀·B(t) + +∫₀ᵗ θ(s)·B(t−s) ds` — the r₀-separation that makes A r₀-free (the affine content; +Vasicek's closed form `r₀·B + θ_v·(t − B)` is the constant-θ special case). -/ +lemma integratedMean_eq (θ : ℝ → ℝ) (hθ : Continuous θ) (κ r₀ t : ℝ) (hκ : κ ≠ 0) : + integratedMean θ κ r₀ t + = r₀ * vasicekBondB κ t + ∫ s in (0 : ℝ)..t, θ s * vasicekBondB κ (t - s) := by + have hsplit : ∀ s : ℝ, deterministic θ κ r₀ s + = r₀ * Real.exp (-(κ * s)) + + Real.exp (-(κ * s)) * (∫ u in (0 : ℝ)..s, Real.exp (κ * u) * θ u) := by + intro s + simp only [deterministic] + rw [mul_add, mul_comm r₀ (Real.exp (-(κ * s)))] + have hbeta : ∫ s in (0 : ℝ)..t, + Real.exp (-(κ * s)) * (∫ u in (0 : ℝ)..s, Real.exp (κ * u) * θ u) + = ∫ s in (0 : ℝ)..t, θ s * vasicekBondB κ (t - s) := by + rw [beta_integral θ hθ κ t hκ, integral_theta_B θ κ t hθ hκ] + have hsplitint : ∫ x in (0 : ℝ)..t, deterministic θ κ r₀ x ∂volume + = ∫ x in (0 : ℝ)..t, (r₀ * Real.exp (-(κ * x)) + + Real.exp (-(κ * x)) * (∫ u in (0 : ℝ)..x, Real.exp (κ * u) * θ u)) ∂volume := + intervalIntegral.integral_congr (fun x _ ↦ hsplit x) + have hadd : ∫ x in (0 : ℝ)..t, (r₀ * Real.exp (-(κ * x)) + + Real.exp (-(κ * x)) * (∫ u in (0 : ℝ)..x, Real.exp (κ * u) * θ u)) ∂volume + = ∫ x in (0 : ℝ)..t, r₀ * Real.exp (-(κ * x)) ∂volume + + ∫ x in (0 : ℝ)..t, Real.exp (-(κ * x)) + * (∫ u in (0 : ℝ)..x, Real.exp (κ * u) * θ u) ∂volume := by + refine intervalIntegral.integral_add ?_ ?_ + · exact (by fun_prop : Continuous + (fun s : ℝ ↦ r₀ * Real.exp (-(κ * s)))).intervalIntegrable 0 t + · have hfc : Continuous (fun u : ℝ ↦ Real.exp (κ * u) * θ u) := by fun_prop + have hcont : Continuous (fun x : ℝ ↦ ∫ u in (0 : ℝ)..x, Real.exp (κ * u) * θ u) := + intervalIntegral.continuous_primitive (fun a b ↦ hfc.intervalIntegrable a b) 0 + exact ((by fun_prop : Continuous + (fun x : ℝ ↦ Real.exp (-(κ * x)))).mul hcont).intervalIntegrable 0 t + rw [integratedMean, hsplitint, hadd, intervalIntegral.integral_const_mul, + integral_exp_neg_eq_bondB κ t hκ, hbeta] + +/-- **The integrated HW short rate** in Wiener representation (mirror of +`vasicekIntegratedRate`), defined as `∫₀ᵗ α + σ·∫₀ᵗ g(u) dB_u` — the representation of +`∫₀ᵗ r_s ds` after the time-order swap, which is the modelling bridge — with `g` the +**Vasicek integrated kernel reused verbatim** (`vasicekIntegratedKernelLp`): +integrating the diffusion kernel `e^{−κ(s−u)}` over `s ∈ [u, T]` is +model-independent, so kernel, L²-element and variance all carry over. -/ +noncomputable def bondRate (hB : IsPreBrownianReal B μ) (θ : ℝ → ℝ) (κ σ r₀ : ℝ) + (hκ : 0 < κ) (T : ℝ≥0) (ω : Ω) : ℝ := + integratedMean θ κ r₀ (T : ℝ) + + σ * (wienerIntegralLp B hB T (vasicekIntegratedKernelLp hκ T) ω) + +/-- **The HW zero-coupon bond price** — the exponential-Gaussian moment: +`P(0,T) = 𝔼[exp(−bondRate T)] = exp(−∫₀ᵀ α + σ²·V(T)/2)` with `V = vasicekBondV` +the Vasicek variance, unchanged: the Wiener bond-price lemma +`integral_exp_neg_add_mul_wienerIntegralLp` at `m = ∫₀ᵀ α`, `c = σ` and the Vasicek integrated +kernel. -/ +theorem bondPrice_eq (hB : IsPreBrownianReal B μ) (θ : ℝ → ℝ) (κ σ r₀ : ℝ) + (hκ : 0 < κ) (T : ℝ≥0) : + ∫ ω, Real.exp (-(bondRate hB θ κ σ r₀ hκ T ω)) ∂μ + = Real.exp (-(integratedMean θ κ r₀ (T : ℝ)) + + σ ^ 2 * vasicekBondV κ (T : ℝ) / 2) := + (integral_exp_neg_add_mul_wienerIntegralLp hB T (integratedMean θ κ r₀ (T : ℝ)) σ + (vasicekIntegratedKernelLp hκ T)).trans <| by rw [vasicekIntegratedKernelLp_integral_sq hκ T] + +/-- **Constant forcing, integrated**: with `θ ≡ κ·θ_v` the integrated deterministic part is +Vasicek's `∫₀ᵀ α = r₀·B(T) + θ_v·(T − B(T))` (`κ ≠ 0`): `integratedMean_eq` plus the kernel mass +`∫₀ᵀ B(T − s) ds = (T − B(T))/κ` (`integral_vasicekIntegratedKernel`). -/ +theorem integratedMean_const (r₀ θ : ℝ) {κ : ℝ} (hκ : κ ≠ 0) (T : ℝ) : + integratedMean (fun _ ↦ κ * θ) κ r₀ T = vasicekIntegratedMean r₀ θ κ T := by + have hmass : ∫ s in (0 : ℝ)..T, vasicekBondB κ (T - s) = (T - vasicekBondB κ T) / κ := + integral_vasicekIntegratedKernel κ T hκ + rw [integratedMean_eq _ continuous_const κ r₀ T hκ, intervalIntegral.integral_const_mul, hmass, + vasicekIntegratedMean] + field_simp + +omit [IsProbabilityMeasure μ] in +/-- **Hull–White with constant forcing is Vasicek**: with `θ ≡ κ·θ_v`, the integrated HW short +rate is the integrated Vasicek short rate at long-run level `θ_v`, as random variables (same +deterministic part by `integratedMean_const`, same Wiener part by construction). -/ +theorem bondRate_const (hB : IsPreBrownianReal B μ) (r₀ θ σ : ℝ) {κ : ℝ} (hκ : 0 < κ) + (T : ℝ≥0) : + bondRate hB (fun _ ↦ κ * θ) κ σ r₀ hκ T = vasicekIntegratedRate hB r₀ θ σ hκ T := by + funext ω + rw [bondRate, vasicekIntegratedRate, integratedMean_const r₀ θ hκ.ne'] + +/-- The HW affine coefficient `A(T) = exp(−∫₀ᵀ θ(s)·B(T−s) ds + σ²·V(T)/2)` — +Vasicek's `vasicekBondA` with the constant-drift term `θ_v·(T − B(T))` replaced by +the θ-forcing integral. (`∫₀ᵀ B(T−s)² ds = vasicekBondV κ T`, so the variance +term is exactly `(σ²/2)·∫₀ᵀ B(τ)² dτ`, the standard Hull–White `A`.) -/ +noncomputable def bondA (θ : ℝ → ℝ) (σ κ t : ℝ) : ℝ := + Real.exp (-(∫ s in (0 : ℝ)..t, θ s * vasicekBondB κ (t - s)) + + σ ^ 2 * vasicekBondV κ t / 2) + +/-- **The time-0 affine form**: `P(0,T) = A(T)·exp(−B(T)·r₀)` with `B` the Vasicek +coefficient **verbatim** and `A` carrying the θ-forcing, independent of `r₀` (the exact +analogue of `vasicekBondPrice_affine`). `P(t,T)` for `t > 0` is not formalized. -/ +theorem bondPrice_affine (hB : IsPreBrownianReal B μ) (θ : ℝ → ℝ) (κ σ r₀ : ℝ) + (hθ : Continuous θ) (hκ : 0 < κ) (T : ℝ≥0) : + ∫ ω, Real.exp (-(bondRate hB θ κ σ r₀ hκ T ω)) ∂μ + = bondA θ σ κ (T : ℝ) * Real.exp (-(vasicekBondB κ (T : ℝ) * r₀)) := by + rw [bondPrice_eq hB θ κ σ r₀ hκ T, bondA, + integratedMean_eq θ hθ κ r₀ (T : ℝ) hκ.ne', ← Real.exp_add] + congr 1 + ring + +/-! ### Calibration — `θ` from the initial forward curve -/ + +/-- **The calibrated drift**, the calibration formula (justified by +`calibAlpha_solves_ODE` and `reprices_curve`): +`θ(t) = ∂_t f(0,t) + κ·f(0,t) + (σ²/2κ)·(1 − e^{−2κt})` — the initial +instantaneous forward curve's slope, plus mean reversion, plus the HJM convexity +correction. Defined with `deriv` (total, junk off-curve); every theorem below +binds `hf0 : ContDiff ℝ 1 f0`, which packages differentiability of `f0` and +continuity of `deriv f0` (`contDiff_one_iff_deriv`). -/ +noncomputable def theta (f0 : ℝ → ℝ) (κ σ : ℝ) (t : ℝ) : ℝ := + deriv f0 t + κ * f0 t + (σ ^ 2 / (2 * κ)) * (1 - Real.exp (-(2 * κ * t))) + +/-- The closed form `β(t) = f(0,t) + (σ²/2κ²)·(1 − e^{−κt})²` — the initial forward plus +the convexity correction. A definition: that it is the calibrated deterministic part is +`mean_eq_forward` (for `f0 ∈ C¹`, `κ ≠ 0`, `r₀ = f(0,0)`), and that it is the expected short +rate is `calibMean_eq_forward` (for `κ > 0`). -/ +noncomputable def calibAlpha (f0 : ℝ → ℝ) (κ σ : ℝ) (t : ℝ) : ℝ := + f0 t + (σ ^ 2 / (2 * κ ^ 2)) * (1 - Real.exp (-(κ * t))) ^ 2 + +/-- `theta` is continuous for a `C¹` curve — `deriv f0` is continuous by +`contDiff_one_iff_deriv`. -/ +lemma theta_continuous (f0 : ℝ → ℝ) (hf0 : ContDiff ℝ 1 f0) (κ σ : ℝ) : + Continuous (theta f0 κ σ) := by + obtain ⟨_, hdd⟩ := contDiff_one_iff_deriv.mp hf0 + exact (hdd.add (hf0.continuous.const_mul κ)).add + (by fun_prop : Continuous fun t : ℝ ↦ (σ ^ 2 / (2 * κ)) * (1 - Real.exp (-(2 * κ * t)))) + +/-- **The calibrated β solves the HW ODE** (verified by differentiation): with `f0` a `C¹` curve, +`β(t) = f(0,t) + (σ²/2κ²)(1 − e^{−κt})²` satisfies +`β'(t) = θ(t) − κ·β(t)` pointwise for `θ = theta f0 κ σ`. Chain rule on β plus the +pointwise algebra `(1 − E²) − (1 − E)² = 2E(1 − E)` (`E = e^{−κt}`); this is what makes the +θ-formula a calibration (sufficient for exact repricing, `reprices_curve`; uniqueness of `θ` is +not proved). -/ +theorem calibAlpha_solves_ODE (f0 : ℝ → ℝ) (hf0 : ContDiff ℝ 1 f0) (κ σ : ℝ) + (hκ : κ ≠ 0) (t : ℝ) : + HasDerivAt (calibAlpha f0 κ σ) (theta f0 κ σ t - κ * calibAlpha f0 κ σ t) t := by + have hfd : HasDerivAt f0 (deriv f0 t) t := (hf0.differentiable_one t).hasDerivAt + have hk : HasDerivAt (fun x : ℝ ↦ κ * x) κ t := by + simpa using (hasDerivAt_id t).const_mul κ + have hexp : HasDerivAt (fun x : ℝ ↦ Real.exp (-(κ * x))) + (Real.exp (-(κ * t)) * (-κ)) t := hk.neg.exp + have hsub : HasDerivAt (fun x : ℝ ↦ 1 - Real.exp (-(κ * x))) + (κ * Real.exp (-(κ * t))) t := by + have h0 := (hasDerivAt_const t 1).sub hexp + rwa [show (0 : ℝ) - Real.exp (-(κ * t)) * (-κ) + = κ * Real.exp (-(κ * t)) from by ring] at h0 + have hsq : HasDerivAt (fun x : ℝ ↦ (1 - Real.exp (-(κ * x))) ^ 2) + (2 * (1 - Real.exp (-(κ * t))) * (κ * Real.exp (-(κ * t)))) t := by + have h0 := hsub.mul hsub + rw [show κ * Real.exp (-(κ * t)) * (1 - Real.exp (-(κ * t))) + + (1 - Real.exp (-(κ * t))) * (κ * Real.exp (-(κ * t))) + = 2 * (1 - Real.exp (-(κ * t))) * (κ * Real.exp (-(κ * t))) from by ring] at h0 + exact h0.congr_of_eventuallyEq (Filter.Eventually.of_forall fun y ↦ pow_two _) + have hcm : HasDerivAt + (fun x : ℝ ↦ (σ ^ 2 / (2 * κ ^ 2)) * (1 - Real.exp (-(κ * x))) ^ 2) + ((σ ^ 2 / (2 * κ ^ 2)) * (2 * (1 - Real.exp (-(κ * t))) + * (κ * Real.exp (-(κ * t))))) t := hsq.const_mul (σ ^ 2 / (2 * κ ^ 2)) + have hE2 : Real.exp (-(2 * κ * t)) = Real.exp (-(κ * t)) ^ 2 := by + rw [pow_two, ← Real.exp_add] + congr 1 + ring + have hval : theta f0 κ σ t - κ * calibAlpha f0 κ σ t + = deriv f0 t + (σ ^ 2 / (2 * κ ^ 2)) * (2 * (1 - Real.exp (-(κ * t))) + * (κ * Real.exp (-(κ * t)))) := by + simp only [theta, calibAlpha, hE2] + field_simp + ring + rw [hval] + exact hfd.add hcm + +/-- **The calibrated deterministic part**: the HW particular solution driven by `theta` +and started at the initial forward `r₀ = f(0,0)` is exactly +`β(t) = f(0,t) + (σ²/2κ²)(1 − e^{−κt})²` — the initial forward plus the convexity +correction (`calibMean_eq_forward` turns it into the expected short rate). Route: +`calibAlpha_solves_ODE` (verified by differentiation) + ODE uniqueness +(`deterministic_eq_of_solves_ODE`; note +`β(0) = f(0,0)` automatically, since `(1 − e^{−κ·0})² = 0`). Only `κ ≠ 0` is +needed — the θ-formula divides by κ; no positivity enters the deterministic +identity. -/ +theorem mean_eq_forward (f0 : ℝ → ℝ) (hf0 : ContDiff ℝ 1 f0) (κ σ : ℝ) (hκ : κ ≠ 0) (t : ℝ) : + deterministic (theta f0 κ σ) κ (f0 0) t + = f0 t + (σ ^ 2 / (2 * κ ^ 2)) * (1 - Real.exp (-(κ * t))) ^ 2 := by + have h := deterministic_eq_of_solves_ODE (theta f0 κ σ) + (theta_continuous f0 hf0 κ σ) κ (calibAlpha f0 κ σ) + (fun s ↦ calibAlpha_solves_ODE f0 hf0 κ σ hκ s) t + rwa [show calibAlpha f0 κ σ 0 = f0 0 from by simp [calibAlpha]] at h + +/-- **The calibrated deterministic part, for `κ > 0`** (`mean_eq_forward`): the HW +particular solution driven by `theta` and +started at the initial forward `r₀ = f(0,0)` is exactly +`β(t) = f(0,t) + (σ²/2κ²)(1 − e^{−κt})²` — `calibAlpha_solves_ODE` + ODE +uniqueness (`deterministic_eq_of_solves_ODE`; note `β(0) = f(0,0)` +automatically, since `(1 − e^{−κ·0})² = 0`). -/ +theorem calibMean (f0 : ℝ → ℝ) (hf0 : ContDiff ℝ 1 f0) (κ σ : ℝ) (hκ : 0 < κ) (t : ℝ) : + deterministic (theta f0 κ σ) κ (f0 0) t + = f0 t + (σ ^ 2 / (2 * κ ^ 2)) * (1 - Real.exp (-(κ * t))) ^ 2 := + mean_eq_forward f0 hf0 κ σ hκ.ne' t + +/-- **The mean identity at the law level**: `𝔼[r_t] = f(0,t) + +(σ²/2κ²)(1 − e^{−κt})²` — the expected HW short rate under calibration is the +initial forward plus the convexity correction (the centred Gaussian part +contributes zero: `integratedRate_hasLaw_gaussian` + +`integral_id_gaussianReal`). -/ +theorem calibMean_eq_forward (hB : IsPreBrownianReal B μ) (f0 : ℝ → ℝ) + (hf0 : ContDiff ℝ 1 f0) (κ σ : ℝ) (hκ : 0 < κ) (t : ℝ≥0) : + ∫ ω, integratedRate hB (theta f0 κ σ) κ σ (f0 0) hκ t ω ∂μ + = f0 (t : ℝ) + (σ ^ 2 / (2 * κ ^ 2)) * (1 - Real.exp (-(κ * (t : ℝ)))) ^ 2 := by + have hlaw := integratedRate_hasLaw_gaussian hB (theta f0 κ σ) κ σ (f0 0) hκ t + rw [hlaw.integral_eq, integral_id_gaussianReal, + calibMean f0 hf0 κ σ hκ (t : ℝ)] + +/-- **The variance identity for calibration**: `V(T) = ∫₀ᵀ B(u)² du` in interval +form. Route: `vasicekIntegratedKernel_integral_sq` gives the `Ioc`-integral of +the integrated kernel `g(u) = B(T−u)`; `intervalIntegral.integral_of_le` moves to +interval form, the integrand is `vasicekBondB κ (T−u)` definitionally, and the +reflection `∫₀ᵀ φ(u) du = ∫₀ᵀ φ(T−u) du` (`integral_comp_sub_left`) lands on +`B(u)` — the L²-norm is symmetric under `u ↦ T−u`. -/ +lemma var_eq_interval (κ : ℝ) (hκ : κ ≠ 0) (𝕋 : ℝ≥0) : + vasicekBondV κ (𝕋 : ℝ) = ∫ u in (0 : ℝ)..(𝕋 : ℝ), (vasicekBondB κ u) ^ 2 := by + have href : ∫ u in (0 : ℝ)..(𝕋 : ℝ), (vasicekBondB κ u) ^ 2 + = ∫ u in (0 : ℝ)..(𝕋 : ℝ), (vasicekBondB κ ((𝕋 : ℝ) - u)) ^ 2 := by + rw [intervalIntegral.integral_comp_sub_left + (f := fun u : ℝ ↦ (vasicekBondB κ u) ^ 2) (𝕋 : ℝ)] + simp + have h2 := vasicekIntegratedKernel_integral_sq hκ 𝕋 + have h3 : (∫ u in Set.Ioc (0 : ℝ) (𝕋 : ℝ), + (vasicekIntegratedKernel κ (𝕋 : ℝ) u) ^ 2 ∂volume) + = ∫ u in (0 : ℝ)..(𝕋 : ℝ), (vasicekIntegratedKernel κ (𝕋 : ℝ) u) ^ 2 ∂volume := + (intervalIntegral.integral_of_le 𝕋.prop).symm + rw [← h2, h3, intervalIntegral.integral_congr + (show EqOn (fun u : ℝ ↦ (vasicekIntegratedKernel κ (𝕋 : ℝ) u) ^ 2) + (fun u : ℝ ↦ (vasicekBondB κ ((𝕋 : ℝ) - u)) ^ 2) (Set.uIcc (0 : ℝ) (𝕋 : ℝ)) + from fun u _ ↦ rfl)] + exact href.symm + +/-- The κ²-scaling bridge: `κ²·∫₀ᵀ B(u)² du = ∫₀ᵀ (1 − e^{−κu})² du` — pure +pointwise algebra on `B(u) = (1 − e^{−κu})/κ`. -/ +private lemma calibVar_key (κ : ℝ) (hκ : κ ≠ 0) (𝕋 : ℝ≥0) : + κ ^ 2 * (∫ s in (0 : ℝ)..(𝕋 : ℝ), (vasicekBondB κ s) ^ 2) + = ∫ s in (0 : ℝ)..(𝕋 : ℝ), (1 - Real.exp (-(κ * s))) ^ 2 := by + rw [← intervalIntegral.integral_const_mul] + refine intervalIntegral.integral_congr + (show EqOn (fun s : ℝ ↦ κ ^ 2 * (vasicekBondB κ s) ^ 2) + (fun s : ℝ ↦ (1 - Real.exp (-(κ * s))) ^ 2) (Set.uIcc (0 : ℝ) (𝕋 : ℝ)) + from fun s _ ↦ ?_) + change κ ^ 2 * ((1 - Real.exp (-(κ * s))) / κ) ^ 2 = (1 - Real.exp (-(κ * s))) ^ 2 + field_simp + +/-- **The convexity-correction integral in isolation**: +`∫₀ᵀ (σ²/2κ²)(1 − e^{−κs})² ds = (σ²/2)·V(T)` — the mean-correction term of +`mean_eq_forward`, integrated, equals half the integrated-rate variance: the +exact quantity the Gaussian bond moment's `σ²V/2` cancels, which is why +`reprices_curve` is exact (`calibIntegratedMean` = `∫₀ᵀ f0` + this). -/ +theorem calibCorrection_integral (κ σ : ℝ) (hκ : κ ≠ 0) (𝕋 : ℝ≥0) : + ∫ s in (0 : ℝ)..(𝕋 : ℝ), (σ ^ 2 / (2 * κ ^ 2)) * (1 - Real.exp (-(κ * s))) ^ 2 + = σ ^ 2 / 2 * vasicekBondV κ (𝕋 : ℝ) := by + rw [intervalIntegral.integral_const_mul (r := (σ ^ 2 / (2 * κ ^ 2))) + (f := fun s : ℝ ↦ (1 - Real.exp (-(κ * s))) ^ 2), + ← calibVar_key κ hκ 𝕋, ← var_eq_interval κ hκ 𝕋] + field_simp + +/-- **The calibrated integrated mean**: `∫₀ᵀ α(s) ds = ∫₀ᵀ f(0,s) ds + +(σ²/2)·V(T)` — the forward-discount integral plus half the integrated-rate +variance. This is the identity the repricing exactness lives on: the convexity +correction in the mean exactly offsets the `σ²V/2` in the Gaussian moment. -/ +theorem calibIntegratedMean (f0 : ℝ → ℝ) (hf0 : ContDiff ℝ 1 f0) (κ σ : ℝ) + (hκ : 0 < κ) (𝕋 : ℝ≥0) : + integratedMean (theta f0 κ σ) κ (f0 0) (𝕋 : ℝ) + = (∫ s in (0 : ℝ)..(𝕋 : ℝ), f0 s) + σ ^ 2 / 2 * vasicekBondV κ (𝕋 : ℝ) := by + have hfa : IntervalIntegrable f0 volume (0 : ℝ) (𝕋 : ℝ) := + hf0.continuous.intervalIntegrable _ _ + have hgb : IntervalIntegrable (fun s : ℝ ↦ (σ ^ 2 / (2 * κ ^ 2)) + * (1 - Real.exp (-(κ * s))) ^ 2) volume (0 : ℝ) (𝕋 : ℝ) := + (by fun_prop : Continuous fun s : ℝ ↦ (σ ^ 2 / (2 * κ ^ 2)) + * (1 - Real.exp (-(κ * s))) ^ 2).intervalIntegrable _ _ + unfold integratedMean + rw [intervalIntegral.integral_congr + (show EqOn (fun s : ℝ ↦ deterministic (theta f0 κ σ) κ (f0 0) s) + (fun s : ℝ ↦ f0 s + (σ ^ 2 / (2 * κ ^ 2)) * (1 - Real.exp (-(κ * s))) ^ 2) + (Set.uIcc (0 : ℝ) (𝕋 : ℝ)) from fun s _ ↦ calibMean f0 hf0 κ σ hκ s), + intervalIntegral.integral_add hfa hgb, calibCorrection_integral κ σ hκ.ne' 𝕋] + +/-- **The repricing identity** (the headline): with `θ = theta f0 κ σ` and the short +rate started at `r₀ = f(0,0)` (`f0 ∈ C¹`, `κ > 0`), the HW model's time-0 bond curve +reprices the market curve read off the initial forwards: +`𝔼[exp(−bondRate T)] = exp(−∫₀ᵀ f(0,s) ds) = P^mkt(0,T)`. +Route: `bondPrice_eq` (the exponential-Gaussian moment) + +`calibIntegratedMean` (`∫₀ᵀ α = ∫₀ᵀ f0 + σ²V/2`) — the `σ²V/2` cancels. -/ +theorem reprices_curve (hB : IsPreBrownianReal B μ) (f0 : ℝ → ℝ) + (hf0 : ContDiff ℝ 1 f0) (κ σ : ℝ) (hκ : 0 < κ) (T : ℝ≥0) : + ∫ ω, Real.exp (-(bondRate hB (theta f0 κ σ) κ σ (f0 0) hκ T ω)) ∂μ + = Real.exp (-(∫ s in (0 : ℝ)..(T : ℝ), f0 s)) := by + rw [bondPrice_eq hB (theta f0 κ σ) κ σ (f0 0) hκ T, + calibIntegratedMean f0 hf0 κ σ hκ T] + congr 1 + ring + +end MathFin.HullWhite diff --git a/LeanPool/MathFin/Models/Rates/Immunization.lean b/LeanPool/MathFin/Models/Rates/Immunization.lean new file mode 100644 index 0000000000..df13f14281 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/Immunization.lean @@ -0,0 +1,129 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.ZCB + +/-! +# Bond portfolio immunization under a deterministic short rate + +A portfolio of zero-coupon bonds with face values `w i` and maturities `T i`, +indexed by a finite set `s`: + + `P(r) = ∑_{i ∈ s} w_i · exp(−r · (T_i − t))`, `t` fixed (today). + +The Macaulay-duration-times-value of the portfolio is + + `D_P · P(r) = ∑_{i ∈ s} w_i · (T_i − t) · exp(−r · (T_i − t))`. + +First-order rate sensitivity: `∂P/∂r = −D_P · P`. + +A portfolio is **first-order immunized** against a liability `L(r)` with duration +`D_L` if the duration-weighted asset value matches that of the liability, in +which case `∂(P − L)/∂r = 0` at the current rate. + +## Main definitions + +* `bondPortfolioValue`: the value of a zero-coupon bond portfolio at rate `r`. +* `bondPortfolioDur`: the duration-times-value `D_P · P` of the bond portfolio. + +## Main results + +* `hasDerivAt_bondPortfolioValue_r`: `∂P/∂r = −D_P · P`. +* `bondPortfolio_single_bond_dur`: a single-bond portfolio's duration-value + equals `w · (T − t) · exp(−r·(T − t))`, recovering the ZCB result in + `ZCB.lean`. +* `bondPortfolio_immunization_first_order`: when the duration-weighted asset + and liability values match, the net portfolio's first-order rate sensitivity + is zero. + +## References + +* [Fabozzi, *Fixed Income Mathematics*][FabozziFIM], Ch 5 +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], Ch 4 +* [Redington (1952)][Redington1952] + +## Tags + +bond immunization, duration matching, asset–liability management, zero-coupon bond portfolio, +interest rate risk, Redington, MSC 91G30, JEL G11, JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- Bond portfolio value at rate `r`. -/ +noncomputable def bondPortfolioValue + {ι : Type*} (s : Finset ι) (w T : ι → ℝ) (t r : ℝ) : ℝ := + ∑ i ∈ s, w i * Real.exp (-(r * (T i - t))) + +/-- Duration-times-value `D_P · P` of the bond portfolio. -/ +noncomputable def bondPortfolioDur + {ι : Type*} (s : Finset ι) (w T : ι → ℝ) (t r : ℝ) : ℝ := + ∑ i ∈ s, w i * (T i - t) * Real.exp (-(r * (T i - t))) + +/-- **First-order rate sensitivity**: `∂P/∂r = −D_P · P` (here equivalently +`−bondPortfolioDur`). -/ +lemma hasDerivAt_bondPortfolioValue_r + {ι : Type*} (s : Finset ι) (w T : ι → ℝ) (t r : ℝ) : + HasDerivAt (fun r' ↦ bondPortfolioValue s w T t r') + (-bondPortfolioDur s w T t r) r := by + unfold bondPortfolioValue bondPortfolioDur + have h_each : ∀ i ∈ s, HasDerivAt + (fun r' ↦ w i * Real.exp (-(r' * (T i - t)))) + (-(w i * (T i - t) * Real.exp (-(r * (T i - t))))) r := by + intro i _ + -- each summand's rate-derivative *is* the ZCB duration atom + -- `ZCB.hasDerivAt_zcb_r` (face value `w i`, maturity `T i`), not a fresh chase. + have h := (hasDerivAt_zcb_r t (T i) r).const_mul (w i) + simp only [zcb] at h + convert h using 1; ring + have h_raw := HasDerivAt.fun_sum h_each + rw [Finset.sum_neg_distrib] at h_raw + exact h_raw + +/-- **Single-bond portfolio duration**: matches the ZCB duration `(T − t)`. -/ +lemma bondPortfolio_single_bond_dur + {ι : Type*} (i : ι) (w T : ι → ℝ) (t r : ℝ) : + bondPortfolioDur {i} w T t r = + w i * (T i - t) * Real.exp (-(r * (T i - t))) := by + unfold bondPortfolioDur + simp + +/-- Single-bond portfolio value matches the ZCB price `w · exp(−r(T − t))`. -/ +lemma bondPortfolio_single_bond_value + {ι : Type*} (i : ι) (w T : ι → ℝ) (t r : ℝ) : + bondPortfolioValue {i} w T t r = w i * Real.exp (-(r * (T i - t))) := by + unfold bondPortfolioValue + simp + +/-- **First-order immunization**: if the duration-weighted asset value equals +the duration-weighted liability value, then the net portfolio's first-order +rate sensitivity is zero. -/ +lemma bondPortfolio_immunization_first_order + {ι κ : Type*} + (sA : Finset ι) (wA TA : ι → ℝ) + (sL : Finset κ) (wL TL : κ → ℝ) + (t r : ℝ) + (h_match : bondPortfolioDur sA wA TA t r = + bondPortfolioDur sL wL TL t r) : + HasDerivAt (fun r' ↦ + bondPortfolioValue sA wA TA t r' - + bondPortfolioValue sL wL TL t r') + 0 r := by + have hA := hasDerivAt_bondPortfolioValue_r sA wA TA t r + have hL := hasDerivAt_bondPortfolioValue_r sL wL TL t r + have h := hA.sub hL + rw [show (0 : ℝ) = -bondPortfolioDur sA wA TA t r - -bondPortfolioDur sL wL TL t r from by + rw [h_match]; ring] + exact h + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/Inflation.lean b/LeanPool/MathFin/Models/Rates/Inflation.lean new file mode 100644 index 0000000000..033d429b0b --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/Inflation.lean @@ -0,0 +1,351 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.ForwardMeasure +public import LeanPool.MathFin.Models.Rates.TimingAdjustment + +/-! +# Inflation is FX: the zero-coupon inflation swap and the YoY convexity + +The Jarrow–Yildirim identification reads the price index `I_t` as an exchange rate +(nominal currency per real good) and the index-linked bond as a bond denominated in +goods. Under that identification the modelling content is one postulate — the +index-linked bond `I_t·Pʳ(t,T)` is a nominal tradable, priced on the real curve — and +everything else in the zero-coupon inflation swap is change-of-numéraire bookkeeping +(`forwardIndex_eq`, `breakeven_eq`: eqs. 17.6/17.7 of the chapter). + +The year-on-year convexity is the quanto correction transplanted to the nominal/real +rate pair: with both rates Gaussian, the expectation of the exponential of the two-rate +deviation is computed by the same ρ-decomposition of a correlated driver into +independent normals that powers `MathFin.quantoForward_of_gaussian` +(`MathFin.Models.BlackScholes.QuantoGrounding`), with the standard-normal MGF +`ProbabilityTheory.integral_exp_mul_stdNormal` (`MathFin.Probability.Brownian.BrownianMartingale`) +applied twice (`yoyRatioExp_gaussian`). +Composing with the Hull–White bond-reconstitution deterministics `Dⁱ = −½Bⁱ²Vⁱ` +collapses the exponent — the real-variance halves cancel, the nominal halves double — to +the chapter's eq. (17.10) (`yoyConvexity_eq`), with the naive ratio of forwards carried +as an explicit multiplicative constant. The deterministic `D = −½B²V` is tied to the library's +Hull–White model (`Models/Rates/HullWhiteCalibration`) by `integral_exp_hwD_forwardMeasure`. With +`V = Var(r_S)` the variance of the Hull–White short rate, the reconstitution factor +`exp(D − B(r_S − f(0,S)))` has mean `1` under the calibrated `S`-forward measure +(`MathFin.forwardMeasure` at the Hull–White bank account, `Models/Rates/TimingAdjustment`). + +## Scope + +Out of scope, and not claimed: eq. (17.8)'s conditional identity as a named lemma (the +landed anchor is `MathFin.changeOfNumeraire_setIntegral_eq`); eq. (17.9)'s SDE-level +drift-shift derivation `δ = −ρ_{rI}σ_rσ_I`; the two-correlated-Hull–White dynamics (the +means, variances and covariance of the rate deviations are explicit inputs here); and the +chapter's numeric tables. The Jarrow–Yildirim identification is a hypothesis (`hident`), +never derived. The reconstitution formula itself, `P(S,T)` as a function of `r_S`, is not derived +either: only its normalisation under the `S`-forward measure is. + +## Main definitions + +* `hwD`: the reconstitution deterministic `Dⁱ = −½·Bⁱ²·Vⁱ` of the Hull–White bond reconstitution + formula. + +## Main results + +* `forwardIndex_eq`: under the Jarrow–Yildirim identification `hident` and positive `B_T`, + `𝔼^{Q^{n,T}}[I_T] = I₀ · Pʳ(0,T) / Pⁿ(0,T)` under the nominal `T`-forward measure. +* `breakeven_eq`: for `I₀ > 0`, if a zero-coupon inflation swap is fair under the nominal + `T`-forward measure, then `(1+b)^T = Pʳ(0,T) / Pⁿ(0,T)`. +* `yoyRatioExp_gaussian`: for independent standard normals `Z₁, Z₂`, `Vⁿ, Vʳ ≥ 0` and `ρ² ≤ 1`, + the closed form of `𝔼[exp(Bⁿ·yⁿ − Bʳ·yʳ)]` for the two correlated Gaussian rate deviations. +* `yoyRatioExp_gaussian_cov`: the same closed form with the correlation replaced by a covariance + `Cov = ρ·√(Vⁿ·Vʳ)` given by hypothesis. +* `yoyConvexity_eq`: the year-on-year convexity closed form. The Gaussian expectation of the + reconstituted bond-ratio factor is the naive ratio of forwards times + `exp(Bⁿ·mⁿ − Bʳ·mʳ + Bⁿ²·Vⁿ − Bʳ·Bⁿ·Cov)`. +* `integral_exp_hwD_forwardMeasure`: in the Hull–White model calibrated to a `C¹` forward curve with + `κ > 0`, `𝔼^{Q^S}[exp(hwD b V − b·(r_S − f(0, S)))] = 1` under the `S`-forward measure. + +## References + +* [S. Bagaria, *Notes on Fixed Income Derivative Pricing*][BagariaFIDP], ch. 17 §§17.3–17.4 + ("the chapter" throughout); the Hull–White reconstitution formula is from its ch. 8. +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + §3.3 + +## Tags + +zero-coupon inflation swap, Jarrow–Yildirim, year-on-year inflation, convexity adjustment, +breakeven inflation, index-linked bond, quanto, MSC 91G30, MSC 91G20, JEL E31 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory + +/-! ## The zero-coupon inflation swap (eqs. 17.6/17.7) + +`Qⁿ` is the nominal pricing measure, `B_T` the money-market account at `T` (a strictly positive +random variable), `Pⁿ₀T = Pⁿ(0,T)` and `Pʳ₀T = Pʳ(0,T)` the nominal and real T-bond prices, `I₀` +today's index and `I_T` the terminal index. The **identification hypothesis** `hident` is the +chapter's postulate verbatim: the index-linked bond, paying `I_T` at `T`, is priced on the real +curve, `𝔼^{Qⁿ}[I_T/B_T] = I₀·Pʳ(0,T)`. + +In `forwardIndex_eq` and `breakeven_eq`, the numéraire measure is the nominal T-forward +measure `MathFin.forwardMeasure Qⁿ B_T` (the T-bond numéraire against the money market), whose +normalising constant is the nominal bond price, tied to the bank account by `hPn0T`: +`Pⁿ₀T = 𝔼^{Qⁿ}[1/B_T]`. When `1/B_T` is integrable and `Qⁿ` is a probability measure it is a +probability measure (`MathFin.forwardMeasure_isProbabilityMeasure`). -/ +namespace MathFin.Inflation.ZCSwap + +variable {Ω : Type*} [MeasurableSpace Ω] {Qn : Measure Ω} + +/-- **The forward index (eq. 17.6).** Under the Jarrow–Yildirim identification +(`hident`: the index-linked bond priced on the real curve), the index under the +nominal T-forward measure (the numéraire measure of the T-bond, terminal value `1`, initial +price `Pⁿ₀T = 𝔼^{Qⁿ}[1/B_T]`) is the real-curve/nominal-curve ratio: + + `𝔼^{Q^{n,T}}[I_T] = I₀ · Pʳ(0,T) / Pⁿ(0,T)`. + +The proof is `MathFin.forwardMeasure_price` at `X := I_T`, plus field algebra; no integrability +hypothesis is needed. -/ +theorem forwardIndex_eq (BT : Ω → ℝ) (Pn0T Pr0T I0 : ℝ) (IT : Ω → ℝ) + (hBTpos : ∀ ω, 0 < BT ω) (hBTmeas : Measurable BT) (hPn0T : 0 < Pn0T) + (hP : Pn0T = ∫ ω, 1 / BT ω ∂Qn) (hident : ∫ ω, IT ω / BT ω ∂Qn = I0 * Pr0T) : + ∫ ω, IT ω ∂(MathFin.forwardMeasure Qn BT) = I0 * Pr0T / Pn0T := by + subst hP + rw [eq_div_iff hPn0T.ne', mul_comm, MathFin.forwardMeasure_price IT hBTmeas hBTpos hPn0T, hident] + +/-- **The breakeven inflation rate (eq. 17.7).** A zero-coupon inflation swap pays +`I_T/I₀ − (1+b)^T` at `T`; `b` is quoted as the breakeven. Fairness (`hfair`: under the the nominal +T-forward measure `forwardMeasure Qⁿ B_T` — the fixed leg `I₀(1+b)^T` matches the floating leg +`I_T`) combined with eq. (17.6) — so under the identification `hident` — gives, for `I₀ > 0`, the +curve-only breakeven identity + + `(1+b)^T = Pʳ(0,T) / Pⁿ(0,T)`, + +with `T : ℕ` the swap's maturity in whole years (only the `(1+b)^T` exponent; `B_T`, `I_T` +are simply terminal random variables). The breakeven is a *ratio of bond prices*, not a +physical-measure expectation of inflation — the chapter's central warning. -/ +theorem breakeven_eq (BT : Ω → ℝ) (Pn0T Pr0T I0 b : ℝ) (T : ℕ) (IT : Ω → ℝ) + (hBTpos : ∀ ω, 0 < BT ω) (hBTmeas : Measurable BT) (hPn0T : 0 < Pn0T) (hI0 : 0 < I0) + (hP : Pn0T = ∫ ω, 1 / BT ω ∂Qn) (hident : ∫ ω, IT ω / BT ω ∂Qn = I0 * Pr0T) + (hfair : ∫ ω, IT ω ∂(MathFin.forwardMeasure Qn BT) + = I0 * (1 + b) ^ T) : + (1 + b) ^ T = Pr0T / Pn0T := by + have hf := forwardIndex_eq BT Pn0T Pr0T I0 IT hBTpos hBTmeas hPn0T hP hident + rw [hfair, mul_div_assoc] at hf + exact mul_left_cancel₀ hI0.ne' hf + +end MathFin.Inflation.ZCSwap + +/-! ## The YoY Gaussian core (eq. 17.10's expectation layer) + +With both rates Gaussian, the year-on-year ratio's convexity is an expectation of an +exponential of a normal. `yoyRatioExp_gaussian` computes it: two rate deviations +`yⁿ = mⁿ + √Vⁿ·Z₁` and `yʳ = mʳ + √Vʳ·(ρ·Z₁ + √(1−ρ²)·Z₂)` from independent standard +normals — the ρ-decomposition of the correlated two-rate driver, exactly the shape of +`MathFin.quantoForward_of_gaussian` — with means `mⁿ, mʳ`, variances `Vⁿ, Vʳ`, +correlation `ρ`, and Hull–White factors `Bⁿ, Bʳ` over `[S, T]`. -/ +namespace MathFin.Inflation.Gaussian + +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + +/-- **The two-rate exponential moment (eq. 17.10's Gaussian core).** For independent +standard normals `Z₁, Z₂` and Gaussian rate deviations `yⁿ = mⁿ + √Vⁿ·Z₁` and +`yʳ = mʳ + √Vʳ·(ρ·Z₁ + √(1−ρ²)·Z₂)`, with `Vⁿ, Vʳ ≥ 0` and `ρ² ≤ 1` (their covariance is +`ρ·√(Vⁿ·Vʳ)`, an elementary fact not stated in Lean), + + `𝔼[exp(Bⁿ·yⁿ − Bʳ·yʳ)] = exp(Bⁿ·mⁿ − Bʳ·mʳ + ½(Bⁿ²Vⁿ + Bʳ²Vʳ − 2·Bⁿ·Bʳ·ρ·√(VⁿVʳ)))`. + +The proof is the `quantoForward_of_gaussian` pattern: pointwise +factorization into `exp(const)·exp(a·Z₁)·exp(b·Z₂)` with `a = Bⁿ√Vⁿ − Bʳρ√Vʳ` and +`b = −Bʳ√(1−ρ²)√Vʳ`, independence factorization of the integral, and two applications +of the 1-D Gaussian MGF; the cross term `−2BⁿBʳρ√(VⁿVʳ)` is the `a²` algebra. -/ +theorem yoyRatioExp_gaussian (mn mr Vn Vr ρ Bn Br : ℝ) + (hVn : 0 ≤ Vn) (hVr : 0 ≤ Vr) (hρ : ρ ^ 2 ≤ 1) + {Z1 Z2 : Ω → ℝ} + (hZ1 : HasLaw Z1 (gaussianReal 0 1) μ) (hZ2 : HasLaw Z2 (gaussianReal 0 1) μ) + (hindep : IndepFun Z1 Z2 μ) : + ∫ ω, Real.exp (Bn * (mn + Real.sqrt Vn * Z1 ω) + - Br * (mr + Real.sqrt Vr * (ρ * Z1 ω + Real.sqrt (1 - ρ ^ 2) * Z2 ω))) ∂μ + = Real.exp (Bn * mn - Br * mr + + (Bn ^ 2 * Vn + Br ^ 2 * Vr - 2 * Bn * Br * ρ * Real.sqrt (Vn * Vr)) / 2) := by + have h1r2 : (0 : ℝ) ≤ 1 - ρ ^ 2 := by linarith + set E : ℝ := Bn * mn - Br * mr + set a : ℝ := Bn * Real.sqrt Vn - Br * ρ * Real.sqrt Vr with ha + set b : ℝ := -(Br * Real.sqrt (1 - ρ ^ 2)) * Real.sqrt Vr with hb + -- Pointwise: the integrand is the constant `exp E` times the two single-driver exponentials. + have hpt : (fun ω ↦ Real.exp (Bn * (mn + Real.sqrt Vn * Z1 ω) + - Br * (mr + Real.sqrt Vr * (ρ * Z1 ω + Real.sqrt (1 - ρ ^ 2) * Z2 ω)))) + = fun ω ↦ Real.exp E * (Real.exp (a * Z1 ω) * Real.exp (b * Z2 ω)) := by + funext ω + rw [← Real.exp_add, ← Real.exp_add] + congr 1 + simp only [E, a, b] + ring + -- Independence factorization of the two single-driver exponentials. + have hindep_exp : IndepFun (fun ω ↦ Real.exp (a * Z1 ω)) (fun ω ↦ Real.exp (b * Z2 ω)) μ := + hindep.exp_mul a b + have hprod : ∫ ω, Real.exp (a * Z1 ω) * Real.exp (b * Z2 ω) ∂μ + = Real.exp (a ^ 2 / 2) * Real.exp (b ^ 2 / 2) := by + rw [← integral_exp_mul_stdNormal hZ1 a, ← integral_exp_mul_stdNormal hZ2 b] + exact hindep_exp.integral_mul_eq_mul_integral + (by have := hZ1.aemeasurable; fun_prop) (by have := hZ2.aemeasurable; fun_prop) + rw [hpt, integral_const_mul, hprod, ← Real.exp_add, ← Real.exp_add] + -- The `a²` algebra: the cross term `−2·Bⁿ·Bʳ·ρ·√(VⁿVʳ)` emerges from `(Bⁿ√Vⁿ − Bʳρ√Vʳ)²`. + have hcross : Bn * Real.sqrt Vn * (Br * ρ * Real.sqrt Vr) + = Bn * Br * ρ * Real.sqrt (Vn * Vr) := by + rw [show Bn * Real.sqrt Vn * (Br * ρ * Real.sqrt Vr) + = (Bn * ρ * Br) * (Real.sqrt Vn * Real.sqrt Vr) from by ring, + ← Real.sqrt_mul hVn Vr] + ring + have ha2 : a ^ 2 = Bn ^ 2 * Vn + Br ^ 2 * ρ ^ 2 * Vr + - 2 * (Bn * Real.sqrt Vn * (Br * ρ * Real.sqrt Vr)) := by + have h1 : (Bn * Real.sqrt Vn) ^ 2 = Bn ^ 2 * Vn := by + rw [mul_pow, Real.sq_sqrt hVn] + have h2 : (Br * ρ * Real.sqrt Vr) ^ 2 = Br ^ 2 * ρ ^ 2 * Vr := by + rw [mul_pow, mul_pow, Real.sq_sqrt hVr] + rw [ha, sub_sq, h1, h2] + ring + have hb2 : b ^ 2 = Br ^ 2 * (1 - ρ ^ 2) * Vr := by + have h1 : (Br * Real.sqrt (1 - ρ ^ 2)) ^ 2 = Br ^ 2 * (1 - ρ ^ 2) := by + rw [mul_pow, Real.sq_sqrt h1r2] + have h2 : (Real.sqrt Vr) ^ 2 = Vr := Real.sq_sqrt hVr + rw [hb, show (-(Br * Real.sqrt (1 - ρ ^ 2)) * Real.sqrt Vr) ^ 2 + = (Br * Real.sqrt (1 - ρ ^ 2)) ^ 2 * (Real.sqrt Vr) ^ 2 from by ring, + h1, h2] + have hsum : E + (a ^ 2 / 2 + b ^ 2 / 2) + = E + (Bn ^ 2 * Vn + Br ^ 2 * Vr - 2 * Bn * Br * ρ * Real.sqrt (Vn * Vr)) / 2 := by + rw [ha2, hb2, hcross] + ring + rw [hsum] + +/-- **Covariance form of the two-rate exponential moment.** The same conclusion with the +correlation slot replaced by `Cov`, fixed by hypothesis `hCov : Cov = ρ·√(Vⁿ·Vʳ)` (the +covariance of the two rate deviations; that identification is not a Lean statement), the +form in which eq. 17.10 is stated in the chapter. -/ +theorem yoyRatioExp_gaussian_cov (mn mr Vn Vr ρ Bn Br Cov : ℝ) + (hVn : 0 ≤ Vn) (hVr : 0 ≤ Vr) (hρ : ρ ^ 2 ≤ 1) (hCov : Cov = ρ * Real.sqrt (Vn * Vr)) + {Z1 Z2 : Ω → ℝ} + (hZ1 : HasLaw Z1 (gaussianReal 0 1) μ) (hZ2 : HasLaw Z2 (gaussianReal 0 1) μ) + (hindep : IndepFun Z1 Z2 μ) : + ∫ ω, Real.exp (Bn * (mn + Real.sqrt Vn * Z1 ω) + - Br * (mr + Real.sqrt Vr * (ρ * Z1 ω + Real.sqrt (1 - ρ ^ 2) * Z2 ω))) ∂μ + = Real.exp (Bn * mn - Br * mr + + (Bn ^ 2 * Vn + Br ^ 2 * Vr - 2 * Bn * Br * Cov) / 2) := by + rw [hCov, yoyRatioExp_gaussian mn mr Vn Vr ρ Bn Br hVn hVr hρ hZ1 hZ2 hindep] + congr 1 + ring + +end MathFin.Inflation.Gaussian + +/-! ## The YoY convexity closed form (eq. 17.10) + +The Hull–White bond-reconstitution formula (chapter 8, quoted at p. 295) expresses the +real/nominal bond-price ratio `Pʳ(S,T)/Pⁿ(S,T)` as the naive ratio of forwards +`Pʳ(0,T)·Pⁿ(0,S)/(Pʳ(0,S)·Pⁿ(0,T))` times the stochastic factor +`e^{Dʳ−Dⁿ}·e^{−Bʳyʳ+Bⁿyⁿ}`, with deterministic parts `Dⁱ = −½Bⁱ²Vⁱ`. Composing +`yoyRatioExp_gaussian_cov` with those deterministics collapses the exponent — the +real-variance halves cancel, the nominal halves double — to the chapter's eq. (17.10). +The reconstitution formula is taken as the integrand of `yoyConvexity_eq`, not derived. What +is derived from the library's Hull–White model is the role of `Dⁱ` as the normaliser of the +reconstitution factor under the calibrated `S`-forward measure +(`integral_exp_hwD_forwardMeasure`). -/ +namespace MathFin.Inflation.Convexity + +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + +/-- **The reconstitution deterministic** `Dⁱ = −½·Bⁱ²·Vⁱ` of the Hull–White bond +reconstitution formula: the deterministic part of bond `i`'s [S,T]-factor, with `Bⁱ` +the Hull–White factor and `Vⁱ` the integrated variance. That `Dʳ − Dⁿ = (Bⁿ²Vⁿ − Bʳ²Vʳ)/2` +exactly cancels the real variance's half and doubles the nominal variance's half in +`yoyRatioExp_gaussian_cov`'s exponent is the collapse mechanism of `yoyConvexity_eq`. -/ +noncomputable def hwD (B V : ℝ) : ℝ := -(B ^ 2 * V) / 2 + +/-- **The year-on-year convexity closed form (eq. 17.10, exact chapter shape).** With +the reconstituted bond-ratio factor — the naive ratio of forwards +`Pʳ₀T·Pⁿ₀S/(Pʳ₀S·Pⁿ₀T)` times `e^{Dʳ−Dⁿ−Bʳyʳ+Bⁿyⁿ}` with `Dⁱ = −½Bⁱ²Vⁱ` (the `hwD` +below) — the Gaussian expectation collapses to the naive ratio times the correction + + `C = exp(Bⁿ·mⁿ − Bʳ·mʳ + Bⁿ²·Vⁿ − Bʳ·Bⁿ·Cov)`, + +the chapter's eq. (17.10) verbatim, with `Cov = ρ·√(VⁿVʳ)` (hypothesis `hCov`) the +covariance of the two rate deviations. The exponent's composition is pure algebra on +`yoyRatioExp_gaussian_cov`: `(Dʳ−Dⁿ) = (Bⁿ²Vⁿ − Bʳ²Vʳ)/2` cancels the *real* +variance's half exactly and doubles the *nominal* variance's half. The means `mⁿ, mʳ`, +variances and `Cov` are inputs: where they come from (two correlated Hull–White fits, the +quanto parent `−ρ_{rI}σ_rσ_I` and the forward-measure parent `−ρ_{nr}σ_nσ_rBⁿ` inside +them) is chapter-sourced interpretation, not proved here. The exponent is affine in `mʳ` +with slope `−Bʳ`, so a quanto shift `Δ` of the real-rate mean moves it by exactly `−Bʳ·Δ` +(the chapter reads `Δ = 0` off `ρ_{rI} = 0`; that link is not modelled). -/ +theorem yoyConvexity_eq (mn mr Vn Vr ρ Bn Br Pn0T Pn0S Pr0T Pr0S Cov : ℝ) + (hVn : 0 ≤ Vn) (hVr : 0 ≤ Vr) (hρ : ρ ^ 2 ≤ 1) (hCov : Cov = ρ * Real.sqrt (Vn * Vr)) + {Z1 Z2 : Ω → ℝ} + (hZ1 : HasLaw Z1 (gaussianReal 0 1) μ) (hZ2 : HasLaw Z2 (gaussianReal 0 1) μ) + (hindep : IndepFun Z1 Z2 μ) : + ∫ ω, (Pr0T * Pn0S / (Pr0S * Pn0T)) * Real.exp (hwD Br Vr - hwD Bn Vn + + (Bn * (mn + Real.sqrt Vn * Z1 ω) + - Br * (mr + Real.sqrt Vr * (ρ * Z1 ω + Real.sqrt (1 - ρ ^ 2) * Z2 ω)))) ∂μ + = (Pr0T * Pn0S / (Pr0S * Pn0T)) + * Real.exp (Bn * mn - Br * mr + Bn ^ 2 * Vn - Br * Bn * Cov) := by + have hkey := Gaussian.yoyRatioExp_gaussian_cov mn mr Vn Vr ρ Bn Br Cov hVn hVr hρ hCov + hZ1 hZ2 hindep + -- Pointwise: the naive ratio times the full factor = (ratio · e^{Dʳ−Dⁿ}) · e^{−Bʳyʳ+Bⁿyⁿ}. + have hpt : (fun ω ↦ (Pr0T * Pn0S / (Pr0S * Pn0T)) * Real.exp (hwD Br Vr - hwD Bn Vn + + (Bn * (mn + Real.sqrt Vn * Z1 ω) + - Br * (mr + Real.sqrt Vr * (ρ * Z1 ω + Real.sqrt (1 - ρ ^ 2) * Z2 ω))))) + = fun ω ↦ ((Pr0T * Pn0S / (Pr0S * Pn0T)) * Real.exp (hwD Br Vr - hwD Bn Vn)) + * Real.exp (Bn * (mn + Real.sqrt Vn * Z1 ω) + - Br * (mr + Real.sqrt Vr * (ρ * Z1 ω + Real.sqrt (1 - ρ ^ 2) * Z2 ω))) := by + funext ω + rw [mul_assoc, ← Real.exp_add] + rw [hpt, integral_const_mul, hkey, mul_assoc, ← Real.exp_add] + -- The `Dⁱ`-collapse: `Dʳ − Dⁿ = (Bⁿ²Vⁿ − Bʳ²Vʳ)/2` cancels the real halves, doubles the nominal. + have hex : hwD Br Vr - hwD Bn Vn + + (Bn * mn - Br * mr + (Bn ^ 2 * Vn + Br ^ 2 * Vr - 2 * Bn * Br * Cov) / 2) + = Bn * mn - Br * mr + Bn ^ 2 * Vn - Br * Bn * Cov := by + simp only [hwD] + ring + rw [hex] + +/-- **The reconstitution deterministic is the forward-measure normaliser.** In the library's +Hull–White model calibrated to a `C¹` forward curve `f0` (`HullWhite.theta`, short rate started +at `f(0,0)`, `κ > 0`), let `V = σ²(1 − e^{−2κS})/(2κ)` be the variance of the short rate `r_S` +(`HullWhite.integratedRate_hasLaw_gaussian`). Then for every factor `b`, under the `S`-forward +measure `Q^S` (`MathFin.forwardMeasure` at the Hull–White bank account), + + `𝔼^{Q^S}[exp(hwD b V − b·(r_S − f(0, S)))] = 1`. + +Under `Q^S` the deviation `r_S − f(0,S)` is `N(0, V)` (`HullWhite.shortRate_hasLaw_forwardMeasure` +and `HullWhite.calibMean`), so `D = −½b²V` cancels its exponential moment. This is the identity +that makes the reconstitution formula `P(S,T) = (P(0,T)/P(0,S))·exp(D − B(S,T)(r_S − f(0,S)))` +consistent with `𝔼^{Q^S}[P(S,T)] = P(0,T)/P(0,S)`. The formula itself is not derived, and the +short rate is the Hull–White Wiener representation (that it solves the SDE is cited, not proved). -/ +theorem integral_exp_hwD_forwardMeasure [IsProbabilityMeasure μ] {B : NNReal → Ω → ℝ} + (hB : IsPreBrownianReal B μ) (f0 : ℝ → ℝ) + (hf0 : ContDiff ℝ 1 f0) (κ σ : ℝ) (hκ : 0 < κ) (S : NNReal) (b : ℝ) : + ∫ ω, Real.exp (hwD b (vasicekSDEVariance σ κ S) + - b * (HullWhite.integratedRate hB (HullWhite.theta f0 κ σ) κ σ (f0 0) hκ S ω - f0 S)) + ∂forwardMeasure μ (fun ω ↦ Real.exp + (HullWhite.bondRate hB (HullWhite.theta f0 κ σ) κ σ (f0 0) hκ S ω)) = 1 := by + have hlaw := gaussianReal_sub_const + (HullWhite.shortRate_hasLaw_forwardMeasure hB (HullWhite.theta f0 κ σ) κ σ (f0 0) hκ S) (f0 S) + have hm := mgf_gaussianReal hlaw (-b) + simp only [mgf] at hm + have hfac (ω : Ω) : Real.exp (hwD b (vasicekSDEVariance σ κ S) + - b * (HullWhite.integratedRate hB (HullWhite.theta f0 κ σ) κ σ (f0 0) hκ S ω - f0 S)) + = Real.exp (hwD b (vasicekSDEVariance σ κ S)) + * Real.exp (-b * (HullWhite.integratedRate hB (HullWhite.theta f0 κ σ) κ σ (f0 0) hκ S ω + - f0 S)) := by + rw [← Real.exp_add] + congr 1 + ring + simp_rw [hfac] + rw [integral_const_mul, hm, ← Real.exp_add, Real.exp_eq_one_iff, + Real.coe_toNNReal _ (vasicekSDEVariance_nonneg σ hκ S.coe_nonneg), + HullWhite.calibMean f0 hf0 κ σ hκ S, hwD, vasicekBondB] + ring + +end MathFin.Inflation.Convexity diff --git a/LeanPool/MathFin/Models/Rates/InterestRateSwap.lean b/LeanPool/MathFin/Models/Rates/InterestRateSwap.lean new file mode 100644 index 0000000000..4580dc23e3 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/InterestRateSwap.lean @@ -0,0 +1,92 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.ZCB + +-- pointers: MathFin/Models/Rates/ZCB.lean +-- main-module: MathFin/Models/Rates/InterestRateSwap.lean +-- benchmark: benchmarks/mathematical_finance.json +-- benchmark-id: mf-fixedincome-swap +-- source-issue: 66 +-- new-defs: annuity, payerSwapValue, parSwapRate + +/-! +# Vanilla interest-rate swap + +The annuity, the payer-swap value, the par swap +rate, and the par identity — the swap is worth zero iff the fixed rate is the +par rate. The identity is pure annuity algebra, proved for any nonzero annuity +and instantiated on the `zcb` curve, where positivity of the discount factors +is a theorem (`zcb_pos`), not an assumption. The annuity here is the numéraire +`A` consumed by `blackPayerSwaption` in `MathFin/Models/Forwards/Black76.lean`. + +## Main definitions + +* `annuity`: the fixed-leg PV01 `A = δ · ∑ i ∈ s, P i` of a payment schedule `s` with daycount + fraction `δ`. +* `payerSwapValue`: the payer-swap value, the floating leg `P₀ − Pₙ` minus the fixed leg `K · A`. +* `parSwapRate`: the par swap rate `S = (P₀ − Pₙ) / A`. + +## Main results + +* `annuity_pos`: the annuity of a nonempty schedule with positive daycount and positive discount + factors is positive. +* `payerSwapValue_eq_zero_iff`: for a nonzero annuity `A`, the payer swap is worth zero iff + `K = parSwapRate P0 Pn A`. +* `payerSwapValue_zcb_eq_zero_iff`: the same par identity on the `zcb` curve, for `δ > 0` and a + nonempty schedule. + +## Tags + +interest rate swap, par swap rate, payer swap, annuity factor, swap valuation, fixed leg, MSC 91G30, +JEL G13 +-/ + + +@[expose] public section + +namespace MathFin + +/-- Annuity (fixed-leg PV01) of a payment schedule `s` with daycount fraction +`δ` and discount factors `P`: `A = δ · ∑ i ∈ s, P i`. -/ +def annuity {ι : Type*} (δ : ℝ) (P : ι → ℝ) (s : Finset ι) : ℝ := δ * ∑ i ∈ s, P i + +/-- Payer-swap value over given discount factors: the floating leg `P₀ − Pₙ` +minus the fixed leg `K · A`, `A` the annuity of the fixed schedule. -/ +def payerSwapValue (P0 Pn K A : ℝ) : ℝ := P0 - Pn - K * A + +/-- Par swap rate: the fixed rate that makes the payer swap worth zero, +`S = (P₀ − Pₙ) / A`. -/ +noncomputable def parSwapRate (P0 Pn A : ℝ) : ℝ := (P0 - Pn) / A + +/-- The annuity of a nonempty schedule with positive daycount and positive +discount factors is positive. -/ +theorem annuity_pos {ι : Type*} {δ : ℝ} {P : ι → ℝ} {s : Finset ι} (hδ : 0 < δ) + (hP : ∀ i ∈ s, 0 < P i) (hs : s.Nonempty) : 0 < annuity δ P s := + mul_pos hδ (Finset.sum_pos hP hs) + +/-- **The par identity**: a payer swap is worth zero iff its fixed rate is the +par swap rate — pure algebra, valid for any nonzero annuity. -/ +theorem payerSwapValue_eq_zero_iff (P0 Pn K : ℝ) {A : ℝ} (hA : A ≠ 0) : + payerSwapValue P0 Pn K A = 0 ↔ K = parSwapRate P0 Pn A := by + change P0 - Pn - K * A = 0 ↔ K = (P0 - Pn) / A + rw [sub_eq_zero, eq_div_iff hA] + exact eq_comm + +/-- The par identity on the `zcb` curve: a positive daycount and a nonempty +payment schedule make the annuity positive (`zcb` is a positive exponential), +so no positivity hypotheses are needed. -/ +theorem payerSwapValue_zcb_eq_zero_iff {ι : Type*} (r δ K T0 Tn : ℝ) (T : ι → ℝ) + (s : Finset ι) (hδ : 0 < δ) (hs : s.Nonempty) : + payerSwapValue (zcb r 0 T0) (zcb r 0 Tn) K (annuity δ (fun i ↦ zcb r 0 (T i)) s) = 0 ↔ + K = parSwapRate (zcb r 0 T0) (zcb r 0 Tn) (annuity δ (fun i ↦ zcb r 0 (T i)) s) := + payerSwapValue_eq_zero_iff _ _ _ + (annuity_pos hδ (fun i _ ↦ zcb_pos r 0 (T i)) hs).ne' + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/Jamshidian.lean b/LeanPool/MathFin/Models/Rates/Jamshidian.lean new file mode 100644 index 0000000000..bbf85fe16e --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/Jamshidian.lean @@ -0,0 +1,467 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.GSRBond +public import LeanPool.MathFin.Models.Rates.HullWhiteBond +public import LeanPool.MathFin.Models.BlackScholes.Put +public import LeanPool.MathFin.Models.Rates.TimingAdjustment + +/-! +# Jamshidian: the zero-coupon bond put and the caplet in the Gaussian short-rate models + +A put on `P(T₀, T₁)` struck at `k` expiring at `T₀` is worth `P(0, T₀)` times the put's +expectation under the `T₀`-forward measure (`forwardMeasure`, the change of numéraire +`forwardMeasure_price`). In a Gaussian short-rate model the bond is +`P(T₀, T₁) = a·exp(−β r_{T₀})` (`bondPrice_hullWhite`), and `r_{T₀}` stays Gaussian under the +`T₀`-forward measure, its mean shifted by `−Cov(r_{T₀}, ∫₀^{T₀} r)` +(`HullWhite.shortRate_hasLaw_forwardMeasure`; for the two-piece GSR, +`gsrShortRate_hasLaw_forwardMeasure`, both instances of `hasLaw_forwardMeasure_wienerIntegralLp`). +So the bond is lognormal there, and the put is a Black put (`bs_put_formula`) on it: + + `put = k·P(0, T₀)·Φ(−d₂) − P(0, T₁)·Φ(−d₁)`, `d₁ = (ln(F/k) + s²/2)/s`, `d₂ = d₁ − s`, + +with forward price `F = P(0, T₁)/P(0, T₀)` and `s = B(T₁ − T₀)·sd(r_{T₀})`, the standard +deviation of `ln P(T₀, T₁)`. The forward price needs no computation with the affine coefficients: +it is the mean of the lognormal under `Q^{T₀}` (`discounted_terminal_eq_S0`) and, by the tower +property (`HasBondPrice.integral_discount_mul`), `𝔼^{T₀}[P(T₀, T₁)] = P(0, T₁)/P(0, T₀)`. + +* `HasBondPrice.integral_bond_forward` — the forward price of the bond. +* `HasBondPrice.value_bondPut_gaussian` — the put, for a bond that is an exponential of a + Gaussian under the `T₀`-forward measure. +* `value_bondPut_wiener` — the plumbing once: for an integrated short rate in Wiener + representation `R T = M T + c T·∫₀ᵀ g_T dB`, the discount factor is integrable, the forward + measure is a probability measure, and the put is the Gaussian one above. +* `value_bondPut_hullWhite`, `value_bondPut_vasicek` — the Hull–White put, with + `s = B(T₁ − T₀)·sd(r_{T₀})`, and the Vasicek put as the constant forcing (`bondRate_const`). +* `value_bondPut_gsr` — the put in the two-piece GSR model: `r_{T₀}` is Gaussian under `Q^{T₀}` + with the variance `gsrShortRateV` of `Models/Rates/GSRBondPriceAt.lean`, and the coefficient + `A(T₀, T₁)` of the bond, which depends on `T₀` and `T₁` separately, never enters. +* `value_bondPut_gsr_self` — at one volatility `σ₁ = σ₂` the GSR put is the Vasicek put + (`zeroCurve_gsr_self`, `gsrShortRateV_self`). +* `value_caplet_hullWhite`, `value_caplet_vasicek`, `value_caplet_gsr` — the caplet of + `value_caplet_eq_bondPut`, `(1 + δK)` such puts at strike `1/(1 + δK)`. + +## What this is, and is not + +The measure `μ` is read as the pricing measure and the Wiener representation of the short rate is +the model (as in `bondPrice_vasicek`). The caplet is *not* priced as a Black-76 caplet in these +models: the forward LIBOR `L = (1/P − 1)/δ` of a lognormal bond is a shifted lognormal (a remark, +not a theorem here), so the hypothesis of `value_caplet_black76` is not claimed and not used; +the caplet is `(1 + δK)` bond puts, which are Black puts on the lognormal bond. + +## Main results + +* `HasBondPrice.integral_bond_forward`: under the `T₀`-forward measure, the expectation of the + bond `X b T₀` is `zeroCurve Q D T₁ / zeroCurve Q D T₀`. +* `HasBondPrice.value_bondPut_gaussian`: if the bond is `a * exp (-(β r))` almost surely under + the `T₀`-forward measure, with `r` Gaussian of variance `v > 0` there, the put on the bond + struck at `k` is worth `P(0, T₀) k Φ(-d₂) - P(0, T₁) Φ(-d₁)`, with `d₁`, `d₂` the Black-Scholes + quantities at forward `P(0, T₁)/P(0, T₀)`, rate `0` and volatility `β√v`. +* `value_bondPut_wiener`: the same price for an integrated short rate in Wiener + representation `R T = M T + c T * ∫₀ᵀ g_T dB`. +* `value_bondPut_hullWhite`, `value_bondPut_vasicek`: the Hull-White and Vasicek bond + puts (`σ ≠ 0`, `0 < T₀ < T₁`), with volatility `vasicekBondB κ (T₁ - T₀)` times the standard + deviation of `r_{T₀}`. +* `value_bondPut_gsr`: the bond put in the two-piece GSR model with volatilities `σ1`, `σ2`. +* `value_bondPut_gsr_self`, `zeroCurve_gsr_self`: at `σ1 = σ2` the GSR zero curve and bond put + are the Vasicek ones. +* `value_caplet_hullWhite`, `value_caplet_vasicek`, `value_caplet_gsr`: in a + `BondModel` for each of these models, the caplet is worth `1 + δK` bond puts struck at + `1/(1 + δK)`, each priced as above. The caplet is not priced as a Black-76 caplet. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + section 3.2; section 3.3 +* [Jamshidian, *An exact bond option formula*][Jamshidian1989] +* [The QuantLib contributors, *QuantLib*][QuantLib], Gsr model + +## Tags + +Jamshidian decomposition, bond put, caplet pricing, Hull–White model, Vasicek model, +forward measure, Gaussian short rate, MSC 91G30, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +namespace MathFin.Contracts + +variable {ι Ω : Type*} {mΩ : MeasurableSpace Ω} + +section Abstract + +variable {Q : Measure Ω} [IsProbabilityMeasure Q] {𝓕 : Filtration ℝ≥0 mΩ} {D : ℝ≥0 → Ω → ℝ} + {X : ι → ℝ≥0 → Ω → ℝ} {b : ι} {T₀ T₁ : ℝ≥0} + +/-- **The forward price of the bond**: under the `T₀`-forward measure (`forwardMeasure` of the bank +account `1/D T₀`), `𝔼^{T₀}[P(T₀, T₁)] = P(0, T₁)/P(0, T₀)`. The tower property turns `D T₁` into +`D T₀ · P(T₀, T₁)`, and the change of numéraire divides by `P(0, T₀)`. -/ +theorem HasBondPrice.integral_bond_forward (h : HasBondPrice Q 𝓕 D X b T₀ T₁) + (hDm : Measurable (D T₀)) (hD0 : Integrable (D T₀) Q) : + ∫ ω, X b T₀ ω ∂(forwardMeasure Q fun ω ↦ 1 / D T₀ ω) + = zeroCurve Q D T₁ / zeroCurve Q D T₀ := by + obtain ⟨hpos, key⟩ := integral_discount_mul_eq_forward h.D_pos hDm hD0 (X b T₀) + rw [h.integral_discount] at key + have hz : zeroCurve Q D T₀ = ∫ ω, D T₀ ω ∂Q := rfl + rw [hz, eq_div_iff hpos.ne', mul_comm] + exact key + +/-- **A put on the bond is a Black put, when the bond is lognormal at the forward measure.** Let +`Q'` be the `T₀`-forward measure and suppose, under it, `r` is Gaussian `N(m, v)` and the bond +price is `P(T₀, T₁) = a·exp(−β r)` with `β > 0`: a lognormal with log-standard-deviation +`s = β√v`. Then the put paying `(k − P(T₀, T₁))⁺` at `T₀` is worth + + `P(0, T₀)·k·Φ(−d₂) − P(0, T₁)·Φ(−d₁)`, `d₁ = bsd1 F k 0 s 1`, `d₂ = bsd2 F k 0 s 1`, + +with `F = P(0, T₁)/P(0, T₀)` the forward price of the bond. The mean of the lognormal is `F` +(`HasBondPrice.integral_bond_forward`), so the constants `a`, `m` enter only through `s`. -/ +theorem HasBondPrice.value_bondPut_gaussian (h : HasBondPrice Q 𝓕 D X b T₀ T₁) + {Q' : Measure Ω} [IsProbabilityMeasure Q'] (hQ' : Q' = forwardMeasure Q fun ω ↦ 1 / D T₀ ω) + (hDm : Measurable (D T₀)) (hD0 : Integrable (D T₀) Q) {r : Ω → ℝ} {m : ℝ} {v : ℝ≥0} + (hv : 0 < v) (hr : HasLaw r (gaussianReal m v) Q') {a β k : ℝ} (ha : 0 < a) (hβ : 0 < β) + (hk : 0 < k) (hP : X b T₀ =ᵐ[Q'] fun ω ↦ a * Real.exp (-(β * r ω))) : + (bondPut b T₀ k).value Q D X + = zeroCurve Q D T₀ * k * Phi (-bsd2 (zeroCurve Q D T₁ / zeroCurve Q D T₀) k 0 + (β * Real.sqrt v) 1) + - zeroCurve Q D T₁ * Phi (-bsd1 (zeroCurve Q D T₁ / zeroCurve Q D T₀) k 0 + (β * Real.sqrt v) 1) := by + subst hQ' + set sd : ℝ := Real.sqrt v with hsd_def + have hsd : 0 < sd := Real.sqrt_pos.2 (by exact_mod_cast hv) + have hsd2 : sd ^ 2 = v := Real.sq_sqrt v.coe_nonneg + set F₀ : ℝ := a * Real.exp (-(β * m) + β ^ 2 * v / 2) with hF₀ + set Z : Ω → ℝ := fun ω ↦ (-1 * r ω - (-1 * m)) / sd with hZdef + have hZ : HasLaw Z (gaussianReal 0 1) (forwardMeasure Q fun ω ↦ 1 / D T₀ ω) := + hasLaw_sub_div_of_gaussianReal (gaussianReal_const_mul hr (-1)) hsd + (by rw [NNReal.coe_mul, NNReal.coe_mk, hsd2]; ring) + have hZmain : BSCallHyp (forwardMeasure Q fun ω ↦ 1 / D T₀ ω) F₀ k 0 (β * sd) 1 Z := + ⟨mul_pos ha (Real.exp_pos _), hk, mul_pos hβ hsd, one_pos, hZ⟩ + have hL : X b T₀ =ᵐ[forwardMeasure Q fun ω ↦ 1 / D T₀ ω] + fun ω ↦ bsTerminal F₀ 0 (β * sd) 1 (Z ω) := hP.mono fun ω hω ↦ by + have hsZ : β * sd * 1 * Z ω = β * (m - r ω) := by + simp only [hZdef]; field_simp; ring + have hs2 : (0 - (β * sd) ^ 2 / 2) * 1 = -(β ^ 2 * v / 2) := by rw [mul_pow, hsd2]; ring + beta_reduce at hω ⊢ + rw [hω] + unfold bsTerminal + rw [Real.sqrt_one, hsZ, hs2, hF₀, mul_assoc, ← Real.exp_add] + congr 2 + ring + obtain ⟨hpos, key⟩ := integral_discount_mul_eq_forward h.D_pos hDm hD0 + (fun ω ↦ max (k - X b T₀ ω) 0) + have hF : F₀ = zeroCurve Q D T₁ / zeroCurve Q D T₀ := by + rw [← h.integral_bond_forward hDm hD0, integral_congr_ae hL] + simpa using (discounted_terminal_eq_S0 hZmain).symm + have hput : ∫ ω, max (k - X b T₀ ω) 0 ∂(forwardMeasure Q fun ω ↦ 1 / D T₀ ω) + = k * Phi (-bsd2 F₀ k 0 (β * sd) 1) - F₀ * Phi (-bsd1 F₀ k 0 (β * sd) 1) := by + rw [integral_congr_ae (g := fun ω ↦ max (k - bsTerminal F₀ 0 (β * sd) 1 (Z ω)) 0) + (hL.mono fun ω hω ↦ by simp only [hω])] + simpa using bs_put_formula hZmain + simp only [bondPut, Contract.value_pay, Payoff.eval, scenarioAt] + rw [← key, hput, ← hF] + have hpos' : 0 < zeroCurve Q D T₀ := hpos + have h1 : zeroCurve Q D T₁ = zeroCurve Q D T₀ * F₀ := by + rw [hF]; field_simp [hpos'.ne'] + rw [h1] + simp only [zeroCurve] + ring + +end Abstract + +/-! ### The Gaussian short-rate models -/ + +section GaussianShortRate + +variable {μ : Measure Ω} [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} {X : ι → ℝ≥0 → Ω → ℝ} {b : ι} + {T₀ T₁ : ℝ≥0} + +/-- **The bond put for an integrated short rate in Wiener representation.** Let +`R T = M T + c T·∫₀ᵀ g_T dB` for every `T`, so the discount factor `shortRateDiscount R` is +`exp(−R)`. Then the discount factor is integrable and the `T₀`-forward measure, of density +`exp(R T₀)`, is a probability measure; if `r` is Gaussian `N(m, v)` under it and the bond +`P(T₀, T₁)` is a.e. `a·exp(−β r)`, the put is the Black put of +`HasBondPrice.value_bondPut_gaussian`. The Hull–White and GSR puts are its instances. -/ +theorem value_bondPut_wiener (hB : IsPreBrownianReal B μ) (hBm : ∀ s, Measurable (B s)) + {R : ℝ≥0 → Ω → ℝ} {M c : ℝ≥0 → ℝ} + {g : ∀ T : ℝ≥0, Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ)))} + (hR : ∀ T ω, R T ω = M T + c T * WienerIntegralL2.wienerIntegralLp B hB T (g T) ω) + (hb : X b T₀ =ᵐ[μ] bondPrice μ (Filtration.natural B fun s ↦ (hBm s).stronglyMeasurable) + (shortRateDiscount R) T₀ T₁) {r : Ω → ℝ} {m v : ℝ} (hv : 0 < v) + (hr : HasLaw r (gaussianReal m v.toNNReal) (forwardMeasure μ fun ω ↦ Real.exp (R T₀ ω))) + {a β k : ℝ} (ha : 0 < a) (hβ : 0 < β) (hk : 0 < k) + (hP : bondPrice μ (Filtration.natural B fun s ↦ (hBm s).stronglyMeasurable) + (shortRateDiscount R) T₀ T₁ =ᵐ[μ] fun ω ↦ a * Real.exp (-(β * r ω))) : + (bondPut b T₀ k).value μ (shortRateDiscount R) X + = zeroCurve μ (shortRateDiscount R) T₀ * k + * Phi (-bsd2 (zeroCurve μ (shortRateDiscount R) T₁ / zeroCurve μ (shortRateDiscount R) T₀) + k 0 (β * Real.sqrt v) 1) + - zeroCurve μ (shortRateDiscount R) T₁ + * Phi (-bsd1 (zeroCurve μ (shortRateDiscount R) T₁ / zeroCurve μ (shortRateDiscount R) T₀) + k 0 (β * Real.sqrt v) 1) := by + have hRm (T : ℝ≥0) : Measurable (R T) := by + rw [show R T = _ from funext (hR T)] + exact ((Lp.stronglyMeasurable _).measurable.const_mul _).const_add _ + have hDm (T : ℝ≥0) : Measurable (shortRateDiscount R T) := by + unfold shortRateDiscount + exact (hRm T).neg.exp + have hDi (T : ℝ≥0) : Integrable (shortRateDiscount R T) μ := + (integrable_one_div_exp_add_mul_wienerIntegralLp hB T (M T) (c T) (g T)).congr <| + ae_of_all _ fun ω ↦ by simp only [shortRateDiscount, hR, one_div, ← Real.exp_neg] + have hbp : HasBondPrice μ (Filtration.natural B fun s ↦ (hBm s).stronglyMeasurable) + (shortRateDiscount R) X b T₀ T₁ := ⟨fun ω ↦ Real.exp_pos _, hDi T₁, hb⟩ + have hfm : (forwardMeasure μ fun ω ↦ 1 / shortRateDiscount R T₀ ω) + = forwardMeasure μ fun ω ↦ Real.exp (R T₀ ω) := by + congr 1 + funext ω + simp [shortRateDiscount, Real.exp_neg] + have : IsProbabilityMeasure (forwardMeasure μ fun ω ↦ 1 / shortRateDiscount R T₀ ω) := by + rw [hfm] + exact forwardMeasure_isProbabilityMeasure (fun ω ↦ Real.exp_pos _) + ((integrable_one_div_exp_add_mul_wienerIntegralLp hB T₀ (M T₀) (c T₀) (g T₀)).congr + (ae_of_all _ fun ω ↦ by simp only [hR])) + rw [← hfm] at hr + have hac : (forwardMeasure μ fun ω ↦ 1 / shortRateDiscount R T₀ ω) ≪ μ := + withDensity_absolutelyContinuous _ _ + have := hbp.value_bondPut_gaussian rfl (hDm T₀) (hDi T₀) (Real.toNNReal_pos.2 hv) hr ha hβ + hk (hac.ae_le (hb.trans hP)) + rwa [Real.coe_toNNReal _ hv.le] at this + +/-- **The zero-coupon bond put in the Hull–White model** (Jamshidian). For continuous forcing `θ`, +`σ ≠ 0` and `0 < T₀ < T₁`, a put struck at `k` expiring at `T₀` on the bond `P(T₀, T₁)` (an +underlying `b` that is a.e. the conditional expectation `bondPrice` of the discount factor) is worth + + `P(0, T₀)·k·Φ(−d₂) − P(0, T₁)·Φ(−d₁)`, `d₁ = bsd1 F k 0 s 1`, `d₂ = bsd2 F k 0 s 1`, + +with `P(0, T) = zeroCurve` the bond prices of the model (`HullWhite.bondPrice_affine`), +`F = P(0, T₁)/P(0, T₀)` and `s = B(T₁ − T₀)·sd(r_{T₀})`, the standard deviation of +`ln P(T₀, T₁)`: the bond is `a·exp(−B(T₁ − T₀) r_{T₀})` (`bondPrice_hullWhite`) and `r_{T₀}` is +Gaussian under the `T₀`-forward measure with the variance of `HullWhite.integratedRate` +(`HullWhite.shortRate_hasLaw_forwardMeasure`), so `value_bondPut_wiener` prices the put as a +Black put. The measure is read as the pricing measure. -/ +theorem value_bondPut_hullWhite (hB : IsPreBrownianReal B μ) (hBm : ∀ s, Measurable (B s)) + {θ : ℝ → ℝ} (hθ : Continuous θ) (κ σ r₀ : ℝ) (hκ : 0 < κ) (h0 : 0 < T₀) (hT : T₀ < T₁) + (hσ : σ ≠ 0) + (hb : X b T₀ =ᵐ[μ] bondPrice μ (Filtration.natural B fun s ↦ (hBm s).stronglyMeasurable) + (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) T₀ T₁) {k : ℝ} (hk : 0 < k) : + (bondPut b T₀ k).value μ (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) X + = zeroCurve μ (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) T₀ * k + * Phi (-bsd2 (zeroCurve μ (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) T₁ + / zeroCurve μ (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) T₀) k 0 + (vasicekBondB κ ((T₁ - T₀ : ℝ≥0) : ℝ) + * Real.sqrt (vasicekSDEVariance σ κ T₀)) 1) + - zeroCurve μ (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) T₁ + * Phi (-bsd1 (zeroCurve μ (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) T₁ + / zeroCurve μ (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) T₀) k 0 + (vasicekBondB κ ((T₁ - T₀ : ℝ≥0) : ℝ) + * Real.sqrt (vasicekSDEVariance σ κ T₀)) 1) := by + exact value_bondPut_wiener hB hBm (M := fun T ↦ HullWhite.integratedMean θ κ r₀ T) + (c := fun _ ↦ σ) (g := fun T ↦ vasicekIntegratedKernelLp hκ T) (fun _ _ ↦ rfl) hb + (vasicekSDE_variance_pos σ κ T₀ hκ (NNReal.coe_pos.2 h0) hσ) + (HullWhite.shortRate_hasLaw_forwardMeasure hB θ κ σ r₀ hκ T₀) (Real.exp_pos _) + (vasicekBondB_pos hκ (NNReal.coe_pos.2 (tsub_pos_of_lt hT))) hk + (bondPrice_hullWhite hB hBm hθ κ σ r₀ hκ hT.le) + +/-- **The caplet in the Hull–White model.** In a `BondModel` for the Hull–White discount factor, +the caplet paying `δ (L(T₀, T₁) − K)⁺` at `T₁` is worth `(1 + δK)` bond puts struck at +`1/(1 + δK)` (`value_caplet_eq_bondPut`), each priced by `value_bondPut_hullWhite`. The +forward LIBOR is a shifted lognormal here, not a lognormal: this is not +`value_caplet_black76`. -/ +theorem value_caplet_hullWhite (hB : IsPreBrownianReal B μ) (hBm : ∀ s, Measurable (B s)) + {θ : ℝ → ℝ} (hθ : Continuous θ) (κ σ r₀ : ℝ) (hκ : 0 < κ) (h0 : 0 < T₀) (hT : T₀ < T₁) + (hσ : σ ≠ 0) {ℓ : ι} {δ K : ℝ} + (h : BondModel μ (Filtration.natural B fun s ↦ (hBm s).stronglyMeasurable) + (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) X b ℓ T₀ T₁ δ) + (hK : 0 < 1 + δ * K) + (hint : Integrable (fun ω ↦ shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ) T₁ ω + * (δ * max (X ℓ T₀ ω - K) 0)) μ) : + (caplet ℓ T₀ T₁ δ K).value μ (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) X + = (1 + δ * K) * + (zeroCurve μ (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) T₀ + * (1 / (1 + δ * K)) + * Phi (-bsd2 (zeroCurve μ (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) T₁ + / zeroCurve μ (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) T₀) + (1 / (1 + δ * K)) 0 + (vasicekBondB κ ((T₁ - T₀ : ℝ≥0) : ℝ) * Real.sqrt (vasicekSDEVariance σ κ T₀)) 1) + - zeroCurve μ (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) T₁ + * Phi (-bsd1 (zeroCurve μ (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) T₁ + / zeroCurve μ (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) T₀) + (1 / (1 + δ * K)) 0 + (vasicekBondB κ ((T₁ - T₀ : ℝ≥0) : ℝ) * Real.sqrt (vasicekSDEVariance σ κ T₀)) 1)) := by + rw [value_caplet_eq_bondPut h hK hint] + exact congrArg _ (value_bondPut_hullWhite hB hBm hθ κ σ r₀ hκ h0 hT hσ h.bond_eq + (one_div_pos.2 hK)) + +/-- **The zero-coupon bond put in the Vasicek model**: the Hull–White put at the constant forcing +`θ ≡ κθ_v` (`HullWhite.bondRate_const`), for the Vasicek integrated rate. -/ +theorem value_bondPut_vasicek (hB : IsPreBrownianReal B μ) (hBm : ∀ s, Measurable (B s)) + (r₀ θ σ : ℝ) {κ : ℝ} (hκ : 0 < κ) (h0 : 0 < T₀) (hT : T₀ < T₁) (hσ : σ ≠ 0) + (hb : X b T₀ =ᵐ[μ] bondPrice μ (Filtration.natural B fun s ↦ (hBm s).stronglyMeasurable) + (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₀ T₁) {k : ℝ} (hk : 0 < k) : + (bondPut b T₀ k).value μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) X + = zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₀ * k + * Phi (-bsd2 (zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₁ + / zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₀) k 0 + (vasicekBondB κ ((T₁ - T₀ : ℝ≥0) : ℝ) + * Real.sqrt (vasicekSDEVariance σ κ T₀)) 1) + - zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₁ + * Phi (-bsd1 (zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₁ + / zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₀) k 0 + (vasicekBondB κ ((T₁ - T₀ : ℝ≥0) : ℝ) + * Real.sqrt (vasicekSDEVariance σ κ T₀)) 1) := by + have hD : shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ) + = shortRateDiscount (HullWhite.bondRate hB (fun _ ↦ κ * θ) κ σ r₀ hκ) := by + funext T ω + simp only [shortRateDiscount, HullWhite.bondRate_const] + rw [hD] at hb ⊢ + exact value_bondPut_hullWhite hB hBm continuous_const κ σ r₀ hκ h0 hT hσ hb hk + +/-- **The caplet in the Vasicek model**: `(1 + δK)` bond puts at strike `1/(1 + δK)` +(`value_caplet_eq_bondPut`), each `value_bondPut_vasicek`. Not a Black-76 caplet: the +forward LIBOR is a shifted lognormal. -/ +theorem value_caplet_vasicek (hB : IsPreBrownianReal B μ) (hBm : ∀ s, Measurable (B s)) + (r₀ θ σ : ℝ) {κ : ℝ} (hκ : 0 < κ) (h0 : 0 < T₀) (hT : T₀ < T₁) (hσ : σ ≠ 0) {ℓ : ι} + {δ K : ℝ} + (h : BondModel μ (Filtration.natural B fun s ↦ (hBm s).stronglyMeasurable) + (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) X b ℓ T₀ T₁ δ) + (hK : 0 < 1 + δ * K) + (hint : Integrable (fun ω ↦ shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ) T₁ ω + * (δ * max (X ℓ T₀ ω - K) 0)) μ) : + (caplet ℓ T₀ T₁ δ K).value μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) X + = (1 + δ * K) * + (zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₀ + * (1 / (1 + δ * K)) + * Phi (-bsd2 (zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₁ + / zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₀) + (1 / (1 + δ * K)) 0 + (vasicekBondB κ ((T₁ - T₀ : ℝ≥0) : ℝ) * Real.sqrt (vasicekSDEVariance σ κ T₀)) 1) + - zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₁ + * Phi (-bsd1 (zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₁ + / zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₀) + (1 / (1 + δ * K)) 0 + (vasicekBondB κ ((T₁ - T₀ : ℝ≥0) : ℝ) * Real.sqrt (vasicekSDEVariance σ κ T₀)) 1)) := by + rw [value_caplet_eq_bondPut h hK hint] + exact congrArg _ (value_bondPut_vasicek hB hBm r₀ θ σ hκ h0 hT hσ h.bond_eq + (one_div_pos.2 hK)) + +/-- **The zero-coupon bond put in the two-piece GSR model.** With volatility `σ₁` up to the +breakpoint `T*` and `σ₂` after, for `0 < T₀ < T₁`, `T* ≤ T₁` and `σ₁, σ₂ ≠ 0`, a put struck at `k` +expiring at `T₀` on the bond `P(T₀, T₁)` (an underlying `b` that is a.e. the conditional +expectation `bondPrice` of the GSR discount factor) is worth + + `P(0, T₀)·k·Φ(−d₂) − P(0, T₁)·Φ(−d₁)`, `d₁ = bsd1 F k 0 s 1`, `d₂ = bsd2 F k 0 s 1`, + +with `P(0, T) = zeroCurve` the bond prices of the model (`gsrBondPrice_eq`, for `T ≥ T*`), +`F = P(0, T₁)/P(0, T₀)` and `s = B(T₁ − T₀)·sd(r_{T₀})`, the standard deviation of `ln P(T₀, T₁)`: +the bond is `A(T₀, T₁)·exp(−B(T₁ − T₀) r_{T₀})` (`bondPrice_gsr`) and `r_{T₀}` is Gaussian under the +`T₀`-forward measure with variance `gsrShortRateV`, the volatility-weighted +`∫₀^{T₀} σ(u)² e^{−2κ(T₀−u)} du` (`gsrShortRate_hasLaw_forwardMeasure`), so +`value_bondPut_wiener` prices the put as a Black put. The coefficient `A(T₀, T₁)`, which +depends on `T₀` and `T₁` separately, plays no role: only `s` enters. The measure is read as the +pricing measure. -/ +theorem value_bondPut_gsr (hB : IsPreBrownianReal B μ) (hBm : ∀ s, Measurable (B s)) + (r₀ θ σ1 σ2 : ℝ) {κ : ℝ} (hκ : 0 < κ) {Tstar : ℝ≥0} (h0 : 0 < T₀) (hT : T₀ < T₁) + (hTstar : Tstar ≤ T₁) (hσ1 : σ1 ≠ 0) (hσ2 : σ2 ≠ 0) + (hb : X b T₀ =ᵐ[μ] bondPrice μ (Filtration.natural B fun s ↦ (hBm s).stronglyMeasurable) + (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) T₀ T₁) {k : ℝ} (hk : 0 < k) : + (bondPut b T₀ k).value μ (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) X + = zeroCurve μ (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) T₀ * k + * Phi (-bsd2 (zeroCurve μ + (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) T₁ + / zeroCurve μ (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) T₀) k 0 + (vasicekBondB κ ((T₁ : ℝ) - T₀) + * Real.sqrt (gsrShortRateV κ σ1 σ2 (Tstar : ℝ) T₀)) 1) + - zeroCurve μ (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) T₁ + * Phi (-bsd1 (zeroCurve μ + (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) T₁ + / zeroCurve μ (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) T₀) k 0 + (vasicekBondB κ ((T₁ : ℝ) - T₀) + * Real.sqrt (gsrShortRateV κ σ1 σ2 (Tstar : ℝ) T₀)) 1) := by + exact value_bondPut_wiener hB hBm (M := fun T ↦ vasicekIntegratedMean r₀ θ κ T) + (c := fun _ ↦ 1) (g := fun T ↦ gsrKernelLp hκ σ1 σ2 (Tstar : ℝ) T) + (fun _ _ ↦ by simp [gsrIntegratedRate]) hb + (gsrShortRateV_pos hκ hσ1 hσ2 Tstar.coe_nonneg (t := (T₀ : ℝ)) (NNReal.coe_pos.2 h0)) + (gsrShortRate_hasLaw_forwardMeasure hB r₀ θ σ1 σ2 hκ Tstar T₀) (Real.exp_pos _) + (vasicekBondB_pos hκ (sub_pos.2 (NNReal.coe_lt_coe.2 hT))) hk + (bondPrice_gsr hB hBm r₀ θ σ1 σ2 hκ hT.le hTstar) + +/-- **The caplet in the two-piece GSR model**: `(1 + δK)` bond puts struck at `1/(1 + δK)` +(`value_caplet_eq_bondPut`), each priced by `value_bondPut_gsr`. As for Hull–White, the +forward LIBOR is a shifted lognormal here, not a lognormal: this is not +`value_caplet_black76`. -/ +theorem value_caplet_gsr (hB : IsPreBrownianReal B μ) (hBm : ∀ s, Measurable (B s)) + (r₀ θ σ1 σ2 : ℝ) {κ : ℝ} (hκ : 0 < κ) {Tstar : ℝ≥0} (h0 : 0 < T₀) (hT : T₀ < T₁) + (hTstar : Tstar ≤ T₁) (hσ1 : σ1 ≠ 0) (hσ2 : σ2 ≠ 0) {ℓ : ι} {δ K : ℝ} + (h : BondModel μ (Filtration.natural B fun s ↦ (hBm s).stronglyMeasurable) + (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) X b ℓ T₀ T₁ δ) + (hK : 0 < 1 + δ * K) + (hint : Integrable (fun ω ↦ shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar) T₁ ω + * (δ * max (X ℓ T₀ ω - K) 0)) μ) : + (caplet ℓ T₀ T₁ δ K).value μ + (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) X + = (1 + δ * K) * + (zeroCurve μ (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) T₀ + * (1 / (1 + δ * K)) + * Phi (-bsd2 (zeroCurve μ + (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) T₁ + / zeroCurve μ (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) T₀) + (1 / (1 + δ * K)) 0 + (vasicekBondB κ ((T₁ : ℝ) - T₀) * Real.sqrt (gsrShortRateV κ σ1 σ2 (Tstar : ℝ) T₀)) 1) + - zeroCurve μ (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) T₁ + * Phi (-bsd1 (zeroCurve μ + (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) T₁ + / zeroCurve μ (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) T₀) + (1 / (1 + δ * K)) 0 + (vasicekBondB κ ((T₁ : ℝ) - T₀) * Real.sqrt (gsrShortRateV κ σ1 σ2 (Tstar : ℝ) T₀)) + 1)) := by + rw [value_caplet_eq_bondPut h hK hint] + exact congrArg _ (value_bondPut_gsr hB hBm r₀ θ σ1 σ2 hκ h0 hT hTstar hσ1 hσ2 h.bond_eq + (one_div_pos.2 hK)) + +/-! ### One volatility: the GSR put is the Vasicek put -/ + +omit [IsProbabilityMeasure μ] in +/-- **The zero curve of the one-volatility GSR model is Vasicek's**: the integrated rates agree +almost surely (`gsrIntegratedRate_self_ae`), so every `𝔼[D T]` does. -/ +theorem zeroCurve_gsr_self (hB : IsPreBrownianReal B μ) (r₀ θ σ : ℝ) {κ : ℝ} (hκ : 0 < κ) + (Tstar T : ℝ≥0) : + zeroCurve μ (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ σ hκ Tstar)) T + = zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T := + integral_congr_ae <| (gsrIntegratedRate_self_ae hB r₀ θ σ hκ Tstar T).mono fun ω h ↦ by + simp only [shortRateDiscount, h] + +/-- **The GSR put at `σ₁ = σ₂` is the Vasicek put.** With one volatility `σ` on both sides of the +breakpoint `T*`, the GSR put of `value_bondPut_gsr` is worth the closed form of +`value_bondPut_vasicek`: the zero curve is Vasicek's (`zeroCurve_gsr_self`) and the variance of +`r_{T₀}` is `σ²(1 − e^{−2κT₀})/(2κ)` (`gsrShortRateV_self`), whatever `T*`. -/ +theorem value_bondPut_gsr_self (hB : IsPreBrownianReal B μ) (hBm : ∀ s, Measurable (B s)) + (r₀ θ σ : ℝ) {κ : ℝ} (hκ : 0 < κ) {Tstar : ℝ≥0} (h0 : 0 < T₀) (hT : T₀ < T₁) + (hTstar : Tstar ≤ T₁) (hσ : σ ≠ 0) + (hb : X b T₀ =ᵐ[μ] bondPrice μ (Filtration.natural B fun s ↦ (hBm s).stronglyMeasurable) + (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ σ hκ Tstar)) T₀ T₁) {k : ℝ} (hk : 0 < k) : + (bondPut b T₀ k).value μ (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ σ hκ Tstar)) X + = zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₀ * k + * Phi (-bsd2 (zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₁ + / zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₀) k 0 + (vasicekBondB κ ((T₁ - T₀ : ℝ≥0) : ℝ) + * Real.sqrt (vasicekSDEVariance σ κ T₀)) 1) + - zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₁ + * Phi (-bsd1 (zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₁ + / zeroCurve μ (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) T₀) k 0 + (vasicekBondB κ ((T₁ - T₀ : ℝ≥0) : ℝ) + * Real.sqrt (vasicekSDEVariance σ κ T₀)) 1) := by + rw [value_bondPut_gsr hB hBm r₀ θ σ σ hκ h0 hT hTstar hσ hσ hb hk] + simp only [zeroCurve_gsr_self hB r₀ θ σ hκ Tstar, gsrShortRateV_self, NNReal.coe_sub hT.le] + +end GaussianShortRate + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Models/Rates/KeyRateDuration.lean b/LeanPool/MathFin/Models/Rates/KeyRateDuration.lean new file mode 100644 index 0000000000..91a3472315 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/KeyRateDuration.lean @@ -0,0 +1,139 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.DurationSensitivity +public import Mathlib.Analysis.Calculus.Deriv.Shift + +/-! +# Key-rate partials sum to the parallel-shift derivative + +`MacaulayModified` prices a bond off a single flat yield, `P(y) = Σ cᵢ / (1 + y)^{tᵢ}` +(`bondPriceDisc`), and `DurationSensitivity` differentiates it: `P'(y) = -ModNum(y)` +(`hasDerivAt_bondPriceDisc`). +Key-rate analysis refines the flat yield to a curve: cashflow `i` is discounted at its own rate +`kᵢ` (one node per cashflow, not a tenor-indexed curve), + + `P(k) = Σ cᵢ / (1 + kᵢ)^{tᵢ}` (`bondPriceKeyRate`). + +The key-rate sensitivity to node `j` is the partial derivative `∂P/∂kⱼ`, the derivative of `P` +along the curve that moves `kⱼ` alone (`Function.update k j`). The key-rate duration is +`KRDⱼ = -(1/P)·∂P/∂kⱼ`; this module states its results for the partials and does not define +the durations. + +The identity that makes key rates a decomposition of duration: the partials sum to the +derivative under a parallel shift `k ↦ k + ε·1`. On a flat curve `k ≡ y` the parallel shift is +a move of the flat yield, so the sum is `dP/dy`, the derivative `hasDerivAt_bondPriceDisc` +computes. + +## Main definitions + +* `bondPriceKeyRate`: the bond price with cashflow `i` discounted at its own rate `k i`, with + annual compounding. + +## Main results + +* `bondPriceKeyRate_update_eq`: moving the spot rate of node `j ∈ s` to `x` leaves every other + cashflow's term unchanged (used to prove both results below). +* `hasDerivAt_bondPriceKeyRate_update`: for `1 + kⱼ ≠ 0`, `∂P/∂kⱼ = -tⱼ·cⱼ / (1 + kⱼ)^{tⱼ+1}`, + as a `HasDerivAt`. +* `hasDerivAt_bondPriceKeyRate_parallel`: on any curve, the parallel-shift derivative is + `Σⱼ ∂P/∂kⱼ`, for any choice of witnesses `∂P/∂kⱼ`. +* `sum_keyRate_partials_eq_deriv_bondPriceDisc`, `sum_deriv_keyRate_eq_deriv_bondPriceDisc`: + on a flat curve `k ≡ y` (`1 + y ≠ 0`), `Σⱼ ∂P/∂kⱼ = dP/dy` (`deriv (bondPriceDisc s t c) y`), + for given partial-derivative witnesses and for the `deriv`s themselves. + +## References + +* [Ho, *Key rate durations: measures of interest rate risks*][Ho1992] + +## Tags + +key rate duration, partial duration, parallel shift, yield curve sensitivity, bond risk, +spot rate node, MSC 91G30, JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +variable {ι : Type*} + +/-- Bond price with cashflow `i` discounted at its own rate `k i` (one node per cashflow), +annual compounding. On a flat curve it is `bondPriceDisc`. -/ +noncomputable def bondPriceKeyRate (s : Finset ι) (t : ι → ℕ) (c k : ι → ℝ) : ℝ := + ∑ i ∈ s, c i / (1 + k i) ^ t i + +/-- On a flat curve the key-rate price is the flat-yield price `bondPriceDisc`. -/ +theorem bondPriceKeyRate_const (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) (y : ℝ) : + bondPriceKeyRate s t c (fun _ ↦ y) = bondPriceDisc s t c y := rfl + +/-- Moving the spot rate of node `j ∈ s` to `x` changes only cashflow `j`'s discount term; the +rest of the curve's contribution is unchanged. -/ +theorem bondPriceKeyRate_update_eq [DecidableEq ι] (s : Finset ι) (t : ι → ℕ) (c k : ι → ℝ) + {j : ι} (hj : j ∈ s) (x : ℝ) : + bondPriceKeyRate s t c (Function.update k j x) = + c j / (1 + x) ^ t j + ∑ i ∈ s.erase j, c i / (1 + k i) ^ t i := by + rw [bondPriceKeyRate, ← Finset.add_sum_erase s _ hj, Function.update_self] + congr 1 + exact Finset.sum_congr rfl fun i hi ↦ by rw [Function.update_of_ne (Finset.ne_of_mem_erase hi)] + +/-- **Key-rate partial derivative.** Moving the spot rate of node `j ∈ s` alone moves only +cashflow `j`'s discount term, so, for `1 + kⱼ ≠ 0`, `∂P/∂kⱼ = -tⱼ·cⱼ / (1 + kⱼ)^{tⱼ+1}`: the +per-cashflow derivative `hasDerivAt_coupon_term` that `hasDerivAt_bondPriceDisc` sums. -/ +theorem hasDerivAt_bondPriceKeyRate_update [DecidableEq ι] (s : Finset ι) (t : ι → ℕ) + (c k : ι → ℝ) {j : ι} (hj : j ∈ s) (hk : 1 + k j ≠ 0) : + HasDerivAt (fun x ↦ bondPriceKeyRate s t c (Function.update k j x)) + (-((t j : ℝ) * c j / (1 + k j) ^ (t j + 1))) (k j) := by + simpa only [bondPriceKeyRate_update_eq s t c k hj] using + (hasDerivAt_coupon_term (c j) (t j) hk).add_const _ + +/-- **Key-rate partials sum to the parallel-shift derivative.** On any curve `k`, if `D j` is +the partial derivative `∂P/∂kⱼ` for every node `j ∈ s`, then the price along the parallel shift +`ε ↦ P(k + ε·1)` has derivative `Σⱼ D j` at `ε = 0`. The partials are taken as hypotheses, so +the statement holds for whatever `∂P/∂kⱼ` is — `hasDerivAt_bondPriceKeyRate_update` computes one +such witness in closed form. -/ +theorem hasDerivAt_bondPriceKeyRate_parallel [DecidableEq ι] (s : Finset ι) (t : ι → ℕ) + (c k : ι → ℝ) {D : ι → ℝ} + (hD : ∀ j ∈ s, + HasDerivAt (fun x ↦ bondPriceKeyRate s t c (Function.update k j x)) (D j) (k j)) : + HasDerivAt (fun ε ↦ bondPriceKeyRate s t c (fun i ↦ k i + ε)) (∑ j ∈ s, D j) 0 := by + unfold bondPriceKeyRate + refine HasDerivAt.fun_sum fun j hj ↦ ?_ + have h0 : HasDerivAt (fun x ↦ bondPriceKeyRate s t c (Function.update k j x)) (D j) + (k j + 0) := by simpa using hD j hj + simpa only [bondPriceKeyRate_update_eq s t c k hj, add_sub_cancel_right] using + (h0.comp_const_add (k j) 0).sub_const (∑ i ∈ s.erase j, c i / (1 + k i) ^ t i) + +/-- **`Σⱼ ∂P/∂kⱼ = dP/dy`.** On a flat curve `k ≡ y` (with `1 + y ≠ 0`), the key-rate partials +`D j = ∂P/∂kⱼ` sum to the derivative of the flat-yield price `bondPriceDisc` at `y`: a +parallel shift of a flat curve is a move of the yield, so `hasDerivAt_bondPriceKeyRate_parallel` +and `hasDerivAt_bondPriceDisc` compute the same derivative. -/ +theorem sum_keyRate_partials_eq_deriv_bondPriceDisc [DecidableEq ι] (s : Finset ι) (t : ι → ℕ) + (c : ι → ℝ) {y : ℝ} (hy : 1 + y ≠ 0) {D : ι → ℝ} + (hD : ∀ j ∈ s, HasDerivAt + (fun x ↦ bondPriceKeyRate s t c (Function.update (fun _ ↦ y) j x)) (D j) y) : + ∑ j ∈ s, D j = deriv (bondPriceDisc s t c) y := by + have hpar := hasDerivAt_bondPriceKeyRate_parallel s t c (fun _ ↦ y) hD + have hflat : HasDerivAt (fun ε ↦ bondPriceKeyRate s t c (fun _ ↦ y + ε)) + (-modifiedNumerator s t c y) 0 := by + have := (hasDerivAt_bondPriceDisc s t c (y := y + 0) (by simpa using hy)).comp_const_add y 0 + rwa [add_zero] at this + rw [hpar.unique hflat, (hasDerivAt_bondPriceDisc s t c hy).deriv] + +/-- **`Σⱼ ∂P/∂kⱼ = dP/dy`, with the partials as `deriv`s.** On a flat curve `k ≡ y` +(`1 + y ≠ 0`), the key-rate partial derivatives sum to the derivative of the flat-yield price +`bondPriceDisc` at `y`. Each partial exists by `hasDerivAt_bondPriceKeyRate_update`. -/ +theorem sum_deriv_keyRate_eq_deriv_bondPriceDisc [DecidableEq ι] (s : Finset ι) (t : ι → ℕ) + (c : ι → ℝ) {y : ℝ} (hy : 1 + y ≠ 0) : + ∑ j ∈ s, deriv (fun x ↦ bondPriceKeyRate s t c (Function.update (fun _ ↦ y) j x)) y = + deriv (bondPriceDisc s t c) y := + sum_keyRate_partials_eq_deriv_bondPriceDisc s t c hy fun _ hj ↦ + (hasDerivAt_bondPriceKeyRate_update s t c _ hj hy).differentiableAt.hasDerivAt + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/LoanAmortization.lean b/LeanPool/MathFin/Models/Rates/LoanAmortization.lean new file mode 100644 index 0000000000..fbba857ce8 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/LoanAmortization.lean @@ -0,0 +1,162 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.CouponBonds + +/-! +# Loan amortization schedules: bullet, equal-principal and level-payment + +All three schedules share the same per-period interest accrual on the outstanding +balance `B_{n-1}`, + + `I_n = B_{n-1} · i`, + +and the same balance recurrence given the period's principal payment `P_n`, + + `B_n = B_{n-1} - P_n`. + +They differ only in how `P_n` is chosen: + +* **Bullet** (interest-only): `P_n = 0` for `n < N`, `P_N = B_0` — the whole + principal is repaid in a single final installment. Closed form: + `B_n = B_0` for `n < N`, `B_N = 0`. +* **Equal-principal**: `P_n = B_0 / N` every period — a constant principal + payment. Closed form: `B_n = B_0 · (1 - n / N)`. +* **Level payment** (mortgage-style): the same payment `A` every period, its + principal part `P_n = A - I_n` being what is left after interest, so + `B_n = B_{n-1}·(1 + i) - A`. Priced against `annuityValue` + (`MathFin/Models/Rates/CouponBonds.lean`), the present value of `N` payments + `A` discounted continuously at rate `r` over periods of length `Δt`: if the + loan's principal is that annuity's value and the period rate is + `i = e^{rΔt} - 1`, then after `n ≤ N` payments the outstanding balance is + the value of the `N - n` payments still to come, and the loan is paid off + at `N`. + +The bullet and equal-principal closed forms are proved by induction on the +shared `balance` recurrence; the level-payment one, by induction on +`levelPaymentBalance` directly, through the one-period annuity identity +`annuityValue_succ_mul_exp_sub` (`CouponBonds.lean`). + +## Main definitions + +* `balance`: the outstanding balance after `n` periods, given an initial balance `B₀` and a + principal-payment schedule `P : ℕ → ℝ`. +* `bulletPrincipal`: the bullet schedule, with the entire balance repaid in period `N`. +* `equalPrincipalPayment`: the equal-principal schedule, a constant payment `B₀ / N` every period. +* `levelPaymentBalance`: the level-payment balance, with interest at period rate `i` accruing on + the outstanding balance before the payment `A` is made. + +## Main results + +* `balance_bullet_lt`, `balance_bullet_eq` — the bullet closed form. +* `balance_equalPrincipal` — the equal-principal closed form + `B_n = B_0 · (1 - n / N)`. +* `levelPaymentBalance`, `balance_levelPayment` — the level-payment balance, + and that it is `balance` with principal `A - I_n`. +* `levelPaymentBalance_eq_annuityValue`, `levelPaymentBalance_eq_zero` — the + balance after `n` level payments is `annuityValue (N - n) A r Δt`, and zero + at `N`. + +## References + +* [Fabozzi, *Bond Markets, Analysis and Strategies*][FabozziBMAS] + +## Tags + +loan amortization, mortgage, bullet loan, level payment, equal principal, outstanding balance, +annuity, MSC 91G30, JEL G21 +-/ + +@[expose] public section + +namespace MathFin + +/-- The outstanding balance after `n` periods, given an initial balance `B₀` +and a principal-payment schedule `P : ℕ → ℝ` (period `k`'s payment is `P k` +for `k = 1, …, n`). Defined by the shared recurrence `B_n = B_{n-1} - P_n`. -/ +def balance (B0 : ℝ) (P : ℕ → ℝ) : ℕ → ℝ + | 0 => B0 + | n + 1 => balance B0 P n - P (n + 1) + +/-- The bullet schedule: no principal is repaid before maturity `N`, and the +entire balance is repaid in period `N`. -/ +def bulletPrincipal (B0 : ℝ) (N : ℕ) : ℕ → ℝ := + fun n ↦ if n = N then B0 else 0 + +/-- Under the bullet schedule, the balance is unchanged before maturity. -/ +theorem balance_bullet_lt {B0 : ℝ} {N n : ℕ} (hn : n < N) : + balance B0 (bulletPrincipal B0 N) n = B0 := by + induction n with + | zero => rfl + | succ k ih => simp [balance, bulletPrincipal, ih (Nat.lt_of_succ_lt hn), hn.ne] + +/-- Under the bullet schedule, the balance is exactly zero at maturity `N ≥ 1` +(at `N = 0` maturity is not a payment period, and the balance stays `B₀`). -/ +theorem balance_bullet_eq {B0 : ℝ} {N : ℕ} (hN : 0 < N) : + balance B0 (bulletPrincipal B0 N) N = 0 := by + obtain ⟨M, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hN.ne' + simp [balance, bulletPrincipal, balance_bullet_lt (Nat.lt_succ_self M)] + +/-- The equal-principal schedule: a constant payment `B₀ / N` every period. -/ +noncomputable def equalPrincipalPayment (B0 : ℝ) (N : ℕ) : ℕ → ℝ := fun _ ↦ B0 / N + +/-- Closed form for the equal-principal schedule: `B_n = B₀ · (1 - n / N)`, +proved by induction on the balance recurrence. (At `N = 0` both sides reduce +to `B₀` under the `x / 0 = 0` convention, so no `N ≠ 0` hypothesis is needed.) -/ +theorem balance_equalPrincipal {B0 : ℝ} {N : ℕ} (n : ℕ) : + balance B0 (equalPrincipalPayment B0 N) n = B0 * (1 - (n : ℝ) / N) := by + induction n with + | zero => simp [balance] + | succ k ih => + simp only [balance, equalPrincipalPayment, ih] + push_cast + ring + +/-- The level-payment balance: interest at period rate `i` accrues on the +outstanding balance, then the payment `A` is made, `B_{n+1} = B_n·(1 + i) - A`. -/ +def levelPaymentBalance (B0 A i : ℝ) : ℕ → ℝ + | 0 => B0 + | n + 1 => levelPaymentBalance B0 A i n * (1 + i) - A + +/-- The level-payment schedule is the shared recurrence `balance` with the +principal part of period `n + 1`'s payment being `A` less the interest +`B_n · i` on the outstanding balance. -/ +theorem balance_levelPayment (B0 A i : ℝ) (n : ℕ) : + balance B0 (fun m ↦ A - levelPaymentBalance B0 A i (m - 1) * i) n = + levelPaymentBalance B0 A i n := by + induction n with + | zero => rfl + | succ k ih => + simp only [balance, levelPaymentBalance, ih, Nat.add_sub_cancel] + ring + +/-- **Level-payment schedule against `annuityValue`.** A loan whose principal +`B₀` is the value `annuityValue N A r Δt` of `N` level payments `A`, at period +rate `i = e^{rΔt} - 1`, has outstanding balance after `n ≤ N` payments equal to +the value of the `N - n` payments still to come. -/ +theorem levelPaymentBalance_eq_annuityValue {B0 A r Δt : ℝ} {N : ℕ} + (hB0 : annuityValue N A r Δt = B0) {n : ℕ} (hn : n ≤ N) : + levelPaymentBalance B0 A (Real.exp (r * Δt) - 1) n = annuityValue (N - n) A r Δt := by + induction n with + | zero => exact hB0.symm + | succ k ih => + obtain ⟨m, hm⟩ := Nat.exists_eq_add_of_lt hn + rw [levelPaymentBalance, ih (Nat.le_of_succ_le hn), add_sub_cancel, + show N - k = m + 1 by omega, show N - (k + 1) = m by omega, + annuityValue_succ_mul_exp_sub] + +/-- **A level-payment loan is paid off at maturity**: with `B₀` the value of the +`N` payments, the balance after the `N`-th is zero. -/ +theorem levelPaymentBalance_eq_zero {B0 A r Δt : ℝ} {N : ℕ} + (hB0 : annuityValue N A r Δt = B0) : + levelPaymentBalance B0 A (Real.exp (r * Δt) - 1) N = 0 := by + rw [levelPaymentBalance_eq_annuityValue hB0 le_rfl, Nat.sub_self, annuityValue, + Finset.sum_range_zero] + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/MacaulayModified.lean b/LeanPool/MathFin/Models/Rates/MacaulayModified.lean new file mode 100644 index 0000000000..3b6b2ec9c3 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/MacaulayModified.lean @@ -0,0 +1,84 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.BigOperators.Field +public import Mathlib.Analysis.Normed.Field.Basic + +/-! +# Macaulay vs modified duration under discrete compounding + +For a bond with discrete-compounded yield `y` and cashflows `c_i` at times +`t_i ∈ ℕ`, define the duration numerators + + `MacNum(y) = Σ t_i · c_i / (1 + y)^{t_i}`, + `ModNum(y) = Σ t_i · c_i / (1 + y)^{t_i + 1}`. + +Modified duration is `ModNum / Price`, Macaulay duration is `MacNum / Price`. +The discrete-compounding identity is + +`ModNum(y) = MacNum(y) / (1 + y)`, + +i.e. modified duration differs from Macaulay duration by exactly one factor of +the discount step. (Under continuous compounding the two coincide.) + +## Main definitions + +* `bondPriceDisc`: the bond price under discrete annual compounding with integer cashflow times. +* `macaulayNumerator`: the Macaulay duration numerator `MacNum(y) = Σ t_i · c_i / (1 + y)^{t_i}`. +* `modifiedNumerator`: the modified duration numerator + `ModNum(y) = Σ t_i · c_i / (1 + y)^{t_i + 1}`. + +## Main results + +* `modifiedNumerator_eq_macaulayNumerator_div`: the algebraic identity. + +## References + +* [Fabozzi, *Fixed Income Mathematics*][FabozziFIM], 4.3 + +## Tags + +Macaulay duration, modified duration, discrete compounding, bond duration, interest rate risk, +MSC 91G30, JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +open Finset + +variable {ι : Type*} + +/-- Bond price under discrete annual compounding with integer cashflow times. -/ +noncomputable def bondPriceDisc (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) (y : ℝ) : ℝ := + ∑ i ∈ s, c i / (1 + y) ^ t i + +/-- Macaulay duration numerator. -/ +noncomputable def macaulayNumerator (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) (y : ℝ) : ℝ := + ∑ i ∈ s, (t i : ℝ) * c i / (1 + y) ^ t i + +/-- Modified duration numerator. -/ +noncomputable def modifiedNumerator (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) (y : ℝ) : ℝ := + ∑ i ∈ s, (t i : ℝ) * c i / (1 + y) ^ (t i + 1) + +/-- **Modified = Macaulay / (1 + y)** at the level of numerators, hence at the +level of durations themselves. -/ +lemma modifiedNumerator_eq_macaulayNumerator_div + (s : Finset ι) (t : ι → ℕ) (c : ι → ℝ) (y : ℝ) (hy : 1 + y ≠ 0) : + modifiedNumerator s t c y = + macaulayNumerator s t c y / (1 + y) := by + unfold modifiedNumerator macaulayNumerator + rw [Finset.sum_div] + refine Finset.sum_congr rfl (fun i _ ↦ ?_) + rw [pow_succ] + field_simp + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/NelsonSiegelSvensson.lean b/LeanPool/MathFin/Models/Rates/NelsonSiegelSvensson.lean new file mode 100644 index 0000000000..f2f991b0b5 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/NelsonSiegelSvensson.lean @@ -0,0 +1,201 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.InnerProductSpace.Basic +public import Mathlib.Analysis.SpecialFunctions.ExpDeriv +public import Mathlib.Topology.Algebra.Module.ModuleTopology + +/-! +# Nelson-Siegel-Svensson yield-curve parametrization + +The **Nelson-Siegel** (1987) and its **Svensson** (1994) four-term extension +are closed-form exponential-basis parametrizations of the zero-coupon yield +curve, fit by least squares to observed yields rather than recovered by +bootstrapping (`Models/Rates/YieldCurve.lean`, `Models/Rates/Bootstrapping.lean`) +from coupon-bond prices. The Svensson curve is + + `y(τ) = β₀ + β₁·s(τ/l₁) + β₂·(s(τ/l₁) - e^{-τ/l₁}) + β₃·(s(τ/l₂) - e^{-τ/l₂})`, + +where `s(x) = (1 - e^{-x})/x` is the (normalized) slope factor shared by the +level/slope/curvature decomposition, and `l₁, l₂ > 0` are decay parameters +governing where the two curvature humps peak. Setting `β₃ = 0` recovers the +plain three-factor Nelson-Siegel curve. + +This is a genuinely different object from bootstrapping: it is a closed form +in four (Nelson-Siegel) or six (Svensson) parameters, fit across the whole +curve at once, rather than a maturity-by-maturity recursive discount-factor +recovery. (Only continuity on `(0, ∞)` is proved here; at `τ = 0` the Lean +definition takes Lean's `x / 0 = 0` junk value, and the short end is stated +as a limit.) + +## Main definitions + +* `nssSlope`: the Nelson-Siegel slope factor `s(x) = (1 - e^{-x}) / x`. +* `nssYield`: the Nelson-Siegel-Svensson closed-form yield curve + `y(τ) = β₀ + β₁·s(τ/l₁) + β₂·(s(τ/l₁) - e^{-τ/l₁}) + β₃·(s(τ/l₂) - e^{-τ/l₂})`. + +## Main results + +* `continuousOn_nssYield` — `y` is continuous on `(0, ∞)` (the economically + meaningful domain: no coupon bond or discount factor is quoted at `τ = 0`). +* `tendsto_nssSlope_nhdsNE_zero` — the core calculus fact underlying the + curve's short end: `s(x) → 1` as `x → 0 (through nonzero values)`, obtained from `HasDerivAt` of + `x ↦ 1 - e^{-x}` at `0` (the slope factor is literally a difference + quotient of that function through the origin). +* `tendsto_nssSlope_atTop` — the slope factor's long end: `s(x) → 0` as `x → ∞`. +* `tendsto_nssYield_nhdsNE_zero` — **short-end limit**: + `y(τ) → β₀ + β₁` as `τ → 0 (through nonzero values)` (the two curvature terms vanish at the short + end, leaving level plus slope). +* `tendsto_nssYield_atTop` — **long-end limit**: `y(τ) → β₀` as `τ → ∞` + (all three non-level terms decay away, leaving the level factor as the + asymptotic long rate). + +The slope factor is also the Vasicek rate loading per unit maturity, +`s(κτ) = vasicekBondB κ τ / τ`; `Models/Rates/VasicekYieldNelsonSiegel.lean` writes the +Vasicek zero yield in these factors. + +## References + +* [C. R. Nelson, A. F. Siegel, *Parsimonious Modeling of Yield Curves*][NelsonSiegel1987]. +* [L. E. O. Svensson, *Estimating and Interpreting Forward Interest Rates: Sweden + 1992–1994*][Svensson1994]. + +## Tags + +Nelson–Siegel, Svensson, yield curve fitting, level slope curvature, parametric yield curve, +zero-coupon yield, MSC 91G30, JEL E43 +-/ + +@[expose] public section + +namespace MathFin + +open Filter Topology + +/-- The Nelson-Siegel **slope factor** `s(x) = (1 - e^{-x}) / x`, the +normalized exponential building block shared by the slope and curvature +terms of the Nelson-Siegel-Svensson curve. -/ +noncomputable def nssSlope (x : ℝ) : ℝ := (1 - Real.exp (-x)) / x + +/-- The **Nelson-Siegel-Svensson** closed-form yield curve: +`y(τ) = β₀ + β₁·s(τ/l₁) + β₂·(s(τ/l₁) - e^{-τ/l₁}) + β₃·(s(τ/l₂) - e^{-τ/l₂})`. +Setting `β₃ = 0` gives the plain three-factor Nelson-Siegel (1987) curve; +the fourth term is Svensson's (1994) extension adding a second curvature +hump at a distinct decay rate `l₂`. -/ +noncomputable def nssYield (β₀ β₁ β₂ β₃ l₁ l₂ τ : ℝ) : ℝ := + β₀ + β₁ * nssSlope (τ / l₁) + + β₂ * (nssSlope (τ / l₁) - Real.exp (-(τ / l₁))) + + β₃ * (nssSlope (τ / l₂) - Real.exp (-(τ / l₂))) + +/-- `nssSlope` is continuous away from `0` (an ordinary quotient of continuous +functions with nonvanishing denominator). -/ +theorem continuousAt_nssSlope {x : ℝ} (hx : x ≠ 0) : ContinuousAt nssSlope x := by + unfold nssSlope + fun_prop (disch := assumption) + +/-- **The curve is continuous on `(0, ∞)`**, the economically meaningful +domain for a yield curve (no instrument is quoted at `τ = 0`). -/ +theorem continuousOn_nssYield (β₀ β₁ β₂ β₃ l₁ l₂ : ℝ) + (hl₁ : l₁ ≠ 0) (hl₂ : l₂ ≠ 0) : + ContinuousOn (nssYield β₀ β₁ β₂ β₃ l₁ l₂) (Set.Ioi 0) := by + have h1 : ∀ τ ∈ Set.Ioi (0 : ℝ), τ / l₁ ≠ 0 := fun τ hτ ↦ div_ne_zero hτ.ne' hl₁ + have h2 : ∀ τ ∈ Set.Ioi (0 : ℝ), τ / l₂ ≠ 0 := fun τ hτ ↦ div_ne_zero hτ.ne' hl₂ + unfold nssYield nssSlope + fun_prop (disch := first | apply h1 | apply h2 | assumption) + +/-- **Core calculus fact**: the slope factor `s(x) = (1-e^{-x})/x` tends to +`1` as `x → 0` through nonzero values. This is the difference quotient of +`f(x) = 1 - e^{-x}` through the origin, so it is exactly `HasDerivAt f 1 0` +read via `hasDerivAt_iff_tendsto_slope`. -/ +theorem tendsto_nssSlope_nhdsNE_zero : + Tendsto nssSlope (𝓝[≠] (0 : ℝ)) (𝓝 1) := by + have hf : HasDerivAt (fun x : ℝ ↦ 1 - Real.exp (-x)) 1 0 := by + have hexp : HasDerivAt (fun x : ℝ ↦ Real.exp (-x)) (-1) 0 := by + simpa using (hasDerivAt_neg (0 : ℝ)).exp + simpa using hexp.const_sub (1 : ℝ) + have hcongr : slope (fun x : ℝ ↦ 1 - Real.exp (-x)) 0 = nssSlope := by + funext x; simp [slope_def_field, nssSlope] + simpa [hcongr] using hasDerivAt_iff_tendsto_slope.mp hf + +/-- Dividing by a nonzero constant tends to `0` through nonzero values as the +numerator tends to `0` through nonzero values (used to transport the `𝓝[≠] 0` +short-end limit of `nssSlope` and `exp` along `τ ↦ τ/l`). -/ +theorem tendsto_div_const_nhdsNE_zero {c : ℝ} (hc : c ≠ 0) : + Tendsto (fun x : ℝ ↦ x / c) (𝓝[≠] (0 : ℝ)) (𝓝[≠] (0 : ℝ)) := by + rw [tendsto_nhdsWithin_iff] + refine ⟨?_, ?_⟩ + · have hbase : Tendsto (fun x : ℝ ↦ x / c) (𝓝 0) (𝓝 0) := by + simpa using (continuous_id.div_const c).tendsto (0 : ℝ) + exact hbase.mono_left nhdsWithin_le_nhds + · filter_upwards [self_mem_nhdsWithin] with x hx + simp only [Set.mem_compl_iff, Set.mem_singleton_iff] at hx ⊢ + exact div_ne_zero hx hc + +/-- **Short-end limit**: as `τ → 0 (through nonzero values)`, the Svensson curve tends to `β₀ + β₁`. +The slope and level stay (`s(τ/lᵢ) → 1`), both curvature terms vanish +(`s(τ/lᵢ) - e^{-τ/lᵢ} → 1 - 1 = 0`), since `τ/lᵢ → 0` and `e^{-τ/lᵢ} → 1`. -/ +theorem tendsto_nssYield_nhdsNE_zero (β₀ β₁ β₂ β₃ l₁ l₂ : ℝ) + (hl₁ : l₁ ≠ 0) (hl₂ : l₂ ≠ 0) : + Tendsto (nssYield β₀ β₁ β₂ β₃ l₁ l₂) (𝓝[≠] (0 : ℝ)) (𝓝 (β₀ + β₁)) := by + have hdiv1 := tendsto_div_const_nhdsNE_zero hl₁ + have hdiv2 := tendsto_div_const_nhdsNE_zero hl₂ + have hs1 : Tendsto (fun τ : ℝ ↦ nssSlope (τ / l₁)) (𝓝[≠] (0 : ℝ)) (𝓝 1) := + tendsto_nssSlope_nhdsNE_zero.comp hdiv1 + have hs2 : Tendsto (fun τ : ℝ ↦ nssSlope (τ / l₂)) (𝓝[≠] (0 : ℝ)) (𝓝 1) := + tendsto_nssSlope_nhdsNE_zero.comp hdiv2 + have he (c : ℝ) : Tendsto (fun τ : ℝ ↦ Real.exp (-(τ / c))) (𝓝[≠] (0 : ℝ)) (𝓝 1) := + ((Real.continuous_exp.comp (continuous_id.div_const c).neg).tendsto' 0 1 (by simp)).mono_left + nhdsWithin_le_nhds + have he1 := he l₁ + have he2 := he l₂ + have h : Tendsto (nssYield β₀ β₁ β₂ β₃ l₁ l₂) (𝓝[≠] (0 : ℝ)) + (𝓝 (β₀ + β₁ * 1 + β₂ * (1 - 1) + β₃ * (1 - 1))) := by + unfold nssYield + exact + (((tendsto_const_nhds.add (hs1.const_mul β₁)).add + ((hs1.sub he1).const_mul β₂)).add + ((hs2.sub he2).const_mul β₃)) + simpa using h + +/-- **Long end of the slope factor**: `s(x) = (1 − e^{−x})/x → 0` as `x → ∞` (the numerator +tends to `1`, the denominator to `∞`). -/ +theorem tendsto_nssSlope_atTop : Tendsto nssSlope atTop (𝓝 0) := by + have hnum : Tendsto (fun x : ℝ ↦ 1 - Real.exp (-x)) atTop (𝓝 1) := by + simpa using tendsto_const_nhds.sub Real.tendsto_exp_neg_atTop_nhds_zero + exact hnum.div_atTop tendsto_id + +/-- **Long-end limit**: as `τ → ∞`, the Svensson curve tends to `β₀`, the +level factor — the slope and both curvature terms decay to `0` since +`s(τ/lᵢ) → 0` and `e^{-τ/lᵢ} → 0`, given `l₁, l₂ > 0`. -/ +theorem tendsto_nssYield_atTop (β₀ β₁ β₂ β₃ l₁ l₂ : ℝ) + (hl₁ : 0 < l₁) (hl₂ : 0 < l₂) : + Tendsto (nssYield β₀ β₁ β₂ β₃ l₁ l₂) atTop (𝓝 β₀) := by + have hdiv1 : Tendsto (fun τ : ℝ ↦ τ / l₁) atTop atTop := + Filter.tendsto_id.atTop_div_const hl₁ + have hdiv2 : Tendsto (fun τ : ℝ ↦ τ / l₂) atTop atTop := + Filter.tendsto_id.atTop_div_const hl₂ + have he1 : Tendsto (fun τ : ℝ ↦ Real.exp (-(τ / l₁))) atTop (𝓝 0) := + Real.tendsto_exp_neg_atTop_nhds_zero.comp hdiv1 + have he2 : Tendsto (fun τ : ℝ ↦ Real.exp (-(τ / l₂))) atTop (𝓝 0) := + Real.tendsto_exp_neg_atTop_nhds_zero.comp hdiv2 + have hs1 : Tendsto (fun τ : ℝ ↦ nssSlope (τ / l₁)) atTop (𝓝 0) := + tendsto_nssSlope_atTop.comp hdiv1 + have hs2 : Tendsto (fun τ : ℝ ↦ nssSlope (τ / l₂)) atTop (𝓝 0) := + tendsto_nssSlope_atTop.comp hdiv2 + have h : Tendsto (nssYield β₀ β₁ β₂ β₃ l₁ l₂) atTop + (𝓝 (β₀ + β₁ * 0 + β₂ * (0 - 0) + β₃ * (0 - 0))) := by + unfold nssYield + exact + (((tendsto_const_nhds.add (hs1.const_mul β₁)).add + ((hs1.sub he1).const_mul β₂)).add + ((hs2.sub he2).const_mul β₃)) + simpa using h + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/OUHermiteVasicek.lean b/LeanPool/MathFin/Models/Rates/OUHermiteVasicek.lean new file mode 100644 index 0000000000..a8b2215022 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/OUHermiteVasicek.lean @@ -0,0 +1,176 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.SDE.OUSpectral +public import LeanPool.MathFin.Models.Rates.VasicekSDEGaussian + +/-! +# The OU Hermite modes decay at their eigenvalues under the Vasicek law + +`Probability/Brownian/SDE/OUSpectral.lean` proves, as polynomial algebra, that the scaled Hermite +polynomials `q_n(x) = He_n(x/s)` are eigenfunctions of the OU generator +`L p = −κx·p' + (σ²/2)·p''` at the stationary scale `2κs² = σ²`, with eigenvalue `−nκ` +(`ouGen_scaledHermite`); no process appears there. The semigroup statement that the eigenvalue +predicts is `𝔼[q_n(X_T)] = e^{−nκT}·q_n(x₀)` for the OU process `X` started at `x₀`. + +This file checks that statement against the library's OU process: the centred Vasicek short rate +`X_T = r_T − θ`, with `r_T` in the Wiener representation whose Gaussian law +`N(vasicekSDEMean, vasicekSDEVariance)` is derived in `vasicekShortRate_hasLaw_gaussian` +(`Models/Rates/VasicekSDEGaussian.lean`), started at `x₀ = r₀ − θ`. For the first three modes, +`n ≤ 2`, the expectation of `q_n(r_T − θ)` is `e^{−nκT}·q_n(r₀ − θ)` +(`integral_scaledHermite_vasicekShortRate`). For `n = 1` this is the decay of the mean; for +`n = 2` it uses the variance `s²(1 − e^{−2κT})`, which is where the stationary scale enters. + +**Scope.** Only `n ≤ 2` is proved: the general mode needs either Gaussian integration by parts +or the Hermite generating function, neither of which is available here. That `ouGen` is the +infinitesimal generator of the Vasicek process is not proved; the decay is computed from the +explicit Gaussian law. + +## Main results + +* `integral_scaledHermite_vasicekShortRate` — `𝔼[q_n(r_T − θ)] = e^{−nκT}·q_n(r₀ − θ)` for + `n ≤ 2`, `κ > 0`, `s ≠ 0`, `2κs² = σ²`. + +## References + +* [G. A. Pavliotis, *Stochastic Processes and Applications*][Pavliotis2014], ch. 4 +* [O. Vasicek, *An equilibrium characterization of the term structure*][Vasicek1977] + +## Tags + +Ornstein–Uhlenbeck, Hermite polynomials, Vasicek model, generator eigenfunctions, mean reversion, +MSC 91G30, MSC 60J60, JEL E43 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Polynomial OUSpectral +open scoped NNReal +open WienerIntegralL2 + +/-- `He₁ = X` over `ℝ`. -/ +private theorem hermiteReal_one : hermiteReal 1 = X := by + simp [hermiteReal] + +/-- `𝔼[(c + Y)/s] = c/s` for `Y ~ N(0, v)`. -/ +theorem integral_add_div_gaussianReal (c s : ℝ) (v : ℝ≥0) : + ∫ x, (c + x) / s ∂(gaussianReal 0 v) = c / s := by + have h1 : Integrable (fun x : ℝ ↦ x) (gaussianReal 0 v) := + (memLp_id_gaussianReal 1).integrable (by norm_num) + rw [integral_div, integral_add (integrable_const c) h1, integral_id_gaussianReal] + simp + +/-- `𝔼[(c + Y)²] = c² + v` for `Y ~ N(0, v)`. -/ +theorem integral_add_sq_gaussianReal (c : ℝ) (v : ℝ≥0) : + ∫ x, (c + x) ^ 2 ∂(gaussianReal 0 v) = c ^ 2 + v := by + have h1 : Integrable (fun x : ℝ ↦ x) (gaussianReal 0 v) := + (memLp_id_gaussianReal 1).integrable (by norm_num) + have h2 : Integrable (fun x : ℝ ↦ x ^ 2) (gaussianReal 0 v) := + (memLp_id_gaussianReal (μ := 0) (v := v) 2).integrable_sq + have hlin : Integrable (fun x : ℝ ↦ c ^ 2 + 2 * c * x) (gaussianReal 0 v) := + (integrable_const _).add (h1.const_mul _) + rw [show (fun x : ℝ ↦ (c + x) ^ 2) = fun x ↦ c ^ 2 + 2 * c * x + x ^ 2 from + funext fun x ↦ by ring, + integral_add hlin h2, integral_add (integrable_const _) (h1.const_mul _), integral_const_mul, + integral_id_gaussianReal, integral_sq_gaussianReal] + simp + +/-- `(c + Y)²` is integrable for `Y ~ N(0, v)`. -/ +theorem integrable_add_sq_gaussianReal (c : ℝ) (v : ℝ≥0) : + Integrable (fun x : ℝ ↦ (c + x) ^ 2) (gaussianReal 0 v) := by + have h1 : Integrable (fun x : ℝ ↦ x) (gaussianReal 0 v) := + (memLp_id_gaussianReal 1).integrable (by norm_num) + have h2 : Integrable (fun x : ℝ ↦ x ^ 2) (gaussianReal 0 v) := + (memLp_id_gaussianReal (μ := 0) (v := v) 2).integrable_sq + rw [show (fun x : ℝ ↦ (c + x) ^ 2) = fun x ↦ c ^ 2 + 2 * c * x + x ^ 2 from + funext fun x ↦ by ring] + exact ((integrable_const _).add (h1.const_mul _)).add h2 + +/-- The first three scaled Hermite modes under `c + Y`, `Y ~ N(0, v)`: +`𝔼[q₀] = 1`, `𝔼[q₁] = c/s`, `𝔼[q₂] = (c² + v)/s² − 1`. -/ +private theorem integral_scaledHermite_gaussianReal (c s : ℝ) (v : ℝ≥0) : + ∫ x, (scaledHermite s 0).eval (c + x) ∂(gaussianReal 0 v) = 1 + ∧ ∫ x, (scaledHermite s 1).eval (c + x) ∂(gaussianReal 0 v) = c / s + ∧ ∫ x, (scaledHermite s 2).eval (c + x) ∂(gaussianReal 0 v) = (c ^ 2 + v) / s ^ 2 - 1 := by + refine ⟨?_, ?_, ?_⟩ + · simp [scaledHermite_eval, hermiteReal_zero] + · simp only [scaledHermite_eval, hermiteReal_one, eval_X] + exact integral_add_div_gaussianReal c s v + · simp only [scaledHermite_eval, hermiteReal_two, eval_sub, eval_mul, eval_X, eval_one] + rw [show (fun x : ℝ ↦ (c + x) / s * ((c + x) / s) - 1) + = fun x ↦ (c + x) ^ 2 / s ^ 2 - 1 from funext fun x ↦ by ring, + integral_sub ((integrable_add_sq_gaussianReal c v).div_const _) (integrable_const 1), + integral_div, integral_add_sq_gaussianReal] + simp + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-- The diffusion part `σ ∫₀ᵀ e^{−κ(T−u)} dB_u` of the Vasicek short rate has law +`N(0, vasicekSDEVariance σ κ T)`: `vasicekShortRate_hasLaw_gaussian` shifted by its mean. -/ +private theorem vasicekNoise_hasLaw (hB : IsPreBrownianReal B μ) (σ : ℝ) {κ : ℝ} (hκ : 0 < κ) + (T : ℝ≥0) : + HasLaw (fun ω ↦ σ * wienerIntegralLp B hB T (vasicekKernelLp κ hκ.le T) ω) + (gaussianReal 0 (vasicekSDEVariance σ κ T).toNNReal) μ := by + have h := gaussianReal_sub_const (vasicekShortRate_hasLaw_gaussian hB 0 0 σ hκ T) + (vasicekSDEMean 0 0 κ T) + rw [sub_self] at h + convert h using 1 + funext ω + ring + +/-- **The OU Hermite modes decay at their eigenvalues under the Vasicek law** (`n ≤ 2`). For the +Vasicek short rate `r_T` started at `r₀`, in its Wiener representation, and the stationary scale +`s` (`2κs² = σ²`, `s ≠ 0`), the scaled Hermite mode `q_n(x) = He_n(x/s)` of the centred rate +satisfies `𝔼[q_n(r_T − θ)] = e^{−nκT}·q_n(r₀ − θ)` for `n = 0, 1, 2`: the semigroup form of the +eigenidentity `ouGen κ σ q_n = −nκ·q_n` (`ouGen_scaledHermite`). -/ +theorem integral_scaledHermite_vasicekShortRate (hB : IsPreBrownianReal B μ) (r₀ θ σ : ℝ) + {κ : ℝ} (hκ : 0 < κ) (T : ℝ≥0) {s : ℝ} (hs : s ≠ 0) (h : 2 * κ * s ^ 2 = σ ^ 2) {n : ℕ} + (hn : n ≤ 2) : + ∫ ω, (scaledHermite s n).eval + (vasicekSDEMean r₀ θ κ T + σ * wienerIntegralLp B hB T (vasicekKernelLp κ hκ.le T) ω - θ) + ∂μ + = Real.exp (-(n * κ * T)) * (scaledHermite s n).eval (r₀ - θ) := by + have hcomp := (vasicekNoise_hasLaw hB σ hκ T).integral_comp + (f := fun x ↦ (scaledHermite s n).eval (vasicekSDEMean r₀ θ κ T - θ + x)) + (by fun_prop : Continuous fun x : ℝ ↦ + (scaledHermite s n).eval (vasicekSDEMean r₀ θ κ T - θ + x)).aestronglyMeasurable + simp only [Function.comp_def] at hcomp + simp only [add_sub_right_comm _ _ θ] + rw [hcomp] + have hc : vasicekSDEMean r₀ θ κ T - θ = (r₀ - θ) * Real.exp (-(κ * T)) := by + unfold vasicekSDEMean + ring + have hκ0 : κ ≠ 0 := hκ.ne' + have hV : ((vasicekSDEVariance σ κ T).toNNReal : ℝ) = s ^ 2 * (1 - Real.exp (-(2 * κ * T))) := by + rw [Real.coe_toNNReal _ (vasicekSDEVariance_nonneg σ hκ T.coe_nonneg), vasicekSDEVariance, ← h] + field_simp + have hE : Real.exp (-(2 * κ * T)) = Real.exp (-(κ * T)) ^ 2 := by + rw [← Real.exp_nat_mul] + congr 1 + push_cast + ring + obtain ⟨h0, h1, h2⟩ := integral_scaledHermite_gaussianReal (vasicekSDEMean r₀ θ κ T - θ) s + (vasicekSDEVariance σ κ T).toNNReal + interval_cases n + · rw [h0] + simp [scaledHermite_eval, hermiteReal_zero] + · rw [h1, hc, scaledHermite_eval, hermiteReal_one, eval_X] + simp only [Nat.cast_one, one_mul] + ring + · rw [h2, hc, hV, hE, scaledHermite_eval, hermiteReal_two] + simp only [eval_sub, eval_mul, eval_X, eval_one] + push_cast + rw [hE] + field_simp + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/PeriodicCompounding.lean b/LeanPool/MathFin/Models/Rates/PeriodicCompounding.lean new file mode 100644 index 0000000000..b3a0d821e3 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/PeriodicCompounding.lean @@ -0,0 +1,95 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.ZCB +public import Mathlib.Analysis.SpecialFunctions.Complex.LogBounds + +/-! +# Periodic compounding against the continuously compounded bond + +An account that accrues simple interest `y` per period and reinvests it grows like `(1 + y) ^ n` +over `n` periods. This file places that geometric growth next to the library's continuously +compounded zero-coupon bond `zcb r t T = exp (−r (T − t))` (`Models/Rates/ZCB.lean`), in three +statements: + +* `one_add_pow_mul_zcb_log`: compounding at `y > −1` per period is exactly continuous compounding + at the equivalent rate `log (1 + y)`, with time measured in periods: discounting the grown + balance by `zcb (log (1 + y)) 0 n` returns the initial balance. This is the conversion + `R_c = m · log (1 + R_m / m)` with `m = 1`. +* `one_add_mul_pow_le_inv_zcb`: at the *same* nominal rate `r`, `n` periods of length `t` (with + `r t ≥ −1`) never out-accrue continuous compounding over the elapsed time `n · t`: + `(1 + r t)^n ≤ 1 / zcb r 0 (n t)` (from `1 + x ≤ exp x`). +* `tendsto_one_add_div_pow_inv_zcb`: splitting a horizon `T` into `n` equal periods, + `(1 + r T / n) ^ n → 1 / zcb r 0 T = exp (r T)` (Mathlib's `Real.tendsto_one_add_div_pow_exp`). + +`eq_mul_pow_of_succ` is the closed form of the recurrence `I (n + 1) = I n · c` that every +per-period accrual index satisfies. The DeFi protocol modules (`Markets/DeFi/Compound`, +`Markets/DeFi/Dai`, `Markets/DeFi/Aave`) instantiate these lemmas for their accrual indices. + +## Main results + +* `eq_mul_pow_of_succ`: if `I (n + 1) = I n · c` for every `n`, then `I n = I 0 · c ^ n`. +* `one_add_pow_mul_zcb_log`: for `y > −1`, `(1 + y) ^ n · zcb (log (1 + y)) 0 n = 1`, so periodic + compounding at `y` is continuous compounding at the rate `log (1 + y)`. +* `one_add_mul_pow_le_inv_zcb`: for `r t ≥ −1`, `(1 + r t) ^ n ≤ (zcb r 0 (n t))⁻¹`. +* `tendsto_one_add_div_pow_inv_zcb`: `(1 + r T / n) ^ n` tends to `(zcb r 0 T)⁻¹ = exp (r T)` as + `n → ∞`. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], §4.2 (measuring interest rates; + continuous compounding and the conversion between compounding frequencies). + +## Tags + +compound interest, continuous compounding, periodic compounding, effective rate, zero-coupon bond, +exponential limit, MSC 91G30, JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +open Filter Topology + +/-- **The closed form of a per-period accrual index**: if `I (n + 1) = I n · c` for every `n`, +then `I n = I 0 · c ^ n`. -/ +theorem eq_mul_pow_of_succ {I : ℕ → ℝ} {c : ℝ} (h : ∀ n, I (n + 1) = I n * c) : + ∀ n, I n = I 0 * c ^ n + | 0 => by simp + | n + 1 => by rw [h n, eq_mul_pow_of_succ h n, pow_succ, mul_assoc] + +/-- **Per-period compounding is continuous compounding at the equivalent rate.** With time +measured in periods, compounding at `y > −1` per period for `n` periods and then discounting by +the zero-coupon bond at the continuously compounded rate `log (1 + y)` returns exactly one: +`(1 + y) ^ n · zcb (log (1 + y)) 0 n = 1`. -/ +theorem one_add_pow_mul_zcb_log {y : ℝ} (hy : -1 < y) (n : ℕ) : + (1 + y) ^ n * zcb (Real.log (1 + y)) 0 n = 1 := by + rw [zcb, ← Real.exp_log (pow_pos (by linarith : (0 : ℝ) < 1 + y) n), Real.log_pow, + ← Real.exp_add, Real.exp_eq_one_iff] + ring + +/-- **Periodic compounding never out-accrues continuous compounding at the same rate.** For +`n` periods of length `t` at the nominal rate `r` (with `r t ≥ −1`), +`(1 + r t) ^ n ≤ 1 / zcb r 0 (n t) = exp (r · n t)`, since `1 + x ≤ exp x`. -/ +theorem one_add_mul_pow_le_inv_zcb {r t : ℝ} (h : -1 ≤ r * t) (n : ℕ) : + (1 + r * t) ^ n ≤ (zcb r 0 (n * t))⁻¹ := by + rw [zcb, sub_zero, ← Real.exp_neg, neg_neg, show r * (n * t) = n * (r * t) by ring, + Real.exp_nat_mul] + exact pow_le_pow_left₀ (by linarith) (by linarith [Real.add_one_le_exp (r * t)]) n + +/-- **Continuous compounding is the limit of periodic compounding.** Splitting the horizon `T` +into `n` equal periods at the nominal rate `r`, the accrual factor `(1 + r T / n) ^ n` tends to +`1 / zcb r 0 T = exp (r T)`. -/ +theorem tendsto_one_add_div_pow_inv_zcb (r T : ℝ) : + Tendsto (fun n : ℕ ↦ (1 + r * T / n) ^ n) atTop (𝓝 (zcb r 0 T)⁻¹) := by + rw [zcb, sub_zero, ← Real.exp_neg, neg_neg] + exact Real.tendsto_one_add_div_pow_exp (r * T) + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/ShortRate.lean b/LeanPool/MathFin/Models/Rates/ShortRate.lean new file mode 100644 index 0000000000..65e03949a6 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/ShortRate.lean @@ -0,0 +1,150 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.Value +public import LeanPool.MathFin.Models.Rates.HullWhiteCalibration +public import LeanPool.MathFin.Models.Rates.GSRPiecewiseVol + +/-! +# Stochastic discounting, and contracts in the Gaussian short-rate models + +In a short-rate model the discount factor is a random variable at each time, +`D t = exp(−∫₀ᵗ r_s ds)` (`shortRateDiscount`), and `Contract.value Q D X c` values a contract +along each outcome by that outcome's discount path. + +A schedule of fixed cash flows sees only the model's zero curve `P(0, t) = 𝔼_Q[D t]` +(`zeroCurve`, `Pricing/Value.lean`): its value under the stochastic discount factor is its value +on that curve (`value_fixedFlows_eq_zeroCurve`), given each `D tᵢ` integrable. The Gaussian +short-rate models give the curve in closed form, and the integrability comes with it, since a +function whose integral is nonzero is integrable (`value_fixedFlows_of_zeroCurve_eq`). So a +coupon bond is worth `∑ cᵢ P(0, tᵢ)` with + +* Vasicek: `P(0, t) = A(t) e^{−B(t) r₀}` (`value_fixedFlows_vasicek`, from + `vasicekBondPrice_affine`); +* Hull–White with continuous forcing `θ`: the same `B`, and `A` carrying `θ` + (`value_fixedFlows_hullWhite`, from `HullWhite.bondPrice_affine`); +* two-piece GSR, for payment dates after the volatility switch `T*`: + `P(0, t) = exp(−M(t) + V(t)/2)` with the GSR variance (`value_fixedFlows_gsr`, from + `gsrBondPrice_eq`). + +In each, the measure is read as the pricing measure: no change of measure is built, as in the +bond-price theorems the instances consume. Contracts whose cash flows depend on the rate, such as +a floating leg paying the rate it observes, are not covered by these closed forms: valuing one +needs the bond prices `P(t, T)` at `t > 0`, the conditional expectation `bondPrice` +(`Models/Rates/Caplet.lean`). For the Vasicek, Hull–White and two-piece GSR models they are in +closed form (`bondPrice_vasicek`, `bondPrice_hullWhite`, `bondPrice_gsr`, +`Models/Rates/VasicekBond.lean`, `Models/Rates/HullWhiteBond.lean`, +`Models/Rates/GSRBond.lean`), and the bond put and caplet follow +(`Models/Rates/Jamshidian.lean`). + +## Main definitions + +* `shortRateDiscount` — `D t = exp(−R t)` from an integrated short rate `R`. + +## Main results + +* `value_fixedFlows_vasicek`, `value_fixedFlows_hullWhite`, `value_fixedFlows_gsr`. + +## Source + +The layered separation of contract semantics from pricing semantics, and the +framing "the contract is not the model", are due to Paul Bilokon, +*The Contract Is Not the Model: Proof-Carrying Exotic Derivatives and the +Economics of Model Risk* (working paper, 9 August 2026; Mathematical +Finance, Imperial College London), with code at + (Apache-2.0). That paper in +turn builds on the compositional contract-DSL of +Peyton Jones, Eber and Seward (2000) and the certified-contract work of Bahr, +Berthold and Elsman (2015) and Annenkov (2018). + +No code is copied from `lean_contracts`; every definition and proof here is +written for this library. See `docs/specs/2026-08-16-contracts-tower-design.md` +§6 for the full credit line. + +## References + +* [Andersen and Piterbarg, *Interest Rate Modeling*][AndersenPiterbarg2010], ch. 10 +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + sec. 1.2; sec. 3.2.1; sec. 3.3 +* [J. Hull and A. White, *Pricing interest-rate-derivative securities*][HullWhite1990] +* [O. Vasicek, *An equilibrium characterization of the term structure*][Vasicek1977] + +## Tags + +stochastic discount factor, zero curve, coupon bond pricing, Vasicek model, Hull–White model, +Gaussian short rate, contract valuation, MSC 91G30, MSC 91G20, JEL E43 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory +open scoped NNReal + +namespace MathFin.Contracts + +variable {ι Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-! ### Short-rate discounting -/ + +/-- The discount factor of a short-rate model, `D t = exp(−R t)`, from its integrated short rate +`R t = ∫₀ᵗ r_s ds`. -/ +noncomputable def shortRateDiscount (R : ℝ≥0 → Ω → ℝ) : ℝ≥0 → Ω → ℝ := + fun t ω ↦ Real.exp (-R t ω) + +/-! ### The Gaussian short-rate models -/ + +variable {μ : Measure Ω} [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} + +/-- **A coupon bond in the Vasicek model**: discounted by `exp(−∫₀ᵗ r)` along the Vasicek short +rate from `r₀`, the schedule paying `cᵢ` at `tᵢ` is worth `∑ A(tᵢ) e^{−B(tᵢ) r₀} cᵢ`, the +affine bond prices of `vasicekBondPrice_affine`, with `μ` read as the pricing measure. -/ +theorem value_fixedFlows_vasicek (hB : IsPreBrownianReal B μ) (r₀ θ σ : ℝ) {κ : ℝ} + (hκ : 0 < κ) (X : ι → ℝ≥0 → Ω → ℝ) (t : ℕ → ℝ≥0) (c : ℕ → ℝ) (n : ℕ) : + (fixedFlows t c n : Contract ι).value μ + (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) X + = ∑ i ∈ Finset.range n, + vasicekBondA θ σ κ (t i) * Real.exp (-(vasicekBondB κ (t i) * r₀)) * c i := + value_fixedFlows_of_zeroCurve_eq (P := fun s ↦ + vasicekBondA θ σ κ s * Real.exp (-(vasicekBondB κ s * r₀))) X t c n + (fun i _ ↦ vasicekBondPrice_affine hB r₀ θ σ hκ (t i)) + fun _ _ ↦ (mul_pos (Real.exp_pos _) (Real.exp_pos _)).ne' + +/-- **A coupon bond in the Hull–White model**: for continuous forcing `θ`, the schedule paying +`cᵢ` at `tᵢ` is worth `∑ A(tᵢ) e^{−B(tᵢ) r₀} cᵢ`, with Vasicek's `B` and `A = HullWhite.bondA` +carrying `θ` (`HullWhite.bondPrice_affine`), with `μ` read as the pricing measure. -/ +theorem value_fixedFlows_hullWhite (hB : IsPreBrownianReal B μ) {θ : ℝ → ℝ} + (hθ : Continuous θ) (κ σ r₀ : ℝ) (hκ : 0 < κ) (X : ι → ℝ≥0 → Ω → ℝ) (t : ℕ → ℝ≥0) + (c : ℕ → ℝ) (n : ℕ) : + (fixedFlows t c n : Contract ι).value μ + (shortRateDiscount (HullWhite.bondRate hB θ κ σ r₀ hκ)) X + = ∑ i ∈ Finset.range n, + HullWhite.bondA θ σ κ (t i) * Real.exp (-(vasicekBondB κ (t i) * r₀)) * c i := + value_fixedFlows_of_zeroCurve_eq (P := fun s ↦ + HullWhite.bondA θ σ κ s * Real.exp (-(vasicekBondB κ s * r₀))) X t c n + (fun i _ ↦ HullWhite.bondPrice_affine hB θ κ σ r₀ hθ hκ (t i)) + fun _ _ ↦ (mul_pos (Real.exp_pos _) (Real.exp_pos _)).ne' + +/-- **A coupon bond in the two-piece GSR model**: with volatility `σ₁` before `T*` and `σ₂` +after, the schedule paying `cᵢ` at dates `tᵢ ≥ T*` is worth `∑ exp(−M(tᵢ) + V(tᵢ)/2) cᵢ`, with +`M` the Vasicek integrated mean and `V = gsrBondV` (`gsrBondPrice_eq`), with `μ` read as the +pricing measure. -/ +theorem value_fixedFlows_gsr (hB : IsPreBrownianReal B μ) (r₀ θ σ1 σ2 : ℝ) {κ : ℝ} + (hκ : 0 < κ) (Tstar : ℝ≥0) (X : ι → ℝ≥0 → Ω → ℝ) (t : ℕ → ℝ≥0) (c : ℕ → ℝ) (n : ℕ) + (ht : ∀ i < n, Tstar ≤ t i) : + (fixedFlows t c n : Contract ι).value μ + (shortRateDiscount (gsrIntegratedRate hB r₀ θ σ1 σ2 hκ Tstar)) X + = ∑ i ∈ Finset.range n, Real.exp (-(vasicekIntegratedMean r₀ θ κ (t i)) + + gsrBondV κ σ1 σ2 (Tstar : ℝ) (t i) / 2) * c i := + value_fixedFlows_of_zeroCurve_eq (P := fun s ↦ Real.exp (-(vasicekIntegratedMean r₀ θ κ s) + + gsrBondV κ σ1 σ2 (Tstar : ℝ) s / 2)) X t c n + (fun i hi ↦ gsrBondPrice_eq hB r₀ θ σ1 σ2 hκ Tstar (t i) (ht i hi)) + fun _ _ ↦ (Real.exp_pos _).ne' + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Models/Rates/TimingAdjustment.lean b/LeanPool/MathFin/Models/Rates/TimingAdjustment.lean new file mode 100644 index 0000000000..7a605763e8 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/TimingAdjustment.lean @@ -0,0 +1,317 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.BrownianMartingale +public import LeanPool.MathFin.Pricing.ForwardMeasure +public import LeanPool.MathFin.Pricing.WienerIntegralForwardMeasure +public import LeanPool.MathFin.Models.Rates.HullWhiteCalibration + +/-! +# The covariance-between-numéraires identity: timing adjustment and futures-forward basis + +Two textbook corrections are the same identity. Let `Q^N` be the measure attached to a +numéraire whose relative weight against the reference numéraire is `e^{−Y}`. For a payoff +`V` with `(ln V, Y)` jointly Gaussian in the two-driver form below, + + `𝔼^{Q^N}[V] = 𝔼^Q[V] · exp(−Cov(ln V, Y))`. + +The static step is `changeOfNumeraire` (`Pricing/Numeraire`): `𝔼^{Q^N}[V]` is +`𝔼^Q[V·e^{−Y}] / 𝔼^Q[e^{−Y}]`. The Gaussian step is the log-normal covariance identity +`𝔼[V·e^{−Y}] = 𝔼[V]·𝔼[e^{−Y}]·exp(−Cov(ln V, Y))`, proved here from the independent-driver +decomposition `Y = n + u(ρ Z₁ + √(1−ρ²) Z₂)`, `ln V = m + s Z₁`, so `Cov(ln V, Y) = ρ s u`. + +* **Hull's timing adjustment** (Hull, *Options, Futures, and Other Derivatives*, the chapter + on convexity, timing and quanto adjustments; the exact lognormal identity underlying its + timing-adjustment formula): `Q` is the `T`-forward measure, `Q^N` the + `T*`-forward measure, and `e^{−Y} = P(T,T*)`. A payoff fixed at `T` and paid at `T*` has + `𝔼^{T*}[V] = 𝔼^T[V]·exp(−Cov(ln V, Y))`. +* **Bagaria's futures-forward basis** (Bagaria, §8.4, the unnumbered covariance identity + preceding Worked case 8.5 — not the Ho–Lee basis approximation of eq. 8.9): `Q` is the + risk-neutral measure, `Q^N` the `T`-forward measure, and `e^{Y}` the bank account + `exp(∫₀ᵀ r)`. The futures price `𝔼^Q[V]` is the forward price `𝔼^T[V]` times + `exp(Cov(ln V, ∫₀ᵀ r))`. + +**Exact vs. linearized.** Both statements here are exact under the Gaussian hypothesis. +Hull's textbook presentation of the timing adjustment, with a `(1 + R_F/m)`-style +simple-compounding denominator, replaces the exact covariance `Cov(ln V, Y)` with its +first-order (bond-duration) approximation in the forward rate. That approximate form is +not proved here and is not exact. + +**What the measures are.** In the two-driver theorems, `Q` is any measure `μ` carrying the two +independent standard normals, `Q^N` is `numeraireMeasure` with the stated normalisation, and `Y` +is the Gaussian variable `n + u(ρ Z₁ + √(1−ρ²) Z₂)`. "Risk-neutral", "`T`-forward", "bank +account `exp(∫₀ᵀ r)`" and "`P(T,T*)`" are readings of these; those theorems model no short rate +or bond. That the futures price is `𝔼^Q[V]` and the forward price is `𝔼^T[V]` are textbook +identifications, not proved here. + +**The Hull–White instance.** The numéraire step does not depend on the two-driver form: +`futuresForwardBasis_of_integral_mul_exp_neg` (`Pricing/ForwardMeasure`) takes the covariance +identity as a hypothesis. `futuresForwardBasis_gaussian` is its two-driver instance. The last +section supplies a second instance in which the short rate and the bond are modelled: the +Hull–White short rate `r_S` and +bank account `exp(∫₀ˢ r)` of `Models/Rates/HullWhiteCalibration`, in their Wiener representations +(that they solve the SDE, and the time-order swap, are cited, not proved there). The covariance +identity is now `integral_exp_mul_exp_neg_wienerIntegralLp`, with +`Cov(r_S, ∫₀ˢ r) = σ²⟪e^{−κ(S−·)}, g⟫ = σ²B(S)²/2`. The `S`-forward measure +is `forwardMeasure μ (exp ∘ bondRate)` — the library's one +`T`-forward measure (`Pricing/ForwardMeasure`) at the bank account `exp(∫₀ˢ r)`; the law of a +Wiener-represented rate under it is `hasLaw_forwardMeasure_wienerIntegralLp` +(`Pricing/WienerIntegralForwardMeasure`). +Under it `r_S ~ N(α(S) − σ²B(S)²/2, var)` (`HullWhite.shortRate_hasLaw_forwardMeasure`), so the +futures–forward gap of the short rate is `𝔼[r_S] − 𝔼^S[r_S] = σ²B(S)²/2` +(`HullWhite.integral_shortRate_sub_forwardMeasure`). For the curve-calibrated model +`𝔼^S[r_S] = f(0, S)` (`HullWhite.forwardMeasure_shortRate_mean_eq_forwardCurve`). These are +statements about the instantaneous short rate `r_S`, not about a futures contract on a term rate. + +## Main results + +* `integral_mul_exp_neg_gaussian` — `𝔼[V·e^{−Y}] = 𝔼[V]·𝔼[e^{−Y}]·exp(−ρ s u)`. +* `timingAdjustment_gaussian` — the exact lognormal identity underlying Hull's timing + adjustment. +* `futuresForwardBasis_gaussian` — Bagaria §8.4's covariance identity, exact Gaussian form. +* `HullWhite.shortRate_hasLaw_forwardMeasure`, `HullWhite.integral_shortRate_sub_forwardMeasure`, + `HullWhite.forwardMeasure_shortRate_mean_eq_forwardCurve` — the Hull–White `S`-forward measure, + the law of `r_S` under it (an instance of `hasLaw_forwardMeasure_wienerIntegralLp`), the + futures–forward gap of the short rate, and the forward curve as the `S`-forward mean of the + calibrated short rate. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull] (the chapter on convexity, + timing and quanto adjustments). +* [S. Bagaria, *Notes on Fixed Income Derivative Pricing*][BagariaFIDP], ch. 8. +* [H. Geman, N. El Karoui, J.-C. Rochet, *Changes of numéraire, changes of probability measure and + option pricing*][GemanElKarouiRochet1995] (the forward measure; `𝔼^T[r_T] = f(0,T)`). +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + §3.3 + +## Tags + +timing adjustment, futures–forward basis, convexity adjustment, change of numéraire, +forward measure, lognormal covariance, Hull–White, MSC 91G30, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + +/-- **The log-normal covariance identity.** With `ln V = m + s Z₁` and +`Y = n + u(ρ Z₁ + √(1−ρ²) Z₂)` for independent standard normals `Z₁, Z₂` (so +`Cov(ln V, Y) = ρ s u`). No bound on `ρ` is assumed: `√(1−ρ²)` enters the proof only through +its square, which cancels identically between the two sides, so the identity holds verbatim +even for `|ρ| > 1` (where `Real.sqrt` returns its junk value `0`). + + `𝔼[V·e^{−Y}] = 𝔼[V] · 𝔼[e^{−Y}] · exp(−ρ s u)`. -/ +theorem integral_mul_exp_neg_gaussian (m s n u ρ : ℝ) + {Z₁ Z₂ : Ω → ℝ} + (h₁ : HasLaw Z₁ (gaussianReal 0 1) μ) (h₂ : HasLaw Z₂ (gaussianReal 0 1) μ) + (hm₁ : Measurable Z₁) (hm₂ : Measurable Z₂) (hindep : IndepFun Z₁ Z₂ μ) : + ∫ ω, Real.exp (m + s * Z₁ ω) + * Real.exp (-(n + u * (ρ * Z₁ ω + Real.sqrt (1 - ρ ^ 2) * Z₂ ω))) ∂μ + = (∫ ω, Real.exp (m + s * Z₁ ω) ∂μ) + * (∫ ω, Real.exp (-(n + u * (ρ * Z₁ ω + Real.sqrt (1 - ρ ^ 2) * Z₂ ω))) ∂μ) + * Real.exp (-(ρ * s * u)) := by + set r := Real.sqrt (1 - ρ ^ 2) + have eL : (fun ω ↦ Real.exp (m + s * Z₁ ω) * Real.exp (-(n + u * (ρ * Z₁ ω + r * Z₂ ω)))) + = fun ω ↦ Real.exp ((m - n) + (s - u * ρ) * Z₁ ω + (-(u * r)) * Z₂ ω) := by + funext ω; rw [← Real.exp_add]; congr 1; ring + have eV : (fun ω ↦ Real.exp (m + s * Z₁ ω)) + = fun ω ↦ Real.exp (m + s * Z₁ ω + 0 * Z₂ ω) := by + funext ω; simp + have eP : (fun ω ↦ Real.exp (-(n + u * (ρ * Z₁ ω + r * Z₂ ω)))) + = fun ω ↦ Real.exp (-n + (-(u * ρ)) * Z₁ ω + (-(u * r)) * Z₂ ω) := by + funext ω; congr 1; ring + rw [eL, eV, eP, integral_exp_affine_indep h₁ h₂ hm₁ hm₂ hindep, + integral_exp_affine_indep h₁ h₂ hm₁ hm₂ hindep, integral_exp_affine_indep h₁ h₂ hm₁ hm₂ hindep, + ← Real.exp_add, ← Real.exp_add] + congr 1 + ring + +/-- **Hull's timing adjustment** (the exact lognormal identity underlying Hull's formula). +Let `Q` be the +`T`-forward measure (reference numéraire `P(·,T)`, worth `1` at `T` and `B₀ = P(0,T)` today), +and let the `T*`-bond be worth `P(T,T*) = e^{−Y}` at `T` and `N₀ = P(0,T*)` today, with the +no-arbitrage normalization `N₀ = B₀·𝔼^T[P(T,T*)]` (hypothesis `hnorm`). These are readings +of `μ` and the two numéraires (see the module note). For a payoff `V` fixed at `T` and paid +at `T*`, with `ln V = m + s Z₁` and `Y = n + u(ρ Z₁ + √(1−ρ²) Z₂)` as in +`integral_mul_exp_neg_gaussian` (so `Cov(ln V, Y) = ρ s u`), the `T*`-forward expectation is + + `𝔼^{T*}[V] = 𝔼^T[V] · exp(−ρ s u)`. + +This is exact; the textbook `(1 + R_F/m)`-style simple-compounding form replaces the exact +`Cov(ln V, Y)` with a first-order (bond-duration) approximation, not proved here. -/ +theorem timingAdjustment_gaussian (m s n u ρ B₀ N₀ : ℝ) + (hB₀ : 0 ≤ B₀) (hN₀ : 0 < N₀) + {Z₁ Z₂ : Ω → ℝ} + (h₁ : HasLaw Z₁ (gaussianReal 0 1) μ) (h₂ : HasLaw Z₂ (gaussianReal 0 1) μ) + (hm₁ : Measurable Z₁) (hm₂ : Measurable Z₂) (hindep : IndepFun Z₁ Z₂ μ) + (hnorm : N₀ = B₀ * + ∫ ω, Real.exp (-(n + u * (ρ * Z₁ ω + Real.sqrt (1 - ρ ^ 2) * Z₂ ω))) ∂μ) : + ∫ ω, Real.exp (m + s * Z₁ ω) ∂(numeraireMeasure μ (fun _ ↦ 1) + (fun ω ↦ Real.exp (-(n + u * (ρ * Z₁ ω + Real.sqrt (1 - ρ ^ 2) * Z₂ ω)))) B₀ N₀) + = (∫ ω, Real.exp (m + s * Z₁ ω) ∂μ) * Real.exp (-(ρ * s * u)) := by + subst hnorm + set P : Ω → ℝ := fun ω ↦ Real.exp (-(n + u * (ρ * Z₁ ω + Real.sqrt (1 - ρ ^ 2) * Z₂ ω))) + set V : Ω → ℝ := fun ω ↦ Real.exp (m + s * Z₁ ω) + have hPm : Measurable P := by fun_prop + have h := changeOfNumeraire (Q := μ) (fun ω ↦ V ω * P ω) hPm measurable_const + (fun ω ↦ Real.exp_pos _) (fun _ ↦ one_pos) hB₀ hN₀ + have hc : (fun ω ↦ V ω * P ω / P ω) = V := by + funext ω; exact mul_div_cancel_right₀ _ (Real.exp_pos _).ne' + simp only [hc, div_one] at h + have hcore := integral_mul_exp_neg_gaussian (μ := μ) m s n u ρ h₁ h₂ hm₁ hm₂ hindep + change ∫ ω, V ω * P ω ∂μ = (∫ ω, V ω ∂μ) * (∫ ω, P ω ∂μ) * _ at hcore + rw [hcore] at h + exact mul_left_cancel₀ hN₀.ne' (h.trans (by ring)) + +/-- **Bagaria's futures-forward basis** (Bagaria, §8.4, the unnumbered covariance identity +preceding Worked case 8.5 — not the Ho–Lee basis approximation of eq. 8.9), exact Gaussian +form. Read `μ` as the risk-neutral measure `Q` with bank account `e^{Y}`, `Y = ∫₀ᵀ r`, and pass +to the `T`-forward measure (numéraire `P(·,T)`, worth `1` at `T` and +`P(0,T) = 𝔼^Q[e^{−Y}]` today, positive by `hN₀`). These are readings: `μ` is any +measure carrying `Z₁, Z₂`, and this theorem models no short rate (see the module note). For an +underlying `V` with `ln V = m + s Z₁` and `Y = n + u(ρ Z₁ + √(1−ρ²) Z₂)` as in +`integral_mul_exp_neg_gaussian` (so `Cov(ln V, Y) = ρ s u`), the textbook futures price +`𝔼^Q[V]` and forward price `𝔼^T[V]` satisfy + + `𝔼^Q[V] = 𝔼^T[V] · exp(ρ s u)`. + +The two-driver instance of `futuresForwardBasis_of_integral_mul_exp_neg`. -/ +theorem futuresForwardBasis_gaussian (m s n u ρ : ℝ) + {Z₁ Z₂ : Ω → ℝ} + (h₁ : HasLaw Z₁ (gaussianReal 0 1) μ) (h₂ : HasLaw Z₂ (gaussianReal 0 1) μ) + (hm₁ : Measurable Z₁) (hm₂ : Measurable Z₂) (hindep : IndepFun Z₁ Z₂ μ) + (hN₀ : 0 < + ∫ ω, Real.exp (-(n + u * (ρ * Z₁ ω + Real.sqrt (1 - ρ ^ 2) * Z₂ ω))) ∂μ) : + ∫ ω, Real.exp (m + s * Z₁ ω) ∂μ + = (∫ ω, Real.exp (m + s * Z₁ ω) ∂(forwardMeasure μ + fun ω ↦ Real.exp (n + u * (ρ * Z₁ ω + Real.sqrt (1 - ρ ^ 2) * Z₂ ω)))) + * Real.exp (ρ * s * u) := + futuresForwardBasis_of_integral_mul_exp_neg (ρ * s * u) (by fun_prop) hN₀ + (integral_mul_exp_neg_gaussian m s n u ρ h₁ h₂ hm₁ hm₂ hindep) + +/-! ## The Hull–White instance: the `S`-forward measure and the short rate + +`r_S = α(S) + σ∫₀ˢ e^{−κ(S−u)} dB_u` (`HullWhite.integratedRate`) and +`∫₀ˢ r = ∫₀ˢ α + σ∫₀ˢ g dB` (`HullWhite.bondRate`) are both Wiener integrals against the same `B`, +so their covariance is `σ²⟪e^{−κ(S−·)}, g⟫ = σ²B(S)²/2`. -/ + +namespace HullWhite + +open WienerIntegralL2 +open scoped NNReal InnerProductSpace + +/-- `∫₀ˢ e^{−κ(S−u)}·g(u) du = B(S)²/2` (`κ ≠ 0`), by the FTC with antiderivative +`e^{−κ(S−u)}/κ² − e^{−κ(S−u)}²/(2κ²)`. -/ +lemma integral_vasicekKernel_mul_vasicekIntegratedKernel (κ S : ℝ) (hκ : κ ≠ 0) : + ∫ u in (0 : ℝ)..S, vasicekKernel κ S u * vasicekIntegratedKernel κ S u + = vasicekBondB κ S ^ 2 / 2 := by + have hderiv (u : ℝ) : HasDerivAt + (fun u : ℝ ↦ Real.exp (-(κ * (S - u))) / κ ^ 2 + - Real.exp (-(κ * (S - u))) * Real.exp (-(κ * (S - u))) / (2 * κ ^ 2)) + (vasicekKernel κ S u * vasicekIntegratedKernel κ S u) u := by + have harg : HasDerivAt (fun u ↦ -(κ * (S - u))) κ u := by + have h : HasDerivAt (fun u ↦ -(κ * (S - u))) (-(κ * (-1))) u := by + apply HasDerivAt.neg; apply HasDerivAt.const_mul + simpa using (hasDerivAt_id u).const_sub S + simpa using h + have he := harg.exp + refine ((he.div_const (κ ^ 2)).sub ((he.mul he).div_const (2 * κ ^ 2))).congr_deriv ?_ + simp only [vasicekKernel, vasicekIntegratedKernel] + field_simp + ring + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt (fun u _ ↦ hderiv u) + (by + apply Continuous.intervalIntegrable + simp only [vasicekKernel, vasicekIntegratedKernel] + fun_prop)] + simp only [sub_self, mul_zero, neg_zero, Real.exp_zero, sub_zero, vasicekBondB] + field_simp + ring + +/-- **The covariance of the HW short rate with its integral, per unit `σ²`**: +`⟪e^{−κ(S−·)}, g⟫_{L²((0,S])} = B(S)²/2`. -/ +lemma inner_vasicekKernelLp_vasicekIntegratedKernelLp {κ : ℝ} (hκ : 0 < κ) (S : ℝ≥0) : + ⟪vasicekKernelLp κ hκ.le S, vasicekIntegratedKernelLp hκ S⟫_ℝ = vasicekBondB κ S ^ 2 / 2 := by + rw [L2.inner_def, ← integral_vasicekKernel_mul_vasicekIntegratedKernel κ S hκ.ne', + intervalIntegral.integral_of_le S.coe_nonneg] + refine integral_congr_ae ?_ + filter_upwards [(vasicekKernel_memLp κ hκ.le S).coeFn_toLp, + (vasicekIntegratedKernel_memLp hκ S).coeFn_toLp] with u h₁ h₂ + simp only [vasicekKernelLp, vasicekIntegratedKernelLp, RCLike.inner_apply, conj_trivial, h₁, h₂] + ring + +variable [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} + +/-- **The law of the Hull–White short rate under the `S`-forward measure**: + + `r_S ~ N(α(S) − σ²B(S)²/2, σ²(1 − e^{−2κS})/(2κ))` under `Q^S`. + +Under `μ` the law is `N(α(S), var)` (`integratedRate_hasLaw_gaussian`); the change to the +`S`-forward measure shifts the mean by `−Cov(r_S, ∫₀ˢ r) = −σ²B(S)²/2` and keeps the variance +(`hasLaw_forwardMeasure_wienerIntegralLp`, with `Cov = σ²⟪e^{−κ(S−·)}, g⟫`). -/ +theorem shortRate_hasLaw_forwardMeasure (hB : IsPreBrownianReal B μ) (θ : ℝ → ℝ) + (κ σ r₀ : ℝ) (hκ : 0 < κ) (S : ℝ≥0) : + HasLaw (integratedRate hB θ κ σ r₀ hκ S) + (gaussianReal (deterministic θ κ r₀ S - σ ^ 2 * vasicekBondB κ S ^ 2 / 2) + (vasicekSDEVariance σ κ S).toNNReal) + (forwardMeasure μ fun ω ↦ Real.exp (bondRate hB θ κ σ r₀ hκ S ω)) := by + have h := hasLaw_forwardMeasure_wienerIntegralLp hB S (deterministic θ κ r₀ S) + (integratedMean θ κ r₀ S) σ σ (deterministic θ κ r₀ S) (vasicekKernelLp κ hκ.le S) + (vasicekIntegratedKernelLp hκ S) (integratedRate_hasLaw_gaussian hB θ κ σ r₀ hκ S) + rwa [inner_vasicekKernelLp_vasicekIntegratedKernelLp hκ S, + show σ * σ * (vasicekBondB κ S ^ 2 / 2) = σ ^ 2 * vasicekBondB κ S ^ 2 / 2 by ring] at h + +/-- **The `S`-forward mean of the Hull–White short rate**: +`𝔼^S[r_S] = α(S) − σ²B(S)²/2`. -/ +theorem integral_shortRate_forwardMeasure (hB : IsPreBrownianReal B μ) (θ : ℝ → ℝ) + (κ σ r₀ : ℝ) (hκ : 0 < κ) (S : ℝ≥0) : + ∫ ω, integratedRate hB θ κ σ r₀ hκ S ω + ∂(forwardMeasure μ fun ω ↦ Real.exp (bondRate hB θ κ σ r₀ hκ S ω)) + = deterministic θ κ r₀ S - σ ^ 2 * vasicekBondB κ S ^ 2 / 2 := by + rw [(shortRate_hasLaw_forwardMeasure hB θ κ σ r₀ hκ S).integral_eq, integral_id_gaussianReal] + +/-- **The futures–forward gap of the Hull–White short rate**: + + `𝔼[r_S] − 𝔼^S[r_S] = σ²B(S)²/2 = (σ²/2κ²)(1 − e^{−κS})²`, + +the mean of `r_S` under the measure `μ` carrying the driver minus its mean under the `S`-forward +measure. It holds for every deterministic forcing `θ`. -/ +theorem integral_shortRate_sub_forwardMeasure (hB : IsPreBrownianReal B μ) (θ : ℝ → ℝ) + (κ σ r₀ : ℝ) (hκ : 0 < κ) (S : ℝ≥0) : + ∫ ω, integratedRate hB θ κ σ r₀ hκ S ω ∂μ + - ∫ ω, integratedRate hB θ κ σ r₀ hκ S ω + ∂(forwardMeasure μ fun ω ↦ Real.exp (bondRate hB θ κ σ r₀ hκ S ω)) + = σ ^ 2 * vasicekBondB κ S ^ 2 / 2 := by + rw [integral_shortRate_forwardMeasure, + (integratedRate_hasLaw_gaussian hB θ κ σ r₀ hκ S).integral_eq, integral_id_gaussianReal] + ring + +/-- **The forward curve is the `S`-forward mean of the calibrated short rate**: with the +calibrated forcing `θ = theta f0 κ σ`, the short rate started at `f(0,0)`, `f0 ∈ C¹` and `κ > 0`, + + `𝔼^S[r_S] = f(0, S)`. + +The calibrated deterministic part is `f(0,S) + σ²B(S)²/2` (`calibMean`), and the forward measure +removes exactly `σ²B(S)²/2` (`integral_shortRate_forwardMeasure`). -/ +theorem forwardMeasure_shortRate_mean_eq_forwardCurve (hB : IsPreBrownianReal B μ) + (f0 : ℝ → ℝ) (hf0 : ContDiff ℝ 1 f0) (κ σ : ℝ) (hκ : 0 < κ) (S : ℝ≥0) : + ∫ ω, integratedRate hB (theta f0 κ σ) κ σ (f0 0) hκ S ω + ∂(forwardMeasure μ fun ω ↦ Real.exp (bondRate hB (theta f0 κ σ) κ σ (f0 0) hκ S ω)) + = f0 S := by + rw [integral_shortRate_forwardMeasure, calibMean f0 hf0 κ σ hκ S, vasicekBondB] + ring + +end HullWhite + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/Vasicek.lean b/LeanPool/MathFin/Models/Rates/Vasicek.lean new file mode 100644 index 0000000000..046bcb7ff8 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/Vasicek.lean @@ -0,0 +1,137 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.InnerProductSpace.Basic +public import Mathlib.Analysis.SpecialFunctions.ExpDeriv +public import Mathlib.Analysis.SpecialFunctions.Log.Basic +public import Mathlib.Topology.Algebra.Module.ModuleTopology + +/-! +# Vasicek mean-reversion (deterministic part) + +The Vasicek short-rate SDE is `dr_t = κ(θ − r_t) dt + σ dW_t`. With `σ = 0` +the deterministic ODE `dr/dt = κ(θ − r)` has explicit solution + + `r(t) = θ + (r₀ − θ) · e^{−κt}`, + +exhibiting exponential mean reversion to `θ` at rate `κ`. We verify two +properties at the level of real-valued calculus: + +* the closed form satisfies the ODE; +* limiting value `r(∞) = θ` (asymptotic, via positivity of `κ`). + +The full Vasicek model including the stochastic part — the SDE closed-form +`r_t ~ N(r_0 e^{−κt} + θ(1−e^{−κt}), σ²(1−e^{−2κt})/(2κ))` — is *stated* (in the +`BSCallHyp` terminal-distribution style) in `MathFin/Models/Rates/VasicekSDE.lean`. +There the variance `σ²(1−e^{−2κt})/(2κ)` is the L² norm that the simple-process +Itô isometry *would* assign to the deterministic integrand `e^{−κ(t−s)}`; the +SDE→distribution derivation itself is not yet formalized (it is gated on the +continuous Itô integral). This file covers only the deterministic +(mean-reversion ODE) part. + +## The half-life + +The Vasicek/OU mean-reversion has a characteristic *half-life* +`t_{1/2} = log 2 / κ`: the time at which the gap from the mean has closed +to half its initial value. Independent of `r₀` and `θ`; only the rate `κ` +matters. (Folded from the former `MeanReversionHalfLife.lean`.) + +## Main definitions + +* `vasicekDeterministic`: the deterministic short-rate solution `r(t) = θ + (r₀ − θ) e^{−κt}`. +* `meanReversionHalfLife`: the half-life of mean-reverting decay at rate `κ`, the time at which + the gap from the long-run mean is half its initial value. + +## Main results + +* `vasicekDeterministic_at_zero`: `r(0) = r₀`. +* `vasicekDeterministic_solves_ODE`: `dr/dt = κ(θ − r(t))`. +* `vasicekDeterministic_tendsto_mean`: `r(t) → θ` as `t → ∞` (for `κ > 0`). +* `vasicekDeterministic_at_halfLife`: at `t = log 2 / κ`, the gap is half + the initial gap. + +## References + +* [O. Vasicek, *An equilibrium characterization of the term structure*][Vasicek1977] + +## Tags + +Vasicek model, mean reversion, Ornstein–Uhlenbeck, half-life, short rate, long-run mean, MSC 91G30, +JEL E43 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- Vasicek deterministic short-rate solution: `r(t) = θ + (r₀ − θ) e^{−κt}`. -/ +noncomputable def vasicekDeterministic (r₀ θ κ t : ℝ) : ℝ := + θ + (r₀ - θ) * Real.exp (-(κ * t)) + +/-- **Initial condition**: `r(0) = r₀`. -/ +lemma vasicekDeterministic_at_zero (r₀ θ κ : ℝ) : + vasicekDeterministic r₀ θ κ 0 = r₀ := by + unfold vasicekDeterministic + simp + +/-- **Vasicek deterministic ODE solution**: the closed form satisfies +`dr/dt = κ · (θ − r(t))`. -/ +theorem vasicekDeterministic_solves_ODE (r₀ θ κ t : ℝ) : + HasDerivAt (vasicekDeterministic r₀ θ κ) + (κ * (θ - vasicekDeterministic r₀ θ κ t)) t := by + unfold vasicekDeterministic + have h_neg_kt : HasDerivAt (fun t ↦ -(κ * t)) (-κ) t := by + have h_kt : HasDerivAt (fun t : ℝ ↦ κ * t) κ t := by + have := (hasDerivAt_id t).const_mul κ + simpa using this + exact h_kt.neg + have h_exp : HasDerivAt (fun t ↦ Real.exp (-(κ * t))) + (Real.exp (-(κ * t)) * (-κ)) t := h_neg_kt.exp + have h_mul : HasDerivAt (fun t ↦ (r₀ - θ) * Real.exp (-(κ * t))) + ((r₀ - θ) * (Real.exp (-(κ * t)) * (-κ))) t := + h_exp.const_mul (r₀ - θ) + have h := h_mul.const_add θ + convert h using 1; ring + +/-- **Long-run mean reversion**: `r(t) → θ` as `t → ∞`, for `κ > 0`. The gap +`(r₀ − θ) e^{−κt}` decays exponentially: `κt → ∞`, so `e^{−κt} → 0`. -/ +theorem vasicekDeterministic_tendsto_mean (r₀ θ κ : ℝ) (hκ : 0 < κ) : + Filter.Tendsto (vasicekDeterministic r₀ θ κ) Filter.atTop (nhds θ) := by + have h1 : Filter.Tendsto (fun t : ℝ ↦ κ * t) Filter.atTop Filter.atTop := + Filter.Tendsto.const_mul_atTop hκ Filter.tendsto_id + have h2 : Filter.Tendsto (fun t : ℝ ↦ Real.exp (-(κ * t))) + Filter.atTop (nhds 0) := + Real.tendsto_exp_neg_atTop_nhds_zero.comp h1 + unfold vasicekDeterministic + simpa using (h2.const_mul (r₀ - θ)).const_add θ + +/-! ## Half-life (folded from `MeanReversionHalfLife.lean`) -/ + +/-- **Half-life** of mean-reverting decay at rate `κ`: the time at which the +gap from the long-run mean is half its initial value. Depends only on `κ`. -/ +noncomputable def meanReversionHalfLife (κ : ℝ) : ℝ := Real.log 2 / κ + +/-- **At the half-life**, the Vasicek deterministic trajectory has closed +exactly half the gap from `θ`: `r(t₁ₐ) − θ = (r₀ − θ) / 2`. -/ +theorem vasicekDeterministic_at_halfLife (r₀ θ κ : ℝ) (hκ : 0 < κ) : + vasicekDeterministic r₀ θ κ (meanReversionHalfLife κ) - θ = + (r₀ - θ) / 2 := by + unfold vasicekDeterministic meanReversionHalfLife + have hκ_ne : κ ≠ 0 := hκ.ne' + have h_inner : κ * (Real.log 2 / κ) = Real.log 2 := by field_simp + have h_exp : Real.exp (-(κ * (Real.log 2 / κ))) = 1 / 2 := by + rw [h_inner, Real.exp_neg, Real.exp_log (by norm_num : (0:ℝ) < 2)] + norm_num + rw [h_exp] + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/VasicekBond.lean b/LeanPool/MathFin/Models/Rates/VasicekBond.lean new file mode 100644 index 0000000000..c60a0fc5da --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/VasicekBond.lean @@ -0,0 +1,73 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.Caplet +public import LeanPool.MathFin.Models.Rates.HullWhiteBond + +/-! +# Bond prices at `t > 0` in the Vasicek model + +`bondPrice Q 𝓕 D t T = 𝔼_Q[D T | 𝓕 t] / D t` (`Models/Rates/Caplet.lean`) is the price at `t` +of one unit paid at `T`, for any stochastic discount factor `D`. For the Vasicek discount factor +`D t = exp(−∫₀ᵗ r)` and the natural filtration of the driving Brownian motion it is the affine +form of the time-`0` price at the remaining maturity (`bondPrice_vasicek`): + + `P(t, T) = A(T − t)·exp(−B(T − t)·r_t)`. + +It is the Hull–White price (`bondPrice_hullWhite`) at the constant forcing `θ ≡ κθ_v` +(`HullWhite.bondRate_const`, `HullWhite.bondA_const`, `HullWhite.integratedRate_const`). + +## Main results + +* `bondPrice_vasicek` — `bondPrice` in the Vasicek model, almost surely. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + section 3.2.1 +* [O. Vasicek, *An equilibrium characterization of the term structure*][Vasicek1977] + +## Tags + +Vasicek model, bond price, affine term structure, conditional expectation, short rate, +zero-coupon bond, MSC 91G30, JEL E43 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory +open scoped NNReal + +namespace MathFin.Contracts + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-- **The Vasicek bond price at time `t`.** With `D t = exp(−∫₀ᵗ r)` along the Vasicek integrated +rate and `𝓕` the natural filtration of the driving Brownian motion, the price at `t` of one unit +paid at `T` is `P(t, T) = A(T − t)·exp(−B(T − t)·r_t)` almost surely, where `r_t` is the short +rate in its Wiener representation and `A`, `B` are the coefficients of the time-`0` price at the +remaining maturity (`vasicekBondPrice_affine`). The measure is read as the pricing measure. -/ +theorem bondPrice_vasicek (hB : IsPreBrownianReal B μ) (hBm : ∀ s, Measurable (B s)) + (r₀ θ σ : ℝ) {κ : ℝ} (hκ : 0 < κ) {t T : ℝ≥0} (htT : t ≤ T) : + bondPrice μ (Filtration.natural B fun s ↦ (hBm s).stronglyMeasurable) + (shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ)) t T + =ᵐ[μ] fun ω ↦ vasicekBondA θ σ κ ((T - t : ℝ≥0) : ℝ) + * Real.exp (-(vasicekBondB κ ((T - t : ℝ≥0) : ℝ) + * (vasicekSDEMean r₀ θ κ t + vasicekDiffusionTerm hB κ σ hκ.le t ω))) := by + have hD : shortRateDiscount (vasicekIntegratedRate hB r₀ θ σ hκ) + = shortRateDiscount (HullWhite.bondRate hB (fun _ ↦ κ * θ) κ σ r₀ hκ) := by + funext T ω + simp only [shortRateDiscount, HullWhite.bondRate_const] + rw [hD] + filter_upwards [bondPrice_hullWhite hB hBm continuous_const κ σ r₀ hκ htT] with ω h + rw [h, HullWhite.bondA_const θ σ hκ.ne', HullWhite.integratedRate_const] + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Models/Rates/VasicekBondPrice.lean b/LeanPool/MathFin/Models/Rates/VasicekBondPrice.lean new file mode 100644 index 0000000000..6675ca6d19 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/VasicekBondPrice.lean @@ -0,0 +1,336 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho, Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralExpMoment + +/-! +# The Vasicek zero-coupon bond price — the affine term structure + +`Models/Rates/VasicekSDEGaussian.lean` derives the terminal short-rate law +`r_T ~ N(mean, var)` from the Wiener representation of the Ornstein–Uhlenbeck +solution. This file takes the next step in the fixed-income layer: the +**zero-coupon bond price** + + `P(0, T) = 𝔼[exp(−∫₀ᵀ r_s ds)]`, + +under the measure `μ` carrying `B`, read as the risk-neutral present value of one unit paid at +`T` (`vasicekBondPrice_girsanov` builds the change from a real-world `μ`). Under the Vasicek model +the *integrated* short rate is again Gaussian, so the bond price is a Gaussian +Laplace transform and collapses to the classical **affine term structure** + + `P(0, T) = exp(−B(T)·r₀ − θ·(T − B(T)) + σ²·V(T)/2)`, `B(T) = (1 − e^{−κT})/κ`. + +## The integrated short rate, in its Wiener representation + +Integrating the OU solution `r_s = r₀e^{−κs} + θ(1 − e^{−κs}) + σ∫₀ˢ e^{−κ(s−u)}dB_u` +over `s ∈ [0, T]` and swapping the (deterministic-after-integration) time order +`∫₀ᵀ∫₀ˢ e^{−κ(s−u)} ds` sends the diffusion kernel `e^{−κ(s−u)}` to the +**integrated kernel** + + `g(u) = ∫_u^T e^{−κ(s−u)} ds = (1 − e^{−κ(T−u)})/κ`, + +so `∫₀ᵀ r_s ds = M(T) + σ·∫₀ᵀ g(u) dB_u`, with deterministic mean +`M(T) = r₀·B(T) + θ·(T − B(T))`. This is the exact analogue, one integration up, +of the OU-solution model that `VasicekSDEGaussian` already takes as `full`: the +integrated rate is carried in its Wiener representation (the time-order swap is +the modelling bridge, cited, not the conclusion), and everything downstream is +derived. `∫₀ᵀ g(u) dB_u` is the Wiener integral of the *deterministic* integrand +`g`, hence centred Gaussian with variance its `L²`-norm + + `V(T) = ∫₀ᵀ g(u)² du = T/κ² − 2(1 − e^{−κT})/κ³ + (1 − e^{−2κT})/(2κ³)`. + +## Main definitions + +* `vasicekBondB`: the affine coefficient `B(T) = (1 − e^{−κT})/κ`. +* `vasicekIntegratedKernel`, `vasicekIntegratedKernelLp`: the integrated kernel + `g(u) = (1 − e^{−κ(T−u)})/κ`, and the same kernel as an element of `L²((0, T])`. +* `vasicekIntegratedMean`: the deterministic mean of the integrated short rate, + `M(T) = r₀·B(T) + θ·(T − B(T))`. +* `vasicekBondV`: the variance `V(T) = ∫₀ᵀ g²` of the diffusion part of the integrated short rate. +* `vasicekIntegratedKernelSqAntideriv`: the antiderivative of `g(u)²`. +* `vasicekIntegratedRate`: the integrated short rate in its Wiener representation, + `∫₀ᵀ r_s ds = M(T) + σ·∫₀ᵀ g(u) dB_u`. +* `vasicekBondA`: the affine coefficient `A(T) = exp(−θ(T − B(T)) + σ²V(T)/2)`. + +## Main results + +* `vasicekIntegratedKernelSqAntideriv`, `hasDerivAt_vasicekIntegratedKernelSqAntideriv`, + `integral_vasicekIntegratedKernel_sq_eq_sub` — the antiderivative of `g²` and its FTC form + over any interval (also used by `Models/Rates/GSRPiecewiseVol`). +* `vasicekIntegratedKernel_integral_sq` — the variance integral `∫₀ᵀ g² = V(T)`, and + `vasicekIntegratedKernelLp_integral_sq`, the same for the `L²` element. +* `integral_vasicekIntegratedKernel`, `integral_vasicekIntegratedKernelLp` — the kernel's mass + `∫₀ᵀ g = (T − B(T))/κ`, the covariance of `∫₀ᵀ g dB` with `B_T`. +* `vasicekIntegratedRate_hasLaw_gaussian` — `∫₀ᵀ r_s ds ~ N(M(T), σ²V(T))`. +* `vasicekBondPrice_eq` — the bond price `𝔼[exp(−∫₀ᵀ r_s ds)] = exp(−M(T) + σ²V(T)/2)`, the + instance `m = M(T)`, `c = σ`, `f = g` of the Wiener bond-price lemma + `integral_exp_neg_add_mul_wienerIntegralLp` + (`Probability/Brownian/Wiener/WienerIntegralExpMoment`). +* `vasicekBondPrice_affine` — the affine form `P(0,T) = A(T)·exp(−B(T)·r₀)`. + +## References + +* [O. Vasicek, *An equilibrium characterization of the term structure*][Vasicek1977] + +## Tags + +Vasicek model, affine term structure, zero-coupon bond price, integrated short rate, +Wiener integral, Gaussian Laplace transform, MSC 91G30, MSC 60H05, JEL E43 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real Set +open scoped NNReal +open WienerIntegralL2 + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-! ### The affine coefficient `B(T)` and the integrated kernel `g` -/ + +/-- The Vasicek affine coefficient `B(T) = (1 − e^{−κT})/κ` — the sensitivity of +the log bond price to the short rate, and the integral `∫₀ᵀ e^{−κs} ds`. -/ +noncomputable def vasicekBondB (κ T : ℝ) : ℝ := (1 - Real.exp (-(κ * T))) / κ + +/-- `B(τ) = (1 − e^{−κτ})/κ` is positive for `κ, τ > 0`. -/ +theorem vasicekBondB_pos {κ τ : ℝ} (hκ : 0 < κ) (hτ : 0 < τ) : 0 < vasicekBondB κ τ := + div_pos (sub_pos.2 (Real.exp_lt_one_iff.2 (neg_neg_of_pos (mul_pos hκ hτ)))) hκ + +/-- The **integrated Vasicek kernel** `g(u) = (1 − e^{−κ(T−u)})/κ = ∫_u^T e^{−κ(s−u)} ds` +— the deterministic integrand whose Wiener integral is the diffusion part of the +integrated short rate. -/ +noncomputable def vasicekIntegratedKernel (κ T : ℝ) : ℝ → ℝ := + fun u ↦ (1 - Real.exp (-(κ * (T - u)))) / κ + +/-- The deterministic mean of the integrated short rate, +`M(T) = ∫₀ᵀ (r₀e^{−κs} + θ(1 − e^{−κs})) ds = r₀·B(T) + θ·(T − B(T))`. -/ +noncomputable def vasicekIntegratedMean (r₀ θ κ T : ℝ) : ℝ := + r₀ * vasicekBondB κ T + θ * (T - vasicekBondB κ T) + +/-- The integrated mean `M(T)` is nonnegative (`κ > 0`, `v₀, θ, τ ≥ 0`): +`0 ≤ B(τ) ≤ τ`. -/ +theorem vasicekIntegratedMean_nonneg {κ v₀ θ τ : ℝ} (hκ : 0 < κ) (hv : 0 ≤ v₀) (hθ : 0 ≤ θ) + (hτ : 0 ≤ τ) : 0 ≤ vasicekIntegratedMean v₀ θ κ τ := by + have hB0 : 0 ≤ vasicekBondB κ τ := by + rw [vasicekBondB] + refine div_nonneg ?_ hκ.le + have : Real.exp (-(κ * τ)) ≤ 1 := Real.exp_le_one_iff.mpr (by nlinarith) + linarith + have hBτ : vasicekBondB κ τ ≤ τ := by + rw [vasicekBondB, div_le_iff₀ hκ] + have := Real.add_one_le_exp (-(κ * τ)) + nlinarith + rw [vasicekIntegratedMean] + have := mul_nonneg hv hB0 + have := mul_nonneg hθ (sub_nonneg.mpr hBτ) + linarith + +/-- The variance of the integrated short rate's diffusion part (the `L²`-norm of +the integrated kernel `g`): `V(T) = ∫₀ᵀ g² = T/κ² − 2(1−e^{−κT})/κ³ + (1−e^{−2κT})/(2κ³)`. -/ +noncomputable def vasicekBondV (κ T : ℝ) : ℝ := + T / κ ^ 2 - 2 * (1 - Real.exp (-(κ * T))) / κ ^ 3 + + (1 - Real.exp (-(2 * κ * T))) / (2 * κ ^ 3) + +/-! ### The integrated kernel is an `L²` integrand -/ + +/-- The integrated kernel is in `L²((0, T])`: on the support it lies in +`[0, 1/κ]` (for `κ > 0`), hence is bounded. -/ +lemma vasicekIntegratedKernel_memLp {κ : ℝ} (hκ : 0 < κ) (T : ℝ≥0) : + MemLp (vasicekIntegratedKernel κ T) 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := by + refine (memLp_top_of_bound (by unfold vasicekIntegratedKernel; fun_prop) (1 / κ) ?_).mono_exponent + le_top + refine (ae_restrict_iff' measurableSet_Ioc).mpr (ae_of_all _ ?_) + intro s hs + rw [vasicekIntegratedKernel, Real.norm_eq_abs] + have hexp_pos : 0 < Real.exp (-(κ * ((T : ℝ) - s))) := Real.exp_pos _ + have hTs : 0 ≤ (T : ℝ) - s := by linarith [hs.2] + have hexp_le : Real.exp (-(κ * ((T : ℝ) - s))) ≤ 1 := + Real.exp_le_one_iff.mpr (by nlinarith [mul_nonneg hκ.le hTs]) + rw [abs_of_nonneg (div_nonneg (by linarith) hκ.le)] + exact (div_le_div_iff_of_pos_right hκ).mpr (by linarith) + +/-- The integrated kernel as an element of `L²((0, T])`. -/ +noncomputable def vasicekIntegratedKernelLp {κ : ℝ} (hκ : 0 < κ) (T : ℝ≥0) : + Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := + (vasicekIntegratedKernel_memLp hκ T).toLp _ + +/-! ### The variance integral `∫₀ᵀ g² = V(T)` -/ + +/-- The antiderivative `F(u) = u/κ² − 2e^{−κ(T−u)}/κ³ + e^{−2κ(T−u)}/(2κ³)` of the squared +integrated kernel `g(u)²`. -/ +noncomputable def vasicekIntegratedKernelSqAntideriv (κ T u : ℝ) : ℝ := + u / κ ^ 2 - 2 * Real.exp (-(κ * (T - u))) / κ ^ 3 + Real.exp (-(2 * κ * (T - u))) / (2 * κ ^ 3) + +/-- For `κ ≠ 0`, `F` differentiates to `g²`: its derivative expands the square +`g² = (1 − 2e^{−κ(T−u)} + e^{−2κ(T−u)})/κ²`. -/ +lemma hasDerivAt_vasicekIntegratedKernelSqAntideriv (κ T u : ℝ) (hκ : κ ≠ 0) : + HasDerivAt (vasicekIntegratedKernelSqAntideriv κ T) + ((vasicekIntegratedKernel κ T u) ^ 2) u := by + have he : Real.exp (-(2 * κ * (T - u))) + = Real.exp (-(κ * (T - u))) * Real.exp (-(κ * (T - u))) := by + rw [← Real.exp_add]; congr 1; ring + have hlin : HasDerivAt (fun u : ℝ ↦ u / κ ^ 2) (1 / κ ^ 2) u := + (hasDerivAt_id u).div_const (κ ^ 2) + have harg1 : HasDerivAt (fun u ↦ -(κ * (T - u))) κ u := by + have h : HasDerivAt (fun u ↦ -(κ * (T - u))) (-(κ * (-1))) u := by + apply HasDerivAt.neg; apply HasDerivAt.const_mul + simpa using (hasDerivAt_id u).const_sub T + simpa using h + have harg2 : HasDerivAt (fun u ↦ -(2 * κ * (T - u))) (2 * κ) u := by + have h : HasDerivAt (fun u ↦ -(2 * κ * (T - u))) (-(2 * κ * (-1))) u := by + apply HasDerivAt.neg; apply HasDerivAt.const_mul + simpa using (hasDerivAt_id u).const_sub T + simpa using h + have hexp1 := harg1.exp + have hexp2 := harg2.exp + have h2 := (hexp1.const_mul (2 : ℝ)).div_const (κ ^ 3) + have h3 := hexp2.div_const (2 * κ ^ 3) + have hcomb := (hlin.sub h2).add h3 + refine hcomb.congr_deriv ?_ + unfold vasicekIntegratedKernel + rw [he] + field_simp + ring + +/-- The FTC form over any interval, for `κ ≠ 0`: `∫_A^B g(u)² du = F(B) − F(A)`. -/ +lemma integral_vasicekIntegratedKernel_sq_eq_sub (κ T A B : ℝ) (hκ : κ ≠ 0) : + ∫ u in A..B, (vasicekIntegratedKernel κ T u) ^ 2 + = vasicekIntegratedKernelSqAntideriv κ T B - vasicekIntegratedKernelSqAntideriv κ T A := by + apply intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun u _ ↦ hasDerivAt_vasicekIntegratedKernelSqAntideriv κ T u hκ) + apply Continuous.intervalIntegrable + unfold vasicekIntegratedKernel; fun_prop + +/-- **The variance-fixing integral**: `∫₀ᵀ g(u)² du = V(T)`, by the FTC with +antiderivative `vasicekIntegratedKernelSqAntideriv`. -/ +lemma vasicekIntegratedKernel_integral_sq {κ : ℝ} (hκ : κ ≠ 0) (T : ℝ≥0) : + ∫ u in Set.Ioc (0 : ℝ) (T : ℝ), (vasicekIntegratedKernel κ T u) ^ 2 ∂volume + = vasicekBondV κ (T : ℝ) := by + rw [← intervalIntegral.integral_of_le (by positivity : (0 : ℝ) ≤ (T : ℝ)), + integral_vasicekIntegratedKernel_sq_eq_sub κ (T : ℝ) 0 (T : ℝ) hκ] + simp only [vasicekIntegratedKernelSqAntideriv, sub_self, mul_zero, neg_zero, Real.exp_zero, + mul_one, sub_zero, zero_div] + rw [vasicekBondV] + field_simp + ring + +/-! ### The kernel's mass `∫₀ᵀ g = (T − B(T))/κ` -/ + +/-- **The mass of the integrated kernel**: `∫₀ᵀ g(u) du = (T − B(T))/κ`, by the FTC with +antiderivative `u/κ − e^{−κ(T−u)}/κ²` (`κ ≠ 0`). It is `⟪𝟙_{(0,T]}, g⟫`, the covariance of the +Wiener integral `∫₀ᵀ g dB` with `B_T`, and `−λσ` times it is the mean shift a constant market +price of risk `λ` gives the integrated rate under the Girsanov measure +(`vasicekBondPrice_girsanov`). -/ +lemma integral_vasicekIntegratedKernel (κ T : ℝ) (hκ : κ ≠ 0) : + ∫ u in (0 : ℝ)..T, vasicekIntegratedKernel κ T u = (T - vasicekBondB κ T) / κ := by + have hderiv (u : ℝ) : HasDerivAt (fun u : ℝ ↦ u / κ - Real.exp (-(κ * (T - u))) / κ ^ 2) + (vasicekIntegratedKernel κ T u) u := by + have harg : HasDerivAt (fun u ↦ -(κ * (T - u))) κ u := by + have h : HasDerivAt (fun u ↦ -(κ * (T - u))) (-(κ * (-1))) u := by + apply HasDerivAt.neg; apply HasDerivAt.const_mul + simpa using (hasDerivAt_id u).const_sub T + simpa using h + have hlin : HasDerivAt (fun u : ℝ ↦ u / κ) (1 / κ) u := (hasDerivAt_id u).div_const κ + refine (hlin.sub (harg.exp.div_const (κ ^ 2))).congr_deriv ?_ + simp only [vasicekIntegratedKernel] + field_simp + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt (fun u _ ↦ hderiv u) + (by apply Continuous.intervalIntegrable; unfold vasicekIntegratedKernel; fun_prop)] + simp only [sub_self, mul_zero, neg_zero, Real.exp_zero, sub_zero, zero_div, vasicekBondB] + field_simp + ring + +/-- `∫₀ᵀ g = (T − B(T))/κ` for the `L²` element of the integrated kernel. -/ +lemma integral_vasicekIntegratedKernelLp {κ : ℝ} (hκ : 0 < κ) (T : ℝ≥0) : + ∫ u in Set.Ioc (0 : ℝ) (T : ℝ), vasicekIntegratedKernelLp hκ T u + = ((T : ℝ) - vasicekBondB κ T) / κ := by + rw [← integral_vasicekIntegratedKernel κ T hκ.ne', intervalIntegral.integral_of_le T.coe_nonneg] + refine integral_congr_ae ?_ + filter_upwards [(vasicekIntegratedKernel_memLp hκ T).coeFn_toLp] with u hu + rw [vasicekIntegratedKernelLp, hu] + +/-! ### The integrated short rate and the bond price -/ + +/-- The **integrated Vasicek short rate** in its Wiener representation: +`∫₀ᵀ r_s ds = M(T) + σ·∫₀ᵀ g(u) dB_u`. -/ +noncomputable def vasicekIntegratedRate (hB : IsPreBrownianReal B μ) (r₀ θ σ : ℝ) {κ : ℝ} + (hκ : 0 < κ) (T : ℝ≥0) (ω : Ω) : ℝ := + vasicekIntegratedMean r₀ θ κ (T : ℝ) + + σ * (wienerIntegralLp B hB T (vasicekIntegratedKernelLp hκ T) ω) + +/-- `∫₀ᵀ g² = V(T)` for the `L²`-representative kernel (a.e. equal to the honest kernel). -/ +lemma vasicekIntegratedKernelLp_integral_sq {κ : ℝ} (hκ : 0 < κ) (T : ℝ≥0) : + (∫ u in Set.Ioc (0 : ℝ) (T : ℝ), (vasicekIntegratedKernelLp hκ T u) ^ 2 ∂volume) + = vasicekBondV κ (T : ℝ) := by + exact (vasicekIntegratedKernel_memLp hκ T).integral_sq_toLp.trans + (vasicekIntegratedKernel_integral_sq hκ.ne' T) + +/-- `V(T) ≥ 0` (it is an integral of a square). -/ +lemma vasicekBondV_nonneg {κ : ℝ} (hκ : 0 < κ) (T : ℝ≥0) : + (0 : ℝ) ≤ vasicekBondV κ (T : ℝ) := by + rw [← vasicekIntegratedKernelLp_integral_sq hκ T] + exact integral_nonneg fun u ↦ sq_nonneg _ + +/-- **Integrated Vasicek short rate is Gaussian.** The integrated rate +`∫₀ᵀ r_s ds = M(T) + σ∫₀ᵀ g dB` has law `N(M(T), σ²V(T))` — the affine map +`x ↦ M(T) + σx` applied to the centred Wiener integral of the integrated +kernel `g`, whose variance is `V(T)`. -/ +theorem vasicekIntegratedRate_hasLaw_gaussian (hB : IsPreBrownianReal B μ) + (r₀ θ σ : ℝ) {κ : ℝ} (hκ : 0 < κ) (T : ℝ≥0) : + HasLaw (vasicekIntegratedRate hB r₀ θ σ hκ T) + (gaussianReal (vasicekIntegratedMean r₀ θ κ (T : ℝ)) + (σ ^ 2 * vasicekBondV κ (T : ℝ)).toNNReal) μ := by + have hW := wienerIntegralLp_hasLaw_gaussian_of_integral_sq hB T (vasicekIntegratedKernelLp hκ T) + (vasicekIntegratedKernelLp_integral_sq hκ T) + have hV_nonneg : (0 : ℝ) ≤ vasicekBondV κ (T : ℝ) := vasicekBondV_nonneg hκ T + have hShift := gaussianReal_const_add (gaussianReal_const_mul hW σ) + (vasicekIntegratedMean r₀ θ κ (T : ℝ)) + convert hShift using 2 + · rfl + · ring + · refine NNReal.coe_injective ?_ + rw [Real.coe_toNNReal _ (mul_nonneg (sq_nonneg σ) hV_nonneg), NNReal.coe_mul, NNReal.coe_mk, + Real.coe_toNNReal _ hV_nonneg] + +/-- **The Vasicek zero-coupon bond price.** The expectation under `μ` (read as the pricing +measure; no change of measure is built here) of one unit at `T`, + + `P(0, T) = 𝔼[exp(−∫₀ᵀ r_s ds)] = exp(−M(T) + σ²V(T)/2)`, + +is the Gaussian Laplace transform of the integrated short rate: the Wiener bond-price lemma +`integral_exp_neg_add_mul_wienerIntegralLp` at `m = M(T)`, `c = σ` and the integrated kernel `g`, +whose squared `L²`-norm is `V(T)` (`vasicekIntegratedKernelLp_integral_sq`). -/ +theorem vasicekBondPrice_eq (hB : IsPreBrownianReal B μ) + (r₀ θ σ : ℝ) {κ : ℝ} (hκ : 0 < κ) (T : ℝ≥0) : + ∫ ω, Real.exp (-(vasicekIntegratedRate hB r₀ θ σ hκ T ω)) ∂μ + = Real.exp (-(vasicekIntegratedMean r₀ θ κ (T : ℝ)) + σ ^ 2 * vasicekBondV κ (T : ℝ) / 2) := + (integral_exp_neg_add_mul_wienerIntegralLp hB T (vasicekIntegratedMean r₀ θ κ (T : ℝ)) σ + (vasicekIntegratedKernelLp hκ T)).trans <| by rw [vasicekIntegratedKernelLp_integral_sq hκ T] + +/-- The Vasicek affine coefficient `A(T) = exp(−θ(T − B(T)) + σ²V(T)/2)`, so that +the bond price factors as `P(0,T) = A(T)·exp(−B(T)·r₀)`. -/ +noncomputable def vasicekBondA (θ σ κ T : ℝ) : ℝ := + Real.exp (-(θ * (T - vasicekBondB κ T)) + σ ^ 2 * vasicekBondV κ T / 2) + +/-- **The affine term structure**: the Vasicek bond price separates the initial +short rate into `P(0,T) = A(T)·exp(−B(T)·r₀)` — the defining shape of an affine +term-structure model, the exponential-affine dependence on `r₀`. -/ +theorem vasicekBondPrice_affine (hB : IsPreBrownianReal B μ) + (r₀ θ σ : ℝ) {κ : ℝ} (hκ : 0 < κ) (T : ℝ≥0) : + ∫ ω, Real.exp (-(vasicekIntegratedRate hB r₀ θ σ hκ T ω)) ∂μ + = vasicekBondA θ σ κ (T : ℝ) * Real.exp (-(vasicekBondB κ (T : ℝ) * r₀)) := by + rw [vasicekBondPrice_eq hB r₀ θ σ hκ T, vasicekBondA, vasicekIntegratedMean, ← Real.exp_add] + congr 1 + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/VasicekBondPriceAt.lean b/LeanPool/MathFin/Models/Rates/VasicekBondPriceAt.lean new file mode 100644 index 0000000000..efc41e7bbd --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/VasicekBondPriceAt.lean @@ -0,0 +1,237 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.VasicekBondPrice +public import LeanPool.MathFin.Models.Rates.VasicekSDEGaussian +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralFiltration + +/-! +# The Vasicek bond price at a time `t > 0` + +`Models/Rates/VasicekBondPrice.lean` prices the zero-coupon bond at time `0`, +`P(0, T) = 𝔼[exp(−∫₀ᵀ r_s ds)] = A(T)·exp(−B(T) r₀)`. This file prices it at a later time `t`, +given the information `𝓕_t = σ(B_s : s ≤ t)` of the driving Brownian motion: + + `𝔼[exp(−∫₀ᵀ r_s ds) | 𝓕_t] = exp(−∫₀ᵗ r_s ds)·A(T − t)·exp(−B(T − t)·r_t)` almost surely, + +so the price at `t` of one unit paid at `T`, the conditional mean of the discount over `[t, T]`, is +`A(T − t)·exp(−B(T − t)·r_t)`, with `A`, `B` the coefficients of the time-`0` price at the remaining +maturity `T − t`: the Vasicek model is time-homogeneous, so the price depends on `t` only through +`r_t` and `T − t`. + +The integrated rate is carried in its Wiener representation (`vasicekIntegratedRate`), so +`∫₀ᵀ r` and `∫₀ᵗ r` are Wiener integrals over different horizons. Given the past +(`Probability/Brownian/Wiener/WienerIntegralFiltration.lean`, `condExp_exp_wienerIntegralLp`), the +integrated kernel `g_T(u) = (1 − e^{−κ(T−u)})/κ` of the horizon `T`, restricted to `(0, t]`, is +`g_t + B(T − t)·e^{−κ(t−u)}`: the past part of `∫₀ᵀ r` depends on the past through `∫₀ᵗ r` and the +Wiener integral `∫₀ᵗ e^{−κ(t−u)} dB_u`, which is `(r_t − mean)/σ`; and the remainder is +independent of the past, with the exponential moments of a centred Gaussian of variance +`∫_t^T g_T² = V(T − t)`. The bridge to +`bondPrice` is `Models/Rates/VasicekBond.lean`. + +## Main results + +* `kernelRestrict_vasicekIntegratedKernelLp` — `g_T|_{(0,t]} = g_t + B(T − t)·e^{−κ(t−·)}`. +* `integral_sq_vasicekIntegratedKernelLp_Ioc` — `∫_t^T g_T² = V(T − t)`. +* `vasicekIntegratedMean_sub` — the mean identity `M(t) − M(T) = −θ(τ − B(τ)) − B(τ) m_t`. +* `condExp_exp_neg_integratedRate` — the conditional discount factor of any Gaussian short rate + with the integrated Vasicek kernel, from the mean identity `M(t) − M(T) = −c − B(T − t)·m` + alone; the Hull–White bond price (`Models/Rates/HullWhiteBondPriceAt.lean`) is its other + instance. +* `vasicekBondPrice_condExp` — the conditional discount factor, affine in `r_t`. + +## References + +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + section 3.2.1 +* [O. Vasicek, *An equilibrium characterization of the term structure*][Vasicek1977] + +## Tags + +Vasicek model, conditional bond price, time-homogeneous, affine term structure, short rate, +Markov property, MSC 91G30, MSC 60H05, JEL E43 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal +open WienerIntegralL2 + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + +lemma vasicekIntegratedKernelLp_coeFn {κ : ℝ} (hκ : 0 < κ) (T : ℝ≥0) : + vasicekIntegratedKernelLp hκ T =ᵐ[volume.restrict (Set.Ioc (0 : ℝ) T)] + vasicekIntegratedKernel κ T := + (vasicekIntegratedKernel_memLp hκ T).coeFn_toLp + +lemma vasicekKernelLp_coeFn (κ : ℝ) (hκ : 0 ≤ κ) (T : ℝ≥0) : + vasicekKernelLp κ hκ T =ᵐ[volume.restrict (Set.Ioc (0 : ℝ) T)] vasicekKernel κ T := + (vasicekKernel_memLp κ hκ T).coeFn_toLp + +/-- **The horizon-`T` kernel seen from time `t`.** On `(0, t]`, the integrated kernel +`g_T(u) = (1 − e^{−κ(T−u)})/κ` is `g_t(u) + B(T − t)·e^{−κ(t−u)}`, since +`e^{−κ(T−u)} = e^{−κ(t−u)} e^{−κ(T−t)}`. -/ +lemma kernelRestrict_vasicekIntegratedKernelLp {κ : ℝ} (hκ : 0 < κ) {t T : ℝ≥0} (htT : t ≤ T) : + kernelRestrict htT (vasicekIntegratedKernelLp hκ T) + = vasicekIntegratedKernelLp hκ t + + vasicekBondB κ ((T - t : ℝ≥0) : ℝ) • vasicekKernelLp κ hκ.le t := by + refine Lp.ext ?_ + filter_upwards [kernelRestrict_coeFn htT (vasicekIntegratedKernelLp hκ T), + (vasicekIntegratedKernelLp_coeFn hκ T).filter_mono (ae_mono (volume_restrict_Ioc_mono htT)), + Lp.coeFn_add (vasicekIntegratedKernelLp hκ t) + (vasicekBondB κ ((T - t : ℝ≥0) : ℝ) • vasicekKernelLp κ hκ.le t), + Lp.coeFn_smul (vasicekBondB κ ((T - t : ℝ≥0) : ℝ)) (vasicekKernelLp κ hκ.le t), + vasicekIntegratedKernelLp_coeFn hκ t, vasicekKernelLp_coeFn κ hκ.le t] + with u h1 h2 h3 h4 h5 h6 + rw [h3, Pi.add_apply, h1, h4, Pi.smul_apply, h5, h6, h2] + simp only [vasicekIntegratedKernel, vasicekKernel, vasicekBondB, smul_eq_mul, NNReal.coe_sub htT] + have : Real.exp (-(κ * ((T : ℝ) - u))) + = Real.exp (-(κ * ((t : ℝ) - u))) * Real.exp (-(κ * ((T : ℝ) - t))) := by + rw [← Real.exp_add]; congr 1; ring + rw [this] + field_simp + ring + +/-- **The variance of the remainder.** `∫_t^T g_T(u)² du = V(T − t)`, the variance function at the +remaining maturity. -/ +lemma integral_sq_vasicekIntegratedKernelLp_Ioc {κ : ℝ} (hκ : 0 < κ) {t T : ℝ≥0} (htT : t ≤ T) : + ∫ s in Set.Ioc (t : ℝ) T, (vasicekIntegratedKernelLp hκ T s) ^ 2 + = vasicekBondV κ ((T - t : ℝ≥0) : ℝ) := by + have ht : (t : ℝ) ≤ T := NNReal.coe_le_coe.2 htT + rw [integral_congr_ae (g := fun s ↦ (vasicekIntegratedKernel κ T s) ^ 2) + (((vasicekIntegratedKernelLp_coeFn hκ T).filter_mono (ae_mono + (Measure.restrict_mono (Set.Ioc_subset_Ioc_left t.coe_nonneg) le_rfl))).mono + fun u hu ↦ congrArg (· ^ 2) hu), + ← intervalIntegral.integral_of_le ht, + integral_vasicekIntegratedKernel_sq_eq_sub κ T t T hκ.ne'] + simp only [vasicekIntegratedKernelSqAntideriv, vasicekBondV, NNReal.coe_sub htT, sub_self, + mul_zero, neg_zero, Real.exp_zero] + field_simp + ring + +/-- The change in the integrated mean from `t` to `T`: the price coefficient at the remaining +maturity, less the mean sensitivity `B(T − t)` to the short-rate mean at `t`. -/ +lemma vasicekIntegratedMean_sub (r₀ θ : ℝ) {κ : ℝ} (hκ : κ ≠ 0) {t T : ℝ≥0} (htT : t ≤ T) : + vasicekIntegratedMean r₀ θ κ t - vasicekIntegratedMean r₀ θ κ T + = -(θ * (((T - t : ℝ≥0) : ℝ) - vasicekBondB κ ((T - t : ℝ≥0) : ℝ))) + - vasicekBondB κ ((T - t : ℝ≥0) : ℝ) * vasicekSDEMean r₀ θ κ t := by + have hT : Real.exp (-(κ * (T : ℝ))) + = Real.exp (-(κ * (t : ℝ))) * Real.exp (-(κ * ((T : ℝ) - t))) := by + rw [← Real.exp_add]; congr 1; ring + simp only [vasicekIntegratedMean, vasicekBondB, vasicekSDEMean, NNReal.coe_sub htT, hT] + field_simp + ring + +/-- **The conditional discount factor of a Gaussian short rate, from the kernel and mean +identities.** For any integrated rate `M_T + ∫₀ᵀ f dB` with a deterministic kernel `f ∈ L²((0, T])` +and deterministic part `M_T`, given the information `𝓕_t`, + + `𝔼[exp(−(M_T + ∫₀ᵀ f dB)) | 𝓕_t] + = exp(−(M_t + ∫₀ᵗ f' dB))·exp(−c + v/2)·exp(−b(m + ∫₀ᵗ h dB))` + +almost surely, as soon as the kernel seen from `t` splits as `f|_{(0,t]} = f' + b·h` (`hf`), the +remainder has variance `v = ∫_t^T f²` (`hv`), and the deterministic parts satisfy +`M_t − M_T = −c − b·m` (`hM`). The constant-volatility models are the instances +`f = σ·g_T` (`condExp_exp_neg_integratedRate`); the piecewise-volatility GSR model is another +(`Models/Rates/GSRBondPriceAt.lean`). -/ +theorem condExp_exp_neg_wienerIntegralLp [IsProbabilityMeasure μ] (hB : IsPreBrownianReal B μ) + (hBm : ∀ s, Measurable (B s)) {t T : ℝ≥0} (htT : t ≤ T) + (f : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) T))) + (f' h : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) t))) {M_t M_T c m b v : ℝ} + (hf : kernelRestrict htT f = f' + b • h) (hv : ∫ s in Set.Ioc (t : ℝ) T, f s ^ 2 = v) + (hM : M_t - M_T = -c - b * m) : + μ[fun ω ↦ Real.exp (-(M_T + wienerIntegralLp B hB T f ω)) + | Filtration.natural B (fun s ↦ (hBm s).stronglyMeasurable) t] + =ᵐ[μ] fun ω ↦ Real.exp (-(M_t + wienerIntegralLp B hB t f' ω)) + * (Real.exp (-c + v / 2) * Real.exp (-(b * (m + wienerIntegralLp B hB t h ω)))) := by + have hfun : (fun ω ↦ Real.exp (-(M_T + wienerIntegralLp B hB T f ω))) + = fun ω ↦ Real.exp (-M_T + 0 * wienerIntegralLp B hB t 0 ω + - 1 * wienerIntegralLp B hB T f ω) := by + funext ω + congr 1 + ring + rw [hfun] + refine (condExp_exp_wienerIntegralLp hB hBm htT 0 f _ 0 1).trans ?_ + rw [hf, map_add, map_smul, one_pow, one_mul, hv] + filter_upwards [Lp.coeFn_add (wienerIntegralLp B hB t f') (b • wienerIntegralLp B hB t h), + Lp.coeFn_smul b (wienerIntegralLp B hB t h)] with ω h1 h2 + rw [h1, Pi.add_apply, h2, Pi.smul_apply, smul_eq_mul, ← Real.exp_add, ← Real.exp_add, + ← Real.exp_add] + congr 1 + linear_combination hM + +/-- **The conditional discount factor of a constant-volatility Gaussian short rate, from the mean +identity alone.** The instance of `condExp_exp_neg_wienerIntegralLp` at `f = σ·g_T`: for any +integrated rate `M_T + σ∫₀ᵀ g_T dB` (the integrated Vasicek kernel `g_T`, any deterministic part +`M_T`), given the information `𝓕_t`, + + `𝔼[exp(−(M_T + σ∫₀ᵀ g_T dB)) | 𝓕_t] + = exp(−(M_t + σ∫₀ᵗ g_t dB))·exp(−c + σ²V(T − t)/2)·exp(−B(T − t)(m + σ∫₀ᵗ e^{−κ(t−·)} dB))` + +almost surely, as soon as the deterministic parts satisfy `M_t − M_T = −c − B(T − t)·m`. The +Vasicek model (`c = θ(τ − B(τ))`, `m` the mean of `r_t`) and the Hull–White model +(`c = ∫_t^T θ B(T − ·)`, `m = α(t)`) are the two instances: they differ only in this identity. -/ +theorem condExp_exp_neg_integratedRate [IsProbabilityMeasure μ] (hB : IsPreBrownianReal B μ) + (hBm : ∀ s, Measurable (B s)) (σ : ℝ) {κ : ℝ} (hκ : 0 < κ) {t T : ℝ≥0} (htT : t ≤ T) + {M_t M_T c m : ℝ} + (hM : M_t - M_T = -c - vasicekBondB κ ((T - t : ℝ≥0) : ℝ) * m) : + μ[fun ω ↦ Real.exp (-(M_T + σ * wienerIntegralLp B hB T (vasicekIntegratedKernelLp hκ T) ω)) + | Filtration.natural B (fun s ↦ (hBm s).stronglyMeasurable) t] + =ᵐ[μ] fun ω ↦ + Real.exp (-(M_t + σ * wienerIntegralLp B hB t (vasicekIntegratedKernelLp hκ t) ω)) + * (Real.exp (-c + σ ^ 2 * vasicekBondV κ ((T - t : ℝ≥0) : ℝ) / 2) + * Real.exp (-(vasicekBondB κ ((T - t : ℝ≥0) : ℝ) + * (m + σ * wienerIntegralLp B hB t (vasicekKernelLp κ hκ.le t) ω)))) := by + have hsm (s : ℝ≥0) (g : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) s))) : + ∀ᵐ ω ∂μ, wienerIntegralLp B hB s (σ • g) ω = σ * wienerIntegralLp B hB s g ω := + wienerIntegralLp_smul_ae hB s σ g + have hv : ∫ s in Set.Ioc (t : ℝ) T, (σ • vasicekIntegratedKernelLp hκ T) s ^ 2 + = σ ^ 2 * vasicekBondV κ ((T - t : ℝ≥0) : ℝ) := by + rw [← integral_sq_vasicekIntegratedKernelLp_Ioc hκ htT, ← integral_const_mul] + refine integral_congr_ae ?_ + filter_upwards [(Lp.coeFn_smul σ (vasicekIntegratedKernelLp hκ T)).filter_mono + (ae_mono (Measure.restrict_mono (Set.Ioc_subset_Ioc_left t.coe_nonneg) le_rfl))] with u hu + rw [hu, Pi.smul_apply, smul_eq_mul, mul_pow] + have key := condExp_exp_neg_wienerIntegralLp hB hBm htT (σ • vasicekIntegratedKernelLp hκ T) + (σ • vasicekIntegratedKernelLp hκ t) (σ • vasicekKernelLp κ hκ.le t) + (b := vasicekBondB κ ((T - t : ℝ≥0) : ℝ)) (c := c) (m := m) + (by rw [map_smul, kernelRestrict_vasicekIntegratedKernelLp hκ htT, smul_add, smul_comm]) hv hM + refine (condExp_congr_ae ?_).trans (key.trans ?_) + · filter_upwards [hsm T (vasicekIntegratedKernelLp hκ T)] with ω hω + rw [hω] + · filter_upwards [hsm t (vasicekIntegratedKernelLp hκ t), hsm t (vasicekKernelLp κ hκ.le t)] + with ω h1 h2 + rw [h1, h2] + +/-- **The Vasicek bond price at time `t`.** Given the information `𝓕_t` of the driving Brownian +motion, the discount factor `exp(−∫₀ᵀ r)` along the Vasicek integrated rate has conditional mean + + `𝔼[exp(−∫₀ᵀ r) | 𝓕_t] = exp(−∫₀ᵗ r)·A(T − t)·exp(−B(T − t)·r_t)` + +almost surely, where `r_t = vasicekSDEMean + σ∫₀ᵗ e^{−κ(t−u)} dB_u` is the short rate in its Wiener +representation (`vasicekShortRate_hasLaw_gaussian`) and `A`, `B` are the coefficients of the +time-`0` price (`vasicekBondPrice_affine`), at the remaining maturity. Dividing by the discount +factor `exp(−∫₀ᵗ r)` known at `t`, the price at `t` of one unit paid at `T` is +`A(T − t)·exp(−B(T − t)·r_t)`. The measure is read as the pricing measure. -/ +theorem vasicekBondPrice_condExp [IsProbabilityMeasure μ] (hB : IsPreBrownianReal B μ) + (hBm : ∀ s, Measurable (B s)) (r₀ θ σ : ℝ) {κ : ℝ} (hκ : 0 < κ) {t T : ℝ≥0} (htT : t ≤ T) : + μ[fun ω ↦ Real.exp (-vasicekIntegratedRate hB r₀ θ σ hκ T ω) + | Filtration.natural B (fun s ↦ (hBm s).stronglyMeasurable) t] + =ᵐ[μ] fun ω ↦ Real.exp (-vasicekIntegratedRate hB r₀ θ σ hκ t ω) + * (vasicekBondA θ σ κ ((T - t : ℝ≥0) : ℝ) + * Real.exp (-(vasicekBondB κ ((T - t : ℝ≥0) : ℝ) + * (vasicekSDEMean r₀ θ κ t + vasicekDiffusionTerm hB κ σ hκ.le t ω)))) := + condExp_exp_neg_integratedRate hB hBm σ hκ htT (c := θ * (((T - t : ℝ≥0) : ℝ) + - vasicekBondB κ ((T - t : ℝ≥0) : ℝ))) (m := vasicekSDEMean r₀ θ κ t) + (vasicekIntegratedMean_sub r₀ θ hκ.ne' htT) + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/VasicekMarket.lean b/LeanPool/MathFin/Models/Rates/VasicekMarket.lean new file mode 100644 index 0000000000..adaa09b61e --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/VasicekMarket.lean @@ -0,0 +1,221 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.VasicekBondPriceAt +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralL2 +public import LeanPool.MathFin.Pricing.Market + +/-! +# The Vasicek bond market + +The Vasicek bond market uses a stochastic bank-account numéraire built from the +Wiener-integral integrated-rate formula. The zero-coupon bond of maturity `T` is the +traded asset (`Rates.vasicekMarket`). The model uses the reference measure `μ` as its pricing +measure. The drift `θ` and short-rate dynamics are specified under that measure. + +The information is the natural filtration of the Brownian motion `B`. The short rate and the +integrated rate are Wiener integrals, that is, classes in `L²(μ)`, which are `𝓕_t`-measurable only +almost surely (`wienerIntegralLp_mem_lpMeas`), whereas a `Market` asks for exact strong +adaptedness. The market therefore uses the `𝓕_t`-measurable representatives +`μ[· | 𝓕_t]` of the Wiener integrals (`vasicekBankAccount`, `vasicekShortRate`): a Wiener +integral that is almost surely `𝓕_t`-measurable is almost surely its own conditional expectation +(`condExp_of_aestronglyMeasurable'`), so the representatives change nothing but a null set. + +Before `T` the bond is worth `P(t, T) = A(T − t) exp(−B(T − t) r_t)` (`vasicekBondPriceRep`). After +`T` its proceeds are held in the bank account, so the asset is `N_t P(t∧T, T) / N_{t∧T}`, and the +deflated asset frozen at `T` is `P(t∧T, T) / N_{t∧T}`. + +## Main definitions + +* `MathFin.Rates.vasicekBankAccount`: the exponential of the `𝓕_t`-measurable + representative of the Wiener-integral integrated-rate formula. +* `MathFin.Rates.vasicekShortRate`: the short rate `r_t`, through the `𝓕_t`-measurable + representative of its diffusion term. +* `MathFin.Rates.vasicekBondPriceRep`: the bond price `A(T − t) exp(−B(T − t) r_t)`. +* `MathFin.Rates.vasicekMarket`: the market of the bank account and the zero-coupon bond. + +## Main results + +* `MathFin.Rates.isPricingMeasure_vasicekMarket`: the reference measure prices the market at the + horizon `T`. The deflated bond frozen at `T` is the conditional expectation of the + terminal discount from `vasicekIntegratedRate` (`vasicekBondPrice_condExp`), a Doob martingale. +* `MathFin.Rates.price_pay_vasicekMarket`: the market price of one unit paid at `T` is the Vasicek + bond price `A(T) exp(−B(T) r₀)`. + +## References + +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + section 3.2.1 +* [O. Vasicek, *An equilibrium characterization of the term structure*][Vasicek1977] + +## Tags + +Vasicek model, bond market, bank account, stochastic numéraire, pricing measure, short rate, +MSC 91G30, MSC 60H05, JEL E43, JEL G12 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Real MathFin MathFin.Contracts +open scoped NNReal +open ItoIntegralL2 + +namespace MathFin.Rates + +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {μ : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + [IsProbabilityMeasure μ] (hB : IsPreBrownianReal B μ) (hBm : ∀ s, Measurable (B s)) + (r₀ θ σ : ℝ) {κ : ℝ} (hκ : 0 < κ) + +/-- **The bank account** through the `𝓕_t`-measurable representative +`μ[∫₀ᵗ r | 𝓕_t]` of the integrated rate. -/ +noncomputable def vasicekBankAccount (t : ℝ≥0) (ω : Ω) : ℝ := + Real.exp (μ[vasicekIntegratedRate hB r₀ θ σ hκ t | natFiltration hBm t] ω) + +/-- **The short rate** `r_t = m_t + σ ∫₀ᵗ e^{−κ(t−u)} dB_u`, through the `𝓕_t`-measurable +representative of the Wiener integral. -/ +noncomputable def vasicekShortRate (t : ℝ≥0) (ω : Ω) : ℝ := + vasicekSDEMean r₀ θ κ t + μ[vasicekDiffusionTerm hB κ σ hκ.le t | natFiltration hBm t] ω + +/-- **The Vasicek bond price at `t ≤ T`**, `A(T − t) exp(−B(T − t) r_t)`. -/ +noncomputable def vasicekBondPriceRep (T t : ℝ≥0) (ω : Ω) : ℝ := + vasicekBondA θ σ κ ((T - t : ℝ≥0) : ℝ) + * Real.exp (-(vasicekBondB κ ((T - t : ℝ≥0) : ℝ) * vasicekShortRate hB hBm r₀ θ σ hκ t ω)) + +lemma aestronglyMeasurable_vasicekIntegratedRate (t : ℝ≥0) : + AEStronglyMeasurable[natFiltration hBm t] (vasicekIntegratedRate hB r₀ θ σ hκ t) μ := + ((mem_lpMeas_iff_aestronglyMeasurable.1 + (wienerIntegralLp_mem_lpMeas hB hBm (t := t) + (vasicekIntegratedKernelLp hκ t))).const_mul σ).const_add _ + +lemma aestronglyMeasurable_vasicekDiffusionTerm (t : ℝ≥0) : + AEStronglyMeasurable[natFiltration hBm t] (vasicekDiffusionTerm hB κ σ hκ.le t) μ := + (mem_lpMeas_iff_aestronglyMeasurable.1 + (wienerIntegralLp_mem_lpMeas hB hBm (t := t) + (vasicekKernelLp κ hκ.le t))).const_mul σ + +lemma integrable_vasicekIntegratedRate (t : ℝ≥0) : + Integrable (vasicekIntegratedRate hB r₀ θ σ hκ t) μ := + (integrable_const _).add (((Lp.memLp _).integrable one_le_two).const_mul σ) + +lemma integrable_vasicekDiffusionTerm (t : ℝ≥0) : + Integrable (vasicekDiffusionTerm hB κ σ hκ.le t) μ := + ((Lp.memLp _).integrable one_le_two).const_mul σ + + +omit [IsProbabilityMeasure μ] in +lemma vasicekIntegratedRate_zero_ae : + ∀ᵐ ω ∂μ, vasicekIntegratedRate hB r₀ θ σ hκ 0 ω = 0 := by + have hf : vasicekIntegratedKernelLp hκ 0 = 0 := + Lp.eq_zero_iff_ae_eq_zero.mpr (by + simp only [NNReal.coe_zero, lt_self_iff_false, not_false_eq_true, Set.Ioc_eq_empty, + Measure.restrict_empty, ae_zero] + exact Filter.eventually_bot) + have h : WienerIntegralL2.wienerIntegralLp B hB 0 (vasicekIntegratedKernelLp hκ 0) = 0 := by + rw [hf, map_zero] + filter_upwards [Lp.coeFn_zero ℝ 2 μ] with ω hω + rw [vasicekIntegratedRate, h, hω] + simp [vasicekIntegratedMean, vasicekBondB] + +/-- The bank account is almost surely the exponential of the Wiener-form integrated rate. +The Wiener integral agrees almost surely with its `𝓕_t`-measurable representative. -/ +lemma vasicekBankAccount_ae_eq (t : ℝ≥0) : + vasicekBankAccount hB hBm r₀ θ σ hκ t + =ᵐ[μ] fun ω ↦ Real.exp (vasicekIntegratedRate hB r₀ θ σ hκ t ω) := + (condExp_of_aestronglyMeasurable' ((natFiltration hBm).le t) + (aestronglyMeasurable_vasicekIntegratedRate hB hBm r₀ θ σ hκ t) + (integrable_vasicekIntegratedRate hB r₀ θ σ hκ t)).fun_comp Real.exp + +/-- The short rate is almost surely `m_t + σ ∫₀ᵗ e^{−κ(t−u)} dB_u`. -/ +lemma vasicekShortRate_ae_eq (t : ℝ≥0) : + vasicekShortRate hB hBm r₀ θ σ hκ t + =ᵐ[μ] fun ω ↦ vasicekSDEMean r₀ θ κ t + vasicekDiffusionTerm hB κ σ hκ.le t ω := + (condExp_of_aestronglyMeasurable' ((natFiltration hBm).le t) + (aestronglyMeasurable_vasicekDiffusionTerm hB hBm σ hκ t) + (integrable_vasicekDiffusionTerm hB σ hκ t)).fun_comp (vasicekSDEMean r₀ θ κ t + ·) + +omit [IsProbabilityMeasure μ] in +lemma stronglyMeasurable_vasicekBankAccount (t : ℝ≥0) : + StronglyMeasurable[natFiltration hBm t] (vasicekBankAccount hB hBm r₀ θ σ hκ t) := + Real.continuous_exp.comp_stronglyMeasurable stronglyMeasurable_condExp + +omit [IsProbabilityMeasure μ] in +lemma stronglyMeasurable_vasicekBondPriceRep (T t : ℝ≥0) : + StronglyMeasurable[natFiltration hBm t] (vasicekBondPriceRep hB hBm r₀ θ σ hκ T t) := + stronglyMeasurable_const.mul (Real.continuous_exp.comp_stronglyMeasurable + (stronglyMeasurable_const.mul (stronglyMeasurable_const.add stronglyMeasurable_condExp)).neg) + +/-- **The Vasicek bond market**: the information is the natural filtration of `B`, the numéraire +is the bank account `exp ∫₀ᵗ r`, and the one asset is the zero-coupon bond of maturity `T`, worth +`A(T − t) exp(−B(T − t) r_t)` before `T` and, after `T`, its proceeds held in the bank account: +`N_t P(t∧T, T) / N_{t∧T}`. The reference measure `μ` is read as the pricing measure. -/ +noncomputable def vasicekMarket (T : ℝ≥0) : Market Unit Ω where + P := μ + 𝓕 := natFiltration hBm + asset _ t ω := vasicekBankAccount hB hBm r₀ θ σ hκ t ω + * (vasicekBondPriceRep hB hBm r₀ θ σ hκ T (min t T) ω + / vasicekBankAccount hB hBm r₀ θ σ hκ (min t T) ω) + numeraire := vasicekBankAccount hB hBm r₀ θ σ hκ + numeraire_pos _ _ := Real.exp_pos _ + asset_adapted _ t := (stronglyMeasurable_vasicekBankAccount hB hBm r₀ θ σ hκ t).mul + (((stronglyMeasurable_vasicekBondPriceRep hB hBm r₀ θ σ hκ T _).div + (stronglyMeasurable_vasicekBankAccount hB hBm r₀ θ σ hκ _)).mono + ((natFiltration hBm).mono (min_le_left t T))) + numeraire_adapted := stronglyMeasurable_vasicekBankAccount hB hBm r₀ θ σ hκ + +omit [IsProbabilityMeasure μ] in +lemma deflated_vasicekMarket (T t : ℝ≥0) (ω : Ω) (i : Unit) : + (vasicekMarket hB hBm r₀ θ σ hκ T).deflated i (min t T) ω + = vasicekBondPriceRep hB hBm r₀ θ σ hκ T (min t T) ω + / vasicekBankAccount hB hBm r₀ θ σ hκ (min t T) ω := by + have h : min (min t T) T = min t T := by simp + have := (Real.exp_pos (μ[vasicekIntegratedRate hB r₀ θ σ hκ (min t T) + | natFiltration hBm (min t T)] ω)).ne' + simp only [Market.deflated, vasicekMarket, h] + field_simp + +/-- **The reference measure prices the Vasicek bond market.** The deflated bond frozen at `T` is +almost surely `μ[exp(−∫₀ᵀ r) | 𝓕_{t∧T}]` (`vasicekBondPrice_condExp`), the Doob martingale of the +discount factor over `[0, T]`; `Q = μ` is trivially equivalent to the reference measure. -/ +theorem isPricingMeasure_vasicekMarket (T : ℝ≥0) : + (vasicekMarket hB hBm r₀ θ σ hκ T).IsPricingMeasure T μ := by + refine .of_isEquivProbMeasure ⟨inferInstance, .rfl, .rfl⟩ fun i ↦ ?_ + refine (martingale_min_of_martingale (martingale_condExp + (fun ω ↦ Real.exp (-vasicekIntegratedRate hB r₀ θ σ hκ T ω)) (natFiltration hBm) μ) + T).congr_ae ?_ fun t ↦ ?_ + · intro t + beta_reduce + rw [show (vasicekMarket hB hBm r₀ θ σ hκ T).deflated i (min t T) = fun ω ↦ + vasicekBondPriceRep hB hBm r₀ θ σ hκ T (min t T) ω + / vasicekBankAccount hB hBm r₀ θ σ hκ (min t T) ω from + funext fun ω ↦ deflated_vasicekMarket hB hBm r₀ θ σ hκ T t ω i] + exact (((stronglyMeasurable_vasicekBondPriceRep hB hBm r₀ θ σ hκ T _).div + (stronglyMeasurable_vasicekBankAccount hB hBm r₀ θ σ hκ _)).mono + ((natFiltration hBm).mono (min_le_left t T))) + · filter_upwards [vasicekBondPrice_condExp hB hBm r₀ θ σ hκ (min_le_right t T), + vasicekBankAccount_ae_eq hB hBm r₀ θ σ hκ (min t T), + vasicekShortRate_ae_eq hB hBm r₀ θ σ hκ (min t T)] with ω h₁ h₂ h₃ + rw [deflated_vasicekMarket, vasicekBondPriceRep, h₃, h₂] + refine h₁.trans ?_ + simp only [div_eq_mul_inv, ← Real.exp_neg] + ring + +/-- **The market price of one unit paid at `T` is the Vasicek bond price** `A(T) exp(−B(T) r₀)`, +under the reference measure, the pricing measure of `isPricingMeasure_vasicekMarket`: the value +of the unit payment with the stochastic deflator `N₀/N_T` built from the Wiener kernel. -/ +theorem price_pay_vasicekMarket (T : ℝ≥0) : + (vasicekMarket hB hBm r₀ θ σ hκ T).price μ (.pay T (.const 1)) + = vasicekBondA θ σ κ (T : ℝ) * Real.exp (-(vasicekBondB κ (T : ℝ) * r₀)) := by + rw [← vasicekBondPrice_affine hB r₀ θ σ hκ T, Market.price, Contract.value_pay] + refine integral_congr_ae ?_ + filter_upwards [vasicekBankAccount_ae_eq hB hBm r₀ θ σ hκ 0, + vasicekBankAccount_ae_eq hB hBm r₀ θ σ hκ T, + vasicekIntegratedRate_zero_ae hB r₀ θ σ hκ] with ω h₀ h₁ h₂ + simp [Payoff.eval, Market.deflator, vasicekMarket, h₀, h₁, h₂, Real.exp_neg] + +end MathFin.Rates diff --git a/LeanPool/MathFin/Models/Rates/VasicekMarketPriceOfRisk.lean b/LeanPool/MathFin/Models/Rates/VasicekMarketPriceOfRisk.lean new file mode 100644 index 0000000000..a628db668f --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/VasicekMarketPriceOfRisk.lean @@ -0,0 +1,256 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.GaussianGirsanov +public import LeanPool.MathFin.Models.Rates.VasicekBondPrice +public import LeanPool.MathFin.Models.Rates.VasicekSDEGaussian +public import LeanPool.MathFin.Probability.Brownian.Girsanov.WienerIntegralGirsanov +public import Mathlib.Algebra.Ring.IsFormallyReal + +/-! +# Vasicek short rate under a constant market price of risk + +Textbook background (the SDEs are not formalized): with a constant market price of risk `λ`, the +Vasicek short rate has real-world dynamics `dr = κ(θ − r)dt + σ dB` and, under the Girsanov +measure `Q_λ = μ.withDensity(exp(−λB_T − λ²T/2))`, dynamics `dr = κ(θ − λσ/κ − r)dt + σ dB^λ` +with `B^λ_t = B_t + λt`. The risk-adjusted long-run level is `θ − λσ/κ`. In the Lean, `r_T` and +`∫₀ᵀ r_s ds` are carried in their Wiener representations (`vasicekShortRate_hasLaw_gaussian`, +`vasicekIntegratedRate`), as elsewhere in the Vasicek layer. +That they solve the SDE, and the time-order swap behind the integrated rate, are cited, not proved. +`Q_λ` is the measure the library constructs: `isProbabilityMeasure_withDensity_girsanov` shows +it is a probability measure, and with a filtration `Btheta_isQBrownianMotion` shows that `B^λ` +has, on `[0, T]`, the increments of a `Q_λ`-Brownian motion. + +## Main results + +* `vasicekSDEMean_physical_eq_riskNeutral`: an algebraic identity of closed forms + (`κ ≠ 0`): `vasicekSDEMean` at level `θ` equals `vasicekSDEMean` at the risk-adjusted level + `θ − λσ/κ` plus `λσ·B(T)`; the analogue of `bsTerminal_physical_eq_riskNeutral`. +* `vasicekShortRate_hasLaw_girsanov`: under `Q_λ`, `r_T ~ N(mean_θ − λσ·B(T), var)`. By the + identity above this is the law of the Vasicek short rate at level `θ − λσ/κ`. +* `vasicekBondPrice_girsanov`: the `Q_λ`-price of the zero-coupon bond, + `𝔼_{Q_λ}[exp(−∫₀ᵀ r_s ds)]`, equals `𝔼_μ[exp(−∫₀ᵀ r_s ds)]` at level `θ − λσ/κ`, in + closed form `exp(−M_{θ−λσ/κ}(T) + σ²V(T)/2)` (`vasicekBondPrice_eq`). +* `vasicekShortRate_hasLaw_esscherTilt`: a static Esscher tilt of `r_T`'s own normalised driver + under which `r_T` has the same law `N(mean_θ − λσ·B(T), var)`. The tilt reproduces the + terminal marginal only: it is `T`-dependent, does not make `B + λt` a Brownian motion, and + prices nothing else. `vasicekShortRate_map_esscherTilt_eq_map_girsanov` records that it agrees + with `Q_λ` on the law of `r_T`. + +Both Girsanov results come from the Cameron–Martin shift `wienerIntegralLp_hasLaw_girsanov`: +under `Q_λ` every Wiener integral `∫₀ᵀ f dB` is `N(−λ∫₀ᵀ f, ∫₀ᵀ f²)`. The joint law of +`(B_T, ∫₀ᵀ e^{−κ(T−s)} dB_s)` is not needed. The mean shift is `−λσ∫₀ᵀ e^{−κ(T−s)} ds = −λσ·B(T)` +for `r_T`, and `−λσ∫₀ᵀ g = −λσ(T − B(T))/κ` for the integrated rate. + +## References + +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + §3.2.1 +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], Thm. + 5.2.3 +* [O. Vasicek, *An equilibrium characterization of the term structure*][Vasicek1977] + +## Tags + +market price of risk, Vasicek model, risk-neutral measure, Cameron–Martin, Esscher transform, +risk-adjusted mean, MSC 91G30, MSC 60H30, JEL E43 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal +open WienerIntegralL2 + +/-- **Real-world vs. risk-neutral Vasicek mean.** An algebraic identity of the closed form +`vasicekSDEMean`, for `κ ≠ 0`: replacing the long-run level `θ` by the risk-neutral level +`θ − lamσ/κ` changes the terminal mean by `−lamσ·(1 − e^{−κT})/κ`. -/ +theorem vasicekSDEMean_physical_eq_riskNeutral (r₀ θ κ σ lam T : ℝ) (hκ : κ ≠ 0) : + vasicekSDEMean r₀ θ κ T + = vasicekSDEMean r₀ (θ - lam * σ / κ) κ T + + lam * σ * vasicekBondB κ T := by + unfold vasicekSDEMean vasicekBondB + field_simp + ring + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-! ### The kernel `e^{−κ(T−s)}`: mass and `L²`-norm -/ + +/-- **The mass of the Vasicek kernel**: `∫₀ᵀ e^{−κ(T−s)} ds = B(T)` (`κ ≠ 0`), by the FTC with +antiderivative `e^{−κ(T−s)}/κ`. It is the covariance of `∫₀ᵀ e^{−κ(T−s)} dB_s` with `B_T`. -/ +lemma integral_vasicekKernel (κ T : ℝ) (hκ : κ ≠ 0) : + ∫ u in (0 : ℝ)..T, vasicekKernel κ T u = vasicekBondB κ T := by + have hderiv (u : ℝ) : HasDerivAt (fun u : ℝ ↦ Real.exp (-(κ * (T - u))) / κ) + (vasicekKernel κ T u) u := by + have harg : HasDerivAt (fun u ↦ -(κ * (T - u))) κ u := by + have h : HasDerivAt (fun u ↦ -(κ * (T - u))) (-(κ * (-1))) u := by + apply HasDerivAt.neg; apply HasDerivAt.const_mul + simpa using (hasDerivAt_id u).const_sub T + simpa using h + refine (harg.exp.div_const κ).congr_deriv ?_ + simp only [vasicekKernel] + field_simp + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt (fun u _ ↦ hderiv u) + (by apply Continuous.intervalIntegrable; unfold vasicekKernel; fun_prop)] + simp only [sub_self, mul_zero, neg_zero, Real.exp_zero, sub_zero, vasicekBondB] + ring + +/-- `∫₀ᵀ e^{−κ(T−s)} ds = B(T)` for the `L²` element of the kernel. -/ +lemma integral_vasicekKernelLp {κ : ℝ} (hκ : 0 < κ) (T : ℝ≥0) : + ∫ u in Set.Ioc (0 : ℝ) (T : ℝ), vasicekKernelLp κ hκ.le T u = vasicekBondB κ T := by + rw [← integral_vasicekKernel κ T hκ.ne', intervalIntegral.integral_of_le T.coe_nonneg] + refine integral_congr_ae ?_ + filter_upwards [(vasicekKernel_memLp κ hκ.le T).coeFn_toLp] with u hu + rw [vasicekKernelLp, hu] + +/-- `∫₀ᵀ (e^{−κ(T−s)})² ds = vasicekSDEVariance 1 κ T` for the `L²` element of the kernel. -/ +private lemma vasicekKernelLp_integral_sq {κ : ℝ} (hκ : 0 < κ) (T : ℝ≥0) : + ∫ u in Set.Ioc (0 : ℝ) (T : ℝ), (vasicekKernelLp κ hκ.le T u) ^ 2 + = vasicekSDEVariance 1 κ T := by + rw [vasicekSDEVariance, one_pow, one_mul, ← vasicekKernel_integral_sq κ hκ.ne' T] + exact (vasicekKernel_memLp κ hκ.le T).integral_sq_toLp + +/-! ### The short rate and the bond under the Girsanov measure -/ + +/-- **The Vasicek terminal short rate under the Girsanov measure.** Under +`Q_λ = μ.withDensity(exp(−lam·B_T − lam²T/2))`, the terminal short rate in its Wiener +representation `r_T = mean_θ + σ∫₀ᵀ e^{−κ(T−s)} dB_s` has law + + `r_T ~ N(mean_θ − lam·σ·B(T), σ²(1 − e^{−2κT})/(2κ))`, `B(T) = vasicekBondB κ T`: + +the Cameron–Martin shift `wienerIntegralLp_hasLaw_girsanov` moves the mean of the Wiener integral +by `−lam·∫₀ᵀ e^{−κ(T−s)} ds = −lam·B(T)` and keeps its variance. By +`vasicekSDEMean_physical_eq_riskNeutral` the mean is `vasicekSDEMean r₀ (θ − lam·σ/κ) κ T`, the law +of the Vasicek short rate at the risk-adjusted level. That the representation solves the SDE is +cited, not proved. -/ +theorem vasicekShortRate_hasLaw_girsanov (hB : IsPreBrownianReal B μ) (r₀ θ σ lam : ℝ) {κ : ℝ} + (hκ : 0 < κ) (T : ℝ≥0) : + HasLaw (fun ω ↦ vasicekSDEMean r₀ θ κ T + + σ * wienerIntegralLp B hB T (vasicekKernelLp κ hκ.le T) ω) + (gaussianReal (vasicekSDEMean r₀ θ κ T - lam * σ * vasicekBondB κ T) + (vasicekSDEVariance σ κ T).toNNReal) + (μ.withDensity fun ω ↦ ENNReal.ofReal (Real.exp (-lam * B T ω - lam ^ 2 * (T : ℝ) / 2))) := by + have hW := wienerIntegralLp_hasLaw_girsanov hB lam T (vasicekKernelLp κ hκ.le T) + rw [integral_vasicekKernelLp hκ T, vasicekKernelLp_integral_sq hκ T] at hW + have hv : (0 : ℝ) ≤ vasicekSDEVariance 1 κ T := vasicekSDEVariance_nonneg 1 hκ T.coe_nonneg + convert gaussianReal_const_add (gaussianReal_const_mul hW σ) (vasicekSDEMean r₀ θ κ T) using 2 + · ring + · refine NNReal.coe_injective ?_ + rw [Real.coe_toNNReal _ (vasicekSDEVariance_nonneg σ hκ T.coe_nonneg), NNReal.coe_mul, + NNReal.coe_mk, Real.coe_toNNReal _ hv] + unfold vasicekSDEVariance + ring + +/-- **The Vasicek bond under the Girsanov measure is the Vasicek bond at the risk-adjusted +level.** With `∫₀ᵀ r_s ds` in its Wiener representation `vasicekIntegratedRate`, + + `𝔼_{Q_λ}[exp(−∫₀ᵀ r_s ds)] = 𝔼_μ[exp(−∫₀ᵀ r^{θ − lam·σ/κ}_s ds)]`, + +where the right side is the `μ`-expectation of `vasicekBondPrice_eq` at long-run level +`θ − lam·σ/κ`, in closed form `exp(−M_{θ−lam·σ/κ}(T) + σ²V(T)/2)` (`vasicekBondPrice_eq`). Under +`Q_λ` the Wiener integral of the integrated kernel `g` is shifted by +`−lam·∫₀ᵀ g = −lam·(T − B(T))/κ` (`wienerIntegralLp_hasLaw_girsanov`, +`integral_vasicekIntegratedKernelLp`), so `σ∫₀ᵀ g dB` shifts by `−lam·σ·(T − B(T))/κ`, exactly +the change of `M(T)` when `θ` drops by `lam·σ/κ`. -/ +theorem vasicekBondPrice_girsanov (hB : IsPreBrownianReal B μ) (r₀ θ σ lam : ℝ) {κ : ℝ} + (hκ : 0 < κ) (T : ℝ≥0) : + ∫ ω, Real.exp (-(vasicekIntegratedRate hB r₀ θ σ hκ T ω)) + ∂(μ.withDensity fun ω ↦ ENNReal.ofReal (Real.exp (-lam * B T ω - lam ^ 2 * (T : ℝ) / 2))) + = ∫ ω, Real.exp (-(vasicekIntegratedRate hB r₀ (θ - lam * σ / κ) σ hκ T ω)) ∂μ := by + have hW := wienerIntegralLp_hasLaw_girsanov hB lam T (vasicekIntegratedKernelLp hκ T) + rw [integral_vasicekIntegratedKernelLp hκ T, vasicekIntegratedKernelLp_integral_sq hκ T] at hW + have hm := mgf_gaussianReal hW (-σ) + simp only [mgf] at hm + have hfac (ω : Ω) : Real.exp (-(vasicekIntegratedRate hB r₀ θ σ hκ T ω)) + = Real.exp (-vasicekIntegratedMean r₀ θ κ T) + * Real.exp (-σ * wienerIntegralLp B hB T (vasicekIntegratedKernelLp hκ T) ω) := by + rw [vasicekIntegratedRate, ← Real.exp_add] + congr 1 + ring + simp_rw [hfac] + rw [integral_const_mul, hm, vasicekBondPrice_eq, Real.coe_toNNReal _ (vasicekBondV_nonneg hκ T), + ← Real.exp_add] + congr 1 + simp only [vasicekIntegratedMean] + ring + +/-- **Vasicek terminal law with the risk-adjusted mean, under a static Esscher tilt of the +terminal driver.** For `κ > 0` and `T > 0`, let `r_T = mean_θ + σ ∫₀ᵀ e^{−κ(T−s)} dB_s` be the +terminal short rate in its Wiener representation, and +`Z = (∫₀ᵀ e^{−κ(T−s)} dB_s)/√v` its standard-normal driver (`v = (1 − e^{−2κT})/(2κ)`). +Under the Esscher tilt `μ.withDensity(exp(cZ − c²/2))` with `c = −lam·B(T)/√v`, the same `r_T` +has law `N(mean_θ − lamσ·B(T), var)`. + +This tilt is a terminal-marginal device, not the pricing measure. It is a `T`-dependent tilt of +`r_T`'s own normalised driver. Under it `B + lam·t` is not a Brownian motion, the rest of the path +(e.g. `∫₀ᵀ r_s ds`) does not have its risk-adjusted law, and it prices no other payoff. The +pricing statements are `vasicekShortRate_hasLaw_girsanov` and `vasicekBondPrice_girsanov`, under +the Girsanov measure `μ.withDensity(exp(−lam·B_T − lam²T/2))`. That measure gives `r_T` the same +law as this tilt (`vasicekShortRate_map_esscherTilt_eq_map_girsanov`). -/ +theorem vasicekShortRate_hasLaw_esscherTilt (hB : IsPreBrownianReal B μ) + (r₀ θ σ lam : ℝ) {κ : ℝ} (hκ : 0 < κ) (T : ℝ≥0) (hT : 0 < T) : + let I : Ω → ℝ := fun ω ↦ wienerIntegralLp B hB T (vasicekKernelLp κ hκ.le T) ω + let s : ℝ := Real.sqrt (vasicekSDEVariance 1 κ T) + let c : ℝ := -(lam * vasicekBondB κ T) / s + HasLaw (fun ω ↦ vasicekSDEMean r₀ θ κ T + σ * I ω) + (gaussianReal (vasicekSDEMean r₀ θ κ T - lam * σ * vasicekBondB κ T) + (vasicekSDEVariance σ κ T).toNNReal) + (μ.withDensity fun ω ↦ ENNReal.ofReal (Real.exp (c * (I ω / s) - c ^ 2 / 2))) := by + intro I s c + -- `I ~ N(0, v)`: the σ = 1, zero-mean instance of the derived terminal law. + have hI : HasLaw I (gaussianReal 0 (vasicekSDEVariance 1 κ T).toNNReal) μ := by + have h := vasicekShortRate_hasLaw_gaussian hB 0 0 1 hκ T + simp only [vasicekSDEMean, zero_mul, add_zero, one_mul, zero_add] at h + exact h + have hv : 0 < vasicekSDEVariance 1 κ T := vasicekSDE_variance_pos 1 κ T hκ hT one_ne_zero + have hs : 0 < s := Real.sqrt_pos.mpr hv + have hss : s ^ 2 = vasicekSDEVariance 1 κ T := Real.sq_sqrt hv.le + have hImeas : Measurable I := (Lp.stronglyMeasurable _).measurable + -- `Z = I/s ~ N(0, 1)`. + have hZ : HasLaw (fun ω ↦ I ω / s) (gaussianReal 0 1) μ := by + have h := gaussianReal_const_mul hI s⁻¹ + convert h using 2 + · rw [div_eq_inv_mul] + · simp + · ext + simp [← hss, hs.ne', max_eq_left (sq_nonneg s)] + have hZQ := hasLaw_esscher_tilt c (hImeas.div_const s) hZ + have h := gaussianReal_const_add (gaussianReal_const_mul hZQ (σ * s)) (vasicekSDEMean r₀ θ κ T) + convert h using 2 + · field_simp + · simp only [c, vasicekBondB]; field_simp; ring + · ext + have hvσ : 0 ≤ vasicekSDEVariance σ κ T := vasicekSDEVariance_nonneg σ hκ T.2 + simp only [Real.coe_toNNReal _ hvσ, NNReal.coe_mk, mul_one] + rw [mul_pow, hss] + unfold vasicekSDEVariance + ring + +/-- **The terminal Esscher tilt and the Girsanov measure give `r_T` the same law**: +`N(mean_θ − lam·σ·B(T), var)` under both (`vasicekShortRate_hasLaw_esscherTilt`, +`vasicekShortRate_hasLaw_girsanov`). Only this terminal marginal is shared. The Girsanov measure +also prices the bond (`vasicekBondPrice_girsanov`); the tilt does not. -/ +theorem vasicekShortRate_map_esscherTilt_eq_map_girsanov (hB : IsPreBrownianReal B μ) + (r₀ θ σ lam : ℝ) {κ : ℝ} (hκ : 0 < κ) (T : ℝ≥0) (hT : 0 < T) : + let I : Ω → ℝ := fun ω ↦ wienerIntegralLp B hB T (vasicekKernelLp κ hκ.le T) ω + let s : ℝ := Real.sqrt (vasicekSDEVariance 1 κ T) + let c : ℝ := -(lam * vasicekBondB κ T) / s + (μ.withDensity fun ω ↦ ENNReal.ofReal (Real.exp (c * (I ω / s) - c ^ 2 / 2))).map + (fun ω ↦ vasicekSDEMean r₀ θ κ T + σ * I ω) + = (μ.withDensity fun ω ↦ ENNReal.ofReal (Real.exp (-lam * B T ω - lam ^ 2 * (T : ℝ) / 2))).map + (fun ω ↦ vasicekSDEMean r₀ θ κ T + σ * I ω) := + (vasicekShortRate_hasLaw_esscherTilt hB r₀ θ σ lam hκ T hT).map_eq.trans + (vasicekShortRate_hasLaw_girsanov hB r₀ θ σ lam hκ T).map_eq.symm + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/VasicekSDE.lean b/LeanPool/MathFin/Models/Rates/VasicekSDE.lean new file mode 100644 index 0000000000..ba02576128 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/VasicekSDE.lean @@ -0,0 +1,154 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho, Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.Vasicek +public import Mathlib.Algebra.Order.Star.Real + +/-! +# Vasicek SDE terminal-distribution form (stated, not derived) (phase 41) + +The pre-existing `Models/Rates/Vasicek.lean` derives only the +**deterministic part** of the Vasicek mean-reverting short-rate model +(the `σ = 0` ODE). This file extends to the **full SDE** + + `dr_t = κ (θ − r_t) dt + σ dB_t`, + +whose closed-form solution is + + `r_t = r_0 · e^{−κt} + θ · (1 − e^{−κt}) + σ · ∫_0^t e^{−κ(t−s)} dB_s`. + +The Itô integral `∫_0^t e^{−κ(t−s)} dB_s` is of a *deterministic* +integrand, so its law is Gaussian (an Itô integral of a deterministic +integrand is an L² limit of independent Gaussian increments; see the +continuous construction in `Probability/Brownian/Ito/ItoIntegralL2.lean`). The integrand's +L² norm gives the variance: + + `Var = σ² · ∫_0^t e^{−2κ(t−s)} ds = σ² · (1 − e^{−2κt}) / (2κ)`. + +Hence under the SDE, + + `r_t ~ N( r_0 · e^{−κt} + θ · (1 − e^{−κt}), σ² · (1 − e^{−2κt}) / (2κ) )`. + +This file gives the explicit *terminal-distribution* form, parameterised +by a standard normal `Z`, in the same style as `BSCallHyp`. + +## Why this is open now + +Phase 36 (simple-process Itô integral) + Phase 32 (BQV identities) + +the deterministic Riemann integral `∫ e^{−2κ(t−s)} ds = (1 − e^{−2κt})/(2κ)` +give the variance computation. The Gaussian-distribution conclusion +follows from the structural fact that Itô integrals of deterministic +integrands are Gaussian (a consequence of the simple-process +construction being a sum of independent Gaussian increments). + +## What this file is + +A **terminal-distribution-form** hypothesis-and-closed-form pairing, in +the BSCallHyp style. The full SDE-to-distribution derivation is the +content of Phase 41 conceptually; the file states the closed form +explicitly so that downstream consumers can use it without re-deriving. + +## Main definitions + +* `vasicekSDEMean`: the Vasicek mean `r_0 · e^{−κt} + θ · (1 − e^{−κt})`. +* `vasicekSDEVariance`: the Vasicek variance `σ² · (1 − e^{−2κt}) / (2κ)`. +* `vasicekSDETerminal`: the terminal short rate `mean + √var · Z` as a function of `Z ~ N(0, 1)`. + +## Main results + +* `vasicekSDE_variance_pos`: positivity of variance for `κ > 0`, `σ ≠ 0`. +* `vasicekSDE_mean_at_zero`: `r_t = r_0` at `t = 0`. + +## Tags + +Vasicek model, short rate SDE, Ornstein–Uhlenbeck, terminal distribution, Gaussian short rate, +mean reversion, MSC 91G30, MSC 60H10, JEL E43 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- **Vasicek SDE mean**: `r_0 · e^{−κt} + θ · (1 − e^{−κt})`. Identical +to the deterministic-part closed form `vasicekDeterministic`. -/ +noncomputable def vasicekSDEMean (r_0 θ κ t : ℝ) : ℝ := + r_0 * Real.exp (-(κ * t)) + θ * (1 - Real.exp (-(κ * t))) + +/-- The SDE mean is the deterministic closed form `vasicekDeterministic`. -/ +theorem vasicekSDEMean_eq_deterministic (r_0 θ κ t : ℝ) : + vasicekSDEMean r_0 θ κ t = vasicekDeterministic r_0 θ κ t := by + unfold vasicekSDEMean vasicekDeterministic; ring + +/-- **Vasicek SDE variance**: `σ² · (1 − e^{−2κt}) / (2κ)`. The L² norm +of the deterministic integrand `e^{−κ(t−·)}` on `[0, t]` against `dB`, +via the simple-Itô isometry. -/ +noncomputable def vasicekSDEVariance (σ κ t : ℝ) : ℝ := + σ ^ 2 * (1 - Real.exp (-(2 * κ * t))) / (2 * κ) + +/-- **Vasicek SDE terminal distribution**: with `Z ~ N(0, 1)`, +`r_t(Z) = mean + √var · Z` has the Gaussian law `N(mean, var)`. -/ +noncomputable def vasicekSDETerminal + (r_0 θ κ σ t : ℝ) (Z : ℝ) : ℝ := + vasicekSDEMean r_0 θ κ t + Real.sqrt (vasicekSDEVariance σ κ t) * Z + +/-- **Mean at `t = 0`** equals the initial value `r_0`. -/ +lemma vasicekSDE_mean_at_zero (r_0 θ κ : ℝ) : + vasicekSDEMean r_0 θ κ 0 = r_0 := by + unfold vasicekSDEMean + simp + +/-- **Variance at `t = 0`** is zero (no diffusion yet). -/ +lemma vasicekSDE_variance_at_zero (σ κ : ℝ) (_hκ : κ ≠ 0) : + vasicekSDEVariance σ κ 0 = 0 := by + unfold vasicekSDEVariance + simp + +/-- **Variance positivity** for positive `κ, t` and non-zero `σ`: as `2κt +> 0`, `e^{−2κt} < 1`, so the variance numerator `1 − e^{−2κt} > 0`. The +denominator `2κ > 0` and `σ² > 0` (from `σ ≠ 0`) make the whole variance +strictly positive. -/ +lemma vasicekSDE_variance_pos (σ κ t : ℝ) + (hκ : 0 < κ) (ht : 0 < t) (hσ : σ ≠ 0) : + 0 < vasicekSDEVariance σ κ t := by + unfold vasicekSDEVariance + have h_κt_pos : 0 < 2 * κ * t := by positivity + have h_exp_lt : Real.exp (-(2 * κ * t)) < 1 := by + rw [show (1 : ℝ) = Real.exp 0 from (Real.exp_zero).symm] + exact Real.exp_lt_exp.mpr (by linarith) + have h_num_pos : 0 < 1 - Real.exp (-(2 * κ * t)) := by linarith + have h_den_pos : 0 < 2 * κ := by linarith + have h_σ_sq_pos : 0 < σ ^ 2 := by + rw [sq] + exact mul_self_pos.mpr hσ + positivity + +/-- **Variance nonnegativity** for `κ > 0`, `t ≥ 0`, any `σ` (no sign hypothesis on `σ` +needed, unlike `vasicekSDE_variance_pos`'s strict form). -/ +lemma vasicekSDEVariance_nonneg (σ : ℝ) {κ : ℝ} (hκ : 0 < κ) {t : ℝ} (ht : 0 ≤ t) : + 0 ≤ vasicekSDEVariance σ κ t := by + unfold vasicekSDEVariance + have : Real.exp (-(2 * κ * t)) ≤ 1 := + Real.exp_le_one_iff.2 (neg_nonpos.2 (by positivity)) + positivity + +open Filter Topology in +/-- **The long-run variance.** For `κ > 0` the closed-form Vasicek variance +`σ²(1 − e^{−2κt})/(2κ)` tends to `σ²/(2κ)` as `t → ∞` — the variance of the textbook +stationary law; no stationary law is constructed here. -/ +theorem tendsto_vasicekSDEVariance_atTop (σ : ℝ) {κ : ℝ} (hκ : 0 < κ) : + Tendsto (fun t ↦ vasicekSDEVariance σ κ t) atTop (𝓝 (σ ^ 2 / (2 * κ))) := by + have he : Tendsto (fun t : ℝ ↦ Real.exp (-(2 * κ * t))) atTop (𝓝 0) := + Real.tendsto_exp_neg_atTop_nhds_zero.comp + (Tendsto.const_mul_atTop (by positivity) tendsto_id) + unfold vasicekSDEVariance + simpa using ((he.const_sub 1).const_mul (σ ^ 2)).div_const (2 * κ) + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/VasicekSDEGaussian.lean b/LeanPool/MathFin/Models/Rates/VasicekSDEGaussian.lean new file mode 100644 index 0000000000..9bcebb5164 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/VasicekSDEGaussian.lean @@ -0,0 +1,174 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho, Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralGaussian +public import LeanPool.MathFin.Models.Rates.VasicekSDE + +/-! +# Vasicek terminal distribution of the Ornstein–Uhlenbeck solution (Itô→pricing bridge) + +`Models/Rates/VasicekSDE.lean` *posited* the terminal law of the Vasicek short +rate `r_t ~ N(mean, var)` as closed-form `def`s, in the `BSCallHyp` style. + +This file **derives** that law for the short rate in its Wiener representation. The Vasicek +SDE `dr_t = κ(θ − r_t)dt + σ dB_t` has, as a textbook fact cited and not proved here, the +solution + + `r_t = r₀ e^{−κt} + θ(1 − e^{−κt}) + σ ∫₀ᵗ e^{−κ(t−s)} dB_s`, + +whose stochastic term is the Wiener integral of the **deterministic** integrand +`e^{−κ(t−s)}`. By `wienerIntegralLp_hasLaw_gaussian` +(`Probability/Brownian/Wiener/WienerIntegralGaussian.lean`) that integral is Gaussian, centred, +with variance its `L²`-norm `∫₀ᵗ e^{−2κ(t−s)} ds = (1 − e^{−2κt})/(2κ)` — exactly +`vasicekSDEVariance σ κ t / σ²`. The affine map `x ↦ mean + σ x` then sends the +law to `gaussianReal (vasicekSDEMean) (vasicekSDEVariance)`. + +This is the **first consumer of the deterministic-integrand Itô tower in the +FixedIncome layer** — the analytic Wiener/Itô machinery becomes load-bearing in +a pricing module, closing the two-tower gap for the Vasicek short rate. + +## Main definitions + +* `vasicekKernel`, `vasicekKernelLp`: the diffusion kernel `s ↦ e^{−κ(T−s)}`, and the same kernel + as an element of `L²((0, T])`. +* `vasicekKernelSqAntideriv`: the antiderivative `u ↦ e^{−2κ(T−u)}/(2κ)` of the squared kernel. +* `vasicekDiffusionTerm`: the Vasicek diffusion term `σ ∫₀ᵀ e^{−κ(T−s)} dB_s`. + +## Main results + +* `vasicekKernel_integral_sq`: `∫₀ᵀ (e^{−κ(T−s)})² ds = (1 − e^{−2κT})/(2κ)`. +* `vasicekShortRate_hasLaw_gaussian`: the genuine terminal short rate + `mean + σ ∫₀ᵀ e^{−κ(T−s)} dB_s` has law `N(vasicekSDEMean, vasicekSDEVariance)`. + +## References + +* [O. Vasicek, *An equilibrium characterization of the term structure*][Vasicek1977] + +## Tags + +Vasicek model, Ornstein–Uhlenbeck, Wiener integral, Gaussian law, short rate, +Itô integral of deterministic integrand, MSC 60H10, MSC 91G30, MSC 60G15 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real Set +open scoped NNReal +open WienerIntegralL2 + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-! ### The Vasicek diffusion kernel `e^{−κ(T−s)}` as an `L²` integrand -/ + +/-- The Vasicek diffusion kernel `s ↦ e^{−κ(T−s)}`. -/ +noncomputable def vasicekKernel (κ T : ℝ) : ℝ → ℝ := fun s ↦ Real.exp (-(κ * (T - s))) + +/-- The kernel is in `L²((0, T])` (continuous, bounded by `1` on the support +for `κ ≥ 0`). -/ +lemma vasicekKernel_memLp (κ : ℝ) (hκ : 0 ≤ κ) (T : ℝ≥0) : + MemLp (vasicekKernel κ T) 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := by + refine (memLp_top_of_bound (by unfold vasicekKernel; fun_prop) 1 ?_).mono_exponent le_top + refine (ae_restrict_iff' measurableSet_Ioc).mpr (ae_of_all _ ?_) + intro s hs + rw [vasicekKernel, Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] + refine Real.exp_le_one_iff.mpr ?_ + have hTs : 0 ≤ (T : ℝ) - s := by linarith [hs.2] + nlinarith [mul_nonneg hκ hTs] + +/-- The kernel as an element of `L²((0, T])`. -/ +noncomputable def vasicekKernelLp (κ : ℝ) (hκ : 0 ≤ κ) (T : ℝ≥0) : + Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := + (vasicekKernel_memLp κ hκ T).toLp _ + +/-! ### The kernel's `L²`-norm is the Vasicek variance (the deterministic integral) -/ + +/-- The antiderivative `u ↦ e^{−2κ(T−u)}/(2κ)` of the squared diffusion kernel +`(e^{−κ(T−u)})²`. -/ +noncomputable def vasicekKernelSqAntideriv (κ T u : ℝ) : ℝ := + Real.exp (-(2 * κ * (T - u))) / (2 * κ) + +/-- For `κ ≠ 0`, `vasicekKernelSqAntideriv` differentiates to the squared kernel +`(e^{−κ(T−u)})² = e^{−2κ(T−u)}`. -/ +lemma hasDerivAt_vasicekKernelSqAntideriv (κ T u : ℝ) (hκ : κ ≠ 0) : + HasDerivAt (vasicekKernelSqAntideriv κ T) ((vasicekKernel κ T u) ^ 2) u := by + have hsq : (vasicekKernel κ T u) ^ 2 = Real.exp (-(2 * κ * (T - u))) := by + rw [vasicekKernel, sq, ← Real.exp_add] + congr 1 + ring + have h1 : HasDerivAt (fun u ↦ -(2 * κ * (T - u))) (2 * κ) u := by + have : HasDerivAt (fun u ↦ -(2 * κ * (T - u))) (-(2 * κ * (-1))) u := by + apply HasDerivAt.neg + apply HasDerivAt.const_mul + simpa using (hasDerivAt_id u).const_sub T + simpa using this + have h3 := ((Real.hasDerivAt_exp _).comp u h1).div_const (2 * κ) + rw [hsq] + rwa [mul_div_assoc, div_self (mul_ne_zero two_ne_zero hκ), mul_one] at h3 + +/-- The FTC form over any interval, for `κ ≠ 0`: +`∫_A^B (e^{−κ(T−u)})² du = e^{−2κ(T−B)}/(2κ) − e^{−2κ(T−A)}/(2κ)`. -/ +lemma integral_vasicekKernel_sq_eq_sub (κ T A B : ℝ) (hκ : κ ≠ 0) : + ∫ u in A..B, (vasicekKernel κ T u) ^ 2 + = vasicekKernelSqAntideriv κ T B - vasicekKernelSqAntideriv κ T A := + intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun u _ ↦ hasDerivAt_vasicekKernelSqAntideriv κ T u hκ) + (Continuous.intervalIntegrable (by unfold vasicekKernel; fun_prop) _ _) + +/-- **The Riemann integral fixing the variance**: +`∫₀ᵀ (e^{−κ(T−s)})² ds = (1 − e^{−2κT})/(2κ)`, by the FTC with antiderivative +`vasicekKernelSqAntideriv`. -/ +lemma vasicekKernel_integral_sq (κ : ℝ) (hκ : κ ≠ 0) (T : ℝ≥0) : + ∫ s in Set.Ioc (0 : ℝ) (T : ℝ), (vasicekKernel κ T s) ^ 2 ∂volume + = (1 - Real.exp (-(2 * κ * T))) / (2 * κ) := by + rw [← intervalIntegral.integral_of_le T.coe_nonneg, integral_vasicekKernel_sq_eq_sub κ T 0 T hκ] + simp only [vasicekKernelSqAntideriv, sub_self, sub_zero, mul_zero, neg_zero, Real.exp_zero] + ring + +/-! ### The genuine terminal short rate and its derived Gaussian law -/ + +/-- The genuine Vasicek diffusion term `σ ∫₀ᵀ e^{−κ(T−s)} dB_s`. -/ +noncomputable def vasicekDiffusionTerm (hB : IsPreBrownianReal B μ) (κ σ : ℝ) + (hκ : 0 ≤ κ) (T : ℝ≥0) (ω : Ω) : ℝ := + σ * (wienerIntegralLp B hB T (vasicekKernelLp κ hκ T) ω) + +/-- **Vasicek terminal law, derived.** The short rate in its Wiener representation +`r_T = vasicekSDEMean + σ ∫₀ᵀ e^{−κ(T−s)} dB_s` (the textbook solution of the Vasicek SDE; +that it solves the SDE is cited, not proved) has the +Gaussian law `N(vasicekSDEMean, vasicekSDEVariance)` — the closed form `VasicekSDE.lean` +posited is now a theorem. -/ +theorem vasicekShortRate_hasLaw_gaussian (hB : IsPreBrownianReal B μ) + (r₀ θ σ : ℝ) {κ : ℝ} (hκ : 0 < κ) (T : ℝ≥0) : + HasLaw (fun ω ↦ vasicekSDEMean r₀ θ κ (T : ℝ) + + σ * (wienerIntegralLp B hB T (vasicekKernelLp κ hκ.le T) ω)) + (gaussianReal (vasicekSDEMean r₀ θ κ (T : ℝ)) (vasicekSDEVariance σ κ (T : ℝ)).toNNReal) + μ := by + -- The Wiener integral of the kernel is Gaussian, centred, variance = ∫ kernel². + have hW := wienerIntegralLp_hasLaw_gaussian_of_integral_sq hB T (vasicekKernelLp κ hκ.le T) + ((vasicekKernel_memLp κ hκ.le T).integral_sq_toLp.trans + (vasicekKernel_integral_sq κ hκ.ne' T)) + -- Scale by σ then shift by the mean; the affine map sends N(0, ∫kernel²) to N(mean, σ²·∫kernel²). + have hkernel_nonneg : (0 : ℝ) ≤ (1 - Real.exp (-(2 * κ * (T : ℝ)))) / (2 * κ) := by + simpa [vasicekSDEVariance] using vasicekSDEVariance_nonneg 1 hκ (NNReal.coe_nonneg T) + have hvar_nonneg : (0 : ℝ) ≤ vasicekSDEVariance σ κ (T : ℝ) := + vasicekSDEVariance_nonneg σ hκ (NNReal.coe_nonneg T) + have hShift := gaussianReal_const_add (gaussianReal_const_mul hW σ) + (vasicekSDEMean r₀ θ κ (T : ℝ)) + convert hShift using 2 + · ring + · refine NNReal.coe_injective ?_ + rw [Real.coe_toNNReal _ hvar_nonneg, NNReal.coe_mul, NNReal.coe_mk, + Real.coe_toNNReal _ hkernel_nonneg] + unfold vasicekSDEVariance + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/VasicekYieldNelsonSiegel.lean b/LeanPool/MathFin/Models/Rates/VasicekYieldNelsonSiegel.lean new file mode 100644 index 0000000000..c8a6c034ef --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/VasicekYieldNelsonSiegel.lean @@ -0,0 +1,165 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.NelsonSiegelSvensson +public import LeanPool.MathFin.Models.Rates.VasicekBondPrice + +/-! +# The Vasicek yield curve in Nelson–Siegel factors + +The Nelson–Siegel slope factor `s(x) = (1 − e^{−x})/x` (`nssSlope`, +`Models/Rates/NelsonSiegelSvensson.lean`) is the Vasicek rate loading per unit maturity: +`s(κτ) = B(τ)/τ` with `B = vasicekBondB` (`vasicekBondB_div_eq_nssSlope`). This file takes the +Vasicek bond price `P(0,T) = 𝔼[exp(−∫₀ᵀ r_s ds)]` that `vasicekBondPrice_eq` +(`Models/Rates/VasicekBondPrice.lean`) derives, and writes its continuously compounded zero +yield `y(T) = −log P(0,T)/T` in slope factors: + + `y(T) = (θ − σ²/(2κ²)) + (r₀ − θ + σ²/κ²)·s(κT) − (σ²/(2κ²))·s(2κT)`. + +So the Vasicek curve is a level plus slope factors at the two decay rates `κ` and `2κ`. With +`σ = 0` it is exactly a three-factor Nelson–Siegel curve (level `θ`, slope `r₀ − θ`, no +curvature, decay `1/κ`: `vasicekYield_zeroVol_eq_nssYield`). With `σ ≠ 0` the formula carries +a second slope factor `s(2κT)`, which is not one of the Svensson terms as written (a Svensson +curvature term is `s(τ/l₂) − e^{−τ/l₂}`); whether the curve can be rewritten in Svensson form +is not addressed here. + +The slope factor's limits (`tendsto_nssSlope_nhdsNE_zero`, `tendsto_nssSlope_atTop`) then give +the two ends of the Vasicek curve: the yield tends to the short rate `r₀` as `T → 0⁺`, and to +the long rate `θ − σ²/(2κ²)` as `T → ∞`. + +As in `vasicekBondPrice_eq`, the expectation is under the probability measure carrying the +Brownian motion, read as the pricing measure, and the integrated short rate is carried in its +Wiener representation. + +## Main results + +* `vasicekBondB_div_eq_nssSlope` — `vasicekBondB κ τ / τ = nssSlope (κ * τ)`. +* `vasicekBondV_div_eq_nssSlope` — `V(T)/T = (1 − 2 s(κT) + s(2κT))/κ²`. +* `vasicekYield_eq_nssSlope` — the Vasicek zero yield in slope factors, for `κ, T > 0`. +* `vasicekYield_zeroVol_eq_nssYield` — at `σ = 0`, the yield is the Nelson–Siegel curve + `nssYield θ (r₀ − θ) 0 0 κ⁻¹ l₂`. +* `tendsto_vasicekYield_nhdsGT_zero` — `y(T) → r₀` as `T → 0⁺`. +* `tendsto_vasicekYield_atTop` — `y(T) → θ − σ²/(2κ²)` as `T → ∞`. + +## References + +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + §3.2.1 +* [C. R. Nelson and A. F. Siegel, *Parsimonious modeling of yield curves*][NelsonSiegel1987] +* [O. Vasicek, *An equilibrium characterization of the term structure*][Vasicek1977] + +## Tags + +Vasicek model, Nelson–Siegel curve, zero yield, term structure, slope factor, long rate, JEL E43, +MSC 91G30 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Filter Topology +open scoped NNReal + +/-- **The Nelson–Siegel slope factor is the Vasicek loading per unit maturity**: +`vasicekBondB κ τ / τ = nssSlope (κ τ)`, both being `(1 − e^{−κτ})/(κτ)`. The two definitions +were written independently, in `VasicekBondPrice` and `NelsonSiegelSvensson`. -/ +theorem vasicekBondB_div_eq_nssSlope (κ τ : ℝ) : vasicekBondB κ τ / τ = nssSlope (κ * τ) := by + rw [vasicekBondB, nssSlope, div_div] + +/-- The Vasicek variance per unit maturity in slope factors: +`V(T)/T = (1 − 2 s(κT) + s(2κT))/κ²`, for `κ, T ≠ 0`. -/ +theorem vasicekBondV_div_eq_nssSlope {κ T : ℝ} (hκ : κ ≠ 0) (hT : T ≠ 0) : + vasicekBondV κ T / T = (1 - 2 * nssSlope (κ * T) + nssSlope (2 * κ * T)) / κ ^ 2 := by + simp only [vasicekBondV, nssSlope] + field_simp + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-- **The Vasicek zero yield in Nelson–Siegel slope factors.** For `κ > 0` and maturity +`T > 0`, the continuously compounded yield of the Vasicek bond price +`P(0,T) = 𝔼[exp(−∫₀ᵀ r_s ds)]` (`vasicekBondPrice_eq`) is +`(θ − σ²/(2κ²)) + (r₀ − θ + σ²/κ²)·s(κT) − (σ²/(2κ²))·s(2κT)`, with `s = nssSlope`. -/ +theorem vasicekYield_eq_nssSlope (hB : IsPreBrownianReal B μ) (r₀ θ σ : ℝ) {κ : ℝ} + (hκ : 0 < κ) (T : ℝ≥0) (hT : 0 < (T : ℝ)) : + -Real.log (∫ ω, Real.exp (-(vasicekIntegratedRate hB r₀ θ σ hκ T ω)) ∂μ) / T + = θ - σ ^ 2 / (2 * κ ^ 2) + (r₀ - θ + σ ^ 2 / κ ^ 2) * nssSlope (κ * T) + - σ ^ 2 / (2 * κ ^ 2) * nssSlope (2 * κ * T) := by + have hκ0 : κ ≠ 0 := hκ.ne' + have hT0 : (T : ℝ) ≠ 0 := hT.ne' + rw [vasicekBondPrice_eq hB r₀ θ σ hκ T, Real.log_exp] + simp only [vasicekIntegratedMean, vasicekBondB, vasicekBondV, nssSlope] + field_simp + ring + +/-- **With zero volatility the Vasicek curve is a Nelson–Siegel curve**: level `θ`, slope +`r₀ − θ`, no curvature, decay `κ⁻¹` (the Svensson decay `l₂` is unused, its loading being +zero). -/ +theorem vasicekYield_zeroVol_eq_nssYield (hB : IsPreBrownianReal B μ) (r₀ θ : ℝ) {κ : ℝ} + (hκ : 0 < κ) (T : ℝ≥0) (hT : 0 < (T : ℝ)) (l₂ : ℝ) : + -Real.log (∫ ω, Real.exp (-(vasicekIntegratedRate hB r₀ θ 0 hκ T ω)) ∂μ) / T + = nssYield θ (r₀ - θ) 0 0 κ⁻¹ l₂ T := by + rw [vasicekYield_eq_nssSlope hB r₀ θ 0 hκ T hT, nssYield, div_inv_eq_mul, mul_comm (T : ℝ) κ] + ring + +/-- `T ↦ c·T` sends `T → 0⁺` (in `ℝ≥0`) to `x → 0` through nonzero values, for `c ≠ 0`. -/ +theorem tendsto_const_mul_coe_nhdsNE {c : ℝ} (hc : c ≠ 0) : + Tendsto (fun T : ℝ≥0 ↦ c * (T : ℝ)) (𝓝[>] 0) (𝓝[≠] 0) := by + rw [tendsto_nhdsWithin_iff] + refine ⟨?_, ?_⟩ + · have h : Tendsto (fun T : ℝ≥0 ↦ c * (T : ℝ)) (𝓝 0) (𝓝 (c * ((0 : ℝ≥0) : ℝ))) := + (continuous_const.mul NNReal.continuous_coe).tendsto 0 + simpa using h.mono_left nhdsWithin_le_nhds + · filter_upwards [self_mem_nhdsWithin] with T hT + simp only [Set.mem_compl_iff, Set.mem_singleton_iff] + exact mul_ne_zero hc (NNReal.coe_pos.mpr hT).ne' + +/-- **The short end of the Vasicek curve is the short rate**: `y(T) → r₀` as `T → 0⁺`, from +`s(x) → 1` as `x → 0`. -/ +theorem tendsto_vasicekYield_nhdsGT_zero (hB : IsPreBrownianReal B μ) (r₀ θ σ : ℝ) {κ : ℝ} + (hκ : 0 < κ) : + Tendsto (fun T : ℝ≥0 ↦ + -Real.log (∫ ω, Real.exp (-(vasicekIntegratedRate hB r₀ θ σ hκ T ω)) ∂μ) / T) + (𝓝[>] 0) (𝓝 r₀) := by + have hlim : Tendsto (fun T : ℝ≥0 ↦ θ - σ ^ 2 / (2 * κ ^ 2) + + (r₀ - θ + σ ^ 2 / κ ^ 2) * nssSlope (κ * T) - σ ^ 2 / (2 * κ ^ 2) * nssSlope (2 * κ * T)) + (𝓝[>] 0) + (𝓝 (θ - σ ^ 2 / (2 * κ ^ 2) + (r₀ - θ + σ ^ 2 / κ ^ 2) * 1 - σ ^ 2 / (2 * κ ^ 2) * 1)) := + (tendsto_const_nhds.add ((tendsto_nssSlope_nhdsNE_zero.comp + (tendsto_const_mul_coe_nhdsNE hκ.ne')).const_mul _)).sub + ((tendsto_nssSlope_nhdsNE_zero.comp + (tendsto_const_mul_coe_nhdsNE (mul_ne_zero two_ne_zero hκ.ne'))).const_mul _) + rw [show θ - σ ^ 2 / (2 * κ ^ 2) + (r₀ - θ + σ ^ 2 / κ ^ 2) * 1 - σ ^ 2 / (2 * κ ^ 2) * 1 + = r₀ by ring] at hlim + refine hlim.congr' ?_ + filter_upwards [self_mem_nhdsWithin] with T hT + exact (vasicekYield_eq_nssSlope hB r₀ θ σ hκ T (NNReal.coe_pos.mpr hT)).symm + +/-- **The Vasicek long rate**: `y(T) → θ − σ²/(2κ²)` as `T → ∞`, from `s(x) → 0` as +`x → ∞`. -/ +theorem tendsto_vasicekYield_atTop (hB : IsPreBrownianReal B μ) (r₀ θ σ : ℝ) {κ : ℝ} + (hκ : 0 < κ) : + Tendsto (fun T : ℝ≥0 ↦ + -Real.log (∫ ω, Real.exp (-(vasicekIntegratedRate hB r₀ θ σ hκ T ω)) ∂μ) / T) + atTop (𝓝 (θ - σ ^ 2 / (2 * κ ^ 2))) := by + have hT : Tendsto (fun T : ℝ≥0 ↦ (T : ℝ)) atTop atTop := NNReal.tendsto_coe_atTop.mpr tendsto_id + have hlim : Tendsto (fun T : ℝ≥0 ↦ θ - σ ^ 2 / (2 * κ ^ 2) + + (r₀ - θ + σ ^ 2 / κ ^ 2) * nssSlope (κ * T) - σ ^ 2 / (2 * κ ^ 2) * nssSlope (2 * κ * T)) + atTop + (𝓝 (θ - σ ^ 2 / (2 * κ ^ 2) + (r₀ - θ + σ ^ 2 / κ ^ 2) * 0 - σ ^ 2 / (2 * κ ^ 2) * 0)) := + (tendsto_const_nhds.add ((tendsto_nssSlope_atTop.comp + (hT.const_mul_atTop hκ)).const_mul _)).sub + ((tendsto_nssSlope_atTop.comp (hT.const_mul_atTop (mul_pos two_pos hκ))).const_mul _) + rw [mul_zero, mul_zero, add_zero, sub_zero] at hlim + refine hlim.congr' ?_ + filter_upwards [eventually_gt_atTop 0] with T hT0 + exact (vasicekYield_eq_nssSlope hB r₀ θ σ hκ T (NNReal.coe_pos.mpr hT0)).symm + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/VasicekZeroMeanReversionLimit.lean b/LeanPool/MathFin/Models/Rates/VasicekZeroMeanReversionLimit.lean new file mode 100644 index 0000000000..5fd4efc84f --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/VasicekZeroMeanReversionLimit.lean @@ -0,0 +1,378 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.VasicekBondPrice +public import LeanPool.MathFin.Models.Rates.VasicekMarketPriceOfRisk + +/-! +# The Vasicek bond price at vanishing mean reversion + +`Models/Rates/VasicekBondPrice.lean` prices the zero-coupon bond under the Vasicek short rate, +`P(0,T) = exp(−M(T) + σ²V(T)/2)` (`vasicekBondPrice_eq`), for every `κ > 0`. This file takes +`κ → 0⁺` in that closed form and shows it lands on the bond price of the driftless Gaussian +short rate `r_s = r₀ + σB_s`, which is priced here a second time, directly, with no Vasicek +formula and no limit (both models carried in their Wiener representation, see Scope): + + `exp(−M(T) + σ²V(T)/2) → exp(−r₀T + σ²T³/6) = 𝔼[exp(−r₀T − σ∫₀ᵀ (T − u) dB_u)]`. + +Limit algebra on the existing definitions (`vasicekBondB`, `vasicekIntegratedMean`, +`vasicekBondV`, `vasicekBondA`); the only new probability is the second route, one more instance +of the Wiener bond-price lemma `integral_exp_neg_add_mul_wienerIntegralLp`. + +## What the formalization forces + +* **The variance limit is a cancellation, not a lemma.** `V(T) = T/κ² − 2(1−e^{−κT})/κ³ + + (1−e^{−2κT})/(2κ³)` is a sum of three terms each of leading order `κ⁻²` (both exponential + numerators vanish linearly in `κ`, so dividing by `κ³` leaves `κ⁻²`); for `T > 0` the middle + one alone tends to `−∞`. No limit rule applies term by term. `abs_vasicekBondV_sub_le` + substitutes the cubic Taylor polynomials of `e^{−κT}` and `e^{−2κT}` (from `Real.exp_bound` + at `n = 4`), the divergent orders `κ⁻², κ⁻¹` cancel exactly, and what is left is the explicit + rate + `|V(T) − T³/3| ≤ 10·|κ|·T⁴` for `|2κT| ≤ 1`. The limit follows by a squeeze. This is the + cancellation a small-`a` branch of QuantLib's `Vasicek::A` has to resolve, here with a stated + error bound. +* **Substitution is not the limit.** Lean's `x / 0 = 0` makes the closed form total at `κ = 0`, + where it evaluates to `exp(−θT)` (`vasicekBondPrice_closedForm_zero_meanReversion`): the price + of a rate pinned at the long-run level, independent of `r₀` and `σ`. The limit is + `exp(−r₀T + σ²T³/6)`, independent of `θ`. A small-`κ` branch must return the limit; any other + value, including the junk value of the `κ > 0` formula, is a different model. +* **The `λ` sign is a convention, fixed by the measure.** Under this library's Girsanov density + `exp(−λB_T − λ²T/2)` the risk-adjusted level is `θ − λσ/κ` + (`vasicekBondPrice_girsanov`), and the `κ → 0⁺` limit of the risk-neutral price is + `exp(−r₀T + λσT²/2 + σ²T³/6)` (`tendsto_vasicekBondPrice_girsanov_zero_meanReversion`). + QuantLib's `Vasicek::A` uses the level `b + λσ/a`, so its `λ` is the negative of the one here. + `A` alone is only the affine factor, not the price (the price is `A·exp(−B·r₀)`, and + `tendsto_vasicekBondA_zero_meanReversion` below gives `A`'s own `λ = 0` limit); the proved + price limit `tendsto_vasicekBondPrice_girsanov_zero_meanReversion` matches QuantLib's + convention under that sign flip. + +## Scope (disclosed) + +* The driftless model is carried, like `vasicekIntegratedRate`, in its Wiener representation + `∫₀ᵀ r_s ds = r₀T + σ∫₀ᵀ (T − u) dB_u`; the time-order swap `∫₀ᵀ B_s ds = ∫₀ᵀ (T − u) dB_u` + is the cited modelling bridge, not proved. +* The limits are stated for the closed forms. For each `κ > 0` the closed form is the + expectation (`vasicekBondPrice_eq`, `vasicekBondPrice_girsanov_eq`); no convergence of the + random variables `∫₀ᵀ r^κ_s ds` as `κ → 0⁺` is claimed. + +## Main definitions + +* `brownianIntegratedKernelLp`: the driftless integrated kernel `u ↦ T − u` as an element of + `L²((0, T])`. +* `brownianIntegratedRate`: the integrated driftless Gaussian short rate in its Wiener + representation, `∫₀ᵀ (r₀ + σB_s) ds = r₀·T + σ·∫₀ᵀ (T − u) dB_u`. + +## Main results + +* `tendsto_vasicekBondB_zero_meanReversion`: `B(T) → T` as `κ → 0` (two-sided). +* `abs_vasicekBondV_sub_le`: `|V(T) − T³/3| ≤ 10·|κ|·T⁴` for `κ ≠ 0`, `|2κT| ≤ 1`. +* `tendsto_vasicekBondV_zero_meanReversion`: `V(T) → T³/3`. +* `tendsto_vasicekIntegratedMean_zero_meanReversion`: `M(T) → r₀T`. +* `tendsto_vasicekBondPrice_zero_meanReversion`: `exp(−M(T) + σ²V(T)/2) → exp(−r₀T + σ²T³/6)`. +* `tendsto_vasicekBondA_zero_meanReversion`: QuantLib's `A(t,T)` tends to `exp(σ²T³/6)`. +* `vasicekBondPrice_closedForm_zero_meanReversion`: the `κ = 0` substitution gives `exp(−θT)`. +* `brownianBondPrice_eq`: the driftless model's price `exp(−r₀T + σ²T³/6)`, derived directly. +* `tendsto_vasicekBondPrice_brownianBondPrice`: the two routes agree. +* `tendsto_vasicekBondPrice_girsanov_zero_meanReversion`: with a market price of risk `λ`, the + limit is `exp(−r₀T + λσT²/2 + σ²T³/6)`. + +## References + +* [The QuantLib contributors, *QuantLib*][QuantLib], Vasicek::A (vasicek.cpp, PR #2599) +* [O. Vasicek, *An equilibrium characterization of the term structure*][Vasicek1977] + +## Tags + +Vasicek model, zero-coupon bond price, vanishing mean reversion, Gaussian short rate, +Taylor cancellation, risk-neutral pricing, MSC 91G30, JEL E43 +-/ + +@[expose] public section + +namespace MathFin + +open Real Filter Topology + +/-- The cubic Taylor polynomial of `exp` with an explicit quartic remainder bound on `|x| ≤ 1`, +from `Real.exp_bound` at `n = 4` (whose constant `5/96` is relaxed to `1`). -/ +lemma abs_exp_sub_cubic_le {x : ℝ} (hx : |x| ≤ 1) : + |Real.exp x - (1 + x + x ^ 2 / 2 + x ^ 3 / 6)| ≤ |x| ^ 4 := by + have h := Real.exp_bound hx (n := 4) (by norm_num) + norm_num [Finset.sum_range_succ, Nat.factorial] at h + calc |Real.exp x - (1 + x + x ^ 2 / 2 + x ^ 3 / 6)| ≤ |x| ^ 4 * (5 / 96) := by + convert h using 3 + _ ≤ |x| ^ 4 := by nlinarith [pow_nonneg (abs_nonneg x) 4] + +/-- The quadratic Taylor polynomial of `exp` with a cubic remainder bound on `|x| ≤ 1`, from +`Real.exp_bound` at `n = 3` (whose constant `2/9` is relaxed to `1`). -/ +lemma abs_exp_sub_quadratic_le {x : ℝ} (hx : |x| ≤ 1) : + |Real.exp x - (1 + x + x ^ 2 / 2)| ≤ |x| ^ 3 := by + have h := Real.exp_bound hx (n := 3) (by norm_num) + norm_num [Finset.sum_range_succ, Nat.factorial] at h + calc |Real.exp x - (1 + x + x ^ 2 / 2)| ≤ |x| ^ 3 * (2 / 9) := by + convert h using 3 + _ ≤ |x| ^ 3 := by nlinarith [pow_nonneg (abs_nonneg x) 3] + +/-- **`B(T) → T` as `κ → 0`**, from either side (the limits below use it along `κ → 0⁺`). +`B(T) = (1 − e^{−κT})/κ` is the difference quotient at `0` of +`κ ↦ −e^{−κT}`, whose derivative there is `T`. -/ +theorem tendsto_vasicekBondB_zero_meanReversion (T : ℝ) : + Tendsto (fun κ ↦ vasicekBondB κ T) (𝓝[≠] 0) (𝓝 T) := by + have hd : HasDerivAt (fun κ : ℝ ↦ 1 - Real.exp (κ * -T)) T 0 := + ((((hasDerivAt_id' (0 : ℝ)).mul_const (-T)).exp).const_sub 1).congr_deriv (by simp) + refine hd.tendsto_slope_zero.congr fun κ ↦ ?_ + simp only [vasicekBondB, zero_add, smul_eq_mul, mul_neg, zero_mul, neg_zero, Real.exp_zero, + sub_self, sub_zero] + ring + +/-- The quantitative cancellation in `V`: for `κ ≠ 0` with `|2κT| ≤ 1`, +`|V(T) − T³/3| ≤ 10·|κ|·T⁴`. Each of the three terms of `V` is of leading order `κ⁻²` (both +exponential numerators vanish linearly in `κ`); substituting the cubic Taylor polynomials of +`e^{−κT}` and `e^{−2κT}` cancels the `κ⁻²` and `κ⁻¹` orders exactly and leaves `T³/3` plus the +quartic remainders divided by `κ³`. -/ +lemma abs_vasicekBondV_sub_le {κ T : ℝ} (hκ : κ ≠ 0) (hsmall : |2 * κ * T| ≤ 1) : + |vasicekBondV κ T - T ^ 3 / 3| ≤ 10 * |κ| * T ^ 4 := by + have hx : |κ * T| ≤ 1 / 2 := by + rw [show 2 * κ * T = 2 * (κ * T) by ring, abs_mul, abs_two] at hsmall + linarith + have h1 : |-(κ * T)| ≤ 1 := by rw [abs_neg]; linarith + have h2 : |-(2 * κ * T)| ≤ 1 := by rwa [abs_neg] + have hE₁ := abs_exp_sub_cubic_le h1 + have hE₂ := abs_exp_sub_cubic_le h2 + rw [abs_neg] at hE₁ hE₂ + have hid : vasicekBondV κ T - T ^ 3 / 3 + = (4 * (Real.exp (-(κ * T)) + - (1 + -(κ * T) + (-(κ * T)) ^ 2 / 2 + (-(κ * T)) ^ 3 / 6)) + - (Real.exp (-(2 * κ * T)) + - (1 + -(2 * κ * T) + (-(2 * κ * T)) ^ 2 / 2 + (-(2 * κ * T)) ^ 3 / 6))) + / (2 * κ ^ 3) := by + simp only [vasicekBondV] + field_simp + ring + have h2abs : |2 * κ * T| ^ 4 = 16 * |κ * T| ^ 4 := by + rw [show 2 * κ * T = 2 * (κ * T) by ring, abs_mul, abs_two]; ring + have hT4 : T ^ 4 = |T| ^ 4 := (Even.pow_abs ⟨2, rfl⟩ T).symm + rw [hid, abs_div, abs_mul, abs_two, abs_pow, div_le_iff₀ (by positivity), hT4] + calc _ ≤ 4 * |κ * T| ^ 4 + 16 * |κ * T| ^ 4 := by + refine (abs_sub _ _).trans ?_ + rw [abs_mul, abs_of_pos (by norm_num : (0 : ℝ) < 4)] + linarith + _ = 10 * |κ| * |T| ^ 4 * (2 * |κ| ^ 3) := by rw [abs_mul]; ring + +/-- **A linear error bound gives the limit.** If `|f κ − L| ≤ C·|κ|` for `κ → 0⁺` eventually, +then `f κ → L`. Both limits below are this squeeze, fed by an explicit Taylor bound. -/ +lemma tendsto_nhdsGT_zero_of_abs_sub_le {f : ℝ → ℝ} {L C : ℝ} + (h : ∀ᶠ κ in 𝓝[>] (0 : ℝ), |f κ - L| ≤ C * |κ|) : Tendsto f (𝓝[>] 0) (𝓝 L) := + tendsto_sub_nhds_zero_iff.mp <| squeeze_zero_norm' (by simpa only [Real.norm_eq_abs] using h) + (Filter.Tendsto.mono_left (Continuous.tendsto' (by fun_prop) 0 0 (by simp)) + nhdsWithin_le_nhds) + +/-- **`V(T) → T³/3` as `κ → 0⁺`** — the genuine three-term cancellation limit. The terms +`T/κ²`, `−2(1 − e^{−κT})/κ³` and `(1 − e^{−2κT})/(2κ³)` of `vasicekBondV` each diverge +(for `T > 0` the middle one tends to `−∞`); only their sum converges, at rate `O(κ)`, by the +explicit bound `abs_vasicekBondV_sub_le` and a squeeze. -/ +theorem tendsto_vasicekBondV_zero_meanReversion (T : ℝ) : + Tendsto (fun κ ↦ vasicekBondV κ T) (𝓝[>] 0) (𝓝 (T ^ 3 / 3)) := + tendsto_nhdsGT_zero_of_abs_sub_le (C := 10 * T ^ 4) <| by + filter_upwards [(((by fun_prop : Continuous fun κ : ℝ ↦ |2 * T * κ|).tendsto' 0 0 + (by simp)).mono_left (nhdsWithin_le_nhds : 𝓝[>] (0 : ℝ) ≤ 𝓝 0)).eventually + (ge_mem_nhds one_pos), self_mem_nhdsWithin] with κ hs hκ + exact (abs_vasicekBondV_sub_le hκ.ne' (by rwa [show 2 * κ * T = 2 * T * κ by ring])).trans_eq + (by ring) + +/-- **`M(T) → r₀·T` as `κ → 0⁺`.** With `B(T) → T`, the level term `θ·(T − B(T))` vanishes: +without mean reversion the long-run level `θ` is never felt. -/ +theorem tendsto_vasicekIntegratedMean_zero_meanReversion (r₀ θ T : ℝ) : + Tendsto (fun κ ↦ vasicekIntegratedMean r₀ θ κ T) (𝓝[>] 0) (𝓝 (r₀ * T)) := by + have hB := (tendsto_vasicekBondB_zero_meanReversion T).mono_left (nhdsGT_le_nhdsNE 0) + simpa [vasicekIntegratedMean] using + ((tendsto_const_nhds (x := r₀)).mul hB).add + ((tendsto_const_nhds (x := θ)).mul ((tendsto_const_nhds (x := T)).sub hB)) + +/-- **The Vasicek bond price at vanishing mean reversion.** The closed form of +`vasicekBondPrice_eq`, `exp(−M(T) + σ²V(T)/2)`, tends as `κ → 0⁺` to `exp(−r₀T + σ²T³/6)`, the +value `brownianBondPrice_eq` below gives for the driftless Gaussian short rate +`r_s = r₀ + σB_s` (in its Wiener representation). -/ +theorem tendsto_vasicekBondPrice_zero_meanReversion (r₀ θ σ T : ℝ) : + Tendsto (fun κ ↦ Real.exp (-(vasicekIntegratedMean r₀ θ κ T) + σ ^ 2 * vasicekBondV κ T / 2)) + (𝓝[>] 0) (𝓝 (Real.exp (-(r₀ * T) + σ ^ 2 * T ^ 3 / 6))) := by + have h := ((tendsto_vasicekIntegratedMean_zero_meanReversion r₀ θ T).neg.add + (((tendsto_const_nhds (x := σ ^ 2)).mul + (tendsto_vasicekBondV_zero_meanReversion T)).div_const 2)).rexp + convert h using 3 + ring + +/-- **QuantLib's `A(t,T)` at vanishing mean reversion.** The `r₀`-independent factor +`vasicekBondA θ σ κ T = exp(−θ(T − B(T)) + σ²V(T)/2)` of the affine price +(`vasicekBondPrice_affine`) tends to `exp(σ²T³/6)`, not to the `κ = 0` substitution value. -/ +theorem tendsto_vasicekBondA_zero_meanReversion (θ σ T : ℝ) : + Tendsto (fun κ ↦ vasicekBondA θ σ κ T) (𝓝[>] 0) (𝓝 (Real.exp (σ ^ 2 * T ^ 3 / 6))) := by + have hB := (tendsto_vasicekBondB_zero_meanReversion T).mono_left (nhdsGT_le_nhdsNE 0) + have h := (((tendsto_const_nhds (x := θ)).mul ((tendsto_const_nhds (x := T)).sub hB)).neg.add + (((tendsto_const_nhds (x := σ ^ 2)).mul + (tendsto_vasicekBondV_zero_meanReversion T)).div_const 2)).rexp + rw [show σ ^ 2 * T ^ 3 / 6 = -(θ * (T - T)) + σ ^ 2 * (T ^ 3 / 3) / 2 by ring] + exact h + +/-- **The `κ = 0` substitution is not the limit.** Lean's `x / 0 = 0` sends `B(T)` and `V(T)` +to `0` at `κ = 0`, hence `M(T)` to `θ·T`, so the closed form `exp(−M(T) + σ²V(T)/2)` evaluates +to `exp(−θT)` there: the price of a constant rate pinned at the long-run level, independent of +`r₀` and `σ`. The limit `tendsto_vasicekBondPrice_zero_meanReversion` is +`exp(−r₀T + σ²T³/6)`, independent of `θ` instead; the removable singularity at `κ = 0` has to +be filled by the limit, not by substitution. -/ +theorem vasicekBondPrice_closedForm_zero_meanReversion (r₀ θ σ T : ℝ) : + Real.exp (-(vasicekIntegratedMean r₀ θ 0 T) + σ ^ 2 * vasicekBondV 0 T / 2) + = Real.exp (-(θ * T)) := by + simp [vasicekIntegratedMean, vasicekBondB, vasicekBondV] + +/-! ### The second route: the driftless Gaussian short rate, priced directly -/ + +section Brownian + +open MeasureTheory ProbabilityTheory +open scoped NNReal +open WienerIntegralL2 + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-- The integrated kernel of the driftless model `r_s = r₀ + σB_s`, `u ↦ T − u` +(`∫₀ᵀ B_s ds = ∫₀ᵀ (T − u) dB_u`), is in `L²((0, T])`: it lies in `[0, T)` there. It is the +`κ → 0⁺` limit of `vasicekIntegratedKernel`, which is defined only for `κ > 0`, so the `κ = 0` +model needs its own. -/ +lemma brownianIntegratedKernel_memLp (T : ℝ≥0) : + MemLp (fun u : ℝ ↦ (T : ℝ) - u) 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := by + refine (memLp_top_of_bound (by fun_prop) (T : ℝ) ?_).mono_exponent le_top + refine (ae_restrict_iff' measurableSet_Ioc).mpr (ae_of_all _ ?_) + intro s hs + rw [Real.norm_eq_abs, abs_of_nonneg (by linarith [hs.2])] + linarith [hs.1] + +/-- The driftless integrated kernel `u ↦ T − u` as an element of `L²((0, T])`. -/ +noncomputable def brownianIntegratedKernelLp (T : ℝ≥0) : + Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := + (brownianIntegratedKernel_memLp T).toLp _ + +/-- `∫₀ᵀ (T − u)² du = T³/3`, for the `L²` element of the driftless kernel. -/ +lemma brownianIntegratedKernelLp_integral_sq (T : ℝ≥0) : + (∫ u in Set.Ioc (0 : ℝ) (T : ℝ), (brownianIntegratedKernelLp T u) ^ 2 ∂volume) + = (T : ℝ) ^ 3 / 3 := by + refine (brownianIntegratedKernel_memLp T).integral_sq_toLp.trans ?_ + rw [← intervalIntegral.integral_of_le T.coe_nonneg, + intervalIntegral.integral_comp_sub_left (fun x : ℝ ↦ x ^ 2)] + simp [integral_pow] + norm_num + +/-- The **integrated driftless Gaussian short rate** in its Wiener representation: +`∫₀ᵀ (r₀ + σB_s) ds = r₀·T + σ·∫₀ᵀ (T − u) dB_u` — the `κ = 0` model, with the same +time-order-swap modelling bridge as `vasicekIntegratedRate` (cited, not proved). -/ +noncomputable def brownianIntegratedRate (hB : IsPreBrownianReal B μ) (r₀ σ : ℝ) (T : ℝ≥0) + (ω : Ω) : ℝ := + r₀ * T + σ * wienerIntegralLp B hB T (brownianIntegratedKernelLp T) ω + +/-- **The bond price of the driftless Gaussian short rate**, +`𝔼[exp(−∫₀ᵀ r_s ds)] = exp(−r₀T + σ²T³/6)`: the Wiener bond-price lemma +`integral_exp_neg_add_mul_wienerIntegralLp` at `m = r₀T`, `c = σ` and the kernel `T − u` (the +same lemma `vasicekBondPrice_eq` applies to the Vasicek kernel). No Vasicek formula and no +limit enters. -/ +theorem brownianBondPrice_eq (hB : IsPreBrownianReal B μ) (r₀ σ : ℝ) (T : ℝ≥0) : + ∫ ω, Real.exp (-(brownianIntegratedRate hB r₀ σ T ω)) ∂μ + = Real.exp (-(r₀ * T) + σ ^ 2 * (T : ℝ) ^ 3 / 6) := by + rw [show (fun ω ↦ Real.exp (-(brownianIntegratedRate hB r₀ σ T ω))) = fun ω ↦ + Real.exp (-(r₀ * T + σ * wienerIntegralLp B hB T (brownianIntegratedKernelLp T) ω)) from rfl, + integral_exp_neg_add_mul_wienerIntegralLp, brownianIntegratedKernelLp_integral_sq] + congr 1 + ring + +/-- **Two routes to the same price.** The Vasicek closed form (`vasicekBondPrice_eq`, which for +each `κ > 0` is the `μ`-expectation `𝔼[exp(−∫₀ᵀ r^κ_s ds)]`) converges as `κ → 0⁺` to the +expectation of the driftless model, priced directly by `brownianBondPrice_eq`. -/ +theorem tendsto_vasicekBondPrice_brownianBondPrice (hB : IsPreBrownianReal B μ) + (r₀ θ σ : ℝ) (T : ℝ≥0) : + Tendsto (fun κ ↦ Real.exp (-(vasicekIntegratedMean r₀ θ κ T) + σ ^ 2 * vasicekBondV κ T / 2)) + (𝓝[>] 0) (𝓝 (∫ ω, Real.exp (-(brownianIntegratedRate hB r₀ σ T ω)) ∂μ)) := by + rw [brownianBondPrice_eq] + exact tendsto_vasicekBondPrice_zero_meanReversion r₀ θ σ T + +end Brownian + +/-! ### A constant market price of risk `λ` -/ + +/-- The second-order behaviour of `B`: for `κ ≠ 0` with `|κT| ≤ 1`, +`|(T − B(T))/κ − T²/2| ≤ |κ|·|T|³`. -/ +lemma abs_vasicekBondB_secondOrder_sub_le {κ T : ℝ} (hκ : κ ≠ 0) (hsmall : |κ * T| ≤ 1) : + |(T - vasicekBondB κ T) / κ - T ^ 2 / 2| ≤ |κ| * |T| ^ 3 := by + have h1 : |-(κ * T)| ≤ 1 := by rwa [abs_neg] + have hE := abs_exp_sub_quadratic_le h1 + rw [abs_neg] at hE + have hid : (T - vasicekBondB κ T) / κ - T ^ 2 / 2 + = (Real.exp (-(κ * T)) - (1 + -(κ * T) + (-(κ * T)) ^ 2 / 2)) / κ ^ 2 := by + simp only [vasicekBondB] + field_simp + ring + rw [hid, abs_div, abs_pow, div_le_iff₀ (by positivity)] + calc _ ≤ |κ * T| ^ 3 := hE + _ = |κ| * |T| ^ 3 * |κ| ^ 2 := by rw [abs_mul]; ring + +/-- `(T − B(T))/κ → T²/2` as `κ → 0⁺` — the `κ ↓ 0` limit of the mass `∫₀ᵀ g` of the integrated +kernel (`integral_vasicekIntegratedKernel`), which carries the Girsanov mean shift. -/ +theorem tendsto_vasicekBondB_secondOrder_zero_meanReversion (T : ℝ) : + Tendsto (fun κ ↦ (T - vasicekBondB κ T) / κ) (𝓝[>] 0) (𝓝 (T ^ 2 / 2)) := + tendsto_nhdsGT_zero_of_abs_sub_le (C := |T| ^ 3) <| by + filter_upwards [(((by fun_prop : Continuous fun κ : ℝ ↦ |T * κ|).tendsto' 0 0 + (by simp)).mono_left (nhdsWithin_le_nhds : 𝓝[>] (0 : ℝ) ≤ 𝓝 0)).eventually + (ge_mem_nhds one_pos), self_mem_nhdsWithin] with κ hs hκ + exact (abs_vasicekBondB_secondOrder_sub_le hκ.ne' (by rwa [mul_comm])).trans_eq (by ring) + +section Girsanov + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-- The closed form of the Girsanov bond price: `vasicekBondPrice_girsanov` composed with +`vasicekBondPrice_eq` at the risk-adjusted level `θ − λσ/κ`. -/ +theorem vasicekBondPrice_girsanov_eq (hB : IsPreBrownianReal B μ) (r₀ θ σ lam : ℝ) {κ : ℝ} + (hκ : 0 < κ) (T : ℝ≥0) : + ∫ ω, Real.exp (-(vasicekIntegratedRate hB r₀ θ σ hκ T ω)) + ∂(μ.withDensity fun ω ↦ ENNReal.ofReal (Real.exp (-lam * B T ω - lam ^ 2 * (T : ℝ) / 2))) + = Real.exp (-(vasicekIntegratedMean r₀ (θ - lam * σ / κ) κ T) + + σ ^ 2 * vasicekBondV κ T / 2) := by + rw [vasicekBondPrice_girsanov, vasicekBondPrice_eq] + +/-- **The Girsanov bond price at vanishing mean reversion.** The closed form of +`vasicekBondPrice_girsanov_eq` tends as `κ → 0⁺` to `exp(−r₀T + λσT²/2 + σ²T³/6)`. The level +shift `−λσ/κ` itself diverges, but it multiplies `T − B(T) = O(κ)`: the mean +`M_{θ−λσ/κ}(T) = M_θ(T) − λσ·(T − B(T))/κ` tends to `r₀T − λσT²/2`. The sign of the `λ` term +is fixed by this library's convention: the density `exp(−λB_T − λ²T/2)` makes `B_t + λt` a +Brownian motion, so the risk-adjusted level is `θ − λσ/κ` (lower for `λ > 0`) and the bond is +dearer. -/ +theorem tendsto_vasicekBondPrice_girsanov_zero_meanReversion (r₀ θ σ lam T : ℝ) : + Tendsto (fun κ ↦ Real.exp (-(vasicekIntegratedMean r₀ (θ - lam * σ / κ) κ T) + + σ ^ 2 * vasicekBondV κ T / 2)) + (𝓝[>] 0) (𝓝 (Real.exp (-(r₀ * T) + lam * σ * T ^ 2 / 2 + σ ^ 2 * T ^ 3 / 6))) := by + have hM (κ : ℝ) : vasicekIntegratedMean r₀ (θ - lam * σ / κ) κ T + = vasicekIntegratedMean r₀ θ κ T - lam * σ * ((T - vasicekBondB κ T) / κ) := by + simp only [vasicekIntegratedMean]; ring + simp_rw [hM] + have h := (((tendsto_vasicekIntegratedMean_zero_meanReversion r₀ θ T).sub + ((tendsto_const_nhds (x := lam * σ)).mul + (tendsto_vasicekBondB_secondOrder_zero_meanReversion T))).neg.add + (((tendsto_const_nhds (x := σ ^ 2)).mul + (tendsto_vasicekBondV_zero_meanReversion T)).div_const 2)).rexp + convert h using 3 + ring + +end Girsanov + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/YieldCurve.lean b/LeanPool/MathFin/Models/Rates/YieldCurve.lean new file mode 100644 index 0000000000..dce20a5049 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/YieldCurve.lean @@ -0,0 +1,117 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.BigOperators.Group.Finset.Basic +public import Mathlib.Basic.Real.Basic +public import Mathlib.Tactic.FieldSimp +public import Mathlib.Tactic.Linarith.Frontend +public import Mathlib.Tactic.Ring.RingNF + +/-! +# Yield curve bootstrapping + +Standard practitioner method to extract zero-coupon bond (ZCB) prices from a +sequence of coupon-bond prices at successive maturities. + +Given a coupon bond paying coupon `c i` at time `T_i` for `i ∈ sprev` (the +earlier maturities) plus `c_last + F` at the new (longest) maturity `T_n`, +with observed price `P`, the new ZCB price `B_last` satisfies: + + `P = (∑_{i ∈ sprev} c i · B i) + (c_last + F) · B_last`, + +so + + `B_last = (P − ∑_{i ∈ sprev} c i · B i) / (c_last + F)`, + +provided `c_last + F ≠ 0`. + +Applied recursively, starting from a single-period bond (where `sprev = ∅` and +`B_last = P / (c_last + F)`), this identity is how the discount curve is bootstrapped +from coupon-bond market data. Only the single steps are proved here; the recursion over +instruments is the search-based `boot` of `Models/Rates/Bootstrapping.lean`, where +`swapBootstrap_recovers_couponBondFactor` shows that bisection on a zero-value swap +recovers the factor named by `bootstrap_solve`. + +## Main definitions + +* `couponBondPricingEq`: the proposition `P = (∑ i ∈ sprev, c i * B i) + (c_last + F) * B_last`, + the price of a coupon bond with previously known maturities `sprev` and one new maturity. + +## Main results + +* `bootstrap_solve`: from the pricing equation, recovers `B_last` as a + closed-form ratio. +* `bootstrap_solve_first`: bootstrap base case for the first bond with empty + previous schedule: `B_1 = P_1 / (c_1 + F)`. +* `bootstrap_solve_second`: bootstrap step for the second bond: + `B_2 = (P_2 − c · B_1) / (c + F)`. +* `bootstrap_consistency`: the bootstrapped price, plugged back into the pricing + equation, recovers the bond price. + +## References + +* [Fabozzi, *Fixed Income Mathematics*][FabozziFIM], Ch 9 +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], Ch 4.6 + +## Tags + +bootstrapping, zero-coupon bond, coupon bond, discount curve, yield curve construction, JEL E43, +MSC 91G30 +-/ + +@[expose] public section + +namespace MathFin + +/-- Coupon-bond pricing equation expressed in terms of previously-known ZCB +prices `B : ι → ℝ` and the new ZCB `B_last`. -/ +def couponBondPricingEq {ι : Type*} (sprev : Finset ι) (c B : ι → ℝ) + (P c_last F B_last : ℝ) : Prop := + P = (∑ i ∈ sprev, c i * B i) + (c_last + F) * B_last + +/-- **Bootstrap solve identity**: from the coupon-bond pricing equation, the +new ZCB price `B_last` is recovered as a closed-form ratio. -/ +lemma bootstrap_solve {ι : Type*} (sprev : Finset ι) (c B : ι → ℝ) + (P c_last F B_last : ℝ) (h : c_last + F ≠ 0) + (hP : couponBondPricingEq sprev c B P c_last F B_last) : + B_last = (P - ∑ i ∈ sprev, c i * B i) / (c_last + F) := by + unfold couponBondPricingEq at hP + field_simp + linarith + +/-- **First-bond bootstrap** (empty previous schedule): a single-period coupon +bond with cash flow `c_last + F` at maturity gives `B_last = P / (c_last + F)`. -/ +lemma bootstrap_solve_first (P c_last F B_last : ℝ) (h : c_last + F ≠ 0) + (hP : P = (c_last + F) * B_last) : + B_last = P / (c_last + F) := by + rw [hP] + field_simp + +/-- **Second-bond bootstrap step**: with one previous ZCB price `B_1` and a +two-period bond paying coupon `c` at both dates plus face `F` at the second, +`B_2 = (P − c · B_1) / (c + F)`. -/ +lemma bootstrap_solve_second (P c F B_1 B_2 : ℝ) (h : c + F ≠ 0) + (hP : P = c * B_1 + (c + F) * B_2) : + B_2 = (P - c * B_1) / (c + F) := by + rw [hP] + field_simp + ring + +/-- **Recursive consistency**: the bootstrapped ZCB price, plugged back into +the pricing equation, recovers the original bond price. -/ +lemma bootstrap_consistency {ι : Type*} (sprev : Finset ι) (c B : ι → ℝ) + (P c_last F : ℝ) (h : c_last + F ≠ 0) : + couponBondPricingEq sprev c B P c_last F + ((P - ∑ i ∈ sprev, c i * B i) / (c_last + F)) := by + unfold couponBondPricingEq + field_simp + ring + +end MathFin diff --git a/LeanPool/MathFin/Models/Rates/ZCB.lean b/LeanPool/MathFin/Models/Rates/ZCB.lean new file mode 100644 index 0000000000..048cbd2726 --- /dev/null +++ b/LeanPool/MathFin/Models/Rates/ZCB.lean @@ -0,0 +1,132 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Analysis.DerivOfDeriv +public import Mathlib.Analysis.SpecialFunctions.ExpDeriv +public import Mathlib.Analysis.SpecialFunctions.Log.Basic +public import Mathlib.Topology.Algebra.Module.ModuleTopology + +/-! +# Fixed-income basics under a deterministic short rate + +Closed-form identities for a zero-coupon bond with continuous compounding under +a constant short rate `r`: + + `B(t, T) = exp(-(r · (T - t)))`. + +## Main definitions + +* `zcb`: the continuous-compounding zero-coupon bond price `zcb r t T = exp (-(r * (T - t)))` + under a constant short rate `r`. + +## Main results + +* `zcb_at_maturity`: `B(T, T) = 1`. +* `zcb_pos`: `B(t, T) > 0`; `positivity` proves it (`evalZcb`). +* `zcb_yield_eq_rate`: under a constant `r`, the yield-to-maturity equals `r`. +* `hasDerivAt_zcb_r`: `∂_r B(t, T) = -(T - t) · B(t, T)` — the bond duration is + the time-to-maturity. +* `zcb_duration_eq_time_to_maturity`: `-∂_r B / B = T - t`. +* `hasDerivAt_deriv_zcb_r`: `∂²_r B(t, T) = (T - t)² · B(t, T)`. +* `zcb_convexity_eq_time_to_maturity_sq`: convexity `∂²_r B / B = (T - t)²`. + +The model is purely deterministic; the Vasicek / CIR / HJM stochastic versions +would need Itô calculus. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 4.2; 4.8; 4.9 + +## Tags + +zero-coupon bond, bond duration, bond convexity, constant short rate, yield to maturity, JEL G12, +MSC 91G30 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- Continuous-compounding zero-coupon bond price under a constant short rate. -/ +noncomputable def zcb (r : ℝ) (t T : ℝ) : ℝ := Real.exp (-(r * (T - t))) + +/-- The bond pays `1` at maturity. -/ +lemma zcb_at_maturity (r T : ℝ) : zcb r T T = 1 := by + unfold zcb + rw [sub_self, mul_zero, neg_zero, Real.exp_zero] + +/-- The bond is positive. `positivity` proves it (`evalZcb`). -/ +lemma zcb_pos (r t T : ℝ) : 0 < zcb r t T := Real.exp_pos _ + +/-- Yield-to-maturity for a ZCB under a constant rate equals the rate. -/ +lemma zcb_yield_eq_rate {r t T : ℝ} (htT : t < T) : + -Real.log (zcb r t T) / (T - t) = r := by + unfold zcb + rw [Real.log_exp, neg_neg] + have h_ne : T - t ≠ 0 := sub_ne_zero.mpr htT.ne' + field_simp + +/-- `∂_r B(t, T) = -(T - t) · B(t, T)`. Duration of a ZCB equals time-to-maturity. -/ +lemma hasDerivAt_zcb_r (t T : ℝ) (r : ℝ) : + HasDerivAt (fun r' ↦ zcb r' t T) (-(T - t) * zcb r t T) r := by + unfold zcb + have h_lin : HasDerivAt (fun r' : ℝ ↦ -(r' * (T - t))) (-(T - t)) r := by + have h := (hasDerivAt_id r).mul_const (T - t) + rw [one_mul] at h + exact h.neg + have h := h_lin.exp + convert h using 1 + ring + +/-- ZCB Macaulay duration equals time-to-maturity: `-∂_r B / B = T - t`. -/ +lemma zcb_duration_eq_time_to_maturity (t T r : ℝ) : + -deriv (fun r' ↦ zcb r' t T) r / zcb r t T = T - t := by + have h_ne : zcb r t T ≠ 0 := (zcb_pos r t T).ne' + rw [(hasDerivAt_zcb_r t T r).deriv] + field_simp + +/-- The r-derivative of the duration formula `-(T - t) · B` is `(T - t)² · B`. The second +derivative of the price itself is `hasDerivAt_deriv_zcb_r`. -/ +private lemma hasDerivAt_zcb_r_r (t T : ℝ) (r : ℝ) : + HasDerivAt (fun r' ↦ -(T - t) * zcb r' t T) ((T - t)^2 * zcb r t T) r := by + have h := (hasDerivAt_zcb_r t T r).const_mul (-(T - t)) + rw [show (T - t) ^ 2 * zcb r t T = -(T - t) * (-(T - t) * zcb r t T) from by ring] + exact h + +/-- `∂²_r B(t, T) = (T - t)² · B(t, T)`, for the price itself: `∂_r B = -(T - t) · B` at every +rate (`hasDerivAt_zcb_r`). -/ +theorem hasDerivAt_deriv_zcb_r (t T r : ℝ) : + HasDerivAt (deriv fun r' ↦ zcb r' t T) ((T - t) ^ 2 * zcb r t T) r := + hasDerivAt_deriv_of_eventually (.of_forall (hasDerivAt_zcb_r t T)) (hasDerivAt_zcb_r_r t T r) + +/-- ZCB convexity = squared time-to-maturity: `∂²_r B / B = (T - t)²`. -/ +lemma zcb_convexity_eq_time_to_maturity_sq (t T r : ℝ) : + deriv (deriv fun r' ↦ zcb r' t T) r / zcb r t T = (T - t)^2 := by + have h_ne : zcb r t T ≠ 0 := (zcb_pos r t T).ne' + rw [(hasDerivAt_deriv_zcb_r t T r).deriv] + field_simp + +end MathFin + +namespace Mathlib.Meta.Positivity +open Lean.Meta Qq + +/-- Extension for the `positivity` tactic: a zero-coupon bond price `zcb r t T` is positive. -/ +@[positivity MathFin.zcb _ _ _] +meta def evalZcb : PositivityExt where eval {u α} _ pα? e := + match pα? with | none => pure .none | some _ => do + match u, α, e with + | 0, ~q(ℝ), ~q(MathFin.zcb $r $t $T) => + assertInstancesCommute + pure (.positive q(MathFin.zcb_pos $r $t $T)) + | _, _, _ => throwError "not zcb" + +end Mathlib.Meta.Positivity diff --git a/LeanPool/MathFin/Models/StochVol/Heston.lean b/LeanPool/MathFin/Models/StochVol/Heston.lean new file mode 100644 index 0000000000..1b831ea0b8 --- /dev/null +++ b/LeanPool/MathFin/Models/StochVol/Heston.lean @@ -0,0 +1,728 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Rates.CIRRiccati +public import Mathlib.Algebra.Ring.IsFormallyReal + +/-! +# The Heston affine transform at the generator/PDE level (2D) + +The 2D Heston state is (x, v) = (log-spot, variance) with + +`dS = rS dt + √v S dW¹`, `dv = κ(θ − v) dt + ξ √v dW²`, `d⟨W¹, W²⟩ = ρ dt`, + +so x = log S obeys `dx = (r − v/2) dt + √v dW¹` (Itô) and the generator on test +functions `f : ℝ → ℝ → ℝ` is + +`Lf = (r − v/2) ∂_x f + κ(θ − v) ∂_v f + (v/2) ∂_xx f + ρ ξ v ∂_xv f + (ξ² v/2) ∂_vv f` +(`hestonGenerator`; the cross term `ρ ξ v ∂_xv` is the new 2D piece, carrying the +correlation; at the generator level it is pure calculus). + +The recipe is Bagaria ch. 14, Prop 14.5 (invariance test `Lu/u ∈ span{gᵢ}`) and eq. 14.4 (`L +e^(φ+ψx) = [μ(x)(ψ + ½ v(x) ψ²)] e^(φ+ψx)`). The 2D reading-off: with exponent-gradient +`(Bx, Bv) = (u, ψ)`, the bracket of the generator lemma below is `(c₀ + c₁ v)` with the +**x-coefficient identically zero** — the third Riccati equation `Bx' = 0` (the log-spot gradient is +conserved). Matching `∂_t Φ + LΦ = 0` (the *backward* pricing equation; Bagaria's Calc 14.6 states +the forward form `∂_t u = Lu`, same matching with negated coefficients, the flip +`affineBondPrice_solves_pde` in `Models/Rates/AffineTermStructurePDE` also makes) gives the +**calendar-time** system + +`Bx' = 0`, `Bv' = u/2 − u²/2 + (κ − ρξu) Bv − (ξ²/2) Bv²`, `A' = −r·u − κθ·Bv`, + +with terminal data `Bx(T) = u`, `Bv(T) = 0`, `A(T) = 0` (payoff `e^{u x}`). In +maturity time `τ = T − t` the `Bv`-equation is the constant-forced Riccati + +`b̂' = ½(u² − u) + (ρξu − κ) b̂ + ½ξ² b̂²`, `b̂(0) = 0` (`hasDerivAt_hestonBv`), + +the Calc 14.6 ψ-equation `ψ' = bψ + ½dψ²` plus the constant `½(u² − u)` produced by the x-row of the +drift (the coupling `−v/2` of variance into log-spot); `â' = ru + κθ b̂` (`hasDerivAt_hestonA`). The +real moment `M(u) = E[e^{u log S_T}]` is the transform at real `u`; the characteristic function is +the same system at `iu` — the complex route is out of scope here. + +The closed forms are the Möbius members + +`b̂(τ) = (u² − u)(e^{γτ} − 1) / ((γ + κ − ρξu)e^{γτ} + (γ − κ + ρξu))`, +`γ = √((κ − ρξu)² + ξ²(u − u²))` (the ρ-shifted CIR root: `cirGamma`'s +`√(κ² + 2ξ²)` under `κ ↦ κ − ρξu` plus the u-dependent piece), + +`â(τ) = ruτ + (2κθ/ξ²)[((γ + κ − ρξu)/2)τ − log(D(τ)/(2γ))]`, `D` the shared +denominator. The ODE residuals vanish after the single substitution +`γ² = (κ − ρξu)² + ξ²(u − u²)`. + +The `Bv`-equation has a constant term `½(u² − u)` and the quadratic sign `+½ξ²ψ²` of +the characteristic-function side, so it is neither the CIR bond `B`-factor +(`B' = 1 − κB − (ξ²/2)B²`, `Models.Rates.CIRRiccati`) nor a constant-free Bernoulli +equation; its Möbius solution is derived here by the quotient rule, one coefficient +rewrite, `field_simp` and `ring`. + +**Guards — the admissible strip.** The CIR discriminant `κ² + 2ξ²` is always +nonnegative; the Heston discriminant +`γ² = (κ − ρξu)² + ξ²(u − u²)` is **not** always nonnegative (it → −∞ as +u → ±∞ when |ρ| < 1): off the strip the closed form silently degenerates (γ = 0 in +Lean's `Real.sqrt`) and is *false* as an ODE solution. This is Bagaria's Thm 14.7 +proviso made concrete — the Riccati explosion / moment-existence strip. The flow +lemmas below take the clean sufficient hypothesis `0 < u < 1`, `ξ ≠ 0`, which +forces `γ > |κ − ρξu|`, hence `D(τ) > 0` for **all** real τ (no per-τ guard); +`κ` and `θ` enter the flow facts with no hypotheses at all (the deterministic layer +needs no Feller-type condition). + +**Not proved.** That the profile at `(0, x₀, v₀)` equals `E[e^{u log S_T}]` is not +proved: it needs a Heston process (existence of the square-root SDE, unbounded +coefficients) and the 2D correlated Itô formula, neither of which the library has. This +module is the generator/PDE level only. + +## Main definitions + +* `expAffine`, `expAffine2`: the exponential-affine families `e^(φ + ψ x)` and + `e^(A + Bx·x + Bv·v)`. +* `hestonGenerator`: the generator + `Lf = (r − v/2) ∂_x f + κ(θ − v) ∂_v f + (v/2) ∂_xx f + ρξv ∂_xv f + (ξ²v/2) ∂_vv f` on test + functions of (log-spot, variance). +* `hestonGamma`: the root `γ = √((κ − ρξu)² + ξ²(u − u²))`. +* `hestonBvDenom`: the Möbius denominator `D(τ) = (γ + κ − ρξu)e^{γτ} + (γ − κ + ρξu)`. +* `hestonBv`: the closed form `b̂(τ) = (u² − u)(e^{γτ} − 1) / D(τ)`. +* `hestonA`: the closed form `â(τ) = ruτ + (2κθ/ξ²)[((γ + κ − ρξu)/2)τ − log(D(τ)/(2γ))]`. +* `hestonProfile`: the candidate transform profile `e^{A(t) + u·x + B(t)·v}`. + +## Main results + +* `hestonGenerator_expAffine2`: the generator applied to `expAffine2 A Bx Bv` is an affine + function of `v` times `expAffine2 A Bx Bv`. +* `hestonBracket_xFree`: the multiplier `L E / E` depends on `v` alone. +* `hestonGamma_eq_cirGamma`: for `0 ≤ u ≤ 1`, `hestonGamma` is `cirGamma` at mean reversion + `κ − ρξu` and volatility `ξ√((u − u²)/2)`. +* `hestonBvDenom_pos`: for `ξ ≠ 0` and `0 < u < 1`, `D(τ) > 0` for every real `τ`. +* `hasDerivAt_hestonBv`: for `ξ ≠ 0` and `0 < u < 1`, `hestonBv` solves the Riccati equation + `b̂' = (u² − u)/2 + (ρξu − κ) b̂ + (ξ²/2) b̂²` with `b̂(0) = 0` (`hestonBv_at_zero`). +* `hasDerivAt_hestonA`: under the same hypotheses, `â' = r u + κθ b̂`. +* `hasDerivAt_hestonBvCalendar`, `hasDerivAt_hestonACalendar`: the same flows in calendar time + `t ↦ b̂(T − t)`, `t ↦ â(T − t)`. +* `hestonProfile_pde`: for any `A, B` solving the calendar-time Riccati system, + `∂_t Φ + LΦ = 0` for `Φ = hestonProfile`. +* `hestonTransform_pde`, `hestonTransform_terminal`: for `ξ ≠ 0` and `0 < u < 1`, the profile + built from `hestonA` and `hestonBv` solves `∂_t Φ + LΦ = 0` and equals `e^{u x}` at `t = T`. + The identification of the profile with `E[e^{u log S_T}]` for a Heston process is not + proved. + +## References + +* [S. Bagaria, *Notes on Fixed Income Derivative Pricing*][BagariaFIDP], ch. 14, Prop 14.5 +* [Heston, *A closed-form solution for options with stochastic volatility with applications to bond + and currency options*][Heston1993] + +## Tags + +Heston model, stochastic volatility, affine transform, Riccati equation, characteristic function, +generator PDE, MSC 91G20, MSC 60J60, JEL G13 +-/ + +@[expose] public section + +namespace MathFin.Heston + +/-! ### The 1D exponential-affine family -/ + +/-- The exponential-affine family `x ↦ e^(φ + ψ x)` (Bagaria ch. 14, eq. 14.4). -/ +noncomputable def expAffine (φ ψ x : ℝ) : ℝ := Real.exp (φ + ψ * x) + +/-- The affine inner function `y ↦ φ + ψ * y` has derivative `ψ`. -/ +theorem hasDerivAt_affine (φ ψ x : ℝ) : HasDerivAt (fun y => φ + ψ * y) ψ x := by + simpa using ((hasDerivAt_id x).const_mul ψ).const_add φ + +/-- Second derivative of the exponential-affine family: `ψ² * e^(φ + ψ x)`. -/ +theorem deriv_deriv_expAffine (φ ψ : ℝ) : + deriv (deriv (expAffine φ ψ)) = fun x => ψ ^ 2 * expAffine φ ψ x := by + have h1 : deriv (expAffine φ ψ) = fun x => Real.exp (φ + ψ * x) * ψ := + funext fun x => (hasDerivAt_affine φ ψ x).exp.deriv + funext x + rw [h1, ((hasDerivAt_affine φ ψ x).exp.mul_const ψ).deriv] + simp only [expAffine] + ring + +/-! ### The 2D exponential-affine family and its partial derivatives -/ + +/-- The 2D exponential-affine family `E_{A,Bx,Bv}(x,v) = e^(A + Bx·x + Bv·v)`, +curried so that each partial derivative is a 1D derivative of an `expAffine` member. -/ +noncomputable def expAffine2 (A Bx Bv x v : ℝ) : ℝ := Real.exp (A + Bx * x + Bv * v) + +/-- x-frozen bridge: `E_{A,Bx,Bv}(·, v)` is the 1D member `expAffine (A + Bv·v) Bx`. -/ +theorem expAffine2_left (A Bx Bv v : ℝ) : + (fun y => expAffine2 A Bx Bv y v) = expAffine (A + Bv * v) Bx := by + funext y + change Real.exp (A + Bx * y + Bv * v) = Real.exp ((A + Bv * v) + Bx * y) + exact Real.exp_eq_exp.mpr (by ring) + +/-- v-frozen bridge: `E_{A,Bx,Bv}(x, ·)` is the 1D member `expAffine (A + Bx·x) Bv`. -/ +theorem expAffine2_right (A Bx Bv x : ℝ) : + expAffine2 A Bx Bv x = expAffine (A + Bx * x) Bv := by + funext w + change Real.exp (A + Bx * x + Bv * w) = Real.exp ((A + Bx * x) + Bv * w) + exact Real.exp_eq_exp.mpr (by ring) + +/-- ∂_x of the 2D family: `Bx · E`. -/ +theorem hasDerivAt_expAffine2_x (A Bx Bv x v : ℝ) : + HasDerivAt (fun y => expAffine2 A Bx Bv y v) (Real.exp (A + Bx * x + Bv * v) * Bx) x := by + rw [expAffine2_left A Bx Bv v] + have h := (hasDerivAt_affine (A + Bv * v) Bx x).exp + rw [show (A + Bv * v) + Bx * x = A + Bx * x + Bv * v from by ring] at h + exact h + +/-- ∂_v of the 2D family: `Bv · E`. -/ +theorem hasDerivAt_expAffine2_v (A Bx Bv x v : ℝ) : + HasDerivAt (expAffine2 A Bx Bv x) (Real.exp (A + Bx * x + Bv * v) * Bv) v := by + rw [expAffine2_right A Bx Bv x] + exact (hasDerivAt_affine (A + Bx * x) Bv v).exp + +/-- ∂_x of the 2D family (function form). -/ +theorem deriv_expAffine2_x (A Bx Bv v : ℝ) : + deriv (fun y => expAffine2 A Bx Bv y v) + = fun y => Real.exp (A + Bx * y + Bv * v) * Bx := + funext fun y => (hasDerivAt_expAffine2_x A Bx Bv y v).deriv + +/-- ∂_v of the 2D family (function form). -/ +theorem deriv_expAffine2_v (A Bx Bv x : ℝ) : + deriv (expAffine2 A Bx Bv x) = fun w => Real.exp (A + Bx * x + Bv * w) * Bv := + funext fun w => (hasDerivAt_expAffine2_v A Bx Bv x w).deriv + +/-- ∂_xx of the 2D family (function form): `Bx² · E`. -/ +theorem deriv_deriv_expAffine2_x (A Bx Bv v : ℝ) : + deriv (deriv (fun y => expAffine2 A Bx Bv y v)) + = fun y => Real.exp (A + Bx * y + Bv * v) * Bx ^ 2 := by + rw [expAffine2_left A Bx Bv v, deriv_deriv_expAffine] + funext y + simp only [expAffine] + rw [show (A + Bv * v) + Bx * y = A + Bx * y + Bv * v from by ring] + ring + +/-- ∂_vv of the 2D family (function form): `Bv² · E`. -/ +theorem deriv_deriv_expAffine2_v (A Bx Bv x : ℝ) : + deriv (deriv (expAffine2 A Bx Bv x)) + = fun w => Real.exp (A + Bx * x + Bv * w) * Bv ^ 2 := by + rw [expAffine2_right A Bx Bv x, deriv_deriv_expAffine] + funext w + simp only [expAffine] + ring + +/-- The mixed derivative ∂_v∂_x (function form): `Bx·Bv · E` — the genuinely 2D +piece, computed as the v-derivative of the x-derivative. -/ +theorem deriv_expAffine2_xv (A Bx Bv x : ℝ) : + deriv (fun w => deriv (fun y => expAffine2 A Bx Bv y w) x) + = fun w => Real.exp (A + Bx * x + Bv * w) * (Bx * Bv) := by + have hfun : ∀ w, deriv (fun y => expAffine2 A Bx Bv y w) x + = Real.exp (A + Bx * x + Bv * w) * Bx := + fun w => (hasDerivAt_expAffine2_x A Bx Bv x w).deriv + have hderiv : ∀ w, HasDerivAt (fun z => Real.exp (A + Bx * x + Bv * z) * Bx) + (Real.exp (A + Bx * x + Bv * w) * (Bx * Bv)) w := by + intro w + have h := ((hasDerivAt_affine (A + Bx * x) Bv w).exp).mul_const Bx + rw [show (A + Bx * x) + Bv * w = A + Bx * x + Bv * w from rfl, + show Real.exp (A + Bx * x + Bv * w) * Bv * Bx + = Real.exp (A + Bx * x + Bv * w) * (Bx * Bv) from by ring] at h + exact h + funext w + simp only [hfun] + exact (hderiv w).deriv + +/-! ### The Heston generator on the exponential-affine family -/ + +/-- The **Heston generator** on test functions `f : ℝ → ℝ → ℝ` (x = log-spot, +v = variance): +`Lf = (r − v/2) ∂_x f + κ(θ − v) ∂_v f + (v/2) ∂_xx f + ρξv ∂_xv f + (ξ²v/2) ∂_vv f` +— the correlated 2D generator of `dx = (r − v/2)dt + √v dW¹`, +`dv = κ(θ − v)dt + ξ√v dW²`, `d⟨W¹,W²⟩ = ρdt` (the covariance matrix is +`v · [[1, ρξ], [ρξ, ξ²]]`, so the mixed generator term is `a₁₂ = ρξv`). -/ +noncomputable def hestonGenerator (r κ θ ξ ρ : ℝ) (f : ℝ → ℝ → ℝ) : ℝ → ℝ → ℝ := + fun x v => + (r - v / 2) * deriv (fun y => f y v) x + + κ * (θ - v) * deriv (f x) v + + v / 2 * deriv (deriv (fun y => f y v)) x + + ρ * ξ * v * deriv (fun w => deriv (fun y => f y w) x) v + + ξ ^ 2 * v / 2 * deriv (deriv (f x)) v + +/-- **The generator on the 2D family.** The Heston generator applied to a member of the 2D +exponential-affine family is an affine-in-`v` bracket times the function itself: + +`L E = ((r·Bx + κθ·Bv) + (Bx²/2 + ρξ·Bx·Bv + ξ²Bv²/2 − κBv − Bx/2)·v) · E` + +— Bagaria ch. 14, eq. 14.4 in the 2D Heston roles: drift `(r − v/2, κ(θ − v))` and +covariance `v·[[1, ρξ], [ρξ, ξ²]]` are both affine in `(x, v)`, so the bracket is +affine (in fact x-free). The cross term `ρξ·Bx·Bv` inside the v-coefficient is the +new 2D content. -/ +theorem hestonGenerator_expAffine2 (r κ θ ξ ρ A Bx Bv : ℝ) : + hestonGenerator r κ θ ξ ρ (expAffine2 A Bx Bv) + = fun x v => ((r * Bx + κ * θ * Bv) + + (Bx ^ 2 / 2 + ρ * ξ * Bx * Bv + ξ ^ 2 / 2 * Bv ^ 2 - κ * Bv - Bx / 2) * v) + * Real.exp (A + Bx * x + Bv * v) := by + funext x v + simp only [hestonGenerator] + rw [deriv_deriv_expAffine2_x A Bx Bv v, deriv_deriv_expAffine2_v A Bx Bv x, + deriv_expAffine2_xv A Bx Bv x, deriv_expAffine2_x A Bx Bv v, + deriv_expAffine2_v A Bx Bv x] + ring + +/-- **The 2D invariance (bracket) corollary.** The bracket of `hestonGenerator_expAffine2` is +affine in `v` with intercept `c₀ = r·Bx + κθ·Bv` and slope +`c₁ = Bx²/2 + ρξ·Bx·Bv + ξ²Bv²/2 − κBv − Bx/2`. Matching the backward pricing +equation `∂_tΦ + LΦ = 0` against `∂_tΦ/Φ = A' + Bx'·x + Bv'·v` reads off the +Heston Riccati system for the `(A, Bx, Bv)` triple: `A' = −c₀`, `Bv' = −c₁`, and +(the x-row) `Bx' = 0` — see `hestonBracket_xFree`. -/ +theorem hestonBracket_affine (r κ θ ξ ρ A Bx Bv : ℝ) : + ∃ (c₀ c₁ : ℝ), c₀ = r * Bx + κ * θ * Bv + ∧ c₁ = Bx ^ 2 / 2 + ρ * ξ * Bx * Bv + ξ ^ 2 / 2 * Bv ^ 2 - κ * Bv - Bx / 2 + ∧ hestonGenerator r κ θ ξ ρ (expAffine2 A Bx Bv) + = fun x v => (c₀ + c₁ * v) * expAffine2 A Bx Bv x v := by + refine ⟨r * Bx + κ * θ * Bv, + Bx ^ 2 / 2 + ρ * ξ * Bx * Bv + ξ ^ 2 / 2 * Bv ^ 2 - κ * Bv - Bx / 2, rfl, rfl, ?_⟩ + rw [hestonGenerator_expAffine2] + funext x v + simp only [expAffine2] + +/-- **The x-free bracket** — the multiplier `L E / E` is a function of `v` alone. +The vanishing x-coefficient is the third Riccati equation: the log-spot gradient +`Bx` is conserved along the transform flow (this is why Heston's transform has a +fixed `u·x` term and only `(A, Bv)` move). -/ +theorem hestonBracket_xFree (r κ θ ξ ρ A Bx Bv : ℝ) : + ∃ (g : ℝ → ℝ), ∀ x v, + hestonGenerator r κ θ ξ ρ (expAffine2 A Bx Bv) x v = g v * expAffine2 A Bx Bv x v := by + refine ⟨fun v => (r * Bx + κ * θ * Bv) + + (Bx ^ 2 / 2 + ρ * ξ * Bx * Bv + ξ ^ 2 / 2 * Bv ^ 2 - κ * Bv - Bx / 2) * v, ?_⟩ + intro x v + rw [hestonGenerator_expAffine2] + simp only [expAffine2] + +/-! ### The Riccati flow (maturity time): the ρ-shifted Möbius closed forms + +The `Bv`-equation `b̂' = ½(u² − u) + (ρξu − κ)b̂ + ½ξ²b̂²` is the general +constant-forced Riccati `b' = c + b₁b + db²` (`c = ½(u²−u)`, `b₁ = ρξu − κ`, +`d = ½ξ²`) — Calc 14.6's ψ-equation plus the x-row's constant. Its linearization +(Calc 14.10's substitution) has characteristic roots `(b₁ ± γ)/2` with +`γ² = b₁² − 4cd = (κ − ρξu)² + ξ²(u − u²)` — the ρ-shifted `cirGamma`. The +Möbius member solving it from `b̂(0) = 0` is derived like `cirBondB` +in `Models/Rates/CIRRiccati` (partial fractions against the fixed points, `b(0) = 0` imposed); the +`â`-antiderivative integrates `κθ·b̂` in closed form (log of the shared +denominator), mirroring `cirBondA`. + +Guards (module header): the strip `0 < u < 1`, `ξ ≠ 0` forces `γ > |κ − ρξu|` and +`D(τ) > 0` for all real `τ`; `κ, θ` carry no hypotheses. -/ + +/-- The Heston characteristic root `γ = √((κ − ρξu)² + ξ²(u − u²))` — `cirGamma`'s +`√(κ² + 2ξ²)` with the ρ-shifted mean reversion `κ ↦ κ − ρξu` and the +moment-dependent piece. -/ +noncomputable def hestonGamma (κ ξ ρ u : ℝ) : ℝ := + Real.sqrt ((κ - ρ * ξ * u) ^ 2 + ξ ^ 2 * (u - u ^ 2)) + +/-- **Heston's root is the CIR root, shifted.** For `0 ≤ u ≤ 1`, the Heston characteristic root +is `cirGamma` (`Models/Rates/CIRRiccati.lean`) at mean reversion `κ − ρξu` and volatility +`ξ√((u − u²)/2)`. -/ +theorem hestonGamma_eq_cirGamma (κ ξ ρ : ℝ) {u : ℝ} (hu₀ : 0 ≤ u) (hu₁ : u ≤ 1) : + hestonGamma κ ξ ρ u = cirGamma (κ - ρ * ξ * u) (ξ * Real.sqrt ((u - u ^ 2) / 2)) := by + have h : 0 ≤ (u - u ^ 2) / 2 := by nlinarith + rw [hestonGamma, cirGamma, mul_pow, Real.sq_sqrt h] + ring_nf + +/-- The shared Möbius denominator `D(τ) = (γ + κ − ρξu)e^{γτ} + (γ − κ + ρξu)` +(positive on the strip for every real `τ`). -/ +noncomputable def hestonBvDenom (κ ξ ρ u τ : ℝ) : ℝ := + (hestonGamma κ ξ ρ u + κ - ρ * ξ * u) * Real.exp (hestonGamma κ ξ ρ u * τ) + + (hestonGamma κ ξ ρ u - κ + ρ * ξ * u) + +/-- The **Heston `Bv`-flow** (maturity time): the explicit Möbius solution of +`b̂' = ½(u² − u) + (ρξu − κ)b̂ + ½ξ²b̂²`, `b̂(0) = 0`: + +`b̂(τ) = (u² − u)(e^{γτ} − 1) / D(τ)`. -/ +noncomputable def hestonBv (κ ξ ρ u τ : ℝ) : ℝ := + (u ^ 2 - u) * (Real.exp (hestonGamma κ ξ ρ u * τ) - 1) / hestonBvDenom κ ξ ρ u τ + +/-- The **Heston `A`-flow** (maturity time): the explicit antiderivative of +`ru + κθ·b̂` vanishing at `τ = 0`: + +`â(τ) = ruτ + (2κθ/ξ²)[((γ + κ − ρξu)/2)τ − log(D(τ)/(2γ))]` + +(the integral of the Möbius flow is the log of the shared denominator — the +linearization identity `b̂ = −(2/ξ²)(log w)'` with `w = e^{λ₋τ}D(τ)/(2γ)`). -/ +noncomputable def hestonA (r κ θ ξ ρ u τ : ℝ) : ℝ := + r * u * τ + (2 * κ * θ / ξ ^ 2) + * ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) / 2 * τ + - Real.log (hestonBvDenom κ ξ ρ u τ / (2 * hestonGamma κ ξ ρ u))) + +/-! #### γ-plumbing (private) -/ + +private theorem hestonGamma_sq (κ ξ ρ u : ℝ) (hu1 : 0 < u) (hu2 : u < 1) : + hestonGamma κ ξ ρ u ^ 2 = (κ - ρ * ξ * u) ^ 2 + ξ ^ 2 * (u - u ^ 2) := by + have hpos : 0 < u * (1 - u) := mul_pos hu1 (by linarith) + have h1 : 0 < u - u ^ 2 := by nlinarith [hpos] + have h3 : 0 ≤ ξ ^ 2 * (u - u ^ 2) := mul_nonneg (sq_nonneg ξ) h1.le + have hnng : 0 ≤ (κ - ρ * ξ * u) ^ 2 + ξ ^ 2 * (u - u ^ 2) := by + linarith [sq_nonneg (κ - ρ * ξ * u), h3] + rw [pow_two, hestonGamma, Real.mul_self_sqrt hnng] + +private theorem hestonGamma_pos (κ ξ ρ u : ℝ) (hξ : ξ ≠ 0) (hu1 : 0 < u) (hu2 : u < 1) : + 0 < hestonGamma κ ξ ρ u := by + refine Real.sqrt_pos.mpr ?_ + have hpos : 0 < u * (1 - u) := mul_pos hu1 (by linarith) + have h1 : 0 < ξ ^ 2 * (u - u ^ 2) := by + have := mul_pos (sq_pos_of_ne_zero hξ) (by nlinarith [hpos]) + nlinarith [this] + have h2 : 0 ≤ (κ - ρ * ξ * u) ^ 2 := sq_nonneg _ + nlinarith + +private theorem hestonGamma_ne_zero (κ ξ ρ u : ℝ) (hξ : ξ ≠ 0) (hu1 : 0 < u) (hu2 : u < 1) : + hestonGamma κ ξ ρ u ≠ 0 := + ne_of_gt (hestonGamma_pos κ ξ ρ u hξ hu1 hu2) + +private theorem hestonGamma_abs_lt (κ ξ ρ u : ℝ) (hξ : ξ ≠ 0) (hu1 : 0 < u) (hu2 : u < 1) : + κ - ρ * ξ * u < hestonGamma κ ξ ρ u ∧ -(κ - ρ * ξ * u) < hestonGamma κ ξ ρ u := by + have hγpos : 0 < hestonGamma κ ξ ρ u := hestonGamma_pos κ ξ ρ u hξ hu1 hu2 + have hsq : (κ - ρ * ξ * u) ^ 2 < hestonGamma κ ξ ρ u ^ 2 := by + rw [hestonGamma_sq κ ξ ρ u hu1 hu2] + have hpos : 0 < u * (1 - u) := mul_pos hu1 (by linarith) + have hp : 0 < ξ ^ 2 * (u - u ^ 2) := by + have := mul_pos (sq_pos_of_ne_zero hξ) (by nlinarith [hpos]) + nlinarith [this] + linarith + have hab := abs_lt.mp (abs_lt_of_sq_lt_sq hsq hγpos.le) + constructor + · linarith [hab.2] + · linarith [hab.1] + +/-- The shared denominator is positive on the strip, for **every** real `τ` +(no per-τ guard: both coefficients `γ ± (κ − ρξu)` are positive and `e^{γτ} > 0`). -/ +theorem hestonBvDenom_pos (κ ξ ρ u τ : ℝ) (hξ : ξ ≠ 0) (hu1 : 0 < u) (hu2 : u < 1) : + 0 < hestonBvDenom κ ξ ρ u τ := by + obtain ⟨h1, h2⟩ := hestonGamma_abs_lt κ ξ ρ u hξ hu1 hu2 + exact add_pos (mul_pos (by linarith) (Real.exp_pos _)) (by linarith) + +/-- Terminal data of the `Bv`-flow: `b̂(0) = 0` (definitional — the numerator +vanishes; no guard needed). -/ +theorem hestonBv_at_zero (κ ξ ρ u : ℝ) : hestonBv κ ξ ρ u 0 = 0 := by + simp only [hestonBv, mul_zero, Real.exp_zero, sub_self, mul_zero, zero_div] + +/-- Terminal data of the `A`-flow: `â(0) = 0` (the linear terms die and the log +sees `D(0)/(2γ) = 2γ/(2γ) = 1`; guard `γ ≠ 0`). -/ +theorem hestonA_at_zero (r κ θ ξ ρ u : ℝ) (hγ : hestonGamma κ ξ ρ u ≠ 0) : + hestonA r κ θ ξ ρ u 0 = 0 := by + have hD0 : hestonBvDenom κ ξ ρ u 0 = 2 * hestonGamma κ ξ ρ u := by + simp only [hestonBvDenom, mul_zero, Real.exp_zero, mul_one] + ring + have h2γ : (2 : ℝ) * hestonGamma κ ξ ρ u ≠ 0 := + mul_ne_zero (by norm_num) hγ + simp only [hestonA, mul_zero, hD0] + rw [div_self h2γ, Real.log_one, sub_self, mul_zero, add_zero] + +/-- **The `Bv` Riccati ODE.** The Möbius closed form solves +`b̂' = ½(u² − u) + (ρξu − κ)b̂ + ½ξ²b̂²` — the Calc 14.6 ψ-equation in the Heston +roles with the x-row's constant. Proof: as `hasDerivAt_cirBondB` +(quotient rule, the coefficient rewrite `ξ²/2 = ((κ−ρξu)² − γ²)/(2(u²−u))` from +`γ² = (κ−ρξu)² + ξ²(u−u²)`, then `field_simp`/`ring`; the residual is a polynomial +identity). -/ +theorem hasDerivAt_hestonBv (κ ξ ρ u τ : ℝ) (hξ : ξ ≠ 0) (hu1 : 0 < u) (hu2 : u < 1) : + HasDerivAt (hestonBv κ ξ ρ u) + ((u ^ 2 - u) / 2 + (ρ * ξ * u - κ) * hestonBv κ ξ ρ u τ + + ξ ^ 2 / 2 * hestonBv κ ξ ρ u τ ^ 2) τ := by + have hc : ξ ^ 2 * (u ^ 2 - u) = (κ - ρ * ξ * u) ^ 2 - hestonGamma κ ξ ρ u ^ 2 := by + rw [hestonGamma_sq κ ξ ρ u hu1 hu2] + ring + -- derivative building blocks + have hlin : HasDerivAt (fun s : ℝ => hestonGamma κ ξ ρ u * s) (hestonGamma κ ξ ρ u) τ := by + simpa using (hasDerivAt_id τ).const_mul (hestonGamma κ ξ ρ u) + have hexp : HasDerivAt (fun s : ℝ => Real.exp (hestonGamma κ ξ ρ u * s)) + (Real.exp (hestonGamma κ ξ ρ u * τ) * hestonGamma κ ξ ρ u) τ := by + simpa using hlin.exp + have hnum : HasDerivAt (fun s : ℝ => (u ^ 2 - u) * (Real.exp (hestonGamma κ ξ ρ u * s) - 1)) + ((u ^ 2 - u) * (Real.exp (hestonGamma κ ξ ρ u * τ) * hestonGamma κ ξ ρ u)) τ := by + simpa using (hexp.sub_const 1).const_mul (u ^ 2 - u) + have hden : HasDerivAt (fun s : ℝ => (hestonGamma κ ξ ρ u + κ - ρ * ξ * u) + * Real.exp (hestonGamma κ ξ ρ u * s) + (hestonGamma κ ξ ρ u - κ + ρ * ξ * u)) + ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) + * (Real.exp (hestonGamma κ ξ ρ u * τ) * hestonGamma κ ξ ρ u)) τ := by + simpa using (hexp.const_mul (hestonGamma κ ξ ρ u + κ - ρ * ξ * u)).fun_add + (hasDerivAt_const τ (hestonGamma κ ξ ρ u - κ + ρ * ξ * u)) + have hDne : hestonBvDenom κ ξ ρ u τ ≠ 0 := + ne_of_gt (hestonBvDenom_pos κ ξ ρ u τ hξ hu1 hu2) + have hD2 : hestonBvDenom κ ξ ρ u τ ^ 2 ≠ 0 := pow_ne_zero 2 hDne + have hq := hnum.div hden hDne + -- the value identity, cleared deterministically: strip the outer `D²`, expand the + -- remaining products, then one `linear_combination` with the γ-relation `hc` + -- (multiplier `−(u²−u)(E−1)²/2`) + have hval : + (((u ^ 2 - u) * (Real.exp (hestonGamma κ ξ ρ u * τ) * hestonGamma κ ξ ρ u) * + ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) * Real.exp (hestonGamma κ ξ ρ u * τ) + + (hestonGamma κ ξ ρ u - κ + ρ * ξ * u)) - + (u ^ 2 - u) * (Real.exp (hestonGamma κ ξ ρ u * τ) - 1) * + ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) + * (Real.exp (hestonGamma κ ξ ρ u * τ) * hestonGamma κ ξ ρ u))) / + ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) * Real.exp (hestonGamma κ ξ ρ u * τ) + + (hestonGamma κ ξ ρ u - κ + ρ * ξ * u)) ^ 2) + = (u ^ 2 - u) / 2 + (ρ * ξ * u - κ) * hestonBv κ ξ ρ u τ + + ξ ^ 2 / 2 * hestonBv κ ξ ρ u τ ^ 2 := by + rw [show ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) * Real.exp (hestonGamma κ ξ ρ u * τ) + + (hestonGamma κ ξ ρ u - κ + ρ * ξ * u)) = hestonBvDenom κ ξ ρ u τ from rfl, + show hestonBv κ ξ ρ u τ = (u ^ 2 - u) + * (Real.exp (hestonGamma κ ξ ρ u * τ) - 1) / hestonBvDenom κ ξ ρ u τ from rfl] + rw [div_eq_iff hD2] + have hR : ((u ^ 2 - u) / 2 + (ρ * ξ * u - κ) + * ((u ^ 2 - u) * (Real.exp (hestonGamma κ ξ ρ u * τ) - 1) + / hestonBvDenom κ ξ ρ u τ) + + ξ ^ 2 / 2 * ((u ^ 2 - u) * (Real.exp (hestonGamma κ ξ ρ u * τ) - 1) + / hestonBvDenom κ ξ ρ u τ) ^ 2) * hestonBvDenom κ ξ ρ u τ ^ 2 + = (u ^ 2 - u) * hestonBvDenom κ ξ ρ u τ ^ 2 / 2 + (ρ * ξ * u - κ) * (u ^ 2 - u) + * (Real.exp (hestonGamma κ ξ ρ u * τ) - 1) * hestonBvDenom κ ξ ρ u τ + + ξ ^ 2 / 2 * (u ^ 2 - u) ^ 2 * (Real.exp (hestonGamma κ ξ ρ u * τ) - 1) ^ 2 := by + rw [div_pow] + field_simp [hDne] + rw [hR] + simp only [hestonBvDenom] + linear_combination (-(u ^ 2 - u) * (Real.exp (hestonGamma κ ξ ρ u * τ) - 1) ^ 2 / 2) * hc + rw [hval] at hq + exact hq + +/-- **The `A`-flow ODE.** `â' = r·u + κθ·b̂` — the integral half of the Riccati +system (`φ' = aψ + ½cψ²`, eq. 14.5, in the Heston roles: the x-row contributes +`r·u`, the v-row `κθ·b̂`). Proof: the `hasDerivAt_cirBondA` idiom — the log's +derivative via `.div_const` + `.log`, cleaned by the key lemma +`(γ + κ − ρξu)(D(τ) − 2γe^{γτ}) = ξ²(u² − u)(e^{γτ} − 1)` (pure ring after the +γ-relation). Guard: the strip. -/ +theorem hasDerivAt_hestonA (r κ θ ξ ρ u τ : ℝ) (hξ : ξ ≠ 0) (hu1 : 0 < u) (hu2 : u < 1) : + HasDerivAt (hestonA r κ θ ξ ρ u) (r * u + κ * θ * hestonBv κ ξ ρ u τ) τ := by + have hγpos : 0 < hestonGamma κ ξ ρ u := hestonGamma_pos κ ξ ρ u hξ hu1 hu2 + have hγne : hestonGamma κ ξ ρ u ≠ 0 := ne_of_gt hγpos + have hDne : hestonBvDenom κ ξ ρ u τ ≠ 0 := + ne_of_gt (hestonBvDenom_pos κ ξ ρ u τ hξ hu1 hu2) + have hDne' : (hestonGamma κ ξ ρ u + κ - ρ * ξ * u) + * Real.exp (hestonGamma κ ξ ρ u * τ) + (hestonGamma κ ξ ρ u - κ + ρ * ξ * u) + ≠ 0 := hDne + have hξ2 : ξ ^ 2 ≠ 0 := pow_ne_zero 2 hξ + have hpos : 0 < u * (1 - u) := mul_pos hu1 (by linarith) + have hnlt : u ^ 2 - u < 0 := by nlinarith [hpos] + have hc : ξ ^ 2 * (u ^ 2 - u) = (κ - ρ * ξ * u) ^ 2 - hestonGamma κ ξ ρ u ^ 2 := by + rw [hestonGamma_sq κ ξ ρ u hu1 hu2] + ring + -- the key lemma (folded denominator as an atom): the linearization identity + have hkey : (hestonGamma κ ξ ρ u + κ - ρ * ξ * u) + * (hestonBvDenom κ ξ ρ u τ - 2 * hestonGamma κ ξ ρ u + * Real.exp (hestonGamma κ ξ ρ u * τ)) + = ξ ^ 2 * (u ^ 2 - u) * (Real.exp (hestonGamma κ ξ ρ u * τ) - 1) := by + simp only [hestonBvDenom] + rw [hc] + ring + -- derivative building blocks + have hlin : HasDerivAt (fun s : ℝ => hestonGamma κ ξ ρ u * s) (hestonGamma κ ξ ρ u) τ := by + simpa using (hasDerivAt_id τ).const_mul (hestonGamma κ ξ ρ u) + have hexp : HasDerivAt (fun s : ℝ => Real.exp (hestonGamma κ ξ ρ u * s)) + (Real.exp (hestonGamma κ ξ ρ u * τ) * hestonGamma κ ξ ρ u) τ := by + simpa using hlin.exp + have hterm1 : HasDerivAt (fun s : ℝ => r * u * s) (r * u) τ := by + simpa using (hasDerivAt_id τ).const_mul (r * u) + have hterm2 : HasDerivAt (fun s : ℝ => (hestonGamma κ ξ ρ u + κ - ρ * ξ * u) / 2 * s) + ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) / 2) τ := by + simpa using (hasDerivAt_id τ).const_mul ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) / 2) + have hdenf : HasDerivAt (fun s : ℝ => (hestonGamma κ ξ ρ u + κ - ρ * ξ * u) + * Real.exp (hestonGamma κ ξ ρ u * s) + (hestonGamma κ ξ ρ u - κ + ρ * ξ * u)) + ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) + * (Real.exp (hestonGamma κ ξ ρ u * τ) * hestonGamma κ ξ ρ u)) τ := by + simpa using (hexp.const_mul (hestonGamma κ ξ ρ u + κ - ρ * ξ * u)).fun_add + (hasDerivAt_const τ (hestonGamma κ ξ ρ u - κ + ρ * ξ * u)) + have h2γ : (2 : ℝ) * hestonGamma κ ξ ρ u ≠ 0 := mul_ne_zero (by norm_num) hγne + have hdiv := hdenf.div_const (2 * hestonGamma κ ξ ρ u) + have hdivne : hestonBvDenom κ ξ ρ u τ / (2 * hestonGamma κ ξ ρ u) ≠ 0 := + div_ne_zero hDne h2γ + have hlog := hdiv.log hdivne + -- assemble the two terms of `hestonA` + have hterm3 : HasDerivAt (fun s : ℝ => (2 * κ * θ / ξ ^ 2) + * ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) / 2 * s + - Real.log (hestonBvDenom κ ξ ρ u s / (2 * hestonGamma κ ξ ρ u)))) + ((2 * κ * θ / ξ ^ 2) + * ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) / 2 + - (((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) + * (Real.exp (hestonGamma κ ξ ρ u * τ) * hestonGamma κ ξ ρ u)) + / (2 * hestonGamma κ ξ ρ u)) + / (hestonBvDenom κ ξ ρ u τ / (2 * hestonGamma κ ξ ρ u)))) τ := + (hterm2.fun_sub hlog).const_mul (2 * κ * θ / ξ ^ 2) + have hsum : HasDerivAt (hestonA r κ θ ξ ρ u) + (r * u + (2 * κ * θ / ξ ^ 2) + * ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) / 2 + - (((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) + * (Real.exp (hestonGamma κ ξ ρ u * τ) * hestonGamma κ ξ ρ u)) + / (2 * hestonGamma κ ξ ρ u)) + / (hestonBvDenom κ ξ ρ u τ / (2 * hestonGamma κ ξ ρ u)))) τ := + hterm1.fun_add hterm3 + -- the value identity: clean the nested division, then the key lemma + have hstep1 : (((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) + * (Real.exp (hestonGamma κ ξ ρ u * τ) * hestonGamma κ ξ ρ u)) + / (2 * hestonGamma κ ξ ρ u)) + / (hestonBvDenom κ ξ ρ u τ / (2 * hestonGamma κ ξ ρ u)) + = (hestonGamma κ ξ ρ u + κ - ρ * ξ * u) * hestonGamma κ ξ ρ u + * Real.exp (hestonGamma κ ξ ρ u * τ) / hestonBvDenom κ ξ ρ u τ := by + field_simp [h2γ, hDne] + have hmain : (2 * κ * θ / ξ ^ 2) + * ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) / 2 + - (hestonGamma κ ξ ρ u + κ - ρ * ξ * u) * hestonGamma κ ξ ρ u + * Real.exp (hestonGamma κ ξ ρ u * τ) / hestonBvDenom κ ξ ρ u τ) + = κ * θ * ((u ^ 2 - u) * (Real.exp (hestonGamma κ ξ ρ u * τ) - 1) + / hestonBvDenom κ ξ ρ u τ) := by + have hcore : (2 / ξ ^ 2) + * ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) / 2 + - (hestonGamma κ ξ ρ u + κ - ρ * ξ * u) * hestonGamma κ ξ ρ u + * Real.exp (hestonGamma κ ξ ρ u * τ) / hestonBvDenom κ ξ ρ u τ) + = (u ^ 2 - u) * (Real.exp (hestonGamma κ ξ ρ u * τ) - 1) + / hestonBvDenom κ ξ ρ u τ := by + have hL : (2 / ξ ^ 2) + * ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) / 2 + - (hestonGamma κ ξ ρ u + κ - ρ * ξ * u) * hestonGamma κ ξ ρ u + * Real.exp (hestonGamma κ ξ ρ u * τ) / hestonBvDenom κ ξ ρ u τ) + = (2 * ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) / 2 + * hestonBvDenom κ ξ ρ u τ + - (hestonGamma κ ξ ρ u + κ - ρ * ξ * u) * hestonGamma κ ξ ρ u + * Real.exp (hestonGamma κ ξ ρ u * τ))) + / (ξ ^ 2 * hestonBvDenom κ ξ ρ u τ) := by + field_simp [hξ2, hDne] + rw [hL, div_eq_div_iff (mul_ne_zero hξ2 hDne) hDne] + linear_combination hestonBvDenom κ ξ ρ u τ * hkey + calc (2 * κ * θ / ξ ^ 2) + * ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) / 2 + - (hestonGamma κ ξ ρ u + κ - ρ * ξ * u) * hestonGamma κ ξ ρ u + * Real.exp (hestonGamma κ ξ ρ u * τ) / hestonBvDenom κ ξ ρ u τ) + = κ * θ * ((2 / ξ ^ 2) + * ((hestonGamma κ ξ ρ u + κ - ρ * ξ * u) / 2 + - (hestonGamma κ ξ ρ u + κ - ρ * ξ * u) * hestonGamma κ ξ ρ u + * Real.exp (hestonGamma κ ξ ρ u * τ) / hestonBvDenom κ ξ ρ u τ)) := by + ring + _ = κ * θ * ((u ^ 2 - u) * (Real.exp (hestonGamma κ ξ ρ u * τ) - 1) + / hestonBvDenom κ ξ ρ u τ) := by rw [hcore] + rw [hstep1, hmain] at hsum + exact hsum + +/-! ### The calendar-time flip (the PDE's time direction) -/ + +/-- **Calendar-time `Bv`-flow.** `B(t) = b̂(T − t)` solves +`B' = u/2 − u²/2 + (κ − ρξu)B − (ξ²/2)B²` — exactly the `hB` hypothesis of +`hestonProfile_pde` (chain rule: `B'(t) = −b̂'(T − t)`). -/ +theorem hasDerivAt_hestonBvCalendar (κ ξ ρ u T : ℝ) (hξ : ξ ≠ 0) (hu1 : 0 < u) + (hu2 : u < 1) (t : ℝ) : + HasDerivAt (fun w => hestonBv κ ξ ρ u (T - w)) + (u / 2 - u ^ 2 / 2 + κ * hestonBv κ ξ ρ u (T - t) + - ρ * ξ * u * hestonBv κ ξ ρ u (T - t) + - ξ ^ 2 / 2 * hestonBv κ ξ ρ u (T - t) ^ 2) t := by + have hts : HasDerivAt (fun w : ℝ => T - w) (-1) t := by + simpa using (hasDerivAt_id t).const_sub T + have hval : ((u ^ 2 - u) / 2 + (ρ * ξ * u - κ) * hestonBv κ ξ ρ u (T - t) + + ξ ^ 2 / 2 * hestonBv κ ξ ρ u (T - t) ^ 2) * (-1) + = u / 2 - u ^ 2 / 2 + κ * hestonBv κ ξ ρ u (T - t) + - ρ * ξ * u * hestonBv κ ξ ρ u (T - t) + - ξ ^ 2 / 2 * hestonBv κ ξ ρ u (T - t) ^ 2 := by + ring + have hcomp : HasDerivAt (fun w : ℝ => hestonBv κ ξ ρ u (T - w)) + (((u ^ 2 - u) / 2 + (ρ * ξ * u - κ) * hestonBv κ ξ ρ u (T - t) + + ξ ^ 2 / 2 * hestonBv κ ξ ρ u (T - t) ^ 2) * (-1)) t := + (hasDerivAt_hestonBv κ ξ ρ u (T - t) hξ hu1 hu2).comp t hts + rw [hval] at hcomp + exact hcomp + +/-- **Calendar-time `A`-flow.** `A(t) = â(T − t)` solves `A' = −r·u − κθ·B(t)` — +exactly the `hA` hypothesis of `hestonProfile_pde`. -/ +theorem hasDerivAt_hestonACalendar (r κ θ ξ ρ u T : ℝ) (hξ : ξ ≠ 0) (hu1 : 0 < u) + (hu2 : u < 1) (t : ℝ) : + HasDerivAt (fun w => hestonA r κ θ ξ ρ u (T - w)) + (-(r * u) - κ * θ * hestonBv κ ξ ρ u (T - t)) t := by + have hts : HasDerivAt (fun w : ℝ => T - w) (-1) t := by + simpa using (hasDerivAt_id t).const_sub T + have hval : (r * u + κ * θ * hestonBv κ ξ ρ u (T - t)) * (-1) + = -(r * u) - κ * θ * hestonBv κ ξ ρ u (T - t) := by + ring + have hcomp : HasDerivAt (fun w : ℝ => hestonA r κ θ ξ ρ u (T - w)) + ((r * u + κ * θ * hestonBv κ ξ ρ u (T - t)) * (-1)) t := + (hasDerivAt_hestonA r κ θ ξ ρ u (T - t) hξ hu1 hu2).comp t hts + rw [hval] at hcomp + exact hcomp + +/-! ### The PDE headline (mirrors `affineBondPrice_solves_pde` / `cirBondPrice_solves_pde`) -/ + +/-- The **candidate transform profile** `Φ(t, x, v) = e^{A(t) + u·x + B(t)·v}` with +terminal data `Φ(T, x, v) = e^{u·x}` (the real-moment transform +`M(u) = E[e^{u log S_T}]`; the characteristic function is the same Riccati system +at `iu`). The parameters live in the flows `A, B`. -/ +noncomputable def hestonProfile (u : ℝ) (A B : ℝ → ℝ) (t x v : ℝ) : ℝ := + Real.exp (A t + u * x + B t * v) + +/-- Terminal condition: with the transform's terminal data `A(T) = 0`, `B(T) = 0` +the profile expires to the payoff `e^{u·x}`. -/ +theorem hestonProfile_terminal (u : ℝ) (A B : ℝ → ℝ) (T x v : ℝ) + (hAT : A T = 0) (hBT : B T = 0) : + hestonProfile u A B T x v = Real.exp (u * x) := by + simp only [hestonProfile, hAT, hBT, zero_mul, add_zero, zero_add] + +/-- **The PDE verification (hypothesis version, the `affineBondPrice_solves_pde` mirror).** +For any coefficient flows `A, B` solving the calendar-time Heston Riccati system + +`B' = u/2 − u²/2 + (κ − ρξu)B − (ξ²/2)B²`, `A' = −r·u − κθ·B`, + +the transform profile satisfies the **backward pricing equation** + +`∂_t Φ + L Φ = 0`, `L = hestonGenerator r κ θ ξ ρ`, + +for every `(t, x, v)` (no `t < T` hypothesis needed — the identity holds +identically; the terminal condition is `hestonProfile_terminal`). Unlike the bond PDEs +of `Models/Rates/AffineTermStructurePDE` there is no discount term on the right: the +funding rate `r` sits inside the drift of `x`, and the payoff `e^{ux}` carries no +discounting. -/ +theorem hestonProfile_pde (r κ θ ξ ρ u : ℝ) (A B : ℝ → ℝ) + (hB : ∀ s, HasDerivAt B (u / 2 - u ^ 2 / 2 + κ * B s - ρ * ξ * u * B s + - ξ ^ 2 / 2 * B s ^ 2) s) + (hA : ∀ s, HasDerivAt A (-(r * u) - κ * θ * B s) s) + (t x v : ℝ) : + deriv (fun s => hestonProfile u A B s x v) t + + hestonGenerator r κ θ ξ ρ (hestonProfile u A B t) x v = 0 := by + -- time derivative: `Φ_t = (A' + B'·v)·Φ` + have hinner : HasDerivAt (fun s : ℝ => A s + (u * x) + B s * v) + (-(r * u) - κ * θ * B t + + (u / 2 - u ^ 2 / 2 + κ * B t - ρ * ξ * u * B t - ξ ^ 2 / 2 * B t ^ 2) * v) t := by + simpa only [add_zero] using + ((hA t).fun_add (hasDerivAt_const t (u * x))).fun_add ((hB t).mul_const v) + have htime : HasDerivAt (fun s : ℝ => hestonProfile u A B s x v) + (Real.exp (A t + u * x + B t * v) + * (-(r * u) - κ * θ * B t + + (u / 2 - u ^ 2 / 2 + κ * B t - ρ * ξ * u * B t - ξ ^ 2 / 2 * B t ^ 2) * v)) t := + hinner.exp + have htime' : deriv (fun s => hestonProfile u A B s x v) t + = Real.exp (A t + u * x + B t * v) + * (-(r * u) - κ * θ * B t + + (u / 2 - u ^ 2 / 2 + κ * B t - ρ * ξ * u * B t - ξ ^ 2 / 2 * B t ^ 2) * v) := + htime.deriv + -- spatial derivatives: the t-frozen profile *is* `expAffine2 (A t) u (B t)` + have hf : hestonProfile u A B t = expAffine2 (A t) u (B t) := rfl + rw [htime', hf, hestonGenerator_expAffine2] + ring + +/-- **The PDE verification (explicit version, the `cirBondPrice_solves_pde` mirror).** +The transform profile built from the explicit Möbius flows +`A(t) = â(T − t)`, `B(t) = b̂(T − t)` satisfies `∂_t Φ + L Φ = 0` for every +`(t, x, v)`. Guards: the strip `0 < u < 1`, `ξ ≠ 0`. -/ +theorem hestonTransform_pde (r κ θ ξ ρ u T : ℝ) (hξ : ξ ≠ 0) (hu1 : 0 < u) + (hu2 : u < 1) (t x v : ℝ) : + deriv (fun s => hestonProfile u (fun w => hestonA r κ θ ξ ρ u (T - w)) + (fun w => hestonBv κ ξ ρ u (T - w)) s x v) t + + hestonGenerator r κ θ ξ ρ (hestonProfile u (fun w => hestonA r κ θ ξ ρ u (T - w)) + (fun w => hestonBv κ ξ ρ u (T - w)) t) x v = 0 := + hestonProfile_pde r κ θ ξ ρ u (fun w => hestonA r κ θ ξ ρ u (T - w)) + (fun w => hestonBv κ ξ ρ u (T - w)) + (fun s => hasDerivAt_hestonBvCalendar κ ξ ρ u T hξ hu1 hu2 s) + (fun s => hasDerivAt_hestonACalendar r κ θ ξ ρ u T hξ hu1 hu2 s) t x v + +/-- Terminal condition of the explicit transform: `Φ(T, x, v) = e^{u·x}` +(`â(0) = 0`, `b̂(0) = 0`). -/ +theorem hestonTransform_terminal (r κ θ ξ ρ u T x v : ℝ) (hξ : ξ ≠ 0) (hu1 : 0 < u) + (hu2 : u < 1) : + hestonProfile u (fun w => hestonA r κ θ ξ ρ u (T - w)) + (fun w => hestonBv κ ξ ρ u (T - w)) T x v + = Real.exp (u * x) := + hestonProfile_terminal u _ _ T x v + (by simpa using hestonA_at_zero r κ θ ξ ρ u (hestonGamma_ne_zero κ ξ ρ u hξ hu1 hu2)) + (by simpa using hestonBv_at_zero κ ξ ρ u) + +end MathFin.Heston diff --git a/LeanPool/MathFin/Models/StochVol/HestonSmallVolOfVol.lean b/LeanPool/MathFin/Models/StochVol/HestonSmallVolOfVol.lean new file mode 100644 index 0000000000..12c7202a9e --- /dev/null +++ b/LeanPool/MathFin/Models/StochVol/HestonSmallVolOfVol.lean @@ -0,0 +1,270 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.StochVol.Heston +public import LeanPool.MathFin.Models.Rates.AffineTermStructurePDE + +/-! +# The Heston transform at vanishing vol-of-vol + +The Riccati closed forms of `Models/StochVol/Heston.lean` (`hestonBv`, `hestonA`) carry the +vol-of-vol `ξ` in two places that break at `ξ = 0`: the prefactor `2κθ/ξ²` of the `A`-flow, +multiplying the bracket `((γ + κ − ρξu)/2)τ − log(D(τ)/(2γ))` whose two terms each tend to +`κτ`. Each piece alone diverges like `κ²θτ/ξ²`; their difference is `O(ξ²)`. This is the +cancellation that a small-`σ` Taylor branch (as in QuantLib's `AnalyticHestonEngine::chF`) +handles. This file proves the limit such a branch must reach, at the level of the Riccati +closed forms. + +At `ξ = 0` the variance follows the deterministic ODE `dv = κ(θ − v)dt`, whose solution is +`vasicekDeterministic v₀ θ κ` (`Models/Rates/Vasicek`), and the transform tends to the +Black–Scholes real moment with total variance +`W = ∫₀^τ v(s) ds = v₀B(τ) + θ(τ − B(τ))`, `B(τ) = (1 − e^{−κτ})/κ` — `vasicekIntegratedMean` +and `vasicekBondB` from `Models/Rates/VasicekBondPrice` (with `hasDerivAt_vasicekBondB` from +`Models/Rates/AffineTermStructurePDE`), reused here as plain closed forms. That `W` is the integral +of the deterministic variance path is `HullWhite.integratedMean_const` with +`HullWhite.deterministic_const` (`Models/Rates/HullWhiteCalibration`); it is not re-proved here, and +the theorems below state the limit with `W := vasicekIntegratedMean v θ κ τ`. + +The `A`-limit is proved without expanding the cancellation: for `ξ ≠ 0`, +`â(τ) = ∫₀^τ (ru + κθ·b̂(s)) ds` (FTC on `hasDerivAt_hestonA`); `b̂` is jointly continuous in +`(ξ, s)` across `ξ = 0` once `κ > 0`, so the parametric integral is continuous in `ξ`. + +Results (`κ > 0`, `0 < u < 1`; limits are `ξ → 0`, `ξ ≠ 0`): + +* `tendsto_hestonBv_smallVolOfVol`: `b̂(τ) → ((u² − u)/2)·B(τ)` (here a genuine + continuity statement, `hestonBv_zero_volOfVol`). +* `hestonA_zero_volOfVol`: Lean's own value at `ξ = 0` is `ruτ` (`2κθ/0 = 0`) — **not** the + limit; the closed form is discontinuous there, the formal shape of the missing branch. +* `tendsto_hestonA_smallVolOfVol`: `â(τ) → ruτ + θ·((u² − u)/2)·(τ − B(τ))`. +* `tendsto_hestonProfile_smallVolOfVol_blackScholes`: the transform profile tends to + `mgf id (gaussianReal (x + r(T − t) − W/2) W) u`, the lognormal log-spot moment. + +**Scope.** This is the real-moment transform `u ∈ (0, 1)` at the Riccati level, as in +`Heston.lean`. Not covered: the characteristic function at complex argument `iu` (QuantLib's +`chF`), the Fourier-inversion price, and the identification of the profile with +`E[e^{u log S_T}]` for a Heston process (`Heston.lean` does not prove it either). The +algebra is the same under `u ↦ iz`: QuantLib's `D = √((κ − iρσz)² + (z² + iz)σ²)` is +`hestonGamma` at `u = iz`. + +## Main results + +* `continuous_hestonBv_volOfVol`: for `κ > 0` and `0 < u < 1`, `(ξ, τ) ↦ hestonBv κ ξ ρ u τ` is + jointly continuous, across `ξ = 0`. +* `hestonBv_zero_volOfVol`, `tendsto_hestonBv_smallVolOfVol`: at `ξ = 0` the flow is + `((u² − u)/2) · B(τ)`, `B(τ) = (1 − e^{−κτ})/κ`, and `b̂ → ` that value as `ξ → 0`. +* `hestonA_zero_volOfVol`: Lean's value of `hestonA` at `ξ = 0` is `r u τ`; this is not the + limit as `ξ → 0`. +* `hestonA_eq_integral`: for `ξ ≠ 0`, `â(τ) = ∫₀^τ (r u + κθ b̂(s)) ds`. +* `tendsto_hestonA_smallVolOfVol`: as `ξ → 0` with `ξ ≠ 0`, + `â(τ) → r u τ + θ ((u² − u)/2) (τ − B(τ))`. +* `tendsto_hestonProfile_smallVolOfVol`: as `ξ → 0` with `ξ ≠ 0`, the Heston profile tends to + `exp(u x + r u (T − t) + ((u² − u)/2) W)`, with `W` the integrated Vasicek mean. +* `tendsto_hestonProfile_smallVolOfVol_blackScholes`: for `v, θ ≥ 0` and `t ≤ T`, the profile + tends to `mgf id (gaussianReal (x + r(T − t) − W/2) W) u`, the lognormal log-spot moment. + This is a limit of the Riccati-level profile, not of a Heston process. + +## References + +* [Heston, *A closed-form solution for options with stochastic volatility with applications to bond + and currency options*][Heston1993] +* [The QuantLib contributors, *QuantLib*][QuantLib], AnalyticHestonEngine::chF + +## Tags + +Heston model, vanishing vol-of-vol, stochastic volatility, Riccati equation, Black–Scholes limit, +MSC 91G20, MSC 60J60, JEL G13 +-/ + +@[expose] public section + +open Filter Topology ProbabilityTheory +open scoped NNReal + +namespace MathFin.Heston + +/-- At zero vol-of-vol the Heston root is the mean-reversion speed: `γ = √(κ²) = κ`. -/ +theorem hestonGamma_zero_volOfVol {κ : ℝ} (hκ : 0 < κ) (ρ u : ℝ) : + hestonGamma κ 0 ρ u = κ := by + simp only [hestonGamma, mul_zero, zero_mul, sub_zero, ne_eq, OfNat.ofNat_ne_zero, + not_false_eq_true, zero_pow, add_zero] + exact Real.sqrt_sq hκ.le + +/-- The shared Möbius denominator is positive for **every** vol-of-vol `ξ`, the degenerate +`ξ = 0` included, once `κ > 0`: at `ξ = 0` it is `2κe^{κτ}`, and for `ξ ≠ 0` this is +`hestonBvDenom_pos`. -/ +theorem hestonBvDenom_pos_of_kappa_pos {κ u : ℝ} (hκ : 0 < κ) (hu1 : 0 < u) (hu2 : u < 1) + (ξ ρ τ : ℝ) : 0 < hestonBvDenom κ ξ ρ u τ := by + rcases eq_or_ne ξ 0 with rfl | hξ + · rw [hestonBvDenom, hestonGamma_zero_volOfVol hκ] + simp only [mul_zero, zero_mul, sub_zero, add_zero, sub_self] + have := Real.exp_pos (κ * τ) + positivity + · exact hestonBvDenom_pos κ ξ ρ u τ hξ hu1 hu2 + +/-- **The `Bv`-flow is jointly continuous in (vol-of-vol, maturity)**, across `ξ = 0`: +square root, exponential and a quotient whose denominator never vanishes. -/ +theorem continuous_hestonBv_volOfVol {κ u : ℝ} (hκ : 0 < κ) (hu1 : 0 < u) (hu2 : u < 1) + (ρ : ℝ) : Continuous (fun p : ℝ × ℝ => hestonBv κ p.1 ρ u p.2) := by + simp only [hestonBv] + refine Continuous.div ?_ ?_ fun p => (hestonBvDenom_pos_of_kappa_pos hκ hu1 hu2 p.1 ρ p.2).ne' + · simp only [hestonGamma] + fun_prop + · simp only [hestonBvDenom, hestonGamma] + fun_prop + +/-- The `Bv`-flow at zero vol-of-vol: `b̂(τ) = ((u² − u)/2)·B(τ)` with +`B(τ) = (1 − e^{−κτ})/κ` (`vasicekBondB`). -/ +theorem hestonBv_zero_volOfVol {κ : ℝ} (hκ : 0 < κ) (ρ u τ : ℝ) : + hestonBv κ 0 ρ u τ = (u ^ 2 - u) / 2 * vasicekBondB κ τ := by + rw [hestonBv, hestonBvDenom, hestonGamma_zero_volOfVol hκ, vasicekBondB, Real.exp_neg] + simp only [mul_zero, zero_mul, sub_zero, add_zero, sub_self] + have he : Real.exp (κ * τ) ≠ 0 := (Real.exp_pos _).ne' + field_simp + ring + +/-- **Small vol-of-vol limit of the `Bv`-flow**: `b̂ → ((u² − u)/2)·(1 − e^{−κτ})/κ` as +`ξ → 0`. No catastrophic cancellation here — `b̂` is continuous in `ξ` at `0`. -/ +theorem tendsto_hestonBv_smallVolOfVol {κ u : ℝ} (hκ : 0 < κ) (hu1 : 0 < u) (hu2 : u < 1) + (ρ τ : ℝ) : + Tendsto (fun ξ => hestonBv κ ξ ρ u τ) (𝓝 0) (𝓝 ((u ^ 2 - u) / 2 * vasicekBondB κ τ)) := by + rw [← hestonBv_zero_volOfVol hκ ρ u τ] + exact ((continuous_hestonBv_volOfVol hκ hu1 hu2 ρ).comp + (Continuous.prodMk_left τ)).tendsto 0 + +/-! ### The `A`-flow: the `κθ/ξ²` prefactor and the integral route around it -/ + +/-- **Lean's literal value of the `A`-flow at `ξ = 0` drops the `κθ` term**: the prefactor +`2κθ/ξ²` is `2κθ/0 = 0` under Lean's division convention, leaving only `ruτ`. This is *not* +the `ξ → 0` limit (`tendsto_hestonA_smallVolOfVol`): the closed form `hestonA` is +discontinuous at `ξ = 0`, which is the formal shape of the missing small-`ξ` branch. -/ +theorem hestonA_zero_volOfVol (r κ θ ρ u τ : ℝ) : hestonA r κ θ 0 ρ u τ = r * u * τ := by + simp [hestonA] + +/-- **The `A`-flow as an integral of the `Bv`-flow** (`ξ ≠ 0`): +`â(τ) = ∫₀^τ (ru + κθ·b̂(s)) ds` — the fundamental theorem of calculus on +`hasDerivAt_hestonA` with `â(0) = 0`. This form carries no `1/ξ²` and is the route to the +`ξ → 0` limit. -/ +theorem hestonA_eq_integral {κ ξ u : ℝ} (r θ ρ : ℝ) (hξ : ξ ≠ 0) (hu1 : 0 < u) (hu2 : u < 1) + (τ : ℝ) : + hestonA r κ θ ξ ρ u τ = ∫ s in (0 : ℝ)..τ, (r * u + κ * θ * hestonBv κ ξ ρ u s) := by + have hcont : Continuous (fun s => r * u + κ * θ * hestonBv κ ξ ρ u s) := + continuous_const.add (continuous_const.mul (continuous_iff_continuousAt.2 fun s => + (hasDerivAt_hestonBv κ ξ ρ u s hξ hu1 hu2).continuousAt)) + have hγ : hestonGamma κ ξ ρ u ≠ 0 := by + have h := hestonBvDenom_pos κ ξ ρ u 0 hξ hu1 hu2 + simp only [hestonBvDenom, mul_zero, Real.exp_zero, mul_one] at h + intro h0 + rw [h0] at h + linarith + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun s _ => hasDerivAt_hestonA r κ θ ξ ρ u s hξ hu1 hu2) (hcont.intervalIntegrable _ _), + hestonA_at_zero r κ θ ξ ρ u hγ, sub_zero] + +/-- The integral of the limiting `A`-integrand, in closed form: +`∫₀^τ (ru + κθ·((u² − u)/2)·B(s)) ds = ruτ + θ·((u² − u)/2)·(τ − B(τ))` +(using `κ·B(s) = 1 − e^{−κs}` and `∫₀^τ e^{−κs} ds = B(τ)`). -/ +theorem integral_hestonA_integrand_zero_volOfVol {κ : ℝ} (hκ : κ ≠ 0) (r θ u τ : ℝ) : + ∫ s in (0 : ℝ)..τ, (r * u + κ * θ * ((u ^ 2 - u) / 2 * vasicekBondB κ s)) + = r * u * τ + θ * ((u ^ 2 - u) / 2) * (τ - vasicekBondB κ τ) := by + have hderiv : ∀ s ∈ Set.uIcc (0 : ℝ) τ, + HasDerivAt (fun s => r * u * s + θ * ((u ^ 2 - u) / 2) * (s - vasicekBondB κ s)) + (r * u + κ * θ * ((u ^ 2 - u) / 2 * vasicekBondB κ s)) s := by + intro s _ + have h : HasDerivAt (fun s => r * u * s + θ * ((u ^ 2 - u) / 2) * (s - vasicekBondB κ s)) + (r * u * 1 + θ * ((u ^ 2 - u) / 2) * (1 - (1 - κ * vasicekBondB κ s))) s := + ((hasDerivAt_id' s).const_mul (r * u)).fun_add + (((hasDerivAt_id' s).fun_sub (hasDerivAt_vasicekBondB hκ s)).const_mul + (θ * ((u ^ 2 - u) / 2))) + convert h using 1 + ring + have hcont : Continuous (fun s => r * u + κ * θ * ((u ^ 2 - u) / 2 * vasicekBondB κ s)) := by + simp only [vasicekBondB] + fun_prop + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hderiv (hcont.intervalIntegrable _ _)] + simp [vasicekBondB] + +/-- **Small vol-of-vol limit of the `A`-flow** (the derived-limit core). As `ξ → 0` +(`ξ ≠ 0`), + +`â(τ) → ruτ + θ·((u² − u)/2)·(τ − (1 − e^{−κτ})/κ)`. + +In the closed form `hestonA` the bracket `((γ + κ − ρξu)/2)τ − log(D(τ)/(2γ))` is a +difference of two terms that each tend to `κτ`, multiplied by `2κθ/ξ²` — each piece +alone diverges like `κ²θτ/ξ²`. The proof never touches that cancellation: it rewrites +`â` as `∫₀^τ (ru + κθ·b̂)` (`hestonA_eq_integral`) and passes the limit through the +integral by joint continuity of `b̂` (`continuous_hestonBv_volOfVol`). -/ +theorem tendsto_hestonA_smallVolOfVol {κ u : ℝ} (hκ : 0 < κ) (hu1 : 0 < u) (hu2 : u < 1) + (r θ ρ τ : ℝ) : + Tendsto (fun ξ => hestonA r κ θ ξ ρ u τ) (𝓝[≠] 0) + (𝓝 (r * u * τ + θ * ((u ^ 2 - u) / 2) * (τ - vasicekBondB κ τ))) := by + set F : ℝ → ℝ := fun ξ => ∫ s in (0 : ℝ)..τ, (r * u + κ * θ * hestonBv κ ξ ρ u s) with hFdef + have hF : Continuous F := by + have hc : Continuous (fun p : ℝ × ℝ => r * u + κ * θ * hestonBv κ p.1 ρ u p.2) := + continuous_const.add (continuous_const.mul (continuous_hestonBv_volOfVol hκ hu1 hu2 ρ)) + exact intervalIntegral.continuous_parametric_intervalIntegral_of_continuous' + (f := fun ξ s => r * u + κ * θ * hestonBv κ ξ ρ u s) hc 0 τ + have hF0 : F 0 = r * u * τ + θ * ((u ^ 2 - u) / 2) * (τ - vasicekBondB κ τ) := by + simp only [hFdef, hestonBv_zero_volOfVol hκ] + exact integral_hestonA_integrand_zero_volOfVol hκ.ne' r θ u τ + have hlim : Tendsto F (𝓝[≠] 0) (𝓝 (F 0)) := (hF.tendsto 0).mono_left nhdsWithin_le_nhds + rw [hF0] at hlim + refine hlim.congr' ?_ + filter_upwards [self_mem_nhdsWithin] with ξ hξ + exact (hestonA_eq_integral r θ ρ hξ hu1 hu2 τ).symm + +/-! ### The transform limit and the Black–Scholes identification -/ + +/-- **Small vol-of-vol limit of the Heston transform profile.** As `ξ → 0` (`ξ ≠ 0`), + +`Φ_ξ(t, x, v) = e^{â(T−t) + u·x + b̂(T−t)·v} → exp(ux + ru(T − t) + ((u² − u)/2)·W)`, + +`W = vasicekIntegratedMean v θ κ (T − t) = ∫₀^{T−t} (θ + (v − θ)e^{−κs}) ds` — the integrated +deterministic variance (`HullWhite.integratedMean_const`, `HullWhite.deterministic_const`). -/ +theorem tendsto_hestonProfile_smallVolOfVol {κ u : ℝ} (hκ : 0 < κ) (hu1 : 0 < u) (hu2 : u < 1) + (r θ ρ T t x v : ℝ) : + Tendsto (fun ξ => hestonProfile u (fun w => hestonA r κ θ ξ ρ u (T - w)) + (fun w => hestonBv κ ξ ρ u (T - w)) t x v) (𝓝[≠] 0) + (𝓝 (Real.exp (u * x + r * u * (T - t) + + (u ^ 2 - u) / 2 * vasicekIntegratedMean v θ κ (T - t)))) := by + have hA := tendsto_hestonA_smallVolOfVol hκ hu1 hu2 r θ ρ (T - t) + have hB := (tendsto_hestonBv_smallVolOfVol hκ hu1 hu2 ρ (T - t)).mono_left + (nhdsWithin_le_nhds (s := {0}ᶜ)) + simp only [hestonProfile] + refine (Real.continuous_exp.tendsto _).comp ?_ + convert (hA.add_const (u * x)).add (hB.mul_const v) using 2 + rw [vasicekIntegratedMean] + ring + +/-- The Black–Scholes (lognormal) real moment: if `log S_T ~ N(x + rτ − W/2, W)` then +`E[e^{u log S_T}] = exp(ux + ruτ + ((u² − u)/2)·W)`. -/ +theorem mgf_gaussianReal_logSpot (x r τ u : ℝ) (W : ℝ≥0) : + mgf id (gaussianReal (x + r * τ - W / 2) W) u + = Real.exp (u * x + r * u * τ + (u ^ 2 - u) / 2 * W) := by + simp only [mgf_id_gaussianReal] + congr 1 + ring + +/-- **Headline: the Heston transform tends to the Black–Scholes moment with the integrated +variance.** For `κ > 0`, `0 < u < 1`, `v, θ ≥ 0`, `t ≤ T`, as the vol-of-vol `ξ → 0` +(`ξ ≠ 0`) the Heston transform profile (`hestonProfile` built from the Riccati closed forms +`hestonA`, `hestonBv`) converges to `E[e^{u·X}]` for the Gaussian +`X ~ N(x + r(T − t) − W/2, W)` — the log-spot law of Black–Scholes with total variance +`W = ∫₀^{T−t} v(s) ds`, `v(s) = θ + (v − θ)e^{−κs}` the `ξ = 0` variance path. -/ +theorem tendsto_hestonProfile_smallVolOfVol_blackScholes {κ u : ℝ} (hκ : 0 < κ) (hu1 : 0 < u) + (hu2 : u < 1) (r θ ρ T t x v : ℝ) (hv : 0 ≤ v) (hθ : 0 ≤ θ) (htT : t ≤ T) : + Tendsto (fun ξ => hestonProfile u (fun w => hestonA r κ θ ξ ρ u (T - w)) + (fun w => hestonBv κ ξ ρ u (T - w)) t x v) (𝓝[≠] 0) + (𝓝 (mgf id + (gaussianReal (x + r * (T - t) - (vasicekIntegratedMean v θ κ (T - t)).toNNReal / 2) + (vasicekIntegratedMean v θ κ (T - t)).toNNReal) u)) := by + rw [mgf_gaussianReal_logSpot, Real.coe_toNNReal _ + (vasicekIntegratedMean_nonneg hκ hv hθ (sub_nonneg.mpr htT))] + exact tendsto_hestonProfile_smallVolOfVol hκ hu1 hu2 r θ ρ T t x v + +end MathFin.Heston diff --git a/LeanPool/MathFin/Models/StochVol/LSVLeverage.lean b/LeanPool/MathFin/Models/StochVol/LSVLeverage.lean new file mode 100644 index 0000000000..9c3512e63e --- /dev/null +++ b/LeanPool/MathFin/Models/StochVol/LSVLeverage.lean @@ -0,0 +1,521 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.ModelFree.BreedenLitzenberger +public import Mathlib.Algebra.Ring.IsFormallyReal + +/-! +# LSV leverage-posterior core + +A local-stochastic-volatility (LSV) model is calibrated to the local-volatility surface by the +condition `L²(t,K) · E[v_t | S_t = K] = σ_loc²(t,K)`: the leverage function `L` is pinned by the +posterior mean of the stochastic variance given the state (Gyöngy's mimicking theorem; the +particle calibration of Guyon and Henry-Labordère). We follow S. Bagaria, *Notes on Fixed Income +Derivative Pricing* (lecture notes), ch. 11, where this is eq. 11.1; the equation, example and +calculation numbers below (Thm 11.2, Ex. 11.1–11.2, Calc 11.3) are that chapter's. + +The conditioning step itself is Mathlib's: `E[v | σ(S)]` is a Borel function of the state by +`stronglyMeasurable_condExp` and the Doob–Dynkin lemma +`StronglyMeasurable.exists_eq_measurable_comp`, and `L²(S)` comes out of the conditional +expectation by `condExp_mul_of_stronglyMeasurable_left`. Those lemmas are not applied to an LSV +model in this file. This file proves the algebraic and analytic core behind the condition, with no +stochastic-process hypotheses: + +* the pinned product and its extremes (`lsv_pinned_product`, eq. 11.6): `m = 1` recovers + pure local vol, `m = σ_loc²` (with `σ_loc > 0`) switches the leverage off (Ex. 11.1); +* the coin-toss λ-dial family (§11.4 / Calc 11.3): branch variances `29/400 ∓ λ/20` keep + `E[v^λ]` pinned at `29/400` for every λ; at the λ = 0 endpoint, read as the constant + posterior `m = 29/400`, the squared leverage at `σ_loc = 1/4` is `25/29` (the exact square of + the chapter's "0.93"); +* the coin-toss posterior of Ex. 11.2 as exact inequalities and limits: ATM posterior on the + high branch `< 1/2`; ATM posterior variance `m(F)` below the unconditional mean; posterior + on the high branch → 1 in both wings (the log-density ratio is a downward parabola in + `ln(K/F)`); and nonconstancy of the posterior variance `m` on the positive strikes; +* the posterior read off option prices (`cointossPhi_eq_deriv_deriv_bsV`, + `cointossPostHi_eq_strike_convexity`, `cointossM_eq_strike_convexity`): by + Breeden–Litzenberger (`breedenLitzenberger`), each branch density is the second strike + derivative of that branch's Black–Scholes call price, so the Bayes weights and the posterior + variance are ratios of call-price convexities. + +## Scope + +* Not proved here: Thm 11.2's *iff* content, that the leverage-defined model reprices the + market (it needs Gyöngy's mimicking theorem with flow uniqueness, which + `GyongyMimicry.gyongy_mimicry_gated` takes as a hypothesis, weak existence on the + local-vol side, the Dupire surface formula on a non-Gaussian carrier, and the McKean–Vlasov + existence question, which is not settled in general); §11.3's grid and particle machinery; + every decimal figure of the chapter's tables (22.9%, 26.9%, 0.98, 1.09 → 0.71), since the + statements here are exact. Here `cointossM` and `cointossPostHi` are defined by their Bayes + formulas; that `cointossM ∘ S_T` is the conditional expectation `E[v | σ(S_T)]` on the + two-branch mixture, and `cointossPostHi ∘ S_T` the conditional probability of the high + branch, is proved in `Models/StochVol/LSVPosteriorConditionalExpectation.lean` + (`cointossM_comp_ae_eq_condExp`, `cointossPostHi_comp_ae_eq_condExp`). + +## Main definitions + +* `cointossVLo`, `cointossVHi`: the branch variances `29/400 ∓ λ/20` of the coin-toss example. +* `cointossPhi`: the branch density, the Black–Scholes lognormal terminal density with spot `F`, + zero rate and unit maturity at volatility `σ`, evaluated at the strike `K`. +* `cointossPostHi`: the posterior weight of the high branch at strike `K` under equal priors, + `φ_hi(K)/(φ_lo(K) + φ_hi(K))`. +* `cointossM`: the posterior mean of the variance at strike `K`, + `(v_lo φ_lo(K) + v_hi φ_hi(K))/(φ_lo(K) + φ_hi(K))`. + +## Main results + +* `lsv_pinned_product`: for a posterior variance `m > 0`, the leverage `σ_loc / √m` satisfies + `L² · m = σ_loc²`. +* `lsv_leverage_of_m_one`, `lsv_leverage_switches_off`: if `m = 1` the leverage is `σ_loc`; if + `σ_loc > 0` and `m = σ_loc²` the leverage is `1`. +* `cointoss_family_mean`: for every `λ`, the two branch variances average to `29/400`. +* `cointoss_endpoint_l0_pinned`, `cointoss_endpoint_l0_quarter`: at `λ = 0` the pinned product holds + with `m = 29/400`, and at `σ_loc = 1/4` the squared leverage is `25/29`. +* `cointoss_posterior_atm_lt_half`: at the money, for `σ_lo < σ_hi`, the posterior weight of the + high branch is below `1/2`. +* `cointossM_atm_lt_uncond`: at the money the posterior variance is below the unconditional mean + `(v_lo + v_hi)/2`. +* `cointoss_posterior_wing_limit_atTop`, `cointoss_posterior_wing_limit_atZero`: the posterior + weight of the high branch tends to `1` as the strike tends to `∞` and to `0⁺`. +* `cointossM_wing_limit_atTop`: the posterior variance tends to `v_hi` as `K → ∞`. +* `cointossM_nonconstant`: the posterior variance is not constant in the strike. +* `cointossPostHi_eq_strike_convexity`, `cointossM_eq_strike_convexity`: the posterior weight and + posterior variance are ratios of second strike derivatives of the branch call prices + `bsV K 0 σ F 1`. + +## References + +* [I. Gyöngy, *Mimicking the one-dimensional marginal distributions of processes having an Itô + differential*][Gyongy1986]. +* [J. Guyon and P. Henry-Labordère, *Being particular about calibration*][GuyonHenryLabordere2012]. +* [S. Bagaria, *Notes on Fixed Income Derivative Pricing*][BagariaFIDP], ch. 11. + +## Tags + +local stochastic volatility, leverage function, Gyöngy mimicking, particle calibration, +conditional variance, Dupire calibration, MSC 91G20, MSC 60J60, JEL G13 +-/ + +@[expose] public section + +namespace MathFin.LSV + +open MeasureTheory ProbabilityTheory Filter Topology + +/-! ## The pinned product and its extremes -/ + +/-- **The pinned product (eq. 11.6 shape), at one strike.** The leverage of an LSV model +is `L = σ_loc / √m`, where `m` is the posterior mean of the stochastic variance at the strike; +the defining product `L² · m = σ_loc²` is an identity as soon as `m > 0`. The λ = 0 +endpoint (`cointoss_endpoint_l0_pinned`) is this telescope at `m = 29/400`. -/ +theorem lsv_pinned_product (σ_loc m : ℝ) (hm : 0 < m) : + (σ_loc / Real.sqrt m) ^ 2 * m = σ_loc ^ 2 := by + rw [div_pow, Real.sq_sqrt hm.le, div_mul_cancel₀ _ hm.ne'] + +/-- **First extreme (Ex. 11.1): `m = 1` ⇒ `L = σ_loc`.** With no stochastic content at a +strike the leverage there is the local volatility itself — pure local vol. -/ +theorem lsv_leverage_of_m_one (σ_loc m : ℝ) (h : m = 1) : + σ_loc / Real.sqrt m = σ_loc := by + simp [h] + +/-- **Second extreme (Ex. 11.1): for `σ_loc > 0`, `m = σ_loc²` ⇒ `L = 1`.** When the stochastic +part already fits the surface, `E[v | S = K] = σ_loc²(K)` and the leverage "switches itself off". -/ +theorem lsv_leverage_switches_off (σ_loc m : ℝ) (hσ : 0 < σ_loc) (h : m = σ_loc ^ 2) : + σ_loc / Real.sqrt m = 1 := by + rw [h, Real.sqrt_sq hσ.le, div_self hσ.ne'] + +/-! ## The coin-toss λ-dial family (§11.4, Calc 11.3) -/ + +/-- The λ-dial branch variances of Calc 11.3, against a flat 25% local-volatility surface: a +low and a high branch, `v_lo(λ) = 29/400 − λ/20` and `v_hi(λ) = 29/400 + λ/20`. At `λ = 1` +these are the Ex. 11.2 coin toss `9/400 = 0.15²` and `49/400 = 0.35²`; at `λ = 0` the dial +collapses to the single deterministic variance `29/400 = (0.269…)²`. -/ +noncomputable def cointossVLo (lam : ℝ) : ℝ := 29 / 400 - lam / 20 + +/-- The high branch of the λ-dial (see `cointossVLo`). -/ +noncomputable def cointossVHi (lam : ℝ) : ℝ := 29 / 400 + lam / 20 + +/-- **λ-invariance of the branch mean:** for every λ, the two-branch average of the variance +is exactly `29/400`. The dial moves variance between the branches without moving the mean — +in the chapter's words, "λ changes the answer, does not change the calibration, and therefore +cannot be determined by it". Only the invariance of the mean is proved; calibration is not +modelled here. -/ +theorem cointoss_family_mean (lam : ℝ) : + (cointossVLo lam + cointossVHi lam) / 2 = 29 / 400 := by + unfold cointossVLo cointossVHi; ring + +/-- The low branch stays positive across the whole dial `λ ∈ [0, 1]` (at `λ = 1` it is +`9/400 > 0`). -/ +theorem cointossVLo_pos (lam : ℝ) (h1 : lam ≤ 1) : 0 < cointossVLo lam := by + unfold cointossVLo; linarith + +/-- The high branch is positive for every nonnegative λ (at `λ = 0` it is `29/400 > 0`). -/ +theorem cointossVHi_pos (lam : ℝ) (h0 : 0 ≤ lam) : 0 < cointossVHi lam := by + unfold cointossVHi; linarith + +/-- **The λ = 0 endpoint in ratio form (Calc 11.3):** the dial collapses to a single +deterministic variance `m ≡ E[v⁰] = 29/400`, so the squared leverage is the flat ratio +`σ_loc² / (29/400)`. The statement is the algebraic identity at `m = 29/400`; that the posterior +`cointossM` equals `29/400` at `λ = 0` is not stated. -/ +theorem cointoss_endpoint_l0_sq (σ_loc : ℝ) : + (σ_loc / Real.sqrt (29 / 400)) ^ 2 = σ_loc ^ 2 / (29 / 400) := by + rw [div_pow, Real.sq_sqrt (by norm_num : (0:ℝ) ≤ 29 / 400)] + +/-- The λ = 0 endpoint in pinned-product form: the constant posterior `29/400` telescopes +with the squared leverage to `σ_loc²`. -/ +theorem cointoss_endpoint_l0_pinned (σ_loc : ℝ) : + (σ_loc / Real.sqrt (29 / 400)) ^ 2 * (29 / 400) = σ_loc ^ 2 := + lsv_pinned_product σ_loc _ (by norm_num) + +/-- **The exact square of the chapter's flat "0.93":** at `σ_loc = 1/4` the λ = 0 squared +leverage is `L⁰² = 25/29` (Calc 11.3's `L⁰ ≈ 0.93` is the square root of this rational). -/ +theorem cointoss_endpoint_l0_quarter : + ((1:ℝ) / 4 / Real.sqrt (29 / 400)) ^ 2 = 25 / 29 := by + rw [cointoss_endpoint_l0_sq]; norm_num + +/-! ## The coin-toss posterior (Ex. 11.2) -/ + +/-- The branch density of the coin-toss example: the Black–Scholes lognormal terminal +density with spot `F`, zero rate, unit maturity and branch volatility `σ`, evaluated at +strike `K` — Ex. 11.2's `φ_c(K)` (`MathFin.lognormalTerminalPDF` at `S_0 = F, r = 0, +T = 1`; branch means the coin came up `σ = σ_lo` or `σ = σ_hi`). -/ +noncomputable def cointossPhi (F σ K : ℝ) : ℝ := + lognormalTerminalPDF F 0 σ 1 K + +/-- The branch density is strictly positive wherever `σ, K > 0` (the Gaussian tail is +positive and the Jacobian `K σ √T` is positive). -/ +theorem cointossPhi_pos {F σ K : ℝ} (hσ : 0 < σ) (hK : 0 < K) : + 0 < cointossPhi F σ K := by + unfold cointossPhi lognormalTerminalPDF + rw [Real.sqrt_one] + exact div_pos (gaussianPDFReal_pos 0 1 _ one_ne_zero) (by positivity) + +/-- At the money the `d₂` of a branch density collapses to `−σ/2` (`r = 0`, `T = 1`, +`K = S_0 = F`). -/ +theorem cointoss_bsd2_atm {F σ : ℝ} (hF : 0 < F) (hσ : 0 < σ) : + bsd2 F F 0 σ 1 = -σ / 2 := by + have h1 : Real.log (F / F) = 0 := by rw [div_self hF.ne', Real.log_one] + rw [bsd2_eq hσ one_pos, h1, Real.sqrt_one, mul_one, zero_add, zero_sub] + field_simp + +/-- The ATM branch density in product form (for `F, σ > 0`): the Gaussian normalization constant +times the Jacobian telescope to `exp(−σ²/8)`. (Auxiliary engine for the ATM comparisons; the +`√(2π)` is the normalization constant of `gaussianPDFReal 0 1`.) -/ +theorem cointossPhi_atm_prod {F σ : ℝ} (hF : 0 < F) (hσ : 0 < σ) : + cointossPhi F σ F * (F * σ) * Real.sqrt (2 * Real.pi) = + Real.exp (-(σ ^ 2 / 8)) := by + unfold cointossPhi lognormalTerminalPDF + rw [cointoss_bsd2_atm hF hσ, Real.sqrt_one] + simp only [gaussianPDFReal, sub_zero, NNReal.coe_one, mul_one] + have hFs : (F * σ : ℝ) ≠ 0 := mul_ne_zero hF.ne' hσ.ne' + have hS : Real.sqrt (2 * Real.pi) ≠ 0 := by positivity + rw [div_mul_cancel₀ _ hFs, mul_comm (Real.sqrt (2 * Real.pi))⁻¹, inv_mul_cancel_right₀ hS] + congr 1 + ring + +/-- **The ATM density ratio** — the engine of every ATM comparison that follows: for `F > 0` +and positive branch volatilities, `φ_lo(F)/φ_hi(F) = (σ_hi/σ_lo) · exp((σ_hi² − σ_lo²)/8)`. +For `σ_lo < σ_hi` this exceeds `1` (`cointossPhi_atm_lt`). -/ +theorem cointossPhi_ratio_atm {F σ_lo σ_hi : ℝ} (hF : 0 < F) (hlo : 0 < σ_lo) + (hσhi : 0 < σ_hi) : + cointossPhi F σ_lo F / cointossPhi F σ_hi F = + (σ_hi / σ_lo) * Real.exp ((σ_hi ^ 2 - σ_lo ^ 2) / 8) := by + have hEdiv : Real.exp (-(σ_lo ^ 2 / 8)) / Real.exp (-(σ_hi ^ 2 / 8)) = + Real.exp ((σ_hi ^ 2 - σ_lo ^ 2) / 8) := by + rw [← Real.exp_sub] + congr 1 + ring + rw [← hEdiv, ← cointossPhi_atm_prod hF hlo, ← cointossPhi_atm_prod hF hσhi] + field_simp + +/-- **At the money, the narrower (low-vol) branch is the denser branch:** `φ_hi(F) < φ_lo(F)` +— the two-line chapter fact `ln(σ_lo/σ_hi) < 0 < (σ_hi²−σ_lo²)/8`, in exact form. -/ +theorem cointossPhi_atm_lt {F σ_lo σ_hi : ℝ} (hF : 0 < F) (hlo : 0 < σ_lo) + (hhi : σ_lo < σ_hi) : + cointossPhi F σ_hi F < cointossPhi F σ_lo F := by + have hσhi : 0 < σ_hi := hlo.trans hhi + rw [← one_lt_div (cointossPhi_pos hσhi hF), cointossPhi_ratio_atm hF hlo hσhi] + refine one_lt_mul_of_le_of_lt ((one_lt_div hlo).2 hhi).le ?_ + rw [Real.one_lt_exp_iff] + have hs2 : σ_lo ^ 2 < σ_hi ^ 2 := by nlinarith + linarith + +/-- The posterior weight of the high branch at strike `K` under equal branch priors — +Ex. 11.2's Bayes ratio `P(hi | S_T = K) = φ_hi(K)/(φ_lo(K) + φ_hi(K))`. -/ +noncomputable def cointossPostHi (F σ_lo σ_hi K : ℝ) : ℝ := + cointossPhi F σ_hi K / (cointossPhi F σ_lo K + cointossPhi F σ_hi K) + +/-- **The ATM posterior on the high branch is below one half** (the strict inequality behind the +chapter's table entry `P(hi | S_T = F) = 0.30`; the decimal itself is not proved). +Engine: `cointossPhi_atm_lt` plus the positivity of both densities. -/ +theorem cointoss_posterior_atm_lt_half {F σ_lo σ_hi : ℝ} (hF : 0 < F) (hlo : 0 < σ_lo) + (hhi : σ_lo < σ_hi) : + cointossPostHi F σ_lo σ_hi F < 1 / 2 := by + have hden : 0 < cointossPhi F σ_lo F + cointossPhi F σ_hi F := + add_pos (cointossPhi_pos hlo hF) (cointossPhi_pos (hlo.trans hhi) hF) + unfold cointossPostHi + rw [div_lt_iff₀ hden] + linarith [cointossPhi_atm_lt hF hlo hhi] + +/-- The posterior mean of the variance at strike `K`, +`m(K) = (v_lo φ_lo(K) + v_hi φ_hi(K))/(φ_lo(K) + φ_hi(K))` — the input of eq. 11.1's +leverage `L = σ_loc/√m`. -/ +noncomputable def cointossM (F σ_lo σ_hi v_lo v_hi K : ℝ) : ℝ := + (v_lo * cointossPhi F σ_lo K + v_hi * cointossPhi F σ_hi K) / + (cointossPhi F σ_lo K + cointossPhi F σ_hi K) + +/-- **The ATM posterior variance sits below the unconditional mean:** for `F, σ_lo > 0`, +`σ_lo < σ_hi` and `v_lo < v_hi`, `m(F) < (v_lo + v_hi)/2`. For `σ_loc > 0` and `m(F) > 0` +this transfers to the leverage, `σ_loc/√m(F) > σ_loc/√((v_lo + v_hi)/2)`; that transfer is +not stated here. Engine: the pinned algebra `(v_hi − v_lo)(φ_lo(F) − φ_hi(F)) > 0`. -/ +theorem cointossM_atm_lt_uncond {F σ_lo σ_hi v_lo v_hi : ℝ} (hF : 0 < F) + (hlo : 0 < σ_lo) (hhi : σ_lo < σ_hi) (hvhi : v_lo < v_hi) : + cointossM F σ_lo σ_hi v_lo v_hi F < (v_lo + v_hi) / 2 := by + have hden : 0 < cointossPhi F σ_lo F + cointossPhi F σ_hi F := + add_pos (cointossPhi_pos hlo hF) (cointossPhi_pos (hlo.trans hhi) hF) + have halt := cointossPhi_atm_lt hF hlo hhi + unfold cointossM + rw [div_lt_div_iff₀ hden zero_lt_two] + nlinarith [mul_pos (sub_pos.mpr hvhi) (sub_pos.mpr halt)] + +/-- For `r = 0`, `T = 1`, `K > 0`: the branch `d₂` is `−(x + σ²/2)/σ` in the log-moneyness +variable `x = ln(K/F)`. (Auxiliary to the wing limits.) -/ +theorem cointoss_bsd2_log {F σ K : ℝ} (hF : 0 < F) (hσ : 0 < σ) (hK : 0 < K) : + bsd2 F K 0 σ 1 = (-Real.log (K / F) - σ ^ 2 / 2) / σ := by + have h1 : Real.log (F / K) = -Real.log (K / F) := by + rw [Real.log_div hF.ne' hK.ne', Real.log_div hK.ne' hF.ne'] + ring + rw [bsd2_eq hσ one_pos, h1, Real.sqrt_one, mul_one, zero_sub] + ring + +/-- **The log-density ratio is a quadratic in log-moneyness** — the engine of both wing +limits: `log(φ_lo/φ_hi) = b − a·(ln(K/F))²` with `a = (σ_hi² − σ_lo²)/(2σ_lo²σ_hi²)` and +intercept `b = ln(σ_hi/σ_lo) + (σ_hi² − σ_lo²)/8`, for `F, K > 0` and positive branch vols. +For `σ_lo < σ_hi`, `a > 0` (a downward parabola), so `|ln(K/F)| → ∞` drives `φ_lo/φ_hi` to +`0`, i.e. the posterior piles onto the wide branch. -/ +theorem cointossPhi_ratio_log {F σ_lo σ_hi K : ℝ} (hF : 0 < F) (hlo : 0 < σ_lo) + (hσhi : 0 < σ_hi) (hK : 0 < K) : + Real.log (cointossPhi F σ_lo K / cointossPhi F σ_hi K) = + (Real.log (σ_hi / σ_lo) + (σ_hi ^ 2 - σ_lo ^ 2) / 8) - + (σ_hi ^ 2 - σ_lo ^ 2) / (2 * σ_lo ^ 2 * σ_hi ^ 2) * (Real.log (K / F)) ^ 2 := by + -- the Gaussian ratio of the two branch densities + have hgr (d₁ d₂ : ℝ) : + gaussianPDFReal 0 1 d₁ / gaussianPDFReal 0 1 d₂ = Real.exp ((d₂ ^ 2 - d₁ ^ 2) / 2) := by + have hstep : gaussianPDFReal 0 1 d₁ / gaussianPDFReal 0 1 d₂ = + Real.exp (-(d₁ ^ 2 / 2)) / Real.exp (-(d₂ ^ 2 / 2)) := by + simp only [gaussianPDFReal, sub_zero] + push_cast + rw [mul_div_mul_left _ _ (by positivity : (Real.sqrt (2 * Real.pi * (1:ℝ)))⁻¹ ≠ 0)] + norm_num + simp only [neg_div] + rw [hstep, ← Real.exp_sub] + congr 1 + ring + -- the strike-ratio assembly (the `K` Jacobians cancel between the branches) + have hφratio : cointossPhi F σ_lo K / cointossPhi F σ_hi K = + (σ_hi / σ_lo) * Real.exp (((Real.log (K / F) + σ_hi ^ 2 / 2) ^ 2 / σ_hi ^ 2 + - (Real.log (K / F) + σ_lo ^ 2 / 2) ^ 2 / σ_lo ^ 2) / 2) := by + have hdiv (g₁ g₂ a b : ℝ) (ha : a ≠ 0) (hb : b ≠ 0) : + (g₁ / a) / (g₂ / b) = (g₁ / g₂) * (b / a) := by + field_simp + unfold cointossPhi lognormalTerminalPDF + rw [cointoss_bsd2_log hF hlo hK, cointoss_bsd2_log hF hσhi hK, Real.sqrt_one, mul_one, + mul_one, + hdiv _ _ _ _ (mul_ne_zero hK.ne' hlo.ne') (mul_ne_zero hK.ne' hσhi.ne'), hgr] + have hscalar : (K * σ_hi) / (K * σ_lo) = σ_hi / σ_lo := by + rw [mul_div_mul_left _ _ hK.ne'] + rw [hscalar, mul_comm (Real.exp _)] + congr 2 + ring + -- take the log of the assembled ratio + have hQ : (((Real.log (K / F) + σ_hi ^ 2 / 2) ^ 2 / σ_hi ^ 2 + - (Real.log (K / F) + σ_lo ^ 2 / 2) ^ 2 / σ_lo ^ 2) / 2) = + (σ_hi ^ 2 - σ_lo ^ 2) / 8 - + (σ_hi ^ 2 - σ_lo ^ 2) / (2 * σ_lo ^ 2 * σ_hi ^ 2) * (Real.log (K / F)) ^ 2 := by + have h1 : (σ_lo ^ 2 : ℝ) ≠ 0 := pow_ne_zero _ hlo.ne' + have h2 : (σ_hi ^ 2 : ℝ) ≠ 0 := pow_ne_zero _ hσhi.ne' + field_simp + ring + rw [hφratio, Real.log_mul (div_pos hσhi hlo).ne' (Real.exp_pos _).ne', Real.log_exp, hQ] + ring + +/-- The posterior weight rewrites as `1/(1 + φ_lo/φ_hi)` — the form the wing limits feed +into. -/ +theorem cointoss_posterior_eq {F σ_lo σ_hi K : ℝ} (hlo : 0 < σ_lo) (hσhi : 0 < σ_hi) + (hK : 0 < K) : + cointossPostHi F σ_lo σ_hi K = + 1 / (1 + cointossPhi F σ_lo K / cointossPhi F σ_hi K) := by + have hφlo : 0 < cointossPhi F σ_lo K := cointossPhi_pos hlo hK + have hφhi : 0 < cointossPhi F σ_hi K := cointossPhi_pos hσhi hK + unfold cointossPostHi + field_simp + ring + +/-- The shared engine of both wing limits: whenever the squared log-moneyness diverges to +`+∞` along a filter on which strikes are eventually positive, the posterior weight on the +wide branch tends to `1`. (Private; the two public forms below instantiate `l`.) -/ +private theorem cointoss_posterior_limit_aux {F σ_lo σ_hi : ℝ} (hF : 0 < F) (hlo : 0 < σ_lo) + (hhi : σ_lo < σ_hi) {l : Filter ℝ} + (hu2 : Tendsto (fun K : ℝ ↦ (Real.log (K / F)) ^ 2) l atTop) + (hpos : ∀ᶠ K in l, (0:ℝ) < K) : + Tendsto (cointossPostHi F σ_lo σ_hi) l (𝓝 1) := by + have hσhi : 0 < σ_hi := hlo.trans hhi + set a : ℝ := (σ_hi ^ 2 - σ_lo ^ 2) / (2 * σ_lo ^ 2 * σ_hi ^ 2) + set b : ℝ := Real.log (σ_hi / σ_lo) + (σ_hi ^ 2 - σ_lo ^ 2) / 8 + have hA : 0 < a := div_pos (by nlinarith) (by positivity) + -- the linear tail `b - a · t` drives `atBot` + have hlin : Tendsto (fun t : ℝ ↦ b - a * t) atTop atBot := by + simpa only [sub_eq_add_neg, neg_mul, id_eq] using + tendsto_atBot_add_const_left _ b (tendsto_id.const_mul_atTop_of_neg (neg_lt_zero.2 hA)) + -- so the log-ratio tends to atBot, and exponentiating gives the density ratio → 0 + have hlogR : Tendsto (fun K : ℝ ↦ + Real.log (cointossPhi F σ_lo K / cointossPhi F σ_hi K)) l atBot := + (hlin.comp hu2).congr' (by + filter_upwards [hpos] with K hK + exact (cointossPhi_ratio_log hF hlo hσhi hK).symm) + have hR : Tendsto (fun K : ℝ ↦ cointossPhi F σ_lo K / cointossPhi F σ_hi K) l (𝓝 0) := by + refine (Real.tendsto_exp_atBot.comp hlogR).congr' ?_ + filter_upwards [hpos] with K hK + exact Real.exp_log (div_pos (cointossPhi_pos hlo hK) (cointossPhi_pos hσhi hK)) + -- and `1/(1 + ·)` is continuous at `0` with value `1` + have hcont : Tendsto (fun t : ℝ ↦ 1 / (1 + t)) (𝓝 0) (𝓝 1) := by + have h : Tendsto (fun t : ℝ ↦ 1 / (1 + t)) (𝓝 0) (𝓝 ((1:ℝ) / ((1:ℝ) + 0))) := + (tendsto_const_nhds (x := (1:ℝ))).div + ((tendsto_const_nhds (x := (1:ℝ))).add tendsto_id) (by norm_num) + simpa using h + exact (hcont.comp hR).congr' (by + filter_upwards [hpos] with K hK + exact (cointoss_posterior_eq hlo hσhi hK).symm) + +/-- **Upper wing limit (Ex. 11.2's table, `K → ∞`):** the posterior weight on the wide +branch tends to `1` — the qualitative content behind the chapter's `0.96` at `K = 160` +(the finite-strike decimal itself is not proved). The log-density ratio is a downward +parabola in `ln(K/F)`, so the branch densities separate exponentially in the wing. -/ +theorem cointoss_posterior_wing_limit_atTop {F σ_lo σ_hi : ℝ} (hF : 0 < F) (hlo : 0 < σ_lo) + (hhi : σ_lo < σ_hi) : + Tendsto (cointossPostHi F σ_lo σ_hi) atTop (𝓝 1) := by + have hu : Tendsto (fun K : ℝ ↦ Real.log (K / F)) atTop atTop := + Real.tendsto_log_atTop.comp (tendsto_id.atTop_div_const hF) + exact cointoss_posterior_limit_aux hF hlo hhi ((tendsto_pow_atTop two_ne_zero).comp hu) + (eventually_gt_atTop 0) + +/-- **Lower wing limit (Ex. 11.2's table, `K → 0⁺`):** the posterior weight on the wide +branch tends to `1` in the lower wing as well — the qualitative content behind the +chapter's `0.98` at `K = 60` (the decimal itself is not proved). Same parabola, read +at `ln(K/F) → −∞`. -/ +theorem cointoss_posterior_wing_limit_atZero {F σ_lo σ_hi : ℝ} (hF : 0 < F) (hlo : 0 < σ_lo) + (hhi : σ_lo < σ_hi) : + Tendsto (cointossPostHi F σ_lo σ_hi) (𝓝[>] 0) (𝓝 1) := by + have hx : Tendsto (fun K : ℝ ↦ Real.log (K / F)) (𝓝[>] 0) atBot := by + refine (tendsto_atBot_add_const_right _ (-Real.log F) Real.tendsto_log_nhdsGT_zero).congr' ?_ + filter_upwards [self_mem_nhdsWithin] with K (hK : 0 < K) + rw [Real.log_div hK.ne' hF.ne', sub_eq_add_neg] + have hsq : Tendsto (fun x : ℝ ↦ x ^ 2) atBot atTop := + ((tendsto_pow_atTop two_ne_zero).comp tendsto_neg_atBot_atTop).congr fun x ↦ neg_sq x + exact cointoss_posterior_limit_aux hF hlo hhi (hsq.comp hx) self_mem_nhdsWithin + +/-- For positive strikes the posterior mean is the flat branch mix +`m(K) = v_lo + (v_hi − v_lo) · P(hi | K)` — the leverage-relevant reading of the posterior +weight. -/ +theorem cointossM_eq_of_pos {F σ_lo σ_hi v_lo v_hi K : ℝ} (hlo : 0 < σ_lo) (hσhi : 0 < σ_hi) + (hK : 0 < K) : + cointossM F σ_lo σ_hi v_lo v_hi K = + v_lo + (v_hi - v_lo) * cointossPostHi F σ_lo σ_hi K := by + have hφlo : 0 < cointossPhi F σ_lo K := cointossPhi_pos hlo hK + have hφhi : 0 < cointossPhi F σ_hi K := cointossPhi_pos hσhi hK + unfold cointossM cointossPostHi + field_simp + ring + +/-- **The posterior variance's upper-wing limit:** `m(K) → v_hi` as `K → ∞` — the posterior +mean of the variance converges to the wide branch in the upper wing (the analogous lower-wing +statement, `m(K) → v_hi` as `K → 0⁺`, would follow the same way from +`cointoss_posterior_wing_limit_atZero`; it is not stated here). -/ +theorem cointossM_wing_limit_atTop {F σ_lo σ_hi v_lo v_hi : ℝ} (hF : 0 < F) (hlo : 0 < σ_lo) + (hhi : σ_lo < σ_hi) : + Tendsto (fun K : ℝ ↦ cointossM F σ_lo σ_hi v_lo v_hi K) atTop (𝓝 v_hi) := by + have h := ((cointoss_posterior_wing_limit_atTop hF hlo hhi).const_mul (v_hi - v_lo)).const_add + v_lo + rw [mul_one, add_sub_cancel] at h + refine h.congr' ?_ + filter_upwards [eventually_gt_atTop (0:ℝ)] with K hK + exact (cointossM_eq_of_pos hlo (hlo.trans hhi) hK).symm + +/-- At `K = 0` both branch densities are `0` (`x / 0 = 0`), so `cointossM` is `0` there. -/ +theorem cointossM_zero (F σ_lo σ_hi v_lo v_hi : ℝ) : + cointossM F σ_lo σ_hi v_lo v_hi 0 = 0 := by + simp [cointossM, cointossPhi, lognormalTerminalPDF] + +/-- **The posterior variance is not constant** for `F, σ_lo > 0`, `σ_lo < σ_hi` and +`v_lo < v_hi` (Ex. 11.2's punchline: the posterior `m` is a +genuine function of the strike; for a flat `σ_loc > 0` and `m > 0` the leverage `σ_loc/√m` +is then not flat either, a transfer not stated here). +If `m` were constant on the (economically meaningful) positive strikes it would equal its own +upper-wing limit `v_hi`; but at the money `m(F) < (v_lo + v_hi)/2 < v_hi`. The quantifier is +restricted to `K > 0`: `cointossM F σ_lo σ_hi v_lo v_hi 0 = 0` by the `x / 0 = 0` convention +(`cointossM_zero`), so an unrestricted `¬ ∃ c, ∀ K, … = c` would hold even for a posterior +that is constant on `(0, ∞)`, and would not capture the intended content. -/ +theorem cointossM_nonconstant {F σ_lo σ_hi v_lo v_hi : ℝ} (hF : 0 < F) + (hlo : 0 < σ_lo) (hhi : σ_lo < σ_hi) (hvhi : v_lo < v_hi) : + ¬ ∃ c : ℝ, ∀ K : ℝ, 0 < K → cointossM F σ_lo σ_hi v_lo v_hi K = c := by + rintro ⟨c, hc⟩ + have h : v_hi = c := tendsto_nhds_unique (cointossM_wing_limit_atTop hF hlo hhi) + (tendsto_const_nhds.congr' (by + filter_upwards [eventually_gt_atTop (0:ℝ)] with K hK using (hc K hK).symm)) + linarith [cointossM_atm_lt_uncond hF hlo hhi hvhi, hc F hF] + +/-! ## The posterior from call prices (Breeden–Litzenberger) + +Each branch density `φ_c` is the lognormal density that Breeden–Litzenberger reads off the +second strike derivative of the branch's call price: `φ_c(K) = ∂²_K C_c(K)` with +`C_c(K) = bsV K 0 σ_c F 1` (zero rate, unit maturity, so the discount factor is `1`). The Bayes +posterior of Ex. 11.2 is therefore a ratio of call-price convexities, the quantities a +calibration observes. -/ + +/-- **A branch density is a call-price convexity.** For `F, σ, K > 0`, +`φ_σ(K) = ∂²_K bsV(K, 0, σ, F, 1)`: Breeden–Litzenberger at zero rate and unit maturity. -/ +theorem cointossPhi_eq_deriv_deriv_bsV {F σ K : ℝ} (hF : 0 < F) (hσ : 0 < σ) (hK : 0 < K) : + cointossPhi F σ K = deriv (deriv fun k ↦ bsV k 0 σ F 1) K := by + rw [(breedenLitzenberger hF hσ hK one_pos).deriv] + simp [cointossPhi] + +/-- **The posterior weight of the high branch from call prices.** For `F, K > 0` and positive +branch volatilities, `P(hi | S_T = K) = C_hi''(K) / (C_lo''(K) + C_hi''(K))`, where +`C_c(K) = bsV K 0 σ_c F 1`. -/ +theorem cointossPostHi_eq_strike_convexity {F σ_lo σ_hi K : ℝ} (hF : 0 < F) (hlo : 0 < σ_lo) + (hhi : 0 < σ_hi) (hK : 0 < K) : + cointossPostHi F σ_lo σ_hi K = + deriv (deriv fun k ↦ bsV k 0 σ_hi F 1) K / + (deriv (deriv fun k ↦ bsV k 0 σ_lo F 1) K + deriv (deriv fun k ↦ bsV k 0 σ_hi F 1) K) := by + rw [cointossPostHi, cointossPhi_eq_deriv_deriv_bsV hF hlo hK, + cointossPhi_eq_deriv_deriv_bsV hF hhi hK] + +/-- **The posterior variance from call prices.** For `F, K > 0` and positive branch +volatilities, `m(K) = (v_lo·C_lo''(K) + v_hi·C_hi''(K)) / (C_lo''(K) + C_hi''(K))`. -/ +theorem cointossM_eq_strike_convexity {F σ_lo σ_hi v_lo v_hi K : ℝ} (hF : 0 < F) + (hlo : 0 < σ_lo) (hhi : 0 < σ_hi) (hK : 0 < K) : + cointossM F σ_lo σ_hi v_lo v_hi K = + (v_lo * deriv (deriv fun k ↦ bsV k 0 σ_lo F 1) K + + v_hi * deriv (deriv fun k ↦ bsV k 0 σ_hi F 1) K) / + (deriv (deriv fun k ↦ bsV k 0 σ_lo F 1) K + deriv (deriv fun k ↦ bsV k 0 σ_hi F 1) K) := by + rw [cointossM, cointossPhi_eq_deriv_deriv_bsV hF hlo hK, + cointossPhi_eq_deriv_deriv_bsV hF hhi hK] + +/-! ## The posterior as a conditional expectation + +On the two-branch mixture space `ℝ ⊕ ℝ` (a standard normal draw on the low or the high branch, +each with probability `1/2`), with terminal price `S_T = F·exp(σ_c z − σ_c²/2)` on branch `c` and +branch variance `v`, the posterior of this file is the conditional expectation: +`cointossM F σ_lo σ_hi v_lo v_hi ∘ S_T =ᵐ E[v | σ(S_T)]`. That theorem, and the matching +statement for `cointossPostHi` as the conditional probability of the high branch, is proved in +`Models/StochVol/LSVPosteriorConditionalExpectation.lean`, which pushes each branch's normal law +forward to the density `cointossPhi F σ_c` on `(0, ∞)` with the library's +`jumpDiffusionIncrementLaw_zero_map_mul_exp` and applies Mathlib's +`ae_eq_condExp_of_forall_setIntegral_eq`. -/ + +end MathFin.LSV diff --git a/LeanPool/MathFin/Models/StochVol/SABRFlochKennedyLimits.lean b/LeanPool/MathFin/Models/StochVol/SABRFlochKennedyLimits.lean new file mode 100644 index 0000000000..4543b5c742 --- /dev/null +++ b/LeanPool/MathFin/Models/StochVol/SABRFlochKennedyLimits.lean @@ -0,0 +1,176 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.StochVol.SABRImpliedVol + +/-! +# The β → 1 and ν → 0 limits of the Le Floc'h–Kennedy SABR building blocks + +Transcribed from QuantLib's `ql/termstructures/volatility/sabr.cpp` +(`SabrFlochKennedyVolatility`), the implementation of Le Floc'h & Kennedy, "Explicit SABR +Calibration through Simple Expansions" (SSRN 2467231, 2014). The SABR implied volatility +(model `dF = α̂ F^β dW₁`, `dα̂ = ν α̂ dW₂`, `dW₁ dW₂ = ρ dt`) is written in terms of two +building blocks of the strike `k`, given the forward `F`: + +* the normalizing transform, in closed form `y(k) = -(F^(1-β) - k^(1-β)) / (1-β)` + (as printed; it is the integral `∫_F^k x^(-β) dx`, an identity not proved here); +* the distance, in closed form `Dint = (1/ν) · log((√(1 + 2ρνy/α + (νy/α)²) - ρ - νy/α) / (1-ρ))` + (as printed; it is the integral `∫_k^F dx / D(x)` with + `D(x) = √(α² + 2αρν y(x) + ν² y(x)²) · x^β`, an identity not proved here); + +with leading-order vol `ω₀(k) = log(F/k) / Dint(k)`. Both closed forms are removable +singularities on admissible SABR parameters: `y` is `0/0` at `β = 1` (the lognormal SABR) and +`Dint` is `(1/ν)·log 1 = ∞ · 0` at `ν = 0` (no vol-of-vol). This file proves the limits that +fill them: + +* `tendsto_sabrFKY_beta_one` — `y(k) → -log(F/k)` as `β → 1` (`F, k > 0`); +* `tendsto_sabrFKDint_nu_zero` — `Dint → -y/α` as `ν → 0` (`ρ ≠ 1`, every `α`, `y`; at + `α = 0` this holds only through Lean's `x/0 = 0` junk value, not as a fact about the + closed form, which is undefined there); +* `tendsto_sabrFKOmega0_nu_zero` — hence `ω₀(k) → -α log(F/k) / y` as `ν → 0` (`y ≠ 0`), for + any real `y`, in particular for `y = sabrFKY F k β`. + +The `ν → 0` limit reuses Hagan's `x(z)` (`sabrX`, `Models/StochVol/SABRImpliedVol.lean`): +`Dint = ν⁻¹ · x(-νy/α)` (`sabrFKDint_eq_sabrX`), so the limit is the slope `x'(0) = 1` +(`hasDerivAt_sabrX_zero`) times the inner derivative `-y/α`. The transform `y` itself has no +Hagan counterpart (Hagan's `z` uses the geometric-mean approximation `(Fk)^((1-β)/2) log(F/k)` +in place of the exact integral `y`). + +What is *not* formalized: the full Le Floc'h–Kennedy vol (the `ω₀` correction terms in +`log ω₀`, `D(F)`, `D(k)` and the `(k^β - F^β)/(k - F)` factor) and its limit; the derivation of +the expansion from the SABR dynamics; and how well it approximates the true SABR implied vol. +The definitions below are the closed forms as printed, so at `β = 1` / `ν = 0` they take Lean's +junk values (`x / 0 = 0`); the theorems are about the limits, not those values. + +## Main definitions + +* `sabrFKY`: the normalizing transform `y(k) = −(F^{1−β} − k^{1−β})/(1−β)`, as printed. +* `sabrFKDint`: the distance `Dint` as a function of `y`, as printed. +* `sabrFKOmega0`: the leading-order volatility `ω₀ = log(F/k)/Dint`. + +## Main results + +* `tendsto_sabrFKY_beta_one`: for `F, k > 0`, `y(k) → −log(F/k)` as `β → 1` with `β ≠ 1`. +* `sabrFKDint_eq_sabrX`: `Dint = ν⁻¹ · x(−νy/α)`, with `x` Hagan's function `sabrX`. +* `tendsto_sabrFKDint_nu_zero`: for `ρ ≠ 1`, `Dint → −y/α` as `ν → 0` with `ν ≠ 0`. +* `tendsto_sabrFKOmega0_nu_zero`: for `α ≠ 0`, `ρ ≠ 1` and `y ≠ 0`, `ω₀ → −α·log(F/k)/y` as + `ν → 0` with `ν ≠ 0`. + +## References + +* [Hagan et al., *Managing smile risk*][HaganKumarLesniewskiWoodward2002] +* [F. Le Floc'h and G. Kennedy, *Explicit SABR calibration through simple + expansions*][LeFlochKennedy2014] +* [The QuantLib contributors, *QuantLib*][QuantLib], ql/termstructures/volatility/sabr.cpp + (SabrFlochKennedyVolatility) + +## Tags + +SABR model, Le Floc'h–Kennedy, implied volatility expansion, lognormal SABR, vol-of-vol limit, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Filter Topology + +/-- **Le Floc'h–Kennedy's normalizing transform**, the closed form as printed, +`y(k) = -(F^(1-β) - k^(1-β)) / (1-β)`; the identification with `∫_F^k x^(-β) dx` (`β ≠ 1`) is +not proved here. At `β = 1` the closed form is `0/0`; `tendsto_sabrFKY_beta_one` gives its limit +`-log(F/k)`. -/ +noncomputable def sabrFKY (F k β : ℝ) : ℝ := -(F ^ (1 - β) - k ^ (1 - β)) / (1 - β) + +/-- **Le Floc'h–Kennedy's distance** `Dint` as a function of `y = y(k)`, the closed form as +printed: `(1/ν) · log((√(1 + 2ρνy/α + (νy/α)²) - ρ - νy/α) / (1-ρ))`; the identification with +`∫_k^F dx / D(x)` is not proved here. At `ν = 0` the closed form is `(1/0) · log 1`; +`tendsto_sabrFKDint_nu_zero` gives its limit `-y/α`. -/ +noncomputable def sabrFKDint (α ρ ν y : ℝ) : ℝ := + 1 / ν * Real.log ((Real.sqrt (1 + 2 * ρ * ν / α * y + (ν / α * y) ^ 2) - ρ - ν / α * y) + / (1 - ρ)) + +/-- **The leading-order Le Floc'h–Kennedy vol** `ω₀ = log(F/k) / Dint`, with `Dint` evaluated +at `y`. -/ +noncomputable def sabrFKOmega0 (F k α ρ ν y : ℝ) : ℝ := Real.log (F / k) / sabrFKDint α ρ ν y + +/-- **`y(k) → -log(F/k)` as `β → 1`, `β ≠ 1`** (`F, k > 0`): the `0/0` in the transform at the +lognormal SABR `β = 1` is removable. With `ε = 1 - β`, `y = (k^ε - F^ε)/ε`, the difference +quotient at `ε = 0` of `ε ↦ k^ε - F^ε`, whose derivative there is `log k - log F`. -/ +theorem tendsto_sabrFKY_beta_one {F k : ℝ} (hF : 0 < F) (hk : 0 < k) : + Tendsto (fun β ↦ sabrFKY F k β) (𝓝[≠] 1) (𝓝 (-Real.log (F / k))) := by + have hg : HasDerivAt (fun ε : ℝ ↦ k ^ ε - F ^ ε) (Real.log k - Real.log F) 0 := by + have h1 : HasDerivAt (fun ε : ℝ ↦ k ^ ε) (k ^ (0 : ℝ) * Real.log k) 0 := + (Real.hasStrictDerivAt_const_rpow hk 0).hasDerivAt + have h2 : HasDerivAt (fun ε : ℝ ↦ F ^ ε) (F ^ (0 : ℝ) * Real.log F) 0 := + (Real.hasStrictDerivAt_const_rpow hF 0).hasDerivAt + have h := h1.sub h2 + simp only [Real.rpow_zero, one_mul] at h + exact h + have hslope := hasDerivAt_iff_tendsto_slope_zero.mp hg + have hmap : Tendsto (fun β : ℝ ↦ 1 - β) (𝓝[≠] 1) (𝓝[≠] 0) := by + rw [tendsto_nhdsWithin_iff] + refine ⟨?_, ?_⟩ + · have : Tendsto (fun β : ℝ ↦ 1 - β) (𝓝 1) (𝓝 (1 - 1)) := + tendsto_const_nhds.sub tendsto_id + simpa using this.mono_left nhdsWithin_le_nhds + · filter_upwards [self_mem_nhdsWithin] with β hβ + exact sub_ne_zero.mpr (Ne.symm hβ) + rw [Real.log_div hF.ne' hk.ne', neg_sub] + refine (hslope.comp hmap).congr fun β ↦ ?_ + simp only [Function.comp_apply, zero_add, Real.rpow_zero, sub_self, sub_zero, smul_eq_mul, + sabrFKY] + ring + +/-- **`Dint` is `ν⁻¹ · x(-νy/α)`** for Hagan's `x(z)` (`sabrX`): the two closed forms share the +same `log((√· ± z - ρ)/(1-ρ))` function, at the argument `z = -νy/α`. -/ +theorem sabrFKDint_eq_sabrX (α ρ ν y : ℝ) : + sabrFKDint α ρ ν y = ν⁻¹ * sabrX ρ (-(y / α) * ν) := by + have hA : 1 + 2 * ρ * ν / α * y + (ν / α * y) ^ 2 + = 1 - 2 * ρ * (-(y / α) * ν) + (-(y / α) * ν) ^ 2 := by ring + unfold sabrFKDint sabrX + rw [one_div, hA] + congr 3 + ring + +/-- **`Dint → -y/α` as `ν → 0`, `ν ≠ 0`** (`ρ ≠ 1`, every `α`, `y`; at `α = 0` this holds +only through Lean's `x/0 = 0` junk value, not as a fact about the closed form, which is +undefined there): the `∞ · 0` in the closed form at zero vol-of-vol is removable. Via +`sabrFKDint_eq_sabrX`, `Dint` is the difference quotient at `ν = 0` of `ν ↦ x(-(y/α)ν)`, +whose derivative there is `x'(0) · (-y/α) = -y/α` (`hasDerivAt_sabrX_zero`). This is the limit +of the closed form as printed; that the closed form is `∫_k^F dx / D(x)` (so that the limit is +the integral with the `ν = 0` coefficient `D(x) = α x^β`) is not proved here. -/ +theorem tendsto_sabrFKDint_nu_zero {α ρ : ℝ} (hρ : ρ ≠ 1) (y : ℝ) : + Tendsto (fun ν ↦ sabrFKDint α ρ ν y) (𝓝[≠] 0) (𝓝 (-y / α)) := by + have hinner : HasDerivAt (fun ν : ℝ ↦ -(y / α) * ν) (-(y / α)) 0 := by + simpa using (hasDerivAt_id (0 : ℝ)).const_mul (-(y / α)) + have hg := HasDerivAt.comp_of_eq (h₂ := sabrX ρ) (0 : ℝ) (hasDerivAt_sabrX_zero hρ) hinner + (by simp) + have h0 : sabrX ρ 0 = 0 := by + have h1ρ : (1 : ℝ) - ρ ≠ 0 := sub_ne_zero.mpr (Ne.symm hρ) + simp [sabrX, h1ρ] + have hslope := hasDerivAt_iff_tendsto_slope_zero.mp hg + rw [one_mul] at hslope + rw [neg_div] + refine hslope.congr fun ν ↦ ?_ + simp [sabrFKDint_eq_sabrX, h0] + +/-- **The leading-order vol at zero vol-of-vol**: `ω₀ → -α log(F/k) / y` as `ν → 0`, `ν ≠ 0` +(`α ≠ 0`, `ρ ≠ 1`, and any real `y ≠ 0`; `y` is a free argument of `sabrFKOmega0`, not tied to +`F`, `k` or `β`). Taking `y = sabrFKY F k β` gives the limit for the printed transform. -/ +theorem tendsto_sabrFKOmega0_nu_zero {F k α ρ y : ℝ} (hα : α ≠ 0) (hρ : ρ ≠ 1) (hy : y ≠ 0) : + Tendsto (fun ν ↦ sabrFKOmega0 F k α ρ ν y) (𝓝[≠] 0) (𝓝 (-α * Real.log (F / k) / y)) := by + have h := tendsto_const_nhds (x := Real.log (F / k)).div (tendsto_sabrFKDint_nu_zero hρ y) + (div_ne_zero (neg_ne_zero.mpr hy) hα) + have e : -α * Real.log (F / k) / y = Real.log (F / k) / (-y / α) := by + field_simp + rw [e] + exact h.congr fun ν ↦ rfl + +end MathFin diff --git a/LeanPool/MathFin/Models/StochVol/SABRImpliedVol.lean b/LeanPool/MathFin/Models/StochVol/SABRImpliedVol.lean new file mode 100644 index 0000000000..29c050a506 --- /dev/null +++ b/LeanPool/MathFin/Models/StochVol/SABRImpliedVol.lean @@ -0,0 +1,311 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.BlackScholes.ImpliedVolatility +public import LeanPool.MathFin.Models.Forwards.Black76 + +/-! +# The SABR lognormal implied-volatility asymptotic approximation + +Hagan, Kumar, Lesniewski & Woodward, "Managing Smile Risk," *Wilmott Magazine*, +September 2002, pp. 84-108. Under the SABR stochastic-volatility model +`dF̂ = α̂F̂^β dW₁`, `dα̂ = να̂ dW₂`, `dW₁ dW₂ = ρ dt` (their eqs. 2.15a-c), singular +perturbation gives the price of European options via Black's formula with an +*explicit, closed-form asymptotic approximation* for the implied volatility +`σ_B(K, f)` as a function of today's forward `f` and strike `K` (eqs. 2.17a-c): + +`σ_B(K,f) = α / [(fK)^((1-β)/2) · (1 + (1-β)²/24 · log²(f/K) + (1-β)⁴/1920 · log⁴(f/K) + ⋯)] + · (z / x(z)) · (1 + [(1-β)²/24 · α²/(fK)^(1-β) + + ρβνα/4/(fK)^((1-β)/2) + (2-3ρ²)/24 · ν²] t_ex + ⋯)` + +where `z = (ν/α)(fK)^((1-β)/2) log(f/K)` and +`x(z) = log((√(1-2ρz+z²) + z - ρ)/(1-ρ))` (eqs. 2.17b-c). + +**This is a closed-form asymptotic approximation, not an exact price** — the +paper derives it via a singular-perturbation (small vol-of-vol, short-maturity) +expansion and explicitly omits higher-order `⋯` terms (stated to be "much, +much smaller" than the displayed terms, but nonzero). Neither that derivation nor +any error bound against the true SABR implied volatility is formalized here: the +two-factor SDE's transition density and its short-time (heat-kernel / +geodesic-distance) asymptotics do not exist in this repo or in +Mathlib/BrownianMotion. The rigorous form of the expansion (an error bound against the +SABR model's implied volatility) is not formalized. What is proved concerns the *printed* +formulas +(eq. 2.17a-c with the `⋯` dropped, and eq. 2.18): + +* At `K = f` the general formula is `0/0` in its `z / x(z)` factor (`z = 0`, + `x(0) = 0`), and the paper says it "reduces to" eq. 2.18. We prove this as a + limit: `sabrImpliedVol K f ⋯ → sabrATMVol f ⋯` as `K → f`, `K ≠ f`. The + removable singularity is resolved by `x'(0) = 1` (`hasDerivAt_sabrX_zero`), so + `z / x(z) → 1`. +* The *backbone law* (section 3): along the leading-order ATM curve + `f ↦ α / f^(1-β)`, `d log σ / d log f = β - 1`, stated as the derivative of + `v ↦ log (sabrBackbone (e^v))` in `v = log f`. + +## Main definitions + +* `sabrZ`, `sabrX` — Hagan's `z` and `x(z)` (eqs. 2.17b, 2.17c). +* `sabrImpliedVol` — the general implied vol `σ_B(K, f)` (eq. 2.17a, `⋯` dropped). +* `sabrATMVol` — the at-the-money implied vol (eq. 2.18). +* `sabrBackbone` — the leading-order ATM vol `α / f^(1-β)` ("the backbone" in the + paper's section 3 terminology). + +## Main results + +* `tendsto_sabrImpliedVol_atm` — eq. 2.17a tends to eq. 2.18 as `K → f` + (for `f > 0`, `α ≠ 0`, `ν ≠ 0`, `ρ ≠ 1`, any `β`, `t_ex`). +* `hasDerivAt_log_sabrBackbone` — `d/df log (α / f^(1-β)) = (β - 1) / f` (`f, α > 0`). +* `hasDerivAt_log_sabrBackbone_exp` — the backbone law in log-log form: + `d/dv log (α / (e^v)^(1-β)) = β - 1` (`α > 0`). +* `sabrBackbone_pos` — the backbone is positive for `α, f > 0`. +* `sabrATMVol_bsV_gt_backbone_bsV` — whenever eq. 2.18's bracketed correction, + scaled by `t_ex`, is positive, the ATM Black call (the statement's zero-rate, + spot = strike = `f` instantiation, `0 < T`) priced at `sabrATMVol` is + strictly above the same call priced at the backbone (via + `bsV_strictMonoOn_sigma`, `Models/BlackScholes/ImpliedVolatility.lean`). +* `sabrATMVol_black_futures_price` — the ATM option priced, as the paper prescribes, by + Black's formula at `σ_ATM = sabrATMVol`: under the Black-76 hypothesis at that vol, + the discounted expected call payoff is `e^{−rT} · f · (2Φ(σ_ATM √T / 2) − 1)`. This + is Black's formula evaluated at eq. 2.18's vol; it does not show that the SABR model + itself produces this price. + +## References + +* [F. Black, *The pricing of commodity contracts*][Black1976] +* [Hagan et al., *Managing smile risk*][HaganKumarLesniewskiWoodward2002], eq. 2.18; eqs. 2.17a-c + and 2.18; section 3 and eq. 2.18 + +## Tags + +SABR model, Hagan formula, implied volatility asymptotics, managing smile risk, backbone, +stochastic volatility, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Filter MeasureTheory Topology + +/-- **The SABR "backbone"**: the leading-order at-the-money implied volatility +`α / f^(1-β)` (the dominant factor in Hagan-Kumar-Lesniewski-Woodward eq. 2.18; +called the *backbone* in their section 3, the curve traced by ATM vol as the +forward `f` varies). -/ +noncomputable def sabrBackbone (f α β : ℝ) : ℝ := α / f ^ (1 - β) + +/-- **The SABR at-the-money implied volatility** (Hagan-Kumar-Lesniewski-Woodward, +*Managing Smile Risk*, Wilmott Magazine 2002, eq. 2.18): + +`σ_ATM = α/f^(1-β) · {1 + [(1-β)²/24 · α²/f^(2-2β) + ρβαν/4/f^(1-β) + (2-3ρ²)/24 · ν²] t_ex + ⋯}` + +the `K = f` specialization of the general formula (eq. 2.17a), where the +`z/x(z)` factor's removable singularity at `z = 0` is already resolved. This is +the asymptotic truncation as printed in the paper (the omitted `⋯` terms are +higher order in the perturbation expansion, stated by the authors to be much +smaller than the displayed correction). -/ +noncomputable def sabrATMVol (f α β ρ ν tex : ℝ) : ℝ := + sabrBackbone f α β * + (1 + ((1 - β) ^ 2 / 24 * (α ^ 2 / f ^ (2 - 2 * β)) + + ρ * β * α * ν / 4 / f ^ (1 - β) + + (2 - 3 * ρ ^ 2) / 24 * ν ^ 2) * tex) + +/-- **The backbone is positive** for `α, f > 0`: `α / f^(1-β) > 0`. -/ +theorem sabrBackbone_pos {f α : ℝ} (β : ℝ) (hf : 0 < f) (hα : 0 < α) : + 0 < sabrBackbone f α β := + div_pos hα (Real.rpow_pos_of_pos hf _) + +/-- **A positive perturbation correction raises the ATM price**: whenever eq. +2.18's bracketed stochastic-vol correction `(1-β)²/24·α²/f^(2-2β) + ρβαν/4/f^(1-β) ++ (2-3ρ²)/24·ν²`, scaled by `t_ex`, is positive, the full ATM vol `sabrATMVol` +strictly exceeds the bare backbone `sabrBackbone` — and, by `bsV_strictMonoOn_sigma` +(`Models/BlackScholes/ImpliedVolatility.lean`, the strict monotonicity of the Black call +price in its vol input), the ATM Black call priced at `sabrATMVol` is strictly more +expensive than the same option priced at the backbone alone. The call compared is the +statement's `bsV f 0 σ f T` instantiation: spot and strike both the forward `f`, rate +`r = 0`, maturity `T` with `0 < T` (`hT`) — the same zero-rate, spot = strike = `f` +call `sabrATMVol_black_futures_price` below spells out in full. The positivity of +the correction is a hypothesis (`hbracket`), not proved; the conclusion is the strict +monotonicity of the Black call in its vol, applied to `backbone < backbone · (1 + c)`. -/ +theorem sabrATMVol_bsV_gt_backbone_bsV {f α β ρ ν tex T : ℝ} (hf : 0 < f) (hα : 0 < α) + (hT : 0 < T) + (hbracket : 0 < ((1 - β) ^ 2 / 24 * (α ^ 2 / f ^ (2 - 2 * β)) + + ρ * β * α * ν / 4 / f ^ (1 - β) + (2 - 3 * ρ ^ 2) / 24 * ν ^ 2) * tex) : + bsV f 0 (sabrBackbone f α β) f T < bsV f 0 (sabrATMVol f α β ρ ν tex) f T := by + have hpos := sabrBackbone_pos β hf hα + have hlt : sabrBackbone f α β < sabrATMVol f α β ρ ν tex := by + unfold sabrATMVol + nlinarith [mul_pos hpos hbracket] + exact bsV_strictMonoOn_sigma hf hT hf hpos (hpos.trans hlt) hlt + +/-- **The ATM price as Black-76 at `sabrATMVol`**: Hagan et al. price European options by +Black's formula with the implied vol `σ_B`; at the money that vol is eq. 2.18. The vol's own +`t_ex` argument is the option's time to expiry, so it is instantiated at the same `T` the +Black-76 price is computed for (not left as an independent free variable — eq. 2.18's ATM vol +is specifically the vol *for an option expiring at `t_ex`*, priced at that same expiry). Under +the Black-76 hypothesis at `σ_ATM = sabrATMVol f α β ρ ν T` (forward `f`, strike `f`, zero +drift), the discounted expected call payoff is `e^{−rT} · f · (2Φ(σ_ATM √T / 2) − 1)` +(`black_futures_formula_atm`). This is Black's formula at eq. 2.18's vol, not a +statement that the SABR dynamics produce this price. -/ +theorem sabrATMVol_black_futures_price {Ω : Type*} {mΩ : MeasurableSpace Ω} + {Q : Measure Ω} [IsProbabilityMeasure Q] {f α β ρ ν T : ℝ} {Z : Ω → ℝ} + (h : BSCallHyp Q f f 0 (sabrATMVol f α β ρ ν T) T Z) (r : ℝ) : + ∫ ω, Real.exp (-r * T) * max (bsTerminal f 0 (sabrATMVol f α β ρ ν T) T (Z ω) - f) 0 ∂Q + = Real.exp (-r * T) * f * (2 * Phi (sabrATMVol f α β ρ ν T * Real.sqrt T / 2) - 1) := + black_futures_formula_atm h r + +/-! ### The general formula (eq. 2.17) and its `K → f` limit -/ + +/-- **Hagan's `x(z)`** (Hagan-Kumar-Lesniewski-Woodward eq. 2.17c): +`x(z) = log((√(1 - 2ρz + z²) + z - ρ) / (1 - ρ))`. -/ +noncomputable def sabrX (ρ z : ℝ) : ℝ := + Real.log ((Real.sqrt (1 - 2 * ρ * z + z ^ 2) + z - ρ) / (1 - ρ)) + +/-- **Hagan's `z`** (eq. 2.17b): `z = (ν/α) (fK)^((1-β)/2) log(f/K)`. -/ +noncomputable def sabrZ (K f α β ν : ℝ) : ℝ := + ν / α * (f * K) ^ ((1 - β) / 2) * Real.log (f / K) + +/-- **The SABR implied volatility `σ_B(K, f)`** (Hagan-Kumar-Lesniewski-Woodward eq. 2.17a), +the printed asymptotic formula with its `⋯` terms dropped: + +`α / [(fK)^((1-β)/2) (1 + (1-β)²/24 log²(f/K) + (1-β)⁴/1920 log⁴(f/K))] · (z / x(z)) + · (1 + [(1-β)²/24 · α²/(fK)^(1-β) + ρβαν/4/(fK)^((1-β)/2) + (2-3ρ²)/24 · ν²] t_ex)`. + +At `K = f` the factor `z / x(z)` is `0 / 0` (Lean's `0 / 0 = 0` makes the literal value +`0` there); `tendsto_sabrImpliedVol_atm` shows the formula tends to `sabrATMVol` as +`K → f`. -/ +noncomputable def sabrImpliedVol (K f α β ρ ν tex : ℝ) : ℝ := + α / ((f * K) ^ ((1 - β) / 2) * + (1 + (1 - β) ^ 2 / 24 * Real.log (f / K) ^ 2 + + (1 - β) ^ 4 / 1920 * Real.log (f / K) ^ 4)) * + (sabrZ K f α β ν / sabrX ρ (sabrZ K f α β ν)) * + (1 + ((1 - β) ^ 2 / 24 * (α ^ 2 / (f * K) ^ (1 - β)) + + ρ * β * α * ν / 4 / (f * K) ^ ((1 - β) / 2) + + (2 - 3 * ρ ^ 2) / 24 * ν ^ 2) * tex) + +/-- **`x(z)` has slope `1` at `z = 0`** (`ρ ≠ 1`). With `x(0) = 0`, this is what makes +`z = 0` a removable singularity of `z / x(z)`. -/ +theorem hasDerivAt_sabrX_zero {ρ : ℝ} (hρ : ρ ≠ 1) : HasDerivAt (sabrX ρ) 1 0 := by + have h1ρ : (1 : ℝ) - ρ ≠ 0 := sub_ne_zero.mpr (Ne.symm hρ) + have hq : HasDerivAt (fun z : ℝ ↦ 1 - 2 * ρ * z + z ^ 2) (-(2 * ρ)) 0 := + ((((hasDerivAt_id' (0 : ℝ)).const_mul (2 * ρ)).const_sub 1).add + (hasDerivAt_pow 2 (0 : ℝ))).congr_deriv (by norm_num) + have hs := hq.sqrt (by norm_num) + have hg := ((hs.add (hasDerivAt_id' (0 : ℝ))).sub_const ρ).div_const (1 - ρ) + have hl := hg.log (by norm_num [h1ρ]) + unfold sabrX + convert hl using 1 + simp only [Pi.add_apply] + norm_num + field_simp + ring + +/-- **`z / x(z) → 1` as `z → 0`, `z ≠ 0`** (`ρ ≠ 1`): the removable singularity of +eq. 2.17a's `z / x(z)` factor, from `x(0) = 0` and `x'(0) = 1`. -/ +theorem tendsto_div_sabrX {ρ : ℝ} (hρ : ρ ≠ 1) : + Tendsto (fun z ↦ z / sabrX ρ z) (𝓝[≠] 0) (𝓝 1) := by + have h := (hasDerivAt_iff_tendsto_slope_zero.mp (hasDerivAt_sabrX_zero hρ)).inv₀ one_ne_zero + have h0 : sabrX ρ 0 = 0 := by + have h1ρ : (1 : ℝ) - ρ ≠ 0 := sub_ne_zero.mpr (Ne.symm hρ) + simp [sabrX, h1ρ] + simpa [h0, div_eq_mul_inv, mul_comm] using h + +/-- **`z → 0` through nonzero values as `K → f`, `K ≠ f`** (`f > 0`, `α ≠ 0`, `ν ≠ 0`): +`z(K)` is continuous at `K = f` with `z(f) = 0`, and `z(K) ≠ 0` for `K > 0`, `K ≠ f`, +since `log(f/K) ≠ 0` there. -/ +theorem tendsto_sabrZ {f α β ν : ℝ} (hf : 0 < f) (hα : α ≠ 0) (hν : ν ≠ 0) : + Tendsto (fun K ↦ sabrZ K f α β ν) (𝓝[≠] f) (𝓝[≠] 0) := by + have hcont : ContinuousAt (fun K ↦ sabrZ K f α β ν) f := by + unfold sabrZ + have hff : f * f ≠ 0 := (mul_pos hf hf).ne' + have hf0 : f ≠ 0 := hf.ne' + have hdiv : f / f ≠ 0 := div_ne_zero hf0 hf0 + have hr : f * f ≠ 0 ∨ 0 ≤ (1 - β) / 2 := Or.inl hff + fun_prop (disch := assumption) + have hval : sabrZ f f α β ν = 0 := by simp [sabrZ, hf.ne'] + rw [tendsto_nhdsWithin_iff] + refine ⟨hval ▸ hcont.tendsto.mono_left nhdsWithin_le_nhds, ?_⟩ + have hpos : ∀ᶠ K in 𝓝[≠] f, 0 < K := nhdsWithin_le_nhds (Ioi_mem_nhds hf) + filter_upwards [hpos, self_mem_nhdsWithin] with K hK hKf + have hfK : f / K ≠ 1 := fun h ↦ hKf ((div_eq_one_iff_eq hK.ne').mp h).symm + simp only [Set.mem_compl_iff, Set.mem_singleton_iff, sabrZ] + exact mul_ne_zero (mul_ne_zero (div_ne_zero hν hα) (Real.rpow_pos_of_pos (mul_pos hf hK) _).ne') + (Real.log_ne_zero_of_pos_of_ne_one (div_pos hf hK) hfK) + +/-- The factors of eq. 2.17a other than `z / x(z)` are continuous in `K` at `K = f` +(`f > 0`). -/ +theorem sabrImpliedVol_rest_continuousAt {f α β ρ ν tex : ℝ} (hf : 0 < f) : + ContinuousAt (fun K ↦ α / ((f * K) ^ ((1 - β) / 2) * + (1 + (1 - β) ^ 2 / 24 * Real.log (f / K) ^ 2 + + (1 - β) ^ 4 / 1920 * Real.log (f / K) ^ 4)) * + (1 + ((1 - β) ^ 2 / 24 * (α ^ 2 / (f * K) ^ (1 - β)) + + ρ * β * α * ν / 4 / (f * K) ^ ((1 - β) / 2) + + (2 - 3 * ρ ^ 2) / 24 * ν ^ 2) * tex)) f := by + have hff : f * f ≠ 0 := (mul_pos hf hf).ne' + have hf0 : f ≠ 0 := hf.ne' + have hdiv : f / f ≠ 0 := div_ne_zero hf0 hf0 + have hr : f * f ≠ 0 ∨ 0 ≤ (1 - β) / 2 := Or.inl hff + have hr' : f * f ≠ 0 ∨ 0 ≤ 1 - β := Or.inl hff + have h1 : (f * f) ^ ((1 - β) / 2) ≠ 0 := (Real.rpow_pos_of_pos (mul_pos hf hf) _).ne' + have h2 : (f * f) ^ (1 - β) ≠ 0 := (Real.rpow_pos_of_pos (mul_pos hf hf) _).ne' + have h3 : (f * f) ^ ((1 - β) / 2) * (1 + (1 - β) ^ 2 / 24 * Real.log (f / f) ^ 2 + + (1 - β) ^ 4 / 1920 * Real.log (f / f) ^ 4) ≠ 0 := by simpa [hf.ne'] using h1 + fun_prop (disch := assumption) + +/-- **The general SABR formula tends to the ATM formula as `K → f`** +(Hagan-Kumar-Lesniewski-Woodward: eq. 2.17a "reduces to" eq. 2.18 at `K = f`): for +`f > 0`, `α ≠ 0`, `ν ≠ 0`, `ρ ≠ 1` and every `β`, `t_ex`, `σ_B(K, f) → σ_ATM(f)` as +`K → f` with `K ≠ f`. At `K = f` itself the printed formula is `0 / 0` in its `z / x(z)` +factor, so the limit, not evaluation, is the content. This concerns the two printed +truncations only; it says nothing about how well either approximates the true SABR +implied volatility. -/ +theorem tendsto_sabrImpliedVol_atm {f α β ρ ν tex : ℝ} (hf : 0 < f) (hα : α ≠ 0) (hν : ν ≠ 0) + (hρ : ρ ≠ 1) : + Tendsto (fun K ↦ sabrImpliedVol K f α β ρ ν tex) (𝓝[≠] f) + (𝓝 (sabrATMVol f α β ρ ν tex)) := by + have hR := (sabrImpliedVol_rest_continuousAt (α := α) (β := β) (ρ := ρ) (ν := ν) (tex := tex) + hf).tendsto.mono_left (nhdsWithin_le_nhds (s := {f}ᶜ)) + have hZX := (tendsto_div_sabrX hρ).comp (tendsto_sabrZ (β := β) hf hα hν) + have hhalf : (f * f) ^ ((1 - β) / 2) = f ^ (1 - β) := by + rw [Real.mul_rpow hf.le hf.le, ← Real.rpow_add hf]; ring_nf + have hfull : (f * f) ^ (1 - β) = f ^ (2 - 2 * β) := by + rw [Real.mul_rpow hf.le hf.le, ← Real.rpow_add hf]; ring_nf + convert hR.mul hZX using 1 + · funext K + simp only [sabrImpliedVol, Function.comp_apply] + ring + · simp only [sabrATMVol, sabrBackbone, hhalf, hfull, div_self hf.ne', Real.log_one] + congr 1 + ring + +/-! ### The backbone law -/ + +/-- Along the leading-order ATM curve `σ(f) = α / f^(1-β)`, `d log σ / df = (β - 1) / f`, +for `f > 0`, `α > 0`. The log-log form is `hasDerivAt_log_sabrBackbone_exp`. -/ +theorem hasDerivAt_log_sabrBackbone {f α : ℝ} (β : ℝ) (hf : 0 < f) (hα : 0 < α) : + HasDerivAt (fun x ↦ Real.log (sabrBackbone x α β)) ((β - 1) / f) f := by + have hev : (fun x ↦ Real.log α - (1 - β) * Real.log x) =ᶠ[𝓝 f] + fun x ↦ Real.log (sabrBackbone x α β) := by + filter_upwards [Ioi_mem_nhds hf] with x hx + rw [sabrBackbone, Real.log_div hα.ne' (Real.rpow_pos_of_pos hx _).ne', Real.log_rpow hx] + have hd := ((Real.hasDerivAt_log hf.ne').const_mul (1 - β)).const_sub (Real.log α) + refine (hd.congr_of_eventuallyEq hev.symm).congr_deriv ?_ + field_simp + ring + +/-- **The SABR backbone law** (Hagan-Kumar-Lesniewski-Woodward section 3): along the +leading-order ATM curve `σ(f) = α / f^(1-β)`, `d log σ / d log f = β - 1`, i.e. the map +`v ↦ log σ(e^v)` has derivative `β - 1` at every `v` (`β = 1`: flat; `β = 0`: `σ ∝ 1/f`). +Holds for `α > 0`. -/ +theorem hasDerivAt_log_sabrBackbone_exp (β : ℝ) {α : ℝ} (hα : 0 < α) (v : ℝ) : + HasDerivAt (fun w ↦ Real.log (sabrBackbone (Real.exp w) α β)) (β - 1) v := by + have h := (hasDerivAt_log_sabrBackbone β (Real.exp_pos v) hα).comp v (Real.hasDerivAt_exp v) + rw [div_mul_cancel₀ _ (Real.exp_pos v).ne'] at h + exact h + +end MathFin diff --git a/LeanPool/MathFin/Pricing/ContinuousMarket.lean b/LeanPool/MathFin/Pricing/ContinuousMarket.lean new file mode 100644 index 0000000000..e2f3daf357 --- /dev/null +++ b/LeanPool/MathFin/Pricing/ContinuousMarket.lean @@ -0,0 +1,298 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.FTAP.FTAP +public import LeanPool.MathFin.Probability.Martingales.MartingaleSetIntegral + +/-! +# Continuous-time market vocabulary: `IsEMM`, simple strategies, no-arbitrage + +A **model-agnostic** frame for the continuous-time first fundamental theorem of asset +pricing (FTAP), parametric over a finite-dimensional real inner-product-space-valued +discounted price process `S : ℝ≥0 → Ω → F`. The Black–Scholes model (`ContinuousFTAP.lean`) +instantiates it at `F = ℝ`; a multi-asset model would instantiate at `F = Fin n → ℝ`. + +* `IsEMM 𝓕 P S T Q` (`EquivMartingaleMeasure.lean`, one notion for every time index) at time + `ℝ≥0`: `Q ≈ P` (mutual absolute continuity) and `S` is a `Q`-martingale w.r.t. the filtration + `𝓕` on `{t ≤ T}`, i.e. the process stopped at `T` is a `Q`-martingale. `IsEMM.sampled` takes it + to time `ℕ` along a schedule. It is what an equivalent measure obtained by a density change on + `𝓕_T` can be: the Girsanov/Esscher + measure makes the discounted Black–Scholes price a martingale on `[0, T]` and no further + (`bs_discounted_isEMM`). A martingale on all of `ℝ≥0` is an EMM at every horizon. +* `SimpleStrategy 𝓕 F` — a piecewise-constant, predictable, bounded trading strategy: + finitely many trading dates `time : Fin (N+1) → ℝ≥0` and `𝓕`-measurable bounded holdings + `hold : Fin N → Ω → F` between consecutive dates. +* `SimpleStrategy.gains` — the discounted terminal gains of a simple strategy against `S`. +* `NoArbitrageSimple 𝓕 P S T` — no simple strategy trading up to `T` has gains that are `P`-a.s. + nonnegative and strictly positive on a `P`-non-null set. +* `martingale_stopped_of_setIntegral_eq` — the way an `IsEMM` is built: adaptedness, integrability + and the set-integral martingale identity on `[0, T]` give the stopped martingale. +* `SimpleStrategy.schedule`, `SimpleStrategy.toDiscrete` — the strategy's trading dates as a + monotone schedule `ℕ → ℝ≥0`, and its holdings as a discrete predictable strategy for the price + sampled along it; `SimpleStrategy.gains_eq_martingaleTransform` says the gains are the + martingale transform of the sampled price by it. +* `IsEMM.sampled` — a continuous-time EMM, sampled along a monotone schedule inside `[0, T]`, is a + discrete-time `MathFin.IsEMM`. +* `isEMM_noArbitrageSimple` — the forward theorem: `IsEMM.sampled` along the strategy's schedule, + then the discrete forward theorem `MathFin.IsEMM.noArbitrage` (vector-valued, `FTAP.lean`). + +## Scope: meaning-1 (operational) vs. meaning-2 (Delbaen–Schachermayer) FTAP + +This file builds **meaning 1**: an EMM for a *given* process, restricted to the honest, +economically transparent class of *simple* (piecewise-constant) strategies. It deliberately +does **not** build meaning 2, the Delbaen–Schachermayer theorem (`NFLVR ↔ ∃ EMM` for a +general locally-bounded semimartingale, admissible strategies over a continuum of trading +times, and the general stochastic integral `∫ φ dS`). Absent by design: + +* general **admissible** strategies (not just piecewise-constant) and the general stochastic + integral `∫ φ dS` against a semimartingale; +* **NFLVR** (no free lunch with vanishing risk) and its distinction from plain no-arbitrage; +* the **converse** direction `NoArbitrageSimple 𝓕 P S T → ∃ Q, IsEMM 𝓕 P S T Q`, and closedness + of the set of claims super-replicable from zero wealth (the Kreps–Yan / Hahn–Banach core DS + needs). + +`IsEMM` here is stated *on a process* `S`, exactly the object Delbaen–Schachermayer's theorem +would produce — so this frame is a strict sub-object of the DS one, and extending it to +meaning 2 is additive (new strategy class + new theorem), not a rewrite. + +One such extension already exists. `Pricing/MarketCompleteness` states replication, +superreplication duality and uniqueness of the pricing measure over the **Itô-integrable +predictable** integrands rather than `SimpleStrategy`. That widening is forced by the +mathematics, not chosen: the hedge martingale representation returns is a general predictable +process, and a general `L²` claim is not the terminal value of any piecewise-constant holding, +so a completeness statement over `SimpleStrategy` would have no witnesses. `SimpleStrategy` +remains the right class *here*, where the whole point is that the forward no-arbitrage +conclusion needs no stochastic integration at all — a finite sum of predictable increments. The +two classes coexist; neither file changes the other, and `IsEMM` is shared. + +## Main definitions + +* `SimpleStrategy`: finitely many trading dates `time 0 ≤ ⋯ ≤ time N` with bounded holdings + `hold i` over `(time i, time i+1]`, each strongly measurable for `𝓕 (time i)`. +* `SimpleStrategy.gains`: the terminal gains `∑ᵢ ⟪hold i, S (time (i+1)) − S (time i)⟫` of a + simple strategy against a price process `S`. +* `NoArbitrageSimple`: no simple strategy trading up to `T` has `P`-a.s. nonnegative gains that + are positive on a `P`-non-null set. +* `sampledFiltration`: the `ℕ`-filtration `n ↦ 𝓕 (t n)` obtained by sampling a filtration along a + monotone schedule `t`. +* `SimpleStrategy.schedule`, `SimpleStrategy.toDiscrete`: a strategy's trading dates as a + schedule, and the strategy read as a discrete holding process. + +## Main results + +* `martingale_stopped_of_setIntegral_eq`: a process adapted and `Q`-integrable on `{t ≤ T}` that + satisfies the set-integral martingale identity there is a martingale once stopped at `T`. +* `martingale_comp_monotone`: a `Q`-martingale sampled along a monotone schedule is a discrete + `Q`-martingale for the sampled filtration. +* `SimpleStrategy.gains_eq_martingaleTransform`: the gains of a simple strategy are the discrete + martingale transform of the sampled price by `toDiscrete`. +* `IsEMM.sampled`: a continuous-time `IsEMM`, sampled along a monotone schedule, is a + discrete-time `IsEMM`. +* `isEMM_noArbitrageSimple`: if `IsEMM 𝓕 P S T Q` holds, there is no simple-strategy arbitrage + up to `T` (the forward direction only). + +## References + +* [Delbaen and Schachermayer][DelbaenSchachermayer] +* [H. Föllmer and A. Schied, *Stochastic Finance: An Introduction in Discrete Time*][FollmerSchied], + §5.2 +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], Ch 5 + +## Tags + +equivalent martingale measure, no arbitrage, simple strategy, fundamental theorem of asset pricing, +self-financing, JEL G13, MSC 91G20, MSC 60G44 +-/ + +@[expose] public section + +namespace MathFin.ContinuousMarket + +open MeasureTheory ProbabilityTheory +open scoped NNReal InnerProductSpace + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + {𝓕 : Filtration ℝ≥0 mΩ} + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [FiniteDimensional ℝ F] + +/-- **The way an EMM's martingale is built.** A process that is `𝓕`-adapted and `Q`-integrable on +`{t ≤ T}` and satisfies the set-integral martingale identity there is a martingale once stopped at +`T`: past the horizon the stopped process is frozen, and `S T` is `𝓕 T ⊆ 𝓕 s`-measurable. -/ +theorem martingale_stopped_of_setIntegral_eq {Q : Measure Ω} [IsFiniteMeasure Q] + {S : ℝ≥0 → Ω → F} {T : ℝ≥0} (hadapt : ∀ t ≤ T, StronglyMeasurable[𝓕 t] (S t)) + (hint : ∀ t ≤ T, Integrable (S t) Q) + (hset : ∀ ⦃s t : ℝ≥0⦄, s ≤ t → t ≤ T → ∀ ⦃A : Set Ω⦄, MeasurableSet[𝓕 s] A → + ∫ ω in A, S t ω ∂Q = ∫ ω in A, S s ω ∂Q) : + Martingale (fun t ↦ S (min t T)) 𝓕 Q := by + refine martingale_iff_setIntegral_eq.2 + ⟨fun s ↦ (hadapt _ (min_le_right _ _)).mono (𝓕.mono (min_le_left _ _)), + fun s ↦ hint _ (min_le_right _ _), fun s t hst A hA ↦ ?_⟩ + by_cases hsT : s ≤ T + · rw [min_eq_left hsT] + exact (hset (le_min hst hsT) (min_le_right _ _) hA).symm + · rw [min_eq_right (not_le.mp hsT).le, min_eq_right ((not_le.mp hsT).le.trans hst)] + +/-- A **simple strategy**: finitely many trading dates `time 0 ≤ time 1 ≤ ⋯ ≤ time N`, with +piecewise-constant, `𝓕`-predictable, bounded holdings `hold i` held over `(time i, time i+1]`. +Does not depend on any measure — it is a purely path-space/filtration object. -/ +structure SimpleStrategy (𝓕 : Filtration ℝ≥0 mΩ) (F : Type*) + [NormedAddCommGroup F] [InnerProductSpace ℝ F] where + /-- The number of trading intervals. -/ + N : ℕ + /-- The `N + 1` trading dates `time 0 ≤ time 1 ≤ ⋯ ≤ time N`. -/ + time : Fin (N + 1) → ℝ≥0 + /-- The trading dates are nondecreasing. -/ + mono : Monotone time + /-- The holding `hold i` carried over the `i`-th interval `(time i, time i+1]`. -/ + hold : Fin N → Ω → F + /-- Predictability: each holding is `𝓕`-strongly-measurable at the start of its interval. -/ + meas : ∀ i : Fin N, StronglyMeasurable[𝓕 (time i.castSucc)] (hold i) + /-- The holdings are uniformly bounded (in `ω` and `i`). -/ + bdd : ∃ K : ℝ, ∀ (i : Fin N) ω, ‖hold i ω‖ ≤ K + +/-- The **discounted terminal gains** of a simple strategy `ψ` against the price process `S`: +`∑ᵢ ⟪hold i, S(time i+1) − S(time i)⟫`. -/ +noncomputable def SimpleStrategy.gains (ψ : SimpleStrategy 𝓕 F) + (S : ℝ≥0 → Ω → F) (ω : Ω) : ℝ := + ∑ i : Fin ψ.N, ⟪ψ.hold i ω, S (ψ.time i.succ) ω - S (ψ.time i.castSucc) ω⟫_ℝ + +/-- **No simple-strategy arbitrage up to `T`**: no simple strategy trading on `[0, T]` (its last +date is `≤ T`) has gains against `S` that are `P`-a.s. nonnegative and strictly positive on a +`P`-non-null set. -/ +def NoArbitrageSimple (𝓕 : Filtration ℝ≥0 mΩ) (P : Measure Ω) (S : ℝ≥0 → Ω → F) (T : ℝ≥0) : + Prop := + ∀ ψ : SimpleStrategy 𝓕 F, ψ.time (Fin.last ψ.N) ≤ T → (0 ≤ᵐ[P] fun ω ↦ ψ.gains S ω) → + P {ω | 0 < ψ.gains S ω} = 0 + +/-- The discrete `ℕ`-filtration `n ↦ 𝓕 (t n)` obtained by **sampling** a continuous-time +filtration `𝓕` along a monotone schedule `t : ℕ → ℝ≥0`. -/ +def sampledFiltration (𝓕 : Filtration ℝ≥0 mΩ) {t : ℕ → ℝ≥0} (ht : Monotone t) : + Filtration ℕ mΩ where + seq n := 𝓕 (t n) + mono' _ _ hij := 𝓕.mono (ht hij) + le' n := 𝓕.le (t n) + +omit [FiniteDimensional ℝ F] in +/-- **A `Q`-martingale sampled along a monotone schedule is a discrete `Q`-martingale.** +Sampling `S` at the increasing times `t 0 ≤ t 1 ≤ ⋯` gives a martingale w.r.t. the sampled +filtration `sampledFiltration 𝓕 ht`: adaptedness and the tower property both restrict along +`t`. A general, standalone structural lemma (the discrete-time trace of a continuous-time +martingale), benchmarked as `gir-martingale-reindex`. `IsEMM.sampled` is its counterpart for a +martingale stopped at the horizon, and is what `isEMM_noArbitrageSimple` uses. -/ +theorem martingale_comp_monotone {Q : Measure Ω} {S : ℝ≥0 → Ω → F} + (hS : Martingale S 𝓕 Q) {t : ℕ → ℝ≥0} (ht : Monotone t) : + Martingale (fun n ↦ S (t n)) (sampledFiltration 𝓕 ht) Q := + ⟨fun n ↦ hS.1 (t n), fun i j hij ↦ hS.2 (t i) (t j) (ht hij)⟩ + +namespace SimpleStrategy + +variable (ψ : SimpleStrategy 𝓕 F) + +/-- The **sampling schedule** of a simple strategy: its trading dates `time 0 ≤ ⋯ ≤ time N`, +held at the last one. -/ +def schedule (n : ℕ) : ℝ≥0 := ψ.time ⟨min n ψ.N, Nat.lt_succ_of_le (min_le_right _ _)⟩ + +omit [FiniteDimensional ℝ F] in +theorem monotone_schedule : Monotone ψ.schedule := fun _ _ hab ↦ + ψ.mono (Fin.mk_le_mk.mpr (min_le_min_right _ hab)) + +omit [FiniteDimensional ℝ F] in +/-- A strategy trading up to `T` has its whole schedule inside `[0, T]`. -/ +theorem schedule_le {T : ℝ≥0} (hψT : ψ.time (Fin.last ψ.N) ≤ T) (n : ℕ) : ψ.schedule n ≤ T := + (ψ.mono (Fin.le_last _)).trans hψT + +omit [FiniteDimensional ℝ F] in +theorem schedule_castSucc (i : Fin ψ.N) : ψ.schedule i = ψ.time i.castSucc := + congrArg ψ.time (Fin.ext (min_eq_left i.2.le)) + +omit [FiniteDimensional ℝ F] in +theorem schedule_succ (i : Fin ψ.N) : ψ.schedule (i + 1) = ψ.time i.succ := + congrArg ψ.time (Fin.ext (min_eq_left i.2)) + +/-- The simple strategy as a **discrete** one: the holding in force over the `n`-th step of the +schedule, `0` outside the trading window. -/ +def toDiscrete : ℕ → Ω → F := fun n ω ↦ + if hn : 0 < n ∧ n ≤ ψ.N then ψ.hold ⟨n - 1, by omega⟩ ω else 0 + +omit [FiniteDimensional ℝ F] in +theorem toDiscrete_succ (i : Fin ψ.N) : ψ.toDiscrete (i + 1) = ψ.hold i := by + funext ω + simp only [toDiscrete] + rw [dite_eq_left ⟨by omega, i.2⟩] + rfl + +omit [FiniteDimensional ℝ F] in +/-- The discrete strategy is predictable for the filtration sampled along the schedule. -/ +theorem toDiscrete_predictable : + ∀ t < ψ.N, StronglyMeasurable[sampledFiltration 𝓕 ψ.monotone_schedule t] + (ψ.toDiscrete (t + 1)) := fun n hn ↦ by + rw [show n + 1 = ((⟨n, hn⟩ : Fin ψ.N) : ℕ) + 1 from rfl, toDiscrete_succ] + change StronglyMeasurable[𝓕 (ψ.schedule n)] _ + rw [schedule_castSucc ψ ⟨n, hn⟩] + exact ψ.meas ⟨n, hn⟩ + +omit [FiniteDimensional ℝ F] in +/-- The discrete strategy is bounded. -/ +theorem toDiscrete_bdd : ∃ K : ℝ, ∀ n ≤ ψ.N, ∀ ω, ‖ψ.toDiscrete n ω‖ ≤ K := by + obtain ⟨K, hK⟩ := ψ.bdd + refine ⟨max K 0, fun n _ ω ↦ ?_⟩ + simp only [toDiscrete] + split_ifs + · exact (hK _ ω).trans (le_max_left _ _) + · simp + +omit [FiniteDimensional ℝ F] in +/-- **The gains of a simple strategy are the martingale transform**, by its discrete holdings, of +the price sampled along its schedule. -/ +theorem gains_eq_martingaleTransform (S : ℝ≥0 → Ω → F) : + ψ.gains S = martingaleTransform ψ.toDiscrete (fun n ↦ S (ψ.schedule n)) ψ.N := by + funext ω + unfold martingaleTransform SimpleStrategy.gains + rw [← Fin.sum_univ_eq_sum_range + (fun k ↦ ⟪ψ.toDiscrete (k + 1) ω, S (ψ.schedule (k + 1)) ω - S (ψ.schedule k) ω⟫_ℝ) ψ.N] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [toDiscrete_succ, schedule_succ, schedule_castSucc] + +end SimpleStrategy + +variable {S : ℝ≥0 → Ω → F} {T : ℝ≥0} {Q : Measure Ω} in +/-- **A continuous-time EMM, sampled, is a discrete-time EMM.** If `Q` is an equivalent +martingale measure up to `T` for the discounted price `S` in continuous time, then along +any monotone schedule `t 0 ≤ t 1 ≤ ⋯` whose first `T' + 1` dates lie in `[0, T]` it is an +equivalent martingale measure, at the discrete horizon `T'`, for the sampled price `n ↦ S (t n)` +and the sampled filtration `n ↦ 𝓕 (t n)`. General Ω; the sampled martingale is built from the +three consequences of `IsEMM` before the horizon (`martingale_min_iff`). -/ +theorem _root_.MathFin.IsEMM.sampled (h : IsEMM 𝓕 P S T Q) {t : ℕ → ℝ≥0} (ht : Monotone t) + (T' : ℕ) (hT' : t T' ≤ T) : + MathFin.IsEMM (sampledFiltration 𝓕 ht) P (fun n ↦ S (t n)) T' Q := + have := h.isProb + ⟨h.toIsEquivProbMeasure, martingale_min_iff.mpr + ⟨fun n hn ↦ h.adapted (t := t n) ((ht hn).trans hT'), + fun n hn ↦ h.integrable (t := t n) ((ht hn).trans hT'), + fun m n hmn hnT' ↦ (h.condExp_eq (s := t m) (t := t n) (ht hmn) ((ht hnT').trans hT')).symm⟩⟩ + +/-- **Forward continuous first FTAP: an equivalent martingale measure precludes simple-strategy +arbitrage.** If `Q` is an EMM for the discounted price `S` up to `T`, then no simple strategy +trading on `[0, T]` has gains that are `P`-a.s. nonnegative and strictly positive on a +`P`-non-null set. + +The proof is the discrete forward theorem. A simple strategy `ψ` is a discrete predictable +strategy (`toDiscrete`) for the price sampled at its own trading dates (`schedule`, a monotone +schedule inside `[0, T]`): the sampled price is a discrete EMM (`IsEMM.sampled`) and the gains +`ψ.gains S` are the martingale transform of the sampled price by the holdings +(`gains_eq_martingaleTransform`). So `MathFin.IsEMM.noArbitrage` (`FTAP.lean`) applies, and the +continuous theorem has no argument of its own. -/ +theorem isEMM_noArbitrageSimple {S : ℝ≥0 → Ω → F} {T : ℝ≥0} {Q : Measure Ω} + (h : IsEMM 𝓕 P S T Q) : NoArbitrageSimple 𝓕 P S T := fun ψ hψT hnonneg ↦ by + rw [ψ.gains_eq_martingaleTransform] at hnonneg ⊢ + have hzero := (h.sampled ψ.monotone_schedule ψ.N (ψ.schedule_le hψT _)).noArbitrage + ψ.toDiscrete ψ.toDiscrete_predictable ψ.toDiscrete_bdd hnonneg + exact measure_mono_null (fun ω hω ↦ ne_of_gt hω) (ae_iff.mp hzero) + +end MathFin.ContinuousMarket diff --git a/LeanPool/MathFin/Pricing/ConvexPricingFunctional.lean b/LeanPool/MathFin/Pricing/ConvexPricingFunctional.lean new file mode 100644 index 0000000000..af1c678e2b --- /dev/null +++ b/LeanPool/MathFin/Pricing/ConvexPricingFunctional.lean @@ -0,0 +1,107 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.StatePrices +public import LeanPool.MathFin.Contracts.Instruments.CallPayoff + +/-! +# Convexity passes through the pricing functional + +**If the payoffs `g i K` are convex in a parameter `K` in every state, and the state prices `q i` +are non-negative, then the price `K ↦ statePricePricing s q (g · K)` is convex in `K`.** Pricing +with non-negative state prices is a positive linear functional, and a positive linear functional +preserves convexity. + +That is why call prices are convex in the strike and why a butterfly spread costs nothing +negative: the call payoff is convex in the strike (`convexOn_call_payoff`, +`Contracts/Instruments/CallPayoff.lean`), and the pricing functional carries the convexity from +payoff to price. Neither fact about prices is separate from this one. + +The same principle under an arbitrary law is `convexOn_integral_call` +(`Models/BlackScholes/StrikeConvexity.lean`), Mathlib's `integral_convexOn_of_integrand_ae` +applied to the call payoff, of which the finite-state statements here are the finitely supported +case; its infinitesimal face is `∂²_K bsV ≥ 0` (`bsV_partial_KK_nonneg`) and the non-negativity of +the implied density (`Models/ModelFree/BreedenLitzenberger.lean`). + +## Main results + +* `statePricePricing_convexOn`: pricing with non-negative state prices preserves convexity in any + parameter. +* `callPrice_finiteState_convexOn_K`: in a finite-state market the call price is convex in the + strike. +* `callPrice_finiteState_butterfly_nonneg`: a butterfly spread has non-negative price, the + price-level face of `butterfly_payoff_nonneg` (`Models/ModelFree/Spreads.lean`). + +## References + +* [Breeden and Litzenberger, *Prices of state-contingent claims implicit in option + prices*][BreedenLitzenberger1978] +* [R. C. Merton, *Theory of rational option pricing*][Merton1973] + +## Tags + +state prices, convexity preservation, butterfly spread, finite-state market, Arrow–Debreu, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Finset + +variable {ι : Type*} + +/-- **The pricing functional preserves convexity.** With non-negative state prices `q i` on `s`, +if each state's payoff `g i K` is convex in `K`, so is the price `statePricePricing s q (g · K)`: +each state's convexity inequality, multiplied by `q i ≥ 0`, sums to the price's. -/ +theorem statePricePricing_convexOn + (s : Finset ι) (q : ι → ℝ) (hq : ∀ i ∈ s, 0 ≤ q i) + (g : ι → ℝ → ℝ) (hg : ∀ i ∈ s, ConvexOn ℝ (Set.univ : Set ℝ) (g i)) : + ConvexOn ℝ (Set.univ : Set ℝ) (fun K ↦ statePricePricing s q (fun i ↦ g i K)) := by + refine ⟨convex_univ, fun K₁ _ K₂ _ a b ha hb hab ↦ ?_⟩ + change ∑ i ∈ s, q i * g i (a • K₁ + b • K₂) + ≤ a • (∑ i ∈ s, q i * g i K₁) + b • (∑ i ∈ s, q i * g i K₂) + simp only [smul_eq_mul] + rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib] + refine Finset.sum_le_sum fun i hi ↦ ?_ + have hconv := (hg i hi).2 (Set.mem_univ K₁) (Set.mem_univ K₂) ha hb hab + simp only [smul_eq_mul] at hconv + linarith [mul_le_mul_of_nonneg_left hconv (hq i hi), + show q i * (a * g i K₁ + b * g i K₂) = a * (q i * g i K₁) + b * (q i * g i K₂) by ring] + +/-- **The call price is convex in the strike (finite-state market).** With non-negative state +prices and terminal values `S i`, the price `K ↦ statePricePricing s q (max (S · − K) 0)` of the +call struck at `K` is convex: the payoff is (`convexOn_call_payoff`), and pricing preserves it +(`statePricePricing_convexOn`). -/ +theorem callPrice_finiteState_convexOn_K (s : Finset ι) + (S : ι → ℝ) (q : ι → ℝ) (hq : ∀ i ∈ s, 0 ≤ q i) : + ConvexOn ℝ (Set.univ : Set ℝ) + (fun K ↦ statePricePricing s q (fun i ↦ max (S i - K) 0)) := + statePricePricing_convexOn s q hq (fun i K ↦ max (S i - K) 0) fun i _ ↦ + convexOn_call_payoff (S i) + +/-- **A butterfly spread has non-negative price (finite-state market).** For strikes `K₁, K₃` +and their midpoint, with `C(K) = statePricePricing s q (max (S · − K) 0)` the call price, +`C(K₁) − 2 C((K₁ + K₃)/2) + C(K₃) ≥ 0`: the midpoint inequality of the convex price +(`callPrice_finiteState_convexOn_K`). Its payoff-level face is `butterfly_payoff_nonneg`, and its +continuous-law counterpart, through `convexOn_integral_call`, is the non-negativity of the implied +density. -/ +theorem callPrice_finiteState_butterfly_nonneg (s : Finset ι) + (S : ι → ℝ) (q : ι → ℝ) (hq : ∀ i ∈ s, 0 ≤ q i) (K₁ K₃ : ℝ) : + 0 ≤ statePricePricing s q (fun i ↦ max (S i - K₁) 0) + - 2 * statePricePricing s q (fun i ↦ max (S i - (K₁ + K₃) / 2) 0) + + statePricePricing s q (fun i ↦ max (S i - K₃) 0) := by + have h := (callPrice_finiteState_convexOn_K s S q hq).2 (Set.mem_univ K₁) (Set.mem_univ K₃) + (by norm_num : (0:ℝ) ≤ 1/2) (by norm_num : (0:ℝ) ≤ 1/2) (by norm_num : (1/2:ℝ) + 1/2 = 1) + simp only [smul_eq_mul] at h + rw [show (1/2 * K₁ + 1/2 * K₃ : ℝ) = (K₁ + K₃) / 2 by ring] at h + linarith + +end MathFin diff --git a/LeanPool/MathFin/Pricing/DiscreteMarket.lean b/LeanPool/MathFin/Pricing/DiscreteMarket.lean new file mode 100644 index 0000000000..089170c61b --- /dev/null +++ b/LeanPool/MathFin/Pricing/DiscreteMarket.lean @@ -0,0 +1,269 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.Parity +public import LeanPool.MathFin.Pricing.FTAP.DalangMortonWillinger +public import LeanPool.MathFin.Pricing.FTAP.FTAPDiscrete +public import LeanPool.MathFin.Pricing.Market +public import LeanPool.MathFin.Probability.Martingales.TimeChange + +/-! +# The discrete-time market on the trunk + +A model for the instruments of `Contracts/Instruments/Options.lean`, its fundamental theorems of +asset pricing read on the trunk's `Market`, and the seam between the contracts layer and the +multi-period FTAP. A one-asset discrete-time market on a general filtered probability space, a price +`S : ℕ → Ω → ℝ` with an equivalent martingale measure `IsEMM 𝓕 P S T Q`, is a contract model +map: between integer dates the underlying is constant, `discreteAssets S T () t = S ⌊t⌋₊` frozen +at the horizon `T` (the price is a `Q`-martingale only up to `T`). The price `S` is quoted in +units of the numeraire, so cash is not discounted, `D ≡ 1`. + +The filtration of the model is `floorFiltration 𝓕`, `t ↦ 𝓕 ⌊t⌋₊`, the time change of `𝓕` along +the step count `t ↦ ⌊t⌋₊` (`Filtration.comp`), and the frozen price is a martingale for it +(`Martingale.comp`). The risk-neutral lemmas of `Pricing/Parity.lean` then +apply as they stand: the forward is worth `S₀ − K` and call minus put is `S₀ − K` at every +maturity (`value_forward`, `value_europeanCall_sub_put`); at an integer maturity `n` the +underlying is `S (min n T)` (`discreteAssets_natCast`). Parity is not re-proved here. + +The discrete market is a `Market` (`toMarket`): the frozen price, the floor filtration and the +unit numéraire. An equivalent martingale measure is a pricing measure of it +(`isPricingMeasure_toMarket_of_isEMM`), and a pricing measure, which is equivalent to `P` only on +the information at the horizon, agrees there with an equivalent martingale measure +(`isPricingMeasure_toMarket_iff`, the converse direction through `Martingale.of_comp` and +`Market.IsPricingMeasure.exists_isEquivProbMeasure`). Its price is the contract value with `D ≡ 1` +(`price_toMarket`). + +**The fundamental theorem on the trunk.** A pricing measure rules out arbitrage +(`Market.IsPricingMeasure.noArbitrage_toMarket`). On a finite sample space with full support, no +arbitrage is equivalent to the existence of a pricing measure +(`noArbitrage_iff_exists_isPricingMeasure_of_finite`, Harrison–Pliska through `ftap_discrete`); on +a general space the same holds **assuming `ConditionalOnePeriodFTAP`** (the conditional one-period +FTAP, not proved in this library; `noArbitrage_iff_exists_isPricingMeasure`, through the +Dalang–Morton–Willinger reduction). The composite `exists_isPricingMeasure_parity` adds parity: +under that hypothesis an arbitrage-free adapted integrable market has one pricing measure `Q` under +which, for every strike and maturity, the forward's price is `S₀ − K` and the call's price less the +put's is `S₀ − K`. + +## Main definitions + +* `floorFiltration`: the continuous-time filtration `t ↦ 𝓕 ⌊t⌋₊` of a discrete one, the time + change `𝓕.comp Nat.floor_mono`. +* `discreteAssets`: the discrete market as a contract model map, frozen at the horizon. +* `toMarket`: the discrete market as a `Market`, with the unit numéraire. + +## Main results + +* `value_forward`, `value_europeanCall_sub_put`: forward value and put–call parity under an `IsEMM`. +* `isPricingMeasure_toMarket_iff`: the pricing measures of `toMarket` are the measures that agree + with an `IsEMM` on the information at the horizon. +* `noArbitrage_iff_exists_isPricingMeasure_of_finite`: the finite-`Ω` FTAP on the trunk. +* `noArbitrage_iff_exists_isPricingMeasure`: the FTAP on the trunk, given + `ConditionalOnePeriodFTAP`. +* `exists_isPricingMeasure_parity`: no arbitrage gives a pricing measure under which parity holds, + given `ConditionalOnePeriodFTAP`. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [J. M. Harrison and S. R. Pliska, *Martingales and stochastic integrals in the theory of + continuous trading*][HarrisonPliska1981] +* [H. Föllmer and A. Schied, *Stochastic Finance: An Introduction in Discrete Time*][FollmerSchied], + §5.2 + +## Tags + +discrete-time market, equivalent martingale measure, put–call parity, forward price, +contract model, Dalang–Morton–Willinger, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +open MeasureTheory +open scoped NNReal + +namespace MathFin.Contracts.DiscreteMarket + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- The continuous-time filtration `t ↦ 𝓕 ⌊t⌋₊` of a discrete-time one: its time change along the +step count. -/ +noncomputable abbrev floorFiltration (𝓕 : Filtration ℕ mΩ) : Filtration ℝ≥0 mΩ := + 𝓕.comp (Nat.floor_mono (R := ℝ≥0)) + +/-- A discrete-time price as a contract model map: constant between integer dates and frozen at +the horizon `T`. -/ +noncomputable def discreteAssets (S : ℕ → Ω → ℝ) (T : ℕ) : Unit → ℝ≥0 → Ω → ℝ := + fun _ t ω ↦ S (min ⌊t⌋₊ T) ω + +/-- At an integer date `n` the underlying is the price at `min n T`. -/ +theorem discreteAssets_natCast (S : ℕ → Ω → ℝ) (T n : ℕ) (ω : Ω) : + discreteAssets S T () (n : ℝ≥0) ω = S (min n T) ω := by + simp [discreteAssets] + +variable {𝓕 : Filtration ℕ mΩ} {P Q : Measure Ω} {S : ℕ → Ω → ℝ} {T : ℕ} {S₀ : ℝ} + +/-- Under an equivalent martingale measure the model's (undiscounted) price is a martingale for +the floor filtration. -/ +theorem martingale_discreteAssets (hQ : IsEMM 𝓕 P S T Q) : + Martingale (fun t ω ↦ (fun _ : ℝ≥0 ↦ (1 : ℝ)) t * discreteAssets S T () t ω) + (floorFiltration 𝓕) Q := by + simpa only [one_mul, discreteAssets] using hQ.martingale.comp (Nat.floor_mono (R := ℝ≥0)) + +/-- **The forward's value under an equivalent martingale measure**: the forward struck at `K`, at +any maturity, is worth `S₀ - K` (the price is in numeraire units, `D ≡ 1`), for a price starting +at `S₀`. This is `value_forward_of_martingale`. -/ +theorem value_forward (hQ : IsEMM 𝓕 P S T Q) (hS₀ : ∀ ω, S 0 ω = S₀) (K : ℝ) (τ : ℝ≥0) : + (forward K τ).value Q (fun _ _ ↦ 1) (discreteAssets S T) = S₀ - K := by + have := hQ.isProb + have := value_forward_of_martingale (K := K) (T := τ) (𝓕 := floorFiltration 𝓕) + (martingale_discreteAssets hQ) rfl + (fun ω ↦ by + change S (min ⌊(0 : ℝ≥0)⌋₊ T) ω = S₀ + rw [Nat.floor_zero, Nat.zero_min] + exact hS₀ ω) + simpa using this + +/-- **Put–call parity under an equivalent martingale measure**: at any maturity, call minus put +is `S₀ - K`. This is `value_europeanCall_sub_put_of_martingale`. -/ +theorem value_europeanCall_sub_put (hQ : IsEMM 𝓕 P S T Q) (hS₀ : ∀ ω, S 0 ω = S₀) (K : ℝ) + (τ : ℝ≥0) : + (europeanCall K τ).value Q (fun _ _ ↦ 1) (discreteAssets S T) + - (europeanPut K τ).value Q (fun _ _ ↦ 1) (discreteAssets S T) = S₀ - K := by + have := hQ.isProb + have := value_europeanCall_sub_put_of_martingale (K := K) (T := τ) (𝓕 := floorFiltration 𝓕) + (martingale_discreteAssets hQ) rfl + (fun ω ↦ by + change S (min ⌊(0 : ℝ≥0)⌋₊ T) ω = S₀ + rw [Nat.floor_zero, Nat.zero_min] + exact hS₀ ω) + simpa using this + +/-! ### The discrete market as a `Market` -/ + +/-- **The discrete market as a `Market`**: the price frozen at the horizon (`discreteAssets`), the +floor filtration, and the unit numéraire, since the price is already quoted in numéraire units. The +price need only be adapted up to the horizon. -/ +noncomputable def toMarket (P : Measure Ω) (𝓕 : Filtration ℕ mΩ) (S : ℕ → Ω → ℝ) (T : ℕ) + (hS : ∀ n ≤ T, StronglyMeasurable[𝓕 n] (S n)) : Market Unit Ω where + P := P + 𝓕 := floorFiltration 𝓕 + asset := discreteAssets S T + numeraire _ _ := 1 + numeraire_pos _ _ := one_pos + asset_adapted _ t := by + change StronglyMeasurable[(floorFiltration 𝓕) t] (S (min ⌊t⌋₊ T)) + rw [floorFiltration, Filtration.comp_apply] + exact (hS (min ⌊t⌋₊ T) (min_le_right _ _)).mono (𝓕.mono (min_le_left _ _)) + numeraire_adapted _ := stronglyMeasurable_const + +variable {hS : ∀ n ≤ T, StronglyMeasurable[𝓕 n] (S n)} + +theorem deflator_toMarket : (toMarket P 𝓕 S T hS).deflator = fun _ _ ↦ 1 := by + funext t ω + simp [Market.deflator, toMarket] + +/-- The price in the discrete market is the contract value with the unit discount `D ≡ 1`. -/ +theorem price_toMarket (c : Contract Unit) : + (toMarket P 𝓕 S T hS).price Q c = c.value Q (fun _ _ ↦ 1) (discreteAssets S T) := by + change c.value Q (toMarket P 𝓕 S T hS).deflator (discreteAssets S T) = _ + rw [deflator_toMarket] + +/-- The deflated asset of the discrete market, frozen at the horizon, is the floor extension of +`n ↦ S (min n T)`. -/ +theorem deflated_toMarket_min (u : Unit) : + (fun t ↦ (toMarket P 𝓕 S T hS).deflated u (min t T)) = fun t ω ↦ S (min ⌊t⌋₊ T) ω := by + funext t ω + have hfl : ⌊min t (T : ℝ≥0)⌋₊ = min ⌊t⌋₊ T := by + rw [Nat.floor_mono.map_min, Nat.floor_natCast] + simp [Market.deflated, toMarket, discreteAssets, hfl] + +/-- **An equivalent martingale measure is a pricing measure of the discrete market**: the floor +extension of the frozen price is a martingale for the floor filtration (`Martingale.comp`). -/ +theorem isPricingMeasure_toMarket_of_isEMM (hQ : IsEMM 𝓕 P S T Q) : + (toMarket P 𝓕 S T hS).IsPricingMeasure T Q := + .of_isEquivProbMeasure hQ.toIsEquivProbMeasure fun u ↦ by + rw [deflated_toMarket_min] + exact hQ.martingale.comp (Nat.floor_mono (R := ℝ≥0)) + +/-- **A pricing measure of the discrete market that is equivalent to `P` everywhere is an +equivalent martingale measure**: the frozen price is read back from its floor extension at the +integer dates (`Martingale.of_comp`, with the right inverse `Nat.cast`). -/ +theorem isEMM_of_isPricingMeasure_toMarket (hQ : (toMarket P 𝓕 S T hS).IsPricingMeasure T Q) + (hQP : IsEquivProbMeasure P Q) : IsEMM 𝓕 P S T Q := by + have hM := hQ.martingale () + rw [deflated_toMarket_min] at hM + exact ⟨hQP, Martingale.of_comp (f := fun n ↦ S (min n T)) (Nat.floor_mono (R := ℝ≥0)) + Nat.mono_cast Nat.floor_natCast hM⟩ + +/-- **The pricing measures of the discrete market are the measures that agree with an equivalent +martingale measure on the information at the horizon.** A pricing measure is equivalent to `P` on +`𝓕 T` only; it agrees there with one equivalent to `P` everywhere +(`Market.IsPricingMeasure.exists_isEquivProbMeasure`), which is an `IsEMM`. Conversely an `IsEMM` +is a pricing measure, and so is every measure agreeing with a pricing measure on `𝓕 T` +(`Market.IsPricingMeasure.of_trim_eq`). -/ +theorem isPricingMeasure_toMarket_iff [IsFiniteMeasure P] : + (toMarket P 𝓕 S T hS).IsPricingMeasure T Q ↔ + ∃ Q', IsEMM 𝓕 P S T Q' ∧ + Q'.trim ((toMarket P 𝓕 S T hS).𝓕.le T) = Q.trim ((toMarket P 𝓕 S T hS).𝓕.le T) := by + refine ⟨fun hQ ↦ ?_, fun ⟨Q', hQ', htrim⟩ ↦ (isPricingMeasure_toMarket_of_isEMM hQ').of_trim_eq + htrim⟩ + have : IsFiniteMeasure (toMarket P 𝓕 S T hS).P := inferInstanceAs (IsFiniteMeasure P) + obtain ⟨Q', hQP, hQ', htrim⟩ := hQ.exists_isEquivProbMeasure + exact ⟨Q', isEMM_of_isPricingMeasure_toMarket hQ' hQP, htrim⟩ + +/-- **A pricing measure rules out arbitrage** in the discrete market: it agrees on the information +at the horizon with an equivalent martingale measure (`isPricingMeasure_toMarket_iff`), which does +(`IsEMM.noArbitrage`). -/ +theorem _root_.MathFin.Market.IsPricingMeasure.noArbitrage_toMarket [IsFiniteMeasure P] + (hQ : (toMarket P 𝓕 S T hS).IsPricingMeasure T Q) : NoArbitrage 𝓕 P S T := + (isPricingMeasure_toMarket_iff.1 hQ).elim fun _ h ↦ h.1.noArbitrage + +/-- **The fundamental theorem of asset pricing on the trunk, finite sample space** +(Harrison–Pliska): a one-asset discrete market on a finite space whose reference measure charges +every state has no arbitrage iff it has a pricing measure. This is `ftap_discrete` read through +`isPricingMeasure_toMarket_iff`. -/ +theorem noArbitrage_iff_exists_isPricingMeasure_of_finite [Finite Ω] [Nonempty Ω] + [MeasurableSingletonClass Ω] [IsFiniteMeasure P] (hSa : StronglyAdapted 𝓕 S) + (hP : ∀ ω, 0 < P {ω}) : + NoArbitrage 𝓕 P S T ↔ ∃ Q, (toMarket P 𝓕 S T fun n _ ↦ hSa n).IsPricingMeasure T Q := + ⟨fun hNA ↦ ((ftap_discrete 𝓕 P S T hSa hP).1 hNA).imp fun _ ↦ isPricingMeasure_toMarket_of_isEMM, + fun ⟨_, hQ⟩ ↦ hQ.noArbitrage_toMarket⟩ + +variable (hS) in +/-- **The fundamental theorem of asset pricing on the trunk, assuming the conditional one-period +FTAP** (Dalang–Morton–Willinger): for an adapted integrable one-asset price, if +`ConditionalOnePeriodFTAP` holds (an hypothesis, **not proved** in this library: see +`DalangMortonWillinger.lean`), no arbitrage is equivalent to the existence of a pricing measure of +the discrete market. Only the forward direction uses the hypothesis. -/ +theorem noArbitrage_iff_exists_isPricingMeasure [IsProbabilityMeasure P] + (hint : ∀ t ≤ T, Integrable (S t) P) (hcond : ConditionalOnePeriodFTAP 𝓕 P S T) : + NoArbitrage 𝓕 P S T ↔ ∃ Q, (toMarket P 𝓕 S T hS).IsPricingMeasure T Q := + ⟨fun hNA ↦ (exists_isEMM_of_noArbitrage_of_conditionalFTAP hS hint hcond hNA).imp + fun _ ↦ isPricingMeasure_toMarket_of_isEMM, fun ⟨_, hQ⟩ ↦ hQ.noArbitrage_toMarket⟩ + +variable (hS) in +/-- **No arbitrage gives a pricing measure under which the contracts satisfy parity**, assuming the +conditional one-period FTAP. For an adapted integrable one-asset price with +`ConditionalOnePeriodFTAP` (an hypothesis, **not proved** in this library: see +`DalangMortonWillinger.lean`), no arbitrage yields one pricing measure `Q` of `toMarket` under +which, for every strike and maturity, the forward's price is `S₀ - K` and the call's price less the +put's is `S₀ - K`. -/ +theorem exists_isPricingMeasure_parity [IsProbabilityMeasure P] (hint : ∀ t ≤ T, Integrable (S t) P) + (hcond : ConditionalOnePeriodFTAP 𝓕 P S T) (hNA : NoArbitrage 𝓕 P S T) + (hS₀ : ∀ ω, S 0 ω = S₀) : + ∃ Q, (toMarket P 𝓕 S T hS).IsPricingMeasure T Q ∧ ∀ (K : ℝ) (τ : ℝ≥0), + (toMarket P 𝓕 S T hS).price Q (forward K τ) = S₀ - K ∧ + (toMarket P 𝓕 S T hS).price Q (europeanCall K τ) + - (toMarket P 𝓕 S T hS).price Q (europeanPut K τ) = S₀ - K := by + obtain ⟨Q, hQ⟩ := exists_isEMM_of_noArbitrage_of_conditionalFTAP hS hint hcond hNA + refine ⟨Q, isPricingMeasure_toMarket_of_isEMM hQ, fun K τ ↦ ?_⟩ + simp only [price_toMarket] + exact ⟨value_forward hQ hS₀ K τ, value_europeanCall_sub_put hQ hS₀ K τ⟩ + +end MathFin.Contracts.DiscreteMarket diff --git a/LeanPool/MathFin/Pricing/Duality/ConvexDuality.lean b/LeanPool/MathFin/Pricing/Duality/ConvexDuality.lean new file mode 100644 index 0000000000..b76f245d1b --- /dev/null +++ b/LeanPool/MathFin/Pricing/Duality/ConvexDuality.lean @@ -0,0 +1,163 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.InnerProductSpace.Basic +public import Mathlib.Analysis.LocallyConvex.Separation + +/-! +# Cone-separation roots for the convex-duality unification + +The shared geometric kernel of mathematical finance's convex-duality pillar: finite-dimensional +separation of a closed convex **cone** `C ⊆ (ι → ℝ)` produces a positive pricing/representing +functional. Two faces of the same Hahn–Banach principle live here: + +* `exists_pos_separating_of_cone_disjoint_simplex` — a cone disjoint from the whole standard simplex + admits a **strictly** positive functional `q` (`> 0` at every coordinate) that is `≤ 0` on the + cone. This is the FTAP separating functional: the attainable-gains cone misses the simplex (no + arbitrage) ⟹ the equivalent martingale measure. It generalizes the subspace kernel + `exists_pos_dual_of_disjoint_stdSimplex` (two-sided `= 0`) to a cone (one-sided `≤ 0`). +* `exists_separating_of_not_mem_cone` — a single point outside a closed convex cone is separated by + a functional `p` that is `≤ 0` on the cone and `> 0` at the point. This is the coherent-risk + representing density: a rejected position separated from the acceptance cone. + +Both rest on two shared atoms — `functional_eq_sum_single` (basis expansion of a functional) and +`functional_nonneg_on_cone` (a functional bounded below on a cone is `≥ 0` on it; the cone's +nonnegative-scaling homogeneity is what turns a separation bound into a sign). The separations +themselves are Mathlib's `geometric_hahn_banach_compact_closed` and +`geometric_hahn_banach_point_closed`. + +## API at this pin + +The cone is a `C : Set (ι → ℝ)` carrying `Convex ℝ C`, `IsClosed C`, and homogeneity +`∀ x ∈ C, ∀ c ≥ 0, c • x ∈ C`. There is no `ConvexCone.dual` constant at this pin, but +`ProperCone`/`PointedCone` *are* live, and Mathlib's `ProperCone.hyperplane_separation` +(`Analysis/Convex/Cone/Dual.lean`) is the separation theorem the results below re-derive +from `geometric_hahn_banach_compact_closed`. Consuming it — packaging `C` as a +`ProperCone ℝ (ι → ℝ)` and keeping only the `Pi.single` coordinate glue — is an open +upgrade; the explicit `Set` representation is a historical choice, not a forced one. + +## Main results + +* `MathFin.exists_pos_separating_of_cone_disjoint_simplex`: for a convex, closed cone `C` in + `ι → ℝ` (`ι` finite) that contains no point of the standard simplex, there exists `q` with + every coordinate positive and `∑ q i * v i ≤ 0` for all `v ∈ C`. +* `MathFin.exists_separating_of_not_mem_cone`: for a convex, closed cone `C` containing `0` and a + point `x₀ ∉ C`, there exists `p` with `∑ p i * v i ≤ 0` on `C` and `0 < ∑ p i * x₀ i`. + +## Tags + +Hahn–Banach separation, convex cone, no arbitrage, coherent risk measure, pricing functional, +separating hyperplane, MSC 90C25, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + + +/-- A continuous linear functional on `ι → ℝ` equals its `∑ wᵢ · f(eᵢ)` expansion on the +standard basis. Shared atom of the two cone-separation theorems below. -/ +lemma functional_eq_sum_single {ι : Type*} [Fintype ι] [DecidableEq ι] + (f : StrongDual ℝ (ι → ℝ)) (w : ι → ℝ) : + f w = ∑ i, w i * f (Pi.single i 1) := by + have hwsum : w = ∑ i, w i • Pi.single i (1 : ℝ) := by + funext j; rw [Finset.sum_apply] + simp only [Pi.smul_apply, smul_eq_mul] + rw [Finset.sum_eq_single j] + · rw [Pi.single_eq_same, mul_one] + · intro b _ hb; rw [Pi.single_eq_of_ne (Ne.symm hb), mul_zero] + · intro h; exact absurd (Finset.mem_univ j) h + conv_lhs => rw [hwsum] + rw [map_sum]; exact Finset.sum_congr rfl fun i _ ↦ by rw [map_smul, smul_eq_mul] + +/-- A functional bounded below by a negative `u` on a cone `C` is nonnegative on `C`: a ray +`c ∈ C` with `f c < 0` is unbounded below on `C` (scale by `(u-1)/f c ≥ 0`), contradicting the +bound. Shared atom of the two cone-separation theorems below. -/ +lemma functional_nonneg_on_cone {ι : Type*} {C : Set (ι → ℝ)} + (hCcone : ∀ ⦃x⦄, x ∈ C → ∀ ⦃c : ℝ⦄, 0 ≤ c → c • x ∈ C) + {f : StrongDual ℝ (ι → ℝ)} {u : ℝ} (hu : u < 0) (hlb : ∀ y ∈ C, u < f y) : + ∀ c ∈ C, 0 ≤ f c := by + intro c hc + by_contra hlt + rw [not_le] at hlt + have hfcne : f c ≠ 0 := ne_of_lt hlt + have ht : 0 ≤ (u - 1) / f c := by + rw [div_nonneg_iff]; right; exact ⟨by linarith, le_of_lt hlt⟩ + have hmem : ((u - 1) / f c) • c ∈ C := hCcone hc ht + have hval : f (((u - 1) / f c) • c) = u - 1 := by rw [map_smul, smul_eq_mul]; field_simp + have hlt2 := hlb _ hmem; rw [hval] at hlt2; linarith + +/-- **Cone separation root.** A closed convex cone `C ⊆ (ι → ℝ)` containing no probability vector +(no nonnegative `v` with `∑ i, v i = 1`, i.e. disjoint from the standard simplex) admits a +strictly-positive functional `q` that is `≤ 0` on `C` (a separating supporting functional). +The geometric heart shared by the FTAP (gains cone), the coherent-risk representation (acceptance +cone), and superhedging (super-replication cone). Generalizes +`exists_pos_dual_of_disjoint_stdSimplex` (subspace ⇒ two-sided `= 0`) to a cone (one-sided `≤ 0`). +-/ +theorem exists_pos_separating_of_cone_disjoint_simplex + {ι : Type*} [Fintype ι] + (C : Set (ι → ℝ)) (hCconv : Convex ℝ C) (hCclosed : IsClosed C) + (hCcone : ∀ ⦃x⦄, x ∈ C → ∀ ⦃c : ℝ⦄, 0 ≤ c → c • x ∈ C) + (hdisj : ∀ v : ι → ℝ, (∀ i, 0 ≤ v i) → ∑ i, v i = 1 → v ∉ C) : + ∃ q : ι → ℝ, (∀ i, 0 < q i) ∧ ∀ v ∈ C, ∑ i, q i * v i ≤ 0 := by + classical + rcases C.eq_empty_or_nonempty with hCempty | hCne + · exact ⟨fun _ ↦ 1, fun _ ↦ one_pos, fun w hw ↦ by rw [hCempty] at hw; simp at hw⟩ + obtain ⟨x₀, hx₀⟩ := hCne + have h0C : (0 : ι → ℝ) ∈ C := by simpa using hCcone hx₀ (le_refl (0 : ℝ)) + set Δ : Set (ι → ℝ) := Set.range fun w : Convexity.StdSimplex ℝ ι ↦ ⇑w.weights + have hconvΔ : Convex ℝ Δ := by + rintro _ ⟨w₁, rfl⟩ _ ⟨w₂, rfl⟩ a b ha hb hab + exact ⟨Convexity.convexCombPair a b ha hb hab w₁ w₂, by simp⟩ + have hcompΔ : IsCompact Δ := + isCompact_range (Convexity.StdSimplex.isEmbedding_toFun_comp_weights ℝ ι).continuous + obtain ⟨f, u, v, hfu, huv, hfv⟩ := geometric_hahn_banach_compact_closed hconvΔ hcompΔ hCconv + hCclosed (Set.disjoint_left.2 (by + rintro _ ⟨w, rfl⟩; exact hdisj _ w.weights_nonneg w.total_of_fintype)) + have hv_neg : v < 0 := by have h0 := hfv 0 h0C; rwa [map_zero] at h0 + have hfC_nonneg : ∀ c ∈ C, 0 ≤ f c := functional_nonneg_on_cone hCcone hv_neg hfv + have hsingle_mem (i : ι) : (Pi.single i (1 : ℝ)) ∈ Δ := + ⟨.single i, by simp [Finsupp.single_eq_pi_single]⟩ + have hsingle_neg : ∀ i, f (Pi.single i (1 : ℝ)) < 0 := fun i ↦ by + have := hfu _ (hsingle_mem i); linarith + refine ⟨fun i ↦ - f (Pi.single i 1), fun i ↦ by have := hsingle_neg i; linarith, fun w hw ↦ ?_⟩ + calc ∑ i, (- f (Pi.single i (1 : ℝ))) * w i + = - ∑ i, w i * f (Pi.single i 1) := by + rw [← Finset.sum_neg_distrib]; exact Finset.sum_congr rfl fun i _ ↦ by ring + _ = - f w := by rw [← functional_eq_sum_single f w] + _ ≤ 0 := by have := hfC_nonneg w hw; linarith + +/-- **Cone point-separation.** A point `x₀` outside a closed convex cone `C ⊆ (ι → ℝ)` is +separated by a functional `p` that is `≤ 0` on `C` and `> 0` at `x₀`. The companion to +`exists_pos_separating_of_cone_disjoint_simplex`: that separates a cone from the whole simplex +(strictly positive `q`); this separates a single exterior point from the cone (a representing +density direction). The coherent-risk representation applies it to a rejected position and the +acceptance cone. -/ +theorem exists_separating_of_not_mem_cone + {ι : Type*} [Fintype ι] (C : Set (ι → ℝ)) + (hCconv : Convex ℝ C) (hCclosed : IsClosed C) + (hCcone : ∀ ⦃x⦄, x ∈ C → ∀ ⦃c : ℝ⦄, 0 ≤ c → c • x ∈ C) + (h0 : (0 : ι → ℝ) ∈ C) {x₀ : ι → ℝ} (hx₀ : x₀ ∉ C) : + ∃ p : ι → ℝ, (∀ v ∈ C, ∑ i, p i * v i ≤ 0) ∧ 0 < ∑ i, p i * x₀ i := by + classical + obtain ⟨f, u, hfx₀, hfC⟩ := geometric_hahn_banach_point_closed hCconv hCclosed hx₀ + have hu_neg : u < 0 := by have h0' := hfC 0 h0; rwa [map_zero] at h0' + have hfC_nonneg : ∀ c ∈ C, 0 ≤ f c := functional_nonneg_on_cone hCcone hu_neg hfC + refine ⟨fun i ↦ - f (Pi.single i 1), fun v hv ↦ ?_, ?_⟩ + · have hsum : ∑ i, (- f (Pi.single i (1 : ℝ))) * v i = - f v := by + rw [functional_eq_sum_single f v, ← Finset.sum_neg_distrib] + exact Finset.sum_congr rfl fun i _ ↦ by ring + rw [hsum]; have := hfC_nonneg v hv; linarith + · have hsum : ∑ i, (- f (Pi.single i (1 : ℝ))) * x₀ i = - f x₀ := by + rw [functional_eq_sum_single f x₀, ← Finset.sum_neg_distrib] + exact Finset.sum_congr rfl fun i _ ↦ by ring + rw [hsum]; linarith + +end MathFin diff --git a/LeanPool/MathFin/Pricing/Duality/ConvexSeparation.lean b/LeanPool/MathFin/Pricing/Duality/ConvexSeparation.lean new file mode 100644 index 0000000000..53ab7488bb --- /dev/null +++ b/LeanPool/MathFin/Pricing/Duality/ConvexSeparation.lean @@ -0,0 +1,91 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.Duality.ConvexDuality +public import Mathlib.Analysis.RCLike.Lemmas + +/-! +# Separating-functional kernel for the finite Fundamental Theorem of Asset Pricing + +A finite-dimensional subspace `V ⊆ (ι → ℝ)` disjoint from the standard simplex +admits a strictly-positive dual functional that annihilates it. This is the +geometric heart of the finite-state FTAP: when the attainable-gains subspace of a +market misses the simplex (no arbitrage), the separating hyperplane *is* the +equivalent martingale measure (a strictly-positive pricing functional). + +This kernel is **derived** from the cone-separation root +`exists_pos_separating_of_cone_disjoint_simplex` (`MathFin/Pricing/Duality/ConvexDuality.lean`): +a subspace is a two-sided cone, so the root's one-sided `≤ 0` bound plus neg-closure +yields the two-sided `= 0` annihilation. It is the subspace case of the convex-duality +unification. + +The underlying separation is the cone root `MathFin.exists_pos_separating_of_cone_disjoint_simplex` +(`Pricing/Duality/ConvexDuality.lean`), specialised to the two-sided subspace case. + +## Main results + +* `MathFin.exists_pos_dual_of_disjoint_stdSimplex` +* `MathFin.exists_ne_zero_sum_mul_eq_zero` — a proper subspace of `ι → ℝ` is annihilated by a + nonzero vector (the second FTAP's dual certificate of incompleteness). +* `MathFin.exists_pos_add_mul_pos` — strictly positive weights stay strictly positive after a + small perturbation in any direction. + +## Tags + +separating hyperplane, no arbitrage, state prices, equivalent martingale measure, finite-state FTAP, +standard simplex, MSC 90C25, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + + +/-- **Separating-dual kernel.** A subspace `V` of the finite-dimensional space +`ι → ℝ` that contains no probability vector (no nonnegative `v` with `∑ i, v i = 1`) admits a +strictly-positive vector `q` whose induced functional annihilates `V`. -/ +theorem exists_pos_dual_of_disjoint_stdSimplex + {ι : Type*} [Fintype ι] + (V : Submodule ℝ (ι → ℝ)) (hV : ∀ v : ι → ℝ, (∀ i, 0 ≤ v i) → ∑ i, v i = 1 → v ∉ V) : + ∃ q : ι → ℝ, (∀ i, 0 < q i) ∧ ∀ v ∈ V, ∑ i, q i * v i = 0 := by + -- A subspace is a two-sided cone: apply the cone-separation root to `V`, then + -- use neg-closure to promote the one-sided `≤ 0` to the two-sided `= 0`. + obtain ⟨q, hpos, hle⟩ := + exists_pos_separating_of_cone_disjoint_simplex (V : Set (ι → ℝ)) V.convex + V.isClosed_of_finiteDimensional (fun x hx c _ ↦ V.smul_mem c hx) + hV + refine ⟨q, hpos, fun v hv ↦ le_antisymm (hle v hv) ?_⟩ + have hneg := hle (-v) (V.neg_mem hv) + simp only [Pi.neg_apply, mul_neg, Finset.sum_neg_distrib] at hneg + linarith + +/-- A proper subspace of `ι → ℝ` over a finite `ι` is annihilated, under the pairing +`∑ g i * η i`, by a nonzero `η`. -/ +theorem exists_ne_zero_sum_mul_eq_zero {ι : Type*} [Fintype ι] {W : Submodule ℝ (ι → ℝ)} + (hW : W < ⊤) : ∃ η : ι → ℝ, η ≠ 0 ∧ ∀ g ∈ W, ∑ i, g i * η i = 0 := by + classical + obtain ⟨ℓ, hℓ0, hℓ⟩ := W.exists_le_ker_of_lt_top hW + let η : ι → ℝ := fun i ↦ ℓ fun j ↦ if i = j then 1 else 0 + have hℓη (g : ι → ℝ) : ℓ g = ∑ i, g i * η i := by + rw [LinearMap.pi_apply_eq_sum_univ ℓ g] + simp [η] + exact ⟨η, fun h ↦ hℓ0 (LinearMap.ext fun g ↦ by simp [hℓη, h]), + fun g hg ↦ (hℓη g).symm.trans (LinearMap.mem_ker.1 (hℓ hg))⟩ + +/-- Positive weights stay positive under a small perturbation in any direction. -/ +theorem exists_pos_add_mul_pos {ι : Type*} [Finite ι] {p : ι → ℝ} (hp : ∀ i, 0 < p i) + (η : ι → ℝ) : ∃ ε > 0, ∀ i, 0 < p i + ε * η i := by + have h : ∀ᶠ ε in nhdsWithin (0 : ℝ) (Set.Ioi 0), ∀ i, 0 < p i + ε * η i := + eventually_nhdsWithin_of_eventually_nhds <| Filter.eventually_all.2 fun i ↦ by + have : Filter.Tendsto (fun ε : ℝ ↦ p i + ε * η i) (nhds 0) (nhds (p i)) := by + simpa using ((continuous_id.mul_const (η i)).const_add (p i)).tendsto 0 + exact this.eventually_const_lt (hp i) + exact (h.and self_mem_nhdsWithin).exists.imp fun _ h ↦ ⟨h.2, h.1⟩ + +end MathFin diff --git a/LeanPool/MathFin/Pricing/EquivMartingaleMeasure.lean b/LeanPool/MathFin/Pricing/EquivMartingaleMeasure.lean new file mode 100644 index 0000000000..1478ef70d5 --- /dev/null +++ b/LeanPool/MathFin/Pricing/EquivMartingaleMeasure.lean @@ -0,0 +1,97 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Martingales.EquivMeasure +public import LeanPool.MathFin.Probability.Martingales.MartingaleFrozen + +/-! +# Equivalent martingale measures up to a horizon + +`IsEMM 𝓕 P S T Q`: `Q` is an equivalent martingale measure for the discounted price `S` up to the +horizon `T`. `Q` is a probability measure with the null sets of `P`, and `S` frozen at the +horizon, `t ↦ S (min t T)`, is a `Q`-martingale for `𝓕`. Time is any linearly ordered index: the +discrete market (`FTAP.lean`, time `ℕ`) and the continuous one (`ContinuousMarket.lean`, time +`ℝ≥0`) state their theorems about this one structure. The horizon is part of the notion because a +price need not be a `Q`-martingale past it; a `Q`-martingale on all of time is an EMM at every +horizon (`IsEMM.of_martingale`). + +The one-period market keeps its own `OnePeriodVector.IsEMM` (a measure under which the price +increment is centred); `isEMM_one_iff_onePeriod` (`FTAP.lean`) shows it is this notion at `T = 1` +with `𝓕 0 = ⊥`. + +## Main definitions + +* `IsEMM 𝓕 P S T Q`: `Q ≈ P` and `t ↦ S (min t T)` is a `Q`-martingale for `𝓕`. + +## Main results + +* `IsEMM.of_martingale`: a martingale under an equivalent probability measure gives an EMM at + every horizon. +* `IsEMM.adapted`, `IsEMM.integrable`, `IsEMM.condExp_eq`: before the horizon the price is + adapted and integrable and satisfies `Q[S t | 𝓕 s] = S s` (`martingale_min_iff`). + +## References + +* [J. M. Harrison and S. R. Pliska, *Martingales and stochastic integrals in the theory of + continuous trading*][HarrisonPliska1981]. +* [H. Föllmer and A. Schied, *Stochastic Finance: An Introduction in Discrete Time*][FollmerSchied] + (equivalent martingale measures and the fundamental theorem). + +## Tags + +equivalent martingale measure, risk-neutral measure, pricing measure, martingale measure, +finite horizon, MSC 60G44, MSC 60G42, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory + +variable {Ω : Type*} {m0 : MeasurableSpace Ω} + {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] + {ι : Type*} [LinearOrder ι] + +/-- **Equivalent martingale measure up to the horizon `T`.** `Q` is a probability measure +mutually absolutely continuous with `P`, and the price `S` frozen at the horizon, +`t ↦ S (min t T)`, is a `Q`-martingale for `𝓕`. A `Q`-martingale on all of `ι` is an EMM at +every horizon (`IsEMM.of_martingale`). -/ +structure IsEMM (𝓕 : Filtration ι m0) (P : Measure Ω) (S : ι → Ω → F) (T : ι) + (Q : Measure Ω) : Prop extends IsEquivProbMeasure P Q where + martingale : Martingale (fun t ↦ S (min t T)) 𝓕 Q + +namespace IsEMM + +variable {𝓕 : Filtration ι m0} {P Q : Measure Ω} {S : ι → Ω → F} {T : ι} + +/-- **A martingale under an equivalent probability measure is an EMM at every horizon.** -/ +theorem of_martingale [IsProbabilityMeasure Q] (hS : Martingale S 𝓕 Q) (hQP : Q ≪ P) + (hPQ : P ≪ Q) (T : ι) : IsEMM 𝓕 P S T Q := + ⟨⟨inferInstance, hQP, hPQ⟩, martingale_min_of_martingale hS T⟩ + +/-- Before the horizon the price is `𝓕`-adapted. -/ +theorem adapted (h : IsEMM 𝓕 P S T Q) {t : ι} (ht : t ≤ T) : StronglyMeasurable[𝓕 t] (S t) := + have := h.isProb + (martingale_min_iff.mp h.martingale).1 t ht + +/-- Before the horizon the price is `Q`-integrable. -/ +theorem integrable (h : IsEMM 𝓕 P S T Q) {t : ι} (ht : t ≤ T) : Integrable (S t) Q := + have := h.isProb + (martingale_min_iff.mp h.martingale).2.1 t ht + +/-- **The martingale property before the horizon**: `Q[S t | 𝓕 s] = S s` for `s ≤ t ≤ T`. -/ +theorem condExp_eq (h : IsEMM 𝓕 P S T Q) {s t : ι} (hst : s ≤ t) (ht : t ≤ T) : + Q[S t | 𝓕 s] =ᵐ[Q] S s := + have := h.isProb + ((martingale_min_iff.mp h.martingale).2.2 hst ht).symm + +end IsEMM + +end MathFin diff --git a/LeanPool/MathFin/Pricing/FTAP/ContinuousFTAP.lean b/LeanPool/MathFin/Pricing/FTAP/ContinuousFTAP.lean new file mode 100644 index 0000000000..93024e8e74 --- /dev/null +++ b/LeanPool/MathFin/Pricing/FTAP/ContinuousFTAP.lean @@ -0,0 +1,109 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.BrownianMartingale +public import LeanPool.MathFin.Pricing.ContinuousMarket + +/-! +# Continuous-time first fundamental theorem of asset pricing (martingale property) + +Under the risk-neutral measure, the **discounted Black–Scholes price process is a +martingale** w.r.t. the Brownian filtration — the defining property of the equivalent +martingale measure (EMM), and the operational content of the first fundamental theorem +of asset pricing in continuous time. This is the continuous-time analogue of the +discrete binomial EMM (`Models/Binomial/SecondFTAP.lean`, `Models/Binomial/BinomialFromFTAP.lean`). + +The risk-neutral geometric Brownian motion is `S_t = S_0 exp((r − σ²/2)t + σ X_t)`, +driven by a filtered pre-Brownian motion `X`. Its discounted value is + + `e^{−rt} S_t = S_0 · exp(σ X_t − σ² t / 2)`, + +i.e. `S_0` times the **Wald exponential** `exp(σ X_t − σ² t / 2)`, which is a martingale +(`ProbabilityTheory.IsFilteredPreBrownian.waldExponential_isMartingale`). Hence the +discounted price is a martingale — directly, with no further stochastic-calculus +machinery. + +## Main results + +* `discountedGBM_isMartingale`: the discounted risk-neutral geometric Brownian motion + `e^{−rt} S_0 exp((r − σ²/2)t + σ X_t)`, driven by a filtered pre-Brownian motion `X`, is a + martingale. +* `discountedGBM_isEMM`: for every horizon `T`, `P` is an equivalent martingale measure (`IsEMM`) + for that process, with `Q = P`. +* `discountedGBM_noArbitrageSimple`: there is no arbitrage among simple strategies trading the + discounted process up to `T`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Ch 9 +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], Ch 5 + +## Tags + +fundamental theorem of asset pricing, risk-neutral measure, equivalent martingale measure, +Black–Scholes, discounted price martingale, geometric Brownian motion, JEL G13, MSC 91G20 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + {𝓕 : Filtration ℝ≥0 mΩ} {X : ℝ≥0 → Ω → ℝ} + [hX : IsFilteredPreBrownian X 𝓕 P] [IsFiniteMeasure P] + +/-- **Continuous-time first FTAP — martingale property of the discounted price.** +For the risk-neutral geometric Brownian motion `S_t = S_0 exp((r − σ²/2)t + σ X_t)` +driven by a filtered pre-Brownian motion `X`, the discounted price process +`t ↦ e^{−rt} S_t` is a martingale w.r.t. the Brownian filtration `𝓕` under `P` — the +defining property of the equivalent martingale measure (the discounted price is a +"fair game" under the risk-neutral measure). + +Immediate from the Wald exponential martingale, since `e^{−rt} S_t = S_0 · exp(σ X_t − +σ² t / 2)`. -/ +theorem discountedGBM_isMartingale (S_0 r σ : ℝ) : + Martingale (fun (t : ℝ≥0) ω ↦ Real.exp (-r * t) * + (S_0 * Real.exp ((r - σ ^ 2 / 2) * t + σ * X t ω))) 𝓕 P := by + have heq : (fun (t : ℝ≥0) ω ↦ Real.exp (-r * t) * + (S_0 * Real.exp ((r - σ ^ 2 / 2) * t + σ * X t ω))) + = (S_0 • fun (t : ℝ≥0) ω ↦ Real.exp (σ * X t ω - σ ^ 2 * (t : ℝ) / 2)) := by + funext t ω + simp only [Pi.smul_apply, smul_eq_mul] + rw [mul_left_comm, ← Real.exp_add] + congr 2 + ring + rw [heq] + exact (IsFilteredPreBrownian.waldExponential_isMartingale σ).smul S_0 + +/-- **The discounted GBM is an equivalent martingale measure — with `Q = P`.** When `P` is the +risk-neutral measure (the driver `X` is a `P`-pre-Brownian), the discounted price `e^{−rt} S_t` is +already a `P`-martingale, so `P` is trivially its own EMM for it, at every horizon `T`: an instance +of the model-agnostic `IsEMM` frame at `F = ℝ`. (The physical-measure Girsanov EMM +`Q ≠ P` is a martingale measure only on `[0, T]`: `bs_discounted_isEMM`.) -/ +theorem discountedGBM_isEMM [IsProbabilityMeasure P] (S_0 r σ : ℝ) (T : ℝ≥0) : + IsEMM 𝓕 P + (fun (t : ℝ≥0) ω ↦ Real.exp (-r * t) * + (S_0 * Real.exp ((r - σ ^ 2 / 2) * t + σ * X t ω))) T P := + IsEMM.of_martingale (discountedGBM_isMartingale S_0 r σ) + Measure.AbsolutelyContinuous.rfl Measure.AbsolutelyContinuous.rfl T + +/-- **No simple-strategy arbitrage for the discounted GBM under its risk-neutral measure.** The +frame's forward FTAP (`isEMM_noArbitrageSimple`) applied to the EMM `discountedGBM_isEMM`: no simple +(piecewise-constant, predictable, bounded) strategy trading the discounted GBM up to `T` has gains +that are `P`-a.s. nonnegative and strictly positive on a `P`-non-null set. -/ +theorem discountedGBM_noArbitrageSimple [IsProbabilityMeasure P] (S_0 r σ : ℝ) (T : ℝ≥0) : + ContinuousMarket.NoArbitrageSimple 𝓕 P + (fun (t : ℝ≥0) ω ↦ Real.exp (-r * t) * + (S_0 * Real.exp ((r - σ ^ 2 / 2) * t + σ * X t ω))) T := + ContinuousMarket.isEMM_noArbitrageSimple (discountedGBM_isEMM S_0 r σ T) + +end MathFin diff --git a/LeanPool/MathFin/Pricing/FTAP/DalangMortonWillinger.lean b/LeanPool/MathFin/Pricing/FTAP/DalangMortonWillinger.lean new file mode 100644 index 0000000000..863b8abae5 --- /dev/null +++ b/LeanPool/MathFin/Pricing/FTAP/DalangMortonWillinger.lean @@ -0,0 +1,125 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.FTAP.DensityPasting +public import LeanPool.MathFin.Pricing.FTAP.NoArbitrageLocal + +/-! +# The Dalang–Morton–Willinger theorem, reduced to its conditional one-period core + +The multi-period fundamental theorem of asset pricing on a general probability space with +finitely many assets (`F = EuclideanSpace ℝ (Fin d)`; the reduction and pasting below use only that +`F` is an inner-product space) and a finite horizon: no arbitrage if and only if there is an +equivalent martingale measure. The standard proof (Föllmer–Schied, *Stochastic Finance*, §5.2; +Rogers 1994; Kabanov–Stricker 2001) has three steps. This file assembles the first two with the +third isolated as one precisely stated hypothesis. + +1. **Reduction** (`NoArbitrageLocal.lean`): multi-period no arbitrage is equivalent to no + arbitrage in each one-period market conditional on `𝓕 t` (`noArbitrage_iff_noArbitrageLocal`). +2. **Pasting** (`DensityPasting.lean`): one-period densities `Z t`, `t < T`, with + `P[Z t | 𝓕 t] = 1` and `P[Z t • S (t+1) | 𝓕 t] = S t` paste to the equivalent martingale + measure `P.withDensity (∏ Z t)` (`LocalEMMDensities.isEMM_pastedMeasure`). +3. **The conditional one-period FTAP** (not proved here): conditional no arbitrage at period `t` + produces such a density `Z t` (`HasOnePeriodDensity`). This is the one-period theorem + `OnePeriodVector.ftap_one_period_vector` (trivial `𝓕 t`) carried out conditionally on `𝓕 t` + for non-trivial `𝓕 t` on a general space; it needs a measurable selection of the one-period + equivalent martingale measure over `𝓕 t` (or closedness of the gains cone in `L⁰`). It is + the hypothesis `ConditionalOnePeriodFTAP` below. + +So what is proved is: **assuming** the conditional one-period FTAP for the price `S`, no arbitrage +is equivalent to the existence of an equivalent martingale measure, the measure being the +explicit product `pastedMeasure`. The forward direction (an equivalent martingale measure +precludes arbitrage) is `IsEMM.noArbitrage` and needs no hypothesis. The general-space +Dalang–Morton–Willinger theorem itself, with `ConditionalOnePeriodFTAP` proved rather than +assumed, remains open in this library (issue #313). + +## Main definitions + +* `HasOnePeriodDensity`: period `t` carries a one-period density (`IsOnePeriodDensity`, defined + in `DensityPasting.lean`). +* `ConditionalOnePeriodFTAP`: conditional no arbitrage at each period yields a one-period density. + +## Main results + +* `exists_isEMM_of_hasOnePeriodDensity`: one-period densities in every period give an equivalent + martingale measure. +* `exists_isEMM_of_noArbitrage_of_conditionalFTAP`: given `ConditionalOnePeriodFTAP`, no + arbitrage gives an equivalent martingale measure. +* `noArbitrage_iff_exists_isEMM`: given `ConditionalOnePeriodFTAP`, no arbitrage is equivalent + to the existence of an equivalent martingale measure. + +## References + +* [H. Föllmer and A. Schied, *Stochastic Finance: An Introduction in Discrete Time*][FollmerSchied], + §5.2 + +## Tags + +fundamental theorem of asset pricing, Dalang–Morton–Willinger, equivalent martingale measure, +no arbitrage, general probability space, conditional one-period market, JEL G13, MSC 91G20, +MSC 60G42 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory + +variable {Ω : Type*} {m0 : MeasurableSpace Ω} + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [CompleteSpace F] + {𝓕 : Filtration ℕ m0} {P : Measure Ω} {S : ℕ → Ω → F} + +/-- **Period `t` carries a one-period density** (`IsOnePeriodDensity`): there is a bounded, +positive, `𝓕 (t+1)`-measurable weight of conditional mean one making `S` a conditional martingale +over `(t, t+1]`. -/ +def HasOnePeriodDensity (𝓕 : Filtration ℕ m0) (P : Measure Ω) (S : ℕ → Ω → F) (t : ℕ) : Prop := + ∃ Z : Ω → ℝ, IsOnePeriodDensity 𝓕 P S t Z + +/-- **The conditional one-period FTAP** for the price `S` up to the horizon `T`, as a hypothesis: +conditional no arbitrage at period `t < T` (`NoArbitrageAt`) yields a one-period density +(`HasOnePeriodDensity`). It is the one remaining step of the Dalang–Morton–Willinger theorem on a +general probability space and is **not proved** in this library; it is the conditional version of +`OnePeriodVector.ftap_one_period_vector`, a theorem of the literature for a finite-dimensional `F` +and an adapted integrable price (Föllmer–Schied §5.2). -/ +def ConditionalOnePeriodFTAP (𝓕 : Filtration ℕ m0) (P : Measure Ω) (S : ℕ → Ω → F) + (T : ℕ) : Prop := + ∀ t < T, NoArbitrageAt 𝓕 P S t → HasOnePeriodDensity 𝓕 P S t + +variable [IsProbabilityMeasure P] {T : ℕ} + +/-- **One-period densities in every period give an equivalent martingale measure**: choosing a +density for each period `t < T` and pasting them (`LocalEMMDensities.isEMM_pastedMeasure`). -/ +theorem exists_isEMM_of_hasOnePeriodDensity + (hS : ∀ t ≤ T, StronglyMeasurable[𝓕 t] (S t)) (hint : ∀ t ≤ T, Integrable (S t) P) + (hd : ∀ t < T, HasOnePeriodDensity 𝓕 P S t) : ∃ Q, IsEMM 𝓕 P S T Q := by + choose! Z hZ using hd + exact ⟨pastedMeasure P Z T, (LocalEMMDensities.mk hS hint hZ).isEMM_pastedMeasure⟩ + +/-- **Dalang–Morton–Willinger, assuming the conditional one-period FTAP**: for an adapted +integrable price, if the conditional one-period FTAP holds (`ConditionalOnePeriodFTAP`) then no +arbitrage gives an equivalent martingale measure. The reduction +`noArbitrageLocal_of_noArbitrage` turns multi-period no arbitrage into conditional no arbitrage +in each period, the hypothesis produces a density per period, and pasting multiplies them. -/ +theorem exists_isEMM_of_noArbitrage_of_conditionalFTAP + (hS : ∀ t ≤ T, StronglyMeasurable[𝓕 t] (S t)) + (hint : ∀ t ≤ T, Integrable (S t) P) (hcond : ConditionalOnePeriodFTAP 𝓕 P S T) + (hNA : NoArbitrage 𝓕 P S T) : ∃ Q, IsEMM 𝓕 P S T Q := + exists_isEMM_of_hasOnePeriodDensity hS hint fun t ht ↦ + hcond t ht (noArbitrageLocal_of_noArbitrage hNA t ht) + +/-- **Dalang–Morton–Willinger, assuming the conditional one-period FTAP**: for an adapted +integrable price, if `ConditionalOnePeriodFTAP` holds then no arbitrage is equivalent to the +existence of an equivalent martingale measure. The converse is `IsEMM.noArbitrage`. -/ +theorem noArbitrage_iff_exists_isEMM (hS : ∀ t ≤ T, StronglyMeasurable[𝓕 t] (S t)) + (hint : ∀ t ≤ T, Integrable (S t) P) (hcond : ConditionalOnePeriodFTAP 𝓕 P S T) : + NoArbitrage 𝓕 P S T ↔ ∃ Q, IsEMM 𝓕 P S T Q := + ⟨exists_isEMM_of_noArbitrage_of_conditionalFTAP hS hint hcond, fun ⟨_, hQ⟩ ↦ hQ.noArbitrage⟩ + +end MathFin diff --git a/LeanPool/MathFin/Pricing/FTAP/DensityPasting.lean b/LeanPool/MathFin/Pricing/FTAP/DensityPasting.lean new file mode 100644 index 0000000000..48b0a88ccb --- /dev/null +++ b/LeanPool/MathFin/Pricing/FTAP/DensityPasting.lean @@ -0,0 +1,349 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.EquivMartingaleMeasure +public import LeanPool.MathFin.Pricing.FTAP.FTAP + +/-! +# Pasting one-period densities into an equivalent martingale measure + +The pasting step of the Dalang–Morton–Willinger theorem. Let `S` be an adapted, integrable +`F`-valued discounted price on a filtered probability space `(Ω, 𝓕, P)` with finite horizon `T`, +and suppose each period `t < T` carries a *one-period density* `Z t`: an `𝓕 (t+1)`-measurable, +strictly positive, bounded weight with `P[Z t | 𝓕 t] = 1` that makes `S` a conditional martingale +over that period, `P[Z t • S (t+1) | 𝓕 t] = S t` (`IsOnePeriodDensity`, bundled over the periods +as `LocalEMMDensities`). Then the measure +`Q = P.withDensity (∏_{t simp [hω] + +namespace LocalEMMDensities + +variable (h : LocalEMMDensities 𝓕 P S T Z) + +omit [CompleteSpace F] in +include h in +lemma stronglyMeasurable_pasted (n : ℕ) (hn : n ≤ T) : + StronglyMeasurable[𝓕 n] (pastedDensity Z n) := by + induction n with + | zero => + have e : pastedDensity Z 0 = fun _ ↦ (1 : ℝ) := funext pastedDensity_zero + rw [e] + exact stronglyMeasurable_const + | succ n ih => + have hnT : n < T := Nat.lt_of_succ_le hn + have e : pastedDensity Z (n + 1) = pastedDensity Z n * Z n := funext (pastedDensity_succ n) + rw [e] + exact ((ih hnT.le).mono (𝓕.mono n.le_succ)).mul (h.density n hnT).meas + +omit [CompleteSpace F] in +include h in +lemma pastedDensity_pos {n : ℕ} (hn : n ≤ T) (ω : Ω) : 0 < pastedDensity Z n ω := + Finset.prod_pos fun s hs ↦ (h.density s (lt_of_lt_of_le (Finset.mem_range.1 hs) hn)).pos ω + +omit [CompleteSpace F] in +include h in +lemma exists_bound_pasted (n : ℕ) (hn : n ≤ T) : ∃ C : ℝ, ∀ ω, pastedDensity Z n ω ≤ C := by + induction n with + | zero => + exact ⟨1, fun ω ↦ (pastedDensity_zero ω).le⟩ + | succ n ih => + have hnT : n < T := Nat.lt_of_succ_le hn + obtain ⟨C, hC⟩ := ih hnT.le + obtain ⟨B, hB⟩ := (h.density n hnT).bdd + refine ⟨C * B, fun ω ↦ ?_⟩ + rw [pastedDensity_succ] + exact mul_le_mul (hC ω) (hB ω) ((h.density n hnT).pos ω).le + ((h.pastedDensity_pos hnT.le ω).le.trans (hC ω)) + +omit [CompleteSpace F] in +include h in +lemma measurable_pasted {n : ℕ} (hn : n ≤ T) : Measurable (pastedDensity Z n) := + ((h.stronglyMeasurable_pasted n hn).mono (𝓕.le n)).measurable + +omit [CompleteSpace F] in +include h in +lemma measurable_Z {t : ℕ} (ht : t < T) : Measurable (Z t) := + ((h.density t ht).meas.mono (𝓕.le (t + 1))).measurable + +omit [CompleteSpace F] [CompleteSpace E] in +include h in +lemma integrable_smul_pasted {n : ℕ} (hn : n ≤ T) {Y : Ω → E} (hY : Integrable Y P) : + Integrable (fun ω ↦ pastedDensity Z n ω • Y ω) P := by + obtain ⟨C, hC⟩ := h.exists_bound_pasted n hn + exact integrable_smul_of_bdd (h.measurable_pasted hn).aestronglyMeasurable + (fun ω ↦ (h.pastedDensity_pos hn ω).le) C hC hY + +omit [CompleteSpace F] [CompleteSpace E] in +include h in +lemma integrable_smul_Z {t : ℕ} (ht : t < T) {Y : Ω → E} (hY : Integrable Y P) : + Integrable (fun ω ↦ Z t ω • Y ω) P := by + obtain ⟨C, hC⟩ := (h.density t ht).bdd + exact integrable_smul_of_bdd (h.measurable_Z ht).aestronglyMeasurable + (fun ω ↦ ((h.density t ht).pos ω).le) C hC hY + +section Probability + +variable [IsProbabilityMeasure P] + +omit [CompleteSpace F] in +include h in +lemma integrable_Z {t : ℕ} (ht : t < T) : Integrable (Z t) P := by + obtain ⟨C, hC⟩ := (h.density t ht).bdd + exact Integrable.of_bound (h.measurable_Z ht).aestronglyMeasurable C + (ae_of_all _ fun ω ↦ (Real.norm_of_nonneg ((h.density t ht).pos ω).le).le.trans (hC ω)) + +omit [CompleteSpace F] in +include h in +/-- **Peeling one density factor**: against an `𝓕 t`-measurable integrable `g`, the period-`t` +density integrates as if it were `1`, since `P[Z t | 𝓕 t] = 1`. -/ +lemma integral_smul_cond {t : ℕ} (ht : t < T) {g : Ω → E} (hg : StronglyMeasurable[𝓕 t] g) + (hgi : Integrable g P) : ∫ ω, Z t ω • g ω ∂P = ∫ ω, g ω ∂P := by + have hZg : Integrable (Z t • g) P := h.integrable_smul_Z ht hgi + have e : P[Z t • g | 𝓕 t] =ᵐ[P] P[Z t | 𝓕 t] • g := + condExp_smul_of_aestronglyMeasurable_right (h.integrable_Z ht) hZg hg.aestronglyMeasurable + calc ∫ ω, Z t ω • g ω ∂P = ∫ ω, (P[Z t • g | 𝓕 t]) ω ∂P := (integral_condExp (𝓕.le t)).symm + _ = ∫ ω, (P[Z t | 𝓕 t] • g) ω ∂P := integral_congr_ae e + _ = ∫ ω, g ω ∂P := by + refine integral_congr_ae ?_ + filter_upwards [(h.density t ht).cond_one] with ω hω + simp [hω] + +omit [CompleteSpace F] in +include h in +/-- **Tower property of the product density**: for `n ≤ m ≤ T` and an `𝓕 n`-measurable +integrable `Y`, `∫ D m • Y = ∫ D n • Y`. -/ +lemma integral_pasted_eq {n m : ℕ} (hnm : n ≤ m) (hmT : m ≤ T) {Y : Ω → E} + (hY : StronglyMeasurable[𝓕 n] Y) (hYi : Integrable Y P) : + ∫ ω, pastedDensity Z m ω • Y ω ∂P = ∫ ω, pastedDensity Z n ω • Y ω ∂P := by + induction m, hnm using Nat.le_induction with + | base => rfl + | succ m hnm ih => + have hmlt : m < T := Nat.lt_of_succ_le hmT + have hg : StronglyMeasurable[𝓕 m] (fun ω ↦ pastedDensity Z m ω • Y ω) := + (h.stronglyMeasurable_pasted m hmlt.le).smul (hY.mono (𝓕.mono hnm)) + have hgi : Integrable (fun ω ↦ pastedDensity Z m ω • Y ω) P := + h.integrable_smul_pasted hmlt.le hYi + have e (ω : Ω) : pastedDensity Z (m + 1) ω • Y ω = + Z m ω • (pastedDensity Z m ω • Y ω) := by + rw [pastedDensity_succ, mul_comm, mul_smul] + simp_rw [e] + exact (h.integral_smul_cond hmlt hg hgi).trans (ih hmlt.le) + +omit [CompleteSpace F] in +include h in +/-- The **total mass** of the product density is `1`. -/ +lemma integral_pasted_eq_one : ∫ ω, pastedDensity Z T ω ∂P = 1 := by + have := h.integral_pasted_eq (E := ℝ) (Nat.zero_le T) le_rfl (Y := fun _ ↦ (1 : ℝ)) + stronglyMeasurable_const (integrable_const 1) + simpa [pastedDensity_zero] using this + +omit [CompleteSpace F] [CompleteSpace E] [IsProbabilityMeasure P] in +include h in +/-- **Change of measure to the pasted measure**: over a measurable set the `pastedMeasure` +integral of `g` is the `P`-integral of `D T • g`. -/ +lemma setIntegral_pastedMeasure {A : Set Ω} (hA : MeasurableSet A) (g : Ω → E) : + ∫ ω in A, g ω ∂(pastedMeasure P Z T) = ∫ ω in A, pastedDensity Z T ω • g ω ∂P := by + unfold pastedMeasure + rw [setIntegral_withDensity_eq_setIntegral_toReal_smul + (h.measurable_pasted le_rfl).ennreal_ofReal + (ae_of_all _ fun _ ↦ ENNReal.ofReal_lt_top) g hA] + refine setIntegral_congr_ae hA (ae_of_all _ fun ω _ ↦ ?_) + simp only [ENNReal.toReal_ofReal (h.pastedDensity_pos le_rfl ω).le] + +include h in +/-- **The one-period step of the martingale property**: for `A ∈ 𝓕 t`, `t < T`, the +`D T`-weighted integrals of `S (t+1)` and `S t` over `A` agree. The weight is peeled down to +`D (t+1)` on `S (t+1)` and to `D t` on `S t`; between them lies the one-period identity +`P[Z t • S (t+1) | 𝓕 t] = S t`. -/ +lemma setIntegral_pasted_step {t : ℕ} (ht : t < T) {A : Set Ω} (hA : MeasurableSet[𝓕 t] A) : + ∫ ω in A, pastedDensity Z T ω • S (t + 1) ω ∂P = ∫ ω in A, pastedDensity Z T ω • S t ω ∂P := by + have hAm : MeasurableSet A := 𝓕.le t A hA + have hA1 : MeasurableSet[𝓕 (t + 1)] A := 𝓕.mono t.le_succ A hA + have hS1 : StronglyMeasurable[𝓕 (t + 1)] (A.indicator (S (t + 1))) := + (h.adapted (t + 1) (Nat.succ_le_of_lt ht)).indicator hA1 + have hS1i : Integrable (A.indicator (S (t + 1))) P := + (h.integrable (t + 1) (Nat.succ_le_of_lt ht)).indicator hAm + have hS0 : StronglyMeasurable[𝓕 t] (A.indicator (S t)) := + (h.adapted t ht.le).indicator hA + have hS0i : Integrable (A.indicator (S t)) P := (h.integrable t ht.le).indicator hAm + -- the weight `D T` on `S (t+1)` is peeled down to `D (t+1)` + have hL : ∫ ω in A, pastedDensity Z T ω • S (t + 1) ω ∂P = + ∫ ω in A, pastedDensity Z (t + 1) ω • S (t + 1) ω ∂P := by + rw [setIntegral_smul_eq_integral_indicator hAm (pastedDensity Z T) (S (t + 1)), + setIntegral_smul_eq_integral_indicator hAm (pastedDensity Z (t + 1)) (S (t + 1))] + exact h.integral_pasted_eq (Nat.succ_le_of_lt ht) le_rfl hS1 hS1i + -- the weight `D T` on `S t` is peeled down to `D t` + have hR : ∫ ω in A, pastedDensity Z T ω • S t ω ∂P = + ∫ ω in A, pastedDensity Z t ω • S t ω ∂P := by + rw [setIntegral_smul_eq_integral_indicator hAm (pastedDensity Z T) (S t), + setIntegral_smul_eq_integral_indicator hAm (pastedDensity Z t) (S t)] + exact h.integral_pasted_eq ht.le le_rfl hS0 hS0i + -- the one-period identity + have hint : Integrable (pastedDensity Z t • (Z t • S (t + 1))) P := + h.integrable_smul_pasted ht.le (h.integrable_smul_Z ht (h.integrable (t + 1) + (Nat.succ_le_of_lt ht))) + have e1 : P[pastedDensity Z t • (Z t • S (t + 1)) | 𝓕 t] =ᵐ[P] + pastedDensity Z t • P[Z t • S (t + 1) | 𝓕 t] := + condExp_smul_of_aestronglyMeasurable_left + (h.stronglyMeasurable_pasted t ht.le).aestronglyMeasurable hint + (h.integrable_smul_Z ht (h.integrable (t + 1) (Nat.succ_le_of_lt ht))) + have e2 : pastedDensity Z t • P[Z t • S (t + 1) | 𝓕 t] =ᵐ[P] pastedDensity Z t • S t := by + filter_upwards [(h.density t ht).cond_price] with ω hω + exact congrArg (fun x ↦ pastedDensity Z t ω • x) hω + have hM : ∫ ω in A, pastedDensity Z (t + 1) ω • S (t + 1) ω ∂P = + ∫ ω in A, pastedDensity Z t ω • S t ω ∂P := by + calc ∫ ω in A, pastedDensity Z (t + 1) ω • S (t + 1) ω ∂P + = ∫ ω in A, (pastedDensity Z t • (Z t • S (t + 1))) ω ∂P := by + refine setIntegral_congr_ae hAm (ae_of_all _ fun ω _ ↦ ?_) + change pastedDensity Z (t + 1) ω • S (t + 1) ω = + pastedDensity Z t ω • (Z t ω • S (t + 1) ω) + rw [pastedDensity_succ, mul_smul] + _ = ∫ ω in A, (P[pastedDensity Z t • (Z t • S (t + 1)) | 𝓕 t]) ω ∂P := + (setIntegral_condExp (𝓕.le t) hint hA).symm + _ = ∫ ω in A, pastedDensity Z t ω • S t ω ∂P := + setIntegral_congr_ae hAm ((e1.trans e2).mono fun ω hω _ ↦ hω) + rw [hL, hM, hR] + +include h in +/-- **The pasted measure is an equivalent martingale measure.** Given one-period densities +`Z t`, `t < T`, for an adapted integrable price `S` (`LocalEMMDensities`), the measure +`P.withDensity (∏_{t simp [hω]⟩ + exact ⟨x, _, martingaleTransform_mem_tradedGains hpred hbdd, hrep⟩ + +end IsEMM + +end MathFin diff --git a/LeanPool/MathFin/Pricing/FTAP/FTAPComplete.lean b/LeanPool/MathFin/Pricing/FTAP/FTAPComplete.lean new file mode 100644 index 0000000000..d552e103b1 --- /dev/null +++ b/LeanPool/MathFin/Pricing/FTAP/FTAPComplete.lean @@ -0,0 +1,130 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.FTAP.FTAPDiscrete + +/-! +# Second FTAP on a finite probability space: complete ↔ unique equivalent martingale measure + +This is the finite-state, single-asset case of Föllmer and Schied's completeness theorem. +For the finite-Ω, finite-horizon market of `FTAPDiscrete.lean` (a full-support +probability `P`, an adapted discounted price `S`, a horizon `T`), a market with no arbitrage and +full information at the horizon (`𝓕 T = ⊤`) is **complete** (`IsCompleteMarket`: every claim is +the terminal wealth of a predictable strategy started from some initial wealth) **iff** its +equivalent martingale measure is **unique**. + +* `complete ⇒ unique` is general (`IsEMM.measure_eq_of_isCompleteMarket`, `Pricing/FTAP/FTAP.lean`): + replicate the indicator of an event and read off its probability. +* `unique ⇒ complete` is the geometric half, by contraposition. The claims replicable from some + wealth are `constants ⊔ gainsSubspace`. If that subspace is proper, a nonzero functional `η` + vanishes on it, i.e. `∑ η = 0` and `η` annihilates every gain. Perturbing the strictly positive + weights of an equivalent martingale measure `Q₀` by a small multiple of `η` keeps them strictly + positive and still annihilating, so they build a second equivalent martingale measure + (`exists_isEMM_of_pos_dual`), different from `Q₀` because `η ≠ 0`. + +## Main results + +* `isCompleteMarket_of_unique` — a unique equivalent martingale measure makes the market complete. +* `ftap_two` — under no arbitrage, and with full information `𝓕 T = ⊤` at the horizon, the market + is complete iff the equivalent martingale measure is unique. + +## References + +* [H. Föllmer and A. Schied, *Stochastic Finance: An Introduction in Discrete Time*][FollmerSchied], + 3rd revised and extended edition, §5.4, Theorem 5.37. +* [J. M. Harrison and S. R. Pliska, *Martingales and stochastic integrals in the theory of + continuous trading*][HarrisonPliska1981] + +## Tags + +second fundamental theorem, market completeness, unique martingale measure, replication, +finite probability space, JEL G13, MSC 91G20 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory + +variable {Ω : Type*} [Fintype Ω] {mΩ : MeasurableSpace Ω} + [MeasurableSingletonClass Ω] (𝓕 : Filtration ℕ mΩ) (P : Measure Ω) (S : ℕ → Ω → ℝ) (T : ℕ) + +variable {𝓕 P S T} in +/-- **Gains are a fair game under an equivalent martingale measure**: every element of the +attainable-gains subspace has `Q`-mean zero. -/ +theorem IsEMM.sum_mul_eq_zero_of_mem_gainsSubspace {Q : Measure Ω} (hQ : IsEMM 𝓕 P S T Q) + {g : Ω → ℝ} (hg : g ∈ gainsSubspace 𝓕 S T) : ∑ ω, Q.real {ω} * g ω = 0 := by + have := hQ.isProb + obtain ⟨φ, hφ, rfl⟩ := mem_gains_imp_predictable 𝓕 S T hg + have h := hQ.integral_martingaleTransform (fun t _ ↦ hφ t) (exists_bound_horizon T φ) + rw [integral_fintype Integrable.of_finite] at h + simpa using h + +omit [Fintype Ω] in +/-- **Second FTAP, `unique ⇒ complete`**: if the market has an equivalent martingale measure and +only one, every claim is replicated by a predictable strategy from some initial wealth. -/ +theorem isCompleteMarket_of_unique [Finite Ω] [Nonempty Ω] (hS : StronglyAdapted 𝓕 S) + (hP : ∀ ω, 0 < P {ω}) + {Q₀ : Measure Ω} (h₀ : IsEMM 𝓕 P S T Q₀) (hu : ∀ Q, IsEMM 𝓕 P S T Q → Q = Q₀) : + IsCompleteMarket 𝓕 P S T := by + classical + cases nonempty_fintype Ω + have := h₀.isProb + have hW : Submodule.span ℝ {fun _ : Ω ↦ (1 : ℝ)} ⊔ gainsSubspace 𝓕 S T = ⊤ := by + by_contra hne + obtain ⟨η, hη0, hη⟩ := exists_ne_zero_sum_mul_eq_zero (lt_top_iff_ne_top.2 hne) + have hsum : ∑ ω, η ω = 0 := by + simpa using hη _ (Submodule.mem_sup_left (Submodule.subset_span rfl)) + -- the weights of `Q₀` + set p : Ω → ℝ := fun ω ↦ Q₀.real {ω} + have hp_pos (ω : Ω) : 0 < p ω := + ENNReal.toReal_pos (fun h ↦ (hP ω).ne' (h₀.ac' h)) (measure_ne_top _ _) + have hp_sum : ∑ ω, p ω = 1 := by simp [p] + -- a small perturbation of the weights in the direction `η` keeps them positive + obtain ⟨ε, hεpos, hq_pos⟩ := exists_pos_add_mul_pos hp_pos η + have hq_dual (g : Ω → ℝ) (hg : g ∈ gainsSubspace 𝓕 S T) : + ∑ ω, (p ω + ε * η ω) * g ω = 0 := by + have : ∑ ω, (p ω + ε * η ω) * g ω = ∑ ω, p ω * g ω + ε * ∑ ω, g ω * η ω := by + rw [Finset.mul_sum, ← Finset.sum_add_distrib] + exact Finset.sum_congr rfl fun ω _ ↦ by ring + rw [this, h₀.sum_mul_eq_zero_of_mem_gainsSubspace hg, hη g (Submodule.mem_sup_right hg)] + simp + obtain ⟨Q', hQ', hQ's⟩ := exists_isEMM_of_pos_dual 𝓕 P S T hS hP hq_pos hq_dual + have hZ : ∑ ω, (p ω + ε * η ω) = 1 := by + rw [Finset.sum_add_distrib, ← Finset.mul_sum, hsum, hp_sum] + simp + refine hη0 (funext fun ω ↦ ?_) + have h2 := hQ's ω + rw [hZ, div_one, hu Q' hQ'] at h2 + have h3 : p ω + ε * η ω = p ω := + (ENNReal.ofReal_eq_ofReal_iff (hq_pos ω).le (hp_pos ω).le).1 + (h2.symm.trans (ENNReal.ofReal_toReal (measure_ne_top _ _)).symm) + exact (mul_eq_zero.1 (by linarith : ε * η ω = 0)).resolve_left hεpos.ne' + intro H _ _ + obtain ⟨y, hy, g, hg, rfl⟩ := Submodule.mem_sup.1 (hW ▸ Submodule.mem_top : H ∈ _) + obtain ⟨x, rfl⟩ := Submodule.mem_span_singleton.1 hy + obtain ⟨φ, hφ, rfl⟩ := mem_gains_imp_predictable 𝓕 S T hg + exact ⟨x, φ, fun t _ ↦ hφ t, exists_bound_horizon T φ, + Filter.Eventually.of_forall fun ω ↦ by simp⟩ + +omit [Fintype Ω] in +/-- **The Second Fundamental Theorem of Asset Pricing on a finite probability space.** For a +single-asset, finite-horizon market on a finite full-support space with no arbitrage and full +information at the horizon (`𝓕 T = ⊤`), the market is complete iff its equivalent martingale +measure is unique. -/ +theorem ftap_two [Finite Ω] [Nonempty Ω] (hS : StronglyAdapted 𝓕 S) (hP : ∀ ω, 0 < P {ω}) + (hT : 𝓕 T = mΩ) + (hNA : NoArbitrage 𝓕 P S T) : IsCompleteMarket 𝓕 P S T ↔ ∃! Q, IsEMM 𝓕 P S T Q := by + refine ⟨fun hc ↦ ?_, fun ⟨Q₀, h₀, hu⟩ ↦ isCompleteMarket_of_unique 𝓕 P S T hS hP h₀ hu⟩ + obtain ⟨Q₀, h₀⟩ := exists_isEMM_of_noArbitrage 𝓕 P S T hS hP hNA + exact ⟨Q₀, h₀, fun Q hQ ↦ Measure.ext fun A hA ↦ + hQ.measure_eq_of_isCompleteMarket hc h₀ (by rw [hT]; exact hA)⟩ + +end MathFin diff --git a/LeanPool/MathFin/Pricing/FTAP/FTAPDiscrete.lean b/LeanPool/MathFin/Pricing/FTAP/FTAPDiscrete.lean new file mode 100644 index 0000000000..23aa20182a --- /dev/null +++ b/LeanPool/MathFin/Pricing/FTAP/FTAPDiscrete.lean @@ -0,0 +1,391 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.Duality.ConvexSeparation +public import LeanPool.MathFin.Pricing.FTAP.FTAPOnePeriod +public import Mathlib.Algebra.Order.Archimedean.Real.Hom +public import Mathlib.Probability.ProbabilityMassFunction.Integrals + +/-! +# Discrete-time FTAP on a finite probability space (scalar, finite horizon) + +The finite-Ω, finite-horizon, single-asset **Fundamental Theorem of Asset +Pricing** (Harrison–Pliska / the finite case of Dalang–Morton–Willinger): a +market has **no arbitrage** iff it admits an **equivalent martingale measure**. + +The discounted price `S : ℕ → Ω → ℝ` is adapted to a filtration `𝓕` on a finite +probability space `(Ω, P)` with full support; a trading strategy `φ` is +predictable (`φ (n+1)` is `𝓕 n`-measurable) and its discounted gains are the +martingale transform `martingaleTransform φ S`. + +The backward direction is the geometric heart of the theorem: the attainable +gains span a subspace of `Ω → ℝ` that, under no arbitrage, misses the standard +simplex, so the separating-dual kernel `exists_pos_dual_of_disjoint_stdSimplex` +(`Pricing/Duality/ConvexSeparation.lean`) produces a strictly-positive pricing +functional — the EMM. The forward direction is `MathFin.IsEMM.noArbitrage` +(`Pricing/FTAP/FTAP.lean`, +where `IsEMM` and `NoArbitrage` are defined for a general space and `F`-valued price), shared with +the one-period market. + +## Scope + +Finite Ω, one scalar discounted asset, finite horizon `T`. The general-Ω DMW +theorem (which needs L⁰-closedness under no arbitrage and measurable selection) +and the `d`-asset generalisation are out of scope here. + +## Relation to the other EMM notions + +* **One period.** At horizon `1` with trivial initial information `𝓕 0 = ⊥`, the time-`0` + price and the time-`1` holding are constants, and this market is the one-period market of + `Pricing/FTAP/FTAPOnePeriod.lean` for the increment `Y = S 1 − S 0`: the EMMs coincide + (`isEMM_one_iff_onePeriod`) and so do the no-arbitrage conditions + (`noArbitrage_one_iff_onePeriod`). +* **Continuous time.** `IsEMM` is one notion for every time index + (`Pricing/EquivMartingaleMeasure.lean`); at time `ℝ≥0`, on a general Ω, it restricts in one + direction: sampled along any monotone schedule inside `[0, T]`, a continuous-time EMM is an + EMM here for the sampled price and filtration (`IsEMM.sampled`, in `ContinuousMarket.lean`, + general Ω, though `ftap_discrete` itself needs finite Ω), and at any time index it is a + one-period EMM for every increment `S t − S s` with `s, t ≤ T` (`IsEMM.increment`). The + converses are not claimed: neither restriction sees adaptedness of `S` at all times or the + martingale property between arbitrary times. + +## Main definitions + +* `incrementIndicator`: `𝟙_A · (S_{t+1} − S_t)`, the discounted gain of holding one unit on the + event `A` over period `t + 1`. +* `gainsSubspace`: the span in `Ω → ℝ` of the increment-indicators over `t < T` and + `𝓕_t`-measurable events `A`; each of its elements is the gain of some predictable strategy + (`mem_gains_imp_predictable`). + +## Main results + +* `MathFin.ftap_discrete` — the biconditional `NoArbitrage ↔ ∃ Q, IsEMM Q` (`NoArbitrage` in + `Pricing/FTAP/FTAP.lean`, `IsEMM` in `Pricing/EquivMartingaleMeasure.lean`), for a finite + `Ω` with `P {ω} > 0` and an adapted price `S` +* `MathFin.isEMM_one_iff_onePeriod`, `MathFin.noArbitrage_one_iff_onePeriod` +* `MathFin.IsEMM.increment` + +## References + +* [H. Föllmer and A. Schied, *Stochastic Finance: An Introduction in Discrete Time*][FollmerSchied], + §1.2 and §5.2 +* [J. M. Harrison and S. R. Pliska, *Martingales and stochastic integrals in the theory of + continuous trading*][HarrisonPliska1981] +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], §5.4 + +## Tags + +fundamental theorem of asset pricing, Harrison–Pliska, Dalang–Morton–Willinger, no arbitrage, +equivalent martingale measure, finite state space, JEL G13, MSC 91G20, MSC 60G42 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory + +-- Heterogeneous use of one rich `variable` context: the algebraic transform +-- lemmas need only `S`, and several theorems do not touch +-- `MeasurableSingletonClass`/`IsProbabilityMeasure` (`Nonempty` is stated where an EMM is built). +-- Five scattered +-- `omit … in` clauses would be noisier than a single suppression, so we disable +-- the unused-section-variable linter file-wide (deliberate, localized). + +/-- On a finite space every strategy is bounded on the horizon. -/ +lemma exists_bound_horizon {Ω : Type*} [Finite Ω] (N : ℕ) (φ : ℕ → Ω → ℝ) : + ∃ K : ℝ, ∀ n ≤ N, ∀ ω, ‖φ n ω‖ ≤ K := by + cases nonempty_fintype Ω + exact ⟨∑ n ∈ Finset.range (N + 1), ∑ ω', |φ n ω'|, fun n hn ω ↦ by + rw [Real.norm_eq_abs] + exact (Finset.single_le_sum (f := fun ω' ↦ |φ n ω'|) (fun _ _ ↦ abs_nonneg _) + (Finset.mem_univ ω)).trans + (Finset.single_le_sum (f := fun n ↦ ∑ ω', |φ n ω'|) + (fun _ _ ↦ Finset.sum_nonneg fun _ _ ↦ abs_nonneg _) + (Finset.mem_range.mpr (Nat.lt_succ_of_le hn)))⟩ + +variable {Ω : Type*} [Fintype Ω] {mΩ : MeasurableSpace Ω} + [MeasurableSingletonClass Ω] (𝓕 : Filtration ℕ mΩ) + (P : Measure Ω) [IsProbabilityMeasure P] (S : ℕ → Ω → ℝ) (T : ℕ) + +omit [Fintype Ω] [MeasurableSingletonClass Ω] in +/-- On a full-support measure a null set is empty — hence any two full-support +measures on `Ω` are mutually absolutely continuous. -/ +lemma eq_empty_of_pos_singleton {μ : Measure Ω} (hμ : ∀ ω, 0 < μ {ω}) + {s : Set Ω} (hs : μ s = 0) : s = ∅ := by + rw [← Set.not_nonempty_iff_eq_empty] + rintro ⟨ω, hω⟩ + exact absurd (hs ▸ measure_mono (Set.singleton_subset_iff.mpr hω) : μ {ω} ≤ 0) + (not_le.mpr (hμ ω)) + +/-- `𝟙_A · (S_{t+1} − S_t)` — the discounted gain of holding one unit on the +event `A` over period `t+1`. -/ +noncomputable def incrementIndicator (t : ℕ) (A : Set Ω) : Ω → ℝ := + fun ω ↦ A.indicator (fun _ ↦ (1 : ℝ)) ω * (S (t + 1) ω - S t ω) + +/-- The **attainable-gains subspace**: the span of the single-period +increment-indicators `𝟙_A · (S_{t+1} − S_t)` over `t < T` and `𝓕_t`-measurable +events `A`. Every element is the discounted gains of some predictable strategy +(see `mem_gains_imp_predictable`). -/ +noncomputable def gainsSubspace : Submodule ℝ (Ω → ℝ) := + Submodule.span ℝ + { g | ∃ t, t < T ∧ ∃ A : Set Ω, MeasurableSet[𝓕 t] A ∧ g = incrementIndicator S t A } + +omit [Fintype Ω] in +/-- The martingale transform is additive in the strategy. -/ +private lemma martingaleTransform_add (φ ψ : ℕ → Ω → ℝ) (n : ℕ) : + martingaleTransform (φ + ψ) S n + = martingaleTransform φ S n + martingaleTransform ψ S n := by + funext ω + simp only [martingaleTransform, Pi.add_apply, Real.inner_apply, add_mul, Finset.sum_add_distrib] + +omit [Fintype Ω] in +/-- The martingale transform is homogeneous in the strategy. -/ +private lemma martingaleTransform_smul (c : ℝ) (φ : ℕ → Ω → ℝ) (n : ℕ) : + martingaleTransform (c • φ) S n = c • martingaleTransform φ S n := by + funext ω + simp only [martingaleTransform, Pi.smul_apply, smul_eq_mul, Real.inner_apply, Finset.mul_sum] + exact Finset.sum_congr rfl fun k _ ↦ by ring + +omit [MeasurableSingletonClass Ω] [Fintype Ω] in +/-- Every element of the attainable-gains subspace is the discounted gains of a +predictable strategy. (`span`-induction: the generators are the gains of the +single-period indicator strategies, and predictable gains are closed under the +vector-space operations.) -/ +theorem mem_gains_imp_predictable {g : Ω → ℝ} (hg : g ∈ gainsSubspace 𝓕 S T) : + ∃ φ : ℕ → Ω → ℝ, + StronglyAdapted 𝓕 (fun n ↦ φ (n + 1)) ∧ martingaleTransform φ S T = g := by + induction hg using Submodule.span_induction with + | mem x hx => + obtain ⟨t, htT, A, hA, rfl⟩ := hx + refine ⟨fun s ↦ if s = t + 1 then A.indicator (fun _ ↦ (1 : ℝ)) else 0, ?_, ?_⟩ + · intro n + dsimp only + split_ifs with h + · have hnt : n = t := by omega + subst hnt + exact stronglyMeasurable_const.indicator hA + · exact stronglyMeasurable_const + · funext ω + simp only [martingaleTransform, Real.inner_apply] + rw [Finset.sum_eq_single t] + · simp [incrementIndicator] + · intro k _ hk + rw [ite_eq_right (by omega : ¬ k + 1 = t + 1)] + simp + · intro ht + exact absurd (Finset.mem_range.mpr htT) ht + | zero => exact ⟨0, fun _ ↦ stronglyMeasurable_const, by funext ω; simp [martingaleTransform]⟩ + | add x y _ _ ihx ihy => + obtain ⟨φ, hφ, hφeq⟩ := ihx + obtain ⟨ψ, hψ, hψeq⟩ := ihy + exact ⟨φ + ψ, fun n ↦ (hφ n).add (hψ n), + by rw [martingaleTransform_add, hφeq, hψeq]⟩ + | smul c x _ ih => + obtain ⟨φ, hφ, hφeq⟩ := ih + exact ⟨c • φ, fun n ↦ (hφ n).const_smul c, by rw [martingaleTransform_smul, hφeq]⟩ + +omit [IsProbabilityMeasure P] [MeasurableSingletonClass Ω] in +/-- Under no arbitrage, the attainable-gains subspace contains no probability vector (a +nonnegative `v` with `∑ ω, v ω = 1`): a nonnegative, nonzero gains vector would be an arbitrage. -/ +theorem gains_disjoint_stdSimplex (hP : ∀ ω, 0 < P {ω}) (hNA : NoArbitrage 𝓕 P S T) : + ∀ v : Ω → ℝ, (∀ ω, 0 ≤ v ω) → ∑ ω, v ω = 1 → v ∉ gainsSubspace 𝓕 S T := by + intro v hnn hsum hv + obtain ⟨φ, hφ, hφeq⟩ := mem_gains_imp_predictable 𝓕 S T hv + -- The gains are `≥ 0` (`v` is in the simplex), so no arbitrage forces them `= 0`. + have hge : 0 ≤ᵐ[P] martingaleTransform φ S T := by + rw [hφeq]; exact Filter.Eventually.of_forall hnn + have hzero : v =ᵐ[P] 0 := by + rw [← hφeq] + exact hNA φ (fun t _ ↦ hφ t) (exists_bound_horizon T φ) hge + -- But `∑ v = 1`, so some `v ω₀ > 0`, contradicting `v = 0` a.e. on full support. + obtain ⟨ω₀, hω₀⟩ : ∃ ω₀, 0 < v ω₀ := by + by_contra hcon + simp only [not_exists, not_lt] at hcon + have hle : ∑ ω, v ω ≤ 0 := Finset.sum_nonpos fun ω _ ↦ hcon ω + rw [hsum] at hle; linarith + have hnull : P {ω | v ω ≠ 0} = 0 := by simpa using ae_iff.mp hzero + have hmem : ω₀ ∈ {ω | v ω ≠ 0} := ne_of_gt hω₀ + rw [eq_empty_of_pos_singleton hP hnull] at hmem + simp at hmem + +omit [IsProbabilityMeasure P] in +/-- **The way a finite-space EMM is built**: strictly positive weights `q` annihilating the +attainable gains give, once normalised, an equivalent martingale measure `Q`, with +`Q {ω} = q ω / ∑ q`. Strict positivity gives `Q ~ P`, and the annihilation of every +increment-indicator gives the martingale property via the conditional-expectation +characterisation. -/ +theorem exists_isEMM_of_pos_dual [Nonempty Ω] (hS : StronglyAdapted 𝓕 S) + (hP : ∀ ω, 0 < P {ω}) {q : Ω → ℝ} (hq_pos : ∀ ω, 0 < q ω) + (hq_dual : ∀ v ∈ gainsSubspace 𝓕 S T, ∑ ω, q ω * v ω = 0) : + ∃ Q, IsEMM 𝓕 P S T Q ∧ ∀ ω, Q {ω} = ENNReal.ofReal (q ω / ∑ ω', q ω') := by + classical + set Z : ℝ := ∑ ω, q ω with hZ + have hZpos : 0 < Z := Finset.sum_pos (fun ω _ ↦ hq_pos ω) Finset.univ_nonempty + have hmnn : ∀ ω, (0 : ℝ) ≤ q ω / Z := fun ω ↦ (div_pos (hq_pos ω) hZpos).le + have hsum1 : ∑ ω, ENNReal.ofReal (q ω / Z) = 1 := by + rw [← ENNReal.ofReal_sum_of_nonneg (fun ω _ ↦ hmnn ω), ← Finset.sum_div, ← hZ, + div_self hZpos.ne', ENNReal.ofReal_one] + set Q : Measure Ω := (PMF.ofFintype (fun ω ↦ ENNReal.ofReal (q ω / Z)) hsum1).toMeasure + with hQdef + have hQprob : IsProbabilityMeasure Q := by rw [hQdef]; infer_instance + have hQsingle : ∀ ω, Q {ω} = ENNReal.ofReal (q ω / Z) := fun ω ↦ by + rw [hQdef, PMF.toMeasure_apply_singleton _ _ (measurableSet_singleton ω), PMF.ofFintype_apply] + have hQpos : ∀ ω, 0 < Q {ω} := fun ω ↦ by + rw [hQsingle ω]; exact ENNReal.ofReal_pos.mpr (div_pos (hq_pos ω) hZpos) + have hQint : ∀ h : Ω → ℝ, ∫ ω, h ω ∂Q = ∑ ω, (q ω / Z) * h ω := by + intro h + rw [hQdef, PMF.integral_eq_sum] + exact Finset.sum_congr rfl fun ω _ ↦ by + rw [PMF.ofFintype_apply, ENNReal.toReal_ofReal (hmnn ω), smul_eq_mul] + -- Full support ⇒ `P` and `Q` are mutually absolutely continuous. + have hQP : Q ≪ P := by + intro s hs; rw [eq_empty_of_pos_singleton hP hs]; exact measure_empty + have hPQ : P ≪ Q := by + intro s hs; rw [eq_empty_of_pos_singleton hQpos hs]; exact measure_empty + refine ⟨Q, .of_condExp_succ ⟨hQprob, hQP, hPQ⟩ (fun t _ ↦ hS t) (fun t _ ↦ Integrable.of_finite) + fun t htT ↦ ?_, hQsingle⟩ + -- Martingale property via the conditional-expectation characterisation. + refine ae_eq_condExp_of_forall_setIntegral_eq (𝓕.le t) Integrable.of_finite + (fun s _ _ ↦ Integrable.of_finite.integrableOn) (fun s hs _ ↦ ?_) + (hS t).aestronglyMeasurable + -- Key: `∫_s (S_{t+1} − S_t) dQ = 0` because the increment-indicator is annihilated. + have hsm : MeasurableSet s := 𝓕.le t s hs + have hinc_eq : s.indicator (fun ω ↦ S (t + 1) ω - S t ω) = incrementIndicator S t s := by + funext ω; simp only [incrementIndicator, Set.indicator_apply]; split_ifs <;> ring + have hkey : ∫ ω, s.indicator (fun ω ↦ S (t + 1) ω - S t ω) ω ∂Q = 0 := by + rw [hinc_eq, hQint] + have hdual := hq_dual (incrementIndicator S t s) + (Submodule.subset_span ⟨t, htT, s, hs, rfl⟩) + calc ∑ ω, (q ω / Z) * incrementIndicator S t s ω + = (∑ ω, q ω * incrementIndicator S t s ω) / Z := by + rw [Finset.sum_div]; exact Finset.sum_congr rfl fun ω _ ↦ by ring + _ = 0 := by rw [hdual, zero_div] + rw [integral_indicator hsm, + integral_sub Integrable.of_finite.integrableOn Integrable.of_finite.integrableOn] at hkey + linarith [hkey] + +omit [IsProbabilityMeasure P] [Fintype Ω] in +/-- **Backward direction**: no arbitrage ⟹ an equivalent martingale measure exists. The +separating dual `q` of the gains subspace (`exists_pos_dual_of_disjoint_stdSimplex`) is strictly +positive and annihilates the gains, so it builds the EMM (`exists_isEMM_of_pos_dual`). -/ +theorem exists_isEMM_of_noArbitrage [Finite Ω] [Nonempty Ω] (hS : StronglyAdapted 𝓕 S) + (hP : ∀ ω, 0 < P {ω}) (hNA : NoArbitrage 𝓕 P S T) : + ∃ Q, IsEMM 𝓕 P S T Q := by + cases nonempty_fintype Ω + obtain ⟨q, hq_pos, hq_dual⟩ := + exists_pos_dual_of_disjoint_stdSimplex (gainsSubspace 𝓕 S T) + (gains_disjoint_stdSimplex 𝓕 P S T hP hNA) + exact (exists_isEMM_of_pos_dual 𝓕 P S T hS hP hq_pos hq_dual).imp fun _ h ↦ h.1 + +omit [IsProbabilityMeasure P] [Fintype Ω] in +/-- **Finite-Ω Fundamental Theorem of Asset Pricing** (Harrison–Pliska; the +finite case of Dalang–Morton–Willinger): a finite-horizon, single-asset market +on a finite full-support probability space has no arbitrage **iff** it admits an +equivalent martingale measure. -/ +theorem ftap_discrete [Finite Ω] [Nonempty Ω] (hS : StronglyAdapted 𝓕 S) (hP : ∀ ω, 0 < P {ω}) : + NoArbitrage 𝓕 P S T ↔ ∃ Q, IsEMM 𝓕 P S T Q := + ⟨fun hNA ↦ exists_isEMM_of_noArbitrage 𝓕 P S T hS hP hNA, + fun ⟨_, hQ⟩ ↦ hQ.noArbitrage⟩ + +/-! ### Horizon one: the one-period market + +With trivial initial information `𝓕 0 = ⊥`, a `⊥`-measurable function is constant +(`stronglyMeasurable_bot_iff`): the time-`0` price is a number, the time-`1` holding is a +constant position, and `Q[· | ⊥]` is the plain expectation (`condExp_bot`). The one-step +market is then the one-period market of `Pricing/FTAP/FTAPOnePeriod.lean` for the increment +`S 1 − S 0`. -/ + +omit [IsProbabilityMeasure P] [Fintype Ω] in +/-- **At horizon `1` the discrete-time EMM is the one-period EMM.** With `𝓕 0 = ⊥` and `S` +adapted, `Q` is an equivalent martingale measure for the one-step market iff it is one for +the one-period excess return `S 1 − S 0`: the one-step martingale condition +`S 0 = E_Q[S 1]` (the price `S 0` being a constant) is `E_Q[S 1 − S 0] = 0`. -/ +theorem isEMM_one_iff_onePeriod [Finite Ω] (hS : StronglyAdapted 𝓕 S) (h0 : 𝓕 0 = ⊥) + {Q : Measure Ω} : + IsEMM 𝓕 P S 1 Q ↔ OnePeriod.IsEMM P (S 1 - S 0) Q := by + have hS0 : StronglyMeasurable[𝓕 0] (S 0) := hS 0 + rw [h0] at hS0 + obtain ⟨c, hc⟩ := stronglyMeasurable_bot_iff.mp hS0 + -- under a probability measure, the constant price `S 0 = c` has mean `c` + have hmean (μ : Measure Ω) [IsProbabilityMeasure μ] : ∫ ω, S 0 ω ∂μ = c := by simp [hc] + constructor + · intro hQ + have := hQ.isProb + have hm := (hQ.condExp_eq (Nat.zero_le 1) le_rfl).symm + rw [h0, condExp_bot, hc] at hm + obtain ⟨_, hcQ⟩ := hm.exists + refine ⟨hQ.toIsEquivProbMeasure, Integrable.of_finite, ?_⟩ + change ∫ ω, (S 1 ω - S 0 ω) ∂Q = 0 + rw [integral_sub Integrable.of_finite Integrable.of_finite, hmean Q] + exact sub_eq_zero.mpr hcQ.symm + · intro hQ + have := hQ.isProb + refine .of_condExp_succ hQ.toIsEquivProbMeasure (fun t _ ↦ hS t) + (fun t _ ↦ Integrable.of_finite) fun t ht ↦ ?_ + obtain rfl : t = 0 := by omega + rw [h0, condExp_bot, hc] + have hfair : ∫ ω, (S 1 ω - S 0 ω) ∂Q = 0 := hQ.fair + rw [integral_sub Integrable.of_finite Integrable.of_finite, hmean Q] at hfair + exact Filter.Eventually.of_forall fun _ ↦ (sub_eq_zero.mp hfair).symm + +omit [Fintype Ω] [MeasurableSingletonClass Ω] [IsProbabilityMeasure P] in +/-- **At horizon `1` discrete-time no arbitrage is one-period no arbitrage.** With +`𝓕 0 = ⊥`, a predictable strategy holds a constant `θ` over the single period, and its +discounted gain `martingaleTransform φ S 1` is `θ · (S 1 − S 0)`. -/ +theorem noArbitrage_one_iff_onePeriod (h0 : 𝓕 0 = ⊥) : + NoArbitrage 𝓕 P S 1 ↔ OnePeriod.NoArbitrage P (S 1 - S 0) := by + have hgain (φ : ℕ → Ω → ℝ) : + martingaleTransform φ S 1 = fun ω ↦ φ 1 ω * (S 1 - S 0) ω := by + funext ω; simp [martingaleTransform, mul_comm] + constructor + · intro hNA θ hθ + have h := hNA (fun _ _ ↦ θ) (fun _ _ ↦ stronglyMeasurable_const) ⟨|θ|, fun _ _ _ ↦ by simp⟩ + (by rw [hgain]; exact hθ) + rwa [hgain] at h + · intro hNA φ hφ _ hpos + have hφ1 : StronglyMeasurable[𝓕 0] (φ 1) := hφ 0 one_pos + rw [h0] at hφ1 + obtain ⟨θ, hθ⟩ := stronglyMeasurable_bot_iff.mp hφ1 + simp only [hgain φ, hθ] at hpos ⊢ + exact hNA θ hpos + +end MathFin + +/-! ### An EMM up to a horizon, restricted to one period + +An `IsEMM` up to a horizon (`Pricing/EquivMartingaleMeasure.lean`, for any time index) is a +process-level object on a general Ω. In continuous time it restricts to the discrete-time notion +(`IsEMM.sampled`, `ContinuousMarket.lean`), and at any time index to the one-period notion +(below); these restrictions are one-directional. -/ + +namespace MathFin + +open MeasureTheory ProbabilityTheory + +/-- **An EMM is a one-period EMM for every increment before the horizon.** If `Q` is an +equivalent martingale measure up to `T` for the discounted price `S`, then for any two dates `s`, +`t ≤ T` it is an equivalent martingale measure, in the sense of +`Pricing/FTAP/FTAPOnePeriodVector.lean`, for the one-period excess return `S t − S s` with a +constant holding: a martingale has the constant expectation of its first date. -/ +theorem IsEMM.increment {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + {ι : Type*} [LinearOrder ι] [OrderBot ι] {𝓕 : Filtration ι mΩ} + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [FiniteDimensional ℝ F] + {S : ι → Ω → F} {T : ι} {Q : Measure Ω} + (h : IsEMM 𝓕 P S T Q) {s t : ι} (hs : s ≤ T) (ht : t ≤ T) : + OnePeriodVector.IsEMM P (S t - S s) Q := by + have := h.isProb + have hmean {u : ι} (hu : u ≤ T) : ∫ ω, S u ω ∂Q = ∫ ω, S ⊥ ω ∂Q := by + rw [← integral_condExp (𝓕.le ⊥)] + exact integral_congr_ae (h.condExp_eq bot_le hu) + refine ⟨h.toIsEquivProbMeasure, (h.integrable ht).sub (h.integrable hs), ?_⟩ + change ∫ ω, (S t ω - S s ω) ∂Q = 0 + rw [integral_sub (h.integrable ht) (h.integrable hs), hmean ht, hmean hs, sub_self] + +end MathFin diff --git a/LeanPool/MathFin/Pricing/FTAP/FTAPOnePeriod.lean b/LeanPool/MathFin/Pricing/FTAP/FTAPOnePeriod.lean new file mode 100644 index 0000000000..95a89fa5c5 --- /dev/null +++ b/LeanPool/MathFin/Pricing/FTAP/FTAPOnePeriod.lean @@ -0,0 +1,104 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.FTAP.FTAPOnePeriodVector + +/-! +# One-period FTAP on a general probability space (scalar) + +The one-period Fundamental Theorem of Asset Pricing (Föllmer–Schied, *Stochastic Finance*, +§1.2; the one-period case of Dalang–Morton–Willinger) for a single scalar discounted excess +return `Y` on an **arbitrary** probability space `(Ω, P)`: no arbitrage ↔ there is an +equivalent martingale measure `Q ~ P` with `Y` integrable and `E_Q[Y] = 0`. + +`Y ∈ L⁰` here: it need not be bounded, and integrability is not free. + +## Relation to the vector and discrete-time theorems + +`IsEMM` is the vector notion `OnePeriodVector.IsEMM` at `F = ℝ`, and `NoArbitrage` is the +vector no-arbitrage condition at `F = ℝ` (`noArbitrage_iff_vector`: on `ℝ` the inner +product `⟪θ, y⟫` is `θ · y`). So `ftap_one_period` is a corollary of +`OnePeriodVector.ftap_one_period_vector` at `F = ℝ`, and carries no proof of its own: the +backward direction (the L¹ tempering and the logistic tilt) and the forward direction +(`MathFin.IsEMM.noArbitrage`) are proved once, in the vector file. On a finite space +with trivial initial information, the one-step market of `Pricing/FTAP/FTAPDiscrete.lean` is +this market for `Y = S 1 − S 0` (`isEMM_one_iff_onePeriod`, `noArbitrage_one_iff_onePeriod`). + +## Scope + +One trading period, **one scalar asset**, arbitrary `(Ω, P)`. The `d`-asset +generalisation is `Pricing/FTAP/FTAPOnePeriodVector.lean`; the general-Ω **multi-period** +Dalang–Morton–Willinger theorem (which glues one-period conditional markets and needs a +measurable selection theorem) is not formalised. + +## Main definitions + +* `NoArbitrage`: any scalar position `θ` whose gain `θ · Y` is `P`-a.e. nonnegative has + `θ · Y = 0` a.e. +* `IsEMM`: `Q ~ P`, `Y` is `Q`-integrable and `E_Q[Y] = 0`; the vector notion + `OnePeriodVector.IsEMM` at `F = ℝ`. + +## Main results + +* `MathFin.OnePeriod.ftap_one_period` +* `MathFin.OnePeriod.noArbitrage_iff_vector` + +## References + +* [H. Föllmer and A. Schied, *Stochastic Finance: An Introduction in Discrete Time*][FollmerSchied], + §1.2 + +## Tags + +fundamental theorem of asset pricing, one-period model, no arbitrage, Föllmer–Schied, +equivalent martingale measure, JEL G13, MSC 91G20 +-/ + +@[expose] public section + +namespace MathFin.OnePeriod + +open MeasureTheory + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} (P : Measure Ω) [IsProbabilityMeasure P] + (Y : Ω → ℝ) + +/-- **No arbitrage**: no scalar position `θ` turns zero wealth into a sure +non-loss with a chance of gain — any `θ` whose discounted gain `θ · Y` is `≥ 0` +a.e. already has `θ · Y = 0` a.e. -/ +def NoArbitrage : Prop := + ∀ θ : ℝ, 0 ≤ᵐ[P] (fun ω ↦ θ * Y ω) → (fun ω ↦ θ * Y ω) =ᵐ[P] 0 + +/-- **Equivalent martingale measure** (one period, scalar): `Q ~ P`, `Y` is `Q`-integrable, +and `E_Q[Y] = 0`. This is the library's one-period notion `OnePeriodVector.IsEMM` at +`F = ℝ`, with the same fields `toIsEquivProbMeasure` (`isProb`, `ac`, `ac'`), `int`, `fair`. -/ +abbrev IsEMM (Q : Measure Ω) : Prop := + OnePeriodVector.IsEMM P Y Q + +omit [IsProbabilityMeasure P] in +/-- **The scalar no-arbitrage condition is the vector one at `F = ℝ`.** On `ℝ` the inner +product `⟪θ, y⟫` is the product `θ · y`, so a scalar position `θ` with gain `θ · Y` is the +vector portfolio `θ ∈ ℝ`. With `IsEMM` defined as `OnePeriodVector.IsEMM` at `F = ℝ`, this +identifies `ftap_one_period` with `OnePeriodVector.ftap_one_period_vector` at `F = ℝ`. -/ +theorem noArbitrage_iff_vector : NoArbitrage P Y ↔ OnePeriodVector.NoArbitrage P Y := by + simp only [NoArbitrage, OnePeriodVector.NoArbitrage, Real.inner_apply] + +/-- **One-period Fundamental Theorem of Asset Pricing** (scalar, general `Ω`). +For a single measurable discounted excess return `Y` on an arbitrary probability +space, *no arbitrage* holds if and only if there exists an *equivalent martingale +measure*: a `Q ~ P` under which `Y` is integrable and `E_Q[Y] = 0`. This is the +Föllmer–Schied / one-period Dalang–Morton–Willinger theorem for one asset, the `F = ℝ` case +of `OnePeriodVector.ftap_one_period_vector`; on a finite space with trivial initial +information its EMM and no-arbitrage notions are those of the horizon-`1` market of +`Pricing/FTAP/FTAPDiscrete.lean` (`isEMM_one_iff_onePeriod`, `noArbitrage_one_iff_onePeriod`). -/ +theorem ftap_one_period (hY : Measurable Y) : + NoArbitrage P Y ↔ ∃ Q, IsEMM P Y Q := + (noArbitrage_iff_vector P Y).trans (OnePeriodVector.ftap_one_period_vector P Y hY) + +end MathFin.OnePeriod diff --git a/LeanPool/MathFin/Pricing/FTAP/FTAPOnePeriodVector.lean b/LeanPool/MathFin/Pricing/FTAP/FTAPOnePeriodVector.lean new file mode 100644 index 0000000000..ad09074a08 --- /dev/null +++ b/LeanPool/MathFin/Pricing/FTAP/FTAPOnePeriodVector.lean @@ -0,0 +1,695 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Martingales.EquivMeasure +public import LeanPool.MathFin.Pricing.FTAP.FTAP +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.Analysis.Calculus.ParametricIntegral +public import Mathlib.Analysis.LocallyConvex.AbsConvexOpen +public import Mathlib.MeasureTheory.Function.SpecialFunctions.Inner +public import Mathlib.Order.CompletePartialOrder +public import Mathlib.Analysis.SpecialFunctions.Log.Deriv + +/-! +# One-period FTAP on a general probability space (finite-dimensional market) + +The Föllmer–Schied / one-period Dalang–Morton–Willinger Fundamental Theorem of Asset +Pricing for a discounted excess return `Y : Ω → F` valued in a **finite-dimensional** +real inner-product space `F` (the `d`-asset market is `F = EuclideanSpace ℝ (Fin d)`) and +**constant** portfolios `θ ∈ F` (trivial initial information) on an **arbitrary** +probability space `(Ω, P)`: no arbitrage ↔ there is an equivalent martingale measure +`Q ~ P` with `Y` integrable and `E_Q[Y] = 0 ∈ F`. + +This is the `d`-asset generalisation of the scalar `Pricing/FTAP/FTAPOnePeriod.lean`, which is +its `F = ℝ` corollary and has no proofs of its own. The forward direction is +`MathFin.IsEMM.noArbitrage` (`Pricing/FTAP/FTAP.lean`) at horizon `1`. +Because `θ` ranges over the **finite-dimensional** `F`, the equivalent martingale measure +is **explicit**: the backward direction minimises the smooth convex softplus +potential `θ ↦ E[log(1 + exp⟪θ,Y⟫)]`. The +potential is constant along the **gains kernel** `N = {θ : ⟪θ,Y⟫ = 0 a.e.}` (the +redundant portfolio directions) and, under no arbitrage, coercive on its orthogonal +complement `Nᗮ`; so a minimiser `θ*` exists on `Nᗮ` and, because the potential is flat +along `N`, is a *global* minimiser. Its first-order condition `E[Y · σ(⟪θ*,Y⟫)] = 0` +(with `σ` the logistic function) hands back a strictly-positive bounded weight +`z = σ(⟪θ*,Y⟫)` whose normalisation `z / E[z]` is the EMM density: a bounded +`(0,1)`-valued logistic tilt, the softplus analogue of the exponential Esscher measure +rather than the Esscher measure itself. No Hahn–Banach, no L⁰-cone closedness, no +measurable selection; those are needed only for the general-Ω **multi-period** DMW. + +## Scope + +One trading period, a **finite-dimensional** market `F`, **trivial `ℱ₀`** (constant `θ`), +and an arbitrary `(Ω, P)`. **No non-redundancy hypothesis**: redundant assets (a `θ ≠ 0` +with `⟪θ,Y⟫ = 0` a.e.) are absorbed by minimising the potential over the gains kernel's +orthogonal complement, where coercivity is recovered. Out of scope (the remaining open +rung): the general-Ω **multi-period** DMW (predictable `L⁰(ℱ_t)`-strategies and the L⁰ +gains-cone closedness). + +## The one-period EMM of the library + +`IsEMM` here is the library's one notion of an equivalent martingale measure for a single +trading period. The other one-period encodings are proved equivalent to it, and the +continuous-time notion restricts to it: + +* the scalar `OnePeriod.IsEMM` (`Pricing/FTAP/FTAPOnePeriod.lean`) is defined as this notion + at `F = ℝ`, and its no-arbitrage condition is this one at `F = ℝ` + (`OnePeriod.noArbitrage_iff_vector`); +* the finite-state `HasEMMMultiState` (`Pricing/FTAP/FTAPMultiState.lean`) holds iff this + notion has a witness on `Ω = Fin N` with the asset returns as an `ℝᴹ`-valued `Y` + (`hasEMMMultiState_iff_exists_isEMM`); +* the discrete-time `MathFin.IsEMM` at horizon `1` with trivial `𝓕 0` + (`Pricing/FTAP/FTAPDiscrete.lean`) is the scalar one for `Y = S 1 − S 0` + (`isEMM_one_iff_onePeriod`); +* a continuous-time `IsEMM` gives this notion for every increment + `S t − S s` (`IsEMM.increment`, in `Pricing/FTAP/FTAPDiscrete.lean`). + +## Main definitions + +* `NoArbitrage`: any constant portfolio `θ ∈ F` whose gain `⟪θ, Y⟫` is `P`-a.e. nonnegative has + `⟪θ, Y⟫ = 0` a.e. +* `IsEMM`: `Q ~ P`, `Y` is `Q`-integrable and `E_Q[Y] = 0 ∈ F`. +* `gainsKernel`: the subspace `{θ : ⟪θ, Y⟫ = 0 a.e.}` of portfolios with a.e. zero gain. +* `softplus`, `logistic`: `log (1 + eᵘ)` and its derivative `eᵘ / (1 + eᵘ)`. +* `potential`: the softplus potential `θ ↦ ∫ softplus ⟪θ, Y⟫ ∂P`, whose minimiser's first-order + condition produces the equivalent martingale measure. + +## Main results + +* `MathFin.OnePeriodVector.ftap_one_period_vector` + +## References + +* [H. Föllmer and A. Schied, *Stochastic Finance: An Introduction in Discrete Time*][FollmerSchied], + §1.2 + +## Tags + +fundamental theorem of asset pricing, softplus potential, d-asset market, no arbitrage, +logistic tilt, Dalang–Morton–Willinger, JEL G13, MSC 91G20, MSC 90C25 +-/ + +@[expose] public section + +namespace MathFin.OnePeriodVector + +open MeasureTheory + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} (P : Measure Ω) [IsProbabilityMeasure P] + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [FiniteDimensional ℝ F] + [MeasurableSpace F] [BorelSpace F] (Y : Ω → F) + +/-- **No arbitrage** (finite-dim market, one period): no constant portfolio `θ ∈ F` turns +zero cost into a sure non-negative discounted gain `⟪θ, Y⟫` with a chance of profit — +any `θ` whose gain `⟪θ, Y⟫` is `≥ 0` a.e. already has `⟪θ, Y⟫ = 0` a.e. -/ +def NoArbitrage : Prop := + ∀ θ : F, 0 ≤ᵐ[P] (fun ω ↦ inner ℝ θ (Y ω)) → + (fun ω ↦ inner ℝ θ (Y ω)) =ᵐ[P] 0 + +/-- **Equivalent martingale measure** (one period, finite-dim): `Q ~ P`, `Y` is +`Q`-integrable, and `E_Q[Y] = 0 ∈ F`. The library's canonical one-period notion; see the +module docstring for the encodings proved equivalent to it. -/ +structure IsEMM (Q : Measure Ω) : Prop extends IsEquivProbMeasure P Q where + int : Integrable Y Q + fair : ∫ ω, Y ω ∂Q = 0 + +omit [IsProbabilityMeasure P] in +/-- **Forward direction**: an equivalent martingale measure precludes arbitrage. The one-period +market is the horizon-`1` market with `𝓕 0 = ⊥`, the `F`-valued price `S 0 = 0`, `S 1 = Y` and the +constant holding `θ`: `E_Q[Y] = 0` makes `S` a `Q`-martingale up to the horizon, the gain is +`⟪θ, S 1 − S 0⟫ = ⟪θ, Y⟫`, and `MathFin.IsEMM.noArbitrage` does the rest. -/ +theorem noArbitrage_of_isEMM (hY : Measurable Y) {Q : Measure Ω} (hQ : IsEMM P Y Q) : + NoArbitrage P Y := by + have := hQ.isProb + intro θ hpos + -- the two-step filtration `⊥ ≤ mΩ` + obtain ⟨𝓕, h0, h1⟩ : ∃ 𝓕 : Filtration ℕ mΩ, 𝓕 0 = ⊥ ∧ 𝓕 1 = mΩ := + ⟨{ seq := fun n ↦ if n = 0 then ⊥ else mΩ + mono' := fun a b hab ↦ by + dsimp only + split_ifs with ha hb hb + · exact le_rfl + · exact bot_le + · exact absurd (Nat.le_zero.mp (hb ▸ hab)) ha + · exact le_rfl + le' := fun n ↦ by + split_ifs + · exact bot_le + · exact le_rfl }, rfl, rfl⟩ + let S : ℕ → Ω → F := fun n ω ↦ if n = 0 then 0 else Y ω + have hS0 : S 0 = 0 := funext fun ω ↦ ite_eq_left rfl + have hS1 : S 1 = Y := funext fun ω ↦ ite_eq_right one_ne_zero + have hgain : martingaleTransform (fun _ _ ↦ θ) S 1 = fun ω ↦ inner ℝ θ (Y ω) := by + funext ω; simp [martingaleTransform, hS0, hS1] + have hE : MathFin.IsEMM 𝓕 P S 1 Q := .of_condExp_succ hQ.toIsEquivProbMeasure + (fun t ht ↦ by + rcases Nat.le_one_iff_eq_zero_or_eq_one.mp ht with rfl | rfl + · rw [hS0]; exact stronglyMeasurable_zero + · rw [hS1, h1]; exact hY.stronglyMeasurable) + (fun t ht ↦ by + rcases Nat.le_one_iff_eq_zero_or_eq_one.mp ht with rfl | rfl + · rw [hS0]; exact integrable_zero _ _ _ + · rw [hS1]; exact hQ.int) + (fun t ht ↦ by + obtain rfl : t = 0 := Nat.lt_one_iff.mp ht + rw [h0, condExp_bot, hS1, hQ.fair, hS0] + exact Filter.Eventually.of_forall fun ω ↦ by simp) + have hnull := hE.noArbitrage (fun _ _ ↦ θ) (fun _ _ ↦ stronglyMeasurable_const) + ⟨‖θ‖, fun _ _ _ ↦ le_rfl⟩ (by rw [hgain]; exact hpos) + rwa [hgain] at hnull + +/-! ### The softplus potential and its logistic derivative + +The backward direction minimises `θ ↦ ∫ softplus ⟪θ,Y⟫`; `softplus u = log(1+eᵘ)` is +the smooth convex penalty whose derivative is the **logistic** `σ(u) = eᵘ/(1+eᵘ) ∈ +(0,1)`. The bounds `u⁺ ≤ softplus u ≤ |u| + log 2` give coercivity and integrability; +`σ ∈ (0,1)` gives the uniform `L¹` domination for differentiating under the integral. -/ + +/-- Softplus penalty `log(1 + eᵘ)`. -/ +noncomputable def softplus (u : ℝ) : ℝ := Real.log (1 + Real.exp u) + +/-- Logistic function `eᵘ/(1 + eᵘ) = σ(u)`, the derivative of `softplus`. -/ +noncomputable def logistic (u : ℝ) : ℝ := Real.exp u / (1 + Real.exp u) + +lemma logistic_pos (u : ℝ) : 0 < logistic u := by rw [logistic]; positivity + +lemma logistic_lt_one (u : ℝ) : logistic u < 1 := by + rw [logistic, div_lt_one (by positivity)]; linarith [Real.exp_pos u] + +lemma softplus_nonneg (u : ℝ) : 0 ≤ softplus u := by + rw [softplus]; exact Real.log_nonneg (by linarith [Real.exp_pos u]) + +lemma self_le_softplus (u : ℝ) : u ≤ softplus u := by + rw [softplus] + calc u = Real.log (Real.exp u) := (Real.log_exp u).symm + _ ≤ Real.log (1 + Real.exp u) := + Real.log_le_log (Real.exp_pos u) (by linarith [Real.exp_pos u]) + +/-- `u⁺ = max u 0 ≤ softplus u`: the lower bound powering coercivity of the potential. -/ +lemma posPart_le_softplus (u : ℝ) : max u 0 ≤ softplus u := + max_le (self_le_softplus u) (softplus_nonneg u) + +/-- `softplus u ≤ |u| + log 2`: the linear-growth upper bound giving `L¹`-integrability. -/ +lemma softplus_le (u : ℝ) : softplus u ≤ |u| + Real.log 2 := by + rw [softplus] + have hb : 1 + Real.exp u ≤ 2 * Real.exp |u| := by + have h1 : Real.exp u ≤ Real.exp |u| := Real.exp_le_exp.mpr (le_abs_self u) + have h2 : (1 : ℝ) ≤ Real.exp |u| := Real.one_le_exp (abs_nonneg u) + linarith + calc Real.log (1 + Real.exp u) ≤ Real.log (2 * Real.exp |u|) := + Real.log_le_log (by positivity) hb + _ = |u| + Real.log 2 := by + rw [Real.log_mul (by norm_num) (Real.exp_ne_zero _), Real.log_exp]; ring + +/-- `softplus` is differentiable with derivative the logistic `σ`. -/ +lemma hasDerivAt_softplus (u : ℝ) : HasDerivAt softplus (logistic u) u := by + have h2 : (1 : ℝ) + Real.exp u ≠ 0 := by positivity + have h1 : HasDerivAt (fun v ↦ 1 + Real.exp v) (Real.exp u) u := by + simpa using (Real.hasDerivAt_exp u).const_add 1 + have h3 := (Real.hasDerivAt_log h2).comp u h1 + rw [show logistic u = (1 + Real.exp u)⁻¹ * Real.exp u from by rw [logistic, div_eq_inv_mul]] + exact h3 + +lemma continuous_softplus : Continuous softplus := by + have hpos : ∀ u : ℝ, (0 : ℝ) < 1 + Real.exp u := fun u ↦ by positivity + exact (continuous_const.add Real.continuous_exp).log (fun u ↦ (hpos u).ne') + +lemma continuous_logistic : Continuous logistic := by + have hpos : ∀ u : ℝ, (0 : ℝ) < 1 + Real.exp u := fun u ↦ by positivity + exact Real.continuous_exp.div (continuous_const.add Real.continuous_exp) (fun u ↦ (hpos u).ne') + +/-- The **softplus potential** `f(θ) = ∫ softplus⟪θ,Y⟫ ∂P`, minimised in the backward +direction; its first-order condition produces the equivalent martingale measure. -/ +noncomputable def potential (θ : F) : ℝ := + ∫ ω, softplus (inner ℝ θ (Y ω)) ∂P + +omit [FiniteDimensional ℝ F] [MeasurableSpace F] [BorelSpace F] in +/-- `softplus⟪θ,Y⟫` is `P`-integrable, dominated by `‖θ‖‖Y‖ + log 2`. -/ +lemma integrable_softplus_inner (hYint : Integrable Y P) (θ : F) : + Integrable (fun ω ↦ softplus (inner ℝ θ (Y ω))) P := by + have hmeas : AEStronglyMeasurable (fun ω ↦ softplus (inner ℝ θ (Y ω))) P := + continuous_softplus.comp_aestronglyMeasurable + ((continuous_const.inner continuous_id).comp_aestronglyMeasurable hYint.aestronglyMeasurable) + refine Integrable.mono' (g := fun ω ↦ ‖θ‖ * ‖Y ω‖ + Real.log 2) ?_ hmeas ?_ + · exact (hYint.norm.const_mul ‖θ‖).add (integrable_const _) + · filter_upwards with ω + rw [Real.norm_eq_abs, abs_of_nonneg (softplus_nonneg _)] + exact (softplus_le _).trans (by gcongr; exact abs_real_inner_le_norm _ _) + +/-- **Directional derivative of the potential**. For `Y ∈ L¹`, `t ↦ f(θ + t•u)` is +differentiable at `0` with derivative `∫ σ⟪θ,Y⟫ · ⟪u,Y⟫ ∂P` — differentiation under the +integral, dominated by `‖u‖‖Y‖` since `σ ∈ (0,1)`. -/ +lemma hasDerivAt_potential_dir (hY : Measurable Y) (hYint : Integrable Y P) (θ u : F) : + HasDerivAt (fun t : ℝ ↦ potential P Y (θ + t • u)) + (∫ ω, logistic (inner ℝ θ (Y ω)) * inner ℝ u (Y ω) ∂P) 0 := by + have hbmeas : Measurable (fun ω ↦ inner ℝ u (Y ω)) := measurable_const.inner hY + have hexp : ∀ (t : ℝ) (ω : Ω), + inner ℝ (θ + t • u) (Y ω) = inner ℝ θ (Y ω) + t * inner ℝ u (Y ω) := fun t ω ↦ by + rw [inner_add_left, real_inner_smul_left] + set Φ : ℝ → Ω → ℝ := + fun t ω ↦ softplus (inner ℝ θ (Y ω) + t * inner ℝ u (Y ω)) with hΦ + set Φ' : ℝ → Ω → ℝ := + fun t ω ↦ logistic (inner ℝ θ (Y ω) + t * inner ℝ u (Y ω)) * inner ℝ u (Y ω) with hΦ' + have hmeas_arg : ∀ t : ℝ, AEStronglyMeasurable + (fun ω ↦ inner ℝ θ (Y ω) + t * inner ℝ u (Y ω)) P := + fun t ↦ ((measurable_const.inner hY).add (hbmeas.const_mul t)).aestronglyMeasurable + have hΦ_meas : ∀ᶠ t in nhds (0 : ℝ), AEStronglyMeasurable (Φ t) P := + Filter.Eventually.of_forall fun t ↦ + continuous_softplus.comp_aestronglyMeasurable (hmeas_arg t) + have hΦ_int : Integrable (Φ 0) P := by + simp only [hΦ, zero_mul, add_zero]; exact integrable_softplus_inner P Y hYint θ + have hΦ'_meas : AEStronglyMeasurable (Φ' 0) P := + (continuous_logistic.comp_aestronglyMeasurable (hmeas_arg 0)).mul hbmeas.aestronglyMeasurable + have h_bound : ∀ᵐ ω ∂P, ∀ x ∈ (Set.univ : Set ℝ), ‖Φ' x ω‖ ≤ ‖u‖ * ‖Y ω‖ := by + filter_upwards with ω x _ + rw [hΦ', Real.norm_eq_abs, abs_mul] + have h1 : |logistic (inner ℝ θ (Y ω) + x * inner ℝ u (Y ω))| ≤ 1 := by + rw [abs_of_pos (logistic_pos _)]; exact (logistic_lt_one _).le + have h2 : |inner ℝ u (Y ω)| ≤ ‖u‖ * ‖Y ω‖ := abs_real_inner_le_norm u (Y ω) + calc |logistic (inner ℝ θ (Y ω) + x * inner ℝ u (Y ω))| * |inner ℝ u (Y ω)| + ≤ 1 * (‖u‖ * ‖Y ω‖) := mul_le_mul h1 h2 (abs_nonneg _) zero_le_one + _ = ‖u‖ * ‖Y ω‖ := one_mul _ + have h_diff : ∀ᵐ ω ∂P, ∀ x ∈ (Set.univ : Set ℝ), + HasDerivAt (fun t ↦ Φ t ω) (Φ' x ω) x := by + filter_upwards with ω x _ + have haff : HasDerivAt (fun t : ℝ ↦ inner ℝ θ (Y ω) + t * inner ℝ u (Y ω)) + (inner ℝ u (Y ω)) x := by + simpa using ((hasDerivAt_id x).mul_const (inner ℝ u (Y ω))).const_add (inner ℝ θ (Y ω)) + have hc := (hasDerivAt_softplus _).comp x haff + simpa only [hΦ, hΦ', Function.comp_def] using hc + obtain ⟨-, hderiv⟩ := hasDerivAt_integral_of_dominated_loc_of_deriv_le (μ := P) + (bound := fun ω ↦ ‖u‖ * ‖Y ω‖) Filter.univ_mem hΦ_meas hΦ_int hΦ'_meas h_bound + (hYint.norm.const_mul ‖u‖) h_diff + have hpot : (fun t : ℝ ↦ potential P Y (θ + t • u)) = fun t ↦ ∫ ω, Φ t ω ∂P := by + funext t; simp only [potential, hΦ] + exact integral_congr_ae (by filter_upwards with ω; rw [hexp t ω]) + have hval : (∫ ω, Φ' 0 ω ∂P) = ∫ ω, logistic (inner ℝ θ (Y ω)) * inner ℝ u (Y ω) ∂P := by + refine integral_congr_ae ?_; filter_upwards with ω; simp only [hΦ', zero_mul, add_zero] + rw [hpot, ← hval]; exact hderiv + +/-- `softplus` is `1`-Lipschitz (its derivative `σ` lies in `(0,1)`). -/ +lemma lipschitzWith_softplus : LipschitzWith 1 softplus := by + refine lipschitzWith_of_nnNorm_deriv_le + (fun x ↦ (hasDerivAt_softplus x).differentiableAt) fun x ↦ ?_ + rw [(hasDerivAt_softplus x).deriv, ← NNReal.coe_le_coe, coe_nnNorm, NNReal.coe_one, + Real.norm_eq_abs, abs_of_pos (logistic_pos x)] + exact (logistic_lt_one x).le + +omit [IsProbabilityMeasure P] [FiniteDimensional ℝ F] [MeasurableSpace F] [BorelSpace F] in +/-- For a `1`-Lipschitz `φ`, the averaged map `θ ↦ ∫ φ⟪θ,Y⟫ ∂P` is `(∫‖Y‖)`-Lipschitz +(`φ` is `1`-Lipschitz and `θ ↦ ⟪θ,Y ω⟫` is `‖Y ω‖`-Lipschitz, by Cauchy–Schwarz). -/ +lemma lipschitzWith_integral_inner {φ : ℝ → ℝ} (hφ : LipschitzWith 1 φ) + (hint : ∀ θ : F, Integrable (fun ω ↦ φ (inner ℝ θ (Y ω))) P) + (hYint : Integrable Y P) : + LipschitzWith (∫ ω, ‖Y ω‖ ∂P).toNNReal (fun θ ↦ ∫ ω, φ (inner ℝ θ (Y ω)) ∂P) := by + have hnn : 0 ≤ ∫ ω, ‖Y ω‖ ∂P := integral_nonneg fun ω ↦ norm_nonneg _ + refine LipschitzWith.of_dist_le_mul fun θ θ' ↦ ?_ + rw [Real.dist_eq, Real.coe_toNNReal _ hnn, ← integral_sub (hint θ) (hint θ'), dist_eq_norm] + have hbound : ∀ ω, ‖φ (inner ℝ θ (Y ω)) - φ (inner ℝ θ' (Y ω))‖ ≤ ‖Y ω‖ * ‖θ - θ'‖ := by + intro ω + have h1 := hφ.dist_le_mul (inner ℝ θ (Y ω)) (inner ℝ θ' (Y ω)) + rw [Real.dist_eq, Real.dist_eq, NNReal.coe_one, one_mul] at h1 + calc ‖φ (inner ℝ θ (Y ω)) - φ (inner ℝ θ' (Y ω))‖ + = |φ (inner ℝ θ (Y ω)) - φ (inner ℝ θ' (Y ω))| := Real.norm_eq_abs _ + _ ≤ |inner ℝ θ (Y ω) - inner ℝ θ' (Y ω)| := h1 + _ = |inner ℝ (θ - θ') (Y ω)| := by rw [inner_sub_left] + _ ≤ ‖Y ω‖ * ‖θ - θ'‖ := by rw [mul_comm]; exact abs_real_inner_le_norm (θ - θ') (Y ω) + calc |∫ ω, (φ (inner ℝ θ (Y ω)) - φ (inner ℝ θ' (Y ω))) ∂P| + ≤ ∫ ω, ‖φ (inner ℝ θ (Y ω)) - φ (inner ℝ θ' (Y ω))‖ ∂P := abs_integral_le_integral_abs .. + _ ≤ ∫ ω, ‖Y ω‖ * ‖θ - θ'‖ ∂P := + integral_mono_ae ((hint θ).sub (hint θ')).norm (hYint.norm.mul_const _) + (Filter.Eventually.of_forall hbound) + _ = (∫ ω, ‖Y ω‖ ∂P) * ‖θ - θ'‖ := integral_mul_const _ _ + +omit [FiniteDimensional ℝ F] [MeasurableSpace F] [BorelSpace F] in +/-- The potential is continuous. -/ +lemma continuous_potential (hYint : Integrable Y P) : Continuous (potential P Y) := + (lipschitzWith_integral_inner P Y lipschitzWith_softplus + (integrable_softplus_inner P Y hYint) hYint).continuous + +/-- `s ↦ max s 0` (positive part) is `1`-Lipschitz. -/ +lemma lipschitzWith_posPart : LipschitzWith 1 (fun s : ℝ ↦ max s 0) := + LipschitzWith.id.max_const 0 + +omit [IsProbabilityMeasure P] [FiniteDimensional ℝ F] [MeasurableSpace F] [BorelSpace F] in +/-- `max⟪θ,Y⟫ 0` is `P`-integrable (dominated by `‖θ‖‖Y‖`). -/ +lemma integrable_posPart_inner (hYint : Integrable Y P) (θ : F) : + Integrable (fun ω ↦ max (inner ℝ θ (Y ω)) 0) P := by + have hmeas : AEStronglyMeasurable (fun ω ↦ max (inner ℝ θ (Y ω)) 0) P := + (continuous_id.max continuous_const).comp_aestronglyMeasurable + ((continuous_const.inner continuous_id).comp_aestronglyMeasurable hYint.aestronglyMeasurable) + refine Integrable.mono' (hYint.norm.const_mul ‖θ‖) hmeas (Filter.Eventually.of_forall fun ω ↦ ?_) + rw [Real.norm_eq_abs, abs_of_nonneg (le_max_right _ _), max_le_iff] + exact ⟨(le_abs_self _).trans (abs_real_inner_le_norm θ (Y ω)), by positivity⟩ + +omit [IsProbabilityMeasure P] [FiniteDimensional ℝ F] [MeasurableSpace F] [BorelSpace F] in +/-- The positive-gain average `g(θ) = ∫⟪θ,Y⟫⁺ ∂P` is continuous. It lower-bounds the +potential (`softplus s ≥ s⁺`) and drives the coercivity argument. -/ +lemma continuous_gainsPos (hYint : Integrable Y P) : + Continuous (fun θ ↦ ∫ ω, max (inner ℝ θ (Y ω)) 0 ∂P) := + (lipschitzWith_integral_inner P Y lipschitzWith_posPart + (integrable_posPart_inner P Y hYint) hYint).continuous + +/-! ### The gains kernel and coercivity over its complement + +`N = {θ : ⟪θ,Y⟫ = 0 a.e.}` is the linear subspace of **redundant** portfolio directions. +The potential is constant along `N`, so the backward construction minimises it over the +orthogonal complement `Nᗮ`, where no arbitrage makes it coercive. A minimiser on `Nᗮ` is +automatically a *global* minimiser (the potential is `N`-translation-invariant), so no +non-redundancy hypothesis is required. -/ + +/-- The **gains kernel** `N = {θ : ⟪θ,Y⟫ = 0 a.e.}`: portfolios whose discounted gain is +a.e. zero. A linear subspace of `F`; the market is non-redundant iff `N = ⊥`. -/ +def gainsKernel : Submodule ℝ F where + carrier := {θ | (fun ω ↦ inner ℝ θ (Y ω)) =ᵐ[P] 0} + zero_mem' := by + change (fun ω ↦ inner ℝ (0 : F) (Y ω)) =ᵐ[P] 0 + filter_upwards with ω; simp + add_mem' := by + intro a b ha hb + change (fun ω ↦ inner ℝ (a + b) (Y ω)) =ᵐ[P] 0 + have ha' : (fun ω ↦ inner ℝ a (Y ω)) =ᵐ[P] 0 := ha + have hb' : (fun ω ↦ inner ℝ b (Y ω)) =ᵐ[P] 0 := hb + filter_upwards [ha', hb'] with ω ea eb + simp only [Pi.zero_apply] at ea eb ⊢ + rw [inner_add_left, ea, eb, add_zero] + smul_mem' := by + intro c b hb + change (fun ω ↦ inner ℝ (c • b) (Y ω)) =ᵐ[P] 0 + have hb' : (fun ω ↦ inner ℝ b (Y ω)) =ᵐ[P] 0 := hb + filter_upwards [hb'] with ω eb + simp only [Pi.zero_apply] at eb ⊢ + rw [real_inner_smul_left, eb, mul_zero] + +omit [IsProbabilityMeasure P] [FiniteDimensional ℝ F] [MeasurableSpace F] [BorelSpace F] in +@[simp] lemma mem_gainsKernel {θ : F} : + θ ∈ gainsKernel P Y ↔ (fun ω ↦ inner ℝ θ (Y ω)) =ᵐ[P] 0 := Iff.rfl + +omit [MeasurableSpace F] [BorelSpace F] in +/-- **Coercivity** of the potential on `Nᗮ` (no arbitrage). The positive gain average +`g(θ) = ∫⟪θ,Y⟫⁺` is positive on `Nᗮ \ {0}` (no arbitrage, plus `N ⊓ Nᗮ = ⊥`), continuous +and positively homogeneous; its minimum `c` over the unit sphere of `Nᗮ` is positive, and +`softplus s ≥ s⁺` gives `c‖θ‖ ≤ f(θ)` for `θ ∈ Nᗮ`. -/ +lemma exists_pos_lower_bound (hYint : Integrable Y P) (hNA : NoArbitrage P Y) + (hNbot : (gainsKernel P Y)ᗮ ≠ ⊥) : + ∃ c > 0, ∀ θ ∈ (gainsKernel P Y)ᗮ, c * ‖θ‖ ≤ potential P Y θ := by + set N := gainsKernel P Y + set g : F → ℝ := fun θ ↦ ∫ ω, max (inner ℝ θ (Y ω)) 0 ∂P with hg + have hg_nonneg : ∀ θ, 0 ≤ g θ := fun θ ↦ integral_nonneg fun ω ↦ le_max_right _ _ + -- `g` is positive on `Nᗮ \ {0}` + have hg_pos : ∀ θ ∈ Nᗮ, θ ≠ 0 → 0 < g θ := by + intro θ hθK hθ + refine (hg_nonneg θ).lt_of_ne fun h ↦ hθ ?_ + have hmax : (fun ω ↦ max (inner ℝ θ (Y ω)) 0) =ᵐ[P] 0 := + (integral_eq_zero_iff_of_nonneg_ae (Filter.Eventually.of_forall fun ω ↦ le_max_right _ _) + (integrable_posPart_inner P Y hYint θ)).mp h.symm + have hnonpos : (fun ω ↦ inner ℝ θ (Y ω)) ≤ᵐ[P] 0 := by + filter_upwards [hmax] with ω hm + have hle : inner ℝ θ (Y ω) ≤ max (inner ℝ θ (Y ω)) 0 := le_max_left _ _ + simp only [Pi.zero_apply] at hm ⊢; rwa [hm] at hle + have hneg := hNA (-θ) (by + filter_upwards [hnonpos] with ω h + simp only [Pi.zero_apply] at h ⊢; rw [inner_neg_left]; linarith) + have hθN : θ ∈ N := by + change (fun ω ↦ inner ℝ θ (Y ω)) =ᵐ[P] 0 + filter_upwards [hneg] with ω hh + simp only [Pi.zero_apply, inner_neg_left] at hh ⊢; linarith + exact inner_self_eq_zero.mp (N.inner_right_of_mem_orthogonal hθN hθK) + -- `g` is positively homogeneous + have hg_hom : ∀ (r : ℝ), 0 ≤ r → ∀ θ, g (r • θ) = r * g θ := by + intro r hr θ + simp only [hg] + rw [← integral_const_mul] + refine integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ ?_) + change max (inner ℝ (r • θ) (Y ω)) 0 = r * max (inner ℝ θ (Y ω)) 0 + rw [real_inner_smul_left] + rcases le_total 0 (inner ℝ θ (Y ω)) with hs | hs + · rw [max_eq_left hs, max_eq_left (mul_nonneg hr hs)] + · rw [max_eq_right hs, max_eq_right (mul_nonpos_of_nonneg_of_nonpos hr hs), mul_zero] + -- minimum of `g` over the unit sphere of `Nᗮ` is positive + have hScompact : IsCompact ((Nᗮ : Set F) ∩ Metric.sphere 0 1) := + (isCompact_sphere 0 1).inter_left Nᗮ.isClosed_of_finiteDimensional + have hSne : ((Nᗮ : Set F) ∩ Metric.sphere 0 1).Nonempty := by + obtain ⟨v, hvK, hv0⟩ := (Submodule.ne_bot_iff _).mp hNbot + have hvnorm : 0 < ‖v‖ := norm_pos_iff.mpr hv0 + refine ⟨(‖v‖⁻¹ : ℝ) • v, Nᗮ.smul_mem _ hvK, ?_⟩ + rw [Metric.mem_sphere, dist_zero_right, norm_smul, norm_inv, Real.norm_eq_abs, + abs_of_pos hvnorm, inv_mul_cancel₀ hvnorm.ne'] + obtain ⟨u₀, hu₀mem, hu₀min⟩ := + hScompact.exists_isMinOn hSne (continuous_gainsPos P Y hYint).continuousOn + obtain ⟨hu₀K, hu₀S⟩ := hu₀mem + have hu₀ne : u₀ ≠ 0 := fun h ↦ by + rw [Metric.mem_sphere, h, dist_self] at hu₀S; exact one_ne_zero hu₀S.symm + refine ⟨g u₀, hg_pos u₀ hu₀K hu₀ne, fun θ hθK ↦ ?_⟩ + have hpg : g θ ≤ potential P Y θ := by + rw [hg, potential] + exact integral_mono_ae (integrable_posPart_inner P Y hYint θ) + (integrable_softplus_inner P Y hYint θ) + (Filter.Eventually.of_forall fun ω ↦ posPart_le_softplus _) + refine le_trans ?_ hpg + rcases eq_or_ne θ 0 with rfl | hθ + · simpa using hg_nonneg 0 + · have hθ0 : (0 : ℝ) < ‖θ‖ := norm_pos_iff.mpr hθ + have hunit : (‖θ‖⁻¹ : ℝ) • θ ∈ (Nᗮ : Set F) ∩ Metric.sphere 0 1 := by + refine ⟨Nᗮ.smul_mem _ hθK, ?_⟩ + rw [Metric.mem_sphere, dist_zero_right, norm_smul, norm_inv, Real.norm_eq_abs, + abs_of_pos hθ0, inv_mul_cancel₀ hθ0.ne'] + calc g u₀ * ‖θ‖ = ‖θ‖ * g u₀ := mul_comm _ _ + _ ≤ ‖θ‖ * g ((‖θ‖⁻¹ : ℝ) • θ) := + mul_le_mul_of_nonneg_left (isMinOn_iff.mp hu₀min _ hunit) hθ0.le + _ = g θ := by + rw [hg_hom ‖θ‖⁻¹ (inv_nonneg.mpr hθ0.le) θ, ← mul_assoc, mul_inv_cancel₀ hθ0.ne', one_mul] + +omit [MeasurableSpace F] [BorelSpace F] in +/-- **The potential attains a global minimum** (no arbitrage). On `Nᗮ`, coercivity makes +the minimum over a large closed ball global; and the potential is constant along `N` +(`⟪n,Y⟫ = 0` a.e.), so a minimiser over `Nᗮ` minimises over all of `F` after the +decomposition `θ = n + z`, `n ∈ N`, `z ∈ Nᗮ`. -/ +lemma exists_global_min_potential (hYint : Integrable Y P) (hNA : NoArbitrage P Y) + (hNbot : (gainsKernel P Y)ᗮ ≠ ⊥) : + ∃ θ₀, ∀ θ, potential P Y θ₀ ≤ potential P Y θ := by + set N := gainsKernel P Y + obtain ⟨c, hc, hlb⟩ := exists_pos_lower_bound P Y hYint hNA hNbot + -- the potential is constant along `N` + have hinv : ∀ ψ : F, ∀ n ∈ N, potential P Y (ψ + n) = potential P Y ψ := by + intro ψ n hn + have hn' : (fun ω ↦ inner ℝ n (Y ω)) =ᵐ[P] 0 := hn + refine integral_congr_ae ?_ + filter_upwards [hn'] with ω he + simp only [Pi.zero_apply] at he + show softplus (inner ℝ (ψ + n) (Y ω)) = softplus (inner ℝ ψ (Y ω)) + rw [inner_add_left, he, add_zero] + -- minimise over the compact set `Nᗮ ∩ closedBall 0 R` + have hp0 : 0 ≤ potential P Y 0 := integral_nonneg fun ω ↦ softplus_nonneg _ + set R : ℝ := potential P Y 0 / c with hRdef + have hR0 : 0 ≤ R := div_nonneg hp0 hc.le + have hKcompact : IsCompact ((Nᗮ : Set F) ∩ Metric.closedBall 0 R) := + (isCompact_closedBall 0 R).inter_left Nᗮ.isClosed_of_finiteDimensional + have hKne : ((Nᗮ : Set F) ∩ Metric.closedBall 0 R).Nonempty := + ⟨0, Nᗮ.zero_mem, Metric.mem_closedBall_self hR0⟩ + obtain ⟨θ₀, hθ₀mem, hθ₀min⟩ := + hKcompact.exists_isMinOn hKne (continuous_potential P Y hYint).continuousOn + obtain ⟨hθ₀K, _⟩ := hθ₀mem + have hcR : c * R = potential P Y 0 := by rw [hRdef]; field_simp + -- θ₀ minimises over all of `Nᗮ` (coercivity escapes the ball) + have hθ₀minK : ∀ θ ∈ Nᗮ, potential P Y θ₀ ≤ potential P Y θ := by + intro θ hθK + rcases le_or_gt ‖θ‖ R with hle | hlt + · exact isMinOn_iff.mp hθ₀min θ ⟨hθK, by rw [Metric.mem_closedBall, dist_zero_right]; exact hle⟩ + · calc potential P Y θ₀ + ≤ potential P Y 0 := isMinOn_iff.mp hθ₀min 0 ⟨Nᗮ.zero_mem, Metric.mem_closedBall_self hR0⟩ + _ = c * R := hcR.symm + _ ≤ c * ‖θ‖ := mul_le_mul_of_nonneg_left hlt.le hc.le + _ ≤ potential P Y θ := hlb θ hθK + -- lift to all of `F`: `f(θ) = f(z) ≥ f(θ₀)` for the `Nᗮ`-component `z` of `θ` + refine ⟨θ₀, fun θ ↦ ?_⟩ + obtain ⟨n, hn, z, hz, hnz⟩ : ∃ n ∈ N, ∃ z ∈ Nᗮ, n + z = θ := by + have hmem : θ ∈ N ⊔ Nᗮ := by + rw [Submodule.sup_orthogonal_of_hasOrthogonalProjection]; trivial + exact Submodule.mem_sup.mp hmem + have hfθ : potential P Y θ = potential P Y z := by + rw [← hnz, add_comm n z, hinv z n hn] + rw [hfθ]; exact hθ₀minK z hz + +/-- **First-order condition**. At a global minimiser `θ₀` of the potential, every +directional derivative vanishes (`IsLocalMin.hasDerivAt_eq_zero`), so the gradient +`∫ σ⟪θ₀,Y⟫ • Y` is the zero vector — the candidate density `z = σ⟪θ₀,Y⟫` makes `Y` fair. -/ +lemma integral_logistic_smul_eq_zero (hY : Measurable Y) (hYint : Integrable Y P) + {θ₀ : F} (hmin : ∀ θ, potential P Y θ₀ ≤ potential P Y θ) : + ∫ ω, logistic (inner ℝ θ₀ (Y ω)) • Y ω ∂P = 0 := by + -- every directional derivative at `θ₀` is `0` + have hdir : ∀ u, ∫ ω, logistic (inner ℝ θ₀ (Y ω)) * inner ℝ u (Y ω) ∂P = 0 := by + intro u + have hmin0 : IsLocalMin (fun t : ℝ ↦ potential P Y (θ₀ + t • u)) 0 := + Filter.Eventually.of_forall fun t ↦ by simp only [zero_smul, add_zero]; exact hmin _ + exact hmin0.hasDerivAt_eq_zero (hasDerivAt_potential_dir P Y hY hYint θ₀ u) + -- the gradient vector is `0`: it is `inner`-orthogonal to everything + have hGint : Integrable (fun ω ↦ logistic (inner ℝ θ₀ (Y ω)) • Y ω) P := by + refine Integrable.mono' hYint.norm + ((continuous_logistic.comp_aestronglyMeasurable + ((continuous_const.inner continuous_id).comp_aestronglyMeasurable + hYint.aestronglyMeasurable)).smul hYint.aestronglyMeasurable) + (Filter.Eventually.of_forall fun ω ↦ ?_) + rw [norm_smul, Real.norm_eq_abs, abs_of_pos (logistic_pos _)] + exact mul_le_of_le_one_left (norm_nonneg _) (logistic_lt_one _).le + have hGu : ∀ u, inner ℝ (∫ ω, logistic (inner ℝ θ₀ (Y ω)) • Y ω ∂P) u = 0 := by + intro u + rw [real_inner_comm, ← integral_inner hGint] + simp_rw [real_inner_smul_right] + exact hdir u + exact inner_self_eq_zero.mp (hGu _) + +/-- **Integrable backward direction** (finite-dim market). For an integrable `Y`, no +arbitrage gives an equivalent martingale measure. If `Y =ᵐ 0` (every direction redundant) +then `Q = P`; otherwise the logistic density `z = σ⟪θ₀,Y⟫` at the potential's global +minimiser is strictly positive, bounded, and fair, so `Q = P.withDensity (z / ∫z)` is the +EMM. -/ +theorem exists_isEMM_of_noArbitrage_integrable (hY : Measurable Y) (hYint : Integrable Y P) + (hNA : NoArbitrage P Y) : + ∃ Q, IsEMM P Y Q := by + by_cases hY0 : (gainsKernel P Y)ᗮ = ⊥ + · -- `Nᗮ = ⊥ ⟹ N = ⊤`: `Y` is a.e. orthogonal to every `θ`, so `E[Y] = 0` and `Q = P` + refine ⟨P, ⟨inferInstance, .rfl, .rfl⟩, hYint, ?_⟩ + have hNtop : gainsKernel P Y = ⊤ := by + have hoo := Submodule.orthogonal_orthogonal (gainsKernel P Y) + rw [hY0, Submodule.bot_orthogonal_eq_top] at hoo + exact hoo.symm + have hall : ∀ θ : F, inner ℝ θ (∫ ω, Y ω ∂P) = (0 : ℝ) := by + intro θ + have hmem : θ ∈ gainsKernel P Y := by rw [hNtop]; exact Submodule.mem_top + have hθN : (fun ω ↦ inner ℝ θ (Y ω)) =ᵐ[P] 0 := (mem_gainsKernel P Y).mp hmem + calc inner ℝ θ (∫ ω, Y ω ∂P) + = ∫ ω, inner ℝ θ (Y ω) ∂P := (integral_inner hYint θ).symm + _ = 0 := by rw [integral_congr_ae hθN]; simp + exact inner_self_eq_zero.mp (hall _) + · obtain ⟨θ₀, hmin⟩ := exists_global_min_potential P Y hYint hNA hY0 + have hfair := integral_logistic_smul_eq_zero P Y hY hYint hmin + set z : Ω → ℝ := fun ω ↦ logistic (inner ℝ θ₀ (Y ω)) + have hzpos : ∀ ω, 0 < z ω := fun ω ↦ logistic_pos _ + have hzlt : ∀ ω, z ω < 1 := fun ω ↦ logistic_lt_one _ + have hzmeas : Measurable z := continuous_logistic.measurable.comp (measurable_const.inner hY) + have hzint : Integrable z P := + ⟨hzmeas.aestronglyMeasurable, HasFiniteIntegral.of_bounded + (Filter.Eventually.of_forall fun ω ↦ by + rw [Real.norm_eq_abs, abs_of_pos (hzpos ω)]; exact (hzlt ω).le)⟩ + set ζ : ℝ := ∫ ω, z ω ∂P with hζ + have hζpos : 0 < ζ := by + rw [hζ, integral_pos_iff_support_of_nonneg_ae + (Filter.Eventually.of_forall fun ω ↦ (hzpos ω).le) hzint, + show Function.support z = Set.univ from Set.eq_univ_of_forall fun ω ↦ (hzpos ω).ne'] + rw [measure_univ]; exact one_pos + set dens : Ω → ℝ := fun ω ↦ z ω / ζ with hdens + have hdpos : ∀ ω, 0 < dens ω := fun ω ↦ div_pos (hzpos ω) hζpos + have hdmeas : Measurable dens := hzmeas.div_const ζ + have hdint : Integrable dens P := hzint.div_const ζ + have hdsum : ∫ ω, dens ω ∂P = 1 := by + simp only [hdens, div_eq_inv_mul] + rw [integral_const_mul, ← hζ, inv_mul_cancel₀ hζpos.ne'] + have hdbound : ∀ ω, dens ω ≤ ζ⁻¹ := fun ω ↦ by + rw [hdens, div_le_iff₀ hζpos, inv_mul_cancel₀ hζpos.ne']; exact (hzlt ω).le + set Q : Measure Ω := P.withDensity (fun ω ↦ ENNReal.ofReal (dens ω)) with hQ + have hofReal_meas : Measurable (fun ω ↦ ENNReal.ofReal (dens ω)) := + ENNReal.measurable_ofReal.comp hdmeas + obtain ⟨hQprob, hQP, hPQ⟩ := isEquivProbMeasure_withDensity P hdpos hdint hdsum + rw [← hQ] at hQprob hQP hPQ + have := hQprob + have hdY_int : Integrable (fun ω ↦ dens ω • Y ω) P := by + refine Integrable.mono' (hYint.norm.const_mul ζ⁻¹) + (hdmeas.aestronglyMeasurable.smul hYint.aestronglyMeasurable) + (Filter.Eventually.of_forall fun ω ↦ ?_) + rw [norm_smul, Real.norm_eq_abs, abs_of_pos (hdpos ω)] + exact mul_le_mul_of_nonneg_right (hdbound ω) (norm_nonneg _) + have hYintQ : Integrable Y Q := by + rw [hQ, integrable_withDensity_iff_integrable_smul' hofReal_meas + (Filter.Eventually.of_forall fun ω ↦ ENNReal.ofReal_lt_top)] + refine hdY_int.congr (Filter.Eventually.of_forall fun ω ↦ ?_) + change dens ω • Y ω = (ENNReal.ofReal (dens ω)).toReal • Y ω + rw [ENNReal.toReal_ofReal (hdpos ω).le] + have hQfair : ∫ ω, Y ω ∂Q = 0 := by + rw [hQ, integral_withDensity_eq_integral_toReal_smul hofReal_meas + (Filter.Eventually.of_forall fun ω ↦ ENNReal.ofReal_lt_top)] + have heq : (fun ω ↦ (ENNReal.ofReal (dens ω)).toReal • Y ω) + = fun ω ↦ ζ⁻¹ • (z ω • Y ω) := by + funext ω + show (ENNReal.ofReal (dens ω)).toReal • Y ω = ζ⁻¹ • (z ω • Y ω) + rw [ENNReal.toReal_ofReal (hdpos ω).le] + change (z ω / ζ) • Y ω = ζ⁻¹ • (z ω • Y ω) + rw [div_eq_inv_mul, mul_smul] + rw [heq, integral_smul, hfair, smul_zero] + exact ⟨Q, ⟨hQprob, hQP, hPQ⟩, hYintQ, hQfair⟩ + +/-- **General backward direction** (finite-dim market, integrability dropped). For a +measurable `Y`, no arbitrage gives an EMM. Pass to the equivalent probability measure +`P_tilde = P.withDensity (w/κ)`, `w = (1+‖Y‖)⁻¹`, under which `Y` is integrable; no arbitrage is +an a.e. notion preserved by `P_tilde ~ P`, so the integrable backward direction applies, and +`Q ~ P_tilde ~ P` by transitivity. -/ +theorem exists_isEMM_of_noArbitrage (hY : Measurable Y) (hNA : NoArbitrage P Y) : + ∃ Q, IsEMM P Y Q := by + set w : Ω → ℝ := fun ω ↦ (1 + ‖Y ω‖)⁻¹ with hwdef + have hw_meas : Measurable w := (measurable_const.add hY.norm).inv + have hden_pos : ∀ ω, (0 : ℝ) < 1 + ‖Y ω‖ := fun ω ↦ by positivity + have hw_pos : ∀ ω, 0 < w ω := fun ω ↦ by simp only [hwdef]; exact inv_pos.mpr (hden_pos ω) + have hw_le_one : ∀ ω, w ω ≤ 1 := fun ω ↦ by + simp only [hwdef]; exact inv_le_one_of_one_le₀ (by linarith [norm_nonneg (Y ω)]) + have hw_int : Integrable w P := + ⟨hw_meas.aestronglyMeasurable, HasFiniteIntegral.of_bounded + (Filter.Eventually.of_forall fun ω ↦ by + rw [Real.norm_eq_abs, abs_of_pos (hw_pos ω)]; exact hw_le_one ω)⟩ + set κ : ℝ := ∫ ω, w ω ∂P with hκdef + have hκ_pos : 0 < κ := by + rw [hκdef, integral_pos_iff_support_of_nonneg_ae + (Filter.Eventually.of_forall fun ω ↦ (hw_pos ω).le) hw_int, + show Function.support w = Set.univ from Set.eq_univ_of_forall fun ω ↦ (hw_pos ω).ne'] + rw [measure_univ]; exact one_pos + set dens : Ω → ℝ := fun ω ↦ w ω / κ with hddef + have hd_meas : Measurable dens := hw_meas.div_const κ + have hd_pos : ∀ ω, 0 < dens ω := fun ω ↦ div_pos (hw_pos ω) hκ_pos + have hd_int : Integrable dens P := hw_int.div_const κ + have hd_sum : ∫ ω, dens ω ∂P = 1 := by + simp only [hddef, div_eq_inv_mul] + rw [integral_const_mul, ← hκdef, inv_mul_cancel₀ hκ_pos.ne'] + set Pt : Measure Ω := P.withDensity (fun ω ↦ ENNReal.ofReal (dens ω)) with hPtdef + have hd_ofReal_meas : Measurable (fun ω ↦ ENNReal.ofReal (dens ω)) := + ENNReal.measurable_ofReal.comp hd_meas + obtain ⟨hPt_prob, hPt_ll_P, hP_ll_Pt⟩ := + isEquivProbMeasure_withDensity P hd_pos hd_int hd_sum + rw [← hPtdef] at hPt_prob hPt_ll_P hP_ll_Pt + have := hPt_prob + have hdY_int : Integrable (fun ω ↦ dens ω • Y ω) P := by + refine ⟨(hd_meas.aestronglyMeasurable.smul hY.aestronglyMeasurable), + HasFiniteIntegral.of_bounded (C := κ⁻¹) (Filter.Eventually.of_forall fun ω ↦ ?_)⟩ + rw [norm_smul, Real.norm_eq_abs, abs_of_pos (hd_pos ω)] + have h1 : w ω * ‖Y ω‖ ≤ 1 := by + simp only [hwdef, inv_mul_eq_div, div_le_one (hden_pos ω)] + linarith [norm_nonneg (Y ω)] + simp only [hddef, div_mul_eq_mul_div] + rw [div_le_iff₀ hκ_pos, inv_mul_cancel₀ hκ_pos.ne']; exact h1 + have hYintPt : Integrable Y Pt := by + rw [hPtdef, integrable_withDensity_iff_integrable_smul' hd_ofReal_meas + (Filter.Eventually.of_forall fun ω ↦ ENNReal.ofReal_lt_top)] + refine hdY_int.congr (Filter.Eventually.of_forall fun ω ↦ ?_) + change dens ω • Y ω = (ENNReal.ofReal (dens ω)).toReal • Y ω + rw [ENNReal.toReal_ofReal (hd_pos ω).le] + have hNAt : NoArbitrage Pt Y := fun θ h ↦ + hPt_ll_P.ae_eq (hNA θ (hP_ll_Pt.ae_le h)) + obtain ⟨Q, hQ⟩ := exists_isEMM_of_noArbitrage_integrable Pt Y hY hYintPt hNAt + exact ⟨Q, ⟨hQ.isProb, hQ.ac.trans hPt_ll_P, hP_ll_Pt.trans hQ.ac'⟩, hQ.int, hQ.fair⟩ + +/-- **One-period Fundamental Theorem of Asset Pricing**, finite-dimensional market, general +`Ω`. For a measurable `F`-valued discounted excess return `Y` (`F = EuclideanSpace ℝ (Fin +d)` is the `d`-asset case), no arbitrage holds iff there is an equivalent martingale +measure `Q ~ P` with `Y` integrable and `E_Q[Y] = 0`. The backward direction is +explicit: minimise the softplus potential over the gains kernel's orthogonal complement +(its logistic weight is the density), needing no Hahn–Banach, no L⁰-cone closedness, +no measurable selection, and **no non-redundancy hypothesis**. -/ +theorem ftap_one_period_vector (hY : Measurable Y) : + NoArbitrage P Y ↔ ∃ Q, IsEMM P Y Q := + ⟨fun hNA ↦ exists_isEMM_of_noArbitrage P Y hY hNA, + fun ⟨_, hQ⟩ ↦ noArbitrage_of_isEMM P Y hY hQ⟩ + +end MathFin.OnePeriodVector diff --git a/LeanPool/MathFin/Pricing/FTAP/MarketFTAP.lean b/LeanPool/MathFin/Pricing/FTAP/MarketFTAP.lean new file mode 100644 index 0000000000..e1aa8119e2 --- /dev/null +++ b/LeanPool/MathFin/Pricing/FTAP/MarketFTAP.lean @@ -0,0 +1,129 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.ContinuousMarket +public import LeanPool.MathFin.Pricing.DiscreteMarket + +/-! +# The fundamental theorem of asset pricing for a market + +No arbitrage as a property of a `Market` (`Market.NoArbitrage`) and the fundamental theorem stated +about markets: no arbitrage if and only if there is a pricing measure. + +A market trades at a grid of dates `t 0 ≤ t 1 ≤ ⋯ ≤ t N`. Its **no arbitrage on the grid** is the +library's `NoArbitrage` (`Pricing/FTAP/FTAP.lean`) of the deflated price sampled along the grid, +for the sampled filtration `n ↦ 𝓕 (t n)`: no bounded predictable strategy turns zero wealth into +a `P`-almost surely non-negative gain that is not almost surely zero. The market **traded on the +grid** (`Market.onGrid`) is the same deflated asset quoted in numéraire units, constant between +the dates; its pricing measures are the measures that agree on the information at the last date +with an equivalent martingale measure of the sampled price (`isPricingMeasure_toMarket_iff`). + +* A pricing measure of the market up to a horizon rules out arbitrage on every grid inside the + horizon (`Market.IsPricingMeasure.noArbitrage`), whatever the market: the continuous-time + martingale property is sampled (`IsEMM.sampled`). +* On a finite sample space charged everywhere by `P`, the converse holds + (`Market.noArbitrage_iff_exists_isPricingMeasure_of_finite`, Harrison–Pliska through + `ftap_discrete`): no arbitrage on the grid exists exactly when the market traded on the grid has + a pricing measure. +* On a general probability space the same equivalence holds **assuming + `ConditionalOnePeriodFTAP`**, which is not proved in this library + (`Market.noArbitrage_iff_exists_isPricingMeasure`, Dalang–Morton–Willinger through + `DalangMortonWillinger.lean`). The unconditional statement is the frontier node `thm:dmw-ftap`. + +The bare-process theorems (`ftap_discrete`, `noArbitrage_iff_exists_isEMM`) are what these are +proved from; this page is the statement about markets. + +## Main definitions + +* `Market.NoArbitrage`: no arbitrage for trading at the dates of a monotone grid. +* `Market.onGrid`: the market traded at the dates of a grid, in numéraire units. + +## Main results + +* `Market.IsPricingMeasure.noArbitrage`: a pricing measure rules out arbitrage on every grid + inside its horizon. +* `Market.noArbitrage_iff_exists_isPricingMeasure_of_finite`: the fundamental theorem on a finite + sample space. +* `Market.noArbitrage_iff_exists_isPricingMeasure`: the fundamental theorem, assuming the + conditional one-period FTAP. + +## References + +* [J. M. Harrison and S. R. Pliska, *Martingales and stochastic integrals in the theory of + continuous trading*][HarrisonPliska1981] +* [H. Föllmer and A. Schied, *Stochastic Finance: An Introduction in Discrete Time*][FollmerSchied], + §5.2 +* [F. Delbaen and W. Schachermayer, *The Mathematics of Arbitrage*][DelbaenSchachermayer] + +## Tags + +fundamental theorem of asset pricing, no arbitrage, pricing measure, market, Harrison–Pliska, +Dalang–Morton–Willinger, JEL G13, MSC 91G20 +-/ + +@[expose] public section + +open MeasureTheory +open scoped NNReal + +namespace MathFin.Market + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- **No arbitrage on a grid.** A one-asset market has no arbitrage when trading at the dates +`t 0 ≤ ⋯ ≤ t N` if the deflated price sampled at those dates has none for the sampled filtration: +no bounded predictable strategy turns zero initial wealth into a `P`-almost surely non-negative +gain that is not almost surely zero. -/ +def NoArbitrage (M : Market Unit Ω) {t : ℕ → ℝ≥0} (ht : Monotone t) (N : ℕ) : Prop := + _root_.MathFin.NoArbitrage (ContinuousMarket.sampledFiltration M.𝓕 ht) M.P + (fun n ↦ M.deflated () (t n)) N + +/-- **The market traded on a grid**: the deflated asset sampled at the dates `t 0 ≤ ⋯ ≤ t N`, +constant between them and frozen at `t N`, for the sampled filtration, with the unit numéraire +(`DiscreteMarket.toMarket`). -/ +noncomputable def onGrid (M : Market Unit Ω) {t : ℕ → ℝ≥0} (ht : Monotone t) (N : ℕ) : + Market Unit Ω := + Contracts.DiscreteMarket.toMarket M.P (ContinuousMarket.sampledFiltration M.𝓕 ht) + (fun n ↦ M.deflated () (t n)) N fun n _ ↦ M.stronglyAdapted_deflated () (t n) + +variable {M : Market Unit Ω} {t : ℕ → ℝ≥0} (ht : Monotone t) {N : ℕ} + +/-- **A pricing measure rules out arbitrage on every grid inside its horizon.** It agrees on the +information at the horizon with an equivalent martingale measure of the deflated asset +(`IsPricingMeasure.exists_isEquivProbMeasure`), whose sampling along the grid is one for the +sampled price (`IsEMM.sampled`), which rules out arbitrage (`IsEMM.noArbitrage`). -/ +theorem IsPricingMeasure.noArbitrage [IsFiniteMeasure M.P] {T : ℝ≥0} {Q : Measure Ω} + (hQ : M.IsPricingMeasure T Q) (hT : t N ≤ T) : M.NoArbitrage ht N := by + obtain ⟨Q', hQ'P, hQ', -⟩ := hQ.exists_isEquivProbMeasure + exact ((hQ'.isEMM hQ'P ()).sampled ht N hT).noArbitrage + +/-- **The fundamental theorem of asset pricing for a market on a finite sample space** +(Harrison–Pliska): when `P` charges every state, a one-asset market has no arbitrage on the grid +exactly when the market traded on the grid has a pricing measure. This is +`noArbitrage_iff_exists_isPricingMeasure_of_finite` for the sampled deflated price. -/ +theorem noArbitrage_iff_exists_isPricingMeasure_of_finite [Finite Ω] [Nonempty Ω] + [MeasurableSingletonClass Ω] [IsFiniteMeasure M.P] (hP : ∀ ω, 0 < M.P {ω}) : + M.NoArbitrage ht N ↔ ∃ Q, (M.onGrid ht N).IsPricingMeasure N Q := + Contracts.DiscreteMarket.noArbitrage_iff_exists_isPricingMeasure_of_finite + (fun n ↦ M.stronglyAdapted_deflated () (t n)) hP + +/-- **The fundamental theorem of asset pricing for a market, assuming the conditional one-period +FTAP** (Dalang–Morton–Willinger): on a probability space, for a deflated price integrable at the +dates of the grid, if `ConditionalOnePeriodFTAP` holds (a hypothesis, **not proved** in this +library: see `DalangMortonWillinger.lean`), no arbitrage on the grid is equivalent to a pricing +measure of the market traded on the grid. Only the forward direction uses the hypothesis. -/ +theorem noArbitrage_iff_exists_isPricingMeasure [IsProbabilityMeasure M.P] + (hint : ∀ n ≤ N, Integrable (M.deflated () (t n)) M.P) + (hcond : ConditionalOnePeriodFTAP (ContinuousMarket.sampledFiltration M.𝓕 ht) M.P + (fun n ↦ M.deflated () (t n)) N) : + M.NoArbitrage ht N ↔ ∃ Q, (M.onGrid ht N).IsPricingMeasure N Q := + Contracts.DiscreteMarket.noArbitrage_iff_exists_isPricingMeasure + (fun n _ ↦ M.stronglyAdapted_deflated () (t n)) hint hcond + +end MathFin.Market diff --git a/LeanPool/MathFin/Pricing/FTAP/NoArbitrageLocal.lean b/LeanPool/MathFin/Pricing/FTAP/NoArbitrageLocal.lean new file mode 100644 index 0000000000..28c4419617 --- /dev/null +++ b/LeanPool/MathFin/Pricing/FTAP/NoArbitrageLocal.lean @@ -0,0 +1,291 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.FTAP.FTAP + +/-! +# No arbitrage is local: multi-period versus conditional one-period + +The reduction step of the Dalang–Morton–Willinger theorem. For an adapted `F`-valued discounted +price `S` on a filtered probability space `(Ω, 𝓕, P)` with finite horizon `T`, the multi-period +`NoArbitrage 𝓕 P S T` of `FTAP.lean` (no bounded predictable strategy turns zero wealth into a +sure nonnegative, non-null gain) holds if and only if every one-period market conditional on +`𝓕 t` is arbitrage free: no `𝓕 t`-measurable position `θ` has an a.s. nonnegative gain +`⟪θ, S (t+1) − S t⟫` that is not a.s. zero (`NoArbitrageLocal`). + +* `NoArbitrage ⇒ NoArbitrageLocal` needs no adaptedness: the position `θ` is truncated to the + bounded `θ 1_{‖θ‖ ≤ n}` and held over `(t, t+1]` only; the gain vanishes on every truncation, + hence a.s. +* `NoArbitrageLocal ⇒ NoArbitrage` is an induction on the horizon. If `V_T + g ≥ 0` with + `g = ⟪φ_{T+1}, S_{T+1} − S_T⟫` and `V_T` the (`𝓕 T`-measurable) gain so far, the position + `φ_{T+1} 1_{V_T<0}` has gain `≥ 0`, so it is a.s. zero and `V_T ≥ 0` a.s.; the induction + hypothesis gives `V_T = 0`, and then `g ≥ 0` forces `g = 0`. + +This is the first half of the multi-period FTAP on a general space; the conditional one-period +FTAP (the measurable-selection step) is not proved here. + +## Main definitions + +* `NoArbitrageAt`: no arbitrage in the one-period market of period `t` conditional on `𝓕 t`. +* `NoArbitrageLocal`: `NoArbitrageAt` for every period `t < T`. +* `singleStrategy`: the strategy holding `θ` over the single period `(t, t+1]`. +* `truncation`: `θ 1_{‖θ‖ ≤ n}`. + +## Main results + +* `noArbitrageLocal_of_noArbitrage`: multi-period no arbitrage gives the local one. +* `noArbitrage_of_noArbitrageLocal`: the local one gives the multi-period one (adapted price). +* `noArbitrage_iff_noArbitrageLocal`: the equivalence. + +## References + +* [H. Föllmer and A. Schied, *Stochastic Finance: An Introduction in Discrete Time*][FollmerSchied], + §5.2 + +## Tags + +no arbitrage, conditional no arbitrage, one-period reduction, predictable strategy, +Dalang–Morton–Willinger, JEL G13, MSC 91G20, MSC 60G42 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped InnerProductSpace + +variable {Ω : Type*} {m0 : MeasurableSpace Ω} + {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] + +/-- **No arbitrage in the conditional one-period market of period `t`.** Every `𝓕 t`-measurable +position `θ` (unbounded allowed) whose one-period gain `⟪θ, S (t+1) − S t⟫` is `P`-a.s. nonnegative +has a `P`-a.s. zero gain. -/ +def NoArbitrageAt (𝓕 : Filtration ℕ m0) (P : Measure Ω) (S : ℕ → Ω → F) (t : ℕ) : Prop := + ∀ θ : Ω → F, StronglyMeasurable[𝓕 t] θ → + 0 ≤ᵐ[P] (fun ω ↦ ⟪θ ω, S (t + 1) ω - S t ω⟫_ℝ) → + (fun ω ↦ ⟪θ ω, S (t + 1) ω - S t ω⟫_ℝ) =ᵐ[P] 0 + +/-- **No arbitrage in each conditional one-period market** of the periods `t < T`. -/ +def NoArbitrageLocal (𝓕 : Filtration ℕ m0) (P : Measure Ω) (S : ℕ → Ω → F) (T : ℕ) : Prop := + ∀ t < T, NoArbitrageAt 𝓕 P S t + +/-- The strategy holding `θ` over the single period `(t, t+1]` and nothing else. -/ +def singleStrategy (t : ℕ) (θ : Ω → F) : ℕ → Ω → F := + fun s ω ↦ if s = t + 1 then θ ω else 0 + +/-- The truncation `θ 1_{‖θ‖ ≤ n}` of a position. -/ +noncomputable def truncation (n : ℕ) (θ : Ω → F) : Ω → F := + {ω | ‖θ ω‖ ≤ (n : ℝ)}.indicator θ + +section Truncation + +variable {θ : Ω → F} {n : ℕ} {ω : Ω} + +omit [InnerProductSpace ℝ F] in +lemma truncation_of_le (h : ‖θ ω‖ ≤ (n : ℝ)) : truncation n θ ω = θ ω := by + simp [truncation, h] + +omit [InnerProductSpace ℝ F] in +lemma truncation_of_not_le (h : ¬ ‖θ ω‖ ≤ (n : ℝ)) : truncation n θ ω = 0 := by + simp [truncation, h] + +omit [InnerProductSpace ℝ F] in +lemma norm_truncation_le : ‖truncation n θ ω‖ ≤ (n : ℝ) := by + by_cases h : ‖θ ω‖ ≤ (n : ℝ) + · rw [truncation_of_le h]; exact h + · rw [truncation_of_not_le h]; simp + +omit [InnerProductSpace ℝ F] in +lemma stronglyMeasurable_truncation {m : MeasurableSpace Ω} (hθ : StronglyMeasurable[m] θ) : + StronglyMeasurable[m] (truncation n θ) := + hθ.indicator (hθ.norm.measurable (measurableSet_Iic (a := (n : ℝ)))) + +end Truncation + +section SingleStrategy + +variable {t T : ℕ} {θ : Ω → F} + +omit [InnerProductSpace ℝ F] in +lemma singleStrategy_self : singleStrategy t θ (t + 1) = θ := by + funext ω; simp [singleStrategy] + +omit [InnerProductSpace ℝ F] in +lemma singleStrategy_of_ne {u : ℕ} (h : u ≠ t) : singleStrategy t θ (u + 1) = 0 := by + funext ω; simp [singleStrategy, h] + +omit [InnerProductSpace ℝ F] in +lemma singleStrategy_predictable {𝓕 : Filtration ℕ m0} (hθ : StronglyMeasurable[𝓕 t] θ) : + ∀ u < T, StronglyMeasurable[𝓕 u] (singleStrategy t θ (u + 1)) := by + intro u _ + by_cases h : u = t + · subst h + rw [singleStrategy_self] + exact hθ + · rw [singleStrategy_of_ne h] + exact stronglyMeasurable_zero + +omit [InnerProductSpace ℝ F] in +lemma norm_singleStrategy_le {K : ℝ} (hK0 : 0 ≤ K) (hK : ∀ ω, ‖θ ω‖ ≤ K) (s : ℕ) (ω : Ω) : + ‖singleStrategy t θ s ω‖ ≤ K := by + by_cases h : s = t + 1 + · simpa [singleStrategy, h] using hK ω + · simpa [singleStrategy, h] using hK0 + +lemma martingaleTransform_singleStrategy (S : ℕ → Ω → F) (ht : t < T) : + martingaleTransform (singleStrategy t θ) S T = + fun ω ↦ ⟪θ ω, S (t + 1) ω - S t ω⟫_ℝ := by + funext ω + rw [martingaleTransform, Finset.sum_eq_single t] + · simp [singleStrategy] + · intro k _ hk + simp [singleStrategy, hk] + · intro h + exact absurd (Finset.mem_range.2 ht) h + +end SingleStrategy + +variable {𝓕 : Filtration ℕ m0} {P : Measure Ω} {S : ℕ → Ω → F} + +/-- **Multi-period no arbitrage gives conditional one-period no arbitrage.** A position `θ` with +a nonnegative gain is truncated to the bounded `θ 1_{‖θ‖ ≤ n}` and held over `(t, t+1]` only; the +resulting bounded predictable strategy has a nonnegative gain, so its gain vanishes; the gain of +`θ` vanishes on each `{‖θ‖ ≤ n}`, hence a.s. -/ +theorem noArbitrageLocal_of_noArbitrage {T : ℕ} (hNA : NoArbitrage 𝓕 P S T) : + NoArbitrageLocal 𝓕 P S T := by + intro t ht θ hθ hpos + have key (n : ℕ) : + (fun ω ↦ ⟪truncation n θ ω, S (t + 1) ω - S t ω⟫_ℝ) =ᵐ[P] 0 := by + have hpos' : 0 ≤ᵐ[P] martingaleTransform (singleStrategy t (truncation n θ)) S T := by + rw [martingaleTransform_singleStrategy S ht] + filter_upwards [hpos] with ω hω + have hω' : 0 ≤ ⟪θ ω, S (t + 1) ω - S t ω⟫_ℝ := hω + change 0 ≤ ⟪truncation n θ ω, S (t + 1) ω - S t ω⟫_ℝ + by_cases h : ‖θ ω‖ ≤ (n : ℝ) + · rw [truncation_of_le h]; exact hω' + · rw [truncation_of_not_le h]; simp + have hbdd : ∃ K : ℝ, ∀ s ≤ T, ∀ ω, ‖singleStrategy t (truncation n θ) s ω‖ ≤ K := + ⟨n, fun s _ ω ↦ + norm_singleStrategy_le (Nat.cast_nonneg n) (fun ω ↦ norm_truncation_le) s ω⟩ + have h := hNA (singleStrategy t (truncation n θ)) + (singleStrategy_predictable (stronglyMeasurable_truncation hθ)) hbdd hpos' + rwa [martingaleTransform_singleStrategy S ht] at h + have hall : ∀ᵐ ω ∂P, ∀ n : ℕ, ⟪truncation n θ ω, S (t + 1) ω - S t ω⟫_ℝ = 0 := + ae_all_iff.2 fun n ↦ key n + filter_upwards [hall] with ω hω + have h1 := hω ⌈‖θ ω‖⌉₊ + rw [truncation_of_le (θ := θ) (ω := ω) (Nat.le_ceil ‖θ ω‖)] at h1 + exact h1 + +/-- The gain process of a predictable strategy is adapted: `martingaleTransform φ S n` is +`𝓕 n`-measurable for `n ≤ T`, for an adapted price. -/ +lemma stronglyMeasurable_martingaleTransform {T : ℕ} + (hS : ∀ t ≤ T, StronglyMeasurable[𝓕 t] (S t)) {φ : ℕ → Ω → F} + (hφ : ∀ t < T, StronglyMeasurable[𝓕 t] (φ (t + 1))) : + ∀ n ≤ T, StronglyMeasurable[𝓕 n] (martingaleTransform φ S n) := by + intro n + induction n with + | zero => + intro _ + rw [martingaleTransform_zero] + exact stronglyMeasurable_zero + | succ n ih => + intro hn + have hnT : n < T := Nat.lt_of_succ_le hn + have e : martingaleTransform φ S (n + 1) = martingaleTransform φ S n + + fun ω ↦ ⟪φ (n + 1) ω, S (n + 1) ω - S n ω⟫_ℝ := by + funext ω + simp only [martingaleTransform, Finset.sum_range_succ, Pi.add_apply] + have h1 : StronglyMeasurable[𝓕 (n + 1)] (martingaleTransform φ S n) := + (ih hnT.le).mono (𝓕.mono n.le_succ) + have h2 : StronglyMeasurable[𝓕 (n + 1)] (φ (n + 1)) := + (hφ n hnT).mono (𝓕.mono n.le_succ) + have h3 : StronglyMeasurable[𝓕 (n + 1)] (S n) := (hS n hnT.le).mono (𝓕.mono n.le_succ) + rw [e] + exact h1.add (h2.inner ((hS (n + 1) hn).sub h3)) + +/-- **Conditional one-period no arbitrage gives multi-period no arbitrage**, for a price adapted +up to the horizon. -/ +theorem noArbitrage_of_noArbitrageLocal {T : ℕ} + (hS : ∀ t ≤ T, StronglyMeasurable[𝓕 t] (S t)) (hloc : NoArbitrageLocal 𝓕 P S T) : + NoArbitrage 𝓕 P S T := by + revert hS hloc + induction T with + | zero => + intro _ _ φ _ _ _ + rw [martingaleTransform_zero] + | succ T ih => + intro hS hloc φ hφ hbdd hnn + have hloc' : NoArbitrageLocal 𝓕 P S T := fun t ht ↦ hloc t (Nat.lt_succ_of_lt ht) + have hφ' : ∀ t < T, StronglyMeasurable[𝓕 t] (φ (t + 1)) := + fun t ht ↦ hφ t (Nat.lt_succ_of_lt ht) + have hbdd' : ∃ K : ℝ, ∀ n ≤ T, ∀ ω, ‖φ n ω‖ ≤ K := + hbdd.imp fun K hK n hn ↦ hK n (hn.trans T.le_succ) + have hS' : ∀ t ≤ T, StronglyMeasurable[𝓕 t] (S t) := fun t ht ↦ hS t (ht.trans T.le_succ) + have hsplit (ω : Ω) : martingaleTransform φ S (T + 1) ω = + martingaleTransform φ S T ω + ⟪φ (T + 1) ω, S (T + 1) ω - S T ω⟫_ℝ := by + simp only [martingaleTransform, Finset.sum_range_succ] + have hV : StronglyMeasurable[𝓕 T] (martingaleTransform φ S T) := + stronglyMeasurable_martingaleTransform hS' hφ' T le_rfl + have hB : MeasurableSet[𝓕 T] {ω | martingaleTransform φ S T ω < 0} := + hV.measurable (measurableSet_Iio (a := (0 : ℝ))) + obtain ⟨θ, hθ⟩ : ∃ θ : Ω → F, + θ = {ω | martingaleTransform φ S T ω < 0}.indicator (φ (T + 1)) := ⟨_, rfl⟩ + have hθ_pos (ω : Ω) (h : martingaleTransform φ S T ω < 0) : θ ω = φ (T + 1) ω := by + rw [hθ]; simp [h] + have hθ_neg (ω : Ω) (h : ¬ martingaleTransform φ S T ω < 0) : θ ω = 0 := by + rw [hθ]; simp [h] + have hθm : StronglyMeasurable[𝓕 T] θ := by + rw [hθ] + exact (hφ T T.lt_succ_self).indicator hB + have hnn1 : 0 ≤ᵐ[P] fun ω ↦ ⟪θ ω, S (T + 1) ω - S T ω⟫_ℝ := by + filter_upwards [hnn] with ω hω + have hω' : 0 ≤ martingaleTransform φ S (T + 1) ω := hω + change 0 ≤ ⟪θ ω, S (T + 1) ω - S T ω⟫_ℝ + by_cases h : martingaleTransform φ S T ω < 0 + · rw [hθ_pos ω h] + have := hsplit ω + linarith + · rw [hθ_neg ω h] + simp + have h1 := hloc T T.lt_succ_self θ hθm hnn1 + have hV0 : 0 ≤ᵐ[P] martingaleTransform φ S T := by + filter_upwards [hnn, h1] with ω hω h1ω + have hω' : 0 ≤ martingaleTransform φ S (T + 1) ω := hω + have h1ω' : ⟪θ ω, S (T + 1) ω - S T ω⟫_ℝ = 0 := h1ω + change 0 ≤ martingaleTransform φ S T ω + by_contra h + have h' : martingaleTransform φ S T ω < 0 := not_le.1 h + rw [hθ_pos ω h'] at h1ω' + have := hsplit ω + linarith + have hV00 : martingaleTransform φ S T =ᵐ[P] 0 := ih hS' hloc' φ hφ' hbdd' hV0 + have hg : 0 ≤ᵐ[P] fun ω ↦ ⟪φ (T + 1) ω, S (T + 1) ω - S T ω⟫_ℝ := by + filter_upwards [hnn, hV00] with ω hω hVω + have hω' : 0 ≤ martingaleTransform φ S (T + 1) ω := hω + have hVω' : martingaleTransform φ S T ω = 0 := hVω + change 0 ≤ ⟪φ (T + 1) ω, S (T + 1) ω - S T ω⟫_ℝ + have := hsplit ω + linarith + have h2 := hloc T T.lt_succ_self (φ (T + 1)) (hφ T T.lt_succ_self) hg + filter_upwards [hV00, h2] with ω hVω h2ω + have hVω' : martingaleTransform φ S T ω = 0 := hVω + have h2ω' : ⟪φ (T + 1) ω, S (T + 1) ω - S T ω⟫_ℝ = 0 := h2ω + change martingaleTransform φ S (T + 1) ω = 0 + rw [hsplit ω, hVω', h2ω', add_zero] + +/-- **No arbitrage is local.** For a price adapted up to the horizon `T`, the multi-period market +is arbitrage free if and only if every one-period market conditional on `𝓕 t`, `t < T`, is. -/ +theorem noArbitrage_iff_noArbitrageLocal {T : ℕ} + (hS : ∀ t ≤ T, StronglyMeasurable[𝓕 t] (S t)) : + NoArbitrage 𝓕 P S T ↔ NoArbitrageLocal 𝓕 P S T := + ⟨noArbitrageLocal_of_noArbitrage, noArbitrage_of_noArbitrageLocal hS⟩ + +end MathFin diff --git a/LeanPool/MathFin/Pricing/ForwardMeasure.lean b/LeanPool/MathFin/Pricing/ForwardMeasure.lean new file mode 100644 index 0000000000..d236af105d --- /dev/null +++ b/LeanPool/MathFin/Pricing/ForwardMeasure.lean @@ -0,0 +1,168 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.Numeraire + +/-! +# The T-forward measure — the zero-coupon bond as numéraire + +The **T-forward measure** `Q^T` is the pricing measure obtained by taking the +zero-coupon bond `P(·, T)` maturing at `T` as the numéraire, instead of the money +market. Its defining property is that the **forward price is a `Q^T`-martingale**: +for any traded claim, + + `P(0, T) · 𝔼^{Q^T}[X] = 𝔼^Q[X / B_T]`, + +with `B` the bank account and `P(0, T) = 𝔼^Q[1/B_T]` the bond price. In the constant-rate +model this gives `𝔼^{Q^T}[S_T] = S_0 / P(0, T) = F(0, T)`. + +This is the natural next instance of the change-of-numéraire engine +(`Pricing/Numeraire`), after the stock numéraire and the exchange-option +`S²`-numéraire. Reading off the engine's slots for the bond numéraire against the +bank-account reference: the bond pays one unit at maturity, so `N_T = P(T, T) = 1`, with +`N_0 = P(0, T) = 𝔼^Q[1/B_T]` and `B_0 = 1`. This is the one `T`-forward measure of the +library: the Hull–White `S`-forward measure (`Models/Rates/TimingAdjustment`), the nominal +forward measure of the inflation swap (`Models/Rates/Inflation`) and the constant-rate case +below are all `forwardMeasure Q B` for their bank accounts `B`. It has no model in it, only +the numéraire change, so it lives in `Pricing/` beside `Numeraire`; the Wiener-represented bank +accounts are in `Pricing/WienerIntegralForwardMeasure.lean`. + +## Honest scope + +In the **constant-rate** world the bond `P(t, T) = e^{−r(T−t)}` is deterministic, +so the density `dQ^T/dQ = (N_T·B_0)/(N_0·B_T) = e^{rT}/e^{rT} = 1` and `Q^T = Q` +coincides with the risk-neutral measure — the forward-price identity below then +reduces to the familiar `𝔼^Q[S_T] = S_0·e^{rT}`. The *construction* and the +change-of-numéraire identity are stated for a general bank account and carry over verbatim +to a stochastic short rate (where `Q^T ≠ Q`); only the concrete constant-rate instance is +degenerate. + +## Main definitions + +* `forwardMeasure`: the `T`-forward measure `Q^T` for a bank account with terminal value `B`, + the change-of-numéraire measure with the zero-coupon bond as numéraire (`N_T = 1`, + `N_0 = 𝔼^Q[1/B]`, `B_0 = 1`). + +## Main results + +* `forwardMeasure_isProbabilityMeasure` — `Q^T` is a probability measure. +* `forwardMeasure_price` — the bond-numéraire change-of-measure identity + `P(0,T)·𝔼^{Q^T}[X] = 𝔼^Q[X/B_T]`. +* `forwardMeasure_expected_spot` — `𝔼^{Q^T}[S_T] = S_0·e^{rT}` from the EMM property, + at the constant bank account `e^{rT}`. +* `futuresForwardBasis_of_integral_mul_exp_neg` — the numéraire step of the futures–forward + basis, for any law satisfying the covariance identity. + +## Tags + +T-forward measure, change of numéraire, zero-coupon bond numéraire, +risk-neutral measure, bond as numeraire, MSC 91G30, JEL G13, JEL E43 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped ENNReal + +variable {Ω : Type*} [MeasurableSpace Ω] + +/-- The **T-forward measure** `Q^T` for the bank account `B` (its terminal value `B_T`): the +change-of-numéraire measure with the zero-coupon bond `P(·, T)` as numéraire, `N_T = 1`, +`N_0 = P(0, T) = 𝔼^Q[1/B_T]`, against the reference `B_T`, `B_0 = 1`. Its density is +`dQ^T/dQ = (1/B_T)/P(0,T)`. It is a probability measure only when `B > 0` and `1/B` is +integrable (`forwardMeasure_isProbabilityMeasure`); when `1/B` is not integrable, `∫ 1/B` is the +Bochner junk value `0` and this is not a price measure. -/ +noncomputable def forwardMeasure (Q : Measure Ω) (B : Ω → ℝ) : Measure Ω := + numeraireMeasure Q B (fun _ ↦ (1 : ℝ)) 1 (∫ ω, 1 / B ω ∂Q) + +/-- The integral `P(0, T) = 𝔼[1/B_T]` of a positive integrable discount factor is positive. -/ +lemma integral_one_div_pos {Q : Measure Ω} [IsProbabilityMeasure Q] {B : Ω → ℝ} + (hB : ∀ ω, 0 < B ω) (hint : Integrable (fun ω ↦ 1 / B ω) Q) : + 0 < ∫ ω, 1 / B ω ∂Q := by + rw [integral_pos_iff_support_of_nonneg (fun ω ↦ (one_div_pos.2 (hB ω)).le) hint] + have : Function.support (fun ω ↦ 1 / B ω) = Set.univ := + Set.eq_univ_of_forall fun ω ↦ (one_div_pos.2 (hB ω)).ne' + rw [this, measure_univ] + exact zero_lt_one + +/-- **The T-forward measure is a probability measure**: the normalisation +`𝔼^Q[N_T/B_T] = N_0/B_0` reads `𝔼^Q[1/B_T] = P(0,T)`, which is the definition of `P(0,T)`. +This is the one probability lemma behind every forward measure of the library. (Equivalence with +`Q` is `numeraireMeasure_isEquivProbMeasure`, not proved here.) -/ +theorem forwardMeasure_isProbabilityMeasure {Q : Measure Ω} [IsProbabilityMeasure Q] + {B : Ω → ℝ} (hB : ∀ ω, 0 < B ω) (hint : Integrable (fun ω ↦ 1 / B ω) Q) : + IsProbabilityMeasure (forwardMeasure Q B) := + numeraireMeasure_isProbabilityMeasure (fun _ ↦ one_pos) hB one_pos + (integral_one_div_pos hB hint) hint (div_one _).symm + +/-- **The bond-numéraire change of measure**: `P(0,T)·𝔼^{Q^T}[X] = 𝔼^Q[X/B_T]`. +Directly the change-of-numéraire theorem with the bond slots `N_T = 1`, `N_0 = P(0,T)`, +`B_0 = 1` (no integrability hypothesis needed). -/ +theorem forwardMeasure_price {Q : Measure Ω} {B : Ω → ℝ} (X : Ω → ℝ) + (hBmeas : Measurable B) (hB : ∀ ω, 0 < B ω) (hP0 : 0 < ∫ ω, 1 / B ω ∂Q) : + (∫ ω, 1 / B ω ∂Q) * ∫ ω, X ω ∂(forwardMeasure Q B) = ∫ ω, X ω / B ω ∂Q := by + unfold forwardMeasure + simpa using changeOfNumeraire (Q := Q) (BT := B) (NT := fun _ ↦ (1 : ℝ)) (B0 := 1) + (N0 := ∫ ω, 1 / B ω ∂Q) X measurable_const hBmeas (fun _ ↦ one_pos) hB zero_le_one hP0 + +/-- **The forward price is the `Q^T`-expectation of the spot**: at the constant bank account +`e^{rT}` and given the EMM property `𝔼^Q[e^{−rT}·S_T] = S_0`, one has +`𝔼^{Q^T}[S_T] = S_0·e^{rT} = S_0/P(0,T)` — the no-arbitrage forward price. -/ +theorem forwardMeasure_expected_spot {Q : Measure Ω} [IsProbabilityMeasure Q] (S_0 r T : ℝ) + (X : Ω → ℝ) (hEMM : ∫ ω, Real.exp (-(r * T)) * X ω ∂Q = S_0) : + ∫ ω, X ω ∂(forwardMeasure Q fun _ ↦ Real.exp (r * T)) = S_0 * Real.exp (r * T) := by + have hp := forwardMeasure_price (Q := Q) X (B := fun _ ↦ Real.exp (r * T)) + measurable_const (fun _ ↦ Real.exp_pos _) + (by simp only [integral_const, probReal_univ, one_smul]; positivity) + simp only [integral_const, probReal_univ, one_smul, ← Real.exp_neg, + div_eq_mul_inv] at hp + have hEMM' : ∫ ω, X ω * Real.exp (-(r * T)) ∂Q = S_0 := by + rw [← hEMM]; exact integral_congr_ae (ae_of_all _ fun ω ↦ mul_comm _ _) + rw [hEMM'] at hp + have he : Real.exp (-(r * T)) * Real.exp (r * T) = 1 := by rw [← Real.exp_add]; simp + linear_combination (Real.exp (r * T)) * hp + - (∫ ω, X ω ∂(forwardMeasure Q fun _ ↦ Real.exp (r * T))) * he + +section FuturesForward + +variable {μ : Measure Ω} + +/-- **The numéraire step of the futures–forward basis, for any law.** Let the bank account be +`e^{Y}` and pass to its `T`-forward measure (`forwardMeasure μ e^{Y}`, the measure of the bond +that pays `1`, worth `𝔼[e^{−Y}]` today). If a payoff `V` satisfies the covariance identity +`𝔼[V·e^{−Y}] = 𝔼[V]·𝔼[e^{−Y}]·e^{−c}` (hypothesis `hcov`), then + + `𝔼^Q[V] = 𝔼^{Q^T}[V] · e^{c}`. + +`MathFin.forwardMeasure_price` plus `hcov`. The Gaussian content enters only through `hcov`: +`futuresForwardBasis_gaussian` supplies it from two independent drivers and +`integral_exp_mul_wienerIntegralLp_eq_forwardMeasure` from the Wiener representation of a +short-rate model. -/ +theorem futuresForwardBasis_of_integral_mul_exp_neg {V Y : Ω → ℝ} (c : ℝ) + (hY : Measurable Y) (hN₀ : 0 < ∫ ω, Real.exp (-Y ω) ∂μ) + (hcov : ∫ ω, V ω * Real.exp (-Y ω) ∂μ + = (∫ ω, V ω ∂μ) * (∫ ω, Real.exp (-Y ω) ∂μ) * Real.exp (-c)) : + ∫ ω, V ω ∂μ + = (∫ ω, V ω ∂(forwardMeasure μ fun ω ↦ Real.exp (Y ω))) * Real.exp c := by + have hinv : (fun ω ↦ 1 / Real.exp (Y ω)) = fun ω ↦ Real.exp (-Y ω) := by + funext ω; rw [one_div, Real.exp_neg] + have h := forwardMeasure_price (Q := μ) V hY.exp (fun ω ↦ Real.exp_pos _) (by rwa [hinv]) + have hc : (fun ω ↦ V ω / Real.exp (Y ω)) = fun ω ↦ V ω * Real.exp (-Y ω) := by + funext ω; rw [Real.exp_neg, div_eq_mul_inv] + rw [hc, hcov, hinv] at h + have h' : ∫ ω, V ω ∂(forwardMeasure μ fun ω ↦ Real.exp (Y ω)) + = (∫ ω, V ω ∂μ) * Real.exp (-c) := + mul_left_cancel₀ hN₀.ne' (h.trans (by ring)) + rw [h', mul_assoc, ← Real.exp_add, neg_add_cancel, Real.exp_zero, mul_one] + +end FuturesForward + +end MathFin diff --git a/LeanPool/MathFin/Pricing/Girsanov.lean b/LeanPool/MathFin/Pricing/Girsanov.lean new file mode 100644 index 0000000000..bd402a7b43 --- /dev/null +++ b/LeanPool/MathFin/Pricing/Girsanov.lean @@ -0,0 +1,156 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.ContinuousMarket +public import LeanPool.MathFin.Probability.Brownian.Girsanov.GirsanovConstantTheta + +/-! +# Continuous-time Girsanov for Black–Scholes — the EMM as an explicit change of measure + +The equivalent martingale measure of the Black–Scholes model, **constructed** as a +Girsanov density change of the physical measure — not recognised after the fact. Under +the physical measure `P` the stock has drift `μ`, +`S_t = S_0 · exp((μ − σ²/2)t + σ X_t)`, so the discounted price is +`D_t = e^{−rt} S_t = S_0 · exp((μ − r − σ²/2)t + σ X_t)`, a `P`-submartingale (drift +`μ − r ≠ 0`). Tilting by the **Girsanov density** with constant market price of risk +`θ = (μ − r)/σ`, + + `Z_t = exp(−θ X_t − ½θ² t)` (the Wald exponential at `α = −θ`), + `Q = P.withDensity Z_T`, + +turns the discounted price into a `Q`-**martingale** on `[0, T]`: `Q` is the EMM. + +The proof is one line of algebra on top of the constant-θ Girsanov theorem. Since +`μ − r = σθ`, the discounted price is `S_0` times the exponential `Q`-martingale of the +drift-corrected process `B^θ_t = X_t + θt` at `a = σ`: + + `(μ − r − σ²/2)t + σX_t = σ(X_t + θt) − ½σ²t`, + +and `expBtheta_isQMartingale` (`GirsanovConstantTheta`) is that exponential's martingale +property under the same `Q`. The constant `S_0` comes out of both integrals. + +This wires the **I ↔ II seam** (pricing ↔ Itô/Brownian tower) on the martingale side: +the risk-neutral measure is an explicit density change of the physical one, retiring the +Wald shortcut of `discountedGBM_isMartingale` (which took `Q = P` from the start). The +*distributional* Girsanov (the drift-corrected `B^θ_t = B_t + ∫₀ᵗ θ_s ds` is a `Q`-Brownian +motion, `gir-thm-9.1.8`) is strictly stronger: `GirsanovConstantTheta` for constant `θ`, +`GirsanovAdaptedTheta` for bounded continuous adapted `θ`, and `GirsanovPredictableTheta` +for bounded predictable `θ`. + +That is the martingale property as a set-integral identity. `bs_discounted_isEMM` packages it as an +equivalent martingale measure of the model-agnostic frame `IsEMM`, at the horizon +`T` of the density: `Q ≈ P` (the density `exp(−θ X_T − ½θ² T)` is positive and integrates to `1`) +and the discounted price stopped at `T` is a `Q`-martingale. The horizon is part of the statement, +not an artefact: past `T` the discounted price is not a `Q`-martingale, and the frame's forward FTAP +(`ContinuousMarket.isEMM_noArbitrageSimple`) is then about strategies trading up to `T`. + +## Main results + +* `MathFin.bs_discounted_isQMartingale` +* `MathFin.bs_discounted_isEMM` + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Ch 9 +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], Ch 5.2 + +## Tags + +Girsanov theorem, risk-neutral measure, market price of risk, Black–Scholes, +equivalent martingale measure, Doléans exponential, JEL G13, MSC 91G20, MSC 60G44 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +/-- **Black–Scholes EMM via Girsanov.** With physical drift `μ`, rate `r`, volatility +`σ ≠ 0`, and market price of risk `θ = (μ − r)/σ`, the discounted stock price +`D_t = S_0 · exp((μ − r − σ²/2)t + σ X_t)` is a martingale on `[0, T]` under the tilted +measure `Q = P.withDensity (exp(−θ X_T − ½θ² T))`: for `s ≤ t ≤ T` and `A ∈ 𝓕_s`, the +`Q`-integrals of `D_t` and `D_s` over `A` agree. `Q` is the equivalent martingale measure, +exhibited as an explicit Girsanov change of measure. It is `S_0` times +`expBtheta_isQMartingale` at `a = σ`. -/ +theorem bs_discounted_isQMartingale + {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + {𝓕 : Filtration ℝ≥0 mΩ} [SigmaFiniteFiltration P 𝓕] + {X : ℝ≥0 → Ω → ℝ} [IsFilteredPreBrownian X 𝓕 P] + (S_0 r μ σ : ℝ) (hσ : σ ≠ 0) (T : ℝ≥0) + {s t : ℝ≥0} (hst : s ≤ t) (htT : t ≤ T) + {A : Set Ω} (hA : MeasurableSet[𝓕 s] A) : + ∫ ω in A, (S_0 * Real.exp ((μ - r - σ ^ 2 / 2) * (t : ℝ) + σ * X t ω)) + ∂(P.withDensity fun ω ↦ ENNReal.ofReal + (Real.exp (-((μ - r) / σ) * X T ω - ((μ - r) / σ) ^ 2 * (T : ℝ) / 2))) + = ∫ ω in A, (S_0 * Real.exp ((μ - r - σ ^ 2 / 2) * (s : ℝ) + σ * X s ω)) + ∂(P.withDensity fun ω ↦ ENNReal.ofReal + (Real.exp (-((μ - r) / σ) * X T ω - ((μ - r) / σ) ^ 2 * (T : ℝ) / 2))) := by + have hD (u : ℝ≥0) (ω : Ω) : (μ - r - σ ^ 2 / 2) * (u : ℝ) + σ * X u ω + = σ * (X u ω + (μ - r) / σ * (u : ℝ)) - σ ^ 2 * (u : ℝ) / 2 := by + field_simp + ring + simp only [hD, integral_const_mul] + rw [expBtheta_isQMartingale ((μ - r) / σ) σ T hst htT hA] + +/-- **The Black–Scholes Girsanov measure is an equivalent martingale measure up to `T`.** With +physical drift `μ`, rate `r`, volatility `σ ≠ 0` and market price of risk `θ = (μ − r)/σ`, the +measure `Q = P.withDensity (exp(−θ X_T − ½θ² T))` is equivalent to `P` and makes the discounted +price `D_t = S_0 · exp((μ − r − σ²/2)t + σ X_t)` a `Q`-martingale on `[0, T]`: an `IsEMM` of the +continuous-market frame at the horizon `T`. + +The set-integral identity is `bs_discounted_isQMartingale`; what the frame adds is adaptedness, +`Q`-integrability (under `Q` the drift-corrected `X_t + θ t` is `N(0, t)`, so `D_t` is `S_0` times a +Gaussian exponential), and equivalence (`girsanovMeasure_isProbabilityMeasure`, a positive density +of unit mean). -/ +theorem bs_discounted_isEMM + {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + {𝓕 : Filtration ℝ≥0 mΩ} [SigmaFiniteFiltration P 𝓕] + {X : ℝ≥0 → Ω → ℝ} [hX : IsFilteredPreBrownian X 𝓕 P] + (S_0 r μ σ : ℝ) (hσ : σ ≠ 0) (T : ℝ≥0) : + IsEMM 𝓕 P + (fun (t : ℝ≥0) ω ↦ S_0 * Real.exp ((μ - r - σ ^ 2 / 2) * (t : ℝ) + σ * X t ω)) T + (P.withDensity fun ω ↦ ENNReal.ofReal + (Real.exp (-((μ - r) / σ) * X T ω - ((μ - r) / σ) ^ 2 * (T : ℝ) / 2))) := by + set θ : ℝ := (μ - r) / σ with hθ + have : IsProbabilityMeasure (P.withDensity fun ω ↦ ENNReal.ofReal + (Real.exp (-θ * X T ω - θ ^ 2 * (T : ℝ) / 2))) := + girsanovMeasure_isProbabilityMeasure (X := X) (𝓕 := 𝓕) θ T + have hmeasX (u : ℝ≥0) : Measurable (X u) := ((hX.stronglyAdapted u).mono (𝓕.le u)).measurable + have hcont (t : ℝ≥0) : Continuous fun x : ℝ ↦ S_0 * Real.exp + ((μ - r - σ ^ 2 / 2) * (t : ℝ) + σ * x) := by + fun_prop + refine ⟨isEquivProbMeasure_withDensity_of_isProbabilityMeasure P + (Real.measurable_exp.comp (((hmeasX T).const_mul (-θ)).sub_const _)).aemeasurable + (ae_of_all _ fun _ ↦ Real.exp_pos _) inferInstance, + ContinuousMarket.martingale_stopped_of_setIntegral_eq + (fun t _ ↦ (hcont t).comp_stronglyMeasurable (hX.stronglyAdapted t)) (fun t htT ↦ ?_) + (fun s t hst htT A hA ↦ ?_)⟩ + · -- `D_t = S_0 · exp(σ B^θ_t − ½σ² t)` with `B^θ_t ~ N(0, t)` under `Q` + have hσθ : σ * θ = μ - r := by rw [hθ]; field_simp + have hlaw := Btheta_map_eq_gaussianReal (P := P) (X := X) (𝓕 := 𝓕) θ T htT + have hexp : Integrable (fun x : ℝ ↦ Real.exp (σ * x)) (gaussianReal 0 t) := + integrable_exp_mul_gaussianReal σ + have hg : Integrable (fun x : ℝ ↦ S_0 * Real.exp (σ * x - σ ^ 2 * (t : ℝ) / 2)) + (gaussianReal 0 t) := by + refine (hexp.const_mul (S_0 * Real.exp (-(σ ^ 2 * (t : ℝ) / 2)))).congr + (ae_of_all _ fun x ↦ ?_) + beta_reduce + rw [show σ * x - σ ^ 2 * (t : ℝ) / 2 = -(σ ^ 2 * (t : ℝ) / 2) + σ * x by ring, Real.exp_add] + ring + rw [← hlaw] at hg + refine ((integrable_map_measure hg.aestronglyMeasurable + ((hmeasX t).add_const _ |>.aemeasurable)).mp hg).congr (ae_of_all _ fun ω ↦ ?_) + change S_0 * Real.exp (σ * (X t ω + θ * (t : ℝ)) - σ ^ 2 * (t : ℝ) / 2) = _ + rw [show σ * (X t ω + θ * (t : ℝ)) - σ ^ 2 * (t : ℝ) / 2 + = (μ - r - σ ^ 2 / 2) * (t : ℝ) + σ * X t ω by linear_combination (t : ℝ) * hσθ] + · exact bs_discounted_isQMartingale S_0 r μ σ hσ T hst htT hA + +end MathFin diff --git a/LeanPool/MathFin/Pricing/Market.lean b/LeanPool/MathFin/Pricing/Market.lean new file mode 100644 index 0000000000..fe39dd6fa8 --- /dev/null +++ b/LeanPool/MathFin/Pricing/Market.lean @@ -0,0 +1,381 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Contracts.Instruments.Options +public import LeanPool.MathFin.Pricing.Value +public import LeanPool.MathFin.Pricing.EquivMartingaleMeasure +public import LeanPool.MathFin.Pricing.StatePrices +public import LeanPool.MathFin.Pricing.Numeraire + +/-! +# The market and its pricing functional + +**A market** is a filtered measurable space with a reference measure `P`, the adapted prices +`S i t` of the traded assets and a strictly positive adapted numéraire `N t`. **A pricing +measure** up to a horizon `T` is a probability measure with the null events of `P` among the +events known at `T` (equivalent to `P` on `𝓕 T`) under which every deflated price `S i t / N t`, +frozen at `T`, is a martingale. + +Equivalence is asked on `𝓕 T` only, as in Föllmer–Schied (§5.2) and Delbaen–Schachermayer: a +horizon-`T` market cannot tell measures apart beyond `𝓕 T`, and on an infinite path space the +risk-neutral and the physical laws are typically singular (i.i.d. coin flips with two +up-probabilities, Brownian motions with two drifts) while equivalent on every `𝓕 T`. For a finite +`P` nothing is lost: a pricing measure agrees on `𝓕 T` with one equivalent to `P` everywhere +(`IsPricingMeasure.exists_isEquivProbMeasure`), and a measure equivalent everywhere under which the +frozen deflated assets are martingales is a pricing measure +(`IsPricingMeasure.of_isEquivProbMeasure`). **The price** of a contract under a measure `Q` is its +value (`Contract.value`) with the deflator `N 0 / N t` on the market's assets: + + `price Q c = 𝔼_Q[∑ (N 0 / N tₖ) · cₖ]` over the contract's cash flows `cₖ` at `tₖ`. + +This is the trunk the library's pricing devices hang on (docs/specs/2026-11-07-one-trunk-design.md, +§3 I1). It is a price when `Q` is a pricing measure and the deflated cash flows are integrable: the +definition is total, and the theorems that call it a price carry those conditions (docs/design.md +§2). + +Two facts make it the price rather than one more integral: + +* a traded asset is priced at its price: under a pricing measure, with a deterministic `N 0`, the + claim that delivers asset `i` at a date `t ≤ T` is worth `𝔼_Q[S i 0]` + (`IsPricingMeasure.price_pay_obs`); +* a fixed-dated contract's price depends on the market only through the law of what it reads: two + markets, on two sample spaces, whose assets and deflators at the contract's observations and + payment dates have one law under their measures give the same price + (`price_eq_of_map_observation_eq`). + A parametric price of a fixed-dated contract defined in one concrete model is therefore its + price in every market with that law. + +The price at an intermediate date `t` is the conditional expectation of the deflated cash flows +given `𝓕 t`, re-expressed at `t` (`priceAt`); deflated to `0`, it averages to the price +(`integral_deflator_mul_priceAt`, the tower property). The zero-coupon bond price `P(t, T)` of the +rates models is the price at `t` of one unit paid at `T` +(`Contracts.bondPrice_deflator_eq_priceAt`, in `Models/Rates/Caplet.lean`). + +Changing the numéraire changes the measure and not the price: the market with numéraire `N` +in place of `B` prices a payment at `T` under the numéraire measure `Q^N` exactly as the original +market does under `Q` (`price_pay_withNumeraire`, the change-of-numéraire theorem +`changeOfNumeraire` read through the price). That `Q^N` is a pricing measure of the new market is +not proved here. + +On a finite sample space the price of a single payment is `statePricePricing` with the state +prices `q ω = (N 0 / N t)(ω) · Q {ω}` (`price_pay_eq_statePricePricing`), non-negative for every +`Q` (`statePrice_nonneg`). + +## Main definitions + +* `Market`: a filtered measurable space, its reference measure, the traded assets and a numéraire. +* `Market.deflator`: `N 0 / N t`. `Market.deflated`: `S i t / N t`. +* `Market.IsPricingMeasure`: a probability measure equivalent to `P` on `𝓕 T` making every + deflated asset a martingale up to the horizon `T`. +* `Market.price`: the value of a contract under a measure, deflated by the numéraire. +* `Market.priceAt`: the price at an intermediate date, a random variable. +* `Market.withNumeraire`: the same market with another numéraire. + +## Main results + +* `Market.price_eq_value_of_numeraire`: a deterministic numéraire prices by the deterministic + deflator `f 0 / f t`; `Market.price_europeanCall_of_numeraire_eq_one`: with unit numéraire the + call is the plain integral of its payoff. +* `Market.stronglyMeasurable_deflator`: the deflator `N 0 / N T` is `𝓕 T`-measurable. +* `Market.IsPricingMeasure.of_isEquivProbMeasure`: a measure equivalent to `P` everywhere that + makes the deflated assets frozen martingales is a pricing measure. +* `Market.IsPricingMeasure.of_trim_eq`: a measure that agrees with a pricing measure on `𝓕 T` is + one. +* `Market.IsPricingMeasure.exists_isEquivProbMeasure`: a pricing measure agrees on `𝓕 T` with a + pricing measure equivalent to `P` everywhere. +* `Market.IsPricingMeasure.price_pay_obs`: a traded asset is priced at its initial price. +* `Market.price_eq_of_map_observation_eq`: law invariance of the price. +* `Market.integral_deflator_mul_priceAt`: the deflated price at `t` averages to the price. +* `Market.price_pay_withNumeraire`: the price is invariant under the change of numéraire. +* `Market.price_pay_eq_statePricePricing`: on a finite sample space the price of a payment is + state-price pricing, with non-negative state prices (`Market.statePrice_nonneg`). + +## References + +* [J. M. Harrison and S. R. Pliska, *Martingales and stochastic integrals in the theory of + continuous trading*][HarrisonPliska1981] +* [H. Geman, N. El Karoui and J.-C. Rochet, *Changes of numéraire, changes of probability measure + and option pricing*][GemanElKarouiRochet1995] +* [H. Föllmer and A. Schied, *Stochastic Finance: An Introduction in Discrete Time*][FollmerSchied], + §5.2 +* [F. Delbaen and W. Schachermayer, *The Mathematics of Arbitrage*][DelbaenSchachermayer] +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] + +## Tags + +market, numéraire, deflator, pricing measure, equivalent martingale measure, risk-neutral +pricing, law invariance, state prices, MSC 91G20, MSC 60G44, JEL G12, JEL G13 +-/ + +@[expose] public section + +open MeasureTheory MathFin.Contracts +open scoped NNReal + +namespace MathFin + +/-- **A market**: a measurable space with a reference measure `P` and a filtration `𝓕`, the +adapted prices `asset i t` of the traded assets, and a strictly positive adapted numéraire. -/ +structure Market (ι Ω : Type*) [mΩ : MeasurableSpace Ω] where + /-- The reference (physical) measure. -/ + P : Measure Ω + /-- The information available at each date. -/ + 𝓕 : Filtration ℝ≥0 mΩ + /-- The price of each traded asset at each date. -/ + asset : ι → ℝ≥0 → Ω → ℝ + /-- The numéraire, in which prices are expressed. -/ + numeraire : ℝ≥0 → Ω → ℝ + numeraire_pos : ∀ t ω, 0 < numeraire t ω + asset_adapted : ∀ i, StronglyAdapted 𝓕 (asset i) + numeraire_adapted : StronglyAdapted 𝓕 numeraire + +namespace Market + +variable {ι Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- The deflator `N 0 / N t`: a cash flow at `t` is worth `N 0 / N t` times itself at `0`. -/ +noncomputable def deflator (M : Market ι Ω) (t : ℝ≥0) (ω : Ω) : ℝ := + M.numeraire 0 ω / M.numeraire t ω + +/-- The price of asset `i` in units of the numéraire, `S i t / N t`. -/ +noncomputable def deflated (M : Market ι Ω) (i : ι) (t : ℝ≥0) (ω : Ω) : ℝ := + M.asset i t ω / M.numeraire t ω + +/-- **`Q` prices the market up to `T`**: a probability measure with the null events of `P` among +the events known at `T` (`Q` and `P` restricted to `𝓕 T` are mutually absolutely continuous), under +which every deflated asset, frozen at `T`, is an `𝓕`-martingale. -/ +structure IsPricingMeasure (M : Market ι Ω) (T : ℝ≥0) (Q : Measure Ω) : Prop where + isProb : IsProbabilityMeasure Q + ac : Q.trim (M.𝓕.le T) ≪ M.P.trim (M.𝓕.le T) + ac' : M.P.trim (M.𝓕.le T) ≪ Q.trim (M.𝓕.le T) + martingale (i : ι) : Martingale (fun t ↦ M.deflated i (min t T)) M.𝓕 Q + +/-- **The price of a contract** under `Q`: its value with the deflator `N 0 / N t` on the market's +assets. It is a price when `Q` is a pricing measure (`IsPricingMeasure`) and the deflated cash flows +are `Q`-integrable. Under another measure it is an integral with no pricing meaning, and for a +non-integrable contract it is the Bochner integral's junk value `0`. -/ +noncomputable def price (M : Market ι Ω) (Q : Measure Ω) (c : Contract ι) : ℝ := + c.value Q M.deflator M.asset + +theorem deflator_pos (M : Market ι Ω) (t : ℝ≥0) (ω : Ω) : 0 < M.deflator t ω := + div_pos (M.numeraire_pos 0 ω) (M.numeraire_pos t ω) + +theorem measurable_asset (M : Market ι Ω) (i : ι) (t : ℝ≥0) : Measurable (M.asset i t) := + ((M.asset_adapted i t).mono (M.𝓕.le t)).measurable + +theorem measurable_numeraire (M : Market ι Ω) (t : ℝ≥0) : Measurable (M.numeraire t) := + ((M.numeraire_adapted t).mono (M.𝓕.le t)).measurable + +theorem measurable_deflator (M : Market ι Ω) (t : ℝ≥0) : Measurable (M.deflator t) := + (M.measurable_numeraire 0).div (M.measurable_numeraire t) + +/-- **A deterministic numéraire gives a deterministic deflator**: if `N t ω = f t` for every date +and state, the deflator is `f 0 / f t`. -/ +theorem deflator_of_numeraire {M : Market ι Ω} {f : ℝ≥0 → ℝ} + (hf : ∀ t ω, M.numeraire t ω = f t) (t : ℝ≥0) (ω : Ω) : M.deflator t ω = f 0 / f t := by + simp only [deflator, hf] + +/-- **The money-market deflator**: with the numéraire `e^{rt}` the deflator is the discount +`e^{−rt}`. The Black–Scholes, clocked-volatility and one-date markets are instances. -/ +theorem deflator_of_numeraire_exp {M : Market ι Ω} {r : ℝ} + (hN : ∀ t ω, M.numeraire t ω = Real.exp (r * t)) (t : ℝ≥0) (ω : Ω) : + M.deflator t ω = Real.exp (-r * t) := by + simp only [deflator_of_numeraire hN, NNReal.coe_zero, mul_zero, Real.exp_zero, one_div, neg_mul, + Real.exp_neg] + +/-- **A deterministic numéraire prices by a deterministic deflator**: if `N t ω = f t`, the price +of a contract is its value with the deflator `f 0 / f t`. The money-market, Bachelier, +clocked-volatility and one-date markets are instances. -/ +theorem price_eq_value_of_numeraire {M : Market ι Ω} {f : ℝ≥0 → ℝ} + (hf : ∀ t ω, M.numeraire t ω = f t) (Q : Measure Ω) (c : Contract ι) : + M.price Q c = c.value Q (fun t _ ↦ f 0 / f t) M.asset := + congrArg (fun D ↦ c.value Q D M.asset) (funext fun t ↦ funext (deflator_of_numeraire hf t)) + +/-- With unit numéraire the call is priced by the plain `Q`-integral of its payoff. -/ +theorem price_europeanCall_of_numeraire_eq_one {M : Market Unit Ω} {T : ℝ≥0} {Q : Measure Ω} + (hN : ∀ t ω, M.numeraire t ω = 1) (K : ℝ) : + M.price Q (europeanCall K T) = ∫ ω, max (M.asset () T ω - K) 0 ∂Q := by + simp [price, europeanCall, europeanCallPayoff, Contract.value_pay, Payoff.eval, scenarioAt, + deflator, hN] + +/-- Each deflated asset is adapted. -/ +theorem stronglyAdapted_deflated (M : Market ι Ω) (i : ι) : StronglyAdapted M.𝓕 (M.deflated i) := + fun t ↦ + ((M.asset_adapted i t).measurable.div (M.numeraire_adapted t).measurable).stronglyMeasurable + +/-- The deflator `N 0 / N T` is known at `T`. -/ +theorem stronglyMeasurable_deflator (M : Market ι Ω) (T : ℝ≥0) : + StronglyMeasurable[M.𝓕 T] (M.deflator T) := + (((M.numeraire_adapted 0).mono (M.𝓕.mono (zero_le (a := T)))).measurable.div + (M.numeraire_adapted T).measurable).stronglyMeasurable + +/-- **A measure equivalent to `P` everywhere is a pricing measure** as soon as every deflated asset, +frozen at `T`, is a martingale under it. -/ +theorem IsPricingMeasure.of_isEquivProbMeasure {M : Market ι Ω} {T : ℝ≥0} {Q : Measure Ω} + (hQ : IsEquivProbMeasure M.P Q) + (hmart : ∀ i, Martingale (fun t ↦ M.deflated i (min t T)) M.𝓕 Q) : + M.IsPricingMeasure T Q := + ⟨hQ.isProb, hQ.ac.trim _, hQ.ac'.trim _, hmart⟩ + +/-- **A pricing measure equivalent to `P` everywhere** is an equivalent martingale measure for each +deflated asset. -/ +theorem IsPricingMeasure.isEMM {M : Market ι Ω} {T : ℝ≥0} {Q : Measure Ω} + (hQ : M.IsPricingMeasure T Q) (hQP : IsEquivProbMeasure M.P Q) (i : ι) : + IsEMM M.𝓕 M.P (M.deflated i) T Q := + ⟨hQP, hQ.martingale i⟩ + +/-- **A pricing measure is determined by its restriction to `𝓕 T`**: a measure that agrees with a +pricing measure on `𝓕 T` is one. The deflated assets frozen at `T` are `𝓕 T`-measurable, so they +are martingales under both (`martingale_min_of_trim_eq`). -/ +theorem IsPricingMeasure.of_trim_eq {M : Market ι Ω} {T : ℝ≥0} {Q Q' : Measure Ω} + (hQ : M.IsPricingMeasure T Q) (h : Q.trim (M.𝓕.le T) = Q'.trim (M.𝓕.le T)) : + M.IsPricingMeasure T Q' := by + have := hQ.isProb + have : IsProbabilityMeasure Q' := ⟨by + rw [← trim_measurableSet_eq (M.𝓕.le T) (@MeasurableSet.univ _ (M.𝓕 T)), ← h, + trim_measurableSet_eq (M.𝓕.le T) (@MeasurableSet.univ _ (M.𝓕 T)), measure_univ]⟩ + refine ⟨this, ?_, ?_, fun i ↦ martingale_min_of_trim_eq h (hQ.martingale i)⟩ + · rw [← h] + exact hQ.ac + · rw [← h] + exact hQ.ac' + +/-- **A pricing measure agrees on `𝓕 T` with one equivalent to `P` everywhere.** Weight `P` by the +density of `Q` with respect to `P` on `𝓕 T` (`exists_isEquivProbMeasure_trim_eq`); the deflated +assets frozen at `T` are `𝓕 T`-measurable, so they stay martingales under the new measure +(`martingale_min_of_trim_eq`). This is how a pricing measure meets the theorems stated for an +`IsEMM`. -/ +theorem IsPricingMeasure.exists_isEquivProbMeasure {M : Market ι Ω} [IsFiniteMeasure M.P] + {T : ℝ≥0} {Q : Measure Ω} (hQ : M.IsPricingMeasure T Q) : + ∃ Q', IsEquivProbMeasure M.P Q' ∧ M.IsPricingMeasure T Q' ∧ + Q'.trim (M.𝓕.le T) = Q.trim (M.𝓕.le T) := by + have := hQ.isProb + obtain ⟨Q', hQ', htrim⟩ := exists_isEquivProbMeasure_trim_eq (M.𝓕.le T) hQ.ac hQ.ac' + have := hQ'.isProb + exact ⟨Q', hQ', .of_isEquivProbMeasure hQ' fun i ↦ + martingale_min_of_trim_eq htrim.symm (hQ.martingale i), htrim⟩ + +/-- **A traded asset is priced at its price.** Under a pricing measure up to `T`, with a +deterministic initial numéraire `N 0 = n₀`, the claim that delivers asset `i` at a date `t ≤ T` is +worth `𝔼_Q[S i 0]`: the deflated asset is a `Q`-martingale, so its mean at `t` is its mean at +`0`. -/ +theorem IsPricingMeasure.price_pay_obs {M : Market ι Ω} {T : ℝ≥0} {Q : Measure Ω} + (hQ : M.IsPricingMeasure T Q) {n₀ : ℝ} (hN₀ : ∀ ω, M.numeraire 0 ω = n₀) (i : ι) + {t : ℝ≥0} (ht : t ≤ T) : + M.price Q (.pay t (.obs i t)) = ∫ ω, M.asset i 0 ω ∂Q := by + have := hQ.isProb + have hmart : ∫ ω, M.deflated i t ω ∂Q = ∫ ω, M.deflated i 0 ω ∂Q := by + rw [← integral_condExp (M.𝓕.le 0)] + refine integral_congr_ae ?_ + have h := (hQ.martingale i).condExp_ae_eq (zero_le (a := t)) + rwa [min_eq_left ht, min_eq_left (zero_le (a := T))] at h + calc M.price Q (.pay t (.obs i t)) = n₀ * ∫ ω, M.deflated i t ω ∂Q := by + rw [price, Contract.value_pay, ← integral_const_mul] + refine integral_congr_ae (.of_forall fun ω ↦ ?_) + simp only [deflator, deflated, Payoff.eval, scenarioAt, hN₀] + ring + _ = ∫ ω, M.asset i 0 ω ∂Q := by + rw [hmart, ← integral_const_mul] + refine integral_congr_ae (.of_forall fun ω ↦ ?_) + have hn₀ : n₀ ≠ 0 := (hN₀ ω ▸ M.numeraire_pos 0 ω).ne' + simp only [deflated, hN₀] + field_simp + +/-- **Law invariance of the price.** A fixed-dated contract has the same price in two markets, on +two sample spaces, if what it reads has one law: the assets at its observations and the deflator at +its payment dates, under `Q` and under `Q'`. -/ +theorem price_eq_of_map_observation_eq {Ω' : Type*} {mΩ' : MeasurableSpace Ω'} + (M : Market ι Ω) (M' : Market ι Ω') {Q : Measure Ω} {Q' : Measure Ω'} (c : Contract ι) + (hc : c.FixedDated) + (h : Q.map (c.observation M.deflator M.asset) = Q'.map (c.observation M'.deflator M'.asset)) : + M.price Q c = M'.price Q' c := + c.value_eq_of_map_observation_eq hc M.measurable_deflator M.measurable_asset + M'.measurable_deflator M'.measurable_asset h + +/-! ### The price at an intermediate date -/ + +/-- **The price of a contract at date `t`**, a random variable: the conditional expectation given +`𝓕 t` of the contract's cash flows deflated to `0`, divided by the deflator `N 0 / N t` to express +it at `t`. It is a price under the conditions that make `price` one (a pricing measure and +integrable deflated cash flows); the definition is total. -/ +noncomputable def priceAt (M : Market ι Ω) (Q : Measure Ω) (t : ℝ≥0) (c : Contract ι) : Ω → ℝ := + fun ω ↦ Q[fun ω' ↦ c.pathPV (fun s ↦ M.deflator s ω') (scenarioAt M.asset ω') | M.𝓕 t] ω + / M.deflator t ω + +/-- **The deflated price at `t` averages to the price**: +`𝔼_Q[(N 0 / N t) · price_t c] = price c`, by the tower property (`integral_condExp`). -/ +theorem integral_deflator_mul_priceAt (M : Market ι Ω) (Q : Measure Ω) [IsFiniteMeasure Q] + (t : ℝ≥0) (c : Contract ι) : + ∫ ω, M.deflator t ω * M.priceAt Q t c ω ∂Q = M.price Q c := by + have h (ω : Ω) : M.deflator t ω * M.priceAt Q t c ω + = Q[fun ω' ↦ c.pathPV (fun s ↦ M.deflator s ω') (scenarioAt M.asset ω') | M.𝓕 t] ω := by + rw [priceAt] + field_simp [(M.deflator_pos t ω).ne'] + simp_rw [h] + exact integral_condExp (M.𝓕.le t) + +/-! ### Change of numéraire -/ + +/-- The market `M` with its numéraire replaced by a strictly positive adapted process `N`. -/ +def withNumeraire (M : Market ι Ω) (N : ℝ≥0 → Ω → ℝ) (hN : ∀ t ω, 0 < N t ω) + (hNa : StronglyAdapted M.𝓕 N) : Market ι Ω := + { M with numeraire := N, numeraire_pos := hN, numeraire_adapted := hNa } + +/-- **The price is invariant under the change of numéraire.** Replace the numéraire `B` of `M` by +a strictly positive adapted `N`, with deterministic initial values `B 0 = b₀` and `N 0 = n₀`. The +new market prices a payment at `T` under the numéraire measure `Q^N`, of density +`(N_T b₀)/(n₀ B_T)` with respect to `Q`, as `M` prices it under `Q`: this is `changeOfNumeraire`, +`n₀ 𝔼^{Q^N}[X / N_T] = b₀ 𝔼^Q[X / B_T]`, and it needs no integrability. -/ +theorem price_pay_withNumeraire [Nonempty Ω] (M : Market ι Ω) (Q : Measure Ω) + {N : ℝ≥0 → Ω → ℝ} (hN : ∀ t ω, 0 < N t ω) (hNa : StronglyAdapted M.𝓕 N) {b₀ n₀ : ℝ} + (hB₀ : ∀ ω, M.numeraire 0 ω = b₀) (hN₀ : ∀ ω, N 0 ω = n₀) (T : ℝ≥0) (a : Payoff ι) : + (M.withNumeraire N hN hNa).price (numeraireMeasure Q (M.numeraire T) (N T) b₀ n₀) (.pay T a) + = M.price Q (.pay T a) := by + obtain ⟨ω₀⟩ := ‹Nonempty Ω› + have hb₀ : 0 < b₀ := hB₀ ω₀ ▸ M.numeraire_pos 0 ω₀ + have hn₀ : 0 < n₀ := hN₀ ω₀ ▸ hN 0 ω₀ + calc (M.withNumeraire N hN hNa).price (numeraireMeasure Q (M.numeraire T) (N T) b₀ n₀) (.pay T a) + = n₀ * ∫ ω, a.eval (scenarioAt M.asset ω) / N T ω + ∂(numeraireMeasure Q (M.numeraire T) (N T) b₀ n₀) := by + rw [price, Contract.value_pay, ← integral_const_mul] + refine integral_congr_ae (.of_forall fun ω ↦ ?_) + simp only [deflator, withNumeraire, hN₀] + ring + _ = b₀ * ∫ ω, a.eval (scenarioAt M.asset ω) / M.numeraire T ω ∂Q := + changeOfNumeraire _ ((hNa T).mono (M.𝓕.le T)).measurable (M.measurable_numeraire T) + (hN T) (M.numeraire_pos T) hb₀.le hn₀ + _ = M.price Q (.pay T a) := by + rw [price, Contract.value_pay, ← integral_const_mul] + refine integral_congr_ae (.of_forall fun ω ↦ ?_) + simp only [deflator, hB₀] + ring + +/-! ### Finite sample spaces: state prices -/ + +/-- The state price of `ω` for a payment at `t`: the deflator at `t` times the `Q`-mass of `ω`. -/ +noncomputable def statePrice (M : Market ι Ω) (Q : Measure Ω) (t : ℝ≥0) (ω : Ω) : ℝ := + M.deflator t ω * Q.real {ω} + +theorem statePrice_nonneg (M : Market ι Ω) (Q : Measure Ω) (t : ℝ≥0) (ω : Ω) : + 0 ≤ M.statePrice Q t ω := + mul_nonneg (M.deflator_pos t ω).le measureReal_nonneg + +/-- **On a finite sample space, the price of a payment is state-price pricing**: the payment at +`t` of a payoff `a` is worth `∑ ω, q ω · a(ω)` with the state prices `q ω = (N 0 / N t)(ω) Q {ω}`, +for every finite measure `Q`. -/ +theorem price_pay_eq_statePricePricing [Fintype Ω] [MeasurableSingletonClass Ω] + (M : Market ι Ω) (Q : Measure Ω) [IsFiniteMeasure Q] (t : ℝ≥0) (a : Payoff ι) : + M.price Q (.pay t a) + = statePricePricing Finset.univ (M.statePrice Q t) fun ω ↦ a.eval (scenarioAt M.asset ω) := by + rw [price, Contract.value_pay, integral_fintype Integrable.of_finite, statePricePricing] + exact Finset.sum_congr rfl fun ω _ ↦ by simp only [statePrice, smul_eq_mul]; ring + +end Market + +end MathFin diff --git a/LeanPool/MathFin/Pricing/NoArbitrageCore.lean b/LeanPool/MathFin/Pricing/NoArbitrageCore.lean new file mode 100644 index 0000000000..5295713a73 --- /dev/null +++ b/LeanPool/MathFin/Pricing/NoArbitrageCore.lean @@ -0,0 +1,80 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Martingale.Basic + +/-! +# No-arbitrage core: a nonnegative zero-mean payoff vanishes + +The shared analytic heart of the forward FTAP. A `Q`-integrable +`f` that is `Q`-a.s. nonnegative with `∫ f dQ = 0` is `Q`-a.s. zero, so its positive set is +`Q`-null (`ae_zero_of_nonneg_of_integral_zero`). The zero integral comes from a martingale +transform started at `0` (`martingale_nonneg_terminal_ae_zero`, below), which is what the +discrete-time `IsEMM.noArbitrage` does; the one-period, finite-Ω and continuous-time +(`ContinuousMarket.isEMM_noArbitrageSimple`, through sampling) forward directions are its +instances. `ae_eq_zero_of_nonneg_of_null_pos` turns the null positive set into +the `=ᵐ 0` form of the no-arbitrage definitions. + +## Main results + +* `ae_zero_of_nonneg_of_integral_zero`: a `Q`-integrable, `Q`-a.s. nonnegative `f` with + `∫ f dQ = 0` has `Q {f > 0} = 0`. +* `ae_eq_zero_of_nonneg_of_null_pos`: an a.s. nonnegative `f` with null positive set is a.e. + zero. +* `martingale_nonneg_terminal_ae_zero`: for a `Q`-martingale `V` on `ℕ` with `V 0 = 0` and + `V T ≥ 0` a.s., `Q {V T > 0} = 0`. + +## Tags + +no arbitrage, fundamental theorem of asset pricing, nonnegative zero-mean payoff, +equivalent martingale measure, martingale transform, MSC 91G20, MSC 60G42, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory + +/-- **A nonnegative payoff with zero mean vanishes a.s.** If `f` is `Q`-integrable, `Q`-a.s. +nonnegative, and has `∫ f dQ = 0`, then `{f > 0}` is `Q`-null. The common closing step of the +forward FTAP in every setting. -/ +theorem ae_zero_of_nonneg_of_integral_zero + {Ω : Type*} [MeasurableSpace Ω] {Q : Measure Ω} {f : Ω → ℝ} + (hf_int : Integrable f Q) (hf_nonneg : 0 ≤ᵐ[Q] f) (hf0 : ∫ ω, f ω ∂Q = 0) : + Q {ω | 0 < f ω} = 0 := by + have hf_zero : f =ᵐ[Q] 0 := (integral_eq_zero_iff_of_nonneg_ae hf_nonneg hf_int).mp hf0 + exact measure_mono_null (fun ω hω ↦ ne_of_gt hω) (ae_iff.mp hf_zero) + +/-- **A nonnegative payoff with a null positive set is a.e. zero.** The no-arbitrage +definitions of every setting conclude `=ᵐ[P] 0`; the forward FTAP produces the null positive +set. -/ +theorem ae_eq_zero_of_nonneg_of_null_pos + {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {f : Ω → ℝ} + (hnn : 0 ≤ᵐ[P] f) (h : P {ω | 0 < f ω} = 0) : f =ᵐ[P] 0 := by + filter_upwards [hnn, measure_eq_zero_iff_ae_notMem.mp h] with ω h1 h2 + exact le_antisymm (not_lt.mp h2) h1 + +/-- **A nonnegative martingale started at `0` vanishes at the terminal time.** The discrete +forward FTAP's route to zero mean: `∫ V_T dQ = ∫ V_0 dQ = 0`, then +`ae_zero_of_nonneg_of_integral_zero`. -/ +theorem martingale_nonneg_terminal_ae_zero + {Ω : Type*} [m0 : MeasurableSpace Ω] {Q : Measure Ω} [IsProbabilityMeasure Q] + {𝓕 : Filtration ℕ m0} {V : ℕ → Ω → ℝ} + (hV : Martingale V 𝓕 Q) (hV0 : V 0 = 0) {T : ℕ} (hVT : 0 ≤ᵐ[Q] V T) : + Q {ω | 0 < V T ω} = 0 := by + have hVT_int : ∫ ω, V T ω ∂Q = 0 := by + have : ∫ ω, V T ω ∂Q = ∫ ω, V 0 ω ∂Q := by + rw [(integral_condExp (𝓕.le 0)).symm] + exact integral_congr_ae (hV.condExp_ae_eq (Nat.zero_le T)) + rw [this, hV0]; simp + exact ae_zero_of_nonneg_of_integral_zero (hV.integrable T) hVT hVT_int + +end MathFin diff --git a/LeanPool/MathFin/Pricing/NoArbitrageDerivations.lean b/LeanPool/MathFin/Pricing/NoArbitrageDerivations.lean new file mode 100644 index 0000000000..8933bbe6c3 --- /dev/null +++ b/LeanPool/MathFin/Pricing/NoArbitrageDerivations.lean @@ -0,0 +1,158 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.StatePrices + +/-! +# Core quant-finance results derived from no-arbitrage (first principles) + +This file derives the canonical static no-arbitrage relations — **put-call +parity** and the **forward price** — from a single structural object: a +non-negative linear pricing functional on payoffs. + +The pattern: a "market" is parameterised by + +* a finite state space `s : Finset ι`, +* non-negative state prices `q : ι → ℝ` (`hq : 0 ≤ q i`), +* terminal asset values `S : ι → ℝ`, + +with two structural constraints: + +* **Bond pricing**: `∑ q i = DF`, where `DF` is the time-0 price of a + contract paying `1` at maturity in every state. +* **Stock pricing**: `∑ q i · S i = S_0`, where `S_0` is the time-0 spot + price of the asset. + +A general claim with payoff `g : ι → ℝ` has time-0 price `Λ(g) := statePricePricing s q g` +(`Pricing/StatePrices.lean`, `∑ q i · g i`). This `Λ` is a non-negative linear +functional, and its linearity lemmas (`statePricePricing_add`, `_smul`, `_const`) are what the +derivations below use. The state prices are an EMM scaled by the discount factor: the bridge +`exists_statePrices_of_hasEMM` (`Pricing/FTAP/FTAPMultiState.lean`) produces `q` with the bond +and stock constraints from `HasEMMMultiState`. + +## Why this is "first principles" + +The pre-existing `bsP_eq_bsV` (in `Models.BlackScholes.PutGreeks`) is an *algebraic* +verification: starting from the closed forms `bsV` and `bsP`, prove they +differ by `S - K · e^{-rτ}`. The proof is `unfold` + `linear_combination` +on the gaussian-CDF identity `Φ(x) + Φ(-x) = 1`. + +The *first-principles* version below — `putCall_parity_from_no_arbitrage` — +makes no reference to `bsV`, `bsP`, the BS formula, or any closed form. It +says: whenever a market admits a non-negative linear pricing functional +with the bond and stock constraints, *any* call and put prices satisfy +parity. The proof is two lines: + +1. Pointwise: `max(S - K, 0) - max(K - S, 0) = S - K`. +2. Linearity of `Λ`: `Λ(C-payoff) - Λ(P-payoff) = Λ(S - K) = S_0 - K · DF`. + +The same template gives the forward price `F = S_0 / DF`. + +## Main results + +* `putCall_parity_from_no_arbitrage`: the parity derivation. +* `forward_price_from_no_arbitrage`: the forward price characterisation. + +## Tags + +put–call parity, forward price, state prices, linear pricing functional, +static no-arbitrage relations, cost of carry, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Finset + +/-- **Put-call parity from no-arbitrage** (first-principles derivation). + +In a finite-state market with non-negative state prices `q : ι → ℝ`, +terminal asset values `S : ι → ℝ`, discount factor `DF = ∑ q i`, and spot +price `S_0 = statePricePricing s q S`, the call price +`C(K) = statePricePricing s q (max(S − K, 0))` and the put price +`P(K) = statePricePricing s q (max(K − S, 0))` satisfy + + `C(K) − P(K) = S_0 − K · DF`. + +The proof has *no reference to the Black-Scholes formula*. It uses only: +* linearity of the pricing functional `statePricePricing s q`, +* the pointwise payoff identity `max(S - K, 0) - max(K - S, 0) = S - K` + (`max_zero_sub_max_neg_zero_eq_self`), +* the bond and stock pricing constraints. + +Specialisation to the BS model recovers `bsP_eq_bsV` (currently proved +algebraically); the algebraic proof there can now be seen as +"the BS closed forms are realised by some such pricing functional." -/ +theorem putCall_parity_from_no_arbitrage + {ι : Type*} (s : Finset ι) (q : ι → ℝ) (S : ι → ℝ) + (DF S₀ K : ℝ) + (h_bond : ∑ i ∈ s, q i = DF) + (h_stock : statePricePricing s q S = S₀) : + statePricePricing s q (fun i ↦ max (S i - K) 0) + - statePricePricing s q (fun i ↦ max (K - S i) 0) = S₀ - K * DF := by + -- pointwise: `max(S i − K, 0) + (−1) · max(K − S i, 0) = S i + (−K)` + have h_payoff : (fun i ↦ max (S i - K) 0 + (-1) * max (K - S i) 0) = fun i ↦ S i + (-K) := + funext fun i ↦ by + have h := max_zero_sub_max_neg_zero_eq_self (S i - K) + rw [show -(S i - K) = K - S i from by ring] at h + linarith + calc statePricePricing s q (fun i ↦ max (S i - K) 0) + - statePricePricing s q (fun i ↦ max (K - S i) 0) + = statePricePricing s q (fun i ↦ max (S i - K) 0 + (-1) * max (K - S i) 0) := by + rw [statePricePricing_add, statePricePricing_smul]; ring + _ = statePricePricing s q (fun i ↦ S i + (-K)) := by rw [h_payoff] + _ = S₀ - K * DF := by + rw [statePricePricing_add, statePricePricing_const, h_stock, h_bond]; ring + +/-- **Forward price from no-arbitrage** (first-principles derivation). + +The fair forward price `F` — the strike at which the forward contract +with terminal payoff `S_T − F` has zero time-0 price — is + + `F = S_0 / DF`. + +With continuous compounding (`DF = e^{−rT}`), this is the classical +`F = S_0 · e^{rT}` cash-and-carry formula. + +The proof: by linearity, `Λ(S_T − F) = Λ(S_T) − F · Λ(1) = S_0 − F · DF`. +Setting this equal to zero and solving gives `F = S_0 / DF`. -/ +theorem forward_price_from_no_arbitrage + {ι : Type*} (s : Finset ι) (q : ι → ℝ) (S : ι → ℝ) + (DF S₀ F : ℝ) (hDF : DF ≠ 0) + (h_bond : ∑ i ∈ s, q i = DF) + (h_stock : statePricePricing s q S = S₀) : + statePricePricing s q (fun i ↦ S i - F) = 0 ↔ F = S₀ / DF := by + -- Λ(S - F) = Λ(S) - F · Λ(1) = S_0 - F · DF. + have h_eval : statePricePricing s q (fun i ↦ S i - F) = S₀ - F * DF := by + rw [show (fun i ↦ S i - F) = fun i ↦ S i + (-F) from funext fun i ↦ sub_eq_add_neg _ _, + statePricePricing_add, statePricePricing_const, h_stock, h_bond] + ring + rw [h_eval] + constructor + · intro h + have : F * DF = S₀ := by linarith + field_simp + linarith + · intro hF + rw [hF]; field_simp; ring + +/-- **Forward price (closed form)**: the unique fair forward is `F = S_0 / DF`. -/ +theorem forward_price_eq_spot_div_discount + {ι : Type*} (s : Finset ι) (q : ι → ℝ) (S : ι → ℝ) + (DF S₀ : ℝ) (hDF : DF ≠ 0) + (h_bond : ∑ i ∈ s, q i = DF) + (h_stock : statePricePricing s q S = S₀) : + ∃! F : ℝ, statePricePricing s q (fun i ↦ S i - F) = 0 := by + refine ⟨S₀ / DF, ?_, ?_⟩ + · exact (forward_price_from_no_arbitrage s q S DF S₀ (S₀ / DF) hDF h_bond h_stock).mpr rfl + · intro F hF + exact (forward_price_from_no_arbitrage s q S DF S₀ F hDF h_bond h_stock).mp hF + +end MathFin diff --git a/LeanPool/MathFin/Pricing/Numeraire.lean b/LeanPool/MathFin/Pricing/Numeraire.lean new file mode 100644 index 0000000000..3d435db414 --- /dev/null +++ b/LeanPool/MathFin/Pricing/Numeraire.lean @@ -0,0 +1,234 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Martingales.ChangeOfMeasure +public import LeanPool.MathFin.Probability.Martingales.EquivMeasure + +/-! +# The change of numéraire + +A **numéraire** is a strictly positive traded asset taken as the unit of +account. Fix a pricing measure `Q` associated to a reference numéraire `B` (the +money market): the arbitrage-free price of a terminal claim `X` is + + `price(X) = B₀ · 𝔼^Q[X / B_T]`. + +Given a second numéraire `N` — strictly positive, with `N/B` a `Q`-martingale +(the tradeability/normalization condition `𝔼^Q[N_T/B_T] = N₀/B₀`) — define the +**numéraire measure** `Q^N` by the Radon–Nikodym density + + `dQ^N/dQ := (N_T · B₀) / (N₀ · B_T)`. + +The **change-of-numéraire theorem** (`changeOfNumeraire`) is that price is +numéraire-invariant: + + `N₀ · 𝔼^{Q^N}[X / N_T] = B₀ · 𝔼^Q[X / B_T]`. + +The proof is a one-line cancellation: transporting the `Q^N`-expectation back to +`Q` multiplies the integrand `X/N_T` by the density `(N_T·B₀)/(N₀·B_T)`, and the +`N_T` cancels, leaving `(B₀/N₀)·(X/B_T)`; the leading `N₀` cancels the `1/N₀`. +Notably the identity needs **no integrability hypothesis** — it is a pure +measure-transport identity (`integral_withDensity_eq_integral_toReal_smul`) +followed by scalar algebra, so it holds verbatim whether or not the claim is +square-integrable. + +This is the abstract backbone of every concrete numéraire change in the library. +The stock numéraire (`Models.BlackScholes.StockNumeraire`: `Φ(d₁)` as the stock-measure +exercise probability) is the instance `B_T = e^{rT}`, `B₀ = 1`, `N = S`; the +second-asset numéraire of the exchange option (`Models.BlackScholes.ExchangeOption`) +and the forward/annuity numéraires of the Garman normal form +(`Models.BlackScholes.GarmanNormalForm`) are further instances — each recovered by +choosing `B`, `N` and reading off the density. + +## Main definitions + +* `numeraireDensity`: the `[0, ∞]`-valued Radon–Nikodym derivative `(N_T · B₀) / (N₀ · B_T)`. +* `numeraireMeasure`: the measure `Q^N = Q.withDensity` of that density. + +## Main results + +* `MathFin.numeraireMeasure_isEquivProbMeasure` — `Q^N` is a probability measure + equivalent to `Q` (`Q^N ≪ Q` and `Q ≪ Q^N`), under the martingale/normalization + condition `𝔼^Q[N_T/B_T] = N₀/B₀`; `numeraireMeasure_isProbabilityMeasure` is its first + component. +* `MathFin.changeOfNumeraire` — price invariance + `N₀·𝔼^{Q^N}[X/N_T] = B₀·𝔼^Q[X/B_T]`. +* `MathFin.changeOfNumeraire_setIntegral_eq` — the **dynamic** change of numéraire: if + `t ↦ (B₀/N₀)(X_t/B_t)` and `t ↦ (B₀/N₀)(N_t/B_t)` are `Q`-martingales (and the mixed product is + integrable) then `X/N` has the set-integral martingale property under `Q^N`. Obtained by + instantiating the Bayes engine `changeOfMeasure_setIntegral_eq` at density process + `Z_t = (N_t·B₀)/(N₀·B_t)` and payoff `D_t = X_t/N_t` — wiring the numéraire seam to the Girsanov + engine. + +## References + +* [H. Geman, N. El Karoui and J. C. Rochet, *Changes of numéraire, changes of probability measure + and option pricing*][GemanElKarouiRochet1995] + +## Tags + +change of numéraire, numeraire measure, Radon–Nikodym density, risk-neutral measure, +forward measure, price invariance, Geman–El Karoui–Rochet, MSC 91G20, MSC 60G44, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory +open scoped ENNReal + +variable {Ω : Type*} + +/-- **The numéraire-change density** `dQ^N/dQ = (N_T · B₀)/(N₀ · B_T)`, as a +`[0,∞]`-valued Radon–Nikodym derivative. Nonnegative whenever the numéraires are +positive. -/ +noncomputable def numeraireDensity (BT NT : Ω → ℝ) (B0 N0 : ℝ) : Ω → ℝ≥0∞ := + fun ω ↦ ENNReal.ofReal (NT ω * B0 / (N0 * BT ω)) + +/-- The numéraire density is a nonnegative real when both numéraires are +positive. -/ +lemma numeraireDensity_toReal_nonneg {BT NT : Ω → ℝ} {B0 N0 : ℝ} + (hNTpos : ∀ ω, 0 < NT ω) (hBTpos : ∀ ω, 0 < BT ω) + (hB0 : 0 ≤ B0) (hN0 : 0 < N0) (ω : Ω) : + 0 ≤ NT ω * B0 / (N0 * BT ω) := + div_nonneg (mul_nonneg (hNTpos ω).le hB0) (mul_nonneg hN0.le (hBTpos ω).le) + +/-- **The numéraire measure** `Q^N := Q.withDensity((N_T·B₀)/(N₀·B_T))`: the +pricing measure attached to numéraire `N`. -/ +noncomputable def numeraireMeasure [MeasurableSpace Ω] + (Q : Measure Ω) (BT NT : Ω → ℝ) (B0 N0 : ℝ) : Measure Ω := + Q.withDensity (numeraireDensity BT NT B0 N0) + +section + +variable [MeasurableSpace Ω] {Q : Measure Ω} {BT NT : Ω → ℝ} {B0 N0 : ℝ} + +/-- **The numéraire measure is an equivalent probability measure.** Under the tradeability / +normalization condition `𝔼^Q[N_T/B_T] = N₀/B₀` (equivalently: `N/B` is a `Q`-martingale), the +density `(N_T·B₀)/(N₀·B_T)` is strictly positive with `Q`-mean `(B₀/N₀)·(N₀/B₀) = 1`, so +`Q^N` is a probability measure with `Q^N ≪ Q` and `Q ≪ Q^N` (`isEquivProbMeasure_withDensity`). -/ +theorem numeraireMeasure_isEquivProbMeasure + (hNTpos : ∀ ω, 0 < NT ω) (hBTpos : ∀ ω, 0 < BT ω) (hB0 : 0 < B0) (hN0 : 0 < N0) + (hint : Integrable (fun ω ↦ NT ω / BT ω) Q) + (hmart : ∫ ω, NT ω / BT ω ∂Q = N0 / B0) : + IsEquivProbMeasure Q (numeraireMeasure Q BT NT B0 N0) := by + have heq : (fun ω ↦ NT ω * B0 / (N0 * BT ω)) = fun ω ↦ (B0 / N0) * (NT ω / BT ω) := by + funext ω; ring + refine isEquivProbMeasure_withDensity Q (g := fun ω ↦ NT ω * B0 / (N0 * BT ω)) + (fun ω ↦ div_pos (mul_pos (hNTpos ω) hB0) (mul_pos hN0 (hBTpos ω))) + (by rw [heq]; exact hint.const_mul _) ?_ + rw [heq, integral_const_mul, hmart] + field_simp + +/-- **The numéraire measure is a probability measure** — the first component of +`numeraireMeasure_isEquivProbMeasure`, under the same normalization condition +`𝔼^Q[N_T/B_T] = N₀/B₀`. -/ +theorem numeraireMeasure_isProbabilityMeasure + (hNTpos : ∀ ω, 0 < NT ω) (hBTpos : ∀ ω, 0 < BT ω) (hB0 : 0 < B0) (hN0 : 0 < N0) + (hint : Integrable (fun ω ↦ NT ω / BT ω) Q) + (hmart : ∫ ω, NT ω / BT ω ∂Q = N0 / B0) : + IsProbabilityMeasure (numeraireMeasure Q BT NT B0 N0) := + (numeraireMeasure_isEquivProbMeasure hNTpos hBTpos hB0 hN0 hint hmart).isProb + +/-- **The change-of-numéraire theorem.** Price is numéraire-invariant: + + `N₀ · 𝔼^{Q^N}[X / N_T] = B₀ · 𝔼^Q[X / B_T]`, + +where `Q^N = Q.withDensity((N_T·B₀)/(N₀·B_T))`. The proof transports the +`Q^N`-integral back to `Q` (multiplying by the density) and cancels `N_T`; no +integrability hypothesis is needed. -/ +theorem changeOfNumeraire (X : Ω → ℝ) + (hNTmeas : Measurable NT) (hBTmeas : Measurable BT) + (hNTpos : ∀ ω, 0 < NT ω) (hBTpos : ∀ ω, 0 < BT ω) (hB0 : 0 ≤ B0) (hN0 : 0 < N0) : + N0 * ∫ ω, X ω / NT ω ∂(numeraireMeasure Q BT NT B0 N0) + = B0 * ∫ ω, X ω / BT ω ∂Q := by + have hden : numeraireMeasure Q BT NT B0 N0 + = Q.withDensity (fun ω ↦ ENNReal.ofReal (NT ω * B0 / (N0 * BT ω))) := rfl + have hdmeas : Measurable fun ω ↦ NT ω * B0 / (N0 * BT ω) := + (hNTmeas.mul measurable_const).div (measurable_const.mul hBTmeas) + rw [hden, integral_withDensity_eq_integral_toReal_smul hdmeas.ennreal_ofReal + (ae_of_all _ fun _ ↦ ENNReal.ofReal_lt_top)] + have hcongr : ∀ ω, (ENNReal.ofReal (NT ω * B0 / (N0 * BT ω))).toReal • (X ω / NT ω) + = (B0 / N0) * (X ω / BT ω) := by + intro ω + rw [ENNReal.toReal_ofReal (numeraireDensity_toReal_nonneg hNTpos hBTpos hB0 hN0 ω), + smul_eq_mul] + field_simp [(hNTpos ω).ne', (hBTpos ω).ne', hN0.ne'] + simp_rw [hcongr, integral_const_mul] + have hcancel : N0 * (B0 / N0 * ∫ ω, X ω / BT ω ∂Q) = B0 * ∫ ω, X ω / BT ω ∂Q := by + field_simp [hN0.ne'] + exact hcancel + +end + +section Dynamic + +open scoped NNReal + +variable {mΩ : MeasurableSpace Ω} {Q : Measure Ω} [IsFiniteMeasure Q] + {𝓕 : Filtration ℝ≥0 mΩ} [SigmaFiniteFiltration Q 𝓕] + {B N X : ℝ≥0 → Ω → ℝ} {B0 N0 : ℝ} + +omit [IsFiniteMeasure Q] in +/-- **The dynamic change-of-numéraire theorem** (set-integral form). Fix a pricing +measure `Q` for the reference numéraire `B` and a second strictly positive numéraire +`N`, both adapted, with the normalisation process `t ↦ (B₀/N₀)(N_t/B_t)` a +`Q`-martingale (`hNB` — the dynamic form of `𝔼^Q[N_T/B_T] = N₀/B₀`). If the discounted +claim `t ↦ (B₀/N₀)(X_t/B_t)` is a `Q`-martingale (`hXB`), then `X/N` has the +`Q^N`-martingale (set-integral) property under the numéraire measure +`Q^N = Q.withDensity((N_T·B₀)/(N₀·B_T))`: for `s ≤ t ≤ T` and `A ∈ 𝓕_s`, the +`Q^N`-integrals of `X_t/N_t` and `X_s/N_s` over `A` agree. + +This is the **Bayes engine** `changeOfMeasure_setIntegral_eq` instantiated at the +density process `Z_t = (N_t·B₀)/(N₀·B_t)` and payoff process `D_t = X_t/N_t`, whose +product `Z_t·D_t = (B₀/N₀)(X_t/B_t)` is exactly `hXB` (the `N_t` cancels). It wires the +change-of-numéraire seam to the Girsanov change-of-measure engine. The tilted measure +is definitionally `numeraireMeasure Q (B T) (N T) B0 N0`. -/ +theorem changeOfNumeraire_setIntegral_eq (T : ℝ≥0) + (hNpos : ∀ u ω, 0 < N u ω) (hBpos : ∀ u ω, 0 < B u ω) + (hB0 : 0 ≤ B0) (hN0 : 0 < N0) + (hNmeas : ∀ u, Measurable (N u)) (hBmeas : ∀ u, Measurable (B u)) + (hDsm : ∀ u, StronglyMeasurable[𝓕 u] (fun ω ↦ X u ω / N u ω)) + (hNB : Martingale (fun t ω ↦ (B0 / N0) * (N t ω / B t ω)) 𝓕 Q) + (hXB : Martingale (fun t ω ↦ (B0 / N0) * (X t ω / B t ω)) 𝓕 Q) + (hmix : ∀ u, u ≤ T → + Integrable (fun ω ↦ X u ω / N u ω * (N T ω * B0 / (N0 * B T ω))) Q) + {s t : ℝ≥0} (hst : s ≤ t) (htT : t ≤ T) + {A : Set Ω} (hA : MeasurableSet[𝓕 s] A) : + ∫ ω in A, X t ω / N t ω + ∂(Q.withDensity (fun ω ↦ ENNReal.ofReal (N T ω * B0 / (N0 * B T ω)))) + = ∫ ω in A, X s ω / N s ω + ∂(Q.withDensity (fun ω ↦ ENNReal.ofReal (N T ω * B0 / (N0 * B T ω)))) := by + -- The density `Z_T = (N_T·B₀)/(N₀·B_T)` is measurable and nonnegative. + have hZmeasT : Measurable (fun ω ↦ N T ω * B0 / (N0 * B T ω)) := + ((hNmeas T).mul measurable_const).div (measurable_const.mul (hBmeas T)) + have hZpos : ∀ ω, 0 ≤ N T ω * B0 / (N0 * B T ω) := fun ω ↦ + div_nonneg (mul_nonneg (hNpos T ω).le hB0) (mul_nonneg hN0.le (hBpos T ω).le) + -- `Z_t = (N_t·B₀)/(N₀·B_t) = (B₀/N₀)(N_t/B_t)` is the normalisation martingale `hNB`. + have hZ : Martingale (fun u ω ↦ N u ω * B0 / (N0 * B u ω)) 𝓕 Q := by + have hfeq : (fun u (ω : Ω) ↦ N u ω * B0 / (N0 * B u ω)) + = fun u ω ↦ (B0 / N0) * (N u ω / B u ω) := by + funext u ω; ring + rw [hfeq]; exact hNB + -- `Z_t·D_t = (B₀/N₀)(X_t/B_t)` — the `N_t` cancels — is the martingale `hXB`. + have hZD : Martingale + (fun t ω ↦ N t ω * B0 / (N0 * B t ω) * (X t ω / N t ω)) 𝓕 Q := by + have hfeq : (fun t (ω : Ω) ↦ N t ω * B0 / (N0 * B t ω) * (X t ω / N t ω)) + = fun t ω ↦ (B0 / N0) * (X t ω / B t ω) := by + funext u ω + field_simp [hN0.ne', (hNpos u ω).ne', (hBpos u ω).ne'] + rw [hfeq]; exact hXB + -- Instantiate the Bayes engine at `Z_t = (N_t·B₀)/(N₀·B_t)`, `D_t = X_t/N_t`. + exact changeOfMeasure_setIntegral_eq (Z := fun u ω ↦ N u ω * B0 / (N0 * B u ω)) + (D := fun u ω ↦ X u ω / N u ω) T hZmeasT hZpos hDsm hZ hZD hmix hst htT hA + +end Dynamic + +end MathFin diff --git a/LeanPool/MathFin/Pricing/OneDateMarket.lean b/LeanPool/MathFin/Pricing/OneDateMarket.lean new file mode 100644 index 0000000000..da0e0fbb2f --- /dev/null +++ b/LeanPool/MathFin/Pricing/OneDateMarket.lean @@ -0,0 +1,265 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.Market +public import LeanPool.MathFin.Probability.Martingales.TimeChange + +/-! +# The one-date market + +The smallest market with a pricing measure, and the one a closed-form family reads in when it +prices at a single date: one traded asset that is quoted at its initial price `s₀` (growing at the +rate `r` of the money market, so that the deflated price is the constant `s₀`) until a date `τ`, +and at a random value `X` from `τ` on, with the money market `e^{rt}` as numéraire and no +information before `τ` (`Market.oneDate`). + +Up to the horizon `τ`, the deflated asset is a martingale for a measure `Q` exactly when it is a +probability measure for which `X` is integrable with `𝔼_Q[X] = s₀ e^{rτ}`. With `Q` equivalent to +the reference measure `P`, it is a pricing measure (`Market.isPricingMeasure_oneDate`). The +information is the time change of the two-step filtration `⊥ ≤ mΩ` along the date `τ` +(`Market.dateFiltration`), so the martingale is that of `martingale_min_of_condExp_succ`, read +along the time change (`Martingale.comp`). + +The price of a contract that reads the asset at `τ` only is the integral against `Q` of its payoff, +discounted by `e^{−rτ}` (`Market.price_pay_obs_oneDate`, `Market.price_europeanCall_oneDate`). + +The model is as small as can be: the initial price is a parameter, with no dynamics before `τ`, +so that a measure prices the market says only that it is equivalent to `P` and calibrated to the +quote `s₀`. A family's socket here certifies that its law prices a market, and the work is in the +family's own moment identity (the Esscher or Merton compensator, the tilted mean). +The families that instantiate it (`Models/Jumps/Market.lean`, `Insurance/EsscherPremium.lean`) say +which law of `X` and which `Q` they read in it. + +## Main definitions + +* `Market.oneDate`: the market of a terminal value `X`, an initial price `s₀`, a rate `r` and a + date `τ`. +* `Market.dateFiltration`: the information of the market, nothing before `τ` and everything from + `τ` on. + +## Main results + +* `Market.isPricingMeasure_oneDate`: a probability measure equivalent to `P`, with `X` integrable + and `𝔼_Q[X] = s₀ e^{rτ}`, is a pricing measure up to `τ`. +* `Market.integral_eq_of_isPricingMeasure_oneDate`: the converse for `τ > 0`: a pricing measure + makes `X` integrable with mean `s₀ e^{rτ}`. +* `Market.price_pay_obs_oneDate`: the claim paying the asset at `τ` is worth `𝔼_Q[e^{−rτ} X]`. +* `Market.price_europeanCall_oneDate`: the call struck at `K` is worth `𝔼_Q[e^{−rτ} (X − K)⁺]`. + +## References + +* [J. M. Harrison and S. R. Pliska, *Martingales and stochastic integrals in the theory of + continuous trading*][HarrisonPliska1981] +* [H. Föllmer and A. Schied, *Stochastic Finance: An Introduction in Discrete Time*][FollmerSchied], + §5.2 + +## Tags + +one-period market, pricing measure, equivalent martingale measure, risk-neutral pricing, +MSC 91G20, MSC 60G44, JEL G13 +-/ + +@[expose] public section + +open MeasureTheory MathFin.Contracts +open scoped NNReal + +namespace MathFin.Market + +/-- The two-step filtration of `ℕ`: nothing is known at `0`, everything from `1` on. -/ +def twoStepFiltration (Ω : Type*) [mΩ : MeasurableSpace Ω] : Filtration ℕ mΩ where + seq n := if n = 0 then ⊥ else mΩ + mono' a b hab := by + dsimp only + split_ifs with ha hb hb + · exact le_rfl + · exact bot_le + · exact absurd (Nat.le_zero.mp (hb ▸ hab)) ha + · exact le_rfl + le' := fun n ↦ by + split_ifs + · exact bot_le + · exact le_rfl + +section TwoStep + +variable (Ω : Type*) [mΩ : MeasurableSpace Ω] + +theorem twoStepFiltration_zero : twoStepFiltration Ω 0 = ⊥ := rfl + +theorem twoStepFiltration_one : twoStepFiltration Ω 1 = mΩ := rfl + +end TwoStep + +/-- The step of a date: `0` before `τ`, `1` from `τ` on. -/ +noncomputable def dateStep (τ t : ℝ≥0) : ℕ := if t < τ then 0 else 1 + +theorem monotone_dateStep (τ : ℝ≥0) : Monotone (dateStep τ) := by + intro a b hab + by_cases hb : b < τ + · simp [dateStep, hb, hab.trans_lt hb] + · by_cases ha : a < τ <;> simp [dateStep, ha, hb] + +theorem dateStep_of_lt {τ t : ℝ≥0} (h : t < τ) : dateStep τ t = 0 := by simp [dateStep, h] + +theorem dateStep_of_not_lt {τ t : ℝ≥0} (h : ¬ t < τ) : dateStep τ t = 1 := by simp [dateStep, h] + +/-- **The information of the one-date market**: nothing is known before `τ`, everything from `τ` +on. It is the two-step filtration read along the step of the date. -/ +noncomputable def dateFiltration (Ω : Type*) [mΩ : MeasurableSpace Ω] (τ : ℝ≥0) : + Filtration ℝ≥0 mΩ := + (twoStepFiltration Ω).comp (monotone_dateStep τ) + +section DateFiltration + +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {τ t : ℝ≥0} + +theorem dateFiltration_of_lt (h : t < τ) : dateFiltration Ω τ t = ⊥ := by + rw [dateFiltration, Filtration.comp_apply, dateStep_of_lt h, twoStepFiltration_zero] + +theorem dateFiltration_of_not_lt (h : ¬ t < τ) : dateFiltration Ω τ t = mΩ := by + rw [dateFiltration, Filtration.comp_apply, dateStep_of_not_lt h, twoStepFiltration_one] + +end DateFiltration + +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] + +/-- **The one-date market**: one asset, quoted at `s₀ e^{rt}` before the date `τ` and at the +random value `X` from `τ` on, with the money market `e^{rt}` as numéraire, no information before +`τ` (`dateFiltration`) and the reference measure `P`. The deflated asset is `s₀` before `τ` and +`X e^{−rτ}` at `τ`. -/ +noncomputable def oneDate (P : Measure Ω) {X : Ω → ℝ} (hX : Measurable X) (s₀ r : ℝ) (τ : ℝ≥0) : + Market Unit Ω where + P := P + 𝓕 := dateFiltration Ω τ + asset _ t ω := if t < τ then s₀ * Real.exp (r * t) else X ω + numeraire t _ := Real.exp (r * t) + numeraire_pos _ _ := Real.exp_pos _ + asset_adapted _ t := by + by_cases h : t < τ + · simp only [h, ↓reduceIte] + have hc : StronglyMeasurable[(⊥ : MeasurableSpace Ω)] + (fun _ : Ω ↦ s₀ * Real.exp (r * t)) := stronglyMeasurable_const + exact hc.mono (dateFiltration_of_lt h).ge + · simp only [h, ↓reduceIte] + exact hX.stronglyMeasurable.mono (dateFiltration_of_not_lt h).ge + numeraire_adapted _ := stronglyMeasurable_const + +variable (P : Measure Ω) {X : Ω → ℝ} (hX : Measurable X) (s₀ r : ℝ) (τ : ℝ≥0) + +/-- The asset of the one-date market at the date `τ` is `X`. -/ +theorem asset_oneDate_self (ω : Ω) : (oneDate P hX s₀ r τ).asset () τ ω = X ω := by + simp [oneDate] + +/-- The deflator of the one-date market at `τ` is the discount `e^{−rτ}`. -/ +theorem deflator_oneDate (ω : Ω) : (oneDate P hX s₀ r τ).deflator τ ω = Real.exp (-r * τ) := + Market.deflator_of_numeraire_exp (fun _ _ ↦ rfl) τ ω + +/-- The deflated price at step `0` is `s₀`, and from step `1` on it is `X e^{−rτ}`. -/ +noncomputable def deflatedStep (X : Ω → ℝ) (s₀ r : ℝ) (τ : ℝ≥0) : ℕ → Ω → ℝ + | 0 => fun _ ↦ s₀ + | _ + 1 => fun ω ↦ X ω / Real.exp (r * τ) + +/-- **The deflated asset, frozen at `τ`, is the deflated step process read along the date**: +`S_tilde (min t τ) = g (min (step t) 1)`. -/ +theorem deflated_oneDate_min (i : Unit) (t : ℝ≥0) (ω : Ω) : + (oneDate P hX s₀ r τ).deflated i (min t τ) ω + = deflatedStep X s₀ r τ (min (dateStep τ t) 1) ω := by + by_cases h : t < τ + · rw [dateStep_of_lt h, Nat.zero_min] + change (if min t τ < τ then s₀ * Real.exp (r * ((min t τ : ℝ≥0) : ℝ)) else X ω) + / Real.exp (r * ((min t τ : ℝ≥0) : ℝ)) = s₀ + rw [min_eq_left h.le] + simp only [h, ↓reduceIte] + exact mul_div_cancel_right₀ _ (Real.exp_pos _).ne' + · rw [dateStep_of_not_lt h, min_self] + change (if min t τ < τ then s₀ * Real.exp (r * ((min t τ : ℝ≥0) : ℝ)) else X ω) + / Real.exp (r * ((min t τ : ℝ≥0) : ℝ)) = X ω / Real.exp (r * τ) + rw [min_eq_right (not_lt.1 h)] + simp only [lt_self_iff_false, ↓reduceIte] + +variable {P hX s₀ r τ} + +/-- **A pricing measure of the one-date market.** A probability measure `Q` equivalent to `P` +under which `X` is integrable with mean `s₀ e^{rτ}` prices the one-date market up to `τ`: the +deflated asset is the constant `s₀` before `τ` and `X e^{−rτ}` at `τ`, and `Q`-integrating the +latter gives back `s₀`. -/ +theorem isPricingMeasure_oneDate {Q : Measure Ω} [IsProbabilityMeasure Q] (hQP : Q ≪ P) + (hPQ : P ≪ Q) (hint : Integrable X Q) (hmean : ∫ ω, X ω ∂Q = s₀ * Real.exp (r * τ)) : + (oneDate P hX s₀ r τ).IsPricingMeasure τ Q := by + have hmart : Martingale (fun n ↦ deflatedStep X s₀ r τ (min n 1)) (twoStepFiltration Ω) Q := by + refine martingale_min_of_condExp_succ (𝓕 := twoStepFiltration Ω) (S := deflatedStep X s₀ r τ) + (T := 1) (fun t ht ↦ ?_) (fun t ht ↦ ?_) (fun t ht ↦ ?_) + · rcases Nat.le_one_iff_eq_zero_or_eq_one.mp ht with rfl | rfl + · have hc : StronglyMeasurable[(⊥ : MeasurableSpace Ω)] (fun _ : Ω ↦ s₀) := + stronglyMeasurable_const + exact hc.mono (twoStepFiltration_zero Ω).ge + · exact (hX.div_const (Real.exp (r * τ))).stronglyMeasurable.mono + (twoStepFiltration_one Ω).ge + · rcases Nat.le_one_iff_eq_zero_or_eq_one.mp ht with rfl | rfl + · exact integrable_const s₀ + · exact hint.div_const (Real.exp (r * τ)) + · obtain rfl : t = 0 := Nat.lt_one_iff.mp ht + rw [twoStepFiltration_zero, condExp_bot] + refine Filter.Eventually.of_forall fun ω ↦ ?_ + change s₀ = ∫ x, X x / Real.exp (r * τ) ∂Q + rw [integral_div, hmean, mul_div_assoc, div_self (Real.exp_pos _).ne', mul_one] + refine .of_isEquivProbMeasure ⟨inferInstance, hQP, hPQ⟩ fun i ↦ ?_ + have e : (fun t ↦ (oneDate P hX s₀ r τ).deflated i (min t τ)) + = fun t ↦ (fun n ↦ deflatedStep X s₀ r τ (min n 1)) (dateStep τ t) := + funext fun t ↦ funext fun ω ↦ deflated_oneDate_min P hX s₀ r τ i t ω + rw [e] + exact hmart.comp (monotone_dateStep τ) + +/-- **A pricing measure of the one-date market has the quoted mean.** For a date `τ > 0`, a +pricing measure `Q` of the one-date market makes `X` integrable with mean `s₀ e^{rτ}`: the deflated +asset is the constant `s₀` at `0` and `X e^{−rτ}` at `τ`, and a martingale keeps its mean +(`Martingale.setIntegral_eq`). This is the converse of `isPricingMeasure_oneDate`. For `τ = 0` the +quote `s₀` is never read, so no such constraint holds. -/ +theorem integral_eq_of_isPricingMeasure_oneDate {Q : Measure Ω} (hτ : 0 < τ) + (hQ : (oneDate P hX s₀ r τ).IsPricingMeasure τ Q) : + Integrable X Q ∧ ∫ ω, X ω ∂Q = s₀ * Real.exp (r * τ) := by + have := hQ.isProb + have hm := hQ.martingale () + have h0 (ω : Ω) : (oneDate P hX s₀ r τ).deflated () (min 0 τ) ω = s₀ := by + rw [deflated_oneDate_min, dateStep_of_lt hτ, Nat.zero_min]; rfl + have hτ' (ω : Ω) : + (oneDate P hX s₀ r τ).deflated () (min τ τ) ω = X ω / Real.exp (r * τ) := by + rw [deflated_oneDate_min, dateStep_of_not_lt (lt_irrefl τ), min_self]; rfl + have hi : Integrable (fun ω ↦ X ω / Real.exp (r * τ)) Q := + (hm.integrable τ).congr (.of_forall hτ') + refine ⟨(hi.mul_const (Real.exp (r * τ))).congr (.of_forall fun ω ↦ ?_), ?_⟩ + · field_simp + · have he : ∫ ω in Set.univ, (oneDate P hX s₀ r τ).deflated () (min 0 τ) ω ∂Q + = ∫ ω in Set.univ, (oneDate P hX s₀ r τ).deflated () (min τ τ) ω ∂Q := + hm.setIntegral_eq (i := 0) (j := τ) (zero_le (a := τ)) (s := Set.univ) MeasurableSet.univ + simp only [h0, hτ', Measure.restrict_univ] at he + have e1 : ∫ _ : Ω, s₀ ∂Q = s₀ := by simp + rw [e1, integral_div, eq_div_iff (Real.exp_pos _).ne'] at he + exact he.symm + +/-- **The claim paying the asset at `τ`** is worth the discounted expectation `𝔼_Q[e^{−rτ} X]`, +under any measure `Q`: the market's price is the contract value (`price`), and the asset at `τ` is +`X`. -/ +theorem price_pay_obs_oneDate (Q : Measure Ω) : + (oneDate P hX s₀ r τ).price Q (.pay τ (.obs () τ)) = ∫ ω, Real.exp (-r * τ) * X ω ∂Q := by + rw [Market.price, Contract.value_pay] + refine integral_congr_ae (.of_forall fun ω ↦ ?_) + simp only [Payoff.eval, scenarioAt, asset_oneDate_self, deflator_oneDate] + +/-- **The European call in the one-date market** is worth `𝔼_Q[e^{−rτ} (X − K)⁺]` under any +measure `Q`. -/ +theorem price_europeanCall_oneDate (Q : Measure Ω) (K : ℝ) : + (oneDate P hX s₀ r τ).price Q (europeanCall K τ) + = ∫ ω, Real.exp (-r * τ) * max (X ω - K) 0 ∂Q := by + rw [Market.price, europeanCall, Contract.value_pay] + refine integral_congr_ae (.of_forall fun ω ↦ ?_) + simp only [europeanCallPayoff, Payoff.eval, scenarioAt, asset_oneDate_self, deflator_oneDate] + +end MathFin.Market diff --git a/LeanPool/MathFin/Pricing/Parity.lean b/LeanPool/MathFin/Pricing/Parity.lean new file mode 100644 index 0000000000..f0686c3b08 --- /dev/null +++ b/LeanPool/MathFin/Pricing/Parity.lean @@ -0,0 +1,179 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.Value +public import LeanPool.MathFin.Contracts.Instruments.Options + +/-! +# The forward and put–call parity in every risk-neutral model + +`Contracts/Instruments/Options.lean` proves that a call pays a put plus a forward on every path, +so in every model the call's value is the put's plus the forward's. This file prices the +forward without choosing a model. Only one fact about the model is used: the discounted +underlying at maturity is integrable with mean `S₀`. Then the forward struck at `K` is worth +`S₀ − K D(T)` (`value_forward_of_integral`), and the call is worth the put plus +`S₀ − K D(T)` (`value_europeanCall_sub_put_of_integral`). The put's integrability comes from +the underlying's. + +That fact holds in every model whose discounted price `t ↦ D(t) X(t)` is a `Q`-martingale +starting from the constant `S₀`, with `D(0) = 1` (`integral_discounted_of_martingale`). This is +the risk-neutral condition of `IsEMM`, which asks for the martingale and also +for `Q ≈ P`; only the martingale is needed here. In that case neither the forward nor the +parity takes an integrability hypothesis (`value_forward_of_martingale`, +`value_europeanCall_sub_put_of_martingale`). + +The Black–Scholes forward (`BlackScholes.value_forward`) is an instance of the first form. + +## Main results + +* `value_forward_of_integral`, `value_forward_of_martingale` — the forward is worth `S₀ − K D(T)`. +* `value_europeanCall_sub_put_of_integral`, `value_europeanCall_sub_put_of_martingale` — + call minus put is `S₀ − K D(T)`. + +## Source + +The layered separation of contract semantics from pricing semantics, and the +framing "the contract is not the model", are due to Paul Bilokon, +*The Contract Is Not the Model: Proof-Carrying Exotic Derivatives and the +Economics of Model Risk* (working paper, 9 August 2026; Mathematical +Finance, Imperial College London), with code at + (Apache-2.0). That paper in +turn builds on the compositional contract-DSL of +Peyton Jones, Eber and Seward (2000) and the certified-contract work of Bahr, +Berthold and Elsman (2015) and Annenkov (2018). + +No code is copied from `lean_contracts`; every definition and proof here is +written for this library. See `docs/specs/2026-08-16-contracts-tower-design.md` +§6 for the full credit line. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], ch. 11; ch. 5 +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], Section + 5.6.2 +* [Stoll, *The relationship between put and call option prices*][Stoll1969] + +## Tags + +put–call parity, forward price, risk-neutral pricing, discounted martingale, model-free pricing, +call minus put, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +open MeasureTheory +open scoped NNReal + +namespace MathFin.Contracts + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} {D : ℝ≥0 → ℝ} + {X : Unit → ℝ≥0 → Ω → ℝ} {S₀ K : ℝ} {T : ℝ≥0} + +/-- The forward's discounted payoff is integrable whenever the discounted underlying is. -/ +theorem integrable_forward_pathPV [IsFiniteMeasure Q] + (hX : Integrable (fun ω ↦ D T * X () T ω) Q) : + Integrable (fun ω ↦ (forward K T).pathPV D (scenarioAt X ω)) Q := by + simp only [forward, Contract.pathPV, Contract.cashflows, Payoff.eval, scenarioAt, + List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, add_zero, mul_sub] + exact hX.sub (integrable_const _) + +/-- If the discounted underlying is integrable and the discount factor is nonzero, so is the +underlying. -/ +theorem integrable_of_integrable_discount_mul (hX : Integrable (fun ω ↦ D T * X () T ω) Q) + (hD : D T ≠ 0) : Integrable (X () T) Q := by + simpa [← mul_assoc, inv_mul_cancel₀ hD] using hX.const_mul (D T)⁻¹ + +/-- The put's discounted payoff is integrable whenever the discounted underlying is. -/ +theorem integrable_europeanPut_pathPV [IsFiniteMeasure Q] + (hX : Integrable (fun ω ↦ D T * X () T ω) Q) : + Integrable (fun ω ↦ (europeanPut K T).pathPV D (scenarioAt X ω)) Q := by + simp only [europeanPut, Contract.pathPV, Contract.cashflows, Payoff.eval, scenarioAt, + List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, add_zero] + rcases eq_or_ne (D T) 0 with hD | hD + · simp [hD] + · exact ((integrable_const K).sub + (integrable_of_integrable_discount_mul hX hD)).pos_part.const_mul _ + +/-- The call's discounted payoff is integrable whenever the discounted underlying is. -/ +theorem integrable_europeanCall_pathPV [IsFiniteMeasure Q] + (hX : Integrable (fun ω ↦ D T * X () T ω) Q) : + Integrable (fun ω ↦ (europeanCall K T).pathPV D (scenarioAt X ω)) Q := by + simp only [europeanCall, europeanCallPayoff, Contract.pathPV, Contract.cashflows, Payoff.eval, + scenarioAt, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, add_zero] + rcases eq_or_ne (D T) 0 with hD | hD + · simp [hD] + · exact ((integrable_of_integrable_discount_mul hX hD).sub + (integrable_const K)).pos_part.const_mul _ + +/-- **The forward's value in any model** in which the discounted underlying at `T` is integrable +with mean `S₀`: the forward struck at `K` is worth `S₀ − K D(T)`. -/ +theorem value_forward_of_integral [IsProbabilityMeasure Q] + (hX : Integrable (fun ω ↦ D T * X () T ω) Q) (hS₀ : ∫ ω, D T * X () T ω ∂Q = S₀) : + (forward K T).value Q (fun t _ ↦ D t) X = S₀ - K * D T := by + rw [forward, Contract.value_pay] + simp only [Payoff.eval, scenarioAt, mul_sub] + rw [integral_sub hX (integrable_const _), hS₀, integral_const, probReal_univ, one_smul] + ring + +/-- **Put–call parity, in any model.** For any measure, deflator and model, if the put's and the +forward's deflated payoffs are integrable, the call is worth the put plus the forward: it pays +exactly that combination on every path (`pathPV_europeanCall_eq_put_add_forward`). -/ +theorem value_europeanCall_eq_put_add_forward (Q : Measure Ω) (D : ℝ≥0 → Ω → ℝ) + (X : Unit → ℝ≥0 → Ω → ℝ) {K : ℝ} {T : ℝ≥0} + (hput : Integrable (fun ω ↦ (europeanPut K T).pathPV (fun t ↦ D t ω) (scenarioAt X ω)) Q) + (hfwd : Integrable (fun ω ↦ (forward K T).pathPV (fun t ↦ D t ω) (scenarioAt X ω)) Q) : + (europeanCall K T).value Q D X = (europeanPut K T).value Q D X + (forward K T).value Q D X := by + rw [← Contract.value_both _ _ _ _ _ hput hfwd] + simp only [Contract.value, pathPV_europeanCall_eq_put_add_forward] + +/-- **Put–call parity in closed form, in any model** in which the discounted underlying at `T` +is integrable with mean `S₀`: `C − P = S₀ − K D(T)`. No integrability of either option is +assumed; the put's follows from the underlying's. -/ +theorem value_europeanCall_sub_put_of_integral [IsProbabilityMeasure Q] + (hX : Integrable (fun ω ↦ D T * X () T ω) Q) (hS₀ : ∫ ω, D T * X () T ω ∂Q = S₀) : + (europeanCall K T).value Q (fun t _ ↦ D t) X - (europeanPut K T).value Q (fun t _ ↦ D t) X + = S₀ - K * D T := by + rw [value_europeanCall_eq_put_add_forward Q (fun t _ ↦ D t) X (integrable_europeanPut_pathPV hX) + (integrable_forward_pathPV hX), value_forward_of_integral hX hS₀] + ring + +variable {𝓕 : Filtration ℝ≥0 mΩ} + +/-- **A martingale keeps its starting mean.** If the discounted price `t ↦ D(t) X(t)` is a +`Q`-martingale, `D(0) = 1` and the price starts at the constant `S₀`, then the discounted price +at every `T` has mean `S₀`. -/ +theorem integral_discounted_of_martingale [IsProbabilityMeasure Q] + (hM : Martingale (fun t ω ↦ D t * X () t ω) 𝓕 Q) (hD₀ : D 0 = 1) + (hX₀ : ∀ ω, X () 0 ω = S₀) (T : ℝ≥0) : + ∫ ω, D T * X () T ω ∂Q = S₀ := by + rw [← integral_condExp (𝓕.le 0), integral_congr_ae (hM.condExp_ae_eq (zero_le (a := T)))] + simp [hD₀, hX₀] + +/-- **The forward's value in any risk-neutral model.** If the discounted price is a +`Q`-martingale starting from `S₀`, with `D(0) = 1`, the forward struck at `K` is worth +`S₀ − K D(T)`. -/ +theorem value_forward_of_martingale [IsProbabilityMeasure Q] + (hM : Martingale (fun t ω ↦ D t * X () t ω) 𝓕 Q) (hD₀ : D 0 = 1) + (hX₀ : ∀ ω, X () 0 ω = S₀) : + (forward K T).value Q (fun t _ ↦ D t) X = S₀ - K * D T := + value_forward_of_integral (hM.integrable T) (integral_discounted_of_martingale hM hD₀ hX₀ T) + +/-- **Put–call parity in every risk-neutral model**, with no integrability hypotheses. If the +discounted price is a `Q`-martingale starting from `S₀`, with `D(0) = 1`, then +`C − P = S₀ − K D(T)`. -/ +theorem value_europeanCall_sub_put_of_martingale [IsProbabilityMeasure Q] + (hM : Martingale (fun t ω ↦ D t * X () t ω) 𝓕 Q) (hD₀ : D 0 = 1) + (hX₀ : ∀ ω, X () 0 ω = S₀) : + (europeanCall K T).value Q (fun t _ ↦ D t) X - (europeanPut K T).value Q (fun t _ ↦ D t) X + = S₀ - K * D T := + value_europeanCall_sub_put_of_integral (hM.integrable T) + (integral_discounted_of_martingale hM hD₀ hX₀ T) + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Pricing/ReplicationPricing.lean b/LeanPool/MathFin/Pricing/ReplicationPricing.lean new file mode 100644 index 0000000000..044091426e --- /dev/null +++ b/LeanPool/MathFin/Pricing/ReplicationPricing.lean @@ -0,0 +1,99 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.InnerProductSpace.Basic +public import Mathlib.MeasureTheory.Integral.Bochner.Set + +/-! +# A replicated claim is worth its initial wealth + +The argument behind "complete ⟹ the pricing measure is unique", once. Fix a class `Gains` of +terminal gains (the terminal wealth of a self-financing strategy started from nothing) and call a +measure `Q` *gains-neutral* if every gain is `Q`-integrable with `Q`-mean zero. A gains-neutral +probability measure dominated by `P` prices a claim replicated `P`-almost surely, `H = x + G` with +`G ∈ Gains`, at its initial wealth `x` (`integral_eq_of_replicates`). If every event of a +σ-algebra `𝓖` has its indicator replicated, two gains-neutral measures then agree on `𝓖` +(`measure_eq_of_replicates`): both give the event the initial wealth of its replication. + +It has two instances, which differ only in what makes the gains neutral: +* the discrete market (`IsEMM.measure_eq_of_isCompleteMarket`, `Pricing/FTAP/FTAP.lean`): the gains + `martingaleTransform φ S T` are a `Q`-martingale started at `0` under any equivalent martingale + measure; +* the Brownian market (`measure_eq_of_pricesGainsAtZero`, `Pricing/MarketCompleteness.lean`): + the gains are the terminal Itô integrals `∫₀ᵀ φ dB`, centered under the reference measure, and + neutrality under other measures is the hypothesis `PricesGainsAtZero`. + +## Main results + +* `integral_eq_of_replicates` — a gains-neutral probability measure `Q ≪ P` prices a replicated + claim `H =ᵐ[P] x + G` at `x`. +* `measureReal_eq_of_replicates` — the indicator case: `Q A = x`. +* `measure_eq_of_replicates` — two gains-neutral probability measures `≪ P` agree on every event + of `𝓖` whose indicator is replicated. + +## References + +* [J. M. Harrison and S. R. Pliska, *Martingales and stochastic integrals in the theory of + continuous trading*][HarrisonPliska1981] +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], Section + 5.4 + +## Tags + +replication, law of one price, gains-neutral measure, unique pricing measure, complete market, +initial wealth, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + +/-- **A replicated claim is worth its initial wealth.** If `Q` is a probability measure dominated +by `P`, the gain `G` is `Q`-integrable with `Q`-mean zero, and `H = x + G` `P`-almost surely, then +`∫ H dQ = x`: transport the almost-sure equality along `Q ≪ P`, then integrate. -/ +theorem integral_eq_of_replicates {Q : Measure Ω} [IsProbabilityMeasure Q] (hQP : Q ≪ P) + {H G : Ω → ℝ} {x : ℝ} (hG : Integrable G Q) (hG0 : ∫ ω, G ω ∂Q = 0) + (hrep : H =ᵐ[P] fun ω ↦ x + G ω) : ∫ ω, H ω ∂Q = x := by + rw [integral_congr_ae (hQP.ae_le hrep), integral_add (integrable_const x) hG, hG0, + integral_const, probReal_univ, one_smul, add_zero] + +/-- **A replicated event has probability its initial wealth.** The indicator case of +`integral_eq_of_replicates`: if `1_A = x + G` `P`-almost surely for a `Q`-neutral gain `G`, then +`Q A = x`. -/ +theorem measureReal_eq_of_replicates {Q : Measure Ω} [IsProbabilityMeasure Q] (hQP : Q ≪ P) + {A : Set Ω} (hA : MeasurableSet A) {G : Ω → ℝ} {x : ℝ} (hG : Integrable G Q) + (hG0 : ∫ ω, G ω ∂Q = 0) (hrep : A.indicator (1 : Ω → ℝ) =ᵐ[P] fun ω ↦ x + G ω) : + Q.real A = x := by + rw [← integral_indicator_one hA] + exact integral_eq_of_replicates hQP hG hG0 hrep + +/-- **Replication determines the pricing measure.** Let `Gains` be a class of gains, and `Q₁`, `Q₂` +probability measures dominated by `P` under which every gain is integrable with mean zero. If the +indicator of every `𝓖`-measurable event is `P`-almost surely `x + G` for some `x` and `G ∈ Gains` +(the market is complete for `𝓖`), then `Q₁` and `Q₂` agree on `𝓖`: replicate the indicator of `A`; +both measures give `A` the initial wealth `x` (`measureReal_eq_of_replicates`). -/ +theorem measure_eq_of_replicates {Q₁ Q₂ : Measure Ω} [IsProbabilityMeasure Q₁] + [IsProbabilityMeasure Q₂] (h₁ : Q₁ ≪ P) (h₂ : Q₂ ≪ P) {Gains : Set (Ω → ℝ)} + (hg₁ : ∀ G ∈ Gains, Integrable G Q₁ ∧ ∫ ω, G ω ∂Q₁ = 0) + (hg₂ : ∀ G ∈ Gains, Integrable G Q₂ ∧ ∫ ω, G ω ∂Q₂ = 0) {𝓖 : MeasurableSpace Ω} + (h𝓖 : 𝓖 ≤ mΩ) + (hcomplete : ∀ A, MeasurableSet[𝓖] A → + ∃ x, ∃ G ∈ Gains, A.indicator (1 : Ω → ℝ) =ᵐ[P] fun ω ↦ x + G ω) + {A : Set Ω} (hA : MeasurableSet[𝓖] A) : Q₁ A = Q₂ A := by + obtain ⟨x, G, hG, hrep⟩ := hcomplete A hA + refine (ENNReal.toReal_eq_toReal_iff' (measure_ne_top _ _) (measure_ne_top _ _)).1 ?_ + exact (measureReal_eq_of_replicates h₁ (h𝓖 _ hA) (hg₁ G hG).1 (hg₁ G hG).2 hrep).trans + (measureReal_eq_of_replicates h₂ (h𝓖 _ hA) (hg₂ G hG).1 (hg₂ G hG).2 hrep).symm + +end MathFin diff --git a/LeanPool/MathFin/Pricing/StatePrices.lean b/LeanPool/MathFin/Pricing/StatePrices.lean new file mode 100644 index 0000000000..dd912e3b2e --- /dev/null +++ b/LeanPool/MathFin/Pricing/StatePrices.lean @@ -0,0 +1,146 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Laws.FiniteWeights + +/-! +# Arrow-Debreu state prices and the linear pricing functional + +In a finite-state market with states `i ∈ s` (a `Finset`), an **Arrow-Debreu +state price** `q i` is the price today of a contingent claim paying `$1` in +state `i` and `$0` elsewhere. + +Properties under no-arbitrage: + +* **Non-negativity**: `0 ≤ q i` for every state. +* **Discount consistency**: `∑ q i = e^{−rT}` (price of the unit-payoff bond). +* **Linear pricing**: for any claim `X : ι → ℝ`, + `V_0(X) = ∑ q i · X i`. + +The state prices are an equivalent description of the **risk-neutral measure**: +`q i = e^{−rT} · ν i`, where `ν i = Q(state i)`. Equivalently, in discrete time +the FTAP gives existence of either equivalent description. + +This is the **discrete-state core** of risk-neutral pricing: every formula in +the library (BS, Black-76, binomial) is `V_0 = ∑ q_i · X_i` in disguise, with +specific `q` given by the model. + +## Main definitions + +* `statePricePricing`: the linear pricing functional `V₀(X) = ∑ i ∈ s, q i * X i` from + Arrow-Debreu state prices `q` on the finite state set `s`. + +## Main results + +* `statePricePricing_eq_integral`: for non-negative state prices, `V_0(X)` is the integral of `X` + against `Measure.ofWeights s q`. +* `statePricePricing_zero`: `V_0(0) = 0`. +* `statePricePricing_one`: `V_0(1) = ∑ q_i` (unit-payoff price = ∑ state prices). +* `statePricePricing_const`: `V_0(c · 1) = c · ∑ q_i` (unit-payoff times constant). +* `statePricePricing_add`: linearity in `X`. +* `statePricePricing_smul`: scalar homogeneity in `X`. +* `statePricePricing_eq_riskNeutral`: relation to risk-neutral expectation + `q_i = e^{−rT} · ν_i ⟹ V_0(X) = e^{−rT} · E^ν[X]`. +* `statePricePricing_nonneg`: payoff non-negative + state prices non-negative ⟹ + price non-negative (no-arb monotonicity). + +## References + +* [Arrow (1953)][Arrow1953] +* [Debreu (1959)][Debreu1959] + +## Tags + +Arrow–Debreu, state prices, risk-neutral measure, linear pricing, contingent claim, +finite-state market, MSC 91G20, JEL D53, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open Finset + +variable {ι : Type*} + +/-- **Linear pricing functional** from Arrow-Debreu state prices: +`V_0(X) = ∑ q_i · X_i`. -/ +noncomputable def statePricePricing (s : Finset ι) (q : ι → ℝ) (X : ι → ℝ) : ℝ := + ∑ i ∈ s, q i * X i + +open MeasureTheory in +/-- **State-price pricing is an integral**: for non-negative state prices `q`, the price of `X` is +`∫ X ∂(∑ i ∈ s, q i • δ_i)`, the integral against the state prices as a measure. -/ +theorem statePricePricing_eq_integral [MeasurableSpace ι] [MeasurableSingletonClass ι] + (s : Finset ι) {q : ι → ℝ} (hq : ∀ i ∈ s, 0 ≤ q i) (X : ι → ℝ) : + statePricePricing s q X = ∫ i, X i ∂Measure.ofWeights s q := + (Measure.integral_ofWeights s hq X).symm + +/-- **Zero payoff has zero price**. -/ +lemma statePricePricing_zero (s : Finset ι) (q : ι → ℝ) : + statePricePricing s q (fun _ ↦ 0) = 0 := by + unfold statePricePricing + simp + +/-- **Unit-payoff price = sum of state prices**: `V_0(1) = ∑ q_i`. By +no-arb this is the zero-coupon bond price `e^{−rT}` (consistency condition). -/ +lemma statePricePricing_one (s : Finset ι) (q : ι → ℝ) : + statePricePricing s q (fun _ ↦ 1) = ∑ i ∈ s, q i := by + unfold statePricePricing + simp + +/-- **Scalar payoff**: `V_0(c · 1) = c · ∑ q_i`. -/ +lemma statePricePricing_const (s : Finset ι) (q : ι → ℝ) (c : ℝ) : + statePricePricing s q (fun _ ↦ c) = c * ∑ i ∈ s, q i := by + unfold statePricePricing + rw [show (fun i ↦ q i * c) = (fun i ↦ c * q i) from funext (fun i ↦ by ring)] + rw [← Finset.mul_sum] + + +/-- **Linearity in payoff** (sum): `V_0(X + Y) = V_0(X) + V_0(Y)`. -/ +lemma statePricePricing_add (s : Finset ι) (q X Y : ι → ℝ) : + statePricePricing s q (fun i ↦ X i + Y i) = + statePricePricing s q X + statePricePricing s q Y := by + unfold statePricePricing + rw [← Finset.sum_add_distrib] + refine Finset.sum_congr rfl (fun i _ ↦ ?_) + ring + +/-- **Scalar homogeneity in payoff**: `V_0(c · X) = c · V_0(X)`. -/ +lemma statePricePricing_smul (s : Finset ι) (q X : ι → ℝ) (c : ℝ) : + statePricePricing s q (fun i ↦ c * X i) = c * statePricePricing s q X := by + unfold statePricePricing + rw [Finset.mul_sum] + refine Finset.sum_congr rfl (fun i _ ↦ ?_) + ring + +/-- **Risk-neutral consistency**: if `q i = e^{−rT} · ν i`, then state-price +pricing equals discounted risk-neutral expectation: +`V_0(X) = e^{−rT} · E^ν[X] = e^{−rT} · ∑ ν_i · X_i`. -/ +theorem statePricePricing_eq_riskNeutral + (s : Finset ι) (ν X : ι → ℝ) (rT : ℝ) : + statePricePricing s (fun i ↦ Real.exp (-rT) * ν i) X = + Real.exp (-rT) * ∑ i ∈ s, ν i * X i := by + unfold statePricePricing + rw [Finset.mul_sum] + refine Finset.sum_congr rfl (fun i _ ↦ ?_) + ring + +/-- **No-arbitrage monotonicity**: under non-negative state prices and a +non-negative payoff, the price is non-negative. -/ +theorem statePricePricing_nonneg + (s : Finset ι) (q X : ι → ℝ) + (hq : ∀ i ∈ s, 0 ≤ q i) (hX : ∀ i ∈ s, 0 ≤ X i) : + 0 ≤ statePricePricing s q X := by + unfold statePricePricing + apply Finset.sum_nonneg + intros i hi + exact mul_nonneg (hq i hi) (hX i hi) + +end MathFin diff --git a/LeanPool/MathFin/Pricing/Value.lean b/LeanPool/MathFin/Pricing/Value.lean new file mode 100644 index 0000000000..716840e772 --- /dev/null +++ b/LeanPool/MathFin/Pricing/Value.lean @@ -0,0 +1,366 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Contracts.Instruments.FixedIncome +public import LeanPool.MathFin.Contracts.Adapted +public import Mathlib.Probability.Martingale.Basic + +/-! +# Pricing a contract: value, its linearity, and the martingale seam + +A `Contract` is still model-agnostic data until it meets a stochastic model. `Scenario` +becomes a random variable once a model `X : ι → ℝ≥0 → Ω → ℝ` and an outcome `ω : Ω` are +fixed (`scenarioAt`); `Contract.value` integrates the resulting `pathPV` against a measure `Q` and +a deflator `D : ℝ≥0 → Ω → ℝ`, each outcome's cash flows discounted along that outcome's path +`t ↦ D t ω`. It is a price when `Q` is a pricing measure of a market whose deflator is `D` +(`Market.price`). A deterministic discount curve is the deflator `fun t _ ↦ D t`. + +This file's connection to the market vocabulary is through `Martingale`, not `IsEMM`: +`value_deliverAsset`'s pricing identity needs a `Q`-martingale price process and `Q` a +probability measure, nothing more. The mutual-absolute-continuity content that makes a +martingale measure an *equivalent* one — `IsEMM`'s `ac`/`ac'` fields — is not needed by +anything here; it lives in `ContinuousMarket.lean` (`isEMM_noArbitrageSimple`), where it +is load-bearing. + +## Main definitions + +* `scenarioAt` — the scenario read off a model `X` at a single outcome `ω`. +* `Contract.value` — the pricing integral `∫ ω, c.pathPV (D · ω) (scenarioAt X ω) ∂Q` under a + deflator `D`. +* `Contract.observation` — what a fixed-dated contract reads at an outcome: the model at its + observations and the deflator at its payment dates; `Contract.pvOf`, its present value as a + function of that. +* `zeroCurve` — the zero curve `t ↦ 𝔼_Q[D t]` of a deflator: the value of one unit paid at `t`. + +## Main results + +* `Contract.value_pay` — a single cash flow is worth the integral of its deflated payoff; + `Contract.value_payFlows` — a schedule of them, the sum. +* `Contract.value_scale`, `Contract.value_both` — `value` is homogeneous and additive, + inherited from `pathPV_scale` and `pathPV_both`. The two carry different hypotheses on + purpose: `value_scale` needs none, because `integral_const_mul` holds unconditionally in + Mathlib's Bochner integral (it returns `0` off the integrable set on both sides), while + `value_both` genuinely needs both summands integrable — `integral_add` is false without + them. That asymmetry, not a uniform "linearity", is the honest content of this pair. +* `Contract.value_deliverAsset` — a contract that simply delivers the asset `S` at time `T` + is worth `∫ ω, S 0 ω ∂Q` today, given `S` is a `Q`-martingale and `Q` a probability + measure. Mechanically this *is* conditional-expectation machinery (`condExp_ae_eq` + + `integral_condExp`), the same kind `value_process_martingale` uses, evaluated at the + fixed times `0` and `T` — it carries no equivalence content, so it is stated against + `Martingale` directly rather than the library's `IsEMM` bundle, whose `ac`/`ac'` fields + this argument never needs. +* `Contract.value_eq_of_pathPV_eq`, `value_fixedFlows_deterministic` — a contract whose deflated + present value is the same along every outcome is worth that amount; a schedule of fixed cash + flows on a deterministic curve is one. +* `Contract.value_congr_ae` — a fixed-dated contract has the same value in two models that agree + almost surely at the `(underlying, date)` observations it reads (`Contract.obsList`). +* `Contract.value_eq_of_map_observation_eq` — **law invariance**: a fixed-dated contract has the + same value in two models, on two sample spaces, whose observations and deflators at the + contract's dates have one law (`Contract.value_eq_integral_map`). +* `Contract.value_process_martingale` — the conditional-expectation value process of a + contract is a `Q`-martingale. Carries **no** `Integrable` hypothesis: `martingale_condExp` + is unconditional, because Mathlib's Bochner integral returns the junk value `0` off the + integrable set, and the constant-`0` process is trivially a martingale — so the theorem is + honest but its content lives entirely in the integrable case. It is also stated with **no** + `IsEMM` hypothesis: it is `martingale_condExp` specialized to a contract's cashflows, true + for any `Q` with a `SigmaFiniteFiltration`, not a fact about the pricing measure. Shipping it + with an `IsEMM` hypothesis would misattribute a conditional-expectation fact to the EMM + structure — and, as `value_deliverAsset` above shows, no theorem in this file has any actual + EMM content to misattribute it to. + +## Source + +The layered separation of contract semantics from pricing semantics, and the +framing "the contract is not the model", are due to Paul Bilokon, +*The Contract Is Not the Model: Proof-Carrying Exotic Derivatives and the +Economics of Model Risk* (working paper, 9 August 2026; Mathematical +Finance, Imperial College London), with code at + (Apache-2.0). That paper in +turn builds on the compositional contract-DSL of +Peyton Jones, Eber and Seward (2000) and the certified-contract work of Bahr, +Berthold and Elsman (2015) and Annenkov (2018). + +Bilokon separates pricing semantics from contract semantics — a pricing model +is a law over deterministic scenarios — and that separation is his; but his +`PricingModel.value` integrates a function never shown measurable and his +`value_eq_of_pathPV_eq` is `congrArg` under the integral, whereas this file's +linearity carries real integrability hypotheses and its delivery-of-asset +identity is a genuine martingale-pricing fact (`Martingale.condExp_ae_eq` +chained through `integral_condExp`), not an unconditional integral congruence. + +No code is copied from `lean_contracts`; every definition and proof here is +written for this library. See `docs/specs/2026-08-16-contracts-tower-design.md` +§6 for the full credit line. + +## References + +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [D. Brigo and F. Mercurio, *Interest Rate Models --- Theory and Practice*][BrigoMercurio2006], + sec. 1.2 +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], 1.1 +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], 5.2; + ch. 5 + +## Tags + +contract pricing, risk-neutral valuation, pricing measure, martingale pricing, discounted payoff, +cash flow valuation, MSC 91G20, MSC 60G44, JEL G13 +-/ + +@[expose] public section + +open MeasureTheory +open scoped NNReal + +namespace MathFin.Contracts + +variable {ι Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- The scenario read off a model at a single outcome. -/ +def scenarioAt (X : ι → ℝ≥0 → Ω → ℝ) (ω : Ω) : Scenario ι := fun i t ↦ X i t ω + +/-- The value of a `Contract` under a measure `Q` and a **deflator** `D : ℝ≥0 → Ω → ℝ`: the +`Q`-expectation of its present value along each outcome `ω`, each cash flow at `t` multiplied by +`D t ω`, against a model `X` that reifies each `Scenario` observation as a random variable. + +The deflator is stochastic: a short-rate model's `D t = exp(−∫₀ᵗ r_s ds)`, or a market's +`N 0 / N t` for a numéraire `N`. A deterministic discount curve `D : ℝ≥0 → ℝ` is the deflator +`fun t _ ↦ D t`. -/ +noncomputable def Contract.value (Q : Measure Ω) (D : ℝ≥0 → Ω → ℝ) + (X : ι → ℝ≥0 → Ω → ℝ) (c : Contract ι) : ℝ := + ∫ ω, c.pathPV (fun t ↦ D t ω) (scenarioAt X ω) ∂Q + +/-- **The value of a single cash flow** is the integral of its deflated payoff. Every +instrument that pays once (`Contracts/Instruments/Options.lean`) reaches its closed form in a +model by rewriting through this lemma. -/ +theorem Contract.value_pay (Q : Measure Ω) (D : ℝ≥0 → Ω → ℝ) (X : ι → ℝ≥0 → Ω → ℝ) (t : ℝ≥0) + (a : Payoff ι) : + (Contract.pay t a).value Q D X = ∫ ω, D t ω * a.eval (scenarioAt X ω) ∂Q := by + simp [Contract.value, Contract.pathPV, Contract.cashflows] + +/-- `value` is homogeneous under `scale`, unconditionally: `integral_const_mul` holds even +off the integrable set (both sides are `0` there), so no integrability hypothesis is needed. -/ +theorem Contract.value_scale (Q : Measure Ω) (D : ℝ≥0 → Ω → ℝ) + (X : ι → ℝ≥0 → Ω → ℝ) (r : ℝ) (a : Contract ι) : + (Contract.scale r a).value Q D X = r * a.value Q D X := by + simp only [value, Contract.pathPV_scale] + exact integral_const_mul r _ + +/-- `value` is additive under `both`, given both summands are integrable — `integral_add` +is false without that hypothesis on either side, unlike `value_scale`'s unconditional case. -/ +theorem Contract.value_both (Q : Measure Ω) (D : ℝ≥0 → Ω → ℝ) + (X : ι → ℝ≥0 → Ω → ℝ) (a b : Contract ι) + (ha : Integrable (fun ω ↦ a.pathPV (fun t ↦ D t ω) (scenarioAt X ω)) Q) + (hb : Integrable (fun ω ↦ b.pathPV (fun t ↦ D t ω) (scenarioAt X ω)) Q) : + (Contract.both a b).value Q D X = a.value Q D X + b.value Q D X := by + simp only [value, Contract.pathPV_both] + exact integral_add ha hb + +/-- A schedule of payments is worth the sum of its payments, given each deflated payoff is +integrable. -/ +theorem Contract.value_payFlows (Q : Measure Ω) (D : ℝ≥0 → Ω → ℝ) (X : ι → ℝ≥0 → Ω → ℝ) + (t : ℕ → ℝ≥0) (a : ℕ → Payoff ι) (n : ℕ) + (hint : ∀ i < n, Integrable (fun ω ↦ D (t i) ω * (a i).eval (scenarioAt X ω)) Q) : + (payFlows t a n).value Q D X + = ∑ i ∈ Finset.range n, (Contract.pay (t i) (a i)).value Q D X := by + simp only [Contract.value_pay] + rw [Contract.value] + simp only [pathPV_payFlows] + exact integral_finsetSum _ fun i hi ↦ hint i (Finset.mem_range.1 hi) + +/-- Under a `Q`-martingale `S` and `Q` a probability measure, a contract that simply +delivers the asset `S` at time `T`, undeflated, is worth `∫ ω, S 0 ω ∂Q` today — the +`Q`-price of `S` at time `0`. This is `Martingale.condExp_ae_eq` between `0` and `T` +chained through `integral_condExp`: a martingale-plus-probability-measure fact evaluated +at fixed times, the same conditional-expectation machinery `value_process_martingale` +uses. It carries no equivalence content — `Q` need not be an EMM for `S`, only a +probability measure under which `S` is a martingale — so it is stated against +`Martingale` directly rather than the library's `IsEMM` bundle, whose `ac`/`ac'` fields +this argument never needs; that mutual-absolute-continuity content lives elsewhere +(`ContinuousMarket.isEMM_noArbitrageSimple`). -/ +theorem Contract.value_deliverAsset {𝓕 : Filtration ℝ≥0 mΩ} + {S : ℝ≥0 → Ω → ℝ} {Q : Measure Ω} [IsProbabilityMeasure Q] + (hM : Martingale S 𝓕 Q) (T : ℝ≥0) : + (Contract.pay T (Payoff.obs () T)).value Q (fun _ _ ↦ 1) (fun _ ↦ S) + = ∫ ω, S 0 ω ∂Q := by + simp only [value, Contract.pathPV, Contract.cashflows, Payoff.eval, scenarioAt, + List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, one_mul, add_zero] + rw [← integral_condExp (𝓕.le 0)] + exact integral_congr_ae (hM.condExp_ae_eq zero_le) + +/-- The conditional-expectation value process of a contract is a `Q`-martingale. Needs +**no** `Integrable` hypothesis — `martingale_condExp` is unconditional, so a non-integrable +contract just gives the constant-`0` martingale (Bochner junk value); the theorem's content +is the integrable case. Needs **no** EMM hypothesis either: it is a property of conditional +expectation, not of the pricing measure — no theorem in this file needs `IsEMM`; +`value_deliverAsset` needs only `Martingale S 𝓕 Q` and `[IsProbabilityMeasure Q]`. -/ +theorem Contract.value_process_martingale {Q : Measure Ω} {𝓕 : Filtration ℝ≥0 mΩ} + [SigmaFiniteFiltration Q 𝓕] (D : ℝ≥0 → Ω → ℝ) (X : ι → ℝ≥0 → Ω → ℝ) + (c : Contract ι) : + Martingale (fun t ↦ Q[fun ω ↦ c.pathPV (fun s ↦ D s ω) (scenarioAt X ω) | 𝓕 t]) 𝓕 Q := + martingale_condExp _ 𝓕 Q + +/-! ### Two models that agree where the contract looks -/ + +/-- **A fixed-dated contract has the same value in two models that agree almost surely at the +observations it reads.** The models need not agree anywhere else: this is what lets a model that +is only Brownian up to a horizon price a contract whose dates lie before it. -/ +theorem Contract.value_congr_ae {Q : Measure Ω} {D : ℝ≥0 → Ω → ℝ} {X Y : ι → ℝ≥0 → Ω → ℝ} + (c : Contract ι) (hc : c.FixedDated) + (h : ∀ p ∈ c.obsList, ∀ᵐ ω ∂Q, X p.1 p.2 ω = Y p.1 p.2 ω) : + c.value Q D X = c.value Q D Y := by + refine integral_congr_ae ?_ + have hall : ∀ᵐ ω ∂Q, ∀ p ∈ {p | p ∈ c.obsList}, X p.1 p.2 ω = Y p.1 p.2 ω := + (ae_ball_iff (List.finite_toSet _).countable).2 h + filter_upwards [hall] with ω hω + unfold Contract.pathPV + rw [Contract.cashflows_congr c hc (s := scenarioAt X ω) (s' := scenarioAt Y ω) hω] + +/-- **A contract whose deflated present value is the same along every outcome is worth that +amount**, under any probability measure. -/ +theorem Contract.value_eq_of_pathPV_eq {Q : Measure Ω} [IsProbabilityMeasure Q] + {D : ℝ≥0 → Ω → ℝ} (X : ι → ℝ≥0 → Ω → ℝ) {c : Contract ι} {v : ℝ} + (h : ∀ ω, c.pathPV (fun t ↦ D t ω) (scenarioAt X ω) = v) : + c.value Q D X = v := by + simp [Contract.value, h] + +/-- On a deterministic discount curve, in every model, a schedule of fixed cash flows is worth +`∑ D(tᵢ) cᵢ`. Under a stochastic deflator it is worth the same sum on the zero curve +`t ↦ 𝔼_Q[D t]` (`value_fixedFlows`). -/ +theorem value_fixedFlows_deterministic {Q : Measure Ω} [IsProbabilityMeasure Q] (D : ℝ≥0 → ℝ) + (X : ι → ℝ≥0 → Ω → ℝ) (t : ℕ → ℝ≥0) (c : ℕ → ℝ) (n : ℕ) : + (fixedFlows t c n : Contract ι).value Q (fun s _ ↦ D s) X + = ∑ i ∈ Finset.range n, D (t i) * c i := + Contract.value_eq_of_pathPV_eq X fun ω ↦ pathPV_fixedFlows D (scenarioAt X ω) t c n + +/-! ### Law invariance -/ + +/-- **What a fixed-dated contract reads** from a model `X` and a deflator `D` at an outcome `ω`: the +model at each of its observations (`c.obsList`) and the deflator at each of its payment dates +(`c.dates`). -/ +def Contract.observation (c : Contract ι) (D : ℝ≥0 → Ω → ℝ) (X : ι → ℝ≥0 → Ω → ℝ) (ω : Ω) : + ({p // p ∈ c.obsList} → ℝ) × ({t // t ∈ c.dates} → ℝ) := + (fun p ↦ X p.1.1 p.1.2 ω, fun t ↦ D t.1 ω) + +open Classical in +/-- The scenario an observation fills in: the observed value at each of `c.obsList`, `0` +elsewhere. -/ +noncomputable def Contract.fillScenario (c : Contract ι) (v : {p // p ∈ c.obsList} → ℝ) : + Scenario ι := + fun i t ↦ if h : (i, t) ∈ c.obsList then v ⟨(i, t), h⟩ else 0 + +open Classical in +/-- The discount factor an observation fills in: the observed value at each of `c.dates`, `0` +elsewhere. -/ +noncomputable def Contract.fillDates (c : Contract ι) (w : {t // t ∈ c.dates} → ℝ) : + ℝ≥0 → ℝ := + fun t ↦ if h : t ∈ c.dates then w ⟨t, h⟩ else 0 + +/-- The present value of a contract as a function of what it reads. -/ +noncomputable def Contract.pvOf (c : Contract ι) + (z : ({p // p ∈ c.obsList} → ℝ) × ({t // t ∈ c.dates} → ℝ)) : ℝ := + c.pathPV (c.fillDates z.2) (c.fillScenario z.1) + +/-- A fixed-dated contract's deflated present value along `ω` is its present value read off the +observation at `ω`. -/ +theorem Contract.pathPV_eq_pvOf (c : Contract ι) (hc : c.FixedDated) (D : ℝ≥0 → Ω → ℝ) + (X : ι → ℝ≥0 → Ω → ℝ) (ω : Ω) : + c.pathPV (fun t ↦ D t ω) (scenarioAt X ω) = c.pvOf (c.observation D X ω) := by + unfold Contract.pvOf + refine c.pathPV_congr hc (fun t ht ↦ ?_) (fun ⟨i, t⟩ hp ↦ ?_) + · simp [Contract.fillDates, Contract.observation, ht] + · simp [Contract.fillScenario, Contract.observation, scenarioAt, hp] + +theorem Contract.measurable_observation (c : Contract ι) {D : ℝ≥0 → Ω → ℝ} + (hD : ∀ t, Measurable (D t)) {X : ι → ℝ≥0 → Ω → ℝ} (hX : ∀ i t, Measurable (X i t)) : + Measurable (c.observation D X) := by + unfold Contract.observation + refine Measurable.prodMk ?_ ?_ + · exact measurable_pi_iff.2 fun p ↦ hX p.1.1 p.1.2 + · exact measurable_pi_iff.2 fun t ↦ hD t.1 + +theorem Contract.measurable_pvOf (c : Contract ι) (hc : c.FixedDated) : Measurable c.pvOf := by + refine Contract.measurable_pathPV (c := c) + (Ω := ({p // p ∈ c.obsList} → ℝ) × ({t // t ∈ c.dates} → ℝ)) hc + (D := fun t z ↦ c.fillDates z.2 t) + (X := fun i t z ↦ c.fillScenario z.1 i t) (fun t ↦ ?_) (fun i t ↦ ?_) + · by_cases h : t ∈ c.dates + · simp only [Contract.fillDates, h, ↓reduceDIte] + exact (measurable_pi_apply _).comp measurable_snd + · simp only [Contract.fillDates, h, ↓reduceDIte] + exact measurable_const + · by_cases h : (i, t) ∈ c.obsList + · simp only [Contract.fillScenario, h, ↓reduceDIte] + exact (measurable_pi_apply _).comp measurable_fst + · simp only [Contract.fillScenario, h, ↓reduceDIte] + exact measurable_const + +/-- **The value of a fixed-dated contract is an integral against the law of what it reads**: the +`Q`-law of its observation, for a measurable model and deflator. -/ +theorem Contract.value_eq_integral_map (c : Contract ι) (hc : c.FixedDated) (Q : Measure Ω) + {D : ℝ≥0 → Ω → ℝ} (hD : ∀ t, Measurable (D t)) {X : ι → ℝ≥0 → Ω → ℝ} + (hX : ∀ i t, Measurable (X i t)) : + c.value Q D X = ∫ z, c.pvOf z ∂(Q.map (c.observation D X)) := by + rw [integral_map (c.measurable_observation hD hX).aemeasurable + (c.measurable_pvOf hc).aestronglyMeasurable] + unfold Contract.value + exact integral_congr_ae (.of_forall fun ω ↦ c.pathPV_eq_pvOf hc D X ω) + +/-- **Law invariance.** A fixed-dated contract has the same value in two models, on two sample +spaces, whose observations have the same law: if `(X, D)` at the contract's observations and +payment dates has one law under `Q` and under `Q'`, the values agree. The value depends on the +model only through that law, which is what lets a model built on one concrete space define a price +in every market with the same law. -/ +theorem Contract.value_eq_of_map_observation_eq {Ω' : Type*} {mΩ' : MeasurableSpace Ω'} + (c : Contract ι) (hc : c.FixedDated) {Q : Measure Ω} {Q' : Measure Ω'} + {D : ℝ≥0 → Ω → ℝ} {D' : ℝ≥0 → Ω' → ℝ} {X : ι → ℝ≥0 → Ω → ℝ} {X' : ι → ℝ≥0 → Ω' → ℝ} + (hD : ∀ t, Measurable (D t)) (hX : ∀ i t, Measurable (X i t)) + (hD' : ∀ t, Measurable (D' t)) (hX' : ∀ i t, Measurable (X' i t)) + (h : Q.map (c.observation D X) = Q'.map (c.observation D' X')) : + c.value Q D X = c.value Q' D' X' := by + rw [c.value_eq_integral_map hc Q hD hX, c.value_eq_integral_map hc Q' hD' hX', h] + +/-! ### The zero curve -/ + +/-- The **zero curve** of a deflator, `P(0, t) = 𝔼_Q[D t]`: the value of one +unit paid at `t`. -/ +noncomputable def zeroCurve (Q : Measure Ω) (D : ℝ≥0 → Ω → ℝ) (t : ℝ≥0) : ℝ := + ∫ ω, D t ω ∂Q + +/-- **A schedule of fixed cash flows is priced off the zero curve**: under a deflator with each +`D tᵢ` integrable, `fixedFlows t c n` is worth `∑ P(0, tᵢ) cᵢ`. -/ +theorem value_fixedFlows {Q : Measure Ω} {D : ℝ≥0 → Ω → ℝ} (X : ι → ℝ≥0 → Ω → ℝ) + (t : ℕ → ℝ≥0) (c : ℕ → ℝ) (n : ℕ) (hD : ∀ i < n, Integrable (D (t i)) Q) : + (fixedFlows t c n : Contract ι).value Q D X + = ∑ i ∈ Finset.range n, zeroCurve Q D (t i) * c i := by + simp only [Contract.value, pathPV_fixedFlows] + rw [integral_finsetSum _ fun i hi ↦ (hD i (Finset.mem_range.1 hi)).mul_const _] + simp only [zeroCurve, integral_mul_const] + +/-- **A deflator reaches a fixed schedule only through its zero curve**: its value under `D` is +its value on the deterministic curve `zeroCurve Q D`, in every model. -/ +theorem value_fixedFlows_eq_zeroCurve {Q : Measure Ω} [IsProbabilityMeasure Q] + {D : ℝ≥0 → Ω → ℝ} (X : ι → ℝ≥0 → Ω → ℝ) (t : ℕ → ℝ≥0) (c : ℕ → ℝ) (n : ℕ) + (hD : ∀ i < n, Integrable (D (t i)) Q) : + (fixedFlows t c n : Contract ι).value Q D X + = (fixedFlows t c n : Contract ι).value Q (fun s _ ↦ zeroCurve Q D s) X := by + rw [value_fixedFlows X t c n hD, value_fixedFlows_deterministic] + +/-- A closed-form zero curve prices a fixed schedule: if `𝔼_Q[D tᵢ] = P(tᵢ) ≠ 0` at each payment +date, the schedule is worth `∑ P(tᵢ) cᵢ`. Integrability is not assumed: a function whose integral +is nonzero is integrable. -/ +theorem value_fixedFlows_of_zeroCurve_eq {Q : Measure Ω} {D : ℝ≥0 → Ω → ℝ} + (X : ι → ℝ≥0 → Ω → ℝ) (t : ℕ → ℝ≥0) (c : ℕ → ℝ) (n : ℕ) {P : ℝ≥0 → ℝ} + (hP : ∀ i < n, zeroCurve Q D (t i) = P (t i)) (hP0 : ∀ i < n, P (t i) ≠ 0) : + (fixedFlows t c n : Contract ι).value Q D X = ∑ i ∈ Finset.range n, P (t i) * c i := by + rw [value_fixedFlows X t c n fun i hi ↦ + Integrable.of_integral_ne_zero ((hP i hi).trans_ne (hP0 i hi))] + exact Finset.sum_congr rfl fun i hi ↦ by rw [hP i (Finset.mem_range.1 hi)] + +end MathFin.Contracts diff --git a/LeanPool/MathFin/Pricing/WienerIntegralForwardMeasure.lean b/LeanPool/MathFin/Pricing/WienerIntegralForwardMeasure.lean new file mode 100644 index 0000000000..d76ba47eb1 --- /dev/null +++ b/LeanPool/MathFin/Pricing/WienerIntegralForwardMeasure.lean @@ -0,0 +1,119 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Laws.Esscher +public import LeanPool.MathFin.Pricing.ForwardMeasure +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralExpMoment + +/-! +# The forward measure of a Wiener-represented bank account + +For a bank account `exp(M + c₂·∫₀ˢ g dB)` whose exponent is a Wiener integral +(`wienerIntegralLp`), the discount factor `1/exp(M + c₂∫g dB)` has a Gaussian exponential moment, +so the `S`-forward measure `forwardMeasure μ (exp(M + c₂∫g dB))` (`Pricing/ForwardMeasure`) is +a probability measure. Under it a Wiener-represented rate `m + c₁·∫₀ˢ f dB` keeps its variance and +its mean shifts by minus its covariance with the account's exponent, `c₁c₂⟪f, g⟫`: the Gaussian +facts behind the bond put in the Hull–White and two-piece GSR models. + +## Main results + +* `integrable_one_div_exp_add_mul_wienerIntegralLp` — the discount factor of a Wiener-represented + bank account is integrable. +* `integral_exp_mul_wienerIntegralLp_eq_forwardMeasure` — futures = forward × exp(covariance), for + the exponential moments of a Wiener-represented rate. +* `hasLaw_forwardMeasure_wienerIntegralLp` — the law of a Wiener-represented rate under the forward + measure of a Wiener-represented bank account; Hull–White (`Models/Rates/TimingAdjustment`) and + GSR (`Models/Rates/GSRBondPriceAt`) short rates are its instances. + +## Tags + +forward measure, Wiener-represented bank account, Hull–White model, Gaussian short rate, +futures versus forward, convexity adjustment, MSC 91G30, MSC 60H05, JEL E43 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open WienerIntegralL2 +open scoped NNReal InnerProductSpace + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + +variable [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} + +/-- **The bond payoff of a Wiener-represented rate is integrable**: the discount factor +`1/exp(M + c·∫₀ˢ g dB) = exp(−(M + c·∫₀ˢ g dB))` has a Gaussian exponential moment. With +`forwardMeasure_isProbabilityMeasure` it makes the forward measure of the bank account +`exp(M + c·∫₀ˢ g dB)` a probability measure. -/ +theorem integrable_one_div_exp_add_mul_wienerIntegralLp (hB : IsPreBrownianReal B μ) (S : ℝ≥0) + (M c : ℝ) (g : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (S : ℝ)))) : + Integrable (fun ω ↦ 1 / Real.exp (M + c * wienerIntegralLp B hB S g ω)) μ := by + refine (((wienerIntegralLp_hasLaw_gaussian hB S g).integrable_fun_comp + (integrable_exp_mul_gaussianReal (-c))).const_mul (Real.exp (-M))).congr + (ae_of_all _ fun ω ↦ ?_) + simp only [one_div, ← Real.exp_neg, ← Real.exp_add] + congr 1 + ring + +/-- **Futures = forward × exp(covariance), for Wiener-represented rates.** With the bank account +`exp(M + c₂·∫₀ˢ g dB)` and any rate `m + c₁·∫₀ˢ f dB`, for every `t`, + + `𝔼[e^{t(m + c₁∫f dB)}] = 𝔼^S[e^{t(m + c₁∫f dB)}] · e^{t c₁ c₂ ⟪f, g⟫}`, + +`⟪f, g⟫ = Cov(∫f dB, ∫g dB)`: the instance of `futuresForwardBasis_of_integral_mul_exp_neg` with the +covariance identity `integral_exp_mul_exp_neg_wienerIntegralLp`. -/ +theorem integral_exp_mul_wienerIntegralLp_eq_forwardMeasure (hB : IsPreBrownianReal B μ) (S : ℝ≥0) + (m M c₁ c₂ t : ℝ) (f g : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (S : ℝ)))) : + ∫ ω, Real.exp (t * (m + c₁ * wienerIntegralLp B hB S f ω)) ∂μ + = (∫ ω, Real.exp (t * (m + c₁ * wienerIntegralLp B hB S f ω)) + ∂forwardMeasure μ fun ω ↦ Real.exp (M + c₂ * wienerIntegralLp B hB S g ω)) + * Real.exp (t * (c₁ * c₂ * ⟪f, g⟫_ℝ)) := by + have hV (ω : Ω) : t * (m + c₁ * wienerIntegralLp B hB S f ω) + = t * m + (t * c₁) * wienerIntegralLp B hB S f ω := by ring + have key := integral_exp_mul_exp_neg_wienerIntegralLp hB S (t * m) M (t * c₁) c₂ f g + refine futuresForwardBasis_of_integral_mul_exp_neg + (Y := fun ω ↦ M + c₂ * wienerIntegralLp B hB S g ω) (t * (c₁ * c₂ * ⟪f, g⟫_ℝ)) ?_ ?_ ?_ + · exact ((Lp.stronglyMeasurable _).measurable.const_mul c₂).const_add M + · rw [integral_exp_neg_add_mul_wienerIntegralLp] + exact Real.exp_pos _ + · simp_rw [hV] + rw [← mul_assoc, ← mul_assoc] + exact key + +/-- **The law of a Wiener-represented rate under the forward measure of a Wiener-represented bank +account.** If `r = m + c₁·∫₀ˢ f dB` is `N(m', v)` under `μ`, then under the forward measure of the +bank account `exp(M + c₂·∫₀ˢ g dB)` it is `N(m' − c₁c₂⟪f, g⟫, v)`: the mean shifts by minus the +covariance of the rate with the account's exponent and the variance is unchanged. The moment +generating function identity `integral_exp_mul_wienerIntegralLp_eq_forwardMeasure` determines the +law (`measure_eq_of_mgf_id_eq`). Hull–White and GSR short rates are its instances. -/ +theorem hasLaw_forwardMeasure_wienerIntegralLp (hB : IsPreBrownianReal B μ) (S : ℝ≥0) + (m M c₁ c₂ m' : ℝ) {v : ℝ≥0} (f g : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (S : ℝ)))) + (hlaw : HasLaw (fun ω ↦ m + c₁ * wienerIntegralLp B hB S f ω) (gaussianReal m' v) μ) : + HasLaw (fun ω ↦ m + c₁ * wienerIntegralLp B hB S f ω) + (gaussianReal (m' - c₁ * c₂ * ⟪f, g⟫_ℝ) v) + (forwardMeasure μ fun ω ↦ Real.exp (M + c₂ * wienerIntegralLp B hB S g ω)) := by + have := forwardMeasure_isProbabilityMeasure (Q := μ) (fun _ ↦ Real.exp_pos _) + (integrable_one_div_exp_add_mul_wienerIntegralLp hB S M c₂ g) + have hae : AEMeasurable (fun ω ↦ m + c₁ * wienerIntegralLp B hB S f ω) + (forwardMeasure μ fun ω ↦ Real.exp (M + c₂ * wienerIntegralLp B hB S g ω)) := + hlaw.aemeasurable.mono_ac (withDensity_absolutelyContinuous _ _) + refine ⟨hae, (measure_eq_of_mgf_id_eq integrable_exp_mul_gaussianReal ?_).symm⟩ + rw [mgf_id_gaussianReal, mgf_id_map hae] + funext t + have hμ := mgf_gaussianReal hlaw t + have h := integral_exp_mul_wienerIntegralLp_eq_forwardMeasure hB S m M c₁ c₂ t f g + simp only [mgf] at hμ ⊢ + rw [hμ, eq_comm, ← eq_div_iff (Real.exp_pos _).ne', ← Real.exp_sub] at h + rw [h] + congr 1 + ring + +end MathFin diff --git a/LeanPool/MathFin/Probability/Analysis/AffineMinorant.lean b/LeanPool/MathFin/Probability/Analysis/AffineMinorant.lean new file mode 100644 index 0000000000..f33964c8b7 --- /dev/null +++ b/LeanPool/MathFin/Probability/Analysis/AffineMinorant.lean @@ -0,0 +1,93 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.Analysis.InnerProductSpace.Basic +public import Mathlib.MeasureTheory.Integral.Bochner.Basic + +/-! +# Jensen's inequality through a supporting line + +If `f` lies above the line through `(m, f m)` with slope `c` at almost every value of `X`, and +`X` has mean `m`, then `f(m) ≤ 𝔼[f(X)]`: the line averages to `f(m)`. For a convex `f` with a +supporting line at the mean this is Jensen's inequality. It asks for no closed domain, unlike +Mathlib's `ConvexOn.map_integral_le`, so it applies on `(0, ∞)`, where Black–Scholes prices are +convex in the spot (`Models/BlackScholes/SpotConvexity.bsV_spot_tangent_le`). + +If the line lies strictly below `f` away from `m` and `X` is not almost surely `m`, the inequality +is strict: the gap `f(X) − line(X)` is nonnegative and positive with positive probability. + +## Main results + +* `le_integral_of_affine_le`: `f(m) ≤ 𝔼[f(X)]` from an affine minorant through `(m, f m)`. +* `lt_integral_of_affine_lt`: `f(m) < 𝔼[f(X)]` from a strict one, unless `X = m` almost surely. +* `integral_lt_integral_of_ae_le_of_not_ae_eq`: the integral is strictly monotone; the strict + inequality above, and the strict upper bound of a jump-diffusion call + (`Models/Jumps/JumpImpliedVol.lean`), both go through it. + +## Tags + +Jensen's inequality, supporting line, convexity, strict inequality, convex price in spot, MSC 60E15, +MSC 28A25 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory + +variable {α : Type*} {mα : MeasurableSpace α} {μ : Measure α} + +/-- **The integral is strictly monotone**: if `f ≤ g` almost everywhere and `f` and `g` are not +almost everywhere equal, then `∫ f < ∫ g`. -/ +lemma integral_lt_integral_of_ae_le_of_not_ae_eq {f g : α → ℝ} (hf : Integrable f μ) + (hg : Integrable g μ) (hfg : f ≤ᵐ[μ] g) (hne : ¬f =ᵐ[μ] g) : ∫ a, f a ∂μ < ∫ a, g a ∂μ := + (integral_mono_ae hf hg hfg).lt_of_ne fun h ↦ hne ((integral_eq_iff_of_ae_le hf hg hfg).1 h) + +variable [IsProbabilityMeasure μ] + +/-- A line through `(m, y)` averages to `y` when `X` has mean `m`. -/ +lemma integral_add_mul_sub {X : α → ℝ} {m : ℝ} (hX : Integrable X μ) (hm : ∫ a, X a ∂μ = m) + (y c : ℝ) : ∫ a, (y + c * (X a - m)) ∂μ = y := by + have hlin : Integrable (fun a ↦ c * (X a - m)) μ := (hX.sub (integrable_const m)).const_mul c + rw [integral_add (integrable_const _) hlin, integral_const_mul, + integral_sub hX (integrable_const m), hm, integral_const, integral_const, probReal_univ, + one_smul, one_smul, sub_self, mul_zero, add_zero] + +/-- **Jensen's inequality through a supporting line.** If `X` has mean `m` and +`f m + c (X − m) ≤ f(X)` almost surely, then `f(m) ≤ 𝔼[f(X)]`. -/ +theorem le_integral_of_affine_le {X : α → ℝ} {f : ℝ → ℝ} {m c : ℝ} (hX : Integrable X μ) + (hm : ∫ a, X a ∂μ = m) (hf : Integrable (fun a ↦ f (X a)) μ) + (h : ∀ᵐ a ∂μ, f m + c * (X a - m) ≤ f (X a)) : f m ≤ ∫ a, f (X a) ∂μ := + (integral_add_mul_sub hX hm (f m) c).symm.trans_le <| + integral_mono_ae ((integrable_const _).add ((hX.sub (integrable_const m)).const_mul c)) hf h + +/-- **Strict Jensen's inequality through a supporting line.** If `X` has mean `m`, the line +`f m + c (X − m)` lies strictly below `f(X)` wherever `X ≠ m`, and `X` is not almost surely `m`, +then `f(m) < 𝔼[f(X)]`. -/ +theorem lt_integral_of_affine_lt {X : α → ℝ} {f : ℝ → ℝ} {m c : ℝ} (hX : Integrable X μ) + (hm : ∫ a, X a ∂μ = m) (hf : Integrable (fun a ↦ f (X a)) μ) + (h : ∀ᵐ a ∂μ, X a ≠ m → f m + c * (X a - m) < f (X a)) (hX_ne : ¬X =ᵐ[μ] fun _ ↦ m) : + f m < ∫ a, f (X a) ∂μ := by + have hlin : Integrable (fun a ↦ f m + c * (X a - m)) μ := + (integrable_const _).add ((hX.sub (integrable_const m)).const_mul c) + have hle : (fun a ↦ f m + c * (X a - m)) ≤ᵐ[μ] fun a ↦ f (X a) := by + filter_upwards [h] with a ha + rcases eq_or_ne (X a) m with hXa | hXa + · simp [hXa] + · exact (ha hXa).le + refine (integral_add_mul_sub hX hm (f m) c).symm.trans_lt <| + integral_lt_integral_of_ae_le_of_not_ae_eq hlin hf hle fun h_eq ↦ hX_ne ?_ + filter_upwards [h, h_eq] with a ha hfa + by_contra hXa + exact (ha hXa).ne hfa + +end MathFin diff --git a/LeanPool/MathFin/Probability/Analysis/Bisection.lean b/LeanPool/MathFin/Probability/Analysis/Bisection.lean new file mode 100644 index 0000000000..d05f6e3d6c --- /dev/null +++ b/LeanPool/MathFin/Probability/Analysis/Bisection.lean @@ -0,0 +1,151 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho, Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.Analysis.SpecificLimits.Basic + +/-! +# The bisection method + +The **bisection method** looks for a solution of `f x = C` on a bracket +`[lo, hi]`: evaluate `f` at the midpoint, keep the half whose endpoints still +straddle `C`, repeat. + +## Why bisection converges + +Bisection only ever asks whether `f m < C`. So the hypothesis it needs is that +`σ` is the **threshold** of `f` against `C` on the bracket: `f x < C ↔ x < σ` +for `x ∈ [lo, hi]`. The estimates converge to that threshold. A strictly +increasing `f` with `f σ = C` has this property (`StrictMonoOn.lt_iff_lt`), and +then the limit is the solution. The property itself asks for neither continuity +nor strictness, and in general `σ` need not solve `f σ = C`. +At a threshold, a step maps the *trap* `[lo, σ] × [σ, hi]` (left +endpoint below `σ`, right endpoint above) into itself: the two branches of the +step are the two directions of the threshold equivalence. `Set.MapsTo.iterate` +then traps `σ` in every bracket. Separately, and whatever `f` is, each step +halves the width. A bracket of width `(hi − lo) / 2ⁿ` that contains `σ` puts +its midpoint within `(hi − lo) / 2ⁿ⁺¹` of it. + +The iteration is a noncomputable definition over `ℝ`. Floating-point rounding +and stopping rules are out of scope. + +## Main definitions + +* `bisectStep`: one bisection step toward `f x = C` on a bracket: evaluate `f` at the midpoint and + keep the half whose endpoints still straddle `C`. +* `bisect`: the `n`-th bisection bracket from `(a, b)`. +* `bisectMid`: the `n`-th bisection estimate, the midpoint of the `n`-th bracket. + +## Main results + +* `bisectStep`, `bisect`, `bisectMid`: one step, the `n`-th bracket, and the + `n`-th estimate (the midpoint of the `n`-th bracket, counted from `n = 0`); + `bisect_zero` and `bisect_succ` unfold the iteration. +* `bisectStep_snd_sub_fst`, `bisect_snd_sub_fst`: a step halves the bracket, so + from any starting bracket `(a, b)` the `n`-th one has width `(b − a) / 2ⁿ`. +* `mapsTo_bisectStep`, `bisect_mem`: at a threshold `σ` the trap is invariant, + so every bracket contains `σ`. +* `bisectMid_mem_Icc`: at a threshold `σ ∈ [lo, hi]`, every estimate lies in `[lo, hi]`. +* `abs_bisectMid_sub_le`, `tendsto_bisectMid`: the `n`-th estimate is within + `(hi − lo) / 2ⁿ⁺¹` of `σ`, and the estimates converge to `σ`. + +## Tags + +bisection method, root finding, implied volatility solver, threshold, interval halving, JEL C63, +MSC 65M06 +-/ + +@[expose] public section + +namespace MathFin + +open Filter Topology + +/-- One **bisection step** toward `f x = C` on the bracket `I = (a, b)`: evaluate +`f` at the midpoint `m`, keep `(m, b)` if `f m < C` and `(a, m)` otherwise. -/ +noncomputable def bisectStep (f : ℝ → ℝ) (C : ℝ) (I : ℝ × ℝ) : ℝ × ℝ := + let m := (I.1 + I.2) / 2 + if f m < C then (m, I.2) else (I.1, m) + +/-- The `n`-th **bisection bracket** for `f x = C`, starting from `(a, b)`. -/ +noncomputable def bisect (f : ℝ → ℝ) (C a b : ℝ) (n : ℕ) : ℝ × ℝ := + (bisectStep f C)^[n] (a, b) + +/-- The **bisection estimate** after `n` steps: the midpoint of the `n`-th +bracket. At `n = 0` it is the midpoint of the starting bracket. -/ +noncomputable def bisectMid (f : ℝ → ℝ) (C a b : ℝ) (n : ℕ) : ℝ := + ((bisect f C a b n).1 + (bisect f C a b n).2) / 2 + +@[simp] lemma bisect_zero (f : ℝ → ℝ) (C a b : ℝ) : bisect f C a b 0 = (a, b) := rfl + +lemma bisect_succ (f : ℝ → ℝ) (C a b : ℝ) (n : ℕ) : + bisect f C a b (n + 1) = bisectStep f C (bisect f C a b n) := + Function.iterate_succ_apply' _ _ _ + +/-- A bisection step halves the bracket, whatever `f` and `C` are. -/ +lemma bisectStep_snd_sub_fst (f : ℝ → ℝ) (C : ℝ) (I : ℝ × ℝ) : + (bisectStep f C I).2 - (bisectStep f C I).1 = (I.2 - I.1) / 2 := by + simp only [bisectStep] + split_ifs <;> ring + +/-- **Halving**: the `n`-th bracket has width `(b − a) / 2ⁿ`, whatever `f` and +`C` are. -/ +theorem bisect_snd_sub_fst (f : ℝ → ℝ) (C a b : ℝ) (n : ℕ) : + (bisect f C a b n).2 - (bisect f C a b n).1 = (b - a) / 2 ^ n := by + induction n with + | zero => simp + | succ n ih => rw [bisect_succ, bisectStep_snd_sub_fst, ih, pow_succ, div_div] + +variable {f : ℝ → ℝ} {C lo hi σ : ℝ} + +/-- **The trap is invariant.** If `σ` is the threshold of `f` against `C` on +`[lo, hi]`, a bisection step keeps the left endpoint in `[lo, σ]` and the right +endpoint in `[σ, hi]`: at the midpoint `m`, `f m < C` means `m < σ`, and +otherwise `σ ≤ m`. -/ +theorem mapsTo_bisectStep (hC : ∀ x ∈ Set.Icc lo hi, f x < C ↔ x < σ) : + Set.MapsTo (bisectStep f C) (Set.Icc lo σ ×ˢ Set.Icc σ hi) + (Set.Icc lo σ ×ˢ Set.Icc σ hi) := by + rintro ⟨a, b⟩ ⟨⟨hla, haσ⟩, hσb, hbh⟩ + have hm : (a + b) / 2 ∈ Set.Icc lo hi := ⟨by linarith, by linarith⟩ + simp only [bisectStep] + split_ifs with h + · exact ⟨⟨hm.1, ((hC _ hm).1 h).le⟩, hσb, hbh⟩ + · exact ⟨⟨hla, haσ⟩, not_lt.1 ((hC _ hm).not.1 h), hm.2⟩ + +/-- **Every bisection bracket traps the threshold**: the `n`-th bracket +`(aₙ, bₙ)` from `(lo, hi)` has `aₙ ∈ [lo, σ]` and `bₙ ∈ [σ, hi]`. -/ +theorem bisect_mem (hC : ∀ x ∈ Set.Icc lo hi, f x < C ↔ x < σ) (hσ : σ ∈ Set.Icc lo hi) + (n : ℕ) : bisect f C lo hi n ∈ Set.Icc lo σ ×ˢ Set.Icc σ hi := + (mapsTo_bisectStep hC).iterate n ⟨⟨le_rfl, hσ.1⟩, hσ.2, le_rfl⟩ + +/-- **Error bound**: the `n`-th estimate is within `(hi − lo) / 2ⁿ⁺¹` of the +threshold, half the width of a bracket that contains both. -/ +theorem abs_bisectMid_sub_le (hC : ∀ x ∈ Set.Icc lo hi, f x < C ↔ x < σ) + (hσ : σ ∈ Set.Icc lo hi) (n : ℕ) : + |bisectMid f C lo hi n - σ| ≤ (hi - lo) / 2 ^ (n + 1) := by + obtain ⟨⟨-, ha⟩, hb, -⟩ := bisect_mem hC hσ n + rw [pow_succ, ← div_div, ← bisect_snd_sub_fst f C, bisectMid, abs_sub_le_iff] + constructor <;> linarith + +/-- **The estimate stays in the bracket**: the `n`-th bisection estimate lies +in `[lo, hi]`, since it is the midpoint of a sub-bracket of `[lo, hi]`. -/ +theorem bisectMid_mem_Icc (hC : ∀ x ∈ Set.Icc lo hi, f x < C ↔ x < σ) (hσ : σ ∈ Set.Icc lo hi) + (n : ℕ) : bisectMid f C lo hi n ∈ Set.Icc lo hi := by + obtain ⟨⟨h1, h2⟩, h3, h4⟩ := bisect_mem hC hσ n + constructor <;> simp only [bisectMid] <;> linarith + +/-- **Convergence**: the bisection estimates converge to the threshold. -/ +theorem tendsto_bisectMid (hC : ∀ x ∈ Set.Icc lo hi, f x < C ↔ x < σ) + (hσ : σ ∈ Set.Icc lo hi) : Tendsto (bisectMid f C lo hi) atTop (𝓝 σ) := + tendsto_iff_dist_tendsto_zero.2 <| squeeze_zero (fun _ ↦ dist_nonneg) + (abs_bisectMid_sub_le hC hσ) <| tendsto_const_nhds.div_atTop <| + (tendsto_pow_atTop_atTop_of_one_lt one_lt_two).comp (tendsto_add_atTop_nat 1) + +end MathFin diff --git a/LeanPool/MathFin/Probability/Analysis/DerivOfDeriv.lean b/LeanPool/MathFin/Probability/Analysis/DerivOfDeriv.lean new file mode 100644 index 0000000000..8e6ba20e07 --- /dev/null +++ b/LeanPool/MathFin/Probability/Analysis/DerivOfDeriv.lean @@ -0,0 +1,77 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.Convex.Deriv +public import Mathlib.Analysis.InnerProductSpace.Basic + +/-! +# Second derivatives, from a formula or from convexity + +A higher-order sensitivity is usually computed by differentiating an explicit formula for a +lower-order one: gamma as `∂_S Φ(d₁)`, because the call delta is `Φ(d₁)`. That computation is a +statement about the formula. It becomes a statement about the price once the formula is known +to *be* the price's derivative on a neighbourhood of the point: then `deriv` of the price agrees +with the formula near the point, and so do their derivatives there. + +* `hasDerivAt_deriv_of_eventually`: `f' = g` near `x` and `g'(x) = c` give `(deriv f)'(x) = c`. +* `hasDerivAt_deriv_param_of_eventually`: the same for a mixed partial `s ↦ ∂_y F(s, y)` at + `x`, when `∂_y F(s, y) = g s` for every `s` near `x`. +* `deriv_deriv_nonneg_of_convexOn`: the converse direction of the second-derivative test. A + convex function's second derivative is non-negative on an open set where it is + differentiable. + +## Main results + +* `hasDerivAt_deriv_param_of_eventually`: if `F s` has derivative `g s` at `y` for all `s` near + `x` and `g` has derivative `g'` at `x`, then `s ↦ deriv (F s) y` has derivative `g'` at `x`. +* `deriv_deriv_nonneg_of_convexOn`: a function convex on an open set `S` and differentiable at + every point of `S` has `0 ≤ deriv (deriv f) x` for `x ∈ S`. + +## Tags + +gamma, second derivative, convexity test, Greeks, sensitivity, differentiation of formula, +MSC 91G20, JEL G13 +-/ + +@[expose] public section + +open Topology + +namespace MathFin + +variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] + [NormedSpace 𝕜 E] + +/-- If `f` has derivative `g y` at every `y` near `x`, and `g` has derivative `g'` at `x`, +then `deriv f` has derivative `g'` at `x`: the second derivative of `f` at `x` is the +derivative of its first-derivative formula. -/ +theorem hasDerivAt_deriv_of_eventually {f g : 𝕜 → E} {x : 𝕜} {g' : E} + (hf : ∀ᶠ y in 𝓝 x, HasDerivAt f (g y) y) (hg : HasDerivAt g g' x) : + HasDerivAt (deriv f) g' x := + hg.congr_of_eventuallyEq (hf.mono fun _ hy ↦ hy.deriv) + +/-- The mixed-partial form: if for every `s` near `x` the function `F s` has derivative +`g s` at `y`, and `g` has derivative `g'` at `x`, then `s ↦ deriv (F s) y` has derivative +`g'` at `x`. -/ +theorem hasDerivAt_deriv_param_of_eventually {F : 𝕜 → 𝕜 → E} {g : 𝕜 → E} {x y : 𝕜} {g' : E} + (hF : ∀ᶠ s in 𝓝 x, HasDerivAt (F s) (g s) y) (hg : HasDerivAt g g' x) : + HasDerivAt (fun s ↦ deriv (F s) y) g' x := + hg.congr_of_eventuallyEq (hF.mono fun _ hs ↦ hs.deriv) + +/-- A convex function has a non-negative second derivative on an open set where it is +differentiable: its derivative is monotone there (`ConvexOn.monotoneOn_deriv`), and a monotone +function's derivative is non-negative. The converse direction of `convexOn_of_deriv2_nonneg'`. -/ +theorem deriv_deriv_nonneg_of_convexOn {S : Set ℝ} {f : ℝ → ℝ} (hf : ConvexOn ℝ S f) + (hS : IsOpen S) (hd : ∀ x ∈ S, DifferentiableAt ℝ f x) {x : ℝ} (hx : x ∈ S) : + 0 ≤ deriv (deriv f) x := by + rw [← derivWithin_of_isOpen hS hx] + exact (hf.monotoneOn_deriv hd).derivWithin_nonneg + +end MathFin diff --git a/LeanPool/MathFin/Probability/Analysis/ExponentialDiscount.lean b/LeanPool/MathFin/Probability/Analysis/ExponentialDiscount.lean new file mode 100644 index 0000000000..4a1404a9e4 --- /dev/null +++ b/LeanPool/MathFin/Probability/Analysis/ExponentialDiscount.lean @@ -0,0 +1,129 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus + +/-! +# The exponential-discount / cumulative-rate principle + +Five apparently distinct quantities in this library share *one* structural +identity: + + *quantity* = `exp(−H(t))`, where `H(t) = ∫₀^t rate(u) du`. + +The instances: + +| object | rate `r(u)` | quantity | +|---|---|---| +| Zero-coupon bond | risk-free rate `r` | `P(t) = exp(−r·(T−t))` | +| Hazard credit | hazard intensity `h` | `S(t) = exp(−h·(T−t))` | +| Survival w/ curve | hazard function `h(u)` | `S(t) = exp(−∫₀^t h(u) du)` (`HazardCurve`) | +| Force of mortality | force `μ(u)` | survival = `exp(−∫₀^t μ(u) du)` (`Mortality`) | +| Vasicek deterministic | drift toward `θ` | `r(t) = θ + (r₀−θ)·exp(−κt)` (no integral) | + +## The dual identity: rate as negative-log-derivative + +Given a *quantity* `Q(t) = exp(−H(t))`, the rate can be *recovered*: + + `−d/dt log Q(t) = d/dt H(t) = rate(t)`. + +This is the conceptual content of every "rate from term-structure" formula: + +* **Forward rate from spot rate**: `f(T) = −d/dT log P(T)` where + `P(T) = exp(−T · R(T))`. (`ForwardRate.lean`) +* **Force of mortality from survival**: `μ(t) = −d/dt log S(t)`. (`Mortality.lean`) +* **Hazard intensity from survival**: `h(t) = −d/dt log S(t)`. (`HazardCurve.lean`) + +The proof is one step: `log(exp(x)) = x` (Mathlib `Real.log_exp`). The +derivative-of-`H` hypothesis carries through unchanged. We record this +identity as `rate_eq_neg_log_deriv` below. + +## Main definitions + +* `cumulativeIntensity`: the cumulative `∫₀ᵗ r(u) du` of a rate `r : ℝ → ℝ`. +* `survivalFromIntensity`: `S(t) = exp(−∫₀ᵗ r(u) du)`, the survival (or discount) factor of a + rate. + +## Main results + +* `rate_eq_neg_log_deriv`: if `H` has derivative `H'(t)` at `t`, then + `-d/dt log(exp(-H(t))) = H'(t)` at `t`. This is the universal + "rate from quantity" recovery. +* `survivalFromIntensity_zero`, `hasDerivAt_neg_log_survivalFromIntensity`: the survival of an + intensity starts at `1` and the intensity is its negative log-derivative. +* `discount_pos`: `exp(-H) > 0` always (so all five discount/survival + quantities are positive). + +## Tags + +discount factor, hazard rate, force of mortality, survival probability, forward rate, +cumulative rate, MSC 91G30, JEL E43, JEL G12 +-/ + +@[expose] public section + +namespace MathFin + +open Real MeasureTheory intervalIntegral + +/-- **The universal rate-recovery identity**: if `H` is differentiable at +`t` with derivative `H'`, then `−d/dt log(exp(−H(t))) = H'(t)` at `t`. + +This is the conceptual reason `forward rate = −d/dT log P` (`ZCB`, `ForwardRate`), +`force of mortality = −d/dt log S` (`Mortality`), and `hazard = −d/dt log S` +(`HazardCurve`) are all *the same identity*: each computes the rate from +the discount/survival, the difference is only in what `H` represents. + +The proof: `log(exp(−H s)) = −H s` (logs and exps are inverses), so +`−log(exp(−H s)) = H s`, and the derivative of the LHS equals `H'(t)` by +hypothesis. -/ +theorem rate_eq_neg_log_deriv {H : ℝ → ℝ} {H' t : ℝ} + (hH : HasDerivAt H H' t) : + HasDerivAt (fun s ↦ -(Real.log (Real.exp (-H s)))) H' t := by + have h_eq : (fun s : ℝ ↦ -(Real.log (Real.exp (-H s)))) = H := by + funext s; rw [Real.log_exp, neg_neg] + rw [h_eq] + exact hH + +/-- Universal discount/survival positivity: `0 < exp(−H)` for any `H`. + +Underpins `survival_pos` (constant-hazard credit), `hazardSurvival_pos` +(time-varying hazard), `survivalFromForce_pos` (mortality), and the +implicit positivity of the BS discount factor `exp(−rT)`. -/ +lemma discount_pos (H : ℝ) : 0 < Real.exp (-H) := Real.exp_pos _ + +/-- **Cumulative intensity** `∫₀ᵗ r(u) du` — the domain-neutral cumulative of a +rate/intensity/force. The single definition that the actuarial cumulative force +(`Mortality.forceCumulative`) and the credit cumulative hazard +(`FixedIncome.HazardCurve.cumHazard`) share. -/ +noncomputable def cumulativeIntensity (r : ℝ → ℝ) (t : ℝ) : ℝ := + ∫ u in (0:ℝ)..t, r u + +/-- **Survival from an intensity** `S(t) = exp(−∫₀ᵗ r(u) du)` — the domain-neutral +survival function. The single definition shared by the actuarial survival +(`Mortality.survivalFromForce`) and the credit survival +(`FixedIncome.HazardCurve.hazardSurvival`): one calculus, two domains. -/ +noncomputable def survivalFromIntensity (r : ℝ → ℝ) (t : ℝ) : ℝ := + Real.exp (-(cumulativeIntensity r t)) + +/-- `S(0) = 1`: nothing accrues before time `0`. -/ +lemma survivalFromIntensity_zero (r : ℝ → ℝ) : survivalFromIntensity r 0 = 1 := by + rw [survivalFromIntensity, cumulativeIntensity, integral_same, neg_zero, Real.exp_zero] + +/-- **An intensity is the negative log-derivative of its survival**: for continuous `r`, +`−d/dt log S(t) = r(t)` — the fundamental theorem of calculus for `cumulativeIntensity` +followed by `rate_eq_neg_log_deriv`. -/ +theorem hasDerivAt_neg_log_survivalFromIntensity {r : ℝ → ℝ} (hr : Continuous r) (t : ℝ) : + HasDerivAt (fun s ↦ -(Real.log (survivalFromIntensity r s))) (r t) t := + rate_eq_neg_log_deriv (H := cumulativeIntensity r) + (intervalIntegral.integral_hasDerivAt_right (hr.intervalIntegrable 0 t) + (hr.stronglyMeasurableAtFilter _ _) hr.continuousAt) + +end MathFin diff --git a/LeanPool/MathFin/Probability/Analysis/ExtendOfNormIsometry.lean b/LeanPool/MathFin/Probability/Analysis/ExtendOfNormIsometry.lean new file mode 100644 index 0000000000..c1f7b89463 --- /dev/null +++ b/LeanPool/MathFin/Probability/Analysis/ExtendOfNormIsometry.lean @@ -0,0 +1,66 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.Normed.Operator.Extend + +/-! +# `extendOfNorm` of a pointwise isometry is a global isometry + +The single generic lemma `LinearMap.norm_extendOfNorm_eq_of_isometry`: if a linear map `e` has dense +range and a (semi)linear map `f` is a pointwise isometry along it (`‖f x‖ = ‖e x‖`), then the +norm-continuous extension `f.extendOfNorm e` is a global isometry `‖f.extendOfNorm e y‖ = ‖y‖`. + +This is the shared analytic kernel of every `L²`-isometry-by-density construction in the library — +the Wiener integral, the Itô CLM, the predictable Itô `L²` integral, and the Itô–Lévy compensated +integral. It lives in its own `Mathlib`-only leaf so both the Brownian (`WienerIntegral`) and jump +(`PoissonCompensatedIntegralOperator`) towers consume it without depending on each other. + +The `≤` half is Mathlib's `LinearMap.norm_extendOfNorm_apply_le` (with `C = 1`); the reverse half is +`DenseRange.induction_on`, propagating the pointwise isometry off the dense range to a closed +equality set. + +## Main results + +* `norm_extendOfNorm_eq_of_isometry`: if `e` has dense range and `f` is a pointwise isometry along + `e` (`‖f x‖ = ‖e x‖`), then its norm-continuous extension satisfies `‖f.extendOfNorm e y‖ = ‖y‖` + for all `y`. + +## Tags + +isometry extension, Itô integral, Wiener integral, density argument, L2 isometry, MSC 60H05, +MSC 60G51 +-/ + +@[expose] public section + +namespace LinearMap + +variable {𝕜 𝕜₂ E Eₗ F : Type*} + [NormedDivisionRing 𝕜] [NormedDivisionRing 𝕜₂] {σ₁₂ : 𝕜 →+* 𝕜₂} + [AddCommGroup E] [SeminormedAddCommGroup Eₗ] [NormedAddCommGroup F] + [Module 𝕜 E] [Module 𝕜₂ F] [IsBoundedSMul 𝕜₂ F] [Module 𝕜 Eₗ] [IsBoundedSMul 𝕜 Eₗ] + [CompleteSpace F] + {f : E →ₛₗ[σ₁₂] F} {e : E →ₗ[𝕜] Eₗ} + +/-- If `e` has dense range and `f` is a pointwise isometry along `e` +(`‖f x‖ = ‖e x‖`), then the `extendOfNorm` extension of `f` along `e` is a global +isometry `‖f.extendOfNorm e y‖ = ‖y‖`. The shared kernel of the Wiener, +Itô-CLM, predictable-Itô, and Itô–Lévy `L²` isometries. -/ +theorem norm_extendOfNorm_eq_of_isometry + (h_dense : DenseRange e) (h_isom : ∀ x, ‖f x‖ = ‖e x‖) (y : Eₗ) : + ‖f.extendOfNorm e y‖ = ‖y‖ := by + have h_on_range : ∀ x, ‖f.extendOfNorm e (e x)‖ = ‖e x‖ := fun x ↦ by + rw [LinearMap.extendOfNorm_eq h_dense ⟨1, fun z ↦ by rw [one_mul]; exact (h_isom z).le⟩, + h_isom] + exact h_dense.induction_on (p := fun z ↦ ‖f.extendOfNorm e z‖ = ‖z‖) y + (isClosed_eq (continuous_norm.comp (f.extendOfNorm e).continuous) continuous_norm) + h_on_range + +end LinearMap diff --git a/LeanPool/MathFin/Probability/Analysis/FiniteMeasureCauchySchwarz.lean b/LeanPool/MathFin/Probability/Analysis/FiniteMeasureCauchySchwarz.lean new file mode 100644 index 0000000000..896ddd0a76 --- /dev/null +++ b/LeanPool/MathFin/Probability/Analysis/FiniteMeasureCauchySchwarz.lean @@ -0,0 +1,107 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.Probability.Moments.Variance + +/-! # Cauchy–Schwarz in expectation + +The real `L²` inequality `∫|f·g| ≤ √(∫ f²)·√(∫ g²)`, read off Mathlib's Hölder inequality +`integral_mul_norm_le_Lp_mul_Lq` at exponents `2, 2`, and its cases against the constant `1`: +`(∫ f)² ≤ ν(univ)·∫ f²` on a finite measure, and `∫|f| ≤ √(∫ f²)` on a probability measure. +Mathlib's `L²` Cauchy–Schwarz is stated for inner products of `Lp` classes, and Jensen +(`ConvexOn.map_integral_le`) gives only the probability case of the second, so the real forms are +assembled once here. + +Consumed by the drift `L²` energy bound (`DriftProcessPredictable`, at `ν = timeMeasure.restrict`), +the SDE-uniqueness drift estimate (`SDEUniqueness`, at `ν = volume.restrict (Ioc 0 s)`), and the +`L¹` bounds of the adapted quadratic variation (`AdaptedQuadraticVariation`). + +The same inequality at the centred variables `X − E X`, `Y − E Y` is Cauchy–Schwarz for the +covariance, `cov(X, Y) ≤ √Var X · √Var Y` (`covariance_le_sqrt_mul_sqrt`). Expanding +`Var(X + Y)` makes the standard deviation subadditive (`sqrt_variance_add_le`). Mathlib has the +covariance calculus but neither inequality. Consumed by the standard-deviation principle and the +Gaussian VaR subadditivity. + +## Main results + +* `integral_abs_mul_le_sqrt_mul_sqrt`: `∫|f·g| ≤ √(∫ f²)·√(∫ g²)` for `f, g` in `L²(ν)`. +* `sq_integral_le_measureReal_mul`: `(∫ f)² ≤ ν(univ)·∫ f²` on a finite measure. +* `integral_abs_le_sqrt_integral_sq`: `∫|f| ≤ √(∫ f²)` on a probability measure. +* `covariance_le_sqrt_mul_sqrt`: `cov(X, Y) ≤ √Var X · √Var Y` for `X, Y` in `L²(P)`. +* `sqrt_variance_add_le`: `√Var(X + Y) ≤ √Var X + √Var Y` for `X, Y` in `L²(P)`. + +## References + +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 8.11 + +## Tags + +Cauchy–Schwarz inequality, Hölder inequality, covariance bound, standard deviation subadditivity, +L2 bound, MSC 60E15, MSC 28A25 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory + +namespace MathFin + +variable {α : Type*} {m : MeasurableSpace α} {ν : Measure α} + +/-- **Cauchy–Schwarz in expectation**: `∫|f·g| ≤ √(∫ f²)·√(∫ g²)`, Hölder at exponents `2, 2`. -/ +theorem integral_abs_mul_le_sqrt_mul_sqrt {f g : α → ℝ} (hf : MemLp f 2 ν) (hg : MemLp g 2 ν) : + ∫ a, |f a * g a| ∂ν ≤ √(∫ a, f a ^ 2 ∂ν) * √(∫ a, g a ^ 2 ∂ν) := by + have h := integral_mul_norm_le_Lp_mul_Lq (μ := ν) Real.HolderConjugate.two_two (f := f) (g := g) + (by rwa [ENNReal.ofReal_ofNat]) (by rwa [ENNReal.ofReal_ofNat]) + have hsq (x : ℝ) : |x| ^ (2 : ℝ) = x ^ 2 := by rw [Real.rpow_two, sq_abs] + simpa only [Real.norm_eq_abs, hsq, ← Real.sqrt_eq_rpow, ← abs_mul] using h + +/-- **Cauchy–Schwarz on a finite measure**: `(∫ f)² ≤ ν(univ)·∫ f²`, the case `g ≡ 1`. -/ +theorem sq_integral_le_measureReal_mul [IsFiniteMeasure ν] {f : α → ℝ} (hf : MemLp f 2 ν) : + (∫ a, f a ∂ν) ^ 2 ≤ (ν Set.univ).toReal * ∫ a, (f a) ^ 2 ∂ν := by + have h := integral_abs_mul_le_sqrt_mul_sqrt hf (memLp_const (1 : ℝ)) + simp only [mul_one, one_pow, integral_const, smul_eq_mul] at h + calc (∫ a, f a ∂ν) ^ 2 = |∫ a, f a ∂ν| ^ 2 := (sq_abs _).symm + _ ≤ (√(∫ a, f a ^ 2 ∂ν) * √(ν.real Set.univ)) ^ 2 := + pow_le_pow_left₀ (abs_nonneg _) (abs_integral_le_integral_abs.trans h) 2 + _ = (ν Set.univ).toReal * ∫ a, (f a) ^ 2 ∂ν := by + rw [mul_pow, Real.sq_sqrt (integral_nonneg fun _ ↦ sq_nonneg _), + Real.sq_sqrt measureReal_nonneg, mul_comm, measureReal_def] + +/-- `∫|f| ≤ √(∫ f²)` on a probability measure, the case `g ≡ 1`. -/ +theorem integral_abs_le_sqrt_integral_sq [IsProbabilityMeasure ν] {f : α → ℝ} + (hf : MemLp f 2 ν) : ∫ a, |f a| ∂ν ≤ √(∫ a, f a ^ 2 ∂ν) := by + simpa using integral_abs_mul_le_sqrt_mul_sqrt hf (memLp_const (1 : ℝ)) + +section Covariance + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + {X Y : Ω → ℝ} + +/-- **Cauchy–Schwarz for covariance**: `cov(X, Y) ≤ √Var X · √Var Y`, the inequality +`integral_abs_mul_le_sqrt_mul_sqrt` for the centred variables. -/ +theorem covariance_le_sqrt_mul_sqrt (hX : MemLp X 2 P) (hY : MemLp Y 2 P) : + cov[X, Y; P] ≤ √Var[X; P] * √Var[Y; P] := by + rw [variance_eq_integral hX.aemeasurable, variance_eq_integral hY.aemeasurable] + exact (le_abs_self _).trans <| abs_integral_le_integral_abs.trans <| + integral_abs_mul_le_sqrt_mul_sqrt (hX.sub (memLp_const _)) (hY.sub (memLp_const _)) + +/-- **The standard deviation is subadditive**: `sd(X + Y) ≤ sd(X) + sd(Y)`. -/ +theorem sqrt_variance_add_le (hX : MemLp X 2 P) (hY : MemLp Y 2 P) : + √Var[fun ω ↦ X ω + Y ω; P] ≤ √Var[X; P] + √Var[Y; P] := by + rw [variance_fun_add hX hY] + have hcs := covariance_le_sqrt_mul_sqrt hX hY + refine Real.sqrt_le_iff.2 ⟨add_nonneg (Real.sqrt_nonneg _) (Real.sqrt_nonneg _), ?_⟩ + nlinarith [Real.sq_sqrt (variance_nonneg X P), Real.sq_sqrt (variance_nonneg Y P)] + +end Covariance + +end MathFin diff --git a/LeanPool/MathFin/Probability/Analysis/IndepFreezing.lean b/LeanPool/MathFin/Probability/Analysis/IndepFreezing.lean new file mode 100644 index 0000000000..f43d24df21 --- /dev/null +++ b/LeanPool/MathFin/Probability/Analysis/IndepFreezing.lean @@ -0,0 +1,266 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.MeasureTheory.Function.ConditionalExpectation.PullOut +public import Mathlib.Probability.ConditionalExpectation +public import Mathlib.Probability.HasLaw +public import Mathlib.Probability.Independence.Integration + +/-! +# Freezing an independent variable + +If `X` and `Y` are independent, the expectation of `g(X, Y)` can be computed by freezing `X` at +a value `x`, averaging `g(x, Y)` over `Y` alone, and then averaging the result over the law of +`X`: + + `𝔼[g(X, Y)] = ∫ x, 𝔼[g(x, Y)] d(law X)`. + +This is the *freezing lemma*. When `X = N` is a count it is the law of total expectation over the +number of jumps, the step every Poisson-mixture computation takes: the jump-diffusion price, +Merton's among them, and the compound-Poisson moment generating function +(`Probability/Jumps/CompoundPoissonMGF.lean`) both go through it. With `X` a jump part of any law it +is the mixing formula of `Models/Jumps/JumpDiffusionMixing.lean`: a jump-diffusion call is the +Black–Scholes price averaged over the jumps. + +The proof composes two Mathlib facts: independence makes the joint law the product of the +marginal laws (`IndepFun.map_prod_eq_prod_map_map`), and an integral against a product measure +is an iterated integral (`integral_prod`). + +Its conditional form is Shreve's *independence lemma* (*Stochastic Calculus for Finance II*, +Lemma 2.3.4): if `X` is measurable for a σ-algebra `𝓜` and `Y` is independent of `𝓜`, then + + `𝔼[g(X, Y) | 𝓜] = G(X)`, with `G(x) = 𝔼[g(x, Y)]`. + +Given `𝓜`, `X` is known and `Y` keeps its law. On an event `s ∈ 𝓜` the joint law of `(X, Y)` +is the law of `X` on `s` times the law of `Y` (`map_restrict_prodMk_of_indep`), so the +unconditional computation runs on every such event, which characterizes the conditional +expectation. This is the step that prices an option at an intermediate date: the state at `t` is +known, and the increment to maturity is independent of the past (the American put's Brownian +transitions, `Models/BlackScholes/American/Stopping/BrownianTransition.lean`, and the jump-diffusion +prices of `Models/Jumps/JumpDiffusionOptionPrices.lean`). + +## Main results + +* `integrable_comp_prodMk_iff_of_indepFun`: `g(X, Y)` is integrable exactly when `g` is + integrable against the product of the laws. +* `integral_comp_prodMk_of_indepFun`: the freezing lemma. +* `integrable_prod_map_of_countable`: for a countable-valued `X`, integrability against the + product of the laws is checked one value of `X` at a time. +* `integral_comp_prodMk_of_indepFun_of_countable`: the freezing lemma for a countable-valued `X` + and a nonnegative `g`, with integrability checked one value of `X` at a time. +* `integral_comp_of_hasLaw_of_countable`: integrating out a countable variable. For `X` with + a countable law `ν`, independent of `Y`, and a nonnegative `F` whose expectations + `c a = 𝔼[F(a, Y)]` are finite and integrable against `ν`, `𝔼[F(X, Y)] = ∫ a, c a ∂ν`. With + `ν = Poisson(Λ)` this is the Poisson-mixture step. +* `condExp_comp_prodMk_of_indep`: the conditional freezing lemma (Shreve's independence lemma), + `𝔼[g(X, Y) | 𝓜] = G(X)` for `X` measurable for `𝓜` and `Y` independent of `𝓜`. +* `condExp_mul_of_indep`: `𝔼[X·Y | m] = X·𝔼[Y]` for `X` measurable for `m` and `Y` for a σ-algebra + independent of `m`. +* `indepFun_prodMk_of_indepFun_prodMk`: if `X` is independent of `(Y, W)` and `Y` of `W`, then + `Y` is independent of `(X, W)`. Mutual independence of three variables can be stated with any + of them split off first. + +## References + +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], Lemma + 2.3.4 + +## Tags + +freezing lemma, independence lemma, Shreve, law of total expectation, Poisson mixture, +conditional expectation, independent random variables, MSC 60E05, MSC 28A25, MSC 91G20 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory + +-- `m` (a sub-σ-algebra, used by the conditional lemmas) precedes `mΩ`, so that `mΩ` is the +-- measurable-space instance in force +variable {Ω α β E : Type*} {m mΩ : MeasurableSpace Ω} {mα : MeasurableSpace α} + {mβ : MeasurableSpace β} [NormedAddCommGroup E] + {P : Measure Ω} [IsFiniteMeasure P] {X : Ω → α} {Y : Ω → β} + +/-- For independent `X` and `Y`, `g(X, Y)` is integrable exactly when `g` is integrable against +the product of the laws of `X` and `Y`. -/ +theorem integrable_comp_prodMk_iff_of_indepFun (hXY : X ⟂ᵢ[P] Y) (hX : AEMeasurable X P) + (hY : AEMeasurable Y P) {g : α × β → E} + (hg : AEStronglyMeasurable g ((P.map X).prod (P.map Y))) : + Integrable (fun ω ↦ g (X ω, Y ω)) P ↔ Integrable g ((P.map X).prod (P.map Y)) := by + rw [← hXY.map_prod_eq_prod_map_map hX hY] at hg ⊢ + exact (integrable_map_measure hg (hX.prodMk hY)).symm + +/-- **The freezing lemma.** For independent `X` and `Y`, and `g` integrable against the product +of their laws, `𝔼[g(X, Y)] = ∫ x, 𝔼[g(x, Y)] d(law X)`. -/ +theorem integral_comp_prodMk_of_indepFun [NormedSpace ℝ E] (hXY : X ⟂ᵢ[P] Y) + (hX : AEMeasurable X P) (hY : AEMeasurable Y P) {g : α × β → E} + (hg : Integrable g ((P.map X).prod (P.map Y))) : + ∫ ω, g (X ω, Y ω) ∂P = ∫ x, ∫ ω, g (x, Y ω) ∂P ∂(P.map X) := by + have hmap := hXY.map_prod_eq_prod_map_map hX hY + have hgm : AEStronglyMeasurable g (P.map fun ω ↦ (X ω, Y ω)) := by + rw [hmap] + exact hg.aestronglyMeasurable + calc ∫ ω, g (X ω, Y ω) ∂P = ∫ p, g p ∂(P.map fun ω ↦ (X ω, Y ω)) := + (integral_map (hX.prodMk hY) hgm).symm + _ = ∫ x, ∫ y, g (x, y) ∂(P.map Y) ∂(P.map X) := by rw [hmap, integral_prod g hg] + _ = ∫ x, ∫ ω, g (x, Y ω) ∂P ∂(P.map X) := integral_congr_ae <| by + filter_upwards [hg.prod_right_ae] with x hx + exact integral_map hY hx.aestronglyMeasurable + +/-- For a countable-valued `X`, integrability of `g` against the product of the laws is checked +one value of `X` at a time: each `g(a, Y)` integrable, and `a ↦ 𝔼‖g(a, Y)‖` integrable against +the law of `X`. Measurability of the sections suffices, since `X` takes countably many values. -/ +theorem integrable_prod_map_of_countable [Countable α] [MeasurableSingletonClass α] + (hY : AEMeasurable Y P) {g : α × β → ℝ} (hgm : ∀ a, Measurable fun b ↦ g (a, b)) + (hint : ∀ a, Integrable (fun ω ↦ g (a, Y ω)) P) + (hint' : Integrable (fun a ↦ ∫ ω, ‖g (a, Y ω)‖ ∂P) (P.map X)) : + Integrable g ((P.map X).prod (P.map Y)) := by + refine (integrable_prod_iff + (measurable_from_prod_countable_right (f := g) hgm).aestronglyMeasurable).mpr + ⟨ae_of_all _ fun a ↦ (integrable_map_measure (hgm a).aestronglyMeasurable hY).mpr (hint a), + hint'.congr (ae_of_all _ fun a ↦ ?_)⟩ + exact (integral_map hY (hgm a).norm.aestronglyMeasurable).symm + +/-- **The freezing lemma for a countable variable.** For a countable-valued `X` independent of `Y` +and a nonnegative `g`, if each `g(a, Y)` is integrable and `a ↦ 𝔼[g(a, Y)]` is integrable against +the law of `X`, then `𝔼[g(X, Y)] = ∫ a, 𝔼[g(a, Y)] d(law X)`. -/ +theorem integral_comp_prodMk_of_indepFun_of_countable [Countable α] + [MeasurableSingletonClass α] (hXY : X ⟂ᵢ[P] Y) (hX : AEMeasurable X P) + (hY : AEMeasurable Y P) {g : α × β → ℝ} (hgm : ∀ a, Measurable fun b ↦ g (a, b)) + (hg0 : ∀ p, 0 ≤ g p) (hint : ∀ a, Integrable (fun ω ↦ g (a, Y ω)) P) + (hint' : Integrable (fun a ↦ ∫ ω, g (a, Y ω) ∂P) (P.map X)) : + ∫ ω, g (X ω, Y ω) ∂P = ∫ a, ∫ ω, g (a, Y ω) ∂P ∂(P.map X) := + integral_comp_prodMk_of_indepFun hXY hX hY <| integrable_prod_map_of_countable hY hgm hint <| + hint'.congr <| ae_of_all _ fun a ↦ integral_congr_ae <| ae_of_all _ fun ω ↦ + (Real.norm_of_nonneg (hg0 (a, Y ω))).symm + +/-- **Integrating out a countable variable.** For `X` with a countable law `ν`, independent of +`Y`, and a nonnegative `F`, if each `F(a, Y)` is integrable with expectation `c a` and `c` is +integrable against `ν`, then `𝔼[F(X, Y)] = ∫ a, c a ∂ν`. For a Poisson count this is the +Poisson-mixture step of a compound-Poisson computation. -/ +theorem integral_comp_of_hasLaw_of_countable [Countable α] [MeasurableSingletonClass α] + {ν : Measure α} (hX : HasLaw X ν P) (hY : AEMeasurable Y P) (hXY : X ⟂ᵢ[P] Y) + {F : α → β → ℝ} (hFm : ∀ a, Measurable fun y ↦ F a y) (hF0 : ∀ a y, 0 ≤ F a y) + {c : α → ℝ} (hint : ∀ a, Integrable (fun ω ↦ F a (Y ω)) P) + (hc : ∀ a, ∫ ω, F a (Y ω) ∂P = c a) (hcint : Integrable c ν) : + ∫ ω, F (X ω) (Y ω) ∂P = ∫ a, c a ∂ν := by + have hint' : Integrable (fun a ↦ ∫ ω, F a (Y ω) ∂P) (P.map X) := by + rw [hX.map_eq] + exact hcint.congr (ae_of_all _ fun a ↦ (hc a).symm) + calc ∫ ω, F (X ω) (Y ω) ∂P = ∫ a, ∫ ω, F a (Y ω) ∂P ∂(P.map X) := + integral_comp_prodMk_of_indepFun_of_countable (g := fun p ↦ F p.1 p.2) hXY + hX.aemeasurable hY hFm (fun p ↦ hF0 p.1 p.2) hint hint' + _ = ∫ a, c a ∂ν := by + rw [hX.map_eq] + exact integral_congr_ae (ae_of_all _ hc) + +/-! ### The conditional freezing lemma -/ + +/-- On an event `s` of a σ-algebra `m` for which `X` is measurable and of which `Y` is independent, +the joint law of `(X, Y)` under `P` restricted to `s` is the law of `X` on `s` times the law of `Y` +under `P`. Normalized by `P(s)`, it says that given `s`, `Y` keeps its law and stays independent of +`X`. -/ +theorem map_restrict_prodMk_of_indep (hm : m ≤ mΩ) (hX : Measurable[m] X) (hY : AEMeasurable Y P) + (hi : Indep (MeasurableSpace.comap Y mβ) m P) {s : Set Ω} (hs : MeasurableSet[m] s) : + (P.restrict s).map (fun ω ↦ (X ω, Y ω)) = ((P.restrict s).map X).prod (P.map Y) := by + have hX' : Measurable X := hX.mono hm le_rfl + refine (Measure.prod_eq fun A B hA hB ↦ ?_).symm + rw [Measure.map_apply_of_aemeasurable (hX'.aemeasurable.prodMk hY).restrict (hA.prod hB), + Measure.map_apply hX' hA, Measure.map_apply_of_aemeasurable hY hB, + Measure.restrict_apply' (hm s hs), Measure.restrict_apply' (hm s hs), Set.mk_preimage_prod, + Set.inter_right_comm, Set.inter_comm _ (Y ⁻¹' B), mul_comm] + exact (Indep_iff _ _ _).1 hi _ _ ⟨B, hB, rfl⟩ ((hX hA).inter hs) + +/-- **The conditional freezing lemma** (Shreve's independence lemma). If `X` is measurable for a +σ-algebra `m` and `Y` is independent of `m`, then `𝔼[g(X, Y) | m] = G(X)` almost surely, with +`G(x) = ∫ g(x, y) d(law Y)(y)`, for `g` strongly measurable and `g(X, Y)` integrable: given `m`, +`X` is known and `Y` keeps its law. On each event of `m` the joint law of `(X, Y)` is a product +(`map_restrict_prodMk_of_indep`), so both sides have the same integral over it. -/ +theorem condExp_comp_prodMk_of_indep [NormedSpace ℝ E] [CompleteSpace E] (hm : m ≤ mΩ) + (hX : Measurable[m] X) (hY : AEMeasurable Y P) + (hi : Indep (MeasurableSpace.comap Y mβ) m P) {g : α × β → E} (hg : StronglyMeasurable g) + (hgi : Integrable (fun ω ↦ g (X ω, Y ω)) P) : + P[fun ω ↦ g (X ω, Y ω) | m] =ᵐ[P] fun ω ↦ ∫ y, g (X ω, y) ∂(P.map Y) := by + have hX' : Measurable X := hX.mono hm le_rfl + have hG : StronglyMeasurable fun x ↦ ∫ y, g (x, y) ∂(P.map Y) := hg.integral_prod_right' + -- on each event of `m`, `g` is integrable against the product law + have hgs (s : Set Ω) (hs : MeasurableSet[m] s) : + Integrable g (((P.restrict s).map X).prod (P.map Y)) := by + rw [← map_restrict_prodMk_of_indep hm hX hY hi hs] + exact (integrable_map_measure hg.aestronglyMeasurable + (hX'.aemeasurable.prodMk hY).restrict).2 hgi.restrict + refine (ae_eq_condExp_of_forall_setIntegral_eq hm hgi (fun _ _ _ ↦ ?_) (fun s hs _ ↦ ?_) + (hG.comp_measurable hX).aestronglyMeasurable).symm + · have hGi := (hgs Set.univ MeasurableSet.univ).integral_prod_left + rw [Measure.restrict_univ] at hGi + exact (hGi.comp_measurable hX').integrableOn + · calc ∫ ω in s, ∫ y, g (X ω, y) ∂(P.map Y) ∂P + = ∫ x, ∫ y, g (x, y) ∂(P.map Y) ∂((P.restrict s).map X) := + (integral_map hX'.aemeasurable hG.aestronglyMeasurable).symm + _ = ∫ p, g p ∂((P.restrict s).map fun ω ↦ (X ω, Y ω)) := by + rw [map_restrict_prodMk_of_indep hm hX hY hi hs, integral_prod g (hgs s hs)] + _ = ∫ ω in s, g (X ω, Y ω) ∂P := + integral_map (hX'.aemeasurable.prodMk hY).restrict hg.aestronglyMeasurable + +/-- **Pulling out a known factor against an independent one.** If `X` is `m`-measurable and `Y` +is measurable for a σ-algebra `m'` independent of `m` (both integrable), then +`𝔼[X·Y | m] = X·𝔼[Y]` almost surely: given `m`, `X` is known and `Y` keeps its mean. With +`X = e^{a+Z}` and `Y = e^{W}`, for `Z` known and `W` independent of the past, this is the +conditional exponential moment of a sum. -/ +theorem condExp_mul_of_indep {m' : MeasurableSpace Ω} {X Y : Ω → ℝ} (hm : m ≤ mΩ) + (hm' : m' ≤ mΩ) (hi : Indep m' m P) (hX : StronglyMeasurable[m] X) + (hY : StronglyMeasurable[m'] Y) (hXi : Integrable X P) (hYi : Integrable Y P) : + P[X * Y | m] =ᵐ[P] fun ω ↦ X ω * ∫ ω, Y ω ∂P := by + have hind : IndepFun X Y P := + (IndepFun_iff_Indep _ _ _).2 + (indep_of_indep_of_le_right (indep_of_indep_of_le_left hi.symm hX.measurable.comap_le) + hY.measurable.comap_le) + refine (condExp_mul_of_stronglyMeasurable_left hX (hind.integrable_mul hXi hYi) hYi).trans ?_ + filter_upwards [condExp_indep_eq hm' hm hY hi] with ω h + rw [Pi.mul_apply, h] + +/-! ### Re-associating independence -/ + +/-- Moving the middle factor of a triple product measure to the front: +`(μ ⊗ (ν ⊗ ρ)).map ((a, b, c) ↦ (b, a, c)) = ν ⊗ (μ ⊗ ρ)`. -/ +theorem map_prod_prod_rotate {γ : Type*} {mγ : MeasurableSpace γ} (μ : Measure α) + (ν : Measure β) (ρ : Measure γ) [SFinite μ] [SFinite ν] [SFinite ρ] : + (μ.prod (ν.prod ρ)).map (fun p : α × β × γ ↦ (p.2.1, p.1, p.2.2)) = ν.prod (μ.prod ρ) := by + have hrot : (fun p : α × β × γ ↦ (p.2.1, p.1, p.2.2)) + = MeasurableEquiv.prodAssoc ∘ Prod.map Prod.swap id ∘ MeasurableEquiv.prodAssoc.symm := + rfl + rw [hrot, ← Measure.map_map MeasurableEquiv.prodAssoc.measurable + ((measurable_swap.prodMap measurable_id).comp MeasurableEquiv.prodAssoc.symm.measurable), + ← Measure.map_map (measurable_swap.prodMap measurable_id) + MeasurableEquiv.prodAssoc.symm.measurable, + ← Measure.prodAssoc_prod (μ := μ), MeasurableEquiv.map_symm_map, + ← Measure.map_prod_map (μ.prod ν) ρ measurable_swap measurable_id, Measure.prod_swap, + Measure.map_id, Measure.prodAssoc_prod] + +/-- **Re-associating independence.** If `X` is independent of `(Y, W)` and `Y` of `W`, then `Y` +is independent of `(X, W)`. Either pair of hypotheses says that `X`, `Y` and `W` are mutually +independent: the joint law is the product of the three marginal laws. -/ +theorem indepFun_prodMk_of_indepFun_prodMk {γ : Type*} {mγ : MeasurableSpace γ} {W : Ω → γ} + (hX : AEMeasurable X P) (hY : AEMeasurable Y P) (hW : AEMeasurable W P) + (hXYW : X ⟂ᵢ[P] fun ω ↦ (Y ω, W ω)) (hYW : Y ⟂ᵢ[P] W) : + Y ⟂ᵢ[P] fun ω ↦ (X ω, W ω) := by + have hXW : X ⟂ᵢ[P] W := hXYW.comp measurable_id measurable_snd + have hrot : Measurable fun p : α × β × γ ↦ (p.2.1, p.1, p.2.2) := by fun_prop + rw [indepFun_iff_map_prod_eq_prod_map_map hY (hX.prodMk hW), + hXW.map_prod_eq_prod_map_map hX hW, + show (fun ω ↦ (Y ω, X ω, W ω)) + = (fun p : α × β × γ ↦ (p.2.1, p.1, p.2.2)) ∘ fun ω ↦ (X ω, Y ω, W ω) from rfl, + ← AEMeasurable.map_map_of_aemeasurable hrot.aemeasurable (hX.prodMk (hY.prodMk hW)), + hXYW.map_prod_eq_prod_map_map hX (hY.prodMk hW), hYW.map_prod_eq_prod_map_map hY hW] + exact map_prod_prod_rotate _ _ _ + +end MathFin diff --git a/LeanPool/MathFin/Probability/Analysis/IndepIsometryKernel.lean b/LeanPool/MathFin/Probability/Analysis/IndepIsometryKernel.lean new file mode 100644 index 0000000000..bb7365733d --- /dev/null +++ b/LeanPool/MathFin/Probability/Analysis/IndepIsometryKernel.lean @@ -0,0 +1,82 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Independence.Integration + +/-! +# The isometry kernel: a past-measurable coefficient against an independent increment + +The Itô isometry for the Brownian integral and for the compensated-Poisson integral is a sum of +the same three one-term facts, each about a coefficient `φ` (measurable for the past) and a fresh +increment `X` (a Brownian increment, a compensated Poisson count) independent of it: + +* the coefficient pairs to zero against a centred increment, `𝔼[φ·X] = 0` + (`IndepFun.integral_mul_eq_zero`), which makes the integral a martingale; +* the diagonal energy `𝔼[χ·X²] = 𝔼[χ]·𝔼[X²]` (`IndepFun.integral_mul_sq`), with `χ = φ²`; +* `L²`-membership of the product `φ·X` (`IndepFun.memLp_two_mul`). + +Nothing here knows where the independence comes from: the Brownian kernel +(`ItoIsometryAdapted`) supplies it from `IsFilteredPreBrownian.indep`, the Poisson kernel +(`PoissonCompensatedIsometryAdapted`) from `indep_of_disjoint_region`, and both then read the +one-term facts off these three lemmas. + +## Main results + +* `IndepFun.integral_mul_comp`: if `φ` is independent of `X`, then `𝔼[φ·g(X)] = 𝔼[φ]·𝔼[g(X)]` + for measurable `g`. +* `IndepFun.integral_mul_eq_zero`: if `φ` is independent of a centred `X`, then `𝔼[φ·X] = 0`. +* `IndepFun.integral_mul_sq`: if `φ` is independent of `X`, then `𝔼[φ·X²] = 𝔼[φ]·𝔼[X²]`. +* `IndepFun.memLp_two_mul`: the product of an independent pair in `L²` is in `L²`. + +## Tags + +Itô isometry, independent increments, martingale difference, compensated Poisson, second moment, +orthogonality, MSC 60H05, MSC 60G51, MSC 60G55 +-/ + +@[expose] public section + +namespace ProbabilityTheory + +open MeasureTheory + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {φ X : Ω → ℝ} + +/-- **A coefficient against a function of an independent increment factorises**: +`𝔼[φ·g(X)] = 𝔼[φ]·𝔼[g(X)]` (Mathlib's `IndepFun.integral_fun_comp_mul_comp` at `f = id`, the +form every isometry kernel uses: `g` a power of the increment, possibly shifted). -/ +theorem IndepFun.integral_mul_comp (h : IndepFun φ X μ) {g : ℝ → ℝ} (hg : Measurable g) + (hφ : AEStronglyMeasurable φ μ) (hX : AEMeasurable X μ) : + ∫ ω, φ ω * g (X ω) ∂μ = (∫ ω, φ ω ∂μ) * ∫ ω, g (X ω) ∂μ := + h.integral_fun_comp_mul_comp (f := id) hφ.aemeasurable hX aestronglyMeasurable_id + hg.aestronglyMeasurable + +/-- **A coefficient independent of a centred increment pairs to zero**: `𝔼[φ·X] = 0`. -/ +theorem IndepFun.integral_mul_eq_zero (h : IndepFun φ X μ) (hφ : AEStronglyMeasurable φ μ) + (hX : AEStronglyMeasurable X μ) (h0 : ∫ ω, X ω ∂μ = 0) : ∫ ω, φ ω * X ω ∂μ = 0 := by + rw [h.integral_fun_mul_eq_mul_integral hφ hX, h0, mul_zero] + +/-- **Diagonal energy**: for `χ` independent of `X`, `𝔼[χ·X²] = 𝔼[χ]·𝔼[X²]`. With `χ = φ²` and +`𝔼[X²]` the variance of the increment, this is the diagonal term of the isometry. -/ +theorem IndepFun.integral_mul_sq (h : IndepFun φ X μ) (hφ : AEStronglyMeasurable φ μ) + (hX : AEStronglyMeasurable X μ) : + ∫ ω, φ ω * X ω ^ 2 ∂μ = (∫ ω, φ ω ∂μ) * ∫ ω, X ω ^ 2 ∂μ := + h.integral_mul_comp (g := fun x : ℝ ↦ x ^ 2) (by fun_prop) hφ hX.aemeasurable + +/-- **A square-integrable coefficient times an independent square-integrable increment is +square-integrable**, since `𝔼[(φ·X)²] = 𝔼[φ²]·𝔼[X²]` is finite. -/ +theorem IndepFun.memLp_two_mul (h : IndepFun φ X μ) (hφ : MemLp φ 2 μ) (hX : MemLp X 2 μ) : + MemLp (fun ω ↦ φ ω * X ω) 2 μ := + (memLp_two_iff_integrable_sq (hφ.aestronglyMeasurable.mul hX.aestronglyMeasurable)).2 <| by + simpa [Pi.mul_def, Function.comp_def, mul_pow] using + (h.comp (φ := fun x : ℝ ↦ x ^ 2) (ψ := fun x : ℝ ↦ x ^ 2) (by fun_prop) + (by fun_prop)).integrable_mul hφ.integrable_sq hX.integrable_sq + +end ProbabilityTheory diff --git a/LeanPool/MathFin/Probability/Analysis/LpMulIsometry.lean b/LeanPool/MathFin/Probability/Analysis/LpMulIsometry.lean new file mode 100644 index 0000000000..f22e259478 --- /dev/null +++ b/LeanPool/MathFin/Probability/Analysis/LpMulIsometry.lean @@ -0,0 +1,280 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.MeasureTheory.Function.L2Space + +/-! # Multiplication by `f` as an isometry `L²(f²·ν) → L²(ν)` + +Multiplying by a fixed measurable `f` carries the weighted space `L²(f²·ν)` isometrically +into `L²(ν)`: + + `∫ |f·ψ|² dν = ∫ |ψ|²·f² dν = ∫ |ψ|² d(f²·ν)`, + +so `‖f·ψ‖_{L²(ν)} = ‖ψ‖_{L²(f²·ν)}`. This is the analytic content behind "the Itô integral +against `M = φ●B` is the Itô integral against `B` of `ψφ`": the bracket measure `d⟨M⟩ = φ²ds` +is the weight, and the chain rule is this isometry composed with `itoIntegralCLM`. + +Mathlib carries only the `p = 1` case, `withDensitySMulLI`, where the density and the +multiplier coincide; at `p = 2` the multiplier is the *square root* of the density, which is +what makes the norm come out right. The general-`p` statement +`‖f·ψ‖_{L^p(ν)} = ‖ψ‖_{L^p(‖f‖ᵖ·ν)}` is the natural home for this and is an upstreaming +candidate; only `p = 2` is built here, since that is the only exponent the Itô tower uses. + +## The well-definedness point + +`Lp ℝ 2 (sqWeight ν f)` is a space of classes modulo `(f²·ν)`-null sets, which is **coarser** +than modulo `ν`-null sets: `{f = 0}` is `(f²·ν)`-null but in general not `ν`-null. So two +representatives of one class can disagree on a `ν`-non-null set, and the map `ψ ↦ f·ψ` is +still well defined — on `{f ≠ 0}` the representatives agree, and on `{f = 0}` both products +vanish. Each linearity proof below therefore ends in a case split on `f x = 0`, exactly as +Mathlib's `withDensitySMulLI` does. This is the step at which a naive attempt breaks. + +## Main definitions + +* `sqWeight`: the measure `f²·ν`, with density `‖f‖ₑ²` against `ν`. +* `mulLM`: multiplication by a measurable `f` as a linear map `L²(f²·ν) →ₗ[ℝ] L²(ν)`. +* `mulLI`: the same map as a linear isometry `L²(f²·ν) →ₗᵢ[ℝ] L²(ν)`; `coeFn_mulLI` gives + `f·ψ` as its a.e. representative. + +## Main results + +* `lp_two_norm_sq` — `‖g‖² = ∫ (g a)² ∂ν` for `g : Lp ℝ 2 ν`. +* `lintegral_sqWeight` — the change-of-density identity for lower integrals. +* `eLpNorm_mul_eq` — the norm identity, for a measurable function. +* `integral_sqWeight`, `setIntegral_sqWeight` — the Bochner transfer, and its set form. +* `sqWeight_ae_ne_zero` — `f²·ν` is carried by `{f ≠ 0}`. +* `sqWeight_sqWeight` — **the weight composes**, `(f²·ν) weighted by g² = (fg)²·ν`; read as a + bracket this is `d⟨ψ●M⟩ = ψ² d⟨M⟩`, and `coeFn_mulLI_mulLI` is its map-level form. +* `ae_of_sqWeight_of_ae_ne_zero` — a.e. statements transfer back when `f ≠ 0` a.e. +* `exists_mulLI_eq` — for `f ≠ 0` a.e. the multiplication isometry is **onto**: `ψ := u/f`. +* `memLp_mul` — `ψ ∈ L²(f²·ν)` implies `f·ψ ∈ L²(ν)`. +* `mulLM`, `mulLI` — the map as a linear map and as a `LinearIsometry`, with `coeFn_mulLM` + the characterising a.e. identity. + +## Tags + +weighted L2 space, change of density, Itô integral chain rule, bracket measure, +multiplication isometry, MSC 60H05, MSC 28A25 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory in +/-- **The real `L²` norm-square as an integral**: `‖g‖² = ∫ (g a)² ∂ν` for `g : Lp ℝ 2 ν`. The one +`L²`-norm bridge of the Brownian and jump towers (Itô isometry, Wiener integral, compensated Poisson +integral), stated once here. -/ +lemma lp_two_norm_sq {α : Type*} {mα : MeasurableSpace α} {ν : Measure α} (g : Lp ℝ 2 ν) : + ‖g‖ ^ 2 = ∫ a, (g a) ^ 2 ∂ν := by + have h : inner ℝ g g = ‖g‖ ^ 2 := real_inner_self_eq_norm_sq g + rw [L2.inner_def] at h + rw [← h] + refine integral_congr_ae ?_ + filter_upwards with a + change (g a) * (g a) = (g a) ^ 2 + ring + +namespace LpMulIsometry + +open MeasureTheory Filter +open scoped ENNReal NNReal + +variable {α : Type*} {m : MeasurableSpace α} {ν : Measure α} {f : α → ℝ} + +/-- The measure `f²·ν`. For `f` the diffusion coefficient of an Itô integral this is the +bracket measure `d⟨M⟩ = f² ds ⊗ dμ`. -/ +noncomputable def sqWeight (ν : Measure α) (f : α → ℝ) : Measure α := + ν.withDensity fun x ↦ ‖f x‖ₑ ^ 2 + +lemma measurable_sqDensity (hf : Measurable f) : Measurable fun x ↦ ‖f x‖ₑ ^ 2 := + hf.eNorm.pow_const 2 + +lemma sqDensity_ne_top (x : α) : ‖f x‖ₑ ^ 2 ≠ ⊤ := by + simp [eNorm_ne_top] + +/-- The density is nonzero exactly where `f` is, which is what turns an a.e. statement for +`sqWeight ν f` into one for `ν` restricted to `{f ≠ 0}`. -/ +lemma sqDensity_ne_zero {x : α} (hx : f x ≠ 0) : ‖f x‖ₑ ^ 2 ≠ 0 := + pow_ne_zero 2 (by simpa using hx) + +/-- **Change of density for lower integrals.** Integrating against `f²·ν` is integrating +against `ν` with the integrand scaled by `‖f‖ₑ²`. -/ +lemma lintegral_sqWeight (hf : Measurable f) (g : α → ℝ≥0∞) : + ∫⁻ x, g x ∂(sqWeight ν f) = ∫⁻ x, ‖f x‖ₑ ^ 2 * g x ∂ν := by + rw [sqWeight, lintegral_withDensity_eq_lintegral_mul_non_measurable _ + (measurable_sqDensity hf) (Eventually.of_forall fun x ↦ (sqDensity_ne_top x).lt_top)] + rfl + +/-- The weight only sees `f` up to a `ν`-null set. -/ +lemma sqWeight_congr_ae {g : α → ℝ} (h : f =ᵐ[ν] g) : sqWeight ν f = sqWeight ν g := by + rw [sqWeight, sqWeight] + exact withDensity_congr_ae (by filter_upwards [h] with x hx; rw [hx]) + +/-- **The weight composes**: weighting by `g` on top of a weighting by `f` is weighting by the +product. Densities multiply, and `‖fg‖ₑ² = ‖f‖ₑ²‖g‖ₑ²`. + +This is the associativity of the chain rule. Reading `sqWeight` as a bracket, it says +`d⟨ψ●M⟩ = ψ² d⟨M⟩`: an Itô integral against an Itô integral is again one, with the brackets +composing the way the integrands do. -/ +lemma sqWeight_sqWeight (hf : Measurable f) {g : α → ℝ} (hg : Measurable g) : + sqWeight (sqWeight ν f) g = sqWeight ν (fun x ↦ f x * g x) := by + have hdens : (fun x ↦ ‖f x * g x‖ₑ ^ 2) + = (fun x ↦ ‖f x‖ₑ ^ 2) * (fun x ↦ ‖g x‖ₑ ^ 2) := by + funext x + simp [eNorm_mul, mul_pow] + simp only [sqWeight, hdens] + exact (withDensity_mul ν (measurable_sqDensity hf) (measurable_sqDensity hg)).symm + +/-- **The norm identity.** `‖f·g‖_{L²(ν)} = ‖g‖_{L²(f²·ν)}`, for a measurable `g` — no +integrability is needed, both sides being lower integrals. -/ +lemma eLpNorm_mul_eq (hf : Measurable f) {g : α → ℝ} (hg : Measurable g) : + eLpNorm (fun x ↦ f x * g x) 2 ν = eLpNorm g 2 (sqWeight ν f) := by + have hfg : AEStronglyMeasurable (fun x ↦ f x * g x) ν := (hf.mul hg).aestronglyMeasurable + rw [eLpNorm_eq_lintegral_rpow_eNorm_toReal (by norm_num) (by norm_num) hfg, + eLpNorm_eq_lintegral_rpow_eNorm_toReal (by norm_num) (by norm_num) hg.aestronglyMeasurable, + lintegral_sqWeight hf] + congr 1 + refine lintegral_congr fun x ↦ ?_ + rw [eNorm_mul, ENNReal.mul_rpow_of_nonneg _ _ (by norm_num : (0:ℝ) ≤ (2:ℝ≥0∞).toReal)] + congr 1 + rw [show ((2 : ℝ≥0∞).toReal) = ((2 : ℕ) : ℝ) by norm_num, ENNReal.rpow_natCast] + +/-- `(‖r‖ₑ²).toReal = r²` — the real form of the density, used to turn a `withDensity` +transfer into an honest multiplication by `f²`. -/ +lemma enorm_sq_toReal (r : ℝ) : (‖r‖ₑ ^ 2).toReal = r ^ 2 := by + rw [ENNReal.toReal_pow, Real.eNorm_eq_ofReal_abs, ENNReal.toReal_ofReal (abs_nonneg r), + sq_abs] + +/-- **Bochner transfer.** Integrating `u` against `f²·ν` is integrating `f²·u` against `ν`. -/ +lemma integral_sqWeight (hf : Measurable f) (u : α → ℝ) : + ∫ x, u x ∂(sqWeight ν f) = ∫ x, f x ^ 2 * u x ∂ν := by + rw [sqWeight, integral_withDensity_eq_integral_toReal_smul (measurable_sqDensity hf) + (Eventually.of_forall fun x ↦ (sqDensity_ne_top x).lt_top)] + exact integral_congr_ae (Eventually.of_forall fun x ↦ by + simp only [smul_eq_mul, enorm_sq_toReal]) + +/-- The set-integral form of `integral_sqWeight`. -/ +lemma setIntegral_sqWeight (hf : Measurable f) {R : Set α} (hR : MeasurableSet R) (u : α → ℝ) : + ∫ x in R, u x ∂(sqWeight ν f) = ∫ x in R, f x ^ 2 * u x ∂ν := by + rw [sqWeight, restrict_withDensity hR, + integral_withDensity_eq_integral_toReal_smul (measurable_sqDensity hf) + (Eventually.of_forall fun x ↦ (sqDensity_ne_top x).lt_top)] + exact integral_congr_ae (Eventually.of_forall fun x ↦ by + simp only [smul_eq_mul, enorm_sq_toReal]) + +/-- `f²·ν` is carried by `{f ≠ 0}`: the weight kills the rest. This is what turns "`f²·g = 0` +`ν`-a.e." into "`g = 0` a.e. for the weighted measure". -/ +lemma sqWeight_ae_ne_zero (hf : Measurable f) : ∀ᵐ x ∂(sqWeight ν f), f x ≠ 0 := by + rw [sqWeight, ae_withDensity_iff (measurable_sqDensity hf)] + filter_upwards with x hx hfx + exact hx (by simp [hfx]) + +/-- `ψ ∈ L²(f²·ν)` implies `f·ψ ∈ L²(ν)`. The measurability is not transported across the +measures — an `Lp` element carries a genuinely `StronglyMeasurable` representative +(`Lp.stronglyMeasurable`), so it is measurable for every measure at once. -/ +lemma memLp_mul (hf : Measurable f) (ψ : Lp ℝ 2 (sqWeight ν f)) : + MemLp (fun x ↦ f x * ψ x) 2 ν := + (eLpNorm_mul_eq hf (Lp.stronglyMeasurable ψ).measurable).trans_lt (Lp.eLpNorm_lt_top ψ) + +/-- When `f ≠ 0` a.e., an a.e. statement for the weighted measure transfers back to `ν`. The +two measures are then equivalent: `f²·ν ≪ ν` always, and the density is a.e. nonzero. -/ +lemma ae_of_sqWeight_of_ae_ne_zero (hf : Measurable f) (hf0 : ∀ᵐ x ∂ν, f x ≠ 0) + {p : α → Prop} (h : ∀ᵐ x ∂(sqWeight ν f), p x) : ∀ᵐ x ∂ν, p x := by + rw [sqWeight, ae_withDensity_iff (measurable_sqDensity hf)] at h + filter_upwards [h, hf0] with x hx hx0 + exact hx (sqDensity_ne_zero hx0) + +/-- **Multiplication by `f` as a linear map** `L²(f²·ν) →ₗ[ℝ] L²(ν)`. -/ +noncomputable def mulLM (ν : Measure α) (hf : Measurable f) : + Lp ℝ 2 (sqWeight ν f) →ₗ[ℝ] Lp ℝ 2 ν where + toFun ψ := (memLp_mul hf ψ).toLp _ + map_add' ψ₁ ψ₂ := by + refine Lp.ext ?_ + filter_upwards [(ae_withDensity_iff (measurable_sqDensity hf)).1 (Lp.coeFn_add ψ₁ ψ₂), + (memLp_mul hf (ψ₁ + ψ₂)).coeFn_toLp, + Lp.coeFn_add ((memLp_mul hf ψ₁).toLp _) ((memLp_mul hf ψ₂).toLp _), + (memLp_mul hf ψ₁).coeFn_toLp, (memLp_mul hf ψ₂).coeFn_toLp] with x hadd h h' h₁ h₂ + rw [h, h', Pi.add_apply, h₁, h₂] + rcases eq_or_ne (f x) 0 with hx | hx + · simp [hx] + · rw [hadd (sqDensity_ne_zero hx), Pi.add_apply, mul_add] + map_smul' r ψ := by + refine Lp.ext ?_ + filter_upwards [(ae_withDensity_iff (measurable_sqDensity hf)).1 (Lp.coeFn_smul r ψ), + (memLp_mul hf (r • ψ)).coeFn_toLp, + Lp.coeFn_smul r ((memLp_mul hf ψ).toLp _), (memLp_mul hf ψ).coeFn_toLp] with x hs h h' h₁ + rw [RingHom.id_apply, h, h', Pi.smul_apply, h₁] + rcases eq_or_ne (f x) 0 with hx | hx + · simp [hx] + · rw [hs (sqDensity_ne_zero hx), Pi.smul_apply, smul_eq_mul, smul_eq_mul] + ring + +/-- **The characterising a.e. identity** — without it the map is opaque. -/ +lemma coeFn_mulLM (ν : Measure α) (hf : Measurable f) (ψ : Lp ℝ 2 (sqWeight ν f)) : + ⇑(mulLM ν hf ψ) =ᵐ[ν] fun x ↦ f x * ψ x := + (memLp_mul hf ψ).coeFn_toLp + +/-- **Multiplication by `f`, bundled as an isometry** `L²(f²·ν) →ₗᵢ[ℝ] L²(ν)`. -/ +noncomputable def mulLI (ν : Measure α) (hf : Measurable f) : + Lp ℝ 2 (sqWeight ν f) →ₗᵢ[ℝ] Lp ℝ 2 ν where + toLinearMap := mulLM ν hf + norm_map' ψ := by + rw [Lp.norm_def, Lp.norm_def, eLpNorm_congr_ae (coeFn_mulLM ν hf ψ), + eLpNorm_mul_eq hf (Lp.stronglyMeasurable ψ).measurable] + +/-- `coeFn_mulLM` for the bundled isometry. -/ +lemma coeFn_mulLI (ν : Measure α) (hf : Measurable f) (ψ : Lp ℝ 2 (sqWeight ν f)) : + ⇑(mulLI ν hf ψ) =ᵐ[ν] fun x ↦ f x * ψ x := + coeFn_mulLM ν hf ψ + +/-- **Multiplying twice is multiplying by the product.** The composite +`L²(g²f²·ν) → L²(f²·ν) → L²(ν)` sends `χ` to `f·(g·χ)`. + +The inner identity holds only `(f²·ν)`-a.e., which is strictly weaker than `ν`-a.e., so it does +not transfer — but it does not need to: off `{f ≠ 0}` the outer multiplication kills both sides. +Same case split as the well-definedness argument, for the same reason. -/ +lemma coeFn_mulLI_mulLI (ν : Measure α) (hf : Measurable f) {g : α → ℝ} (hg : Measurable g) + (χ : Lp ℝ 2 (sqWeight (sqWeight ν f) g)) : + ⇑(mulLI ν hf (mulLI (sqWeight ν f) hg χ)) =ᵐ[ν] fun x ↦ f x * (g x * χ x) := by + -- term mode, not `rw`: the measure is `sqWeight ν f`, which is `ν.withDensity …` only up to + -- unfolding, and `rw` matches syntactically. Elaboration unifies up to defeq and succeeds. + have h2 : ∀ᵐ x ∂ν, ‖f x‖ₑ ^ 2 ≠ 0 → + (mulLI (sqWeight ν f) hg χ : α → ℝ) x = g x * (χ : α → ℝ) x := + (ae_withDensity_iff (measurable_sqDensity hf)).1 (coeFn_mulLI (sqWeight ν f) hg χ) + filter_upwards [coeFn_mulLI ν hf (mulLI (sqWeight ν f) hg χ), h2] with x hx1 hx2 + rw [hx1] + rcases eq_or_ne (f x) 0 with h0 | h0 + · simp [h0] + · rw [hx2 (sqDensity_ne_zero h0)] + +/-- **Multiplication by `f` is onto when `f ≠ 0` a.e.** The preimage of `u` is `u/f`, which +lands in the weighted space precisely because the weight cancels the division: +`∫|u/f|² f² dν = ∫|u|² dν`. This is what turns a hedge against `B` into a holding in a price +with volatility `f`. -/ +theorem exists_mulLI_eq (hf : Measurable f) (hf0 : ∀ᵐ x ∂ν, f x ≠ 0) (u : Lp ℝ 2 ν) : + ∃ ψ : Lp ℝ 2 (sqWeight ν f), mulLI ν hf ψ = u := by + have hcancel : (fun x ↦ f x * ((u : α → ℝ) x / f x)) =ᵐ[ν] ⇑u := by + filter_upwards [hf0] with x hx + field_simp + have hquot : MemLp (fun x ↦ (u : α → ℝ) x / f x) 2 (sqWeight ν f) := by + have hmeas : Measurable fun x ↦ (u : α → ℝ) x / f x := + (Lp.stronglyMeasurable u).measurable.div hf + rw [memLp_iff, ← eLpNorm_mul_eq hf hmeas, eLpNorm_congr_ae hcancel] + exact Lp.eLpNorm_lt_top u + refine ⟨hquot.toLp _, Lp.ext ?_⟩ + have hcoe : ∀ᵐ x ∂ν, (hquot.toLp _ : α → ℝ) x = (u : α → ℝ) x / f x := + ae_of_sqWeight_of_ae_ne_zero hf hf0 hquot.coeFn_toLp + filter_upwards [coeFn_mulLI ν hf (hquot.toLp _), hcoe, hf0] with x h1 h2 hx + rw [h1, h2] + field_simp + +end LpMulIsometry +end MathFin diff --git a/LeanPool/MathFin/Probability/Analysis/StdSimplexProd.lean b/LeanPool/MathFin/Probability/Analysis/StdSimplexProd.lean new file mode 100644 index 0000000000..a6b072d65c --- /dev/null +++ b/LeanPool/MathFin/Probability/Analysis/StdSimplexProd.lean @@ -0,0 +1,65 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Geometry.Convex.ConvexSpace.Defs +public import Mathlib.GroupTheory.GroupAction.Ring + +/-! +# The product of two standard simplices + +`Convexity.StdSimplex R X` is the finitely supported probability distributions on `X`. Mathlib has +the monad structure (`StdSimplex.map`, `StdSimplex.join`) and no product of independent +distributions. `StdSimplex.prod p q` is the monadic bind of `p` against `x ↦ q.map (x, ·)`, so its +weights are nonnegative and sum to one by the monad's own proofs, and its weight at `(x, y)` is the +product `p x * q y` (`StdSimplex.weights_prod`). + +## Main definitions + +* `StdSimplex.prod`: the product distribution of `p : StdSimplex R X` and `q : StdSimplex R Y`, + the monadic bind of `p` against `x ↦ q.map (x, ·)`. + +## Main results + +* `StdSimplex.weights_prod`: the weight of `p.prod q` at `(x, y)` is `p.weights x * q.weights y`. + +## Tags + +product of distributions, independent distributions, standard simplex, +finitely supported probability, monad bind, MSC 60E05 +-/ + +@[expose] public section + +namespace Convexity.StdSimplex + +variable {R : Type*} [Semiring R] [PartialOrder R] [IsStrictOrderedRing R] {X Y : Type*} + +/-- The **product distribution** of independent `p` on `X` and `q` on `Y`. -/ +noncomputable def prod (p : StdSimplex R X) (q : StdSimplex R Y) : StdSimplex R (X × Y) := + (p.map fun x ↦ q.map (x, ·)).join + +/-- The weight of the product distribution at `(x, y)` is `p x * q y`. -/ +@[simp] theorem weights_prod (p : StdSimplex R X) (q : StdSimplex R Y) (x : X) (y : Y) : + (p.prod q).weights (x, y) = p.weights x * q.weights y := by + classical + have key : ((p.weights.mapDomain fun x ↦ q.map (x, ·)).sum fun d r ↦ r • d.weights) = + p.weights.sum fun x r ↦ r • (q.map (x, ·)).weights := + Finsupp.sum_mapDomain_index (fun _ ↦ zero_smul _ _) fun _ _ _ ↦ add_smul _ _ _ + rw [prod, weights_join, weights_map, key, Finsupp.sum_apply, Finsupp.sum_eq_single x] + · simp [Finsupp.mapDomain_apply_of_injective (Prod.mk_right_injective x)] + · intro x' _ hx' + have hn : ((x, y) : X × Y) ∉ Set.range fun y' ↦ (x', y') := by + rintro ⟨y', hy'⟩ + exact hx' (congrArg Prod.fst hy') + simp [Finsupp.mapDomain_of_notMem_range _ _ hn] + · intro _ + simp + +end Convexity.StdSimplex diff --git a/LeanPool/MathFin/Probability/Brownian/BrownianCylinderGeneration.lean b/LeanPool/MathFin/Probability/Brownian/BrownianCylinderGeneration.lean new file mode 100644 index 0000000000..9e6216c020 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/BrownianCylinderGeneration.lean @@ -0,0 +1,180 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralL2 + +/-! # Countable generation of the Brownian σ-algebra + +The natural filtration `𝓕ᴮ_T = σ(B_s : s ≤ T)` (`ItoIntegralL2.natFiltration`) is an +*uncountable* supremum — one `comap (B s)` for every `s` in `[0,T]`. Nothing in that +definition says the σ-algebra is generated by countably many coordinates, and for a +process with arbitrary paths it is not. + +**Path continuity is what changes that, and it is the entire content of this file.** +A continuous path is determined by its values on a dense set, so `B_s` is the +pointwise limit of `B_q` along dyadic grid points `q → s`, and a pointwise limit of +measurable functions is measurable (`measurable_of_tendsto_metrizable`). The +uncountable supremum therefore collapses onto the countable chain of *finite* +cylinder σ-algebras `σ(B_q : q ∈ dyadicGrid T n)`: + +`⨆ₙ σ(B_q : q ∈ {k·T/2ⁿ : k ≤ 2ⁿ}) = 𝓕ᴮ_T`. + +The two inclusions are wildly asymmetric. `≤` is bookkeeping: every grid point lies +in `[0,T]`. `≥` is the theorem, and `hBcont` is used there and nowhere else — drop it +and the statement is false. + +The nearest grid point at or below `s` is `⌊(s/T)·2ⁿ⌋·T/2ⁿ`, and its convergence to +`s` is Mathlib's `tendsto_nat_floor_mul_div_atTop` read along `x = 2ⁿ`. The +degenerate horizon `T = 0` needs no separate branch: `s/T·T = s` survives it, because +`s ≤ T = 0` forces `s = 0` and Lean's `x/0 = 0`. + +## Downstream + +`cylinderFiltration` bundles the cylinder σ-algebras as an `ℕ`-filtration, which is +the shape Lévy's upward theorem wants (`MeasureTheory.Integrable.tendsto_ae_condExp` +and its `eLpNorm` companion): conditional expectations along a filtration converge to +the conditional expectation on the limit σ-algebra. That is how the +martingale-representation argument pushes a `𝓕ᴮ_T`-measurable `L²` variable onto the +countably many coordinates the Wiener-exponential totality argument can see. + +## Main definitions + +* `dyadicGrid`: the dyadic grid `{k·T/2ⁿ : k ≤ 2ⁿ}` on `[0, T]`, as a `Finset ℝ≥0`. +* `cylinderSigma`: the σ-algebra generated by the process at the `n`-th dyadic grid. +* `cylinderFiltration`: the cylinder σ-algebras bundled as a filtration indexed by `ℕ`. + +## Main results + +* `dyadicGrid`, `dyadicGrid_le`, `dyadicGrid_mono` — the grid `{k·T/2ⁿ : k ≤ 2ⁿ}`, the fact + that it sits in `[0,T]`, and the nesting that makes `cylinderFiltration` monotone. +* `iSup_cylinderSigma_eq_natFiltration` — **countable generation**: for a process with + continuous paths the uncountable supremum `σ(B_s : s ≤ T)` is `⨆ₙ cylinderSigma B T n`. +* `iSup_cylinderFiltration_eq_natFiltration` — the same, in the filtration vocabulary Lévy's + upward theorem consumes. + +## Tags + +Brownian filtration, countable generation, dyadic grid, cylinder sigma-algebra, Lévy upward theorem, +path continuity, MSC 60J65, MSC 60G07 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory Filter +open scoped NNReal Topology + +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {B : ℝ≥0 → Ω → ℝ} + +/-- The dyadic grid `{k·T/2^n : k ≤ 2^n}` on `[0,T]`. -/ +noncomputable def dyadicGrid (T : ℝ≥0) (n : ℕ) : Finset ℝ≥0 := + (Finset.range (2 ^ n + 1)).image fun k : ℕ ↦ (k : ℝ≥0) * T / (2 ^ n) + +/-- Every dyadic grid point lies in `[0,T]`: `k ≤ 2ⁿ` gives `k·T/2ⁿ ≤ T`. -/ +lemma dyadicGrid_le {T : ℝ≥0} {n : ℕ} {q : ℝ≥0} (hq : q ∈ dyadicGrid T n) : q ≤ T := by + obtain ⟨k, hk, rfl⟩ := Finset.mem_image.mp hq + have hk' : (k : ℝ≥0) ≤ 2 ^ n := by + exact_mod_cast Nat.lt_succ_iff.mp (Finset.mem_range.mp hk) + rw [div_le_iff₀ (by positivity : (0 : ℝ≥0) < 2 ^ n), mul_comm T] + exact mul_le_mul_of_nonneg_right hk' zero_le + +/-- The grids nest: refining `n` to `n+1` sends `k·T/2ⁿ` to `2k·T/2ⁿ⁺¹`. `Monotone` +into `Finset` is `⊆`, which is what makes `cylinderFiltration` a filtration. -/ +lemma dyadicGrid_mono (T : ℝ≥0) : Monotone (dyadicGrid T) := by + refine monotone_nat_of_le_succ fun n q hq ↦ ?_ + obtain ⟨k, hk, rfl⟩ := Finset.mem_image.mp hq + rw [Finset.mem_range] at hk + refine Finset.mem_image.mpr ⟨2 * k, Finset.mem_range.mpr ?_, ?_⟩ + · have h2 : 2 ^ (n + 1) = 2 * 2 ^ n := by ring + omega + · push_cast + rw [show ((2 : ℝ≥0) ^ (n + 1)) = 2 * 2 ^ n by ring, mul_assoc, + mul_div_mul_left _ _ two_ne_zero] + +/-- The σ-algebra generated by the process at the `n`-th dyadic grid. -/ +@[reducible] noncomputable def cylinderSigma (B : ℝ≥0 → Ω → ℝ) (T : ℝ≥0) (n : ℕ) : + MeasurableSpace Ω := + ⨆ q ∈ dyadicGrid T n, MeasurableSpace.comap (B q) inferInstance + +/-- The cylinder σ-algebras bundled as an `ℕ`-filtration: the shape +`Integrable.tendsto_ae_condExp` / `Integrable.tendsto_eLpNorm_condExp` demand. -/ +noncomputable def cylinderFiltration (B : ℝ≥0 → Ω → ℝ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) : Filtration ℕ mΩ where + seq n := cylinderSigma B T n + mono' _ _ h := biSup_mono fun _ hq ↦ dyadicGrid_mono T h hq + le' _ := iSup₂_le fun q _ ↦ (hBmeas q).comap_le + +/-- **The Brownian σ-algebra is countably generated by dyadic cylinders.** For a +process with continuous paths the uncountable supremum `σ(B_s : s ≤ T)` collapses onto +the countable chain `⨆ₙ σ(B_q : q ∈ dyadicGrid T n)`. `≤` only needs the grid to sit in +`[0,T]`; `≥` is where continuity is used, and it is used nowhere else. -/ +theorem iSup_cylinderSigma_eq_natFiltration (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun s : ℝ≥0 ↦ B s ω) (T : ℝ≥0) : + (⨆ n : ℕ, cylinderSigma B T n) + = (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas) T := by + have hnat : (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas) T + = ⨆ r : ℝ≥0, ⨆ _ : r ≤ T, MeasurableSpace.comap (B r) inferInstance := rfl + rw [hnat] + refine le_antisymm + (iSup_le fun n ↦ iSup₂_le fun r hr ↦ + le_iSup₂ (f := fun u (_ : u ≤ T) ↦ MeasurableSpace.comap (B u) inferInstance) r + (dyadicGrid_le hr)) + (iSup₂_le fun s hs ↦ ?_) + -- The dyadic approximants of `s`: the nearest grid point at or below it. + obtain ⟨q, hqmem, hq⟩ : ∃ q : ℕ → ℝ≥0, + (∀ n, q n ∈ dyadicGrid T n) ∧ Tendsto q atTop (𝓝 s) := by + have ha0 : (0 : ℝ) ≤ (s : ℝ) / (T : ℝ) := div_nonneg s.coe_nonneg T.coe_nonneg + have ha1 : (s : ℝ) / (T : ℝ) ≤ 1 := by + rcases eq_or_lt_of_le T.coe_nonneg with hT | hT + · simp [← hT] + · exact (div_le_one hT).mpr (NNReal.coe_le_coe.mpr hs) + refine ⟨fun n ↦ (⌊(s : ℝ) / (T : ℝ) * 2 ^ n⌋₊ : ℝ≥0) * T / 2 ^ n, fun n ↦ ?_, ?_⟩ + · refine Finset.mem_image.mpr ⟨⌊(s : ℝ) / (T : ℝ) * 2 ^ n⌋₊, + Finset.mem_range.mpr (Nat.lt_succ_of_le (Nat.floor_le_of_le ?_)), rfl⟩ + push_cast + exact mul_le_of_le_one_left (by positivity) ha1 + · have haT : (s : ℝ) / (T : ℝ) * (T : ℝ) = (s : ℝ) := by + rcases eq_or_ne (T : ℝ) 0 with hT | hT + · have hs0 : (s : ℝ) = 0 := by + have h := NNReal.coe_le_coe.mpr hs + rw [hT] at h + exact le_antisymm h s.coe_nonneg + rw [hT, hs0] + simp + · exact div_mul_cancel₀ _ hT + have h1 := ((tendsto_nat_floor_mul_div_atTop ha0).comp + (tendsto_pow_atTop_atTop_of_one_lt (by norm_num : (1 : ℝ) < 2))).mul_const (T : ℝ) + rw [haT] at h1 + rw [← NNReal.tendsto_coe] + refine Tendsto.congr (fun n ↦ ?_) h1 + simp only [Function.comp_apply] + push_cast + ring + -- `B s` is a pointwise limit of `⨆ₙ cylinderSigma`-measurable functions. + have hgrid (n : ℕ) : Measurable[⨆ m : ℕ, cylinderSigma B T m] (B (q n)) := + Measurable.of_comap_le <| + (le_iSup₂ (f := fun r (_ : r ∈ dyadicGrid T n) ↦ + MeasurableSpace.comap (B r) inferInstance) (q n) (hqmem n)).trans + (le_iSup (fun m : ℕ ↦ cylinderSigma B T m) n) + have key : Measurable[⨆ n : ℕ, cylinderSigma B T n] (B s) := + @measurable_of_tendsto_metrizable Ω ℝ (⨆ n : ℕ, cylinderSigma B T n) _ _ _ _ + (fun n ↦ B (q n)) (B s) hgrid + (tendsto_pi_nhds.mpr fun ω ↦ ((hBcont ω).tendsto s).comp hq) + exact key.comap_le + +/-- The filtration-bundled restatement, the form Lévy's upward theorem consumes: +`cylinderFiltration` is a filtration whose limit σ-algebra is `𝓕ᴮ_T`. -/ +theorem iSup_cylinderFiltration_eq_natFiltration (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun s : ℝ≥0 ↦ B s ω) (T : ℝ≥0) : + (⨆ n : ℕ, (cylinderFiltration B T hBmeas) n) + = (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas) T := + iSup_cylinderSigma_eq_natFiltration hBmeas hBcont T + +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/BrownianExpMoment.lean b/LeanPool/MathFin/Probability/Brownian/BrownianExpMoment.lean new file mode 100644 index 0000000000..927b879d7c --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/BrownianExpMoment.lean @@ -0,0 +1,158 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.BrownianMartingale + +/-! # Exponential moments of Brownian marginals + +A pre-Brownian motion's marginal `B_s` is `N(0, s)`, so it has *every* exponential +moment. Concretely, transferring the standard Gaussian moment-generating function +(`integrable_exp_mul_gaussianReal`, `mgf_id_gaussianReal`) along the law +`hB.hasLaw_eval s : HasLaw (B s) (gaussianReal 0 s) μ`, + + `∫ exp(c · B_s) ∂μ = exp(c² s / 2)`, + +and the absolute-value variant `exp(c · |B_s|) ∈ L²(μ)` with the uniform bound +`∫ exp(c · |B_s|) ∂μ ≤ 2 · exp(c² s / 2)` (via `exp(c|x|) ≤ exp(cx) + exp(−cx)`). + +These are the integrability base stones the exponential-growth Itô formula +(`ItoFormulaLocalized`) needs to dominate its cutoff approximants: the marginal +exponential moment, together with Tonelli, controls the `L²` norm of path +integrals of exponential-growth integrands. `GaussianMoments` holds the +*polynomial* moments; this file holds the exponential ones. + +## Main results + +* `integral_exp_mul_eval`: `∫ exp(c · B_s) ∂μ = exp(c² s / 2)` for a pre-Brownian motion `B`. +* `integrable_exp_mul_eval`, `memLp_exp_mul_eval`: `exp(c · B_s)` is integrable and in `L²(μ)`. +* `memLp_exp_incr`: `exp(c · (B_v − B_u))` is in `L²(μ)`. +* `memLp_exp_abs_eval`, `integrable_exp_abs_eval`: `exp(c · |B_s|)` is in `L²(μ)` and integrable. +* `integral_exp_abs_eval_le`: `∫ exp(c · |B_s|) ∂μ ≤ 2 · exp(c² s / 2)`. + +## Tags + +exponential moment, moment generating function, Gaussian marginal, lognormal, Brownian motion, +MSC 60J65, MSC 60E10 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal + +/-- Pointwise: `exp(c|x|) ≤ exp(cx) + exp(−cx)` (the absolute value picks the larger +exponent; the other summand is nonnegative). -/ +lemma exp_mul_abs_le_add (c x : ℝ) : + Real.exp (c * |x|) ≤ Real.exp (c * x) + Real.exp (-c * x) := by + rcases le_total 0 x with hx | hx + · rw [abs_of_nonneg hx]; exact le_add_of_nonneg_right (Real.exp_nonneg _) + · rw [abs_of_nonpos hx, mul_neg, ← neg_mul]; exact le_add_of_nonneg_left (Real.exp_nonneg _) + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) + +include hB + +/-- `exp(c · B_s)` is integrable: Mathlib's `integrable_exp_mul_gaussianReal` transferred along +`HasLaw.integrable_fun_comp` at the marginal law `B_s ~ N(0, s)`. -/ +lemma integrable_exp_mul_eval (s : ℝ≥0) (c : ℝ) : + Integrable (fun ω ↦ Real.exp (c * B s ω)) μ := + (hB.hasLaw_eval s).integrable_fun_comp (integrable_exp_mul_gaussianReal c) + +/-- The Brownian marginal MGF: `∫ exp(c · B_s) ∂μ = exp(c² s / 2)`, the gaussianReal MGF +`integral_exp_mul_gaussianReal_zero` transferred along `B_s ~ N(0, s)`. -/ +lemma integral_exp_mul_eval (s : ℝ≥0) (c : ℝ) : + ∫ ω, Real.exp (c * B s ω) ∂μ = Real.exp (c ^ 2 * (s : ℝ) / 2) := by + have hg : AEStronglyMeasurable (fun x : ℝ ↦ Real.exp (c * x)) (Measure.map (B s) μ) := + (Real.continuous_exp.comp (continuous_const.mul continuous_id)).aestronglyMeasurable + rw [(integral_map (hB.hasLaw_eval s).aemeasurable hg).symm, (hB.hasLaw_eval s).map_eq, + integral_exp_mul_gaussianReal_zero] + +/-- `exp(c · B_s) ∈ L²(μ)`: its square is `exp(2c · B_s)`, integrable by the marginal MGF. -/ +lemma memLp_exp_mul_eval (s : ℝ≥0) (c : ℝ) : + MemLp (fun ω ↦ Real.exp (c * B s ω)) 2 μ := by + have hmeas : AEStronglyMeasurable (fun ω ↦ Real.exp (c * B s ω)) μ := + ((Real.continuous_exp.comp (continuous_const.mul continuous_id)).measurable.comp_aemeasurable + (hB.hasLaw_eval s).aemeasurable).aestronglyMeasurable + rw [memLp_two_iff_integrable_sq hmeas] + have hsq : (fun ω ↦ Real.exp (c * B s ω) ^ 2) = (fun ω ↦ Real.exp (2 * c * B s ω)) := by + funext ω; rw [← Real.exp_nat_mul]; congr 1; push_cast; ring + rw [hsq] + exact integrable_exp_mul_eval hB s (2 * c) + +/-- `exp(c · |B_s|) ∈ L²(μ)`: dominated by `exp(c · B_s) + exp(−c · B_s) ∈ L²`. -/ +lemma memLp_exp_abs_eval (s : ℝ≥0) (c : ℝ) : + MemLp (fun ω ↦ Real.exp (c * |B s ω|)) 2 μ := by + have hmeas : AEStronglyMeasurable (fun ω ↦ Real.exp (c * |B s ω|)) μ := + ((Real.continuous_exp.comp (continuous_const.mul continuous_abs)).measurable.comp_aemeasurable + (hB.hasLaw_eval s).aemeasurable).aestronglyMeasurable + refine ((memLp_exp_mul_eval hB s c).add (memLp_exp_mul_eval hB s (-c))).mono hmeas + (ae_of_all _ fun ω ↦ ?_) + simp only [Pi.add_apply] + rw [Real.norm_eq_abs, Real.norm_eq_abs, abs_of_nonneg (Real.exp_nonneg _), + abs_of_nonneg (by positivity : (0 : ℝ) ≤ Real.exp (c * B s ω) + Real.exp (-c * B s ω))] + exact exp_mul_abs_le_add c (B s ω) + +/-- `exp(c · (B_v − B_u)) ∈ L²(μ)`: an increment has a second exponential moment too. +The increment is not a marginal, so the law transfer does not apply to it directly; +instead `xy ≤ ½(x² + y²)` splits it into the two marginals `exp(2c·B_v)` and +`exp(−2c·B_u)`, each already in `L²`. -/ +lemma memLp_exp_incr (u v : ℝ≥0) (c : ℝ) : + MemLp (fun ω ↦ Real.exp (c * (B v ω - B u ω))) 2 μ := by + have hmeas : AEStronglyMeasurable (fun ω ↦ Real.exp (c * (B v ω - B u ω))) μ := + (Real.measurable_exp.comp_aemeasurable + (((hB.hasLaw_eval v).aemeasurable.sub (hB.hasLaw_eval u).aemeasurable).const_mul + c)).aestronglyMeasurable + have key (ω : Ω) : Real.exp (c * (B v ω - B u ω)) + ≤ 1 / 2 * (Real.exp (2 * c * B v ω) + Real.exp (-(2 * c) * B u ω)) := by + have h1 : Real.exp (c * (B v ω - B u ω)) + = Real.exp (c * B v ω) * Real.exp (-(c * B u ω)) := by + rw [← Real.exp_add]; congr 1; ring + have h2 : Real.exp (2 * c * B v ω) = Real.exp (c * B v ω) ^ 2 := by + rw [sq, ← Real.exp_add]; congr 1; ring + have h3 : Real.exp (-(2 * c) * B u ω) = Real.exp (-(c * B u ω)) ^ 2 := by + rw [sq, ← Real.exp_add]; congr 1; ring + rw [h1, h2, h3] + nlinarith [sq_nonneg (Real.exp (c * B v ω) - Real.exp (-(c * B u ω)))] + refine MemLp.mono (((memLp_exp_mul_eval hB v (2 * c)).add + (memLp_exp_mul_eval hB u (-(2 * c)))).const_mul (1 / 2)) hmeas (ae_of_all _ fun ω ↦ ?_) + simp only [Pi.add_apply] + rw [Real.norm_eq_abs, Real.norm_eq_abs, abs_of_pos (Real.exp_pos _), + abs_of_nonneg (by positivity : + (0 : ℝ) ≤ 1 / 2 * (Real.exp (2 * c * B v ω) + Real.exp (-(2 * c) * B u ω)))] + exact key ω + +/-- `exp(c · |B_s|)` is integrable: dominated by `exp(c·B_s) + exp(−c·B_s) ∈ L¹`. -/ +lemma integrable_exp_abs_eval (s : ℝ≥0) (c : ℝ) : + Integrable (fun ω ↦ Real.exp (c * |B s ω|)) μ := + ((integrable_exp_mul_eval hB s c).add (integrable_exp_mul_eval hB s (-c))).mono' + ((Real.continuous_exp.comp (continuous_const.mul continuous_abs)).measurable.comp_aemeasurable + (hB.hasLaw_eval s).aemeasurable).aestronglyMeasurable + (ae_of_all _ fun ω ↦ by + rw [Real.norm_eq_abs, abs_of_nonneg (Real.exp_nonneg _)]; exact exp_mul_abs_le_add c (B s ω)) + +/-- Uniform exponential-moment bound: `∫ exp(c · |B_s|) ∂μ ≤ 2 · exp(c² s / 2)`. -/ +lemma integral_exp_abs_eval_le (s : ℝ≥0) (c : ℝ) : + ∫ ω, Real.exp (c * |B s ω|) ∂μ ≤ 2 * Real.exp (c ^ 2 * (s : ℝ) / 2) := by + have hbnd : ∀ ω, Real.exp (c * |B s ω|) + ≤ Real.exp (c * B s ω) + Real.exp (-c * B s ω) := fun ω ↦ exp_mul_abs_le_add c (B s ω) + have hlhs_int : Integrable (fun ω ↦ Real.exp (c * |B s ω|)) μ := integrable_exp_abs_eval hB s c + have hsum_int : Integrable (fun ω ↦ Real.exp (c * B s ω) + Real.exp (-c * B s ω)) μ := + (integrable_exp_mul_eval hB s c).add (integrable_exp_mul_eval hB s (-c)) + calc ∫ ω, Real.exp (c * |B s ω|) ∂μ + ≤ ∫ ω, (Real.exp (c * B s ω) + Real.exp (-c * B s ω)) ∂μ := + integral_mono hlhs_int hsum_int hbnd + _ = Real.exp (c ^ 2 * (s : ℝ) / 2) + Real.exp ((-c) ^ 2 * (s : ℝ) / 2) := by + rw [integral_add (integrable_exp_mul_eval hB s c) (integrable_exp_mul_eval hB s (-c)), + integral_exp_mul_eval hB s c, integral_exp_mul_eval hB s (-c)] + _ = 2 * Real.exp (c ^ 2 * (s : ℝ) / 2) := by rw [neg_sq]; ring + +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/BrownianMarkov.lean b/LeanPool/MathFin/Probability/Brownian/BrownianMarkov.lean new file mode 100644 index 0000000000..671ce9dc46 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/BrownianMarkov.lean @@ -0,0 +1,134 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.KLS.BrownianMotion.Gaussian.BrownianMotion +public import LeanPool.MathFin.Probability.Analysis.IndepFreezing + +/-! +# Brownian Markov property at the σ-algebra level + +Degenne's `BrownianMotion` package proves the weak Markov property in the +function-valued form: `IsPreBrownianReal.indepFun_shift` states that the shifted +increment map `ω ↦ (X (t₀ + t) ω − X t₀ ω)_t` is independent (as a random +variable valued in `ℝ≥0 → ℝ`) of the past evaluation map +`ω ↦ (X t ω)_{t ≤ t₀}`, and `IsPreBrownianReal.shift` states the shifted process +is again a pre-Brownian motion. + +The textbook statement (Saporito, Theorem 5.1.4) is the σ-algebra form: the +post-`t₀` increment process is independent of the **natural filtration** +`𝓕ᵉ_{t₀} = σ(X_u : u ≤ t₀)`. This file closes that gap: by +`Filtration.natural_eq_comap`, the natural σ-algebra at `t₀` *is* the comap of +the past evaluation map, so the function-valued independence upgrades to + + `Indep σ(shifted increments) (Filtration.natural X _ t₀) P`, + +which together with `IsPreBrownianReal.shift` is the full textbook package: after +`t₀`, Brownian motion **restarts afresh, independently of its entire past**. + +The same two facts give the Markov property as a conditional expectation. The shifted process is +pre-Brownian, so its law on the path space `ℝ≥0 → ℝ` (product σ-algebra) is Degenne's +projective-limit measure `gaussianLimit` (`IsPreBrownianReal.hasLaw_gaussianLimit`), and the +freezing lemma `condExp_comp_prodMk_of_indep` (`Probability/Analysis/IndepFreezing`, Shreve's +independence lemma) turns the σ-algebra independence into + + `𝔼[g(Y, (X_{t₀+t} − X_{t₀})_t) | 𝓕ᵉ_{t₀}] = ∫ g(Y, x) dW(x)` + +for every `𝓕ᵉ_{t₀}`-measurable `Y`. This is the simple Markov property at a fixed time +`t₀` for the natural (unaugmented) filtration, not the strong Markov property. + +## Main results + +* `shift_indep_natural` — σ(increments after `t₀`) is independent of the + natural filtration at `t₀`. +* `brownian_markov_property` — the textbook package: the shifted increment + process is a pre-Brownian motion *and* independent of `𝓕ᵉ_{t₀}`. +* `condExp_shift_eq_integral_gaussianLimit` — the Markov property in conditional-expectation + form: given `𝓕ᵉ_{t₀}`, a functional of the past and the future increment path is + integrated against `gaussianLimit` in its future argument. + +## References + +* [I. Karatzas and S. E. Shreve, *Brownian Motion and Stochastic Calculus*][KaratzasShreve1991], + §2.5 +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Theorem 5.1.4 +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], Lemma + 2.3.4 + +## Tags + +Markov property, independent increments, natural filtration, restart afresh, Brownian motion, +MSC 60J65, MSC 60J60 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + {X : ℝ≥0 → Ω → ℝ} + +/-- **σ-algebra form of the weak Markov property.** The σ-algebra generated by +the shifted increment map `ω ↦ (X (t₀ + t) ω − X t₀ ω)_t` is independent of +the natural filtration `σ(X_u : u ≤ t₀)`. Upgrade of Degenne's +`IsPreBrownianReal.indepFun_shift` via `Filtration.natural_eq_comap`. -/ +theorem shift_indep_natural (h : IsPreBrownianReal X P) + (hX : ∀ t, Measurable (X t)) (t₀ : ℝ≥0) : + Indep + (MeasurableSpace.comap (fun ω (t : ℝ≥0) ↦ X (t₀ + t) ω - X t₀ ω) inferInstance) + (Filtration.natural X (fun t ↦ (hX t).stronglyMeasurable) t₀) P := by + rw [Filtration.natural_eq_comap] + exact (IndepFun_iff_Indep _ _ _).1 (h.indepFun_shift t₀) + +/-- **Theorem 5.1.4 (Brownian Markov property).** For a pre-Brownian motion +`X` and any `t₀ ≥ 0`, the post-`t₀` increment process +`t ↦ X (t₀ + t) − X t₀` is itself a pre-Brownian motion, and it is +independent of the natural filtration `𝓕ᵉ_{t₀} = σ(X_u : u ≤ t₀)` — the +σ-algebra of the *entire* past, not merely finitely many past evaluations. -/ +theorem brownian_markov_property (h : IsPreBrownianReal X P) + (hX : ∀ t, Measurable (X t)) (t₀ : ℝ≥0) : + IsPreBrownianReal (fun t ω ↦ X (t₀ + t) ω - X t₀ ω) P ∧ + Indep + (MeasurableSpace.comap (fun ω (t : ℝ≥0) ↦ X (t₀ + t) ω - X t₀ ω) inferInstance) + (Filtration.natural X (fun t ↦ (hX t).stronglyMeasurable) t₀) P := + ⟨h.shift t₀, shift_indep_natural h hX t₀⟩ + +/-- **The Markov property as a conditional expectation.** For a pre-Brownian motion `X` with +measurable sections, a time `t₀`, a `𝓕ᵉ_{t₀}`-measurable `Y` and a strongly measurable `g` with +`g(Y, ·)` integrable along the future increment path, + + `𝔼[g(Y, (X_{t₀+t} − X_{t₀})_t) | 𝓕ᵉ_{t₀}] = ∫ g(Y, x) dW(x)` almost surely, + +with `W = gaussianLimit` the pre-Brownian law on the product path space `ℝ≥0 → ℝ`: given the +past, the past is frozen and +the future increment path keeps the law of a Brownian motion started at `0`. The freezing +lemma `condExp_comp_prodMk_of_indep` applied to `shift_indep_natural`; the law of the +shifted process is `gaussianLimit` because it is pre-Brownian (`IsPreBrownianReal.shift`, +`IsPreBrownianReal.hasLaw_gaussianLimit`). -/ +theorem condExp_shift_eq_integral_gaussianLimit (h : IsPreBrownianReal X P) + (hX : ∀ t, Measurable (X t)) (t₀ : ℝ≥0) {α : Type*} {mα : MeasurableSpace α} {Y : Ω → α} + (hY : Measurable[Filtration.natural X (fun t ↦ (hX t).stronglyMeasurable) t₀] Y) + {g : α × (ℝ≥0 → ℝ) → ℝ} (hg : StronglyMeasurable g) + (hgi : Integrable (fun ω ↦ g (Y ω, fun t ↦ X (t₀ + t) ω - X t₀ ω)) P) : + P[fun ω ↦ g (Y ω, fun t ↦ X (t₀ + t) ω - X t₀ ω) | + Filtration.natural X (fun t ↦ (hX t).stronglyMeasurable) t₀] + =ᵐ[P] fun ω ↦ ∫ x, g (Y ω, x) ∂gaussianLimit := by + have : IsProbabilityMeasure P := h.isGaussianProcess.isProbabilityMeasure + have hshift : Measurable fun ω (t : ℝ≥0) ↦ X (t₀ + t) ω - X t₀ ω := + .of_eval fun t ↦ (hX _).sub (hX _) + have hlaw : P.map (fun ω (t : ℝ≥0) ↦ X (t₀ + t) ω - X t₀ ω) = gaussianLimit := + ((h.shift t₀).hasLaw_gaussianLimit hshift.aemeasurable).map_eq + rw [← hlaw] + exact condExp_comp_prodMk_of_indep + ((Filtration.natural X fun t ↦ (hX t).stronglyMeasurable).le t₀) hY hshift.aemeasurable + (shift_indep_natural h hX t₀) hg hgi + +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/BrownianMartingale.lean b/LeanPool/MathFin/Probability/Brownian/BrownianMartingale.lean new file mode 100644 index 0000000000..d4cd2fdab3 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/BrownianMartingale.lean @@ -0,0 +1,417 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho, Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.KLS.BrownianMotion.Gaussian.BrownianMotion +public import LeanPool.MathFin.Probability.Gaussian.GaussianMoments +public import LeanPool.MathFin.Probability.Jumps.ExpMartingaleIndepIncrements + +/-! +# Martingale properties of Brownian motion + +For a filtered pre-Brownian motion `X`, the following are martingales w.r.t. the filtration `𝓕`: + +* `X` itself (already provided as `IsPreBrownianReal.isMartingale` in + `Gaussian/BrownianMotion.lean`) +* `t ↦ (X t)² − t` +* `t ↦ exp(α X_t − α² t / 2)` (Wald exponential), for any `α : ℝ`: the exponential martingale of + the process `αX`, whose increments are independent of the past with Gaussian exponential + moments (`MathFin.martingale_exp_sub_of_indep_increments`, + `Probability/Jumps/ExpMartingaleIndepIncrements`) + +## Main results + +* `IsFilteredPreBrownian.squareSubTime_isMartingale` +* `IsFilteredPreBrownian.waldExponential_isMartingale` + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Proposition 4.3.6 + (fixed-level hitting), Remark 5.1.6 and Theorem 5.1.5. + +## Tags + +Wald exponential, exponential martingale, Brownian motion, Doléans exponential, martingale, +MSC 60J65, MSC 60G44 +-/ + +@[expose] public section + +open MeasureTheory Filter +open scoped NNReal ENNReal + +namespace ProbabilityTheory + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + {𝓕 : Filtration ℝ≥0 mΩ} {X : ℝ≥0 → Ω → ℝ} + +/-- MGF specialization: for `α : ℝ` and `v : ℝ≥0`, +`∫ x, exp(α x) ∂(gaussianReal 0 v) = exp(α² v / 2)`. The Gaussian-MGF-along-a-law base +stone, also consumed by `BrownianExpMoment` (the natural long-term home is `GaussianMoments`, +which both files import; kept here to avoid a corpus-wide restale). -/ +lemma integral_exp_mul_gaussianReal_zero (α : ℝ) (v : ℝ≥0) : + ∫ x, Real.exp (α * x) ∂(gaussianReal 0 v) = Real.exp (α ^ 2 * (v : ℝ) / 2) := by + have h := congr_fun (mgf_id_gaussianReal (μ := 0) (v := v)) α + change mgf id (gaussianReal 0 v) α = _ + rw [h] + ring_nf + +/-- **Standard-normal MGF** via `HasLaw` transfer: `𝔼[exp(a·Z)] = exp(a²/2)` for +`Z ~ N(0,1)` — Mathlib's `mgf_gaussianReal` with `mgf` unfolded, kept as a rewrite handle. -/ +lemma integral_exp_mul_stdNormal {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + {Z : Ω → ℝ} (hZ : HasLaw Z (gaussianReal 0 1) P) (a : ℝ) : + ∫ ω, Real.exp (a * Z ω) ∂P = Real.exp (a ^ 2 / 2) := by + simpa [mgf] using mgf_gaussianReal hZ a + +/-- The MGF of an affine form in two independent standard normals: +`𝔼[exp(c + a Z₁ + b Z₂)] = exp(c + a²/2 + b²/2)`. -/ +lemma integral_exp_affine_indep {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + {Z₁ Z₂ : Ω → ℝ} + (h₁ : HasLaw Z₁ (gaussianReal 0 1) P) (h₂ : HasLaw Z₂ (gaussianReal 0 1) P) + (hm₁ : Measurable Z₁) (hm₂ : Measurable Z₂) (hindep : IndepFun Z₁ Z₂ P) (c a b : ℝ) : + ∫ ω, Real.exp (c + a * Z₁ ω + b * Z₂ ω) ∂P = Real.exp (c + a ^ 2 / 2 + b ^ 2 / 2) := by + have hpt : (fun ω ↦ Real.exp (c + a * Z₁ ω + b * Z₂ ω)) + = fun ω ↦ Real.exp c * (Real.exp (a * Z₁ ω) * Real.exp (b * Z₂ ω)) := by + funext ω; rw [← Real.exp_add, ← Real.exp_add, add_assoc] + have hind : IndepFun (fun ω ↦ Real.exp (a * Z₁ ω)) (fun ω ↦ Real.exp (b * Z₂ ω)) P := + hindep.exp_mul a b + have hprod : ∫ ω, Real.exp (a * Z₁ ω) * Real.exp (b * Z₂ ω) ∂P + = Real.exp (a ^ 2 / 2) * Real.exp (b ^ 2 / 2) := by + rw [← integral_exp_mul_stdNormal h₁ a, ← integral_exp_mul_stdNormal h₂ b] + exact hind.integral_mul_eq_mul_integral (by fun_prop) (by fun_prop) + rw [hpt, integral_const_mul, hprod, ← Real.exp_add, ← Real.exp_add, add_assoc] + +namespace IsFilteredPreBrownian + +variable [hX : IsFilteredPreBrownian X 𝓕 P] [IsFiniteMeasure P] + +omit [IsFiniteMeasure P] in +/-- A measurable function of the increment `X_t − X_s` is independent of `𝓕_s`. The shared step +behind the Wald martingale (`α(X_t − X_s)`) and Brownian motion with drift as a jump-diffusion +(`IsFilteredPreBrownian.jumpDiffusionProcess`, increment `b(t − s) + σ(X_t − X_s)`). -/ +lemma indep_comap_of_eq_comp_increment {s t : ℝ≥0} (hst : s ≤ t) {Z : Ω → ℝ} {f : ℝ → ℝ} + (hf : Measurable f) (hZ : ∀ ω, Z ω = f (X t ω - X s ω)) : + Indep (MeasurableSpace.comap Z inferInstance) (𝓕 s) P := + indep_of_indep_of_le_left (hX.indep s t hst) + (MeasurableSpace.comap_le_comap_of_eq_comp f hf (funext hZ)) + +/-- For a Borel-measurable `φ : ℝ → ℝ` with `∫ φ (X_t ω − X_s ω) ∂P = c`, the +conditional expectation of `φ ∘ (X_t − X_s)` given `𝓕 s` is a.e. the constant +`c`. Captures the "increment is independent of the past, so functions of it +behave like deterministic constants under conditional expectation" pattern. -/ +lemma condExp_comp_increment_eq_const {s t : ℝ≥0} (hst : s ≤ t) + (h_meas_diff : Measurable (fun ω ↦ X t ω - X s ω)) + {φ : ℝ → ℝ} (hφ : Measurable φ) {c : ℝ} + (h_int_eq : ∫ ω, φ (X t ω - X s ω) ∂P = c) : + P[fun ω ↦ φ (X t ω - X s ω) | (𝓕 s : MeasurableSpace Ω)] =ᵐ[P] fun _ ↦ c := by + have h_indep : Indep (MeasurableSpace.comap (fun ω ↦ X t ω - X s ω) (borel ℝ)) (𝓕 s) P := + hX.indep s t hst + have hφ_comap : + Measurable[MeasurableSpace.comap (fun ω ↦ X t ω - X s ω) (borel ℝ)] + (fun ω ↦ φ (X t ω - X s ω)) := + hφ.comp (Measurable.of_comap_le le_rfl) + have := condExp_indep_eq h_meas_diff.comap_le (𝓕.le s) + hφ_comap.stronglyMeasurable h_indep + rwa [h_int_eq] at this + +/-- For a filtered pre-Brownian motion `X`, the process `t ↦ (X t)² − t` is a martingale +w.r.t. `𝓕`. + +Decomposition: `(X_t)² = (X_s)² + 2 X_s (X_t − X_s) + (X_t − X_s)²`. The first summand is +`𝓕_s`-measurable; the cross term has zero conditional expectation by pull-out + independence; +the squared increment has conditional expectation `t − s` (its variance). -/ +theorem squareSubTime_isMartingale : + Martingale (fun t ω ↦ (X t ω) ^ 2 - (t : ℝ)) 𝓕 P := by + refine ⟨fun u ↦ ?_, fun s t hst ↦ ?_⟩ + -- Adaptedness of `(X u)² − u`. + · have hB : StronglyMeasurable[𝓕 u] (X u) := hX.stronglyAdapted u + have hsq : StronglyMeasurable[𝓕 u] (fun ω ↦ (X u ω) ^ 2) := by + simp only [pow_two]; exact hB.mul hB + exact hsq.sub stronglyMeasurable_const + -- Conditional-expectation step. + have h_int_s : Integrable (X s) P := hX.integrable_eval s + have h_int_t : Integrable (X t) P := hX.integrable_eval t + have h_int_diff : Integrable (fun ω ↦ X t ω - X s ω) P := h_int_t.sub h_int_s + have h_meas_t : Measurable (X t) := ((hX.stronglyAdapted t).mono (𝓕.le t)).measurable + have h_meas_s : Measurable (X s) := ((hX.stronglyAdapted s).mono (𝓕.le s)).measurable + have h_meas_diff : Measurable (fun ω ↦ X t ω - X s ω) := h_meas_t.sub h_meas_s + have h_eq_diff : (fun ω ↦ X t ω - X s ω) = (X t - X s : Ω → ℝ) := rfl + -- HasLaws from `IsPreBrownianReal`. + have hL_diff : HasLaw (X t - X s) (gaussianReal 0 (t - s)) P := + MathFin.hasLaw_increment hX.toIsPreBrownianReal hst + have hL_s : HasLaw (X s) (gaussianReal 0 s) P := hX.hasLaw_eval s + -- L² membership transferred via HasLaw + `memLp_id_gaussianReal`. + have h_Bs_memLp : MemLp (X s) 2 P := hL_s.memLp (memLp_id_gaussianReal 2) + have h_diff_memLp : MemLp (fun ω ↦ X t ω - X s ω) 2 P := by + rw [h_eq_diff] + exact hL_diff.memLp (memLp_id_gaussianReal 2) + -- Integrabilities. + have h_int_Bs_sq : Integrable (fun ω ↦ (X s ω) ^ 2) P := h_Bs_memLp.integrable_sq + have h_int_diff_sq : Integrable (fun ω ↦ (X t ω - X s ω) ^ 2) P := h_diff_memLp.integrable_sq + have h_int_cross : Integrable (fun ω ↦ X s ω * (X t ω - X s ω)) P := + h_Bs_memLp.integrable_mul h_diff_memLp + -- Mean of increment is 0. + have h_int_diff_zero : ∫ ω, (X t ω - X s ω) ∂P = 0 := by + rw [h_eq_diff, hL_diff.integral_eq, integral_id_gaussianReal] + -- Variance of increment integral: ∫ (X_t − X_s)² ∂P = t − s. + have h_int_diff_sq_zero : ∫ ω, (X t ω - X s ω) ^ 2 ∂P = (t : ℝ) - (s : ℝ) := by + have h_change : ∫ ω, (X t ω - X s ω) ^ 2 ∂P + = ∫ x, x ^ 2 ∂(gaussianReal 0 (t - s)) := by + simpa [Function.comp] using hL_diff.integral_comp (f := fun x : ℝ ↦ x ^ 2) (by fun_prop) + rw [h_change, MathFin.integral_sq_gaussianReal] + exact NNReal.coe_sub hst + -- `𝓕_s`-measurability of `X_s` and `(X_s)²`. + have h_smeas_s : StronglyMeasurable[𝓕 s] (X s) := hX.stronglyAdapted s + have h_smeas_s_sq : StronglyMeasurable[𝓕 s] (fun ω ↦ (X s ω) ^ 2) := by + simp only [pow_two]; exact h_smeas_s.mul h_smeas_s + -- `E[(X_s)² | 𝓕_s] = (X_s)²`. + have h_condBs_sq : + P[fun ω ↦ (X s ω) ^ 2 | (𝓕 s : MeasurableSpace Ω)] = fun ω ↦ (X s ω) ^ 2 := + condExp_of_stronglyMeasurable (𝓕.le s) h_smeas_s_sq h_int_Bs_sq + -- `E[X_t − X_s | 𝓕_s] =ᵐ 0` and `E[(X_t − X_s)² | 𝓕_s] =ᵐ (t − s)` + -- (the increment is independent of `𝓕 s`). + have h_condDiff : + P[fun ω ↦ X t ω - X s ω | (𝓕 s : MeasurableSpace Ω)] =ᵐ[P] fun _ ↦ (0 : ℝ) := + condExp_comp_increment_eq_const hst h_meas_diff measurable_id h_int_diff_zero + have h_condDiffSq : + P[fun ω ↦ (X t ω - X s ω) ^ 2 | (𝓕 s : MeasurableSpace Ω)] + =ᵐ[P] fun _ ↦ ((t : ℝ) - (s : ℝ)) := + condExp_comp_increment_eq_const hst h_meas_diff (measurable_id.pow_const 2) + h_int_diff_sq_zero + -- Pull-out for the cross term. + have h_cross_eq : + (fun ω ↦ X s ω * (X t ω - X s ω)) = (X s) * (fun ω ↦ X t ω - X s ω) := rfl + have h_pullout : + P[fun ω ↦ X s ω * (X t ω - X s ω) | (𝓕 s : MeasurableSpace Ω)] + =ᵐ[P] (X s) * (P[fun ω ↦ X t ω - X s ω | (𝓕 s : MeasurableSpace Ω)]) := by + rw [h_cross_eq] + exact condExp_mul_of_stronglyMeasurable_left h_smeas_s + (by simpa [h_cross_eq] using h_int_cross) h_int_diff + have h_cond_cross : + P[fun ω ↦ X s ω * (X t ω - X s ω) | (𝓕 s : MeasurableSpace Ω)] + =ᵐ[P] fun _ ↦ (0 : ℝ) := by + refine h_pullout.trans ?_ + filter_upwards [h_condDiff] with ω hω + change (X s) ω * (P[fun ω ↦ X t ω - X s ω | (𝓕 s : MeasurableSpace Ω)]) ω = (0 : ℝ) + rw [hω]; simp + -- Decomposition of the integrand. + have h_decomp_ae : + (fun ω ↦ (X t ω) ^ 2 - (t : ℝ)) =ᵐ[P] fun ω ↦ + ((X s ω) ^ 2 + 2 * (X s ω * (X t ω - X s ω))) + + ((X t ω - X s ω) ^ 2 - (t : ℝ)) := + Filter.Eventually.of_forall fun ω ↦ by ring + -- `condExp` respects ae-equality. + have step1 : + P[fun ω ↦ (X t ω) ^ 2 - (t : ℝ) | (𝓕 s : MeasurableSpace Ω)] + =ᵐ[P] P[fun ω ↦ + ((X s ω) ^ 2 + 2 * (X s ω * (X t ω - X s ω))) + + ((X t ω - X s ω) ^ 2 - (t : ℝ)) | (𝓕 s : MeasurableSpace Ω)] := + condExp_congr_ae h_decomp_ae + -- Outer linearity. + have h_int_inner_left : + Integrable (fun ω ↦ (X s ω) ^ 2 + 2 * (X s ω * (X t ω - X s ω))) P := + h_int_Bs_sq.add (h_int_cross.const_mul 2) + have h_int_inner_right : + Integrable (fun ω ↦ (X t ω - X s ω) ^ 2 - (t : ℝ)) P := + h_int_diff_sq.sub (integrable_const _) + have step2 : + P[fun ω ↦ + ((X s ω) ^ 2 + 2 * (X s ω * (X t ω - X s ω))) + + ((X t ω - X s ω) ^ 2 - (t : ℝ)) | (𝓕 s : MeasurableSpace Ω)] + =ᵐ[P] + (P[fun ω ↦ (X s ω) ^ 2 + 2 * (X s ω * (X t ω - X s ω)) + | (𝓕 s : MeasurableSpace Ω)]) + + (P[fun ω ↦ (X t ω - X s ω) ^ 2 - (t : ℝ) | (𝓕 s : MeasurableSpace Ω)]) := + condExp_add h_int_inner_left h_int_inner_right _ + -- Inner linearity. Use `(2 : ℝ) •` so `condExp_smul` applies. + have h_eq_smul : (fun ω ↦ 2 * (X s ω * (X t ω - X s ω))) + = (2 : ℝ) • (fun ω ↦ X s ω * (X t ω - X s ω)) := by + funext ω; simp [Pi.smul_apply, smul_eq_mul] + have h_int_2cross : Integrable (fun ω ↦ 2 * (X s ω * (X t ω - X s ω))) P := + h_int_cross.const_mul 2 + have step3a : + P[fun ω ↦ (X s ω) ^ 2 + 2 * (X s ω * (X t ω - X s ω)) + | (𝓕 s : MeasurableSpace Ω)] + =ᵐ[P] + (P[fun ω ↦ (X s ω) ^ 2 | (𝓕 s : MeasurableSpace Ω)]) + + (P[fun ω ↦ 2 * (X s ω * (X t ω - X s ω)) | (𝓕 s : MeasurableSpace Ω)]) := + condExp_add h_int_Bs_sq h_int_2cross _ + have step3b : + P[fun ω ↦ 2 * (X s ω * (X t ω - X s ω)) | (𝓕 s : MeasurableSpace Ω)] + =ᵐ[P] (2 : ℝ) • P[fun ω ↦ X s ω * (X t ω - X s ω) | (𝓕 s : MeasurableSpace Ω)] := by + rw [h_eq_smul]; exact condExp_smul (2 : ℝ) _ _ + rw [h_condBs_sq] at step3a + have step3 : + P[fun ω ↦ (X s ω) ^ 2 + 2 * (X s ω * (X t ω - X s ω)) + | (𝓕 s : MeasurableSpace Ω)] + =ᵐ[P] + (fun ω ↦ (X s ω) ^ 2) + + (2 : ℝ) • (P[fun ω ↦ X s ω * (X t ω - X s ω) | (𝓕 s : MeasurableSpace Ω)]) := by + filter_upwards [step3a, step3b] with ω h3a h3b + simp only [Pi.add_apply, Pi.smul_apply, smul_eq_mul] at h3a h3b ⊢ + linarith + -- Inner sub on the right. + have step4 : + P[fun ω ↦ (X t ω - X s ω) ^ 2 - (t : ℝ) | (𝓕 s : MeasurableSpace Ω)] + =ᵐ[P] + (P[fun ω ↦ (X t ω - X s ω) ^ 2 | (𝓕 s : MeasurableSpace Ω)]) - + (fun _ ↦ (t : ℝ)) := by + have h_const_int : Integrable (fun _ : Ω ↦ (t : ℝ)) P := integrable_const _ + have step4a : + P[fun ω ↦ (X t ω - X s ω) ^ 2 - (t : ℝ) | (𝓕 s : MeasurableSpace Ω)] + =ᵐ[P] + (P[fun ω ↦ (X t ω - X s ω) ^ 2 | (𝓕 s : MeasurableSpace Ω)]) - + P[fun _ : Ω ↦ (t : ℝ) | (𝓕 s : MeasurableSpace Ω)] := + condExp_sub h_int_diff_sq h_const_int _ + have step4b : + P[fun _ : Ω ↦ (t : ℝ) | (𝓕 s : MeasurableSpace Ω)] = fun _ ↦ (t : ℝ) := + condExp_const (𝓕.le s) (t : ℝ) + filter_upwards [step4a] with ω h4a + rw [h4a, step4b] + -- Combine via `linear_combination`. + filter_upwards [step1, step2, step3, step4, h_cond_cross, h_condDiffSq] + with ω hs1 hs2 hs3 hs4 hcross hdiffsq + simp only [Pi.add_apply, Pi.sub_apply, Pi.smul_apply, smul_eq_mul] at hs2 hs3 hs4 + linear_combination hs1 + hs2 + hs3 + hs4 + 2 * hcross + hdiffsq + +/-- **Wald exponential martingale.** For a filtered pre-Brownian motion `X` and `α : ℝ`, +the process `t ↦ exp(α X_t − α² t / 2)` is a martingale w.r.t. `𝓕`. It is the exponential +martingale of the process `αX` (`MathFin.martingale_exp_sub_of_indep_increments`): the increment +`α(X_t − X_s)` is a function of `X_t − X_s`, so it is independent of `𝓕_s`, and since +`X_t − X_s ∼ N(0, t − s)` its exponential moment is `e^{α²(t − s)/2}` (the Gaussian MGF). -/ +theorem waldExponential_isMartingale (α : ℝ) : + Martingale (fun t ω ↦ Real.exp (α * X t ω - α ^ 2 * (t : ℝ) / 2)) 𝓕 P := by + refine MathFin.martingale_exp_sub_of_indep_increments (X := fun t ω ↦ α * X t ω) + (ψ := fun t : ℝ≥0 ↦ α ^ 2 * (t : ℝ) / 2) (fun t ↦ (hX.stronglyAdapted t).const_mul α) + (fun s t hst ↦ ?_) + (fun t ↦ (hX.hasLaw_eval t).integrable_fun_comp (integrable_exp_mul_gaussianReal α)) + (fun s t hst ↦ ?_) + · -- `α(X_t − X_s)` is a function of the increment, which is independent of `𝓕_s` + exact hX.indep_comap_of_eq_comp_increment hst (f := fun y ↦ α * y) (by fun_prop) + fun ω ↦ (mul_sub α (X t ω) (X s ω)).symm + · -- the increment is `N(0, t − s)`, whose exponential moment at `α` is `e^{α²(t − s)/2}` + have hf : AEStronglyMeasurable (fun x : ℝ ↦ Real.exp (α * x)) (gaussianReal 0 (t - s)) := by + fun_prop + have h := (MathFin.hasLaw_increment hX.toIsPreBrownianReal hst).integral_comp hf + rw [integral_exp_mul_gaussianReal_zero, NNReal.coe_sub hst] at h + change ∫ ω, Real.exp (α * X t ω - α * X s ω) ∂P + = Real.exp (α ^ 2 * (t : ℝ) / 2 - α ^ 2 * (s : ℝ) / 2) + calc ∫ ω, Real.exp (α * X t ω - α * X s ω) ∂P + = ∫ ω, Real.exp (α * (X t ω - X s ω)) ∂P := by simp_rw [mul_sub] + _ = Real.exp (α ^ 2 * ((t : ℝ) - s) / 2) := h + _ = Real.exp (α ^ 2 * (t : ℝ) / 2 - α ^ 2 * (s : ℝ) / 2) := by + congr 1 + ring + +end IsFilteredPreBrownian + +end ProbabilityTheory + +/-! ## Hitting time of an open set is a stopping time + +For a continuous adapted process `X` and an open set `A`, the hitting time +`τ_A = inf {t ≥ 0 : X_t ∈ A}` is a stopping time w.r.t. any right-continuous +filtration. The proof reduces `{ω | τ ω < i}` to a countable union of +`{ω | X_q ω ∈ A}` for nonnegative rationals `q < i` (continuity of `X(·, ω)` +upgrades any real witness to a rational witness via `Real.exists_rat_btwn`), +then applies `isStoppingTime_of_measurableSet_lt_of_isRightContinuous`. + +The result is generic — applies to any adapted continuous process — but lives +here because the canonical application is to Brownian motion paths. +This is an open-set counterpart to the fixed-level result in Saporito's +Proposition 4.3.6, with a right-continuous filtration. -/ + +namespace MathFin + +open MeasureTheory ProbabilityTheory + +variable {Ω β : Type*} {mΩ : MeasurableSpace Ω} + +/-- Key set identity: for continuous adapted `X` and open `A`, the set +`{ω | hittingAfter X A 0 ω < i}` equals the countable union over nonnegative +rationals `q < i` of `{ω | X (q : ℝ) ω ∈ A}`. -/ +lemma hittingAfter_lt_eq_iUnion_rationals + [TopologicalSpace β] + {X : ℝ → Ω → β} {A : Set β} + (hX_cont : ∀ ω, Continuous (fun t ↦ X t ω)) (hA_open : IsOpen A) + (i : ℝ) : + {ω | hittingAfter X A 0 ω < (i : WithTop ℝ)} + = ⋃ (q : ℚ) (_ : (0 : ℝ) ≤ (q : ℝ)) (_ : (q : ℝ) < i), + {ω | X (q : ℝ) ω ∈ A} := by + ext ω + rw [Set.mem_ofPred_eq, hittingAfter_lt_iff] + simp only [Set.mem_iUnion, Set.mem_ofPred_eq, Set.mem_Ico, exists_prop] + constructor + · rintro ⟨j, ⟨hj_nn, hj_lt⟩, hXj⟩ + have h_pre : (fun t : ℝ ↦ X t ω) ⁻¹' A ∈ nhds j := + ((hX_cont ω).continuousAt).preimage_mem_nhds (hA_open.mem_nhds hXj) + rcases lt_or_eq_of_le hj_nn with hj_pos | hj_zero + · obtain ⟨δ, hδ_pos, hδ_sub⟩ : ∃ δ > 0, + Set.Ioo (j - δ) (j + δ) ⊆ (fun t : ℝ ↦ X t ω) ⁻¹' A := by + have h_nhds := Metric.mem_nhds_iff.mp h_pre + obtain ⟨ε, hε_pos, hε_sub⟩ := h_nhds + refine ⟨ε, hε_pos, fun s hs ↦ ?_⟩ + refine hε_sub ?_ + simp only [Metric.mem_ball, Real.dist_eq, Set.mem_Ioo] at hs ⊢ + cases hs with | intro h1 h2 => exact abs_sub_lt_iff.mpr ⟨by linarith, by linarith⟩ + have h_min_pos : 0 < min δ (min j (i - j)) := + lt_min hδ_pos (lt_min hj_pos (by linarith)) + set δ' := min δ (min j (i - j)) / 2 with hδ'_def + have hδ'_pos : 0 < δ' := half_pos h_min_pos + have hδ'_lt_min : δ' < min δ (min j (i - j)) := half_lt_self h_min_pos + have hδ'_le_δ : δ' ≤ δ := hδ'_lt_min.le.trans (min_le_left _ _) + have hδ'_lt_j : δ' < j := + hδ'_lt_min.trans_le ((min_le_right _ _).trans (min_le_left _ _)) + have hδ'_lt_i_sub_j : δ' < i - j := + hδ'_lt_min.trans_le ((min_le_right _ _).trans (min_le_right _ _)) + have h_sub_pre : Set.Ioo (j - δ') (j + δ') ⊆ (fun t : ℝ ↦ X t ω) ⁻¹' A := by + intro s hs + refine hδ_sub ⟨?_, ?_⟩ + · linarith [hs.1, hδ'_le_δ] + · linarith [hs.2, hδ'_le_δ] + obtain ⟨q, hq1, hq2⟩ := exists_rat_btwn (show j - δ' < j + δ' by linarith) + refine ⟨q, ?_, ?_, h_sub_pre ⟨hq1, hq2⟩⟩ + · linarith [hδ'_lt_j] + · linarith [hδ'_lt_i_sub_j] + · refine ⟨0, ?_, ?_, ?_⟩ + · simp + · push_cast + linarith + · push_cast + rw [show (0 : ℝ) = j from hj_zero] + exact hXj + · rintro ⟨q, hq_nn, hq_lt, hXq⟩ + exact ⟨(q : ℝ), ⟨hq_nn, hq_lt⟩, hXq⟩ + +/-- For continuous adapted `X` and open `A`, `{hittingAfter X A 0 < i}` is `𝓕 i`-measurable. -/ +lemma measurableSet_hittingAfter_lt_of_open + [TopologicalSpace β] [MeasurableSpace β] [BorelSpace β] + {𝓕 : Filtration ℝ mΩ} {X : ℝ → Ω → β} {A : Set β} + (hX_cont : ∀ ω, Continuous (fun t ↦ X t ω)) (hX_adapted : Adapted 𝓕 X) + (hA_open : IsOpen A) (i : ℝ) : + MeasurableSet[𝓕 i] {ω | hittingAfter X A 0 ω < (i : WithTop ℝ)} := by + rw [hittingAfter_lt_eq_iUnion_rationals hX_cont hA_open] + refine MeasurableSet.iUnion fun q ↦ ?_ + refine MeasurableSet.iUnion fun hq_nn ↦ ?_ + refine MeasurableSet.iUnion fun hq_lt ↦ ?_ + exact 𝓕.mono hq_lt.le _ (hX_adapted (q : ℝ) hA_open.measurableSet) + +/-- **Open-set hitting time.** For a continuous adapted process `X` and an open set `A`, +`hittingAfter X A 0` is a stopping time for a right-continuous filtration. +Saporito's Proposition 4.3.6 concerns hitting a fixed level. -/ +theorem isStoppingTime_hittingAfter_of_open + [TopologicalSpace β] [MeasurableSpace β] [BorelSpace β] + {𝓕 : Filtration ℝ mΩ} [𝓕.IsRightContinuous] + {X : ℝ → Ω → β} {A : Set β} + (hX_cont : ∀ ω, Continuous (fun t ↦ X t ω)) (hX_adapted : Adapted 𝓕 X) + (hA_open : IsOpen A) : + IsStoppingTime 𝓕 (hittingAfter X A 0) := + isStoppingTime_of_measurableSet_lt_of_isRightContinuous fun i ↦ + measurableSet_hittingAfter_lt_of_open hX_cont hX_adapted hA_open i + +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/BrownianQuadraticVariation.lean b/LeanPool/MathFin/Probability/Brownian/BrownianQuadraticVariation.lean new file mode 100644 index 0000000000..38b036ce6c --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/BrownianQuadraticVariation.lean @@ -0,0 +1,211 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Gaussian.GaussianMoments + +/-! +# Quadratic variation of Brownian motion (L¹ expectation) + +For a real-indexed process `B : ℝ → Ω → ℝ` with measurable sections and +Gaussian increments `B t − B s ∼ N(0, t − s)`, the squared-increment sums +along the equipartition of `[0, t]` with `n + 1` subintervals have +expectation `n t / (n + 1)`, which tends to `t` as `n → ∞`. + +This is the L¹ form of `[B, B]_t = t` (Saporito Theorem 6.1.1). It does +not require independence of increments or continuity of paths — purely a +marginal moment computation via `variance_id_gaussianReal`. + +## Main definitions + +* `BrownianQuadraticVariation`: the hypotheses on a real-indexed process `B` (measurable sections + and Gaussian increments `B t − B s ∼ N(0, t − s)`) that suffice for the `L¹` quadratic-variation + identity. + +## Main results + +* `BrownianQuadraticVariation.qv_equals_t` — the squared-increment-sum + expectations along the equipartition of `[0, t]` tend to `t`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Theorem 6.1.1 + +## Tags + +quadratic variation, squared increments, Wiener process, [B, B]_t = t, Gaussian increments, +MSC 60J65, MSC 60H05 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal + +namespace MathFin + +/-- Hypotheses on a real-indexed process `B : ℝ → Ω → ℝ` that suffice for +the quadratic-variation identity at expectation (Saporito Theorem 6.1.1). + +`measurable` is included because `Measure.map` is only meaningful for +(a.e.-)measurable functions; together with `gaussian_increments` it yields +the second-moment integral via `integral_map` + `variance_id_gaussianReal`. -/ +structure BrownianQuadraticVariation {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) (B : ℝ → Ω → ℝ) : Prop where + measurable : ∀ t : ℝ, Measurable (B t) + gaussian_increments : ∀ ⦃s t : ℝ⦄, 0 ≤ s → s ≤ t → + ∃ v : NNReal, (v : ℝ) = t - s ∧ + Measure.map (fun ω ↦ B t ω - B s ω) μ = gaussianReal 0 v + +namespace BrownianQuadraticVariation + +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} {B : ℝ → Ω → ℝ} + +/-- The increment `B t − B s` is measurable. -/ +theorem measurable_increment (hB : BrownianQuadraticVariation μ B) + (s t : ℝ) : Measurable (fun ω ↦ B t ω - B s ω) := + (hB.measurable t).sub (hB.measurable s) + +/-- Integrability of `x²` under any centered real Gaussian. -/ +lemma integrable_sq_gaussianReal_zero (v : ℝ≥0) : + Integrable (fun x : ℝ ↦ x ^ 2) (gaussianReal 0 v) := by + have h_lp : MemLp (id : ℝ → ℝ) 2 (gaussianReal 0 v) := memLp_id_gaussianReal 2 + exact h_lp.integrable_sq + +/-- For `s ≤ t`, the squared increment `(B t − B s)²` has expectation `t − s`. -/ +theorem integral_sq_increment (hB : BrownianQuadraticVariation μ B) + {s t : ℝ} (hs : 0 ≤ s) (hst : s ≤ t) : + ∫ ω, (B t ω - B s ω) ^ 2 ∂μ = t - s := by + obtain ⟨v, hv, h_map⟩ := hB.gaussian_increments hs hst + have h_aem : AEMeasurable (fun ω ↦ B t ω - B s ω) μ := + (hB.measurable_increment s t).aemeasurable + have h_map_int : ∫ y : ℝ, y ^ 2 ∂(Measure.map (fun ω ↦ B t ω - B s ω) μ) + = ∫ ω, (B t ω - B s ω) ^ 2 ∂μ := + integral_map h_aem (by fun_prop) + rw [← h_map_int, h_map, MathFin.integral_sq_gaussianReal, hv] + +/-- The squared increment is integrable. -/ +theorem integrable_sq_increment (hB : BrownianQuadraticVariation μ B) + {s t : ℝ} (hs : 0 ≤ s) (hst : s ≤ t) : + Integrable (fun ω ↦ (B t ω - B s ω) ^ 2) μ := by + obtain ⟨v, _, h_map⟩ := hB.gaussian_increments hs hst + have h_aem : AEMeasurable (fun ω ↦ B t ω - B s ω) μ := + (hB.measurable_increment s t).aemeasurable + refine (show Integrable ((fun x : ℝ ↦ x ^ 2) ∘ (fun ω ↦ B t ω - B s ω)) μ from + Integrable.comp_aemeasurable ?_ h_aem) + rw [h_map] + exact integrable_sq_gaussianReal_zero _ + +/-- **Mean of BM increment is zero**: `E[B_t − B_s] = 0` for `s ≤ t`. +Pushforward law is `gaussianReal 0 v` with `v = t − s`; the first moment of +a centred Gaussian is `0`. -/ +theorem integral_increment (hB : BrownianQuadraticVariation μ B) + {s t : ℝ} (hs : 0 ≤ s) (hst : s ≤ t) : + ∫ ω, (B t ω - B s ω) ∂μ = 0 := by + obtain ⟨v, _hv, h_map⟩ := hB.gaussian_increments hs hst + have h_aem : AEMeasurable (fun ω ↦ B t ω - B s ω) μ := + (hB.measurable_increment s t).aemeasurable + have h_map_int : ∫ y : ℝ, y ∂(Measure.map (fun ω ↦ B t ω - B s ω) μ) + = ∫ ω, (B t ω - B s ω) ∂μ := + integral_map h_aem (by fun_prop) + rw [← h_map_int, h_map, integral_id_gaussianReal] + +/-- Integrability of the BM increment `B_t − B_s` under a finite measure. -/ +theorem integrable_increment + (hB : BrownianQuadraticVariation μ B) {s t : ℝ} (hs : 0 ≤ s) (hst : s ≤ t) : + Integrable (fun ω ↦ B t ω - B s ω) μ := by + obtain ⟨v, _, h_map⟩ := hB.gaussian_increments hs hst + have h_aem : AEMeasurable (fun ω ↦ B t ω - B s ω) μ := + (hB.measurable_increment s t).aemeasurable + refine (show Integrable ((fun x : ℝ ↦ x) ∘ (fun ω ↦ B t ω - B s ω)) μ from + Integrable.comp_aemeasurable ?_ h_aem) + rw [h_map] + exact (memLp_id_gaussianReal 1).integrable (by norm_num) + +/-- Expectation of the squared-increment sum along the equipartition: +`∫ Σ_k (B_{(k+1)t/(n+1)} − B_{kt/(n+1)})² ∂μ = n t / (n + 1)`. -/ +private lemma integral_sum_sq_equipartition (hB : BrownianQuadraticVariation μ B) + {t : ℝ} (ht : 0 ≤ t) (n : ℕ) : + ∫ ω, ∑ k ∈ Finset.range n, + (B (((k : ℝ) + 1) * t / (n + 1)) ω - B ((k : ℝ) * t / (n + 1)) ω) ^ 2 ∂μ + = n * t / (n + 1) := by + have hstart (k : ℕ) : (0 : ℝ) ≤ (k : ℝ) * t / (n + 1) := by positivity + have hend (k : ℕ) : (k : ℝ) * t / (n + 1) ≤ ((k : ℝ) + 1) * t / (n + 1) := by + rw [div_le_div_iff_of_pos_right (by positivity : (0 : ℝ) < (n : ℝ) + 1)] + nlinarith + rw [integral_finsetSum _ (fun k _ ↦ hB.integrable_sq_increment (hstart k) (hend k))] + have hsum : ∀ k ∈ Finset.range n, + ∫ ω, (B (((k : ℝ) + 1) * t / (n + 1)) ω - B ((k : ℝ) * t / (n + 1)) ω) ^ 2 ∂μ + = t / (n + 1) := fun k _ ↦ by + rw [hB.integral_sq_increment (hstart k) (hend k)] + field_simp + ring + rw [Finset.sum_congr rfl hsum, Finset.sum_const, Finset.card_range, nsmul_eq_mul] + field_simp + +/-- Real-analysis fact: `n t / (n + 1) → t` as `n → ∞`. -/ +lemma tendsto_nt_div_succ (t : ℝ) : + Filter.Tendsto (fun n : ℕ ↦ (n : ℝ) * t / ((n : ℝ) + 1)) atTop (nhds t) := by + have h_eq : ∀ n : ℕ, (n : ℝ) * t / ((n : ℝ) + 1) = t - t / ((n : ℝ) + 1) := by + intro n + have hn : ((n : ℝ) + 1) ≠ 0 := by positivity + field_simp + ring + rw [show (fun n : ℕ ↦ (n : ℝ) * t / ((n : ℝ) + 1)) = + (fun n : ℕ ↦ t - t / ((n : ℝ) + 1)) from funext h_eq] + have h_one_div : Filter.Tendsto (fun n : ℕ ↦ (1 : ℝ) / ((n : ℝ) + 1)) atTop (nhds (0 : ℝ)) := + tendsto_one_div_add_atTop_nhds_zero_nat + have h_t_div : Filter.Tendsto (fun n : ℕ ↦ t / ((n : ℝ) + 1)) atTop (nhds (0 : ℝ)) := by + have h_const_mul : Filter.Tendsto (fun n : ℕ ↦ t * ((1 : ℝ) / ((n : ℝ) + 1))) atTop + (nhds (t * 0)) := h_one_div.const_mul t + rw [mul_zero] at h_const_mul + refine h_const_mul.congr ?_ + intro n + ring + have h_sub : Filter.Tendsto (fun n : ℕ ↦ t - t / ((n : ℝ) + 1)) atTop (nhds (t - 0)) := + tendsto_const_nhds.sub h_t_div + rwa [sub_zero] at h_sub + +/-- Saporito Theorem 6.1.1, in L¹ form: for a process with measurable sections and +Gaussian increments, the squared-increment sums along the equipartition of `[0, t]` +with `n + 1` subintervals have expectation tending to `t` as `n → ∞`. -/ +theorem qv_equals_t (hB : BrownianQuadraticVariation μ B) + {t : ℝ} (ht : 0 ≤ t) : + Filter.Tendsto + (fun n : ℕ ↦ + ∫ ω, (∑ k ∈ Finset.range n, + (B ((↑k + 1) * t / (n + 1)) ω - B (↑k * t / (n + 1)) ω) ^ 2) ∂μ) + atTop (nhds t) := + (tendsto_nt_div_succ t).congr fun n ↦ + (hB.integral_sum_sq_equipartition ht n).symm + +end BrownianQuadraticVariation + +/-- **Bridge: a (measurable) pre-Brownian motion is a quadratic-variation +process.** Reparametrising a pre-Brownian (`IsPreBrownianReal`) process +`B : ℝ≥0 → Ω → ℝ` to the real line via `Real.toNNReal` (`B' t := B t.toNNReal`), +the result satisfies the `BrownianQuadraticVariation` hypotheses, so the whole +variance-swap tower can be driven from a single `IsPreBrownianReal` hypothesis +(plus evaluation-measurability — `IsPreBrownianReal` supplies only a.e. +measurability). The increment law is `MathFin.hasLaw_increment` (Mathlib's +`IsPreBrownianReal.hasLaw_sub` with its `nndist` variance read as the `ℝ≥0` subtraction) at +the reparametrised times `t.toNNReal`, `s.toNNReal`. -/ +theorem brownianQuadraticVariation_of_isPreBrownianReal + {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + (hB : IsPreBrownianReal B μ) (hBmeas : ∀ u : ℝ≥0, Measurable (B u)) : + BrownianQuadraticVariation μ (fun t ω ↦ B t.toNNReal ω) where + measurable t := hBmeas t.toNNReal + gaussian_increments := by + intro s t hs hst + have ht : (0 : ℝ) ≤ t := hs.trans hst + have hst' : s.toNNReal ≤ t.toNNReal := Real.toNNReal_mono hst + refine ⟨t.toNNReal - s.toNNReal, ?_, ?_⟩ + · rw [NNReal.coe_sub hst', Real.coe_toNNReal t ht, Real.coe_toNNReal s hs] + · exact (hasLaw_increment hB hst').map_eq + +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/ExpMartingaleBrownian.lean b/LeanPool/MathFin/Probability/Brownian/ExpMartingaleBrownian.lean new file mode 100644 index 0000000000..b9dac2246d --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/ExpMartingaleBrownian.lean @@ -0,0 +1,137 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.ExpMartingaleQBrownian +public import LeanPool.KLS.BrownianMotion.Gaussian.BrownianMotion + +/-! +# Brownian motion from an exponential martingale + +`Probability/Brownian/ExpMartingaleQBrownian.lean` turns the exponential-martingale data +`IsExpQMartingale Q 𝓕 Y T` (`Y` adapted, `Y_0 = 0` a.e., every `t ↦ exp(a·Y_t − ½a²t)` a +`Q`-martingale on `[0,T]`) into `N(0,t−s)` increments and Mathlib's `HasIndepIncrements` on +`[0,T]`. Its docstring names what it leaves out: independence of the increments from the past, +and the conclusion on the whole time axis. This module supplies both. + +* **Independence from the past.** The conditional moment-generating function + `𝔼_Q[exp(a·(Y_t − Y_s)) | 𝓕_s] = exp(½a²(t−s))` is deterministic. Integrated over + `A ∈ 𝓕_s`, it says that the law of `Y_t − Y_s` under `Q` restricted to `A` has the + moment-generating function of `Q(A)·N(0,t−s)`, and a finite measure with every exponential + moment is fixed by its moment-generating function (`measure_eq_of_mgf_id_eq`). Evaluated on a + Borel set `B`, this is `Q({Y_t − Y_s ∈ B} ∩ A) = Q(Y_t − Y_s ∈ B)·Q(A)`. +* **The whole time axis.** If the data hold for every horizon `T`, the marginal laws are + `N(0,t)` and the increments are independent, so `Y` is a pre-Brownian motion (Mathlib's + `HasIndepIncrements.isPreBrownianReal_of_hasLaw`); with independence from the past it is a + filtered pre-Brownian motion in the sense of BrownianMotion's `IsFilteredPreBrownian`; with + continuous paths it is Mathlib's `IsBrownianReal`. + +This is the exponential-martingale form of Lévy's characterization: the hypothesis is that every +`exp(a·Y − ½a²·)` is a martingale. Lévy's characterization in its usual form (a continuous local +martingale `M` with `M₀ = 0` and `M² − t` a local martingale is a Brownian motion) is proved from +this theorem in `LevyCharacterization.lean`: the exponential martingales come from a cell-by-cell +second-order expansion, not from Itô's formula. + +## Main results + +* `MathFin.indep_increment_of_expMartingale`: `Y_t − Y_s` is `Q`-independent of `𝓕_s` for + `s ≤ t ≤ T`. +* `MathFin.hasIndepIncrements_of_forall_expMartingale`: `HasIndepIncrements Y Q` on all of `ℝ≥0` + when the data hold for every horizon. +* `MathFin.isPreBrownianReal_of_expMartingale`: then `IsPreBrownianReal Y Q`. +* `MathFin.isFilteredPreBrownian_of_expMartingale`: then `IsFilteredPreBrownian Y 𝓕 Q`. +* `MathFin.isBrownianReal_of_expMartingale`: with a.s. continuous paths, `IsBrownianReal Y Q`. + +## Tags + +Lévy characterization, exponential martingale, Brownian motion, independent increments, +filtered Brownian motion, MSC 60J65, MSC 60G44 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} [IsProbabilityMeasure Q] + {𝓕 : Filtration ℝ≥0 mΩ} {Y : ℝ≥0 → Ω → ℝ} {T : ℝ≥0} + +/-- **Increments are independent of the past.** For `s ≤ t ≤ T`, `Y_t − Y_s` is `Q`-independent +of `𝓕_s`. Integrating the deterministic conditional moment-generating function +(`IsExpQMartingale.condExp_exp_increment`) over `A ∈ 𝓕_s` shows that the law of `Y_t − Y_s` under +`Q` restricted to `A` has the moment-generating function of `Q(A)·N(0,t−s)`, hence is that measure +(`measure_eq_of_mgf_id_eq`); on a Borel set `B` this reads +`Q({Y_t − Y_s ∈ B} ∩ A) = Q(A)·N(0,t−s)(B) = Q(A)·Q(Y_t − Y_s ∈ B)`. -/ +theorem indep_increment_of_expMartingale (h : IsExpQMartingale Q 𝓕 Y T) {s t : ℝ≥0} + (hst : s ≤ t) (htT : t ≤ T) : + Indep (MeasurableSpace.comap (fun ω ↦ Y t ω - Y s ω) inferInstance) (𝓕 s) Q := by + have hD : Measurable fun ω ↦ Y t ω - Y s ω := (h.measurable t).sub (h.measurable s) + have hlaw := increment_map_eq_gaussianReal_of_expMartingale h hst htT + have hlaw' : HasLaw (fun ω ↦ Y t ω - Y s ω) (gaussianReal 0 (t - s)) Q := + ⟨hD.aemeasurable, hlaw⟩ + have hexp (u : ℝ) : Integrable (fun ω ↦ Real.exp (u * (Y t ω - Y s ω))) Q := + hlaw'.integrable_fun_comp (integrable_exp_mul_gaussianReal u) + refine (Indep_iff _ _ Q).2 fun _ A ⟨B, hB, hBA⟩ hA ↦ ?_ + subst hBA + have : IsFiniteMeasure (Q A • gaussianReal 0 (t - s)) := + Measure.smul_finite _ (measure_ne_top Q A) + have hrestrict : (Q.restrict A).map (fun ω ↦ Y t ω - Y s ω) = Q A • gaussianReal 0 (t - s) := by + refine measure_eq_of_mgf_id_eq (fun u ↦ (integrable_map_measure (by fun_prop) + hD.aemeasurable).2 (hexp u).restrict) ?_ + funext u + rw [mgf_id_map hD.aemeasurable, mgf_smul_measure, mgf_id_gaussianReal, mgf, + ← setIntegral_condExp (𝓕.le s) (hexp u) hA, + setIntegral_congr_ae (𝓕.le s A hA) ((h.condExp_exp_increment u hst + htT).mono fun _ hω _ ↦ hω), setIntegral_const, NNReal.coe_sub hst, measureReal_def, + smul_eq_mul] + ring_nf + have hB' := congrArg (· B) hrestrict + simp only [Measure.map_apply hD hB, Measure.restrict_apply (hD hB), smul_apply, + smul_eq_mul, ← hlaw] at hB' + rw [hB', mul_comm] + +/-! ### The whole time axis -/ + +/-- **Independent increments on the whole axis.** If the exponential-martingale data hold for every +horizon `T`, then `Y` has independent increments on `ℝ≥0`: times `t₀ ≤ ⋯ ≤ tₙ` lie in `[0,tₙ]`, +where `hasIndepIncrements_of_expMartingale` applies. -/ +theorem hasIndepIncrements_of_forall_expMartingale (h : ∀ T, IsExpQMartingale Q 𝓕 Y T) : + HasIndepIncrements Y Q := fun n t ht ↦ + hasIndepIncrements_of_expMartingale (h (t (Fin.last n))) n + (fun i ↦ ⟨t i, ht (Fin.le_last i)⟩) fun _ _ hij ↦ ht hij + +/-- **Pre-Brownian motion from exponential martingales.** If the exponential-martingale data hold +for every horizon, `Y` is a pre-Brownian motion under `Q`: its marginals are `N(0,t)` +(`map_eq_gaussianReal_of_expMartingale`) and its increments are independent, which fixes every +finite-dimensional law (`HasIndepIncrements.isPreBrownianReal_of_hasLaw`). -/ +theorem isPreBrownianReal_of_expMartingale (h : ∀ T, IsExpQMartingale Q 𝓕 Y T) : + IsPreBrownianReal Y Q := + (hasIndepIncrements_of_forall_expMartingale h).isPreBrownianReal_of_hasLaw fun t ↦ + ⟨((h t).measurable t).aemeasurable, map_eq_gaussianReal_of_expMartingale (h t) le_rfl⟩ + +/-- **Filtered pre-Brownian motion from exponential martingales.** If the exponential-martingale +data hold for every horizon, `Y` is an `𝓕`-pre-Brownian motion under `Q` in the sense of +BrownianMotion's `IsFilteredPreBrownian`: pre-Brownian, adapted, and with each increment +`Y_t − Y_s` independent of `𝓕_s` (`indep_increment_of_expMartingale`). -/ +theorem isFilteredPreBrownian_of_expMartingale (h : ∀ T, IsExpQMartingale Q 𝓕 Y T) : + IsFilteredPreBrownian Y 𝓕 Q where + toIsPreBrownianReal := isPreBrownianReal_of_expMartingale h + stronglyAdapted := (h 0).adapted + indep _ t hst := indep_increment_of_expMartingale (h t) hst le_rfl + +/-- **Brownian motion from exponential martingales.** If the exponential-martingale data hold for +every horizon and the paths of `Y` are a.s. continuous, `Y` is a Brownian motion under `Q` +(`IsBrownianReal`). -/ +theorem isBrownianReal_of_expMartingale (h : ∀ T, IsExpQMartingale Q 𝓕 Y T) + (hcont : ∀ᵐ ω ∂Q, Continuous (Y · ω)) : IsBrownianReal Y Q where + toIsPreBrownianReal := isPreBrownianReal_of_expMartingale h + cont := hcont + +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/ExpMartingaleQBrownian.lean b/LeanPool/MathFin/Probability/Brownian/ExpMartingaleQBrownian.lean new file mode 100644 index 0000000000..07c3505592 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/ExpMartingaleQBrownian.lean @@ -0,0 +1,474 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Laws.Esscher +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.MeasureTheory.Function.ConditionalExpectation.PullOut +public import Mathlib.Probability.Independence.CharacteristicFunction +public import Mathlib.Probability.Independence.Process.HasIndepIncrements.Basic +public import Mathlib.Probability.Process.Adapted + +/-! +# Brownian increment laws from an exponential martingale + +A process-agnostic packaging of the argument that turns an **exponential-martingale +hypothesis** into the increment laws of a Brownian motion under a probability measure `Q`. Fix a +probability space `(Ω, Q)`, a filtration `𝓕`, a horizon `T`, and a real process +`Y : ℝ≥0 → Ω → ℝ` that is `𝓕`-adapted, starts at `0` (a.e. `Q`), and satisfies + + `for every a : ℝ, the process t ↦ exp(a·Y_t − ½a² t) is a Q-martingale on [0,T]`. + +These three data are bundled as `IsExpQMartingale Q 𝓕 Y T`. The single theorem +`isQBrownianMotion_of_expMartingale` restates the zero start and derives two more properties of `Y` +under `Q` on `[0,T]`: `N(0,t−s)` increments, and independent increments in Mathlib's sense +(`HasIndepIncrements`). Together they fix every finite-dimensional law of `Y` on `[0,T]` to that +of a Brownian motion; that implication is not restated here (on the whole time axis `ℝ≥0` it is +Mathlib's `HasIndepIncrements.isPreBrownianReal_of_hasLaw`). Neither path continuity nor +independence of the increments from the past (`Y_t − Y_s` from `𝓕_s`) is part of the conclusion. +Nothing in the argument refers to how `Y` or `Q` was constructed. + +The mechanism: the exponential martingale at `s = 0` fixes the marginal moment-generating +function `𝔼_Q[exp(a·Y_t)] = exp(½a²t)`, hence the marginal law, and the conditional form +`𝔼_Q[exp(a·(Y_t − Y_s))|𝓕_s] = exp(½a²(t−s))` is deterministic, giving Gaussian increments. For +successive increments over `t₀ ≤ t₁ ≤ ⋯ ≤ tₙ`, the earlier ones are `𝓕_{tₙ₋₁}`-measurable and +factor out of the conditional expectation given `𝓕_{tₙ₋₁}`, so by induction the joint +moment-generating function is the product of the Gaussian ones. Every linear combination of the +increments is then Gaussian with the diagonal variance, and `iIndepFun_iff_charFun_pi` turns that +into joint independence. + +The value of the abstraction is coherence: the constant-, simple-, continuous- and +predictable-`θ` Girsanov drift-corrected processes each need only supply their own +exponential martingale (via the Bayes change-of-measure engine) and then instantiate this +one theorem. + +## Main definitions + +* `IsExpQMartingale`: the characterization data on a process `Y` under `Q`: adapted, starting at + `0` almost surely, and for every `a : ℝ` the set-integral martingale identity for + `exp(a·Y_t − ½a²t)` on `[0, T]` (integrability is not a field). +* `IsBrownianOn`: under `Q`, `Y` starts at `0` almost surely, has `N(0, t − s)` increments and + independent increments (`HasIndepIncrements`) on `[0, T]`; these fix the finite-dimensional + laws of a Brownian motion, but path continuity is not part of it. + +## Main results + +* `MathFin.map_eq_gaussianReal_of_expMartingale` — the marginal law `Q.map Y_t = N(0,t)`. +* `MathFin.increment_map_eq_gaussianReal_of_expMartingale` — the increment law `N(0,t−s)`. +* `MathFin.increments_iIndepFun_of_expMartingale` — successive increments are jointly + `Q`-independent. +* `MathFin.hasIndepIncrements_of_expMartingale` — `Y` has independent increments on `[0,T]`. +* `MathFin.isQBrownianMotion_of_expMartingale` — `IsExpQMartingale Q 𝓕 Y T → IsBrownianOn Q T Y`. +* `MathFin.IsBrownianOn.congr_modification` — invariance under a modification. + +## Tags + +Girsanov theorem, Lévy characterization, exponential martingale, Brownian increments, +moment generating function, Q-Brownian motion, MSC 60J65, MSC 60G44 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal RealInnerProductSpace + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- **The exponential-martingale characterization data.** A real process `Y` on the filtered +probability space `(Ω, 𝓕, Q)` that is `𝓕`-adapted, starts at `0` a.e. `Q`, and for which every +`t ↦ exp(a·Y_t − ½a² t)` is a `Q`-martingale on `[0,T]` (stated as the set-integral identity over +`𝓕_s`-sets). These are exactly the data output by the Bayes change-of-measure engine for a +drift-corrected process, and exactly the data consumed by `isQBrownianMotion_of_expMartingale`. -/ +structure IsExpQMartingale (Q : Measure Ω) (𝓕 : Filtration ℝ≥0 mΩ) (Y : ℝ≥0 → Ω → ℝ) (T : ℝ≥0) : + Prop where + /-- `Y` is adapted to the filtration. -/ + adapted : StronglyAdapted 𝓕 Y + /-- `Y` starts at `0` (a.e. `Q`). -/ + zero_start : Y 0 =ᵐ[Q] 0 + /-- For every `a`, `exp(a·Y_· − ½a²·)` is a `Q`-martingale on `[0,T]`. -/ + martingale : ∀ (a : ℝ) {s t : ℝ≥0}, s ≤ t → t ≤ T → ∀ {A : Set Ω}, + MeasurableSet[(𝓕 s : MeasurableSpace Ω)] A → + ∫ ω in A, Real.exp (a * Y t ω - a ^ 2 * (t : ℝ) / 2) ∂Q + = ∫ ω in A, Real.exp (a * Y s ω - a ^ 2 * (s : ℝ) / 2) ∂Q + +/-- Each `Y_u` of the characterization data is measurable, being `𝓕_u`-measurable. -/ +protected theorem IsExpQMartingale.measurable {Q : Measure Ω} {𝓕 : Filtration ℝ≥0 mΩ} + {Y : ℝ≥0 → Ω → ℝ} {T : ℝ≥0} (h : IsExpQMartingale Q 𝓕 Y T) (u : ℝ≥0) : Measurable (Y u) := + h.adapted.stronglyMeasurable.measurable + +variable {Q : Measure Ω} [IsProbabilityMeasure Q] {𝓕 : Filtration ℝ≥0 mΩ} + {Y : ℝ≥0 → Ω → ℝ} {T : ℝ≥0} + +/-- **A Gaussian MGF identifies the Gaussian law.** If a real random variable has the +moment-generating function `a ↦ exp(v·a²/2)` of `N(0,v)` under `Q`, its law is `N(0,v)`: +`N(0,v)` has every exponential moment, so its moment-generating function determines it +(`measure_eq_of_mgf_id_eq`). -/ +theorem map_eq_gaussianReal_of_mgf {X : Ω → ℝ} (hX : AEMeasurable X Q) {v : ℝ≥0} + (hmgf : ∀ a, mgf X Q a = Real.exp (v * a ^ 2 / 2)) : Q.map X = gaussianReal 0 v := by + refine Eq.symm (measure_eq_of_mgf_id_eq integrable_exp_mul_gaussianReal ?_) + rw [mgf_id_gaussianReal, mgf_id_map hX] + funext a + rw [hmgf, zero_mul, zero_add] + +/-- **Marginal `Q`-MGF.** `𝔼_Q[exp(a·Y_t)] = exp(½ t a²)`: read off from the exponential +martingale at `s = 0` (the `Q`-integral of `exp(a·Y_t − ½a²t)` equals its value at `0`, which is +`exp(a·Y_0) = 1` a.e. since `Y_0 = 0`). -/ +private theorem mgf_expY_eq (h : IsExpQMartingale Q 𝓕 Y T) {t : ℝ≥0} (htT : t ≤ T) (a : ℝ) : + ∫ ω, Real.exp (a * Y t ω) ∂Q = Real.exp ((t : ℝ) * a ^ 2 / 2) := by + have hbrick := h.martingale a (zero_le : (0 : ℝ≥0) ≤ t) htT (A := Set.univ) MeasurableSet.univ + simp only [Measure.restrict_univ] at hbrick + have hRHS : ∫ ω, Real.exp (a * Y 0 ω - a ^ 2 * ((0 : ℝ≥0) : ℝ) / 2) ∂Q = 1 := by + have hae : (fun ω ↦ Real.exp (a * Y 0 ω - a ^ 2 * ((0 : ℝ≥0) : ℝ) / 2)) + =ᵐ[Q] fun _ ↦ (1 : ℝ) := by + filter_upwards [h.zero_start] with ω hω; simp [hω] + rw [integral_congr_ae hae]; simp + rw [hRHS] at hbrick + have hLHS : ∫ ω, Real.exp (a * Y t ω - a ^ 2 * (t : ℝ) / 2) ∂Q + = Real.exp (-(a ^ 2 * (t : ℝ) / 2)) * ∫ ω, Real.exp (a * Y t ω) ∂Q := by + rw [← integral_const_mul] + refine integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ ?_) + change Real.exp (a * Y t ω - a ^ 2 * (t : ℝ) / 2) + = Real.exp (-(a ^ 2 * (t : ℝ) / 2)) * Real.exp (a * Y t ω) + rw [show a * Y t ω - a ^ 2 * (t : ℝ) / 2 = -(a ^ 2 * (t : ℝ) / 2) + a * Y t ω from by ring, + Real.exp_add] + rw [hLHS, mul_comm] at hbrick + have hfac : Real.exp (-(a ^ 2 * (t : ℝ) / 2)) ≠ 0 := (Real.exp_pos _).ne' + rw [(mul_eq_one_iff_eq_inv₀ hfac).mp hbrick, ← Real.exp_neg] + congr 1; ring + +/-- **Marginal law.** `Q.map Y_t = N(0, t)`: the `Q`-MGF is the Gaussian MGF (`mgf_expY_eq`), +which identifies the law (`map_eq_gaussianReal_of_mgf`). -/ +theorem map_eq_gaussianReal_of_expMartingale (h : IsExpQMartingale Q 𝓕 Y T) {t : ℝ≥0} + (htT : t ≤ T) : Q.map (Y t) = gaussianReal 0 t := + map_eq_gaussianReal_of_mgf (h.measurable t).aemeasurable (mgf_expY_eq h htT) + +/-- **Marginal `Q`-integrability.** `exp(a·Y_u)` is `Q`-integrable for `u ≤ T` — its law is +`N(0,u)` and the Gaussian MGF is finite. -/ +private theorem integrable_expY (h : IsExpQMartingale Q 𝓕 Y T) (a : ℝ) {u : ℝ≥0} (huT : u ≤ T) : + Integrable (fun ω ↦ Real.exp (a * Y u ω)) Q := by + rw [show (fun ω ↦ Real.exp (a * Y u ω)) = (fun x ↦ Real.exp (a * x)) ∘ (Y u) from rfl, + ← integrable_map_measure (by fun_prop) (h.measurable u).aemeasurable, + map_eq_gaussianReal_of_expMartingale h huT] + exact integrable_exp_mul_gaussianReal a + +omit [IsProbabilityMeasure Q] in +/-- **Cauchy–Schwarz for exponentials.** If `exp(2f)` and `exp(2g)` are `Q`-integrable, so is +`exp(f)·exp(g)`: `exp f` and `exp g` are then in `L²(Q)`. -/ +theorem integrable_exp_mul_exp {f g : Ω → ℝ} (hf : Measurable f) (hg : Measurable g) + (hf2 : Integrable (fun ω ↦ Real.exp (2 * f ω)) Q) + (hg2 : Integrable (fun ω ↦ Real.exp (2 * g ω)) Q) : + Integrable (fun ω ↦ Real.exp (f ω) * Real.exp (g ω)) Q := by + have hL2 {u : Ω → ℝ} (hu : Measurable u) (hu2 : Integrable (fun ω ↦ Real.exp (2 * u ω)) Q) : + MemLp (fun ω ↦ Real.exp (u ω)) 2 Q := by + refine (memLp_two_iff_integrable_sq hu.exp.aestronglyMeasurable).2 (hu2.congr ?_) + filter_upwards with ω + rw [two_mul, Real.exp_add, pow_two] + exact (hL2 hf hf2).integrable_mul (hL2 hg hg2) + +/-- **Conditional exponential martingale.** `𝔼_Q[exp(a·Y_t − ½a² t)|𝓕_s] = exp(a·Y_s − ½a² s)` +a.e., the conditional form of the `martingale` field (its set-integral identity converted via +`ae_eq_condExp_of_forall_setIntegral_eq`). -/ +private theorem condExp_expY (h : IsExpQMartingale Q 𝓕 Y T) (a : ℝ) {s t : ℝ≥0} (hst : s ≤ t) + (htT : t ≤ T) : + Q[fun ω ↦ Real.exp (a * Y t ω - a ^ 2 * (t : ℝ) / 2) | 𝓕 s] + =ᵐ[Q] fun ω ↦ Real.exp (a * Y s ω - a ^ 2 * (s : ℝ) / 2) := by + have hfint : ∀ u : ℝ≥0, u ≤ T → + Integrable (fun ω ↦ Real.exp (a * Y u ω - a ^ 2 * (u : ℝ) / 2)) Q := by + intro u huT + have hfac : (fun ω ↦ Real.exp (a * Y u ω - a ^ 2 * (u : ℝ) / 2)) + = fun ω ↦ Real.exp (-(a ^ 2 * (u : ℝ) / 2)) * Real.exp (a * Y u ω) := by + funext ω + rw [show a * Y u ω - a ^ 2 * (u : ℝ) / 2 = -(a ^ 2 * (u : ℝ) / 2) + a * Y u ω from by ring, + Real.exp_add] + rw [hfac]; exact (integrable_expY h a huT).const_mul _ + have hsm : StronglyMeasurable[(𝓕 s : MeasurableSpace Ω)] + (fun ω ↦ Real.exp (a * Y s ω - a ^ 2 * (s : ℝ) / 2)) := by + have hcont : Continuous fun x : ℝ ↦ a * x - a ^ 2 * (s : ℝ) / 2 := by fun_prop + exact Real.continuous_exp.comp_stronglyMeasurable (hcont.comp_stronglyMeasurable (h.adapted s)) + refine (ae_eq_condExp_of_forall_setIntegral_eq (𝓕.le s) (hfint t htT) + (fun A _ _ ↦ (hfint s (hst.trans htT)).integrableOn) (fun A hA _ ↦ ?_) + hsm.aestronglyMeasurable).symm + exact (h.martingale a hst htT hA).symm + +/-- **Conditional moment-generating function of an increment.** +`𝔼_Q[exp(a·(Y_t − Y_s)) | 𝓕_s] = exp(½a²(t−s))` a.e., deterministic: pull the `𝓕_s`-measurable +factor `exp(½a²t − a·Y_s)` out of `condExp_expY`. -/ +theorem IsExpQMartingale.condExp_exp_increment (h : IsExpQMartingale Q 𝓕 Y T) (a : ℝ) {s t : ℝ≥0} + (hst : s ≤ t) (htT : t ≤ T) : + Q[fun ω ↦ Real.exp (a * (Y t ω - Y s ω)) | 𝓕 s] + =ᵐ[Q] fun _ ↦ Real.exp (a ^ 2 * ((t : ℝ) - (s : ℝ)) / 2) := by + set ft : Ω → ℝ := fun ω ↦ Real.exp (a * Y t ω - a ^ 2 * (t : ℝ) / 2) with hftdef + set gs : Ω → ℝ := fun ω ↦ Real.exp (a ^ 2 * (t : ℝ) / 2 - a * Y s ω) with hgsdef + have hgs_sm : StronglyMeasurable[(𝓕 s : MeasurableSpace Ω)] gs := by + have hcont : Continuous fun x : ℝ ↦ a ^ 2 * (t : ℝ) / 2 - a * x := by fun_prop + exact Real.continuous_exp.comp_stronglyMeasurable (hcont.comp_stronglyMeasurable (h.adapted s)) + have hft_int : Integrable ft Q := by + have hfac : ft = fun ω ↦ Real.exp (-(a ^ 2 * (t : ℝ) / 2)) * Real.exp (a * Y t ω) := by + funext ω + change Real.exp (a * Y t ω - a ^ 2 * (t : ℝ) / 2) + = Real.exp (-(a ^ 2 * (t : ℝ) / 2)) * Real.exp (a * Y t ω) + rw [show a * Y t ω - a ^ 2 * (t : ℝ) / 2 = -(a ^ 2 * (t : ℝ) / 2) + a * Y t ω from by ring, + Real.exp_add] + rw [hfac]; exact (integrable_expY h a htT).const_mul _ + have hprod : (fun ω ↦ gs ω * ft ω) = fun ω ↦ Real.exp (a * (Y t ω - Y s ω)) := by + funext ω; rw [hgsdef, hftdef, ← Real.exp_add]; congr 1; ring + have hprod_int : Integrable (fun ω ↦ gs ω * ft ω) Q := by + rw [hprod] + refine (integrable_exp_mul_exp ((h.measurable t).const_mul a) ((h.measurable s).const_mul (-a)) + (by simpa only [mul_assoc] using integrable_expY h (2 * a) htT) + (by simpa only [mul_assoc] using integrable_expY h (2 * -a) (hst.trans htT))).congr ?_ + filter_upwards with ω + rw [← Real.exp_add] + congr 1 + ring + have hpull := condExp_mul_of_stronglyMeasurable_left (m := (𝓕 s : MeasurableSpace Ω)) + hgs_sm hprod_int hft_int + have hcond := condExp_expY h a hst htT + have hint_eq : (fun ω ↦ Real.exp (a * (Y t ω - Y s ω))) = gs * ft := hprod.symm + rw [hint_eq] + filter_upwards [hpull, hcond] with ω hp hc + rw [hp, Pi.mul_apply, + show (Q[ft | 𝓕 s]) ω = Real.exp (a * Y s ω - a ^ 2 * (s : ℝ) / 2) from hc, + hgsdef, ← Real.exp_add] + congr 1; ring + +/-- **Unconditional `Q`-MGF of the increment.** `𝔼_Q[exp(a·(Y_t − Y_s))] = exp(½a²(t−s))` — the +tower property on the deterministic conditional MGF `IsExpQMartingale.condExp_exp_increment`. -/ +private theorem Y_increment_mgf (h : IsExpQMartingale Q 𝓕 Y T) (a : ℝ) {s t : ℝ≥0} (hst : s ≤ t) + (htT : t ≤ T) : + ∫ ω, Real.exp (a * (Y t ω - Y s ω)) ∂Q = Real.exp (a ^ 2 * ((t : ℝ) - (s : ℝ)) / 2) := by + rw [← integral_condExp (𝓕.le s), integral_congr_ae (h.condExp_exp_increment a hst htT), + integral_const, show Q.real Set.univ = 1 from by simp, one_smul] + +/-- **Increment law.** `Q.map (Y_t − Y_s) = N(0, t−s)`: the unconditional increment MGF +(`Y_increment_mgf`) is the Gaussian one. -/ +theorem increment_map_eq_gaussianReal_of_expMartingale (h : IsExpQMartingale Q 𝓕 Y T) {s t : ℝ≥0} + (hst : s ≤ t) (htT : t ≤ T) : + Q.map (fun ω ↦ Y t ω - Y s ω) = gaussianReal 0 (t - s) := by + refine map_eq_gaussianReal_of_mgf ((h.measurable t).sub (h.measurable s)).aemeasurable + fun a ↦ (Y_increment_mgf h a hst htT).trans ?_ + rw [NNReal.coe_sub hst] + congr 1 + ring + +/-- **`Q`-integrability of the increment exponential.** `exp(c·(Y_t − Y_s))` is `Q`-integrable — +its law is `N(0,t−s)`. -/ +private theorem integrable_exp_Y_increment (h : IsExpQMartingale Q 𝓕 Y T) (c : ℝ) {s t : ℝ≥0} + (hst : s ≤ t) (htT : t ≤ T) : + Integrable (fun ω ↦ Real.exp (c * (Y t ω - Y s ω))) Q := by + have hincmeas : Measurable fun ω ↦ Y t ω - Y s ω := (h.measurable t).sub (h.measurable s) + rw [show (fun ω ↦ Real.exp (c * (Y t ω - Y s ω))) + = (fun x ↦ Real.exp (c * x)) ∘ (fun ω ↦ Y t ω - Y s ω) from rfl, + ← integrable_map_measure (by fun_prop) hincmeas.aemeasurable, + increment_map_eq_gaussianReal_of_expMartingale h hst htT] + exact integrable_exp_mul_gaussianReal c + +/-! ### Independence of any number of increments -/ + +/-- **Joint `Q`-MGF of successive increments.** For a monotone sequence of times `t` in `[0,T]` and +reals `a`, `exp(∑_{k constructor <;> simp + | succ n ih => + have htn : t n ≤ t (n + 1) := ht (Nat.le_add_right n 1) + -- the first `n` increments are `𝓕_{t_n}`-measurable + have hS : StronglyMeasurable[(𝓕 (t n) : MeasurableSpace Ω)] + (fun ω ↦ ∑ k ∈ Finset.range n, a k * (Y (t (k + 1)) ω - Y (t k) ω)) := + Finset.stronglyMeasurable_fun_sum _ fun k hk ↦ by + have hk : k + 1 ≤ n := Finset.mem_range.mp hk + exact ((h.adapted.stronglyMeasurable_le (ht hk)).sub + (h.adapted.stronglyMeasurable_le (ht (Nat.le_of_succ_le hk)))).const_mul (a k) + set e1 : Ω → ℝ := fun ω ↦ Real.exp (∑ k ∈ Finset.range n, a k * (Y (t (k + 1)) ω - Y (t k) ω)) + set e2 : Ω → ℝ := fun ω ↦ Real.exp (a n * (Y (t (n + 1)) ω - Y (t n) ω)) + have he1 : StronglyMeasurable[(𝓕 (t n) : MeasurableSpace Ω)] e1 := + Real.continuous_exp.comp_stronglyMeasurable hS + have he2 : Integrable e2 Q := integrable_exp_Y_increment h (a n) htn (htT _) + have h12 : Integrable (e1 * e2) Q := + integrable_exp_mul_exp (hS.mono (𝓕.le (t n))).measurable + (((h.measurable (t (n + 1))).sub (h.measurable (t n))).const_mul (a n)) + (by simpa only [Finset.mul_sum, mul_assoc] using (ih fun k ↦ 2 * a k).1) + (by simpa only [mul_assoc] using integrable_exp_Y_increment h (2 * a n) htn (htT _)) + rw [show (fun ω ↦ Real.exp (∑ k ∈ Finset.range (n + 1), a k * (Y (t (k + 1)) ω - Y (t k) ω))) + = e1 * e2 from funext fun ω ↦ by + simp only [e1, e2, Pi.mul_apply] + rw [Finset.sum_range_succ, Real.exp_add]] + refine ⟨h12, ?_⟩ + calc ∫ ω, (e1 * e2) ω ∂Q + = ∫ ω, (Q[e1 * e2 | 𝓕 (t n)]) ω ∂Q := (integral_condExp (𝓕.le (t n))).symm + _ = ∫ ω, e1 ω * Real.exp (a n ^ 2 * ((t (n + 1) : ℝ) - (t n : ℝ)) / 2) ∂Q := by + refine integral_congr_ae ?_ + filter_upwards [condExp_mul_of_stronglyMeasurable_left + (m := (𝓕 (t n) : MeasurableSpace Ω)) he1 h12 he2, + h.condExp_exp_increment (a n) htn (htT (n + 1))] with ω hp hc + rw [hp, Pi.mul_apply] + exact congrArg (e1 ω * ·) hc + _ = (∫ ω, e1 ω ∂Q) * Real.exp (a n ^ 2 * ((t (n + 1) : ℝ) - (t n : ℝ)) / 2) := + integral_mul_const _ _ + _ = ∏ k ∈ Finset.range (n + 1), Real.exp (a k ^ 2 * ((t (k + 1) : ℝ) - (t k : ℝ)) / 2) := by + rw [Finset.prod_range_succ] + exact congrArg (· * _) (ih a).2 + +/-- **Linear combinations of successive increments are Gaussian under `Q`.** For a monotone +sequence of times in `[0,T]` and reals `c`, `∑_{k rfl + | succ n ih => + change simpleDoleansExp (X := X) s d n 0 ω * cellExp (X := X) (s n) (s (n + 1)) (d n) 0 ω = 1 + rw [ih, cellExp_zero, mul_one] + +/-- The simple Doléans exponential is strictly positive (a product of exponentials). -/ +lemma simpleDoleansExp_pos (s : ℕ → ℝ≥0) (d : ℕ → Ω → ℝ) (N : ℕ) (t : ℝ≥0) (ω : Ω) : + 0 < simpleDoleansExp (X := X) s d N t ω := by + induction N with + | zero => exact one_pos + | succ n ih => + change 0 < simpleDoleansExp (X := X) s d n t ω * cellExp (X := X) (s n) (s (n + 1)) (d n) t ω + exact mul_pos ih (Real.exp_pos _) + +/-- **The simple (piecewise-constant adapted) drift** `∑_{i simp [simpleDoleansExp] + | succ n ih => + change simpleDoleansExp (X := X) s d n t ω * cellExp (X := X) (s n) (s (n + 1)) (d n) t ω = _ + rw [ih, cellExp, ← Real.exp_add, Finset.sum_range_succ] + +/-- **The simple Girsanov spine.** `Z_t · exp(a·B^θ_t − ½a²t) = exp(a·X_0) · E^{a−c}_t`, where the +density `Z = E^{−c}` and the tilted density `E^{a−c}` are simple Doléans exponentials, and +`B^θ_t = X_t + simpleDrift_t`. This is the "`Z·D` is another exponential density" trick for simple +θ: the per-cell exponents `(−c_i)ΔX_i − ½c_i²Δτ_i` and `a·ΔX_i + a·c_i·Δτ_i − ½a²Δτ_i` combine to +`(a−c_i)ΔX_i − ½(a−c_i)²Δτ_i`, the `a−c` cell. Needs the partition to cover `[0,t]` +(`s_0 = 0`, `t ≤ T ≤ s_N`), so the increments telescope to `X_t − X_0` and `t`. Combined with +`X_0 = 0` a.e. it gives `Z·D =ᵐ E^{a−c}`. -/ +lemma simple_spine (s : ℕ → ℝ≥0) (hs0 : s 0 = 0) (c : ℕ → Ω → ℝ) (a : ℝ) (N : ℕ) + {t T : ℝ≥0} (htT : t ≤ T) (hNT : T ≤ s N) (ω : Ω) : + simpleDoleansExp (X := X) s (fun i ω ↦ -(c i ω)) N t ω + * Real.exp (a * (X t ω + simpleDrift s c N t ω) - a ^ 2 * (t : ℝ) / 2) + = Real.exp (a * X 0 ω) + * simpleDoleansExp (X := X) s (fun i ω ↦ a - c i ω) N t ω := by + rw [simpleDoleansExp_eq_exp_sum, simpleDoleansExp_eq_exp_sum, ← Real.exp_add, ← Real.exp_add] + congr 1 + have htN : min (s N) t = t := min_eq_right (htT.trans hNT) + have h0t : min (s 0) t = 0 := by rw [hs0]; exact min_eq_left (zero_le : (0 : ℝ≥0) ≤ t) + have hβX : ∑ i ∈ Finset.range N, (X (min (s (i + 1)) t) ω - X (min (s i) t) ω) + = X t ω - X 0 ω := by + rw [Finset.sum_range_sub (fun i ↦ X (min (s i) t) ω) N, htN, h0t] + have hβτ : ∑ i ∈ Finset.range N, + (NNReal.toReal (min (s (i + 1)) t) - NNReal.toReal (min (s i) t)) = (t : ℝ) := by + rw [Finset.sum_range_sub (fun i ↦ NNReal.toReal (min (s i) t)) N, htN, h0t]; simp + have key : + (∑ i ∈ Finset.range N, + ((a - c i ω) * (X (min (s (i + 1)) t) ω - X (min (s i) t) ω) + - (a - c i ω) ^ 2 + * (NNReal.toReal (min (s (i + 1)) t) - NNReal.toReal (min (s i) t)) / 2)) + - (∑ i ∈ Finset.range N, + ((-(c i ω)) * (X (min (s (i + 1)) t) ω - X (min (s i) t) ω) + - (-(c i ω)) ^ 2 + * (NNReal.toReal (min (s (i + 1)) t) - NNReal.toReal (min (s i) t)) / 2)) + = a * (X t ω - X 0 ω) + a * simpleDrift s c N t ω - a ^ 2 * (t : ℝ) / 2 := by + rw [← Finset.sum_sub_distrib, + Finset.sum_congr rfl (fun i _ ↦ show + ((a - c i ω) * (X (min (s (i + 1)) t) ω - X (min (s i) t) ω) + - (a - c i ω) ^ 2 + * (NNReal.toReal (min (s (i + 1)) t) - NNReal.toReal (min (s i) t)) / 2) + - ((-(c i ω)) * (X (min (s (i + 1)) t) ω - X (min (s i) t) ω) + - (-(c i ω)) ^ 2 + * (NNReal.toReal (min (s (i + 1)) t) - NNReal.toReal (min (s i) t)) / 2) + = a * (X (min (s (i + 1)) t) ω - X (min (s i) t) ω) + + a * (c i ω * (NNReal.toReal (min (s (i + 1)) t) - NNReal.toReal (min (s i) t))) + - a ^ 2 / 2 * (NNReal.toReal (min (s (i + 1)) t) - NNReal.toReal (min (s i) t)) + from by ring), + Finset.sum_sub_distrib, Finset.sum_add_distrib, + ← Finset.mul_sum, ← Finset.mul_sum, ← Finset.mul_sum, hβX, hβτ] + simp only [simpleDrift]; ring + linear_combination -key + +variable {P : Measure Ω} [IsProbabilityMeasure P] {𝓕 : Filtration ℝ≥0 mΩ} + [SigmaFiniteFiltration P 𝓕] [hX : IsFilteredPreBrownian X 𝓕 P] + +include hX in +/-- **Unit `P`-mean of the density.** `∫ Z_T dP = 1`: the martingale property equates the mean at +`T` with the mean at `0`, where `Z_0 = 1`. -/ +theorem simpleDoleansExp_integral_eq_one (s : ℕ → ℝ≥0) (hs : Monotone s) (d : ℕ → Ω → ℝ) + (hd : ∀ i, StronglyMeasurable[(𝓕 (s i) : MeasurableSpace Ω)] (d i)) {K : ℝ} + (hd_bdd : ∀ i ω, |d i ω| ≤ K) (N : ℕ) (T : ℝ≥0) : + ∫ ω, simpleDoleansExp (X := X) s d N T ω ∂P = 1 := by + have hmart := simpleDoleansExp_isMartingale (X := X) (P := P) s hs d hd hd_bdd N + have hmean := + hmart.setIntegral_eq (i := 0) (j := T) (zero_le : (0:ℝ≥0) ≤ T) (s := Set.univ) + MeasurableSet.univ + simp only [Measure.restrict_univ] at hmean + calc ∫ ω, simpleDoleansExp (X := X) s d N T ω ∂P + = ∫ ω, simpleDoleansExp (X := X) s d N 0 ω ∂P := hmean.symm + _ = ∫ _, (1 : ℝ) ∂P := + integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ simpleDoleansExp_zero s d N ω) + _ = 1 := by simp + +include hX in +/-- **The simple Girsanov measure is a probability measure.** `Q = P.withDensity Z_T` with the +positive, unit-mean simple Doléans density `Z_T`. -/ +theorem simpleGirsanovMeasure_isProbabilityMeasure (s : ℕ → ℝ≥0) (hs : Monotone s) (d : ℕ → Ω → ℝ) + (hd : ∀ i, StronglyMeasurable[(𝓕 (s i) : MeasurableSpace Ω)] (d i)) {K : ℝ} + (hd_bdd : ∀ i ω, |d i ω| ≤ K) (N : ℕ) (T : ℝ≥0) : + IsProbabilityMeasure + (P.withDensity fun ω ↦ ENNReal.ofReal (simpleDoleansExp (X := X) s d N T ω)) := by + have hmart := simpleDoleansExp_isMartingale (X := X) (P := P) s hs d hd hd_bdd N + exact (isEquivProbMeasure_withDensity P (fun ω ↦ simpleDoleansExp_pos s d N T ω) + (hmart.integrable T) (simpleDoleansExp_integral_eq_one s hs d hd hd_bdd N T)).isProb + +/-- **Adaptedness of the simple drift.** `simpleDrift s c N u` is `𝓕_u`-measurable when the +multipliers are adapted (`c i` is `𝓕_{s i}`-measurable): each cell contributes +`c_i · (s_{i+1}∧u − s_i∧u)`, and either `s_i ≤ u` (so `c_i` is `𝓕_u`-measurable) or `u ≤ s_i` +(so the clamped interval length is `0`). -/ +lemma stronglyMeasurable_simpleDrift {s : ℕ → ℝ≥0} (hs : Monotone s) {c : ℕ → Ω → ℝ} + (hc : ∀ i, StronglyMeasurable[(𝓕 (s i) : MeasurableSpace Ω)] (c i)) (N : ℕ) (u : ℝ≥0) : + StronglyMeasurable[(𝓕 u : MeasurableSpace Ω)] (fun ω ↦ simpleDrift s c N u ω) := by + have hfun : (fun ω ↦ simpleDrift s c N u ω) + = ∑ i ∈ Finset.range N, + (fun ω ↦ c i ω * (NNReal.toReal (min (s (i + 1)) u) - NNReal.toReal (min (s i) u))) := by + funext ω; simp only [simpleDrift, Finset.sum_apply] + rw [hfun] + apply Finset.stronglyMeasurable_sum + intro i _ + rcases le_total (s i) u with hiu | hui + · exact ((hc i).mono (𝓕.mono hiu)).mul_const _ + · have hτ : NNReal.toReal (min (s (i + 1)) u) - NNReal.toReal (min (s i) u) = 0 := by + rw [min_eq_right (hui.trans (hs (Nat.le_succ i))), min_eq_right hui]; ring + simp only [hτ, mul_zero] + exact stronglyMeasurable_const + +omit [IsProbabilityMeasure P] [SigmaFiniteFiltration P 𝓕] in +include hX in +/-- The pre-Brownian motion starts at `0` a.e.: `X_0` has law `𝒩(0,0) = δ_0`. -/ +theorem X0_ae_eq_zero : ∀ᵐ ω ∂P, X 0 ω = 0 := by + have hmeasX0 : Measurable (X 0) := ((hX.stronglyAdapted 0).mono (𝓕.le 0)).measurable + have hmap := Measure.map_apply (μ := P) hmeasX0 (measurableSet_singleton (0 : ℝ)).compl + rw [(hX.hasLaw_eval 0).map_eq, gaussianReal_zero_var, + Measure.dirac_apply' _ (measurableSet_singleton (0 : ℝ)).compl] at hmap + have hpre : X 0 ⁻¹' {(0 : ℝ)}ᶜ = {ω | X 0 ω ≠ 0} := by ext ω; simp [Set.mem_preimage] + rw [hpre] at hmap + exact ae_iff.mpr (by simpa using hmap.symm) + +omit [IsProbabilityMeasure P] [SigmaFiniteFiltration P 𝓕] in +include hX in +/-- **The simple Girsanov spine, a.e. form.** For a partition covering `[0,t]` (`s_0 = 0`, +`t ≤ T ≤ s_N`), the product of the density `Z = E^{−c}` and the drift-corrected exponential +`exp(a·B^θ_t − ½a²t)` is a.e. equal to the tilted simple Doléans exponential `E^{a−c}_t` — because +`X_0 = 0` a.e. `P` kills the `exp(a·X_0)` factor of `simple_spine`. This is the "`Z·D` is another +exponential density" identity that will feed the Bayes change-of-measure engine, exactly as +`Wald(−θ)·Wald(a)` collapses to `Wald(a−θ)` in the constant-θ file. -/ +theorem simple_spine_ae (s : ℕ → ℝ≥0) (hs0 : s 0 = 0) (c : ℕ → Ω → ℝ) (a : ℝ) (N : ℕ) + {t T : ℝ≥0} (htT : t ≤ T) (hNT : T ≤ s N) : + (fun ω ↦ simpleDoleansExp (X := X) s (fun i ω ↦ -(c i ω)) N t ω + * Real.exp (a * (X t ω + simpleDrift s c N t ω) - a ^ 2 * (t : ℝ) / 2)) + =ᵐ[P] fun ω ↦ simpleDoleansExp (X := X) s (fun i ω ↦ a - c i ω) N t ω := by + filter_upwards [X0_ae_eq_zero (X := X) (𝓕 := 𝓕)] with ω hω + rw [simple_spine s hs0 c a N htT hNT ω, hω, mul_zero, Real.exp_zero, one_mul] + +include hX in +/-- **Mixed-time integrability for the Bayes engine.** For `u ≤ T ≤ s_N`, the product +`exp(a·B^θ_u − ½a²u) · Z_T` (with density `Z = E^{−c}`) is `P`-integrable. Both factors are in +`L²(P)`: the drift-corrected exponential by the Gaussian MGF of `X_u` (the drift is bounded by +`K·u`), and the density because `Z_T² = E^{−2c}_T · exp(∑ c_i²Δτ_i)` with `∑ c_i²Δτ_i ≤ K²T`, an +integrable martingale times a bounded factor. Hölder (`MemLp.mul`, `L²·L² ⊆ L¹`) closes it. -/ +theorem integrable_expBthetaSimple_mul_density (s : ℕ → ℝ≥0) (hs : Monotone s) (hs0 : s 0 = 0) + (c : ℕ → Ω → ℝ) (hc : ∀ i, StronglyMeasurable[(𝓕 (s i) : MeasurableSpace Ω)] (c i)) + {K : ℝ} (hc_bdd : ∀ i ω, |c i ω| ≤ K) (a : ℝ) (N : ℕ) {u T : ℝ≥0} (huT : u ≤ T) + (hNT : T ≤ s N) : + Integrable (fun ω ↦ + Real.exp (a * (X u ω + simpleDrift s c N u ω) - a ^ 2 * (u : ℝ) / 2) + * simpleDoleansExp (X := X) s (fun i ω ↦ -(c i ω)) N T ω) P := by + have hmeasX : ∀ v, Measurable (X v) := fun v ↦ ((hX.stronglyAdapted v).mono (𝓕.le v)).measurable + have hDsm : StronglyMeasurable[(𝓕 u : MeasurableSpace Ω)] + (fun ω ↦ Real.exp (a * (X u ω + simpleDrift s c N u ω) - a ^ 2 * (u : ℝ) / 2)) := by + have hcont : Continuous fun x : ℝ ↦ a * x - a ^ 2 * (u : ℝ) / 2 := by fun_prop + exact Real.continuous_exp.comp_stronglyMeasurable (hcont.comp_stronglyMeasurable + ((hX.stronglyAdapted u).add (stronglyMeasurable_simpleDrift hs hc N u))) + have hDmeas : Measurable + (fun ω ↦ Real.exp (a * (X u ω + simpleDrift s c N u ω) - a ^ 2 * (u : ℝ) / 2)) := + (hDsm.mono (𝓕.le u)).measurable + -- density multipliers `−c` and `−2c` are adapted and bounded + have hdneg : ∀ i, StronglyMeasurable[(𝓕 (s i) : MeasurableSpace Ω)] (fun ω ↦ -(c i ω)) := + fun i ↦ (hc i).neg + have hbneg : ∀ i ω, |(-(c i ω))| ≤ K := fun i ω ↦ by rw [abs_neg]; exact hc_bdd i ω + have hd2 : ∀ i, StronglyMeasurable[(𝓕 (s i) : MeasurableSpace Ω)] (fun ω ↦ -(2 * c i ω)) := + fun i ↦ ((hc i).const_mul 2).neg + have hb2 : ∀ i ω, |(-(2 * c i ω))| ≤ 2 * K := fun i ω ↦ by + rw [abs_neg, abs_mul, abs_of_nonneg (by norm_num : (0 : ℝ) ≤ 2)] + exact mul_le_mul_of_nonneg_left (hc_bdd i ω) (by norm_num) + have hZmeasT : Measurable (fun ω ↦ simpleDoleansExp (X := X) s (fun i ω ↦ -(c i ω)) N T ω) := + (((simpleDoleansExp_isMartingale (X := X) (P := P) s hs _ hdneg hbneg N).1 T).mono + (𝓕.le T)).measurable + -- `D_u ∈ L²`: Gaussian MGF of `X_u`, drift bounded + have hDu2 : MemLp (fun ω ↦ + Real.exp (a * (X u ω + simpleDrift s c N u ω) - a ^ 2 * (u : ℝ) / 2)) 2 P := by + rw [memLp_two_iff_integrable_sq hDmeas.aestronglyMeasurable] + refine Integrable.mono' + (g := fun ω ↦ Real.exp (2 * |a| * K * (T : ℝ)) * Real.exp (2 * a * X u ω)) + (((hX.hasLaw_eval u).integrable_fun_comp + (integrable_exp_mul_gaussianReal (2 * a))).const_mul _) + (hDmeas.pow_const 2).aestronglyMeasurable (Filter.Eventually.of_forall fun ω ↦ ?_) + have hK0 : (0 : ℝ) ≤ K := (abs_nonneg (c 0 ω)).trans (hc_bdd 0 ω) + have hdrift := simpleDrift_abs_le hs hs0 hc_bdd N (huT.trans hNT) ω + rw [Real.norm_of_nonneg (sq_nonneg _), pow_two, ← Real.exp_add, ← Real.exp_add] + refine Real.exp_le_exp.mpr ?_ + have h1 : a * simpleDrift s c N u ω ≤ |a| * (K * (u : ℝ)) := + (le_abs_self _).trans (by rw [abs_mul]; exact mul_le_mul_of_nonneg_left hdrift (abs_nonneg a)) + have h2 : |a| * (K * (u : ℝ)) ≤ |a| * (K * (T : ℝ)) := + mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left (by exact_mod_cast huT) hK0) (abs_nonneg a) + simp only [mul_add] + nlinarith [h1, h2, mul_nonneg (sq_nonneg a) (NNReal.coe_nonneg u)] + -- `Z_T ∈ L²`: `Z_T² = E^{−2c}_T · exp(∑ c²Δτ) ≤ exp(K²T)·E^{−2c}_T` + have hZT2 : MemLp (fun ω ↦ simpleDoleansExp (X := X) s (fun i ω ↦ -(c i ω)) N T ω) 2 P := by + rw [memLp_two_iff_integrable_sq hZmeasT.aestronglyMeasurable] + have hZ2c_int : Integrable + (fun ω ↦ simpleDoleansExp (X := X) s (fun i ω ↦ -(2 * c i ω)) N T ω) P := + (simpleDoleansExp_isMartingale (X := X) (P := P) s hs _ hd2 hb2 N).integrable T + refine Integrable.mono' + (g := fun ω ↦ Real.exp (K ^ 2 * (T : ℝ)) + * simpleDoleansExp (X := X) s (fun i ω ↦ -(2 * c i ω)) N T ω) + (hZ2c_int.const_mul _) (hZmeasT.pow_const 2).aestronglyMeasurable + (Filter.Eventually.of_forall fun ω ↦ ?_) + rw [Real.norm_of_nonneg (sq_nonneg _)] + have hZsq_eq : (simpleDoleansExp (X := X) s (fun i ω ↦ -(c i ω)) N T ω) ^ 2 + = simpleDoleansExp (X := X) s (fun i ω ↦ -(2 * c i ω)) N T ω + * Real.exp (∑ i ∈ Finset.range N, (c i ω) ^ 2 + * (NNReal.toReal (min (s (i + 1)) T) - NNReal.toReal (min (s i) T))) := by + rw [simpleDoleansExp_eq_exp_sum, simpleDoleansExp_eq_exp_sum, pow_two, ← Real.exp_add, + ← Real.exp_add] + congr 1 + rw [← Finset.sum_add_distrib, ← Finset.sum_add_distrib] + exact Finset.sum_congr rfl (fun i _ ↦ by ring) + rw [hZsq_eq] + have hSumBnd : ∑ i ∈ Finset.range N, (c i ω) ^ 2 + * (NNReal.toReal (min (s (i + 1)) T) - NNReal.toReal (min (s i) T)) ≤ K ^ 2 * (T : ℝ) := by + rw [← simpleTau_sum hs0 N hNT, Finset.mul_sum] + refine Finset.sum_le_sum fun i _ ↦ mul_le_mul_of_nonneg_right ?_ (simpleTau_nonneg hs i T) + nlinarith [(abs_le.mp (hc_bdd i ω)).1, (abs_le.mp (hc_bdd i ω)).2] + rw [mul_comm (Real.exp (K ^ 2 * (T : ℝ)))] + exact mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr hSumBnd) + (simpleDoleansExp_pos s _ N T ω).le + exact (memLp_one_iff_integrable.mp (hZT2.mul hDu2)).congr + (Filter.Eventually.of_forall fun ω ↦ mul_comm _ _) + +include hX in +/-- **The simple-θ drift-corrected process, packaged as exponential-martingale data.** For a +partition covering `[0,T]` (`s_0 = 0`, `T ≤ s_N`) with bounded adapted multipliers `c`, the +drift-corrected process `B^θ_u = X_u + simpleDrift_u` is `𝓕`-adapted, starts at `0` a.e. under +`Q = P.withDensity(E^{−c}_T)`, and for every `a` the exponential `exp(a·B^θ − ½a²·)` is a +`Q`-martingale on `[0,T]`. The martingale field feeds the Bayes engine (`Z = E^{−c}` and +`Z·D =ᵐ E^{a−c}`, the α2 martingale): `∫_A D_u dQ = ∫_A Z_u D_u dP` (mixed-time integrability from +`integrable_expBthetaSimple_mul_density`), then `Z_u D_u =ᵐ E^{a−c}_u` (`simple_spine_ae`) turns the +`Q`-martingale identity into the `P`-martingale identity of `E^{a−c}`. -/ +theorem isExpQMartingale_BthetaSimple (s : ℕ → ℝ≥0) (hs : Monotone s) (hs0 : s 0 = 0) + (c : ℕ → Ω → ℝ) (hc : ∀ i, StronglyMeasurable[(𝓕 (s i) : MeasurableSpace Ω)] (c i)) {K : ℝ} + (hc_bdd : ∀ i ω, |c i ω| ≤ K) (N : ℕ) {T : ℝ≥0} (hNT : T ≤ s N) : + IsExpQMartingale + (P.withDensity fun ω ↦ + ENNReal.ofReal (simpleDoleansExp (X := X) s (fun i ω ↦ -(c i ω)) N T ω)) + 𝓕 (fun u ω ↦ X u ω + simpleDrift s c N u ω) T := by + have hdneg : ∀ i, StronglyMeasurable[(𝓕 (s i) : MeasurableSpace Ω)] (fun ω ↦ -(c i ω)) := + fun i ↦ (hc i).neg + have hbneg : ∀ i ω, |(-(c i ω))| ≤ K := fun i ω ↦ by rw [abs_neg]; exact hc_bdd i ω + have hZmart : Martingale (fun u ω ↦ simpleDoleansExp (X := X) s (fun i ω ↦ -(c i ω)) N u ω) 𝓕 P := + simpleDoleansExp_isMartingale (X := X) s hs _ hdneg hbneg N + have hZmeasT : Measurable (fun ω ↦ simpleDoleansExp (X := X) s (fun i ω ↦ -(c i ω)) N T ω) := + ((hZmart.1 T).mono (𝓕.le T)).measurable + have hZpos : ∀ ω, 0 ≤ simpleDoleansExp (X := X) s (fun i ω ↦ -(c i ω)) N T ω := + fun ω ↦ (simpleDoleansExp_pos s _ N T ω).le + refine ⟨fun u ↦ (hX.stronglyAdapted u).add (stronglyMeasurable_simpleDrift hs hc N u), ?_, ?_⟩ + · -- zero start: `X_0 = 0` a.e. `Q` (`Q ≪ P`), `simpleDrift_0 = 0` + have hQP : (P.withDensity fun ω ↦ + ENNReal.ofReal (simpleDoleansExp (X := X) s (fun i ω ↦ -(c i ω)) N T ω)) ≪ P := + withDensity_absolutelyContinuous _ _ + filter_upwards [hQP.ae_le (X0_ae_eq_zero (X := X) (𝓕 := 𝓕))] with ω hω + simp [hω, simpleDrift_zero] + · -- martingale field via the Bayes `[0,T]` change-of-measure engine: `Z = E^{−c}`, the drift- + -- corrected exponential `D`, and `M = E^{a−c}` with `Z·D =ᵐ M` on `[0,T]` (`simple_spine_ae`). + intro a s' t' hst' ht'T A hA + have hEsm : ∀ i, StronglyMeasurable[(𝓕 (s i) : MeasurableSpace Ω)] (fun ω ↦ a - c i ω) := + fun i ↦ stronglyMeasurable_const.sub (hc i) + have hEb : ∀ i ω, |a - c i ω| ≤ |a| + K := fun i ω ↦ by + rw [abs_le]; obtain ⟨h1, h2⟩ := abs_le.mp (hc_bdd i ω) + refine ⟨?_, ?_⟩ <;> nlinarith [neg_abs_le a, le_abs_self a] + have hEmart : + Martingale (fun u ω ↦ simpleDoleansExp (X := X) s (fun i ω ↦ a - c i ω) N u ω) 𝓕 P := + simpleDoleansExp_isMartingale (X := X) s hs _ hEsm hEb N + have hDsm : ∀ u, StronglyMeasurable[(𝓕 u : MeasurableSpace Ω)] + (fun ω ↦ Real.exp (a * (X u ω + simpleDrift s c N u ω) - a ^ 2 * (u : ℝ) / 2)) := by + intro u + have hcont : Continuous fun x : ℝ ↦ a * x - a ^ 2 * (u : ℝ) / 2 := by fun_prop + exact Real.continuous_exp.comp_stronglyMeasurable (hcont.comp_stronglyMeasurable + ((hX.stronglyAdapted u).add (stronglyMeasurable_simpleDrift hs hc N u))) + exact changeOfMeasure_setIntegral_eq_of_ae_martingale T hZmeasT hZpos hDsm hZmart hEmart + (fun u huT ↦ simple_spine_ae (𝓕 := 𝓕) s hs0 c a N huT hNT) + (fun u huT ↦ integrable_expBthetaSimple_mul_density s hs hs0 c hc hc_bdd a N huT hNT) + hst' ht'T hA + +include hX in +/-- **Simple (piecewise-constant adapted) distributional Girsanov: the increments of `B^θ` under +`Q`.** For a partition covering `[0,T]` (`s_0 = 0`, `T ≤ s_N`) and bounded adapted multipliers `c`, +under `Q = P.withDensity(E^{−c}_T)` the drift-corrected process +`B^θ_t = X_t + ∑_i c_i (s_{i+1}∧t − s_i∧t)` has, on `[0,T]`: zero start, Gaussian increments +`N(0,t−s)`, and independent increments (`HasIndepIncrements`), which fix its finite-dimensional laws +on `[0,T]`; path continuity is not stated. One application of the exponential characterization +`isQBrownianMotion_of_expMartingale` to `isExpQMartingale_BthetaSimple` — no characteristic-function +chain re-derived (the whole payoff of the abstraction). This is the general bounded-*adapted*-θ +Girsanov for the simple case, strictly beyond constant θ, on the existing tower — no +adapted-integrand Itô formula. -/ +theorem Btheta_simple_isQBrownianMotion (s : ℕ → ℝ≥0) (hs : Monotone s) (hs0 : s 0 = 0) + (c : ℕ → Ω → ℝ) (hc : ∀ i, StronglyMeasurable[(𝓕 (s i) : MeasurableSpace Ω)] (c i)) {K : ℝ} + (hc_bdd : ∀ i ω, |c i ω| ≤ K) (N : ℕ) {T : ℝ≥0} (hNT : T ≤ s N) : + IsBrownianOn (P.withDensity fun ω ↦ + ENNReal.ofReal (simpleDoleansExp (X := X) s (fun i ω ↦ -(c i ω)) N T ω)) T + fun t ω ↦ X t ω + simpleDrift s c N t ω := by + have hdneg : ∀ i, StronglyMeasurable[(𝓕 (s i) : MeasurableSpace Ω)] (fun ω ↦ -(c i ω)) := + fun i ↦ (hc i).neg + have hbneg : ∀ i ω, |(-(c i ω))| ≤ K := fun i ω ↦ by rw [abs_neg]; exact hc_bdd i ω + have : IsProbabilityMeasure (P.withDensity fun ω ↦ + ENNReal.ofReal (simpleDoleansExp (X := X) s (fun i ω ↦ -(c i ω)) N T ω)) := + simpleGirsanovMeasure_isProbabilityMeasure (X := X) (𝓕 := 𝓕) s hs _ hdneg hbneg N T + exact isQBrownianMotion_of_expMartingale + (isExpQMartingale_BthetaSimple (X := X) (𝓕 := 𝓕) s hs hs0 c hc hc_bdd N hNT) + +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Girsanov/PredictableDensityGeneral.lean b/LeanPool/MathFin/Probability/Brownian/Girsanov/PredictableDensityGeneral.lean new file mode 100644 index 0000000000..728d7a299b --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Girsanov/PredictableDensityGeneral.lean @@ -0,0 +1,274 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralHorizonDense +public import Mathlib.Algebra.Ring.IsFormallyReal + +/-! # Simple processes are dense in the bracket-weighted predictable `L²` + +`ItoIntegralCLM.simpleAssemblyHorizon_denseRange` puts the simple processes densely inside +`L²(trim_T)`. The Itô integral against `M = φ●B` lives on the **weighted** space +`L²(φ²·trim_T)` instead — `φ²ds` being the bracket `d⟨M⟩` — and its characterisation as *the* +stochastic integral, as well as the passage from simple strategies to general ones, both need +density there. + +## The argument, and why it is short + +The flat density proof is a π-λ induction over the predictable rectangles, and porting it +wholesale to a second measure would duplicate its longest argument. It does not need porting. +Its core, `ItoIntegralCLM.setIntegral_eq_zero_of_orthogonal_pred`, is a statement about an +*integrable* function on `trim_T`, and the weighted problem reduces to it by moving the weight +into the integrand: if `g ∈ L²(f²·trim_T)` is orthogonal to every simple process, then + + `h := f²·g` + +is `trim_T`-integrable (`∫|h| d(trim) = ∫|g| d(f²·trim) ≤ ‖g‖·(f²·trim)(univ)^{1/2}`), and +orthogonality says exactly that `∫_R h d(trim) = 0` on every predictable rectangle `R`. The +π-λ core then gives `h = 0` a.e., and since `f²·trim_T` is carried by `{f ≠ 0}`, that is +`g = 0` a.e. for the weighted measure. + +So the weight is handled where it is cheap — inside the integrand — and the hard measure +theory is used once, unchanged. `setIntegral_eq_zero_of_orthogonal_pred` was weakened from an +`L²` class to an integrable function for exactly this call; `h` is `L¹` and generally not `L²`. + +## Main definitions + +* `simpleAssemblyOfMeasure`: the embedding of the bounded simple processes into `L²(ν)` for an + arbitrary finite measure `ν` on the predictable σ-algebra, the analogue of `simpleAssemblyHorizon` + with the trim measure replaced by `ν`. + +## Main results + +* `memLp_uncurry_of_isFiniteMeasure` — a simple process is `L²` for *any* finite predictable + measure, since `SimpleProcess.coe_bounded` bounds it uniformly. +* `isFiniteMeasure_sqWeight` — `f²·trim_T` is finite exactly because `f ∈ L²(trim_T)`. +* `inner_simpleAssemblyOfMeasure_iocSPHorizon` — the rectangle inner product, where the weight moves + from the measure into the integrand. +* `simpleAssembly_sqWeight_denseRange` — the density theorem. + +## References + +* [I. Karatzas and S. E. Shreve, *Brownian Motion and Stochastic Calculus*][KaratzasShreve1991], + 3.2.5 + +## Tags + +density of simple processes, weighted predictable L2, bracket-weighted space, +stochastic integral construction, predictable rectangles, MSC 60H05, MSC 60G07 +-/ + +@[expose] public section + +namespace MathFin +namespace PredictableDensityGeneral + +open MeasureTheory ProbabilityTheory Filter ItoIntegralCLM LpMulIsometry +open scoped NNReal ENNReal InnerProductSpace + +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-! ### A simple process is `L²` for every finite predictable measure -/ + +/-- A simple process is bounded (`SimpleProcess.coe_bounded`), so it is square-integrable +against **any** finite measure on the predictable σ-algebra — no relation to `trim_T` needed. +This is what lets the same `TBoundedSP` index the weighted space. -/ +lemma memLp_uncurry_of_isFiniteMeasure (hBmeas : ∀ t, Measurable (B t)) + (ν : @Measure (ℝ≥0 × Ω) + (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas).predictable) [IsFiniteMeasure ν] + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) : + MemLp (Function.uncurry ⇑V) 2 ν := by + obtain ⟨C, hC⟩ := V.coe_bounded + exact MemLp.of_bound V.isStronglyPredictable.aestronglyMeasurable C + (Eventually.of_forall fun z ↦ hC z.1 z.2) + +/-- **The weighted simple-process embedding**, the analogue of `simpleAssemblyHorizon` with the +trim measure replaced by an arbitrary finite predictable `ν`. -/ +noncomputable def simpleAssemblyOfMeasure (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (ν : @Measure (ℝ≥0 × Ω) + (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas).predictable) [IsFiniteMeasure ν] : + TBoundedSP T hBmeas →ₗ[ℝ] Lp ℝ 2 ν where + toFun V := (memLp_uncurry_of_isFiniteMeasure hBmeas ν V.val).toLp _ + map_add' V W := by + change (memLp_uncurry_of_isFiniteMeasure hBmeas ν ((V + W) : TBoundedSP T hBmeas).val).toLp _ + = _ + rw [Submodule.coe_add, + ← MemLp.toLp_add (memLp_uncurry_of_isFiniteMeasure hBmeas ν V.val) + (memLp_uncurry_of_isFiniteMeasure hBmeas ν W.val)] + congr 1 + exact ItoIntegralL2.uncurry_coe_add hBmeas V.val W.val + map_smul' c V := by + change (memLp_uncurry_of_isFiniteMeasure hBmeas ν ((c • V) : TBoundedSP T hBmeas).val).toLp _ + = _ + rw [Submodule.coe_smul, RingHom.id_apply, + ← MemLp.toLp_const_smul c (memLp_uncurry_of_isFiniteMeasure hBmeas ν V.val)] + congr 1 + exact ItoIntegralL2.uncurry_coe_smul hBmeas c V.val + +lemma coeFn_simpleAssemblyOfMeasure (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (ν : @Measure (ℝ≥0 × Ω) + (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas).predictable) [IsFiniteMeasure ν] + (V : TBoundedSP T hBmeas) : + ⇑(simpleAssemblyOfMeasure T hBmeas ν V) =ᵐ[ν] Function.uncurry ⇑V.val := + (memLp_uncurry_of_isFiniteMeasure hBmeas ν V.val).coeFn_toLp + +/-! ### The bracket weight -/ + +omit [IsProbabilityMeasure μ] in +/-- `f²·trim_T` is a finite measure exactly when `f ∈ L²(trim_T)`: its total mass is `‖f‖²`. -/ +lemma isFiniteMeasure_sqWeight (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + {f : ℝ≥0 × Ω → ℝ} (hfL2 : MemLp f 2 (trimMeasure (μ := μ) T hBmeas)) : + IsFiniteMeasure (sqWeight (trimMeasure (μ := μ) T hBmeas) f) := by + refine ⟨?_⟩ + have hlt : ∫⁻ z, ‖f z‖ₑ ^ 2 ∂(trimMeasure (μ := μ) T hBmeas) < ⊤ := by + have h := hfL2.eLpNorm_lt_top + rw [eLpNorm_eq_lintegral_rpow_eNorm_toReal (by norm_num) (by norm_num) + hfL2.aestronglyMeasurable] at h + have h2 : (∫⁻ z, ‖f z‖ₑ ^ ((2 : ℝ≥0∞).toReal) ∂(trimMeasure (μ := μ) T hBmeas)) ≠ ⊤ := by + intro htop + rw [htop] at h + simp [ENNReal.top_rpow_of_pos] at h + refine lt_of_le_of_ne le_top ?_ + intro htop + exact h2 (by + rw [← htop] + refine lintegral_congr fun z ↦ ?_ + rw [show ((2 : ℝ≥0∞).toReal) = ((2 : ℕ) : ℝ) by norm_num, ENNReal.rpow_natCast]) + rw [sqWeight, withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ] + exact hlt + +/-! ### Density in the bracket-weighted space -/ + +omit [IsProbabilityMeasure μ] in +/-- The inner product of the rectangle simple process against `g`, taken in the weighted +space, is a set-integral of `f²·g` against `trim_T`. This is where the weight moves from the +measure into the integrand. -/ +lemma inner_simpleAssemblyOfMeasure_iocSPHorizon (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + {f : ℝ≥0 × Ω → ℝ} + (hf : Measurable[(ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas).predictable] f) + [IsFiniteMeasure (sqWeight (trimMeasure (μ := μ) T hBmeas) f)] + {a b : ℝ≥0} (hab : a ≤ b) (hbT : b ≤ T) {F : Set Ω} + (hF : MeasurableSet[(ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas) a] F) + (g : Lp ℝ 2 (sqWeight (trimMeasure (μ := μ) T hBmeas) f)) : + ⟪simpleAssemblyOfMeasure T hBmeas (sqWeight (trimMeasure (μ := μ) T hBmeas) f) + (iocSPHorizon hBmeas hab hbT hF), g⟫_ℝ + = ∫ z in Set.Ioc a b ×ˢ F, f z ^ 2 * g z ∂(trimMeasure (μ := μ) T hBmeas) := by + set 𝓕 := ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas + let : MeasurableSpace (ℝ≥0 × Ω) := 𝓕.predictable + have hRpred : MeasurableSet (Set.Ioc a b ×ˢ F) := + MeasureTheory.measurableSet_predictable_Ioc_prod (𝓕 := 𝓕) a b hF + rw [L2.inner_def] + have h_ae : ∀ᵐ z ∂(sqWeight (trimMeasure (μ := μ) T hBmeas) f), + (⟪(simpleAssemblyOfMeasure T hBmeas (sqWeight (trimMeasure (μ := μ) T hBmeas) f) + (iocSPHorizon hBmeas hab hbT hF) : ℝ≥0 × Ω → ℝ) z, + (g : ℝ≥0 × Ω → ℝ) z⟫_ℝ : ℝ) + = (Set.Ioc a b ×ˢ F).indicator (fun z ↦ (g : ℝ≥0 × Ω → ℝ) z) z := by + filter_upwards [coeFn_simpleAssemblyOfMeasure T hBmeas + (sqWeight (trimMeasure (μ := μ) T hBmeas) f) (iocSPHorizon hBmeas hab hbT hF)] with z hz + have hSA : (simpleAssemblyOfMeasure T hBmeas (sqWeight (trimMeasure (μ := μ) T hBmeas) f) + (iocSPHorizon hBmeas hab hbT hF) : ℝ≥0 × Ω → ℝ) z + = (Set.Ioc a b ×ˢ F).indicator (fun _ ↦ (1 : ℝ)) z := by + rw [hz, uncurry_iocSPHorizon_eq hBmeas hab hbT hF] + rw [hSA] + change (g : ℝ≥0 × Ω → ℝ) z * (Set.Ioc a b ×ˢ F).indicator (fun _ ↦ (1 : ℝ)) z = _ + by_cases hz_in : z ∈ Set.Ioc a b ×ˢ F + · rw [Set.indicator_of_mem hz_in, Set.indicator_of_mem hz_in, mul_one] + · rw [Set.indicator_of_notMem hz_in, Set.indicator_of_notMem hz_in, mul_zero] + rw [integral_congr_ae h_ae, integral_indicator hRpred, setIntegral_sqWeight hf hRpred] + +/-- **Density in the bracket-weighted space.** The simple processes are dense in +`L²(f²·trim_T)`. + +The weighted problem reduces to the flat π-λ core by moving the weight into the integrand: a +`g` orthogonal to every simple process makes `h := f²·g` integrate to zero over every +predictable rectangle, `setIntegral_eq_zero_of_orthogonal_pred` promotes that to every +predictable set, and `h = 0` a.e. forces `g = 0` where `f ≠ 0` — which is `f²·trim_T`-a.e., +that measure being carried by `{f ≠ 0}`. `h` is `L¹` and generally not `L²`, which is why the +core takes an integrable function rather than an `L²` class. -/ +theorem simpleAssembly_sqWeight_denseRange (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + {f : ℝ≥0 × Ω → ℝ} + (hf : Measurable[(ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas).predictable] f) + [IsFiniteMeasure (sqWeight (trimMeasure (μ := μ) T hBmeas) f)] : + DenseRange (simpleAssemblyOfMeasure T hBmeas + (sqWeight (trimMeasure (μ := μ) T hBmeas) f)) := by + set 𝓕 := ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas + let : MeasurableSpace (ℝ≥0 × Ω) := 𝓕.predictable + suffices h_orth_bot : (LinearMap.range (simpleAssemblyOfMeasure T hBmeas + (sqWeight (trimMeasure (μ := μ) T hBmeas) f)))ᗮ = ⊥ by + rw [denseRange_iff_closure_range, + ← LinearMap.coe_range (simpleAssemblyOfMeasure T hBmeas + (sqWeight (trimMeasure (μ := μ) T hBmeas) f)), + ← Submodule.topologicalClosure_coe, + Submodule.topologicalClosure_eq_top_iff.mpr h_orth_bot, Submodule.top_coe] + rw [Submodule.eq_bot_iff] + intro g h_mem + rw [Submodule.mem_orthogonal] at h_mem + -- the weight moved into the integrand: `h` is `L¹(trim_T)`, generally not `L²` + have hgmeas : Measurable[𝓕.predictable] (g : ℝ≥0 × Ω → ℝ) := + (Lp.stronglyMeasurable g).measurable + have hh_meas : AEStronglyMeasurable (fun z ↦ f z ^ 2 * (g : ℝ≥0 × Ω → ℝ) z) + (trimMeasure (μ := μ) T hBmeas) := + (((hf.pow_const 2).mul hgmeas)).aestronglyMeasurable + have hlint : ∫⁻ z, ‖f z ^ 2 * (g : ℝ≥0 × Ω → ℝ) z‖ₑ ∂(trimMeasure (μ := μ) T hBmeas) + = ∫⁻ z, ‖(g : ℝ≥0 × Ω → ℝ) z‖ₑ ∂(sqWeight (trimMeasure (μ := μ) T hBmeas) f) := by + rw [lintegral_sqWeight hf] + refine lintegral_congr fun z ↦ ?_ + rw [eNorm_mul, eNorm_pow] + have hh_int : Integrable (fun z ↦ f z ^ 2 * (g : ℝ≥0 × Ω → ℝ) z) + (trimMeasure (μ := μ) T hBmeas) := by + refine ⟨hh_meas, ?_⟩ + rw [HasFiniteIntegral, hlint] + exact ((Lp.memLp g).integrable one_le_two).2 + -- orthogonality on every basic predictable rectangle + have h_orth : ∀ R ∈ predictableRect (mΩ := mΩ) hBmeas, + ∫ z in R, f z ^ 2 * (g : ℝ≥0 × Ω → ℝ) z ∂(trimMeasure (μ := μ) T hBmeas) = 0 := by + intro R hR + rcases hR with ⟨F₀, hF₀, rfl⟩ | ⟨a, b, _hab, F, hF, rfl⟩ + · have h_R_pred : MeasurableSet[𝓕.predictable] ({(⊥ : ℝ≥0)} ×ˢ F₀) := + MeasureTheory.measurableSet_predictable_singleton_bot_prod (𝓕 := 𝓕) hF₀ + rw [setIntegral_eq_setIntegral_inter_supp hBmeas _ _ h_R_pred] + have h_empty : ({(⊥ : ℝ≥0)} ×ˢ F₀) ∩ Set.Ioc 0 T ×ˢ (Set.univ : Set Ω) = ∅ := by + rw [Set.prod_inter_prod, + show ({(⊥ : ℝ≥0)} ∩ Set.Ioc 0 T : Set ℝ≥0) = ∅ by ext x; simp, + Set.empty_prod] + rw [h_empty, setIntegral_empty] + · have h_R_pred : MeasurableSet[𝓕.predictable] (Set.Ioc a b ×ˢ F) := + MeasureTheory.measurableSet_predictable_Ioc_prod (𝓕 := 𝓕) a b hF + rw [setIntegral_eq_setIntegral_inter_supp hBmeas _ _ h_R_pred] + have h_inter : (Set.Ioc a b ×ˢ F) ∩ (Set.Ioc 0 T ×ˢ (Set.univ : Set Ω)) + = Set.Ioc (max a 0) (min b T) ×ˢ F := by + ext ⟨t, ω⟩ + simp only [Set.mem_inter_iff, Set.mem_prod, Set.mem_Ioc, Set.mem_univ, and_true] + constructor + · rintro ⟨⟨⟨h1, h2⟩, hω⟩, ⟨h3, h4⟩⟩ + exact ⟨⟨max_lt h1 h3, le_min h2 h4⟩, hω⟩ + · rintro ⟨⟨h1, h2⟩, hω⟩ + refine ⟨⟨⟨(le_max_left _ _).trans_lt h1, h2.trans (min_le_left _ _)⟩, hω⟩, ?_⟩ + exact ⟨(le_max_right _ _).trans_lt h1, h2.trans (min_le_right _ _)⟩ + rw [h_inter, show max a 0 = a from max_eq_left bot_le] + by_cases hab' : a ≤ min b T + · have hbT' : min b T ≤ T := min_le_right _ _ + rw [← inner_simpleAssemblyOfMeasure_iocSPHorizon T hBmeas hf hab' hbT' hF g] + exact h_mem _ ⟨iocSPHorizon hBmeas hab' hbT' hF, rfl⟩ + · push Not at hab' + rw [Set.Ioc_eq_empty (not_lt.mpr hab'.le), Set.empty_prod, setIntegral_empty] + -- π-λ core, then a.e. vanishing, then transfer back across the weight + have hh0 : (fun z ↦ f z ^ 2 * (g : ℝ≥0 × Ω → ℝ) z) + =ᵐ[trimMeasure (μ := μ) T hBmeas] 0 := + hh_int.ae_eq_zero_of_forall_setIntegral_eq_zero + (fun s hs _ ↦ setIntegral_eq_zero_of_orthogonal_pred T hBmeas hh_int h_orth s hs) + refine (Lp.eq_zero_iff_ae_eq_zero (f := g)).mpr ?_ + filter_upwards [(withDensity_absolutelyContinuous + (trimMeasure (μ := μ) T hBmeas) (fun z ↦ ‖f z‖ₑ ^ 2)).ae_le hh0, + sqWeight_ae_ne_zero (ν := trimMeasure (μ := μ) T hBmeas) hf] with z hz hfz + have : f z ^ 2 ≠ 0 := pow_ne_zero 2 hfz + simpa [this] using hz + +end PredictableDensityGeneral +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Girsanov/SimpleDoleansExponential.lean b/LeanPool/MathFin/Probability/Brownian/Girsanov/SimpleDoleansExponential.lean new file mode 100644 index 0000000000..3820520070 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Girsanov/SimpleDoleansExponential.lean @@ -0,0 +1,580 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.BrownianMartingale +public import Mathlib.MeasureTheory.Order.Group.Lattice + +/-! +# The simple Doléans exponential — the martingale foundation of adapted Girsanov (Track α) + +Route-α, brick α1 (`docs/plans/2026-07-06-girsanov-track-alpha.md`). The market price +of risk `θ` of the general Girsanov theorem (`gir-thm-9.1.8`) is **adapted** (path +dependent), so the Doléans density `exp(∫θ dB − ½∫θ² ds)` has a *random* multiplier in +each partition cell. The constant-θ Wald exponential (`waldExponential_isMartingale`) +freezes each increment against a **deterministic** function of the past +(`IsFilteredPreBrownian.condExp_comp_increment_eq_const`); the adapted case needs the same +freezing against an `𝓕_r`-measurable **random** multiplier `c`. + +This file proves that genuinely new estimate: + +* `MathFin.condExp_exp_adapted_mul_increment` — + `𝔼[exp(c·(X_t − X_r)) | 𝓕_r] = exp(½ c² (t − r))` a.e., for `c` `𝓕_r`-measurable and + bounded, `r ≤ t`. + +The mechanism is the **freezing lemma**: the increment `Δ = X_t − X_r` is independent of +`𝓕_r` (`hX.indep`), so the joint law of the `𝓕_r`-measurable pair `(c, ·)` and `Δ` +factorizes (`indepFun_iff_map_prod_eq_prod_map_map`), and Fubini (`integral_prod`) freezes +`c` while the inner Gaussian MGF `∫ exp(c·z) d𝒩(0,t−r) = exp(½c²(t−r))` +(`integral_exp_mul_gaussianReal_zero`) collapses the increment. + +Everything else in Track α (the running exponential's martingale property α2, the simple-θ +Girsanov α3) reuses the constant-θ apparatus in `GirsanovConstantTheta.lean` once this +brick lands. + +## Main definitions + +* `cellExp`: the single-cell Doléans exponential over `(a, b]` with multiplier `c`, clamped to + `[0, t]`. +* `simpleDoleansExp`: the running simple Doléans exponential over the first `N` cells of a + partition `s` with multipliers `d`. + +## Main results + +* `condExp_exp_adapted_mul_increment`: the conditional MGF of a Brownian increment against a + bounded `𝓕_r`-measurable multiplier `c`. +* `condExp_expCell_eq_one`: the normalised cell factor `exp(c·(X_t − X_r) − c²(t − r)/2)` has + conditional expectation `1` given `𝓕_r`. +* `cellExp_isMartingale`: the single-cell exponential over `(a, b]` is a `P`-martingale for a + bounded `𝓕_a`-measurable multiplier. +* `mul_cellExp_isMartingale`: appending one cell to a martingale frozen after `p` gives a + martingale. +* `simpleDoleansExp_isMartingale`: for a monotone partition and uniformly bounded adapted + multipliers, the simple Doléans exponential is a `P`-martingale. + +## Tags + +Doléans exponential, Girsanov theorem, exponential martingale, freezing lemma, market price of risk, +Wald exponential, MSC 60G44, MSC 60H05, MSC 91G20 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + {𝓕 : Filtration ℝ≥0 mΩ} + +/-- **The freezing set-integral identity.** For a bounded `𝓕_r`-measurable multiplier `c` +and an increment `Δ` with law `𝒩(0,v)` independent of `𝓕_r`, and any `A ∈ 𝓕_r`, +`∫_A exp(c·Δ) = ∫_A exp(½ c² v)`. The `𝓕_r`-measurable `(c, 𝟙_A)` is independent of `Δ`, so +the joint law factorizes (`indepFun_iff_map_prod_eq_prod_map_map`) and Fubini +(`integral_prod`) freezes `c`, leaving the inner Gaussian MGF `∫ exp(c·z) d𝒩(0,v) = +exp(½c²v)` (`integral_exp_mul_gaussianReal_zero`). -/ +lemma condExp_exp_adapted_freeze_setIntegral + {c : Ω → ℝ} {r : ℝ≥0} (hc_frf : Measurable[(𝓕 r : MeasurableSpace Ω)] c) + {K : ℝ} (hK : ∀ ω, |c ω| ≤ K) + {Δ : Ω → ℝ} (hΔ_meas : Measurable Δ) {v : ℝ≥0} (hΔlaw : HasLaw Δ (gaussianReal 0 v) P) + (hindep0 : Indep (MeasurableSpace.comap Δ (borel ℝ)) (𝓕 r) P) + {A : Set Ω} (hA : MeasurableSet[(𝓕 r : MeasurableSpace Ω)] A) : + ∫ ω in A, Real.exp (c ω * Δ ω) ∂P = ∫ ω in A, Real.exp ((c ω) ^ 2 * (v : ℝ) / 2) ∂P := by + classical + have hc_meas : Measurable c := hc_frf.mono (𝓕.le r) le_rfl + have hA_mΩ : MeasurableSet A := (𝓕.le r) A hA + -- Pointwise domination of `exp(c·Δ)` by two Gaussian-MGF terms (no `0 ≤ K` needed). + have hbound : ∀ ω, Real.exp (c ω * Δ ω) + ≤ Real.exp (K * Δ ω) + Real.exp (-K * Δ ω) := by + intro ω + obtain ⟨hlo, hhi⟩ := abs_le.mp (hK ω) + rcases le_total 0 (Δ ω) with hΔ | hΔ + · exact le_add_of_le_of_nonneg (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hhi hΔ)) + (Real.exp_nonneg _) + · exact le_add_of_nonneg_of_le (Real.exp_nonneg _) + (Real.exp_le_exp.mpr (mul_le_mul_of_nonpos_right hlo hΔ)) + have hbnd_int : Integrable (fun ω ↦ Real.exp (K * Δ ω) + Real.exp (-K * Δ ω)) P := + (hΔlaw.integrable_fun_comp (integrable_exp_mul_gaussianReal K)).add + (hΔlaw.integrable_fun_comp (integrable_exp_mul_gaussianReal (-K))) + -- The `𝓕_r`-measurable pair `Y = (c, 𝟙_A)` and the coupling `F ((cc,ind),z) = ind·exp(cc·z)`. + set Y : Ω → ℝ × ℝ := fun ω ↦ (c ω, A.indicator (fun _ ↦ (1 : ℝ)) ω) with hYdef + set F : (ℝ × ℝ) × ℝ → ℝ := fun p ↦ p.1.2 * Real.exp (p.1.1 * p.2) with hFdef + have hY_meas : Measurable Y := hc_meas.prodMk (measurable_const.indicator hA_mΩ) + have hY_frf : Measurable[(𝓕 r : MeasurableSpace Ω)] Y := + hc_frf.prodMk (measurable_const.indicator hA) + have hF_meas : Measurable F := + (measurable_fst.snd).mul ((measurable_fst.fst.mul measurable_snd).exp) + -- Independence of `Y` and `Δ`, hence the joint law factorizes. + have hindepYΔ : IndepFun Y Δ P := + Indep.symm (indep_of_indep_of_le_right hindep0 hY_frf.comap_le) + have hjoint : P.map (fun ω ↦ (Y ω, Δ ω)) = (P.map Y).prod (P.map Δ) := + (indepFun_iff_map_prod_eq_prod_map_map hY_meas.aemeasurable hΔ_meas.aemeasurable).mp hindepYΔ + have hYΔ_aem : AEMeasurable (fun ω ↦ (Y ω, Δ ω)) P := (hY_meas.prodMk hΔ_meas).aemeasurable + -- `F` is integrable against the joint law (dominated by the two Gaussian-MGF terms). + have hFcomp_le : ∀ ω, ‖F (Y ω, Δ ω)‖ ≤ Real.exp (K * Δ ω) + Real.exp (-K * Δ ω) := by + intro ω + have hval : F (Y ω, Δ ω) = A.indicator (fun _ ↦ (1 : ℝ)) ω * Real.exp (c ω * Δ ω) := by + simp only [hFdef, hYdef] + rw [hval, Real.norm_eq_abs, abs_mul, abs_of_nonneg (Real.exp_nonneg _)] + by_cases hω : ω ∈ A + · rw [Set.indicator_of_mem hω]; simp only [abs_one, one_mul]; exact hbound ω + · rw [Set.indicator_apply, ite_eq_right hω, abs_zero, zero_mul]; positivity + have hFcomp_int : Integrable (fun ω ↦ F (Y ω, Δ ω)) P := + Integrable.mono' hbnd_int (hF_meas.comp (hY_meas.prodMk hΔ_meas)).aestronglyMeasurable + (Filter.Eventually.of_forall hFcomp_le) + have hF_int_prod : Integrable F ((P.map Y).prod (P.map Δ)) := by + rw [← hjoint, integrable_map_measure hF_meas.aestronglyMeasurable hYΔ_aem] + exact hFcomp_int + -- Compute the inner integral (freeze `y`, evaluate the Gaussian MGF). + have hinner : ∀ y : ℝ × ℝ, ∫ z, F (y, z) ∂(P.map Δ) + = y.2 * Real.exp (y.1 ^ 2 * (v : ℝ) / 2) := by + intro y + rw [hΔlaw.map_eq] + have : (fun z ↦ F (y, z)) = fun z ↦ y.2 * Real.exp (y.1 * z) := by funext z; rw [hFdef] + rw [this, integral_const_mul, integral_exp_mul_gaussianReal_zero] + -- Chain: setIntegral → integral of `F∘(Y,Δ)` → joint law → Fubini → back. + rw [← integral_indicator hA_mΩ, ← integral_indicator hA_mΩ] + have hLHS : (fun ω ↦ A.indicator (fun ω ↦ Real.exp (c ω * Δ ω)) ω) + = fun ω ↦ F (Y ω, Δ ω) := by + funext ω; rw [hFdef, hYdef] + by_cases hω : ω ∈ A <;> simp [hω] + have hRHS : (fun ω ↦ A.indicator (fun ω ↦ Real.exp ((c ω) ^ 2 * (v : ℝ) / 2)) ω) + = fun ω ↦ (Y ω).2 * Real.exp ((Y ω).1 ^ 2 * (v : ℝ) / 2) := by + funext ω; rw [hYdef] + by_cases hω : ω ∈ A <;> simp [hω] + rw [hLHS, hRHS] + rw [← integral_map hYΔ_aem hF_meas.aestronglyMeasurable, hjoint, + integral_prod F hF_int_prod] + rw [← integral_map hY_meas.aemeasurable + (by fun_prop : AEStronglyMeasurable + (fun y : ℝ × ℝ ↦ y.2 * Real.exp (y.1 ^ 2 * (v : ℝ) / 2)) (P.map Y))] + exact integral_congr_ae (Filter.Eventually.of_forall hinner) + +variable [SigmaFiniteFiltration P 𝓕] {X : ℝ≥0 → Ω → ℝ} + [hX : IsFilteredPreBrownian X 𝓕 P] + +/-- **Conditional MGF of a Brownian increment against a random adapted multiplier.** +For `c` `𝓕_r`-measurable and bounded, and `r ≤ t`, +`𝔼[exp(c·(X_t − X_r)) | 𝓕_r] = exp(½ c² (t − r))` a.e. + +The `𝓕_r`-measurable `c` is *frozen*: `Δ = X_t − X_r` is independent of `𝓕_r`, so the joint +law factorizes and Fubini evaluates the inner Gaussian MGF `∫ exp(c·z) d𝒩(0,t−r)`. This is +the adapted-multiplier generalization of the constant-`α` freezing inside +`waldExponential_isMartingale`. -/ +theorem condExp_exp_adapted_mul_increment + {c : Ω → ℝ} {r : ℝ≥0} (hc : StronglyMeasurable[(𝓕 r : MeasurableSpace Ω)] c) + {K : ℝ} (hK : ∀ ω, |c ω| ≤ K) {t : ℝ≥0} (hrt : r ≤ t) : + P[fun ω ↦ Real.exp (c ω * (X t ω - X r ω)) | (𝓕 r : MeasurableSpace Ω)] + =ᵐ[P] fun ω ↦ Real.exp ((c ω) ^ 2 * ((t : ℝ) - (r : ℝ)) / 2) := by + have hc_meas : Measurable c := (hc.mono (𝓕.le r)).measurable + have h_meas_diff : Measurable (fun ω ↦ X t ω - X r ω) := + (((hX.stronglyAdapted t).mono (𝓕.le t)).measurable).sub + (((hX.stronglyAdapted r).mono (𝓕.le r)).measurable) + -- The increment law, with variance `t − r`. + have hΔlaw : HasLaw (fun ω ↦ X t ω - X r ω) (gaussianReal 0 (t - r)) P := + hasLaw_increment hX.toIsPreBrownianReal hrt + have hindep0 : Indep (MeasurableSpace.comap (fun ω ↦ X t ω - X r ω) (borel ℝ)) (𝓕 r) P := + hX.indep r t hrt + -- The candidate conditional expectation `g = exp(½ c² (t−r))` is `𝓕_r`-measurable. + have hg_sm : StronglyMeasurable[(𝓕 r : MeasurableSpace Ω)] + (fun ω ↦ Real.exp ((c ω) ^ 2 * ((t : ℝ) - (r : ℝ)) / 2)) := + Real.continuous_exp.comp_stronglyMeasurable + ((((continuous_pow 2).comp_stronglyMeasurable hc).mul stronglyMeasurable_const).div + stronglyMeasurable_const) + -- Integrability of `f = exp(c·Δ)` and `g`. + have hf_int : Integrable (fun ω ↦ Real.exp (c ω * (X t ω - X r ω))) P := by + refine Integrable.mono' + ((hΔlaw.integrable_fun_comp (integrable_exp_mul_gaussianReal K)).add + (hΔlaw.integrable_fun_comp (integrable_exp_mul_gaussianReal (-K)))) + (hc_meas.mul h_meas_diff).exp.aestronglyMeasurable (Filter.Eventually.of_forall fun ω ↦ ?_) + rw [Real.norm_of_nonneg (Real.exp_nonneg _)] + obtain ⟨hlo, hhi⟩ := abs_le.mp (hK ω) + rcases le_total 0 (X t ω - X r ω) with hΔ | hΔ + · exact le_add_of_le_of_nonneg (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hhi hΔ)) + (Real.exp_nonneg _) + · exact le_add_of_nonneg_of_le (Real.exp_nonneg _) + (Real.exp_le_exp.mpr (mul_le_mul_of_nonpos_right hlo hΔ)) + have hg_int : Integrable (fun ω ↦ Real.exp ((c ω) ^ 2 * ((t : ℝ) - (r : ℝ)) / 2)) P := by + refine Integrable.mono' (integrable_const (Real.exp (K ^ 2 * ((t : ℝ) - (r : ℝ)) / 2))) + (hg_sm.mono (𝓕.le r)).aestronglyMeasurable (Filter.Eventually.of_forall fun ω ↦ ?_) + rw [Real.norm_of_nonneg (Real.exp_nonneg _)] + refine Real.exp_le_exp.mpr ?_ + have hsq : (c ω) ^ 2 ≤ K ^ 2 := by + obtain ⟨hlo, hhi⟩ := abs_le.mp (hK ω); nlinarith [abs_nonneg (c ω), hK ω] + have hnn : (0 : ℝ) ≤ (t : ℝ) - (r : ℝ) := sub_nonneg.mpr (NNReal.coe_le_coe.mpr hrt) + have := mul_le_mul_of_nonneg_right hsq hnn + linarith + -- Assemble via the set-integral characterization of conditional expectation. + refine (ae_eq_condExp_of_forall_setIntegral_eq (𝓕.le r) hf_int + (fun A _ _ ↦ hg_int.integrableOn) (fun A hA _ ↦ ?_) hg_sm.aestronglyMeasurable).symm + have hfreeze := condExp_exp_adapted_freeze_setIntegral (P := P) (𝓕 := 𝓕) hc.measurable hK + h_meas_diff hΔlaw hindep0 hA + rw [NNReal.coe_sub hrt] at hfreeze + exact hfreeze.symm + +/-- **The normalized cell factor conditionally integrates to `1`.** For `c` `𝓕_r`-measurable +bounded and `r ≤ t`, `𝔼[exp(c·(X_t − X_r) − ½ c² (t − r)) | 𝓕_r] = 1` a.e. — the +martingale-difference form of `condExp_exp_adapted_mul_increment`, obtained by pulling the +`𝓕_r`-measurable factor `exp(−½ c² (t − r))` out and collapsing with the conditional MGF. -/ +theorem condExp_expCell_eq_one {c : Ω → ℝ} {r : ℝ≥0} + (hc : StronglyMeasurable[(𝓕 r : MeasurableSpace Ω)] c) + {K : ℝ} (hK : ∀ ω, |c ω| ≤ K) {t : ℝ≥0} (hrt : r ≤ t) : + P[fun ω ↦ Real.exp (c ω * (X t ω - X r ω) - (c ω) ^ 2 * ((t : ℝ) - (r : ℝ)) / 2) | + (𝓕 r : MeasurableSpace Ω)] =ᵐ[P] fun _ ↦ (1 : ℝ) := by + have hc_meas : Measurable c := (hc.mono (𝓕.le r)).measurable + have hXt : Measurable (X t) := ((hX.stronglyAdapted t).mono (𝓕.le t)).measurable + have hXr : Measurable (X r) := ((hX.stronglyAdapted r).mono (𝓕.le r)).measurable + have h_meas_diff : Measurable (fun ω ↦ X t ω - X r ω) := hXt.sub hXr + have hΔlaw : HasLaw (fun ω ↦ X t ω - X r ω) (gaussianReal 0 (nndist (t : ℝ) (r : ℝ))) P := + hX.hasLaw_sub t r + have htr : (0 : ℝ) ≤ (t : ℝ) - (r : ℝ) := sub_nonneg.mpr (NNReal.coe_le_coe.mpr hrt) + set ft : Ω → ℝ := fun ω ↦ Real.exp (c ω * (X t ω - X r ω)) with hftdef + set gr : Ω → ℝ := fun ω ↦ Real.exp (-((c ω) ^ 2 * ((t : ℝ) - (r : ℝ)) / 2)) with hgrdef + have hgr_sm : StronglyMeasurable[(𝓕 r : MeasurableSpace Ω)] gr := + Real.continuous_exp.comp_stronglyMeasurable + ((by fun_prop : Continuous fun x : ℝ ↦ + -(x ^ 2 * ((t : ℝ) - (r : ℝ)) / 2)).comp_stronglyMeasurable + hc) + -- Domination bound reused for both `ft` and `gr·ft`. + have hbnd_int : Integrable (fun ω ↦ Real.exp (K * (X t ω - X r ω)) + + Real.exp (-K * (X t ω - X r ω))) P := + (hΔlaw.integrable_fun_comp (integrable_exp_mul_gaussianReal K)).add + (hΔlaw.integrable_fun_comp (integrable_exp_mul_gaussianReal (-K))) + have hft_int : Integrable ft P := by + refine Integrable.mono' hbnd_int (by fun_prop) (Filter.Eventually.of_forall fun ω ↦ ?_) + rw [hftdef, Real.norm_of_nonneg (Real.exp_nonneg _)] + obtain ⟨hlo, hhi⟩ := abs_le.mp (hK ω) + rcases le_total 0 (X t ω - X r ω) with hΔ | hΔ + · exact le_add_of_le_of_nonneg (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hhi hΔ)) + (Real.exp_nonneg _) + · exact le_add_of_nonneg_of_le (Real.exp_nonneg _) + (Real.exp_le_exp.mpr (mul_le_mul_of_nonpos_right hlo hΔ)) + have hprod : (fun ω ↦ Real.exp (c ω * (X t ω - X r ω) - (c ω) ^ 2 * ((t : ℝ) - (r : ℝ)) / 2)) + = gr * ft := by + funext ω; show _ = (gr * ft) ω + rw [Pi.mul_apply, hgrdef, hftdef, ← Real.exp_add]; congr 1; ring + have hprod_int : Integrable (gr * ft) P := by + rw [← hprod] + refine Integrable.mono' hbnd_int (by fun_prop) (Filter.Eventually.of_forall fun ω ↦ ?_) + rw [Real.norm_of_nonneg (Real.exp_nonneg _)] + have hstep : Real.exp (c ω * (X t ω - X r ω) - (c ω) ^ 2 * ((t : ℝ) - (r : ℝ)) / 2) + ≤ Real.exp (c ω * (X t ω - X r ω)) := + Real.exp_le_exp.mpr (by nlinarith [sq_nonneg (c ω), htr]) + refine hstep.trans ?_ + obtain ⟨hlo, hhi⟩ := abs_le.mp (hK ω) + rcases le_total 0 (X t ω - X r ω) with hΔ | hΔ + · exact le_add_of_le_of_nonneg (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hhi hΔ)) + (Real.exp_nonneg _) + · exact le_add_of_nonneg_of_le (Real.exp_nonneg _) + (Real.exp_le_exp.mpr (mul_le_mul_of_nonpos_right hlo hΔ)) + rw [hprod] + have hpull := condExp_mul_of_stronglyMeasurable_left (m := (𝓕 r : MeasurableSpace Ω)) + hgr_sm hprod_int hft_int + have hcond := condExp_exp_adapted_mul_increment (P := P) (𝓕 := 𝓕) (X := X) hc hK hrt + filter_upwards [hpull, hcond] with ω hp hc' + rw [hp, Pi.mul_apply, + show (P[ft | (𝓕 r : MeasurableSpace Ω)]) ω = Real.exp ((c ω) ^ 2 * ((t : ℝ) - (r : ℝ)) / 2) + from hc', hgrdef, ← Real.exp_add, neg_add_cancel, Real.exp_zero] + +/-- **The single-cell Doléans exponential over `(a,b]`, clamped to `[0,t]`.** For a multiplier +`c`, `cellExp a b c t = exp(c·(X_{b∧t} − X_{a∧t}) − ½ c² (b∧t − a∧t))`: it is `1` before `a`, +the running Wald exponential `exp(c(X_t − X_a) − ½c²(t−a))` inside `[a,b]`, and frozen at its +`b`-value after `b`. -/ +noncomputable def cellExp (a b : ℝ≥0) (c : Ω → ℝ) (t : ℝ≥0) (ω : Ω) : ℝ := + Real.exp (c ω * (X (min b t) ω - X (min a t) ω) + - (c ω) ^ 2 * (NNReal.toReal (min b t) - NNReal.toReal (min a t)) / 2) + +lemma cellExp_of_le_left {a b : ℝ≥0} (hab : a ≤ b) {c : Ω → ℝ} {t : ℝ≥0} + (ht : t ≤ a) (ω : Ω) : cellExp (X := X) a b c t ω = 1 := by + rw [cellExp, min_eq_right (ht.trans hab), min_eq_right ht]; simp + +lemma cellExp_of_mem {a b : ℝ≥0} {c : Ω → ℝ} {t : ℝ≥0} (hat : a ≤ t) (htb : t ≤ b) (ω : Ω) : + cellExp (X := X) a b c t ω + = Real.exp (c ω * (X t ω - X a ω) - (c ω) ^ 2 * ((t : ℝ) - (a : ℝ)) / 2) := by + rw [cellExp, min_eq_right htb, min_eq_left hat] + +lemma cellExp_of_ge_right {a b : ℝ≥0} (hab : a ≤ b) {c : Ω → ℝ} {t : ℝ≥0} (hbt : b ≤ t) (ω : Ω) : + cellExp (X := X) a b c t ω + = Real.exp (c ω * (X b ω - X a ω) - (c ω) ^ 2 * ((b : ℝ) - (a : ℝ)) / 2) := by + rw [cellExp, min_eq_left hbt, min_eq_left (hab.trans hbt)] + +include hX in +omit [IsProbabilityMeasure P] [SigmaFiniteFiltration P 𝓕] in +/-- Integrability of an increment cell factor `exp(c·(X_q − X_p) − ½c²(q−p))` for a bounded +multiplier and `p ≤ q` — the increment `X_q − X_p` is Gaussian, dominated by two Gaussian MGFs. -/ +lemma integrable_cellIncrement {c : Ω → ℝ} (hc_meas : Measurable c) {K : ℝ} + (hK : ∀ ω, |c ω| ≤ K) (p q : ℝ≥0) (hpq : p ≤ q) : + Integrable (fun ω ↦ Real.exp (c ω * (X q ω - X p ω) + - (c ω) ^ 2 * (NNReal.toReal q - NNReal.toReal p) / 2)) P := by + have hXq : Measurable (X q) := ((hX.stronglyAdapted q).mono (𝓕.le q)).measurable + have hXp : Measurable (X p) := ((hX.stronglyAdapted p).mono (𝓕.le p)).measurable + have hΔlaw : HasLaw (fun ω ↦ X q ω - X p ω) (gaussianReal 0 (nndist (q : ℝ) (p : ℝ))) P := + hX.hasLaw_sub q p + have hpqr : (0 : ℝ) ≤ NNReal.toReal q - NNReal.toReal p := + sub_nonneg.mpr (NNReal.coe_le_coe.mpr hpq) + refine Integrable.mono' + ((hΔlaw.integrable_fun_comp (integrable_exp_mul_gaussianReal K)).add + (hΔlaw.integrable_fun_comp (integrable_exp_mul_gaussianReal (-K)))) + (by fun_prop) (Filter.Eventually.of_forall fun ω ↦ ?_) + rw [Real.norm_of_nonneg (Real.exp_nonneg _)] + have hstep : Real.exp + (c ω * (X q ω - X p ω) - (c ω) ^ 2 * (NNReal.toReal q - NNReal.toReal p) / 2) + ≤ Real.exp (c ω * (X q ω - X p ω)) := + Real.exp_le_exp.mpr (by nlinarith [sq_nonneg (c ω), hpqr]) + refine hstep.trans ?_ + obtain ⟨hlo, hhi⟩ := abs_le.mp (hK ω) + rcases le_total 0 (X q ω - X p ω) with hΔ | hΔ + · exact le_add_of_le_of_nonneg (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hhi hΔ)) + (Real.exp_nonneg _) + · exact le_add_of_nonneg_of_le (Real.exp_nonneg _) + (Real.exp_le_exp.mpr (mul_le_mul_of_nonpos_right hlo hΔ)) + +include hX in +/-- **The single-cell Doléans exponential over `(a,b]` is a `P`-martingale.** For `a ≤ b` and a +bounded `𝓕_a`-measurable multiplier `c`, `t ↦ cellExp a b c t` is a martingale w.r.t. `𝓕`. + +`cellExp` is `1` before `a`, the running Wald exponential inside `[a,b]`, and frozen after `b`. +The conditional expectation splits into four regions of `(s,t)` relative to `[a,b]`, each closing +by `condExp_expCell_eq_one` (the random-multiplier freezing) — through the tower `𝓕_s ⊆ 𝓕_a` +when `s ≤ a ≤ t`, and by pulling the `𝓕_s`-measurable `cellExp_s` out when `a ≤ s`. -/ +theorem cellExp_isMartingale {a b : ℝ≥0} (hab : a ≤ b) {c : Ω → ℝ} + (hc : StronglyMeasurable[(𝓕 a : MeasurableSpace Ω)] c) {K : ℝ} (hK : ∀ ω, |c ω| ≤ K) : + Martingale (fun t ω ↦ cellExp (X := X) a b c t ω) 𝓕 P := by + have hc_meas : Measurable c := (hc.mono (𝓕.le a)).measurable + -- Integrability at every time, from the increment cell helper. + have hcell_int : ∀ u : ℝ≥0, Integrable (fun ω ↦ cellExp (X := X) a b c u ω) P := fun u ↦ + integrable_cellIncrement (𝓕 := 𝓕) hc_meas hK (min a u) (min b u) (min_le_min_right u hab) + -- Adaptedness. + have hadapt : ∀ u : ℝ≥0, StronglyMeasurable[(𝓕 u : MeasurableSpace Ω)] + (fun ω ↦ cellExp (X := X) a b c u ω) := by + intro u + rcases le_total a u with hau | hua + · have hcu : StronglyMeasurable[(𝓕 u : MeasurableSpace Ω)] c := hc.mono (𝓕.mono hau) + have hXbu : StronglyMeasurable[(𝓕 u : MeasurableSpace Ω)] (X (min b u)) := + (hX.stronglyAdapted (min b u)).mono (𝓕.mono (min_le_right b u)) + have hXau : StronglyMeasurable[(𝓕 u : MeasurableSpace Ω)] (X (min a u)) := + (hX.stronglyAdapted (min a u)).mono (𝓕.mono (min_le_right a u)) + exact Real.continuous_exp.comp_stronglyMeasurable ((hcu.mul (hXbu.sub hXau)).sub + ((((continuous_pow 2).comp_stronglyMeasurable hcu).mul stronglyMeasurable_const).div + stronglyMeasurable_const)) + · rw [funext fun ω ↦ cellExp_of_le_left hab hua ω]; exact stronglyMeasurable_const + refine ⟨hadapt, fun s t hst ↦ ?_⟩ + change P[fun ω ↦ cellExp (X := X) a b c t ω | (𝓕 s : MeasurableSpace Ω)] + =ᵐ[P] fun ω ↦ cellExp (X := X) a b c s ω + rcases le_total t a with hta | hta + · -- (A) `t ≤ a`: both `1`. + rw [funext fun ω ↦ cellExp_of_le_left hab hta ω, + funext fun ω ↦ cellExp_of_le_left hab (hst.trans hta) ω] + exact (condExp_const (𝓕.le s) (1 : ℝ)).eventuallyEq + rcases le_total b s with hbs | hbs + · -- (B) `b ≤ s`: both frozen at the `b`-value. + have hsm : StronglyMeasurable[(𝓕 s : MeasurableSpace Ω)] + (fun ω ↦ Real.exp (c ω * (X b ω - X a ω) - (c ω) ^ 2 * ((b : ℝ) - (a : ℝ)) / 2)) := by + have hcs : StronglyMeasurable[(𝓕 s : MeasurableSpace Ω)] c := hc.mono (𝓕.mono (hab.trans hbs)) + have hXbs : StronglyMeasurable[(𝓕 s : MeasurableSpace Ω)] (X b) := + (hX.stronglyAdapted b).mono (𝓕.mono hbs) + have hXas : StronglyMeasurable[(𝓕 s : MeasurableSpace Ω)] (X a) := + (hX.stronglyAdapted a).mono (𝓕.mono (hab.trans hbs)) + exact Real.continuous_exp.comp_stronglyMeasurable ((hcs.mul (hXbs.sub hXas)).sub + ((((continuous_pow 2).comp_stronglyMeasurable hcs).mul stronglyMeasurable_const).div + stronglyMeasurable_const)) + have hfr : (fun ω ↦ cellExp (X := X) a b c t ω) + = fun ω ↦ Real.exp (c ω * (X b ω - X a ω) - (c ω) ^ 2 * ((b : ℝ) - (a : ℝ)) / 2) := + funext fun ω ↦ cellExp_of_ge_right hab (hbs.trans hst) ω + rw [hfr, funext fun ω ↦ cellExp_of_ge_right hab hbs ω] + exact (condExp_of_stronglyMeasurable (𝓕.le s) hsm (hfr ▸ hcell_int t)).eventuallyEq + rcases le_total s a with hsa | hsa + · -- (C) `s ≤ a ≤ t`: `cellExp_s = 1`, tower through `𝓕_a`. + have hEa : P[(fun ω ↦ cellExp (X := X) a b c t ω) | (𝓕 a : MeasurableSpace Ω)] + =ᵐ[P] fun _ ↦ (1 : ℝ) := by + rw [funext fun ω ↦ show cellExp (X := X) a b c t ω + = Real.exp (c ω * (X (min b t) ω - X a ω) + - (c ω) ^ 2 * (NNReal.toReal (min b t) - NNReal.toReal a) / 2) by + rw [cellExp, min_eq_left hta]] + exact condExp_expCell_eq_one hc hK (le_min hab hta) + rw [funext fun ω ↦ cellExp_of_le_left hab hsa ω] + refine (condExp_condExp_of_le (𝓕.mono hsa) (𝓕.le a)).symm.trans ?_ + exact (condExp_congr_ae hEa).trans (condExp_const (𝓕.le s) (1 : ℝ)).eventuallyEq + · -- (D) `a ≤ s ≤ b`: pull out the `𝓕_s`-measurable `cellExp_s`, freeze the `(s, b∧t]` increment. + have hcs : StronglyMeasurable[(𝓕 s : MeasurableSpace Ω)] c := hc.mono (𝓕.mono hsa) + have hsβ : s ≤ min b t := le_min hbs hst + have hfactor : (fun ω ↦ cellExp (X := X) a b c t ω) + = (fun ω ↦ cellExp (X := X) a b c s ω) + * fun ω ↦ Real.exp (c ω * (X (min b t) ω - X s ω) + - (c ω) ^ 2 * (NNReal.toReal (min b t) - NNReal.toReal s) / 2) := by + funext ω + simp only [Pi.mul_apply] + rw [cellExp, min_eq_left hta, cellExp_of_mem hsa hbs ω, ← Real.exp_add] + congr 1; ring + rw [hfactor] + have hpull := condExp_mul_of_stronglyMeasurable_left (m := (𝓕 s : MeasurableSpace Ω)) + (hadapt s) (hfactor ▸ hcell_int t) + (integrable_cellIncrement (𝓕 := 𝓕) hc_meas hK s (min b t) hsβ) + refine hpull.trans ?_ + filter_upwards [condExp_expCell_eq_one (P := P) (𝓕 := 𝓕) (X := X) hcs hK hsβ] with ω hg + rw [Pi.mul_apply, show (P[(fun ω ↦ Real.exp (c ω * (X (min b t) ω - X s ω) + - (c ω) ^ 2 * (NNReal.toReal (min b t) - NNReal.toReal s) / 2)) | + (𝓕 s : MeasurableSpace Ω)]) ω = 1 from hg, mul_one] + +include hX in +/-- **Appending one cell preserves the martingale.** If `M` is a `P`-martingale that is *frozen +after* `p` (constant in time past `p`), then multiplying by a fresh cell `cellExp p q c` +(`c` bounded `𝓕_p`-measurable, `p ≤ q`) is again a `P`-martingale. Cross-cell integrability uses +only the pairwise independence of the `(p, b∧t]` increment from `𝓕_p` (`IndepFun.integrable_mul`); +the conditional expectation splits on `s`, `t` versus `p`, closing by `cellExp_isMartingale`. -/ +theorem mul_cellExp_isMartingale {M : ℝ≥0 → Ω → ℝ} (hM : Martingale M 𝓕 P) + {p : ℝ≥0} (hMfroz : ∀ u ω, p ≤ u → M u ω = M p ω) + {q : ℝ≥0} (hpq : p ≤ q) {c : Ω → ℝ} (hc : StronglyMeasurable[(𝓕 p : MeasurableSpace Ω)] c) + {K : ℝ} (hK : ∀ ω, |c ω| ≤ K) : + Martingale (fun t ω ↦ M t ω * cellExp (X := X) p q c t ω) 𝓕 P := by + have hc_meas : Measurable c := (hc.mono (𝓕.le p)).measurable + have hMp_meas : Measurable (M p) := ((hM.1 p).mono (𝓕.le p)).measurable + have hG_mart := cellExp_isMartingale (X := X) (P := P) hpq hc hK + -- Integrability at each time, in the frozen `M_p` form used by every case. + have hMpG_int : ∀ t : ℝ≥0, Integrable (fun ω ↦ M p ω * cellExp (X := X) p q c t ω) P := by + intro t + rcases le_total t p with htp | hpt + · rw [show (fun ω ↦ M p ω * cellExp (X := X) p q c t ω) = M p from + funext fun ω ↦ by rw [cellExp_of_le_left hpq htp ω, mul_one]] + exact hM.integrable p + · have hpqt : p ≤ min q t := le_min hpq hpt + have hXqt : Measurable (X (min q t)) := + ((hX.stronglyAdapted (min q t)).mono (𝓕.le _)).measurable + have hXp : Measurable (X p) := ((hX.stronglyAdapted p).mono (𝓕.le p)).measurable + have hcellval : (fun ω ↦ M p ω * cellExp (X := X) p q c t ω) + = fun ω ↦ M p ω * Real.exp (c ω * (X (min q t) ω - X p ω) + - (c ω) ^ 2 * (NNReal.toReal (min q t) - NNReal.toReal p) / 2) := by + funext ω; rw [cellExp, min_eq_left hpt] + have hΔlaw : HasLaw (fun ω ↦ X (min q t) ω - X p ω) + (gaussianReal 0 (nndist ((min q t : ℝ≥0) : ℝ) ((p : ℝ≥0) : ℝ))) P := + hX.hasLaw_sub (min q t) p + have hindepΔ : IndepFun (M p) (fun ω ↦ X (min q t) ω - X p ω) P := + Indep.symm (indep_of_indep_of_le_right (hX.indep p (min q t) hpqt) + (hM.1 p).measurable.comap_le) + have hindepK : IndepFun (fun ω ↦ |M p ω|) + (fun ω ↦ Real.exp (K * (X (min q t) ω - X p ω))) P := + hindepΔ.comp (ψ := fun x ↦ Real.exp (K * x)) measurable_abs (by fun_prop) + have hindepnK : IndepFun (fun ω ↦ |M p ω|) + (fun ω ↦ Real.exp (-K * (X (min q t) ω - X p ω))) P := + hindepΔ.comp (ψ := fun x ↦ Real.exp (-K * x)) measurable_abs (by fun_prop) + have hMabs_int : Integrable (fun ω ↦ |M p ω|) P := (hM.integrable p).abs + have hbnd : Integrable (fun ω ↦ |M p ω| * Real.exp (K * (X (min q t) ω - X p ω)) + + |M p ω| * Real.exp (-K * (X (min q t) ω - X p ω))) P := + (hindepK.integrable_mul hMabs_int + (hΔlaw.integrable_fun_comp (integrable_exp_mul_gaussianReal K))).add + (hindepnK.integrable_mul hMabs_int + (hΔlaw.integrable_fun_comp (integrable_exp_mul_gaussianReal (-K)))) + rw [hcellval] + have hpqr : (0 : ℝ) ≤ NNReal.toReal (min q t) - NNReal.toReal p := + sub_nonneg.mpr (NNReal.coe_le_coe.mpr hpqt) + refine Integrable.mono' hbnd (by fun_prop) (Filter.Eventually.of_forall fun ω ↦ ?_) + rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (Real.exp_nonneg _)] + have hle1 : c ω * (X (min q t) ω - X p ω) + - (c ω) ^ 2 * (NNReal.toReal (min q t) - NNReal.toReal p) / 2 + ≤ c ω * (X (min q t) ω - X p ω) := by nlinarith [sq_nonneg (c ω), hpqr] + have hGle : Real.exp (c ω * (X (min q t) ω - X p ω) + - (c ω) ^ 2 * (NNReal.toReal (min q t) - NNReal.toReal p) / 2) + ≤ Real.exp (K * (X (min q t) ω - X p ω)) + Real.exp (-K * (X (min q t) ω - X p ω)) := by + refine (Real.exp_le_exp.mpr hle1).trans ?_ + obtain ⟨hlo, hhi⟩ := abs_le.mp (hK ω) + rcases le_total 0 (X (min q t) ω - X p ω) with hΔ | hΔ + · exact le_add_of_le_of_nonneg (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hhi hΔ)) + (Real.exp_nonneg _) + · exact le_add_of_nonneg_of_le (Real.exp_nonneg _) + (Real.exp_le_exp.mpr (mul_le_mul_of_nonpos_right hlo hΔ)) + calc |M p ω| * Real.exp (c ω * (X (min q t) ω - X p ω) + - (c ω) ^ 2 * (NNReal.toReal (min q t) - NNReal.toReal p) / 2) + ≤ |M p ω| * (Real.exp (K * (X (min q t) ω - X p ω)) + + Real.exp (-K * (X (min q t) ω - X p ω))) := + mul_le_mul_of_nonneg_left hGle (abs_nonneg _) + _ = _ := by ring + refine ⟨fun t ↦ (hM.1 t).mul (hG_mart.1 t), fun s t hst ↦ ?_⟩ + change P[fun ω ↦ M t ω * cellExp (X := X) p q c t ω | (𝓕 s : MeasurableSpace Ω)] + =ᵐ[P] fun ω ↦ M s ω * cellExp (X := X) p q c s ω + rcases le_total p s with hps | hsp + · -- (I) `p ≤ s`: `M` frozen, pull out the `𝓕_s`-measurable `M_p`, `cellExp` martingale. + rw [show (fun ω ↦ M t ω * cellExp (X := X) p q c t ω) + = fun ω ↦ M p ω * cellExp (X := X) p q c t ω from + funext fun ω ↦ by rw [hMfroz t ω (hps.trans hst)], + show (fun ω ↦ M s ω * cellExp (X := X) p q c s ω) + = fun ω ↦ M p ω * cellExp (X := X) p q c s ω from + funext fun ω ↦ by rw [hMfroz s ω hps]] + refine (condExp_mul_of_stronglyMeasurable_left (m := (𝓕 s : MeasurableSpace Ω)) + ((hM.1 p).mono (𝓕.mono hps)) (hMpG_int t) (hG_mart.integrable t)).trans ?_ + filter_upwards [hG_mart.2 s t hst] with ω hgw + rw [Pi.mul_apply, hgw] + · rcases le_total t p with htp | hpt + · -- (II) `t ≤ p`: both cells are `1`, `M` martingale. + rw [show (fun ω ↦ M t ω * cellExp (X := X) p q c t ω) = M t from + funext fun ω ↦ by rw [cellExp_of_le_left hpq htp ω, mul_one], + show (fun ω ↦ M s ω * cellExp (X := X) p q c s ω) = M s from + funext fun ω ↦ by rw [cellExp_of_le_left hpq (hst.trans htp) ω, mul_one]] + exact hM.2 s t hst + · -- (III) `s ≤ p ≤ t`: tower through `𝓕_p`; inner pull-out gives `M_p` (cell at `p` is `1`). + rw [show (fun ω ↦ M s ω * cellExp (X := X) p q c s ω) = M s from + funext fun ω ↦ by rw [cellExp_of_le_left hpq hsp ω, mul_one], + show (fun ω ↦ M t ω * cellExp (X := X) p q c t ω) + = fun ω ↦ M p ω * cellExp (X := X) p q c t ω from + funext fun ω ↦ by rw [hMfroz t ω hpt]] + have hinner : P[(fun ω ↦ M p ω * cellExp (X := X) p q c t ω) | + (𝓕 p : MeasurableSpace Ω)] =ᵐ[P] M p := by + refine (condExp_mul_of_stronglyMeasurable_left (m := (𝓕 p : MeasurableSpace Ω)) (hM.1 p) + (hMpG_int t) (hG_mart.integrable t)).trans ?_ + filter_upwards [hG_mart.2 p t hpt] with ω hgw + rw [Pi.mul_apply, hgw, cellExp_of_le_left hpq (le_refl p) ω, mul_one] + calc P[(fun ω ↦ M p ω * cellExp (X := X) p q c t ω) | (𝓕 s : MeasurableSpace Ω)] + =ᵐ[P] P[P[(fun ω ↦ M p ω * cellExp (X := X) p q c t ω) | + (𝓕 p : MeasurableSpace Ω)] | (𝓕 s : MeasurableSpace Ω)] := + (condExp_condExp_of_le (𝓕.mono hsp) (𝓕.le p)).symm + _ =ᵐ[P] P[M p | (𝓕 s : MeasurableSpace Ω)] := condExp_congr_ae hinner + _ =ᵐ[P] M s := hM.2 s p hsp + +/-- **The running simple Doléans exponential** over the first `N` cells of a partition +`s : ℕ → ℝ≥0` with multipliers `d : ℕ → Ω → ℝ`: the product `∏_{i 1 + | (n + 1), t, ω => + simpleDoleansExp s d n t ω * cellExp (X := X) (s n) (s (n + 1)) (d n) t ω + +/-- The simple Doléans exponential over the first `N` cells is **frozen after `s N`**: past the +last partition point every cell factor is constant in time. -/ +lemma simpleDoleansExp_frozen (s : ℕ → ℝ≥0) (hs : Monotone s) (d : ℕ → Ω → ℝ) : + ∀ (N : ℕ) (u : ℝ≥0) (ω : Ω), s N ≤ u → + simpleDoleansExp (X := X) s d N u ω = simpleDoleansExp (X := X) s d N (s N) ω := by + intro N + induction N with + | zero => intro u ω _; rfl + | succ n ih => + intro u ω hu + have hsn : s n ≤ s (n + 1) := hs (Nat.le_succ n) + change simpleDoleansExp (X := X) s d n u ω * cellExp (X := X) (s n) (s (n + 1)) (d n) u ω + = simpleDoleansExp (X := X) s d n (s (n + 1)) ω + * cellExp (X := X) (s n) (s (n + 1)) (d n) (s (n + 1)) ω + rw [ih u ω (hsn.trans hu), ih (s (n + 1)) ω hsn, + cellExp_of_ge_right hsn hu, cellExp_of_ge_right hsn (le_refl _)] + +include hX in +/-- **The simple Doléans exponential is a `P`-martingale.** For a monotone partition +`s : ℕ → ℝ≥0` and uniformly bounded adapted multipliers `d` (`d i` is `𝓕_{s i}`-measurable), +the running product `simpleDoleansExp s d N` is a martingale w.r.t. `𝓕` — the density process of +the simple (piecewise-constant-adapted) Girsanov change of measure. Induction on `N` via +`mul_cellExp_isMartingale`, with the `simpleDoleansExp_frozen` invariant feeding each new cell. -/ +theorem simpleDoleansExp_isMartingale (s : ℕ → ℝ≥0) (hs : Monotone s) (d : ℕ → Ω → ℝ) + (hd : ∀ i, StronglyMeasurable[(𝓕 (s i) : MeasurableSpace Ω)] (d i)) {K : ℝ} + (hd_bdd : ∀ i ω, |d i ω| ≤ K) (N : ℕ) : + Martingale (fun t ω ↦ simpleDoleansExp (X := X) s d N t ω) 𝓕 P := by + induction N with + | zero => exact martingale_const 𝓕 P 1 + | succ n ih => + exact mul_cellExp_isMartingale (X := X) ih + (fun u ω hu ↦ simpleDoleansExp_frozen (X := X) s hs d n u ω hu) + (hs (Nat.le_succ n)) (hd n) (hd_bdd n) + +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Girsanov/WienerIntegralGirsanov.lean b/LeanPool/MathFin/Probability/Brownian/Girsanov/WienerIntegralGirsanov.lean new file mode 100644 index 0000000000..d5ef03c169 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Girsanov/WienerIntegralGirsanov.lean @@ -0,0 +1,139 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralExpMoment +public import LeanPool.MathFin.Probability.Laws.Esscher + +/-! +# Wiener integrals under the constant-`λ` Girsanov measure + +Fix a pre-Brownian motion `B` under `μ`, a horizon `T` and a constant `λ`, and let + + `Q_λ = μ.withDensity(exp(−λB_T − λ²T/2))`, + +the constant-`θ` Girsanov measure of `Probability/Brownian/Girsanov/GirsanovConstantTheta` (there, +with a filtration, +`B_t + λt` is shown to have the increments of a `Q_λ`-Brownian motion on `[0, T]`, +`Btheta_isQBrownianMotion`). This file computes the `Q_λ`-law of every Wiener integral with a +deterministic kernel: the measure change shifts its mean by `−λ∫₀ᵀ f` and keeps its variance, + + under `Q_λ`, `∫₀ᵀ f dB ~ N(−λ∫₀ᵀ f, ∫₀ᵀ f²)` (`wienerIntegralLp_hasLaw_girsanov`). + +This is the Cameron–Martin shift of a Wiener integral: `dB = dB^λ − λ dt` with `B^λ` the +`Q_λ`-Brownian motion. + +## Proof + +`B_T` is the Wiener integral of the indicator `𝟙 = 𝟙_{(0,T]}` +(`eval_ae_eq_wienerIntegralLp_stepIndicator`). By linearity, `−λB_T + t·∫f dB` is a.s. the single +Wiener integral `∫(tf − λ𝟙) dB`, so the `Q_λ`-moment-generating function of `∫f dB` is one Gaussian +exponential moment under `μ`: + + `𝔼_{Q_λ}[e^{t∫f dB}] = e^{−λ²T/2}·e^{‖tf − λ𝟙‖²/2} = e^{−tλ⟪𝟙,f⟫ + t²‖f‖²/2}`, + +using `‖𝟙‖² = T`. No joint law of `(B_T, ∫f dB)` is needed. The moment-generating function +determines the law (`measure_eq_of_mgf_id_eq`). At `t = 0` the same identity gives +`Q_λ(Ω) = 1` (`isProbabilityMeasure_withDensity_girsanov`). That result needs only the +pre-Brownian hypothesis; `girsanovMeasure_isProbabilityMeasure` states it for a filtered +pre-Brownian motion. + +## Main results + +* `integral_exp_mul_wienerIntegralLp_withDensity_girsanov`: under + `Q_λ = μ.withDensity(exp(−λB_T − λ²T/2))`, `𝔼[exp(t·∫f dB)] = exp(−tλ⟪𝟙_{(0,T]}, f⟫ + t²‖f‖²/2)`. +* `isProbabilityMeasure_withDensity_girsanov`: `Q_λ` is a probability measure for a + pre-Brownian motion. +* `wienerIntegralLp_hasLaw_girsanov`: under `Q_λ`, `∫₀ᵀ f dB ~ N(−λ∫₀ᵀ f, ∫₀ᵀ f²)`. + +## Tags + +Girsanov theorem, Cameron–Martin shift, Wiener integral, measure change, drift shift, +Doléans density, MSC 60H05, MSC 60G15, MSC 91G20 +-/ + +@[expose] public section + +namespace MathFin +namespace WienerIntegralL2 + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal InnerProductSpace + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-- **The `Q_λ`-moment-generating function of a Wiener integral**: +`𝔼_{Q_λ}[exp(t·∫f dB)] = exp(−tλ⟪𝟙_{(0,T]}, f⟫ + t²‖f‖²/2)`. -/ +lemma integral_exp_mul_wienerIntegralLp_withDensity_girsanov (hB : IsPreBrownianReal B μ) + (lam : ℝ) (T : ℝ≥0) (f : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ)))) (t : ℝ) : + ∫ ω, Real.exp (t * wienerIntegralLp B hB T f ω) + ∂(μ.withDensity fun ω ↦ ENNReal.ofReal (Real.exp (-lam * B T ω - lam ^ 2 * (T : ℝ) / 2))) + = Real.exp (-(t * lam * ⟪stepIndicatorLp T (StepIndex.whole T), f⟫_ℝ) + + t ^ 2 * ‖f‖ ^ 2 / 2) := by + have hZ : AEMeasurable (fun ω ↦ Real.exp (-lam * B T ω - lam ^ 2 * (T : ℝ) / 2)) μ := by + have := hB.aemeasurable T + fun_prop + rw [integral_withDensity_eq_integral_toReal_smul₀ hZ.ennreal_ofReal + (ae_of_all _ fun _ ↦ ENNReal.ofReal_lt_top)] + have hpt : (fun ω ↦ (ENNReal.ofReal (Real.exp (-lam * B T ω - lam ^ 2 * (T : ℝ) / 2))).toReal + • Real.exp (t * wienerIntegralLp B hB T f ω)) + =ᵐ[μ] fun ω ↦ Real.exp (-(lam ^ 2 * (T : ℝ) / 2)) * Real.exp (1 * wienerIntegralLp B hB T + (t • f + (-lam) • stepIndicatorLp T (StepIndex.whole T)) ω) := by + filter_upwards [eval_ae_eq_wienerIntegralLp_stepIndicator hB T, + wienerIntegralLp_smul_add_smul_ae hB T t (-lam) f (stepIndicatorLp T (StepIndex.whole T))] + with ω hBT hlin + rw [ENNReal.toReal_ofReal (Real.exp_pos _).le, smul_eq_mul, hlin, hBT, ← Real.exp_add, + ← Real.exp_add] + congr 1 + ring + rw [integral_congr_ae hpt, integral_const_mul, integral_exp_mul_wienerIntegralLp, + norm_smul_add_smul_sq_real, norm_stepIndicatorLp_whole_sq, + real_inner_comm (stepIndicatorLp T (StepIndex.whole T)) f, ← Real.exp_add] + congr 1 + ring + +/-- **The constant-`λ` Girsanov measure is a probability measure**, for a pre-Brownian motion: the +`t = 0` case of `integral_exp_mul_wienerIntegralLp_withDensity_girsanov`, `∫ 1 dQ_λ = 1`. -/ +theorem isProbabilityMeasure_withDensity_girsanov (hB : IsPreBrownianReal B μ) (lam : ℝ) + (T : ℝ≥0) : + IsProbabilityMeasure + (μ.withDensity fun ω ↦ ENNReal.ofReal (Real.exp (-lam * B T ω - lam ^ 2 * (T : ℝ) / 2))) := by + have h := integral_exp_mul_wienerIntegralLp_withDensity_girsanov hB lam T 0 0 + simp only [zero_mul, neg_zero, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, zero_pow, + zero_div, add_zero, Real.exp_zero, integral_const, smul_eq_mul, mul_one] at h + constructor + rwa [measureReal_def, ENNReal.toReal_eq_one_iff] at h + +/-- **Wiener integrals under the Girsanov measure (Cameron–Martin shift).** Under +`Q_λ = μ.withDensity(exp(−λB_T − λ²T/2))`, the Wiener integral of a deterministic kernel +`f ∈ L²((0, T])` is Gaussian with its mean shifted by `−λ∫₀ᵀ f` and its variance unchanged: + + `∫₀ᵀ f dB ~ N(−λ·∫₀ᵀ f, ∫₀ᵀ f²)` under `Q_λ`. -/ +theorem wienerIntegralLp_hasLaw_girsanov (hB : IsPreBrownianReal B μ) (lam : ℝ) (T : ℝ≥0) + (f : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ)))) : + HasLaw (fun ω ↦ wienerIntegralLp B hB T f ω) + (gaussianReal (-(lam * ∫ s in Set.Ioc (0 : ℝ) (T : ℝ), f s)) + (∫ s in Set.Ioc (0 : ℝ) (T : ℝ), f s ^ 2).toNNReal) + (μ.withDensity fun ω ↦ ENNReal.ofReal (Real.exp (-lam * B T ω - lam ^ 2 * (T : ℝ) / 2))) := by + have := isProbabilityMeasure_withDensity_girsanov hB lam T + have hae : AEMeasurable (fun ω ↦ wienerIntegralLp B hB T f ω) + (μ.withDensity fun ω ↦ ENNReal.ofReal (Real.exp (-lam * B T ω - lam ^ 2 * (T : ℝ) / 2))) := + (Lp.aestronglyMeasurable _).aemeasurable.mono_ac (withDensity_absolutelyContinuous _ _) + refine ⟨hae, (measure_eq_of_mgf_id_eq integrable_exp_mul_gaussianReal ?_).symm⟩ + rw [mgf_id_gaussianReal, mgf_id_map hae] + funext t + simp only [mgf] + rw [integral_exp_mul_wienerIntegralLp_withDensity_girsanov, inner_stepIndicatorLp_whole, + lp_two_norm_sq, Real.coe_toNNReal _ (integral_nonneg fun _ ↦ sq_nonneg _)] + congr 1 + ring + +end WienerIntegralL2 + +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/AdaptedProcessToLp.lean b/LeanPool/MathFin/Probability/Brownian/Ito/AdaptedProcessToLp.lean new file mode 100644 index 0000000000..e4ea213456 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/AdaptedProcessToLp.lean @@ -0,0 +1,201 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralHorizonDense + +/-! +# Realizing a bounded adapted continuous process as an Itô-integrand class (the σ-realization) + +The Itô integral `∫₀ᵀ σ dB` (`ItoIntegralCLM.itoIntegralCLM`) takes its integrand from the +**predictable** `L²` space `E := Lp ℝ 2 (trimMeasure T)` — an `Lp` class over the trim product +measure on the predictable σ-algebra, never a raw process `σ : ℝ≥0 → Ω → ℝ`. To integrate a genuine +bounded adapted process (e.g. a continuous market price of risk `θ` for the general adapted Girsanov +theorem), one must first **realize** it inside `E`. This is the σ-realization: the last piece of +"the concrete adapted stochastic integral" (SP0, half (i)) that the drift/Itô SDE files build only +for their specific processes. + +For an **every-`ω`-continuous** bounded adapted `σ` this is a short assembly on the existing tower — +no a.e./everywhere friction, exactly as `DriftProcessPredictable.driftSimpleProcess` handles its +elementary drift: + +* `MathFin.isStronglyPredictable_of_bdd_adapted_cont` — continuous + adapted ⟹ predictable, via + Degenne's `StronglyAdapted.isStronglyPredictable_of_leftContinuous` (continuity gives the + left-continuity it wants); +* `MathFin.memLp_uncurry_of_bdd_adapted_cont` — predictable + bounded on the *finite* measure + `trimMeasure T` ⟹ `MemLp … 2`; +* `MathFin.processToLp` — the realization `σ ↦ (its class in E)`, with `processToLp_coeFn` the a.e. + identification back to `Function.uncurry σ`. + +This unblocks the continuous-adapted Girsanov (brick α4): `∫θdB` and its Doléans density are now +formable for a bounded adapted continuous `θ`. + +## Main definitions + +* `processToLp`: the realization of a bounded adapted process with continuous paths as an + element of the Itô-integrand space `Lp ℝ 2 (trimMeasure T)`. +* `processToLpPredictable`: the same realization for a bounded strongly predictable process. + +## Main results + +* `isStronglyPredictable_of_bdd_adapted_cont`: a bounded adapted process with continuous paths + is strongly predictable. +* `isStronglyPredictable_deterministic`, `isStronglyPredictable_const`, + `isStronglyPredictable_time`: a continuous function of time alone, a constant, and time itself + are predictable. +* `isStronglyPredictable_comp_path`: a Borel function of time and a continuous adapted path is + predictable. +* `memLp_uncurry_of_bdd_adapted_cont`, `memLp_uncurry_of_bdd_predictable`: such a process, and + any bounded predictable one, is in `L²` over `trimMeasure T`. +* `processToLp_coeFn`, `processToLpPredictable_coeFn`: the realization agrees with the process + `trimMeasure T`-almost everywhere. +* `processToLpPredictable_ae_slice`: the predictable realization agrees with the process on almost + every `ω`-slice. + +## Tags + +Itô integrand, predictable process, stochastic integral, market price of risk, L2 space, MSC 60H05, +MSC 60G07 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Filter Topology +open scoped NNReal ENNReal + +namespace MathFin + +open ItoIntegralL2 ItoIntegralCLM + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} + +/-- **A bounded adapted continuous process is predictable.** For an `𝓕`-adapted `σ` that is +continuous in time for every `ω`, the space-time function `(t, ω) ↦ σ t ω` is measurable for the +predictable σ-algebra — continuity gives the left-continuity Degenne's +`StronglyAdapted.isStronglyPredictable_of_leftContinuous` requires, and no randomness in the +time-regularity means no exceptional null set to dodge. -/ +theorem isStronglyPredictable_of_bdd_adapted_cont (hBmeas : ∀ t, Measurable (B t)) + {σ : ℝ≥0 → Ω → ℝ} + (hadap : ∀ t, StronglyMeasurable[(natFiltration hBmeas t : MeasurableSpace Ω)] (σ t)) + (hcont : ∀ ω, Continuous (fun t : ℝ≥0 ↦ σ t ω)) : + IsStronglyPredictable (natFiltration hBmeas) σ := by + apply MeasureTheory.StronglyAdapted.isStronglyPredictable_of_leftContinuous hadap + exact fun ω a ↦ (hcont ω).continuousWithinAt + +/-- **A deterministic continuous function of time is predictable** for the natural filtration. -/ +theorem isStronglyPredictable_deterministic (hBmeas : ∀ t, Measurable (B t)) {f : ℝ≥0 → ℝ} + (hf : Continuous f) : + IsStronglyPredictable (natFiltration hBmeas) fun (s : ℝ≥0) (_ : Ω) ↦ f s := + isStronglyPredictable_of_bdd_adapted_cont hBmeas (fun _ ↦ stronglyMeasurable_const) + fun _ ↦ hf + +/-- A constant process is predictable for the natural filtration. -/ +theorem isStronglyPredictable_const (hBmeas : ∀ t, Measurable (B t)) (c : ℝ) : + IsStronglyPredictable (natFiltration hBmeas) fun (_ : ℝ≥0) (_ : Ω) ↦ c := + isStronglyPredictable_deterministic hBmeas continuous_const + +/-- Time itself, `(s, ω) ↦ s`, is predictable for the natural filtration. -/ +theorem isStronglyPredictable_time (hBmeas : ∀ t, Measurable (B t)) : + IsStronglyPredictable (natFiltration hBmeas) fun (s : ℝ≥0) (_ : Ω) ↦ (s : ℝ) := + isStronglyPredictable_deterministic hBmeas NNReal.continuous_coe + +/-- **A Borel function of time and a continuous adapted path is predictable.** -/ +theorem isStronglyPredictable_comp_path (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) {h : ℝ → ℝ → ℝ} + (hh : Measurable fun p : ℝ × ℝ ↦ h p.1 p.2) : + IsStronglyPredictable (natFiltration hBmeas) fun (s : ℝ≥0) ω ↦ h s (B s ω) := + (hh.comp (StronglyMeasurable.prodMk (isStronglyPredictable_time hBmeas) + (isStronglyPredictable_of_bdd_adapted_cont hBmeas (stronglyAdapted_natFiltration hBmeas) + hBcont)).measurable).stronglyMeasurable + +/-- **A bounded adapted continuous process is `L²` over `trimMeasure T`.** It is predictable +(`isStronglyPredictable_of_bdd_adapted_cont`) and bounded, and `trimMeasure T` is a finite +measure, so `MemLp.of_bound` applies. -/ +theorem memLp_uncurry_of_bdd_adapted_cont (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + {σ : ℝ≥0 → Ω → ℝ} + (hadap : ∀ t, StronglyMeasurable[(natFiltration hBmeas t : MeasurableSpace Ω)] (σ t)) + (hcont : ∀ ω, Continuous (fun t : ℝ≥0 ↦ σ t ω)) {C : ℝ} (hbdd : ∀ t ω, |σ t ω| ≤ C) : + MemLp (Function.uncurry σ) 2 (trimMeasure (μ := μ) T hBmeas) := + MemLp.of_bound + (isStronglyPredictable_of_bdd_adapted_cont hBmeas hadap hcont).aestronglyMeasurable + C (ae_of_all _ fun z ↦ by rw [Real.norm_eq_abs]; exact hbdd z.1 z.2) + +/-- **The σ-realization.** A bounded adapted continuous process realized as an element of the +Itô-integrand space `E = Lp ℝ 2 (trimMeasure T)` — the domain of +`ItoIntegralCLM.itoIntegralCLM`. This is the missing bridge from a raw bounded adapted continuous +process `σ : ℝ≥0 → Ω → ℝ` to `∫₀ᵀ σ dB`; with it, the general continuous-adapted Girsanov density is +formable. -/ +noncomputable def processToLp (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + {σ : ℝ≥0 → Ω → ℝ} + (hadap : ∀ t, StronglyMeasurable[(natFiltration hBmeas t : MeasurableSpace Ω)] (σ t)) + (hcont : ∀ ω, Continuous (fun t : ℝ≥0 ↦ σ t ω)) {C : ℝ} (hbdd : ∀ t ω, |σ t ω| ≤ C) : + Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) := + (memLp_uncurry_of_bdd_adapted_cont T hBmeas hadap hcont hbdd).toLp (Function.uncurry σ) + +/-- **The realization agrees with `σ` a.e.** +`processToLp T σ =ᵐ[trimMeasure T] Function.uncurry σ` — the identification that lets Itô-integral +computations read the class back as the process. -/ +theorem processToLp_coeFn (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + {σ : ℝ≥0 → Ω → ℝ} + (hadap : ∀ t, StronglyMeasurable[(natFiltration hBmeas t : MeasurableSpace Ω)] (σ t)) + (hcont : ∀ ω, Continuous (fun t : ℝ≥0 ↦ σ t ω)) {C : ℝ} (hbdd : ∀ t ω, |σ t ω| ≤ C) : + processToLp (μ := μ) T hBmeas hadap hcont hbdd + =ᵐ[trimMeasure (μ := μ) T hBmeas] Function.uncurry σ := + (memLp_uncurry_of_bdd_adapted_cont T hBmeas hadap hcont hbdd).coeFn_toLp + +/-! ### The σ-realization for a bounded **predictable** integrand (Girsanov Rung 1) + +Dropping the continuity hypothesis: the Itô integral's domain is the *predictable* `L²` space, so a +bounded process that is already strongly predictable needs no continuity to be realized — the +`aestronglyMeasurable` it carries is exactly what `MemLp.of_bound` consumes. The continuous +realization above is the special case `IsStronglyPredictable` = +`isStronglyPredictable_of_bdd_adapted_cont`. -/ + +/-- **A bounded predictable process is `L²` over `trimMeasure T`.** Predictable + bounded on the +finite measure `trimMeasure T` ⟹ `MemLp.of_bound`; the continuity of +`memLp_uncurry_of_bdd_adapted_cont` is dropped. -/ +theorem memLp_uncurry_of_bdd_predictable (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + {σ : ℝ≥0 → Ω → ℝ} (hpred : IsStronglyPredictable (natFiltration hBmeas) σ) + {C : ℝ} (hbdd : ∀ t ω, |σ t ω| ≤ C) : + MemLp (Function.uncurry σ) 2 (trimMeasure (μ := μ) T hBmeas) := + MemLp.of_bound hpred.aestronglyMeasurable C + (ae_of_all _ fun z ↦ by rw [Real.norm_eq_abs]; exact hbdd z.1 z.2) + +/-- **The σ-realization for a bounded predictable process.** Realizes a bounded strongly-predictable +`σ : ℝ≥0 → Ω → ℝ` as an element of the Itô-integrand space `E = Lp ℝ 2 (trimMeasure T)` — the +domain of `ItoIntegralCLM.itoIntegralCLM` — with no continuity assumption. -/ +noncomputable def processToLpPredictable (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + {σ : ℝ≥0 → Ω → ℝ} (hpred : IsStronglyPredictable (natFiltration hBmeas) σ) + {C : ℝ} (hbdd : ∀ t ω, |σ t ω| ≤ C) : + Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) := + (memLp_uncurry_of_bdd_predictable T hBmeas hpred hbdd).toLp (Function.uncurry σ) + +/-- **The predictable realization agrees with `σ` a.e.** -/ +theorem processToLpPredictable_coeFn (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + {σ : ℝ≥0 → Ω → ℝ} (hpred : IsStronglyPredictable (natFiltration hBmeas) σ) + {C : ℝ} (hbdd : ∀ t ω, |σ t ω| ≤ C) : + processToLpPredictable (μ := μ) T hBmeas hpred hbdd + =ᵐ[trimMeasure (μ := μ) T hBmeas] Function.uncurry σ := + (memLp_uncurry_of_bdd_predictable T hBmeas hpred hbdd).coeFn_toLp + +/-- **The predictable realization agrees with `σ` on almost every `ω`-slice.** The a.e. +identification `processToLpPredictable_coeFn` over `trimMeasure`, read through the product measure +`timeMeasureHorizon T ⊗ μ` (`ae_eq_of_ae_eq_trim`) as: for `μ`-a.e. `ω`, the path `s ↦ σ s ω` and +the representative `s ↦ ⇑(processToLpPredictable σ) (s, ω)` agree for `timeMeasureHorizon T`-a.e. +`s`. -/ +theorem processToLpPredictable_ae_slice (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + {σ : ℝ≥0 → Ω → ℝ} (hpred : IsStronglyPredictable (natFiltration hBmeas) σ) + {C : ℝ} (hbdd : ∀ t ω, |σ t ω| ≤ C) : + ∀ᵐ ω ∂μ, ∀ᵐ s ∂(timeMeasureHorizon T), + processToLpPredictable (μ := μ) T hBmeas hpred hbdd (s, ω) = σ s ω := + Measure.ae_ae_of_ae_prod + ((Measure.measurePreserving_swap (μ := μ) (ν := timeMeasureHorizon T)).quasiMeasurePreserving.ae + (ae_eq_of_ae_eq_trim (processToLpPredictable_coeFn (μ := μ) T hBmeas hpred hbdd))) + +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/DriftProcessModification.lean b/LeanPool/MathFin/Probability/Brownian/Ito/DriftProcessModification.lean new file mode 100644 index 0000000000..0512567e9c --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/DriftProcessModification.lean @@ -0,0 +1,527 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.DriftProcessPredictable + +/-! # The pathwise drift process: convergence and modification (SDE-existence bridge, #19→existence) + +The `L²` drift operator `driftProcessAssembled : E →L E` is assembled abstractly (`extendOfNorm`); +`driftContinuousMod` is its pointwise-`limUnder` pathwise realization. This file supplies the drift +analog of the Itô side's `itoContinuousMod_tendsto` / `_modification`: the per-`t` value bridge that +lets an `E`-element be sliced into a genuine pathwise identity — the piece the pathwise +SDE-existence statement (`sc-thm-8.2.5`, existence half) needs. + +The drift side is **simpler** than the Itô side: `driftSimpleProcess V · ω` is continuous for +*every* `ω` (a finite sum of `𝓕`-coefficients times continuous time-increments), so there is no +exceptional null set and no martingale maximal inequality — the uniform-in-`t` control is pure +Cauchy–Schwarz (`sq_intervalIntegral_le`) against the deterministic time integral. + +## Main results + +* `drift_maximal_prob`: for a `T`-bounded simple process `W` and `ε > 0`, the probability that the + running maximum of `|drift W|` over `[0, T]` reaches `ε` is at most + `(ε²)⁻¹·T·‖simpleAssemblyHorizon W‖²`. +* `drift_ae_eventually_sup_lt`: almost surely the running maximum of `|drift (Vₙ − Vₙ₊₁)|` over + `[0, T]` is eventually below `(3/4)ⁿ`, for the fast approximating sequence `Vₙ`. +* `driftContinuousMod_tendsto`: for almost every `ω` and every `t ≤ T`, the elementary drifts + `driftSimpleProcess Vₙ t ω` converge to `driftContinuousMod φ t ω`. +* `driftProcessAssembled_coeFn`: the assembled drift operator has `coeFn` almost everywhere equal + to the pathwise limit process `driftContinuousMod T g`. +* `driftContinuousMod_eq_setIntegral`: for every `t ≤ T` and almost every `ω`, + `driftContinuousMod T g t ω` equals `∫_{(0,t]} ⇑g(s, ω) ds` for the representative `⇑g`. + +## Tags + +drift process, continuous modification, SDE existence, Cauchy–Schwarz, pathwise integral, MSC 60H10, +MSC 60H05 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Filter Topology +open scoped NNReal ENNReal + +namespace MathFin +namespace ItoIntegralProcessContinuousModification +open ItoIntegralL2 ItoIntegralCLM ItoIntegralProcess ItoIntegralProcessGeneral + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} + +/-- **The running-max keystone (drift).** For `i ≤ T`, `|driftSimpleProcess W i ω|` is bounded by +the running maximum over `[0,T]`. The supremum is genuine (not the junk value of an unbounded +family): `driftSimpleProcess W · ω` is continuous and `[0,T]` is compact, so the family is bounded +above. -/ +lemma drift_norm_le_iSup_Iic (hBmeas : ∀ t, Measurable (B t)) + (W : SimpleProcess ℝ (natFiltration hBmeas)) (ω : Ω) {i T : ℝ≥0} (hi : i ≤ T) : + |driftSimpleProcess hBmeas W i ω| + ≤ ⨆ j : Set.Iic T, |driftSimpleProcess hBmeas W (j : ℝ≥0) ω| := by + have hcont : Continuous fun j : Set.Iic T ↦ |driftSimpleProcess hBmeas W (j : ℝ≥0) ω| := + (continuous_abs.comp (driftSimpleProcess_continuous hBmeas W ω)).comp continuous_subtype_val + have hIic : (Set.Iic T : Set ℝ≥0) = Set.Icc 0 T := by + ext x; simp only [Set.mem_Iic, Set.mem_Icc, zero_le, true_and] + have : CompactSpace (Set.Iic T) := isCompact_iff_compactSpace.mp (hIic ▸ isCompact_Icc) + exact le_ciSup (isCompact_range hcont).bddAbove ⟨i, hi⟩ + +/-! ## Layer 1 — the drift maximal estimate (direct Chebyshev) and Borel–Cantelli -/ + +/-- The elementary drift **negates**: `drift (-V) = -drift V` (via `driftSimpleProcess_smul (-1)`). +-/ +lemma driftSimpleProcess_neg (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration hBmeas)) (t : ℝ≥0) : + driftSimpleProcess hBmeas (-V) t = -driftSimpleProcess hBmeas V t := by + rw [show (-V) = (-1 : ℝ) • V from (neg_one_smul ℝ V).symm, driftSimpleProcess_smul, neg_one_smul] + +/-- The elementary drift is **subtractive** (from `_add` + `_neg`), mirroring +`itoSimpleProcess_sub`. -/ +lemma driftSimpleProcess_sub (hBmeas : ∀ t, Measurable (B t)) + (V W : SimpleProcess ℝ (natFiltration hBmeas)) (t : ℝ≥0) : + driftSimpleProcess hBmeas (V - W) t + = driftSimpleProcess hBmeas V t - driftSimpleProcess hBmeas W t := by + rw [sub_eq_add_neg, driftSimpleProcess_add, driftSimpleProcess_neg, ← sub_eq_add_neg] + +/-- **The `E`-norm² of a simple embedding as a double integral.** Tonelli turns +`‖simpleAssemblyHorizon W‖²` into `∫_Ω ∫₀ᵀ (⇑W)² ds dμ` — the outer-`ω`, inner-time energy that the +drift Chebyshev bound reads. -/ +lemma simpleAssemblyHorizon_norm_sq (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (W : TBoundedSP T hBmeas) : + ‖simpleAssemblyHorizon (μ := μ) T hBmeas W‖ ^ 2 + = ∫ ω, ∫ s in Set.Ioc (0 : ℝ≥0) T, (⇑W.val s ω) ^ 2 ∂timeMeasure ∂μ := by + set 𝓕 := natFiltration (mΩ := mΩ) hBmeas + have hmemV := memLp_uncurry_trimMeasure (μ := μ) T hBmeas W.val + have hpredV := W.val.isStronglyPredictable + have hmemV_prod : MemLp (Function.uncurry ⇑W.val) 2 ((timeMeasureHorizon T).prod μ) := + memLp_of_memLp_trim 𝓕.predictable_le_prod hmemV + have hintV := hmemV_prod.integrable_sq + rw [show simpleAssemblyHorizon (μ := μ) T hBmeas W = hmemV.toLp (Function.uncurry ⇑W.val) from + rfl, + lp_two_norm_sq, integral_congr_ae (g := fun z ↦ (Function.uncurry ⇑W.val z) ^ 2) + (by filter_upwards [hmemV.coeFn_toLp] with z hz; rw [hz]), + show trimMeasure (μ := μ) T hBmeas + = ((timeMeasureHorizon T).prod μ).trim 𝓕.predictable_le_prod from rfl, + ← integral_trim 𝓕.predictable_le_prod (f := fun z ↦ (Function.uncurry ⇑W.val z) ^ 2) + (hpredV.pow 2)] + symm + rw [integral_prod _ hintV] + exact integral_integral_swap hintV.swap + +/-- **Pointwise sup bound.** For every `ω`, the squared running maximum of `|drift W · ω|` over +`[0,T]` is at most the deterministic energy `T·∫₀ᵀ (⇑W)²`: each slice obeys +`driftSimpleProcess_sq_le`, so the sup does too. Sup-free on the right — the input to a Chebyshev +bound that dodges sup-measurability. -/ +lemma drift_iSup_sq_le (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (W : SimpleProcess ℝ (natFiltration hBmeas)) (ω : Ω) : + (⨆ i : Set.Iic T, |driftSimpleProcess hBmeas W (i : ℝ≥0) ω|) ^ 2 + ≤ (T : ℝ) * ∫ s in Set.Ioc (0 : ℝ≥0) T, (⇑W s ω) ^ 2 ∂timeMeasure := by + have : Nonempty (Set.Iic T) := ⟨⟨0, by simp⟩⟩ + set R := (T : ℝ) * ∫ s in Set.Ioc (0 : ℝ≥0) T, (⇑W s ω) ^ 2 ∂timeMeasure + have hR0 : 0 ≤ R := mul_nonneg T.coe_nonneg (integral_nonneg fun s ↦ sq_nonneg _) + have hbound : (⨆ i : Set.Iic T, |driftSimpleProcess hBmeas W (i : ℝ≥0) ω|) ≤ Real.sqrt R := + ciSup_le fun i ↦ by + rw [← Real.sqrt_sq_eq_abs] + exact Real.sqrt_le_sqrt (driftSimpleProcess_sq_le T hBmeas W (Set.mem_Iic.mp i.2) ω) + have h0 : 0 ≤ ⨆ i : Set.Iic T, |driftSimpleProcess hBmeas W (i : ℝ≥0) ω| := + Real.iSup_nonneg fun i ↦ abs_nonneg _ + calc (⨆ i : Set.Iic T, |driftSimpleProcess hBmeas W (i : ℝ≥0) ω|) ^ 2 + ≤ (Real.sqrt R) ^ 2 := by simpa [pow_two] using mul_self_le_mul_self h0 hbound + _ = R := Real.sq_sqrt hR0 + +/-- **The drift maximal probability (direct Chebyshev).** For a `T`-bounded simple process `W`, the +probability that the running maximum of `|drift W|` over `[0,T]` reaches `ε` is at most +`(ε²)⁻¹·T·‖simpleAssemblyHorizon W‖²`. Unlike the Itô side (Doob's weak-type maximal inequality), +the drift paths are honestly continuous, so the sup is controlled pathwise by `drift_iSup_sq_le`; +bounding the event by the sup-free set `{ε² ≤ T∫₀ᵀW²}` sidesteps sup-measurability and leaves a +one-line Markov. -/ +lemma drift_maximal_prob (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) (W : TBoundedSP T hBmeas) + {ε : ℝ} (hε : 0 < ε) : + μ.real {ω | ε ≤ ⨆ i : Set.Iic T, |driftSimpleProcess hBmeas W.val (i : ℝ≥0) ω|} + ≤ (ε ^ 2)⁻¹ * ((T : ℝ) * ‖simpleAssemblyHorizon (μ := μ) T hBmeas W‖ ^ 2) := by + set 𝓕 := natFiltration (mΩ := mΩ) hBmeas + have hmemV := memLp_uncurry_trimMeasure (μ := μ) T hBmeas W.val + have hmemV_prod : MemLp (Function.uncurry ⇑W.val) 2 ((timeMeasureHorizon T).prod μ) := + memLp_of_memLp_trim 𝓕.predictable_le_prod hmemV + have hintV := hmemV_prod.integrable_sq + have hfun_int : Integrable + (fun ω ↦ (T : ℝ) * ∫ s in Set.Ioc (0 : ℝ≥0) T, (⇑W.val s ω) ^ 2 ∂timeMeasure) μ := + (hintV.integral_prod_right).const_mul _ + have hfun_nonneg : 0 ≤ᵐ[μ] + fun ω ↦ (T : ℝ) * ∫ s in Set.Ioc (0 : ℝ≥0) T, (⇑W.val s ω) ^ 2 ∂timeMeasure := + ae_of_all _ fun ω ↦ mul_nonneg T.coe_nonneg (integral_nonneg fun s ↦ sq_nonneg _) + have hmarkov := mul_meas_ge_le_integral_of_nonneg hfun_nonneg hfun_int (ε ^ 2) + have hintg : (∫ ω, (T : ℝ) * ∫ s in Set.Ioc (0 : ℝ≥0) T, (⇑W.val s ω) ^ 2 ∂timeMeasure ∂μ) + = (T : ℝ) * ‖simpleAssemblyHorizon (μ := μ) T hBmeas W‖ ^ 2 := by + rw [integral_const_mul, simpleAssemblyHorizon_norm_sq] + have hsub : {ω | ε ≤ ⨆ i : Set.Iic T, |driftSimpleProcess hBmeas W.val (i : ℝ≥0) ω|} + ⊆ {ω | ε ^ 2 ≤ (T : ℝ) * ∫ s in Set.Ioc (0 : ℝ≥0) T, (⇑W.val s ω) ^ 2 ∂timeMeasure} := by + intro ω hω + simp only [Set.mem_ofPred_eq] at hω ⊢ + calc ε ^ 2 ≤ (⨆ i : Set.Iic T, |driftSimpleProcess hBmeas W.val (i : ℝ≥0) ω|) ^ 2 := by + simpa [pow_two] using mul_self_le_mul_self hε.le hω + _ ≤ _ := drift_iSup_sq_le T hBmeas W.val ω + have hmono : μ.real {ω | ε ≤ ⨆ i : Set.Iic T, |driftSimpleProcess hBmeas W.val (i : ℝ≥0) ω|} + ≤ μ.real + {ω | ε ^ 2 ≤ (T : ℝ) * ∫ s in Set.Ioc (0 : ℝ≥0) T, (⇑W.val s ω) ^ 2 ∂timeMeasure} := by + rw [measureReal_def, measureReal_def] + exact ENNReal.toReal_mono (measure_ne_top μ _) (measure_mono hsub) + have hchain : ε ^ 2 * + μ.real {ω | ε ≤ ⨆ i : Set.Iic T, |driftSimpleProcess hBmeas W.val (i : ℝ≥0) ω|} + ≤ (T : ℝ) * ‖simpleAssemblyHorizon (μ := μ) T hBmeas W‖ ^ 2 := + (mul_le_mul_of_nonneg_left hmono (by positivity)).trans (hmarkov.trans_eq hintg) + calc μ.real {ω | ε ≤ ⨆ i : Set.Iic T, |driftSimpleProcess hBmeas W.val (i : ℝ≥0) ω|} + = (ε ^ 2)⁻¹ + * (ε ^ 2 * + μ.real {ω | ε ≤ ⨆ i : Set.Iic T, |driftSimpleProcess hBmeas W.val (i : ℝ≥0) ω|}) := by + rw [← mul_assoc, inv_mul_cancel₀ (by positivity), one_mul] + _ ≤ (ε ^ 2)⁻¹ * ((T : ℝ) * ‖simpleAssemblyHorizon (μ := μ) T hBmeas W‖ ^ 2) := + mul_le_mul_of_nonneg_left hchain (by positivity) + +/-- **Summable maximal tail (drift).** For the fast subsequence `V` (`approxSeq`), the probabilities +that the running max of `|drift (Vₙ − Vₙ₊₁)|` over `[0,T]` reaches `(3/4)ⁿ` are summable: Chebyshev +gives `≤ ((3/4)ⁿ)⁻²·T·‖simpleAssemblyHorizon (Vₙ−Vₙ₊₁)‖² ≤ (16/9)ⁿ·T·(2·2⁻ⁿ)² = 4T·(4/9)ⁿ`, and +`4/9 < 1`. -/ +theorem drift_summable_maximal_tail (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) (V : ℕ → TBoundedSP T hBmeas) + (hV : ∀ n, ‖simpleAssemblyHorizon (μ := μ) T hBmeas (V n) - φ‖ ≤ (2⁻¹ : ℝ) ^ n) : + Summable (fun n ↦ μ.real {ω | (3 / 4 : ℝ) ^ n ≤ + ⨆ i : Set.Iic T, |driftSimpleProcess hBmeas (V n - V (n + 1)).val (i : ℝ≥0) ω|}) := by + refine Summable.of_nonneg_of_le (fun n ↦ measureReal_nonneg) (fun n ↦ ?_) + ((summable_geometric_of_lt_one (r := 4 / 9) (by norm_num) (by norm_num)).mul_left (4 * (T : ℝ))) + refine + (drift_maximal_prob T hBmeas (V n - V (n + 1)) (ε := (3 / 4 : ℝ) ^ n) (by positivity)).trans + ?_ + have hnorm : ‖simpleAssemblyHorizon (μ := μ) T hBmeas (V n - V (n + 1))‖ ≤ 2 * (2⁻¹ : ℝ) ^ n := by + rw [map_sub] + calc ‖simpleAssemblyHorizon (μ := μ) T hBmeas (V n) + - simpleAssemblyHorizon (μ := μ) T hBmeas (V (n + 1))‖ + ≤ ‖simpleAssemblyHorizon (μ := μ) T hBmeas (V n) - φ‖ + + ‖φ - simpleAssemblyHorizon (μ := μ) T hBmeas (V (n + 1))‖ := by + have h := norm_add_le (simpleAssemblyHorizon (μ := μ) T hBmeas (V n) - φ) + (φ - simpleAssemblyHorizon (μ := μ) T hBmeas (V (n + 1))) + simpa using h + _ ≤ (2⁻¹ : ℝ) ^ n + (2⁻¹ : ℝ) ^ (n + 1) := by + gcongr + · exact hV n + · rw [norm_sub_rev]; exact hV (n + 1) + _ ≤ 2 * (2⁻¹ : ℝ) ^ n := by + rw [pow_succ]; linarith [pow_nonneg (by norm_num : (0 : ℝ) ≤ 2⁻¹) n] + calc (((3 / 4 : ℝ) ^ n) ^ 2)⁻¹ + * ((T : ℝ) * ‖simpleAssemblyHorizon (μ := μ) T hBmeas (V n - V (n + 1))‖ ^ 2) + ≤ (((3 / 4 : ℝ) ^ n) ^ 2)⁻¹ * ((T : ℝ) * (2 * (2⁻¹ : ℝ) ^ n) ^ 2) := by + gcongr + _ = 4 * (T : ℝ) * (4 / 9 : ℝ) ^ n := by + have e1 : ((3 / 4 : ℝ) ^ n) ^ 2 = (9 / 16 : ℝ) ^ n := by + rw [← pow_mul, mul_comm n 2, pow_mul]; norm_num + have e2 : (2 * (2⁻¹ : ℝ) ^ n) ^ 2 = 4 * (1 / 4 : ℝ) ^ n := by + rw [mul_pow, ← pow_mul, mul_comm n 2, pow_mul]; norm_num + rw [e1, e2, ← inv_pow, show (9 / 16 : ℝ)⁻¹ = 16 / 9 from by norm_num, + show (16 / 9 : ℝ) ^ n * ((T : ℝ) * (4 * (1 / 4 : ℝ) ^ n)) + = 4 * (T : ℝ) * ((16 / 9 : ℝ) ^ n * (1 / 4 : ℝ) ^ n) from by ring, + ← mul_pow, show (16 / 9 : ℝ) * (1 / 4) = 4 / 9 from by norm_num] + +/-- **A.s. eventual smallness (Borel–Cantelli, drift).** Since the maximal tail is summable, for +almost every `ω` the running maximum of `|drift (Vₙ − Vₙ₊₁)|` over `[0,T]` is eventually below +`(3/4)ⁿ` — the pathwise input to the uniform-Cauchy argument. -/ +theorem drift_ae_eventually_sup_lt (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) (V : ℕ → TBoundedSP T hBmeas) + (hV : ∀ n, ‖simpleAssemblyHorizon (μ := μ) T hBmeas (V n) - φ‖ ≤ (2⁻¹ : ℝ) ^ n) : + ∀ᵐ ω ∂μ, ∀ᶠ n in atTop, + (⨆ i : Set.Iic T, |driftSimpleProcess hBmeas (V n - V (n + 1)).val (i : ℝ≥0) ω|) + < (3 / 4 : ℝ) ^ n := by + set A : ℕ → Set Ω := fun n ↦ {ω | (3 / 4 : ℝ) ^ n ≤ + ⨆ i : Set.Iic T, |driftSimpleProcess hBmeas (V n - V (n + 1)).val (i : ℝ≥0) ω|} with hA + have hconv : (∑' n, μ (A n)) ≠ ∞ := by + have heq : ∀ n, μ (A n) = ENNReal.ofReal (μ.real (A n)) := + fun n ↦ (ENNReal.ofReal_toReal (measure_ne_top μ _)).symm + simp_rw [heq] + rw [← ENNReal.ofReal_tsum_of_nonneg (fun n ↦ measureReal_nonneg) + (drift_summable_maximal_tail T hBmeas φ V hV)] + exact ENNReal.ofReal_ne_top + filter_upwards [ae_eventually_notMem hconv] with ω hω + filter_upwards [hω] with n hn + rwa [hA, Set.mem_ofPred_eq, not_le] at hn + +/-! ## Layer 2 — pointwise a.s. convergence of the elementary drifts -/ + +/-- **Pointwise a.s. convergence (drift).** For almost every `ω` and every `t ≤ T`, the +approximating elementary drifts `driftSimpleProcess Vₙ t ω` converge to `driftContinuousMod φ t ω`. +The consecutive distances are eventually `< (3/4)ⁿ` (a.s., uniformly in `t ≤ T`, by +`drift_ae_eventually_sup_lt` + the running-max keystone + subtractivity), hence summable, so the +sequence is Cauchy in `ℝ`. This is the drift analog of `itoContinuousMod_tendsto`, with no +martingale and no exceptional null set beyond the Borel–Cantelli one. -/ +theorem driftContinuousMod_tendsto (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ∀ᵐ ω ∂μ, ∀ t : ℝ≥0, t ≤ T → + Tendsto (fun n ↦ driftSimpleProcess hBmeas ((approxSeq T hBmeas φ).choose n).val t ω) atTop + (𝓝 (driftContinuousMod T hBmeas φ t ω)) := by + set V := (approxSeq T hBmeas φ).choose with hVdef + have hV := (approxSeq T hBmeas φ).choose_spec + filter_upwards [drift_ae_eventually_sup_lt T hBmeas φ V hV] with ω hω + intro t ht + have hcauchy : CauchySeq (fun n ↦ driftSimpleProcess hBmeas (V n).val t ω) := by + apply cauchySeq_of_summable_dist + obtain ⟨N, hN⟩ := eventually_atTop.mp hω + rw [← summable_nat_add_iff N] + refine Summable.of_nonneg_of_le (fun n ↦ dist_nonneg) (fun n ↦ ?_) + (f := fun n ↦ (3 / 4 : ℝ) ^ (n + N)) ?_ + · rw [dist_eq_norm, Real.norm_eq_abs] + have hcoe : ((V (n + N) - V (n + N + 1)).val : SimpleProcess ℝ (natFiltration hBmeas)) + = (V (n + N)).val - (V (n + N + 1)).val := rfl + have hlin : driftSimpleProcess hBmeas (V (n + N)).val t ω + - driftSimpleProcess hBmeas (V (n + N + 1)).val t ω + = driftSimpleProcess hBmeas (V (n + N) - V (n + N + 1)).val t ω := by + rw [hcoe] + exact (congrFun + (driftSimpleProcess_sub hBmeas (V (n + N)).val (V (n + N + 1)).val t) ω).symm + rw [hlin] + exact (drift_norm_le_iSup_Iic hBmeas (V (n + N) - V (n + N + 1)).val ω ht).trans + (hN (n + N) (Nat.le_add_left N n)).le + · simp_rw [pow_add] + exact (summable_geometric_of_lt_one (by norm_num) (by norm_num)).mul_right _ + simpa only [driftContinuousMod, hVdef] using hcauchy.tendsto_limUnder + +/-! ## Layer 3 — the assembled drift's pointwise realization (the crux) -/ + +/-- **The assembled drift, sliced, is the pathwise drift limit.** The abstract `extendOfNorm` +operator `driftProcessAssembled T g : E →L E` — built from the density of `simpleAssemblyHorizon`, +with no pathwise content of its own — has `coeFn` almost everywhere equal to the honest pointwise +`limUnder` process `driftContinuousMod T g`. This is the drift analog of the Itô side's +`itoProcessAssembled` being *built from* `itoContinuousMod`; here the identification must be +**proved**, via two convergences of the same approximating sequence `driftSimpleProcessLp Vₙ` +(`Vₙ → g` in `E`): to `driftProcessAssembled g` by the operator's continuity, and to +`driftContinuousMod T g` a.e. (Layer 2 lifted from the per-slice a.e. to the trim measure — the +convergence set is predictable-measurable, so its product-conull status transfers to the trim via +`trim_measurableSet_eq`). In-measure limits on the finite trim measure are a.e.-unique. -/ +theorem driftProcessAssembled_coeFn (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (g : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ⇑(driftProcessAssembled (μ := μ) T hBmeas g) + =ᵐ[trimMeasure (μ := μ) T hBmeas] Function.uncurry (driftContinuousMod T hBmeas g) := by + set V := (approxSeq T hBmeas g).choose with hVdef + have hV := (approxSeq T hBmeas g).choose_spec + have hGpred : ∀ n, StronglyMeasurable[(natFiltration hBmeas).predictable] + (Function.uncurry (driftSimpleProcess hBmeas (V n).val)) := + fun n ↦ driftSimpleProcess_isStronglyPredictable hBmeas (V n).val + have hHpred : StronglyMeasurable[(natFiltration hBmeas).predictable] + (Function.uncurry (driftContinuousMod T hBmeas g)) := + driftContinuousMod_isStronglyPredictable T hBmeas g + set C := {z : ℝ≥0 × Ω | Tendsto + (fun n ↦ Function.uncurry (driftSimpleProcess hBmeas (V n).val) z) atTop + (𝓝 (Function.uncurry (driftContinuousMod T hBmeas g) z))} with hC + have hCpred : MeasurableSet[(natFiltration hBmeas).predictable] C := by + let : MeasurableSpace (ℝ≥0 × Ω) := (natFiltration hBmeas).predictable + exact measurableSet_tendsto_fun (fun n ↦ (hGpred n).measurable) hHpred.measurable + -- C is prod-conull, built from the per-slice a.e. convergence of Layer 2 + have hCprod : ∀ᵐ z ∂((timeMeasureHorizon T).prod μ), z ∈ C := by + have hset : MeasurableSet C := + measurableSet_tendsto_fun + (fun n ↦ ((hGpred n).mono (natFiltration hBmeas).predictable_le_prod).measurable) + ((hHpred.mono (natFiltration hBmeas).predictable_le_prod).measurable) + refine (Measure.ae_prod_iff_ae_ae hset).mpr ?_ + have hsub : ∀ᵐ t ∂(timeMeasureHorizon T), t ≤ T := by + rw [timeMeasureHorizon] + filter_upwards [ae_restrict_mem measurableSet_Ioc] with t ht using ht.2 + filter_upwards [hsub] with t htT + filter_upwards [driftContinuousMod_tendsto T hBmeas g] with ω hω + exact hω t htT + -- transfer prod-conull ↦ trim-conull (C is predictable-measurable) + have h0 : (trimMeasure (μ := μ) T hBmeas) Cᶜ = 0 := by + rw [show trimMeasure (μ := μ) T hBmeas + = ((timeMeasureHorizon T).prod μ).trim (natFiltration hBmeas).predictable_le_prod from rfl, + trim_measurableSet_eq (natFiltration hBmeas).predictable_le_prod hCpred.compl] + exact hCprod + have hae_trim : ∀ᵐ z ∂(trimMeasure (μ := μ) T hBmeas), z ∈ C := by + rw [ae_iff]; exact h0 + -- the E-limit: driftSimpleProcessLp Vₙ → driftProcessAssembled g by CLM continuity + have hsa : Tendsto (fun n ↦ simpleAssemblyHorizon (μ := μ) T hBmeas (V n)) atTop (𝓝 g) := by + rw [tendsto_iff_norm_sub_tendsto_zero] + exact squeeze_zero (fun n ↦ norm_nonneg _) hV + (tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num) (by norm_num)) + have hLp : Tendsto (fun n ↦ driftSimpleProcessLp (μ := μ) T hBmeas (V n).val) atTop + (𝓝 (driftProcessAssembled (μ := μ) T hBmeas g)) := by + have hrw : (fun n ↦ driftSimpleProcessLp (μ := μ) T hBmeas (V n).val) + = fun n ↦ + driftProcessAssembled (μ := μ) T hBmeas + (simpleAssemblyHorizon (μ := μ) T hBmeas (V n)) := + funext fun n ↦ (driftProcessAssembled_simpleAssembly T hBmeas (V n)).symm + rw [hrw] + exact ((driftProcessAssembled (μ := μ) T hBmeas).continuous.tendsto g).comp hsa + -- two convergences in measure, then a.e.-uniqueness + have hGmeas := fun n ↦ + (memLp_uncurry_driftSimpleProcess (μ := μ) T hBmeas (V n).val).aestronglyMeasurable + have hmeasG : TendstoInMeasure (trimMeasure (μ := μ) T hBmeas) + (fun n ↦ Function.uncurry (driftSimpleProcess hBmeas (V n).val)) atTop + (Function.uncurry (driftContinuousMod T hBmeas g)) := + tendstoInMeasure_of_tendsto_ae hGmeas hae_trim + have heLp : Tendsto (fun n ↦ eLpNorm (Function.uncurry (driftSimpleProcess hBmeas (V n).val) + - ⇑(driftProcessAssembled (μ := μ) T hBmeas g)) 2 (trimMeasure (μ := μ) T hBmeas)) + atTop (𝓝 0) := by + refine (Lp.tendsto_Lp_iff_tendsto_eLpNorm'' + (fun n ↦ Function.uncurry (driftSimpleProcess hBmeas (V n).val)) + (fun n ↦ memLp_uncurry_driftSimpleProcess T hBmeas (V n).val) + (⇑(driftProcessAssembled (μ := μ) T hBmeas g)) (Lp.memLp _)).mp ?_ + simp only [Lp.toLp_coeFn] + exact hLp + have hmeasP : TendstoInMeasure (trimMeasure (μ := μ) T hBmeas) + (fun n ↦ Function.uncurry (driftSimpleProcess hBmeas (V n).val)) atTop + (⇑(driftProcessAssembled (μ := μ) T hBmeas g)) := + tendstoInMeasure_of_tendsto_eLpNorm (by norm_num) heLp + exact (tendstoInMeasure_ae_unique hmeasG hmeasP).symm + +/-! ## Layer 4 refinement — the pathwise drift as an honest single Lebesgue integral -/ + +/-- **The ω-slice energy of a simple embedding minus a target.** `∫_Ω ∫₀ᵀ (⇑W − ⇑g)² ds dμ` equals +the squared `E`-distance `‖simpleAssemblyHorizon W − g‖²` — the driver of the `L¹(μ)` decay +`Dₙ(ω) → 0` used in `driftContinuousMod_eq_setIntegral`. Tonelli through the trim↔product transfer +(`integral_trim_ae` + `ae_eq_of_ae_eq_trim`, both keyed off `AEStronglyMeasurable` w.r.t. the +trim). -/ +theorem drift_slice_energy_eq (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (g : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) (W : TBoundedSP T hBmeas) : + (∫ ω, ∫ s in Set.Ioc (0 : ℝ≥0) T, (⇑W.val s ω - ⇑g (s, ω)) ^ 2 ∂timeMeasure ∂μ) + = ‖simpleAssemblyHorizon (μ := μ) T hBmeas W - g‖ ^ 2 := by + set 𝓕 := natFiltration (mΩ := mΩ) hBmeas + set h := simpleAssemblyHorizon (μ := μ) T hBmeas W - g with hh + -- ⇑h agrees a.e. with the pointwise difference + have hcoe : ⇑h =ᵐ[trimMeasure (μ := μ) T hBmeas] fun z ↦ ⇑W.val z.1 z.2 - ⇑g z := by + have h1 : ⇑h =ᵐ[trimMeasure (μ := μ) T hBmeas] + ⇑(simpleAssemblyHorizon (μ := μ) T hBmeas W) - ⇑g := Lp.coeFn_sub _ _ + have h2 : ⇑(simpleAssemblyHorizon (μ := μ) T hBmeas W) + =ᵐ[trimMeasure (μ := μ) T hBmeas] Function.uncurry ⇑W.val := + (memLp_uncurry_trimMeasure (μ := μ) T hBmeas W.val).coeFn_toLp + filter_upwards [h1, h2] with z hz1 hz2 + rw [hz1, Pi.sub_apply, hz2]; rfl + have hcoe_prod : ⇑h =ᵐ[(timeMeasureHorizon T).prod μ] fun z ↦ ⇑W.val z.1 z.2 - ⇑g z := + ae_eq_of_ae_eq_trim hcoe + have hcoesq : (fun z ↦ (⇑h z) ^ 2) + =ᵐ[(timeMeasureHorizon T).prod μ] fun z ↦ (⇑W.val z.1 z.2 - ⇑g z) ^ 2 := by + filter_upwards [hcoe_prod] with z hz; rw [hz] + -- ⇑h is L² over the product, so (⇑h)² is integrable there + have hmemh_prod : MemLp (⇑h) 2 ((timeMeasureHorizon T).prod μ) := memLp_prod_of_lp T hBmeas h + have hinth : Integrable (fun z ↦ (⇑h z) ^ 2) ((timeMeasureHorizon T).prod μ) := + hmemh_prod.integrable_sq + have hintdiff : Integrable (fun z ↦ (⇑W.val z.1 z.2 - ⇑g z) ^ 2) + ((timeMeasureHorizon T).prod μ) := + hinth.congr hcoesq + have hsm_hsq : AEStronglyMeasurable[𝓕.predictable] (fun z ↦ (⇑h z) ^ 2) + (trimMeasure (μ := μ) T hBmeas) := (Lp.aestronglyMeasurable h).pow 2 + have htrim2 : (∫ z, (⇑h z) ^ 2 ∂trimMeasure (μ := μ) T hBmeas) + = ∫ z, (⇑h z) ^ 2 ∂((timeMeasureHorizon T).prod μ) := + (integral_trim_ae 𝓕.predictable_le_prod hsm_hsq).symm + rw [lp_two_norm_sq, htrim2, integral_congr_ae hcoesq, integral_prod _ hintdiff] + exact integral_integral_swap hintdiff.swap + +/-- **The prod-`L²` integrability of a simple embedding minus a target's pointwise difference +squared** — the Fubini feed for the ω-slice energy `Dₙ`. -/ +theorem drift_slice_sq_integrable (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (g : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) (W : TBoundedSP T hBmeas) : + Integrable (fun z ↦ (⇑W.val z.1 z.2 - ⇑g z) ^ 2) ((timeMeasureHorizon T).prod μ) := by + set 𝓕 := natFiltration (mΩ := mΩ) hBmeas + set h := simpleAssemblyHorizon (μ := μ) T hBmeas W - g with hh + have h2 : ⇑(simpleAssemblyHorizon (μ := μ) T hBmeas W) + =ᵐ[trimMeasure (μ := μ) T hBmeas] Function.uncurry ⇑W.val := + (memLp_uncurry_trimMeasure (μ := μ) T hBmeas W.val).coeFn_toLp + have hcoe_trim : ⇑h =ᵐ[trimMeasure (μ := μ) T hBmeas] fun z ↦ ⇑W.val z.1 z.2 - ⇑g z := by + filter_upwards [Lp.coeFn_sub (simpleAssemblyHorizon (μ := μ) T hBmeas W) g, h2] with z hz1 hz2 + rw [hz1, Pi.sub_apply, hz2]; rfl + have hcoe : ⇑h =ᵐ[(timeMeasureHorizon T).prod μ] fun z ↦ ⇑W.val z.1 z.2 - ⇑g z := + ae_eq_of_ae_eq_trim hcoe_trim + exact (memLp_prod_of_lp T hBmeas h).integrable_sq.congr + (by filter_upwards [hcoe] with z hz; rw [hz]) + +/-- **The pathwise drift limit is a Lebesgue integral.** For every `t ≤ T`, the pointwise `limUnder` +drift `driftContinuousMod T g t ω` equals the time integral `∫_{(0,t]} ⇑g(s,ω) ds` of the +representative `⇑g` of the class `g`, for almost every `ω`. Applied at `g = lipComp b X`, this +writes the drift term of `sde_pathwise_decomposition` as the time integral of a representative of +`b∘X`; the per-path identity with `∫₀ᵗ b(X_s(ω)) ds` for a chosen representative of `X` is not +stated. The elementary drifts satisfy `driftSimpleProcess Vₙ t ω = ∫₀ᵗ ⇑Vₙ(s,ω) ds` and converge to +`driftContinuousMod` (Layer 2); the ω-slice energies `Dₙ(ω) = ∫₀ᵀ (⇑Vₙ − ⇑g)²(s,ω) ds` decay in +`L¹(μ)` (`= ‖simpleAssemblyHorizon Vₙ − g‖² → 0`, `drift_slice_energy_eq`), so along a subsequence +`Dₙₖ(ω) → 0` a.e., whence the interval Cauchy–Schwarz `|∫₀ᵗ(⇑Vₙₖ − ⇑g)| ≤ √(T·Dₙₖ(ω)) → 0` forces +`∫₀ᵗ ⇑Vₙₖ → ∫₀ᵗ ⇑g`. Matching the two limits. -/ +theorem driftContinuousMod_eq_setIntegral (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (g : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) {t : ℝ≥0} (ht : t ≤ T) : + ∀ᵐ ω ∂μ, driftContinuousMod T hBmeas g t ω + = ∫ s in Set.Ioc (0 : ℝ≥0) t, ⇑g (s, ω) ∂timeMeasure := by + set V := (approxSeq T hBmeas g).choose with hVdef + have hV := (approxSeq T hBmeas g).choose_spec + have : IsFiniteMeasure (timeMeasure.restrict (Set.Ioc (0 : ℝ≥0) t)) := + ⟨by rw [Measure.restrict_apply_univ, timeMeasure_Ioc]; exact ENNReal.ofReal_lt_top⟩ + have hg_prod : MemLp (⇑g) 2 ((timeMeasureHorizon T).prod μ) := memLp_prod_of_lp T hBmeas g + have hg_slice : ∀ᵐ ω ∂μ, MemLp (fun s ↦ ⇑g (s, ω)) 2 (timeMeasureHorizon T) := by + filter_upwards [hg_prod.aestronglyMeasurable.prodMk_right, + hg_prod.integrable_sq.prod_left_ae] with ω hω1 hω2 + exact (memLp_two_iff_integrable_sq hω1).mpr hω2 + -- the ω-slice energy and its L¹(μ) decay + set D : ℕ → Ω → ℝ := fun n ω ↦ + ∫ s in Set.Ioc (0 : ℝ≥0) T, (⇑(V n).val s ω - ⇑g (s, ω)) ^ 2 ∂timeMeasure with hDdef + have hDnn : ∀ n, 0 ≤ᵐ[μ] D n := fun n ↦ ae_of_all _ fun ω ↦ integral_nonneg fun s ↦ sq_nonneg _ + have hDint : ∀ n, Integrable (D n) μ := + fun n ↦ (drift_slice_sq_integrable T hBmeas g (V n)).integral_prod_right + have hD0 : Tendsto (fun n ↦ ∫ ω, D n ω ∂μ) atTop (𝓝 0) := by + have heq : ∀ n, (∫ ω, D n ω ∂μ) = ‖simpleAssemblyHorizon (μ := μ) T hBmeas (V n) - g‖ ^ 2 := + fun n ↦ drift_slice_energy_eq T hBmeas g (V n) + simp_rw [heq] + have h0 : Tendsto (fun n ↦ ‖simpleAssemblyHorizon (μ := μ) T hBmeas (V n) - g‖) atTop (𝓝 0) := + squeeze_zero (fun n ↦ norm_nonneg _) hV + (tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num) (by norm_num)) + simpa using h0.pow 2 + -- L¹ decay ⟹ convergence in measure ⟹ a.e.-convergent subsequence + have hDeLp : Tendsto (fun n ↦ eLpNorm (D n - fun _ ↦ (0 : ℝ)) 1 μ) atTop (𝓝 0) := by + have hrw : ∀ n, eLpNorm (D n - fun _ ↦ (0 : ℝ)) 1 μ = ENNReal.ofReal (∫ ω, D n ω ∂μ) := by + intro n + have hsub : (D n - fun _ ↦ (0 : ℝ)) = D n := by funext ω; simp + have hlint : (∫⁻ ω, ‖D n ω‖ₑ ∂μ) = ∫⁻ ω, ENNReal.ofReal (D n ω) ∂μ := by + refine lintegral_congr_ae ?_ + filter_upwards [hDnn n] with ω hω + rw [Real.eNorm_eq_ofReal_abs, abs_of_nonneg hω] + rw [hsub, eLpNorm_one_eq_lintegral_eNorm (hDint n).aestronglyMeasurable, hlint, + ← ofReal_integral_eq_lintegral_ofReal (hDint n) (hDnn n)] + rw [tendsto_congr hrw, ← ENNReal.ofReal_zero] + exact (ENNReal.continuous_ofReal.tendsto 0).comp hD0 + have hDmeasure : TendstoInMeasure μ D atTop (fun _ ↦ (0 : ℝ)) := + tendstoInMeasure_of_tendsto_eLpNorm one_ne_zero hDeLp + obtain ⟨ns, hns_mono, hns_ae⟩ := hDmeasure.exists_seq_tendsto_ae + -- combine, a.e. ω + filter_upwards [hns_ae, hg_slice, driftContinuousMod_tendsto T hBmeas g] with ω hωD hωg hωlim + have hlim_sub : Tendsto (fun k ↦ driftSimpleProcess hBmeas (V (ns k)).val t ω) atTop + (𝓝 (driftContinuousMod T hBmeas g t ω)) := (hωlim t ht).comp hns_mono.tendsto_atTop + have hlim_int : Tendsto (fun k ↦ driftSimpleProcess hBmeas (V (ns k)).val t ω) atTop + (𝓝 (∫ s in Set.Ioc (0 : ℝ≥0) t, ⇑g (s, ω) ∂timeMeasure)) := by + rw [tendsto_iff_dist_tendsto_zero] + refine squeeze_zero (fun k ↦ dist_nonneg) (fun k ↦ ?_) + (g := fun k ↦ Real.sqrt ((T : ℝ) * D (ns k) ω)) ?_ + · -- dist bound via interval Cauchy–Schwarz + have hVt : MemLp (fun s ↦ ⇑(V (ns k)).val s ω) 2 (timeMeasure.restrict (Set.Ioc 0 t)) := + (memLp_slice T hBmeas (V (ns k)).val ω).mono_measure + (Measure.restrict_mono (Set.Ioc_subset_Ioc_right ht) le_rfl) + have hgt : MemLp (fun s ↦ ⇑g (s, ω)) 2 (timeMeasure.restrict (Set.Ioc 0 t)) := + hωg.mono_measure (Measure.restrict_mono (Set.Ioc_subset_Ioc_right ht) le_rfl) + have hfT : MemLp (fun s ↦ ⇑(V (ns k)).val s ω - ⇑g (s, ω)) 2 + (timeMeasure.restrict (Set.Ioc (0 : ℝ≥0) T)) := + (memLp_slice T hBmeas (V (ns k)).val ω).sub hωg + rw [Real.dist_eq, ← Real.sqrt_sq_eq_abs] + refine Real.sqrt_le_sqrt ?_ + rw [driftSimpleProcess_eq_setIntegral, + ← integral_sub (hVt.integrable (by norm_num)) (hgt.integrable (by norm_num))] + calc (∫ s in Set.Ioc (0 : ℝ≥0) t, (⇑(V (ns k)).val s ω - ⇑g (s, ω)) ∂timeMeasure) ^ 2 + ≤ (timeMeasure.restrict (Set.Ioc (0 : ℝ≥0) t)).real Set.univ + * ∫ s in Set.Ioc (0 : ℝ≥0) t, (⇑(V (ns k)).val s ω - ⇑g (s, ω)) ^ 2 ∂timeMeasure := + sq_integral_le_measureReal_mul (hVt.sub hgt) + _ ≤ (T : ℝ) * D (ns k) ω := by + rw [measureReal_def, Measure.restrict_apply_univ, timeMeasure_Ioc, + ENNReal.toReal_ofReal (by rw [NNReal.coe_zero, sub_zero]; exact t.coe_nonneg), + NNReal.coe_zero, sub_zero] + refine mul_le_mul (by exact_mod_cast ht) ?_ (integral_nonneg fun s ↦ sq_nonneg _) + T.coe_nonneg + exact setIntegral_mono_set hfT.integrable_sq (ae_of_all _ fun s ↦ sq_nonneg _) + (ae_of_all _ fun _ h ↦ Set.Ioc_subset_Ioc_right ht h) + · rw [← Real.sqrt_zero, ← mul_zero (T : ℝ)] + exact (Real.continuous_sqrt.tendsto _).comp (tendsto_const_nhds.mul hωD) + exact tendsto_nhds_unique hlim_sub hlim_int + +end ItoIntegralProcessContinuousModification +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/DriftProcessPredictable.lean b/LeanPool/MathFin/Probability/Brownian/Ito/DriftProcessPredictable.lean new file mode 100644 index 0000000000..0020ef8fed --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/DriftProcessPredictable.lean @@ -0,0 +1,462 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Analysis.FiniteMeasureCauchySchwarz +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessContinuousModification + +/-! # Predictability and `L²` assembly of the drift process (SDE-existence keystone II) + +The Picard iterate for the SDE `dX = b(X)dt + σ(X)dB` is +`Φ(X)_t = η + ∫₀ᵗ b(X_s) ds + ∫₀ᵗ σ(X_s) dB_s`. The Itô term was assembled into +the predictable `L²` space `E := Lp ℝ 2 (trimMeasure T)` in +`ItoProcessPredictable`. This file does the same for the **drift** term +`t ↦ ∫₀ᵗ g(s, ω) ds`: it too must land back in `E` (predictable `L²`), because the +*next* iterate is fed through the Itô integral, whose integrand domain is `E`. + +The drift is pure Lebesgue integration, so — unlike the Itô side — **none of this +needs the Brownian motion `B` itself** (`IsPreBrownianReal`), only its *filtration* +`natFiltration hBmeas`. Each elementary drift `driftSimpleProcess V` (the Lebesgue +integral of the step process `V`) is genuinely continuous and adapted for **every** +`ω` — a finite sum of `𝓕`-measurable coefficients times deterministic continuous +time-increments — so Degenne's `StronglyAdapted.isStronglyPredictable_of_leftContinuous` +applies to the base case. The contrast with the Itô side is the elegant part: there +the continuous version is only `∀ᵐ ω`-continuous and adapted to the *augmented* +filtration, so the theorem is applied per-elementary-process to dodge that friction; +here there is no friction to dodge — no randomness in the time-regularity means no +exceptional null set — and the theorem applies to the raw `natFiltration` directly. + +**Part 1 — predictability.** +* `driftSimpleProcess` — the elementary drift `∑_p V(p)(ω)·((p.2 ∧ t) − (p.1 ∧ t))`. +* `driftSimpleProcess_continuous` / `_stronglyAdapted` / `_isStronglyPredictable`. +* `driftContinuousMod` / `_isStronglyPredictable` — the pointwise-`limUnder` drift-limit + process (via `StronglyMeasurable.limUnder`) and its predictability. Provided for + **parity with the Itô side's `itoContinuousMod`**, a genuine everywhere-defined + pathwise realization for future SDE-path-continuity use; the `L²` keystone below + does **not** route through it (its predictability comes for free from membership in + the predictable trim space `E`). + +**Part 2 — the drift as a bounded operator on `E`.** +* `driftSimpleProcess_eq_setIntegral` — the honest-integral bridge + `driftSimpleProcess V t ω = ∫₀ᵗ ⇑V(s,ω) ds` (against `timeMeasure`). +* `driftSimpleProcessLp` — the elementary drift packaged as an element of `E`. +* `driftSimpleProcessLp_norm_le` — the energy bound + `‖driftSimpleProcessLp V‖ ≤ T·‖simpleAssemblyHorizon V‖` (Tonelli → pointwise Cauchy–Schwarz → + Fubini → the outer `∫₀ᵀ`). +* `driftProcessAssembled` — **the keystone**: `g ↦ (t ↦ ∫₀ᵗ g(s,·) ds)` as a CLM + `E →L E`. Because it is a CLM into the predictable trim space `E`, it is linear, + bounded (`‖·‖ ≤ T‖·‖`), and predictable — all for free. That routing through `E`, + rather than re-proving each property by hand, is the payoff of this construction. + +## Main definitions + +* `driftSimpleProcess`: the elementary drift (Lebesgue) integral `∫₀ᵗ V(s, ω) ds` of a simple + process `V`. +* `driftSimpleProcessLp`: the elementary drift assembled as an element of + `Lp ℝ 2 (trimMeasure T)`. +* `driftProcessLM`: the elementary drift as a linear map on the `T`-bounded simple processes. +* `driftProcessAssembled`: the continuous linear extension of that map to + `Lp ℝ 2 (trimMeasure T)`. +* `driftContinuousMod`: the pathwise drift-limit process of an integrand `φ`, defined by a + pointwise limit. + +## Main results + +* `driftSimpleProcess_continuous`, `driftSimpleProcess_stronglyAdapted`, + `driftSimpleProcess_isStronglyPredictable`: the elementary drift has continuous paths, is + adapted, and is predictable. +* `driftSimpleProcess_eq_setIntegral`: the elementary drift is the Lebesgue integral of the + process over `(0, t]`. +* `driftSimpleProcessLp_norm_le`: the `L²` energy bound of the elementary drift for `T`-bounded + simple processes. +* `driftProcessAssembled_norm_le`: `‖driftProcessAssembled φ‖ ≤ T‖φ‖`. +* `driftContinuousMod_isStronglyPredictable`, `driftContinuousMod_stronglyAdapted`: the + pathwise drift-limit process is predictable and adapted. + +## Tags + +drift term, Picard iteration, SDE existence, predictable process, Lebesgue integral, L2 operator, +MSC 60H10, MSC 60H05 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Filter Topology +open scoped NNReal ENNReal + +namespace MathFin +namespace ItoIntegralProcessContinuousModification +open ItoIntegralL2 ItoIntegralCLM ItoIntegralProcess ItoIntegralProcessGeneral + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} + +/-- `timeMeasure` restricted to any bounded time-interval `(a, b]` is finite +(`timeMeasure (a, b] = ofReal (b − a) < ∞`), so the Cauchy–Schwarz / `L²` steps +below on `(0, t]` find their finiteness instance by resolution. -/ +private instance isFiniteMeasure_timeMeasure_restrict_Ioc (a b : ℝ≥0) : + IsFiniteMeasure (timeMeasure.restrict (Set.Ioc a b)) := + ⟨by rw [Measure.restrict_apply_univ, timeMeasure_Ioc]; exact ENNReal.ofReal_lt_top⟩ + +/-- **The elementary drift (Lebesgue) integral** of a simple process `V`: +`driftSimpleProcess V t ω = ∑_p V(p)(ω)·((p.2 ∧ t) − (p.1 ∧ t))`. This is exactly +`∫₀ᵗ V_tilde(s, ω) ds` for the step process `V_tilde = ∑_p V(p)·𝟙_{(p.1, p.2]}` — the time +increment `(p.2 ∧ t) − (p.1 ∧ t)` is the Lebesgue length of `(p.1, p.2] ∩ (0, t]`. +(The clamp `min · t` is taken in `ℝ≥0` and then coerced, so the increment matches +`timeMeasure_Ioc_inter`'s `ℝ≥0`-valued endpoints definitionally in the bridge below.) -/ +noncomputable def driftSimpleProcess (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration hBmeas)) (t : ℝ≥0) (ω : Ω) : ℝ := + V.value.sum fun p v ↦ v ω * (((min p.2 t : ℝ≥0) : ℝ) - ((min p.1 t : ℝ≥0) : ℝ)) + +/-- **Path continuity of the elementary drift.** For every `ω`, `t ↦ driftSimpleProcess V t ω` +is continuous: a finite sum of `V(p)(ω)` (constant in `t`) times the continuous +time-increment `(p.2 ∧ t) − (p.1 ∧ t)` (continuous clamp `t ↦ min c t`, then the +coercion `ℝ≥0 → ℝ`). -/ +theorem driftSimpleProcess_continuous (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration hBmeas)) (ω : Ω) : + Continuous (fun t : ℝ≥0 ↦ driftSimpleProcess hBmeas V t ω) := by + simp only [driftSimpleProcess, Finsupp.sum] + fun_prop + +/-- **The elementary drift is adapted.** For each `t`, `driftSimpleProcess V t` is +`𝓕_t`-measurable: it is `∑_p V(p)·c_p(t)` with `c_p(t) := (p.2 ∧ t) − (p.1 ∧ t)` a +real constant; for `p.1 ≤ t` the coefficient `V(p)` is `𝓕_{p.1} ⊆ 𝓕_t`-measurable, and +for `p.1 > t` the increment `c_p(t)` collapses to `0` (both endpoints clamp to `t`). -/ +theorem driftSimpleProcess_stronglyAdapted (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration hBmeas)) : + StronglyAdapted (natFiltration hBmeas) (driftSimpleProcess hBmeas V) := by + intro t + have hsm : ∀ p ∈ V.value.support, StronglyMeasurable[natFiltration hBmeas t] + (fun ω ↦ V.value p ω * (((min p.2 t : ℝ≥0) : ℝ) - ((min p.1 t : ℝ≥0) : ℝ))) := by + intro p hp + by_cases ht : p.1 ≤ t + · exact + (((V.measurable_value p).mono ((natFiltration hBmeas).mono ht) + le_rfl).stronglyMeasurable).mul + stronglyMeasurable_const + · rw [not_le] at ht + have h1 : min p.1 t = t := min_eq_right ht.le + have h2 : min p.2 t = t := min_eq_right (ht.le.trans (V.le_of_mem_support_value p hp)) + simp only [h1, h2, sub_self, mul_zero] + exact stronglyMeasurable_const + exact Finset.stronglyMeasurable_fun_sum _ hsm + +/-- **The elementary drift is predictable** as a space-time function — genuinely +(every `ω`) continuous, hence left-continuous, and genuinely adapted, so Degenne's +`StronglyAdapted.isStronglyPredictable_of_leftContinuous` applies (the base case, +sidestepping the a.e./everywhere friction). -/ +theorem driftSimpleProcess_isStronglyPredictable (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration hBmeas)) : + IsStronglyPredictable (natFiltration hBmeas) (driftSimpleProcess hBmeas V) := by + apply MeasureTheory.StronglyAdapted.isStronglyPredictable_of_leftContinuous + · exact driftSimpleProcess_stronglyAdapted hBmeas V + · exact fun ω a ↦ (driftSimpleProcess_continuous hBmeas V ω).continuousWithinAt + +/-- The pathwise drift-limit process: for each `t, ω` the limit (junk off the +convergence set) of the elementary drifts of a fixed approximating sequence `Vₙ` +(`approxSeq`'s choice for `φ`). -/ +noncomputable def driftContinuousMod (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) (t : ℝ≥0) (ω : Ω) : ℝ := + limUnder atTop fun n ↦ driftSimpleProcess hBmeas ((approxSeq T hBmeas φ).choose n).val t ω + +/-- **The assembled drift is predictable** (general integrand). By construction +`driftContinuousMod` is the pointwise `limUnder` of the elementary drifts of a fixed +approximating sequence; each is predictable (`driftSimpleProcess_isStronglyPredictable`), +and `StronglyMeasurable.limUnder` lifts predictability to the limit. -/ +theorem driftContinuousMod_isStronglyPredictable (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + IsStronglyPredictable (natFiltration hBmeas) (driftContinuousMod T hBmeas φ) := by + rw [IsStronglyPredictable] + have hrw : (Function.uncurry (driftContinuousMod T hBmeas φ)) + = fun z : ℝ≥0 × Ω ↦ limUnder atTop (fun n ↦ + Function.uncurry (driftSimpleProcess hBmeas + ((approxSeq T hBmeas φ).choose n).val) z) := by + funext z; rfl + rw [hrw] + let : MeasurableSpace (ℝ≥0 × Ω) := (natFiltration hBmeas).predictable + exact StronglyMeasurable.limUnder (fun n ↦ + driftSimpleProcess_isStronglyPredictable hBmeas + ((approxSeq T hBmeas φ).choose n).val) + +/-- **The assembled drift is fixed-time `𝓕`-adapted.** At each `t`, `driftContinuousMod T φ t` is +the pointwise `limUnder` of the elementary drifts `driftSimpleProcess (approxSeq φ)ₙ t`, each +`𝓕 t`-strongly-measurable (`driftSimpleProcess_stronglyAdapted`), and `StronglyMeasurable.limUnder` +lifts adaptedness to the limit — the pointwise-in-time companion of +`driftContinuousMod_isStronglyPredictable`, feeding the `IsExpQMartingale.adapted` field of the +predictable-θ Girsanov theorem. -/ +theorem driftContinuousMod_stronglyAdapted (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + StronglyAdapted (natFiltration hBmeas) (driftContinuousMod T hBmeas φ) := by + intro t + let : MeasurableSpace Ω := (natFiltration hBmeas t : MeasurableSpace Ω) + exact StronglyMeasurable.limUnder fun n ↦ + driftSimpleProcess_stronglyAdapted hBmeas ((approxSeq T hBmeas φ).choose n).val t + +/-! ## Part 2 — the drift assembled into `E` (`L²`, energy bound, linearity) -/ + +/-- **Bridge to the honest Lebesgue integral.** The elementary drift is literally the +Lebesgue integral `∫₀ᵗ ⇑V(s,ω) ds` (against `timeMeasure`) of the step process `⇑V`: on +`(0,t]` the `⊥`-fibre vanishes and `⇑V(s,ω) = ∑_p 𝟙_{(p.1,p.2]}(s)·V(p)(ω)`, so each interval +contributes `V(p)(ω)·timeMeasure((0,t] ∩ (p.1,p.2])`, whose real value is the time-increment +`(p.2 ∧ t) − (p.1 ∧ t)`. This is the identity the `L²` bound reads through Cauchy–Schwarz. -/ +theorem driftSimpleProcess_eq_setIntegral (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration hBmeas)) (t : ℝ≥0) (ω : Ω) : + driftSimpleProcess hBmeas V t ω = ∫ s in Set.Ioc (0 : ℝ≥0) t, ⇑V s ω ∂timeMeasure := by + have htoReal : ∀ p : ℝ≥0 × ℝ≥0, p.1 ≤ p.2 → + (timeMeasure (Set.Ioc (0 : ℝ≥0) t ∩ Set.Ioc p.1 p.2)).toReal + = ((min p.2 t : ℝ≥0) : ℝ) - ((min p.1 t : ℝ≥0) : ℝ) := by + intro p hp12 + rw [Set.inter_comm, timeMeasure_Ioc_inter, NNReal.coe_zero, max_eq_left p.1.coe_nonneg, + NNReal.coe_min, NNReal.coe_min] + by_cases ht : p.1 ≤ t + · rw [ENNReal.toReal_ofReal (by + have : (p.1 : ℝ) ≤ min (p.2 : ℝ) t := + le_min (by exact_mod_cast hp12) (by exact_mod_cast ht) + linarith), min_eq_left (by exact_mod_cast ht : (p.1 : ℝ) ≤ t)] + · rw [not_le] at ht + have htp1 : (t : ℝ) ≤ p.1 := le_of_lt (by exact_mod_cast ht) + have htp2 : (t : ℝ) ≤ p.2 := htp1.trans (by exact_mod_cast hp12) + rw [min_eq_right htp2, min_eq_right htp1, sub_self, + ENNReal.ofReal_eq_zero.mpr (by linarith), ENNReal.toReal_zero] + have hV_eq : Set.EqOn (fun s ↦ ⇑V s ω) + (fun s ↦ ∑ p ∈ V.value.support, (Set.Ioc p.1 p.2).indicator (fun _ ↦ V.value p ω) s) + (Set.Ioc (0 : ℝ≥0) t) := by + intro s hs + have hs0 : s ∉ ({⊥} : Set ℝ≥0) := by + simp only [Set.mem_singleton_iff] + rintro rfl + exact absurd hs.1 not_lt_bot + simp only [SimpleProcess.apply_eq, Set.indicator_of_notMem hs0, zero_add, Finsupp.sum] + have hint : ∀ p ∈ V.value.support, + Integrable (fun s ↦ (Set.Ioc p.1 p.2).indicator (fun _ ↦ V.value p ω) s) + (timeMeasure.restrict (Set.Ioc (0 : ℝ≥0) t)) := + fun p _ ↦ (integrable_const (V.value p ω)).indicator measurableSet_Ioc + rw [driftSimpleProcess, Finsupp.sum, setIntegral_congr_fun measurableSet_Ioc hV_eq, + integral_finsetSum _ hint] + refine Finset.sum_congr rfl (fun p hp ↦ ?_) + rw [setIntegral_indicator measurableSet_Ioc, setIntegral_const, smul_eq_mul, + measureReal_def, htoReal p (V.le_of_mem_support_value p hp), mul_comm] + +/-- **The elementary drift is `L²`** — indeed bounded. Each term satisfies +`|V(p)(ω)·((p.2 ∧ t) − (p.1 ∧ t))| ≤ valueBound·p.2` (the coefficient is bounded and the +time-increment lies in `[0, p.2]`), so the finite sum is bounded by the constant +`∑_p valueBound·p.2`; being predictable on the finite measure `trimMeasure T`, it is `MemLp`. -/ +theorem memLp_uncurry_driftSimpleProcess (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration hBmeas)) : + MemLp (Function.uncurry (driftSimpleProcess hBmeas V)) 2 (trimMeasure (μ := μ) T hBmeas) := by + refine MemLp.of_bound (driftSimpleProcess_isStronglyPredictable hBmeas V).aestronglyMeasurable + (∑ p ∈ V.value.support, V.valueBound * (p.2 : ℝ)) (ae_of_all _ fun z ↦ ?_) + rw [Function.uncurry_apply_pair, driftSimpleProcess, Finsupp.sum, Real.norm_eq_abs] + refine (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum fun p hp ↦ ?_) + rw [abs_mul] + have hval : |V.value p z.2| ≤ V.valueBound := by + rw [← Real.norm_eq_abs]; exact V.value_le_valueBound p z.2 + have hc : |((min p.2 z.1 : ℝ≥0) : ℝ) - ((min p.1 z.1 : ℝ≥0) : ℝ)| ≤ (p.2 : ℝ) := by + rw [abs_of_nonneg (by + have : ((min p.1 z.1 : ℝ≥0) : ℝ) ≤ ((min p.2 z.1 : ℝ≥0) : ℝ) := by + exact_mod_cast min_le_min_right z.1 (V.le_of_mem_support_value p hp) + linarith)] + have h1 : ((min p.2 z.1 : ℝ≥0) : ℝ) ≤ (p.2 : ℝ) := by exact_mod_cast min_le_left p.2 z.1 + have h2 : (0 : ℝ) ≤ ((min p.1 z.1 : ℝ≥0) : ℝ) := (min p.1 z.1).coe_nonneg + linarith + exact mul_le_mul hval hc (abs_nonneg _) (le_trans (abs_nonneg _) hval) + +/-- **The elementary-drift slice is `L²` in the time variable** (bounded step process on the +finite measure `timeMeasure.restrict (Ioc 0 T)`). -/ +theorem memLp_slice (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration hBmeas)) (ω : Ω) : + MemLp (fun s ↦ ⇑V s ω) 2 (timeMeasure.restrict (Set.Ioc (0 : ℝ≥0) T)) := by + refine MemLp.of_bound + (((V.isStronglyPredictable.mono (natFiltration hBmeas).predictable_le_prod).comp_measurable + (measurable_id.prodMk measurable_const)).aestronglyMeasurable) + (V.valueBotBound + ∑ p ∈ V.value.support, V.valueBound) (ae_of_all _ fun s ↦ ?_) + rw [SimpleProcess.apply_eq, Real.norm_eq_abs] + refine (abs_add_le _ _).trans (add_le_add ?_ ?_) + · rw [Set.indicator] + split_ifs with h + · exact V.valueBot_le_valueBotBound ω + · rw [abs_zero]; exact V.valueBotBound_nonneg + · rw [Finsupp.sum] + refine (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum fun p _ ↦ ?_) + rw [Set.indicator] + split_ifs with h + · rw [← Real.norm_eq_abs]; exact V.value_le_valueBound p ω + · rw [abs_zero]; exact V.valueBound_nonneg + +/-- **Pointwise `L²` bound of the elementary drift** (bridge + Cauchy–Schwarz + interval +extension): for `t ≤ T`, `(driftSimpleProcess V t ω)² ≤ T·∫₀ᵀ (⇑V s ω)² ds`. -/ +theorem driftSimpleProcess_sq_le (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration hBmeas)) {t : ℝ≥0} (htT : t ≤ T) (ω : Ω) : + (driftSimpleProcess hBmeas V t ω) ^ 2 + ≤ (T : ℝ) * ∫ s in Set.Ioc (0 : ℝ≥0) T, (⇑V s ω) ^ 2 ∂timeMeasure := by + rw [driftSimpleProcess_eq_setIntegral] + have hCS := sq_integral_le_measureReal_mul (ν := timeMeasure.restrict (Set.Ioc (0 : ℝ≥0) t)) + (f := fun s ↦ ⇑V s ω) ((memLp_slice T hBmeas V ω).mono_measure (Measure.restrict_mono + (Set.Ioc_subset_Ioc_right htT) le_rfl)) + rw [Measure.restrict_apply_univ, timeMeasure_Ioc, + ENNReal.toReal_ofReal (by rw [NNReal.coe_zero, sub_zero]; exact t.coe_nonneg), + NNReal.coe_zero, sub_zero] at hCS + refine hCS.trans (mul_le_mul (by exact_mod_cast htT) ?_ (integral_nonneg fun s ↦ sq_nonneg _) + T.coe_nonneg) + exact setIntegral_mono_set ((memLp_slice T hBmeas V ω).integrable_sq) + (ae_of_all _ fun s ↦ sq_nonneg _) (ae_of_all _ fun _ h ↦ Set.Ioc_subset_Ioc_right htT h) + +/-- **Additivity** of the elementary drift in the simple process (`Finsupp.sum_add_index'`, +the summand being linear in the coefficient). -/ +theorem driftSimpleProcess_add (hBmeas : ∀ t, Measurable (B t)) + (V W : SimpleProcess ℝ (natFiltration hBmeas)) (t : ℝ≥0) : + driftSimpleProcess hBmeas (V + W) t + = driftSimpleProcess hBmeas V t + driftSimpleProcess hBmeas W t := by + funext ω + simp only [driftSimpleProcess] + rw [show (V + W).value = V.value + W.value from rfl] + exact Finsupp.sum_add_index' (fun p ↦ by simp) (fun p a b ↦ by simp [Pi.add_apply, add_mul]) + +/-- **Homogeneity** of the elementary drift in the simple process (through the honest-integral +bridge + `integral_const_mul`). -/ +theorem driftSimpleProcess_smul (hBmeas : ∀ t, Measurable (B t)) (c : ℝ) + (V : SimpleProcess ℝ (natFiltration hBmeas)) (t : ℝ≥0) : + driftSimpleProcess hBmeas (c • V) t = c • driftSimpleProcess hBmeas V t := by + funext ω + simp only [Pi.smul_apply, smul_eq_mul] + rw [driftSimpleProcess_eq_setIntegral, driftSimpleProcess_eq_setIntegral, ← integral_const_mul] + refine setIntegral_congr_fun measurableSet_Ioc (fun s _ ↦ ?_) + rw [SimpleProcess.coe_smul, Pi.smul_apply, Pi.smul_apply, smul_eq_mul] + +/-- The elementary drift assembled as an element of `E = Lp ℝ 2 (trimMeasure T)`. -/ +noncomputable def driftSimpleProcessLp (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration hBmeas)) : + Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) := + (memLp_uncurry_driftSimpleProcess T hBmeas V).toLp + (Function.uncurry (driftSimpleProcess hBmeas V)) + +/-- **The drift energy bound** — the relative `L²` bound that makes the drift a bounded operator on +`E`: `‖driftSimpleProcessLp V‖ ≤ T·‖simpleAssemblyHorizon V‖`. Tonelli turns the `E`-norm into +`∫₀ᵀ∫_Ω (drift)² `; the pointwise Cauchy–Schwarz bound `(drift)² ≤ T·∫₀ᵀ(⇑V)²` and Fubini collapse +the inner double integral to `T·‖simpleAssemblyHorizon V‖²`; the outer `∫₀ᵀ` adds the last `T`. -/ +theorem driftSimpleProcessLp_norm_le (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (V : TBoundedSP T hBmeas) : + ‖driftSimpleProcessLp (μ := μ) T hBmeas V.val‖ ≤ (T : ℝ) * + ‖simpleAssemblyHorizon (μ := μ) T hBmeas V‖ := by + set 𝓕 := natFiltration (mΩ := mΩ) hBmeas + have hpredD := driftSimpleProcess_isStronglyPredictable hBmeas V.val + have hmemD := memLp_uncurry_driftSimpleProcess (μ := μ) T hBmeas V.val + have hmemV := memLp_uncurry_trimMeasure (μ := μ) T hBmeas V.val + -- both `E`-norms², via `lp_two_norm_sq` + `coeFn_toLp` + `integral_trim`, as product integrals. + have hnorm : ∀ (g : ℝ≥0 → Ω → ℝ) + (hg : MemLp (Function.uncurry g) 2 (trimMeasure (μ := μ) T hBmeas)), + StronglyMeasurable[𝓕.predictable] (Function.uncurry g) → + ‖hg.toLp (Function.uncurry g)‖ ^ 2 + = ∫ z, (Function.uncurry g z) ^ 2 ∂((timeMeasureHorizon T).prod μ) := by + intro g hg hgp + rw [lp_two_norm_sq, integral_congr_ae (g := fun z ↦ (Function.uncurry g z) ^ 2) + (by filter_upwards [hg.coeFn_toLp] with z hz; rw [hz]), + show trimMeasure (μ := μ) T hBmeas + = ((timeMeasureHorizon T).prod μ).trim 𝓕.predictable_le_prod from rfl, + ← integral_trim 𝓕.predictable_le_prod + (f := fun z ↦ (Function.uncurry g z) ^ 2) (hgp.pow 2)] + have hsAsm : simpleAssemblyHorizon (μ := μ) T hBmeas V = hmemV.toLp (Function.uncurry ⇑V.val) := + rfl + have hsq : ‖driftSimpleProcessLp (μ := μ) T hBmeas V.val‖ ^ 2 + ≤ ((T : ℝ) * ‖simpleAssemblyHorizon (μ := μ) T hBmeas V‖) ^ 2 := by + rw [driftSimpleProcessLp, hnorm _ hmemD hpredD, mul_pow, hsAsm, + hnorm _ hmemV V.val.isStronglyPredictable] + -- ∫ (drift)² ∂prod ≤ (T:ℝ)² · ∫ (⇑V)² ∂prod + have hmemD_prod : MemLp (Function.uncurry (driftSimpleProcess hBmeas V.val)) 2 + ((timeMeasureHorizon T).prod μ) := + memLp_of_memLp_trim 𝓕.predictable_le_prod hmemD + have hmemV_prod : MemLp (Function.uncurry ⇑V.val) 2 ((timeMeasureHorizon T).prod μ) := + memLp_of_memLp_trim 𝓕.predictable_le_prod hmemV + have hintD := hmemD_prod.integrable_sq + have hintV := hmemV_prod.integrable_sq + rw [integral_prod _ hintD] + -- Fubini: `∫_ω ∫_{Ioc 0 T}(⇑V)² dμ = ∫_prod (⇑V)²`. + have hW : ∫ ω, (∫ s in Set.Ioc (0 : ℝ≥0) T, (⇑V.val s ω) ^ 2 ∂timeMeasure) ∂μ + = ∫ z, (Function.uncurry ⇑V.val z) ^ 2 ∂((timeMeasureHorizon T).prod μ) := by + rw [integral_prod _ hintV] + exact integral_integral_swap hintV.swap + calc ∫ t, ∫ ω, (driftSimpleProcess hBmeas V.val t ω) ^ 2 ∂μ ∂(timeMeasureHorizon T) + ≤ ∫ _t : ℝ≥0, (T : ℝ) * ∫ z, (Function.uncurry ⇑V.val z) ^ 2 + ∂((timeMeasureHorizon T).prod μ) + ∂(timeMeasureHorizon T) := by + refine integral_mono_ae hintD.integral_prod_left (integrable_const _) ?_ + have hslice : ∀ᵐ t ∂(timeMeasureHorizon T), + Integrable (fun ω ↦ (driftSimpleProcess hBmeas V.val t ω) ^ 2) μ := + hintD.prod_right_ae + filter_upwards [ae_restrict_mem (μ := timeMeasure) measurableSet_Ioc, hslice] + with t ht hint_t + calc ∫ ω, (driftSimpleProcess hBmeas V.val t ω) ^ 2 ∂μ + ≤ ∫ ω, (T : ℝ) * ∫ s in Set.Ioc (0 : ℝ≥0) T, (⇑V.val s ω) ^ 2 ∂timeMeasure ∂μ := + integral_mono_ae hint_t + ((hintV.integral_prod_right).const_mul _) + (ae_of_all _ fun ω ↦ driftSimpleProcess_sq_le T hBmeas V.val ht.2 ω) + _ = (T : ℝ) * ∫ z, (Function.uncurry ⇑V.val z) ^ 2 + ∂((timeMeasureHorizon T).prod μ) := by + rw [integral_const_mul, hW] + _ = (T : ℝ) ^ 2 * ∫ z, (Function.uncurry ⇑V.val z) ^ 2 ∂((timeMeasureHorizon T).prod μ) := by + rw [integral_const, timeMeasureHorizon, measureReal_def, Measure.restrict_apply_univ, + timeMeasure_Ioc, + ENNReal.toReal_ofReal (by rw [NNReal.coe_zero, sub_zero]; exact T.coe_nonneg), + NNReal.coe_zero, sub_zero, smul_eq_mul] + ring + have h := Real.sqrt_le_sqrt hsq + rwa [Real.sqrt_sq (norm_nonneg _), Real.sqrt_sq (mul_nonneg T.coe_nonneg (norm_nonneg _))] at h + +/-- **The elementary drift as a linear map** on the `T`-bounded simple processes, +`V ↦ driftSimpleProcessLp V` (the target of the `extendOfNorm` extension). -/ +noncomputable def driftProcessLM (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) : + TBoundedSP T hBmeas →ₗ[ℝ] Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) where + toFun V := driftSimpleProcessLp (μ := μ) T hBmeas V.val + map_add' V W := by + change driftSimpleProcessLp (μ := μ) T hBmeas ((V + W).val) = _ + rw [Submodule.coe_add, driftSimpleProcessLp, driftSimpleProcessLp, driftSimpleProcessLp, + ← MemLp.toLp_add (memLp_uncurry_driftSimpleProcess T hBmeas V.val) + (memLp_uncurry_driftSimpleProcess T hBmeas W.val)] + congr 1 + funext z + exact congrFun (driftSimpleProcess_add hBmeas V.val W.val z.1) z.2 + map_smul' c V := by + change driftSimpleProcessLp (μ := μ) T hBmeas ((c • V).val) = _ + rw [Submodule.coe_smul, driftSimpleProcessLp, driftSimpleProcessLp, RingHom.id_apply, + ← MemLp.toLp_const_smul c (memLp_uncurry_driftSimpleProcess T hBmeas V.val)] + congr 1 + funext z + exact congrFun (driftSimpleProcess_smul hBmeas c V.val z.1) z.2 + +/-- **The assembled drift as a CLM on `E`.** Extends the elementary drift `driftProcessLM` +along the dense embedding `simpleAssemblyHorizon`, via `LinearMap.extendOfNorm` with the energy +bound `driftSimpleProcessLp_norm_le`. For `g ∈ E`, this is `t ↦ ∫₀ᵗ g(s,·) ds` — the drift term of +the Picard iterate — landing back in the predictable `L²` space `E`. Being a CLM it is linear, +bounded (`‖·‖ ≤ T‖·‖`), and predictable-by-construction, all for free. -/ +noncomputable def driftProcessAssembled (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) : + Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) →L[ℝ] Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) := + (driftProcessLM (μ := μ) T hBmeas).extendOfNorm (simpleAssemblyHorizon (μ := μ) T hBmeas) + +/-- **The bridge (definitional).** On the embedding of a `T`-bounded simple process, the +assembled drift reproduces the elementary drift `driftSimpleProcessLp V`. -/ +theorem driftProcessAssembled_simpleAssembly (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (V : TBoundedSP T hBmeas) : + driftProcessAssembled (μ := μ) T hBmeas (simpleAssemblyHorizon (μ := μ) T hBmeas V) + = driftSimpleProcessLp (μ := μ) T hBmeas V.val := by + rw [driftProcessAssembled, + LinearMap.extendOfNorm_eq (simpleAssemblyHorizon_denseRange (μ := μ) T hBmeas) + ⟨(T : ℝ), fun W ↦ driftSimpleProcessLp_norm_le T hBmeas W⟩] + rfl + +/-- **The drift operator bound** `‖driftProcessAssembled φ‖ ≤ T‖φ‖` for general `φ ∈ E` — the +witness of the `‖·‖ ≤ T‖·‖` the CLM advertises: the `extendOfNorm` operator norm inherited from the +elementary energy bound `driftSimpleProcessLp_norm_le`. -/ +theorem driftProcessAssembled_norm_le (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ‖driftProcessAssembled (μ := μ) T hBmeas φ‖ ≤ (T : ℝ) * ‖φ‖ := by + rw [driftProcessAssembled] + exact LinearMap.norm_extendOfNorm_apply_le (simpleAssemblyHorizon_denseRange (μ := μ) T hBmeas) + (T : ℝ) (fun W ↦ driftSimpleProcessLp_norm_le T hBmeas W) φ + +end ItoIntegralProcessContinuousModification +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralCLM.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralCLM.lean new file mode 100644 index 0000000000..9b1a12996e --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralCLM.lean @@ -0,0 +1,305 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralL2Dense + +/-! +# The horizon-`T` Itô integral is the infinite-horizon one on the band `(0,T]` + +`itoIntegralCLM : Lp ℝ 2 trimMeasure →L[ℝ] Lp ℝ 2 μ` is **defined** as the infinite-horizon +Itô integral `itoIntegralL2` (`ItoIntegralL2Dense`) composed with `bandExtend T`, the extension +by zero of a `[0,T]` integrand to the `[0,∞)` predictable `L²` (a linear isometry, with +`restrictToBand T`, the `Lp` inclusion for `trimMeasure T ≤ trim_full`, as left inverse). +There is no second extension argument: linearity, continuity and the isometry +(`itoIntegralCLM_norm`) are those of `itoIntegralL2` and `bandExtend`, and the value on +`T`-bounded simple processes (`itoIntegralCLM_simpleAssemblyHorizon`) is +`bandExtend_simpleAssemblyHorizon` followed by `itoIntegralL2_simpleAssembly`. + +The density of the horizon-`T` simple processes (`ItoIntegralHorizonDense`) stays: it is the +engine under `itoIntegralL2`'s own density, and the consumers of this file use it to +reduce statements about `itoIntegralCLM` to simple processes. + +## Main definitions + +* `monoMeasureLp`: the norm-`≤ 1` inclusion `Lp 2 μ →L[ℝ] Lp 2 ν` for `ν ≤ μ`. +* `restrictToBand`: restriction of a `[0,∞)` predictable integrand to the band `[0,T]`. +* `bandExtend`: extension by zero of a `[0,T]` integrand to the `[0,∞)` predictable `L²`. +* `itoIntegralCLM`: the Itô integral on `[0,T]`, the infinite-horizon `itoIntegralL2` composed + with `bandExtend`. + +## Main results + +* `restrictToBand_bandExtend`: `restrictToBand` is a left inverse of `bandExtend`. +* `itoIntegralCLM_simpleAssemblyHorizon`: on a simple embedding the CLM agrees with the elementary + Itô integral, `itoIntegralCLM (simpleAssemblyHorizon V) = itoSimpleLp V`. +* `itoIntegralCLM_norm`: the Itô isometry on `[0,T]`, `‖itoIntegralCLM f‖ = ‖f‖` for every + `f ∈ Lp 2 trim_T`. + +## Tags + +Itô integral, stochastic integral, Itô isometry, continuous linear map, finite horizon, +predictable integrands, MSC 60H05, MSC 60G44 +-/ + +@[expose] public section + +open MeasureTheory Filter Topology NNReal ENNReal ProbabilityTheory +open scoped MeasureTheory NNReal ENNReal InnerProductSpace + +namespace MathFin +namespace ItoIntegralCLM + +open ItoIntegralL2 + +/-! ### The `Lp` inclusion for `ν ≤ μ` (generic) -/ + +section MonoMeasureLp +variable {α : Type*} {_mα : MeasurableSpace α} {μ ν : Measure α} + +/-- **The `Lp` inclusion for `ν ≤ μ`.** For `f ∈ Lp 2 μ` the *same* function lies in +`Lp 2 ν` with no larger norm (a smaller measure can only shrink the `L²` norm), so +`f ↦ f` is a norm-`≤ 1` continuous linear map `Lp 2 μ →L[ℝ] Lp 2 ν`. Mathlib has +`MemLp.mono_measure` but no packaged CLM; generic measure theory, a natural upstream +candidate. Specialises to measure restriction (`ν = μ.restrict s`, via +`Measure.restrict_le_self`). -/ +noncomputable def monoMeasureLp (h : ν ≤ μ) : Lp ℝ 2 μ →L[ℝ] Lp ℝ 2 ν := + LinearMap.mkContinuous + { toFun := fun f ↦ ((Lp.memLp f).mono_measure h).toLp + map_add' := fun f g ↦ by + refine Lp.ext ?_ + filter_upwards [MemLp.coeFn_toLp ((Lp.memLp (f + g)).mono_measure h), + Lp.coeFn_add (((Lp.memLp f).mono_measure h).toLp) (((Lp.memLp g).mono_measure h).toLp), + MemLp.coeFn_toLp ((Lp.memLp f).mono_measure h), + MemLp.coeFn_toLp ((Lp.memLp g).mono_measure h), + (Lp.coeFn_add f g).filter_mono (ae_mono h)] with x h1 h2 h3 h4 h5 + simp only [h1, h2, h3, h4, h5, Pi.add_apply] + map_smul' := fun c f ↦ by + refine Lp.ext ?_ + filter_upwards [MemLp.coeFn_toLp ((Lp.memLp (c • f)).mono_measure h), + Lp.coeFn_smul c (((Lp.memLp f).mono_measure h).toLp), + MemLp.coeFn_toLp ((Lp.memLp f).mono_measure h), + (Lp.coeFn_smul c f).filter_mono (ae_mono h)] with x h1 h2 h3 h4 + simp only [h1, h2, h3, h4, Pi.smul_apply, RingHom.id_apply] } + 1 (fun f ↦ by + simp only [LinearMap.coe_mk, AddHom.coe_mk, one_mul, Lp.norm_def] + refine ENNReal.toReal_mono (Lp.memLp f).eLpNorm_ne_top ?_ + rw [eLpNorm_congr_ae (MemLp.coeFn_toLp ((Lp.memLp f).mono_measure h))] + exact eLpNorm_mono_measure _ h) + +@[simp] lemma monoMeasureLp_coeFn (h : ν ≤ μ) (f : Lp ℝ 2 μ) : + ⇑(monoMeasureLp h f) =ᵐ[ν] ⇑f := by + simp only [monoMeasureLp, LinearMap.mkContinuous_apply, LinearMap.coe_mk, AddHom.coe_mk] + exact MemLp.coeFn_toLp _ + +end MonoMeasureLp + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} + +/-- **Restriction of a `[0,∞)` predictable integrand to the band `[0,T]`** as a CLM +`Lp 2 trim_full →L[ℝ] Lp 2 (trimMeasure T)`: the `Lp` inclusion for +`trimMeasure T ≤ trim_full` (the band restriction, `trimMeasure_eq_restrict` + +`Measure.restrict_le_self`). The integrand seen on `[0,T]`. -/ +noncomputable def restrictToBand (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) : + Lp ℝ 2 ((timeMeasure.prod μ).trim (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod) + →L[ℝ] Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) := + monoMeasureLp ((trimMeasure_eq_restrict T hBmeas).le.trans Measure.restrict_le_self) + +@[simp] lemma restrictToBand_coeFn (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (f : Lp ℝ 2 ((timeMeasure.prod μ).trim (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod)) : + ⇑(restrictToBand (μ := μ) T hBmeas f) =ᵐ[trimMeasure (μ := μ) T hBmeas] ⇑f := + monoMeasureLp_coeFn _ f + +/-- **The `[0,T]`-restriction of a simple process's `[0,∞)` assembly is its `[0,T]` +simple-process element** `simpleProcessL2Horizon`. Both are `toLp (uncurry V)` — one against +the full trim, one against the `[0,T]` trim — and `restrictToBand` only re-reads the +*same* function against the smaller measure, so they coincide a.e. on `[0,T]` (where +`trimMeasure` is supported). **No truncation of `V` is needed**: the `[0,T]` element is +literally `V`'s integrand re-measured, not a clamped process. -/ +lemma restrictToBand_simpleAssembly (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + restrictToBand (μ := μ) T hBmeas (simpleAssembly hBmeas V) + = simpleProcessL2Horizon (μ := μ) T hBmeas V := by + have hmono : trimMeasure (μ := μ) T hBmeas + ≤ (timeMeasure.prod μ).trim (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod := + (trimMeasure_eq_restrict T hBmeas).le.trans Measure.restrict_le_self + refine Lp.ext ?_ + calc ⇑(restrictToBand (μ := μ) T hBmeas (simpleAssembly hBmeas V)) + =ᵐ[trimMeasure (μ := μ) T hBmeas] ⇑(simpleAssembly hBmeas V) := + restrictToBand_coeFn T hBmeas _ + _ =ᵐ[trimMeasure (μ := μ) T hBmeas] Function.uncurry ⇑V := + (MemLp.coeFn_toLp (memLp_uncurry_trim hBmeas V)).filter_mono (ae_mono hmono) + _ =ᵐ[trimMeasure (μ := μ) T hBmeas] ⇑(simpleProcessL2Horizon (μ := μ) T hBmeas V) := + (MemLp.coeFn_toLp (memLp_uncurry_trimMeasure T hBmeas V)).symm + +/-! ### Extension by zero: the isometric section of `restrictToBand` + +A `[0,T]` integrand is a `[0,∞)` integrand carried by the band `(0,T] × Ω`: `bandExtend T` is +that inclusion, and `restrictToBand T` its left inverse. Composing `itoIntegralL2` with it is the +`[0,T]` Itô integral (`itoIntegralCLM_apply`), so horizon consistency +between finite horizons is the equality of two extensions by zero. -/ + +/-- The predictable trim gives no mass to the time origin `{0} × Ω`. -/ +lemma ae_fst_ne_zero_trim (hBmeas : ∀ u, Measurable (B u)) : + ∀ᵐ z ∂((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod), z.1 ≠ 0 := by + rw [Filter.eventually_iff, mem_ae_iff, + show {z : ℝ≥0 × Ω | z.1 ≠ 0}ᶜ = {(⊥ : ℝ≥0)} ×ˢ (Set.univ : Set Ω) from by ext z; simp, + trim_measurableSet_eq _ (MeasureTheory.measurableSet_predictable_singleton_bot_prod + (𝓕 := natFiltration (mΩ := mΩ) hBmeas) MeasurableSet.univ), + Measure.prod_prod, timeMeasure_singleton, zero_mul] + +/-- Restricting to the band `(0,T] × Ω` commutes with taking indicators: a.e.-equality in +the `[0,T]` trim lifts to a.e.-equality of the band indicators in the `[0,∞)` trim. -/ +lemma indicator_band_ae_eq (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + {f g : ℝ≥0 × Ω → ℝ} (h : f =ᵐ[trimMeasure (μ := μ) T hBmeas] g) : + (Set.Ioc 0 T ×ˢ (Set.univ : Set Ω)).indicator f + =ᵐ[(timeMeasure.prod μ).trim (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod] + (Set.Ioc 0 T ×ˢ (Set.univ : Set Ω)).indicator g := by + rw [trimMeasure_eq_restrict] at h + filter_upwards [(ae_restrict_iff' + (MeasureTheory.measurableSet_predictable_Ioc_prod + (𝓕 := natFiltration (mΩ := mΩ) hBmeas) 0 T MeasurableSet.univ)).1 h] with z hz + by_cases hzs : z ∈ Set.Ioc 0 T ×ˢ (Set.univ : Set Ω) + · rw [Set.indicator_of_mem hzs, Set.indicator_of_mem hzs, hz hzs] + · rw [Set.indicator_of_notMem hzs, Set.indicator_of_notMem hzs] + +lemma memLp_indicator_band (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + MemLp ((Set.Ioc 0 T ×ˢ (Set.univ : Set Ω)).indicator φ) 2 + ((timeMeasure.prod μ).trim (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod) := + (memLp_indicator_iff_restrict (MeasureTheory.measurableSet_predictable_Ioc_prod + (𝓕 := natFiltration (mΩ := mΩ) hBmeas) 0 T MeasurableSet.univ).nullMeasurableSet).2 + (by rw [← trimMeasure_eq_restrict]; exact Lp.memLp φ) + +/-- **Extension by zero** of a `[0,T]` integrand to the `[0,∞)` predictable `L²`: the +isometric section of `restrictToBand`. -/ +noncomputable def bandExtend (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) : + Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) →ₗᵢ[ℝ] + Lp ℝ 2 ((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod) where + toFun φ := (memLp_indicator_band T hBmeas φ).toLp + ((Set.Ioc 0 T ×ˢ (Set.univ : Set Ω)).indicator φ) + map_add' φ ψ := by + refine Lp.ext ?_ + filter_upwards [MemLp.coeFn_toLp (memLp_indicator_band T hBmeas (φ + ψ)), + Lp.coeFn_add ((memLp_indicator_band T hBmeas φ).toLp _) + ((memLp_indicator_band T hBmeas ψ).toLp _), + MemLp.coeFn_toLp (memLp_indicator_band T hBmeas φ), + MemLp.coeFn_toLp (memLp_indicator_band T hBmeas ψ), + indicator_band_ae_eq T hBmeas (Lp.coeFn_add φ ψ)] with z h1 h2 h3 h4 h5 + simp only [h1, h2, h3, h4, h5, Pi.add_apply, Set.indicator_add'] + map_smul' c φ := by + refine Lp.ext ?_ + filter_upwards [MemLp.coeFn_toLp (memLp_indicator_band T hBmeas (c • φ)), + Lp.coeFn_smul c ((memLp_indicator_band T hBmeas φ).toLp _), + MemLp.coeFn_toLp (memLp_indicator_band T hBmeas φ), + indicator_band_ae_eq T hBmeas (Lp.coeFn_smul c φ)] with z h1 h2 h3 h4 + simp only [h1, h2, h3, h4, Pi.smul_apply, RingHom.id_apply] + by_cases hz : z ∈ Set.Ioc 0 T ×ˢ (Set.univ : Set Ω) + · rw [Set.indicator_of_mem hz, Set.indicator_of_mem hz, Pi.smul_apply] + · rw [Set.indicator_of_notMem hz, Set.indicator_of_notMem hz, smul_zero] + norm_map' φ := by + rw [LinearMap.coe_mk, AddHom.coe_mk, Lp.norm_toLp, Lp.norm_def, + eLpNorm_indicator_eq_eLpNorm_restrict + (MeasureTheory.measurableSet_predictable_Ioc_prod + (𝓕 := natFiltration (mΩ := mΩ) hBmeas) 0 T MeasurableSet.univ).nullMeasurableSet, + ← trimMeasure_eq_restrict] + +lemma bandExtend_coeFn (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ⇑(bandExtend T hBmeas φ) =ᵐ[(timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod] + (Set.Ioc 0 T ×ˢ (Set.univ : Set Ω)).indicator ⇑φ := + MemLp.coeFn_toLp (memLp_indicator_band T hBmeas φ) + +/-- `restrictToBand` is a left inverse of `bandExtend`: a `[0,T]` integrand is unchanged by +extending it by zero and restricting back. -/ +lemma restrictToBand_bandExtend (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + restrictToBand (μ := μ) T hBmeas (bandExtend T hBmeas φ) = φ := by + refine Lp.ext ?_ + filter_upwards [restrictToBand_coeFn T hBmeas (bandExtend T hBmeas φ), + (bandExtend_coeFn T hBmeas φ).filter_mono + (ae_mono ((trimMeasure_eq_restrict T hBmeas).le.trans Measure.restrict_le_self)), + ae_fst_mem_Ioc_trimMeasure (μ := μ) T hBmeas] with z h1 h2 h3 + rw [h1, h2] + exact Set.indicator_of_mem (show z ∈ Set.Ioc 0 T ×ˢ (Set.univ : Set Ω) from + ⟨h3, Set.mem_univ _⟩) _ + +/-- A class carried by `(0,T] × Ω`, extended by zero, is the same function read in the +`[0,∞)` trim. -/ +lemma bandExtend_toLp_ae_eq (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) {g : ℝ≥0 × Ω → ℝ} + (hg0 : ∀ z : ℝ≥0 × Ω, T < z.1 → g z = 0) + (hgm : MemLp g 2 (trimMeasure (μ := μ) T hBmeas)) : + ⇑(bandExtend T hBmeas (hgm.toLp g)) =ᵐ[(timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod] g := by + filter_upwards [bandExtend_coeFn T hBmeas (hgm.toLp g), + indicator_band_ae_eq T hBmeas hgm.coeFn_toLp, ae_fst_ne_zero_trim hBmeas] with z h1 h2 h0 + rw [h1, h2] + by_cases hz : z.1 ≤ T + · exact Set.indicator_of_mem (show z ∈ Set.Ioc 0 T ×ˢ (Set.univ : Set Ω) from + ⟨⟨pos_iff_ne_zero.2 h0, hz⟩, Set.mem_univ _⟩) _ + · rw [Set.indicator_of_notMem (show z ∉ Set.Ioc 0 T ×ˢ (Set.univ : Set Ω) from fun h ↦ hz h.1.2), + hg0 z (not_le.1 hz)] + +/-- On a `T`-bounded simple process, extension by zero turns the `[0,T]` embedding into the +`[0,∞)` one. -/ +lemma bandExtend_simpleAssemblyHorizon (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (V : TBoundedSP T hBmeas) : + bandExtend T hBmeas (simpleAssemblyHorizon (μ := μ) T hBmeas V) = + simpleAssembly hBmeas V.val := by + refine Lp.ext ?_ + filter_upwards [bandExtend_coeFn T hBmeas (simpleAssemblyHorizon (μ := μ) T hBmeas V), + indicator_band_ae_eq T hBmeas (memLp_uncurry_trimMeasure (μ := μ) T hBmeas V.val).coeFn_toLp, + (memLp_uncurry_trim (μ := μ) hBmeas V.val).coeFn_toLp, + ae_fst_ne_zero_trim hBmeas] with z h1 h2 h3 h0 + refine h1.trans (h2.trans (Eq.trans ?_ h3.symm)) + rcases z with ⟨t, ω⟩ + by_cases ht : t ≤ T + · exact Set.indicator_of_mem (show (t, ω) ∈ Set.Ioc 0 T ×ˢ (Set.univ : Set Ω) from + ⟨⟨pos_iff_ne_zero.2 h0, ht⟩, Set.mem_univ _⟩) _ + · rw [Set.indicator_of_notMem + (show (t, ω) ∉ Set.Ioc 0 T ×ˢ (Set.univ : Set Ω) from fun h ↦ ht h.1.2)] + exact (uncurry_eq_zero_of_lt V (not_le.1 ht) ω).symm + +/-! ### The CLM `itoIntegralCLM` and its isometry -/ + +/-- **The Itô integral on `[0,T]`**: the infinite-horizon integral `itoIntegralL2` of the +integrand extended by zero (`bandExtend`). A continuous linear map as a composite of one. -/ +noncomputable def itoIntegralCLM (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) : + Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) →L[ℝ] Lp ℝ 2 μ := + (itoIntegralL2 hB hBmeas).comp (bandExtend T hBmeas).toContinuousLinearMap + +theorem itoIntegralCLM_apply (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + itoIntegralCLM hB T hBmeas φ = itoIntegralL2 hB hBmeas (bandExtend T hBmeas φ) := + rfl + +/-- **The CLM agrees with the elementary Itô integral on a simple embedding**: +`itoIntegralCLM (simpleAssemblyHorizon V) = itoSimpleLp V`. The bridge every consumer of the CLM +crosses to get back to the finite increment sum `∑ V(p)·(B_{p.2} − B_{p.1})`: it is what makes +`DenseRange.equalizer` arguments over `simpleAssemblyHorizon_denseRange` computable at all. -/ +theorem itoIntegralCLM_simpleAssemblyHorizon (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (V : TBoundedSP T hBmeas) : + itoIntegralCLM hB T hBmeas (simpleAssemblyHorizon (μ := μ) T hBmeas V) + = ItoIntegralL2.itoSimpleLp hB hBmeas V.val := by + rw [itoIntegralCLM_apply, bandExtend_simpleAssemblyHorizon, itoIntegralL2_simpleAssembly] + +/-- **The continuous-time Itô isometry on `[0,T]`.** For every +`f ∈ Lp 2 trim_T`, `‖itoIntegralCLM f‖ = ‖f‖`. -/ +theorem itoIntegralCLM_norm (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) + (f : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ‖itoIntegralCLM hB T hBmeas f‖ = ‖f‖ := by + rw [itoIntegralCLM_apply, itoIntegralL2_norm, LinearIsometry.norm_map] + +end ItoIntegralCLM +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralCovariation.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralCovariation.lean new file mode 100644 index 0000000000..7b91945f1a --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralCovariation.lean @@ -0,0 +1,117 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralCLM +/-! # Covariation of Itô integrals: the bilinear Itô isometry + +The Itô isometry `‖∫φ dB‖ = ‖φ‖` (`ItoIntegralCLM.itoIntegralCLM_norm`) says +the Itô integral preserves L²-*norms*. A linear norm-isometry between real +inner-product spaces automatically preserves the *inner product* — the +polarization identity recovers `⟪x, y⟫` from norms — so the integral preserves +L²-inner-products too: `⟪∫φ dB, ∫ψ dB⟫ = ⟪φ, ψ⟫`. Unfolding both Hilbert inner +products as Bochner integrals (`L2.inner_def`; the real inner product on `ℝ` is +multiplication) this is the **covariation of two Itô integrals** + + `𝔼_μ[(∫φ dB)·(∫ψ dB)] = ∫ φ·ψ d(trim)`, + +the polarized companion of the isometry — the L²-level statement of +`⟨∫φ dB, ∫ψ dB⟩ = ∫₀ᵀ φ_s ψ_s ds` (the predictable `trim` measure *is* `ds ⊗ μ` +trimmed to the predictable σ-algebra — a `.trim`, agreeing with `ds ⊗ μ` on +predictable integrands). The diagonal `φ = ψ` recovers the isometry exactly. + +The reusable artifact is the bundled `LinearIsometry` `itoIsometry`: every Itô +inner-product fact is now one application of `LinearIsometry.inner_map_map`. This +is the bilinear completion of the B1 finite-horizon analytic tower and the +covariance backbone for multi-factor / covariance-swap pricing. + +The unbounded-horizon `[0,∞)` analog (`itoIntegralL2`, B2) is identical once the +full predictable trim measure is exposed behind a named def; deferred. + +## Main definitions + +* `itoIsometry`: the `[0,T]` Itô integral bundled as a linear isometry + `Lp ℝ 2 trim_T →ₗᵢ[ℝ] Lp ℝ 2 μ`. + +## Main results + +* `inner_itoIntegralCLM`: the `[0,T]` integral preserves the `L²` inner product, + `⟪∫φ dB, ∫ψ dB⟫ = ⟪φ, ψ⟫`. +* `covariation_itoIntegralCLM`: `𝔼_μ[(∫φ dB)(∫ψ dB)] = ⟪φ, ψ⟫`. +* `variance_itoIntegralCLM`: on the diagonal, `𝔼_μ[(∫φ dB)²] = ‖φ‖²`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Ch 7 + +## Tags + +covariation, bilinear Itô isometry, polarization identity, inner product, stochastic integral, +covariance, MSC 60H05, MSC 60G44 +-/ + +@[expose] public section + +namespace MathFin +namespace ItoIntegralCovariation + +open MeasureTheory Filter Topology NNReal ENNReal ProbabilityTheory +open scoped MeasureTheory NNReal ENNReal InnerProductSpace + +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) + +include hB + +/-- The `[0,T]` Itô integral bundled as a **linear isometry** +`Lp ℝ 2 trim_T →ₗᵢ[ℝ] Lp ℝ 2 μ`: the CLM `itoIntegralCLM` together with the +Itô isometry `itoIntegralCLM_norm`. The `norm_map'` field rewrites the +`ContinuousLinearMap`→`LinearMap` coercion (`coe_coe`) rather than forcing a +defeq through the underlying `extendOfNorm` term. -/ +noncomputable def itoIsometry (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) : + Lp ℝ 2 (ItoIntegralCLM.trimMeasure (μ := μ) T hBmeas) →ₗᵢ[ℝ] Lp ℝ 2 μ where + toLinearMap := (ItoIntegralCLM.itoIntegralCLM hB T hBmeas).toLinearMap + norm_map' x := by + simpa only [ContinuousLinearMap.coe_coe] using + ItoIntegralCLM.itoIntegralCLM_norm hB T hBmeas x + +/-- **Covariation of Itô integrals (inner-product form).** The `[0,T]` integral +preserves the L²-inner product: `⟪∫φ dB, ∫ψ dB⟫ = ⟪φ, ψ⟫`. Polarization of the +Itô isometry, via `LinearIsometry.inner_map_map`. -/ +theorem inner_itoIntegralCLM (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (φ ψ : Lp ℝ 2 (ItoIntegralCLM.trimMeasure (μ := μ) T hBmeas)) : + ⟪ItoIntegralCLM.itoIntegralCLM hB T hBmeas φ, + ItoIntegralCLM.itoIntegralCLM hB T hBmeas ψ⟫_ℝ = ⟪φ, ψ⟫_ℝ := + (itoIsometry hB T hBmeas).inner_map_map φ ψ + +/-- **Covariation of Itô integrals (expectation form).** +`𝔼_μ[(∫φ dB)·(∫ψ dB)] = ⟪φ, ψ⟫` — the expectation of the product of two Itô +integrals is the L²(trim) inner product of their integrands, i.e. +`∫ φ·ψ d(trim) = 𝔼_μ ∫₀ᵀ φ_s ψ_s ds`. The cross-isometry; `φ = ψ` recovers the +Itô isometry (`variance_itoIntegralCLM`). -/ +theorem covariation_itoIntegralCLM (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (φ ψ : Lp ℝ 2 (ItoIntegralCLM.trimMeasure (μ := μ) T hBmeas)) : + ∫ ω, (ItoIntegralCLM.itoIntegralCLM hB T hBmeas φ : Ω → ℝ) ω + * (ItoIntegralCLM.itoIntegralCLM hB T hBmeas ψ : Ω → ℝ) ω ∂μ + = ⟪φ, ψ⟫_ℝ := by + have h := inner_itoIntegralCLM hB T hBmeas φ ψ + rw [L2.inner_def] at h + simpa only [RCLike.inner_apply, conj_trivial, mul_comm] using h + +/-- **Itô isometry, recovered from covariation.** The diagonal `φ = ψ`: +`𝔼_μ[(∫φ dB)²] = ‖φ‖²`. The Itô integral is centered (mean zero), so this second +moment is also its variance — hence the name. -/ +theorem variance_itoIntegralCLM (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (φ : Lp ℝ 2 (ItoIntegralCLM.trimMeasure (μ := μ) T hBmeas)) : + ∫ ω, (ItoIntegralCLM.itoIntegralCLM hB T hBmeas φ : Ω → ℝ) ω ^ 2 ∂μ + = ‖φ‖ ^ 2 := by + have h := covariation_itoIntegralCLM hB T hBmeas φ φ + rw [real_inner_self_eq_norm_sq] at h + simpa only [pow_two] using h + +end ItoIntegralCovariation +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralHorizonDense.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralHorizonDense.lean new file mode 100644 index 0000000000..028ae78b96 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralHorizonDense.lean @@ -0,0 +1,703 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralL2 + +/-! +# Horizon-`T` simple processes are dense in the predictable `L²` + +This file is the density engine under the Itô integral: the bounded-horizon embedding of +adapted simple step processes (`simpleAssemblyHorizon`), its isometry +(`norm_itoAssemblyHorizon`), and its density in `Lp ℝ 2 trimMeasure` +(`simpleAssemblyHorizon_denseRange`). The Itô integral itself +(`itoIntegralL2`, then `itoIntegralCLM` as its restriction to the band) is built on it in +`ItoIntegralL2Dense` and `ItoIntegralCLM`. + +Here `trimMeasure = ((timeMeasureHorizon T).prod μ).trim 𝓕.predictable_le_prod` and +`timeMeasureHorizon T = timeMeasure.restrict (Ioc 0 T)`. The construction mirrors +`WienerIntegralL2.lean` line-for-line at the orthogonal-complement layer. + +## Mathematical thesis + +The Itô integral on adapted simple step processes is a finite Riemann-style sum +`∑ φₖ (B_{tₖ₊₁} − B_{tₖ})`. Density of these among all `L²`-predictable +integrands reduces, via Dynkin's π-λ theorem over the **basic predictable +rectangles** `Ioc a b ×ˢ F` with `F ∈ ℱₐ` (a π-system that generates the +predictable σ-algebra), to "a function orthogonal to every rectangle indicator +is zero a.e." We have the discrete isometry (`assembly_isometry`, imported); +we provide the density here. + +## Coherence with Degenne / `BrownianMotion` + +Consumes upstream (all from +`.lake/packages/BrownianMotion/BrownianMotion/StochasticIntegral/SimpleProcess.lean`): + +* `ProbabilityTheory.SimpleProcess` — the integrand type, used by the + existing `ItoIntegralL2.simpleAssembly` (= `Finsupp.linearCombination` over + predictable indicators). +* `ProbabilityTheory.ElementaryPredictableSet` + `.indicator` — the + predictable-set indicator realisation as a `SimpleProcess`. +* `ProbabilityTheory.ElementaryPredictableSet.generateFrom_eq_predictable` — + the **upstream Stage-3 generation lemma** for any filtration on a + countably-generated-`atTop` index (`ℝ≥0` qualifies). + +Adds (the genuinely new content of this file): + +* `predictableRect` — the basic-rectangle family generating the predictable + σ-algebra. T enters at the measure layer (`trimMeasure`), not here. +* `isPiSystem_predictableRect` — closure under non-empty intersection. +* `setIntegral_eq_zero_of_orthogonal_pred` — π-λ-induction set-integral + vanishing, for any *integrable* `g` (not merely an `L²` class: the weighted + density argument of `PredictableDensityGeneral` applies it to `g·w`, which is + only `L¹`). +* `simpleAssemblyHorizon_denseRange` — density of the existing simple-process + assembly's range, in the restricted trim `L²`. + +## Conventions + +* Time axis: `ℝ≥0`. Bounded horizon `T : ℝ≥0` enters via + `timeMeasure.restrict (Ioc 0 T)` (the trim measure becomes finite of mass `T`). +* Predictable rectangles use `Ioc` (left-open, right-closed), matching + `stochasticIoc` in `BrownianMotion` and the Wiener case. + +The `ℝ≥0` (unbounded-horizon) Itô CLM is built on top of this file in +`MathFin/Probability/Brownian/Ito/ItoIntegralL2Dense.lean` (`itoIntegralL2`), by σ-finite +exhaustion of the time axis: each finite frame restricts to a `trimMeasure`, +so `setIntegral_eq_zero_of_orthogonal_pred` (de-privatised for that reuse) and +the `predictableRect` π-system are the bridges it consumes. + +## Main definitions + +* `timeMeasureHorizon`: the restriction of `timeMeasure` to `Ioc 0 T`, of total mass `T`. +* `trimMeasure`: the product measure `timeMeasureHorizon T ⊗ μ`, trimmed to the predictable + σ-algebra of the natural Brownian filtration; the `L²` domain of the CLM. +* `predictableRect`: a basic predictable rectangle, `{⊥} ×ˢ F₀` or `Ioc a b ×ˢ F`. +* `TBoundedSP`: the submodule of simple processes whose intervals all have right endpoint `≤ T`. +* `simpleProcessL2Horizon`: a simple process's `L²` class in the `T`-restricted trim. +* `simpleAssemblyHorizon`: the `T`-restricted simple-process `L²` embedding, as a linear map. +* `itoAssemblyHorizon`: the Itô assembly composed with the inclusion `TBoundedSP T ↪ SimpleProcess`. +* `iocSPHorizon`: the `T`-bounded simple process representing the indicator of `Ioc a b × F`. + +## Main results + +* `trimMeasure_eq_restrict`: the `T`-restricted predictable trim equals the restriction of the + full predictable trim to `Ioc 0 T × univ`. +* `generateFrom_predictableRect`: the basic predictable rectangles generate the predictable + σ-algebra. +* `norm_itoAssemblyHorizon`: the Itô isometry on `T`-bounded simple processes, inherited from + the full isometry through the trim-norm equality. +* `setIntegral_eq_zero_of_orthogonal_pred`: a `g ∈ L²(trim_T)` whose set integral over every basic + predictable rectangle vanishes has vanishing set integral over every predictable set. +* `simpleAssemblyHorizon_denseRange`: the image of `simpleAssemblyHorizon` is dense in + `Lp 2 trim_T`. + +## Tags + +density of simple processes, simple processes, predictable rectangles, π–λ theorem, +Itô integral construction, predictable sigma-algebra, MSC 60H05, MSC 60G07 +-/ + +@[expose] public section + +open MeasureTheory Filter Topology NNReal ENNReal ProbabilityTheory +open scoped MeasureTheory NNReal ENNReal InnerProductSpace + +namespace MathFin +namespace ItoIntegralCLM + +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} + +/-! ### Bounded horizon: the restricted trim measure -/ + +/-- The restriction of `timeMeasure` (the σ-finite Lebesgue pushforward to +`ℝ≥0`, defined in `ItoIntegralL2.lean`) to `Ioc 0 T`. Finite of total mass `T`. -/ +noncomputable def timeMeasureHorizon (T : ℝ≥0) : Measure ℝ≥0 := + ItoIntegralL2.timeMeasure.restrict (Set.Ioc 0 T) + +/-- `timeMeasureHorizon T` has finite total mass `T`. The acceptance of bounded +horizon is precisely that this instance exists; the unbounded `timeMeasure` +is only σ-finite. -/ +instance (T : ℝ≥0) : IsFiniteMeasure (timeMeasureHorizon T) := by + refine ⟨?_⟩ + rw [timeMeasureHorizon, Measure.restrict_apply MeasurableSet.univ, Set.univ_inter, + ItoIntegralL2.timeMeasure_Ioc] + exact ENNReal.ofReal_lt_top + +/-- The product measure `timeMeasureHorizon T ⊗ μ`, trimmed to the predictable +σ-algebra of the natural Brownian filtration. The `L²`-domain of the CLM. + +Reuses Degenne's `Filtration.predictable_le_prod` (upstream `L2M.lean` L27), +which is exactly the σ-algebra hypothesis `extendOfNorm` consumes. + +The return type is left implicit so the σ-algebra is the predictable one (the +`trim` result), not the default `Prod.instMeasurableSpace` — annotating the +return type would force the default and cause an `Application type mismatch`. -/ +noncomputable def trimMeasure (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) := + ((timeMeasureHorizon T).prod μ).trim + (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod + +/-! ### Basic predictable rectangles: the π-system + +We work with **basic** rectangles `Ioc a b ×ˢ F` (single rectangles, +`F ∈ ℱₐ`) — plus the `{0} ×ˢ F₀` "bottom" piece for `F₀ ∈ ℱ₀` — rather than +upstream's `ElementaryPredictableSet` (finite disjoint unions). Reason: +intersection of two basic rectangles is trivially another basic rectangle +(`Set.Ioc_inter_Ioc`, filtration monotonicity); intersection of two +`ElementaryPredictableSet`s would require reorganising disjoint unions, which +is mathematically equivalent but adds friction at the π-system layer. + +Both families generate the same σ-algebra, `𝓕.predictable`: the basic +rectangles are exactly the components from which any `ElementaryPredictableSet` +is built (finite disjoint union of `{⊥} × B` and `(s,t] × B'`), so they +generate everything `ElementaryPredictableSet` does (upstream: +`ElementaryPredictableSet.generateFrom_eq_predictable`). -/ + +/-- A basic predictable rectangle in `ℝ≥0 × Ω`: either `{⊥} ×ˢ F₀` (`F₀ ∈ ℱ₀`, +and `(⊥ : ℝ≥0) = 0`) or `Ioc a b ×ˢ F` (`F ∈ ℱₐ`, `a < b`). This is Degenne's +`Filtration.predictableRectangles` at our natural filtration — the family was +upstreamed to BrownianMotion, so we consume it rather than restate it, and get +`IsSetSemiring` (strictly more than the π-system this tower needs) for free. No +`T` constraint at the σ-algebra level: T enters only via `timeMeasureHorizon`. -/ +noncomputable def predictableRect (hBmeas : ∀ t, Measurable (B t)) : + Set (Set (ℝ≥0 × Ω)) := + (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas).predictableRectangles + +/-- The basic predictable rectangles form a **π-system**, which is all Dynkin +needs downstream. Projected from Degenne's `IsSetSemiring`: upstream proves the +strictly stronger statement (closure under intersection *and* the difference +decomposition), so the π-system property is one field of it. -/ +lemma isPiSystem_predictableRect (hBmeas : ∀ t, Measurable (B t)) : + IsPiSystem (predictableRect (mΩ := mΩ) hBmeas) := + (MeasureTheory.Filtration.isSetSemiring_predictableRectangles _).isPiSystem + +/-- Generators of the predictable σ-algebra: the basic predictable rectangles +form a generating family. -/ +theorem generateFrom_predictableRect (hBmeas : ∀ t, Measurable (B t)) : + MeasurableSpace.generateFrom (predictableRect (mΩ := mΩ) hBmeas) = + (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas).predictable := by + set 𝓕 := ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas + apply le_antisymm + · -- ≤: every basic rectangle is predictable-measurable + apply MeasurableSpace.generateFrom_le + rintro S (⟨F₀, hF₀, rfl⟩ | ⟨a, b, _hab, F, hF, rfl⟩) + · -- `{0} ×ˢ F₀ = {⊥} ×ˢ F₀` (`(⊥ : ℝ≥0) = 0` by `rfl`) + exact MeasureTheory.measurableSet_predictable_singleton_bot_prod (𝓕 := 𝓕) hF₀ + · exact MeasureTheory.measurableSet_predictable_Ioc_prod (𝓕 := 𝓕) a b hF + · -- ≥: the predictable σ-algebra is contained in `generateFrom predictableRect` + apply MeasureTheory.measurableSpace_le_predictable_of_measurableSet + -- Bot generator `{⊥} ×ˢ A`: directly a basic rectangle (`⊥ = 0`) + · intro A hA + exact MeasurableSpace.measurableSet_generateFrom + (MeasureTheory.Filtration.singletonBot_prod_mem_predictableRectangles _ hA) + -- Ioi generator `Ioi i ×ˢ A`: write as countable union of `Ioc i (seq n) ×ˢ A` + · intro i A hA + obtain ⟨seq, _hmono, htends⟩ := + Filter.exists_seq_monotone_tendsto_atTop_atTop ℝ≥0 + have h_Ioi : (Set.Ioi i : Set ℝ≥0) = ⋃ n : ℕ, Set.Ioc i (seq n) := by + ext s + simp only [Set.mem_Ioi, Set.mem_iUnion, Set.mem_Ioc] + refine ⟨fun his ↦ ?_, fun ⟨_, h, _⟩ ↦ h⟩ + rw [Filter.tendsto_atTop_atTop] at htends + obtain ⟨n, hn⟩ := htends s + exact ⟨n, his, hn n le_rfl⟩ + rw [h_Ioi, Set.iUnion_prod_const] + exact MeasurableSet.iUnion fun n ↦ MeasurableSpace.measurableSet_generateFrom + (MeasureTheory.Filtration.Ioc_prod_mem_predictableRectangles _ i (seq n) hA) + +/-! ### Phase 4: T-restricted simple-process embedding + +The bridge `trimMeasure = trim_full.restrict (Ioc 0 T × univ)` lets us reuse +`ItoIntegralL2.memLp_uncurry_trim` (the full-trim `L²` claim) by simply +restricting to `[0,T] × Ω`. T-bounded simple processes (intervals ≤ T) form a +submodule of `SimpleProcess`; on this submodule, the existing Itô isometry +(`assembly_isometry`) directly gives the T-Itô isometry — no separate +T-truncation machinery needed. -/ + +/-- **Bridge.** The T-restricted predictable trim equals the restriction of the +full predictable trim to `Ioc 0 T × univ`. Proof: `prod_restrict_eq_prod_univ` +moves the time-restrict out of the product, then `restrict_trim` swaps `restrict` +and `trim` (legal because `Ioc 0 T × univ` is a basic predictable rectangle, hence +predictable-measurable). -/ +lemma trimMeasure_eq_restrict (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) : + trimMeasure (μ := μ) T hBmeas = + ((ItoIntegralL2.timeMeasure.prod μ).trim + (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod).restrict + (Set.Ioc 0 T ×ˢ Set.univ) := by + set 𝓕 := ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas + change ((timeMeasureHorizon T).prod μ).trim 𝓕.predictable_le_prod = _ + unfold timeMeasureHorizon + rw [Measure.restrict_prod_eq_prod_univ, + ← MeasureTheory.restrict_trim 𝓕.predictable_le_prod _ + (MeasureTheory.measurableSet_predictable_Ioc_prod (𝓕 := 𝓕) 0 T MeasurableSet.univ)] + +/-- **The `T`-trim lives on `(0, T] × Ω`**: trim-a.e. `z`, the time coordinate `z.1` lies in +`Ioc 0 T`. The pointwise reading of `trimMeasure_eq_restrict` — a restriction charges nothing +outside the set it restricts to. What an integrand does past the horizon is therefore invisible +to the trim, so a time cutoff that is the identity on `[0, T]` may be erased from any +trim-a.e. statement. -/ +lemma ae_fst_mem_Ioc_trimMeasure (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) : + ∀ᵐ z ∂(trimMeasure (μ := μ) T hBmeas), z.1 ∈ Set.Ioc 0 T := by + rw [trimMeasure_eq_restrict] + exact (ae_restrict_mem (MeasureTheory.measurableSet_predictable_Ioc_prod + (𝓕 := ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas) 0 T MeasurableSet.univ)).mono + fun _ hz ↦ hz.1 + +variable (hB : IsPreBrownianReal B μ) + +/-- `uncurry V ∈ L²` in the T-restricted trim. Mirrors +`ItoIntegralL2.memLp_uncurry_trim` via the bridge + `MemLp.restrict`. -/ +lemma memLp_uncurry_trimMeasure (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) : + MemLp (Function.uncurry ⇑V) 2 (trimMeasure (μ := μ) T hBmeas) := by + rw [trimMeasure_eq_restrict] + exact (ItoIntegralL2.memLp_uncurry_trim hBmeas V).restrict _ + +omit [IsProbabilityMeasure μ] in +/-- An `L²` class of the predictable trim is `L²` of the product measure itself: the trim only +coarsens the σ-algebra, so `MemLp` lifts through `memLp_of_memLp_trim`. -/ +lemma memLp_prod_of_lp (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + MemLp (⇑φ) 2 ((timeMeasureHorizon T).prod μ) := + memLp_of_memLp_trim (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod + (Lp.memLp φ) + +/-- The simple process's `L²` class in the T-restricted trim. -/ +noncomputable def simpleProcessL2Horizon (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) : + Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) := + (memLp_uncurry_trimMeasure T hBmeas V).toLp (Function.uncurry ⇑V) + +/-! ### T-bounded simple processes -/ + +/-- The submodule of simple processes whose intervals all have right endpoint +`≤ T`. The discrete Itô integral `∑ V(p)(B_{p.2}−B_{p.1})` on such a `V` +automatically lives in `[0,T]`, so the existing `assembly_isometry` directly +gives the T-Itô isometry. -/ +def TBoundedSP (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) : + Submodule ℝ (SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) where + carrier := { V | ∀ p ∈ V.value.support, p.2 ≤ T } + add_mem' {V W} hV hW p hp := by + rcases Finset.mem_union.mp (Finsupp.support_add hp) with h | h + · exact hV p h + · exact hW p h + zero_mem' p hp := absurd hp (by simp) + smul_mem' c V hV p hp := hV p (Finsupp.support_smul hp) + +/-- For T-bounded `V`, `uncurry V` vanishes for `t > T`. The bot piece vanishes +because `t > T ≥ ⊥` rules out `t = ⊥`; each interval piece +`1_{Ioc p.1 p.2}(t) · V(p)(ω)` vanishes because `t > T ≥ p.2`. -/ +lemma uncurry_eq_zero_of_lt {T : ℝ≥0} {hBmeas : ∀ t, Measurable (B t)} + (V : TBoundedSP T hBmeas) {t : ℝ≥0} (ht : T < t) (ω : Ω) : + Function.uncurry ⇑V.val (t, ω) = 0 := by + change ⇑V.val t ω = 0 + rw [SimpleProcess.apply_eq] + have ht0 : t ≠ ⊥ := by + intro h + rw [h, NNReal.bot_eq_zero] at ht + exact absurd ht (by simp) + have hbot : ({(⊥ : ℝ≥0)} : Set ℝ≥0).indicator + (fun _ ↦ V.val.valueBot ω) t = 0 := + Set.indicator_of_notMem (by simpa using ht0) _ + rw [hbot, zero_add, Finsupp.sum] + refine Finset.sum_eq_zero fun p hp ↦ ?_ + refine Set.indicator_of_notMem ?_ _ + simp only [Set.mem_Ioc, not_and, not_le] + intro _ + exact lt_of_le_of_lt (V.property p hp) ht + +/-- For T-bounded `V`, the `L²` norm of `uncurry V` in `trim_T` equals the norm +in the full trim. Both integrate `|uncurry V|²` over the same effective support: +trim_T integrates over `[0,T] × Ω`, and `uncurry V` vanishes off it (the bot +fibre `{0} × Ω` has measure zero in `timeMeasure.prod μ`). Pure +measure-theoretic equality — `IsPreBrownianReal B μ` is not needed. -/ +private lemma eLpNorm_uncurry_trim_T_eq_trim (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (V : TBoundedSP T hBmeas) : + eLpNorm (Function.uncurry ⇑V.val) 2 (trimMeasure (μ := μ) T hBmeas) + = eLpNorm (Function.uncurry ⇑V.val) 2 + ((ItoIntegralL2.timeMeasure.prod μ).trim + (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod) := by + set 𝓕 := ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas + -- `Ioc 0 T × univ` is predictable-measurable (the natural σ-algebra of the + -- trimmed measure). The `eLpNorm_indicator_eq_eLpNorm_restrict` lemma uses + -- the trim's σ-algebra (via the file-level variable binding), so we need the + -- predictable witness, not the larger product one. + have hS_pred : MeasurableSet[𝓕.predictable] (Set.Ioc 0 T ×ˢ (Set.univ : Set Ω)) := + MeasureTheory.measurableSet_predictable_Ioc_prod (𝓕 := 𝓕) 0 T MeasurableSet.univ + -- The bot fibre `{0} × Ω` has zero predictable-trim-measure (timeMeasure {0} = 0). + have hnull : ((ItoIntegralL2.timeMeasure.prod μ).trim 𝓕.predictable_le_prod) + ({(0 : ℝ≥0)} ×ˢ (Set.univ : Set Ω)) = 0 := by + have hbot_meas : MeasurableSet[𝓕.predictable] ({(0 : ℝ≥0)} ×ˢ (Set.univ : Set Ω)) := + MeasureTheory.measurableSet_predictable_singleton_bot_prod + (𝓕 := 𝓕) (s := (Set.univ : Set Ω)) MeasurableSet.univ + rw [MeasureTheory.trim_measurableSet_eq 𝓕.predictable_le_prod hbot_meas, + Measure.prod_prod, ItoIntegralL2.timeMeasure_singleton, zero_mul] + -- For T-bounded V: indicator over `Ioc 0 T × univ` of `uncurry V` is a.e. equal + -- to `uncurry V` itself (the difference is supported on the null bot fibre). + have hae : {z : ℝ≥0 × Ω | z.1 ≠ 0} ∈ MeasureTheory.ae + ((ItoIntegralL2.timeMeasure.prod μ).trim 𝓕.predictable_le_prod) := by + rw [show {z : ℝ≥0 × Ω | z.1 ≠ 0} = ({(0 : ℝ≥0)} ×ˢ (Set.univ : Set Ω))ᶜ by + ext ⟨t, ω⟩; simp] + exact compl_mem_ae_iff.mpr hnull + have h_ae_eq : (Set.Ioc 0 T ×ˢ (Set.univ : Set Ω)).indicator (Function.uncurry ⇑V.val) + =ᵐ[((ItoIntegralL2.timeMeasure.prod μ).trim 𝓕.predictable_le_prod)] + Function.uncurry ⇑V.val := by + filter_upwards [hae] with z hz + -- hz : z.1 ≠ 0 + by_cases htT : z.1 ≤ T + · rw [Set.indicator_of_mem] + refine ⟨⟨?_, htT⟩, Set.mem_univ _⟩ + exact pos_iff_ne_zero.mpr hz + · push Not at htT + rw [Set.indicator_of_notMem] + · exact (uncurry_eq_zero_of_lt V htT z.2).symm + · intro ⟨⟨_, hle⟩, _⟩ + exact absurd hle (not_le.mpr htT) + -- Chain: trim_T → restrict (bridge) → indicator (lemma, .symm) → uncurry V (a.e.). + calc eLpNorm (Function.uncurry ⇑V.val) 2 (trimMeasure (μ := μ) T hBmeas) + = eLpNorm (Function.uncurry ⇑V.val) 2 + (((ItoIntegralL2.timeMeasure.prod μ).trim 𝓕.predictable_le_prod).restrict + (Set.Ioc 0 T ×ˢ Set.univ)) := by rw [trimMeasure_eq_restrict] + _ = eLpNorm ((Set.Ioc 0 T ×ˢ (Set.univ : Set Ω)).indicator (Function.uncurry ⇑V.val)) 2 + ((ItoIntegralL2.timeMeasure.prod μ).trim 𝓕.predictable_le_prod) := + (MeasureTheory.eLpNorm_indicator_eq_eLpNorm_restrict hS_pred.nullMeasurableSet).symm + _ = eLpNorm (Function.uncurry ⇑V.val) 2 + ((ItoIntegralL2.timeMeasure.prod μ).trim 𝓕.predictable_le_prod) := + MeasureTheory.eLpNorm_congr_ae h_ae_eq + +/-- The T-restricted simple-process `L²` norm equals the full-trim norm for +T-bounded `V`. -/ +private lemma simpleProcessL2Horizon_norm_eq (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (V : TBoundedSP T hBmeas) : + ‖simpleProcessL2Horizon (μ := μ) T hBmeas V.val‖ + = ‖ItoIntegralL2.simpleProcessL2 (μ := μ) hBmeas V.val‖ := by + have h := eLpNorm_uncurry_trim_T_eq_trim (μ := μ) T hBmeas V + unfold simpleProcessL2Horizon ItoIntegralL2.simpleProcessL2 + rw [Lp.norm_toLp, Lp.norm_toLp, h] + +/-- **The T-restricted simple-process `L²` embedding** as a linear map. -/ +noncomputable def simpleAssemblyHorizon (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) : + TBoundedSP T hBmeas →ₗ[ℝ] Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) where + toFun V := simpleProcessL2Horizon T hBmeas V.val + map_add' V W := by + change simpleProcessL2Horizon T hBmeas ((V + W).val) = _ + rw [Submodule.coe_add, simpleProcessL2Horizon, simpleProcessL2Horizon, simpleProcessL2Horizon, + ← MemLp.toLp_add (memLp_uncurry_trimMeasure T hBmeas V.val) + (memLp_uncurry_trimMeasure T hBmeas W.val)] + congr 1 + exact ItoIntegralL2.uncurry_coe_add hBmeas V.val W.val + map_smul' c V := by + change simpleProcessL2Horizon T hBmeas ((c • V).val) = _ + rw [Submodule.coe_smul, simpleProcessL2Horizon, simpleProcessL2Horizon, RingHom.id_apply, + ← MemLp.toLp_const_smul c (memLp_uncurry_trimMeasure T hBmeas V.val)] + congr 1 + exact ItoIntegralL2.uncurry_coe_smul hBmeas c V.val + +/-- The Itô assembly composed with the inclusion `TBoundedSP T ↪ SimpleProcess`. +For T-bounded `V`, the discrete Itô integral `∑ V(p)(B_{p.2}−B_{p.1})` +automatically lives in `[0,T]`. -/ +noncomputable def itoAssemblyHorizon (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) : + TBoundedSP T hBmeas →ₗ[ℝ] Lp ℝ 2 μ := + (ItoIntegralL2.itoAssembly hB hBmeas).comp (TBoundedSP T hBmeas).subtype + +/-- **The T-restricted Itô isometry on simple processes.** Inherits the full +isometry (`ItoIntegralL2.assembly_isometry`) via the trim-norm equality. -/ +theorem norm_itoAssemblyHorizon (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (V : TBoundedSP T hBmeas) : + ‖itoAssemblyHorizon hB T hBmeas V‖ = ‖simpleAssemblyHorizon (μ := μ) T hBmeas V‖ := by + change ‖ItoIntegralL2.itoAssembly hB hBmeas V.val‖ + = ‖simpleProcessL2Horizon (μ := μ) T hBmeas V.val‖ + rw [simpleProcessL2Horizon_norm_eq T hBmeas V] + exact ItoIntegralL2.assembly_isometry hB hBmeas V.val + +/-! ### Phase 5: Set-integral vanishing on the orthogonal complement + +The heart of the density argument. A function `g ∈ L²(trim_T)` whose set-integral +over every basic predictable rectangle vanishes has vanishing set-integral on +every measurable set in the predictable σ-algebra. The proof is Dynkin's π-λ +theorem applied to `predictableRect` (π-system from Phase 2; generator from +Phase 3). The total-integral step uses that `Ioc 0 T × univ` is a basic +rectangle (when `T > 0`) and supports `trim_T` fully; for `T = 0`, `trim_T` is +the zero measure and the total integral is trivially zero. -/ + +/-- `trimMeasure` is a finite measure (product of `timeMeasureHorizon` — bounded +by `T` — and the probability measure `μ`, then trimmed). -/ +instance (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) : + IsFiniteMeasure (trimMeasure (μ := μ) T hBmeas) := by + unfold trimMeasure + infer_instance + +/-- The heart of the density argument, reused by the unbounded-horizon CLM +(`ItoIntegralL2Dense`): a function `g ∈ L²(trim_T)` whose set-integral over every +basic predictable rectangle vanishes has vanishing set-integral over every +predictable-measurable set. Dynkin's π-λ theorem over `predictableRect`; the +total-integral step uses finiteness of `trimMeasure`. -/ +lemma setIntegral_eq_zero_of_orthogonal_pred (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) + {g : ℝ≥0 × Ω → ℝ} + (hg_int : Integrable g (trimMeasure (μ := μ) T hBmeas)) + (h_orth : ∀ R ∈ predictableRect (mΩ := mΩ) hBmeas, + ∫ z in R, g z ∂(trimMeasure (μ := μ) T hBmeas) = 0) + (s : Set (ℝ≥0 × Ω)) + (hs : MeasurableSet[(ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas).predictable] s) : + ∫ z in s, g z ∂(trimMeasure (μ := μ) T hBmeas) = 0 := by + set 𝓕 := ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas + -- Total integral vanishes: trim_T is supported on `Ioc 0 T × univ`. For + -- `T > 0` the rect is in `predictableRect` (orthogonality); for `T = 0` + -- trim_T is zero. + have h_total : ∫ z, g z ∂(trimMeasure (μ := μ) T hBmeas) = 0 := by + by_cases hT : 0 < T + · -- `T > 0`: split ∫ univ into ∫_S + ∫_Sᶜ; both vanish. + have hR : Set.Ioc 0 T ×ˢ (Set.univ : Set Ω) ∈ predictableRect (mΩ := mΩ) hBmeas := + Or.inr ⟨0, T, hT, Set.univ, MeasurableSet.univ, rfl⟩ + have hS_pred : MeasurableSet[𝓕.predictable] (Set.Ioc 0 T ×ˢ (Set.univ : Set Ω)) := + MeasureTheory.measurableSet_predictable_Ioc_prod (𝓕 := 𝓕) 0 T MeasurableSet.univ + -- Sᶜ has zero trim_T-measure: trim_T = trim_full.restrict S, so trim_T Sᶜ = trim_full(Sᶜ∩S) = + -- 0. + have hSc_null : + (trimMeasure (μ := μ) T hBmeas) (Set.Ioc 0 T ×ˢ (Set.univ : Set Ω))ᶜ = 0 := by + rw [trimMeasure_eq_restrict, + Measure.restrict_apply (MeasurableSet.compl hS_pred), + Set.compl_inter_self] + exact measure_empty + have h_int_Sc : ∫ z in (Set.Ioc 0 T ×ˢ Set.univ)ᶜ, g z + ∂(trimMeasure (μ := μ) T hBmeas) = 0 := + setIntegral_measure_zero g hSc_null + have h_int_S := h_orth _ hR + have h_split := integral_add_compl + (μ := trimMeasure (μ := μ) T hBmeas) (f := g) hS_pred hg_int + linarith + · -- `T = 0`: trim_T is the zero measure. + push Not at hT + have hT0 : T = 0 := le_antisymm hT bot_le + have h_zero : trimMeasure (μ := μ) T hBmeas = 0 := by + subst hT0 + unfold trimMeasure timeMeasureHorizon + rw [Set.Ioc_self, Measure.restrict_empty, Measure.zero_prod, + MeasureTheory.zero_trim] + -- Extract `g` as a standalone function to avoid the motive issue. + let gf : ℝ≥0 × Ω → ℝ := (g : ℝ≥0 × Ω → ℝ) + change ∫ z, gf z ∂(trimMeasure (μ := μ) T hBmeas) = 0 + rw [h_zero] + exact integral_zero_measure gf + -- π-system induction over `predictableRect` (Phase 2 + Phase 3). + refine MeasurableSpace.induction_on_inter + (C := fun s _ ↦ ∫ z in s, g z ∂(trimMeasure (μ := μ) T hBmeas) = 0) + (h_eq := (generateFrom_predictableRect hBmeas).symm) + (h_inter := isPiSystem_predictableRect hBmeas) + (empty := setIntegral_empty) + (basic := fun R hR ↦ h_orth R hR) + (compl := ?_) (iUnion := ?_) s hs + · -- Complement: `∫ g = ∫_S g + ∫_Sᶜ g`; total is zero, S piece is zero, so Sᶜ piece is zero. + intro S hS hPS + have h_split := integral_add_compl + (μ := trimMeasure (μ := μ) T hBmeas) (f := g) hS hg_int + linarith + · -- Disjoint countable union. + intro f hf hfm hf_zero + rw [integral_iUnion hfm hf hg_int.integrableOn] + simp [hf_zero] + +/-! ### Phase 6: Density of `simpleAssemblyHorizon` and the CLM + +The image of `simpleAssemblyHorizon : TBoundedSP T →ₗ[ℝ] Lp ℝ 2 trim_T` is dense. +Proof: orthogonal-complement argument. Take `g ⊥ range(simpleAssemblyHorizon)`. +For each basic predictable rect `R` we construct a T-bounded SP `V_R` such that +`⟪simpleAssemblyHorizon V_R, g⟫ = ∫_R g d trim_T`. Orthogonality gives the integral +zero; Phase 5 extends to all measurable sets; `ae_eq_zero_of_forall_setIntegral` +concludes `g = 0`. The CLM `itoIntegralCLM` is then the `extendOfNorm` of +`itoAssemblyHorizon` along the (now dense) `simpleAssemblyHorizon`. -/ + +/-- The T-bounded SimpleProcess representing the indicator of `Ioc a b × F`, +built from upstream `ElementaryPredictableSet.IocProd.indicator`. We require +`a ≤ b` (so the IocProd's index set `I` is `{(a, b)}`) and `b ≤ T` (so the only +interval is in `[0, T]`). -/ +noncomputable def iocSPHorizon {T : ℝ≥0} (hBmeas : ∀ t, Measurable (B t)) + {a b : ℝ≥0} (hab : a ≤ b) (hbT : b ≤ T) {F : Set Ω} + (hF : MeasurableSet[(ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas) a] F) : + TBoundedSP T hBmeas := + ⟨(ElementaryPredictableSet.IocProd a b hF).indicator (1 : ℝ), fun p hp ↦ by + -- The value is `Finsupp.onFinset I (...)` so its support is contained in I. + have h_I_eq : (ElementaryPredictableSet.IocProd a b hF).I = {(a, b)} := by + change (if a ≤ b then ({(a, b)} : Finset _) else ∅) = _ + rw [ite_eq_left hab] + have h_in_I : p ∈ (ElementaryPredictableSet.IocProd a b hF).I := by + by_contra hp_not + apply Finsupp.mem_support_iff.mp hp + change ((ElementaryPredictableSet.IocProd a b hF).indicator 1).value p = 0 + simp [ElementaryPredictableSet.indicator, Finsupp.onFinset_apply, hp_not] + rw [h_I_eq, Finset.mem_singleton] at h_in_I + rcases h_in_I with rfl + exact hbT⟩ + +/-- The uncurry of `iocSPHorizon hab hbT hF` agrees pointwise with `(Ioc a b × F).indicator 1`. +Public because `PredictableDensityGeneral` needs it to run the same rectangle argument +against the bracket-weighted measure. -/ +lemma uncurry_iocSPHorizon_eq {T : ℝ≥0} (hBmeas : ∀ t, Measurable (B t)) + {a b : ℝ≥0} (hab : a ≤ b) (hbT : b ≤ T) {F : Set Ω} + (hF : MeasurableSet[(ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas) a] F) : + Function.uncurry ⇑(iocSPHorizon hBmeas hab hbT hF : TBoundedSP T hBmeas).val + = (Set.Ioc a b ×ˢ F).indicator (fun _ ↦ (1 : ℝ)) := by + funext ⟨t, ω⟩ + change ⇑((ElementaryPredictableSet.IocProd a b hF).indicator (1 : ℝ)) t ω + = (Set.Ioc a b ×ˢ F).indicator (fun _ ↦ (1 : ℝ)) (t, ω) + rw [ElementaryPredictableSet.coe_indicator, + ElementaryPredictableSet.coe_IocProd a b hF] + rfl + +/-- Inner product of `simpleAssemblyHorizon (iocSPHorizon ...)` with `g` equals the +set-integral of `g` over the rectangle. -/ +private lemma inner_simpleAssemblyHorizon_iocSPHorizon {T : ℝ≥0} (hBmeas : ∀ t, Measurable (B t)) + {a b : ℝ≥0} (hab : a ≤ b) (hbT : b ≤ T) {F : Set Ω} + (hF : MeasurableSet[(ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas) a] F) + (g : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ⟪simpleAssemblyHorizon (μ := μ) T hBmeas (iocSPHorizon hBmeas hab hbT hF), g⟫_ℝ + = ∫ z in Set.Ioc a b ×ˢ F, g z ∂(trimMeasure (μ := μ) T hBmeas) := by + set 𝓕 := ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas + -- The Lp inner product takes its typeclass MeasurableSpace from trim_T's σ-alg + -- (which is predictable, not the default product σ-alg). Make it explicit so + -- `L2.inner_def` synthesises correctly. + let : MeasurableSpace (ℝ≥0 × Ω) := 𝓕.predictable + rw [L2.inner_def] + -- The L² inner product unfolds to ∫ ⟪f z, g z⟫_ℝ = ∫ g z * f z (Mathlib's + -- real inner product convention `⟪x, y⟫_ℝ = y * x`). + have h_coe := MemLp.coeFn_toLp + (memLp_uncurry_trimMeasure (μ := μ) T hBmeas + (iocSPHorizon hBmeas hab hbT hF : TBoundedSP T hBmeas).val) + have h_uncurry_eq := uncurry_iocSPHorizon_eq hBmeas hab hbT hF + have h_ae_eq : ∀ᵐ z ∂(trimMeasure (μ := μ) T hBmeas), + (⟪(simpleAssemblyHorizon (μ := μ) T hBmeas (iocSPHorizon hBmeas hab hbT hF) : ℝ≥0 × Ω → ℝ) z, + (g : ℝ≥0 × Ω → ℝ) z⟫_ℝ : ℝ) + = (Set.Ioc a b ×ˢ F).indicator (fun z ↦ (g : ℝ≥0 × Ω → ℝ) z) z := by + filter_upwards [h_coe] with z hz + -- Rewrite simpleAssemblyHorizon V into uncurry V via h_coe; then uncurry V via h_uncurry_eq. + have hSA_eq : + (simpleAssemblyHorizon (μ := μ) T hBmeas (iocSPHorizon hBmeas hab hbT hF) : ℝ≥0 × Ω → ℝ) z + = (Set.Ioc a b ×ˢ F).indicator (fun _ ↦ (1 : ℝ)) z := by + calc (simpleAssemblyHorizon (μ := μ) T hBmeas (iocSPHorizon hBmeas hab hbT hF) : + ℝ≥0 × Ω → ℝ) z + = Function.uncurry ⇑(iocSPHorizon hBmeas hab hbT hF : TBoundedSP T hBmeas).val z := hz + _ = (Set.Ioc a b ×ˢ F).indicator (fun _ ↦ (1 : ℝ)) z := by rw [h_uncurry_eq] + rw [hSA_eq] + -- Real inner product: ⟪x, y⟫_ℝ = y * x for x, y : ℝ. + change (g : ℝ≥0 × Ω → ℝ) z * (Set.Ioc a b ×ˢ F).indicator (fun _ ↦ (1 : ℝ)) z + = (Set.Ioc a b ×ˢ F).indicator (fun z ↦ (g : ℝ≥0 × Ω → ℝ) z) z + by_cases hz_in : z ∈ Set.Ioc a b ×ˢ F + · rw [Set.indicator_of_mem hz_in, Set.indicator_of_mem hz_in, mul_one] + · rw [Set.indicator_of_notMem hz_in, Set.indicator_of_notMem hz_in, mul_zero] + rw [integral_congr_ae h_ae_eq] + -- ∫ z, R.indicator g z d trim_T = ∫_R g z d trim_T (since R is predictable-measurable) + exact integral_indicator + (MeasureTheory.measurableSet_predictable_Ioc_prod (𝓕 := 𝓕) a b hF) + +/-! ### Density of `simpleAssemblyHorizon` -/ + +/-- Bridge lemma: integrating any `g : Lp 2 trim_T` over a predictable-measurable `R` equals the +integral over `R ∩ (Ioc 0 T × univ)`. The complement of `Ioc 0 T × univ` is `trim_T`-null because +`trim_T = trim_full.restrict (Ioc 0 T × univ)`. -/ +lemma setIntegral_eq_setIntegral_inter_supp {T : ℝ≥0} + (hBmeas : ∀ t, Measurable (B t)) + (g : ℝ≥0 × Ω → ℝ) (R : Set (ℝ≥0 × Ω)) + (hR : MeasurableSet[(ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas).predictable] R) : + ∫ z in R, g z ∂(trimMeasure (μ := μ) T hBmeas) = + ∫ z in R ∩ (Set.Ioc 0 T ×ˢ Set.univ), g z ∂(trimMeasure (μ := μ) T hBmeas) := by + set 𝓕 := ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas + -- Reset the typeclass to predictable σ-alg locally (trim_T's natural σ-alg). + let : MeasurableSpace (ℝ≥0 × Ω) := 𝓕.predictable + have hS_pred : MeasurableSet (Set.Ioc 0 T ×ˢ (Set.univ : Set Ω)) := + MeasureTheory.measurableSet_predictable_Ioc_prod (𝓕 := 𝓕) 0 T MeasurableSet.univ + -- (trim_T).restrict R = (trim_full.restrict S).restrict R = trim_full.restrict (R ∩ S) + -- and (trim_T).restrict (R ∩ S) = trim_full.restrict ((R ∩ S) ∩ S) = trim_full.restrict (R ∩ S). + have h1 : (trimMeasure (μ := μ) T hBmeas).restrict R + = (trimMeasure (μ := μ) T hBmeas).restrict (R ∩ Set.Ioc 0 T ×ˢ Set.univ) := by + rw [trimMeasure_eq_restrict, + Measure.restrict_restrict hR, + Measure.restrict_restrict (hR.inter hS_pred), + Set.inter_assoc, Set.inter_self] + change ∫ z, g z ∂((trimMeasure (μ := μ) T hBmeas).restrict R) + = ∫ z, g z ∂((trimMeasure (μ := μ) T hBmeas).restrict (R ∩ Set.Ioc 0 T ×ˢ Set.univ)) + rw [h1] + +/-- **Density**: the image of `simpleAssemblyHorizon` is dense in `Lp 2 trim_T`. +Proof outline: take `g ⊥ range(simpleAssemblyHorizon)`. For every basic predictable +rect `R`, derive `∫_R g d trim_T = 0`: +* For the bot piece `{0} × F₀`: subset of `{0} × univ`, which is `trim_T`-null. +* For `Ioc a b × F`: reduce to `Ioc a (min b T) × F` via the bridge, then apply + orthogonality (when non-empty) or get `∫_∅ = 0` (when degenerate). +Phase 5 extends to all predictable-measurable sets; `Lp.ae_eq_zero` concludes. -/ +theorem simpleAssemblyHorizon_denseRange (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) : + DenseRange (simpleAssemblyHorizon (μ := μ) T hBmeas) := by + set 𝓕 := ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas + suffices h_orth_bot : + (LinearMap.range (simpleAssemblyHorizon (μ := μ) T hBmeas))ᗮ = ⊥ by + rw [denseRange_iff_closure_range, + ← LinearMap.coe_range (simpleAssemblyHorizon (μ := μ) T hBmeas), + ← Submodule.topologicalClosure_coe, + Submodule.topologicalClosure_eq_top_iff.mpr h_orth_bot, Submodule.top_coe] + rw [Submodule.eq_bot_iff] + intro g h_mem + rw [Submodule.mem_orthogonal] at h_mem + -- For every basic predictable rect R, ∫_R g d trim_T = 0. + have h_orth : ∀ R ∈ predictableRect (mΩ := mΩ) hBmeas, + ∫ z in R, g z ∂(trimMeasure (μ := μ) T hBmeas) = 0 := by + intro R hR + rcases hR with ⟨F₀, hF₀, rfl⟩ | ⟨a, b, _hab, F, hF, rfl⟩ + · -- Bot: ∫_{{0} × F₀} g = 0 because {0} × F₀ ⊆ {0} × univ ⊆ (Ioc 0 T × univ)ᶜ + -- (trim_T is supported on Ioc 0 T × univ). + have h_R_pred : MeasurableSet[𝓕.predictable] ({(⊥ : ℝ≥0)} ×ˢ F₀) := + MeasureTheory.measurableSet_predictable_singleton_bot_prod (𝓕 := 𝓕) hF₀ + rw [setIntegral_eq_setIntegral_inter_supp hBmeas g _ h_R_pred] + have h_empty : ({(⊥ : ℝ≥0)} ×ˢ F₀) ∩ Set.Ioc 0 T ×ˢ (Set.univ : Set Ω) = ∅ := by + rw [Set.prod_inter_prod, + show ({(⊥ : ℝ≥0)} ∩ Set.Ioc 0 T : Set ℝ≥0) = ∅ by + ext x; simp, + Set.empty_prod] + rw [h_empty, setIntegral_empty] + · -- Ioc a b × F: bridge to Ioc a (min b T) × F, then orthogonality or empty. + have h_R_pred : MeasurableSet[𝓕.predictable] (Set.Ioc a b ×ˢ F) := + MeasureTheory.measurableSet_predictable_Ioc_prod (𝓕 := 𝓕) a b hF + rw [setIntegral_eq_setIntegral_inter_supp hBmeas g _ h_R_pred] + have h_inter : (Set.Ioc a b ×ˢ F) ∩ (Set.Ioc 0 T ×ˢ (Set.univ : Set Ω)) + = Set.Ioc (max a 0) (min b T) ×ˢ F := by + ext ⟨t, ω⟩ + simp only [Set.mem_inter_iff, Set.mem_prod, Set.mem_Ioc, Set.mem_univ, and_true] + constructor + · rintro ⟨⟨⟨h1, h2⟩, hω⟩, ⟨h3, h4⟩⟩ + exact ⟨⟨max_lt h1 h3, le_min h2 h4⟩, hω⟩ + · rintro ⟨⟨h1, h2⟩, hω⟩ + refine ⟨⟨⟨(le_max_left _ _).trans_lt h1, h2.trans (min_le_left _ _)⟩, hω⟩, ?_⟩ + exact ⟨(le_max_right _ _).trans_lt h1, h2.trans (min_le_right _ _)⟩ + rw [h_inter] + have hmax : max a 0 = a := max_eq_left bot_le + rw [hmax] + -- Now: ∫_{Ioc a (min b T) × F} g d trim_T = 0 + by_cases hab' : a ≤ min b T + · -- Build iocSPHorizon at (a, min b T, F): T-bounded with b' = min b T ≤ T. + have hbT' : min b T ≤ T := min_le_right _ _ + have h_set := inner_simpleAssemblyHorizon_iocSPHorizon (μ := μ) hBmeas hab' hbT' hF g + have h_inner := h_mem _ ⟨iocSPHorizon hBmeas hab' hbT' hF, rfl⟩ + rw [← h_set] + exact h_inner + · -- a > min b T: Ioc a (min b T) = ∅, so R_T = ∅. + push Not at hab' + rw [Set.Ioc_eq_empty (not_lt.mpr hab'.le), Set.empty_prod, setIntegral_empty] + -- Apply Phase 5 + Lp.ae_eq_zero_of_forall_setIntegral_eq_zero. Use letI to make + -- trim_T's σ-alg (predictable) the ambient typeclass. + let : MeasurableSpace (ℝ≥0 × Ω) := 𝓕.predictable + refine (Lp.eq_zero_iff_ae_eq_zero (f := g)).mpr ?_ + exact Lp.ae_eq_zero_of_forall_setIntegral_eq_zero g + (by norm_num : (2 : ℝ≥0∞) ≠ 0) (by norm_num : (2 : ℝ≥0∞) ≠ ∞) + (fun _ _ _ ↦ ((Lp.memLp g).integrable one_le_two).integrableOn) + (fun s hs _ ↦ setIntegral_eq_zero_of_orthogonal_pred T hBmeas + ((Lp.memLp g).integrable one_le_two) h_orth s hs) + +end ItoIntegralCLM +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralL2.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralL2.lean new file mode 100644 index 0000000000..3ccdf219cf --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralL2.lean @@ -0,0 +1,530 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.KLS.BrownianMotion.StochasticIntegral.SimpleProcess +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIsometryAdapted +public import LeanPool.KLS.BrownianMotion.StochasticIntegral.Predictable +public import Mathlib.RingTheory.PiTensorProduct +public import Mathlib.RingTheory.WittVector.IsPoly +public import Mathlib.Tactic.ReduceModChar +public import Std.Tactic.BVDecide.Normalize.Prop + +/-! +# The L²-adapted Itô isometry, anchored on Degenne's `SimpleProcess` + +This file establishes the **Itô isometry for adapted simple processes** — the substantive +analytic content of the L² Itô integral — built on Degenne's +`BrownianMotion.StochasticIntegral` objects (the maximally-coherent choice). The Itô integral +*operator* itself (the CLM `itoIntegralCLM`) is assembled from this isometry in +`ItoIntegralCLM.lean`; the *discrete* isometry core is `ItoIsometryAdapted.lean`. The cornerstone +is that the cross-terms vanish by the **weak Markov property** (`rect_increment_pairing`, +from `ItoIsometryAdapted.lean`), *not* by deterministic covariance — the precise distinction +between the Itô integral (random adapted integrands) and the Wiener integral (deterministic +integrands, `WienerIntegralL2.lean`). Degenne's `SimpleProcess` allows *overlapping* +intervals, which is exactly why `rect_increment_pairing` is the right tool. + +## Main definitions + +* `natFiltration`: the natural Brownian filtration `𝓕ᴮ_t = σ(B_u : u ≤ t)`. +* `itoSimple`: the elementary Itô integral of a simple process `V` at the terminal time, + `∑ₚ V(p) · (B_{p.2} − B_{p.1})`. +* `itoSimpleLp`: that integral as an element of `Lp ℝ 2 μ`. +* `itoAssembly`: the elementary Itô integral as a linear map `SimpleProcess →ₗ[ℝ] Lp ℝ 2 μ`. +* `timeMeasure`: Lebesgue measure on the time axis `ℝ≥0`. +* `elemIntegrand`: the elementary integrand `Z · 1_{(a,b]}`, a bounded weight on `Ω` switched on + over a time band. +* `rectTerm`: the contribution `𝟙_{(p.1,p.2]}(t) · V(p)(ω)` of one interval `p` to the uncurried + simple process. +* `simpleProcessL2`: the embedding of a simple process into the predictable `L²` space, as the + class of its uncurried version. +* `simpleAssembly`: that embedding as a linear map. + +## Main results + +* `SimpleProcess.coe_finset_sum` — Degenne's `coe_add`, summed over a `Finset`: the coercion + of a finite sum of simple processes is the sum of the coercions (an upstream candidate). +* `elemIntegrand` — the elementary integrand `Z·1_{(a,b]}`, and `rectTerm` its instance at a + simple process's band; `uncurry_ae_eq_sum_rectTerm_of_ae_fst_ne_zero` decomposes a simple + process into its bands for **any** measure charging the time origin nothing, which is what + lets the bracket-weighted spaces of the integral-against-a-martingale reuse it. +* `itoSimple` / `itoSimple_apply` — the elementary Itô integral + `(V ● B)_⊤ = ∑ₚ V(p)·(B_{p.2}−B_{p.1})` (Degenne's `SimpleProcess.integral` against + multiplication, at the terminal time `⊤`). +* `memLp_itoSimple` / `itoSimpleLp` — it lies in `L²(μ)`. +* `itoSimple_sq_integral` / `itoSimpleLp_norm_sq` — **the Itô isometry**: + `‖itoSimpleLp V‖² = ∫ (itoSimple V)² dμ = Σ_{p,q} E[V(p)·V(q)] · vol((p]∩(q])`. + +## Toward the continuous integral + +The continuous extension to a CLM `L2Predictable ν μ →L[ℝ] Lp ℝ 2 μ` is built on top of the +isometry by L²-completion: the time measure `ν` (Lebesgue on `ℝ≥0`, below), the embedding of +simple processes into the predictable `L²`, density of those embeddings (via +`generateFrom_eq_predictable`), and `LinearMap.extendOfNorm`. This is the foundation of a +continuous-time Itô-*calculus* layer (Itô's lemma, SDEs). The full resume-plan is in +`docs/archive/ito-integral-clm-deferred.md`. + +## Tags + +Itô isometry, simple processes, elementary Itô integral, natural filtration, stochastic integral, +weak Markov property, MSC 60H05, MSC 60G44, MSC 60J65 +-/ + +@[expose] public section + +namespace ProbabilityTheory.SimpleProcess + +variable {ι Ω E : Type*} [LinearOrder ι] [OrderBot ι] {mΩ : MeasurableSpace Ω} + [NormedAddCommGroup E] [MeasurableSpace E] [NormedSpace ℝ E] [BorelSpace E] + [SecondCountableTopology E] {𝓕 : MeasureTheory.Filtration ι mΩ} + +/-- The coercion of a finite sum of simple processes is the sum of the coercions: `coe_zero` and +`coe_add` make the coercion an additive map, and `map_sum` sums it. -/ +theorem coe_finset_sum {κ : Type*} (s : Finset κ) (W : κ → SimpleProcess E 𝓕) : + ⇑(∑ k ∈ s, W k) = ∑ k ∈ s, ⇑(W k) := + map_sum (⟨⟨fun V ↦ ⇑V, coe_zero⟩, coe_add⟩ : SimpleProcess E 𝓕 →+ ι → Ω → E) W s + +end ProbabilityTheory.SimpleProcess + +namespace MathFin +namespace ItoIntegralL2 + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal InnerProductSpace + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + {B : ℝ≥0 → Ω → ℝ} + +/-- The **natural Brownian filtration** `𝓕ᴮ_t = σ(B_u : u ≤ t)`. -/ +noncomputable def natFiltration (hBmeas : ∀ t, Measurable (B t)) : Filtration ℝ≥0 mΩ := + Filtration.natural B (fun t ↦ (hBmeas t).stronglyMeasurable) + +/-- `B` is adapted to its own natural filtration +(Mathlib's `Filtration.stronglyAdapted_natural`). -/ +theorem stronglyAdapted_natFiltration (hBmeas : ∀ t, Measurable (B t)) : + StronglyAdapted (natFiltration hBmeas) B := + Filtration.stronglyAdapted_natural _ + +/-- The **elementary Itô integral** of a simple process `V` against Brownian motion +`B`, evaluated at the terminal time: `(V ● B)_⊤ = ∑ₚ V(p)·(B_{p.2} − B_{p.1})`, +the increment sum with nothing truncated. + +Until the 2026-07-27 pin this *was* Degenne's `SimpleProcess.integral … ⊤`: his +elementary integral was indexed by `WithTop ι`, so `⊤` named the untruncated +value and `SimpleProcess.integral_top` unfolded it to this sum. At the new pin +`integral : ι → Ω → G` — the index dropped `WithTop`, `integral_top` is +commented out upstream, and with `ι = ℝ≥0` there is no `⊤` to evaluate at. The +untruncated value is therefore no longer *expressible* as an evaluation of +`integral`, and is taken as the definition here. + +Nothing downstream is weakened: every consumer goes through `itoSimple_apply` +(now definitional), and the process-level integral `itoSimpleProcess` still +consumes `SimpleProcess.integral` directly, at a genuine time `t : ℝ≥0`. +Restoring the consumption relation — `itoSimple = integral … t` for any `t` +dominating `V`'s finite support — is a follow-up recorded in +`docs/archive/upstream-consumption-review-2026-07-27.md`. -/ +noncomputable def itoSimple (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : Ω → ℝ := + fun ω ↦ V.value.sum fun p v ↦ v ω * (B p.2 ω - B p.1 ω) + +/-- The terminal Itô integral as the explicit increment sum +`(V ● B)_⊤ ω = ∑ₚ V(p) ω · (B_{p.2} ω − B_{p.1} ω)`. -/ +lemma itoSimple_apply (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) (ω : Ω) : + itoSimple hBmeas V ω + = V.value.sum fun p v ↦ v ω * (B p.2 ω - B p.1 ω) := + rfl + +variable [IsProbabilityMeasure μ] + +/-- **Step 1 — `L²` membership.** The terminal Itô integral of a simple process is in +`L²(μ)`: it is the finite sum `∑ₚ V(p)·(B_{p.2}−B_{p.1})`, and each summand is in `L²` +by `memLp_adapted_mul_increment` — the coefficient `V(p)` is `𝓕_{p.1}`-measurable (the +filtration the core is stated against) and bounded (hence `L²` on the probability space). -/ +theorem memLp_itoSimple (hB : IsPreBrownianReal B μ) (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + MemLp (itoSimple hBmeas V) 2 μ := by + rw [show itoSimple hBmeas V + = fun ω ↦ ∑ p ∈ V.value.support, V.value p ω * (B p.2 ω - B p.1 ω) + from funext fun ω ↦ by rw [itoSimple_apply]; rfl] + refine memLp_finsetSum V.value.support (fun p hp ↦ ?_) + refine ItoIsometryAdapted.memLp_adapted_mul_increment (hB.isFilteredPreBrownian hBmeas) + (V.le_of_mem_support_value p hp) (V.measurable_value p) ?_ + exact MemLp.of_bound + ((V.measurable_value p).mono ((natFiltration hBmeas).le p.1) le_rfl).aestronglyMeasurable + V.valueBound (ae_of_all _ (V.value_le_valueBound p)) + +/-- The terminal Itô integral of a simple process as an element of `Lp ℝ 2 μ`. -/ +noncomputable def itoSimpleLp (hB : IsPreBrownianReal B μ) (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : Lp ℝ 2 μ := + (memLp_itoSimple hB hBmeas V).toLp _ + +/-- **Step 2 — the Itô isometry on simple processes** (the predictable-rectangle double +sum). For a simple process `V`, + + `∫ (itoSimple V)² dμ = Σ_{p,q} E[V(p)·V(q)] · vol((p.1,p.2] ∩ (q.1,q.2])`, + +where `vol((p.1,p.2] ∩ (q.1,q.2]) = max 0 (min p.2 q.2 − max p.1 q.1)`. The square of the +increment sum expands into a double sum whose every term collapses by +`rect_increment_pairing` — the genuinely-stochastic content (cross terms vanish by the +weak Markov property, diagonal terms give the deterministic overlap). The right-hand side +is exactly `‖V‖²` in the predictable `L²` space, so this is the Itô isometry. -/ +theorem itoSimple_sq_integral (hB : IsPreBrownianReal B μ) (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + ∫ ω, (itoSimple hBmeas V ω) ^ 2 ∂μ + = ∑ p ∈ V.value.support, ∑ q ∈ V.value.support, + (∫ ω, V.value p ω * V.value q ω ∂μ) + * max 0 ((min (p.2 : ℝ) q.2) - (max (p.1 : ℝ) q.1)) := by + set a : (ℝ≥0 × ℝ≥0) → Ω → ℝ := fun p ω ↦ V.value p ω * (B p.2 ω - B p.1 ω) + have ha_L2 : ∀ p ∈ V.value.support, MemLp (a p) 2 μ := fun p hp ↦ + ItoIsometryAdapted.memLp_adapted_mul_increment (hB.isFilteredPreBrownian hBmeas) + (V.le_of_mem_support_value p hp) (V.measurable_value p) + (MemLp.of_bound + ((V.measurable_value p).mono ((natFiltration hBmeas).le p.1) le_rfl).aestronglyMeasurable + V.valueBound (ae_of_all _ (V.value_le_valueBound p))) + have hint : ∀ p ∈ V.value.support, ∀ q ∈ V.value.support, + Integrable (fun ω ↦ a p ω * a q ω) μ := + fun p hp q hq ↦ (ha_L2 p hp).integrable_mul (ha_L2 q hq) + calc ∫ ω, (itoSimple hBmeas V ω) ^ 2 ∂μ + = ∫ ω, ∑ p ∈ V.value.support, ∑ q ∈ V.value.support, a p ω * a q ω ∂μ := by + refine integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ ?_) + change itoSimple hBmeas V ω ^ 2 + = ∑ p ∈ V.value.support, ∑ q ∈ V.value.support, a p ω * a q ω + rw [show itoSimple hBmeas V ω = ∑ p ∈ V.value.support, a p ω from by + rw [itoSimple_apply]; rfl, sq, Finset.sum_mul_sum] + _ = ∑ p ∈ V.value.support, ∑ q ∈ V.value.support, ∫ ω, a p ω * a q ω ∂μ := by + rw [integral_finsetSum _ (fun p hp ↦ integrable_finsetSum _ fun q hq ↦ hint p hp q hq)] + exact Finset.sum_congr rfl fun p hp ↦ + integral_finsetSum _ (fun q hq ↦ hint p hp q hq) + _ = ∑ p ∈ V.value.support, ∑ q ∈ V.value.support, + (∫ ω, V.value p ω * V.value q ω ∂μ) + * max 0 ((min (p.2 : ℝ) q.2) - (max (p.1 : ℝ) q.1)) := by + refine Finset.sum_congr rfl fun p hp ↦ Finset.sum_congr rfl fun q hq ↦ ?_ + exact ItoIsometryAdapted.rect_increment_pairing (hB.isFilteredPreBrownian hBmeas) + (V.measurable_value p) (V.measurable_value q) + (fun ω ↦ by rw [← Real.norm_eq_abs]; exact V.value_le_valueBound p ω) + (fun ω ↦ by rw [← Real.norm_eq_abs]; exact V.value_le_valueBound q ω) + (V.le_of_mem_support_value p hp) (V.le_of_mem_support_value q hq) + +/-- **The Itô isometry in `Lp`-norm form.** `‖itoSimpleLp V‖²` equals the predictable- +rectangle double sum — i.e. `‖V‖²` in the predictable `L²` space. This is the norm +identity that `extendOfNorm` consumes to build the continuous Itô integral. -/ +theorem itoSimpleLp_norm_sq (hB : IsPreBrownianReal B μ) (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + ‖(itoSimpleLp hB hBmeas V : Lp ℝ 2 μ)‖ ^ 2 + = ∑ p ∈ V.value.support, ∑ q ∈ V.value.support, + (∫ ω, V.value p ω * V.value q ω ∂μ) + * max 0 ((min (p.2 : ℝ) q.2) - (max (p.1 : ℝ) q.1)) := by + rw [lp_two_norm_sq, ← itoSimple_sq_integral hB hBmeas V] + refine integral_congr_ae ?_ + filter_upwards [(memLp_itoSimple hB hBmeas V).coeFn_toLp] with ω hω + rw [show (itoSimpleLp hB hBmeas V : Ω → ℝ) ω = itoSimple hBmeas V ω from hω] + +/-! ### The time measure `ν` — Lebesgue on `ℝ≥0` + +The CLM domain is `L2Predictable ν μ = Lp ℝ 2 ((ν.prod μ).trim 𝓕.predictable_le_prod)` +(Degenne's `L2M`). The interval overlap appearing in the isometry **is** Lebesgue length +(it comes from `E[(Bₜ−Bₛ)²] = t−s`), so `ν` must be Lebesgue measure on the time axis `ℝ≥0`. +Since `ℝ≥0` carries no canonical `volume`, we take the comap of `volume` along the (closed, +hence measurable) embedding `ℝ≥0 ↪ ℝ`. -/ + +/-- The coercion `ℝ≥0 → ℝ` as a measurable embedding (it is a closed embedding). -/ +lemma measurableEmbedding_nnrealCoe : MeasurableEmbedding ((↑) : ℝ≥0 → ℝ) := + NNReal.isClosedEmbedding_coe.measurableEmbedding + +/-- Lebesgue measure on the time axis `ℝ≥0` — the comap of `volume` along `ℝ≥0 ↪ ℝ`. -/ +noncomputable def timeMeasure : Measure ℝ≥0 := Measure.comap ((↑) : ℝ≥0 → ℝ) volume + +/-- `timeMeasure` of a time interval `(a, b]` is its length `b - a`. -/ +lemma timeMeasure_Ioc (a b : ℝ≥0) : + timeMeasure (Set.Ioc a b) = ENNReal.ofReal ((b : ℝ) - a) := by + have himg : ((↑) : ℝ≥0 → ℝ) '' Set.Ioc a b = Set.Ioc (a : ℝ) b := by + ext x + simp only [Set.mem_image, Set.mem_Ioc] + constructor + · rintro ⟨y, ⟨hay, hyb⟩, rfl⟩ + exact ⟨by exact_mod_cast hay, by exact_mod_cast hyb⟩ + · rintro ⟨hax, hxb⟩ + have hx0 : 0 ≤ x := le_of_lt (lt_of_le_of_lt a.coe_nonneg hax) + exact ⟨⟨x, hx0⟩, ⟨by exact_mod_cast hax, by exact_mod_cast hxb⟩, rfl⟩ + rw [timeMeasure, measurableEmbedding_nnrealCoe.comap_apply, himg, Real.volume_Ioc] + +/-- The `vol((p.1,p.2] ∩ (q.1,q.2])` factor of the Itô-isometry double sum, as a +`timeMeasure` of the intersection of two time intervals. -/ +lemma timeMeasure_Ioc_inter (a b c d : ℝ≥0) : + timeMeasure (Set.Ioc a b ∩ Set.Ioc c d) + = ENNReal.ofReal (min (b : ℝ) d - max (a : ℝ) c) := by + rw [Set.Ioc_inter_Ioc, timeMeasure_Ioc, NNReal.coe_min, NNReal.coe_max] + +/-- `timeMeasure` is finite on compacts (comap of `volume`, which is, along the +continuous measurable embedding `ℝ≥0 ↪ ℝ`). -/ +instance : IsFiniteMeasureOnCompacts timeMeasure := + IsFiniteMeasureOnCompacts.comap' volume NNReal.continuous_coe measurableEmbedding_nnrealCoe + +/-- `timeMeasure` is σ-finite (Lebesgue on the locally compact, σ-compact `ℝ≥0`). -/ +instance : SigmaFinite timeMeasure := inferInstance + +/-- `timeMeasure` of a single time point is `0` (Lebesgue is non-atomic). -/ +lemma timeMeasure_singleton (a : ℝ≥0) : timeMeasure {a} = 0 := by + rw [timeMeasure, measurableEmbedding_nnrealCoe.comap_apply, Set.image_singleton, + Real.volume_singleton] + +/-! ### Embedding simple processes into the predictable `L²` + +The uncurried simple process `uncurry V : ℝ≥0 × Ω → ℝ` is, up to a `timeMeasure.prod μ`-null +set (the time-fibre `{⊥}`), the finite sum over `V.value.support` of **rectangle terms** +`𝟙_{(p.1,p.2]}(t) · V(p)(ω)`. Each rectangle term is `L²` in the product (its time-support is +a finite-measure interval and `V` is bounded), so `uncurry V ∈ L²(timeMeasure.prod μ)`; being +predictable-strongly-measurable, it descends to `L2Predictable timeMeasure μ`. -/ + +/-- **The elementary integrand** `Z·1_{(a,b]}`: a bounded weight on `Ω` switched on over a +time band. It is the atom of every simple process (`rectTerm` below is this at the band `p` +with weight `V.value p`) and, in the tower above, the integrand on which a stochastic integral +is pinned to its Riemann–Stieltjes value. It depends on neither the driver nor the +filtration. -/ +noncomputable def elemIntegrand (a b : ℝ≥0) (Z : Ω → ℝ) : ℝ≥0 × Ω → ℝ := + fun z ↦ (Set.Ioc a b).indicator (fun _ ↦ (1 : ℝ)) z.1 * Z z.2 + +/-- The contribution of one interval `p` to the uncurried simple process, in product +form `𝟙_{(p.1,p.2]}(t) · V(p)(ω)` — the elementary integrand at the band `p`. -/ +noncomputable def rectTerm (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) (p : ℝ≥0 × ℝ≥0) : + ℝ≥0 × Ω → ℝ := + elemIntegrand p.1 p.2 (V.value p) + +/-- The rectangle term as an indicator of the product rectangle `(p.1,p.2] ×ˢ univ`. -/ +lemma rectTerm_eq_indicator (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) (p : ℝ≥0 × ℝ≥0) : + rectTerm hBmeas V p + = (Set.Ioc p.1 p.2 ×ˢ (Set.univ : Set Ω)).indicator (fun z ↦ V.value p z.2) := by + funext z + rw [rectTerm, elemIntegrand, Set.indicator_apply, Set.indicator_apply] + simp only [Set.mem_prod, Set.mem_univ, and_true] + split_ifs <;> simp + +/-- **Each rectangle term is `L²`** in the product measure: its time-support is the +finite-measure interval `(p.1,p.2]` and `V(p)` is bounded. -/ +lemma memLp_rectTerm (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) (p : ℝ≥0 × ℝ≥0) : + MemLp (rectTerm hBmeas V p) 2 (timeMeasure.prod μ) := by + have : IsFiniteMeasure (timeMeasure.restrict (Set.Ioc p.1 p.2)) := + ⟨by rw [Measure.restrict_apply MeasurableSet.univ, Set.univ_inter, timeMeasure_Ioc]; + exact ENNReal.ofReal_lt_top⟩ + rw [rectTerm_eq_indicator, + memLp_indicator_iff_restrict (measurableSet_Ioc.prod MeasurableSet.univ).nullMeasurableSet, + ← Measure.prod_restrict, Measure.restrict_univ] + have hmeas : Measurable (fun z : ℝ≥0 × Ω ↦ V.value p z.2) := + ((V.measurable_value p).mono ((natFiltration hBmeas).le p.1) le_rfl).comp measurable_snd + exact MemLp.of_bound hmeas.aestronglyMeasurable V.valueBound + (ae_of_all _ fun z ↦ by rw [Real.norm_eq_abs]; exact V.value_le_valueBound p z.2) + +/-- **The uncurried simple process is a.e. the finite sum of its rectangle terms** — for +*any* measure that charges the time origin nothing. + +The origin is the whole content: `SimpleProcess.apply_eq` writes `V` as its value at `⊥` plus +the band sum, and the first term is what has to go. Nothing else about the measure is used, and +in particular nothing about the σ-algebra it lives on, so the same statement serves the flat +product measure here and the bracket-weighted predictable measure the integral against an Itô +integral is built on. -/ +lemma uncurry_ae_eq_sum_rectTerm_of_ae_fst_ne_zero {m : MeasurableSpace (ℝ≥0 × Ω)} + {ν : @Measure (ℝ≥0 × Ω) m} (hν : ∀ᵐ z ∂ν, z.1 ≠ 0) (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + Function.uncurry ⇑V =ᵐ[ν] fun z ↦ ∑ p ∈ V.value.support, rectTerm hBmeas V p z := by + filter_upwards [hν] with z hz + change ⇑V z.1 z.2 = _ + rw [SimpleProcess.apply_eq, Set.indicator_of_notMem (by simpa using hz), zero_add, Finsupp.sum] + refine Finset.sum_congr rfl fun p _ ↦ ?_ + rw [rectTerm, elemIntegrand, Set.indicator_apply, Set.indicator_apply] + split_ifs <;> simp + +/-- The time origin is `timeMeasure.prod μ`-null, the time fibre `{⊥}` being Lebesgue-null. -/ +lemma ae_fst_ne_zero_prod (μ : Measure Ω) [SFinite μ] : + ∀ᵐ z : ℝ≥0 × Ω ∂(timeMeasure.prod μ), z.1 ≠ 0 := by + rw [Filter.eventually_iff, mem_ae_iff, + show {z : ℝ≥0 × Ω | z.1 ≠ 0}ᶜ = {(0 : ℝ≥0)} ×ˢ (Set.univ : Set Ω) from by ext z; simp, + Measure.prod_prod, timeMeasure_singleton, zero_mul] + +/-- **The uncurried simple process is a.e. the finite sum of its rectangle terms.** +They agree off the time-fibre `{⊥}`, which is `timeMeasure.prod μ`-null. -/ +lemma uncurry_ae_eq_sum_rectTerm (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + Function.uncurry ⇑V + =ᵐ[timeMeasure.prod μ] fun z ↦ ∑ p ∈ V.value.support, rectTerm hBmeas V p z := + uncurry_ae_eq_sum_rectTerm_of_ae_fst_ne_zero (ae_fst_ne_zero_prod μ) hBmeas V + +/-- **The uncurried simple process is `L²`** in the product measure (finite sum of +`L²` rectangle terms). -/ +lemma memLp_uncurry_prod (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + MemLp (Function.uncurry ⇑V) 2 (timeMeasure.prod μ) := + (memLp_congr_ae (uncurry_ae_eq_sum_rectTerm hBmeas V)).mpr + (memLp_finsetSum _ fun p _ ↦ memLp_rectTerm hBmeas V p) + +/-- The uncurried simple process is `L²` in the **trimmed** (predictable) product +measure: it is predictable-strongly-measurable (`SimpleProcess.isStronglyPredictable`) +with the same finite `L²` norm as in the untrimmed product (`eLpNorm_trim`). -/ +lemma memLp_uncurry_trim (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + MemLp (Function.uncurry ⇑V) 2 + ((timeMeasure.prod μ).trim (natFiltration hBmeas).predictable_le_prod) := + by rw [memLp_iff, eLpNorm_trim _ V.isStronglyPredictable]; exact memLp_uncurry_prod hBmeas V + +/-- **The embedding** of a simple process into the predictable `L²` space, as the class of +its uncurried version. The codomain `Lp ℝ 2 ((timeMeasure.prod μ).trim …)` is *definitionally* +Degenne's `L2Predictable timeMeasure μ`; we keep it unfolded here so the `Lp` norm instance is +available (the opaque `L2Predictable` def has none), and re-wrap as `L2Predictable` only at the +final continuous integral. The Itô isometry identifies its norm with that of `itoSimpleLp`. -/ +noncomputable def simpleProcessL2 (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + Lp ℝ 2 ((timeMeasure.prod μ).trim (natFiltration hBmeas).predictable_le_prod) := + (memLp_uncurry_trim hBmeas V).toLp (Function.uncurry ⇑V) + +/-- **Cross-integral of two rectangle terms.** Fubini (`integral_prod_mul`) factorises it +into the time-overlap `vol((p]∩(q]) = max 0 (min p.2 q.2 − max p.1 q.1)` and the sample +correlation `E[V(p)·V(q)]`. -/ +lemma integral_rectTerm_mul (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) (p q : ℝ≥0 × ℝ≥0) : + ∫ z, rectTerm hBmeas V p z * rectTerm hBmeas V q z ∂(timeMeasure.prod μ) + = (∫ ω, V.value p ω * V.value q ω ∂μ) + * max 0 ((min (p.2 : ℝ) q.2) - (max (p.1 : ℝ) q.1)) := by + have hfun : (fun z : ℝ≥0 × Ω ↦ rectTerm hBmeas V p z * rectTerm hBmeas V q z) + = fun z ↦ ((Set.Ioc p.1 p.2).indicator (fun _ ↦ (1 : ℝ)) z.1 + * (Set.Ioc q.1 q.2).indicator (fun _ ↦ (1 : ℝ)) z.1) + * (V.value p z.2 * V.value q z.2) := by + funext z; simp only [rectTerm, elemIntegrand]; ring + rw [hfun, integral_prod_mul + (fun i ↦ (Set.Ioc p.1 p.2).indicator (fun _ ↦ (1 : ℝ)) i + * (Set.Ioc q.1 q.2).indicator (fun _ ↦ (1 : ℝ)) i) + (fun ω ↦ V.value p ω * V.value q ω), mul_comm] + congr 1 + have hpt : ∀ i : ℝ≥0, (Set.Ioc p.1 p.2).indicator (fun _ ↦ (1 : ℝ)) i + * (Set.Ioc q.1 q.2).indicator (fun _ ↦ (1 : ℝ)) i + = (Set.Ioc p.1 p.2 ∩ Set.Ioc q.1 q.2).indicator (1 : ℝ≥0 → ℝ) i := by + intro i; rw [Set.inter_indicator_one]; rfl + simp_rw [hpt] + rw [integral_indicator_one (measurableSet_Ioc.inter measurableSet_Ioc), + Measure.real_def, timeMeasure_Ioc_inter, ENNReal.toReal_ofReal', max_comm] + +/-- **The embedding is an `L²` isometry onto the Itô-isometry double sum.** Its squared norm +in `L2Predictable` equals the same predictable-rectangle double sum as the elementary Itô +integral `itoSimpleLp` (the squared increment-sum expands and Fubini-factorises termwise). +This norm identity is what makes the continuous extension an isometry. -/ +theorem simpleProcessL2_norm_sq (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + ‖simpleProcessL2 (μ := μ) hBmeas V‖ ^ 2 + = ∑ p ∈ V.value.support, ∑ q ∈ V.value.support, + (∫ ω, V.value p ω * V.value q ω ∂μ) + * max 0 ((min (p.2 : ℝ) q.2) - (max (p.1 : ℝ) q.1)) := by + -- Step A: ‖simpleProcessL2 V‖² = ∫ (uncurry V)² in the product measure (via `eLpNorm_trim`). + have hStepA : ‖simpleProcessL2 (μ := μ) hBmeas V‖ ^ 2 + = ∫ z, (Function.uncurry ⇑V z) ^ 2 ∂(timeMeasure.prod μ) := by + rw [lp_two_norm_sq (simpleProcessL2 (μ := μ) hBmeas V)] + have hco : (fun z ↦ (simpleProcessL2 (μ := μ) hBmeas V z) ^ 2) + =ᵐ[(timeMeasure.prod μ).trim (natFiltration hBmeas).predictable_le_prod] + fun z ↦ (Function.uncurry ⇑V z) ^ 2 := by + filter_upwards [(memLp_uncurry_trim hBmeas V).coeFn_toLp] with z hz + rw [show (simpleProcessL2 (μ := μ) hBmeas V) z = Function.uncurry ⇑V z from hz] + rw [integral_congr_ae hco] + simp only [pow_two] + have hsm2 : StronglyMeasurable[(natFiltration hBmeas).predictable] + (fun z ↦ Function.uncurry ⇑V z * Function.uncurry ⇑V z) := + V.isStronglyPredictable.mul V.isStronglyPredictable + exact (integral_trim (natFiltration hBmeas).predictable_le_prod hsm2).symm + rw [hStepA] + -- Step B: expand the square into the rectangle double sum and integrate termwise. + have hint : ∀ p ∈ V.value.support, ∀ q ∈ V.value.support, + Integrable (fun z ↦ rectTerm hBmeas V p z * rectTerm hBmeas V q z) (timeMeasure.prod μ) := + fun p _ q _ ↦ (memLp_rectTerm hBmeas V p).integrable_mul (memLp_rectTerm hBmeas V q) + have hsq : ∀ᵐ z ∂(timeMeasure.prod μ), (Function.uncurry ⇑V z) ^ 2 + = ∑ p ∈ V.value.support, ∑ q ∈ V.value.support, + rectTerm hBmeas V p z * rectTerm hBmeas V q z := by + filter_upwards [uncurry_ae_eq_sum_rectTerm hBmeas V] with z hz + rw [hz, sq, Finset.sum_mul_sum] + rw [integral_congr_ae hsq, + integral_finsetSum _ (fun p hp ↦ integrable_finsetSum _ fun q hq ↦ hint p hp q hq)] + refine Finset.sum_congr rfl fun p hp ↦ ?_ + rw [integral_finsetSum _ fun q hq ↦ hint p hp q hq] + exact Finset.sum_congr rfl fun q _ ↦ integral_rectTerm_mul hBmeas V p q + +/-! ### Linear assembly maps and the isometry on simple processes -/ + +/-- The elementary Itô integral is additive in the simple process. -/ +lemma itoSimple_add (hBmeas : ∀ t, Measurable (B t)) + (V W : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + itoSimple hBmeas (V + W) = itoSimple hBmeas V + itoSimple hBmeas W := by + funext ω + simp only [itoSimple, Pi.add_apply, show (V + W).value = V.value + W.value from rfl] + exact Finsupp.sum_add_index' (fun p ↦ by simp) (fun p v w ↦ by simp [add_mul]) + +/-- The elementary Itô integral is homogeneous in the simple process. -/ +lemma itoSimple_smul (hBmeas : ∀ t, Measurable (B t)) (c : ℝ) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + itoSimple hBmeas (c • V) = c • itoSimple hBmeas V := by + funext ω + simp only [itoSimple, Pi.smul_apply, smul_eq_mul, + show (c • V).value = c • V.value from rfl] + rw [Finsupp.sum_smul_index' (fun p ↦ by simp), Finsupp.mul_sum] + exact Finsupp.sum_congr fun p _ ↦ by simp [mul_assoc] + +/-- **The elementary Itô integral as a linear map** `SimpleProcess →ₗ[ℝ] Lp ℝ 2 μ`. -/ +noncomputable def itoAssembly (hB : IsPreBrownianReal B μ) (hBmeas : ∀ t, Measurable (B t)) : + SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas) →ₗ[ℝ] Lp ℝ 2 μ where + toFun V := itoSimpleLp hB hBmeas V + map_add' V W := by + rw [itoSimpleLp, itoSimpleLp, itoSimpleLp, + ← MemLp.toLp_add (memLp_itoSimple hB hBmeas V) (memLp_itoSimple hB hBmeas W)] + congr 1 + exact itoSimple_add hBmeas V W + map_smul' c V := by + rw [itoSimpleLp, itoSimpleLp, RingHom.id_apply, + ← MemLp.toLp_const_smul c (memLp_itoSimple hB hBmeas V)] + congr 1 + exact itoSimple_smul hBmeas c V + +/-- The uncurried simple process is additive. -/ +lemma uncurry_coe_add (hBmeas : ∀ t, Measurable (B t)) + (V W : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + Function.uncurry ⇑(V + W) = Function.uncurry ⇑V + Function.uncurry ⇑W := by + rw [SimpleProcess.coe_add]; rfl + +/-- The uncurried simple process is homogeneous. -/ +lemma uncurry_coe_smul (hBmeas : ∀ t, Measurable (B t)) (c : ℝ) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + Function.uncurry ⇑(c • V) = c • Function.uncurry ⇑V := by + rw [SimpleProcess.coe_smul]; rfl + +/-- **The embedding into the predictable `L²` as a linear map** +`SimpleProcess →ₗ[ℝ] Lp ℝ 2 ((timeMeasure.prod μ).trim …)`. -/ +noncomputable def simpleAssembly (hBmeas : ∀ t, Measurable (B t)) : + SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas) + →ₗ[ℝ] Lp ℝ 2 ((timeMeasure.prod μ).trim (natFiltration hBmeas).predictable_le_prod) where + toFun V := simpleProcessL2 (μ := μ) hBmeas V + map_add' V W := by + rw [simpleProcessL2, simpleProcessL2, simpleProcessL2, + ← MemLp.toLp_add (memLp_uncurry_trim hBmeas V) (memLp_uncurry_trim hBmeas W)] + congr 1 + exact uncurry_coe_add hBmeas V W + map_smul' c V := by + rw [simpleProcessL2, simpleProcessL2, RingHom.id_apply, + ← MemLp.toLp_const_smul c (memLp_uncurry_trim hBmeas V)] + congr 1 + exact uncurry_coe_smul hBmeas c V + +/-- **The Itô isometry on simple processes.** `‖itoAssembly V‖ = ‖simpleAssembly V‖`: both +squared norms equal the predictable-rectangle double sum (`itoSimpleLp_norm_sq`, +`simpleProcessL2_norm_sq`). This is the bound `extendOfNorm` consumes. -/ +theorem assembly_isometry (hB : IsPreBrownianReal B μ) (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + ‖itoAssembly (μ := μ) hB hBmeas V‖ = ‖simpleAssembly (μ := μ) hBmeas V‖ := by + have hsq : ‖itoAssembly (μ := μ) hB hBmeas V‖ ^ 2 = ‖simpleAssembly (μ := μ) hBmeas V‖ ^ 2 := by + change ‖(itoSimpleLp hB hBmeas V : Lp ℝ 2 μ)‖ ^ 2 = ‖simpleProcessL2 (μ := μ) hBmeas V‖ ^ 2 + rw [itoSimpleLp_norm_sq hB hBmeas V, simpleProcessL2_norm_sq hBmeas V] + exact (sq_eq_sq₀ (norm_nonneg _) (norm_nonneg _)).mp hsq + +end ItoIntegralL2 +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralL2Dense.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralL2Dense.lean new file mode 100644 index 0000000000..ab10cb26ba --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralL2Dense.lean @@ -0,0 +1,358 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralHorizonDense + +/-! +# Infinite-horizon Itô integral on `[0,∞)` as a continuous linear isometry + +This file builds the unbounded-horizon Itô integral (the horizon-`T` one, +`ItoIntegralCLM.itoIntegralCLM`, is its restriction to the band `(0,T]`), reusing the finite-horizon +density machinery of `ItoIntegralHorizonDense` via σ-finite exhaustion, delivering the Itô integral +on all of `[0,∞)` as a continuous linear map + +`itoIntegralL2 : Lp ℝ 2 trim_full →L[ℝ] Lp ℝ 2 μ` + +where `trim_full = (timeMeasure.prod μ).trim 𝓕.predictable_le_prod` is Degenne's +`L2Predictable timeMeasure μ` (kept unfolded for the `Lp` norm instance, as in +`ItoIntegralL2.lean`). This is the σ-finite completion: `timeMeasure` (Lebesgue +on `ℝ≥0`) is infinite, only σ-finite, so the orthogonal-complement density +argument cannot use the finite-measure complement shortcut. + +## The mathematical content + +The embedding and the Itô isometry on simple processes are already built +(`ItoIntegralL2.simpleAssembly` / `assembly_isometry`). The one remaining step is +**density** of the simple-process embedding in the predictable `L²`. We obtain it +from the *finite-horizon* density machinery (`ItoIntegralHorizonDense`) by a σ-finite +exhaustion of the time axis: + +* the basic predictable rectangles `Ioc a b ×ˢ F` / `{0} ×ˢ F₀` are a π-system + generating the predictable σ-algebra (`ItoIntegralCLM.predictableRect`, + T-independent — reused verbatim); +* a function `g ∈ L²(trim_full)` orthogonal to every rectangle indicator has + vanishing set-integral over every rectangle (`itoOrthRect`); +* on each finite frame `Fₙ = Ioc 0 (n+1) ×ˢ univ` the trimmed measure restricts + to the *finite* `ItoIntegralCLM.trimMeasure (n+1)` + (`ItoIntegralCLM.trimMeasure_eq_restrict`), so the finite-horizon + π-λ-induction lemma `ItoIntegralCLM.setIntegral_eq_zero_of_orthogonal_pred` + applies and forces `g =ᵐ 0` on `Fₙ`; +* the frames cover all of `Ioi 0 ×ˢ univ`, whose complement `{0} ×ˢ univ` is + `trim_full`-null (`timeMeasure {0} = 0`), so `g =ᵐ[trim_full] 0`. + +`LinearMap.extendOfNorm` then yields the CLM and the isometry +`‖itoIntegralL2 f‖ = ‖f‖`. + +## Coherence + +Pure consumption of the finite-horizon layer + Degenne's `SimpleProcess` +infrastructure; nothing of the π-system or the isometry is reproved. This closes +the unbounded-horizon gap recorded in `docs/archive/ito-integral-clm-deferred.md`. + +## Main definitions + +* `itoIntegralL2`: the unbounded-horizon Itô integral `Lp ℝ 2 trim_full →L[ℝ] Lp ℝ 2 μ`, the + extension of `itoAssembly` along the dense `simpleAssembly`. + +## Main results + +* `simpleAssembly_denseRange`: the image of `simpleAssembly` is dense in the predictable `L²`. +* `itoIntegralL2_norm`: the unbounded-horizon Itô isometry, `‖itoIntegralL2 f‖ = ‖f‖` for every + `f ∈ Lp 2 trim_full`. +* `itoIntegralL2_simpleAssembly`: on a simple process the `[0,∞)` integral is the explicit + increment sum `itoSimpleLp V`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Ch 7 + +## Tags + +Itô integral, infinite horizon, stochastic integral, Itô isometry, σ-finite exhaustion, +predictable integrands, MSC 60H05, MSC 60G07 +-/ + +@[expose] public section + +open MeasureTheory Filter Topology NNReal ENNReal ProbabilityTheory +open scoped MeasureTheory NNReal ENNReal InnerProductSpace + +namespace MathFin +namespace ItoIntegralL2 + +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {μ : Measure Ω} + {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) [IsProbabilityMeasure μ] + +include hB + +/-! ### The rectangle indicator as a simple process -/ + +omit hB [IsProbabilityMeasure μ] in +/-- The simple process realising the indicator of `Ioc a b ×ˢ F` (`F ∈ ℱₐ`), via +upstream `ElementaryPredictableSet.IocProd.indicator`. Unlike `iocSPHorizon` there is +no horizon bound: this is a plain `SimpleProcess`, not a member of the +`T`-bounded submodule. -/ +private noncomputable def iocSP (hBmeas : ∀ t, Measurable (B t)) (a b : ℝ≥0) {F : Set Ω} + (hF : MeasurableSet[(natFiltration (mΩ := mΩ) hBmeas) a] F) : + SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas) := + (ElementaryPredictableSet.IocProd a b hF).indicator (1 : ℝ) + +omit hB [IsProbabilityMeasure μ] in +/-- The uncurry of `iocSP hBmeas a b hF` is the indicator of `Ioc a b ×ˢ F`. -/ +private lemma uncurry_iocSP_eq (hBmeas : ∀ t, Measurable (B t)) (a b : ℝ≥0) {F : Set Ω} + (hF : MeasurableSet[(natFiltration (mΩ := mΩ) hBmeas) a] F) : + Function.uncurry ⇑(iocSP hBmeas a b hF) + = (Set.Ioc a b ×ˢ F).indicator (fun _ ↦ (1 : ℝ)) := by + funext ⟨t, ω⟩ + change ⇑((ElementaryPredictableSet.IocProd a b hF).indicator (1 : ℝ)) t ω + = (Set.Ioc a b ×ˢ F).indicator (fun _ ↦ (1 : ℝ)) (t, ω) + rw [ElementaryPredictableSet.coe_indicator, + ElementaryPredictableSet.coe_IocProd a b hF] + rfl + +omit hB in +/-- Inner product of `simpleAssembly (iocSP …)` with `g` is the set-integral of +`g` over the rectangle `Ioc a b ×ˢ F` in `trim_full`. -/ +private lemma inner_simpleAssembly_iocSP (hBmeas : ∀ t, Measurable (B t)) (a b : ℝ≥0) + {F : Set Ω} (hF : MeasurableSet[(natFiltration (mΩ := mΩ) hBmeas) a] F) + (g : Lp ℝ 2 ((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod)) : + ⟪simpleAssembly (μ := μ) hBmeas (iocSP hBmeas a b hF), g⟫_ℝ + = ∫ z in Set.Ioc a b ×ˢ F, g z ∂((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod) := by + let : MeasurableSpace (ℝ≥0 × Ω) := (natFiltration (mΩ := mΩ) hBmeas).predictable + rw [L2.inner_def] + have h_coe := MemLp.coeFn_toLp + (memLp_uncurry_trim (μ := μ) hBmeas (iocSP hBmeas a b hF)) + have h_uncurry_eq := uncurry_iocSP_eq hBmeas a b hF + have h_ae_eq : ∀ᵐ z ∂((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod), + (⟪(simpleAssembly (μ := μ) hBmeas (iocSP hBmeas a b hF) : ℝ≥0 × Ω → ℝ) z, + (g : ℝ≥0 × Ω → ℝ) z⟫_ℝ : ℝ) + = (Set.Ioc a b ×ˢ F).indicator (fun z ↦ (g : ℝ≥0 × Ω → ℝ) z) z := by + filter_upwards [h_coe] with z hz + have hSA_eq : + (simpleAssembly (μ := μ) hBmeas (iocSP hBmeas a b hF) : ℝ≥0 × Ω → ℝ) z + = (Set.Ioc a b ×ˢ F).indicator (fun _ ↦ (1 : ℝ)) z := by + calc (simpleAssembly (μ := μ) hBmeas (iocSP hBmeas a b hF) : ℝ≥0 × Ω → ℝ) z + = Function.uncurry ⇑(iocSP hBmeas a b hF) z := hz + _ = (Set.Ioc a b ×ˢ F).indicator (fun _ ↦ (1 : ℝ)) z := by rw [h_uncurry_eq] + rw [hSA_eq] + change (g : ℝ≥0 × Ω → ℝ) z * (Set.Ioc a b ×ˢ F).indicator (fun _ ↦ (1 : ℝ)) z + = (Set.Ioc a b ×ˢ F).indicator (fun z ↦ (g : ℝ≥0 × Ω → ℝ) z) z + by_cases hz_in : z ∈ Set.Ioc a b ×ˢ F + · rw [Set.indicator_of_mem hz_in, Set.indicator_of_mem hz_in, mul_one] + · rw [Set.indicator_of_notMem hz_in, Set.indicator_of_notMem hz_in, mul_zero] + rw [integral_congr_ae h_ae_eq] + exact integral_indicator + (MeasureTheory.measurableSet_predictable_Ioc_prod + (𝓕 := natFiltration (mΩ := mΩ) hBmeas) a b hF) + +/-! ### Orthogonality on rectangles -/ + +omit hB in +/-- A function `g` orthogonal to the range of `simpleAssembly` has vanishing +set-integral over every basic predictable rectangle. The `{0} ×ˢ F₀` piece is +`trim_full`-null (`timeMeasure {0} = 0`); the `Ioc a b ×ˢ F` piece is the inner +product `⟪simpleAssembly (iocSP …), g⟫`, which orthogonality kills. -/ +private lemma itoOrthRect (hBmeas : ∀ t, Measurable (B t)) + (g : Lp ℝ 2 ((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod)) + (h_orth : ∀ V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas), + ⟪simpleAssembly (μ := μ) hBmeas V, g⟫_ℝ = 0) : + ∀ R ∈ ItoIntegralCLM.predictableRect (mΩ := mΩ) hBmeas, + ∫ z in R, g z ∂((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod) = 0 := by + intro R hR + rcases hR with ⟨F₀, hF₀, rfl⟩ | ⟨a, b, F, _hab, hF, rfl⟩ + · -- `{0} ×ˢ F₀` is `trim_full`-null. + have hpred : MeasurableSet[(natFiltration (mΩ := mΩ) hBmeas).predictable] + ({(0 : ℝ≥0)} ×ˢ F₀) := + MeasureTheory.measurableSet_predictable_singleton_bot_prod + (𝓕 := natFiltration (mΩ := mΩ) hBmeas) hF₀ + have h_null : ((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod) + ({(0 : ℝ≥0)} ×ˢ F₀) = 0 := by + rw [trim_measurableSet_eq _ hpred, Measure.prod_prod, timeMeasure_singleton, + zero_mul] + exact setIntegral_measure_zero _ h_null + · -- `Ioc a b ×ˢ F` is the inner product, which orthogonality kills. + rw [← inner_simpleAssembly_iocSP (μ := μ) hBmeas a b hF g] + exact h_orth (iocSP hBmeas a b hF) + +/-! ### σ-finite exhaustion: orthogonal ⇒ a.e. zero -/ + +omit hB in +/-- A function `g` orthogonal to the range of `simpleAssembly` is a.e. zero. The +σ-finite exhaustion uses finite frames `Φ n = Ioc 0 (n+1) ×ˢ univ`: on each, the +trim measure restricts to the *finite* `ItoIntegralCLM.trimMeasure (n+1)` +(`trimMeasure_eq_restrict`), where the finite-horizon π-λ-induction lemma +`ItoIntegralCLM.setIntegral_eq_zero_of_orthogonal_pred` forces `g =ᵐ 0`. The +frames cover `Ioi 0 ×ˢ univ`, whose complement `{0} ×ˢ univ` is `trim_full`-null +(`timeMeasure {0} = 0`). -/ +private lemma aezeroOfOrth (hBmeas : ∀ t, Measurable (B t)) + (g : Lp ℝ 2 ((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod)) + (h_orth : ∀ V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas), + ⟪simpleAssembly (μ := μ) hBmeas V, g⟫_ℝ = 0) : + (g : ℝ≥0 × Ω → ℝ) =ᵐ[(timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod] 0 := by + let : MeasurableSpace (ℝ≥0 × Ω) := (natFiltration (mΩ := mΩ) hBmeas).predictable + have h_rect := itoOrthRect (μ := μ) hBmeas g h_orth + -- predictable-measurability of any rectangle in `predictableRect` + have hRpred : ∀ R ∈ ItoIntegralCLM.predictableRect (mΩ := mΩ) hBmeas, + MeasurableSet[(natFiltration (mΩ := mΩ) hBmeas).predictable] R := by + intro R hR + rw [← ItoIntegralCLM.generateFrom_predictableRect hBmeas] + exact MeasurableSpace.measurableSet_generateFrom hR + -- the finite frames + set Φ : ℕ → Set (ℝ≥0 × Ω) := fun n ↦ Set.Ioc 0 ((n : ℝ≥0) + 1) ×ˢ Set.univ with hΦ + have hΦ_mem : ∀ n, Φ n ∈ ItoIntegralCLM.predictableRect (mΩ := mΩ) hBmeas := fun n ↦ + Or.inr ⟨0, (n : ℝ≥0) + 1, by positivity, Set.univ, MeasurableSet.univ, rfl⟩ + have hΦ_meas : ∀ n, MeasurableSet[(natFiltration (mΩ := mΩ) hBmeas).predictable] (Φ n) := + fun n ↦ hRpred _ (hΦ_mem n) + -- per-frame a.e. zero + have h_frame : ∀ n : ℕ, (g : ℝ≥0 × Ω → ℝ) + =ᵐ[((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod).restrict (Φ n)] 0 := by + intro n + have h_bridge : ItoIntegralCLM.trimMeasure (μ := μ) ((n : ℝ≥0) + 1) hBmeas + = ((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod).restrict (Φ n) := + ItoIntegralCLM.trimMeasure_eq_restrict (μ := μ) ((n : ℝ≥0) + 1) hBmeas + rw [← h_bridge] + -- view `g` as a member of `Lp 2 (trimMeasure (n+1))` + have hmemn : MemLp (g : ℝ≥0 × Ω → ℝ) 2 + (ItoIntegralCLM.trimMeasure (μ := μ) ((n : ℝ≥0) + 1) hBmeas) := by + rw [h_bridge]; exact (Lp.memLp g).restrict (Φ n) + set gₙ := hmemn.toLp (g : ℝ≥0 × Ω → ℝ) + have hgn_coe : (gₙ : ℝ≥0 × Ω → ℝ) + =ᵐ[ItoIntegralCLM.trimMeasure (μ := μ) ((n : ℝ≥0) + 1) hBmeas] + (g : ℝ≥0 × Ω → ℝ) := hmemn.coeFn_toLp + -- orthogonality of `g` transfers to `trimMeasure (n+1)` + have h_transfer_g : ∀ R ∈ ItoIntegralCLM.predictableRect (mΩ := mΩ) hBmeas, + ∫ z in R, (g : ℝ≥0 × Ω → ℝ) z + ∂(ItoIntegralCLM.trimMeasure (μ := μ) ((n : ℝ≥0) + 1) hBmeas) = 0 := by + intro R hR + have h_eq : ∫ z in R, (g : ℝ≥0 × Ω → ℝ) z + ∂(ItoIntegralCLM.trimMeasure (μ := μ) ((n : ℝ≥0) + 1) hBmeas) + = ∫ z in R ∩ Φ n, (g : ℝ≥0 × Ω → ℝ) z ∂((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod) := by + rw [h_bridge] + rw [show ∫ z in R, (g : ℝ≥0 × Ω → ℝ) z ∂(((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod).restrict (Φ n)) + = ∫ z, (g : ℝ≥0 × Ω → ℝ) z ∂((((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod).restrict (Φ n)).restrict R) + from rfl, + Measure.restrict_restrict (hRpred R hR)] + rw [h_eq] + by_cases hne : (R ∩ Φ n).Nonempty + · exact h_rect _ (ItoIntegralCLM.isPiSystem_predictableRect hBmeas R hR (Φ n) (hΦ_mem n) hne) + · rw [Set.not_nonempty_iff_eq_empty.mp hne, setIntegral_empty] + -- transfer to `gₙ`, then apply the finite-horizon lemma + have h_transfer : ∀ R ∈ ItoIntegralCLM.predictableRect (mΩ := mΩ) hBmeas, + ∫ z in R, (gₙ : ℝ≥0 × Ω → ℝ) z + ∂(ItoIntegralCLM.trimMeasure (μ := μ) ((n : ℝ≥0) + 1) hBmeas) = 0 := by + intro R hR + rw [setIntegral_congr_ae (hRpred R hR) (hgn_coe.mono fun z hz _ ↦ hz)] + exact h_transfer_g R hR + have hgn0 : (gₙ : ℝ≥0 × Ω → ℝ) + =ᵐ[ItoIntegralCLM.trimMeasure (μ := μ) ((n : ℝ≥0) + 1) hBmeas] 0 := + Lp.ae_eq_zero_of_forall_setIntegral_eq_zero gₙ + (by norm_num : (2 : ℝ≥0∞) ≠ 0) (by norm_num : (2 : ℝ≥0∞) ≠ ∞) + (fun _ _ _ ↦ ((Lp.memLp gₙ).integrable one_le_two).integrableOn) + (fun s hs _ ↦ ItoIntegralCLM.setIntegral_eq_zero_of_orthogonal_pred + (μ := μ) ((n : ℝ≥0) + 1) hBmeas ((Lp.memLp gₙ).integrable one_le_two) + h_transfer s hs) + exact hgn_coe.symm.trans hgn0 + -- patch: a.e. zero on every frame + the cover's complement is null ⇒ a.e. zero + have key : ∀ᵐ z ∂((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod), + ∀ n : ℕ, z ∈ Φ n → (g : ℝ≥0 × Ω → ℝ) z = (0 : ℝ≥0 × Ω → ℝ) z := by + rw [ae_all_iff] + intro n + exact (ae_restrict_iff' (hΦ_meas n)).mp (h_frame n) + have hcov : ∀ᵐ z ∂((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod), z ∈ ⋃ n, Φ n := by + rw [ae_iff] + have hsub : {z : ℝ≥0 × Ω | z ∉ ⋃ n, Φ n} ⊆ {(0 : ℝ≥0)} ×ˢ Set.univ := by + intro z hz + simp only [Set.mem_ofPred_eq, Set.mem_iUnion, hΦ, Set.mem_prod, Set.mem_Ioc, + Set.mem_univ, and_true, not_exists, not_and, not_le] at hz + obtain ⟨t, ω⟩ := z + simp only [Set.mem_prod, Set.mem_singleton_iff, Set.mem_univ, and_true] + by_contra ht + have htpos : 0 < t := by + rcases eq_or_lt_of_le (bot_le : (0 : ℝ≥0) ≤ t) with h | h + · exact absurd h.symm ht + · exact h + obtain ⟨m, hm⟩ := exists_nat_ge (t : ℝ≥0) + exact absurd (le_trans hm (le_add_of_nonneg_right zero_le_one)) (not_le.mpr (hz m htpos)) + have hnull : ((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod) + ({(0 : ℝ≥0)} ×ˢ (Set.univ : Set Ω)) = 0 := by + have hpred : MeasurableSet[(natFiltration (mΩ := mΩ) hBmeas).predictable] + ({(0 : ℝ≥0)} ×ˢ (Set.univ : Set Ω)) := + MeasureTheory.measurableSet_predictable_singleton_bot_prod + (𝓕 := natFiltration (mΩ := mΩ) hBmeas) MeasurableSet.univ + rw [trim_measurableSet_eq _ hpred, Measure.prod_prod, timeMeasure_singleton, zero_mul] + exact measure_mono_null hsub hnull + filter_upwards [key, hcov] with z hz hz_cov + obtain ⟨n, hn⟩ := Set.mem_iUnion.mp hz_cov + exact hz n hn + +/-! ### Density, the CLM, and the unbounded-horizon isometry -/ + +omit hB in +/-- **Density**: the image of `simpleAssembly` is dense in the predictable `L²`. +Orthogonal-complement argument: a `g` orthogonal to the range is a.e. zero +(`aezeroOfOrth`). -/ +theorem simpleAssembly_denseRange (hBmeas : ∀ t, Measurable (B t)) : + DenseRange (simpleAssembly (μ := μ) hBmeas) := by + suffices h_orth_bot : + (LinearMap.range (simpleAssembly (μ := μ) hBmeas))ᗮ = ⊥ by + rw [denseRange_iff_closure_range, + ← LinearMap.coe_range (simpleAssembly (μ := μ) hBmeas), + ← Submodule.topologicalClosure_coe, + Submodule.topologicalClosure_eq_top_iff.mpr h_orth_bot, Submodule.top_coe] + rw [Submodule.eq_bot_iff] + intro g h_mem + rw [Submodule.mem_orthogonal] at h_mem + refine (Lp.eq_zero_iff_ae_eq_zero (f := g)).mpr ?_ + exact aezeroOfOrth (μ := μ) hBmeas g (fun V ↦ h_mem _ ⟨V, rfl⟩) + +/-- **The unbounded-horizon Itô integral as a CLM.** Built from `itoAssembly` +along the (now dense) `simpleAssembly` via `LinearMap.extendOfNorm`. Its domain +`Lp ℝ 2 trim_full` is Degenne's `L2Predictable timeMeasure μ`. -/ +noncomputable def itoIntegralL2 (hBmeas : ∀ t, Measurable (B t)) : + Lp ℝ 2 ((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod) →L[ℝ] Lp ℝ 2 μ := + (itoAssembly (μ := μ) hB hBmeas).extendOfNorm (simpleAssembly (μ := μ) hBmeas) + +/-- **The unbounded-horizon Itô isometry.** For every `f ∈ Lp 2 trim_full`, +`‖itoIntegralL2 f‖ = ‖f‖`. -/ +theorem itoIntegralL2_norm (hBmeas : ∀ t, Measurable (B t)) + (f : Lp ℝ 2 ((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod)) : + ‖itoIntegralL2 (μ := μ) hB hBmeas f‖ = ‖f‖ := by + rw [itoIntegralL2] + exact LinearMap.norm_extendOfNorm_eq_of_isometry + (simpleAssembly_denseRange (μ := μ) hBmeas) (assembly_isometry hB hBmeas) f + +/-- **The `[0,∞)` integral of a simple process is its explicit simple integral** +`itoSimpleLp V` (`extendOfNorm` on the dense embedding). -/ +lemma itoIntegralL2_simpleAssembly (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + itoIntegralL2 hB hBmeas (simpleAssembly hBmeas V) = itoSimpleLp hB hBmeas V := by + rw [itoIntegralL2, LinearMap.extendOfNorm_eq (simpleAssembly_denseRange (μ := μ) hBmeas) + ⟨1, fun W ↦ by rw [one_mul]; exact (assembly_isometry hB hBmeas W).le⟩] + rfl + +end ItoIntegralL2 +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcess.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcess.lean new file mode 100644 index 0000000000..ff35af0ddd --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcess.lean @@ -0,0 +1,221 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralL2 + +/-! # The Itô integral as a process `t ↦ (V ● B)_t`, with genuine `L²` content + +The elementary Itô integral of a simple process `V`, viewed as a **process** +indexed by finite time `t : ℝ≥0` — the value of `∫₀ᵗ V dB` truncated at `t`. +Built on Degenne's `SimpleProcess.integral` at the finite (deterministic) +stopping time `(t : WithTop ℝ≥0)`, so it is coherent with the upstream +elementary-integral algebra (linearity is inherited for free). + +Unlike a bare scaffold, this file proves the **genuine analytic content** the +process layer rests on: + +* `itoSimpleProcess_apply` — the explicit truncated increment-sum + `(V ● B)_t ω = ∑_p V(p)(ω)·(B_{p.2∧t}(ω) − B_{p.1∧t}(ω))` (the deterministic + stopped process at `t` collapses to `B(· ∧ t)`). +* `memLp_itoSimpleProcess` — `(V ● B)_t ∈ L²(μ)` at **every** time `t`. This is + the real work: each summand is, after truncation, either `0` (interval past + `t`) or an adapted coefficient times a Brownian increment (`p.1 ≤ t`), so the + adapted-increment `L²` lemma applies; the finite sum is `L²`. (Same engine as + `ItoIntegralL2.memLp_itoSimple`, with the truncation case-split.) +* `itoSimpleProcessLp` — its `Lp ℝ 2 μ` class. +* `itoSimpleProcess_eq_itoSimple` — at any `t` past all interval right + endpoints, the process equals the **terminal** `ItoIntegralL2.itoSimple V`, + i.e. the object the continuous Itô CLM (`ItoIntegralCLM`) extends. This is the + bridge tying the process view to the L²/CLM foundation. +* `itoSimpleProcess_zero_time` — `(V ● B)_0 = 0` (every increment collapses). +* `V`-linearity (`add`/`smul`/`neg`), inherited from `SimpleProcess.integral`. + +The next layer, built on `memLp_itoSimpleProcess` here, now delivers all four +of adaptedness, pathwise continuity, the martingale property and the +time-indexed isometry: see `ItoIntegralProcessIsometry` +(`itoSimpleProcess_isometry_time`), `ItoIntegralProcessContinuousModification` +and `ItoIntegralProcessMartingale`. + +## Main definitions + +* `itoSimpleProcess`: the process-level elementary Itô integral of a simple process `V` against + `B` at finite time `t`, Degenne's `SimpleProcess.integral` at the deterministic stopping time + `t`. +* `itoSimpleProcessLp`: the process Itô integral at time `t` as an element of `Lp ℝ 2 μ`. + +## Main results + +* `itoSimpleProcess_apply`: the explicit truncated increment sum + `(V ● B)_t ω = ∑_p V(p)(ω) · (B_{p.2∧t}(ω) − B_{p.1∧t}(ω))`. +* `itoSimpleProcess_add`, `itoSimpleProcess_smul`: the process Itô integral is additive and + homogeneous in the simple process. +* `itoSimpleProcess_zero_time`: at `t = 0` the process is `0`. +* `itoSimpleProcess_eq_itoSimple`: at any `t` past all interval right endpoints the process equals + the terminal Itô integral `itoSimple V`. +* `memLp_itoSimpleProcess`: `(V ● B)_t` is in `L²(μ)` at every time `t`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Ch 7 + +## Tags + +Itô integral process, simple processes, elementary stochastic integral, stopped process, +L² martingale, MSC 60H05, MSC 60G44 +-/ + +@[expose] public section + +namespace MathFin +namespace ItoIntegralProcess + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + {B : ℝ≥0 → Ω → ℝ} + +/-- **Process-level elementary Itô integral** of a simple `V` against Brownian +motion `B`, at finite time `t`. Degenne's `SimpleProcess.integral` against +multiplication, evaluated at the deterministic stopping time `t`. + +Since the 2026-07-27 pin his integral is indexed by `ι` itself rather than +`WithTop ι`, so the time argument is `t : ℝ≥0` with no coercion; the semantics +are unchanged (the definition still truncates each increment at `t`). -/ +noncomputable def itoSimpleProcess (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) + (t : ℝ≥0) : Ω → ℝ := + SimpleProcess.integral (ContinuousLinearMap.mul ℝ ℝ) V B t + +/-- The deterministic stopped process at a constant time `u` collapses to +`B (· ∧ u)`: `stoppedProcess B (fun _ ↦ u) s = B (min s u)`. With the time index +no longer wrapped in `WithTop`, this is Mathlib's definition of +`stoppedProcess` unfolded — the `untopA` bookkeeping the old pin needed is +gone. -/ +lemma stoppedProcess_const_coe (u s : ℝ≥0) (ω : Ω) : + stoppedProcess B (fun _ : Ω ↦ u) s ω = B (min s u) ω := rfl + +/-- **Explicit truncated increment-sum**: +`(V ● B)_t ω = ∑_p V(p)(ω)·(B_{p.2∧t}(ω) − B_{p.1∧t}(ω))`. -/ +lemma itoSimpleProcess_apply (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) + (t : ℝ≥0) (ω : Ω) : + itoSimpleProcess hBmeas V t ω + = V.value.sum fun p v ↦ v ω * (B (min p.2 t) ω - B (min p.1 t) ω) := by + simp only [itoSimpleProcess, SimpleProcess.integral, ContinuousLinearMap.mul_apply'] + refine Finsupp.sum_congr fun p _ ↦ ?_ + rw [stoppedProcess_const_coe, stoppedProcess_const_coe] + +/-- The elementary process Itô integral is **additive** in the simple process. -/ +lemma itoSimpleProcess_add (hBmeas : ∀ t, Measurable (B t)) + (V W : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) + (t : ℝ≥0) : + itoSimpleProcess hBmeas (V + W) t = itoSimpleProcess hBmeas V t + + itoSimpleProcess hBmeas W t := by + funext ω + simp only [itoSimpleProcess, SimpleProcess.integral_add_left, Pi.add_apply] + +/-- The elementary process Itô integral is **homogeneous** in the simple process. -/ +lemma itoSimpleProcess_smul (hBmeas : ∀ t, Measurable (B t)) (c : ℝ) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) (t : ℝ≥0) : + itoSimpleProcess hBmeas (c • V) t = c • itoSimpleProcess hBmeas V t := by + funext ω + simp only [itoSimpleProcess, SimpleProcess.integral_smul_left, Pi.smul_apply] + +/-- The elementary process Itô integral on `-V` flips sign. -/ +lemma itoSimpleProcess_neg (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) (t : ℝ≥0) : + itoSimpleProcess hBmeas (-V) t = -itoSimpleProcess hBmeas V t := by + funext ω + simp only [itoSimpleProcess, SimpleProcess.integral_neg_left, Pi.neg_apply] + +/-- **At `t = 0`**, the process is `0`: every increment `B_{p.i∧0} = B_0` +collapses, so each term `V(p)·(B_0 − B_0) = 0`. -/ +@[simp] lemma itoSimpleProcess_zero_time (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) : + itoSimpleProcess hBmeas V 0 = 0 := by + funext ω + rw [itoSimpleProcess_apply, Finsupp.sum] + refine Finset.sum_eq_zero fun p _ ↦ ?_ + have e1 : min p.1 (0 : ℝ≥0) = 0 := min_eq_right zero_le + have e2 : min p.2 (0 : ℝ≥0) = 0 := min_eq_right zero_le + rw [e1, e2, sub_self, mul_zero] + +/-- **Terminal agreement with the CLM base object.** At any `t` past all +interval right endpoints, the process equals the terminal Itô integral +`ItoIntegralL2.itoSimple V` (which the continuous Itô CLM extends). -/ +lemma itoSimpleProcess_eq_itoSimple (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) + {t : ℝ≥0} (ht : ∀ p ∈ V.value.support, p.2 ≤ t) : + itoSimpleProcess hBmeas V t = ItoIntegralL2.itoSimple hBmeas V := by + funext ω + rw [itoSimpleProcess_apply, ItoIntegralL2.itoSimple_apply] + refine Finsupp.sum_congr fun p hp ↦ ?_ + have h2 : min p.2 t = p.2 := min_eq_left (ht p hp) + have h1 : min p.1 t = p.1 := min_eq_left ((V.le_of_mem_support_value p hp).trans (ht p hp)) + rw [h1, h2] + +variable (hB : IsPreBrownianReal B μ) + +include hB + +/-- A simple process's value `V(p)` is in `L²(μ)`: it is `𝓕_{p.1}`-measurable and +bounded by `V.valueBound`, hence `L²` on the probability space. -/ +theorem memLp_value (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) + (p : ℝ≥0 × ℝ≥0) : MemLp (V.value p) 2 μ := by + have : IsProbabilityMeasure μ := hB.isGaussianProcess.isProbabilityMeasure + exact MemLp.of_bound + ((V.measurable_value p).mono ((ItoIntegralL2.natFiltration hBmeas).le p.1) + le_rfl).aestronglyMeasurable + V.valueBound (ae_of_all _ (V.value_le_valueBound p)) + +/-- Each truncated summand `V(p)·(B_{p.2∧t} − B_{p.1∧t})` is in `L²`: for `p.1 ≤ t` +an adapted coefficient times the increment over `[p.1, p.2∧t]`; past `t` the zero +function. The per-term content of `memLp_itoSimpleProcess`. -/ +theorem memLp_truncated_term (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) + (t : ℝ≥0) {p : ℝ≥0 × ℝ≥0} (hp : p ∈ V.value.support) : + MemLp (fun ω ↦ V.value p ω * (B (min p.2 t) ω - B (min p.1 t) ω)) 2 μ := by + have : IsProbabilityMeasure μ := hB.isGaussianProcess.isProbabilityMeasure + by_cases ht : p.1 ≤ t + · -- active interval: adapted coefficient × increment over `[p.1, p.2 ∧ t]` + rw [min_eq_left ht] + exact ItoIsometryAdapted.memLp_adapted_mul_increment (hB.isFilteredPreBrownian hBmeas) + (le_min (V.le_of_mem_support_value p hp) ht) + (V.measurable_value p) + (memLp_value hB hBmeas V p) + · -- interval entirely past `t`: both endpoints truncate to `t`, term is `0` + push Not at ht + have h1 : min p.1 t = t := min_eq_right ht.le + have h2 : min p.2 t = t := min_eq_right (ht.le.trans (V.le_of_mem_support_value p hp)) + simp only [h1, h2, sub_self, mul_zero] + exact memLp_const 0 + +/-- **`L²` membership at every time `t`** — the genuine analytic content. After +truncation each summand is `0` (interval past `t`) or an adapted coefficient times +a Brownian increment (`p.1 ≤ t`), so the finite sum is `L²(μ)` +(`memLp_truncated_term`). -/ +theorem memLp_itoSimpleProcess (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) + (t : ℝ≥0) : + MemLp (itoSimpleProcess hBmeas V t) 2 μ := by + rw [show itoSimpleProcess hBmeas V t + = fun ω ↦ ∑ p ∈ V.value.support, V.value p ω * (B (min p.2 t) ω - B (min p.1 t) ω) + from funext fun ω ↦ by rw [itoSimpleProcess_apply]; rfl] + exact memLp_finsetSum _ fun p hp ↦ memLp_truncated_term hB hBmeas V t hp + +/-- The process Itô integral at time `t` as an element of `Lp ℝ 2 μ`. -/ +noncomputable def itoSimpleProcessLp (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) + (t : ℝ≥0) : Lp ℝ 2 μ := + (memLp_itoSimpleProcess hB hBmeas V t).toLp _ + +end ItoIntegralProcess +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessContinuousModification.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessContinuousModification.lean new file mode 100644 index 0000000000..961b4a15f7 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessContinuousModification.lean @@ -0,0 +1,437 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessGeneral +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessLocalMartingale +public import LeanPool.MathFin.Probability.Support.DoobContinuous + +/-! +# Continuous modification of the general-integrand Itô process (the gate) + +The first pathwise-regularity result for the **general** integrand: a continuous +modification of the `L²`-valued process `t ↦ itoProcessCLM T t φ` on a finite +horizon `[0,T]`. + +B1b (`ItoIntegralProcessGeneral`) built the general-integrand Itô integral as an +`Lp ℝ 2 μ`-valued process — adapted, an `L²` martingale, `L²`-continuous in `t`, +but with no honest sample paths. B3 (`ItoIntegralProcessLocalMartingale`) gave +pathwise continuity only for the **simple** integrand. This file closes the gap: +approximate `φ` by simple processes `Vₙ` (density, B1b); each `Vₙ ● B` has +continuous paths (B3); Degenne's continuous-time weak-type maximal inequality +(`maximal_ineq_norm`) + Borel–Cantelli on a fast subsequence make `(Vₙ ● B)` +a.s.-uniformly Cauchy on `[0,T]`, so the uniform limit `itoContinuousMod` is +pathwise continuous (`itoContinuousMod_continuousOn`) and equals `(φ ● B)_t` a.e. +at every `t ≤ T` (a **modification**, `itoContinuousMod_modification`), bundled by +`exists_continuous_modification_itoProcess`. + +This continuous modification is the *input* the localized stochastic calculus +consumes: the `IsLocalMartingale` packaging is an explicit follow-on (Degenne's +`Martingale.IsLocalMartingale` needs paths càdlàg for **every** `ω`, which for the +general integrand requires an augmented filtration — the "usual conditions" — that +`natFiltration` does not carry; B3 sidesteps this because the *simple* process is +continuous and adapted for every `ω`). It is **not** proved here. + +## Coherence + +Pure consumption + assembly. Degenne's general càdlàg modification, `cadlagModif` in +`StochasticIntegral/Quasimartingale/CadlagModificationBanach.lean`, has no `sorry` at our pin, but +it is a modification only for a right-continuous filtration, and adapted only if that filtration is +also complete: the usual conditions, which `natFiltration` does not carry. So this result is not a +duplicate, and the `L²`-continuity + Doob route yields a genuinely **continuous** (not merely +càdlàg) version. Nothing of the isometry, density, or martingale property is reproved — the maximal +inequality is Degenne's, the continuous approximants are B3's, the density is B1b's. + +See `docs/superpowers/specs/2026-06-26-ito-continuous-modification-design.md`. + +## Main definitions + +* `itoContinuousMod`: the pathwise limit process, for each `t, ω` the limit (if it exists) of the + approximating simple integrals `(Vₙ ● B)_t ω` along `approxSeq`, junk off the convergence set. + +## Main results + +* `itoSimpleProcess_maximal_weak`: the weak-type maximal bound + `ε · μ{ε ≤ sup_{i ≤ T} ‖(V ● B)_i‖} ≤ ∫_{that set} ‖(V ● B)_T‖` for the elementary Itô integral. +* `itoSimpleProcess_maximal_prob`: for a `T`-bounded simple process `V` and `ε > 0`, the + probability that the running maximum of `(V ● B)` over `[0,T]` reaches `ε` is at most + `ε⁻¹ · ‖simpleAssemblyHorizon V‖`. +* `approxSeq`: every predictable integrand `φ` has a fast approximating sequence of `T`-bounded + simple processes, with `‖simpleAssemblyHorizon Vₙ − φ‖ ≤ 2⁻ⁿ`. +* `ae_eventually_sup_lt`: for such a fast approximating sequence `Vₙ` (and continuous Brownian + paths), almost surely the running maximum of the consecutive difference `(Vₙ − Vₙ₊₁) ● B` over + `[0,T]` is eventually below `(3/4)ⁿ`. +* `itoContinuousMod_modification`: for every `t ≤ T`, `itoContinuousMod φ t` agrees almost + everywhere with `itoProcessCLM T t φ`. +* `itoContinuousMod_continuousOn`: almost every path of `itoContinuousMod φ` is continuous on + `[0,T]`. +* `exists_continuous_modification_itoProcess`: there is a process agreeing almost everywhere with + `itoProcessCLM T t φ` at every `t ≤ T`, with almost surely continuous paths on `[0,T]`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Ch 7 + +## Tags + +continuous modification, Itô integral, Doob maximal inequality, Borel–Cantelli, stochastic integral, +sample paths, MSC 60H05, MSC 60G44, MSC 60G07 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Filter Topology +open scoped NNReal ENNReal + +namespace MathFin +namespace ItoIntegralProcessContinuousModification + +open ItoIntegralL2 ItoIntegralCLM ItoIntegralProcess ItoIntegralProcessGeneral + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) + +include hB + +/-! ## Phase 1 — the maximal estimate -/ + +/-- **Continuous-time weak-type maximal bound** for the elementary Itô integral. +The process `t ↦ (V ● B)_t` is a continuous `L²` martingale (B1a's martingale +property + B3's path continuity), so Degenne's continuous-time maximal inequality +`maximal_ineq_norm` applies directly at `n := T`, where `⨆ i : Set.Iic T` is the +running supremum over the whole interval `[0,T]`. -/ +theorem itoSimpleProcess_maximal_weak (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (V : SimpleProcess ℝ (natFiltration hBmeas)) (T : ℝ≥0) (ε : ℝ) : + ε • μ.real {ω | ε ≤ ⨆ i : Set.Iic T, ‖itoSimpleProcess hBmeas V i ω‖} + ≤ ∫ ω in {ω | ε ≤ ⨆ i : Set.Iic T, ‖itoSimpleProcess hBmeas V i ω‖}, + ‖itoSimpleProcess hBmeas V T ω‖ ∂μ := + maximal_ineq_norm (itoSimpleProcess_isMartingale hB hBmeas V) ε T + (fun ω _ ↦ (itoSimpleProcess_pathContinuous hBmeas hBcont V ω).continuousWithinAt) + +/-- **Chebyshev form** of the maximal bound, with the `L²` terminal norm on the right. For a +`T`-bounded simple process `V`, the probability that the running maximum of `(V ● B)` over `[0,T]` +reaches `ε` is at most `ε⁻¹ · ‖simpleAssemblyHorizon V‖`: combine the weak bound with +`∫_S ‖(V●B)_T‖ ≤ ∫ ‖(V●B)_T‖ ≤ ‖(V●B)_T‖_{L²}` (set-integral monotonicity + `L¹ ≤ L²` on the +probability space) and the terminal Itô isometry `‖(V●B)_T‖_{L²} = ‖simpleAssemblyHorizon V‖`. -/ +theorem itoSimpleProcess_maximal_prob (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (T : ℝ≥0) (V : TBoundedSP T hBmeas) {ε : ℝ} (hε : 0 < ε) : + μ.real {ω | ε ≤ ⨆ i : Set.Iic T, ‖itoSimpleProcess hBmeas V.val i ω‖} + ≤ ε⁻¹ * ‖simpleAssemblyHorizon (μ := μ) T hBmeas V‖ := by + set f := itoSimpleProcess hBmeas V.val T + set S := {ω | ε ≤ ⨆ i : Set.Iic T, ‖itoSimpleProcess hBmeas V.val i ω‖} + have hf : MemLp f 2 μ := memLp_itoSimpleProcess hB hBmeas V.val T + have hfi : Integrable f μ := hf.integrable (by norm_num) + have hweak := itoSimpleProcess_maximal_weak hB hBmeas hBcont V.val T ε + -- ∫_S ‖f‖ ≤ ∫ ‖f‖ + have hsub : ∫ ω in S, ‖f ω‖ ∂μ ≤ ∫ ω, ‖f ω‖ ∂μ := + setIntegral_le_integral hfi.norm (ae_of_all _ fun ω ↦ norm_nonneg _) + -- ∫ ‖f‖ ≤ ‖f‖_{L²} = ‖itoSimpleProcessLp V T‖ + have hL2 : ∫ ω, ‖f ω‖ ∂μ ≤ ‖itoSimpleProcessLp hB hBmeas V.val T‖ := by + rw [itoSimpleProcessLp, Lp.norm_toLp, + ← ENNReal.toReal_ofReal (integral_nonneg fun ω ↦ norm_nonneg _), + ofReal_integral_norm_eq_lintegral_eNorm hfi, + ← eLpNorm_one_eq_lintegral_eNorm hfi.aestronglyMeasurable] + exact ENNReal.toReal_mono hf.eLpNorm_ne_top (eLpNorm_le_eLpNorm_of_exponent_le (by norm_num)) + -- terminal Itô isometry on the simple embedding + have hterm : ‖itoSimpleProcessLp hB hBmeas V.val T‖ = + ‖simpleAssemblyHorizon (μ := μ) T hBmeas V‖ := by + rw [← itoProcessCLM_simpleAssemblyHorizon hB T T hBmeas V, + itoProcessCLM_norm_terminal hB T hBmeas] + -- assemble: ε * μ.real S ≤ ‖simpleAssemblyHorizon V‖, then divide by ε > 0 + rw [smul_eq_mul] at hweak + have hchain : ε * μ.real S ≤ ‖simpleAssemblyHorizon (μ := μ) T hBmeas V‖ := + hweak.trans (hsub.trans (hL2.trans_eq hterm)) + calc μ.real S = ε⁻¹ * (ε * μ.real S) := by + rw [← mul_assoc, inv_mul_cancel₀ hε.ne', one_mul] + _ ≤ ε⁻¹ * ‖simpleAssemblyHorizon (μ := μ) T hBmeas V‖ := + mul_le_mul_of_nonneg_left hchain (inv_nonneg.mpr hε.le) + +/-! ## Phase 2 — approximating subsequence, Borel–Cantelli, continuous limit -/ + +omit hB in +/-- **Fast approximating subsequence.** By density of the simple-process +embedding (`simpleAssemblyHorizon_denseRange`), every predictable integrand `φ` is +approximated by `T`-bounded simple processes `Vₙ` with +`‖simpleAssemblyHorizon Vₙ − φ‖ ≤ 2⁻ⁿ`. -/ +theorem approxSeq (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ∃ V : ℕ → TBoundedSP T hBmeas, + ∀ n, ‖simpleAssemblyHorizon (μ := μ) T hBmeas (V n) - φ‖ ≤ (2⁻¹ : ℝ) ^ n := by + have hd := simpleAssemblyHorizon_denseRange (μ := μ) T hBmeas + have hex : ∀ n : ℕ, ∃ V : TBoundedSP T hBmeas, + ‖simpleAssemblyHorizon (μ := μ) T hBmeas V - φ‖ ≤ (2⁻¹ : ℝ) ^ n := by + intro n + obtain ⟨V, hV⟩ := hd.exists_dist_lt φ (by positivity : (0 : ℝ) < (2⁻¹ : ℝ) ^ n) + exact ⟨V, by rw [← dist_eq_norm, dist_comm]; exact hV.le⟩ + choose V hV using hex + exact ⟨V, hV⟩ + +omit hB in +/-- The elementary process Itô integral is **subtractive** in the simple +process (from B1a's `itoSimpleProcess_add` / `_neg`). -/ +lemma itoSimpleProcess_sub (hBmeas : ∀ t, Measurable (B t)) + (V W : SimpleProcess ℝ (natFiltration hBmeas)) (t : ℝ≥0) : + itoSimpleProcess hBmeas (V - W) t + = itoSimpleProcess hBmeas V t - itoSimpleProcess hBmeas W t := by + rw [sub_eq_add_neg, itoSimpleProcess_add, itoSimpleProcess_neg, ← sub_eq_add_neg] + +/-- **Summable maximal tail.** For the fast subsequence `V` (`approxSeq`), the +probabilities that the running max of the consecutive difference +`(Vₙ − Vₙ₊₁) ● B` over `[0,T]` reaches `εₙ := (3/4)ⁿ` are summable: each is +`≤ εₙ⁻¹ · ‖simpleAssemblyHorizon (Vₙ − Vₙ₊₁)‖ ≤ εₙ⁻¹ · 2·2⁻ⁿ = 2·(2/3)ⁿ`. The choice +`εₙ = (3/4)ⁿ ∈ (2⁻¹, 1)ⁿ` makes both `Σ εₙ⁻¹·2⁻ⁿ` and `Σ εₙ` converge. -/ +theorem summable_maximal_tail (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) (V : ℕ → TBoundedSP T hBmeas) + (hV : ∀ n, ‖simpleAssemblyHorizon (μ := μ) T hBmeas (V n) - φ‖ ≤ (2⁻¹ : ℝ) ^ n) : + Summable (fun n ↦ μ.real {ω | (3 / 4 : ℝ) ^ n ≤ + ⨆ i : Set.Iic T, ‖itoSimpleProcess hBmeas (V n - V (n + 1)).val i ω‖}) := by + refine Summable.of_nonneg_of_le (fun n ↦ measureReal_nonneg) (fun n ↦ ?_) + ((summable_geometric_of_lt_one (r := 2 / 3) (by norm_num) (by norm_num)).mul_left 2) + -- per-term: μ.real {…} ≤ 2 * (2/3)ⁿ + refine (itoSimpleProcess_maximal_prob hB hBmeas hBcont T (V n - V (n + 1)) + (ε := (3 / 4 : ℝ) ^ n) (by positivity)).trans ?_ + have hnorm : ‖simpleAssemblyHorizon (μ := μ) T hBmeas (V n - V (n + 1))‖ ≤ 2 * (2⁻¹ : ℝ) ^ n := by + rw [map_sub] + calc ‖simpleAssemblyHorizon (μ := μ) T hBmeas (V n) + - simpleAssemblyHorizon (μ := μ) T hBmeas (V (n + 1))‖ + ≤ ‖simpleAssemblyHorizon (μ := μ) T hBmeas (V n) - φ‖ + + ‖φ - simpleAssemblyHorizon (μ := μ) T hBmeas (V (n + 1))‖ := by + have h := norm_add_le (simpleAssemblyHorizon (μ := μ) T hBmeas (V n) - φ) + (φ - simpleAssemblyHorizon (μ := μ) T hBmeas (V (n + 1))) + simpa using h + _ ≤ (2⁻¹ : ℝ) ^ n + (2⁻¹ : ℝ) ^ (n + 1) := by + gcongr + · exact hV n + · rw [norm_sub_rev]; exact hV (n + 1) + _ ≤ 2 * (2⁻¹ : ℝ) ^ n := by + rw [pow_succ]; linarith [pow_nonneg (by norm_num : (0 : ℝ) ≤ 2⁻¹) n] + calc ((3 / 4 : ℝ) ^ n)⁻¹ * ‖simpleAssemblyHorizon (μ := μ) T hBmeas (V n - V (n + 1))‖ + ≤ ((3 / 4 : ℝ) ^ n)⁻¹ * (2 * (2⁻¹ : ℝ) ^ n) := + mul_le_mul_of_nonneg_left hnorm (by positivity) + _ = 2 * (2 / 3 : ℝ) ^ n := by + rw [← inv_pow, mul_comm (2 : ℝ) ((2⁻¹ : ℝ) ^ n), ← mul_assoc, ← mul_pow, + show ((3 / 4 : ℝ)⁻¹ * 2⁻¹) = 2 / 3 from by norm_num, mul_comm] + +/-- **A.s. eventual smallness (Borel–Cantelli).** Since the maximal tail is +summable, for almost every `ω` the running maximum of the consecutive difference +`(Vₙ − Vₙ₊₁) ● B` over `[0,T]` is eventually below `(3/4)ⁿ`. This is the pathwise +input to the uniform-Cauchy argument. -/ +theorem ae_eventually_sup_lt (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) (V : ℕ → TBoundedSP T hBmeas) + (hV : ∀ n, ‖simpleAssemblyHorizon (μ := μ) T hBmeas (V n) - φ‖ ≤ (2⁻¹ : ℝ) ^ n) : + ∀ᵐ ω ∂μ, ∀ᶠ n in atTop, + (⨆ i : Set.Iic T, ‖itoSimpleProcess hBmeas (V n - V (n + 1)).val i ω‖) < (3 / 4 : ℝ) ^ n := by + set A : ℕ → Set Ω := fun n ↦ {ω | (3 / 4 : ℝ) ^ n ≤ + ⨆ i : Set.Iic T, ‖itoSimpleProcess hBmeas (V n - V (n + 1)).val i ω‖} with hA + have hconv : (∑' n, μ (A n)) ≠ ∞ := by + have heq : ∀ n, μ (A n) = ENNReal.ofReal (μ.real (A n)) := + fun n ↦ (ENNReal.ofReal_toReal (measure_ne_top μ _)).symm + simp_rw [heq] + rw [← ENNReal.ofReal_tsum_of_nonneg (fun n ↦ measureReal_nonneg) + (summable_maximal_tail hB T hBmeas hBcont φ V hV)] + exact ENNReal.ofReal_ne_top + filter_upwards [ae_eventually_notMem hconv] with ω hω + filter_upwards [hω] with n hn + rwa [hA, Set.mem_ofPred_eq, not_le] at hn + +/-! ## Phase 3 — continuous limit, modification, capstone -/ + +omit hB in +/-- **The running-max keystone.** For `i ≤ T`, the value `‖(W ● B)_i ω‖` is +bounded by the running maximum over `[0,T]`. The supremum is genuine (not the +junk value of an unbounded family): `(W ● B)_· ω` is continuous (B3) and `[0,T]` +is compact, so the family is bounded above. This unlocks the pointwise control of +consecutive differences. -/ +lemma norm_le_iSup_Iic (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (W : SimpleProcess ℝ (natFiltration hBmeas)) (ω : Ω) {i : ℝ≥0} (hi : i ≤ T) : + ‖itoSimpleProcess hBmeas W i ω‖ + ≤ ⨆ j : Set.Iic T, ‖itoSimpleProcess hBmeas W (j : ℝ≥0) ω‖ := by + have hcont : Continuous fun j : Set.Iic T ↦ ‖itoSimpleProcess hBmeas W (j : ℝ≥0) ω‖ := + (continuous_norm.comp (itoSimpleProcess_pathContinuous hBmeas hBcont W ω)).comp + continuous_subtype_val + have hIic : (Set.Iic T : Set ℝ≥0) = Set.Icc 0 T := by + ext x; simp only [Set.mem_Iic, Set.mem_Icc, zero_le, true_and] + have : CompactSpace (Set.Iic T) := isCompact_iff_compactSpace.mp (hIic ▸ isCompact_Icc) + exact le_ciSup (isCompact_range hcont).bddAbove ⟨i, hi⟩ + +omit hB in +/-- The pathwise limit process: for each `t, ω` the limit (if it exists) of the +approximating simple integrals `(Vₙ ● B)_t ω`, junk off the convergence set. The +subsequence `Vₙ` is `approxSeq`'s choice for `φ`. -/ +noncomputable def itoContinuousMod (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) (t : ℝ≥0) (ω : Ω) : ℝ := + limUnder atTop fun n ↦ itoSimpleProcess hBmeas ((approxSeq T hBmeas φ).choose n).val t ω + +/-- **Pointwise a.s. convergence.** For almost every `ω` and every `t ≤ T`, the +approximating sequence `(Vₙ ● B)_t ω` converges to `itoContinuousMod φ t ω`. The +consecutive distances are eventually `< (3/4)ⁿ` (a.s., uniformly in `t ≤ T`, by +`ae_eventually_sup_lt` + the running-max keystone + linearity), hence summable, +so the sequence is Cauchy in the complete space `ℝ`. -/ +theorem itoContinuousMod_tendsto (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ∀ᵐ ω ∂μ, ∀ t : ℝ≥0, t ≤ T → + Tendsto (fun n ↦ itoSimpleProcess hBmeas ((approxSeq T hBmeas φ).choose n).val t ω) atTop + (𝓝 (itoContinuousMod T hBmeas φ t ω)) := by + set V := (approxSeq T hBmeas φ).choose with hVdef + have hV := (approxSeq T hBmeas φ).choose_spec + filter_upwards [ae_eventually_sup_lt hB T hBmeas hBcont φ V hV] with ω hω + intro t ht + have hcauchy : CauchySeq (fun n ↦ itoSimpleProcess hBmeas (V n).val t ω) := by + apply cauchySeq_of_summable_dist + obtain ⟨N, hN⟩ := eventually_atTop.mp hω + rw [← summable_nat_add_iff N] + refine Summable.of_nonneg_of_le (fun n ↦ dist_nonneg) (fun n ↦ ?_) + (f := fun n ↦ (3 / 4 : ℝ) ^ (n + N)) ?_ + · rw [dist_eq_norm] + have hcoe : ((V (n + N) - V (n + N + 1)).val : SimpleProcess ℝ (natFiltration hBmeas)) + = (V (n + N)).val - (V (n + N + 1)).val := rfl + have hlin : itoSimpleProcess hBmeas (V (n + N)).val t ω + - itoSimpleProcess hBmeas (V (n + N + 1)).val t ω + = itoSimpleProcess hBmeas (V (n + N) - V (n + N + 1)).val t ω := by + rw [hcoe] + exact (congrFun (itoSimpleProcess_sub hBmeas (V (n + N)).val (V (n + N + 1)).val t) ω).symm + rw [hlin] + exact (norm_le_iSup_Iic T hBmeas hBcont (V (n + N) - V (n + N + 1)).val ω ht).trans + (hN (n + N) (Nat.le_add_left N n)).le + · simp_rw [pow_add] + exact (summable_geometric_of_lt_one (by norm_num) (by norm_num)).mul_right _ + simpa only [itoContinuousMod, hVdef] using hcauchy.tendsto_limUnder + +/-- **The modification (Task 7).** For every `t ≤ T`, the pathwise limit `itoContinuousMod φ t` +agrees almost everywhere with the `L²` process value `itoProcessCLM T t φ`. Two convergences to +compare: `Fₙ → itoContinuousMod` a.e. (pointwise, above) and `Fₙ → itoProcessCLM T t φ` in measure +(from the `L²` convergence +`itoSimpleProcessLp Vₙ t = itoProcessCLM T t (simpleAssemblyHorizon Vₙ) → itoProcessCLM T t φ`, via +the bridge + CLM continuity). In-measure limits are a.e.-unique. -/ +theorem itoContinuousMod_modification (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) {t : ℝ≥0} (ht : t ≤ T) : + (fun ω ↦ itoContinuousMod T hBmeas φ t ω) =ᵐ[μ] itoProcessCLM hB T t hBmeas φ := by + set V := (approxSeq T hBmeas φ).choose with hVdef + have hV := (approxSeq T hBmeas φ).choose_spec + set F : ℕ → Ω → ℝ := fun n ω ↦ itoSimpleProcess hBmeas (V n).val t ω + have hFmeas : ∀ n, AEStronglyMeasurable (F n) μ := + fun n ↦ (memLp_itoSimpleProcess hB hBmeas (V n).val t).aestronglyMeasurable + -- (a) F → itoContinuousMod a.e. ⟹ in measure + have hmeasG : TendstoInMeasure μ F atTop (fun ω ↦ itoContinuousMod T hBmeas φ t ω) := by + refine tendstoInMeasure_of_tendsto_ae hFmeas ?_ + filter_upwards [itoContinuousMod_tendsto hB T hBmeas hBcont φ] with ω hω using hω t ht + -- (b) F → ⇑(itoProcessCLM T t φ) in measure, from L² convergence + have hsa : Tendsto (fun n ↦ simpleAssemblyHorizon (μ := μ) T hBmeas (V n)) atTop (𝓝 φ) := by + rw [tendsto_iff_norm_sub_tendsto_zero] + exact squeeze_zero (fun n ↦ norm_nonneg _) hV + (tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num) (by norm_num)) + have hLp : Tendsto (fun n ↦ itoSimpleProcessLp hB hBmeas (V n).val t) atTop + (𝓝 (itoProcessCLM hB T t hBmeas φ)) := by + have hrw : (fun n ↦ itoSimpleProcessLp hB hBmeas (V n).val t) + = fun n ↦ itoProcessCLM hB T t hBmeas (simpleAssemblyHorizon (μ := μ) T hBmeas (V n)) := + funext fun n ↦ (itoProcessCLM_simpleAssemblyHorizon hB T t hBmeas (V n)).symm + rw [hrw] + exact ((itoProcessCLM hB T t hBmeas).continuous.tendsto φ).comp hsa + have heLp : Tendsto (fun n ↦ eLpNorm (F n - ⇑(itoProcessCLM hB T t hBmeas φ)) 2 μ) + atTop (𝓝 0) := by + refine (Lp.tendsto_Lp_iff_tendsto_eLpNorm'' F + (fun n ↦ memLp_itoSimpleProcess hB hBmeas (V n).val t) + (⇑(itoProcessCLM hB T t hBmeas φ)) (Lp.memLp _)).mp ?_ + simp only [Lp.toLp_coeFn] + exact hLp + have hmeasH : TendstoInMeasure μ F atTop (⇑(itoProcessCLM hB T t hBmeas φ)) := + tendstoInMeasure_of_tendsto_eLpNorm (by norm_num) heLp + exact tendstoInMeasure_ae_unique hmeasG hmeasH + +omit hB in +/-- Consecutive-difference bound combining linearity with the running-max keystone: +for `t ≤ T`, `‖(Vₐ ● B)_t − (Vₐ₊₁ ● B)_t‖` is at most the running max of +`(Vₐ − Vₐ₊₁) ● B` over `[0,T]`. -/ +lemma consecutive_norm_le (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) (V : ℕ → TBoundedSP T hBmeas) + (ω : Ω) {t : ℝ≥0} (ht : t ≤ T) (a : ℕ) : + ‖itoSimpleProcess hBmeas (V a).val t ω - itoSimpleProcess hBmeas (V (a + 1)).val t ω‖ + ≤ ⨆ j : Set.Iic T, ‖itoSimpleProcess hBmeas (V a - V (a + 1)).val (j : ℝ≥0) ω‖ := by + have hcoe : ((V a - V (a + 1)).val : SimpleProcess ℝ (natFiltration hBmeas)) + = (V a).val - (V (a + 1)).val := rfl + rw [show itoSimpleProcess hBmeas (V a).val t ω - itoSimpleProcess hBmeas (V (a + 1)).val t ω + = itoSimpleProcess hBmeas (V a - V (a + 1)).val t ω from by + rw [hcoe]; exact (congrFun (itoSimpleProcess_sub hBmeas (V a).val (V (a + 1)).val t) ω).symm] + exact norm_le_iSup_Iic T hBmeas hBcont (V a - V (a + 1)).val ω ht + +/-- **Pathwise continuity (the rest of Task 6).** For almost every `ω`, the pathwise limit +`t ↦ itoContinuousMod φ t ω` is continuous on `[0,T]`. The approximating continuous paths +`(Vₙ ● B)_· ω` (B3) converge to it *uniformly* on `[0,T]`: the running max gives +`‖itoContinuousMod φ t ω − (Vₙ ● B)_t ω‖ ≤ 4·(3/4)ⁿ` for all `t ≤ T` once `n` is large (geometric +tail of the consecutive differences, uniform in `t`). A uniform limit of continuous functions is +continuous. -/ +theorem itoContinuousMod_continuousOn (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ∀ᵐ ω ∂μ, ContinuousOn (fun t ↦ itoContinuousMod T hBmeas φ t ω) (Set.Icc 0 T) := by + set V := (approxSeq T hBmeas φ).choose with hVdef + have hV := (approxSeq T hBmeas φ).choose_spec + filter_upwards [ae_eventually_sup_lt hB T hBmeas hBcont φ V hV, + itoContinuousMod_tendsto hB T hBmeas hBcont φ] with ω hω htends + rw [show (Set.Icc 0 T : Set ℝ≥0) = Set.Iic T from by + ext x; simp only [Set.mem_Icc, Set.mem_Iic, zero_le, true_and]] + obtain ⟨N, hN⟩ := eventually_atTop.mp hω + have huniform : TendstoUniformlyOn (fun n t ↦ itoSimpleProcess hBmeas (V n).val t ω) + (fun t ↦ itoContinuousMod T hBmeas φ t ω) atTop (Set.Iic T) := by + rw [Metric.tendstoUniformlyOn_iff] + intro ε hε + have htend0 : Tendsto (fun n ↦ 4 * (3 / 4 : ℝ) ^ n) atTop (𝓝 0) := by + rw [show (0 : ℝ) = 4 * 0 from by ring] + exact (tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num) (by norm_num)).const_mul 4 + filter_upwards [eventually_ge_atTop N, htend0.eventually_lt_const hε] with n hn hnε + intro t ht + rw [Set.mem_Iic] at ht + rw [dist_comm] + -- the uniform bound: dist (fₙ t ω) (X t ω) ≤ 4·(3/4)ⁿ + have htendsto : Tendsto (fun k ↦ itoSimpleProcess hBmeas (V (k + n)).val t ω) atTop + (𝓝 (itoContinuousMod T hBmeas φ t ω)) := (htends t ht).comp (tendsto_add_atTop_nat n) + have hstep : ∀ k, dist (itoSimpleProcess hBmeas (V (k + n)).val t ω) + (itoSimpleProcess hBmeas (V (k + 1 + n)).val t ω) ≤ (3 / 4 : ℝ) ^ n * (3 / 4 : ℝ) ^ k := by + intro k + rw [show k + 1 + n = (k + n) + 1 from by ring, dist_eq_norm] + refine (consecutive_norm_le T hBmeas hBcont V ω ht (k + n)).trans ?_ + exact (hN (k + n) (hn.trans (Nat.le_add_left n k))).le.trans + (le_of_eq (by rw [pow_add]; ring)) + have h0 := + dist_le_of_le_geometric_of_tendsto₀ (3 / 4) ((3 / 4 : ℝ) ^ n) (by norm_num) hstep htendsto + simp only [zero_add] at h0 + refine lt_of_le_of_lt (h0.trans (le_of_eq ?_)) hnε + rw [show (1 : ℝ) - 3 / 4 = 1 / 4 from by norm_num]; ring + have hcont : ∀ᶠ n in atTop, + ContinuousOn (fun t ↦ itoSimpleProcess hBmeas (V n).val t ω) (Set.Iic T) := + Eventually.of_forall fun n ↦ + (itoSimpleProcess_pathContinuous hBmeas hBcont (V n).val ω).continuousOn + exact huniform.continuousOn hcont.frequently + +/-! ## Phase 4 — the headline existence theorem (the gate) -/ + +/-- **The continuous modification of the general-integrand Itô process on `[0,T]` +exists (the gate).** There is a process `X : ℝ≥0 → Ω → ℝ` that (i) agrees almost +everywhere with the `L²` process value `itoProcessCLM T t φ` at every `t ≤ T` — a +**modification** — and (ii) has almost-surely continuous paths on `[0,T]`. This is +the first pathwise-regularity result for the general integrand, and the +localization gateway for the unbounded-coefficient Itô calculus. -/ +theorem exists_continuous_modification_itoProcess (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ∃ X : ℝ≥0 → Ω → ℝ, + (∀ t, t ≤ T → X t =ᵐ[μ] itoProcessCLM hB T t hBmeas φ) ∧ + (∀ᵐ ω ∂μ, ContinuousOn (fun t ↦ X t ω) (Set.Icc 0 T)) := + ⟨itoContinuousMod T hBmeas φ, + fun _ ht ↦ itoContinuousMod_modification hB T hBmeas hBcont φ ht, + itoContinuousMod_continuousOn hB T hBmeas hBcont φ⟩ + +end ItoIntegralProcessContinuousModification +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessGeneral.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessGeneral.lean new file mode 100644 index 0000000000..4bf49731a3 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessGeneral.lean @@ -0,0 +1,237 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralCLM +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessL2Inf + +/-! # The general-integrand Itô integral as an L² martingale on `[0,T]` (B1b) + +B1a built the simple-integrand Itô integral `t ↦ (V●B)_t` as a continuous L² +martingale. This file extends it to a **general** predictable integrand +`φ ∈ Lp ℝ 2 (trimMeasure T)` (= Degenne's `L2Predictable` on `[0,T]`): the process +`t ↦ (φ●B)_t := ∫₀ᵗ φ dB` is an L² martingale (a.e.-adapted; no path continuity is claimed +here), with the Itô contraction `‖(φ●B)_t‖ ≤ ‖φ‖` and the terminal Itô isometry +`‖(φ●B)_T‖ = ‖φ‖`. The explicit time-indexed isometry +`E[(φ●B)_t²] = ∫₀ᵗ E[φ_s²] ds` is proved in the companion module +`ItoIntegralProcessIsometry` (`itoProcessCLM_norm_sq`), by density-transferring the +band-restricted simple-process isometry against a band-truncation CLM. + +The process is *defined* as the infinite-horizon process `itoProcessL2Inf` +(`ItoIntegralProcessL2Inf`) composed with `bandExtend`, i.e. as the `𝓕_t`-conditional-expectation +projection (`condExpL2`) of the terminal integral `itoIntegralCLM`; its martingale property, +adaptedness and the contraction `‖(φ●B)_t‖ ≤ ‖φ‖` are those of the infinite-horizon engine, proved +there once. The bridge to B1a's simple-integrand process (`itoProcessCLM_simpleAssemblyHorizon`) is +B1a's martingale property. + +## Main definitions + +* `itoProcessCLM`: the Itô integral process `(φ●B)_t = ∫₀ᵗ φ dB` on `[0,T]`, the `𝓕_t` + conditional-expectation projection (`condExpL2`) of the terminal integral `itoIntegralCLM`. + +## Main results + +* `itoProcessCLM_simpleAssemblyHorizon` — the bridge back to B1a. +* `itoProcessCLM_zero_time` — the process starts at `0` (inherited from the infinite-horizon + engine, `itoProcessL2Inf_zero_time`). +* `itoProcessCLM_eq_condExpL2` — **the key identity** (by definition): `(φ●B)_t` is the + `𝓕_t`-projection of the terminal integral. +* `itoProcessCLM_aeStronglyMeasurable`, `itoIntegralProcessGen_isMartingale` — its two + corollaries: a.e.-adaptedness and the martingale property. +* `itoProcessCLM_norm_le` — the contraction `‖(φ●B)_t‖ ≤ ‖φ‖`. +* `itoProcessCLM_terminal_eq`, `itoProcessCLM_norm_terminal` — at the horizon the process is + the terminal integral, so the contraction is the Itô isometry. +* `integral_itoIntegralCLM` — the terminal integral is centered. +* `itoIntegralProcessGen_l2_continuous` — `t ↦ (φ●B)_t` is `L²`-continuous. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Ch 7 + +## Tags + +Itô integral process, L² martingale, Itô isometry, stochastic integral, predictable integrand, +conditional expectation, MSC 60H05, MSC 60G44 +-/ + +@[expose] public section + +namespace MathFin +namespace ItoIntegralProcessGeneral + +open MeasureTheory ProbabilityTheory +open ItoIntegralL2 ItoIntegralCLM ItoIntegralProcess ItoIntegralProcessL2Infinite +open scoped NNReal ENNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) + +include hB + +/-- **The Itô integral process on `[0,T]`**: the `𝓕_t`-conditional-expectation projection +(`condExpL2`) of the terminal integral `itoIntegralCLM`. For `φ ∈ L²(predictable, [0,T])`, this +is `∫₀ᵗ φ dB ∈ L²(μ)`; it is the band restriction `itoProcessL2Inf t ∘ bandExtend T` of the +infinite-horizon process. -/ +noncomputable def itoProcessCLM (T t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) : + Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) →L[ℝ] Lp ℝ 2 μ := + (itoProcessL2Inf hB t hBmeas).comp (bandExtend T hBmeas).toContinuousLinearMap + +/-- **The key identity.** The general Itô integral at time `t` is the +conditional-expectation projection of its terminal value `∫₀ᵀ φ dB` onto `𝓕_t`: +`(φ●B)_t = condExpL2 𝓕_t (itoIntegralCLM T φ)`. Adaptedness and the martingale +property are corollaries. -/ +theorem itoProcessCLM_eq_condExpL2 (T t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + itoProcessCLM hB T t hBmeas φ + = (condExpL2 ℝ ℝ ((natFiltration hBmeas).le t) + (itoIntegralCLM hB T hBmeas φ) : Lp ℝ 2 μ) := + rfl + +/-- **The bridge to B1a.** On the embedding of a `T`-bounded simple process, the general CLM +reproduces B1a's t-process `(V●B)_t`: on simple processes the terminal integral is `itoSimple V` +and B1a's martingale reads `μ[itoSimple V | 𝓕_t] = (V●B)_t`. -/ +theorem itoProcessCLM_simpleAssemblyHorizon (T t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (V : TBoundedSP T hBmeas) : + itoProcessCLM hB T t hBmeas (simpleAssemblyHorizon (μ := μ) T hBmeas V) + = itoSimpleProcessLp hB hBmeas V.val t := by + rw [itoProcessCLM_eq_condExpL2, itoIntegralCLM_simpleAssemblyHorizon] + refine Lp.ext ?_ + simp only [itoSimpleProcessLp, itoSimpleLp] + filter_upwards [(memLp_itoSimpleProcess hB hBmeas V.val t).coeFn_toLp, + (memLp_itoSimple hB hBmeas V.val).condExpL2_ae_eq_condExp (𝕜 := ℝ) + ((natFiltration hBmeas).le t), + condExp_itoSimple_eq hB T t hBmeas V.val V.property] with ω hω1 hω2 hω3 + rw [hω2, hω3, hω1] + +/-- **The Itô integral process starts at zero**: it is the infinite-horizon process, which does +(`itoProcessL2Inf_zero_time`), at the band extension of the integrand. -/ +@[simp] theorem itoProcessCLM_zero_time (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + itoProcessCLM hB T 0 hBmeas φ = 0 := + itoProcessL2Inf_zero_time hB hBmeas _ + +/-- **a.e.-adaptedness.** `(φ●B)_t` is a.e. `𝓕_t`-measurable: it is the `condExpL2` +projection onto the `𝓕_t`-measurable subspace (`itoProcessL2Inf_aeStronglyMeasurable`). -/ +theorem itoProcessCLM_aeStronglyMeasurable (T t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + AEStronglyMeasurable[natFiltration hBmeas t] + (itoProcessCLM hB T t hBmeas φ : Ω → ℝ) μ := + itoProcessL2Inf_aeStronglyMeasurable hB t hBmeas (bandExtend T hBmeas φ) + +/-- **The general Itô integral is an L² martingale (B1b).** For `i ≤ j`, +`μ[(φ●B)_j | 𝓕_i] =ᵐ (φ●B)_i`: the martingale property of the infinite-horizon process +(`itoProcessL2Inf_isMartingale`), the conditional-expectation tower for `∫₀ᵀ φ dB`. -/ +theorem itoIntegralProcessGen_isMartingale (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) {i j : ℝ≥0} (hij : i ≤ j) : + μ[(itoProcessCLM hB T j hBmeas φ : Ω → ℝ) | natFiltration hBmeas i] + =ᵐ[μ] (itoProcessCLM hB T i hBmeas φ : Ω → ℝ) := + itoProcessL2Inf_isMartingale hB hBmeas (bandExtend T hBmeas φ) hij + +/-- **The Itô-isometry contraction.** `‖(φ●B)_t‖ ≤ ‖φ‖`: conditional expectation is an L² +contraction (`itoProcessL2Inf_norm_le`) and `bandExtend` is an isometry. -/ +theorem itoProcessCLM_norm_le (T t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ‖itoProcessCLM hB T t hBmeas φ‖ ≤ ‖φ‖ := + (itoProcessL2Inf_norm_le hB t hBmeas (bandExtend T hBmeas φ)).trans_eq + (LinearIsometry.norm_map _ _) + +/-- **At the terminal time the process is the terminal integral.** `(φ●B)_T = itoIntegralCLM φ` +as `Lp` elements: both are continuous-linear in `φ` and reproduce `itoSimple V` on the dense +simple processes (`(V●B)_T = itoSimple V`). -/ +theorem itoProcessCLM_terminal_eq (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + itoProcessCLM hB T T hBmeas φ = itoIntegralCLM hB T hBmeas φ := + congrFun (DenseRange.equalizer (simpleAssemblyHorizon_denseRange (μ := μ) T hBmeas) + (itoProcessCLM hB T T hBmeas).continuous (itoIntegralCLM hB T hBmeas).continuous + (funext fun V ↦ by + simp only [Function.comp_apply, itoProcessCLM_simpleAssemblyHorizon, + itoIntegralCLM_simpleAssemblyHorizon, itoSimpleProcessLp, itoSimpleLp, + itoSimpleProcess_eq_itoSimple hBmeas V.val (fun p hp ↦ V.property p hp)])) φ + +/-- **Terminal Itô isometry.** At the horizon the process is the terminal integral +(`itoProcessCLM_terminal_eq`), so `‖(φ●B)_T‖ = ‖φ‖` exactly. -/ +theorem itoProcessCLM_norm_terminal (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ‖itoProcessCLM hB T T hBmeas φ‖ = ‖φ‖ := by + rw [itoProcessCLM_terminal_eq hB T hBmeas φ, itoIntegralCLM_norm hB T hBmeas φ] + +/-- **The Itô integral is centered**, `𝔼[∫₀ᵀ φ dB] = 0`: the integral process is a +martingale started at `0`, and conditioning preserves the mean. -/ +theorem integral_itoIntegralCLM (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ∫ ω, itoIntegralCLM hB T hBmeas φ ω ∂μ = 0 := by + have hmart := itoIntegralProcessGen_isMartingale hB T hBmeas φ (i := 0) (j := T) zero_le + rw [itoProcessCLM_zero_time hB T hBmeas φ] at hmart + rw [← itoProcessCLM_terminal_eq hB T hBmeas φ, + ← integral_condExp ((natFiltration hBmeas).le 0), integral_congr_ae hmart] + simp + +/-- **L²-continuity.** `t ↦ (φ●B)_t` is continuous into `Lp ℝ 2 μ`. The simple- +process integrals `t ↦ (Vₙ●B)_t` (continuous by B1a's +`itoSimpleProcessLp_l2_continuous`) approximate it *uniformly in `t`* — the +contraction `‖(φ●B)_t − (Vₙ●B)_t‖ ≤ ‖φ − Vₙ‖` is `t`-free — so the limit is +continuous (`TendstoUniformly.continuous`). -/ +theorem itoIntegralProcessGen_l2_continuous (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + Continuous (fun t ↦ itoProcessCLM hB T t hBmeas φ) := by + -- approximate `φ` by a sequence of simple-process embeddings (dense range). + obtain ⟨g, hg_range, hg_lim⟩ := mem_closure_iff_seq_limit.mp + ((simpleAssemblyHorizon_denseRange (μ := μ) T hBmeas).closure_range.ge (Set.mem_univ φ)) + choose V hV using hg_range + -- each approximant's process is continuous in `t` (bridge to B1a's continuity). + have hcont_n : ∀ n, Continuous (fun t ↦ itoProcessCLM hB T t hBmeas (g n)) := fun n ↦ by + simp only [← hV n, itoProcessCLM_simpleAssemblyHorizon] + exact itoSimpleProcessLp_l2_continuous hB hBmeas (V n).val + -- uniform convergence: `dist ≤ ‖φ − gₙ‖ → 0`, independent of `t`. + have huniform : TendstoUniformly (fun n t ↦ itoProcessCLM hB T t hBmeas (g n)) + (fun t ↦ itoProcessCLM hB T t hBmeas φ) Filter.atTop := by + rw [Metric.tendstoUniformly_iff] + intro ε hε + have hnorm_lim : Filter.Tendsto (fun n ↦ ‖φ - g n‖) Filter.atTop (nhds 0) := by + have := (tendsto_const_nhds (x := φ)).sub hg_lim + simpa using this.norm + filter_upwards [hnorm_lim.eventually (eventually_lt_nhds hε)] with n hn t + rw [dist_eq_norm, ← map_sub] + exact lt_of_le_of_lt (itoProcessCLM_norm_le hB T t hBmeas (φ - g n)) hn + exact huniform.continuous (Filter.Eventually.of_forall hcont_n).frequently + +omit hB [IsProbabilityMeasure μ] in +/-- **A `timeMeasure` integral over `(0, T]` is an interval integral over `[0, T]`.** For every +`g : ℝ≥0 → ℝ`, `∫ s in Ioc 0 T, g s ∂timeMeasure = ∫ x in 0..T, g x.toNNReal`. Since +`timeMeasure = Measure.comap ((↑) : ℝ≥0 → ℝ) volume`, this is a change of variables along the +coercion (`MeasurableEmbedding.restrict_comap`, `.map_comap`, `.integral_map`) followed by +`intervalIntegral.integral_of_le`, so it needs no measurability or integrability hypothesis. -/ +theorem timeMeasure_Ioc_eq_interval {g : ℝ≥0 → ℝ} (T : ℝ≥0) : + ∫ s in Set.Ioc 0 T, g s ∂timeMeasure = ∫ x in (0)..(T : ℝ), g (Real.toNNReal x) := by + have himg : ((↑) : ℝ≥0 → ℝ) '' Set.Ioc 0 T = Set.Ioc 0 (T : ℝ) := by + ext x + simp only [Set.mem_image, Set.mem_Ioc] + constructor + · rintro ⟨y, ⟨hy1, hy2⟩, rfl⟩ + exact ⟨mod_cast hy1, mod_cast hy2⟩ + · rintro ⟨hx1, hx2⟩ + have hy : (Real.toNNReal x : ℝ) = x := Real.coe_toNNReal x hx1.le + exact ⟨Real.toNNReal x, ⟨Real.toNNReal_pos.2 hx1, NNReal.coe_le_coe.1 (hy.trans_le hx2)⟩, hy⟩ + have hmap : Measure.map ((↑) : ℝ≥0 → ℝ) (timeMeasure.restrict (Set.Ioc 0 T)) + = volume.restrict (((↑) : ℝ≥0 → ℝ) '' Set.Ioc 0 T) := by + rw [timeMeasure, MeasurableEmbedding.restrict_comap measurableEmbedding_nnrealCoe, + MeasurableEmbedding.map_comap measurableEmbedding_nnrealCoe, + Measure.restrict_restrict measurableEmbedding_nnrealCoe.measurableSet_range, + Set.inter_eq_right.2 (Set.image_subset_range _ _)] + calc ∫ s in Set.Ioc 0 T, g s ∂timeMeasure + = ∫ x, g (Real.toNNReal x) ∂(timeMeasure.restrict (Set.Ioc 0 T)) := + integral_congr_ae (.of_forall fun x ↦ by simp only [Real.toNNReal_coe]) + _ = ∫ y, g (Real.toNNReal y) ∂(Measure.map ((↑) : ℝ≥0 → ℝ) + (timeMeasure.restrict (Set.Ioc 0 T))) := + (measurableEmbedding_nnrealCoe.integral_map fun y : ℝ ↦ g (Real.toNNReal y)).symm + _ = ∫ x in Set.Ioc 0 (T : ℝ), g (Real.toNNReal x) := by rw [hmap, himg] + _ = ∫ x in (0)..(T : ℝ), g (Real.toNNReal x) := + (intervalIntegral.integral_of_le (NNReal.coe_nonneg T)).symm + +end ItoIntegralProcessGeneral +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessIsometry.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessIsometry.lean new file mode 100644 index 0000000000..2beb22aeb1 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessIsometry.lean @@ -0,0 +1,376 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessGeneral +public import Mathlib.Probability.CondVar + +/-! # The time-indexed Itô isometry for the general Itô integral (B1b) + +B1b built the general Itô integral `(φ●B)_t = ∫₀ᵗ φ dB` and proved it a continuous +L² martingale, with the contraction `‖(φ●B)_t‖ ≤ ‖φ‖` and the terminal isometry +`‖(φ●B)_T‖ = ‖φ‖`. This file proves the **explicit time-indexed Itô isometry** + +`E[(φ●B)_t²] = ∫_{(0,t]×Ω} φ² d(trimMeasure T)` (= `∫₀ᵗ E[φ_s²] ds`), + +the L²-energy law that B1b deferred. On a simple process `V` the LHS is B1a's +`itoSimpleProcess_isometry_time` (the t-capped predictable-rectangle double sum); +the RHS is the same double sum, via a **band-restricted** version of +`ItoIntegralL2.integral_rectTerm_mul` (the time integral picks up an `∩ (0,t]`). +The general case follows by density. + +## Main results + +* `itoProcessCLM_norm_sq`: for `t ≤ T` and a predictable `φ ∈ L²([0,T])`, + `E[(φ●B)_t²] = ∫_{(0,t]×Ω} φ² d(trimMeasure T)`. +* `setIntegral_Ioc_prod_add`: the band integral of an integrable space-time function is additive + over adjacent time bands. +* `clm_band_energy`: for `u ≤ v ≤ T`, `𝔼[((φ●B)_v − (φ●B)_u)²]` is the band energy + `∫_{(u,v]×Ω} φ² d(trimMeasure T)`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Ch 7 + +## Tags + +time-indexed Itô isometry, Itô isometry, energy identity, stochastic integral, L² martingale, +MSC 60H05, MSC 60G44 +-/ + +@[expose] public section + +namespace MathFin +namespace ItoIntegralProcessGeneral + +open MeasureTheory ProbabilityTheory ItoIntegralL2 ItoIntegralCLM ItoIntegralProcess +open scoped NNReal ENNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) + +include hB + +omit [IsProbabilityMeasure μ] in +/-- **Band-restricted rectangle cross-integral.** The `ItoIntegralL2.integral_rectTerm_mul` +identity with the time integral restricted to `(0,t]`: the overlap factor gains an +`∩ (0,t]`, capping the right endpoint at `t`. (Fubini over the restricted product +`(timeMeasure.restrict (Ioc 0 t)) ⊗ μ`, then `timeMeasure` of the triple interval +intersection.) -/ +private lemma integral_rectTerm_mul_band (t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (V : SimpleProcess ℝ (natFiltration hBmeas)) (p q : ℝ≥0 × ℝ≥0) : + ∫ z in (Set.Ioc 0 t ×ˢ (Set.univ : Set Ω)), + rectTerm hBmeas V p z * rectTerm hBmeas V q z ∂(timeMeasure.prod μ) + = (∫ ω, V.value p ω * V.value q ω ∂μ) + * max 0 ((min (min (p.2 : ℝ) q.2) (t : ℝ)) - (max (p.1 : ℝ) q.1)) := by + have : IsProbabilityMeasure μ := hB.isGaussianProcess.isProbabilityMeasure + have hfun : (fun z : ℝ≥0 × Ω ↦ rectTerm hBmeas V p z * rectTerm hBmeas V q z) + = fun z ↦ ((Set.Ioc p.1 p.2).indicator (fun _ ↦ (1 : ℝ)) z.1 + * (Set.Ioc q.1 q.2).indicator (fun _ ↦ (1 : ℝ)) z.1) + * (V.value p z.2 * V.value q z.2) := by + funext z; simp only [rectTerm, elemIntegrand]; ring + rw [setIntegral_congr_fun (measurableSet_Ioc.prod MeasurableSet.univ) + (fun z _ ↦ congrFun hfun z), + ← Measure.restrict_prod_eq_prod_univ, + integral_prod_mul + (fun i : ℝ≥0 ↦ (Set.Ioc p.1 p.2).indicator (fun _ ↦ (1 : ℝ)) i + * (Set.Ioc q.1 q.2).indicator (fun _ ↦ (1 : ℝ)) i) + (fun ω ↦ V.value p ω * V.value q ω), mul_comm] + congr 1 + have hpt : ∀ i : ℝ≥0, (Set.Ioc p.1 p.2).indicator (fun _ ↦ (1 : ℝ)) i + * (Set.Ioc q.1 q.2).indicator (fun _ ↦ (1 : ℝ)) i + = (Set.Ioc p.1 p.2 ∩ Set.Ioc q.1 q.2).indicator (1 : ℝ≥0 → ℝ) i := by + intro i; rw [Set.inter_indicator_one]; rfl + simp_rw [hpt] + rw [integral_indicator_one (measurableSet_Ioc.inter measurableSet_Ioc), Measure.real_def, + Measure.restrict_apply (measurableSet_Ioc.inter measurableSet_Ioc), + Set.Ioc_inter_Ioc, Set.Ioc_inter_Ioc, timeMeasure_Ioc, ENNReal.toReal_ofReal'] + push_cast + rw [max_eq_left (le_max_of_le_left (by positivity))] + exact max_comm _ _ + +omit hB in +/-- **Band-overlap reconciliation (pure ℝ).** B1a's time-indexed isometry expresses the +overlap of two predictable rectangles as `max 0 (min(p.2∧t, q.2∧t) − max(p.1∧t, q.1∧t))` +(each endpoint individually truncated at `t`), whereas the band-restricted cross-integral +(`integral_rectTerm_mul_band`) produces `max 0 (min(p.2∧q.2, t) − max(p.1, q.1))` (the joint +overlap intersected with `(0,t]`). These are equal: both measure the length of +`(p.1,p.2] ∩ (q.1,q.2] ∩ (0,t]`. When the joint overlap is nonempty its left endpoint +`max p.1 q.1 < t`, so the individual `∧t`-truncations on the left are inert; when empty, +both clamp to `0`. -/ +lemma band_overlap_real (P1 P2 Q1 Q2 T : ℝ) : + max 0 (min (min P2 T) (min Q2 T) - max (min P1 T) (min Q1 T)) + = max 0 (min (min P2 Q2) T - max P1 Q1) := by + -- The right endpoints coincide unconditionally: `(P2∧T)∧(Q2∧T) = (P2∧Q2)∧T`. + have hR : min (min P2 T) (min Q2 T) = min (min P2 Q2) T := by + rw [min_min_min_comm, min_self] + rw [hR] + rcases le_total (max P1 Q1) T with hLT | hLT + · -- Overlap can be nonempty: the left `∧t`-truncations are inert. + rw [min_eq_left ((le_max_left P1 Q1).trans hLT), + min_eq_left ((le_max_right P1 Q1).trans hLT)] + · -- `max P1 Q1 ≥ T ≥` right endpoint: both differences are `≤ 0`, both clamp to `0`. + have hRle : min (min P2 Q2) T ≤ T := min_le_right _ _ + have hL : max (min P1 T) (min Q1 T) = T := by + apply le_antisymm (max_le (min_le_right _ _) (min_le_right _ _)) + rcases le_total P1 Q1 with h | h + · rw [max_eq_right h] at hLT; exact le_max_of_le_right (le_min hLT le_rfl) + · rw [max_eq_left h] at hLT; exact le_max_of_le_left (le_min hLT le_rfl) + rw [hL, max_eq_left (by linarith : min (min P2 Q2) T - T ≤ 0), + max_eq_left (by linarith : min (min P2 Q2) T - max P1 Q1 ≤ 0)] + +omit hB in +/-- **Restricting the horizon-`T` predictable measure to the `(0,t]` band gives the +horizon-`t` measure** (for `t ≤ T`). Both are restrictions of the same full predictable +trim; `band_t ∩ band_T = band_t`. This lets the time-indexed energy +`∫_{(0,t]} · d(trimMeasure T)` collapse to a plain integral against `trimMeasure t`. -/ +private lemma trimMeasure_restrict_band {t T : ℝ≥0} (htT : t ≤ T) + (hBmeas : ∀ u, Measurable (B u)) : + (trimMeasure (μ := μ) T hBmeas).restrict (Set.Ioc 0 t ×ˢ (Set.univ : Set Ω)) + = trimMeasure (μ := μ) t hBmeas := by + rw [trimMeasure_eq_restrict T hBmeas, + Measure.restrict_restrict_of_subset + (Set.prod_mono (Set.Ioc_subset_Ioc le_rfl htT) subset_rfl), + trimMeasure_eq_restrict t hBmeas] + +omit hB in +/-- **Dropping the horizon-`t` predictable trim** to the untrimmed product over the +`(0,t]` band. `trimMeasure t = ((timeMeasure.restrict (0,t]) ⊗ μ).trim`; `integral_trim` +removes the trim (legal for predictable-strongly-measurable `f`) and +`Measure.restrict_prod_eq_prod_univ` moves the time-restriction out to a band on the +product. -/ +private lemma integral_trimMeasure {t : ℝ≥0} (hBmeas : ∀ u, Measurable (B u)) + {f : ℝ≥0 × Ω → ℝ} + (hf : StronglyMeasurable[(natFiltration hBmeas).predictable] f) : + ∫ z, f z ∂(trimMeasure (μ := μ) t hBmeas) + = ∫ z in (Set.Ioc 0 t ×ˢ (Set.univ : Set Ω)), f z ∂(timeMeasure.prod μ) := by + rw [show trimMeasure (μ := μ) t hBmeas + = ((timeMeasureHorizon t).prod μ).trim (natFiltration hBmeas).predictable_le_prod from rfl, + integral_trim (natFiltration hBmeas).predictable_le_prod hf, + show ((timeMeasureHorizon t).prod μ : Measure (ℝ≥0 × Ω)) + = (timeMeasure.prod μ).restrict (Set.Ioc 0 t ×ˢ (Set.univ : Set Ω)) from by + rw [timeMeasureHorizon, Measure.restrict_prod_eq_prod_univ]] + +omit [IsProbabilityMeasure μ] in +/-- **Time-indexed energy of a simple process (RHS form).** For `t ≤ T`, the +predictable `L²`-energy of `uncurry V` over the `(0,t]` band equals the truncated +predictable-rectangle double sum: collapse band+trim to the horizon-`t` measure +(`trimMeasure_restrict_band`), drop the trim (`integral_trimMeasure`), then expand the +square and Fubini-factorise each cross-term (`integral_rectTerm_mul_band`). Mirrors +`ItoIntegralL2.simpleProcessL2_norm_sq` with the band cap. -/ +private lemma band_integral_uncurry_sq {t T : ℝ≥0} (htT : t ≤ T) + (hBmeas : ∀ u, Measurable (B u)) (V : SimpleProcess ℝ (natFiltration hBmeas)) : + ∫ z in (Set.Ioc 0 t ×ˢ (Set.univ : Set Ω)), + (Function.uncurry ⇑V z) ^ 2 ∂(trimMeasure (μ := μ) T hBmeas) + = ∑ p ∈ V.value.support, ∑ q ∈ V.value.support, + (∫ ω, V.value p ω * V.value q ω ∂μ) + * max 0 ((min (min (p.2 : ℝ) q.2) (t : ℝ)) - max (p.1 : ℝ) q.1) := by + have : IsProbabilityMeasure μ := hB.isGaussianProcess.isProbabilityMeasure + -- (A) collapse band+trim to the horizon-`t` measure, then drop the trim. + rw [trimMeasure_restrict_band htT] + simp only [pow_two] + have hsm : StronglyMeasurable[(natFiltration hBmeas).predictable] + (fun z ↦ Function.uncurry ⇑V z * Function.uncurry ⇑V z) := + V.isStronglyPredictable.mul V.isStronglyPredictable + rw [integral_trimMeasure hBmeas hsm] + -- (B) expand the square into the rectangle double sum and integrate termwise. + have hint : ∀ p ∈ V.value.support, ∀ q ∈ V.value.support, + Integrable (fun z ↦ rectTerm hBmeas V p z * rectTerm hBmeas V q z) (timeMeasure.prod μ) := + fun p _ q _ ↦ (memLp_rectTerm hBmeas V p).integrable_mul (memLp_rectTerm hBmeas V q) + have hsq : (fun z ↦ Function.uncurry ⇑V z * Function.uncurry ⇑V z) + =ᵐ[(timeMeasure.prod μ).restrict (Set.Ioc 0 t ×ˢ (Set.univ : Set Ω))] + fun z ↦ ∑ p ∈ V.value.support, ∑ q ∈ V.value.support, + rectTerm hBmeas V p z * rectTerm hBmeas V q z := by + filter_upwards [ae_restrict_of_ae (uncurry_ae_eq_sum_rectTerm hBmeas V)] with z hz + rw [hz, Finset.sum_mul_sum] + rw [integral_congr_ae hsq, + integral_finsetSum _ (fun p hp ↦ + (integrable_finsetSum _ fun q hq ↦ hint p hp q hq).integrableOn)] + refine Finset.sum_congr rfl fun p hp ↦ ?_ + rw [integral_finsetSum _ fun q hq ↦ (hint p hp q hq).integrableOn] + exact Finset.sum_congr rfl fun q _ ↦ integral_rectTerm_mul_band hB t hBmeas V p q + +omit [IsProbabilityMeasure μ] in +/-- **Time-indexed Itô isometry on a simple process.** `‖(V●B)_t‖² = ∫_{(0,t]×Ω}(uncurry V)²` +for `t ≤ T`: the LHS is B1a's `itoSimpleProcess_isometry_time` (the per-endpoint +`∧t`-truncated predictable-rectangle double sum); the RHS is `band_integral_uncurry_sq` +(the joint-overlap-`∩(0,t]` double sum); the two overlap forms agree pointwise by +`band_overlap_real`. -/ +private lemma itoSimpleProcessLp_band_isometry {t T : ℝ≥0} (htT : t ≤ T) + (hBmeas : ∀ u, Measurable (B u)) (V : SimpleProcess ℝ (natFiltration hBmeas)) : + ‖itoSimpleProcessLp (μ := μ) hB hBmeas V t‖ ^ 2 + = ∫ z in (Set.Ioc 0 t ×ˢ (Set.univ : Set Ω)), + (Function.uncurry ⇑V z) ^ 2 ∂(trimMeasure (μ := μ) T hBmeas) := by + rw [band_integral_uncurry_sq hB htT hBmeas V] + have hLHS : ‖itoSimpleProcessLp (μ := μ) hB hBmeas V t‖ ^ 2 + = ∫ ω, (itoSimpleProcess hBmeas V t ω) ^ 2 ∂μ := by + rw [lp_two_norm_sq (itoSimpleProcessLp hB hBmeas V t)] + refine integral_congr_ae ?_ + filter_upwards [(memLp_itoSimpleProcess hB hBmeas V t).coeFn_toLp] with ω hω + rw [show (itoSimpleProcessLp hB hBmeas V t : Ω → ℝ) ω = itoSimpleProcess hBmeas V t ω from hω] + rw [hLHS, itoSimpleProcess_isometry_time hB hBmeas V t] + refine Finset.sum_congr rfl fun p _ ↦ Finset.sum_congr rfl fun q _ ↦ ?_ + congr 1 + push_cast + exact band_overlap_real _ _ _ _ _ + +omit hB in +/-- `(0,t]×Ω` is measurable for the predictable σ-algebra carried by `trimMeasure`. -/ +lemma measurableSet_band (t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) : + MeasurableSet[(natFiltration hBmeas).predictable] (Set.Ioc 0 t ×ˢ (Set.univ : Set Ω)) := + MeasureTheory.measurableSet_predictable_Ioc_prod (𝓕 := natFiltration hBmeas) 0 t + MeasurableSet.univ + +omit [IsProbabilityMeasure μ] hB in +/-- Truncation to the `(0,t]`-band keeps `L²`. -/ +private lemma memLp_truncBand (T t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + MemLp ((Set.Ioc 0 t ×ˢ (Set.univ : Set Ω)).indicator (φ : ℝ≥0 × Ω → ℝ)) 2 + (trimMeasure (μ := μ) T hBmeas) := + (Lp.memLp φ).indicator (measurableSet_band t hBmeas).nullMeasurableSet + +omit [IsProbabilityMeasure μ] hB in +/-- **Band truncation as a norm-`≤1` CLM** on the predictable `L²` space: pointwise +indicator multiplication `φ ↦ 𝟙_{(0,t]×Ω} · φ` (on `L²` this is the orthogonal projection +onto the `(0,t]`-band, but it is formalised here only as a norm-`≤1` CLM — `mkContinuous` +via `eLpNorm_indicator_le`). The general time-indexed isometry reads +`‖itoProcessCLM T t φ‖² = ‖truncCLM T t φ‖²` — both sides continuous in `φ`, equal on the +dense simple processes. -/ +private noncomputable def truncCLM (T t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) : + Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) →L[ℝ] + Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) := + LinearMap.mkContinuous + { toFun := fun φ ↦ (memLp_truncBand T t hBmeas φ).toLp + ((Set.Ioc 0 t ×ˢ (Set.univ : Set Ω)).indicator (φ : ℝ≥0 × Ω → ℝ)) + map_add' := fun φ ψ ↦ by + refine Lp.ext ?_ + filter_upwards [(memLp_truncBand T t hBmeas (φ + ψ)).coeFn_toLp, + Lp.coeFn_add ((memLp_truncBand T t hBmeas φ).toLp _) + ((memLp_truncBand T t hBmeas ψ).toLp _), + (memLp_truncBand T t hBmeas φ).coeFn_toLp, + (memLp_truncBand T t hBmeas ψ).coeFn_toLp, + Lp.coeFn_add φ ψ] with z e_sum e_radd e_φ e_ψ h_φψ + rw [e_sum, e_radd, Pi.add_apply, e_φ, e_ψ] + simp only [Set.indicator_apply, h_φψ, Pi.add_apply] + split_ifs <;> ring + map_smul' := fun c φ ↦ by + refine Lp.ext ?_ + filter_upwards [(memLp_truncBand T t hBmeas (c • φ)).coeFn_toLp, + Lp.coeFn_smul c ((memLp_truncBand T t hBmeas φ).toLp _), + (memLp_truncBand T t hBmeas φ).coeFn_toLp, + Lp.coeFn_smul c φ] with z e_sm e_rsmul e_φ h_φ + rw [e_sm, RingHom.id_apply, e_rsmul, Pi.smul_apply, e_φ] + simp only [Set.indicator_apply, h_φ, Pi.smul_apply, smul_eq_mul] + split_ifs <;> ring } + 1 (fun φ ↦ by + simp only [LinearMap.coe_mk, AddHom.coe_mk] + rw [one_mul, Lp.norm_toLp, Lp.norm_def] + exact ENNReal.toReal_mono (Lp.memLp φ).eLpNorm_ne_top + (eLpNorm_indicator_le _ (measurableSet_band t hBmeas).nullMeasurableSet)) + +omit [IsProbabilityMeasure μ] hB in +/-- **The truncation CLM realises the band energy.** `‖truncCLM T t φ‖² = ∫_{(0,t]×Ω} φ²`: +its value is `𝟙_{(0,t]} · φ`, whose squared `L²`-norm integrates `φ²` over the band. This is +the continuous RHS the general isometry equalises against. -/ +private lemma truncCLM_norm_sq (T t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ‖truncCLM (μ := μ) T t hBmeas φ‖ ^ 2 + = ∫ z in (Set.Ioc 0 t ×ˢ (Set.univ : Set Ω)), (φ z) ^ 2 + ∂(trimMeasure (μ := μ) T hBmeas) := by + rw [lp_two_norm_sq, ← integral_indicator (measurableSet_band t hBmeas)] + refine integral_congr_ae ?_ + filter_upwards [(memLp_truncBand T t hBmeas φ).coeFn_toLp] with z hz + rw [show (truncCLM (μ := μ) T t hBmeas φ : ℝ≥0 × Ω → ℝ) z + = (Set.Ioc 0 t ×ˢ (Set.univ : Set Ω)).indicator (φ : ℝ≥0 × Ω → ℝ) z from hz] + by_cases hzm : z ∈ (Set.Ioc 0 t ×ˢ (Set.univ : Set Ω)) + · rw [Set.indicator_of_mem hzm, Set.indicator_of_mem hzm] + · rw [Set.indicator_of_notMem hzm, Set.indicator_of_notMem hzm]; norm_num + +/-- **The time-indexed Itô isometry (B1b, general integrand).** For `t ≤ T` and any predictable +`φ ∈ L²([0,T])`, `E[(φ●B)_t²] = ∫_{(0,t]×Ω} φ² d(predictable measure)` (`= ∫₀ᵗ E[φ_s²] ds`). +Both `φ ↦ ‖(φ●B)_t‖²` (a CLM norm) and `φ ↦ ∫_{(0,t]} φ²` (`= ‖truncCLM T t φ‖²`) are continuous, +and they agree on the dense simple processes (`itoSimpleProcessLp_band_isometry`), so they agree +everywhere (`DenseRange.equalizer`). This is the deferred L²-energy law completing B1b's isometry +— the per-`t` refinement of the terminal `itoProcessCLM_norm_terminal`. -/ +theorem itoProcessCLM_norm_sq {t T : ℝ≥0} (htT : t ≤ T) (hBmeas : ∀ u, Measurable (B u)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ‖itoProcessCLM hB T t hBmeas φ‖ ^ 2 + = ∫ z in (Set.Ioc 0 t ×ˢ (Set.univ : Set Ω)), (φ z) ^ 2 + ∂(trimMeasure (μ := μ) T hBmeas) := by + rw [← truncCLM_norm_sq T t hBmeas φ] + refine congrFun (DenseRange.equalizer (simpleAssemblyHorizon_denseRange (μ := μ) T hBmeas) + ((continuous_pow 2).comp (itoProcessCLM hB T t hBmeas).continuous.norm) + ((continuous_pow 2).comp (truncCLM (μ := μ) T t hBmeas).continuous.norm) + (funext fun V ↦ ?_)) φ + simp only [Function.comp_apply] + rw [itoProcessCLM_simpleAssemblyHorizon, truncCLM_norm_sq, + itoSimpleProcessLp_band_isometry hB htT hBmeas V.val] + refine integral_congr_ae ?_ + filter_upwards [ae_restrict_of_ae (memLp_uncurry_trimMeasure T hBmeas V.val).coeFn_toLp] with z hz + rw [show (simpleAssemblyHorizon (μ := μ) T hBmeas V : ℝ≥0 × Ω → ℝ) z + = Function.uncurry ⇑V.val z from hz] + + +omit hB [IsProbabilityMeasure μ] in +/-- **The band integral is additive in the time band**: for an integrable space-time function the +integral over `(a,c] × Ω` of the predictable trim measure is the sum of the integrals over the +adjacent bands `(a,b] × Ω` and `(b,c] × Ω`. -/ +theorem setIntegral_Ioc_prod_add {T : ℝ≥0} (hBmeas : ∀ t, Measurable (B t)) {F : ℝ≥0 × Ω → ℝ} + (hF : Integrable F (trimMeasure (μ := μ) T hBmeas)) {a b c : ℝ≥0} (hab : a ≤ b) + (hbc : b ≤ c) : + ∫ z in Set.Ioc a c ×ˢ (Set.univ : Set Ω), F z ∂(trimMeasure (μ := μ) T hBmeas) + = ∫ z in Set.Ioc a b ×ˢ (Set.univ : Set Ω), F z ∂(trimMeasure (μ := μ) T hBmeas) + + ∫ z in Set.Ioc b c ×ˢ (Set.univ : Set Ω), F z ∂(trimMeasure (μ := μ) T hBmeas) := by + rw [← Set.Ioc_union_Ioc_eq_Ioc hab hbc, Set.union_prod] + exact setIntegral_union (Set.Disjoint.set_prod_left (Set.Ioc_disjoint_Ioc_of_le le_rfl) _ _) + (measurableSet_predictable_Ioc_prod b c MeasurableSet.univ) hF.integrableOn hF.integrableOn + +/-- **The band-energy law of the Itô integral process**: the `L²` energy of the increment of +`(φ●B)` over a band `(u,v]`, `v ≤ T`, is the band energy of the integrand, + + `𝔼[((φ●B)_v − (φ●B)_u)²] = ∫_{(u,v]×Ω} φ² d(trimMeasure T)`. + +Pythagoras for the martingale `itoProcessCLM` (`(φ●B)_u` is the conditional expectation of +`(φ●B)_v`: `condVar_ae_eq_condExp_sq_sub_sq_condExp`), then the time-indexed isometry +`itoProcessCLM_norm_sq` at `v` and at `u` and the band additivity `setIntegral_Ioc_prod_add`. -/ +theorem clm_band_energy (hBmeas : ∀ t, Measurable (B t)) {T : ℝ≥0} + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) {u v : ℝ≥0} (huv : u ≤ v) (hvT : v ≤ T) : + ∫ ω, ((itoProcessCLM hB T v hBmeas φ : Ω → ℝ) ω + - (itoProcessCLM hB T u hBmeas φ : Ω → ℝ) ω) ^ 2 ∂μ + = ∫ z in Set.Ioc u v ×ˢ (Set.univ : Set Ω), (φ z) ^ 2 + ∂(trimMeasure (μ := μ) T hBmeas) := by + set A := itoProcessCLM hB T v hBmeas φ + set b := itoProcessCLM hB T u hBmeas φ + have hm := (natFiltration hBmeas).le u + have hmart : μ[(A : Ω → ℝ) | natFiltration hBmeas u] =ᵐ[μ] (b : Ω → ℝ) := + itoIntegralProcessGen_isMartingale hB T hBmeas φ huv + have hnrm (w : ℝ≥0) (hw : w ≤ T) : ∫ ω, (itoProcessCLM hB T w hBmeas φ : Ω → ℝ) ω ^ 2 ∂μ + = ∫ z in Set.Ioc 0 w ×ˢ (Set.univ : Set Ω), (φ z) ^ 2 ∂(trimMeasure (μ := μ) T hBmeas) := + (lp_two_norm_sq _).symm.trans (itoProcessCLM_norm_sq hB hw hBmeas φ) + have hpyth : ∫ ω, ((A : Ω → ℝ) ω - μ[(A : Ω → ℝ) | natFiltration hBmeas u] ω) ^ 2 ∂μ + = ∫ ω, (A : Ω → ℝ) ω ^ 2 ∂μ - ∫ ω, μ[(A : Ω → ℝ) | natFiltration hBmeas u] ω ^ 2 ∂μ := by + have hA := Lp.memLp A + have hsq : Integrable (μ[(A : Ω → ℝ) | natFiltration hBmeas u] ^ 2) μ := + (hA.condExp one_le_two).integrable_sq + have h := integral_congr_ae (condVar_ae_eq_condExp_sq_sub_sq_condExp hm hA) + rw [condVar, integral_condExp hm, integral_sub' integrable_condExp hsq, + integral_condExp hm] at h + exact h + calc _ = ∫ ω, ((A : Ω → ℝ) ω - μ[(A : Ω → ℝ) | natFiltration hBmeas u] ω) ^ 2 ∂μ := + integral_congr_ae (by filter_upwards [hmart] with ω hω using by rw [hω]) + _ = ∫ ω, (A : Ω → ℝ) ω ^ 2 ∂μ - ∫ ω, (b : Ω → ℝ) ω ^ 2 ∂μ := by + rw [hpyth, show ∫ ω, μ[(A : Ω → ℝ) | natFiltration hBmeas u] ω ^ 2 ∂μ + = ∫ ω, (b : Ω → ℝ) ω ^ 2 ∂μ from + integral_congr_ae (by filter_upwards [hmart] with ω hω using by rw [hω])] + _ = _ := by + rw [hnrm v hvT, hnrm u (huv.trans hvT), + setIntegral_Ioc_prod_add hBmeas (Lp.memLp φ).integrable_sq zero_le huv] + ring + +end ItoIntegralProcessGeneral +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessL2Inf.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessL2Inf.lean new file mode 100644 index 0000000000..ec867eb7f8 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessL2Inf.lean @@ -0,0 +1,184 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralL2Dense +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessMartingale + +/-! +# The unbounded-horizon Itô integral as an L² process + +B2 (`ItoIntegralL2Dense`) built the **terminal** `[0,∞)` Itô integral +`itoIntegralL2 : Lp 2 trim_full →L[ℝ] Lp 2 μ` over the **horizon-independent** +predictable integrand `f` (the σ-finite completion). This file lifts it to a +**process** `itoProcessL2Inf t f := E[∫₀^∞ f dB | 𝓕_t]` — the +conditional-expectation projection of the terminal integral onto the natural +filtration `𝓕_t`. + +Because the integrand no longer depends on the horizon, the L² **martingale +property** (`itoProcessL2Inf_isMartingale`), **adaptedness** +(`itoProcessL2Inf_aeStronglyMeasurable`) and the **contraction** +(`itoProcessL2Inf_norm_le`) hold on all of `ℝ≥0` directly from the conditional-expectation +tower, once. The finite-horizon process `itoProcessCLM T t` (`ItoIntegralProcessGeneral`) is +this engine composed with `bandExtend T`, and inherits all three. + +On the dense simple integrands the process is B1a's discrete process +(`condExp_itoSimple_eq`, `condExp_itoIntegralL2_simple`, `itoProcessL2Inf_simpleAssembly_ae`), +and density transfers the start `(f●B)_0 = 0` (`itoProcessL2Inf_zero_time`). + +## Main definitions + +* `itoProcessL2Inf`: the unbounded-horizon Itô process `(f●B)_t = E[∫₀^∞ f dB | 𝓕_t]`, the + conditional-expectation projection of `itoIntegralL2 f` onto `𝓕_t`. + +## Main results + +* `itoProcessL2Inf_isMartingale`: for `i ≤ j`, `E[(f●B)_j | 𝓕_i] =ᵐ (f●B)_i`. +* `itoProcessL2Inf_aeStronglyMeasurable`: `(f●B)_t` is almost everywhere `𝓕_t`-measurable. +* `itoProcessL2Inf_norm_le`: `‖(f●B)_t‖ ≤ ‖f‖`. +* `condExp_itoSimple_eq`: for `T`-bounded `V`, `μ[itoSimple V | 𝓕_t] = (V●B)_t`. +* `itoProcessL2Inf_zero_time`: `(f●B)_0 = 0`. + +## Tags + +Itô integral process, infinite horizon, L² martingale, conditional expectation, stochastic integral, +MSC 60H05, MSC 60G44 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +namespace MathFin +namespace ItoIntegralProcessL2Infinite + +open ItoIntegralL2 ItoIntegralProcess + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) + +/-- **The unbounded-horizon Itô process** `(f●B)_t = E[∫₀^∞ f dB | 𝓕_t]`: the +conditional-expectation projection of the terminal `[0,∞)` integral `itoIntegralL2 f` +onto `𝓕_t`. The horizon-independent analogue of `itoProcessCLM`. -/ +noncomputable def itoProcessL2Inf (t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) : + Lp ℝ 2 ((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod) →L[ℝ] Lp ℝ 2 μ := + ((lpMeas ℝ ℝ (natFiltration hBmeas t) 2 μ).subtypeL.comp + (condExpL2 ℝ ℝ ((natFiltration hBmeas).le t))).comp (itoIntegralL2 hB hBmeas) + +/-- Unfold of the process to the `condExpL2` projection of the terminal integral +(coerced from the `𝓕_t`-measurable subspace into `Lp 2 μ`). -/ +lemma itoProcessL2Inf_apply (t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (f : Lp ℝ 2 ((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod)) : + itoProcessL2Inf hB t hBmeas f + = (condExpL2 ℝ ℝ ((natFiltration hBmeas).le t) (itoIntegralL2 hB hBmeas f) : Lp ℝ 2 μ) := + rfl + +/-- **The unbounded-horizon Itô process is an L² martingale.** For `i ≤ j`, +`E[(f●B)_j | 𝓕_i] =ᵐ (f●B)_i` — directly from the conditional-expectation tower, +since each value is `E[∫₀^∞ f dB | 𝓕_k]`. -/ +theorem itoProcessL2Inf_isMartingale (hBmeas : ∀ u, Measurable (B u)) + (f : Lp ℝ 2 ((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod)) {i j : ℝ≥0} (hij : i ≤ j) : + μ[(itoProcessL2Inf hB j hBmeas f : Ω → ℝ) | natFiltration hBmeas i] + =ᵐ[μ] (itoProcessL2Inf hB i hBmeas f : Ω → ℝ) := by + have hbridge : ∀ k : ℝ≥0, + (itoProcessL2Inf hB k hBmeas f : Ω → ℝ) + =ᵐ[μ] μ[(itoIntegralL2 hB hBmeas f : Ω → ℝ) | natFiltration hBmeas k] := by + intro k + rw [itoProcessL2Inf_apply] + have h := (Lp.memLp (itoIntegralL2 hB hBmeas f)).condExpL2_ae_eq_condExp + (𝕜 := ℝ) ((natFiltration hBmeas).le k) + rwa [Lp.toLp_coeFn] at h + calc μ[(itoProcessL2Inf hB j hBmeas f : Ω → ℝ) | natFiltration hBmeas i] + =ᵐ[μ] μ[μ[(itoIntegralL2 hB hBmeas f : Ω → ℝ) | natFiltration hBmeas j] + | natFiltration hBmeas i] := condExp_congr_ae (hbridge j) + _ =ᵐ[μ] μ[(itoIntegralL2 hB hBmeas f : Ω → ℝ) | natFiltration hBmeas i] := + condExp_condExp_of_le ((natFiltration hBmeas).mono hij) ((natFiltration hBmeas).le j) + _ =ᵐ[μ] (itoProcessL2Inf hB i hBmeas f : Ω → ℝ) := (hbridge i).symm + +/-- **a.e.-adaptedness.** `(f●B)_t` is a.e. `𝓕_t`-measurable: it is the `condExpL2` +projection onto the `𝓕_t`-measurable subspace. -/ +theorem itoProcessL2Inf_aeStronglyMeasurable (t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (f : Lp ℝ 2 ((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod)) : + AEStronglyMeasurable[natFiltration hBmeas t] + (itoProcessL2Inf hB t hBmeas f : Ω → ℝ) μ := by + rw [itoProcessL2Inf_apply] + exact mem_lpMeas_iff_aestronglyMeasurable.mp + (condExpL2 ℝ ℝ ((natFiltration hBmeas).le t) (itoIntegralL2 hB hBmeas f)).2 + +/-- **The Itô-isometry contraction.** `‖(f●B)_t‖ ≤ ‖f‖`: conditional expectation is +an L² contraction and the terminal integral is an isometry (`itoIntegralL2_norm`). -/ +theorem itoProcessL2Inf_norm_le (t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (f : Lp ℝ 2 ((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod)) : + ‖itoProcessL2Inf hB t hBmeas f‖ ≤ ‖f‖ := by + rw [itoProcessL2Inf_apply] + exact (norm_condExpL2_le ((natFiltration hBmeas).le t) (itoIntegralL2 hB hBmeas f)).trans + (itoIntegralL2_norm hB hBmeas f).le + +omit [IsProbabilityMeasure μ] in +include hB in +/-- B1a's martingale to the terminal: `μ[itoSimple V | 𝓕_t] = (V●B)_t` for +`T`-bounded `V` (`(V●B)_{T'} = itoSimple V` at `T' = t ⊔ T`). -/ +theorem condExp_itoSimple_eq (T t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (V : SimpleProcess ℝ (natFiltration hBmeas)) (hVT : ∀ p ∈ V.value.support, p.2 ≤ T) : + μ[itoSimple hBmeas V | natFiltration hBmeas t] + =ᵐ[μ] fun ω ↦ itoSimpleProcess hBmeas V t ω := by + have hT'eq : itoSimpleProcess hBmeas V (max t T) = itoSimple hBmeas V := + itoSimpleProcess_eq_itoSimple hBmeas V fun p hp ↦ (hVT p hp).trans (le_max_right t T) + simpa only [hT'eq] using (itoSimpleProcess_isMartingale hB hBmeas V).2 t (max t T) + (le_max_left t T) + +/-- **Simple-process increment-independence.** For a simple +process `V`, the conditional expectation of its `[0,∞)` integral onto `𝓕_t` is the +`[0,t]` truncation `(V●B)_t`: pick a horizon past `V`'s finite support, where the +`[0,∞)` integral coincides with the truncated process, and apply B1a's martingale +property (`condExp_itoSimple_eq`). -/ +lemma condExp_itoIntegralL2_simple (t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + μ[(itoIntegralL2 hB hBmeas (simpleAssembly hBmeas V) : Ω → ℝ) | natFiltration hBmeas t] + =ᵐ[μ] fun ω ↦ itoSimpleProcess hBmeas V t ω := by + have hbridge : (itoIntegralL2 hB hBmeas (simpleAssembly hBmeas V) : Ω → ℝ) + =ᵐ[μ] itoSimple hBmeas V := by + rw [itoIntegralL2_simpleAssembly] + exact (memLp_itoSimple hB hBmeas V).coeFn_toLp + exact (condExp_congr_ae hbridge).trans + (condExp_itoSimple_eq hB (V.value.support.sup (fun p ↦ p.2)) t hBmeas V + (fun p hp ↦ Finset.le_sup hp)) + +/-- **The process on a simple integrand is B1a's `[0,t]` discrete integral**: +`(V●B)_t = E[∫₀^∞ V dB | 𝓕_t]` a.e. -/ +lemma itoProcessL2Inf_simpleAssembly_ae (t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + (itoProcessL2Inf hB t hBmeas (simpleAssembly hBmeas V) : Ω → ℝ) + =ᵐ[μ] itoSimpleProcess hBmeas V t := by + rw [itoProcessL2Inf_apply] + have h := (Lp.memLp (itoIntegralL2 hB hBmeas (simpleAssembly hBmeas V))).condExpL2_ae_eq_condExp + (𝕜 := ℝ) ((natFiltration hBmeas).le t) + rw [Lp.toLp_coeFn] at h + exact h.trans (condExp_itoIntegralL2_simple hB t hBmeas V) + +/-- **The unbounded-horizon Itô process starts at zero**, `(f●B)_0 = 0`. On the dense simple +processes this is `itoSimpleProcess_zero_time`, and both sides are continuous-linear in `f`. -/ +theorem itoProcessL2Inf_zero_time (hBmeas : ∀ u, Measurable (B u)) + (f : Lp ℝ 2 ((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod)) : + itoProcessL2Inf hB 0 hBmeas f = 0 := by + refine congrFun (DenseRange.equalizer (simpleAssembly_denseRange (μ := μ) hBmeas) + (itoProcessL2Inf hB 0 hBmeas).continuous + (continuous_const (y := (0 : Lp ℝ 2 μ))) (funext fun V ↦ ?_)) f + refine Lp.ext ((itoProcessL2Inf_simpleAssembly_ae hB 0 hBmeas V).trans ?_) + rw [itoSimpleProcess_zero_time] + exact (Lp.coeFn_zero ℝ 2 μ).symm + +end ItoIntegralProcessL2Infinite +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessL2Infinite.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessL2Infinite.lean new file mode 100644 index 0000000000..4f8a0bc738 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessL2Infinite.lean @@ -0,0 +1,260 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessGeneral + +/-! +# Horizon consistency of the Itô integral process + +The unbounded-horizon process `itoProcessL2Inf` (`ItoIntegralProcessL2Inf`) restricted to `[0,T]` +is the finite-horizon `itoProcessCLM T` of the band-restricted integrand +(`itoProcessL2Inf_eq_itoProcessCLM`), by the Itô increment-independence +`E[∫₀^∞ f dB | 𝓕_T] = ∫₀ᵀ f dB`. On the dense simple processes this is concrete, via the +`[0,T]` clamp `clampSP` of a simple process. + +## The `[0,∞)` continuous-local-martingale arc + +* **step 1** — the L² process: `ItoIntegralProcessL2Inf`; +* **step 2** — horizon consistency: this file; +* **step 3** — the glued continuous modification on `[0,∞)` (the finite gate per + horizon `T = n`, glued by `indistinguishable_of_modification_on`); +* **step 4** — the `IsLocalMartingale` on the null-augmented filtration (reusing + `condExp_sup_nulls` / `augFiltration` from the `[0,T]` follow-on). + +## Main definitions + +* `clampSP`: the `[0,T]` clamp of a simple process. + +## Main results + +* `clampSP_itoSimpleProcess`: for `t ≤ T` the `[0,T]` clamp of a simple process has the same + `[0,t]` discrete Itô integral. +* `itoProcessCLM_simpleProcessL2Horizon`: for `t ≤ T`, `itoProcessCLM T t` of a simple process's + `[0,T]` `L²` integrand is its `[0,t]` discrete Itô integral. +* `itoProcessL2Inf_eq_itoProcessCLM`: for `t ≤ T`, `(f●B)_t = (f|[0,T] ● B)_t`, the + unbounded-horizon process equals the finite-horizon process of the `[0,T]`-restricted + integrand. + +## Tags + +horizon consistency, Itô integral, continuous local martingale, infinite horizon, +stochastic integral, MSC 60H05, MSC 60G44 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Filter Topology +open scoped NNReal ENNReal + +namespace MathFin +namespace ItoIntegralProcessL2Infinite + +open ItoIntegralL2 ItoIntegralCLM ItoIntegralProcess ItoIntegralProcessGeneral + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) + +/-! ### The `[0,T]` clamp of a simple process + +The increment-independence crux +`itoIntegralCLM T (simpleProcessL2Horizon T V) =ᵐ itoSimpleProcess V T` cannot be read off the +existing `T`-bounded machinery directly, because a general `V` may carry intervals reaching past +`T`. We clamp `V` to the band: **drop the intervals starting past `T`, clamp every surviving right +endpoint to `T`**. The clamp `clampSP T V` is `T`-bounded, its discrete Itô integral on `[0,t]` +agrees with `V`'s for `t ≤ T`, and its `[0,T]` `L²` integrand agrees with `V`'s — so `V` and its +clamp are indistinguishable to all of the `[0,T]` machinery, which is exactly what closes the +crux. -/ + +/-- Fiber-sum value of the clamped `mapDomain`: `mapDomain` collapses intervals sharing a +left endpoint, so the value at `p` is the (finite) sum of the original `V`-values over the +clamp-preimage of `p`. The contributors all share `p`'s left endpoint, which keeps the +value `𝓕_{p.1}`-measurable. -/ +private lemma clamp_value_apply (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) (p : ℝ≥0 × ℝ≥0) (ω : Ω) : + ((V.value.filter (fun q ↦ q.1 ≤ T)).mapDomain (fun q ↦ (q.1, q.2 ⊓ T))) p ω + = ∑ a ∈ (V.value.filter (fun q ↦ q.1 ≤ T)).support, + (if (a.1, a.2 ⊓ T) = p then V.value a ω else 0) := by + rw [Finsupp.mapDomain, Finsupp.sum_apply, Finsupp.sum, Finset.sum_apply] + refine Finset.sum_congr rfl fun a ha ↦ ?_ + rw [Finsupp.support_filter, Finset.mem_filter] at ha + rw [Finsupp.single_apply] + by_cases h : (a.1, a.2 ⊓ T) = p + · simp only [ite_eq_left h, Finsupp.filter_apply_pos (fun q ↦ q.1 ≤ T) V.value ha.2] + · simp only [ite_eq_right h, Pi.zero_apply] + +/-- **The `[0,T]` clamp of a simple process.** -/ +noncomputable def clampSP (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas) where + valueBot := V.valueBot + value := (V.value.filter (fun q ↦ q.1 ≤ T)).mapDomain (fun q ↦ (q.1, q.2 ⊓ T)) + le_of_mem_support_value := fun p hp ↦ by + obtain ⟨a, ha, rfl⟩ := Finset.mem_image.mp (Finsupp.mapDomain_support hp) + rw [Finsupp.support_filter, Finset.mem_filter] at ha + exact le_inf (V.le_of_mem_support_value a ha.1) ha.2 + measurable_valueBot := V.measurable_valueBot + measurable_value' := fun p hp ↦ by + rw [show ((V.value.filter (fun q ↦ q.1 ≤ T)).mapDomain (fun q ↦ (q.1, q.2 ⊓ T))) p + = fun ω ↦ ∑ a ∈ (V.value.filter (fun q ↦ q.1 ≤ T)).support, + (if (a.1, a.2 ⊓ T) = p then V.value a ω else 0) + from funext fun ω ↦ clamp_value_apply T hBmeas V p ω] + refine Finset.measurable_sum _ fun a ha ↦ ?_ + by_cases h : (a.1, a.2 ⊓ T) = p + · simp only [ite_eq_left h] + rw [Finsupp.support_filter, Finset.mem_filter] at ha + have hp1 : a.1 = p.1 := (Prod.ext_iff.mp h).1 + exact hp1 ▸ V.measurable_value a + · simp only [ite_eq_right h]; exact measurable_const + bounded_valueBot := V.bounded_valueBot + bounded_value := by + refine ⟨(V.value.filter (fun q ↦ q.1 ≤ T)).support.card • |V.valueBound|, fun p hp ω ↦ ?_⟩ + rw [clamp_value_apply] + calc ‖∑ a ∈ (V.value.filter (fun q ↦ q.1 ≤ T)).support, + (if (a.1, a.2 ⊓ T) = p then V.value a ω else 0)‖ + ≤ ∑ a ∈ (V.value.filter (fun q ↦ q.1 ≤ T)).support, + ‖(if (a.1, a.2 ⊓ T) = p then V.value a ω else 0)‖ := norm_sum_le _ _ + _ ≤ ∑ _a ∈ (V.value.filter (fun q ↦ q.1 ≤ T)).support, |V.valueBound| := by + refine Finset.sum_le_sum fun a ha ↦ ?_ + by_cases h : (a.1, a.2 ⊓ T) = p + · simp only [ite_eq_left h] + exact (V.value_le_valueBound a ω).trans (le_abs_self _) + · simp only [ite_eq_right h, norm_zero]; exact abs_nonneg _ + _ = (V.value.filter (fun q ↦ q.1 ≤ T)).support.card • |V.valueBound| := by + rw [Finset.sum_const] + +/-- **Master `Finsupp.sum` identity for the clamp.** Any additive-in-the-value statistic +`φ` summed over the clamp equals the same statistic summed over `V`, provided `φ` is +invariant under the right-endpoint clamp on the kept intervals (`hclamp`) and vanishes on +the dropped ones (`hdrop`). Both `clampSP_itoSimpleProcess` and `clampSP_simpleProcessL2Horizon` +are instances. -/ +private lemma clampSP_value_sum {N : Type*} [AddCommMonoid N] (T : ℝ≥0) + (hBmeas : ∀ u, Measurable (B u)) (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) + (φ : ℝ≥0 × ℝ≥0 → (Ω → ℝ) → N) + (hφ0 : ∀ p, φ p 0 = 0) (hφadd : ∀ p u v, φ p (u + v) = φ p u + φ p v) + (hclamp : ∀ a ∈ V.value.support, a.1 ≤ T → φ (a.1, a.2 ⊓ T) (V.value a) = φ a (V.value a)) + (hdrop : ∀ a ∈ V.value.support, T < a.1 → φ a (V.value a) = 0) : + (clampSP T hBmeas V).value.sum φ = V.value.sum φ := by + change ((V.value.filter (fun q ↦ q.1 ≤ T)).mapDomain (fun q ↦ (q.1, q.2 ⊓ T))).sum φ + = V.value.sum φ + rw [Finsupp.sum_mapDomain_index hφ0 hφadd, Finsupp.sum, Finsupp.support_filter, + Finset.sum_filter] + conv_rhs => rw [Finsupp.sum] + refine Finset.sum_congr rfl fun a ha ↦ ?_ + by_cases hP : a.1 ≤ T + · rw [ite_eq_left hP, Finsupp.filter_apply_pos (fun q ↦ q.1 ≤ T) V.value hP] + exact hclamp a ha hP + · rw [ite_eq_right hP] + exact (hdrop a ha (not_le.mp hP)).symm + +/-- **Clamp preserves the `[0,t]` discrete Itô integral for `t ≤ T`.** -/ +lemma clampSP_itoSimpleProcess (T t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) (ht : t ≤ T) : + itoSimpleProcess hBmeas (clampSP T hBmeas V) t = itoSimpleProcess hBmeas V t := by + funext ω + rw [itoSimpleProcess_apply, itoSimpleProcess_apply] + refine clampSP_value_sum T hBmeas V (fun p v ↦ v ω * (B (min p.2 t) ω - B (min p.1 t) ω)) + (fun p ↦ by simp) (fun p u v ↦ by simp only [Pi.add_apply]; ring) + (fun a ha hP ↦ ?_) (fun a ha hP ↦ ?_) + · rw [show min (a.2 ⊓ T) t = min a.2 t from by rw [min_assoc, min_eq_right ht]] + · have h1 : min a.1 t = t := min_eq_right (le_of_lt (lt_of_le_of_lt ht hP)) + have h2 : min a.2 t = t := + min_eq_right + (le_of_lt (lt_of_le_of_lt ht (lt_of_lt_of_le hP (V.le_of_mem_support_value a ha)))) + rw [h1, h2, sub_self, mul_zero] + +/-- **Clamp agrees with `V` pointwise on the band `(0,T]`.** -/ +lemma clampSP_apply (T s : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) (hsT : s ≤ T) (ω : Ω) : + (clampSP T hBmeas V) s ω = V s ω := by + rw [SimpleProcess.apply_eq, SimpleProcess.apply_eq] + congr 1 + exact clampSP_value_sum T hBmeas V (fun p v ↦ (Set.Ioc p.1 p.2).indicator (fun _ ↦ v ω) s) + (fun p ↦ by simp) + (fun p u v ↦ by + simp only [Set.indicator_apply, Pi.add_apply] + split_ifs <;> simp) + (fun a ha hP ↦ by + simp only [Set.indicator_apply] + refine if_congr (Iff.intro (fun h ↦ ⟨h.1, h.2.trans inf_le_left⟩) + (fun h ↦ ⟨h.1, le_inf h.2 hsT⟩)) rfl rfl) + (fun a ha hP ↦ by + rw [Set.indicator_of_notMem] + rintro ⟨h1, _⟩ + exact absurd (lt_of_le_of_lt hsT hP) (not_lt.mpr h1.le)) + +/-- **Clamp preserves the `[0,T]` `L²` integrand.** -/ +lemma clampSP_simpleProcessL2Horizon (T : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) : + simpleProcessL2Horizon (μ := μ) T hBmeas (clampSP T hBmeas V) + = simpleProcessL2Horizon (μ := μ) T hBmeas V := by + refine Lp.ext ((MemLp.coeFn_toLp (memLp_uncurry_trimMeasure T hBmeas (clampSP T hBmeas V))).trans + ((?_ : Function.uncurry ⇑(clampSP T hBmeas V) + =ᵐ[trimMeasure (μ := μ) T hBmeas] Function.uncurry ⇑V).trans + (MemLp.coeFn_toLp (memLp_uncurry_trimMeasure T hBmeas V)).symm)) + rw [trimMeasure_eq_restrict] + refine Filter.eventuallyEq_of_mem + (self_mem_ae_restrict (MeasureTheory.measurableSet_predictable_Ioc_prod + (𝓕 := natFiltration hBmeas) 0 T MeasurableSet.univ)) (fun z hz ↦ ?_) + obtain ⟨⟨_, hzT⟩, _⟩ := hz + exact clampSP_apply T z.1 hBmeas V hzT z.2 + +/-- **The increment-independence crux (process form).** For `t ≤ T` the finite-horizon +process `itoProcessCLM T t` of `V`'s `[0,T]` `L²` integrand reproduces `V`'s `[0,t]` discrete Itô +integral. Via the clamp: `simpleProcessL2Horizon T V = simpleAssemblyHorizon T (clampSP T V)` +(`clampSP_simpleProcessL2Horizon`), `itoProcessCLM_simpleAssemblyHorizon` then gives `(V'●B)_t` of +the `T`-bounded clamp, which equals `(V●B)_t` (`clampSP_itoSimpleProcess`). -/ +lemma itoProcessCLM_simpleProcessL2Horizon (T t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) + (V : SimpleProcess ℝ (natFiltration (mΩ := mΩ) hBmeas)) (ht : t ≤ T) : + (itoProcessCLM hB T t hBmeas (simpleProcessL2Horizon (μ := μ) T hBmeas V) : Ω → ℝ) + =ᵐ[μ] itoSimpleProcess hBmeas V t := by + have hclampT : clampSP T hBmeas V ∈ TBoundedSP T hBmeas := fun p hp ↦ by + obtain ⟨a, _, rfl⟩ := Finset.mem_image.mp (Finsupp.mapDomain_support hp) + exact inf_le_right + have hP1 : simpleProcessL2Horizon (μ := μ) T hBmeas V + = simpleAssemblyHorizon (μ := μ) T hBmeas ⟨clampSP T hBmeas V, hclampT⟩ := + (clampSP_simpleProcessL2Horizon T hBmeas V).symm + rw [hP1, itoProcessCLM_simpleAssemblyHorizon] + exact clampSP_itoSimpleProcess T t hBmeas V ht ▸ + (memLp_itoSimpleProcess hB hBmeas (clampSP T hBmeas V) t).coeFn_toLp + +/-! ## Step 2 — horizon consistency + +The crux relating `itoProcessL2Inf` (`[0,∞)`) to `itoProcessCLM` (`[0,T]`) is the **Itô +increment-independence** `E[∫₀^∞ f dB | 𝓕_T] = ∫₀ᵀ f dB`. The `[0,∞)` process restricted to +`[0,T]` is the finite-horizon process of the band-restricted integrand. Both +`f ↦ itoProcessL2Inf t f` and `f ↦ itoProcessCLM T t (restrictToBand T f)` are +continuous-linear in `f` and, on the dense simple processes, both reproduce `V`'s `[0,t]` +discrete Itô integral (`itoProcessL2Inf_simpleAssembly_ae` on the left; +`restrictToBand_simpleAssembly` + `itoProcessCLM_simpleProcessL2Horizon` on the right), so they +agree everywhere. -/ + +/-- **Horizon consistency.** For `t ≤ T`, the unbounded-horizon process equals the +finite-horizon process of the `[0,T]`-restricted integrand: +`(f●B)_t = (f|[0,T] ● B)_t`. -/ +theorem itoProcessL2Inf_eq_itoProcessCLM (T t : ℝ≥0) (hBmeas : ∀ u, Measurable (B u)) (ht : t ≤ T) + (f : Lp ℝ 2 ((timeMeasure.prod μ).trim + (natFiltration (mΩ := mΩ) hBmeas).predictable_le_prod)) : + itoProcessL2Inf hB t hBmeas f + = itoProcessCLM hB T t hBmeas (restrictToBand (μ := μ) T hBmeas f) := by + refine congrFun (DenseRange.equalizer (simpleAssembly_denseRange (μ := μ) hBmeas) + (itoProcessL2Inf hB t hBmeas).continuous + ((itoProcessCLM hB T t hBmeas).comp (restrictToBand (μ := μ) T hBmeas)).continuous + (funext fun V ↦ ?_)) f + simp only [Function.comp_apply, ContinuousLinearMap.comp_apply] + refine Lp.ext ?_ + have hLHS := itoProcessL2Inf_simpleAssembly_ae hB t hBmeas V + have hRHS : (itoProcessCLM hB T t hBmeas + (restrictToBand (μ := μ) T hBmeas (simpleAssembly hBmeas V)) : Ω → ℝ) + =ᵐ[μ] itoSimpleProcess hBmeas V t := by + rw [restrictToBand_simpleAssembly T hBmeas V] + exact itoProcessCLM_simpleProcessL2Horizon hB T t hBmeas V ht + exact hLHS.trans hRHS.symm + +end ItoIntegralProcessL2Infinite +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessLocalMartingale.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessLocalMartingale.lean new file mode 100644 index 0000000000..49441d7dfc --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessLocalMartingale.lean @@ -0,0 +1,116 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessMartingale +public import LeanPool.MathFin.Probability.Support.LocalMartingale + +/-! +# The elementary Itô integral as a continuous local martingale (Summit B / B3) + +The genuinely new result here is **pathwise (sample-path) regularity** — the +first such result in the Itô tower, which so far is an `L²`/in-measure theory. +For a **continuous** Brownian motion `B` (the standard pathwise setting — +`IsPreBrownianReal` fixes only the finite-dimensional laws, and Degenne's +Kolmogorov–Chentsov machinery produces a continuous version): + +* `itoSimpleProcess_pathContinuous` — for each `ω`, the path `t ↦ (V ● B)_t ω` is + continuous. Via the explicit truncated increment-sum + `(V ● B)_t ω = ∑_p V(p)ω·(B_{p.2∧t}ω − B_{p.1∧t}ω)` (`itoSimpleProcess_apply`), + each summand is the continuous Brownian path `B(·)ω` composed with the + continuous clamp `t ↦ min p.i t`, and a finite sum of continuous functions is + continuous. + +The continuity then unlocks the **localization** entry point — the bridge that +places the integral inside Degenne's local-martingale framework: + +* `itoSimpleProcess_isLocalMartingale` — `(V ● B)` is a continuous **local + martingale** (`IsLocalMartingale`). It is already a genuine `L²` martingale + (`itoSimpleProcess_isMartingale`, B1a); with the continuous (hence càdlàg) + paths this is exactly the hypothesis of Degenne's `Martingale.IsLocalMartingale`, + so the integral lands in the upstream local-martingale class — the gateway + object for the localized stochastic calculus (SDEs, Lévy's characterization, + dynamic Girsanov). + +## Coherence + +Pure consumption: the martingale property is B1a, the path continuity is a +finite sum of continuous clamped Brownian increments, and the local-martingale +packaging is Degenne's sorry-free `Martingale.IsLocalMartingale` +(`Locally.of_prop` along the constant localizing sequence). Nothing is reproved. + +## Scope + +Honest scope: the **elementary** (simple-integrand) integral, under a continuous +Brownian motion. For these `L²`-bounded simple integrands the integral is in fact +a true martingale, so the local-martingale statement is the canonical *framing* +that connects to the localized theory; the genuinely new content here is the +pathwise continuity. The general-integrand pathwise local martingale needs a +continuous modification of the `L²` limit and remains the next gate. + +## Main results + +* `itoSimpleProcess_pathContinuous`: for continuous Brownian paths, each path + `t ↦ (V ● B)_t ω` of the elementary Itô integral is continuous. +* `itoSimpleProcess_isLocalMartingale`: for continuous Brownian paths, the elementary Itô integral + `(V ● B)` is an `IsLocalMartingale`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Ch 7 + +## Tags + +continuous local martingale, path continuity, simple integrand, Itô integral, sample paths, +MSC 60G44, MSC 60H05 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Filter Topology +open scoped NNReal ENNReal + +namespace MathFin +namespace ItoIntegralProcess + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) + +include hB + +omit hB in +/-- **Pathwise continuity of the elementary Itô integral.** Given continuous +Brownian paths, for each `ω` the path `t ↦ (V ● B)_t ω` is continuous: it is the +finite sum `∑_p V(p)ω·(B_{p.2∧t}ω − B_{p.1∧t}ω)` (`itoSimpleProcess_apply`), each +summand the continuous path `B(·)ω` composed with the continuous clamp +`t ↦ min p.i t`. -/ +theorem itoSimpleProcess_pathContinuous (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) (ω : Ω) : + Continuous fun t : ℝ≥0 ↦ itoSimpleProcess hBmeas V t ω := by + simp_rw [fun t ↦ itoSimpleProcess_apply hBmeas V t ω, Finsupp.sum] + refine continuous_finsetSum _ fun p _ ↦ ?_ + refine continuous_const.mul (Continuous.sub ?_ ?_) + · exact (hBcont ω).comp (continuous_const.min continuous_id) + · exact (hBcont ω).comp (continuous_const.min continuous_id) + +/-- **The elementary Itô integral is a continuous local martingale.** Combining +B1a's martingale property (`itoSimpleProcess_isMartingale`) with the continuous +(hence càdlàg) paths gives the hypotheses of Degenne's +`Martingale.IsLocalMartingale`, so `(V ● B)` lands in the upstream +local-martingale class. -/ +theorem itoSimpleProcess_isLocalMartingale (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) : + IsLocalMartingale (fun t ω ↦ itoSimpleProcess hBmeas V t ω) + (ItoIntegralL2.natFiltration hBmeas) μ := + Martingale.IsLocalMartingale (itoSimpleProcess_isMartingale hB hBmeas V) + (fun ω ↦ (itoSimpleProcess_pathContinuous hBmeas hBcont V ω).isCadlag) + +end ItoIntegralProcess +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessLocalMartingaleGeneral.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessLocalMartingaleGeneral.lean new file mode 100644 index 0000000000..23dad4a929 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessLocalMartingaleGeneral.lean @@ -0,0 +1,287 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessContinuousModification + +/-! +# The general-integrand Itô integral as a continuous local martingale + +The continuous modification (`itoContinuousMod`) is a martingale that is +continuous only *almost surely* — its `limUnder` paths are junk off the +convergence set. Degenne's `Martingale.IsLocalMartingale` needs paths càdlàg for +**every** `ω`, which forces an everywhere-continuous representative; but the +modification on a null set can only be repaired while staying adapted if the +filtration carries the null sets. This file builds the **null-augmented +filtration** `𝓕 ⊔ 𝓝` (`𝓝` = the σ-algebra of `μ`-null measurable sets) — the +**completeness** half of the "usual conditions" (right-continuity, the other +half, is neither added nor needed here) — together with the +cond-expectation-invariance under it. These are the measure-theoretic core of the +everywhere-continuous local-martingale upgrade in +`exists_continuous_localMartingale_modification`. + +## Main definitions + +* `nullsAlg`: the σ-algebra generated by the `μ`-null measurable sets. +* `nullAugmentation`: the null augmentation `𝓕 ⊔ 𝓝` of a filtration. +* `augFiltration`: the null-augmented Brownian filtration `𝓕ᴮ ⊔ 𝓝`. +* `itoLocalMod`: the everywhere-defined representative of the continuous modification, clamped to + `[0,T]` via `min · T` and zeroed off a good set `G`. + +## Main results + +* `exists_ae_eq_of_sup_nulls`: every set measurable for the null-augmented σ-algebra `m₁ ⊔ 𝓝` is + `μ`-almost everywhere equal to an `m₁`-measurable set. +* `condExp_sup_nulls`: conditioning on `m₁ ⊔ 𝓝` agrees `μ`-almost everywhere with conditioning on + `m₁`. +* `supermartingale_nullAugmentation`: a supermartingale stays one under the null augmentation of + its filtration. +* `condExp_itoProcessCLM_min`: the `L²` Itô process frozen at `T` satisfies the martingale + identity `E[M_{j∧T} | 𝓕_i] = M_{i∧T}` a.e. for `i ≤ j`. +* `condExp_itoLocalMod`: `itoLocalMod` satisfies the martingale identity on the null + augmentation, for any co-null `G`. +* `exists_continuous_localMartingale_modification`: the general-integrand Itô process on `[0,T]` + has a modification with everywhere-continuous paths that is an `IsLocalMartingale` for the + null-augmented Brownian filtration `augFiltration`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Ch 7 + +## Tags + +null-augmented filtration, usual conditions, completeness, local martingale, +continuous modification, Itô integral, MSC 60G44, MSC 60G07, MSC 60H05 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Filter Topology +open scoped NNReal ENNReal + +namespace MathFin +namespace ItoLocalMartingale + +variable {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} + +/-- The σ-algebra generated by the `μ`-null **measurable** sets (so it stays +`≤ m0`). It contains every measurable null set; augmenting a filtration by it +supplies the **completeness** (null-set augmentation) needed to repair an +a.e.-continuous modification into an everywhere-continuous adapted process. -/ +@[reducible] def nullsAlg (m0 : MeasurableSpace Ω) (μ : Measure Ω) : MeasurableSpace Ω := + MeasurableSpace.generateFrom {s | MeasurableSet[m0] s ∧ μ s = 0} + +lemma nullsAlg_le : nullsAlg m0 μ ≤ m0 := + MeasurableSpace.generateFrom_le fun _ hs ↦ hs.1 + +/-- **The measure-theoretic crux.** Every set measurable for the null-augmented +σ-algebra `m₁ ⊔ 𝓝` is `μ`-a.e. equal to an `m₁`-measurable set. This is exactly +membership in Mathlib's `eventuallyMeasurableSpace m₁ (ae μ)` — the σ-algebra of +sets `=ᵐ` an `m₁`-set — which dominates both `m₁` (`le_eventuallyMeasurableSpace`) +and the null generators of `𝓝` (each `=ᵐ ∅`), hence their supremum. -/ +theorem exists_ae_eq_of_sup_nulls {m₁ : MeasurableSpace Ω} + {s : Set Ω} (hs : MeasurableSet[m₁ ⊔ nullsAlg m0 μ] s) : + ∃ t, MeasurableSet[m₁] t ∧ s =ᵐ[μ] t := by + exact (sup_le le_eventuallyMeasurableSpace + (MeasurableSpace.generateFrom_le fun _ hu ↦ + ⟨∅, m₁.measurableSet_empty, ae_eq_empty.mpr hu.2⟩) : + m₁ ⊔ nullsAlg m0 μ ≤ eventuallyMeasurableSpace m₁ (ae μ)) s hs + +/-- **Cond-expectation invariance under the null augmentation.** Conditioning on +the null-augmented σ-algebra `m₁ ⊔ 𝓝` agrees `μ`-a.e. with conditioning on `m₁`: +the extra information is only null sets, which carry no information. Proof: +`μ[f | m₁]` is `m₁`-measurable (hence `(m₁ ⊔ 𝓝)`-measurable) and satisfies the +`(m₁ ⊔ 𝓝)`-set-integral characterisation of the conditional expectation, because +every `(m₁ ⊔ 𝓝)`-set is `=ᵐ` an `m₁`-set (`exists_ae_eq_of_sup_nulls`) over which +the `m₁`-characterisation already holds. -/ +theorem condExp_sup_nulls [IsFiniteMeasure μ] {m₁ : MeasurableSpace Ω} (hm₁ : m₁ ≤ m0) + {f : Ω → ℝ} (hf : Integrable f μ) : + μ[f | m₁ ⊔ nullsAlg m0 μ] =ᵐ[μ] μ[f | m₁] := by + have hm : m₁ ⊔ nullsAlg m0 μ ≤ m0 := sup_le hm₁ nullsAlg_le + have : SigmaFinite (μ.trim hm₁) := (isFiniteMeasure_trim hm₁).toSigmaFinite + have : SigmaFinite (μ.trim hm) := (isFiniteMeasure_trim hm).toSigmaFinite + refine (ae_eq_condExp_of_forall_setIntegral_eq hm hf + (fun s _ _ ↦ integrable_condExp.integrableOn) (fun s hs _ ↦ ?_) + ((stronglyMeasurable_condExp.mono le_sup_left).aestronglyMeasurable)).symm + obtain ⟨t, htm, hst⟩ := exists_ae_eq_of_sup_nulls hs + rw [setIntegral_congr_set hst, setIntegral_condExp hm₁ hf htm] + exact (setIntegral_congr_set hst).symm + +/-- The **null augmentation** `𝓕 ⊔ 𝓝` of a filtration: at every time it adjoins the σ-algebra +`nullsAlg` generated by the `μ`-null measurable sets. Completeness only; right-continuity is not +added. -/ +noncomputable def nullAugmentation (𝓕 : Filtration ℝ≥0 m0) (μ : Measure Ω) : Filtration ℝ≥0 m0 := + 𝓕 ⊔ Filtration.const ℝ≥0 (nullsAlg m0 μ) nullsAlg_le + +@[simp] lemma nullAugmentation_apply (𝓕 : Filtration ℝ≥0 m0) (i : ℝ≥0) : + nullAugmentation 𝓕 μ i = 𝓕 i ⊔ nullsAlg m0 μ := rfl + +/-- **A supermartingale stays one under the null augmentation**: adaptedness is inherited, and +conditioning on `𝓕 i ⊔ 𝓝` agrees a.e. with conditioning on `𝓕 i` (`condExp_sup_nulls`). -/ +theorem supermartingale_nullAugmentation [IsFiniteMeasure μ] {𝓕 : Filtration ℝ≥0 m0} + {U : ℝ≥0 → Ω → ℝ} (hU : Supermartingale U 𝓕 μ) : + Supermartingale U (nullAugmentation 𝓕 μ) μ := by + refine ⟨fun t => (hU.stronglyAdapted t).mono le_sup_left, ?_, hU.integrable⟩ + intro i j hij + exact (condExp_sup_nulls (𝓕.le i) (hU.integrable j)).trans_le (hU.2.1 i j hij) + +/-- **An almost-sure property holds on a co-null set of the null σ-algebra**: a measurable +null set covers the exceptional set (`exists_measurable_superset_of_null`), and its complement is +a set of `nullsAlg`. Zeroing a process off such a set keeps it adapted to the null augmentation. -/ +theorem exists_nullsAlg_of_ae {p : Ω → Prop} (h : ∀ᵐ ω ∂μ, p ω) : + ∃ G : Set Ω, MeasurableSet[nullsAlg m0 μ] G ∧ μ Gᶜ = 0 ∧ ∀ ω ∈ G, p ω := by + obtain ⟨N, hsub, hNm, hN0⟩ := exists_measurable_superset_of_null (ae_iff.mp h) + exact ⟨Nᶜ, (MeasurableSpace.measurableSet_generateFrom + (show N ∈ {s | MeasurableSet[m0] s ∧ μ s = 0} from ⟨hNm, hN0⟩)).compl, + by rwa [compl_compl], fun ω hω ↦ not_not.mp fun h ↦ hω (hsub h)⟩ + +/-- A process continuous on `[0, T]` along the paths of `G`, frozen at `T` and zeroed off `G`, has +every path continuous. -/ +theorem continuous_indicator_min {G : Set Ω} {T : ℝ≥0} {X : ℝ≥0 → Ω → ℝ} + (hX : ∀ ω ∈ G, ContinuousOn (fun t ↦ X t ω) (Set.Icc 0 T)) (ω : Ω) : + Continuous fun t ↦ G.indicator (X (min t T)) ω := by + by_cases hω : ω ∈ G + · simp only [Set.indicator_of_mem hω] + exact (hX ω hω).comp_continuous (continuous_id.min continuous_const) + fun t ↦ ⟨zero_le, min_le_right _ _⟩ + · simpa only [Set.indicator_of_notMem hω] using continuous_const + +end ItoLocalMartingale + +namespace ItoIntegralProcessLocalMartingaleGeneral + +open ItoIntegralL2 ItoIntegralCLM ItoIntegralProcess ItoIntegralProcessGeneral +open ItoIntegralProcessContinuousModification ItoLocalMartingale + +variable {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} + [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) + +/-- The **null-augmented Brownian filtration** `𝓕ᴮ ⊔ 𝓝`: at each time it adjoins the +`μ`-null measurable sets to `𝓕ᴮ_t`. This supplies the **completeness** (null-set +augmentation) needed to repair the a.e.-continuous modification into an +everywhere-continuous *adapted* process; right-continuity, the other half of the +"usual conditions", is not added and not needed here. -/ +noncomputable def augFiltration (hBmeas : ∀ t, Measurable (B t)) : Filtration ℝ≥0 m0 := + nullAugmentation (natFiltration hBmeas) μ + +omit [IsProbabilityMeasure μ] in +@[simp] lemma augFiltration_apply (hBmeas : ∀ t, Measurable (B t)) (i : ℝ≥0) : + augFiltration (μ := μ) hBmeas i = natFiltration hBmeas i ⊔ nullsAlg m0 μ := rfl + +/-- The **everywhere-defined representative**: the continuous modification clamped to +`[0,T]` via `min · T` (constant past `T`), zeroed off the good set `G`. On `G` it is the +genuine continuous path; off the `μ`-null `Gᶜ` it is `0`. -/ +noncomputable def itoLocalMod (G : Set Ω) (T t : ℝ≥0) (hBmeas : ∀ s, Measurable (B s)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) (ω : Ω) : ℝ := + G.indicator (fun ω ↦ itoContinuousMod T hBmeas φ (min t T) ω) ω + +/-- **The `L²` Itô process frozen at `T` is a martingale**: at times `min i T ≤ min j T` it is the +martingale `itoProcessCLM` (`itoIntegralProcessGen_isMartingale`), and past `T` it is constant. -/ +theorem condExp_itoProcessCLM_min (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) {i j : ℝ≥0} (hij : i ≤ j) : + μ[(itoProcessCLM hB T (min j T) hBmeas φ : Ω → ℝ) | natFiltration hBmeas i] + =ᵐ[μ] (itoProcessCLM hB T (min i T) hBmeas φ : Ω → ℝ) := by + by_cases hiT : i ≤ T + · rw [min_eq_left hiT] + exact itoIntegralProcessGen_isMartingale hB T hBmeas φ (le_min hij hiT) + · have hTi : T ≤ i := (not_le.mp hiT).le + rw [min_eq_right (hTi.trans hij), min_eq_right hTi] + refine condExp_of_aestronglyMeasurable' ((natFiltration hBmeas).le i) ?_ + ((Lp.memLp _).integrable (by norm_num)) + obtain ⟨g, hg, hfg⟩ := itoProcessCLM_aeStronglyMeasurable hB T T hBmeas φ + exact ⟨g, hg.mono ((natFiltration hBmeas).mono hTi), hfg⟩ + +/-- Off a null set `Gᶜ`, the representative `itoLocalMod` is a modification of the `L²` Itô process +frozen at `T`. -/ +theorem itoLocalMod_ae_eq (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) {G : Set Ω} (hG : μ Gᶜ = 0) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) (i : ℝ≥0) : + (fun ω ↦ itoLocalMod G T i hBmeas φ ω) + =ᵐ[μ] (itoProcessCLM hB T (min i T) hBmeas φ : Ω → ℝ) := by + refine EventuallyEq.trans ?_ + (itoContinuousMod_modification hB T hBmeas hBcont φ (min_le_right i T)) + filter_upwards [show ∀ᵐ ω ∂μ, ω ∈ G by rw [ae_iff]; exact hG] with ω hω + simp only [itoLocalMod, Set.indicator_of_mem hω] + +include hB in +/-- **The martingale identity of `itoLocalMod` on the null augmentation**, for any co-null `G`: +conditioning on `𝓕ᴮ_i ⊔ 𝓝` is conditioning on `𝓕ᴮ_i` (`condExp_sup_nulls`), where the frozen +`L²` process is a martingale (`condExp_itoProcessCLM_min`). -/ +theorem condExp_itoLocalMod (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) {G : Set Ω} (hG : μ Gᶜ = 0) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) {i j : ℝ≥0} (hij : i ≤ j) : + μ[(fun ω ↦ itoLocalMod G T j hBmeas φ ω) | augFiltration (μ := μ) hBmeas i] + =ᵐ[μ] (fun ω ↦ itoLocalMod G T i hBmeas φ ω) := + calc μ[(fun ω ↦ itoLocalMod G T j hBmeas φ ω) | augFiltration (μ := μ) hBmeas i] + =ᵐ[μ] μ[(itoProcessCLM hB T (min j T) hBmeas φ : Ω → ℝ) + | natFiltration hBmeas i ⊔ nullsAlg m0 μ] := + condExp_congr_ae (itoLocalMod_ae_eq hB T hBmeas hBcont hG φ j) + _ =ᵐ[μ] μ[(itoProcessCLM hB T (min j T) hBmeas φ : Ω → ℝ) | natFiltration hBmeas i] := + condExp_sup_nulls ((natFiltration hBmeas).le i) ((Lp.memLp _).integrable (by norm_num)) + _ =ᵐ[μ] (itoProcessCLM hB T (min i T) hBmeas φ : Ω → ℝ) := + condExp_itoProcessCLM_min hB T hBmeas φ hij + _ =ᵐ[μ] (fun ω ↦ itoLocalMod G T i hBmeas φ ω) := + (itoLocalMod_ae_eq hB T hBmeas hBcont hG φ i).symm + +/-- **The general-integrand Itô process has an everywhere-continuous local-martingale +representative.** There is a process `X : ℝ≥0 → Ω → ℝ` that (i) is a **modification** of +the `L²` Itô process on the horizon — `X t =ᵐ itoProcessCLM T t φ` for every `t ≤ T`; +(ii) has **everywhere**-continuous paths; (iii) is a genuine `IsLocalMartingale` for the +**null-augmented** Brownian filtration `augFiltration` (the martingale property holds globally +on `ℝ≥0`, the clamp `min · T` freezing it past `T`; only the modification clause (i) is +horizon-scoped); and (iv) is `StronglyMeasurable[augFiltration i]` at each `i` — the per-horizon +adaptedness, exposed explicitly so the `[0,∞)` gluing arc can consume it. This upgrades the gate +(`exists_continuous_modification_itoProcess`, an +a.e.-continuous *modification*) to Degenne's local-martingale interface, whose `∀ ω, IsCadlag` +hypothesis forces the everywhere-continuous representative: its **adaptedness** the null +augmentation supplies (the repaired good set `G ∈ 𝓝`), its **martingale property** transferring +across the augmentation via `condExp_sup_nulls`. -/ +theorem exists_continuous_localMartingale_modification (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ∃ X : ℝ≥0 → Ω → ℝ, + (∀ t, t ≤ T → X t =ᵐ[μ] itoProcessCLM hB T t hBmeas φ) ∧ + (∀ ω, Continuous fun t ↦ X t ω) ∧ + IsLocalMartingale X (augFiltration (μ := μ) hBmeas) μ ∧ + (∀ i, StronglyMeasurable[augFiltration (μ := μ) hBmeas i] (X i)) := by + -- a co-null good set of the null σ-algebra: pointwise convergence and continuity on `[0, T]` + obtain ⟨G, hGaug, hGnull, hGgood⟩ := exists_nullsAlg_of_ae (μ := μ) + (p := fun ω ↦ (∀ t : ℝ≥0, t ≤ T → Tendsto + (fun n ↦ itoSimpleProcess hBmeas ((approxSeq T hBmeas φ).choose n).val t ω) atTop + (𝓝 (itoContinuousMod T hBmeas φ t ω))) + ∧ ContinuousOn (fun t ↦ itoContinuousMod T hBmeas φ t ω) (Set.Icc 0 T)) <| by + filter_upwards [itoContinuousMod_tendsto hB T hBmeas hBcont φ, + itoContinuousMod_continuousOn hB T hBmeas hBcont φ] with ω h1 h2 using ⟨h1, h2⟩ + -- adaptedness to the augmented filtration: a pointwise limit of `G.indicator` of the simple + -- integrals, each `natFiltration`-measurable + have hadapt : ∀ i : ℝ≥0, StronglyMeasurable[natFiltration hBmeas i ⊔ nullsAlg m0 μ] + (fun ω ↦ itoLocalMod G T i hBmeas φ ω) := by + intro i + refine stronglyMeasurable_of_tendsto atTop + (f := fun n ↦ G.indicator + (fun ω ↦ itoSimpleProcess hBmeas ((approxSeq T hBmeas φ).choose n).val (min i T) ω)) + (fun n ↦ ?_) ?_ + · exact (((itoSimpleProcess_isMartingale hB hBmeas + ((approxSeq T hBmeas φ).choose n).val).1 (min i T)).mono + (((natFiltration hBmeas).mono (min_le_left i T)).trans le_sup_left)).indicator + ((le_sup_right : nullsAlg m0 μ ≤ natFiltration hBmeas i ⊔ nullsAlg m0 μ) _ hGaug) + · refine tendsto_pi_nhds.mpr (fun ω ↦ ?_) + by_cases hω : ω ∈ G + · simp only [Set.indicator_of_mem hω, itoLocalMod] + exact (hGgood ω hω).1 (min i T) (min_le_right i T) + · simp only [Set.indicator_of_notMem hω, itoLocalMod] + exact tendsto_const_nhds + have hcont : ∀ ω, Continuous (fun t ↦ itoLocalMod G T t hBmeas φ ω) := + continuous_indicator_min fun ω hω ↦ (hGgood ω hω).2 + refine ⟨fun t ω ↦ itoLocalMod G T t hBmeas φ ω, fun t ht ↦ ?_, hcont, ?_, hadapt⟩ + · simpa only [min_eq_left ht] using itoLocalMod_ae_eq hB T hBmeas hBcont hGnull φ t + · exact Martingale.IsLocalMartingale ⟨hadapt, fun i j hij ↦ + condExp_itoLocalMod hB T hBmeas hBcont hGnull φ hij⟩ fun ω ↦ (hcont ω).isCadlag + +end ItoIntegralProcessLocalMartingaleGeneral +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessLocalMartingaleInfinite.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessLocalMartingaleInfinite.lean new file mode 100644 index 0000000000..1cb2c62b7f --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessLocalMartingaleInfinite.lean @@ -0,0 +1,234 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessL2Infinite +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessLocalMartingaleGeneral + +/-! +# The unbounded-horizon Itô integral as a continuous local martingale on `ℝ≥0` + +The finite-horizon follow-on (`exists_continuous_localMartingale_modification`) gives, for each +horizon `T = n`, an everywhere-continuous local-martingale modification `Xₙ` of the band-restricted +integrand. Horizon consistency (`itoProcessL2Inf_eq_itoProcessCLM`) makes every `Xₙ` a modification +of the *same* unbounded-horizon process `itoProcessL2Inf · f` on `[0,n]`, so on a co-null set the +`Xₙ` agree on overlaps (`indistinguishable_of_modification_on`). Gluing them — at time `t` read the +horizon `⌈t⌉₊+1`, which is strictly above `t` — yields a single process `gluedProc` continuous on +**all** of `ℝ≥0`, a modification of `itoProcessL2Inf · f` at **every** `t`, and adapted to the +null-augmented filtration. Its martingale property is the **global** `itoProcessL2Inf_isMartingale` +transported across the augmentation by `condExp_sup_nulls` — no horizon clamp is needed (unlike the +`[0,T]` follow-on), because the unbounded-horizon process is genuinely a martingale on the whole +half-line. + +## Main definitions + +* `horizonProc`: the per-horizon (`T = n`) everywhere-continuous local-martingale modification + of the `[0,n]`-band-restricted integrand. +* `gluedProc`: the glued unbounded-horizon process, reading at time `t` the horizon `⌈t⌉₊ + 1` + restricted to the good set `G`. + +## Main results + +* `horizonProc_agree`: for `m ≤ n`, the two horizon processes agree almost surely as paths on + `[0,m)`. +* `exists_continuous_martingale_modification_infinite`: the unbounded-horizon Itô process has a + modification, at every `t`, with everywhere-continuous paths on `ℝ≥0` that is a `Martingale` + for the null-augmented Brownian filtration. +* `exists_continuous_localMartingale_modification_infinite`: the same modification statement, with + `IsLocalMartingale` in place of `Martingale`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Ch 7 + +## Tags + +continuous local martingale, gluing modifications, infinite horizon, Itô integral, +null-augmented filtration, MSC 60G44, MSC 60H05 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Filter Topology +open scoped NNReal ENNReal + +namespace MathFin +namespace ItoLocalMartingaleInfinite + +open ItoIntegralL2 ItoIntegralCLM ItoIntegralProcess ItoIntegralProcessGeneral +open ItoIntegralProcessL2Infinite ItoIntegralProcessLocalMartingaleGeneral ItoLocalMartingale + +variable {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} + [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (f : Lp ℝ 2 ((timeMeasure.prod μ).trim (natFiltration (mΩ := m0) hBmeas).predictable_le_prod)) + +/-- The per-horizon (`T = n`) everywhere-continuous local-martingale modification of the +`[0,n]`-band-restricted integrand, from the finite-horizon follow-on. -/ +noncomputable def horizonProc (n : ℕ) : ℝ≥0 → Ω → ℝ := + (exists_continuous_localMartingale_modification hB (n : ℝ≥0) hBmeas hBcont + (restrictToBand (μ := μ) (n : ℝ≥0) hBmeas f)).choose + +/-- Every horizon process is a modification of the **unbounded-horizon** process on `[0,n]`: +its finite-horizon modification clause composed with horizon consistency. -/ +lemma horizonProc_mod_inf (n : ℕ) (t : ℝ≥0) (ht : t ≤ (n : ℝ≥0)) : + horizonProc hB hBmeas hBcont f n t =ᵐ[μ] (itoProcessL2Inf hB t hBmeas f : Ω → ℝ) := by + have hmod := (exists_continuous_localMartingale_modification hB (n : ℝ≥0) hBmeas hBcont + (restrictToBand (μ := μ) (n : ℝ≥0) hBmeas f)).choose_spec.1 t ht + exact (itoProcessL2Inf_eq_itoProcessCLM hB (n : ℝ≥0) t hBmeas ht f).symm ▸ hmod + +lemma horizonProc_cont (n : ℕ) (ω : Ω) : + Continuous (fun t ↦ horizonProc hB hBmeas hBcont f n t ω) := + (exists_continuous_localMartingale_modification hB (n : ℝ≥0) hBmeas hBcont + (restrictToBand (μ := μ) (n : ℝ≥0) hBmeas f)).choose_spec.2.1 ω + +lemma horizonProc_adapted (n : ℕ) (i : ℝ≥0) : + StronglyMeasurable[augFiltration (μ := μ) hBmeas i] (horizonProc hB hBmeas hBcont f n i) := + (exists_continuous_localMartingale_modification hB (n : ℝ≥0) hBmeas hBcont + (restrictToBand (μ := μ) (n : ℝ≥0) hBmeas f)).choose_spec.2.2.2 i + +/-- **Pairwise indistinguishability on overlaps.** For `m ≤ n`, the two horizon processes agree +a.e.-pathwise on `[0,m)`: both are continuous and both modify `itoProcessL2Inf · f` there, so +`indistinguishable_of_modification_on` upgrades the a.e.-at-each-`t` agreement to a.e.-for-all-`t`. +-/ +lemma horizonProc_agree (m n : ℕ) (hmn : m ≤ n) : + ∀ᵐ ω ∂μ, ∀ t < (m : ℝ≥0), + horizonProc hB hBmeas hBcont f m t ω = horizonProc hB hBmeas hBcont f n t ω := by + refine indistinguishable_of_modification_on (P := μ) (isOpen_Iio) + (Filter.Eventually.of_forall fun ω ↦ (horizonProc_cont hB hBmeas hBcont f m ω).continuousOn) + (Filter.Eventually.of_forall fun ω ↦ (horizonProc_cont hB hBmeas hBcont f n ω).continuousOn) + (fun t ht ↦ ?_) + have htm : t ≤ (m : ℝ≥0) := le_of_lt ht + have htn : t ≤ (n : ℝ≥0) := htm.trans (by exact_mod_cast hmn) + exact (horizonProc_mod_inf hB hBmeas hBcont f m t htm).trans + (horizonProc_mod_inf hB hBmeas hBcont f n t htn).symm + +/-- **The glued unbounded-horizon process.** At time `t` it reads the horizon `⌈t⌉₊+1` (strictly +above `t`), restricted to the good set `G`. On `G` all horizons agree on overlaps, so this is a +single continuous path; off the `μ`-null `Gᶜ` it is `0`. -/ +noncomputable def gluedProc (G : Set Ω) (t : ℝ≥0) (ω : Ω) : ℝ := + G.indicator (fun ω ↦ horizonProc hB hBmeas hBcont f (⌈t⌉₊ + 1) t ω) ω + +include hBcont + +/-- **The unbounded-horizon Itô integral admits a continuous GLOBAL martingale modification.** +There is a process `X` that (i) is a **modification** of the unbounded-horizon `L²` process at +**every** `t` — `X t =ᵐ itoProcessL2Inf t f`; (ii) has **everywhere**-continuous paths on the whole +half-line; and (iii) is a genuine `Martingale` for the null-augmented Brownian filtration. Unlike +the `[0,T]` follow-on there is no horizon clamp: the martingale property holds globally on `ℝ≥0`, +supplied directly by `itoProcessL2Inf_isMartingale` through `condExp_sup_nulls`. The +local-martingale corollary `exists_continuous_localMartingale_modification_infinite` wraps this; +the exposed global martingale is what a genuine localizing sequence (e.g. exit times, Summit C) +needs in order to stop `X`. -/ +theorem exists_continuous_martingale_modification_infinite : + ∃ X : ℝ≥0 → Ω → ℝ, + (∀ t, X t =ᵐ[μ] (itoProcessL2Inf hB t hBmeas f : Ω → ℝ)) ∧ + (∀ ω, Continuous fun t ↦ X t ω) ∧ + Martingale X (augFiltration (μ := μ) hBmeas) μ := by + -- co-null good set on which every pair of horizons agrees on its overlap + have hae : ∀ᵐ ω ∂μ, ∀ m n : ℕ, m ≤ n → ∀ t < (m : ℝ≥0), + horizonProc hB hBmeas hBcont f m t ω = horizonProc hB hBmeas hBcont f n t ω := by + refine ae_all_iff.mpr fun m ↦ ae_all_iff.mpr fun n ↦ ?_ + by_cases hmn : m ≤ n + · filter_upwards [horizonProc_agree hB hBmeas hBcont f m n hmn] with ω hω + exact fun _ ↦ hω + · exact Filter.Eventually.of_forall fun ω h ↦ absurd h hmn + obtain ⟨N, hsubN, hNmeas, hNnull⟩ := exists_measurable_superset_of_null (ae_iff.mp hae) + set G : Set Ω := Nᶜ with hGdef + have hGnull : μ Gᶜ = 0 := by rw [hGdef, compl_compl]; exact hNnull + have hGaug : MeasurableSet[nullsAlg m0 μ] G := + (MeasurableSpace.measurableSet_generateFrom + (show N ∈ {s | MeasurableSet[m0] s ∧ μ s = 0} from ⟨hNmeas, hNnull⟩)).compl + have hGgood : ∀ ω ∈ G, ∀ m n : ℕ, m ≤ n → ∀ t < (m : ℝ≥0), + horizonProc hB hBmeas hBcont f m t ω = horizonProc hB hBmeas hBcont f n t ω := by + intro ω hω + rw [hGdef, Set.mem_compl_iff] at hω + exact not_not.mp fun h ↦ hω (hsubN h) + -- symmetric agreement: any two horizons strictly above `t` agree at `t`, on `G` + have hGsymm : ∀ ω ∈ G, ∀ (p q : ℕ) (t : ℝ≥0), t < (p : ℝ≥0) → t < (q : ℝ≥0) → + horizonProc hB hBmeas hBcont f p t ω = horizonProc hB hBmeas hBcont f q t ω := by + intro ω hω p q t htp htq + rcases le_total p q with hpq | hqp + · exact hGgood ω hω p q hpq t htp + · exact (hGgood ω hω q p hqp t htq).symm + -- `⌈t⌉₊+1` is a horizon strictly above `t` + have hceil : ∀ t : ℝ≥0, t < ((⌈t⌉₊ + 1 : ℕ) : ℝ≥0) := fun t ↦ + lt_of_le_of_lt (Nat.le_ceil t) (by exact_mod_cast Nat.lt_succ_self ⌈t⌉₊) + -- on `G`, the glued process equals horizon `K` on `[0,K)` for every `K` + have hglueK : ∀ ω ∈ G, ∀ (K : ℕ) (t : ℝ≥0), t < (K : ℝ≥0) → + gluedProc hB hBmeas hBcont f G t ω = horizonProc hB hBmeas hBcont f K t ω := by + intro ω hω K t htK + simp only [gluedProc, Set.indicator_of_mem hω] + exact hGsymm ω hω (⌈t⌉₊ + 1) K t (hceil t) htK + -- (1) everywhere continuity of the glued paths + have hcont : ∀ ω, Continuous (fun t ↦ gluedProc hB hBmeas hBcont f G t ω) := by + intro ω + by_cases hω : ω ∈ G + · refine continuous_iff_continuousAt.mpr fun t₀ ↦ ?_ + set K : ℕ := ⌈t₀⌉₊ + 1 + have ht₀K : t₀ < (K : ℝ≥0) := hceil t₀ + refine (horizonProc_cont hB hBmeas hBcont f K ω).continuousAt.congr ?_ + refine (Filter.eventuallyEq_of_mem (Iio_mem_nhds ht₀K) fun t ht ↦ ?_).symm + exact hglueK ω hω K t ht + · have hrw : (fun t ↦ gluedProc hB hBmeas hBcont f G t ω) = fun _ ↦ (0 : ℝ) := + funext fun t ↦ by simp only [gluedProc, Set.indicator_of_notMem hω] + rw [hrw]; exact continuous_const + -- (2) modification at every `t` + have hmod : ∀ t : ℝ≥0, (fun ω ↦ gluedProc hB hBmeas hBcont f G t ω) + =ᵐ[μ] (itoProcessL2Inf hB t hBmeas f : Ω → ℝ) := by + intro t + have hG_ae : ∀ᵐ ω ∂μ, ω ∈ G := by rw [ae_iff]; exact hGnull + have hstep : (fun ω ↦ gluedProc hB hBmeas hBcont f G t ω) + =ᵐ[μ] (fun ω ↦ horizonProc hB hBmeas hBcont f (⌈t⌉₊ + 1) t ω) := by + filter_upwards [hG_ae] with ω hω + simp only [gluedProc, Set.indicator_of_mem hω] + exact hstep.trans + (horizonProc_mod_inf hB hBmeas hBcont f (⌈t⌉₊ + 1) t (le_of_lt (hceil t))) + -- (3) adaptedness to the augmented filtration + have hadapt : ∀ i : ℝ≥0, StronglyMeasurable[natFiltration hBmeas i ⊔ nullsAlg m0 μ] + (fun ω ↦ gluedProc hB hBmeas hBcont f G i ω) := by + intro i + have h := horizonProc_adapted hB hBmeas hBcont f (⌈i⌉₊ + 1) i + rw [augFiltration_apply] at h + exact h.indicator + ((le_sup_right : nullsAlg m0 μ ≤ natFiltration hBmeas i ⊔ nullsAlg m0 μ) _ hGaug) + -- (4) the augmented martingale identity, from the GLOBAL itoProcessL2Inf martingale + have hmart : ∀ {i j : ℝ≥0}, i ≤ j → + μ[(fun ω ↦ gluedProc hB hBmeas hBcont f G j ω) | natFiltration hBmeas i ⊔ nullsAlg m0 μ] + =ᵐ[μ] (fun ω ↦ gluedProc hB hBmeas hBcont f G i ω) := by + intro i j hij + calc μ[(fun ω ↦ gluedProc hB hBmeas hBcont f G j ω) + | natFiltration hBmeas i ⊔ nullsAlg m0 μ] + =ᵐ[μ] μ[(itoProcessL2Inf hB j hBmeas f : Ω → ℝ) + | natFiltration hBmeas i ⊔ nullsAlg m0 μ] := condExp_congr_ae (hmod j) + _ =ᵐ[μ] μ[(itoProcessL2Inf hB j hBmeas f : Ω → ℝ) | natFiltration hBmeas i] := + condExp_sup_nulls ((natFiltration hBmeas).le i) ((Lp.memLp _).integrable (by norm_num)) + _ =ᵐ[μ] (itoProcessL2Inf hB i hBmeas f : Ω → ℝ) := + itoProcessL2Inf_isMartingale hB hBmeas f hij + _ =ᵐ[μ] (fun ω ↦ gluedProc hB hBmeas hBcont f G i ω) := (hmod i).symm + -- assemble the GLOBAL martingale + refine ⟨fun t ω ↦ gluedProc hB hBmeas hBcont f G t ω, hmod, hcont, + ⟨fun i ↦ ?_, fun i j hij ↦ ?_⟩⟩ + · rw [augFiltration_apply]; exact hadapt i + · rw [augFiltration_apply]; exact hmart hij + +/-- **The unbounded-horizon Itô integral is a continuous local martingale on all of `ℝ≥0`** — +the local-martingale wrapper of `exists_continuous_martingale_modification_infinite` (its global +martingale plus the everywhere-continuous, hence càdlàg, paths). -/ +theorem exists_continuous_localMartingale_modification_infinite : + ∃ X : ℝ≥0 → Ω → ℝ, + (∀ t, X t =ᵐ[μ] (itoProcessL2Inf hB t hBmeas f : Ω → ℝ)) ∧ + (∀ ω, Continuous fun t ↦ X t ω) ∧ + IsLocalMartingale X (augFiltration (μ := μ) hBmeas) μ := by + obtain ⟨X, hmod, hcont, hmart⟩ := + exists_continuous_martingale_modification_infinite hB hBmeas hBcont f + exact ⟨X, hmod, hcont, + Martingale.IsLocalMartingale hmart (fun ω ↦ (hcont ω).isCadlag)⟩ + +end ItoLocalMartingaleInfinite +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessMartingale.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessMartingale.lean new file mode 100644 index 0000000000..10c1028f32 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIntegralProcessMartingale.lean @@ -0,0 +1,401 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcess +public import Mathlib.Tactic.Polynomial.Basic + +/-! # The Itô integral process is an adapted L² martingale (B1a) + +The simple-integrand Itô integral `t ↦ (V●B)_t` (`ItoIntegralProcess`), as a +process, is adapted, a martingale, satisfies the time-indexed isometry, and is +L²-continuous. The conditional martingale-difference `condExp_adapted_mul_increment` +— the conditional sibling of the unconditional +`ItoIsometryAdapted.integral_adapted_mul_increment` — packages +`μ[φ·ΔB | 𝓕_{t₀}] = 0` as a reusable lemma; the martingale property itself is +established directly, applying that same set-integral characterisation per +`𝓕_s`-set. Pathwise continuity and general (non-simple) integrands are later +milestones. + +## Main results + +* `itoSimpleProcess_adaptedAt`: `(V●B)_t` is `𝓕_t`-measurable. +* `condExp_adapted_mul_increment`: for a bounded `φ` adapted at `t₀ ≤ t₁`, the conditional + expectation of `φ · (B_{t₁} − B_{t₀})` given `𝓕_{t₀}` vanishes. +* `itoSimpleProcess_isMartingale`: `t ↦ (V●B)_t` is a martingale, `μ[(V●B)_j | 𝓕_i] = (V●B)_i` + for `i ≤ j`. +* `itoSimpleProcess_isometry_time`: `E[(V●B)_t²]` is the predictable-rectangle double sum with + every interval endpoint truncated at `t`. +* `itoSimpleProcessLp_l2_continuous`: `t ↦ (V●B)_t` is continuous into `Lp ℝ 2 μ`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Ch 7 + +## Tags + +Itô integral martingale, martingale difference, simple integrand, stochastic integral, +L² continuity, MSC 60G44, MSC 60H05 +-/ + +@[expose] public section + +namespace MathFin +namespace ItoIntegralProcess + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + {B : ℝ≥0 → Ω → ℝ} + +/-- The process `(V●B)_t` is `𝓕_t`-measurable: each surviving summand is an +`𝓕_{p.1}`-measurable coefficient (`p.1 ≤ t`) times increments `B_{p.i∧t}` with +`p.i ∧ t ≤ t`. -/ +theorem itoSimpleProcess_adaptedAt (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) (t : ℝ≥0) : + Measurable[ItoIntegralL2.natFiltration hBmeas t] (itoSimpleProcess hBmeas V t) := by + -- `B u` is `𝓕_t`-measurable for `u ≤ t`: `comap (B u) ≤ ⨆ j ≤ t, comap (B j) = 𝓕_t`. + have hBmeas_le : ∀ {u : ℝ≥0}, u ≤ t → + Measurable[ItoIntegralL2.natFiltration hBmeas t] (B u) := by + intro u hu + have hle : MeasurableSpace.comap (B u) (inferInstance : MeasurableSpace ℝ) + ≤ ItoIntegralL2.natFiltration hBmeas t := + le_iSup₂_of_le u hu le_rfl + exact (measurable_iff_comap_le.mpr le_rfl).mono hle le_rfl + rw [show itoSimpleProcess hBmeas V t + = fun ω ↦ ∑ p ∈ V.value.support, + V.value p ω * (B (min p.2 t) ω - B (min p.1 t) ω) + from funext fun ω ↦ by rw [itoSimpleProcess_apply]; rfl] + refine Finset.measurable_sum _ (fun p hp ↦ ?_) + by_cases ht : p.1 ≤ t + · -- active interval: coefficient `𝓕_{p.1} ⊆ 𝓕_t`, both truncated endpoints `≤ t` + have hV : Measurable[ItoIntegralL2.natFiltration hBmeas t] (V.value p) := + (V.measurable_value p).mono ((ItoIntegralL2.natFiltration hBmeas).mono ht) le_rfl + exact hV.mul ((hBmeas_le (min_le_right p.2 t)).sub (hBmeas_le (min_le_right p.1 t))) + · -- interval past `t`: both endpoints truncate to `t`, the term is `0` + push Not at ht + have h1 : min p.1 t = t := min_eq_right ht.le + have h2 : min p.2 t = t := min_eq_right (ht.le.trans (V.le_of_mem_support_value p hp)) + simp only [h1, h2, sub_self, mul_zero] + exact measurable_const + +variable (hB : IsPreBrownianReal B μ) + +include hB + +/-- **Conditional martingale-difference** — the conditional sibling of the +unconditional `ItoIsometryAdapted.integral_adapted_mul_increment`, packaged for +reuse. For `φ` adapted at `t₀ ≤ t₁` and bounded, +`μ[φ·(B_{t₁}−B_{t₀}) | 𝓕_{t₀}] = 0`, via the set-integral characterisation of +conditional expectation: the candidate `0` agrees with `φ·ΔB` on every +`𝓕_{t₀}`-set, since `(s.indicator φ)·ΔB` is the unconditional +martingale-difference. (`itoSimpleProcess_isMartingale` applies this same +characterisation directly per-set rather than calling this lemma; it stands here +as the reusable single-increment statement.) -/ +theorem condExp_adapted_mul_increment (hBmeas : ∀ t, Measurable (B t)) + {t₀ t₁ : ℝ≥0} (ht : t₀ ≤ t₁) {φ : Ω → ℝ} + (hφ : Measurable[ItoIntegralL2.natFiltration hBmeas t₀] φ) {C : ℝ} (hC : ∀ ω, |φ ω| ≤ C) : + μ[fun ω ↦ φ ω * (B t₁ ω - B t₀ ω) | ItoIntegralL2.natFiltration hBmeas t₀] + =ᵐ[μ] 0 := by + have : IsProbabilityMeasure μ := hB.isGaussianProcess.isProbabilityMeasure + have hm : ItoIntegralL2.natFiltration hBmeas t₀ ≤ mΩ := + (ItoIntegralL2.natFiltration hBmeas).le t₀ + have hφm : Measurable φ := hφ.mono hm le_rfl + have hφ_L2 : MemLp φ 2 μ := + MemLp.of_bound hφm.aestronglyMeasurable C + (ae_of_all _ fun ω ↦ (Real.norm_eq_abs _).trans_le (hC ω)) + have hg_int : Integrable (fun ω ↦ φ ω * (B t₁ ω - B t₀ ω)) μ := + (ItoIsometryAdapted.memLp_adapted_mul_increment (hB.isFilteredPreBrownian hBmeas) ht hφ + hφ_L2).integrable (by norm_num) + symm + refine ae_eq_condExp_of_forall_setIntegral_eq hm hg_int + (fun s _ _ ↦ (integrable_zero Ω ℝ μ).integrableOn) (fun s hs _ ↦ ?_) ?_ + · -- `∫_s 0 = ∫_s φ·ΔB`, and `∫_s φ·ΔB = ∫ (s.indicator φ)·ΔB = 0`. + have heq2 : Set.indicator s (fun ω ↦ φ ω * (B t₁ ω - B t₀ ω)) + = fun ω ↦ s.indicator φ ω * (B t₁ ω - B t₀ ω) := by + funext ω; by_cases h : ω ∈ s <;> simp [h] + simp only [Pi.zero_apply, integral_zero] + rw [← integral_indicator (hm s hs), heq2] + exact (ItoIsometryAdapted.integral_adapted_mul_increment + (hB.isFilteredPreBrownian hBmeas) ht (hφ.indicator hs)).symm + · exact stronglyMeasurable_const.aestronglyMeasurable + +omit hB in +/-- **Clamped-increment identity.** For `u ≤ v` and `i ≤ j`, the increment between +times `i` and `j` of the single-interval contribution `t ↦ B_{v∧t} − B_{u∧t}` is +the Brownian increment over `[u∨i, (u∨i)∨(v∧j)]` — so it is a martingale +difference past `𝓕_i`. (`B` is an arbitrary path here; pure `min`/`max` algebra.) -/ +lemma clamped_increment_eq {u v i j : ℝ≥0} (huv : u ≤ v) (hij : i ≤ j) + (ω : Ω) : + (B (min v j) ω - B (min u j) ω) - (B (min v i) ω - B (min u i) ω) + = B (max (max u i) (min v j)) ω - B (max u i) ω := by + rcases le_total i u with h1 | h1 <;> rcases le_total j u with h2 | h2 <;> + rcases le_total i v with h3 | h3 <;> rcases le_total j v with h4 | h4 <;> + simp_all <;> grind + +/-- **The Itô integral process is an `L²` martingale.** `t ↦ (V●B)_t` is adapted +(`itoSimpleProcess_adaptedAt`), `L¹` (`memLp_itoSimpleProcess`, `L²⟹L¹` on a +probability space), and for `i ≤ j`, `μ[(V●B)_j | 𝓕_i] = (V●B)_i`: the increment +`(V●B)_i − (V●B)_j` is, per interval, `V(p)·(B(mₚ) − B(Mₚ))` with +`mₚ = p.1∨i ≤ Mₚ = (p.1∨i)∨(p.2∧j)` (`clamped_increment_eq`), whose `𝓕_i`-set +integral vanishes by the unconditional martingale-difference +`integral_adapted_mul_increment` applied to `s.indicator (V(p))` (adapted at `mₚ`). -/ +theorem itoSimpleProcess_isMartingale (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) : + Martingale (fun t ω ↦ itoSimpleProcess hBmeas V t ω) + (ItoIntegralL2.natFiltration hBmeas) μ := by + have : IsProbabilityMeasure μ := hB.isGaussianProcess.isProbabilityMeasure + refine ⟨fun t ↦ (itoSimpleProcess_adaptedAt hBmeas V t).stronglyMeasurable, ?_⟩ + intro i j hij + have hint : ∀ t : ℝ≥0, Integrable (fun ω ↦ itoSimpleProcess hBmeas V t ω) μ := + fun t ↦ (memLp_itoSimpleProcess hB hBmeas V t).integrable (by norm_num) + have hadapt : ∀ p ∈ V.value.support, + Measurable[ItoIntegralL2.natFiltration hBmeas (max p.1 i)] (V.value p) := fun p _ ↦ + (V.measurable_value p).mono ((ItoIntegralL2.natFiltration hBmeas).mono (le_max_left _ _)) + le_rfl + have hVL2 : ∀ p, MemLp (V.value p) 2 μ := fun p ↦ memLp_value hB hBmeas V p + have hle_mM : ∀ p : ℝ≥0 × ℝ≥0, + max p.1 i ≤ max (max p.1 i) (min p.2 j) := fun _ ↦ le_max_left _ _ + symm + refine ae_eq_condExp_of_forall_setIntegral_eq ((ItoIntegralL2.natFiltration hBmeas).le i) + (hint j) (fun s _ _ ↦ (hint i).integrableOn) (fun s hs _ ↦ ?_) + (itoSimpleProcess_adaptedAt hBmeas V i).stronglyMeasurable.aestronglyMeasurable + have hmle : ItoIntegralL2.natFiltration hBmeas i ≤ mΩ := + (ItoIntegralL2.natFiltration hBmeas).le i + -- the `i`-minus-`j` increment is `-∑ₚ V(p)·(B(Mₚ) − B(mₚ))` + have hpt : (fun ω ↦ itoSimpleProcess hBmeas V i ω - itoSimpleProcess hBmeas V j ω) + = fun ω ↦ -∑ p ∈ V.value.support, + V.value p ω * (B (max (max p.1 i) (min p.2 j)) ω - B (max p.1 i) ω) := by + funext ω + rw [itoSimpleProcess_apply, itoSimpleProcess_apply, Finsupp.sum, Finsupp.sum, + ← Finset.sum_sub_distrib, ← Finset.sum_neg_distrib] + refine Finset.sum_congr rfl fun p hp ↦ ?_ + have hcl := clamped_increment_eq (B := B) (V.le_of_mem_support_value p hp) hij ω + rw [← mul_sub, ← mul_neg] + congr 1 + linarith [hcl] + have hterm_int : ∀ p ∈ V.value.support, + Integrable (fun ω ↦ V.value p ω + * (B (max (max p.1 i) (min p.2 j)) ω - B (max p.1 i) ω)) (μ.restrict s) := + fun p hp ↦ ((ItoIsometryAdapted.memLp_adapted_mul_increment + (hB.isFilteredPreBrownian hBmeas) (hle_mM p) (hadapt p hp) (hVL2 p)).integrable + (by norm_num)).integrableOn + rw [← sub_eq_zero, ← integral_sub (hint i).integrableOn (hint j).integrableOn, hpt, + integral_neg, neg_eq_zero, integral_finsetSum _ hterm_int] + refine Finset.sum_eq_zero fun p hp ↦ ?_ + rw [← integral_indicator (hmle s hs), + show (s.indicator fun ω ↦ V.value p ω + * (B (max (max p.1 i) (min p.2 j)) ω - B (max p.1 i) ω)) + = fun ω ↦ s.indicator (V.value p) ω + * (B (max (max p.1 i) (min p.2 j)) ω - B (max p.1 i) ω) from by + funext ω; by_cases h : ω ∈ s <;> simp [h]] + exact ItoIsometryAdapted.integral_adapted_mul_increment (hB.isFilteredPreBrownian hBmeas) + (hle_mM p) ((hadapt p hp).indicator + ((ItoIntegralL2.natFiltration hBmeas).mono (le_max_right _ _) s hs)) + +/-- **Time-indexed Itô isometry.** `E[(V●B)_t²]` equals the predictable-rectangle +double sum with every interval endpoint truncated at `t`: +`∑_{p,q} E[V(p)·V(q)]·vol((p.1∧t, p.2∧t] ∩ (q.1∧t, q.2∧t])`. The proof mirrors the +terminal `ItoIntegralL2.itoSimple_sq_integral`: the square of the truncated +increment sum expands into a double sum; active rectangles collapse by +`rect_increment_pairing`, while a rectangle whose left endpoint is past `t` has a +collapsed (zero-length) increment matching the zero overlap on the right. +Mathematically, `itoSimple_sq_integral` is recovered when `t` is past every right +endpoint. (RHS endpoints are cast after `min` — `↑(p.2∧t)` — to match +`rect_increment_pairing`'s output.) -/ +theorem itoSimpleProcess_isometry_time (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) (t : ℝ≥0) : + ∫ ω, (itoSimpleProcess hBmeas V t ω) ^ 2 ∂μ + = ∑ p ∈ V.value.support, ∑ q ∈ V.value.support, + (∫ ω, V.value p ω * V.value q ω ∂μ) + * max 0 ((min ((min p.2 t : ℝ≥0) : ℝ) ((min q.2 t : ℝ≥0) : ℝ)) + - (max ((min p.1 t : ℝ≥0) : ℝ) ((min q.1 t : ℝ≥0) : ℝ))) := by + have : IsProbabilityMeasure μ := hB.isGaussianProcess.isProbabilityMeasure + set a : (ℝ≥0 × ℝ≥0) → Ω → ℝ := + fun p ω ↦ V.value p ω * (B (min p.2 t) ω - B (min p.1 t) ω) with ha_def + have ha_L2 : ∀ p ∈ V.value.support, MemLp (a p) 2 μ := + fun p hp ↦ memLp_truncated_term hB hBmeas V t hp + have hint : ∀ p ∈ V.value.support, ∀ q ∈ V.value.support, + Integrable (fun ω ↦ a p ω * a q ω) μ := + fun p hp q hq ↦ (ha_L2 p hp).integrable_mul (ha_L2 q hq) + calc ∫ ω, (itoSimpleProcess hBmeas V t ω) ^ 2 ∂μ + = ∫ ω, ∑ p ∈ V.value.support, ∑ q ∈ V.value.support, a p ω * a q ω ∂μ := by + refine integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ ?_) + change itoSimpleProcess hBmeas V t ω ^ 2 + = ∑ p ∈ V.value.support, ∑ q ∈ V.value.support, a p ω * a q ω + rw [show itoSimpleProcess hBmeas V t ω = ∑ p ∈ V.value.support, a p ω from by + rw [itoSimpleProcess_apply]; rfl, sq, Finset.sum_mul_sum] + _ = ∑ p ∈ V.value.support, ∑ q ∈ V.value.support, ∫ ω, a p ω * a q ω ∂μ := by + rw [integral_finsetSum _ (fun p hp ↦ integrable_finsetSum _ fun q hq ↦ hint p hp q hq)] + exact Finset.sum_congr rfl fun p hp ↦ + integral_finsetSum _ (fun q hq ↦ hint p hp q hq) + _ = ∑ p ∈ V.value.support, ∑ q ∈ V.value.support, + (∫ ω, V.value p ω * V.value q ω ∂μ) + * max 0 ((min ((min p.2 t : ℝ≥0) : ℝ) ((min q.2 t : ℝ≥0) : ℝ)) + - (max ((min p.1 t : ℝ≥0) : ℝ) ((min q.1 t : ℝ≥0) : ℝ))) := by + refine Finset.sum_congr rfl fun p hp ↦ Finset.sum_congr rfl fun q hq ↦ ?_ + by_cases htp : p.1 ≤ t + · by_cases htq : q.1 ≤ t + · -- both rectangles active: collapse via the rectangle pairing + simp only [ha_def, min_eq_left htp, min_eq_left htq] + exact ItoIsometryAdapted.rect_increment_pairing (hB.isFilteredPreBrownian hBmeas) + (V.measurable_value p) + (V.measurable_value q) + (fun ω ↦ by rw [← Real.norm_eq_abs]; exact V.value_le_valueBound p ω) + (fun ω ↦ by rw [← Real.norm_eq_abs]; exact V.value_le_valueBound q ω) + (le_min (V.le_of_mem_support_value p hp) htp) + (le_min (V.le_of_mem_support_value q hq) htq) + · -- `q` past `t`: its increment collapses, overlap is zero + have hq1 : min q.1 t = t := min_eq_right (not_le.mp htq).le + have hq2 : min q.2 t = t := + min_eq_right ((not_le.mp htq).le.trans (V.le_of_mem_support_value q hq)) + have hz : ∀ ω, a p ω * a q ω = 0 := fun ω ↦ by simp [ha_def, hq1, hq2] + rw [integral_congr_ae (Filter.Eventually.of_forall hz), integral_zero, hq1, hq2, + max_eq_left (sub_nonpos.mpr ((min_le_right _ _).trans (le_max_right _ _))), mul_zero] + · -- `p` past `t`: symmetric + have hp1 : min p.1 t = t := min_eq_right (not_le.mp htp).le + have hp2 : min p.2 t = t := + min_eq_right ((not_le.mp htp).le.trans (V.le_of_mem_support_value p hp)) + have hz : ∀ ω, a p ω * a q ω = 0 := fun ω ↦ by simp [ha_def, hp1, hp2] + rw [integral_congr_ae (Filter.Eventually.of_forall hz), integral_zero, hp1, hp2, + max_eq_left (sub_nonpos.mpr ((min_le_left _ _).trans (le_max_left _ _))), mul_zero] + +/-- **`L²`-continuity.** `t ↦ (V●B)_t` is continuous into `Lp ℝ 2 μ`. For `s ≤ t` +the increment `(V●B)_t − (V●B)_s = ∑_p V(p)·(B_{a_p∨(p.2∧t)} − B_{a_p})` +(`a_p = p.1∨s`) is a finite sum of adapted Brownian increments over sub-intervals of +`(s, t]` (`clamped_increment_eq`). Cauchy–Schwarz over the finite support plus the +single-increment isometry `integral_adapted_sq_mul_increment_sq` give the `√`-Hölder +modulus `‖(V●B)_t − (V●B)_s‖² ≤ (|support|·∑_p E[V(p)²])·|t − s|`, whence continuity. -/ +theorem itoSimpleProcessLp_l2_continuous (hBmeas : ∀ t, Measurable (B t)) + (V : SimpleProcess ℝ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas)) : + Continuous (fun t : ℝ≥0 ↦ (itoSimpleProcessLp hB hBmeas V t : Lp ℝ 2 μ)) := by + have : IsProbabilityMeasure μ := hB.isGaussianProcess.isProbabilityMeasure + set C : ℝ := (V.value.support.card : ℝ) + * ∑ p ∈ V.value.support, ∫ ω, (V.value p ω) ^ 2 ∂μ with hC + have hVsq_nonneg : ∀ p, 0 ≤ ∫ ω, (V.value p ω) ^ 2 ∂μ := + fun p ↦ integral_nonneg fun ω ↦ sq_nonneg _ + have hC0 : 0 ≤ C := + mul_nonneg (Nat.cast_nonneg _) (Finset.sum_nonneg fun p _ ↦ hVsq_nonneg p) + -- `L²`-modulus on an ordered pair: `∫ ((V●B)_t − (V●B)_s)² ≤ C·(t − s)` for `s ≤ t`. + have hmod : ∀ {s t : ℝ≥0}, s ≤ t → + ∫ ω, (itoSimpleProcess hBmeas V t ω - itoSimpleProcess hBmeas V s ω) ^ 2 ∂μ + ≤ C * ((t : ℝ) - s) := by + intro s t hst + have hadapt : ∀ p, Measurable[ItoIntegralL2.natFiltration hBmeas (max p.1 s)] (V.value p) := + fun p ↦ (V.measurable_value p).mono + ((ItoIntegralL2.natFiltration hBmeas).mono (le_max_left _ _)) le_rfl + have hVL2 : ∀ p, MemLp (V.value p) 2 μ := fun p ↦ memLp_value hB hBmeas V p + have hXL2 : ∀ p, MemLp (fun ω ↦ V.value p ω + * (B (max (max p.1 s) (min p.2 t)) ω - B (max p.1 s) ω)) 2 μ := fun p ↦ + ItoIsometryAdapted.memLp_adapted_mul_increment (hB.isFilteredPreBrownian hBmeas) + (le_max_left _ _) (hadapt p) (hVL2 p) + have hintXsq : ∀ p, Integrable (fun ω ↦ (V.value p ω + * (B (max (max p.1 s) (min p.2 t)) ω - B (max p.1 s) ω)) ^ 2) μ := + fun p ↦ (hXL2 p).integrable_sq + have hgdiff : ∀ ω, itoSimpleProcess hBmeas V t ω - itoSimpleProcess hBmeas V s ω + = ∑ p ∈ V.value.support, V.value p ω + * (B (max (max p.1 s) (min p.2 t)) ω - B (max p.1 s) ω) := by + intro ω + rw [itoSimpleProcess_apply, itoSimpleProcess_apply, Finsupp.sum, Finsupp.sum, + ← Finset.sum_sub_distrib] + refine Finset.sum_congr rfl fun p hp ↦ ?_ + have hcl := clamped_increment_eq (B := B) (V.le_of_mem_support_value p hp) hst ω + rw [← mul_sub, hcl] + have hsq_int : Integrable (fun ω ↦ (∑ p ∈ V.value.support, V.value p ω + * (B (max (max p.1 s) (min p.2 t)) ω - B (max p.1 s) ω)) ^ 2) μ := + (memLp_finsetSum _ fun p _ ↦ hXL2 p).integrable_sq + have hcard_int : Integrable (fun ω ↦ (V.value.support.card : ℝ) + * ∑ p ∈ V.value.support, (V.value p ω + * (B (max (max p.1 s) (min p.2 t)) ω - B (max p.1 s) ω)) ^ 2) μ := + (integrable_finsetSum _ fun p _ ↦ hintXsq p).const_mul _ + calc ∫ ω, (itoSimpleProcess hBmeas V t ω - itoSimpleProcess hBmeas V s ω) ^ 2 ∂μ + = ∫ ω, (∑ p ∈ V.value.support, V.value p ω + * (B (max (max p.1 s) (min p.2 t)) ω - B (max p.1 s) ω)) ^ 2 ∂μ := by + refine integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ ?_) + simp only [hgdiff] + _ ≤ ∫ ω, (V.value.support.card : ℝ) * ∑ p ∈ V.value.support, (V.value p ω + * (B (max (max p.1 s) (min p.2 t)) ω - B (max p.1 s) ω)) ^ 2 ∂μ := by + refine integral_mono hsq_int hcard_int fun ω ↦ ?_ + have h := Finset.sum_mul_sq_le_sq_mul_sq V.value.support (fun _ ↦ (1 : ℝ)) + (fun p ↦ V.value p ω * (B (max (max p.1 s) (min p.2 t)) ω - B (max p.1 s) ω)) + simpa only [one_mul, one_pow, Finset.sum_const, nsmul_eq_mul, mul_one] using h + _ = (V.value.support.card : ℝ) * ∑ p ∈ V.value.support, ∫ ω, (V.value p ω + * (B (max (max p.1 s) (min p.2 t)) ω - B (max p.1 s) ω)) ^ 2 ∂μ := by + rw [integral_const_mul, integral_finsetSum _ fun p _ ↦ hintXsq p] + _ ≤ C * ((t : ℝ) - s) := by + rw [hC, mul_assoc] + refine mul_le_mul_of_nonneg_left ?_ (Nat.cast_nonneg _) + rw [Finset.sum_mul] + refine Finset.sum_le_sum fun p hp ↦ ?_ + have hXsq_eq : ∫ ω, (V.value p ω + * (B (max (max p.1 s) (min p.2 t)) ω - B (max p.1 s) ω)) ^ 2 ∂μ + = (∫ ω, (V.value p ω) ^ 2 ∂μ) + * (((max (max p.1 s) (min p.2 t) : ℝ≥0) : ℝ) - ((max p.1 s : ℝ≥0) : ℝ)) := by + rw [← ItoIsometryAdapted.integral_adapted_sq_mul_increment_sq + (hB.isFilteredPreBrownian hBmeas) (le_max_left _ _) (hadapt p)] + exact integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ by ring) + rw [hXsq_eq] + refine mul_le_mul_of_nonneg_left ?_ (hVsq_nonneg p) + have e1 : ((min p.2 t : ℝ≥0) : ℝ) ≤ (t : ℝ) := by exact_mod_cast min_le_right p.2 t + have e2 : (s : ℝ) ≤ ((max p.1 s : ℝ≥0) : ℝ) := by exact_mod_cast le_max_right p.1 s + have e3 : (s : ℝ) ≤ (t : ℝ) := by exact_mod_cast hst + rw [NNReal.coe_max] + rcases le_total ((min p.2 t : ℝ≥0) : ℝ) ((max p.1 s : ℝ≥0) : ℝ) with h | h + · rw [max_eq_left h]; linarith + · rw [max_eq_right h]; linarith + -- symmetric modulus in `dist`, then the `√`-Hölder bound and continuity. + have hmod_sym : ∀ t s : ℝ≥0, + ∫ ω, (itoSimpleProcess hBmeas V t ω - itoSimpleProcess hBmeas V s ω) ^ 2 ∂μ + ≤ C * dist t s := by + intro t s + rw [NNReal.dist_eq] + rcases le_total s t with h | h + · rw [abs_of_nonneg (by exact_mod_cast sub_nonneg.mpr (NNReal.coe_le_coe.mpr h))] + exact hmod h + · rw [abs_of_nonpos (by exact_mod_cast sub_nonpos.mpr (NNReal.coe_le_coe.mpr h)), neg_sub, + show (fun ω ↦ (itoSimpleProcess hBmeas V t ω - itoSimpleProcess hBmeas V s ω) ^ 2) + = (fun ω ↦ (itoSimpleProcess hBmeas V s ω - itoSimpleProcess hBmeas V t ω) ^ 2) + from funext fun ω ↦ by ring] + exact hmod h + set F : ℝ≥0 → Lp ℝ 2 μ := fun t ↦ itoSimpleProcessLp hB hBmeas V t with hF + rw [continuous_iff_continuousAt] + intro s + have hbound : ∀ t : ℝ≥0, ‖F t - F s‖ ≤ Real.sqrt C * Real.sqrt (dist t s) := by + intro t + have hnorm_sq : ‖F t - F s‖ ^ 2 + = ∫ ω, (itoSimpleProcess hBmeas V t ω - itoSimpleProcess hBmeas V s ω) ^ 2 ∂μ := by + have hsub : F t - F s + = ((memLp_itoSimpleProcess hB hBmeas V t).sub + (memLp_itoSimpleProcess hB hBmeas V s)).toLp _ := by + simp only [hF] + change (memLp_itoSimpleProcess hB hBmeas V t).toLp _ - + (memLp_itoSimpleProcess hB hBmeas V s).toLp _ = _ + rw [← MemLp.toLp_sub] + rw [hsub, ← real_inner_self_eq_norm_sq, L2.inner_def] + refine integral_congr_ae ?_ + filter_upwards [MemLp.coeFn_toLp ((memLp_itoSimpleProcess (μ := μ) hB hBmeas V t).sub + (memLp_itoSimpleProcess (μ := μ) hB hBmeas V s))] with ω hω + rw [hω]; simp only [Pi.sub_apply] + change (itoSimpleProcess hBmeas V t ω - itoSimpleProcess hBmeas V s ω) + * (itoSimpleProcess hBmeas V t ω - itoSimpleProcess hBmeas V s ω) + = (itoSimpleProcess hBmeas V t ω - itoSimpleProcess hBmeas V s ω) ^ 2 + ring + rw [← Real.sqrt_mul hC0, ← Real.sqrt_sq (norm_nonneg (F t - F s))] + refine Real.sqrt_le_sqrt ?_ + rw [hnorm_sq]; exact hmod_sym t s + have htendsto : Filter.Tendsto + (fun t : ℝ≥0 ↦ Real.sqrt C * Real.sqrt (dist t s)) (nhds s) (nhds 0) := by + have hcont : Continuous (fun t : ℝ≥0 ↦ Real.sqrt C * Real.sqrt (dist t s)) := + continuous_const.mul ((continuous_id.dist continuous_const).sqrt) + simpa [dist_self] using hcont.tendsto s + exact (tendsto_iff_norm_sub_tendsto_zero).mpr + (squeeze_zero (fun t ↦ norm_nonneg _) hbound htendsto) + +end ItoIntegralProcess +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoIsometryAdapted.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIsometryAdapted.lean new file mode 100644 index 0000000000..c6a1c01fed --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoIsometryAdapted.lean @@ -0,0 +1,448 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.KLS.BrownianMotion.Gaussian.BrownianMotion +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralL2 +public import LeanPool.MathFin.Probability.Analysis.IndepIsometryKernel + +/-! +# The adapted Itô isometry (the increment-independence cornerstone) + +The Wiener integral (`Probability/Brownian/Wiener/WienerIntegralL2.lean`) handles +*deterministic* integrands: there the cross-terms vanish by the BM +covariance `E[(B_t-B_s)(B_v-B_u)] = vol((s,t]∩(u,v])`. That is *not* the +Itô integral. The Itô integral allows a **random, adapted** integrand +`φ`, and the cross-terms vanish for a different, deeper reason: the next +increment `B_{t₁} - B_{t₀}` is *independent of the past* `𝓕_{t₀}` and has mean zero. + +This file builds that genuinely-stochastic core **once, against an arbitrary filtration**: +`hF : IsFilteredPreBrownian B 𝓕 μ` (BrownianMotion's class: `B` is `𝓕`-adapted and the +increment `B t - B s` is independent of `𝓕 s`), and "adapted at `t₀`" is Mathlib's +`Measurable[𝓕 t₀]`. The natural filtration is the instance +`IsPreBrownianReal.isFilteredPreBrownian` (`ItoIntegralL2.natFiltration`). The +Poisson isometry (`PoissonCompensatedIsometryAdapted.lean`) is the same argument against +`PoissonRandomMeasure.pastFiltration`, with the independent-scattering field +`indep_of_disjoint_region` in place of `hF.indep`. The one-term facts that follow from independence +(`integral_mul_eq_zero`, `integral_mul_sq`, `memLp_two_mul`) are stated once for both, in +`IndepIsometryKernel`. + +## Crux results + +* `adapted_indepFun_increment` — an integrand `𝓕_{t₀}`-measurable is + independent of the forward increment `B_{t₁} - B_{t₀}`. +* `integral_adapted_mul_increment` — **martingale-difference property**: + `E[φ · (B_{t₁} - B_{t₀})] = 0` for `φ` adapted and integrable. This is + the discrete statement that the Itô integral is a martingale. +* `integral_adapted_mul_increment_sq` — **isometry kernel**: + `E[χ · (B_{t₁} - B_{t₀})²] = E[χ] · (t₁ - t₀)` (with the square form + `integral_adapted_sq_mul_increment_sq` as the `χ = φ²` corollary). + +## Coherence with upstream and the Wiener layer + +Degenne's `BrownianMotion/StochasticIntegral/` already abstracts the +simple-predictable-integrand objects (`SimpleProcess`, `ElementaryPredictableSet`, +`L2Predictable`) — but proves no *integrand-to-integral* isometry; that is the gap +this file fills. (Since the 2026-07-27 pin bump upstream does prove an isometry, +`SquareIntegrable.toL2Isom` in `StochasticIntegral/SquareIntegrable.lean` — but it +is the other one: the `LinearIsometryEquiv` sending a square-integrable martingale +to its terminal value `X ∞` in `L²`, i.e. the Doob-space isomorphism, not +`‖∫ φ dB‖₂² = ∫ 𝔼[φ²] dt`. The two compose rather than compete, and consuming +`SquareIntegrable` for our `L²`-martingale layer is an open follow-up — see +`docs/archive/upstream-consumption-review-2026-07-27.md`.) +The deterministic second moment `integral_increment_sq` is *consumed* as the diagonal +instance of `WienerIntegralL2.covariance_increment_aux` — the single +shared increment-covariance lemma. Unifying onto the package's +`SimpleProcess`/`L2Predictable` remains deferred to a structural pass of the +simple-process layer. + +## Main results + +* `adapted_indepFun_increment`: an `𝓕_{t₀}`-measurable integrand is independent of the forward + increment `B_{t₁} − B_{t₀}`. +* `integral_adapted_mul_increment`: for `φ` adapted to `𝓕_{t₀}`, + `E[φ · (B_{t₁} − B_{t₀})] = 0`. +* `integral_adapted_sq_mul_increment_sq`: for `φ` adapted to `𝓕_{t₀}`, + `E[φ² · (B_{t₁} − B_{t₀})²] = E[φ²] · (t₁ − t₀)`. +* `memLp_adapted_mul_increment`: for `φ` adapted to `𝓕_{t₀}` and in `L²`, + `φ · (B_{t₁} − B_{t₀})` is in `L²`. +* `integral_cross_increment_bilinear_eq_zero`: for adapted integrand families `φ`, `ψ` and + `j < k`, `E[(φⱼ ΔBⱼ)(ψₖ ΔBₖ)] = 0`. +* `ito_isometry_discrete_bilinear`: `E[(Σₖ φₖ ΔBₖ)(Σₖ ψₖ ΔBₖ)] = Σₖ E[φₖ ψₖ] (t_{k+1} − t_k)`. +* `ito_isometry_discrete`: `E[(Σₖ φₖ ΔBₖ)²] = Σₖ E[φₖ²] (t_{k+1} − t_k)` for adapted `L²` + integrand families. +* `ito_isometry_brownian_self`: the discrete isometry for `φₖ = B(tₖ)`, with only measurability + hypotheses. +* `rect_increment_pairing`: for `f` `𝓕_s`-measurable and `g` `𝓕_{s'}`-measurable, both bounded, + `E[f (B_t − B_s) · g (B_{t'} − B_{s'})] = E[f g] · vol((s,t] ∩ (s',t'])`. + +## Tags + +Itô isometry, adapted integrand, martingale difference, independent increments, stochastic integral, +Wiener integral, MSC 60H05, MSC 60J65, MSC 60G44 +-/ + +@[expose] public section + +namespace MathFin +namespace ItoIsometryAdapted + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + {B : ℝ≥0 → Ω → ℝ} {𝓕 : Filtration ℝ≥0 mΩ} + +/-! ### Adaptedness of the Brownian coordinates -/ + +/-- `B u` is `𝓕 t`-measurable for `u ≤ t`: the process is adapted. -/ +theorem _root_.ProbabilityTheory.IsFilteredPreBrownian.measurable_eval_of_le + (hF : IsFilteredPreBrownian B 𝓕 μ) {u t : ℝ≥0} (hu : u ≤ t) : Measurable[𝓕 t] (B u) := + ((hF.stronglyAdapted u).mono (𝓕.mono hu)).measurable + +/-- Each `B t` is ambient-measurable. -/ +theorem _root_.ProbabilityTheory.IsFilteredPreBrownian.measurable_eval + (hF : IsFilteredPreBrownian B 𝓕 μ) (t : ℝ≥0) : Measurable (B t) := + (hF.measurable_eval_of_le le_rfl).mono (𝓕.le t) le_rfl + +/-- An integrand `𝓕_{t₀}`-measurable is independent of the forward increment +`B_{t₁} - B_{t₀}` (the filtered-Brownian independence `hF.indep`, read through +`comap φ ≤ 𝓕 t₀`). -/ +theorem adapted_indepFun_increment + (hF : IsFilteredPreBrownian B 𝓕 μ) {t₀ t₁ : ℝ≥0} (ht : t₀ ≤ t₁) + {φ : Ω → ℝ} (hφ : Measurable[𝓕 t₀] φ) : + IndepFun φ (fun ω ↦ B t₁ ω - B t₀ ω) μ := + (IndepFun_iff_Indep _ _ _).2 (indep_of_indep_of_le_left (hF.indep t₀ t₁ ht).symm hφ.comap_le) + +/-- **Martingale-difference property of the Itô integral** (discrete form): +for `φ` adapted to `𝓕_{t₀}`, the integrand times the next Brownian increment +has mean zero, `E[φ · (B_{t₁} - B_{t₀})] = 0`. This is the reason the Itô +integral is a martingale — and it holds for *random* `φ`, where the Wiener +(deterministic) covariance argument does not apply. -/ +theorem integral_adapted_mul_increment + (hF : IsFilteredPreBrownian B 𝓕 μ) {t₀ t₁ : ℝ≥0} (ht : t₀ ≤ t₁) + {φ : Ω → ℝ} (hφ : Measurable[𝓕 t₀] φ) : + ∫ ω, φ ω * (B t₁ ω - B t₀ ω) ∂μ = 0 := by + refine (adapted_indepFun_increment hF ht hφ).integral_mul_eq_zero + (hφ.mono (𝓕.le t₀) le_rfl).aestronglyMeasurable + ((hF.measurable_eval t₁).sub (hF.measurable_eval t₀)).aestronglyMeasurable ?_ + have h := (hF.hasLaw_sub t₁ t₀).integral_eq + rwa [integral_id_gaussianReal] at h + +/-- The forward increment has second moment `E[(B_{t₁} - B_{t₀})²] = t₁ - t₀`: the +diagonal instance of the Wiener-layer increment covariance +`WienerIntegralL2.covariance_increment_aux`. -/ +theorem integral_increment_sq (hB : IsPreBrownianReal B μ) + {t₀ t₁ : ℝ≥0} (ht : t₀ ≤ t₁) : + ∫ ω, (B t₁ ω - B t₀ ω) ^ 2 ∂μ = (t₁ : ℝ) - t₀ := by + have : IsProbabilityMeasure μ := hB.isGaussianProcess.isProbabilityMeasure + have h := WienerIntegralL2.covariance_increment_aux hB t₀ t₁ t₀ t₁ ht ht + simp only [min_self, max_self] at h + rw [max_eq_right (sub_nonneg.mpr (NNReal.coe_le_coe.mpr ht))] at h + rw [← h] + exact integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ pow_two (B t₁ ω - B t₀ ω)) + +/-- **General isometry kernel**: for `χ` adapted to `𝓕_{t₀}`, +`E[χ · (B_{t₁} - B_{t₀})²] = E[χ] · (t₁ - t₀)`. The increment's square is +independent of the past and has mean `t₁ - t₀`. Specialises to +`integral_adapted_sq_mul_increment_sq` (take `χ = φ²`); supplies the *diagonal* +term of the bilinear isometry below (`χ = φₖ · ψₖ`). -/ +theorem integral_adapted_mul_increment_sq + (hF : IsFilteredPreBrownian B 𝓕 μ) {t₀ t₁ : ℝ≥0} (ht : t₀ ≤ t₁) + {χ : Ω → ℝ} (hχ : Measurable[𝓕 t₀] χ) : + ∫ ω, χ ω * (B t₁ ω - B t₀ ω) ^ 2 ∂μ = (∫ ω, χ ω ∂μ) * ((t₁ : ℝ) - t₀) := by + rw [(adapted_indepFun_increment hF ht hχ).integral_mul_sq + (hχ.mono (𝓕.le t₀) le_rfl).aestronglyMeasurable + ((hF.measurable_eval t₁).sub (hF.measurable_eval t₀)).aestronglyMeasurable, + integral_increment_sq hF.toIsPreBrownianReal ht] + +/-- **Isometry kernel** (the diagonal term of the Itô isometry): for `φ` +adapted to `𝓕_{t₀}`, `E[φ² · (B_{t₁} - B_{t₀})²] = E[φ²] · (t₁ - t₀)`. The +`χ = φ²` instance of `integral_adapted_mul_increment_sq`. -/ +theorem integral_adapted_sq_mul_increment_sq + (hF : IsFilteredPreBrownian B 𝓕 μ) {t₀ t₁ : ℝ≥0} (ht : t₀ ≤ t₁) + {φ : Ω → ℝ} (hφ : Measurable[𝓕 t₀] φ) : + ∫ ω, (φ ω) ^ 2 * (B t₁ ω - B t₀ ω) ^ 2 ∂μ = + (∫ ω, (φ ω) ^ 2 ∂μ) * ((t₁ : ℝ) - t₀) := + integral_adapted_mul_increment_sq hF ht (hφ.pow_const 2) + +/-- If `φ` is adapted to `𝓕_{t₀}` and in `L²`, then `φ · (B_{t₁} - B_{t₀})` is +in `L²`: the increment is in `L²` and independent of `φ`, so the product's +square is integrable. This is the `L²`-membership of a single term of an +adapted simple integral. -/ +theorem memLp_adapted_mul_increment + (hF : IsFilteredPreBrownian B 𝓕 μ) {t₀ t₁ : ℝ≥0} (ht : t₀ ≤ t₁) + {φ : Ω → ℝ} (hφ : Measurable[𝓕 t₀] φ) (hφL2 : MemLp φ 2 μ) : + MemLp (fun ω ↦ φ ω * (B t₁ ω - B t₀ ω)) 2 μ := + (adapted_indepFun_increment hF ht hφ).memLp_two_mul hφL2 + hF.isGaussianProcess.hasGaussianLaw_sub.memLp_two + +/-! ### The discrete Itô isometry over a partition -/ + +/-- **Bilinear cross terms vanish.** For two adapted integrand families `φ`, +`ψ` and `j < k`, `E[(φⱼ·ΔBⱼ)·(ψₖ·ΔBₖ)] = 0`. The factor `φⱼ·ΔBⱼ·ψₖ` is +`𝓕_{tₖ}`-measurable, and `ΔBₖ` is independent of it with mean zero. -/ +theorem integral_cross_increment_bilinear_eq_zero + (hF : IsFilteredPreBrownian B 𝓕 μ) {t : ℕ → ℝ≥0} (hmono : Monotone t) + {φ ψ : ℕ → Ω → ℝ} (hφ : ∀ n, Measurable[𝓕 (t n)] (φ n)) + (hψ : ∀ n, Measurable[𝓕 (t n)] (ψ n)) {j k : ℕ} (hjk : j < k) : + ∫ ω, (φ j ω * (B (t (j + 1)) ω - B (t j) ω)) * + (ψ k ω * (B (t (k + 1)) ω - B (t k) ω)) ∂μ = 0 := by + have hΦ : Measurable[𝓕 (t k)] + (fun ω ↦ φ j ω * (B (t (j + 1)) ω - B (t j) ω) * ψ k ω) := + (((hφ j).mono (𝓕.mono (hmono hjk.le)) le_rfl).mul + ((hF.measurable_eval_of_le (hmono hjk)).sub + (hF.measurable_eval_of_le (hmono hjk.le)))).mul (hψ k) + have hstep : t k ≤ t (k + 1) := hmono (Nat.le_succ k) + have h0 := integral_adapted_mul_increment hF hstep hΦ + rw [show (fun ω ↦ (φ j ω * (B (t (j + 1)) ω - B (t j) ω)) * + (ψ k ω * (B (t (k + 1)) ω - B (t k) ω))) + = (fun ω ↦ (φ j ω * (B (t (j + 1)) ω - B (t j) ω) * ψ k ω) * + (B (t (k + 1)) ω - B (t k) ω)) from by funext ω; ring] + exact h0 + +/-- **The bilinear discrete Itô isometry** (the inner-product/polarised form). +For adapted `L²` integrand families `φ`, `ψ` over a partition `t`, + + `E[(Σₖ φₖ·ΔBₖ)·(Σₖ ψₖ·ΔBₖ)] = Σₖ E[φₖ·ψₖ]·(t_{k+1} − t_k)`. + +This is the workhorse for the continuous Itô isometry: the inner product of two +adapted simple integrals is the `L²(Ω × [0,T])` inner product of the integrands. +The diagonal terms give the mixed kernel `integral_adapted_mul_increment_sq`; +the off-diagonal terms vanish by `integral_cross_increment_bilinear_eq_zero`. -/ +theorem ito_isometry_discrete_bilinear + (hF : IsFilteredPreBrownian B 𝓕 μ) {N : ℕ} {t : ℕ → ℝ≥0} (hmono : Monotone t) + {φ ψ : ℕ → Ω → ℝ} (hφ : ∀ n, Measurable[𝓕 (t n)] (φ n)) + (hψ : ∀ n, Measurable[𝓕 (t n)] (ψ n)) + (hφL2 : ∀ n, MemLp (φ n) 2 μ) (hψL2 : ∀ n, MemLp (ψ n) 2 μ) : + ∫ ω, (∑ k ∈ Finset.range N, φ k ω * (B (t (k + 1)) ω - B (t k) ω)) * + (∑ k ∈ Finset.range N, ψ k ω * (B (t (k + 1)) ω - B (t k) ω)) ∂μ = + ∑ k ∈ Finset.range N, (∫ ω, φ k ω * ψ k ω ∂μ) * ((t (k + 1) : ℝ) - t k) := by + have : IsProbabilityMeasure μ := hF.isGaussianProcess.isProbabilityMeasure + set a : ℕ → Ω → ℝ := fun k ω ↦ φ k ω * (B (t (k + 1)) ω - B (t k) ω) with ha_def + set b : ℕ → Ω → ℝ := fun k ω ↦ ψ k ω * (B (t (k + 1)) ω - B (t k) ω) with hb_def + have ha_L2 : ∀ k, MemLp (a k) 2 μ := fun k ↦ + memLp_adapted_mul_increment hF (hmono (Nat.le_succ k)) (hφ k) (hφL2 k) + have hb_L2 : ∀ k, MemLp (b k) 2 μ := fun k ↦ + memLp_adapted_mul_increment hF (hmono (Nat.le_succ k)) (hψ k) (hψL2 k) + have hint : ∀ j k, Integrable (fun ω ↦ a j ω * b k ω) μ := fun j k ↦ + (ha_L2 j).integrable_mul (hb_L2 k) + -- Diagonal term = mixed variance kernel. + have hdiag : ∀ k, ∫ ω, a k ω * b k ω ∂μ = + (∫ ω, φ k ω * ψ k ω ∂μ) * ((t (k + 1) : ℝ) - t k) := by + intro k + have hstep : t k ≤ t (k + 1) := hmono (Nat.le_succ k) + have hχ : Measurable[𝓕 (t k)] (fun ω ↦ φ k ω * ψ k ω) := (hφ k).mul (hψ k) + rw [show (fun ω ↦ a k ω * b k ω) + = (fun ω ↦ (φ k ω * ψ k ω) * (B (t (k + 1)) ω - B (t k) ω) ^ 2) from by + funext ω; simp only [ha_def, hb_def]; ring] + exact integral_adapted_mul_increment_sq hF hstep hχ + -- Off-diagonal terms vanish. + have hcross : ∀ j ∈ Finset.range N, ∀ k ∈ Finset.range N, j ≠ k → + ∫ ω, a j ω * b k ω ∂μ = 0 := by + intro j _ k _ hjk + rcases lt_or_gt_of_ne hjk with h | h + · exact integral_cross_increment_bilinear_eq_zero hF hmono hφ hψ h + · rw [show (fun ω ↦ a j ω * b k ω) = (fun ω ↦ b k ω * a j ω) from by funext ω; ring] + exact integral_cross_increment_bilinear_eq_zero hF hmono hψ hφ h + calc ∫ ω, (∑ k ∈ Finset.range N, a k ω) * (∑ k ∈ Finset.range N, b k ω) ∂μ + = ∫ ω, ∑ j ∈ Finset.range N, ∑ k ∈ Finset.range N, a j ω * b k ω ∂μ := by + refine integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ ?_) + change (∑ k ∈ Finset.range N, a k ω) * (∑ k ∈ Finset.range N, b k ω) + = ∑ j ∈ Finset.range N, ∑ k ∈ Finset.range N, a j ω * b k ω + rw [Finset.sum_mul_sum] + _ = ∑ j ∈ Finset.range N, ∑ k ∈ Finset.range N, ∫ ω, a j ω * b k ω ∂μ := by + rw [integral_finsetSum _ (fun j _ ↦ integrable_finsetSum _ (fun k _ ↦ hint j k))] + exact Finset.sum_congr rfl + (fun j _ ↦ integral_finsetSum _ (fun k _ ↦ hint j k)) + _ = ∑ j ∈ Finset.range N, ∫ ω, a j ω * b j ω ∂μ := by + refine Finset.sum_congr rfl (fun j hj ↦ ?_) + exact Finset.sum_eq_single j (fun k hk hkj ↦ hcross j hj k hk (Ne.symm hkj)) + (fun hj' ↦ absurd hj hj') + _ = ∑ k ∈ Finset.range N, (∫ ω, φ k ω * ψ k ω ∂μ) * ((t (k + 1) : ℝ) - t k) := + Finset.sum_congr rfl (fun k _ ↦ hdiag k) + +/-- **The discrete Itô isometry** (adapted simple integrands): +`E[(Σₖ φₖ·(B_{t_{k+1}} − B_{t_k}))²] = Σₖ E[φₖ²]·(t_{k+1} − t_k)`. The genuine +Itô isometry — the integrand is *random*. It is the `ψ = φ` diagonal of the +inner-product form `ito_isometry_discrete_bilinear` (`x² = x·x`). -/ +theorem ito_isometry_discrete + (hF : IsFilteredPreBrownian B 𝓕 μ) {N : ℕ} {t : ℕ → ℝ≥0} (hmono : Monotone t) + {φ : ℕ → Ω → ℝ} (hadapt : ∀ n, Measurable[𝓕 (t n)] (φ n)) + (hL2 : ∀ n, MemLp (φ n) 2 μ) : + ∫ ω, (∑ k ∈ Finset.range N, φ k ω * (B (t (k + 1)) ω - B (t k) ω)) ^ 2 ∂μ = + ∑ k ∈ Finset.range N, (∫ ω, (φ k ω) ^ 2 ∂μ) * ((t (k + 1) : ℝ) - t k) := by + simp only [pow_two] + exact ito_isometry_discrete_bilinear hF hmono hadapt hadapt hL2 hL2 + +/-- `E[B_s²] = s` (mean zero, variance `s`). -/ +theorem integral_eval_sq (hB : IsPreBrownianReal B μ) (hBmeas : ∀ s, Measurable (B s)) + (s : ℝ≥0) : + ∫ ω, (B s ω) ^ 2 ∂μ = (s : ℝ) := by + rw [← variance_of_integral_eq_zero (hBmeas s).aemeasurable (hB.integral_eval s)] + show Var[B s; μ] = (s : ℝ) + rw [(hB.hasLaw_eval s).variance_eq, variance_id_gaussianReal] + +/-- **The discrete `∫₀ᵀ B dB` isometry** — the canonical instance, with *no* +remaining hypotheses beyond measurability. Taking the adapted `L²` integrand +`φₖ = B(tₖ)`, + + `E[(Σₖ B(tₖ)·(B_{t_{k+1}} − B_{t_k}))²] = Σₖ t_k·(t_{k+1} − t_k)`, + +the Riemann-sum form of the Itô isometry `E[(∫₀ᵀ B dB)²] = ∫₀ᵀ t dt`. -/ +theorem ito_isometry_brownian_self + (hF : IsFilteredPreBrownian B 𝓕 μ) {N : ℕ} {t : ℕ → ℝ≥0} (hmono : Monotone t) : + ∫ ω, (∑ k ∈ Finset.range N, B (t k) ω * (B (t (k + 1)) ω - B (t k) ω)) ^ 2 ∂μ = + ∑ k ∈ Finset.range N, (t k : ℝ) * ((t (k + 1) : ℝ) - t k) := by + rw [ito_isometry_discrete hF hmono (φ := fun k ↦ B (t k)) + (fun n ↦ hF.measurable_eval_of_le le_rfl) + (fun n ↦ (hF.isGaussianProcess.hasGaussianLaw_eval (t n)).memLp_two)] + exact Finset.sum_congr rfl + (fun k _ ↦ by rw [integral_eval_sq hF.toIsPreBrownianReal hF.measurable_eval]) + +/-! ### Pairing identity for predictable rectangles + +The bridge to the *continuous* Itô integral. For an adapted indicator `f` +(`𝓕_s`-measurable) and `g` (`𝓕_{s'}`-measurable), + + `E[f·(B_t − B_s) · g·(B_{t'} − B_{s'})] = E[f·g] · vol((s,t] ∩ (s',t'])`. + +This is the adapted generalisation of `WienerIntegralL2.covariance_increment_aux` +(take `f = g = 1`). It is the inner-product identity that makes the assembly of +predictable simple integrands an isometry into `L²(Ω × [0,T])`. The split-at-the- +later-start argument: the pre-overlap part pairs to zero (martingale difference), and in +the post-overlap part both increments are *forward* of the later start; splitting the longer +at the shorter's end, the cross piece is a martingale difference and the diagonal piece is +the isometry kernel (`integral_adapted_mul_increment_mul_increment`). -/ + +/-- Integrability of `h · ΔB · ΔB'` for `h` bounded (the products that appear +when splitting the rectangle pairing). -/ +lemma integrable_bdd_two_increment (hB : IsPreBrownianReal B μ) + {h : Ω → ℝ} (hhm : Measurable h) + {C : ℝ} (hhb : ∀ ω, |h ω| ≤ C) (a b c d : ℝ≥0) : + Integrable (fun ω ↦ h ω * ((B b ω - B a ω) * (B d ω - B c ω))) μ := by + have hprod : Integrable (fun ω ↦ (B b ω - B a ω) * (B d ω - B c ω)) μ := + (hB.isGaussianProcess.hasGaussianLaw_sub.memLp_two).integrable_mul + (hB.isGaussianProcess.hasGaussianLaw_sub.memLp_two) + exact hprod.bdd_mul hhm.aestronglyMeasurable + (Filter.Eventually.of_forall fun ω ↦ by rw [Real.norm_eq_abs]; exact hhb ω) + +/-- **Two nested forward increments from one start**: for a bounded `χ` adapted to +`𝓕_a` and `a ≤ b ≤ c`, `E[χ·(B_b − B_a)·(B_c − B_a)] = E[χ]·(b − a)`. Split +`B_c − B_a = (B_c − B_b) + (B_b − B_a)`: the first piece pairs `χ·(B_b − B_a)` (which is +`𝓕_b`-measurable) with a forward increment, a martingale difference; the second is the +isometry kernel. -/ +theorem integral_adapted_mul_increment_mul_increment + (hF : IsFilteredPreBrownian B 𝓕 μ) {a b c : ℝ≥0} (hab : a ≤ b) (hbc : b ≤ c) + {χ : Ω → ℝ} (hχ : Measurable[𝓕 a] χ) {C : ℝ} (hχb : ∀ ω, |χ ω| ≤ C) : + ∫ ω, χ ω * ((B b ω - B a ω) * (B c ω - B a ω)) ∂μ = (∫ ω, χ ω ∂μ) * ((b : ℝ) - a) := by + have hχm : Measurable χ := hχ.mono (𝓕.le a) le_rfl + have hB' := hF.toIsPreBrownianReal + have hχb' : Measurable[𝓕 b] (fun ω ↦ χ ω * (B b ω - B a ω)) := + (hχ.mono (𝓕.mono hab) le_rfl).mul + ((hF.measurable_eval_of_le le_rfl).sub (hF.measurable_eval_of_le hab)) + have h1 := integral_adapted_mul_increment hF hbc hχb' + have h2 := integral_adapted_mul_increment_sq hF hab hχ + have hsplit : ∀ ω, χ ω * ((B b ω - B a ω) * (B c ω - B a ω)) + = χ ω * (B b ω - B a ω) * (B c ω - B b ω) + χ ω * (B b ω - B a ω) ^ 2 := fun ω ↦ by ring + simp_rw [hsplit] + rw [integral_add, h1, h2, zero_add] + · exact (integrable_bdd_two_increment hB' hχm hχb a b b c).congr + (Filter.Eventually.of_forall fun ω ↦ by ring) + · exact (integrable_bdd_two_increment hB' hχm hχb a b a b).congr + (Filter.Eventually.of_forall fun ω ↦ by ring) + +/-- Pairing identity, oriented case `s ≤ s'`. -/ +lemma integral_mul_increment_mul_increment_eq_of_le + (hF : IsFilteredPreBrownian B 𝓕 μ) {f g : Ω → ℝ} {s t s' t' : ℝ≥0} + (hf : Measurable[𝓕 s] f) (hg : Measurable[𝓕 s'] g) + {Cf Cg : ℝ} (hfb : ∀ ω, |f ω| ≤ Cf) (hgb : ∀ ω, |g ω| ≤ Cg) + (_hst : s ≤ t) (hst' : s' ≤ t') (hss' : s ≤ s') : + ∫ ω, (f ω * (B t ω - B s ω)) * (g ω * (B t' ω - B s' ω)) ∂μ = + (∫ ω, f ω * g ω ∂μ) * max 0 ((min (t : ℝ) t') - max (s : ℝ) s') := by + have hB' := hF.toIsPreBrownianReal + have hfm : Measurable f := hf.mono (𝓕.le s) le_rfl + have hgm : Measurable g := hg.mono (𝓕.le s') le_rfl + have hfg : Measurable[𝓕 s'] (fun ω ↦ f ω * g ω) := (hf.mono (𝓕.mono hss') le_rfl).mul hg + have hfgm : Measurable (fun ω ↦ f ω * g ω) := hfm.mul hgm + have hfgb : ∀ ω, |f ω * g ω| ≤ Cf * Cg := fun ω ↦ by + rw [abs_mul] + exact mul_le_mul (hfb ω) (hgb ω) (abs_nonneg _) (le_trans (abs_nonneg _) (hfb ω)) + have hmaxss' : max (s : ℝ) s' = (s' : ℝ) := max_eq_right (by exact_mod_cast hss') + rw [hmaxss'] + by_cases htle : t ≤ s' + · -- Disjoint intervals: the whole pairing is a forward increment with mean zero. + have hχ : Measurable[𝓕 s'] (fun ω ↦ f ω * (B t ω - B s ω) * g ω) := + ((hf.mono (𝓕.mono hss') le_rfl).mul + ((hF.measurable_eval_of_le htle).sub (hF.measurable_eval_of_le hss'))).mul hg + have h0 := integral_adapted_mul_increment hF hst' hχ + have hzero : max (0 : ℝ) ((min (t : ℝ) t') - s') = 0 := by + refine max_eq_left ?_ + have : (min (t : ℝ) t') ≤ (s' : ℝ) := + le_trans (min_le_left _ _) (by exact_mod_cast htle) + linarith + rw [hzero, mul_zero, ← h0] + exact integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ by ring) + · -- Overlapping intervals: split the first increment at the later start `s'`. + replace htle := not_le.mp htle + have hT1 : ∫ ω, f ω * g ω * ((B s' ω - B s ω) * (B t' ω - B s' ω)) ∂μ = 0 := by + have hχ : Measurable[𝓕 s'] (fun ω ↦ f ω * g ω * (B s' ω - B s ω)) := + hfg.mul ((hF.measurable_eval_of_le le_rfl).sub (hF.measurable_eval_of_le hss')) + have h0 := integral_adapted_mul_increment hF hst' hχ + rw [← h0] + exact integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ by ring) + have hT2 : ∫ ω, f ω * g ω * ((B t ω - B s' ω) * (B t' ω - B s' ω)) ∂μ + = (∫ ω, f ω * g ω ∂μ) * (((min t t' : ℝ≥0) : ℝ) - s') := by + rcases le_total t t' with htt | htt + · rw [min_eq_left htt] + exact integral_adapted_mul_increment_mul_increment hF htle.le htt hfg hfgb + · rw [min_eq_right htt, ← integral_adapted_mul_increment_mul_increment hF hst' htt hfg hfgb] + exact integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ by ring) + have hsum : ∫ ω, (f ω * (B t ω - B s ω)) * (g ω * (B t' ω - B s' ω)) ∂μ + = (∫ ω, f ω * g ω * ((B s' ω - B s ω) * (B t' ω - B s' ω)) ∂μ) + + ∫ ω, f ω * g ω * ((B t ω - B s' ω) * (B t' ω - B s' ω)) ∂μ := by + rw [← integral_add (integrable_bdd_two_increment hB' hfgm hfgb s s' s' t') + (integrable_bdd_two_increment hB' hfgm hfgb s' t s' t')] + exact integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ by ring) + have hcoe : ((min t t' : ℝ≥0) : ℝ) = min (t : ℝ) t' := by + rcases le_total t t' with h | h + · rw [min_eq_left h, min_eq_left (by exact_mod_cast h)] + · rw [min_eq_right h, min_eq_right (by exact_mod_cast h)] + rw [hsum, hT1, hT2, zero_add, hcoe] + congr 1 + have h1 : (s' : ℝ) ≤ min (t : ℝ) t' := + le_min (by exact_mod_cast htle.le) (by exact_mod_cast hst') + rw [max_eq_right (by linarith)] + +/-- **Pairing identity for predictable rectangles.** For adapted bounded +integrands `f` (`𝓕_s`-measurable) and `g` (`𝓕_{s'}`-measurable), + + `E[f·(B_t − B_s) · g·(B_{t'} − B_{s'})] = E[f·g] · vol((s,t] ∩ (s',t'])`, + +with `vol((s,t] ∩ (s',t']) = max 0 (min t t' − max s s')`. The adapted +generalisation of the Wiener covariance identity, and the inner-product core of +the continuous Itô isometry. -/ +theorem rect_increment_pairing + (hF : IsFilteredPreBrownian B 𝓕 μ) {f g : Ω → ℝ} {s t s' t' : ℝ≥0} + (hf : Measurable[𝓕 s] f) (hg : Measurable[𝓕 s'] g) + {Cf Cg : ℝ} (hfb : ∀ ω, |f ω| ≤ Cf) (hgb : ∀ ω, |g ω| ≤ Cg) + (hst : s ≤ t) (hst' : s' ≤ t') : + ∫ ω, (f ω * (B t ω - B s ω)) * (g ω * (B t' ω - B s' ω)) ∂μ = + (∫ ω, f ω * g ω ∂μ) * max 0 ((min (t : ℝ) t') - max (s : ℝ) s') := by + rcases le_total s s' with h | h + · exact integral_mul_increment_mul_increment_eq_of_le hF hf hg hfb hgb hst hst' h + · rw [show (∫ ω, (f ω * (B t ω - B s ω)) * (g ω * (B t' ω - B s' ω)) ∂μ) + = ∫ ω, (g ω * (B t' ω - B s' ω)) * (f ω * (B t ω - B s ω)) ∂μ from + integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ by ring), + integral_mul_increment_mul_increment_eq_of_le hF hg hf hgb hfb hst' hst h] + congr 1 + · exact integral_congr_ae (Filter.Eventually.of_forall fun ω ↦ by ring) + · rw [min_comm (t' : ℝ) t, max_comm (s' : ℝ) s] + +end ItoIsometryAdapted +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoProcessPredictable.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoProcessPredictable.lean new file mode 100644 index 0000000000..d0bd93f4bb --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoProcessPredictable.lean @@ -0,0 +1,368 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessContinuousModification +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralProcessIsometry + +/-! # Predictability and `L²` assembly of the Itô process (the SDE-existence keystone) + +To run a Picard iteration for the SDE `dX = b(X)dt + σ(X)dB` inside the +predictable `L²` space `E := Lp ℝ 2 (trimMeasure T)`, the Itô term +`t ↦ (φ ● B)_t`, assembled as a *space-time* function, must itself be +**predictable** — otherwise the iterate cannot be fed back through the Itô +integral (whose integrand domain is the predictable `L²` space). This is the +one genuinely new regularity fact the construction needs: everything before +`ItoIntegralProcessGeneral` only ever needed the process to be adapted at each +fixed time (into `Lp μ`), never jointly predictable in `(t, ω)`. + +Mathlib's `Probability/Process/Predictable.lean` supplies only the easy +direction (predictable ⟹ adapted). The hard direction — a left-continuous +adapted process is predictable — is **Degenne's** +`StronglyAdapted.isStronglyPredictable_of_leftContinuous`, which needs left-continuity on +every path. We apply it not to the continuous modification `itoContinuousMod` +directly, whose paths are continuous only almost surely, but to each *elementary* +Itô integral `itoSimpleProcess V`, which is genuinely continuous for **every** `ω` +(from Brownian path continuity) and genuinely adapted (its martingale property). +Predictability of the general process then lifts through the pointwise `limUnder` +that *defines* `itoContinuousMod` (`StronglyMeasurable.limUnder`), so +`itoContinuousMod` is predictable, and in particular adapted, for the natural +filtration itself; no augmentation is needed. + +* path continuity is `ItoIntegralProcess.itoSimpleProcess_pathContinuous`, consumed here. +* `itoSimpleProcess_isStronglyPredictable` — the elementary integral is predictable. +* `itoContinuousMod_isStronglyPredictable` — the general assembled process is predictable. +* `memLp_itoContinuousMod` — the assembled process is `L²` in the predictable trim measure. +* `itoProcessAssembled` — it, packaged as an element of `Lp ℝ 2 (trimMeasure T)` (the space + a Picard iterate for the SDE lands in). +* `itoProcessAssembled_norm_sq` — the energy identity + `‖itoProcessAssembled φ‖²_E = ∫₀ᵀ ‖(φ●B)_t‖² dt` (the contraction workhorse for the SDE fixed + point). +* `itoProcessAssembled_add` / `itoProcessAssembled_sub` — linearity of the assembled process (as an + `Lp` class), so the contraction difference reduces to the energy identity via `itoProcessCLM`'s + linearity. + +## Main definitions + +* `itoProcessAssembled`: the space-time function `(t,ω) ↦ (φ ● B)_t(ω)`, the continuous + modification, as an element of `Lp ℝ 2 (trimMeasure T)`. + +## Main results + +* `itoSimpleProcess_isStronglyPredictable`: the elementary Itô integral is predictable as a + space-time function. +* `itoContinuousMod_isStronglyPredictable`: the assembled Itô process `itoContinuousMod` is + predictable. +* `memLp_itoContinuousMod`: `itoContinuousMod` is in `L²` for the predictable trim measure. +* `itoProcessAssembled_norm_sq`: `‖itoProcessAssembled φ‖² = ∫₀ᵀ ‖(φ ● B)_t‖² dt`. +* `itoProcessAssembled_norm_le`: `‖itoProcessAssembled φ‖ ≤ √T · ‖φ‖`. +* `itoProcessAssembled_add`, `itoProcessAssembled_sub`: the assembled Itô process is additive and + subtractive in the integrand. + +## Tags + +predictable process, Picard iteration, SDE existence, stochastic differential equation, +Itô integral, left-continuous adapted, MSC 60H10, MSC 60H05, MSC 60G07 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Filter Topology +open scoped NNReal ENNReal + +namespace MathFin +namespace ItoIntegralProcessContinuousModification +open ItoIntegralL2 ItoIntegralCLM ItoIntegralProcess ItoIntegralProcessGeneral + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) + +include hB + +omit [IsProbabilityMeasure μ] in +/-- **The elementary Itô integral is predictable** as a space-time function. It is +genuinely (every `ω`) continuous — hence left-continuous — and genuinely adapted +(the martingale property `itoSimpleProcess_isMartingale.1`), so Degenne's +`StronglyAdapted.isStronglyPredictable_of_leftContinuous` applies directly. This +is the base case that sidesteps the a.e./everywhere friction which blocks +applying the same lemma to the continuous modification directly. -/ +theorem itoSimpleProcess_isStronglyPredictable (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (V : SimpleProcess ℝ (natFiltration hBmeas)) : + IsStronglyPredictable (natFiltration hBmeas) (itoSimpleProcess hBmeas V) := by + apply MeasureTheory.StronglyAdapted.isStronglyPredictable_of_leftContinuous + · exact (itoSimpleProcess_isMartingale hB hBmeas V).1 + · exact fun ω a ↦ + (ItoIntegralProcess.itoSimpleProcess_pathContinuous hBmeas hBcont V ω).continuousWithinAt + +/-- **The assembled Itô process is predictable** (general integrand). By +construction `itoContinuousMod` is the pointwise `limUnder` of the elementary +integrals of a fixed approximating sequence `Vₙ`; each is predictable +(`itoSimpleProcess_isStronglyPredictable`), and `StronglyMeasurable.limUnder` +lifts strong predictable-measurability to the limit. (The ambient σ-algebra must +be pinned to the predictable one before invoking the limit lemma, which would +otherwise synthesize the default product σ-algebra.) -/ +theorem itoContinuousMod_isStronglyPredictable (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + IsStronglyPredictable (natFiltration hBmeas) (itoContinuousMod T hBmeas φ) := by + rw [IsStronglyPredictable] + have hrw : (Function.uncurry (itoContinuousMod T hBmeas φ)) + = fun z : ℝ≥0 × Ω ↦ limUnder atTop (fun n ↦ + Function.uncurry (itoSimpleProcess hBmeas + ((approxSeq T hBmeas φ).choose n).val) z) := by + funext z; rfl + rw [hrw] + let : MeasurableSpace (ℝ≥0 × Ω) := (natFiltration hBmeas).predictable + exact StronglyMeasurable.limUnder (fun n ↦ + itoSimpleProcess_isStronglyPredictable hB hBmeas hBcont + ((approxSeq T hBmeas φ).choose n).val) + +/-- **The assembled Itô process is `L²`** in the predictable trim measure. It is predictable +(`itoContinuousMod_isStronglyPredictable`); the energy is finite because, slice by slice, the +modification identity and the Itô contraction give `∫₀ᵀ ‖(φ ● B)_t‖² dt ≤ T ‖φ‖²` (`eLpNorm_trim` +drops the trim, then Tonelli splits the product and each time-slice is bounded by +`itoProcessCLM_norm_le`). -/ +theorem memLp_itoContinuousMod (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + MemLp (Function.uncurry (itoContinuousMod T hBmeas φ)) 2 (trimMeasure (μ := μ) T hBmeas) := by + have hpred := itoContinuousMod_isStronglyPredictable hB T hBmeas hBcont φ + rw [memLp_iff, show trimMeasure (μ := μ) T hBmeas + = ((timeMeasureHorizon T).prod μ).trim (natFiltration hBmeas).predictable_le_prod from rfl, + eLpNorm_trim _ hpred, + eLpNorm_lt_top_iff_lintegral_rpow_eNorm_lt_top (by norm_num) (by norm_num) + (hpred.mono (natFiltration hBmeas).predictable_le_prod).aestronglyMeasurable, + lintegral_prod _ + ((hpred.mono (natFiltration hBmeas).predictable_le_prod).measurable.eNorm.pow_const _ + |>.aemeasurable)] + -- per-time energy bound: for `t ≤ T` the slice energy is `≤ ‖φ‖²` + have key : ∀ t : ℝ≥0, t ≤ T → + (∫⁻ ω, ‖itoContinuousMod T hBmeas φ t ω‖ₑ ^ (2 : ℝ≥0∞).toReal ∂μ) + ≤ (ENNReal.ofReal ‖φ‖) ^ (2 : ℝ≥0∞).toReal := by + intro t htT + have hmod : (∫⁻ ω, ‖itoContinuousMod T hBmeas φ t ω‖ₑ ^ (2 : ℝ≥0∞).toReal ∂μ) + = ∫⁻ ω, ‖(itoProcessCLM hB T t hBmeas φ : Ω → ℝ) ω‖ₑ ^ (2 : ℝ≥0∞).toReal ∂μ := by + refine lintegral_congr_ae ?_ + filter_upwards [itoContinuousMod_modification hB T hBmeas hBcont φ htT] with ω hω + rw [hω] + rw [hmod, lintegral_rpow_eNorm_eq_rpow_eLpNorm' (by norm_num : (0 : ℝ) < (2 : ℝ≥0∞).toReal)] + gcongr + rw [← eLpNorm_eq_eLpNorm' (by norm_num) (by norm_num) + (Lp.aestronglyMeasurable (itoProcessCLM hB T t hBmeas φ)), ← Lp.eNorm_def, ← ofReal_norm] + exact ENNReal.ofReal_le_ofReal (itoProcessCLM_norm_le hB T t hBmeas φ) + refine lt_of_le_of_lt + (lintegral_mono_ae (g := fun _ ↦ (ENNReal.ofReal ‖φ‖) ^ (2 : ℝ≥0∞).toReal) ?_) ?_ + · have hsub : ∀ᵐ t ∂(timeMeasureHorizon T), t ≤ T := by + rw [timeMeasureHorizon] + filter_upwards [ae_restrict_mem measurableSet_Ioc] with t ht using ht.2 + filter_upwards [hsub] with t htT using key t htT + · rw [lintegral_const] + exact ENNReal.mul_lt_top + (ENNReal.rpow_lt_top_of_nonneg (by norm_num) ENNReal.ofReal_ne_top) (measure_lt_top _ _) + +/-- **The assembled Itô process as an element of the predictable `L²` space `E`.** +The space-time function `(t,ω) ↦ (φ ● B)_t(ω)` (the continuous modification), packaged as a +class in `Lp ℝ 2 (trimMeasure T)` — the object a Picard iterate for the SDE lands in. -/ +noncomputable def itoProcessAssembled (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) := + (memLp_itoContinuousMod hB T hBmeas hBcont φ).toLp + (Function.uncurry (itoContinuousMod T hBmeas φ)) + +/-- **The energy identity.** `‖itoProcessAssembled φ‖²_E = ∫₀ᵀ ‖(φ ● B)_t‖² dt` — the squared +`E`-norm of the assembled process is the time-integral of the per-time Itô `L²`-norms. Slice by +slice the modification identity turns the space-time integral (Tonelli over the trimmed product) +into `∫₀ᵀ ‖itoProcessCLM T t φ‖² dt`. Paired with `itoProcessCLM_norm_sq` (the `[0,t]` energy +`‖itoProcessCLM T t φ‖² = ∫_{(0,t]×Ω} φ²`), this is the Grönwall/Bielecki workhorse the SDE +contraction consumes. -/ +theorem itoProcessAssembled_norm_sq (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ‖itoProcessAssembled hB T hBmeas hBcont φ‖ ^ 2 + = ∫ t, ‖itoProcessCLM hB T t hBmeas φ‖ ^ 2 ∂(timeMeasureHorizon T) := by + have hpred := itoContinuousMod_isStronglyPredictable hB T hBmeas hBcont φ + have hmem := memLp_itoContinuousMod hB T hBmeas hBcont φ + have hmem_prod : MemLp (Function.uncurry (itoContinuousMod T hBmeas φ)) 2 + ((timeMeasureHorizon T).prod μ) := + memLp_of_memLp_trim (natFiltration hBmeas).predictable_le_prod hmem + have hint : Integrable (fun z ↦ (Function.uncurry (itoContinuousMod T hBmeas φ) z) ^ 2) + ((timeMeasureHorizon T).prod μ) := by + refine (hmem_prod.integrable_mul hmem_prod).congr ?_ + filter_upwards with z + rw [Pi.mul_apply, pow_two] + have hcoe : ⇑(itoProcessAssembled hB T hBmeas hBcont φ) + =ᵐ[trimMeasure (μ := μ) T hBmeas] Function.uncurry (itoContinuousMod T hBmeas φ) := + hmem.coeFn_toLp + have htrim : (∫ z, (Function.uncurry (itoContinuousMod T hBmeas φ) z) ^ 2 + ∂(trimMeasure (μ := μ) T hBmeas)) + = ∫ z, (Function.uncurry (itoContinuousMod T hBmeas φ) z) ^ 2 + ∂((timeMeasureHorizon T).prod μ) := + (integral_trim (μ := (timeMeasureHorizon T).prod μ) + (natFiltration hBmeas).predictable_le_prod (hpred.pow 2)).symm + rw [lp_two_norm_sq, + integral_congr_ae (g := fun z ↦ (Function.uncurry (itoContinuousMod T hBmeas φ) z) ^ 2) + (by filter_upwards [hcoe] with z hz; rw [hz]), + htrim, integral_prod _ hint] + refine integral_congr_ae ?_ + have hsub : ∀ᵐ t ∂(timeMeasureHorizon T), t ≤ T := by + rw [timeMeasureHorizon] + filter_upwards [ae_restrict_mem measurableSet_Ioc] with t ht using ht.2 + filter_upwards [hsub] with t htT + rw [lp_two_norm_sq] + refine integral_congr_ae ?_ + filter_upwards [itoContinuousMod_modification hB T hBmeas hBcont φ htT] with ω hω + simp only [Function.uncurry] + rw [hω] + +/-- **The Itô operator bound** `‖itoProcessAssembled φ‖ ≤ √T‖φ‖` — the norm corollary of the energy +identity `itoProcessAssembled_norm_sq`: it turns the square norm into `∫₀ᵀ ‖itoProcessCLM t φ‖² dt`, +and each `[0,t]`-energy is `≤` the full energy `‖φ‖²` (the Itô isometry is flat in `t`), so the +time-integral is `≤ T‖φ‖²`. The `√T` (vs the drift's `T`) is the contraction workhorse. -/ +theorem itoProcessAssembled_norm_le (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ‖itoProcessAssembled hB T hBmeas hBcont φ‖ ≤ Real.sqrt (T : ℝ) * ‖φ‖ := by + have hφsq : Integrable (fun z ↦ (φ z) ^ 2) (trimMeasure (μ := μ) T hBmeas) := + (Lp.memLp φ).integrable_sq + have hsq : ‖itoProcessAssembled hB T hBmeas hBcont φ‖ ^ 2 ≤ (T : ℝ) * ‖φ‖ ^ 2 := by + rw [itoProcessAssembled_norm_sq] + have hpt : ∀ᵐ t ∂(timeMeasureHorizon T), + ‖itoProcessCLM hB T t hBmeas φ‖ ^ 2 ≤ ‖φ‖ ^ 2 := by + filter_upwards [ae_restrict_mem (μ := timeMeasure) measurableSet_Ioc] with t ht + rw [itoProcessCLM_norm_sq hB ht.2 hBmeas φ, lp_two_norm_sq] + exact setIntegral_le_integral hφsq (ae_of_all _ fun z ↦ sq_nonneg _) + calc ∫ t, ‖itoProcessCLM hB T t hBmeas φ‖ ^ 2 ∂(timeMeasureHorizon T) + ≤ ∫ _t, ‖φ‖ ^ 2 ∂(timeMeasureHorizon T) := + integral_mono_of_nonneg (ae_of_all _ fun _ ↦ sq_nonneg _) (integrable_const _) hpt + _ = (T : ℝ) * ‖φ‖ ^ 2 := by + rw [integral_const, timeMeasureHorizon, measureReal_def, Measure.restrict_apply_univ, + timeMeasure_Ioc, + ENNReal.toReal_ofReal (by rw [NNReal.coe_zero, sub_zero]; exact T.coe_nonneg), + NNReal.coe_zero, sub_zero, smul_eq_mul] + have h := Real.sqrt_le_sqrt hsq + rwa [Real.sqrt_sq (norm_nonneg _), Real.sqrt_mul T.coe_nonneg, Real.sqrt_sq (norm_nonneg _)] at h + +/-- **Additivity** of the assembled Itô process (as an `Lp` class). Both sides are modifications +of the linear process `itoProcessCLM T · (φ+ψ)`, so they agree slice by slice (the modification +identity + `itoProcessCLM`'s `map_add`); the per-time a.e. equalities lift to an a.e. equality on +the trimmed product (`Measure.ae_prod_iff_ae_ae` + `ae_eq_trim_of_stronglyMeasurable`). -/ +theorem itoProcessAssembled_add (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (φ ψ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + itoProcessAssembled hB T hBmeas hBcont (φ + ψ) + = itoProcessAssembled hB T hBmeas hBcont φ + itoProcessAssembled hB T hBmeas hBcont ψ := by + have hpredφ := itoContinuousMod_isStronglyPredictable hB T hBmeas hBcont φ + have hpredψ := itoContinuousMod_isStronglyPredictable hB T hBmeas hBcont ψ + have hpredS' : StronglyMeasurable[(natFiltration hBmeas).predictable] + (Function.uncurry (itoContinuousMod T hBmeas (φ + ψ))) := + itoContinuousMod_isStronglyPredictable hB T hBmeas hBcont (φ + ψ) + have hgSM : StronglyMeasurable[(natFiltration hBmeas).predictable] + (Function.uncurry (itoContinuousMod T hBmeas φ) + + Function.uncurry (itoContinuousMod T hBmeas ψ)) := + StronglyMeasurable.add hpredφ hpredψ + have hkey : Function.uncurry (itoContinuousMod T hBmeas (φ + ψ)) + =ᵐ[trimMeasure (μ := μ) T hBmeas] + (Function.uncurry (itoContinuousMod T hBmeas φ) + + Function.uncurry (itoContinuousMod T hBmeas ψ)) := by + refine hpredS'.ae_eq_trim_of_stronglyMeasurable + (natFiltration hBmeas).predictable_le_prod hgSM ?_ + have hset : MeasurableSet {z : ℝ≥0 × Ω | + Function.uncurry (itoContinuousMod T hBmeas (φ + ψ)) z + = (Function.uncurry (itoContinuousMod T hBmeas φ) + + Function.uncurry (itoContinuousMod T hBmeas ψ)) z} := + measurableSet_eq_fun (hpredS'.mono (natFiltration hBmeas).predictable_le_prod).measurable + (hgSM.mono (natFiltration hBmeas).predictable_le_prod).measurable + rw [Filter.EventuallyEq, Measure.ae_prod_iff_ae_ae hset] + have hsub : ∀ᵐ t ∂(timeMeasureHorizon T), t ≤ T := by + rw [timeMeasureHorizon] + filter_upwards [ae_restrict_mem measurableSet_Ioc] with t ht using ht.2 + filter_upwards [hsub] with t htT + filter_upwards [itoContinuousMod_modification hB T hBmeas hBcont (φ + ψ) htT, + itoContinuousMod_modification hB T hBmeas hBcont φ htT, + itoContinuousMod_modification hB T hBmeas hBcont ψ htT, + Lp.coeFn_add (itoProcessCLM hB T t hBmeas φ) (itoProcessCLM hB T t hBmeas ψ)] + with ω hωS hωφ hωψ hωadd + simp only [Function.uncurry, Pi.add_apply] + rw [hωS, map_add, hωadd, Pi.add_apply, ← hωφ, ← hωψ] + have hcoeS : ⇑(itoProcessAssembled hB T hBmeas hBcont (φ + ψ)) + =ᵐ[trimMeasure (μ := μ) T hBmeas] Function.uncurry (itoContinuousMod T hBmeas (φ + ψ)) := + (memLp_itoContinuousMod hB T hBmeas hBcont (φ + ψ)).coeFn_toLp + have hcoeφ : ⇑(itoProcessAssembled hB T hBmeas hBcont φ) + =ᵐ[trimMeasure (μ := μ) T hBmeas] Function.uncurry (itoContinuousMod T hBmeas φ) := + (memLp_itoContinuousMod hB T hBmeas hBcont φ).coeFn_toLp + have hcoeψ : ⇑(itoProcessAssembled hB T hBmeas hBcont ψ) + =ᵐ[trimMeasure (μ := μ) T hBmeas] Function.uncurry (itoContinuousMod T hBmeas ψ) := + (memLp_itoContinuousMod hB T hBmeas hBcont ψ).coeFn_toLp + refine Lp.ext ?_ + filter_upwards [hcoeS, hkey, hcoeφ, hcoeψ, + Lp.coeFn_add (itoProcessAssembled hB T hBmeas hBcont φ) + (itoProcessAssembled hB T hBmeas hBcont ψ)] with z hzS hzk hzφ hzψ hza + rw [hzS, hzk, hza] + simp only [Pi.add_apply, hzφ, hzψ] + +/-- **Subtractivity** of the assembled Itô process (the SDE contraction consumes this: it turns +`itoProcessAssembled (σ∘X) − itoProcessAssembled (σ∘Y)` into `itoProcessAssembled (σ∘X − σ∘Y)`, +whose energy is `∫₀ᵀ ‖itoProcessCLM T t (σ∘X − σ∘Y)‖² dt`). -/ +theorem itoProcessAssembled_sub (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (φ ψ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + itoProcessAssembled hB T hBmeas hBcont (φ - ψ) + = itoProcessAssembled hB T hBmeas hBcont φ - itoProcessAssembled hB T hBmeas hBcont ψ := by + have hpredφ := itoContinuousMod_isStronglyPredictable hB T hBmeas hBcont φ + have hpredψ := itoContinuousMod_isStronglyPredictable hB T hBmeas hBcont ψ + have hpredS' : StronglyMeasurable[(natFiltration hBmeas).predictable] + (Function.uncurry (itoContinuousMod T hBmeas (φ - ψ))) := + itoContinuousMod_isStronglyPredictable hB T hBmeas hBcont (φ - ψ) + have hgSM : StronglyMeasurable[(natFiltration hBmeas).predictable] + (Function.uncurry (itoContinuousMod T hBmeas φ) + - Function.uncurry (itoContinuousMod T hBmeas ψ)) := + StronglyMeasurable.sub hpredφ hpredψ + have hkey : Function.uncurry (itoContinuousMod T hBmeas (φ - ψ)) + =ᵐ[trimMeasure (μ := μ) T hBmeas] + (Function.uncurry (itoContinuousMod T hBmeas φ) + - Function.uncurry (itoContinuousMod T hBmeas ψ)) := by + refine hpredS'.ae_eq_trim_of_stronglyMeasurable + (natFiltration hBmeas).predictable_le_prod hgSM ?_ + have hset : MeasurableSet {z : ℝ≥0 × Ω | + Function.uncurry (itoContinuousMod T hBmeas (φ - ψ)) z + = (Function.uncurry (itoContinuousMod T hBmeas φ) + - Function.uncurry (itoContinuousMod T hBmeas ψ)) z} := + measurableSet_eq_fun (hpredS'.mono (natFiltration hBmeas).predictable_le_prod).measurable + (hgSM.mono (natFiltration hBmeas).predictable_le_prod).measurable + rw [Filter.EventuallyEq, Measure.ae_prod_iff_ae_ae hset] + have hsub : ∀ᵐ t ∂(timeMeasureHorizon T), t ≤ T := by + rw [timeMeasureHorizon] + filter_upwards [ae_restrict_mem measurableSet_Ioc] with t ht using ht.2 + filter_upwards [hsub] with t htT + filter_upwards [itoContinuousMod_modification hB T hBmeas hBcont (φ - ψ) htT, + itoContinuousMod_modification hB T hBmeas hBcont φ htT, + itoContinuousMod_modification hB T hBmeas hBcont ψ htT, + Lp.coeFn_sub (itoProcessCLM hB T t hBmeas φ) (itoProcessCLM hB T t hBmeas ψ)] + with ω hωS hωφ hωψ hωsub + simp only [Function.uncurry, Pi.sub_apply] + rw [hωS, map_sub, hωsub, Pi.sub_apply, ← hωφ, ← hωψ] + have hcoeS : ⇑(itoProcessAssembled hB T hBmeas hBcont (φ - ψ)) + =ᵐ[trimMeasure (μ := μ) T hBmeas] Function.uncurry (itoContinuousMod T hBmeas (φ - ψ)) := + (memLp_itoContinuousMod hB T hBmeas hBcont (φ - ψ)).coeFn_toLp + have hcoeφ : ⇑(itoProcessAssembled hB T hBmeas hBcont φ) + =ᵐ[trimMeasure (μ := μ) T hBmeas] Function.uncurry (itoContinuousMod T hBmeas φ) := + (memLp_itoContinuousMod hB T hBmeas hBcont φ).coeFn_toLp + have hcoeψ : ⇑(itoProcessAssembled hB T hBmeas hBcont ψ) + =ᵐ[trimMeasure (μ := μ) T hBmeas] Function.uncurry (itoContinuousMod T hBmeas ψ) := + (memLp_itoContinuousMod hB T hBmeas hBcont ψ).coeFn_toLp + refine Lp.ext ?_ + filter_upwards [hcoeS, hkey, hcoeφ, hcoeψ, + Lp.coeFn_sub (itoProcessAssembled hB T hBmeas hBcont φ) + (itoProcessAssembled hB T hBmeas hBcont ψ)] with z hzS hzk hzφ hzψ hza + rw [hzS, hzk, hza] + simp only [Pi.sub_apply, hzφ, hzψ] + +end ItoIntegralProcessContinuousModification +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoProcessQV.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoProcessQV.lean new file mode 100644 index 0000000000..7b1683f699 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoProcessQV.lean @@ -0,0 +1,337 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.QuadraticVariationL2 +public import Mathlib.Algebra.Order.Chebyshev +public import Mathlib.RingTheory.WittVector.IsPoly +public import Mathlib.Tactic.ReduceModChar + +/-! +# Quadratic variation of an Itô process: the drift contributes nothing + +Saporito, Theorem 7.4.5: an Itô process `X_t = X₀ + ∫₀ᵗ a ds + ∫₀ᵗ σ dB` +has quadratic variation `⟨X⟩_t = ∫₀ᵗ σ² ds` — the drift drops out entirely. + +This file derives the theorem's celebrated content in the constant-`σ`, +Lipschitz-drift regime: for `X_t = X₀ + A_t + σ·B_t` with the drift path `A` +`Cₐ`-Lipschitz in time (exactly what `A_t = ∫₀ᵗ a ds` with `|a| ≤ Cₐ` gives), +the equipartition squared-increment sums of `X` over `[0, T]` converge in +mean square to `σ²·T = ∫₀ᵀ σ² ds`: + + `E[(∑ₖ (ΔXₖ)² − σ²T)²] → 0`. + +Expanding `(ΔXₖ)² = (ΔAₖ)² + 2σ·ΔAₖΔBₖ + σ²(ΔBₖ)²`, the three pieces die at +explicit rates: + +* the **pure drift** term is squeezed pathwise: `∑(ΔAₖ)² ≤ Cₐ²T²/n`; +* the **cross** term dies in `L²` at rate `1/n`: Cauchy–Schwarz against + `E[(ΔBₖ)²] = Δt`; +* the **diffusion** term is `σ²(∑(ΔBₖ)² − T)`, the Brownian quadratic + variation (`QuadraticVariationL2.sum_increment_sq_sub_sq_le`), with its + `2T²/n` Gaussian-kurtosis rate. + +Time- or state-dependent `σ` requires the stochastic-integral-as-process +layer (Summit B); the drift-immunity mechanism is identical. + +## Main results + +* `ItoProcessQV.tendsto_qv_ito_process` — `∑ₖ (ΔXₖ)² → σ²T` in `L²` + (Theorem 7.4.5 in the constant-`σ` regime, fully derived). + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Theorem 7.4.5 + +## Tags + +quadratic variation, Itô process, drift immunity, mean-square convergence, realized variance, +MSC 60H05, MSC 60J65, MSC 60G44 +-/ + +@[expose] public section + +namespace MathFin + +namespace ItoProcessQV + +open MeasureTheory ProbabilityTheory ItoIsometryAdapted MathFin.QuadraticVariationL2 Filter +open scoped NNReal ENNReal Topology + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + {B : ℝ≥0 → Ω → ℝ} + +private theorem integral_add_three_sq_le {E F G : Ω → ℝ} + (hE2_int : Integrable (fun ω ↦ (E ω) ^ 2) μ) + (hF2_int : Integrable (fun ω ↦ (F ω) ^ 2) μ) + (hG2_int : Integrable (fun ω ↦ (G ω) ^ 2) μ) : + ∫ ω, (E ω + F ω + G ω) ^ 2 ∂μ ≤ + 3 * ∫ ω, (E ω) ^ 2 ∂μ + 3 * ∫ ω, (F ω) ^ 2 ∂μ + 3 * ∫ ω, (G ω) ^ 2 ∂μ := by + have h3 : ∀ ω, (E ω + F ω + G ω) ^ 2 + ≤ 3 * (E ω) ^ 2 + 3 * (F ω) ^ 2 + 3 * (G ω) ^ 2 := fun ω ↦ by + nlinarith [sq_nonneg (E ω - F ω), sq_nonneg (E ω - G ω), sq_nonneg (F ω - G ω)] + calc ∫ ω, (E ω + F ω + G ω) ^ 2 ∂μ + _ ≤ ∫ ω, (3 * (E ω) ^ 2 + 3 * (F ω) ^ 2 + 3 * (G ω) ^ 2) ∂μ := + integral_mono_of_nonneg (Eventually.of_forall fun ω ↦ sq_nonneg _) + (((hE2_int.const_mul 3).add (hF2_int.const_mul 3)).add + (hG2_int.const_mul 3)) (Eventually.of_forall h3) + _ = 3 * ∫ ω, (E ω) ^ 2 ∂μ + 3 * ∫ ω, (F ω) ^ 2 ∂μ + 3 * ∫ ω, (G ω) ^ 2 ∂μ := by + have hEF : Integrable (fun ω ↦ 3 * (E ω) ^ 2 + 3 * (F ω) ^ 2) μ := + (hE2_int.const_mul 3).add (hF2_int.const_mul 3) + have hG3 : Integrable (fun ω ↦ 3 * (G ω) ^ 2) μ := hG2_int.const_mul 3 + rw [integral_add hEF hG3, + integral_add (hE2_int.const_mul 3) (hF2_int.const_mul 3), + integral_const_mul, integral_const_mul, integral_const_mul] + +/-- Per-`n` mean-square bound: the squared-increment sum of the Itô process +misses `σ²T` by at most `C/n`. -/ +private lemma qv_bound (hB : IsPreBrownianReal B μ) (hBmeas : ∀ t, Measurable (B t)) (T : ℝ≥0) + {X A : ℝ≥0 → Ω → ℝ} {X₀ : Ω → ℝ} {σ Ca : ℝ} (hCa : 0 ≤ Ca) + (hX : ∀ t ω, X t ω = X₀ ω + A t ω + σ * B t ω) + (hA_meas : ∀ t, Measurable (A t)) + (hA_lip : ∀ ⦃s t : ℝ≥0⦄, s ≤ t → ∀ ω, |A t ω - A s ω| ≤ Ca * ((t : ℝ) - s)) + {n : ℕ} (hn : 0 < n) : + ∫ ω, (∑ k ∈ Finset.range n, + (X (unifPart T n (k + 1)) ω - X (unifPart T n k) ω) ^ 2 + - σ ^ 2 * (T : ℝ)) ^ 2 ∂μ + ≤ (3 * (Ca ^ 2 * (T : ℝ) ^ 2) ^ 2 + 12 * σ ^ 2 * Ca ^ 2 * (T : ℝ) ^ 3 + + 6 * σ ^ 4 * (T : ℝ) ^ 2) / n := by + have : IsProbabilityMeasure μ := hB.isGaussianProcess.isProbabilityMeasure + have hn1 : (1 : ℝ) ≤ (n : ℝ) := by exact_mod_cast hn + have hnR : (0 : ℝ) < (n : ℝ) := by linarith + have hmono : Monotone (unifPart T n) := unifPart_mono T n + have hs0 : unifPart T n 0 = 0 := unifPart_zero T n + have hsn : unifPart T n n = T := unifPart_self T hn.ne' + have hle : ∀ k, unifPart T n k ≤ unifPart T n (k + 1) := fun k ↦ + hmono (Nat.le_succ k) + have hgapeq : ∀ k, (unifPart T n (k + 1) : ℝ) - unifPart T n k = (T : ℝ) / n := + unifPart_succ_sub T n + -- abbreviations for the three pieces + set E : Ω → ℝ := fun ω ↦ ∑ k ∈ Finset.range n, + (A (unifPart T n (k + 1)) ω - A (unifPart T n k) ω) ^ 2 with hE + set F : Ω → ℝ := fun ω ↦ 2 * σ * ∑ k ∈ Finset.range n, + (A (unifPart T n (k + 1)) ω - A (unifPart T n k) ω) + * (B (unifPart T n (k + 1)) ω - B (unifPart T n k) ω) with hF + set G : Ω → ℝ := fun ω ↦ σ ^ 2 * ((∑ k ∈ Finset.range n, + (B (unifPart T n (k + 1)) ω - B (unifPart T n k) ω) ^ 2) - (T : ℝ)) with hG + -- pointwise decomposition + have hsplit : ∀ ω, (∑ k ∈ Finset.range n, + (X (unifPart T n (k + 1)) ω - X (unifPart T n k) ω) ^ 2) + - σ ^ 2 * (T : ℝ) = E ω + F ω + G ω := by + intro ω + have hterm : ∀ k ∈ Finset.range n, + (X (unifPart T n (k + 1)) ω - X (unifPart T n k) ω) ^ 2 + = (A (unifPart T n (k + 1)) ω - A (unifPart T n k) ω) ^ 2 + + (2 * σ * ((A (unifPart T n (k + 1)) ω - A (unifPart T n k) ω) + * (B (unifPart T n (k + 1)) ω - B (unifPart T n k) ω)) + + σ ^ 2 * (B (unifPart T n (k + 1)) ω - B (unifPart T n k) ω) ^ 2) := + fun k _ ↦ by simp only [hX]; ring + rw [Finset.sum_congr rfl hterm, Finset.sum_add_distrib, Finset.sum_add_distrib, + ← Finset.mul_sum, ← Finset.mul_sum, hE, hF, hG] + ring + -- measurabilities + have hΔA_meas : ∀ k : ℕ, Measurable fun ω ↦ + A (unifPart T n (k + 1)) ω - A (unifPart T n k) ω := fun k ↦ + (hA_meas _).sub (hA_meas _) + have hΔB_meas : ∀ k : ℕ, Measurable fun ω ↦ + B (unifPart T n (k + 1)) ω - B (unifPart T n k) ω := fun k ↦ + (hBmeas _).sub (hBmeas _) + -- drift increment bound + have hΔA_bd : ∀ k : ℕ, ∀ ω, + |A (unifPart T n (k + 1)) ω - A (unifPart T n k) ω| ≤ Ca * ((T : ℝ) / n) := by + intro k ω + calc |A (unifPart T n (k + 1)) ω - A (unifPart T n k) ω| + ≤ Ca * ((unifPart T n (k + 1) : ℝ) - unifPart T n k) := hA_lip (hle k) ω + _ = Ca * ((T : ℝ) / n) := by rw [hgapeq k] + -- Brownian increment moments + have hΔB2 : ∀ k : ℕ, MemLp (fun ω ↦ + B (unifPart T n (k + 1)) ω - B (unifPart T n k) ω) 2 μ := fun k ↦ + (memLp_increment_four hB (unifPart T n k) (unifPart T n (k + 1))).mono_exponent + (by norm_num) + have hΔB_int_sq : ∀ k : ℕ, ∫ ω, + (B (unifPart T n (k + 1)) ω - B (unifPart T n k) ω) ^ 2 ∂μ = (T : ℝ) / n := by + intro k + rw [integral_increment_sq (μ := μ) hB (hle k), hgapeq k] + -- ===== bound for the pure-drift term ===== + have hE_nonneg : ∀ ω, 0 ≤ E ω := fun ω ↦ + Finset.sum_nonneg fun k _ ↦ sq_nonneg _ + have hE_bd : ∀ ω, E ω ≤ Ca ^ 2 * (T : ℝ) ^ 2 / n := by + intro ω + have hsum : E ω ≤ ∑ _k ∈ Finset.range n, (Ca * ((T : ℝ) / n)) ^ 2 := by + rw [hE] + refine Finset.sum_le_sum fun k _ ↦ ?_ + rw [← sq_abs] + exact pow_le_pow_left₀ (abs_nonneg _) (hΔA_bd k ω) 2 + rw [Finset.sum_const, Finset.card_range, nsmul_eq_mul] at hsum + calc E ω ≤ (n : ℝ) * (Ca * ((T : ℝ) / n)) ^ 2 := hsum + _ = Ca ^ 2 * (T : ℝ) ^ 2 / n := by field_simp + have hIE : ∫ ω, (E ω) ^ 2 ∂μ ≤ (Ca ^ 2 * (T : ℝ) ^ 2 / n) ^ 2 := by + have hpt : ∀ ω, (E ω) ^ 2 ≤ (Ca ^ 2 * (T : ℝ) ^ 2 / n) ^ 2 := fun ω ↦ + pow_le_pow_left₀ (hE_nonneg ω) (hE_bd ω) 2 + calc ∫ ω, (E ω) ^ 2 ∂μ + ≤ ∫ _ω, (Ca ^ 2 * (T : ℝ) ^ 2 / n) ^ 2 ∂μ := + integral_mono_of_nonneg (Eventually.of_forall fun ω ↦ sq_nonneg _) + (integrable_const _) (Eventually.of_forall hpt) + _ = (Ca ^ 2 * (T : ℝ) ^ 2 / n) ^ 2 := by + rw [integral_const] + simp [measureReal_def] + -- ===== bound for the diffusion term ===== + have hG_inner_memLp : MemLp (fun ω ↦ (∑ k ∈ Finset.range n, + (B (unifPart T n (k + 1)) ω - B (unifPart T n k) ω) ^ 2) - (T : ℝ)) 2 μ := by + have hsum : MemLp (fun ω ↦ ∑ k ∈ Finset.range n, + (B (unifPart T n (k + 1)) ω - B (unifPart T n k) ω) ^ 2) 2 μ := by + apply memLp_finsetSum + intro k _ + simpa using memLp_increment_sq_centered_two hB (unifPart T n k) (unifPart T n (k + 1)) 0 + exact hsum.sub (memLp_const (T : ℝ)) + have hIG : ∫ ω, (G ω) ^ 2 ∂μ ≤ σ ^ 4 * (2 * ((T : ℝ) / n) * T) := by + have hbound := sum_increment_sq_sub_sq_le (μ := μ) hB hBmeas hmono hs0 n + (fun k _ ↦ le_of_eq (hgapeq k)) + rw [hsn] at hbound + have hpt : ∀ ω, (G ω) ^ 2 = σ ^ 4 * ((∑ k ∈ Finset.range n, + (B (unifPart T n (k + 1)) ω - B (unifPart T n k) ω) ^ 2) - (T : ℝ)) ^ 2 := + fun ω ↦ by simp only [hG]; ring + have hcongr : ∫ ω, (G ω) ^ 2 ∂μ = ∫ ω, σ ^ 4 * ((∑ k ∈ Finset.range n, + (B (unifPart T n (k + 1)) ω - B (unifPart T n k) ω) ^ 2) - (T : ℝ)) ^ 2 ∂μ := + integral_congr_ae (Eventually.of_forall hpt) + rw [hcongr, integral_const_mul] + exact mul_le_mul_of_nonneg_left hbound (by positivity) + -- ===== bound for the cross term ===== + have hΔAB_memLp : ∀ k ∈ Finset.range n, MemLp (fun ω ↦ + (A (unifPart T n (k + 1)) ω - A (unifPart T n k) ω) + * (B (unifPart T n (k + 1)) ω - B (unifPart T n k) ω)) 2 μ := by + intro k _ + refine MemLp.of_le ((hΔB2 k).const_mul (Ca * ((T : ℝ) / n))) + ((hΔA_meas k).mul (hΔB_meas k)).aestronglyMeasurable + (Eventually.of_forall fun ω ↦ ?_) + simp only [Real.norm_eq_abs, abs_mul] + rw [abs_of_nonneg hCa, abs_of_nonneg (show (0 : ℝ) ≤ (T : ℝ) / n by positivity)] + exact mul_le_mul_of_nonneg_right (hΔA_bd k ω) (abs_nonneg _) + have hF_memLp : MemLp F 2 μ := by + rw [hF] + exact (memLp_finsetSum _ hΔAB_memLp).const_mul _ + have hIF : ∫ ω, (F ω) ^ 2 ∂μ ≤ 4 * σ ^ 2 * Ca ^ 2 * (T : ℝ) ^ 3 / n := by + -- pointwise: F² ≤ 4σ²(CaT/n)² · n · ∑(ΔBₖ)² + have hpt : ∀ ω, (F ω) ^ 2 ≤ 4 * σ ^ 2 * (Ca * ((T : ℝ) / n)) ^ 2 + * ((n : ℝ) * ∑ k ∈ Finset.range n, + (B (unifPart T n (k + 1)) ω - B (unifPart T n k) ω) ^ 2) := by + intro ω + let a (k : ℕ) := A (unifPart T n (k + 1)) ω - A (unifPart T n k) ω + let b (k : ℕ) := B (unifPart T n (k + 1)) ω - B (unifPart T n k) ω + have ha : (∑ k ∈ Finset.range n, (a k) ^ 2) ≤ (n : ℝ) * (Ca * ((T : ℝ) / n)) ^ 2 := by + calc (∑ k ∈ Finset.range n, (a k) ^ 2) + _ ≤ ∑ _k ∈ Finset.range n, (Ca * ((T : ℝ) / n)) ^ 2 := by + exact Finset.sum_le_sum fun k _ ↦ by + rw [← sq_abs] + exact pow_le_pow_left₀ (abs_nonneg _) (hΔA_bd k ω) 2 + _ = _ := by simp [nsmul_eq_mul] + rw [hF, mul_pow] + change (2 * σ) ^ 2 * (∑ k ∈ Finset.range n, a k * b k) ^ 2 ≤ + 4 * σ ^ 2 * (Ca * ((T : ℝ) / n)) ^ 2 * (n * ∑ k ∈ Finset.range n, (b k) ^ 2) + calc (2 * σ) ^ 2 * (∑ k ∈ Finset.range n, a k * b k) ^ 2 + _ ≤ (2 * σ) ^ 2 * + ((∑ k ∈ Finset.range n, (a k) ^ 2) * (∑ k ∈ Finset.range n, (b k) ^ 2)) := by + gcongr + exact Finset.sum_mul_sq_le_sq_mul_sq _ _ _ + _ ≤ (2 * σ) ^ 2 * (n * (Ca * ((T : ℝ) / n)) ^ 2 * + (∑ k ∈ Finset.range n, (b k) ^ 2)) := by gcongr + _ = _ := by ring + have hRHS_int : Integrable (fun ω ↦ 4 * σ ^ 2 * (Ca * ((T : ℝ) / n)) ^ 2 + * ((n : ℝ) * ∑ k ∈ Finset.range n, + (B (unifPart T n (k + 1)) ω - B (unifPart T n k) ω) ^ 2)) μ := by + refine Integrable.const_mul ?_ _ + refine Integrable.const_mul ?_ _ + exact integrable_finsetSum _ fun k _ ↦ (hΔB2 k).integrable_sq + calc ∫ ω, (F ω) ^ 2 ∂μ + ≤ ∫ ω, 4 * σ ^ 2 * (Ca * ((T : ℝ) / n)) ^ 2 + * ((n : ℝ) * ∑ k ∈ Finset.range n, + (B (unifPart T n (k + 1)) ω - B (unifPart T n k) ω) ^ 2) ∂μ := + integral_mono_of_nonneg (Eventually.of_forall fun ω ↦ sq_nonneg _) + hRHS_int (Eventually.of_forall hpt) + _ = 4 * σ ^ 2 * (Ca * ((T : ℝ) / n)) ^ 2 * ((n : ℝ) + * ∑ k ∈ Finset.range n, ((T : ℝ) / n)) := by + rw [integral_const_mul, integral_const_mul, integral_finsetSum _ + (fun k _ ↦ (hΔB2 k).integrable_sq)] + congr 2 + exact Finset.sum_congr rfl fun k _ ↦ hΔB_int_sq k + _ = 4 * σ ^ 2 * Ca ^ 2 * (T : ℝ) ^ 3 / n := by + rw [Finset.sum_const, Finset.card_range, nsmul_eq_mul] + field_simp + -- ===== integrabilities for the assembly ===== + have hE_meas : Measurable E := by + rw [hE] + exact Finset.measurable_sum _ fun k _ ↦ (hΔA_meas k).pow_const 2 + have hE2_int : Integrable (fun ω ↦ (E ω) ^ 2) μ := by + refine Integrable.mono' (integrable_const ((Ca ^ 2 * (T : ℝ) ^ 2 / n) ^ 2)) + ((hE_meas.pow_const 2).aestronglyMeasurable) + (Eventually.of_forall fun ω ↦ ?_) + rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)] + exact pow_le_pow_left₀ (hE_nonneg ω) (hE_bd ω) 2 + have hF2_int : Integrable (fun ω ↦ (F ω) ^ 2) μ := hF_memLp.integrable_sq + have hG2_int : Integrable (fun ω ↦ (G ω) ^ 2) μ := by + have : MemLp G 2 μ := by + rw [hG] + exact hG_inner_memLp.const_mul _ + exact this.integrable_sq + -- ===== assembly ===== + calc ∫ ω, (∑ k ∈ Finset.range n, + (X (unifPart T n (k + 1)) ω - X (unifPart T n k) ω) ^ 2 + - σ ^ 2 * (T : ℝ)) ^ 2 ∂μ + = ∫ ω, (E ω + F ω + G ω) ^ 2 ∂μ := + integral_congr_ae (Eventually.of_forall fun ω ↦ by simp only [hsplit]) + _ ≤ 3 * ∫ ω, (E ω) ^ 2 ∂μ + 3 * ∫ ω, (F ω) ^ 2 ∂μ + 3 * ∫ ω, (G ω) ^ 2 ∂μ := + integral_add_three_sq_le hE2_int hF2_int hG2_int + _ ≤ 3 * (Ca ^ 2 * (T : ℝ) ^ 2 / n) ^ 2 + 3 * (4 * σ ^ 2 * Ca ^ 2 * (T : ℝ) ^ 3 / n) + + 3 * (σ ^ 4 * (2 * ((T : ℝ) / n) * T)) := by + gcongr + _ ≤ (3 * (Ca ^ 2 * (T : ℝ) ^ 2) ^ 2 + 12 * σ ^ 2 * Ca ^ 2 * (T : ℝ) ^ 3 + + 6 * σ ^ 4 * (T : ℝ) ^ 2) / n := by + rw [div_pow] + have hn2 : (n : ℝ) ≤ (n : ℝ) ^ 2 := by nlinarith + have h1 : 3 * ((Ca ^ 2 * (T : ℝ) ^ 2) ^ 2 / (n : ℝ) ^ 2) + ≤ 3 * ((Ca ^ 2 * (T : ℝ) ^ 2) ^ 2 / n) := by + gcongr + have h2 : (3 : ℝ) * (4 * σ ^ 2 * Ca ^ 2 * (T : ℝ) ^ 3 / n) + = 12 * σ ^ 2 * Ca ^ 2 * (T : ℝ) ^ 3 / n := by ring + have h3' : (3 : ℝ) * (σ ^ 4 * (2 * ((T : ℝ) / n) * T)) + = 6 * σ ^ 4 * (T : ℝ) ^ 2 / n := by ring + rw [h2, h3'] + rw [show (3 * (Ca ^ 2 * (T : ℝ) ^ 2) ^ 2 + 12 * σ ^ 2 * Ca ^ 2 * (T : ℝ) ^ 3 + + 6 * σ ^ 4 * (T : ℝ) ^ 2) / n + = 3 * ((Ca ^ 2 * (T : ℝ) ^ 2) ^ 2 / n) + 12 * σ ^ 2 * Ca ^ 2 * (T : ℝ) ^ 3 / n + + 6 * σ ^ 4 * (T : ℝ) ^ 2 / n from by ring] + gcongr + +/-- **Theorem 7.4.5 (quadratic variation of an Itô process), constant-`σ` +regime, fully derived.** For `X_t = X₀ + A_t + σ·B_t` with `A` a +`Cₐ`-Lipschitz drift path (the integrated form of a bounded drift), the +equipartition squared-increment sums of `X` over `[0, T]` converge in mean +square to `σ²·T = ∫₀ᵀ σ² ds`: the **drift contributes nothing** to the +quadratic variation. -/ +theorem tendsto_qv_ito_process (hB : IsPreBrownianReal B μ) + (hBmeas : ∀ t, Measurable (B t)) (T : ℝ≥0) + {X A : ℝ≥0 → Ω → ℝ} {X₀ : Ω → ℝ} {σ Ca : ℝ} (hCa : 0 ≤ Ca) + (hX : ∀ t ω, X t ω = X₀ ω + A t ω + σ * B t ω) + (hA_meas : ∀ t, Measurable (A t)) + (hA_lip : ∀ ⦃s t : ℝ≥0⦄, s ≤ t → ∀ ω, |A t ω - A s ω| ≤ Ca * ((t : ℝ) - s)) : + Tendsto (fun n : ℕ ↦ ∫ ω, (∑ k ∈ Finset.range n, + (X (unifPart T n (k + 1)) ω - X (unifPart T n k) ω) ^ 2 + - σ ^ 2 * (T : ℝ)) ^ 2 ∂μ) + atTop (𝓝 0) := by + have : IsProbabilityMeasure μ := hB.isGaussianProcess.isProbabilityMeasure + refine squeeze_zero' + (g := fun n : ℕ ↦ (3 * (Ca ^ 2 * (T : ℝ) ^ 2) ^ 2 + + 12 * σ ^ 2 * Ca ^ 2 * (T : ℝ) ^ 3 + 6 * σ ^ 4 * (T : ℝ) ^ 2) / n) + (Eventually.of_forall fun n ↦ integral_nonneg fun ω ↦ sq_nonneg _) ?_ + (tendsto_const_div_atTop_nhds_zero_nat _) + filter_upwards [eventually_gt_atTop 0] with n hn + exact qv_bound hB hBmeas T hCa hX hA_meas hA_lip hn + +end ItoProcessQV + +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Ito/ItoRiemannSum.lean b/LeanPool/MathFin/Probability/Brownian/Ito/ItoRiemannSum.lean new file mode 100644 index 0000000000..bd7a0f53be --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Ito/ItoRiemannSum.lean @@ -0,0 +1,98 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.UnifPart +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralL2 + +/-! # The Riemann–Itô sum + +The one left-endpoint sum of the Itô stack: for an integrand `θ : ℝ≥0 → Ω → ℝ` and the uniform +partition of `[0, T]` into `n` cells (`unifPart`), + + `riemannσ θ T n ω = ∑_{k simp [ouGen, hermiteReal_zero] + | succ n ih => + rw [hermiteReal_succ, ouGen_sub, ouGen_X_mul, ouGen_derivative, ih, + Real.sq_sqrt (by norm_num), derivative_smul] + simp only [one_smul, ← Polynomial.C_mul', Nat.cast_succ, map_add, map_one, map_neg, + map_ofNat] + ring + +/-! ## The stationary scale: `He_n(x/s)` (Calc 14.14 in general position) + +At the stationary scale `s² = σ²/2κ`, the eigenfunctions are the *rescaled* Hermite +polynomials `He_n(x/s)`. The chain rule for the scaling `x ↦ x/s` conjugates the general +generator into the unit one — the diffusion coefficient `σ²/2` loses exactly the factor +`s²` that the two derivatives of the scaling gain — so the unit eigenidentity transfers +with eigenvalue `-nκ` (the chapter's `L He_n = -nκ He_n`, Pearson-table OU row). -/ + +/-- The scaled Hermite polynomial `q_n(x) = He_n(x/s)`: `hermiteReal n` composed with the +scaling `X ↦ s⁻¹ • X`. -/ +noncomputable def scaledHermite (s : ℝ) (n : ℕ) : Polynomial ℝ := + (hermiteReal n).comp (s⁻¹ • X) + +/-- `q_n(x) = He_n(x/s)`, pointwise. -/ +theorem scaledHermite_eval (n : ℕ) (x s : ℝ) : + Polynomial.eval x (scaledHermite s n) = Polynomial.eval (x / s) (hermiteReal n) := by + have hx : Polynomial.eval x (s⁻¹ • X) = x / s := by + rw [Polynomial.eval_smul, smul_eq_mul, Polynomial.eval_X, div_eq_mul_inv, mul_comm] + rw [scaledHermite, Polynomial.eval_comp, hx] + +/-- The unit generator spelled out: at `κ = 1`, `σ² = 2` the OU generator is the +operator `p ↦ -(X * p') + p''` — the classical Hermite ODE operator. -/ +theorem ouGen_sqrt2 (f : Polynomial ℝ) : + ouGen 1 (Real.sqrt 2) f = -(X * f.derivative) + f.derivative.derivative := by + rw [ouGen, Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 2), div_self two_ne_zero] + simp + +/-- **The scaling conjugation (the chain rule for `x ↦ x/s`).** Composing with the +scaling `X ↦ s⁻¹ • X` conjugates the general generator into `κ` times the unit one: +the drift coefficient survives, and the diffusion coefficient `σ²/2` divided by the +`s²` that the two chain-rule factors contribute is exactly `κ` (this is where the +stationary-scale identity `2κs² = σ²` enters). -/ +theorem ouGen_comp_smulX (κ σ s : ℝ) (hs : s ≠ 0) (h : 2 * κ * s ^ 2 = σ ^ 2) + (f : Polynomial ℝ) : + ouGen κ σ (f.comp (s⁻¹ • X)) + = κ • (ouGen 1 (Real.sqrt 2) f).comp (s⁻¹ • X) := by + have hX : (s⁻¹ • X).derivative = Polynomial.C s⁻¹ := by + rw [← Polynomial.C_mul', derivative_mul, derivative_C, derivative_X, zero_mul, + zero_add, mul_one] + have hd1 : (f.comp (s⁻¹ • X)).derivative + = Polynomial.C s⁻¹ * f.derivative.comp (s⁻¹ • X) := by + rw [Polynomial.derivative_comp, hX] + have hd2 : (f.comp (s⁻¹ • X)).derivative.derivative + = Polynomial.C (s⁻¹ * s⁻¹) * f.derivative.derivative.comp (s⁻¹ • X) := by + rw [hd1, derivative_mul, derivative_C, zero_mul, zero_add, Polynomial.derivative_comp, + hX, ← mul_assoc, ← map_mul] + have hκc : σ ^ 2 / 2 * (s⁻¹ * s⁻¹) = κ := by + rw [← h] + field_simp + rw [ouGen, hd2, hd1] + simp only [← Polynomial.C_mul'] + rw [show Polynomial.C (σ ^ 2 / 2) + * (Polynomial.C (s⁻¹ * s⁻¹) + * (derivative (derivative f)).comp (Polynomial.C s⁻¹ * X)) + = Polynomial.C (σ ^ 2 / 2 * (s⁻¹ * s⁻¹)) + * (derivative (derivative f)).comp (Polynomial.C s⁻¹ * X) from by + rw [← mul_assoc, ← map_mul], + hκc, ouGen_sqrt2, Polynomial.add_comp, Polynomial.neg_comp, Polynomial.mul_comp, + Polynomial.X_comp] + ring + +/-- **The scaled eigenidentity, polynomial level (Calc 14.14 / Pearson-table OU row).** +At the stationary scale `s² = σ²/2κ`, the generator maps the scaled Hermite polynomial +`q_n = He_n(x/s)` to `-(nκ) • q_n`. The eigenvalue is `-nκ` — the OU row of the +eigenvalue table, and the diagonal of the chapter's moment ladder (not formalized here). -/ +theorem ouGen_scaledHermite {κ σ s : ℝ} (hs : s ≠ 0) (h : 2 * κ * s ^ 2 = σ ^ 2) + (n : ℕ) : + ouGen κ σ (scaledHermite s n) = (-(n : ℝ) * κ) • scaledHermite s n := by + rw [scaledHermite, ouGen_comp_smulX κ σ s hs h, ouGen_hermite, Polynomial.smul_comp, + smul_smul, mul_comm] + +/-- **The scaled eigenidentity, eval level.** For +`q_n(x) = He_n(x/s)`: `eval x (L q_n) = -(nκ) · eval x q_n` at every point `x`. -/ +theorem eval_ouGen_scaledHermite {κ σ s : ℝ} (hs : s ≠ 0) (h : 2 * κ * s ^ 2 = σ ^ 2) + (n : ℕ) (x : ℝ) : + Polynomial.eval x (ouGen κ σ (scaledHermite s n)) + = -(n : ℝ) * κ * Polynomial.eval x (scaledHermite s n) := by + rw [ouGen_scaledHermite hs h n, Polynomial.eval_smul, smul_eq_mul] + +/-- `He₂ = X² - 1` over `ℝ`. -/ +theorem hermiteReal_two : hermiteReal 2 = X * X - 1 := by + have h2 : Polynomial.hermite 2 = (X : Polynomial ℤ) * X - 1 := by + rw [show (2 : ℕ) = 1 + 1 from rfl, Polynomial.hermite_succ, Polynomial.hermite_one, + derivative_X] + rw [hermiteReal, h2] + simp + +/-- **The `n = 2` mechanism of Calc 14.14.** With `f = (x/s)² - 1` (the +evaluated `He_2(x/s)`), the generator output evaluates to `-(2κ) · f` — the drift term +preserves the degree (the chapter's text says it "lowers" it, a slip), the diffusion term +supplies exactly the constant that closes the polynomial back on itself, and the +arithmetic uses `σ²/s² = 2κ` (via the stationary-scale hypothesis). -/ +theorem eval_ouGen_scaledHermite_two {κ σ s : ℝ} (hs : s ≠ 0) (h : 2 * κ * s ^ 2 = σ ^ 2) + (x : ℝ) : + Polynomial.eval x (ouGen κ σ (scaledHermite s 2)) + = -(2 : ℝ) * κ * ((x / s) ^ 2 - 1) := by + rw [eval_ouGen_scaledHermite hs h 2 x, scaledHermite_eval, hermiteReal_two] + simp only [Polynomial.eval_sub, Polynomial.eval_mul, Polynomial.eval_X, + Polynomial.eval_one] + ring + +/-! ## The Gaussian no-flux condition (Calc 14.13, one dimension) + +The reversibility mechanism of the spectral route, at its Gaussian instance: the +stationary density `π(x) ∝ exp(-x²/(2s²))` has score `π'/π = -x/s²`, so the drift and +diffusion fluxes cancel — `(σ²/2)·π' = -κx·π` when `s² = σ²/2κ`. The score computed +below is the scale-`s` counterpart of the `n = 1` case of the Rodrigues formula +`hermite_eq_deriv_gaussian` (`Mathlib/RingTheory/Polynomial/Hermite/Gaussian.lean`, unit +scale: Hermite polynomials as Gaussian-density derivatives), proved here directly by the +chain rule; the no-flux lemma is that score times `σ²/2` under the stationary-scale +identity. -/ + +/-- **The Gaussian score (Calc 14.13's derivative, eval level).** The unnormalized +Gaussian density `π(x) = exp(-x²/(2s²))` satisfies `π'(x) = -(x/s²)·π(x)`: the log-density +is `-(x/s)²/2`, whose gradient `-(x/s²)` is the score. `deriv_exp` + the chain rule. (That +`π` is the OU stationary density at `s² = σ²/2κ` is not proved here.) -/ +theorem gaussianScore_ou (s : ℝ) (x : ℝ) : + deriv (fun y ↦ Real.exp (-(y ^ 2 / (2 * s ^ 2)))) x + = -(x / s ^ 2) * Real.exp (-(x ^ 2 / (2 * s ^ 2))) := by + have h2 : HasDerivAt (fun y ↦ -(y ^ 2 / (2 * s ^ 2))) (-(x / s ^ 2)) x := by + have h1 := (hasDerivAt_pow 2 x).div_const (2 * s ^ 2) + have hval : ((2 : ℕ) * x ^ (2 - 1)) / (2 * s ^ 2) = x / s ^ 2 := by + rw [pow_one, Nat.cast_ofNat, mul_div_mul_left _ _ two_ne_zero] + rw [hval] at h1 + exact h1.neg + exact (h2.exp.deriv).trans (by ring) + +/-- **The no-flux condition (Calc 14.13, stationary Gaussian instance).** At the +stationary scale `s² = σ²/2κ`, the drift flux `-κx·π` balances the diffusion flux +`(σ²/2)·π'`: the condition `μπ = ½(σ²π)'` that yields the divergence form (14.19) +and hence the generator's symmetry (the symmetry itself is not proved here). -/ +theorem gaussianNoFlux_ou {κ σ s : ℝ} (hs : s ≠ 0) (h : 2 * κ * s ^ 2 = σ ^ 2) (x : ℝ) : + σ ^ 2 / 2 * deriv (fun y ↦ Real.exp (-(y ^ 2 / (2 * s ^ 2)))) x + = -(κ * x) * Real.exp (-(x ^ 2 / (2 * s ^ 2))) := by + rw [gaussianScore_ou s x, ← h] + field_simp + +/-! ## The gap bias (the "asymptotic rate" remark, two modes) + +The chapter's effective decay rate of a multimodal expansion is the weighted average +`Σ λ_n c_n e^{-λ_n t} / Σ c_n e^{-λ_n t}`. With two modes and positive weights, that +average (here with rates `l₁ ≤ l₂`) is at least the slowest rate `l₁` for every `t` — so +fitting a single exponential to a two-mode decay reads off a rate at least `l₁` and never +understates mean reversion (the chapter's second, independent route to the Bagaria ch. 20 +estimation bias). Only the pointwise bound is proved here; the fitted-exponential +consequence is not formalized. -/ + +/-- **The two-mode gap inequality.** For rates `l₁ ≤ l₂`, positive mode weights +`0 < c₁, c₂` and any `t`, the effective decay rate of the two-mode mixture — the +weighted average of the rates, weighted by the surviving mode masses — is at least the +slowest rate `l₁`. The gap `l₂ - l₁` shows up as the excess carried by the fast mode; +the chapter's one-exponential-fit warning is a consequence of this pointwise bound (not +proved here). -/ +theorem twoMode_rate_ge_slowest {l₁ l₂ c₁ c₂ t : ℝ} (hl₂ : l₁ ≤ l₂) + (hc₁ : 0 < c₁) (hc₂ : 0 < c₂) : + l₁ ≤ (l₁ * c₁ * Real.exp (-(l₁ * t)) + l₂ * c₂ * Real.exp (-(l₂ * t))) + / (c₁ * Real.exp (-(l₁ * t)) + c₂ * Real.exp (-(l₂ * t))) := by + set E₁ := Real.exp (-(l₁ * t)) + set E₂ := Real.exp (-(l₂ * t)) + have hE₁pos : 0 < E₁ := Real.exp_pos _ + have hE₂pos : 0 < E₂ := Real.exp_pos _ + have hD : (c₁ * E₁ + c₂ * E₂) ≠ 0 := + (add_pos (mul_pos hc₁ hE₁pos) (mul_pos hc₂ hE₂pos)).ne' + have hkey : 0 ≤ (l₂ - l₁) * (c₂ * E₂) := + mul_nonneg (sub_nonneg.2 hl₂) (mul_nonneg hc₂.le hE₂pos.le) + field_simp + nlinarith [hkey] + +/-! ## The swirl (Ex. 14.2): matrix algebra only + +The chapter's two-dimensional counterexample is the swirl `dZ = -AZ dt + dW` with +`A = [[1, θ], [-θ, 1]]`, whose antisymmetric part rotates. One fragment of it needs no process +theory: the stationary covariance is isotropic (a symmetric `Σ` with `AΣ + ΣAᵀ = I` is `½I`), so +the rotation drops out of the snapshot. In the chapter's argument this is why a snapshot cannot +detect non-reversibility; that conclusion, and the complex spectrum `-1 ± iθ` of `-A`, are not +formalized here. -/ + +/-- **The swirl's stationary covariance is isotropic.** Any symmetric `Σ` +solving the stationary-covariance equation `AΣ + ΣAᵀ = I` for the swirl matrix +`A = [[1, θ], [-θ, 1]]` is `½I`: the solution does not depend on the rotation `θ`, so the +snapshot carries no trace of the circulation. In the chapter's argument (Ex. 14.2) this is why a +stationary snapshot alone cannot detect that the drift is non-reversible for `θ ≠ 0` — that +non-reversibility conclusion itself is not formalized here. -/ +theorem swirl_isotropy (θ a b d : ℝ) + (h : (!![(1 : ℝ), θ; -θ, 1] : Matrix (Fin 2) (Fin 2) ℝ) * !![a, b; b, d] + + !![a, b; b, d] * !![(1 : ℝ), -θ; θ, 1] = 1) : + (!![(a : ℝ), b; b, d] : Matrix (Fin 2) (Fin 2) ℝ) + = !![(1 / 2 : ℝ), 0; 0, 1 / 2] := by + have hM : ((!![(1 : ℝ), θ; -θ, 1] : Matrix (Fin 2) (Fin 2) ℝ) * !![a, b; b, d] + + !![a, b; b, d] * !![(1 : ℝ), -θ; θ, 1]) + = !![2 * a + 2 * θ * b, 2 * b + θ * d - θ * a; 2 * b + θ * d - θ * a, + 2 * d - 2 * θ * b] := by + ext i j + fin_cases i <;> fin_cases j <;> + simp <;> ring + rw [hM] at h + have e00 : 2 * a + 2 * θ * b = 1 := by simpa using congrFun (congrFun h 0) 0 + have e01 : 2 * b + θ * d - θ * a = 0 := by simpa using congrFun (congrFun h 0) 1 + have e11 : 2 * d - 2 * θ * b = 1 := by simpa using congrFun (congrFun h 1) 1 + have hkey : (1 + θ ^ 2) * b = 0 := by linear_combination (1 / 2) * e01 - (θ / 4) * (e11 - e00) + have hb : b = 0 := (mul_eq_zero.1 hkey).resolve_left (by positivity) + subst hb + have ha : a = 1 / 2 := by linarith [e00] + have hd : d = 1 / 2 := by linarith [e11] + apply Matrix.ext + intro i j + fin_cases i <;> fin_cases j <;> + simp [ha, hd] + +end MathFin.OUSpectral diff --git a/LeanPool/MathFin/Probability/Brownian/SDE/SDEExistence.lean b/LeanPool/MathFin/Probability/Brownian/SDE/SDEExistence.lean new file mode 100644 index 0000000000..18decd92a9 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/SDE/SDEExistence.lean @@ -0,0 +1,655 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.DriftProcessPredictable +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoProcessPredictable +public import Mathlib.Topology.Algebra.Order.Floor +public import Mathlib.Topology.MetricSpace.Contracting + +/-! # SDE existence/uniqueness via Picard on `E` (build) + +The strong solution of `dX = b(X)dt + σ(X)dB`, `X₀ = η` is the fixed point of the Picard iterate +`Φ(X)_t = η + ∫₀ᵗ b(X_s) ds + ∫₀ᵗ σ(X_s) dB_s`, built as a self-map of the predictable `L²` space +`E := Lp ℝ 2 (trimMeasure T)`. Both analytic terms already land back in `E` — the drift as a +genuine CLM `driftProcessAssembled : E →L[ℝ] E`, the Itô term as the element-valued linear map +`itoProcessAssembled : E → E` (built from a continuous modification, so *not* a CLM — its linearity +is re-established a.e.). This file wires them into the Picard map, proves the contraction estimate +`‖Φ(X) − Φ(Y)‖ ≤ (T·L_b + √T·L_σ)·‖X − Y‖`, and — when that constant is `< 1` — obtains the **unique +fixed point** (`picardSolution`) via Banach's theorem: existence and uniqueness of the strong +solution in `E`. + +The `T` vs `√T` asymmetry is structural: both terms integrate a `[0,t]` quantity over `t ∈ [0,T]`, +but Cauchy–Schwarz already spends a factor of time inside each drift slice (leaving the full `T`), +whereas the Itô isometry bounds each `[0,t]` energy flatly by the total energy (so only `√T` +survives the outer time-integral). The `driftProcessAssembled_norm_le` (`≤ T‖·‖`) and +`itoProcessAssembled_norm_le` (`≤ √T‖·‖`) bounds live with their operators in +`DriftProcessPredictable` / `ItoProcessPredictable`. + +* `lipComp` — the coefficient composition `f ∘ X ∈ E` (centered via `lipschitz_sub_const`); + `lipComp_sub_norm_le` — its `L`-Lipschitz bound. +* `picardMap` — the Picard iterate `Φ : E → E`. +* `picardMap_contraction` — the contraction estimate; `picardMap_contractingWith` — as + `ContractingWith`. +* `picardSolution` — the strong solution (the fixed point); `picardMap_exists_unique_fixedPoint` — + `∃!`. + +**All horizons.** The smallness condition is removed by iterating: the *band energy* +`bandEnergy T s Z = ∫_{(0,s]×Ω} Z²` of the Picard difference satisfies the Volterra inequality +`bandEnergy s (Φ X − Φ Y) ≤ 2(T L_b² + L_σ²) ∫₀ˢ bandEnergy u (X − Y) du` (the Itô term exactly, +by the Itô isometry on bands; the drift term by Cauchy–Schwarz on simple processes, extended by +density), hence `‖Φⁿ X − Φⁿ Y‖² ≤ (2(T L_b² + L_σ²) T)ⁿ/n! · ‖X − Y‖²`. For large `n` the iterate +`Φⁿ` is a contraction and Mathlib's `ContractingWith.isFixedPt_fixedPoint_iterate` gives the unique +fixed point for every `T` (`picardMap_exists_unique_fixedPoint_any_horizon`). The short-horizon +`picardSolution` is kept: downstream modules consume it with its `ContractingWith` hypothesis. + +The remaining bridge to the benchmark `sc-thm-8.2.5` (its `ℝ`-time, pointwise-per-`t`, +`intervalIntegral`-drift, opaque-`Iσ` shape) is the next step. + +## Main definitions + +* `lipComp`: the composition `f ∘ X ∈ E` of a Lipschitz `f : ℝ → ℝ` with a process `X` in the + predictable `L²` space `E`, centred at `f 0`. +* `picardMap`: the Picard iterate + `Φ(X) = η + driftProcessAssembled(b∘X) + itoProcessAssembled(σ∘X)`, a self-map of `E`. +* `picardSolution`: the fixed point of `picardMap` given by Banach's theorem when it is a + contraction. + +* `bandEnergy`: the `L²` mass `∫_{(0,s]×Ω} Z²` of a process of `E` on a time band. +* `picardRate`: the Volterra constant `2(T L_b² + L_σ²)`. + +## Main results + +* `lipComp_sub_norm_le`: `lipComp` is `L`-Lipschitz in `X` for the `E`-norm. +* `picardMap_contraction`: `‖Φ(X) − Φ(Y)‖ ≤ (T·L_b + √T·L_σ)·‖X − Y‖`. +* `picardMap_contractingWith`: `picardMap` is a contraction on `E` once `T·L_b + √T·L_σ < 1`. +* `picardMap_exists_unique_fixedPoint`: in that regime `picardSolution` is a fixed point of the + Picard map and the only one in `E`. +* `bandEnergy_itoProcessAssembled`, `bandEnergy_driftProcessAssembled_le`, + `bandEnergy_picardMap_sub_le`: the band-by-band (Volterra) estimates. +* `picardMap_iterate_norm_sq_le`: `‖Φⁿ X − Φⁿ Y‖² ≤ (2(T L_b² + L_σ²) T)ⁿ/n! · ‖X − Y‖²`. +* `picardMap_exists_unique_fixedPoint_any_horizon`: for every horizon `T`, the Picard map has a + unique fixed point in `E`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Thm 8.2.5 + +## Tags + +stochastic differential equation, strong solution, Picard iteration, Banach fixed point, +Lipschitz coefficients, existence and uniqueness, MSC 60H10, MSC 60H05 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Filter Topology +open scoped NNReal ENNReal + +namespace MathFin +namespace SDEExistence +open ItoIntegralL2 ItoIntegralCLM ItoIntegralProcess ItoIntegralProcessGeneral + ItoIntegralProcessContinuousModification + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} + +/-- Centering a Lipschitz coefficient at `0`: `x ↦ f x − f 0` is `L`-Lipschitz and +sends `0 ↦ 0`, so it composes with an `L²` process via `LipschitzWith.compLp`. -/ +theorem lipschitz_sub_const {f : ℝ → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) : + LipschitzWith L (fun x ↦ f x - f 0) := + LipschitzWith.of_dist_le_mul fun x y ↦ by + simpa only [Real.dist_eq, sub_sub_sub_cancel_right] using hf.dist_le_mul x y + +/-- **The coefficient composition** `f ∘ X ∈ E` for a Lipschitz `f : ℝ → ℝ` and a +predictable process `X ∈ E`: `f(0)·1 + (f − f 0)∘X`. The centered part lands in `E` by +`compLp` (predictability is inherited from `E`'s trim measure); the constant `f 0` is +added back as a genuine element of `E` (finite measure). -/ +noncomputable def lipComp (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (f : ℝ → ℝ) (L : ℝ≥0) (hf : LipschitzWith L f) + (X : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) := + Lp.const 2 _ (f 0) + (lipschitz_sub_const hf).compLp (by simp) X + +/-- **The composition is `L`-Lipschitz in `X`** — the constant `f 0` cancels in the +difference, and `LipschitzWith.norm_compLp_sub_le` bounds the centered part. This is the +per-coefficient Lipschitz factor of the Picard contraction. -/ +theorem lipComp_sub_norm_le (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + {f : ℝ → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (X Y : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ‖lipComp T hBmeas f L hf X - lipComp T hBmeas f L hf Y‖ ≤ (L : ℝ) * ‖X - Y‖ := by + rw [lipComp, lipComp, add_sub_add_left_eq_sub] + exact (lipschitz_sub_const hf).norm_compLp_sub_le (by simp) X Y + +/-- **The Picard iterate** `Φ(X) = η + driftProcessAssembled(b∘X) + itoProcessAssembled(σ∘X)`, +a self-map of `E`. Its fixed point is the strong solution of the SDE. -/ +noncomputable def picardMap (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + {b σ : ℝ → ℝ} {Lb Lσ : ℝ≥0} (hb : LipschitzWith Lb b) (hσ : LipschitzWith Lσ σ) + (η_E : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) + (X : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) := + η_E + driftProcessAssembled T hBmeas (lipComp T hBmeas b Lb hb X) + + itoProcessAssembled hB T hBmeas hBcont (lipComp T hBmeas σ Lσ hσ X) + +/-- **The Picard difference.** The initial condition cancels, so `Φ(X) − Φ(Y)` is the drift of the +difference `b∘X − b∘Y` plus the Itô term of `σ∘X − σ∘Y`. Both the global contraction estimate +and the pointwise-in-time (band energy) estimates below start from this decomposition. -/ +theorem picardMap_sub (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + {b σ : ℝ → ℝ} {Lb Lσ : ℝ≥0} (hb : LipschitzWith Lb b) (hσ : LipschitzWith Lσ σ) + (η_E X Y : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + picardMap hB T hBmeas hBcont hb hσ η_E X - picardMap hB T hBmeas hBcont hb hσ η_E Y + = driftProcessAssembled (μ := μ) T hBmeas + (lipComp T hBmeas b Lb hb X - lipComp T hBmeas b Lb hb Y) + + itoProcessAssembled hB T hBmeas hBcont + (lipComp T hBmeas σ Lσ hσ X - lipComp T hBmeas σ Lσ hσ Y) := by + rw [map_sub (driftProcessAssembled (μ := μ) T hBmeas), + itoProcessAssembled_sub hB T hBmeas hBcont, picardMap, picardMap] + abel + +/-- **The Picard contraction estimate** `‖Φ(X) − Φ(Y)‖ ≤ (T·L_b + √T·L_σ)·‖X − Y‖`. The +initial condition cancels in the difference; the drift term contributes `T·L_b` (operator +bound `T` × Lipschitz `L_b`), the Itô term `√T·L_σ` (operator bound `√T` × Lipschitz `L_σ`). +For `T` small this constant is `< 1`, giving a contraction. -/ +theorem picardMap_contraction (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + {b σ : ℝ → ℝ} {Lb Lσ : ℝ≥0} (hb : LipschitzWith Lb b) (hσ : LipschitzWith Lσ σ) + (η_E X Y : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ‖picardMap hB T hBmeas hBcont hb hσ η_E X - picardMap hB T hBmeas hBcont hb hσ η_E Y‖ + ≤ ((T : ℝ) * Lb + Real.sqrt (T : ℝ) * Lσ) * ‖X - Y‖ := by + rw [picardMap_sub hB T hBmeas hBcont hb hσ η_E X Y] + calc ‖driftProcessAssembled (μ := μ) T hBmeas + (lipComp T hBmeas b Lb hb X - lipComp T hBmeas b Lb hb Y) + + itoProcessAssembled hB T hBmeas hBcont + (lipComp T hBmeas σ Lσ hσ X - lipComp T hBmeas σ Lσ hσ Y)‖ + ≤ ‖driftProcessAssembled (μ := μ) T hBmeas + (lipComp T hBmeas b Lb hb X - lipComp T hBmeas b Lb hb Y)‖ + + ‖itoProcessAssembled hB T hBmeas hBcont + (lipComp T hBmeas σ Lσ hσ X - lipComp T hBmeas σ Lσ hσ Y)‖ := norm_add_le _ _ + _ ≤ (T : ℝ) * ‖lipComp T hBmeas b Lb hb X - lipComp T hBmeas b Lb hb Y‖ + + Real.sqrt (T : ℝ) * ‖lipComp T hBmeas σ Lσ hσ X - lipComp T hBmeas σ Lσ hσ Y‖ := + add_le_add (driftProcessAssembled_norm_le T hBmeas _) + (itoProcessAssembled_norm_le hB T hBmeas hBcont _) + _ ≤ (T : ℝ) * ((Lb : ℝ) * ‖X - Y‖) + Real.sqrt (T : ℝ) * ((Lσ : ℝ) * ‖X - Y‖) := + add_le_add + (mul_le_mul_of_nonneg_left (lipComp_sub_norm_le T hBmeas hb X Y) T.coe_nonneg) + (mul_le_mul_of_nonneg_left (lipComp_sub_norm_le T hBmeas hσ X Y) (Real.sqrt_nonneg _)) + _ = ((T : ℝ) * Lb + Real.sqrt (T : ℝ) * Lσ) * ‖X - Y‖ := by ring + +/-- **The Picard map is a contraction** on `E` once `T·L_b + √T·L_σ < 1` (a smallness +condition on the horizon `T` given the Lipschitz constants). Packages +`picardMap_contraction` as Mathlib's `ContractingWith`. -/ +theorem picardMap_contractingWith (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + {b σ : ℝ → ℝ} {Lb Lσ : ℝ≥0} (hb : LipschitzWith Lb b) (hσ : LipschitzWith Lσ σ) + (η_E : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) + (hc : (T : ℝ) * Lb + Real.sqrt (T : ℝ) * Lσ < 1) : + ContractingWith (Real.toNNReal ((T : ℝ) * Lb + Real.sqrt (T : ℝ) * Lσ)) + (picardMap hB T hBmeas hBcont hb hσ η_E) := by + have hc0 : (0 : ℝ) ≤ (T : ℝ) * Lb + Real.sqrt (T : ℝ) * Lσ := by positivity + refine ⟨?_, LipschitzWith.of_dist_le_mul fun X Y ↦ ?_⟩ + · rw [← NNReal.coe_lt_coe, Real.coe_toNNReal _ hc0, NNReal.coe_one]; exact hc + · rw [dist_eq_norm, dist_eq_norm, Real.coe_toNNReal _ hc0] + exact picardMap_contraction hB T hBmeas hBcont hb hσ η_E X Y + +/-- **The strong solution** of the SDE (contraction regime): the unique fixed point of the +Picard map in `E`, from Banach's fixed-point theorem (`ContractingWith.fixedPoint`; `E` is a +complete, nonempty metric space). -/ +noncomputable def picardSolution (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + {b σ : ℝ → ℝ} {Lb Lσ : ℝ≥0} (hb : LipschitzWith Lb b) (hσ : LipschitzWith Lσ σ) + (η_E : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) + (hc : (T : ℝ) * Lb + Real.sqrt (T : ℝ) * Lσ < 1) : + Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) := + (picardMap_contractingWith hB T hBmeas hBcont hb hσ η_E hc).fixedPoint _ + +/-- **Existence + uniqueness** of the strong solution: `picardSolution` is a fixed point of +the Picard map, and it is the *only* one — the SDE `dX = b(X)dt + σ(X)dB` has a unique +strong solution in `E` under the contraction condition. -/ +theorem picardMap_exists_unique_fixedPoint (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + {b σ : ℝ → ℝ} {Lb Lσ : ℝ≥0} (hb : LipschitzWith Lb b) (hσ : LipschitzWith Lσ σ) + (η_E : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) + (hc : (T : ℝ) * Lb + Real.sqrt (T : ℝ) * Lσ < 1) : + ∃! X, picardMap hB T hBmeas hBcont hb hσ η_E X = X := by + refine ⟨picardSolution hB T hBmeas hBcont hb hσ η_E hc, ?_, fun Y hY ↦ ?_⟩ + · exact (picardMap_contractingWith hB T hBmeas hBcont hb hσ η_E hc).fixedPoint_isFixedPt + · exact (picardMap_contractingWith hB T hBmeas hBcont hb hσ η_E hc).fixedPoint_unique hY + +/-! ### Pointwise-in-time (band) energy + +The contraction `picardMap_contraction` is global in `T`. To remove the smallness condition we need +its time-localised form: the energy of the Picard difference on the band `(0, s] × Ω` is bounded by +a Volterra integral `∫₀ˢ` of the energy of the input on `(0, u] × Ω`. The band energy is the +quantity the Itô isometry already speaks (`itoProcessCLM_norm_sq`). -/ + +/-- The **band energy** `∫_{(0,s]×Ω} Z² d(trimMeasure T)` of a predictable `L²` process: its `L²` +mass on the time band `(0, s]`. For `s = T` it is `‖Z‖²`. -/ +noncomputable def bandEnergy (T s : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (Z : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : ℝ := + ∫ z in Set.Ioc 0 s ×ˢ (Set.univ : Set Ω), (Z z) ^ 2 ∂(trimMeasure (μ := μ) T hBmeas) + +omit [IsProbabilityMeasure μ] in +theorem bandEnergy_nonneg (T s : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (Z : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : 0 ≤ bandEnergy T s hBmeas Z := + integral_nonneg fun _ ↦ sq_nonneg _ + +omit [IsProbabilityMeasure μ] in +theorem monotone_bandEnergy (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (Z : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + Monotone fun s ↦ bandEnergy T s hBmeas Z := + fun _ _ h ↦ setIntegral_mono_set (Lp.memLp Z).integrable_sq.integrableOn + (ae_of_all _ fun _ ↦ sq_nonneg _) + (ae_of_all _ fun _ hx ↦ Set.prod_mono (Set.Ioc_subset_Ioc_right h) subset_rfl hx) + +omit [IsProbabilityMeasure μ] in +theorem bandEnergy_le_norm_sq (T s : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (Z : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : bandEnergy T s hBmeas Z ≤ ‖Z‖ ^ 2 := by + rw [bandEnergy, lp_two_norm_sq] + exact setIntegral_le_integral (Lp.memLp Z).integrable_sq (ae_of_all _ fun _ ↦ sq_nonneg _) + +/-- The trim measure lives on `(0, T] × Ω`, so the band energy at the horizon is the full energy. -/ +theorem norm_sq_eq_bandEnergy (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (Z : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : ‖Z‖ ^ 2 = bandEnergy T T hBmeas Z := by + have h : (trimMeasure (μ := μ) T hBmeas).restrict (Set.Ioc 0 T ×ˢ (Set.univ : Set Ω)) + = trimMeasure (μ := μ) T hBmeas := + Measure.restrict_eq_self_of_ae_mem + ((ae_fst_mem_Ioc_trimMeasure (μ := μ) T hBmeas).mono fun _ hz ↦ ⟨hz, Set.mem_univ _⟩) + rw [bandEnergy, lp_two_norm_sq, h] + +omit [IsProbabilityMeasure μ] in +theorem bandEnergy_add_le (T s : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (Z W : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + bandEnergy T s hBmeas (Z + W) ≤ 2 * bandEnergy T s hBmeas Z + 2 * bandEnergy T s hBmeas W := by + have hZ := (Lp.memLp Z).integrable_sq.integrableOn + (s := Set.Ioc 0 s ×ˢ (Set.univ : Set Ω)) + have hW := (Lp.memLp W).integrable_sq.integrableOn + (s := Set.Ioc 0 s ×ˢ (Set.univ : Set Ω)) + have hsum : ∫ z in Set.Ioc 0 s ×ˢ (Set.univ : Set Ω), (2 * (Z z) ^ 2 + 2 * (W z) ^ 2) + ∂(trimMeasure (μ := μ) T hBmeas) + = 2 * bandEnergy T s hBmeas Z + 2 * bandEnergy T s hBmeas W := by + rw [integral_add (hZ.const_mul 2) (hW.const_mul 2), integral_const_mul, integral_const_mul, + bandEnergy, bandEnergy] + refine le_trans (integral_mono_ae (Lp.memLp (Z + W)).integrable_sq.integrableOn + ((hZ.const_mul 2).add (hW.const_mul 2)) ?_) hsum.le + filter_upwards [ae_restrict_of_ae (Lp.coeFn_add Z W)] with z hz + simp only [hz, Pi.add_apply] + nlinarith [sq_nonneg (Z z - W z)] + +/-- `timeMeasure` restricted to a bounded time-interval `(0, s]` is finite. -/ +private instance isFiniteMeasure_timeMeasure_restrict_Ioc_zero (s : ℝ≥0) : + IsFiniteMeasure (timeMeasure.restrict (Set.Ioc (0 : ℝ≥0) s)) := + inferInstanceAs (IsFiniteMeasure (timeMeasureHorizon s)) + +omit [IsProbabilityMeasure μ] in +/-- The band energy is a bounded monotone, hence integrable, function of the band edge. -/ +theorem integrable_bandEnergy (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (Z : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) (s : ℝ≥0) : + Integrable (fun u ↦ bandEnergy T u hBmeas Z) (timeMeasure.restrict (Set.Ioc (0 : ℝ≥0) s)) := + Integrable.of_bound (monotone_bandEnergy T hBmeas Z).measurable.aestronglyMeasurable (‖Z‖ ^ 2) + (ae_of_all _ fun u ↦ by + rw [Real.norm_eq_abs, abs_of_nonneg (bandEnergy_nonneg T u hBmeas Z)] + exact bandEnergy_le_norm_sq T u hBmeas Z) + +/-- Restricting the predictable product to a band `(0, t] × Ω` restricts the time factor. -/ +theorem prod_restrict_band (T : ℝ≥0) {t : ℝ≥0} (htT : t ≤ T) : + ((timeMeasureHorizon T).prod μ).restrict (Set.Ioc (0 : ℝ≥0) t ×ˢ (Set.univ : Set Ω)) + = (timeMeasure.restrict (Set.Ioc (0 : ℝ≥0) t)).prod μ := by + rw [← Measure.prod_restrict, Measure.restrict_univ, timeMeasureHorizon, + Measure.restrict_restrict measurableSet_Ioc, + Set.inter_eq_left.2 (Set.Ioc_subset_Ioc_right htT)] + +/-- **Band energy as a time integral of slices.** For a predictable `L²` process given by a +function `g`, the band energy over `(0, s]` is `∫₀ˢ 𝔼[g_t²] dt`. -/ +theorem bandEnergy_toLp (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) {g : ℝ≥0 → Ω → ℝ} + (hg : StronglyMeasurable[(natFiltration (mΩ := mΩ) hBmeas).predictable] + (Function.uncurry g)) + (hmem : MemLp (Function.uncurry g) 2 (trimMeasure (μ := μ) T hBmeas)) {s : ℝ≥0} + (hsT : s ≤ T) : + bandEnergy T s hBmeas (hmem.toLp _) + = ∫ t in Set.Ioc (0 : ℝ≥0) s, ∫ ω, (g t ω) ^ 2 ∂μ ∂timeMeasure := by + set 𝓕 := natFiltration (mΩ := mΩ) hBmeas + have hband : MeasurableSet[𝓕.predictable] (Set.Ioc (0 : ℝ≥0) s ×ˢ (Set.univ : Set Ω)) := + MeasureTheory.measurableSet_predictable_Ioc_prod (𝓕 := 𝓕) 0 s MeasurableSet.univ + have hbandP : MeasurableSet (Set.Ioc (0 : ℝ≥0) s ×ˢ (Set.univ : Set Ω)) := + MeasurableSet.prod measurableSet_Ioc MeasurableSet.univ + have hint : Integrable (fun z ↦ (Function.uncurry g z) ^ 2) ((timeMeasureHorizon T).prod μ) := + (memLp_of_memLp_trim 𝓕.predictable_le_prod hmem).integrable_sq + have h1 : bandEnergy T s hBmeas (hmem.toLp _) + = ∫ z in Set.Ioc (0 : ℝ≥0) s ×ˢ (Set.univ : Set Ω), (Function.uncurry g z) ^ 2 + ∂(trimMeasure (μ := μ) T hBmeas) := by + refine integral_congr_ae (ae_restrict_of_ae ?_) + filter_upwards [hmem.coeFn_toLp] with z hz + rw [hz] + have hsm : StronglyMeasurable[𝓕.predictable] + ((Set.Ioc (0 : ℝ≥0) s ×ˢ (Set.univ : Set Ω)).indicator + (fun z ↦ (Function.uncurry g z) ^ 2)) := + (hg.pow 2).indicator hband + have h2 : ∫ z in Set.Ioc (0 : ℝ≥0) s ×ˢ (Set.univ : Set Ω), (Function.uncurry g z) ^ 2 + ∂(trimMeasure (μ := μ) T hBmeas) + = ∫ z in Set.Ioc (0 : ℝ≥0) s ×ˢ (Set.univ : Set Ω), (Function.uncurry g z) ^ 2 + ∂((timeMeasureHorizon T).prod μ) := by + rw [← integral_indicator hband, ← integral_indicator hbandP] + exact (integral_trim (μ := (timeMeasureHorizon T).prod μ) 𝓕.predictable_le_prod hsm).symm + have h3 : ∫ z in Set.Ioc (0 : ℝ≥0) s ×ˢ (Set.univ : Set Ω), (Function.uncurry g z) ^ 2 + ∂((timeMeasureHorizon T).prod μ) + = ∫ t in Set.Ioc (0 : ℝ≥0) s, ∫ ω, (g t ω) ^ 2 ∂μ ∂timeMeasure := by + rw [setIntegral_prod _ hint.integrableOn] + simp only [Measure.restrict_univ, Function.uncurry_apply_pair] + rw [timeMeasureHorizon, Measure.restrict_restrict measurableSet_Ioc, + Set.inter_eq_left.2 (Set.Ioc_subset_Ioc_right hsT)] + rw [h1, h2, h3] + +/-- **The Itô term, band by band.** `‖𝟙_{(0,s]}·(φ●B)‖² = ∫₀ˢ ‖𝟙_{(0,u]}·φ‖² du`: the band energy +of the assembled Itô process is the Volterra integral of the band energy of the integrand +(slice by slice the modification identity plus `itoProcessCLM_norm_sq`). -/ +theorem bandEnergy_itoProcessAssembled (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + (φ : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) {s : ℝ≥0} (hsT : s ≤ T) : + bandEnergy T s hBmeas (itoProcessAssembled hB T hBmeas hBcont φ) + = ∫ u in Set.Ioc (0 : ℝ≥0) s, bandEnergy T u hBmeas φ ∂timeMeasure := by + rw [itoProcessAssembled, + bandEnergy_toLp T hBmeas (g := itoContinuousMod T hBmeas φ) + (itoContinuousMod_isStronglyPredictable hB T hBmeas hBcont φ) + (memLp_itoContinuousMod hB T hBmeas hBcont φ) hsT] + refine setIntegral_congr_fun measurableSet_Ioc fun t ht ↦ ?_ + have htT : t ≤ T := ht.2.trans hsT + have hb : bandEnergy T t hBmeas φ = ‖itoProcessCLM hB T t hBmeas φ‖ ^ 2 := + (itoProcessCLM_norm_sq hB htT hBmeas φ).symm + change ∫ ω, (itoContinuousMod T hBmeas φ t ω) ^ 2 ∂μ = bandEnergy T t hBmeas φ + rw [hb, lp_two_norm_sq] + refine integral_congr_ae ?_ + filter_upwards [itoContinuousMod_modification hB T hBmeas hBcont φ htT] with ω hω + rw [hω] + +theorem continuous_bandEnergy (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) {s : ℝ≥0} (hsT : s ≤ T) : + Continuous fun Z : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) ↦ bandEnergy T s hBmeas Z := by + have h : (fun Z : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) ↦ bandEnergy T s hBmeas Z) + = fun Z ↦ ‖itoProcessCLM hB T s hBmeas Z‖ ^ 2 := + funext fun Z ↦ (itoProcessCLM_norm_sq hB hsT hBmeas Z).symm + rw [h] + exact (itoProcessCLM hB T s hBmeas).continuous.norm.pow 2 + +/-- The assembled Itô process is `√T`-Lipschitz in the integrand (additivity and the operator +bound `itoProcessAssembled_norm_le`), in particular continuous. -/ +theorem lipschitzWith_itoProcessAssembled (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) : + LipschitzWith (NNReal.sqrt T) (itoProcessAssembled hB T hBmeas hBcont) := by + refine LipschitzWith.of_dist_le_mul fun X Y ↦ ?_ + rw [dist_eq_norm, dist_eq_norm, ← itoProcessAssembled_sub, Real.coe_sqrt] + exact itoProcessAssembled_norm_le hB T hBmeas hBcont _ + +/-- **The elementary drift, band by band.** For a `T`-bounded simple process `V`, the band energy +of its drift is at most `s ∫₀ˢ (band energy of V on (0,u]) du`: pointwise Cauchy–Schwarz +(`driftSimpleProcess_sq_le` at horizon `t`) gives `d_t² ≤ t∫₀ᵗ V²`, then Fubini on the band. -/ +theorem bandEnergy_driftSimpleProcessLp_le (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (V : TBoundedSP T hBmeas) {s : ℝ≥0} (hsT : s ≤ T) : + bandEnergy T s hBmeas (driftSimpleProcessLp (μ := μ) T hBmeas V.val) + ≤ (s : ℝ) * ∫ u in Set.Ioc (0 : ℝ≥0) s, + bandEnergy T u hBmeas (simpleAssemblyHorizon (μ := μ) T hBmeas V) ∂timeMeasure := by + set 𝓕 := natFiltration (mΩ := mΩ) hBmeas + have hmemD := memLp_uncurry_driftSimpleProcess (μ := μ) T hBmeas V.val + have hmemV := memLp_uncurry_trimMeasure (μ := μ) T hBmeas V.val + have hpredD : StronglyMeasurable[𝓕.predictable] + (Function.uncurry (driftSimpleProcess hBmeas V.val)) := + driftSimpleProcess_isStronglyPredictable hBmeas V.val + have hpredV : StronglyMeasurable[𝓕.predictable] (Function.uncurry ⇑V.val) := + V.val.isStronglyPredictable + have hsAsm : simpleAssemblyHorizon (μ := μ) T hBmeas V + = hmemV.toLp (Function.uncurry ⇑V.val) := rfl + have hintD : Integrable (fun z ↦ (Function.uncurry (driftSimpleProcess hBmeas V.val) z) ^ 2) + ((timeMeasureHorizon T).prod μ) := + (memLp_of_memLp_trim 𝓕.predictable_le_prod hmemD).integrable_sq + have hintV : Integrable (fun z ↦ (Function.uncurry ⇑V.val z) ^ 2) + ((timeMeasureHorizon T).prod μ) := + (memLp_of_memLp_trim 𝓕.predictable_le_prod hmemV).integrable_sq + -- the slice bound at a fixed time `t ≤ T` + have hpt : ∀ t : ℝ≥0, t ≤ T → + Integrable (fun ω ↦ (driftSimpleProcess hBmeas V.val t ω) ^ 2) μ → + ∫ ω, (driftSimpleProcess hBmeas V.val t ω) ^ 2 ∂μ + ≤ (t : ℝ) * bandEnergy T t hBmeas (simpleAssemblyHorizon (μ := μ) T hBmeas V) := by + intro t htT hint_t + have hintV_t : Integrable (fun z ↦ (Function.uncurry ⇑V.val z) ^ 2) + ((timeMeasure.restrict (Set.Ioc (0 : ℝ≥0) t)).prod μ) := by + rw [← prod_restrict_band T htT] + exact hintV.integrableOn + have hswap : ∫ ω, ∫ r in Set.Ioc (0 : ℝ≥0) t, (⇑V.val r ω) ^ 2 ∂timeMeasure ∂μ + = ∫ r in Set.Ioc (0 : ℝ≥0) t, ∫ ω, (⇑V.val r ω) ^ 2 ∂μ ∂timeMeasure := + (integral_integral_swap (f := fun r ω ↦ (⇑V.val r ω) ^ 2) hintV_t).symm + have hsim : bandEnergy T t hBmeas (simpleAssemblyHorizon (μ := μ) T hBmeas V) + = ∫ r in Set.Ioc (0 : ℝ≥0) t, ∫ ω, (⇑V.val r ω) ^ 2 ∂μ ∂timeMeasure := by + rw [hsAsm] + exact bandEnergy_toLp T hBmeas (g := ⇑V.val) hpredV hmemV htT + rw [hsim, ← hswap, ← integral_const_mul] + exact integral_mono_ae hint_t (hintV_t.integral_prod_right.const_mul _) + (ae_of_all _ fun ω ↦ driftSimpleProcess_sq_le t hBmeas V.val le_rfl ω) + have hL : bandEnergy T s hBmeas (driftSimpleProcessLp (μ := μ) T hBmeas V.val) + = ∫ t in Set.Ioc (0 : ℝ≥0) s, ∫ ω, (driftSimpleProcess hBmeas V.val t ω) ^ 2 ∂μ + ∂timeMeasure := + bandEnergy_toLp T hBmeas (g := driftSimpleProcess hBmeas V.val) hpredD hmemD hsT + have hslice : ∀ᵐ t ∂(timeMeasure.restrict (Set.Ioc (0 : ℝ≥0) s)), + Integrable (fun ω ↦ (driftSimpleProcess hBmeas V.val t ω) ^ 2) μ := by + have h : ∀ᵐ t ∂(timeMeasure.restrict (Set.Ioc (0 : ℝ≥0) T)), + Integrable (fun ω ↦ (driftSimpleProcess hBmeas V.val t ω) ^ 2) μ := + hintD.prod_right_ae + exact ae_restrict_of_ae_restrict_of_subset (Set.Ioc_subset_Ioc_right hsT) h + have hintDt : Integrable (fun t ↦ ∫ ω, (driftSimpleProcess hBmeas V.val t ω) ^ 2 ∂μ) + (timeMeasure.restrict (Set.Ioc (0 : ℝ≥0) s)) := by + have h : Integrable (fun t ↦ ∫ ω, (driftSimpleProcess hBmeas V.val t ω) ^ 2 ∂μ) + (timeMeasure.restrict (Set.Ioc (0 : ℝ≥0) T)) := hintD.integral_prod_left + exact h.mono_measure (Measure.restrict_mono (Set.Ioc_subset_Ioc_right hsT) le_rfl) + rw [hL, ← integral_const_mul] + refine integral_mono_ae hintDt + ((integrable_bandEnergy T hBmeas (simpleAssemblyHorizon (μ := μ) T hBmeas V) s).const_mul _) + ?_ + filter_upwards [ae_restrict_mem measurableSet_Ioc, hslice] with t ht hint_t + exact (hpt t (ht.2.trans hsT) hint_t).trans + (mul_le_mul_of_nonneg_right (by exact_mod_cast ht.2) (bandEnergy_nonneg T t hBmeas _)) + +/-- **The assembled drift, band by band.** For every `g ∈ E` and `s ≤ T`, +`‖𝟙_{(0,s]}·∫₀·g‖² ≤ s · ‖𝟙_{(0,s]}·(g●B)‖²` — i.e. `s ∫₀ˢ (energy of g on (0,u]) du`, the Itô +side being its exact Volterra form (`bandEnergy_itoProcessAssembled`). Proved on the dense simple +processes (`bandEnergy_driftSimpleProcessLp_le`) and extended by continuity of both sides. -/ +theorem bandEnergy_driftProcessAssembled_le (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + {s : ℝ≥0} (hsT : s ≤ T) (g : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + bandEnergy T s hBmeas (driftProcessAssembled T hBmeas g) + ≤ (s : ℝ) * bandEnergy T s hBmeas (itoProcessAssembled hB T hBmeas hBcont g) := by + have hc1 : Continuous fun g' : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) ↦ + bandEnergy T s hBmeas (driftProcessAssembled T hBmeas g') := + (continuous_bandEnergy hB T hBmeas hsT).comp (driftProcessAssembled T hBmeas).continuous + have hc2 : Continuous fun g' : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas) ↦ + (s : ℝ) * bandEnergy T s hBmeas (itoProcessAssembled hB T hBmeas hBcont g') := + continuous_const.mul ((continuous_bandEnergy hB T hBmeas hsT).comp + (lipschitzWith_itoProcessAssembled hB T hBmeas hBcont).continuous) + have key : ∀ V : TBoundedSP T hBmeas, + bandEnergy T s hBmeas + (driftProcessAssembled T hBmeas (simpleAssemblyHorizon (μ := μ) T hBmeas V)) + ≤ (s : ℝ) * bandEnergy T s hBmeas + (itoProcessAssembled hB T hBmeas hBcont (simpleAssemblyHorizon (μ := μ) T hBmeas V)) := + fun V ↦ by + rw [driftProcessAssembled_simpleAssembly, + bandEnergy_itoProcessAssembled hB T hBmeas hBcont _ hsT] + exact bandEnergy_driftSimpleProcessLp_le T hBmeas V hsT + exact DenseRange.induction_on (simpleAssemblyHorizon_denseRange (μ := μ) T hBmeas) g + (isClosed_le hc1 hc2) key + +/-- **The coefficient composition, band by band.** Pointwise `|f x − f y| ≤ L|x − y|` integrates +over any band: `‖𝟙_{(0,s]}(f∘X − f∘Y)‖² ≤ L²‖𝟙_{(0,s]}(X − Y)‖²`. -/ +theorem bandEnergy_lipComp_sub_le (T s : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + {f : ℝ → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (X Y : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + bandEnergy T s hBmeas (lipComp T hBmeas f L hf X - lipComp T hBmeas f L hf Y) + ≤ (L : ℝ) ^ 2 * bandEnergy T s hBmeas (X - Y) := by + have key : ∀ a b : ℝ, (f a - f 0 - (f b - f 0)) ^ 2 ≤ (L : ℝ) ^ 2 * (a - b) ^ 2 := by + intro a b + have h := (lipschitz_sub_const hf).dist_le_mul a b + rw [Real.dist_eq, Real.dist_eq] at h + calc (f a - f 0 - (f b - f 0)) ^ 2 = |f a - f 0 - (f b - f 0)| ^ 2 := (sq_abs _).symm + _ ≤ ((L : ℝ) * |a - b|) ^ 2 := pow_le_pow_left₀ (abs_nonneg _) h 2 + _ = (L : ℝ) ^ 2 * (a - b) ^ 2 := by rw [mul_pow, sq_abs] + rw [lipComp, lipComp, add_sub_add_left_eq_sub] + have hint := (Lp.memLp (X - Y)).integrable_sq.integrableOn + (s := Set.Ioc 0 s ×ˢ (Set.univ : Set Ω)) + unfold bandEnergy + rw [← integral_const_mul] + refine integral_mono_ae (Lp.memLp _).integrable_sq.integrableOn (hint.const_mul _) ?_ + refine ae_restrict_of_ae ?_ + filter_upwards [Lp.coeFn_sub ((lipschitz_sub_const hf).compLp (by simp) X) + ((lipschitz_sub_const hf).compLp (by simp) Y), + (lipschitz_sub_const hf).coeFn_compLp (by simp) X, + (lipschitz_sub_const hf).coeFn_compLp (by simp) Y, Lp.coeFn_sub X Y] with z h1 h2 h3 h4 + simp only [h1, Pi.sub_apply, h2, h3, h4, Function.comp_apply] + exact key _ _ + +/-- The Volterra rate constant `2 (T L_b² + L_σ²)` of the Picard difference. -/ +noncomputable def picardRate (T Lb Lσ : ℝ≥0) : ℝ := 2 * ((T : ℝ) * (Lb : ℝ) ^ 2 + (Lσ : ℝ) ^ 2) + +theorem picardRate_nonneg (T Lb Lσ : ℝ≥0) : 0 ≤ picardRate T Lb Lσ := by + unfold picardRate; positivity + +/-- **The Picard difference is a Volterra operator on band energies.** For `s ≤ T`, +`‖𝟙_{(0,s]}(Φ X − Φ Y)‖² ≤ 2(T L_b² + L_σ²) ∫₀ˢ ‖𝟙_{(0,u]}(X − Y)‖² du`. The drift term is +bounded by `bandEnergy_driftProcessAssembled_le`, the Itô term is exactly its Volterra integral +(`bandEnergy_itoProcessAssembled`), and `(a + b)² ≤ 2a² + 2b²` splits the sum. -/ +theorem bandEnergy_picardMap_sub_le (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + {b σ : ℝ → ℝ} {Lb Lσ : ℝ≥0} (hb : LipschitzWith Lb b) (hσ : LipschitzWith Lσ σ) + (η_E X Y : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) {s : ℝ≥0} (hsT : s ≤ T) : + bandEnergy T s hBmeas + (picardMap hB T hBmeas hBcont hb hσ η_E X - picardMap hB T hBmeas hBcont hb hσ η_E Y) + ≤ picardRate T Lb Lσ * + ∫ u in Set.Ioc (0 : ℝ≥0) s, bandEnergy T u hBmeas (X - Y) ∂timeMeasure := by + have hI0 : 0 ≤ ∫ u in Set.Ioc (0 : ℝ≥0) s, bandEnergy T u hBmeas (X - Y) ∂timeMeasure := + integral_nonneg fun u ↦ bandEnergy_nonneg T u hBmeas _ + -- the Volterra integral of a Lipschitz composition + have hlip : ∀ {f : ℝ → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f), + ∫ u in Set.Ioc (0 : ℝ≥0) s, + bandEnergy T u hBmeas (lipComp T hBmeas f L hf X - lipComp T hBmeas f L hf Y) ∂timeMeasure + ≤ (L : ℝ) ^ 2 * ∫ u in Set.Ioc (0 : ℝ≥0) s, bandEnergy T u hBmeas (X - Y) ∂timeMeasure := by + intro f L hf + rw [← integral_const_mul] + exact integral_mono (integrable_bandEnergy T hBmeas _ s) + ((integrable_bandEnergy T hBmeas _ s).const_mul _) + fun u ↦ bandEnergy_lipComp_sub_le T u hBmeas hf X Y + have hito : bandEnergy T s hBmeas (itoProcessAssembled hB T hBmeas hBcont + (lipComp T hBmeas σ Lσ hσ X - lipComp T hBmeas σ Lσ hσ Y)) + ≤ (Lσ : ℝ) ^ 2 * ∫ u in Set.Ioc (0 : ℝ≥0) s, bandEnergy T u hBmeas (X - Y) ∂timeMeasure := by + rw [bandEnergy_itoProcessAssembled hB T hBmeas hBcont _ hsT] + exact hlip hσ + have hdrift : bandEnergy T s hBmeas (driftProcessAssembled T hBmeas + (lipComp T hBmeas b Lb hb X - lipComp T hBmeas b Lb hb Y)) + ≤ (T : ℝ) * ((Lb : ℝ) ^ 2 * + ∫ u in Set.Ioc (0 : ℝ≥0) s, bandEnergy T u hBmeas (X - Y) ∂timeMeasure) := by + refine (bandEnergy_driftProcessAssembled_le hB T hBmeas hBcont hsT _).trans ?_ + rw [bandEnergy_itoProcessAssembled hB T hBmeas hBcont _ hsT] + exact (mul_le_mul_of_nonneg_left (hlip hb) s.coe_nonneg).trans + (mul_le_mul_of_nonneg_right (by exact_mod_cast hsT) (mul_nonneg (sq_nonneg _) hI0)) + rw [picardMap_sub hB T hBmeas hBcont hb hσ η_E X Y] + refine (bandEnergy_add_le T s hBmeas _ _).trans ?_ + unfold picardRate + nlinarith [hito, hdrift] + +/-- `∫₀ˢ uⁿ du = sⁿ⁺¹/(n+1)` against `timeMeasure` (the Lebesgue measure on `ℝ≥0`). -/ +theorem setIntegral_pow_Ioc_timeMeasure (n : ℕ) (s : ℝ≥0) : + ∫ u in Set.Ioc (0 : ℝ≥0) s, (u : ℝ) ^ n ∂timeMeasure = (s : ℝ) ^ (n + 1) / (n + 1) := by + have hcongr : ∫ x in (0 : ℝ)..(s : ℝ), ((Real.toNNReal x : ℝ≥0) : ℝ) ^ n + = ∫ x in (0 : ℝ)..(s : ℝ), x ^ n := + intervalIntegral.integral_congr fun x hx ↦ by + have hx0 : 0 ≤ x := by + rcases Set.mem_uIcc.1 hx with h | h + · exact h.1 + · linarith [h.1, h.2, s.coe_nonneg] + simp only [Real.coe_toNNReal _ hx0] + rw [timeMeasure_Ioc_eq_interval (g := fun u : ℝ≥0 ↦ (u : ℝ) ^ n), hcongr, integral_pow] + simp + +/-- **Picard iterates decay factorially, band by band.** For `s ≤ T`, +`‖𝟙_{(0,s]}(Φⁿ X − Φⁿ Y)‖² ≤ (2(T L_b² + L_σ²) s)ⁿ / n! · ‖X − Y‖²`. By induction on the Volterra +estimate `bandEnergy_picardMap_sub_le`, using `∫₀ˢ uⁿ du = sⁿ⁺¹/(n+1)`. -/ +theorem bandEnergy_picardMap_iterate_le (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + {b σ : ℝ → ℝ} {Lb Lσ : ℝ≥0} (hb : LipschitzWith Lb b) (hσ : LipschitzWith Lσ σ) + (η_E X Y : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) (n : ℕ) : + ∀ s : ℝ≥0, s ≤ T → + bandEnergy T s hBmeas ((picardMap hB T hBmeas hBcont hb hσ η_E)^[n] X + - (picardMap hB T hBmeas hBcont hb hσ η_E)^[n] Y) + ≤ (picardRate T Lb Lσ * (s : ℝ)) ^ n / (n.factorial : ℝ) * ‖X - Y‖ ^ 2 := by + induction n with + | zero => + intro s _ + simpa using bandEnergy_le_norm_sq T s hBmeas (X - Y) + | succ n ih => + intro s hsT + rw [Function.iterate_succ_apply', Function.iterate_succ_apply'] + refine (bandEnergy_picardMap_sub_le hB T hBmeas hBcont hb hσ η_E _ _ hsT).trans ?_ + have hK : 0 ≤ picardRate T Lb Lσ := picardRate_nonneg T Lb Lσ + have hf : (n.factorial : ℝ) ≠ 0 := by positivity + have hmono : ∫ u in Set.Ioc (0 : ℝ≥0) s, bandEnergy T u hBmeas + ((picardMap hB T hBmeas hBcont hb hσ η_E)^[n] X + - (picardMap hB T hBmeas hBcont hb hσ η_E)^[n] Y) ∂timeMeasure + ≤ ∫ u in Set.Ioc (0 : ℝ≥0) s, + (picardRate T Lb Lσ ^ n / (n.factorial : ℝ) * ‖X - Y‖ ^ 2) * (u : ℝ) ^ n + ∂timeMeasure := by + refine setIntegral_mono_on (integrable_bandEnergy T hBmeas _ s) ?_ measurableSet_Ioc + fun u hu ↦ ?_ + · exact ((continuous_const.mul (NNReal.continuous_coe.pow n)).integrableOn_Icc).mono_set + Set.Ioc_subset_Icc_self + · calc _ ≤ (picardRate T Lb Lσ * (u : ℝ)) ^ n / (n.factorial : ℝ) * ‖X - Y‖ ^ 2 := + ih u (hu.2.trans hsT) + _ = _ := by rw [mul_pow]; ring + rw [integral_const_mul, setIntegral_pow_Ioc_timeMeasure] at hmono + refine (mul_le_mul_of_nonneg_left hmono hK).trans_eq ?_ + rw [Nat.factorial_succ] + push_cast + first | (field_simp; done) | (field_simp; ring) + +/-- **Picard iterates contract in `E`, factorially.** +`‖Φⁿ X − Φⁿ Y‖² ≤ (2(T L_b² + L_σ²) T)ⁿ / n! · ‖X − Y‖²` for every horizon `T`. -/ +theorem picardMap_iterate_norm_sq_le (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + {b σ : ℝ → ℝ} {Lb Lσ : ℝ≥0} (hb : LipschitzWith Lb b) (hσ : LipschitzWith Lσ σ) + (η_E X Y : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) (n : ℕ) : + ‖(picardMap hB T hBmeas hBcont hb hσ η_E)^[n] X + - (picardMap hB T hBmeas hBcont hb hσ η_E)^[n] Y‖ ^ 2 + ≤ (picardRate T Lb Lσ * (T : ℝ)) ^ n / (n.factorial : ℝ) * ‖X - Y‖ ^ 2 := + (norm_sq_eq_bandEnergy T hBmeas _).le.trans + (bandEnergy_picardMap_iterate_le hB T hBmeas hBcont hb hσ η_E X Y n T le_rfl) + +/-- **A unique Picard fixed point on every horizon.** For Lipschitz `b, σ` +and any `T` (no smallness condition `T L_b + √T L_σ < 1`), the Picard map of +`dX = b(X)dt + σ(X)dB`, `X₀ = η` has exactly one fixed point in the predictable `L²` space `E`. +Some iterate `Φⁿ` is a contraction (`picardMap_iterate_norm_sq_le`: factorial decay), and a map +with a contracting iterate has a unique fixed point +(`ContractingWith.isFixedPt_fixedPoint_iterate`). -/ +theorem picardMap_exists_unique_fixedPoint_any_horizon (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + {b σ : ℝ → ℝ} {Lb Lσ : ℝ≥0} (hb : LipschitzWith Lb b) (hσ : LipschitzWith Lσ σ) + (η_E : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) : + ∃! X, picardMap hB T hBmeas hBcont hb hσ η_E X = X := by + obtain ⟨n, hn⟩ : ∃ n : ℕ, (picardRate T Lb Lσ * (T : ℝ)) ^ n / (n.factorial : ℝ) < 1 / 4 := + ((FloorSemiring.tendsto_pow_div_factorial_atTop (picardRate T Lb Lσ * (T : ℝ))).eventually + (gt_mem_nhds (by norm_num))).exists + let K : ℝ≥0 := ⟨1 / 2, by norm_num⟩ + have hK : (K : ℝ) = 1 / 2 := rfl + have hc : ContractingWith K (picardMap hB T hBmeas hBcont hb hσ η_E)^[n] := by + refine ⟨by rw [← NNReal.coe_lt_coe, hK]; norm_num, LipschitzWith.of_dist_le_mul fun X Y ↦ ?_⟩ + rw [dist_eq_norm, dist_eq_norm, hK] + have h2 : ‖(picardMap hB T hBmeas hBcont hb hσ η_E)^[n] X + - (picardMap hB T hBmeas hBcont hb hσ η_E)^[n] Y‖ ^ 2 ≤ (1 / 2 * ‖X - Y‖) ^ 2 := + (picardMap_iterate_norm_sq_le hB T hBmeas hBcont hb hσ η_E X Y n).trans + (calc _ ≤ 1 / 4 * ‖X - Y‖ ^ 2 := mul_le_mul_of_nonneg_right hn.le (sq_nonneg _) + _ = _ := by ring) + exact (pow_le_pow_iff_left₀ (norm_nonneg _) (by positivity) two_ne_zero).1 h2 + exact ⟨hc.fixedPoint _, hc.isFixedPt_fixedPoint_iterate, + fun Y hY ↦ hc.fixedPoint_unique (Function.IsFixedPt.iterate hY n)⟩ + +end SDEExistence +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/SDE/SDEPathwise.lean b/LeanPool/MathFin/Probability/Brownian/SDE/SDEPathwise.lean new file mode 100644 index 0000000000..72069bbb70 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/SDE/SDEPathwise.lean @@ -0,0 +1,131 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.SDE.SDEExistence +public import LeanPool.MathFin.Probability.Brownian.Ito.DriftProcessModification + +/-! # The Picard fixed point, sliced into paths (SDE existence, the pathwise bridge) + +`SDEExistence` produced the solution of `dX = b(X)dt + σ(X)dB` as the **abstract** fixed point +`picardSolution ∈ E = Lp ℝ 2 (trimMeasure T)` of the Picard map +`Φ(X) = η + driftProcessAssembled(b∘X) + itoProcessAssembled(σ∘X)`, under the short-horizon +contraction condition `T·L_b + √T·L_σ < 1`. That fixed point is an `L²` equivalence class on the +space–time product. + +This file slices the fixed-point equation `X = Φ(X)`, which holds in `E`, into a decomposition of +representatives: `X(t, ω) = η(t, ω) + (drift limit)_t(ω) + (Itô modification)_t(ω)` for almost +every `(t, ω)` with respect to `trimMeasure T` (`sde_pathwise_decomposition`). The two analytic +terms are given by processes defined at every `(t, ω)`: +* the **drift** `driftProcessAssembled(b∘X)` has `coeFn` a.e. equal to the pointwise `limUnder` + process `driftContinuousMod(b∘X)` (`driftProcessAssembled_coeFn`, `DriftProcessModification`); +* the **Itô term** `itoProcessAssembled(σ∘X)` is by construction the class of the continuous + modification `itoContinuousMod(σ∘X)` (`ItoProcessPredictable`). + +For each `t ≤ T`, the drift term is almost surely the time integral +`∫_{(0,t]} (b∘X)(s, ω) ds` of a representative of the class `b∘X = lipComp b X` +(`sde_pathwise_drift_eq_setIntegral`). A representative of a class is determined only up to a +null set of `(s, ω)`, and the per-path identity with `∫₀ᵗ b(X_s(ω)) ds` for a chosen +representative of `X` is not proved here. Nor is it proved that `X` has a representative that is +a continuous adapted process satisfying the integral equation at every `t` almost surely, which +is the textbook notion of a strong solution. + +## Main results + +* `sde_pathwise_decomposition`: the `E`-fixed point `picardSolution` decomposes, for almost every + `(t, ω)` under `trimMeasure T`, as `η` plus the drift term plus the Itô modification term. +* `sde_pathwise_drift_eq_setIntegral`: for every `t ≤ T`, the drift term of that decomposition is + the time integral of `b ∘ X` over `[0, t]`. + +## References + +* [B. Oksendal, *Stochastic Differential Equations*][Oksendal2003], Thm 5.2.1 +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Thm 8.2.5 + +## Tags + +stochastic differential equation, strong solution, Picard fixed point, pathwise decomposition, +drift and Itô term, continuous modification, MSC 60H10, MSC 60H05 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Filter Topology +open scoped NNReal ENNReal + +namespace MathFin +namespace SDEExistence +open ItoIntegralL2 ItoIntegralCLM ItoIntegralProcess ItoIntegralProcessGeneral + ItoIntegralProcessContinuousModification + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} + +/-- **The Picard fixed point, sliced into paths.** The abstract `E`-fixed point `picardSolution` +decomposes, almost everywhere for `trimMeasure T` on the space–time product, into its initial +condition, a drift process and an Itô process: +`X(t, ω) = η(t, ω) + driftContinuousMod(b∘X)_t(ω) + itoContinuousMod(σ∘X)_t(ω)`. +The drift process is the pointwise `limUnder` of elementary drift integrals +(`driftProcessAssembled_coeFn`); the Itô process is the continuous modification of `(σ∘X) ● B` +(`itoProcessAssembled` is defined from `itoContinuousMod`). The fixed-point equation `X = Φ(X)` +holds in `E`; taking `coeFn` through `Lp.coeFn_add` and the two realization identities slices it +into this form. -/ +theorem sde_pathwise_decomposition (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + {b σ : ℝ → ℝ} {Lb Lσ : ℝ≥0} (hb : LipschitzWith Lb b) (hσ : LipschitzWith Lσ σ) + (η_E : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) + (hc : (T : ℝ) * Lb + Real.sqrt (T : ℝ) * Lσ < 1) : + ⇑(picardSolution hB T hBmeas hBcont hb hσ η_E hc) + =ᵐ[trimMeasure (μ := μ) T hBmeas] + fun z ↦ ⇑η_E z + + Function.uncurry (driftContinuousMod T hBmeas + (lipComp T hBmeas b Lb hb (picardSolution hB T hBmeas hBcont hb hσ η_E hc))) z + + Function.uncurry (itoContinuousMod T hBmeas + (lipComp T hBmeas σ Lσ hσ (picardSolution hB T hBmeas hBcont hb hσ η_E hc))) z := by + set X := picardSolution hB T hBmeas hBcont hb hσ η_E hc + -- X is a fixed point of the Picard map, which is definitionally the sum of the three terms + have hfix : picardMap hB T hBmeas hBcont hb hσ η_E X = X := + (picardMap_contractingWith hB T hBmeas hBcont hb hσ η_E hc).fixedPoint_isFixedPt + have hX : X = η_E + driftProcessAssembled (μ := μ) T hBmeas (lipComp T hBmeas b Lb hb X) + + itoProcessAssembled hB T hBmeas hBcont (lipComp T hBmeas σ Lσ hσ X) := + hfix.symm + -- the two pathwise-realization identities + have hdrift := driftProcessAssembled_coeFn (μ := μ) T hBmeas (lipComp T hBmeas b Lb hb X) + have hito : ⇑(itoProcessAssembled hB T hBmeas hBcont (lipComp T hBmeas σ Lσ hσ X)) + =ᵐ[trimMeasure (μ := μ) T hBmeas] + Function.uncurry (itoContinuousMod T hBmeas (lipComp T hBmeas σ Lσ hσ X)) := + (memLp_itoContinuousMod hB T hBmeas hBcont (lipComp T hBmeas σ Lσ hσ X)).coeFn_toLp + -- slice the fixed-point equation through coeFn (rewrite only the standalone ⇑X, not the X in + -- lipComp) + filter_upwards [Lp.coeFn_add + (η_E + driftProcessAssembled (μ := μ) T hBmeas (lipComp T hBmeas b Lb hb X)) + (itoProcessAssembled hB T hBmeas hBcont (lipComp T hBmeas σ Lσ hσ X)), + Lp.coeFn_add η_E (driftProcessAssembled (μ := μ) T hBmeas (lipComp T hBmeas b Lb hb X)), + hdrift, hito] with z h1 h2 hd hi + conv_lhs => rw [hX] + simp only [h1, h2, hd, hi, Pi.add_apply] + +/-- **The drift term is a time integral.** For every `t ≤ T`, the drift term +`driftContinuousMod(b∘X)` of `sde_pathwise_decomposition` is, almost surely, the time integral +`∫_{(0,t]} (b∘X)(s, ω) ds` of the representative `⇑(lipComp b X)` of the class `b∘X` +(`driftContinuousMod_eq_setIntegral` applied to `lipComp b X`). The per-path identity with +`∫₀ᵗ b(X_s(ω)) ds` for a chosen representative of `X` is not stated. -/ +theorem sde_pathwise_drift_eq_setIntegral (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) (hBcont : ∀ ω, Continuous fun t : ℝ≥0 ↦ B t ω) + {b σ : ℝ → ℝ} {Lb Lσ : ℝ≥0} (hb : LipschitzWith Lb b) (hσ : LipschitzWith Lσ σ) + (η_E : Lp ℝ 2 (trimMeasure (μ := μ) T hBmeas)) + (hc : (T : ℝ) * Lb + Real.sqrt (T : ℝ) * Lσ < 1) {t : ℝ≥0} (ht : t ≤ T) : + ∀ᵐ ω ∂μ, driftContinuousMod T hBmeas + (lipComp T hBmeas b Lb hb (picardSolution hB T hBmeas hBcont hb hσ η_E hc)) t ω + = ∫ s in Set.Ioc (0 : ℝ≥0) t, + ⇑(lipComp T hBmeas b Lb hb (picardSolution hB T hBmeas hBcont hb hσ η_E hc)) (s, ω) + ∂timeMeasure := + driftContinuousMod_eq_setIntegral T hBmeas _ ht + +end SDEExistence +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/SDE/SDEUniqueness.lean b/LeanPool/MathFin/Probability/Brownian/SDE/SDEUniqueness.lean new file mode 100644 index 0000000000..589d508890 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/SDE/SDEUniqueness.lean @@ -0,0 +1,365 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Analysis.FiniteMeasureCauchySchwarz +public import Mathlib.Algebra.Ring.IsFormallyReal +public import Mathlib.Analysis.ODE.Gronwall +public import Mathlib.Order.CompletePartialOrder +public import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus +public import Mathlib.MeasureTheory.Integral.Prod + +/-! # Pathwise uniqueness for SDEs via Grönwall + +Uniqueness half of the strong-solution theorem for `dX = μ(X)dt + σ(X)dB`, `X₀ = η`: +two solutions agree almost surely at every time. The argument is the classical +`L²`-energy / Grönwall one, carried out on the pathwise processes `X, Y : ℝ → Ω → ℝ`. + +Let `g t := 𝔼[(Xₜ − Yₜ)²] = ∫_Ω (X t ω − Y t ω)² dμ` be the `L²` error. Subtracting the two +integral equations (the initial condition `η` cancels) and taking `L²` norms, +`(a+b)² ≤ 2a² + 2b²` splits the error into a drift and a diffusion contribution: +* the **drift** term is controlled by Cauchy–Schwarz in time and the Lipschitz bound on `μ`, + giving `≤ 2t·Lμ² ∫₀ᵗ g`; +* the **diffusion** term is controlled by the **Itô isometry** — supplied here as the honest + hypothesis `hIso` (an equality/inequality that the genuine Itô integral satisfies; in this + library it is `MathFin.ItoIntegralProcessGeneral.itoProcessCLM_norm_sq` / + `variance_itoIntegralCLM`) — and the Lipschitz bound on `σ`, giving `≤ 2Lσ² ∫₀ᵗ g`. + +Together `g t ≤ K ∫₀ᵗ g` with `K = 2(t·Lμ² + Lσ²)`, and Grönwall (in the `a = 0` form +`eq_zero_of_abs_deriv_le_mul_abs_self_of_eq_zero_right`, fed the primitive `G t = ∫₀ᵗ g`) +forces `g ≡ 0`, i.e. `Xₜ = Yₜ` a.s. for every `t`. + +**Honest scope.** This is the *uniqueness* half only; existence of a strong solution is +delivered separately (and, at the current toolchain, conditionally in the `L²` space `E`) by +`MathFin.SDEExistence.picardMap_exists_unique_fixedPoint`. The diffusion operator enters through +an abstract `Iσ` whose only assumed property is the isometric energy bound `hIso` — a genuine +theorem about the Itô integral, not the uniqueness conclusion in disguise. + +## Main definitions + +* `IsL2SolutionPair`: two `L²` strong solutions of `dZ = μ(Z)dt + σ(Z)dB`, `Z₀ = η` with a shared + driver, packaged with the regularity the energy argument uses. + +## Main results + +* `gronwall_zero_of_le_const_mul_integral`: Grönwall in integral form with `a = 0`: a nonnegative + `g`, continuous on `[0,∞)`, with `g t ≤ K · ∫₀ᵗ g` on `[0, b]` vanishes there. +* `sde_pathwise_uniqueness`: the `L²`-energy Grönwall argument showing two solutions agree almost + surely at every time, under the drift and diffusion bounds taken as hypotheses. +* `IsL2SolutionPair.uniqueness`: two `L²` strong solutions sharing a driver agree almost surely + at every time. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Theorem 8.2.5 + +## Tags + +pathwise uniqueness, Grönwall inequality, stochastic differential equation, Itô isometry, +Lipschitz coefficients, strong solution, MSC 60H10, MSC 60H05 +-/ + +@[expose] public section + +open MeasureTheory intervalIntegral Set Topology +open scoped NNReal ENNReal + +namespace MathFin + +/-- **Grönwall, integral form, `a = 0`.** A nonnegative `g`, continuous on `[0,∞)`, with +`g t ≤ K · ∫₀ᵗ g` for every `t ≥ 0` (and `K ≥ 0`), vanishes on `[0,∞)`. The primitive +`G t = ∫₀ᵗ g` is `C¹` with `G' = g` (FTC, `g` continuous), `G 0 = 0`, and +`‖G' x‖ = g x ≤ K·G x = K‖G x‖`, so +`eq_zero_of_abs_deriv_le_mul_abs_self_of_eq_zero_right` gives `G ≡ 0`; then +`g t ≤ K·G t = 0` with `g ≥ 0` gives `g t = 0`. -/ +theorem gronwall_zero_of_le_const_mul_integral {g : ℝ → ℝ} {K b : ℝ} + (hg0 : ∀ t, 0 ≤ g t) (hgc : ContinuousOn g (Set.Ici 0)) + (hle : ∀ t ∈ Set.Icc 0 b, g t ≤ K * ∫ s in (0 : ℝ)..t, g s) : + ∀ t ∈ Set.Icc 0 b, g t = 0 := by + intro t ht + obtain ⟨ht0, htb⟩ := ht + set G : ℝ → ℝ := fun u ↦ ∫ s in (0:ℝ)..u, g s with hGdef + -- g is interval-integrable on every [0,u] with u ≥ 0 (continuous on Ici 0) + have hgii : ∀ u, 0 ≤ u → IntervalIntegrable g volume 0 u := by + intro u hu + apply ContinuousOn.intervalIntegrable + rw [Set.uIcc_of_le hu] + exact hgc.mono Set.Icc_subset_Ici_self + -- G ≥ 0 on [0,∞) + have hGnonneg : ∀ u, 0 ≤ u → 0 ≤ G u := by + intro u hu + exact intervalIntegral.integral_nonneg hu (fun s _ ↦ hg0 s) + -- G continuous on [0,t] + have hGcont : ContinuousOn G (Set.Icc 0 t) := by + have hInt : IntegrableOn g (Set.uIcc 0 t) volume := by + apply ContinuousOn.integrableOn_uIcc + rw [Set.uIcc_of_le ht0]; exact hgc.mono Set.Icc_subset_Ici_self + have hc := intervalIntegral.continuousOn_primitive_interval hInt + rwa [Set.uIcc_of_le ht0] at hc + -- FTC: G' = g on [0,t) + have hGderiv : ∀ x ∈ Set.Ico 0 t, HasDerivWithinAt G (g x) (Set.Ici x) x := by + intro x hx + have hmono : Set.Ioi x ⊆ Set.Ici 0 := + Set.Ioi_subset_Ici_self.trans (Set.Ici_subset_Ici.mpr hx.1) + have hcont : ContinuousWithinAt g (Set.Ioi x) x := (hgc x hx.1).mono hmono + have hmeas : StronglyMeasurableAtFilter g (𝓝[Set.Ioi x] x) volume := + ((hgc.mono (Set.Ici_subset_Ici.mpr hx.1)).stronglyMeasurableAtFilter_nhdsWithin + measurableSet_Ici x).filter_mono (nhdsWithin_mono x Set.Ioi_subset_Ici_self) + exact intervalIntegral.integral_hasDerivWithinAt_right (hgii x hx.1) hmeas hcont + have hG0 : G 0 = 0 := by simp [hGdef] + -- the Grönwall bound ‖G' x‖ = g x ≤ K G x = K‖G x‖ + have hbound : ∀ x ∈ Set.Ico 0 t, ‖g x‖ ≤ K * ‖G x‖ := by + intro x hx + rw [Real.norm_of_nonneg (hg0 x), Real.norm_of_nonneg (hGnonneg x hx.1)] + exact hle x ⟨hx.1, hx.2.le.trans htb⟩ + have hGzero := eq_zero_of_abs_deriv_le_mul_abs_self_of_eq_zero_right hGcont hGderiv hG0 hbound + have hGt : G t = 0 := hGzero t (Set.right_mem_Icc.mpr ht0) + -- g t ≤ K * G t = 0, and g t ≥ 0 + have hint0 : (∫ s in (0:ℝ)..t, g s) = 0 := hGt + have hlt := hle t ⟨ht0, htb⟩ + rw [hint0, mul_zero] at hlt + exact le_antisymm hlt (hg0 t) + +/-- **Cauchy–Schwarz in time** (interval-integral form): `(∫₀ˢ f)² ≤ s·∫₀ˢ f²` for `0 ≤ s`, +given `f ∈ L²` on `(0,s]`. -/ +lemma sq_intervalIntegral_le {f : ℝ → ℝ} {s : ℝ} (hs : 0 ≤ s) + (hf : MemLp f 2 (volume.restrict (Set.Ioc 0 s))) : + (∫ u in (0:ℝ)..s, f u) ^ 2 ≤ s * ∫ u in (0:ℝ)..s, (f u) ^ 2 := by + have hcs := sq_integral_le_measureReal_mul hf + rw [Measure.restrict_apply_univ, Real.volume_Ioc, sub_zero, ENNReal.toReal_ofReal hs] at hcs + rw [intervalIntegral.integral_of_le hs, intervalIntegral.integral_of_le hs] + exact hcs + +/-- **Drift energy bound** (Cauchy–Schwarz in time + Lipschitz `μ` + Tonelli). With `μ_coef` +`Lμ`-Lipschitz, the `L²` energy of the drift-difference `∫₀ˢ (μ(Xᵤ)−μ(Yᵤ)) du` is controlled by +the time-integrated state energy: +`𝔼[(∫₀ˢ(μ(Xᵤ)−μ(Yᵤ)))²] ≤ Lμ²·s·∫₀ˢ 𝔼[(Xᵤ−Yᵤ)²]`. This *derives* the drift hypothesis of +`sde_pathwise_uniqueness` (with `Cdrift = Lμ²`), so the drift term is not assumed but proven. -/ +lemma drift_energy_le {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {μ_coef : ℝ → ℝ} {Lμ : ℝ≥0} (hμ : LipschitzWith Lμ μ_coef) + {X Y : ℝ → Ω → ℝ} {s : ℝ} (hs : 0 ≤ s) + (hfL2 : ∀ᵐ ω ∂μ, + MemLp (fun u ↦ μ_coef (X u ω) - μ_coef (Y u ω)) 2 (volume.restrict (Set.Ioc 0 s))) + (hLHSint : Integrable (fun ω ↦ (∫ u in (0 : ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2) μ) + (hprodXY : Integrable (Function.uncurry fun u ω ↦ (X u ω - Y u ω) ^ 2) + ((volume.restrict (Set.uIoc 0 s)).prod μ)) : + (∫ ω, (∫ u in (0:ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2 ∂μ) + ≤ (Lμ : ℝ) ^ 2 * s * ∫ u in (0:ℝ)..s, (∫ ω, (X u ω - Y u ω) ^ 2 ∂μ) := by + -- the state-error interval- and time-integrability come from product-integrability (Fubini) + have hXYii : ∀ᵐ ω ∂μ, IntervalIntegrable (fun u ↦ (X u ω - Y u ω) ^ 2) volume 0 s := by + filter_upwards [hprodXY.prod_left_ae] with ω hω + simp only [Function.uncurry] at hω + rw [Set.uIoc_of_le hs] at hω + exact (intervalIntegrable_iff_integrableOn_Ioc_of_le hs).mpr hω + have hRHSint : Integrable (fun ω ↦ ∫ u in (0:ℝ)..s, (X u ω - Y u ω) ^ 2) μ := by + refine (hprodXY.integral_prod_right).congr (ae_of_all _ fun ω ↦ ?_) + simp only [Function.uncurry] + rw [intervalIntegral.integral_of_le hs, Set.uIoc_of_le hs] + -- a.e. pointwise: (∫₀ˢ (μ(Xᵤ)−μ(Yᵤ)))² ≤ s·(Lμ²·∫₀ˢ (Xᵤ−Yᵤ)²) + have hptw : ∀ᵐ ω ∂μ, (∫ u in (0:ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2 + ≤ s * ((Lμ : ℝ) ^ 2 * ∫ u in (0:ℝ)..s, (X u ω - Y u ω) ^ 2) := by + filter_upwards [hfL2, hXYii] with ω hL2 hii + have hCS := sq_intervalIntegral_le hs hL2 + have hLip : ∀ u, (μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2 + ≤ (Lμ : ℝ) ^ 2 * (X u ω - Y u ω) ^ 2 := by + intro u + have hd := hμ.dist_le_mul (X u ω) (Y u ω) + rw [Real.dist_eq, Real.dist_eq] at hd + have h1 : (μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2 + = |μ_coef (X u ω) - μ_coef (Y u ω)| ^ 2 := (sq_abs _).symm + have h2 : (Lμ : ℝ) ^ 2 * (X u ω - Y u ω) ^ 2 = ((Lμ : ℝ) * |X u ω - Y u ω|) ^ 2 := by + rw [mul_pow, sq_abs] + rw [h1, h2] + exact pow_le_pow_left₀ (abs_nonneg _) hd 2 + have hLHS_ii : IntervalIntegrable (fun u ↦ (μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2) volume 0 s := + (intervalIntegrable_iff_integrableOn_Ioc_of_le hs).mpr hL2.integrable_sq + have hmono : (∫ u in (0:ℝ)..s, (μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2) + ≤ ∫ u in (0:ℝ)..s, (Lμ : ℝ) ^ 2 * (X u ω - Y u ω) ^ 2 := + intervalIntegral.integral_mono_on hs hLHS_ii (hii.const_mul _) (fun u _ ↦ hLip u) + calc (∫ u in (0:ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2 + ≤ s * ∫ u in (0:ℝ)..s, (μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2 := hCS + _ ≤ s * ∫ u in (0:ℝ)..s, (Lμ : ℝ) ^ 2 * (X u ω - Y u ω) ^ 2 := + mul_le_mul_of_nonneg_left hmono hs + _ = s * ((Lμ : ℝ) ^ 2 * ∫ u in (0:ℝ)..s, (X u ω - Y u ω) ^ 2) := by + rw [intervalIntegral.integral_const_mul] + calc (∫ ω, (∫ u in (0:ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2 ∂μ) + ≤ ∫ ω, s * ((Lμ : ℝ) ^ 2 * ∫ u in (0:ℝ)..s, (X u ω - Y u ω) ^ 2) ∂μ := + integral_mono_ae hLHSint ((hRHSint.const_mul _).const_mul _) hptw + _ = s * (Lμ : ℝ) ^ 2 * ∫ ω, (∫ u in (0:ℝ)..s, (X u ω - Y u ω) ^ 2) ∂μ := by + rw [MeasureTheory.integral_const_mul, MeasureTheory.integral_const_mul]; ring + _ = s * (Lμ : ℝ) ^ 2 * ∫ u in (0:ℝ)..s, ∫ ω, (X u ω - Y u ω) ^ 2 ∂μ := by + rw [← MeasureTheory.intervalIntegral_integral_swap + (f := fun u ω ↦ (X u ω - Y u ω) ^ 2) hprodXY] + _ = (Lμ : ℝ) ^ 2 * s * ∫ u in (0:ℝ)..s, ∫ ω, (X u ω - Y u ω) ^ 2 ∂μ := by ring + +/-- **Pathwise SDE uniqueness via the `L²`-energy Grönwall argument.** Let `X, Y : ℝ → Ω → ℝ` +both solve `Z t = η + ∫₀ᵗ μ(Zₛ)ds + (Iσ Z)ₜ` (the initial condition `η` is common and cancels in +the difference `hdecomp`). Given the two standard `L²` energy estimates — the **drift bound** +`hdrift` (Cauchy–Schwarz in time + Lipschitz `μ`, contributing the factor `s`) and the +**diffusion bound** `hIso` (the **Itô isometry** + Lipschitz `σ`) — together with the regularity +that the state error is square-integrable per time (`hXYint`), its two pieces are square-integrable +(`hDint`, `hJint`), and the energy `s ↦ 𝔼[(Xₛ−Yₛ)²]` is continuous (`hEcont`), the two solutions +agree almost surely at every time. + +The energy `E s = 𝔼[(Xₛ−Yₛ)²]` satisfies `E s ≤ (2·Cdrift·s + 2·Cdiff)·∫₀ˢ E`; on `[0,t]` the +prefactor is dominated by the constant `K = 2·Cdrift·t + 2·Cdiff`, and +`gronwall_zero_of_le_const_mul_integral` forces `E ≡ 0`, i.e. `Xₜ = Yₜ` a.s. -/ +theorem sde_pathwise_uniqueness + {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + {μ_coef : ℝ → ℝ} {X Y : ℝ → Ω → ℝ} {Iσ : (ℝ → Ω → ℝ) → ℝ → Ω → ℝ} + {Cdrift Cdiff : ℝ} (hCd : 0 ≤ Cdrift) + (hXYint : ∀ s, 0 ≤ s → Integrable (fun ω ↦ (X s ω - Y s ω) ^ 2) μ) + (hDint : ∀ s, 0 ≤ s → + Integrable (fun ω ↦ (∫ u in (0 : ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2) μ) + (hJint : ∀ s, 0 ≤ s → Integrable (fun ω ↦ ((Iσ X) s ω - (Iσ Y) s ω) ^ 2) μ) + (hEcont : ContinuousOn (fun s ↦ ∫ ω, (X s ω - Y s ω) ^ 2 ∂μ) (Set.Ici 0)) + (hdecomp : ∀ s, 0 ≤ s → ∀ᵐ ω ∂μ, X s ω - Y s ω + = (∫ u in (0 : ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) + ((Iσ X) s ω - (Iσ Y) s ω)) + (hdrift : ∀ s, 0 ≤ s → + (∫ ω, (∫ u in (0 : ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2 ∂μ) + ≤ Cdrift * s * ∫ u in (0 : ℝ)..s, (∫ ω, (X u ω - Y u ω) ^ 2 ∂μ)) + (hIso : ∀ s, 0 ≤ s → + (∫ ω, ((Iσ X) s ω - (Iσ Y) s ω) ^ 2 ∂μ) + ≤ Cdiff * ∫ u in (0 : ℝ)..s, (∫ ω, (X u ω - Y u ω) ^ 2 ∂μ)) : + ∀ t, 0 ≤ t → ∀ᵐ ω ∂μ, X t ω = Y t ω := by + -- the L² energy of the state error + set E : ℝ → ℝ := fun s ↦ ∫ ω, (X s ω - Y s ω) ^ 2 ∂μ + have hE0 : ∀ s, 0 ≤ E s := fun s ↦ integral_nonneg fun ω ↦ sq_nonneg _ + have hAnn : ∀ s, 0 ≤ s → 0 ≤ ∫ u in (0:ℝ)..s, E u := fun s hs ↦ + intervalIntegral.integral_nonneg hs fun u _ ↦ hE0 u + -- per-time energy inequality: E s ≤ 2·Cdrift·s·(∫₀ˢ E) + 2·Cdiff·(∫₀ˢ E) + have hEbound : ∀ s, 0 ≤ s → + E s ≤ 2 * Cdrift * s * (∫ u in (0:ℝ)..s, E u) + 2 * Cdiff * (∫ u in (0:ℝ)..s, E u) := by + intro s hs + have hEeq : E s = ∫ ω, ((∫ u in (0:ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) + + ((Iσ X) s ω - (Iσ Y) s ω)) ^ 2 ∂μ := by + apply MeasureTheory.integral_congr_ae + filter_upwards [hdecomp s hs] with ω hω + rw [hω] + have hptw : ∀ ω, ((∫ u in (0:ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) + + ((Iσ X) s ω - (Iσ Y) s ω)) ^ 2 + ≤ 2 * (∫ u in (0:ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2 + + 2 * ((Iσ X) s ω - (Iσ Y) s ω) ^ 2 := fun ω ↦ by + nlinarith [sq_nonneg ((∫ u in (0:ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) + - ((Iσ X) s ω - (Iσ Y) s ω))] + have hLint : Integrable (fun ω ↦ ((∫ u in (0:ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) + + ((Iσ X) s ω - (Iσ Y) s ω)) ^ 2) μ := by + apply (hXYint s hs).congr + filter_upwards [hdecomp s hs] with ω hω + rw [hω] + have hRint : Integrable (fun ω ↦ 2 * (∫ u in (0:ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2 + + 2 * ((Iσ X) s ω - (Iσ Y) s ω) ^ 2) μ := + ((hDint s hs).const_mul 2).add ((hJint s hs).const_mul 2) + rw [hEeq] + calc ∫ ω, ((∫ u in (0:ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) + + ((Iσ X) s ω - (Iσ Y) s ω)) ^ 2 ∂μ + ≤ ∫ ω, (2 * (∫ u in (0:ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2 + + 2 * ((Iσ X) s ω - (Iσ Y) s ω) ^ 2) ∂μ := integral_mono hLint hRint hptw + _ = 2 * (∫ ω, (∫ u in (0:ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2 ∂μ) + + 2 * (∫ ω, ((Iσ X) s ω - (Iσ Y) s ω) ^ 2 ∂μ) := by + rw [integral_add ((hDint s hs).const_mul 2) ((hJint s hs).const_mul 2), + MeasureTheory.integral_const_mul, MeasureTheory.integral_const_mul] + _ ≤ 2 * (Cdrift * s * ∫ u in (0:ℝ)..s, E u) + 2 * (Cdiff * ∫ u in (0:ℝ)..s, E u) := + add_le_add (by have := hdrift s hs; linarith) + (by have := hIso s hs; linarith) + _ = 2 * Cdrift * s * (∫ u in (0:ℝ)..s, E u) + 2 * Cdiff * (∫ u in (0:ℝ)..s, E u) := by ring + -- conclude via Grönwall on each [0,t] + intro t ht + have hEt : E t = 0 := by + refine gronwall_zero_of_le_const_mul_integral hE0 hEcont (K := 2 * Cdrift * t + 2 * Cdiff) + (b := t) ?_ t ⟨ht, le_rfl⟩ + intro s hs + obtain ⟨hs0, hst⟩ := hs + have hAs : 0 ≤ ∫ u in (0:ℝ)..s, E u := hAnn s hs0 + calc E s ≤ 2 * Cdrift * s * (∫ u in (0:ℝ)..s, E u) + 2 * Cdiff * (∫ u in (0:ℝ)..s, E u) := + hEbound s hs0 + _ ≤ (2 * Cdrift * t + 2 * Cdiff) * ∫ u in (0:ℝ)..s, E u := by + have hmono : 2 * Cdrift * s ≤ 2 * Cdrift * t := + mul_le_mul_of_nonneg_left hst (mul_nonneg (by norm_num) hCd) + rw [add_mul] + linarith [mul_le_mul_of_nonneg_right hmono hAs] + -- E t = 0 with a nonnegative integrand ⇒ Xₜ = Yₜ a.s. + have hsq0 : (fun ω ↦ (X t ω - Y t ω) ^ 2) =ᵐ[μ] 0 := + (integral_eq_zero_iff_of_nonneg (fun ω ↦ sq_nonneg _) (hXYint t ht)).mp hEt + filter_upwards [hsq0] with ω hω + simp only [Pi.zero_apply] at hω + exact sub_eq_zero.mp (sq_eq_zero_iff.mp hω) + +/-- **A pair of `L²` strong solutions** of `dZ = μ(Z)dt + σ(Z)dB`, `Z₀ = η`, sharing the driver, +packaged with the regularity the `L²`-energy Grönwall uniqueness argument consumes. This is the +honest re-encoding of the textbook existence/uniqueness structure: uniqueness is **not** a field but +a *theorem* (`IsL2SolutionPair.uniqueness`) derived from these hypotheses. The diffusion enters +through the operator `Iσ` (read `Iσ Z ≈ ∫₀ᵗ σ(Zₛ)dB`); its only assumed property is the **Itô +isometry bound** `isometry` — a genuine property of the Itô integral +(`MathFin.ItoIntegralProcessGeneral.itoProcessCLM_norm_sq`), not the uniqueness conclusion. The +drift is **not** assumed controlled: `lipschitz` (plus the drift regularity) *derives* its energy +bound via `drift_energy_le`. -/ +structure IsL2SolutionPair {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + (μ_coef : ℝ → ℝ) (Lμ : ℝ≥0) (Cdiff : ℝ) + (X Y : ℝ → Ω → ℝ) (Iσ : (ℝ → Ω → ℝ) → ℝ → Ω → ℝ) : Prop where + /-- The drift coefficient is `Lμ`-Lipschitz (Theorem 8.2.5 hypothesis). -/ + lipschitz : LipschitzWith Lμ μ_coef + /-- Both processes solve the SDE integral equation; the common initial condition `η` cancels in + the difference. -/ + solvesDiff : ∀ s, 0 ≤ s → ∀ᵐ ω ∂μ, X s ω - Y s ω + = (∫ u in (0:ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) + ((Iσ X) s ω - (Iσ Y) s ω) + /-- The `L²` error `s ↦ 𝔼[(Xₛ−Yₛ)²]` is continuous (continuous `L²` solution paths). -/ + energyCont : ContinuousOn (fun s ↦ ∫ ω, (X s ω - Y s ω) ^ 2 ∂μ) (Set.Ici 0) + /-- **Itô isometry bound** for the diffusion difference — the sole assumed property of `Iσ`. -/ + isometry : ∀ s, 0 ≤ s → (∫ ω, ((Iσ X) s ω - (Iσ Y) s ω) ^ 2 ∂μ) + ≤ Cdiff * ∫ u in (0:ℝ)..s, (∫ ω, (X u ω - Y u ω) ^ 2 ∂μ) + /-- The state error is square-integrable at each time. -/ + stateSq : ∀ s, 0 ≤ s → Integrable (fun ω ↦ (X s ω - Y s ω) ^ 2) μ + /-- The drift-difference integrand is `L²` in time, a.e. `ω`. -/ + driftMemL2 : ∀ s, 0 ≤ s → ∀ᵐ ω ∂μ, + MemLp (fun u ↦ μ_coef (X u ω) - μ_coef (Y u ω)) 2 (volume.restrict (Set.Ioc 0 s)) + /-- The drift term is square-integrable. -/ + driftSq : ∀ s, 0 ≤ s → + Integrable (fun ω ↦ (∫ u in (0:ℝ)..s, μ_coef (X u ω) - μ_coef (Y u ω)) ^ 2) μ + /-- The diffusion term is square-integrable. -/ + diffSq : ∀ s, 0 ≤ s → Integrable (fun ω ↦ ((Iσ X) s ω - (Iσ Y) s ω) ^ 2) μ + /-- The squared state error is jointly integrable on `(0,s] × Ω` (for Tonelli). Its two + marginals — interval-integrability in time and integrability of the time-integral — are Fubini + consequences, derived inside `drift_energy_le` rather than carried as separate fields. -/ + stateSqProdInt : ∀ s, 0 ≤ s → Integrable (Function.uncurry fun u ω ↦ (X u ω - Y u ω) ^ 2) + ((volume.restrict (Set.uIoc 0 s)).prod μ) + +/-- **Theorem 8.2.5 (uniqueness), pathwise `L²` form.** Two `L²` strong solutions sharing a driver +agree almost surely at every time. The drift energy bound is derived from Lipschitz `μ` +(`drift_energy_le`), the diffusion from the Itô isometry (`isometry` field), and the `L²`-energy +Grönwall argument (`sde_pathwise_uniqueness`) closes it. -/ +theorem IsL2SolutionPair.uniqueness {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {μ_coef : ℝ → ℝ} {Lμ : ℝ≥0} {Cdiff : ℝ} + {X Y : ℝ → Ω → ℝ} {Iσ : (ℝ → Ω → ℝ) → ℝ → Ω → ℝ} + (h : IsL2SolutionPair μ μ_coef Lμ Cdiff X Y Iσ) : + ∀ t, 0 ≤ t → ∀ᵐ ω ∂μ, X t ω = Y t ω := + sde_pathwise_uniqueness (Cdrift := (Lμ : ℝ) ^ 2) (sq_nonneg _) + h.stateSq h.driftSq h.diffSq h.energyCont h.solvesDiff + (fun s hs ↦ drift_energy_le h.lipschitz hs (h.driftMemL2 s hs) (h.driftSq s hs) + (h.stateSqProdInt s hs)) + h.isometry + +/-- **Non-vacuity guard**: the hypothesis bundle is satisfiable — the zero solution on any +probability space is an `IsL2SolutionPair`. So `IsL2SolutionPair.uniqueness` is not vacuously +true of a contradictory hypothesis set. -/ +example {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] : + IsL2SolutionPair μ (μ_coef := fun _ ↦ 0) (Lμ := 0) (Cdiff := 0) + (X := fun _ _ ↦ 0) (Y := fun _ _ ↦ 0) (Iσ := fun _ _ _ ↦ 0) where + lipschitz := (LipschitzWith.const (0 : ℝ)).weaken (le_refl 0) + solvesDiff := fun s _ ↦ ae_of_all _ fun ω ↦ by simp + energyCont := by simpa using continuousOn_const + isometry := fun s _ ↦ by simp + stateSq := fun s _ ↦ by simp + driftMemL2 := fun s _ ↦ ae_of_all _ fun ω ↦ by simp + driftSq := fun s _ ↦ by simp + diffSq := fun s _ ↦ by simp + stateSqProdInt := fun s _ ↦ by + simp only [sub_self, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, zero_pow] + exact integrable_zero _ _ _ + +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/UnifPart.lean b/LeanPool/MathFin/Probability/Brownian/UnifPart.lean new file mode 100644 index 0000000000..2963b24a39 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/UnifPart.lean @@ -0,0 +1,130 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Tactic.NormNum.RealSqrt +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.Analysis.RCLike.Basic +public import Mathlib.Analysis.SpecificLimits.Basic + +/-! +# The uniform partition of `[0, T]` + +The library's one equipartition: `unifPart T n k = (k/n)·T`, the `k`-th of the `n + 1` nodes +`0 = t₀ ≤ … ≤ tₙ = T` that cut `[0, T]` into `n` cells of length `T/n`. Every Riemann sum, +Riemann–Stieltjes sum and quadratic-variation sum of the Itô stack runs along it, so the +facts about it are proved here once: monotone, `≤ T`, endpoints, cell length, the telescoping +`∑ (t_{k+1} − t_k) = T`. + +`unifPartIcc s t` is the same partition of `[s, t]`, shifted to start at `s`. + +## Main definitions + +* `unifPart`: the uniform partition of `[0, T]` into `n` cells, `unifPart T n k = (k/n)·T`. +* `unifPartIcc`: the uniform partition of `[s, t]` into `n` cells, `unifPart (t − s) n k` shifted + to start at `s`. + +## Main results + +* `unifPart_mono`, `unifPart_le_T`, `unifPart_zero`, `unifPart_self` — monotone, bounded by + `T`, and the endpoints `0` and `T`. +* `unifPart_succ_sub`, `unifPart_mesh_sum` — every cell has length `T/n`, and the lengths + telescope to `T`. +* `tendsto_inv_sqrt_nat_add`, `one_div_sqrt_le_two` — the `1/√n` mesh rate of the `O(√mesh)` + bounds: a null sequence, and the shift comparison `1/√n ≤ 2/√(n+1)`. + +## Tags + +uniform partition, equipartition, mesh size, Riemann sum grid, time discretisation, MSC 60H05 +-/ + +@[expose] public section + +namespace MathFin + +open Filter Topology +open scoped NNReal + +/-- The uniform partition of `[0, T]`: the `n`-th refinement places its `k`-th node at `kT/n`. -/ +noncomputable def unifPart (T : ℝ≥0) (n k : ℕ) : ℝ≥0 := (k : ℝ≥0) / (n : ℝ≥0) * T + +@[simp] lemma unifPart_zero (T : ℝ≥0) (n : ℕ) : unifPart T n 0 = 0 := by simp [unifPart] + +/-- The last node of the uniform partition into `n ≠ 0` cells is `T`. -/ +lemma unifPart_self (T : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : unifPart T n n = T := by + have hn0 : (n : ℝ≥0) ≠ 0 := Nat.cast_ne_zero.2 hn + simp [unifPart, hn0] + +/-- The partition points `unifPart T n = (k/n)·T` are monotone in `k`. -/ +lemma unifPart_mono (T : ℝ≥0) (n : ℕ) : Monotone (unifPart T n) := + fun _ _ hab ↦ by unfold unifPart; gcongr + +/-- A partition point `unifPart T n j ≤ T` whenever `j ≤ n`. -/ +lemma unifPart_le_T {T : ℝ≥0} {n j : ℕ} (hj : j ≤ n) : unifPart T n j ≤ T := by + rcases eq_or_ne n 0 with rfl | hn + · obtain rfl := Nat.le_zero.1 hj; simp + · exact (unifPart_mono T n hj).trans_eq (unifPart_self T hn) + +/-- The cells of the uniform partition have length `T/n`. -/ +lemma unifPart_succ_sub (T : ℝ≥0) (n k : ℕ) : + ((unifPart T n (k + 1) : ℝ) - unifPart T n k) = (T : ℝ) / n := by + push_cast [unifPart] + ring + +/-- The uniform-partition mesh telescopes: `∑_{k simp + | add x y hx hy => rw [map_add, map_add]; exact add_mem hx hy + | single i a => + rw [stepAssembly, Finsupp.linearCombination_single, map_smul] + exact Submodule.smul_mem _ _ (h i) + +/-- The Brownian increment, as an element of `Lp`, is `m`-measurable when its endpoints are. -/ +lemma wienerIncrementLp_mem_lpMeas (hB : IsPreBrownianReal B μ) + (i : StepIndex T) (h1 : StronglyMeasurable[m] (B i.1.1)) + (h2 : StronglyMeasurable[m] (B i.1.2)) : + wienerIncrementLp B hB i ∈ lpMeas ℝ ℝ m 2 μ := by + rw [mem_lpMeas_iff_aestronglyMeasurable] + exact (h2.sub h1).aestronglyMeasurable.congr + (MemLp.coeFn_toLp (memLp_increment hB i.1.1 i.1.2)).symm + +variable [IsProbabilityMeasure μ] + +/-- The Wiener integral of the kernel restricted to `(0, t]` is `𝓕_t`-measurable. -/ +lemma wienerIntegralLp_past_mem_lpMeas (hB : IsPreBrownianReal B μ) + (hBm : ∀ s, Measurable (B s)) (htT : t ≤ T) + (f : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) T))) : + wienerIntegralLp B hB t (kernelRestrict htT f) + ∈ lpMeas ℝ ℝ (Filtration.natural B (fun s ↦ (hBm s).stronglyMeasurable) t) 2 μ := by + have hF := Filtration.stronglyAdapted_natural (fun s ↦ (hBm s).stronglyMeasurable) + refine mem_lpMeas_of_stepIndicator ((Filtration.natural B _).le t) + ((wienerIntegralLp B hB t).comp (kernelRestrict htT)) (fun i ↦ ?_) f + simp only [ContinuousLinearMap.comp_apply, kernelRestrict_stepIndicatorLp, + wienerIntegralLp_stepIndicator] + exact wienerIncrementLp_mem_lpMeas hB _ + ((hF _).mono ((Filtration.natural B _).mono (min_le_right _ _))) + ((hF _).mono ((Filtration.natural B _).mono (min_le_right _ _))) + +/-- The σ-algebra of the post-`t` increments `ω ↦ (B_{t+s} − B_t)_s`. -/ +abbrev postσ (B : ℝ≥0 → Ω → ℝ) (t : ℝ≥0) : MeasurableSpace Ω := + MeasurableSpace.comap (fun ω (s : ℝ≥0) ↦ B (t + s) ω - B t ω) inferInstance + +lemma postσ_le (hBm : ∀ s, Measurable (B s)) (t : ℝ≥0) : postσ B t ≤ mΩ := + Measurable.comap_le (.of_eval fun _ ↦ (hBm _).sub (hBm _)) + +lemma stronglyMeasurable_postσ (s : ℝ≥0) : + StronglyMeasurable[postσ B t] fun ω ↦ B (t + s) ω - B t ω := + ((measurable_pi_apply s).comp + (comap_measurable fun ω (s : ℝ≥0) ↦ B (t + s) ω - B t ω)).stronglyMeasurable + +/-- The remainder `∫₀ᵀ f dB − ∫₀ᵗ f dB` of a step indicator is `postσ`-measurable: it is the +increment of the post-`t` process over `((s − t)⁺, (u − t)⁺]`. -/ +lemma wienerIntegralLp_future_step_mem_lpMeas (hB : IsPreBrownianReal B μ) (htT : t ≤ T) + (i : StepIndex T) : + wienerIntegralLp B hB T (stepIndicatorLp T i) + - wienerIntegralLp B hB t (kernelRestrict htT (stepIndicatorLp T i)) + ∈ lpMeas ℝ ℝ (postσ B t) 2 μ := by + rw [mem_lpMeas_iff_aestronglyMeasurable, kernelRestrict_stepIndicatorLp, + wienerIntegralLp_stepIndicator, wienerIntegralLp_stepIndicator] + refine ((stronglyMeasurable_postσ (B := B) (t := t) (i.1.2 - t)).sub + (stronglyMeasurable_postσ (B := B) (t := t) (i.1.1 - t))).aestronglyMeasurable.congr ?_ + filter_upwards [Lp.coeFn_sub (wienerIncrementLp B hB i) (wienerIncrementLp B hB (stepClip t i)), + MemLp.coeFn_toLp (memLp_increment hB i.1.1 i.1.2), + MemLp.coeFn_toLp (memLp_increment hB (stepClip t i).1.1 (stepClip t i).1.2)] with ω h1 h2 h3 + rw [h1, Pi.sub_apply] + change _ = (wienerIncrementLp B hB i : Ω → ℝ) ω - _ + rw [show (wienerIncrementLp B hB i : Ω → ℝ) ω = B i.1.2 ω - B i.1.1 ω from h2, + show (wienerIncrementLp B hB (stepClip t i) : Ω → ℝ) ω + = B (min i.1.2 t) ω - B (min i.1.1 t) ω from h3] + rcases le_total i.1.2 t with h | h <;> rcases le_total i.1.1 t with h' | h' <;> + simp [tsub_eq_zero_of_le, add_tsub_cancel_of_le, *] + +/-- The remainder `∫₀ᵀ f dB − ∫₀ᵗ f dB` of any kernel is `postσ`-measurable, hence independent of +the past. -/ +lemma wienerIntegralLp_future_mem_lpMeas (hB : IsPreBrownianReal B μ) + (hBm : ∀ s, Measurable (B s)) (htT : t ≤ T) + (f : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) T))) : + wienerIntegralLp B hB T f - wienerIntegralLp B hB t (kernelRestrict htT f) + ∈ lpMeas ℝ ℝ (postσ B t) 2 μ := + mem_lpMeas_of_stepIndicator (postσ_le hBm t) + (wienerIntegralLp B hB T - (wienerIntegralLp B hB t).comp (kernelRestrict htT)) + (fun i ↦ wienerIntegralLp_future_step_mem_lpMeas hB htT i) f + +lemma integral_sq_Ioc_split (htT : t ≤ T) (f : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) T))) : + ∫ s in Set.Ioc (0 : ℝ) T, f s ^ 2 + = (∫ s in Set.Ioc (0 : ℝ) t, f s ^ 2) + ∫ s in Set.Ioc (t : ℝ) T, f s ^ 2 := by + have hsq : Integrable (fun s ↦ f s ^ 2) (volume.restrict (Set.Ioc (0 : ℝ) T)) := + (Lp.memLp f).integrable_sq + have ht : (t : ℝ) ≤ T := NNReal.coe_le_coe.2 htT + have h := setIntegral_union (μ := volume) (f := fun s ↦ f s ^ 2) + (Set.disjoint_left.2 fun x (hx : x ∈ Set.Ioc (0 : ℝ) t) (hy : x ∈ Set.Ioc (t : ℝ) T) ↦ + absurd hx.2 (not_le.2 hy.1)) measurableSet_Ioc + (hsq.mono_measure (Measure.restrict_mono (Set.Ioc_subset_Ioc_right ht) le_rfl)) + (hsq.mono_measure (Measure.restrict_mono (Set.Ioc_subset_Ioc_left t.coe_nonneg) le_rfl)) + rw [Set.Ioc_union_Ioc_eq_Ioc t.coe_nonneg ht] at h + exact h + +/-- The Wiener integral over `(0, t]` is `𝓕_t`-measurable. -/ +lemma wienerIntegralLp_mem_lpMeas (hB : IsPreBrownianReal B μ) (hBm : ∀ s, Measurable (B s)) + (h : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) t))) : + wienerIntegralLp B hB t h + ∈ lpMeas ℝ ℝ (Filtration.natural B (fun s ↦ (hBm s).stronglyMeasurable) t) 2 μ := by + have hF := Filtration.stronglyAdapted_natural (fun s ↦ (hBm s).stronglyMeasurable) + refine mem_lpMeas_of_stepIndicator ((Filtration.natural B _).le t) (wienerIntegralLp B hB t) + (fun i ↦ ?_) h + rw [wienerIntegralLp_stepIndicator] + exact wienerIncrementLp_mem_lpMeas hB _ + ((hF _).mono ((Filtration.natural B _).mono (i.2.1.trans i.2.2))) + ((hF _).mono ((Filtration.natural B _).mono i.2.2)) + +/-- **The remainder factor.** For a `postσ`-measurable representative `N'` of the remainder +`∫₀ᵀ f dB − ∫₀ᵗ f dB`, the factor `e^{−cN'}` is integrable with mean `e^{c²∫_t^T f²/2}`: the +remainder is independent of the past part, and the product of the two factors is the Gaussian +exponential moment of `∫₀ᵀ f dB`. -/ +lemma integral_exp_neg_future (hB : IsPreBrownianReal B μ) (hBm : ∀ s, Measurable (B s)) + (htT : t ≤ T) (f : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) T))) (c : ℝ) {N' : Ω → ℝ} + (hN'm : StronglyMeasurable[postσ B t] N') + (hNN' : ((wienerIntegralLp B hB T f + - wienerIntegralLp B hB t (kernelRestrict htT f) : Lp ℝ 2 μ) : Ω → ℝ) =ᵐ[μ] N') : + Integrable (fun ω ↦ Real.exp (-(c * N' ω))) μ ∧ + ∫ ω, Real.exp (-(c * N' ω)) ∂μ + = Real.exp (c ^ 2 * (∫ s in Set.Ioc (t : ℝ) T, f s ^ 2) / 2) := by + have hle := (Filtration.natural B (fun s ↦ (hBm s).stronglyMeasurable)).le t + obtain ⟨P', hP'm, hPP'⟩ := mem_lpMeas_iff_aestronglyMeasurable.1 + (wienerIntegralLp_past_mem_lpMeas hB hBm htT f) + have hW : (wienerIntegralLp B hB T f : Ω → ℝ) =ᵐ[μ] P' + N' := by + filter_upwards [Lp.coeFn_sub (wienerIntegralLp B hB T f) + (wienerIntegralLp B hB t (kernelRestrict htT f)), hPP', hNN'] with ω h1 h2 h3 + rw [Pi.add_apply, ← h2] + rw [Pi.sub_apply] at h1 + linarith + set E1 : Ω → ℝ := fun ω ↦ Real.exp (-(c * P' ω)) with hE1def + set E2 : Ω → ℝ := fun ω ↦ Real.exp (-(c * N' ω)) with hE2def + have hE1 : StronglyMeasurable[Filtration.natural B (fun s ↦ (hBm s).stronglyMeasurable) t] E1 := + Real.continuous_exp.comp_stronglyMeasurable (hP'm.const_mul c).neg + have hE2 : StronglyMeasurable[postσ B t] E2 := + Real.continuous_exp.comp_stronglyMeasurable (hN'm.const_mul c).neg + have hprod : (fun ω ↦ Real.exp (-(c * wienerIntegralLp B hB T f ω))) =ᵐ[μ] E1 * E2 := by + filter_upwards [hW] with ω h + rw [Pi.mul_apply, hE1def, hE2def] + simp only + rw [← Real.exp_add, h, Pi.add_apply] + congr 1 + ring + have hWint : Integrable (fun ω ↦ Real.exp (-(c * wienerIntegralLp B hB T f ω))) μ := + ((wienerIntegralLp_hasLaw_gaussian hB T f).integrable_fun_comp + (integrable_exp_mul_gaussianReal (-c))).congr + (ae_of_all _ fun ω ↦ by simp only [neg_mul]) + have hint : Integrable (E1 * E2) μ := hWint.congr hprod + have hindep : Indep (postσ B t) + (Filtration.natural B (fun s ↦ (hBm s).stronglyMeasurable) t) μ := + shift_indep_natural hB hBm t + have hIndFun : IndepFun E1 E2 μ := + (IndepFun_iff_Indep _ _ _).2 + (indep_of_indep_of_le_right (indep_of_indep_of_le_left hindep.symm hE1.measurable.comap_le) + hE2.measurable.comap_le) + have hE1ae : AEStronglyMeasurable E1 μ := (hE1.mono hle).aestronglyMeasurable + have hE2ae : AEStronglyMeasurable E2 μ := (hE2.mono (postσ_le hBm t)).aestronglyMeasurable + have hE2int : Integrable E2 μ := + hIndFun.integrable_right_of_integrable_op (fun x y ↦ x * y) 1 one_ne_zero + (fun x y ↦ by simp [eNorm_mul]) hint hE1ae hE2ae + fun h ↦ by obtain ⟨ω, hω⟩ := h.exists; exact (Real.exp_pos _).ne' hω + refine ⟨hE2int, ?_⟩ + have hI_W : ∫ ω, (E1 * E2) ω ∂μ = Real.exp (c ^ 2 * ‖f‖ ^ 2 / 2) := by + rw [← integral_congr_ae hprod] + have := integral_exp_mul_wienerIntegralLp hB T f (-c) + simpa only [neg_mul, neg_sq] using this + have hI_P : ∫ ω, E1 ω ∂μ + = Real.exp (c ^ 2 * ‖kernelRestrict htT f‖ ^ 2 / 2) := by + rw [show ∫ ω, E1 ω ∂μ = ∫ ω, Real.exp + (-(c * wienerIntegralLp B hB t (kernelRestrict htT f) ω)) ∂μ from + integral_congr_ae (hPP'.mono fun ω h ↦ by simp only [hE1def, h])] + have := integral_exp_mul_wienerIntegralLp hB t (kernelRestrict htT f) (-c) + simpa only [neg_mul, neg_sq] using this + have hmul := hIndFun.integral_mul_eq_mul_integral hE1ae hE2ae + rw [hI_W, hI_P] at hmul + have hnorm : ‖f‖ ^ 2 = ‖kernelRestrict htT f‖ ^ 2 + ∫ s in Set.Ioc (t : ℝ) T, f s ^ 2 := by + rw [lp_two_norm_sq, lp_two_norm_sq, integral_sq_Ioc_split htT f] + congr 1 + exact integral_congr_ae ((kernelRestrict_coeFn htT f).mono fun x hx ↦ by simp only [hx]) + have hpos := Real.exp_pos (c ^ 2 * ‖kernelRestrict htT f‖ ^ 2 / 2) + refine mul_left_cancel₀ hpos.ne' ?_ + rw [← hmul, ← Real.exp_add, hnorm] + congr 1 + ring + +/-- **The conditional Laplace transform of a Wiener integral.** Given the past `𝓕_t`, the +integral `∫₀ᵀ f dB` is its past part `∫₀ᵗ f dB` (the Wiener integral of the restricted kernel) +plus an independent centred Gaussian of variance `∫_t^T f²`; so, with a further past Wiener +integral `∫₀ᵗ h dB` carried along, + + `𝔼[e^{a + b∫₀ᵗ h dB − c∫₀ᵀ f dB} | 𝓕_t] = e^{a + b∫₀ᵗ h dB − c∫₀ᵗ f dB}·e^{c²∫_t^T f²/2}` + +almost surely. -/ +theorem condExp_exp_wienerIntegralLp (hB : IsPreBrownianReal B μ) + (hBm : ∀ s, Measurable (B s)) (htT : t ≤ T) + (h : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) t))) + (f : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) T))) (a b c : ℝ) : + μ[fun ω ↦ Real.exp (a + b * wienerIntegralLp B hB t h ω - c * wienerIntegralLp B hB T f ω) + | Filtration.natural B (fun s ↦ (hBm s).stronglyMeasurable) t] + =ᵐ[μ] fun ω ↦ Real.exp (a + b * wienerIntegralLp B hB t h ω + - c * wienerIntegralLp B hB t (kernelRestrict htT f) ω) + * Real.exp (c ^ 2 * (∫ s in Set.Ioc (t : ℝ) T, f s ^ 2) / 2) := by + set 𝓕t := Filtration.natural B (fun s ↦ (hBm s).stronglyMeasurable) t + have hle : 𝓕t ≤ mΩ := (Filtration.natural B _).le t + obtain ⟨P', hP'm, hPP'⟩ := mem_lpMeas_iff_aestronglyMeasurable.1 + (wienerIntegralLp_past_mem_lpMeas hB hBm htT f) + obtain ⟨H', hH'm, hHH'⟩ := mem_lpMeas_iff_aestronglyMeasurable.1 + (wienerIntegralLp_mem_lpMeas hB hBm h) + obtain ⟨N', hN'm, hNN'⟩ := mem_lpMeas_iff_aestronglyMeasurable.1 + (wienerIntegralLp_future_mem_lpMeas hB hBm htT f) + obtain ⟨hE2int, hI_N⟩ := integral_exp_neg_future hB hBm htT f c hN'm hNN' + have hW : (wienerIntegralLp B hB T f : Ω → ℝ) =ᵐ[μ] P' + N' := by + filter_upwards [Lp.coeFn_sub (wienerIntegralLp B hB T f) + (wienerIntegralLp B hB t (kernelRestrict htT f)), hPP', hNN'] with ω h1 h2 h3 + rw [Pi.add_apply, ← h2] + rw [Pi.sub_apply] at h1 + linarith + set E1 : Ω → ℝ := fun ω ↦ Real.exp (a + b * H' ω - c * P' ω) + set E2 : Ω → ℝ := fun ω ↦ Real.exp (-(c * N' ω)) + have hE1 : StronglyMeasurable[𝓕t] E1 := + Real.continuous_exp.comp_stronglyMeasurable + ((stronglyMeasurable_const.add (hH'm.const_mul b)).sub (hP'm.const_mul c)) + have hE2 : StronglyMeasurable[postσ B t] E2 := + Real.continuous_exp.comp_stronglyMeasurable (hN'm.const_mul c).neg + have hprod : (fun ω ↦ Real.exp (a + b * wienerIntegralLp B hB t h ω + - c * wienerIntegralLp B hB T f ω)) =ᵐ[μ] E1 * E2 := by + filter_upwards [hW, hHH'] with ω hw hh + dsimp only [E1, E2, Pi.mul_apply] + rw [← Real.exp_add, hw, hh, Pi.add_apply] + congr 1 + ring + -- `E1` is integrable: a Gaussian exponential moment + have hlin : (wienerIntegralLp B hB t (b • h - c • kernelRestrict htT f) : Ω → ℝ) + =ᵐ[μ] fun ω ↦ b * wienerIntegralLp B hB t h ω + - c * wienerIntegralLp B hB t (kernelRestrict htT f) ω := by + rw [map_sub, map_smul, map_smul] + filter_upwards [Lp.coeFn_sub (b • wienerIntegralLp B hB t h) + (c • wienerIntegralLp B hB t (kernelRestrict htT f)), + Lp.coeFn_smul b (wienerIntegralLp B hB t h), + Lp.coeFn_smul c (wienerIntegralLp B hB t (kernelRestrict htT f))] with ω h1 h2 h3 + rw [h1, Pi.sub_apply, h2, h3] + rfl + have hE1int : Integrable E1 μ := + (((wienerIntegralLp_hasLaw_gaussian hB t + (b • h - c • kernelRestrict htT f)).integrable_fun_comp + (integrable_exp_mul_gaussianReal 1)).const_mul (Real.exp a)).congr <| by + filter_upwards [hlin, hPP', hHH'] with ω h1 h2 h3 + dsimp only [E1] + rw [← Real.exp_add, one_mul, h1, ← h2, ← h3] + congr 1 + ring + refine (condExp_congr_ae hprod).trans + ((condExp_mul_of_indep hle (postσ_le hBm t) (shift_indep_natural hB hBm t) hE1 hE2 hE1int + hE2int).trans ?_) + filter_upwards [hPP', hHH'] with ω hP hH + rw [hI_N] + simp only [E1, hP, hH] + +end Closure + +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Wiener/WienerIntegralGaussian.lean b/LeanPool/MathFin/Probability/Brownian/Wiener/WienerIntegralGaussian.lean new file mode 100644 index 0000000000..0a2326bfb2 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Wiener/WienerIntegralGaussian.lean @@ -0,0 +1,309 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralL2 +public import Mathlib.RingTheory.WittVector.IsPoly +public import Mathlib.Tactic.Polynomial.Basic +public import Mathlib.Tactic.ReduceModChar +public import Std.Tactic.BVDecide.Normalize.Prop + +/-! +# The Wiener integral of a deterministic integrand is Gaussian + +The Wiener integral `wienerIntegralLp B hB T : L²([0,T]) →L[ℝ] L²(μ)` +(`Probability/Brownian/Wiener/WienerIntegralL2.lean`) was built as an isometry — its *norm* is +pinned (`wienerIntegralLp_norm`, `wienerIntegralLp_integral_sq`) but its *law* +was not. This file proves the missing distributional fact: + + for a **deterministic** integrand `f ∈ L²([0,T])`, the random variable + `ω ↦ (wienerIntegralLp B hB T f) ω` is **Gaussian**, centred, with variance + `‖f‖²₂ = ∫₀ᵀ f²`: + + `μ.map (wienerIntegralLp B hB T f) = gaussianReal 0 ‖f‖²`. + +This is the structural fact behind every linear-SDE terminal law (Vasicek / +Ornstein–Uhlenbeck / Hull–White): the diffusion term `σ ∫₀ᵗ e^{−κ(t−s)} dB_s` +is a deterministic-integrand Itô integral, hence Gaussian, with variance fixed +by the isometry. See `Models/Rates/VasicekSDEGaussian.lean`. + +## Proof + +The Wiener integral is the `extendOfNorm` closure of the elementary integral +`wienerAssembly` on simple (step) processes, along the dense embedding +`stepAssembly` of step indicators in `L²([0,T])` (`stepAssembly_denseRange`). + +1. **Simple processes are Gaussian.** `wienerAssembly B hB T x = + ∑ᵢ xᵢ (B_{tᵢ} − B_{sᵢ})` is a finite linear combination of the Gaussian + process `B`. The scaled-increment family is a Gaussian process + (`IsGaussianProcess.of_isGaussianProcess`), so its finite sum is Gaussian + (`hasGaussianLaw_fun_sum`). `map_eq_gaussianReal` then pins the law to + `gaussianReal 0 ‖stepAssembly x‖²` — mean `0` (Brownian increments are + centred) and variance `‖wienerAssembly x‖² = ‖stepAssembly x‖²` (the Itô + isometry, `wiener_assembly_isometry`). + +2. **Pass to the L²-limit by characteristic functions.** For each frequency + `t`, the map `g ↦ charFun (μ.map (wienerIntegralLp g)) t` is continuous + (charFun is `|t|`-Lipschitz in the `L²` random variable) and equals + `exp(−‖g‖² t²/2)` on the dense simple processes; both sides are continuous, + so they agree on all of `L²([0,T])` (`DenseRange.induction_on`). Two finite + measures on `ℝ` with equal characteristic functions coincide + (`Measure.ext_of_charFun`), giving the law. + +## Main results + +* `wienerIntegralLp_map_eq_gaussianReal`: `μ.map (wienerIntegralLp B hB T f) = + gaussianReal 0 (‖f‖²).toNNReal`. +* `wienerIntegralLp_hasLaw_gaussian`: the `HasLaw` form with the variance in + integral shape `(∫₀ᵀ f²).toNNReal`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Ch 6/7 + +## Tags + +Wiener integral, Gaussian law, deterministic integrand, Ornstein–Uhlenbeck, Vasicek model, +characteristic function, MSC 60H05, MSC 60G15, MSC 60J65 +-/ + +@[expose] public section + +namespace MathFin +namespace WienerIntegralL2 + +open MeasureTheory ProbabilityTheory Finset Complex +open scoped NNReal ENNReal Topology InnerProductSpace + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-! ### The Wiener integral agrees with the elementary integral on step processes -/ + +/-- On the range of `stepAssembly`, the extended Wiener integral is the +elementary integral `wienerAssembly` (this is `LinearMap.extendOfNorm_eq`). -/ +lemma wienerIntegralLp_stepAssembly (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (x : StepIndex T →₀ ℝ) : + wienerIntegralLp B hB T (stepAssembly T x) = wienerAssembly B hB T x := by + rw [wienerIntegralLp, + LinearMap.extendOfNorm_eq (stepAssembly_denseRange T) + ⟨1, fun y ↦ by rw [one_mul]; exact (wiener_assembly_isometry hB T y).le⟩] + +/-! ### Simple processes are Gaussian -/ + +omit [IsProbabilityMeasure μ] in +/-- Explicit a.e. form of the elementary integral: `wienerAssembly B hB T x` +agrees a.e. with the finite sum of scaled Brownian increments. -/ +lemma wienerAssembly_coeFn (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (x : StepIndex T →₀ ℝ) : + (wienerAssembly B hB T x : Ω → ℝ) =ᵐ[μ] + fun ω ↦ ∑ i ∈ x.support, x i • (B i.1.2 ω - B i.1.1 ω) := by + have hExpand : wienerAssembly B hB T x + = ∑ i ∈ x.support, x i • wienerIncrementLp B hB i := by + rw [wienerAssembly, Finsupp.linearCombination_apply, Finsupp.sum] + have hterm : ∀ i ∈ x.support, + (↑(x i • wienerIncrementLp B hB i) : Ω → ℝ) + =ᵐ[μ] fun ω ↦ x i • (B i.1.2 ω - B i.1.1 ω) := by + intro i _ + filter_upwards [Lp.coeFn_smul (x i) (wienerIncrementLp B hB i), + MemLp.coeFn_toLp (memLp_increment hB i.1.1 i.1.2)] with ω hsmul htoLp + rw [hsmul] + simp only [Pi.smul_apply] + rw [show (wienerIncrementLp B hB i : Ω → ℝ) ω = B i.1.2 ω - B i.1.1 ω from htoLp] + rw [hExpand] + refine (Lp.coeFn_finsetSum x.support (fun i ↦ x i • wienerIncrementLp B hB i)).trans ?_ + filter_upwards [(Filter.eventually_all_finset x.support).2 hterm] with ω hω + rw [Finset.sum_apply] + exact Finset.sum_congr rfl (fun i hi ↦ hω i hi) + +omit [IsProbabilityMeasure μ] in +/-- The scaled-increment family `i ↦ xᵢ (B_{hiᵢ} − B_{loᵢ})` is a Gaussian +process: each value is a (continuous-linear) combination of finitely many +values of the Gaussian process `B`. -/ +lemma isGaussianProcess_scaledIncrement (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (x : StepIndex T →₀ ℝ) : + IsGaussianProcess (fun (i : StepIndex T) ω ↦ x i • (B i.1.2 ω - B i.1.1 ω)) μ := by + refine hB.isGaussianProcess.of_isGaussianProcess (fun i ↦ ⟨{i.1.1, i.1.2}, + LinearMap.toContinuousLinearMap + { toFun := fun v ↦ x i • (v ⟨i.1.2, by simp⟩ - v ⟨i.1.1, by simp⟩) + map_add' := fun v w ↦ by simp only [Pi.add_apply]; module + map_smul' := fun c v ↦ by simp only [Pi.smul_apply, RingHom.id_apply]; module }, ?_⟩) + intro ω + simp [Finset.restrict] + +omit [IsProbabilityMeasure μ] in +/-- A simple (step-process) Wiener integral has a Gaussian law. -/ +lemma wienerAssembly_hasGaussianLaw (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (x : StepIndex T →₀ ℝ) : + HasGaussianLaw (fun ω ↦ (wienerAssembly B hB T x) ω) μ := by + have hsum : HasGaussianLaw + (fun ω ↦ ∑ i ∈ x.support, x i • (B i.1.2 ω - B i.1.1 ω)) μ := + (isGaussianProcess_scaledIncrement hB T x).hasGaussianLaw_fun_sum (I := x.support) + exact hsum.congr (wienerAssembly_coeFn hB T x).symm + +/-- The elementary integral is centred: `∫ wienerAssembly B hB T x ∂μ = 0`. -/ +lemma wienerAssembly_integral_zero (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (x : StepIndex T →₀ ℝ) : + ∫ ω, (wienerAssembly B hB T x) ω ∂μ = 0 := by + rw [integral_congr_ae (wienerAssembly_coeFn hB T x)] + have hsum : ∫ ω, ∑ i ∈ x.support, x i • (B i.1.2 ω - B i.1.1 ω) ∂μ + = ∑ i ∈ x.support, ∫ ω, x i • (B i.1.2 ω - B i.1.1 ω) ∂μ := + integral_finsetSum x.support + (fun i _ ↦ Integrable.smul (x i) ((memLp_increment hB i.1.1 i.1.2).integrable one_le_two)) + rw [hsum] + refine Finset.sum_eq_zero (fun i _ ↦ ?_) + rw [integral_smul, + integral_sub ((hB.isGaussianProcess.hasGaussianLaw_eval i.1.2).memLp_two.integrable one_le_two) + ((hB.isGaussianProcess.hasGaussianLaw_eval i.1.1).memLp_two.integrable one_le_two), + hB.integral_eval i.1.2, hB.integral_eval i.1.1, sub_zero, smul_zero] + +/-- The law of a simple-process Wiener integral: `gaussianReal 0 ‖stepAssembly x‖²`. -/ +lemma wienerAssembly_map_eq_gaussianReal (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (x : StepIndex T →₀ ℝ) : + μ.map (fun ω ↦ (wienerAssembly B hB T x) ω) + = gaussianReal 0 (‖stepAssembly T x‖ ^ 2).toNNReal := by + rw [(wienerAssembly_hasGaussianLaw hB T x).map_eq_gaussianReal] + have hmean : μ[fun ω ↦ (wienerAssembly B hB T x) ω] = 0 := + wienerAssembly_integral_zero hB T x + have hvar : Var[fun ω ↦ (wienerAssembly B hB T x) ω; μ] = ‖stepAssembly T x‖ ^ 2 := by + rw [variance_eq_integral + ((Lp.aestronglyMeasurable (wienerAssembly B hB T x)).aemeasurable), hmean] + simp only [sub_zero] + rw [← lp_two_norm_sq (wienerAssembly B hB T x), ← wiener_assembly_isometry hB T x] + rw [hmean, hvar] + +/-! ### Pass to the L²-limit by characteristic functions -/ + +/-- Auxiliary: on a probability measure, `∫ ‖g‖ ≤ ‖g‖₂` for `g ∈ L²`. -/ +lemma L1_norm_le_L2_norm_prob (g : Lp ℝ 2 μ) : + ∫ ω, ‖g ω‖ ∂μ ≤ ‖g‖ := by + rw [show (∫ ω, ‖g ω‖ ∂μ) = (eLpNorm (g : Ω → ℝ) 1 μ).toReal by + rw [eLpNorm_one_eq_lintegral_eNorm (Lp.aestronglyMeasurable g), + ← integral_norm_eq_lintegral_eNorm (Lp.aestronglyMeasurable g)], + Lp.norm_def] + exact ENNReal.toReal_mono (Lp.eLpNorm_ne_top g) + (eLpNorm_le_eLpNorm_of_exponent_le one_le_two) + +/-- The characteristic function of `μ.map h` is `|t|`-Lipschitz in `h : L²(μ)`. -/ +lemma charFun_map_lp_dist_le (t : ℝ) (h₁ h₂ : Lp ℝ 2 μ) : + ‖charFun (μ.map (h₁ : Ω → ℝ)) t - charFun (μ.map (h₂ : Ω → ℝ)) t‖ + ≤ |t| * ‖h₁ - h₂‖ := by + have hInt : ∀ h : Lp ℝ 2 μ, Integrable (fun ω ↦ cexp (↑t * ↑(h ω) * I)) μ := fun h ↦ + (memLp_top_of_bound (by fun_prop) 1 + (ae_of_all _ fun ω ↦ by rw [Complex.norm_exp]; simp)).integrable le_top + have hcf : ∀ h : Lp ℝ 2 μ, charFun (μ.map (h : Ω → ℝ)) t + = ∫ ω, cexp (↑t * ↑(h ω) * I) ∂μ := by + intro h + rw [charFun_apply_real, integral_map (Lp.aestronglyMeasurable h).aemeasurable + (Continuous.aestronglyMeasurable (by fun_prop))] + have hbound : ∀ ω, ‖cexp (↑t * ↑(h₁ ω) * I) - cexp (↑t * ↑(h₂ ω) * I)‖ + ≤ |t| * |h₁ ω - h₂ ω| := by + intro ω + have hfac : cexp (↑t * ↑(h₁ ω) * I) - cexp (↑t * ↑(h₂ ω) * I) + = cexp (↑t * ↑(h₂ ω) * I) * (cexp (I * ((t * (h₁ ω - h₂ ω) : ℝ) : ℂ)) - 1) := by + rw [mul_sub, mul_one, ← Complex.exp_add, + show (↑t * ↑(h₂ ω) * I + I * ((t * (h₁ ω - h₂ ω) : ℝ) : ℂ)) = ↑t * ↑(h₁ ω) * I by + push_cast; ring] + rw [hfac, norm_mul, show ‖cexp (↑t * ↑(h₂ ω) * I)‖ = 1 by + rw [show (↑t * ↑(h₂ ω) * I : ℂ) = ↑(t * h₂ ω) * I by push_cast; ring, + Complex.norm_exp_ofReal_mul_I], one_mul] + calc ‖cexp (I * ((t * (h₁ ω - h₂ ω) : ℝ) : ℂ)) - 1‖ + ≤ ‖(t * (h₁ ω - h₂ ω) : ℝ)‖ := Real.norm_exp_I_mul_ofReal_sub_one_le + _ = |t| * |h₁ ω - h₂ ω| := by rw [Real.norm_eq_abs, abs_mul] + have hint_bound : Integrable (fun ω ↦ |t| * |h₁ ω - h₂ ω|) μ := by + refine Integrable.const_mul ?_ _ + have hi : Integrable (fun ω ↦ (h₁ - h₂) ω) μ := (Lp.memLp (h₁ - h₂)).integrable one_le_two + refine hi.abs.congr ?_ + filter_upwards [Lp.coeFn_sub h₁ h₂] with ω hω; rw [hω, Pi.sub_apply] + rw [hcf, hcf] + calc ‖(∫ ω, cexp (↑t * ↑(h₁ ω) * I) ∂μ) - ∫ ω, cexp (↑t * ↑(h₂ ω) * I) ∂μ‖ + = ‖∫ ω, (cexp (↑t * ↑(h₁ ω) * I) - cexp (↑t * ↑(h₂ ω) * I)) ∂μ‖ := by + rw [integral_sub (hInt h₁) (hInt h₂)] + _ ≤ ∫ ω, ‖cexp (↑t * ↑(h₁ ω) * I) - cexp (↑t * ↑(h₂ ω) * I)‖ ∂μ := + norm_integral_le_integral_norm _ + _ ≤ ∫ ω, |t| * |h₁ ω - h₂ ω| ∂μ := + integral_mono_of_nonneg (ae_of_all _ fun ω ↦ norm_nonneg _) hint_bound + (ae_of_all _ hbound) + _ = |t| * ∫ ω, |h₁ ω - h₂ ω| ∂μ := by rw [integral_const_mul] + _ ≤ |t| * ‖h₁ - h₂‖ := by + refine mul_le_mul_of_nonneg_left ?_ (abs_nonneg t) + have hcongr : ∫ ω, |h₁ ω - h₂ ω| ∂μ = ∫ ω, ‖(h₁ - h₂) ω‖ ∂μ := by + refine integral_congr_ae ?_ + filter_upwards [Lp.coeFn_sub h₁ h₂] with ω hω + rw [hω, Real.norm_eq_abs, Pi.sub_apply] + rw [hcongr] + exact L1_norm_le_L2_norm_prob _ + +/-- **The Wiener integral of a deterministic integrand is Gaussian.** For every +`f ∈ L²([0,T])`, `μ.map (wienerIntegralLp B hB T f) = gaussianReal 0 ‖f‖²`. -/ +theorem wienerIntegralLp_map_eq_gaussianReal (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (f : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ)))) : + μ.map (fun ω ↦ (wienerIntegralLp B hB T f) ω) + = gaussianReal 0 (‖f‖ ^ 2).toNNReal := by + refine Measure.ext_of_charFun (funext fun t ↦ ?_) + have hcont1 : Continuous (fun g : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) ↦ + charFun (μ.map (fun ω ↦ (wienerIntegralLp B hB T g) ω)) t) := by + have hL : LipschitzWith |t|.toNNReal + (fun h : Lp ℝ 2 μ ↦ charFun (μ.map (h : Ω → ℝ)) t) := + LipschitzWith.of_dist_le_mul fun h₁ h₂ ↦ by + rw [Complex.dist_eq] + refine (charFun_map_lp_dist_le t h₁ h₂).trans (le_of_eq ?_) + rw [Real.coe_toNNReal _ (abs_nonneg t), dist_eq_norm] + exact hL.continuous.comp (wienerIntegralLp B hB T).continuous + have hcont2 : Continuous (fun g : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) ↦ + cexp (-(((‖g‖ ^ 2 : ℝ) : ℂ) * (t : ℂ) ^ 2 / 2))) := by + apply Continuous.cexp; fun_prop + have hbase : ∀ x : StepIndex T →₀ ℝ, + charFun (μ.map (fun ω ↦ (wienerIntegralLp B hB T (stepAssembly T x)) ω)) t + = cexp (-(((‖stepAssembly T x‖ ^ 2 : ℝ) : ℂ) * (t : ℂ) ^ 2 / 2)) := by + intro x + rw [wienerIntegralLp_stepAssembly hB T x, wienerAssembly_map_eq_gaussianReal hB T x, + charFun_gaussianReal] + congr 1 + rw [show (((‖stepAssembly T x‖ ^ 2).toNNReal : ℝ)) = ‖stepAssembly T x‖ ^ 2 from + Real.coe_toNNReal _ (by positivity)] + push_cast; ring + have hf_eq : charFun (μ.map (fun ω ↦ (wienerIntegralLp B hB T f) ω)) t + = cexp (-(((‖f‖ ^ 2 : ℝ) : ℂ) * (t : ℂ) ^ 2 / 2)) := + (stepAssembly_denseRange T).induction_on + (p := fun g ↦ charFun (μ.map (fun ω ↦ (wienerIntegralLp B hB T g) ω)) t + = cexp (-(((‖g‖ ^ 2 : ℝ) : ℂ) * (t : ℂ) ^ 2 / 2))) + f (isClosed_eq hcont1 hcont2) hbase + rw [hf_eq, charFun_gaussianReal] + congr 1 + rw [show (((‖f‖ ^ 2).toNNReal : ℝ)) = ‖f‖ ^ 2 from Real.coe_toNNReal _ (by positivity)] + push_cast; ring + +/-- **`HasLaw` form**, with the variance in integral shape `∫₀ᵀ f²`. -/ +theorem wienerIntegralLp_hasLaw_gaussian (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (f : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ)))) : + HasLaw (fun ω ↦ (wienerIntegralLp B hB T f) ω) + (gaussianReal 0 (∫ s in Set.Ioc (0 : ℝ) (T : ℝ), (f s) ^ 2 ∂volume).toNNReal) μ where + aemeasurable := (Lp.aestronglyMeasurable _).aemeasurable + map_eq := by + rw [wienerIntegralLp_map_eq_gaussianReal hB T f] + congr 2 + exact lp_two_norm_sq f + +/-- The `L²` representative of an `L²` function has the same squared integral. -/ +theorem _root_.MeasureTheory.MemLp.integral_sq_toLp {α : Type*} {mα : MeasurableSpace α} + {ν : Measure α} {f : α → ℝ} (hf : MemLp f 2 ν) : + ∫ x, (hf.toLp f x) ^ 2 ∂ν = ∫ x, f x ^ 2 ∂ν := + integral_congr_ae <| hf.coeFn_toLp.mono fun _ hx ↦ by simp only [hx] + +/-- **`HasLaw` form with the variance given**: when `∫₀ᵀ f² = v`, the Wiener integral of `f` is +`N(0, v)`. -/ +theorem wienerIntegralLp_hasLaw_gaussian_of_integral_sq (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (f : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ)))) {v : ℝ} + (hv : ∫ s in Set.Ioc (0 : ℝ) (T : ℝ), (f s) ^ 2 ∂volume = v) : + HasLaw (fun ω ↦ (wienerIntegralLp B hB T f) ω) (gaussianReal 0 v.toNNReal) μ := + hv ▸ wienerIntegralLp_hasLaw_gaussian hB T f + +end WienerIntegralL2 +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Wiener/WienerIntegralIndicator.lean b/LeanPool/MathFin/Probability/Brownian/Wiener/WienerIntegralIndicator.lean new file mode 100644 index 0000000000..b5c94c9e2d --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Wiener/WienerIntegralIndicator.lean @@ -0,0 +1,68 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralL2 + +/-! +# The Wiener integral of a step indicator is the increment + +The Wiener isometry `wienerIntegralLp B hB T : L²([0,T]) →L[ℝ] L²(μ)` is built as +`(wienerAssembly).extendOfNorm (stepAssembly)` — the norm-continuous extension of the +map that sends the step indicator `𝟙_{(s,t]}` to the Brownian increment `B_t − B_s`. +This file records the *defining* identity that the extension actually realizes on those +generators, + + `wienerIntegralLp B hB T (stepIndicatorLp T i) = wienerIncrementLp B hB i`, + +i.e. `∫ 𝟙_{(s,t]} dB = B_t − B_s`. It is immediate from +`LinearMap.extendOfNorm_eq` (the extension agrees with the base map on the dense +subspace) applied to the single-basis coefficient `Finsupp.single i 1`, since both +assembly maps are `Finsupp.linearCombination` of their respective generators. This is +the piece that lets a finite sum of Brownian values `∑ᵢ B_{tᵢ}` be read as a single +Wiener integral of the deterministic step kernel `∑ᵢ 𝟙_{(0,tᵢ]}` — the route the +geometric-average Asian option (and any BM-value basket) takes to its Gaussian law. + +## Main results + +* `wienerIntegralLp_stepIndicator`: the Wiener integral of a step indicator is the Brownian + increment, `∫ 𝟙_{(lo, hi]} dB = B_hi − B_lo`. + +## Tags + +Wiener integral, Brownian increment, step indicator, isometry extension, geometric Asian option, +step kernel, MSC 60H05, MSC 60J65 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal +open WienerIntegralL2 + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} + +/-- **The Wiener integral of a step indicator is the Brownian increment**: +`∫ 𝟙_{(lo,hi]} dB = B_hi − B_lo`. The extension `wienerIntegralLp` agrees with the base +assembly on the dense span of step indicators (`LinearMap.extendOfNorm_eq`), and on the +single-basis coefficient `stepAssembly (single i 1) = stepIndicatorLp i`, +`wienerAssembly (single i 1) = wienerIncrementLp i`. -/ +lemma wienerIntegralLp_stepIndicator (hB : IsPreBrownianReal B μ) (T : ℝ≥0) (i : StepIndex T) : + wienerIntegralLp B hB T (stepIndicatorLp T i) = wienerIncrementLp B hB i := by + have hstep : stepIndicatorLp T i = stepAssembly T (Finsupp.single i (1 : ℝ)) := by + rw [stepAssembly, Finsupp.linearCombination_single, one_smul] + have hincr : wienerIncrementLp B hB i = wienerAssembly B hB T (Finsupp.single i (1 : ℝ)) := by + rw [wienerAssembly, Finsupp.linearCombination_single, one_smul] + rw [hstep, hincr, wienerIntegralLp] + exact LinearMap.extendOfNorm_eq (stepAssembly_denseRange T) + ⟨1, fun z ↦ by rw [one_mul]; exact (wiener_assembly_isometry hB T z).le⟩ _ + +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Wiener/WienerIntegralIto.lean b/LeanPool/MathFin/Probability/Brownian/Wiener/WienerIntegralIto.lean new file mode 100644 index 0000000000..84c70da15d --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Wiener/WienerIntegralIto.lean @@ -0,0 +1,227 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Brownian.Ito.ItoIntegralCLM +public import LeanPool.MathFin.Probability.Brownian.Wiener.WienerIntegralIndicator + +/-! +# The Wiener integral is the Itô integral of a deterministic integrand + +`WienerIntegralL2.wienerIntegralLp` (on `L²((0, T])`) and `ItoIntegralCLM.itoIntegralCLM` (on the +predictable `L²` space `Lp ℝ 2 (trimMeasure T)`) are built by the same `extendOfNorm` +construction. This file identifies them: embedding `f ∈ L²((0, T])` as the deterministic process +`(s, ω) ↦ f s` (`detEmbed`, an isometry), the Wiener integral is the Itô integral of that process, + + `wienerIntegralLp B hB T = itoIntegralCLM hB T hBmeas ∘ detEmbed T hBmeas`. + +## Main definitions + +* `detEmbed`: the isometric embedding `L²((0, T]) → L²(trimMeasure T)` sending a kernel `f` to + the deterministic process `(s, ω) ↦ f s`. + +## Main results + +* `wienerIntegralLp_eq_itoIntegralCLM` — the identification of the two continuous linear maps. + +## Scope + +The bridge needs the measurability hypothesis `hBmeas : ∀ t, Measurable (B t)`, because the Itô side +is defined through the natural filtration of `B`; the Wiener integral does not. It only identifies +the two continuous linear maps on `L²((0, T])`. It does not reprove the Wiener isometry, linearity +or Gaussian law, which stay where they are. + +## References + +* [B. Oksendal, *Stochastic Differential Equations*][Oksendal2003], §3.1-3.2 +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Ch 7 + +## Tags + +Wiener integral, Itô integral, deterministic integrand, isometric embedding, predictable L2 space, +MSC 60H05, MSC 60J65 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal InnerProductSpace + +namespace MathFin +namespace WienerIntegralIto +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {μ : Measure Ω} + +/-- The coercion `ℝ≥0 → ℝ` carries the time measure `timeMeasureHorizon T` on `(0, T]` to Lebesgue +measure restricted to `(0, T] ⊆ ℝ`. -/ +lemma measurePreserving_coe_timeMeasureHorizon (T : ℝ≥0) : + MeasurePreserving ((↑) : ℝ≥0 → ℝ) (ItoIntegralCLM.timeMeasureHorizon T) + (volume.restrict (Set.Ioc (0 : ℝ) T)) := by + refine ⟨measurable_coe_nnreal_real, ?_⟩ + ext A hA + rw [Measure.map_apply measurable_coe_nnreal_real hA, ItoIntegralCLM.timeMeasureHorizon, + Measure.restrict_apply (measurable_coe_nnreal_real hA), ItoIntegralL2.timeMeasure, + ItoIntegralL2.measurableEmbedding_nnrealCoe.comap_apply, Measure.restrict_apply hA] + congr 1 + ext x + simp only [Set.mem_image, Set.mem_inter_iff, Set.mem_preimage, Set.mem_Ioc] + constructor + · rintro ⟨y, ⟨hy, h0, hT⟩, rfl⟩ + exact ⟨hy, by exact_mod_cast h0, by exact_mod_cast hT⟩ + · rintro ⟨hx, h0, hT⟩ + exact ⟨⟨x, h0.le⟩, ⟨hx, by exact_mod_cast h0, by exact_mod_cast hT⟩, rfl⟩ + +/-- The time coordinate `ℝ≥0 × Ω → ℝ≥0` is measurable for the predictable σ-algebra: every +`(a, ∞) × Ω` is a countable union of basic predictable rectangles `(a, n] × Ω`. -/ +lemma measurable_fst_predictable (𝓕 : Filtration ℝ≥0 mΩ) : + Measurable[𝓕.predictable, inferInstance] (Prod.fst : ℝ≥0 × Ω → ℝ≥0) := by + let : MeasurableSpace (ℝ≥0 × Ω) := 𝓕.predictable + refine measurable_of_Ioi fun a ↦ ?_ + have : (Prod.fst : ℝ≥0 × Ω → ℝ≥0) ⁻¹' Set.Ioi a = ⋃ n : ℕ, Set.Ioc a n ×ˢ (Set.univ : Set Ω) := by + ext ⟨t, ω⟩ + simp only [Set.mem_preimage, Set.mem_Ioi, Set.mem_iUnion, Set.mem_prod, Set.mem_Ioc, + Set.mem_univ, and_true] + exact ⟨fun h ↦ (exists_nat_ge t).imp fun n hn ↦ ⟨h, hn⟩, fun ⟨_, h, _⟩ ↦ h⟩ + rw [this] + exact MeasurableSet.iUnion fun n ↦ measurableSet_predictable_Ioc_prod (𝓕 := 𝓕) a n + MeasurableSet.univ + +variable [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} + +/-- The time coordinate carries the predictable trim `trimMeasure T` to `timeMeasureHorizon T`: the +trim does not change the measure of a set measurable for the coarser σ-algebra, and `μ` is a +probability measure. -/ +lemma measurePreserving_fst_trimMeasure (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) : + @MeasurePreserving _ _ (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas).predictable _ + Prod.fst (ItoIntegralCLM.trimMeasure (μ := μ) T hBmeas) + (ItoIntegralCLM.timeMeasureHorizon T) := by + set 𝓕 := ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas + let : MeasurableSpace (ℝ≥0 × Ω) := 𝓕.predictable + refine ⟨measurable_fst_predictable 𝓕, ?_⟩ + ext A hA + rw [Measure.map_apply (measurable_fst_predictable 𝓕) hA, ItoIntegralCLM.trimMeasure, + trim_measurableSet_eq _ ((measurable_fst_predictable 𝓕) hA), ← Set.prod_univ, + Measure.prod_prod, measure_univ, mul_one] + +/-- **The deterministic integrands inside the Itô space**: the isometry +`L²((0, T]) → L²(trimMeasure T)` sending `f` to the process `(s, ω) ↦ f s`, the composite of +composition with the coercion `ℝ≥0 → ℝ` and with the time coordinate. -/ +noncomputable def detEmbed (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) : + Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) T)) →ₗᵢ[ℝ] + Lp ℝ 2 (ItoIntegralCLM.trimMeasure (μ := μ) T hBmeas) := + (Lp.compMeasurePreservingₗᵢ ℝ Prod.fst (measurePreserving_fst_trimMeasure (μ := μ) T hBmeas)).comp + (Lp.compMeasurePreservingₗᵢ ℝ ((↑) : ℝ≥0 → ℝ) (measurePreserving_coe_timeMeasureHorizon T)) + + +open WienerIntegralL2 ItoIntegralCLM in +/-- The simple process `𝟙_{(lo, hi] × Ω}` is the indicator of the rectangle, trim-a.e. -/ +lemma ae_simpleAssemblyHorizon_iocSPHorizon (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) + (i : StepIndex T) : + ∀ᵐ z ∂(trimMeasure (μ := μ) T hBmeas), + (simpleAssemblyHorizon (μ := μ) T hBmeas + (iocSPHorizon hBmeas i.2.1 i.2.2 (F := Set.univ) MeasurableSet.univ) : ℝ≥0 × Ω → ℝ) z = + (Set.Ioc i.1.1 i.1.2 ×ˢ (Set.univ : Set Ω)).indicator (fun _ ↦ (1 : ℝ)) z := by + filter_upwards [MemLp.coeFn_toLp (memLp_uncurry_trimMeasure (μ := μ) T hBmeas + (iocSPHorizon hBmeas i.2.1 i.2.2 (F := Set.univ) MeasurableSet.univ).val)] with z hz + calc _ = Function.uncurry + ⇑(iocSPHorizon hBmeas i.2.1 i.2.2 (F := Set.univ) MeasurableSet.univ).val z := + hz + _ = _ := by rw [uncurry_iocSPHorizon_eq] + +open WienerIntegralL2 ItoIntegralCLM in +/-- The embedded step indicator `𝟙_{(lo, hi]}` is the `T`-bounded simple process +`𝟙_{(lo, hi] × Ω}`. -/ +lemma detEmbed_stepIndicatorLp (T : ℝ≥0) (hBmeas : ∀ t, Measurable (B t)) (i : StepIndex T) : + detEmbed (μ := μ) T hBmeas (stepIndicatorLp T i) = + simpleAssemblyHorizon (μ := μ) T hBmeas + (iocSPHorizon hBmeas i.2.1 i.2.2 (F := Set.univ) MeasurableSet.univ) := by + let : MeasurableSpace (ℝ≥0 × Ω) := (ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas).predictable + refine Lp.ext ?_ + have hA := (Lp.coeFn_compMeasurePreserving (p := 2) (stepIndicatorLp T i) + (measurePreserving_coe_timeMeasureHorizon T)).trans + ((measurePreserving_coe_timeMeasureHorizon T).quasiMeasurePreserving.ae_eq_comp + (indicatorConstLp_coeFn (p := 2) (c := (1 : ℝ)) (hs := i.measurableSet_interval) + (hμs := i.restrict_interval_ne_top))) + have hB := (measurePreserving_fst_trimMeasure (μ := μ) T hBmeas).quasiMeasurePreserving.ae_eq_comp + hA + have h2 := Lp.coeFn_compMeasurePreserving (p := 2) + ((Lp.compMeasurePreservingₗᵢ ℝ ((↑) : ℝ≥0 → ℝ) (measurePreserving_coe_timeMeasureHorizon T)) + (stepIndicatorLp T i)) + (measurePreserving_fst_trimMeasure (μ := μ) T hBmeas) + filter_upwards [h2, hB, ae_simpleAssemblyHorizon_iocSPHorizon (μ := μ) T hBmeas i] + with z hz2 hz3 hz5 + refine (hz2.trans hz3).trans (Eq.trans ?_ hz5.symm) + change i.interval.indicator (fun _ ↦ (1 : ℝ)) (z.1 : ℝ) = _ + by_cases h : z.1 ∈ Set.Ioc i.1.1 i.1.2 + · rw [Set.indicator_of_mem (show z ∈ Set.Ioc i.1.1 i.1.2 ×ˢ (Set.univ : Set Ω) from ⟨h, trivial⟩), + Set.indicator_of_mem (show (z.1 : ℝ) ∈ i.interval from + ⟨NNReal.coe_lt_coe.2 h.1, NNReal.coe_le_coe.2 h.2⟩)] + · rw [Set.indicator_of_notMem (show z ∉ Set.Ioc i.1.1 i.1.2 ×ˢ (Set.univ : Set Ω) from + fun hz ↦ h hz.1), + Set.indicator_of_notMem (show (z.1 : ℝ) ∉ i.interval from + fun hh ↦ h ⟨NNReal.coe_lt_coe.1 hh.1, NNReal.coe_le_coe.1 hh.2⟩)] + +open WienerIntegralL2 ItoIntegralCLM in +/-- The elementary Itô integral of `𝟙_{(lo, hi] × Ω}` is the Brownian increment `B_hi − B_lo`. -/ +lemma itoSimpleLp_iocSPHorizon (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) + (i : StepIndex T) : + ItoIntegralL2.itoSimpleLp hB hBmeas + (iocSPHorizon hBmeas i.2.1 i.2.2 (F := Set.univ) MeasurableSet.univ).val = + wienerIncrementLp B hB i := by + refine MemLp.toLp_congr _ _ (Filter.Eventually.of_forall fun ω ↦ ?_) + have hI : (ElementaryPredictableSet.IocProd i.1.1 i.1.2 + (𝓕 := ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas) + (B := Set.univ) MeasurableSet.univ).I = {(i.1.1, i.1.2)} := ite_eq_left i.2.1 + unfold ItoIntegralL2.itoSimple + have hsub : + (iocSPHorizon hBmeas i.2.1 i.2.2 (F := Set.univ) MeasurableSet.univ).val.value.support ⊆ + {(i.1.1, i.1.2)} := fun p hp ↦ by + by_contra hp_not' + have hp_not : p ∉ (ElementaryPredictableSet.IocProd i.1.1 i.1.2 + (𝓕 := ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas) + (B := Set.univ) MeasurableSet.univ).I := by rwa [hI] + apply Finsupp.mem_support_iff.mp hp + change ((ElementaryPredictableSet.IocProd i.1.1 i.1.2 + (𝓕 := ItoIntegralL2.natFiltration (mΩ := mΩ) hBmeas) + (B := Set.univ) MeasurableSet.univ).indicator (1 : ℝ)).value p = 0 + simp [ElementaryPredictableSet.indicator, Finsupp.onFinset_apply, hp_not] + rw [Finsupp.sum_of_support_subset _ hsub (fun p v ↦ v ω * (B p.2 ω - B p.1 ω)) + (fun p _ ↦ by simp), Finset.sum_singleton] + simp only [iocSPHorizon, ElementaryPredictableSet.indicator, Finsupp.onFinset_apply, hI, + Finset.mem_singleton, ite_true] + change Set.univ.indicator (fun _ ↦ (1 : ℝ)) ω * (B i.1.2 ω - B i.1.1 ω) = _ + simp + +open WienerIntegralL2 ItoIntegralCLM in +/-- **The Wiener integral is the Itô integral of the deterministic integrand.** On `L²((0, T])` +the two continuous linear maps agree: `wienerIntegralLp = itoIntegralCLM ∘ detEmbed`. Both are +continuous, they agree on step indicators (each sends `𝟙_{(s, t]}` to `B_t − B_s`), and step +indicators are dense. -/ +theorem wienerIntegralLp_eq_itoIntegralCLM (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (hBmeas : ∀ t, Measurable (B t)) : + wienerIntegralLp B hB T = + (itoIntegralCLM hB T hBmeas).comp (detEmbed (μ := μ) T hBmeas).toContinuousLinearMap := by + have key (i : StepIndex T) : wienerIntegralLp B hB T (stepIndicatorLp T i) = + itoIntegralCLM hB T hBmeas (detEmbed (μ := μ) T hBmeas (stepIndicatorLp T i)) := by + rw [wienerIntegralLp_stepIndicator, detEmbed_stepIndicatorLp, + itoIntegralCLM_simpleAssemblyHorizon, itoSimpleLp_iocSPHorizon] + refine DFunLike.coe_injective <| (stepAssembly_denseRange T).equalizer + (wienerIntegralLp B hB T).continuous + ((itoIntegralCLM hB T hBmeas).comp + (detEmbed (μ := μ) T hBmeas).toContinuousLinearMap).continuous ?_ + refine congrArg DFunLike.coe (Finsupp.lhom_ext + (φ := (wienerIntegralLp B hB T).toLinearMap ∘ₗ stepAssembly T) + (ψ := ((itoIntegralCLM hB T hBmeas).comp + (detEmbed (μ := μ) T hBmeas).toContinuousLinearMap).toLinearMap ∘ₗ stepAssembly T) + fun i a ↦ ?_) + simp only [LinearMap.comp_apply, stepAssembly, Finsupp.linearCombination_single, + ContinuousLinearMap.coe_coe, map_smul, ContinuousLinearMap.comp_apply, key] + rfl + +end WienerIntegralIto +end MathFin diff --git a/LeanPool/MathFin/Probability/Brownian/Wiener/WienerIntegralL2.lean b/LeanPool/MathFin/Probability/Brownian/Wiener/WienerIntegralL2.lean new file mode 100644 index 0000000000..4d15479dd0 --- /dev/null +++ b/LeanPool/MathFin/Probability/Brownian/Wiener/WienerIntegralL2.lean @@ -0,0 +1,448 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Analysis.ExtendOfNormIsometry +public import LeanPool.MathFin.Probability.Analysis.LpMulIsometry +public import LeanPool.MathFin.Probability.Gaussian.GaussianMoments +public import Mathlib.Tactic.Basify +public import Mathlib.Tactic.ENatToNat + +/-! +# Wiener integral on L²([0, T]) + +Builds the continuous linear isometry + + `wienerIntegralLp : Lp ℝ 2 (volume.restrict (Set.Ioc 0 T)) →L[ℝ] Lp ℝ 2 μ` + +from the formal-combination assembly isometry (`assembly_isometry`) via the +standard density / `LinearMap.extendOfNorm` construction. + +## Construction + +1. Index step intervals by `StepIndex T := { (s, t) : ℝ≥0 × ℝ≥0 // s ≤ t ∧ t ≤ T }`. +2. Two linear maps out of the finitely supported coefficient space + `StepIndex T →₀ ℝ`: + * `stepAssembly`: `δ_(s, t) ↦ indicatorConstLp 2 _ _ 1` in + `Lp ℝ 2 (volume.restrict (Set.Ioc 0 T))`. + * `wienerAssembly`: `δ_(s, t) ↦ [fun ω ↦ B t ω - B s ω]` in `Lp ℝ 2 μ`. +3. `‖wienerAssembly f‖ = ‖stepAssembly f‖` for every `f : StepIndex T →₀ ℝ`, + from the BM covariance identity `E[(B_t-B_s)(B_v-B_u)] = vol((s,t]∩(u,v])`. +4. Density of step indicators in `Lp` via orthogonal complement + + π-system induction over `borel_eq_generateFrom_Ioc_le` + + `Lp.ae_eq_zero_of_forall_setIntegral_eq_zero`. +5. `LinearMap.extendOfNorm` yields the CLM `wienerIntegralLp`, an isometry. + +## Main definitions + +* `StepIndex`: a pair `(s, t)` with `s ≤ t ≤ T`, representing the step interval `(s, t]`. +* `stepIndicatorLp`: the indicator `𝟙_{(lo, hi]}` as an element of `L²((0, T])`. +* `wienerIncrementLp`: the Brownian increment `B_hi − B_lo` as an element of `Lp ℝ 2 μ`. +* `stepAssembly`, `wienerAssembly`: the linear maps from finitely supported coefficients on + `StepIndex T` to step functions and to Wiener increments. +* `wienerIntegralLp`: the Wiener integral as a continuous linear map + `L²((0, T]) →L[ℝ] Lp ℝ 2 μ`, the norm-continuous extension of `wienerAssembly` along + `stepAssembly`; `wienerIntegralLp_norm` and `wienerIntegralLp_integral_sq` give the isometry. + +## Main results + +* `wiener_assembly_isometry`: the step-function Itô isometry on + `StepIndex T →₀ ℝ`. +* `stepAssembly_denseRange`: step indicators span a dense subspace of + `Lp ℝ 2 (volume.restrict (Set.Ioc 0 T))`. +* `wienerIntegralLp_norm`: the Itô isometry `‖wienerIntegralLp f‖ = ‖f‖`. +* `wienerIntegralLp_integral_sq`: the Itô isometry in integral form, + `∫ ω, (I f ω)² ∂μ = ∫ s in (0, T], (f s)² ∂volume`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Theorem 6.2.5 + +## Tags + +Wiener integral, Itô isometry, step functions, L2 construction, Brownian motion integral, +density of step functions, MSC 60H05, MSC 60J65, MSC 60G15 +-/ + +@[expose] public section + +namespace MathFin +namespace WienerIntegralL2 + +open MeasureTheory ProbabilityTheory Finset +open scoped NNReal ENNReal Topology InnerProductSpace + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} + {B : ℝ≥0 → Ω → ℝ} + +/-! ### Step-interval index -/ + +/-- A pair `(s, t) ∈ ℝ≥0 × ℝ≥0` with `s ≤ t ≤ T`, representing the half-open +interval `(s, t] ⊆ [0, T]` used as a basic unit of step functions. -/ +abbrev StepIndex (T : ℝ≥0) : Type := { p : ℝ≥0 × ℝ≥0 // p.1 ≤ p.2 ∧ p.2 ≤ T } + +namespace StepIndex +variable {T : ℝ≥0} + +/-- Lower endpoint of the interval, as a real. -/ +def lo (i : StepIndex T) : ℝ := (i.1.1 : ℝ) + +/-- Upper endpoint of the interval, as a real. -/ +def hi (i : StepIndex T) : ℝ := (i.1.2 : ℝ) + +/-- The right endpoint `hi i` of a `StepIndex` is `≤ T`. -/ +lemma hi_le_T (i : StepIndex T) : i.hi ≤ (T : ℝ) := by + unfold hi + exact_mod_cast i.2.2 + +/-- The half-open interval `(lo, hi]` as a subset of ℝ. -/ +def interval (i : StepIndex T) : Set ℝ := Set.Ioc i.lo i.hi + +/-- The `StepIndex` interval `(lo, hi]` is measurable. -/ +lemma measurableSet_interval (i : StepIndex T) : + MeasurableSet (i.interval) := measurableSet_Ioc + +/-- The interval represented by a `StepIndex T` is contained in `(0, T]`. -/ +lemma interval_subset_Ioc_zero_T (i : StepIndex T) : + i.interval ⊆ Set.Ioc (0 : ℝ) (T : ℝ) := by + rintro x ⟨hx_lo, hx_hi⟩ + exact ⟨lt_of_le_of_lt (i.1.1 : ℝ≥0).coe_nonneg hx_lo, + hx_hi.trans i.hi_le_T⟩ + +/-- The `StepIndex` interval has finite Lebesgue measure. -/ +lemma volume_interval_lt_top (i : StepIndex T) : + (volume i.interval) ≠ ∞ := by + rw [interval, Real.volume_Ioc] + exact ENNReal.ofReal_ne_top + +end StepIndex + +/-! ### Lp elements: step indicator and Wiener increment -/ + +/-- Helper: measure of an interval under the restricted volume is finite. -/ +lemma StepIndex.restrict_interval_ne_top {T : ℝ≥0} (i : StepIndex T) : + (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) i.interval ≠ ∞ := by + rw [Measure.restrict_apply i.measurableSet_interval, + Set.inter_eq_left.mpr i.interval_subset_Ioc_zero_T] + exact i.volume_interval_lt_top + +/-- The indicator `𝟙_{(lo, hi]}` as an element of `Lp ℝ 2 (volume.restrict (Set.Ioc 0 T))`. -/ +noncomputable def stepIndicatorLp (T : ℝ≥0) (i : StepIndex T) : + Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := + indicatorConstLp 2 i.measurableSet_interval i.restrict_interval_ne_top (1 : ℝ) + +/-- The Wiener increment `B(hi) - B(lo)` as an element of `Lp ℝ 2 μ`. -/ +noncomputable def wienerIncrementLp (B : ℝ≥0 → Ω → ℝ) + (hB : IsPreBrownianReal B μ) {T : ℝ≥0} (i : StepIndex T) : Lp ℝ 2 μ := + (memLp_increment hB i.1.1 i.1.2).toLp _ + +variable [IsProbabilityMeasure μ] + +/-! ### Assembly maps on finitely supported coefficients -/ + +/-- Linear map from finitely supported coefficients to step functions. -/ +noncomputable def stepAssembly (T : ℝ≥0) : + (StepIndex T →₀ ℝ) →ₗ[ℝ] Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := + Finsupp.linearCombination ℝ (stepIndicatorLp T) + +/-- Linear map from finitely supported coefficients to Wiener increments. -/ +noncomputable def wienerAssembly (B : ℝ≥0 → Ω → ℝ) + (hB : IsPreBrownianReal B μ) (T : ℝ≥0) : + (StepIndex T →₀ ℝ) →ₗ[ℝ] Lp ℝ 2 μ := + Finsupp.linearCombination ℝ (wienerIncrementLp B hB (T := T)) + +/-! ### Covariance identity for BM increments + +For `s ≤ t, u ≤ v ∈ ℝ≥0`, +`E[(B_t - B_s)(B_v - B_u)] = vol((s, t] ∩ (u, v])`. + +The right hand side is written as `max 0 (min t v - max s u)`. -/ + +/-- `∫ ω, B s ω * B t ω ∂μ = min s t` for pre-Brownian motion `B` with zero start, +using `IsPreBrownianReal.covariance_eval` and `covariance_eq_sub` (the means are zero). -/ +lemma integral_mul_eval (hB : IsPreBrownianReal B μ) (s t : ℝ≥0) : + ∫ ω, B s ω * B t ω ∂μ = ((min s t : ℝ≥0) : ℝ) := by + have hBs : MemLp (B s) 2 μ := (hB.isGaussianProcess.hasGaussianLaw_eval s).memLp_two + have hBt : MemLp (B t) 2 μ := (hB.isGaussianProcess.hasGaussianLaw_eval t).memLp_two + have h_cov := hB.covariance_eval s t + rw [covariance_eq_sub hBs hBt] at h_cov + have hEs : ∫ ω, B s ω ∂μ = 0 := hB.integral_eval s + have hEt : ∫ ω, B t ω ∂μ = 0 := hB.integral_eval t + rw [hEs, hEt, zero_mul, sub_zero] at h_cov + exact h_cov + +/-- Endpoint arithmetic for the covariance of two ordered Brownian increments. -/ +lemma min_sub_min_sub_min_add_min_eq_max_zero + (s t u v : ℝ≥0) (hst : s ≤ t) (huv : u ≤ v) : + ((min t v : ℝ≥0) : ℝ) - ((min t u : ℝ≥0) : ℝ) - + ((min s v : ℝ≥0) : ℝ) + ((min s u : ℝ≥0) : ℝ) = + max 0 ((min (t : ℝ) v) - (max (s : ℝ) u)) := by + have hst : (s : ℝ) ≤ t := mod_cast hst + have huv : (u : ℝ) ≤ v := mod_cast huv + push_cast + simp only [min_def, max_def] + split_ifs <;> linarith + +/-- Covariance identity for BM increments: +`E[(B_t - B_s)(B_v - B_u)] = vol((s, t] ∩ (u, v])`, +expressed via `max 0 (min t v - max s u)`. -/ +lemma covariance_increment_aux (hB : IsPreBrownianReal B μ) + (s t u v : ℝ≥0) (hst : s ≤ t) (huv : u ≤ v) : + ∫ ω, (B t ω - B s ω) * (B v ω - B u ω) ∂μ = + max 0 ((min (t : ℝ) v) - (max (s : ℝ) u)) := by + have hBs : MemLp (B s) 2 μ := (hB.isGaussianProcess.hasGaussianLaw_eval s).memLp_two + have hBt : MemLp (B t) 2 μ := (hB.isGaussianProcess.hasGaussianLaw_eval t).memLp_two + have hBu : MemLp (B u) 2 μ := (hB.isGaussianProcess.hasGaussianLaw_eval u).memLp_two + have hBv : MemLp (B v) 2 μ := (hB.isGaussianProcess.hasGaussianLaw_eval v).memLp_two + have hInt_tv : Integrable (fun ω ↦ B t ω * B v ω) μ := + MemLp.integrable_mul hBt hBv + have hInt_tu : Integrable (fun ω ↦ B t ω * B u ω) μ := + MemLp.integrable_mul hBt hBu + have hInt_sv : Integrable (fun ω ↦ B s ω * B v ω) μ := + MemLp.integrable_mul hBs hBv + have hInt_su : Integrable (fun ω ↦ B s ω * B u ω) μ := + MemLp.integrable_mul hBs hBu + have h_eq_fun : + (fun ω ↦ (B t ω - B s ω) * (B v ω - B u ω)) = + (fun ω ↦ B t ω * B v ω - B t ω * B u ω - B s ω * B v ω + B s ω * B u ω) := by + funext ω + ring + have e1 : ∫ ω, B t ω * B v ω - B t ω * B u ω ∂μ = + (∫ ω, B t ω * B v ω ∂μ) - (∫ ω, B t ω * B u ω ∂μ) := + integral_sub hInt_tv hInt_tu + have e2 : ∫ ω, B t ω * B v ω - B t ω * B u ω - B s ω * B v ω ∂μ = + (∫ ω, B t ω * B v ω - B t ω * B u ω ∂μ) - (∫ ω, B s ω * B v ω ∂μ) := + integral_sub (hInt_tv.sub hInt_tu) hInt_sv + have e3 : + ∫ ω, B t ω * B v ω - B t ω * B u ω - B s ω * B v ω + B s ω * B u ω ∂μ = + (∫ ω, B t ω * B v ω - B t ω * B u ω - B s ω * B v ω ∂μ) + + (∫ ω, B s ω * B u ω ∂μ) := + integral_add ((hInt_tv.sub hInt_tu).sub hInt_sv) hInt_su + have h_lhs : + ∫ ω, (B t ω - B s ω) * (B v ω - B u ω) ∂μ = + (∫ ω, B t ω * B v ω ∂μ) - (∫ ω, B t ω * B u ω ∂μ) - + (∫ ω, B s ω * B v ω ∂μ) + (∫ ω, B s ω * B u ω ∂μ) := by + rw [h_eq_fun] + linarith [e1, e2, e3] + rw [h_lhs, integral_mul_eval hB t v, integral_mul_eval hB t u, + integral_mul_eval hB s v, integral_mul_eval hB s u] + exact min_sub_min_sub_min_add_min_eq_max_zero s t u v hst huv + +/-! ### The key isometry on finitely supported coefficients -/ + +/-- The core pairing identity: for two step indices `i j ∈ StepIndex T`, +the inner product of the Wiener increments equals the inner product of the +step indicators in `Lp ℝ 2 (volume.restrict (Set.Ioc 0 T))`. -/ +private lemma inner_wienerIncrementLp_eq (hB : IsPreBrownianReal B μ) + {T : ℝ≥0} (i j : StepIndex T) : + ⟪wienerIncrementLp B hB i, wienerIncrementLp B hB j⟫_ℝ = + ⟪stepIndicatorLp T i, stepIndicatorLp T j⟫_ℝ := by + -- LHS: L2.inner_def reduces ⟪·, ·⟫ to ∫ ⟪f, g⟫_ℝ ∂μ; for real values + -- ⟪x, y⟫_ℝ = y * x (Mathlib star-product convention), so we commute via ring. + have hLHS : ⟪wienerIncrementLp B hB i, wienerIncrementLp B hB j⟫_ℝ = + max 0 ((min (i.hi : ℝ) j.hi) - (max (i.lo : ℝ) j.lo)) := by + rw [L2.inner_def] + have h_eq : ∀ᵐ ω ∂μ, + (⟪(wienerIncrementLp B hB i : Ω → ℝ) ω, + (wienerIncrementLp B hB j : Ω → ℝ) ω⟫_ℝ : ℝ) = + (B i.1.2 ω - B i.1.1 ω) * (B j.1.2 ω - B j.1.1 ω) := by + filter_upwards [MemLp.coeFn_toLp (memLp_increment hB i.1.1 i.1.2), + MemLp.coeFn_toLp (memLp_increment hB j.1.1 j.1.2)] + with ω hωI hωJ + rw [show (wienerIncrementLp B hB i : Ω → ℝ) ω = B i.1.2 ω - B i.1.1 ω from hωI, + show (wienerIncrementLp B hB j : Ω → ℝ) ω = B j.1.2 ω - B j.1.1 ω from hωJ] + change (B j.1.2 ω - B j.1.1 ω) * (B i.1.2 ω - B i.1.1 ω) = _ + ring + rw [integral_congr_ae h_eq] + exact covariance_increment_aux hB i.1.1 i.1.2 j.1.1 j.1.2 i.2.1 j.2.1 + -- RHS: indicator inner product = volume of intersection = max 0 (min hi - max lo). + have hRHS : ⟪stepIndicatorLp T i, stepIndicatorLp T j⟫_ℝ = + max 0 ((min (i.hi : ℝ) j.hi) - (max (i.lo : ℝ) j.lo)) := by + rw [stepIndicatorLp, stepIndicatorLp, + MeasureTheory.L2.real_inner_indicatorConstLp_one_indicatorConstLp_one + i.measurableSet_interval j.measurableSet_interval + i.restrict_interval_ne_top j.restrict_interval_ne_top] + have h_inter : i.interval ∩ j.interval = + Set.Ioc (max (i.lo : ℝ) j.lo) (min (i.hi : ℝ) j.hi) := by + simp [StepIndex.interval, Set.Ioc_inter_Ioc] + have h_sub : + Set.Ioc (max (i.lo : ℝ) j.lo) (min (i.hi : ℝ) j.hi) ⊆ Set.Ioc (0 : ℝ) (T : ℝ) := by + rw [← h_inter] + exact fun x hx ↦ i.interval_subset_Ioc_zero_T hx.1 + rw [Measure.real_def, + Measure.restrict_apply (i.measurableSet_interval.inter j.measurableSet_interval), + h_inter, Set.inter_eq_left.mpr h_sub, Real.volume_Ioc, + ENNReal.toReal_ofReal', max_comm] + rw [hLHS, hRHS] + +theorem wiener_assembly_isometry (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (f : StepIndex T →₀ ℝ) : + ‖wienerAssembly B hB T f‖ = ‖stepAssembly T f‖ := by + -- Squares of both norms equal a common double-sum over `f.support × f.support`. + have h_sq : ‖wienerAssembly B hB T f‖ ^ 2 = ‖stepAssembly T f‖ ^ 2 := by + rw [← @real_inner_self_eq_norm_sq _ _ _ (wienerAssembly B hB T f), + ← @real_inner_self_eq_norm_sq _ _ _ (stepAssembly T f)] + simp only [wienerAssembly, stepAssembly, Finsupp.linearCombination_apply] + rw [Finsupp.sum_inner, Finsupp.sum_inner] + refine Finsupp.sum_congr (fun i _ ↦ ?_) + rw [Finsupp.inner_sum, Finsupp.inner_sum] + refine Finsupp.sum_congr (fun j _ ↦ ?_) + rw [real_inner_smul_left, real_inner_smul_right, + real_inner_smul_left, real_inner_smul_right, + inner_wienerIncrementLp_eq hB i j] + exact (sq_eq_sq₀ (norm_nonneg _) (norm_nonneg _)).mp h_sq + +/-! ### Density of step indicators in `Lp ℝ 2 (volume.restrict (Ioc 0 T))` + +Orthogonal-complement route: take `g` orthogonal to every step indicator; +deduce `∫ x in Ioc a b, g x ∂ν = 0` for every `a ≤ b` (truncating endpoints to +`[0, T]` reduces to the orthogonality hypothesis); extend by π-system induction +(`{Ioc a b | a ≤ b}` is a π-system generating `Borel ℝ`) to all measurable sets; +apply `Lp.ae_eq_zero_of_forall_setIntegral_eq_zero` to conclude `g = 0`. Hence +the orthogonal complement is `⊥`, so the closure of the range is `⊤`. -/ + +/-- For `g : Lp ℝ 2 (volume.restrict (Ioc 0 T))` orthogonal to every step +indicator, the set-integral of `g` over any half-open interval `Ioc a b` +(arbitrary `a ≤ b ∈ ℝ`) vanishes. -/ +private lemma setIntegral_Ioc_eq_zero_of_orthogonal {T : ℝ≥0} + (g : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ)))) + (h_orth : ∀ i : StepIndex T, ⟪stepIndicatorLp T i, g⟫_ℝ = 0) + (a b : ℝ) : + ∫ x in Set.Ioc a b, g x ∂(volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) = 0 := by + -- Push the restrict through: `∫ x in s, g x ∂(volume.restrict S) = ∫ x in s ∩ S, g x ∂volume`. + rw [show (∫ x in Set.Ioc a b, (g : ℝ → ℝ) x ∂(volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ)))) + = ∫ x in Set.Ioc (max a 0) (min b (T : ℝ)), (g : ℝ → ℝ) x ∂volume by + show ∫ x, _ ∂((volume.restrict _).restrict _) = ∫ x, _ ∂(volume.restrict _) + rw [Measure.restrict_restrict measurableSet_Ioc, Set.Ioc_inter_Ioc]] + by_cases hab' : max a 0 ≤ min b (T : ℝ) + · -- Build a StepIndex matching `(max a 0, min b T]` and apply orthogonality. + have ha'_nn : (0 : ℝ) ≤ max a 0 := le_max_right _ _ + have hb'_T : min b (T : ℝ) ≤ (T : ℝ) := min_le_right _ _ + have hb'_nn : (0 : ℝ) ≤ min b (T : ℝ) := le_trans ha'_nn hab' + let i : StepIndex T := + ⟨(⟨max a 0, ha'_nn⟩, ⟨min b (T : ℝ), hb'_nn⟩), hab', by exact_mod_cast hb'_T⟩ + -- The orthogonal inner product evaluates to `∫ x in (max a 0, min b T], g x ∂volume`: + -- after `inner_indicatorConstLp_one` it's `∫ in i.interval over ν`, and since + -- `i.interval ⊆ Ioc 0 T`, the restrict collapses. + have h_inner_to_int : + ⟪stepIndicatorLp T i, g⟫_ℝ = + ∫ x in Set.Ioc (max a 0) (min b (T : ℝ)), g x ∂volume := by + have h_indicator_inner : + ⟪stepIndicatorLp T i, g⟫_ℝ = + ∫ x in i.interval, g x ∂(volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := by + rw [stepIndicatorLp] + exact MeasureTheory.L2.inner_indicatorConstLp_one (𝕜 := ℝ) + i.measurableSet_interval i.restrict_interval_ne_top g + rw [h_indicator_inner] + change ∫ x, _ ∂((volume.restrict _).restrict i.interval) = _ + rw [Measure.restrict_restrict i.measurableSet_interval] + change ∫ x in i.interval ∩ Set.Ioc (0 : ℝ) (T : ℝ), g x ∂volume = _ + rw [show i.interval ∩ Set.Ioc (0 : ℝ) (T : ℝ) = Set.Ioc (max a 0) (min b (T : ℝ)) by + change Set.Ioc (max a 0) (min b (T : ℝ)) ∩ Set.Ioc (0 : ℝ) (T : ℝ) = _ + rw [Set.Ioc_inter_Ioc, max_eq_left ha'_nn, min_eq_left hb'_T]] + rw [← h_inner_to_int] + exact h_orth i + · push Not at hab' + rw [Set.Ioc_eq_empty (lt_asymm hab'), setIntegral_empty] + +/-- For `g : Lp ℝ 2 (volume.restrict (Ioc 0 T))` orthogonal to every step +indicator, the set-integral of `g` over any measurable set vanishes. +Proved by π-system induction (`borel_eq_generateFrom_Ioc_le`) over the base +case `setIntegral_Ioc_eq_zero_of_orthogonal`. -/ +private lemma setIntegral_eq_zero_of_orthogonal {T : ℝ≥0} + (g : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ)))) + (h_orth : ∀ i : StepIndex T, ⟪stepIndicatorLp T i, g⟫_ℝ = 0) + (s : Set ℝ) (hs : MeasurableSet s) : + ∫ x in s, g x ∂(volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) = 0 := by + -- ν is a finite measure (volume of (0, T] = T < ∞). + have : IsFiniteMeasure (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := by + refine ⟨?_⟩ + rw [Measure.restrict_apply MeasurableSet.univ, Set.univ_inter, Real.volume_Ioc] + exact ENNReal.ofReal_lt_top + have hg_int : Integrable g (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := + (Lp.memLp g).integrable (by norm_num : (1 : ℝ≥0∞) ≤ 2) + -- Apply π-system induction over `Borel ℝ = generateFrom {Ioc a b | a ≤ b}`. + refine MeasurableSpace.induction_on_inter (C := fun s _ ↦ + ∫ x in s, g x ∂(volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) = 0) + (h_eq := borel_eq_generateFrom_Ioc_le ℝ) (h_inter := ?_) + (empty := ?_) (basic := ?_) (compl := ?_) (iUnion := ?_) s hs + · -- π-system: intersection of two `Ioc a b` (nonempty) is again such. + rintro u ⟨a₁, b₁, _, rfl⟩ v ⟨a₂, b₂, _, rfl⟩ huv + rw [Set.Ioc_inter_Ioc] at huv + exact ⟨max a₁ a₂, min b₁ b₂, (Set.nonempty_Ioc.mp huv).le, (Set.Ioc_inter_Ioc ..).symm⟩ + · exact setIntegral_empty + · -- Base case `Ioc a b`. + rintro _ ⟨a, b, _, rfl⟩ + exact setIntegral_Ioc_eq_zero_of_orthogonal g h_orth a b + · -- Complement: ∫ univ = 0 (by base case `a = 0, b = T`), so ∫ tᶜ = -∫ t = 0. + intro t ht hPt + have h_full : + ∫ x, g x ∂(volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) = 0 := by + have h_ioc := setIntegral_Ioc_eq_zero_of_orthogonal g h_orth 0 (T : ℝ) + rwa [show (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))).restrict + (Set.Ioc (0 : ℝ) (T : ℝ)) = volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ)) by + rw [Measure.restrict_restrict measurableSet_Ioc, Set.inter_self]] at h_ioc + linarith [integral_add_compl ht hg_int, hPt, h_full] + · -- Disjoint union: countable additivity. + intro f hf hf_meas hf_zero + rw [integral_iUnion hf_meas hf hg_int.integrableOn] + simp [hf_zero] + +/-- The map `stepAssembly T` has dense range in +`Lp ℝ 2 (volume.restrict (Set.Ioc 0 T))`. The proof identifies the orthogonal +complement with `⊥` using `setIntegral_eq_zero_of_orthogonal` and +`Lp.ae_eq_zero_of_forall_setIntegral_eq_zero`. -/ +theorem stepAssembly_denseRange (T : ℝ≥0) : + DenseRange (stepAssembly T) := by + have : IsFiniteMeasure (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) := + ⟨by rw [Measure.restrict_apply MeasurableSet.univ, Set.univ_inter, Real.volume_Ioc]; + exact ENNReal.ofReal_lt_top⟩ + -- Suffices: `(LinearMap.range (stepAssembly T))ᗮ = ⊥` (every `g` orthogonal to range is 0). + suffices h_orth_eq_bot : (LinearMap.range (stepAssembly T))ᗮ = ⊥ by + rw [denseRange_iff_closure_range, ← LinearMap.coe_range (stepAssembly T), + ← Submodule.topologicalClosure_coe, + Submodule.topologicalClosure_eq_top_iff.mpr h_orth_eq_bot, Submodule.top_coe] + rw [Submodule.eq_bot_iff] + intro g h_mem + rw [Submodule.mem_orthogonal] at h_mem + have h_orth : ∀ i : StepIndex T, ⟪stepIndicatorLp T i, g⟫_ℝ = 0 := fun i ↦ + h_mem _ ⟨Finsupp.single i 1, by simp [stepAssembly, Finsupp.linearCombination_single]⟩ + exact (Lp.eq_zero_iff_ae_eq_zero (f := g)).mpr <| + Lp.ae_eq_zero_of_forall_setIntegral_eq_zero g (by norm_num) (by simp) + (fun _ _ _ ↦ ((Lp.memLp g).integrable one_le_two).integrableOn) + (fun s hs _ ↦ setIntegral_eq_zero_of_orthogonal g h_orth s hs) + +/-- The Wiener integral as a continuous linear isometry +`Lp ℝ 2 (volume.restrict (Set.Ioc 0 T)) →L[ℝ] Lp ℝ 2 μ`. -/ +noncomputable def wienerIntegralLp (B : ℝ≥0 → Ω → ℝ) + (hB : IsPreBrownianReal B μ) (T : ℝ≥0) : + Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ))) →L[ℝ] Lp ℝ 2 μ := + (wienerAssembly B hB T).extendOfNorm (stepAssembly T) + +/-- Itô isometry, norm form. For every `f ∈ L²([0, T])`, +`‖wienerIntegralLp f‖ = ‖f‖`. -/ +theorem wienerIntegralLp_norm (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (f : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ)))) : + ‖wienerIntegralLp B hB T f‖ = ‖f‖ := by + rw [wienerIntegralLp] + exact LinearMap.norm_extendOfNorm_eq_of_isometry + (stepAssembly_denseRange T) (wiener_assembly_isometry hB T) f + +/-- Itô isometry, integral form. For every `f ∈ L²([0, T])`, +`∫ ω, (wienerIntegralLp f ω)² ∂μ = ∫ s in (0, T], (f s)² ∂volume`. -/ +theorem wienerIntegralLp_integral_sq (hB : IsPreBrownianReal B μ) (T : ℝ≥0) + (f : Lp ℝ 2 (volume.restrict (Set.Ioc (0 : ℝ) (T : ℝ)))) : + ∫ ω, (wienerIntegralLp B hB T f ω) ^ 2 ∂μ = + ∫ s in Set.Ioc (0 : ℝ) (T : ℝ), (f s) ^ 2 ∂volume := by + rw [← lp_two_norm_sq (wienerIntegralLp B hB T f), + wienerIntegralLp_norm hB T f, + lp_two_norm_sq f] + +end WienerIntegralL2 +end MathFin diff --git a/LeanPool/MathFin/Probability/Dependence/Copula.lean b/LeanPool/MathFin/Probability/Dependence/Copula.lean new file mode 100644 index 0000000000..4a17096e07 --- /dev/null +++ b/LeanPool/MathFin/Probability/Dependence/Copula.lean @@ -0,0 +1,341 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Laws.Quantile + +/-! +# Copulas + +A **copula** on `ℝ^ι` is a probability measure whose coordinates are all uniformly distributed on +`(0, 1)` (`IsCopula`). Its distribution function `u ↦ C.real (Iic u)` is what McNeil, Frey and +Embrechts (*Quantitative Risk Management*, 2015, Definition 7.1) call a copula. We take the +measure-first definition: grounding, uniform margins and `d`-increasingness of the distribution +function are then theorems about a measure rather than axioms on a function. + +The central fact about copulas is Sklar's theorem (`Probability/Dependence/Sklar.lean`). This file +covers the structure every copula shares. + +* **Fréchet–Hoeffding bounds.** On `[0, 1]^ι` every copula satisfies + `max (∑ uᵢ − (d − 1)) 0 ≤ C(u) ≤ minᵢ uᵢ` (`IsCopula.sum_sub_le_measureReal_Iic`, + `IsCopula.measureReal_Iic_le`). The upper bound is monotonicity of measure and the lower bound + is the union bound on the complement. +* **The three fundamental copulas.** These are the independence copula `Π` (a product of uniform + laws, `C(u) = ∏ uᵢ`), the comonotonicity copula `M` (the law of `(U, …, U)`, `C(u) = min uᵢ`), + and in dimension two the countermonotonicity copula `W` (the law of `(U, 1 − U)`, + `C(u) = max (u₀ + u₁ − 1) 0`). `M` attains the upper bound in every dimension and `W` attains + the lower bound in dimension two. +* **The lower bound is not attained for `d ≥ 3`.** No copula has distribution function + `max (∑ uᵢ − (d − 1)) 0` (`not_exists_isCopula_frechetLower`, QRM Exercise Book, Exercise 7.3). + The events `{Uᵢ ≤ 1/2}` for three coordinates would be pairwise null while each carries mass + `1/2`, for a total of `3/2 > 1`. +* **Distribution functions determine laws on `ℝ^ι`.** Two probability measures on `ℝ^ι` that agree + on every lower orthant `Iic u` are equal (`ext_of_measure_Iic_pi`). This is the + multidimensional version of `MeasureTheory.Measure.ext_of_Iic`, and it is what makes a copula + unique in Sklar's theorem. + +## Main definitions + +* `IsCopula`: a probability measure on `ι → ℝ` whose every coordinate is uniform on `(0, 1)`. +* `independenceCopula`: the law `Π` of a vector of independent uniforms. +* `comonotoneCopula`: the law `M` of `(U, …, U)` for a single uniform `U`. +* `countermonotoneCopula`: the law `W` of `(U, 1 − U)`, in dimension two. + +## Main results + +* `IsCopula.measureReal_coord_le`: each coordinate is uniform, `C(vᵢ ≤ t) = t` on `[0, 1]`. +* `IsCopula.ae_mem_Ioo`: almost every point of a copula lies in the open cube `(0, 1)^ι`. +* `IsCopula.measureReal_Iic_le`, `IsCopula.sum_sub_le_measureReal_Iic`: the Fréchet–Hoeffding + bounds (McNeil, Frey and Embrechts, 2015, Theorem 7.8). +* `ext_of_measure_Iic_pi`: joint distribution functions determine probability laws on `ℝ^ι`. +* `not_exists_isCopula_frechetLower`: for `d ≥ 3` the lower Fréchet bound is not a copula. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], revised edition (2015), §7.1.1, Theorem 7.8. +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 7.3 + +## Tags + +Fréchet–Hoeffding bounds, comonotonicity, countermonotonicity, independence copula, +dependence modelling, MSC 62H05, MSC 91G70, JEL C02 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set + +/-! ### The uniform law on `(0, 1)` -/ + +/-- The uniform law on `(0, 1)` gives `(-∞, t]` mass `t` for `t ∈ [0, 1]`. -/ +lemma uniformIoo_real_Iic {t : ℝ} (h0 : 0 ≤ t) (h1 : t ≤ 1) : + (volume.restrict (Ioo (0 : ℝ) 1)).real (Iic t) = t := by + rw [measureReal_def, uniformIoo_Iic h0 h1, ENNReal.toReal_ofReal h0] + +/-- The uniform law on `(0, 1)` gives `(1, ∞)` no mass. -/ +lemma uniformIoo_Ioi_one : volume.restrict (Ioo (0 : ℝ) 1) (Ioi 1) = 0 := by + rw [Measure.restrict_apply measurableSet_Ioi, + show Ioi (1 : ℝ) ∩ Ioo 0 1 = ∅ from eq_empty_of_forall_notMem fun _ h ↦ h.2.2.not_gt h.1, + measure_empty] + +/-! ### Copulas -/ + +/-- A **copula** on `ℝ^ι`: a probability measure whose every coordinate is uniformly distributed on +`(0, 1)`. Its distribution function `u ↦ C.real (Iic u)` is a copula in the sense of +McNeil–Frey–Embrechts, Definition 7.1. -/ +structure IsCopula {ι : Type*} (C : Measure (ι → ℝ)) : Prop where + /-- A copula is a probability measure. -/ + isProbabilityMeasure : IsProbabilityMeasure C + /-- Every coordinate of a copula is uniform on `(0, 1)`. -/ + map_eval (i : ι) : C.map (fun v ↦ v i) = volume.restrict (Ioo 0 1) + +namespace IsCopula + +variable {ι : Type*} {C : Measure (ι → ℝ)} + +/-- Under a copula, each coordinate has the uniform law on `(0, 1)`. -/ +lemma hasLaw_eval (hC : IsCopula C) (i : ι) : + HasLaw (fun v : ι → ℝ ↦ v i) (volume.restrict (Ioo 0 1)) C := + ⟨(measurable_pi_apply i).aemeasurable, hC.map_eval i⟩ + +/-- The mass a copula gives to a condition on one coordinate is its uniform probability. -/ +lemma measure_coord_preimage (hC : IsCopula C) (i : ι) {s : Set ℝ} (hs : MeasurableSet s) : + C {v | v i ∈ s} = volume.restrict (Ioo 0 1) s := by + rw [← hC.map_eval i, Measure.map_apply (measurable_pi_apply i) hs] + rfl + +/-- **Uniform margins**: `C(vᵢ ≤ t) = t` for `t ∈ [0, 1]`. -/ +lemma measureReal_coord_le (hC : IsCopula C) (i : ι) {t : ℝ} (h0 : 0 ≤ t) (h1 : t ≤ 1) : + C.real {v | v i ≤ t} = t := by + rw [measureReal_def, show {v : ι → ℝ | v i ≤ t} = {v | v i ∈ Iic t} from rfl, + hC.measure_coord_preimage i measurableSet_Iic, ← measureReal_def, uniformIoo_real_Iic h0 h1] + +/-- Almost every point of a copula lies in the open cube `(0, 1)^ι`. -/ +lemma ae_mem_Ioo [Countable ι] (hC : IsCopula C) : ∀ᵐ v ∂C, ∀ i, v i ∈ Ioo 0 1 := by + refine ae_all_iff.2 fun i ↦ ?_ + have hmeas : MeasurableSet (Ioo (0 : ℝ) 1)ᶜ := measurableSet_Ioo.compl + have h := hC.measure_coord_preimage i hmeas + rw [Measure.restrict_apply hmeas, compl_inter_self, measure_empty] at h + filter_upwards [measure_eq_zero_iff_ae_notMem.1 h] with v hv + simpa using hv + +/-- **Upper Fréchet–Hoeffding bound**: `C(u) ≤ uᵢ` for every coordinate with `uᵢ ∈ [0, 1]`, +i.e. `C(u) ≤ minᵢ uᵢ`. -/ +theorem measureReal_Iic_le (hC : IsCopula C) (u : ι → ℝ) (i : ι) (hi : u i ∈ Icc 0 1) : + C.real (Iic u) ≤ u i := by + have := hC.isProbabilityMeasure + calc C.real (Iic u) ≤ C.real {v | v i ≤ u i} := measureReal_mono fun v hv ↦ hv i + _ = u i := hC.measureReal_coord_le i hi.1 hi.2 + +/-- **Lower Fréchet–Hoeffding bound**: `∑ uᵢ − (d − 1) ≤ C(u)` on `[0, 1]^ι`, the union bound on +the complement of the orthant. -/ +theorem sum_sub_le_measureReal_Iic [Fintype ι] (hC : IsCopula C) (u : ι → ℝ) + (hu : ∀ i, u i ∈ Icc 0 1) : ∑ i, u i - (Fintype.card ι - 1) ≤ C.real (Iic u) := by + have := hC.isProbabilityMeasure + have hcompl : (Iic u)ᶜ = ⋃ i, {v : ι → ℝ | u i < v i} := by + ext v + simp [Pi.le_def] + have hcoord (i : ι) : C.real {v : ι → ℝ | u i < v i} = 1 - u i := by + rw [show {v : ι → ℝ | u i < v i} = {v | v i ≤ u i}ᶜ by ext v; simp, + probReal_compl_eq_one_sub (measurableSet_le (measurable_pi_apply i) measurable_const), + hC.measureReal_coord_le i (hu i).1 (hu i).2] + have hunion := measureReal_iUnion_fintype_le (μ := C) fun i ↦ {v : ι → ℝ | u i < v i} + rw [← hcompl, probReal_compl_eq_one_sub measurableSet_Iic] at hunion + simp only [hcoord, Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, + mul_one] at hunion + linarith + +end IsCopula + +/-! ### Joint distribution functions determine laws on `ℝ^ι` -/ + +/-- The lower half-lines are a countable spanning family of `ℝ`. -/ +lemma isCountablySpanning_range_Iic : IsCountablySpanning (range (Iic : ℝ → Set ℝ)) := + ⟨fun n : ℕ ↦ Iic (n : ℝ), fun _ ↦ mem_range_self _, + iUnion_eq_univ_iff.2 fun x ↦ ⟨⌈x⌉₊, Nat.le_ceil x⟩⟩ + +/-- **Joint distribution functions determine probability laws on `ℝ^ι`**: two probability measures +that agree on every lower orthant `Iic u` are equal. The orthants are the boxes built from the +π-system of half-lines, which generates the product σ-algebra. -/ +theorem ext_of_measure_Iic_pi {ι : Type*} [Finite ι] {μ ν : Measure (ι → ℝ)} + [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] (h : ∀ u, μ (Iic u) = ν (Iic u)) : + μ = ν := by + refine ext_of_generate_finite (pi univ '' pi univ fun _ ↦ range Iic) + (generateFrom_eq_pi (fun _ ↦ (borel_eq_generateFrom_Iic ℝ).symm.trans + BorelSpace.measurable_eq.symm) fun _ ↦ isCountablySpanning_range_Iic).symm + (IsPiSystem.pi fun _ ↦ isPiSystem_Iic) ?_ (by simp) + rintro _ ⟨s, hs, rfl⟩ + choose u hu using fun i ↦ hs i (mem_univ i) + rw [show pi univ s = Iic u by rw [← funext hu, pi_univ_Iic]] + exact h u + +/-! ### The independence, comonotonicity and countermonotonicity copulas -/ + +section Fundamental + +variable (ι : Type*) [Fintype ι] + +/-- The **independence copula** `Π`: the law of a vector of independent uniforms. -/ +noncomputable def independenceCopula : Measure (ι → ℝ) := + Measure.pi fun _ ↦ volume.restrict (Ioo 0 1) + +/-- The **comonotonicity copula** `M`: the law of `(U, …, U)` for a single uniform `U`. -/ +noncomputable def comonotoneCopula : Measure (ι → ℝ) := + (volume.restrict (Ioo (0 : ℝ) 1)).map fun t _ ↦ t + +variable {ι} + +/-- `Π` is a copula. -/ +theorem isCopula_independenceCopula : IsCopula (independenceCopula ι) := + ⟨inferInstanceAs (IsProbabilityMeasure (Measure.pi _)), + fun i ↦ (measurePreserving_eval _ i).map_eq⟩ + +/-- `Π(u) = ∏ uᵢ` on `[0, 1]^ι`. -/ +theorem independenceCopula_real_Iic (u : ι → ℝ) (hu : ∀ i, u i ∈ Icc 0 1) : + (independenceCopula ι).real (Iic u) = ∏ i, u i := by + rw [independenceCopula, ← pi_univ_Iic, measureReal_def, Measure.pi_pi, ENNReal.toReal_prod] + exact Finset.prod_congr rfl fun i _ ↦ uniformIoo_real_Iic (hu i).1 (hu i).2 + +omit [Fintype ι] in +/-- `M` is a copula. -/ +theorem isCopula_comonotoneCopula : IsCopula (comonotoneCopula ι) where + isProbabilityMeasure := + inferInstanceAs (IsProbabilityMeasure ((volume.restrict (Ioo (0 : ℝ) 1)).map fun t _ ↦ t)) + map_eval i := by + rw [comonotoneCopula, Measure.map_map (measurable_pi_apply i) (by fun_prop)] + exact Measure.map_id + +/-- `M(u) = minᵢ uᵢ` on `[0, 1]^ι`: the comonotonicity copula attains the upper Fréchet–Hoeffding +bound. -/ +theorem comonotoneCopula_real_Iic [Nonempty ι] (u : ι → ℝ) (hu : ∀ i, u i ∈ Icc 0 1) : + (comonotoneCopula ι).real (Iic u) = Finset.univ.inf' Finset.univ_nonempty u := by + obtain ⟨i, -, hi⟩ := Finset.exists_mem_eq_inf' Finset.univ_nonempty u + rw [comonotoneCopula, map_measureReal_apply (by fun_prop) measurableSet_Iic, + show (fun t _ ↦ t) ⁻¹' Iic u = Iic (Finset.univ.inf' Finset.univ_nonempty u) by + ext t; simp [Pi.le_def], hi] + exact uniformIoo_real_Iic (hu i).1 (hu i).2 + +/-- The **countermonotonicity copula** `W` in dimension two: the law of `(U, 1 − U)`. -/ +noncomputable def countermonotoneCopula : Measure (Fin 2 → ℝ) := + (volume.restrict (Ioo (0 : ℝ) 1)).map fun t ↦ ![t, 1 - t] + +/-- The reflection `t ↦ 1 − t` preserves the uniform law on `(0, 1)`. -/ +lemma map_one_sub_uniformIoo : + (volume.restrict (Ioo (0 : ℝ) 1)).map (fun t ↦ 1 - t) = volume.restrict (Ioo 0 1) := by + have h := (volume.measurePreserving_sub_left (1 : ℝ)).restrict_preimage + (measurableSet_Ioo (a := (0 : ℝ)) (b := 1)) + rw [show (fun t : ℝ ↦ 1 - t) ⁻¹' Ioo 0 1 = Ioo 0 1 by + ext t; simp only [mem_preimage, mem_Ioo]; constructor <;> intro h <;> constructor <;> linarith + [h.1, h.2]] at h + exact h.map_eq + +/-- `W` is a copula. -/ +theorem isCopula_countermonotoneCopula : IsCopula countermonotoneCopula where + isProbabilityMeasure := + inferInstanceAs (IsProbabilityMeasure + ((volume.restrict (Ioo (0 : ℝ) 1)).map fun t ↦ ![t, 1 - t])) + map_eval i := by + rw [countermonotoneCopula, Measure.map_map (measurable_pi_apply i) (by fun_prop)] + fin_cases i + · exact Measure.map_id + · exact map_one_sub_uniformIoo + +/-- `W(u) = max (u₀ + u₁ − 1) 0` on `[0, 1]²`: in dimension two the countermonotonicity copula +attains the lower Fréchet–Hoeffding bound. -/ +theorem countermonotoneCopula_real_Iic (u : Fin 2 → ℝ) (hu : ∀ i, u i ∈ Icc 0 1) : + countermonotoneCopula.real (Iic u) = max (u 0 + u 1 - 1) 0 := by + rw [countermonotoneCopula, map_measureReal_apply (by fun_prop) measurableSet_Iic, + show (fun t ↦ ![t, 1 - t]) ⁻¹' Iic u = Icc (1 - u 1) (u 0) by + ext t + simp only [mem_preimage, mem_Iic, Pi.le_def, Fin.forall_fin_two, mem_Icc] + simp only [Matrix.cons_val_zero, Matrix.cons_val_one] + constructor <;> intro h <;> constructor <;> linarith [h.1, h.2], + measureReal_def, Measure.restrict_apply measurableSet_Icc] + have hsub : Icc (1 - u 1) (u 0) ∩ Ioo 0 1 ⊆ Icc (1 - u 1) (u 0) := inter_subset_left + have hsup : Ioo (1 - u 1) (u 0) ⊆ Icc (1 - u 1) (u 0) ∩ Ioo 0 1 := fun t ht ↦ + ⟨Ioo_subset_Icc_self ht, by linarith [ht.1, (hu 1).2], by linarith [ht.2, (hu 0).2]⟩ + rw [le_antisymm ((measure_mono hsub).trans_eq Real.volume_Icc) + ((Real.volume_Ioo.symm.trans_le (measure_mono hsup))), ENNReal.toReal_ofReal', + sub_sub_eq_add_sub] + +end Fundamental + +/-! ### The lower Fréchet–Hoeffding bound is not a copula in dimension `d ≥ 3` -/ + +/-- **The lower Fréchet–Hoeffding bound is not a copula for `d ≥ 3`** (QRM Exercise Book, +Exercise 7.3). No copula on `ℝ^ι` with `card ι ≥ 3` has distribution function +`max (∑ uᵢ − (d − 1)) 0` on `[0, 1]^ι`. + +Suppose one did. For two coordinates `a ≠ b`, the point with `uₐ = u_b = 1/2` and all other +entries `1` gives `max (d − 1 − (d − 1)) 0 = 0`. The coordinates of a copula are almost surely +below `1`, so `{Uₐ ≤ 1/2} ∩ {U_b ≤ 1/2}` is null. Three such events are then pairwise almost +disjoint and each has mass `1/2`, so their union would have mass `3/2 > 1`. -/ +theorem not_exists_isCopula_frechetLower {ι : Type*} [Fintype ι] + (hι : 3 ≤ Fintype.card ι) : + ¬ ∃ C : Measure (ι → ℝ), IsCopula C ∧ ∀ u : ι → ℝ, (∀ i, u i ∈ Icc 0 1) → + C.real (Iic u) = max (∑ i, u i - (Fintype.card ι - 1)) 0 := by + classical + rintro ⟨C, hC, hW⟩ + have := hC.isProbabilityMeasure + obtain ⟨e⟩ := + Function.Embedding.nonempty_of_card_le (by simpa using hι : Fintype.card (Fin 3) ≤ _) + set A : ι → Set (ι → ℝ) := fun a ↦ {v | v a ≤ 1 / 2} + have hA (a : ι) : C (A a) = ENNReal.ofReal (1 / 2) := by + rw [← ofReal_measureReal, hC.measureReal_coord_le a (by norm_num) (by norm_num)] + have hAmeas (a : ι) : MeasurableSet (A a) := + measurableSet_le (measurable_pi_apply a) measurable_const + -- coordinates exceed `1` only on a null set + have hbig : C {v : ι → ℝ | ∃ c, 1 < v c} = 0 := by + rw [measure_eq_zero_iff_ae_notMem] + filter_upwards [hC.ae_mem_Ioo] with v hv ⟨c, hc⟩ + exact lt_asymm (hv c).2 hc + -- two distinct coordinates are almost never both at most `1/2` + have hpair {a b : ι} (hab : a ≠ b) : AEDisjoint C (A a) (A b) := by + set u : ι → ℝ := fun c ↦ 1 - (if c = a then 1 / 2 else 0) - (if c = b then 1 / 2 else 0) + have hua : u a = 1 / 2 := by simp only [u, ite_eq_right hab]; norm_num + have hub : u b = 1 / 2 := by simp only [u, ite_eq_right hab.symm]; norm_num + have huc {c : ι} (hca : c ≠ a) (hcb : c ≠ b) : u c = 1 := by + simp only [u, ite_eq_right hca, ite_eq_right hcb]; norm_num + have hu : ∀ c, u c ∈ Icc 0 1 := fun c ↦ by + by_cases hca : c = a + · rw [hca, hua]; norm_num + by_cases hcb : c = b + · rw [hcb, hub]; norm_num + rw [huc hca hcb]; norm_num + have hsum : ∑ c, u c = Fintype.card ι - 1 := by + simp only [u, Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, + mul_one, Finset.sum_ite_eq', Finset.mem_univ, ite_true] + ring + have hIic : C (Iic u) = 0 := by + rw [← ofReal_measureReal, hW u hu, hsum, sub_self, max_self, ENNReal.ofReal_zero] + refine measure_mono_null (fun v hv ↦ ?_) (measure_union_null hIic hbig) + by_contra hnot + rw [mem_union, not_or] at hnot + refine hnot.1 fun c ↦ ?_ + by_cases hca : c = a + · rw [hca, hua]; exact hv.1 + by_cases hcb : c = b + · rw [hcb, hub]; exact hv.2 + rw [huc hca hcb] + exact not_lt.1 fun h ↦ hnot.2 ⟨c, h⟩ + have hne (i j : Fin 3) (hij : i ≠ j) : e i ≠ e j := e.injective.ne hij + have hunion : C (A (e 0) ∪ A (e 1) ∪ A (e 2)) = ENNReal.ofReal (3 / 2) := by + rw [measure_union₀ (hAmeas _).nullMeasurableSet + (((hpair (hne 0 2 (by decide))).union_left (hpair (hne 1 2 (by decide))))), + measure_union₀ (hAmeas _).nullMeasurableSet (hpair (hne 0 1 (by decide))), hA, hA, hA, + ← ENNReal.ofReal_add (by norm_num) (by norm_num), + ← ENNReal.ofReal_add (by norm_num) (by norm_num)] + norm_num + have hle := prob_le_one (μ := C) (s := A (e 0) ∪ A (e 1) ∪ A (e 2)) + rw [hunion, ENNReal.ofReal_le_one] at hle + norm_num at hle + +end MathFin diff --git a/LeanPool/MathFin/Probability/Dependence/CopulaFamilies.lean b/LeanPool/MathFin/Probability/Dependence/CopulaFamilies.lean new file mode 100644 index 0000000000..a05c303223 --- /dev/null +++ b/LeanPool/MathFin/Probability/Dependence/CopulaFamilies.lean @@ -0,0 +1,483 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Dependence.Copula +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.MeasureTheory.Integral.Pi + +/-! +# Copula families: Farlie–Gumbel–Morgenstern and Clayton + +Two parametric bivariate families from McNeil–Frey–Embrechts, *Quantitative Risk Management* +(2015), Chapter 7, and the QRM Exercise Book, Exercises 7.17 and 7.19. + +**Farlie–Gumbel–Morgenstern.** The FGM copula `fgmCopula θ` is the law on the unit square with +density `1 + θ(1 − 2u)(1 − 2v)` against the independence copula. For `|θ| ≤ 1` it is a copula +(`isCopula_fgmCopula`) with distribution function `uv + θ uv(1 − u)(1 − v)` +(`fgmCopula_real_Iic`). For `|θ| > 1` no copula has that distribution function, so +`|θ| ≤ 1` is exactly the admissible range (`exists_isCopula_fgm_iff`). A negative-mass rectangle +near a corner of the square rules out the other values. Its Spearman's rho is `θ/3` +(`spearmanRho_fgmCopula`), so the family only reaches rank correlations in `[−1/3, 1/3]`. This is +the drawback the exercise asks about: FGM can model only weak dependence. + +**Clayton.** The Clayton copula function `C_θ(u, v) = (u^{−θ} + v^{−θ} − 1)^{−1/θ}` is treated at +the level of the function. This file proves its coefficient of lower tail dependence, +`lim_{u → 0⁺} C_θ(u, u)/u = 2^{−1/θ}` (`tendsto_claytonCopulaFun_diag_div`), and its limits in the +parameter: the independence copula `uv` as `θ → 0⁺` (`tendsto_claytonCopulaFun_zero`) and the +comonotonicity copula `min(u, v)` as `θ → ∞` (`tendsto_claytonCopulaFun_atTop`). That +`C_θ` is the distribution function of a copula (the Archimedean-generator or gamma-frailty +construction) is **not** proved here. + +**Spearman's rho** of a bivariate copula is the linear correlation of its two uniform coordinates +(`spearmanRho`). For a random vector with continuous margins it is Spearman's rho of the vector, +computed on its copula (MFE Definition 7.33). Under a copula it equals `12 E[U₀U₁] − 3` +(`IsCopula.spearmanRho_eq`). + +## Main definitions + +* `spearmanRho`: Spearman's rank correlation of a bivariate copula. +* `fgmDensity`: the Farlie–Gumbel–Morgenstern density `1 + θ(1 − 2u)(1 − 2v)`. +* `fgmCopula`: the Farlie–Gumbel–Morgenstern copula, the law with density `fgmDensity θ` against + the independence copula. +* `claytonCopulaFun`: the Clayton copula function `C_θ(u, v) = (u^{−θ} + v^{−θ} − 1)^{−1/θ}`. + +## Main results + +* `IsCopula.spearmanRho_eq`: `ρ_S = 12 E[U₀U₁] − 3` for every bivariate copula. +* `isCopula_fgmCopula`, `fgmCopula_real_Iic`: the FGM copula and its distribution function. +* `exists_isCopula_fgm_iff`: `uv + θuv(1 − u)(1 − v)` is a copula exactly when `|θ| ≤ 1`. +* `spearmanRho_fgmCopula`: `ρ_S = θ/3`. +* `tendsto_claytonCopulaFun_diag_div`: Clayton lower tail dependence `λ_l = 2^{−1/θ}`. +* `tendsto_claytonCopulaFun_zero`, `tendsto_claytonCopulaFun_atTop`: the limits `Π` and `M`. + +## References + +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 7.17(b); Ex. 7.19(a); Ex. 7.19(d) + +## Tags + +Farlie–Gumbel–Morgenstern copula, Clayton copula, tail dependence, Spearman's rho, rank correlation, +Archimedean copula, MSC 62H05, MSC 91G70 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set Filter Topology + +/-! ### Integrals against the uniform law on `(0, 1)` -/ + +/-- Integrals over the uniform law on `(0, 1)` are interval integrals over `[0, 1]`. -/ +lemma integral_uniformIoo (f : ℝ → ℝ) : + ∫ x, f x ∂(volume.restrict (Ioo 0 1)) = ∫ x in (0 : ℝ)..1, f x := by + rw [intervalIntegral.integral_of_le zero_le_one, integral_Ioc_eq_integral_Ioo] + +/-- Integrals over `(-∞, t]` against the uniform law on `(0, 1)` are interval integrals over +`[0, t]` for `t ∈ [0, 1]`. -/ +lemma setIntegral_uniformIoo_Iic (f : ℝ → ℝ) {t : ℝ} (h0 : 0 ≤ t) (h1 : t ≤ 1) : + ∫ x in Iic t, f x ∂(volume.restrict (Ioo 0 1)) = ∫ x in (0 : ℝ)..t, f x := by + rw [Measure.restrict_restrict measurableSet_Iic, intervalIntegral.integral_of_le h0] + rcases h1.lt_or_eq with h1 | rfl + · rw [show Iic t ∩ Ioo 0 1 = Ioc 0 t by + ext p; exact ⟨fun h ↦ ⟨h.2.1, h.1⟩, fun h ↦ ⟨h.2, h.1, h.2.trans_lt h1⟩⟩] + · rw [inter_eq_right.2 (Ioo_subset_Ioc_self.trans Ioc_subset_Iic_self)] + exact setIntegral_congr_set Ioo_ae_eq_Ioc + +/-! ### Spearman's rho of a bivariate copula -/ + +/-- **Spearman's rank correlation** of a bivariate copula: the linear correlation of its two +uniform coordinates. For a random vector with continuous margins this is Spearman's rho of the +vector, `ρ_S(X₁, X₂) = ρ(F₁(X₁), F₂(X₂))`, computed on its copula. -/ +noncomputable def spearmanRho (C : Measure (Fin 2 → ℝ)) : ℝ := + covariance (fun v ↦ v 0) (fun v ↦ v 1) C / + √(variance (fun v ↦ v 0) C * variance (fun v ↦ v 1) C) + +/-- Coordinates of a copula are square-integrable: they lie in `(0, 1)` almost surely. -/ +lemma IsCopula.memLp_eval {ι : Type*} [Countable ι] {C : Measure (ι → ℝ)} (hC : IsCopula C) + (i : ι) : MemLp (fun v : ι → ℝ ↦ v i) 2 C := by + have := hC.isProbabilityMeasure + refine MemLp.of_bound (measurable_pi_apply i).aestronglyMeasurable 1 ?_ + filter_upwards [hC.ae_mem_Ioo] with v hv + rw [Real.norm_eq_abs, abs_of_pos (hv i).1] + exact (hv i).2.le + +/-- **Spearman's rho of a copula** is `12 E[U₀U₁] − 3`: each uniform coordinate has mean `1/2` and +variance `1/12`. -/ +theorem IsCopula.spearmanRho_eq {C : Measure (Fin 2 → ℝ)} (hC : IsCopula C) : + spearmanRho C = 12 * ∫ v, v 0 * v 1 ∂C - 3 := by + have := hC.isProbabilityMeasure + have hmean (i : Fin 2) : ∫ v, v i ∂C = 1 / 2 := by + rw [show (fun v : Fin 2 → ℝ ↦ v i) = id ∘ fun v ↦ v i from rfl, + (hC.hasLaw_eval i).integral_comp aestronglyMeasurable_id, integral_uniformIoo] + simp [integral_id] + have hsq (i : Fin 2) : ∫ v, (v i) ^ 2 ∂C = 1 / 3 := by + rw [show (fun v : Fin 2 → ℝ ↦ (v i) ^ 2) = (fun x : ℝ ↦ x ^ 2) ∘ fun v ↦ v i from rfl, + (hC.hasLaw_eval i).integral_comp (by fun_prop), integral_uniformIoo] + simp [integral_pow] + norm_num + have hvar (i : Fin 2) : variance (fun v ↦ v i) C = 1 / 12 := by + rw [variance_eq_sub (hC.memLp_eval i)] + simp only [Pi.pow_apply] + rw [hsq, hmean] + norm_num + rw [spearmanRho, covariance_eq_sub (hC.memLp_eval 0) (hC.memLp_eval 1), hvar, hvar] + simp only [Pi.mul_apply] + rw [hmean, hmean, show √((1 : ℝ) / 12 * (1 / 12)) = 1 / 12 by + rw [Real.sqrt_eq_iff_mul_self_eq_of_pos (by norm_num)]] + ring + +/-! ### The Farlie–Gumbel–Morgenstern copula -/ + +/-- The **Farlie–Gumbel–Morgenstern density** `1 + θ(1 − 2u)(1 − 2v)` on the unit square. -/ +noncomputable def fgmDensity (θ : ℝ) (v : Fin 2 → ℝ) : ℝ := + 1 + θ * ((1 - 2 * v 0) * (1 - 2 * v 1)) + +/-- The **Farlie–Gumbel–Morgenstern copula**: density `1 + θ(1 − 2u)(1 − 2v)` against the +independence copula. It is a copula for `|θ| ≤ 1` (`isCopula_fgmCopula`). -/ +noncomputable def fgmCopula (θ : ℝ) : Measure (Fin 2 → ℝ) := + (independenceCopula (Fin 2)).withDensity fun v ↦ ENNReal.ofReal (fgmDensity θ v) + +variable {θ : ℝ} + +lemma measurable_fgmDensity (θ : ℝ) : Measurable (fgmDensity θ) := by + unfold fgmDensity; fun_prop + +/-- The FGM density is nonnegative on the open unit square when `|θ| ≤ 1`. -/ +lemma fgmDensity_nonneg (hθ : |θ| ≤ 1) {v : Fin 2 → ℝ} (hv : ∀ i, v i ∈ Ioo 0 1) : + 0 ≤ fgmDensity θ v := by + have hb (i : Fin 2) : |1 - 2 * v i| ≤ 1 := + abs_le.2 ⟨by linarith [(hv i).2], by linarith [(hv i).1]⟩ + have hprod : |θ * ((1 - 2 * v 0) * (1 - 2 * v 1))| ≤ 1 := by + rw [abs_mul, abs_mul] + calc |θ| * (|1 - 2 * v 0| * |1 - 2 * v 1|) ≤ 1 * (1 * 1) := by + gcongr + exacts [hb 0, hb 1] + _ = 1 := by norm_num + unfold fgmDensity + linarith [neg_abs_le (θ * ((1 - 2 * v 0) * (1 - 2 * v 1)))] + +/-- Integrals of a product of one-coordinate functions against the independence copula +factor. -/ +lemma integral_independenceCopula_two (f g : ℝ → ℝ) : + ∫ v, f (v 0) * g (v 1) ∂(independenceCopula (Fin 2)) = + (∫ x, f x ∂(volume.restrict (Ioo 0 1))) * ∫ x, g x ∂(volume.restrict (Ioo 0 1)) := by + have h := integral_fintype_prod_eq_prod (𝕜 := ℝ) + (μ := fun _ : Fin 2 ↦ volume.restrict (Ioo (0 : ℝ) 1)) ![f, g] + simpa [Fin.prod_univ_two, independenceCopula] using h + +/-- Functions bounded on the open unit square are integrable against the independence copula. -/ +lemma integrable_independenceCopula_two {h : (Fin 2 → ℝ) → ℝ} (hm : Measurable h) (M : ℝ) + (hM : ∀ v : Fin 2 → ℝ, (∀ i, v i ∈ Ioo 0 1) → |h v| ≤ M) : + Integrable h (independenceCopula (Fin 2)) := by + have := isCopula_independenceCopula (ι := Fin 2) |>.isProbabilityMeasure + refine Integrable.of_bound hm.aestronglyMeasurable M ?_ + filter_upwards [isCopula_independenceCopula.ae_mem_Ioo] with v hv + exact hM v hv + +/-- The FGM density restricted to a rectangle splits into two products of one-coordinate +functions. -/ +private lemma indicator_rect_fgmDensity (θ : ℝ) (A B : Set ℝ) : + {v : Fin 2 → ℝ | v 0 ∈ A ∧ v 1 ∈ B}.indicator (fgmDensity θ) = fun v ↦ + A.indicator 1 (v 0) * B.indicator 1 (v 1) + + θ * (A.indicator (fun x ↦ 1 - 2 * x) (v 0) * B.indicator (fun y ↦ 1 - 2 * y) (v 1)) := by + ext v + by_cases h0 : v 0 ∈ A <;> by_cases h1 : v 1 ∈ B <;> + simp [h0, h1, indicator_of_mem, indicator_of_notMem, fgmDensity] + +/-- **Mass of a rectangle** under the FGM copula. For measurable `A`, `B`, with `λ` the uniform +law on `(0, 1)`, the FGM mass of `{U₀ ∈ A, U₁ ∈ B}` is +`λ(A) λ(B) + θ (∫_A (1 − 2x) dλ) (∫_B (1 − 2y) dλ)`. -/ +theorem fgmCopula_rect (hθ : |θ| ≤ 1) {A B : Set ℝ} (hA : MeasurableSet A) + (hB : MeasurableSet B) : + fgmCopula θ {v | v 0 ∈ A ∧ v 1 ∈ B} = ENNReal.ofReal + ((volume.restrict (Ioo 0 1)).real A * (volume.restrict (Ioo 0 1)).real B + + θ * ((∫ x in A, (1 - 2 * x) ∂(volume.restrict (Ioo 0 1))) * + ∫ y in B, (1 - 2 * y) ∂(volume.restrict (Ioo 0 1)))) := by + set S : Set (Fin 2 → ℝ) := {v | v 0 ∈ A ∧ v 1 ∈ B} + have hS : MeasurableSet S := + (measurable_pi_apply 0 hA).inter (measurable_pi_apply 1 hB) + have hint1 : Integrable (fun v : Fin 2 → ℝ ↦ A.indicator 1 (v 0) * B.indicator 1 (v 1)) + (independenceCopula (Fin 2)) := + integrable_independenceCopula_two + (((measurable_const.indicator hA).comp (measurable_pi_apply 0)).mul + ((measurable_const.indicator hB).comp (measurable_pi_apply 1))) 1 fun v _ ↦ by + by_cases h0 : v 0 ∈ A <;> by_cases h1 : v 1 ∈ B <;> simp [h0, h1] + have hint2 : Integrable (fun v : Fin 2 → ℝ ↦ + A.indicator (fun x ↦ 1 - 2 * x) (v 0) * B.indicator (fun y ↦ 1 - 2 * y) (v 1)) + (independenceCopula (Fin 2)) := by + refine integrable_independenceCopula_two + ((((measurable_const.sub (measurable_const.mul measurable_id)).indicator hA).comp + (measurable_pi_apply 0)).mul + (((measurable_const.sub (measurable_const.mul measurable_id)).indicator hB).comp + (measurable_pi_apply 1))) 1 fun v hv ↦ ?_ + have hb (i : Fin 2) : |1 - 2 * v i| ≤ 1 := + abs_le.2 ⟨by linarith [(hv i).2], by linarith [(hv i).1]⟩ + rw [abs_mul] + refine (mul_le_of_le_one_left (abs_nonneg _) ?_).trans ?_ + · by_cases h0 : v 0 ∈ A + · simpa [h0] using hb 0 + · simp [h0] + · by_cases h1 : v 1 ∈ B + · simpa [h1] using hb 1 + · simp [h1] + have hnn : 0 ≤ᵐ[independenceCopula (Fin 2)] S.indicator (fgmDensity θ) := by + filter_upwards [isCopula_independenceCopula.ae_mem_Ioo] with v hv + exact indicator_nonneg (fun w _ ↦ fgmDensity_nonneg hθ hv) v + have hSint : Integrable (S.indicator (fgmDensity θ)) (independenceCopula (Fin 2)) := by + rw [indicator_rect_fgmDensity]; exact hint1.add (hint2.const_mul θ) + rw [fgmCopula, withDensity_apply _ hS, ← lintegral_indicator hS, + show S.indicator (fun v ↦ ENNReal.ofReal (fgmDensity θ v)) = + fun v ↦ ENNReal.ofReal (S.indicator (fgmDensity θ) v) by + ext v; by_cases hv : v ∈ S <;> simp [hv], + ← ofReal_integral_eq_lintegral_ofReal hSint hnn, indicator_rect_fgmDensity, + integral_add hint1 (hint2.const_mul θ), integral_const_mul, integral_independenceCopula_two, + integral_independenceCopula_two, integral_indicator_one hA, integral_indicator_one hB, + integral_indicator hA, integral_indicator hB] + +/-- `∫₀¹ (1 − 2x) dx = 0`: the FGM perturbation integrates out of each margin. -/ +lemma integral_uniformIoo_one_sub_two_mul : + ∫ x, (1 - 2 * x) ∂(volume.restrict (Ioo (0 : ℝ) 1)) = 0 := by + rw [integral_uniformIoo, intervalIntegral.integral_sub intervalIntegrable_const + ((by fun_prop : Continuous fun x : ℝ ↦ 2 * x).intervalIntegrable _ _), + intervalIntegral.integral_const_mul, integral_id] + norm_num + +/-- `∫₀ᵗ (1 − 2x) dx = t − t²`. -/ +lemma integral_zero_one_sub_two_mul (t : ℝ) : ∫ x in (0 : ℝ)..t, (1 - 2 * x) = t - t ^ 2 := by + rw [intervalIntegral.integral_sub intervalIntegrable_const + ((by fun_prop : Continuous fun x : ℝ ↦ 2 * x).intervalIntegrable _ _), + intervalIntegral.integral_const_mul, integral_id] + simp only [intervalIntegral.integral_const, sub_zero, smul_eq_mul, mul_one] + ring + +/-- **The FGM copula is a copula** for `|θ| ≤ 1`. -/ +theorem isCopula_fgmCopula (hθ : |θ| ≤ 1) : IsCopula (fgmCopula θ) := by + have hmarg (A : Set ℝ) (hA : MeasurableSet A) (i : Fin 2) : + fgmCopula θ ((fun v : Fin 2 → ℝ ↦ v i) ⁻¹' A) = volume.restrict (Ioo 0 1) A := by + have hint : ∫ y in univ, (1 - 2 * y) ∂(volume.restrict (Ioo (0 : ℝ) 1)) = 0 := by + rw [Measure.restrict_univ, integral_uniformIoo_one_sub_two_mul] + fin_cases i + · change fgmCopula θ ((fun v : Fin 2 → ℝ ↦ v 0) ⁻¹' A) = _ + rw [show (fun v : Fin 2 → ℝ ↦ v 0) ⁻¹' A = {v | v 0 ∈ A ∧ v 1 ∈ univ} by ext; simp, + fgmCopula_rect hθ hA MeasurableSet.univ, probReal_univ, hint, mul_one, mul_zero, + mul_zero, add_zero, ofReal_measureReal] + · change fgmCopula θ ((fun v : Fin 2 → ℝ ↦ v 1) ⁻¹' A) = _ + rw [show (fun v : Fin 2 → ℝ ↦ v 1) ⁻¹' A = {v | v 0 ∈ univ ∧ v 1 ∈ A} by ext; simp, + fgmCopula_rect hθ MeasurableSet.univ hA, probReal_univ, hint, one_mul, zero_mul, + mul_zero, add_zero, ofReal_measureReal] + have hprob : IsProbabilityMeasure (fgmCopula θ) := + ⟨by simpa using hmarg univ MeasurableSet.univ 0⟩ + exact ⟨hprob, fun i ↦ Measure.ext fun A hA ↦ by + rw [Measure.map_apply (measurable_pi_apply i) hA, hmarg A hA i]⟩ + +/-- **The FGM distribution function**: `C(u) = u₀u₁ + θ u₀u₁(1 − u₀)(1 − u₁)` on `[0, 1]²`. -/ +theorem fgmCopula_real_Iic (hθ : |θ| ≤ 1) (u : Fin 2 → ℝ) (hu : ∀ i, u i ∈ Icc 0 1) : + (fgmCopula θ).real (Iic u) = u 0 * u 1 + θ * u 0 * u 1 * (1 - u 0) * (1 - u 1) := by + have := (isCopula_fgmCopula hθ).isProbabilityMeasure + rw [show Iic u = {v : Fin 2 → ℝ | v 0 ∈ Iic (u 0) ∧ v 1 ∈ Iic (u 1)} by + ext v; simp [Pi.le_def, Fin.forall_fin_two], + measureReal_def, fgmCopula_rect hθ measurableSet_Iic measurableSet_Iic, + uniformIoo_real_Iic (hu 0).1 (hu 0).2, uniformIoo_real_Iic (hu 1).1 (hu 1).2, + setIntegral_uniformIoo_Iic _ (hu 0).1 (hu 0).2, setIntegral_uniformIoo_Iic _ (hu 1).1 (hu 1).2, + integral_zero_one_sub_two_mul, integral_zero_one_sub_two_mul, ENNReal.toReal_ofReal] + · ring + · -- the closed form is the mass of an orthant, hence nonnegative + have h0 := (hu 0).1; have h1 := (hu 1).1; have h0' := (hu 0).2; have h1' := (hu 1).2 + have ha : 0 ≤ u 0 - u 0 ^ 2 := by nlinarith + have hb : 0 ≤ u 1 - u 1 ^ 2 := by nlinarith + have hθ' := abs_le.1 hθ + nlinarith [mul_nonneg ha hb, mul_le_mul_of_nonneg_left (sub_le_self (u 0) (sq_nonneg (u 0))) h1, + mul_nonneg (mul_nonneg ha hb) (by linarith : (0 : ℝ) ≤ 1 + θ)] + +/-- **FGM is a copula exactly for `|θ| ≤ 1`** (QRM Exercise Book, Exercise 7.19): some copula has +distribution function `uv + θ uv(1 − u)(1 − v)` on `[0, 1]²` if and only if `|θ| ≤ 1`. For +`θ < −1` the mass of a small square at the origin would be negative, and for `θ > 1` so would the +mass of a thin strip `{U₀ ≤ ε, U₁ > 1 − ε}`. -/ +theorem exists_isCopula_fgm_iff (θ : ℝ) : + (∃ C : Measure (Fin 2 → ℝ), IsCopula C ∧ ∀ u : Fin 2 → ℝ, (∀ i, u i ∈ Icc 0 1) → + C.real (Iic u) = u 0 * u 1 + θ * u 0 * u 1 * (1 - u 0) * (1 - u 1)) ↔ |θ| ≤ 1 := by + refine ⟨fun ⟨C, hC, hdf⟩ ↦ ?_, fun hθ ↦ ⟨fgmCopula θ, isCopula_fgmCopula hθ, + fgmCopula_real_Iic hθ⟩⟩ + have := hC.isProbabilityMeasure + -- for `1 + a < 0`, some level `ε ∈ (0, 1)` keeps `1 + a (1 − ε)²` negative + have hsmall (a : ℝ) (ha : 1 + a < 0) : ∃ ε ∈ Ioo (0 : ℝ) 1, 1 + a * (1 - ε) ^ 2 < 0 := by + have hlim : Tendsto (fun ε : ℝ ↦ 1 + a * (1 - ε) ^ 2) (𝓝[>] 0) (𝓝 (1 + a)) := by + have hcont : Continuous fun ε : ℝ ↦ 1 + a * (1 - ε) ^ 2 := by fun_prop + simpa using (hcont.tendsto 0).mono_left nhdsWithin_le_nhds + obtain ⟨ε, hε, hε01⟩ := ((hlim.eventually_lt_const ha).and (Ioo_mem_nhdsGT one_pos)).exists + exact ⟨ε, hε01, hε⟩ + by_contra hθ + rw [abs_le, not_and_or, not_le, not_le] at hθ + rcases hθ with hneg | hpos + · -- `θ < −1`: the square `[0, ε]²` would carry negative mass + obtain ⟨ε, hε, hneg'⟩ := hsmall θ (by linarith) + have h := hdf ![ε, ε] fun i ↦ by fin_cases i <;> exact ⟨hε.1.le, hε.2.le⟩ + simp only [Matrix.cons_val_zero, Matrix.cons_val_one] at h + have hnn := measureReal_nonneg (μ := C) (s := Iic ![ε, ε]) + rw [h] at hnn + nlinarith [mul_pos (mul_pos hε.1 hε.1) (neg_pos.2 hneg')] + · -- `θ > 1`: the strip `{U₀ ≤ ε, U₁ > 1 − ε}` would carry negative mass + obtain ⟨ε, hε, hneg'⟩ := hsmall (-θ) (by linarith) + have h := hdf ![ε, 1 - ε] fun i ↦ by + fin_cases i <;> simp <;> constructor <;> linarith [hε.1, hε.2] + simp only [Matrix.cons_val_zero, Matrix.cons_val_one] at h + have hsub : C.real (Iic ![ε, 1 - ε]) ≤ C.real {v : Fin 2 → ℝ | v 0 ≤ ε} := + measureReal_mono fun v hv ↦ by simpa using hv 0 + rw [h, hC.measureReal_coord_le 0 hε.1.le hε.2.le] at hsub + nlinarith [mul_pos (mul_pos hε.1 hε.1) (neg_pos.2 hneg')] + +/-- **Spearman's rho of the FGM copula is `θ/3`** (QRM Exercise Book, Exercise 7.19(d)), so the +family attains rank correlations only in `[−1/3, 1/3]`. -/ +theorem spearmanRho_fgmCopula (hθ : |θ| ≤ 1) : spearmanRho (fgmCopula θ) = θ / 3 := by + rw [(isCopula_fgmCopula hθ).spearmanRho_eq] + have hnn : ∀ᵐ v ∂(independenceCopula (Fin 2)), 0 ≤ fgmDensity θ v := by + filter_upwards [isCopula_independenceCopula.ae_mem_Ioo] with v hv + exact fgmDensity_nonneg hθ hv + have hpt : (fun v : Fin 2 → ℝ ↦ (ENNReal.ofReal (fgmDensity θ v)).toReal • (v 0 * v 1)) =ᵐ[ + independenceCopula (Fin 2)] fun v ↦ v 0 * v 1 + + θ * ((v 0 * (1 - 2 * v 0)) * (v 1 * (1 - 2 * v 1))) := by + filter_upwards [hnn] with v hv + rw [ENNReal.toReal_ofReal hv, smul_eq_mul, fgmDensity] + ring + have hint1 : Integrable (fun v : Fin 2 → ℝ ↦ v 0 * v 1) (independenceCopula (Fin 2)) := + integrable_independenceCopula_two (by fun_prop) 1 fun v hv ↦ by + rw [abs_mul, abs_of_pos (hv 0).1, abs_of_pos (hv 1).1] + exact (mul_le_of_le_one_left (hv 1).1.le (hv 0).2.le).trans (hv 1).2.le + have hint2 : Integrable (fun v : Fin 2 → ℝ ↦ (v 0 * (1 - 2 * v 0)) * (v 1 * (1 - 2 * v 1))) + (independenceCopula (Fin 2)) := + integrable_independenceCopula_two (by fun_prop) 1 fun v hv ↦ by + have hb (i : Fin 2) : |v i * (1 - 2 * v i)| ≤ 1 := by + rw [abs_mul, abs_of_pos (hv i).1] + exact (mul_le_of_le_one_left (abs_nonneg _) (hv i).2.le).trans + (abs_le.2 ⟨by linarith [(hv i).2], by linarith [(hv i).1]⟩) + rw [abs_mul] + exact (mul_le_of_le_one_left (abs_nonneg _) (hb 0)).trans (hb 1) + have hx : ∫ x in (0 : ℝ)..1, x = 1 / 2 := by rw [integral_id]; norm_num + have hx2 : ∫ x in (0 : ℝ)..1, x * (1 - 2 * x) = -1 / 6 := by + rw [show (fun x : ℝ ↦ x * (1 - 2 * x)) = fun x ↦ x - 2 * x ^ 2 by ext x; ring, + intervalIntegral.integral_sub + ((by fun_prop : Continuous fun x : ℝ ↦ x).intervalIntegrable _ _) + ((by fun_prop : Continuous fun x : ℝ ↦ 2 * x ^ 2).intervalIntegrable _ _), + intervalIntegral.integral_const_mul, integral_id, integral_pow] + norm_num + rw [fgmCopula, integral_withDensity_eq_integral_toReal_smul + (measurable_fgmDensity θ).ennreal_ofReal (ae_of_all _ fun _ ↦ ENNReal.ofReal_lt_top), + integral_congr_ae hpt, integral_add hint1 (hint2.const_mul θ), integral_const_mul, + integral_independenceCopula_two (fun x ↦ x) (fun x ↦ x), + integral_independenceCopula_two (fun x ↦ x * (1 - 2 * x)) (fun x ↦ x * (1 - 2 * x)), + integral_uniformIoo, integral_uniformIoo, hx, hx2] + ring + +/-! ### The Clayton copula function -/ + +/-- The **Clayton copula function** `C_θ(u, v) = (u^{−θ} + v^{−θ} − 1)^{−1/θ}`. Only the function +is studied here. That it is the distribution function of a copula is not proved. -/ +noncomputable def claytonCopulaFun (θ u v : ℝ) : ℝ := + (u ^ (-θ) + v ^ (-θ) - 1) ^ (-1 / θ) + +/-- On the diagonal, `C_θ(u, u) = u (2 − u^θ)^{−1/θ}`. -/ +lemma claytonCopulaFun_diag (hθ : 0 < θ) {u : ℝ} (hu : 0 < u) (hu1 : u ≤ 1) : + claytonCopulaFun θ u u = u * (2 - u ^ θ) ^ (-1 / θ) := by + have hpow : u ^ θ ≤ 1 := Real.rpow_le_one hu.le hu1 hθ.le + have hsplit : u ^ (-θ) + u ^ (-θ) - 1 = u ^ (-θ) * (2 - u ^ θ) := by + rw [mul_sub, ← Real.rpow_add hu, neg_add_cancel, Real.rpow_zero] + ring + rw [claytonCopulaFun, hsplit, Real.mul_rpow (Real.rpow_nonneg hu.le _) (by linarith), + ← Real.rpow_mul hu.le, show -θ * (-1 / θ) = 1 by field_simp, Real.rpow_one] + +/-- **Lower tail dependence of the Clayton copula** (QRM Exercise Book, Exercise 7.17(b)): +`λ_l = lim_{u → 0⁺} C_θ(u, u)/u = 2^{−1/θ}`. -/ +theorem tendsto_claytonCopulaFun_diag_div (hθ : 0 < θ) : + Tendsto (fun u ↦ claytonCopulaFun θ u u / u) (𝓝[>] 0) (𝓝 (2 ^ (-1 / θ))) := by + have hpow : Tendsto (fun u : ℝ ↦ u ^ θ) (𝓝[>] 0) (𝓝 0) := by + have := (Real.continuousAt_rpow_const 0 θ (Or.inr hθ.le)).tendsto.mono_left + (nhdsWithin_le_nhds (s := Ioi 0)) + simpa [Real.zero_rpow hθ.ne'] using this + have hlim : Tendsto (fun u : ℝ ↦ (2 - u ^ θ) ^ (-1 / θ)) (𝓝[>] 0) (𝓝 (2 ^ (-1 / θ))) := by + have h2 : Tendsto (fun u : ℝ ↦ 2 - u ^ θ) (𝓝[>] 0) (𝓝 2) := by + simpa using (tendsto_const_nhds (x := (2 : ℝ))).sub hpow + exact (Real.continuousAt_rpow_const 2 (-1 / θ) (Or.inl two_ne_zero)).tendsto.comp h2 + refine hlim.congr' ?_ + filter_upwards [Ioo_mem_nhdsGT one_pos] with u hu + rw [claytonCopulaFun_diag hθ hu.1 hu.2.le, mul_div_cancel_left₀ _ hu.1.ne'] + +/-- **The Clayton copula tends to the comonotonicity copula as `θ → ∞`** (QRM Exercise Book, +Exercise 7.17(d)): `C_θ(u, v) → min(u, v)` for `u, v ∈ (0, 1]`. -/ +theorem tendsto_claytonCopulaFun_atTop {u v : ℝ} (hu : 0 < u) (hu1 : u ≤ 1) (hv : 0 < v) + (hv1 : v ≤ 1) : Tendsto (fun θ ↦ claytonCopulaFun θ u v) atTop (𝓝 (min u v)) := by + have hm : 0 < min u v := lt_min hu hv + -- `m^{−θ} ≤ u^{−θ} + v^{−θ} − 1 ≤ 2 m^{−θ}` for `θ > 0`, with `m = min u v` + have hlo (θ : ℝ) (hθ : 0 < θ) : min u v ^ (-θ) ≤ u ^ (-θ) + v ^ (-θ) - 1 := by + have hu' : 1 ≤ u ^ (-θ) := Real.one_le_rpow_of_pos_of_le_one_of_nonpos hu hu1 (by linarith) + have hv' : 1 ≤ v ^ (-θ) := Real.one_le_rpow_of_pos_of_le_one_of_nonpos hv hv1 (by linarith) + rcases min_choice u v with h | h <;> rw [h] <;> linarith + have hhi (θ : ℝ) (hθ : 0 < θ) : u ^ (-θ) + v ^ (-θ) - 1 ≤ 2 * min u v ^ (-θ) := by + have hu' : u ^ (-θ) ≤ min u v ^ (-θ) := + Real.rpow_le_rpow_of_nonpos hm (min_le_left u v) (by linarith) + have hv' : v ^ (-θ) ≤ min u v ^ (-θ) := + Real.rpow_le_rpow_of_nonpos hm (min_le_right u v) (by linarith) + have hv1' : 1 ≤ v ^ (-θ) := Real.one_le_rpow_of_pos_of_le_one_of_nonpos hv hv1 (by linarith) + linarith + have hexp (θ : ℝ) (hθ : 0 < θ) : -1 / θ ≤ 0 := div_nonpos_of_nonpos_of_nonneg (by norm_num) hθ.le + have hmθ (θ : ℝ) (hθ : 0 < θ) : (min u v ^ (-θ)) ^ (-1 / θ) = min u v := by + rw [← Real.rpow_mul hm.le, show -θ * (-1 / θ) = 1 by field_simp, Real.rpow_one] + have hup (θ : ℝ) (hθ : 0 < θ) : claytonCopulaFun θ u v ≤ min u v := by + rw [claytonCopulaFun, ← hmθ θ hθ] + exact Real.rpow_le_rpow_of_nonpos (Real.rpow_pos_of_pos hm _) (hlo θ hθ) (hexp θ hθ) + have hdown (θ : ℝ) (hθ : 0 < θ) : (2 : ℝ) ^ (-1 / θ) * min u v ≤ claytonCopulaFun θ u v := by + rw [claytonCopulaFun, ← hmθ θ hθ, ← Real.mul_rpow zero_le_two (Real.rpow_nonneg hm.le _)] + exact Real.rpow_le_rpow_of_nonpos + (lt_of_lt_of_le (Real.rpow_pos_of_pos hm _) (hlo θ hθ)) (hhi θ hθ) (hexp θ hθ) + have hlim2 : Tendsto (fun θ : ℝ ↦ (2 : ℝ) ^ (-1 / θ) * min u v) atTop (𝓝 (min u v)) := by + have h0 : Tendsto (fun θ : ℝ ↦ -1 / θ) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop tendsto_id + have h2 := ((Real.continuousAt_const_rpow two_ne_zero (b := 0)).tendsto.comp h0).mul_const + (min u v) + simpa using h2 + refine tendsto_of_tendsto_of_tendsto_of_le_of_le' hlim2 tendsto_const_nhds ?_ ?_ + · filter_upwards [eventually_gt_atTop 0] with θ hθ using hdown θ hθ + · filter_upwards [eventually_gt_atTop 0] with θ hθ using hup θ hθ + +/-- **The Clayton copula tends to the independence copula as `θ → 0⁺`** (QRM Exercise Book, +Exercise 7.17(c)): `C_θ(u, v) → uv` for `u, v ∈ (0, 1]`. Writing +`C_θ = exp(−θ⁻¹ log(u^{−θ} + v^{−θ} − 1))`, the exponent is minus the difference quotient at `0` +of `θ ↦ log(u^{−θ} + v^{−θ} − 1)`, whose derivative there is `−log u − log v`. -/ +theorem tendsto_claytonCopulaFun_zero {u v : ℝ} (hu : 0 < u) (hu1 : u ≤ 1) (hv : 0 < v) + (hv1 : v ≤ 1) : Tendsto (fun θ ↦ claytonCopulaFun θ u v) (𝓝[>] 0) (𝓝 (u * v)) := by + set s : ℝ → ℝ := fun θ ↦ u ^ (-θ) + v ^ (-θ) - 1 + have hs0 : s 0 = 1 := by simp [s] + have hspos (θ : ℝ) (hθ : 0 < θ) : 0 < s θ := by + have hu' : 1 ≤ u ^ (-θ) := Real.one_le_rpow_of_pos_of_le_one_of_nonpos hu hu1 (by linarith) + have hv' : 1 ≤ v ^ (-θ) := Real.one_le_rpow_of_pos_of_le_one_of_nonpos hv hv1 (by linarith) + simp only [s]; linarith + have hpow (x : ℝ) (hx : 0 < x) : HasDerivAt (fun θ : ℝ ↦ x ^ (-θ)) (-Real.log x) 0 := by + have h := (Real.hasStrictDerivAt_const_rpow hx (-0)).hasDerivAt.comp 0 (hasDerivAt_neg 0) + rw [neg_zero, Real.rpow_zero, one_mul, mul_neg_one] at h + exact h + have hderiv : HasDerivAt (fun θ ↦ Real.log (s θ)) (-Real.log u + -Real.log v) 0 := by + have hs : HasDerivAt s (-Real.log u + -Real.log v) 0 := + ((hpow u hu).add (hpow v hv)).sub_const 1 + have h := hs.log (by rw [hs0]; exact one_ne_zero) + rwa [hs0, div_one] at h + have hslope : Tendsto (fun t : ℝ ↦ t⁻¹ * Real.log (s t)) (𝓝[>] 0) + (𝓝 (-Real.log u + -Real.log v)) := by + simpa [hs0] using hderiv.tendsto_slope_zero_right + have hexp : Tendsto (fun θ : ℝ ↦ Real.exp (-(θ⁻¹ * Real.log (s θ)))) (𝓝[>] 0) + (𝓝 (Real.exp (-(-Real.log u + -Real.log v)))) := + (Real.continuous_exp.tendsto _).comp hslope.neg + rw [show -(-Real.log u + -Real.log v) = Real.log (u * v) by + rw [Real.log_mul hu.ne' hv.ne']; ring, Real.exp_log (mul_pos hu hv)] at hexp + refine hexp.congr' ?_ + filter_upwards [self_mem_nhdsWithin] with θ hθ + rw [claytonCopulaFun, Real.rpow_def_of_pos (hspos θ hθ)] + congr 1 + ring + +end MathFin diff --git a/LeanPool/MathFin/Probability/Dependence/CorrelationFallacies.lean b/LeanPool/MathFin/Probability/Dependence/CorrelationFallacies.lean new file mode 100644 index 0000000000..13a66c7c29 --- /dev/null +++ b/LeanPool/MathFin/Probability/Dependence/CorrelationFallacies.lean @@ -0,0 +1,253 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Gaussian.NormalQuantile +public import Mathlib.Probability.Distributions.Gaussian.HasGaussianLaw.Basic +public import Mathlib.Probability.Distributions.Gaussian.HasGaussianLaw.Independence +public import Mathlib.Probability.Independence.Integration +public import Mathlib.Topology.UniformSpace.Uniformizable + +/-! +# Normal margins and zero correlation determine neither independence nor normality + +Embrechts, McNeil and Straumann (2002) list the fallacies that come from reading linear correlation +as a complete description of dependence. The standard counterexample (QRM Exercise Book +Ex. 6.1 and 6.18; McNeil–Frey–Embrechts (2015), Fallacy 1) is a standard normal `Z` and an +independent random sign `V`, `P(V = 1) = P(V = −1) = 1/2`, combined as `Y = V Z`. Then: + +* `Y` is standard normal (`hasLaw_mul_gaussianReal`), because a random sign times a symmetric + variable keeps its law (`rademacher_mconv_of_map_neg`); +* `cov(Z, Y) = 0` (`covariance_mul_eq_zero`); +* `Z` and `Y` are **not independent** (`not_indepFun_mul`), since `|Y| = |Z|`; +* `Z + Y` is **not Gaussian** (`not_hasLaw_add_mul_gaussianReal`). It vanishes exactly when + `V = −1`, which has probability `1/2`, whereas a Gaussian law gives the point `0` mass `0` or + `1`; +* hence `(Z, Y)` is **not jointly Gaussian** (`not_hasGaussianLaw_prod`), although both margins + are: for a jointly Gaussian pair, zero covariance would force independence + (Mathlib's `HasGaussianLaw.indepFun_of_covariance_eq_zero`). + +So margins together with the correlation do not determine the joint law. Two variables can be +standard normal and uncorrelated without being independent, and without their sum being normal. +Such a pair exists (`exists_gaussian_uncorrelated_not_indepFun`). + +## Main definitions + +* `rademacher`: the law of a fair random sign, `±1` each with probability `1/2`. + +## Main results + +* `rademacher_mconv_of_map_neg`: a random sign times an independent symmetric variable has the + same law as the variable. +* `hasLaw_mul_gaussianReal`, `covariance_mul_eq_zero`, `not_indepFun_mul`, + `not_hasLaw_add_mul_gaussianReal`, `not_hasGaussianLaw_prod`: the counterexample. +* `exists_gaussian_uncorrelated_not_indepFun`: the counterexample is realized. + +## References + +* [Embrechts, McNeil and Straumann (2002)][EmbrechtsMcNeilStraumann2002] +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 6.1, 6.18 + +## Tags + +correlation fallacy, uncorrelated not independent, joint normality, dependence, +Embrechts–McNeil–Straumann, random sign, MSC 62H05, MSC 60E05, MSC 91G70 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal + +/-- The **Rademacher law** of a fair random sign: `±1`, each with probability `1/2`. -/ +noncomputable def rademacher : Measure ℝ := + (2 : ℝ≥0∞)⁻¹ • (Measure.dirac 1 + Measure.dirac (-1)) + +instance isProbabilityMeasure_rademacher : IsProbabilityMeasure rademacher := + ⟨by simp [rademacher, ENNReal.inv_two_add_inv_two]⟩ + +/-- A random sign has mean zero. -/ +lemma integral_id_rademacher : ∫ x, x ∂rademacher = 0 := by + rw [rademacher, integral_smul_measure, integral_add_measure (integrable_dirac (by simp)) + (integrable_dirac (by simp)), integral_dirac, integral_dirac] + simp + +/-- A random sign is almost surely `±1`. -/ +lemma ae_rademacher : ∀ᵐ x ∂rademacher, x = 1 ∨ x = -1 := by + rw [ae_iff] + simp [rademacher, Measure.dirac_apply] + +/-- A random sign takes the value `-1` with probability `1/2`. -/ +lemma rademacher_singleton_neg_one : rademacher {-1} = 2⁻¹ := by + simp [rademacher, show (1 : ℝ) ≠ -1 by norm_num] + +/-- **A random sign times an independent symmetric variable keeps its law**: if `μ` is symmetric, +`μ.map (−·) = μ`, then the multiplicative convolution of the Rademacher law with `μ` is `μ`. -/ +theorem rademacher_mconv_of_map_neg {μ : Measure ℝ} [SFinite μ] + (hμ : μ.map (fun x ↦ -x) = μ) : rademacher ∗ₘ μ = μ := by + rw [rademacher, Measure.mconv_smul_left, Measure.add_mconv, Measure.dirac_mconv, + Measure.dirac_mconv] + simp only [one_mul, neg_one_mul, Measure.map_id', hμ] + rw [← two_smul ℝ≥0∞ μ, smul_smul, ENNReal.inv_mul_cancel (by norm_num) (by norm_num), one_smul] + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + {Z V : Ω → ℝ} + +omit [IsProbabilityMeasure P] in +/-- A variable with the Rademacher law is almost surely `±1`. -/ +private lemma ae_eq_one_or_neg_one (hV : HasLaw V rademacher P) : + ∀ᵐ ω ∂P, V ω = 1 ∨ V ω = -1 := + (hV.ae_iff (p := fun x ↦ x = 1 ∨ x = -1) (measurableSet_setOfPred.1 + ((measurableSet_singleton 1).union (measurableSet_singleton (-1))))).2 ae_rademacher + +omit [IsProbabilityMeasure P] in +/-- `HasLaw` transfers the mass of a preimage; Mathlib's `HasLaw.measureReal_eq` is stated for +set-builder events, and the proofs below work with preimages. -/ +lemma measureReal_preimage_of_hasLaw {X : Ω → ℝ} {μ : Measure ℝ} (hX : HasLaw X μ P) + {s : Set ℝ} (hs : MeasurableSet s) : P.real (X ⁻¹' s) = μ.real s := by + rw [← map_measureReal_apply_of_aemeasurable hX.aemeasurable hs, hX.map_eq] + +omit [IsProbabilityMeasure P] in +/-- **`Y = V Z` is standard normal**: a random sign times an independent standard normal +variable. -/ +theorem hasLaw_mul_gaussianReal (hZ : HasLaw Z (gaussianReal 0 1) P) (hV : HasLaw V rademacher P) + (hVZ : V ⟂ᵢ[P] Z) : HasLaw (fun ω ↦ V ω * Z ω) (gaussianReal 0 1) P := by + have h := hVZ.hasLaw_fun_mul hV hZ + rwa [rademacher_mconv_of_map_neg (μ := gaussianReal 0 1) + (by rw [gaussianReal_map_neg, neg_zero])] at h + +/-- **Zero correlation**: `cov(Z, V Z) = 0`, since `E[Z · V Z] = E[V] E[Z²] = 0`. -/ +theorem covariance_mul_eq_zero (hZ : HasLaw Z (gaussianReal 0 1) P) (hV : HasLaw V rademacher P) + (hVZ : V ⟂ᵢ[P] Z) : cov[Z, fun ω ↦ V ω * Z ω; P] = 0 := by + have hY := hasLaw_mul_gaussianReal hZ hV hVZ + have hEV : P[V] = 0 := by rw [hV.integral_eq, integral_id_rademacher] + have hEZ : P[Z] = 0 := by rw [hZ.integral_eq, integral_id_gaussianReal] + have hind : V ⟂ᵢ[P] (fun ω ↦ Z ω * Z ω) := + hVZ.comp (φ := id) (ψ := fun z ↦ z * z) measurable_id (measurable_id.mul measurable_id) + rw [covariance_eq_sub hZ.hasGaussianLaw.memLp_two + hY.hasGaussianLaw.memLp_two, hEZ, zero_mul, sub_zero] + calc P[Z * fun ω ↦ V ω * Z ω] = ∫ ω, V ω * (Z ω * Z ω) ∂P := by + congr 1; ext ω; simp only [Pi.mul_apply]; ring + _ = P[V] * ∫ ω, Z ω * Z ω ∂P := + hind.integral_fun_mul_eq_mul_integral hV.aemeasurable.aestronglyMeasurable + (hZ.aemeasurable.mul hZ.aemeasurable).aestronglyMeasurable + _ = 0 := by rw [hEV, zero_mul] + +omit [IsProbabilityMeasure P] in +/-- `|V Z| = |Z|` almost surely. -/ +private lemma ae_abs_mul_eq (hV : HasLaw V rademacher P) : + ∀ᵐ ω ∂P, |V ω * Z ω| = |Z ω| := by + filter_upwards [ae_eq_one_or_neg_one hV] with ω hω + rcases hω with h1 | h1 <;> simp [h1] + +/-- The standard normal law puts mass strictly between `0` and `1` on `[-1, 1]`. -/ +lemma gaussianReal_Icc_mem_Ioo : + (gaussianReal 0 1).real (Icc (-1) 1) ∈ Ioo 0 1 := by + have := nullSingletonClass_gaussianReal (μ := 0) (v := 1) one_ne_zero + have hIoc : (gaussianReal 0 1).real (Icc (-1) 1) = Phi 1 - Phi (-1) := by + rw [measureReal_def, ← measure_congr (Ioc_ae_eq_Icc (μ := gaussianReal 0 1)), + ← measure_cdf (gaussianReal 0 1), StieltjesFunction.measure_Ioc, + ENNReal.toReal_ofReal (sub_nonneg.2 (monotone_cdf _ (by norm_num))), + cdf_gaussianReal_zero_one] + rw [hIoc] + exact ⟨sub_pos.2 (strictMono_Phi (by norm_num)), + by linarith [(Phi_mem_Ioo 1).2, (Phi_mem_Ioo (-1)).1]⟩ + +omit [IsProbabilityMeasure P] in +/-- **`Z` and `V Z` are not independent**, though uncorrelated: they share the absolute value, +so `P(|Z| ≤ 1, |V Z| ≤ 1) = P(|Z| ≤ 1) ≠ P(|Z| ≤ 1)²`. -/ +theorem not_indepFun_mul (hZ : HasLaw Z (gaussianReal 0 1) P) (hV : HasLaw V rademacher P) : + ¬ Z ⟂ᵢ[P] (fun ω ↦ V ω * Z ω) := by + intro hind + have hS : MeasurableSet (Icc (-1 : ℝ) 1) := measurableSet_Icc + have hiff : ∀ᵐ ω ∂P, (V ω * Z ω ∈ Icc (-1 : ℝ) 1 ↔ Z ω ∈ Icc (-1 : ℝ) 1) := by + filter_upwards [ae_abs_mul_eq (Z := Z) hV] with ω hω + rw [mem_Icc, mem_Icc, ← abs_le, ← abs_le, hω] + have hsame : (fun ω ↦ V ω * Z ω) ⁻¹' Icc (-1) 1 =ᵐ[P] Z ⁻¹' Icc (-1) 1 := by + filter_upwards [hiff] with ω hω + exact hω + have hinter : (Z ⁻¹' Icc (-1) 1 ∩ (fun ω ↦ V ω * Z ω) ⁻¹' Icc (-1) 1 : Set Ω) + =ᵐ[P] Z ⁻¹' Icc (-1) 1 := by + filter_upwards [hiff] with ω hω + exact ⟨fun h ↦ h.1, fun h ↦ ⟨h, hω.2 h⟩⟩ + have h := hind.measure_inter_preimage_eq_mul _ _ hS hS + rw [measure_congr hinter, measure_congr hsame] at h + have hc : P.real (Z ⁻¹' Icc (-1) 1) ∈ Ioo 0 1 := by + rw [measureReal_preimage_of_hasLaw hZ hS] + exact gaussianReal_Icc_mem_Ioo + have h' : P.real (Z ⁻¹' Icc (-1) 1) + = P.real (Z ⁻¹' Icc (-1) 1) * P.real (Z ⁻¹' Icc (-1) 1) := by + simp only [measureReal_def] + rw [← ENNReal.toReal_mul, ← h] + nlinarith [mul_pos hc.1 (sub_pos.2 hc.2)] + +/-- `Z + V Z` vanishes with probability exactly `1/2`: on `{V = −1}`, and otherwise only where +`Z = 0`, a null event. -/ +private lemma measureReal_add_mul_eq_zero (hZ : HasLaw Z (gaussianReal 0 1) P) + (hV : HasLaw V rademacher P) : P.real {ω | Z ω + V ω * Z ω = 0} = 2⁻¹ := by + have hset : {ω | Z ω + V ω * Z ω = 0} =ᵐ[P] (V ⁻¹' {-1} ∪ Z ⁻¹' {0} : Set Ω) := by + filter_upwards [ae_eq_one_or_neg_one hV] with ω hω + rcases hω with h1 | h1 <;> simp [h1, show (1 : ℝ) ≠ -1 by norm_num] + have hV1 : P.real (V ⁻¹' {-1}) = 2⁻¹ := by + rw [measureReal_preimage_of_hasLaw hV (measurableSet_singleton _), measureReal_def, + rademacher_singleton_neg_one] + simp + have hZ0 : P.real (Z ⁻¹' {0}) = 0 := by + have := nullSingletonClass_gaussianReal (μ := 0) (v := 1) one_ne_zero + rw [measureReal_preimage_of_hasLaw hZ (measurableSet_singleton _)] + simp [measureReal_def] + rw [measureReal_congr hset] + refine le_antisymm ((measureReal_union_le _ _).trans (by rw [hV1, hZ0, add_zero])) ?_ + rw [← hV1] + exact measureReal_mono subset_union_left + +/-- **`Z + V Z` is not Gaussian**: it has an atom of mass `1/2` at `0`, while a Gaussian law gives +the point `0` mass `0` (positive variance) or `0` or `1` (a point mass). -/ +theorem not_hasLaw_add_mul_gaussianReal (hZ : HasLaw Z (gaussianReal 0 1) P) + (hV : HasLaw V rademacher P) : + ¬ ∃ m v, HasLaw (fun ω ↦ Z ω + V ω * Z ω) (gaussianReal m v) P := by + rintro ⟨m, v, hS⟩ + have h := measureReal_add_mul_eq_zero hZ hV + rw [show {ω | Z ω + V ω * Z ω = 0} = (fun ω ↦ Z ω + V ω * Z ω) ⁻¹' {0} from rfl, + measureReal_preimage_of_hasLaw hS (measurableSet_singleton _)] at h + by_cases hv : v = 0 + · subst hv + rw [gaussianReal_zero_var] at h + by_cases hm : m = 0 <;> simp [measureReal_def, hm] at h + · have := nullSingletonClass_gaussianReal (μ := m) hv + simp [measureReal_def] at h + +/-- **`(Z, V Z)` is not jointly Gaussian**, although both margins are standard normal: a jointly +Gaussian pair with zero covariance is independent +(`HasGaussianLaw.indepFun_of_covariance_eq_zero`), and `Z`, `V Z` are uncorrelated but +dependent. -/ +theorem not_hasGaussianLaw_prod (hZ : HasLaw Z (gaussianReal 0 1) P) (hV : HasLaw V rademacher P) + (hVZ : V ⟂ᵢ[P] Z) : ¬ HasGaussianLaw (fun ω ↦ (Z ω, V ω * Z ω)) P := fun h ↦ + not_indepFun_mul hZ hV <| h.indepFun_of_covariance_eq_zero (covariance_mul_eq_zero hZ hV hVZ) + +/-- **The correlation fallacy is realized**: there are two standard normal random variables that +are uncorrelated, not independent, not jointly Gaussian, and whose sum is not Gaussian. -/ +theorem exists_gaussian_uncorrelated_not_indepFun : + ∃ (Ω : Type) (_ : MeasurableSpace Ω) (P : Measure Ω) (Z Y : Ω → ℝ), + IsProbabilityMeasure P ∧ HasLaw Z (gaussianReal 0 1) P ∧ HasLaw Y (gaussianReal 0 1) P ∧ + cov[Z, Y; P] = 0 ∧ ¬ Z ⟂ᵢ[P] Y ∧ ¬ HasGaussianLaw (fun ω ↦ (Z ω, Y ω)) P ∧ + ¬ ∃ m v, HasLaw (fun ω ↦ Z ω + Y ω) (gaussianReal m v) P := by + have hV : HasLaw Prod.fst rademacher (rademacher.prod (gaussianReal 0 1)) := + ⟨measurable_fst.aemeasurable, by simp⟩ + have hZ : HasLaw Prod.snd (gaussianReal 0 1) (rademacher.prod (gaussianReal 0 1)) := + ⟨measurable_snd.aemeasurable, by simp⟩ + have hVZ : (Prod.fst : ℝ × ℝ → ℝ) ⟂ᵢ[rademacher.prod (gaussianReal 0 1)] Prod.snd := + indepFun_prod measurable_id measurable_id + exact ⟨ℝ × ℝ, inferInstance, rademacher.prod (gaussianReal 0 1), Prod.snd, fun ω ↦ ω.1 * ω.2, + inferInstance, hZ, + hasLaw_mul_gaussianReal hZ hV hVZ, covariance_mul_eq_zero hZ hV hVZ, not_indepFun_mul hZ hV, + not_hasGaussianLaw_prod hZ hV hVZ, not_hasLaw_add_mul_gaussianReal hZ hV⟩ + +end MathFin diff --git a/LeanPool/MathFin/Probability/Dependence/GaussianCopula.lean b/LeanPool/MathFin/Probability/Dependence/GaussianCopula.lean new file mode 100644 index 0000000000..56877b54bf --- /dev/null +++ b/LeanPool/MathFin/Probability/Dependence/GaussianCopula.lean @@ -0,0 +1,307 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Dependence.Sklar +public import LeanPool.MathFin.Probability.Gaussian.BivariateNormalCDF +public import Mathlib.Algebra.Order.Star.Real + +/-! +# The one-factor Gaussian copula + +The **one-factor Gaussian copula** on `n` names with factor loading `ρ ∈ [−1, 1]` is the copula of +the latent vector +`Xᵢ = ρ Z₀ + √(1 − ρ²) Zᵢ`, `i : Fin n`, +where the systematic factor `Z₀` and the idiosyncratic factors `Z₁, …, Zₙ` are independent standard +normals (`stdNormalFactors`). Every `Xᵢ` is standard normal (`map_gaussianFactorVec`), +`Cov(Xᵢ, Xⱼ) = ρ²` for `i ≠ j` (`covariance_gaussianFactorVec`), and each pair `(Xᵢ, Xⱼ)` has the +standard bivariate normal law with correlation `ρ²` (`map_pair_gaussianFactorVec`, through +`eq_bivariateNormalLaw`). Loadings `ρ` and `−ρ` give the same copula +(`gaussianFactorCopula_neg`), so the family is parametrized by the pairwise correlation `ρ²` +alone. The library's one-factor default model (`Risk/Credit/BernoulliMixture.lean`, +`VasicekIRB.lean`, `TrancheLoss.lean`) is written in that parameter, the asset correlation `ρ` of +`√ρ F + √(1 − ρ) εᵢ`; the probability that all its names default at a common default +probability `π` is this copula at loading `√ρ`, evaluated at `(π, …, π)` +(`Risk/Credit/OneFactorCopula.lean`). Name `i` defaults by time `t` when `Xᵢ ≤ Φ⁻¹(pᵢ(t))`. + +We take the factors as a point `(z₀, z) : ℝ × (Fin n → ℝ)` under the product of standard normal +laws, with the systematic factor in the first slot, so that every name is treated symmetrically. +(A common bivariate construction instead writes the pair as `(Z₁, ρ Z₁ + √(1 − ρ²) Z₂)`, with +correlation `ρ`; the symmetric model here has pairwise correlation `ρ²`, never negative.) + +The copula is defined via `copulaOf`, so being a copula is Sklar's theorem. + +## Main definitions + +* `stdNormalFactors`: the product of `n + 1` standard normal laws on `ℝ × (Fin n → ℝ)`, the + systematic factor `Z₀` in the first slot and the idiosyncratic factors in the second. +* `gaussianFactorVec`: the latent vector `Xᵢ = ρ z₀ + √(1 − ρ²) zᵢ`. +* `gaussianFactorCopula`: the copula of `gaussianFactorVec ρ` under `stdNormalFactors n`. + +## Main results + +* `gaussianFactorCopula`, `isCopula_gaussianFactorCopula`, `gaussianFactorCopula_real_Iic`. +* `covariance_gaussianFactorVec`, `map_pair_gaussianFactorVec`, `measureReal_gaussianFactorVec_le`: + pairwise covariance `ρ²`, bivariate normal pairs, and the pairwise joint distribution function + `P(Xᵢ ≤ a, Xⱼ ≤ b) = N₂(a, b; ρ²)`. +* `gaussianFactorCopula_neg`: loadings `ρ` and `−ρ` give the same copula. +* `gaussianFactorCopula_zero`: `ρ = 0` gives the independence copula `Π`. +* `gaussianFactorCopula_one`: `ρ = 1` gives the comonotonicity copula `M` (so does `ρ = −1`, by + `gaussianFactorCopula_neg`). + +The countermonotonicity copula `W` (`countermonotoneCopula`) is defined on `Fin 2` only (for `d ≥ 3` +the lower Fréchet bound is not a copula, `not_exists_isCopula_frechetLower`). Since the pairwise +correlations `ρ²` are nonnegative, `W` is not a member of this family; that is not stated as a +lemma. + +## References + +* [J. Hull and A. White, *Valuation of a CDO and an $n$-th to default CDS without Monte Carlo + simulation*][HullWhite2004] + +## Tags + +Gaussian copula, one-factor model, factor loading, asset correlation, default dependence, +latent variable, MSC 62H05, MSC 91G40, JEL G32 +-/ +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set + +variable {n : ℕ} {ρ : ℝ} + +/-- The law of the factors of the one-factor model: a systematic standard normal `Z₀` and `n` +idiosyncratic standard normals, all independent. -/ +noncomputable abbrev stdNormalFactors (n : ℕ) : Measure (ℝ × (Fin n → ℝ)) := + (gaussianReal 0 1).prod (stdNormalVec (Fin n)) + +/-- The **one-factor Gaussian latent vector** `Xᵢ = ρ z₀ + √(1 − ρ²) zᵢ`. -/ +noncomputable def gaussianFactorVec (ρ : ℝ) (z : ℝ × (Fin n → ℝ)) : Fin n → ℝ := + fun i ↦ ρ * z.1 + √(1 - ρ ^ 2) * z.2 i + +@[fun_prop] lemma measurable_gaussianFactorVec (ρ : ℝ) : + Measurable (gaussianFactorVec (n := n) ρ) := + measurable_pi_iff.2 fun i ↦ by unfold gaussianFactorVec; fun_prop + +/-- `(Z₀, Zᵢ)` is a pair of independent standard normals. -/ +lemma map_stdNormalFactors_pair (i : Fin n) : + (stdNormalFactors n).map (fun z ↦ (z.1, z.2 i)) = stdNormalPair := by + rw [show (fun z : ℝ × (Fin n → ℝ) ↦ (z.1, z.2 i)) = Prod.map id (fun w ↦ w i) from rfl, + ← Measure.map_prod_map _ _ measurable_id (measurable_pi_apply i), Measure.map_id, + (measurePreserving_eval (fun _ ↦ gaussianReal 0 1) i).map_eq] + +/-- For `ρ ∈ [−1, 1]` every coordinate of the latent vector is standard normal. -/ +lemma map_gaussianFactorVec (hρ : ρ ∈ Icc (-1) 1) (i : Fin n) : + (stdNormalFactors n).map (fun z ↦ gaussianFactorVec ρ z i) = gaussianReal 0 1 := by + rw [show (fun z ↦ gaussianFactorVec ρ z i) = + (fun p : ℝ × ℝ ↦ ρ * p.1 + √(1 - ρ ^ 2) * p.2) ∘ (fun z ↦ (z.1, z.2 i)) from rfl, + ← Measure.map_map (by fun_prop) (by fun_prop), map_stdNormalFactors_pair, + map_linear_stdNormalPair, Real.sq_sqrt (by nlinarith [hρ.1, hρ.2]), add_sub_cancel, + Real.toNNReal_one] + +/-- `Φ` pushes the standard normal law to the uniform law on `(0, 1)`. -/ +lemma map_Phi_gaussianReal : (gaussianReal 0 1).map Phi = volume.restrict (Ioo 0 1) := by + simpa [cdf_gaussianReal_zero_one] using (hasLaw_cdf (μ := gaussianReal 0 1) HasLaw.id + (by rw [cdf_gaussianReal_zero_one]; exact continuous_Phi)).map_eq + +/-! ### Moments and pairs of the latent vector -/ + +/-- The systematic factor is square integrable. -/ +private lemma memLp_fst_stdNormalFactors : + MemLp (fun z : ℝ × (Fin n → ℝ) ↦ z.1) 2 (stdNormalFactors n) := + (memLp_id_gaussianReal' 2 (by simp)).comp_fst _ + +/-- Each idiosyncratic factor is square integrable. -/ +private lemma memLp_snd_apply_stdNormalFactors (k : Fin n) : + MemLp (fun z : ℝ × (Fin n → ℝ) ↦ z.2 k) 2 (stdNormalFactors n) := + (memLp_eval_stdNormalVec k).comp_snd _ + +/-- Each latent coordinate is centred. -/ +lemma integral_gaussianFactorVec (hρ : ρ ∈ Icc (-1) 1) (i : Fin n) : + ∫ z, gaussianFactorVec ρ z i ∂stdNormalFactors n = 0 := by + have h := integral_id_gaussianReal (μ := 0) (v := 1) + rw [← map_gaussianFactorVec hρ i, integral_map (by fun_prop) (by fun_prop)] at h + exact h + +/-- Each latent coordinate has unit variance. -/ +lemma variance_gaussianFactorVec (hρ : ρ ∈ Icc (-1) 1) (i : Fin n) : + Var[fun z ↦ gaussianFactorVec ρ z i; stdNormalFactors n] = 1 := by + rw [← variance_id_map (by fun_prop), map_gaussianFactorVec hρ i, variance_id_gaussianReal, + NNReal.coe_one] + +/-- **Pairwise covariance `ρ²`**: for `i ≠ j`, `Cov(Xᵢ, Xⱼ) = ρ²`, for every `ρ`. Only the +systematic factor is shared: `Cov(Z₀, Z₀) = 1`, while `Z₀`, `Zᵢ`, `Zⱼ` are pairwise uncorrelated. -/ +theorem covariance_gaussianFactorVec (ρ : ℝ) {i j : Fin n} (hij : i ≠ j) : + cov[fun z ↦ gaussianFactorVec ρ z i, fun z ↦ gaussianFactorVec ρ z j; stdNormalFactors n] = + ρ ^ 2 := by + have h₀ := memLp_fst_stdNormalFactors (n := n) + have hA : MemLp (fun z : ℝ × (Fin n → ℝ) ↦ ρ * z.1) 2 (stdNormalFactors n) := h₀.const_mul ρ + have hB (k : Fin n) : + MemLp (fun z : ℝ × (Fin n → ℝ) ↦ √(1 - ρ ^ 2) * z.2 k) 2 (stdNormalFactors n) := + (memLp_snd_apply_stdNormalFactors k).const_mul _ + -- the covariances of the factors + have c00 : cov[fun z : ℝ × (Fin n → ℝ) ↦ z.1, fun z ↦ z.1; stdNormalFactors n] = 1 := by + rw [covariance_self h₀.aemeasurable] + have h := (measurePreserving_fst (μ := gaussianReal 0 1) + (ν := stdNormalVec (Fin n))).variance_fun_comp (f := id) aemeasurable_id + rw [variance_id_gaussianReal] at h + exact h.trans NNReal.coe_one + have c0 (k : Fin n) : cov[fun z : ℝ × (Fin n → ℝ) ↦ z.1, fun z ↦ z.2 k; stdNormalFactors n] = 0 := + covariance_fst_snd_prod (memLp_id_gaussianReal' 2 (by simp)) (memLp_eval_stdNormalVec k) + have ci0 : cov[fun z : ℝ × (Fin n → ℝ) ↦ z.2 i, fun z ↦ z.1; stdNormalFactors n] = 0 := by + rw [covariance_comm, c0 i] + have cij : cov[fun z : ℝ × (Fin n → ℝ) ↦ z.2 i, fun z ↦ z.2 j; stdNormalFactors n] = 0 := by + have hsnd : (stdNormalFactors n).map Prod.snd = stdNormalVec (Fin n) := by + rw [Measure.map_snd_prod, measure_univ, one_smul] + have h := covariance_map_fun (μ := stdNormalFactors n) (X := fun w : Fin n → ℝ ↦ w i) + (Y := fun w ↦ w j) (Z := Prod.snd) (measurable_pi_apply i).aestronglyMeasurable + (measurable_pi_apply j).aestronglyMeasurable measurable_snd.aemeasurable + rw [hsnd] at h + exact h.symm.trans <| ((iIndepFun_pi (μ := fun _ : Fin n ↦ gaussianReal 0 1) + (X := fun _ : Fin n ↦ (id : ℝ → ℝ)) fun _ ↦ aemeasurable_id).indepFun hij).covariance_eq_zero + (memLp_eval_stdNormalVec i) (memLp_eval_stdNormalVec j) + -- bilinearity + change cov[(fun z : ℝ × (Fin n → ℝ) ↦ ρ * z.1) + fun z ↦ √(1 - ρ ^ 2) * z.2 i, + (fun z : ℝ × (Fin n → ℝ) ↦ ρ * z.1) + fun z ↦ √(1 - ρ ^ 2) * z.2 j; stdNormalFactors n] = ρ ^ 2 + rw [covariance_add_left hA (hB i) (hA.add (hB j)), covariance_add_right hA hA (hB j), + covariance_add_right (hB i) hA (hB j)] + simp only [covariance_const_mul_left, covariance_const_mul_right] + linear_combination ρ ^ 2 * c00 + ρ * √(1 - ρ ^ 2) * c0 j + √(1 - ρ ^ 2) * ρ * ci0 + + √(1 - ρ ^ 2) ^ 2 * cij + +/-- The pair `(Xᵢ, Xⱼ)` as a continuous linear image of the factors. -/ +private noncomputable def gaussianFactorPairCLM (ρ : ℝ) (i j : Fin n) : + ℝ × (Fin n → ℝ) →L[ℝ] ℝ × ℝ := + (ρ • ContinuousLinearMap.fst ℝ ℝ (Fin n → ℝ) + √(1 - ρ ^ 2) • + (ContinuousLinearMap.proj (R := ℝ) (φ := fun _ : Fin n ↦ ℝ) i).comp + (ContinuousLinearMap.snd ℝ ℝ (Fin n → ℝ))).prod + (ρ • ContinuousLinearMap.fst ℝ ℝ (Fin n → ℝ) + √(1 - ρ ^ 2) • + (ContinuousLinearMap.proj (R := ℝ) (φ := fun _ : Fin n ↦ ℝ) j).comp + (ContinuousLinearMap.snd ℝ ℝ (Fin n → ℝ))) + +/-- **Each pair of latent coordinates is standard bivariate normal with correlation `ρ²`**: for +`ρ ∈ [−1, 1]` and `i ≠ j`, the law of `(Xᵢ, Xⱼ)` is `bivariateNormalLaw (ρ²)`. The pair is a +continuous linear image of the Gaussian factors, hence Gaussian, with centred unit-variance +coordinates and covariance `ρ²` (`covariance_gaussianFactorVec`); `eq_bivariateNormalLaw` +identifies it. -/ +theorem map_pair_gaussianFactorVec (hρ : ρ ∈ Icc (-1) 1) {i j : Fin n} (hij : i ≠ j) : + (stdNormalFactors n).map (fun z ↦ (gaussianFactorVec ρ z i, gaussianFactorVec ρ z j)) = + bivariateNormalLaw (ρ ^ 2) := by + have hpair : ⇑(gaussianFactorPairCLM ρ i j) = + fun z ↦ (gaussianFactorVec ρ z i, gaussianFactorVec ρ z j) := by + funext z + simp [gaussianFactorPairCLM, gaussianFactorVec] + have : IsGaussian ((stdNormalFactors n).map + fun z ↦ (gaussianFactorVec ρ z i, gaussianFactorVec ρ z j)) := by + have h : IsGaussian ((stdNormalFactors n).map (gaussianFactorPairCLM ρ i j)) := inferInstance + rwa [hpair] at h + have hm : Measurable fun z : ℝ × (Fin n → ℝ) ↦ + (gaussianFactorVec ρ z i, gaussianFactorVec ρ z j) := by + fun_prop + have hρ2 : ρ ^ 2 ≤ 1 := by nlinarith [hρ.1, hρ.2] + refine eq_bivariateNormalLaw (by nlinarith [hρ2, sq_nonneg ρ]) ?_ ?_ ?_ ?_ ?_ + · rw [integral_map hm.aemeasurable measurable_fst.aestronglyMeasurable] + exact integral_gaussianFactorVec hρ i + · rw [integral_map hm.aemeasurable measurable_snd.aestronglyMeasurable] + exact integral_gaussianFactorVec hρ j + · rw [variance_map measurable_fst.aemeasurable hm.aemeasurable] + exact variance_gaussianFactorVec hρ i + · rw [variance_map measurable_snd.aemeasurable hm.aemeasurable] + exact variance_gaussianFactorVec hρ j + · rw [covariance_map_fun measurable_fst.aestronglyMeasurable measurable_snd.aestronglyMeasurable + hm.aemeasurable] + exact covariance_gaussianFactorVec ρ hij + +/-- **Pairwise joint distribution function**: for `ρ ∈ [−1, 1]` and `i ≠ j`, +`P(Xᵢ ≤ a, Xⱼ ≤ b) = N₂(a, b; ρ²)`. -/ +theorem measureReal_gaussianFactorVec_le (hρ : ρ ∈ Icc (-1) 1) {i j : Fin n} (hij : i ≠ j) + (a b : ℝ) : + (stdNormalFactors n).real {z | gaussianFactorVec ρ z i ≤ a ∧ gaussianFactorVec ρ z j ≤ b} = + bivariateNormalCDF a b (ρ ^ 2) := by + rw [bivariateNormalCDF_eq_law, ← map_pair_gaussianFactorVec hρ hij, + map_measureReal_apply (by fun_prop) (measurableSet_Iic.prod measurableSet_Iic)] + rfl + +/-! ### The copula -/ + +/-- The **one-factor Gaussian copula** on `n` names with loading `ρ`: the copula of +`gaussianFactorVec ρ`. It is a copula for `ρ ∈ [−1, 1]` (`isCopula_gaussianFactorCopula`). -/ +noncomputable def gaussianFactorCopula (n : ℕ) (ρ : ℝ) : Measure (Fin n → ℝ) := + copulaOf (gaussianFactorVec ρ) (stdNormalFactors n) + +/-- Each marginal CDF of the latent vector is `Φ`, hence continuous — the hypothesis Sklar's +theorem needs. -/ +lemma continuous_cdf_gaussianFactorVec (hρ : ρ ∈ Icc (-1) 1) (i : Fin n) : + Continuous (cdf ((stdNormalFactors n).map fun z ↦ gaussianFactorVec ρ z i)) := by + rw [map_gaussianFactorVec hρ, cdf_gaussianReal_zero_one] + exact continuous_Phi + +/-- For `ρ ∈ [−1, 1]` the copula is the law of `(Φ(X₁), …, Φ(Xₙ))`. -/ +lemma gaussianFactorCopula_eq_map (hρ : ρ ∈ Icc (-1) 1) : + gaussianFactorCopula n ρ = + (stdNormalFactors n).map fun z i ↦ Phi (gaussianFactorVec ρ z i) := by + simp only [gaussianFactorCopula, copulaOf, map_gaussianFactorVec hρ, cdf_gaussianReal_zero_one] + +/-- **The one-factor Gaussian copula is a copula** for every `ρ ∈ [−1, 1]`. -/ +theorem isCopula_gaussianFactorCopula (hρ : ρ ∈ Icc (-1) 1) : IsCopula (gaussianFactorCopula n ρ) := + isCopula_copulaOf (measurable_gaussianFactorVec ρ).aemeasurable + (continuous_cdf_gaussianFactorVec hρ) + +/-- **Distribution function**: on `(0, 1)ⁿ`, `C(u) = P(Xᵢ ≤ Φ⁻¹(uᵢ) for all i)`. -/ +theorem gaussianFactorCopula_real_Iic (hρ : ρ ∈ Icc (-1) 1) (u : Fin n → ℝ) + (hu : ∀ i, u i ∈ Ioo 0 1) : + (gaussianFactorCopula n ρ).real (Iic u) = + (stdNormalFactors n).real {z | gaussianFactorVec ρ z ≤ fun i ↦ PhiInv (u i)} := by + rw [measureReal_le_eq_copulaOf (measurable_gaussianFactorVec ρ).aemeasurable + (continuous_cdf_gaussianFactorVec hρ)] + simp only [map_gaussianFactorVec hρ, cdf_gaussianReal_zero_one] + rw [show (fun i ↦ Phi (PhiInv (u i))) = u from funext fun i ↦ Phi_PhiInv (hu i)] + rfl + +/-! ### The independence and comonotone members -/ + +/-- **`ρ = 0` gives the independence copula** `Π`. -/ +theorem gaussianFactorCopula_zero : gaussianFactorCopula n 0 = independenceCopula (Fin n) := by + have hf : (fun z : ℝ × (Fin n → ℝ) ↦ fun i ↦ Phi (gaussianFactorVec 0 z i)) = + (fun w i ↦ Phi (w i)) ∘ Prod.snd := by + ext z i; simp [gaussianFactorVec] + rw [gaussianFactorCopula_eq_map (by norm_num), hf, + ← Measure.map_map (by fun_prop) measurable_snd, Measure.map_snd_prod, measure_univ, one_smul, + Measure.pi_map_pi (fun _ ↦ measurable_Phi.aemeasurable)] + simp [map_Phi_gaussianReal, independenceCopula] + +/-- **`ρ = 1` gives the comonotonicity copula** `M`: every name loads only on `Z₀`. -/ +theorem gaussianFactorCopula_one : gaussianFactorCopula n 1 = comonotoneCopula (Fin n) := by + have hf : (fun z : ℝ × (Fin n → ℝ) ↦ fun i ↦ Phi (gaussianFactorVec 1 z i)) = + (fun t _ ↦ t) ∘ Phi ∘ Prod.fst := by + ext z i; simp [gaussianFactorVec] + rw [gaussianFactorCopula_eq_map (by norm_num), hf, + ← Measure.map_map (by fun_prop) (measurable_Phi.comp measurable_fst), + ← Measure.map_map measurable_Phi measurable_fst, Measure.map_fst_prod, measure_univ, one_smul] + simp [map_Phi_gaussianReal, comonotoneCopula] + +/-- **The copula sees the loading only through `ρ²`**: loadings `ρ` and `−ρ` give the same copula. +Negating the systematic factor preserves its law and turns one latent vector into the other. -/ +theorem gaussianFactorCopula_neg (hρ : ρ ∈ Icc (-1) 1) : + gaussianFactorCopula n (-ρ) = gaussianFactorCopula n ρ := by + have hρ' : -ρ ∈ Icc (-1) 1 := ⟨by linarith [hρ.2], by linarith [hρ.1]⟩ + have hN : (stdNormalFactors n).map (fun z : ℝ × (Fin n → ℝ) ↦ (-z.1, z.2)) = + stdNormalFactors n := by + rw [show (fun z : ℝ × (Fin n → ℝ) ↦ (-z.1, z.2)) = Prod.map (fun x : ℝ ↦ -x) id from rfl, + ← Measure.map_prod_map _ _ (by fun_prop) measurable_id, gaussianReal_map_neg, neg_zero, + Measure.map_id] + have hf : (fun z : ℝ × (Fin n → ℝ) ↦ fun i ↦ Phi (gaussianFactorVec (-ρ) z i)) = + (fun z i ↦ Phi (gaussianFactorVec ρ z i)) ∘ fun z ↦ (-z.1, z.2) := by + ext z i + simp [gaussianFactorVec] + rw [gaussianFactorCopula_eq_map hρ', gaussianFactorCopula_eq_map hρ, hf, + ← Measure.map_map (by fun_prop) (by fun_prop), hN] + +end MathFin diff --git a/LeanPool/MathFin/Probability/Dependence/HoeffdingCovariance.lean b/LeanPool/MathFin/Probability/Dependence/HoeffdingCovariance.lean new file mode 100644 index 0000000000..72ecbac5a0 --- /dev/null +++ b/LeanPool/MathFin/Probability/Dependence/HoeffdingCovariance.lean @@ -0,0 +1,458 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Gaussian.BivariateNormalCDF +public import Mathlib.Algebra.Order.Star.Real + +/-! +# Hoeffding's covariance identity + +For square-integrable random variables `X, Y` on a probability space, the covariance is the +integral over the plane of the gap between the joint CDF and the product of the marginal CDFs: + + `cov(X, Y) = ∫∫ (P(X ≤ s, Y ≤ t) − P(X ≤ s) P(Y ≤ t)) ds dt` + +(`covariance_eq_integral_cdf`; Hoeffding 1940, Höffding's lemma in McNeil–Frey–Embrechts (2015), +Chapter 7). + +The proof writes each real number as the integral of its signed layer, +`a = ∫ (𝟙{s < a} − 𝟙{s < 0}) ds`, so that `X Y`, `E[X]` and `E[Y]` become integrals over the plane +of indicator expressions. Fubini swaps the expectation inside, and at each point `(s, t)` the +constants `𝟙{s < 0}`, `𝟙{t < 0}` cancel from the covariance of the indicators +`𝟙{X > s}` and `𝟙{Y > t}`. That covariance equals `P(X ≤ s, Y ≤ t) − P(X ≤ s) P(Y ≤ t)` by +inclusion–exclusion. The identity is stated for the law of `(X, Y)` on `ℝ²` +(`covariance_fst_snd_eq_integral`) and transported to random variables through their joint law. + +## Consequences + +* **Covariance is monotone in the joint CDF** (`covariance_le_covariance_of_cdf_le`; QRM Exercise + Book Ex. 7.14). Two pairs with the same marginal laws whose joint CDFs are pointwise ordered have + ordered covariances, and so ordered correlations. The marginals fix the subtracted term and the + variances, and the joint CDF enters linearly. Combined with the Fréchet–Hoeffding bounds on joint + CDFs (proved for copulas in `Probability/Dependence/Copula.lean`), this is the mechanism by which + comonotone + (resp. countermonotone) dependence attains the largest (resp. smallest) correlation for given + marginals (MFE (2015) Theorem 7.28). +* **Default-correlation bounds** (`le_covariance_indicator_one`, `covariance_indicator_one_le`; + Ex. 11.7). For default indicators of events with probabilities `p₁, p₂`, the covariance lies + between `max(p₁ + p₂ − 1, 0) − p₁p₂` and `min(p₁, p₂) − p₁p₂`: these are the Fréchet bounds on + `P(A ∩ B)`. The bounds are attained by nested events and by events whose union is certain. The + correlation bounds follow by dividing by `√(p₁(1 − p₁)p₂(1 − p₂))`. + +## Main results + +* `covariance_indicator_one`: `cov(𝟙_A, 𝟙_B) = P(A ∩ B) − P(A) P(B)`. +* `integral_bivariateNormalCDF_sub_mul`: at the standard bivariate normal law with correlation + `r ∈ [−1, 1]`, `∫∫ (N₂(s, t; r) − Φ(s) Φ(t)) ds dt = r`. +* `covariance_fst_snd_eq_integral`: Hoeffding's identity for a law on `ℝ²`. +* `covariance_eq_integral_cdf`: Hoeffding's identity for random variables. +* `integrable_cdf_sub_mul`: the Hoeffding integrand is integrable on `ℝ²`. +* `covariance_le_covariance_of_cdf_le`, `correlation_le_correlation_of_cdf_le`: ordering. +* `variance_indicator_one`, `covariance_indicator_one_le`, `le_covariance_indicator_one`, + `covariance_indicator_one_of_subset`, `covariance_indicator_one_of_union_eq_univ`, + `correlation_indicator_one_le`, `le_correlation_indicator_one`: default-correlation bounds. + +## References + +* [Höffding (1940)][Hoeffding1940] +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Lemma 7.27 +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 11.7; Ex. 7.14 + +## Tags + +Hoeffding covariance identity, Fréchet–Hoeffding bounds, joint distribution function, +comonotonicity, default correlation, correlation bounds, dependence, MSC 62H05, MSC 60E15, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set Function + +/-! ### Covariance of indicators -/ + +section Indicator + +variable {α : Type*} {mα : MeasurableSpace α} {μ : Measure α} [IsProbabilityMeasure μ] + {A B : Set α} + +/-- An indicator is square integrable. -/ +lemma memLp_indicator_one (hA : MeasurableSet A) : MemLp (A.indicator (1 : α → ℝ)) 2 μ := + memLp_indicator_const 2 hA.nullMeasurableSet 1 (Or.inr (measure_ne_top _ _)) + +/-- **Covariance of two indicators**: `cov(𝟙_A, 𝟙_B) = P(A ∩ B) − P(A) P(B)`. -/ +theorem covariance_indicator_one (hA : MeasurableSet A) (hB : MeasurableSet B) : + cov[A.indicator 1, B.indicator 1; μ] = μ.real (A ∩ B) - μ.real A * μ.real B := by + rw [covariance_eq_sub (memLp_indicator_one hA) (memLp_indicator_one hB), ← inter_indicator_one, + integral_indicator_one (hA.inter hB), integral_indicator_one hA, integral_indicator_one hB] + +/-- Shifting indicators by constants does not change their covariance: +`E[(𝟙_A − c)(𝟙_B − d)] − E[𝟙_A − c] E[𝟙_B − d] = P(A ∩ B) − P(A) P(B)`. -/ +lemma integral_indicator_sub_mul_sub (hA : MeasurableSet A) (hB : MeasurableSet B) (c d : ℝ) : + ∫ x, (A.indicator 1 x - c) * (B.indicator 1 x - d) ∂μ + - (∫ x, (A.indicator 1 x - c) ∂μ) * ∫ x, (B.indicator 1 x - d) ∂μ + = μ.real (A ∩ B) - μ.real A * μ.real B := by + have hf : MemLp (fun x ↦ A.indicator 1 x - c) 2 μ := (memLp_indicator_one hA).sub (memLp_const c) + have hg : MemLp (fun x ↦ B.indicator 1 x - d) 2 μ := (memLp_indicator_one hB).sub (memLp_const d) + rw [← covariance_indicator_one hA hB, + ← covariance_sub_const_left ((memLp_indicator_one hA).integrable one_le_two) c, + ← covariance_sub_const_right ((memLp_indicator_one hB).integrable one_le_two) d] + exact (covariance_eq_sub hf hg).symm + +/-- **Variance of an indicator**: `Var(𝟙_A) = P(A) (1 − P(A))`. -/ +theorem variance_indicator_one (hA : MeasurableSet A) : + Var[A.indicator 1; μ] = μ.real A * (1 - μ.real A) := by + rw [← covariance_self (memLp_indicator_one hA).aemeasurable, + covariance_indicator_one hA hA, inter_self] + ring + +/-- Inclusion–exclusion leaves `P(A ∩ B) − P(A) P(B)` unchanged under complementing both events. -/ +lemma measureReal_inter_sub_mul_compl (hA : MeasurableSet A) (hB : MeasurableSet B) : + μ.real (Aᶜ ∩ Bᶜ) - μ.real Aᶜ * μ.real Bᶜ = μ.real (A ∩ B) - μ.real A * μ.real B := by + have h := measureReal_union_add_inter (μ := μ) (s := A) hB + rw [← compl_union, probReal_compl_eq_one_sub (hA.union hB), probReal_compl_eq_one_sub hA, + probReal_compl_eq_one_sub hB] + linarith + +/-! ### Default-correlation bounds -/ + +/-- **Upper Fréchet bound for default covariance**: +`cov(𝟙_A, 𝟙_B) ≤ min(P(A), P(B)) − P(A) P(B)`. -/ +theorem covariance_indicator_one_le (hA : MeasurableSet A) (hB : MeasurableSet B) : + cov[A.indicator 1, B.indicator 1; μ] ≤ min (μ.real A) (μ.real B) - μ.real A * μ.real B := by + rw [covariance_indicator_one hA hB] + gcongr + exact le_min (measureReal_mono inter_subset_left) (measureReal_mono inter_subset_right) + +/-- **Lower Fréchet bound for default covariance**: +`max(P(A) + P(B) − 1, 0) − P(A) P(B) ≤ cov(𝟙_A, 𝟙_B)`. -/ +theorem le_covariance_indicator_one (hA : MeasurableSet A) (hB : MeasurableSet B) : + max (μ.real A + μ.real B - 1) 0 - μ.real A * μ.real B + ≤ cov[A.indicator 1, B.indicator 1; μ] := by + rw [covariance_indicator_one hA hB] + gcongr + refine max_le ?_ measureReal_nonneg + have h := measureReal_union_add_inter (μ := μ) (s := A) hB + have h1 : μ.real (A ∪ B) ≤ 1 := measureReal_le_one + linarith + +/-- The upper bound is attained by nested events: if `A ⊆ B` then +`cov(𝟙_A, 𝟙_B) = min(P(A), P(B)) − P(A) P(B)`. -/ +theorem covariance_indicator_one_of_subset (hA : MeasurableSet A) (hB : MeasurableSet B) + (hAB : A ⊆ B) : + cov[A.indicator 1, B.indicator 1; μ] = min (μ.real A) (μ.real B) - μ.real A * μ.real B := by + rw [covariance_indicator_one hA hB, inter_eq_left.2 hAB, min_eq_left (measureReal_mono hAB)] + +/-- The lower bound is attained when the union is certain: if `A ∪ B = univ` then +`cov(𝟙_A, 𝟙_B) = max(P(A) + P(B) − 1, 0) − P(A) P(B)`. -/ +theorem covariance_indicator_one_of_union_eq_univ (hA : MeasurableSet A) (hB : MeasurableSet B) + (hAB : A ∪ B = univ) : + cov[A.indicator 1, B.indicator 1; μ] + = max (μ.real A + μ.real B - 1) 0 - μ.real A * μ.real B := by + have h := measureReal_union_add_inter (μ := μ) (s := A) hB + have h0 : 0 ≤ μ.real (A ∩ B) := measureReal_nonneg + rw [hAB, probReal_univ] at h + rw [covariance_indicator_one hA hB, max_eq_left (by linarith)] + linarith + +/-- **Upper bound on default correlation** (QRM Exercise Book Ex. 11.7): +`ρ(𝟙_A, 𝟙_B) ≤ (min(p₁, p₂) − p₁p₂) / √(p₁(1 − p₁)p₂(1 − p₂))`. -/ +theorem correlation_indicator_one_le (hA : MeasurableSet A) (hB : MeasurableSet B) : + cov[A.indicator 1, B.indicator 1; μ] / √(Var[A.indicator 1; μ] * Var[B.indicator 1; μ]) + ≤ (min (μ.real A) (μ.real B) - μ.real A * μ.real B) + / √(μ.real A * (1 - μ.real A) * (μ.real B * (1 - μ.real B))) := by + rw [variance_indicator_one hA, variance_indicator_one hB] + gcongr + exact covariance_indicator_one_le hA hB + +/-- **Lower bound on default correlation** (QRM Exercise Book Ex. 11.7): +`(max(p₁ + p₂ − 1, 0) − p₁p₂) / √(p₁(1 − p₁)p₂(1 − p₂)) ≤ ρ(𝟙_A, 𝟙_B)`. -/ +theorem le_correlation_indicator_one (hA : MeasurableSet A) (hB : MeasurableSet B) : + (max (μ.real A + μ.real B - 1) 0 - μ.real A * μ.real B) + / √(μ.real A * (1 - μ.real A) * (μ.real B * (1 - μ.real B))) + ≤ cov[A.indicator 1, B.indicator 1; μ] + / √(Var[A.indicator 1; μ] * Var[B.indicator 1; μ]) := by + rw [variance_indicator_one hA, variance_indicator_one hB] + gcongr + exact le_covariance_indicator_one hA hB + +end Indicator + +/-! ### The signed layer of a real number -/ + +/-- `𝟙{s < a} − 𝟙{s < 0}`, the signed indicator of the interval between `0` and `a`. -/ +private noncomputable def layer (a s : ℝ) : ℝ := + (Iio a).indicator 1 s - (Iio 0).indicator 1 s + +private lemma layer_eq (a s : ℝ) : + layer a s = (Ico 0 a).indicator 1 s - (Ico a 0).indicator 1 s := by + rcases lt_or_ge s 0 with h0 | h0 <;> rcases lt_or_ge s a with ha | ha + · simp [layer, h0, ha, h0.not_ge, ha.not_ge] + · simp [layer, h0, ha, h0.not_ge, ha.not_gt] + · simp [layer, h0, ha, h0.not_gt, ha.not_ge] + · simp [layer, h0, ha, h0.not_gt, ha.not_gt] + +private lemma abs_layer (a s : ℝ) : + |layer a s| = (Ico 0 a).indicator 1 s + (Ico a 0).indicator 1 s := by + rcases lt_or_ge s 0 with h0 | h0 <;> rcases lt_or_ge s a with ha | ha + · simp [layer, h0, ha, h0.not_ge, ha.not_ge] + · simp [layer, h0, ha, h0.not_ge, ha.not_gt] + · simp [layer, h0, ha, h0.not_gt, ha.not_ge] + · simp [layer, h0, ha, h0.not_gt, ha.not_gt] + +/-- The indicator of a bounded interval `[a, b)` is integrable. -/ +lemma integrable_indicator_Ico (a b : ℝ) : + Integrable ((Ico a b).indicator (1 : ℝ → ℝ)) := + (integrableOn_const (by simp)).integrable_indicator measurableSet_Ico + +private lemma integrable_layer (a : ℝ) : Integrable (layer a) := by + rw [show layer a = (Ico 0 a).indicator 1 - (Ico a 0).indicator 1 from funext (layer_eq a)] + exact (integrable_indicator_Ico 0 a).sub (integrable_indicator_Ico a 0) + +/-- The signed layer integrates to its endpoint: `∫ (𝟙{s < a} − 𝟙{s < 0}) ds = a`. -/ +private lemma integral_layer (a : ℝ) : ∫ s, layer a s = a := by + simp_rw [layer_eq] + rw [integral_sub (integrable_indicator_Ico 0 a) (integrable_indicator_Ico a 0), + integral_indicator_one measurableSet_Ico, integral_indicator_one measurableSet_Ico, + Real.volume_real_Ico, Real.volume_real_Ico] + rcases le_total 0 a with h | h <;> simp [h] + +private lemma integral_abs_layer (a : ℝ) : ∫ s, |layer a s| = |a| := by + simp_rw [abs_layer] + rw [integral_add (integrable_indicator_Ico 0 a) (integrable_indicator_Ico a 0), + integral_indicator_one measurableSet_Ico, integral_indicator_one measurableSet_Ico, + Real.volume_real_Ico, Real.volume_real_Ico] + rcases le_total 0 a with h | h <;> simp [h, abs_of_nonneg, abs_of_nonpos] + +private lemma measurable_layer : Measurable (uncurry layer) := + (measurable_const.indicator (measurableSet_lt measurable_snd measurable_fst)).sub + (measurable_const.indicator (measurableSet_Iio.preimage measurable_snd)) + +/-! ### Hoeffding's identity for a law on the plane -/ + +section Plane + +variable {μ : Measure (ℝ × ℝ)} [IsProbabilityMeasure μ] + +omit [IsProbabilityMeasure μ] in +/-- `(x, s) ↦ layer (f x) s` is integrable against `μ ⊗ ds` when `f` is integrable. -/ +private lemma integrable_layer_comp {f : ℝ × ℝ → ℝ} (hf : Measurable f) (hint : Integrable f μ) : + Integrable (uncurry fun (x : ℝ × ℝ) s ↦ layer (f x) s) (μ.prod volume) := by + have hmeas : Measurable (uncurry fun (x : ℝ × ℝ) s ↦ layer (f x) s) := + measurable_layer.comp ((hf.comp measurable_fst).prodMk measurable_snd) + refine (integrable_prod_iff hmeas.aestronglyMeasurable).2 + ⟨ae_of_all _ fun x ↦ integrable_layer (f x), ?_⟩ + simpa only [uncurry_apply_pair, Real.norm_eq_abs, integral_abs_layer] using hint.abs + +omit [IsProbabilityMeasure μ] in +/-- `(x, (s, t)) ↦ layer x.1 s · layer x.2 t` is integrable against `μ ⊗ ds dt` when the +coordinates are square integrable: its inner integral is `|x.1 x.2|`. -/ +private lemma integrable_layer_mul (h₁ : MemLp Prod.fst 2 μ) (h₂ : MemLp Prod.snd 2 μ) : + Integrable (uncurry fun (x p : ℝ × ℝ) ↦ layer x.1 p.1 * layer x.2 p.2) (μ.prod volume) := by + have hmeas : Measurable (uncurry fun (x p : ℝ × ℝ) ↦ layer x.1 p.1 * layer x.2 p.2) := + (measurable_layer.comp (measurable_fst.fst.prodMk measurable_snd.fst)).mul + (measurable_layer.comp (measurable_fst.snd.prodMk measurable_snd.snd)) + refine (integrable_prod_iff hmeas.aestronglyMeasurable).2 ⟨ae_of_all _ fun x ↦ ?_, ?_⟩ + · rw [Measure.volume_eq_prod] + exact (integrable_layer x.1).mul_prod (integrable_layer x.2) + · have hnorm (x : ℝ × ℝ) : + ∫ p, ‖uncurry (fun (x p : ℝ × ℝ) ↦ layer x.1 p.1 * layer x.2 p.2) (x, p)‖ + = |x.1 * x.2| := by + simp only [uncurry_apply_pair, norm_mul, Real.norm_eq_abs] + rw [Measure.volume_eq_prod, + integral_prod_mul (fun s ↦ |layer x.1 s|) (fun t ↦ |layer x.2 t|), integral_abs_layer, + integral_abs_layer, abs_mul] + simp_rw [hnorm] + exact (h₁.integrable_mul h₂).abs + +/-- At each point of the plane, the covariance of the two layers is the Hoeffding integrand. -/ +private lemma integral_layer_mul_sub (p : ℝ × ℝ) : + ∫ x, layer x.1 p.1 * layer x.2 p.2 ∂μ - (∫ x, layer x.1 p.1 ∂μ) * ∫ x, layer x.2 p.2 ∂μ + = μ.real (Iic p) - μ.real (Prod.fst ⁻¹' Iic p.1) * μ.real (Prod.snd ⁻¹' Iic p.2) := by + have hA : MeasurableSet (Prod.fst ⁻¹' Ioi p.1 : Set (ℝ × ℝ)) := + measurableSet_Ioi.preimage measurable_fst + have hB : MeasurableSet (Prod.snd ⁻¹' Ioi p.2 : Set (ℝ × ℝ)) := + measurableSet_Ioi.preimage measurable_snd + have h1 (x : ℝ × ℝ) : + layer x.1 p.1 = (Prod.fst ⁻¹' Ioi p.1).indicator 1 x - (Iio 0).indicator 1 p.1 := rfl + have h2 (x : ℝ × ℝ) : + layer x.2 p.2 = (Prod.snd ⁻¹' Ioi p.2).indicator 1 x - (Iio 0).indicator 1 p.2 := rfl + simp_rw [h1, h2] + rw [integral_indicator_sub_mul_sub hA hB, ← measureReal_inter_sub_mul_compl hA hB, + ← preimage_compl, ← preimage_compl, compl_Ioi, compl_Ioi] + rfl + +/-- **Hoeffding's covariance identity for a law on `ℝ²`**: if the coordinates are square +integrable under `μ`, then `cov_μ(x₁, x₂) = ∫ (F(p) − F₁(p₁) F₂(p₂)) dp`, with `F` the joint +CDF and `F₁`, `F₂` the marginal CDFs. The integrand is integrable +(`integrable_cdf_sub_mul_fst_snd`). -/ +theorem covariance_fst_snd_eq_integral (h₁ : MemLp Prod.fst 2 μ) (h₂ : MemLp Prod.snd 2 μ) : + cov[Prod.fst, Prod.snd; μ] = ∫ p : ℝ × ℝ, + (μ.real (Iic p) - μ.real (Prod.fst ⁻¹' Iic p.1) * μ.real (Prod.snd ⁻¹' Iic p.2)) := by + have hF := integrable_layer_mul h₁ h₂ + have hG₁ := integrable_layer_comp measurable_fst (h₁.integrable one_le_two) + have hG₂ := integrable_layer_comp measurable_snd (h₂.integrable one_le_two) + have hXY : ∫ x : ℝ × ℝ, x.1 * x.2 ∂μ + = ∫ p : ℝ × ℝ, ∫ x, layer x.1 p.1 * layer x.2 p.2 ∂μ := by + rw [← integral_integral_swap hF] + refine integral_congr_ae (ae_of_all _ fun x ↦ ?_) + dsimp only + rw [Measure.volume_eq_prod, integral_prod_mul (layer x.1) (layer x.2), integral_layer, + integral_layer] + have hX : ∫ x : ℝ × ℝ, x.1 ∂μ = ∫ s, ∫ x, layer x.1 s ∂μ := by + rw [← integral_integral_swap hG₁] + exact integral_congr_ae (ae_of_all _ fun x ↦ (integral_layer x.1).symm) + have hY : ∫ x : ℝ × ℝ, x.2 ∂μ = ∫ t, ∫ x, layer x.2 t ∂μ := by + rw [← integral_integral_swap hG₂] + exact integral_congr_ae (ae_of_all _ fun x ↦ (integral_layer x.2).symm) + have hint : Integrable fun p : ℝ × ℝ ↦ ∫ x, layer x.1 p.1 * layer x.2 p.2 ∂μ := + hF.integral_prod_right + have hprod : Integrable (fun p : ℝ × ℝ ↦ (∫ x, layer x.1 p.1 ∂μ) * ∫ x, layer x.2 p.2 ∂μ) := by + rw [Measure.volume_eq_prod] + exact hG₁.integral_prod_right.mul_prod hG₂.integral_prod_right + calc cov[Prod.fst, Prod.snd; μ] + = (∫ x : ℝ × ℝ, x.1 * x.2 ∂μ) - (∫ x : ℝ × ℝ, x.1 ∂μ) * ∫ x : ℝ × ℝ, x.2 ∂μ := + covariance_eq_sub h₁ h₂ + _ = (∫ p : ℝ × ℝ, ∫ x, layer x.1 p.1 * layer x.2 p.2 ∂μ) + - ∫ p : ℝ × ℝ, (∫ x, layer x.1 p.1 ∂μ) * ∫ x, layer x.2 p.2 ∂μ := by + rw [hXY, hX, hY, Measure.volume_eq_prod, + integral_prod_mul (fun s ↦ ∫ x, layer x.1 s ∂μ) (fun t ↦ ∫ x, layer x.2 t ∂μ)] + _ = ∫ p : ℝ × ℝ, (∫ x, layer x.1 p.1 * layer x.2 p.2 ∂μ + - (∫ x, layer x.1 p.1 ∂μ) * ∫ x, layer x.2 p.2 ∂μ) := (integral_sub hint hprod).symm + _ = _ := integral_congr_ae (ae_of_all _ integral_layer_mul_sub) + +/-- The Hoeffding integrand of a law on `ℝ²` with square-integrable coordinates is integrable. -/ +theorem integrable_cdf_sub_mul_fst_snd (h₁ : MemLp Prod.fst 2 μ) (h₂ : MemLp Prod.snd 2 μ) : + Integrable fun p : ℝ × ℝ ↦ + μ.real (Iic p) - μ.real (Prod.fst ⁻¹' Iic p.1) * μ.real (Prod.snd ⁻¹' Iic p.2) := by + have hint : Integrable fun p : ℝ × ℝ ↦ ∫ x, layer x.1 p.1 * layer x.2 p.2 ∂μ := + (integrable_layer_mul h₁ h₂).integral_prod_right + have hprod : Integrable (fun p : ℝ × ℝ ↦ (∫ x, layer x.1 p.1 ∂μ) * ∫ x, layer x.2 p.2 ∂μ) := by + rw [Measure.volume_eq_prod] + exact (integrable_layer_comp measurable_fst + (h₁.integrable one_le_two)).integral_prod_right.mul_prod + (integrable_layer_comp measurable_snd (h₂.integrable one_le_two)).integral_prod_right + exact (hint.sub hprod).congr (ae_of_all _ integral_layer_mul_sub) + +end Plane + +/-! ### Hoeffding's identity for random variables -/ + +section RandomVariables + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + {X Y : Ω → ℝ} + +omit [IsProbabilityMeasure P] in +/-- Square integrability of `X` and `Y` transfers to the coordinates of their joint law. -/ +lemma memLp_fst_snd_map (hX : MemLp X 2 P) (hY : MemLp Y 2 P) : + MemLp Prod.fst 2 (P.map fun ω ↦ (X ω, Y ω)) ∧ MemLp Prod.snd 2 (P.map fun ω ↦ (X ω, Y ω)) := + have hZ := hX.aemeasurable.prodMk hY.aemeasurable + ⟨(memLp_map_measure_iff measurable_fst.aestronglyMeasurable hZ).2 hX, + (memLp_map_measure_iff measurable_snd.aestronglyMeasurable hZ).2 hY⟩ + +omit [IsProbabilityMeasure P] in +/-- The Hoeffding integrand of the joint law of `(X, Y)`, written in terms of `X` and `Y`. -/ +lemma cdf_sub_mul_map (hX : AEMeasurable X P) (hY : AEMeasurable Y P) (p : ℝ × ℝ) : + (P.map fun ω ↦ (X ω, Y ω)).real (Iic p) + - (P.map fun ω ↦ (X ω, Y ω)).real (Prod.fst ⁻¹' Iic p.1) + * (P.map fun ω ↦ (X ω, Y ω)).real (Prod.snd ⁻¹' Iic p.2) + = P.real {ω | X ω ≤ p.1 ∧ Y ω ≤ p.2} + - P.real {ω | X ω ≤ p.1} * P.real {ω | Y ω ≤ p.2} := by + have hZ := hX.prodMk hY + rw [map_measureReal_apply_of_aemeasurable hZ measurableSet_Iic, + map_measureReal_apply_of_aemeasurable hZ (measurableSet_Iic.preimage measurable_fst), + map_measureReal_apply_of_aemeasurable hZ (measurableSet_Iic.preimage measurable_snd)] + rfl + +/-- **Hoeffding's covariance identity** (Hoeffding 1940; Höffding's lemma in +McNeil–Frey–Embrechts (2015), Chapter 7): for square-integrable `X, Y`, +`cov(X, Y) = ∫∫ (P(X ≤ s, Y ≤ t) − P(X ≤ s) P(Y ≤ t)) ds dt`. -/ +theorem covariance_eq_integral_cdf (hX : MemLp X 2 P) (hY : MemLp Y 2 P) : + cov[X, Y; P] = ∫ p : ℝ × ℝ, + (P.real {ω | X ω ≤ p.1 ∧ Y ω ≤ p.2} - P.real {ω | X ω ≤ p.1} * P.real {ω | Y ω ≤ p.2}) := by + have hZ := hX.aemeasurable.prodMk hY.aemeasurable + obtain ⟨h₁, h₂⟩ := memLp_fst_snd_map hX hY + have hlaw : HasLaw (fun ω ↦ (X ω, Y ω)) (P.map fun ω ↦ (X ω, Y ω)) P := ⟨hZ, rfl⟩ + rw [show cov[X, Y; P] = cov[Prod.fst ∘ (fun ω ↦ (X ω, Y ω)), Prod.snd ∘ (fun ω ↦ (X ω, Y ω)); P] + from rfl, hlaw.covariance_comp measurable_fst.aemeasurable measurable_snd.aemeasurable, + covariance_fst_snd_eq_integral h₁ h₂] + exact integral_congr_ae (ae_of_all _ (cdf_sub_mul_map hX.aemeasurable hY.aemeasurable)) + +/-- The Hoeffding integrand of square-integrable `X, Y` is integrable on `ℝ²`. -/ +theorem integrable_cdf_sub_mul (hX : MemLp X 2 P) (hY : MemLp Y 2 P) : + Integrable fun p : ℝ × ℝ ↦ + P.real {ω | X ω ≤ p.1 ∧ Y ω ≤ p.2} - P.real {ω | X ω ≤ p.1} * P.real {ω | Y ω ≤ p.2} := by + obtain ⟨h₁, h₂⟩ := memLp_fst_snd_map hX hY + exact (integrable_cdf_sub_mul_fst_snd h₁ h₂).congr + (ae_of_all _ (cdf_sub_mul_map hX.aemeasurable hY.aemeasurable)) + +variable {Ω' : Type*} {mΩ' : MeasurableSpace Ω'} {P' : Measure Ω'} [IsProbabilityMeasure P'] + {X' Y' : Ω' → ℝ} + +/-- **Covariance is monotone in the joint CDF** (QRM Exercise Book Ex. 7.14): if `(X, Y)` and +`(X', Y')` have the same marginal laws and `P(X ≤ s, Y ≤ t) ≤ P'(X' ≤ s, Y' ≤ t)` for all +`s, t`, then `cov(X, Y) ≤ cov(X', Y')`. -/ +theorem covariance_le_covariance_of_cdf_le (hX : MemLp X 2 P) (hY : MemLp Y 2 P) + (hX' : MemLp X' 2 P') (hY' : MemLp Y' 2 P') (hlawX : P.map X = P'.map X') + (hlawY : P.map Y = P'.map Y') + (hF : ∀ s t, P.real {ω | X ω ≤ s ∧ Y ω ≤ t} ≤ P'.real {ω | X' ω ≤ s ∧ Y' ω ≤ t}) : + cov[X, Y; P] ≤ cov[X', Y'; P'] := by + have hmarg {Z : Ω → ℝ} {Z' : Ω' → ℝ} (hZ : AEMeasurable Z P) (hZ' : AEMeasurable Z' P') + (h : P.map Z = P'.map Z') (s : ℝ) : P.real {ω | Z ω ≤ s} = P'.real {ω | Z' ω ≤ s} := by + have e := congrArg (fun ν : Measure ℝ ↦ ν.real (Iic s)) h + rw [map_measureReal_apply_of_aemeasurable hZ measurableSet_Iic, + map_measureReal_apply_of_aemeasurable hZ' measurableSet_Iic] at e + exact e + rw [covariance_eq_integral_cdf hX hY, covariance_eq_integral_cdf hX' hY'] + refine integral_mono (integrable_cdf_sub_mul hX hY) (integrable_cdf_sub_mul hX' hY') + fun p ↦ ?_ + rw [hmarg hX.aemeasurable hX'.aemeasurable hlawX, hmarg hY.aemeasurable hY'.aemeasurable hlawY] + exact sub_le_sub_right (hF p.1 p.2) _ + +/-- **Correlation is monotone in the joint CDF**: under the hypotheses of +`covariance_le_covariance_of_cdf_le`, the correlations are ordered too, because equal marginal +laws have equal variances. -/ +theorem correlation_le_correlation_of_cdf_le (hX : MemLp X 2 P) (hY : MemLp Y 2 P) + (hX' : MemLp X' 2 P') (hY' : MemLp Y' 2 P') (hlawX : P.map X = P'.map X') + (hlawY : P.map Y = P'.map Y') + (hF : ∀ s t, P.real {ω | X ω ≤ s ∧ Y ω ≤ t} ≤ P'.real {ω | X' ω ≤ s ∧ Y' ω ≤ t}) : + cov[X, Y; P] / √(Var[X; P] * Var[Y; P]) ≤ cov[X', Y'; P'] / √(Var[X'; P'] * Var[Y'; P']) := by + have hvar {Z : Ω → ℝ} {Z' : Ω' → ℝ} (hZ : AEMeasurable Z P) (hZ' : AEMeasurable Z' P') + (h : P.map Z = P'.map Z') : Var[Z; P] = Var[Z'; P'] := by + rw [(HasLaw.mk hZ rfl : HasLaw Z (P.map Z) P).variance_eq, h, + (HasLaw.mk hZ' rfl : HasLaw Z' (P'.map Z') P').variance_eq] + rw [hvar hX.aemeasurable hX'.aemeasurable hlawX, hvar hY.aemeasurable hY'.aemeasurable hlawY] + gcongr + exact covariance_le_covariance_of_cdf_le hX hY hX' hY' hlawX hlawY hF + +end RandomVariables + +/-! ### At the standard bivariate normal law -/ + +/-- **Hoeffding's identity at the standard bivariate normal law**: for `r ∈ [−1, 1]`, +`∫∫ (N₂(s, t; r) − Φ(s) Φ(t)) ds dt = r`. The covariance of the Cholesky pair is `r` +(`covariance_fst_snd_bivariateNormalLaw`), its joint CDF is `N₂(·, ·; r)` and its margins are +standard normal. -/ +theorem integral_bivariateNormalCDF_sub_mul {r : ℝ} (hr : r ^ 2 ≤ 1) : + ∫ p : ℝ × ℝ, (bivariateNormalCDF p.1 p.2 r - Phi p.1 * Phi p.2) = r := by + have h := covariance_fst_snd_eq_integral (μ := bivariateNormalLaw r) + (memLp_fst_bivariateNormalLaw r) (memLp_snd_bivariateNormalLaw r) + rw [covariance_fst_snd_bivariateNormalLaw] at h + refine Eq.trans ?_ h.symm + congr 1 + funext p + rw [bivariateNormalCDF_eq_law, Set.Iic_prod_eq, + ← map_measureReal_apply measurable_fst measurableSet_Iic, + ← map_measureReal_apply measurable_snd measurableSet_Iic, map_fst_bivariateNormalLaw hr, + map_snd_bivariateNormalLaw, ← cdf_eq_real, ← cdf_eq_real, cdf_gaussianReal_zero_one] + +end MathFin diff --git a/LeanPool/MathFin/Probability/Dependence/MarshallOlkin.lean b/LeanPool/MathFin/Probability/Dependence/MarshallOlkin.lean new file mode 100644 index 0000000000..b355088c89 --- /dev/null +++ b/LeanPool/MathFin/Probability/Dependence/MarshallOlkin.lean @@ -0,0 +1,429 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Dependence.HoeffdingCovariance + +/-! +# The Marshall–Olkin common-shock model + +Three independent exponential clocks `T₁, T₂, T₃` with rates `λ₁, λ₂, λ₃ > 0` drive two default +times. `T₁`, `T₂` are idiosyncratic shocks, and `T₃` is a common shock that kills both names. +Firm `j` defaults at `Xⱼ = min(Tⱼ, T₃)` (QRM Exercise Book Ex. 7.23; McNeil–Frey–Embrechts (2015) +Section 7.2.2; Marshall and Olkin 1967). In Lean the clocks are `T 0`, `T 1`, `T 2`, with rates +`rate 0`, `rate 1`, `rate 2`. + +* **Joint survival** (`marshallOlkin_survival`): for `s, t ≥ 0`, + `P(X₁ > s, X₂ > t) = exp(−λ₁ s − λ₂ t − λ₃ max(s, t))`. +* **Margins** (`hasLaw_marshallOlkin_fst`, `hasLaw_marshallOlkin_snd`): `Xⱼ ~ Exp(λⱼ + λ₃)`. +* **The survival copula** (`marshallOlkin_survival_eq_copula`): the joint survival function is + the Marshall–Olkin copula `C(u₁, u₂) = min(u₁^{1−α₁} u₂, u₁ u₂^{1−α₂})`, with + `αⱼ = λ₃ / (λⱼ + λ₃)`, evaluated at the marginal survival probabilities. +* **Dependence** (`marshallOlkin_survival_gt_mul`, `marshallOlkin_diagonal_pos`): the names + survive together more often than independent names with the same margins would. With positive + probability they default at the same instant, so the joint law has a singular component even + though both margins are continuous. +* **Default covariance** (`covariance_indicator_marshallOlkin`): for horizons `s, t ≥ 0` the + default indicators `𝟙{X₁ ≤ s}`, `𝟙{X₂ ≤ t}` have covariance + `exp(−(λ₁ + λ₃)s − (λ₂ + λ₃)t) (exp(λ₃ min(s, t)) − 1)`, by the indicator covariance + `covariance_indicator_one` of `Probability/Dependence/HoeffdingCovariance.lean`. +* **First to default** (`marshallOlkin_firstToDefault_survival`, + `marshallOlkin_firstToDefault_spread_lt`): `min(X₁, X₂) = min(T₁, T₂, T₃)` survives to `t` with + probability `exp(−(λ₁ + λ₂ + λ₃) t)`. So the first-to-default intensity is `λ₁ + λ₂ + λ₃`. That + is strictly below the sum `(λ₁ + λ₃) + (λ₂ + λ₃)` of the single-name intensities whenever the + common shock is active. For independent names `Models/Credit/FirstToDefault.lean` + (`firstToDefault_spread_eq_sum_hazards`) shows the first-to-default spread equals the sum of + the single-name hazards, and its docstring asserts that default correlation only lowers the + spread below this sum. The common shock is a machine-checked instance of that assertion: it + correlates the two defaults and lowers the basket intensity by exactly `λ₃`. + +## Main definitions + +* `marshallOlkinCopula`: the bivariate copula `C(u₁, u₂) = min(u₁^{1−α₁} u₂, u₁ u₂^{1−α₂})` + with parameters `α₁`, `α₂`. + +## Main results + +For independent exponential clocks `T i` of positive rates `rate i`: + +* `marshallOlkin_survival`: for `s, t ≥ 0`, + `P(X₁ > s, X₂ > t) = exp(−λ₁ s − λ₂ t − λ₃ max(s, t))`. +* `hasLaw_marshallOlkin_fst`, `hasLaw_marshallOlkin_snd`: `X₁ ~ Exp(λ₁ + λ₃)` and + `X₂ ~ Exp(λ₂ + λ₃)`. +* `marshallOlkin_survival_eq_copula`: for `s, t ≥ 0`, the joint survival probability equals + `marshallOlkinCopula` (with `αⱼ = λ₃/(λⱼ + λ₃)`) at the two marginal survival probabilities. +* `marshallOlkin_survival_gt_mul`: for `s, t > 0`, the joint survival probability is strictly + larger than the product of the marginal ones. +* `marshallOlkin_diagonal_pos`: `P(X₁ = X₂) > 0`. +* `covariance_indicator_marshallOlkin`: for `s, t ≥ 0`, `Cov(𝟙{X₁ ≤ s}, 𝟙{X₂ ≤ t})` is + `exp(−(λ₁+λ₃)s − (λ₂+λ₃)t)·(exp(λ₃ min(s, t)) − 1)`. +* `marshallOlkin_firstToDefault_survival`: for `t ≥ 0`, `P(min(X₁, X₂) > t) = exp(−(λ₁+λ₂+λ₃)t)`. +* `marshallOlkin_firstToDefault_spread`, `marshallOlkin_single_name_spread_fst`, + `marshallOlkin_single_name_spread_snd`: for `t > 0`, `−log P(·)/t` equals `λ₁+λ₂+λ₃` for the + first-to-default time and `λ₁+λ₃`, `λ₂+λ₃` for the single names. +* `marshallOlkin_firstToDefault_spread_lt`: for `t > 0`, the first-to-default spread is strictly + below the sum of the two single-name spreads. + +## References + +* [Marshall and Olkin (1967)][MarshallOlkin1967] +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 7.23 + +## Tags + +Marshall–Olkin copula, common shock, joint default, default correlation, first-to-default, +exponential clocks, survival copula, MSC 91G40, MSC 62H05, JEL G33 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set + +/-- The exponential survival function: `Exp(r)` puts mass `exp(−r · max(t, 0))` on `(t, ∞)`. -/ +lemma expMeasure_real_Ioi {r : ℝ} (hr : 0 < r) (t : ℝ) : + (expMeasure r).real (Ioi t) = Real.exp (-(r * max t 0)) := by + have := isProbabilityMeasure_expMeasure hr + rw [← compl_Iic, probReal_compl_eq_one_sub measurableSet_Iic, ← cdf_eq_real, + cdf_expMeasure_eq hr] + rcases le_total 0 t with ht | ht + · rw [ite_eq_left ht, max_eq_left ht] + ring + · rcases ht.lt_or_eq with ht | rfl + · rw [ite_eq_right (not_le.2 ht), max_eq_right ht.le] + simp + · simp + +/-- An exponential clock outlasts any horizon with positive probability. -/ +lemma expMeasure_Ioi_ne_zero {r : ℝ} (hr : 0 < r) (t : ℝ) : expMeasure r (Ioi t) ≠ 0 := by + intro h + have h' := expMeasure_real_Ioi hr t + rw [measureReal_def, h, ENNReal.toReal_zero] at h' + exact (Real.exp_pos _).ne h' + +/-- An exponential clock rings before a positive horizon with positive probability. -/ +lemma expMeasure_Iic_ne_zero {r t : ℝ} (hr : 0 < r) (ht : 0 < t) : + expMeasure r (Iic t) ≠ 0 := by + have := isProbabilityMeasure_expMeasure hr + rw [← ofReal_cdf, cdf_expMeasure_eq hr, ite_eq_left ht.le, ne_eq, ENNReal.ofReal_eq_zero, not_le, + sub_pos] + exact (Real.exp_lt_exp.2 (neg_lt_zero.2 (mul_pos hr ht))).trans_eq Real.exp_zero + +/-- Two laws on `ℝ` with the same survival function coincide. -/ +lemma ext_of_measureReal_Ioi {μ ν : Measure ℝ} [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + (h : ∀ u, μ.real (Ioi u) = ν.real (Ioi u)) : μ = ν := by + refine Measure.ext_of_Iic _ _ fun a ↦ ?_ + have h1 : μ.real (Iic a) = ν.real (Iic a) := by + rw [← compl_Ioi, probReal_compl_eq_one_sub measurableSet_Ioi, + probReal_compl_eq_one_sub measurableSet_Ioi, h] + rwa [measureReal_def, measureReal_def, + ENNReal.toReal_eq_toReal_iff' (measure_ne_top _ _) (measure_ne_top _ _)] at h1 + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + {T : Fin 3 → Ω → ℝ} {rate : Fin 3 → ℝ} + +omit [IsProbabilityMeasure P] in +/-- Survival of all three clocks past their own thresholds: independence factorizes it. -/ +lemma measureReal_iInter_Ioi_of_hasLaw_expMeasure (hrate : ∀ i, 0 < rate i) + (hT : ∀ i, HasLaw (T i) (expMeasure (rate i)) P) (hind : iIndepFun T P) (c : Fin 3 → ℝ) : + P.real (⋂ i, T i ⁻¹' Ioi (c i)) = ∏ i, Real.exp (-(rate i * max (c i) 0)) := by + rw [measureReal_def, hind.meas_iInter fun i ↦ ⟨Ioi (c i), measurableSet_Ioi, rfl⟩, + ENNReal.toReal_prod] + refine Finset.prod_congr rfl fun i _ ↦ ?_ + rw [← measureReal_def, ← map_measureReal_apply_of_aemeasurable (hT i).aemeasurable + measurableSet_Ioi, (hT i).map_eq] + exact expMeasure_real_Ioi (hrate i) (c i) + +omit [IsProbabilityMeasure P] in +/-- The survival function of a minimum of two of the independent clocks. -/ +lemma measureReal_lt_min_of_hasLaw_expMeasure (hrate : ∀ i, 0 < rate i) + (hT : ∀ i, HasLaw (T i) (expMeasure (rate i)) P) (hind : iIndepFun T P) {i j : Fin 3} + (hij : i ≠ j) (u : ℝ) : + P.real {ω | u < min (T i ω) (T j ω)} + = (expMeasure (rate i + rate j)).real (Ioi u) := by + rw [expMeasure_real_Ioi (add_pos (hrate i) (hrate j)), + show {ω | u < min (T i ω) (T j ω)} = T i ⁻¹' Ioi u ∩ T j ⁻¹' Ioi u by ext; simp, + measureReal_def, (hind.indepFun hij).measure_inter_preimage_eq_mul _ _ measurableSet_Ioi + measurableSet_Ioi, ENNReal.toReal_mul, ← measureReal_def, ← measureReal_def, + ← map_measureReal_apply_of_aemeasurable (hT i).aemeasurable measurableSet_Ioi, (hT i).map_eq, + ← map_measureReal_apply_of_aemeasurable (hT j).aemeasurable measurableSet_Ioi, (hT j).map_eq, + expMeasure_real_Ioi (hrate i), expMeasure_real_Ioi (hrate j), ← Real.exp_add] + congr 1 + ring + +/-- A minimum of two independent exponential clocks is exponential at the summed rate. -/ +lemma hasLaw_min_expMeasure (hrate : ∀ i, 0 < rate i) + (hT : ∀ i, HasLaw (T i) (expMeasure (rate i)) P) (hind : iIndepFun T P) {i j : Fin 3} + (hij : i ≠ j) : + HasLaw (fun ω ↦ min (T i ω) (T j ω)) (expMeasure (rate i + rate j)) P := by + have hmeas : AEMeasurable (fun ω ↦ min (T i ω) (T j ω)) P := + (hT i).aemeasurable.min (hT j).aemeasurable + have := isProbabilityMeasure_expMeasure (add_pos (hrate i) (hrate j)) + refine ⟨hmeas, ext_of_measureReal_Ioi fun u ↦ ?_⟩ + rw [map_measureReal_apply_of_aemeasurable hmeas measurableSet_Ioi] + exact measureReal_lt_min_of_hasLaw_expMeasure hrate hT hind hij u + +/-- **Margins of the Marshall–Olkin model**: `X₁ = min(T₁, T₃) ~ Exp(λ₁ + λ₃)`. -/ +theorem hasLaw_marshallOlkin_fst (hrate : ∀ i, 0 < rate i) + (hT : ∀ i, HasLaw (T i) (expMeasure (rate i)) P) (hind : iIndepFun T P) : + HasLaw (fun ω ↦ min (T 0 ω) (T 2 ω)) (expMeasure (rate 0 + rate 2)) P := + hasLaw_min_expMeasure hrate hT hind (by decide) + +/-- **Margins of the Marshall–Olkin model**: `X₂ = min(T₂, T₃) ~ Exp(λ₂ + λ₃)`. -/ +theorem hasLaw_marshallOlkin_snd (hrate : ∀ i, 0 < rate i) + (hT : ∀ i, HasLaw (T i) (expMeasure (rate i)) P) (hind : iIndepFun T P) : + HasLaw (fun ω ↦ min (T 1 ω) (T 2 ω)) (expMeasure (rate 1 + rate 2)) P := + hasLaw_min_expMeasure hrate hT hind (by decide) + +omit [IsProbabilityMeasure P] in +/-- **Joint survival of the Marshall–Olkin model** (QRM Exercise Book Ex. 7.23): for `s, t ≥ 0`, +`P(X₁ > s, X₂ > t) = exp(−λ₁ s − λ₂ t − λ₃ max(s, t))`. Both names survive exactly when the +idiosyncratic clocks pass their own horizons and the common shock passes the later one. -/ +theorem marshallOlkin_survival (hrate : ∀ i, 0 < rate i) + (hT : ∀ i, HasLaw (T i) (expMeasure (rate i)) P) (hind : iIndepFun T P) {s t : ℝ} + (hs : 0 ≤ s) (ht : 0 ≤ t) : + P.real {ω | s < min (T 0 ω) (T 2 ω) ∧ t < min (T 1 ω) (T 2 ω)} + = Real.exp (-(rate 0 * s) - rate 1 * t - rate 2 * max s t) := by + have hset : {ω | s < min (T 0 ω) (T 2 ω) ∧ t < min (T 1 ω) (T 2 ω)} + = ⋂ i, T i ⁻¹' Ioi (![s, t, max s t] i) := by + ext ω + simp only [mem_ofPred_eq, mem_iInter, mem_preimage, mem_Ioi, lt_min_iff] + constructor + · rintro ⟨⟨h0, h2⟩, h1, h2'⟩ i + fin_cases i + exacts [h0, h1, max_lt h2 h2'] + · intro h + have h2 : max s t < T 2 ω := h 2 + exact ⟨⟨h 0, (le_max_left s t).trans_lt h2⟩, h 1, (le_max_right s t).trans_lt h2⟩ + rw [hset, measureReal_iInter_Ioi_of_hasLaw_expMeasure hrate hT hind ![s, t, max s t], + Fin.prod_univ_three, ← Real.exp_add, ← Real.exp_add] + simp only [Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, + Matrix.tail_cons] + rw [max_eq_left hs, max_eq_left ht, max_eq_left (le_max_of_le_left hs)] + congr 1 + +/-- The bivariate **Marshall–Olkin copula** `C(u₁, u₂) = min(u₁^{1−α₁} u₂, u₁ u₂^{1−α₂})`. -/ +noncomputable def marshallOlkinCopula (α₁ α₂ u₁ u₂ : ℝ) : ℝ := + min (u₁ ^ (1 - α₁) * u₂) (u₁ * u₂ ^ (1 - α₂)) + +omit [IsProbabilityMeasure P] in +/-- **The Marshall–Olkin survival copula** (QRM Exercise Book Ex. 7.23(a)): for `s, t ≥ 0` the +joint survival probability of `(X₁, X₂)` is the Marshall–Olkin copula with +`αⱼ = λ₃ / (λⱼ + λ₃)` evaluated at the marginal survival probabilities: +`P(X₁ > s, X₂ > t) = C(P(X₁ > s), P(X₂ > t))`. -/ +theorem marshallOlkin_survival_eq_copula (hrate : ∀ i, 0 < rate i) + (hT : ∀ i, HasLaw (T i) (expMeasure (rate i)) P) (hind : iIndepFun T P) {s t : ℝ} + (hs : 0 ≤ s) (ht : 0 ≤ t) : + P.real {ω | s < min (T 0 ω) (T 2 ω) ∧ t < min (T 1 ω) (T 2 ω)} + = marshallOlkinCopula (rate 2 / (rate 0 + rate 2)) (rate 2 / (rate 1 + rate 2)) + (P.real {ω | s < min (T 0 ω) (T 2 ω)}) (P.real {ω | t < min (T 1 ω) (T 2 ω)}) := by + have h02 : rate 0 + rate 2 ≠ 0 := (add_pos (hrate 0) (hrate 2)).ne' + have h12 : rate 1 + rate 2 ≠ 0 := (add_pos (hrate 1) (hrate 2)).ne' + rw [marshallOlkin_survival hrate hT hind hs ht, + measureReal_lt_min_of_hasLaw_expMeasure hrate hT hind (i := 0) (j := 2) (by decide), + measureReal_lt_min_of_hasLaw_expMeasure hrate hT hind (i := 1) (j := 2) (by decide), + expMeasure_real_Ioi (add_pos (hrate 0) (hrate 2)), + expMeasure_real_Ioi (add_pos (hrate 1) (hrate 2)), max_eq_left hs, max_eq_left ht, + marshallOlkinCopula, ← Real.exp_mul, ← Real.exp_mul, ← Real.exp_add, ← Real.exp_add, + ← Real.exp_monotone.map_min] + congr 1 + have e1 : -((rate 0 + rate 2) * s) * (1 - rate 2 / (rate 0 + rate 2)) = -(rate 0 * s) := by + field_simp + ring + have e2 : -((rate 1 + rate 2) * t) * (1 - rate 2 / (rate 1 + rate 2)) = -(rate 1 * t) := by + field_simp + ring + rw [e1, e2] + rcases le_total s t with hst | hst + · rw [max_eq_right hst, min_eq_left (by nlinarith [hrate 2])] + ring + · rw [max_eq_left hst, min_eq_right (by nlinarith [hrate 2])] + ring + +omit [IsProbabilityMeasure P] in +/-- **Positive quadrant dependence**: for `s, t > 0` the two names survive together more often +than independent names with the same margins would, +`P(X₁ > s, X₂ > t) > P(X₁ > s) P(X₂ > t)`. The excess factor is `exp(λ₃ min(s, t))`. -/ +theorem marshallOlkin_survival_gt_mul (hrate : ∀ i, 0 < rate i) + (hT : ∀ i, HasLaw (T i) (expMeasure (rate i)) P) (hind : iIndepFun T P) {s t : ℝ} + (hs : 0 < s) (ht : 0 < t) : + P.real {ω | s < min (T 0 ω) (T 2 ω)} * P.real {ω | t < min (T 1 ω) (T 2 ω)} + < P.real {ω | s < min (T 0 ω) (T 2 ω) ∧ t < min (T 1 ω) (T 2 ω)} := by + rw [marshallOlkin_survival hrate hT hind hs.le ht.le, + measureReal_lt_min_of_hasLaw_expMeasure hrate hT hind (i := 0) (j := 2) (by decide), + measureReal_lt_min_of_hasLaw_expMeasure hrate hT hind (i := 1) (j := 2) (by decide), + expMeasure_real_Ioi (add_pos (hrate 0) (hrate 2)), + expMeasure_real_Ioi (add_pos (hrate 1) (hrate 2)), max_eq_left hs.le, max_eq_left ht.le, + ← Real.exp_add, Real.exp_lt_exp] + rcases le_total s t with hst | hst + · rw [max_eq_right hst] + nlinarith [hrate 2] + · rw [max_eq_left hst] + nlinarith [hrate 2] + +/-- **The Marshall–Olkin law charges the diagonal**: `P(X₁ = X₂) > 0`, although both margins are +exponential and hence atomless. The common shock makes the two defaults simultaneous with +positive probability, so the joint law has a singular component on `{x₁ = x₂}`. -/ +theorem marshallOlkin_diagonal_pos (hrate : ∀ i, 0 < rate i) + (hT : ∀ i, HasLaw (T i) (expMeasure (rate i)) P) (hind : iIndepFun T P) : + 0 < P.real {ω | min (T 0 ω) (T 2 ω) = min (T 1 ω) (T 2 ω)} := by + have hmeas (i : Fin 3) : MeasurableSet (![Ioi (1 : ℝ), Ioi 1, Iic 1] i) := by + fin_cases i + exacts [measurableSet_Ioi, measurableSet_Ioi, measurableSet_Iic] + have hsub : ⋂ i, T i ⁻¹' ![Ioi (1 : ℝ), Ioi 1, Iic 1] i + ⊆ {ω | min (T 0 ω) (T 2 ω) = min (T 1 ω) (T 2 ω)} := by + intro ω hω + simp only [mem_iInter, mem_preimage] at hω + have h0 : 1 < T 0 ω := hω 0 + have h1 : 1 < T 1 ω := hω 1 + have h2 : T 2 ω ≤ 1 := hω 2 + change min (T 0 ω) (T 2 ω) = min (T 1 ω) (T 2 ω) + rw [min_eq_right (h2.trans h0.le), min_eq_right (h2.trans h1.le)] + have hpos (i : Fin 3) : P (T i ⁻¹' ![Ioi (1 : ℝ), Ioi 1, Iic 1] i) ≠ 0 := by + rw [← Measure.map_apply_of_aemeasurable (hT i).aemeasurable (hmeas i), (hT i).map_eq] + fin_cases i + exacts [expMeasure_Ioi_ne_zero (hrate 0) 1, expMeasure_Ioi_ne_zero (hrate 1) 1, + expMeasure_Iic_ne_zero (hrate 2) one_pos] + have hS : 0 < P.real (⋂ i, T i ⁻¹' ![Ioi (1 : ℝ), Ioi 1, Iic 1] i) := by + rw [measureReal_def, hind.meas_iInter fun i ↦ ⟨_, hmeas i, rfl⟩] + exact ENNReal.toReal_pos (Finset.prod_ne_zero_iff.2 fun i _ ↦ hpos i) + (ENNReal.prod_ne_top fun i _ ↦ measure_ne_top _ _) + exact hS.trans_le (measureReal_mono hsub) + +/-- **Default covariance under a common shock**: for horizons `s, t ≥ 0`, the default indicators +`𝟙{X₁ ≤ s}` and `𝟙{X₂ ≤ t}` have covariance +`exp(−(λ₁ + λ₃)s − (λ₂ + λ₃)t) · (exp(λ₃ min(s, t)) − 1)`, positive when `λ₃ min(s, t) > 0`. The +covariance of two indicators is `P(A ∩ B) − P(A)P(B)` (`covariance_indicator_one`, +`Probability/Dependence/HoeffdingCovariance.lean`), unchanged under complementing both events +(`measureReal_inter_sub_mul_compl`), so it is read off the joint survival function +(`marshallOlkin_survival`) and the margins. -/ +theorem covariance_indicator_marshallOlkin (hrate : ∀ i, 0 < rate i) + (hT : ∀ i, HasLaw (T i) (expMeasure (rate i)) P) (hind : iIndepFun T P) {s t : ℝ} + (hs : 0 ≤ s) (ht : 0 ≤ t) : + cov[{ω | min (T 0 ω) (T 2 ω) ≤ s}.indicator 1, {ω | min (T 1 ω) (T 2 ω) ≤ t}.indicator 1; P] = + Real.exp (-((rate 0 + rate 2) * s) - (rate 1 + rate 2) * t) * + (Real.exp (rate 2 * min s t) - 1) := by + set Z : Ω → ℝ × ℝ := fun ω ↦ (min (T 0 ω) (T 2 ω), min (T 1 ω) (T 2 ω)) + have hZ : AEMeasurable Z P := ((hT 0).aemeasurable.min (hT 2).aemeasurable).prodMk + ((hT 1).aemeasurable.min (hT 2).aemeasurable) + have hA : MeasurableSet (Prod.fst ⁻¹' Iic s : Set (ℝ × ℝ)) := + measurableSet_Iic.preimage measurable_fst + have hB : MeasurableSet (Prod.snd ⁻¹' Iic t : Set (ℝ × ℝ)) := + measurableSet_Iic.preimage measurable_snd + -- the covariance is computed on the joint law of `(X₁, X₂)` + have hcov : cov[{ω | min (T 0 ω) (T 2 ω) ≤ s}.indicator 1, + {ω | min (T 1 ω) (T 2 ω) ≤ t}.indicator 1; P] = + cov[(Prod.fst ⁻¹' Iic s).indicator 1, (Prod.snd ⁻¹' Iic t).indicator 1; P.map Z] := + (covariance_map_fun (measurable_one.indicator hA).aestronglyMeasurable + (measurable_one.indicator hB).aestronglyMeasurable hZ).symm + have e₁ : Z ⁻¹' ((Prod.fst ⁻¹' Iic s)ᶜ ∩ (Prod.snd ⁻¹' Iic t)ᶜ) = + {ω | s < min (T 0 ω) (T 2 ω) ∧ t < min (T 1 ω) (T 2 ω)} := by + ext ω + simp [Z] + have e₂ : Z ⁻¹' (Prod.fst ⁻¹' Iic s)ᶜ = {ω | s < min (T 0 ω) (T 2 ω)} := by + ext ω + simp [Z] + have e₃ : Z ⁻¹' (Prod.snd ⁻¹' Iic t)ᶜ = {ω | t < min (T 1 ω) (T 2 ω)} := by + ext ω + simp [Z] + rw [hcov, covariance_indicator_one hA hB, ← measureReal_inter_sub_mul_compl hA hB, + map_measureReal_apply_of_aemeasurable hZ (hA.compl.inter hB.compl), + map_measureReal_apply_of_aemeasurable hZ hA.compl, + map_measureReal_apply_of_aemeasurable hZ hB.compl, e₁, e₂, e₃, + marshallOlkin_survival hrate hT hind hs ht, + measureReal_lt_min_of_hasLaw_expMeasure hrate hT hind (i := 0) (j := 2) (by decide), + measureReal_lt_min_of_hasLaw_expMeasure hrate hT hind (i := 1) (j := 2) (by decide), + expMeasure_real_Ioi (add_pos (hrate 0) (hrate 2)), + expMeasure_real_Ioi (add_pos (hrate 1) (hrate 2)), max_eq_left hs, max_eq_left ht] + have hmax : max s t = s + t - min s t := by linarith [min_add_max s t] + have h₁ : Real.exp (-(rate 0 * s) - rate 1 * t - rate 2 * max s t) = + Real.exp (-((rate 0 + rate 2) * s) - (rate 1 + rate 2) * t) * + Real.exp (rate 2 * min s t) := by + rw [← Real.exp_add, hmax] + congr 1 + ring + have h₂ : Real.exp (-((rate 0 + rate 2) * s)) * Real.exp (-((rate 1 + rate 2) * t)) = + Real.exp (-((rate 0 + rate 2) * s) - (rate 1 + rate 2) * t) := by + rw [← Real.exp_add, sub_eq_add_neg] + rw [h₁, h₂] + ring + +/-! ### First to default under a common shock -/ + +omit [IsProbabilityMeasure P] in +/-- **First-to-default survival under a common shock**: for `t ≥ 0`, +`P(min(X₁, X₂) > t) = exp(−(λ₁ + λ₂ + λ₃) t)`, since `min(X₁, X₂) = min(T₁, T₂, T₃)`. -/ +theorem marshallOlkin_firstToDefault_survival (hrate : ∀ i, 0 < rate i) + (hT : ∀ i, HasLaw (T i) (expMeasure (rate i)) P) (hind : iIndepFun T P) {t : ℝ} + (ht : 0 ≤ t) : + P.real {ω | t < min (min (T 0 ω) (T 2 ω)) (min (T 1 ω) (T 2 ω))} + = Real.exp (-((rate 0 + rate 1 + rate 2) * t)) := by + have hset : {ω | t < min (min (T 0 ω) (T 2 ω)) (min (T 1 ω) (T 2 ω))} + = ⋂ i, T i ⁻¹' Ioi t := by + ext ω + simp only [mem_ofPred_eq, mem_iInter, mem_preimage, mem_Ioi, lt_min_iff] + constructor + · rintro ⟨⟨h0, h2⟩, h1, -⟩ i + fin_cases i + exacts [h0, h1, h2] + · intro h + exact ⟨⟨h 0, h 2⟩, h 1, h 2⟩ + rw [hset, measureReal_iInter_Ioi_of_hasLaw_expMeasure hrate hT hind (fun _ ↦ t), + Fin.prod_univ_three, ← Real.exp_add, ← Real.exp_add, max_eq_left ht] + congr 1 + ring + +omit [IsProbabilityMeasure P] in +/-- The first-to-default credit spread under a common shock, `−log P(min(X₁, X₂) > t) / t`, is the +basket intensity `λ₁ + λ₂ + λ₃`. -/ +theorem marshallOlkin_firstToDefault_spread (hrate : ∀ i, 0 < rate i) + (hT : ∀ i, HasLaw (T i) (expMeasure (rate i)) P) (hind : iIndepFun T P) {t : ℝ} + (ht : 0 < t) : + -Real.log (P.real {ω | t < min (min (T 0 ω) (T 2 ω)) (min (T 1 ω) (T 2 ω))}) / t + = rate 0 + rate 1 + rate 2 := by + rw [marshallOlkin_firstToDefault_survival hrate hT hind ht.le, Real.log_exp, neg_neg, + mul_div_assoc, div_self ht.ne', mul_one] + +omit [IsProbabilityMeasure P] in +/-- The single-name credit spread of the first name is its intensity `λ₁ + λ₃`. -/ +theorem marshallOlkin_single_name_spread_fst (hrate : ∀ i, 0 < rate i) + (hT : ∀ i, HasLaw (T i) (expMeasure (rate i)) P) (hind : iIndepFun T P) {t : ℝ} + (ht : 0 < t) : + -Real.log (P.real {ω | t < min (T 0 ω) (T 2 ω)}) / t = rate 0 + rate 2 := by + rw [measureReal_lt_min_of_hasLaw_expMeasure hrate hT hind (i := 0) (j := 2) (by decide), + expMeasure_real_Ioi (add_pos (hrate 0) (hrate 2)), max_eq_left ht.le, Real.log_exp, neg_neg, + mul_div_assoc, div_self ht.ne', mul_one] + +omit [IsProbabilityMeasure P] in +/-- The single-name credit spread of the second name is its intensity `λ₂ + λ₃`. -/ +theorem marshallOlkin_single_name_spread_snd (hrate : ∀ i, 0 < rate i) + (hT : ∀ i, HasLaw (T i) (expMeasure (rate i)) P) (hind : iIndepFun T P) {t : ℝ} + (ht : 0 < t) : + -Real.log (P.real {ω | t < min (T 1 ω) (T 2 ω)}) / t = rate 1 + rate 2 := by + rw [measureReal_lt_min_of_hasLaw_expMeasure hrate hT hind (i := 1) (j := 2) (by decide), + expMeasure_real_Ioi (add_pos (hrate 1) (hrate 2)), max_eq_left ht.le, Real.log_exp, neg_neg, + mul_div_assoc, div_self ht.ne', mul_one] + +omit [IsProbabilityMeasure P] in +/-- **Default correlation lowers the first-to-default spread**: under an active common shock +(`λ₃ > 0`), the first-to-default spread `λ₁ + λ₂ + λ₃` is strictly below the sum of the +single-name spreads `(λ₁ + λ₃) + (λ₂ + λ₃)`. The sum is what independent names with the same +single-name spreads would pay (`firstToDefault_spread_eq_sum_hazards`). -/ +theorem marshallOlkin_firstToDefault_spread_lt (hrate : ∀ i, 0 < rate i) + (hT : ∀ i, HasLaw (T i) (expMeasure (rate i)) P) (hind : iIndepFun T P) {t : ℝ} + (ht : 0 < t) : + -Real.log (P.real {ω | t < min (min (T 0 ω) (T 2 ω)) (min (T 1 ω) (T 2 ω))}) / t + < -Real.log (P.real {ω | t < min (T 0 ω) (T 2 ω)}) / t + + -Real.log (P.real {ω | t < min (T 1 ω) (T 2 ω)}) / t := by + rw [marshallOlkin_firstToDefault_spread hrate hT hind ht, + marshallOlkin_single_name_spread_fst hrate hT hind ht, + marshallOlkin_single_name_spread_snd hrate hT hind ht] + linarith [hrate 2] + +end MathFin diff --git a/LeanPool/MathFin/Probability/Dependence/Sklar.lean b/LeanPool/MathFin/Probability/Dependence/Sklar.lean new file mode 100644 index 0000000000..a3c111616c --- /dev/null +++ b/LeanPool/MathFin/Probability/Dependence/Sklar.lean @@ -0,0 +1,225 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Dependence.Copula + +/-! +# Sklar's theorem + +**Sklar's theorem** (McNeil–Frey–Embrechts, *Quantitative Risk Management*, 2015, Theorem 7.3) says +that a joint distribution function is its copula evaluated at its marginal distribution functions, +`F(x) = C(F₁(x₁), …, F_d(x_d))`, and that the copula is unique when the margins are continuous. +The converse builds a joint law from any copula and any margins. + +Both directions are the one-dimensional transforms of `Probability/Laws/Quantile.lean`, applied +coordinate by coordinate. + +* **Existence (continuous margins).** The *copula of a random vector* `X` is the joint law of its + probability-integral transforms `Uᵢ = Fᵢ(Xᵢ)` (`copulaOf`). Each `Uᵢ` is uniform + (`hasLaw_cdf`), so this law is a copula (`isCopula_copulaOf`). The events `{Xᵢ ≤ xᵢ}` and + `{Fᵢ(Xᵢ) ≤ Fᵢ(xᵢ)}` are nested and have the same probability `Fᵢ(xᵢ)`, so they agree almost + surely. That gives the Sklar identity `P(X ≤ x) = C(F(x))` (`measureReal_le_eq_copulaOf`). +* **Converse (arbitrary margins).** Under any copula `C`, the vector of quantiles + `(quantile μᵢ (vᵢ))ᵢ` has margins `μᵢ` (the quantile transform) and joint distribution function + `x ↦ C(F₁(x₁), …, F_d(x_d))` (`measureReal_quantile_le_eq`). This needs no continuity, only the + Galois connection `quantile μᵢ p ≤ x ↔ p ≤ Fᵢ(x)`. +* **Uniqueness (continuous margins).** A copula satisfying the Sklar identity is `copulaOf X` + (`eq_copulaOf_of_measureReal_le`). By the converse its quantile vector has the joint distribution + function of `X`, hence the law of `X` (`ext_of_measure_Iic_pi`). Pushing forward along the + margins returns the copula, because `Fᵢ ∘ quantile μᵢ` is the identity on `(0, 1)` when `Fᵢ` is + continuous. +* **Invariance.** Strictly increasing transformations of the coordinates leave the copula + unchanged (`copulaOf_comp_strictMono`, MFE Proposition 7.7). The probability-integral transform + of `Tᵢ(Xᵢ)` at `Tᵢ(y)` is that of `Xᵢ` at `y`. + +The existence and uniqueness halves assume continuous margins. For general margins a copula still +exists, but the construction needs the randomized distributional transform, and uniqueness holds +only on the product of the ranges of the `Fᵢ`. Neither is formalized here. + +## Main definitions + +* `copulaOf`: the copula of a random vector `X` under `P`, the joint law of its + probability-integral transforms `Uᵢ = Fᵢ(Xᵢ)`. + +## Main results + +* `isCopula_copulaOf`, `measureReal_le_eq_copulaOf`: Sklar's theorem, existence (continuous + margins). +* `eq_copulaOf_of_measureReal_le`: Sklar's theorem, uniqueness (continuous margins). +* `hasLaw_quantile_coord`, `measureReal_quantile_le_eq`: the converse of Sklar's theorem. +* `copulaOf_comp_strictMono`: the copula is invariant under strictly increasing transformations. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Proposition 7.7; Theorem 7.3 +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 7.2 +* [Sklar (1959)][Sklar1959] + +## Tags + +Sklar's theorem, copula, marginal distributions, probability integral transform, +dependence structure, copula invariance, MSC 62H05, MSC 60E05, MSC 91G70 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set + +variable {ι : Type*} [Fintype ι] {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + {X : Ω → ι → ℝ} + +/-- The **copula of a random vector** `X`: the joint law of its probability-integral transforms +`Uᵢ = Fᵢ(Xᵢ)`, where `Fᵢ` is the CDF of the `i`-th coordinate. For continuous margins it is the +unique copula of Sklar's theorem. -/ +noncomputable def copulaOf (X : Ω → ι → ℝ) (P : Measure Ω) : Measure (ι → ℝ) := + P.map fun ω i ↦ cdf (P.map fun ω ↦ X ω i) (X ω i) + +omit [Fintype ι] in +/-- The probability-integral transform of a random vector is measurable. -/ +lemma aemeasurable_cdf_coord [Finite ι] (hX : AEMeasurable X P) : + AEMeasurable (fun ω i ↦ cdf (P.map fun ω ↦ X ω i) (X ω i)) P := + aemeasurable_pi_iff.2 fun i ↦ (monotone_cdf _).measurable.comp_aemeasurable (hX.eval i) + +variable [IsProbabilityMeasure P] + +omit [Fintype ι] in +/-- **Sklar's theorem, existence of the copula** (continuous margins): the joint law of the +probability-integral transforms of `X` is a copula. -/ +theorem isCopula_copulaOf [Finite ι] (hX : AEMeasurable X P) + (hF : ∀ i, Continuous (cdf (P.map fun ω ↦ X ω i))) : IsCopula (copulaOf X P) where + isProbabilityMeasure := + inferInstanceAs (IsProbabilityMeasure + (P.map fun ω i ↦ cdf (P.map fun ω ↦ X ω i) (X ω i))) + map_eval i := by + rw [copulaOf, AEMeasurable.map_map_of_aemeasurable (measurable_pi_apply i).aemeasurable + (aemeasurable_cdf_coord hX)] + exact (hasLaw_cdf ⟨hX.eval i, rfl⟩ (hF i)).map_eq + +/-- For a real random variable `Y` with continuous CDF `F`, the events `{Y ≤ y}` and +`{F(Y) ≤ F(y)}` agree almost surely. They are nested and both have probability `F(y)`. -/ +lemma ae_eq_le_iff_cdf_le {Y : Ω → ℝ} (hY : AEMeasurable Y P) + (hF : Continuous (cdf (P.map Y))) (y : ℝ) : + {ω | Y ω ≤ y} =ᵐ[P] {ω | cdf (P.map Y) (Y ω) ≤ cdf (P.map Y) y} := by + have hU := hasLaw_cdf (μ := P.map Y) ⟨hY, rfl⟩ hF + refine ae_eq_of_subset_of_measure_ge (fun ω hω ↦ monotone_cdf _ hω) + (le_of_eq ?_) (hY.nullMeasurable measurableSet_Iic) (measure_ne_top _ _) + rw [show {ω | cdf (P.map Y) (Y ω) ≤ cdf (P.map Y) y} = + (fun ω ↦ cdf (P.map Y) (Y ω)) ⁻¹' Iic (cdf (P.map Y) y) from rfl, + ← Measure.map_apply_of_aemeasurable hU.aemeasurable measurableSet_Iic, hU.map_eq, + ← ofReal_measureReal, uniformIoo_real_Iic (cdf_nonneg _ y) (cdf_le_one _ y), ofReal_cdf, + Measure.map_apply_of_aemeasurable hY measurableSet_Iic] + rfl + +omit [Fintype ι] in +/-- **Sklar's theorem, the identity** (continuous margins): the joint distribution function of `X` +is its copula evaluated at the marginal distribution functions, +`P(X ≤ x) = C(F₁(x₁), …, F_d(x_d))`. -/ +theorem measureReal_le_eq_copulaOf [Finite ι] (hX : AEMeasurable X P) + (hF : ∀ i, Continuous (cdf (P.map fun ω ↦ X ω i))) (x : ι → ℝ) : + P.real {ω | X ω ≤ x} = + (copulaOf X P).real (Iic fun i ↦ cdf (P.map fun ω ↦ X ω i) (x i)) := by + rw [copulaOf, map_measureReal_apply_of_aemeasurable (aemeasurable_cdf_coord hX) + measurableSet_Iic] + refine measureReal_congr ?_ + filter_upwards [ae_all_iff.2 fun i ↦ ae_eq_le_iff_cdf_le (hX.eval i) (hF i) (x i)] with ω hω + simp only [Pi.le_def] + exact forall_congr' hω + +/-! ### The converse: a joint law from a copula and margins -/ + +section Converse + +variable {C : Measure (ι → ℝ)} (μ : ι → Measure ℝ) [∀ i, IsProbabilityMeasure (μ i)] + +omit [Fintype ι] in +/-- **The converse of Sklar's theorem, margins**: under a copula `C`, the quantile transform of the +`i`-th coordinate has law `μᵢ`. -/ +theorem hasLaw_quantile_coord (hC : IsCopula C) (i : ι) : + HasLaw (fun v : ι → ℝ ↦ quantile (μ i) (v i)) (μ i) C := + (hasLaw_quantile (μ i)).comp (hC.hasLaw_eval i) + +omit [Fintype ι] in +/-- The vector of coordinatewise quantile transforms is measurable under a copula. -/ +lemma aemeasurable_quantile_coord [Finite ι] (hC : IsCopula C) : + AEMeasurable (fun v : ι → ℝ ↦ fun i ↦ quantile (μ i) (v i)) C := + aemeasurable_pi_iff.2 fun i ↦ (hasLaw_quantile_coord μ hC i).aemeasurable + +omit [∀ i, IsProbabilityMeasure (μ i)] [Fintype ι] in +/-- **The converse of Sklar's theorem, joint law**: under a copula `C`, the vector of quantiles +`(quantile μᵢ (vᵢ))ᵢ` has joint distribution function `x ↦ C(F₁(x₁), …, F_d(x_d))`. No continuity +of the margins is needed. -/ +theorem measureReal_quantile_le_eq [Finite ι] (hC : IsCopula C) (x : ι → ℝ) : + C.real {v | (fun i ↦ quantile (μ i) (v i)) ≤ x} = C.real (Iic fun i ↦ cdf (μ i) (x i)) := by + refine measureReal_congr ?_ + filter_upwards [hC.ae_mem_Ioo] with v hv + simp only [Pi.le_def] + exact forall_congr' fun i ↦ quantile_le_iff (hv i) + +end Converse + +/-! ### Uniqueness -/ + +omit [Fintype ι] in +/-- **Sklar's theorem, uniqueness** (continuous margins): a copula whose value at the marginal +distribution functions is the joint distribution function of `X` is the copula of `X`. -/ +theorem eq_copulaOf_of_measureReal_le [Finite ι] (hX : AEMeasurable X P) + (hF : ∀ i, Continuous (cdf (P.map fun ω ↦ X ω i))) {C : Measure (ι → ℝ)} (hC : IsCopula C) + (hCX : ∀ x, P.real {ω | X ω ≤ x} = + C.real (Iic fun i ↦ cdf (P.map fun ω ↦ X ω i) (x i))) : + C = copulaOf X P := by + set μ : ι → Measure ℝ := fun i ↦ P.map fun ω ↦ X ω i + have : ∀ i, IsProbabilityMeasure (μ i) := fun _ ↦ inferInstance + have := hC.isProbabilityMeasure + set q : (ι → ℝ) → ι → ℝ := fun v i ↦ quantile (μ i) (v i) + set F : (ι → ℝ) → ι → ℝ := fun y i ↦ cdf (μ i) (y i) + have hq : AEMeasurable q C := aemeasurable_quantile_coord μ hC + have hFmeas : Measurable F := .of_eval fun i ↦ + (monotone_cdf (μ i)).measurable.comp (measurable_pi_apply i) + -- the quantile vector of `C` has the law of `X` + have hlaw : C.map q = P.map X := by + refine ext_of_measure_Iic_pi fun x ↦ ?_ + rw [Measure.map_apply_of_aemeasurable hq measurableSet_Iic, + Measure.map_apply_of_aemeasurable hX measurableSet_Iic, ← ofReal_measureReal, + ← ofReal_measureReal] + congr 1 + exact (measureReal_quantile_le_eq μ hC x).trans (hCX x).symm + -- pushing the law of `X` forward along the margins returns `C` + have hFq : (fun v ↦ F (q v)) =ᵐ[C] id := by + filter_upwards [hC.ae_mem_Ioo] with v hv + exact funext fun i ↦ cdf_quantile (hF i) (hv i) + calc C = C.map (fun v ↦ F (q v)) := by rw [Measure.map_congr hFq, Measure.map_id] + _ = (C.map q).map F := (AEMeasurable.map_map_of_aemeasurable hFmeas.aemeasurable hq).symm + _ = (P.map X).map F := by rw [hlaw] + _ = copulaOf X P := AEMeasurable.map_map_of_aemeasurable hFmeas.aemeasurable hX + +/-! ### Invariance under increasing transformations -/ + +omit [Fintype ι] in +/-- **The copula is invariant under strictly increasing transformations of the margins** +(McNeil–Frey–Embrechts, Proposition 7.7): transforming each coordinate by a strictly increasing +map leaves the copula of the vector unchanged. The probability-integral transform of `Tᵢ(Xᵢ)` at +`Tᵢ(y)` equals that of `Xᵢ` at `y`. -/ +theorem copulaOf_comp_strictMono (hX : AEMeasurable X P) + {T : ι → ℝ → ℝ} (hT : ∀ i, StrictMono (T i)) : + copulaOf (fun ω i ↦ T i (X ω i)) P = copulaOf X P := by + have hcdf (i : ι) (y : ℝ) : + cdf (P.map fun ω ↦ T i (X ω i)) (T i y) = cdf (P.map fun ω ↦ X ω i) y := by + have hTi : AEMeasurable (fun ω ↦ T i (X ω i)) P := + (hT i).monotone.measurable.comp_aemeasurable (hX.eval i) + rw [cdf_eq_real, cdf_eq_real, map_measureReal_apply_of_aemeasurable hTi measurableSet_Iic, + map_measureReal_apply_of_aemeasurable (hX.eval i) measurableSet_Iic] + congr 1 + ext ω + exact (hT i).le_iff_le + simp only [copulaOf, hcdf] + +end MathFin diff --git a/LeanPool/MathFin/Probability/Discrete/DoobDecomposition.lean b/LeanPool/MathFin/Probability/Discrete/DoobDecomposition.lean new file mode 100644 index 0000000000..e5b3360111 --- /dev/null +++ b/LeanPool/MathFin/Probability/Discrete/DoobDecomposition.lean @@ -0,0 +1,103 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Martingale.Centering + +/-! +# Doob decomposition: existence and uniqueness + +Mathlib provides the decomposition operators `MeasureTheory.martingalePart` / +`MeasureTheory.predictablePart` together with four separate facts — the sum +identity, the martingale property of the martingale part, predictability of +the predictable part, `predictablePart f ℱ μ 0 = 0` — and two "essential +uniqueness" lemmas (`martingalePart_add_ae_eq`, `predictablePart_add_ae_eq`). +It never packages them as the textbook theorem. + +This file assembles the **Doob decomposition for adapted integrable processes**. +For `f : ℕ → Ω → E` on a filtered measure space, the decomposition is + + `f = M + A`, `M` a martingale, `A` predictable with `A 0 = 0`, + +and the decomposition is unique in the a.e. sense: any other such pair +`(M', A')` satisfies `M' n =ᵐ[μ] M n` and `A' n =ᵐ[μ] A n` at every time `n`. + +Saporito's Theorem 2.2.12 states the submartingale case, where the predictable +compensator is also nondecreasing. + +Predictability is encoded as in Mathlib's uniqueness lemmas: the shifted +process `n ↦ A (n + 1)` is `ℱ`-strongly-adapted, i.e. `A (n + 1)` is +`ℱ n`-measurable (`A` is known one step ahead). + +## Main results + +* `doob_decomposition_unique` — the uniqueness half: any decomposition of `f` + agrees a.e. with `(martingalePart f ℱ μ, predictablePart f ℱ μ)`. +* `doob_decomposition` — the full existence-and-uniqueness statement. + +`Probability/Discrete/SnellDoobDecomposition.lean` applies the uniqueness half to the finite-horizon +Snell +envelope `snellEnvelope` (`Probability/Discrete/SnellEnvelope.lean`) at `X = univ`, whose +compensator is a.e. nonincreasing and constant on the continuation region. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Theorem 2.2.12 (submartingale case) + +## Tags + +Doob decomposition, predictable part, martingale part, compensator, uniqueness, MSC 60G42, MSC 60G48 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory + +variable {Ω E : Type*} {m0 : MeasurableSpace Ω} + [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] + {μ : Measure Ω} {ℱ : Filtration ℕ m0} + +/-- **Uniqueness of the Doob decomposition.** If `f = M + A` with `M` a +martingale and `A` predictable (`A (n+1)` is `ℱ n`-measurable), integrable, +and null at `0`, then `M` and `A` agree a.e. at every time with Mathlib's +canonical parts `martingalePart f ℱ μ` and `predictablePart f ℱ μ`. -/ +theorem doob_decomposition_unique [SigmaFiniteFiltration μ ℱ] + {f M A : ℕ → Ω → E} + (hM : Martingale M ℱ μ) + (hA : StronglyAdapted ℱ fun n ↦ A (n + 1)) (hA0 : A 0 = 0) + (hA_int : ∀ n, Integrable (A n) μ) + (hMA : M + A = f) (n : ℕ) : + M n =ᵐ[μ] martingalePart f ℱ μ n ∧ A n =ᵐ[μ] predictablePart f ℱ μ n := by + subst hMA + exact ⟨(martingalePart_add_ae_eq hM hA hA0 hA_int n).symm, + (predictablePart_add_ae_eq hM hA hA0 hA_int n).symm⟩ + +/-- **Doob decomposition for adapted processes.** Every adapted +integrable process `f : ℕ → Ω → E` decomposes as `f = M + A` where `M` is a +martingale and `A` is predictable with `A 0 = 0`; the decomposition is unique +up to a.e. equality at every time. The witnesses are Mathlib's +`martingalePart f ℱ μ` and `predictablePart f ℱ μ`. -/ +theorem doob_decomposition [SigmaFiniteFiltration μ ℱ] + {f : ℕ → Ω → E} (hf : StronglyAdapted ℱ f) (hf_int : ∀ n, Integrable (f n) μ) : + ∃ M A : ℕ → Ω → E, + (Martingale M ℱ μ ∧ (StronglyAdapted ℱ fun n ↦ A (n + 1)) ∧ A 0 = 0 ∧ + M + A = f) ∧ + ∀ M' A' : ℕ → Ω → E, Martingale M' ℱ μ → + (StronglyAdapted ℱ fun n ↦ A' (n + 1)) → A' 0 = 0 → + (∀ n, Integrable (A' n) μ) → M' + A' = f → + ∀ n, M' n =ᵐ[μ] M n ∧ A' n =ᵐ[μ] A n := + ⟨martingalePart f ℱ μ, predictablePart f ℱ μ, + ⟨martingale_martingalePart hf hf_int, stronglyAdapted_predictablePart, + predictablePart_zero, martingalePart_add_predictablePart ℱ μ f⟩, + fun _ _ hM' hA' hA'0 hA'_int hM'A' n ↦ + doob_decomposition_unique hM' hA' hA'0 hA'_int hM'A' n⟩ + +end MathFin diff --git a/LeanPool/MathFin/Probability/Discrete/L2MartingaleConvergence.lean b/LeanPool/MathFin/Probability/Discrete/L2MartingaleConvergence.lean new file mode 100644 index 0000000000..191dda76da --- /dev/null +++ b/LeanPool/MathFin/Probability/Discrete/L2MartingaleConvergence.lean @@ -0,0 +1,105 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Discrete.MartingaleDominator +public import TauCeti.MeasureTheory.Function.UniformIntegrable +public import Mathlib.Probability.Martingale.Convergence + +/-! +# L²-bounded discrete martingales converge in L² + +Mathlib's martingale convergence theory gives, for an L¹-bounded +submartingale, almost-everywhere convergence to `ℱ.limitProcess f μ` +(`Submartingale.ae_tendsto_limitProcess`), membership of the limit in `Lᵖ` +under an `Lᵖ` bound (`Submartingale.memLp_limitProcess`), and **L¹**-norm +convergence under uniform integrability +(`Submartingale.tendsto_eLpNorm_one_limitProcess`). It does **not** contain +the classical L² statement: an L²-bounded martingale converges in L²-norm. + +This file obtains uniform integrability from a square-integrable envelope. +Its finite-time bound is Tau Ceti's Doob inequality +`MeasureTheory.Martingale.eLpNorm_partialSups_norm_le`, used at `p = 2`. + +1. the running maxima `ω ↦ max_{k ≤ n} ‖f k ω‖` are uniformly L²-bounded by + `2R` (Doob at `p = 2`); +2. by monotone convergence the all-time envelope `ω ↦ ⨆ n ‖f n ω‖` is + square-integrable, and it dominates every `f n` — steps 1–2 are the `p = 2` + case of `MeasureTheory.LpDominator`, shared with + `LpContinuousMartingaleConvergence`; +3. a single L² dominator makes the family uniformly integrable in L² + (`MemLp.uniformIntegrable_of_eNorm_le` in Tau Ceti); +4. Vitali (`tendsto_Lp_finite_of_tendsto_ae`) upgrades the a.e. convergence + to L²-norm convergence. + +## Main results + +* `martingale_ae_tendsto_and_eLpNorm_two_tendsto` — for a martingale `f` + with `eLpNorm (f n) 2 μ ≤ R` for all `n`: a.e. convergence to + `ℱ.limitProcess f μ` **and** `eLpNorm (f n − ℱ.limitProcess f μ) 2 μ → 0`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Theorem 2.5.1 + +## Tags + +martingale convergence, L²-bounded martingale, Doob maximal inequality, uniform integrability, +Vitali theorem, MSC 60G42, MSC 60F15 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal Topology + +/-- **L² martingale convergence** (Saporito, Theorem 2.5.1, L² form). A +martingale bounded in L² converges to `ℱ.limitProcess f μ` almost everywhere +**and** in L²-norm. The a.e. half is Mathlib's upcrossing-based convergence; +an L² envelope from Tau Ceti's Doob bound dominates every `f n` +(`MeasureTheory.LpDominator`). The envelope gives uniform integrability in L², +and Vitali's convergence theorem gives L² convergence. -/ +theorem martingale_ae_tendsto_and_eLpNorm_two_tendsto + {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} [IsFiniteMeasure μ] + {ℱ : Filtration ℕ m0} {f : ℕ → Ω → ℝ} {R : ℝ≥0} + (hf : Martingale f ℱ μ) (hbdd : ∀ n, eLpNorm (f n) 2 μ ≤ R) : + (∀ᵐ ω ∂μ, Filter.Tendsto (fun n ↦ f n ω) Filter.atTop + (nhds (ℱ.limitProcess f μ ω))) ∧ + Filter.Tendsto (fun n ↦ eLpNorm (f n - ℱ.limitProcess f μ) 2 μ) + Filter.atTop (nhds 0) := by + have hmeas (n : ℕ) : AEStronglyMeasurable (f n) μ := + ((hf.stronglyMeasurable n).mono (ℱ.le n)).aestronglyMeasurable + -- L¹ bound from the L² bound on a finite measure + have hbdd1 : ∃ R₁ : ℝ≥0, ∀ n, eLpNorm (f n) 1 μ ≤ (R₁ : ℝ≥0∞) := by + set c : ℝ≥0∞ := μ Set.univ ^ (1 / (1 : ℝ≥0∞).toReal - 1 / (2 : ℝ≥0∞).toReal) + with hc_def + have hc_ne : c ≠ ∞ := by + rw [hc_def] + exact (ENNReal.rpow_lt_top_of_nonneg (by norm_num) (measure_ne_top μ _)).ne + refine ⟨((R : ℝ≥0∞) * c).toNNReal, fun n ↦ ?_⟩ + have h := eLpNorm_le_eLpNorm_mul_rpow_measure_univ (μ := μ) (p := 1) (q := 2) + one_le_two (hmeas n) + rw [ENNReal.coe_toNNReal (by finiteness)] + exact h.trans (mul_le_mul_left (hbdd n) _) + obtain ⟨R₁, hR₁⟩ := hbdd1 + have h_ae := hf.submartingale.ae_tendsto_limitProcess ((iSup_le hR₁).trans_lt ENNReal.coe_lt_top) + -- Doob's L² maximal inequality: the envelope `⨆ n ‖f n‖` is in L² and dominates every `f n` + have hb (n : ℕ) : eLpNorm (f n) (ENNReal.ofReal 2) μ ≤ ENNReal.ofReal R := by + simpa using hbdd n + have hdom : MemLp (LpDominator.dominator f) 2 μ := by + simpa using LpDominator.dominator_memLp one_lt_two hf hb + exact ⟨h_ae, tendsto_Lp_finite_of_tendsto_ae one_le_two ENNReal.ofNat_ne_top hmeas + (hf.submartingale.memLp_limitProcess ((iSup_le hbdd).trans_lt ENNReal.coe_lt_top)) + (hdom.uniformIntegrable_of_eNorm_le one_le_two ENNReal.ofNat_ne_top hmeas + (fun n ↦ (LpDominator.norm_le_dominator one_lt_two hf hb n).mono fun _ h ↦ by + simpa only [← ofReal_norm, Real.norm_eq_abs] using + ENNReal.ofReal_le_ofReal (h.trans (le_abs_self _)))).unifIntegrable h_ae⟩ + +end MathFin diff --git a/LeanPool/MathFin/Probability/Discrete/MarkovPathMeasure.lean b/LeanPool/MathFin/Probability/Discrete/MarkovPathMeasure.lean new file mode 100644 index 0000000000..75784bf09f --- /dev/null +++ b/LeanPool/MathFin/Probability/Discrete/MarkovPathMeasure.lean @@ -0,0 +1,223 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.CategoryTheory.Countable +public import Mathlib.Probability.Kernel.IonescuTulcea.Traj +public import Mathlib.Probability.ProbabilityMassFunction.Basic + +/-! +# The path distribution of a constructed Markov chain + +The forward direction of Saporito's Theorem 1.1.2 gives finite-path +factorization from the Markov property. For the time-homogeneous construction +in this file with initial law `λ` and transition law `P`, the factors give + + `P(X₀ = i₀, …, X_n = i_n) = λ(i₀) · ∏_{k simpa using markovPathMeasure_cylinder_zero init P path + | succ n ih => + rw [markovPathMeasure_cylinder_succ, ih, Finset.prod_range_succ, mul_assoc] + +end MathFin diff --git a/LeanPool/MathFin/Probability/Discrete/MartingaleDominator.lean b/LeanPool/MathFin/Probability/Discrete/MartingaleDominator.lean new file mode 100644 index 0000000000..20bc609904 --- /dev/null +++ b/LeanPool/MathFin/Probability/Discrete/MartingaleDominator.lean @@ -0,0 +1,182 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import TauCeti.Probability.Martingale.MaximalInequality.Lp +public import LeanPool.MathFin.Init + +/-! +# An all-time integrable martingale envelope + +A discrete martingale bounded in `Lᵖ`, for `p > 1`, is dominated by the real +supremum of its norms. The module uses Tau Ceti's finite-time maximal inequality +and monotone convergence to put this envelope in `Lᵖ`. +-/ + +@[expose] public section + +noncomputable section + +open Filter Finset Set +open scoped ENNReal Topology + +namespace MeasureTheory + +variable {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} + +namespace LpDominator + +variable {𝒢 : Filtration ℕ m0} {f : ℕ → Ω → ℝ} {p R : ℝ} + +/-- `maxₖ≤ₙ ‖f k ω‖`, the running max of the norms. -/ +private noncomputable def runMaxNorm (f : ℕ → Ω → ℝ) (n : ℕ) (ω : Ω) : ℝ := + (Finset.range (n + 1)).sup' Finset.nonempty_range_add_one (fun k ↦ ‖f k ω‖) + +omit [MeasurableSpace Ω] in +private lemma runMaxNorm_nonneg (f : ℕ → Ω → ℝ) (n : ℕ) (ω : Ω) : 0 ≤ runMaxNorm f n ω := + (norm_nonneg _).trans <| Finset.le_sup' (f := fun k ↦ ‖f k ω‖) + (Finset.mem_range.mpr (Nat.succ_pos n)) + +omit [MeasurableSpace Ω] in +private lemma runMaxNorm_mono (f : ℕ → Ω → ℝ) (ω : Ω) : Monotone (fun n ↦ runMaxNorm f n ω) := + fun _ _ hmn ↦ Finset.sup'_le _ _ fun k hk ↦ + Finset.le_sup' (f := fun k ↦ ‖f k ω‖) <| + Finset.mem_range.mpr <| (Finset.mem_range.mp hk).trans_le (by omega) + +/-- The all-time envelope `⨆ₖ ‖f k ω‖ₑ`, in `ℝ≥0∞`. -/ +noncomputable def enormSup (f : ℕ → Ω → ℝ) (ω : Ω) : ℝ≥0∞ := ⨆ k : ℕ, ‖f k ω‖ₑ + +lemma measurable_enormSup (hf : ∀ k, Measurable (f k)) : Measurable (enormSup f) := + Measurable.iSup fun k ↦ (hf k).eNorm + +/-- A nonnegative real power commutes with the supremum of a monotone sequence in `ℝ≥0∞`. -/ +lemma iSup_rpow_of_monotone {g : ℕ → ℝ≥0∞} (hg : Monotone g) (hp : 0 ≤ p) : + (⨆ n, g n) ^ p = ⨆ n, (g n) ^ p := + tendsto_nhds_unique + ((ENNReal.continuous_rpow_const.tendsto _).comp (tendsto_atTop_iSup hg)) + (tendsto_atTop_iSup fun _ _ hmn ↦ ENNReal.monotone_rpow_of_nonneg hp (hg hmn)) + +/-- `ENNReal.ofReal` commutes with the supremum over a nonempty finset. -/ +lemma ofReal_finset_sup' {ι : Type*} {s : Finset ι} (hs : s.Nonempty) (g : ι → ℝ) : + ENNReal.ofReal (s.sup' hs g) = s.sup' hs (fun i ↦ ENNReal.ofReal (g i)) := + Finset.apply_sup'_eq_sup'_comp hs ENNReal.ofReal ENNReal.ofReal_max + +omit [MeasurableSpace Ω] in +private lemma iSup_ofReal_runMaxNorm (f : ℕ → Ω → ℝ) (ω : Ω) : + (⨆ n : ℕ, ENNReal.ofReal (runMaxNorm f n ω)) = enormSup f ω := by + refine le_antisymm (iSup_le fun n ↦ ?_) (iSup_le fun k ↦ ?_) + · rw [runMaxNorm, ofReal_finset_sup'] + refine Finset.sup'_le _ _ fun k _ ↦ ?_ + rw [ofReal_norm] + exact le_iSup (fun j : ℕ ↦ ‖f j ω‖ₑ) k + · refine le_iSup_of_le k ?_ + rw [← ofReal_norm] + exact ENNReal.ofReal_le_ofReal <| + Finset.le_sup' (f := fun j ↦ ‖f j ω‖) (Finset.mem_range.mpr (Nat.lt_succ_self k)) + +private lemma measurable_runMaxNorm (hf : Martingale f 𝒢 μ) (n : ℕ) : + Measurable (runMaxNorm f n) := + Finset.measurable_range_sup'' (n := n) fun k _ ↦ + ((hf.stronglyMeasurable k).mono (𝒢.le k)).measurable.norm + +private lemma lintegral_ofReal_runMaxNorm_rpow_le [IsFiniteMeasure μ] (hp : 1 < p) + (hf : Martingale f 𝒢 μ) + (hbound : ∀ n, eLpNorm (f n) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) (n : ℕ) : + ∫⁻ ω, ENNReal.ofReal (runMaxNorm f n ω ^ p) ∂μ + ≤ (ENNReal.ofReal (p / (p - 1)) * ENNReal.ofReal R) ^ p := by + have hp_pos : 0 < p := lt_trans zero_lt_one hp + have hDoob : eLpNorm (fun ω ↦ runMaxNorm f n ω) (ENNReal.ofReal p) μ + ≤ ENNReal.ofReal (p / (p - 1)) * ENNReal.ofReal R := + by + have hp_enn : 1 < ENNReal.ofReal p := by + rwa [← ENNReal.ofReal_one, ENNReal.ofReal_lt_ofReal_iff hp_pos] + have h := hf.eLpNorm_partialSups_norm_le n hp_enn ENNReal.ofReal_ne_top + rw [← ENNReal.ofReal_div_sub_one hp] at h + have hr : partialSups (fun k ω ↦ ‖f k ω‖) n = fun ω ↦ runMaxNorm f n ω := by + ext ω + simp only [Pi.partialSups_apply, partialSups_apply, runMaxNorm, Nat.range_succ_eq_Iic] + rw [hr] at h + exact h.trans (by gcongr; exact hbound n) + rw [eLpNorm_eq_lintegral_rpow_eNorm_toReal (by simp [hp_pos]) ENNReal.ofReal_ne_top + (measurable_runMaxNorm hf n).aestronglyMeasurable, + ENNReal.toReal_ofReal hp_pos.le] at hDoob + have hpow := ENNReal.rpow_le_rpow hDoob hp_pos.le + rw [← ENNReal.rpow_mul, one_div, inv_mul_cancel₀ hp_pos.ne', ENNReal.rpow_one] at hpow + refine le_trans (le_of_eq <| lintegral_congr fun ω ↦ ?_) hpow + rw [Real.eNorm_of_nonneg (runMaxNorm_nonneg f n ω), + ENNReal.ofReal_rpow_of_nonneg (runMaxNorm_nonneg f n ω) hp_pos.le] + +/-- Monotone-convergence bound on `∫⁻ (enormSup f ω)^p ∂μ`. -/ +lemma lintegral_enormSup_rpow_le [IsFiniteMeasure μ] (hp : 1 < p) (hf : Martingale f 𝒢 μ) + (hbound : ∀ n, eLpNorm (f n) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) : + ∫⁻ ω, enormSup f ω ^ p ∂μ ≤ (ENNReal.ofReal (p / (p - 1)) * ENNReal.ofReal R) ^ p := by + have hp_pos : 0 < p := lt_trans zero_lt_one hp + set g : ℕ → Ω → ℝ≥0∞ := fun n ω ↦ ENNReal.ofReal (runMaxNorm f n ω) + have hg_mono : ∀ ω, Monotone (fun n ↦ g n ω) := fun ω _ _ hmn ↦ + ENNReal.ofReal_le_ofReal (runMaxNorm_mono f ω hmn) + have h_meas : ∀ n, AEMeasurable (fun ω ↦ g n ω ^ p) μ := fun n ↦ + ((ENNReal.continuous_rpow_const.measurable.comp + (measurable_runMaxNorm hf n).ennreal_ofReal)).aemeasurable + rw [show (fun ω ↦ enormSup f ω ^ p) = fun ω ↦ ⨆ n, g n ω ^ p from + funext fun ω ↦ by rw [← iSup_ofReal_runMaxNorm, iSup_rpow_of_monotone (hg_mono ω) hp_pos.le]] + rw [lintegral_iSup' h_meas (Filter.Eventually.of_forall fun ω _ _ hmn ↦ + ENNReal.monotone_rpow_of_nonneg hp_pos.le (hg_mono ω hmn))] + refine iSup_le fun n ↦ ?_ + simp_rw [show ∀ ω, g n ω ^ p = ENNReal.ofReal (runMaxNorm f n ω ^ p) from fun ω ↦ + ENNReal.ofReal_rpow_of_nonneg (runMaxNorm_nonneg f n ω) hp_pos.le] + exact lintegral_ofReal_runMaxNorm_rpow_le hp hf hbound n + +private lemma enormSup_rpow_lintegral_lt_top [IsFiniteMeasure μ] (hp : 1 < p) + (hf : Martingale f 𝒢 μ) + (hbound : ∀ n, eLpNorm (f n) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) : + ∫⁻ ω, enormSup f ω ^ p ∂μ < ⊤ := + (lintegral_enormSup_rpow_le hp hf hbound).trans_lt <| + ENNReal.rpow_lt_top_of_nonneg (lt_trans zero_lt_one hp).le + (ENNReal.mul_ne_top ENNReal.ofReal_ne_top ENNReal.ofReal_ne_top) + +lemma enormSup_lt_top_ae [IsFiniteMeasure μ] (hp : 1 < p) (hf : Martingale f 𝒢 μ) + (hbound : ∀ n, eLpNorm (f n) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) : + ∀ᵐ ω ∂μ, enormSup f ω < ⊤ := by + have hp_pos : 0 < p := lt_trans zero_lt_one hp + filter_upwards [ae_lt_top ((measurable_enormSup fun k ↦ + ((hf.stronglyMeasurable k).mono (𝒢.le k)).measurable).pow_const p) + (enormSup_rpow_lintegral_lt_top hp hf hbound).ne] with ω hω + exact (ENNReal.rpow_lt_top_iff_of_pos hp_pos).mp hω + +/-- The real-valued envelope `f*(ω) = (⨆ₖ ‖f k ω‖ₑ).toReal`. -/ +noncomputable def dominator (f : ℕ → Ω → ℝ) (ω : Ω) : ℝ := (enormSup f ω).toReal + +lemma measurable_dominator (hf : ∀ k, Measurable (f k)) : Measurable (dominator f) := + (measurable_enormSup hf).ennreal_toReal + +lemma dominator_memLp [IsFiniteMeasure μ] (hp : 1 < p) (hf : Martingale f 𝒢 μ) + (hbound : ∀ n, eLpNorm (f n) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) : + MemLp (dominator f) (ENNReal.ofReal p) μ := by + have hp_pos : 0 < p := lt_trans zero_lt_one hp + have hmeas : AEStronglyMeasurable (dominator f) μ := + (measurable_dominator fun k ↦ + ((hf.stronglyMeasurable k).mono (𝒢.le k)).measurable).aestronglyMeasurable + rw [memLp_iff, eLpNorm_eq_lintegral_rpow_eNorm_toReal (by simp [hp_pos]) ENNReal.ofReal_ne_top + hmeas, ENNReal.toReal_ofReal hp_pos.le] + refine ENNReal.rpow_lt_top_of_nonneg (by positivity) (lt_of_le_of_lt ?_ + (enormSup_rpow_lintegral_lt_top hp hf hbound)).ne + refine lintegral_mono fun ω ↦ ENNReal.rpow_le_rpow ?_ hp_pos.le + rw [dominator, Real.eNorm_of_nonneg ENNReal.toReal_nonneg] + exact ENNReal.ofReal_toReal_le + +lemma norm_le_dominator [IsFiniteMeasure μ] (hp : 1 < p) (hf : Martingale f 𝒢 μ) + (hbound : ∀ n, eLpNorm (f n) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) (n : ℕ) : + ∀ᵐ ω ∂μ, ‖f n ω‖ ≤ dominator f ω := by + filter_upwards [enormSup_lt_top_ae hp hf hbound] with ω hlt + rw [show ‖f n ω‖ = (‖f n ω‖ₑ).toReal by + rw [Real.eNorm_eq_ofReal_abs, ENNReal.toReal_ofReal (abs_nonneg _), Real.norm_eq_abs]] + exact ENNReal.toReal_mono hlt.ne <| le_iSup (fun k : ℕ ↦ ‖f k ω‖ₑ) n + +end LpDominator + +end MeasureTheory diff --git a/LeanPool/MathFin/Probability/Discrete/MartingaleTransform.lean b/LeanPool/MathFin/Probability/Discrete/MartingaleTransform.lean new file mode 100644 index 0000000000..d6743698a2 --- /dev/null +++ b/LeanPool/MathFin/Probability/Discrete/MartingaleTransform.lean @@ -0,0 +1,193 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Martingale.Basic + +/-! +# Martingale transform (Theorem 2.2.9) + +The martingale transform of a martingale by a bounded predictable process is +itself a martingale (the discrete stochastic integral). + +The price `M` and the holding `A` take values in a real inner-product space `F`, and a step's +gain is the pairing `⟪A_{k+1}, M_{k+1} − M_k⟫` (a portfolio of several assets against the vector +of their price increments), so the transform is real-valued. The scalar theorem is the case +`F = ℝ`, where `⟪a, b⟫ = a * b` (`Real.inner_apply`): `A_{k+1} * (M_{k+1} − M_k)`. + +## Main definitions + +* `martingaleTransform`: the discrete stochastic integral + `(A · M)_n = ∑_{k Z i + | n + 1, i => fun ω ↦ + if i ∈ X then max (Z i ω) (P[snellEnvelopeAux P 𝓕 X Z n (i + 1) | 𝓕 i] ω) + else P[snellEnvelopeAux P 𝓕 X Z n (i + 1) | 𝓕 i] ω + +/-- The **Snell envelope** of `Z` for the horizon `N`, exercise times `X`: the recursion run for +the `N - i` remaining steps from `min i N`, so it is frozen at `Z N` past the horizon. -/ +noncomputable def snellEnvelope (P : Measure Ω) (𝓕 : Filtration ℕ ‹MeasurableSpace Ω›) + (X : Set ℕ) (Z : ℕ → Ω → ℝ) (N i : ℕ) : Ω → ℝ := + snellEnvelopeAux P 𝓕 X Z (N - i) (min i N) + +theorem snellEnvelopeAux_succ_of_mem {n i : ℕ} (hi : i ∈ X) : + snellEnvelopeAux P 𝓕 X Z (n + 1) i = + fun ω ↦ max (Z i ω) (P[snellEnvelopeAux P 𝓕 X Z n (i + 1) | 𝓕 i] ω) := by + rw [snellEnvelopeAux] + exact funext fun ω ↦ ite_eq_left hi + +theorem snellEnvelopeAux_succ_of_notMem {n i : ℕ} (hi : i ∉ X) : + snellEnvelopeAux P 𝓕 X Z (n + 1) i = P[snellEnvelopeAux P 𝓕 X Z n (i + 1) | 𝓕 i] := by + rw [snellEnvelopeAux] + exact funext fun ω ↦ ite_eq_right hi + +theorem snellEnvelopeAux_measurable (hZ : Adapted 𝓕 Z) (n i : ℕ) : + Measurable[𝓕 i] (snellEnvelopeAux P 𝓕 X Z n i) := by + cases n with + | zero => exact hZ i + | succ n => + by_cases hi : i ∈ X + · rw [snellEnvelopeAux_succ_of_mem hi] + exact (hZ i).max stronglyMeasurable_condExp.measurable + · rw [snellEnvelopeAux_succ_of_notMem hi] + exact stronglyMeasurable_condExp.measurable + +theorem snellEnvelopeAux_integrable (hZ : ∀ i, Integrable (Z i) P) (n i : ℕ) : + Integrable (snellEnvelopeAux P 𝓕 X Z n i) P := by + cases n with + | zero => exact hZ i + | succ n => + by_cases hi : i ∈ X + · rw [snellEnvelopeAux_succ_of_mem hi] + exact (hZ i).sup integrable_condExp + · rw [snellEnvelopeAux_succ_of_notMem hi] + exact integrable_condExp + +/-- At the horizon and at the exercise times the envelope dominates the reward. -/ +theorem snellEnvelopeAux_dominates {n i : ℕ} (h : n = 0 ∨ i ∈ X) (ω : Ω) : + Z i ω ≤ snellEnvelopeAux P 𝓕 X Z n i ω := by + cases n with + | zero => exact le_rfl + | succ n => + rw [snellEnvelopeAux_succ_of_mem (h.resolve_left n.succ_ne_zero)] + exact le_max_left _ _ + +/-- The continuation value is at most the envelope: the supermartingale step. -/ +theorem snellEnvelopeAux_condExp_le (n i : ℕ) (ω : Ω) : + P[snellEnvelopeAux P 𝓕 X Z n (i + 1) | 𝓕 i] ω ≤ snellEnvelopeAux P 𝓕 X Z (n + 1) i ω := by + by_cases hi : i ∈ X + · rw [snellEnvelopeAux_succ_of_mem hi] + exact le_max_right _ _ + · rw [snellEnvelopeAux_succ_of_notMem hi] + +theorem snellEnvelope_after_horizon {N i : ℕ} (hNi : N ≤ i) : + snellEnvelope P 𝓕 X Z N i = Z N := by + simp only [snellEnvelope, Nat.sub_eq_zero_of_le hNi, min_eq_right hNi, snellEnvelopeAux] + +theorem snellEnvelope_succ_of_mem {N i : ℕ} (hi : i < N) (hX : i ∈ X) : + snellEnvelope P 𝓕 X Z N i = + fun ω ↦ max (Z i ω) (P[snellEnvelope P 𝓕 X Z N (i + 1) | 𝓕 i] ω) := by + have hn : N - i = (N - (i + 1)) + 1 := by omega + rw [snellEnvelope, min_eq_left hi.le, hn, snellEnvelopeAux_succ_of_mem hX] + simp only [snellEnvelope, min_eq_left (show i + 1 ≤ N by omega)] + +theorem snellEnvelope_succ_of_notMem {N i : ℕ} (hi : i < N) (hX : i ∉ X) : + snellEnvelope P 𝓕 X Z N i = P[snellEnvelope P 𝓕 X Z N (i + 1) | 𝓕 i] := by + have hn : N - i = (N - (i + 1)) + 1 := by omega + rw [snellEnvelope, min_eq_left hi.le, hn, snellEnvelopeAux_succ_of_notMem hX] + simp only [snellEnvelope, min_eq_left (show i + 1 ≤ N by omega)] + +theorem snellEnvelope_stronglyAdapted (hZ : Adapted 𝓕 Z) (N : ℕ) : + StronglyAdapted 𝓕 (snellEnvelope P 𝓕 X Z N) := fun i ↦ + ((snellEnvelopeAux_measurable hZ (N - i) (min i N)).mono (𝓕.mono (min_le_left _ _)) + le_rfl).stronglyMeasurable + +theorem snellEnvelope_integrable (hZ : ∀ i, Integrable (Z i) P) (N i : ℕ) : + Integrable (snellEnvelope P 𝓕 X Z N i) P := + snellEnvelopeAux_integrable hZ _ _ + +/-- The envelope dominates the reward at the exercise times and past the horizon. -/ +theorem snellEnvelope_dominates {N i : ℕ} (h : i ∈ X ∨ N ≤ i) (ω : Ω) : + Z (min i N) ω ≤ snellEnvelope P 𝓕 X Z N i ω := by + rcases le_or_gt N i with hNi | hiN + · exact snellEnvelopeAux_dominates (Or.inl (Nat.sub_eq_zero_of_le hNi)) ω + · exact snellEnvelopeAux_dominates + (Or.inr (by rw [min_eq_left hiN.le]; exact h.resolve_right hiN.not_ge)) ω + +/-- **Minimality**: an integrable supermartingale `U` that dominates the reward almost surely at +the exercise times in `[i, i + n)` and at time `i + n` dominates the envelope with `n` steps +left from `i`. -/ +theorem snellEnvelopeAux_le_supermartingale {U : ℕ → Ω → ℝ} (hU : Supermartingale U 𝓕 P) + (hi : ∀ i, Integrable (Z i) P) (n i : ℕ) + (hdom : ∀ j, i ≤ j → j ≤ i + n → (j ∈ X ∨ j = i + n) → Z j ≤ᵐ[P] U j) : + snellEnvelopeAux P 𝓕 X Z n i ≤ᵐ[P] U i := by + induction n generalizing i with + | zero => exact hdom i le_rfl le_rfl (Or.inr rfl) + | succ n ih => + have hc := condExp_mono (m := 𝓕 i) (snellEnvelopeAux_integrable hi n (i + 1)) + (hU.integrable (i + 1)) + (ih (i + 1) fun j hj hjn h ↦ hdom j (i.le_succ.trans hj) (by omega) + (h.imp_right fun h ↦ by omega)) + by_cases hX : i ∈ X + · rw [snellEnvelopeAux_succ_of_mem hX] + filter_upwards [hdom i le_rfl (by omega) (Or.inl hX), hc, hU.2.1 i (i + 1) i.le_succ] + with ω hz hc hu + exact max_le hz (hc.trans hu) + · rw [snellEnvelopeAux_succ_of_notMem hX] + filter_upwards [hc, hU.2.1 i (i + 1) i.le_succ] with ω hc hu + exact hc.trans hu + +/-- **The Snell envelope is the smallest supermartingale** dominating the reward (almost surely) +at the exercise times up to the horizon `N` and at `N`. -/ +theorem snellEnvelope_le_supermartingale {N : ℕ} {U : ℕ → Ω → ℝ} (hU : Supermartingale U 𝓕 P) + (hi : ∀ i, Integrable (Z i) P) (hdom : ∀ j ≤ N, (j ∈ X ∨ j = N) → Z j ≤ᵐ[P] U j) + {i : ℕ} (hiN : i ≤ N) : snellEnvelope P 𝓕 X Z N i ≤ᵐ[P] U i := by + simpa only [snellEnvelope, min_eq_left hiN] using + snellEnvelopeAux_le_supermartingale hU hi (N - i) i fun j hij hj h ↦ + hdom j (by omega) (h.imp_right fun h ↦ by omega) + +/-- The envelope is positively homogeneous in the reward. -/ +theorem snellEnvelopeAux_const_mul {a : ℝ} (ha : 0 ≤ a) (n i : ℕ) : + snellEnvelopeAux P 𝓕 X (fun j ω ↦ a * Z j ω) n i =ᵐ[P] + fun ω ↦ a * snellEnvelopeAux P 𝓕 X Z n i ω := by + induction n generalizing i with + | zero => exact Eventually.of_forall fun _ ↦ rfl + | succ n ih => + have hc := condExp_congr_ae (m := 𝓕 i) (ih (i + 1)) + have hm := condExp_smul (μ := P) a (snellEnvelopeAux P 𝓕 X Z n (i + 1)) (𝓕 i) + by_cases hX : i ∈ X + · rw [snellEnvelopeAux_succ_of_mem hX, snellEnvelopeAux_succ_of_mem hX] + filter_upwards [hc, hm] with ω hω hmω + rw [hω] + change P[fun ω ↦ a * snellEnvelopeAux P 𝓕 X Z n (i + 1) ω | 𝓕 i] ω = _ at hmω + rw [hmω] + exact (mul_max_of_nonneg _ _ ha).symm + · rw [snellEnvelopeAux_succ_of_notMem hX, snellEnvelopeAux_succ_of_notMem hX] + filter_upwards [hc, hm] with ω hω hmω + rw [hω] + exact hmω + +variable [IsProbabilityMeasure P] + +/-- **The Snell envelope is a supermartingale.** -/ +theorem snellEnvelope_supermartingale (hZ : Adapted 𝓕 Z) (hi : ∀ i, Integrable (Z i) P) + (N : ℕ) : Supermartingale (snellEnvelope P 𝓕 X Z N) 𝓕 P := by + refine supermartingale_nat (snellEnvelope_stronglyAdapted hZ N) (snellEnvelope_integrable hi N) + fun i ↦ ?_ + by_cases hiN : i < N + · by_cases hX : i ∈ X + · rw [snellEnvelope_succ_of_mem hiN hX] + exact Eventually.of_forall fun ω ↦ le_max_right _ _ + · rw [snellEnvelope_succ_of_notMem hiN hX] + · have hNi : N ≤ i := le_of_not_gt hiN + rw [snellEnvelope_after_horizon hNi, snellEnvelope_after_horizon (hNi.trans i.le_succ), + condExp_of_stronglyMeasurable (𝓕.le i) + (((hZ N).mono (𝓕.mono hNi) le_rfl).stronglyMeasurable) (hi N)] + +end MathFin diff --git a/LeanPool/MathFin/Probability/Gaussian/BivariateGaussian.lean b/LeanPool/MathFin/Probability/Gaussian/BivariateGaussian.lean new file mode 100644 index 0000000000..457debcfc9 --- /dev/null +++ b/LeanPool/MathFin/Probability/Gaussian/BivariateGaussian.lean @@ -0,0 +1,205 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.ConditionalExpectation +public import Mathlib.Probability.Distributions.Gaussian.HasGaussianLaw.Basic +public import Mathlib.Probability.Distributions.Gaussian.HasGaussianLaw.Independence + +/-! +# Conditional expectation of a bivariate Gaussian + +For `(X, Y)` jointly Gaussian with means `μ_X, μ_Y`, `Var Y = σ_Y² > 0` and +`Cov(X, Y) = ρ σ_X σ_Y` with `σ_X > 0` (`BivariateGaussianHyp`): + + E[X | σ(Y)] = μ_X + (ρ σ_X / σ_Y) (Y − μ_Y) a.s. + +The hypotheses do not ask that `Var X = σ_X²` or `|ρ| < 1`: only the covariance of `X` with `Y` +enters. The standard bivariate normal law of `Probability/Gaussian/BivariateNormalCDF.lean` +satisfies them (`bivariateGaussianHyp_bivariateNormalLaw`), giving `E[X | Y] = r Y` there. + +## Main definitions + +* `BivariateGaussianHyp`: the hypotheses of the conditional-expectation formula for a pair + `(X, Y)` with means `μ_X, μ_Y`, `Var Y = σ_Y² > 0` and `Cov(X, Y) = ρ σ_X σ_Y`. + +## Main results + +* `conditional_expectation_formula`: under `BivariateGaussianHyp`, + `E[X | σ(Y)] = μ_X + (ρ σ_X / σ_Y) (Y − μ_Y)` almost surely. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Theorem B.1.3(2), p. 177. + The printed coefficient uses `Σ_XX` in the numerator. The scalar identity + here uses the cross-covariance, the scalar instance of `Σ_XY Σ_YY⁻¹`. + +## Tags + +conditional expectation, jointly Gaussian, regression coefficient, correlation, bivariate normal, +MSC 60E05, MSC 60G15 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory + +/-- Hypotheses for the bivariate Gaussian conditional-expectation formula. -/ +structure BivariateGaussianHyp {Ω : Type*} {mΩ : MeasurableSpace Ω} + (P : Measure Ω) [IsProbabilityMeasure P] + (X Y : Ω → ℝ) (μ_X μ_Y σ_X σ_Y ρ : ℝ) : Prop where + σ_X_pos : 0 < σ_X + σ_Y_pos : 0 < σ_Y + X_meas : Measurable X + Y_meas : Measurable Y + /-- (X, Y) is jointly Gaussian. -/ + joint_gaussian : HasGaussianLaw (fun ω ↦ (X ω, Y ω)) P + /-- Marginal mean of X. -/ + mean_X : ∫ ω, X ω ∂P = μ_X + /-- Marginal mean of Y. -/ + mean_Y : ∫ ω, Y ω ∂P = μ_Y + /-- Variance of Y is σ_Y². -/ + var_Y : Var[Y; P] = σ_Y ^ 2 + /-- Cov(X, Y) = ρ σ_X σ_Y. -/ + cov_XY : cov[X, Y; P] = ρ * σ_X * σ_Y + +namespace BivariateGaussianHyp + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + {P : Measure Ω} [IsProbabilityMeasure P] + {X Y : Ω → ℝ} {μ_X μ_Y σ_X σ_Y ρ : ℝ} + +/-- The continuous linear map `(x, y) ↦ (x - β y, y)`. -/ +private noncomputable def linearShift (β : ℝ) : ℝ × ℝ →L[ℝ] ℝ × ℝ := + (ContinuousLinearMap.fst ℝ ℝ ℝ - β • ContinuousLinearMap.snd ℝ ℝ ℝ).prod + (ContinuousLinearMap.snd ℝ ℝ ℝ) + +/-- Pointwise-evaluation lemma for `linearShift` to keep proofs readable. -/ +@[simp] private lemma linearShift_apply (β : ℝ) (p : ℝ × ℝ) : + linearShift β p = (p.1 - β * p.2, p.2) := by + simp [linearShift] + +/-- Conditional expectation formula for a bivariate Gaussian. -/ +theorem conditional_expectation_formula + (h : BivariateGaussianHyp P X Y μ_X μ_Y σ_X σ_Y ρ) : + (P[X | MeasurableSpace.comap Y inferInstance]) + =ᵐ[P] fun ω ↦ μ_X + (ρ * σ_X / σ_Y) * (Y ω - μ_Y) := by + set β : ℝ := ρ * σ_X / σ_Y with hβ_def + set Xhat : Ω → ℝ := fun ω ↦ μ_X + β * (Y ω - μ_Y) + have hY_le : MeasurableSpace.comap Y inferInstance ≤ mΩ := by + rintro s ⟨t, ht, rfl⟩ + exact h.Y_meas ht + have hY_smeas_comap : StronglyMeasurable[MeasurableSpace.comap Y inferInstance] Y := + (Measurable.of_comap_le le_rfl).stronglyMeasurable + have hXhat_smeas : StronglyMeasurable[MeasurableSpace.comap Y inferInstance] Xhat := by + refine StronglyMeasurable.add stronglyMeasurable_const ?_ + refine StronglyMeasurable.const_mul ?_ β + exact hY_smeas_comap.sub stronglyMeasurable_const + have hX_int : Integrable X P := h.joint_gaussian.fst.integrable + have hY_int : Integrable Y P := h.joint_gaussian.snd.integrable + have hXhat_int : Integrable Xhat P := by + refine Integrable.add (integrable_const _) ?_ + exact (hY_int.sub (integrable_const _)).const_mul β + have h_condXhat : P[Xhat | MeasurableSpace.comap Y inferInstance] = Xhat := + condExp_of_stronglyMeasurable hY_le hXhat_smeas hXhat_int + have hPair_eq : + (fun ω ↦ (X ω - β * Y ω, Y ω)) + = (linearShift β) ∘ (fun ω ↦ (X ω, Y ω)) := by + funext ω + simp [Function.comp] + have h_jointGaussian_diff : HasGaussianLaw (fun ω ↦ (X ω - β * Y ω, Y ω)) P := by + rw [hPair_eq] + exact h.joint_gaussian.map_of_measurable (linearShift β) + (linearShift β).continuous.measurable + have hcov_zero : cov[fun ω ↦ X ω - β * Y ω, Y; P] = 0 := by + have h_memLp_X : MemLp X 2 P := h.joint_gaussian.fst.memLp_two + have h_memLp_Y : MemLp Y 2 P := h.joint_gaussian.snd.memLp_two + have h_memLp_betaY : MemLp (fun ω ↦ β * Y ω) 2 P := h_memLp_Y.const_mul β + rw [show (fun ω ↦ X ω - β * Y ω) = (fun ω ↦ X ω) - (fun ω ↦ β * Y ω) from rfl] + rw [covariance_sub_left h_memLp_X h_memLp_betaY h_memLp_Y] + rw [show (fun ω ↦ β * Y ω) = β • Y from by + funext ω + simp [Pi.smul_apply, smul_eq_mul]] + rw [covariance_smul_left, h.cov_XY, + show cov[Y, Y; P] = Var[Y; P] from covariance_self h_memLp_Y.aemeasurable, + h.var_Y] + have hY_ne : σ_Y ≠ 0 := ne_of_gt h.σ_Y_pos + rw [hβ_def] + field_simp + ring + have hIndep : IndepFun (fun ω ↦ X ω - β * Y ω) Y P := + h_jointGaussian_diff.indepFun_of_covariance_eq_zero hcov_zero + have h_diff_meas : Measurable (fun ω ↦ X ω - β * Y ω) := + h.X_meas.sub (h.Y_meas.const_mul β) + have h_diff_smeas_comap : + StronglyMeasurable[MeasurableSpace.comap (fun ω ↦ X ω - β * Y ω) (borel ℝ)] + (fun ω ↦ X ω - β * Y ω) := + (Measurable.of_comap_le le_rfl).stronglyMeasurable + have h_diff_le_comap : + MeasurableSpace.comap (fun ω ↦ X ω - β * Y ω) (borel ℝ) ≤ mΩ := + h_diff_meas.comap_le + have h_indep_sigma : + Indep (MeasurableSpace.comap (fun ω ↦ X ω - β * Y ω) (borel ℝ)) + (MeasurableSpace.comap Y inferInstance) P := + (IndepFun_iff_Indep _ _ _).mp hIndep + have hE_diff : ∫ ω, X ω - β * Y ω ∂P = μ_X - β * μ_Y := by + rw [integral_sub hX_int (hY_int.const_mul β), integral_const_mul, h.mean_X, h.mean_Y] + have h_int_diff : Integrable (fun ω ↦ X ω - β * Y ω) P := + hX_int.sub (hY_int.const_mul β) + have h_condDiff : + P[fun ω ↦ X ω - β * Y ω | (MeasurableSpace.comap Y inferInstance)] + =ᵐ[P] fun _ ↦ μ_X - β * μ_Y := by + have := condExp_indep_eq h_diff_le_comap hY_le h_diff_smeas_comap h_indep_sigma + rw [hE_diff] at this + exact this + have h_X_decomp : (X : Ω → ℝ) = Xhat + (fun ω ↦ X ω - β * Y ω - (μ_X - β * μ_Y)) := by + funext ω + change X ω = (μ_X + β * (Y ω - μ_Y)) + (X ω - β * Y ω - (μ_X - β * μ_Y)) + ring + have h_cond_split : + P[X | MeasurableSpace.comap Y inferInstance] + =ᵐ[P] (P[Xhat | MeasurableSpace.comap Y inferInstance]) + + (P[fun ω ↦ X ω - β * Y ω - (μ_X - β * μ_Y) + | MeasurableSpace.comap Y inferInstance]) := by + conv_lhs => rw [h_X_decomp] + exact condExp_add hXhat_int (h_int_diff.sub (integrable_const _)) _ + have h_cond_centered : + P[fun ω ↦ X ω - β * Y ω - (μ_X - β * μ_Y) + | MeasurableSpace.comap Y inferInstance] + =ᵐ[P] fun _ ↦ (0 : ℝ) := by + have h1 : P[fun ω ↦ X ω - β * Y ω - (μ_X - β * μ_Y) + | MeasurableSpace.comap Y inferInstance] + =ᵐ[P] + (P[fun ω ↦ X ω - β * Y ω | MeasurableSpace.comap Y inferInstance]) + - P[fun _ : Ω ↦ μ_X - β * μ_Y | MeasurableSpace.comap Y inferInstance] := + condExp_sub h_int_diff (integrable_const _) _ + have h2 : P[fun _ : Ω ↦ μ_X - β * μ_Y | MeasurableSpace.comap Y inferInstance] + = fun _ ↦ μ_X - β * μ_Y := + condExp_const hY_le (μ_X - β * μ_Y) + filter_upwards [h1, h_condDiff] with ω hω1 hω2 + show _ = (0 : ℝ) + rw [hω1, Pi.sub_apply, hω2, h2] + ring + refine h_cond_split.trans ?_ + filter_upwards [h_cond_centered] with ω hω + change ((P[Xhat | MeasurableSpace.comap Y inferInstance]) + + (P[fun ω ↦ X ω - β * Y ω - (μ_X - β * μ_Y) + | MeasurableSpace.comap Y inferInstance])) ω + = μ_X + (ρ * σ_X / σ_Y) * (Y ω - μ_Y) + simp only [Pi.add_apply] + rw [hω, h_condXhat] + change (μ_X + β * (Y ω - μ_Y)) + (0 : ℝ) = μ_X + (ρ * σ_X / σ_Y) * (Y ω - μ_Y) + rw [hβ_def] + ring + +end BivariateGaussianHyp + +end MathFin diff --git a/LeanPool/MathFin/Probability/Gaussian/BivariateNormalCDF.lean b/LeanPool/MathFin/Probability/Gaussian/BivariateNormalCDF.lean new file mode 100644 index 0000000000..a93728a225 --- /dev/null +++ b/LeanPool/MathFin/Probability/Gaussian/BivariateNormalCDF.lean @@ -0,0 +1,627 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Gaussian.NormalQuantile +public import LeanPool.MathFin.Probability.Gaussian.BivariateGaussian +public import Mathlib.Probability.Distributions.Gaussian.CharFun +public import Mathlib.Probability.Distributions.Gaussian.Fernique +public import Mathlib.Topology.UniformSpace.Uniformizable + +/-! +# The standard bivariate normal CDF `N₂(a, b; r)` + +For independent standard normals `Z₁, Z₂` (the coordinates of `N(0,1) ⊗ N(0,1)`) and +`r ∈ [-1, 1]`, the Cholesky construction + + X = r Z₂ + √(1 − r²) Z₁, Y = Z₂ + +gives a standard bivariate normal pair with correlation `r`, and +`N₂(a, b; r) = P(X ≤ a, Y ≤ b)`. + +The Cholesky map is a continuous linear map, so `bivariateNormalLaw r` is Gaussian in Mathlib's +sense (`IsGaussian`, via `isGaussian_map` and Mathlib's instance for products of Gaussian +measures). A Gaussian measure is determined by its mean and covariance (Mathlib's +characteristic-function `Measure.ext_of_charFunDual` with `IsGaussian.charFunDual_eq'`); on `ℝ²` +this says that a centred Gaussian law with unit variances and covariance `r` is +`bivariateNormalLaw r` (`eq_bivariateNormalLaw`). The swap symmetry is derived from it. + +## Main definitions + +* `stdNormalPair`: the law `N(0,1) ⊗ N(0,1)` of two independent standard normals on `ℝ × ℝ`. +* `stdNormalVec`: the law of a vector of independent standard normals indexed by a finite type. +* `choleskyPair`: the continuous linear map `(z₁, z₂) ↦ (r z₂ + √(1 − r²) z₁, z₂)`. +* `bivariateNormalLaw`: the law of the Cholesky pair; for `r² ≤ 1` the standard bivariate normal + law with correlation `r`. +* `bivariateNormalCDF`: `N₂(a, b; r) = P(X ≤ a, Y ≤ b)` for the Cholesky pair `(X, Y)`. +* `gaussianPair`: the Cholesky pair shifted and scaled, coordinate `i` being `μᵢ + σᵢ Zᵢ`. + +## Main results + +* `stdNormalPair`, `map_linear_stdNormalPair`: `c Z₁ + d Z₂ ∼ N(0, c² + d²)`. +* `stdNormalVec ι`: the law `N(0, 1)^ι` of a vector of independent standard normals, and its + `IsGaussian` instance (Mathlib's `iIndepFun.hasGaussianLaw`). Pushed to + `EuclideanSpace ℝ ι` it is Mathlib's `stdGaussian` (`map_pi_eq_stdGaussian`). +* `isGaussian_bivariateNormalLaw`: the law of the Cholesky pair is Gaussian, for every `r`. +* `covariance_fst_snd_bivariateNormalLaw`, `variance_snd_bivariateNormalLaw`: `Cov(X, Y) = r` and + `Var Y = 1` for every `r`; `variance_fst_bivariateNormalLaw`: `Var X = 1` for `r² ≤ 1`. +* `map_fst_bivariateNormalLaw`, `map_snd_bivariateNormalLaw`: both margins are `N(0, 1)`, read + off Mathlib's `IsGaussian.map_eq_gaussianReal`. +* `eq_bivariateNormalLaw`: a Gaussian law on `ℝ²` with centred coordinates, unit variances and + covariance `r` (`r² ≤ 1`) is `bivariateNormalLaw r`. +* `gaussianPair`, `hasGaussianLaw_gaussianPair`, `integral_gaussianPair`, + `variance_gaussianPair`, `covariance_gaussianPair`: `(μ₀ + σ₀ X, μ₁ + σ₁ Y)` is a Gaussian pair + with means `μ`, variances `σ²` and covariance `r σ₀ σ₁` (`r² ≤ 1` for the variances), so every + two-asset Gaussian model has a realization. +* `bivariateGaussianHyp_bivariateNormalLaw`, `condExp_fst_bivariateNormalLaw`: the pair satisfies + the hypotheses `BivariateGaussianHyp` of `Probability/Gaussian/BivariateGaussian.lean`, so + `E[X | Y] = r Y` almost surely. +* `bivariateNormalLaw_map_swap`, `bivariateNormalCDF_comm`: `(Y, X)` has the same law as + `(X, Y)`, so `N₂(a, b; r) = N₂(b, a; r)`. +* `bivariateNormalCDF_zero`, `bivariateNormalCDF_one`, `bivariateNormalCDF_neg_one`: the + independent, comonotone and countermonotone cases; `posPart_Phi_sub_Phi`: + `(Φ(t) − Φ(k))⁺` is the standard normal probability of `(k, t]`. +* `bivariateNormalCDF_flip_snd`: **`N₂(a, b; r) + N₂(a, -b; -r) = Φ(a)`**, the two-asset + analogue of `Phi_add_Phi_neg` — the key algebraic ingredient behind exact two-asset closed + forms (Stulz 1982, Heynen & Kat 1994/96) that package `N₂(·,·;ρ)` / `N₂(·,·;-ρ)` pairs. +* `bivariateNormalCDF_neg_neg`: **`N₂(-a, -b; r) = 1 - Φ(a) - Φ(b) + N₂(a, b; r)`**, the joint + survival identity, derived purely algebraically from `bivariateNormalCDF_flip_snd`, + `bivariateNormalCDF_comm` and `Phi_neg` (no new measure-theoretic argument). Reading either + side as the joint survival `P(X > a, Y > b)` is not stated here. + +Outside `r ∈ [-1, 1]` the square root truncates to `0` and the construction is no longer the +standard bivariate normal with correlation `r` (it degenerates to the law of `(rY, Y)`, still with +`Cov(X, Y) = r` but `Var X = r²`); every result that needs unit variances carries the hypothesis +`r ^ 2 ≤ 1`. + +Mathlib's `ProbabilityTheory.multivariateGaussian` lives on `EuclideanSpace ℝ (Fin 2)` rather +than `ℝ × ℝ`; the identification of `bivariateNormalLaw r` with it is not stated here. + +## References + +* [P. Billingsley, *Probability and Measure*][Billingsley1995], §29 + +## Tags + +bivariate normal distribution, Cholesky construction, correlation, Gaussian vector, +two-asset option, joint distribution function, MSC 60E05, MSC 60G15, JEL C02 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real Set + +/-- The law of two independent standard normals, `N(0,1) ⊗ N(0,1)`. It is Gaussian by Mathlib's +instance for products of Gaussian measures. -/ +noncomputable abbrev stdNormalPair : Measure (ℝ × ℝ) := (gaussianReal 0 1).prod (gaussianReal 0 1) + +/-- The law of a vector of independent standard normals indexed by `ι`: Mathlib's product measure +`Measure.pi` of `N(0, 1)`. Its image under `WithLp.toLp 2` is Mathlib's +`stdGaussian (EuclideanSpace ℝ ι)` (`map_pi_eq_stdGaussian`). -/ +noncomputable abbrev stdNormalVec (ι : Type*) [Fintype ι] : Measure (ι → ℝ) := + Measure.pi fun _ : ι ↦ gaussianReal 0 1 + +/-- **A vector of independent standard normals is Gaussian**: Mathlib's +`iIndepFun.hasGaussianLaw` applied to the coordinates of `Measure.pi`. -/ +instance isGaussian_stdNormalVec (ι : Type*) [Fintype ι] : IsGaussian (stdNormalVec ι) := by + have h : HasGaussianLaw id (stdNormalVec ι) := + iIndepFun.hasGaussianLaw (X := fun i (x : ι → ℝ) ↦ x i) + (fun i ↦ (measurePreserving_eval (fun _ : ι ↦ gaussianReal 0 1) i).hasLaw.hasGaussianLaw) + (iIndepFun_pi (X := fun _ : ι ↦ id) fun _ ↦ aemeasurable_id) + simpa using h.isGaussian_map + +/-- A coordinate of a vector of independent standard normals is square integrable. -/ +lemma memLp_eval_stdNormalVec {ι : Type*} [Fintype ι] (i : ι) : + MemLp (fun w : ι → ℝ ↦ w i) 2 (stdNormalVec ι) := + (measurePreserving_eval (fun _ : ι ↦ gaussianReal 0 1) i).hasLaw.memLp (memLp_id_gaussianReal 2) + +/-- The Cholesky map `(z₁, z₂) ↦ (r z₂ + √(1 − r²) z₁, z₂)`, as a continuous linear map. -/ +noncomputable def choleskyPair (r : ℝ) : ℝ × ℝ →L[ℝ] ℝ × ℝ := + (r • ContinuousLinearMap.snd ℝ ℝ ℝ + √(1 - r ^ 2) • ContinuousLinearMap.fst ℝ ℝ ℝ).prod + (ContinuousLinearMap.snd ℝ ℝ ℝ) + +@[simp] +lemma choleskyPair_apply (r : ℝ) (p : ℝ × ℝ) : + choleskyPair r p = (r * p.2 + √(1 - r ^ 2) * p.1, p.2) := by + simp [choleskyPair] + +@[fun_prop] +lemma measurable_choleskyPair (r : ℝ) : Measurable (choleskyPair r) := + (choleskyPair r).measurable + +/-- The law of the Cholesky pair. For `r ^ 2 ≤ 1` it is the standard bivariate normal law with +correlation `r` (`eq_bivariateNormalLaw`, `map_fst_bivariateNormalLaw`, +`covariance_fst_snd_bivariateNormalLaw`); for `r ^ 2 > 1` it is the law of `(rY, Y)`. -/ +noncomputable def bivariateNormalLaw (r : ℝ) : Measure (ℝ × ℝ) := + stdNormalPair.map (choleskyPair r) + +instance (r : ℝ) : IsProbabilityMeasure (bivariateNormalLaw r) := + inferInstanceAs (IsProbabilityMeasure (stdNormalPair.map (choleskyPair r))) + +/-- **The Cholesky pair is Gaussian**, for every `r`: the image of the Gaussian measure +`N(0,1) ⊗ N(0,1)` under a continuous linear map (Mathlib's `isGaussian_map`). -/ +instance isGaussian_bivariateNormalLaw (r : ℝ) : IsGaussian (bivariateNormalLaw r) := + inferInstanceAs (IsGaussian (stdNormalPair.map (choleskyPair r))) + +/-- **The standard bivariate normal CDF** `N₂(a, b; r) = P(X ≤ a, Y ≤ b)` for the Cholesky pair +`X = r Z₂ + √(1 − r²) Z₁`, `Y = Z₂`. -/ +noncomputable def bivariateNormalCDF (a b r : ℝ) : ℝ := + stdNormalPair.real {p : ℝ × ℝ | r * p.2 + √(1 - r ^ 2) * p.1 ≤ a ∧ p.2 ≤ b} + +/-- `N₂(a, b; r)` is the `bivariateNormalLaw r`-measure of the quadrant `(-∞, a] × (-∞, b]`. -/ +lemma bivariateNormalCDF_eq_law (a b r : ℝ) : + bivariateNormalCDF a b r = (bivariateNormalLaw r).real (Iic a ×ˢ Iic b) := by + rw [bivariateNormalCDF, bivariateNormalLaw, map_measureReal_apply (measurable_choleskyPair r) + (measurableSet_Iic.prod measurableSet_Iic)] + congr 1 + +/-- A linear combination of independent standard normals: `c Z₁ + d Z₂ ∼ N(0, c² + d²)`. -/ +lemma map_linear_stdNormalPair (c d : ℝ) : + stdNormalPair.map (fun p ↦ c * p.1 + d * p.2) = + gaussianReal 0 (c ^ 2 + d ^ 2).toNNReal := by + have hf : (fun p : ℝ × ℝ ↦ c * p.1 + d * p.2) = + (fun q : ℝ × ℝ ↦ q.1 + q.2) ∘ Prod.map (c * ·) (d * ·) := rfl + rw [hf, ← Measure.map_map (by fun_prop) (by fun_prop), ← Measure.map_prod_map _ _ + (by fun_prop) (by fun_prop), gaussianReal_map_const_mul, gaussianReal_map_const_mul] + change gaussianReal _ _ ∗ gaussianReal _ _ = _ + rw [gaussianReal_conv_gaussianReal] + congr 1 + · simp + · ext; rw [Real.coe_toNNReal _ (by positivity)]; simp + +/-- A linear functional of the Cholesky pair, for every `r`: +`c X + d Y ∼ N(0, (c √(1 − r²))² + (c r + d)²)`. -/ +lemma map_linear_bivariateNormalLaw' (r c d : ℝ) : + (bivariateNormalLaw r).map (fun q ↦ c * q.1 + d * q.2) = + gaussianReal 0 ((c * √(1 - r ^ 2)) ^ 2 + (c * r + d) ^ 2).toNNReal := by + rw [bivariateNormalLaw, Measure.map_map (by fun_prop) (measurable_choleskyPair r)] + have hf : (fun q : ℝ × ℝ ↦ c * q.1 + d * q.2) ∘ choleskyPair r = + fun p ↦ (c * √(1 - r ^ 2)) * p.1 + (c * r + d) * p.2 := by + ext p; simp only [Function.comp, choleskyPair_apply]; ring + rw [hf, map_linear_stdNormalPair] + +/-- A linear functional of the bivariate normal pair: `c X + d Y ∼ N(0, c² + 2cdr + d²)`. -/ +lemma map_linear_bivariateNormalLaw {r : ℝ} (hr : r ^ 2 ≤ 1) (c d : ℝ) : + (bivariateNormalLaw r).map (fun q ↦ c * q.1 + d * q.2) = + gaussianReal 0 (c ^ 2 + 2 * c * d * r + d ^ 2).toNNReal := by + rw [map_linear_bivariateNormalLaw', mul_pow, sq_sqrt (by linarith)] + congr 2 + ring + +/-- `c X + d Y ∈ L²(bivariateNormalLaw r)`, for every `r`. -/ +lemma memLp_linear_bivariateNormalLaw (r c d : ℝ) : + MemLp (fun q : ℝ × ℝ ↦ c * q.1 + d * q.2) 2 (bivariateNormalLaw r) := + HasLaw.memLp ⟨by fun_prop, map_linear_bivariateNormalLaw' r c d⟩ (memLp_id_gaussianReal 2) + +lemma memLp_fst_bivariateNormalLaw (r : ℝ) : MemLp Prod.fst 2 (bivariateNormalLaw r) := by + simpa using memLp_linear_bivariateNormalLaw r 1 0 + +lemma memLp_snd_bivariateNormalLaw (r : ℝ) : MemLp Prod.snd 2 (bivariateNormalLaw r) := by + simpa using memLp_linear_bivariateNormalLaw r 0 1 + +/-- `E[c X + d Y] = 0`, for every `r`. -/ +lemma integral_linear_bivariateNormalLaw (r c d : ℝ) : + ∫ q, c * q.1 + d * q.2 ∂bivariateNormalLaw r = 0 := by + have h := integral_id_gaussianReal (μ := 0) + (v := ((c * √(1 - r ^ 2)) ^ 2 + (c * r + d) ^ 2).toNNReal) + rw [← map_linear_bivariateNormalLaw' r c d, integral_map (by fun_prop) (by fun_prop)] at h + exact h + +lemma integral_fst_bivariateNormalLaw (r : ℝ) : ∫ q, q.1 ∂bivariateNormalLaw r = 0 := by + simpa using integral_linear_bivariateNormalLaw r 1 0 + +lemma integral_snd_bivariateNormalLaw (r : ℝ) : ∫ q, q.2 ∂bivariateNormalLaw r = 0 := by + simpa using integral_linear_bivariateNormalLaw r 0 1 + +/-- `Var[c X + d Y] = (c √(1 − r²))² + (c r + d)²`, for every `r`. -/ +private lemma variance_linear_bivariateNormalLaw' (r c d : ℝ) : + Var[fun q ↦ c * q.1 + d * q.2; bivariateNormalLaw r] = + (c * √(1 - r ^ 2)) ^ 2 + (c * r + d) ^ 2 := by + rw [← variance_id_map (by fun_prop), map_linear_bivariateNormalLaw' r c d, + variance_id_gaussianReal, Real.coe_toNNReal _ (by positivity)] + +/-- `Var[c X + d Y] = c ^ 2 + 2 c d r + d ^ 2` for `r² ≤ 1`. -/ +lemma variance_linear_bivariateNormalLaw {r : ℝ} (hr : r ^ 2 ≤ 1) (c d : ℝ) : + Var[fun q ↦ c * q.1 + d * q.2; bivariateNormalLaw r] = c ^ 2 + 2 * c * d * r + d ^ 2 := by + rw [variance_linear_bivariateNormalLaw', mul_pow, sq_sqrt (by linarith)] + ring + +/-- `Var Y = 1`, for every `r` (`Y = Z₂` never involves the root). -/ +lemma variance_snd_bivariateNormalLaw (r : ℝ) : Var[Prod.snd; bivariateNormalLaw r] = 1 := by + rw [show (Prod.snd : ℝ × ℝ → ℝ) = fun q ↦ 0 * q.1 + 1 * q.2 by ext; simp, + variance_linear_bivariateNormalLaw'] + ring + +/-- `Var X = 1` for `r² ≤ 1` (for `r² > 1`, `X = rY` and `Var X = r²`). -/ +lemma variance_fst_bivariateNormalLaw {r : ℝ} (hr : r ^ 2 ≤ 1) : + Var[Prod.fst; bivariateNormalLaw r] = 1 := by + rw [show (Prod.fst : ℝ × ℝ → ℝ) = fun q ↦ 1 * q.1 + 0 * q.2 by ext; simp, + variance_linear_bivariateNormalLaw hr] + ring + +/-- **The parameter is the covariance**: `Cov(X, Y) = r`, for every `r` (for `r² > 1` the pair is +`(rY, Y)`, whose covariance is still `r`). With `variance_fst_bivariateNormalLaw` and +`variance_snd_bivariateNormalLaw`, `r` is the correlation when `r² ≤ 1`. -/ +theorem covariance_fst_snd_bivariateNormalLaw (r : ℝ) : + cov[Prod.fst, Prod.snd; bivariateNormalLaw r] = r := by + have v₁ : Var[Prod.fst; bivariateNormalLaw r] = √(1 - r ^ 2) ^ 2 + r ^ 2 := by + rw [show (Prod.fst : ℝ × ℝ → ℝ) = fun q ↦ 1 * q.1 + 0 * q.2 by ext; simp, + variance_linear_bivariateNormalLaw'] + ring + have v₃ : Var[Prod.fst + Prod.snd; bivariateNormalLaw r] = √(1 - r ^ 2) ^ 2 + (r + 1) ^ 2 := by + rw [show (Prod.fst + Prod.snd : ℝ × ℝ → ℝ) = fun q ↦ 1 * q.1 + 1 * q.2 by ext; simp, + variance_linear_bivariateNormalLaw'] + ring + have hadd := variance_add (memLp_fst_bivariateNormalLaw r) (memLp_snd_bivariateNormalLaw r) + rw [v₁, v₃, variance_snd_bivariateNormalLaw] at hadd + linear_combination (-1 / 2 : ℝ) * hadd + +/-- The first margin `X ∼ N(0, 1)`, read off Mathlib's `IsGaussian.map_eq_gaussianReal` (needs +`r ^ 2 ≤ 1`: for `|r| > 1` the junk-valued root makes `X = r Y`, which is not `N(0, 1)`). -/ +lemma map_fst_bivariateNormalLaw {r : ℝ} (hr : r ^ 2 ≤ 1) : + (bivariateNormalLaw r).map Prod.fst = gaussianReal 0 1 := by + have h := IsGaussian.map_eq_gaussianReal (μ := bivariateNormalLaw r) + (ContinuousLinearMap.fst ℝ ℝ ℝ) + simp only [ContinuousLinearMap.coe_fst'] at h + rw [h, integral_fst_bivariateNormalLaw, variance_fst_bivariateNormalLaw hr, Real.toNNReal_one] + +/-- The second margin `Y = Z₂ ∼ N(0, 1)`, for every `r`, read off Mathlib's +`IsGaussian.map_eq_gaussianReal`. -/ +lemma map_snd_bivariateNormalLaw (r : ℝ) : + (bivariateNormalLaw r).map Prod.snd = gaussianReal 0 1 := by + have h := IsGaussian.map_eq_gaussianReal (μ := bivariateNormalLaw r) + (ContinuousLinearMap.snd ℝ ℝ ℝ) + simp only [ContinuousLinearMap.coe_snd'] at h + rw [h, integral_snd_bivariateNormalLaw, variance_snd_bivariateNormalLaw, Real.toNNReal_one] + +/-! ### A Gaussian law on `ℝ²` is determined by its first two moments -/ + +/-- `L q = L(1, 0) q₁ + L(0, 1) q₂` for a continuous linear functional on `ℝ²`. -/ +lemma strongDual_prod_apply (L : StrongDual ℝ (ℝ × ℝ)) (q : ℝ × ℝ) : + L q = L (1, 0) * q.1 + L (0, 1) * q.2 := by + have : q = q.1 • ((1 : ℝ), (0 : ℝ)) + q.2 • ((0 : ℝ), (1 : ℝ)) := by ext <;> simp + conv_lhs => rw [this] + simp only [map_add, map_smul, smul_eq_mul] + ring + +/-- The mean of a law on `ℝ²` with integrable coordinates is the pair of coordinate means. -/ +lemma integral_id_prod_eq {μ : Measure (ℝ × ℝ)} (h₁ : Integrable Prod.fst μ) + (h₂ : Integrable Prod.snd μ) : μ[id] = (∫ q, q.1 ∂μ, ∫ q, q.2 ∂μ) := + integral_pair h₁ h₂ + +/-- The variance of `a X + b Y` from the second moments of the coordinates. -/ +lemma variance_linear_of_memLp {μ : Measure (ℝ × ℝ)} [IsFiniteMeasure μ] + (h₁ : MemLp Prod.fst 2 μ) (h₂ : MemLp Prod.snd 2 μ) (a b : ℝ) : + Var[fun q ↦ a * q.1 + b * q.2; μ] = a ^ 2 * Var[Prod.fst; μ] + + 2 * a * b * cov[Prod.fst, Prod.snd; μ] + b ^ 2 * Var[Prod.snd; μ] := by + rw [variance_fun_add (h₁.const_mul a) (h₂.const_mul b), variance_const_mul, variance_const_mul, + covariance_const_mul_left, covariance_const_mul_right] + ring + +/-- The variance of a continuous linear functional on `ℝ²` from the second moments of the +coordinates. -/ +lemma variance_strongDual {μ : Measure (ℝ × ℝ)} [IsFiniteMeasure μ] + (h₁ : MemLp Prod.fst 2 μ) (h₂ : MemLp Prod.snd 2 μ) (L : StrongDual ℝ (ℝ × ℝ)) : + Var[L; μ] = L (1, 0) ^ 2 * Var[Prod.fst; μ] + + 2 * L (1, 0) * L (0, 1) * cov[Prod.fst, Prod.snd; μ] + L (0, 1) ^ 2 * Var[Prod.snd; μ] := by + set a := L (1, 0) + set b := L (0, 1) + have hL : ⇑L = fun q ↦ a * q.1 + b * q.2 := funext (strongDual_prod_apply L) + rw [hL, variance_linear_of_memLp h₁ h₂] + +/-- **A Gaussian law on `ℝ²` with standardized coordinates is the Cholesky law.** If `μ` is +Gaussian, its coordinates are centred with unit variances, and their covariance is `r` with +`r² ≤ 1`, then `μ = bivariateNormalLaw r`. Both laws are Gaussian with the same mean and the same +variance on every linear functional, so their characteristic functions agree (Mathlib's +`IsGaussian.charFunDual_eq'` and `Measure.ext_of_charFunDual`). -/ +theorem eq_bivariateNormalLaw {μ : Measure (ℝ × ℝ)} [IsGaussian μ] {r : ℝ} (hr : r ^ 2 ≤ 1) + (h₁ : ∫ q, q.1 ∂μ = 0) (h₂ : ∫ q, q.2 ∂μ = 0) (v₁ : Var[Prod.fst; μ] = 1) + (v₂ : Var[Prod.snd; μ] = 1) (hc : cov[Prod.fst, Prod.snd; μ] = r) : + μ = bivariateNormalLaw r := by + have m₁ : MemLp Prod.fst 2 μ := by + simpa using IsGaussian.memLp_dual μ (ContinuousLinearMap.fst ℝ ℝ ℝ) 2 (by simp) + have m₂ : MemLp Prod.snd 2 μ := by + simpa using IsGaussian.memLp_dual μ (ContinuousLinearMap.snd ℝ ℝ ℝ) 2 (by simp) + have hmean : μ[id] = (bivariateNormalLaw r)[id] := by + rw [integral_id_prod_eq (m₁.integrable one_le_two) (m₂.integrable one_le_two), + integral_id_prod_eq ((memLp_fst_bivariateNormalLaw r).integrable one_le_two) + ((memLp_snd_bivariateNormalLaw r).integrable one_le_two), + h₁, h₂, integral_fst_bivariateNormalLaw, integral_snd_bivariateNormalLaw] + refine Measure.ext_of_charFunDual (funext fun L ↦ ?_) + rw [IsGaussian.charFunDual_eq', IsGaussian.charFunDual_eq', hmean, + covarianceBilinDual_self_eq_variance (IsGaussian.memLp_two_id (μ := μ)), + covarianceBilinDual_self_eq_variance (IsGaussian.memLp_two_id (μ := bivariateNormalLaw r)), + variance_strongDual m₁ m₂, v₁, v₂, hc, + variance_strongDual (memLp_fst_bivariateNormalLaw r) (memLp_snd_bivariateNormalLaw r), + variance_fst_bivariateNormalLaw hr, variance_snd_bivariateNormalLaw, + covariance_fst_snd_bivariateNormalLaw] + +/-- **Exchangeability**: for `r ∈ [-1, 1]`, `(Y, X)` has the same law as `(X, Y)`. The swapped +law is Gaussian (the swap is a continuous linear equivalence) with the same moments, so +`eq_bivariateNormalLaw` applies. -/ +theorem bivariateNormalLaw_map_swap {r : ℝ} (hr : r ^ 2 ≤ 1) : + (bivariateNormalLaw r).map Prod.swap = bivariateNormalLaw r := by + have hswap : ⇑(ContinuousLinearEquiv.prodComm ℝ ℝ ℝ) = Prod.swap := funext fun _ ↦ by simp + have : IsGaussian ((bivariateNormalLaw r).map Prod.swap) := by + rw [← hswap] + infer_instance + refine eq_bivariateNormalLaw hr ?_ ?_ ?_ ?_ ?_ + · rw [integral_map measurable_swap.aemeasurable (by fun_prop)] + exact integral_snd_bivariateNormalLaw r + · rw [integral_map measurable_swap.aemeasurable (by fun_prop)] + exact integral_fst_bivariateNormalLaw r + · rw [variance_map (by fun_prop) measurable_swap.aemeasurable] + exact variance_snd_bivariateNormalLaw r + · rw [variance_map (by fun_prop) measurable_swap.aemeasurable] + exact variance_fst_bivariateNormalLaw hr + · rw [covariance_map_fun (by fun_prop) (by fun_prop) measurable_swap.aemeasurable] + exact (covariance_comm _ _).trans (covariance_fst_snd_bivariateNormalLaw r) + +/-- **The Cholesky pair satisfies `BivariateGaussianHyp`** +(`Probability/Gaussian/BivariateGaussian.lean`) +with means `0`, `σ_X = σ_Y = 1` and `ρ = r`, for every `r`. The structure does not constrain +`Var X`; for `r² > 1` the pair is `(rY, Y)` with `Var X = r²`, and the hypotheses still hold. -/ +theorem bivariateGaussianHyp_bivariateNormalLaw (r : ℝ) : + BivariateGaussianHyp (bivariateNormalLaw r) Prod.fst Prod.snd 0 0 1 1 r where + σ_X_pos := one_pos + σ_Y_pos := one_pos + X_meas := measurable_fst + Y_meas := measurable_snd + joint_gaussian := IsGaussian.hasGaussianLaw_id + mean_X := integral_fst_bivariateNormalLaw r + mean_Y := integral_snd_bivariateNormalLaw r + var_Y := by rw [variance_snd_bivariateNormalLaw]; norm_num + cov_XY := by rw [covariance_fst_snd_bivariateNormalLaw]; ring + +/-- **Regression of `X` on `Y`**: for the Cholesky pair, `E[X | Y] = r Y` almost surely, for every +`r`. The bivariate Gaussian conditional-expectation formula +(`BivariateGaussianHyp.conditional_expectation_formula`) at +`bivariateGaussianHyp_bivariateNormalLaw`. -/ +theorem condExp_fst_bivariateNormalLaw (r : ℝ) : + (bivariateNormalLaw r)[Prod.fst | MeasurableSpace.comap Prod.snd inferInstance] + =ᵐ[bivariateNormalLaw r] fun p ↦ r * p.2 := by + filter_upwards [(bivariateGaussianHyp_bivariateNormalLaw r).conditional_expectation_formula] + with p hp + rw [hp] + ring + +/-- **Symmetry**: `N₂(a, b; r) = N₂(b, a; r)` for `r ∈ [-1, 1]`. -/ +theorem bivariateNormalCDF_comm (a b : ℝ) {r : ℝ} (hr : r ^ 2 ≤ 1) : + bivariateNormalCDF a b r = bivariateNormalCDF b a r := by + rw [bivariateNormalCDF_eq_law, bivariateNormalCDF_eq_law] + conv_lhs => rw [← bivariateNormalLaw_map_swap hr] + rw [map_measureReal_apply measurable_swap (measurableSet_Iic.prod measurableSet_Iic), + preimage_swap_prod] + +/-- `N₂(a, b; r)` in terms of `Y = Z₂` alone, when the `Z₁` coefficient vanishes. -/ +private lemma bivariateNormalCDF_of_sqrt_eq_zero {a b r : ℝ} (h : √(1 - r ^ 2) = 0) : + bivariateNormalCDF a b r = (gaussianReal 0 1).real {y | r * y ≤ a ∧ y ≤ b} := by + have hset : {p : ℝ × ℝ | r * p.2 + √(1 - r ^ 2) * p.1 ≤ a ∧ p.2 ≤ b} = + Prod.snd ⁻¹' {y | r * y ≤ a ∧ y ≤ b} := by ext p; simp [h] + have hm : MeasurableSet {y : ℝ | r * y ≤ a ∧ y ≤ b} := + (measurableSet_le (measurable_id.const_mul r) measurable_const).inter + (measurableSet_le measurable_id measurable_const) + rw [bivariateNormalCDF, hset, ← map_measureReal_apply measurable_snd hm, Measure.map_snd_prod] + simp + +/-- **Independence** (`r = 0`): `N₂(a, b; 0) = Φ(a) Φ(b)`. -/ +theorem bivariateNormalCDF_zero (a b : ℝ) : bivariateNormalCDF a b 0 = Phi a * Phi b := by + have hset : {p : ℝ × ℝ | 0 * p.2 + √(1 - 0 ^ 2) * p.1 ≤ a ∧ p.2 ≤ b} = Iic a ×ˢ Iic b := by + ext p; simp only [mem_ofPred_eq, mem_prod, mem_Iic]; norm_num + rw [bivariateNormalCDF, hset, measureReal_prod_prod] + rfl + +/-- **Comonotone** (`r = 1`): `N₂(a, b; 1) = Φ(min a b)`. -/ +theorem bivariateNormalCDF_one (a b : ℝ) : bivariateNormalCDF a b 1 = Phi (min a b) := by + rw [bivariateNormalCDF_of_sqrt_eq_zero (by simp)] + congr 1 + ext y; simp + +/-- `(Φ(t) − Φ(k))⁺` is the standard normal probability of `(k, t]`. -/ +lemma posPart_Phi_sub_Phi (k t : ℝ) : + (Phi t - Phi k)⁺ = (gaussianReal 0 1).real (Ioc k t) := by + rcases le_total t k with h | h + · rw [Ioc_eq_empty (not_lt.2 h), measureReal_empty, posPart_eq_zero] + exact sub_nonpos.2 (strictMono_Phi.monotone h) + · rw [posPart_eq_self.2 (sub_nonneg.2 (strictMono_Phi.monotone h)), ← Iic_sdiff_Iic, + measureReal_sdiff (Iic_subset_Iic.2 h) measurableSet_Iic, ← cdf_eq_real, ← cdf_eq_real, + cdf_gaussianReal_zero_one] + +/-- **Countermonotone** (`r = -1`): `N₂(a, b; -1) = (Φ(b) − Φ(−a))⁺`. -/ +theorem bivariateNormalCDF_neg_one (a b : ℝ) : + bivariateNormalCDF a b (-1) = (Phi b - Phi (-a))⁺ := by + rw [bivariateNormalCDF_of_sqrt_eq_zero (by simp), posPart_Phi_sub_Phi] + have hset : {y : ℝ | -1 * y ≤ a ∧ y ≤ b} = Icc (-a) b := by + ext y; simp only [mem_ofPred_eq, mem_Icc]; constructor <;> rintro ⟨h1, h2⟩ <;> constructor <;> + linarith + have := nullSingletonClass_gaussianReal (μ := 0) one_ne_zero + rw [hset, measureReal_congr Ioc_ae_eq_Icc.symm] + +/-! ## A sign-flip identity: `N₂(a, b; r) + N₂(a, -b; -r) = Φ(a)` + +Negating the second coordinate of the Cholesky pair sends correlation `r` to `-r` without +touching the `X`-margin, so splitting the real line into the closed rays `Iic b` and `Ici b` +(covering `ℝ`, meeting only at the null set `{b}` for the atom-free `Y`-margin) gives the +identity below. It is the two-asset analogue of `Phi_add_Phi_neg`. -/ + +/-- The sign-flip map `(x, y) ↦ (x, -y)` sends `bivariateNormalLaw r` to `bivariateNormalLaw +(-r)`: negating `Y` negates the correlation, unconditionally in `r`. -/ +lemma bivariateNormalLaw_map_negSnd (r : ℝ) : + (bivariateNormalLaw r).map (fun p : ℝ × ℝ ↦ (p.1, -p.2)) = bivariateNormalLaw (-r) := by + have hnegStd : stdNormalPair.map (fun p : ℝ × ℝ ↦ (p.1, -p.2)) = stdNormalPair := by + have hf : (fun p : ℝ × ℝ ↦ (p.1, -p.2)) = Prod.map id (fun x : ℝ ↦ -x) := rfl + rw [hf, stdNormalPair, ← Measure.map_prod_map _ _ measurable_id (by fun_prop), + Measure.map_id, gaussianReal_map_neg, neg_zero] + have hcomm : (fun p : ℝ × ℝ ↦ (p.1, -p.2)) ∘ choleskyPair r = + choleskyPair (-r) ∘ (fun p : ℝ × ℝ ↦ (p.1, -p.2)) := by + funext p + simp only [Function.comp, choleskyPair_apply, neg_sq, Prod.mk.injEq] + constructor <;> first | ring | trivial + rw [bivariateNormalLaw, bivariateNormalLaw, + Measure.map_map (by fun_prop) (measurable_choleskyPair r), hcomm, + ← Measure.map_map (measurable_choleskyPair (-r)) (by fun_prop), hnegStd] + +/-- **The sign-flip identity**: `N₂(a, b; r) + N₂(a, -b; -r) = Φ(a)`. Splits `(bivariateNormalLaw +r).real (Iic a ×ˢ ·)` across the closed-ray cover `Iic b ∪ Ici b = univ` (meeting at the null +set `{b}`, since the `Y`-margin `map_snd_bivariateNormalLaw` is atom-free), then reads off the +`X`-margin via `map_fst_bivariateNormalLaw`. -/ +theorem bivariateNormalCDF_flip_snd (a b : ℝ) {r : ℝ} (hr : r ^ 2 ≤ 1) : + bivariateNormalCDF a b r + bivariateNormalCDF a (-b) (-r) = Phi a := by + have hflip : bivariateNormalCDF a (-b) (-r) = (bivariateNormalLaw r).real (Iic a ×ˢ Ici b) := by + rw [bivariateNormalCDF_eq_law, ← bivariateNormalLaw_map_negSnd r, + map_measureReal_apply (by fun_prop) (measurableSet_Iic.prod measurableSet_Iic)] + congr 1 + ext p + simp only [mem_preimage, mem_prod, mem_Iic, mem_Ici] + constructor + · rintro ⟨h1, h2⟩; exact ⟨h1, by linarith⟩ + · rintro ⟨h1, h2⟩; exact ⟨h1, by linarith⟩ + have hsingleton : (bivariateNormalLaw r).real (Iic a ×ˢ ({b} : Set ℝ)) = 0 := by + have hsub : (Iic a ×ˢ ({b} : Set ℝ) : Set (ℝ × ℝ)) ⊆ univ ×ˢ ({b} : Set ℝ) := + prod_mono (subset_univ _) subset_rfl + have hzero : (bivariateNormalLaw r).real (univ ×ˢ ({b} : Set ℝ)) = 0 := by + have : NullSingletonClass (gaussianReal (0 : ℝ) (1 : NNReal)) := + nullSingletonClass_gaussianReal one_ne_zero + rw [show (univ ×ˢ ({b} : Set ℝ) : Set (ℝ × ℝ)) = Prod.snd ⁻¹' {b} by ext p; simp, + ← map_measureReal_apply measurable_snd (measurableSet_singleton b), + map_snd_bivariateNormalLaw] + simp [measureReal_def] + exact le_antisymm (hzero ▸ measureReal_mono hsub) measureReal_nonneg + have hunion : (Iic a ×ˢ Iic b : Set (ℝ × ℝ)) ∪ (Iic a ×ˢ Ici b) = Iic a ×ˢ univ := by + rw [← prod_union]; congr 1; ext x; simp + have hinter : (Iic a ×ˢ Iic b : Set (ℝ × ℝ)) ∩ (Iic a ×ˢ Ici b) = Iic a ×ˢ {b} := by + rw [← prod_inter]; congr 1; ext x; simp [le_antisymm_iff] + have hkey := measureReal_union_add_inter (μ := bivariateNormalLaw r) + (s := Iic a ×ˢ Iic b) (t := Iic a ×ˢ Ici b) (measurableSet_Iic.prod measurableSet_Ici) + rw [hunion, hinter, hsingleton, add_zero] at hkey + have hmargin : (bivariateNormalLaw r).real (Iic a ×ˢ (univ : Set ℝ)) = Phi a := by + rw [show (Iic a ×ˢ (univ : Set ℝ) : Set (ℝ × ℝ)) = Prod.fst ⁻¹' Iic a by ext p; simp, + ← map_measureReal_apply measurable_fst measurableSet_Iic, + map_fst_bivariateNormalLaw hr] + simp [measureReal_def, Phi_def] + rw [bivariateNormalCDF_eq_law, hflip, ← hkey, hmargin] + +/-- **Joint survival identity**: `N₂(-a, -b; r) = 1 - Φ(a) - Φ(b) + N₂(a, b; r)`, derived purely +algebraically from the sign-flip identity `bivariateNormalCDF_flip_snd`, the symmetry +`bivariateNormalCDF_comm` and `Phi_neg` — no new measure-theoretic content. (Reading either side +as `P(X > a, Y > b)` is not stated here.) This is the identity that collapses the strike-side +terms of Stulz-style two-asset closed forms. -/ +theorem bivariateNormalCDF_neg_neg (a b : ℝ) {r : ℝ} (hr : r ^ 2 ≤ 1) : + bivariateNormalCDF (-a) (-b) r = 1 - Phi a - Phi b + bivariateNormalCDF a b r := by + have hr' : (-r) ^ 2 ≤ 1 := by rwa [neg_sq] + have h1 := bivariateNormalCDF_flip_snd a b hr + have h2 := bivariateNormalCDF_flip_snd (-b) a hr' + rw [neg_neg, Phi_neg, bivariateNormalCDF_comm (-b) a hr', + bivariateNormalCDF_comm (-b) (-a) hr] at h2 + linarith + +end MathFin + +/-! ### The first threshold to `+∞` -/ + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set Filter Topology + +/-- **Sending the first threshold to `+∞` recovers the second margin**: `N₂(a, b; r) → Φ(b)` as +`a → ∞`, for every `r`. The quadrants `(-∞, a] × (-∞, b]` increase to `ℝ × (-∞, b]` +(continuity of measure from below, `tendsto_measure_iUnion_atTop`), whose +`bivariateNormalLaw r`-measure is `Φ(b)` by the second margin `map_snd_bivariateNormalLaw`, +which needs no condition on `r`. -/ +theorem tendsto_bivariateNormalCDF_atTop_fst (b r : ℝ) : + Tendsto (fun a ↦ bivariateNormalCDF a b r) atTop (𝓝 (Phi b)) := by + have hmono : Monotone fun a : ℝ ↦ (Iic a ×ˢ Iic b : Set (ℝ × ℝ)) := + fun _ _ h ↦ prod_mono (Iic_subset_Iic.mpr h) subset_rfl + have hU : (⋃ a : ℝ, (Iic a ×ˢ Iic b : Set (ℝ × ℝ))) = univ ×ˢ Iic b := by + ext p + simp only [mem_iUnion, mem_prod, mem_Iic, mem_univ, true_and] + exact ⟨fun ⟨_, _, h⟩ ↦ h, fun h ↦ ⟨p.1, le_rfl, h⟩⟩ + have hlim : Tendsto (fun a : ℝ ↦ bivariateNormalLaw r (Iic a ×ˢ Iic b)) atTop + (𝓝 (bivariateNormalLaw r (univ ×ˢ Iic b))) := by + rw [← hU] + exact tendsto_measure_iUnion_atTop hmono + have hPhi : Phi b = (bivariateNormalLaw r (univ ×ˢ Iic b)).toReal := by + rw [show (univ ×ˢ Iic b : Set (ℝ × ℝ)) = Prod.snd ⁻¹' Iic b by ext p; simp, + ← Measure.map_apply measurable_snd measurableSet_Iic, map_snd_bivariateNormalLaw, Phi_def] + rw [hPhi] + simp only [bivariateNormalCDF_eq_law, measureReal_def] + exact (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp hlim + +/-! ### A Gaussian pair with any means, volatilities and correlation -/ + +/-- The Cholesky pair shifted and scaled: coordinate `i` is `μᵢ + σᵢ Zᵢ`, where `(Z₀, Z₁)` is the +pair of coordinates of `ℝ × ℝ`. Under `bivariateNormalLaw r` with `r² ≤ 1` it is a Gaussian pair +with means `μ`, volatilities `|σ|` and covariance `r σ₀ σ₁`, so a two-asset model with any such +parameters has a realization. -/ +noncomputable def gaussianPair (μ σ : Fin 2 → ℝ) : Fin 2 → ℝ × ℝ → ℝ := + fun i q ↦ μ i + σ i * ![q.1, q.2] i + +lemma gaussianPair_zero (μ σ : Fin 2 → ℝ) : + gaussianPair μ σ 0 = fun q ↦ μ 0 + σ 0 * q.1 := rfl + +lemma gaussianPair_one (μ σ : Fin 2 → ℝ) : + gaussianPair μ σ 1 = fun q ↦ μ 1 + σ 1 * q.2 := rfl + +/-- **The pair is jointly Gaussian**, for every `r`: it is a translate of a continuous linear +image of the Gaussian measure `bivariateNormalLaw r`. -/ +theorem hasGaussianLaw_gaussianPair (r : ℝ) (μ σ : Fin 2 → ℝ) : + HasGaussianLaw (fun q i ↦ gaussianPair μ σ i q) (bivariateNormalLaw r) := by + let L : ℝ × ℝ →L[ℝ] Fin 2 → ℝ := + ContinuousLinearMap.pi ![σ 0 • ContinuousLinearMap.fst ℝ ℝ ℝ, + σ 1 • ContinuousLinearMap.snd ℝ ℝ ℝ] + have h : (fun q i ↦ gaussianPair μ σ i q) = (μ + ·) ∘ L := by + ext q i + fin_cases i <;> simp [gaussianPair, L] + refine ⟨by rw [h]; fun_prop, ?_⟩ + rw [h, ← Measure.map_map (measurable_const_add μ) L.measurable] + infer_instance + +lemma memLp_gaussianPair (r : ℝ) (μ σ : Fin 2 → ℝ) (i : Fin 2) : + MemLp (gaussianPair μ σ i) 2 (bivariateNormalLaw r) := by + revert i + refine Fin.forall_fin_two.2 ⟨?_, ?_⟩ + · rw [gaussianPair_zero] + exact (memLp_const (μ 0)).add ((memLp_fst_bivariateNormalLaw r).const_mul (σ 0)) + · rw [gaussianPair_one] + exact (memLp_const (μ 1)).add ((memLp_snd_bivariateNormalLaw r).const_mul (σ 1)) + +lemma integral_gaussianPair (r : ℝ) (μ σ : Fin 2 → ℝ) (i : Fin 2) : + ∫ q, gaussianPair μ σ i q ∂bivariateNormalLaw r = μ i := by + have h₀ := (memLp_fst_bivariateNormalLaw r).integrable one_le_two + have h₁ := (memLp_snd_bivariateNormalLaw r).integrable one_le_two + revert i + refine Fin.forall_fin_two.2 ⟨?_, ?_⟩ + · simp [gaussianPair_zero, integral_add (integrable_const _) (h₀.const_mul _), + integral_const_mul, integral_fst_bivariateNormalLaw] + · simp [gaussianPair_one, integral_add (integrable_const _) (h₁.const_mul _), + integral_const_mul, integral_snd_bivariateNormalLaw] + +lemma variance_gaussianPair {r : ℝ} (hr : r ^ 2 ≤ 1) (μ σ : Fin 2 → ℝ) (i : Fin 2) : + Var[gaussianPair μ σ i; bivariateNormalLaw r] = σ i ^ 2 := by + revert i + refine Fin.forall_fin_two.2 ⟨?_, ?_⟩ + · rw [gaussianPair_zero, variance_const_add (by fun_prop), variance_const_mul, + variance_fst_bivariateNormalLaw hr] + simp + · rw [gaussianPair_one, variance_const_add (by fun_prop), variance_const_mul, + variance_snd_bivariateNormalLaw] + simp + +/-- **The parameter `r` is the correlation of the pair**: `Cov = r σ₀ σ₁`, for every `r`. -/ +theorem covariance_gaussianPair (r : ℝ) (μ σ : Fin 2 → ℝ) : + cov[gaussianPair μ σ 0, gaussianPair μ σ 1; bivariateNormalLaw r] = r * σ 0 * σ 1 := by + have h₀ := ((memLp_fst_bivariateNormalLaw r).const_mul (σ 0)).integrable one_le_two + have h₁ := ((memLp_snd_bivariateNormalLaw r).const_mul (σ 1)).integrable one_le_two + rw [gaussianPair_zero, gaussianPair_one, covariance_const_add_left h₀, + covariance_const_add_right h₁, covariance_const_mul_left, covariance_const_mul_right, + covariance_fst_snd_bivariateNormalLaw] + ring + +end MathFin diff --git a/LeanPool/MathFin/Probability/Gaussian/FeynmanKacHeatEquation.lean b/LeanPool/MathFin/Probability/Gaussian/FeynmanKacHeatEquation.lean new file mode 100644 index 0000000000..a1078d92e7 --- /dev/null +++ b/LeanPool/MathFin/Probability/Gaussian/FeynmanKacHeatEquation.lean @@ -0,0 +1,1347 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.Calculus.Deriv.Prod +public import Mathlib.Analysis.Calculus.ParametricIntegral +public import Mathlib.Analysis.SpecialFunctions.Sqrt +public import Mathlib.Probability.BrownianMotion.Basic + +/-! +# Feynman–Kac for the heat equation + +This file constructs the heat flow as a Gaussian convolution. It identifies +the convolution with `E[g(x + B_t)]` when the law of `B_t` is centered Gaussian +with variance `t`, and verifies the heat equation for the payoff growth bounds +in the derivative lemmas. At time zero the expectation is `g(x)` when +`B 0 = 0` almost surely. Saporito's Theorem 9.2.1 starts from a unique +bounded classical solution and gives its expectation representation. + +This proof does **not** use Itô calculus. The mechanism is: + +1. By `Measure.map` transfer, `u(t, x) = ∫ y, g(x + y) ∂(gaussianReal 0 t)` + `= ∫ y, g(x + y) · gaussianPDFReal 0 t y ∂volume` for `t > 0`. +2. The Gaussian density satisfies the heat-kernel PDE: + `∂_t pdf(t, y) = (1/2) ∂²_y pdf(t, y)` (pure calculus). +3. Differentiating under the integral sign passes the PDE through to `u`. + +## Main definitions + +* `heatKernel`: `K(t, y) = (2π t)^{-1/2} · exp(−y² / (2 t))`, defined for all `t : ℝ`; the + statements about it assume `0 < t`. +* `feynmanU`: `feynmanU g t x = ∫ z, g z · K(t, z − x) dz`, the heat-kernel form of + `E[g(x + B_t)]`. + +## Main results + +* `heatConvolution_eq_add_integral_deriv` — the integrated heat-equation form + `u(t, x) = u(0, x) + ½ ∫₀ᵗ ∂²_x u(s, x) ds` for the Gaussian convolution. +* `feynmanKac_boundary` / `feynmanU_eq_expectation` — `u(t, x) = E[g(x + B_t)]`. +* `expectation_ito` / `expectation_ito_isPreBrownian` — the expectation-form Itô + identity `E[f(B_t)] = f(0) + ½ ∫₀ᵗ E[f''(B_s)] ds`. +* `hasFDerivAt_heatKernel` — the heat kernel is jointly Fréchet-differentiable in + `(t, y)` (with `hasDerivAt_heatKernel_t` / `_y` / `_y_y`, the kernel-side derivatives). +* `hasDerivAt_feynmanU_t` / `_x` / `_xx` + `feynmanU_heat_equation` — for sub-Gaussian `h` + the convolution `u = feynmanU h` is differentiable in `t`, twice in `x`, and solves + `∂_t u = ½ ∂_xx u` (every derivative falls on the kernel; `h` needs only the growth + bound). These make the heat flow load-bearing for the Black–Scholes PDE + (`Models/BlackScholes/PDEFromFeynmanKac.lean`, benchmark `sc-bs-pde-feynman-kac`). + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Theorem 9.2.1, + representation of a bounded classical solution + +## Tags + +Feynman–Kac formula, heat equation, heat kernel, parabolic PDE, Black–Scholes PDE, +Gaussian convolution, MSC 60H30, MSC 35K10, JEL G13 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Filter Real +open scoped NNReal ENNReal + +namespace MathFin +namespace FeynmanKacHeatEquation + +/-! ### Heat-kernel PDE on `gaussianPDFReal 0 t y` + +We prove `∂_t pdf(0, t, y) = (1/2) ∂²_y pdf(0, t, y)` for `t > 0`. -/ + +/-- Our own heat-kernel form: `K(t, y) = (2π t)^{-1/2} · exp(−y² / (2 t))`. +Defined for all `t : ℝ` (when `t ≤ 0` the formula returns nonsense but the +heat-kernel statements gate on `0 < t`). -/ +noncomputable def heatKernel (t y : ℝ) : ℝ := + (Real.sqrt (2 * Real.pi * t))⁻¹ * Real.exp (-(y ^ 2) / (2 * t)) + +/-- For `t > 0`, the Mathlib `gaussianPDFReal 0 t y` equals our heatKernel. -/ +private lemma heatKernel_eq_gaussianPDFReal {t : ℝ} (ht : 0 < t) (y : ℝ) : + heatKernel t y = gaussianPDFReal 0 t.toNNReal y := by + rw [heatKernel, gaussianPDFReal_def] + have htN : (t.toNNReal : ℝ) = t := Real.coe_toNNReal _ ht.le + rw [htN] + ring_nf + +/-- First `y`-derivative of the heat kernel: `∂_y K = -(y/t) K`. -/ +private lemma hasDerivAt_heatKernel_y {t : ℝ} (ht : 0 < t) (y : ℝ) : + HasDerivAt (fun z ↦ heatKernel t z) (-(y / t) * heatKernel t y) y := by + have h_neg_y_sq : HasDerivAt (fun z : ℝ ↦ -(z ^ 2)) (-(2 * y)) y := by + convert (hasDerivAt_pow 2 y).neg using 1; push_cast; ring + have h_inner : HasDerivAt (fun z : ℝ ↦ -(z ^ 2) / (2 * t)) (-(y / t)) y := by + have := h_neg_y_sq.div_const (2 * t) + have ht_ne : (2 * t) ≠ 0 := by positivity + convert this using 1; field_simp + have h_exp : HasDerivAt (fun z : ℝ ↦ Real.exp (-(z ^ 2) / (2 * t))) + (Real.exp (-(y ^ 2) / (2 * t)) * -(y / t)) y := h_inner.exp + have h_mul := h_exp.const_mul ((Real.sqrt (2 * Real.pi * t))⁻¹) + -- h_mul : HasDerivAt (fun z ↦ K(t, z)) ((√(2πt))⁻¹ * (exp(-y²/(2t)) * -(y/t))) y + have h_val : + (Real.sqrt (2 * Real.pi * t))⁻¹ * (Real.exp (-(y ^ 2) / (2 * t)) * -(y / t)) + = -(y / t) * heatKernel t y := by + unfold heatKernel; ring + rw [← h_val]; exact h_mul + +/-- First `t`-derivative of the heat kernel: `∂_t K = K · (y² − t) / (2 t²)`. -/ +private lemma hasDerivAt_heatKernel_t {y : ℝ} {t : ℝ} (ht : 0 < t) : + HasDerivAt (fun s ↦ heatKernel s y) (heatKernel t y * (y ^ 2 - t) / (2 * t ^ 2)) t := by + -- Write K(s, y) = f(s) * g(s, y) where f(s) = (√(2πs))⁻¹ and g(s) = exp(-y²/(2s)). + -- f'(s) = -(1/2) * f(s) / s + -- g'(s) = g(s) * y² / (2 s²) + -- K'(s) = f'g + fg' = K · [-(1/(2s)) + y²/(2s²)] = K · (y² - s) / (2 s²) + -- f(s) = (√(2πs))⁻¹: derivative computation + have h_2pi_pos : 0 < 2 * Real.pi := by positivity + have h_2pis_pos : 0 < 2 * Real.pi * t := by positivity + have h_sqrt_pos : 0 < Real.sqrt (2 * Real.pi * t) := Real.sqrt_pos.mpr h_2pis_pos + have h_sqrt_ne : Real.sqrt (2 * Real.pi * t) ≠ 0 := h_sqrt_pos.ne' + have h_2pis_id : HasDerivAt (fun s : ℝ ↦ 2 * Real.pi * s) (2 * Real.pi) t := by + have := (hasDerivAt_id t).const_mul (2 * Real.pi) + simpa using this + have h_sqrt_inner : HasDerivAt (fun s : ℝ ↦ Real.sqrt (2 * Real.pi * s)) + (1 / (2 * Real.sqrt (2 * Real.pi * t)) * (2 * Real.pi)) t := + (Real.hasDerivAt_sqrt h_2pis_pos.ne').comp t h_2pis_id + have h_f : HasDerivAt (fun s : ℝ ↦ (Real.sqrt (2 * Real.pi * s))⁻¹) + (-(1 / (2 * Real.sqrt (2 * Real.pi * t)) * (2 * Real.pi)) / + (Real.sqrt (2 * Real.pi * t)) ^ 2) t := + h_sqrt_inner.inv h_sqrt_ne + -- g(s) = exp(-y²/(2s)): derivative computation + have h_2s : HasDerivAt (fun s : ℝ ↦ 2 * s) 2 t := by + simpa using (hasDerivAt_id t).const_mul 2 + have ht_ne : t ≠ 0 := ht.ne' + have h_2t_ne : (2 * t) ≠ 0 := by positivity + have h_inv_2s : HasDerivAt (fun s : ℝ ↦ (2 * s)⁻¹) (-2 / (2 * t) ^ 2) t := + h_2s.inv h_2t_ne + have h_inner : HasDerivAt (fun s : ℝ ↦ -(y ^ 2) / (2 * s)) + (-(y ^ 2) * (-2 / (2 * t) ^ 2)) t := by + have h_eq : (fun s : ℝ ↦ -(y ^ 2) / (2 * s)) = (fun s : ℝ ↦ -(y ^ 2) * (2 * s)⁻¹) := by + funext s; rw [div_eq_mul_inv] + rw [h_eq] + exact h_inv_2s.const_mul (-(y ^ 2)) + have h_g : HasDerivAt (fun s : ℝ ↦ Real.exp (-(y ^ 2) / (2 * s))) + (Real.exp (-(y ^ 2) / (2 * t)) * (-(y ^ 2) * (-2 / (2 * t) ^ 2))) t := h_inner.exp + -- Combine via product rule + have h_K := h_f.mul h_g + -- h_K : HasDerivAt (f * g) (h_f_val * g(t) + f(t) * h_g_val) t + -- where the value is: + -- -(1/(2√(2πt)) * 2π) / (√(2πt))² · exp(-y²/(2t)) + -- + (√(2πt))⁻¹ · (exp(-y²/(2t)) · (-y² · (-2/(2t)²))) + -- Using (√(2πt))² = 2πt, simplify: + -- -π/(2πt · √(2πt)) · exp + (√(2πt))⁻¹ · exp · y²/(2t²) + -- = (√(2πt))⁻¹ · exp · [-1/(2t) + y²/(2t²)] + -- = (√(2πt))⁻¹ · exp · (y² - t)/(2t²) + -- = heatKernel t y · (y² - t)/(2t²) + have h_sqrt_sq : (Real.sqrt (2 * Real.pi * t)) ^ 2 = 2 * Real.pi * t := + Real.sq_sqrt h_2pis_pos.le + have h_pi_ne : (Real.pi : ℝ) ≠ 0 := Real.pi_pos.ne' + have h_val : + -(1 / (2 * Real.sqrt (2 * Real.pi * t)) * (2 * Real.pi)) + / (Real.sqrt (2 * Real.pi * t)) ^ 2 * Real.exp (-(y ^ 2) / (2 * t)) + + (Real.sqrt (2 * Real.pi * t))⁻¹ + * (Real.exp (-(y ^ 2) / (2 * t)) * (-(y ^ 2) * (-2 / (2 * t) ^ 2))) + = heatKernel t y * (y ^ 2 - t) / (2 * t ^ 2) := by + unfold heatKernel + rw [h_sqrt_sq] + field_simp + ring + rw [← h_val]; exact h_K + +/-- Second `y`-derivative of the heat kernel: `∂²_y K = K · (y² − t) / t²`. +The first-derivative function being `z ↦ -(z/t) · K(t, z)`. -/ +private lemma hasDerivAt_heatKernel_y_y {t : ℝ} (ht : 0 < t) (y : ℝ) : + HasDerivAt (fun z ↦ -(z / t) * heatKernel t z) (heatKernel t y * (y ^ 2 - t) / t ^ 2) y := by + have ht_ne : t ≠ 0 := ht.ne' + have h_a : HasDerivAt (fun z : ℝ ↦ -(z / t)) (-(1 / t)) y := by + have h1 : HasDerivAt (fun z : ℝ ↦ z / t) (1 / t) y := by + have := (hasDerivAt_id y).div_const t + simpa using this + exact h1.neg + have h_b : HasDerivAt (fun z : ℝ ↦ heatKernel t z) (-(y / t) * heatKernel t y) y := + hasDerivAt_heatKernel_y ht y + have h_prod := h_a.mul h_b + have h_val : + -(1 / t) * heatKernel t y + -(y / t) * (-(y / t) * heatKernel t y) + = heatKernel t y * (y ^ 2 - t) / t ^ 2 := by + field_simp; ring + rw [← h_val]; exact h_prod + +/-- **Kernel `x`-derivative of the shifted heat kernel** `x ↦ K(t, z − x)`: +`∂_x K(t, z − x) = ((z − x)/t)·K(t, z − x)`. Chain rule on `hasDerivAt_heatKernel_y` +through the inner map `x ↦ z − x`. Building block for the shifted-integral heat +equation `∂_t u = ½ ∂_xx u` (benchmark `sc-thm-9.2.1`). -/ +private lemma hasDerivAt_heatKernel_x {t : ℝ} (ht : 0 < t) (z x : ℝ) : + HasDerivAt (fun x' ↦ heatKernel t (z - x')) + ((z - x) / t * heatKernel t (z - x)) x := by + have h := (hasDerivAt_heatKernel_y ht (z - x)).comp x ((hasDerivAt_id x).const_sub z) + convert h using 1 <;> first | rfl | ring + +/-- **Second kernel `x`-derivative**: +`∂_xx K(t, z − x) = ∂_x [((z − x)/t)·K(t, z − x)] = K(t, z − x)·((z − x)² − t)/t²`. +Chain rule on `hasDerivAt_heatKernel_y_y` through `x ↦ z − x`, then a sign flip +(`(z − x)/t · K = −(−(z − x)/t · K)`). Building block for `sc-thm-9.2.1`. -/ +private lemma hasDerivAt_heatKernel_x_x {t : ℝ} (ht : 0 < t) (z x : ℝ) : + HasDerivAt (fun x' ↦ (z - x') / t * heatKernel t (z - x')) + (heatKernel t (z - x) * ((z - x) ^ 2 - t) / t ^ 2) x := by + have hfun : (fun x' ↦ (z - x') / t * heatKernel t (z - x')) + = (fun x' ↦ -(-((z - x') / t) * heatKernel t (z - x'))) := by funext x'; ring + rw [hfun] + have h := ((hasDerivAt_heatKernel_y_y ht (z - x)).comp x + ((hasDerivAt_id x).const_sub z)).neg + convert h using 1 <;> first | rfl | ring + +/-- **Joint differentiability of the heat kernel** in `(t, y)` (for `t > 0`). The Fréchet derivative +at `(t₀, y₀)` is the row functional `(a, b) ↦ ∂_t K · a + ∂_y K · b` (`∂_t K = K·(y²−t)/(2t²)`, +`∂_y K = −(y/t)·K`). Built from the elementary calculus of `(√(2πt))⁻¹·exp(−y²/(2t))`; the two +columns read off against the basis. This upgrades the two separately-proved partials to a *total* +derivative — the one genuinely-2D ingredient that lets the price, differentiated along a curve +`τ ↦ (v τ, w τ)` with both kernel arguments moving, collapse to a single chain rule. -/ +lemma hasFDerivAt_heatKernel {t₀ : ℝ} (ht₀ : 0 < t₀) (y₀ : ℝ) : + HasFDerivAt (fun p : ℝ × ℝ ↦ heatKernel p.1 p.2) + ((heatKernel t₀ y₀ * (y₀ ^ 2 - t₀) / (2 * t₀ ^ 2)) • ContinuousLinearMap.fst ℝ ℝ ℝ + + (-(y₀ / t₀) * heatKernel t₀ y₀) • ContinuousLinearMap.snd ℝ ℝ ℝ) (t₀, y₀) := by + have h2pit : (0:ℝ) < 2 * Real.pi * t₀ := by positivity + have hsqrt_ne : Real.sqrt (2 * Real.pi * t₀) ≠ 0 := (Real.sqrt_pos.mpr h2pit).ne' + have h2t0_ne : (2 * t₀) ≠ 0 := by positivity + have hlin1 : HasFDerivAt (fun p : ℝ × ℝ ↦ 2 * Real.pi * p.1) + ((2 * Real.pi) • ContinuousLinearMap.fst ℝ ℝ ℝ) (t₀, y₀) := by + exact ((2 * Real.pi) • ContinuousLinearMap.fst ℝ ℝ ℝ).hasFDerivAt (x := (t₀, y₀)) + have hlin2 : HasFDerivAt (fun p : ℝ × ℝ ↦ 2 * p.1) + ((2 : ℝ) • ContinuousLinearMap.fst ℝ ℝ ℝ) (t₀, y₀) := by + exact ((2 : ℝ) • ContinuousLinearMap.fst ℝ ℝ ℝ).hasFDerivAt (x := (t₀, y₀)) + have hsnd : HasFDerivAt (fun p : ℝ × ℝ ↦ p.2) (ContinuousLinearMap.snd ℝ ℝ ℝ) (t₀, y₀) := by + exact (ContinuousLinearMap.snd ℝ ℝ ℝ).hasFDerivAt (x := (t₀, y₀)) + have hA := (hasDerivAt_inv hsqrt_ne).comp_hasFDerivAt (t₀, y₀) + ((Real.hasDerivAt_sqrt h2pit.ne').comp_hasFDerivAt (t₀, y₀) hlin1) + have hnum := (hsnd.pow 2).neg + have hden := (hasDerivAt_inv h2t0_ne).comp_hasFDerivAt (t₀, y₀) hlin2 + have hB := (hnum.mul hden).exp + convert hA.mul hB using 1 <;> try rfl + refine ContinuousLinearMap.ext fun v ↦ ?_ + simp only [add_apply, smul_apply, + neg_apply, ContinuousLinearMap.coe_fst', + ContinuousLinearMap.coe_snd', smul_eq_mul, + Pi.mul_apply, Pi.neg_apply, Function.comp_apply, heatKernel] + rw [show -(y₀ ^ 2) / (2 * t₀) = -(y₀ ^ 2) * (2 * t₀)⁻¹ from div_eq_mul_inv _ _, + show Real.sqrt (2 * Real.pi * t₀) ^ 2 = 2 * Real.pi * t₀ from Real.sq_sqrt h2pit.le] + field_simp + ring + +/-- **Derivative of the heat kernel along a curve** `s ↦ K(v s, z − w s)`. With both the variance +`v s` and the centre `w s` moving, the chain rule on `hasFDerivAt_heatKernel` collapses to +`v′·∂_t K + w′·∂_x K`. The kernel-level engine for the Black–Scholes `τ`-derivative, where +`v τ = σ²τ` and `w τ = log S + (r − σ²/2)τ` move together. -/ +lemma hasDerivAt_heatKernel_comp {v w : ℝ → ℝ} {τ₀ vd wd : ℝ} + (hv : HasDerivAt v vd τ₀) (hw : HasDerivAt w wd τ₀) (hvpos : 0 < v τ₀) (z : ℝ) : + HasDerivAt (fun s ↦ heatKernel (v s) (z - w s)) + (vd * (heatKernel (v τ₀) (z - w τ₀) * ((z - w τ₀) ^ 2 - v τ₀) / (2 * (v τ₀) ^ 2)) + + wd * ((z - w τ₀) / (v τ₀) * heatKernel (v τ₀) (z - w τ₀))) τ₀ := by + have hcurve : HasDerivAt (fun s ↦ (v s, z - w s)) (vd, -wd) τ₀ := + hv.prodMk (hw.const_sub z) + have hcomp := (hasFDerivAt_heatKernel hvpos (z - w τ₀)).comp_hasDerivAt τ₀ hcurve + convert hcomp using 1 <;> try rfl + simp only [add_apply, smul_apply, + ContinuousLinearMap.coe_fst', ContinuousLinearMap.coe_snd', smul_eq_mul] + ring + +/-- **Heat-kernel PDE on `heatKernel`**: `∂_t K = (1/2) ∂²_y K`. As an algebraic +identity on the derivative values from `hasDerivAt_heatKernel_t` and +`hasDerivAt_heatKernel_y_y`. + +The load-bearing kernel-side input to the **heat equation for `u`** `∂_t u = ½ ∂_xx u`: +used by `feynmanU_heat_equation` and the Black–Scholes PDE proof in +`Models/BlackScholes/PDEFromFeynmanKac.lean`. -/ +private lemma heatKernel_t_eq_half_y_y {t : ℝ} (ht : 0 < t) (y : ℝ) : + heatKernel t y * (y ^ 2 - t) / (2 * t ^ 2) + = (1 / 2) * (heatKernel t y * (y ^ 2 - t) / t ^ 2) := by + have ht_ne : t ≠ 0 := ht.ne' + field_simp + +/-! ### Auxiliary integrability + nonnegativity for the heat kernel -/ + +/-- The heat kernel is nonnegative. -/ +lemma heatKernel_nonneg {t : ℝ} (ht : 0 < t) (y : ℝ) : 0 ≤ heatKernel t y := by + rw [heatKernel_eq_gaussianPDFReal ht] + exact gaussianPDFReal_nonneg 0 _ y + +/-- For `t > 0`, the heat kernel is integrable in `y` over Lebesgue. -/ +lemma integrable_heatKernel {t : ℝ} (ht : 0 < t) : + Integrable (fun y ↦ heatKernel t y) volume := by + have := integrable_gaussianPDFReal (0 : ℝ) t.toNNReal + refine this.congr (Filter.Eventually.of_forall fun y ↦ ?_) + exact (heatKernel_eq_gaussianPDFReal ht y).symm + +/-- **Transfer integrability from the Gaussian law to the heat kernel.** If `g ∈ L¹(N(0,t))`, +then `g · K(t,·)` is Lebesgue-integrable — because `N(0,t) = volume.withDensity K(t,·)`. This +turns Gaussian moments (`memLp_id_gaussianReal`) into integrability of polynomial × heat kernel, +needed for the integration-by-parts in the expectation-form Itô formula. -/ +private lemma integrable_mul_heatKernel_of_gaussian {t : ℝ} (ht : 0 < t) {g : ℝ → ℝ} + (hg : Integrable g (gaussianReal 0 t.toNNReal)) : + Integrable (fun y ↦ g y * heatKernel t y) volume := by + have hv : (t.toNNReal : ℝ≥0) ≠ 0 := (Real.toNNReal_pos.mpr ht).ne' + rw [gaussianReal_of_var_ne_zero 0 hv, + integrable_withDensity_iff_integrable_smul' (by fun_prop) + (ae_of_all _ fun y ↦ gaussianPDF_lt_top)] at hg + refine hg.congr (Filter.Eventually.of_forall fun y ↦ ?_) + change (gaussianPDF 0 t.toNNReal y).toReal • g y = g y * heatKernel t y + have hpdf : (gaussianPDF 0 t.toNNReal y).toReal = heatKernel t y := by + rw [heatKernel_eq_gaussianPDFReal ht] + simp only [gaussianPDF] + rw [ENNReal.toReal_ofReal (gaussianPDFReal_nonneg _ _ _)] + rw [smul_eq_mul, hpdf]; ring + +/-- First moment: `y · K(t, ·)` is integrable. -/ +lemma integrable_id_mul_heatKernel {t : ℝ} (ht : 0 < t) : + Integrable (fun y ↦ y * heatKernel t y) volume := + integrable_mul_heatKernel_of_gaussian ht + ((memLp_id_gaussianReal (μ := 0) (v := t.toNNReal) 1).integrable (by norm_num)) + +/-- Second moment: `y² · K(t, ·)` is integrable. -/ +lemma integrable_sq_mul_heatKernel {t : ℝ} (ht : 0 < t) : + Integrable (fun y ↦ y ^ 2 * heatKernel t y) volume := + integrable_mul_heatKernel_of_gaussian ht + (memLp_id_gaussianReal (μ := 0) (v := t.toNNReal) 2).integrable_sq + +/-- `∂_y K = -(y/t)·K` is integrable. -/ +private lemma integrable_dK {t : ℝ} (ht : 0 < t) : + Integrable (fun y ↦ -(y / t) * heatKernel t y) volume := by + refine ((integrable_id_mul_heatKernel ht).const_mul (-(1 / t))).congr + (Filter.Eventually.of_forall fun y ↦ ?_) + change -(1 / t) * (y * heatKernel t y) = -(y / t) * heatKernel t y + ring + +/-- `∂²_y K = K·(y²−t)/t²` is integrable. -/ +private lemma integrable_ddK {t : ℝ} (ht : 0 < t) : + Integrable (fun y ↦ heatKernel t y * (y ^ 2 - t) / t ^ 2) volume := by + have ht_ne : t ≠ 0 := ht.ne' + refine (((integrable_sq_mul_heatKernel ht).const_mul (1 / t ^ 2)).sub + ((integrable_heatKernel ht).const_mul (1 / t))).congr (Filter.Eventually.of_forall fun y ↦ ?_) + change 1 / t ^ 2 * (y ^ 2 * heatKernel t y) - 1 / t * heatKernel t y + = heatKernel t y * (y ^ 2 - t) / t ^ 2 + field_simp + +/-- **Integration by parts against the heat kernel** (the analytic heart of expectation-Itô). +For `f ∈ C²_b`, two improper integrations by parts over `ℝ` move both derivatives off the kernel +onto `f`: `∫ f(y)·∂²_y K(t,y) dy = ∫ f′′(y)·K(t,y) dy`. The boundary terms vanish (`f, f′` bounded, +`K, ∂_y K` Gaussian-decaying), which is encoded by `integral_mul_deriv_eq_deriv_mul_of_integrable` +(the integrable-product form needs no explicit boundary hypothesis). -/ +private lemma ibp_heatKernel {t : ℝ} (ht : 0 < t) {f f' f'' : ℝ → ℝ} + (hf : ∀ x, HasDerivAt f (f' x) x) (hf' : ∀ x, HasDerivAt f' (f'' x) x) + (hf''c : Continuous f'') {Cf Cf' Cf'' : ℝ} + (hCf : ∀ x, |f x| ≤ Cf) (hCf' : ∀ x, |f' x| ≤ Cf') (hCf'' : ∀ x, |f'' x| ≤ Cf'') : + ∫ y, f y * (heatKernel t y * (y ^ 2 - t) / t ^ 2) ∂volume + = ∫ y, f'' y * heatKernel t y ∂volume := by + have hfc : Continuous f := continuous_iff_continuousAt.mpr fun x ↦ (hf x).continuousAt + have hf'c : Continuous f' := continuous_iff_continuousAt.mpr fun x ↦ (hf' x).continuousAt + have hi_f_ddK : Integrable (fun y ↦ f y * (heatKernel t y * (y ^ 2 - t) / t ^ 2)) volume := + (integrable_ddK ht).bdd_mul hfc.aestronglyMeasurable + (ae_of_all _ fun y ↦ by rw [Real.norm_eq_abs]; exact hCf y) + have hi_f'_dK : Integrable (fun y ↦ f' y * (-(y / t) * heatKernel t y)) volume := + (integrable_dK ht).bdd_mul hf'c.aestronglyMeasurable + (ae_of_all _ fun y ↦ by rw [Real.norm_eq_abs]; exact hCf' y) + have hi_f_dK : Integrable (fun y ↦ f y * (-(y / t) * heatKernel t y)) volume := + (integrable_dK ht).bdd_mul hfc.aestronglyMeasurable + (ae_of_all _ fun y ↦ by rw [Real.norm_eq_abs]; exact hCf y) + have hi_f''_K : Integrable (fun y ↦ f'' y * heatKernel t y) volume := + (integrable_heatKernel ht).bdd_mul hf''c.aestronglyMeasurable + (ae_of_all _ fun y ↦ by rw [Real.norm_eq_abs]; exact hCf'' y) + have hi_f'_K : Integrable (fun y ↦ f' y * heatKernel t y) volume := + (integrable_heatKernel ht).bdd_mul hf'c.aestronglyMeasurable + (ae_of_all _ fun y ↦ by rw [Real.norm_eq_abs]; exact hCf' y) + have ibp1 := integral_mul_deriv_eq_deriv_mul_of_integrable + (u := f) (v := fun z ↦ -(z / t) * heatKernel t z) + (v' := fun z ↦ heatKernel t z * (z ^ 2 - t) / t ^ 2) + (fun x _ ↦ hf x) (fun x _ ↦ hasDerivAt_heatKernel_y_y ht x) hi_f_ddK hi_f'_dK hi_f_dK + have ibp2 := integral_mul_deriv_eq_deriv_mul_of_integrable + (u := f') (v := fun z ↦ heatKernel t z) + (v' := fun z ↦ -(z / t) * heatKernel t z) + (fun x _ ↦ hf' x) (fun x _ ↦ hasDerivAt_heatKernel_y ht x) hi_f'_dK hi_f''_K hi_f'_K + rw [ibp1, ibp2, neg_neg] + +/-- The heat kernel is continuous in the space variable (for any fixed time). -/ +lemma continuous_heatKernel (s : ℝ) : Continuous (fun y ↦ heatKernel s y) := by + unfold heatKernel; fun_prop + +/-- The polynomial-times-heat-kernel function `(y² + c)·K(s, y)` is integrable (`s > 0`). This +is the integrable majorant used to dominate `∂_t K(·, y)` over a time-neighbourhood of `t` +(instantiated at `s = 3t/2`); built directly from the moment integrabilities +`integrable_sq_mul_heatKernel` / `integrable_heatKernel`, avoiding raw-`rpow` Gaussians. -/ +private lemma integrable_poly_heatKernel {s : ℝ} (hs : 0 < s) (c : ℝ) : + Integrable (fun y ↦ (y ^ 2 + c) * heatKernel s y) volume := by + refine ((integrable_sq_mul_heatKernel hs).add + ((integrable_heatKernel hs).const_mul c)).congr (Filter.Eventually.of_forall fun y ↦ ?_) + simp only [Pi.add_apply]; ring + +/-- **Completing-the-square mean shift at the kernel level.** Multiplying the heat kernel by the +exponential `eᶻ` is the same as translating its centre by the variance: +`eᶻ·K(σ, z−c) = e^{c+σ/2}·K(σ, z−(c+σ))`. The proof is the elementary completing-the-square identity +`z − (z−c)²/(2σ) = (c+σ/2) − (z−(c+σ))²/(2σ)` — the analytic core underlying the Cameron–Martin / +Girsanov density shift, here used purely as a real-analysis fact (no measure change). It converts a +sub-Gaussian envelope `eᶻ·poly·K` into `poly·(shifted K)`, whose integrability is then just Gaussian +moments — the load-bearing input to `integrable_exp_mul_poly_heatKernel`. -/ +private lemma exp_mul_heatKernel {σ : ℝ} (hσ : 0 < σ) (c z : ℝ) : + Real.exp z * heatKernel σ (z - c) + = Real.exp (c + σ / 2) * heatKernel σ (z - (c + σ)) := by + have hσ' : σ ≠ 0 := hσ.ne' + simp only [heatKernel] + rw [mul_left_comm, mul_left_comm (Real.exp (c + σ / 2))] + congr 1 + rw [← Real.exp_add, ← Real.exp_add] + congr 1 + field_simp + ring + +/-- **The sub-Gaussian envelope is integrable.** For `σ > 0`, the function +`z ↦ eᶻ·((z−c)² + d)·K(σ, z−c)` is Lebesgue-integrable. By the mean shift `exp_mul_heatKernel` +it equals `e^{c+σ/2}·((z−c)² + d)·K(σ, z−(c+σ))`; expanding `(z−c)² = (z−(c+σ))² + 2σ(z−(c+σ)) + σ²` +turns it into a finite combination of heat-kernel moments (`integrable_sq_mul_heatKernel`, +`integrable_id_mul_heatKernel`, `integrable_heatKernel`) translated by `c+σ` +(`Integrable.comp_sub_right`). This is the dominating function that lets the call payoff +`(eᶻ − K)⁺ ≤ eᶻ` pass under the integral sign — the one genuinely new analytic ingredient for the +kernel-side heat equation. -/ +lemma integrable_exp_mul_poly_heatKernel {σ : ℝ} (hσ : 0 < σ) (c d : ℝ) : + Integrable (fun z ↦ Real.exp z * (((z - c) ^ 2 + d) * heatKernel σ (z - c))) volume := by + have hbase : Integrable (fun w : ℝ ↦ + w ^ 2 * heatKernel σ w + 2 * σ * (w * heatKernel σ w) + (σ ^ 2 + d) * heatKernel σ w) + volume := by + have h1 := integrable_sq_mul_heatKernel hσ + have h2 := (integrable_id_mul_heatKernel hσ).const_mul (2 * σ) + have h3 := (integrable_heatKernel hσ).const_mul (σ ^ 2 + d) + exact (h1.add h2).add h3 + have htrans := (hbase.comp_sub_right (c + σ)).const_mul (Real.exp (c + σ / 2)) + refine htrans.congr (Filter.Eventually.of_forall fun z ↦ ?_) + dsimp only + rw [show Real.exp z * (((z - c) ^ 2 + d) * heatKernel σ (z - c)) + = ((z - c) ^ 2 + d) * (Real.exp z * heatKernel σ (z - c)) from by ring, + exp_mul_heatKernel hσ c z] + ring + +/-- **Integrability of a sub-Gaussian payoff against the shifted heat kernel.** For `t > 0`, +`h` continuous with `|h z| ≤ eᶻ`, the integrand `z ↦ h z · K(t, z−x)` is Lebesgue-integrable — +dominated by the envelope `eᶻ·((z−x)²+1)·K(t, z−x)` of `integrable_exp_mul_poly_heatKernel`. The +"value at the base point" integrability shared by the time- and first-space-derivative lemmas +`hasDerivAt_feynmanU_t` / `hasDerivAt_feynmanU_x` below. -/ +lemma integrable_payoff_mul_heatKernel {t : ℝ} (ht : 0 < t) {h : ℝ → ℝ} (hhc : Continuous h) + (hh : ∀ z, |h z| ≤ Real.exp z) (x : ℝ) : + Integrable (fun z ↦ h z * heatKernel t (z - x)) volume := by + refine (integrable_exp_mul_poly_heatKernel ht x 1).mono' + (hhc.mul ((continuous_heatKernel t).comp + (continuous_id.sub continuous_const))).aestronglyMeasurable (ae_of_all _ fun z ↦ ?_) + change ‖h z * heatKernel t (z - x)‖ ≤ Real.exp z * (((z - x) ^ 2 + 1) * heatKernel t (z - x)) + rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (heatKernel_nonneg ht (z - x))] + have hKnn := heatKernel_nonneg ht (z - x) + calc |h z| * heatKernel t (z - x) + ≤ Real.exp z * heatKernel t (z - x) := mul_le_mul_of_nonneg_right (hh z) hKnn + _ ≤ Real.exp z * (((z - x) ^ 2 + 1) * heatKernel t (z - x)) := by + apply mul_le_mul_of_nonneg_left _ (Real.exp_nonneg z) + simpa only [one_mul] using mul_le_mul_of_nonneg_right + (show 1 ≤ (z - x) ^ 2 + 1 from le_add_of_nonneg_left (sq_nonneg (z - x))) hKnn + +/-- **Spatial monotonicity of the heat kernel.** For `t > 0` and `|x − x₀| < δ`, the kernel centred +near `x` is dominated by a *wider* kernel centred at the fixed `x₀`: +`K(t, z − x) ≤ √2 · e^{δ²/(2t)} · K(2t, z − x₀)`. From the elementary `(a + b)² ≥ ½a² − b²` (here +`(z−x)² ≥ ½(z−x₀)² − (x−x₀)² ≥ ½(z−x₀)² − δ²`), so +`exp(−(z−x)²/(2t)) ≤ e^{δ²/(2t)}·exp(−(z−x₀)²/(4t))`, and +`exp(−(z−x₀)²/(4t)) = √2·√(2πt)·K(2t,z−x₀)`. This is the spatial analogue of the temporal bound +`K(s,·) ≤ √3·K(3t/2,·)` (`heatKernel_temporal_le`); it makes the `x`-derivatives' dominating +function independent of `x` over `Metric.ball x₀ δ`. -/ +lemma heatKernel_shift_le {t : ℝ} (ht : 0 < t) {x x₀ δ : ℝ} + (hx : |x - x₀| < δ) (z : ℝ) : + heatKernel t (z - x) + ≤ Real.sqrt 2 * Real.exp (δ ^ 2 / (2 * t)) * heatKernel (2 * t) (z - x₀) := by + have h2t : (0 : ℝ) < 2 * t := by positivity + have h4t : (0 : ℝ) < 4 * t := by positivity + have hδsq : (x - x₀) ^ 2 < δ ^ 2 := sq_lt_sq' (abs_lt.mp hx).1 (abs_lt.mp hx).2 + have hnum : 2 * (z - x) ^ 2 - (z - x₀) ^ 2 + 2 * δ ^ 2 ≥ 0 := by + linarith only [sq_nonneg (z - x₀ - 2 * (x - x₀)), hδsq] + have hexp : -(z - x) ^ 2 / (2 * t) ≤ δ ^ 2 / (2 * t) + -(z - x₀) ^ 2 / (4 * t) := by + rw [div_add_div _ _ (ne_of_gt h2t) (ne_of_gt h4t), div_le_div_iff₀ h2t (by positivity)] + linarith only [mul_nonneg hnum (sq_nonneg t)] + have hexp_le : Real.exp (-(z - x) ^ 2 / (2 * t)) + ≤ Real.exp (δ ^ 2 / (2 * t)) * Real.exp (-(z - x₀) ^ 2 / (4 * t)) := by + rw [← Real.exp_add]; exact Real.exp_le_exp.mpr hexp + have hconst : (Real.sqrt (2 * Real.pi * t))⁻¹ + = Real.sqrt 2 * (Real.sqrt (2 * Real.pi * (2 * t)))⁻¹ := by + rw [show 2 * Real.pi * (2 * t) = 2 * (2 * Real.pi * t) from by ring, + Real.sqrt_mul (by norm_num : (0:ℝ) ≤ 2), mul_inv, ← mul_assoc, + mul_inv_cancel₀ (Real.sqrt_pos.mpr (by norm_num : (0:ℝ) < 2)).ne', one_mul] + have hKeq : (Real.sqrt (2 * Real.pi * t))⁻¹ * Real.exp (-(z - x₀) ^ 2 / (4 * t)) + = Real.sqrt 2 * heatKernel (2 * t) (z - x₀) := by + rw [heatKernel, show -(z - x₀) ^ 2 / (2 * (2 * t)) = -(z - x₀) ^ 2 / (4 * t) from by + rw [show 2 * (2 * t) = 4 * t from by ring], hconst] + ring + calc heatKernel t (z - x) + = (Real.sqrt (2 * Real.pi * t))⁻¹ * Real.exp (-(z - x) ^ 2 / (2 * t)) := by rw [heatKernel] + _ ≤ (Real.sqrt (2 * Real.pi * t))⁻¹ + * (Real.exp (δ ^ 2 / (2 * t)) * Real.exp (-(z - x₀) ^ 2 / (4 * t))) := + mul_le_mul_of_nonneg_left hexp_le (by positivity) + _ = Real.exp (δ ^ 2 / (2 * t)) + * ((Real.sqrt (2 * Real.pi * t))⁻¹ * Real.exp (-(z - x₀) ^ 2 / (4 * t))) := by ring + _ = Real.exp (δ ^ 2 / (2 * t)) * (Real.sqrt 2 * heatKernel (2 * t) (z - x₀)) := by rw [hKeq] + _ = Real.sqrt 2 * Real.exp (δ ^ 2 / (2 * t)) * heatKernel (2 * t) (z - x₀) := by ring + +/-- **Temporal monotonicity of the heat kernel.** On the time-window `(t/2, 3t/2)`, +`K(s, y) ≤ √3 · K(3t/2, y)`: a smaller variance is dominated by the fixed wider one. The temporal +analogue of `heatKernel_shift_le`, and the domination engine for the time-derivative lemmas +`hasDerivAt_phi` / `hasDerivAt_feynmanU_t`. -/ +lemma heatKernel_temporal_le {t s : ℝ} (ht : 0 < t) (hs_lo : t / 2 < s) (hs_hi : s < 3 * t / 2) + (y : ℝ) : heatKernel s y ≤ Real.sqrt 3 * heatKernel (3 * t / 2) y := by + have hs_pos : 0 < s := by linarith + have hKstep : heatKernel s y ≤ (Real.sqrt (Real.pi * t))⁻¹ * Real.exp (-(y ^ 2) / (3 * t)) := by + rw [heatKernel] + have hf1 : (Real.sqrt (2 * Real.pi * s))⁻¹ ≤ (Real.sqrt (Real.pi * t))⁻¹ := by + apply inv_anti₀ (by positivity) (Real.sqrt_le_sqrt ?_) + linarith only [mul_le_mul_of_nonneg_left (show t ≤ 2 * s by linarith only [hs_lo]) + Real.pi_pos.le] + have hf2 : Real.exp (-(y ^ 2) / (2 * s)) ≤ Real.exp (-(y ^ 2) / (3 * t)) := by + apply Real.exp_le_exp.mpr + rw [neg_div, neg_div, neg_le_neg_iff, div_le_div_iff₀ (by positivity) (by positivity)] + exact mul_le_mul_of_nonneg_left (by linarith only [hs_hi]) (sq_nonneg y) + exact mul_le_mul hf1 hf2 (by positivity) (by positivity) + have hKeq : (Real.sqrt (Real.pi * t))⁻¹ * Real.exp (-(y ^ 2) / (3 * t)) + = Real.sqrt 3 * heatKernel (3 * t / 2) y := by + have hsqrt : Real.sqrt (2 * Real.pi * (3 * t / 2)) = Real.sqrt 3 * Real.sqrt (Real.pi * t) := by + rw [show 2 * Real.pi * (3 * t / 2) = 3 * (Real.pi * t) from by ring, + Real.sqrt_mul (by norm_num : (0:ℝ) ≤ 3)] + simp only [heatKernel] + rw [show -(y ^ 2) / (2 * (3 * t / 2)) = -(y ^ 2) / (3 * t) from by + rw [show 2 * (3 * t / 2) = 3 * t from by ring], + hsqrt, mul_inv] + field_simp + exact hKeq ▸ hKstep + +/-- **Quadratic-over-variance ratio bound** on the time window `(t/2, 3t/2)`: +`|w² − s| / (2 s²) ≤ 2 (w² + 3t/2) / t²`. The polynomial factor of the time-derivative domination, +shared verbatim (modulo the centring `w = y` vs `w = z−x`) by `hasDerivAt_phi` and +`hasDerivAt_feynmanU_t`. -/ +lemma sq_sub_div_le {t s : ℝ} (ht : 0 < t) (hs_lo : t / 2 < s) (hs_hi : s < 3 * t / 2) + (w : ℝ) : |w ^ 2 - s| / (2 * s ^ 2) ≤ 2 * (w ^ 2 + 3 * t / 2) / t ^ 2 := by + have hs_pos : 0 < s := by linarith + have habs : |w ^ 2 - s| ≤ w ^ 2 + 3 * t / 2 := by + rw [abs_le]; constructor <;> nlinarith [sq_nonneg w] + have ht4s : t ^ 2 ≤ 4 * s ^ 2 := by + have h := (sq_le_sq₀ ht.le (show 0 ≤ 2 * s by positivity)).2 + (show t ≤ 2 * s by linarith only [hs_lo]) + linarith only [h] + rw [div_le_div_iff₀ (by positivity) (by positivity)] + linarith only [mul_le_mul_of_nonneg_right habs (sq_nonneg t), + mul_le_mul_of_nonneg_left ht4s (show (0:ℝ) ≤ w ^ 2 + 3 * t / 2 by positivity)] + +/-- **Local domination of the heat kernel under a joint variance + centre perturbation.** When the +variance `v` stays in `(v₀/2, 3v₀/2)` and the centre `x` within `δ` of `x₀`, +`K(v, z−x) ≤ √3·√2·e^{δ²/(3v₀)}·K(3v₀, z−x₀)`. The composition of `heatKernel_temporal_le` +(variance) with `heatKernel_shift_le` (centre); the domination engine for differentiating the price +along the curve `τ ↦ (σ²τ, log S + (r−σ²/2)τ)`, where both kernel arguments move with `τ`. -/ +lemma heatKernel_loc_le {v₀ v x x₀ δ : ℝ} (hv₀ : 0 < v₀) + (hv_lo : v₀ / 2 < v) (hv_hi : v < 3 * v₀ / 2) (hx : |x - x₀| < δ) (z : ℝ) : + heatKernel v (z - x) + ≤ Real.sqrt 3 * (Real.sqrt 2 * Real.exp (δ ^ 2 / (3 * v₀))) * + heatKernel (3 * v₀) (z - x₀) := by + have h32 : (0 : ℝ) < 3 * v₀ / 2 := by positivity + calc heatKernel v (z - x) + ≤ Real.sqrt 3 * heatKernel (3 * v₀ / 2) (z - x) := + heatKernel_temporal_le hv₀ hv_lo hv_hi (z - x) + _ ≤ Real.sqrt 3 * (Real.sqrt 2 * Real.exp (δ ^ 2 / (2 * (3 * v₀ / 2))) + * heatKernel (2 * (3 * v₀ / 2)) (z - x₀)) := + mul_le_mul_of_nonneg_left (heatKernel_shift_le h32 hx z) (Real.sqrt_nonneg 3) + _ = Real.sqrt 3 * (Real.sqrt 2 * Real.exp (δ ^ 2 / (3 * v₀))) * + heatKernel (3 * v₀) (z - x₀) := by + rw [show 2 * (3 * v₀ / 2) = 3 * v₀ from by ring]; ring + +/-- **Curve quadratic-ratio bound** (the `∂_t`-kernel polynomial factor of the curve domination). On +`v ∈ (v₀/2, 3v₀/2)` with the centre shifted by `≤ d` (`|W − W₀| ≤ d`), the moving denominator is +absorbed into the fixed `v₀`: `|W²−v|/(2v²) ≤ 2(2W₀²+2d²+3v₀/2)/v₀²`. Isolated as its own lemma so +the `nlinarith` elaborates without the heartbeat blow-up that defeats it inline. -/ +lemma curve_sq_ratio_le {v₀ v W W₀ d : ℝ} (hv₀ : 0 < v₀) (hvlo : v₀ / 2 < v) + (hvhi : v < 3 * v₀ / 2) (hW : |W - W₀| ≤ d) (hd : 0 ≤ d) : + |W ^ 2 - v| / (2 * v ^ 2) ≤ 2 * (2 * W₀ ^ 2 + 2 * d ^ 2 + 3 * v₀ / 2) / v₀ ^ 2 := by + have hvpos : 0 < v := by linarith + have hWsq : W ^ 2 ≤ 2 * W₀ ^ 2 + 2 * d ^ 2 := by + have hd2 : (W - W₀) ^ 2 ≤ d ^ 2 := by + nlinarith [sq_abs (W - W₀), mul_le_mul hW hW (abs_nonneg (W - W₀)) hd] + nlinarith [hd2, sq_nonneg (W - 2 * W₀)] + have habs : |W ^ 2 - v| ≤ W ^ 2 + v := by rw [abs_le]; constructor <;> nlinarith [sq_nonneg W] + have hfac : (0:ℝ) ≤ 4 * v ^ 2 - v₀ ^ 2 := by nlinarith [hvlo, hvpos, hv₀] + have hpoly_nn : (0:ℝ) ≤ 2 * W₀ ^ 2 + 2 * d ^ 2 + 3 * v₀ / 2 := by positivity + rw [div_le_div_iff₀ (by positivity) (by positivity)] + nlinarith [habs, hWsq, hvhi, hvpos, mul_nonneg hpoly_nn hfac, sq_nonneg W₀] + +/-- **Curve linear-ratio bound** (the `∂_x`-kernel polynomial factor). Companion to +`curve_sq_ratio_le`: `|W|/v ≤ 2(W₀²+1+d)/v₀` on `v > v₀/2` with `|W − W₀| ≤ d`. -/ +lemma curve_abs_ratio_le {v₀ v W W₀ d : ℝ} (hv₀ : 0 < v₀) (hvlo : v₀ / 2 < v) + (hW : |W - W₀| ≤ d) (hd : 0 ≤ d) : + |W| / v ≤ 2 * (W₀ ^ 2 + 1 + d) / v₀ := by + have hvpos : 0 < v := by linarith + have hWabs : |W| ≤ W₀ ^ 2 + 1 + d := by + have h1 : |W| ≤ |W₀| + d := by + have htri : |W| ≤ |W₀| + |W - W₀| := by + calc |W| = |W₀ + (W - W₀)| := by ring_nf + _ ≤ |W₀| + |W - W₀| := abs_add_le _ _ + linarith [htri, hW] + have h2 : |W₀| ≤ W₀ ^ 2 + 1 := by nlinarith [sq_nonneg (|W₀| - 1), sq_abs W₀, abs_nonneg W₀] + linarith + rw [div_le_div_iff₀ hvpos (by positivity)] + nlinarith [hWabs, hvlo, hvpos, hv₀, abs_nonneg W, + mul_nonneg (show (0:ℝ) ≤ W₀ ^ 2 + 1 + d by positivity) (show (0:ℝ) ≤ 2 * v - v₀ by linarith)] + +/-- **Parametric differentiation under the integral, for an `h`-weighted kernel family.** The single +skeleton behind every derivative of a heat-flow integral `p ↦ ∫ z, h z · φ(p, z) dz`: given the +family's pointwise derivative `φ′(p, ·)` on a ball around `p₀`, an integrable base point, and an +integrable uniform dominating function for `h·φ′`, the integral is differentiable with +`d/dp = ∫ h·φ′(p₀, ·)`. Specialising `φ` to `K(s, z−x)` (time) or `K(t, z−x')` (space, once and +twice) recovers `hasDerivAt_phi` and `hasDerivAt_feynmanU_{t,x,xx}`, each supplying only its +genuinely-distinct domination. The `h z`-factor is pulled through `HasDerivAt.const_mul`, so callers +hand over the bare kernel-family derivative. -/ +theorem hasDerivAt_integral_mul_kernelFamily {h : ℝ → ℝ} (hhc : Continuous h) + {φ φ' : ℝ → ℝ → ℝ} {p₀ r : ℝ} (hr : 0 < r) + (hφc : ∀ p, Continuous (fun z ↦ φ p z)) (hφ'c : Continuous (fun z ↦ φ' p₀ z)) + (hpt : Integrable (fun z ↦ h z * φ p₀ z) volume) + {bound : ℝ → ℝ} (hbi : Integrable bound volume) + (hb : ∀ᵐ z ∂volume, ∀ p ∈ Metric.ball p₀ r, ‖h z * φ' p z‖ ≤ bound z) + (hderiv : ∀ z, ∀ p ∈ Metric.ball p₀ r, HasDerivAt (fun p ↦ φ p z) (φ' p z) p) : + HasDerivAt (fun p ↦ ∫ z, h z * φ p z ∂volume) (∫ z, h z * φ' p₀ z ∂volume) p₀ := + (hasDerivAt_integral_of_dominated_loc_of_deriv_le (F := fun p z ↦ h z * φ p z) + (F' := fun p z ↦ h z * φ' p z) (Metric.ball_mem_nhds p₀ hr) + (Filter.Eventually.of_forall fun p ↦ (hhc.mul (hφc p)).aestronglyMeasurable) + hpt (hhc.mul hφ'c).aestronglyMeasurable hb hbi + (ae_of_all _ fun z p hp ↦ (hderiv z p hp).const_mul (h z))).2 + +/-- **Differentiation under the integral for the Gaussian convolution.** For `t > 0` and `f` +continuous and bounded (`|f| ≤ Cf`), `φ(s) = ∫ f(y)·K(s, y) dy` is differentiable at `t` with +`φ′(t) = ∫ f(y)·∂_t K(t, y) dy`. The `s`-derivative `f(y)·K(s,y)·(y²−s)/(2s²)` is dominated, +uniformly over `s ∈ (t/2, 3t/2)`, by `Cf·(2√3/t²)·(y²+3t/2)·K(3t/2, y)` (integrable), using the +heat-kernel monotonicity `K(s, y) ≤ √3·K(3t/2, y)` on that interval. -/ +private lemma hasDerivAt_phi {t : ℝ} (ht : 0 < t) {f : ℝ → ℝ} (hfc : Continuous f) + {Cf : ℝ} (hCf : ∀ x, |f x| ≤ Cf) : + HasDerivAt (fun s ↦ ∫ y, f y * heatKernel s y ∂volume) + (∫ y, f y * (heatKernel t y * (y ^ 2 - t) / (2 * t ^ 2)) ∂volume) t := by + have h32 : (0 : ℝ) < 3 * t / 2 := by positivity + have hCf0 : 0 ≤ Cf := le_trans (abs_nonneg _) (hCf 0) + have hf_gauss : Integrable f (gaussianReal 0 t.toNNReal) := + (integrable_const Cf).mono' hfc.aestronglyMeasurable + (ae_of_all _ fun y ↦ by rw [Real.norm_eq_abs]; exact hCf y) + refine hasDerivAt_integral_mul_kernelFamily (φ := fun s y ↦ heatKernel s y) + (φ' := fun s y ↦ heatKernel s y * (y ^ 2 - s) / (2 * s ^ 2)) + (p₀ := t) (r := t / 2) hfc (by positivity) + (fun s ↦ continuous_heatKernel s) + (((continuous_heatKernel t).mul ((continuous_pow 2).sub continuous_const)).div_const _) + (integrable_mul_heatKernel_of_gaussian ht hf_gauss) + ((integrable_poly_heatKernel h32 (3 * t / 2)).const_mul (Cf * (2 * Real.sqrt 3 / t ^ 2))) + ?_ (fun y s hs ↦ ?_) + · -- uniform domination on `(t/2, 3t/2)`, via temporal monotonicity `heatKernel_temporal_le` + refine ae_of_all _ fun y s hs ↦ ?_ + rw [Metric.mem_ball, Real.dist_eq, abs_lt] at hs + have hs_lo : t / 2 < s := by linarith [hs.1] + have hs_hi : s < 3 * t / 2 := by linarith [hs.2] + have hs_pos : 0 < s := by linarith + have hKsnn : 0 ≤ heatKernel s y := heatKernel_nonneg hs_pos y + have hKtnn : 0 ≤ heatKernel (3 * t / 2) y := heatKernel_nonneg h32 y + have hK := heatKernel_temporal_le ht hs_lo hs_hi y + have hpoly := sq_sub_div_le ht hs_lo hs_hi y + have habs_nn : 0 ≤ |y ^ 2 - s| / (2 * s ^ 2) := by positivity + have hF'norm : ‖f y * (heatKernel s y * (y ^ 2 - s) / (2 * s ^ 2))‖ + = |f y| * (heatKernel s y * (|y ^ 2 - s| / (2 * s ^ 2))) := by + rw [Real.norm_eq_abs, abs_mul, abs_div, abs_mul, + abs_of_nonneg hKsnn, abs_of_nonneg (by positivity : (0:ℝ) ≤ 2 * s ^ 2), mul_div_assoc] + rw [hF'norm] + calc |f y| * (heatKernel s y * (|y ^ 2 - s| / (2 * s ^ 2))) + ≤ Cf * (Real.sqrt 3 * heatKernel (3 * t / 2) y * (2 * (y ^ 2 + 3 * t / 2) / t ^ 2)) := by + refine mul_le_mul (hCf y) ?_ (mul_nonneg hKsnn habs_nn) hCf0 + exact mul_le_mul hK hpoly habs_nn (mul_nonneg (Real.sqrt_nonneg 3) hKtnn) + _ = Cf * (2 * Real.sqrt 3 / t ^ 2) * ((y ^ 2 + 3 * t / 2) * heatKernel (3 * t / 2) y) := by + ring + · -- pointwise kernel `s`-derivative + rw [Metric.mem_ball, Real.dist_eq, abs_lt] at hs + exact hasDerivAt_heatKernel_t (y := y) (by linarith [hs.1]) + +/-- **The Gaussian convolution satisfies the heat equation.** For `f ∈ C²_b`, +`φ(s) = ∫ f(y)·K(s, y) dy` has `φ′(t) = ½·∫ f′′(y)·K(t, y) dy`. Combines the parametric derivative +`hasDerivAt_phi` (`φ′(t) = ∫ f·∂_t K`) with the kernel PDE `∂_t K = ½·∂²_y K` and the double +integration by parts `∫ f·∂²_y K = ∫ f′′·K` (`ibp_heatKernel`). This is the heat equation for the +*function* `φ`, not merely the kernel. -/ +private lemma hasDerivAt_phi_heatEq {t : ℝ} (ht : 0 < t) {f f' f'' : ℝ → ℝ} + (hf : ∀ x, HasDerivAt f (f' x) x) (hf' : ∀ x, HasDerivAt f' (f'' x) x) + (hf''c : Continuous f'') {Cf Cf' Cf'' : ℝ} + (hCf : ∀ x, |f x| ≤ Cf) (hCf' : ∀ x, |f' x| ≤ Cf') (hCf'' : ∀ x, |f'' x| ≤ Cf'') : + HasDerivAt (fun s ↦ ∫ y, f y * heatKernel s y ∂volume) + (1 / 2 * ∫ y, f'' y * heatKernel t y ∂volume) t := by + have hfc : Continuous f := continuous_iff_continuousAt.mpr fun x ↦ (hf x).continuousAt + convert hasDerivAt_phi ht hfc hCf using 1 + rw [← ibp_heatKernel ht hf hf' hf''c hCf hCf' hCf'', ← integral_const_mul] + refine integral_congr_ae (Filter.Eventually.of_forall fun y ↦ ?_) + ring + +/-- **The heat kernel is an approximate identity** (`ε → 0⁺`): for `f` continuous and bounded +(`|f| ≤ Cf`), `∫ f(y)·K(ε, y) dy → f(0)`. Proof by the rescaling `y = √ε·u`, which turns the +integral into `∫ f(√ε·u)·φ(u) du` against the *fixed* standard-normal density +`φ(u) = (2π)^{-1/2} e^{-u²/2}`, followed by dominated convergence (`f(√ε·u) → f(0)` pointwise, +dominated by the integrable `Cf·φ`). This supplies the `ε → 0` boundary value for the FTC. -/ +private lemma tendsto_integral_heatKernel_zero {f : ℝ → ℝ} (hfc : Continuous f) + {Cf : ℝ} (hCf : ∀ x, |f x| ≤ Cf) : + Tendsto (fun ε ↦ ∫ y, f y * heatKernel ε y ∂volume) (nhdsWithin 0 (Set.Ioi 0)) + (nhds (f 0)) := by + set g : ℝ → ℝ := fun u ↦ (Real.sqrt (2 * Real.pi))⁻¹ * Real.exp (-(1 / 2) * u ^ 2) with hg + have hgc : Continuous g := by rw [hg]; fun_prop + have hgnn : ∀ u, 0 ≤ g u := fun u ↦ by rw [hg]; positivity + have hg_int : Integrable g volume := + (integrable_exp_neg_mul_sq (by norm_num : (0:ℝ) < 1 / 2)).const_mul (Real.sqrt (2 * Real.pi))⁻¹ + have hg_int1 : ∫ u, g u ∂volume = 1 := by + simp only [hg] + rw [integral_const_mul, integral_gaussian, show Real.pi / (1 / 2) = 2 * Real.pi from by ring, + inv_mul_cancel₀ (by positivity : Real.sqrt (2 * Real.pi) ≠ 0)] + -- rescaling identity `φ(ε) = ∫ u, f(√ε·u)·g(u)` for ε > 0 + have hrw : ∀ ε : ℝ, 0 < ε → + (∫ y, f y * heatKernel ε y ∂volume) = ∫ u, f (Real.sqrt ε * u) * g u ∂volume := by + intro ε hε + have hsε : 0 < Real.sqrt ε := Real.sqrt_pos.mpr hε + have hεne : ε ≠ 0 := hε.ne' + have hscale : ∀ u, Real.sqrt ε * heatKernel ε (Real.sqrt ε * u) = g u := by + intro u + simp only [hg, heatKernel] + have hse2 : Real.sqrt ε ^ 2 = ε := Real.sq_sqrt hε.le + have hexp : -(Real.sqrt ε * u) ^ 2 / (2 * ε) = -(1 / 2) * u ^ 2 := by + rw [mul_pow, hse2]; field_simp + rw [hexp, Real.sqrt_mul (by positivity : (0:ℝ) ≤ 2 * Real.pi) ε, mul_inv] + field_simp + have hcomp := Measure.integral_comp_mul_left (fun y ↦ f y * heatKernel ε y) (Real.sqrt ε) + rw [abs_of_pos (by positivity : (0:ℝ) < (Real.sqrt ε)⁻¹), smul_eq_mul] at hcomp + have hkey : ∀ u, f (Real.sqrt ε * u) * g u + = Real.sqrt ε * (f (Real.sqrt ε * u) * heatKernel ε (Real.sqrt ε * u)) := by + intro u; rw [← hscale u]; ring + rw [integral_congr_ae (Filter.Eventually.of_forall hkey), integral_const_mul, hcomp, + ← mul_assoc, mul_inv_cancel₀ hsε.ne', one_mul] + -- dominated convergence on the rescaled integrand + have hlimeq : f 0 = ∫ u, f 0 * g u ∂volume := by rw [integral_const_mul, hg_int1, mul_one] + rw [hlimeq] + refine Tendsto.congr' (f₁ := fun ε ↦ ∫ u, f (Real.sqrt ε * u) * g u ∂volume) + (by filter_upwards [self_mem_nhdsWithin] with ε hε using (hrw ε hε).symm) ?_ + refine tendsto_integral_filter_of_dominated_convergence (fun u ↦ Cf * g u) ?_ ?_ + (hg_int.const_mul Cf) ?_ + · filter_upwards [self_mem_nhdsWithin] with ε _hε + exact ((hfc.comp (continuous_const.mul continuous_id)).mul hgc).aestronglyMeasurable + · filter_upwards [self_mem_nhdsWithin] with ε _hε + refine Filter.Eventually.of_forall fun u ↦ ?_ + rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (hgnn u)] + exact mul_le_mul_of_nonneg_right (hCf _) (hgnn u) + · refine Filter.Eventually.of_forall fun u ↦ ?_ + apply Tendsto.mul_const + have hsqrt0 : Tendsto Real.sqrt (nhdsWithin 0 (Set.Ioi 0)) (nhds 0) := by + have h := (Real.continuous_sqrt.tendsto 0).mono_left + (nhdsWithin_le_nhds (a := (0:ℝ)) (s := Set.Ioi 0)) + rwa [Real.sqrt_zero] at h + have h_inner : Tendsto (fun ε : ℝ ↦ Real.sqrt ε * u) (nhdsWithin 0 (Set.Ioi 0)) (nhds 0) := by + have := hsqrt0.mul_const u; rwa [zero_mul] at this + exact (hfc.tendsto 0).comp h_inner + +/-- The heat kernel integrates to `1` over `ℝ` (it is a probability density), for `s > 0`. -/ +private lemma integral_heatKernel_eq_one {s : ℝ} (hs : 0 < s) : + ∫ y, heatKernel s y ∂volume = 1 := by + rw [integral_congr_ae (Filter.Eventually.of_forall (heatKernel_eq_gaussianPDFReal hs))] + exact integral_gaussianPDFReal_eq_one 0 (Real.toNNReal_pos.mpr hs).ne' + +/-- Uniform bound on the time-derivative `φ′(s) = ½∫f′′·K(s,·)`: `|φ′(s)| ≤ ½·Cf′′` for `s > 0`. +Here `∫ K(s,·) = 1` and `|f′′| ≤ Cf′′`. This majorant makes `φ′` interval-integrable on `[0, t]`. -/ +private lemma abs_half_integral_ddf_heatKernel_le {s : ℝ} (hs : 0 < s) {f'' : ℝ → ℝ} + (_hf''c : Continuous f'') {Cf'' : ℝ} (hCf'' : ∀ x, |f'' x| ≤ Cf'') : + |(1 / 2) * ∫ y, f'' y * heatKernel s y ∂volume| ≤ (1 / 2) * Cf'' := by + rw [abs_mul, abs_of_nonneg (by norm_num : (0:ℝ) ≤ 1 / 2)] + refine mul_le_mul_of_nonneg_left ?_ (by norm_num : (0:ℝ) ≤ 1 / 2) + calc |∫ y, f'' y * heatKernel s y ∂volume| + ≤ ∫ y, |f'' y * heatKernel s y| ∂volume := abs_integral_le_integral_abs + _ ≤ ∫ y, Cf'' * heatKernel s y ∂volume := by + refine integral_mono_of_nonneg (Filter.Eventually.of_forall fun y ↦ abs_nonneg _) + ((integrable_heatKernel hs).const_mul Cf'') (Filter.Eventually.of_forall fun y ↦ ?_) + change |f'' y * heatKernel s y| ≤ Cf'' * heatKernel s y + rw [abs_mul, abs_of_nonneg (heatKernel_nonneg hs y)] + exact mul_le_mul_of_nonneg_right (hCf'' y) (heatKernel_nonneg hs y) + _ = Cf'' := by rw [integral_const_mul, integral_heatKernel_eq_one hs, mul_one] + +/-- **Itô's formula in expectation — analytic core (Feynman–Kac).** For `f ∈ C²_b` and `t > 0`, +`∫ f(y)·K(t,y) dy = f(0) + ∫₀ᵗ ½·(∫ f′′(y)·K(s,y) dy) ds`. The Gaussian convolution at time `t` +equals its `t→0` boundary value `f(0)` plus the integral of its time-derivative +`φ′(s) = ½∫f′′·K(s,·)`. Proof: the fundamental theorem of calculus for the continuous-corrected +`Φ` (value `φ(s)` for `s>0`, `f(0)` at `s=0`), whose right derivative on `(0,t)` is `φ′` +(`hasDerivAt_phi_heatEq`), whose boundary value is the approximate-identity limit +(`tendsto_integral_heatKernel_zero`), and whose derivative is interval-integrable (bounded by +`½Cf′′`). Under the standard Brownian hypotheses this reads `E[f(Bₜ)] = f(0) + ½∫₀ᵗ E[f′′(Bₛ)] ds` +via `feynmanU_eq_expectation`. -/ +theorem heatConvolution_eq_add_integral_deriv {t : ℝ} (ht : 0 < t) {f f' f'' : ℝ → ℝ} + (hf : ∀ x, HasDerivAt f (f' x) x) (hf' : ∀ x, HasDerivAt f' (f'' x) x) + (hf''c : Continuous f'') {Cf Cf' Cf'' : ℝ} + (hCf : ∀ x, |f x| ≤ Cf) (hCf' : ∀ x, |f' x| ≤ Cf') (hCf'' : ∀ x, |f'' x| ≤ Cf'') : + (∫ y, f y * heatKernel t y ∂volume) + = f 0 + ∫ s in (0:ℝ)..t, (1 / 2) * ∫ y, f'' y * heatKernel s y ∂volume := by + have hfc : Continuous f := continuous_iff_continuousAt.mpr fun x ↦ (hf x).continuousAt + set φ : ℝ → ℝ := fun s ↦ ∫ y, f y * heatKernel s y ∂volume with hφdef + set ψ : ℝ → ℝ := fun s ↦ (1 / 2) * ∫ y, f'' y * heatKernel s y ∂volume with hψdef + set Φ : ℝ → ℝ := fun s ↦ if 0 < s then φ s else f 0 with hΦdef + -- (a) `ψ = φ′` is interval-integrable on `[0, t]` (continuous on `(0,t]`, bounded by `½Cf′′`) + have hψ_cont : ∀ s : ℝ, 0 < s → ContinuousAt ψ s := fun s hs ↦ + (hasDerivAt_phi hs hf''c hCf'').continuousAt.const_mul (1 / 2) + have hψ_int : IntervalIntegrable ψ volume 0 t := by + rw [intervalIntegrable_iff_integrableOn_Ioc_of_le ht.le] + refine Integrable.mono' (g := fun _ : ℝ ↦ (1 / 2) * Cf'') + (integrableOn_const (hs := measure_Ioc_lt_top.ne)) + (ContinuousOn.aestronglyMeasurable (fun s hs ↦ (hψ_cont s hs.1).continuousWithinAt) + measurableSet_Ioc) + (ae_restrict_of_forall_mem measurableSet_Ioc fun s hs ↦ ?_) + change ‖(1 / 2) * ∫ y, f'' y * heatKernel s y ∂volume‖ ≤ (1 / 2) * Cf'' + rw [Real.norm_eq_abs] + exact abs_half_integral_ddf_heatKernel_le hs.1 hf''c hCf'' + -- (b) `Φ` is continuous on `[0, t]` + have hΦ_cont : ContinuousOn Φ (Set.Icc 0 t) := by + intro s hs + rcases eq_or_lt_of_le hs.1 with h0 | h0 + · rw [← h0, ContinuousWithinAt, show Φ 0 = f 0 from ite_eq_right (lt_irrefl 0), + show Set.Icc (0:ℝ) t = {0} ∪ Set.Ioc 0 t from by + rw [Set.union_comm, Set.Ioc_union_left ht.le], + nhdsWithin_union, nhdsWithin_singleton, tendsto_sup] + refine ⟨by rw [← show Φ 0 = f 0 from ite_eq_right (lt_irrefl 0)]; exact tendsto_pure_nhds Φ 0, + ?_⟩ + refine Filter.Tendsto.congr' ?_ ((tendsto_integral_heatKernel_zero hfc hCf).mono_left + (nhdsWithin_mono 0 Set.Ioc_subset_Ioi_self)) + filter_upwards [self_mem_nhdsWithin] with x hx using (ite_eq_left hx.1).symm + · have hca : ContinuousAt Φ s := by + refine (hasDerivAt_phi h0 hfc hCf).continuousAt.congr ?_ + filter_upwards [lt_mem_nhds h0] with x hx using (ite_eq_left hx).symm + exact hca.continuousWithinAt + -- (c) right derivative of `Φ` on `(0, t)` is `ψ` + have hΦ_deriv : ∀ s ∈ Set.Ioo (0:ℝ) t, HasDerivWithinAt Φ (ψ s) (Set.Ioi s) s := by + intro s hs + have heq : Φ =ᶠ[nhds s] φ := by + filter_upwards [lt_mem_nhds hs.1] with x hx using ite_eq_left hx + exact ((hasDerivAt_phi_heatEq hs.1 hf hf' hf''c hCf hCf' hCf'').congr_of_eventuallyEq + heq).hasDerivWithinAt + -- (d) FTC, then read off the boundary values `Φ t = φ t`, `Φ 0 = f 0` + have hFTC := + intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le ht.le hΦ_cont hΦ_deriv hψ_int + rw [show Φ t = φ t from ite_eq_left ht, show Φ 0 = f 0 from ite_eq_right (lt_irrefl 0)] at hFTC + linarith [hFTC] + +/-! ### The Feynman–Kac function `u(t, x) = ∫ z, g(z) · K(t, z - x) dz` + +We define `u` directly via the heat-kernel representation, then show it equals +the textbook formula `E[g(x + B_t)]` under the standard BM hypotheses. -/ + +/-- Feynman–Kac heat-kernel function: `u(t, x) = ∫ z, g(z) · K(t, z − x) dz`. +This form is symmetric to `∫ y, g(x + y) · K(t, y) dy` by Lebesgue translation +invariance, but is easier to differentiate in `x` (the `x`-dependence sits in +the kernel argument, not in `g`). -/ +noncomputable def feynmanU (g : ℝ → ℝ) (t x : ℝ) : ℝ := + ∫ z, g z * heatKernel t (z - x) ∂volume + +/-! ### Equivalence of forms: `∫ y, g(x+y) · K(t, y) dy = ∫ z, g(z) · K(t, z-x) dz` -/ + +/-- Lebesgue translation invariance: `∫ y, g(x+y) · K(t, y) dy = feynmanU g t x`. -/ +private lemma integral_shift_eq_feynmanU (g : ℝ → ℝ) (t x : ℝ) : + ∫ y, g (x + y) * heatKernel t y ∂volume = feynmanU g t x := by + rw [feynmanU] + have h_fun_eq : (fun z ↦ g z * heatKernel t (z - x)) + = (fun z ↦ g (x + (z - x)) * heatKernel t (z - x)) := by + funext z; congr 2; ring + rw [h_fun_eq] + exact (MeasureTheory.integral_sub_right_eq_self + (fun z ↦ g (x + z) * heatKernel t z) x).symm + +/-! ### Identification of `feynmanU` with `E[g(x + B_t)]` -/ + +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + +/-- **Core transfer.** If `B_t` has law `N(0, t)` +(`Measure.map (B t) μ = gaussianReal 0 t.toNNReal`), the heat-kernel form `feynmanU g t x` equals +the expectation `E[g(x + B_t)]`. Factored out of `feynmanU_eq_expectation` so the same transfer +serves both the increment-hypothesis bundle and the `IsPreBrownianReal` marginal law. -/ +theorem feynmanU_eq_integral_of_map + {B : ℝ → Ω → ℝ} {g : ℝ → ℝ} {t : ℝ} + (h_aem : AEMeasurable (B t) μ) + (h_map : Measure.map (B t) μ = gaussianReal 0 t.toNNReal) + (hg_cont : Continuous g) (ht : 0 < t) (x : ℝ) : + feynmanU g t x = ∫ ω, g (x + B t ω) ∂μ := by + have h_eg_cont : Continuous (fun y ↦ g (x + y)) := + hg_cont.comp (continuous_const.add continuous_id) + have h_eg_smeas_map : AEStronglyMeasurable (fun y ↦ g (x + y)) (Measure.map (B t) μ) := + h_eg_cont.aestronglyMeasurable + have h_expect_eq_gauss : + ∫ ω, g (x + B t ω) ∂μ = ∫ y, g (x + y) ∂(gaussianReal 0 t.toNNReal) := by + have h_map' : ∫ y, g (x + y) ∂(Measure.map (B t) μ) = ∫ ω, g (x + B t ω) ∂μ := + integral_map h_aem h_eg_smeas_map + rw [← h_map', h_map] + have h_tN_ne : (t.toNNReal : ℝ≥0) ≠ 0 := (Real.toNNReal_pos.mpr ht).ne' + have h_gauss_eq_pdf : + ∫ y, g (x + y) ∂(gaussianReal 0 t.toNNReal) = + ∫ y, gaussianPDFReal 0 t.toNNReal y • g (x + y) ∂volume := + integral_gaussianReal_eq_integral_smul (μ := 0) (v := t.toNNReal) + (f := fun y ↦ g (x + y)) h_tN_ne + have h_pdf_eq_heat : ∀ y, + gaussianPDFReal 0 t.toNNReal y • g (x + y) = g (x + y) * heatKernel t y := by + intro y + rw [← heatKernel_eq_gaussianPDFReal ht y, smul_eq_mul, mul_comm] + rw [h_expect_eq_gauss, h_gauss_eq_pdf, + show (fun y ↦ gaussianPDFReal 0 t.toNNReal y • g (x + y)) + = (fun y ↦ g (x + y) * heatKernel t y) from funext h_pdf_eq_heat] + exact (integral_shift_eq_feynmanU g t x).symm + +/-- For `t > 0`, the heat-kernel form `feynmanU g t x` equals the Feynman–Kac +expectation `E[g(x + B_t)]`, assuming: +* `B 0 = 0` a.s. +* `B_t − B_0 ∼ N(0, t)` (Gaussian increments at the origin), +* `B_t` is measurable, +* `g` is continuous. -/ +theorem feynmanU_eq_expectation + {B : ℝ → Ω → ℝ} {g : ℝ → ℝ} + (hB_meas : ∀ t, Measurable (B t)) + (hB_zero : ∀ᵐ ω ∂μ, B 0 ω = 0) + (hB_gauss : ∀ ⦃s t : ℝ⦄, s ≤ t → + ∃ v : NNReal, (v : ℝ) = t - s ∧ + Measure.map (fun ω ↦ B t ω - B s ω) μ = gaussianReal 0 v) + (hg_cont : Continuous g) + {t : ℝ} (ht : 0 < t) (x : ℝ) : + feynmanU g t x = ∫ ω, g (x + B t ω) ∂μ := by + -- Step 1: Use `B 0 = 0 a.s.` and `gauss_increments` at (0, t) to deduce + -- Measure.map (B t) μ = gaussianReal 0 t.toNNReal. + obtain ⟨v, hv_eq, h_map_diff⟩ := hB_gauss ht.le + have hv_eq_t : (v : ℝ) = t := by rw [hv_eq]; ring + have hv_t : v = t.toNNReal := by + apply NNReal.coe_inj.mp + rw [hv_eq_t, Real.coe_toNNReal _ ht.le] + have h_diff_eq : (fun ω ↦ B t ω - B 0 ω) =ᵐ[μ] (fun ω ↦ B t ω) := by + filter_upwards [hB_zero] with ω hω + rw [hω, sub_zero] + have h_map_Bt : Measure.map (B t) μ = gaussianReal 0 t.toNNReal := by + rw [← hv_t, ← h_map_diff] + exact (Measure.map_congr h_diff_eq).symm + -- Steps 2–5 are the core transfer, now factored out: + exact feynmanU_eq_integral_of_map (hB_meas t).aemeasurable h_map_Bt hg_cont ht x + +/-- The boundary condition: at `t = 0`, the Feynman-Kac expectation equals `g(x)` +(since `B 0 = 0` a.s. and `μ` is a probability measure). -/ +theorem feynmanKac_boundary [IsProbabilityMeasure μ] + {B : ℝ → Ω → ℝ} {g : ℝ → ℝ} + (hB_zero : ∀ᵐ ω ∂μ, B 0 ω = 0) (x : ℝ) : + ∫ ω, g (x + B 0 ω) ∂μ = g x := by + have h_pt : ∀ᵐ ω ∂μ, g (x + B 0 ω) = g x := by + filter_upwards [hB_zero] with ω hω + rw [hω, add_zero] + rw [integral_congr_ae h_pt, integral_const, probReal_univ, one_smul] + +/-- **Itô's formula in expectation** (Dynkin / Kolmogorov form). For a Brownian motion `B` +(`B 0 = 0` a.s., Gaussian increments `B_t − B_s ∼ N(0, t−s)`, each `B_t` measurable) and +`f ∈ C²_b`, `E[f(Bₜ)] = f(0) + ½·∫₀ᵗ E[f′′(Bₛ)] ds` for `t > 0`. This is the expectation form of +the analytic Feynman–Kac identity `heatConvolution_eq_add_integral_deriv`, transported across the +bridge `feynmanU_eq_expectation` (`∫ g·K(r,·) = E[g(B_r)]`). The `½ f′′` term is the signature of +the quadratic variation of Brownian motion — the source of the Itô correction. -/ +theorem expectation_ito + {B : ℝ → Ω → ℝ} + (hB_meas : ∀ t, Measurable (B t)) + (hB_zero : ∀ᵐ ω ∂μ, B 0 ω = 0) + (hB_gauss : ∀ ⦃s t : ℝ⦄, s ≤ t → + ∃ v : NNReal, (v : ℝ) = t - s ∧ + Measure.map (fun ω ↦ B t ω - B s ω) μ = gaussianReal 0 v) + {t : ℝ} (ht : 0 < t) {f f' f'' : ℝ → ℝ} + (hf : ∀ x, HasDerivAt f (f' x) x) (hf' : ∀ x, HasDerivAt f' (f'' x) x) + (hf''c : Continuous f'') {Cf Cf' Cf'' : ℝ} + (hCf : ∀ x, |f x| ≤ Cf) (hCf' : ∀ x, |f' x| ≤ Cf') (hCf'' : ∀ x, |f'' x| ≤ Cf'') : + (∫ ω, f (B t ω) ∂μ) = f 0 + ∫ s in (0:ℝ)..t, (1 / 2) * ∫ ω, f'' (B s ω) ∂μ := by + have hfc : Continuous f := continuous_iff_continuousAt.mpr fun x ↦ (hf x).continuousAt + -- the heat-kernel ↔ expectation bridge, for any continuous `g` and time `r > 0` + have hbridge : ∀ (g : ℝ → ℝ), Continuous g → ∀ {r : ℝ}, 0 < r → + (∫ y, g y * heatKernel r y ∂volume) = ∫ ω, g (B r ω) ∂μ := by + intro g hgc r hr + have h1 := integral_shift_eq_feynmanU g r 0 + simp only [zero_add] at h1 + rw [h1, feynmanU_eq_expectation hB_meas hB_zero hB_gauss hgc hr 0] + simp only [zero_add] + rw [← hbridge f hfc ht, heatConvolution_eq_add_integral_deriv ht hf hf' hf''c hCf hCf' hCf''] + congr 1 + refine intervalIntegral.integral_congr_ae (ae_of_all _ fun s hs ↦ ?_) + rw [Set.uIoc_of_le ht.le] at hs + show (1 / 2) * ∫ y, f'' y * heatKernel s y ∂volume = (1 / 2) * ∫ ω, f'' (B s ω) ∂μ + rw [hbridge f'' hf''c hs.1] + +/-- **Itô's formula in expectation for a pre-Brownian motion** — the repo-standard +`IsPreBrownianReal` (Degenne) reading of `expectation_ito`. For `f ∈ C²_b` and `t > 0`, +`E[f(X_t)] = f(0) + ½·∫₀ᵗ E[f′′(X_s)] ds`. The increment-law hypotheses are discharged from the +marginal law `IsPreBrownianReal.hasLaw_eval` through the shared transfer +`feynmanU_eq_integral_of_map`. (`X` is `ℝ≥0`-indexed; the `∫₀ᵗ` runs over real `s`, so `X` is read +at `·.toNNReal`.) -/ +theorem expectation_ito_isPreBrownian {X : ℝ≥0 → Ω → ℝ} (hX : IsPreBrownianReal X μ) + {t : ℝ} (ht : 0 < t) {f f' f'' : ℝ → ℝ} + (hf : ∀ x, HasDerivAt f (f' x) x) (hf' : ∀ x, HasDerivAt f' (f'' x) x) + (hf''c : Continuous f'') {Cf Cf' Cf'' : ℝ} + (hCf : ∀ x, |f x| ≤ Cf) (hCf' : ∀ x, |f' x| ≤ Cf') (hCf'' : ∀ x, |f'' x| ≤ Cf'') : + (∫ ω, f (X t.toNNReal ω) ∂μ) + = f 0 + ∫ s in (0:ℝ)..t, (1 / 2) * ∫ ω, f'' (X s.toNNReal ω) ∂μ := by + have hfc : Continuous f := continuous_iff_continuousAt.mpr fun x ↦ (hf x).continuousAt + have hbridge : ∀ (g : ℝ → ℝ), Continuous g → ∀ {r : ℝ}, 0 < r → + (∫ y, g y * heatKernel r y ∂volume) = ∫ ω, g (X r.toNNReal ω) ∂μ := by + intro g hgc r hr + have h1 := integral_shift_eq_feynmanU g r 0 + simp only [zero_add] at h1 + rw [h1, feynmanU_eq_integral_of_map (B := fun s ↦ X s.toNNReal) (t := r) + (hX.aemeasurable r.toNNReal) + (hX.hasLaw_eval r.toNNReal).map_eq hgc hr 0] + simp only [zero_add] + rw [← hbridge f hfc ht, heatConvolution_eq_add_integral_deriv ht hf hf' hf''c hCf hCf' hCf''] + congr 1 + refine intervalIntegral.integral_congr_ae (ae_of_all _ fun s hs ↦ ?_) + rw [Set.uIoc_of_le ht.le] at hs + show (1 / 2) * ∫ y, f'' y * heatKernel s y ∂volume = (1 / 2) * ∫ ω, f'' (X s.toNNReal ω) ∂μ + rw [hbridge f'' hf''c hs.1] + +/-! ### Kernel-side heat equation for `feynmanU` (sub-Gaussian payoff) + +For `h` continuous with `|h z| ≤ eᶻ` (the call payoff `(eᶻ − K)⁺ ≤ eᶻ` qualifies) and `t > 0`, +`u(t, x) = feynmanU h t x` is twice differentiable in `x`, differentiable in `t`, and satisfies the +heat equation `∂_t u = ½ ∂_xx u`. Every derivative falls on the smooth, fast-decaying *kernel*; `h` +needs no regularity beyond the growth bound. The three diff-under-integral lemmas mirror +`hasDerivAt_phi`, replacing its bounded `|f| ≤ Cf` by the sub-Gaussian envelope +`integrable_exp_mul_poly_heatKernel` and (for the `x`-derivatives) its temporal monotonicity by the +spatial `heatKernel_shift_le`. This kernel-side heat equation for `u` (`feynmanU_heat_equation`, +with the derivatives below) is consumed by the Black–Scholes-PDE keystone `sc-bs-pde-feynman-kac`. +-/ + +/-- **Time-derivative of the Feynman–Kac function** (kernel-side, sub-Gaussian payoff). For `h` +continuous with `|h z| ≤ eᶻ` and `t > 0`, +`∂_t (feynmanU h t x) = ∫ z, h z · K(t, z−x)·((z−x)²−t)/(2t²) dz`. The sub-Gaussian analogue of +`hasDerivAt_phi`: the `s`-derivative is dominated, uniformly over `s ∈ (t/2, 3t/2)`, by the +integrable envelope `(2√3/t²)·eᶻ·((z−x)²+3t/2)·K(3t/2, z−x)`, via the temporal monotonicity +`K(s, w) ≤ √3·K(3t/2, w)`. Differentiating the kernel (not the payoff) is what frees `h` of any +regularity beyond exponential growth — the call payoff's kink is irrelevant. -/ +theorem hasDerivAt_feynmanU_t {t : ℝ} (ht : 0 < t) {h : ℝ → ℝ} (hhc : Continuous h) + (hh : ∀ z, |h z| ≤ Real.exp z) (x : ℝ) : + HasDerivAt (fun s ↦ feynmanU h s x) + (∫ z, h z * (heatKernel t (z - x) * ((z - x) ^ 2 - t) / (2 * t ^ 2)) ∂volume) t := by + change HasDerivAt (fun s ↦ ∫ z, h z * heatKernel s (z - x) ∂volume) + (∫ z, h z * (heatKernel t (z - x) * ((z - x) ^ 2 - t) / (2 * t ^ 2)) ∂volume) t + have h32 : (0 : ℝ) < 3 * t / 2 := by positivity + refine hasDerivAt_integral_mul_kernelFamily (φ := fun s z ↦ heatKernel s (z - x)) + (φ' := fun s z ↦ heatKernel s (z - x) * ((z - x) ^ 2 - s) / (2 * s ^ 2)) + (p₀ := t) (r := t / 2) hhc (by positivity) + (fun s ↦ (continuous_heatKernel s).comp (continuous_id.sub continuous_const)) + (((continuous_heatKernel t).comp (continuous_id.sub continuous_const)).mul + (((continuous_id.sub continuous_const).pow 2).sub continuous_const) |>.div_const _) + (integrable_payoff_mul_heatKernel ht hhc hh x) + ((integrable_exp_mul_poly_heatKernel h32 x (3 * t / 2)).const_mul (2 * Real.sqrt 3 / t ^ 2)) + ?_ (fun z s hs ↦ ?_) + · -- uniform domination on `(t/2, 3t/2)`, via temporal monotonicity `heatKernel_temporal_le` + refine ae_of_all _ fun z s hs ↦ ?_ + rw [Metric.mem_ball, Real.dist_eq, abs_lt] at hs + have hs_lo : t / 2 < s := by linarith [hs.1] + have hs_hi : s < 3 * t / 2 := by linarith [hs.2] + have hs_pos : 0 < s := by linarith + have hKsnn : 0 ≤ heatKernel s (z - x) := heatKernel_nonneg hs_pos (z - x) + have hKtnn : 0 ≤ heatKernel (3 * t / 2) (z - x) := heatKernel_nonneg h32 (z - x) + have hK := heatKernel_temporal_le ht hs_lo hs_hi (z - x) + have hpoly := sq_sub_div_le ht hs_lo hs_hi (z - x) + have habs_nn : 0 ≤ |(z - x) ^ 2 - s| / (2 * s ^ 2) := by positivity + have hF'norm : ‖h z * (heatKernel s (z - x) * ((z - x) ^ 2 - s) / (2 * s ^ 2))‖ + = |h z| * (heatKernel s (z - x) * (|(z - x) ^ 2 - s| / (2 * s ^ 2))) := by + rw [Real.norm_eq_abs, abs_mul, abs_div, abs_mul, + abs_of_nonneg hKsnn, abs_of_nonneg (by positivity : (0:ℝ) ≤ 2 * s ^ 2), mul_div_assoc] + rw [hF'norm] + calc |h z| * (heatKernel s (z - x) * (|(z - x) ^ 2 - s| / (2 * s ^ 2))) + ≤ Real.exp z + * (Real.sqrt 3 * heatKernel (3 * t / 2) (z - x) + * (2 * ((z - x) ^ 2 + 3 * t / 2) / t ^ 2)) := by + refine mul_le_mul (hh z) ?_ (mul_nonneg hKsnn habs_nn) (Real.exp_nonneg z) + exact mul_le_mul hK hpoly habs_nn (mul_nonneg (Real.sqrt_nonneg 3) hKtnn) + _ = (2 * Real.sqrt 3 / t ^ 2) + * (Real.exp z * (((z - x) ^ 2 + 3 * t / 2) * heatKernel (3 * t / 2) (z - x))) := by + ring + · -- pointwise kernel `s`-derivative + rw [Metric.mem_ball, Real.dist_eq, abs_lt] at hs + exact hasDerivAt_heatKernel_t (y := z - x) (by linarith [hs.1]) + +/-- **Space-derivative of the Feynman–Kac function** (kernel-side, sub-Gaussian payoff). For `h` +continuous with `|h z| ≤ eᶻ` and `t > 0`, +`∂_x (feynmanU h t x) = ∫ z, h z · ((z−x)/t)·K(t, z−x) dz`. Differentiating the shifted kernel in +`x` via `hasDerivAt_heatKernel_x`; dominated, uniformly over `x' ∈ ball x 1`, by the integrable +envelope `(√2·e^{1/2t}/t)·eᶻ·((z−x)²+2)·K(2t, z−x)` (`integrable_exp_mul_poly_heatKernel` at σ=2t), +via the spatial monotonicity `heatKernel_shift_le`. -/ +theorem hasDerivAt_feynmanU_x {t : ℝ} (ht : 0 < t) {h : ℝ → ℝ} (hhc : Continuous h) + (hh : ∀ z, |h z| ≤ Real.exp z) (x : ℝ) : + HasDerivAt (fun x' ↦ feynmanU h t x') + (∫ z, h z * ((z - x) / t * heatKernel t (z - x)) ∂volume) x := by + change HasDerivAt (fun x' ↦ ∫ z, h z * heatKernel t (z - x') ∂volume) + (∫ z, h z * ((z - x) / t * heatKernel t (z - x)) ∂volume) x + have h2t : (0 : ℝ) < 2 * t := by positivity + refine hasDerivAt_integral_mul_kernelFamily (φ := fun x' z ↦ heatKernel t (z - x')) + (φ' := fun x' z ↦ (z - x') / t * heatKernel t (z - x')) + (p₀ := x) (r := 1) hhc (by norm_num) + (fun c ↦ (continuous_heatKernel t).comp (continuous_id.sub continuous_const)) + (((continuous_id.sub continuous_const).div_const t).mul + ((continuous_heatKernel t).comp (continuous_id.sub continuous_const))) + (integrable_payoff_mul_heatKernel ht hhc hh x) + ((integrable_exp_mul_poly_heatKernel h2t x 2).const_mul + (Real.sqrt 2 * Real.exp (1 / (2 * t)) / t)) + ?_ (fun z x' _ ↦ hasDerivAt_heatKernel_x ht z x') + · -- uniform domination on `ball x 1`, via spatial monotonicity `heatKernel_shift_le` + refine ae_of_all _ fun z x' hx' ↦ ?_ + rw [Metric.mem_ball, Real.dist_eq] at hx' + have hKsnn : 0 ≤ heatKernel t (z - x') := heatKernel_nonneg ht (z - x') + have hKshift : heatKernel t (z - x') + ≤ Real.sqrt 2 * Real.exp (1 / (2 * t)) * heatKernel (2 * t) (z - x) := by + simpa [one_pow] using heatKernel_shift_le ht hx' z + have habs2 : |z - x'| ≤ (z - x) ^ 2 + 2 := by + have htri : |z - x'| ≤ |z - x| + |x - x'| := by + have hsplit : z - x' = (z - x) + (x - x') := by ring + rw [hsplit]; exact abs_add_le _ _ + have hxx : |x - x'| ≤ 1 := by rw [abs_sub_comm]; linarith [hx'] + have hsq : |z - x| ≤ (z - x) ^ 2 + 1 := by + nlinarith [sq_nonneg (|z - x| - 1), sq_abs (z - x), abs_nonneg (z - x)] + linarith + have hF'norm : ‖h z * ((z - x') / t * heatKernel t (z - x'))‖ + = 1 / t * (|h z| * (|z - x'| * heatKernel t (z - x'))) := by + rw [Real.norm_eq_abs, abs_mul, abs_mul, abs_div, abs_of_nonneg hKsnn, abs_of_nonneg ht.le] + ring + rw [hF'norm] + have hstep : |h z| * (|z - x'| * heatKernel t (z - x')) + ≤ Real.exp z + * (((z - x) ^ 2 + 2) + * (Real.sqrt 2 * Real.exp (1 / (2 * t)) * heatKernel (2 * t) (z - x))) := by + refine mul_le_mul (hh z) ?_ (mul_nonneg (abs_nonneg _) hKsnn) (Real.exp_nonneg z) + exact mul_le_mul habs2 hKshift hKsnn (by positivity) + calc 1 / t * (|h z| * (|z - x'| * heatKernel t (z - x'))) + ≤ 1 / t + * (Real.exp z + * (((z - x) ^ 2 + 2) + * (Real.sqrt 2 * Real.exp (1 / (2 * t)) * heatKernel (2 * t) (z - x)))) := + mul_le_mul_of_nonneg_left hstep (by positivity) + _ = (Real.sqrt 2 * Real.exp (1 / (2 * t)) / t) + * (Real.exp z * (((z - x) ^ 2 + 2) * heatKernel (2 * t) (z - x))) := by ring + +/-- **Second space-derivative of the Feynman–Kac function**. The derivative of the first-space- +derivative integral is `∫ z, h z · K(t, z−x)·((z−x)²−t)/t² dz`. Same template, now differentiating +`hasDerivAt_heatKernel_x_x`; dominated over `x' ∈ ball x 1` by the envelope at `σ=2t, d=3+t` +(using `|(z−x')²−t| ≤ 3((z−x)²+(3+t))`). -/ +theorem hasDerivAt_feynmanU_xx {t : ℝ} (ht : 0 < t) {h : ℝ → ℝ} (hhc : Continuous h) + (hh : ∀ z, |h z| ≤ Real.exp z) (x : ℝ) : + HasDerivAt (fun x' ↦ ∫ z, h z * ((z - x') / t * heatKernel t (z - x')) ∂volume) + (∫ z, h z * (heatKernel t (z - x) * ((z - x) ^ 2 - t) / t ^ 2) ∂volume) x := by + have h2t : (0 : ℝ) < 2 * t := by positivity + refine hasDerivAt_integral_mul_kernelFamily + (φ := fun x' z ↦ (z - x') / t * heatKernel t (z - x')) + (φ' := fun x' z ↦ heatKernel t (z - x') * ((z - x') ^ 2 - t) / t ^ 2) + (p₀ := x) (r := 1) hhc (by norm_num) + (fun c ↦ ((continuous_id.sub continuous_const).div_const t).mul + ((continuous_heatKernel t).comp (continuous_id.sub continuous_const))) + (((continuous_heatKernel t).comp (continuous_id.sub continuous_const)).mul + (((continuous_id.sub continuous_const).pow 2).sub continuous_const) |>.div_const _) + ?_ + ((integrable_exp_mul_poly_heatKernel h2t x (3 + t)).const_mul + (3 * Real.sqrt 2 * Real.exp (1 / (2 * t)) / t ^ 2)) + ?_ (fun z x' _ ↦ hasDerivAt_heatKernel_x_x ht z x') + · -- the first-derivative integrand is integrable at the base point + apply ((integrable_exp_mul_poly_heatKernel ht x 1).const_mul (1 / t)).mono' + · exact (hhc.mul (((continuous_id.sub continuous_const).div_const t).mul + ((continuous_heatKernel t).comp (continuous_id.sub continuous_const)))).aestronglyMeasurable + · refine ae_of_all _ fun z ↦ ?_ + have hKnn := heatKernel_nonneg ht (z - x) + have hnorm : ‖h z * ((z - x) / t * heatKernel t (z - x))‖ + = 1 / t * (|h z| * (|z - x| * heatKernel t (z - x))) := by + rw [Real.norm_eq_abs, abs_mul, abs_mul, abs_div, abs_of_nonneg hKnn, + abs_of_nonneg ht.le]; ring + rw [hnorm] + have habs1 : |z - x| ≤ (z - x) ^ 2 + 1 := by + nlinarith [sq_nonneg (|z - x| - 1), sq_abs (z - x), abs_nonneg (z - x)] + apply mul_le_mul_of_nonneg_left _ (by positivity : (0:ℝ) ≤ 1 / t) + refine mul_le_mul (hh z) ?_ (mul_nonneg (abs_nonneg _) hKnn) (Real.exp_nonneg z) + exact mul_le_mul_of_nonneg_right habs1 hKnn + · -- uniform domination on `ball x 1`, via spatial monotonicity `heatKernel_shift_le` + refine ae_of_all _ fun z x' hx' ↦ ?_ + rw [Metric.mem_ball, Real.dist_eq] at hx' + have hKsnn : 0 ≤ heatKernel t (z - x') := heatKernel_nonneg ht (z - x') + have hKshift : heatKernel t (z - x') + ≤ Real.sqrt 2 * Real.exp (1 / (2 * t)) * heatKernel (2 * t) (z - x) := by + simpa [one_pow] using heatKernel_shift_le ht hx' z + have hb : (x - x') ^ 2 ≤ 1 := by + have hxx : |x - x'| ≤ 1 := by rw [abs_sub_comm]; linarith [hx'] + nlinarith [sq_abs (x - x'), hxx, abs_nonneg (x - x')] + have habs2 : |(z - x') ^ 2 - t| ≤ 3 * ((z - x) ^ 2 + (3 + t)) := by + rw [abs_le] + refine ⟨?_, ?_⟩ + · nlinarith + [sq_nonneg (z - x), sq_nonneg (z - 2 * x + x'), sq_nonneg (2 * (z - x) + (x - x')), + hb, ht.le, sq_nonneg (z - x')] + · nlinarith + [sq_nonneg (z - x), sq_nonneg (z - 2 * x + x'), sq_nonneg (2 * (z - x) + (x - x')), + hb, ht.le, sq_nonneg (z - x')] + have hF'norm : ‖h z * (heatKernel t (z - x') * ((z - x') ^ 2 - t) / t ^ 2)‖ + = 1 / t ^ 2 * (|h z| * (heatKernel t (z - x') * |(z - x') ^ 2 - t|)) := by + rw [Real.norm_eq_abs, abs_mul, abs_div, abs_mul, abs_of_nonneg hKsnn, + abs_of_nonneg (by positivity : (0:ℝ) ≤ t ^ 2)] + ring + rw [hF'norm] + have hstep : |h z| * (heatKernel t (z - x') * |(z - x') ^ 2 - t|) + ≤ Real.exp z + * ((Real.sqrt 2 * Real.exp (1 / (2 * t)) * heatKernel (2 * t) (z - x)) + * (3 * ((z - x) ^ 2 + (3 + t)))) := by + refine mul_le_mul (hh z) ?_ (mul_nonneg hKsnn (abs_nonneg _)) (Real.exp_nonneg z) + exact mul_le_mul hKshift habs2 (abs_nonneg _) + (mul_nonneg (mul_nonneg (Real.sqrt_nonneg 2) (Real.exp_nonneg _)) + (heatKernel_nonneg h2t (z - x))) + calc 1 / t ^ 2 * (|h z| * (heatKernel t (z - x') * |(z - x') ^ 2 - t|)) + ≤ 1 / t ^ 2 + * (Real.exp z + * ((Real.sqrt 2 * Real.exp (1 / (2 * t)) * heatKernel (2 * t) (z - x)) + * (3 * ((z - x) ^ 2 + (3 + t))))) := + mul_le_mul_of_nonneg_left hstep (by positivity) + _ = (3 * Real.sqrt 2 * Real.exp (1 / (2 * t)) / t ^ 2) + * (Real.exp z * (((z - x) ^ 2 + (3 + t)) * heatKernel (2 * t) (z - x))) := by ring + +/-- **Derivative of the Feynman–Kac function along an affine curve** `s ↦ (α s, x₀ + β s)` +(kernel-side, sub-Gaussian payoff). For `h` continuous with `|h z| ≤ eᶻ`, `α > 0`, `τ > 0`, the +price `s ↦ feynmanU h (α s) (x₀ + β s)` — with both kernel arguments moving — is differentiable at +`τ` with `d/ds = ∫ z, h z · (α·∂_t K + β·∂_x K)`. This is the Black–Scholes `τ`-derivative engine +(`α = σ²`, `β = r − σ²/2`, `x₀ = log S`) and the consumer that makes the heat kernel's joint +differentiability `hasFDerivAt_heatKernel` load-bearing for pricing. Pointwise derivative: +`hasDerivAt_heatKernel_comp`. The uniform domination on `s ∈ (τ/2, 3τ/2)` bounds the two terms +*separately* by Gaussian-moment envelopes (`integrable_exp_mul_poly_heatKernel`) via +`heatKernel_loc_le` + `curve_sq_ratio_le` / `curve_abs_ratio_le` — no single mega-constant — fed to +`hasDerivAt_integral_mul_kernelFamily`. -/ +theorem hasDerivAt_feynmanU_comp {h : ℝ → ℝ} (hhc : Continuous h) (hh : ∀ z, |h z| ≤ Real.exp z) + {α β x₀ τ : ℝ} (hα : 0 < α) (hτ : 0 < τ) : + HasDerivAt (fun s ↦ feynmanU h (α * s) (x₀ + β * s)) + (∫ z, h z * (α * (heatKernel (α * τ) (z - (x₀ + β * τ)) + * ((z - (x₀ + β * τ)) ^ 2 - α * τ) / (2 * (α * τ) ^ 2)) + + β * ((z - (x₀ + β * τ)) / (α * τ) + * heatKernel (α * τ) (z - (x₀ + β * τ)))) ∂volume) τ := by + change HasDerivAt (fun s ↦ ∫ z, h z * heatKernel (α * s) (z - (x₀ + β * s)) ∂volume) _ τ + have hατ : (0 : ℝ) < α * τ := by positivity + have h3ατ : (0 : ℝ) < 3 * (α * τ) := by positivity + have hd_nn : (0 : ℝ) ≤ |β| * (τ / 2) := by positivity + set Cexp : ℝ := + Real.sqrt 3 * (Real.sqrt 2 * Real.exp ((|β| * (τ / 2) + 1) ^ 2 / (3 * (α * τ)))) with hCexp + have hCexp_nn : 0 ≤ Cexp := by rw [hCexp]; positivity + refine hasDerivAt_integral_mul_kernelFamily + (φ := fun s z ↦ heatKernel (α * s) (z - (x₀ + β * s))) + (φ' := fun s z ↦ α * (heatKernel (α * s) (z - (x₀ + β * s)) + * ((z - (x₀ + β * s)) ^ 2 - α * s) / (2 * (α * s) ^ 2)) + + β * ((z - (x₀ + β * s)) / (α * s) * heatKernel (α * s) (z - (x₀ + β * s)))) + (p₀ := τ) (r := τ / 2) hhc (by positivity) + (fun s ↦ (continuous_heatKernel (α * s)).comp (continuous_id.sub continuous_const)) + ((((((continuous_heatKernel (α * τ)).comp (continuous_id.sub continuous_const)).mul + (((continuous_id.sub continuous_const).pow 2).sub continuous_const)).div_const + _).const_mul α).add + ((((continuous_id.sub continuous_const).div_const _).mul + ((continuous_heatKernel (α * τ)).comp (continuous_id.sub continuous_const))).const_mul β)) + (integrable_payoff_mul_heatKernel hατ hhc hh (x₀ + β * τ)) + (((integrable_exp_mul_poly_heatKernel h3ατ (x₀ + β * τ) + ((|β| * (τ / 2)) ^ 2 + 3 * (α * τ) / 4)).const_mul (4 * α * Cexp / (α * τ) ^ 2)).add + ((integrable_exp_mul_poly_heatKernel h3ατ (x₀ + β * τ) + (1 + |β| * (τ / 2))).const_mul (2 * |β| * Cexp / (α * τ)))) + ?_ ?_ + · -- uniform domination: bound the two terms separately by Gaussian-moment envelopes + refine ae_of_all _ fun z s hs ↦ ?_ + rw [Metric.mem_ball, Real.dist_eq, abs_lt] at hs + have hs_pos : 0 < s := by linarith [hs.1] + have hvpos : 0 < α * s := by positivity + have hvlo : α * τ / 2 < α * s := by nlinarith [mul_pos hα (show (0:ℝ) < s - τ / 2 by linarith)] + have hvhi : α * s < 3 * (α * τ) / 2 := by + nlinarith [mul_pos hα (show (0:ℝ) < 3 * τ / 2 - s by linarith)] + set W : ℝ := z - (x₀ + β * s) with hW + set W₀ : ℝ := z - (x₀ + β * τ) with hW₀ + have hKnn : 0 ≤ heatKernel (α * s) W := heatKernel_nonneg hvpos _ + have hK0nn : 0 ≤ heatKernel (3 * (α * τ)) W₀ := heatKernel_nonneg h3ατ _ + have hWd : |W - W₀| ≤ |β| * (τ / 2) := by + rw [hW, hW₀, show z - (x₀ + β * s) - (z - (x₀ + β * τ)) = β * (τ - s) from by ring, abs_mul] + have : |τ - s| ≤ τ / 2 := by rw [abs_le]; constructor <;> linarith + exact mul_le_mul_of_nonneg_left this (abs_nonneg β) + have hcenter : |(x₀ + β * s) - (x₀ + β * τ)| < |β| * (τ / 2) + 1 := by + rw [show x₀ + β * s - (x₀ + β * τ) = β * (s - τ) from by ring, abs_mul] + have : |s - τ| < τ / 2 := by rw [abs_lt]; constructor <;> linarith + nlinarith [mul_le_mul_of_nonneg_left this.le (abs_nonneg β), abs_nonneg β] + have hk : heatKernel (α * s) W ≤ Cexp * heatKernel (3 * (α * τ)) W₀ := by + have := heatKernel_loc_le (v₀ := α * τ) (v := α * s) (x := x₀ + β * s) (x₀ := x₀ + β * τ) + (δ := |β| * (τ / 2) + 1) hατ hvlo hvhi hcenter z + rwa [← hW, ← hW₀, ← hCexp] at this + have hrt := curve_sq_ratio_le (v₀ := α * τ) (v := α * s) (W := W) (W₀ := W₀) + (d := |β| * (τ / 2)) hατ hvlo hvhi hWd hd_nn + have hrx := curve_abs_ratio_le (v₀ := α * τ) (v := α * s) (W := W) (W₀ := W₀) + (d := |β| * (τ / 2)) hατ hvlo hWd hd_nn + -- |φ'| ≤ the two nonneg envelope-ready terms + have e1 : |α * (heatKernel (α * s) W * (W ^ 2 - α * s) / (2 * (α * s) ^ 2))| + = α * (heatKernel (α * s) W * (|W ^ 2 - α * s| / (2 * (α * s) ^ 2))) := by + rw [abs_mul, abs_of_nonneg hα.le, abs_div, abs_mul, abs_of_nonneg hKnn, + abs_of_nonneg (by positivity : (0:ℝ) ≤ 2 * (α * s) ^ 2), mul_div_assoc] + have e2 : |β * (W / (α * s) * heatKernel (α * s) W)| + = |β| * (|W| / (α * s) * heatKernel (α * s) W) := by + rw [abs_mul, abs_mul, abs_div, abs_of_nonneg hvpos.le, abs_of_nonneg hKnn] + rw [Real.norm_eq_abs, abs_mul] + refine (mul_le_mul (hh z) ((abs_add_le _ _).trans_eq (by rw [e1, e2])) + (abs_nonneg _) (Real.exp_nonneg z)).trans ?_ + rw [mul_add] + simp only [Pi.add_apply, ← hW₀] + have hr_t_nn : (0:ℝ) ≤ |W ^ 2 - α * s| / (2 * (α * s) ^ 2) := by positivity + refine add_le_add ?_ ?_ + · -- α-term ≤ first envelope + calc Real.exp z * (α * (heatKernel (α * s) W * (|W ^ 2 - α * s| / (2 * (α * s) ^ 2)))) + ≤ Real.exp z * (α * ((Cexp * heatKernel (3 * (α * τ)) W₀) + * (2 * (2 * W₀ ^ 2 + 2 * (|β| * (τ / 2)) ^ 2 + 3 * (α * τ) / 2) / (α * τ) ^ 2))) := + mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left + (mul_le_mul hk hrt hr_t_nn (mul_nonneg hCexp_nn hK0nn)) hα.le) + (Real.exp_nonneg z) + _ = 4 * α * Cexp / (α * τ) ^ 2 + * (Real.exp z * ((W₀ ^ 2 + ((|β| * (τ / 2)) ^ 2 + 3 * (α * τ) / 4)) + * heatKernel (3 * (α * τ)) W₀)) := by ring + · -- β-term ≤ second envelope + calc Real.exp z * (|β| * (|W| / (α * s) * heatKernel (α * s) W)) + ≤ Real.exp z * (|β| * (2 * (W₀ ^ 2 + 1 + |β| * (τ / 2)) / (α * τ) + * (Cexp * heatKernel (3 * (α * τ)) W₀))) := + mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left + (mul_le_mul hrx hk hKnn (by positivity)) (abs_nonneg β)) + (Real.exp_nonneg z) + _ = 2 * |β| * Cexp / (α * τ) + * (Real.exp z * ((W₀ ^ 2 + (1 + |β| * (τ / 2))) + * heatKernel (3 * (α * τ)) W₀)) := by ring + · -- pointwise curve derivative + refine fun z s hs ↦ ?_ + rw [Metric.mem_ball, Real.dist_eq, abs_lt] at hs + have hs_pos : 0 < s := by linarith [hs.1] + exact hasDerivAt_heatKernel_comp (v := fun s ↦ α * s) (w := fun s ↦ x₀ + β * s) + (by simpa using (hasDerivAt_id s).const_mul α) + (by simpa using ((hasDerivAt_id s).const_mul β).const_add x₀) (by positivity) z + +/-- **The Feynman–Kac function solves the heat equation** `∂_t u = ½ ∂_xx u` (the derivative +*values*). Pointwise on the kernel: `K·((z−x)²−t)/(2t²) = ½·K·((z−x)²−t)/t²`. Combined with +`hasDerivAt_feynmanU_t` (`∂_t u = ∫ h·K·((z−x)²−t)/(2t²)`) and `hasDerivAt_feynmanU_xx` +(`∂_xx u = ∫ h·K·((z−x)²−t)/t²`) this is the heat equation for `u = feynmanU h`. Consumed by the +Black–Scholes-PDE keystone `bsV_satisfies_bs_pde_via_feynmanKac` (`sc-bs-pde-feynman-kac`). -/ +theorem feynmanU_heat_equation {t : ℝ} (ht : 0 < t) (h : ℝ → ℝ) (x : ℝ) : + (∫ z, h z * (heatKernel t (z - x) * ((z - x) ^ 2 - t) / (2 * t ^ 2)) ∂volume) + = (1 / 2) * ∫ z, h z * (heatKernel t (z - x) * ((z - x) ^ 2 - t) / t ^ 2) ∂volume := by + rw [← integral_const_mul] + congr 1 + ext z + rw [heatKernel_t_eq_half_y_y ht (z - x)] + ring + +end FeynmanKacHeatEquation +end MathFin diff --git a/LeanPool/MathFin/Probability/Gaussian/GaussianCDFDeriv.lean b/LeanPool/MathFin/Probability/Gaussian/GaussianCDFDeriv.lean new file mode 100644 index 0000000000..bace9ac923 --- /dev/null +++ b/LeanPool/MathFin/Probability/Gaussian/GaussianCDFDeriv.lean @@ -0,0 +1,133 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Gaussian.StandardNormal + +/-! +# Derivative of the standard normal CDF: `Φ'(x) = ϕ(x)` + +The standard normal CDF `Phi x = (gaussianReal 0 1 (Iic x)).toReal` has +derivative equal to the standard normal PDF at every point, by FTC. + +This is a foundational identity not present in Mathlib (no `Real.erf`, no +`gaussianReal_Iic_hasDerivAt`). Proved here via Lebesgue-`Iic` decomposition +into an interval integral plus a constant, then `intervalIntegral.integral_hasDerivAt_right`. + +## Main results + +* `hasDerivAt_Phi` — `HasDerivAt Phi (gaussianPDFReal 0 1 x) x` for every `x : ℝ`. +* `hasDerivAt_gaussianPDFReal_zero_one` — the PDF derivative `ϕ'(z) = -z·ϕ(z)` + (and its `.neg`-flip `hasDerivAt_neg_gaussianPDFReal_zero_one`), the + standard-normal first derivative reused across the Greeks and the Bachelier + truncated-mean identity. + +## Tags + +standard normal CDF, normal density, Black–Scholes delta, Gaussian derivative, +fundamental theorem of calculus, MSC 60E05, MSC 91G20 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- `(−ϕ(0,1,·))' = z · ϕ(0,1,z)`. Algebraic content: `d/dz [exp(-z²/2)] = -z · exp(-z²/2)`. -/ +lemma hasDerivAt_neg_gaussianPDFReal_zero_one (z : ℝ) : + HasDerivAt (fun z' : ℝ ↦ -gaussianPDFReal 0 1 z') + (z * gaussianPDFReal 0 1 z) z := by + unfold gaussianPDFReal + simp only [NNReal.coe_one, mul_one, sub_zero] + set c := (Real.sqrt (2 * π))⁻¹ + -- d/dz [-z²/2] = -z + have h_sq : HasDerivAt (fun z' : ℝ ↦ -(z'^2)/2) (-z) z := by + have h_pow : HasDerivAt (fun z' : ℝ ↦ z'^2) (2 * z) z := by + simpa using hasDerivAt_pow 2 z + have h_div : HasDerivAt (fun z' : ℝ ↦ z'^2 / 2) z z := by + have := h_pow.div_const 2; simpa using this + have h_neg : HasDerivAt (fun z' : ℝ ↦ -(z'^2 / 2)) (-z) z := h_div.neg + have h_eq : (fun z' : ℝ ↦ -(z'^2)/2) = (fun z' : ℝ ↦ -(z'^2 / 2)) := by + funext z'; ring + rw [h_eq]; exact h_neg + -- d/dz [exp(-z²/2)] = exp(-z²/2) · -z + have h_exp : HasDerivAt (fun z' : ℝ ↦ Real.exp (-(z'^2)/2)) + (Real.exp (-(z^2)/2) * -z) z := h_sq.exp + -- d/dz [c · exp(-z²/2)] = c · exp(-z²/2) · -z + have h_const : HasDerivAt (fun z' : ℝ ↦ c * Real.exp (-(z'^2)/2)) + (c * (Real.exp (-(z^2)/2) * -z)) z := h_exp.const_mul c + -- neg + have h_neg := h_const.neg + convert h_neg using 1; ring + +/-- `ϕ(0,1,·)' = -z · ϕ(0,1,z)` — the standard-normal PDF derivative (the +`.neg`-flip of `hasDerivAt_neg_gaussianPDFReal_zero_one`). The single +standard-normal first-derivative reused across the Greeks files. -/ +theorem hasDerivAt_gaussianPDFReal_zero_one (z : ℝ) : + HasDerivAt (fun z' : ℝ ↦ gaussianPDFReal 0 1 z') + (-(z * gaussianPDFReal 0 1 z)) z := by + have h := (hasDerivAt_neg_gaussianPDFReal_zero_one z).neg + have h_eq : ((-fun z' : ℝ ↦ -gaussianPDFReal 0 1 z') : ℝ → ℝ) + = fun z' : ℝ ↦ gaussianPDFReal 0 1 z' := by funext z'; simp + rw [h_eq] at h + exact h + +/-- **Standard normal CDF derivative**: `Phi'(x) = gaussianPDFReal 0 1 x`. -/ +theorem hasDerivAt_Phi (x : ℝ) : + HasDerivAt Phi (gaussianPDFReal 0 1 x) x := by + set a : ℝ := x - 1 + have hax : a < x := by change x - 1 < x; linarith + have h_pdf_int : Integrable (gaussianPDFReal 0 1) volume := + integrable_gaussianPDFReal _ _ + have h_pdf_cont : Continuous (gaussianPDFReal 0 1) := by + unfold gaussianPDFReal + exact (continuous_const).mul (by fun_prop) + have h_int_ax : IntervalIntegrable (gaussianPDFReal 0 1) volume a x := + h_pdf_int.intervalIntegrable + -- FTC right endpoint + have h_ftc : HasDerivAt (fun u ↦ ∫ z in a..u, gaussianPDFReal 0 1 z) + (gaussianPDFReal 0 1 x) x := + intervalIntegral.integral_hasDerivAt_right h_int_ax + h_pdf_cont.aestronglyMeasurable.stronglyMeasurableAtFilter + h_pdf_cont.continuousAt + -- Add the constant Phi a. + have h_shifted : HasDerivAt + (fun u ↦ Phi a + ∫ z in a..u, gaussianPDFReal 0 1 z) + (gaussianPDFReal 0 1 x) x := by + have := h_ftc.const_add (Phi a) + simpa using this + -- Phi equals this function in a neighborhood of x (for y > a). + have h_eq_nhds : Phi =ᶠ[nhds x] + (fun u ↦ Phi a + ∫ z in a..u, gaussianPDFReal 0 1 z) := by + refine Filter.eventually_of_mem (Ioi_mem_nhds hax) ?_ + intro y hy + rw [Set.mem_Ioi] at hy + change Phi y = Phi a + ∫ z in a..y, gaussianPDFReal 0 1 z + rw [Phi_eq_integral, Phi_eq_integral, intervalIntegral.integral_of_le hy.le] + have h_decomp : Set.Iic y = Set.Iic a ∪ Set.Ioc a y := by + ext z + simp only [Set.mem_Iic, Set.mem_union, Set.mem_Ioc] + refine ⟨fun hz ↦ ?_, fun hz ↦ ?_⟩ + · by_cases h : z ≤ a + · exact Or.inl h + · exact Or.inr ⟨not_le.mp h, hz⟩ + · rcases hz with h | ⟨_, h⟩ + · linarith + · exact h + have h_disj : Disjoint (Set.Iic a) (Set.Ioc a y) := by + rw [Set.disjoint_left] + intro z hz1 hz2 + simp only [Set.mem_Iic] at hz1 + simp only [Set.mem_Ioc] at hz2 + linarith [hz2.1] + rw [h_decomp, setIntegral_union h_disj measurableSet_Ioc + h_pdf_int.integrableOn h_pdf_int.integrableOn] + exact h_shifted.congr_of_eventuallyEq h_eq_nhds + +end MathFin diff --git a/LeanPool/MathFin/Probability/Gaussian/GaussianMoments.lean b/LeanPool/MathFin/Probability/Gaussian/GaussianMoments.lean new file mode 100644 index 0000000000..a346ddd039 --- /dev/null +++ b/LeanPool/MathFin/Probability/Gaussian/GaussianMoments.lean @@ -0,0 +1,227 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho, Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import TauCeti.Probability.Distributions.Gaussian.Moments +public import Mathlib.Probability.BrownianMotion.Basic +public import Mathlib.Probability.Distributions.Gaussian.HasGaussianLaw.Basic +public import Mathlib.Probability.Distributions.Gaussian.IsGaussianProcess.Basic +public import Mathlib.Topology.UniformSpace.Uniformizable + +/-! +# Gaussian moments + +Small, shared moment facts for real Gaussians used across the Brownian-motion +foundations (`BrownianMartingale`, `BrownianQuadraticVariation`, the L² quadratic +variation). Kept in one place so each identity is proved exactly once. + +The fourth moment reuses Degenne's `(2n)`-th central-moment formula +(`ProbabilityTheory.centralMoment_two_mul_gaussianReal`) rather than re-deriving the +Gaussian integral — coherence with the upstream `brownian-motion` package. + +## Main results + +* `integral_sq_gaussianReal`, `integral_pow3_gaussianReal`, `integral_pow4_gaussianReal`, + `integral_pow6_gaussianReal`: the second, third, fourth and sixth moments of `N(0, v)` are + `v`, `0`, `3 v²` and `15 v³`. +* `integral_sq_sub_var_sq_gaussianReal`, `integral_sq_sub_var_gaussianReal`: for `N(0, v)`, + `∫ (x² − v)² = 2 v²` and `∫ (x² − v) = 0`. +* `integral_sq_of_hasLaw_gaussianReal`: `X ~ N(m, v)` gives `𝔼[X²] = m² + v`. +* `hasLaw_increment`: for `s ≤ t`, the increment `B t − B s` of a pre-Brownian motion has law + `N(0, t − s)`. +* `hasLaw_sum_range_gaussianReal`: a sum of `n` independent `N(m, v)` variables has law + `N(n m, n v)`. +* `hasLaw_sub_div_of_gaussianReal`: if `X ~ N(μ, v)` with `v = s²`, `s > 0`, then + `(X − μ)/s ~ N(0, 1)`. + +## Tags + +Gaussian moments, fourth moment, central moments, normal distribution, variance, MSC 60E05, +MSC 60J65 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal + +/-- Second moment of a centered real Gaussian: `∫ x, x² ∂(gaussianReal 0 v) = v`. +For a mean-zero law the second moment is the variance (`variance_id_gaussianReal`). -/ +lemma integral_sq_gaussianReal (v : ℝ≥0) : + ∫ x, x ^ 2 ∂(gaussianReal 0 v) = (v : ℝ) := by + have h_var : variance id (gaussianReal 0 v) = (v : ℝ) := variance_id_gaussianReal + have h_mean : ∫ x, x ∂(gaussianReal 0 v) = 0 := integral_id_gaussianReal + rw [variance_of_integral_eq_zero aemeasurable_id h_mean] at h_var + exact h_var + +/-- Third moment of a centered real Gaussian (odd moment, by density symmetry). -/ +lemma integral_pow3_gaussianReal (v : ℝ≥0) : + ∫ x, x ^ 3 ∂(gaussianReal 0 v) = 0 := by + rcases eq_or_ne v 0 with rfl | hv + · rw [gaussianReal_zero_var] + simp + · rw [integral_gaussianReal_eq_integral_smul hv] + simp only [smul_eq_mul] + have hmap : Measure.map (fun x : ℝ ↦ -x) (volume : Measure ℝ) = volume := + (Measure.measurePreserving_neg (μ := (volume : Measure ℝ))).map_eq + have hpdfneg : ∀ x : ℝ, gaussianPDFReal 0 v (-x) = gaussianPDFReal 0 v x := by + intro x + simp only [gaussianPDFReal, sub_zero, neg_sq] + have hsub : ∫ y, gaussianPDFReal 0 v y * y ^ 3 ∂volume + = ∫ x, gaussianPDFReal 0 v (-x) * (-x) ^ 3 ∂volume := by + have h1 : ∫ y, gaussianPDFReal 0 v y * y ^ 3 ∂volume + = ∫ y, gaussianPDFReal 0 v y * y ^ 3 + ∂(Measure.map (fun x : ℝ ↦ -x) (volume : Measure ℝ)) := by + rw [hmap] + rw [h1] + exact integral_map_equiv (MeasurableEquiv.neg (G := ℝ)) + (fun y : ℝ ↦ gaussianPDFReal 0 v y * y ^ 3) + rw [hsub] + have hcongr : ∫ x, gaussianPDFReal 0 v (-x) * (-x) ^ 3 ∂volume + = -∫ x, gaussianPDFReal 0 v x * x ^ 3 ∂volume := by + have hpt : ∀ x : ℝ, gaussianPDFReal 0 v (-x) * (-x) ^ 3 + = -(gaussianPDFReal 0 v x * x ^ 3) := by + intro x + rw [hpdfneg x] + ring + rw [integral_congr_ae (Filter.Eventually.of_forall hpt), integral_neg] + rw [hcongr] + linarith + +/-- Fourth moment of a centered real Gaussian: `∫ x, x⁴ ∂(gaussianReal 0 v) = 3 v²` +(the kurtosis identity `E[X⁴] = 3·Var²`, the source of the `2(Δt)²` variance of squared +Brownian increments). Via the `(2n)`-th central-moment formula +`centralMoment_two_mul_gaussianReal` at `n = 2` (`(2·2−1)!! = 3!! = 3`). -/ +lemma integral_pow4_gaussianReal (v : ℝ≥0) : + ∫ x, x ^ 4 ∂(gaussianReal 0 v) = 3 * (v : ℝ) ^ 2 := by + simpa using TauCeti.Probability.integral_sub_pow_four_gaussianReal 0 v + +/-- Sixth moment of a centered real Gaussian: `∫ x, x⁶ ∂(gaussianReal 0 v) = 15 v³` +(`E[X⁶] = 15·Var³`). It controls the `L²` size of the Itô–Taylor remainder +(`E[(ΔB)⁶] = 15(Δt)³`, so `‖|ΔB|³‖_{L²} = √15·(Δt)^{3/2}` sums to `O(n^{-1/2})`). +Via the `(2n)`-th central-moment formula `centralMoment_two_mul_gaussianReal` at +`n = 3` (`(2·3−1)!! = 5!! = 15`). -/ +lemma integral_pow6_gaussianReal (v : ℝ≥0) : + ∫ x, x ^ 6 ∂(gaussianReal 0 v) = 15 * (v : ℝ) ^ 3 := by + simpa [Nat.doubleFactorial, mul_comm] using + TauCeti.Probability.integral_sub_pow_two_mul_gaussianReal 0 v 3 + +/-- **Mean-square fluctuation of a squared centered Gaussian**: `∫ (x² − v)² ∂N(0,v) = 2v²`, +i.e. `Var(X²) = 2·Var(X)²` for `X ~ N(0,v)`. This is the kurtosis `E[X⁴] = 3v²` minus +`(E[X²])² = v²`. It is exactly the per-interval term `E[((ΔB)² − Δt)²] = 2(Δt)²` whose sum +gives the `2t²/n` rate of the L² quadratic variation. -/ +lemma integral_sq_sub_var_sq_gaussianReal (v : ℝ≥0) : + ∫ x, (x ^ 2 - (v : ℝ)) ^ 2 ∂(gaussianReal 0 v) = 2 * (v : ℝ) ^ 2 := by + have hint2 : Integrable (fun x : ℝ ↦ x ^ 2) (gaussianReal 0 v) := + (memLp_id_gaussianReal (μ := 0) (v := v) 2).integrable_sq + have hint4 : Integrable (fun x : ℝ ↦ x ^ 4) (gaussianReal 0 v) := by + have h := (memLp_id_gaussianReal (μ := 0) (v := v) 4).integrable_norm_pow (p := 4) (by norm_num) + simp only [id_eq, Real.norm_eq_abs] at h + have hfe : (fun x : ℝ ↦ |x| ^ 4) = fun x : ℝ ↦ x ^ 4 := + funext fun x ↦ by rw [pow_abs, abs_of_nonneg (by positivity)] + rwa [hfe] at h + have hcm2 : Integrable (fun x : ℝ ↦ 2 * (v : ℝ) * x ^ 2) (gaussianReal 0 v) := + hint2.const_mul (2 * (v : ℝ)) + have hdiff : Integrable (fun a : ℝ ↦ a ^ 4 - 2 * (v : ℝ) * a ^ 2) (gaussianReal 0 v) := + hint4.sub hcm2 + have hexpand : ∀ x : ℝ, (x ^ 2 - (v : ℝ)) ^ 2 = x ^ 4 - 2 * (v : ℝ) * x ^ 2 + (v : ℝ) ^ 2 := + fun x ↦ by ring + have huniv : (gaussianReal 0 v).real Set.univ = 1 := by + rw [measureReal_def, measure_univ, ENNReal.toReal_one] + rw [integral_congr_ae (Filter.Eventually.of_forall hexpand), + integral_add hdiff (integrable_const _), + integral_sub hint4 hcm2, + integral_pow4_gaussianReal, integral_const_mul, integral_sq_gaussianReal, integral_const, + huniv] + simp only [smul_eq_mul] + ring + +/-- **A centered squared Gaussian has mean zero**: `∫ (x² − v) ∂N(0,v) = 0`, i.e. +`E[X² − Var] = 0` for `X ~ N(0,v)`. (`E[X²] = v`.) -/ +lemma integral_sq_sub_var_gaussianReal (v : ℝ≥0) : + ∫ x, (x ^ 2 - (v : ℝ)) ∂(gaussianReal 0 v) = 0 := by + have hint2 : Integrable (fun x : ℝ ↦ x ^ 2) (gaussianReal 0 v) := + (memLp_id_gaussianReal (μ := 0) (v := v) 2).integrable_sq + have huniv : (gaussianReal 0 v).real Set.univ = 1 := by + rw [measureReal_def, measure_univ, ENNReal.toReal_one] + rw [integral_sub hint2 (integrable_const _), integral_sq_gaussianReal, integral_const, huniv, + one_smul, sub_self] + +/-- The second moment of a Gaussian random variable: `X ~ N(m, v)` gives +`𝔼[X²] = m² + v` (`variance_eq_sub` on the law). -/ +theorem integral_sq_of_hasLaw_gaussianReal {Ω : Type*} {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} {X : Ω → ℝ} {m : ℝ} {v : ℝ≥0} + (hX : HasLaw X (gaussianReal m v) μ) : ∫ ω, X ω ^ 2 ∂μ = m ^ 2 + v := by + have h := variance_eq_sub (memLp_id_gaussianReal' (μ := m) (v := v) 2 (by simp)) + simp only [variance_id_gaussianReal, Pi.pow_apply, id] at h + rw [integral_id_gaussianReal] at h + have hc := hX.integral_comp (f := fun x : ℝ ↦ x ^ 2) (by fun_prop) + simp only [Function.comp_def] at hc + rw [hc] + linarith + +/-! ### Brownian increments -/ + +/-- For `s ≤ t : ℝ≥0`, the increment `B t − B s` of a pre-Brownian motion has law +`gaussianReal 0 (t - s)`. Degenne's `hasLaw_sub` states the variance as `nndist`; this is the +same fact with the `ℝ≥0` subtraction the time-indexed towers actually carry, which is the only +reason the conversion keeps reappearing. -/ +lemma hasLaw_increment {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) {s t : ℝ≥0} (hst : s ≤ t) : + HasLaw (fun ω ↦ B t ω - B s ω) (gaussianReal 0 (t - s)) μ := by + have hL := hB.hasLaw_sub t s + have hv : nndist (t : ℝ) (s : ℝ) = (t - s : ℝ≥0) := by + apply NNReal.coe_injective + rw [coe_nndist, Real.dist_eq, NNReal.coe_sub hst, + abs_of_nonneg (sub_nonneg.mpr (NNReal.coe_le_coe.mpr hst))] + rw [← hv]; exact hL + +/-- A pre-Brownian increment `B t − B s` lies in `L²(μ)`, for any two times. -/ +lemma memLp_increment {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) (s t : ℝ≥0) : + MemLp (fun ω ↦ B t ω - B s ω) 2 μ := + hB.isGaussianProcess.hasGaussianLaw_sub.memLp_two + +/-! ### Sums and standardization of Gaussian variables -/ + +/-- A sum of `n` independent `N(m, v)` variables is `N(n·m, n·v)`. -/ +theorem hasLaw_sum_range_gaussianReal {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} + {J : ℕ → Ω → ℝ} {m : ℝ} {v : ℝ≥0} + (hJ : ∀ i, HasLaw (J i) (gaussianReal m v) Q) (hind : iIndepFun J Q) (n : ℕ) : + HasLaw (∑ i ∈ Finset.range n, J i) (gaussianReal (n * m) (n * v)) Q := by + have := (hJ 0).isProbabilityMeasure + induction n with + | zero => + simp only [Finset.sum_range_zero, Nat.cast_zero, zero_mul, gaussianReal_zero_var] + exact hasLaw_dirac_of_ae_eq (ae_of_all _ fun _ ↦ rfl) + | succ n ih => + rw [Finset.sum_range_succ] + have h := (hind.indepFun_sum_range_succ₀ (fun i ↦ (hJ i).aemeasurable) n).hasLaw_add ih (hJ n) + rw [gaussianReal_conv_gaussianReal] at h + convert h using 2 <;> push_cast <;> ring + +/-- Standardizing a Gaussian: if `X ∼ N(μ, s²)` with `s > 0`, then `(X − μ)/s ∼ N(0, 1)`. -/ +theorem hasLaw_sub_div_of_gaussianReal {Ω : Type*} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} + {X : Ω → ℝ} {μ s : ℝ} {v : ℝ≥0} + (hX : HasLaw X (gaussianReal μ v) Q) (hs : 0 < s) (hv : (v : ℝ) = s ^ 2) : + HasLaw (fun ω ↦ (X ω - μ) / s) (gaussianReal 0 1) Q := by + have h := gaussianReal_const_mul (gaussianReal_sub_const hX μ) s⁻¹ + have hparam : gaussianReal (s⁻¹ * (μ - μ)) (.mk (s⁻¹ ^ 2) (sq_nonneg _) * v) + = gaussianReal 0 1 := by + congr 1 + · rw [sub_self, mul_zero] + · ext + rw [NNReal.coe_mul, NNReal.coe_mk, hv, NNReal.coe_one, inv_pow, + inv_mul_cancel₀ (pow_pos hs 2).ne'] + rw [hparam] at h + simpa only [div_eq_inv_mul] using h + +end MathFin diff --git a/LeanPool/MathFin/Probability/Gaussian/GaussianPairLinearLaw.lean b/LeanPool/MathFin/Probability/Gaussian/GaussianPairLinearLaw.lean new file mode 100644 index 0000000000..0876b16ea6 --- /dev/null +++ b/LeanPool/MathFin/Probability/Gaussian/GaussianPairLinearLaw.lean @@ -0,0 +1,160 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Gaussian.BivariateNormalCDF + +/-! +# Linear combinations of a correlated standard Gaussian pair + +Let `(U, V)` be jointly Gaussian, each standard normal, with covariance `ρ`. Then `ρ² ≤ 1` +(`sq_le_one_of_covariance_unit`, from `Var[U − ρV] = 1 − ρ² ≥ 0`), and the pair has the +standard bivariate normal law `bivariateNormalLaw ρ` of +`Probability/Gaussian/BivariateNormalCDF.lean`: +a Gaussian law on `ℝ²` is pinned by its means, variances and covariance +(`eq_bivariateNormalLaw`). Every linear combination `aU + bV` is therefore the centred +Gaussian `N(0, a² + 2abρ + b²)` (`map_linear_bivariateNormalLaw`), and its exponential moment +follows from the Gaussian moment generating function: + + `𝔼[e^{aU + bV}] = e^{(a² + 2abρ + b²)/2}`. + +This is the computation behind every second moment of a pair of correlated lognormal prices, +such as the cross-moment of a basket (`Models/BlackScholes/BasketMomentMatching.lean`). + +## Main results + +* `variance_linear_of_unit` — `Var[aU + bV] = a² + 2abρ + b²` for unit variances. +* `covariance_linear_of_unit` — `cov(pU + qV, aU + bV) = pa + (pb + qa)ρ + qb`. +* `sq_le_one_of_covariance_unit` — a covariance of unit-variance variables has `ρ² ≤ 1`. +* `hasLaw_bivariateNormalLaw_of_gaussianPair` — `(U, V) ~ bivariateNormalLaw ρ`. +* `hasLaw_linear_gaussianPair` — `aU + bV ~ N(0, a² + 2abρ + b²)`. +* `integral_exp_linear_gaussianPair` — `𝔼[e^{aU + bV}] = e^{(a² + 2abρ + b²)/2}`. + +## Tags + +correlated Gaussians, linear combination, basket option, lognormal cross-moment, +moment generating function, bivariate normal, MSC 60E05, MSC 60G15, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + +/-- **Variance of a linear combination of unit-variance variables**: +`Var[aU + bV] = a² + 2abρ + b²` when `Var U = Var V = 1` and `cov(U, V) = ρ`. -/ +theorem variance_linear_of_unit [IsFiniteMeasure P] {U V : Ω → ℝ} {ρ : ℝ} + (hmU : MemLp U 2 P) (hmV : MemLp V 2 P) (hU : Var[U; P] = 1) (hV : Var[V; P] = 1) + (hcov : cov[U, V; P] = ρ) (a b : ℝ) : + Var[fun ω ↦ a * U ω + b * V ω; P] = a ^ 2 + 2 * a * b * ρ + b ^ 2 := by + rw [variance_fun_add (hmU.const_mul a) (hmV.const_mul b), variance_const_mul, + variance_const_mul, covariance_const_mul_left, covariance_const_mul_right, hcov, hU, hV] + ring + +/-- **Covariance of two linear combinations of unit-variance variables**: +`cov(pU + qV, aU + bV) = pa + (pb + qa)ρ + qb` when `Var U = Var V = 1` and +`cov(U, V) = ρ` (covariance bilinearity). -/ +theorem covariance_linear_of_unit [IsFiniteMeasure P] {U V : Ω → ℝ} {ρ : ℝ} + (hmU : MemLp U 2 P) (hmV : MemLp V 2 P) (hU : Var[U; P] = 1) (hV : Var[V; P] = 1) + (hcov : cov[U, V; P] = ρ) (p q a b : ℝ) : + cov[fun ω ↦ p * U ω + q * V ω, fun ω ↦ a * U ω + b * V ω; P] + = p * a + (p * b + q * a) * ρ + q * b := by + change cov[(fun ω ↦ p * U ω) + (fun ω ↦ q * V ω), (fun ω ↦ a * U ω) + (fun ω ↦ b * V ω); P] = _ + rw [covariance_add_left (hmU.const_mul p) (hmV.const_mul q) + ((hmU.const_mul a).add (hmV.const_mul b)), + covariance_add_right (hmU.const_mul p) (hmU.const_mul a) (hmV.const_mul b), + covariance_add_right (hmV.const_mul q) (hmU.const_mul a) (hmV.const_mul b)] + simp only [covariance_const_mul_left, covariance_const_mul_right] + rw [covariance_self hmU.aemeasurable, covariance_self hmV.aemeasurable, covariance_comm V U, + hcov, hU, hV] + ring + +/-- **Correlations are at most one in absolute value**: if `Var U = Var V = 1` and +`cov(U, V) = ρ`, then `ρ² ≤ 1`, since `0 ≤ Var[U − ρV] = 1 − ρ²`. -/ +theorem sq_le_one_of_covariance_unit [IsFiniteMeasure P] {U V : Ω → ℝ} {ρ : ℝ} + (hmU : MemLp U 2 P) (hmV : MemLp V 2 P) (hU : Var[U; P] = 1) (hV : Var[V; P] = 1) + (hcov : cov[U, V; P] = ρ) : ρ ^ 2 ≤ 1 := by + have h := variance_nonneg (fun ω ↦ 1 * U ω + -ρ * V ω) P + rw [variance_linear_of_unit hmU hmV hU hV hcov] at h + nlinarith [h] + +/-- **A standardized Gaussian pair has the standard bivariate normal law**: if `(U, V)` is +jointly Gaussian with `U, V ~ N(0, 1)` and `cov(U, V) = ρ`, then +`(U, V) ~ bivariateNormalLaw ρ`. The law of the pair is Gaussian with the coordinate means, +variances and covariance of `bivariateNormalLaw ρ`, so `eq_bivariateNormalLaw` identifies it. -/ +theorem hasLaw_bivariateNormalLaw_of_gaussianPair {U V : Ω → ℝ} {ρ : ℝ} + (hUV : HasGaussianLaw (fun ω ↦ (U ω, V ω)) P) + (hU : HasLaw U (gaussianReal 0 1) P) (hV : HasLaw V (gaussianReal 0 1) P) + (hcov : cov[U, V; P] = ρ) : + HasLaw (fun ω ↦ (U ω, V ω)) (bivariateNormalLaw ρ) P := by + have := hUV.isProbabilityMeasure + have := hUV.isGaussian_map + have hU1 : Var[U; P] = 1 := by + rw [hU.variance_eq, variance_id_gaussianReal, NNReal.coe_one] + have hV1 : Var[V; P] = 1 := by + rw [hV.variance_eq, variance_id_gaussianReal, NNReal.coe_one] + have hρ := sq_le_one_of_covariance_unit hU.hasGaussianLaw.memLp_two + hV.hasGaussianLaw.memLp_two hU1 hV1 hcov + have hpair : AEMeasurable (fun ω ↦ (U ω, V ω)) P := hUV.aemeasurable + refine ⟨hpair, eq_bivariateNormalLaw hρ ?_ ?_ ?_ ?_ ?_⟩ + · rw [integral_map hpair measurable_fst.aestronglyMeasurable] + exact hU.integral_eq.trans integral_id_gaussianReal + · rw [integral_map hpair measurable_snd.aestronglyMeasurable] + exact hV.integral_eq.trans integral_id_gaussianReal + · rw [variance_map measurable_fst.aemeasurable hpair] + exact hU1 + · rw [variance_map measurable_snd.aemeasurable hpair] + exact hV1 + · rw [covariance_map measurable_fst.aestronglyMeasurable measurable_snd.aestronglyMeasurable + hpair] + exact hcov + +/-- **A linear combination of a correlated standard Gaussian pair is Gaussian**: for `(U, V)` +jointly Gaussian with `U, V ~ N(0, 1)` and `cov(U, V) = ρ`, `aU + bV ~ N(0, a² + 2abρ + b²)`: +the law `map_linear_bivariateNormalLaw` of a linear functional of `bivariateNormalLaw ρ`, +transported along `hasLaw_bivariateNormalLaw_of_gaussianPair`. -/ +theorem hasLaw_linear_gaussianPair {U V : Ω → ℝ} {ρ : ℝ} + (hUV : HasGaussianLaw (fun ω ↦ (U ω, V ω)) P) + (hU : HasLaw U (gaussianReal 0 1) P) (hV : HasLaw V (gaussianReal 0 1) P) + (hcov : cov[U, V; P] = ρ) (a b : ℝ) : + HasLaw (fun ω ↦ a * U ω + b * V ω) + (gaussianReal 0 (a ^ 2 + 2 * a * b * ρ + b ^ 2).toNNReal) P := by + have := hUV.isProbabilityMeasure + have hρ := sq_le_one_of_covariance_unit hU.hasGaussianLaw.memLp_two + hV.hasGaussianLaw.memLp_two + (by rw [hU.variance_eq, variance_id_gaussianReal, NNReal.coe_one]) + (by rw [hV.variance_eq, variance_id_gaussianReal, NNReal.coe_one]) hcov + exact HasLaw.comp ⟨by fun_prop, map_linear_bivariateNormalLaw hρ a b⟩ + (hasLaw_bivariateNormalLaw_of_gaussianPair hUV hU hV hcov) + +/-- **Exponential moment of a linear combination of a correlated standard Gaussian pair**: +`𝔼[e^{aU + bV}] = e^{(a² + 2abρ + b²)/2}`, the moment generating function of +`N(0, a² + 2abρ + b²)` (`hasLaw_linear_gaussianPair`) at `1`. -/ +theorem integral_exp_linear_gaussianPair {U V : Ω → ℝ} {ρ : ℝ} + (hUV : HasGaussianLaw (fun ω ↦ (U ω, V ω)) P) + (hU : HasLaw U (gaussianReal 0 1) P) (hV : HasLaw V (gaussianReal 0 1) P) + (hcov : cov[U, V; P] = ρ) (a b : ℝ) : + ∫ ω, Real.exp (a * U ω + b * V ω) ∂P = Real.exp ((a ^ 2 + 2 * a * b * ρ + b ^ 2) / 2) := by + have := hUV.isProbabilityMeasure + have hL := hasLaw_linear_gaussianPair hUV hU hV hcov a b + have hnn : 0 ≤ a ^ 2 + 2 * a * b * ρ + b ^ 2 := by + rw [← variance_linear_of_unit hU.hasGaussianLaw.memLp_two hV.hasGaussianLaw.memLp_two + (by rw [hU.variance_eq, variance_id_gaussianReal, NNReal.coe_one]) + (by rw [hV.variance_eq, variance_id_gaussianReal, NNReal.coe_one]) hcov a b] + exact variance_nonneg _ _ + have hmgf := congrFun (mgf_fun_id_gaussianReal (μ := 0) + (v := (a ^ 2 + 2 * a * b * ρ + b ^ 2).toNNReal)) 1 + simp only [mgf, one_mul, mul_one, one_pow, zero_add] at hmgf + rw [← Real.coe_toNNReal _ hnn, ← hmgf] + exact hL.integral_comp (f := Real.exp) Real.continuous_exp.aestronglyMeasurable + +end MathFin diff --git a/LeanPool/MathFin/Probability/Gaussian/GaussianPartialMoments.lean b/LeanPool/MathFin/Probability/Gaussian/GaussianPartialMoments.lean new file mode 100644 index 0000000000..05950bf8c4 --- /dev/null +++ b/LeanPool/MathFin/Probability/Gaussian/GaussianPartialMoments.lean @@ -0,0 +1,161 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Gaussian.StandardNormal +public import LeanPool.MathFin.Probability.Gaussian.GaussianCDFDeriv + +/-! +# Partial moments of the standard normal + +The integrals of the standard normal density `ϕ` over a right tail `(a, ∞)` that the closed forms +of the library are built from: + +* `integrable_id_mul_gaussianPDFReal_volume`: `z ↦ z·ϕ(z)` is integrable. +* `integral_id_mul_gaussianPDFReal_Ioi`: the truncated first moment `∫_(a,∞) z·ϕ(z) dz = ϕ(a)`, + by the fundamental theorem of calculus, since `(−ϕ)' = z·ϕ`. +* `integral_gaussianPDFReal_Ioi`: the tail mass `∫_(a,∞) ϕ = 1 − Φ(a)`. +* `integral_max_sub_mul_gaussianPDFReal`: the stop-loss transform + `E[(Z − z)⁺] = ϕ(z) − z·(1 − Φ(z))` for `Z ~ N(0,1)`. + +The Bachelier call (`Models/Bachelier/Bachelier`), the Rockafellar–Uryasev characterisation of +Gaussian CVaR (`Risk/RockafellarUryasev`) and the normal tail bounds +(`Probability/Gaussian/NormalTail`) are all read off these four facts. + +## Main results + +* `integrable_id_mul_gaussianPDFReal_volume`: `z ↦ z·ϕ(z)` is integrable. +* `integral_id_mul_gaussianPDFReal_Ioi`: `∫_(a,∞) z·ϕ(z) dz = ϕ(a)`. +* `integral_gaussianPDFReal_Ioi`: `∫_(a,∞) ϕ = 1 − Φ(a)`. +* `integral_max_sub_mul_gaussianPDFReal`: `∫ max (x − z) 0 · ϕ(x) dx = ϕ(z) − z·(1 − Φ(z))`, + the stop-loss transform of `N(0, 1)`. + +## Tags + +truncated normal moment, stop-loss transform, normal tail, Bachelier model, Gaussian CVaR, +expected shortfall, MSC 60E05, MSC 91G70, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real Filter +open scoped NNReal ENNReal Topology + +/-! ### Integrability of `z ↦ z · ϕ(0, 1, z)` -/ + +/-- The function `z ↦ z · ϕ(0, 1, z)` is integrable on `ℝ` (against Lebesgue). +Derived by transferring `Integrable id (gaussianReal 0 1)` (the existence of the +first moment of `N(0, 1)`) through the withDensity identification of +`gaussianReal`. -/ +lemma integrable_id_mul_gaussianPDFReal_volume : + Integrable (fun z : ℝ ↦ z * gaussianPDFReal 0 1 z) volume := by + have h_id_integrable : Integrable (id : ℝ → ℝ) (gaussianReal (0 : ℝ) 1) := by + have h_memLp : MemLp (id : ℝ → ℝ) 2 (gaussianReal (0 : ℝ) 1) := memLp_id_gaussianReal 2 + exact (h_memLp.mono_exponent (by norm_num : (1 : ℝ≥0∞) ≤ 2)).integrable le_rfl + rw [gaussianReal_of_var_ne_zero (0 : ℝ) (one_ne_zero : (1 : ℝ≥0) ≠ 0)] at h_id_integrable + have h_pdf_meas : Measurable (gaussianPDF (0 : ℝ) 1) := by + unfold gaussianPDF; fun_prop + have h_pdf_lt_top : ∀ᵐ z ∂(volume : Measure ℝ), gaussianPDF (0 : ℝ) 1 z < ∞ := by + refine ae_of_all _ (fun z ↦ ?_) + unfold gaussianPDF; exact ENNReal.ofReal_lt_top + rw [integrable_withDensity_iff_integrable_smul' h_pdf_meas h_pdf_lt_top] at h_id_integrable + have h_eq : (fun z : ℝ ↦ (gaussianPDF (0 : ℝ) 1 z).toReal • id z) + = (fun z : ℝ ↦ z * gaussianPDFReal 0 1 z) := by + funext z + change (gaussianPDF (0 : ℝ) 1 z).toReal • z = z * gaussianPDFReal 0 1 z + unfold gaussianPDF + rw [ENNReal.toReal_ofReal (gaussianPDFReal_nonneg _ _ _)] + simp [smul_eq_mul, mul_comm] + rwa [h_eq] at h_id_integrable + +/-! ### Truncated first moment of the standard normal -/ + +/-- **Truncated mean** of `N(0, 1)` on `(a, ∞)`: +`∫ z in Ioi a, z · ϕ(z) dz = ϕ(a)`. + +Proved via FTC for improper integrals (`integral_Ioi_of_hasDerivAt_of_tendsto`) +using the antiderivative `z ↦ -ϕ(z)` of `z ↦ z · ϕ(z)`, and the fact that +`ϕ(z) → 0` as `z → ∞`. -/ +lemma integral_id_mul_gaussianPDFReal_Ioi (a : ℝ) : + ∫ z in Set.Ioi a, z * gaussianPDFReal 0 1 z = gaussianPDFReal 0 1 a := by + -- Antiderivative of z · ϕ(0,1,z) is -ϕ(0,1,z) + have h_deriv : ∀ x ∈ Set.Ioi a, + HasDerivAt (fun z' ↦ -gaussianPDFReal 0 1 z') (x * gaussianPDFReal 0 1 x) x := by + intro x _; exact hasDerivAt_neg_gaussianPDFReal_zero_one x + have h_cont : ContinuousWithinAt (fun z' : ℝ ↦ -gaussianPDFReal 0 1 z') (Set.Ici a) a := by + have : Continuous fun z' : ℝ ↦ -gaussianPDFReal 0 1 z' := by + unfold gaussianPDFReal; fun_prop + exact this.continuousWithinAt + have h_int : IntegrableOn (fun z' : ℝ ↦ z' * gaussianPDFReal 0 1 z') (Set.Ioi a) volume := by + have h_full : Integrable (fun z' : ℝ ↦ z' * gaussianPDFReal 0 1 z') volume := + integrable_id_mul_gaussianPDFReal_volume + exact h_full.integrableOn + have h_lim : Tendsto (fun z' : ℝ ↦ -gaussianPDFReal 0 1 z') atTop (𝓝 0) := by + rw [show (0 : ℝ) = -0 from neg_zero.symm] + refine Tendsto.neg ?_ + -- gaussianPDFReal 0 1 z = (sqrt(2π))⁻¹ · exp(-z²/2). Both factors handled separately. + have h_atBot : Tendsto (fun z : ℝ ↦ -(z - 0)^2/2) atTop atBot := by + have h_sub : Tendsto (fun z : ℝ ↦ (z - 0)^2) atTop atTop := by simp + have h_neg : Tendsto (fun z : ℝ ↦ -((z - 0)^2)) atTop atBot := + tendsto_neg_atTop_atBot.comp h_sub + have h_div := h_neg.atBot_div_const (by norm_num : (0 : ℝ) < 2) + simpa using h_div + have h_exp : Tendsto (fun z : ℝ ↦ Real.exp (-(z - 0)^2/2)) atTop (𝓝 0) := + Real.tendsto_exp_atBot.comp h_atBot + have h_mul := h_exp.const_mul ((Real.sqrt (2 * π))⁻¹ : ℝ) + rw [mul_zero] at h_mul + convert h_mul using 1 + funext z; unfold gaussianPDFReal; simp [NNReal.coe_one] + have hres := integral_Ioi_of_hasDerivAt_of_tendsto h_cont h_deriv h_int h_lim + -- hres : ∫ z in Ioi a, z * pdf z = 0 - (-pdf a) = pdf a + linarith [hres] + +/-! ### Tail mass and the stop-loss transform -/ + +/-- **Gaussian tail mass in pdf form**: `∫_{Ioi a} ϕ(x) dx = 1 − Φ(a)`. -/ +lemma integral_gaussianPDFReal_Ioi (a : ℝ) : + ∫ x in Set.Ioi a, gaussianPDFReal 0 1 x = 1 - Phi a := by + have h_meas : (gaussianReal (0 : ℝ) 1 (Set.Ioi a)).toReal + = ∫ x in Set.Ioi a, gaussianPDFReal 0 1 x := by + rw [gaussianReal_apply_eq_integral _ one_ne_zero] + exact ENNReal.toReal_ofReal <| setIntegral_nonneg measurableSet_Ioi + (fun _ _ ↦ gaussianPDFReal_nonneg _ _ _) + rw [← h_meas, gaussianReal_Ioi_toReal, Phi_neg] + +/-- **Standard-normal expected shortfall**: `E[(Z − z)⁺] = ϕ(z) − z·(1 − Φ(z))`. +The positive part localizes the integral to the tail `Ioi z`, where it splits +into the truncated first moment (`= ϕ(z)`) minus `z` times the tail mass. -/ +lemma integral_max_sub_mul_gaussianPDFReal (z : ℝ) : + ∫ x, max (x - z) 0 * gaussianPDFReal 0 1 x + = gaussianPDFReal 0 1 z - z * (1 - Phi z) := by + have h_eq : (fun x ↦ max (x - z) 0 * gaussianPDFReal 0 1 x) + = Set.indicator (Set.Ioi z) (fun x ↦ (x - z) * gaussianPDFReal 0 1 x) := by + funext x + by_cases hx : x ∈ Set.Ioi z + · rw [Set.indicator_of_mem hx, max_eq_left (sub_nonneg.2 (Set.mem_Ioi.1 hx).le)] + · have hxz : x ≤ z := not_lt.1 (fun h ↦ hx (Set.mem_Ioi.2 h)) + rw [Set.indicator_of_notMem hx, max_eq_right (sub_nonpos.2 hxz), zero_mul] + rw [h_eq, integral_indicator measurableSet_Ioi] + have h_int_x : IntegrableOn (fun x ↦ x * gaussianPDFReal 0 1 x) (Set.Ioi z) volume := + integrable_id_mul_gaussianPDFReal_volume.integrableOn + have h_int_pdf : IntegrableOn (fun x ↦ z * gaussianPDFReal 0 1 x) (Set.Ioi z) volume := + ((integrable_gaussianPDFReal 0 1).const_mul z).integrableOn + calc ∫ x in Set.Ioi z, (x - z) * gaussianPDFReal 0 1 x + = ∫ x in Set.Ioi z, + (x * gaussianPDFReal 0 1 x - z * gaussianPDFReal 0 1 x) := by + congr 1; funext x; ring + _ = (∫ x in Set.Ioi z, x * gaussianPDFReal 0 1 x) + - ∫ x in Set.Ioi z, z * gaussianPDFReal 0 1 x := + integral_sub h_int_x h_int_pdf + _ = gaussianPDFReal 0 1 z - z * (1 - Phi z) := by + rw [integral_id_mul_gaussianPDFReal_Ioi, integral_const_mul, + integral_gaussianPDFReal_Ioi] + +end MathFin diff --git a/LeanPool/MathFin/Probability/Gaussian/NormalQuantile.lean b/LeanPool/MathFin/Probability/Gaussian/NormalQuantile.lean new file mode 100644 index 0000000000..7924ddad0b --- /dev/null +++ b/LeanPool/MathFin/Probability/Gaussian/NormalQuantile.lean @@ -0,0 +1,173 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho, Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Laws.Quantile +public import LeanPool.MathFin.Probability.Gaussian.GaussianCDFDeriv + +/-! +# The standard normal quantile function `Φ⁻¹` + +`Φ⁻¹` is the quantile function of the standard normal law (`PhiInv`). Mathlib has no inverse of +the normal CDF, so the library's Gaussian risk closed forms (`Risk/Gaussian.lean`) were +written in a quantile parameter `z` with `Φ(z) = α`. Here the parameter becomes a function of the +level. + +Because `Φ` is continuous and strictly increasing, the generalized inverse of +`Probability/Laws/Quantile.lean` is a two-sided inverse: `Φ (Φ⁻¹ p) = p` on `(0, 1)` and +`Φ⁻¹ (Φ x) = x` for every `x`. The quantile of a general Gaussian law then follows from +equivariance under the affine map `z ↦ m + σ z` (`quantile_gaussianReal`). + +## Main definitions + +* `PhiInv`: the standard normal quantile function `Φ⁻¹`, the generalized inverse of `Φ`. + +## Main results + +* `continuous_Phi`, `strictMono_Phi`, `Phi_mem_Ioo`: `Φ` is continuous, strictly increasing + and takes values in `(0, 1)`. Its automation: `continuous_Phi` and `measurable_Phi` are + `fun_prop` lemmas, `Phi_lt_Phi` / `Phi_le_Phi` are `gcongr` lemmas, and `positivity` proves + `0 < Φ x` (`Phi_pos`, `evalPhi`). +* `Phi_PhiInv`, `PhiInv_Phi`: the two inverse identities. +* `PhiInv_one_sub`: symmetry, `Φ⁻¹(1 − p) = −Φ⁻¹(p)`. +* `PhiInv_nonneg_iff`, `PhiInv_pos_iff`: `Φ⁻¹(p)` has the sign of `p − 1/2`. +* `quantile_gaussianReal`: the `p`-quantile of `N(m, σ²)` is `m + σ Φ⁻¹(p)`. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Example 2.11 + +## Tags + +inverse normal CDF, probit function, Gaussian quantile, normal percentile, value-at-risk quantile, +MSC 60E05, MSC 62G30 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set +open scoped NNReal + +variable {p x : ℝ} + +/-- The CDF of the standard normal law is `Φ`. -/ +lemma cdf_gaussianReal_zero_one : ⇑(cdf (gaussianReal 0 1)) = Phi := by + ext x + rw [cdf_eq_real, Phi_def, measureReal_def] + +/-- `Φ` is continuous. -/ +@[fun_prop] lemma continuous_Phi : Continuous Phi := + continuous_iff_continuousAt.2 fun x ↦ (hasDerivAt_Phi x).continuousAt + +/-- `Φ` is measurable. -/ +@[fun_prop] lemma measurable_Phi : Measurable Phi := continuous_Phi.measurable + +/-- `Φ` is strictly increasing: its derivative, the normal density, is positive. -/ +lemma strictMono_Phi : StrictMono Phi := + strictMono_of_hasDerivAt_pos hasDerivAt_Phi fun x ↦ gaussianPDFReal_pos 0 1 x one_ne_zero + +/-- `Φ` takes values in the open unit interval. -/ +lemma Phi_mem_Ioo (x : ℝ) : Phi x ∈ Ioo 0 1 := + ⟨(Phi_nonneg (x - 1)).trans_lt (strictMono_Phi (sub_one_lt x)), + (strictMono_Phi (lt_add_one x)).trans_le (Phi_le_one _)⟩ + +/-- `Φ` is positive. `positivity` proves it (`evalPhi`). -/ +lemma Phi_pos (x : ℝ) : 0 < Phi x := (Phi_mem_Ioo x).1 + +/-- `Φ` is strictly increasing, in the form `gcongr` uses. -/ +@[gcongr] lemma Phi_lt_Phi {x y : ℝ} (h : x < y) : Phi x < Phi y := strictMono_Phi h + +/-- `Φ` is increasing, in the form `gcongr` uses. -/ +@[gcongr] lemma Phi_le_Phi {x y : ℝ} (h : x ≤ y) : Phi x ≤ Phi y := strictMono_Phi.monotone h + +/-- `Φ(0) = 1/2`, by symmetry. -/ +lemma Phi_zero : Phi 0 = 1 / 2 := by + linarith [Phi_add_Phi_neg 0, show Phi (-0) = Phi 0 by rw [neg_zero]] + +/-- The **standard normal quantile function** `Φ⁻¹`. -/ +noncomputable def PhiInv (p : ℝ) : ℝ := + quantile (gaussianReal 0 1) p + +/-- The Galois connection for `Φ⁻¹`: `Φ⁻¹(p) ≤ x ↔ p ≤ Φ(x)`. -/ +theorem PhiInv_le_iff (hp : p ∈ Ioo 0 1) : PhiInv p ≤ x ↔ p ≤ Phi x := by + rw [PhiInv, quantile_le_iff hp, cdf_gaussianReal_zero_one] + +/-- `x < Φ⁻¹(p) ↔ Φ(x) < p`. -/ +theorem lt_PhiInv_iff (hp : p ∈ Ioo 0 1) : x < PhiInv p ↔ Phi x < p := by + rw [PhiInv, lt_quantile_iff hp, cdf_gaussianReal_zero_one] + +/-- `Φ ∘ Φ⁻¹` is the identity on `(0, 1)`. -/ +theorem Phi_PhiInv (hp : p ∈ Ioo 0 1) : Phi (PhiInv p) = p := by + rw [← cdf_gaussianReal_zero_one] + exact cdf_quantile (by rw [cdf_gaussianReal_zero_one]; exact continuous_Phi) hp + +/-- `Φ⁻¹ ∘ Φ` is the identity. -/ +theorem PhiInv_Phi (x : ℝ) : PhiInv (Phi x) = x := by + have h := quantile_cdf (μ := gaussianReal 0 1) (x := x) + (by rw [cdf_gaussianReal_zero_one]; exact strictMono_Phi) + (by rw [cdf_gaussianReal_zero_one]; exact Phi_mem_Ioo x) + rwa [cdf_gaussianReal_zero_one] at h + +/-- `Φ⁻¹` is strictly increasing on `(0, 1)`. -/ +theorem strictMonoOn_PhiInv : StrictMonoOn PhiInv (Ioo 0 1) := fun _ hp _ hq hpq ↦ by + rwa [lt_PhiInv_iff hq, Phi_PhiInv hp] + +/-- **Symmetry of the normal quantile**: `Φ⁻¹(1 − p) = −Φ⁻¹(p)`. -/ +theorem PhiInv_one_sub (hp : p ∈ Ioo 0 1) : PhiInv (1 - p) = -PhiInv p := by + conv_lhs => rw [← Phi_PhiInv hp, ← Phi_neg, PhiInv_Phi] + +/-- The median of the standard normal law is `0`. -/ +theorem PhiInv_half : PhiInv (1 / 2) = 0 := by + rw [← Phi_zero, PhiInv_Phi] + +/-- `Φ⁻¹(p) ≥ 0` exactly when `p ≥ 1/2`. -/ +theorem PhiInv_nonneg_iff (hp : p ∈ Ioo 0 1) : 0 ≤ PhiInv p ↔ 1 / 2 ≤ p := by + rw [← strictMono_Phi.le_iff_le, Phi_PhiInv hp, Phi_zero] + +/-- `Φ⁻¹(p) > 0` exactly when `p > 1/2`. -/ +theorem PhiInv_pos_iff (hp : p ∈ Ioo 0 1) : 0 < PhiInv p ↔ 1 / 2 < p := by + rw [← strictMono_Phi.lt_iff_lt, Phi_PhiInv hp, Phi_zero] + +/-- Every Gaussian law is an affine image of the standard one: +`N(m, v) = (z ↦ √v · z + m)_* N(0, 1)`. -/ +lemma gaussianReal_eq_map_standard (m : ℝ) (v : ℝ≥0) : + gaussianReal m v = (gaussianReal 0 1).map fun z ↦ √(v : ℝ) * z + m := by + rw [show (fun z : ℝ ↦ √(v : ℝ) * z + m) = (· + m) ∘ (√(v : ℝ) * ·) from rfl, + ← Measure.map_map (measurable_add_const m) (measurable_const_mul _), gaussianReal_map_const_mul, + gaussianReal_map_add_const, mul_zero, zero_add, mul_one] + congr + ext + simp + +/-- **The quantile of a Gaussian law**: the `p`-quantile of `N(m, v)` is `m + √v · Φ⁻¹(p)`. -/ +theorem quantile_gaussianReal (m : ℝ) (v : ℝ≥0) (hp : p ∈ Ioo 0 1) : + quantile (gaussianReal m v) p = m + √(v : ℝ) * PhiInv p := by + rw [gaussianReal_eq_map_standard, quantile_map (h := fun z ↦ √(v : ℝ) * z + m) + ((monotone_id.const_mul (by positivity)).add_const m) + (by fun_prop : Continuous fun z : ℝ ↦ √(v : ℝ) * z + m).lowerSemicontinuous hp, + PhiInv, add_comm] + +end MathFin + +namespace Mathlib.Meta.Positivity +open Lean.Meta Qq + +/-- Extension for the `positivity` tactic: the standard normal CDF `Φ` is positive. -/ +@[positivity MathFin.Phi _] +meta def evalPhi : PositivityExt where eval {u α} _ pα? e := + match pα? with | none => pure .none | some _ => do + match u, α, e with + | 0, ~q(ℝ), ~q(MathFin.Phi $a) => + assertInstancesCommute + pure (.positive q(MathFin.Phi_pos $a)) + | _, _, _ => throwError "not Phi" + +end Mathlib.Meta.Positivity diff --git a/LeanPool/MathFin/Probability/Gaussian/NormalTail.lean b/LeanPool/MathFin/Probability/Gaussian/NormalTail.lean new file mode 100644 index 0000000000..ee9e07ac20 --- /dev/null +++ b/LeanPool/MathFin/Probability/Gaussian/NormalTail.lean @@ -0,0 +1,78 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Gaussian.NormalQuantile +public import LeanPool.MathFin.Probability.Gaussian.GaussianPartialMoments +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.Analysis.Real.Pi.Bounds + +/-! # The left tail of the standard normal + +Four facts about `Φ` and the standard normal density `φ` used to bound option prices far from +the money: `Φ(x) → 0` as `x → −∞`, the Mills bound `−x·Φ(x) ≤ φ(x)`, `φ ≤ 1`, and the +Lipschitz bound on `Φ` that follows. + +## Main results + +* `tendsto_Phi_atBot`, `tendsto_Phi_atTop`: `Φ(x) → 0` as `x → −∞` and `Φ(x) → 1` as `x → +∞`. +* `neg_mul_Phi_le_gaussianPDFReal`: `−x·Φ(x) ≤ φ(x)` for all `x`. +* `gaussianPDFReal_zero_one_le_one`: the standard normal density is at most `1`. +* `Phi_sub_le`: `Φ` is 1-Lipschitz, `Φ(y) − Φ(x) ≤ y − x` for `x ≤ y`. + +## Tags + +Mills ratio, normal tail bound, Gaussian tail, deep out-of-the-money option, +standard normal density, MSC 60E15, MSC 91G20 +-/ + +@[expose] public section + +namespace MathFin + +open Filter Topology ProbabilityTheory MeasureTheory + +/-- `Φ` tends to `0` at `−∞`. -/ +theorem tendsto_Phi_atBot : Tendsto Phi atBot (𝓝 0) := + cdf_gaussianReal_zero_one ▸ tendsto_cdf_atBot (gaussianReal 0 1) + +/-- `Φ` tends to `1` at `+∞`. -/ +theorem tendsto_Phi_atTop : Tendsto Phi atTop (𝓝 1) := + cdf_gaussianReal_zero_one ▸ tendsto_cdf_atTop (gaussianReal 0 1) + +/-- **The Mills bound**, in the form `−x·Φ(x) ≤ φ(x)`: the stop-loss value +`𝔼[(Z + x)⁺] = φ(x) + x·Φ(x)` of a standard normal `Z` is nonnegative. -/ +theorem neg_mul_Phi_le_gaussianPDFReal (x : ℝ) : -x * Phi x ≤ gaussianPDFReal 0 1 x := by + have h0 : 0 ≤ ∫ y, max (y - -x) 0 * gaussianPDFReal 0 1 y := + integral_nonneg fun y ↦ mul_nonneg (le_max_right _ _) (gaussianPDFReal_nonneg _ _ _) + rw [integral_max_sub_mul_gaussianPDFReal, gaussianPDFReal_zero_one_neg, Phi_neg] at h0 + linarith + +/-- The standard normal density is at most `1`. -/ +theorem gaussianPDFReal_zero_one_le_one (x : ℝ) : gaussianPDFReal 0 1 x ≤ 1 := by + rw [gaussianPDFReal_def] + simp only [NNReal.coe_one, mul_one, sub_zero] + exact (mul_le_of_le_one_left (Real.exp_pos _).le + (inv_le_one_of_one_le₀ (Real.one_le_sqrt.2 (by nlinarith [Real.pi_gt_three])))).trans + (Real.exp_le_one_iff.2 + (div_nonpos_of_nonpos_of_nonneg (neg_nonpos.2 (sq_nonneg x)) zero_le_two)) + +/-- The standard normal CDF is 1-Lipschitz: `Φ(y) − Φ(x) ≤ y − x` for `x ≤ y` (its density is at +most `1`). -/ +theorem Phi_sub_le {x y : ℝ} (hxy : x ≤ y) : Phi y - Phi x ≤ y - x := by + have h := Convex.norm_image_sub_le_of_norm_deriv_le (f := Phi) (C := 1) (s := Set.univ) + (fun z _ ↦ (hasDerivAt_Phi z).differentiableAt) + (fun z _ ↦ by + rw [(hasDerivAt_Phi z).deriv, Real.norm_eq_abs, + abs_of_nonneg (gaussianPDFReal_nonneg 0 1 z)] + exact gaussianPDFReal_zero_one_le_one z) + convex_univ (Set.mem_univ x) (Set.mem_univ y) + rw [Real.norm_eq_abs, Real.norm_eq_abs, abs_of_nonneg (sub_nonneg.2 hxy)] at h + exact (le_abs_self _).trans (by simpa using h) + +end MathFin diff --git a/LeanPool/MathFin/Probability/Gaussian/StandardGaussianMGF.lean b/LeanPool/MathFin/Probability/Gaussian/StandardGaussianMGF.lean new file mode 100644 index 0000000000..cd98f9cba1 --- /dev/null +++ b/LeanPool/MathFin/Probability/Gaussian/StandardGaussianMGF.lean @@ -0,0 +1,87 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Gaussian.StandardNormal + +/-! +# Standard normal moment-generating function: the one computation in BS + +Every closed-form risk-neutral expectation under the BS lognormal hypothesis +reduces to a single identity: + + `∫ exp(c · Z) ∂N(0,1) = exp(c² / 2)`. + +This is the *moment-generating function (MGF) of the standard normal*. It is +proved in `Probability.Gaussian.StandardNormal` as `integral_exp_mul_gaussianPDFReal_univ` +by completing-the-square (`exp(c · z) · pdf(0, 1, z) = exp(c²/2) · pdf(c, 1, z)`) +followed by integration of the shifted PDF against Lebesgue. + +## How the MGF generates BS pricing + +The standard-normal MGF is enough to derive *every* lognormal moment and +*every* European pricing formula in the BS family. The variations live in two +ancillary moves: + +1. **Affine rescaling**: `S_T = S_0 · exp((r − σ²/2)T + σ√T · Z)` ⟹ exponents + are of the form `α + β · Z`. Use `MGF(β)` plus the constant prefactor `exp(α)`. + +2. **Half-line restriction**: when the payoff vanishes off `{S_T > K}`, + integrate against the right tail (equivalent to multiplying by `Φ(d_i)`). + +| Pricing target | MGF instance | Result | +|---------------------------|---------------------|----------------------------------------------| +| Forward price `E[S_T]` | `β = σ√T` | `S_0 · exp(rT)` | +| `n`-th moment `E[S_T^n]` | `β = n · σ√T` | `S_0^n · exp(n·rT + n(n−1)/2 · σ²T)` | +| Power forward `e^{−rT}·…` | same | `S_0^n · exp((n−1)·rT + n(n−1)/2 · σ²T)` | +| Lognormal variance | derived from `n=2` | `S_0² · exp(2rT) · (exp(σ²T) − 1)` | +| BS call `e^{−rT}·E[(S−K)⁺]`| `β = σ√T`, half-line| `S · Φ(d₁) − K · e^{−rT} · Φ(d₂)` | +| Variance swap log moment | first-moment of Z | `σ² T / 2` (no MGF; linear E[Z]=0) | + +All of these are already proved in this library. This file packages the +*affine-shifted* MGF identity that they share, as a named theorem suitable +for re-use, and serves as a navigational guide to the structural unification. + +## Main results + +* `integral_exp_affine_gaussianPDFReal_univ`: the affine-shifted MGF + `∫ exp(α + β · z) · pdf(0, 1, z) = exp(α + β²/2)`. + +The single-line corollary pattern: each downstream theorem unfolds a payoff +of the form `S_0^k · exp(α + β · Z)`, factors `S_0^k · exp(α)` out, and applies +this identity at `β`. + +## Tags + +moment generating function, lognormal moments, Black–Scholes, Gaussian expectation, +risk-neutral expectation, standard normal, MSC 60E10, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- **Affine-shifted standard-normal MGF** (Lebesgue form): +`∫ exp(α + β · z) · pdf(0, 1, z) dz = exp(α + β²/2)`. + +Direct corollary of the bare MGF `integral_exp_mul_gaussianPDFReal_univ` plus +`exp(α + β·z) = exp(α) · exp(β·z)` and linearity of integration. -/ +lemma integral_exp_affine_gaussianPDFReal_univ (α β : ℝ) : + ∫ z, Real.exp (α + β * z) * gaussianPDFReal 0 1 z = + Real.exp (α + β^2 / 2) := by + -- Factor the integrand: exp(α + β·z) · pdf = exp(α) · (exp(β·z) · pdf). + rw [show (fun z ↦ Real.exp (α + β * z) * gaussianPDFReal 0 1 z) = + (fun z ↦ Real.exp α * (Real.exp (β * z) * gaussianPDFReal 0 1 z)) + from funext (fun z ↦ by rw [Real.exp_add]; ring)] + rw [integral_const_mul, integral_exp_mul_gaussianPDFReal_univ] + -- exp(α) · exp(β²/2) = exp(α + β²/2) + rw [← Real.exp_add] + +end MathFin diff --git a/LeanPool/MathFin/Probability/Gaussian/StandardNormal.lean b/LeanPool/MathFin/Probability/Gaussian/StandardNormal.lean new file mode 100644 index 0000000000..c4b6d3d89f --- /dev/null +++ b/LeanPool/MathFin/Probability/Gaussian/StandardNormal.lean @@ -0,0 +1,230 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Order.CompletePartialOrder +public import Mathlib.Probability.Distributions.Gaussian.Real +public import Mathlib.Topology.Separation.CompletelyRegular + +/-! +# Standard normal primitives: CDF, tail, and the Gaussian MGF + +The pricing-independent core of the Black–Scholes computation: the standard +normal CDF `Φ`, its symmetry and tail identities, the completing-the-square +shift, and the moment-generating function `∫ exp(c·z) ∂N(0,1) = exp(c²/2)`. + +These are **foundations**, not pricing: every closed-form Gaussian +expectation in the BS family (`Call`, `Forward`, the Greeks, the lognormal +moments) reduces to the four lemmas below. They previously lived inside +`Models/BlackScholes/Call.lean` and `Models/BlackScholes/Forward.lean`, which forced the +*Foundations* files that need them (`GaussianCDFDeriv`, `StandardGaussianMGF`) +to import the pricing layer — a layering inversion. Hoisting them here lets +`Call`/`Forward` and the Foundations Gaussian files all build on a common, +pricing-free base. + +## Main definitions + +* `Phi`: the standard normal CDF, `Φ(x) = P(Z ≤ x)` for `Z ~ N(0, 1)`, as the real value of + `gaussianReal 0 1 (Iic x)`. + +## Main results + +* `Phi_neg`, `Phi_add_Phi_neg`, `Phi_le_one`, `Phi_eq_integral` — the reflection `Φ(−x) = 1 − Φ(x)`, + the bound `Φ ≤ 1`, and `Φ` as an integral of the density. +* `setIntegral_gaussianPDFReal_eq_toReal` — the `∫ pdf = N(s).toReal` bridge + every closed-form Gaussian integral factors through. +* `gaussianPDFReal_zero_one_neg` — evenness of the standard-normal density + `ϕ(-z) = ϕ(z)`; `continuous_gaussianPDFReal` — a Gaussian density is continuous. +* `gaussianReal_Ioi_toReal` — the right tail `Q(Ioi a) = Φ(-a)`. +* `exp_mul_gaussianPDFReal_zero_one` — the completing-the-square shift. +* `integral_exp_mul_gaussianPDFReal_Ioi` — the shifted Gaussian tail integral + `∫_{Ioi a} exp(c·z)·pdf = exp(c²/2)·Φ(c − a)` (the asset-payoff primitive). +* `integral_exp_mul_gaussianPDFReal_univ` — the standard-normal MGF + `∫ exp(c·z)·pdf = exp(c²/2)`. + +## Tags + +standard normal CDF, Gaussian tail, moment generating function, completing the square, +normal distribution function, Black–Scholes building block, MSC 60E05, MSC 60E10, MSC 91G20 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal + +/-! ### Standard normal CDF -/ + +/-- The standard normal cumulative distribution function `Φ(x) = P(Z ≤ x)` +where `Z ~ N(0, 1)`. -/ +noncomputable def Phi (x : ℝ) : ℝ := + (gaussianReal 0 1 (Set.Iic x)).toReal + +lemma Phi_def (x : ℝ) : Phi x = (gaussianReal 0 1 (Set.Iic x)).toReal := rfl + +lemma Phi_nonneg (x : ℝ) : 0 ≤ Phi x := ENNReal.toReal_nonneg + +/-- The set-integral of the standard-normal density over a measurable set `s` +equals the (real) Gaussian measure of `s`: `∫_{z ∈ s} ϕ(μ,1,z) dz = N(μ,1)(s)`. +The `.toReal`-of-`gaussianReal` bridge that every closed-form Gaussian integral +factors through (`Phi_eq_integral`, the call/put/digital tails, the MGF shift). -/ +lemma setIntegral_gaussianPDFReal_eq_toReal {s : Set ℝ} (hs : MeasurableSet s) (μ : ℝ) : + ∫ z in s, gaussianPDFReal μ 1 z = (gaussianReal μ 1 s).toReal := by + rw [gaussianReal_apply_eq_integral μ (one_ne_zero : (1 : ℝ≥0) ≠ 0) s] + exact (ENNReal.toReal_ofReal (setIntegral_nonneg hs + (fun _ _ ↦ gaussianPDFReal_nonneg _ _ _))).symm + +/-- `Φ(x)` as the Lebesgue integral of the standard-normal density over `(-∞, x]`. -/ +lemma Phi_eq_integral (x : ℝ) : + Phi x = ∫ z in Set.Iic x, gaussianPDFReal 0 1 z := by + rw [Phi_def, setIntegral_gaussianPDFReal_eq_toReal measurableSet_Iic (0 : ℝ)] + +/-- `Φ(-x) = 1 − Φ(x)`. Symmetry of the standard normal around 0. -/ +lemma Phi_neg (x : ℝ) : Phi (-x) = 1 - Phi x := by + -- Standard normal is symmetric: gaussianReal 0 1 is invariant under negation + have hmap : (gaussianReal (0 : ℝ) 1).map (fun y ↦ -y) = gaussianReal 0 1 := by + rw [gaussianReal_map_neg, neg_zero] + -- Iic(-x) under negation pulls back to Ici x + have h_preimage : (fun y : ℝ ↦ -y) ⁻¹' Set.Iic (-x) = Set.Ici x := by + ext y; simp [Set.mem_Ici] + -- gaussianReal 0 1 (Iic(-x)) = gaussianReal 0 1 (Ici x) + have h_eq : gaussianReal (0 : ℝ) 1 (Set.Iic (-x)) = gaussianReal 0 1 (Set.Ici x) := by + conv_lhs => rw [← hmap] + rw [Measure.map_apply measurable_neg measurableSet_Iic, h_preimage] + -- Ici x and Iio x partition univ; under NullSingletonClass, Q(Iio x) = Q(Iic x) + have h_one_nz : (1 : ℝ≥0) ≠ 0 := one_ne_zero + have : NullSingletonClass (gaussianReal (0 : ℝ) 1) := + nullSingletonClass_gaussianReal h_one_nz + have h_iio_iic : gaussianReal (0 : ℝ) 1 (Set.Iic x) = gaussianReal 0 1 (Set.Iio x) := by + have h_decomp : Set.Iic x = Set.Iio x ∪ {x} := by + ext y; simp [Set.mem_Iic, le_iff_lt_or_eq, eq_comm] + have h_disj : Disjoint (Set.Iio x) ({x} : Set ℝ) := + Set.disjoint_singleton_right.mpr (lt_irrefl x) + rw [h_decomp, measure_union h_disj (measurableSet_singleton _), + measure_singleton, add_zero] + have h_total : gaussianReal (0 : ℝ) 1 (Set.Iio x) + gaussianReal 0 1 (Set.Ici x) + = 1 := by + rw [← measure_union (Set.Iio_disjoint_Ici le_rfl) measurableSet_Ici, + Set.Iio_union_Ici, measure_univ] + -- gaussianReal 0 1 (Iic(-x)) = gaussianReal 0 1 (Ici x) = 1 - gaussianReal 0 1 (Iic x) + rw [Phi_def, h_eq, Phi_def] + have h_iic_finite : gaussianReal (0 : ℝ) 1 (Set.Iic x) ≠ ⊤ := (measure_lt_top _ _).ne + have h_sum : gaussianReal (0 : ℝ) 1 (Set.Iic x) + gaussianReal 0 1 (Set.Ici x) = 1 := by + rw [h_iio_iic]; exact h_total + have h_eq_sub : gaussianReal (0 : ℝ) 1 (Set.Ici x) = 1 - gaussianReal 0 1 (Set.Iic x) := by + refine ENNReal.eq_sub_of_add_eq h_iic_finite ?_ + rw [add_comm]; exact h_sum + rw [h_eq_sub, ENNReal.toReal_sub_of_le (by + rw [show (1 : ℝ≥0∞) = gaussianReal (0 : ℝ) 1 Set.univ from measure_univ.symm] + exact measure_mono (Set.subset_univ _)) (by simp)] + rfl + +/-- `Φ(x) + Φ(-x) = 1`. -/ +lemma Phi_add_Phi_neg (x : ℝ) : Phi x + Phi (-x) = 1 := by + rw [Phi_neg]; ring + +/-- **Standard normal CDF upper bound** `Φ(x) ≤ 1`, from `Φ(x) + Φ(-x) = 1` +and `Φ(-x) ≥ 0`. The pricing-free home of the bound used across the BS price +rectangle (`PriceBounds`) and the KMV-Merton default probability (`KMVMerton`). -/ +lemma Phi_le_one (x : ℝ) : Phi x ≤ 1 := by + have h_sum : Phi x + Phi (-x) = 1 := Phi_add_Phi_neg x + have h_neg : 0 ≤ Phi (-x) := Phi_nonneg _ + linarith + +/-- **Standard normal PDF evenness**: `ϕ(-z) = ϕ(z)`, since the density depends +on `z` only through `z²`. Model-agnostic — consumed by the Greeks and the +put-strike convexity. -/ +lemma gaussianPDFReal_zero_one_neg (z : ℝ) : + gaussianPDFReal 0 1 (-z) = gaussianPDFReal 0 1 z := by + unfold gaussianPDFReal + congr 2 + ring + +/-- A Gaussian density is continuous. -/ +lemma continuous_gaussianPDFReal (μ : ℝ) (v : ℝ≥0) : Continuous (gaussianPDFReal μ v) := by + rw [gaussianPDFReal_def] + fun_prop + +/-! ### Tail probabilities of the standard normal -/ + +/-- `Q(Ioi a) = 1 − Φ(a) = Φ(-a)`. The right tail of the standard normal. -/ +lemma gaussianReal_Ioi_toReal (a : ℝ) : + (gaussianReal 0 1 (Set.Ioi a)).toReal = Phi (-a) := by + have h_compl : Set.Ioi a = (Set.Iic a)ᶜ := by ext y; simp + rw [h_compl, prob_compl_eq_one_sub measurableSet_Iic] + rw [ENNReal.toReal_sub_of_le (by + rw [show (1 : ℝ≥0∞) = gaussianReal (0 : ℝ) 1 Set.univ from measure_univ.symm] + exact measure_mono (Set.subset_univ _)) (by simp)] + rw [Phi_neg, ENNReal.toReal_one, Phi_def] + +/-! ### Completing the square -/ + +/-- The exponential shift identity: `exp(c·z) · gaussianPDFReal 0 1 z = +exp(c²/2) · gaussianPDFReal c 1 z`. This is the algebraic content of +"completing the square" `c·z − z²/2 = c²/2 − (z − c)²/2`. -/ +lemma exp_mul_gaussianPDFReal_zero_one (c z : ℝ) : + Real.exp (c * z) * gaussianPDFReal 0 1 z = + Real.exp (c^2 / 2) * gaussianPDFReal c 1 z := by + unfold gaussianPDFReal + simp only [NNReal.coe_one, mul_one] + have key : c * z + -(z - 0)^2 / 2 = c^2 / 2 + -(z - c)^2 / 2 := by ring + set P : ℝ := (Real.sqrt (2 * π))⁻¹ with P_def + calc Real.exp (c * z) * ((Real.sqrt (2 * π))⁻¹ * Real.exp (-(z - 0)^2 / 2)) + = P * (Real.exp (c * z) * Real.exp (-(z - 0)^2 / 2)) := by rw [P_def]; ring + _ = P * Real.exp (c * z + -(z - 0)^2 / 2) := by rw [Real.exp_add] + _ = P * Real.exp (c^2 / 2 + -(z - c)^2 / 2) := by rw [key] + _ = P * (Real.exp (c^2 / 2) * Real.exp (-(z - c)^2 / 2)) := by rw [Real.exp_add] + _ = Real.exp (c^2 / 2) * ((Real.sqrt (2 * π))⁻¹ * Real.exp (-(z - c)^2 / 2)) := by + rw [P_def]; ring + +/-- The shifted Gaussian tail integral — the core BS computational primitive: + `∫ z in Ioi a, exp(c·z) · gaussianPDFReal 0 1 z dz = exp(c²/2) · Φ(c − a)`. + +Combines `exp_mul_gaussianPDFReal_zero_one` (algebraic completing-the-square) +with `gaussianReal_map_add_const` (push forward via shift). -/ +lemma integral_exp_mul_gaussianPDFReal_Ioi (a c : ℝ) : + ∫ z in Set.Ioi a, Real.exp (c * z) * gaussianPDFReal 0 1 z + = Real.exp (c^2 / 2) * Phi (c - a) := by + rw [setIntegral_congr_fun measurableSet_Ioi + (fun z _ ↦ exp_mul_gaussianPDFReal_zero_one c z), integral_const_mul] + congr 1 + have h_int_eq : ∫ z in Set.Ioi a, gaussianPDFReal c 1 z + = (gaussianReal c (1 : ℝ≥0) (Set.Ioi a)).toReal := + setIntegral_gaussianPDFReal_eq_toReal measurableSet_Ioi c + have h_shift : gaussianReal c (1 : ℝ≥0) (Set.Ioi a) = + gaussianReal 0 1 (Set.Ioi (a - c)) := by + have hmap : (gaussianReal (0 : ℝ) 1).map (fun y ↦ y + c) = gaussianReal c 1 := by + rw [gaussianReal_map_add_const, zero_add] + rw [← hmap, Measure.map_apply (by fun_prop) measurableSet_Ioi] + congr 1; ext y; simp [Set.mem_Ioi, sub_lt_iff_lt_add, add_comm] + rw [h_int_eq, h_shift, gaussianReal_Ioi_toReal, neg_sub] + +/-! ### Standard-normal moment generating function -/ + +/-- **MGF of the standard normal**: `∫ z, exp(c·z) · pdf(0,1,z) dz = exp(c²/2)`. + +Combines `exp_mul_gaussianPDFReal_zero_one` (completing-the-square) with +Mathlib's `integral_gaussianPDFReal_eq_one`. + +Mathlib's `mgf_gaussianReal` gives the same value as an integral against the +`gaussianReal` *measure*; this is the explicit Lebesgue/pdf form the Black–Scholes +integrals consume directly, and the completing-the-square shift it factors through +(`exp_mul_gaussianPDFReal_zero_one`) plus the truncated `Ioi` sibling above are the +load-bearing primitives with no Mathlib analogue. -/ +lemma integral_exp_mul_gaussianPDFReal_univ (c : ℝ) : + ∫ z, Real.exp (c * z) * gaussianPDFReal 0 1 z = Real.exp (c^2 / 2) := by + rw [show (fun z ↦ Real.exp (c * z) * gaussianPDFReal 0 1 z) + = (fun z ↦ Real.exp (c^2 / 2) * gaussianPDFReal c 1 z) from + funext (exp_mul_gaussianPDFReal_zero_one c), + integral_const_mul, + integral_gaussianPDFReal_eq_one c (one_ne_zero : (1 : ℝ≥0) ≠ 0), mul_one] + +end MathFin diff --git a/LeanPool/MathFin/Probability/Gaussian/WeakForwardUniqueness.lean b/LeanPool/MathFin/Probability/Gaussian/WeakForwardUniqueness.lean new file mode 100644 index 0000000000..6bca60e67b --- /dev/null +++ b/LeanPool/MathFin/Probability/Gaussian/WeakForwardUniqueness.lean @@ -0,0 +1,540 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.Analysis.CStarAlgebra.Classes +public import Mathlib.Analysis.Calculus.Deriv.Prod +public import Mathlib.Analysis.ODE.Gronwall +public import Mathlib.MeasureTheory.Measure.CharacteristicFunction.Basic + +/-! +# Weak uniqueness for the constant-coefficient forward equation + +`IsWeakForwardFlow afn bfn T ρ` says that a flow of probability measures `ρ : ℝ → Measure ℝ` +solves, on `[0, T]`, the integrated weak forward equation with coefficient functions `afn`, +`bfn : ℝ → ℝ → ℝ`: for every test `g` whose first three derivatives are bounded, + +`∫ g dρ s = ∫ g dρ 0 + ∫ x in 0..s, (∫ g' · afn x dρ x + ½ ∫ g'' · bfn x dρ x)`, + +and the generator integrand is interval-integrable (so the interval integral is not a junk +value). This is the hypothesis that `MathFin.GyongyMimicry.gyongy_mimicry_gated` states for +the two flows its flow-uniqueness hypothesis `hgate` compares. + +`weakForwardUniqueConst` is the constant-coefficient case (`afn ≡ b`, `bfn ≡ v`): two such +flows with `ρ 0 = η 0` coincide on `(0, T]`. It is the statement `hgate` asks for, proved +for constant coefficients. The proof pairs both flows against `cos(ξ·)` and `sin(ξ·)`; the +pairing differences solve a linear system with zero initial value, which Grönwall's +inequality forces to vanish, so the flows have equal characteristic functions +(`MeasureTheory.Measure.ext_of_charFun`). + +## Main definitions + +* `IsWeakForwardFlow`: a flow of probability measures `ρ` solves, on `[0, T]`, the integrated + weak forward equation with coefficient functions `afn`, `bfn`, tested against `g` with + bounded first three derivatives, with interval-integrable generator integrand. + +## Main results + +* `weakForwardUniqueConst`: two flows solving `IsWeakForwardFlow` with the same constant + coefficients `b` and `v` and the same initial law coincide at every time `s ∈ (0, T]`. + +## References + +* [I. Karatzas and S. E. Shreve, *Brownian Motion and Stochastic Calculus*][KaratzasShreve1991] +* [Stroock and Varadhan, *Multidimensional Diffusion Processes*][StroockVaradhan1979] + +## Tags + +Fokker–Planck equation, weak forward equation, uniqueness of flows, Gyöngy mimicking, +characteristic function, Grönwall inequality, MSC 60J60, MSC 60E10, MSC 35K10 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory + +/-- `ρ` is a flow of probability measures solving, on `[0, T]`, the integrated weak forward +equation with coefficient functions `afn`, `bfn`, for every test `g` with `HasDerivAt` chain +`g, g', g'', g'''` and bounded `g', g'', g'''`. The generator integrand is required to be +interval-integrable, so the interval integral in the identity is a genuine one. -/ +def IsWeakForwardFlow (afn bfn : ℝ → ℝ → ℝ) (T : ℝ) (ρ : ℝ → Measure ℝ) : Prop := + (∀ s, IsProbabilityMeasure (ρ s)) ∧ + ∀ (g g' g'' g''' : ℝ → ℝ) (C1 C2 C3 : ℝ), + (∀ x, HasDerivAt g (g' x) x) → (∀ x, HasDerivAt g' (g'' x) x) → + (∀ x, HasDerivAt g'' (g''' x) x) → + (∀ x, |g' x| ≤ C1) → (∀ x, |g'' x| ≤ C2) → (∀ x, |g''' x| ≤ C3) → + ∀ s ∈ Set.Ioc 0 T, + (∫ y, g y ∂(ρ s) = ∫ y, g y ∂(ρ 0) + + ∫ x in (0)..s, + ((∫ y, g' y * afn x y ∂(ρ x)) + 1 / 2 * (∫ y, g'' y * bfn x y ∂(ρ x)))) ∧ + IntervalIntegrable + (fun x => (∫ y, g' y * afn x y ∂(ρ x)) + 1 / 2 * (∫ y, g'' y * bfn x y ∂(ρ x))) + volume 0 s + +/-- The constant-coefficient identity of `IsWeakForwardFlow`, with the constants pulled out +of the pairings. -/ +private lemma IsWeakForwardFlow.const_identity {b v T : ℝ} {ρ : ℝ → Measure ℝ} + (hρ : IsWeakForwardFlow (fun _ _ ↦ b) (fun _ _ ↦ v) T ρ) + {g g' g'' g''' : ℝ → ℝ} {C1 C2 C3 : ℝ} + (h1 : ∀ x, HasDerivAt g (g' x) x) (h2 : ∀ x, HasDerivAt g' (g'' x) x) + (h3 : ∀ x, HasDerivAt g'' (g''' x) x) + (hb1 : ∀ x, |g' x| ≤ C1) (hb2 : ∀ x, |g'' x| ≤ C2) (hb3 : ∀ x, |g''' x| ≤ C3) + {s : ℝ} (hs : s ∈ Set.Ioc 0 T) : + (∫ y, g y ∂(ρ s) = ∫ y, g y ∂(ρ 0) + + ∫ r in (0)..s, (b * ∫ y, g' y ∂(ρ r) + v / 2 * ∫ y, g'' y ∂(ρ r))) ∧ + IntervalIntegrable + (fun r => b * ∫ y, g' y ∂(ρ r) + v / 2 * ∫ y, g'' y ∂(ρ r)) volume 0 s := by + have hw : (fun r => (∫ y, g' y * b ∂(ρ r)) + 1 / 2 * (∫ y, g'' y * v ∂(ρ r))) + = fun r => b * ∫ y, g' y ∂(ρ r) + v / 2 * ∫ y, g'' y ∂(ρ r) := + funext fun r => by rw [integral_mul_const, integral_mul_const]; ring + simpa only [hw] using hρ.2 g g' g'' g''' C1 C2 C3 h1 h2 h3 hb1 hb2 hb3 s hs + +/-! ### The pairing layer + +Against a probability measure, the pairing with a bounded function is bounded +by the sup bound; the integrated identity then makes every admissible +pairing Lipschitz-continuous in time. -/ + +/-- The increment of an admissible pairing over an interval, both endpoints in +`[0, T]`: the difference of pairings is the oriented integral of the pairing +integrand. -/ +private lemma pairing_increment {b v T : ℝ} {ρ : ℝ → Measure ℝ} + (hρ : IsWeakForwardFlow (fun _ _ ↦ b) (fun _ _ ↦ v) T ρ) + {g g' g'' g''' : ℝ → ℝ} {C1 C2 C3 : ℝ} + (h1 : ∀ x, HasDerivAt g (g' x) x) (h2 : ∀ x, HasDerivAt g' (g'' x) x) + (h3 : ∀ x, HasDerivAt g'' (g''' x) x) + (hb1 : ∀ x, |g' x| ≤ C1) (hb2 : ∀ x, |g'' x| ≤ C2) + (hb3 : ∀ x, |g''' x| ≤ C3) + {s₀ s : ℝ} (hs₀ : s₀ ∈ Set.Icc 0 T) (hs : s ∈ Set.Icc 0 T) : + ∫ y, g y ∂(ρ s) - ∫ y, g y ∂(ρ s₀) + = ∫ r in s₀..s, (b * ∫ y, g' y ∂(ρ r) + v / 2 * ∫ y, g'' y ∂(ρ r)) := by + set w : ℝ → ℝ := fun r => b * ∫ y, g' y ∂(ρ r) + v / 2 * ∫ y, g'' y ∂(ρ r) + have ident : ∀ u ∈ Set.Ioc 0 T, + ∫ y, g y ∂(ρ u) = ∫ y, g y ∂(ρ 0) + ∫ r in (0)..u, w r ∧ + IntervalIntegrable w volume 0 u := fun u hu => + hρ.const_identity h1 h2 h3 hb1 hb2 hb3 hu + have interior : ∀ {u₁ u₂ : ℝ}, 0 < u₁ → 0 < u₂ → u₁ ≤ T → u₂ ≤ T → + ∫ y, g y ∂(ρ u₂) - ∫ y, g y ∂(ρ u₁) = ∫ r in u₁..u₂, w r := by + intro u₁ u₂ hu₁ hu₂ hu₁T hu₂T + have hI1 := ident u₁ ⟨hu₁, hu₁T⟩ + have hI2 := ident u₂ ⟨hu₂, hu₂T⟩ + rcases le_total u₂ u₁ with hle | hle + · have hsub : IntervalIntegrable w volume u₂ u₁ := hI1.2.mono_set + (Set.uIcc_subset_uIcc (Set.mem_uIcc_of_le (le_of_lt hu₂) hle) + (Set.mem_uIcc_of_le (le_of_lt hu₁) le_rfl)) + have hadd := intervalIntegral.integral_add_adjacent_intervals hI2.2 hsub + rw [hI2.1, hI1.1, ← hadd, intervalIntegral.integral_symm u₂ u₁] + ring + · have hsub : IntervalIntegrable w volume u₁ u₂ := hI2.2.mono_set + (Set.uIcc_subset_uIcc (Set.mem_uIcc_of_le (le_of_lt hu₁) hle) + (Set.mem_uIcc_of_le (le_of_lt hu₂) le_rfl)) + have hadd := intervalIntegral.integral_add_adjacent_intervals hI1.2 hsub + rw [hI2.1, hI1.1, ← hadd] + ring + rcases eq_or_lt_of_le hs₀.1 with h0 | h0pos + · subst h0 + rcases eq_or_lt_of_le hs.1 with h1eq | h1pos + · subst h1eq; rw [sub_self, intervalIntegral.integral_same] + · linarith [(ident s ⟨h1pos, hs.2⟩).1] + · rcases eq_or_lt_of_le hs.1 with h1eq | h1pos + · subst h1eq + have hI1 := ident s₀ ⟨h0pos, hs₀.2⟩ + have hsym : (∫ r in s₀..(0:ℝ), w r) = -(∫ r in (0)..s₀, w r) := + intervalIntegral.integral_symm 0 s₀ + rw [hI1.1, hsym] + ring + · exact interior h0pos h1pos hs₀.2 hs.2 + +/-- The pairing of an admissible test is Lipschitz in time on `[0, T]`: the +pairing increment is an interval integral of an integrand bounded by +`|b| * C1 + |v| / 2 * C2` (via `norm_integral_le_of_norm_le_const` on each of the two pieces). -/ +private lemma abs_pairing_lipschitz {b v T : ℝ} {ρ : ℝ → Measure ℝ} + (hρ : IsWeakForwardFlow (fun _ _ ↦ b) (fun _ _ ↦ v) T ρ) + {g g' g'' g''' : ℝ → ℝ} {C1 C2 C3 : ℝ} + (h1 : ∀ x, HasDerivAt g (g' x) x) (h2 : ∀ x, HasDerivAt g' (g'' x) x) + (h3 : ∀ x, HasDerivAt g'' (g''' x) x) + (hb1 : ∀ x, |g' x| ≤ C1) (hb2 : ∀ x, |g'' x| ≤ C2) + (hb3 : ∀ x, |g''' x| ≤ C3) + {s₀ s : ℝ} (hs₀ : s₀ ∈ Set.Icc 0 T) (hs : s ∈ Set.Icc 0 T) : + |∫ y, g y ∂(ρ s) - ∫ y, g y ∂(ρ s₀)| ≤ (|b| * C1 + |v| / 2 * C2) * |s - s₀| := by + rw [pairing_increment hρ h1 h2 h3 hb1 hb2 hb3 hs₀ hs, ← Real.norm_eq_abs] + refine intervalIntegral.norm_integral_le_of_norm_le_const (fun r _ => ?_) + rw [Real.norm_eq_abs] + have := hρ.1 r + have hb1' : |∫ y, g' y ∂(ρ r)| ≤ C1 := by + simpa using norm_integral_le_of_norm_le_const (μ := ρ r) (f := g') (ae_of_all _ hb1) + have hb2' : |∫ y, g'' y ∂(ρ r)| ≤ C2 := by + simpa using norm_integral_le_of_norm_le_const (μ := ρ r) (f := g'') (ae_of_all _ hb2) + calc |b * ∫ y, g' y ∂(ρ r) + v / 2 * ∫ y, g'' y ∂(ρ r)| + ≤ |b * ∫ y, g' y ∂(ρ r)| + |v / 2 * ∫ y, g'' y ∂(ρ r)| := abs_add_le _ _ + _ = |b| * |∫ y, g' y ∂(ρ r)| + |v / 2| * |∫ y, g'' y ∂(ρ r)| := by rw [abs_mul, abs_mul] + _ ≤ |b| * C1 + |v| / 2 * C2 := by + rw [show |v / 2| = |v| / 2 by rw [abs_div, abs_two]] + exact add_le_add (mul_le_mul_of_nonneg_left hb1' (abs_nonneg b)) + (mul_le_mul_of_nonneg_left hb2' (by positivity)) + +/-- Two flows' pairing differences against the same admissible test are Lipschitz, with +twice the single-flow constant: the shared triangle-inequality step behind both `hUlip` and +`hWlip` in `pairing_cos_sin_eq`. -/ +private lemma diff_pairing_lipschitz {b v T : ℝ} {ρ η : ℝ → Measure ℝ} + (hρ : IsWeakForwardFlow (fun _ _ ↦ b) (fun _ _ ↦ v) T ρ) + (hη : IsWeakForwardFlow (fun _ _ ↦ b) (fun _ _ ↦ v) T η) + {g g' g'' g''' : ℝ → ℝ} {C1 C2 C3 : ℝ} + (h1 : ∀ x, HasDerivAt g (g' x) x) (h2 : ∀ x, HasDerivAt g' (g'' x) x) + (h3 : ∀ x, HasDerivAt g'' (g''' x) x) + (hb1 : ∀ x, |g' x| ≤ C1) (hb2 : ∀ x, |g'' x| ≤ C2) + (hb3 : ∀ x, |g''' x| ≤ C3) + {s₀ s : ℝ} (hs₀ : s₀ ∈ Set.Icc (0 : ℝ) T) (hs : s ∈ Set.Icc (0 : ℝ) T) : + |((∫ y, g y ∂(ρ s)) - ∫ y, g y ∂(η s)) - ((∫ y, g y ∂(ρ s₀)) - ∫ y, g y ∂(η s₀))| + ≤ 2 * (|b| * C1 + |v| / 2 * C2) * |s - s₀| := by + have h1' := abs_pairing_lipschitz hρ h1 h2 h3 hb1 hb2 hb3 hs₀ hs + have h2' := abs_pairing_lipschitz hη h1 h2 h3 hb1 hb2 hb3 hs₀ hs + calc |((∫ y, g y ∂(ρ s)) - ∫ y, g y ∂(η s)) - ((∫ y, g y ∂(ρ s₀)) - ∫ y, g y ∂(η s₀))| + = |((∫ y, g y ∂(ρ s)) - ∫ y, g y ∂(ρ s₀)) - ((∫ y, g y ∂(η s)) - ∫ y, g y ∂(η s₀))| := by + congr 1; ring + _ ≤ |(∫ y, g y ∂(ρ s)) - ∫ y, g y ∂(ρ s₀)| + |(∫ y, g y ∂(η s)) - ∫ y, g y ∂(η s₀)| := + abs_sub _ _ + _ ≤ (|b| * C1 + |v| / 2 * C2) * |s - s₀| + (|b| * C1 + |v| / 2 * C2) * |s - s₀| := + add_le_add h1' h2' + _ = 2 * (|b| * C1 + |v| / 2 * C2) * |s - s₀| := by ring + +/-- A function Lipschitz on `[0, T]` (with a known-nonnegative constant) is continuous +there: the `ε`-`δ` argument shared by every Lipschitz-from-a-pairing-identity bound in +this file. -/ +lemma continuousOn_Icc_of_abs_sub_le_mul_abs_sub {f : ℝ → ℝ} {T L : ℝ} + (hLip : ∀ s₀ s, s₀ ∈ Set.Icc (0 : ℝ) T → s ∈ Set.Icc (0 : ℝ) T → + |f s - f s₀| ≤ L * |s - s₀|) : + ContinuousOn f (Set.Icc 0 T) := + (LipschitzOnWith.of_dist_le' (K := L) fun s₀ hs₀ s hs => by + simpa [Real.dist_eq, abs_sub_comm] using hLip s₀ s hs₀ hs).continuousOn + +/-- The generator's linear combination against a frequency, bounded by the sup-norm: the +shared triangle-inequality step behind both components of `hFbound` in `pairing_cos_sin_eq` +(the `ℝ × ℝ` Grönwall bound `‖F' x‖ ≤ K * ‖F x‖`). -/ +lemma abs_mul_add_mul_sq_le_mul_max (b v ξ p q : ℝ) : + |b * ξ * p + v / 2 * ξ ^ 2 * q| ≤ (|b| * |ξ| + |v| / 2 * ξ ^ 2) * max |p| |q| := by + have hp : |p| ≤ max |p| |q| := le_max_left _ _ + have hq : |q| ≤ max |p| |q| := le_max_right _ _ + calc |b * ξ * p + v / 2 * ξ ^ 2 * q| + ≤ |b * ξ * p| + |v / 2 * ξ ^ 2 * q| := abs_add_le _ _ + _ = |b| * |ξ| * |p| + |v| / 2 * ξ ^ 2 * |q| := by + rw [abs_mul, abs_mul, abs_mul, abs_mul, show |v / 2| = |v| / 2 by rw [abs_div, abs_two], + abs_of_nonneg (sq_nonneg ξ)] + _ ≤ |b| * |ξ| * max |p| |q| + |v| / 2 * ξ ^ 2 * max |p| |q| := + add_le_add (mul_le_mul_of_nonneg_left hp (by positivity)) + (mul_le_mul_of_nonneg_left hq (by positivity)) + _ = (|b| * |ξ| + |v| / 2 * ξ ^ 2) * max |p| |q| := by ring + +/-! ### Trigonometric test chains + +`cos(ξ·)` and `sin(ξ·)` have constant-coefficient derivative chains: the +generator `b · (·)' + v/2 · (·)''` maps each to a linear combination of the +other, with no new functions appearing — the algebraic fact that drives the +Volterra system in `pairing_cos_sin_eq`. -/ + +/-- The derivative of `x ↦ cos (ξ * x)` is `-ξ * sin (ξ * x)`. -/ +lemma hasDerivAt_cos_const_mul (ξ x : ℝ) : + HasDerivAt (fun x => Real.cos (ξ * x)) (-ξ * Real.sin (ξ * x)) x := + ((Real.hasDerivAt_cos (ξ * x)).comp x (hasDerivAt_const_mul ξ)).congr_deriv (by ring) + +/-- The derivative of `x ↦ -ξ * sin (ξ * x)` is `-ξ ^ 2 * cos (ξ * x)`. -/ +lemma hasDerivAt_neg_mul_sin_const_mul (ξ x : ℝ) : + HasDerivAt (fun x => -ξ * Real.sin (ξ * x)) (-ξ ^ 2 * Real.cos (ξ * x)) x := + (((Real.hasDerivAt_sin (ξ * x)).comp x (hasDerivAt_const_mul ξ)).const_mul (-ξ)).congr_deriv + (by ring) + +/-- The derivative of `x ↦ -ξ ^ 2 * cos (ξ * x)` is `ξ ^ 3 * sin (ξ * x)`. -/ +lemma hasDerivAt_neg_sq_mul_cos_const_mul (ξ x : ℝ) : + HasDerivAt (fun x => -ξ ^ 2 * Real.cos (ξ * x)) (ξ ^ 3 * Real.sin (ξ * x)) x := + (((Real.hasDerivAt_cos (ξ * x)).comp x (hasDerivAt_const_mul ξ)).const_mul + (-ξ ^ 2)).congr_deriv (by ring) + +/-- The derivative of `x ↦ sin (ξ * x)` is `ξ * cos (ξ * x)`. -/ +lemma hasDerivAt_sin_const_mul (ξ x : ℝ) : + HasDerivAt (fun x => Real.sin (ξ * x)) (ξ * Real.cos (ξ * x)) x := + ((Real.hasDerivAt_sin (ξ * x)).comp x (hasDerivAt_const_mul ξ)).congr_deriv (by ring) + +/-- The derivative of `x ↦ ξ * cos (ξ * x)` is `-ξ ^ 2 * sin (ξ * x)`. -/ +lemma hasDerivAt_mul_cos_const_mul (ξ x : ℝ) : + HasDerivAt (fun x => ξ * Real.cos (ξ * x)) (-ξ ^ 2 * Real.sin (ξ * x)) x := + (((Real.hasDerivAt_cos (ξ * x)).comp x (hasDerivAt_const_mul ξ)).const_mul ξ).congr_deriv + (by ring) + +/-- The derivative of `x ↦ -ξ ^ 2 * sin (ξ * x)` is `-ξ ^ 3 * cos (ξ * x)`. -/ +lemma hasDerivAt_neg_sq_mul_sin_const_mul (ξ x : ℝ) : + HasDerivAt (fun x => -ξ ^ 2 * Real.sin (ξ * x)) (-ξ ^ 3 * Real.cos (ξ * x)) x := + (((Real.hasDerivAt_sin (ξ * x)).comp x (hasDerivAt_const_mul ξ)).const_mul + (-ξ ^ 2)).congr_deriv (by ring) + +/-- The sup bounds for the `cos(ξ·)` derivative chain, bundled: `C1 = |ξ|`, `C2 = ξ²`, +`C3 = |ξ|³`. -/ +lemma abs_cos_derivative_chain_le (ξ : ℝ) : + (∀ y : ℝ, |(-ξ) * Real.sin (ξ * y)| ≤ |ξ|) ∧ + (∀ y : ℝ, |(-ξ ^ 2) * Real.cos (ξ * y)| ≤ ξ ^ 2) ∧ + (∀ y : ℝ, |ξ ^ 3 * Real.sin (ξ * y)| ≤ |ξ| ^ 3) := by + refine ⟨fun y => ?_, fun y => ?_, fun y => ?_⟩ + · rw [abs_mul]; simpa using mul_le_mul_of_nonneg_left (Real.abs_sin_le_one _) (abs_nonneg ξ) + · rw [abs_mul, abs_neg, abs_of_nonneg (sq_nonneg ξ)] + exact (mul_le_mul_of_nonneg_left (Real.abs_cos_le_one _) (sq_nonneg ξ)).trans_eq (mul_one _) + · rw [abs_mul, abs_pow] + exact (mul_le_mul_of_nonneg_left (Real.abs_sin_le_one _) (by positivity)).trans_eq (mul_one _) + +/-- The sup bounds for the `sin(ξ·)` derivative chain, bundled: same constants as +`abs_cos_derivative_chain_le`. -/ +lemma abs_sin_derivative_chain_le (ξ : ℝ) : + (∀ y : ℝ, |ξ * Real.cos (ξ * y)| ≤ |ξ|) ∧ + (∀ y : ℝ, |(-ξ ^ 2) * Real.sin (ξ * y)| ≤ ξ ^ 2) ∧ + (∀ y : ℝ, |(-ξ ^ 3) * Real.cos (ξ * y)| ≤ |ξ| ^ 3) := by + refine ⟨fun y => ?_, fun y => ?_, fun y => ?_⟩ + · rw [abs_mul]; simpa using mul_le_mul_of_nonneg_left (Real.abs_cos_le_one _) (abs_nonneg ξ) + · rw [abs_mul, abs_neg, abs_of_nonneg (sq_nonneg ξ)] + exact (mul_le_mul_of_nonneg_left (Real.abs_sin_le_one _) (sq_nonneg ξ)).trans_eq (mul_one _) + · rw [abs_mul, abs_neg, abs_pow] + exact (mul_le_mul_of_nonneg_left (Real.abs_cos_le_one _) (by positivity)).trans_eq (mul_one _) + +/-! ### Localizing the fundamental theorem of calculus to `[0, T]` + +The pairing identity is only known on `[0, T]`; to differentiate a Volterra +primitive from the right at a point `x ∈ [0, T)` it suffices that the +integrand be continuous *near `x` within `[0, T]`* — `HasDerivWithinAt` only +sees the germ of the function within the target set, so continuity on `[0, +T]` already supplies everything `integral_hasDerivWithinAt_right` needs at +the one-sided filters `Ici x` / `Ioi x`. -/ + +/-- The primitive `u ↦ ∫ r in 0..u, h r` of a function continuous on `[0, T]` has right derivative +`h x` at each `x ∈ [0, T)`. -/ +lemma hasDerivWithinAt_Ici_of_continuousOn {h : ℝ → ℝ} {x T : ℝ} + (hcont : ContinuousOn h (Set.Icc 0 T)) (hx0 : 0 ≤ x) (hxT : x < T) : + HasDerivWithinAt (fun u => ∫ r in (0 : ℝ)..u, h r) (h x) (Set.Ici x) x := by + have hmemx : x ∈ Set.Icc (0 : ℝ) T := ⟨hx0, hxT.le⟩ + have hmem : Set.Icc (0 : ℝ) T ∈ nhdsWithin x (Set.Ioi x) := + Icc_mem_nhdsGT_of_mem ⟨hx0, hxT⟩ + have hmeas : StronglyMeasurableAtFilter h (nhdsWithin x (Set.Ioi x)) := + ⟨Set.Icc 0 T, hmem, hcont.aestronglyMeasurable measurableSet_Icc⟩ + have hb : ContinuousWithinAt h (Set.Ioi x) x := by + have h1 : ContinuousWithinAt h (Set.Icc 0 T) x := hcont x hmemx + have h2 : ContinuousWithinAt h (Set.Ioi x ∩ Set.Icc 0 T) x := + h1.mono Set.inter_subset_right + exact (continuousWithinAt_inter' hmem).mp h2 + have hintg : IntervalIntegrable h volume 0 x := + ContinuousOn.intervalIntegrable_of_Icc hx0 (hcont.mono (Set.Icc_subset_Icc_right hxT.le)) + exact intervalIntegral.integral_hasDerivWithinAt_right hintg hmeas hb + +/-- A function equal to its own Volterra primitive on `[0, T]` is right-differentiable there, +with derivative the (continuous) generator value: combines +`hasDerivWithinAt_Ici_of_continuousOn` (the primitive's own derivative) with the +`=ᶠ[𝓝[Ici x] x]` transfer from the primitive identity — the shared step behind both +`hCderiv` and `hSderiv` in `hasDerivWithinAt_cosPairing_sinPairing`. -/ +lemma hasDerivWithinAt_of_volterra_primitive {g h : ℝ → ℝ} {x T : ℝ} + (hcont : ContinuousOn h (Set.Icc 0 T)) (hx0 : 0 ≤ x) (hxT : x < T) + (hprim : ∀ s ∈ Set.Icc (0 : ℝ) T, g s = g 0 + ∫ r in (0 : ℝ)..s, h r) : + HasDerivWithinAt g (h x) (Set.Ici x) x := by + have hderiv0 : HasDerivWithinAt (fun u => ∫ r in (0 : ℝ)..u, h r) (h x) (Set.Ici x) x := + hasDerivWithinAt_Ici_of_continuousOn hcont hx0 hxT + have heq : g =ᶠ[nhdsWithin x (Set.Ici x)] (fun s => g 0 + ∫ r in (0 : ℝ)..s, h r) := + Filter.eventually_of_mem (Icc_mem_nhdsGE_of_mem ⟨hx0, hxT⟩) hprim + exact (hderiv0.const_add (g 0)).congr_of_eventuallyEq_of_mem heq (le_refl x) + +/-- An admissible pairing is the Volterra primitive of its generator value, once the +generator is recognized as a named function `h`: the shared `pairing_increment` + generator +rewrite step behind both `hCprim` and `hSprim` in `hasDerivWithinAt_cosPairing_sinPairing`. -/ +private lemma pairing_volterra_primitive {b v T : ℝ} {μ : ℝ → Measure ℝ} + (hμ : IsWeakForwardFlow (fun _ _ ↦ b) (fun _ _ ↦ v) T μ) (hT : 0 < T) + {g g' g'' g''' : ℝ → ℝ} {C1 C2 C3 : ℝ} + (h1 : ∀ x, HasDerivAt g (g' x) x) (h2 : ∀ x, HasDerivAt g' (g'' x) x) + (h3 : ∀ x, HasDerivAt g'' (g''' x) x) + (hb1 : ∀ x, |g' x| ≤ C1) (hb2 : ∀ x, |g'' x| ≤ C2) + (hb3 : ∀ x, |g''' x| ≤ C3) (h : ℝ → ℝ) + (hheq : ∀ r, h r = b * ∫ y, g' y ∂(μ r) + v / 2 * ∫ y, g'' y ∂(μ r)) : + ∀ s ∈ Set.Icc (0 : ℝ) T, + (∫ y, g y ∂(μ s)) = (∫ y, g y ∂(μ 0)) + ∫ r in (0 : ℝ)..s, h r := by + intro s hs + have hinc := pairing_increment hμ h1 h2 h3 hb1 hb2 hb3 (Set.left_mem_Icc.mpr hT.le) hs + have hcongr : (∫ r in (0 : ℝ)..s, + (b * ∫ y, g' y ∂(μ r) + v / 2 * ∫ y, g'' y ∂(μ r))) = ∫ r in (0 : ℝ)..s, h r := + intervalIntegral.integral_congr fun r _ => (hheq r).symm + rw [hcongr] at hinc + linarith [hinc] + +/-! ### The Volterra system at a fixed frequency -/ + +/-- For a flow obeying the weak forward equation with constant coefficients, +the pairings against `cos(ξ·)` and `sin(ξ·)` are right-differentiable on `[0, +T)`, with derivatives given by the generator applied to the paired +trigonometric test. -/ +private lemma hasDerivWithinAt_cosPairing_sinPairing {b v T : ℝ} {μ : ℝ → Measure ℝ} + (hμ : IsWeakForwardFlow (fun _ _ ↦ b) (fun _ _ ↦ v) T μ) (ξ x : ℝ) (hx0 : 0 ≤ x) + (hxT : x < T) : + HasDerivWithinAt (fun s => ∫ y, Real.cos (ξ * y) ∂(μ s)) + (-b * ξ * (∫ y, Real.sin (ξ * y) ∂(μ x)) - v / 2 * ξ ^ 2 * (∫ y, Real.cos (ξ * y) ∂(μ x))) + (Set.Ici x) x ∧ + HasDerivWithinAt (fun s => ∫ y, Real.sin (ξ * y) ∂(μ s)) + (b * ξ * (∫ y, Real.cos (ξ * y) ∂(μ x)) - v / 2 * ξ ^ 2 * (∫ y, Real.sin (ξ * y) ∂(μ x))) + (Set.Ici x) x := by + have hT : 0 < T := hx0.trans_lt hxT + obtain ⟨hb1, hb2, hb3⟩ := abs_cos_derivative_chain_le ξ + obtain ⟨hb1', hb2', hb3'⟩ := abs_sin_derivative_chain_le ξ + have hCcont : ContinuousOn (fun s => ∫ y, Real.cos (ξ * y) ∂(μ s)) (Set.Icc 0 T) := + continuousOn_Icc_of_abs_sub_le_mul_abs_sub fun s₀ s hs₀ hs => + abs_pairing_lipschitz hμ (hasDerivAt_cos_const_mul ξ) (hasDerivAt_neg_mul_sin_const_mul ξ) + (hasDerivAt_neg_sq_mul_cos_const_mul ξ) hb1 hb2 hb3 hs₀ hs + have hScont : ContinuousOn (fun s => ∫ y, Real.sin (ξ * y) ∂(μ s)) (Set.Icc 0 T) := + continuousOn_Icc_of_abs_sub_le_mul_abs_sub fun s₀ s hs₀ hs => + abs_pairing_lipschitz hμ (hasDerivAt_sin_const_mul ξ) (hasDerivAt_mul_cos_const_mul ξ) + (hasDerivAt_neg_sq_mul_sin_const_mul ξ) hb1' hb2' hb3' hs₀ hs + set h : ℝ → ℝ := fun r => -b * ξ * (∫ y, Real.sin (ξ * y) ∂(μ r)) + - v / 2 * ξ ^ 2 * (∫ y, Real.cos (ξ * y) ∂(μ r)) with hhdef + set k : ℝ → ℝ := fun r => b * ξ * (∫ y, Real.cos (ξ * y) ∂(μ r)) + - v / 2 * ξ ^ 2 * (∫ y, Real.sin (ξ * y) ∂(μ r)) with hkdef + have hhcont : ContinuousOn h (Set.Icc 0 T) := by + rw [hhdef]; exact (continuousOn_const.mul hScont).sub (continuousOn_const.mul hCcont) + have hkcont : ContinuousOn k (Set.Icc 0 T) := by + rw [hkdef]; exact (continuousOn_const.mul hCcont).sub (continuousOn_const.mul hScont) + have hCprim : ∀ s ∈ Set.Icc (0 : ℝ) T, + (∫ y, Real.cos (ξ * y) ∂(μ s)) = (∫ y, Real.cos (ξ * y) ∂(μ 0)) + ∫ r in (0 : ℝ)..s, h r := + pairing_volterra_primitive hμ hT (hasDerivAt_cos_const_mul ξ) + (hasDerivAt_neg_mul_sin_const_mul ξ) + (hasDerivAt_neg_sq_mul_cos_const_mul ξ) hb1 hb2 hb3 h fun r => by + simp only [hhdef, integral_const_mul]; ring + have hSprim : ∀ s ∈ Set.Icc (0 : ℝ) T, + (∫ y, Real.sin (ξ * y) ∂(μ s)) = (∫ y, Real.sin (ξ * y) ∂(μ 0)) + ∫ r in (0 : ℝ)..s, k r := + pairing_volterra_primitive hμ hT (hasDerivAt_sin_const_mul ξ) (hasDerivAt_mul_cos_const_mul ξ) + (hasDerivAt_neg_sq_mul_sin_const_mul ξ) hb1' hb2' hb3' k fun r => by + simp only [hkdef, integral_const_mul]; ring + have hCderiv : HasDerivWithinAt (fun s => ∫ y, Real.cos (ξ * y) ∂(μ s)) (h x) (Set.Ici x) x := + hasDerivWithinAt_of_volterra_primitive hhcont hx0 hxT hCprim + have hSderiv : HasDerivWithinAt (fun s => ∫ y, Real.sin (ξ * y) ∂(μ s)) (k x) (Set.Ici x) x := + hasDerivWithinAt_of_volterra_primitive hkcont hx0 hxT hSprim + exact ⟨hCderiv, hSderiv⟩ + +/-- For a fixed frequency `ξ`, the pairings of `ρ` and `η` against `cos(ξ·)` +and `sin(ξ·)` agree throughout `[0, T]`, given agreement at `0`. The pairing +differences solve a linear Volterra system; a Lipschitz bound gives their +continuity, the one-sided FTC gives their right derivatives, and Grönwall's +inequality (applied to the `ℝ × ℝ`-valued pair, whose sup-norm bounds the +derivative by `K` times itself) forces both to vanish. -/ +private lemma pairing_cos_sin_eq {b v T : ℝ} {ρ η : ℝ → Measure ℝ} + (hρ : IsWeakForwardFlow (fun _ _ ↦ b) (fun _ _ ↦ v) T ρ) + (hη : IsWeakForwardFlow (fun _ _ ↦ b) (fun _ _ ↦ v) T η) + (hstart : ρ 0 = η 0) (ξ : ℝ) : + ∀ s ∈ Set.Icc (0 : ℝ) T, + (∫ y, Real.cos (ξ * y) ∂(ρ s) = ∫ y, Real.cos (ξ * y) ∂(η s)) ∧ + (∫ y, Real.sin (ξ * y) ∂(ρ s) = ∫ y, Real.sin (ξ * y) ∂(η s)) := by + obtain ⟨hb1, hb2, hb3⟩ := abs_cos_derivative_chain_le ξ + obtain ⟨hb1', hb2', hb3'⟩ := abs_sin_derivative_chain_le ξ + set K : ℝ := |b| * |ξ| + |v| / 2 * ξ ^ 2 with hKdef + set U : ℝ → ℝ := fun s => (∫ y, Real.cos (ξ * y) ∂(ρ s)) - ∫ y, Real.cos (ξ * y) ∂(η s) + with hUdef + set W : ℝ → ℝ := fun s => (∫ y, Real.sin (ξ * y) ∂(ρ s)) - ∫ y, Real.sin (ξ * y) ∂(η s) + with hWdef + have hUlip : ∀ s₀ s, s₀ ∈ Set.Icc (0 : ℝ) T → s ∈ Set.Icc (0 : ℝ) T → + |U s - U s₀| ≤ 2 * K * |s - s₀| := by + intro s₀ s hs₀ hs + have := diff_pairing_lipschitz hρ hη (hasDerivAt_cos_const_mul ξ) + (hasDerivAt_neg_mul_sin_const_mul ξ) + (hasDerivAt_neg_sq_mul_cos_const_mul ξ) hb1 hb2 hb3 hs₀ hs + simpa only [hUdef, hKdef] using this + have hWlip : ∀ s₀ s, s₀ ∈ Set.Icc (0 : ℝ) T → s ∈ Set.Icc (0 : ℝ) T → + |W s - W s₀| ≤ 2 * K * |s - s₀| := by + intro s₀ s hs₀ hs + have := diff_pairing_lipschitz hρ hη (hasDerivAt_sin_const_mul ξ) + (hasDerivAt_mul_cos_const_mul ξ) + (hasDerivAt_neg_sq_mul_sin_const_mul ξ) hb1' hb2' hb3' hs₀ hs + simpa only [hWdef, hKdef] using this + have hUcont : ContinuousOn U (Set.Icc 0 T) := continuousOn_Icc_of_abs_sub_le_mul_abs_sub hUlip + have hWcont : ContinuousOn W (Set.Icc 0 T) := continuousOn_Icc_of_abs_sub_le_mul_abs_sub hWlip + set F : ℝ → ℝ × ℝ := fun s => (U s, W s) with hFdef + set F' : ℝ → ℝ × ℝ := fun x => (-b * ξ * W x - v / 2 * ξ ^ 2 * U x, + b * ξ * U x - v / 2 * ξ ^ 2 * W x) with hF'def + have hFcont : ContinuousOn F (Set.Icc 0 T) := hUcont.prodMk hWcont + have hFderiv : ∀ x ∈ Set.Ico (0 : ℝ) T, HasDerivWithinAt F (F' x) (Set.Ici x) x := by + intro x hx + obtain ⟨hx0, hxT⟩ := hx + obtain ⟨hCρ, hSρ⟩ := hasDerivWithinAt_cosPairing_sinPairing hρ ξ x hx0 hxT + obtain ⟨hCη, hSη⟩ := hasDerivWithinAt_cosPairing_sinPairing hη ξ x hx0 hxT + have hU' : HasDerivWithinAt U (-b * ξ * W x - v / 2 * ξ ^ 2 * U x) (Set.Ici x) x := by + refine (hCρ.sub hCη).congr_deriv ?_ + simp only [hUdef, hWdef] + ring + have hW' : HasDerivWithinAt W (b * ξ * U x - v / 2 * ξ ^ 2 * W x) (Set.Ici x) x := by + refine (hSρ.sub hSη).congr_deriv ?_ + simp only [hUdef, hWdef] + ring + exact hU'.prodMk hW' + have hF0 : F 0 = 0 := by + have hU0 : U 0 = 0 := by simp only [hUdef, hstart, sub_self] + have hW0 : W 0 = 0 := by simp only [hWdef, hstart, sub_self] + simp [hFdef, hU0, hW0] + have hFbound : ∀ x ∈ Set.Ico (0 : ℝ) T, ‖F' x‖ ≤ K * ‖F x‖ := by + intro x _ + rw [hF'def, hFdef, Prod.norm_mk, Prod.norm_mk] + apply max_le + · have heq : (-b * ξ * W x - v / 2 * ξ ^ 2 * U x) + = b * ξ * (-W x) + v / 2 * ξ ^ 2 * (-U x) := by ring + rw [heq] + have hb := abs_mul_add_mul_sq_le_mul_max b v ξ (-W x) (-U x) + rwa [abs_neg, abs_neg, max_comm, ← hKdef] at hb + · have heq : (b * ξ * U x - v / 2 * ξ ^ 2 * W x) = b * ξ * U x + v / 2 * ξ ^ 2 * (-W x) := by + ring + rw [heq] + have hb := abs_mul_add_mul_sq_le_mul_max b v ξ (U x) (-W x) + rwa [abs_neg, ← hKdef] at hb + have hFzero := eq_zero_of_abs_deriv_le_mul_abs_self_of_eq_zero_right hFcont hFderiv hF0 hFbound + intro s hs + have hz := hFzero s hs + rw [hFdef] at hz + have hUz : U s = 0 := by have := congrArg Prod.fst hz; simpa using this + have hWz : W s = 0 := by have := congrArg Prod.snd hz; simpa using this + refine ⟨?_, ?_⟩ + · have := hUz; rw [hUdef] at this; linarith [this] + · have := hWz; rw [hWdef] at this; linarith [this] + +/-- The characteristic function of a probability measure, split into its real/imaginary +`cos`/`sin` pairings: the shared computation behind both sides of `weakForwardUniqueConst`'s +`charFun` comparison (applied once to `ρ s`, once to `η s`). -/ +lemma charFun_eq_cos_add_sin_mul_I {μ : Measure ℝ} [IsProbabilityMeasure μ] (ξ : ℝ) : + charFun μ ξ = ((∫ x, Real.cos (ξ * x) ∂μ : ℝ) : ℂ) + + ((∫ x, Real.sin (ξ * x) ∂μ : ℝ) : ℂ) * Complex.I := by + have hexp : ∀ x : ℝ, Complex.exp ((ξ : ℂ) * (x : ℂ) * Complex.I) + = (Real.cos (ξ * x) : ℂ) + (Real.sin (ξ * x) : ℂ) * Complex.I := by + intro x + rw [show ((ξ : ℂ) * (x : ℂ)) = ((ξ * x : ℝ) : ℂ) by push_cast; ring] + rw [Complex.exp_mul_I, Complex.ofReal_cos, Complex.ofReal_sin] + have hint : ∀ g : ℝ → ℝ, Continuous g → (∀ x, |g x| ≤ 1) → + Integrable (fun x => (g x : ℂ)) μ := fun g hgc hg => + Integrable.mono' (integrable_const (1 : ℝ)) + (Complex.continuous_ofReal.comp hgc).aestronglyMeasurable + (Filter.Eventually.of_forall fun x => by + simp only [Complex.norm_real, Real.norm_eq_abs]; exact hg x) + rw [charFun_apply_real] + simp_rw [hexp] + rw [integral_add (hint _ (by fun_prop) fun x => Real.abs_cos_le_one (ξ * x)) + ((hint _ (by fun_prop) fun x => Real.abs_sin_le_one (ξ * x)).mul_const Complex.I), + integral_mul_const, integral_complex_ofReal, integral_complex_ofReal] + +/-- **Weak uniqueness for the constant-coefficient forward equation.** Two flows solving +`IsWeakForwardFlow` with the same constant coefficients (`afn ≡ b`, `bfn ≡ v`) and the same +initial law coincide at every time in `(0, T]`. -/ +theorem weakForwardUniqueConst {ρ η : ℝ → Measure ℝ} {b v T : ℝ} + (hρ : IsWeakForwardFlow (fun _ _ ↦ b) (fun _ _ ↦ v) T ρ) + (hη : IsWeakForwardFlow (fun _ _ ↦ b) (fun _ _ ↦ v) T η) + (hstart : ρ 0 = η 0) : + ∀ s ∈ Set.Ioc (0 : ℝ) T, ρ s = η s := by + intro s hs + have := hρ.1 s + have := hη.1 s + have hsIcc : s ∈ Set.Icc (0 : ℝ) T := ⟨hs.1.le, hs.2⟩ + refine Measure.ext_of_charFun (funext fun ξ => ?_) + obtain ⟨hc, hsi⟩ := pairing_cos_sin_eq hρ hη hstart ξ s hsIcc + rw [charFun_eq_cos_add_sin_mul_I, charFun_eq_cos_add_sin_mul_I, hc, hsi] + +end MathFin diff --git a/LeanPool/MathFin/Probability/Jumps/CompoundPoissonMGF.lean b/LeanPool/MathFin/Probability/Jumps/CompoundPoissonMGF.lean new file mode 100644 index 0000000000..c9f8d01318 --- /dev/null +++ b/LeanPool/MathFin/Probability/Jumps/CompoundPoissonMGF.lean @@ -0,0 +1,146 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Analysis.IndepFreezing +public import LeanPool.MathFin.Probability.Jumps.PoissonPgf +public import Mathlib.Probability.Moments.Basic + +/-! +# The compound-Poisson aggregate-loss MGF + +For i.i.d. claim sizes `Xᵢ` with common moment generating function `M_X(t)`, integrating the MGF +of the `n`-claim sum `∑_{i + simp only [Finset.sum_apply, Finset.sum_empty, mul_zero, Real.exp_zero] + exact integrable_const _ + | insert i s hi_notin_s h_rec => + rw [Finset.sum_insert hi_notin_s] + exact (h_indep.indepFun_finsetSum_of_notMem₀ h_meas hi_notin_s).symm.integrable_exp_mul_add + (h_int i (Finset.mem_insert_self _ _)) + (h_rec fun j hj ↦ h_int j (Finset.mem_insert_of_mem hj)) + +/-- **The `n`-claim aggregate MGF is the `n`-th power of the common claim MGF.** For i.i.d. +claim sizes `X` (independent, identically distributed), the MGF of the `n`-claim aggregate +`∑_{i N.N ω B) ⁻¹' {⊤} := by + ext ω; simp [Set.mem_preimage] + rw [hset, ← Measure.map_apply (N.measurable_eval hB) (measurableSet_singleton ⊤), + N.poisson_law hB hfin] + change poissonMeasureENN (referenceIntensity ν B).toNNReal {⊤} = 0 + unfold poissonMeasureENN + rw [Measure.map_apply (by fun_prop) (measurableSet_singleton ⊤), + show (fun n : ℕ => (n : ℝ≥0∞)) ⁻¹' {(⊤ : ℝ≥0∞)} = ∅ from by + ext n + simp only [Set.mem_preimage, Set.mem_singleton_iff, Set.mem_empty_iff_false, iff_false] + exact ENNReal.natCast_ne_top n] + exact measure_empty + +/-- **Additivity of the compensated increment** on disjoint finite-intensity sets: +`Ñ(X ∪ Y) = Ñ(X) + Ñ(Y)` a.e. (count additivity + a.e. finiteness). -/ +theorem compensated_add_of_disjoint (N : PoissonRandomMeasure P ν) {X Y : Set (ℝ × E)} + (hX : MeasurableSet X) (hY : MeasurableSet Y) (hdisj : Disjoint X Y) + (hXfin : referenceIntensity ν X ≠ ⊤) (hYfin : referenceIntensity ν Y ≠ ⊤) : + ∀ᵐ ω ∂P, N.compensated (X ∪ Y) ω = N.compensated X ω + N.compensated Y ω := by + filter_upwards [ae_count_ne_top N hX hXfin, ae_count_ne_top N hY hYfin] with ω hXω hYω + simp only [PoissonRandomMeasure.compensated] + rw [measure_union hdisj hY, ENNReal.toReal_add hXω hYω, + show referenceIntensity ν (X ∪ Y) = referenceIntensity ν X + referenceIntensity ν Y from + measure_union hdisj hY, ENNReal.toReal_add hXfin hYfin] + ring + +/-- **Uncorrelated on disjoint regions**: `𝔼[Ñ(X)·Ñ(Y)] = 0` for disjoint measurable `X, Y` (finite +`Y`). `Ñ(X)` lives on the region disjoint from `Y`, so `Ñ(X) ⟂ Ñ(Y)`; `Ñ(Y)` is mean-zero. -/ +theorem compensated_mul_compensated_disjoint (N : PoissonRandomMeasure P ν) {X Y : Set (ℝ × E)} + (hX : MeasurableSet X) (hY : MeasurableSet Y) (hdisj : Disjoint X Y) + (hYfin : referenceIntensity ν Y ≠ ⊤) : + ∫ ω, N.compensated X ω * N.compensated Y ω ∂P = 0 := by + refine integral_mul_compensated_eq_zero N hY hYfin ?_ + change Measurable[N.regionSigma Y] fun ω => (N.N ω X).toReal - (referenceIntensity ν X).toReal + have hc : Measurable[N.regionSigma Y] fun ω => N.N ω X := + (measurable_iff_comap_le.mpr le_rfl).mono (le_iSup₂_of_le X ⟨hdisj, hX⟩ le_rfl) le_rfl + exact hc.ennreal_toReal.sub measurable_const + +/-- **The covariance of the compensated Poisson random measure**: `𝔼[Ñ(C)·Ñ(D)] = ν̂(C ∩ D)`. `Ñ` is +an orthogonal martingale measure with intensity `ν̂`. Decompose into the three disjoint pieces +`C∩D`, `C\D`, `D\C`; the three cross-pairs vanish and the diagonal `𝔼[Ñ(C∩D)²]` is `ν̂(C∩D)`. -/ +theorem compensated_covariance (N : PoissonRandomMeasure P ν) {C D : Set (ℝ × E)} + (hC : MeasurableSet C) (hD : MeasurableSet D) + (hCfin : referenceIntensity ν C ≠ ⊤) (hDfin : referenceIntensity ν D ≠ ⊤) : + ∫ ω, N.compensated C ω * N.compensated D ω ∂P = (referenceIntensity ν (C ∩ D)).toReal := by + have hIms : MeasurableSet (C ∩ D) := hC.inter hD + have hC'ms : MeasurableSet (C \ D) := hC.diff hD + have hD'ms : MeasurableSet (D \ C) := hD.diff hC + have hIfin : referenceIntensity ν (C ∩ D) ≠ ⊤ := + ne_top_of_le_ne_top hCfin (measure_mono Set.inter_subset_left) + have hC'fin : referenceIntensity ν (C \ D) ≠ ⊤ := + ne_top_of_le_ne_top hCfin (measure_mono Set.sdiff_subset) + have hD'fin : referenceIntensity ν (D \ C) ≠ ⊤ := + ne_top_of_le_ne_top hDfin (measure_mono Set.sdiff_subset) + have hIC' : Disjoint (C ∩ D) (C \ D) := Set.disjoint_left.mpr fun _ hx1 hx2 => hx2.2 hx1.2 + have hID' : Disjoint (C ∩ D) (D \ C) := Set.disjoint_left.mpr fun _ hx1 hx2 => hx2.2 hx1.1 + have hC'D' : Disjoint (C \ D) (D \ C) := Set.disjoint_left.mpr fun _ hx1 hx2 => hx2.2 hx1.1 + -- a.e. decompositions of the two increments + have hdC : ∀ᵐ ω ∂P, N.compensated C ω + = N.compensated (C ∩ D) ω + N.compensated (C \ D) ω := by + have h := compensated_add_of_disjoint N hIms hC'ms hIC' hIfin hC'fin + rwa [Set.inter_union_sdiff] at h + have hdD : ∀ᵐ ω ∂P, N.compensated D ω + = N.compensated (C ∩ D) ω + N.compensated (D \ C) ω := by + have h := compensated_add_of_disjoint N hIms hD'ms hID' hIfin hD'fin + rwa [show (C ∩ D) ∪ (D \ C) = + D from by rw [Set.inter_comm]; exact Set.inter_union_sdiff D C] at h + -- L² membership ⇒ integrability of every cross product + have hL2 : ∀ {S : Set (ℝ × E)}, MeasurableSet S → referenceIntensity ν S ≠ ⊤ → + MemLp (N.compensated S) 2 P := fun hS hSf => memLp_compensated N hS hSf + -- expand the product into the four pieces + have hprod : ∀ᵐ ω ∂P, N.compensated C ω * N.compensated D ω + = (N.compensated (C ∩ D) ω) ^ 2 + + N.compensated (C ∩ D) ω * N.compensated (D \ C) ω + + N.compensated (C \ D) ω * N.compensated (C ∩ D) ω + + N.compensated (C \ D) ω * N.compensated (D \ C) ω := by + filter_upwards [hdC, hdD] with ω hCω hDω + rw [hCω, hDω]; ring + rw [integral_congr_ae hprod] + have hi1 : Integrable (fun ω => (N.compensated (C ∩ D) ω) ^ 2) P := + (hL2 hIms hIfin).integrable_sq + have hi2 : Integrable (fun ω => N.compensated (C ∩ D) ω * N.compensated (D \ C) ω) P := + (hL2 hIms hIfin).integrable_mul (hL2 hD'ms hD'fin) + have hi3 : Integrable (fun ω => N.compensated (C \ D) ω * N.compensated (C ∩ D) ω) P := + (hL2 hC'ms hC'fin).integrable_mul (hL2 hIms hIfin) + have hi4 : Integrable (fun ω => N.compensated (C \ D) ω * N.compensated (D \ C) ω) P := + (hL2 hC'ms hC'fin).integrable_mul (hL2 hD'ms hD'fin) + have hf12 : Integrable (fun ω => (N.compensated (C ∩ D) ω) ^ 2 + + N.compensated (C ∩ D) ω * N.compensated (D \ C) ω) P := hi1.add hi2 + have hf123 : Integrable (fun ω => (N.compensated (C ∩ D) ω) ^ 2 + + N.compensated (C ∩ D) ω * N.compensated (D \ C) ω + + N.compensated (C \ D) ω * N.compensated (C ∩ D) ω) P := hf12.add hi3 + rw [integral_add hf123 hi4, integral_add hf12 hi3, + integral_add hi1 hi2, compensated_integral_sq N hIms hIfin, + compensated_mul_compensated_disjoint N hIms hD'ms hID' hD'fin, + compensated_mul_compensated_disjoint N hC'ms hIms hIC'.symm hIfin, + compensated_mul_compensated_disjoint N hC'ms hD'ms hC'D' hD'fin] + ring + +/-! ### Weighted future pairings — the bilinear rung + +The covariance above is the `φ ≡ 1` case of a **weighted** future pairing +`𝔼[φ · Ñ(C) · Ñ(D)] = 𝔼[φ] · ν̂(C ∩ D)` for `φ` adapted at a time `s` before both `C, D` +(`C, D ⊆ (s, ∞) × E`). It is the jump analogue of `ItoIsometryAdapted.rect_increment_pairing` +(Brownian rectangles — cited, not reused): the past-adapted weight factors out of every future +increment, and the increment covariance supplies `ν̂(C ∩ D)`. From it, splitting a box at the later +of two start times gives the **overlapping-box bilinear pairing** the Itô–Lévy isometry sums over. + +All of it rests on the *single-increment* field `indep_of_disjoint_region` — no past-vs-future +`σ`-algebra independence is assumed. Integrability of the triple products is bought by the same +independence (a past-adapted factor is `⟂` any future increment it multiplies). -/ + +/-- The past `σ`-algebra `pastFiltration s` sits inside the disjoint-region `σ`-algebra of any +set lying strictly after `s` (`D ⊆ (s, ∞) × E`) — the generalisation of +`pastFiltration_le_regionSigma` from a future box to an arbitrary future set. -/ +private lemma pastFiltration_le_regionSigma_sub (N : PoissonRandomMeasure P ν) {s : ℝ} + {D : Set (ℝ × E)} (hD : D ⊆ Set.Ioi s ×ˢ Set.univ) : + N.pastFiltration s ≤ N.regionSigma D := by + refine iSup₂_le fun C hC => le_iSup₂_of_le C ⟨?_, hC.2⟩ le_rfl + refine Set.disjoint_of_subset hC.1 hD (Set.disjoint_left.mpr ?_) + rintro ⟨x, e⟩ hx hxD + exact absurd (Set.mem_Iic.mp (Set.mem_prod.mp hx).1) + (not_le.mpr (Set.mem_Ioi.mp (Set.mem_prod.mp hxD).1)) + +/-- A compensated increment on `p` is measurable for the disjoint-region `σ`-algebra of any set `q` +disjoint from `p`. -/ +private lemma compensated_measurable_regionSigma (N : PoissonRandomMeasure P ν) + {p q : Set (ℝ × E)} (hpq : Disjoint p q) (hpms : MeasurableSet p) : + Measurable[N.regionSigma q] (N.compensated p) := by + change Measurable[N.regionSigma q] fun ω => (N.N ω p).toReal - (referenceIntensity ν p).toReal + have hc : Measurable[N.regionSigma q] fun ω => N.N ω p := + (measurable_iff_comap_le.mpr le_rfl).mono (le_iSup₂_of_le p ⟨hpq, hpms⟩ le_rfl) le_rfl + exact hc.ennreal_toReal.sub measurable_const + +/-- **Past-adapted `⟂` future compensated increment (general future set).** For `φ` adapted at `s` +and `D ⊆ (s, ∞) × E`, `φ ⟂ Ñ(D)`. The set-level version of `adapted_indepFun_compensated`. -/ +private lemma adapted_indepFun_compensated_sub (N : PoissonRandomMeasure P ν) {s : ℝ} + {D : Set (ℝ × E)} (hDms : MeasurableSet D) (hDsub : D ⊆ Set.Ioi s ×ˢ Set.univ) + {φ : Ω → ℝ} (hφ : Measurable[N.pastFiltration s] φ) : + IndepFun φ (N.compensated D) P := by + have hfield : Indep (N.regionSigma D) + (MeasurableSpace.comap (fun ω => N.N ω D) inferInstance) P := + N.indep_of_disjoint_region hDms + have hφ_le : MeasurableSpace.comap φ inferInstance ≤ N.regionSigma D := + le_trans (measurable_iff_comap_le.mp hφ) + (pastFiltration_le_regionSigma_sub N hDsub) + have hraw : IndepFun φ (fun ω => N.N ω D) P := + (IndepFun_iff_Indep _ _ _).mpr (indep_of_indep_of_le_left hfield hφ_le) + have hcomp := hraw.comp (φ := (id : ℝ → ℝ)) + (ψ := fun x : ℝ≥0∞ => x.toReal - (referenceIntensity ν D).toReal) + measurable_id (by fun_prop) + simp only [Function.comp_def, id_eq] at hcomp + exact hcomp + +/-- **Weighted diagonal energy (general future set).** For `φ` adapted at `s`, integrable, and +`D ⊆ (s, ∞) × E`, `𝔼[φ · Ñ(D)²] = 𝔼[φ] · ν̂(D)`: `φ ⟂ Ñ(D)²` and `𝔼[Ñ(D)²] = ν̂(D)`. -/ +private lemma integral_adapted_mul_compensated_sq_sub (N : PoissonRandomMeasure P ν) {s : ℝ} + {D : Set (ℝ × E)} (hDms : MeasurableSet D) (hDsub : D ⊆ Set.Ioi s ×ˢ Set.univ) + (hDfin : referenceIntensity ν D ≠ ⊤) {φ : Ω → ℝ} (hφ : Measurable[N.pastFiltration s] φ) + (hφint : Integrable φ P) : + ∫ ω, φ ω * (N.compensated D ω) ^ 2 ∂P = (∫ ω, φ ω ∂P) * (referenceIntensity ν D).toReal := by + rw [(adapted_indepFun_compensated_sub N hDms hDsub hφ).integral_mul_sq + hφint.aestronglyMeasurable (memLp_compensated N hDms hDfin).aestronglyMeasurable, + compensated_integral_sq N hDms hDfin] + +/-- **The weighted future bilinear pairing** — the covariance carrying a past-adapted weight. For +`φ` adapted at `s` and integrable, and `C, D ⊆ (s, ∞) × E` measurable finite-intensity, + + `𝔼[φ · Ñ(C) · Ñ(D)] = 𝔼[φ] · ν̂(C ∩ D)`. + +This is `compensated_covariance` with a weight (`φ ≡ 1` recovers it). Decompose `C, D` into the +three disjoint pieces `C∩D`, `C\D`, `D\C` (all still after `s`); the weighted product expands into +the diagonal `φ · Ñ(C∩D)²` plus three cross pieces `φ · Ñ(p) · Ñ(q)` with `p, q` disjoint. Each +cross piece pairs to zero (`integral_mul_compensated_eq_zero`, the weighted factor `φ · Ñ(p)` being +`regionSigma q`-measurable); the diagonal is `𝔼[φ] · ν̂(C∩D)` +(`integral_adapted_mul_compensated_sq_sub`). Every product is integrable because a past-adapted +factor is independent of the future increment it multiplies. -/ +theorem integral_adapted_bilinear_future (N : PoissonRandomMeasure P ν) {s : ℝ} + {C D : Set (ℝ × E)} (hCms : MeasurableSet C) (hDms : MeasurableSet D) + (hCsub : C ⊆ Set.Ioi s ×ˢ Set.univ) (hDsub : D ⊆ Set.Ioi s ×ˢ Set.univ) + (hCfin : referenceIntensity ν C ≠ ⊤) (hDfin : referenceIntensity ν D ≠ ⊤) + {φ : Ω → ℝ} (hφ : Measurable[N.pastFiltration s] φ) (hφint : Integrable φ P) : + ∫ ω, φ ω * N.compensated C ω * N.compensated D ω ∂P + = (∫ ω, φ ω ∂P) * (referenceIntensity ν (C ∩ D)).toReal := by + -- the three disjoint pieces, all still strictly after `s` + have hIms : MeasurableSet (C ∩ D) := hCms.inter hDms + have hC'ms : MeasurableSet (C \ D) := hCms.diff hDms + have hD'ms : MeasurableSet (D \ C) := hDms.diff hCms + have hIsub : C ∩ D ⊆ Set.Ioi s ×ˢ Set.univ := Set.inter_subset_left.trans hCsub + have hC'sub : C \ D ⊆ Set.Ioi s ×ˢ Set.univ := Set.sdiff_subset.trans hCsub + have hD'sub : D \ C ⊆ Set.Ioi s ×ˢ Set.univ := Set.sdiff_subset.trans hDsub + have hIfin : referenceIntensity ν (C ∩ D) ≠ ⊤ := + ne_top_of_le_ne_top hCfin (measure_mono Set.inter_subset_left) + have hC'fin : referenceIntensity ν (C \ D) ≠ ⊤ := + ne_top_of_le_ne_top hCfin (measure_mono Set.sdiff_subset) + have hD'fin : referenceIntensity ν (D \ C) ≠ ⊤ := + ne_top_of_le_ne_top hDfin (measure_mono Set.sdiff_subset) + have hIC' : Disjoint (C ∩ D) (C \ D) := Set.disjoint_left.mpr fun _ hx1 hx2 => hx2.2 hx1.2 + have hID' : Disjoint (C ∩ D) (D \ C) := Set.disjoint_left.mpr fun _ hx1 hx2 => hx2.2 hx1.1 + have hC'D' : Disjoint (C \ D) (D \ C) := Set.disjoint_left.mpr fun _ hx1 hx2 => hx2.2 hx1.1 + -- a.e. decompositions of the two increments + have hdC : ∀ᵐ ω ∂P, N.compensated C ω + = N.compensated (C ∩ D) ω + N.compensated (C \ D) ω := by + have h := compensated_add_of_disjoint N hIms hC'ms hIC' hIfin hC'fin + rwa [Set.inter_union_sdiff] at h + have hdD : ∀ᵐ ω ∂P, N.compensated D ω + = N.compensated (C ∩ D) ω + N.compensated (D \ C) ω := by + have h := compensated_add_of_disjoint N hIms hD'ms hID' hIfin hD'fin + rwa [show (C ∩ D) ∪ (D \ C) = D from by + rw [Set.inter_comm]; exact Set.inter_union_sdiff D C] at h + -- reusable measurability / integrability shorthands + have hφreg : ∀ {q : Set (ℝ × E)}, q ⊆ Set.Ioi s ×ˢ Set.univ → Measurable[N.regionSigma q] φ := + fun hq => hφ.mono + (pastFiltration_le_regionSigma_sub N hq) le_rfl + have hÑint : ∀ {p : Set (ℝ × E)}, MeasurableSet p → referenceIntensity ν p ≠ ⊤ → + Integrable (N.compensated p) P := + fun hp hpf => (memLp_compensated N hp hpf).integrable (by norm_num) + have hφÑint : ∀ {p : Set (ℝ × E)}, MeasurableSet p → p ⊆ Set.Ioi s ×ˢ Set.univ → + referenceIntensity ν p ≠ ⊤ → Integrable (fun ω => φ ω * N.compensated p ω) P := + fun hp hps hpf => + (adapted_indepFun_compensated_sub N hp hps hφ).integrable_mul hφint (hÑint hp hpf) + -- independence of a weighted disjoint increment from a fresh increment + have hindep_cross : ∀ {p q : Set (ℝ × E)}, Disjoint p q → MeasurableSet p → + q ⊆ Set.Ioi s ×ˢ Set.univ → MeasurableSet q → + IndepFun (fun ω => φ ω * N.compensated p ω) (N.compensated q) P := by + intro p q hpq hpms hqsub hqms + have hX : Measurable[N.regionSigma q] (fun ω => φ ω * N.compensated p ω) := + (hφreg hqsub).mul (compensated_measurable_regionSigma N hpq hpms) + have hfield : Indep (N.regionSigma q) + (MeasurableSpace.comap (fun ω => N.N ω q) inferInstance) P := + N.indep_of_disjoint_region hqms + have hraw : IndepFun (fun ω => φ ω * N.compensated p ω) (fun ω => N.N ω q) P := + (IndepFun_iff_Indep _ _ _).mpr + (indep_of_indep_of_le_left hfield (measurable_iff_comap_le.mp hX)) + have hc := hraw.comp (φ := (id : ℝ → ℝ)) + (ψ := fun x : ℝ≥0∞ => x.toReal - (referenceIntensity ν q).toReal) measurable_id (by fun_prop) + simp only [Function.comp_def, id_eq] at hc + exact hc + -- expand the weighted product into diagonal + three cross pieces + have hprod : ∀ᵐ ω ∂P, φ ω * N.compensated C ω * N.compensated D ω + = φ ω * (N.compensated (C ∩ D) ω) ^ 2 + + φ ω * N.compensated (C ∩ D) ω * N.compensated (D \ C) ω + + φ ω * N.compensated (C \ D) ω * N.compensated (C ∩ D) ω + + φ ω * N.compensated (C \ D) ω * N.compensated (D \ C) ω := by + filter_upwards [hdC, hdD] with ω hCω hDω + rw [hCω, hDω]; ring + rw [integral_congr_ae hprod] + -- integrabilities of the four pieces + have hindepI2 := (adapted_indepFun_compensated_sub N hIms hIsub hφ).comp + (φ := (id : ℝ → ℝ)) (ψ := fun x : ℝ => x ^ 2) measurable_id (by fun_prop) + simp only [Function.comp_def, id_eq] at hindepI2 + have hi1 : Integrable (fun ω => φ ω * (N.compensated (C ∩ D) ω) ^ 2) P := + hindepI2.integrable_mul hφint ((memLp_compensated N hIms hIfin).integrable_sq) + have hi2 : Integrable + (fun ω => φ ω * N.compensated (C ∩ D) ω * N.compensated (D \ C) ω) P := + (hindep_cross hID' hIms hD'sub hD'ms).integrable_mul + (hφÑint hIms hIsub hIfin) (hÑint hD'ms hD'fin) + have hi3 : Integrable + (fun ω => φ ω * N.compensated (C \ D) ω * N.compensated (C ∩ D) ω) P := + (hindep_cross hIC'.symm hC'ms hIsub hIms).integrable_mul + (hφÑint hC'ms hC'sub hC'fin) (hÑint hIms hIfin) + have hi4 : Integrable + (fun ω => φ ω * N.compensated (C \ D) ω * N.compensated (D \ C) ω) P := + (hindep_cross hC'D' hC'ms hD'sub hD'ms).integrable_mul + (hφÑint hC'ms hC'sub hC'fin) (hÑint hD'ms hD'fin) + have hf12 : Integrable (fun ω => φ ω * (N.compensated (C ∩ D) ω) ^ 2 + + φ ω * N.compensated (C ∩ D) ω * N.compensated (D \ C) ω) P := hi1.add hi2 + have hf123 : Integrable (fun ω => φ ω * (N.compensated (C ∩ D) ω) ^ 2 + + φ ω * N.compensated (C ∩ D) ω * N.compensated (D \ C) ω + + φ ω * N.compensated (C \ D) ω * N.compensated (C ∩ D) ω) P := hf12.add hi3 + -- the three cross pieces vanish; the diagonal is `𝔼[φ]·ν̂(C∩D)` + have hX2 : Measurable[N.regionSigma (D \ C)] (fun ω => φ ω * N.compensated (C ∩ D) ω) := + (hφreg hD'sub).mul (compensated_measurable_regionSigma N hID' hIms) + have hX3 : Measurable[N.regionSigma (C ∩ D)] (fun ω => φ ω * N.compensated (C \ D) ω) := + (hφreg hIsub).mul (compensated_measurable_regionSigma N hIC'.symm hC'ms) + have hX4 : Measurable[N.regionSigma (D \ C)] (fun ω => φ ω * N.compensated (C \ D) ω) := + (hφreg hD'sub).mul (compensated_measurable_regionSigma N hC'D' hC'ms) + rw [integral_add hf123 hi4, integral_add hf12 hi3, integral_add hi1 hi2, + integral_adapted_mul_compensated_sq_sub N hIms hIsub hIfin hφ hφint, + integral_mul_compensated_eq_zero N hD'ms hD'fin hX2, + integral_mul_compensated_eq_zero N hIms hIfin hX3, + integral_mul_compensated_eq_zero N hD'ms hD'fin hX4] + ring + +/-- **The overlapping-box bilinear pairing** — the Itô–Lévy inner-product core. For coefficients +`φa` adapted at `sa`, `φb` adapted at `sb` with `sa ≤ sb`, both bounded, + + `𝔼[(φa · Ñ(boxa)) · (φb · Ñ(boxb))] = 𝔼[φa · φb] · ν̂(boxa ∩ boxb)`, + +with `boxa = (sa, ta] × Aa`, `boxb = (sb, tb] × Ab`. The jump analogue of +`ItoIsometryAdapted.rect_increment_pairing` (Brownian rectangles — cited, not reused). Split `boxa` +in time at the later start `sb`: the past part `(-∞, sb]` pairs to zero against the future increment +`Ñ(boxb)` (`integral_mul_compensated_eq_zero`); the future part `(sb, ∞)` starts at `sb` alongside +`boxb`, so the weighted future pairing `integral_adapted_bilinear_future` supplies +`𝔼[φa φb] · ν̂(futPart ∩ boxb)`, and `futPart ∩ boxb = boxa ∩ boxb`. -/ +theorem integral_bilinear_pairing (N : PoissonRandomMeasure P ν) + {sa ta sb tb : ℝ} (hab : sa ≤ sb) + {Aa Ab : Set E} (hAa : MeasurableSet Aa) (hAb : MeasurableSet Ab) + (hAafin : ν Aa ≠ ⊤) (hAbfin : ν Ab ≠ ⊤) + {φa φb : Ω → ℝ} {Ca Cb : ℝ} + (hφa : Measurable[N.pastFiltration sa] φa) (hφb : Measurable[N.pastFiltration sb] φb) + (hφaB : ∀ ω, |φa ω| ≤ Ca) (hφbB : ∀ ω, |φb ω| ≤ Cb) : + ∫ ω, (φa ω * N.compensated (Set.Ioc sa ta ×ˢ Aa) ω) + * (φb ω * N.compensated (Set.Ioc sb tb ×ˢ Ab) ω) ∂P + = (∫ ω, φa ω * φb ω ∂P) + * (referenceIntensity ν ((Set.Ioc sa ta ×ˢ Aa) ∩ (Set.Ioc sb tb ×ˢ Ab))).toReal := by + -- measurability of the boxes and the past / future half-planes at `sb` + have hboxams : MeasurableSet (Set.Ioc sa ta ×ˢ Aa) := measurableSet_Ioc.prod hAa + have hboxbms : MeasurableSet (Set.Ioc sb tb ×ˢ Ab) := measurableSet_Ioc.prod hAb + have hIicms : MeasurableSet (Set.Iic sb ×ˢ (Set.univ : Set E)) := + measurableSet_Iic.prod MeasurableSet.univ + have hIoims : MeasurableSet (Set.Ioi sb ×ˢ (Set.univ : Set E)) := + measurableSet_Ioi.prod MeasurableSet.univ + have hpastms : MeasurableSet (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Iic sb ×ˢ Set.univ)) := + hboxams.inter hIicms + have hfutms : MeasurableSet (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Ioi sb ×ˢ Set.univ)) := + hboxams.inter hIoims + -- finiteness (the halves are subsets of `boxa`) + have hboxafin : referenceIntensity ν (Set.Ioc sa ta ×ˢ Aa) ≠ ⊤ := + referenceIntensity_box_ne_top hAafin + have hboxbfin : referenceIntensity ν (Set.Ioc sb tb ×ˢ Ab) ≠ ⊤ := + referenceIntensity_box_ne_top hAbfin + have hpastfin : referenceIntensity ν (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Iic sb ×ˢ Set.univ)) ≠ ⊤ := + ne_top_of_le_ne_top hboxafin (measure_mono Set.inter_subset_left) + have hfutfin : referenceIntensity ν (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Ioi sb ×ˢ Set.univ)) ≠ ⊤ := + ne_top_of_le_ne_top hboxafin (measure_mono Set.inter_subset_left) + -- geometry: `boxb ⊆` future, past `⟂` future, past `∪` future `= boxa`, + -- `futPart ∩ boxb = boxa ∩ boxb` + have hIicIoi : Disjoint (Set.Iic sb ×ˢ (Set.univ : Set E)) (Set.Ioi sb ×ˢ Set.univ) := + Set.disjoint_left.mpr fun ⟨x, e⟩ hx hxD => + absurd (Set.mem_Iic.mp (Set.mem_prod.mp hx).1) + (not_le.mpr (Set.mem_Ioi.mp (Set.mem_prod.mp hxD).1)) + have hboxbsub : Set.Ioc sb tb ×ˢ Ab ⊆ Set.Ioi sb ×ˢ Set.univ := + Set.prod_mono Set.Ioc_subset_Ioi_self (Set.subset_univ _) + have hfutsub : Set.Ioc sa ta ×ˢ Aa ∩ (Set.Ioi sb ×ˢ Set.univ) ⊆ Set.Ioi sb ×ˢ Set.univ := + Set.inter_subset_right + have hpastdisjb : Disjoint (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Iic sb ×ˢ Set.univ)) + (Set.Ioc sb tb ×ˢ Ab) := + Set.disjoint_of_subset Set.inter_subset_right hboxbsub hIicIoi + have hdisj_pf : Disjoint (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Iic sb ×ˢ Set.univ)) + (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Ioi sb ×ˢ Set.univ)) := + Set.disjoint_of_subset Set.inter_subset_right Set.inter_subset_right hIicIoi + have hunion : (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Iic sb ×ˢ Set.univ)) + ∪ (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Ioi sb ×ˢ Set.univ)) = Set.Ioc sa ta ×ˢ Aa := by + rw [← Set.inter_union_distrib_left, ← Set.union_prod, Set.Iic_union_Ioi, + Set.univ_prod_univ, Set.inter_univ] + have hfutinter : (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Ioi sb ×ˢ Set.univ)) ∩ (Set.Ioc sb tb ×ˢ Ab) + = (Set.Ioc sa ta ×ˢ Aa) ∩ (Set.Ioc sb tb ×ˢ Ab) := by + rw [Set.inter_assoc, Set.inter_eq_right.mpr hboxbsub] + -- the weight `φa · φb` is adapted at `sb`, bounded, hence integrable + have hφ : Measurable[N.pastFiltration sb] (fun ω => φa ω * φb ω) := + (hφa.mono (N.pastFiltration.mono hab) le_rfl).mul hφb + have hbound : ∀ ω, ‖φa ω * φb ω‖ ≤ Ca * Cb := fun ω => by + rw [Real.norm_eq_abs, abs_mul] + exact mul_le_mul (hφaB ω) (hφbB ω) (abs_nonneg _) ((abs_nonneg _).trans (hφaB ω)) + have hφint : Integrable (fun ω => φa ω * φb ω) P := + (memLp_top_of_bound (hφ.mono (N.pastFiltration.le sb) le_rfl).aestronglyMeasurable (Ca * Cb) + (ae_of_all _ hbound)).integrable + le_top + -- `Ñ(boxa) = Ñ(pastPart) + Ñ(futPart)` a.e. + have hdecomp : ∀ᵐ ω ∂P, N.compensated (Set.Ioc sa ta ×ˢ Aa) ω + = N.compensated (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Iic sb ×ˢ Set.univ)) ω + + N.compensated (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Ioi sb ×ˢ Set.univ)) ω := by + have h := compensated_add_of_disjoint N hpastms hfutms hdisj_pf hpastfin hfutfin + rwa [hunion] at h + -- split the integrand: past term (⟶ 0) + future term (⟶ master pairing) + have hprod : ∀ᵐ ω ∂P, + (φa ω * N.compensated (Set.Ioc sa ta ×ˢ Aa) ω) + * (φb ω * N.compensated (Set.Ioc sb tb ×ˢ Ab) ω) + = φa ω * φb ω * N.compensated (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Iic sb ×ˢ Set.univ)) ω + * N.compensated (Set.Ioc sb tb ×ˢ Ab) ω + + φa ω * φb ω * N.compensated (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Ioi sb ×ˢ Set.univ)) ω + * N.compensated (Set.Ioc sb tb ×ˢ Ab) ω := by + filter_upwards [hdecomp] with ω hω + rw [hω]; ring + rw [integral_congr_ae hprod] + -- integrabilities: bounded weight × (`L²`-increment) × (`L²`-increment) + have hint_past : Integrable (fun ω => φa ω * φb ω + * N.compensated (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Iic sb ×ˢ Set.univ)) ω + * N.compensated (Set.Ioc sb tb ×ˢ Ab) ω) P := + (((memLp_compensated N hpastms hpastfin).integrable_mul + (memLp_compensated N hboxbms hboxbfin)).bdd_mul + (hφ.mono (N.pastFiltration.le sb) le_rfl).aestronglyMeasurable (ae_of_all _ hbound)).congr + (ae_of_all _ fun ω => by simp only [Pi.mul_apply]; ring) + have hint_fut : Integrable (fun ω => φa ω * φb ω + * N.compensated (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Ioi sb ×ˢ Set.univ)) ω + * N.compensated (Set.Ioc sb tb ×ˢ Ab) ω) P := + (((memLp_compensated N hfutms hfutfin).integrable_mul + (memLp_compensated N hboxbms hboxbfin)).bdd_mul + (hφ.mono (N.pastFiltration.le sb) le_rfl).aestronglyMeasurable (ae_of_all _ hbound)).congr + (ae_of_all _ fun ω => by simp only [Pi.mul_apply]; ring) + rw [integral_add hint_past hint_fut] + -- past term vanishes (weighted past-region factor `⟂` fresh future increment) + have hXpast : Measurable[N.regionSigma (Set.Ioc sb tb ×ˢ Ab)] + (fun ω => φa ω * φb ω + * N.compensated (Set.Ioc sa ta ×ˢ Aa ∩ (Set.Iic sb ×ˢ Set.univ)) ω) := + (hφ.mono + (pastFiltration_le_regionSigma_sub N hboxbsub) le_rfl).mul + (compensated_measurable_regionSigma N hpastdisjb hpastms) + rw [integral_mul_compensated_eq_zero N hboxbms hboxbfin hXpast, zero_add, + integral_adapted_bilinear_future N hfutms hboxbms hfutsub hboxbsub hfutfin hboxbfin hφ hφint, + hfutinter] + +end MathFin diff --git a/LeanPool/MathFin/Probability/Jumps/PoissonCompensatedIntegralL2.lean b/LeanPool/MathFin/Probability/Jumps/PoissonCompensatedIntegralL2.lean new file mode 100644 index 0000000000..fc692bfdb6 --- /dev/null +++ b/LeanPool/MathFin/Probability/Jumps/PoissonCompensatedIntegralL2.lean @@ -0,0 +1,162 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Jumps.PoissonCompensatedIsometryAdapted + +/-! +# The Itô–Lévy isometry for simple integrands + +The jump analogue of `Probability/Brownian/Ito/ItoIsometryAdapted.lean`'s `ito_isometry_discrete` — +the genuine +compensated-Poisson `L²` isometry for a *simple predictable* integrand over a `time × mark` grid. +For a time partition `t₀ ≤ t₁ ≤ ⋯`, disjoint finite-intensity marks `A₀, …, A_{m-1}`, and +coefficients `φⱼₗ` each adapted at `tⱼ` and in `L²`, + + `𝔼[(∑ⱼ ∑ₗ φⱼₗ · Ñ((tⱼ,tⱼ₊₁] × Aₗ))²] = ∑ⱼ ∑ₗ 𝔼[φⱼₗ²] · (tⱼ₊₁ − tⱼ) · ν(Aₗ)`, + +the right-hand side being `‖φ‖²` in `L²(dP ⊗ dt ⊗ dν)`. The square expands into a grid-indexed +double sum; every off-diagonal pair vanishes by `integral_cross_compensated_eq_zero` — different +time blocks are disjoint in time, same-block/different-mark pairs are disjoint in the mark — and the +diagonal is `integral_adapted_sq_mul_compensated_sq`. This is `full`: the real second-moment +computation, not a definitional identity. + +## Provenance + +Design mirrors our continuous Itô `ito_isometry_discrete`; the PRM kernel is from +`Probability/Jumps/PoissonCompensatedIsometryAdapted` (PRM field shape consulted from +`cgarryZA/LevyStochCalc`, cited). This file gives the isometry for simple +integrands on the stated time and mark partitions. The related LevyStochCalc +theorem `itoIsometry_compensated_unified_existence` includes an isometry for +progressively measurable integrands. + +## Main results + +* `compensated_simple_isometry`: for a monotone time grid `t` with `0 ≤ t 0`, disjoint + finite-intensity marks `A l`, and `L²` coefficients `φ j l` adapted at `t j`, + `𝔼[(∑ⱼ∑ₗ φⱼₗ Ñ((tⱼ, tⱼ₊₁] × Aₗ))²] = ∑ⱼ∑ₗ 𝔼[φⱼₗ²]·(tⱼ₊₁ − tⱼ)·ν(Aₗ).toReal`. + +## References + +* [Applebaum (2009)][Applebaum2009], Thm 4.2.3 +* [*cgarryZA/LevyStochCalc*][LevyStochCalc], `itoIsometry_compensated_unified_existence` + (related Itô–Lévy isometry for progressively measurable integrands) + +## Tags + +Itô–Lévy isometry, compensated Poisson integral, jump process integral, +simple predictable integrand, Lévy stochastic calculus, MSC 60G51, MSC 60H05, MSC 60G55 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +variable {Ω : Type*} [MeasurableSpace Ω] {E : Type*} [MeasurableSpace E] + {P : Measure Ω} [IsProbabilityMeasure P] {ν : Measure E} [SigmaFinite ν] + +/-- **The Itô–Lévy isometry for simple integrands.** For a monotone time partition `t` (with +`0 ≤ t 0`), pairwise-disjoint finite-intensity marks `A`, and coefficients `φ j l` adapted at +`t j` and in `L²`, + + `𝔼[(∑ⱼ ∑ₗ φⱼₗ · Ñ((tⱼ,tⱼ₊₁] × Aₗ))²] = ∑ⱼ ∑ₗ 𝔼[φⱼₗ²] · (tⱼ₊₁ − tⱼ) · ν(Aₗ)`. -/ +theorem compensated_simple_isometry (N : PoissonRandomMeasure P ν) + {Nt m : ℕ} {t : ℕ → ℝ} (ht0 : 0 ≤ t 0) (hmono : Monotone t) + {A : ℕ → Set E} (hAms : ∀ l, MeasurableSet (A l)) (hAfin : ∀ l, ν (A l) ≠ ⊤) + (hAdisj : Pairwise (Function.onFun Disjoint A)) + {φ : ℕ → ℕ → Ω → ℝ} (hadapt : ∀ j l, Measurable[N.pastFiltration (t j)] (φ j l)) + (hmemLp : ∀ j l, MemLp (φ j l) 2 P) : + ∫ ω, (∑ j ∈ Finset.range Nt, ∑ l ∈ Finset.range m, + φ j l ω * N.compensated (Set.Ioc (t j) (t (j + 1)) ×ˢ A l) ω) ^ 2 ∂P + = ∑ j ∈ Finset.range Nt, ∑ l ∈ Finset.range m, + (∫ ω, (φ j l ω) ^ 2 ∂P) * ((t (j + 1) - t j) * (ν (A l)).toReal) := by + classical + set a : ℕ × ℕ → Ω → ℝ := + fun p ω => φ p.1 p.2 ω * N.compensated (Set.Ioc (t p.1) (t (p.1 + 1)) ×ˢ A p.2) ω with ha + set I : Finset (ℕ × ℕ) := Finset.range Nt ×ˢ Finset.range m with hI + have ht0j : ∀ j, 0 ≤ t j := fun j => le_trans ht0 (hmono (Nat.zero_le j)) + -- each grid term is `L²`, so every product is integrable + have haL2 : ∀ p, MemLp (a p) 2 P := fun p => + memLp_adapted_mul_compensated N (hAms p.2) (hAfin p.2) (hadapt p.1 p.2) (hmemLp p.1 p.2) + have hint : ∀ p q, Integrable (fun ω => a p ω * a q ω) P := + fun p q => (haL2 p).integrable_mul (haL2 q) + -- boxes disjoint in time when the earlier time-index precedes the later + have hdisjT : ∀ p q : ℕ × ℕ, p.1 < q.1 → + Disjoint (Set.Ioc (t p.1) (t (p.1 + 1)) ×ˢ A p.2) + (Set.Ioc (t q.1) (t (q.1 + 1)) ×ˢ A q.2) := by + intro p q hlt + have hle : t (p.1 + 1) ≤ t q.1 := hmono (Nat.succ_le_of_lt hlt) + rw [Set.disjoint_left] + rintro z hz1 hz2 + exact absurd (le_trans (Set.mem_Ioc.mp (Set.mem_prod.mp hz1).1).2 hle) + (not_le.mpr (Set.mem_Ioc.mp (Set.mem_prod.mp hz2).1).1) + -- boxes disjoint in the mark when the marks differ + have hdisjM : ∀ p q : ℕ × ℕ, p.2 ≠ q.2 → + Disjoint (Set.Ioc (t p.1) (t (p.1 + 1)) ×ˢ A p.2) + (Set.Ioc (t q.1) (t (q.1 + 1)) ×ˢ A q.2) := by + intro p q hlm + rw [Set.disjoint_left] + rintro z hz1 hz2 + exact (Set.disjoint_left.mp (hAdisj hlm)) (Set.mem_prod.mp hz1).2 (Set.mem_prod.mp hz2).2 + -- oriented cross-term (later time-index carries the fresh increment) + have cross_oriented : ∀ p q : ℕ × ℕ, t p.1 ≤ t q.1 → + Disjoint (Set.Ioc (t p.1) (t (p.1 + 1)) ×ˢ A p.2) + (Set.Ioc (t q.1) (t (q.1 + 1)) ×ˢ A q.2) → ∫ ω, a p ω * a q ω ∂P = 0 := + fun p q hab hdisj => integral_cross_compensated_eq_zero N hab + (measurableSet_Ioc.prod (hAms p.2)) (hAms q.2) (hAfin q.2) hdisj + (hadapt p.1 p.2) (hadapt q.1 q.2) + -- every off-diagonal pair vanishes + have cross_zero : ∀ p q : ℕ × ℕ, p ≠ q → ∫ ω, a p ω * a q ω ∂P = 0 := by + intro p q hpq + rcases lt_trichotomy p.1 q.1 with hlt | heq | hgt + · exact cross_oriented p q (hmono hlt.le) (hdisjT p q hlt) + · exact cross_oriented p q (le_of_eq (congrArg t heq)) + (hdisjM p q (fun h => hpq (Prod.ext heq h))) + · rw [show (fun ω => a p ω * a q ω) = (fun ω => a q ω * a p ω) from + funext fun ω => mul_comm _ _] + exact cross_oriented q p (hmono hgt.le) (hdisjT q p hgt) + -- diagonal energy + have diag_eval : ∀ p : ℕ × ℕ, ∫ ω, a p ω * a p ω ∂P + = (∫ ω, (φ p.1 p.2 ω) ^ 2 ∂P) * ((t (p.1 + 1) - t p.1) * (ν (A p.2)).toReal) := by + intro p + have h1 : (fun ω => a p ω * a p ω) + = fun ω => (φ p.1 p.2 ω) ^ 2 + * (N.compensated (Set.Ioc (t p.1) (t (p.1 + 1)) ×ˢ A p.2) ω) ^ 2 := by + funext ω; simp only [ha]; ring + rw [h1, integral_adapted_sq_mul_compensated_sq N (hAms p.2) (hAfin p.2) (hadapt p.1 p.2), + referenceIntensity_box_toReal (ht0j p.1) (hmono (Nat.le_succ p.1))] + -- fold nested grid sums into a single pair sum + have hsum : ∀ ω, (∑ p ∈ I, a p ω) + = ∑ j ∈ Finset.range Nt, ∑ l ∈ Finset.range m, + φ j l ω * N.compensated (Set.Ioc (t j) (t (j + 1)) ×ˢ A l) ω := by + intro ω; simp only [hI, Finset.sum_product, ha] + calc ∫ ω, (∑ j ∈ Finset.range Nt, ∑ l ∈ Finset.range m, + φ j l ω * N.compensated (Set.Ioc (t j) (t (j + 1)) ×ˢ A l) ω) ^ 2 ∂P + = ∫ ω, ∑ p ∈ I, ∑ q ∈ I, a p ω * a q ω ∂P := by + refine integral_congr_ae (Filter.Eventually.of_forall fun ω => ?_) + change (∑ j ∈ Finset.range Nt, ∑ l ∈ Finset.range m, + φ j l ω * N.compensated (Set.Ioc (t j) (t (j + 1)) ×ˢ A l) ω) ^ 2 + = ∑ p ∈ I, ∑ q ∈ I, a p ω * a q ω + rw [← hsum ω, pow_two, Finset.sum_mul_sum] + _ = ∑ p ∈ I, ∑ q ∈ I, ∫ ω, a p ω * a q ω ∂P := by + rw [integral_finsetSum _ (fun p _ => integrable_finsetSum _ fun q _ => hint p q)] + exact Finset.sum_congr rfl fun p _ => integral_finsetSum _ fun q _ => hint p q + _ = ∑ p ∈ I, ∫ ω, a p ω * a p ω ∂P := by + refine Finset.sum_congr rfl fun p hp => ?_ + exact Finset.sum_eq_single p (fun q _ hqp => cross_zero p q (Ne.symm hqp)) + (fun hp' => absurd hp hp') + _ = ∑ p ∈ I, (∫ ω, (φ p.1 p.2 ω) ^ 2 ∂P) * ((t (p.1 + 1) - t p.1) * (ν (A p.2)).toReal) := + Finset.sum_congr rfl fun p _ => diag_eval p + _ = ∑ j ∈ Finset.range Nt, ∑ l ∈ Finset.range m, + (∫ ω, (φ j l ω) ^ 2 ∂P) * ((t (j + 1) - t j) * (ν (A l)).toReal) := by + simp only [hI, Finset.sum_product] + +end MathFin diff --git a/LeanPool/MathFin/Probability/Jumps/PoissonCompensatedIntegralL2Dense.lean b/LeanPool/MathFin/Probability/Jumps/PoissonCompensatedIntegralL2Dense.lean new file mode 100644 index 0000000000..28da081fd6 --- /dev/null +++ b/LeanPool/MathFin/Probability/Jumps/PoissonCompensatedIntegralL2Dense.lean @@ -0,0 +1,202 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Jumps.PoissonCompensatedIntegralL2 + +/-! +# The Itô–Lévy isometry in `L²`-norm form + +`Probability/Jumps/PoissonCompensatedIntegralL2.lean` proved the compensated-Poisson isometry with +the +right-hand side written as an explicit sum `∑ⱼ∑ₗ 𝔼[φⱼₗ²]·(tⱼ₊₁−tⱼ)·ν(Aₗ)`. This module recognises +that sum as the `L²`-norm of the *integrand itself* against the product reference measure `P ⊗ ν̂` +(`ν̂ = Leb[0,∞) ⊗ ν`): the simple integrand `H(ω,z) = ∑ⱼ∑ₗ φⱼₗ(ω)·𝟙_{(tⱼ,tⱼ₊₁]×Aₗ}(z)` has + + `∫ H² d(P ⊗ ν̂) = ∑ⱼ∑ₗ 𝔼[φⱼₗ²]·(tⱼ₊₁−tⱼ)·ν(Aₗ)`, + +so the isometry becomes the norm identity `𝔼[(∫ H dÑ)²] = ‖H‖²_{L²(dP ⊗ dt ⊗ dν)}` — the shape the +compensated-integral CLM is completed from (`LinearMap.extendOfNorm`) and the shape in which the +Itô–Lévy isometry is usually stated. The integrand-`L²`-norm computation is the jump analogue of +`ItoIntegralL2.simpleProcessL2_norm_sq`, but *simpler*: the grid boxes are pairwise disjoint, so the +cross terms vanish by `ν̂(boxᵢ ∩ boxⱼ) = 0` rather than an interval-overlap formula. + +## Provenance + +Mirrors our continuous `ItoIntegralL2.simpleProcessL2_norm_sq`; consumes B1 +(`compensated_simple_isometry`), whose Poisson-random-measure object's field shape is consulted from +`cgarryZA/LevyStochCalc` (Apache-2.0, cited) — a faithful rendering of Applebaum 2009 Def. 2.3.1. +The statements here give the isometry for adapted coefficients on a marked +time grid. `PoissonCompensatedIntegralOperator` extends a marked simple-integrand +isometry to the closure of those integrands. LevyStochCalc's related theorem +`itoIsometry_compensated_unified_existence` includes the isometry for progressively +measurable square-integrable integrands. + +## Main results + +* `simpleIntegrand_sq_integral`: for the grid integrand `H(ω, z) = ∑ⱼ∑ₗ φⱼₗ(ω)·𝟙_{(tⱼ,tⱼ₊₁]×Aₗ}(z)` + with `L²` coefficients, `∫ H² d(P ⊗ ν̂) = ∑ⱼ∑ₗ 𝔼[φⱼₗ²]·(tⱼ₊₁ − tⱼ)·ν(Aₗ).toReal`. +* `compensated_integral_isometry`: for adapted `L²` coefficients, the squared compensated integral + of `H` has `𝔼[(∑ⱼ∑ₗ φⱼₗ Ñ((tⱼ, tⱼ₊₁] × Aₗ))²] = ∫ H² d(P ⊗ ν̂)`. + +## References + +* [Applebaum (2009)][Applebaum2009], Thm 4.2.3 +* [*cgarryZA/LevyStochCalc*][LevyStochCalc], `itoIsometry_compensated_unified_existence` + (related Itô–Lévy isometry for progressively measurable integrands) + +## Tags + +Itô–Lévy isometry, L2 norm identity, compensated Poisson integral, reference intensity measure, +jump integrand, MSC 60G51, MSC 60H05, MSC 60G55 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +variable {Ω : Type*} [MeasurableSpace Ω] {E : Type*} [MeasurableSpace E] + {P : Measure Ω} [IsProbabilityMeasure P] {ν : Measure E} [SigmaFinite ν] + +/-- **The integrand's `L²`-norm² equals the isometry's right-hand side.** For the grid simple +integrand `H(ω,z) = ∑ⱼ∑ₗ φⱼₗ(ω)·𝟙_{(tⱼ,tⱼ₊₁]×Aₗ}(z)`, +`∫ H² d(P ⊗ ν̂) = ∑ⱼ∑ₗ 𝔼[φⱼₗ²]·(tⱼ₊₁−tⱼ)·ν(Aₗ)`. The square expands into a grid double sum; each +product integral factorises (Fubini, `integral_prod_mul`) into `𝔼[φᵢφⱼ]·ν̂(boxᵢ ∩ boxⱼ).toReal`, +which is `0` off the diagonal (disjoint boxes) and `𝔼[φⱼₗ²]·(tⱼ₊₁−tⱼ)·ν(Aₗ)` on it. -/ +theorem simpleIntegrand_sq_integral + {Nt m : ℕ} {t : ℕ → ℝ} (ht0 : 0 ≤ t 0) (hmono : Monotone t) + {A : ℕ → Set E} (hAms : ∀ l, MeasurableSet (A l)) (hAfin : ∀ l, ν (A l) ≠ ⊤) + (hAdisj : Pairwise (Function.onFun Disjoint A)) + {φ : ℕ → ℕ → Ω → ℝ} (hmemLp : ∀ j l, MemLp (φ j l) 2 P) : + ∫ p, (∑ j ∈ Finset.range Nt, ∑ l ∈ Finset.range m, + φ j l p.1 + * (Set.Ioc (t j) (t (j + 1)) ×ˢ A l).indicator (fun _ => (1 : ℝ)) p.2) ^ 2 + ∂(P.prod (referenceIntensity ν)) + = ∑ j ∈ Finset.range Nt, ∑ l ∈ Finset.range m, + (∫ ω, (φ j l ω) ^ 2 ∂P) * ((t (j + 1) - t j) * (ν (A l)).toReal) := by + classical + -- box of a pair index, and the elementary term + set box : ℕ × ℕ → Set (ℝ × E) := fun i => Set.Ioc (t i.1) (t (i.1 + 1)) ×ˢ A i.2 with hbox + set a : ℕ × ℕ → (Ω × (ℝ × E)) → ℝ := + fun i p => φ i.1 i.2 p.1 * (box i).indicator (fun _ => (1 : ℝ)) p.2 with ha + set I : Finset (ℕ × ℕ) := Finset.range Nt ×ˢ Finset.range m with hI + have ht0j : ∀ j, 0 ≤ t j := fun j => le_trans ht0 (hmono (Nat.zero_le j)) + have hboxms : ∀ i : ℕ × ℕ, MeasurableSet (box i) := fun i => measurableSet_Ioc.prod (hAms i.2) + have hboxfin : ∀ i : ℕ × ℕ, referenceIntensity ν (box i) ≠ ⊤ := + fun i => referenceIntensity_box_ne_top (hAfin i.2) + -- indicator product = indicator of the intersection + have hind : ∀ i j : ℕ × ℕ, + (fun z => (box i).indicator (fun _ => (1 : ℝ)) z * (box j).indicator (fun _ => (1 : ℝ)) z) + = (box i ∩ box j).indicator (fun _ => (1 : ℝ)) := by + intro i j; funext z + by_cases hzi : z ∈ box i <;> by_cases hzj : z ∈ box j <;> + simp [Set.indicator_of_mem, Set.indicator_of_notMem, Set.mem_inter_iff, hzi, hzj] + -- coefficient products are `L¹`; indicator products are `L¹` on the finite boxes + have hφint : ∀ i j : ℕ × ℕ, Integrable (fun ω => φ i.1 i.2 ω * φ j.1 j.2 ω) P := + fun i j => (hmemLp i.1 i.2).integrable_mul (hmemLp j.1 j.2) + have hGint : ∀ i j : ℕ × ℕ, Integrable + (fun z => (box i).indicator (fun _ => (1 : ℝ)) z * (box j).indicator (fun _ => (1 : ℝ)) z) + (referenceIntensity ν) := by + intro i j + rw [hind i j] + exact (integrable_indicator_iff ((hboxms i).inter (hboxms j))).mpr + (integrableOn_const (hs := (lt_of_le_of_lt (measure_mono Set.inter_subset_left) + (hboxfin i).lt_top).ne)) + -- product term: shape, integrability, value + have hprodform : ∀ i j : ℕ × ℕ, (fun p : Ω × (ℝ × E) => a i p * a j p) + = fun p => (φ i.1 i.2 p.1 * φ j.1 j.2 p.1) + * ((box i).indicator (fun _ => (1 : ℝ)) p.2 * + (box j).indicator (fun _ => (1 : ℝ)) p.2) := by + intro i j; funext p; simp only [ha]; ring + have hint : ∀ i j : ℕ × ℕ, + Integrable (fun p => a i p * a j p) (P.prod (referenceIntensity ν)) := by + intro i j; rw [hprodform i j]; exact (hφint i j).mul_prod (hGint i j) + have hterm : ∀ i j : ℕ × ℕ, ∫ p, a i p * a j p ∂(P.prod (referenceIntensity ν)) + = (∫ ω, φ i.1 i.2 ω * φ j.1 j.2 ω ∂P) * (referenceIntensity ν (box i ∩ box j)).toReal := by + intro i j + rw [hprodform i j, integral_prod_mul (fun ω => φ i.1 i.2 ω * φ j.1 j.2 ω) + (fun z => (box i).indicator (fun _ => (1 : ℝ)) z * (box j).indicator (fun _ => (1 : ℝ)) z), + hind i j, integral_indicator ((hboxms i).inter (hboxms j)), setIntegral_const, + smul_eq_mul, mul_one, measureReal_def] + -- distinct grid boxes are disjoint (time-index apart ⇒ disjoint in time; else in mark) + have hdisj : ∀ i j : ℕ × ℕ, i ≠ j → Disjoint (box i) (box j) := by + intro i j hij + rcases lt_trichotomy i.1 j.1 with hlt | heq | hgt + · have hle : t (i.1 + 1) ≤ t j.1 := hmono (Nat.succ_le_of_lt hlt) + rw [hbox, Set.disjoint_left] + rintro z hz1 hz2 + exact absurd (le_trans (Set.mem_Ioc.mp (Set.mem_prod.mp hz1).1).2 hle) + (not_le.mpr (Set.mem_Ioc.mp (Set.mem_prod.mp hz2).1).1) + · have hlm : i.2 ≠ j.2 := fun h => hij (Prod.ext heq h) + rw [hbox, Set.disjoint_left] + rintro z hz1 hz2 + exact (Set.disjoint_left.mp (hAdisj hlm)) (Set.mem_prod.mp hz1).2 (Set.mem_prod.mp hz2).2 + · have hle : t (j.1 + 1) ≤ t i.1 := hmono (Nat.succ_le_of_lt hgt) + rw [hbox, Set.disjoint_left] + rintro z hz1 hz2 + exact absurd (le_trans (Set.mem_Ioc.mp (Set.mem_prod.mp hz2).1).2 hle) + (not_le.mpr (Set.mem_Ioc.mp (Set.mem_prod.mp hz1).1).1) + -- fold the nested grid sum into a single pair sum + have hsum : ∀ p, (∑ i ∈ I, a i p) + = ∑ j ∈ Finset.range Nt, ∑ l ∈ Finset.range m, + φ j l p.1 + * (Set.Ioc (t j) (t (j + 1)) ×ˢ A l).indicator (fun _ => (1 : ℝ)) p.2 := by + intro p; simp only [hI, Finset.sum_product, ha, hbox] + calc ∫ p, (∑ j ∈ Finset.range Nt, ∑ l ∈ Finset.range m, + φ j l p.1 + * (Set.Ioc (t j) (t (j + 1)) ×ˢ A l).indicator (fun _ => (1 : ℝ)) p.2) ^ 2 + ∂(P.prod (referenceIntensity ν)) + = ∫ p, ∑ i ∈ I, ∑ j ∈ I, a i p * a j p ∂(P.prod (referenceIntensity ν)) := by + refine integral_congr_ae (Filter.Eventually.of_forall fun p => ?_) + change (∑ j ∈ Finset.range Nt, ∑ l ∈ Finset.range m, + φ j l p.1 + * (Set.Ioc (t j) (t (j + 1)) ×ˢ A l).indicator (fun _ => (1 : ℝ)) p.2) ^ 2 + = ∑ i ∈ I, ∑ j ∈ I, a i p * a j p + rw [← hsum p, pow_two, Finset.sum_mul_sum] + _ = ∑ i ∈ I, ∑ j ∈ I, ∫ p, a i p * a j p ∂(P.prod (referenceIntensity ν)) := by + rw [integral_finsetSum _ (fun i _ => integrable_finsetSum _ fun j _ => hint i j)] + exact Finset.sum_congr rfl fun i _ => integral_finsetSum _ fun j _ => hint i j + _ = ∑ i ∈ I, ∫ p, a i p * a i p ∂(P.prod (referenceIntensity ν)) := by + refine Finset.sum_congr rfl fun i hi => ?_ + refine Finset.sum_eq_single i (fun j _ hji => ?_) (fun hi' => absurd hi hi') + rw [hterm i j, Set.disjoint_iff_inter_eq_empty.mp (hdisj i j (Ne.symm hji)), + measure_empty, ENNReal.toReal_zero, mul_zero] + _ = ∑ i ∈ I, (∫ ω, (φ i.1 i.2 ω) ^ 2 ∂P) * ((t (i.1 + 1) - t i.1) * (ν (A i.2)).toReal) := by + refine Finset.sum_congr rfl fun i _ => ?_ + rw [hterm i i, Set.inter_self, hbox, + referenceIntensity_box_toReal (ν := ν) (ht0j i.1) (hmono (Nat.le_succ i.1))] + congr 1 + exact integral_congr_ae (Filter.Eventually.of_forall fun ω => (pow_two (φ i.1 i.2 ω)).symm) + _ = ∑ j ∈ Finset.range Nt, ∑ l ∈ Finset.range m, + (∫ ω, (φ j l ω) ^ 2 ∂P) * ((t (j + 1) - t j) * (ν (A l)).toReal) := by + simp only [hI, Finset.sum_product] + +/-- **The Itô–Lévy isometry in norm form.** `𝔼[(∫ H dÑ)²] = ‖H‖²_{L²(dP ⊗ dt ⊗ dν)}`: the +compensated integral of the simple integrand `H(ω,z) = ∑ⱼ∑ₗ φⱼₗ(ω)·𝟙_{(tⱼ,tⱼ₊₁]×Aₗ}(z)` has the same +`L²(P)`-norm as `H` has in `L²(P ⊗ ν̂)`. Combines B1's `compensated_simple_isometry` with the +integrand-norm computation; this is the norm identity the compensated-integral CLM completes from. +-/ +theorem compensated_integral_isometry (N : PoissonRandomMeasure P ν) + {Nt m : ℕ} {t : ℕ → ℝ} (ht0 : 0 ≤ t 0) (hmono : Monotone t) + {A : ℕ → Set E} (hAms : ∀ l, MeasurableSet (A l)) (hAfin : ∀ l, ν (A l) ≠ ⊤) + (hAdisj : Pairwise (Function.onFun Disjoint A)) + {φ : ℕ → ℕ → Ω → ℝ} (hadapt : ∀ j l, Measurable[N.pastFiltration (t j)] (φ j l)) + (hmemLp : ∀ j l, MemLp (φ j l) 2 P) : + ∫ ω, (∑ j ∈ Finset.range Nt, ∑ l ∈ Finset.range m, + φ j l ω * N.compensated (Set.Ioc (t j) (t (j + 1)) ×ˢ A l) ω) ^ 2 ∂P + = ∫ p, (∑ j ∈ Finset.range Nt, ∑ l ∈ Finset.range m, + φ j l p.1 + * (Set.Ioc (t j) (t (j + 1)) ×ˢ A l).indicator (fun _ => (1 : ℝ)) p.2) ^ 2 + ∂(P.prod (referenceIntensity ν)) := by + rw [compensated_simple_isometry N ht0 hmono hAms hAfin hAdisj hadapt hmemLp, + simpleIntegrand_sq_integral ht0 hmono hAms hAfin hAdisj hmemLp] + +end MathFin diff --git a/LeanPool/MathFin/Probability/Jumps/PoissonCompensatedIntegralOperator.lean b/LeanPool/MathFin/Probability/Jumps/PoissonCompensatedIntegralOperator.lean new file mode 100644 index 0000000000..58d8c47f5c --- /dev/null +++ b/LeanPool/MathFin/Probability/Jumps/PoissonCompensatedIntegralOperator.lean @@ -0,0 +1,459 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Jumps.PoissonCompensatedSimpleIntegrand +public import LeanPool.MathFin.Probability.Analysis.ExtendOfNormIsometry +public import LeanPool.MathFin.Probability.Analysis.LpMulIsometry +public import LeanPool.MathFin.Probability.Jumps.PoissonCompensatedBilinear + +/-! +# The compensated-Poisson integral operator on marked simple integrands + +The two linear maps out of the marked simple-integrand module `levySimpleModule`, mirroring the +continuous `ItoIntegralL2.itoAssembly` / `simpleAssembly`: + +* `intAssembly : levySimpleModule N →ₗ[ℝ] Lp ℝ 2 P` — the elementary compensated integral + `∑_b φ_b · Ñ(box b)`, viewed in `L²(P)`; +* `emb : levySimpleModule N →ₗ[ℝ] Lp ℝ 2 (P.prod (referenceIntensity ν))` — the integrand + `∑_b φ_b · 𝟙_{box b}`, viewed in `L²(dP ⊗ dν̂)` (the sibling module). + +The `L²` isometry `‖intAssembly V‖ = ‖emb V‖`, obtained by summing the overlapping-box bilinear +pairing `integral_bilinear_pairing`, and the `extendOfNorm` CLM are built on these. + +## Provenance + +The linear extension mirrors the continuous `ItoIntegralL2` assembly. The norm +identity is stated on the closure of marked simple integrands. LevyStochCalc's +`itoIsometry_compensated_unified_existence` proves a related horizon-wise isometry +as part of its càdlàg construction for progressively measurable integrands. + +## Main definitions + +* `intSum`, `intSumLp`: the elementary compensated integral `∑_b φ_b · Ñ(box b)` of a marked + simple integrand `V`, as a function and as a class in `L²(P)`. +* `intAssembly`: the elementary compensated integral as a linear map + `levySimpleModule N →ₗ[ℝ] L²(P)`. +* `embFun`, `embLp`: the integrand `∑_b φ_b · 𝟙_{box b}`, as a function on `Ω × (ℝ × E)` and as a + class in `L²(P ⊗ ν̂)`. +* `emb`: the integrand embedding as a linear map `levySimpleModule N →ₗ[ℝ] L²(P ⊗ ν̂)`. +* `levyClosure`: the `L²(P ⊗ ν̂)` closure of the range of `emb`. +* `embCorestrict`: `emb` corestricted to `levyClosure`. +* `itoLevyIntegralL2`: the continuous linear extension of the elementary integral to + `levyClosure N →L[ℝ] L²(P)`. + +## Main results + +* `assembly_isometry`: `‖intAssembly N V‖ = ‖emb N V‖` for every marked simple integrand `V`. +* `embCorestrict_denseRange`: the marked simple integrands are dense in `levyClosure N`. +* `itoLevyIntegralL2_norm`: `‖itoLevyIntegralL2 N H‖ = ‖H‖` for every `H` in `levyClosure N`. +* `intSum_sq_integral`, `embFun_sq_integral`: the squared norms of `intSum` and `embFun` expand + as double sums over the box family. + +## References + +* [Applebaum (2009)][Applebaum2009], Thm 4.2.3 +* [*cgarryZA/LevyStochCalc*][LevyStochCalc], `itoIsometry_compensated_unified_existence` + (related Itô–Lévy isometry for progressively measurable integrands) + +## Tags + +compensated Poisson integral, marked simple integrands, elementary integral, +Itô–Lévy integral operator, Lévy stochastic integral, MSC 60G51, MSC 60H05, MSC 60G55 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal InnerProductSpace + +variable {Ω : Type*} [MeasurableSpace Ω] {E : Type*} [MeasurableSpace E] + {P : Measure Ω} [IsProbabilityMeasure P] {ν : Measure E} [SigmaFinite ν] + +/-- A marked simple integrand's coefficient is in `L²(P)`: it is bounded (hence `L^∞`) and +measurable, so on the probability space it is `L²`. -/ +lemma IsLevySimple.memLp_coe {N : PoissonRandomMeasure P ν} {V : (ℝ × ℝ × Set E) →₀ (Ω → ℝ)} + (hV : IsLevySimple N V) (b : ℝ × ℝ × Set E) : MemLp (V b) 2 P := by + obtain ⟨C, _, hC⟩ := hV.bound_coe + have hm : Measurable (V b) := (hV.measurable_coe b).mono (N.pastFiltration.le b.1) le_rfl + exact (memLp_top_of_bound hm.aestronglyMeasurable C + (ae_of_all _ fun ω => by rw [Real.norm_eq_abs]; exact hC b ω)).mono_exponent le_top + +/-! ### The elementary compensated integral as a linear map -/ + +/-- The **elementary compensated integral** `∑_{b} φ_b(·) · Ñ(box b)(·)` of a marked simple +integrand, as a function `Ω → ℝ`. -/ +noncomputable def intSum (N : PoissonRandomMeasure P ν) (V : levySimpleModule N) : Ω → ℝ := + V.1.sum fun b φ => fun ω => φ ω * N.compensated (indexBox b) ω + +/-- The elementary integral is in `L²(P)`: a finite sum of `L²` terms `φ_b · Ñ(box b)` +(`memLp_adapted_mul_compensated`). -/ +lemma memLp_intSum (N : PoissonRandomMeasure P ν) (V : levySimpleModule N) : + MemLp (intSum N V) 2 P := by + have hrw : intSum N V + = fun ω => ∑ b ∈ V.1.support, V.1 b ω * N.compensated (indexBox b) ω := by + funext ω; simp only [intSum, Finsupp.sum, Finset.sum_apply] + rw [hrw] + exact memLp_finsetSum V.1.support fun b hb => + memLp_adapted_mul_compensated N (V.2.markMeasurable b hb) (V.2.markFinite b hb) + (V.2.adapted b hb) (V.2.memLp_coe b) + +/-- The elementary integral is additive in the integrand. -/ +lemma intSum_add (N : PoissonRandomMeasure P ν) (V W : levySimpleModule N) : + intSum N (V + W) = intSum N V + intSum N W := by + have key : ((V + W : levySimpleModule N) : (ℝ × ℝ × Set E) →₀ (Ω → ℝ)) + = (V : (ℝ × ℝ × Set E) →₀ (Ω → ℝ)) + (W : (ℝ × ℝ × Set E) →₀ (Ω → ℝ)) := rfl + simp only [intSum, key] + exact Finsupp.sum_add_index' (fun b => funext fun ω => by simp) + (fun b φ ψ => funext fun ω => by simp [add_mul]) + +/-- The elementary integral is homogeneous in the integrand. -/ +lemma intSum_smul (N : PoissonRandomMeasure P ν) (c : ℝ) (V : levySimpleModule N) : + intSum N (c • V) = c • intSum N V := by + have key : ((c • V : levySimpleModule N) : (ℝ × ℝ × Set E) →₀ (Ω → ℝ)) + = c • (V : (ℝ × ℝ × Set E) →₀ (Ω → ℝ)) := rfl + simp only [intSum, key] + rw [Finsupp.sum_smul_index' (fun b => funext fun ω => by simp)] + simp only [Finsupp.sum] + rw [Finset.smul_sum] + exact Finset.sum_congr rfl fun b _ => funext fun ω => by simp [smul_eq_mul, mul_assoc] + +/-- The elementary integral, in `L²(P)`. -/ +noncomputable def intSumLp (N : PoissonRandomMeasure P ν) (V : levySimpleModule N) : Lp ℝ 2 P := + (memLp_intSum N V).toLp + +/-- **The compensated-Poisson integral as a linear map** `levySimpleModule →ₗ[ℝ] L²(P)`. -/ +noncomputable def intAssembly (N : PoissonRandomMeasure P ν) : + levySimpleModule N →ₗ[ℝ] Lp ℝ 2 P where + toFun V := intSumLp N V + map_add' V W := by + rw [intSumLp, intSumLp, intSumLp, + ← MemLp.toLp_add (memLp_intSum N V) (memLp_intSum N W)] + congr 1 + exact intSum_add N V W + map_smul' c V := by + rw [intSumLp, intSumLp, RingHom.id_apply, ← MemLp.toLp_const_smul c (memLp_intSum N V)] + congr 1 + exact intSum_smul N c V + +/-! ### The integrand embedding into the predictable `L²(dP ⊗ dν̂)` -/ + +omit [IsProbabilityMeasure P] in +/-- A single box term `φ(ω)·𝟙_{(s,t]×A}(z)` is in `L²(P ⊗ ν̂)`: its square is +`φ(ω)² · 𝟙_box(z)`, an `L¹` product of `φ² ∈ L¹(P)` and the finite-box indicator `∈ L¹(ν̂)` +(`Integrable.mul_prod`). -/ +lemma memLp_indicatorTerm {s t : ℝ} {A : Set E} + (hA : MeasurableSet A) (hAfin : ν A ≠ ⊤) {φ : Ω → ℝ} (hφm : Measurable φ) + (hφL2 : MemLp φ 2 P) : + MemLp (fun p : Ω × (ℝ × E) => φ p.1 * (Set.Ioc s t ×ˢ A).indicator (fun _ => (1 : ℝ)) p.2) 2 + (P.prod (referenceIntensity ν)) := by + have hboxms : MeasurableSet (Set.Ioc s t ×ˢ A) := measurableSet_Ioc.prod hA + have hboxfin : referenceIntensity ν (Set.Ioc s t ×ˢ A) ≠ ⊤ := referenceIntensity_box_ne_top hAfin + have hgm : Measurable + (fun p : Ω × (ℝ × E) => φ p.1 * (Set.Ioc s t ×ˢ A).indicator (fun _ => (1 : ℝ)) p.2) := + (hφm.comp measurable_fst).mul ((measurable_const.indicator hboxms).comp measurable_snd) + refine (memLp_two_iff_integrable_sq hgm.aestronglyMeasurable).mpr ?_ + have hform : (fun p : Ω × (ℝ × E) => + (φ p.1 * (Set.Ioc s t ×ˢ A).indicator (fun _ => (1 : ℝ)) p.2) ^ 2) + = fun p => (φ p.1) ^ 2 * ((Set.Ioc s t ×ˢ A).indicator (fun _ => (1 : ℝ)) p.2 + * (Set.Ioc s t ×ˢ A).indicator (fun _ => (1 : ℝ)) p.2) := by + funext p; ring + rw [hform] + have hg : Integrable (fun z : ℝ × E => (Set.Ioc s t ×ˢ A).indicator (fun _ => (1 : ℝ)) z + * (Set.Ioc s t ×ˢ A).indicator (fun _ => (1 : ℝ)) z) (referenceIntensity ν) := by + rw [show (fun z : ℝ × E => (Set.Ioc s t ×ˢ A).indicator (fun _ => (1 : ℝ)) z + * (Set.Ioc s t ×ˢ A).indicator (fun _ => (1 : ℝ)) z) + = (Set.Ioc s t ×ˢ A).indicator (fun _ => (1 : ℝ)) from by + funext z; by_cases hz : z ∈ Set.Ioc s t ×ˢ A <;> + simp [Set.indicator_of_mem, Set.indicator_of_notMem, hz]] + exact (integrable_indicator_iff hboxms).mpr (integrableOn_const (hs := hboxfin)) + exact (hφL2.integrable_sq).mul_prod hg + +/-- The **integrand** `∑_b φ_b(·) · 𝟙_{box b}(·)` of a marked simple integrand, a function on +`Ω × (ℝ × E)`. -/ +noncomputable def embFun (N : PoissonRandomMeasure P ν) (V : levySimpleModule N) : + Ω × (ℝ × E) → ℝ := + V.1.sum fun b φ => fun p => φ p.1 * (indexBox b).indicator (fun _ => (1 : ℝ)) p.2 + +/-- The integrand is in `L²(P ⊗ ν̂)`: a finite sum of `L²` box terms (`memLp_indicatorTerm`). -/ +lemma memLp_embFun (N : PoissonRandomMeasure P ν) (V : levySimpleModule N) : + MemLp (embFun N V) 2 (P.prod (referenceIntensity ν)) := by + have hrw : embFun N V = fun p => ∑ b ∈ V.1.support, + V.1 b p.1 * (Set.Ioc b.1 b.2.1 ×ˢ b.2.2).indicator (fun _ => (1 : ℝ)) p.2 := by + funext p; simp only [embFun, indexBox, Finsupp.sum, Finset.sum_apply] + rw [hrw] + refine memLp_finsetSum V.1.support ?_ + intro b hb + exact memLp_indicatorTerm (V.2.markMeasurable b hb) (V.2.markFinite b hb) + ((V.2.measurable_coe b).mono (N.pastFiltration.le b.1) le_rfl) (V.2.memLp_coe b) + +/-- The integrand embedding is additive in the integrand. -/ +lemma embFun_add (N : PoissonRandomMeasure P ν) (V W : levySimpleModule N) : + embFun N (V + W) = embFun N V + embFun N W := by + have key : ((V + W : levySimpleModule N) : (ℝ × ℝ × Set E) →₀ (Ω → ℝ)) + = (V : (ℝ × ℝ × Set E) →₀ (Ω → ℝ)) + (W : (ℝ × ℝ × Set E) →₀ (Ω → ℝ)) := rfl + simp only [embFun, key] + exact Finsupp.sum_add_index' (fun b => funext fun p => by simp) + (fun b φ ψ => funext fun p => by simp [add_mul]) + +/-- The integrand embedding is homogeneous in the integrand. -/ +lemma embFun_smul (N : PoissonRandomMeasure P ν) (c : ℝ) (V : levySimpleModule N) : + embFun N (c • V) = c • embFun N V := by + have key : ((c • V : levySimpleModule N) : (ℝ × ℝ × Set E) →₀ (Ω → ℝ)) + = c • (V : (ℝ × ℝ × Set E) →₀ (Ω → ℝ)) := rfl + simp only [embFun, key] + rw [Finsupp.sum_smul_index' (fun b => funext fun p => by simp)] + simp only [Finsupp.sum] + rw [Finset.smul_sum] + exact Finset.sum_congr rfl fun b _ => funext fun p => by simp [smul_eq_mul, mul_assoc] + +/-- The integrand, in `L²(P ⊗ ν̂)`. -/ +noncomputable def embLp (N : PoissonRandomMeasure P ν) (V : levySimpleModule N) : + Lp ℝ 2 (P.prod (referenceIntensity ν)) := (memLp_embFun N V).toLp + +/-- **The integrand embedding as a linear map** `levySimpleModule →ₗ[ℝ] L²(dP ⊗ dν̂)`. -/ +noncomputable def emb (N : PoissonRandomMeasure P ν) : + levySimpleModule N →ₗ[ℝ] Lp ℝ 2 (P.prod (referenceIntensity ν)) where + toFun V := embLp N V + map_add' V W := by + rw [embLp, embLp, embLp, ← MemLp.toLp_add (memLp_embFun N V) (memLp_embFun N W)] + congr 1 + exact embFun_add N V W + map_smul' c V := by + rw [embLp, embLp, RingHom.id_apply, ← MemLp.toLp_const_smul c (memLp_embFun N V)] + congr 1 + exact embFun_smul N c V + +/-! ### The isometry `‖intAssembly V‖ = ‖emb V‖` (summing the bilinear pairing) -/ + +/-- Each box term of the elementary integral is in `L²(P)`. -/ +lemma memLp_intTerm (N : PoissonRandomMeasure P ν) (V : levySimpleModule N) + {b : ℝ × ℝ × Set E} (hb : b ∈ V.1.support) : + MemLp (fun ω => V.1 b ω * N.compensated (indexBox b) ω) 2 P := + memLp_adapted_mul_compensated N (V.2.markMeasurable b hb) (V.2.markFinite b hb) + (V.2.adapted b hb) (V.2.memLp_coe b) + +/-- Each box term of the integrand is in `L²(P ⊗ ν̂)`. -/ +lemma memLp_embTerm (N : PoissonRandomMeasure P ν) (V : levySimpleModule N) + {b : ℝ × ℝ × Set E} (hb : b ∈ V.1.support) : + MemLp (fun p : Ω × (ℝ × E) => V.1 b p.1 * (indexBox b).indicator (fun _ => (1 : ℝ)) p.2) 2 + (P.prod (referenceIntensity ν)) := + memLp_indicatorTerm (V.2.markMeasurable b hb) (V.2.markFinite b hb) + ((V.2.measurable_coe b).mono (N.pastFiltration.le b.1) le_rfl) (V.2.memLp_coe b) + +/-- A pair of elementary-integral box terms has an integrable product (`L² · L²`), in scalar-lambda +form (so the double-sum `∫ = ∑∫` rewrites match). -/ +lemma integrable_intPair (N : PoissonRandomMeasure P ν) (V : levySimpleModule N) + {ba bb : ℝ × ℝ × Set E} (hba : ba ∈ V.1.support) (hbb : bb ∈ V.1.support) : + Integrable (fun ω => (V.1 ba ω * N.compensated (indexBox ba) ω) + * (V.1 bb ω * N.compensated (indexBox bb) ω)) P := + (memLp_intTerm N V hba).integrable_mul (memLp_intTerm N V hbb) + +/-- A pair of integrand box terms has an integrable product (`L² · L²`), in scalar-lambda form. -/ +lemma integrable_embPair (N : PoissonRandomMeasure P ν) (V : levySimpleModule N) + {ba bb : ℝ × ℝ × Set E} (hba : ba ∈ V.1.support) (hbb : bb ∈ V.1.support) : + Integrable (fun p : Ω × (ℝ × E) => + (V.1 ba p.1 * (indexBox ba).indicator (fun _ => (1 : ℝ)) p.2) + * (V.1 bb p.1 * (indexBox bb).indicator (fun _ => (1 : ℝ)) p.2)) + (P.prod (referenceIntensity ν)) := + (memLp_embTerm N V hba).integrable_mul (memLp_embTerm N V hbb) + +/-- **The `L²(P)` second moment as a double sum** over the box family. -/ +lemma intSum_sq_integral (N : PoissonRandomMeasure P ν) (V : levySimpleModule N) : + ∫ ω, (intSum N V ω) ^ 2 ∂P + = ∑ ba ∈ V.1.support, ∑ bb ∈ V.1.support, + ∫ ω, (V.1 ba ω * N.compensated (indexBox ba) ω) + * (V.1 bb ω * N.compensated (indexBox bb) ω) ∂P := by + have hrw : intSum N V + = fun ω => ∑ b ∈ V.1.support, V.1 b ω * N.compensated (indexBox b) ω := by + funext ω; simp only [intSum, Finsupp.sum, Finset.sum_apply] + rw [hrw] + have hsq : (fun ω => (∑ b ∈ V.1.support, V.1 b ω * N.compensated (indexBox b) ω) ^ 2) + = fun ω => ∑ ba ∈ V.1.support, ∑ bb ∈ V.1.support, + (V.1 ba ω * N.compensated (indexBox ba) ω) + * (V.1 bb ω * N.compensated (indexBox bb) ω) := by + funext ω; rw [sq, Finset.sum_mul_sum] + rw [hsq] + rw [integral_finsetSum V.1.support fun ba hba => integrable_finsetSum V.1.support fun bb hbb => + integrable_intPair N V hba hbb] + refine Finset.sum_congr rfl fun ba hba => ?_ + exact integral_finsetSum V.1.support fun bb hbb => + integrable_intPair N V hba hbb + +/-- **The `L²(P ⊗ ν̂)` integrand norm as a double sum** over the box family. -/ +lemma embFun_sq_integral (N : PoissonRandomMeasure P ν) (V : levySimpleModule N) : + ∫ p, (embFun N V p) ^ 2 ∂(P.prod (referenceIntensity ν)) + = ∑ ba ∈ V.1.support, ∑ bb ∈ V.1.support, + ∫ p, (V.1 ba p.1 * (indexBox ba).indicator (fun _ => (1 : ℝ)) p.2) + * (V.1 bb p.1 * (indexBox bb).indicator (fun _ => (1 : ℝ)) p.2) + ∂(P.prod (referenceIntensity ν)) := by + have hrw : embFun N V = fun p => ∑ b ∈ V.1.support, + V.1 b p.1 * (indexBox b).indicator (fun _ => (1 : ℝ)) p.2 := by + funext p; simp only [embFun, Finsupp.sum, Finset.sum_apply] + rw [hrw] + have hsq : (fun p : Ω × (ℝ × E) => + (∑ b ∈ V.1.support, V.1 b p.1 * (indexBox b).indicator (fun _ => (1 : ℝ)) p.2) ^ 2) + = fun p => ∑ ba ∈ V.1.support, ∑ bb ∈ V.1.support, + (V.1 ba p.1 * (indexBox ba).indicator (fun _ => (1 : ℝ)) p.2) + * (V.1 bb p.1 * (indexBox bb).indicator (fun _ => (1 : ℝ)) p.2) := by + funext p; rw [sq, Finset.sum_mul_sum] + rw [hsq] + rw [integral_finsetSum V.1.support fun ba hba => integrable_finsetSum V.1.support fun bb hbb => + integrable_embPair N V hba hbb] + refine Finset.sum_congr rfl fun ba hba => ?_ + exact integral_finsetSum V.1.support fun bb hbb => + integrable_embPair N V hba hbb + +/-- **The per-pair identity** connecting the two double sums: the compensated-integral pairing of +two box terms equals the `L²(P ⊗ ν̂)` pairing of the two integrand terms — both are +`𝔼[φ_ba φ_bb] · ν̂(box ba ∩ box bb)`. The `⟵` is the overlapping-box bilinear pairing +`integral_bilinear_pairing` (rung 2, ordering the pair by start), the `⟶` is Fubini +(`integral_prod_mul`) on the product measure. -/ +lemma pair_integral_eq (N : PoissonRandomMeasure P ν) (V : levySimpleModule N) + {ba bb : ℝ × ℝ × Set E} (hba : ba ∈ V.1.support) (hbb : bb ∈ V.1.support) : + ∫ ω, (V.1 ba ω * N.compensated (indexBox ba) ω) + * (V.1 bb ω * N.compensated (indexBox bb) ω) ∂P + = ∫ p, (V.1 ba p.1 * (indexBox ba).indicator (fun _ => (1 : ℝ)) p.2) + * (V.1 bb p.1 * (indexBox bb).indicator (fun _ => (1 : ℝ)) p.2) + ∂(P.prod (referenceIntensity ν)) := by + obtain ⟨C, _, hC⟩ := V.2.bound_coe + have hboxams : MeasurableSet (indexBox ba) := measurableSet_Ioc.prod (V.2.markMeasurable ba hba) + have hboxbms : MeasurableSet (indexBox bb) := measurableSet_Ioc.prod (V.2.markMeasurable bb hbb) + -- the compensated pairing equals `𝔼[φ_ba φ_bb] · ν̂(box ba ∩ box bb)` (WLOG order by start) + have hLHS : ∫ ω, (V.1 ba ω * N.compensated (indexBox ba) ω) + * (V.1 bb ω * N.compensated (indexBox bb) ω) ∂P + = (∫ ω, V.1 ba ω * V.1 bb ω ∂P) + * (referenceIntensity ν (indexBox ba ∩ indexBox bb)).toReal := by + rcases le_total ba.1 bb.1 with hab | hab + · exact integral_bilinear_pairing N hab (V.2.markMeasurable ba hba) (V.2.markMeasurable bb hbb) + (V.2.markFinite ba hba) (V.2.markFinite bb hbb) (V.2.adapted ba hba) (V.2.adapted bb hbb) + (fun ω => hC ba ω) (fun ω => hC bb ω) + · have hpair := integral_bilinear_pairing N (ta := bb.2.1) (tb := ba.2.1) hab + (V.2.markMeasurable bb hbb) (V.2.markMeasurable ba hba) (V.2.markFinite bb hbb) + (V.2.markFinite ba hba) (V.2.adapted bb hbb) (V.2.adapted ba hba) + (fun ω => hC bb ω) (fun ω => hC ba ω) + calc ∫ ω, (V.1 ba ω * N.compensated (indexBox ba) ω) + * (V.1 bb ω * N.compensated (indexBox bb) ω) ∂P + = ∫ ω, (V.1 bb ω * N.compensated (indexBox bb) ω) + * (V.1 ba ω * N.compensated (indexBox ba) ω) ∂P := + integral_congr_ae (Filter.Eventually.of_forall fun ω => by ring) + _ = (∫ ω, V.1 bb ω * V.1 ba ω ∂P) + * (referenceIntensity ν (indexBox bb ∩ indexBox ba)).toReal := hpair + _ = (∫ ω, V.1 ba ω * V.1 bb ω ∂P) + * (referenceIntensity ν (indexBox ba ∩ indexBox bb)).toReal := by + rw [Set.inter_comm (indexBox bb) (indexBox ba)] + congr 1 + exact integral_congr_ae (Filter.Eventually.of_forall fun ω => by ring) + -- the integrand pairing equals the same, by Fubini + have hRHS : ∫ p, (V.1 ba p.1 * (indexBox ba).indicator (fun _ => (1 : ℝ)) p.2) + * (V.1 bb p.1 * (indexBox bb).indicator (fun _ => (1 : ℝ)) p.2) + ∂(P.prod (referenceIntensity ν)) + = (∫ ω, V.1 ba ω * V.1 bb ω ∂P) + * (referenceIntensity ν (indexBox ba ∩ indexBox bb)).toReal := by + have hind : (fun z : ℝ × E => (indexBox ba).indicator (fun _ => (1 : ℝ)) z + * (indexBox bb).indicator (fun _ => (1 : ℝ)) z) + = (indexBox ba ∩ indexBox bb).indicator (fun _ => (1 : ℝ)) := by + funext z; by_cases hzi : z ∈ indexBox ba <;> by_cases hzj : z ∈ indexBox bb <;> + simp [Set.indicator_of_mem, Set.indicator_of_notMem, Set.mem_inter_iff, hzi, hzj] + rw [show (fun p : Ω × (ℝ × E) => + (V.1 ba p.1 * (indexBox ba).indicator (fun _ => (1 : ℝ)) p.2) + * (V.1 bb p.1 * (indexBox bb).indicator (fun _ => (1 : ℝ)) p.2)) + = fun p => (V.1 ba p.1 * V.1 bb p.1) + * ((indexBox ba).indicator (fun _ => (1 : ℝ)) p.2 + * (indexBox bb).indicator (fun _ => (1 : ℝ)) p.2) from by funext p; ring, + integral_prod_mul (fun ω => V.1 ba ω * V.1 bb ω) + (fun z => (indexBox ba).indicator (fun _ => (1 : ℝ)) z + * (indexBox bb).indicator (fun _ => (1 : ℝ)) z), + hind, integral_indicator (hboxams.inter hboxbms), setIntegral_const, smul_eq_mul, mul_one, + measureReal_def] + rw [hLHS, hRHS] + +/-- **The Itô–Lévy isometry on marked simple integrands** (the identity `extendOfNorm` consumes): +`‖intAssembly V‖ = ‖emb V‖`. Both squared norms expand into the same box-family double sum, equal +term-by-term by `pair_integral_eq` — i.e. the compensated integral into `L²(P)` and the integrand in +`L²(P ⊗ ν̂)` have equal norms. -/ +theorem assembly_isometry (N : PoissonRandomMeasure P ν) (V : levySimpleModule N) : + ‖intAssembly N V‖ = ‖emb N V‖ := by + have hsq : ‖intAssembly N V‖ ^ 2 = ‖emb N V‖ ^ 2 := by + change ‖(intSumLp N V : Lp ℝ 2 P)‖ ^ 2 = + ‖(embLp N V : Lp ℝ 2 (P.prod (referenceIntensity ν)))‖ ^ 2 + rw [lp_two_norm_sq, lp_two_norm_sq] + rw [show (∫ ω, ((intSumLp N V : Ω → ℝ) ω) ^ 2 ∂P) = ∫ ω, (intSum N V ω) ^ 2 ∂P from + integral_congr_ae (by + filter_upwards [(memLp_intSum N V).coeFn_toLp] with ω hω; simp only [intSumLp]; rw [hω]), + show (∫ p, ((embLp N V : Ω × (ℝ × E) → ℝ) p) ^ 2 ∂(P.prod (referenceIntensity ν))) + = ∫ p, (embFun N V p) ^ 2 ∂(P.prod (referenceIntensity ν)) from + integral_congr_ae (by + filter_upwards [(memLp_embFun N V).coeFn_toLp] with p hp; simp only [embLp]; rw [hp]), + intSum_sq_integral, embFun_sq_integral] + exact Finset.sum_congr rfl fun ba hba => Finset.sum_congr rfl fun bb hbb => + pair_integral_eq N V hba hbb + exact (sq_eq_sq₀ (norm_nonneg _) (norm_nonneg _)).mp hsq + +/-! ### The Itô–Lévy integral CLM on the `L²` closure of the simple integrands -/ + +/-- **The `L²(dP ⊗ dν̂)` closure of the marked simple integrands** — the domain of the extended +Itô–Lévy integral. Concretely the topological closure of `emb`'s range: every element is an `L²` +limit of marked simple integrands `∑_b φ_b · 𝟙_{box b}`. Defining the target *as* this closure makes +the extension's density hypothesis a soft topological fact (`embCorestrict_denseRange`), +sidestepping an explicit marked-predictable `σ`-algebra characterisation. -/ +noncomputable def levyClosure (N : PoissonRandomMeasure P ν) : + Submodule ℝ (Lp ℝ 2 (P.prod (referenceIntensity ν))) := + (LinearMap.range (emb N)).topologicalClosure + +/-- The integrand embedding `emb`, corestricted to the closure `levyClosure` of its range — the +dense-range map along which the elementary integral extends. -/ +noncomputable def embCorestrict (N : PoissonRandomMeasure P ν) : + levySimpleModule N →ₗ[ℝ] levyClosure N := + (emb N).codRestrict (levyClosure N) + (fun V => Submodule.le_topologicalClosure _ (LinearMap.mem_range_self (emb N) V)) + +/-- **Marked simple integrands are dense in their `L²` closure** `levyClosure`. Pushed into the +ambient `L²` the corestricted embedding's range is exactly `emb`'s range, whose closure is +`levyClosure` by construction; so every element of the closure subtype lies in the closure of that +range (`IsInducing.subtypeVal.dense_iff`). -/ +theorem embCorestrict_denseRange (N : PoissonRandomMeasure P ν) : + DenseRange (embCorestrict N) := by + have hind : Topology.IsInducing ((↑) : levyClosure N → Lp ℝ 2 (P.prod (referenceIntensity ν))) := + Topology.IsInducing.subtypeVal + rw [DenseRange, hind.dense_iff] + intro x + have himg : ((↑) : levyClosure N → Lp ℝ 2 (P.prod (referenceIntensity ν))) + '' Set.range (embCorestrict N) + = Set.range (emb N) := by + rw [← Set.range_comp]; rfl + rw [himg, ← LinearMap.coe_range, ← Submodule.topologicalClosure_coe] + exact x.2 + +/-- **The Itô–Lévy compensated-Poisson integral as a CLM** on the `L²` closure of the marked simple +integrands: the norm-continuous extension of the elementary integral `intAssembly` along the dense +embedding `embCorestrict` (`LinearMap.extendOfNorm`). -/ +noncomputable def itoLevyIntegralL2 (N : PoissonRandomMeasure P ν) : + levyClosure N →L[ℝ] Lp ℝ 2 P := by + -- `refine … ?_; exact` rather than a bare `(intAssembly N).extendOfNorm (embCorestrict N)`: the + -- CLM goal type pins `Eₗ = ↥(levyClosure N)` with its seminormed-group instances, so `exact` + -- bridges the `Submodule.addCommMonoid` vs seminormed `AddCommMonoid` diamond in one cheap + -- `isDefEq`. (docs/patterns.md — "extendOfNorm into a submodule".) + refine LinearMap.extendOfNorm (E := ↥(levySimpleModule N)) (F := Lp ℝ 2 P) (intAssembly N) ?_ + exact embCorestrict N + +/-- **Compensated-Poisson norm isometry on the closure of marked simple integrands.** +The overlapping-box bilinear pairing proves the norm identity on marked simple +integrands (`assembly_isometry`). The identity extends by continuity to `levyClosure`. -/ +theorem itoLevyIntegralL2_norm (N : PoissonRandomMeasure P ν) (H : levyClosure N) : + ‖itoLevyIntegralL2 N H‖ = ‖H‖ := by + have key : ∀ V : levySimpleModule N, ‖intAssembly N V‖ = ‖embCorestrict N V‖ := + fun V => by rw [← Submodule.norm_coe]; exact assembly_isometry N V + -- `unfold` exposes the def's already-bridged `extendOfNorm` term; discharging the isometry kernel + -- against the submodule codomain reuses the finite instance comparison. + unfold itoLevyIntegralL2 + exact LinearMap.norm_extendOfNorm_eq_of_isometry (embCorestrict_denseRange N) key H + +end MathFin diff --git a/LeanPool/MathFin/Probability/Jumps/PoissonCompensatedIsometryAdapted.lean b/LeanPool/MathFin/Probability/Jumps/PoissonCompensatedIsometryAdapted.lean new file mode 100644 index 0000000000..cceede4009 --- /dev/null +++ b/LeanPool/MathFin/Probability/Jumps/PoissonCompensatedIsometryAdapted.lean @@ -0,0 +1,263 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Jumps.PoissonRandomMeasure +public import LeanPool.MathFin.Probability.Analysis.IndepIsometryKernel +public import Mathlib.Probability.Process.Filtration + +/-! +# The compensated-Poisson isometry kernel (increment-independence cornerstone) + +The jump analogue of `Probability/Brownian/Ito/ItoIsometryAdapted.lean`. For a Poisson random +measure `N`, the second-moment energy identities that the Itô–Lévy isometry sums are: + +* diagonal `𝔼[φ² · Ñ(box)²] = 𝔼[φ²] · ν̂(box)` (`integral_adapted_sq_mul_compensated_sq`); +* cross `𝔼[φ · Ñ(box₁) · ψ · Ñ(box₂)] = 0` for disjoint boxes with `box₁` in the past-region + of `box₂` (`integral_cross_compensated_eq_zero`). + +Both flow from the single structure field `indep_of_disjoint_region` (independent scattering): +`N` on any region disjoint from `D` is independent of `N(·, D)`. The past `σ`-algebra at a time +`s` and the count on any box disjoint from a future box both live in that "disjoint region", so +one field closes every cross-term — the different-time cross pairs *and* the same-time / +different-mark cross pairs that a `time × mark` simple integrand produces. + +The one-term facts that follow from independence (mean zero, diagonal energy, `L²`-membership) +are the Brownian ones, stated once in `IndepIsometryKernel`. + +## Provenance + +Design mirrors our continuous `ItoIsometryAdapted`; the PRM object is from +`Probability/Jumps/PoissonRandomMeasure` (field shape consulted from `cgarryZA/LevyStochCalc`, +cited). This file proves the isometry on simple adapted integrands. The +related LevyStochCalc theorem `itoIsometry_compensated_unified_existence` +includes an isometry for progressively measurable integrands. + +## Main definitions + +* `PoissonRandomMeasure.pastFiltration`: the filtration whose time-`s` σ-algebra is generated by + the counts on measurable space-time sets contained in `(-∞, s] × E`. +* `PoissonRandomMeasure.regionSigma`: the σ-algebra generated by the counts on measurable + space-time sets disjoint from `D`. + +## Main results + +* `adapted_indepFun_compensated`: an integrand adapted at `s` is independent of + `Ñ((s, t] × A)`. +* `integral_mul_compensated_eq_zero`: `𝔼[X·Ñ(D)] = 0` for `X` measurable for `regionSigma D`, + with `D` measurable of finite intensity. +* `integral_adapted_sq_mul_compensated_sq`: `𝔼[φ²·Ñ((s, t] × A)²] = 𝔼[φ²]·ν̂((s, t] × A)` for `φ` + adapted at `s`. +* `integral_cross_compensated_eq_zero`: the cross term `𝔼[φa Ñ(Ba)·φb Ñ((sb, tb] × Ab)]` vanishes + for `sa ≤ sb` and `Ba` disjoint from `(sb, tb] × Ab`. +* `memLp_adapted_mul_compensated`: `φ·Ñ((s, t] × A)` is in `L²(P)` for adapted `L²` `φ`. +* `referenceIntensity_box_toReal`: `ν̂((a, b] × A).toReal = (b − a)·(ν A).toReal` for `0 ≤ a ≤ b`. + +## Tags + +Itô–Lévy isometry, compensated Poisson measure, second moment identity, independent scattering, +adapted jump integrand, MSC 60G51, MSC 60H05, MSC 60G55 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +variable {Ω : Type*} [MeasurableSpace Ω] {E : Type*} [MeasurableSpace E] + {P : Measure Ω} [IsProbabilityMeasure P] {ν : Measure E} [SigmaFinite ν] + +/-! ### The past and disjoint-region `σ`-algebras -/ + +/-- The **PRM past filtration** — at time `s` the `σ`-algebra generated by the counts on +space-time sets contained in `(-∞, s] × E`. "Adapted at `s`" is `Measurable[N.pastFiltration s]`, +the same predicate the Brownian isometry core states against `𝓕 s`. -/ +def PoissonRandomMeasure.pastFiltration (N : PoissonRandomMeasure P ν) : + Filtration ℝ (inferInstance : MeasurableSpace Ω) where + seq s := ⨆ C ∈ {C : Set (ℝ × E) | C ⊆ Set.Iic s ×ˢ Set.univ ∧ MeasurableSet C}, + MeasurableSpace.comap (fun ω => N.N ω C) inferInstance + mono' _ _ h := iSup₂_le fun C hC => le_iSup₂_of_le C + ⟨hC.1.trans (Set.prod_mono (Set.Iic_subset_Iic.2 h) le_rfl), hC.2⟩ le_rfl + le' _ := iSup₂_le fun _ hC => measurable_iff_comap_le.mp (N.measurable_eval hC.2) + +/-- The **disjoint-region `σ`-algebra of `D`** — generated by the counts on all measurable +space-time sets disjoint from `D`. This is the left factor of the `indep_of_disjoint_region` +independence, made into a named object. -/ +@[reducible] def PoissonRandomMeasure.regionSigma (N : PoissonRandomMeasure P ν) + (D : Set (ℝ × E)) : MeasurableSpace Ω := + ⨆ C ∈ {C : Set (ℝ × E) | Disjoint C D ∧ MeasurableSet C}, + MeasurableSpace.comap (fun ω => N.N ω C) inferInstance + +/-- A past-set at `sa` is disjoint from a future box `(sb, tb] × Ab` when `sa ≤ sb`, and it +carries its measurability into membership of `regionSigma`'s index set. -/ +lemma pastSet_mem_regionSigma_index {sa sb tb : ℝ} (hab : sa ≤ sb) (Ab : Set E) + {C : Set (ℝ × E)} (hC : C ⊆ Set.Iic sa ×ˢ Set.univ ∧ MeasurableSet C) : + Disjoint C (Set.Ioc sb tb ×ˢ Ab) ∧ MeasurableSet C := by + refine ⟨?_, hC.2⟩ + have hdt : Disjoint (Set.Iic sa) (Set.Ioc sb tb) := by + rw [Set.disjoint_left] + intro x hx1 hx2 + exact absurd (le_trans hx1 hab) (not_le.mpr (Set.mem_Ioc.mp hx2).1) + exact Set.disjoint_of_subset hC.1 (Set.prod_mono le_rfl (Set.subset_univ Ab)) + (Set.disjoint_prod.2 (.inl hdt)) + +/-- `regionSigma D ≤ mΩ`: every generating count is `mΩ`-measurable. -/ +private lemma regionSigma_le (N : PoissonRandomMeasure P ν) (D : Set (ℝ × E)) : + N.regionSigma D ≤ (inferInstance : MeasurableSpace Ω) := + iSup₂_le fun _ hC => measurable_iff_comap_le.mp (N.measurable_eval hC.2) + +/-- The past `σ`-algebra at `sa` sits inside the disjoint-region `σ`-algebra of a future +box `(sb, tb] × Ab`, for `sa ≤ sb`. -/ +private lemma pastFiltration_le_regionSigma (N : PoissonRandomMeasure P ν) {sa sb tb : ℝ} + (hab : sa ≤ sb) (Ab : Set E) : + N.pastFiltration sa ≤ N.regionSigma (Set.Ioc sb tb ×ˢ Ab) := + iSup₂_le fun C hC => le_iSup₂_of_le C (pastSet_mem_regionSigma_index hab Ab hC) le_rfl + +/-- The count on any measurable set disjoint from `D` lands in the disjoint-region +`σ`-algebra of `D`. -/ +private lemma comap_le_regionSigma (N : PoissonRandomMeasure P ν) {Ba D : Set (ℝ × E)} + (hdisj : Disjoint Ba D) (hBa : MeasurableSet Ba) : + MeasurableSpace.comap (fun ω => N.N ω Ba) inferInstance ≤ N.regionSigma D := + le_iSup₂_of_le Ba ⟨hdisj, hBa⟩ le_rfl + +/-! ### Measurability of adapted integrands and compensated increments -/ + +/-- The reference intensity of a finite-mark box `(s,t] × A` is finite. -/ +theorem referenceIntensity_box_ne_top {s t : ℝ} {A : Set E} (hAfin : ν A ≠ ⊤) : + referenceIntensity ν (Set.Ioc s t ×ˢ A) ≠ ⊤ := by + change ((volume.restrict (Set.Ici (0 : ℝ))).prod ν) (Set.Ioc s t ×ˢ A) ≠ ⊤ + rw [Measure.prod_prod] + refine ENNReal.mul_ne_top ?_ hAfin + rw [Measure.restrict_apply measurableSet_Ioc] + exact ne_top_of_le_ne_top (by rw [Real.volume_Ioc]; exact ENNReal.ofReal_ne_top) + (measure_mono Set.inter_subset_left) + +/-- On a box `(a,b] × A` with `0 ≤ a ≤ b`, the reference intensity is `(b − a) · ν(A)` — the +`L²(dt ⊗ dν)`-weight one term of the isometry carries. -/ +theorem referenceIntensity_box_toReal {a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) {A : Set E} : + (referenceIntensity ν (Set.Ioc a b ×ˢ A)).toReal = (b - a) * (ν A).toReal := by + have hsub : Set.Ioc a b ⊆ Set.Ici (0 : ℝ) := + fun x hx => le_of_lt (lt_of_le_of_lt ha (Set.mem_Ioc.mp hx).1) + have hval : referenceIntensity ν (Set.Ioc a b ×ˢ A) = ENNReal.ofReal (b - a) * ν A := by + change ((volume.restrict (Set.Ici (0 : ℝ))).prod ν) (Set.Ioc a b ×ˢ A) = _ + rw [Measure.prod_prod, Measure.restrict_apply measurableSet_Ioc, + Set.inter_eq_left.mpr hsub, Real.volume_Ioc] + rw [hval, ENNReal.toReal_mul, ENNReal.toReal_ofReal (by linarith)] + +/-! ### The independence cornerstone and the energy identities -/ + +/-- **Past-adapted `⟂` future compensated increment.** An integrand adapted at `s` is +independent of `Ñ((s,t] × A)`. Re-derived in one `indep_of_disjoint_region` step: the past +at `s` lives on `(-∞,s] × E`, which is disjoint from the future box `(s,t] × A`, so +`comap φ ≤ pastFiltration s ≤ regionSigma((s,t] × A)`, and the field pairs that region against the +box count; then compose with `x ↦ x.toReal − ν̂(box)`. -/ +theorem adapted_indepFun_compensated (N : PoissonRandomMeasure P ν) {s t : ℝ} + {A : Set E} (hA : MeasurableSet A) {φ : Ω → ℝ} (hφ : Measurable[N.pastFiltration s] φ) : + IndepFun φ (N.compensated (Set.Ioc s t ×ˢ A)) P := by + have hbox : MeasurableSet (Set.Ioc s t ×ˢ A) := measurableSet_Ioc.prod hA + have hfield : Indep (N.regionSigma (Set.Ioc s t ×ˢ A)) + (MeasurableSpace.comap (fun ω => N.N ω (Set.Ioc s t ×ˢ A)) inferInstance) P := + N.indep_of_disjoint_region hbox + have hφ_le : MeasurableSpace.comap φ inferInstance ≤ N.regionSigma (Set.Ioc s t ×ˢ A) := + le_trans (measurable_iff_comap_le.mp hφ) (pastFiltration_le_regionSigma N le_rfl A) + have hraw : IndepFun φ (fun ω => N.N ω (Set.Ioc s t ×ˢ A)) P := + (IndepFun_iff_Indep _ _ _).mpr (indep_of_indep_of_le_left hfield hφ_le) + have hcomp := hraw.comp (φ := (id : ℝ → ℝ)) + (ψ := fun x : ℝ≥0∞ => x.toReal - (referenceIntensity ν (Set.Ioc s t ×ˢ A)).toReal) + measurable_id (by fun_prop) + simp only [Function.comp_def, id_eq] at hcomp + exact hcomp + +/-- **Zero-pairing against a fresh compensated increment.** If `X` is measurable for the +disjoint-region `σ`-algebra of `D`, then `𝔼[X · Ñ(D)] = 0`: `X ⟂ Ñ(D)` (independent +scattering) and `Ñ(D)` is mean-zero. This is the single engine behind every cross-term. -/ +theorem integral_mul_compensated_eq_zero (N : PoissonRandomMeasure P ν) {D : Set (ℝ × E)} + (hD : MeasurableSet D) (hfin : referenceIntensity ν D ≠ ⊤) + {X : Ω → ℝ} (hX : Measurable[N.regionSigma D] X) : + ∫ ω, X ω * N.compensated D ω ∂P = 0 := by + have hXm : Measurable X := hX.mono (regionSigma_le N D) le_rfl + have hfield : Indep (N.regionSigma D) + (MeasurableSpace.comap (fun ω => N.N ω D) inferInstance) P := N.indep_of_disjoint_region hD + have hraw : IndepFun X (fun ω => N.N ω D) P := + (IndepFun_iff_Indep _ _ _).mpr + (indep_of_indep_of_le_left hfield (measurable_iff_comap_le.mp hX)) + have hcomp : IndepFun X (N.compensated D) P := by + have h := hraw.comp (φ := (id : ℝ → ℝ)) + (ψ := fun x : ℝ≥0∞ => x.toReal - (referenceIntensity ν D).toReal) measurable_id (by fun_prop) + simp only [Function.comp_def, id_eq] at h + exact h + exact hcomp.integral_mul_eq_zero hXm.aestronglyMeasurable + (N.measurable_compensated hD).aestronglyMeasurable (compensated_integral_zero N hD hfin) + +/-- **Diagonal energy** (the isometry's diagonal term): for `φ` adapted at `s`, +`𝔼[φ² · Ñ((s,t] × A)²] = 𝔼[φ²] · ν̂((s,t] × A)`. The increment's square is independent of +the past (`adapted_indepFun_compensated`, squared) and has mean `ν̂(box)` +(`compensated_integral_sq`). -/ +theorem integral_adapted_sq_mul_compensated_sq (N : PoissonRandomMeasure P ν) + {s t : ℝ} {A : Set E} (hA : MeasurableSet A) (hAfin : ν A ≠ ⊤) + {φ : Ω → ℝ} (hφ : Measurable[N.pastFiltration s] φ) : + ∫ ω, (φ ω) ^ 2 * (N.compensated (Set.Ioc s t ×ˢ A) ω) ^ 2 ∂P + = (∫ ω, (φ ω) ^ 2 ∂P) * (referenceIntensity ν (Set.Ioc s t ×ˢ A)).toReal := by + have hbox : MeasurableSet (Set.Ioc s t ×ˢ A) := measurableSet_Ioc.prod hA + have hfin : referenceIntensity ν (Set.Ioc s t ×ˢ A) ≠ ⊤ := referenceIntensity_box_ne_top hAfin + have hφm : Measurable φ := (hφ.mono (N.pastFiltration.le s) le_rfl) + have hÑm : Measurable (N.compensated (Set.Ioc s t ×ˢ A)) := N.measurable_compensated hbox + rw [(adapted_indepFun_compensated N hA (hφ.pow_const 2)).integral_mul_sq + (hφm.pow_const 2).aestronglyMeasurable hÑm.aestronglyMeasurable, + compensated_integral_sq N hbox hfin] + +/-- **Cross-term vanishing** (both cross families of a `time × mark` simple integrand). For +`φa` adapted at `sa`, `φb` adapted at `sb` with `sa ≤ sb`, a measurable `Ba` disjoint from the +future box `(sb, tb] × Ab`, + + `𝔼[(φa · Ñ(Ba)) · (φb · Ñ((sb,tb] × Ab))] = 0`. + +The first factor `φa · Ñ(Ba) · φb` is measurable for `regionSigma((sb,tb] × Ab)` — `φa`, `φb` +past-adapted (their pasts precede the box), `Ñ(Ba)` on a disjoint box — so it pairs to zero +against the fresh increment by `integral_mul_compensated_eq_zero`. Different-time cross pairs +take `Ba = (sa, ta] × Aa` with `ta ≤ sb`; same-time / different-mark pairs take +`Ba = (sb, tb] × Aa` with `Aa ∩ Ab = ∅`. -/ +theorem integral_cross_compensated_eq_zero (N : PoissonRandomMeasure P ν) + {sa sb tb : ℝ} (hab : sa ≤ sb) + {Ba : Set (ℝ × E)} (hBa : MeasurableSet Ba) {Ab : Set E} (hAb : MeasurableSet Ab) + (hAbfin : ν Ab ≠ ⊤) (hdisj : Disjoint Ba (Set.Ioc sb tb ×ˢ Ab)) + {φa φb : Ω → ℝ} (hφa : Measurable[N.pastFiltration sa] φa) + (hφb : Measurable[N.pastFiltration sb] φb) : + ∫ ω, (φa ω * N.compensated Ba ω) + * (φb ω * N.compensated (Set.Ioc sb tb ×ˢ Ab) ω) ∂P = 0 := by + have hboxbms : MeasurableSet (Set.Ioc sb tb ×ˢ Ab) := measurableSet_Ioc.prod hAb + have hfin : referenceIntensity ν (Set.Ioc sb tb ×ˢ Ab) ≠ ⊤ := referenceIntensity_box_ne_top hAbfin + have hXa : Measurable[N.regionSigma (Set.Ioc sb tb ×ˢ Ab)] φa := + hφa.mono (pastFiltration_le_regionSigma N hab Ab) le_rfl + have hXÑa : Measurable[N.regionSigma (Set.Ioc sb tb ×ˢ Ab)] (N.compensated Ba) := by + change Measurable[N.regionSigma (Set.Ioc sb tb ×ˢ Ab)] + fun ω => (N.N ω Ba).toReal - (referenceIntensity ν Ba).toReal + have hc : Measurable[N.regionSigma (Set.Ioc sb tb ×ˢ Ab)] fun ω => N.N ω Ba := + (measurable_iff_comap_le.mpr le_rfl).mono (comap_le_regionSigma N hdisj hBa) le_rfl + exact hc.ennreal_toReal.sub measurable_const + have hXb : Measurable[N.regionSigma (Set.Ioc sb tb ×ˢ Ab)] φb := + hφb.mono (pastFiltration_le_regionSigma N le_rfl Ab) le_rfl + have hX : Measurable[N.regionSigma (Set.Ioc sb tb ×ˢ Ab)] + fun ω => φa ω * N.compensated Ba ω * φb ω := (hXa.mul hXÑa).mul hXb + have hzero := integral_mul_compensated_eq_zero N hboxbms hfin hX + rw [← hzero] + exact integral_congr_ae (Filter.Eventually.of_forall fun ω => by ring) + +/-- **Each simple-integrand term is `L²`.** For `φ` adapted at `s` and in `L²`, the term +`φ · Ñ((s,t] × A) ∈ L²(P)`: the increment is `L²` (`memLp_compensated`) and independent of the +`L²` coefficient `φ`, so the product's square is integrable. -/ +theorem memLp_adapted_mul_compensated (N : PoissonRandomMeasure P ν) {s t : ℝ} + {A : Set E} (hA : MeasurableSet A) (hAfin : ν A ≠ ⊤) + {φ : Ω → ℝ} (hφ : Measurable[N.pastFiltration s] φ) (hφL2 : MemLp φ 2 P) : + MemLp (fun ω => φ ω * N.compensated (Set.Ioc s t ×ˢ A) ω) 2 P := + (adapted_indepFun_compensated N hA hφ).memLp_two_mul hφL2 + (memLp_compensated N (measurableSet_Ioc.prod hA) (referenceIntensity_box_ne_top hAfin)) + +end MathFin diff --git a/LeanPool/MathFin/Probability/Jumps/PoissonCompensatedSimpleIntegrand.lean b/LeanPool/MathFin/Probability/Jumps/PoissonCompensatedSimpleIntegrand.lean new file mode 100644 index 0000000000..c642336606 --- /dev/null +++ b/LeanPool/MathFin/Probability/Jumps/PoissonCompensatedSimpleIntegrand.lean @@ -0,0 +1,149 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Jumps.PoissonCompensatedIsometryAdapted + +/-! +# The marked simple integrand as a vector space + +The source module for the compensated-Poisson (Itô–Lévy) integral operator: finite formal sums +`∑ᵢ φᵢ · 𝟙_{(sᵢ, tᵢ] × Aᵢ}` of space-time boxes, each coefficient `φᵢ` bounded and adapted at its +box's start `sᵢ`, each mark `Aᵢ` measurable with finite intensity. + +Encoded as the submodule `levySimpleModule` of the `Finsupp` module `(ℝ × ℝ × Set E) →₀ (Ω → ℝ)` +(index `b = (s, t, A)` ↦ coefficient), carved by the predicate `IsLevySimple`. This is the marked +analogue of Degenne's `ProbabilityTheory.SimpleProcess` (time-indexed; no space-time version exists +in Mathlib or BrownianMotion). Adding two integrands concatenates their box families (`Finsupp` +add), scaling scales the coefficients, and adaptedness / finite marks / a uniform bound are each +preserved under `0`, `+`, `•` — so the marked integrands are a genuine submodule and inherit the +`Module ℝ` structure, with no bespoke instance. + +The elementary integral, the two `L²` embeddings, the isometry (summing the overlapping-box bilinear +pairing `integral_bilinear_pairing`), and the `extendOfNorm` CLM are built on this source in the +sibling modules. + +## Provenance + +Structure shape mirrors `ProbabilityTheory.SimpleProcess` (Degenne, BrownianMotion — a `Finsupp` of +interval coefficients); the compensated-integral content is our own. The PRM field shape is +consulted from `cgarryZA/LevyStochCalc` (Apache-2.0, cited). + +## Main definitions + +* `indexBox`: the space-time box `(s, t] × A` of an index `b = (s, t, A)`. +* `IsLevySimple`: a finitely supported family `V` of coefficients indexed by boxes is a marked + simple integrand when each `V b` is adapted at the box start, each mark is measurable with + finite `ν`-intensity, and the coefficients are uniformly bounded. +* `levySimpleModule`: the marked simple integrands as a submodule of + `(ℝ × ℝ × Set E) →₀ (Ω → ℝ)`. + +## Main results + +* `mem_levySimpleModule`: membership in `levySimpleModule N` is `IsLevySimple N`. +* `IsLevySimple.measurable_coe`: every coefficient of a marked simple integrand is adapted at its + index's start, since off the support it is `0`. +* `IsLevySimple.bound_coe`: a marked simple integrand has a nonnegative uniform bound `C` at every + index. + +## Tags + +marked simple integrand, space-time boxes, Lévy integrand, predictable simple process, +Poisson integral domain, MSC 60G51, MSC 60H05, MSC 60G55 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +variable {Ω : Type*} [MeasurableSpace Ω] {E : Type*} [MeasurableSpace E] + {P : Measure Ω} [IsProbabilityMeasure P] {ν : Measure E} [SigmaFinite ν] + +/-- The space-time box of an index `b = (s, t, A)`: the rectangle `(s, t] × A`. -/ +def indexBox (b : ℝ × ℝ × Set E) : Set (ℝ × E) := Set.Ioc b.1 b.2.1 ×ˢ b.2.2 + +/-- **The marked-simple predicate.** A `Finsupp` `V : (ℝ × ℝ × Set E) →₀ (Ω → ℝ)` is a marked simple +integrand when, on each box `b = (s, t, A)` in its (finite) support, the coefficient `V b` is +adapted at the start `s = b.1`, the mark `A = b.2.2` is measurable with finite `ν`-intensity, and +the coefficients are uniformly bounded. -/ +structure IsLevySimple (N : PoissonRandomMeasure P ν) + (V : (ℝ × ℝ × Set E) →₀ (Ω → ℝ)) : Prop where + /-- Each coefficient is adapted at its box's start. -/ + adapted : ∀ b ∈ V.support, Measurable[N.pastFiltration b.1] (V b) + /-- Each box's mark is measurable. -/ + markMeasurable : ∀ b ∈ V.support, MeasurableSet b.2.2 + /-- Each box's mark has finite intensity. -/ + markFinite : ∀ b ∈ V.support, ν b.2.2 ≠ ⊤ + /-- The coefficients are uniformly bounded. -/ + bounded : ∃ C : ℝ, ∀ b ∈ V.support, ∀ ω, |V b ω| ≤ C + +namespace IsLevySimple + +/-- Off its support a coefficient is `0`, so a marked simple integrand's coefficient is adapted at +`b.1` for **every** index `b`. -/ +lemma measurable_coe {N : PoissonRandomMeasure P ν} {V : (ℝ × ℝ × Set E) →₀ (Ω → ℝ)} + (hV : IsLevySimple N V) (b : ℝ × ℝ × Set E) : Measurable[N.pastFiltration b.1] (V b) := by + by_cases hb : b ∈ V.support + · exact hV.adapted b hb + · rw [Finsupp.notMem_support_iff.mp hb]; exact measurable_const + +/-- A nonnegative uniform bound holding at **every** index `b` (off the support the coefficient is +`0`). -/ +lemma bound_coe {N : PoissonRandomMeasure P ν} {V : (ℝ × ℝ × Set E) →₀ (Ω → ℝ)} + (hV : IsLevySimple N V) : ∃ C : ℝ, 0 ≤ C ∧ ∀ b ω, |V b ω| ≤ C := by + obtain ⟨C, hC⟩ := hV.bounded + refine ⟨max 0 C, le_max_left _ _, fun b ω => ?_⟩ + by_cases hb : b ∈ V.support + · exact (hC b hb ω).trans (le_max_right _ _) + · rw [Finsupp.notMem_support_iff.mp hb]; simp + +end IsLevySimple + +/-- **The marked simple integrands as a submodule** of the `Finsupp` module. The zero integrand has +empty support (all conditions vacuous); a sum's support lies in the union of the two supports so its +marks stay valid, its coefficients add (adaptedness closed under `+`, bound `Cᵥ + C_w`); a scalar +multiple keeps the support and scales the bound by `|c|`. -/ +def levySimpleModule (N : PoissonRandomMeasure P ν) : + Submodule ℝ ((ℝ × ℝ × Set E) →₀ (Ω → ℝ)) where + carrier := {V | IsLevySimple N V} + zero_mem' := by + refine ⟨fun b hb => ?_, fun b hb => ?_, fun b hb => ?_, 0, fun b hb => ?_⟩ <;> simp at hb + add_mem' := by + intro V W hV hW + refine ⟨fun b hb => ?_, fun b hb => ?_, fun b hb => ?_, ?_⟩ + · rw [Finsupp.add_apply]; exact (hV.measurable_coe b).add (hW.measurable_coe b) + · rcases Finset.mem_union.mp (Finsupp.support_add hb) with h | h + · exact hV.markMeasurable b h + · exact hW.markMeasurable b h + · rcases Finset.mem_union.mp (Finsupp.support_add hb) with h | h + · exact hV.markFinite b h + · exact hW.markFinite b h + · obtain ⟨Cv, _, hCv⟩ := hV.bound_coe + obtain ⟨Cw, _, hCw⟩ := hW.bound_coe + refine ⟨Cv + Cw, fun b _ ω => ?_⟩ + rw [Finsupp.add_apply, Pi.add_apply, abs_le] + have hx := abs_le.mp (hCv b ω); have hy := abs_le.mp (hCw b ω) + constructor <;> linarith [hx.1, hx.2, hy.1, hy.2] + smul_mem' := by + intro c V hV + refine ⟨fun b hb => ?_, fun b hb => ?_, fun b hb => ?_, ?_⟩ + · rw [Finsupp.smul_apply]; exact (hV.measurable_coe b).const_smul c + · exact hV.markMeasurable b (Finsupp.support_smul hb) + · exact hV.markFinite b (Finsupp.support_smul hb) + · obtain ⟨C, _, hC⟩ := hV.bound_coe + refine ⟨|c| * C, fun b _ ω => ?_⟩ + rw [Finsupp.smul_apply, Pi.smul_apply, smul_eq_mul, abs_mul] + exact mul_le_mul_of_nonneg_left (hC b ω) (abs_nonneg c) + +@[simp] lemma mem_levySimpleModule {N : PoissonRandomMeasure P ν} + {V : (ℝ × ℝ × Set E) →₀ (Ω → ℝ)} : V ∈ levySimpleModule N ↔ IsLevySimple N V := Iff.rfl + +end MathFin diff --git a/LeanPool/MathFin/Probability/Jumps/PoissonCounting.lean b/LeanPool/MathFin/Probability/Jumps/PoissonCounting.lean new file mode 100644 index 0000000000..7b9b70e952 --- /dev/null +++ b/LeanPool/MathFin/Probability/Jumps/PoissonCounting.lean @@ -0,0 +1,286 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Laws.ErlangSum +public import Mathlib.Probability.Distributions.Poisson.Basic + +/-! +# The Poisson marginal law from the arrival-time construction + +Saporito's Theorem 3.3.5 states the Poisson marginal law and derives +it from infinitesimal transition probabilities. Here the counting process is +constructed from iid `Exp(r)` interarrival times and its marginal law follows +from the arrival-time identities. + +This file derives the marginal from the construction: + +* the `k`-th arrival time `T k = ξ₀ + ⋯ + ξ_{k−1}` has the `Erlang(k, r) = + gammaMeasure k r` law (`ErlangSum.map_sum_iidExp`, our Gamma convolution + identity); +* the counting event `{N t = k}` is the difference + `{T k ≤ t} \ {T (k+1) ≤ t}`; +* the analytic heart: the **Gamma-CDF difference identity** + + `∫₀ᵗ γ_k − ∫₀ᵗ γ_{k+1} = e^{−rt} (rt)ᵏ / k!` + + where `γ_k` is the `Gamma(k, r)` density — proved by the fundamental + theorem of calculus applied to `Φ_k(u) = (ru)ᵏ e^{−ru}/k!`, whose + derivative telescopes to exactly `γ_k − γ_{k+1}`. + +## Main results + +* `PoissonCounting.map_count_eq_poissonMeasure` — for iid `Exp(r)` + interarrivals and the counting process they generate, + `N t ∼ Poisson(r·t)` by the arrival-time derivation. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Theorem 3.3.5 (the marginal law) + +## Tags + +Poisson process, counting process, Erlang distribution, Gamma distribution, interarrival times, +Poisson marginal law, MSC 60G55, MSC 60E05 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal Nat + +namespace PoissonCounting + +variable {r t : ℝ} + +/-! ### Integrability of the Gamma density on `[0, t]` -/ + +/-- The Gamma density of shape `a ≥ 1` is continuous on `[0, ∞)`. -/ +lemma continuousOn_gammaPDFReal {a : ℝ} (ha : 1 ≤ a) (r : ℝ) : + ContinuousOn (gammaPDFReal a r) (Set.Ici 0) := by + have hform : ContinuousOn + (fun x : ℝ ↦ r ^ a / Real.Gamma a * x ^ (a - 1) * rexp (-(r * x))) + (Set.Ici 0) := by + refine ContinuousOn.mul (ContinuousOn.mul continuousOn_const ?_) ?_ + · exact continuousOn_id.rpow_const fun x _ ↦ Or.inr (by linarith) + · exact ((continuous_const.mul continuous_id).neg.rexp).continuousOn + exact hform.congr fun x hx ↦ by + rw [gammaPDFReal, ite_eq_left (Set.mem_Ici.mp hx)] + +/-- The Gamma density of shape `a ≥ 1` is interval integrable on `[0, t]`. -/ +lemma intervalIntegrable_gammaPDFReal {a : ℝ} (ha : 1 ≤ a) (ht : 0 ≤ t) : + IntervalIntegrable (gammaPDFReal a r) volume 0 t := by + refine ContinuousOn.intervalIntegrable ?_ + refine (continuousOn_gammaPDFReal ha r).mono ?_ + rw [Set.uIcc_of_le ht] + exact fun x hx ↦ hx.1 + +/-! ### The Gamma CDF as an interval integral -/ + +/-- For shape `a ≥ 1`, the `Gamma(a, r)` measure of `Iic t` is the interval +integral of its density over `[0, t]` (the density vanishes on negatives). -/ +lemma gammaMeasure_Iic {a : ℝ} (ha : 1 ≤ a) (hr : 0 < r) (ht : 0 ≤ t) : + gammaMeasure a r (Set.Iic t) + = ENNReal.ofReal (∫ s in (0:ℝ)..t, gammaPDFReal a r s) := by + have hInt : IntegrableOn (gammaPDFReal a r) (Set.Icc 0 t) volume := + ((continuousOn_gammaPDFReal ha r).mono Set.Icc_subset_Ici_self).integrableOn_compact + isCompact_Icc + rw [show gammaMeasure a r = volume.withDensity (gammaPDF a r) from rfl, + withDensity_apply _ measurableSet_Iic, + lintegral_Iic_eq_lintegral_Iio_add_Icc _ ht, + lintegral_gammaPDF_of_nonpos le_rfl, zero_add, + show gammaPDF a r = fun s ↦ ENNReal.ofReal (gammaPDFReal a r s) from rfl, + ← ofReal_integral_eq_lintegral_ofReal hInt + (Filter.Eventually.of_forall fun s ↦ + gammaPDFReal_nonneg (by linarith) hr s), + integral_Icc_eq_integral_Ioc, ← intervalIntegral.integral_of_le ht] + +/-! ### The Gamma-CDF difference identity (the analytic heart) -/ + +/-- The telescoping antiderivative: on `s ≥ 0`, `Φ_k(u) = (ru)ᵏ e^{−ru}/k!` +has derivative `γ_k(s) − γ_{k+1}(s)` (Gamma densities of natural shapes). -/ +lemma hasDerivAt_gamma_antideriv {k : ℕ} (hk : k ≠ 0) + {s : ℝ} (hs : 0 ≤ s) : + HasDerivAt (fun u : ℝ ↦ (r * u) ^ k * rexp (-(r * u)) / k !) + (gammaPDFReal k r s - gammaPDFReal (k + 1 : ℕ) r s) s := by + obtain ⟨m, rfl⟩ : ∃ m, k = m + 1 := + ⟨k - 1, (Nat.succ_pred_eq_of_pos (Nat.pos_of_ne_zero hk)).symm⟩ + have h1 : HasDerivAt (fun u : ℝ ↦ (r * u) ^ (m + 1)) + (((m + 1 : ℕ) : ℝ) * (r * s) ^ m * r) s := by + have := (hasDerivAt_pow (m + 1) (r * s)).comp s ((hasDerivAt_id s).const_mul r) + convert this using 1 <;> first | rfl | (push_cast; ring) + have h2 : HasDerivAt (fun u : ℝ ↦ rexp (-(r * u))) + (rexp (-(r * s)) * (-r)) s := by + have := (((hasDerivAt_id s).const_mul r).neg).exp + simpa using this + have h3 := (h1.mul h2).div_const ((m + 1)! : ℝ) + convert h3 using 1 + -- value identity: γ_{m+1}(s) − γ_{m+2}(s) equals the product-rule expression + have hGm : Real.Gamma ((m + 1 : ℕ) : ℝ) = (m ! : ℝ) := by + push_cast + exact_mod_cast Real.Gamma_nat_eq_factorial m + have hGm1 : Real.Gamma ((m + 1 + 1 : ℕ) : ℝ) = ((m + 1)! : ℝ) := by + push_cast + exact_mod_cast Real.Gamma_nat_eq_factorial (m + 1) + have hs_pow : s ^ (((m + 1 : ℕ) : ℝ) - 1) = s ^ m := by + rw [show ((m + 1 : ℕ) : ℝ) - 1 = ((m : ℕ) : ℝ) by push_cast; ring, + Real.rpow_natCast] + have hs_pow1 : s ^ (((m + 1 + 1 : ℕ) : ℝ) - 1) = s ^ (m + 1) := by + rw [show ((m + 1 + 1 : ℕ) : ℝ) - 1 = ((m + 1 : ℕ) : ℝ) by push_cast; ring, + Real.rpow_natCast] + have hr_pow : r ^ (((m + 1 : ℕ) : ℕ) : ℝ) = r ^ (m + 1 : ℕ) := + Real.rpow_natCast r (m + 1) + have hr_pow1 : r ^ (((m + 1 + 1 : ℕ) : ℕ) : ℝ) = r ^ (m + 1 + 1 : ℕ) := + Real.rpow_natCast r (m + 1 + 1) + have hm0 : (m ! : ℝ) ≠ 0 := by positivity + have hm10 : ((m + 1)! : ℝ) ≠ 0 := by positivity + simp only [gammaPDFReal, ite_eq_left hs] + rw [hGm, hGm1, hr_pow, hr_pow1, hs_pow, hs_pow1, Nat.factorial_succ] + simp only [mul_pow] + push_cast + field_simp + ring + +/-- **Gamma-CDF difference identity.** For `k ≥ 1`, `r > 0`, `t ≥ 0`: +`∫₀ᵗ γ_k − ∫₀ᵗ γ_{k+1} = e^{−rt} (rt)ᵏ / k!` — the Poisson pmf appears as +the telescoping gap between consecutive Erlang CDFs (a formal calculus +identity; no positivity of `r` is needed). -/ +lemma integral_gammaPDFReal_sub_succ (ht : 0 ≤ t) + {k : ℕ} (hk : k ≠ 0) : + (∫ s in (0:ℝ)..t, gammaPDFReal k r s) + - ∫ s in (0:ℝ)..t, gammaPDFReal (k + 1 : ℕ) r s + = rexp (-(r * t)) * (r * t) ^ k / k ! := by + have hk1 : (1 : ℝ) ≤ ((k : ℕ) : ℝ) := by + exact_mod_cast Nat.one_le_iff_ne_zero.mpr hk + have hk1' : (1 : ℝ) ≤ ((k + 1 : ℕ) : ℝ) := by push_cast; linarith + have hint1 := intervalIntegrable_gammaPDFReal (a := ((k : ℕ) : ℝ)) (r := r) hk1 ht + have hint2 := intervalIntegrable_gammaPDFReal (a := ((k + 1 : ℕ) : ℝ)) (r := r) hk1' ht + rw [← intervalIntegral.integral_sub hint1 hint2, + intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun s hs ↦ hasDerivAt_gamma_antideriv hk + (by rw [Set.uIcc_of_le ht] at hs; exact hs.1)) + (hint1.sub hint2)] + rw [mul_zero, zero_pow hk, zero_mul, zero_div, sub_zero] + ring + +/-- The base case against zero: `∫₀ᵗ γ_1 = 1 − e^{−rt}` (the exponential +CDF). -/ +lemma integral_gammaPDFReal_one (ht : 0 ≤ t) : + ∫ s in (0:ℝ)..t, gammaPDFReal 1 r s = 1 - rexp (-(r * t)) := by + have hderiv : ∀ s ∈ Set.uIcc (0:ℝ) t, + HasDerivAt (fun u : ℝ ↦ -rexp (-(r * u))) (gammaPDFReal 1 r s) s := by + intro s hs + rw [Set.uIcc_of_le ht] at hs + have h := hasDerivAt_neg_exp_mul_exp (r := r) (x := s) + convert h using 1 + simp only [gammaPDFReal, ite_eq_left hs.1] + rw [Real.Gamma_one, Real.rpow_one, sub_self, Real.rpow_zero] + ring + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hderiv + (intervalIntegrable_gammaPDFReal le_rfl ht)] + simp only [mul_zero, neg_zero, Real.exp_zero] + ring + +/-! ### The marginal law of the counting process -/ + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + +/-- **Poisson marginal law from interarrival times.** Let `ξ i` be iid `Exp(rate)` +interarrival times and `N` the counting process they generate. Then `N t = k` +exactly when the `k`-th arrival has happened by `t` and the `(k+1)`-st has not, +and `N t ∼ Poisson(rate · t)`. + +The proof composes the Erlang law of the arrival times (the Gamma convolution +identity) with the Gamma-CDF difference identity. -/ +theorem map_count_eq_poissonMeasure [IsProbabilityMeasure μ] + {rate : ℝ≥0} (hrate : 0 < rate) + {ξ : ℕ → Ω → ℝ} (hmeas : ∀ i, Measurable (ξ i)) + (hnonneg : ∀ i ω, 0 ≤ ξ i ω) + (hlaw : ∀ i, μ.map (ξ i) = expMeasure rate) + (hindep : iIndepFun ξ μ) + {N : ℝ → Ω → ℕ} + (hcount : ∀ t k ω, N t ω = k ↔ + (∑ i ∈ Finset.range k, ξ i ω) ≤ t ∧ t < ∑ i ∈ Finset.range (k + 1), ξ i ω) + {t : ℝ} (ht : 0 ≤ t) : + μ.map (N t) = poissonMeasure (rate * ⟨t, ht⟩) := by + have hr : (0 : ℝ) < rate := NNReal.coe_pos.mpr hrate + -- arrival times + set T : ℕ → Ω → ℝ := fun k ω ↦ ∑ i ∈ Finset.range k, ξ i ω with hT + have hTmeas : ∀ k, Measurable (T k) := fun k ↦ + Finset.measurable_sum _ fun i _ ↦ hmeas i + have hTmono : ∀ k ω, T k ω ≤ T (k + 1) ω := fun k ω ↦ by + rw [hT] + simp only [Finset.sum_range_succ] + exact le_add_of_nonneg_right (hnonneg k ω) + -- the Erlang law of the k-th arrival + have hTlaw : ∀ k : ℕ, k ≠ 0 → μ.map (T k) = gammaMeasure k rate := by + intro k hk + have h := ErlangSum.map_sum_iidExp hr hmeas hlaw hindep (Finset.range k) + (Finset.nonempty_range_iff.mpr hk) + rwa [show (∑ i ∈ Finset.range k, ξ i) = T k from + funext fun ω ↦ Finset.sum_apply ω (Finset.range k) ξ, + Finset.card_range] at h + -- arrival events and their measures + have hTset_meas : ∀ k, MeasurableSet {ω | T k ω ≤ t} := fun k ↦ + measurableSet_le (hTmeas k) measurable_const + have hF : ∀ k : ℕ, k ≠ 0 → μ {ω | T k ω ≤ t} + = ENNReal.ofReal (∫ s in (0:ℝ)..t, gammaPDFReal k rate s) := by + intro k hk + have hk1 : (1 : ℝ) ≤ ((k : ℕ) : ℝ) := by + exact_mod_cast Nat.one_le_iff_ne_zero.mpr hk + have hmap : μ {ω | T k ω ≤ t} = μ.map (T k) (Set.Iic t) := by + rw [Measure.map_apply (hTmeas k) measurableSet_Iic] + rfl + rw [hmap, hTlaw k hk, gammaMeasure_Iic hk1 hr ht] + -- the counting event as a difference of arrival events + have hpre : ∀ k : ℕ, + (N t) ⁻¹' {k} = {ω | T k ω ≤ t} \ {ω | T (k + 1) ω ≤ t} := by + intro k + ext ω + simp [hcount t k ω, hT, not_le] + have hNmeas : Measurable (N t) := measurable_to_countable' fun k ↦ by + rw [hpre k]; exact (hTset_meas k).diff (hTset_meas (k + 1)) + have hsub : ∀ k : ℕ, {ω | T (k + 1) ω ≤ t} ⊆ {ω | T k ω ≤ t} := + fun k ω h ↦ le_trans (hTmono k ω) h + have hdiff : ∀ k : ℕ, μ ((N t) ⁻¹' {k}) + = μ {ω | T k ω ≤ t} - μ {ω | T (k + 1) ω ≤ t} := by + intro k + rw [hpre k, measure_sdiff (hsub k) (hTset_meas (k + 1)).nullMeasurableSet + (measure_ne_top μ _)] + -- assemble per singleton + refine Measure.ext_of_singleton fun k ↦ ?_ + rw [Measure.map_apply hNmeas (measurableSet_singleton k), + poissonMeasure_singleton, hdiff k] + have hco : ((rate * ⟨t, ht⟩ : ℝ≥0) : ℝ) = (rate : ℝ) * t := rfl + rcases Nat.eq_zero_or_pos k with rfl | hkpos + · -- k = 0 : survival of the first arrival + have hT0 : {ω | T 0 ω ≤ t} = Set.univ := by + ext ω + simp [hT, ht] + have hexp_le : rexp (-((rate : ℝ) * t)) ≤ 1 := + Real.exp_le_one_iff.mpr (neg_nonpos.mpr (mul_nonneg rate.coe_nonneg ht)) + rw [hT0, measure_univ, hF 1 one_ne_zero, + show ((1 : ℕ) : ℝ) = (1 : ℝ) from Nat.cast_one, + integral_gammaPDFReal_one ht, + show (1 : ℝ≥0∞) = ENNReal.ofReal 1 from ENNReal.ofReal_one.symm, + ← ENNReal.ofReal_sub 1 (by linarith)] + norm_num [hco] + · -- k ≥ 1 : the Gamma-CDF difference identity + have hk : k ≠ 0 := Nat.pos_iff_ne_zero.mp hkpos + have hnn : 0 ≤ ∫ s in (0:ℝ)..t, gammaPDFReal (k + 1 : ℕ) rate s := + intervalIntegral.integral_nonneg ht fun s _ ↦ + gammaPDFReal_nonneg (by positivity) hr s + rw [hF k hk, hF (k + 1) (Nat.succ_ne_zero k), + ← ENNReal.ofReal_sub _ hnn, + integral_gammaPDFReal_sub_succ ht hk, hco] + +end PoissonCounting + +end MathFin diff --git a/LeanPool/MathFin/Probability/Jumps/PoissonInterarrival.lean b/LeanPool/MathFin/Probability/Jumps/PoissonInterarrival.lean new file mode 100644 index 0000000000..4aed6c58f3 --- /dev/null +++ b/LeanPool/MathFin/Probability/Jumps/PoissonInterarrival.lean @@ -0,0 +1,155 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Distributions.Exponential +public import Mathlib.Probability.Distributions.Poisson.Basic + +/-! +# The first interarrival time of a Poisson process is exponential + +Saporito, Proposition 3.3.6 asserts that the interarrival times of a Poisson +process are iid `Exp(rate)`. The full iid statement for the whole sequence +needs the strong Markov property of the process (upstream-gated). What *is* +derivable from the bare counting axioms — zero start, Poisson increments, +independent increments, monotone paths — is the proposition's analytic core, +and this file derives exactly that: + +* **survival law**: `P(N_t = 0) = e^{−rate·t}` — read off the increment law; +* **memoryless factorisation**: `P(N_t = 0) = P(N_s = 0) · P(N_t − N_s = 0)` + — survival of the first arrival factorises over disjoint windows, the + signature property of the exponential law (derived from independent + increments, not assumed); +* **the law itself**: the first arrival time `τ` (characterised by + `τ > t ↔ N_t = 0`) satisfies `τ ∼ Exp(rate)` — by computing its CDF from + the survival law and identifying it with Mathlib's `cdf_expMeasure_eq`. + +## Main results + +* `PoissonInterarrival.survival_eq` — `μ {N t = 0} = e^{−rate t}`. +* `PoissonInterarrival.survival_factorizes` — `μ {N t = 0} = μ {N s = 0} * μ {N t - N s = 0}` + for `s ≤ t`, the factorisation behind the memoryless property. +* `PoissonInterarrival.map_firstArrival_eq_expMeasure` — + `τ ∼ Exp(rate)`, fully derived. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Proposition 3.3.6 + +## Tags + +Poisson process, first arrival time, exponential distribution, memoryless property, waiting time, +survival function, MSC 60G55, MSC 60E05 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal + +namespace PoissonInterarrival + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + +/-- **Survival law of the first arrival.** From the increment law alone: +`P(N_t = 0) = e^{−rate·t}` for `t ≥ 0`. -/ +theorem survival_eq {rate : ℝ≥0} {N : ℝ → Ω → ℕ} + (hmeas : ∀ t, Measurable (N t)) (hzero : ∀ ω, N 0 ω = 0) + (hincr : ∀ ⦃s t : ℝ⦄, 0 ≤ s → (hst : s ≤ t) → + Measure.map (fun ω ↦ N t ω - N s ω) μ + = poissonMeasure (rate * ⟨t - s, sub_nonneg.mpr hst⟩)) + {t : ℝ} (ht : 0 ≤ t) : + μ {ω | N t ω = 0} = ENNReal.ofReal (rexp (-((rate : ℝ) * t))) := by + have h := hincr le_rfl ht + rw [show (fun ω ↦ N t ω - N 0 ω) = N t from + funext fun ω ↦ by rw [hzero ω, Nat.sub_zero]] at h + have hset : μ {ω | N t ω = 0} = μ.map (N t) {0} := by + rw [Measure.map_apply (hmeas t) (measurableSet_singleton 0)] + rfl + rw [hset, h, poissonMeasure_singleton] + norm_num + rfl + +/-- **Memoryless factorisation (the exponential signature).** Survival of +the first arrival factorises over disjoint windows: +`P(N_t = 0) = P(N_s = 0) · P(N_t − N_s = 0)` — derived from independent +increments and monotone paths, not assumed. -/ +theorem survival_factorizes {N : ℝ → Ω → ℕ} + (hzero : ∀ ω, N 0 ω = 0) + (hmono : ∀ ⦃s t : ℝ⦄, s ≤ t → ∀ ω, N s ω ≤ N t ω) + (hindep : ∀ ⦃s t u v : ℝ⦄, 0 ≤ s → s ≤ t → t ≤ u → u ≤ v → + IndepFun (fun ω ↦ N t ω - N s ω) (fun ω ↦ N v ω - N u ω) μ) + {s t : ℝ} (hs : 0 ≤ s) (hst : s ≤ t) : + μ {ω | N t ω = 0} + = μ {ω | N s ω = 0} * μ {ω | N t ω - N s ω = 0} := by + have hI : IndepFun (N s) (fun ω ↦ N t ω - N s ω) μ := by + have h := hindep le_rfl hs le_rfl hst + rwa [show (fun ω ↦ N s ω - N 0 ω) = N s from + funext fun ω ↦ by rw [hzero ω, Nat.sub_zero]] at h + have hsplit : {ω | N t ω = 0} + = (N s) ⁻¹' {0} ∩ (fun ω ↦ N t ω - N s ω) ⁻¹' {0} := by + ext ω + have hm := hmono hst ω + simp only [Set.mem_ofPred_eq, Set.mem_inter_iff, Set.mem_preimage, + Set.mem_singleton_iff] + omega + rw [hsplit, + hI.measure_inter_preimage_eq_mul _ _ (measurableSet_singleton 0) + (measurableSet_singleton 0)] + rfl + +/-- **Proposition 3.3.6, first interarrival (derived).** If `τ` is the first +arrival time of the counting process (`τ > t ↔ N_t = 0` for `t ≥ 0`, +`τ ≥ 0`), then `τ ∼ Exp(rate)`. The CDF is computed from the survival law +and matched against Mathlib's closed-form exponential CDF. -/ +theorem map_firstArrival_eq_expMeasure [IsProbabilityMeasure μ] + {rate : ℝ≥0} (hrate : 0 < rate) {N : ℝ → Ω → ℕ} + (hmeas : ∀ t, Measurable (N t)) (hzero : ∀ ω, N 0 ω = 0) + (hincr : ∀ ⦃s t : ℝ⦄, 0 ≤ s → (hst : s ≤ t) → + Measure.map (fun ω ↦ N t ω - N s ω) μ + = poissonMeasure (rate * ⟨t - s, sub_nonneg.mpr hst⟩)) + {τ : Ω → ℝ} (hτ_meas : Measurable τ) (hτ_nonneg : ∀ ω, 0 ≤ τ ω) + (hτ_first : ∀ ⦃t : ℝ⦄, 0 ≤ t → {ω | t < τ ω} = {ω | N t ω = 0}) : + μ.map τ = expMeasure rate := by + have hr : (0 : ℝ) < rate := NNReal.coe_pos.mpr hrate + have : IsProbabilityMeasure (expMeasure (rate : ℝ)) := + isProbabilityMeasure_expMeasure hr + -- the exponential CDF in measure form + have hexp_Iic : ∀ x : ℝ, expMeasure (rate : ℝ) (Set.Iic x) + = ENNReal.ofReal (if 0 ≤ x then 1 - rexp (-((rate : ℝ) * x)) else 0) := by + intro x + rw [← ENNReal.ofReal_toReal (measure_ne_top (expMeasure (rate : ℝ)) _), + show ((expMeasure (rate : ℝ) (Set.Iic x)).toReal) + = cdf (expMeasure (rate : ℝ)) x from by rw [cdf_eq_real, measureReal_def], + cdf_expMeasure_eq hr x] + refine Measure.ext_of_Iic _ _ fun x ↦ ?_ + rw [Measure.map_apply hτ_meas measurableSet_Iic, hexp_Iic x] + rcases lt_or_ge x 0 with hx | hx + · -- x < 0 : τ ≥ 0 makes the event empty + rw [ite_eq_right (not_le.mpr hx), ENNReal.ofReal_zero, + show τ ⁻¹' Set.Iic x = ∅ from Set.eq_empty_of_forall_notMem fun ω h ↦ + absurd (le_trans (hτ_nonneg ω) (Set.mem_Iic.mp h)) (not_le.mpr hx)] + exact measure_empty + · -- x ≥ 0 : complement of the survival event + have hcompl : τ ⁻¹' Set.Iic x = {ω | x < τ ω}ᶜ := by + ext ω + simp [not_lt] + have hsurv_set : MeasurableSet {ω | x < τ ω} := + measurableSet_lt measurable_const hτ_meas + rw [ite_eq_left hx, hcompl, measure_compl hsurv_set (measure_ne_top μ _), + measure_univ, hτ_first hx, + survival_eq hmeas hzero hincr hx, + show (1 : ℝ≥0∞) = ENNReal.ofReal 1 from ENNReal.ofReal_one.symm, + ← ENNReal.ofReal_sub 1 (Real.exp_nonneg _)] + +end PoissonInterarrival + +end MathFin diff --git a/LeanPool/MathFin/Probability/Jumps/PoissonMaxima.lean b/LeanPool/MathFin/Probability/Jumps/PoissonMaxima.lean new file mode 100644 index 0000000000..514228bc6f --- /dev/null +++ b/LeanPool/MathFin/Probability/Jumps/PoissonMaxima.lean @@ -0,0 +1,205 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Jumps.PoissonPgf +public import LeanPool.MathFin.Probability.Laws.GeneralizedPareto +public import Mathlib.Order.CompletePartialOrder + +/-! +# The maximum of a Poisson number of losses + +Over a fixed period a Poisson(`λ`) number `N` of losses occurs, with iid severities `Y₀, Y₁, …` +of distribution function `G`, independent of `N`. The largest loss stays below `x` exactly +when none of the `N` losses exceeds `x`, and + + `P(max_{i 0` and `x ≥ 0`, `exp(−λ Gbar_{ξ,β}(x)) = H_ξ((x − μ)/σ)` with `σ = β λ^ξ` and +`μ = β(λ^ξ − 1)/ξ`. -/ +theorem exp_neg_mul_gpdTail {ξ β : ℝ} (hξ : ξ ≠ 0) (hβ : 0 < β) {l : ℝ} (hl : 0 < l) {x : ℝ} + (hx : 0 ≤ x) : + exp (-(l * gpdTail ξ β x)) = + gevCDF ξ ((x - β * (l ^ ξ - 1) / ξ) / (β * l ^ ξ)) := by + have hβ0 : β ≠ 0 := hβ.ne' + have hs : 0 < l ^ ξ := rpow_pos_of_pos hl ξ + have hs0 : l ^ ξ ≠ 0 := hs.ne' + -- the GEV argument is the GPD support variable rescaled by `λ^{−ξ}` + have hkey : 1 + ξ * ((x - β * (l ^ ξ - 1) / ξ) / (β * l ^ ξ)) = + (1 + ξ * (x / β)) / l ^ ξ := by + field_simp + ring + by_cases hsupp : 0 < 1 + ξ * (x / β) + · have hpos : 0 < 1 + ξ * ((x - β * (l ^ ξ - 1) / ξ) / (β * l ^ ξ)) := by + rw [hkey] + exact div_pos hsupp hs + rw [gpdTail_of_nonneg hξ hx hsupp.le, gevCDF_of_pos hξ hpos, hkey, + div_rpow hsupp.le hs.le, ← rpow_mul hl.le, show ξ * (-1 / ξ) = -1 by field_simp, + rpow_neg_one, div_inv_eq_mul, mul_comm l] + · have hle : 1 + ξ * (x / β) ≤ 0 := not_lt.1 hsupp + have hneg : ξ < 0 := by + by_contra! h + have : 0 ≤ ξ * (x / β) := mul_nonneg h (div_nonneg hx hβ.le) + linarith + have hnp : 1 + ξ * ((x - β * (l ^ ξ - 1) / ξ) / (β * l ^ ξ)) ≤ 0 := by + rw [hkey] + exact div_nonpos_of_nonpos_of_nonneg hle hs.le + rw [gpdTail_of_endpoint_le hξ hx hle, mul_zero, neg_zero, exp_zero, + gevCDF_of_nonpos hξ hnp, ite_eq_right (not_lt.2 hneg.le)] + +/-- For `ξ = 0`, `λ > 0` and `x ≥ 0`, `exp(−λ e^{−x/β}) = H_0((x − β log λ)/β)`. -/ +theorem exp_neg_mul_gpdTail_zero {β : ℝ} (hβ : 0 < β) {l : ℝ} (hl : 0 < l) {x : ℝ} + (hx : 0 ≤ x) : exp (-(l * gpdTail 0 β x)) = gevCDF 0 ((x - β * log l) / β) := by + have hβ0 : β ≠ 0 := hβ.ne' + rw [gpdTail_zero_shape hx, gevCDF_zero, + show -((x - β * log l) / β) = log l + -(x / β) by + rw [sub_div, mul_div_cancel_left₀ _ hβ0]; ring, + exp_add, exp_log hl] + +/-- **MFE Exercise 5.26.** If `N ∼ Poisson(λ)`, `λ > 0`, is independent of iid `GPD(ξ, β)` losses +`(Yᵢ)` with `ξ ≠ 0`, the largest loss has a generalized extreme value law on `[0, ∞)`: +`P(max_{i 0`, is independent of iid +exponential losses `GPD(0, β)`, the largest loss has a Gumbel law on `[0, ∞)`: +`P(max_{i + first + | (funext n; rw [mul_pow]; ring) + | (rw [← exp_eq_exp_ℝ, ← Real.exp_add]; congr 1; ring) + +/-- **Weighted Poisson series** (`tsum` form). -/ +lemma tsum_poisson_weights_mul_pow (r : ℝ≥0) (x : ℝ) : + ∑' n : ℕ, rexp (-(r : ℝ)) * (r : ℝ) ^ n / n ! * x ^ n + = rexp ((r : ℝ) * (x - 1)) := + (hasSum_poisson_weights_mul_pow r x).tsum_eq + +/-- **Poisson probability generating function**: `E[x^N] = e^{r(x−1)}` for +`N ∼ Poisson(r)` and every `x : ℝ`. Stated as an honest expectation against +`poissonMeasure`; no integrability hypothesis is needed since the codomain +is finite-dimensional (`integral_poissonMeasure`). -/ +theorem integral_pow_poissonMeasure (r : ℝ≥0) (x : ℝ) : + ∫ n, x ^ n ∂(poissonMeasure r) = rexp ((r : ℝ) * (x - 1)) := by + rw [integral_poissonMeasure r (fun n ↦ x ^ n)] + simp_rw [smul_eq_mul] + exact tsum_poisson_weights_mul_pow r x + +/-- `n ↦ xⁿ` is integrable against `Poisson(r)` for every `x : ℝ`: the weighted absolute values +`∑ₙ e^{−r} rⁿ/n! · |x|ⁿ` sum to `e^{r(|x|−1)}`. -/ +lemma integrable_pow_poissonMeasure (r : ℝ≥0) (x : ℝ) : + Integrable (fun n : ℕ ↦ x ^ n) (poissonMeasure r) := by + rw [integrable_poissonMeasure_iff] + simp_rw [norm_pow, Real.norm_eq_abs] + exact (hasSum_poisson_weights_mul_pow r |x|).summable + +end PoissonPgf + +end MathFin diff --git a/LeanPool/MathFin/Probability/Jumps/PoissonRandomMeasure.lean b/LeanPool/MathFin/Probability/Jumps/PoissonRandomMeasure.lean new file mode 100644 index 0000000000..e890898a8a --- /dev/null +++ b/LeanPool/MathFin/Probability/Jumps/PoissonRandomMeasure.lean @@ -0,0 +1,292 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.Order.CompletePartialOrder +public import Mathlib.Probability.Distributions.Poisson.Basic + +/-! +# Poisson random measure and the compensated increment + +A *Poisson random measure* `N` on the time-mark space `[0, ∞) × E` with σ-finite +mark-intensity `ν` is the driving object of Lévy-driven stochastic calculus: `N(·, B)` +is `Poisson`-distributed with mean `ν̂(B)` (`ν̂ := Leb[0,∞) ⊗ ν`), and counts on disjoint +regions are independent. The *compensated* measure `Ñ(B) := N(B) − ν̂(B)` is the mean-zero, +`L²` object one integrates against. + +This module provides the object as a hypothesis-bundling structure (its fields are the +Applebaum Def. 2.3.1 properties) plus the two Poisson moment facts the isometry needs — +`𝔼[N(B)] = ν̂(B)` and `𝔼[N(B)²] = ν̂(B)² + ν̂(B)` — hence `𝔼[Ñ(B)] = 0`, `𝔼[Ñ(B)²] = ν̂(B)`. + +Mathlib carries the Poisson law (`poissonMeasure`, `integral_poissonMeasure`) +but *not* its mean or variance; we derive them here from the total-mass identity by a single +index shift (`(n+1)·pmf(n+1) = r·pmf(n)`), with no exp-series differentiation. + +## Provenance + +The `PoissonRandomMeasure` structure's field shape is consulted from +`cgarryZA/LevyStochCalc` (Apache-2.0), itself a faithful rendering of Applebaum Def. 2.3.1; +the simple adapted-integrand isometry is in `PoissonCompensatedIsometryAdapted` +and `PoissonCompensatedIntegralL2`. The related LevyStochCalc theorem +`itoIsometry_compensated_unified_existence` includes an isometry for progressively +measurable integrands. References: Applebaum, *Lévy Processes and Stochastic +Calculus*, CUP 2009, Definition 2.3.1 and Theorem 4.2.3. + +## Main definitions + +* `referenceIntensity`: the product measure `Leb[0, ∞) ⊗ ν` on the time-mark space `ℝ × E`. +* `PoissonRandomMeasure`: a family of counting measures `N ω` on `ℝ × E` that are measurable in + `ω`, with `N(·, B) ∼ Poisson(ν̂ B)` for finite-intensity `B`, and counts on regions disjoint + from `D` independent of the count on `D`. +* `PoissonRandomMeasure.compensated`: the compensated increment `Ñ(B) = N(B) − ν̂(B)`. +* `poissonMeasureENN`: the Poisson law pushed to `ℝ≥0∞`. + +## Main results + +* `poissonMeasure_integral_id`, `poissonMeasure_integral_sq`: the Poisson mean `r` and second + moment `r² + r`. +* `compensated_integral_zero`: `𝔼[Ñ(B)] = 0` for measurable `B` of finite intensity. +* `compensated_integral_sq`: `𝔼[Ñ(B)²] = ν̂(B)` for measurable `B` of finite intensity. +* `memLp_compensated`: `Ñ(D) ∈ L²(P)` for measurable `D` of finite intensity. + +## Tags + +Poisson random measure, compensated measure, Lévy-driven calculus, mark intensity, Applebaum, +jump measure, MSC 60G55, MSC 60G51 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +/-! ## §1 Moments of the scalar Poisson law (Mathlib gap-fill) -/ + +/-- The Poisson pmf weight `c_r(n) = e^{-r} · r^n / n!`. Reducible so it folds/unfolds +cheaply against the summand of `integral_poissonMeasure` / `hasSum_one_poissonMeasure`. -/ +@[reducible] private noncomputable def pw (r : ℝ≥0) (n : ℕ) : ℝ := + Real.exp (-(r : ℝ)) * (r : ℝ) ^ n / n.factorial + +/-- The pmf weights sum to one. -/ +private theorem hasSum_pw (r : ℝ≥0) : HasSum (pw r) 1 := + hasSum_one_poissonMeasure r + +/-- **Shift identity** `(n+1)·c_r(n+1) = r·c_r(n)` — the engine of both moments. -/ +private theorem pw_succ_mul (r : ℝ≥0) (n : ℕ) : + ((n : ℝ) + 1) * pw r (n + 1) = (r : ℝ) * pw r n := by + change ((n : ℝ) + 1) * (Real.exp (-(r : ℝ)) * (r : ℝ) ^ (n + 1) / (n + 1).factorial) + = (r : ℝ) * (Real.exp (-(r : ℝ)) * (r : ℝ) ^ n / n.factorial) + rw [Nat.factorial_succ] + have hn : ((n : ℝ) + 1) ≠ 0 := by positivity + have hf : (n.factorial : ℝ) ≠ 0 := by exact_mod_cast n.factorial_ne_zero + push_cast + field_simp + ring + +/-- **First moment sum**: `HasSum (fun n => c_r(n)·n) r`. -/ +private theorem hasSum_pw_mul_id (r : ℝ≥0) : + HasSum (fun n => pw r n * (n : ℝ)) (r : ℝ) := by + have hshift : HasSum (fun n => pw r (n + 1) * ((n : ℝ) + 1)) (r : ℝ) := by + have hbase : HasSum (fun n => (r : ℝ) * pw r n) (r : ℝ) := by + simpa using (hasSum_pw r).mul_left (r : ℝ) + have hfun : (fun n => pw r (n + 1) * ((n : ℝ) + 1)) = (fun n => (r : ℝ) * pw r n) := by + funext n; rw [mul_comm (pw r (n + 1)) _, pw_succ_mul r n] + rw [hfun]; exact hbase + refine (hasSum_nat_add_iff' 1).mp ?_ + simpa using hshift + +/-- **Poisson mean**: `∫ n, (n : ℝ) ∂poissonMeasure r = r`. -/ +theorem poissonMeasure_integral_id (r : ℝ≥0) : + ∫ n, (n : ℝ) ∂(poissonMeasure r) = (r : ℝ) := by + rw [integral_poissonMeasure] + simp only [smul_eq_mul] + exact (hasSum_pw_mul_id r).tsum_eq + +/-- **Second-moment sum**: `HasSum (fun n => c_r(n)·n²) (r² + r)` — via `n² = n(n-1) + n`, +using the same `(n+1)·c_r(n+1) = r·c_r(n)` shift twice. -/ +private theorem hasSum_pw_mul_sq (r : ℝ≥0) : + HasSum (fun n => pw r n * (n : ℝ) ^ 2) ((r : ℝ) ^ 2 + (r : ℝ)) := by + have hsum1 : HasSum (fun n => pw r n * (n : ℝ) + pw r n) ((r : ℝ) + 1) := by + simpa using (hasSum_pw_mul_id r).add (hasSum_pw r) + have hshift : HasSum (fun n => pw r (n + 1) * ((n : ℝ) + 1) ^ 2) ((r : ℝ) ^ 2 + (r : ℝ)) := by + have hbase : HasSum (fun n => (r : ℝ) * (pw r n * (n : ℝ) + pw r n)) + ((r : ℝ) ^ 2 + (r : ℝ)) := by + have := hsum1.mul_left (r : ℝ) + have hval : (r : ℝ) * ((r : ℝ) + 1) = (r : ℝ) ^ 2 + (r : ℝ) := by ring + rwa [hval] at this + have hfun : (fun n => pw r (n + 1) * ((n : ℝ) + 1) ^ 2) + = (fun n => (r : ℝ) * (pw r n * (n : ℝ) + pw r n)) := by + funext n + have hps := pw_succ_mul r n + have hexp : pw r (n + 1) * ((n : ℝ) + 1) ^ 2 + = ((n : ℝ) + 1) * (((n : ℝ) + 1) * pw r (n + 1)) := by ring + rw [hexp, hps]; ring + rw [hfun]; exact hbase + refine (hasSum_nat_add_iff' 1).mp ?_ + simpa using hshift + +/-- **Poisson second moment**: `∫ n, (n : ℝ)^2 ∂poissonMeasure r = r^2 + r`. -/ +theorem poissonMeasure_integral_sq (r : ℝ≥0) : + ∫ n, (n : ℝ) ^ 2 ∂(poissonMeasure r) = (r : ℝ) ^ 2 + (r : ℝ) := by + rw [integral_poissonMeasure] + simp only [smul_eq_mul] + exact (hasSum_pw_mul_sq r).tsum_eq + +/-! ## §2 The Poisson random measure and its compensated increment -/ + +variable {Ω : Type*} [MeasurableSpace Ω] {E : Type*} [MeasurableSpace E] + +/-- The Poisson law `Poisson(μ)` pushed to `ℝ≥0∞` (via `ℕ ↪ ℝ≥0∞`) — the law of the +extended-real count `N(·, B)`. -/ +noncomputable def poissonMeasureENN (μ : ℝ≥0) : Measure ℝ≥0∞ := + (poissonMeasure μ).map (fun n : ℕ => (n : ℝ≥0∞)) + +/-- The reference intensity `Leb[0,∞) ⊗ ν` on the time-mark space `ℝ × E`. -/ +noncomputable def referenceIntensity (ν : Measure E) : Measure (ℝ × E) := + (volume.restrict (Set.Ici (0 : ℝ))).prod ν + +instance (ν : Measure E) [SigmaFinite ν] : SigmaFinite (referenceIntensity ν) := + inferInstanceAs (SigmaFinite ((volume.restrict (Set.Ici (0 : ℝ))).prod ν)) + +/-- **Poisson random measure on `[0,∞) × E`** with σ-finite mark-intensity `ν`, over a +probability space `(Ω, P)`. Its fields are the Applebaum (Def. 2.3.1) properties: each +`N(·, B)` is `Poisson(ν̂(B))`-distributed (`ν̂ = Leb[0,∞) ⊗ ν`), and `N` scatters +independently — the counts on any region disjoint from `D` are independent of `N(·, D)` +(`indep_of_disjoint_region`), which unifies disjoint-box independence with past/future +increment independence. Field shape consulted from `cgarryZA/LevyStochCalc` (cited); the +isometry built on it is our own. -/ +structure PoissonRandomMeasure (P : Measure Ω) [IsProbabilityMeasure P] + (ν : Measure E) [SigmaFinite ν] where + /-- The `ω`-indexed family of counting measures on the time-mark space `ℝ × E`. -/ + N : Ω → Measure (ℝ × E) + /-- Each evaluation `ω ↦ N(ω, B)` is measurable. -/ + measurable_eval : ∀ {B : Set (ℝ × E)}, MeasurableSet B → Measurable (fun ω => N ω B) + /-- `N(·, B)` has `Poisson(ν̂ B)` law under `P`, for finite-intensity `B`. -/ + poisson_law : ∀ {B : Set (ℝ × E)}, MeasurableSet B → referenceIntensity ν B ≠ ⊤ → + P.map (fun ω => N ω B) = poissonMeasureENN (referenceIntensity ν B).toNNReal + /-- **Independent scattering** (the defining Poisson-random-measure property, Applebaum + Def. 2.3.1(2), in its `σ`-algebra form): the counts `N(·, C)` on *all* measurable regions + `C` disjoint from `D`, jointly, are independent of the count `N(·, D)`. This single field + drives every cross-term of the Itô–Lévy isometry: it subsumes both count-independence on + disjoint boxes (take a two-element family) and past/future increment independence (the past + at `s` lives on `(-∞,s] × E`, disjoint from any future box `(s,t] × A`). -/ + indep_of_disjoint_region : ∀ {D : Set (ℝ × E)}, MeasurableSet D → + Indep + (⨆ C ∈ {C : Set (ℝ × E) | Disjoint C D ∧ MeasurableSet C}, + MeasurableSpace.comap (fun ω => N ω C) inferInstance) + (MeasurableSpace.comap (fun ω => N ω D) inferInstance) P + +/-- The **compensated increment** `Ñ(B) := N(B) − ν̂(B)` (a real number for finite-intensity +`B`) — the mean-zero, `L²` object one integrates against. -/ +noncomputable def PoissonRandomMeasure.compensated {P : Measure Ω} [IsProbabilityMeasure P] + {ν : Measure E} [SigmaFinite ν] (N : PoissonRandomMeasure P ν) + (B : Set (ℝ × E)) (ω : Ω) : ℝ := + (N.N ω B).toReal - (referenceIntensity ν B).toReal + +/-- The compensated increment `Ñ(B)` is measurable. -/ +theorem PoissonRandomMeasure.measurable_compensated {P : Measure Ω} [IsProbabilityMeasure P] + {ν : Measure E} [SigmaFinite ν] (N : PoissonRandomMeasure P ν) {B : Set (ℝ × E)} + (hB : MeasurableSet B) : Measurable (N.compensated B) := + ((N.measurable_eval hB).ennreal_toReal).sub measurable_const + +/-! ### Compensated-increment moments (transport of the scalar moments through `poisson_law`) -/ + +/-- Integral against `poissonMeasureENN` reduces to a `ℕ`-integral against `poissonMeasure`. -/ +private theorem integral_poissonMeasureENN (μ : ℝ≥0) (g : ℝ≥0∞ → ℝ) (hg : Measurable g) : + ∫ y, g y ∂(poissonMeasureENN μ) = ∫ n : ℕ, g (n : ℝ≥0∞) ∂(poissonMeasure μ) := by + unfold poissonMeasureENN + rw [integral_map (by fun_prop) hg.aestronglyMeasurable] + +variable {P : Measure Ω} [IsProbabilityMeasure P] {ν : Measure E} [SigmaFinite ν] + +/-- Transport `∫ g(N(B)) ∂P` to a Poisson `ℕ`-integral, via the `poisson_law` field. -/ +private theorem integral_count_g (N : PoissonRandomMeasure P ν) {B : Set (ℝ × E)} + (hB : MeasurableSet B) (hfin : referenceIntensity ν B ≠ ⊤) + (g : ℝ≥0∞ → ℝ) (hg : Measurable g) : + ∫ ω, g (N.N ω B) ∂P + = ∫ n : ℕ, g (n : ℝ≥0∞) ∂(poissonMeasure (referenceIntensity ν B).toNNReal) := by + have h1 : ∫ ω, g (N.N ω B) ∂P = ∫ y, g y ∂(P.map (fun ω => N.N ω B)) := + (integral_map (N.measurable_eval hB).aemeasurable hg.aestronglyMeasurable).symm + rw [h1, N.poisson_law hB hfin, integral_poissonMeasureENN _ _ hg] + +/-- **Compensated first moment `HasSum`**: `∑' n, c_r(n)·(n − r) = 0`. -/ +private theorem hasSum_pw_compensated (r : ℝ≥0) : + HasSum (fun n => pw r n * ((n : ℝ) - (r : ℝ))) 0 := by + have h : HasSum (fun n => pw r n * (n : ℝ) - (r : ℝ) * pw r n) ((r : ℝ) - (r : ℝ) * 1) := + (hasSum_pw_mul_id r).sub ((hasSum_pw r).mul_left (r : ℝ)) + rw [show (r : ℝ) - (r : ℝ) * 1 = 0 from by ring] at h + have hfun : (fun n => pw r n * ((n : ℝ) - (r : ℝ))) + = (fun n => pw r n * (n : ℝ) - (r : ℝ) * pw r n) := by funext n; ring + rw [hfun]; exact h + +/-- **Compensated second moment `HasSum`**: `∑' n, c_r(n)·(n − r)² = r`. -/ +private theorem hasSum_pw_compensated_sq (r : ℝ≥0) : + HasSum (fun n => pw r n * ((n : ℝ) - (r : ℝ)) ^ 2) (r : ℝ) := by + have h : HasSum + (fun n => pw r n * (n : ℝ) ^ 2 - 2 * (r : ℝ) * (pw r n * (n : ℝ)) + (r : ℝ) ^ 2 * pw r n) + ((r : ℝ) ^ 2 + (r : ℝ) - 2 * (r : ℝ) * (r : ℝ) + (r : ℝ) ^ 2 * 1) := + ((hasSum_pw_mul_sq r).sub ((hasSum_pw_mul_id r).mul_left (2 * (r : ℝ)))).add + ((hasSum_pw r).mul_left ((r : ℝ) ^ 2)) + rw [show (r : ℝ) ^ 2 + (r : ℝ) - 2 * (r : ℝ) * (r : ℝ) + (r : ℝ) ^ 2 * 1 = (r : ℝ) from by ring] + at h + have hfun : (fun n => pw r n * ((n : ℝ) - (r : ℝ)) ^ 2) + = (fun n => pw r n * (n : ℝ) ^ 2 - 2 * (r : ℝ) * (pw r n * (n : ℝ)) + (r : ℝ) ^ + 2 * pw r n) := by + funext n; ring + rw [hfun]; exact h + +/-- **Compensated increment is mean-zero**: `𝔼[Ñ(B)] = 0` (finite-intensity `B`). -/ +theorem compensated_integral_zero (N : PoissonRandomMeasure P ν) {B : Set (ℝ × E)} + (hB : MeasurableSet B) (hfin : referenceIntensity ν B ≠ ⊤) : + ∫ ω, N.compensated B ω ∂P = 0 := by + simp only [PoissonRandomMeasure.compensated] + rw [integral_count_g N hB hfin + (fun x => x.toReal - (referenceIntensity ν B).toReal) (by fun_prop)] + simp only [ENNReal.toReal_natCast] + rw [integral_poissonMeasure] + simp only [smul_eq_mul] + exact (hasSum_pw_compensated (referenceIntensity ν B).toNNReal).tsum_eq + +/-- **Compensated increment second moment**: `𝔼[Ñ(B)²] = ν̂(B)` (finite-intensity `B`) — +this is the diagonal energy the Itô–Lévy isometry sums. -/ +theorem compensated_integral_sq (N : PoissonRandomMeasure P ν) {B : Set (ℝ × E)} + (hB : MeasurableSet B) (hfin : referenceIntensity ν B ≠ ⊤) : + ∫ ω, (N.compensated B ω) ^ 2 ∂P = (referenceIntensity ν B).toReal := by + simp only [PoissonRandomMeasure.compensated] + rw [integral_count_g N hB hfin + (fun x => (x.toReal - (referenceIntensity ν B).toReal) ^ 2) (by fun_prop)] + simp only [ENNReal.toReal_natCast] + rw [integral_poissonMeasure] + simp only [smul_eq_mul] + exact (hasSum_pw_compensated_sq (referenceIntensity ν B).toNNReal).tsum_eq + +/-- **The compensated increment is `L²`**: `Ñ(D) ∈ L²(P)` for finite-intensity `D`. Its law is +`Poisson(ν̂ D)` pushed through `n ↦ n − ν̂ D`, whose second moment is finite — concretely +`∑ₙ c_r(n)·(n − r)² = r < ∞` (`hasSum_pw_compensated_sq`). This is the `L²`-membership each +simple-integrand term of the Itô–Lévy isometry needs. -/ +theorem memLp_compensated (N : PoissonRandomMeasure P ν) {D : Set (ℝ × E)} + (hD : MeasurableSet D) (hfin : referenceIntensity ν D ≠ ⊤) : + MemLp (N.compensated D) 2 P := by + refine (memLp_two_iff_integrable_sq (N.measurable_compensated hD).aestronglyMeasurable).mpr ?_ + have hrw : (fun ω => (N.compensated D ω) ^ 2) + = (fun x : ℝ≥0∞ => (x.toReal - (referenceIntensity ν D).toReal) ^ 2) ∘ + (fun ω => N.N ω D) := rfl + rw [hrw, ← integrable_map_measure (by fun_prop) (N.measurable_eval hD).aemeasurable, + N.poisson_law hD hfin, poissonMeasureENN, + integrable_map_measure (by fun_prop) (Measurable.aemeasurable (by fun_prop)), + integrable_poissonMeasure_iff] + refine ((hasSum_pw_compensated_sq (referenceIntensity ν D).toNNReal).summable).congr fun n => ?_ + simp only [Function.comp_apply, ENNReal.toReal_natCast, Real.norm_eq_abs] + rw [abs_of_nonneg (sq_nonneg _)] + rfl + +end MathFin diff --git a/LeanPool/MathFin/Probability/Jumps/PoissonSuperposition.lean b/LeanPool/MathFin/Probability/Jumps/PoissonSuperposition.lean new file mode 100644 index 0000000000..bef8483fb4 --- /dev/null +++ b/LeanPool/MathFin/Probability/Jumps/PoissonSuperposition.lean @@ -0,0 +1,112 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Jumps.PoissonCounting + +/-! +# Superposition of Poisson streams: merging two arrival-time constructions + +Two counting processes built from independent families of i.i.d. `Exp(r₁)` and `Exp(r₂)` +interarrival times (`Probability/Jumps/PoissonCounting`) merge into a count with +`Poisson((r₁ + r₂)·t)` +law at every time `t ≥ 0`. The marginal laws are derived by `map_count_eq_poissonMeasure`, and the +independence of the two counts is derived from that of the interarrival families; the +convolution is Mathlib's `IndepFun.hasLaw_add_poissonMeasure` (the sum of independent Poisson +variables is Poisson), consumed directly. This is the one-time marginal of the merged stream; +that the merged count is a Poisson process (independent increments, exponential merged +interarrival times) is not proved. + +## Main results + +* `PoissonSuperposition.map_add_count_eq_poissonMeasure` — the merged count has + `Poisson((r₁ + r₂)·t)` law at every time `t ≥ 0`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Theorem 3.3.9 + +## Tags + +superposition of Poisson processes, merged arrival stream, sum of independent Poisson, +counting process, interarrival times, MSC 60G55, MSC 60E05 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal + +namespace PoissonSuperposition + +/-! ### Merging two arrival-time constructions -/ + +/-- A counting process read off its interarrival times is a function of the whole family of +interarrival times: `N t` is measurable for the σ-algebra that family generates. -/ +lemma measurable_count_comap {Ω : Type*} {ξ : ℕ → Ω → ℝ} + {N : ℝ → Ω → ℕ} + (hcount : ∀ t k ω, N t ω = k ↔ + (∑ i ∈ Finset.range k, ξ i ω) ≤ t ∧ t < ∑ i ∈ Finset.range (k + 1), ξ i ω) (t : ℝ) : + Measurable[MeasurableSpace.comap (fun ω i ↦ ξ i ω) inferInstance] (N t) := by + refine @measurable_to_countable' ℕ Ω _ _ + (MeasurableSpace.comap (fun ω i ↦ ξ i ω) inferInstance) (N t) fun k ↦ + ⟨{x : ℕ → ℝ | (∑ i ∈ Finset.range k, x i) ≤ t ∧ t < ∑ i ∈ Finset.range (k + 1), x i}, + ?_, ?_⟩ + · exact (measurableSet_le (Finset.measurable_sum _ fun i _ ↦ measurable_pi_apply i) + measurable_const).inter + (measurableSet_lt measurable_const (Finset.measurable_sum _ fun i _ ↦ measurable_pi_apply i)) + · ext ω + simp only [Set.mem_preimage, Set.mem_ofPred_eq, Set.mem_singleton_iff, hcount] + +/-- **Superposition of two arrival-time constructions.** Let `ξ` and `η` be families of i.i.d. +`Exp(r₁)` and `Exp(r₂)` interarrival times, independent of each other, and `N₁`, `N₂` the +counting processes they generate (`N t = k` iff the `k`-th arrival has happened by `t` but the +`(k+1)`-st has not). Then for every `t ≥ 0` the merged count `N₁ t + N₂ t` has the +`Poisson((r₁ + r₂)·t)` law. + +The marginals `Poisson(r₁ t)` and `Poisson(r₂ t)` are derived from the constructions +(`PoissonCounting.map_count_eq_poissonMeasure`); the two counts are independent because each is +a function of its own interarrival family (`measurable_count_comap`); the convolution is +`IndepFun.hasLaw_add_poissonMeasure`. Only the one-time marginal of the merged stream is stated. -/ +theorem map_add_count_eq_poissonMeasure {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsProbabilityMeasure μ] {r₁ r₂ : ℝ≥0} (hr₁ : 0 < r₁) (hr₂ : 0 < r₂) {ξ η : ℕ → Ω → ℝ} + (hξm : ∀ i, Measurable (ξ i)) (hηm : ∀ i, Measurable (η i)) + (hξ0 : ∀ i ω, 0 ≤ ξ i ω) (hη0 : ∀ i ω, 0 ≤ η i ω) + (hξlaw : ∀ i, μ.map (ξ i) = expMeasure r₁) (hηlaw : ∀ i, μ.map (η i) = expMeasure r₂) + (hξind : iIndepFun ξ μ) (hηind : iIndepFun η μ) + (hξη : IndepFun (fun ω i ↦ ξ i ω) (fun ω i ↦ η i ω) μ) + {N₁ N₂ : ℝ → Ω → ℕ} + (hN₁ : ∀ t k ω, N₁ t ω = k ↔ + (∑ i ∈ Finset.range k, ξ i ω) ≤ t ∧ t < ∑ i ∈ Finset.range (k + 1), ξ i ω) + (hN₂ : ∀ t k ω, N₂ t ω = k ↔ + (∑ i ∈ Finset.range k, η i ω) ≤ t ∧ t < ∑ i ∈ Finset.range (k + 1), η i ω) + {t : ℝ} (ht : 0 ≤ t) : + μ.map (fun ω ↦ N₁ t ω + N₂ t ω) = poissonMeasure ((r₁ + r₂) * ⟨t, ht⟩) := by + have hind : IndepFun (N₁ t) (N₂ t) μ := + (IndepFun_iff_Indep _ _ _).2 (indep_of_indep_of_le_right + (indep_of_indep_of_le_left ((IndepFun_iff_Indep _ _ _).1 hξη) + (measurable_count_comap hN₁ t).comap_le) + (measurable_count_comap hN₂ t).comap_le) + have hmeas (ζ : ℕ → Ω → ℝ) (hζ : ∀ i, Measurable (ζ i)) {N : ℝ → Ω → ℕ} + (hN : ∀ t k ω, N t ω = k ↔ + (∑ i ∈ Finset.range k, ζ i ω) ≤ t ∧ t < ∑ i ∈ Finset.range (k + 1), ζ i ω) : + Measurable (N t) := + (measurable_count_comap hN t).mono + (show Measurable fun ω i ↦ ζ i ω from measurable_pi_iff.2 hζ).comap_le le_rfl + have h := hind.hasLaw_add_poissonMeasure + ⟨(hmeas ξ hξm hN₁).aemeasurable, + PoissonCounting.map_count_eq_poissonMeasure hr₁ hξm hξ0 hξlaw hξind hN₁ ht⟩ + ⟨(hmeas η hηm hN₂).aemeasurable, + PoissonCounting.map_count_eq_poissonMeasure hr₂ hηm hη0 hηlaw hηind hN₂ ht⟩ + exact h.map_eq.trans (congrArg _ (add_mul r₁ r₂ _).symm) + +end PoissonSuperposition + +end MathFin diff --git a/LeanPool/MathFin/Probability/Jumps/PoissonThinning.lean b/LeanPool/MathFin/Probability/Jumps/PoissonThinning.lean new file mode 100644 index 0000000000..85466815fc --- /dev/null +++ b/LeanPool/MathFin/Probability/Jumps/PoissonThinning.lean @@ -0,0 +1,421 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Distributions.Poisson.Basic +public import Mathlib.Probability.IdentDistrib +public import Mathlib.Topology.UniformSpace.Uniformizable + +/-! +# Thinning (splitting) of a Poisson count: the binomial-marking factorisation + +Last and Penrose's Proposition 1.3 gives the thinning law for a single Poisson count. +Mark each event of a `Poisson(r)` count independently as type 1 with +probability `p` or type 2 with probability `1 − p`. The two type counts +are independent Poisson variables with rates `p·r` and `(1−p)·r`. +Saporito's Theorem 3.3.10 gives the component process laws by an +interarrival argument. + +The textbook marking mechanism says: the joint pmf of the pair +`(type-1 count, type-2 count)` at `(j, k)` is + + `P(N = j+k) · C(j+k, j) pʲ (1−p)ᵏ = e^{−r} r^{j+k}/(j+k)! · C(j+k,j) pʲ (1−p)ᵏ` + +(a Poisson count split by a conditional Binomial). This file takes exactly +that marking law as the hypothesis and **derives** the theorem: the marked +joint measure *is* the product `Poisson(p·r) × Poisson((1−p)·r)`. The heart is +the pointwise factorisation `C(j+k,j)/(j+k)! = 1/(j!·k!)` together with +`e^{−r} = e^{−p·r}·e^{−(1−p)·r}` — after which marginals fall out by +projection and independence by the joint-law-equals-product-law criterion. + +The marking law itself is derived as well, from the mechanism it describes: a `Poisson(r)` +count `N` and i.i.d. marks `Y 0, Y 1, …` independent of `N`, the type of the `i`-th event being +whether `Y i` lies in a set `A`. Given `N = n` the number of the first `n` marks in `A` is +`Binomial(n, p)` with `p = P(Y 0 ∈ A)`, by independence and identical distribution of the +marks (a sum over the `C(n, j)` sets of `j` indices), and `N` is independent of the marks; so +the pair of counts satisfies the marking hypothesis (`thinned_streams_of_iid_marks`). + +## Main definitions + +* `markedWeight`: the weight `e^{−r} r^{j+k}/(j+k)! · C(j+k, j) pʲ (1−p)ᵏ` of the binomially + marked `Poisson(r)` pair law at `(j, k)`. +* `markedPoissonMeasure`: the measure on `ℕ × ℕ` with these weights. +* `marksIn`: the number of the first `n` marks `Y 0, …, Y (n−1)` that lie in `A`. + +## Main results + +* `PoissonThinning.markedPoissonMeasure_eq_prod` — the marked joint measure + factorises as `Poisson(p·r) ×ₘ Poisson((1−p)·r)`. +* `PoissonThinning.thinned_streams` — for counts `M, K` whose joint law is the + binomial marking of `Poisson(r)`: `M ∼ Poisson(p·r)`, `K ∼ Poisson((1−p)·r)`, + and `M ⟂ K`. `thinned_streams₀` gives the same statement for a.e.-measurable counts. +* `PoissonThinning.measure_marksIn_eq` — the number of the first `n` i.i.d. marks in `A` is + `Binomial(n, P(Y 0 ∈ A))`. +* `PoissonThinning.thinned_streams_of_iid_marks` — for a `Poisson(r)` count with i.i.d. marks + independent of it, the counts of marks in `A` and in + `Aᶜ` are independent with laws `Poisson(p·r)` and `Poisson((1−p)·r)`. + +## References + +* G. Last and M. Penrose, *Lectures on the Poisson Process*, Proposition 1.3, + for the product law of the two counts. +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Theorem 3.3.10, + for the component Poisson process laws. + +## Tags + +Poisson thinning, Poisson splitting, binomial marking, independent Poisson counts, +marked Poisson process, MSC 60G55, MSC 60E05 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal Nat + +namespace PoissonThinning + +/-! ### The marked joint measure -/ + +/-- Weight of the binomially-marked `Poisson(r)` pair law at `(j, k)`: +`e^{−r} r^{j+k}/(j+k)! · C(j+k, j) pʲ (1−p)ᵏ` — "`j+k` events arrived, and a +Binomial(`j+k`, `p`) draw sent `j` of them to stream 1". -/ +noncomputable def markedWeight (r p : ℝ≥0) (jk : ℕ × ℕ) : ℝ := + rexp (-(r : ℝ)) * (r : ℝ) ^ (jk.1 + jk.2) / (jk.1 + jk.2)! * + ((jk.1 + jk.2).choose jk.1) * (p : ℝ) ^ jk.1 * (1 - (p : ℝ)) ^ jk.2 + +/-- The joint law of the two thinned counts, as a measure on `ℕ × ℕ`. -/ +noncomputable def markedPoissonMeasure (r p : ℝ≥0) : Measure (ℕ × ℕ) := + Measure.sum fun jk ↦ ENNReal.ofReal (markedWeight r p jk) • Measure.dirac jk + +lemma markedPoissonMeasure_singleton (r p : ℝ≥0) (jk : ℕ × ℕ) : + markedPoissonMeasure r p {jk} = ENNReal.ofReal (markedWeight r p jk) := by + rw [markedPoissonMeasure, Measure.sum_smul_dirac_singleton] + +/-! ### The pointwise factorisation -/ + +/-- **Pointwise factorisation of the marked weight.** For `p ≤ 1`, +`e^{−r} r^{j+k}/(j+k)! · C(j+k,j) pʲ (1−p)ᵏ + = [e^{−pr}(pr)ʲ/j!] · [e^{−(1−p)r}((1−p)r)ᵏ/k!]`. -/ +private lemma markedWeight_eq {r p : ℝ≥0} (hp : p ≤ 1) (j k : ℕ) : + markedWeight r p (j, k) + = rexp (-((p * r : ℝ≥0) : ℝ)) * ((p * r : ℝ≥0) : ℝ) ^ j / j ! * + (rexp (-(((1 - p) * r : ℝ≥0) : ℝ)) * + (((1 - p) * r : ℝ≥0) : ℝ) ^ k / k !) := by + have hq : (((1 : ℝ≥0) - p : ℝ≥0) : ℝ) = 1 - (p : ℝ) := by + rw [NNReal.coe_sub hp, NNReal.coe_one] + have hfact : ((j + k).choose j : ℝ) * (j ! : ℝ) * (k ! : ℝ) = ((j + k)! : ℝ) := by + rw [show (j + k).choose j = (j + k).choose k from Nat.choose_symm_add] + exact_mod_cast congrArg (Nat.cast : ℕ → ℝ) + (Nat.add_choose_mul_factorial_mul_factorial j k) + have hsplit : rexp (-(r : ℝ)) + = rexp (-((p : ℝ) * r)) * rexp (-((1 - (p : ℝ)) * r)) := by + rw [← Real.exp_add] + congr 1 + ring + have hj0 : (j ! : ℝ) ≠ 0 := by positivity + have hk0 : (k ! : ℝ) ≠ 0 := by positivity + have hjk0 : ((j + k)! : ℝ) ≠ 0 := by positivity + rw [markedWeight] + push_cast [hq] + rw [hsplit] + simp only [mul_pow] + field_simp + linear_combination (r : ℝ) ^ (j + k) * (p : ℝ) ^ j * (1 - (p : ℝ)) ^ k * hfact + +/-! ### The measure-level factorisation -/ + +/-- **Poisson thinning factorisation.** The binomially +marked `Poisson(r)` joint measure is the product +`Poisson(p·r) ×ₘ Poisson((1−p)·r)` — thinned streams are independent Poissons +at the thinned rates. -/ +theorem markedPoissonMeasure_eq_prod (r : ℝ≥0) {p : ℝ≥0} (hp : p ≤ 1) : + markedPoissonMeasure r p + = (poissonMeasure (p * r)).prod (poissonMeasure ((1 - p) * r)) := by + refine Measure.ext_of_singleton fun jk ↦ ?_ + obtain ⟨j, k⟩ := jk + rw [markedPoissonMeasure_singleton, markedWeight_eq hp, + show ({(j, k)} : Set (ℕ × ℕ)) = {j} ×ˢ {k} from + (Set.singleton_prod_singleton).symm, + Measure.prod_prod, poissonMeasure_singleton, poissonMeasure_singleton, + ENNReal.ofReal_mul (by positivity)] + +/-! ### Thinned streams at random-variable level -/ + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + +/-- The marking hypothesis at event level determines the joint law (a.e.-measurable counts). -/ +theorem map_pair_eq_marked₀ {M K : Ω → ℕ} (hM : AEMeasurable M μ) (hK : AEMeasurable K μ) + {r p : ℝ≥0} + (hjoint : ∀ j k : ℕ, μ {ω | M ω = j ∧ K ω = k} + = ENNReal.ofReal (markedWeight r p (j, k))) : + μ.map (fun ω ↦ (M ω, K ω)) = markedPoissonMeasure r p := by + refine Measure.ext_of_singleton fun jk ↦ ?_ + obtain ⟨j, k⟩ := jk + rw [Measure.map_apply_of_aemeasurable (hM.prodMk hK) (measurableSet_singleton _), + markedPoissonMeasure_singleton, + show (fun ω ↦ (M ω, K ω)) ⁻¹' {(j, k)} = {ω | M ω = j ∧ K ω = k} by + ext ω; simp [Prod.ext_iff]] + exact hjoint j k + +/-- The marking hypothesis at event level determines the joint law. -/ +theorem map_pair_eq_marked {M K : Ω → ℕ} (hM : Measurable M) (hK : Measurable K) + {r p : ℝ≥0} + (hjoint : ∀ j k : ℕ, μ {ω | M ω = j ∧ K ω = k} + = ENNReal.ofReal (markedWeight r p (j, k))) : + μ.map (fun ω ↦ (M ω, K ω)) = markedPoissonMeasure r p := + map_pair_eq_marked₀ hM.aemeasurable hK.aemeasurable hjoint + +/-- **Poisson thinning for a.e.-measurable counts.** If the law of `(M, K)` is the binomial +marking of `Poisson(r)` with marking probability `p ≤ 1`, then `M ∼ Poisson(p·r)`, +`K ∼ Poisson((1−p)·r)`, and `M` and `K` are independent. -/ +theorem thinned_streams₀ {M K : Ω → ℕ} (hM : AEMeasurable M μ) (hK : AEMeasurable K μ) + {r p : ℝ≥0} (hp : p ≤ 1) + (hjoint : ∀ j k : ℕ, μ {ω | M ω = j ∧ K ω = k} + = ENNReal.ofReal (markedWeight r p (j, k))) : + μ.map M = poissonMeasure (p * r) ∧ + μ.map K = poissonMeasure ((1 - p) * r) ∧ + IndepFun M K μ := by + have hpair : μ.map (fun ω ↦ (M ω, K ω)) + = (poissonMeasure (p * r)).prod (poissonMeasure ((1 - p) * r)) := by + rw [map_pair_eq_marked₀ hM hK hjoint, markedPoissonMeasure_eq_prod r hp] + have hMlaw : μ.map M = poissonMeasure (p * r) := by + rw [← Measure.fst_map_prodMk₀ hM hK, hpair, Measure.fst_prod] + have hKlaw : μ.map K = poissonMeasure ((1 - p) * r) := by + rw [← Measure.snd_map_prodMk₀ hM hK, hpair, Measure.snd_prod] + have σM : SigmaFinite (μ.map M) := by rw [hMlaw]; infer_instance + have σK : SigmaFinite (μ.map K) := by rw [hKlaw]; infer_instance + refine ⟨hMlaw, hKlaw, ?_⟩ + rw [indepFun_iff_map_prod_eq_prod_map_map' hM hK σM σK, hMlaw, hKlaw] + exact hpair + +/-- **Poisson thinning.** If the joint law of the type counts `(M, K)` is the binomial marking +of `Poisson(r)` with marking probability `p ≤ 1`, then `M ∼ Poisson(p·r)`, +`K ∼ Poisson((1−p)·r)`, and `M` and `K` are **independent**. -/ +theorem thinned_streams {M K : Ω → ℕ} (hM : Measurable M) (hK : Measurable K) + {r p : ℝ≥0} (hp : p ≤ 1) + (hjoint : ∀ j k : ℕ, μ {ω | M ω = j ∧ K ω = k} + = ENNReal.ofReal (markedWeight r p (j, k))) : + μ.map M = poissonMeasure (p * r) ∧ + μ.map K = poissonMeasure ((1 - p) * r) ∧ + IndepFun M K μ := + thinned_streams₀ hM.aemeasurable hK.aemeasurable hp hjoint + +/-! ### Thinning by i.i.d. marks -/ + +section IidMarks + +open Finset + +variable {α : Type*} {mα : MeasurableSpace α} + +open scoped Classical in +/-- The number of the first `n` marks `Y 0 ω, …, Y (n - 1) ω` that lie in `A`. -/ +noncomputable def marksIn (Y : ℕ → Ω → α) (A : Set α) (n : ℕ) (ω : Ω) : ℕ := + ((range n).filter fun i ↦ Y i ω ∈ A).card + +open scoped Classical in +/-- The event that the indices `i < n` with `Y i ∈ A` are exactly `S ⊆ range n` is the +intersection of the events `{Y i ∈ A}` (`i ∈ S`) and `{Y i ∉ A}` (`i ∉ S`), `i < n`. -/ +lemma setOf_filter_eq (Y : ℕ → Ω → α) (A : Set α) {n : ℕ} {S : Finset ℕ} + (hS : S ⊆ range n) : + {ω | (range n).filter (fun i ↦ Y i ω ∈ A) = S} + = ⋂ i ∈ range n, Y i ⁻¹' (if i ∈ S then A else Aᶜ) := by + ext ω + simp only [Set.mem_ofPred_eq, Set.mem_iInter, Set.mem_preimage, Finset.ext_iff, mem_filter, + mem_range] + constructor + · intro h i hi + split_ifs with hiS + · exact ((h i).2 hiS).2 + · exact fun hA ↦ hiS ((h i).1 ⟨hi, hA⟩) + · intro h i + constructor + · rintro ⟨hi, hA⟩ + have hi' := h i hi + split_ifs at hi' with hiS + · exact hiS + · exact absurd hA hi' + · intro hiS + have hi := mem_range.1 (hS hiS) + have hi' := h i hi + rw [ite_eq_left hiS] at hi' + exact ⟨hi, hi'⟩ + +open scoped Classical in +lemma measurableSet_setOf_filter_eq {Y : ℕ → Ω → α} (hY : ∀ i, Measurable (Y i)) {A : Set α} + (hA : MeasurableSet A) {n : ℕ} {S : Finset ℕ} (hS : S ⊆ range n) : + MeasurableSet {ω | (range n).filter (fun i ↦ Y i ω ∈ A) = S} := by + rw [setOf_filter_eq Y A hS] + exact Finset.measurableSet_biInter _ fun i _ ↦ hY i (by split_ifs; exacts [hA, hA.compl]) + +open scoped Classical in +/-- **The pattern of marks.** For i.i.d. marks, the probability that the indices `i < n` with +`Y i ∈ A` are exactly `S ⊆ range n` is `pᵏ (1 − p)ⁿ⁻ᵏ`, `p = P(Y 0 ∈ A)`, `k = #S`. -/ +lemma measure_setOf_filter_eq [IsProbabilityMeasure μ] {Y : ℕ → Ω → α} + (hY : ∀ i, Measurable (Y i)) (hind : iIndepFun Y μ) (hid : ∀ i, IdentDistrib (Y i) (Y 0) μ μ) + {A : Set α} (hA : MeasurableSet A) {n : ℕ} {S : Finset ℕ} (hS : S ⊆ range n) : + μ {ω | (range n).filter (fun i ↦ Y i ω ∈ A) = S} + = μ (Y 0 ⁻¹' A) ^ S.card * (1 - μ (Y 0 ⁻¹' A)) ^ (n - S.card) := by + have hp (i : ℕ) : μ (Y i ⁻¹' A) = μ (Y 0 ⁻¹' A) := (hid i).measure_mem_eq hA + have hq (i : ℕ) : μ (Y i ⁻¹' Aᶜ) = 1 - μ (Y 0 ⁻¹' A) := by + rw [Set.preimage_compl, prob_compl_eq_one_sub (hY i hA), hp i] + have hc1 : ((range n).filter fun i ↦ i ∈ S).card = S.card := by + rw [filter_mem_eq_inter, inter_eq_right.2 hS] + have hc2 : ((range n).filter fun i ↦ ¬ i ∈ S).card = n - S.card := by + have h := card_filter_add_card_filter_not (s := range n) fun i ↦ i ∈ S + rw [hc1, card_range] at h + omega + have hfac : ∀ i ∈ range n, μ (Y i ⁻¹' (if i ∈ S then A else Aᶜ)) + = if i ∈ S then μ (Y 0 ⁻¹' A) else 1 - μ (Y 0 ⁻¹' A) := fun i _ ↦ by + split_ifs + exacts [hp i, hq i] + have hmeas : ∀ i ∈ range n, MeasurableSet (if i ∈ S then A else Aᶜ) := fun i _ ↦ by + split_ifs + exacts [hA, hA.compl] + rw [setOf_filter_eq Y A hS, + hind.measure_inter_preimage_eq_mul (range n) (sets := fun i ↦ if i ∈ S then A else Aᶜ) hmeas, + prod_congr rfl hfac, prod_ite, prod_const, prod_const, hc1, hc2] + +open scoped Classical in +/-- The event "exactly `j` of the first `n` marks lie in `A`" is the disjoint union, over the +`j`-element subsets `S` of `range n`, of the events "the marks in `A` are exactly `S`". -/ +lemma setOf_marksIn_eq (Y : ℕ → Ω → α) (A : Set α) (n j : ℕ) : + {ω | marksIn Y A n ω = j} + = ⋃ S ∈ (range n).powersetCard j, {ω | (range n).filter (fun i ↦ Y i ω ∈ A) = S} := by + ext ω + simp only [marksIn, Set.mem_ofPred_eq, Set.mem_iUnion, mem_powersetCard, exists_prop] + constructor + · intro h + exact ⟨_, ⟨filter_subset _ _, h⟩, rfl⟩ + · rintro ⟨S, ⟨-, hS⟩, rfl⟩ + exact hS + +open scoped Classical in +lemma measurableSet_marksIn_eq {Y : ℕ → Ω → α} (hY : ∀ i, Measurable (Y i)) {A : Set α} + (hA : MeasurableSet A) (n j : ℕ) : MeasurableSet {ω | marksIn Y A n ω = j} := by + rw [setOf_marksIn_eq] + exact Finset.measurableSet_biUnion _ fun S hS ↦ + measurableSet_setOf_filter_eq hY hA (mem_powersetCard.1 hS).1 + +open scoped Classical in +/-- **The binomial count of i.i.d. marks.** For i.i.d. marks, the number of the first `n` marks +in `A` is `Binomial(n, p)`, `p = P(Y 0 ∈ A)`: +`P(#{i < n : Y i ∈ A} = j) = C(n, j) pʲ (1 − p)ⁿ⁻ʲ`. -/ +theorem measure_marksIn_eq [IsProbabilityMeasure μ] {Y : ℕ → Ω → α} + (hY : ∀ i, Measurable (Y i)) (hind : iIndepFun Y μ) (hid : ∀ i, IdentDistrib (Y i) (Y 0) μ μ) + {A : Set α} (hA : MeasurableSet A) (n j : ℕ) : + μ {ω | marksIn Y A n ω = j} + = n.choose j * μ (Y 0 ⁻¹' A) ^ j * (1 - μ (Y 0 ⁻¹' A)) ^ (n - j) := by + rw [setOf_marksIn_eq, measure_biUnion_finset] + · have hterm : ∀ S ∈ (range n).powersetCard j, + μ {ω | (range n).filter (fun i ↦ Y i ω ∈ A) = S} + = μ (Y 0 ⁻¹' A) ^ j * (1 - μ (Y 0 ⁻¹' A)) ^ (n - j) := fun S hS ↦ by + rw [measure_setOf_filter_eq hY hind hid hA (mem_powersetCard.1 hS).1, + (mem_powersetCard.1 hS).2] + rw [sum_congr rfl hterm, sum_const, card_powersetCard, card_range, nsmul_eq_mul, mul_assoc] + · intro S _ T _ hST + exact Set.disjoint_left.2 fun ω h₁ h₂ ↦ + hST ((show (range n).filter (fun i ↦ Y i ω ∈ A) = S from h₁).symm.trans h₂) + · exact fun S hS ↦ measurableSet_setOf_filter_eq hY hA (mem_powersetCard.1 hS).1 + +open scoped Classical in +/-- The count of marks in `A` among the first `n`, as a function of `n` and of the whole mark +sequence, is measurable. -/ +lemma measurable_marksIn_uncurry {A : Set α} (hA : MeasurableSet A) : + Measurable fun q : ℕ × (ℕ → α) ↦ marksIn (fun i y ↦ y i) A q.1 q.2 := by + refine measurable_to_countable' fun j ↦ ?_ + have h : (fun q : ℕ × (ℕ → α) ↦ marksIn (fun i y ↦ y i) A q.1 q.2) ⁻¹' {j} + = ⋃ n : ℕ, {n} ×ˢ {y | marksIn (fun i y ↦ y i) A n y = j} := by + ext ⟨n, y⟩ + simp + rw [h] + exact MeasurableSet.iUnion fun n ↦ (measurableSet_singleton n).prod + (measurableSet_marksIn_eq (fun i ↦ measurable_pi_apply i) hA n j) + +open scoped Classical in +/-- **Thinning by i.i.d. marks** (Last and Penrose, Proposition 1.3). Let `N` be a `Poisson(r)` +count and `Y 0, Y 1, …` i.i.d. marks independent of `N`, and let `A` be a measurable set of marks, +`p = P(Y 0 ∈ A)`. Then the number of the first `N` marks in `A` and the number in `Aᶜ` are +independent, with laws `Poisson(p·r)` and `Poisson((1 − p)·r)`. + +The binomial-marking hypothesis of `thinned_streams` is derived: the pair of counts is +`(j, k)` exactly when `N = j + k` and `j` of the first `j + k` marks lie in `A`; the two events +are independent (`N` is independent of the marks), the first has probability +`e^{−r} r^{j+k}/(j+k)!` and the second `C(j+k, j) pʲ (1 − p)ᵏ` (`measure_marksIn_eq`). -/ +theorem thinned_streams_of_iid_marks [IsProbabilityMeasure μ] {r : ℝ≥0} {N : Ω → ℕ} + {Y : ℕ → Ω → α} {A : Set α} (hA : MeasurableSet A) + (hN : HasLaw N (poissonMeasure r) μ) (hY : ∀ i, Measurable (Y i)) (hind : iIndepFun Y μ) + (hid : ∀ i, IdentDistrib (Y i) (Y 0) μ μ) (hNY : IndepFun N (fun ω i ↦ Y i ω) μ) : + μ.map (fun ω ↦ marksIn Y A (N ω) ω) = poissonMeasure ((μ (Y 0 ⁻¹' A)).toNNReal * r) ∧ + μ.map (fun ω ↦ marksIn Y Aᶜ (N ω) ω) + = poissonMeasure ((1 - (μ (Y 0 ⁻¹' A)).toNNReal) * r) ∧ + IndepFun (fun ω ↦ marksIn Y A (N ω) ω) (fun ω ↦ marksIn Y Aᶜ (N ω) ω) μ := by + set p : ℝ≥0 := (μ (Y 0 ⁻¹' A)).toNNReal + have hpμ : μ (Y 0 ⁻¹' A) = p := (ENNReal.coe_toNNReal (measure_ne_top _ _)).symm + have hp1 : p ≤ 1 := by + have h := prob_le_one (μ := μ) (s := Y 0 ⁻¹' A) + rw [hpμ] at h + exact_mod_cast h + have hYvec : AEMeasurable (fun ω i ↦ Y i ω) μ := .of_eval fun i ↦ (hY i).aemeasurable + -- the marks in `Aᶜ` are the marks not in `A`, so the two counts add up to the total + have hsum (n : ℕ) (ω : Ω) : marksIn Y A n ω + marksIn Y Aᶜ n ω = n := by + have h := card_filter_add_card_filter_not (s := range n) fun i ↦ Y i ω ∈ A + rw [card_range] at h + unfold marksIn + convert h using 3 + ext i + simp + have hcount {B : Set α} (hB : MeasurableSet B) : + AEMeasurable (fun ω ↦ marksIn Y B (N ω) ω) μ := + (measurable_marksIn_uncurry hB).comp_aemeasurable (hN.aemeasurable.prodMk hYvec) + refine thinned_streams₀ (hcount hA) (hcount hA.compl) hp1 fun j k ↦ ?_ + -- the pair of counts is `(j, k)` iff `N = j + k` and `j` of the first `j + k` marks lie in `A` + have hset : {ω | marksIn Y A (N ω) ω = j ∧ marksIn Y Aᶜ (N ω) ω = k} + = N ⁻¹' {j + k} ∩ (fun ω i ↦ Y i ω) ⁻¹' {y | marksIn (fun i y ↦ y i) A (j + k) y = j} := by + ext ω + simp only [Set.mem_ofPred_eq, Set.mem_inter_iff, Set.mem_preimage, Set.mem_singleton_iff] + have htot := hsum (N ω) ω + constructor + · rintro ⟨h1, h2⟩ + have hN' : N ω = j + k := by omega + refine ⟨hN', ?_⟩ + rw [← hN'] + exact h1 + · rintro ⟨hN', h1⟩ + have h1' : marksIn Y A (N ω) ω = j := by + rw [hN'] + exact h1 + exact ⟨h1', by omega⟩ + have hmw : markedWeight r p (j, k) = (rexp (-(r : ℝ)) * (r : ℝ) ^ (j + k) / ((j + k)! : ℝ)) + * ((((j + k).choose j : ℕ) : ℝ) * (p : ℝ) ^ j * (1 - (p : ℝ)) ^ k) := by + simp only [markedWeight] + ring + have hq0 : (0 : ℝ) ≤ 1 - (p : ℝ) := sub_nonneg.2 (by exact_mod_cast hp1) + rw [hset, hNY.measure_inter_preimage_eq_mul _ _ (measurableSet_singleton (j + k)) + (measurableSet_marksIn_eq (fun i ↦ measurable_pi_apply i) hA (j + k) j), + ← Measure.map_apply_of_aemeasurable hN.aemeasurable (measurableSet_singleton (j + k)), + hN.map_eq, poissonMeasure_singleton, + show (fun ω i ↦ Y i ω) ⁻¹' {y | marksIn (fun i y ↦ y i) A (j + k) y = j} + = {ω | marksIn Y A (j + k) ω = j} from rfl, + measure_marksIn_eq hY hind hid hA, hpμ, Nat.add_sub_cancel_left, hmw, + ENNReal.ofReal_mul (by positivity : + (0 : ℝ) ≤ rexp (-(r : ℝ)) * (r : ℝ) ^ (j + k) / ((j + k)! : ℝ)), + ENNReal.ofReal_mul (by positivity : (0 : ℝ) ≤ (((j + k).choose j : ℕ) : ℝ) * (p : ℝ) ^ j), + ENNReal.ofReal_mul (Nat.cast_nonneg _), ENNReal.ofReal_natCast, + ENNReal.ofReal_pow (NNReal.coe_nonneg p), ENNReal.ofReal_coe_nnreal, ENNReal.ofReal_pow hq0, + ENNReal.ofReal_sub _ (NNReal.coe_nonneg p), ENNReal.ofReal_one, ENNReal.ofReal_coe_nnreal] + +end IidMarks + +end PoissonThinning + +end MathFin diff --git a/LeanPool/MathFin/Probability/Laws/ErlangSum.lean b/LeanPool/MathFin/Probability/Laws/ErlangSum.lean new file mode 100644 index 0000000000..17aee36c84 --- /dev/null +++ b/LeanPool/MathFin/Probability/Laws/ErlangSum.lean @@ -0,0 +1,281 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Distributions.Exponential +public import Mathlib.Probability.Independence.Basic + +/-! +# Sums of iid exponentials are Erlang: the Gamma convolution identity + +Mathlib has the Gamma and exponential distributions (`gammaMeasure`, +`expMeasure = gammaMeasure 1`) but **no convolution identity** for them: there +is no lemma computing `gammaMeasure a r ∗ expMeasure r`, and consequently no +proof that the sum of `n` iid `Exp(r)` waiting times is `Erlang(n, r)` +(Saporito, Appendix B.2). + +This file proves both, from the densities up. + +The analytic heart is the convolution of densities. For `a > 0` the +exponential factors merge into a constant — +`exp (−r·x) · exp (−r·(z−x)) = exp (−r·z)` — so the Beta-type integral +degenerates to the elementary `∫_0^z x^(a−1) dx = z^a / a`, and +`Γ(a+1) = a·Γ(a)` turns the constant into exactly the `Gamma (a+1, r)` +normalisation. No Beta function, no special-function machinery: the identity +holds for every real `a > 0` by completing the constant. + +## Main results + +* `ErlangSum.gammaMeasure_conv_expMeasure` — + `gammaMeasure a r ∗ expMeasure r = gammaMeasure (a+1) r` for `a, r > 0`. +* `ErlangSum.map_sum_iidExp` — for iid `Exp(r)` variables indexed by a + nonempty finset `s`, the law of `∑ i ∈ s, X i` is `gammaMeasure s.card r`. +* `sum_iidExp_law_gammaMeasure` — the textbook form: the sum of all `n ≥ 1` + coordinates has law `Erlang(n, r) = gammaMeasure n r`. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Appendix B.2, p. 178 + +## Tags + +Erlang distribution, Gamma convolution, exponential waiting times, Poisson process arrival time, +sum of exponentials, MSC 60E05, MSC 60G55 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal + +namespace ErlangSum + +variable {a r : ℝ} + +/-! ### The density-level convolution identity -/ + +/-- Pointwise (away from `x = 0`): the product of the `Gamma(a,r)` density at +`x` and the `Exp(r)` density at `z − x` collapses, after the exponentials +merge, to a constant multiple of `x^(a−1)` supported on `(0, z]`. -/ +lemma gammaPDF_mul_exponentialPDF_sub_of_ne_zero (ha : 0 < a) (hr : 0 < r) {z x : ℝ} (hx : x ≠ 0) : + gammaPDF a r x * exponentialPDF r (z - x) + = ENNReal.ofReal ((Set.Ioc 0 z).indicator + (fun t ↦ r ^ (a + 1) / Gamma a * Real.exp (-(r * z)) * t ^ (a - 1)) x) := by + rcases lt_or_gt_of_ne hx with hx_neg | hx_pos + · rw [gammaPDF_of_neg hx_neg, + Set.indicator_of_notMem + (show x ∉ Set.Ioc 0 z from fun h ↦ absurd h.1 (not_lt.mpr hx_neg.le)), + ENNReal.ofReal_zero, zero_mul] + · by_cases hxz : x ≤ z + · have hzx : (0 : ℝ) ≤ z - x := by linarith + rw [gammaPDF_of_nonneg hx_pos.le, exponentialPDF_eq, ite_eq_left hzx, + ← ENNReal.ofReal_mul (by positivity), + Set.indicator_of_mem (Set.mem_Ioc.mpr ⟨hx_pos, hxz⟩)] + congr 1 + have hexp : Real.exp (-(r * x)) * Real.exp (-(r * (z - x))) + = Real.exp (-(r * z)) := by + rw [← Real.exp_add]; ring_nf + calc r ^ a / Gamma a * x ^ (a - 1) * Real.exp (-(r * x)) + * (r * Real.exp (-(r * (z - x)))) + = r ^ a * r / Gamma a * x ^ (a - 1) + * (Real.exp (-(r * x)) * Real.exp (-(r * (z - x)))) := by ring + _ = r ^ (a + 1) / Gamma a * Real.exp (-(r * z)) * x ^ (a - 1) := by + rw [hexp, Real.rpow_add_one hr.ne']; ring + · rw [exponentialPDF_of_neg (by linarith), mul_zero, + Set.indicator_of_notMem (show x ∉ Set.Ioc 0 z from fun h ↦ absurd h.2 hxz), + ENNReal.ofReal_zero] + +/-- The elementary Beta-degenerate integral: `∫_{(0,z]} x^(a−1) dx = z^a / a`. -/ +lemma setIntegral_rpow_sub_one_Ioc (ha : 0 < a) {z : ℝ} (hz : 0 ≤ z) : + ∫ x in Set.Ioc 0 z, x ^ (a - 1) = z ^ a / a := by + rw [← intervalIntegral.integral_of_le hz, + integral_rpow (Or.inl (by linarith)), + show a - 1 + 1 = a from by ring, + Real.zero_rpow ha.ne', sub_zero] + +/-- **Density convolution identity.** For `a, r > 0` and every `z`, +`∫ gammaPDF a r x · exponentialPDF r (z−x) dx = gammaPDF (a+1) r z`. -/ +lemma lintegral_gammaPDF_mul_exponentialPDF + (ha : 0 < a) (hr : 0 < r) (z : ℝ) : + ∫⁻ x, gammaPDF a r x * exponentialPDF r (z - x) = gammaPDF (a + 1) r z := by + rcases lt_or_ge z 0 with hz | hz + · -- `z < 0`: integrand vanishes identically, and so does the target density + rw [gammaPDF_of_neg hz, show (fun x ↦ gammaPDF a r x * exponentialPDF r (z - x)) + = fun _ ↦ 0 from funext fun x ↦ ?_, lintegral_zero] + rcases lt_or_ge x 0 with hx | hx + · rw [gammaPDF_of_neg hx, zero_mul] + · rw [exponentialPDF_of_neg (by linarith), mul_zero] + · -- `0 ≤ z`: reduce to the elementary integral on `(0, z]` + have h0 : ∀ᵐ x : ℝ, x ≠ (0 : ℝ) := by + refine ae_iff.mpr ?_ + simp + set c : ℝ := r ^ (a + 1) / Gamma a * Real.exp (-(r * z)) with hc_def + have h_int : IntegrableOn (fun x : ℝ ↦ c * x ^ (a - 1)) (Set.Ioc 0 z) volume := by + refine Integrable.const_mul ?_ c + exact (intervalIntegral.intervalIntegrable_rpow' (by linarith)).1 + calc ∫⁻ x, gammaPDF a r x * exponentialPDF r (z - x) + = ∫⁻ x, ENNReal.ofReal + ((Set.Ioc 0 z).indicator (fun t ↦ c * t ^ (a - 1)) x) := by + refine lintegral_congr_ae ?_ + filter_upwards [h0] with x hx + exact gammaPDF_mul_exponentialPDF_sub_of_ne_zero ha hr hx + _ = ∫⁻ x, (Set.Ioc 0 z).indicator + (fun t ↦ ENNReal.ofReal (c * t ^ (a - 1))) x := by + refine lintegral_congr fun x ↦ ?_ + by_cases hx : x ∈ Set.Ioc 0 z + · rw [Set.indicator_of_mem hx, Set.indicator_of_mem hx] + · rw [Set.indicator_of_notMem hx, Set.indicator_of_notMem hx, + ENNReal.ofReal_zero] + _ = ∫⁻ x in Set.Ioc 0 z, ENNReal.ofReal (c * x ^ (a - 1)) := + lintegral_indicator measurableSet_Ioc _ + _ = ENNReal.ofReal (∫ x in Set.Ioc 0 z, c * x ^ (a - 1)) := by + rw [← ofReal_integral_eq_lintegral_ofReal h_int] + refine Filter.Eventually.mono (ae_restrict_mem measurableSet_Ioc) + fun x hx ↦ ?_ + have : (0 : ℝ) ≤ x ^ (a - 1) := Real.rpow_nonneg hx.1.le _ + positivity + _ = ENNReal.ofReal (c * (z ^ a / a)) := by + rw [integral_const_mul, setIntegral_rpow_sub_one_Ioc ha hz] + _ = gammaPDF (a + 1) r z := by + rw [gammaPDF_of_nonneg hz] + congr 1 + rw [hc_def, Real.Gamma_add_one ha.ne', show a + 1 - 1 = a from by ring] + field_simp + +/-! ### The measure-level convolution identity -/ + +/-- **Gamma–exponential convolution**: for `a, r > 0`, +`gammaMeasure a r ∗ expMeasure r = gammaMeasure (a + 1) r`. + +This identity (and any Gamma convolution) is absent from Mathlib; it is the +measure-level packaging of `lintegral_gammaPDF_mul_exponentialPDF` via +Tonelli and translation invariance of Lebesgue measure. -/ +theorem gammaMeasure_conv_expMeasure (ha : 0 < a) (hr : 0 < r) : + gammaMeasure a r ∗ expMeasure r = gammaMeasure (a + 1) r := by + have hg : Measurable (gammaPDF a r) := (measurable_gammaPDFReal a r).ennreal_ofReal + have he : Measurable (exponentialPDF r) := + (measurable_exponentialPDFReal r).ennreal_ofReal + ext s hs + have h_ind : Measurable (s.indicator (1 : ℝ → ℝ≥0∞)) := + measurable_const.indicator hs + -- expand the convolution as an iterated integral over the densities + rw [show expMeasure r = volume.withDensity (exponentialPDF r) from rfl, + show gammaMeasure a r = volume.withDensity (gammaPDF a r) from rfl] at * + rw [← lintegral_indicator_one hs, Measure.lintegral_conv h_ind] + -- unfold the inner withDensity and translate `y ↦ w − x` + have step_inner : ∀ x : ℝ, + ∫⁻ y, s.indicator 1 (x + y) ∂(volume.withDensity (exponentialPDF r)) + = ∫⁻ w, exponentialPDF r (w - x) * s.indicator 1 w := by + intro x + rw [lintegral_withDensity_eq_lintegral_mul _ he + (show Measurable fun y : ℝ ↦ s.indicator 1 (x + y) from + h_ind.comp (measurable_const_add x))] + rw [← lintegral_add_right_eq_self + (fun w ↦ exponentialPDF r (w - x) * s.indicator 1 w) x] + refine lintegral_congr fun y ↦ ?_ + simp only [Pi.mul_apply] + rw [add_sub_cancel_right, add_comm x y] + simp_rw [step_inner] + -- unfold the outer withDensity + have h_inner_meas : Measurable fun x : ℝ ↦ + ∫⁻ w, exponentialPDF r (w - x) * s.indicator 1 w := by + refine Measurable.lintegral_prod_right' (f := fun p : ℝ × ℝ ↦ + exponentialPDF r (p.2 - p.1) * s.indicator 1 p.2) ?_ + exact (he.comp (measurable_snd.sub measurable_fst)).mul (h_ind.comp measurable_snd) + rw [lintegral_withDensity_eq_lintegral_mul _ hg h_inner_meas] + -- push the density inside, Tonelli-swap, evaluate via the heart identity + have h_uncurry : Measurable fun p : ℝ × ℝ ↦ + gammaPDF a r p.1 * (exponentialPDF r (p.2 - p.1) * s.indicator 1 p.2) := + (hg.comp measurable_fst).mul + ((he.comp (measurable_snd.sub measurable_fst)).mul (h_ind.comp measurable_snd)) + calc ∫⁻ x, (gammaPDF a r * fun x ↦ + ∫⁻ w, exponentialPDF r (w - x) * s.indicator 1 w) x + = ∫⁻ x, ∫⁻ w, gammaPDF a r x * (exponentialPDF r (w - x) * s.indicator 1 w) := by + refine lintegral_congr fun x ↦ ?_ + simp only [Pi.mul_apply] + exact (lintegral_const_mul _ (show Measurable fun w : ℝ ↦ + exponentialPDF r (w - x) * s.indicator 1 w from + (he.comp (measurable_sub_const x)).mul h_ind)).symm + _ = ∫⁻ w, ∫⁻ x, gammaPDF a r x * (exponentialPDF r (w - x) * s.indicator 1 w) := + lintegral_lintegral_swap h_uncurry.aemeasurable + _ = ∫⁻ w, gammaPDF (a + 1) r w * s.indicator 1 w := by + refine lintegral_congr fun w ↦ ?_ + rw [show (fun x ↦ gammaPDF a r x * (exponentialPDF r (w - x) * s.indicator 1 w)) + = fun x ↦ gammaPDF a r x * exponentialPDF r (w - x) * s.indicator 1 w from + funext fun x ↦ by ring] + rw [lintegral_mul_const _ (show Measurable fun x : ℝ ↦ + gammaPDF a r x * exponentialPDF r (w - x) from + hg.mul (he.comp (measurable_const_sub w))), + lintegral_gammaPDF_mul_exponentialPDF ha hr w] + _ = ∫⁻ w in s, gammaPDF (a + 1) r w := by + rw [← lintegral_indicator hs] + refine lintegral_congr fun w ↦ ?_ + by_cases hw : w ∈ s + · simp [Set.indicator_of_mem hw] + · simp [Set.indicator_of_notMem hw] + _ = gammaMeasure (a + 1) r s := (withDensity_apply _ hs).symm + +/-! ### Sums of iid exponentials -/ + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + +/-- **Erlang from iid exponentials, finset form.** If the `X i` are iid +`Exp(r)` and `s` is a nonempty finset (over any index type — `Fin n` for the +textbook statement, `ℕ` for the arrival times of a Poisson process), the law +of `∑ i ∈ s, X i` is `gammaMeasure s.card r`. Induction on `s`: the base case +is `expMeasure = gammaMeasure 1` (definitional), the step is +`gammaMeasure_conv_expMeasure` via `IndepFun.map_add_eq_map_conv_map`. -/ +theorem map_sum_iidExp [IsProbabilityMeasure μ] {r : ℝ} (hr : 0 < r) + {ι : Type*} {X : ι → Ω → ℝ} (hmeas : ∀ i, Measurable (X i)) + (hlaw : ∀ i, Measure.map (X i) μ = expMeasure r) + (hindep : iIndepFun X μ) + (s : Finset ι) (hs : s.Nonempty) : + Measure.map (∑ i ∈ s, X i) μ = gammaMeasure s.card r := by + induction s using Finset.cons_induction with + | empty => exact absurd hs (by simp) + | cons i t hi ih => + rcases t.eq_empty_or_nonempty with rfl | ht + · simpa [expMeasure] using hlaw i + · have hsum_meas : Measurable (∑ j ∈ t, X j) := by + rw [show (∑ j ∈ t, X j) = fun a ↦ ∑ j ∈ t, X j a from + funext fun a ↦ Finset.sum_apply a t X] + exact t.measurable_sum fun j _ ↦ hmeas j + have hindep' : IndepFun (∑ j ∈ t, X j) (X i) μ := + hindep.indepFun_finsetSum_of_notMem hmeas hi + rw [Finset.sum_cons, + show X i + ∑ j ∈ t, X j = (∑ j ∈ t, X j) + X i from add_comm _ _, + hindep'.map_add_eq_map_conv_map hsum_meas (hmeas i), + ih ht, hlaw i, + gammaMeasure_conv_expMeasure (by exact_mod_cast ht.card_pos) hr] + congr 1 + rw [Finset.card_cons] + push_cast + ring + +/-- **Erlang law for a sum of iid exponentials** (Saporito, Appendix B.2). The `n`-th +arrival time of a `Poisson(r)` process — the sum of `n ≥ 1` iid `Exp(r)` +interarrival times — has the `Erlang(n, r) = gammaMeasure n r` law. Proved +from the densities up via the Gamma convolution identity; no part of the +conclusion is assumed. -/ +theorem sum_iidExp_law_gammaMeasure [IsProbabilityMeasure μ] {r : ℝ} (hr : 0 < r) + {n : ℕ} (hn : n ≠ 0) {X : Fin n → Ω → ℝ} (hmeas : ∀ i, Measurable (X i)) + (hlaw : ∀ i, Measure.map (X i) μ = expMeasure r) + (hindep : iIndepFun X μ) : + Measure.map (fun ω ↦ ∑ i, X i ω) μ = gammaMeasure n r := by + have : Nonempty (Fin n) := ⟨⟨0, Nat.pos_of_ne_zero hn⟩⟩ + have h := map_sum_iidExp hr hmeas hlaw hindep Finset.univ Finset.univ_nonempty + rw [show (fun ω ↦ ∑ i, X i ω) = ∑ i, X i from + funext fun ω ↦ (Finset.sum_apply ω Finset.univ X).symm] + simpa [Finset.card_univ] using h + +end ErlangSum + +end MathFin diff --git a/LeanPool/MathFin/Probability/Laws/Esscher.lean b/LeanPool/MathFin/Probability/Laws/Esscher.lean new file mode 100644 index 0000000000..9dd157f326 --- /dev/null +++ b/LeanPool/MathFin/Probability/Laws/Esscher.lean @@ -0,0 +1,203 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.Analytic.IsolatedZeros +public import Mathlib.Analysis.CStarAlgebra.Classes +public import Mathlib.MeasureTheory.Measure.Tilted +public import Mathlib.Probability.Distributions.Gaussian.Real + +/-! +# The Esscher transform of a law on `ℝ` + +The Esscher transform with parameter `θ` reweights a law `μ` on `ℝ` by `e^{θx}` and renormalizes +it: Mathlib's exponentially tilted measure `μ.tilted (θ * ·)`. Gerber and Shiu use it to choose a +pricing measure; here it acts on one law on `ℝ`. For a Gaussian law it is the static Girsanov change +of measure. + +* `integral_exp_mul_tilted_const_mul`, `mgf_id_tilted_const_mul`: the exponential moments of the + tilted law are ratios of those of `μ`, `∫ e^{ux} dμ_θ = ∫ e^{(u + θ)x} dμ / ∫ e^{θx} dμ` + (Mathlib's `integral_exp_tilted` at linear exponents). +* `integrable_exp_mul_tilted_const_mul`: `μ_θ` has the exponential moment of order `u` when `μ` has + those of orders `θ` and `u + θ`; so where the moment-generating function of `μ` is finite near + `θ`, that of `μ_θ` is finite near `0` (`zero_mem_interior_integrableExpSet_tilted`). +* `measure_eq_of_mgf_id_eventuallyEq`: a finite measure whose moment-generating function is finite + near `0` is determined by that function near `0` (the identity theorem for Mathlib's complex + moment-generating function); `measure_eq_of_mgf_id_eq` is the case of every exponential moment. +* `ofReal_integral_exp_smul_tilted`: before it is normalized the transform is a density, + `(∫ e^f dμ)·μ.tilted f = e^f·μ` when `e^f` is integrable, for a measure on any space. On a Lévy + measure this is how the transform acts on the jumps (`smul_tilted_eq_withDensity`). +* `gaussianReal_tilted_const_mul`: the transform shifts the mean of a Gaussian law, `N(m, v)` + tilted by `e^{θx}` is `N(m + θv, v)`. + +The first three identify a tilted law by computing one function. Their users: the Esscher +transform of the jump-diffusion log-return law (`jumpDiffusionIncrementLaw_tilted`) uses all three; +the Gaussian increments of `isQBrownianMotion_of_expMartingale` are identified by +`measure_eq_of_mgf_id_eq`; and the identification of the Lévy measure from the law +(`jumpDiffusionIncrementLaw_eq_iff`) applies `measure_eq_of_mgf_id_eventuallyEq` to finite measures +that are not probability laws. The Gaussian tilt gives the static Girsanov change of measure +(`gaussianReal_withDensity_esscher`, its case `N(0, 1)`), the change of drift of a jump-diffusion +law (`jumpDiffusionIncrementLaw_absolutelyContinuous`), the no-jump tilt +(`jumpDiffusionIncrementLaw_zero_tilted`) and Merton's tilted jumps (`mertonJump_tilted`). + +## Main results + +* `mgf_id_tilted_const_mul`: for the Esscher-tilted law `μ_θ = μ.tilted (θ * ·)`, + `mgf id μ_θ u = mgf id μ (u + θ) / mgf id μ θ`. +* `integral_exp_mul_tilted_const_mul`, `integrable_exp_mul_tilted_const_mul`: the same identity on + `∫ e^{ux}`, and integrability of `e^{ux}` under `μ_θ` when `e^{θx}` and `e^{(u+θ)x}` are + `μ`-integrable. +* `measure_eq_of_mgf_id_eventuallyEq`, `measure_eq_of_mgf_id_eq`: a finite measure on `ℝ` is + determined by its moment-generating function near `0` (when `0` is interior to the set of + integrable exponents), and by that function when every exponential moment exists. +* `ofReal_integral_exp_smul_tilted`: when `e^f` is `μ`-integrable, `(∫ e^f dμ)·μ.tilted f` is + the measure with density `e^f` against `μ`. +* `gaussianReal_tilted_const_mul`: tilting `N(m, v)` by `e^{θx}` gives `N(m + θ v, v)`. + +## References + +* [Esscher, *On the probability function in the collective theory of risk*][Esscher1932] +* [Gerber and Shiu, *Option pricing by Esscher transforms*][GerberShiu1994] + +## Tags + +Esscher transform, exponential tilting, Gerber–Shiu, pricing measure, Gaussian tilt, +moment generating function, MSC 60E10, MSC 91G20, JEL G13 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real Filter +open scoped NNReal Topology + +/-- **A measure is determined by its moment-generating function near `0`**: if the +moment-generating function of a finite measure `μ` on `ℝ` is finite on a neighbourhood of `0`, +every finite measure `μ'` with the same moment-generating function on a neighbourhood of `0` is +`μ`. On an interval `(-ε, ε)` of exponential moments of both, the complex moment-generating +functions are analytic in the vertical strip `|Re z| < ε` (Mathlib's `analyticOnNhd_complexMGF`) +and agree at its real points, hence on the whole strip (the identity theorem). On the imaginary +axis they are the characteristic functions (`complexMGF_id_mul_I`), which determine the measure +(`Measure.ext_of_charFun`). -/ +lemma measure_eq_of_mgf_id_eventuallyEq {μ μ' : Measure ℝ} [IsFiniteMeasure μ] + [IsFiniteMeasure μ'] (h0 : 0 ∈ interior (integrableExpSet id μ)) + (h : mgf id μ =ᶠ[𝓝 0] mgf id μ') : μ = μ' := by + -- the zero measure: `μ'` has total mass `mgf id μ' 0 = 0` + rcases eq_or_ne μ 0 with rfl | hμ0 + · have h00 : μ'.real Set.univ = 0 := by + rw [← mgf_zero' (X := id), ← h.eq_of_nhds, mgf_zero_measure, Pi.zero_apply] + rw [measureReal_eq_zero_iff, Measure.measure_univ_eq_zero] at h00 + exact h00.symm + obtain ⟨ε, hε, hball⟩ := Metric.eventually_nhds_iff_ball.1 + ((eventually_mem_set.2 (mem_interior_iff_mem_nhds.1 h0)).and h) + -- both measures have the exponential moments of the orders in `(-ε, ε)` + have hμ : Metric.ball (0 : ℝ) ε ⊆ interior (integrableExpSet id μ) := + interior_maximal (fun t ht ↦ (hball t ht).1) Metric.isOpen_ball + have hμ' : Metric.ball (0 : ℝ) ε ⊆ interior (integrableExpSet id μ') := by + refine interior_maximal (fun t ht ↦ ?_) Metric.isOpen_ball + have hpos : mgf id μ' t ≠ 0 := (hball t ht).2 ▸ (mgf_pos' (X := id) hμ0 (hball t ht).1).ne' + by_contra hint + exact hpos (mgf_undef (X := id) hint) + -- so their complex moment-generating functions agree on the strip `|Re z| < ε` + have hS : IsPreconnected {z : ℂ | z.re ∈ Metric.ball (0 : ℝ) ε} := + ((convex_ball (0 : ℝ) ε).linear_preimage Complex.reLm).isPreconnected + have hEq : Set.EqOn (complexMGF id μ) (complexMGF id μ') + {z : ℂ | z.re ∈ Metric.ball (0 : ℝ) ε} := by + refine AnalyticOnNhd.eqOn_of_preconnected_of_frequently_eq + (analyticOnNhd_complexMGF.mono fun z hz ↦ hμ hz) + (analyticOnNhd_complexMGF.mono fun z hz ↦ hμ' hz) hS (z₀ := ((0 : ℝ) : ℂ)) + (by simpa using hε) ?_ + have h_real : ∃ᶠ x : ℝ in 𝓝[≠] 0, complexMGF id μ x = complexMGF id μ' x := + (Eventually.frequently (h.filter_mono nhdsWithin_le_nhds)).mono fun y hy ↦ by + rw [complexMGF_ofReal, complexMGF_ofReal, hy] + rw [frequently_iff_seq_forall] at h_real ⊢ + obtain ⟨xs, hx_tendsto, hx_eq⟩ := h_real + refine ⟨fun n ↦ xs n, ?_, hx_eq⟩ + rw [tendsto_nhdsWithin_iff] at hx_tendsto ⊢ + exact ⟨tendsto_ofReal_iff.2 hx_tendsto.1, by simpa using hx_tendsto.2⟩ + -- on the imaginary axis they are the characteristic functions + refine Measure.ext_of_charFun (funext fun t ↦ ?_) + rw [← complexMGF_id_mul_I, ← complexMGF_id_mul_I] + exact hEq (by simpa using hε) + +/-- **A measure with exponential moments of every order is determined by its moment-generating +function**: a finite measure `μ` on `ℝ` with every exponential moment equals each finite measure +`μ'` with the same moment-generating function (`measure_eq_of_mgf_id_eventuallyEq`). -/ +lemma measure_eq_of_mgf_id_eq {μ μ' : Measure ℝ} [IsFiniteMeasure μ] [IsFiniteMeasure μ'] + (hμ : ∀ u, Integrable (fun x ↦ rexp (u * x)) μ) (h : mgf id μ = mgf id μ') : μ = μ' := by + have hset : integrableExpSet id μ = Set.univ := Set.eq_univ_of_forall hμ + exact measure_eq_of_mgf_id_eventuallyEq (by simp [hset]) (Eventually.of_forall (congr_fun h)) + +/-- **The exponential moments of an Esscher-tilted law** are ratios of those of the law: +`∫ e^{ux} dμ_θ = ∫ e^{(u + θ)x} dμ / ∫ e^{θx} dμ`, for `μ_θ = μ.tilted (θ * ·)`. This is Mathlib's +`integral_exp_tilted` at linear exponents. -/ +lemma integral_exp_mul_tilted_const_mul (μ : Measure ℝ) (θ u : ℝ) : + ∫ x, rexp (u * x) ∂(μ.tilted (θ * ·)) + = (∫ x, rexp ((u + θ) * x) ∂μ) / ∫ x, rexp (θ * x) ∂μ := by + simp only [integral_exp_tilted, Pi.add_apply, ← add_mul, add_comm θ u] + +/-- `integral_exp_mul_tilted_const_mul` in Mathlib's terms: +`mgf id μ_θ u = mgf id μ (u + θ) / mgf id μ θ`. -/ +lemma mgf_id_tilted_const_mul (μ : Measure ℝ) (θ u : ℝ) : + mgf id (μ.tilted (θ * ·)) u = mgf id μ (u + θ) / mgf id μ θ := + integral_exp_mul_tilted_const_mul μ θ u + +/-- **The Esscher transform before normalization**: when `e^f` is `μ`-integrable, `μ` tilted by `f` +and scaled back by its normalizing constant `∫ e^f dμ` is `μ` with density `e^f`. On a Lévy measure +this is how the transform acts on the jumps (`smul_tilted_eq_withDensity`). -/ +lemma ofReal_integral_exp_smul_tilted {α : Type*} {mα : MeasurableSpace α} {μ : Measure α} + {f : α → ℝ} (hf : Integrable (fun x ↦ rexp (f x)) μ) : + ENNReal.ofReal (∫ x, rexp (f x) ∂μ) • μ.tilted f + = μ.withDensity fun x ↦ ENNReal.ofReal (rexp (f x)) := by + rcases eq_zero_or_neZero μ with rfl | _ + · simp + have hm : 0 < ∫ x, rexp (f x) ∂μ := integral_exp_pos hf + rw [Measure.tilted, ← withDensity_smul' _ _ ENNReal.ofReal_ne_top] + refine congrArg μ.withDensity (funext fun x ↦ ?_) + rw [Pi.smul_apply, smul_eq_mul, ← ENNReal.ofReal_mul hm.le, mul_div_cancel₀ _ hm.ne'] + +/-- An Esscher-tilted law has the exponential moment of order `u` when the law has those of orders +`θ` and `u + θ`. -/ +lemma integrable_exp_mul_tilted_const_mul {μ : Measure ℝ} {θ u : ℝ} + (hθ : Integrable (fun x ↦ rexp (θ * x)) μ) (hu : Integrable (fun x ↦ rexp ((u + θ) * x)) μ) : + Integrable (fun x ↦ rexp (u * x)) (μ.tilted (θ * ·)) := by + rw [integrable_tilted_iff hθ] + simpa only [smul_eq_mul, ← Real.exp_add, ← add_mul, add_comm θ u] using hu + +/-- Where the moment-generating function of `μ` is finite near `θ`, `μ` has the exponential +moments of the orders `u + θ` for `u` near `0`. -/ +lemma eventually_integrable_exp_add_mul {μ : Measure ℝ} {θ : ℝ} + (hθ : θ ∈ interior (integrableExpSet id μ)) : + ∀ᶠ u in 𝓝 (0 : ℝ), Integrable (fun x ↦ rexp ((u + θ) * x)) μ := + ((continuous_add_const θ).tendsto' 0 θ (zero_add θ)).eventually_mem + (mem_interior_iff_mem_nhds.1 hθ) + +/-- Where the moment-generating function of `μ` is finite near `θ`, that of the tilted law +`μ.tilted (θ * ·)` is finite near `0` (`integrable_exp_mul_tilted_const_mul`). -/ +lemma zero_mem_interior_integrableExpSet_tilted {μ : Measure ℝ} {θ : ℝ} + (hθ : θ ∈ interior (integrableExpSet id μ)) : + 0 ∈ interior (integrableExpSet id (μ.tilted (θ * ·))) := by + have hint : ∀ᶠ u in 𝓝 (0 : ℝ), Integrable (fun x ↦ rexp (u * x)) (μ.tilted (θ * ·)) := + (eventually_integrable_exp_add_mul hθ).mono fun u hu ↦ + integrable_exp_mul_tilted_const_mul (interior_subset (s := integrableExpSet id μ) hθ) hu + exact mem_interior_iff_mem_nhds.2 hint + +/-- **The Esscher transform of a Gaussian law shifts its mean**: `N(m, v)` tilted by `e^{θx}` is +`N(m + θv, v)`. The Gaussian `N(m + θv, v)` has every exponential moment, and the two +moment-generating functions agree: `𝔼[e^{(u + θ)X}] / 𝔼[e^{θX}] = e^{(m + θv)u + vu²/2}` for +`X ~ N(m, v)` (Mathlib's `mgf_id_gaussianReal`). -/ +lemma gaussianReal_tilted_const_mul (m : ℝ) (v : ℝ≥0) (θ : ℝ) : + (gaussianReal m v).tilted (θ * ·) = gaussianReal (m + θ * v) v := by + refine Eq.symm (measure_eq_of_mgf_id_eq integrable_exp_mul_gaussianReal (funext fun u ↦ ?_)) + simp only [mgf_id_tilted_const_mul, mgf_id_gaussianReal, ← Real.exp_sub] + congr 1 + ring + +end MathFin diff --git a/LeanPool/MathFin/Probability/Laws/Estimation.lean b/LeanPool/MathFin/Probability/Laws/Estimation.lean new file mode 100644 index 0000000000..40a16498f4 --- /dev/null +++ b/LeanPool/MathFin/Probability/Laws/Estimation.lean @@ -0,0 +1,574 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Gaussian.GaussianMoments +public import LeanPool.MathFin.Probability.Gaussian.GaussianPartialMoments +public import Mathlib.MeasureTheory.Measure.LogLikelihoodRatio +public import Mathlib.Probability.Independence.Integration + +/-! +# Estimation: Gaussian variance-ratio divergence and realised-volatility bias + +**Detection.** Between two centred Gaussian regimes with variance ratio +`r = σ²_high/σ²_low`, the per-observation discrimination information is the Kullback–Leibler +divergence `D = ½(r − 1 − ln r)` (`kl_gaussianReal_var_ratio`), stated as the integral of the +log-likelihood ratio `MeasureTheory.llr` against the high-variance law. The proof writes both +laws in `withDensity` form (`gaussianReal_of_var_ne_zero`) and identifies the Radon–Nikodym +derivative with the pdf ratio (`MeasureTheory.Measure.rnDeriv_withDensity_right`). `D` is the +denominator of Wald's sequential-test delay `≈ ln(1/α)/D`; near `r = 1` it is `(r − 1)²/4` up +to a cubic remainder (`abs_klVarRatio_sub_sq_le`). + +**Realised volatility.** Observing `n` increments of second moment `σ²Δt` through mean-zero +noise of variance `η²` (each increment independent of its two noise draws, and adjacent noise +draws independent of each other) makes the expected realised variance +`σ²T + 2nη²`: a bias linear in the sampling frequency (`integral_sum_sq_noisy_increments`; +Zhang, Mykland and Aït-Sahalia). The square-root estimator of a nondegenerate variance target +is biased low, `E[σ̂] < σ` (`sqrtBias_oneSided`, with the one-sample Gaussian instance +`sqrtBias_absGaussianSample`). For one Gaussian sample the bias is exact: +`E|Z| = √(2v/π)` for `Z ∼ N(0, v)` (`integral_abs_gaussianReal`), read off the truncated first +moment of the standard normal in `Probability/Gaussian/GaussianPartialMoments.lean`. The endpoint +drift estimator `(X_T − X_0)/T` of `X_t = μt + σB_t` has law `N(μ, σ²/T)`, so its standard error +`σ/√T` does not depend on the sampling frequency (`drift_se_endpoint_hasLaw`, +`drift_se_endpoint_var`). + +## Scope + +Not proved here: the sequential-test delay `ln(1/α)/D` itself (only `D` is formalised); the +identification of the stated `∫ llr` with Mathlib's `InformationTheory.klDiv` (it needs absolute +continuity and integrability of `llr`, `InformationTheory.toReal_klDiv`); the exact constant +`√(2/n)·Γ((n+1)/2)/Γ(n/2)` of the square-root bias for `n ≥ 2` (the `n = 1` value is +`integral_abs_gaussianReal`); and noise-robust estimators such as two-scale realised variance. +The drift statements here take a single `B_T ∼ N(0, T)` and the endpoint estimator +`(μT + σB_T)/T` as given, so `n` does not appear in them; that the `n`-sample estimator of a +pre-Brownian motion with drift, on an equally spaced grid, reduces to this endpoint form is +`hasLaw_fracDiff_one_driftEstimator` in `Choice/Performance/FracDiffWeights.lean`. + +## Main results + +* `kl_gaussianReal_var_ratio`: the integral of the log-likelihood ratio `llr` of `N(0, r·v)` against + `N(0, v)`, taken under `N(0, r·v)`, is `(r − 1 − ln r) / 2`, for `v ≠ 0` and `r ≠ 0`. +* `abs_klVarRatio_sub_sq_le`: for `|r − 1| ≤ 1/2`, `(r − 1 − ln r)/2` differs from + `(r − 1)²/4` by at most `|r − 1|³`. +* `integral_sum_sq_noisy_increments`: with increments of second moment `σ²·Δt` observed through + mean-zero noise of second moment `η²` (independence hypotheses as stated), the noisy realised + sum of squares has expectation `σ²T + 2nη²`, where `T = n·Δt`. +* `sqrtBias_oneSided`: for a nonnegative, integrable, nondegenerate `Y` with `E[Y] = σ²` and + `σ > 0`, `E[√Y] < σ`. +* `sqrtBias_absGaussianSample`, `integral_abs_gaussianReal`: for `Z ∼ N(0, v)` with `v ≠ 0`, + `E|Z| < √v`; and `E|Z| = √(2v/π)`. +* `drift_se_endpoint_hasLaw`, `drift_se_endpoint_var`: for `X_t = μt + σB_t` with `B_T ∼ N(0, T)`, + the endpoint estimator `(X_T − X_0)/T` has law `N(μ, σ²/T)` and variance `σ²/T`. + +## References + +* [T. M. Cover and J. A. Thomas, *Elements of Information Theory*][CoverThomas2006]. +* [L. Zhang, P. A. Mykland and Y. Aït-Sahalia, *A tale of two time scales: determining + integrated volatility with noisy high-frequency data*][ZhangMyklandAitSahalia2005]. +* [A. Wald, *Sequential Analysis*][Wald1947]. +* [N. L. Johnson, S. Kotz and N. Balakrishnan, *Continuous Univariate Distributions, + Vol.~1*][JohnsonKotzBalakrishnan1994], ch. 13 + +## Tags + +Kullback–Leibler divergence, realised volatility, microstructure noise, variance ratio, +estimator bias, MSC 62F10, MSC 62P05, JEL C58 +-/ + +@[expose] public section + +open MeasureTheory ProbabilityTheory Real + +open scoped ENNReal NNReal + +namespace MathFin + +/-! ## The D-term: KL divergence between variance-ratio Gaussians -/ + +section KL + +/-- Pointwise identity: the log of the pdf ratio between `N(0, r·v)` and `N(0, v)` is +the quadratic `−½·ln r + x²(r−1)/(2rv)` (completing-the-square algebra, the +one-observation form of the D-term). -/ +lemma log_ratio_gaussianPDFReal_eq {r v : ℝ≥0} (hv : v ≠ 0) (hr : r ≠ 0) (x : ℝ) : + Real.log (gaussianPDFReal 0 (r * v) x / gaussianPDFReal 0 v x) = + -(Real.log (r : ℝ)) / 2 + x ^ 2 * ((r : ℝ) - 1) / (2 * (r : ℝ) * (v : ℝ)) := by + have hvpc : 0 < v := hv.bot_lt + have hrpc : 0 < r := hr.bot_lt + have hposP : 0 < gaussianPDFReal 0 (r * v) x := gaussianPDFReal_pos _ _ _ (mul_ne_zero hr hv) + have hposQ : 0 < gaussianPDFReal 0 v x := gaussianPDFReal_pos _ _ _ hv + have h2piv : (0 : ℝ) < 2 * π * v := mul_pos two_pi_pos (NNReal.coe_pos.mpr hvpc) + have h2pirv : (0 : ℝ) < 2 * π * ((r : ℝ) * (v : ℝ)) := + mul_pos two_pi_pos (mul_pos (NNReal.coe_pos.mpr hrpc) (NNReal.coe_pos.mpr hvpc)) + have hrvcoe : ((r * v : ℝ≥0) : ℝ) = (r : ℝ) * (v : ℝ) := by push_cast; ring + have hlr : Real.log (2 * π * (v : ℝ)) - Real.log (2 * π * ((r : ℝ) * (v : ℝ))) = + -(Real.log (r : ℝ)) := by + rw [← Real.log_div h2piv.ne' h2pirv.ne', + show (2 * π * (v : ℝ)) / (2 * π * ((r : ℝ) * (v : ℝ))) = ((r : ℝ))⁻¹ by field_simp, + Real.log_inv] + have hA : Real.log (gaussianPDFReal 0 (r * v) x) + = -(Real.log (2 * π * ((r : ℝ) * (v : ℝ)))) / 2 + - x ^ 2 / (2 * ((r : ℝ) * (v : ℝ))) := by + change Real.log ((Real.sqrt (2 * π * ((r * v : ℝ≥0) : ℝ)))⁻¹ * + Real.exp (-(x - 0) ^ 2 / (2 * ((r * v : ℝ≥0) : ℝ)))) = _ + rw [sub_zero, hrvcoe] + rw [Real.log_mul (by positivity : + (0 : ℝ) < (Real.sqrt (2 * π * ((r : ℝ) * (v : ℝ))))⁻¹).ne' (Real.exp_pos _).ne', + Real.log_inv, Real.log_exp, + Real.log_sqrt (by positivity : (0 : ℝ) ≤ 2 * π * ((r : ℝ) * (v : ℝ)))] + ring + have hB : Real.log (gaussianPDFReal 0 v x) + = -(Real.log (2 * π * (v : ℝ))) / 2 - x ^ 2 / (2 * (v : ℝ)) := by + change Real.log ((Real.sqrt (2 * π * (v : ℝ≥0) : ℝ))⁻¹ * + Real.exp (-(x - 0) ^ 2 / (2 * (v : ℝ≥0) : ℝ))) = _ + rw [sub_zero] + rw [Real.log_mul (by positivity : (0 : ℝ) < (Real.sqrt (2 * π * (v : ℝ)))⁻¹).ne' + (Real.exp_pos _).ne', Real.log_inv, Real.log_exp, + Real.log_sqrt (by positivity : (0 : ℝ) ≤ 2 * π * (v : ℝ))] + ring + calc Real.log (gaussianPDFReal 0 (r * v) x / gaussianPDFReal 0 v x) + = Real.log (gaussianPDFReal 0 (r * v) x) - Real.log (gaussianPDFReal 0 v x) := + Real.log_div hposP.ne' hposQ.ne' + _ = (Real.log (2 * π * (v : ℝ)) - Real.log (2 * π * ((r : ℝ) * (v : ℝ)))) / 2 + + (x ^ 2 / (2 * (v : ℝ)) - x ^ 2 / (2 * ((r : ℝ) * (v : ℝ)))) := by + rw [hA, hB]; ring + _ = -(Real.log (r : ℝ)) / 2 + + (x ^ 2 / (2 * (v : ℝ)) - x ^ 2 / (2 * ((r : ℝ) * (v : ℝ)))) := by rw [hlr] + _ = -(Real.log (r : ℝ)) / 2 + x ^ 2 * ((r : ℝ) - 1) / (2 * (r : ℝ) * (v : ℝ)) := by + have hx1 : x ^ 2 / (2 * (v : ℝ)) - x ^ 2 / (2 * ((r : ℝ) * (v : ℝ))) + = x ^ 2 * ((r : ℝ) - 1) / (2 * (r : ℝ) * (v : ℝ)) := by + field_simp + rw [hx1] + +/-- **The D-term.** `KL(N(0, r·v) ‖ N(0, v))` — the integral of the log +likelihood ratio `llr` against `N(0, r·v)` (the high-variance law when `r > 1`) — is +`½(r − 1 − ln r)`, the denominator of Wald's sequential-test delay `≈ ln(1/α)/D` +observations (the delay itself is not proved here). +The proof writes both laws in `withDensity` form, computes the RN derivative as the +pdf ratio via `Measure.rnDeriv_withDensity_right` and `Measure.rnDeriv_withDensity`, +and integrates the resulting quadratic termwise with the second moment +`MathFin.integral_sq_gaussianReal`. -/ +theorem kl_gaussianReal_var_ratio {r v : ℝ≥0} (hv : v ≠ 0) (hr : r ≠ 0) : + ∫ x, llr (gaussianReal 0 (r * v)) (gaussianReal 0 v) x ∂(gaussianReal 0 (r * v)) = + ((r : ℝ) - 1 - Real.log (r : ℝ)) / 2 := by + have hrv : r * v ≠ 0 := mul_ne_zero hr hv + have hP : gaussianReal 0 (r * v) = volume.withDensity (gaussianPDF 0 (r * v)) := + gaussianReal_of_var_ne_zero _ hrv + have hQ : gaussianReal 0 v = volume.withDensity (gaussianPDF 0 v) := + gaussianReal_of_var_ne_zero _ hv + -- the RN derivative of P against volume is the pdf: + have hrnvol : (volume.withDensity (gaussianPDF 0 (r * v))).rnDeriv volume + =ᵐ[volume] gaussianPDF 0 (r * v) := + Measure.rnDeriv_withDensity volume (measurable_gaussianPDF _ _) + -- hence the RN derivative of P against Q is the pdf ratio, a.e. volume: + have hrn := Measure.rnDeriv_withDensity_right (μ := gaussianReal 0 (r * v)) (ν := volume) + (f := gaussianPDF 0 v) (measurable_gaussianPDF _ _).aemeasurable + (ae_of_all volume fun x ↦ by + simp only [gaussianPDF, ne_eq, ENNReal.ofReal_eq_zero, not_le] + exact gaussianPDFReal_pos _ _ x hv) + (ae_of_all volume fun x ↦ ENNReal.ofReal_ne_top) + rw [← hQ, hP] at hrn + have hcomb : (volume.withDensity (gaussianPDF 0 (r * v))).rnDeriv (gaussianReal 0 v) + =ᵐ[volume] fun x ↦ (gaussianPDF 0 v x)⁻¹ * gaussianPDF 0 (r * v) x := by + filter_upwards [hrn, hrnvol] with x h1 h2 + rw [h2] at h1 + exact h1 + have hreal : ∀ x : ℝ, (gaussianPDF 0 v x)⁻¹ * gaussianPDF 0 (r * v) x + = ENNReal.ofReal (gaussianPDFReal 0 (r * v) x / gaussianPDFReal 0 v x) := by + intro x + calc (gaussianPDF 0 v x)⁻¹ * gaussianPDF 0 (r * v) x + = (ENNReal.ofReal (gaussianPDFReal 0 v x))⁻¹ * + ENNReal.ofReal (gaussianPDFReal 0 (r * v) x) := by rw [gaussianPDF, gaussianPDF] + _ = ENNReal.ofReal (gaussianPDFReal 0 v x)⁻¹ * + ENNReal.ofReal (gaussianPDFReal 0 (r * v) x) := by + rw [ENNReal.ofReal_inv_of_pos (gaussianPDFReal_pos _ _ x hv)] + _ = ENNReal.ofReal ((gaussianPDFReal 0 v x)⁻¹ * gaussianPDFReal 0 (r * v) x) := by + rw [ENNReal.ofReal_mul (inv_nonneg.2 (gaussianPDFReal_nonneg _ _ x))] + _ = ENNReal.ofReal (gaussianPDFReal 0 (r * v) x / gaussianPDFReal 0 v x) := by + rw [div_eq_inv_mul] + -- the llr integrand is the log pdf ratio, a.e. volume, hence a.e. P: + have hllr : llr (gaussianReal 0 (r * v)) (gaussianReal 0 v) + =ᵐ[volume] fun x ↦ Real.log (gaussianPDFReal 0 (r * v) x / gaussianPDFReal 0 v x) := by + filter_upwards [hcomb] with x hx + change Real.log (((gaussianReal 0 (r * v)).rnDeriv (gaussianReal 0 v) x).toReal) = _ + rw [hP, hx, hreal x, + ENNReal.toReal_ofReal + (div_nonneg (gaussianPDFReal_nonneg _ _ x) (gaussianPDFReal_nonneg _ _ x))] + have hPac : gaussianReal 0 (r * v) ≪ volume := gaussianReal_absolutelyContinuous _ hrv + have hllr' : llr (gaussianReal 0 (r * v)) (gaussianReal 0 v) + =ᵐ[gaussianReal 0 (r * v)] fun x ↦ + -(Real.log (r : ℝ)) / 2 + x ^ 2 * ((r : ℝ) - 1) / (2 * (r : ℝ) * (v : ℝ)) := by + filter_upwards [hPac.ae_le hllr] with x hx + rw [hx, log_ratio_gaussianPDFReal_eq hv hr] + rw [integral_congr_ae hllr'] + have hsplit : ∫ x : ℝ, -(Real.log (r : ℝ)) / 2 + x ^ 2 * ((r : ℝ) - 1) / (2 * (r : ℝ) * (v : ℝ)) + ∂(gaussianReal 0 (r * v)) + = -(Real.log (r : ℝ)) / 2 + + (∫ x : ℝ, x ^ 2 ∂(gaussianReal 0 (r * v))) + * (((r : ℝ) - 1) / (2 * (r : ℝ) * (v : ℝ))) := by + have h0 : Integrable (fun x : ℝ ↦ x ^ 2) (gaussianReal 0 (r * v)) := + (memLp_id_gaussianReal 2).integrable_sq + have hint1 : Integrable (fun _ : ℝ ↦ -(Real.log (r : ℝ)) / 2) (gaussianReal 0 (r * v)) := + integrable_const _ + have hshape : ∀ x : ℝ, -(Real.log (r : ℝ)) / 2 + x ^ 2 * ((r : ℝ) - 1) / (2 * (r : ℝ) * (v : ℝ)) + = -(Real.log (r : ℝ)) / 2 + x ^ 2 * (((r : ℝ) - 1) / (2 * (r : ℝ) * (v : ℝ))) := + fun _ ↦ by ring + rw [integral_congr_ae (ae_of_all _ hshape), + integral_add hint1 (h0.mul_const _), + integral_const, integral_mul_const, probReal_univ, one_smul] + rw [hsplit, MathFin.integral_sq_gaussianReal] + push_cast + field_simp + ring + +/-- **The small-shift quadratic (to leading order, halving the gap between the regimes quarters +the information).** Near `r = 1` the value `D(r) = (r − 1 − ln r)/2` of +`kl_gaussianReal_var_ratio` is `(r−1)²/4` up to a cubic remainder: +`|D(r) − (r−1)²/4| ≤ |r−1|³` whenever `|r − 1| ≤ ½`. The statement is about this real +function; it does not mention the Gaussian laws. So the discrimination information vanishes +quadratically as the two regimes coalesce, and a delay `≈ ln(1/α)/D` would grow like +`1/(r−1)²`. From the second-order log-series bound +`Real.abs_log_sub_add_sum_range_le` at `x = 1 − r`. -/ +theorem abs_klVarRatio_sub_sq_le {r : ℝ} (hr : |r - 1| ≤ 1 / 2) : + |(r - 1 - Real.log r) / 2 - (r - 1) ^ 2 / 4| ≤ |r - 1| ^ 3 := by + have h := abs_log_sub_add_sum_range_le (x := 1 - r) (by rw [abs_sub_comm]; linarith) 2 + rw [sub_sub_cancel, abs_sub_comm] at h + have hsum : ∑ i ∈ Finset.range 2, (1 - r) ^ (i + 1) / (i + 1) = (1 - r) + (1 - r) ^ 2 / 2 := by + norm_num [Finset.sum_range_succ] + rw [hsum] at h + have hb : |r - 1| ^ 3 / (1 - |r - 1|) ≤ 2 * |r - 1| ^ 3 := by + rw [div_le_iff₀ (by linarith)] + nlinarith [mul_nonneg (pow_nonneg (abs_nonneg (r - 1)) 3) + (by linarith : (0 : ℝ) ≤ 1 / 2 - |r - 1|)] + rw [show (r - 1 - Real.log r) / 2 - (r - 1) ^ 2 / 4 + = -((1 - r) + (1 - r) ^ 2 / 2 + Real.log r) / 2 by ring, abs_div, abs_neg, abs_two] + linarith + +end KL + +/-! ## Realised variance under mean-zero noise -/ + +section RealizedVol + +variable {α : Type*} [MeasurableSpace α] {μ : Measure α} + +/-- **The realised-variance noise bias is linear in sampling frequency** (Zhang, Mykland and +Aït-Sahalia 2005). Over `n` increments `ΔX_i` with second moment `E[(ΔX_i)²] = σ²·Δt` (the +`MathFin.integral_sq_gaussianReal` moment in the Gaussian instance) +observed through mean-zero noise `ε_j` of scale `η` (`E[ε_j] = 0`, `E[ε_j²] = η²`), so that +the observed price is `Y = X + ε` and the observed increment is +`ΔY_i = ΔX_i + (ε_{i+1} − ε_i)`, the noisy realised sum has expectation `σ²T + 2nη²` +where `T = n·Δt`: each increment contributes its signal second moment plus **two** noise +second moments, and all cross-terms vanish by independence + mean-zero +(`IndepFun.integral_mul_eq_mul_integral`). Only the independences the cross-terms use are +assumed — each increment against its two noise draws, and adjacent noise draws pairwise — so +iid noise independent of the signal is a special case. No probability hypothesis on `μ` is +needed; the integrability hypotheses are kept explicit. -/ +theorem integral_sum_sq_noisy_increments {n : ℕ} {dt T sigma eta : ℝ} (hT : T = (n : ℝ) * dt) + (dX : ℕ → α → ℝ) (e : ℕ → α → ℝ) + (hdXi : ∀ i ∈ Finset.range n, Integrable (dX i) μ) + (hei : ∀ j ∈ Finset.range (n + 1), Integrable (e j) μ) + (hdXsq : ∀ i ∈ Finset.range n, Integrable (fun x ↦ dX i x * dX i x) μ) + (hesq : ∀ j ∈ Finset.range (n + 1), Integrable (fun x ↦ e j x * e j x) μ) + (h_mom : ∀ i ∈ Finset.range n, ∫ x, dX i x * dX i x ∂μ = sigma * sigma * dt) + (h_noise_sq : ∀ j ∈ Finset.range (n + 1), ∫ x, e j x * e j x ∂μ = eta * eta) + (h_noise_mean : ∀ j ∈ Finset.range (n + 1), ∫ x, e j x ∂μ = 0) + (h_noise_indep : ∀ i ∈ Finset.range n, e i ⟂ᵢ[μ] e (i + 1)) + (h_cross : ∀ i ∈ Finset.range n, dX i ⟂ᵢ[μ] e i ∧ dX i ⟂ᵢ[μ] e (i + 1)) : + ∫ x, ∑ i ∈ Finset.range n, (dX i x + (e (i + 1) x - e i x)) ^ 2 ∂μ + = sigma * sigma * T + 2 * (n : ℝ) * eta * eta := by + have hexp : ∀ (i : ℕ) (x : α), (dX i x + (e (i + 1) x - e i x)) ^ 2 = + dX i x * dX i x + e i x * e i x + e (i + 1) x * e (i + 1) x + + 2 * (dX i x * e (i + 1) x) - 2 * (dX i x * e i x) + - 2 * (e i x * e (i + 1) x) := + fun _ _ ↦ by ring + have key : ∀ i ∈ Finset.range n, + (∫ x : α, (dX i x + (e (i + 1) x - e i x)) ^ 2 ∂μ = sigma * sigma * dt + 2 * eta * eta) + ∧ Integrable (fun x : α ↦ (dX i x + (e (i + 1) x - e i x)) ^ 2) μ := by + intro i hi + have h0 : i ∈ Finset.range (n + 1) := by simp at hi ⊢; omega + have h1 : i + 1 ∈ Finset.range (n + 1) := by simp at hi ⊢; omega + -- the six integrable pieces + have i1 : Integrable (fun x : α ↦ dX i x * dX i x) μ := hdXsq i hi + have i2 : Integrable (fun x : α ↦ e i x * e i x) μ := hesq i h0 + have i3 : Integrable (fun x : α ↦ e (i + 1) x * e (i + 1) x) μ := hesq (i + 1) h1 + have c1 : Integrable (fun x : α ↦ dX i x * e i x) μ := + (h_cross i hi).1.integrable_mul (hdXi i hi) (hei i h0) + have c2 : Integrable (fun x : α ↦ dX i x * e (i + 1) x) μ := + (h_cross i hi).2.integrable_mul (hdXi i hi) (hei (i + 1) h1) + have c3 : Integrable (fun x : α ↦ e i x * e (i + 1) x) μ := + (h_noise_indep i hi).integrable_mul (hei i h0) (hei (i + 1) h1) + have c1' : Integrable (fun x : α ↦ 2 * (dX i x * e i x)) μ := c1.const_mul 2 + have c2' : Integrable (fun x : α ↦ 2 * (dX i x * e (i + 1) x)) μ := c2.const_mul 2 + have c3' : Integrable (fun x : α ↦ 2 * (e i x * e (i + 1) x)) μ := c3.const_mul 2 + have i12 : Integrable (fun x : α ↦ dX i x * dX i x + e i x * e i x) μ := i1.add i2 + have i123 : Integrable + (fun x : α ↦ dX i x * dX i x + e i x * e i x + e (i + 1) x * e (i + 1) x) μ := + i12.add i3 + have i1234 : Integrable + (fun x : α ↦ dX i x * dX i x + e i x * e i x + e (i + 1) x * e (i + 1) x + + 2 * (dX i x * e (i + 1) x)) μ := i123.add c2' + have i12345 : Integrable + (fun x : α ↦ dX i x * dX i x + e i x * e i x + e (i + 1) x * e (i + 1) x + + 2 * (dX i x * e (i + 1) x) - 2 * (dX i x * e i x)) μ := i1234.sub c1' + have p6 : Integrable + (fun x : α ↦ dX i x * dX i x + e i x * e i x + e (i + 1) x * e (i + 1) x + + 2 * (dX i x * e (i + 1) x) - 2 * (dX i x * e i x) + - 2 * (e i x * e (i + 1) x)) μ := i12345.sub c3' + refine ⟨?_, p6.congr (ae_of_all μ fun x ↦ (hexp i x).symm)⟩ + rw [integral_congr_ae (ae_of_all μ fun x ↦ hexp i x)] + -- split into the six integrals; each cross-term factors and vanishes + have z1 : ∫ x : α, dX i x * e i x ∂μ = (∫ x, dX i x ∂μ) * (∫ x, e i x ∂μ) := + (h_cross i hi).1.integral_mul_eq_mul_integral (hdXi i hi).1 (hei i h0).1 + have z2 : ∫ x : α, dX i x * e (i + 1) x ∂μ + = (∫ x, dX i x ∂μ) * (∫ x, e (i + 1) x ∂μ) := + (h_cross i hi).2.integral_mul_eq_mul_integral (hdXi i hi).1 (hei (i + 1) h1).1 + have z3 : ∫ x : α, e i x * e (i + 1) x ∂μ + = (∫ x, e i x ∂μ) * (∫ x, e (i + 1) x ∂μ) := + (h_noise_indep i hi).integral_mul_eq_mul_integral (hei i h0).1 (hei (i + 1) h1).1 + rw [integral_sub i12345 c3', integral_sub i1234 c1', integral_add i123 c2', + integral_add i12 i3, integral_add i1 i2, + h_mom i hi, h_noise_sq i h0, h_noise_sq (i + 1) h1, + integral_const_mul, z2, h_noise_mean (i + 1) h1, mul_zero, + integral_const_mul, z1, h_noise_mean i h0, mul_zero, + integral_const_mul, z3, h_noise_mean i h0, h_noise_mean (i + 1) h1, mul_zero, mul_zero] + ring + calc ∫ x, ∑ i ∈ Finset.range n, (dX i x + (e (i + 1) x - e i x)) ^ 2 ∂μ + = ∑ i ∈ Finset.range n, ∫ x : α, (dX i x + (e (i + 1) x - e i x)) ^ 2 ∂μ := + integral_finsetSum (Finset.range n) fun i hi ↦ (key i hi).2 + _ = ∑ i ∈ Finset.range n, (sigma * sigma * dt + 2 * eta * eta) := + Finset.sum_congr rfl fun i hi ↦ (key i hi).1 + _ = sigma * sigma * T + 2 * (n : ℝ) * eta * eta := by + rw [hT, Finset.sum_const, Finset.card_range] + ring + +end RealizedVol + +/-! ## The square-root estimator is biased low -/ + +section SqrtBias + +variable {α : Type*} [MeasurableSpace α] {μ : Measure α} [IsProbabilityMeasure μ] + +/-- **The sign of the square-root bias: `E[σ̂] < σ`.** If `Y ≥ 0` is a nondegenerate target with +`E[Y] = σ²` (the sample reading: `Y = RV/T`, the noise-free annualised realised variance +whose square root is the volatility estimator `σ̂ = √Y`), then `E[√Y] < σ` — the +square-root estimator of a nondegenerate volatility is **biased low**. Strictness comes +from the tangent-line identity at `σ²`: `√y = (y + σ²)/(2σ) − (√y − σ)²/(2σ)`, whose +remainder is strictly positive on `{Y ≠ σ²}`, a set of positive measure by nondegeneracy. +The exact Gaussian constant `√(2/n)·Γ((n+1)/2)/Γ(n/2)` of the bias is not formalized here +for `n ≥ 2`; for `n = 1` it is `integral_abs_gaussianReal`. -/ +theorem sqrtBias_oneSided {Y : α → ℝ} (hYnn : ∀ ω, 0 ≤ Y ω) + {sigma : ℝ} (hsig : 0 < sigma) (hint : Integrable Y μ) + (hmean : ∫ ω, Y ω ∂μ = sigma * sigma) (hnd : μ {ω | Y ω ≠ sigma * sigma} ≠ 0) : + ∫ ω, Real.sqrt (Y ω) ∂μ < sigma := by + have hsqrtsig : Real.sqrt (sigma * sigma) = sigma := Real.sqrt_mul_self (le_of_lt hsig) + set c : ℝ := (2 * Real.sqrt (sigma * sigma))⁻¹ with hc + have hcpos : 0 < c := by positivity + -- the tangent identity: √Y = (Y + σ²)/(2σ) − (√Y − σ)²/(2σ), with c = 1/(2σ) + have hid : ∀ ω : α, Real.sqrt (Y ω) = + c * Y ω + c * (sigma * sigma) + - c * (Real.sqrt (Y ω) - Real.sqrt (sigma * sigma)) ^ 2 := by + intro ω + have e1 : (Real.sqrt (Y ω)) ^ 2 = Y ω := Real.sq_sqrt (hYnn ω) + have e2 : (Real.sqrt (sigma * sigma)) ^ 2 = sigma * sigma := Real.sq_sqrt (by positivity) + have hkey : (Real.sqrt (Y ω) - Real.sqrt (sigma * sigma)) ^ 2 + = Y ω + sigma * sigma - 2 * Real.sqrt (Y ω) * Real.sqrt (sigma * sigma) := by + rw [sub_sq, e1, e2] + ring + rw [hkey, hc] + field_simp + ring + -- integrability of the two pieces + have hintP : Integrable (fun ω ↦ c * Y ω + c * (sigma * sigma)) μ := by + have h := (hint.mul_const c).add (integrable_const (c * (sigma * sigma))) + refine h.congr (ae_of_all μ fun ω ↦ ?_) + simp only [Pi.add_apply] + ring + have hkey2 : ∀ ω : α, (Real.sqrt (Y ω) - Real.sqrt (sigma * sigma)) ^ 2 + ≤ 2 * Y ω + 2 * (sigma * sigma) := by + intro ω + have e1 : (Real.sqrt (Y ω)) ^ 2 = Y ω := Real.sq_sqrt (hYnn ω) + have e2 : (Real.sqrt (sigma * sigma)) ^ 2 = sigma * sigma := Real.sq_sqrt (by positivity) + nlinarith [sq_nonneg (Real.sqrt (Y ω) + Real.sqrt (sigma * sigma)), e1, e2] + have hintD : Integrable (fun ω ↦ 2 * c * Y ω + 2 * c * (sigma * sigma)) μ := by + have h := (hint.mul_const (2 * c)).add (integrable_const (2 * c * (sigma * sigma))) + refine h.congr (ae_of_all μ fun ω ↦ ?_) + simp only [Pi.add_apply] + ring + have hintg : Integrable (fun ω ↦ c * (Real.sqrt (Y ω) - Real.sqrt (sigma * sigma)) ^ 2) μ := by + refine Integrable.mono hintD ?_ ?_ + · have := hint.1 + fun_prop + · filter_upwards [] with ω + change |c * (Real.sqrt (Y ω) - Real.sqrt (sigma * sigma)) ^ 2| + ≤ |2 * c * Y ω + 2 * c * (sigma * sigma)| + rw [abs_of_nonneg (mul_nonneg (le_of_lt hcpos) (sq_nonneg _)), + abs_of_nonneg (by nlinarith [hcpos, hYnn ω, sq_nonneg (sigma * sigma)])] + calc c * (Real.sqrt (Y ω) - Real.sqrt (sigma * sigma)) ^ 2 + ≤ c * (2 * Y ω + 2 * (sigma * sigma)) := + mul_le_mul_of_nonneg_left (hkey2 ω) (le_of_lt hcpos) + _ = 2 * c * Y ω + 2 * c * (sigma * sigma) := by ring + -- the constant piece integrates to σ = √(σ²) + have hPint : ∫ ω, c * Y ω + c * (sigma * sigma) ∂μ + = Real.sqrt (sigma * sigma) := by + have h1 : Integrable (fun ω : α ↦ c * Y ω) μ := + (hint.mul_const c).congr (ae_of_all μ fun ω ↦ mul_comm _ _) + have hconst : ∫ ω : α, c * (sigma * sigma) ∂μ = c * (sigma * sigma) := by + have h := integral_const (c * (sigma * sigma)) (μ := μ) + rw [h] + simp + rw [integral_add h1 (integrable_const _), + show (fun ω : α ↦ c * Y ω) = fun ω ↦ Y ω * c from funext fun _ ↦ mul_comm _ _, + integral_mul_const c (fun ω ↦ Y ω), hmean, hconst, hc] + field_simp + rw [Real.sq_sqrt (by positivity : (0 : ℝ) ≤ sigma ^ 2)] + ring + -- the remainder has strictly positive integral on the nondegeneracy set + have hintgpos : 0 < ∫ ω, c * (Real.sqrt (Y ω) - Real.sqrt (sigma * sigma)) ^ 2 ∂μ := by + rw [integral_pos_iff_support_of_nonneg_ae + (ae_of_all μ fun ω ↦ mul_nonneg hcpos.le (sq_nonneg _)) hintg, pos_iff_ne_zero] + intro hzero + refine hnd (measure_mono_null (fun ω hω ↦ ?_) hzero) + have hsne : Real.sqrt (Y ω) ≠ Real.sqrt (sigma * sigma) := fun heq ↦ hω (by + rw [← Real.sq_sqrt (hYnn ω), ← Real.sq_sqrt (by positivity : (0 : ℝ) ≤ sigma * sigma), heq]) + exact (mul_pos hcpos (sq_pos_iff.mpr (sub_ne_zero.mpr hsne))).ne' + rw [integral_congr_ae (ae_of_all μ hid), integral_sub hintP hintg, hPint] + linarith [hintgpos, hsqrtsig] + +/-- **The Gaussian sample instance: `E[|Z|] < σ` for `Z ~ N(0, σ²)`.** The single-sample +(`n = 1`) realised-volatility estimator is `σ̂ = |Z| = √(Z²)`, whose target +`Y = Z²` is nondegenerate (`P(Z² = σ²) = 0` — a nondegenerate Gaussian has no atoms, +`NullSingletonClass`) — so `sqrtBias_oneSided` applies. The exact value +`E|Z| = σ√(2/π) ≈ 0.798σ` is `integral_abs_gaussianReal`. -/ +theorem sqrtBias_absGaussianSample {v : ℝ≥0} (hv : v ≠ 0) : + ∫ x, |x| ∂(gaussianReal 0 v) < Real.sqrt (v : ℝ) := by + have hvpc : 0 < v := hv.bot_lt + have hvpos : (0 : ℝ) < v := NNReal.coe_pos.mpr hvpc + have : NullSingletonClass (gaussianReal 0 v) := nullSingletonClass_gaussianReal hv + have hsqrtpos : (0 : ℝ) < Real.sqrt v := Real.sqrt_pos.2 hvpos + have hsqrtsq : Real.sqrt (v : ℝ) * Real.sqrt (v : ℝ) = (v : ℝ) := + Real.mul_self_sqrt (le_of_lt hvpos) + have habs : ∀ x : ℝ, |x| = Real.sqrt (x ^ 2) := fun x ↦ (Real.sqrt_sq_eq_abs x).symm + -- nondegeneracy: P(Z² = σ²) = 0 since the set is a union of two singletons + have hsetzero : (gaussianReal 0 v) {x : ℝ | x ^ 2 = Real.sqrt (v : ℝ) * Real.sqrt (v : ℝ)} + = 0 := by + have hsub : {x : ℝ | x ^ 2 = Real.sqrt (v : ℝ) * Real.sqrt (v : ℝ)} + ⊆ {Real.sqrt (v : ℝ)} ∪ {-Real.sqrt (v : ℝ)} := by + intro x hx + have habsx : |x| = Real.sqrt (v : ℝ) := by + rw [habs x, hx, ← sq, Real.sqrt_sq (by positivity)] + by_cases hx0 : 0 ≤ x + · exact Or.inl (by rw [abs_of_nonneg hx0] at habsx; exact habsx) + · refine Or.inr ?_ + have hxneg : -x = Real.sqrt (v : ℝ) := by + rw [← abs_of_neg (not_le.mp hx0)] + exact habsx + change x = -Real.sqrt (v : ℝ) + linarith + refine measure_mono_null hsub ?_ + rw [measure_union_null (measure_singleton _) (measure_singleton _)] + have hnd : (gaussianReal 0 v) + {x : ℝ | x ^ 2 ≠ Real.sqrt (v : ℝ) * Real.sqrt (v : ℝ)} ≠ 0 := by + have hmeas : MeasurableSet {x : ℝ | x ^ 2 = Real.sqrt (v : ℝ) * Real.sqrt (v : ℝ)} := by + change MeasurableSet ((fun x : ℝ ↦ x ^ 2) ⁻¹' {Real.sqrt (v : ℝ) * Real.sqrt (v : ℝ)}) + exact MeasurableSet.preimage (measurableSet_singleton _) (by fun_prop) + have hcompl : {x : ℝ | x ^ 2 ≠ Real.sqrt (v : ℝ) * Real.sqrt (v : ℝ)} + = {x : ℝ | x ^ 2 = Real.sqrt (v : ℝ) * Real.sqrt (v : ℝ)}ᶜ := by + ext x + simp [ne_eq] + rw [hcompl, measure_compl hmeas (measure_ne_top _ _), hsetzero, measure_univ] + simp + have hmain := sqrtBias_oneSided (μ := gaussianReal 0 v) (Y := fun x : ℝ ↦ x ^ 2) + (sigma := Real.sqrt (v : ℝ)) (fun _ ↦ sq_nonneg _) hsqrtpos + (memLp_id_gaussianReal 2).integrable_sq + (by rw [MathFin.integral_sq_gaussianReal v]; exact hsqrtsq.symm) hnd + rw [show (fun x : ℝ ↦ |x|) = fun x : ℝ ↦ Real.sqrt (x ^ 2) from funext habs] + exact hmain + +/-- **Mean absolute value of a centred Gaussian: `E|Z| = √(2v/π)` for `Z ∼ N(0, v)`.** The +one-sample volatility estimator `|Z|` therefore underestimates `σ = √v` by the exact factor +`√(2/π) ≈ 0.798` (compare `sqrtBias_absGaussianSample`). For `v = 1`, `|x|ϕ(x)` is the even +function `y ↦ yϕ(y)` of `|x|`, so `E|Z| = 2∫₀^∞ zϕ(z) dz = 2ϕ(0)` by the truncated first +moment `integral_id_mul_gaussianPDFReal_Ioi`; a general `v` is the image of `N(0, 1)` under +`x ↦ √v·x` (`gaussianReal_map_const_mul`). -/ +theorem integral_abs_gaussianReal (v : ℝ≥0) : + ∫ x, |x| ∂(gaussianReal 0 v) = √(2 * v / π) := by + have hφ (x : ℝ) : gaussianPDFReal 0 1 |x| = gaussianPDFReal 0 1 x := by + simp [gaussianPDFReal, sq_abs] + have hstd : ∫ x, |x| ∂(gaussianReal 0 1) = 2 * (√(2 * π))⁻¹ := by + calc ∫ x, |x| ∂(gaussianReal 0 1) + = ∫ x, |x| * gaussianPDFReal 0 1 |x| := by + rw [integral_gaussianReal_eq_integral_smul one_ne_zero] + congr 1 with x + rw [hφ, smul_eq_mul, mul_comm] + _ = 2 * ∫ x in Set.Ioi 0, x * gaussianPDFReal 0 1 x := + integral_comp_abs (f := fun y ↦ y * gaussianPDFReal 0 1 y) + _ = 2 * (√(2 * π))⁻¹ := by + rw [integral_id_mul_gaussianPDFReal_Ioi] + simp [gaussianPDFReal] + have hmap : gaussianReal 0 v = (gaussianReal 0 1).map (√(v : ℝ) * ·) := by + rw [gaussianReal_map_const_mul, mul_zero, mul_one] + congr 1 + ext + exact (Real.sq_sqrt (NNReal.coe_nonneg v)).symm + rw [hmap, integral_map (continuous_const_mul _).aemeasurable continuous_abs.aestronglyMeasurable] + simp_rw [abs_mul, abs_of_nonneg (Real.sqrt_nonneg _)] + rw [integral_const_mul, hstd, eq_comm, + Real.sqrt_eq_iff_mul_self_eq (by positivity) (by positivity)] + have h : √(v : ℝ) * (2 * (√(2 * π))⁻¹) * (√(v : ℝ) * (2 * (√(2 * π))⁻¹)) = + (√(v : ℝ) * √(v : ℝ)) * 4 * (√(2 * π) * √(2 * π))⁻¹ := by ring + rw [h, Real.mul_self_sqrt (NNReal.coe_nonneg v), Real.mul_self_sqrt (by positivity)] + field_simp + ring + +end SqrtBias + +/-! ## The drift estimator sees only the endpoints -/ + +section DriftSE + +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + +/-- **The endpoint drift estimator (its law).** For `X_t = μt + σB_t` with `B_T ~ N(0, T)`, +the endpoint drift estimator `(X_T − X_0)/T = μ + (σ/T)·B_T` has law `N(μ, σ²/T)` — an +affine pushforward of the gaussianReal sample (`gaussianReal_const_mul` then +`gaussianReal_const_add`). The variance slot is `σ²/T`, so the drift standard error `σ/√T` +does not depend on the number `n` of sampling points (`n` does not appear in the statement, +which takes the endpoint form as given). -/ +theorem drift_se_endpoint_hasLaw {T : ℝ} (hT : 0 < T) (mu sigma : ℝ) {B : Ω → ℝ} + (hB : HasLaw B (gaussianReal 0 T.toNNReal) P) : + HasLaw (fun ω ↦ (mu * T + sigma * B ω) / T) + (gaussianReal mu (sigma ^ 2 / T).toNNReal) P := by + have h1 := gaussianReal_const_mul hB (sigma / T) + have h2 := gaussianReal_const_add h1 mu + have hcong : (fun ω ↦ (mu * T + sigma * B ω) / T) + = (fun ω ↦ mu + sigma / T * B ω) := by + funext ω + field_simp + rw [hcong] + convert h2 using 2 + · ring + · refine NNReal.coe_injective ?_ + rw [Real.coe_toNNReal _ (by positivity), NNReal.coe_mul, NNReal.coe_mk, + Real.coe_toNNReal _ hT.le] + field_simp + +/-- **The endpoint drift estimator (its variance).** `Var[(X_T − X_0)/T] = σ²/T`: the drift +estimator's standard error is `σ/√T`, independent of the sampling frequency `n`, because the +estimator is a function of the endpoints only. Via `HasLaw.variance_eq` and +`variance_id_gaussianReal`. -/ +theorem drift_se_endpoint_var {T : ℝ} (hT : 0 < T) (mu sigma : ℝ) {B : Ω → ℝ} + (hB : HasLaw B (gaussianReal 0 T.toNNReal) P) : + Var[fun ω ↦ (mu * T + sigma * B ω) / T; P] = sigma ^ 2 / T := by + rw [(drift_se_endpoint_hasLaw hT mu sigma hB).variance_eq, variance_id_gaussianReal, + Real.coe_toNNReal _ (by positivity)] + +end DriftSE + +end MathFin diff --git a/LeanPool/MathFin/Probability/Laws/ExpMin.lean b/LeanPool/MathFin/Probability/Laws/ExpMin.lean new file mode 100644 index 0000000000..bff0cb772e --- /dev/null +++ b/LeanPool/MathFin/Probability/Laws/ExpMin.lean @@ -0,0 +1,107 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Distributions.Exponential +public import Mathlib.Probability.Independence.Basic + +/-! +# Minimum of independent exponentials (Appendix B.2) + +The minimum of independent exponentials has the `Exp(∑ rates)` **survival function**: +`μ {ω | t < min_i τ_i ω} = exp (-(∑ rates) * t)` for `t ≥ 0`, derived from joint +independence (`iIndepFun.meas_iInter`) and the individual exponential laws +(`expMeasure` CDF formula). The law identity itself — that the minimum *is* +`Exp(∑ rates)` as a measure — is not stated here. + +## Main results + +* `minimum_survival`: for jointly independent `τ i` with exponential laws of rates `rates i > 0` + and `t ≥ 0`, `μ {ω | t < min_i τ_i ω} = exp (-(∑ rates) * t)`. The law of the minimum as a + measure is not stated. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], B.2 + +## Tags + +minimum of exponentials, survival function, competing risks, first default time, +independent exponentials, MSC 60E05, MSC 91G40 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Finset + +variable {Ω : Type*} {n : ℕ} {rates : Fin n → ℝ} {τ : Fin n → Ω → ℝ} + +/-- Survival function of `expMeasure r` for `t ≥ 0`. -/ +lemma expMeasure_Ioi (r : ℝ) (hr : 0 < r) {t : ℝ} (ht : 0 ≤ t) : + expMeasure r (Set.Ioi t) = ENNReal.ofReal (Real.exp (-(r * t))) := by + have : IsProbabilityMeasure (expMeasure r) := isProbabilityMeasure_expMeasure hr + have h_compl : expMeasure r (Set.Ioi t) = 1 - expMeasure r (Set.Iic t) := by + have h_eq : (Set.Ioi t : Set ℝ) = (Set.Iic t)ᶜ := Set.compl_Iic.symm + rw [h_eq, measure_compl measurableSet_Iic (measure_ne_top _ _), measure_univ] + have h_iic : expMeasure r (Set.Iic t) = ENNReal.ofReal (cdf (expMeasure r) t) := + (ProbabilityTheory.ofReal_cdf (expMeasure r) t).symm + rw [h_compl, h_iic, cdf_expMeasure_eq hr t, ite_eq_left ht] + have hexp_le : Real.exp (-(r * t)) ≤ 1 := by + apply Real.exp_le_one_iff.mpr + have := mul_nonneg hr.le ht + linarith + have h_diff_nonneg : (0 : ℝ) ≤ 1 - Real.exp (-(r * t)) := by linarith + rw [← ENNReal.ofReal_one, ← ENNReal.ofReal_sub _ h_diff_nonneg] + congr 1 + ring + +/-- The set `{ω | t < min_i τ_i ω}` rewrites to `⋂_i {ω | t < τ_i ω}`. -/ +lemma min_gt_iInter (hn : 0 < n) (t : ℝ) : + {ω : Ω | t < (Finset.univ.inf' ⟨⟨0, hn⟩, Finset.mem_univ _⟩ + (fun i : Fin n ↦ τ i ω))} + = ⋂ i : Fin n, (τ i) ⁻¹' Set.Ioi t := by + ext ω + simp only [Set.mem_ofPred_eq, Set.mem_iInter, Set.mem_preimage, Set.mem_Ioi] + exact ⟨fun h i => h.trans_le (Finset.inf'_le _ (Finset.mem_univ i)), + fun h => (Finset.lt_inf'_iff _).2 fun i _ => h i⟩ + +variable {m0 : MeasurableSpace Ω} {μ : Measure Ω} + +/-- Appendix B.2: minimum of independent exponentials. + +For a finite family of jointly independent `Exp(rates i)` random variables `τ : Fin n → Ω → ℝ`, +the survival function of the pointwise minimum is `exp(-(∑ rates) · t)` for `t ≥ 0` — +i.e. the minimum has law `Exp(∑ rates)` (at the survival-function / CDF level). -/ +theorem minimum_survival + (hrates_pos : ∀ i, 0 < rates i) + (hexp_law : ∀ i, Measure.map (τ i) μ = expMeasure (rates i)) + (hindep : iIndepFun τ μ) + (hmeas : ∀ i, Measurable (τ i)) + (hn : 0 < n) {t : ℝ} (ht : 0 ≤ t) : + μ {ω | t < Finset.univ.inf' ⟨⟨0, hn⟩, Finset.mem_univ _⟩ + (fun i : Fin n ↦ τ i ω)} = + ENNReal.ofReal (Real.exp (-((∑ i, rates i) * t))) := by + rw [min_gt_iInter hn t] + rw [hindep.meas_iInter (fun _ ↦ ⟨Set.Ioi t, measurableSet_Ioi, rfl⟩)] + have step_each : ∀ i, μ ((τ i) ⁻¹' Set.Ioi t) + = ENNReal.ofReal (Real.exp (-(rates i * t))) := fun i ↦ by + rw [show μ ((τ i) ⁻¹' Set.Ioi t) = (Measure.map (τ i) μ) (Set.Ioi t) from + (Measure.map_apply (hmeas i) measurableSet_Ioi).symm, + hexp_law i, expMeasure_Ioi (rates i) (hrates_pos i) ht] + simp_rw [step_each] + rw [← ENNReal.ofReal_prod_of_nonneg (fun i _ ↦ (Real.exp_pos _).le)] + congr 1 + rw [← Real.exp_sum] + congr 1 + rw [Finset.sum_neg_distrib] + simp [Finset.sum_mul] + +end MathFin diff --git a/LeanPool/MathFin/Probability/Laws/ExtremeValue.lean b/LeanPool/MathFin/Probability/Laws/ExtremeValue.lean new file mode 100644 index 0000000000..22ac53cfab --- /dev/null +++ b/LeanPool/MathFin/Probability/Laws/ExtremeValue.lean @@ -0,0 +1,260 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.SpecialFunctions.Complex.LogBounds +public import Mathlib.Probability.Distributions.Exponential + +/-! +# Extreme value theory: the GEV family and maximum domains of attraction + +The maximum `Mₙ = max(X₁, …, Xₙ)` of `n` iid losses with distribution function `F` has +distribution function `Fⁿ`. Extreme value theory asks for normalizing constants `cₙ > 0`, `dₙ` +with `Fⁿ(cₙ x + dₙ) → H(x)`. The Fisher–Tippett–Gnedenko theorem says the only possible +non-degenerate limits are, up to location and scale, the **generalized extreme value** +distribution functions (McNeil–Frey–Embrechts, *Quantitative Risk Management* (2015), +Definition 5.1) + + `H_ξ(x) = exp(−(1 + ξx)^{−1/ξ})` on `1 + ξx > 0`, `H_0(x) = exp(−e^{−x})`. + +This file sets up the family and the notion of maximum domain of attraction (`InMDA`). The +Fisher–Tippett–Gnedenko theorem itself is not formalized here. + +* **The Poisson approximation.** `Fⁿ(uₙ) → e^{−τ}` if and only if `n F_bar(uₙ) → τ` (MFE + Exercise 5.23(a), `tendsto_pow_iff_tendsto_nat_mul_tail`). A maximum of `n` draws stays below + `uₙ` exactly when none of the `n` draws exceeds it, and the number of exceedances is + asymptotically Poisson with mean `n F_bar(uₙ)`. All the domain-of-attraction computations below + go through this equivalence. The `⇐` direction is Mathlib's + `Real.tendsto_one_add_pow_exp_of_tendsto`; the `⇒` direction is a squeeze of `n (1 − aₙ)` + between `n log aₙ` and `aₙ · n log aₙ`. +* **Max-stability.** For every `ξ` and `n ≥ 1`, + `H_ξ(nᶻ x + (nᶻ − 1)/ξ)ⁿ = H_ξ(x)` with `z = ξ` (and `H_0(x + log n)ⁿ = H_0(x)`), + so the maximum of `n` iid GEV variables is again GEV of the same shape (`gevCDF_max_stable`, + MFE Exercise 5.10 in the Fréchet case). In particular every GEV lies in its own domain of + attraction. +* **The exponential law** lies in the Gumbel domain of attraction with `cₙ = 1/λ`, + `dₙ = log n / λ` (MFE Exercise 5.23(b), `tendsto_cdf_expMeasure_pow_gumbel`). + +The generalized Pareto family and its domain of attraction are in +`Probability/Laws/GeneralizedPareto.lean`, and the Poisson–GPD–GEV link is in +`Probability/Jumps/PoissonMaxima.lean`. + +## Main definitions + +* `gevCDF`: the standard generalized extreme value distribution function `H_ξ`, with the Gumbel + case `exp(−e^{−x})` at `ξ = 0`. +* `InMDA`: `F` lies in the maximum domain of attraction of `H`, i.e. `F(cₙ x + dₙ)ⁿ → H(x)` for + some constants `cₙ > 0` and `dₙ`. +* `gevNormScale`, `gevNormLoc`: the max-stability normalizing constants `nᶻ` and `(nᶻ − 1)/ξ` + (`log n` at `ξ = 0`), with `z = ξ`. + +## Main results + +* `tendsto_pow_iff_tendsto_mul_one_sub`: `aₙⁿ → e^{−τ} ↔ n (1 − aₙ) → τ` for `aₙ ≥ 0`. +* `tendsto_pow_iff_tendsto_nat_mul_tail`: MFE Exercise 5.23(a) for a distribution function. +* `gevNormScale`, `gevNormLoc`, `one_add_mul_gevNorm`: the max-stability normalization. +* `gevCDF_max_stable`, `gevCDF_inMDA`: max-stability of the GEV family. +* `tendsto_cdf_expMeasure_pow_gumbel`, `cdf_expMeasure_inMDA`: exponential ∈ MDA(Gumbel). + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Section 5.1; Section 5.1.1 +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 5.10; Ex. 5.23(a); Ex. 5.23(b) + +## Tags + +extreme value theory, generalized extreme value, Gumbel, Fréchet, +domain of attraction, block maxima, MSC 62G30, MSC 60E05, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open Real Filter Topology MeasureTheory ProbabilityTheory + +/-- The standard **generalized extreme value** distribution function `H_ξ`: +`H_ξ(x) = exp(−(1 + ξx)^{−1/ξ})` where `1 + ξx > 0`, with the value `0` below the support +(`ξ > 0`, Fréchet case) and `1` above it (`ξ < 0`, Weibull case), and the Gumbel distribution +function `H_0(x) = exp(−e^{−x})` for `ξ = 0`. -/ +noncomputable def gevCDF (ξ x : ℝ) : ℝ := + if ξ = 0 then exp (-exp (-x)) + else if 0 < 1 + ξ * x then exp (-(1 + ξ * x) ^ (-1 / ξ)) + else if 0 < ξ then 0 else 1 + +/-- Pointwise convergence of normalized powers of `F` to `H`. For a distribution +function `F` and a continuous nondegenerate distribution function `H`, this is +the maximum domain of attraction condition in McNeil, Frey and Embrechts (2015), +Definition 5.2. The predicate accepts arbitrary functions and requires convergence +at every `x`. -/ +def InMDA (F H : ℝ → ℝ) : Prop := + ∃ c d : ℕ → ℝ, (∀ n, 0 < c n) ∧ + ∀ x, Tendsto (fun n : ℕ ↦ F (c n * x + d n) ^ n) atTop (𝓝 (H x)) + +/-- The Gumbel case of the GEV. -/ +lemma gevCDF_zero (x : ℝ) : gevCDF 0 x = exp (-exp (-x)) := + ite_eq_left rfl + +lemma gevCDF_of_pos {ξ x : ℝ} (hξ : ξ ≠ 0) (hx : 0 < 1 + ξ * x) : + gevCDF ξ x = exp (-(1 + ξ * x) ^ (-1 / ξ)) := by + rw [gevCDF, ite_eq_right hξ, ite_eq_left hx] + +lemma gevCDF_of_nonpos {ξ x : ℝ} (hξ : ξ ≠ 0) (hx : 1 + ξ * x ≤ 0) : + gevCDF ξ x = if 0 < ξ then 0 else 1 := by + rw [gevCDF, ite_eq_right hξ, ite_eq_right hx.not_gt] + +/-! ### The Poisson approximation -/ + +/-- **Poisson approximation of powers.** For a nonnegative sequence `a`, +`aₙⁿ → e^{−τ}` if and only if `n (1 − aₙ) → τ`. -/ +theorem tendsto_pow_iff_tendsto_mul_one_sub {a : ℕ → ℝ} (ha : ∀ n, 0 ≤ a n) (τ : ℝ) : + Tendsto (fun n ↦ a n ^ n) atTop (𝓝 (exp (-τ))) ↔ + Tendsto (fun n : ℕ ↦ (n : ℝ) * (1 - a n)) atTop (𝓝 τ) := by + refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ + · -- a positive limit keeps `aₙ` away from `0` + have hpos : ∀ᶠ n in atTop, 0 < a n := by + filter_upwards [h.eventually (lt_mem_nhds (exp_pos (-τ))), eventually_ge_atTop 1] + with n hn hn1 + refine (ha n).lt_of_ne fun h0 ↦ ?_ + rw [← h0, zero_pow (by omega)] at hn + exact hn.false + -- taking logarithms: `n log aₙ → −τ` + have hlog : Tendsto (fun n : ℕ ↦ (n : ℝ) * log (a n)) atTop (𝓝 (-τ)) := by + have := h.log (exp_pos _).ne' + rw [log_exp] at this + exact this.congr fun n ↦ log_pow (a n) n + -- so `log aₙ → 0` and `aₙ → 1` + have ha1 : Tendsto a atTop (𝓝 1) := by + have h0 : Tendsto (fun n : ℕ ↦ log (a n)) atTop (𝓝 0) := by + have := hlog.mul (tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop) + rw [mul_zero] at this + refine this.congr' ?_ + filter_upwards [eventually_ge_atTop 1] with n hn + have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.2 (by omega) + simp only [Function.comp_apply] + field_simp + have := (continuous_exp.tendsto 0).comp h0 + rw [exp_zero] at this + exact this.congr' (hpos.mono fun n hn ↦ exp_log hn) + -- squeeze `n (aₙ − 1)` between `n log aₙ` and `aₙ · (n log aₙ)` + have hsq : Tendsto (fun n : ℕ ↦ (n : ℝ) * (a n - 1)) atTop (𝓝 (-τ)) := by + refine tendsto_of_tendsto_of_tendsto_of_le_of_le' hlog (by simpa using ha1.mul hlog) + (hpos.mono fun n hn ↦ mul_le_mul_of_nonneg_left (log_le_sub_one_of_pos hn) + n.cast_nonneg) (hpos.mono fun n hn ↦ ?_) + calc (n : ℝ) * (a n - 1) = n * a n * (1 - (a n)⁻¹) := by field_simp + _ ≤ n * a n * log (a n) := + mul_le_mul_of_nonneg_left (one_sub_inv_le_log_of_pos hn) (by positivity) + _ = a n * (n * log (a n)) := by ring + have := hsq.neg + rw [neg_neg] at this + exact this.congr fun n ↦ by ring + · have h' : Tendsto (fun n : ℕ ↦ (n : ℝ) * (a n - 1)) atTop (𝓝 (-τ)) := + h.neg.congr fun n ↦ by ring + exact (Real.tendsto_one_add_pow_exp_of_tendsto h').congr fun n ↦ by ring + +/-- **The Poisson approximation for maxima** (MFE Exercise 5.23(a)): for a distribution +function `F`, levels `uₙ` and `h > 0`, +`F(uₙ)ⁿ → h ↔ n (1 − F(uₙ)) → −log h`. With `uₙ = cₙ x + dₙ` this says +`Fⁿ(cₙ x + dₙ) → H(x)` exactly when `n F_bar(cₙ x + dₙ) → −log H(x)`. -/ +theorem tendsto_pow_iff_tendsto_nat_mul_tail {F : ℝ → ℝ} (hF : ∀ x, 0 ≤ F x) (u : ℕ → ℝ) + {h : ℝ} (hh : 0 < h) : + Tendsto (fun n ↦ F (u n) ^ n) atTop (𝓝 h) ↔ + Tendsto (fun n : ℕ ↦ (n : ℝ) * (1 - F (u n))) atTop (𝓝 (-log h)) := by + have := tendsto_pow_iff_tendsto_mul_one_sub (fun n ↦ hF (u n)) (-log h) + rwa [neg_neg, exp_log hh] at this + +/-! ### Max-stability of the GEV family -/ + +/-- The scale normalization `nᶻ` of max-stability, with `z = ξ` (kept positive at `n = 0`). -/ +noncomputable def gevNormScale (ξ : ℝ) (n : ℕ) : ℝ := + max (n : ℝ) 1 ^ ξ + +/-- The location normalization of max-stability: `(nᶻ − 1)/ξ` with `z = ξ`, and its limit +`log n` when `ξ = 0`. -/ +noncomputable def gevNormLoc (ξ : ℝ) (n : ℕ) : ℝ := + if ξ = 0 then log n else (gevNormScale ξ n - 1) / ξ + +lemma gevNormScale_pos (ξ : ℝ) (n : ℕ) : 0 < gevNormScale ξ n := + rpow_pos_of_pos (lt_max_of_lt_right one_pos) ξ + +/-- The max-stability normalization moves the GEV support by a factor: for `ξ ≠ 0`, +`1 + ξ (cₙ x + dₙ) = cₙ (1 + ξ x)`. -/ +lemma one_add_mul_gevNorm {ξ : ℝ} (hξ : ξ ≠ 0) (n : ℕ) (x : ℝ) : + 1 + ξ * (gevNormScale ξ n * x + gevNormLoc ξ n) = gevNormScale ξ n * (1 + ξ * x) := by + rw [gevNormLoc, ite_eq_right hξ] + field_simp + ring + +/-- **Max-stability of the GEV family** (MFE Exercise 5.10 for the Fréchet case): for every +shape `ξ` and every `n ≥ 1`, `H_ξ(nᶻ x + dₙ)ⁿ = H_ξ(x)` with `z = ξ` and `dₙ = (nᶻ − 1)/ξ` +(`dₙ = log n` for `ξ = 0`). The maximum of `n` iid `H_ξ` variables, rescaled, is again `H_ξ`. -/ +theorem gevCDF_max_stable (ξ x : ℝ) {n : ℕ} (hn : n ≠ 0) : + gevCDF ξ (gevNormScale ξ n * x + gevNormLoc ξ n) ^ n = gevCDF ξ x := by + have hn1 : (1 : ℝ) ≤ n := Nat.one_le_cast.2 (Nat.pos_of_ne_zero hn) + have hnpos : (0 : ℝ) < n := one_pos.trans_le hn1 + have hn0 : (n : ℝ) ≠ 0 := hnpos.ne' + by_cases hξ : ξ = 0 + · subst hξ + rw [gevNormLoc, ite_eq_left rfl, gevNormScale, rpow_zero, one_mul, gevCDF_zero, gevCDF_zero, + ← exp_nat_mul, neg_add, exp_add, exp_neg (log n), exp_log hnpos] + congr 1 + field_simp + · have hc : 0 < gevNormScale ξ n := gevNormScale_pos ξ n + have hcn : gevNormScale ξ n = (n : ℝ) ^ ξ := by rw [gevNormScale, max_eq_left hn1] + have hkey := one_add_mul_gevNorm hξ n x + by_cases hx : 0 < 1 + ξ * x + · have hpos : 0 < 1 + ξ * (gevNormScale ξ n * x + gevNormLoc ξ n) := hkey ▸ mul_pos hc hx + rw [gevCDF_of_pos hξ hpos, gevCDF_of_pos hξ hx, hkey, ← exp_nat_mul, + mul_rpow hc.le hx.le, hcn, ← rpow_mul hnpos.le, show ξ * (-1 / ξ) = -1 by field_simp, + rpow_neg_one] + congr 1 + field_simp + · have hx' : 1 + ξ * x ≤ 0 := not_lt.1 hx + have hnp : 1 + ξ * (gevNormScale ξ n * x + gevNormLoc ξ n) ≤ 0 := + hkey ▸ mul_nonpos_of_nonneg_of_nonpos hc.le hx' + rw [gevCDF_of_nonpos hξ hnp, gevCDF_of_nonpos hξ hx'] + split_ifs <;> simp [hn] + +/-- Every GEV distribution function lies in its own maximum domain of attraction: the +normalized maxima are exactly `H_ξ` from `n = 1` on. -/ +theorem gevCDF_inMDA (ξ : ℝ) : InMDA (gevCDF ξ) (gevCDF ξ) := + ⟨gevNormScale ξ, gevNormLoc ξ, gevNormScale_pos ξ, fun x ↦ tendsto_const_nhds.congr' <| + (eventually_ge_atTop 1).mono fun _ hn ↦ (gevCDF_max_stable ξ x (by omega)).symm⟩ + +/-! ### The exponential law is in the Gumbel domain of attraction -/ + +/-- **MFE Exercise 5.23(b).** For the exponential law with rate `λ > 0`, +`F(x/λ + log n/λ)ⁿ → exp(−e^{−x}) = H_0(x)`: the maximum of `n` iid exponentials, recentred +by `log n / λ` and rescaled by `λ`, converges to the Gumbel law. -/ +theorem tendsto_cdf_expMeasure_pow_gumbel {r : ℝ} (hr : 0 < r) (x : ℝ) : + Tendsto (fun n : ℕ ↦ cdf (expMeasure r) (r⁻¹ * x + log n / r) ^ n) atTop + (𝓝 (gevCDF 0 x)) := by + rw [gevCDF_zero, tendsto_pow_iff_tendsto_nat_mul_tail (cdf_nonneg _) _ (exp_pos _), log_exp, + neg_neg] + refine tendsto_const_nhds.congr' ?_ + filter_upwards [eventually_ge_atTop 1, + (tendsto_log_atTop.comp tendsto_natCast_atTop_atTop).eventually_ge_atTop (-x)] + with n hn hlog + have hnpos : (0 : ℝ) < n := Nat.cast_pos.2 hn + have hn0 : (n : ℝ) ≠ 0 := hnpos.ne' + have hr0 : r ≠ 0 := hr.ne' + have hlog' : 0 ≤ x + log n := by simp only [Function.comp_apply] at hlog; linarith + have harg : r⁻¹ * x + log n / r = (x + log n) / r := by field_simp + rw [harg, cdf_expMeasure_eq hr, ite_eq_left (div_nonneg hlog' hr.le), + show r * ((x + log n) / r) = x + log n by field_simp, neg_add, exp_add, exp_neg (log n), + exp_log hnpos] + field_simp + ring + +/-- The exponential law lies in the maximum domain of attraction of the Gumbel distribution. -/ +theorem cdf_expMeasure_inMDA {r : ℝ} (hr : 0 < r) : InMDA (cdf (expMeasure r)) (gevCDF 0) := + ⟨fun _ ↦ r⁻¹, fun n ↦ log n / r, fun _ ↦ inv_pos.2 hr, tendsto_cdf_expMeasure_pow_gumbel hr⟩ + +end MathFin diff --git a/LeanPool/MathFin/Probability/Laws/FiniteWeights.lean b/LeanPool/MathFin/Probability/Laws/FiniteWeights.lean new file mode 100644 index 0000000000..66d75fccdf --- /dev/null +++ b/LeanPool/MathFin/Probability/Laws/FiniteWeights.lean @@ -0,0 +1,85 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.MeasureTheory.Integral.Bochner.SumMeasure + +/-! +# The law of a finite weight vector + +`Measure.ofWeights s p` is the measure `∑ i ∈ s, p i • δ_i` with the weights `p i` on the finite +set `s`: the single adaptor between the library's `Finset`-indexed weight vectors (probabilities, +state prices, spectral weights) and Mathlib's measures. For non-negative weights its integral is +the weighted sum, `∫ f ∂ofWeights s p = ∑ i ∈ s, p i * f i`, so a statement about weighted sums is +a statement about an integral, and a finite measure on a finite space is the law of its own +point masses (`ofWeights_univ_real_singleton`). It lives in `MeasureTheory.Measure` as an upstream +candidate (cf. `PMF.toMeasure`, which needs weights summing to one). + +## Main definitions + +* `MeasureTheory.Measure.ofWeights`: the measure `∑ i ∈ s, ofReal (p i) • dirac i`. + +## Main results + +* `MeasureTheory.Measure.integral_ofWeights`: `∫ f ∂ofWeights s p = ∑ i ∈ s, p i * f i` for + non-negative weights. +* `MeasureTheory.Measure.isProbabilityMeasure_ofWeights`: weights summing to one give a + probability measure. +* `MeasureTheory.Measure.ofWeights_univ_real_singleton`: a finite measure on a finite type with + measurable singletons is `ofWeights univ (fun i ↦ μ.real {i})`. + +## References + +* [H. Föllmer and A. Schied, *Stochastic Finance: An Introduction in Discrete Time*][FollmerSchied], + §1.1 + +## Tags + +finite law, point masses, discrete probability, weights, Dirac measure, MSC 28A25 +-/ + +@[expose] public section + +open MeasureTheory + +namespace MeasureTheory.Measure + +variable {ι : Type*} [MeasurableSpace ι] + +/-- **The measure with weights `p i` on the points `i ∈ s`**: `∑ i ∈ s, p i • δ_i`, with negative +weights read as `0`. -/ +noncomputable def ofWeights (s : Finset ι) (p : ι → ℝ) : Measure ι := + ∑ i ∈ s, ENNReal.ofReal (p i) • Measure.dirac i + +/-- Weights that are non-negative and sum to one give a probability measure. -/ +theorem isProbabilityMeasure_ofWeights {s : Finset ι} {p : ι → ℝ} (hp0 : ∀ i ∈ s, 0 ≤ p i) + (hp1 : ∑ i ∈ s, p i = 1) : IsProbabilityMeasure (ofWeights s p) := + ⟨by simp [ofWeights, ← ENNReal.ofReal_sum_of_nonneg hp0, hp1]⟩ + +/-- **The integral against finite weights is the weighted sum**: +`∫ f ∂(∑ i ∈ s, p i • δ_i) = ∑ i ∈ s, p i * f i` for non-negative weights. -/ +theorem integral_ofWeights [MeasurableSingletonClass ι] (s : Finset ι) {p : ι → ℝ} + (hp : ∀ i ∈ s, 0 ≤ p i) (f : ι → ℝ) : + ∫ i, f i ∂ofWeights s p = ∑ i ∈ s, p i * f i := by + have hint : ∀ i ∈ s, Integrable f (ENNReal.ofReal (p i) • Measure.dirac i) := fun i _ ↦ + (integrable_dirac (by simp)).smul_measure ENNReal.ofReal_ne_top + rw [ofWeights, integral_finsetSum_measure hint] + refine Finset.sum_congr rfl fun i hi ↦ ?_ + rw [integral_smul_measure, integral_dirac, ENNReal.toReal_ofReal (hp i hi), smul_eq_mul] + +/-- **A finite measure on a finite type is the law of its point masses**: +`μ = ∑ i, μ {i} • δ_i`. -/ +theorem ofWeights_univ_real_singleton [Fintype ι] [MeasurableSingletonClass ι] (μ : Measure ι) + [IsFiniteMeasure μ] : ofWeights Finset.univ (fun i ↦ μ.real {i}) = μ := by + refine Eq.trans ?_ (Measure.sum_smul_dirac μ) + rw [ofWeights, Measure.sum_fintype] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + rw [measureReal_def, ENNReal.ofReal_toReal (measure_ne_top μ _)] + +end MeasureTheory.Measure diff --git a/LeanPool/MathFin/Probability/Laws/GammaPoissonMixturePgf.lean b/LeanPool/MathFin/Probability/Laws/GammaPoissonMixturePgf.lean new file mode 100644 index 0000000000..1ec3f262fd --- /dev/null +++ b/LeanPool/MathFin/Probability/Laws/GammaPoissonMixturePgf.lean @@ -0,0 +1,175 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Jumps.PoissonPgf +public import Mathlib.Probability.Distributions.Gamma +public import Mathlib.Probability.Moments.Basic + +/-! +# CreditRisk+ sector probability-generating function (Poisson–Gamma mixture) + +CreditRisk+ (Credit Suisse First Boston, 1997) models each sector's systematic +risk factor as a random intensity `Λ ∼ Gamma(a, r)` (shape `a`, Mathlib's +*rate* parametrisation `r = 1/β` for the technical document's scale `β`). +Conditional on `Λ = λ`, the sector default count `N` is Poisson(`λ`), with +conditional pgf `E[z^N | Λ = λ] = exp(λ(z−1))` +(`PoissonPgf.integral_pow_poissonMeasure`, `Probability/Jumps/PoissonPgf.lean`). + +**The mixture, as an iterated integral.** The unconditional sector pgf is the +tower property `G_N(z) = E_Λ[E[z^N | Λ]]`. Here it is stated as the iterated +integral + + `∫ λ, (∫ n, z ^ n ∂Poisson(λ)) ∂Gamma(a, r) = (r / (r − (z − 1))) ^ a`, + +whose inner integral is the Poisson pgf and whose outer integral is the Gamma +moment-generating function at `z − 1`. The mixed law of `N` itself (a +`Measure.bind` of the Poisson kernel against the Gamma law) and a pair of random +variables `(N, Λ)` with this conditional structure are not constructed. + +The loss-banding approximation that turns the exact per-sector pgf into +CreditRisk+'s practical recursion is **out of scope** here, as is the portfolio +pgf across independent sectors. + +## Main results + +* `integral_exp_mul_gammaMeasure`, `mgf_id_gammaMeasure`: the Gamma(`a`, `r`) + moment-generating function, `∫ λ, exp(s·λ) ∂Gamma(a,r) = (r / (r − s)) ^ a` + for `s < r` (Mathlib has the Gamma law but no Gamma MGF). +* `integral_integral_pow_poissonMeasure_gammaMeasure`: the Poisson–Gamma + mixture sector pgf, as the iterated integral above, for `z < r + 1`. +* `integral_integral_pow_poissonMeasure_gammaMeasure_eq_negBinomial`: the same + pgf in the technical document's `p = β / (1 + β)` scale parametrisation, + `((1 − p) / (1 − p·z)) ^ a`. +* `poissonMeasure_real_compl_singleton_zero`: `PD_i = 1 − e^{−λ_i}`, i.e. + `P(N_i ≠ 0) = 1 − e^{−λ_i}` for `N_i ∼ Poisson(λ_i)`. + +## References + +* [N. L. Johnson, S. Kotz and N. Balakrishnan, *Continuous Univariate Distributions, + Vol.~1*][JohnsonKotzBalakrishnan1994], ch. 17 + +## Tags + +CreditRisk+, Poisson–Gamma mixture, negative binomial, probability generating function, +default count, sector risk factor, MSC 91G40, MSC 60E10, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real Set +open scoped NNReal ENNReal + +namespace GammaPoissonMixturePgf + +/-- **Gamma moment-generating function.** For `Λ ∼ Gamma(a, r)` (shape `a`, +rate `r`) and `s < r`, `E[exp(s·Λ)] = (r / (r − s)) ^ a`. Proved the same way +Mathlib normalises the Gamma pdf (`lintegral_gammaPDF_eq_one`): factor the +pdf's `exp(−r·λ)` against `exp(s·λ)` into `exp(−(r−s)·λ)` and apply the Gamma +integral `integral_rpow_mul_exp_neg_mul_Ioi` at rate `r − s`. -/ +theorem integral_exp_mul_gammaMeasure {a r s : ℝ} (ha : 0 < a) (hr : 0 < r) (hs : s < r) : + ∫ lam, rexp (s * lam) ∂(gammaMeasure a r) = (r / (r - s)) ^ a := by + have hrs : 0 < r - s := by linarith + have hmeasg : Measurable (fun lam : ℝ ↦ ENNReal.ofReal (rexp (s * lam))) := + ((measurable_id'.const_mul s).exp).ennreal_ofReal + have hmeasf : Measurable (gammaPDF a r) := + (measurable_gammaPDFReal a r).ennreal_ofReal + have hmeasF : Measurable + (fun lam : ℝ ↦ r ^ a / Gamma a * lam ^ (a - 1) * exp (-((r - s) * lam))) := + ((measurable_id'.pow_const (a - 1)).const_mul _).mul + (measurable_id'.const_mul (r - s)).neg.exp + rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ fun lam ↦ (Real.exp_pos _).le) + ((measurable_id'.const_mul s).exp.aestronglyMeasurable)] + have hL : ∫⁻ lam, ENNReal.ofReal (rexp (s * lam)) ∂(gammaMeasure a r) + = ∫⁻ lam in Ici (0 : ℝ), ENNReal.ofReal + (r ^ a / Gamma a * lam ^ (a - 1) * exp (-((r - s) * lam))) := by + rw [gammaMeasure, lintegral_withDensity_eq_lintegral_mul _ hmeasf hmeasg, + ← lintegral_add_compl _ (measurableSet_Ici (a := (0 : ℝ))), compl_Ici] + have hleft : ∫⁻ lam in Iio (0 : ℝ), + (gammaPDF a r * fun lam ↦ ENNReal.ofReal (rexp (s * lam))) lam = 0 := by + rw [setLIntegral_congr_fun (g := fun _ ↦ (0 : ℝ≥0∞)) measurableSet_Iio] + · simp + · intro lam (hlam : lam < 0) + simp [Pi.mul_apply, gammaPDF_of_neg hlam] + have hright : ∫⁻ lam in Ici (0 : ℝ), + (gammaPDF a r * fun lam ↦ ENNReal.ofReal (rexp (s * lam))) lam + = ∫⁻ lam in Ici (0 : ℝ), ENNReal.ofReal + (r ^ a / Gamma a * lam ^ (a - 1) * exp (-((r - s) * lam))) := by + refine setLIntegral_congr_fun measurableSet_Ici (fun lam (hlam : 0 ≤ lam) ↦ ?_) + simp only [Pi.mul_apply, gammaPDF_of_nonneg hlam] + rw [← ENNReal.ofReal_mul (by positivity)] + congr 1 + rw [show -((r - s) * lam) = -(r * lam) + s * lam by ring, Real.exp_add] + ring + rw [hright, hleft, add_zero] + rw [hL, ← integral_eq_lintegral_of_nonneg_ae + ((ae_restrict_iff' measurableSet_Ici).mpr + (ae_of_all _ fun lam (hlam : 0 ≤ lam) ↦ by positivity)) + hmeasF.aestronglyMeasurable] + have hF : (fun lam : ℝ ↦ r ^ a / Gamma a * lam ^ (a - 1) * exp (-((r - s) * lam))) + = fun lam : ℝ ↦ (r ^ a / Gamma a) * (lam ^ (a - 1) * exp (-((r - s) * lam))) := by + funext lam; ring + rw [hF, MeasureTheory.integral_const_mul, integral_Ici_eq_integral_Ioi, + integral_rpow_mul_exp_neg_mul_Ioi ha hrs] + have hGpos : (0 : ℝ) < Gamma a := Gamma_pos_of_pos ha + rw [mul_comm ((1 / (r - s)) ^ a) (Gamma a), ← mul_assoc, div_mul_cancel₀ _ hGpos.ne', + ← Real.mul_rpow hr.le (by positivity), mul_one_div] + +/-- The Gamma moment-generating function in Mathlib's `mgf` form, the sibling of +`mgf_id_gaussianReal`: `mgf id (gammaMeasure a r) s = (r / (r − s)) ^ a` for `s < r`. -/ +theorem mgf_id_gammaMeasure {a r s : ℝ} (ha : 0 < a) (hr : 0 < r) (hs : s < r) : + mgf id (gammaMeasure a r) s = (r / (r - s)) ^ a := + integral_exp_mul_gammaMeasure ha hr hs + +/-- **CreditRisk+ sector pgf** (Poisson–Gamma mixture, exact, before loss-banding): for +`z < r + 1`, the Poisson pgf `E[z^N | Λ = λ] = ∫ n, z ^ n ∂Poisson(λ)` integrated against +`Λ ∼ Gamma(a, r)` is `(r / (r − (z − 1))) ^ a`. This is the tower property +`E[z^N] = E_Λ[E[z^N | Λ]]` written as an iterated integral; the mixed law of `N` is not +constructed. The Gamma law lives on `[0, ∞)`, so `λ.toNNReal = λ` almost everywhere and the outer +integral is the Gamma MGF at `z − 1`. -/ +theorem integral_integral_pow_poissonMeasure_gammaMeasure {a r z : ℝ} (ha : 0 < a) (hr : 0 < r) + (hz : z < r + 1) : + ∫ lam, (∫ n, z ^ n ∂poissonMeasure lam.toNNReal) ∂gammaMeasure a r = + (r / (r - (z - 1))) ^ a := by + have hmeasf : Measurable (gammaPDF a r) := (measurable_gammaPDFReal a r).ennreal_ofReal + have hpos : ∀ᵐ lam ∂gammaMeasure a r, 0 ≤ lam := by + rw [gammaMeasure, ae_withDensity_iff hmeasf] + exact ae_of_all _ fun lam hlam ↦ not_lt.1 fun hneg ↦ hlam (gammaPDF_of_neg hneg) + rw [← integral_exp_mul_gammaMeasure ha hr (show z - 1 < r by linarith)] + refine integral_congr_ae ?_ + filter_upwards [hpos] with lam hlam + rw [PoissonPgf.integral_pow_poissonMeasure, Real.coe_toNNReal _ hlam, mul_comm lam] + +/-- **Sector pgf, negative-binomial-style `p`-form.** With `β > 0` the mixture scale and +`p = β / (1 + β)`, the sector pgf is `((1 − p) / (1 − p·z)) ^ a`, matching the CreditRisk+ +technical document's parametrisation. Mathlib's `gammaMeasure` is rate-parametrised, so the +Gamma law used is `gammaMeasure a (1 / β)`. -/ +theorem integral_integral_pow_poissonMeasure_gammaMeasure_eq_negBinomial {a β z : ℝ} + (ha : 0 < a) (hβ : 0 < β) (hz : z < 1 + 1 / β) : + ∫ lam, (∫ n, z ^ n ∂poissonMeasure lam.toNNReal) ∂gammaMeasure a (1 / β) = + ((1 - β / (1 + β)) / (1 - β / (1 + β) * z)) ^ a := by + have hr : (0 : ℝ) < 1 / β := by positivity + rw [integral_integral_pow_poissonMeasure_gammaMeasure ha hr (by rw [add_comm]; linarith)] + congr 1 + have hβ1 : (1 : ℝ) + β ≠ 0 := by positivity + field_simp + ring + +/-- **`PD_i = 1 − e^{−λ_i}`**: for `N ∼ Poisson(λ)`, the default probability `P(N ≠ 0)` equals +`1 − e^{−λ}`, since `P(N = 0) = e^{−λ}` and probabilities sum to `1`. -/ +theorem poissonMeasure_real_compl_singleton_zero (lam : ℝ≥0) : + (poissonMeasure lam).real {0}ᶜ = 1 - rexp (-(lam : ℝ)) := by + have h0 : (poissonMeasure lam).real {0} = rexp (-(lam : ℝ)) := by + rw [poissonMeasure_real_singleton]; simp + rw [measureReal_compl (MeasurableSet.singleton 0), probReal_univ, h0] + +end GammaPoissonMixturePgf + +end MathFin diff --git a/LeanPool/MathFin/Probability/Laws/GeneralizedPareto.lean b/LeanPool/MathFin/Probability/Laws/GeneralizedPareto.lean new file mode 100644 index 0000000000..2f91ccf902 --- /dev/null +++ b/LeanPool/MathFin/Probability/Laws/GeneralizedPareto.lean @@ -0,0 +1,534 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Laws.ExtremeValue +public import LeanPool.MathFin.Probability.Laws.Quantile +public import Mathlib.Algebra.Order.Star.Real + +/-! +# The generalized Pareto distribution + +The **generalized Pareto distribution** `GPD(ξ, β)` has tail function + + `Gbar_{ξ,β}(x) = (1 + ξx/β)^{−1/ξ}` (`e^{−x/β}` when `ξ = 0`), + +on `x ≥ 0` (and `x ≤ −β/ξ` when `ξ < 0`). It is the model of the peaks-over-threshold method +(McNeil–Frey–Embrechts, *Quantitative Risk Management* (2015), §5.2). The Pickands–Balkema–de +Haan theorem, which makes it the limit law of excesses over high thresholds, is not formalized +here. This file proves the properties that make the GPD a consistent model for excesses. + +* **Domain of attraction** (MFE Exercise 5.16). `G_{ξ,β} ∈ MDA(H_ξ)` for every shape `ξ`, with + the normalizing constants of GEV max-stability scaled by `β` (`tendsto_gpdCDF_pow`, + `gpdCDF_inMDA`). The Pareto (Lomax) tail `(κ/(κ + x))^α` is the GPD tail with `ξ = 1/α`, + `β = κ/α` (`gpdTail_inv_shape`), so the Pareto law lies in the Fréchet domain `MDA(H_{1/α})`. +* **Threshold stability.** Excesses of a GPD over a threshold `u` in its support are again GPD, + with the same shape and scale `β + ξu`: `Gbar_{ξ,β}(u + x) = Gbar_{ξ,β}(u) · Gbar_{ξ,β+ξu}(x)` + (`gpdTail_add`). As laws, `(X − u | X > u) ∼ GPD(ξ, β + ξu)` (`map_cond_gpdMeasure`). +* **The GPD law.** `gpdMeasure ξ β` is the law of `β (e^{ξE} − 1)/ξ` (`β E` for `ξ = 0`) for a + standard exponential `E`. Its distribution function is `G_{ξ,β}` (`cdf_gpdMeasure`), and its + quantile function, the value-at-risk of a GPD loss, is `β((1 − p)^{−ξ} − 1)/ξ` + (`quantile_gpdMeasure_of_ne_zero`), or `−β log(1 − p)` when `ξ = 0`. +* **Tail averages.** For `ξ < 1` the average of the quantile function over `(α, 1)` is + `(q(α) + β)/(1 − ξ)` (`setIntegral_quantile_gpdMeasure`). This is the expected shortfall + formula `ES_α = (VaR_α + β)/(1 − ξ)` of MFE eq. (5.19) at threshold `0`. The mean is + `β/(1 − ξ)` (`integral_id_gpdMeasure`). The **mean excess function** is linear, + `e(u) = E[X − u | X > u] = (β + ξu)/(1 − ξ)` (`integral_sub_cond_gpdMeasure`, MFE + Exercise 5.19(b)), which is what a sample mean-excess plot is inspected for. + +## Main definitions + +* `gpdTail`: the tail function `Gbar_{ξ,β}(x) = (1 + ξx/β)^{−1/ξ}` (`e^{−x/β}` for `ξ = 0`), + equal to `1` for `x ≤ 0` and to `0` beyond the right endpoint `−β/ξ` when `ξ < 0`. +* `gpdCDF`: the distribution function `G_{ξ,β} = 1 − Gbar_{ξ,β}`. +* `gpdMeasure`: the law `GPD(ξ, β)` of `β(e^{ξE} − 1)/ξ` (`β E` for `ξ = 0`) for a standard + exponential variable `E`. + +## Main results + +* `tendsto_gpdCDF_pow`, `gpdCDF_inMDA`: `G_{ξ,β} ∈ MDA(H_ξ)`. +* `gpdTail_add`, `gpdCDF_excess`: threshold stability for distribution functions. +* `gpdMeasure`, `cdf_gpdMeasure`, `quantile_gpdMeasure`: the GPD law and its quantiles. +* `setIntegral_quantile_gpdMeasure`, `integral_id_gpdMeasure`: tail averages and the mean. +* `map_cond_gpdMeasure`, `integral_sub_cond_gpdMeasure`: excesses of the GPD law and the + mean excess function. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Section 5.2.1 +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 5.16; Ex. 5.19(b) + +## Tags + +generalized Pareto distribution, peaks over threshold, mean excess function, expected shortfall, +tail risk, MSC 62G30, MSC 91G70, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open Real Filter Topology MeasureTheory ProbabilityTheory Set + +variable {ξ β x : ℝ} + +/-! ### The tail and distribution functions -/ + +/-- For positive scale `β`, the **generalized Pareto tail function** is +`Gbar_{ξ,β}(x) = (1 + ξx/β)^{−1/ξ}` on the support and `e^{−x/β}` when `ξ = 0`. +It equals `1` for `x ≤ 0` and `0` beyond the right endpoint `−β/ξ` when `ξ < 0`. -/ +noncomputable def gpdTail (ξ β x : ℝ) : ℝ := + if ξ = 0 then exp (-(max x 0 / β)) else max (1 + ξ * (max x 0 / β)) 0 ^ (-1 / ξ) + +/-- For positive scale `β`, the **generalized Pareto distribution function** is +`G_{ξ,β} = 1 − Gbar_{ξ,β}` (McNeil, Frey and Embrechts, 2015, +Definition 5.16, equation (5.8)). -/ +noncomputable def gpdCDF (ξ β x : ℝ) : ℝ := + 1 - gpdTail ξ β x + +lemma gpdTail_of_nonpos (hx : x ≤ 0) : gpdTail ξ β x = 1 := by + rw [gpdTail, max_eq_right hx, zero_div, neg_zero, exp_zero, mul_zero, add_zero, + max_eq_left zero_le_one, one_rpow, ite_self] + +lemma gpdTail_zero_shape (hx : 0 ≤ x) : gpdTail 0 β x = exp (-(x / β)) := by + rw [gpdTail, ite_eq_left rfl, max_eq_left hx] + +lemma gpdTail_of_nonneg (hξ : ξ ≠ 0) (hx : 0 ≤ x) (h : 0 ≤ 1 + ξ * (x / β)) : + gpdTail ξ β x = (1 + ξ * (x / β)) ^ (-1 / ξ) := by + rw [gpdTail, ite_eq_right hξ, max_eq_left hx, max_eq_left h] + +/-- Beyond the right endpoint `−β/ξ` (only possible for `ξ < 0`) the tail vanishes. -/ +lemma gpdTail_of_endpoint_le (hξ : ξ ≠ 0) (hx : 0 ≤ x) (h : 1 + ξ * (x / β) ≤ 0) : + gpdTail ξ β x = 0 := by + rw [gpdTail, ite_eq_right hξ, max_eq_left hx, max_eq_right h, + zero_rpow (div_ne_zero (by norm_num) hξ)] + +/-- The tail is positive inside the support. -/ +lemma gpdTail_pos (hx : 0 < 1 + ξ * (max x 0 / β)) : 0 < gpdTail ξ β x := by + unfold gpdTail + split_ifs + · exact exp_pos _ + · rw [max_eq_left hx.le] + exact rpow_pos_of_pos hx _ + +/-- The tail is at most `1`. -/ +lemma gpdTail_le_one (hβ : 0 < β) : gpdTail ξ β x ≤ 1 := by + have hm : 0 ≤ max x 0 / β := div_nonneg (le_max_right _ _) hβ.le + unfold gpdTail + split_ifs with hξ + · exact exp_le_one_iff.2 (neg_nonpos.2 hm) + · rcases lt_or_gt_of_ne hξ with hneg | hpos + · refine rpow_le_one (le_max_right _ _) (max_le ?_ zero_le_one) + (div_nonneg_of_nonpos (by norm_num) hneg.le) + nlinarith [mul_nonneg (neg_nonneg.2 hneg.le) hm] + · exact rpow_le_one_of_one_le_of_nonpos + (le_max_of_le_left (by nlinarith [mul_nonneg hpos.le hm])) + (by rw [neg_div]; exact neg_nonpos.2 (one_div_pos.2 hpos).le) + +/-- The Pareto (Lomax) tail `(κ/(κ + x))^α` is the GPD tail with shape `1/α` and scale `κ/α`. -/ +lemma gpdTail_inv_shape {α κ : ℝ} (hα : 0 < α) (hκ : 0 < κ) (hx : 0 ≤ x) : + gpdTail α⁻¹ (κ / α) x = (κ / (κ + x)) ^ α := by + have hα0 : α ≠ 0 := hα.ne' + have hκ0 : κ ≠ 0 := hκ.ne' + have hbase : 1 + α⁻¹ * (x / (κ / α)) = (κ + x) / κ := by field_simp + rw [gpdTail_of_nonneg (inv_ne_zero hα.ne') hx (by rw [hbase]; positivity), hbase, + show -1 / α⁻¹ = -α by field_simp, rpow_neg (by positivity), ← inv_rpow (by positivity), + inv_div] + +/-! ### The domain of attraction of the GPD -/ + +/-- **MFE Exercise 5.16.** The GPD lies in the domain of attraction of the GEV of the same +shape: with `cₙ = β nᶻ` and `dₙ = β (nᶻ − 1)/ξ` (`z = ξ`; `dₙ = β log n` for `ξ = 0`), +`G_{ξ,β}(cₙ x + dₙ)ⁿ → H_ξ(x)` for every `x`. -/ +theorem tendsto_gpdCDF_pow (hβ : 0 < β) (ξ x : ℝ) : + Tendsto (fun n : ℕ ↦ gpdCDF ξ β (β * (gevNormScale ξ n * x + gevNormLoc ξ n)) ^ n) + atTop (𝓝 (gevCDF ξ x)) := by + have hF (y : ℝ) : 0 ≤ gpdCDF ξ β y := sub_nonneg.2 (gpdTail_le_one hβ) + have hβ0 : β ≠ 0 := hβ.ne' + -- the levels, divided by `β`, are the GEV max-stability levels + have hlev (n : ℕ) : β * (gevNormScale ξ n * x + gevNormLoc ξ n) / β = + gevNormScale ξ n * x + gevNormLoc ξ n := mul_div_cancel_left₀ _ hβ0 + by_cases hξ : ξ = 0 + · subst hξ + rw [gevCDF_zero, tendsto_pow_iff_tendsto_nat_mul_tail hF _ (exp_pos _), log_exp, neg_neg] + refine tendsto_const_nhds.congr' ?_ + filter_upwards [eventually_ge_atTop 1, + (tendsto_log_atTop.comp tendsto_natCast_atTop_atTop).eventually_ge_atTop (-x)] + with n hn hlog + have hnpos : (0 : ℝ) < n := Nat.cast_pos.2 hn + have hn0 : (n : ℝ) ≠ 0 := hnpos.ne' + have hlog' : 0 ≤ x + log n := by simp only [Function.comp_apply] at hlog; linarith + have hv : gevNormScale 0 n * x + gevNormLoc 0 n = x + log n := by + rw [gevNormScale, rpow_zero, one_mul, gevNormLoc, ite_eq_left rfl] + rw [gpdCDF, sub_sub_cancel, gpdTail_zero_shape (mul_nonneg hβ.le (hv ▸ hlog')), hlev, hv, + neg_add, exp_add, exp_neg (log n), exp_log hnpos] + field_simp + have hkey (n : ℕ) : 1 + ξ * (β * (gevNormScale ξ n * x + gevNormLoc ξ n) / β) = + gevNormScale ξ n * (1 + ξ * x) := by + rw [hlev, one_add_mul_gevNorm hξ] + by_cases hx : 0 < 1 + ξ * x + · -- inside the support: `n Gbar(uₙ) = (1 + ξx)^{−1/ξ}` as soon as `uₙ ≥ 0` + rw [gevCDF_of_pos hξ hx, tendsto_pow_iff_tendsto_nat_mul_tail hF _ (exp_pos _), log_exp, + neg_neg] + -- the normalized levels `vₙ = cₙ x + dₙ` are eventually nonnegative + have hev : ∀ᶠ n : ℕ in atTop, 0 ≤ gevNormScale ξ n * x + gevNormLoc ξ n := by + rcases lt_or_gt_of_ne hξ with hneg | hpos + · have ht : Tendsto (fun n : ℕ ↦ (n : ℝ) ^ ξ) atTop (𝓝 0) := by + have := (tendsto_rpow_neg_atTop (neg_pos.2 hneg)).comp tendsto_natCast_atTop_atTop + simpa only [neg_neg, Function.comp_def] using this + filter_upwards [eventually_ge_atTop 1, + ht.eventually (ge_mem_nhds (one_div_pos.2 hx))] with n hn hle + have hcn : gevNormScale ξ n = (n : ℝ) ^ ξ := by + rw [gevNormScale, max_eq_left (Nat.one_le_cast.2 hn)] + have h1 : gevNormScale ξ n * (1 + ξ * x) ≤ 1 := by + rw [hcn] + calc (n : ℝ) ^ ξ * (1 + ξ * x) ≤ 1 / (1 + ξ * x) * (1 + ξ * x) := + mul_le_mul_of_nonneg_right hle hx.le + _ = 1 := by field_simp + have h2 := one_add_mul_gevNorm hξ n x + by_contra! h3 + nlinarith [mul_pos_of_neg_of_neg hneg h3] + · have ht : Tendsto (fun n : ℕ ↦ (n : ℝ) ^ ξ) atTop atTop := + (tendsto_rpow_atTop hpos).comp tendsto_natCast_atTop_atTop + filter_upwards [eventually_ge_atTop 1, ht.eventually_ge_atTop (1 / (1 + ξ * x))] + with n hn hge + have hcn : gevNormScale ξ n = (n : ℝ) ^ ξ := by + rw [gevNormScale, max_eq_left (Nat.one_le_cast.2 hn)] + have h1 : 1 ≤ gevNormScale ξ n * (1 + ξ * x) := by + rw [hcn] + calc 1 = 1 / (1 + ξ * x) * (1 + ξ * x) := by field_simp + _ ≤ (n : ℝ) ^ ξ * (1 + ξ * x) := mul_le_mul_of_nonneg_right hge hx.le + have h2 := one_add_mul_gevNorm hξ n x + by_contra! h3 + nlinarith [mul_neg_of_pos_of_neg hpos h3] + refine tendsto_const_nhds.congr' ?_ + filter_upwards [eventually_ge_atTop 1, hev] with n hn hv + have hnpos : (0 : ℝ) < n := Nat.cast_pos.2 hn + have hn0 : (n : ℝ) ≠ 0 := hnpos.ne' + have hcn : gevNormScale ξ n = (n : ℝ) ^ ξ := by + rw [gevNormScale, max_eq_left (Nat.one_le_cast.2 hn)] + have hsupp : 0 ≤ 1 + ξ * (β * (gevNormScale ξ n * x + gevNormLoc ξ n) / β) := by + rw [hkey] + exact (mul_pos (gevNormScale_pos ξ n) hx).le + rw [gpdCDF, sub_sub_cancel, gpdTail_of_nonneg hξ (mul_nonneg hβ.le hv) hsupp, hkey, + mul_rpow (gevNormScale_pos ξ n).le hx.le, hcn, ← rpow_mul hnpos.le, + show ξ * (-1 / ξ) = -1 by field_simp, rpow_neg_one] + field_simp + · -- outside the support the powers are eventually constant + have hx' : 1 + ξ * x ≤ 0 := not_lt.1 hx + rw [gevCDF_of_nonpos hξ hx'] + refine tendsto_const_nhds.congr' ((eventually_ge_atTop 1).mono fun n hn ↦ ?_) + dsimp only + have hle : 1 + ξ * (β * (gevNormScale ξ n * x + gevNormLoc ξ n) / β) ≤ 0 := by + rw [hkey] + exact mul_nonpos_of_nonneg_of_nonpos (gevNormScale_pos ξ n).le hx' + rw [hlev] at hle + rcases lt_or_gt_of_ne hξ with hneg | hpos + · -- `ξ < 0`: beyond the right endpoint, `G = 1` + have hv : 0 ≤ gevNormScale ξ n * x + gevNormLoc ξ n := by + by_contra! h3 + nlinarith [mul_pos_of_neg_of_neg hneg h3] + have hle' : 1 + ξ * (β * (gevNormScale ξ n * x + gevNormLoc ξ n) / β) ≤ 0 := by + rwa [hlev] + rw [ite_eq_right (not_lt.2 hneg.le), gpdCDF, + gpdTail_of_endpoint_le hξ (mul_nonneg hβ.le hv) hle', sub_zero, one_pow] + · -- `ξ > 0`: below the left endpoint, `G = 0` + have hv : gevNormScale ξ n * x + gevNormLoc ξ n ≤ 0 := by + by_contra! h3 + nlinarith [mul_pos hpos h3] + rw [ite_eq_left hpos, gpdCDF, gpdTail_of_nonpos (mul_nonpos_of_nonneg_of_nonpos hβ.le hv), + sub_self, zero_pow (by omega)] + +/-- **The GPD is in the maximum domain of attraction of the GEV of the same shape** +(MFE Exercise 5.16). -/ +theorem gpdCDF_inMDA (hβ : 0 < β) (ξ : ℝ) : InMDA (gpdCDF ξ β) (gevCDF ξ) := + ⟨fun n ↦ β * gevNormScale ξ n, fun n ↦ β * gevNormLoc ξ n, + fun n ↦ mul_pos hβ (gevNormScale_pos ξ n), fun x ↦ by + simpa only [mul_add, mul_assoc] using tendsto_gpdCDF_pow hβ ξ x⟩ + +/-! ### Threshold stability -/ + +/-- **Threshold stability of the GPD**: for a threshold `u ≥ 0` inside the support and `x ≥ 0`, +`Gbar_{ξ,β}(u + x) = Gbar_{ξ,β}(u) · Gbar_{ξ,β+ξu}(x)`. -/ +theorem gpdTail_add (hβ : 0 < β) {u : ℝ} (hu : 0 ≤ u) (hsupp : 0 < 1 + ξ * (u / β)) + (hx : 0 ≤ x) : gpdTail ξ β (u + x) = gpdTail ξ β u * gpdTail ξ (β + ξ * u) x := by + have hβ0 : β ≠ 0 := hβ.ne' + have hβ' : 0 < β + ξ * u := by + have : β + ξ * u = β * (1 + ξ * (u / β)) := by field_simp + rw [this] + exact mul_pos hβ hsupp + have hβ'0 : β + ξ * u ≠ 0 := hβ'.ne' + by_cases hξ : ξ = 0 + · subst hξ + rw [gpdTail_zero_shape (add_nonneg hu hx), gpdTail_zero_shape hu, zero_mul, add_zero, + gpdTail_zero_shape hx, ← exp_add] + congr 1 + ring + · -- the support factorizes: `1 + ξ(u + x)/β = (1 + ξu/β)(1 + ξx/(β + ξu))` + have hfac : 1 + ξ * ((u + x) / β) = + (1 + ξ * (u / β)) * (1 + ξ * (x / (β + ξ * u))) := by + field_simp + ring + rw [gpdTail_of_nonneg hξ hu hsupp.le] + by_cases hB : 0 ≤ 1 + ξ * (x / (β + ξ * u)) + · rw [gpdTail_of_nonneg hξ (add_nonneg hu hx) (hfac ▸ mul_nonneg hsupp.le hB), hfac, + gpdTail_of_nonneg hξ hx hB, mul_rpow hsupp.le hB] + · push Not at hB + rw [gpdTail_of_endpoint_le hξ (add_nonneg hu hx) + (hfac ▸ (mul_neg_of_pos_of_neg hsupp hB).le), + gpdTail_of_endpoint_le hξ hx hB.le, mul_zero] + +/-- **The excess distribution of a GPD is a GPD**: over a threshold `u ≥ 0` inside the support, +`(G(u + x) − G(u))/(1 − G(u)) = G_{ξ,β+ξu}(x)` for `x ≥ 0`. -/ +theorem gpdCDF_excess (hβ : 0 < β) {u : ℝ} (hu : 0 ≤ u) (hsupp : 0 < 1 + ξ * (u / β)) + (hx : 0 ≤ x) : + (gpdCDF ξ β (u + x) - gpdCDF ξ β u) / (1 - gpdCDF ξ β u) = gpdCDF ξ (β + ξ * u) x := by + have hpos : 0 < gpdTail ξ β u := gpdTail_pos (by rwa [max_eq_left hu]) + have hpos0 : gpdTail ξ β u ≠ 0 := hpos.ne' + simp only [gpdCDF, sub_sub_sub_cancel_left, sub_sub_cancel] + rw [gpdTail_add hβ hu hsupp hx, ← mul_one_sub, mul_div_cancel_left₀ _ hpos0] + +/-! ### The GPD law -/ + +/-- The transform `e ↦ β(e^{ξe} − 1)/ξ` (`β e` for `ξ = 0`) that turns a standard exponential +variable into a generalized Pareto one. -/ +noncomputable def gpdOfExp (ξ β e : ℝ) : ℝ := + if ξ = 0 then β * e else β * (exp (ξ * e) - 1) / ξ + +/-- The **generalized Pareto law** `GPD(ξ, β)`: the law of `β(e^{ξE} − 1)/ξ` for a standard +exponential variable `E` (`β E` when `ξ = 0`). -/ +noncomputable def gpdMeasure (ξ β : ℝ) : Measure ℝ := + (expMeasure 1).map (gpdOfExp ξ β) + +lemma continuous_gpdOfExp : Continuous (gpdOfExp ξ β) := + continuous_if_const _ (fun _ ↦ by fun_prop) fun _ ↦ by fun_prop + +lemma gpdOfExp_zero : gpdOfExp ξ β 0 = 0 := by + unfold gpdOfExp + split_ifs <;> simp + +lemma strictMono_gpdOfExp (hβ : 0 < β) : StrictMono (gpdOfExp ξ β) := by + intro a b hab + unfold gpdOfExp + split_ifs with hξ + · exact mul_lt_mul_of_pos_left hab hβ + · have key (e : ℝ) : β * (exp (ξ * e) - 1) / ξ = β / ξ * (exp (ξ * e) - 1) := by ring + rw [key, key] + rcases lt_or_gt_of_ne hξ with hneg | hpos + · exact mul_lt_mul_of_neg_left + (sub_lt_sub_right (exp_lt_exp.2 (mul_lt_mul_of_neg_left hab hneg)) 1) + (div_neg_of_pos_of_neg hβ hneg) + · exact mul_lt_mul_of_pos_left + (sub_lt_sub_right (exp_lt_exp.2 (mul_lt_mul_of_pos_left hab hpos)) 1) + (div_pos hβ hpos) + +instance isProbabilityMeasure_gpdMeasure : IsProbabilityMeasure (gpdMeasure ξ β) := + haveI := isProbabilityMeasure_expMeasure (r := 1) one_pos + inferInstanceAs (IsProbabilityMeasure ((expMeasure 1).map (gpdOfExp ξ β))) + +/-- **The distribution function of the GPD law** is `G_{ξ,β}`. -/ +theorem cdf_gpdMeasure (hβ : 0 < β) (x : ℝ) : cdf (gpdMeasure ξ β) x = gpdCDF ξ β x := by + have := isProbabilityMeasure_expMeasure (r := 1) one_pos + have hβ0 : β ≠ 0 := hβ.ne' + have hmeas : Measurable (gpdOfExp ξ β) := continuous_gpdOfExp.measurable + have hsm : StrictMono (gpdOfExp ξ β) := strictMono_gpdOfExp hβ + have hexp (t : ℝ) (ht : 0 ≤ t) : (expMeasure 1).real (Iic t) = 1 - exp (-t) := by + rw [← cdf_eq_real, cdf_expMeasure_eq one_pos, ite_eq_left ht, one_mul] + rw [cdf_eq_real, gpdMeasure, map_measureReal_apply hmeas measurableSet_Iic, gpdCDF] + rcases lt_or_ge x 0 with hx | hx + · -- below the support + rw [gpdTail_of_nonpos hx.le, sub_self] + have hsub : gpdOfExp ξ β ⁻¹' Iic x ⊆ Iic 0 := fun e he ↦ + (hsm.lt_iff_lt.1 (by rw [gpdOfExp_zero]; exact lt_of_le_of_lt he hx)).le + refine le_antisymm ?_ measureReal_nonneg + calc (expMeasure 1).real (gpdOfExp ξ β ⁻¹' Iic x) ≤ (expMeasure 1).real (Iic 0) := + measureReal_mono hsub + _ = 0 := by rw [hexp 0 le_rfl, neg_zero, exp_zero, sub_self] + by_cases hend : ξ ≠ 0 ∧ 1 + ξ * (x / β) ≤ 0 + · -- beyond the right endpoint every value of the transform lies below `x` + obtain ⟨hξ, hle⟩ := hend + have hneg : ξ < 0 := by + by_contra! h + have : 0 ≤ ξ * (x / β) := mul_nonneg h (div_nonneg hx hβ.le) + linarith + have hx' : -β / ξ ≤ x := by + rw [div_le_iff_of_neg hneg] + have h1 : x * ξ = β * (ξ * (x / β)) := by field_simp + nlinarith [mul_le_mul_of_nonneg_left hle hβ.le] + have hall : gpdOfExp ξ β ⁻¹' Iic x = univ := by + ext e + simp only [mem_preimage, mem_Iic, mem_univ, iff_true] + rw [gpdOfExp, ite_eq_right hξ] + have h2 : β * exp (ξ * e) / ξ < 0 := div_neg_of_pos_of_neg (mul_pos hβ (exp_pos _)) hneg + calc β * (exp (ξ * e) - 1) / ξ = β * exp (ξ * e) / ξ + -β / ξ := by ring + _ ≤ x := by linarith + rw [hall, probReal_univ, gpdTail_of_endpoint_le hξ hx hle, sub_zero] + -- inside the support the preimage is `Iic t` with `t = −log Gbar(x)` + push Not at hend + have hsupp' : 0 < 1 + ξ * (max x 0 / β) := by + rw [max_eq_left hx] + by_cases hξ : ξ = 0 + · simp [hξ] + · exact hend hξ + have hpos : 0 < gpdTail ξ β x := gpdTail_pos hsupp' + obtain ⟨t, ht⟩ : ∃ t, t = -log (gpdTail ξ β x) := ⟨_, rfl⟩ + have ht0 : 0 ≤ t := ht ▸ neg_nonneg.2 (log_nonpos hpos.le (gpdTail_le_one hβ)) + have hinv : gpdOfExp ξ β t = x := by + by_cases hξ : ξ = 0 + · subst hξ + rw [ht, gpdTail_zero_shape hx, log_exp, neg_neg, gpdOfExp, ite_eq_left rfl] + field_simp + · have hs := hend hξ + rw [ht, gpdTail_of_nonneg hξ hx hs.le, log_rpow hs, gpdOfExp, ite_eq_right hξ, + show ξ * -(-1 / ξ * log (1 + ξ * (x / β))) = log (1 + ξ * (x / β)) by field_simp, + exp_log hs] + field_simp + ring + have hpre : gpdOfExp ξ β ⁻¹' Iic x = Iic t := by + ext e + simp only [mem_preimage, mem_Iic] + rw [← hinv, hsm.le_iff_le] + rw [hpre, hexp t ht0, ht, neg_neg, exp_log hpos] + +/-- **The quantile function of the GPD law** is the transform of the exponential quantile: +`q(p) = gpdOfExp ξ β (−log(1 − p))`. -/ +theorem quantile_gpdMeasure (hβ : 0 < β) {p : ℝ} (hp : p ∈ Ioo 0 1) : + quantile (gpdMeasure ξ β) p = gpdOfExp ξ β (-log (1 - p)) := by + have := isProbabilityMeasure_expMeasure (r := 1) one_pos + rw [gpdMeasure, quantile_map (strictMono_gpdOfExp hβ).monotone + continuous_gpdOfExp.lowerSemicontinuous hp, quantile_expMeasure one_pos hp, div_one] + +/-- **Value-at-risk of a GPD loss** (`ξ ≠ 0`): `q(p) = β((1 − p)^{−ξ} − 1)/ξ`. -/ +theorem quantile_gpdMeasure_of_ne_zero (hβ : 0 < β) (hξ : ξ ≠ 0) {p : ℝ} (hp : p ∈ Ioo 0 1) : + quantile (gpdMeasure ξ β) p = β * ((1 - p) ^ (-ξ) - 1) / ξ := by + rw [quantile_gpdMeasure hβ hp, gpdOfExp, ite_eq_right hξ, rpow_def_of_pos (sub_pos.2 hp.2)] + ring_nf + +/-- **Value-at-risk of an exponential GPD loss** (`ξ = 0`): `q(p) = −β log(1 − p)`. -/ +theorem quantile_gpdMeasure_zero (hβ : 0 < β) {p : ℝ} (hp : p ∈ Ioo 0 1) : + quantile (gpdMeasure 0 β) p = -(β * log (1 - p)) := by + rw [quantile_gpdMeasure hβ hp, gpdOfExp, ite_eq_left rfl, mul_neg] + +/-! ### Tail averages, the mean, and the mean excess function -/ + +/-- **Tail integral of the GPD quantile.** For `ξ < 1` and `α < 1`, +`∫_α^1 q(u) du = (1 − α)(q(α) + β)/(1 − ξ)`, where `q(u) = gpdOfExp ξ β (−log(1 − u))`. -/ +theorem setIntegral_gpdOfExp_Ioo (hβ : 0 < β) (hξ1 : ξ < 1) {α : ℝ} (hα1 : α < 1) : + ∫ u in Ioo α 1, gpdOfExp ξ β (-log (1 - u)) = + (1 - α) * (gpdOfExp ξ β (-log (1 - α)) + β) / (1 - ξ) := by + have hs : 0 < 1 - α := sub_pos.2 hα1 + have hs0 : 1 - α ≠ 0 := hs.ne' + have h1ξ : 1 - ξ ≠ 0 := (sub_pos.2 hξ1).ne' + have hβ0 : β ≠ 0 := hβ.ne' + -- move to an interval integral and substitute `t = 1 − u` + rw [← integral_Ioc_eq_integral_Ioo, ← intervalIntegral.integral_of_le hα1.le, + intervalIntegral.integral_comp_sub_left (fun t ↦ gpdOfExp ξ β (-log t)) 1, sub_self] + by_cases hξ : ξ = 0 + · subst hξ + simp only [gpdOfExp, ite_true] + rw [intervalIntegral.integral_const_mul, intervalIntegral.integral_neg, integral_log] + simp only [log_zero, mul_zero, sub_zero, add_zero] + ring + · -- on `(0, 1 − α]` the integrand is `(β/ξ)(t^{−ξ} − 1)` + have hcongr : ∫ t in (0 : ℝ)..1 - α, gpdOfExp ξ β (-log t) = + ∫ t in (0 : ℝ)..1 - α, β / ξ * (t ^ (-ξ) - 1) := by + refine intervalIntegral.integral_congr_ae (ae_of_all _ fun t ht ↦ ?_) + rw [uIoc_of_le hs.le] at ht + rw [gpdOfExp, ite_eq_right hξ, rpow_def_of_pos ht.1] + ring_nf + have hint : IntervalIntegrable (fun t : ℝ ↦ t ^ (-ξ)) volume 0 (1 - α) := + intervalIntegral.intervalIntegrable_rpow' (by linarith) + have h1ξ' : -ξ + 1 ≠ 0 := (by linarith : (0 : ℝ) < -ξ + 1).ne' + rw [hcongr, intervalIntegral.integral_const_mul, intervalIntegral.integral_sub hint + intervalIntegrable_const, integral_rpow (Or.inl (by linarith)), + intervalIntegral.integral_const, zero_rpow h1ξ', rpow_add_one hs0, smul_eq_mul, mul_one, + sub_zero, sub_zero, gpdOfExp, ite_eq_right hξ, + show ξ * -log (1 - α) = log (1 - α) * -ξ by ring, ← rpow_def_of_pos hs] + field_simp + ring + +/-- **Expected shortfall of a GPD loss** (MFE eq. (5.19) at threshold `0`): for `ξ < 1`, the +average of the quantile function over `(α, 1)` is `(q(α) + β)/(1 − ξ)`, i.e. +`ES_α = (VaR_α + β)/(1 − ξ)`. -/ +theorem setIntegral_quantile_gpdMeasure (hβ : 0 < β) (hξ1 : ξ < 1) {α : ℝ} + (hα : α ∈ Ioo 0 1) : + (1 - α)⁻¹ * ∫ u in Ioo α 1, quantile (gpdMeasure ξ β) u = + (quantile (gpdMeasure ξ β) α + β) / (1 - ξ) := by + have hs0 : 1 - α ≠ 0 := (sub_pos.2 hα.2).ne' + rw [setIntegral_congr_fun measurableSet_Ioo fun u hu ↦ + quantile_gpdMeasure hβ ⟨hα.1.trans hu.1, hu.2⟩, + setIntegral_gpdOfExp_Ioo hβ hξ1 hα.2, quantile_gpdMeasure hβ hα] + field_simp + +/-- **The mean of the GPD** is `β/(1 − ξ)` for `ξ < 1`. -/ +theorem integral_id_gpdMeasure (hβ : 0 < β) (hξ1 : ξ < 1) : + ∫ x, x ∂(gpdMeasure ξ β) = β / (1 - ξ) := by + rw [integral_eq_setIntegral_quantile (f := fun x ↦ x) aestronglyMeasurable_id, + setIntegral_congr_fun measurableSet_Ioo fun u hu ↦ quantile_gpdMeasure hβ hu, + setIntegral_gpdOfExp_Ioo hβ hξ1 one_pos, sub_zero, log_one, neg_zero, gpdOfExp_zero, + one_mul, zero_add] + +/-- **Excesses of the GPD law are GPD**: for a threshold `u ≥ 0` inside the support, the law of +`X − u` given `X > u` is `GPD(ξ, β + ξu)`. -/ +theorem map_cond_gpdMeasure (hβ : 0 < β) {u : ℝ} (hu : 0 ≤ u) (hsupp : 0 < 1 + ξ * (u / β)) : + ((gpdMeasure ξ β)[|Ioi u]).map (· - u) = gpdMeasure ξ (β + ξ * u) := by + have hβ' : 0 < β + ξ * u := by + have : β + ξ * u = β * (1 + ξ * (u / β)) := by field_simp + rw [this] + exact mul_pos hβ hsupp + have htail : 0 < gpdTail ξ β u := gpdTail_pos (by rwa [max_eq_left hu]) + have hIoi : gpdMeasure ξ β (Ioi u) = ENNReal.ofReal (gpdTail ξ β u) := by + rw [← measure_cdf (gpdMeasure ξ β), + StieltjesFunction.measure_Ioi _ (tendsto_cdf_atTop (gpdMeasure ξ β)), + cdf_gpdMeasure hβ, gpdCDF, sub_sub_cancel] + have hne : gpdMeasure ξ β (Ioi u) ≠ 0 := by + rw [hIoi] + exact (ENNReal.ofReal_pos.2 htail).ne' + have : IsProbabilityMeasure ((gpdMeasure ξ β)[|Ioi u]) := cond_isProbabilityMeasure hne + have hmeas : Measurable fun x : ℝ ↦ x - u := measurable_sub_const u + refine Measure.ext_of_Iic _ _ fun a ↦ ?_ + have hpre : Ioi u ∩ (fun x ↦ x - u) ⁻¹' Iic a = Ioc u (a + u) := by + ext y + simp + have hIoc : gpdMeasure ξ β (Ioc u (a + u)) = + ENNReal.ofReal (gpdCDF ξ β (a + u) - gpdCDF ξ β u) := by + rw [← measure_cdf (gpdMeasure ξ β), StieltjesFunction.measure_Ioc, cdf_gpdMeasure hβ, + cdf_gpdMeasure hβ] + rw [Measure.map_apply hmeas measurableSet_Iic, cond_apply measurableSet_Ioi, hpre, hIoc, hIoi, + ← ofReal_cdf, cdf_gpdMeasure hβ'] + rcases lt_or_ge a 0 with ha | ha + · -- a negative excess level has no mass on either side + have hmono : gpdCDF ξ β (a + u) ≤ gpdCDF ξ β u := by + rw [← cdf_gpdMeasure hβ, ← cdf_gpdMeasure hβ] + exact monotone_cdf _ (by linarith) + rw [ENNReal.ofReal_of_nonpos (sub_nonpos.2 hmono), mul_zero, gpdCDF, + gpdTail_of_nonpos ha.le, sub_self, ENNReal.ofReal_zero] + · rw [add_comm a u, show gpdCDF ξ β (u + a) - gpdCDF ξ β u = + gpdTail ξ β u * gpdCDF ξ (β + ξ * u) a by + rw [gpdCDF, gpdCDF, gpdCDF, gpdTail_add hβ hu hsupp ha] + ring, + ENNReal.ofReal_mul htail.le, ← mul_assoc, + ENNReal.inv_mul_cancel (ENNReal.ofReal_pos.2 htail).ne' ENNReal.ofReal_ne_top, one_mul] + +/-- **The mean excess function of the GPD is linear** (MFE Exercise 5.19(b)): for `ξ < 1` and a +threshold `u ≥ 0` inside the support, `e(u) = E[X − u | X > u] = (β + ξu)/(1 − ξ)`. -/ +theorem integral_sub_cond_gpdMeasure (hβ : 0 < β) (hξ1 : ξ < 1) {u : ℝ} (hu : 0 ≤ u) + (hsupp : 0 < 1 + ξ * (u / β)) : + ∫ x, (x - u) ∂((gpdMeasure ξ β)[|Ioi u]) = (β + ξ * u) / (1 - ξ) := by + have hβ' : 0 < β + ξ * u := by + have : β + ξ * u = β * (1 + ξ * (u / β)) := by field_simp + rw [this] + exact mul_pos hβ hsupp + have hmap := integral_map (μ := (gpdMeasure ξ β)[|Ioi u]) (φ := fun x ↦ x - u) (f := id) + (measurable_sub_const u).aemeasurable aestronglyMeasurable_id + rw [map_cond_gpdMeasure hβ hu hsupp] at hmap + simp only [id] at hmap + rw [← hmap, integral_id_gpdMeasure hβ' hξ1] + +end MathFin diff --git a/LeanPool/MathFin/Probability/Laws/Quantile.lean b/LeanPool/MathFin/Probability/Laws/Quantile.lean new file mode 100644 index 0000000000..c296dfb76c --- /dev/null +++ b/LeanPool/MathFin/Probability/Laws/Quantile.lean @@ -0,0 +1,284 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Distributions.Exponential +public import Mathlib.Probability.HasLaw + +/-! +# The quantile function of a law on `ℝ` + +The **quantile function** of a probability measure `μ` on `ℝ` is the generalized inverse of its +CDF `F = cdf μ`: + + `quantile μ p = inf {x | p ≤ F x}`, `p ∈ (0, 1)`. + +Mathlib has the CDF (`ProbabilityTheory.cdf`) but no inverse. This file supplies it, together +with the facts that make it the right object. + +* **The Galois connection.** For `p ∈ (0, 1)`, `quantile μ p ≤ x ↔ p ≤ F x` (`quantile_le_iff`). + Everything below is read off this one equivalence. It needs neither continuity nor strict + monotonicity of `F`, so atoms and flat stretches of `F` are handled without case analysis. Its + contrapositive `x < quantile μ p ↔ F x < p` (`lt_quantile_iff`) is the threshold form that the + bisection method (`Probability/Analysis/Bisection.lean`) converges under. +* **The quantile transform.** Under the uniform law on `(0, 1)`, `quantile μ` has law `μ` + (`hasLaw_quantile`). So every law on `ℝ` is the image of the uniform law under a monotone map, + and expectations are integrals over `(0, 1)`: `∫ f dμ = ∫₀¹ f (quantile μ p) dp` + (`integral_eq_setIntegral_quantile`). +* **The probability integral transform.** If `F` is continuous, `F ∘ quantile μ` is the identity + on `(0, 1)` (`cdf_quantile`), so `F(X)` is uniform whenever `X` has law `μ` (`hasLaw_cdf`). +* **Equivariance.** Quantiles commute with monotone lower-semicontinuous maps, in particular with + continuous increasing ones: `quantile (μ.map h) p = h (quantile μ p)` (`quantile_map`). + +In risk management `quantile μ α` is the value-at-risk at level `α` of a loss with law `μ` +(`Risk/ValueAtRisk.lean`). + +## Main definitions + +* `quantile`: the generalized inverse `quantile μ p = inf {x | p ≤ cdf μ x}` of the CDF of a law + `μ` on `ℝ`, meaningful for `p ∈ (0, 1)`. + +## Main results + +* `quantile_le_iff`, `lt_quantile_iff`: the Galois connection with the CDF. +* `le_cdf_quantile`: `p ≤ F (quantile μ p)`, from right-continuity of `F`. +* `monotoneOn_quantile`, `aemeasurable_quantile`: monotone, hence measurable, on `(0, 1)`. +* `quantile_dirac`: a point mass is its own quantile. +* `quantile_eq_iff`: a quantile is characterized by the CDF on both sides of it. +* `quantile_expMeasure`: the exponential quantile `−log(1 − p)/r`. +* `uniformIoo_Iic`: the uniform law on `(0, 1)` gives `(-∞, c]` mass `c`. +* `hasLaw_quantile`: the quantile transform. +* `integral_eq_setIntegral_quantile`: expectations as integrals of the quantile function. +* `continuous_cdf`: a law without atoms has a continuous CDF. +* `cdf_quantile`, `hasLaw_cdf`: the probability integral transform. +* `quantile_cdf`: `quantile μ (F x) = x` when `F` is strictly increasing. +* `quantile_map`: equivariance under monotone lower-semicontinuous maps. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Appendix A.1.2; Proposition 7.2; Proposition 7.2 / Appendix A.1.2; + Proposition A.3 +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 2.21; Ex. 2.6; Ex. 7.2 + +## Tags + +generalized inverse CDF, quantile function, probability integral transform, quantile transform, +value-at-risk, Galois connection, MSC 62G30, MSC 60E05, MSC 91G70 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set Filter Topology + +/-- The **quantile function** of a law `μ` on `ℝ`: the generalized inverse of its CDF, +`quantile μ p = inf {x | p ≤ cdf μ x}`. Its values are meaningful for `p ∈ (0, 1)`, where the set +is nonempty and bounded below. -/ +noncomputable def quantile (μ : Measure ℝ) (p : ℝ) : ℝ := + sInf {x | p ≤ cdf μ x} + +/-- The uniform law on `(0, 1)` is a probability measure. -/ +instance isProbabilityMeasure_volume_restrict_Ioo_zero_one : + IsProbabilityMeasure (volume.restrict (Ioo (0 : ℝ) 1)) := + ⟨by simp⟩ + +variable {μ : Measure ℝ} {p x : ℝ} + +/-! ### The Galois connection with the CDF -/ + +/-- For `p < 1` some `x` has `p ≤ F x`, because `F → 1` at `+∞`. -/ +lemma nonempty_setOf_le_cdf (hp : p < 1) : {x | p ≤ cdf μ x}.Nonempty := + (tendsto_cdf_atTop μ |>.eventually_const_lt hp).exists.imp fun _ ↦ le_of_lt + +/-- For `0 < p` the set `{x | p ≤ F x}` is bounded below, because `F → 0` at `-∞`. -/ +lemma bddBelow_setOf_le_cdf (hp : 0 < p) : BddBelow {x | p ≤ cdf μ x} := by + obtain ⟨b, hb⟩ := (tendsto_cdf_atBot μ |>.eventually_lt_const hp).exists + exact ⟨b, fun x hx ↦ le_of_not_gt fun hxb ↦ (hx.trans (monotone_cdf μ hxb.le)).not_gt hb⟩ + +/-- Right-continuity of `F` keeps the infimum inside the set: `p ≤ F (quantile μ p)`. -/ +lemma le_cdf_quantile (hp : p ∈ Ioo 0 1) : p ≤ cdf μ (quantile μ p) := by + refine ge_of_tendsto (((cdf μ).right_continuous _).mono Ioi_subset_Ici_self) ?_ + filter_upwards [self_mem_nhdsWithin] with y hy + obtain ⟨x, hx, hxy⟩ := exists_lt_of_csInf_lt (nonempty_setOf_le_cdf hp.2) hy + exact hx.trans (monotone_cdf μ hxy.le) + +/-- **The Galois connection** between the quantile function and the CDF: for `p ∈ (0, 1)`, +`quantile μ p ≤ x ↔ p ≤ F x`. -/ +theorem quantile_le_iff (hp : p ∈ Ioo 0 1) : quantile μ p ≤ x ↔ p ≤ cdf μ x := + ⟨fun h ↦ (le_cdf_quantile hp).trans (monotone_cdf μ h), + fun h ↦ csInf_le (bddBelow_setOf_le_cdf hp.1) h⟩ + +/-- The Galois connection read contrapositively: `x < quantile μ p ↔ F x < p`. The quantile is +the threshold of the CDF against `p`. -/ +theorem lt_quantile_iff (hp : p ∈ Ioo 0 1) : x < quantile μ p ↔ cdf μ x < p := by + simpa only [not_le] using (quantile_le_iff hp).not + +/-- The quantile function is monotone on `(0, 1)`. -/ +lemma monotoneOn_quantile : MonotoneOn (quantile μ) (Ioo 0 1) := fun _ hp _ hq hpq ↦ + (quantile_le_iff hp).2 (hpq.trans (le_cdf_quantile hq)) + +/-- Monotone on `(0, 1)`, hence measurable for the uniform law there. -/ +lemma aemeasurable_quantile : AEMeasurable (quantile μ) (volume.restrict (Ioo 0 1)) := + aemeasurable_restrict_of_monotoneOn measurableSet_Ioo monotoneOn_quantile + +/-- A point mass sits at its own quantile at every level. -/ +theorem quantile_dirac (a : ℝ) (hp : p ∈ Ioo 0 1) : quantile (Measure.dirac a) p = a := by + refine eq_of_forall_ge_iff fun x ↦ ?_ + rw [quantile_le_iff hp, cdf_eq_real] + by_cases hax : a ≤ x + · rw [measureReal_def, Measure.dirac_apply_of_mem (mem_Iic.2 hax)] + simpa [hax] using hp.2.le + · rw [measureReal_def, Measure.dirac_apply' a measurableSet_Iic, + indicator_of_notMem (by simpa using hax)] + simpa [hax] using hp.1 + +/-- A level's quantile is pinned down by the CDF: `quantile μ p = a` exactly when `p ≤ F(a)` and +`F(x) < p` for every `x < a`. -/ +theorem quantile_eq_iff (hp : p ∈ Ioo 0 1) {a : ℝ} : + quantile μ p = a ↔ p ≤ cdf μ a ∧ ∀ x < a, cdf μ x < p := by + refine ⟨?_, fun ⟨ha, hlt⟩ ↦ le_antisymm ((quantile_le_iff hp).2 ha) + (le_of_forall_lt fun x hx ↦ (lt_quantile_iff hp).2 (hlt x hx))⟩ + rintro rfl + exact ⟨le_cdf_quantile hp, fun _ hx ↦ (lt_quantile_iff hp).1 hx⟩ + +/-- The quantile of the exponential law with rate `r`: `quantile (Exp r) p = −log(1 − p)/r`. -/ +theorem quantile_expMeasure {r : ℝ} (hr : 0 < r) (hp : p ∈ Ioo 0 1) : + quantile (expMeasure r) p = -Real.log (1 - p) / r := by + have h1p : 0 < 1 - p := sub_pos.2 hp.2 + have hlog : Real.log (1 - p) < 0 := Real.log_neg h1p (by linarith [hp.1]) + refine eq_of_forall_ge_iff fun y ↦ ?_ + rw [quantile_le_iff hp, cdf_expMeasure_eq hr] + split_ifs with hy + · rw [le_sub_comm, ← Real.le_log_iff_exp_le h1p, neg_le, div_le_iff₀ hr, mul_comm] + · exact iff_of_false (not_le.2 hp.1) + (not_le.2 ((not_le.1 hy).trans_le (div_nonneg (by linarith) hr.le))) + +/-! ### The quantile transform -/ + +/-- The uniform law on `(0, 1)` gives `(-∞, c]` mass `c` for `c ∈ [0, 1]`. -/ +theorem uniformIoo_Iic {c : ℝ} (h0 : 0 ≤ c) (h1 : c ≤ 1) : + volume.restrict (Ioo (0 : ℝ) 1) (Iic c) = ENNReal.ofReal c := by + rw [Measure.restrict_apply measurableSet_Iic] + rcases h1.lt_or_eq with h1 | rfl + · rw [show Iic c ∩ Ioo 0 1 = Ioc 0 c by + ext p; exact ⟨fun h ↦ ⟨h.2.1, h.1⟩, fun h ↦ ⟨h.2, h.1, h.2.trans_lt h1⟩⟩] + simp + · rw [inter_eq_right.2 (Ioo_subset_Ioc_self.trans Ioc_subset_Iic_self)] + simp + +/-- **The quantile transform.** Under the uniform law on `(0, 1)`, the quantile function of a +probability measure `μ` has law `μ`: every law on `ℝ` is the image of the uniform law under its +own quantile function. -/ +theorem hasLaw_quantile (μ : Measure ℝ) [IsProbabilityMeasure μ] : + HasLaw (quantile μ) μ (volume.restrict (Ioo 0 1)) where + aemeasurable := aemeasurable_quantile + map_eq := by + refine Measure.ext_of_Iic _ _ fun a ↦ ?_ + have hset : quantile μ ⁻¹' Iic a ∩ Ioo 0 1 = Iic (cdf μ a) ∩ Ioo 0 1 := by + ext p + exact ⟨fun h ↦ ⟨(quantile_le_iff h.2).1 h.1, h.2⟩, + fun h ↦ ⟨(quantile_le_iff h.2).2 h.1, h.2⟩⟩ + rw [Measure.map_apply_of_aemeasurable aemeasurable_quantile measurableSet_Iic, + Measure.restrict_apply' measurableSet_Ioo, hset, ← Measure.restrict_apply measurableSet_Iic, + uniformIoo_Iic (cdf_nonneg μ a) (cdf_le_one μ a), ofReal_cdf] + +/-- **Expectations as integrals of the quantile function**: `∫ f dμ = ∫₀¹ f (quantile μ p) dp`. -/ +theorem integral_eq_setIntegral_quantile [IsProbabilityMeasure μ] {E : Type*} + [NormedAddCommGroup E] [NormedSpace ℝ E] {f : ℝ → E} (hf : AEStronglyMeasurable f μ) : + ∫ x, f x ∂μ = ∫ p in Ioo 0 1, f (quantile μ p) := + ((hasLaw_quantile μ).integral_comp hf).symm + +/-- Integrability transfers along the quantile transform. -/ +theorem integrableOn_comp_quantile_iff [IsProbabilityMeasure μ] {E : Type*} + [NormedAddCommGroup E] {f : ℝ → E} (hf : AEStronglyMeasurable f μ) : + IntegrableOn (fun p ↦ f (quantile μ p)) (Ioo 0 1) ↔ Integrable f μ := by + have h := integrable_map_measure (by rwa [(hasLaw_quantile μ).map_eq]) aemeasurable_quantile + rw [(hasLaw_quantile μ).map_eq] at h + exact h.symm + +/-! ### Continuous CDFs and the probability integral transform -/ + +/-- A law without atoms has a continuous CDF: the jump of `F` at `x` is the mass of `{x}`. -/ +theorem continuous_cdf [IsProbabilityMeasure μ] [NullSingletonClass μ] : Continuous (cdf μ) := by + refine continuous_iff_continuousAt.2 fun x ↦ continuousAt_iff_continuous_left_right.2 + ⟨?_, (cdf μ).right_continuous x⟩ + rw [continuousWithinAt_Iio_iff_Iic.symm, + (monotone_cdf μ).continuousWithinAt_Iio_iff_leftLim_eq] + have hjump := (cdf μ).measure_singleton x + rw [measure_cdf, measure_singleton, eq_comm, ENNReal.ofReal_eq_zero, sub_nonpos] at hjump + exact le_antisymm ((monotone_cdf μ).leftLim_le le_rfl) hjump + +/-- If `F` is continuous, `F ∘ quantile μ` is the identity on `(0, 1)`. -/ +theorem cdf_quantile (hF : Continuous (cdf μ)) (hp : p ∈ Ioo 0 1) : + cdf μ (quantile μ p) = p := by + refine le_antisymm (le_of_tendsto ((hF.tendsto _).mono_left + (nhdsWithin_le_nhds (s := Iio (quantile μ p)))) ?_) (le_cdf_quantile hp) + filter_upwards [self_mem_nhdsWithin] with y hy + exact ((lt_quantile_iff hp).1 hy).le + +/-- **The probability integral transform**: if `X` has law `μ` and `F` is continuous, then `F(X)` +is uniform on `(0, 1)`. -/ +theorem hasLaw_cdf {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} {X : Ω → ℝ} + [IsProbabilityMeasure μ] (hX : HasLaw X μ P) (hF : Continuous (cdf μ)) : + HasLaw (fun ω ↦ cdf μ (X ω)) (volume.restrict (Ioo 0 1)) P := + (hasLaw_quantile μ).comp_of_hasLaw_comp (monotone_cdf μ).measurable.aemeasurable hX <| + HasLaw.id.congr <| (ae_restrict_mem measurableSet_Ioo).mono fun _ hp ↦ cdf_quantile hF hp + +/-- If `F` is strictly increasing, `quantile μ ∘ F` is the identity where `F ∈ (0, 1)`. -/ +theorem quantile_cdf (hF : StrictMono (cdf μ)) (hx : cdf μ x ∈ Ioo 0 1) : + quantile μ (cdf μ x) = x := + eq_of_forall_ge_iff fun _ ↦ (quantile_le_iff hx).trans hF.le_iff_le + +/-! ### Equivariance -/ + +/-- **Quantiles commute with monotone lower-semicontinuous maps**: +`quantile (μ.map h) p = h (quantile μ p)`. Lower semicontinuity makes `{h ≤ y}` closed, which is +what keeps the lower sets of `h ∘ quantile` and of the image quantile aligned; continuous +increasing maps are the main instance (`quantile_map_of_strictMono`). -/ +theorem quantile_map [IsProbabilityMeasure μ] {h : ℝ → ℝ} (hmono : Monotone h) + (hlsc : LowerSemicontinuous h) (hp : p ∈ Ioo 0 1) : + quantile (μ.map h) p = h (quantile μ p) := by + have hmeas : Measurable h := hmono.measurable + refine eq_of_forall_ge_iff fun y ↦ ?_ + rw [quantile_le_iff hp, cdf_eq_real, map_measureReal_apply hmeas measurableSet_Iic] + constructor + · intro hpy + by_contra! hlt + -- the sublevel set `{h ≤ y}` is closed and lies strictly below `quantile μ p` + set S := h ⁻¹' Iic y + have hS : S ⊆ Iio (quantile μ p) := fun z hz ↦ + lt_of_not_ge fun hqz ↦ (hlt.trans_le (hmono hqz)).not_ge hz + rcases S.eq_empty_or_nonempty with hS0 | hSne + · rw [hS0, measureReal_empty] at hpy + exact hp.1.not_ge hpy + have hbdd : BddAbove S := ⟨quantile μ p, fun z hz ↦ (hS hz).le⟩ + have hmem : sSup S ∈ S := (hlsc.isClosed_preimage y).csSup_mem hSne hbdd + have hcdf : cdf μ (sSup S) < p := (lt_quantile_iff hp).1 (hS hmem) + rw [cdf_eq_real] at hcdf + exact (hpy.trans (measureReal_mono fun z hz ↦ le_csSup hbdd hz)).not_gt hcdf + · intro hqy + calc p ≤ cdf μ (quantile μ p) := le_cdf_quantile hp + _ = μ.real (Iic (quantile μ p)) := cdf_eq_real μ _ + _ ≤ μ.real (h ⁻¹' Iic y) := measureReal_mono fun z hz ↦ (hmono hz).trans hqy + +/-- Quantiles commute with continuous strictly increasing maps (MFE Exercise 2.21). -/ +theorem quantile_map_of_strictMono [IsProbabilityMeasure μ] {h : ℝ → ℝ} (hmono : StrictMono h) + (hcont : Continuous h) (hp : p ∈ Ioo 0 1) : + quantile (μ.map h) p = h (quantile μ p) := + quantile_map hmono.monotone hcont.lowerSemicontinuous hp + +/-- Quantiles are affine-equivariant: `quantile (μ.map (a · + b)) p = a · quantile μ p + b` for +`a > 0`. -/ +theorem quantile_map_affine [IsProbabilityMeasure μ] {a b : ℝ} (ha : 0 < a) (hp : p ∈ Ioo 0 1) : + quantile (μ.map fun x ↦ a * x + b) p = a * quantile μ p + b := + quantile_map_of_strictMono (fun _ _ hxy ↦ by gcongr) (by fun_prop) hp + +end MathFin diff --git a/LeanPool/MathFin/Probability/Laws/QuantileConvergence.lean b/LeanPool/MathFin/Probability/Laws/QuantileConvergence.lean new file mode 100644 index 0000000000..8bf7e0acb8 --- /dev/null +++ b/LeanPool/MathFin/Probability/Laws/QuantileConvergence.lean @@ -0,0 +1,181 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Laws.Quantile +public import Mathlib.Probability.StrongLaw + +/-! +# Convergence of quantiles and of empirical distribution functions + +Two limit theorems for the quantile layer of `Probability/Laws/Quantile.lean`. + +* **Quantiles are continuous along almost-sure convergence.** If `X n → Y` almost surely and the + `α`-quantile `q` of `Y` is *strict*, meaning `α < P(Y ≤ x)` for every `x > q`, then the + `α`-quantiles of the `X n` converge to `q` (`tendsto_quantile_of_tendsto_ae`). The half below `q` + needs nothing: there `P(Y ≤ x) < α` by the Galois connection, and continuity of `P` along the + decreasing events `⋃_{n ≥ N} {X n ≤ x}` pushes the strict inequality onto the `X n`. The half + above `q` runs the same argument with the increasing events `⋂_{n ≥ N} {X n ≤ x}`, and it is + where strictness enters: across a flat stretch of the limit CDF at level `α` the quantiles of the + `X n` are free to oscillate. +* **The strong law for the empirical CDF.** For pairwise independent, identically distributed + `εᵢ` whose law has a continuous CDF `G`, almost surely the empirical CDF + `x ↦ (1/m) #{i < m | εᵢ ≤ x}` converges to `G` at every point at once + (`tendsto_empiricalCDF_ae`). Etemadi's strong law (`ProbabilityTheory.strong_law_ae`) gives the + convergence at each rational `x`; the empirical CDF is monotone in `x` and `G` is continuous, so + every real point is squeezed between rational ones. Because the almost-sure event does not + depend on `x`, the empirical CDF may be evaluated at a *random* point. This is the conditional + law of large numbers behind the large-portfolio limit of `Risk/Credit/VasicekIRB.lean`. + +## Main definitions + +* `empiricalCDF`: the empirical CDF `x ↦ (1/m) #{i < m | ε i ω ≤ x}` of the first `m` + observations. + +## Main results + +* `cdf_map_eq_measureReal`: the CDF of a pushforward law. +* `tendsto_quantile_of_tendsto_ae`: quantiles converge along almost-sure convergence to a limit + with a strict quantile. +* `empiricalCDF_mono`: the empirical distribution function is monotone. +* `tendsto_empiricalCDF_ae`: for pairwise independent observations with a common law whose CDF `G` + is continuous, almost surely the empirical CDF converges to `G` at every `x`. + +## References + +* [van der Vaart (1998)][VanDerVaart1998], Lemma 21.2 + +## Tags + +convergence of quantiles, empirical distribution function, Glivenko–Cantelli, +strong law of large numbers, large portfolio limit, empirical CDF, MSC 60F15, MSC 62G30 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set Filter Topology + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + +/-- The CDF of the law of `X` at `x` is the probability of `{X ≤ x}`. -/ +lemma cdf_map_eq_measureReal [IsProbabilityMeasure P] {X : Ω → ℝ} (hX : AEMeasurable X P) + (x : ℝ) : cdf (P.map X) x = P.real (X ⁻¹' Iic x) := by + rw [cdf_eq_real, map_measureReal_apply_of_aemeasurable hX measurableSet_Iic] + +/-! ### Quantiles along almost-sure convergence -/ + +/-- **Quantiles converge along almost-sure convergence.** If `X n → Y` almost surely and the +`α`-quantile of `Y` is strict (`α < P(Y ≤ x)` for every `x` above it), then the `α`-quantiles of the +laws of the `X n` converge to the `α`-quantile of the law of `Y`. -/ +theorem tendsto_quantile_of_tendsto_ae [IsProbabilityMeasure P] {X : ℕ → Ω → ℝ} {Y : Ω → ℝ} + (hX : ∀ n, AEMeasurable (X n) P) (hY : AEMeasurable Y P) + (hlim : ∀ᵐ ω ∂P, Tendsto (fun n ↦ X n ω) atTop (𝓝 (Y ω))) {α : ℝ} (hα : α ∈ Ioo 0 1) + (hstrict : ∀ x, quantile (P.map Y) α < x → α < cdf (P.map Y) x) : + Tendsto (fun n ↦ quantile (P.map (X n)) α) atTop (𝓝 (quantile (P.map Y) α)) := by + refine tendsto_order.2 ⟨fun a ha ↦ ?_, fun b hb ↦ ?_⟩ + · -- below the quantile: `P(Y ≤ a) < α`, and the events `⋃_{n ≥ N} {X n ≤ a}` decrease into + -- `{Y ≤ a}` up to a null set + rw [lt_quantile_iff hα, cdf_map_eq_measureReal hY, measureReal_def] at ha + have hYa := (ENNReal.lt_ofReal_iff_toReal_lt (measure_ne_top _ _)).2 ha + let B : ℕ → Set Ω := fun N ↦ ⋃ n ≥ N, X n ⁻¹' Iic a + have hB : Antitone B := fun N M hNM ω hω ↦ by + obtain ⟨n, hn, h⟩ := mem_iUnion₂.1 hω + exact mem_iUnion₂.2 ⟨n, hNM.trans hn, h⟩ + have hBlim := tendsto_measure_iInter_atTop (fun N ↦ .iUnion fun n ↦ .iUnion fun _ ↦ + (hX n).nullMeasurableSet_preimage measurableSet_Iic) hB ⟨0, measure_ne_top _ _⟩ + have hinter : P (⋂ N, B N) ≤ P (Y ⁻¹' Iic a) := by + refine measure_mono_ae <| hlim.mono fun ω hω hmem ↦ ?_ + change Y ω ≤ a + by_contra! h + obtain ⟨N, hN⟩ := eventually_atTop.1 (hω.eventually (lt_mem_nhds h)) + obtain ⟨n, hn, hle⟩ := mem_iUnion₂.1 (mem_iInter.1 hmem N) + exact (hN n hn).not_ge hle + obtain ⟨N, hN⟩ := (hBlim.eventually (gt_mem_nhds (hinter.trans_lt hYa))).exists + filter_upwards [eventually_ge_atTop N] with n hn + rw [lt_quantile_iff hα, cdf_map_eq_measureReal (hX n), measureReal_def, + ← ENNReal.lt_ofReal_iff_toReal_lt (measure_ne_top _ _)] + exact (measure_mono fun ω h ↦ mem_iUnion₂.2 ⟨n, hn, h⟩).trans_lt hN + · -- above the quantile: take `q < c < b' < b`; strictness gives `α < P(Y ≤ c)`, and the events + -- `⋂_{n ≥ N} {X n ≤ b'}` increase to a set containing `{Y ≤ c}` up to a null set + obtain ⟨b', hqb', hb'b⟩ := exists_between hb + obtain ⟨c, hqc, hcb'⟩ := exists_between hqb' + have hYc := hstrict c hqc + rw [cdf_map_eq_measureReal hY, measureReal_def] at hYc + have hYc' := (ENNReal.ofReal_lt_iff_lt_toReal hα.1.le (measure_ne_top _ _)).2 hYc + let A : ℕ → Set Ω := fun N ↦ ⋂ n ≥ N, X n ⁻¹' Iic b' + have hA : Monotone A := fun N M hNM ω hω ↦ + mem_iInter₂.2 fun n hn ↦ mem_iInter₂.1 hω n (hNM.trans hn) + have hunion : P (Y ⁻¹' Iic c) ≤ P (⋃ N, A N) := by + refine measure_mono_ae <| hlim.mono fun ω hω (hYω : Y ω ≤ c) ↦ ?_ + obtain ⟨N, hN⟩ := eventually_atTop.1 (hω.eventually (gt_mem_nhds (hYω.trans_lt hcb'))) + exact mem_iUnion.2 ⟨N, mem_iInter₂.2 fun n hn ↦ (hN n hn).le⟩ + obtain ⟨N, hN⟩ := + ((tendsto_measure_iUnion_atTop hA).eventually (lt_mem_nhds (hYc'.trans_le hunion))).exists + filter_upwards [eventually_ge_atTop N] with n hn + refine lt_of_le_of_lt ((quantile_le_iff hα).2 ?_) hb'b + rw [cdf_map_eq_measureReal (hX n), measureReal_def] + exact ((ENNReal.ofReal_lt_iff_lt_toReal hα.1.le (measure_ne_top _ _)).1 + (hN.trans_le (measure_mono fun ω hω ↦ mem_iInter₂.1 hω n hn))).le + +/-! ### The strong law for the empirical CDF -/ + +/-- The **empirical CDF** of the first `m` observations `ε 0 ω, …, ε (m - 1) ω`, at `x`: the +fraction of them that are at most `x`. -/ +noncomputable def empiricalCDF (ε : ℕ → Ω → ℝ) (m : ℕ) (ω : Ω) (x : ℝ) : ℝ := + (m : ℝ)⁻¹ * ∑ i ∈ Finset.range m, (Iic x).indicator 1 (ε i ω) + +/-- The empirical CDF is monotone in the evaluation point. -/ +lemma empiricalCDF_mono (ε : ℕ → Ω → ℝ) (m : ℕ) (ω : Ω) : Monotone (empiricalCDF ε m ω) := + fun _ _ hxy ↦ mul_le_mul_of_nonneg_left (Finset.sum_le_sum fun _ _ ↦ + indicator_le_indicator_of_subset (Iic_subset_Iic.2 hxy) (fun _ ↦ zero_le_one) _) + (inv_nonneg.2 m.cast_nonneg) + +/-- **The strong law for the empirical CDF.** If the `ε i` are pairwise independent with a common +law `μ` whose CDF is continuous, then almost surely the empirical CDF converges to `cdf μ` at every +point simultaneously. -/ +theorem tendsto_empiricalCDF_ae [IsProbabilityMeasure P] {ε : ℕ → Ω → ℝ} {μ : Measure ℝ} + [IsProbabilityMeasure μ] (hε : ∀ i, HasLaw (ε i) μ P) + (hind : Pairwise fun i j ↦ ε i ⟂ᵢ[P] ε j) (hG : Continuous (cdf μ)) : + ∀ᵐ ω ∂P, ∀ x, Tendsto (fun m ↦ empiricalCDF ε m ω x) atTop (𝓝 (cdf μ x)) := by + -- Etemadi's strong law at each rational threshold + have hrat : ∀ᵐ ω ∂P, ∀ t : ℚ, + Tendsto (fun m ↦ empiricalCDF ε m ω t) atTop (𝓝 (cdf μ t)) := by + refine ae_all_iff.2 fun t ↦ ?_ + have hf : Measurable ((Iic (t : ℝ)).indicator (1 : ℝ → ℝ)) := + measurable_const.indicator measurableSet_Iic + have hbound (y : ℝ) : ‖(Iic (t : ℝ)).indicator (1 : ℝ → ℝ) y‖ ≤ 1 := by + by_cases hy : y ∈ Iic (t : ℝ) <;> simp [hy] + have hslln := strong_law_ae (fun i ω ↦ (Iic (t : ℝ)).indicator 1 (ε i ω)) + (.of_bound (hf.comp_aemeasurable (hε 0).aemeasurable).aestronglyMeasurable 1 + (ae_of_all _ fun ω ↦ hbound (ε 0 ω))) + (fun i j hij ↦ (hind hij).comp hf hf) + (fun i ↦ (IdentDistrib.mk (hε i).aemeasurable (hε 0).aemeasurable + ((hε i).map_eq.trans (hε 0).map_eq.symm)).comp hf) + have hmean : P[fun ω ↦ (Iic (t : ℝ)).indicator 1 (ε 0 ω)] = cdf μ t := by + rw [← Function.comp_def, (hε 0).integral_comp hf.aestronglyMeasurable, + integral_indicator_one measurableSet_Iic, cdf_eq_real] + filter_upwards [hslln] with ω hω + simpa only [empiricalCDF, hmean, smul_eq_mul] using hω + filter_upwards [hrat] with ω hω x + refine tendsto_order.2 ⟨fun a ha ↦ ?_, fun b hb ↦ ?_⟩ + · -- a rational `t < x` with `a < G t`, by continuity of `G` at `x` + obtain ⟨l, u, ⟨hlx, hxu⟩, hsub⟩ := mem_nhds_iff_exists_Ioo_subset.1 + ((isOpen_lt continuous_const hG).mem_nhds ha) + obtain ⟨t, hlt, htx⟩ := exists_rat_btwn hlx + filter_upwards [(hω t).eventually (lt_mem_nhds (hsub ⟨hlt, htx.trans hxu⟩))] with m hm + exact hm.trans_le (empiricalCDF_mono ε m ω htx.le) + · -- a rational `t > x` with `G t < b`, by continuity of `G` at `x` + obtain ⟨l, u, ⟨hlx, hxu⟩, hsub⟩ := mem_nhds_iff_exists_Ioo_subset.1 + ((isOpen_lt hG continuous_const).mem_nhds hb) + obtain ⟨t, hxt, htu⟩ := exists_rat_btwn hxu + filter_upwards [(hω t).eventually (gt_mem_nhds (hsub ⟨hlx.trans hxt, htu⟩))] with m hm + exact (empiricalCDF_mono ε m ω hxt.le).trans_lt hm + +end MathFin diff --git a/LeanPool/MathFin/Probability/Laws/StudentT.lean b/LeanPool/MathFin/Probability/Laws/StudentT.lean new file mode 100644 index 0000000000..2637905e18 --- /dev/null +++ b/LeanPool/MathFin/Probability/Laws/StudentT.lean @@ -0,0 +1,301 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral +public import Mathlib.Probability.Distributions.Cauchy + +/-! +# The Student-t law + +The standard (unit-scale) Student-t law with `ν > 0` degrees of freedom is the law on `ℝ` with +density proportional to the kernel `(1 + x²/ν)^(-(ν+1)/2)`. + +Mathlib has no Student-t law at this pin. This file builds it as `volume.withDensity` of the +normalized kernel, `studentTPDFReal ν x = k_ν(x) / C_ν` with `C_ν = ∫ k_ν` +(`studentTNormConst`), so that it integrates to one by construction. The kernel is integrable for +every `ν > 0` by Mathlib's Japanese-bracket bound `integrable_rpow_neg_one_add_norm_sq`. The +constant is then computed, `C_ν = √(νπ) Γ(ν/2) / Γ((ν+1)/2)`, by writing the kernel as a Gamma +mixture of Gaussian kernels and exchanging the integrals, so the density is the textbook one. + +## Main definitions + +* `studentTKernel`: the unnormalised kernel `k_ν(x) = (1 + x²/ν)^(-(ν+1)/2)`. +* `studentTNormConst`: the normalising constant `C_ν = ∫ k_ν` (equal to + `√(νπ) Γ(ν/2) / Γ((ν+1)/2)` for `ν > 0`, by `studentTNormConst_eq`). +* `studentTPDFReal`, `studentTPDF`: the density `k_ν / C_ν`, real- and `ℝ≥0∞`-valued. +* `studentTMeasure`: the standard Student-t law, `volume.withDensity (studentTPDF ν)`; a + probability measure for `ν > 0`. + +## Main results + +* `isProbabilityMeasure_studentTMeasure`: the Student-t law is a probability measure for `ν > 0`. +* `studentTNormConst_eq`, `studentTPDFReal_eq`: the normalizing constant and the density in + closed form, `g_ν(x) = Γ((ν+1)/2) / (√(νπ) Γ(ν/2)) · (1 + x²/ν)^(-(ν+1)/2)`. +* `studentTMeasure_one`: at `ν = 1` it is Mathlib's standard Cauchy law `cauchyMeasure 0 1`. +* `integrable_mul_studentTPDFReal`: the law has a finite mean for `ν > 1`. +* `setIntegral_Ioi_mul_studentTPDFReal`: the tail first moment + `∫_q^∞ t g_ν(t) dt = g_ν(q) (ν + q²)/(ν − 1)` for `ν > 1`, the integral behind the + McNeil–Frey–Embrechts expected-shortfall closed form. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts] + +## Tags + +Student-t distribution, heavy tails, Cauchy distribution, expected shortfall, degrees of freedom, +Gamma mixture, MSC 60E05, MSC 91G70 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped ENNReal Topology + +variable {ν : ℝ} + +/-! ### The kernel and its normalizing constant -/ + +/-- The unnormalized Student-t kernel `k_ν(x) = (1 + x²/ν)^(-(ν+1)/2)`. -/ +noncomputable def studentTKernel (ν x : ℝ) : ℝ := (1 + x ^ 2 / ν) ^ (-(ν + 1) / 2) + +lemma studentTKernel_pos (hν : 0 < ν) (x : ℝ) : 0 < studentTKernel ν x := + rpow_pos_of_pos (by positivity : 0 < 1 + x ^ 2 / ν) _ + +lemma continuous_studentTKernel (hν : 0 < ν) : Continuous (studentTKernel ν) := + (by fun_prop : Continuous fun x : ℝ ↦ 1 + x ^ 2 / ν).rpow_const + fun x ↦ Or.inl (by positivity : 0 < 1 + x ^ 2 / ν).ne' + +/-- The kernel is integrable for every `ν > 0`: it is the Japanese bracket `(1 + ‖y‖²)^(-r/2)` +with `r = ν + 1 > 1 = dim ℝ`, at `y = x/√ν`. -/ +lemma integrable_studentTKernel (hν : 0 < ν) : Integrable (studentTKernel ν) := + ((integrable_rpow_neg_one_add_norm_sq (E := ℝ) (μ := volume) (r := ν + 1) + (by simp; linarith)).comp_div (sqrt_pos.2 hν).ne').congr <| ae_of_all _ fun x ↦ by + simp only [studentTKernel, norm_eq_abs, sq_abs, div_pow, sq_sqrt hν.le] + +/-- The normalizing constant `C_ν = ∫ k_ν`; positive for `ν > 0` +(`studentTNormConst_pos`). For `ν ≤ 0` the value is junk. -/ +noncomputable def studentTNormConst (ν : ℝ) : ℝ := ∫ x, studentTKernel ν x + +lemma studentTNormConst_pos (hν : 0 < ν) : 0 < studentTNormConst ν := + (integral_pos_iff_support_of_nonneg (fun x ↦ (studentTKernel_pos hν x).le) + (integrable_studentTKernel hν)).2 <| by + rw [Function.support_eq_univ fun x ↦ (studentTKernel_pos hν x).ne'] + simp + +/-! ### The normalizing constant in closed form -/ + +/-- The Gamma-mixture integrand: `k_ν(x) = Γ(s)⁻¹ ∫_0^∞ u^(s−1) e^(−(1 + x²/ν) u) du` with +`s = (ν+1)/2`. -/ +private lemma studentTKernel_eq_integral (hν : 0 < ν) (x : ℝ) : + studentTKernel ν x = (Gamma ((ν + 1) / 2))⁻¹ * + ∫ u in Ioi 0, u ^ ((ν + 1) / 2 - 1) * exp (-((1 + x ^ 2 / ν) * u)) := by + have hb : 0 < 1 + x ^ 2 / ν := by positivity + rw [integral_rpow_mul_exp_neg_mul_Ioi (by linarith) hb, studentTKernel, one_div, + inv_rpow hb.le, ← rpow_neg hb.le, neg_div] + field_simp + +/-- The inner Gaussian integral: integrating the mixture integrand over `x` gives +`u^(s−1) e^(−u) √(π/(u/ν))`. -/ +lemma integral_rpow_mul_exp_neg_mul_one_add_sq_div (hν : 0 < ν) (u : ℝ) : + ∫ x, u ^ ((ν + 1) / 2 - 1) * exp (-((1 + x ^ 2 / ν) * u)) = + u ^ ((ν + 1) / 2 - 1) * exp (-u) * √(π / (u / ν)) := by + rw [← integral_gaussian (u / ν), ← integral_const_mul] + congr 1 with x + rw [mul_assoc, ← exp_add] + congr 2 + field_simp + ring + +/-- The outer integrand, rearranged: for `u > 0`, +`u^(s−1) e^(−u) √(π/(u/ν)) = √(νπ) · e^(−u) u^(ν/2−1)`, the Gamma integrand at `ν/2`. -/ +lemma rpow_mul_exp_mul_sqrt_pi_div_eq {u : ℝ} (hu : 0 < u) : + u ^ ((ν + 1) / 2 - 1) * exp (-u) * √(π / (u / ν)) = + √(ν * π) * (exp (-u) * u ^ (ν / 2 - 1)) := by + have hsq : √(π / (u / ν)) = √(ν * π) * u ^ (-(1 / 2) : ℝ) := by + rw [rpow_neg hu.le, ← sqrt_eq_rpow, div_div_eq_mul_div, mul_comm π, sqrt_div' _ hu.le, + div_eq_mul_inv] + rw [hsq, show ν / 2 - 1 = ((ν + 1) / 2 - 1) + -(1 / 2) by ring, rpow_add hu] + ring + +/-- **The Student-t normalizing constant**: `C_ν = √(νπ) Γ(ν/2) / Γ((ν+1)/2)` +(equivalently `√ν · B(1/2, ν/2)`). Proved by writing the kernel as a Gamma mixture of Gaussian +kernels and exchanging the two integrals (Fubini, integrability via `integrable_prod_iff'`). -/ +theorem studentTNormConst_eq (hν : 0 < ν) : + studentTNormConst ν = √(ν * π) * Gamma (ν / 2) / Gamma ((ν + 1) / 2) := by + set f : ℝ → ℝ → ℝ := fun x u ↦ u ^ ((ν + 1) / 2 - 1) * exp (-((1 + x ^ 2 / ν) * u)) + have hmeas : AEStronglyMeasurable (Function.uncurry f) + (volume.prod (volume.restrict (Ioi (0 : ℝ)))) := + (by fun_prop : Measurable (Function.uncurry f)).aestronglyMeasurable + have hint : Integrable (Function.uncurry f) (volume.prod (volume.restrict (Ioi (0 : ℝ)))) := by + refine (integrable_prod_iff' hmeas).2 ⟨?_, ?_⟩ + · refine (ae_restrict_iff' measurableSet_Ioi).2 (ae_of_all _ fun u (hu : 0 < u) ↦ ?_) + refine ((integrable_exp_neg_mul_sq (div_pos hu hν)).const_mul + (u ^ ((ν + 1) / 2 - 1) * exp (-u))).congr (ae_of_all _ fun x ↦ ?_) + simp only [f, Function.uncurry_apply_pair, mul_assoc, ← exp_add] + congr 2 + field_simp + ring + · refine ((GammaIntegral_convergent (half_pos hν)).const_mul √(ν * π)).congr + ((ae_restrict_iff' measurableSet_Ioi).2 (ae_of_all _ fun u (hu : 0 < u) ↦ ?_)) + simp only [Function.uncurry_apply_pair, f] + rw [← rpow_mul_exp_mul_sqrt_pi_div_eq hu, ← integral_rpow_mul_exp_neg_mul_one_add_sq_div hν u] + exact integral_congr_ae (ae_of_all _ fun x ↦ (norm_of_nonneg (by positivity)).symm) + calc studentTNormConst ν + = (Gamma ((ν + 1) / 2))⁻¹ * ∫ x, ∫ u in Ioi 0, f x u := by + rw [studentTNormConst, ← integral_const_mul] + exact integral_congr_ae (ae_of_all _ (studentTKernel_eq_integral hν)) + _ = (Gamma ((ν + 1) / 2))⁻¹ * ∫ u in Ioi 0, ∫ x, f x u := by + rw [integral_integral_swap hint] + _ = (Gamma ((ν + 1) / 2))⁻¹ * ∫ u in Ioi 0, √(ν * π) * (exp (-u) * u ^ (ν / 2 - 1)) := by + congr 1 + refine setIntegral_congr_fun measurableSet_Ioi fun u (hu : 0 < u) ↦ ?_ + rw [integral_rpow_mul_exp_neg_mul_one_add_sq_div hν u, rpow_mul_exp_mul_sqrt_pi_div_eq hu] + _ = √(ν * π) * Gamma (ν / 2) / Gamma ((ν + 1) / 2) := by + rw [integral_const_mul, ← Gamma_eq_integral (half_pos hν)] + field_simp + +/-! ### The density and the law -/ + +/-- The standard Student-t density `g_ν(x) = k_ν(x) / C_ν`; a probability density for `ν > 0` +(`integral_studentTPDFReal`). For `ν ≤ 0` the value is junk. -/ +noncomputable def studentTPDFReal (ν x : ℝ) : ℝ := studentTKernel ν x / studentTNormConst ν + +/-- The Student-t density as an `ℝ≥0∞`-valued function. -/ +noncomputable def studentTPDF (ν x : ℝ) : ℝ≥0∞ := ENNReal.ofReal (studentTPDFReal ν x) + +lemma studentTPDFReal_pos (hν : 0 < ν) (x : ℝ) : 0 < studentTPDFReal ν x := + div_pos (studentTKernel_pos hν x) (studentTNormConst_pos hν) + +/-- **The textbook Student-t density**: +`g_ν(x) = Γ((ν+1)/2) / (√(νπ) Γ(ν/2)) · (1 + x²/ν)^(-(ν+1)/2)`. -/ +theorem studentTPDFReal_eq (hν : 0 < ν) (x : ℝ) : + studentTPDFReal ν x = Gamma ((ν + 1) / 2) / (√(ν * π) * Gamma (ν / 2)) * + (1 + x ^ 2 / ν) ^ (-(ν + 1) / 2) := by + rw [studentTPDFReal, studentTNormConst_eq hν, studentTKernel, div_div_eq_mul_div, mul_comm] + ring + +lemma integrable_studentTPDFReal (hν : 0 < ν) : Integrable (studentTPDFReal ν) := + (integrable_studentTKernel hν).div_const _ + +lemma integral_studentTPDFReal (hν : 0 < ν) : ∫ x, studentTPDFReal ν x = 1 := by + simp only [studentTPDFReal, integral_div] + exact div_self (studentTNormConst_pos hν).ne' + +lemma lintegral_studentTPDF (hν : 0 < ν) : ∫⁻ x, studentTPDF ν x = 1 := by + simp only [studentTPDF] + rw [← ofReal_integral_eq_lintegral_ofReal (integrable_studentTPDFReal hν) + (ae_of_all _ fun x ↦ (studentTPDFReal_pos hν x).le), integral_studentTPDFReal hν, + ENNReal.ofReal_one] + +/-- The standard **Student-t law** with `ν` degrees of freedom; a probability measure for `ν > 0` +(`isProbabilityMeasure_studentTMeasure`). For `ν ≤ 0` the value is junk. -/ +noncomputable def studentTMeasure (ν : ℝ) : Measure ℝ := volume.withDensity (studentTPDF ν) + +lemma isProbabilityMeasure_studentTMeasure (hν : 0 < ν) : + IsProbabilityMeasure (studentTMeasure ν) := + ⟨by rw [studentTMeasure, withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ, + lintegral_studentTPDF hν]⟩ + +@[fun_prop] +lemma measurable_studentTPDFReal (ν : ℝ) : Measurable (studentTPDFReal ν) := by + unfold studentTPDFReal studentTKernel + fun_prop + +@[fun_prop] +lemma measurable_studentTPDF (ν : ℝ) : Measurable (studentTPDF ν) := + (measurable_studentTPDFReal ν).ennreal_ofReal + +/-- The Student-t law has a density, so it charges no single point. -/ +instance nullSingletonClass_studentTMeasure (ν : ℝ) : NullSingletonClass (studentTMeasure ν) := + inferInstanceAs (NullSingletonClass (volume.withDensity _)) + +/-! ### The Cauchy anchor -/ + +lemma studentTKernel_one (x : ℝ) : studentTKernel 1 x = (1 + x ^ 2)⁻¹ := by + rw [studentTKernel, div_one, show (-(1 + 1) / 2 : ℝ) = -1 by norm_num, rpow_neg_one] + +lemma studentTNormConst_one : studentTNormConst 1 = π := by + simp only [studentTNormConst, studentTKernel_one, integral_univ_inv_one_add_sq] + +/-- **At one degree of freedom the Student-t law is the standard Cauchy law**, Mathlib's +`cauchyMeasure 0 1`. -/ +theorem studentTMeasure_one : studentTMeasure 1 = cauchyMeasure 0 1 := by + rw [cauchyMeasure_of_scale_ne_zero 0 one_ne_zero, studentTMeasure] + congr 1 with x + simp only [studentTPDF, cauchyPDF, studentTPDFReal, cauchyPDFReal, studentTKernel_one, + studentTNormConst_one, sub_zero, NNReal.coe_one, one_pow] + congr 1 + ring + +/-! ### The first moment -/ + +/-- For `ν > 1` the law has a finite mean: `|x| g_ν(x) ≤ (√ν / C_ν) (1 + x²/ν)^(-ν/2)`, a +Japanese bracket with `r = ν > 1`. -/ +lemma integrable_mul_studentTPDFReal (hν : 1 < ν) : + Integrable fun x ↦ x * studentTPDFReal ν x := by + have hν0 : 0 < ν := by linarith + have hC := studentTNormConst_pos hν0 + have h := ((integrable_rpow_neg_one_add_norm_sq (E := ℝ) (μ := volume) (r := ν) + (by simpa using hν)).comp_div (sqrt_pos.2 hν0).ne').const_mul (√ν / studentTNormConst ν) + refine h.mono' (by fun_prop) (ae_of_all _ fun x ↦ ?_) + have hb : 0 < 1 + x ^ 2 / ν := by positivity + have h1 : |x| ≤ √ν * (1 + x ^ 2 / ν) ^ (1 / 2 : ℝ) := by + rw [← sqrt_eq_rpow, ← sqrt_mul hν0.le, ← sqrt_sq_eq_abs] + refine sqrt_le_sqrt ?_ + rw [mul_add, mul_div_cancel₀ _ hν0.ne'] + linarith + have h2 : (1 + x ^ 2 / ν) ^ (1 / 2 : ℝ) * studentTKernel ν x = (1 + x ^ 2 / ν) ^ (-ν / 2) := by + rw [studentTKernel, ← rpow_add hb] + ring_nf + rw [norm_mul, norm_of_nonneg (studentTPDFReal_pos hν0 x).le] + simp only [norm_eq_abs, sq_abs, div_pow, sq_sqrt hν0.le, studentTPDFReal] + refine (mul_le_mul_of_nonneg_right h1 (div_pos (studentTKernel_pos hν0 x) hC).le).trans_eq ?_ + rw [← h2] + ring + +/-- **The tail first moment of the Student-t law**: for `ν > 1`, +`∫_q^∞ t g_ν(t) dt = g_ν(q) (ν + q²)/(ν − 1)`. The antiderivative of `t g_ν(t)` is +`−(ν/(ν−1)) C_ν⁻¹ (1 + t²/ν)^((1−ν)/2)`, which vanishes at `+∞` because `ν > 1`. -/ +theorem setIntegral_Ioi_mul_studentTPDFReal (hν : 1 < ν) (q : ℝ) : + ∫ t in Ioi q, t * studentTPDFReal ν t = + studentTPDFReal ν q * ((ν + q ^ 2) / (ν - 1)) := by + have hν0 : 0 < ν := by linarith + have hν1 : ν - 1 ≠ 0 := by linarith + have hC := (studentTNormConst_pos hν0).ne' + set c := -(ν / (ν - 1)) / studentTNormConst ν + have hderiv (t : ℝ) : HasDerivAt (fun t ↦ c * (1 + t ^ 2 / ν) ^ ((1 - ν) / 2)) + (t * studentTPDFReal ν t) t := by + have hb : 0 < 1 + t ^ 2 / ν := by positivity + have h := (((hasDerivAt_pow 2 t).div_const ν).const_add 1).rpow_const + (p := (1 - ν) / 2) (Or.inl hb.ne') |>.const_mul c + refine h.congr_deriv ?_ + simp only [studentTPDFReal, studentTKernel, show (1 - ν) / 2 - 1 = -(ν + 1) / 2 by ring, c] + field_simp + ring + have hlim : Tendsto (fun t ↦ c * (1 + t ^ 2 / ν) ^ ((1 - ν) / 2)) atTop (𝓝 0) := by + have hb : Tendsto (fun t : ℝ ↦ 1 + t ^ 2 / ν) atTop atTop := + tendsto_atTop_add_const_left _ _ + ((tendsto_pow_atTop two_ne_zero).atTop_div_const hν0) + have := (tendsto_rpow_neg_atTop (y := (ν - 1) / 2) (by linarith)).comp hb + simpa [show -((ν - 1) / 2) = (1 - ν) / 2 by ring] using this.const_mul c + rw [integral_Ioi_of_hasDerivAt_of_tendsto (hderiv q).continuousAt.continuousWithinAt + (fun t _ ↦ hderiv t) (integrable_mul_studentTPDFReal hν).integrableOn hlim] + have hb : 0 < 1 + q ^ 2 / ν := by positivity + rw [studentTPDFReal, studentTKernel, show (1 - ν) / 2 = -(ν + 1) / 2 + 1 by ring, + rpow_add_one hb.ne'] + simp only [c] + field_simp + ring + +end MathFin diff --git a/LeanPool/MathFin/Probability/Martingales/BoundedLocalMartingale.lean b/LeanPool/MathFin/Probability/Martingales/BoundedLocalMartingale.lean new file mode 100644 index 0000000000..b7c2992b08 --- /dev/null +++ b/LeanPool/MathFin/Probability/Martingales/BoundedLocalMartingale.lean @@ -0,0 +1,176 @@ +/- +Copyright (c) 2026 Robert Martin. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Robert Martin, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Martingales.MartingaleSetIntegral +public import LeanPool.MathFin.Probability.Martingales.StoppedProcessPaths +public import LeanPool.MathFin.Probability.Support.LocalMartingale +public import Mathlib.MeasureTheory.Integral.DominatedConvergence + +/-! +# Bounded local martingales and smaller filtrations + +Promotion is proved by dominated convergence of localized set integrals. The file lives in +`Probability/` because the promotion is general: the American-put stopping development and the +localisation of Lévy's characterisation (`LevyCharacterization`) both use it. +No unproved upstream optional-sampling or uniform-integrability result is used. +Adaptation to the target filtration is explicit; a local property alone is +not silently treated as pointwise adaptation on exceptional null outcomes. + +## Main results + +* `martingale_smaller_filtration`: a martingale for `𝓖` that is adapted to a smaller filtration + `𝓕 ≤ 𝓖` is a martingale for `𝓕`. +* `locally_bounded_localMartingale_is_martingale`: an adapted local martingale that is bounded on + `[0,T]` for each `T` is a martingale. +* `bounded_localMartingale_is_martingale`: an adapted local martingale bounded by a constant is a + martingale. +* `martingale_stoppedProcess_of_locally_bounded`: an adapted continuous-path local martingale + stopped at a stopping time `ρ` with `⊥ < ρ` everywhere, whose stopped process is bounded on + `[0,T]` for each `T`, is a martingale. +* `exists_martingale_eqOn`: a continuous-path local martingale with `X 0 = 0` almost surely has a + localising sequence `σ` such that each `N` has a continuous-path martingale `Y` agreeing almost + surely with `X` at each time `t ≤ σ N`. +* `isLocalMartingale_congr_ae`: a process `Y` adapted with càdlàg paths and almost surely equal + to a local martingale `X` (`X ≡ᵐ[P] Y`) is a local martingale. + +## Tags + +local martingale, localization, dominated convergence, martingale property, smaller filtration, +MSC 60G44, MSC 60G48 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set Filter +open scoped NNReal Topology + +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsFiniteMeasure P] + {𝓕 𝓖 : Filtration ℝ≥0 ‹MeasurableSpace Ω›} {X : ℝ≥0 → Ω → ℝ} + +theorem martingale_smaller_filtration (hFG : 𝓕 ≤ 𝓖) (hX : Martingale X 𝓖 P) + (hadapt : StronglyAdapted 𝓕 X) : Martingale X 𝓕 P := + martingale_iff_setIntegral_eq.2 ⟨hadapt, hX.integrable, + fun _ _ hij _ hs => hX.setIntegral_eq hij (hFG _ _ hs)⟩ + +theorem locally_bounded_localMartingale_is_martingale (hX : IsLocalMartingale X 𝓕 P) + (hadapt : StronglyAdapted 𝓕 X) + (hbound : ∀ T : ℝ≥0, ∃ C : ℝ, ∀ t, t ≤ T → ∀ ω, ‖X t ω‖ ≤ C) : + Martingale X 𝓕 P := by + obtain ⟨τ,hτ,hloc⟩ := hX + let Y : ℕ → ℝ≥0 → Ω → ℝ := fun n => + stoppedProcess (fun t => {ω | ⊥ < τ n ω}.indicator (X t)) (τ n) + have hY : ∀ n, Martingale (Y n) 𝓕 P := fun n => (hloc n).1 + have hYbound : ∀ t, ∃ C : ℝ, ∀ n ω, ‖Y n t ω‖ ≤ C := by + intro t + obtain ⟨C,hC⟩ := hbound t + refine ⟨C,fun n ω => ?_⟩ + have hu : (min (t : WithTop ℝ≥0) (τ n ω)).untopA ≤ t := + WithTop.untopA_le (min_le_left _ _) + exact (norm_indicator_le_norm_self _ _).trans (hC _ hu ω) + have hlim : ∀ t, ∀ᵐ ω ∂P, Tendsto (fun n => Y n t ω) atTop (𝓝 (X t ω)) := by + intro t + filter_upwards [hτ.tendsto_top] with ω hω + have hlarge : ∀ᶠ n in atTop, ((t+1 : ℝ≥0) : WithTop ℝ≥0) < τ n ω := + hω.eventually (Ioi_mem_nhds (WithTop.coe_lt_top (t+1))) + have heq : (fun n => Y n t ω) =ᶠ[atTop] (fun _ => X t ω) := by + filter_upwards [hlarge] with n hn + have hle : (t : WithTop ℝ≥0) ≤ τ n ω := + (show (t : WithTop ℝ≥0) ≤ + (t+1 : ℝ≥0) by exact_mod_cast le_add_of_nonneg_right zero_le).trans hn.le + have hpos : (⊥ : WithTop ℝ≥0) < τ n ω := + (show (⊥ : WithTop ℝ≥0) < (t+1 : ℝ≥0) by + change (0 : WithTop ℝ≥0) < _ + exact_mod_cast (show (0 : ℝ≥0) < t+1 by positivity)).trans hn + exact (stoppedProcess_eq_of_le hle).trans + (indicator_of_mem (show ω ∈ {ω | ⊥ < τ n ω} from hpos) _) + exact tendsto_const_nhds.congr' heq.symm + have hint : ∀ t, Integrable (X t) P := by + intro t + obtain ⟨C,hC⟩ := hbound t + exact (integrable_const C).mono' ((hadapt t).mono (𝓕.le t)).aestronglyMeasurable + (Eventually.of_forall (hC t le_rfl)) + refine martingale_iff_setIntegral_eq.2 ⟨hadapt, hint, fun i j hij s hs ↦ ?_⟩ + have hconv (t : ℝ≥0) : Tendsto (fun n => ∫ ω in s, Y n t ω ∂P) atTop + (𝓝 (∫ ω in s, X t ω ∂P)) := by + obtain ⟨C,hC⟩ := hYbound t + exact tendsto_integral_of_dominated_convergence (fun _ => C) + (fun n => ((hY n).integrable t).aestronglyMeasurable.restrict) (integrable_const C) + (fun n => Eventually.of_forall (hC n)) (ae_restrict_of_ae (hlim t)) + have hi := hconv i + have heq : (fun n => ∫ ω in s, Y n i ω ∂P) = (fun n => ∫ ω in s, Y n j ω ∂P) := + funext (fun n => (hY n).setIntegral_eq hij hs) + rw [heq] at hi + exact tendsto_nhds_unique hi (hconv j) + +theorem bounded_localMartingale_is_martingale (hX : IsLocalMartingale X 𝓕 P) + (hadapt : StronglyAdapted 𝓕 X) {C : ℝ} + (hbound : ∀ t ω, ‖X t ω‖ ≤ C) : Martingale X 𝓕 P := + locally_bounded_localMartingale_is_martingale hX hadapt + (fun _ => ⟨C,fun t _ ω => hbound t ω⟩) + +/-- **A continuous adapted local martingale stopped at a positive stopping time where it is +locally bounded is a martingale.** Stopping a local martingale keeps it a local martingale +(`IsStable.locally`); at a positive `ρ` the stopping indicator is inert +(`stoppedProcess_indicator_eq`), so this is `locally_bounded_localMartingale_is_martingale`. -/ +theorem martingale_stoppedProcess_of_locally_bounded {ρ : Ω → WithTop ℝ≥0} + (hX : IsLocalMartingale X 𝓕 P) (hXad : StronglyAdapted 𝓕 X) + (hXc : ∀ ω, Continuous fun t ↦ X t ω) (hρ : IsStoppingTime 𝓕 ρ) (hpos : ∀ ω, ⊥ < ρ ω) + (hbound : ∀ T : ℝ≥0, ∃ C : ℝ, ∀ t, t ≤ T → ∀ ω, ‖stoppedProcess X ρ t ω‖ ≤ C) : + Martingale (stoppedProcess X ρ) 𝓕 P := by + have hloc := (isStable_martingale (𝓕 := 𝓕) (P := P)).locally X hX _ hρ + rw [stoppedProcess_indicator_eq hpos] at hloc + have had := hXad.stoppedProcess_indicator (fun ω ↦ (hXc ω).isCadlag.isRightContinuous) hρ + rw [stoppedProcess_indicator_eq hpos] at had + exact locally_bounded_localMartingale_is_martingale hloc had hbound + +omit [IsFiniteMeasure P] in +/-- **A continuous local martingale is, along its localising sequence, a continuous martingale.** +For `σ` the localising sequence of `X`, each `N` has a continuous martingale `Y` (`X` stopped at +`σ N`, zeroed where `σ N = 0`) with `X t = Y t` almost surely on `{t ≤ σ N}`. The zeroing is +invisible because `X 0 = 0` almost surely. -/ +theorem exists_martingale_eqOn (hX : IsLocalMartingale X 𝓕 P) + (hXc : ∀ ω, Continuous fun t ↦ X t ω) (hX0 : ∀ᵐ ω ∂P, X 0 ω = 0) : + ∃ σ : ℕ → Ω → WithTop ℝ≥0, IsLocalizingSequence 𝓕 σ P ∧ ∀ N, ∃ Y : ℝ≥0 → Ω → ℝ, + Martingale Y 𝓕 P ∧ (∀ ω, Continuous fun t ↦ Y t ω) ∧ + ∀ t : ℝ≥0, ∀ᵐ ω ∂P, (t : WithTop ℝ≥0) ≤ σ N ω → X t ω = Y t ω := by + obtain ⟨σ, hσ, hloc⟩ := hX + refine ⟨σ, hσ, fun N ↦ ⟨_, (hloc N).1, fun ω ↦ ?_, fun t ↦ hX0.mono fun ω h0 hle ↦ ?_⟩⟩ + · by_cases hpos : ⊥ < σ N ω + · simp only [stoppedProcess, Set.indicator_of_mem (show ω ∈ {ω | ⊥ < σ N ω} from hpos)] + exact (hXc ω).comp (continuous_untopA_min _) + · simp only [stoppedProcess, Set.indicator_of_notMem (show ω ∉ {ω | ⊥ < σ N ω} from hpos)] + exact continuous_const + · by_cases hpos : ⊥ < σ N ω + · rw [stoppedProcess_eq_of_le hle, Set.indicator_of_mem (show ω ∈ {ω | ⊥ < σ N ω} from hpos)] + · obtain rfl : t = 0 := le_antisymm (WithTop.coe_le_coe.1 (hle.trans (not_lt.1 hpos))) zero_le + rw [h0] + simp only [stoppedProcess] + rw [Set.indicator_of_notMem (show ω ∉ {ω | ⊥ < σ N ω} from hpos)] + +omit [IsFiniteMeasure P] in +/-- **A process indistinguishable from a local martingale is one**, provided it is adapted with +cadlag paths: the stopped processes are almost surely equal at each time, hence have the same +conditional expectations, and the stopped `Y` is adapted. -/ +theorem isLocalMartingale_congr_ae {Y : ℝ≥0 → Ω → ℝ} (hX : IsLocalMartingale X 𝓕 P) + (hY : StronglyAdapted 𝓕 Y) (hYc : ∀ ω, IsCadlag fun t ↦ Y t ω) + (hXY : X ≡ᵐ[P] Y) : IsLocalMartingale Y 𝓕 P := by + obtain ⟨τ, hτ, hloc⟩ := hX + refine ⟨τ, hτ, fun n ↦ ?_⟩ + obtain ⟨hmart, -⟩ := hloc n + have ht (t : ℝ≥0) : (fun ω ↦ stoppedProcess (fun i ↦ {ω | ⊥ < τ n ω}.indicator (X i)) (τ n) t ω) + =ᵐ[P] fun ω ↦ stoppedProcess (fun i ↦ {ω | ⊥ < τ n ω}.indicator (Y i)) (τ n) t ω := by + filter_upwards [hXY] with ω h + simp only [stoppedProcess, Set.indicator_apply, h] + exact ⟨⟨hY.stoppedProcess_indicator (fun ω ↦ (hYc ω).isRightContinuous) (hτ.isStoppingTime n), + fun i j hij ↦ (condExp_congr_ae (ht j).symm).trans ((hmart.2 i j hij).trans (ht i))⟩, + isStable_isCadlag Y hYc _ (hτ.isStoppingTime n)⟩ + +end MathFin diff --git a/LeanPool/MathFin/Probability/Martingales/ChangeOfMeasure.lean b/LeanPool/MathFin/Probability/Martingales/ChangeOfMeasure.lean new file mode 100644 index 0000000000..b039778cf9 --- /dev/null +++ b/LeanPool/MathFin/Probability/Martingales/ChangeOfMeasure.lean @@ -0,0 +1,130 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Martingale.Basic + +/-! +# The Bayes change-of-measure martingale engine + +The abstract heart of Girsanov's theorem, isolated from any stochastic-calculus +machinery. Fix a finite measure `P`, a filtration `𝓕`, and a **density process** +`Z` that is a `P`-martingale with `Z_T ≥ 0`. Let `Q := P.withDensity Z_T` be the +tilted measure. Then a process `D` is a **`Q`-martingale on `[0, T]`** when +the product `Z · D` is a `P`-martingale (one direction; the set-integral form is proved): + + `∫_A D_t dQ = ∫_A Z_t D_t dP = ∫_A Z_s D_s dP = ∫_A D_s dQ` for `A ∈ 𝓕_s`. + +The two outer equalities are the **Bayes/pull-out step** — for a set `A ∈ 𝓕_s ⊆ 𝓕_u` +and `D_u` `𝓕_u`-measurable, +`∫_A D_u Z_T dP = ∫_A D_u · P[Z_T | 𝓕_u] dP = ∫_A D_u Z_u dP` since `Z` is a +`P`-martingale (`condExp_mul_of_stronglyMeasurable_left` + `setIntegral_condExp`). +The middle equality is the `Z · D` martingale property (`Martingale.setIntegral_eq`). + +This is the reusable engine: any concrete change of measure (the Black–Scholes +Girsanov tilt in `MathFin/Pricing/Girsanov.lean`; and, once the tower gains an +adapted-integrand Itô formula, the general Doléans–Dade exponential) is one +instance — supply `Z`, `D`, and the two martingale facts. + +## Main results + +* `MathFin.changeOfMeasure_setIntegral_eq` + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Ch 9 +* [S. E. Shreve, *Stochastic Calculus for Finance II: Continuous-Time Models*][ShreveSCFII], Ch 5.2 + +## Tags + +Bayes rule, change of measure, density process, Radon–Nikodym, Girsanov tilt, martingale under Q, +MSC 60G44, MSC 91G20 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal + +/-- **Bayes change-of-measure engine (`[0,T]` form).** Let `Z` be a `P`-martingale with `Z_T ≥ 0` +(the density process), `D` an `𝓕`-adapted process, `M` a `P`-martingale, and suppose the product +`Z · D` agrees with `M` a.e. on `[0, T]` (`Z_u · D_u =ᵐ M_u` for `u ≤ T`). Then `D` is a martingale +under `Q := P.withDensity (Z_T)` on `[0, T]`: for `s ≤ t ≤ T` and `A ∈ 𝓕_s`, the `Q`-integrals of +`D_t` and `D_s` over `A` agree. + +The generality over the full-martingale form `changeOfMeasure_setIntegral_eq` is that `Z · D` itself +need **not** be a martingale — only its `[0,T]`-restriction need agree with an honest martingale +`M`. This is exactly the simple-θ Girsanov situation, where the tilted-density identity +`Z · D =ᵐ E^{a−c}` (`simple_spine_ae`) holds only on `[0,T]` (beyond the last partition point +`Z · D` diverges from the Doléans martingale `E^{a−c}` by a forward Wald factor). The mechanism is +unchanged: `∫_A D_u dQ = ∫_A Z_u D_u dP` (withDensity conversion + Bayes pull-out, using `hmix`, +`hZ`, `hDsm`, none of which touch `M`), then `Z_u D_u =ᵐ M_u` and `M`'s martingale property close +the loop. No stochastic calculus, only conditional expectations. -/ +theorem changeOfMeasure_setIntegral_eq_of_ae_martingale + {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + {𝓕 : Filtration ℝ≥0 mΩ} [SigmaFiniteFiltration P 𝓕] + {Z D M : ℝ≥0 → Ω → ℝ} (T : ℝ≥0) + (hZmeasT : Measurable (Z T)) (hZpos : ∀ ω, 0 ≤ Z T ω) + (hDsm : ∀ u, StronglyMeasurable[𝓕 u] (D u)) + (hZ : Martingale Z 𝓕 P) (hM : Martingale M 𝓕 P) + (hZDM : ∀ u, u ≤ T → (fun ω ↦ Z u ω * D u ω) =ᵐ[P] M u) + (hmix : ∀ u, u ≤ T → Integrable (fun ω ↦ D u ω * Z T ω) P) + {s t : ℝ≥0} (hst : s ≤ t) (htT : t ≤ T) + {A : Set Ω} (hA : MeasurableSet[𝓕 s] A) : + ∫ ω in A, D t ω ∂(P.withDensity (fun ω ↦ ENNReal.ofReal (Z T ω))) + = ∫ ω in A, D s ω ∂(P.withDensity (fun ω ↦ ENNReal.ofReal (Z T ω))) := by + have hAmΩ : MeasurableSet A := 𝓕.le s A hA + -- `∫_A D_u dQ = ∫_A Z_u D_u dP` for `s ≤ u ≤ T` (withDensity conversion + Bayes pull-out). + have helper : ∀ u, s ≤ u → u ≤ T → + ∫ ω in A, D u ω ∂(P.withDensity (fun ω ↦ ENNReal.ofReal (Z T ω))) + = ∫ ω in A, Z u ω * D u ω ∂P := by + intro u hsu huT + have hAu : MeasurableSet[𝓕 u] A := 𝓕.mono hsu A hA + rw [setIntegral_withDensity_eq_setIntegral_toReal_smul hZmeasT.ennreal_ofReal + (ae_of_all (P.restrict A) fun _ ↦ ENNReal.ofReal_lt_top) _ hAmΩ] + have hconv : ∀ ω, (ENNReal.ofReal (Z T ω)).toReal • D u ω = D u ω * Z T ω := by + intro ω; rw [ENNReal.toReal_ofReal (hZpos ω), smul_eq_mul, mul_comm] + simp_rw [hconv] + rw [← setIntegral_condExp (𝓕.le u) (hmix u huT) hAu] + have hae : P[fun ω ↦ D u ω * Z T ω | 𝓕 u] =ᵐ[P] fun ω ↦ Z u ω * D u ω := by + have h1 := condExp_mul_of_stronglyMeasurable_left (m := 𝓕 u) + (hDsm u) (hmix u huT) (hZ.integrable T) + refine h1.trans ?_ + filter_upwards [hZ.condExp_ae_eq huT] with ω hh2 + simp only [Pi.mul_apply, hh2]; ring + exact setIntegral_congr_ae hAmΩ (hae.mono fun ω h _ ↦ h) + rw [helper t hst htT, helper s le_rfl (hst.trans htT), + setIntegral_congr_ae hAmΩ ((hZDM t htT).mono fun ω h _ ↦ h), + setIntegral_congr_ae hAmΩ ((hZDM s (hst.trans htT)).mono fun ω h _ ↦ h)] + exact (hM.setIntegral_eq hst hA).symm + +/-- **Bayes change-of-measure engine (full-martingale form).** The special case of +`changeOfMeasure_setIntegral_eq_of_ae_martingale` where the product `Z · D` is itself a +`P`-martingale (take `M := Z · D`, so the `=ᵐ` hypothesis is reflexivity): then `D` is a martingale +under `Q := P.withDensity (Z_T)` on `[0,T]`. This is the constant-θ Girsanov situation, where +`Z · D = Wald(a−θ)` is a genuine martingale everywhere. -/ +theorem changeOfMeasure_setIntegral_eq + {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + {𝓕 : Filtration ℝ≥0 mΩ} [SigmaFiniteFiltration P 𝓕] + {Z D : ℝ≥0 → Ω → ℝ} (T : ℝ≥0) + (hZmeasT : Measurable (Z T)) (hZpos : ∀ ω, 0 ≤ Z T ω) + (hDsm : ∀ u, StronglyMeasurable[𝓕 u] (D u)) + (hZ : Martingale Z 𝓕 P) + (hZD : Martingale (fun t ω ↦ Z t ω * D t ω) 𝓕 P) + (hmix : ∀ u, u ≤ T → Integrable (fun ω ↦ D u ω * Z T ω) P) + {s t : ℝ≥0} (hst : s ≤ t) (htT : t ≤ T) + {A : Set Ω} (hA : MeasurableSet[𝓕 s] A) : + ∫ ω in A, D t ω ∂(P.withDensity (fun ω ↦ ENNReal.ofReal (Z T ω))) + = ∫ ω in A, D s ω ∂(P.withDensity (fun ω ↦ ENNReal.ofReal (Z T ω))) := + changeOfMeasure_setIntegral_eq_of_ae_martingale T hZmeasT hZpos hDsm hZ hZD + (fun _ _ ↦ Filter.EventuallyEq.rfl) hmix hst htT hA + +end MathFin diff --git a/LeanPool/MathFin/Probability/Martingales/EquivMeasure.lean b/LeanPool/MathFin/Probability/Martingales/EquivMeasure.lean new file mode 100644 index 0000000000..dc46fe4627 --- /dev/null +++ b/LeanPool/MathFin/Probability/Martingales/EquivMeasure.lean @@ -0,0 +1,151 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.InnerProductSpace.Basic +public import Mathlib.MeasureTheory.Integral.Bochner.Basic +public import Mathlib.MeasureTheory.Measure.Decomposition.RadonNikodym + +/-! +# Equivalent probability measures, and the one from a positive normalised density + +`IsEquivProbMeasure P Q` (`Q` a probability measure with `Q ≪ P` and `P ≪ Q`) is the prefix every +equivalent-martingale-measure structure of the library extends. + +A strictly-positive, `P`-integrable density `g` with `∫ g ∂P = 1` defines an +**equivalent probability measure** `P.withDensity (fun ω ↦ ENNReal.ofReal (g ω))`: it is a +probability measure (total mass `∫ g = 1`) and mutually absolutely continuous with `P` +(`withDensity` is always `≪ P`, and `P ≪` it because the density is a.e. nonzero). + +This is the change-of-measure ritual shared by the equivalent-martingale-measure constructions +in the one-period FTAP files (`FTAPOnePeriod.lean`, `FTAPOnePeriodVector.lean`): each builds its +fair density (a logistic Esscher weight, or a `(1+‖Y‖)⁻¹` tempering for the `L¹` reduction), +normalises it, and then needs exactly `IsEquivProbMeasure P Q`. + +An equivalence on a sub-σ-algebra `m` extends to the whole space: `P` weighted by the density +`d(Q|m)/d(P|m)` of the restrictions is equivalent to `P` everywhere and is `Q` on `m` +(`exists_isEquivProbMeasure_trim_eq`). A pricing measure up to a horizon `T` need only be equivalent +to the reference measure on the information `𝓕 T`, and this is how it meets the theorems stated for +measures equivalent on the whole space. + +## Main definitions + +* `IsEquivProbMeasure`: `Q` is a probability measure with `Q ≪ P` and `P ≪ Q`. + +## Main results + +* `absolutelyContinuous_withDensity_ofReal`: an a.e. strictly positive density makes `P` + absolutely continuous with respect to `P.withDensity (ofReal g)`. +* `isEquivProbMeasure_withDensity_of_isProbabilityMeasure`: `P.withDensity (ofReal g)` for an a.e. + strictly positive density `g` is equivalent to `P` as soon as it is a probability measure. +* `isEquivProbMeasure_withDensity`: for a strictly positive, `P`-integrable `g` with `∫ g ∂P = 1`, + `P.withDensity (ofReal g)` is an equivalent probability measure. +* `trim_withDensity_rnDeriv_trim`: `P` weighted by `d(Q|m)/d(P|m)` restricts to `Q|m` on `m`, when + `Q|m ≪ P|m`. +* `integral_rnDeriv_trim_mul`: `∫ (d(Q|m)/d(P|m)) * g ∂P = ∫ g ∂Q` for `m`-measurable `g`, when + `Q|m ≪ P|m`. +* `exists_isEquivProbMeasure_trim_eq`: a probability measure equivalent to `P` on a sub-σ-algebra + agrees there with one equivalent to `P` on the whole space. + +## Tags + +equivalent probability measure, mutual absolute continuity, density, withDensity, +equivalent martingale measure, MSC 28A25, MSC 91G20 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory + +/-- A density that is a.e. strictly positive makes `P` absolutely continuous with respect to +`P.withDensity (fun ω ↦ ENNReal.ofReal (g ω))`: the density vanishes only on a `P`-null set. +(The other direction, `withDensity ≪ P`, is `withDensity_absolutelyContinuous` and needs +nothing.) -/ +theorem absolutelyContinuous_withDensity_ofReal {Ω : Type*} {mΩ : MeasurableSpace Ω} + (P : Measure Ω) {g : Ω → ℝ} (hmeas : AEMeasurable g P) (hpos : ∀ᵐ ω ∂P, 0 < g ω) : + P ≪ P.withDensity (fun ω ↦ ENNReal.ofReal (g ω)) := + withDensity_absolutelyContinuous' hmeas.ennreal_ofReal + (hpos.mono fun _ hω ↦ ENNReal.ofReal_pos.mpr hω |>.ne') + +/-- `Q` is an **equivalent probability measure** for `P`: a probability measure with the same null +sets, `Q ≪ P` and `P ≪ Q`. The prefix shared by every equivalent-martingale-measure structure of +the library (`IsEMM`, at every time index, and `OnePeriodVector.IsEMM`), which `extend` it. -/ +structure IsEquivProbMeasure {Ω : Type*} {mΩ : MeasurableSpace Ω} (P Q : Measure Ω) : Prop where + isProb : IsProbabilityMeasure Q + ac : Q ≪ P + ac' : P ≪ Q + +/-- `Q = P.withDensity (ofReal g)` for an a.e. strictly positive density `g` is an equivalent +probability measure as soon as it is a probability measure: `≪ P` holds for every density +(`withDensity_absolutelyContinuous`), `P ≪` by positivity +(`absolutelyContinuous_withDensity_ofReal`). -/ +theorem isEquivProbMeasure_withDensity_of_isProbabilityMeasure {Ω : Type*} + {mΩ : MeasurableSpace Ω} (P : Measure Ω) {g : Ω → ℝ} (hmeas : AEMeasurable g P) + (hpos : ∀ᵐ ω ∂P, 0 < g ω) + (hQ : IsProbabilityMeasure (P.withDensity (fun ω ↦ ENNReal.ofReal (g ω)))) : + IsEquivProbMeasure P (P.withDensity (fun ω ↦ ENNReal.ofReal (g ω))) := + ⟨hQ, withDensity_absolutelyContinuous _ _, absolutelyContinuous_withDensity_ofReal P hmeas hpos⟩ + +/-- A strictly-positive, `P`-integrable density `g` with `∫ g ∂P = 1` makes +`Q = P.withDensity (fun ω ↦ ENNReal.ofReal (g ω))` a probability measure equivalent to `P`. +(Measurability is not assumed: the integrability of `g` already makes it a.e.-measurable, which +is all `withDensity` needs.) -/ +theorem isEquivProbMeasure_withDensity {Ω : Type*} {mΩ : MeasurableSpace Ω} (P : Measure Ω) + {g : Ω → ℝ} (hpos : ∀ ω, 0 < g ω) (hint : Integrable g P) + (hsum : ∫ ω, g ω ∂P = 1) : + IsEquivProbMeasure P (P.withDensity (fun ω ↦ ENNReal.ofReal (g ω))) := + isEquivProbMeasure_withDensity_of_isProbabilityMeasure P hint.aemeasurable (ae_of_all _ hpos) + ⟨by + rw [withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ, + ← ofReal_integral_eq_lintegral_ofReal hint (ae_of_all _ fun ω ↦ (hpos ω).le), hsum, + ENNReal.ofReal_one]⟩ + +/-- **Weighting `P` by the density of the restrictions reproduces `Q` on `m`.** If `Q|m ≪ P|m`, the +measure `P.withDensity (d(Q|m)/d(P|m))` restricts to `Q|m` on `m ≤ m0`. -/ +theorem trim_withDensity_rnDeriv_trim {Ω : Type*} {m m0 : MeasurableSpace Ω} (hm : m ≤ m0) + {P Q : Measure Ω} [IsFiniteMeasure P] [IsFiniteMeasure Q] (hQP : Q.trim hm ≪ P.trim hm) : + (P.withDensity ((Q.trim hm).rnDeriv (P.trim hm))).trim hm = Q.trim hm := by + rw [trim_withDensity hm (Measure.measurable_rnDeriv _ _), Measure.withDensity_rnDeriv_eq _ _ hQP] + +/-- **Change of measure on a sub-σ-algebra.** If `Q|m ≪ P|m`, an `m`-measurable `g` has +`P`-expectation against the density `d(Q|m)/d(P|m)` of the restrictions equal to its +`Q`-expectation. -/ +theorem integral_rnDeriv_trim_mul {Ω : Type*} {m m0 : MeasurableSpace Ω} (hm : m ≤ m0) + {P Q : Measure Ω} [IsFiniteMeasure P] [IsFiniteMeasure Q] (hQP : Q.trim hm ≪ P.trim hm) + {g : Ω → ℝ} (hg : StronglyMeasurable[m] g) : + ∫ ω, ((Q.trim hm).rnDeriv (P.trim hm) ω).toReal * g ω ∂P = ∫ ω, g ω ∂Q := by + have hf : Measurable[m] ((Q.trim hm).rnDeriv (P.trim hm)) := Measure.measurable_rnDeriv _ _ + calc ∫ ω, ((Q.trim hm).rnDeriv (P.trim hm) ω).toReal * g ω ∂P + = ∫ ω, g ω ∂P.withDensity ((Q.trim hm).rnDeriv (P.trim hm)) := + (integral_withDensity_eq_integral_toReal_smul (hf.mono hm le_rfl) + (ae_of_ae_trim hm (Measure.rnDeriv_lt_top _ _)) g).symm + _ = ∫ ω, g ω ∂(P.withDensity ((Q.trim hm).rnDeriv (P.trim hm))).trim hm := + integral_trim hm hg + _ = ∫ ω, g ω ∂Q := by rw [trim_withDensity_rnDeriv_trim hm hQP, ← integral_trim hm hg] + +/-- **An equivalence on a sub-σ-algebra extends to the whole space.** If the probability measure `Q` +has the null sets of `P` among the events of `m ≤ m0`, then `P` weighted by the density +`d(Q|m)/d(P|m)` of the restrictions is a probability measure equivalent to `P` on all of `m0` that +is `Q` on `m`. The density is positive `P`-almost everywhere because `P|m ≪ Q|m`. -/ +theorem exists_isEquivProbMeasure_trim_eq {Ω : Type*} {m m0 : MeasurableSpace Ω} (hm : m ≤ m0) + {P Q : Measure Ω} [IsFiniteMeasure P] [IsProbabilityMeasure Q] (hQP : Q.trim hm ≪ P.trim hm) + (hPQ : P.trim hm ≪ Q.trim hm) : + ∃ Q' : Measure Ω, IsEquivProbMeasure P Q' ∧ Q'.trim hm = Q.trim hm := by + have hf : Measurable[m] ((Q.trim hm).rnDeriv (P.trim hm)) := Measure.measurable_rnDeriv _ _ + have htrim := trim_withDensity_rnDeriv_trim hm hQP + refine ⟨P.withDensity ((Q.trim hm).rnDeriv (P.trim hm)), + ⟨⟨?_⟩, withDensity_absolutelyContinuous _ _, ?_⟩, htrim⟩ + · rw [← trim_measurableSet_eq hm (@MeasurableSet.univ _ m), htrim, + trim_measurableSet_eq hm (@MeasurableSet.univ _ m), measure_univ] + · exact withDensity_absolutelyContinuous' (hf.mono hm le_rfl).aemeasurable + ((ae_of_ae_trim hm (hPQ.ae_le (Measure.rnDeriv_pos hQP))).mono fun _ h ↦ h.ne') + +end MathFin diff --git a/LeanPool/MathFin/Probability/Martingales/LocalisationInMeasure.lean b/LeanPool/MathFin/Probability/Martingales/LocalisationInMeasure.lean new file mode 100644 index 0000000000..e81ee10bed --- /dev/null +++ b/LeanPool/MathFin/Probability/Martingales/LocalisationInMeasure.lean @@ -0,0 +1,268 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Process.Adapted + +/-! # Localisation in the sample space + +A statement about a process with continuous paths is often proved first on the event that the +path stays in `[−N, N]` up to `T`, where the process may be replaced by a bounded one, and then +on all of `Ω`. This file collects what that needs, without stopping times. + +* **Convergence in measure is local** (`tendstoInMeasure_of_ae_eqOn`, `tendstoInMeasure_of_eqOn`): + if, on each of a sequence of events whose complements have measure tending to `0`, the sequence + agrees with one converging in measure, and the limit agrees with the other limit, the sequence + converges in measure. The events need not be measurable. +* **Limits in measure are local** (`ae_eq_of_tendstoInMeasure_of_eqOn`): two sequences converging + in measure that agree on an event have limits that agree almost everywhere on it. This is + Mathlib's `tendstoInMeasure_ae_unique` on an event. +* **Continuous paths stay bounded** (`tendsto_measure_compl_abs_le`): the events "the path stays + in `[−N, N]` up to `T`" exhaust `Ω` in probability. +* **Continuous modifications are indistinguishable** (`ae_forall_eq_of_continuousOn`) on + `[0, T]`: the analogue, for a closed interval, of Degenne's + `indistinguishable_of_modification_on`, which is stated on an open set. On events that shrink + with time the paths agree up to a random time (`ae_forall_eq_of_continuousOn_of_antitone`), and + two processes with continuous paths that are, at each time, limits in measure of the same + sequence are indistinguishable (`ae_forall_eq_of_tendstoInMeasure`). +* **Reading a process at a random level** (`measurableSet_forall_abs_le`, + `measurable_apply_countable`): for continuous paths "bounded by `R` on `[0, T]`" is an event, and + `ω ↦ f (n ω) ω` is measurable for a measurable `n` with countably many values. + +## Main results + +* `tendstoInMeasure_of_ae_eqOn`, `tendstoInMeasure_of_eqOn`: convergence in measure is local, on a + sequence of events whose complements have measure tending to `0`. +* `ae_eq_of_tendstoInMeasure_of_eqOn`: two sequences converging in measure that agree on an event + have limits that agree almost everywhere on it. +* `ae_forall_eq_of_continuousOn`: two processes with a.e. continuous paths on `[0, T]` that agree + a.e. at each time of `[0, T]` agree on all of `[0, T]` almost surely. +* `ae_forall_eq_of_continuousOn_of_antitone`: the same on a shrinking family of events, up to a + random time. +* `ae_forall_eq_of_tendstoInMeasure`: two such processes that are, at each time, limits in measure + of the same sequence are indistinguishable on `[0, T]`. +* `measurableSet_forall_abs_le`: for a process with continuous paths, "stays in `[−R, R]` on + `[0, T]`" is an event. +* `tendsto_measure_compl_abs_le`, `tendsto_measure_compl_abs_le_of_stronglyAdapted`: the measure + of the complement of `{∀ t ∈ [0, T], |X t| ≤ N}` tends to `0` as `N → ∞`. + +## Tags + +convergence in measure, localisation, continuous paths, indistinguishable processes, modification, +sample space event, MSC 60G07, MSC 28A25 +-/ + +@[expose] public section + +namespace MathFin +namespace LocalisationInMeasure + +open MeasureTheory Filter Topology Set +open scoped NNReal ENNReal + +/-! ### Limits in measure are local -/ + +/-- **Convergence in measure is local.** If on each of a sequence of events `A N`, whose +complements have measure tending to `0`, the sequence `g` agrees almost everywhere with a +sequence `G N` that converges in measure to `H N`, and `h` agrees with `H N` almost everywhere on +`A N`, then `g` converges in measure to `h`. The events need not be measurable. -/ +theorem tendstoInMeasure_of_ae_eqOn {Ω E : Type*} [MeasurableSpace Ω] [EDist E] {μ : Measure Ω} + {g : ℕ → Ω → E} {h : Ω → E} {A : ℕ → Set Ω} (hA : Tendsto (fun N ↦ μ (A N)ᶜ) atTop (𝓝 0)) + {G : ℕ → ℕ → Ω → E} {H : ℕ → Ω → E} (hGH : ∀ N, TendstoInMeasure μ (G N) atTop (H N)) + (hg : ∀ N n, ∀ᵐ ω ∂μ, ω ∈ A N → g n ω = G N n ω) + (hh : ∀ N, ∀ᵐ ω ∂μ, ω ∈ A N → h ω = H N ω) : + TendstoInMeasure μ g atTop h := by + intro ε hε + refine ENNReal.tendsto_atTop_zero.2 fun δ hδ ↦ ?_ + obtain ⟨N, hN⟩ := ENNReal.tendsto_atTop_zero.1 hA (δ / 2) (ENNReal.half_pos hδ.ne') + obtain ⟨n₀, hn₀⟩ := ENNReal.tendsto_atTop_zero.1 (hGH N ε hε) (δ / 2) (ENNReal.half_pos hδ.ne') + refine ⟨n₀, fun n hn ↦ ?_⟩ + have hgh : ∀ᵐ ω ∂μ, ω ∈ A N → g n ω = G N n ω ∧ h ω = H N ω := + ((hg N n).and (hh N)).mono fun ω hp hω ↦ ⟨hp.1 hω, hp.2 hω⟩ + calc μ {ω | ε ≤ edist (g n ω) (h ω)} + ≤ μ ((A N)ᶜ ∪ {ω | ε ≤ edist (G N n ω) (H N ω)} + ∪ {ω | ¬(ω ∈ A N → g n ω = G N n ω ∧ h ω = H N ω)}) := by + refine measure_mono fun ω hω ↦ ?_ + by_cases hωA : ω ∈ A N + · by_cases hωe : g n ω = G N n ω ∧ h ω = H N ω + · exact Or.inl (Or.inr (by simpa only [mem_ofPred_eq, hωe.1, hωe.2] using hω)) + · exact Or.inr fun h' ↦ hωe (h' hωA) + · exact Or.inl (Or.inl hωA) + _ ≤ μ (A N)ᶜ + μ {ω | ε ≤ edist (G N n ω) (H N ω)} + 0 := by + rw [← ae_iff.1 hgh] + exact (measure_union_le _ _).trans (add_le_add_left (measure_union_le _ _) _) + _ ≤ δ / 2 + δ / 2 + 0 := by gcongr; exacts [hN N le_rfl, hn₀ n hn] + _ = δ := by rw [add_zero, ENNReal.add_halves] + +/-- **Convergence in measure is local**, for sequences that agree everywhere on the events: +`tendstoInMeasure_of_ae_eqOn`. -/ +theorem tendstoInMeasure_of_eqOn {Ω E : Type*} [MeasurableSpace Ω] [EDist E] {μ : Measure Ω} + {g : ℕ → Ω → E} {h : Ω → E} {A : ℕ → Set Ω} (hA : Tendsto (fun N ↦ μ (A N)ᶜ) atTop (𝓝 0)) + {G : ℕ → ℕ → Ω → E} {H : ℕ → Ω → E} (hGH : ∀ N, TendstoInMeasure μ (G N) atTop (H N)) + (hg : ∀ N n, EqOn (g n) (G N n) (A N)) (hh : ∀ N, ∀ᵐ ω ∂μ, ω ∈ A N → h ω = H N ω) : + TendstoInMeasure μ g atTop h := + tendstoInMeasure_of_ae_eqOn hA hGH (fun N n ↦ Eventually.of_forall (hg N n)) hh + +/-- **Limits in measure are local.** Two sequences that agree on an event and converge in measure +have limits that agree almost everywhere on the event: along a common subsequence both converge +almost surely. On `A = univ` this is `tendstoInMeasure_ae_unique`. -/ +theorem ae_eq_of_tendstoInMeasure_of_eqOn {Ω E : Type*} [MeasurableSpace Ω] [EMetricSpace E] + {μ : Measure Ω} {g g' : ℕ → Ω → E} {h h' : Ω → E} {A : Set Ω} + (hg : TendstoInMeasure μ g atTop h) (hg' : TendstoInMeasure μ g' atTop h') + (heq : ∀ n, EqOn (g n) (g' n) A) : + ∀ᵐ ω ∂μ, ω ∈ A → h ω = h' ω := by + obtain ⟨n₁, hn₁, h1⟩ := hg.exists_seq_tendsto_ae + obtain ⟨n₂, hn₂, h2⟩ := (hg'.comp hn₁.tendsto_atTop).exists_seq_tendsto_ae + filter_upwards [h1, h2] with ω h1 h2 hω + exact tendsto_nhds_unique (h1.comp hn₂.tendsto_atTop) + (h2.congr fun i ↦ (heq _ hω).symm) + +/-! ### Bounded paths -/ + +/-- `[0, T]` has a countable dense subset. -/ +theorem exists_countable_dense_Icc (T : ℝ≥0) : + ∃ D ⊆ Icc (0 : ℝ≥0) T, D.Countable ∧ Icc 0 T ⊆ closure D := + (TopologicalSpace.IsSeparable.of_separableSpace _).exists_countable_dense_subset + +/-- A path continuous on `[0, T]` and bounded by `R` on a dense subset is bounded by `R` on +`[0, T]`. -/ +theorem abs_le_of_dense {T : ℝ≥0} {D : Set ℝ≥0} (hDI : D ⊆ Icc 0 T) (hDd : Icc 0 T ⊆ closure D) + {x : ℝ≥0 → ℝ} (hx : ContinuousOn x (Icc 0 T)) {R : ℝ} (h : ∀ t ∈ D, |x t| ≤ R) {t : ℝ≥0} + (ht : t ∈ Icc 0 T) : |x t| ≤ R := + abs_le.2 ((hx.preimage_isClosed_of_isClosed isClosed_Icc isClosed_Icc).closure_subset_iff.2 + (fun s hs ↦ ⟨hDI hs, abs_le.1 (h s hs)⟩) (hDd ht)).2 + +/-- A path continuous on `[0, T]` is bounded there by an integer. -/ +theorem exists_nat_abs_le_Icc {T : ℝ≥0} {x : ℝ≥0 → ℝ} (hx : ContinuousOn x (Icc 0 T)) : + ∃ N : ℕ, ∀ t ∈ Icc 0 T, |x t| ≤ N := by + obtain ⟨R, hR⟩ := isCompact_Icc.exists_bound_of_continuousOn hx + obtain ⟨N, hN⟩ := exists_nat_ge R + exact ⟨N, fun t ht ↦ (hR t ht).trans hN⟩ + +/-- **Two processes with continuous paths that agree at each time agree as paths, up to a random +time.** If almost every path of `Y` and of `Y'` is continuous on `[0, T]`, the event `A t` shrinks +as `t` grows, and at each `t ∈ [0, T]` the processes agree almost everywhere on `A t`, then almost +everywhere they agree at every `t ∈ [0, T]` with `ω ∈ A t`: at `0` and on a countable dense set of +times, and so at `t`, approached from the left, by continuity. The events need not be +measurable. -/ +theorem ae_forall_eq_of_continuousOn_of_antitone {Ω E : Type*} [MeasurableSpace Ω] + [TopologicalSpace E] [T2Space E] {μ : Measure Ω} {T : ℝ≥0} {Y Y' : ℝ≥0 → Ω → E} + (hY : ∀ᵐ ω ∂μ, ContinuousOn (fun t ↦ Y t ω) (Icc 0 T)) + (hY' : ∀ᵐ ω ∂μ, ContinuousOn (fun t ↦ Y' t ω) (Icc 0 T)) {A : ℝ≥0 → Set Ω} (hA : Antitone A) + (h : ∀ t ∈ Icc 0 T, ∀ᵐ ω ∂μ, ω ∈ A t → Y t ω = Y' t ω) : + ∀ᵐ ω ∂μ, ∀ t ∈ Icc 0 T, ω ∈ A t → Y t ω = Y' t ω := by + obtain ⟨D, hDI, hDc, hDd⟩ := exists_countable_dense_Icc T + filter_upwards [hY, hY', (ae_ball_iff hDc).2 fun t ht ↦ h t (hDI ht), + h 0 (left_mem_Icc.2 zero_le)] with ω h1 h2 hD h0 t ht hAt + rcases eq_zero_or_pos t with rfl | htpos + · exact h0 hAt + have hsub : Icc 0 t ⊆ Icc 0 T := Icc_subset_Icc_right ht.2 + exact EqOn.of_subset_closure (s := Ioo 0 t ∩ D) (fun s hs ↦ hD s hs.2 (hA hs.1.2.le hAt)) + (h1.mono hsub) (h2.mono hsub) (fun s hs ↦ Ioo_subset_Icc_self hs.1) + ((closure_Ioo htpos.ne).symm.subset.trans (closure_minimal (fun s hs ↦ + isOpen_Ioo.inter_closure ⟨hs, hDd ⟨zero_le, hs.2.le.trans ht.2⟩⟩) isClosed_closure)) + (right_mem_Icc.2 zero_le) + +/-- **Two modifications with continuous paths are indistinguishable on `[0, T]`.** If almost every +path of `Y` and of `Y'` is continuous on `[0, T]` and `Y t = Y' t` almost everywhere at each +`t ∈ [0, T]`, then almost everywhere `Y t = Y' t` at every `t ∈ [0, T]`. -/ +theorem ae_forall_eq_of_continuousOn {Ω E : Type*} [MeasurableSpace Ω] [TopologicalSpace E] + [T2Space E] {μ : Measure Ω} {T : ℝ≥0} {Y Y' : ℝ≥0 → Ω → E} + (hY : ∀ᵐ ω ∂μ, ContinuousOn (fun t ↦ Y t ω) (Icc 0 T)) + (hY' : ∀ᵐ ω ∂μ, ContinuousOn (fun t ↦ Y' t ω) (Icc 0 T)) + (h : ∀ t ∈ Icc 0 T, Y t =ᵐ[μ] Y' t) : + ∀ᵐ ω ∂μ, ∀ t ∈ Icc 0 T, Y t ω = Y' t ω := + (ae_forall_eq_of_continuousOn_of_antitone (A := fun _ ↦ univ) hY hY' antitone_const + fun t ht ↦ (h t ht).mono fun _ h _ ↦ h).mono fun ω h t ht ↦ h t ht (mem_univ ω) + +/-- **Two processes with continuous paths that are, at each time, limits in measure of the same +sequence are indistinguishable** on `[0, T]`. -/ +theorem ae_forall_eq_of_tendstoInMeasure {Ω E : Type*} [MeasurableSpace Ω] [EMetricSpace E] + {μ : Measure Ω} {T : ℝ≥0} {Y Y' : ℝ≥0 → Ω → E} + (hY : ∀ᵐ ω ∂μ, ContinuousOn (fun t ↦ Y t ω) (Icc 0 T)) + (hY' : ∀ᵐ ω ∂μ, ContinuousOn (fun t ↦ Y' t ω) (Icc 0 T)) {g : ℝ≥0 → ℕ → Ω → E} + (hg : ∀ t ∈ Icc 0 T, TendstoInMeasure μ (g t) atTop (Y t)) + (hg' : ∀ t ∈ Icc 0 T, TendstoInMeasure μ (g t) atTop (Y' t)) : + ∀ᵐ ω ∂μ, ∀ t ∈ Icc 0 T, Y t ω = Y' t ω := + ae_forall_eq_of_continuousOn hY hY' fun t ht ↦ tendstoInMeasure_ae_unique (hg t ht) (hg' t ht) + +/-- "The path stays in `[−R, R]` on a countable set of times" is an event. -/ +theorem measurableSet_forall_abs_le_of_countable {Ω : Type*} {mΩ : MeasurableSpace Ω} + {D : Set ℝ≥0} (hD : D.Countable) {X : ℝ≥0 → Ω → ℝ} (hXm : ∀ t ∈ D, Measurable (X t)) + (R : ℝ) : MeasurableSet {ω | ∀ t ∈ D, |X t ω| ≤ R} := by + simp only [ofPred_forall] + exact .biInter hD fun t ht ↦ + measurableSet_le (continuous_abs.measurable.comp (hXm t ht)) measurable_const + +/-- For a process with continuous paths, "the path stays in `[−R, R]` on `[0, T]`" is an event: +it is the event "bounded by `R` on a countable dense set of times" (`abs_le_of_dense`). -/ +theorem measurableSet_forall_abs_le {Ω : Type*} {mΩ : MeasurableSpace Ω} {T : ℝ≥0} + {X : ℝ≥0 → Ω → ℝ} (hXm : ∀ t ∈ Icc 0 T, Measurable (X t)) + (hXc : ∀ ω, ContinuousOn (fun t ↦ X t ω) (Icc 0 T)) (R : ℝ) : + MeasurableSet {ω | ∀ t ∈ Icc 0 T, |X t ω| ≤ R} := by + obtain ⟨D, hDI, hDc, hDd⟩ := exists_countable_dense_Icc T + refine (measurableSet_forall_abs_le_of_countable hDc (fun t ht ↦ hXm t (hDI ht)) R).congr ?_ + ext ω + simp only [mem_ofPred_eq] + exact ⟨fun h t ht ↦ abs_le_of_dense hDI hDd (hXc ω) h ht, fun h t ht ↦ h t (hDI ht)⟩ + +/-- **A family read at a random index is measurable**: for a countable index, `ω ↦ f (n ω) ω` is +measurable when `n` and each `f i` are. It is the first step of Mathlib's `Measurable.find`. -/ +theorem measurable_apply_countable {Ω ι β : Type*} {mΩ : MeasurableSpace Ω} [MeasurableSpace ι] + [Countable ι] [MeasurableSingletonClass ι] [MeasurableSpace β] {f : ι → Ω → β} + (hf : ∀ i, Measurable (f i)) {n : Ω → ι} (hn : Measurable n) : + Measurable fun ω ↦ f (n ω) ω := + (measurable_from_prod_countable_left (f := fun p : Ω × ι ↦ f p.2 p.1) hf).comp + (measurable_id.prodMk hn) + +/-- **A process with continuous paths stays in `[−N, N]` up to `T` with probability tending to +`1`.** The events are not assumed measurable. Their complements are covered by the +non-continuity null set and the complements of the measurable events "bounded by `N` on a +countable dense set", which decrease to a null set. -/ +theorem tendsto_measure_compl_abs_le {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsFiniteMeasure μ] {T : ℝ≥0} {X : ℝ≥0 → Ω → ℝ} + (hXm : ∀ t, Measurable (X t)) (hXc : ∀ᵐ ω ∂μ, ContinuousOn (fun t ↦ X t ω) (Icc 0 T)) : + Tendsto (fun N : ℕ ↦ μ {ω | ∀ t ∈ Icc 0 T, |X t ω| ≤ N}ᶜ) atTop (𝓝 0) := by + obtain ⟨D, hDI, hDc, hDd⟩ := exists_countable_dense_Icc T + set G : ℕ → Set Ω := fun N ↦ {ω | ∀ t ∈ D, |X t ω| ≤ N} + have hGm (N : ℕ) : MeasurableSet (G N) := + measurableSet_forall_abs_le_of_countable hDc (fun t _ ↦ hXm t) N + have hGlim := tendsto_measure_iInter_atTop (μ := μ) (s := fun N ↦ (G N)ᶜ) + (fun N ↦ (hGm N).compl.nullMeasurableSet) + (fun N M hNM ↦ compl_subset_compl.2 fun ω hω t ht ↦ (hω t ht).trans (Nat.cast_le.2 hNM)) + ⟨0, measure_ne_top _ _⟩ + have hnull : μ {ω | ¬ContinuousOn (fun t ↦ X t ω) (Icc 0 T)} = 0 := ae_iff.1 hXc + have hinter : μ (⋂ N, (G N)ᶜ) = 0 := by + refine measure_mono_null ?_ hnull + intro ω hω hc + obtain ⟨N, hN⟩ := exists_nat_abs_le_Icc hc + exact mem_iInter.1 hω N fun t ht ↦ hN t (hDI ht) + rw [hinter] at hGlim + refine tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds hGlim (fun _ ↦ bot_le) + fun N ↦ ?_ + calc μ {ω | ∀ t ∈ Icc 0 T, |X t ω| ≤ N}ᶜ + ≤ μ ({ω | ¬ContinuousOn (fun t ↦ X t ω) (Icc 0 T)} ∪ (G N)ᶜ) := by + refine measure_mono fun ω hω ↦ ?_ + by_cases hc : ContinuousOn (fun t ↦ X t ω) (Icc 0 T) + · exact Or.inr fun hG ↦ hω fun t ht ↦ abs_le_of_dense hDI hDd hc hG ht + · exact Or.inl hc + _ ≤ μ {ω | ¬ContinuousOn (fun t ↦ X t ω) (Icc 0 T)} + μ (G N)ᶜ := measure_union_le _ _ + _ = μ (G N)ᶜ := by rw [hnull, zero_add] + +/-- **An adapted process with continuous paths stays in `[−N, N]` up to `T` with probability +tending to `1`** (`tendsto_measure_compl_abs_le`). -/ +theorem tendsto_measure_compl_abs_le_of_stronglyAdapted {Ω : Type*} {mΩ : MeasurableSpace Ω} + {μ : Measure Ω} [IsFiniteMeasure μ] {𝓕 : Filtration ℝ≥0 mΩ} {T : ℝ≥0} {X : ℝ≥0 → Ω → ℝ} + (hX : StronglyAdapted 𝓕 X) (hXc : ∀ ω, Continuous fun t ↦ X t ω) : + Tendsto (fun N : ℕ ↦ μ {ω | ∀ t ∈ Icc 0 T, |X t ω| ≤ N}ᶜ) atTop (𝓝 0) := + tendsto_measure_compl_abs_le (fun t ↦ ((hX t).mono (𝓕.le t)).measurable) + (.of_forall fun ω ↦ (hXc ω).continuousOn) + +end LocalisationInMeasure +end MathFin diff --git a/LeanPool/MathFin/Probability/Martingales/LpContinuousMartingaleConvergence.lean b/LeanPool/MathFin/Probability/Martingales/LpContinuousMartingaleConvergence.lean new file mode 100644 index 0000000000..ffcc6e018a --- /dev/null +++ b/LeanPool/MathFin/Probability/Martingales/LpContinuousMartingaleConvergence.lean @@ -0,0 +1,608 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Discrete.MartingaleDominator +public import TauCeti.MeasureTheory.Function.UniformIntegrable +public import LeanPool.MathFin.Probability.Support.DoobContinuous +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.Order.CompletePartialOrder +public import Mathlib.Probability.Martingale.Convergence + +/-! +# Lp continuous-martingale convergence (Theorem 4.3.10, Saporito) + +A continuous martingale `(M_t)` bounded in `L^p` (`p ≥ 1`) converges almost +surely to an integrable `M_∞`; for `p > 1` it also converges in `L^p`. + + Proof strategy: + 1. Sample at natural times: `N_k(ω) := M (k : ℝ) ω` is a discrete + martingale with respect to the sub-filtration `𝓕_k := 𝓕 (k : ℝ)`. + 2. The L^p bound transfers to N (since N_k = M_k for k : ℕ). + Also L^1 bound from finite measure + L^p bound (Hölder when p > 1, + direct when p = 1). + 3. Apply Mathlib's `Submartingale.exists_ae_tendsto_of_bdd` to get + almost-sure convergence of N at natural times. + 4. By path continuity, the continuous-time limit at `t → ∞` agrees + with the natural-time limit. (This step uses Doob's L^p maximal + inequality on the increment martingale to show + `sup_{n ≤ t ≤ n+1} |M_t - M_n| → 0` in probability.) + 5. For `p > 1`: L^p-boundedness gives uniform integrability in L^p + (de la Vallée-Poussin) and combined with a.s. convergence yields + L^p convergence (Vitali). + + Steps 3, 4, and 5 are all proved below. + + Step 3 (`p ≥ 1`, natural-time a.s. convergence): proved as + `lp_continuous_martingale_converges_at_naturals`. Uses Mathlib's + `Submartingale.ae_tendsto_limitProcess` after transferring the `L^p` bound + to an `L^1` bound (Hölder on a finite measure space) at the natural-time + sub-filtration. + + Step 4 (continuous-time bridge, `p > 1`, real-time in-measure): proved as + `lp_continuous_martingale_tendstoInMeasure`. The increment martingale + `Y_n(s) := M(n + s) − M(n)` is built on `shiftedFiltration 𝓕 n` via + `Martingale.sub` of a shifted process and a constant; right-continuity + transfers from `M`. The Tau Ceti bound via `maximal_ineq_norm` controls the running max, + the eLpNorm-triangle + Hölder gives `‖M_(n+1) − M_n‖_1 → 0`, and + Tau Ceti's `Martingale.ae_iSup_eNorm_lt_top` gives an a.s. bound for the running max. + A `Nat.floor` set-inclusion argument then closes the conclusion modulo a + μ-null set. The combined natural-a.s. + real-in-measure form is + `lp_continuous_martingale_full`. + + Step 5 (`p > 1`, natural-time `L^p` convergence): proved as + `lp_continuous_martingale_tendsto_eLpNorm_at_naturals`. Tau Ceti's Doob + inequality `Martingale.eLpNorm_partialSups_norm_le` bounds the running max; + monotone convergence (`lintegral_iSup'`) lifts it to the infinite sup + `S ω := ⨆_k ‖N_k ω‖ₑ`, yielding `MemLp ((S ω).toReal) p` — the envelope + dominator `MeasureTheory.LpDominator.dominator`, shared with + `L2MartingaleConvergence`. The domination lemma + `MemLp.uniformIntegrable_of_eNorm_le` from + `TauCeti.MeasureTheory.Function.UniformIntegrable` then gives + `UniformIntegrable (discreteSample M) (ofReal p) μ`, and Mathlib's Vitali + (`tendsto_Lp_finite_of_tendsto_ae`) closes it. + + The textbook claims real-time a.s. convergence (under continuous paths) + and real-time `L^p` convergence (under uniform integrability lifted to + real time). Both require cadlag paths, which this file does not assume — + only right-continuity. The in-measure form is the canonical conclusion + for right-continuous martingales. + +## Main definitions + +* `discreteSample`: the sample `n ↦ M n` of a continuous-time process at the natural times. +* `natTimeSubfiltration`: the filtration `k ↦ 𝓕 k` at the natural times. +* `discreteSampleLimit`: the almost-sure limit of the discrete sample, from Mathlib's + `Filtration.limitProcess`. +* `shiftedFiltration`: the filtration `t ↦ 𝓕 (n + t)` on `ℝ≥0`. +* `incrementProc`: the increment process `Y_n t = M (n + t) − M n`. + +## Main results + +* `lp_continuous_martingale_converges_at_naturals`: a martingale bounded in `Lᵖ` (`p ≥ 1`) on a + finite measure space has an integrable `M_inf` with `M n → M_inf` almost surely along the + natural times. +* `lp_continuous_martingale_tendsto_eLpNorm_at_naturals`: for `p > 1` and an `Lᵖ` bound `R`, + `M n → discreteSampleLimit` in `Lᵖ` along the natural times. +* `lp_continuous_martingale_tendstoInMeasure`: for `p > 1` and right-continuous paths, + `M t → discreteSampleLimit` in measure as `t → ∞` over real times. +* `lp_continuous_martingale_full`: for `p > 1` and right-continuous paths, an integrable `M_inf` + with a.s. convergence along the natural times and convergence in measure over real times. + +## References + +* [Y. F. Saporito, *Stochastic Processes*][Saporito], Theorem 4.3.10 + +## Tags + +martingale convergence theorem, Lp-bounded martingale, Doob maximal inequality, +continuous martingale, Vitali, almost sure convergence, MSC 60G44, MSC 60G42, MSC 60F15 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Filter +open scoped Topology ENNReal NNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- Discrete-time sample of a continuous-time process at natural times. -/ +noncomputable def discreteSample (M : ℝ → Ω → ℝ) (n : ℕ) (ω : Ω) : ℝ := + M (n : ℝ) ω + +/-- Sub-filtration at natural times. -/ +def natTimeSubfiltration (𝓕 : Filtration ℝ mΩ) : Filtration ℕ mΩ where + seq n := 𝓕 (n : ℝ) + mono' n m hnm := 𝓕.mono (by exact_mod_cast hnm) + le' n := 𝓕.le _ + +/-- A continuous martingale sampled at natural times is a discrete + martingale with respect to the natural-time sub-filtration. -/ +private lemma discreteSample_martingale + {μ : Measure Ω} {𝓕 : Filtration ℝ mΩ} {M : ℝ → Ω → ℝ} + (hM : Martingale M 𝓕 μ) : + Martingale (discreteSample M) (natTimeSubfiltration 𝓕) μ := by + refine ⟨?_, ?_⟩ + · intro n + exact hM.stronglyAdapted (n : ℝ) + · intro i j hij + have hij' : (i : ℝ) ≤ (j : ℝ) := by exact_mod_cast hij + exact hM.2 (i : ℝ) (j : ℝ) hij' + +/-- L^1-norm bound from L^p-norm bound on a finite measure space (Hölder). -/ +lemma eLpNorm_one_le_of_eLpNorm_p + {μ : Measure Ω} {f : Ω → ℝ} {p : ℝ} (hp : 1 ≤ p) + {R : ℝ} (hR : eLpNorm f (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) + (hfm : AEStronglyMeasurable f μ) : + eLpNorm f 1 μ ≤ ENNReal.ofReal R * μ Set.univ ^ ((1 : ℝ) - 1 / p) := by + have hp_pos : 0 < p := lt_of_lt_of_le zero_lt_one hp + have h1_le_p : (1 : ℝ≥0∞) ≤ ENNReal.ofReal p := by + rw [show (1 : ℝ≥0∞) = ENNReal.ofReal 1 by simp] + exact ENNReal.ofReal_le_ofReal hp + refine (eLpNorm_le_eLpNorm_mul_rpow_measure_univ + (μ := μ) (p := 1) (q := ENNReal.ofReal p) (f := f) h1_le_p hfm).trans ?_ + rw [ENNReal.toReal_one, ENNReal.toReal_ofReal hp_pos.le, one_div_one] + gcongr + +/-- The L^1 bound for the discrete sample, expressed as `ℝ≥0` for the + Mathlib submartingale-convergence API. -/ +private lemma discreteSample_l1_bounded + {μ : Measure Ω} [IsFiniteMeasure μ] {𝓕 : Filtration ℝ mΩ} + {M : ℝ → Ω → ℝ} {p R : ℝ} (hp : 1 ≤ p) + (hM : Martingale M 𝓕 μ) + (hbound : ∀ t, eLpNorm (M t) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) : + ∃ R' : ℝ≥0, + ∀ n : ℕ, eLpNorm (discreteSample M n) 1 μ ≤ (R' : ℝ≥0∞) := by + have hp_pos : 0 < p := lt_of_lt_of_le zero_lt_one hp + have h_exp_nn : 0 ≤ (1 : ℝ) - 1 / p := by + have : 1 / p ≤ 1 := (div_le_one hp_pos).mpr hp + linarith + set bound : ℝ≥0∞ := ENNReal.ofReal R * μ Set.univ ^ ((1 : ℝ) - 1 / p) + have hbound_lt_top : bound < ⊤ := + ENNReal.mul_lt_top ENNReal.ofReal_lt_top + (ENNReal.rpow_lt_top_of_nonneg h_exp_nn (measure_ne_top _ _)) + refine ⟨bound.toNNReal, fun n ↦ ?_⟩ + rw [ENNReal.coe_toNNReal hbound_lt_top.ne] + exact eLpNorm_one_le_of_eLpNorm_p hp (hbound (n : ℝ)) + ((hM.stronglyMeasurable (n : ℝ)).mono (𝓕.le _)).aestronglyMeasurable + +/-- The canonical limit of the discrete sample: a `(⨆ k, 𝓕 k)`-measurable + function to which the sample converges a.s. Defined via Mathlib's + `Filtration.limitProcess`. -/ +noncomputable def discreteSampleLimit + (μ : Measure Ω) (𝓕 : Filtration ℝ mΩ) + (M : ℝ → Ω → ℝ) : Ω → ℝ := + (natTimeSubfiltration 𝓕).limitProcess (discreteSample M) μ + +/-- The discrete sample converges a.s. to its limit process. -/ +private lemma discreteSample_ae_tendsto_limitProcess + {μ : Measure Ω} [IsFiniteMeasure μ] {𝓕 : Filtration ℝ mΩ} + {M : ℝ → Ω → ℝ} {p R : ℝ} (hp : 1 ≤ p) + (hM : Martingale M 𝓕 μ) + (hbound : ∀ t, eLpNorm (M t) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) : + ∀ᵐ ω ∂μ, + Tendsto (fun n : ℕ ↦ M (n : ℝ) ω) atTop (𝓝 (discreteSampleLimit μ 𝓕 M ω)) := by + obtain ⟨R', hR'⟩ := discreteSample_l1_bounded hp hM hbound + exact (discreteSample_martingale hM).submartingale.ae_tendsto_limitProcess + ((iSup_le hR').trans_lt ENNReal.coe_lt_top) + +/-- The limit process is integrable (in `L^1`). -/ +private lemma discreteSampleLimit_integrable + {μ : Measure Ω} [IsFiniteMeasure μ] {𝓕 : Filtration ℝ mΩ} + {M : ℝ → Ω → ℝ} {p R : ℝ} (hp : 1 ≤ p) + (hM : Martingale M 𝓕 μ) + (hbound : ∀ t, eLpNorm (M t) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) : + Integrable (discreteSampleLimit μ 𝓕 M) μ := by + obtain ⟨R', hR'⟩ := discreteSample_l1_bounded hp hM hbound + have hAE : ∀ n, AEStronglyMeasurable (discreteSample M n) μ := fun n ↦ + (((discreteSample_martingale hM).stronglyMeasurable n).mono + ((natTimeSubfiltration 𝓕).le _)).aestronglyMeasurable + have h_memLp : MemLp (discreteSampleLimit μ 𝓕 M) 1 μ := + MeasureTheory.Filtration.memLp_limitProcess_of_eLpNorm_bdd hAE + ((iSup_le hR').trans_lt ENNReal.coe_lt_top) + exact h_memLp.integrable le_rfl + +/-- Theorem 4.3.10 (Saporito Ch 4.3), natural-time formulation. + + A continuous-time martingale `(M_t)` bounded in `L^p` (`p ≥ 1`) + sampled at natural times `t = n : ℕ` converges almost surely to an + integrable limit `M_∞ := (natTimeSubfiltration 𝓕).limitProcess`. + + This is the discrete-time skeleton of Theorem 4.3.10. The full + continuous-time conclusion `Tendsto (fun t : ℝ ↦ M t ω) atTop ...` + follows from this skeleton + path continuity + a maximal-oscillation + bound (via Doob's `L^p` inequality applied to the increment martingale + `(M_t - M_n)_{t ∈ [n, n+1]}`). For `p > 1`, the `L^p` convergence + follows from a.s. convergence + uniform integrability in `L^p`. Both + extensions are documented as follow-on work. -/ +theorem lp_continuous_martingale_converges_at_naturals + {μ : Measure Ω} [IsFiniteMeasure μ] {𝓕 : Filtration ℝ mΩ} + {M : ℝ → Ω → ℝ} {p : ℝ} (hp : 1 ≤ p) + (hM : Martingale M 𝓕 μ) + (hbound : ∃ R : ℝ, + ∀ t, eLpNorm (M t) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) : + ∃ (M_inf : Ω → ℝ), Integrable M_inf μ ∧ + ∀ᵐ ω ∂μ, Tendsto (fun n : ℕ ↦ M (n : ℝ) ω) atTop (𝓝 (M_inf ω)) := by + obtain ⟨R, hR⟩ := hbound + exact ⟨discreteSampleLimit μ 𝓕 M, + discreteSampleLimit_integrable hp hM hR, + discreteSample_ae_tendsto_limitProcess hp hM hR⟩ + +/-! ### Step 5: `L^p` convergence at natural times (`p > 1`). -/ + +open MeasureTheory.LpDominator in +/-- L^p convergence at natural times (for `p > 1`). The discrete sample of an +`L^p`-bounded continuous martingale converges to the limit process in `L^p`. -/ +theorem lp_continuous_martingale_tendsto_eLpNorm_at_naturals + {μ : Measure Ω} [IsFiniteMeasure μ] {𝓕 : Filtration ℝ mΩ} + {M : ℝ → Ω → ℝ} {p R : ℝ} (hp : 1 < p) + (hM : Martingale M 𝓕 μ) + (hbound : ∀ t, eLpNorm (M t) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) : + Tendsto (fun n : ℕ ↦ eLpNorm + (fun ω ↦ M (n : ℝ) ω - discreteSampleLimit μ 𝓕 M ω) (ENNReal.ofReal p) μ) + atTop (𝓝 0) := by + have hp_one_enn : (1 : ℝ≥0∞) ≤ ENNReal.ofReal p := ENNReal.one_le_ofReal.mpr hp.le + have h_sample_meas : ∀ n, AEStronglyMeasurable (discreteSample M n) μ := fun n ↦ + (((discreteSample_martingale hM).stronglyMeasurable n).mono + ((natTimeSubfiltration 𝓕).le _)).aestronglyMeasurable + have hdom := dominator_memLp hp (discreteSample_martingale hM) (fun n ↦ hbound n) + have hui := hdom.uniformIntegrable_of_eNorm_le hp_one_enn ENNReal.ofReal_ne_top h_sample_meas + (fun n ↦ (norm_le_dominator hp (discreteSample_martingale hM) + (fun k ↦ hbound k) n).mono fun _ h ↦ by + simpa only [← ofReal_norm, Real.norm_eq_abs] using + ENNReal.ofReal_le_ofReal (h.trans (le_abs_self _))) + exact tendsto_Lp_finite_of_tendsto_ae hp_one_enn ENNReal.ofReal_ne_top h_sample_meas + (Submartingale.memLp_limitProcess (discreteSample_martingale hM).submartingale + ((iSup_le fun (n : ℕ) ↦ hbound (n : ℝ)).trans_lt ENNReal.ofReal_lt_top)) + hui.unifIntegrable (discreteSample_ae_tendsto_limitProcess hp.le hM hbound) + +/-! ### Step 4: Continuous-time bridge. -/ + +/-- Shifted filtration on `ℝ≥0` starting at natural index `n`: +`(shiftedFiltration 𝓕 n).seq t = 𝓕 ((n : ℝ) + t)`. -/ +def shiftedFiltration (𝓕 : Filtration ℝ mΩ) (n : ℕ) : Filtration ℝ≥0 mΩ where + seq t := 𝓕 ((n : ℝ) + (t : ℝ)) + mono' s t hst := 𝓕.mono <| by + have : (s : ℝ) ≤ (t : ℝ) := by exact_mod_cast hst + linarith + le' _ := 𝓕.le _ + +/-- Shifted continuous-time process `(t : ℝ≥0) ↦ M ((n : ℝ) + t)`. -/ +private noncomputable def shiftedProc (M : ℝ → Ω → ℝ) (n : ℕ) (t : ℝ≥0) (ω : Ω) : ℝ := + M ((n : ℝ) + (t : ℝ)) ω + +/-- Constant-in-time process `(_ : ℝ≥0) ↦ M (n : ℝ)`. -/ +private noncomputable def constProc (M : ℝ → Ω → ℝ) (n : ℕ) (_t : ℝ≥0) (ω : Ω) : ℝ := + M (n : ℝ) ω + +/-- Increment process `Y_n t ω := M ((n : ℝ) + t) ω - M (n : ℝ) ω`, indexed by `t : ℝ≥0`. -/ +noncomputable def incrementProc (M : ℝ → Ω → ℝ) (n : ℕ) (t : ℝ≥0) (ω : Ω) : ℝ := + M ((n : ℝ) + (t : ℝ)) ω - M (n : ℝ) ω + +private lemma shiftedProc_martingale {μ : Measure Ω} {𝓕 : Filtration ℝ mΩ} + {M : ℝ → Ω → ℝ} (hM : Martingale M 𝓕 μ) (n : ℕ) : + Martingale (shiftedProc M n) (shiftedFiltration 𝓕 n) μ := by + refine ⟨fun t ↦ hM.stronglyMeasurable _, fun s t hst ↦ ?_⟩ + have h_le : (n : ℝ) + (s : ℝ) ≤ (n : ℝ) + (t : ℝ) := by + have hs_le_t : (s : ℝ) ≤ (t : ℝ) := by + exact_mod_cast hst + linarith + exact hM.condExp_ae_eq h_le + +private lemma constProc_martingale {μ : Measure Ω} [IsFiniteMeasure μ] {𝓕 : Filtration ℝ mΩ} + {M : ℝ → Ω → ℝ} (hM : Martingale M 𝓕 μ) (n : ℕ) : + Martingale (constProc M n) (shiftedFiltration 𝓕 n) μ := by + have h_le_shifted : ∀ s : ℝ≥0, + (𝓕 (n : ℝ) : MeasurableSpace Ω) ≤ (shiftedFiltration 𝓕 n).seq s := fun s ↦ + 𝓕.mono (by + have hs_nonneg : (0 : ℝ) ≤ (s : ℝ) := s.coe_nonneg + linarith) + refine ⟨fun t ↦ (hM.stronglyMeasurable _).mono (h_le_shifted t), fun s _t _hst ↦ ?_⟩ + have hM_meas : StronglyMeasurable[(shiftedFiltration 𝓕 n).seq s] (M (n : ℝ)) := + (hM.stronglyMeasurable _).mono (h_le_shifted s) + change μ[fun ω ↦ M (n : ℝ) ω | (shiftedFiltration 𝓕 n).seq s] =ᵐ[μ] fun ω ↦ M (n : ℝ) ω + rw [condExp_of_stronglyMeasurable ((shiftedFiltration 𝓕 n).le _) hM_meas (hM.integrable _)] + +private lemma incrementProc_eq_sub (M : ℝ → Ω → ℝ) (n : ℕ) : + incrementProc M n = shiftedProc M n - constProc M n := rfl + +private lemma incrementProc_martingale {μ : Measure Ω} [IsFiniteMeasure μ] {𝓕 : Filtration ℝ mΩ} + {M : ℝ → Ω → ℝ} (hM : Martingale M 𝓕 μ) (n : ℕ) : + Martingale (incrementProc M n) (shiftedFiltration 𝓕 n) μ := by + rw [incrementProc_eq_sub] + exact (shiftedProc_martingale hM n).sub (constProc_martingale hM n) + +/-- Right-continuity of `M (· , ω)` transfers to the increment `incrementProc M n (· , ω)`. -/ +private lemma incrementProc_isRightContinuous + {M : ℝ → Ω → ℝ} (hM_cont : ∀ ω, _root_.IsRightContinuous (fun t : ℝ ↦ M t ω)) + (n : ℕ) (ω : Ω) : + _root_.IsRightContinuous (fun t : ℝ≥0 ↦ incrementProc M n t ω) := by + intro a + refine ContinuousWithinAt.sub ?_ continuousWithinAt_const + set shift : ℝ≥0 → ℝ := fun t ↦ ((n : ℝ) + (t : ℝ)) with shift_def + have h_shift_cont : Continuous shift := + continuous_const.add NNReal.continuous_coe + have h_f_rc : ContinuousWithinAt (fun u : ℝ ↦ M u ω) (Set.Ioi (shift a)) (shift a) := + hM_cont ω _ + have h_mapsto : Set.MapsTo shift (Set.Ioi a) (Set.Ioi (shift a)) := fun t ht ↦ by + have hlt : (a : ℝ) < (t : ℝ) := by + exact_mod_cast ht + change shift a < shift t + simp only [shift_def] + linarith + exact h_f_rc.comp h_shift_cont.continuousWithinAt h_mapsto + +/-- L^p triangle: `eLpNorm (M_(n+1) - M_n) p μ → 0` from step 5 + reindex. -/ +lemma eLpNorm_increment_p_tendsto_zero + {μ : Measure Ω} [IsFiniteMeasure μ] {𝓕 : Filtration ℝ mΩ} + {M : ℝ → Ω → ℝ} {p R : ℝ} (hp : 1 < p) + (hM : Martingale M 𝓕 μ) + (hbound : ∀ t, eLpNorm (M t) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) : + Tendsto (fun n : ℕ ↦ eLpNorm + (fun ω ↦ M ((n : ℝ) + 1) ω - M (n : ℝ) ω) (ENNReal.ofReal p) μ) atTop (𝓝 0) := by + set L : Ω → ℝ := discreteSampleLimit μ 𝓕 M + have h_meas_M : ∀ k : ℝ, AEStronglyMeasurable (M k) μ := fun k ↦ + ((hM.stronglyMeasurable _).mono (𝓕.le _)).aestronglyMeasurable + have h_meas_L : AEStronglyMeasurable L μ := + (Submartingale.memLp_limitProcess (discreteSample_martingale hM).submartingale + ((iSup_le fun (n : ℕ) ↦ hbound (n : ℝ)).trans_lt ENNReal.ofReal_lt_top)).aestronglyMeasurable + have h_one_le_p : (1 : ℝ≥0∞) ≤ ENNReal.ofReal p := ENNReal.one_le_ofReal.mpr hp.le + -- step 5 gives ‖M n - L‖_p → 0 + have hL_step5 : Tendsto (fun n : ℕ ↦ eLpNorm + (fun ω ↦ M (n : ℝ) ω - L ω) (ENNReal.ofReal p) μ) atTop (𝓝 0) := + lp_continuous_martingale_tendsto_eLpNorm_at_naturals hp hM hbound + -- ‖M (n+1) - L‖_p → 0 (reindex via `tendsto_add_atTop_iff_nat 1`) + have hL_shift : Tendsto (fun n : ℕ ↦ eLpNorm + (fun ω ↦ M ((n : ℝ) + 1) ω - L ω) (ENNReal.ofReal p) μ) atTop (𝓝 0) := by + refine ((tendsto_add_atTop_iff_nat 1).mpr hL_step5).congr (fun n ↦ ?_) + congr 1 + funext ω + congr 2 + push_cast + ring + -- triangle: ‖M(n+1) - M n‖_p ≤ ‖M(n+1) - L‖_p + ‖M n - L‖_p + have h_triangle : ∀ n : ℕ, + eLpNorm (fun ω ↦ M ((n : ℝ) + 1) ω - M (n : ℝ) ω) (ENNReal.ofReal p) μ + ≤ eLpNorm (fun ω ↦ M ((n : ℝ) + 1) ω - L ω) (ENNReal.ofReal p) μ + + eLpNorm (fun ω ↦ M (n : ℝ) ω - L ω) (ENNReal.ofReal p) μ := fun n ↦ by + have h_eq : (fun ω ↦ M ((n : ℝ) + 1) ω - M (n : ℝ) ω) + = (fun ω ↦ (M ((n : ℝ) + 1) ω - L ω) - (M (n : ℝ) ω - L ω)) := by + funext ω + ring + rw [h_eq] + exact eLpNorm_sub_le h_one_le_p + have h_rhs : Tendsto (fun n : ℕ ↦ + eLpNorm (fun ω ↦ M ((n : ℝ) + 1) ω - L ω) (ENNReal.ofReal p) μ + + eLpNorm (fun ω ↦ M (n : ℝ) ω - L ω) (ENNReal.ofReal p) μ) atTop (𝓝 0) := by + have h : Tendsto _ atTop (𝓝 ((0 : ℝ≥0∞) + (0 : ℝ≥0∞))) := + Filter.Tendsto.add hL_shift hL_step5 + rwa [add_zero] at h + exact tendsto_of_tendsto_of_tendsto_of_le_of_le + (tendsto_const_nhds (x := (0 : ℝ≥0∞))) h_rhs (fun _ ↦ zero_le) h_triangle + +/-- L^1 triangle: `eLpNorm (M_(n+1) - M_n) 1 μ → 0` via Hölder from `p → 0`. -/ +lemma eLpNorm_increment_one_tendsto_zero + {μ : Measure Ω} [IsFiniteMeasure μ] {𝓕 : Filtration ℝ mΩ} + {M : ℝ → Ω → ℝ} {p R : ℝ} (hp : 1 < p) + (hM : Martingale M 𝓕 μ) + (hbound : ∀ t, eLpNorm (M t) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) : + Tendsto (fun n : ℕ ↦ eLpNorm + (fun ω ↦ M ((n : ℝ) + 1) ω - M (n : ℝ) ω) 1 μ) atTop (𝓝 0) := by + have hp_pos : 0 < p := lt_trans zero_lt_one hp + have h_meas_diff : ∀ n : ℕ, + AEStronglyMeasurable (fun ω ↦ M ((n : ℝ) + 1) ω - M (n : ℝ) ω) μ := fun n ↦ + ((hM.stronglyMeasurable _).mono (𝓕.le _)).aestronglyMeasurable.sub + ((hM.stronglyMeasurable _).mono (𝓕.le _)).aestronglyMeasurable + have h_one_le_p : (1 : ℝ≥0∞) ≤ ENNReal.ofReal p := ENNReal.one_le_ofReal.mpr hp.le + set C : ℝ≥0∞ := μ Set.univ ^ (1 - 1 / p) with C_def + have hLp : Tendsto (fun n : ℕ ↦ eLpNorm + (fun ω ↦ M ((n : ℝ) + 1) ω - M (n : ℝ) ω) (ENNReal.ofReal p) μ) atTop (𝓝 0) := + eLpNorm_increment_p_tendsto_zero hp hM hbound + have h_holder : ∀ n : ℕ, eLpNorm (fun ω ↦ M ((n : ℝ) + 1) ω - M (n : ℝ) ω) 1 μ + ≤ eLpNorm (fun ω ↦ M ((n : ℝ) + 1) ω - M (n : ℝ) ω) (ENNReal.ofReal p) μ * C := fun n ↦ by + refine (eLpNorm_le_eLpNorm_mul_rpow_measure_univ (μ := μ) + (p := 1) (q := ENNReal.ofReal p) h_one_le_p (h_meas_diff n)).trans ?_ + rw [C_def, ENNReal.toReal_one, ENNReal.toReal_ofReal hp_pos.le, one_div_one] + have hC_ne_top : C ≠ ⊤ := + ENNReal.rpow_ne_top_of_nonneg + (by + have hp_inv_le_one : 1 / p ≤ 1 := (div_le_one hp_pos).mpr hp.le + linarith) + (measure_ne_top _ _) + have h_bound_tendsto : Tendsto (fun n : ℕ ↦ eLpNorm + (fun ω ↦ M ((n : ℝ) + 1) ω - M (n : ℝ) ω) (ENNReal.ofReal p) μ * C) atTop (𝓝 0) := by + have h := ENNReal.Tendsto.mul_const hLp (Or.inr hC_ne_top) + rwa [zero_mul] at h + exact tendsto_of_tendsto_of_tendsto_of_le_of_le + (tendsto_const_nhds (x := (0 : ℝ≥0∞))) h_bound_tendsto (fun _ ↦ zero_le) h_holder + +/-- The increment's `L^1` integral, in real-valued form. -/ +lemma integral_norm_increment_tendsto_zero + {μ : Measure Ω} [IsFiniteMeasure μ] {𝓕 : Filtration ℝ mΩ} + {M : ℝ → Ω → ℝ} {p R : ℝ} (hp : 1 < p) + (hM : Martingale M 𝓕 μ) + (hbound : ∀ t, eLpNorm (M t) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) : + Tendsto (fun n : ℕ ↦ ∫ ω, ‖M ((n : ℝ) + 1) ω - M (n : ℝ) ω‖ ∂μ) atTop (𝓝 0) := by + have h_meas : ∀ n : ℕ, + AEStronglyMeasurable (fun ω ↦ M ((n : ℝ) + 1) ω - M (n : ℝ) ω) μ := fun n ↦ + ((hM.stronglyMeasurable _).mono (𝓕.le _)).aestronglyMeasurable.sub + ((hM.stronglyMeasurable _).mono (𝓕.le _)).aestronglyMeasurable + have h_eLp1 := eLpNorm_increment_one_tendsto_zero hp hM hbound + have h_eq : (fun n : ℕ ↦ ∫ ω, ‖M ((n : ℝ) + 1) ω - M (n : ℝ) ω‖ ∂μ) = + (fun n : ℕ ↦ (eLpNorm (fun ω ↦ M ((n : ℝ) + 1) ω - M (n : ℝ) ω) 1 μ).toReal) := by + funext n + rw [integral_norm_eq_lintegral_eNorm (h_meas n), eLpNorm_one_eq_lintegral_eNorm (h_meas n)] + rw [h_eq] + have h_toReal : + Tendsto (fun n : ℕ ↦ (eLpNorm (fun ω ↦ M ((n : ℝ) + 1) ω - M (n : ℝ) ω) 1 μ).toReal) + atTop (𝓝 ((0 : ℝ≥0∞).toReal)) := + (ENNReal.tendsto_toReal ENNReal.zero_ne_top).comp h_eLp1 + simpa using h_toReal + +/-- Sup-in-measure: for each `ε > 0`, `μ.real {ω | ε ≤ sup_{t ≤ 1} |incrementProc M n t ω|} → 0`. -/ +private lemma sup_increment_measure_tendsto_zero + {μ : Measure Ω} [IsFiniteMeasure μ] {𝓕 : Filtration ℝ mΩ} + {M : ℝ → Ω → ℝ} {p R : ℝ} (hp : 1 < p) + (hM : Martingale M 𝓕 μ) + (hM_cont : ∀ ω, _root_.IsRightContinuous (fun t : ℝ ↦ M t ω)) + (hbound : ∀ t, eLpNorm (M t) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) + {ε : ℝ} (hε : 0 < ε) : + Tendsto (fun n : ℕ ↦ μ.real {ω | ε ≤ ⨆ i : Set.Iic (1 : ℝ≥0), + ‖incrementProc M n i ω‖}) atTop (𝓝 0) := by + set S : ℕ → Set Ω := fun n ↦ + {ω | ε ≤ ⨆ i : Set.Iic (1 : ℝ≥0), ‖incrementProc M n i ω‖} + have h_bound : ∀ n : ℕ, + ε * μ.real (S n) ≤ ∫ ω, ‖M ((n : ℝ) + 1) ω - M (n : ℝ) ω‖ ∂μ := fun n ↦ by + have h_max := ProbabilityTheory.maximal_ineq_norm (incrementProc_martingale hM n) ε 1 + (incrementProc_isRightContinuous hM_cont n) + rw [smul_eq_mul] at h_max + refine h_max.trans ?_ + have h_endpoint : + (fun ω ↦ ‖incrementProc M n 1 ω‖) + = fun ω ↦ ‖M ((n : ℝ) + 1) ω - M (n : ℝ) ω‖ := by + funext ω + change ‖M ((n : ℝ) + ((1 : ℝ≥0) : ℝ)) ω - _‖ = _ + rw [NNReal.coe_one] + rw [h_endpoint] + have hmem (t : ℝ) : MemLp (M t) (ENNReal.ofReal p) μ := + (hbound t).trans_lt ENNReal.ofReal_lt_top + have hint : Integrable (fun ω ↦ M ((n : ℝ) + 1) ω - M (n : ℝ) ω) μ := + ((hmem _).sub (hmem _)).integrable (ENNReal.one_le_ofReal.mpr hp.le) + exact setIntegral_le_integral hint.norm (Filter.Eventually.of_forall fun _ ↦ norm_nonneg _) + -- ε * μ.real S → 0 by sandwich with integral_norm_increment_tendsto_zero + have h_int := integral_norm_increment_tendsto_zero hp hM hbound + have h_eps_mul : Tendsto (fun n : ℕ ↦ ε * μ.real (S n)) atTop (𝓝 0) := + tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds h_int + (fun n ↦ mul_nonneg hε.le measureReal_nonneg) h_bound + -- divide by ε + have h_div := h_eps_mul.const_mul ε⁻¹ + simp only [mul_zero] at h_div + refine h_div.congr fun n ↦ ?_ + rw [← mul_assoc, inv_mul_cancel₀ hε.ne', one_mul] + +/-- The norm of the increment trajectory on `[0, 1]` is `BddAbove` a.s., +by Tau Ceti's continuous-time bound `Martingale.ae_iSup_eNorm_lt_top`. -/ +private lemma incrementProc_bddAbove_ae + {μ : Measure Ω} [IsFiniteMeasure μ] {𝓕 : Filtration ℝ mΩ} + {M : ℝ → Ω → ℝ} (hM : Martingale M 𝓕 μ) + (hM_cont : ∀ ω, _root_.IsRightContinuous (fun t : ℝ ↦ M t ω)) (n : ℕ) : + ∀ᵐ ω ∂μ, BddAbove (Set.range fun i : Set.Iic (1 : ℝ≥0) ↦ + ‖incrementProc M n i ω‖) := by + have hrc : ∀ᵐ ω ∂μ, ∀ t < (1 : ℝ≥0), + ContinuousWithinAt (fun u ↦ incrementProc M n u ω) (Set.Ioi t) t := + ae_of_all _ fun ω t _ ↦ incrementProc_isRightContinuous hM_cont n ω t + have h_ne_top := (incrementProc_martingale hM n).ae_iSup_eNorm_lt_top hrc + filter_upwards [h_ne_top] with ω hω + refine ⟨(⨆ t ≤ (1 : ℝ≥0), ‖incrementProc M n t ω‖ₑ).toReal, ?_⟩ + rintro _ ⟨i, rfl⟩ + dsimp only + rw [← ENNReal.toReal_ofReal (norm_nonneg (incrementProc M n i ω))] + exact ENNReal.toReal_mono hω.ne + (by rw [ofReal_norm]; exact le_iSup₂_of_le i i.2 le_rfl) + +/-- Theorem 4.3.10 (Saporito Ch 4.3), real-time convergence in measure. + +An `L^p`-bounded continuous-time martingale `(M_t)` with right-continuous paths on a finite +probability space converges in measure to the natural-time limit `discreteSampleLimit μ 𝓕 M` +as `t → ∞` along all reals (not just along natural numbers). -/ +theorem lp_continuous_martingale_tendstoInMeasure + {μ : Measure Ω} [IsFiniteMeasure μ] {𝓕 : Filtration ℝ mΩ} + {M : ℝ → Ω → ℝ} {p R : ℝ} (hp : 1 < p) + (hM : Martingale M 𝓕 μ) + (hM_cont : ∀ ω, _root_.IsRightContinuous (fun t : ℝ ↦ M t ω)) + (hbound : ∀ t, eLpNorm (M t) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) : + TendstoInMeasure μ M atTop (discreteSampleLimit μ 𝓕 M) := by + set L := discreteSampleLimit μ 𝓕 M + rw [tendstoInMeasure_iff_measureReal_norm] + intro ε hε + have hε2 : 0 < ε / 2 := by linarith + -- Step 3 a.s. → in-measure for the discrete sample + have h_disc_meas : TendstoInMeasure μ (discreteSample M) atTop L := + tendstoInMeasure_of_tendsto_ae + (fun n : ℕ ↦ ((hM.stronglyMeasurable _).mono (𝓕.le _)).aestronglyMeasurable) + (discreteSample_ae_tendsto_limitProcess hp.le hM hbound) + rw [tendstoInMeasure_iff_measureReal_norm] at h_disc_meas + have h_B := h_disc_meas (ε / 2) hε2 + have h_A := sup_increment_measure_tendsto_zero hp hM hM_cont hbound hε2 + have h_A_real := h_A.comp (tendsto_nat_floor_atTop (α := ℝ)) + have h_B_real := h_B.comp (tendsto_nat_floor_atTop (α := ℝ)) + set A : ℕ → Set Ω := fun n ↦ {ω | ε / 2 ≤ ⨆ i : Set.Iic (1 : ℝ≥0), ‖incrementProc M n i ω‖} + set B : ℕ → Set Ω := fun n ↦ {ω | ε / 2 ≤ ‖discreteSample M n ω - L ω‖} + -- Set inclusion (a.s.): for t ≥ 0, {ω | ε ≤ ‖M t - L‖} ⊆ A_{⌊t⌋} ∪ B_{⌊t⌋} + -- (modulo a μ-null set where the increment trajectory is unbounded — then the + -- ℝ-valued iSup defaults to 0 and `‖increment s ω‖ ≤ iSup` may fail). + have h_subset : ∀ᶠ t in (Filter.atTop : Filter ℝ), + ∀ᵐ ω ∂μ, + ω ∈ {ω | ε ≤ ‖M t ω - L ω‖} → ω ∈ A (Nat.floor t) ∪ B (Nat.floor t) := by + refine Filter.eventually_atTop.mpr ⟨0, fun t ht ↦ ?_⟩ + filter_upwards [incrementProc_bddAbove_ae hM hM_cont (Nat.floor t)] with ω h_bdd hω + set n := Nat.floor t + have h_n_cast : (n : ℝ) ≤ t := Nat.floor_le ht + have h_t_lt : t < (n : ℝ) + 1 := Nat.lt_floor_add_one t + have h_tri : ‖M t ω - L ω‖ ≤ ‖M t ω - M (n : ℝ) ω‖ + ‖M (n : ℝ) ω - L ω‖ := by + rw [show M t ω - L ω = (M t ω - M (n : ℝ) ω) + (M (n : ℝ) ω - L ω) by ring] + exact norm_add_le _ _ + by_cases hAB : ε / 2 ≤ ‖M t ω - M (n : ℝ) ω‖ + · left + change ε / 2 ≤ ⨆ i : Set.Iic (1 : ℝ≥0), ‖incrementProc M n i ω‖ + refine hAB.trans ?_ + set s : ℝ≥0 := ⟨t - (n : ℝ), by linarith⟩ + have h_s_le_one : s ≤ 1 := by + rw [← NNReal.coe_le_coe, NNReal.coe_one] + change t - (n : ℝ) ≤ 1 + linarith + rw [show M t ω - M (n : ℝ) ω = incrementProc M n s ω by + change _ = M ((n : ℝ) + (s : ℝ)) ω - M (n : ℝ) ω + congr 2 + change t = (n : ℝ) + (t - (n : ℝ)) + ring] + exact le_ciSup (f := fun i : Set.Iic (1 : ℝ≥0) ↦ ‖incrementProc M n i ω‖) h_bdd + ⟨s, h_s_le_one⟩ + · right + change ε / 2 ≤ ‖M (n : ℝ) ω - L ω‖ + have hAB' : ‖M t ω - M (n : ℝ) ω‖ < ε / 2 := not_le.mp hAB + linarith [le_trans hω h_tri] + have h_bound : ∀ᶠ t in (Filter.atTop : Filter ℝ), + μ.real {ω | ε ≤ ‖M t ω - L ω‖} ≤ + μ.real (A (Nat.floor t)) + μ.real (B (Nat.floor t)) := by + filter_upwards [h_subset] with t hsub + have h_meas_le : μ {ω | ε ≤ ‖M t ω - L ω‖} ≤ + μ (A (Nat.floor t) ∪ B (Nat.floor t)) := measure_mono_ae hsub + exact (ENNReal.toReal_mono (measure_ne_top _ _) h_meas_le).trans + (measureReal_union_le _ _) + have h_sum : Tendsto (fun t : ℝ ↦ μ.real (A (Nat.floor t)) + μ.real (B (Nat.floor t))) + atTop (𝓝 0) := by + have h := h_A_real.add h_B_real + rwa [add_zero] at h + exact tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds h_sum + (Filter.Eventually.of_forall fun _ ↦ measureReal_nonneg) h_bound + +/-- Theorem 4.3.10 (Saporito Ch 4.3), combined natural-a.s. and real-time-in-measure. + +For an `L^p`-bounded continuous-time martingale (`p > 1`) with right-continuous paths on a +finite probability space, there is an integrable limit `M_∞` to which the process converges +a.s. at natural times and in measure as `t → ∞` along all reals. -/ +theorem lp_continuous_martingale_full + {μ : Measure Ω} [IsFiniteMeasure μ] {𝓕 : Filtration ℝ mΩ} + {M : ℝ → Ω → ℝ} {p : ℝ} (hp : 1 < p) + (hM : Martingale M 𝓕 μ) + (hM_cont : ∀ ω, _root_.IsRightContinuous (fun t : ℝ ↦ M t ω)) + (hbound : ∃ R : ℝ, + ∀ t, eLpNorm (M t) (ENNReal.ofReal p) μ ≤ ENNReal.ofReal R) : + ∃ (M_inf : Ω → ℝ), Integrable M_inf μ ∧ + (∀ᵐ ω ∂μ, Tendsto (fun n : ℕ ↦ M (n : ℝ) ω) atTop (𝓝 (M_inf ω))) ∧ + TendstoInMeasure μ M atTop M_inf := by + obtain ⟨R, hR⟩ := hbound + refine ⟨discreteSampleLimit μ 𝓕 M, ?_, ?_, ?_⟩ + · exact discreteSampleLimit_integrable hp.le hM hR + · exact discreteSample_ae_tendsto_limitProcess hp.le hM hR + · exact lp_continuous_martingale_tendstoInMeasure hp hM hM_cont hR + +end MathFin diff --git a/LeanPool/MathFin/Probability/Martingales/MartingaleFrozen.lean b/LeanPool/MathFin/Probability/Martingales/MartingaleFrozen.lean new file mode 100644 index 0000000000..6416912b8e --- /dev/null +++ b/LeanPool/MathFin/Probability/Martingales/MartingaleFrozen.lean @@ -0,0 +1,146 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Martingale.Basic + +/-! +# A martingale up to a horizon, frozen at the horizon + +A process `S` that is a martingale only up to a horizon `T` (adapted and integrable on +`{t ≤ T}`, `S s = E[S t | 𝓕 s]` for `s ≤ t ≤ T`) is a martingale once it is frozen at `T`: +`t ↦ S (min t T)` is a martingale for the same filtration, and every martingale of that form +arises so (`martingale_min_iff`). Past the horizon the frozen process is constant, and the +constant `S T` is `𝓕 T ⊆ 𝓕 s`-measurable, so it is its own conditional expectation. + +This is the vocabulary of the horizon-`T` equivalent martingale measure `MathFin.IsEMM` +(`EquivMartingaleMeasure.lean`), discrete and continuous: the hypothesis there is the +frozen martingale, and the three consequences read off it (adaptedness, integrability and the +martingale identity before the horizon) are the forward direction of `martingale_min_iff`. On +`ℕ` the identity need only be given one step at a time (`martingale_min_of_condExp_succ`). + +A frozen process is `𝓕 T`-measurable at every time, so whether it is a martingale depends on the +measure only through its restriction to `𝓕 T`: two measures that agree on `𝓕 T` have the same +frozen martingales (`martingale_min_of_trim_eq`). This is why a pricing measure up to `T` need only +be equivalent to the reference measure on `𝓕 T` (`Market.IsPricingMeasure`). + +## Main results + +* `martingale_min_iff`: `t ↦ S (min t T)` is a martingale for `𝓕` iff `S` is adapted and + integrable on `{t ≤ T}` and `S s = E[S t | 𝓕 s]` for `s ≤ t ≤ T` (finite measure). +* `martingale_min_of_condExp_succ`: on `ℕ`, adaptedness and integrability up to `T` and the + one-step identity `S t = E[S (t+1) | 𝓕 t]` for `t < T` make `n ↦ S (min n T)` a martingale. +* `martingale_min_of_martingale`: a martingale frozen at any time is one. +* `martingale_min_of_trim_eq`: a frozen martingale stays one under any measure with the same + restriction to `𝓕 T`. +* `MeasureTheory.Martingale.congr_ae`: an adapted process equal almost surely at each time to a + martingale is one. + +## Tags + +martingale up to a horizon, stopped martingale, frozen process, equivalent martingale measure, +finite horizon martingale, MSC 60G44, MSC 60G48 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory + +variable {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} + {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] + +/-- **An adapted process equal almost surely at each time to a martingale is a martingale**: the +conditional expectations see the process only up to null sets. -/ +theorem _root_.MeasureTheory.Martingale.congr_ae {ι : Type*} [Preorder ι] {𝓕 : Filtration ι m0} + {f g : ι → Ω → E} (hf : Martingale f 𝓕 μ) (hg : StronglyAdapted 𝓕 g) + (hfg : ∀ i, f i =ᵐ[μ] g i) : Martingale g 𝓕 μ := + ⟨hg, fun i j hij ↦ (condExp_congr_ae (hfg j)).symm.trans ((hf.2 i j hij).trans (hfg i))⟩ + +section LinearOrder + +variable {ι : Type*} [LinearOrder ι] {𝓕 : Filtration ι m0} {S : ι → Ω → E} {T : ι} + +/-- **A martingale up to `T`, frozen at `T`, is a martingale; and conversely.** `t ↦ S (min t T)` +is a `μ`-martingale for `𝓕` iff `S` is adapted and integrable on `{t ≤ T}` and satisfies the +martingale identity `S s = E[S t | 𝓕 s]` for `s ≤ t ≤ T`. -/ +theorem martingale_min_iff [IsFiniteMeasure μ] : + Martingale (fun t ↦ S (min t T)) 𝓕 μ ↔ + (∀ t ≤ T, StronglyMeasurable[𝓕 t] (S t)) ∧ (∀ t ≤ T, Integrable (S t) μ) ∧ + ∀ ⦃s t⦄, s ≤ t → t ≤ T → S s =ᵐ[μ] μ[S t | 𝓕 s] := by + refine ⟨fun h ↦ ⟨fun t ht ↦ by simpa only [min_eq_left ht] using h.1 t, + fun t ht ↦ by simpa only [min_eq_left ht] using h.integrable t, + fun s t hst ht ↦ by + simpa only [min_eq_left ht, min_eq_left (hst.trans ht)] using + (h.condExp_ae_eq hst).symm⟩, fun ⟨hadapt, hint, hmart⟩ ↦ + ⟨fun s ↦ (hadapt _ (min_le_right _ _)).mono (𝓕.mono (min_le_left _ _)), + fun i j hij ↦ ?_⟩⟩ + change μ[S (min j T) | 𝓕 i] =ᵐ[μ] S (min i T) + rcases le_or_gt j T with hj | hj + · simpa only [min_eq_left hj, min_eq_left (hij.trans hj)] using (hmart hij hj).symm + rw [min_eq_right hj.le] + rcases le_or_gt i T with hi | hi + · simpa only [min_eq_left hi, min_eq_right hj.le] using (hmart hi le_rfl).symm + · rw [min_eq_right hi.le] + exact .of_eq (condExp_of_stronglyMeasurable (𝓕.le i) + ((hadapt T le_rfl).mono (𝓕.mono hi.le)) (hint T le_rfl)) + +/-- **A martingale frozen at any time is a martingale.** -/ +theorem martingale_min_of_martingale [IsFiniteMeasure μ] (hS : Martingale S 𝓕 μ) (T : ι) : + Martingale (fun t ↦ S (min t T)) 𝓕 μ := + martingale_min_iff.mpr + ⟨fun t _ ↦ hS.1 t, fun t _ ↦ hS.integrable t, fun _ _ hst _ ↦ (hS.condExp_ae_eq hst).symm⟩ + +/-- **A frozen martingale depends on the measure only up to the horizon.** If `t ↦ S (min t T)` is +a `μ`-martingale and `ν` agrees with `μ` on `𝓕 T`, it is a `ν`-martingale: before the horizon +every `S t` is `𝓕 T`-measurable, so its integrability and its integrals over the sets of +`𝓕 s ⊆ 𝓕 T` are the same under both measures. -/ +theorem martingale_min_of_trim_eq {ν : Measure Ω} [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (hμν : μ.trim (𝓕.le T) = ν.trim (𝓕.le T)) (hS : Martingale (fun t ↦ S (min t T)) 𝓕 μ) : + Martingale (fun t ↦ S (min t T)) 𝓕 ν := by + obtain ⟨hadapt, hint, hmart⟩ := martingale_min_iff.mp hS + have hT {t : ι} (ht : t ≤ T) : StronglyMeasurable[𝓕 T] (S t) := (hadapt t ht).mono (𝓕.mono ht) + have hintν {t : ι} (ht : t ≤ T) : Integrable (S t) ν := by + refine integrable_of_integrable_trim (𝓕.le T) ?_ + rw [← hμν] + exact (hint t ht).trim (𝓕.le T) (hT ht) + have hset {t : ι} (ht : t ≤ T) {A : Set Ω} (hA : MeasurableSet[𝓕 T] A) : + ∫ ω in A, S t ω ∂ν = ∫ ω in A, S t ω ∂μ := by + rw [setIntegral_trim (𝓕.le T) (hT ht) hA, setIntegral_trim (𝓕.le T) (hT ht) hA, hμν] + refine martingale_min_iff.mpr ⟨hadapt, fun t ht ↦ hintν ht, fun s t hst ht ↦ ?_⟩ + refine ae_eq_condExp_of_forall_setIntegral_eq (𝓕.le s) (hintν ht) + (fun _ _ _ ↦ (hintν (hst.trans ht)).integrableOn) (fun A hA _ ↦ ?_) + (hadapt s (hst.trans ht)).aestronglyMeasurable + have hAT : MeasurableSet[𝓕 T] A := 𝓕.mono (hst.trans ht) A hA + rw [hset (hst.trans ht) hAT, hset ht hAT, ← setIntegral_condExp (𝓕.le s) (hint t ht) hA] + exact setIntegral_congr_ae (𝓕.le s A hA) ((hmart hst ht).mono fun _ h _ ↦ h) + +end LinearOrder + +/-- **The one-step form on `ℕ`.** A process that is adapted and integrable up to `T` and satisfies +the one-step martingale identity `S t = E[S (t+1) | 𝓕 t]` for `t < T` is a martingale once frozen +at `T`. -/ +theorem martingale_min_of_condExp_succ [IsFiniteMeasure μ] {𝓕 : Filtration ℕ m0} + {S : ℕ → Ω → E} {T : ℕ} (hadapt : ∀ t ≤ T, StronglyMeasurable[𝓕 t] (S t)) + (hint : ∀ t ≤ T, Integrable (S t) μ) (hmart : ∀ t < T, S t =ᵐ[μ] μ[S (t + 1) | 𝓕 t]) : + Martingale (fun n ↦ S (min n T)) 𝓕 μ := by + refine martingale_of_condExp_sub_eq_zero_nat + (fun n ↦ (hadapt _ (min_le_right _ _)).mono (𝓕.mono (min_le_left _ _))) + (fun n ↦ hint _ (min_le_right _ _)) fun n ↦ ?_ + show μ[S (min (n + 1) T) - S (min n T) | 𝓕 n] =ᵐ[μ] 0 + rcases lt_or_ge n T with hn | hn + · rw [min_eq_left hn.le, min_eq_left (Nat.succ_le_of_lt hn)] + filter_upwards [condExp_sub (hint (n + 1) hn) (hint n hn.le) (𝓕 n), hmart n hn] + with ω h_sub h_mart + rw [Pi.zero_apply, h_sub, Pi.sub_apply, + condExp_of_stronglyMeasurable (𝓕.le n) (hadapt n hn.le) (hint n hn.le), ← h_mart, sub_self] + · simp [min_eq_right hn, min_eq_right (hn.trans n.le_succ)] + +end MathFin diff --git a/LeanPool/MathFin/Probability/Martingales/MartingaleSetIntegral.lean b/LeanPool/MathFin/Probability/Martingales/MartingaleSetIntegral.lean new file mode 100644 index 0000000000..319d3acf40 --- /dev/null +++ b/LeanPool/MathFin/Probability/Martingales/MartingaleSetIntegral.lean @@ -0,0 +1,58 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Martingale.Basic + +/-! +# A martingale from set-integral identities, over any index + +Mathlib proves `martingale_of_setIntegral_eq_succ` for `ℕ`-indexed processes, where one-step +identities suffice. Over a general (e.g. continuous) index there is no successor, and the +identities are over every pair `i ≤ j`: `martingale_iff_setIntegral_eq` is that statement. It is +the characterisation of conditional expectation by set integrals +(`ae_eq_condExp_of_forall_setIntegral_eq`) read off as the martingale property, with Mathlib's +`Martingale.setIntegral_eq` as the converse, and the way the +library's continuous-time martingales (the exponential martingales, the stopped price of an +equivalent martingale measure, promoted local martingales) are built. + +## Main results + +* `martingale_iff_setIntegral_eq`: a process is a martingale iff it is adapted, integrable, and + for `i ≤ j` its set integrals over `𝒢 i`-measurable sets agree at times `i` and `j`. + +## Tags + +martingale characterisation, set integral identity, continuous-time martingale, +conditional expectation, martingale property, MSC 60G44, MSC 60G48 +-/ + +@[expose] public section + +namespace MeasureTheory + +variable {Ω ι E : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} [Preorder ι] + [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {𝒢 : Filtration ι m0} + {f : ι → Ω → E} + +/-- **A process is a martingale iff it is adapted, integrable, and its set integrals over +`𝒢 i`-measurable sets are constant in time.** The forward direction is Mathlib's +`Martingale.setIntegral_eq`; the converse is the characterisation of conditional expectation by set +integrals. Over a `σ`-finite filtration (in particular any finite measure), with any index. -/ +theorem martingale_iff_setIntegral_eq [SigmaFiniteFiltration μ 𝒢] : + Martingale f 𝒢 μ ↔ StronglyAdapted 𝒢 f ∧ (∀ i, Integrable (f i) μ) ∧ + ∀ ⦃i j⦄, i ≤ j → ∀ s : Set Ω, MeasurableSet[𝒢 i] s → + ∫ ω in s, f i ω ∂μ = ∫ ω in s, f j ω ∂μ := + ⟨fun hf ↦ ⟨hf.stronglyAdapted, hf.integrable, fun _ _ hij _ hs ↦ hf.setIntegral_eq hij hs⟩, + fun ⟨hadp, hint, hf⟩ ↦ ⟨hadp, fun _ _ hij ↦ + (ae_eq_condExp_of_forall_setIntegral_eq (𝒢.le _) (hint _) + (fun _ _ _ ↦ (hint _).integrableOn) (fun s hs _ ↦ hf hij s hs) + (hadp _).aestronglyMeasurable).symm⟩⟩ + +end MeasureTheory diff --git a/LeanPool/MathFin/Probability/Martingales/StoppedProcessPaths.lean b/LeanPool/MathFin/Probability/Martingales/StoppedProcessPaths.lean new file mode 100644 index 0000000000..67f070a63e --- /dev/null +++ b/LeanPool/MathFin/Probability/Martingales/StoppedProcessPaths.lean @@ -0,0 +1,84 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Process.Stopping + +/-! +# Paths of a stopped process + +Facts about `stoppedProcess X ρ t ω = X (min t (ρ ω)) ω` that are independent of what `X` and `ρ` +are: the stopped time `t ∧ ρ` read back in `ℝ≥0` (`coe_untopA_min`), its continuity and value at +`0`, the stopped process inheriting continuity of paths (`continuous_stoppedProcess`), and the +stopping indicator being inert when `ρ` is positive (`stoppedProcess_indicator_eq`). +`BoundedLocalMartingale`, `LevyCharacterization` and `ItoFormulaUnrestrictedLocMart` localise by +stopping, and share these. + +## Main results + +* `coe_untopA_min`: `min t ρ`, read back in `ℝ≥0`, is again `min t ρ` in `WithTop ℝ≥0`. +* `continuous_untopA_min`, `untopA_min_zero`: `t ↦ t ∧ ρ` is continuous and equals `0` at `t = 0`. +* `stoppedProcess_indicator_eq`: when every `ρ ω` is positive, the indicator `{⊥ < ρ}` inside a + stopped process changes nothing. +* `continuous_stoppedProcess`: a stopped process has continuous paths when `X` does. + +## Tags + +stopped process, localisation, path continuity, stopping time, local martingale, MSC 60G40, +MSC 60G07 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory +open scoped NNReal + +variable {Ω : Type*} {X : ℝ≥0 → Ω → ℝ} + +lemma coe_untopA (x : ℝ≥0) : ((x : WithTop ℝ≥0)).untopA = x := rfl + +/-- `min t ρ`, read back in `ℝ≥0`, is again `min t ρ` in `WithTop ℝ≥0`. -/ +theorem coe_untopA_min (t : ℝ≥0) (c : WithTop ℝ≥0) : + (((min (t : WithTop ℝ≥0) c).untopA : ℝ≥0) : WithTop ℝ≥0) = min (t : WithTop ℝ≥0) c := by + induction c using WithTop.recTopCoe with + | top => rw [min_top_right]; rfl + | coe c => rw [← WithTop.coe_min, coe_untopA] + +/-- `t ↦ (t ∧ ρ)` is continuous. -/ +theorem continuous_untopA_min (c : WithTop ℝ≥0) : + Continuous fun t : ℝ≥0 ↦ (min (t : WithTop ℝ≥0) c).untopA := by + induction c using WithTop.recTopCoe with + | top => simp only [min_top_right]; exact continuous_id + | coe c => + simp only [← WithTop.coe_min, coe_untopA] + exact continuous_id.min continuous_const + +/-- At time `0` the stopped time is `0`. -/ +theorem untopA_min_zero (c : WithTop ℝ≥0) : (min ((0 : ℝ≥0) : WithTop ℝ≥0) c).untopA = 0 := by + induction c using WithTop.recTopCoe with + | top => rw [min_top_right]; rfl + | coe c => rw [← WithTop.coe_min, coe_untopA]; simp + +/-- When every `ρ ω` is positive, the indicator in the stopped process is inert. -/ +theorem stoppedProcess_indicator_eq {ρ : Ω → WithTop ℝ≥0} (hρ : ∀ ω, ⊥ < ρ ω) + (X : ℝ≥0 → Ω → ℝ) : + stoppedProcess (fun i ↦ {ω | ⊥ < ρ ω}.indicator (X i)) ρ = stoppedProcess X ρ := by + funext t ω + simp only [stoppedProcess] + exact Set.indicator_of_mem (show ω ∈ {ω : Ω | ⊥ < ρ ω} from hρ ω) _ + +/-- The stopped process has continuous paths. -/ +theorem continuous_stoppedProcess (hcont : ∀ ω, Continuous fun t ↦ X t ω) + (ρ : Ω → WithTop ℝ≥0) (ω : Ω) : + Continuous fun t ↦ stoppedProcess X ρ t ω := + (hcont ω).comp (continuous_untopA_min (ρ ω)) + +end MathFin diff --git a/LeanPool/MathFin/Probability/Martingales/TimeChange.lean b/LeanPool/MathFin/Probability/Martingales/TimeChange.lean new file mode 100644 index 0000000000..83ec5a87dc --- /dev/null +++ b/LeanPool/MathFin/Probability/Martingales/TimeChange.lean @@ -0,0 +1,70 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import TauCeti.Probability.Martingale.Basic + +/-! +# A martingale along a monotone time change + +A filtration `𝓕` indexed by `ι` and a monotone map `φ : κ → ι` give a filtration indexed by `κ`, +`t ↦ 𝓕 (φ t)` (`Filtration.comp`). A martingale `f` for `𝓕` read along `φ`, `t ↦ f (φ t)`, is a +martingale for it (`Martingale.comp`). When `φ` has a monotone right inverse `ψ` (`φ (ψ i) = i`), +the converse holds: a process whose reading along `φ` is a martingale is one itself +(`Martingale.of_comp`). + +The time change that matters here is the step count of a discrete market seen in continuous time: +`t ↦ ⌊t⌋₊` for unit steps, `t ↦ ⌊t / h⌋₊` for steps of length `h`. The discrete market and the +binomial tree become markets indexed by `ℝ≥0` this way (`Pricing/DiscreteMarket.lean`, +`Models/Binomial/Market.lean`). + +## Main definitions + +* `MeasureTheory.Filtration.comp`: the filtration `t ↦ 𝓕 (φ t)` along a monotone `φ`. + +## Main results + +* `MeasureTheory.Martingale.comp`: a martingale read along a monotone time change is a martingale. +* `MeasureTheory.Martingale.of_comp`: the converse, along a time change with a monotone right + inverse. + +## References + +* [Rogers and Williams][RogersWilliams] + +## Tags + +martingale, filtration, time change, reindexing, discrete time in continuous time, MSC 60G42, +MSC 60G44 +-/ + +@[expose] public section + +namespace MeasureTheory + +variable {Ω ι κ E : Type*} {m : MeasurableSpace Ω} [Preorder ι] [Preorder κ] + [NormedAddCommGroup E] [NormedSpace ℝ E] {μ : Measure Ω} + +/-- **Conversely, a process whose reading along a time change is a martingale is a martingale**, +when the time change `φ` has a monotone right inverse `ψ`: read the martingale at the times +`ψ i`. -/ +theorem Martingale.of_comp {𝓕 : Filtration ι m} {f : ι → Ω → E} {φ : κ → ι} (hφ : Monotone φ) + {ψ : ι → κ} (hψ : Monotone ψ) (hφψ : ∀ i, φ (ψ i) = i) + (hf : Martingale (fun t ↦ f (φ t)) (𝓕.comp hφ) μ) : Martingale f 𝓕 μ := by + refine ⟨fun i ↦ ?_, fun i j hij ↦ ?_⟩ + · have h := hf.1 (ψ i) + beta_reduce at h + rw [Filtration.comp_apply, hφψ] at h + exact h + · have h := hf.2 (ψ i) (ψ j) (hψ hij) + beta_reduce at h + rw [Filtration.comp_apply, hφψ, hφψ] at h + exact h + +end MeasureTheory diff --git a/LeanPool/MathFin/Probability/Martingales/UnifIntegrableL2.lean b/LeanPool/MathFin/Probability/Martingales/UnifIntegrableL2.lean new file mode 100644 index 0000000000..99d08d5f29 --- /dev/null +++ b/LeanPool/MathFin/Probability/Martingales/UnifIntegrableL2.lean @@ -0,0 +1,203 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Algebra.Order.Star.Real +public import Mathlib.MeasureTheory.Function.L2Space +public import Mathlib.MeasureTheory.Function.UniformIntegrable + +/-! +# Bounded in `L²` ⟹ uniformly integrable in `L¹` (a finite-measure Vitali producer) + +Mathlib provides the Vitali *consumer* `MeasureTheory.tendsto_Lp_finite_of_tendstoInMeasure` +(uniform integrability + convergence in measure ⟹ `L¹` convergence) but **no producer** of uniform +integrability from an `Lᵖ` bound with `p > 1`. This file supplies the `p = 2` case (the truncation +producer needs no finiteness of `μ` — only the downstream Vitali consumer does): + +* `MathFin.unifIntegrable_one_of_sq_integral_le` — a family `f : ι → α → ℝ` with `f i ∈ L²` and a + **uniform** second-moment bound `∫ (f i)² ≤ M` is `UnifIntegrable f 1 μ`. + +The proof is a Chebyshev truncation fed to `MeasureTheory.unifIntegrable_of`: on `{‖f i‖ ≥ C}` one +has `C·‖f i‖ ≤ ‖f i‖²`, so the truncated `L¹` tail `∫_{‖f i‖≥C} ‖f i‖ ≤ C⁻¹·∫‖f i‖² ≤ C⁻¹·M`, which +is `≤ ε` once `C ≥ M/ε` — uniformly in `i`. + +The intended use is the `L²→L¹` limit of Girsanov Doléans densities `Z⁽ⁿ⁾_T`, whose uniform bound +`∫ (Z⁽ⁿ⁾)² ≤ exp(K²T)` comes from the `Z² = E^{−2c}·exp(∑ c²Δτ)` identity; this lemma is the piece +that lets convergence in measure upgrade to `L¹` (hence `∫ Z⁽ⁿ⁾ → ∫ Z`, delivering unit mean). + +## Main results + +* `unifIntegrable_one_of_sq_integral_le`: a family in `L²` with a uniform bound + `∫ (f i)² ≤ M` on second moments is uniformly integrable in `L¹`. +* `tendsto_setIntegral_of_tendstoInMeasure_of_sq_bound`: on a finite measure, an `L²`-bounded + sequence converging in measure to `g ∈ L¹` has set integrals converging to those of `g`. +* `tendsto_setIntegral_of_subseq_ae_of_sq_bound`: the same conclusion from the a.e.-subsequence + principle in place of convergence in measure. +* `memLp_two_of_subseq_ae_of_sq_bound`: an a.e.-subsequence limit of an `L²`-bounded sequence of + measurable functions is in `L²` (Fatou). + +## Tags + +uniform integrability, Vitali convergence, Chebyshev truncation, second-moment bound, +L1 convergence, MSC 28A25, MSC 60E15 +-/ + +@[expose] public section + +open MeasureTheory Filter Topology +open scoped ENNReal NNReal + +namespace MathFin + +variable {α : Type*} {mα : MeasurableSpace α} {μ : Measure α} {ι : Type*} {f : ι → α → ℝ} + +/-- **Bounded in `L²` ⟹ uniformly integrable in `L¹`.** If every `f i` is in `L²` and their second +moments are uniformly bounded (`∫ (f i)² ≤ M`), then `f` is uniformly integrable in `L¹`. Chebyshev +truncation: `∫_{‖f i‖≥C} ‖f i‖ ≤ C⁻¹·M ≤ ε` for `C ≥ M/ε`, uniformly in `i` — no finiteness of `μ` +is needed for the truncation bound itself. -/ +theorem unifIntegrable_one_of_sq_integral_le (hf : ∀ i, MemLp (f i) 2 μ) + {M : ℝ} (hM : ∀ i, ∫ x, (f i x) ^ 2 ∂μ ≤ M) : + UnifIntegrable f 1 μ := by + refine unifIntegrable_of le_rfl (by norm_num) (fun i ↦ (hf i).aestronglyMeasurable) ?_ + intro ε' hε' + rcases eq_or_ne ε' ⊤ with rfl | hε'top + · exact ⟨0, fun _ ↦ le_top⟩ + obtain ⟨ε, hε, rfl⟩ : ∃ ε : ℝ, 0 < ε ∧ ENNReal.ofReal ε = ε' := + ⟨ε'.toReal, ENNReal.toReal_pos hε'.ne' hε'top, ENNReal.ofReal_toReal hε'top⟩ + refine ⟨Real.toNNReal (M / ε) + 1, fun i ↦ ?_⟩ + set C : ℝ≥0 := Real.toNNReal (M / ε) + 1 with hCdef + have hCpos : (0 : ℝ≥0∞) < (C : ℝ≥0∞) := by + rw [ENNReal.coe_pos, hCdef]; positivity + -- `∫⁻ ‖f i‖ₑ² = ofReal (∫ (f i)²) ≤ ofReal M`. + have hlint_sq : ∫⁻ x, ‖f i x‖ₑ ^ 2 ∂μ ≤ ENNReal.ofReal M := by + have hpt : ∀ x, ‖f i x‖ₑ ^ 2 = ENNReal.ofReal ((f i x) ^ 2) := fun x ↦ by + rw [Real.eNorm_eq_ofReal_abs, ← ENNReal.ofReal_pow (abs_nonneg _), sq_abs] + calc ∫⁻ x, ‖f i x‖ₑ ^ 2 ∂μ = ∫⁻ x, ENNReal.ofReal ((f i x) ^ 2) ∂μ := by simp_rw [hpt] + _ = ENNReal.ofReal (∫ x, (f i x) ^ 2 ∂μ) := + (ofReal_integral_eq_lintegral_ofReal ((hf i).integrable_sq) + (ae_of_all _ fun x ↦ sq_nonneg _)).symm + _ ≤ ENNReal.ofReal M := ENNReal.ofReal_le_ofReal (hM i) + -- `eLpNorm (indicator …) 1 = ∫⁻ over the truncation set of `‖f i‖ₑ`. + rw [eLpNorm_one_eq_lintegral_eNorm ((hf i).aestronglyMeasurable.indicator₀ + (nullMeasurableSet_le aemeasurable_const (hf i).aestronglyMeasurable.nnNorm.aemeasurable))] + set S : Set α := {x | C ≤ ‖f i x‖₊} + have henorm_ind : ∀ x, ‖S.indicator (f i) x‖ₑ = S.indicator (fun x ↦ ‖f i x‖ₑ) x := fun x ↦ by + by_cases hx : x ∈ S <;> simp [hx] + simp_rw [henorm_ind] + -- Chebyshev: `C · S.indicator ‖f i‖ₑ ≤ ‖f i‖ₑ²` pointwise. + have hpt_cheb : ∀ x, (C : ℝ≥0∞) * S.indicator (fun x ↦ ‖f i x‖ₑ) x ≤ ‖f i x‖ₑ ^ 2 := fun x ↦ by + by_cases hx : x ∈ S + · rw [Set.indicator_of_mem hx, sq] + have hCx : (C : ℝ≥0∞) ≤ ‖f i x‖ₑ := by + rw [Real.eNorm_eq_ofReal_abs, ← ENNReal.ofReal_coe_nnreal] + refine ENNReal.ofReal_le_ofReal ?_ + rw [← Real.norm_eq_abs, ← coe_nnNorm] + exact_mod_cast hx + exact mul_le_mul' hCx le_rfl + · rw [Set.indicator_of_notMem hx, mul_zero]; exact zero_le + have hchain : (C : ℝ≥0∞) * ∫⁻ x, S.indicator (fun x ↦ ‖f i x‖ₑ) x ∂μ ≤ ENNReal.ofReal M := by + rw [← lintegral_const_mul' _ _ ENNReal.coe_ne_top] + exact (lintegral_mono hpt_cheb).trans hlint_sq + -- `C · I ≤ ofReal M ≤ C · ofReal ε`, then cancel `C`. + have hMCε : ENNReal.ofReal M ≤ (C : ℝ≥0∞) * ENNReal.ofReal ε := by + rw [← ENNReal.ofReal_coe_nnreal, ← ENNReal.ofReal_mul (by positivity : (0 : ℝ) ≤ (C : ℝ))] + refine ENNReal.ofReal_le_ofReal ?_ + have hle : M / ε ≤ (C : ℝ) := by + rw [hCdef]; push_cast [Real.coe_toNNReal']; linarith [le_max_left (M / ε) (0 : ℝ)] + calc M = M / ε * ε := by rw [div_mul_cancel₀ _ hε.ne'] + _ ≤ (C : ℝ) * ε := mul_le_mul_of_nonneg_right hle hε.le + have hcancel := hchain.trans hMCε + rw [mul_comm (C : ℝ≥0∞), mul_comm (C : ℝ≥0∞)] at hcancel + exact (ENNReal.mul_le_mul_iff_left hCpos.ne' ENNReal.coe_ne_top).mp hcancel + +/-- **Set-integral `L¹`-convergence from an `L²` bound + convergence in measure.** On a finite +measure, a family `f : ℕ → α → ℝ` with `f n ∈ L²`, a **uniform** second-moment bound +`∫ (f n)² ≤ M`, and convergence in measure `f n → g` (with `g ∈ L¹`) satisfies +`∫_A f n → ∫_A g` on every set `A`. The `L²` bound produces uniform integrability +(`unifIntegrable_one_of_sq_integral_le`), which upgrades convergence in measure to `L¹` +(the Vitali consumer `tendsto_Lp_finite_of_tendstoInMeasure`), and `L¹` convergence transfers +to (set-)integrals (`tendsto_setIntegral_of_L1`). This is the endpoint the Girsanov continuous +Doléans limit consumes: `Z⁽ⁿ⁾ → Z` in measure with `∫ (Z⁽ⁿ⁾)² ≤ exp(K²T)` gives +`∫_A f(B^θⁿ) Z⁽ⁿ⁾ → ∫_A f(B^θ) Z` for every `𝓕`-set `A`. -/ +theorem tendsto_setIntegral_of_tendstoInMeasure_of_sq_bound [IsFiniteMeasure μ] + {f : ℕ → α → ℝ} {g : α → ℝ} (hf : ∀ n, MemLp (f n) 2 μ) + {M : ℝ} (hM : ∀ n, ∫ x, (f n x) ^ 2 ∂μ ≤ M) (hg : MemLp g 1 μ) + (hconv : TendstoInMeasure μ f atTop g) (A : Set α) : + Tendsto (fun n ↦ ∫ x in A, f n x ∂μ) atTop (𝓝 (∫ x in A, g x ∂μ)) := by + have hui : UnifIntegrable f 1 μ := unifIntegrable_one_of_sq_integral_le hf hM + have hL1 : Tendsto (fun n ↦ eLpNorm (f n - g) 1 μ) atTop (𝓝 0) := + tendsto_Lp_finite_of_tendstoInMeasure le_rfl ENNReal.one_ne_top + (fun n ↦ (hf n).aestronglyMeasurable) hg hui hconv + refine tendsto_setIntegral_of_L1 g hg.aestronglyMeasurable + (Filter.Eventually.of_forall fun n ↦ (hf n).integrable (by norm_num)) ?_ A + exact hL1.congr fun n ↦ + eLpNorm_one_eq_lintegral_eNorm ((hf n).aestronglyMeasurable.sub hg.aestronglyMeasurable) + +/-- **Set-integral limit from the a.e.-subsequence principle + an `L²` bound.** On a finite measure, +a family `f : ℕ → α → ℝ` with `f n ∈ L²`, a uniform second-moment bound `∫ (f n)² ≤ M`, a limit +`g ∈ L¹`, and the hypothesis that **every subsequence has a further subsequence converging to `g` +a.e.** satisfies `∫_A f n → ∫_A g`. This routes the composition of convergences (exp, sums, +products) through the a.e. level — where continuity is free — instead of through a +`TendstoInMeasure` algebra that Mathlib does not provide. The real sequence `∫_A f n` converges by +the subsequence principle (`tendsto_of_subseq_tendsto`): each subsequence's a.e.-sub-subsequence +gives convergence in measure (`tendstoInMeasure_of_tendsto_ae`), which +`tendsto_setIntegral_of_tendstoInMeasure_of_sq_bound` turns into the set-integral limit. This is the +endpoint the continuous-Girsanov Doléans limit consumes: `f n = exp(a·B^θⁿ)·Z⁽ⁿ⁾`, whose stochastic +part converges in measure (brick b) so every subsequence has an a.e.-convergent one, while the drift +parts converge everywhere. -/ +theorem tendsto_setIntegral_of_subseq_ae_of_sq_bound [IsFiniteMeasure μ] + {f : ℕ → α → ℝ} {g : α → ℝ} (hf : ∀ n, MemLp (f n) 2 μ) + {M : ℝ} (hM : ∀ n, ∫ x, (f n x) ^ 2 ∂μ ≤ M) (hg : MemLp g 1 μ) + (hsub : ∀ ns : ℕ → ℕ, Tendsto ns atTop atTop → + ∃ ms : ℕ → ℕ, ∀ᵐ x ∂μ, Tendsto (fun k ↦ f (ns (ms k)) x) atTop (𝓝 (g x))) + (A : Set α) : + Tendsto (fun n ↦ ∫ x in A, f n x ∂μ) atTop (𝓝 (∫ x in A, g x ∂μ)) := by + refine tendsto_of_subseq_tendsto (fun ns hns ↦ ?_) + obtain ⟨ms, hae⟩ := hsub ns hns + refine ⟨ms, ?_⟩ + have hconv : TendstoInMeasure μ (fun k ↦ f (ns (ms k))) atTop g := + tendstoInMeasure_of_tendsto_ae (fun k ↦ (hf _).aestronglyMeasurable) hae + exact tendsto_setIntegral_of_tendstoInMeasure_of_sq_bound + (fun k ↦ hf (ns (ms k))) (fun k ↦ hM (ns (ms k))) hg hconv A + +/-- **Fatou `L²`-membership of an a.e.-subsequence limit.** If every `f n ∈ L²` with a uniform +second moment `∫ (f n)² ≤ M`, and some subsequence has `f (msₖ) → g` a.e., then `g ∈ L²`: Fatou on +the squared enorms, `∫⁻ ‖g²‖ₑ ≤ liminf ∫⁻ ‖f(msₖ)²‖ₑ = liminf ∫ f(msₖ)² ≤ M < ∞`. No finiteness of +`μ` is needed (pure Fatou) — the limit-side companion to the finite-measure Vitali producers above, +and the single principle behind an a.e.-subsequential `L²` limit inheriting its family's uniform +second moment (both the Girsanov continuous and predictable Doléans densities consume it). -/ +theorem memLp_two_of_subseq_ae_of_sq_bound {f : ℕ → α → ℝ} {g : α → ℝ} + (hf : ∀ n, MemLp (f n) 2 μ) (hmeas : ∀ n, Measurable (f n)) + {M : ℝ} (hM : ∀ n, ∫ x, (f n x) ^ 2 ∂μ ≤ M) + (hsub : ∃ ms : ℕ → ℕ, ∀ᵐ x ∂μ, Tendsto (fun k ↦ f (ms k) x) atTop (𝓝 (g x))) : + MemLp g 2 μ := by + obtain ⟨ms, hae⟩ := hsub + have hgmeas : AEStronglyMeasurable g μ := + aestronglyMeasurable_of_tendsto_ae atTop (fun k ↦ (hmeas (ms k)).aestronglyMeasurable) hae + rw [memLp_two_iff_integrable_sq hgmeas] + refine ⟨hgmeas.pow 2, ?_⟩ + rw [hasFiniteIntegral_iff_eNorm] + have hsqbnd : ∀ k, ∫⁻ x, ‖(f (ms k) x) ^ 2‖ₑ ∂μ ≤ ENNReal.ofReal M := fun k ↦ by + have hint_sq := (memLp_two_iff_integrable_sq (hf (ms k)).aestronglyMeasurable).mp (hf (ms k)) + calc ∫⁻ x, ‖(f (ms k) x) ^ 2‖ₑ ∂μ + = ∫⁻ x, ENNReal.ofReal ((f (ms k) x) ^ 2) ∂μ := + lintegral_congr fun x ↦ by rw [Real.eNorm_eq_ofReal (sq_nonneg _)] + _ = ENNReal.ofReal (∫ x, (f (ms k) x) ^ 2 ∂μ) := + (ofReal_integral_eq_lintegral_ofReal hint_sq (ae_of_all _ fun x ↦ sq_nonneg _)).symm + _ ≤ ENNReal.ofReal M := ENNReal.ofReal_le_ofReal (hM (ms k)) + have hlim : (fun x ↦ ‖(g x) ^ 2‖ₑ) + =ᵐ[μ] fun x ↦ Filter.liminf (fun k ↦ ‖(f (ms k) x) ^ 2‖ₑ) atTop := by + filter_upwards [hae] with x hx + exact ((hx.pow 2).eNorm.liminf_eq).symm + rw [lintegral_congr_ae hlim] + exact ((lintegral_liminf_le (fun k ↦ ((hmeas (ms k)).pow_const 2).eNorm)).trans + ((liminf_le_liminf (Filter.Eventually.of_forall hsqbnd)).trans (liminf_const _).le)).trans_lt + ENNReal.ofReal_lt_top + +end MathFin diff --git a/LeanPool/MathFin/Probability/Support/DoobContinuous.lean b/LeanPool/MathFin/Probability/Support/DoobContinuous.lean new file mode 100644 index 0000000000..95b8e7b68b --- /dev/null +++ b/LeanPool/MathFin/Probability/Support/DoobContinuous.lean @@ -0,0 +1,64 @@ +/- +Copyright (c) 2026 Lean Pool contributors. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Lean Pool contributors +-/ +module + +public import TauCeti.Probability.Martingale.MaximalInequality.Event + +/-! +# Continuous-time Doob bound in real-valued notation + +Convert Tau Ceti's extended nonnegative running supremum to a real one using +its almost-sure finiteness theorem. +-/ + +@[expose] public section + +open MeasureTheory Filter Set +open scoped NNReal ENNReal + +namespace ProbabilityTheory + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} [IsFiniteMeasure μ] + {𝓕 : Filtration ℝ≥0 mΩ} {M : ℝ≥0 → Ω → ℝ} + +theorem maximal_ineq_norm (hM : Martingale M 𝓕 μ) (ε : ℝ) (T : ℝ≥0) + (hcont : ∀ ω, IsRightContinuous (M · ω)) : + ε • μ.real {ω | ε ≤ ⨆ i : Iic T, ‖M i ω‖} ≤ + ∫ ω in {ω | ε ≤ ⨆ i : Iic T, ‖M i ω‖}, ‖M T ω‖ ∂μ := by + by_cases hε : 0 ≤ ε + swap + · exact (mul_nonpos_of_nonpos_of_nonneg (le_of_not_ge hε) measureReal_nonneg).trans + (integral_nonneg fun _ ↦ norm_nonneg _) + have hrc : ∀ᵐ ω ∂μ, ∀ t < T, ContinuousWithinAt (fun u ↦ M u ω) (Ioi t) t := + ae_of_all _ fun ω t _ ↦ hcont ω t + let c : ℝ≥0 := ⟨ε, hε⟩ + have hevent : {ω | ε ≤ ⨆ i : Iic T, ‖M i ω‖} =ᵐ[μ] + {ω | (c : ℝ≥0∞) ≤ ⨆ t ≤ T, ENNReal.ofReal ‖M t ω‖} := by + filter_upwards [hM.ae_iSup_eNorm_lt_top hrc] with ω hω + let S : ℝ≥0∞ := ⨆ t ≤ T, ENNReal.ofReal ‖M t ω‖ + have hs : S ≠ ∞ := by simpa only [← ofReal_norm, S] using hω.ne + have hle (i : Iic T) : ‖M i ω‖ ≤ S.toReal := by + rw [← ENNReal.toReal_ofReal (norm_nonneg (M i ω))] + exact ENNReal.toReal_mono hs (le_iSup₂_of_le i i.2 le_rfl) + have hb : BddAbove (range fun i : Iic T ↦ ‖M i ω‖) := + ⟨S.toReal, fun _ ⟨i, hi⟩ ↦ hi ▸ hle i⟩ + have hsup : (⨆ i : Iic T, ‖M i ω‖) = S.toReal := by + refine le_antisymm (ciSup_le hle) ?_ + have hnonneg := (norm_nonneg (M T ω)).trans (le_ciSup hb ⟨T, le_rfl⟩) + refine ENNReal.toReal_le_of_le_ofReal hnonneg ?_ + exact iSup₂_le fun t ht ↦ ENNReal.ofReal_le_ofReal (le_ciSup hb ⟨t, ht⟩) + change (ε ≤ ⨆ i : Iic T, ‖M i ω‖) ↔ (c : ℝ≥0∞) ≤ S + rw [hsup, ← ENNReal.ofReal_coe_nnreal (p := c), ENNReal.ofReal_le_iff_le_toReal hs] + rfl + rw [measureReal_congr hevent, setIntegral_congr_set hevent] + have h := hM.norm.mul_measure_le_iSup_le_setIntegral (fun _ _ ↦ norm_nonneg _) + (hrc.mono fun _ h t ht ↦ (h t ht).norm) c + have hc : (c : ℝ≥0∞).toReal = ε := ENNReal.coe_toReal c + simpa only [ENNReal.toReal_mul, hc, smul_eq_mul, measureReal_def, + ENNReal.toReal_ofReal (integral_nonneg fun _ ↦ norm_nonneg _), c] + using ENNReal.toReal_mono ENNReal.ofReal_ne_top h + +end ProbabilityTheory diff --git a/LeanPool/MathFin/Probability/Support/LocalMartingale.lean b/LeanPool/MathFin/Probability/Support/LocalMartingale.lean new file mode 100644 index 0000000000..b006c77048 --- /dev/null +++ b/LeanPool/MathFin/Probability/Support/LocalMartingale.lean @@ -0,0 +1,105 @@ +/- +Copyright (c) 2025 Rémy Degenne. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Rémy Degenne, Lean Pool contributors +-/ +module + +-- Adapted from Rémy Degenne's BrownianMotion project for Lean Pool. + +public import Mathlib.Probability.Process.Indistinguishable +public import TauCeti.Probability.Martingale.ContinuousStopping +public import Mathlib.Probability.Process.LocalProperty +public import TauCeti.Probability.Process.Progressive + +/-! +# Local càdlàg martingales + +Adapted from BrownianMotion (commit 497e5e2a) for time indexed by the +nonnegative reals, using Mathlib localization and Tau Ceti optional stopping. +-/ + +@[expose] public section + +open MeasureTheory Filter +open scoped NNReal Topology + +namespace ProbabilityTheory + +variable {Ω E : Type*} {mΩ : MeasurableSpace Ω} +variable [NormedAddCommGroup E] [NormedSpace ℝ E] +variable {P : Measure Ω} {𝓕 : Filtration ℝ≥0 mΩ} {X : ℝ≥0 → Ω → E} + +/-- A process with càdlàg martingale stages along a localizing sequence. -/ +def IsLocalMartingale (X : ℝ≥0 → Ω → E) (𝓕 : Filtration ℝ≥0 mΩ) (P : Measure Ω) : Prop := + Locally (fun Y ↦ Martingale Y 𝓕 P ∧ ∀ ω, IsCadlag (Y · ω)) 𝓕 X P + +theorem Martingale.IsLocalMartingale (hX : Martingale X 𝓕 P) (hC : ∀ ω, IsCadlag (X · ω)) : + IsLocalMartingale X 𝓕 P := .of_prop ⟨hX, hC⟩ + +omit [NormedSpace ℝ E] in +theorem _root_.MeasureTheory.StronglyAdapted.stoppedProcess_indicator + (hX : StronglyAdapted 𝓕 X) (hC : ∀ ω, IsRightContinuous (X · ω)) + {τ : Ω → WithTop ℝ≥0} (hτ : IsStoppingTime 𝓕 τ) : + StronglyAdapted 𝓕 (stoppedProcess (fun t ↦ {ω | ⊥ < τ ω}.indicator (X t)) τ) := by + rw [stoppedProcess_indicator_comm'] + have hs := ((hX.isStronglyProgressive_of_isRightContinuous hC).stoppedProcess hτ).stronglyAdapted + exact fun t ↦ (hs t).indicator (𝓕.mono bot_le _ (hτ.measurableSet_gt ⊥)) + +omit [NormedAddCommGroup E] [NormedSpace ℝ E] in +private theorem stoppedProcess_of_eq_coe {ω : Ω} {t : ℝ≥0} {τ : Ω → WithTop ℝ≥0} + (s : ℝ≥0) (hτ : τ ω = t) : stoppedProcess X τ s ω = X (min s t) ω := by + rw [stoppedProcess, hτ, ← WithTop.coe_min, WithTop.untopA_eq_untop WithTop.coe_ne_top] + rfl + +omit [NormedSpace ℝ E] in +private theorem stoppedRightContinuous {ω : Ω} (hX : IsRightContinuous (X · ω)) + (τ : Ω → WithTop ℝ≥0) : IsRightContinuous (stoppedProcess X τ · ω) := by + cases h : τ ω with + | top => + have hstop : (stoppedProcess X τ · ω) = (X · ω) := + funext fun s ↦ stoppedProcess_eq_of_le (by rw [h]; exact le_top) + rwa [hstop] + | coe t => + simp only [stoppedProcess_of_eq_coe _ h] + intro s + obtain hst | hts := lt_or_ge s t + · exact hX (min s t) |>.comp (f := (min · t)) (by fun_prop) (by grind [Set.MapsTo]) + · exact (continuous_const (y := X t ω)).continuousWithinAt.congr (by grind) (by grind) + +omit [NormedSpace ℝ E] in +private theorem stoppedCadlag {ω : Ω} (hX : IsCadlag (X · ω)) (τ : Ω → WithTop ℝ≥0) : + IsCadlag (stoppedProcess X τ · ω) := by + cases h : τ ω with + | top => + have hstop : (stoppedProcess X τ · ω) = (X · ω) := + funext fun s ↦ stoppedProcess_eq_of_le (by rw [h]; exact le_top) + rwa [hstop] + | coe t => + refine ⟨stoppedRightContinuous hX.isRightContinuous τ, fun s ↦ ?_⟩ + simp only [stoppedProcess_of_eq_coe _ h] + obtain hst | hts := le_or_gt s t + · obtain ⟨l, hl⟩ := hX.tendsto_nhdsLT s + exact ⟨l, hl.congr' (Set.EqOn.eventuallyEq_nhdsWithin fun u hu ↦ by grind)⟩ + · refine ⟨X t ω, tendsto_const_nhds.congr' ?_⟩ + rw [eventuallyEq_nhdsWithin_iff, eventually_nhds_iff] + exact ⟨Set.Ioi t, by grind, isOpen_Ioi, by grind⟩ + +omit [NormedSpace ℝ E] in +theorem isStable_isCadlag : + IsStable 𝓕 (fun (Y : ℝ≥0 → Ω → E) ↦ ∀ ω, IsCadlag (Y · ω)) := by + intro Y hY τ hτ ω + simp only [stoppedProcess_indicator_comm'] + by_cases hω : ω ∈ {ω | ⊥ < τ ω} + · simpa only [Set.indicator_of_mem hω] using stoppedCadlag (hY ω) τ + · simpa only [Set.indicator_of_notMem hω] using (IsCadlag.const (c := (0 : E)) (X := ℝ≥0)) + +theorem isStable_martingale [IsFiniteMeasure P] [CompleteSpace E] : + IsStable 𝓕 (fun (Y : ℝ≥0 → Ω → E) ↦ Martingale Y 𝓕 P ∧ ∀ ω, IsCadlag (Y · ω)) := by + intro Y hY τ hτ + have hC : ∀ ω, IsRightContinuous (Y · ω) := fun ω ↦ (hY.2 ω).isRightContinuous + exact ⟨hY.1.stoppedProcess_indicator_of_ae_isRightContinuous + (hY.1.stronglyAdapted.isStronglyProgressive_of_isRightContinuous hC) + (ae_of_all _ hC) hτ, isStable_isCadlag Y hY.2 τ hτ⟩ + +end ProbabilityTheory diff --git a/LeanPool/MathFin/Risk/AcceptanceSet.lean b/LeanPool/MathFin/Risk/AcceptanceSet.lean new file mode 100644 index 0000000000..0dad070bbf --- /dev/null +++ b/LeanPool/MathFin/Risk/AcceptanceSet.lean @@ -0,0 +1,154 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Pricing.Duality.ConvexDuality +public import LeanPool.MathFin.Risk.Coherent +public import Mathlib.Algebra.Order.Star.Real + +/-! +# Coherent risk measures: the Artzner–Delbaen–Eber–Heath representation (finite state) + +A coherent risk measure `ρ` of losses on a finite state space `ι` (`IsCoherentRiskMeasure`) is, by +its four ADEH axioms, the supremum of expected loss `∑ qᵢ Lᵢ` over a set of representing +probability vectors `q`. The geometric content is convex duality: the **acceptance cone** +`{L | ρ L ≤ 0}` is a closed convex cone, and a rejected loss is separated from it by a representing +density — the *same* Hahn–Banach separation that gives the FTAP its equivalent martingale measure +(here via the point-from-cone primitive `MathFin.exists_separating_of_not_mem_cone`). This is the +risk-side face of the convex-duality unification. + +The representation is stated as `IsLUB` (ρ L is the least upper bound of the expected losses), which +is the precise "ρ = sup over measures" statement without the conditionally-complete-lattice `iSup` +overhead. + +On a finite state space with measurable singletons and any finite reference measure `P`, every +loss is integrable and pointwise order implies almost-sure order. The resulting pointwise +monotonicity of `ρ` suffices for the separation argument. The representing vectors are specified +by their nonpositive expectation on every acceptable loss. + +## Main definitions + +* `representingSet`: the probability vectors `q` (`qᵢ ≥ 0`, `∑ qᵢ = 1`) with `∑ qᵢ Zᵢ ≤ 0` for + every acceptable loss `Z` (`ρ Z ≤ 0`), the densities that separate the acceptance cone. + +## Main results + +* `MathFin.IsCoherentRiskMeasure.acceptance_closed`, `.convex_acceptance`, `.cone`: the acceptance + set `{L | ρ L ≤ 0}` is a closed convex cone. +* `MathFin.coherentRisk_isLUB` — the representation + +## References + +* [P. Artzner et al., *Coherent measures of risk*][ArtznerDelbaenEberHeath1999] + +## Tags + +coherent risk measure, Artzner-Delbaen-Eber-Heath, acceptance set, dual representation, +Hahn-Banach separation, representing measures, MSC 91G70, MSC 91G80, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory + +namespace IsCoherentRiskMeasure +variable {ι : Type*} [Fintype ι] [MeasurableSpace ι] [MeasurableSingletonClass ι] + {P : Measure ι} [IsFiniteMeasure P] {ρ : (ι → ℝ) → ℝ} + +omit [Fintype ι] in +/-- The acceptance set `{L | ρ L ≤ 0}` is closed (ρ is continuous). -/ +lemma acceptance_closed [Finite ι] (hρ : IsCoherentRiskMeasure P ρ) : + IsClosed {L : ι → ℝ | ρ L ≤ 0} := + isClosed_le hρ.continuous continuous_const + +omit [Fintype ι] [MeasurableSingletonClass ι] [IsFiniteMeasure P] in +/-- `0` is acceptable. -/ +lemma zero_mem (hρ : IsCoherentRiskMeasure P ρ) : (0 : ι → ℝ) ∈ {L : ι → ℝ | ρ L ≤ 0} := + hρ.rho_zero.le + +omit [Fintype ι] in +/-- The acceptance set is a cone (positive homogeneity). -/ +lemma cone [Finite ι] (hρ : IsCoherentRiskMeasure P ρ) : + ∀ ⦃L⦄, L ∈ {L : ι → ℝ | ρ L ≤ 0} → ∀ ⦃c : ℝ⦄, 0 ≤ c → c • L ∈ {L : ι → ℝ | ρ L ≤ 0} := + fun _ hL _ hc ↦ (hρ.const_mul .of_finite hc).trans_le (mul_nonpos_of_nonneg_of_nonpos hc hL) + +omit [Fintype ι] in +/-- The acceptance set is convex. -/ +lemma convex_acceptance [Finite ι] (hρ : IsCoherentRiskMeasure P ρ) : + Convex ℝ {L : ι → ℝ | ρ L ≤ 0} := by + simpa using hρ.convexOn_univ.convex_le 0 + +omit [Fintype ι] in +/-- Every nonpositive loss (a gain in every state) is acceptable (monotonicity). -/ +lemma nonpos_mem [Finite ι] (hρ : IsCoherentRiskMeasure P ρ) {L : ι → ℝ} (hL : L ≤ 0) : + L ∈ {L : ι → ℝ | ρ L ≤ 0} := + (hρ.mono_of_le hL).trans_eq hρ.rho_zero + +end IsCoherentRiskMeasure + +/-- The representing set: probability vectors that price every acceptable loss nonpositively +(the densities separating the acceptance cone). -/ +def representingSet {ι : Type*} [Fintype ι] (ρ : (ι → ℝ) → ℝ) : Set (ι → ℝ) := + {q | (∀ i, 0 ≤ q i) ∧ (∑ i, q i = 1) ∧ ∀ Z ∈ {Y : ι → ℝ | ρ Y ≤ 0}, ∑ i, q i * Z i ≤ 0} + +/-- **Coherent-risk representation (Artzner–Delbaen–Eber–Heath, finite state).** A coherent risk +measure `ρ` of losses is the supremum of expected loss over its representing probability vectors: +`ρ L` is the least upper bound of `{∑ qᵢ Lᵢ | q ∈ representingSet ρ}`. The upper bound is +cash-invariance; the least-upper-bound is the point-from-cone separation of the rejected loss +`L − b`, for an upper bound `b < ρ L`, from the acceptance cone, normalised to a representing +density. -/ +theorem coherentRisk_isLUB {ι : Type*} [Fintype ι] [MeasurableSpace ι] + [MeasurableSingletonClass ι] {P : Measure ι} [IsFiniteMeasure P] {ρ : (ι → ℝ) → ℝ} + (hρ : IsCoherentRiskMeasure P ρ) (L : ι → ℝ) : + IsLUB ((fun q ↦ ∑ i, q i * L i) '' representingSet ρ) (ρ L) := by + classical + -- a probability vector prices a shifted loss at the shifted price + have hshift {q : ι → ℝ} (hq : ∑ i, q i = 1) (L : ι → ℝ) (m : ℝ) : + ∑ i, q i * (L i + m) = ∑ i, q i * L i + m := by + simp [mul_add, Finset.sum_add_distrib, ← Finset.sum_mul, hq] + constructor + · rintro _ ⟨q, ⟨-, hq₁, hq⟩, rfl⟩ + have hmem : (fun i ↦ L i + -ρ L) ∈ {Y : ι → ℝ | ρ Y ≤ 0} := + ((hρ.add_const .of_finite _).trans (add_neg_cancel _)).le + have := hq _ hmem + rw [hshift hq₁] at this + linarith + · intro b hb + by_contra hlt + rw [not_le] at hlt + have hL' : (fun i ↦ L i + -b) ∉ {Y : ι → ℝ | ρ Y ≤ 0} := by + change ¬ ρ _ ≤ 0 + rw [hρ.add_const .of_finite, not_le]; linarith + obtain ⟨p, hp_le, hp_pos⟩ := exists_separating_of_not_mem_cone _ hρ.convex_acceptance + hρ.acceptance_closed hρ.cone hρ.zero_mem hL' + have hp_nonneg (i : ι) : 0 ≤ p i := by + have hle := hp_le _ (hρ.nonpos_mem (L := -Pi.single i 1) fun j ↦ by + simp only [Pi.neg_apply, Pi.single_apply, Pi.zero_apply] + split_ifs <;> norm_num) + simpa [Pi.single_apply] using hle + have hS : 0 < ∑ i, p i := by + refine lt_of_le_of_ne (Finset.sum_nonneg fun i _ ↦ hp_nonneg i) fun h0 ↦ ?_ + have hp0 := (Finset.sum_eq_zero_iff_of_nonneg fun i _ ↦ hp_nonneg i).1 h0.symm + simp [hp0] at hp_pos + set S := ∑ i, p i + have hq_mem : (fun i ↦ p i / S) ∈ representingSet ρ := + ⟨fun i ↦ div_nonneg (hp_nonneg i) hS.le, by rw [← Finset.sum_div, div_self hS.ne'], + fun Z hZ ↦ by + simp_rw [div_mul_eq_mul_div, ← Finset.sum_div] + exact div_nonpos_of_nonpos_of_nonneg (hp_le Z hZ) hS.le⟩ + have hle := hb ⟨_, hq_mem, rfl⟩ + have hq₁ : ∑ i, p i / S = 1 := hq_mem.2.1 + have hpos : 0 < ∑ i, p i / S * (L i + -b) := by + simp_rw [div_mul_eq_mul_div, ← Finset.sum_div] + exact div_pos hp_pos hS + rw [hshift hq₁] at hpos + linarith + +end MathFin diff --git a/LeanPool/MathFin/Risk/Additivity.lean b/LeanPool/MathFin/Risk/Additivity.lean new file mode 100644 index 0000000000..89387b4972 --- /dev/null +++ b/LeanPool/MathFin/Risk/Additivity.lean @@ -0,0 +1,71 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.Gaussian +public import LeanPool.MathFin.Probability.Gaussian.NormalQuantile + +/-! +# Gaussian VaR/CVaR additivity at perfect positive correlation + +At `ρ = 1`, the joint-gaussian standard deviation becomes +`√(σ₁² + 2 σ₁ σ₂ + σ₂²) = σ₁ + σ₂` and the subadditivity inequality from +`Risk.CoherentAxioms` is sharpened to equality. This is the extremal +case where diversification provides no benefit. + +## Main results + +* `gaussianVaR_additive_at_rho_one`: at `ρ = 1`, VaR is additive. +* `gaussianCVaR_additive_at_rho_one`: at `ρ = 1`, CVaR is additive. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Ch 8 + +## Tags + +VaR additivity, CVaR additivity, perfect correlation, Gaussian risk, diversification benefit, +MSC 91G70, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-- **Gaussian VaR additivity at perfect positive correlation** (`ρ = 1`): +the joint stdev becomes `σ₁ + σ₂` and the subadditivity inequality is an +equality. -/ +lemma gaussianVaR_additive_at_rho_one {μ₁ μ₂ σ₁ σ₂ z : ℝ} + (h₁ : 0 ≤ σ₁) (h₂ : 0 ≤ σ₂) : + gaussianVaR (μ₁ + μ₂) + (Real.sqrt (σ₁^2 + 2 * 1 * σ₁ * σ₂ + σ₂^2)) z = + gaussianVaR μ₁ σ₁ z + gaussianVaR μ₂ σ₂ z := by + unfold gaussianVaR + have h_sum_sq : σ₁^2 + 2 * 1 * σ₁ * σ₂ + σ₂^2 = (σ₁ + σ₂)^2 := by ring + rw [h_sum_sq] + have h_sum_nn : 0 ≤ σ₁ + σ₂ := add_nonneg h₁ h₂ + rw [Real.sqrt_sq h_sum_nn] + ring + +/-- **Gaussian CVaR additivity at perfect positive correlation** (`ρ = 1`). -/ +lemma gaussianCVaR_additive_at_rho_one {μ₁ μ₂ σ₁ σ₂ z α : ℝ} + (h₁ : 0 ≤ σ₁) (h₂ : 0 ≤ σ₂) : + gaussianCVaR (μ₁ + μ₂) + (Real.sqrt (σ₁^2 + 2 * 1 * σ₁ * σ₂ + σ₂^2)) z α = + gaussianCVaR μ₁ σ₁ z α + gaussianCVaR μ₂ σ₂ z α := by + unfold gaussianCVaR + have h_sum_sq : σ₁^2 + 2 * 1 * σ₁ * σ₂ + σ₂^2 = (σ₁ + σ₂)^2 := by ring + rw [h_sum_sq] + have h_sum_nn : 0 ≤ σ₁ + σ₂ := add_nonneg h₁ h₂ + rw [Real.sqrt_sq h_sum_nn] + ring + +end MathFin diff --git a/LeanPool/MathFin/Risk/Coherent.lean b/LeanPool/MathFin/Risk/Coherent.lean new file mode 100644 index 0000000000..3ee3ef549f --- /dev/null +++ b/LeanPool/MathFin/Risk/Coherent.lean @@ -0,0 +1,157 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Analysis.Convex.Continuous +public import Mathlib.Analysis.InnerProductSpace.Basic +public import Mathlib.Analysis.RCLike.Lemmas +public import Mathlib.MeasureTheory.Function.L1Space.Integrable + +/-! +# Coherent risk measures: the four axioms of Artzner, Delbaen, Eber and Heath + +A **coherent risk measure** on the integrable losses of a measure space `(Ω, P)` is a functional +`ρ : (Ω → ℝ) → ℝ` with the four axioms of Artzner, Delbaen, Eber and Heath, *Coherent measures of +risk*, Math. Finance **9** (1999), in the convention of McNeil, Frey and Embrechts (*Quantitative +Risk Management*, Definition 2.18): a **loss** is signed as a loss, so a larger `X` is worse and +`ρ` increases with it. + +* `mono`: `X ≤ Y` almost surely gives `ρ X ≤ ρ Y`; +* `add_const`: `ρ (X + m) = ρ X + m`, so `ρ X` is the capital that makes the loss `X` acceptable; +* `const_mul`: `ρ (c X) = c ρ X` for `c ≥ 0`; +* `add_le`: `ρ (X + Y) ≤ ρ X + ρ Y`. + +This is the one coherence structure of the library: value-at-risk's cousin expected shortfall, the +spectral risk measures, worst-case loss and the acceptance-set theory +(`Risk/AcceptanceSet.lean`) all land in it. The older *positions* convention of the ADEH +paper (a position `X` is a gain, its loss is `−X`; `ρ` decreases with `X` and +`ρ (X + m) = ρ X − m`) is the same object at `L ↦ ρ(−L)` on a finite state space with counting +measure; `Risk/PositionsConvention.lean` proves that. + +The axioms constrain `ρ` on integrable losses. Almost-sure monotonicity gives equal risk to losses +that are equal almost surely. The additional law-invariance property is treated in +`Risk/LawInvariance.lean`. On a finite state space with measurable singletons and a finite +reference measure, every function is integrable and pointwise order implies almost-sure order. +This gives the finite-state monotonicity and continuity lemmas for any such reference measure. + +## Main definitions + +* `IsConvexRiskMeasure`: the base object of the theory (Föllmer and Schied 2002): almost-sure + monotonicity, translation `ρ (X + m) = ρ X + m`, and convexity on the integrable losses. +* `IsCoherentRiskMeasure`: the four axioms of a coherent risk measure `ρ` of losses on a measure + space `(Ω, P)`: almost-sure monotonicity, translation `ρ (X + m) = ρ X + m`, positive + homogeneity `ρ (c X) = c ρ X` for `c ≥ 0`, and subadditivity. + +## Main results + +* `IsCoherentRiskMeasure.toIsConvexRiskMeasure`: a coherent risk measure is a convex one (a parent + projection). +* `IsCoherentRiskMeasure.rho_zero`: `ρ 0 = 0`. +* `convexOn_of_const_mul_of_add_le`: positive homogeneity and subadditivity give convexity. +* `IsCoherentRiskMeasure.mono_of_le`, `IsCoherentRiskMeasure.continuous`: on a finite state space + `ρ` is pointwise-monotone and continuous. + +## Tags + +coherent risk measure, Artzner-Delbaen-Eber-Heath, subadditivity, translation invariance, +positive homogeneity, monotonicity, capital requirement, MSC 91G70, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- A measure that charges every point of a countable space sees all of it: a property holds +almost everywhere exactly when it holds everywhere. Counting measure is the case `P {ω} = 1`. -/ +lemma ae_iff_forall_of_singleton_ne_zero {P : Measure Ω} {p : Ω → Prop} [Countable Ω] + (hP : ∀ ω, P {ω} ≠ 0) : (∀ᵐ ω ∂P, p ω) ↔ ∀ ω, p ω := + ae_iff_of_countable.trans <| forall_congr' fun ω ↦ ⟨fun h ↦ h (hP ω), fun h _ ↦ h⟩ + +/-- The three axioms of a **convex risk measure** (Föllmer and Schied, *Convex measures of risk +and trading constraints*, Finance Stoch. 6 (2002)) for a functional `ρ` on the integrable losses of +`(Ω, P)`, in the loss convention of `IsCoherentRiskMeasure`: almost-sure monotonicity, +translation `ρ (X + m) = ρ X + m`, and convexity. This is the base object: the entropic risk +measure and shortfall risk are convex and not coherent, and `IsCoherentRiskMeasure` extends it +with positive homogeneity and subadditivity. -/ +structure IsConvexRiskMeasure (P : Measure Ω) (ρ : (Ω → ℝ) → ℝ) : Prop where + mono : ∀ ⦃X Y : Ω → ℝ⦄, Integrable X P → Integrable Y P → X ≤ᵐ[P] Y → ρ X ≤ ρ Y + add_const : ∀ ⦃X : Ω → ℝ⦄, Integrable X P → ∀ m : ℝ, ρ (fun ω ↦ X ω + m) = ρ X + m + convexOn : ConvexOn ℝ {X | Integrable X P} ρ + +/-- Positive homogeneity and subadditivity give convexity on the integrable losses. -/ +lemma convexOn_of_const_mul_of_add_le {P : Measure Ω} {ρ : (Ω → ℝ) → ℝ} + (const_mul : ∀ ⦃X : Ω → ℝ⦄, Integrable X P → ∀ ⦃c : ℝ⦄, 0 ≤ c → + ρ (fun ω ↦ c * X ω) = c * ρ X) + (add_le : ∀ ⦃X Y : Ω → ℝ⦄, Integrable X P → Integrable Y P → + ρ (fun ω ↦ X ω + Y ω) ≤ ρ X + ρ Y) : + ConvexOn ℝ {X | Integrable X P} ρ := by + refine ⟨fun x hx y hy a b _ _ _ ↦ ?_, fun x hx y hy a b ha hb _ ↦ ?_⟩ + · exact (hx.smul a).add (hy.smul b) + · have h := add_le (hx.const_mul a) (hy.const_mul b) + rw [const_mul hx ha, const_mul hy hb] at h + exact h + +/-- The four axioms of a **coherent risk measure** (Artzner, Delbaen, Eber and Heath 1999; +McNeil–Frey–Embrechts, Definition 2.18) for a functional `ρ` on the integrable losses of +`(Ω, P)`: monotonicity, translation invariance, positive homogeneity and subadditivity. A loss is +signed as a loss, so a larger `X` is worse and `ρ` increases with it. It is a convex risk measure +(`toIsConvexRiskMeasure`): convexity is the default of that field, derived from positive +homogeneity and subadditivity, so a constructor supplies the four axioms only. -/ +structure IsCoherentRiskMeasure (P : Measure Ω) (ρ : (Ω → ℝ) → ℝ) : Prop + extends IsConvexRiskMeasure P ρ where + const_mul : ∀ ⦃X : Ω → ℝ⦄, Integrable X P → ∀ ⦃c : ℝ⦄, 0 ≤ c → + ρ (fun ω ↦ c * X ω) = c * ρ X + add_le : ∀ ⦃X Y : Ω → ℝ⦄, Integrable X P → Integrable Y P → + ρ (fun ω ↦ X ω + Y ω) ≤ ρ X + ρ Y + convexOn := convexOn_of_const_mul_of_add_le const_mul add_le + +namespace IsCoherentRiskMeasure + +variable {P : Measure Ω} {ρ : (Ω → ℝ) → ℝ} + +/-- `ρ 0 = 0` (positive homogeneity at `c = 2`). -/ +lemma rho_zero (hρ : IsCoherentRiskMeasure P ρ) : ρ 0 = 0 := by + have h := hρ.const_mul (integrable_zero Ω ℝ P) (c := 2) (by norm_num) + rw [show (fun ω ↦ 2 * (0 : Ω → ℝ) ω) = 0 by ext; simp] at h + linarith + +section Finite + +variable {ι : Type*} [Fintype ι] [MeasurableSpace ι] [MeasurableSingletonClass ι] + {P : Measure ι} [IsFiniteMeasure P] {ρ : (ι → ℝ) → ℝ} + +omit [Fintype ι] in +/-- On a finite state space a pointwise smaller loss has the smaller risk: pointwise order implies +almost-sure order, and every function is integrable. -/ +lemma mono_of_le [Finite ι] (hρ : IsCoherentRiskMeasure P ρ) {X Y : ι → ℝ} (h : X ≤ Y) : + ρ X ≤ ρ Y := + hρ.mono .of_finite .of_finite (ae_of_all _ h) + +omit [Fintype ι] in +/-- A finite-state coherent risk measure is convex on all of `ℝ^ι`. -/ +lemma convexOn_univ [Finite ι] (hρ : IsCoherentRiskMeasure P ρ) : ConvexOn ℝ Set.univ ρ := by + simpa [show {X : ι → ℝ | Integrable X P} = Set.univ from + Set.eq_univ_of_forall fun _ ↦ .of_finite] using hρ.convexOn + +omit [Fintype ι] in +/-- A finite-state coherent risk measure is continuous (a finite convex function on `ℝ^ι`). -/ +lemma continuous [Finite ι] (hρ : IsCoherentRiskMeasure P ρ) : Continuous ρ := by + have := Fintype.ofFinite ι + rw [← continuousOn_univ] + exact hρ.convexOn_univ.continuousOn isOpen_univ + +end Finite + +end IsCoherentRiskMeasure + +end MathFin diff --git a/LeanPool/MathFin/Risk/CoherentAxioms.lean b/LeanPool/MathFin/Risk/CoherentAxioms.lean new file mode 100644 index 0000000000..d2ac11ed14 --- /dev/null +++ b/LeanPool/MathFin/Risk/CoherentAxioms.lean @@ -0,0 +1,238 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.Gaussian +public import LeanPool.MathFin.Risk.GaussianExpectedShortfall +public import LeanPool.MathFin.Risk.GaussianValueAtRisk + +/-! +# Coherence of Gaussian value-at-risk and expected shortfall + +The closed forms `gaussianVaR μ σ z = μ + σ z` and `gaussianCVaR μ σ z α = μ + σ ϕ(z)/(1 − α)` +(`Risk/Gaussian.lean`) are the value-at-risk and the expected shortfall of a loss +`L ~ N(μ, σ²)` at the normal quantile `z = Φ⁻¹(α)` (`valueAtRisk_of_hasLaw_gaussianReal`, +`expectedShortfall_of_hasLaw_gaussianReal`). This file records how the four axioms of Artzner, +Delbaen, Eber and Heath (1999) read on them. + +**Expected shortfall.** It is coherent on every integrable loss, Gaussian or not +(`expectedShortfall_isCoherentRiskMeasure`, an instance of the library's one coherence structure +`IsCoherentRiskMeasure`). Translation, homogeneity and monotonicity of Gaussian expected shortfall +need nothing Gaussian: they are the structure's axioms. What the Gaussian family adds is the closed +form of the sum. A jointly Gaussian pair has a Gaussian sum, so the structure's +`ES(X + Y) ≤ ES X + ES Y` is the parameter inequality `gaussianCVaR_sd_add_le`, with the variance of +the sum in the volatility slot. +**Value-at-risk.** It is not coherent in general (`Risk/VaRSuperadditivity.lean`), but on a +jointly Gaussian pair at a level `α ≥ 1/2` it is subadditive +(`valueAtRisk_add_le_of_hasGaussianLaw` there), because `VaR = E + sd Φ⁻¹(α)` and the standard +deviation is subadditive (`sqrt_variance_add_le`). + +**The random-variable side.** For a Gaussian loss `X`, the Gaussian laws of the affine images +`X + c` and `λ X` (`gaussianReal_add_const`, `gaussianReal_const_mul`) turn the value-at-risk and +the expected shortfall of the image into the closed forms at the transformed parameters, and the +parameter identities below finish the proofs: +`valueAtRisk_add_const_of_hasGaussianLaw`, `valueAtRisk_const_mul_of_hasGaussianLaw`, +`expectedShortfall_add_const_of_hasGaussianLaw`, `expectedShortfall_const_mul_of_hasGaussianLaw`. +(Translation and homogeneity of VaR and ES hold for every loss, `valueAtRisk_add_const`, +`expectedShortfall_add_const`; what these state is that the closed form is carried along.) + +**The parameter formulas.** `gaussianVaR_translation`, `gaussianCVaR_translation`, +`gaussianVaR_positiveHomogeneity`, `gaussianCVaR_positiveHomogeneity`, `gaussianVaR_monotone_mean`, +`gaussianCVaR_monotone_mean`, `joint_stdev_le`, `gaussianVaR_subadditive` and +`gaussianCVaR_subadditive` are identities and inequalities about the two real functions `μ + σ z` +and `μ + σ ϕ(z)/(1 − α)` on all real parameters, including `σ < 0` and `α ≥ 1`, where neither is +the risk measure of any law. They stay as parameter algebra for that reason, and the translation +and homogeneity ones are the lemmas the random-variable theorems consume. Monotonicity in the mean +orders the parameters at equal volatility, not random variables, so it keeps its parameter form. +In `gaussianVaR_subadditive` and `gaussianCVaR_subadditive` the correlation `ρ` is a free parameter; +`valueAtRisk_add_le_of_hasGaussianLaw` and `gaussianCVaR_sd_add_le` are the statements at the +correlation a pair actually has. + +## Main results + +* `gaussianCVaR_sd_add_le`: the closed-form CVaR of a jointly Gaussian pair is subadditive, with + the exact volatility of the sum; a corollary of the coherence of expected shortfall. +* `joint_stdev_le`: `√(σ₁² + 2 ρ σ₁ σ₂ + σ₂²) ≤ σ₁ + σ₂` for `ρ ≤ 1` and `σ_i ≥ 0`. +* The parameter formulas listed above, and the four random-variable theorems that consume the + translation and homogeneity ones. + +## References + +* [C. Acerbi and D. Tasche, *On the coherence of expected shortfall*][AcerbiTasche2002] +* [P. Artzner et al., *Coherent measures of risk*][ArtznerDelbaenEberHeath1999] +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Ch 2.3 + +## Tags + +coherence of VaR, expected shortfall coherence, Gaussian VaR, subadditivity, +jointly Gaussian losses, translation invariance, MSC 91G70, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open Real MeasureTheory Set ProbabilityTheory + +/-- **VaR translation invariance**: `VaR(L + c) = VaR(L) + c`. -/ +lemma gaussianVaR_translation (μ σ z c : ℝ) : + gaussianVaR (μ + c) σ z = gaussianVaR μ σ z + c := by + unfold gaussianVaR; ring + +/-- **CVaR translation invariance**: `CVaR(L + c) = CVaR(L) + c`. -/ +lemma gaussianCVaR_translation (μ σ z α c : ℝ) : + gaussianCVaR (μ + c) σ z α = gaussianCVaR μ σ z α + c := by + unfold gaussianCVaR; ring + +/-- **VaR positive homogeneity**: `VaR(λ·L) = λ·VaR(L)` for `λ ≥ 0`. The volatility +scales by `|λ|·σ`, so the hypothesis `0 ≤ λ` is load-bearing (it discharges `|λ| = λ`). -/ +lemma gaussianVaR_positiveHomogeneity (μ σ z : ℝ) {l : ℝ} (hl : 0 ≤ l) : + gaussianVaR (l * μ) (|l| * σ) z = l * gaussianVaR μ σ z := by + unfold gaussianVaR; rw [abs_of_nonneg hl]; ring + +/-- **CVaR positive homogeneity**: `CVaR(λ·L) = λ·CVaR(L)` for `λ ≥ 0` (volatility +scales by `|λ|·σ`, so `0 ≤ λ` is load-bearing). -/ +lemma gaussianCVaR_positiveHomogeneity (μ σ z α : ℝ) {l : ℝ} (hl : 0 ≤ l) : + gaussianCVaR (l * μ) (|l| * σ) z α = l * gaussianCVaR μ σ z α := by + unfold gaussianCVaR; rw [abs_of_nonneg hl]; ring + +/-- **VaR monotonicity in mean** at the same volatility and right-tail quantile: +if `μ₁ ≤ μ₂` and `σ ≥ 0`, then `VaR(L₁) ≤ VaR(L₂)`. -/ +lemma gaussianVaR_monotone_mean {μ₁ μ₂ σ z : ℝ} + (hμ : μ₁ ≤ μ₂) : + gaussianVaR μ₁ σ z ≤ gaussianVaR μ₂ σ z := by + unfold gaussianVaR + linarith + +/-- **CVaR monotonicity in mean** at the same volatility: if `μ₁ ≤ μ₂`, then +`CVaR(L₁) ≤ CVaR(L₂)`. -/ +lemma gaussianCVaR_monotone_mean {μ₁ μ₂ σ z α : ℝ} + (hμ : μ₁ ≤ μ₂) : + gaussianCVaR μ₁ σ z α ≤ gaussianCVaR μ₂ σ z α := by + unfold gaussianCVaR + linarith + +/-- **Joint-standard-deviation triangle inequality**: +`√(σ₁² + 2 ρ σ₁ σ₂ + σ₂²) ≤ σ₁ + σ₂` whenever `ρ ≤ 1` and `σ_i ≥ 0`. This is +the substantive inequality behind gaussian subadditivity. -/ +lemma joint_stdev_le {σ₁ σ₂ ρ : ℝ} + (h₁ : 0 ≤ σ₁) (h₂ : 0 ≤ σ₂) (hρ : ρ ≤ 1) : + Real.sqrt (σ₁ ^ 2 + 2 * ρ * σ₁ * σ₂ + σ₂ ^ 2) ≤ σ₁ + σ₂ := by + have h_sum_sq : σ₁ ^ 2 + 2 * ρ * σ₁ * σ₂ + σ₂ ^ 2 ≤ (σ₁ + σ₂) ^ 2 := by + have h_prod : 0 ≤ σ₁ * σ₂ := mul_nonneg h₁ h₂ + nlinarith [mul_nonneg (sub_nonneg.mpr hρ) h_prod] + have h_sum_nn : 0 ≤ σ₁ + σ₂ := add_nonneg h₁ h₂ + have : Real.sqrt (σ₁ ^ 2 + 2 * ρ * σ₁ * σ₂ + σ₂ ^ 2) ≤ + Real.sqrt ((σ₁ + σ₂) ^ 2) := Real.sqrt_le_sqrt h_sum_sq + rwa [Real.sqrt_sq h_sum_nn] at this + +/-- **Gaussian VaR subadditivity**: for joint-gaussian `L₁ + L₂ ~ N(μ₁ + μ₂, σ₊²)` +with `σ₊ = √(σ₁² + 2 ρ σ₁ σ₂ + σ₂²)` and `ρ ≤ 1`, `σ_i ≥ 0`, `z ≥ 0`: +`VaR(L₁ + L₂) ≤ VaR(L₁) + VaR(L₂)`. -/ +lemma gaussianVaR_subadditive {μ₁ μ₂ σ₁ σ₂ ρ z : ℝ} + (h₁ : 0 ≤ σ₁) (h₂ : 0 ≤ σ₂) (hρ : ρ ≤ 1) (hz : 0 ≤ z) : + gaussianVaR (μ₁ + μ₂) + (Real.sqrt (σ₁ ^ 2 + 2 * ρ * σ₁ * σ₂ + σ₂ ^ 2)) z ≤ + gaussianVaR μ₁ σ₁ z + gaussianVaR μ₂ σ₂ z := by + unfold gaussianVaR + have h_stdev : Real.sqrt (σ₁ ^ 2 + 2 * ρ * σ₁ * σ₂ + σ₂ ^ 2) ≤ σ₁ + σ₂ := + joint_stdev_le h₁ h₂ hρ + nlinarith + +/-- **Gaussian CVaR subadditivity**: same setup as `gaussianVaR_subadditive`, +plus the level `α < 1`. -/ +lemma gaussianCVaR_subadditive {μ₁ μ₂ σ₁ σ₂ ρ z α : ℝ} + (h₁ : 0 ≤ σ₁) (h₂ : 0 ≤ σ₂) (hρ : ρ ≤ 1) (hα : α < 1) : + gaussianCVaR (μ₁ + μ₂) + (Real.sqrt (σ₁ ^ 2 + 2 * ρ * σ₁ * σ₂ + σ₂ ^ 2)) z α ≤ + gaussianCVaR μ₁ σ₁ z α + gaussianCVaR μ₂ σ₂ z α := by + unfold gaussianCVaR + have h_stdev : Real.sqrt (σ₁ ^ 2 + 2 * ρ * σ₁ * σ₂ + σ₂ ^ 2) ≤ σ₁ + σ₂ := + joint_stdev_le h₁ h₂ hρ + have h_one_alpha : 0 < 1 - α := by linarith + have h_pdf_nn : 0 ≤ gaussianPDFReal 0 1 z := gaussianPDFReal_nonneg _ _ _ + have h_factor_nn : 0 ≤ gaussianPDFReal 0 1 z / (1 - α) := + div_nonneg h_pdf_nn h_one_alpha.le + have h_mul : Real.sqrt (σ₁ ^ 2 + 2 * ρ * σ₁ * σ₂ + σ₂ ^ 2) * + (gaussianPDFReal 0 1 z / (1 - α)) ≤ + (σ₁ + σ₂) * (gaussianPDFReal 0 1 z / (1 - α)) := + mul_le_mul_of_nonneg_right h_stdev h_factor_nn + linarith + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} {X Y : Ω → ℝ} {α : ℝ} + +/-- **Closed-form CVaR is subadditive on jointly Gaussian losses**: for a jointly Gaussian pair +`(X, Y)` (degenerate margins allowed), the closed form `gaussianCVaR` at the +mean `E X + E Y` and the standard deviation of `X + Y` is at most the sum of the closed forms at +the margins. It is the subadditivity of expected shortfall (`expectedShortfall_add_le`) read +through the Gaussian laws of `X`, `Y` and `X + Y`. -/ +theorem gaussianCVaR_sd_add_le (h : HasGaussianLaw (fun ω ↦ (X ω, Y ω)) P) (hα : α ∈ Ioo 0 1) : + gaussianCVaR (P[X] + P[Y]) √Var[fun ω ↦ X ω + Y ω; P] (PhiInv α) α ≤ + gaussianCVaR P[X] √Var[X; P] (PhiInv α) α + gaussianCVaR P[Y] √Var[Y; P] (PhiInv α) α := by + have := h.isProbabilityMeasure + have key := expectedShortfall_add_le h.fst.integrable h.snd.integrable hα + rwa [expectedShortfall_of_hasGaussianLaw h.fun_add hα, + expectedShortfall_of_hasGaussianLaw h.fst hα, expectedShortfall_of_hasGaussianLaw h.snd hα, + integral_add h.fst.integrable h.snd.integrable] at key + +/-! ### The random-variable side: the affine images of a Gaussian loss -/ + +/-- A Gaussian loss, as the law `N(E X, Var X)` of `Risk/Gaussian.lean`. -/ +lemma hasLaw_gaussianReal_of_hasGaussianLaw (hX : HasGaussianLaw X P) : + HasLaw X (gaussianReal P[X] Var[X; P].toNNReal) P := + ⟨hX.aemeasurable, hX.map_eq_gaussianReal⟩ + +/-- **Translation of a Gaussian loss**, through the Gaussian law `N(E X + c, Var X)` of `X + c`: +`VaR_α(X + c) = gaussianVaR (E X) (sd X) Φ⁻¹(α) + c`. The location shift of +`gaussianVaR_translation`, read as the value-at-risk of the shifted loss. -/ +theorem valueAtRisk_add_const_of_hasGaussianLaw (hX : HasGaussianLaw X P) (hα : α ∈ Ioo 0 1) + (c : ℝ) : + valueAtRisk (fun ω ↦ X ω + c) P α = gaussianVaR P[X] √Var[X; P] (PhiInv α) + c := by + rw [valueAtRisk_of_hasLaw_gaussianReal + (gaussianReal_add_const (hasLaw_gaussianReal_of_hasGaussianLaw hX) c) hα, + Real.coe_toNNReal _ (variance_nonneg X P), gaussianVaR_translation] + +/-- **Positive homogeneity of a Gaussian loss**, through the Gaussian law +`N(λ E X, λ² Var X)` of `λ X`: `VaR_α(λ X) = λ · gaussianVaR (E X) (sd X) Φ⁻¹(α)` for `λ ≥ 0`. The +scaling of `gaussianVaR_positiveHomogeneity`, read as the value-at-risk of the scaled loss. -/ +theorem valueAtRisk_const_mul_of_hasGaussianLaw (hX : HasGaussianLaw X P) (hα : α ∈ Ioo 0 1) + {l : ℝ} (hl : 0 ≤ l) : + valueAtRisk (fun ω ↦ l * X ω) P α = l * gaussianVaR P[X] √Var[X; P] (PhiInv α) := by + rw [valueAtRisk_of_hasLaw_gaussianReal + (gaussianReal_const_mul (hasLaw_gaussianReal_of_hasGaussianLaw hX) l) hα, + NNReal.coe_mul, NNReal.coe_mk, Real.sqrt_mul (sq_nonneg l), Real.sqrt_sq_eq_abs, + Real.coe_toNNReal _ (variance_nonneg X P), gaussianVaR_positiveHomogeneity _ _ _ hl] + +/-- **Translation of a Gaussian loss**, expected shortfall: `ES_α(X + c) = +gaussianCVaR (E X) (sd X) Φ⁻¹(α) α + c`, the Gaussian law of `X + c` through +`expectedShortfall_of_hasGaussianLaw` and `gaussianCVaR_translation`. -/ +theorem expectedShortfall_add_const_of_hasGaussianLaw (hX : HasGaussianLaw X P) + (hα : α ∈ Ioo 0 1) (c : ℝ) : + expectedShortfall (fun ω ↦ X ω + c) P α = + gaussianCVaR P[X] √Var[X; P] (PhiInv α) α + c := by + have := hX.isProbabilityMeasure + rw [expectedShortfall_of_hasGaussianLaw + (gaussianReal_add_const (hasLaw_gaussianReal_of_hasGaussianLaw hX) c).hasGaussianLaw hα, + variance_add_const hX.aemeasurable.aestronglyMeasurable, + integral_add hX.integrable (integrable_const c)] + simp [gaussianCVaR_translation] + +/-- **Positive homogeneity of a Gaussian loss**, expected shortfall: `ES_α(λ X) = +λ · gaussianCVaR (E X) (sd X) Φ⁻¹(α) α` for `λ ≥ 0`, the Gaussian law of `λ X` through +`expectedShortfall_of_hasGaussianLaw` and `gaussianCVaR_positiveHomogeneity`. -/ +theorem expectedShortfall_const_mul_of_hasGaussianLaw (hX : HasGaussianLaw X P) + (hα : α ∈ Ioo 0 1) {l : ℝ} (hl : 0 ≤ l) : + expectedShortfall (fun ω ↦ l * X ω) P α = + l * gaussianCVaR P[X] √Var[X; P] (PhiInv α) α := by + rw [expectedShortfall_of_hasGaussianLaw + (gaussianReal_const_mul (hasLaw_gaussianReal_of_hasGaussianLaw hX) l).hasGaussianLaw hα, + variance_const_mul, integral_const_mul, Real.sqrt_mul (sq_nonneg l), Real.sqrt_sq_eq_abs, + gaussianCVaR_positiveHomogeneity _ _ _ _ hl] + +end MathFin diff --git a/LeanPool/MathFin/Risk/CollateralizedExposureBrownian.lean b/LeanPool/MathFin/Risk/CollateralizedExposureBrownian.lean new file mode 100644 index 0000000000..679227f436 --- /dev/null +++ b/LeanPool/MathFin/Risk/CollateralizedExposureBrownian.lean @@ -0,0 +1,90 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Credit.CVA +public import LeanPool.MathFin.Probability.Gaussian.GaussianMoments + +/-! +# Collateralized exposure under a Brownian-driven process + +Collateral is the exposure process itself evaluated `Δ` earlier, `C t := V (t - Δ)`: a two-way +CSA with zero threshold and zero minimum transfer amount, posted with a lag `Δ` (the margin +period of risk). + +* `collateralizedExposure V Δ t ω = max (V t ω - V (t - Δ) ω) 0`, time indexed by `ℝ≥0` to match + `IsPreBrownianReal`. The lag `t - Δ` is `ℝ≥0` truncated subtraction, so for `Δ > t` it is `0` + and `C_t` is `V_0`; the theorem below assumes `Δ ≤ t`. +* `collateralizedExposure_brownian_gaussian`: for `V t = m + σ B t` with `B` a pre-Brownian + motion (`IsPreBrownianReal`), `0 < Δ ≤ t` and `σ > 0`, the expected collateralized exposure is + `E[(V_t - V_{t-Δ})⁺] = σ√Δ · φ(0)`. The level `m` drops out of the increment + `V_t - V_{t-Δ} = σ (B_t - B_{t-Δ})`, whose law comes from the Brownian finite-dimensional laws + (`MathFin.hasLaw_increment`); standardized to `Z ~ N(0,1)` by `hasLaw_sub_div_of_gaussianReal`, + it is `σ√Δ · Z`, and `CVA.expectedExposure_gaussian` at mean `0` gives the answer, the density + `φ(0)` scaled by the volatility of the increment. + +## Main definitions + +* `collateralizedExposure`: the exposure `max (V t − V (t − Δ)) 0` at time `t` when the + collateral is the process itself lagged by `Δ`, with `ℝ≥0` truncated subtraction in `t − Δ`. + +## Main results + +* `collateralizedExposure_brownian_gaussian`: for `V t = m + σ B t` with `B` a pre-Brownian + motion, `σ > 0` and `0 < Δ ≤ t`, `E[(V_t − V_{t−Δ})⁺] = σ√Δ · φ(0)`, with `φ(0)` the standard + Gaussian density at `0`. The level `m` drops out. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull] (collateralized exposure / CSAs). + +## Tags + +collateralized exposure, credit support annex, margin period of risk, counterparty credit risk, +Brownian exposure, CVA, MSC 91G40, MSC 60J65, JEL G32 +-/ + +@[expose] public section + +namespace MathFin.CVA + +open MeasureTheory Real ProbabilityTheory +open scoped NNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + +/-- Collateralized exposure at time `t` with lag `Δ`: `max(V_t - C_t, 0)` with the lagged +collateral `C_t := V_{t-Δ}`, the same process `Δ` earlier. -/ +noncomputable def collateralizedExposure (V : ℝ≥0 → Ω → ℝ) (Δ t : ℝ≥0) (ω : Ω) : ℝ := + max (V t ω - V (t - Δ) ω) 0 + +/-- **Collateralized exposure under a Brownian-driven process, in closed form**: for +`V_t = m + σ B_t` with `B` a pre-Brownian motion, `σ > 0` and `0 < Δ ≤ t`, +`E[(V_t - V_{t-Δ})⁺] = σ√Δ · φ(0)`; the level `m` drops out. The law of the increment comes from +`MathFin.hasLaw_increment`. -/ +theorem collateralizedExposure_brownian_gaussian [IsProbabilityMeasure P] {B : ℝ≥0 → Ω → ℝ} + (hB : IsPreBrownianReal B P) (m σ : ℝ) (hσ : 0 < σ) {Δ t : ℝ≥0} (hΔpos : 0 < Δ) + (hΔt : Δ ≤ t) : + ∫ ω, collateralizedExposure (fun t ω ↦ m + σ * B t ω) Δ t ω ∂P + = σ * √(Δ : ℝ) * gaussianPDFReal 0 1 0 := by + have hΔ : (0 : ℝ) < Δ := hΔpos + have hinc : HasLaw (fun ω ↦ B t ω - B (t - Δ) ω) (gaussianReal 0 Δ) P := by + simpa [tsub_tsub_cancel_of_le hΔt] using hasLaw_increment hB (tsub_le_self (a := t) (b := Δ)) + have hZ : HasLaw (fun ω ↦ (B t ω - B (t - Δ) ω) / √(Δ : ℝ)) (gaussianReal 0 1) P := by + simpa using hasLaw_sub_div_of_gaussianReal hinc (Real.sqrt_pos.mpr hΔ) (Real.sq_sqrt hΔ.le).symm + have hΔne : √(Δ : ℝ) ≠ 0 := (Real.sqrt_pos.mpr hΔ).ne' + have hpt (ω : Ω) : collateralizedExposure (fun t ω ↦ m + σ * B t ω) Δ t ω + = max (0 + σ * √(Δ : ℝ) * ((B t ω - B (t - Δ) ω) / √(Δ : ℝ))) 0 := by + rw [collateralizedExposure, zero_add, mul_assoc, mul_div_cancel₀ _ hΔne] + congr 1 + ring + simp_rw [hpt] + rw [expectedExposure_gaussian hZ hσ hΔ] + simp + +end MathFin.CVA diff --git a/LeanPool/MathFin/Risk/ComponentVaR.lean b/LeanPool/MathFin/Risk/ComponentVaR.lean new file mode 100644 index 0000000000..f2db01b603 --- /dev/null +++ b/LeanPool/MathFin/Risk/ComponentVaR.lean @@ -0,0 +1,191 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Portfolio.RiskParityFOC +public import LeanPool.MathFin.Risk.GaussianRiskMarkowitz + +/-! +# Component and marginal Value-at-Risk (the Euler allocation) + +For a zero-mean Gaussian portfolio loss with positions `x : ι → ℝ` and covariance kernel `σ`, the +parametric VaR is `VaR = α · √(x'Σx)` for a quantile multiplier `α` (e.g. `α = Φ⁻¹(level)`, as in +`Risk/Gaussian.lean`). Here `portfolioVaRN` is *defined* as that expression. The +Gaussian quantile identity behind it is `valueAtRisk_portfolio_gaussian_eq_portfolioVaRN`: for a +Gaussian vector `X` of risk-factor changes, `VaR_α(∑ wᵢXᵢ)` is the mean `∑ wᵢ E Xᵢ` plus +`portfolioVaRN` at the multiplier `Φ⁻¹(α)` and the covariance kernel of `X` +(`valueAtRisk_portfolio_gaussian`, `Risk/GaussianRiskMarkowitz.lean`). Since +`x ↦ √(x'Σx)` is positively homogeneous of degree 1, Euler's theorem predicts +`∑ᵢ xᵢ · ∂VaR/∂xᵢ = VaR`. Here the marginal VaR is *defined* by the textbook +closed form `α(Σx)ᵢ/√(x'Σx)`. For symmetric `σ` and positive portfolio variance these are the +partial derivatives of `portfolioVaRN`: its derivative along any direction `d` is +`∑ᵢ dᵢ · marginalVaRᵢ` (`hasDerivAt_portfolioVaRN`). With this definition the component VaR +`xᵢ · marginalVaRᵢ` is `α/√(x'Σx)` times the risk contribution `xᵢ(Σx)ᵢ` of +`Choice/Portfolio/RiskParityFOC.lean`, and the Euler identity reduces to +`sum_riskContribution_eq_variance`. + +## Main definitions + +* `portfolioVaRN`: the parametric portfolio VaR `α · √(x'Σx)`, with `x'Σx` the `portfolioVarN` + of positions `x` against the kernel `σ`. +* `marginalVaR`: the marginal VaR `α (Σx)ᵢ / √(x'Σx)`, defined as this closed form. +* `componentVaR`: the component VaR `xᵢ · marginalVaR i`. + +## Main results + +* `sum_componentVaR_eq_portfolioVaRN`: the Euler allocation `∑ᵢ CVaRᵢ = VaR`, stated for + `0 < x'Σx` (strictly positive portfolio variance). +* `hasDerivAt_portfolioVaRN`: for symmetric `σ` and `0 < x'Σx`, the derivative of `portfolioVaRN` + along any direction `d` is `∑ᵢ dᵢ · marginalVaRᵢ`. +* `valueAtRisk_portfolio_gaussian_eq_portfolioVaRN`: the VaR of a Gaussian portfolio loss is its + mean plus `portfolioVaRN` at `Φ⁻¹(α)`. +* `sum_componentVaR_eq_valueAtRisk_sub`: the component VaRs at `Φ⁻¹(α)` allocate the VaR of a + Gaussian portfolio loss in excess of its mean. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Corollary 8.43 +* [D. Tasche, *Capital allocation to business units and sub-portfolios: the Euler + principle*][Tasche2008] + +## Tags + +component VaR, marginal VaR, Euler allocation, parametric VaR, risk contribution, delta-normal VaR, +MSC 91G70, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +section Euler + +variable {ι : Type*} (s : Finset ι) (x : ι → ℝ) (σ : ι → ι → ℝ) (α : ℝ) + +/-- Parametric portfolio VaR `α · √(x'Σx)`, with `x'Σx` the N-asset portfolio variance of +`Choice/Portfolio/MarkowitzNAsset.lean`. -/ +noncomputable def portfolioVaRN : ℝ := α * Real.sqrt (portfolioVarN s x σ) + +/-- **Marginal VaR**: *defined* as the textbook closed form `α·(Σx)ᵢ/√(x'Σx)`, with +`(Σx)ᵢ = marginalVariance s σ x i`. For symmetric `σ` and positive portfolio variance it is the +partial derivative of `portfolioVaRN` in `xᵢ` (`hasDerivAt_portfolioVaRN`). -/ +noncomputable def marginalVaR (i : ι) : ℝ := + α * marginalVariance s σ x i / Real.sqrt (portfolioVarN s x σ) + +/-- **Component VaR**: `CVaRᵢ = xᵢ · marginalVaRᵢ`, i.e. `α/√(x'Σx)` times the risk contribution +`riskContribution s σ x i = xᵢ(Σx)ᵢ`. -/ +noncomputable def componentVaR (i : ι) : ℝ := x i * marginalVaR s x σ α i + +/-- **Euler allocation of VaR**: the component VaRs sum to the portfolio VaR, `∑ᵢ CVaRᵢ = VaR`, +whenever the portfolio variance is (strictly) positive. This is the identity Euler's theorem +predicts for the degree-1-homogeneous map `x ↦ α√(x'Σx)`; since `marginalVaR` is defined by its +closed form, the proof is the algebra `∑ᵢ xᵢ(Σx)ᵢ = x'Σx` (`sum_riskContribution_eq_variance`). -/ +theorem sum_componentVaR_eq_portfolioVaRN (hvar : 0 < portfolioVarN s x σ) : + ∑ i ∈ s, componentVaR s x σ α i = portfolioVaRN s x σ α := by + have hsqrt : Real.sqrt (portfolioVarN s x σ) ≠ 0 := (Real.sqrt_pos.mpr hvar).ne' + unfold componentVaR marginalVaR portfolioVaRN + have hsum : + ∑ i ∈ s, x i * (α * marginalVariance s σ x i / Real.sqrt (portfolioVarN s x σ)) = + α * (∑ i ∈ s, riskContribution s σ x i) / Real.sqrt (portfolioVarN s x σ) := by + rw [Finset.mul_sum, Finset.sum_div] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + unfold riskContribution + ring + have hsq : Real.sqrt (portfolioVarN s x σ) * Real.sqrt (portfolioVarN s x σ) = + portfolioVarN s x σ := Real.mul_self_sqrt hvar.le + rw [hsum, sum_riskContribution_eq_variance, + div_eq_iff hsqrt, mul_assoc, hsq] + +/-- **The portfolio variance along a line** `x + t d` is the quadratic +`Var(x) + t · ∑ᵢⱼ (dᵢxⱼ + xᵢdⱼ)σᵢⱼ + t² Var(d)`. -/ +lemma portfolioVarN_add_mul (d : ι → ℝ) (t : ℝ) : + portfolioVarN s (fun k ↦ x k + t * d k) σ = + portfolioVarN s x σ + t * ∑ i ∈ s, ∑ j ∈ s, (d i * x j + x i * d j) * σ i j + + t ^ 2 * portfolioVarN s d σ := by + simp only [portfolioVarN, Finset.mul_sum, ← Finset.sum_add_distrib] + exact Finset.sum_congr rfl fun i _ ↦ Finset.sum_congr rfl fun j _ ↦ by ring + +/-- For a symmetric kernel the linear coefficient of `portfolioVarN_add_mul` is twice +`∑ᵢ dᵢ (Σx)ᵢ`. -/ +lemma sum_sum_add_mul_eq_two_mul (hσ : ∀ i ∈ s, ∀ j ∈ s, σ i j = σ j i) (d : ι → ℝ) : + ∑ i ∈ s, ∑ j ∈ s, (d i * x j + x i * d j) * σ i j = + 2 * ∑ i ∈ s, d i * marginalVariance s σ x i := by + have h2 : ∑ i ∈ s, ∑ j ∈ s, x i * d j * σ i j = ∑ i ∈ s, ∑ j ∈ s, d i * x j * σ i j := by + rw [Finset.sum_comm] + exact Finset.sum_congr rfl fun i hi ↦ Finset.sum_congr rfl fun j hj ↦ by + rw [hσ j hj i hi]; ring + calc ∑ i ∈ s, ∑ j ∈ s, (d i * x j + x i * d j) * σ i j + = ∑ i ∈ s, ∑ j ∈ s, d i * x j * σ i j + ∑ i ∈ s, ∑ j ∈ s, x i * d j * σ i j := by + simp only [add_mul, Finset.sum_add_distrib] + _ = 2 * ∑ i ∈ s, ∑ j ∈ s, d i * x j * σ i j := by rw [h2, two_mul] + _ = 2 * ∑ i ∈ s, d i * marginalVariance s σ x i := by + congr 1 + exact Finset.sum_congr rfl fun i _ ↦ by + rw [marginalVariance, Finset.mul_sum] + exact Finset.sum_congr rfl fun j _ ↦ by ring + +/-- **The marginal VaRs are the partial derivatives of the parametric VaR**: for a symmetric +kernel and a positive portfolio variance, the derivative of `portfolioVaRN` at `x` along any +direction `d` is `∑ᵢ dᵢ · marginalVaRᵢ`. -/ +theorem hasDerivAt_portfolioVaRN (hσ : ∀ i ∈ s, ∀ j ∈ s, σ i j = σ j i) + (hvar : 0 < portfolioVarN s x σ) (d : ι → ℝ) : + HasDerivAt (fun t ↦ portfolioVaRN s (fun k ↦ x k + t * d k) σ α) + (∑ i ∈ s, d i * marginalVaR s x σ α i) 0 := by + set S := ∑ i ∈ s, d i * marginalVariance s σ x i with hS + have hfun : (fun t ↦ portfolioVarN s (fun k ↦ x k + t * d k) σ) = + fun t ↦ portfolioVarN s x σ + t * (2 * S) + t ^ 2 * portfolioVarN s d σ := by + funext t + rw [portfolioVarN_add_mul, sum_sum_add_mul_eq_two_mul s x σ hσ] + have hpoly : HasDerivAt (fun t ↦ portfolioVarN s (fun k ↦ x k + t * d k) σ) (2 * S) 0 := by + rw [hfun] + exact ((((hasDerivAt_id' (x := (0 : ℝ))).mul_const (2 * S)).const_add _).add + ((hasDerivAt_pow 2 (0 : ℝ)).mul_const _)).congr_deriv (by simp) + have h0 : portfolioVarN s (fun k ↦ x k + 0 * d k) σ = portfolioVarN s x σ := by simp + have hsqrt := (hpoly.sqrt (by rw [h0]; exact hvar.ne')).const_mul α + rw [h0] at hsqrt + refine hsqrt.congr_deriv ?_ + simp only [marginalVaR, hS, Finset.mul_sum, Finset.sum_div] + field_simp + +end Euler + +/-! ### Gaussian portfolio losses -/ + +section Gaussian + +open MeasureTheory ProbabilityTheory Set + +variable {ι : Type*} [Fintype ι] {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + {X : ι → Ω → ℝ} {α : ℝ} + +/-- **The parametric VaR is the VaR of a Gaussian portfolio loss above its mean**: for a +Gaussian vector `X` of risk-factor changes and `α ∈ (0, 1)`, +`VaR_α(∑ wᵢXᵢ) = ∑ wᵢ E Xᵢ + portfolioVaRN` at the multiplier `Φ⁻¹(α)` and the covariance kernel +of `X`. -/ +theorem valueAtRisk_portfolio_gaussian_eq_portfolioVaRN + (hX : HasGaussianLaw (fun ω ↦ (X · ω)) P) (w : ι → ℝ) (hα : α ∈ Ioo 0 1) : + valueAtRisk (fun ω ↦ ∑ i, w i * X i ω) P α = + ∑ i, w i * P[X i] + + portfolioVaRN Finset.univ w (fun i j ↦ cov[X i, X j; P]) (PhiInv α) := by + rw [valueAtRisk_portfolio_gaussian hX w hα, portfolioVaRN, mul_comm (PhiInv α)] + +/-- **Euler allocation of a Gaussian VaR**: for a Gaussian vector `X`, weights `w` with positive +portfolio variance and `α ∈ (0, 1)`, the component VaRs at the multiplier `Φ⁻¹(α)` sum to the VaR +of the portfolio loss in excess of its mean: `∑ᵢ CVaRᵢ = VaR_α(∑ wᵢXᵢ) − ∑ wᵢ E Xᵢ`. -/ +theorem sum_componentVaR_eq_valueAtRisk_sub + (hX : HasGaussianLaw (fun ω ↦ (X · ω)) P) (w : ι → ℝ) (hα : α ∈ Ioo 0 1) + (hvar : 0 < portfolioVarN Finset.univ w fun i j ↦ cov[X i, X j; P]) : + ∑ i, componentVaR Finset.univ w (fun i j ↦ cov[X i, X j; P]) (PhiInv α) i = + valueAtRisk (fun ω ↦ ∑ i, w i * X i ω) P α - ∑ i, w i * P[X i] := by + rw [sum_componentVaR_eq_portfolioVaRN _ _ _ _ hvar, + valueAtRisk_portfolio_gaussian_eq_portfolioVaRN hX w hα, add_sub_cancel_left] + +end Gaussian + +end MathFin diff --git a/LeanPool/MathFin/Risk/CompoundPoissonCVaR.lean b/LeanPool/MathFin/Risk/CompoundPoissonCVaR.lean new file mode 100644 index 0000000000..841aedec23 --- /dev/null +++ b/LeanPool/MathFin/Risk/CompoundPoissonCVaR.lean @@ -0,0 +1,184 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Jumps.CompoundPoissonMGF +public import LeanPool.MathFin.Risk.ExpectedShortfall + +/-! +# Expected shortfall of a compound-Poisson aggregate loss + +The aggregate loss `L = ∑_{i (Apache-2.0). That paper in +turn builds on the compositional contract-DSL of +Peyton Jones, Eber and Seward (2000) and the certified-contract work of Bahr, +Berthold and Elsman (2015) and Annenkov (2018). + +No code is copied from `lean_contracts`; every definition and proof here is +written for this library. See `docs/specs/2026-08-16-contracts-tower-design.md` +§6 for the full credit line. + +## References + +* [P. Artzner et al., *Coherent measures of risk*][ArtznerDelbaenEberHeath1999] +* [P. Bilokon, *The Contract Is Not the Model*][Bilokon2026] +* [J. C. Cox, S. A. Ross and M. Rubinstein, *Option pricing: a simplified + approach*][CoxRossRubinstein1979] +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Section 2.2; Section 2.3 +* [S. E. Shreve, *Stochastic Calculus for Finance I: The Binomial Asset Pricing Model*][ShreveSCFI], + Theorem 1.2.2 + +## Tags + +value at risk, expected shortfall, subadditivity, position loss, hedged position, +risk of a derivative book, MSC 91G70, JEL G32 +-/ + +@[expose] public section + +open MeasureTheory Set +open scoped NNReal + +namespace MathFin + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} {α : ℝ} + +namespace Contracts + +variable {ι : Type*} {D : ℝ≥0 → ℝ} {X : ι → ℝ≥0 → Ω → ℝ} + +/-- The **loss of a position** in the contract `c` bought at price `p`: along each outcome, the +price paid less the discounted payoff. -/ +noncomputable def Contract.loss (p : ℝ) (D : ℝ≥0 → ℝ) (X : ι → ℝ≥0 → Ω → ℝ) (c : Contract ι) : + Ω → ℝ := + fun ω ↦ p - c.pathPV D (scenarioAt X ω) + +variable [IsProbabilityMeasure P] + +/-- **A book's expected shortfall is at most the sum of its contracts'.** Holding `a` bought at +`p_a` and `b` bought at `p_b` loses what the two positions lose together (`Contract.pathPV_both`), +and expected shortfall is subadditive (`expectedShortfall_add_le`). -/ +theorem expectedShortfall_loss_both_le (hα : α ∈ Ioo 0 1) {a b : Contract ι} + (ha : Integrable (fun ω ↦ a.pathPV D (scenarioAt X ω)) P) + (hb : Integrable (fun ω ↦ b.pathPV D (scenarioAt X ω)) P) (pa pb : ℝ) : + expectedShortfall ((Contract.both a b).loss (pa + pb) D X) P α + ≤ expectedShortfall (a.loss pa D X) P α + expectedShortfall (b.loss pb D X) P α := by + have h : (Contract.both a b).loss (pa + pb) D X = fun ω ↦ a.loss pa D X ω + b.loss pb D X ω := + funext fun ω ↦ by simp only [Contract.loss, Contract.pathPV_both]; ring + rw [h] + exact expectedShortfall_add_le ((integrable_const pa).sub ha) ((integrable_const pb).sub hb) hα + +/-- **A position that never pays a negative amount cannot lose more than its price.** If the +discounted payoff of `c` is nonnegative on every outcome, the value-at-risk of the position bought +at `p` is at most `p`. -/ +theorem valueAtRisk_loss_le_of_nonneg (hα : α ∈ Ioo 0 1) {c : Contract ι} + (hm : AEMeasurable (fun ω ↦ c.pathPV D (scenarioAt X ω)) P) + (hc : ∀ ω, 0 ≤ c.pathPV D (scenarioAt X ω)) (p : ℝ) : + valueAtRisk (c.loss p D X) P α ≤ p := by + calc valueAtRisk (c.loss p D X) P α ≤ valueAtRisk (fun _ ↦ p) P α := + valueAtRisk_mono (aemeasurable_const.sub hm) aemeasurable_const + (Filter.Eventually.of_forall fun ω ↦ sub_le_self p (hc ω)) hα + _ = p := valueAtRisk_const p hα + +/-- **A long call's value-at-risk is at most its premium**, for a nonnegative discount factor. -/ +theorem valueAtRisk_loss_europeanCall_le (hα : α ∈ Ioo 0 1) {X : Unit → ℝ≥0 → Ω → ℝ} {K : ℝ} + {T : ℝ≥0} (hD : 0 ≤ D T) + (hm : AEMeasurable (fun ω ↦ (europeanCall K T).pathPV D (scenarioAt X ω)) P) (p : ℝ) : + valueAtRisk ((europeanCall K T).loss p D X) P α ≤ p := + valueAtRisk_loss_le_of_nonneg hα hm (fun ω ↦ by + simpa [europeanCall, europeanCallPayoff, Contract.pathPV, Contract.cashflows, Payoff.eval] + using mul_nonneg hD (le_max_right _ _)) p + +namespace Binomial + +variable {u d ρ h : ℝ} {q : ℝ≥0} (hq : q ≤ 1) + +/-- **A hedged seller carries no risk.** In the binomial tree under no-arbitrage, a seller of a +European contract who receives its value and follows the hedge of `pathPV_eq_value_add_gains` +loses `pathPV − (value + gains) = 0` on every path. So under every law `P` of the coin flips, +physical or not, the hedged position has zero value-at-risk and zero expected shortfall at every +level. -/ +theorem valueAtRisk_hedged_eq_zero (hqcrr : crrUpProb u d ρ = q) (S₀ : ℝ) {T : ℝ≥0} {N : ℕ} + (hTN : (T : ℝ) / h = N) (hna : BinomialNoArb u d ρ) (hS₀ : S₀ ≠ 0) {a : Payoff Unit} + {g : ℝ → ℝ} (hg : ∀ s : Scenario Unit, a.eval s = g (s () T)) : + ∃ H : ℕ → (ℕ → Bool) → ℝ, StronglyAdapted flipFiltration (fun n ↦ H (n + 1)) ∧ + ∀ (P : Measure (ℕ → Bool)) [IsProbabilityMeasure P], ∀ α ∈ Ioo (0 : ℝ) 1, + let L := fun ω ↦ (Contract.pay T a).pathPV (discount ρ h) (scenarioAt (assets S₀ u d h) ω) + - ((Contract.pay T a).value (coinFlipMeasure q hq) (fun t _ ↦ discount ρ h t) + (assets S₀ u d h) + + martingaleTransform H (discountedSpot S₀ u d ρ) N ω) + valueAtRisk L P α = 0 ∧ expectedShortfall L P α = 0 := by + obtain ⟨H, hH, hrep⟩ := pathPV_eq_value_add_gains hq hqcrr S₀ hTN hna hS₀ hg + refine ⟨H, hH, fun P _ α hα ↦ ?_⟩ + have hL : (fun ω ↦ (Contract.pay T a).pathPV (discount ρ h) (scenarioAt (assets S₀ u d h) ω) + - ((Contract.pay T a).value (coinFlipMeasure q hq) (fun t _ ↦ discount ρ h t) + (assets S₀ u d h) + + martingaleTransform H (discountedSpot S₀ u d ρ) N ω)) + = fun _ ↦ 0 := funext fun ω ↦ sub_eq_zero.2 (hrep ω) + simp only [hL] + exact ⟨valueAtRisk_const 0 hα, expectedShortfall_const 0 hα⟩ + +end Binomial + +end Contracts + +end MathFin diff --git a/LeanPool/MathFin/Risk/Credit/BernoulliMixture.lean b/LeanPool/MathFin/Risk/Credit/BernoulliMixture.lean new file mode 100644 index 0000000000..1b56faa47a --- /dev/null +++ b/LeanPool/MathFin/Risk/Credit/BernoulliMixture.lean @@ -0,0 +1,290 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Gaussian.NormalQuantile +public import Mathlib.Algebra.Order.Star.Real + +/-! +# Bernoulli mixture models of portfolio credit risk + +In a **Bernoulli mixture model** the default indicators of the obligors of a loan portfolio are +conditionally independent given a random default probability `Q ∈ [0, 1]`, the state of the +economy. We use the standard representation (McNeil–Frey–Embrechts 2015, §11.2): obligor `i` +defaults on the event `{Uᵢ ≤ Q}`, where the `Uᵢ` are independent and uniform on `(0, 1)` and +independent of `Q`. Given `Q = q`, each obligor defaults with probability `q`, independently of +the others. Dependence between defaults comes only from the common `Q`. + +* **Joint default probabilities are moments of the mixing variable** (QRM Exercise Book, + Ex. 11.11a). For every group `s` of obligors, `P(all of s default) = E[Q^|s|]` + (`measureReal_iInter_default_eq_integral_pow`). The proof is Fubini on the joint law + `law(Q) ⊗ Unif(0,1)^ι`: given `Q = q`, the group defaults with probability `q^|s|`. +* **Default correlation is nonnegative** (Ex. 11.4a, 11.11b). For two distinct obligors the + covariance of the default indicators is `P(Dᵢ ∩ Dⱼ) − P(Dᵢ) P(Dⱼ) = E[Q²] − E[Q]² = Var(Q)` + (`measureReal_inter_default_sub_mul`), which is never negative. So the default correlation + `ρ_Y = (π₂ − π₁²)/(π₁ − π₁²)` equals `Var(Q)/(π₁(1 − π₁))` (`defaultCorrelation_eq`). +* **The one-factor Gaussian threshold model is a Bernoulli mixture** (Ex. 11.2d, 11.9, 11.17a). + Obligor `i` defaults when its asset value `√ρ F + √(1 − ρ) εᵢ` falls below `Φ⁻¹(π)`, with `F` + and the `εᵢ` independent standard normals. That event is `{Φ(εᵢ) ≤ p(F)}`, where + `p(f) = Φ((Φ⁻¹(π) − √ρ f)/√(1 − ρ))` (`oneFactor_default_iff`). The `Φ(εᵢ)` are uniform by the + probability integral transform, so the joint default probabilities are + `πₖ = ∫ p(x)^k φ(x) dx` (`oneFactor_measureReal_iInter_default`). Each obligor defaults with + probability exactly `π`, because the asset value is again standard normal + (`oneFactor_measureReal_default`). + +## Main definitions + +* `oneFactorPD`: the conditional default probability `Φ((Φ⁻¹(π) − √ρ f) / √(1 − ρ))` of the + one-factor Gaussian threshold model at default probability `π`, asset correlation `ρ` and + factor value `f`. + +## Main results + +* `measureReal_iInter_default_eq_integral_pow`: `πₖ = E[Q^k]`. +* `measureReal_inter_default_sub_mul`: the default covariance is `Var(Q)`. +* `defaultCorrelation_eq`: `ρ_Y = Var(Q)/(π₁(1 − π₁))`, and `defaultCorrelation_nonneg`. +* `oneFactor_asset_le_iff`, `oneFactor_default_iff`: the threshold event is the mixture event. +* `oneFactor_bernoulliMixture`: the one-factor model satisfies the mixture hypotheses. +* `oneFactor_measureReal_iInter_default`: `πₖ = ∫ p(x)^k dN(0,1)(x)` in the Gaussian model. +* `oneFactor_measureReal_default`: each obligor defaults with probability `π`. +* `oneFactor_measureReal_inter_default_sub_mul`: the default covariance is `Var(p(F))`. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Section 11.2 +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 11.11(a); Ex. 11.2(c), 11.9; Ex. 11.4(a), 11.11(b); + Ex. 11.4(a), 11.9 + +## Tags + +Bernoulli mixture model, portfolio credit risk, default correlation, one-factor Gaussian model, +conditionally independent defaults, joint default probability, Vasicek model, MSC 91G40, MSC 60E05, +JEL G32, JEL G33 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set +open scoped NNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + {ι : Type*} [Fintype ι] + +/-! ### Joint default probabilities of a Bernoulli mixture -/ + +omit [Fintype ι] in +/-- **Joint default probabilities of a Bernoulli mixture are moments of the mixing variable** +(QRM Exercise Book, Ex. 11.11a). Obligor `i` defaults when `Uᵢ ≤ Q`, where the `Uᵢ` are independent +uniforms on `(0, 1)`, independent of the mixing variable `Q ∈ [0, 1]`. Then every group `s` of +obligors defaults jointly with probability `E[Q^|s|]`. -/ +theorem measureReal_iInter_default_eq_integral_pow [Finite ι] {Q : Ω → ℝ} {U : ι → Ω → ℝ} + (hQ : AEMeasurable Q P) (hQ01 : ∀ᵐ ω ∂P, Q ω ∈ Icc 0 1) + (hU : ∀ i, HasLaw (U i) (volume.restrict (Ioo 0 1)) P) (hUind : iIndepFun U P) + (hQU : Q ⟂ᵢ[P] fun ω i ↦ U i ω) (s : Finset ι) : + P.real (⋂ i ∈ s, {ω | U i ω ≤ Q ω}) = ∫ ω, Q ω ^ s.card ∂P := by + cases nonempty_fintype ι + classical + have hUv : AEMeasurable (fun ω i ↦ U i ω) P := + .of_eval fun i ↦ (hU i).aemeasurable + -- the joint law of `(Q, U)` is `law(Q) ⊗ Unif(0,1)^ι` + have hlawU : P.map (fun ω i ↦ U i ω) = Measure.pi fun _ ↦ volume.restrict (Ioo (0 : ℝ) 1) := by + rw [(iIndepFun_iff_map_fun_eq_pi_map fun i ↦ (hU i).aemeasurable).1 hUind] + exact congrArg Measure.pi (funext fun i ↦ (hU i).map_eq) + have hjoint := (indepFun_iff_map_prod_eq_prod_map_map hQ hUv).1 hQU + -- the joint default event is a preimage under `(Q, U)` + let S : Set (ℝ × (ι → ℝ)) := ⋂ i ∈ s, {p | p.2 i ≤ p.1} + have hS : MeasurableSet S := .biInter s.countable_toSet fun i _ ↦ + measurableSet_le ((measurable_pi_apply i).comp measurable_snd) measurable_fst + have hpre : ⋂ i ∈ s, {ω | U i ω ≤ Q ω} = (fun ω ↦ (Q ω, fun i ↦ U i ω)) ⁻¹' S := by + ext ω; simp [S] + -- given `Q = q ∈ [0, 1]`, the group defaults with probability `q ^ |s|` + have hsec (q : ℝ) (hq : q ∈ Icc (0 : ℝ) 1) : + (Measure.pi fun _ : ι ↦ volume.restrict (Ioo (0 : ℝ) 1)) (Prod.mk q ⁻¹' S) = + ENNReal.ofReal (q ^ s.card) := by + have hbox : Prod.mk q ⁻¹' S = univ.pi fun i ↦ if i ∈ s then Iic q else univ := by + ext v + simp only [S, mem_preimage, mem_iInter, mem_ofPred_eq, mem_univ_pi] + refine ⟨fun h i ↦ ?_, fun h i hi ↦ by simpa [hi] using h i⟩ + split_ifs with hi + exacts [h i hi, mem_univ _] + rw [hbox, Measure.pi_pi, ENNReal.ofReal_pow hq.1, ← Finset.prod_const, + ← Fintype.prod_ite_mem s fun _ ↦ ENNReal.ofReal q] + refine Finset.prod_congr rfl fun i _ ↦ ?_ + split_ifs + · exact uniformIoo_Iic hq.1 hq.2 + · exact measure_univ + have hint : Integrable (fun ω ↦ Q ω ^ s.card) P := + .of_bound (hQ.pow_const _).aestronglyMeasurable 1 <| hQ01.mono fun ω hω ↦ by + rw [Real.norm_eq_abs, abs_of_nonneg (pow_nonneg hω.1 _)] + exact pow_le_one₀ hω.1 hω.2 + rw [hpre, measureReal_def, ← Measure.map_apply_of_aemeasurable (hQ.prodMk hUv) hS, hjoint, + hlawU, Measure.prod_apply hS, + lintegral_map' (measurable_measure_prodMk_left hS).aemeasurable hQ, + lintegral_congr_ae (hQ01.mono fun ω hω ↦ hsec (Q ω) hω), + ← ofReal_integral_eq_lintegral_ofReal hint (hQ01.mono fun ω hω ↦ pow_nonneg hω.1 _), + ENNReal.toReal_ofReal (integral_nonneg_of_ae (hQ01.mono fun ω hω ↦ pow_nonneg hω.1 _))] + +omit [Fintype ι] in +/-- **The default covariance of a Bernoulli mixture is the variance of the mixing variable** +(QRM Exercise Book, Ex. 11.4a): `P(Dᵢ ∩ Dⱼ) − P(Dᵢ) P(Dⱼ) = Var(Q)` for distinct obligors. -/ +theorem measureReal_inter_default_sub_mul [Finite ι] {Q : Ω → ℝ} {U : ι → Ω → ℝ} + (hQ : AEMeasurable Q P) (hQ01 : ∀ᵐ ω ∂P, Q ω ∈ Icc 0 1) + (hU : ∀ i, HasLaw (U i) (volume.restrict (Ioo 0 1)) P) (hUind : iIndepFun U P) + (hQU : Q ⟂ᵢ[P] fun ω i ↦ U i ω) {i j : ι} (hij : i ≠ j) : + P.real ({ω | U i ω ≤ Q ω} ∩ {ω | U j ω ≤ Q ω}) - + P.real {ω | U i ω ≤ Q ω} * P.real {ω | U j ω ≤ Q ω} = Var[Q; P] := by + classical + have hπ (k : ι) : P.real {ω | U k ω ≤ Q ω} = P[Q] := by + simpa using measureReal_iInter_default_eq_integral_pow hQ hQ01 hU hUind hQU {k} + have hπ₂ : P.real ({ω | U i ω ≤ Q ω} ∩ {ω | U j ω ≤ Q ω}) = P[Q ^ 2] := by + simpa [Finset.card_pair hij, Pi.pow_apply] using + measureReal_iInter_default_eq_integral_pow hQ hQ01 hU hUind hQU {i, j} + have hQ2 : MemLp Q 2 P := .of_bound hQ.aestronglyMeasurable 1 <| hQ01.mono fun ω hω ↦ by + rw [Real.norm_eq_abs, abs_of_nonneg hω.1]; exact hω.2 + rw [hπ₂, hπ, hπ, variance_eq_sub hQ2] + ring + +omit [Fintype ι] in +/-- **Default correlation in a Bernoulli mixture** (QRM Exercise Book, Ex. 11.11b): with +`π₁ = P(Dᵢ)` and `π₂ = P(Dᵢ ∩ Dⱼ)`, the correlation `(π₂ − π₁²)/(π₁ − π₁²)` of the default +indicators equals `Var(Q) / (E[Q](1 − E[Q]))`. -/ +theorem defaultCorrelation_eq [Finite ι] {Q : Ω → ℝ} {U : ι → Ω → ℝ} + (hQ : AEMeasurable Q P) (hQ01 : ∀ᵐ ω ∂P, Q ω ∈ Icc 0 1) + (hU : ∀ i, HasLaw (U i) (volume.restrict (Ioo 0 1)) P) (hUind : iIndepFun U P) + (hQU : Q ⟂ᵢ[P] fun ω i ↦ U i ω) {i j : ι} (hij : i ≠ j) : + (P.real ({ω | U i ω ≤ Q ω} ∩ {ω | U j ω ≤ Q ω}) - P.real {ω | U i ω ≤ Q ω} ^ 2) / + (P.real {ω | U i ω ≤ Q ω} - P.real {ω | U i ω ≤ Q ω} ^ 2) = + Var[Q; P] / (P[Q] * (1 - P[Q])) := by + classical + have hπ (k : ι) : P.real {ω | U k ω ≤ Q ω} = P[Q] := by + simpa using measureReal_iInter_default_eq_integral_pow hQ hQ01 hU hUind hQU {k} + have hcov := measureReal_inter_default_sub_mul hQ hQ01 hU hUind hQU hij + rw [hπ j, ← hπ i, ← sq] at hcov + rw [hcov, hπ i] + ring + +omit [Fintype ι] in +/-- **Default correlation in a Bernoulli mixture is nonnegative** (QRM Exercise Book, Ex. 11.4a): +the covariance of two default indicators is a variance. -/ +theorem defaultCorrelation_nonneg [Finite ι] {Q : Ω → ℝ} {U : ι → Ω → ℝ} + (hQ : AEMeasurable Q P) (hQ01 : ∀ᵐ ω ∂P, Q ω ∈ Icc 0 1) + (hU : ∀ i, HasLaw (U i) (volume.restrict (Ioo 0 1)) P) (hUind : iIndepFun U P) + (hQU : Q ⟂ᵢ[P] fun ω i ↦ U i ω) {i j : ι} (hij : i ≠ j) : + P.real {ω | U i ω ≤ Q ω} * P.real {ω | U j ω ≤ Q ω} ≤ + P.real ({ω | U i ω ≤ Q ω} ∩ {ω | U j ω ≤ Q ω}) := by + have := measureReal_inter_default_sub_mul hQ hQ01 hU hUind hQU hij + linarith [variance_nonneg Q P] + +/-! ### The one-factor Gaussian threshold model -/ + +/-- The **conditional default probability** of the one-factor Gaussian threshold model with +default probability `π` and asset correlation `ρ`, given the systematic factor `F = f`: +`p(f) = Φ((Φ⁻¹(π) − √ρ f)/√(1 − ρ))`. -/ +noncomputable def oneFactorPD (π ρ f : ℝ) : ℝ := + Phi ((PhiInv π - √ρ * f) / √(1 - ρ)) + +lemma measurable_oneFactorPD (π ρ : ℝ) : Measurable (oneFactorPD π ρ) := + continuous_Phi.measurable.comp (by fun_prop) + +/-- The asset value `√ρ f + √(1 − ρ) e` falls below the threshold `Φ⁻¹(π)` exactly when the +idiosyncratic term `e` falls below the factor-dependent level `(Φ⁻¹(π) − √ρ f)/√(1 − ρ)`. -/ +lemma oneFactor_asset_le_iff {π ρ : ℝ} (hρ : ρ < 1) (f e : ℝ) : + √ρ * f + √(1 - ρ) * e ≤ PhiInv π ↔ e ≤ (PhiInv π - √ρ * f) / √(1 - ρ) := by + rw [le_div_iff₀ (Real.sqrt_pos.2 (sub_pos.2 hρ))] + constructor <;> intro <;> linarith + +/-- **The threshold event is a mixture event.** The asset value `√ρ f + √(1 − ρ) e` falls below +the threshold `Φ⁻¹(π)` exactly when `Φ(e) ≤ p(f)`. -/ +theorem oneFactor_default_iff {π ρ : ℝ} (hρ : ρ < 1) (f e : ℝ) : + √ρ * f + √(1 - ρ) * e ≤ PhiInv π ↔ Phi e ≤ oneFactorPD π ρ f := by + rw [oneFactor_asset_le_iff hρ, oneFactorPD, strictMono_Phi.le_iff_le] + +omit [IsProbabilityMeasure P] [Fintype ι] in +/-- **The one-factor Gaussian threshold model is a Bernoulli mixture.** With `F` and the `εᵢ` +independent standard normals, the mixing variable `Q = p(F)` and the variables `Uᵢ = Φ(εᵢ)` +satisfy the hypotheses of the mixture theorems: `Q ∈ [0, 1]`, the `Uᵢ` are independent uniforms +on `(0, 1)` (the probability integral transform), and `Q` is independent of them. The threshold +events are the mixture events `{Uᵢ ≤ Q}` (`oneFactor_default_iff`). -/ +theorem oneFactor_bernoulliMixture {π ρ : ℝ} {F : Ω → ℝ} {ε : ι → Ω → ℝ} + (hF : HasLaw F (gaussianReal 0 1) P) (hε : ∀ i, HasLaw (ε i) (gaussianReal 0 1) P) + (hεind : iIndepFun ε P) (hFε : F ⟂ᵢ[P] fun ω i ↦ ε i ω) : + AEMeasurable (fun ω ↦ oneFactorPD π ρ (F ω)) P ∧ + (∀ᵐ ω ∂P, oneFactorPD π ρ (F ω) ∈ Icc 0 1) ∧ + (∀ i, HasLaw (fun ω ↦ Phi (ε i ω)) (volume.restrict (Ioo 0 1)) P) ∧ + iIndepFun (fun i ω ↦ Phi (ε i ω)) P ∧ + (fun ω ↦ oneFactorPD π ρ (F ω)) ⟂ᵢ[P] fun ω i ↦ Phi (ε i ω) := by + have hPhi : Measurable Phi := continuous_Phi.measurable + refine ⟨(measurable_oneFactorPD π ρ).comp_aemeasurable hF.aemeasurable, + ae_of_all _ fun ω ↦ Ioo_subset_Icc_self (Phi_mem_Ioo _), fun i ↦ ?_, + hεind.comp (fun _ ↦ Phi) fun _ ↦ hPhi, + hFε.comp (measurable_oneFactorPD π ρ) + (.of_eval fun i ↦ hPhi.comp (measurable_pi_apply i))⟩ + have h := hasLaw_cdf (hε i) (by rw [cdf_gaussianReal_zero_one]; exact continuous_Phi) + simpa only [cdf_gaussianReal_zero_one] using h + +omit [Fintype ι] in +/-- **Joint default probabilities in the one-factor Gaussian threshold model** (QRM Exercise Book, +Ex. 11.9). With `F` and the `εᵢ` independent standard normals, every group `s` of obligors +defaults jointly with probability `∫ p(x)^|s| dN(0,1)(x)`: the model is a Bernoulli mixture +(`oneFactor_bernoulliMixture`), so this is `measureReal_iInter_default_eq_integral_pow`. -/ +theorem oneFactor_measureReal_iInter_default [Finite ι] {π ρ : ℝ} {F : Ω → ℝ} {ε : ι → Ω → ℝ} + (hF : HasLaw F (gaussianReal 0 1) P) (hε : ∀ i, HasLaw (ε i) (gaussianReal 0 1) P) + (hεind : iIndepFun ε P) (hFε : F ⟂ᵢ[P] fun ω i ↦ ε i ω) (hρ : ρ < 1) (s : Finset ι) : + P.real (⋂ i ∈ s, {ω | √ρ * F ω + √(1 - ρ) * ε i ω ≤ PhiInv π}) = + ∫ x, oneFactorPD π ρ x ^ s.card ∂gaussianReal 0 1 := by + obtain ⟨hQ, hQ01, hU, hUind, hQU⟩ := oneFactor_bernoulliMixture (π := π) (ρ := ρ) hF hε hεind hFε + simp_rw [oneFactor_default_iff hρ] + rw [measureReal_iInter_default_eq_integral_pow hQ hQ01 hU hUind hQU s, + ← hF.integral_comp (((measurable_oneFactorPD π ρ).pow_const _).aestronglyMeasurable)] + rfl + +omit [IsProbabilityMeasure P] in +/-- **Each obligor defaults with probability `π`** in the one-factor Gaussian threshold model: the +asset value `√ρ F + √(1 − ρ) ε` of independent standard normals is again standard normal, and it +falls below `Φ⁻¹(π)` with probability `Φ(Φ⁻¹(π)) = π`. -/ +theorem oneFactor_measureReal_default {π ρ : ℝ} {F e : Ω → ℝ} + (hF : HasLaw F (gaussianReal 0 1) P) (he : HasLaw e (gaussianReal 0 1) P) (hFe : F ⟂ᵢ[P] e) + (hπ : π ∈ Ioo 0 1) (hρ0 : 0 ≤ ρ) (hρ1 : ρ ≤ 1) : + P.real {ω | √ρ * F ω + √(1 - ρ) * e ω ≤ PhiInv π} = π := by + have hsum := gaussianReal_add_gaussianReal_of_indepFun + (hFe.comp (measurable_const_mul √ρ) (measurable_const_mul √(1 - ρ))) + (gaussianReal_const_mul hF √ρ) (gaussianReal_const_mul he √(1 - ρ)) + have hvar : (.mk (√ρ ^ 2) (sq_nonneg _) * 1 + .mk (√(1 - ρ) ^ 2) (sq_nonneg _) * 1 : ℝ≥0) + = 1 := by + apply NNReal.coe_injective + simp [Real.sq_sqrt hρ0, Real.sq_sqrt (sub_nonneg.2 hρ1)] + rw [mul_zero, mul_zero, add_zero, hvar] at hsum + have hlaw : HasLaw (fun ω ↦ √ρ * F ω + √(1 - ρ) * e ω) (gaussianReal 0 1) P := + ⟨(hF.aemeasurable.const_mul _).add (he.aemeasurable.const_mul _), by rw [← hsum]; rfl⟩ + rw [hlaw.measureReal_eq (p := (· ≤ PhiInv π)) measurableSet_Iic] + change (gaussianReal 0 1).real (Iic (PhiInv π)) = π + rw [← cdf_eq_real, cdf_gaussianReal_zero_one, Phi_PhiInv hπ] + +omit [Fintype ι] in +/-- **The default covariance in the one-factor Gaussian threshold model is a variance** +(QRM Exercise Book, Ex. 11.4a in the Gaussian model). For distinct obligors, +`P(Dᵢ ∩ Dⱼ) − P(Dᵢ) P(Dⱼ) = Var(p(F))`, the variance of the conditional default probability: the +model is a Bernoulli mixture (`oneFactor_bernoulliMixture`), so this is +`measureReal_inter_default_sub_mul`. -/ +theorem oneFactor_measureReal_inter_default_sub_mul [Finite ι] {π ρ : ℝ} {F : Ω → ℝ} + {ε : ι → Ω → ℝ} (hF : HasLaw F (gaussianReal 0 1) P) + (hε : ∀ i, HasLaw (ε i) (gaussianReal 0 1) P) (hεind : iIndepFun ε P) + (hFε : F ⟂ᵢ[P] fun ω i ↦ ε i ω) (hρ : ρ < 1) {i j : ι} (hij : i ≠ j) : + P.real ({ω | √ρ * F ω + √(1 - ρ) * ε i ω ≤ PhiInv π} ∩ + {ω | √ρ * F ω + √(1 - ρ) * ε j ω ≤ PhiInv π}) - + P.real {ω | √ρ * F ω + √(1 - ρ) * ε i ω ≤ PhiInv π} * + P.real {ω | √ρ * F ω + √(1 - ρ) * ε j ω ≤ PhiInv π} = + Var[fun ω ↦ oneFactorPD π ρ (F ω); P] := by + obtain ⟨hQ, hQ01, hU, hUind, hQU⟩ := oneFactor_bernoulliMixture (π := π) (ρ := ρ) hF hε hεind hFε + simp_rw [oneFactor_default_iff hρ] + exact measureReal_inter_default_sub_mul hQ hQ01 hU hUind hQU hij + +end MathFin diff --git a/LeanPool/MathFin/Risk/Credit/CreditMetrics.lean b/LeanPool/MathFin/Risk/Credit/CreditMetrics.lean new file mode 100644 index 0000000000..fd12391513 --- /dev/null +++ b/LeanPool/MathFin/Risk/Credit/CreditMetrics.lean @@ -0,0 +1,305 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Gaussian.BivariateNormalCDF +public import LeanPool.MathFin.Probability.Dependence.HoeffdingCovariance +public import Mathlib.LinearAlgebra.Matrix.Stochastic + +/-! +# CreditMetrics rating transitions + +In the CreditMetrics methodology (J.P. Morgan, *CreditMetrics — Technical Document*, 1997, ch. 6) +an obligor's credit rating moves between finitely many states `ι` (AAA, AA, …, CCC, Default) once +per period, with migration probabilities given by a row-stochastic **transition matrix** `P`: the +entry `P i j` is the probability of moving from rating `i` to rating `j`. Mathlib's +`Matrix.rowStochastic ℝ ι` is exactly this object, and it is a submonoid of `Matrix ι ι ℝ`. + +* **Multi-period migration.** The `k`-period transition matrix is `P ^ k`, again row-stochastic: + this is `Submonoid.pow_mem` for Mathlib's submonoid. +* **Default is absorbing.** If no obligor leaves the Default state `d` (row `d` of `P` is the + indicator of `d`), the probability `(P ^ k) i d` of being in default after `k` periods is + monotone in `k` (`monotone_pow_apply_absorbing`). +* **Gaussian threshold migration.** Row `i` of the CreditMetrics matrix is generated by a + latent standard normal return `Z`: with thresholds `-∞ = z 0 ≤ z 1 ≤ ⋯ ≤ z m = +∞`, the obligor + lands in bucket `j` iff `z j < Z ≤ z (j + 1)` (`ratingBucket`). The buckets partition `ℝ` + (`iUnion_ratingBucket`, `pairwise_disjoint_ratingBucket`), so their probabilities under any + probability law sum to one, and a matrix built row by row this way is row-stochastic + (`thresholdMatrix_mem_rowStochastic`); the CreditMetrics case is the law `N(0, 1)`, + `thresholdMatrix_mem_rowStochastic (gaussianReal 0 1)`. +* **Calibration.** Conversely, every transition matrix arises this way: with the thresholds + `Φ⁻¹` of the cumulative row sums `∑_{k < j} P i k` (`gaussianThresholds`; `-∞` and `+∞` at the + ends), standard normal threshold migration reproduces `P` exactly + (`thresholdMatrix_gaussianThresholds`). +* **Two obligors.** When the latent returns of two obligors are standard bivariate normal with + asset correlation `r` (`bivariateNormalLaw r`), both land in the lowest rating bucket (Default, + in the threshold ordering) with probability `N₂(Φ⁻¹(P i 0), Φ⁻¹(P k 0); r)` + (`measureReal_default_prod_gaussianThresholds`), and the covariance of their default indicators + is `N₂(Φ⁻¹(P i 0), Φ⁻¹(P k 0); r) − P i 0 · P k 0` + (`covariance_indicator_default_gaussianThresholds`, by `covariance_indicator_one`). Joint + migration to buckets other than Default is not stated. + +## Main definitions + +* `ratingBucket`: the set `{x | z j < x ≤ z (j + 1)}` of latent returns that send the obligor to + rating `j`, for thresholds `z`. +* `thresholdMatrix`: the transition matrix `μ(z i j < Z ≤ z i (j + 1))` generated by row-wise + thresholds `z i` and a latent-return law `μ`. +* `gaussianThreshold`: `⊥` for `c ≤ 0`, `⊤` for `c ≥ 1` and `Φ⁻¹(c)` in between. +* `cumulativeRow`: the cumulative probability `∑_{k < j} P i k` of the ratings below `j` in row + `i`. +* `gaussianThresholds`: the thresholds `Φ⁻¹(∑_{k < j} P i k)` calibrated to a transition matrix + `P`. + +## Main results + +* `monotone_pow_apply_absorbing`: for a row-stochastic matrix with an absorbing state `d`, the + cumulative default probability `(P ^ k) i d` is nondecreasing in `k`. +* `thresholdMatrix_mem_rowStochastic`: for monotone thresholds running from `⊥` to `⊤` and a + probability latent law, threshold migration gives a transition matrix. +* `thresholdMatrix_gaussianThresholds`: for a row-stochastic `P`, the calibrated thresholds + reproduce the matrix. +* `measureReal_default_prod_gaussianThresholds`, `covariance_indicator_default_gaussianThresholds`: + joint default and default covariance of two obligors with correlated returns. + +## References + +* [J.P. Morgan, *CreditMetrics Technical Document*][CreditMetrics1997], ch. 6; ch. 8 + +## Tags + +CreditMetrics, rating transitions, migration matrix, transition matrix, absorbing default, +Gaussian threshold model, asset correlation, MSC 91G40, MSC 60J10, JEL G24, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open Matrix MeasureTheory ProbabilityTheory Set + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +/-! ### Multi-period transitions and the absorbing default state -/ + +/-- If the state `d` (Default) is absorbing for the transition matrix `P`, the probability +`(P ^ k) i d` of having defaulted within `k` periods, starting from rating `i`, is monotone +in `k`. -/ +theorem monotone_pow_apply_absorbing {P : Matrix ι ι ℝ} (hP : P ∈ rowStochastic ℝ ι) {d : ι} + (hd : P d d = 1) (i : ι) : Monotone fun k : ℕ ↦ (P ^ k) i d := by + refine monotone_nat_of_le_succ fun k ↦ ?_ + have hk : P ^ k ∈ rowStochastic ℝ ι := Submonoid.pow_mem _ hP k + rw [pow_succ, Matrix.mul_apply, ← Finset.add_sum_erase _ _ (Finset.mem_univ d), hd, mul_one] + exact le_add_of_nonneg_right <| Finset.sum_nonneg fun j _ ↦ + mul_nonneg (nonneg_of_mem_rowStochastic hk) (nonneg_of_mem_rowStochastic hP) + +/-! ### Threshold migration -/ + +variable {m : ℕ} + +/-- The bucket `{x | z j < x ≤ z (j + 1)}` of latent returns that send the obligor to rating `j`, +for thresholds `z : Fin (m + 1) → EReal`. -/ +def ratingBucket (z : Fin (m + 1) → EReal) (j : Fin m) : Set ℝ := + {x | z j.castSucc < x ∧ x ≤ z j.succ} + +lemma measurableSet_ratingBucket (z : Fin (m + 1) → EReal) (j : Fin m) : + MeasurableSet (ratingBucket z j) := + (measurableSet_lt measurable_const measurable_coe_real_ereal).inter + (measurableSet_le measurable_coe_real_ereal measurable_const) + +/-- Buckets of monotone thresholds are pairwise disjoint. -/ +lemma pairwise_disjoint_ratingBucket {z : Fin (m + 1) → EReal} (hz : Monotone z) : + Pairwise fun j k ↦ Disjoint (ratingBucket z j) (ratingBucket z k) := by + have key (j k : Fin m) (hjk : j < k) : Disjoint (ratingBucket z j) (ratingBucket z k) := + Set.disjoint_left.2 fun x hj hk ↦ + (hj.2.trans (hz (Fin.succ_le_castSucc_iff.2 hjk))).not_gt hk.1 + exact fun j k hjk ↦ hjk.lt_or_gt.elim (key j k) fun h ↦ (key k j h).symm + +/-- With `z 0 = ⊥` and `z (last m) = ⊤`, the buckets cover `ℝ`. -/ +lemma iUnion_ratingBucket {z : Fin (m + 1) → EReal} (h0 : z 0 = ⊥) (hm : z (Fin.last m) = ⊤) : + ⋃ j, ratingBucket z j = univ := by + refine eq_univ_of_forall fun x ↦ mem_iUnion.2 ?_ + -- The first threshold at or above `x` closes the bucket containing `x`. + set s := Finset.univ.filter fun k : Fin (m + 1) ↦ x ≤ z k + have hs : s.Nonempty := ⟨Fin.last m, by simp [s, hm]⟩ + set k := s.min' hs + have hk : x ≤ z k := (Finset.mem_filter.1 (s.min'_mem hs)).2 + have hk0 : k ≠ 0 := fun h ↦ by simp [h, h0] at hk + obtain ⟨j, hj⟩ := Fin.exists_succ_eq.2 hk0 + refine ⟨j, not_le.1 fun hle ↦ ?_, hj ▸ hk⟩ + have : k ≤ j.castSucc := s.min'_le _ (by simp [s, hle]) + exact (Fin.castSucc_lt_succ (i := j)).not_ge (hj ▸ this) + +/-- For thresholds `-∞ = z 0 ≤ ⋯ ≤ z m = +∞` and any probability law `μ` of the latent return, +the bucket probabilities sum to one. -/ +theorem sum_measureReal_ratingBucket (μ : Measure ℝ) [IsProbabilityMeasure μ] + {z : Fin (m + 1) → EReal} (hz : Monotone z) (h0 : z 0 = ⊥) (hm : z (Fin.last m) = ⊤) : + ∑ j, μ.real (ratingBucket z j) = 1 := by + rw [← measureReal_iUnion_fintype (pairwise_disjoint_ratingBucket hz) + (measurableSet_ratingBucket z), iUnion_ratingBucket h0 hm, probReal_univ] + +/-- The transition matrix generated by row-wise thresholds `z i` and a latent-return law `μ`: +`thresholdMatrix μ z i j = μ(z i j < Z ≤ z i (j + 1))`. -/ +noncomputable def thresholdMatrix (μ : Measure ℝ) (z : Fin m → Fin (m + 1) → EReal) : + Matrix (Fin m) (Fin m) ℝ := + of fun i j ↦ μ.real (ratingBucket (z i) j) + +/-- Threshold migration produces a valid transition matrix. -/ +theorem thresholdMatrix_mem_rowStochastic (μ : Measure ℝ) [IsProbabilityMeasure μ] + {z : Fin m → Fin (m + 1) → EReal} (hz : ∀ i, Monotone (z i)) (h0 : ∀ i, z i 0 = ⊥) + (hm : ∀ i, z i (Fin.last m) = ⊤) : thresholdMatrix μ z ∈ rowStochastic ℝ (Fin m) := + mem_rowStochastic_iff_sum.2 + ⟨fun _ _ ↦ measureReal_nonneg, fun i ↦ sum_measureReal_ratingBucket μ (hz i) (h0 i) (hm i)⟩ + +/-! ### Calibration of the thresholds to a transition matrix -/ + +/-- The standard normal threshold below which a latent return falls with probability `c`: `⊥` for +`c ≤ 0`, `⊤` for `c ≥ 1`, and `Φ⁻¹(c)` in between. -/ +noncomputable def gaussianThreshold (c : ℝ) : EReal := + if c ≤ 0 then ⊥ else if 1 ≤ c then ⊤ else (PhiInv c : EReal) + +lemma gaussianThreshold_zero : gaussianThreshold 0 = ⊥ := ite_eq_left le_rfl + +lemma gaussianThreshold_of_mem_Ioo {c : ℝ} (hc : c ∈ Ioo 0 1) : + gaussianThreshold c = (PhiInv c : EReal) := by + rw [gaussianThreshold, ite_eq_right (not_le.2 hc.1), ite_eq_right (not_le.2 hc.2)] + +lemma gaussianThreshold_mono {c d : ℝ} (hcd : c ≤ d) : + gaussianThreshold c ≤ gaussianThreshold d := by + by_cases hc0 : c ≤ 0 + · rw [gaussianThreshold, ite_eq_left hc0] + exact bot_le + by_cases hd1 : 1 ≤ d + · have hd0 : ¬d ≤ 0 := not_le.2 (by linarith [not_le.1 hc0]) + simp only [gaussianThreshold, ite_eq_left hd1, ite_eq_right hd0] + exact le_top + have hc1 : ¬1 ≤ c := fun h ↦ hd1 (h.trans hcd) + have hd0 : ¬d ≤ 0 := fun h ↦ hc0 (hcd.trans h) + simp only [gaussianThreshold, ite_eq_right hc0, ite_eq_right hc1, ite_eq_right hd0, + ite_eq_right hd1, EReal.coe_le_coe_iff] + exact strictMonoOn_PhiInv.monotoneOn ⟨not_le.1 hc0, not_le.1 hc1⟩ ⟨not_le.1 hd0, not_le.1 hd1⟩ hcd + +/-- A standard normal return falls below the threshold of `c ∈ [0, 1]` with probability `c`. -/ +lemma measureReal_coe_le_gaussianThreshold {c : ℝ} (hc : c ∈ Icc 0 1) : + (gaussianReal 0 1).real {x : ℝ | (x : EReal) ≤ gaussianThreshold c} = c := by + unfold gaussianThreshold + split_ifs with h0 h1 + · simp [le_antisymm h0 hc.1] + · simp [le_antisymm hc.2 h1] + · simp only [EReal.coe_le_coe_iff] + rw [show {x : ℝ | x ≤ PhiInv c} = Iic (PhiInv c) from rfl, ← cdf_eq_real, + cdf_gaussianReal_zero_one, Phi_PhiInv ⟨not_le.1 h0, not_le.1 h1⟩] + +/-- The standard normal law puts mass `d − c` between the thresholds of `c ≤ d` in `[0, 1]`. -/ +lemma measureReal_gaussianThreshold_lt_le {c d : ℝ} (hc : c ∈ Icc 0 1) (hd : d ∈ Icc 0 1) + (hcd : c ≤ d) : + (gaussianReal 0 1).real + {x : ℝ | gaussianThreshold c < (x : EReal) ∧ (x : EReal) ≤ gaussianThreshold d} = + d - c := by + have hset : {x : ℝ | gaussianThreshold c < (x : EReal) ∧ (x : EReal) ≤ gaussianThreshold d} = + {x : ℝ | (x : EReal) ≤ gaussianThreshold d} \ + {x : ℝ | (x : EReal) ≤ gaussianThreshold c} := by + ext x + simp only [mem_ofPred_eq, mem_sdiff, not_le] + exact and_comm + have hsub : {x : ℝ | (x : EReal) ≤ gaussianThreshold c} ⊆ + {x : ℝ | (x : EReal) ≤ gaussianThreshold d} := + fun _ hx ↦ le_trans hx (gaussianThreshold_mono hcd) + rw [hset, measureReal_sdiff hsub (measurableSet_le measurable_coe_real_ereal measurable_const), + measureReal_coe_le_gaussianThreshold hd, measureReal_coe_le_gaussianThreshold hc] + +/-- The cumulative probability `∑_{k < j} P i k` of the ratings below `j` in row `i`. -/ +noncomputable def cumulativeRow (P : Matrix (Fin m) (Fin m) ℝ) (i : Fin m) (j : Fin (m + 1)) : ℝ := + ∑ k ∈ Finset.univ.filter (fun k : Fin m ↦ k.castSucc < j), P i k + +lemma cumulativeRow_zero (P : Matrix (Fin m) (Fin m) ℝ) (i : Fin m) : cumulativeRow P i 0 = 0 := by + simp [cumulativeRow] + +lemma cumulativeRow_succ (P : Matrix (Fin m) (Fin m) ℝ) (i j : Fin m) : + cumulativeRow P i j.succ = cumulativeRow P i j.castSucc + P i j := by + have h : Finset.univ.filter (fun k : Fin m ↦ k.castSucc < j.succ) = + insert j (Finset.univ.filter fun k : Fin m ↦ k.castSucc < j.castSucc) := by + ext k + simp [Fin.castSucc_lt_succ_iff, Fin.castSucc_lt_castSucc_iff, le_iff_eq_or_lt] + rw [cumulativeRow, h, Finset.sum_insert (by simp)] + exact add_comm _ _ + +lemma cumulativeRow_mem_Icc {P : Matrix (Fin m) (Fin m) ℝ} (hP : P ∈ rowStochastic ℝ (Fin m)) + (i : Fin m) (j : Fin (m + 1)) : cumulativeRow P i j ∈ Icc 0 1 := by + refine ⟨Finset.sum_nonneg fun k _ ↦ nonneg_of_mem_rowStochastic hP, ?_⟩ + calc cumulativeRow P i j ≤ ∑ k, P i k := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + fun k _ _ ↦ nonneg_of_mem_rowStochastic hP + _ = 1 := (mem_rowStochastic_iff_sum.1 hP).2 i + +/-- The **CreditMetrics thresholds** of a transition matrix: in row `i`, the threshold below +rating `j` is `Φ⁻¹` of the cumulative probability `∑_{k < j} P i k` (`-∞` and `+∞` at the ends). -/ +noncomputable def gaussianThresholds (P : Matrix (Fin m) (Fin m) ℝ) (i : Fin m) (j : Fin (m + 1)) : + EReal := + gaussianThreshold (cumulativeRow P i j) + +/-- **Threshold calibration recovers the transition matrix** (CreditMetrics): for a row-stochastic +`P`, standard normal threshold migration with the thresholds `gaussianThresholds P` (`Φ⁻¹` of the +cumulative row sums) has transition matrix exactly `P`. -/ +theorem thresholdMatrix_gaussianThresholds {P : Matrix (Fin m) (Fin m) ℝ} + (hP : P ∈ rowStochastic ℝ (Fin m)) : + thresholdMatrix (gaussianReal 0 1) (gaussianThresholds P) = P := by + ext i j + have hle : cumulativeRow P i j.castSucc ≤ cumulativeRow P i j.succ := by + rw [cumulativeRow_succ] + linarith [nonneg_of_mem_rowStochastic hP (i := i) (j := j)] + simp only [thresholdMatrix, of_apply, ratingBucket, gaussianThresholds] + rw [measureReal_gaussianThreshold_lt_le (cumulativeRow_mem_Icc hP i _) + (cumulativeRow_mem_Icc hP i _) hle, cumulativeRow_succ] + ring + +/-! ### Two obligors with correlated returns -/ + +/-- The lowest rating bucket of the calibrated thresholds is `(-∞, Φ⁻¹(P i 0)]`. -/ +lemma ratingBucket_gaussianThresholds_zero {P : Matrix (Fin (m + 1)) (Fin (m + 1)) ℝ} + {i : Fin (m + 1)} (hpd : P i 0 ∈ Ioo 0 1) : + ratingBucket (gaussianThresholds P i) 0 = Iic (PhiInv (P i 0)) := by + have h1 : cumulativeRow P i (0 : Fin (m + 1)).succ = P i 0 := by + rw [cumulativeRow_succ, Fin.castSucc_zero, cumulativeRow_zero, zero_add] + ext x + simp only [ratingBucket, gaussianThresholds, Fin.castSucc_zero, cumulativeRow_zero, h1, + gaussianThreshold_zero, gaussianThreshold_of_mem_Ioo hpd, mem_ofPred_eq, mem_Iic, + EReal.bot_lt_coe, true_and, EReal.coe_le_coe_iff] + +/-- **Joint default of two obligors** (CreditMetrics, correlated migration). Two obligors in +ratings `i` and `k` migrate by the calibrated thresholds of `P`, and their latent returns are +standard bivariate normal with asset correlation `r` (`bivariateNormalLaw r`). With default +probabilities `P i 0, P k 0 ∈ (0, 1)` (the lowest bucket), both default with probability +`N₂(Φ⁻¹(P i 0), Φ⁻¹(P k 0); r)`. -/ +theorem measureReal_default_prod_gaussianThresholds {P : Matrix (Fin (m + 1)) (Fin (m + 1)) ℝ} + {i k : Fin (m + 1)} (hi : P i 0 ∈ Ioo 0 1) (hk : P k 0 ∈ Ioo 0 1) (r : ℝ) : + (bivariateNormalLaw r).real + (ratingBucket (gaussianThresholds P i) 0 ×ˢ ratingBucket (gaussianThresholds P k) 0) = + bivariateNormalCDF (PhiInv (P i 0)) (PhiInv (P k 0)) r := by + rw [ratingBucket_gaussianThresholds_zero hi, ratingBucket_gaussianThresholds_zero hk, + bivariateNormalCDF_eq_law] + +/-- **Default covariance of two obligors** (CreditMetrics): under the hypotheses of +`measureReal_default_prod_gaussianThresholds` with `r ∈ [−1, 1]`, the covariance of the two default +indicators is `N₂(Φ⁻¹(P i 0), Φ⁻¹(P k 0); r) − P i 0 · P k 0`; each obligor defaults with +probability `P i 0` (resp. `P k 0`) because each margin of the pair is standard normal. -/ +theorem covariance_indicator_default_gaussianThresholds + {P : Matrix (Fin (m + 1)) (Fin (m + 1)) ℝ} {i k : Fin (m + 1)} (hi : P i 0 ∈ Ioo 0 1) + (hk : P k 0 ∈ Ioo 0 1) {r : ℝ} (hr : r ^ 2 ≤ 1) : + cov[(Prod.fst ⁻¹' ratingBucket (gaussianThresholds P i) 0).indicator 1, + (Prod.snd ⁻¹' ratingBucket (gaussianThresholds P k) 0).indicator 1; bivariateNormalLaw r] = + bivariateNormalCDF (PhiInv (P i 0)) (PhiInv (P k 0)) r - P i 0 * P k 0 := by + rw [ratingBucket_gaussianThresholds_zero hi, ratingBucket_gaussianThresholds_zero hk, + covariance_indicator_one (measurableSet_Iic.preimage measurable_fst) + (measurableSet_Iic.preimage measurable_snd), + ← map_measureReal_apply measurable_fst measurableSet_Iic, + ← map_measureReal_apply measurable_snd measurableSet_Iic, map_fst_bivariateNormalLaw hr, + map_snd_bivariateNormalLaw, ← cdf_eq_real, ← cdf_eq_real, cdf_gaussianReal_zero_one, + Phi_PhiInv hi, Phi_PhiInv hk, bivariateNormalCDF_eq_law, Set.prod_eq] + +end MathFin diff --git a/LeanPool/MathFin/Risk/Credit/CreditRiskPlus.lean b/LeanPool/MathFin/Risk/Credit/CreditRiskPlus.lean new file mode 100644 index 0000000000..5581cf776d --- /dev/null +++ b/LeanPool/MathFin/Risk/Credit/CreditRiskPlus.lean @@ -0,0 +1,73 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Laws.GammaPoissonMixturePgf +public import LeanPool.MathFin.Probability.Jumps.CompoundPoissonMGF + +/-! +# The CreditRisk+ sector loss MGF + +In CreditRisk+ (Credit Suisse First Boston, *CreditRisk+: A Credit Risk Management Framework*, +1997) the number of defaults in a sector is Poisson with a random intensity `Λ ∼ Gamma(a, r)`, +and each default causes a loss drawn independently from a common severity law. The sector loss +`L = ∑_{i < N} Xᵢ` is then a compound Poisson sum whose Poisson intensity is mixed against the +Gamma law. + +This file joins the two layers the library already has. The MGF of the `n`-loss sum is +`M_X(t)ⁿ` (`mgf_range_sum_of_iid`, `Probability/Jumps/CompoundPoissonMGF.lean`), so the mixture is +the Poisson–Gamma sector pgf (`integral_integral_pow_poissonMeasure_gammaMeasure`, +`Probability/Laws/GammaPoissonMixturePgf.lean`) evaluated at `z = M_X(t)`. For `M_X(t) < r + 1`, + + `∫ λ, (∫ n, M_{∑_{i 0` and + `M_X(t) < r + 1`, the compound-Poisson MGF `∫ n, M_{∑_{i 0`): if `M_X(t) < r + 1`, the compound-Poisson MGF `∫ n, M_{∑_{i a` absorbs the slice `[a, d]` of the +portfolio loss fraction `L`. Its loss, as a fraction of the tranche notional, is +`((L − a)⁺ − (L − d)⁺)/(d − a)` (`tranchePayoff`; S. Bagaria, *Notes on Fixed Income +Derivative Pricing* (lecture notes), ch. 18, eq. 18.9; Hull ch. 25). +So every tranche expected loss is `(d − a)⁻¹` times a difference of two stop-loss expectations +`E[(L − K)⁺]`. That decomposition is not stated for a general `L`; it is used only inside the +proof of the LHP result `integral_tranchePayoff_oneFactorPD` below. + +In the **large homogeneous portfolio** (LHP) limit of the one-factor Gaussian threshold model, +the loss fraction is the conditional default probability `p(F) = Φ((Φ⁻¹(π) − √ρ F)/√(1 − ρ))` of +the standard normal systematic factor `F` (`tendsto_oneFactorLossFraction_ae` in +`Risk/Credit/VasicekIRB.lean`). For it, with `π, K ∈ (0, 1)` and `0 ≤ ρ < 1`, the stop-loss +expectation has the closed form + + `E[(p(F) − K)⁺] = π − N₂(Φ⁻¹(π), Φ⁻¹(K); √(1 − ρ))` + +(`integral_posPart_oneFactorPD_sub`; O. Vasicek, "Loan portfolio value", *Risk* 15(12) (2002), +the unnumbered stop-loss price — Hull's own tranche-pricing route, ch. 25 eqs. 25.9–25.11, is the +discretized expected-tranche-principal recursion and never states this closed form), where +`N₂(·, ·; r)` is the standard bivariate normal CDF with correlation `r` (`bivariateNormalCDF`, +`Probability/Gaussian/BivariateNormalCDF.lean`). The proof writes `K = Φ(k)` and, with `ε` a +standard normal independent of `F`, reads `(Φ(T) − Φ(k))⁺` as the conditional probability of +`{k < ε ≤ T}` given `F`. Fubini on `N(0,1) ⊗ N(0,1)` turns the expectation into +`P(√ρ F + √(1 − ρ) ε ≤ Φ⁻¹(π)) − P(√ρ F + √(1 − ρ) ε ≤ Φ⁻¹(π), ε ≤ k)`. The first term is `π`; +the second is `N₂` at correlation `√(1 − ρ)`, since `√(1 − (√(1 − ρ))²) = √ρ`. + +## Main definitions + +* `tranchePayoff`: the loss `((L − a)⁺ − (L − d)⁺)/(d − a)` of the tranche `[a, d]` as a fraction + of its notional, when the portfolio loss fraction is `L`. + +## Main results + +* `tranchePayoff_mem_Icc`, `monotone_tranchePayoff`: for `a < d` the tranche loss + lies in `[0, 1]` and is nondecreasing in the portfolio loss. +* `integral_posPart_oneFactorPD_sub`: the LHP stop-loss closed form. +* `integral_tranchePayoff_oneFactorPD`: the LHP tranche expected loss as a difference of two + bivariate normal CDFs. +* `tendsto_integral_tranchePayoff_oneFactorLossFraction`: the finite-pool tranche expected loss + converges to the LHP closed form. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull], ch. 25 +* [O. Vasicek, *Loan portfolio value*][Vasicek2002] + +## Tags + +CDO tranche, tranche expected loss, large homogeneous portfolio, attachment and detachment, +stop-loss, Vasicek model, bivariate normal, structured credit, MSC 91G40, MSC 60E05, JEL G24, +JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set Filter Topology + +/-! ### The tranche payoff -/ + +/-- The loss of the tranche `[a, d]` as a fraction of its notional when the portfolio loss +fraction is `L`: `((L − a)⁺ − (L − d)⁺)/(d − a)`. -/ +noncomputable def tranchePayoff (a d L : ℝ) : ℝ := + ((L - a)⁺ - (L - d)⁺) / (d - a) + +/-- For `a < d`, the tranche loss lies in `[0, 1]`. -/ +theorem tranchePayoff_mem_Icc {a d : ℝ} (had : a < d) (L : ℝ) : + tranchePayoff a d L ∈ Icc 0 1 := by + have hda : 0 < d - a := sub_pos.2 had + rw [tranchePayoff, mem_Icc, div_le_one hda] + refine ⟨div_nonneg ?_ hda.le, ?_⟩ <;> simp only [posPart_def] <;> + rcases max_cases (L - a) 0 with h | h <;> rcases max_cases (L - d) 0 with h' | h' <;> + linarith [h.1, h'.1, h.2, h'.2] + +/-- For `a < d`, the tranche loss is nondecreasing (`Monotone`) in the portfolio loss; it is +constant outside `[a, d]`. -/ +theorem monotone_tranchePayoff {a d : ℝ} (had : a < d) : Monotone (tranchePayoff a d) := by + intro L L' hL + refine div_le_div_of_nonneg_right ?_ (sub_pos.2 had).le + simp only [posPart_def] + rcases max_cases (L - a) 0 with h | h <;> rcases max_cases (L - d) 0 with h' | h' <;> + rcases max_cases (L' - a) 0 with g | g <;> rcases max_cases (L' - d) 0 with g' | g' <;> + linarith [h.1, h'.1, h.2, h'.2, g.1, g'.1, g.2, g'.2] + +/-! ### The LHP stop-loss closed form -/ + +/-- **The LHP stop-loss closed form** (Vasicek 2002, the unnumbered stop-loss price; the +one-factor model itself is Hull ch. 25): for a standard normal systematic factor, `π, K ∈ (0, 1)` +and `0 ≤ ρ < 1`, the large-pool loss fraction +`p(F) = Φ((Φ⁻¹(π) − √ρ F)/√(1 − ρ))` satisfies +`E[(p(F) − K)⁺] = π − N₂(Φ⁻¹(π), Φ⁻¹(K); √(1 − ρ))`. -/ +theorem integral_posPart_oneFactorPD_sub {π ρ K : ℝ} (hπ : π ∈ Ioo 0 1) (hρ0 : 0 ≤ ρ) + (hρ1 : ρ < 1) (hK : K ∈ Ioo 0 1) : + ∫ f, (oneFactorPD π ρ f - K)⁺ ∂gaussianReal 0 1 = + π - bivariateNormalCDF (PhiInv π) (PhiInv K) √(1 - ρ) := by + set μ := gaussianReal 0 1 + set k := PhiInv K + set T : ℝ → ℝ := fun f ↦ (PhiInv π - √ρ * f) / √(1 - ρ) + have hT : Measurable T := by fun_prop + -- the stop-loss payoff is the conditional probability of `{k < ε ≤ T(F)}` + have hpay (f : ℝ) : (oneFactorPD π ρ f - K)⁺ = μ.real (Prod.mk f ⁻¹' + {p : ℝ × ℝ | k < p.2 ∧ p.2 ≤ T p.1}) := by + rw [oneFactorPD, ← Phi_PhiInv hK, posPart_Phi_sub_Phi]; rfl + set S : Set (ℝ × ℝ) := {p | k < p.2 ∧ p.2 ≤ T p.1} + have hS : MeasurableSet S := + (measurableSet_lt measurable_const measurable_snd).inter + (measurableSet_le measurable_snd (hT.comp measurable_fst)) + -- Fubini on `N(0,1) ⊗ N(0,1)` + have hfub : ∫ f, (oneFactorPD π ρ f - K)⁺ ∂μ = (μ.prod μ).real S := by + simp_rw [hpay] + rw [measureReal_def, Measure.prod_apply hS, integral_eq_lintegral_of_nonneg_ae + (ae_of_all _ fun _ ↦ measureReal_nonneg) + (measurable_measure_prodMk_left hS).ennreal_toReal.aestronglyMeasurable] + congr 1 + exact lintegral_congr fun f ↦ ENNReal.ofReal_toReal (measure_ne_top _ _) + -- the default event `{√ρ F + √(1 − ρ) ε ≤ Φ⁻¹(π)}` splits off the event `{ε ≤ k}` + set A : Set (ℝ × ℝ) := {p | √ρ * p.1 + √(1 - ρ) * p.2 ≤ PhiInv π} + have hA : MeasurableSet A := measurableSet_le (by fun_prop) measurable_const + have hSA : S = A \ (A ∩ {p | p.2 ≤ k}) := by + ext p + simp only [S, A, T, mem_ofPred_eq, Set.mem_sdiff, mem_inter_iff, + oneFactor_asset_le_iff hρ1, not_and, not_le] + tauto + have hdef : (μ.prod μ).real A = π := by + have hind : IndepFun Prod.fst Prod.snd (μ.prod μ) := + indepFun_prod (X := id) (Y := id) measurable_id measurable_id + exact oneFactor_measureReal_default (P := μ.prod μ) (F := Prod.fst) (e := Prod.snd) + ⟨measurable_fst.aemeasurable, by simp [μ]⟩ ⟨measurable_snd.aemeasurable, by simp [μ]⟩ + hind hπ hρ0 hρ1.le + have hN₂ : (μ.prod μ).real (A ∩ {p | p.2 ≤ k}) = + bivariateNormalCDF (PhiInv π) k √(1 - ρ) := by + rw [bivariateNormalCDF, stdNormalPair, Real.sq_sqrt (sub_nonneg.2 hρ1.le), sub_sub_cancel] + congr 1 + ext p + simp only [A, mem_inter_iff, mem_ofPred_eq] + rw [add_comm (√(1 - ρ) * p.2)] + rw [hfub, hSA, measureReal_sdiff inter_subset_left (hA.inter (measurableSet_le measurable_snd + measurable_const)), hdef, hN₂] + +/-- **The LHP tranche expected loss** for attachment `a` and detachment `d` with +`0 < a < d < 1`, `π ∈ (0, 1)` and `0 ≤ ρ < 1`, and `F` standard normal: +`E[tranchePayoff a d (p(F))]` is +`(N₂(Φ⁻¹(π), Φ⁻¹(d); √(1 − ρ)) − N₂(Φ⁻¹(π), Φ⁻¹(a); √(1 − ρ)))/(d − a)`. -/ +theorem integral_tranchePayoff_oneFactorPD {π ρ a d : ℝ} (hπ : π ∈ Ioo 0 1) (hρ0 : 0 ≤ ρ) + (hρ1 : ρ < 1) (ha : 0 < a) (had : a < d) (hd : d < 1) : + ∫ f, tranchePayoff a d (oneFactorPD π ρ f) ∂gaussianReal 0 1 = + (bivariateNormalCDF (PhiInv π) (PhiInv d) √(1 - ρ) - + bivariateNormalCDF (PhiInv π) (PhiInv a) √(1 - ρ)) / (d - a) := by + have hint {K : ℝ} (hK : 0 ≤ K) : + Integrable (fun f ↦ (oneFactorPD π ρ f - K)⁺) (gaussianReal 0 1) := + .of_bound ((measurable_oneFactorPD π ρ).sub_const K).posPart.aestronglyMeasurable 1 + (ae_of_all _ fun f ↦ by + rw [Real.norm_of_nonneg (posPart_nonneg _), posPart_def] + exact max_le (by linarith [(Phi_mem_Ioo ((PhiInv π - √ρ * f) / √(1 - ρ))).2, + show oneFactorPD π ρ f = Phi ((PhiInv π - √ρ * f) / √(1 - ρ)) from rfl]) zero_le_one) + simp only [tranchePayoff] + rw [integral_div, integral_sub (hint ha.le) (hint (ha.trans had).le), + integral_posPart_oneFactorPD_sub hπ hρ0 hρ1 ⟨ha, had.trans hd⟩, + integral_posPart_oneFactorPD_sub hπ hρ0 hρ1 ⟨ha.trans had, hd⟩] + ring + +/-! ### From the finite pool to the LHP limit -/ + +/-- The tranche payoff is continuous in the portfolio loss. -/ +lemma continuous_tranchePayoff (a d : ℝ) : Continuous (tranchePayoff a d) := by + unfold tranchePayoff + fun_prop + +/-- **The finite-pool tranche expected loss converges to the LHP closed form.** With `F` and the +`εᵢ` standard normals, the `εᵢ` pairwise independent, the expected loss of the tranche `[a, d]` +on the first `m` obligors of the one-factor Gaussian threshold model converges, as `m → ∞`, to +`(N₂(Φ⁻¹(π), Φ⁻¹(d); √(1 − ρ)) − N₂(Φ⁻¹(π), Φ⁻¹(a); √(1 − ρ)))/(d − a)`, for `π ∈ (0, 1)`, +`0 ≤ ρ < 1` and `0 < a < d < 1`. Independence of `F` from the `εᵢ` is not assumed. The proof is +dominated convergence (the tranche loss lies in `[0, 1]`) along the almost-sure large-portfolio +limit. -/ +theorem tendsto_integral_tranchePayoff_oneFactorLossFraction {Ω : Type*} {mΩ : MeasurableSpace Ω} + {P : Measure Ω} [IsProbabilityMeasure P] {π ρ a d : ℝ} {F : Ω → ℝ} {ε : ℕ → Ω → ℝ} + (hF : HasLaw F (gaussianReal 0 1) P) (hε : ∀ i, HasLaw (ε i) (gaussianReal 0 1) P) + (hind : Pairwise fun i j ↦ ε i ⟂ᵢ[P] ε j) (hπ : π ∈ Ioo 0 1) (hρ0 : 0 ≤ ρ) (hρ1 : ρ < 1) + (ha : 0 < a) (had : a < d) (hd : d < 1) : + Tendsto (fun m ↦ ∫ ω, tranchePayoff a d (oneFactorLossFraction π ρ F ε m ω) ∂P) atTop + (𝓝 ((bivariateNormalCDF (PhiInv π) (PhiInv d) √(1 - ρ) - + bivariateNormalCDF (PhiInv π) (PhiInv a) √(1 - ρ)) / (d - a))) := by + have hcont := continuous_tranchePayoff a d + rw [← integral_tranchePayoff_oneFactorPD hπ hρ0 hρ1 ha had hd, + ← hF.integral_comp (f := fun x ↦ tranchePayoff a d (oneFactorPD π ρ x)) + (hcont.measurable.comp (measurable_oneFactorPD π ρ)).aestronglyMeasurable] + refine tendsto_integral_of_dominated_convergence (fun _ ↦ 1) + (fun m ↦ (hcont.measurable.comp_aemeasurable (aemeasurable_oneFactorLossFraction + hF.aemeasurable (fun i ↦ (hε i).aemeasurable) m)).aestronglyMeasurable) + (integrable_const 1) (fun m ↦ ae_of_all _ fun ω ↦ ?_) ?_ + · have h := tranchePayoff_mem_Icc had (oneFactorLossFraction π ρ F ε m ω) + rw [Real.norm_of_nonneg h.1] + exact h.2 + · filter_upwards [tendsto_oneFactorLossFraction_ae hε hind hρ1 F] with ω hω + exact (hcont.tendsto _).comp hω + +end MathFin diff --git a/LeanPool/MathFin/Risk/Credit/VasicekIRB.lean b/LeanPool/MathFin/Risk/Credit/VasicekIRB.lean new file mode 100644 index 0000000000..1ab6aae4f6 --- /dev/null +++ b/LeanPool/MathFin/Risk/Credit/VasicekIRB.lean @@ -0,0 +1,228 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Laws.QuantileConvergence +public import LeanPool.MathFin.Risk.Credit.BernoulliMixture +public import LeanPool.MathFin.Risk.ValueAtRisk + +/-! +# The Basel IRB formula as the quantile of the large-portfolio loss + +In the one-factor Gaussian threshold model of `Risk/Credit/BernoulliMixture.lean`, obligor `i` +defaults when its asset value `√ρ F + √(1 − ρ) εᵢ` falls below `Φ⁻¹(π)`. The systematic factor `F` +is standard normal and the idiosyncratic terms `εᵢ` are standard normals. The **loss fraction** +of the first `m` obligors is `L_m = (1/m) #{i < m | obligor i defaults}` +(`oneFactorLossFraction`). This file proves the theorem behind the internal-ratings-based (IRB) +capital formula of Basel II/III (Vasicek 2002; Gordy 2003, the asymptotic single-risk-factor +model): + + `VaR_α(L_m) → Φ((Φ⁻¹(π) + √ρ Φ⁻¹(α)) / √(1 − ρ))` as `m → ∞` + +(`tendsto_valueAtRisk_oneFactorLossFraction`). The right side is `asrfQuantile π ρ α`, the IRB +worst-case default rate at confidence `α`. Basel sets `α = 0.999`. The rest of the regulatory +capital formula is not modelled here: loss given default, the subtraction of expected loss, the +maturity adjustment and the 12.5 risk-weight scaling. + +The proof has three steps. + +1. **The large-portfolio limit** (`tendsto_oneFactorLossFraction_ae`): `L_m → p(F)` almost surely, + where `p(f) = Φ((Φ⁻¹(π) − √ρ f)/√(1 − ρ))` is the conditional default probability. Obligor `i` + defaults exactly when `εᵢ ≤ T = (Φ⁻¹(π) − √ρ F)/√(1 − ρ)`, so `L_m` is the empirical CDF of the + `εᵢ` at the random point `T`. By the strong law for the empirical CDF + (`Probability/Laws/QuantileConvergence.lean`) it converges to `Φ(T) = p(F)`. Only pairwise + independence of the idiosyncratic terms enters. Independence of `F` from them is needed for the + finite-portfolio mixture formulas (`oneFactor_measureReal_iInter_default`) but not for the + limit. +2. **The quantile of the limit** (`valueAtRisk_oneFactorPD`). `p(F) = h(−F)` with + `h(z) = Φ((Φ⁻¹(π) + √ρ z)/√(1 − ρ))` continuous and increasing, and `−F` is standard normal. So + `VaR_α(p(F)) = h(Φ⁻¹(α))`, by equivariance of VaR (`valueAtRisk_comp`). +3. **VaR passes to the limit** (`tendsto_valueAtRisk_of_tendsto_ae`). The `α`-quantile of `p(F)` + is strict (`lt_measureReal_oneFactorPD_le`): the law of `p(F)` has no flat stretch at level `α`. + So the quantiles of the `L_m` converge by `tendsto_quantile_of_tendsto_ae`. + +The statements hold for every `π` and every `ρ < 1` (with Lean's `√ρ = 0` for `ρ < 0`). The credit +reading needs `π ∈ (0, 1)`, where `π` is each obligor's default probability +(`oneFactor_measureReal_default`), and `ρ ∈ [0, 1)`, where `ρ` is the asset correlation. + +## Main definitions + +* `oneFactorLossFraction`: the fraction of the first `m` obligors of the one-factor Gaussian + threshold model whose asset value `√ρ F + √(1 − ρ) εᵢ` is at most `Φ⁻¹(π)`. +* `asrfQuantile`: the asymptotic single-risk-factor quantile + `Φ((Φ⁻¹(π) + √ρ Φ⁻¹(α)) / √(1 − ρ))`, the Basel IRB worst-case default rate at confidence `α`. + +## Main results + +* `tendsto_valueAtRisk_of_tendsto_ae`: VaR converges along almost-sure convergence to a loss with + a strict quantile. +* `oneFactorLossFraction_eq_empiricalCDF`: the loss fraction is an empirical CDF at a random point. +* `tendsto_oneFactorLossFraction_ae`: `L_m → p(F)` almost surely. +* `valueAtRisk_oneFactorPD`: `VaR_α(p(F)) = asrfQuantile π ρ α`. +* `tendsto_valueAtRisk_oneFactorLossFraction`: **the IRB formula is the limit of `VaR_α(L_m)`**. + +## References + +* [Gordy (2003)][Gordy2003] +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Section 11.3.2 +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 11.16, 11.17 +* [O. Vasicek, *Loan portfolio value*][Vasicek2002] + +## Tags + +Basel IRB formula, Vasicek model, asymptotic single risk factor, Gordy, large portfolio limit, +worst-case default rate, regulatory capital, one-factor model, MSC 91G40, MSC 60F15, JEL G28, +JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set Filter Topology + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + {π ρ α : ℝ} + +/-! ### VaR along almost-sure convergence -/ + +/-- **VaR is continuous along almost-sure convergence** to a loss whose `α`-quantile is strict, +meaning every level above `VaR_α(Y)` is reached with probability more than `α`. -/ +theorem tendsto_valueAtRisk_of_tendsto_ae {X : ℕ → Ω → ℝ} {Y : Ω → ℝ} + (hX : ∀ n, AEMeasurable (X n) P) (hY : AEMeasurable Y P) + (hlim : ∀ᵐ ω ∂P, Tendsto (fun n ↦ X n ω) atTop (𝓝 (Y ω))) (hα : α ∈ Ioo 0 1) + (hstrict : ∀ x, valueAtRisk Y P α < x → α < P.real {ω | Y ω ≤ x}) : + Tendsto (fun n ↦ valueAtRisk (X n) P α) atTop (𝓝 (valueAtRisk Y P α)) := + tendsto_quantile_of_tendsto_ae hX hY hlim hα fun x hx ↦ by + rw [cdf_map_eq_measureReal hY] + exact hstrict x hx + +/-! ### The loss fraction of the one-factor model -/ + +/-- The **loss fraction** of the first `m` obligors of the one-factor Gaussian threshold model: the +fraction of them whose asset value `√ρ F + √(1 − ρ) εᵢ` is at most `Φ⁻¹(π)`. -/ +noncomputable def oneFactorLossFraction (π ρ : ℝ) (F : Ω → ℝ) (ε : ℕ → Ω → ℝ) (m : ℕ) + (ω : Ω) : ℝ := + (m : ℝ)⁻¹ * ∑ i ∈ Finset.range m, (Iic (PhiInv π)).indicator 1 (√ρ * F ω + √(1 - ρ) * ε i ω) + +/-- The **asymptotic single-risk-factor quantile**, the Basel IRB worst-case default rate at +confidence `α`: `Φ((Φ⁻¹(π) + √ρ Φ⁻¹(α))/√(1 − ρ))`. -/ +noncomputable def asrfQuantile (π ρ α : ℝ) : ℝ := + Phi ((PhiInv π + √ρ * PhiInv α) / √(1 - ρ)) + +omit [IsProbabilityMeasure P] in +lemma aemeasurable_oneFactorLossFraction {F : Ω → ℝ} {ε : ℕ → Ω → ℝ} (hF : AEMeasurable F P) + (hε : ∀ i, AEMeasurable (ε i) P) (m : ℕ) : + AEMeasurable (oneFactorLossFraction π ρ F ε m) P := by + have hdef (i : ℕ) : AEMeasurable + (fun ω ↦ (Iic (PhiInv π)).indicator (1 : ℝ → ℝ) (√ρ * F ω + √(1 - ρ) * ε i ω)) P := + (measurable_const.indicator measurableSet_Iic).comp_aemeasurable + ((hF.const_mul _).add ((hε i).const_mul _)) + exact (Finset.aemeasurable_fun_sum _ fun i _ ↦ hdef i).const_mul _ + +omit [IsProbabilityMeasure P] in +/-- The loss fraction is the empirical CDF of the idiosyncratic terms at the random threshold +`(Φ⁻¹(π) − √ρ F)/√(1 − ρ)`. -/ +lemma oneFactorLossFraction_eq_empiricalCDF (hρ : ρ < 1) (F : Ω → ℝ) (ε : ℕ → Ω → ℝ) (m : ℕ) + (ω : Ω) : + oneFactorLossFraction π ρ F ε m ω = empiricalCDF ε m ω ((PhiInv π - √ρ * F ω) / √(1 - ρ)) := by + refine congrArg _ (Finset.sum_congr rfl fun i _ ↦ ?_) + simp only [indicator_apply, mem_Iic, oneFactor_asset_le_iff hρ, Pi.one_apply] + +/-- **The large-portfolio limit**: the loss fraction converges almost surely to the conditional +default probability `p(F)`. The idiosyncratic terms are pairwise independent standard normals; +the systematic factor `F` is arbitrary. -/ +theorem tendsto_oneFactorLossFraction_ae {ε : ℕ → Ω → ℝ} + (hε : ∀ i, HasLaw (ε i) (gaussianReal 0 1) P) (hind : Pairwise fun i j ↦ ε i ⟂ᵢ[P] ε j) + (hρ : ρ < 1) (F : Ω → ℝ) : + ∀ᵐ ω ∂P, Tendsto (fun m ↦ oneFactorLossFraction π ρ F ε m ω) atTop + (𝓝 (oneFactorPD π ρ (F ω))) := by + filter_upwards + [tendsto_empiricalCDF_ae hε hind (by rw [cdf_gaussianReal_zero_one]; exact continuous_Phi)] + with ω hω + simp_rw [oneFactorLossFraction_eq_empiricalCDF hρ] + simpa only [cdf_gaussianReal_zero_one, oneFactorPD] using + hω ((PhiInv π - √ρ * F ω) / √(1 - ρ)) + +/-! ### The quantile of the limit -/ + +/-- The increasing profile `h(z) = Φ((Φ⁻¹(π) + √ρ z)/√(1 − ρ))` with `p(f) = h(−f)`. -/ +private lemma monotone_asrfProfile (hρ : ρ < 1) : + Monotone fun z ↦ Phi ((PhiInv π + √ρ * z) / √(1 - ρ)) := + strictMono_Phi.monotone.comp fun _ _ hzw ↦ by + have := (Real.sqrt_pos.2 (sub_pos.2 hρ)).le + gcongr + +private lemma continuous_asrfProfile : Continuous fun z ↦ Phi ((PhiInv π + √ρ * z) / √(1 - ρ)) := + continuous_Phi.comp (by fun_prop) + +private lemma oneFactorPD_eq (f : ℝ) : + oneFactorPD π ρ f = Phi ((PhiInv π + √ρ * -f) / √(1 - ρ)) := by + rw [oneFactorPD, mul_neg, ← sub_eq_add_neg] + +/-- **The quantile of the limiting loss**: for a standard normal factor `F`, +`VaR_α(p(F)) = Φ((Φ⁻¹(π) + √ρ Φ⁻¹(α))/√(1 − ρ))`. The loss `p(F)` is the increasing continuous +profile `h` applied to the standard normal `−F`, and VaR commutes with `h`. -/ +theorem valueAtRisk_oneFactorPD {F : Ω → ℝ} (hF : HasLaw F (gaussianReal 0 1) P) (hρ : ρ < 1) + (hα : α ∈ Ioo 0 1) : + valueAtRisk (fun ω ↦ oneFactorPD π ρ (F ω)) P α = asrfQuantile π ρ α := by + have hG : HasLaw (fun ω ↦ -F ω) (gaussianReal 0 1) P := by + have h := gaussianReal_neg hF + rw [neg_zero] at h + exact h + simp_rw [oneFactorPD_eq] + rw [valueAtRisk_comp (h := fun z ↦ Phi ((PhiInv π + √ρ * z) / √(1 - ρ))) hG.aemeasurable + (monotone_asrfProfile hρ) continuous_asrfProfile.lowerSemicontinuous hα, + valueAtRisk_eq_quantile hG] + rfl + +/-- **The `α`-quantile of the limiting loss is strict**: every level above +`asrfQuantile π ρ α` is reached by `p(F)` with probability more than `α`. -/ +theorem lt_measureReal_oneFactorPD_le {F : Ω → ℝ} (hF : HasLaw F (gaussianReal 0 1) P) + (hρ : ρ < 1) (hα : α ∈ Ioo 0 1) {x : ℝ} (hx : asrfQuantile π ρ α < x) : + α < P.real {ω | oneFactorPD π ρ (F ω) ≤ x} := by + -- continuity of the profile at `Φ⁻¹(α)` gives `z > Φ⁻¹(α)` whose image is still below `x` + obtain ⟨z, hzx, hz⟩ := (((continuous_asrfProfile (π := π) (ρ := ρ)).tendsto (PhiInv α)).eventually + (gt_mem_nhds hx) |>.filter_mono nhdsWithin_le_nhds |>.and + (self_mem_nhdsWithin (s := Ioi (PhiInv α)))).exists + have hG : HasLaw (fun ω ↦ -F ω) (gaussianReal 0 1) P := by + have h := gaussianReal_neg hF + rw [neg_zero] at h + exact h + have hNz : P.real {ω | -F ω ≤ z} = Phi z := by + rw [hG.measureReal_eq (p := (· ≤ z)) measurableSet_Iic, + ← cdf_gaussianReal_zero_one, cdf_eq_real] + rfl + calc α = Phi (PhiInv α) := (Phi_PhiInv hα).symm + _ < Phi z := strictMono_Phi hz + _ = P.real {ω | -F ω ≤ z} := hNz.symm + _ ≤ P.real {ω | oneFactorPD π ρ (F ω) ≤ x} := measureReal_mono fun ω hω ↦ by + rw [mem_ofPred_eq, oneFactorPD_eq] + exact (monotone_asrfProfile hρ hω).trans hzx.le + +/-! ### The IRB formula as a limit theorem -/ + +/-- **The Basel IRB formula is the quantile of the large-portfolio loss** (Vasicek 2002; +Gordy 2003). In the one-factor Gaussian threshold model with a standard normal factor `F` and +pairwise independent standard normal idiosyncratic terms, the value-at-risk of the loss fraction +of the first `m` obligors converges, as `m → ∞`, to +`Φ((Φ⁻¹(π) + √ρ Φ⁻¹(α))/√(1 − ρ))`. -/ +theorem tendsto_valueAtRisk_oneFactorLossFraction {F : Ω → ℝ} {ε : ℕ → Ω → ℝ} + (hF : HasLaw F (gaussianReal 0 1) P) (hε : ∀ i, HasLaw (ε i) (gaussianReal 0 1) P) + (hind : Pairwise fun i j ↦ ε i ⟂ᵢ[P] ε j) (hρ : ρ < 1) (hα : α ∈ Ioo 0 1) : + Tendsto (fun m ↦ valueAtRisk (oneFactorLossFraction π ρ F ε m) P α) atTop + (𝓝 (asrfQuantile π ρ α)) := by + rw [← valueAtRisk_oneFactorPD hF hρ hα] + exact tendsto_valueAtRisk_of_tendsto_ae + (aemeasurable_oneFactorLossFraction hF.aemeasurable fun i ↦ (hε i).aemeasurable) + ((measurable_oneFactorPD π ρ).comp_aemeasurable hF.aemeasurable) + (tendsto_oneFactorLossFraction_ae hε hind hρ F) hα fun x hx ↦ + lt_measureReal_oneFactorPD_le hF hρ hα (by rwa [valueAtRisk_oneFactorPD hF hρ hα] at hx) + +end MathFin diff --git a/LeanPool/MathFin/Risk/DiscreteVaR.lean b/LeanPool/MathFin/Risk/DiscreteVaR.lean new file mode 100644 index 0000000000..d5e42c2246 --- /dev/null +++ b/LeanPool/MathFin/Risk/DiscreteVaR.lean @@ -0,0 +1,411 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Analysis.StdSimplexProd +public import LeanPool.MathFin.Probability.Laws.FiniteWeights +public import LeanPool.MathFin.Risk.ValueAtRisk + +/-! +# Value-at-risk and expected shortfall at a finite law + +For a loss `L : ι → ℝ` on a finite state space with probability vector +`q : Convexity.StdSimplex ℝ ι` (weights `q.weights i ≥ 0` summing to `1`), value-at-risk is +`VaR_α = inf {x | α ≤ ∑_{L i ≤ x} q i}` (`finiteVaR`) and expected shortfall is the quantile +average `ES_α = (1 − α)⁻¹ ∫_α^1 VaR_u du` (`finiteES`). For `α ∈ (0, 1)` these are +`valueAtRisk` and `expectedShortfall` of `Risk/ValueAtRisk.lean` at the law +`∑ i, q i • δ_i` (`finiteVaR_eq_valueAtRisk`, `finiteES_eq_expectedShortfall`), written as +`Finset` sums so that concrete laws evaluate by case analysis on the loss level. The probability +vector is bundled, so no lemma threads nonnegativity and total mass; the two half-bonds' joint law +is the product `StdSimplex.prod` of the single bond's law with itself. + +The file works the two-bond example. A single `$100` bond defaulting with probability `1/25` has +`VaR₀.₉₅ = 0`: the loss is 0 with probability `24/25 ≥ 0.95`. The same exposure split into two +`$50` bonds defaulting independently has `VaR₀.₉₅ = 50`, so VaR penalizes the diversified position. +At the single bond, expected shortfall is `80` while the conditional tail mean `E[L | L ≥ VaR₀.₉₅]` +is the unconditional mean `4`. + +These are worked instances of general results in the library. In +`Risk/VaRSuperadditivity.lean`, `valueAtRisk_sum_bernoulli_of_card_two` is the two-loan +example for independent (`iIndepFun`), identically distributed unit losses sharing one default +probability `p`: on `(1 − p)² < α ≤ 1 − p` each loan has VaR `0` and the portfolio VaR `1`. The +exact superadditivity window, for `α ∈ (0, 1)` and any number of independent, identically +distributed Bernoulli losses (same shared `p`), is `valueAtRisk_sum_bernoulli_superadditive_iff`. +For an integrable loss and `α ∈ (0, 1)`, the dual representation of ES over bounded densities is +`isGreatest_integral_mul_expectedShortfall` (`Risk/ExpectedShortfall.lean`). + +## Main definitions + +* `finiteVaR`: value-at-risk at a finite law, `inf {x | α ≤ ∑_{L i ≤ x} qᵢ}`, for a loss `L` and + a bundled probability vector `q`. +* `finiteES`: expected shortfall at a finite law, `(1 − α)⁻¹ ∫_α^1 finiteVaR q L u du`. +* `Measure.ofWeights univ q.weights`: the law `∑ᵢ qᵢ • δᵢ` of a probability vector + (`Probability/Laws/FiniteWeights`), a probability measure. +* `condTailMean`: the `q`-weighted mean of `L` over the tail event `{i | finiteVaR q L α ≤ L i}`, + divided by the tail mass. +* `oneQ`, `oneL`, `jointQ`, `halfL₁`, `halfL₂`: the data of the worked example, a single `$100` + bond defaulting with probability `1/25` against two independent `$50` bonds. + +## Main results + +* `finiteVaR_eq_valueAtRisk`, `finiteES_eq_expectedShortfall`: for `α ∈ (0, 1)`, the finite forms + agree with the general definitions at the law `∑ i, q i • δ_i`. +* `finiteVaR_eq_value_min`: for `α ∈ (0, 1]`, VaR at a finite law is attained at a loss value. +* `finiteVaR_two_point`: for `α ∈ (0, 1]`, VaR of a loss that is `0` with mass `a` and `c > 0` with + mass `1 - a`. +* `finiteVaR_one_bond`, `finiteVaR_two_halves`: `VaR₀.₉₅` is `0` for the single bond and `50` + for the split position. +* `finiteVaR_subadditivity_fails`: on the joint space of the two half-bonds, the halves' `VaR₀.₉₅` + sum to less than the total's (which is `50` by `finiteVaR_two_halves`). + `valueAtRisk_ofWeights_subadditivity_fails` states the same failure for the library's + `valueAtRisk` at the law `∑ p, jointQ p • δ_p`. +* `finiteVaR_counterexample_window`: for the two half-bonds and `α ∈ (0, 1]`, subadditivity fails + exactly for `(24/25)² < α ≤ 24/25`. +* `finiteES_one_bond`: `ES₀.₉₅ = 80` for the single bond. +* `condTailMean_one_bond`: at the single bond the tail event `{L ≥ VaR₀.₉₅}` is the whole space, + so the conditional tail mean is `E[L] = 4`. +* `isGreatest_finiteES_one_bond`: for the single bond, `ES₀.₉₅` is the greatest `E[Z·L]` over + densities `0 ≤ Z ≤ (1 − 19/20)⁻¹` with `E[Z] = 1`. + +## References + +* [C. Acerbi and D. Tasche, *On the coherence of expected shortfall*][AcerbiTasche2002] + +## Tags + +value at risk, expected shortfall, finite loss distribution, VaR subadditivity failure, +bond portfolio example, conditional tail mean, MSC 91G70, JEL G32 +-/ + +@[expose] public section + +namespace MathFin.DiscreteVaR + +open MeasureTheory Set +open scoped Interval +open Convexity + +variable {ι : Type*} [Fintype ι] + +/-! ## The definitions and the bridge to `valueAtRisk` -/ + +/-- **VaR at a finite law**: the infimum of the loss levels `x` at which the `q`-mass of +`{i | L i ≤ x}` reaches `α`. For `α ∈ (0, 1]` the set is nonempty and bounded below, which is the +only range used in this file. Outside that range the set can be empty or all of `ℝ`, where `sInf` +returns the junk value `0`. -/ +noncomputable def finiteVaR (q : StdSimplex ℝ ι) (L : ι → ℝ) (α : ℝ) : ℝ := + sInf {x | α ≤ ∑ i with L i ≤ x, q.weights i} + +/-- **ES at a finite law**: the quantile average, `(1 - α)⁻¹` times the oriented interval integral +`∫ u in α..1` of the quantile function `u ↦ finiteVaR q L u`. For `α ∈ (0, 1)` this is the +quantile average over `[α, 1]`, and the bridge `finiteES_eq_expectedShortfall` covers exactly that +range, the only one used in this file. Elsewhere it is junk: for `α ≤ 0` the integrand on +`[α, 0]` is `finiteVaR`'s junk value `0`; at `α = 1` the factor `(1 - α)⁻¹` is Lean's `0⁻¹ = 0`, so +`finiteES q L 1 = 0` for every loss; for `α > 1` the integral runs backwards and the prefactor +is negative. -/ +noncomputable def finiteES (q : StdSimplex ℝ ι) (L : ι → ℝ) (α : ℝ) : ℝ := + (1 - α)⁻¹ * ∫ u in α..1, finiteVaR q L u + +section Bridge + +variable [MeasurableSpace ι] {q : StdSimplex ℝ ι} + +/-- The law `Measure.ofWeights univ q.weights = ∑ i, q i • δ_i` of a probability vector is a +probability measure. -/ +instance : IsProbabilityMeasure (Measure.ofWeights Finset.univ q.weights) := + Measure.isProbabilityMeasure_ofWeights (fun i _ ↦ q.weights_nonneg i) (by simp) + +variable [MeasurableSingletonClass ι] + +/-- Under `Measure.ofWeights univ q.weights` the mass of `{L ≤ x}` is the sum in `finiteVaR`. -/ +lemma ofWeights_real_le (L : ι → ℝ) (x : ℝ) : + (Measure.ofWeights Finset.univ q.weights).real {i | L i ≤ x} + = ∑ i with L i ≤ x, q.weights i := by + rw [measureReal_def, Measure.ofWeights, FunLike.coe_sum, Finset.sum_apply] + simp_rw [smul_apply, smul_eq_mul] + rw [ENNReal.toReal_sum fun i _ ↦ ENNReal.mul_ne_top ENNReal.ofReal_ne_top (measure_ne_top _ _), + Finset.sum_filter] + refine Finset.sum_congr rfl fun i _ ↦ ?_ + by_cases hi : L i ≤ x <;> simp [Measure.dirac_apply, hi, q.weights_nonneg i] + +/-- For `α ∈ (0, 1)`, `finiteVaR` is `valueAtRisk` at the law `∑ i, q i • δ_i`. -/ +theorem finiteVaR_eq_valueAtRisk {L : ι → ℝ} {α : ℝ} (hα : α ∈ Ioo 0 1) : + finiteVaR q L α = valueAtRisk L (Measure.ofWeights Finset.univ q.weights) α := by + have hset : {x | α ≤ ∑ i with L i ≤ x, q.weights i} + = Ici (valueAtRisk L (Measure.ofWeights Finset.univ q.weights) α) := by + ext x + simp [valueAtRisk_le_iff (measurable_of_finite L).aemeasurable hα, ofWeights_real_le] + rw [finiteVaR, hset, csInf_Ici] + +/-- For `α ∈ (0, 1)`, `finiteES` is `expectedShortfall` at the law `∑ i, q i • δ_i`. -/ +theorem finiteES_eq_expectedShortfall {L : ι → ℝ} {α : ℝ} (hα : α ∈ Ioo 0 1) : + finiteES q L α = expectedShortfall L (Measure.ofWeights Finset.univ q.weights) α := by + rw [finiteES, expectedShortfall, intervalIntegral.integral_of_le hα.2.le, + integral_Ioc_eq_integral_Ioo] + exact congrArg _ <| setIntegral_congr_fun measurableSet_Ioo fun u hu ↦ + finiteVaR_eq_valueAtRisk ⟨hα.1.trans hu.1, hu.2⟩ + +end Bridge + +/-! ## Evaluating `finiteVaR` -/ + +section Evaluation + +variable {q : StdSimplex ℝ ι} {L : ι → ℝ} {α : ℝ} + +/-- **The evaluation principle**: if the `q`-mass of `{L ≤ v₀}` reaches α and the mass of +`{L ≤ x}` stays below α for every `x < v₀`, then `finiteVaR q L α = v₀`. Pure order arithmetic, +with no hypothesis on `α`. -/ +theorem finiteVaR_eq_of_mem_of_forall_lt {v₀ : ℝ} + (hmem : α ≤ ∑ i with L i ≤ v₀, q.weights i) + (hbelow : ∀ x < v₀, ∑ i with L i ≤ x, q.weights i < α) : + finiteVaR q L α = v₀ := + IsLeast.csInf_eq ⟨hmem, fun x hx ↦ not_lt.1 fun h ↦ (hbelow x h).not_ge hx⟩ + +/-- For `α ≤ 1`, the loss values `v` at which the mass of `{L ≤ v}` is at least α form a +nonempty finite set: at the largest loss value that mass is the full mass `1 ≥ α`. -/ +theorem nonempty_values_mass_ge (hα1 : α ≤ 1) : + {v ∈ Finset.univ.image L | α ≤ ∑ i with L i ≤ v, q.weights i}.Nonempty := by + have hne := (Finset.nonempty_of_sum_ne_zero (by rw [q.total_of_fintype]; norm_num)).image L + have hfull : {i ∈ (Finset.univ : Finset ι) | L i ≤ (Finset.univ.image L).max' hne} + = Finset.univ := + Finset.filter_true_of_mem fun i _ ↦ + Finset.le_max' _ _ (Finset.mem_image_of_mem _ (Finset.mem_univ _)) + exact ⟨_, Finset.mem_filter.2 ⟨Finset.max'_mem _ hne, by rwa [hfull, q.total_of_fintype]⟩⟩ + +/-- **Attainment.** For `α ∈ (0, 1]`, the infimum over `ℝ` is the minimum over the loss values +`v ∈ Finset.image L univ` at which the `q`-mass of `{L ≤ v}` is at least α, so VaR is attained at a +loss value. -/ +theorem finiteVaR_eq_value_min (hα0 : 0 < α) (hα1 : α ≤ 1) : + finiteVaR q L α = {v ∈ Finset.univ.image L | α ≤ ∑ i with L i ≤ v, q.weights i}.min' + (nonempty_values_mass_ge hα1) := by + refine IsLeast.csInf_eq ⟨(Finset.mem_filter.1 (Finset.min'_mem _ _)).2, + fun x (hx : α ≤ _) ↦ ?_⟩ + -- the largest loss value `L j ≤ x` carries the same mass as `x`, so it lies in the filter + obtain ⟨j, hj, hjmax⟩ := + Finset.exists_max_image _ L (Finset.nonempty_of_sum_ne_zero (hα0.trans_le hx).ne') + have hjx := (Finset.mem_filter.1 hj).2 + have hfilt : {i ∈ (Finset.univ : Finset ι) | L i ≤ L j} + = {i ∈ (Finset.univ : Finset ι) | L i ≤ x} := + Finset.filter_congr fun i _ ↦ ⟨fun h ↦ h.trans hjx, fun h ↦ hjmax i (by simpa using h)⟩ + exact (Finset.min'_le _ _ (Finset.mem_filter.2 ⟨Finset.mem_image_of_mem _ (Finset.mem_univ j), + hfilt ▸ hx⟩)).trans hjx + +/-- **Two-point laws.** If the mass of `{L ≤ x}` is `0` for `x < 0`, `a` for `0 ≤ x < c` and +`a + b = 1` for `x ≥ c`, with `c > 0`, then at every level `α ∈ (0, 1]` the VaR is `0` for +`α ≤ a` and `c` above. -/ +theorem finiteVaR_two_point {a b c : ℝ} (hab : a + b = 1) (hc : 0 < c) + (hcdf : ∀ x, ∑ i with L i ≤ x, q.weights i + = (if 0 ≤ x then a else 0) + (if c ≤ x then b else 0)) + (hα0 : 0 < α) (hα1 : α ≤ 1) : + finiteVaR q L α = if α ≤ a then 0 else c := by + split_ifs <;> refine finiteVaR_eq_of_mem_of_forall_lt ?_ fun x hx ↦ ?_ <;> rw [hcdf] <;> + split_ifs <;> linarith + +end Evaluation + +/-! ## The single bond -/ + +/-- Probability vector of the single `$100` bond: default (`true`) with probability `1/25`, +survival (`false`) with probability `24/25`. -/ +noncomputable def oneQ : StdSimplex ℝ Bool := + .duple true false (s := 1 / 25) (t := 24 / 25) (by norm_num) (by norm_num) (by norm_num) + +@[simp] lemma oneQ_true : oneQ.weights true = 1 / 25 := by simp [oneQ] + +@[simp] lemma oneQ_false : oneQ.weights false = 24 / 25 := by simp [oneQ] + +/-- Loss of the single `$100` bond: 100 on default, 0 on survival. -/ +def oneL : Bool → ℝ := fun b ↦ if b then 100 else 0 + +private lemma one_bond_cdf (x : ℝ) : + ∑ b with oneL b ≤ x, oneQ.weights b + = (if 0 ≤ x then 24 / 25 else 0) + (if 100 ≤ x then 1 / 25 else 0) := by + rw [Finset.sum_filter, Fintype.sum_bool] + simp [oneL, add_comm] + +/-- The single-bond VaR as a function of the level `α ∈ (0, 1]`: `0` for `α ≤ 24/25`, `100` +above. This is the quantile function integrated in `finiteES_one_bond`. -/ +theorem finiteVaR_one_bond_window (α : ℝ) (hα0 : 0 < α) (hα1 : α ≤ 1) : + finiteVaR oneQ oneL α = if α ≤ 24 / 25 then 0 else 100 := + finiteVaR_two_point (by norm_num) (by norm_num) one_bond_cdf hα0 hα1 + +/-- The single `$100` bond defaulting w.p. `1/25` has `VaR₀.₉₅ = 0`: the loss is 0 with probability +`24/25 ≥ 19/20`. -/ +theorem finiteVaR_one_bond : finiteVaR oneQ oneL (19 / 20) = 0 := by + rw [finiteVaR_one_bond_window _ (by norm_num) (by norm_num), ite_eq_left (by norm_num)] + +/-! ## The two half-bonds on their joint space `Bool × Bool` -/ + +/-- Joint law of the two independent `$50` half-bonds (`true` = default): the product of the +marginals `1/25` / `24/25`. -/ +noncomputable def jointQ : StdSimplex ℝ (Bool × Bool) := + oneQ.prod oneQ + +/-- Loss of the first half-bond: 50 if it defaults, else 0. -/ +def halfL₁ : Bool × Bool → ℝ := fun p ↦ if p.1 then 50 else 0 + +/-- Loss of the second half-bond: 50 if it defaults, else 0. -/ +def halfL₂ : Bool × Bool → ℝ := fun p ↦ if p.2 then 50 else 0 + +private lemma joint_half₁_cdf (x : ℝ) : + ∑ p with halfL₁ p ≤ x, jointQ.weights p + = (if 0 ≤ x then 24 / 25 else 0) + (if 50 ≤ x then 1 / 25 else 0) := by + rw [Finset.sum_filter, Fintype.sum_prod_type] + norm_num [halfL₁, jointQ] + split_ifs <;> norm_num + +private lemma joint_half₂_cdf (x : ℝ) : + ∑ p with halfL₂ p ≤ x, jointQ.weights p + = (if 0 ≤ x then 24 / 25 else 0) + (if 50 ≤ x then 1 / 25 else 0) := by + rw [Finset.sum_filter, Fintype.sum_prod_type] + norm_num [halfL₂, jointQ] + split_ifs <;> norm_num + +/-- Mass of `{halfL₁ + halfL₂ ≤ x}` under the joint law: no default w.p. `9216/10000 = (24/25)²`, +one default w.p. `768/10000 = 2·(24/25)(1/25)`, two w.p. `16/10000 = (1/25)²`. -/ +private lemma joint_cdf (x : ℝ) : + ∑ p with (halfL₁ + halfL₂) p ≤ x, jointQ.weights p + = (if 0 ≤ x then 9216 / 10000 else 0) + (if 50 ≤ x then 768 / 10000 else 0) + + (if 100 ≤ x then 16 / 10000 else 0) := by + rw [Finset.sum_filter, Fintype.sum_prod_type] + norm_num [halfL₁, halfL₂, jointQ] + split_ifs <;> norm_num + +/-- The first half-bond's VaR as a function of the level `α ∈ (0, 1]`. -/ +theorem finiteVaR_half₁_window (α : ℝ) (hα0 : 0 < α) (hα1 : α ≤ 1) : + finiteVaR jointQ halfL₁ α = if α ≤ 24 / 25 then 0 else 50 := + finiteVaR_two_point (by norm_num) (by norm_num) joint_half₁_cdf hα0 hα1 + +/-- The second half-bond's VaR as a function of the level `α ∈ (0, 1]`. -/ +theorem finiteVaR_half₂_window (α : ℝ) (hα0 : 0 < α) (hα1 : α ≤ 1) : + finiteVaR jointQ halfL₂ α = if α ≤ 24 / 25 then 0 else 50 := + finiteVaR_two_point (by norm_num) (by norm_num) joint_half₂_cdf hα0 hα1 + +/-- The total VaR of the two half-bonds as a function of the level `α ∈ (0, 1]`: `0` up to the +mass `9216/10000` of no default, `50` up to the mass `9984/10000` of at most one default, `100` +above. -/ +theorem finiteVaR_joint_window (α : ℝ) (hα0 : 0 < α) (hα1 : α ≤ 1) : + finiteVaR jointQ (halfL₁ + halfL₂) α + = if α ≤ 9216 / 10000 then 0 else if α ≤ 9984 / 10000 then 50 else 100 := by + split_ifs <;> refine finiteVaR_eq_of_mem_of_forall_lt ?_ fun x hx ↦ ?_ <;> rw [joint_cdf] <;> + split_ifs <;> linarith + +/-- The same exposure split into two independent `$50` bonds has `VaR₀.₉₅ = 50`: +`P(L = 0) = 0.9216 < 0.95` but `P(L ≤ 50) = 0.9984 ≥ 0.95`. -/ +theorem finiteVaR_two_halves : finiteVaR jointQ (halfL₁ + halfL₂) (19 / 20) = 50 := by + rw [finiteVaR_joint_window _ (by norm_num) (by norm_num)] + norm_num + +/-- **The failure window.** For the level `α ∈ (0, 1]`, subadditivity fails exactly for +`9216/10000 < α ≤ 24/25`, where `9216/10000 = (24/25)²`. The right endpoint is included because +the definition uses `α ≤ P(L ≤ x)`: at `α = 24/25` each half keeps VaR `0` while the total has +VaR `50`. At `α = 9216/10000` the total VaR is still `0`, so the left endpoint is excluded. -/ +theorem finiteVaR_counterexample_window (α : ℝ) (hα0 : 0 < α) (hα1 : α ≤ 1) : + finiteVaR jointQ halfL₁ α + finiteVaR jointQ halfL₂ α + < finiteVaR jointQ (halfL₁ + halfL₂) α ↔ 9216 / 10000 < α ∧ α ≤ 24 / 25 := by + rw [finiteVaR_joint_window α hα0 hα1, finiteVaR_half₁_window α hα0 hα1, + finiteVaR_half₂_window α hα0 hα1] + constructor + · split_ifs <;> intro h <;> norm_num at h <;> exact ⟨by linarith, by linarith⟩ + · rintro ⟨h1, h2⟩ + rw [ite_eq_left h2, ite_eq_right h1.not_ge, ite_eq_left (by linarith)] + norm_num + +/-- **Subadditivity fails at the 95% level** on one probability space: the two `$50` half-bonds' +`VaR₀.₉₅` sum to less than the `VaR₀.₉₅` of their total. The values are `0` for each half +(`finiteVaR_half₁_window`, `finiteVaR_half₂_window`) and `50` for the total +(`finiteVaR_two_halves`). -/ +theorem finiteVaR_subadditivity_fails : + finiteVaR jointQ halfL₁ (19 / 20) + finiteVaR jointQ halfL₂ (19 / 20) + < finiteVaR jointQ (halfL₁ + halfL₂) (19 / 20) := + (finiteVaR_counterexample_window _ (by norm_num) (by norm_num)).2 ⟨by norm_num, by norm_num⟩ + +/-- **Subadditivity of `valueAtRisk` fails**: the same failure for the library's `valueAtRisk` +at the law `∑ p, jointQ p • δ_p` of the two half-bonds, through the bridge +`finiteVaR_eq_valueAtRisk`. -/ +theorem valueAtRisk_ofWeights_subadditivity_fails : + valueAtRisk halfL₁ (Measure.ofWeights Finset.univ jointQ.weights) (19 / 20) + + valueAtRisk halfL₂ (Measure.ofWeights Finset.univ jointQ.weights) (19 / 20) + < valueAtRisk (halfL₁ + halfL₂) (Measure.ofWeights Finset.univ jointQ.weights) (19 / 20) := by + have hα : (19 / 20 : ℝ) ∈ Ioo 0 1 := ⟨by norm_num, by norm_num⟩ + rw [← finiteVaR_eq_valueAtRisk hα, ← finiteVaR_eq_valueAtRisk hα, + ← finiteVaR_eq_valueAtRisk hα] + exact finiteVaR_subadditivity_fails + +/-! ## Expected shortfall at the single bond -/ + +/-- `ES₀.₉₅ = 80` for the single bond: the quantile function is `0` on `[19/20, 24/25]` and `100` +on `(24/25, 1]`, so the average is `(1/(1/20)) · 100 · (1 - 24/25) = 80`. -/ +theorem finiteES_one_bond : finiteES oneQ oneL (19 / 20) = 80 := by + have hz1 (u) (hu : u ∈ Icc (19 / 20 : ℝ) (24 / 25)) : finiteVaR oneQ oneL u = 0 := by + rw [finiteVaR_one_bond_window u (by linarith [hu.1]) (by linarith [hu.2]), ite_eq_left hu.2] + have hc1 (u) (hu : u ∈ Ioc (24 / 25 : ℝ) 1) : finiteVaR oneQ oneL u = 100 := by + rw [finiteVaR_one_bond_window u (by linarith [hu.1]) hu.2, ite_eq_right (not_le.2 hu.1)] + -- the quantile function agrees a.e. with a constant on each piece, which gives both + -- integrability and the value of the integral in one hypothesis + have hae1 : finiteVaR oneQ oneL =ᵐ[volume.restrict (Ι (19 / 20 : ℝ) (24 / 25))] + fun _ ↦ (0 : ℝ) := + Set.EqOn.aeEq_restrict (fun u hu ↦ by + rw [uIoc_of_le (by norm_num : (19 / 20 : ℝ) ≤ 24 / 25)] at hu + exact hz1 u (Ioc_subset_Icc_self hu)) measurableSet_uIoc + have hae2 : finiteVaR oneQ oneL =ᵐ[volume.restrict (Ι (24 / 25 : ℝ) 1)] fun _ ↦ (100 : ℝ) := + Set.EqOn.aeEq_restrict (fun u hu ↦ by + rw [uIoc_of_le (by norm_num : (24 / 25 : ℝ) ≤ 1)] at hu + exact hc1 u hu) measurableSet_uIoc + have h1int : IntervalIntegrable (finiteVaR oneQ oneL) volume (19 / 20 : ℝ) (24 / 25) := + intervalIntegrable_const.congr_ae hae1.symm + have h2int : IntervalIntegrable (finiteVaR oneQ oneL) volume (24 / 25 : ℝ) 1 := + intervalIntegrable_const.congr_ae hae2.symm + have hval1 : ∫ u in (19 / 20 : ℝ)..(24 / 25), finiteVaR oneQ oneL u = 0 := by + rw [intervalIntegral.integral_congr_ae_restrict hae1]; simp + have hval2 : ∫ u in (24 / 25 : ℝ)..1, finiteVaR oneQ oneL u = 4 := by + rw [intervalIntegral.integral_congr_ae_restrict hae2]; norm_num + rw [finiteES, ← intervalIntegral.integral_add_adjacent_intervals h1int h2int, hval1, hval2] + norm_num + +/-! ## The conditional tail mean at an atom -/ + +/-- **`E[L | L ≥ VaR_α]` at a finite law**: the `q`-weighted mean of `L` over the tail event +`{i | finiteVaR q L α ≤ L i}`. For `α ∈ (0, 1]` the tail mass is positive (not stated as a lemma +here), so this is a genuine conditional mean; outside that range the tail mass can be `0` and the +quotient returns the junk value `0`. -/ +noncomputable def condTailMean (q : StdSimplex ℝ ι) (L : ι → ℝ) (α : ℝ) : ℝ := + (∑ i with finiteVaR q L α ≤ L i, q.weights i * L i) / + (∑ i with finiteVaR q L α ≤ L i, q.weights i) + +/-- At the single bond the tail event `{L ≥ VaR₀.₉₅} = {L ≥ 0}` is the whole state space, so the +conditional tail mean is the unconditional expectation `E[L] = 4`, while `ES₀.₉₅ = 80` +(`finiteES_one_bond`). -/ +theorem condTailMean_one_bond : condTailMean oneQ oneL (19 / 20) = 4 := by + have hfilt : {b ∈ (Finset.univ : Finset Bool) | finiteVaR oneQ oneL (19 / 20) ≤ oneL b} + = Finset.univ := + Finset.filter_true_of_mem fun b _ ↦ by rw [finiteVaR_one_bond]; cases b <;> norm_num [oneL] + rw [condTailMean, hfilt, oneQ.total_of_fintype, div_one] + norm_num [oneL] + +/-! ## The bounded-density representation of ES at the single bond -/ + +/-- For the single bond, `ES₀.₉₅` is the greatest value of `E[Z·L]` over densities `Z` with +`0 ≤ Z ≤ (1 - 19/20)⁻¹ = 20` and `E[Z] = 1`; both equal `80` (`finiteES_one_bond`). This is the +two-state analogue of `isGreatest_integral_mul_expectedShortfall`. The objective is +`E[Z·L] = 4·Z(default)`, so the maximum puts `Z(default)` at the cap `20`, and `E[Z] = 1` then +gives `Z(survival) = 5/24`. -/ +theorem isGreatest_finiteES_one_bond : + IsGreatest ((fun Z : Bool → ℝ ↦ ∑ b, oneQ.weights b * Z b * oneL b) '' + {Z | (∀ b, 0 ≤ Z b ∧ Z b ≤ (1 - 19 / 20)⁻¹) ∧ ∑ b, oneQ.weights b * Z b = 1}) + (finiteES oneQ oneL (19 / 20)) := by + rw [finiteES_one_bond] + refine ⟨⟨fun c ↦ if c then 20 else 5 / 24, + ⟨fun c ↦ by cases c <;> norm_num, by norm_num⟩, by norm_num [oneL]⟩, ?_⟩ + rintro v ⟨Z, ⟨hcap, -⟩, rfl⟩ + have := (hcap true).2 + norm_num [oneL] at this ⊢ + linarith + +end MathFin.DiscreteVaR diff --git a/LeanPool/MathFin/Risk/Elicitability.lean b/LeanPool/MathFin/Risk/Elicitability.lean new file mode 100644 index 0000000000..d7e880e725 --- /dev/null +++ b/LeanPool/MathFin/Risk/Elicitability.lean @@ -0,0 +1,485 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.ExpectedShortfall + +/-! +# Elicitability: value-at-risk is elicitable, expected shortfall is not + +A functional `T` of laws on `ℝ`, with values in any type `V`, is **elicitable** on a class `C` of +laws if it is the unique minimizer of an expected score: some scoring function `S(x, y)` makes +`T μ` the unique minimizer of `x ↦ ∫ S(x, y) dμ(y)` for every `μ ∈ C` (Gneiting 2011; +McNeil–Frey–Embrechts (2015), §9.3). Real-valued functionals (`V = ℝ`) are the single-valued case; +a **jointly** elicitable pair `(T₁, T₂)` is elicitability at `V = ℝ × ℝ` +(`Risk/JointElicitability.lean`). +Elicitability is what makes a risk forecast comparable with realized losses: competing forecasts +are ranked by their average realized scores (QRM Exercise Book, Exercises 9.5 and 9.16). + +* **Elicitable functionals have convex level sets** (`StrictlyElicits.apply_mixture`). If + `T μ = T ν`, then `T` takes the same value on every mixture of `μ` and `ν` in the class. The + expected score is affine along a mixture of laws (`integral_mixture`), the property + `expectedUtility_mix` of `Choice/Utility/VonNeumannMorgenstern.lean` records for expected utility. + So the common minimizer of the two expected scores also minimizes their mixture. +* **VaR is elicitable** (`strictlyElicits_pinballLoss`). The pinball loss + `S_α(x, y) = (𝟙{y ≤ x} − α)(x − y)` elicits the `α`-quantile on the laws with finite mean whose + `α`-quantile is unique. The expected pinball loss is `1 − α` times the Rockafellar–Uryasev + objective, minus a constant (`integral_pinballLoss`). So VaR minimizing it is the + Rockafellar–Uryasev theorem of `Risk/ExpectedShortfall.lean`. Uniqueness is the exact + excess formula `rockafellarUryasev_sub_expectedShortfall`: `g(c) − ES_α(X)` integrates the + distance of the VaR curve from `c` over the levels on the wrong side of `α`. +* **ES is not elicitable** (`not_isElicitable_expectedShortfall`). For every `α ∈ (0, 1)`, the + point mass `δ₀` and the two-point law `esLevelWitness α = ((1+α)/2) δ₋₁ + ((1−α)/2) δ₁` both have + `ES_α = 0`. Their mixture `(1 − α) δ₀ + α · esLevelWitness α` has `ES_α = α/2`. So the level set + `{ES_α = 0}` is not convex, and no scoring function elicits `ES_α` on any class containing these + three laws, in particular on all laws with finite mean + (`not_isElicitable_expectedShortfall_integrable`). + +With `Risk/ExpectedShortfall.lean` this gives one half of each side of the regulatory +trade-off: expected shortfall is coherent but not elicitable, while value-at-risk is elicitable. +Its failure of subadditivity is proved in `Risk/VaRSuperadditivity.lean`. + +## Main definitions + +* `StrictlyElicits`: the scoring function `S` strictly elicits the functional `T` on a class `C` + of laws, i.e. `T μ` is the unique minimizer of `x ↦ ∫ S(x, y) dμ(y)` for every `μ ∈ C`. +* `IsElicitable`: some scoring function strictly elicits `T` on `C`. +* `pinballLoss`: the pinball loss `(𝟙{y ≤ x} − α)(x − y)` of a quantile forecast `x` against a + realized loss `y`. +* `esLevelWitness`, `esLevelMixture`: the two-point law `((1 + α)/2) δ₋₁ + ((1 − α)/2) δ₁` and + the mixture `(1 − α) δ₀ + α · esLevelWitness α` used to show that expected shortfall is not + elicitable. + +## Main results + +* `StrictlyElicits.apply_mixture`: on a class closed under the mixture, a strictly elicited + functional is constant on mixtures of laws with equal values (convex level sets). +* `integral_pinballLoss`: the expected pinball loss in terms of `rockafellarUryasev`. +* `integral_pinballLoss_valueAtRisk_le`: VaR minimizes the expected pinball loss. +* `rockafellarUryasev_sub_expectedShortfall`: the exact Rockafellar–Uryasev excess. +* `expectedShortfall_lt_rockafellarUryasev`: when the quantile is unique, `ES_α < RU(c)` for every + `c ≠ VaR_α`, so VaR is the unique minimizer of the Rockafellar–Uryasev function. +* `strictlyElicits_pinballLoss`: the pinball loss strictly elicits the `α`-quantile on the laws + with a finite mean and a unique `α`-quantile. +* `not_isElicitable_expectedShortfall`: for `α ∈ (0, 1)`, `ES_α` is not elicitable on any class of + laws containing `δ₀`, `esLevelWitness α` and `esLevelMixture α`. + +## References + +* [T. Gneiting, *Making and evaluating point forecasts*][Gneiting2011] +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Section 9.3 +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 9.5(c); Ex. 9.5, 9.16 + +## Tags + +elicitability, pinball loss, quantile loss, scoring function, backtesting, VaR vs ES, +forecast comparison, MSC 91G70, MSC 62F10, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set +open scoped NNReal ENNReal + +/-! ### Elicitability and convex level sets -/ + +/-- The scoring function `S` **strictly elicits** the functional `T` on the class `C` of laws on +`ℝ`, with values in `V`: for every `μ ∈ C` each expected score `∫ S x y dμ(y)` is finite, and +`T μ` is the unique minimizer of `x ↦ ∫ S x y dμ(y)` over `x : V`. -/ +def StrictlyElicits {V : Type*} (S : V → ℝ → ℝ) (T : Measure ℝ → V) (C : Set (Measure ℝ)) : + Prop := + ∀ μ ∈ C, (∀ x, Integrable (S x) μ) ∧ ∀ x, x ≠ T μ → ∫ y, S (T μ) y ∂μ < ∫ y, S x y ∂μ + +/-- A functional of laws is **elicitable** on `C` if some scoring function strictly elicits it. -/ +def IsElicitable {V : Type*} (T : Measure ℝ → V) (C : Set (Measure ℝ)) : Prop := + ∃ S, StrictlyElicits S T C + +variable {V : Type*} {S : V → ℝ → ℝ} {T : Measure ℝ → V} {C : Set (Measure ℝ)} + +/-- The integral against a mixture of laws is the mixture of the integrals. -/ +lemma integral_mixture {f : ℝ → ℝ} {μ ν : Measure ℝ} (hμ : Integrable f μ) + (hν : Integrable f ν) {c : ℝ≥0} (hc : c ≤ 1) : + ∫ y, f y ∂(c • μ + (1 - c) • ν) = c * ∫ y, f y ∂μ + (1 - c : ℝ) * ∫ y, f y ∂ν := by + rw [integral_add_measure hμ.smul_measure_nnreal hν.smul_measure_nnreal, + integral_smul_nnreal_measure, integral_smul_nnreal_measure, NNReal.smul_def, NNReal.smul_def, + smul_eq_mul, smul_eq_mul, NNReal.coe_sub hc, NNReal.coe_one] + +/-- A mixture of two probability measures is a probability measure. -/ +lemma isProbabilityMeasure_mixture {μ ν : Measure ℝ} [IsProbabilityMeasure μ] + [IsProbabilityMeasure ν] {c : ℝ≥0} (hc : c ≤ 1) : + IsProbabilityMeasure (c • μ + (1 - c) • ν) := + ⟨by simpa using add_tsub_cancel_of_le (show (c : ℝ≥0∞) ≤ 1 by exact_mod_cast hc)⟩ + +/-- **Elicitable functionals have convex level sets** (Osband 1985; Gneiting 2011, Theorem 6). +If `T μ = T ν` and the mixture `c μ + (1 − c) ν` lies in `C`, then `T` takes the same value on the +mixture: the common minimizer of the two expected scores minimizes their mixture, and the +minimizer of the mixed expected score is unique. -/ +theorem StrictlyElicits.apply_mixture (hS : StrictlyElicits S T C) {μ ν : Measure ℝ} + (hμ : μ ∈ C) (hν : ν ∈ C) {c : ℝ≥0} (hc : c ≤ 1) (hm : c • μ + (1 - c) • ν ∈ C) + (hμν : T μ = T ν) : T (c • μ + (1 - c) • ν) = T μ := by + by_contra hne + obtain ⟨hμi, hμlt⟩ := hS μ hμ + obtain ⟨hνi, hνlt⟩ := hS ν hν + have h1 := (hμlt _ hne).le + have h2 := (hνlt _ (hμν ▸ hne)).le + have h3 := (hS _ hm).2 _ (Ne.symm hne) + rw [← hμν] at h2 + rw [integral_mixture (hμi _) (hνi _) hc, integral_mixture (hμi _) (hνi _) hc] at h3 + have hc1 : (0 : ℝ) ≤ 1 - c := sub_nonneg.2 (by exact_mod_cast hc) + nlinarith [mul_le_mul_of_nonneg_left h1 c.coe_nonneg, mul_le_mul_of_nonneg_left h2 hc1] + +/-- An elicitable functional has convex level sets. -/ +theorem IsElicitable.apply_mixture (hT : IsElicitable T C) {μ ν : Measure ℝ} (hμ : μ ∈ C) + (hν : ν ∈ C) {c : ℝ≥0} (hc : c ≤ 1) (hm : c • μ + (1 - c) • ν ∈ C) (hμν : T μ = T ν) : + T (c • μ + (1 - c) • ν) = T μ := + hT.choose_spec.apply_mixture hμ hν hc hm hμν + +/-! ### The pinball loss and the Rockafellar–Uryasev objective -/ + +/-- The **pinball loss** at level `α`, the score of a quantile forecast `x` against a realized loss +`y`: `S_α(x, y) = (1 − α)(x − y)⁺ + α (y − x)⁺`. -/ +noncomputable def pinballLoss (α x y : ℝ) : ℝ := + (1 - α) * max (x - y) 0 + α * max (y - x) 0 + +/-- The pinball loss in its textbook form `(𝟙{y ≤ x} − α)(x − y)`. -/ +lemma pinballLoss_eq_ite (α x y : ℝ) : + pinballLoss α x y = ((if y ≤ x then 1 else 0) - α) * (x - y) := by + unfold pinballLoss + split_ifs with h + · rw [max_eq_left (sub_nonneg.2 h), max_eq_right (sub_nonpos.2 h)] + ring + · rw [max_eq_right (sub_nonpos.2 (not_le.1 h).le), max_eq_left (sub_nonneg.2 (not_le.1 h).le)] + ring + +/-- The pinball loss is the shortfall `(y − x)⁺` plus a function affine in `(x, y)`. -/ +lemma pinballLoss_eq_max_add (α x y : ℝ) : + pinballLoss α x y = max (y - x) 0 + (1 - α) * x - (1 - α) * y := by + unfold pinballLoss + rcases le_total y x with h | h + · rw [max_eq_left (sub_nonneg.2 h), max_eq_right (sub_nonpos.2 h)] + ring + · rw [max_eq_right (sub_nonpos.2 h), max_eq_left (sub_nonneg.2 h)] + ring + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + {X : Ω → ℝ} {α : ℝ} + +/-- **The expected pinball loss is the Rockafellar–Uryasev objective**, rescaled: +`E[S_α(x, X)] = (1 − α)·(x + (1 − α)⁻¹ E[(X − x)⁺]) − (1 − α)·E[X]`. -/ +theorem integral_pinballLoss (hX : Integrable X P) (hα : α ∈ Ioo 0 1) (x : ℝ) : + ∫ ω, pinballLoss α x (X ω) ∂P = + (1 - α) * rockafellarUryasev X P α x - (1 - α) * ∫ ω, X ω ∂P := by + have h1α : 1 - α ≠ 0 := (sub_pos.2 hα.2).ne' + have hpos : Integrable (fun ω ↦ max (X ω - x) 0) P := (hX.sub (integrable_const x)).pos_part + have h1 : Integrable (fun ω ↦ max (X ω - x) 0 + (1 - α) * x) P := hpos.add (integrable_const _) + have h2 : Integrable (fun ω ↦ (1 - α) * X ω) P := hX.const_mul _ + simp_rw [pinballLoss_eq_max_add] + rw [integral_sub h1 h2, + integral_add hpos (integrable_const _), integral_const, integral_const_mul, rockafellarUryasev, + probReal_univ, one_smul, mul_add, mul_inv_cancel_left₀ h1α] + ring + +/-- **VaR minimizes the expected pinball loss**: the Rockafellar–Uryasev theorem, rescaled. -/ +theorem integral_pinballLoss_valueAtRisk_le (hX : Integrable X P) (hα : α ∈ Ioo 0 1) (x : ℝ) : + ∫ ω, pinballLoss α (valueAtRisk X P α) (X ω) ∂P ≤ ∫ ω, pinballLoss α x (X ω) ∂P := by + rw [integral_pinballLoss hX hα, integral_pinballLoss hX hα, rockafellarUryasev_valueAtRisk hX hα] + exact sub_le_sub_right (mul_le_mul_of_nonneg_left + (expectedShortfall_le_rockafellarUryasev hX hα x) (sub_pos.2 hα.2).le) _ + +/-- **The exact Rockafellar–Uryasev excess**: with `q(u) = VaR_u(X)`, +`g(c) − ES_α(X) = (1 − α)⁻¹ (∫_{(0, α]} (q(u) − c)⁺ du + ∫_{(α, 1)} (c − q(u))⁺ du)`. +The excess integrates the distance of the VaR curve from `c` over the levels on the wrong side +of `α`: levels below `α` whose quantile is above `c`, and levels above `α` whose quantile is +below `c`. -/ +theorem rockafellarUryasev_sub_expectedShortfall (hX : Integrable X P) (hα : α ∈ Ioo 0 1) + (c : ℝ) : + rockafellarUryasev X P α c - expectedShortfall X P α = + (1 - α)⁻¹ * ((∫ u in Ioc 0 α, max (valueAtRisk X P u - c) 0) + + ∫ u in Ioo α 1, max (c - valueAtRisk X P u) 0) := by + have h1α : 0 < 1 - α := sub_pos.2 hα.2 + have hq : IntegrableOn (fun u ↦ valueAtRisk X P u) (Ioo α 1) := + (integrableOn_valueAtRisk hX).mono_set (Ioo_subset_Ioo_left hα.1.le) + have hpos := integrableOn_max_valueAtRisk_sub hX c + have hneg : IntegrableOn (fun u ↦ max (c - valueAtRisk X P u) 0) (Ioo α 1) := + ((integrableOn_const (by simp)).sub hq).pos_part + -- split `(0, 1)` at `α`, and on `(α, 1)` write `t⁺ = t + (−t)⁺` + have hqc : IntegrableOn (fun u ↦ valueAtRisk X P u - c) (Ioo α 1) := + hq.sub (integrableOn_const (C := c) (by simp)) + have hsplit : ∫ u in Ioo 0 1, max (valueAtRisk X P u - c) 0 = + (∫ u in Ioc 0 α, max (valueAtRisk X P u - c) 0) + + ((∫ u in Ioo α 1, valueAtRisk X P u) - (1 - α) * c + + ∫ u in Ioo α 1, max (c - valueAtRisk X P u) 0) := by + rw [← Ioc_union_Ioo_eq_Ioo hα.1.le hα.2, setIntegral_union + (Ioc_disjoint_Ioi_same.mono_right Ioo_subset_Ioi_self) measurableSet_Ioo + (hpos.mono_set fun u hu ↦ ⟨hu.1, hu.2.trans_lt hα.2⟩) + (hpos.mono_set (Ioo_subset_Ioo_left hα.1.le))] + congr 1 + rw [setIntegral_congr_fun measurableSet_Ioo fun u _ ↦ + (show max (valueAtRisk X P u - c) 0 = + (valueAtRisk X P u - c) + max (c - valueAtRisk X P u) 0 by + rcases le_total c (valueAtRisk X P u) with h | h + · rw [max_eq_left (sub_nonneg.2 h), max_eq_right (sub_nonpos.2 h), add_zero] + · rw [max_eq_right (sub_nonpos.2 h), max_eq_left (sub_nonneg.2 h)]; ring), + integral_add hqc hneg, + integral_sub hq (integrableOn_const (by simp)), setIntegral_const, + Real.volume_real_Ioo_of_le hα.2.le, smul_eq_mul] + rw [rockafellarUryasev, integral_max_sub_eq_setIntegral_valueAtRisk hX.aemeasurable, hsplit, + expectedShortfall] + field_simp + ring + +/-- A nonnegative integrand that is at least `δ > 0` on a nondegenerate interval inside the +domain has a positive integral. -/ +lemma setIntegral_pos_of_ge_on_Ioo {f : ℝ → ℝ} {s : Set ℝ} (hf : IntegrableOn f s) + (hf0 : ∀ u ∈ s, 0 ≤ f u) {a b δ : ℝ} (hab : a < b) (hsub : Ioo a b ⊆ s) (hδ : 0 < δ) + (hfδ : ∀ u ∈ Ioo a b, δ ≤ f u) (hs : MeasurableSet s) : 0 < ∫ u in s, f u := by + calc (0 : ℝ) < ∫ _ in Ioo a b, δ := by + rw [setIntegral_const, Real.volume_real_Ioo_of_le hab.le, smul_eq_mul] + exact mul_pos (sub_pos.2 hab) hδ + _ ≤ ∫ u in Ioo a b, f u := + setIntegral_mono_on (integrableOn_const (by simp)) (hf.mono_set hsub) measurableSet_Ioo hfδ + _ ≤ ∫ u in s, f u := + setIntegral_mono_set hf ((ae_restrict_iff' hs).2 (ae_of_all _ hf0)) + (Filter.Eventually.of_forall fun _ h ↦ hsub h) + +/-- **VaR is the unique minimizer of the Rockafellar–Uryasev objective** when the `α`-quantile is +unique, i.e. the distribution function exceeds `α` right after `VaR_α(X)`. Below VaR the levels +`(P(X ≤ c), α]` have quantiles above `c`; above VaR the levels `(α, P(X ≤ x))` have quantiles at +most `x < c`. Either way the exact excess `rockafellarUryasev_sub_expectedShortfall` is positive. -/ +theorem expectedShortfall_lt_rockafellarUryasev (hX : Integrable X P) (hα : α ∈ Ioo 0 1) + (huniq : ∀ x, valueAtRisk X P α < x → α < P.real {ω | X ω ≤ x}) {c : ℝ} + (hc : c ≠ valueAtRisk X P α) : expectedShortfall X P α < rockafellarUryasev X P α c := by + have h1α : 0 < 1 - α := sub_pos.2 hα.2 + set q := valueAtRisk X P α + have hX' := hX.aemeasurable + have hlo : IntegrableOn (fun u ↦ max (valueAtRisk X P u - c) 0) (Ioc 0 α) := + (integrableOn_max_valueAtRisk_sub hX c).mono_set fun u hu ↦ ⟨hu.1, hu.2.trans_lt hα.2⟩ + have hhi : IntegrableOn (fun u ↦ max (c - valueAtRisk X P u) 0) (Ioo α 1) := + ((integrableOn_const (by simp)).sub + ((integrableOn_valueAtRisk hX).mono_set (Ioo_subset_Ioo_left hα.1.le))).pos_part + have hlo0 : 0 ≤ ∫ u in Ioc 0 α, max (valueAtRisk X P u - c) 0 := + setIntegral_nonneg measurableSet_Ioc fun _ _ ↦ le_max_right _ _ + have hhi0 : 0 ≤ ∫ u in Ioo α 1, max (c - valueAtRisk X P u) 0 := + setIntegral_nonneg measurableSet_Ioo fun _ _ ↦ le_max_right _ _ + have hpos : 0 < (∫ u in Ioc 0 α, max (valueAtRisk X P u - c) 0) + + ∫ u in Ioo α 1, max (c - valueAtRisk X P u) 0 := by + rcases hc.lt_or_gt with hcq | hcq + · -- below VaR: on `(P(X ≤ c'), α)` with `c < c' < q` the quantile is above `c'` + obtain ⟨c', hcc', hc'q⟩ := exists_between hcq + have hF : P.real {ω | X ω ≤ c'} < α := (lt_valueAtRisk_iff hX' hα).1 hc'q + have hF0 : 0 ≤ P.real {ω | X ω ≤ c'} := measureReal_nonneg + refine add_pos_of_pos_of_nonneg (setIntegral_pos_of_ge_on_Ioo + (a := max 0 (P.real {ω | X ω ≤ c'})) (b := α) hlo (fun _ _ ↦ le_max_right _ _) + (max_lt hα.1 hF) + (fun u hu ↦ ⟨(le_max_left 0 _).trans_lt hu.1, hu.2.le⟩) + (sub_pos.2 hcc') (fun u hu ↦ ?_) measurableSet_Ioc) hhi0 + have hu' : u ∈ Ioo 0 1 := ⟨(le_max_left 0 _).trans_lt hu.1, hu.2.trans hα.2⟩ + have : c' < valueAtRisk X P u := + (lt_valueAtRisk_iff hX' hu').2 ((le_max_right 0 _).trans_lt hu.1) + exact le_max_of_le_left (by linarith) + · -- above VaR: on `(α, P(X ≤ x))` with `q < x < c` the quantile is at most `x` + obtain ⟨x, hqx, hxc⟩ := exists_between hcq + have hF : α < P.real {ω | X ω ≤ x} := huniq x hqx + have hF1 : P.real {ω | X ω ≤ x} ≤ 1 := measureReal_le_one + refine add_pos_of_nonneg_of_pos hlo0 (setIntegral_pos_of_ge_on_Ioo (a := α) + (b := min (P.real {ω | X ω ≤ x}) 1) hhi + (fun _ _ ↦ le_max_right _ _) (lt_min hF hα.2) + (fun u hu ↦ ⟨hu.1, hu.2.trans_le (min_le_right _ _)⟩) (sub_pos.2 hxc) (fun u hu ↦ ?_) + measurableSet_Ioo) + have hu' : u ∈ Ioo 0 1 := ⟨hα.1.trans hu.1, hu.2.trans_le (min_le_right _ _)⟩ + have : valueAtRisk X P u ≤ x := + (valueAtRisk_le_iff hX' hu').2 (hu.2.trans_le (min_le_left _ _)).le + exact le_max_of_le_left (by linarith) + have := rockafellarUryasev_sub_expectedShortfall hX hα c + have : 0 < rockafellarUryasev X P α c - expectedShortfall X P α := by + rw [this]; exact mul_pos (inv_pos.2 h1α) hpos + linarith + +/-- **The pinball loss strictly elicits the `α`-quantile** on the laws with finite mean whose +`α`-quantile is unique: there the quantile is the unique minimizer of the expected pinball loss. -/ +theorem strictlyElicits_pinballLoss (hα : α ∈ Ioo 0 1) : + StrictlyElicits (pinballLoss α) (fun μ ↦ quantile μ α) + {μ | IsProbabilityMeasure μ ∧ Integrable id μ ∧ + ∀ x, quantile μ α < x → α < cdf μ x} := by + rintro μ ⟨hμ, hint, huniq⟩ + have hvar : valueAtRisk id μ α = quantile μ α := by rw [valueAtRisk, Measure.map_id] + refine ⟨fun x ↦ ?_, fun x hx ↦ ?_⟩ + · have hp : Integrable (fun y : ℝ ↦ max (y - x) 0) μ := (hint.sub (integrable_const x)).pos_part + rw [show pinballLoss α x = fun y ↦ max (y - x) 0 + (1 - α) * x - (1 - α) * y from + funext (pinballLoss_eq_max_add α x)] + exact (hp.add (integrable_const _)).sub (hint.const_mul _) + · have h := integral_pinballLoss (P := μ) (X := id) hint hα + simp only [id] at h + dsimp only + rw [h, h, ← hvar, rockafellarUryasev_valueAtRisk hint hα] + refine sub_lt_sub_right (mul_lt_mul_of_pos_left + (expectedShortfall_lt_rockafellarUryasev hint hα (fun y hy ↦ ?_) (hvar ▸ hx)) + (sub_pos.2 hα.2)) _ + rw [hvar] at hy + have h' := huniq y hy + rw [cdf_eq_real] at h' + exact h' + +/-! ### Expected shortfall is not elicitable -/ + +/-- A scaled point mass integrates every real function. -/ +lemma integrable_smul_dirac (f : ℝ → ℝ) (c : ℝ≥0) (a : ℝ) : + Integrable f (c • Measure.dirac a) := + (integrable_dirac eNorm_lt_top).smul_measure_nnreal + +/-- The integral against a scaled point mass is the scaled evaluation. -/ +lemma integral_smul_dirac (f : ℝ → ℝ) (c : ℝ≥0) (a : ℝ) : + ∫ y, f y ∂(c • Measure.dirac a) = c * f a := by + rw [integral_smul_nnreal_measure, integral_dirac, NNReal.smul_def, smul_eq_mul] + +/-- The two-point law `((1 + α)/2) δ₋₁ + ((1 − α)/2) δ₁`: at level `α` its expected shortfall is +`0`, the same as that of the point mass `δ₀`. -/ +noncomputable def esLevelWitness (α : ℝ) : Measure ℝ := + ((1 + α) / 2).toNNReal • Measure.dirac (-1) + ((1 - α) / 2).toNNReal • Measure.dirac 1 + +/-- The mixture `(1 − α) δ₀ + α · esLevelWitness α`, whose expected shortfall at level `α` is +`α/2`. -/ +noncomputable def esLevelMixture (α : ℝ) : Measure ℝ := + (1 - α).toNNReal • Measure.dirac 0 + (1 - (1 - α).toNNReal) • esLevelWitness α + +private lemma integrable_esLevelWitness (f : ℝ → ℝ) : Integrable f (esLevelWitness α) := + (integrable_smul_dirac f _ _).add_measure (integrable_smul_dirac f _ _) + +private lemma integral_esLevelWitness (hα : α ∈ Ioo 0 1) (f : ℝ → ℝ) : + ∫ y, f y ∂esLevelWitness α = (1 + α) / 2 * f (-1) + (1 - α) / 2 * f 1 := by + rw [esLevelWitness, integral_add_measure (integrable_smul_dirac f _ _) + (integrable_smul_dirac f _ _), integral_smul_dirac, integral_smul_dirac, + Real.coe_toNNReal _ (by linarith [hα.1]), Real.coe_toNNReal _ (by linarith [hα.2])] + +private lemma integral_esLevelMixture (hα : α ∈ Ioo 0 1) (f : ℝ → ℝ) : + ∫ y, f y ∂esLevelMixture α = + (1 - α) * f 0 + α * ((1 + α) / 2 * f (-1) + (1 - α) / 2 * f 1) := by + have hc : ((1 - (1 - α).toNNReal : ℝ≥0) : ℝ) = α := by + rw [NNReal.coe_sub (by simpa using hα.1.le), NNReal.coe_one, + Real.coe_toNNReal _ (by linarith [hα.2])] + ring + rw [esLevelMixture, integral_add_measure (integrable_smul_dirac f _ _) + (integrable_esLevelWitness f).smul_measure_nnreal, integral_smul_dirac, + integral_smul_nnreal_measure, integral_esLevelWitness hα, NNReal.smul_def, smul_eq_mul, hc, + Real.coe_toNNReal _ (by linarith [hα.2])] + +private lemma isProbabilityMeasure_esLevelWitness (hα : α ∈ Ioo 0 1) : + IsProbabilityMeasure (esLevelWitness α) := by + constructor + have h := integral_esLevelWitness hα fun _ ↦ (1 : ℝ) + rw [integral_const, smul_eq_mul, mul_one] at h + have h1 : (esLevelWitness α).real univ = 1 := by linarith + rw [measureReal_def, ENNReal.toReal_eq_one_iff] at h1 + exact h1 + +private lemma isProbabilityMeasure_esLevelMixture (hα : α ∈ Ioo 0 1) : + IsProbabilityMeasure (esLevelMixture α) := by + have := isProbabilityMeasure_esLevelWitness hα + exact isProbabilityMeasure_mixture (by simpa using hα.1.le) + +/-- An `ES_α` value is pinned by a Rockafellar–Uryasev threshold from above and an admissible +stress density from below. -/ +private lemma expectedShortfall_eq_of_bounds {μ : Measure ℝ} [IsProbabilityMeasure μ] + (hint : Integrable id μ) (hα : α ∈ Ioo 0 1) {v c : ℝ} {D : ℝ → ℝ} + (hc : rockafellarUryasev id μ α c ≤ v) (hD : Measurable D) (hD0 : ∀ y, 0 ≤ D y) + (hD1 : ∀ y, D y ≤ (1 - α)⁻¹) (hDint : ∫ y, D y ∂μ = 1) (hDv : v ≤ ∫ y, D y * y ∂μ) : + expectedShortfall id μ α = v := + le_antisymm ((expectedShortfall_le_rockafellarUryasev hint hα c).trans hc) + (hDv.trans (integral_mul_le_expectedShortfall hint hα hD.aestronglyMeasurable + (ae_of_all _ hD0) (ae_of_all _ hD1) hDint)) + +/-- `ES_α(δ₀) = 0`. -/ +lemma expectedShortfall_dirac_zero (hα : α ∈ Ioo 0 1) : + expectedShortfall id (Measure.dirac 0) α = 0 := + expectedShortfall_eq_of_bounds (integrable_dirac eNorm_lt_top) hα (c := 0) (D := fun _ ↦ 1) + (by simp [rockafellarUryasev]) measurable_const (fun _ ↦ zero_le_one) + (fun _ ↦ by rw [one_le_inv₀ (sub_pos.2 hα.2)]; linarith [hα.1]) (by simp) (by simp) + +/-- `ES_α` of the two-point witness is `0`. -/ +lemma expectedShortfall_esLevelWitness (hα : α ∈ Ioo 0 1) : + expectedShortfall id (esLevelWitness α) α = 0 := by + have := isProbabilityMeasure_esLevelWitness hα + have h1α : 0 < 1 - α := sub_pos.2 hα.2 + have h1a : 1 + α ≠ 0 := by linarith [hα.1] + have hβ : (1 + α)⁻¹ ≤ (1 - α)⁻¹ := inv_anti₀ h1α (by linarith [hα.1]) + refine expectedShortfall_eq_of_bounds (integrable_esLevelWitness _) hα (c := -1) + (D := fun y ↦ if 0 < y then (1 - α)⁻¹ else (1 + α)⁻¹) ?_ + (Measurable.ite (measurableSet_lt measurable_const measurable_id) measurable_const + measurable_const) + (fun y ↦ by split_ifs; exacts [(inv_pos.2 h1α).le, inv_nonneg.2 (by linarith [hα.1])]) + (fun y ↦ by split_ifs; exacts [le_rfl, hβ]) ?_ ?_ + · rw [rockafellarUryasev, integral_esLevelWitness hα] + norm_num + rw [inv_mul_cancel₀ h1α.ne'] + · rw [integral_esLevelWitness hα] + norm_num + field_simp + ring + · rw [integral_esLevelWitness hα] + norm_num + apply le_of_eq + field_simp + +/-- `ES_α` of the mixture `(1 − α) δ₀ + α · esLevelWitness α` is `α/2`. -/ +lemma expectedShortfall_esLevelMixture (hα : α ∈ Ioo 0 1) : + expectedShortfall id (esLevelMixture α) α = α / 2 := by + have := isProbabilityMeasure_esLevelMixture hα + have h1α : 0 < 1 - α := sub_pos.2 hα.2 + have hγ : (1 - α / 2) / (1 - α) ≤ (1 - α)⁻¹ := by + rw [div_eq_mul_inv] + exact mul_le_of_le_one_left (inv_nonneg.2 h1α.le) (by linarith [hα.1]) + have hγ0 : 0 ≤ (1 - α / 2) / (1 - α) := div_nonneg (by linarith [hα.2]) h1α.le + refine expectedShortfall_eq_of_bounds (μ := esLevelMixture α) + ((integrable_smul_dirac id _ _).add_measure (integrable_esLevelWitness id).smul_measure_nnreal) + hα (c := 0) + (D := fun y ↦ if 0 < y then (1 - α)⁻¹ else if y < 0 then 0 else (1 - α / 2) / (1 - α)) ?_ + (Measurable.ite (measurableSet_lt measurable_const measurable_id) measurable_const + (Measurable.ite (measurableSet_lt measurable_id measurable_const) measurable_const + measurable_const)) + (fun y ↦ by split_ifs; exacts [(inv_pos.2 h1α).le, le_rfl, hγ0]) + (fun y ↦ by split_ifs; exacts [le_rfl, inv_nonneg.2 h1α.le, hγ]) ?_ ?_ + · rw [rockafellarUryasev, integral_esLevelMixture hα] + norm_num + apply le_of_eq + field_simp + · rw [integral_esLevelMixture hα] + norm_num + field_simp + ring + · rw [integral_esLevelMixture hα] + norm_num + apply le_of_eq + field_simp + +/-- **Expected shortfall is not elicitable** (Gneiting 2011): for every `α ∈ (0, 1)`, no scoring +function elicits `ES_α` on a class of laws containing `δ₀`, `esLevelWitness α` and their mixture +`esLevelMixture α`. The two laws share `ES_α = 0` while the mixture has `ES_α = α/2`, so the level +set `{ES_α = 0}` is not convex (`IsElicitable.apply_mixture`). -/ +theorem not_isElicitable_expectedShortfall (hα : α ∈ Ioo 0 1) {C : Set (Measure ℝ)} + (h0 : Measure.dirac 0 ∈ C) (hW : esLevelWitness α ∈ C) (hM : esLevelMixture α ∈ C) : + ¬ IsElicitable (fun μ ↦ expectedShortfall id μ α) C := fun hT ↦ by + have h := hT.apply_mixture h0 hW (c := (1 - α).toNNReal) (by simpa using hα.1.le) hM + (by rw [expectedShortfall_dirac_zero hα, expectedShortfall_esLevelWitness hα]) + rw [show (1 - α).toNNReal • Measure.dirac 0 + (1 - (1 - α).toNNReal) • esLevelWitness α = + esLevelMixture α from rfl, expectedShortfall_esLevelMixture hα, + expectedShortfall_dirac_zero hα] at h + linarith [hα.1] + +/-- `ES_α` is not elicitable on the laws with finite mean. -/ +theorem not_isElicitable_expectedShortfall_integrable (hα : α ∈ Ioo 0 1) : + ¬ IsElicitable (fun μ ↦ expectedShortfall id μ α) + {μ | IsProbabilityMeasure μ ∧ Integrable id μ} := + not_isElicitable_expectedShortfall hα ⟨inferInstance, integrable_dirac eNorm_lt_top⟩ + ⟨isProbabilityMeasure_esLevelWitness hα, integrable_esLevelWitness _⟩ + ⟨isProbabilityMeasure_esLevelMixture hα, + (integrable_smul_dirac id _ _).add_measure (integrable_esLevelWitness id).smul_measure_nnreal⟩ + +end MathFin diff --git a/LeanPool/MathFin/Risk/EntropicRisk.lean b/LeanPool/MathFin/Risk/EntropicRisk.lean new file mode 100644 index 0000000000..f2968645dc --- /dev/null +++ b/LeanPool/MathFin/Risk/EntropicRisk.lean @@ -0,0 +1,219 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.LawInvariance +public import LeanPool.MathFin.Risk.UtilityDerivation +public import Mathlib.Probability.ProbabilityMassFunction.Constructions + +/-! +# Entropic risk: the certainty equivalent of exponential utility + +The **entropic risk measure** of a loss `X` with risk aversion `γ > 0` is +`ρ_γ(X) = γ⁻¹ log E[exp (γ X)]`. It is the cash amount an agent with exponential utility +`u(x) = −exp (−γ x)` is indifferent to paying instead of bearing the loss: the position `−X` is +acceptable under `u` at wealth `0` exactly when `ρ_γ(X) ≤ 0` (`acceptableUnderUtility_exp_iff`). +This is the joint of the choice limb with the risk limb: the acceptance set of `UtilityDerivation`, +for the exponential utility, is the acceptance set of the entropic risk measure. + +The entropic risk measure is the standard example of a **convex risk measure that is not coherent** +(`isConvexRiskMeasure_entropicRisk`, `not_isCoherentRiskMeasure_entropicRisk`): convexity is Hölder +(weighted AM-GM under the expectation), and positive homogeneity fails because `ρ_γ(c X)` is the +entropic risk at aversion `c γ`, not `c ρ_γ(X)`. It is law invariant +(`isLawInvariant_entropicRisk`). + +The convexity and acceptance statements are made on a finite state space with a probability +measure, where every loss is integrable and `exp (γ X)` is too: on a general space `E[exp (γ X)]` +may be infinite, which Lean's Bochner integral reads as `0`, so convexity on all integrable +losses would be a statement about that junk value. The acceptance statement is made +against `acceptableUnderUtility`, which works on finite weights `p i = P {i}`. + +## Main definitions + +* `entropicRisk`: `ρ_γ(X) = γ⁻¹ log E[exp (γ X)]`. + +## Main results + +* `isConvexRiskMeasure_entropicRisk`: on a finite probability space, `ρ_γ` is a convex risk measure. +* `not_isCoherentRiskMeasure_entropicRisk`: it is not coherent: positive homogeneity fails on a + fair coin. +* `acceptableUnderUtility_exp_iff`: the position `−L` is acceptable under exponential utility at + wealth `0` iff `ρ_γ(L) ≤ 0`. +* `isLawInvariant_entropicRisk`: `ρ_γ` depends on the loss only through its law. + +## References + +* [H. Föllmer and A. Schied, *Convex measures of risk and trading constraints*][FollmerSchied2002] +* [H. Föllmer and A. Schied, *Stochastic Finance: An Introduction in Discrete + Time*][FollmerSchied], §4.9 + +## Tags + +entropic risk, certainty equivalent, exponential utility, convex risk measure, acceptance set, +Hölder inequality, MSC 91G70, MSC 91B16, JEL G32, JEL D81 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory Real + +/-- The **entropic risk** of a loss `X` at risk aversion `γ`: `γ⁻¹ log E[exp (γ X)]`. -/ +noncomputable def entropicRisk {Ω : Type*} [MeasurableSpace Ω] (X : Ω → ℝ) (P : Measure Ω) + (γ : ℝ) : ℝ := + γ⁻¹ * log (∫ ω, exp (γ * X ω) ∂P) + +/-- **Entropic risk is law invariant**: `E[exp (γ X)]` is an integral against the law of `X`. -/ +theorem isLawInvariant_entropicRisk {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} (γ : ℝ) : + IsLawInvariant P fun X ↦ entropicRisk X P γ := by + have key {X : Ω → ℝ} (hX : AEMeasurable X P) : + ∫ ω, exp (γ * X ω) ∂P = ∫ x, exp (γ * x) ∂(P.map X) := + (integral_map (f := fun x ↦ exp (γ * x)) hX + (Continuous.aestronglyMeasurable (by fun_prop))).symm + intro X Y hX hY h + simp only [entropicRisk, key hX, key hY, h] + +/-- The weighted AM-GM step of the Hölder inequality, normalised by `A` and `B`. -/ +lemma rpow_mul_rpow_le {A B s t a b : ℝ} (hA : 0 < A) (hB : 0 < B) (hs : 0 < s) (ht : 0 < t) + (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : + s ^ a * t ^ b ≤ A ^ a * B ^ b * (a * (s / A) + b * (t / B)) := by + have h := Real.geom_mean_le_arith_mean2_weighted ha hb (div_pos hs hA).le (div_pos ht hB).le hab + rw [Real.div_rpow hs.le hA.le, Real.div_rpow ht.le hB.le] at h + have hA' := Real.rpow_pos_of_pos hA a + have hB' := Real.rpow_pos_of_pos hB b + calc s ^ a * t ^ b = A ^ a * B ^ b * (s ^ a / A ^ a * (t ^ b / B ^ b)) := by field_simp + _ ≤ _ := mul_le_mul_of_nonneg_left h (by positivity) + +section Finite + +variable {ι : Type*} [Fintype ι] [MeasurableSpace ι] [MeasurableSingletonClass ι] + {P : Measure ι} [IsProbabilityMeasure P] {γ : ℝ} {X Y : ι → ℝ} + +omit [Fintype ι] in +lemma integral_exp_mul_pos (γ : ℝ) (X : ι → ℝ) [Finite ι] : 0 < ∫ ω, exp (γ * X ω) ∂P := + integral_exp_pos (f := fun ω ↦ γ * X ω) .of_finite + +omit [Fintype ι] in +/-- Entropic risk is monotone. -/ +theorem entropicRisk_mono [Finite ι] (hγ : 0 < γ) (h : X ≤ᵐ[P] Y) : + entropicRisk X P γ ≤ entropicRisk Y P γ := by + have := integral_mono_ae (μ := P) .of_finite .of_finite + (h.mono fun ω hω ↦ Real.exp_le_exp.2 (mul_le_mul_of_nonneg_left hω hγ.le)) + exact mul_le_mul_of_nonneg_left (Real.log_le_log (integral_exp_mul_pos γ X) this) + (inv_nonneg.2 hγ.le) + +omit [Fintype ι] in +/-- Entropic risk is cash invariant: `ρ_γ(X + m) = ρ_γ(X) + m`. -/ +theorem entropicRisk_add_const [Finite ι] (hγ : 0 < γ) (X : ι → ℝ) (m : ℝ) : + entropicRisk (fun ω ↦ X ω + m) P γ = entropicRisk X P γ + m := by + have e (ω : ι) : exp (γ * (X ω + m)) = exp (γ * m) * exp (γ * X ω) := by + rw [← Real.exp_add]; congr 1; ring + simp only [entropicRisk, e, integral_const_mul] + rw [Real.log_mul (exp_pos _).ne' (integral_exp_mul_pos γ X).ne', Real.log_exp] + field_simp + ring + +omit [Fintype ι] in +/-- Entropic risk is convex: Hölder's inequality `E[e^{γ(aX + bY)}] ≤ E[e^{γX}]^a E[e^{γY}]^b` +under the logarithm. -/ +theorem entropicRisk_convex [Finite ι] (hγ : 0 < γ) {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) + (hab : a + b = 1) (X Y : ι → ℝ) : + entropicRisk (fun ω ↦ a * X ω + b * Y ω) P γ ≤ + a * entropicRisk X P γ + b * entropicRisk Y P γ := by + have hA := integral_exp_mul_pos (P := P) γ X + have hB := integral_exp_mul_pos (P := P) γ Y + set A := ∫ ω, exp (γ * X ω) ∂P + set B := ∫ ω, exp (γ * Y ω) ∂P + have pt (ω : ι) : exp (γ * (a * X ω + b * Y ω)) ≤ + A ^ a * B ^ b * (a * (exp (γ * X ω) / A) + b * (exp (γ * Y ω) / B)) := by + refine le_of_eq_of_le ?_ (rpow_mul_rpow_le hA hB (exp_pos (γ * X ω)) (exp_pos (γ * Y ω)) + ha hb hab) + rw [← Real.exp_mul, ← Real.exp_mul, ← Real.exp_add]; congr 1; ring + have hint : ∫ ω, exp (γ * (a * X ω + b * Y ω)) ∂P ≤ A ^ a * B ^ b := by + refine (integral_mono .of_finite .of_finite pt).trans_eq ?_ + rw [integral_const_mul, integral_add .of_finite .of_finite, integral_const_mul, + integral_const_mul, integral_div, integral_div, div_self hA.ne', div_self hB.ne'] + rw [mul_one, mul_one, hab, mul_one] + have hl := Real.log_le_log (integral_exp_mul_pos (P := P) γ (fun ω ↦ a * X ω + b * Y ω)) hint + rw [Real.log_mul (Real.rpow_pos_of_pos hA a).ne' (Real.rpow_pos_of_pos hB b).ne', + Real.log_rpow hA, Real.log_rpow hB] at hl + calc entropicRisk (fun ω ↦ a * X ω + b * Y ω) P γ + ≤ γ⁻¹ * (a * log A + b * log B) := + mul_le_mul_of_nonneg_left hl (inv_nonneg.2 hγ.le) + _ = a * entropicRisk X P γ + b * entropicRisk Y P γ := by simp only [entropicRisk, A, B]; ring + +omit [Fintype ι] in +/-- **Entropic risk is a convex risk measure** on a finite probability space. -/ +theorem isConvexRiskMeasure_entropicRisk [Finite ι] (hγ : 0 < γ) : + IsConvexRiskMeasure P fun X ↦ entropicRisk X P γ where + mono _ _ _ _ h := entropicRisk_mono hγ h + add_const _ _ m := entropicRisk_add_const hγ _ m + convexOn := ⟨fun _ _ _ _ _ _ _ _ _ ↦ .of_finite, fun X _ Y _ _ _ ha hb hab ↦ + entropicRisk_convex hγ ha hb hab X Y⟩ + +/-- **Acceptance under exponential utility is entropic risk at most zero.** On a finite +probability space with the weights `p i = P {i}`, the position `−L` is acceptable under the +exponential utility `u(x) = −exp (−γ x)` at wealth `0` (`acceptableUnderUtility`) exactly when +the entropic risk `ρ_γ(L)` of the loss `L` is nonpositive. -/ +theorem acceptableUnderUtility_exp_iff (hγ : 0 < γ) (L : ι → ℝ) : + acceptableUnderUtility Finset.univ (fun i ↦ P.real {i}) (fun x ↦ -exp (-γ * x)) 0 (-L) ↔ + entropicRisk L P γ ≤ 0 := by + have hE : ∫ ω, exp (γ * L ω) ∂P = ∑ i, P.real {i} * exp (γ * L i) := by + rw [integral_fintype .of_finite]; simp only [smul_eq_mul] + have hpos := integral_exp_mul_pos (P := P) γ L + have e (i : ι) : P.real {i} * -exp (-γ * (0 + (-L) i)) = -(P.real {i} * exp (γ * L i)) := by + rw [mul_neg]; congr 3; simp only [Pi.neg_apply, zero_add]; ring + simp only [acceptableUnderUtility, expectedUtility] + simp only [e, Finset.sum_neg_distrib, mul_zero, Real.exp_zero, ← hE, neg_le_neg_iff] + simp only [entropicRisk] + generalize ∫ ω, exp (γ * L ω) ∂P = I at hpos ⊢ + have hlog : log I ≤ 0 ↔ I ≤ 1 := by simpa using Real.log_le_log_iff hpos one_pos + rw [← hlog] + refine ⟨fun h ↦ mul_nonpos_of_nonneg_of_nonpos (inv_nonneg.2 hγ.le) h, fun h ↦ ?_⟩ + by_contra hc + exact absurd h (not_le.2 (mul_pos (inv_pos.2 hγ) (not_le.1 hc))) + +end Finite + +/-- **Entropic risk is convex and not coherent.** On a fair coin, the entropic risk of the loss +`(2, 0)` is not twice that of `(1, 0)`: positive homogeneity fails for every `γ > 0`. -/ +theorem not_isCoherentRiskMeasure_entropicRisk {γ : ℝ} (hγ : 0 < γ) : + ∃ (P : Measure (Fin 2)) (_ : IsProbabilityMeasure P), + ¬ IsCoherentRiskMeasure P fun X ↦ entropicRisk X P γ := by + let p : PMF (Fin 2) := PMF.ofFintype (fun _ ↦ (2 : ENNReal)⁻¹) (by + rw [Fin.sum_univ_two, ENNReal.inv_two_add_inv_two]) + refine ⟨p.toMeasure, inferInstance, fun h ↦ ?_⟩ + have hw (i : Fin 2) : (p.toMeasure).real {i} = 1 / 2 := by + rw [measureReal_def, PMF.toMeasure_apply_singleton _ _ (measurableSet_singleton i)] + simp [p] + have key (a b : ℝ) : entropicRisk (![a, b] : Fin 2 → ℝ) p.toMeasure γ = + γ⁻¹ * log ((exp (γ * a) + exp (γ * b)) / 2) := by + rw [entropicRisk, integral_fintype .of_finite] + simp only [Fin.sum_univ_two, hw, smul_eq_mul] + simp only [Matrix.cons_val_zero, Matrix.cons_val_one] + congr 2; ring + have h2 : entropicRisk (![2, 0] : Fin 2 → ℝ) p.toMeasure γ = + 2 * entropicRisk (![1, 0] : Fin 2 → ℝ) p.toMeasure γ := by + have := h.const_mul (X := ![1, 0]) .of_finite (c := 2) (by norm_num) + rw [show (fun ω ↦ 2 * (![1, 0] : Fin 2 → ℝ) ω) = ![2, 0] by + ext i; fin_cases i <;> simp] at this + exact this + rw [key, key] at h2 + simp only [mul_zero, Real.exp_zero, mul_one] at h2 + have hu : exp (γ * 2) = exp γ * exp γ := by rw [← Real.exp_add]; ring_nf + have hu1 : 1 < exp γ := by linarith [Real.add_one_lt_exp hγ.ne'] + rw [hu] at h2 + have h3 : log ((exp γ ^ 2 + 1) / 2) = 2 * log ((exp γ + 1) / 2) := by + field_simp at h2; linarith + have h4 := Real.log_injOn_pos (Set.mem_Ioi.2 (by positivity)) (Set.mem_Ioi.2 (by positivity)) + (h3.trans (by rw [Real.log_pow]; norm_num) : log ((exp γ ^ 2 + 1) / 2) = + log (((exp γ + 1) / 2) ^ 2)) + nlinarith [mul_pos (sub_pos.2 hu1) (sub_pos.2 hu1)] + +end MathFin diff --git a/LeanPool/MathFin/Risk/EquicorrelationConcentration.lean b/LeanPool/MathFin/Risk/EquicorrelationConcentration.lean new file mode 100644 index 0000000000..c34d8d256c --- /dev/null +++ b/LeanPool/MathFin/Risk/EquicorrelationConcentration.lean @@ -0,0 +1,136 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.Concentration +public import LeanPool.MathFin.Choice.Portfolio.MarkowitzNAsset + +/-! +# Equicorrelated variance is concentration plus a systematic floor + +For a covariance kernel with a common variance `v` and a common pairwise covariance `ρ v` +(`σᵢᵢ = v`, and `σᵢⱼ = ρ v` for `i ≠ j`), the Markowitz portfolio variance splits as + + `Var(w) = v · ((1 − ρ) · HHI(w) + ρ · (∑ wᵢ)²)` + +(`portfolioVarN_equicorrelated_eq_herfindahl`). For fully invested weights (`∑ wᵢ = 1`) this +reads `Var(w) = v · ((1 − ρ) · HHI(w) + ρ)` (`portfolioVarN_equicorrelated_of_sum_eq_one`). + +* The diversifiable part `(1 − ρ) v · HHI(w)` is the Herfindahl–Hirschman concentration of the + weights. Since `HHI ≥ 1/n` on a fully invested portfolio (`herfindahl_card_inv_le_of_sum_one`), + for `ρ ≤ 1` no fully invested portfolio has variance below `v ((1 − ρ)/n + ρ)` + (`portfolioVarN_equicorrelated_ge`), and equal weights attain it + (`portfolioVarN_equicorrelated_equal_weights`). +* The systematic part `ρ v` does not depend on the weights at all. For `v ≥ 0` and `ρ ≤ 1` no + fully invested portfolio, however diversified, has variance below `ρ v` + (`mul_le_portfolioVarN_equicorrelated`). + +The uncorrelated case `ρ = 0` is `Risk/ConcentrationVariance.lean` +(`portfolioVarN_diag_eq_herfindahl`): there the floor vanishes and variance is pure concentration. +The floor `ρ v` is the Markowitz face of the large-portfolio limit of the one-factor credit model +(`Risk/Credit/VasicekIRB.lean`): there too the idiosyncratic risk averages out and the factor risk +remains. A certified unification of two known textbook facts, not new finance. + +## Main results + +* `portfolioVarN_equicorrelated_eq_herfindahl`: `Var(w) = v ((1 − ρ) HHI(w) + ρ (∑ wᵢ)²)`. +* `portfolioVarN_equicorrelated_of_sum_eq_one`: `Var(w) = v ((1 − ρ) HHI(w) + ρ)` when fully + invested. +* `portfolioVarN_equicorrelated_ge`, `portfolioVarN_equicorrelated_equal_weights`: equal weights + minimize the variance of a fully invested equicorrelated portfolio (`ρ ≤ 1`, `v ≥ 0`). +* `mul_le_portfolioVarN_equicorrelated`: the systematic floor `ρ v ≤ Var(w)`. + +## References + +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 6.16 + +## Tags + +equicorrelation, Herfindahl index, minimum variance portfolio, systematic risk, diversification, +MSC 91G10, JEL G11 +-/ + +@[expose] public section + +namespace MathFin + +variable {ι : Type*} [DecidableEq ι] + +omit [DecidableEq ι] in +/-- **Equicorrelation × concentration bridge.** A kernel with common variance `v` and common +covariance `ρ v` ⇒ `Var(w) = v · ((1 − ρ) · HHI(w) + ρ · (∑ wᵢ)²)`. At `ρ = 0` this is +`portfolioVarN_diag_eq_herfindahl`. -/ +theorem portfolioVarN_equicorrelated_eq_herfindahl (s : Finset ι) (w : ι → ℝ) + (σ : ι → ι → ℝ) (v ρ : ℝ) (h_var : ∀ i ∈ s, σ i i = v) + (h_cov : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → σ i j = ρ * v) : + portfolioVarN s w σ = v * ((1 - ρ) * herfindahl s w + ρ * (∑ i ∈ s, w i) ^ 2) := by + classical + have hterm (i : ι) (hi : i ∈ s) (j : ι) (hj : j ∈ s) : w i * w j * σ i j = + ρ * v * (w i * w j) + (1 - ρ) * v * (if i = j then w i * w j else 0) := by + by_cases hij : i = j + · subst hij + rw [h_var i hi, ite_eq_left rfl] + ring + · rw [h_cov i hi j hj hij, ite_eq_right hij] + ring + have hdiag (i : ι) (hi : i ∈ s) : ∑ j ∈ s, (if i = j then w i * w j else 0) = w i ^ 2 := by + rw [Finset.sum_ite_eq, ite_eq_left hi, sq] + calc portfolioVarN s w σ + = ∑ i ∈ s, ∑ j ∈ s, + (ρ * v * (w i * w j) + (1 - ρ) * v * (if i = j then w i * w j else 0)) := + Finset.sum_congr rfl fun i hi ↦ Finset.sum_congr rfl fun j hj ↦ hterm i hi j hj + _ = ρ * v * ∑ i ∈ s, ∑ j ∈ s, w i * w j + (1 - ρ) * v * ∑ i ∈ s, w i ^ 2 := by + simp only [Finset.sum_add_distrib, ← Finset.mul_sum] + rw [Finset.sum_congr rfl hdiag] + _ = v * ((1 - ρ) * herfindahl s w + ρ * (∑ i ∈ s, w i) ^ 2) := by + rw [herfindahl, sq (∑ i ∈ s, w i), Finset.sum_mul_sum] + ring + +variable {s : Finset ι} {w : ι → ℝ} {σ : ι → ι → ℝ} {v ρ : ℝ} + +omit [DecidableEq ι] in +/-- For fully invested weights the equicorrelated variance is `v · ((1 − ρ) · HHI(w) + ρ)`. -/ +theorem portfolioVarN_equicorrelated_of_sum_eq_one (h_var : ∀ i ∈ s, σ i i = v) + (h_cov : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → σ i j = ρ * v) (h_sum : ∑ i ∈ s, w i = 1) : + portfolioVarN s w σ = v * ((1 - ρ) * herfindahl s w + ρ) := by + rw [portfolioVarN_equicorrelated_eq_herfindahl s w σ v ρ h_var h_cov, h_sum, one_pow, mul_one] + +omit [DecidableEq ι] in +/-- **Equal weights are variance-minimal** under equicorrelation: for `v ≥ 0` and `ρ ≤ 1`, every +fully invested portfolio of `n` assets has `Var(w) ≥ v · ((1 − ρ)/n + ρ)`, because `HHI ≥ 1/n`. -/ +theorem portfolioVarN_equicorrelated_ge (h_var : ∀ i ∈ s, σ i i = v) + (h_cov : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → σ i j = ρ * v) (h_sum : ∑ i ∈ s, w i = 1) (hv : 0 ≤ v) + (hρ : ρ ≤ 1) : + v * ((1 - ρ) / s.card + ρ) ≤ portfolioVarN s w σ := by + have hH := herfindahl_card_inv_le_of_sum_one s w h_sum + have h1ρ : 0 ≤ 1 - ρ := sub_nonneg.2 hρ + rw [portfolioVarN_equicorrelated_of_sum_eq_one h_var h_cov h_sum, div_eq_mul_inv] + gcongr + +omit [DecidableEq ι] in +/-- Equal weights attain the bound of `portfolioVarN_equicorrelated_ge`: +`Var(1/n, …, 1/n) = v · ((1 − ρ)/n + ρ)`. -/ +theorem portfolioVarN_equicorrelated_equal_weights (h_var : ∀ i ∈ s, σ i i = v) + (h_cov : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → σ i j = ρ * v) (hs : s.Nonempty) : + portfolioVarN s (fun _ ↦ (s.card : ℝ)⁻¹) σ = v * ((1 - ρ) / s.card + ρ) := by + have hc : (s.card : ℝ) ≠ 0 := Nat.cast_ne_zero.2 hs.card_pos.ne' + rw [portfolioVarN_equicorrelated_eq_herfindahl s _ σ v ρ h_var h_cov, herfindahl] + simp only [Finset.sum_const, nsmul_eq_mul] + field_simp + +omit [DecidableEq ι] in +/-- **The systematic floor**: for `v ≥ 0` and `ρ ≤ 1`, no fully invested equicorrelated portfolio, +however diversified, has variance below `ρ v`. -/ +theorem mul_le_portfolioVarN_equicorrelated (h_var : ∀ i ∈ s, σ i i = v) + (h_cov : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → σ i j = ρ * v) (h_sum : ∑ i ∈ s, w i = 1) (hv : 0 ≤ v) + (hρ : ρ ≤ 1) : + ρ * v ≤ portfolioVarN s w σ := by + rw [portfolioVarN_equicorrelated_of_sum_eq_one h_var h_cov h_sum] + nlinarith [mul_nonneg hv (mul_nonneg (sub_nonneg.2 hρ) (herfindahl_nonneg s w))] + +end MathFin diff --git a/LeanPool/MathFin/Risk/ExpectedShortfall.lean b/LeanPool/MathFin/Risk/ExpectedShortfall.lean new file mode 100644 index 0000000000..364fdb4b4f --- /dev/null +++ b/LeanPool/MathFin/Risk/ExpectedShortfall.lean @@ -0,0 +1,489 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.ValueAtRisk +public import LeanPool.MathFin.Risk.AcceptanceSet +public import Mathlib.Topology.Separation.CompletelyRegular +public import Mathlib.Order.CompletePartialOrder + +/-! +# Expected shortfall is coherent: the Rockafellar–Uryasev theorem for every integrable loss + +For an integrable loss `X` and a level `α ∈ (0, 1)`, the **Rockafellar–Uryasev theorem** says that +expected shortfall is the minimum of the one-parameter objective + + `g(c) = c + (1 − α)⁻¹ E[(X − c)⁺]`, + +and that the minimum is attained at `c = VaR_α(X)` (`isLeast_rockafellarUryasev`, +`rockafellarUryasev_valueAtRisk`). The Gaussian case is `Risk/RockafellarUryasev.lean`; +this file proves it for every integrable loss, atoms included. + +The proof is the Gaussian file's pointwise certificate, moved to quantile coordinates. Under the +quantile transform `E[(X − c)⁺] = ∫₀¹ (q(u) − c)⁺ du` with `q = VaR_·(X)`, and pointwise + + `(q(u) − c)⁺ ≥ (q(u) − c) · 𝟙{u > α}`, + +which integrates to `g(c) ≥ ES_α(X)`. At `c = q(α)` the certificate is exact, because `q` is +monotone: the positive part vanishes on `(0, α]` and is the identity on `(α, 1)`. In quantile +coordinates an atom of `X` is a flat stretch of `q`, so the argument needs no case analysis +for atoms. + +**Coherence follows in one line per axiom** (`expectedShortfall_isCoherentRiskMeasure`). +Subadditivity, the axiom that value-at-risk fails (`Risk/VaRSuperadditivity.lean`), is +`(a + b)⁺ ≤ a⁺ + b⁺` inside the objective at `c = VaR_α(X) + VaR_α(Y)`. This is the result behind +the Basel III move of market-risk capital from `VaR₉₉` to `ES₉₇.₅`. + +**The dual representation** (`isGreatest_integral_mul_expectedShortfall`) says ES is a +worst-case expectation. `ES_α(X)` is the largest value of `E[D·X]` over densities +`0 ≤ D ≤ (1 − α)⁻¹` with `E[D] = 1`. The maximizer loads the tail event `{X > VaR_α(X)}`, plus the +fraction of the atom at `VaR_α(X)` needed to make up mass `1 − α`. The value +`ES_α(X) = (1 − α)⁻¹ (E[X·𝟙{X > q}] + q·(1 − α − P(X > q)))` at `q = VaR_α(X)` is the formula of +Acerbi and Tasche (`expectedShortfall_eq_acerbiTasche`). + +## Main definitions + +* `rockafellarUryasev`: the objective `c ↦ c + (1 − α)⁻¹ E[(X − c)⁺]` of a loss `X` at level + `α`. + +## Main results + +* `isLeast_rockafellarUryasev`: `ES_α(X)` is its minimum; `rockafellarUryasev_valueAtRisk`: the + minimum is attained at `VaR_α(X)`. +* `expectedShortfall_add_le`: subadditivity of ES. +* `expectedShortfall_isCoherentRiskMeasure`: ES is a coherent risk measure. +* `expectedShortfall_eq_acerbiTasche`: the Acerbi–Tasche formula. +* `expectedShortfall_eq_setIntegral_tail`: without atoms, ES is the mean of the `α`-tail. +* `isGreatest_integral_mul_expectedShortfall`: the dual representation of ES. +* `representingSet_expectedShortfall`: on a finite probability space the ADEH representing set of + ES is exactly the probability vectors `q` with `qᵢ ≤ (1 − α)⁻¹ P{i}`, the densities bounded by + `(1 − α)⁻¹`. +* `expectedShortfall_isLUB_representingSet`: on a finite probability space ES is a coherent risk + measure of `Risk/AcceptanceSet.lean`, so the finite representation theorem + `coherentRisk_isLUB` applies to it. + +## References + +* [C. Acerbi and D. Tasche, *On the coherence of expected shortfall*][AcerbiTasche2002] +* [P. Artzner et al., *Coherent measures of risk*][ArtznerDelbaenEberHeath1999] +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Proposition 8.13; Section 8.1; Section 8.1.3; Section 8.2 +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 2.6, 8.2(c); Ex. 8.19; Ex. 8.2(a); Ex. 8.2(b) +* [Rockafellar and Uryasev (2000)][RockafellarUryasev2000] +* [Rockafellar and Uryasev (2002)][RockafellarUryasev2002] + +## Tags + +expected shortfall, conditional VaR, Rockafellar-Uryasev, tail risk, Acerbi-Tasche, +coherent risk measure, Basel III, dual representation, MSC 91G70, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} {X Y : Ω → ℝ} {α : ℝ} + +/-- The **Rockafellar–Uryasev objective** of a loss `X` at level `α`: +`c ↦ c + (1 − α)⁻¹ E[(X − c)⁺]`. -/ +noncomputable def rockafellarUryasev (X : Ω → ℝ) (P : Measure Ω) (α c : ℝ) : ℝ := + c + (1 - α)⁻¹ * ∫ ω, max (X ω - c) 0 ∂P + +variable [IsProbabilityMeasure P] + +/-- The expected positive part of `X − c` in quantile coordinates: +`E[(X − c)⁺] = ∫₀¹ (VaR_u(X) − c)⁺ du`. -/ +lemma integral_max_sub_eq_setIntegral_valueAtRisk (hX : AEMeasurable X P) (c : ℝ) : + ∫ ω, max (X ω - c) 0 ∂P = ∫ u in Ioo 0 1, max (valueAtRisk X P u - c) 0 := by + calc ∫ ω, max (X ω - c) 0 ∂P = ∫ x, max (x - c) 0 ∂P.map X := + (integral_map (f := fun x ↦ max (x - c) 0) hX (by fun_prop)).symm + _ = ∫ u in Ioo 0 1, max (valueAtRisk X P u - c) 0 := + integral_eq_setIntegral_quantile (by fun_prop) + +/-- `u ↦ (VaR_u(X) − c)⁺` is integrable on `(0, 1)` for an integrable loss. -/ +lemma integrableOn_max_valueAtRisk_sub (hX : Integrable X P) (c : ℝ) : + IntegrableOn (fun u ↦ max (valueAtRisk X P u - c) 0) (Ioo 0 1) := + ((integrableOn_valueAtRisk hX).sub (integrableOn_const (by simp))).pos_part + +/-- The shortfall part of the objective, integrated over the tail levels: +`∫_α^1 (VaR_u(X) − c) du = ∫_α^1 VaR_u(X) du − (1 − α) c`. -/ +private lemma setIntegral_valueAtRisk_sub (hX : Integrable X P) (hα : α ∈ Ioo 0 1) (c : ℝ) : + ∫ u in Ioo α 1, (valueAtRisk X P u - c) = + (∫ u in Ioo α 1, valueAtRisk X P u) - (1 - α) * c := by + rw [integral_sub ((integrableOn_valueAtRisk hX).mono_set (Ioo_subset_Ioo_left hα.1.le)) + (integrableOn_const (by simp)), setIntegral_const, Real.volume_real_Ioo_of_le hα.2.le, + smul_eq_mul] + +/-- **The Rockafellar–Uryasev inequality**: `ES_α(X) ≤ c + (1 − α)⁻¹ E[(X − c)⁺]` for every +threshold `c`. The certificate `(q(u) − c)⁺ ≥ (q(u) − c)·𝟙{u > α}`, integrated over `(0, 1)`. -/ +theorem expectedShortfall_le_rockafellarUryasev (hX : Integrable X P) (hα : α ∈ Ioo 0 1) + (c : ℝ) : expectedShortfall X P α ≤ rockafellarUryasev X P α c := by + have h1α : 0 < 1 - α := sub_pos.2 hα.2 + have hcert : ∫ u in Ioo α 1, (valueAtRisk X P u - c) ≤ + ∫ u in Ioo 0 1, max (valueAtRisk X P u - c) 0 := + (setIntegral_mono_on + (((integrableOn_valueAtRisk hX).sub (integrableOn_const (by simp))).mono_set + (Ioo_subset_Ioo_left hα.1.le)) + ((integrableOn_max_valueAtRisk_sub hX c).mono_set (Ioo_subset_Ioo_left hα.1.le)) + measurableSet_Ioo fun _ _ ↦ le_max_left _ _).trans <| + setIntegral_mono_set (integrableOn_max_valueAtRisk_sub hX c) + (ae_of_all _ fun _ ↦ le_max_right _ _) + (Filter.Eventually.of_forall fun _ h ↦ Ioo_subset_Ioo_left hα.1.le h) + rw [setIntegral_valueAtRisk_sub hX hα] at hcert + rw [rockafellarUryasev, integral_max_sub_eq_setIntegral_valueAtRisk hX.aemeasurable, + expectedShortfall, inv_mul_le_iff₀ h1α, mul_add, mul_inv_cancel_left₀ h1α.ne'] + linarith + +/-- **The Rockafellar–Uryasev objective attains ES at VaR**: at `c = VaR_α(X)` the certificate is +exact, since the VaR curve lies below `VaR_α(X)` on `(0, α]` and above it on `(α, 1)`. -/ +theorem rockafellarUryasev_valueAtRisk (hX : Integrable X P) (hα : α ∈ Ioo 0 1) : + rockafellarUryasev X P α (valueAtRisk X P α) = expectedShortfall X P α := by + have h1α : 0 < 1 - α := sub_pos.2 hα.2 + set q := valueAtRisk X P α + have hsplit : ∫ u in Ioo 0 1, max (valueAtRisk X P u - q) 0 = + ∫ u in Ioo α 1, (valueAtRisk X P u - q) := by + rw [setIntegral_eq_of_subset_of_forall_sdiff_eq_zero measurableSet_Ioo + (Ioo_subset_Ioo_left hα.1.le) fun u hu ↦ max_eq_right <| sub_nonpos.2 <| + valueAtRisk_mono_level hu.1 hα (not_lt.1 fun h ↦ hu.2 ⟨h, hu.1.2⟩)] + exact setIntegral_congr_fun measurableSet_Ioo fun u hu ↦ max_eq_left <| sub_nonneg.2 <| + valueAtRisk_mono_level hα ⟨hα.1.trans hu.1, hu.2⟩ hu.1.le + rw [rockafellarUryasev, integral_max_sub_eq_setIntegral_valueAtRisk hX.aemeasurable, hsplit, + setIntegral_valueAtRisk_sub hX hα, expectedShortfall] + field_simp + ring + +/-- **The Rockafellar–Uryasev theorem** for an arbitrary integrable loss: `ES_α(X)` is the least +value of `c ↦ c + (1 − α)⁻¹ E[(X − c)⁺]`. The minimizer `c = VaR_α(X)` is named in +`rockafellarUryasev_valueAtRisk`. -/ +theorem isLeast_rockafellarUryasev (hX : Integrable X P) (hα : α ∈ Ioo 0 1) : + IsLeast (range (rockafellarUryasev X P α)) (expectedShortfall X P α) := + ⟨⟨_, rockafellarUryasev_valueAtRisk hX hα⟩, by + rintro _ ⟨c, rfl⟩ + exact expectedShortfall_le_rockafellarUryasev hX hα c⟩ + +/-! ### Coherence -/ + +/-- **Subadditivity of expected shortfall**: `ES_α(X + Y) ≤ ES_α(X) + ES_α(Y)`. Evaluate the +Rockafellar–Uryasev objective of `X + Y` at `VaR_α(X) + VaR_α(Y)` and split the positive part, +`(a + b)⁺ ≤ a⁺ + b⁺`. -/ +theorem expectedShortfall_add_le (hX : Integrable X P) (hY : Integrable Y P) + (hα : α ∈ Ioo 0 1) : + expectedShortfall (fun ω ↦ X ω + Y ω) P α ≤ + expectedShortfall X P α + expectedShortfall Y P α := by + have h1α : 0 < 1 - α := sub_pos.2 hα.2 + set a := valueAtRisk X P α + set b := valueAtRisk Y P α + have hXa : Integrable (fun ω ↦ max (X ω - a) 0) P := (hX.sub (integrable_const a)).pos_part + have hYb : Integrable (fun ω ↦ max (Y ω - b) 0) P := (hY.sub (integrable_const b)).pos_part + have hsplit : ∫ ω, max (X ω + Y ω - (a + b)) 0 ∂P ≤ + (∫ ω, max (X ω - a) 0 ∂P) + ∫ ω, max (Y ω - b) 0 ∂P := by + rw [← integral_add hXa hYb] + refine integral_mono (((hX.add hY).sub (integrable_const _)).pos_part) (hXa.add hYb) + fun ω ↦ ?_ + rw [max_le_iff] + exact ⟨by linarith [le_max_left (X ω - a) 0, le_max_left (Y ω - b) 0], + add_nonneg (le_max_right _ _) (le_max_right _ _)⟩ + calc expectedShortfall (fun ω ↦ X ω + Y ω) P α + ≤ rockafellarUryasev (fun ω ↦ X ω + Y ω) P α (a + b) := + expectedShortfall_le_rockafellarUryasev (hX.add hY) hα _ + _ ≤ rockafellarUryasev X P α a + rockafellarUryasev Y P α b := by + simp only [rockafellarUryasev] + have := mul_le_mul_of_nonneg_left hsplit (inv_nonneg.2 h1α.le) + linarith + _ = expectedShortfall X P α + expectedShortfall Y P α := by + rw [rockafellarUryasev_valueAtRisk hX hα, rockafellarUryasev_valueAtRisk hY hα] + +/-- **Expected shortfall is a coherent risk measure** on the integrable losses (Acerbi and Tasche +2002; McNeil–Frey–Embrechts, Proposition 8.13 context). -/ +theorem expectedShortfall_isCoherentRiskMeasure (hα : α ∈ Ioo 0 1) : + IsCoherentRiskMeasure P (fun X ↦ expectedShortfall X P α) where + mono _ _ hX hY hXY := expectedShortfall_mono hX hY hXY hα + add_const _ hX m := expectedShortfall_add_const hX hα m + const_mul _ hX _ hc := expectedShortfall_const_mul hX hα hc + add_le _ _ hX hY := expectedShortfall_add_le hX hY hα + +/-! ### The Acerbi–Tasche formula and the dual representation -/ + +/-- **The Acerbi–Tasche formula**: with `q = VaR_α(X)`, +`ES_α(X) = (1 − α)⁻¹ (E[X·𝟙{X > q}] + q·(1 − α − P(X > q)))`. The correction term is the part of +the atom at `q` that lies in the `α`-tail; it vanishes when `P(X = q) = 0`. -/ +theorem expectedShortfall_eq_acerbiTasche (hX : Integrable X P) (hα : α ∈ Ioo 0 1) : + expectedShortfall X P α = + (1 - α)⁻¹ * ((∫ ω in {ω | valueAtRisk X P α < X ω}, X ω ∂P) + + valueAtRisk X P α * (1 - α - P.real {ω | valueAtRisk X P α < X ω})) := by + have h1α : 0 < 1 - α := sub_pos.2 hα.2 + set q := valueAtRisk X P α + have hmeas : NullMeasurableSet {ω | q < X ω} P := + nullMeasurableSet_lt aemeasurable_const hX.aemeasurable + have hpos : ∫ ω, max (X ω - q) 0 ∂P = (∫ ω in {ω | q < X ω}, X ω ∂P) - + q * P.real {ω | q < X ω} := by + rw [show (fun ω ↦ max (X ω - q) 0) = {ω | q < X ω}.indicator (fun ω ↦ X ω - q) from + funext fun ω ↦ by + by_cases h : q < X ω + · rw [indicator_of_mem (show ω ∈ {ω | q < X ω} from h), + max_eq_left (sub_nonneg.2 h.le)] + · rw [indicator_of_notMem (show ω ∉ {ω | q < X ω} from h), + max_eq_right (sub_nonpos.2 (not_lt.1 h))], + integral_indicator₀ hmeas, integral_sub hX.integrableOn (integrableOn_const (by simp)), + setIntegral_const, smul_eq_mul, mul_comm] + rw [← rockafellarUryasev_valueAtRisk hX hα, rockafellarUryasev, hpos] + field_simp + ring + +/-- **Without atoms the `α`-tail has mass `1 − α`**: if the law of `X` has a continuous CDF, then +`P(X > VaR_α(X)) = 1 − α`. -/ +theorem measureReal_valueAtRisk_lt (hX : AEMeasurable X P) (hF : Continuous (cdf (P.map X))) + (hα : α ∈ Ioo 0 1) : P.real {ω | valueAtRisk X P α < X ω} = 1 - α := by + rw [show {ω | valueAtRisk X P α < X ω} = X ⁻¹' (Iic (valueAtRisk X P α))ᶜ by ext; simp, + ← map_measureReal_apply_of_aemeasurable hX measurableSet_Iic.compl, + probReal_compl_eq_one_sub measurableSet_Iic, ← cdf_eq_real, valueAtRisk, cdf_quantile hF hα] + +/-- **Without atoms ES is the mean of the tail**: if the law of `X` has a continuous CDF, the +correction term of `expectedShortfall_eq_acerbiTasche` vanishes and +`ES_α(X) = (1 − α)⁻¹ E[X·𝟙{X > VaR_α(X)}]`. The tail event has mass `1 − α` +(`measureReal_valueAtRisk_lt`), so this is the mean of `X` over it. -/ +theorem expectedShortfall_eq_setIntegral_tail (hX : Integrable X P) + (hF : Continuous (cdf (P.map X))) (hα : α ∈ Ioo 0 1) : + expectedShortfall X P α = (1 - α)⁻¹ * ∫ ω in {ω | valueAtRisk X P α < X ω}, X ω ∂P := by + rw [expectedShortfall_eq_acerbiTasche hX hα, measureReal_valueAtRisk_lt hX.aemeasurable hF hα] + ring + +/-- The mass strictly below the `α`-quantile is at most `α`: under the quantile transform, the +levels whose quantile lies below `quantile μ α` are levels below `α`. -/ +lemma measure_Iio_quantile_le {μ : Measure ℝ} [IsProbabilityMeasure μ] (hα : α ∈ Ioo 0 1) : + μ (Iio (quantile μ α)) ≤ ENNReal.ofReal α := + calc μ (Iio (quantile μ α)) + = volume.restrict (Ioo 0 1) {u | quantile μ u < quantile μ α} := + ((hasLaw_quantile μ).measure_eq (p := fun x ↦ x < quantile μ α) measurableSet_Iio).symm + _ = volume ({u | quantile μ u < quantile μ α} ∩ Ioo 0 1) := + Measure.restrict_apply' measurableSet_Ioo + _ ≤ volume (Ioo 0 α) := measure_mono fun u ⟨hu, hu01⟩ ↦ + ⟨hu01.1, lt_of_not_ge fun h ↦ (monotoneOn_quantile hα hu01 h).not_gt hu⟩ + _ = ENNReal.ofReal α := by simp + +/-- **ES dominates every stress expectation**: for a density `D` with `0 ≤ D ≤ (1 − α)⁻¹` and +`E[D] = 1`, `E[D·X] ≤ ES_α(X)`. Pointwise `D·X ≤ q·D + (1 − α)⁻¹ (X − q)⁺` with +`q = VaR_α(X)`, and the right side integrates to the Rockafellar–Uryasev objective at `q`. -/ +theorem integral_mul_le_expectedShortfall (hX : Integrable X P) (hα : α ∈ Ioo 0 1) + {D : Ω → ℝ} (hD : AEStronglyMeasurable D P) (hD0 : ∀ᵐ ω ∂P, 0 ≤ D ω) + (hD1 : ∀ᵐ ω ∂P, D ω ≤ (1 - α)⁻¹) (hDint : ∫ ω, D ω ∂P = 1) : + ∫ ω, D ω * X ω ∂P ≤ expectedShortfall X P α := by + set q := valueAtRisk X P α + have hbdd : ∀ᵐ ω ∂P, ‖D ω‖ ≤ (1 - α)⁻¹ := + (hD0.and hD1).mono fun ω h ↦ (Real.norm_of_nonneg h.1).trans_le h.2 + have hDi : Integrable D P := (integrable_const _).mono' hD hbdd + have hpos : Integrable (fun ω ↦ max (X ω - q) 0) P := (hX.sub (integrable_const q)).pos_part + calc ∫ ω, D ω * X ω ∂P ≤ ∫ ω, (q * D ω + (1 - α)⁻¹ * max (X ω - q) 0) ∂P := + integral_mono_ae (hX.bdd_mul hD hbdd) ((hDi.const_mul q).add (hpos.const_mul _)) <| + (hD0.and hD1).mono fun ω ⟨h0, h1⟩ ↦ by + nlinarith [mul_le_mul_of_nonneg_left (le_max_left (X ω - q) 0) h0, + mul_le_mul_of_nonneg_right h1 (le_max_right (X ω - q) 0)] + _ = rockafellarUryasev X P α q := by + rw [integral_add (hDi.const_mul q) (hpos.const_mul _), integral_const_mul, + integral_const_mul, hDint, mul_one, rockafellarUryasev] + _ = expectedShortfall X P α := rockafellarUryasev_valueAtRisk hX hα + +/-- **The ES-maximizing stress density** is a function of the loss: `(1 − α)⁻¹` on the tail +`{X > q}`, the fraction `β ∈ [0, 1]` of it on the atom `{X = q}` that completes the tail mass to +`1 − α`, and `0` below, where `q = VaR_α(X)`. It makes the pointwise bound of +`integral_mul_le_expectedShortfall` exact: `g(x)·(x − q) = (1 − α)⁻¹ (x − q)⁺` for every `x`. -/ +theorem exists_density_integral_mul_eq_expectedShortfall (hX : Integrable X P) + (hα : α ∈ Ioo 0 1) : + ∃ g : ℝ → ℝ, Measurable g ∧ (∀ x, 0 ≤ g x) ∧ (∀ x, g x ≤ (1 - α)⁻¹) ∧ + ∫ ω, g (X ω) ∂P = 1 ∧ ∫ ω, g (X ω) * X ω ∂P = expectedShortfall X P α := by + have h1α : 0 < 1 - α := sub_pos.2 hα.2 + set q := valueAtRisk X P α + -- the tail above `q` has mass at most `1 − α`, and with the atom at least `1 − α` + have ha : (P.map X).real (Ioi q) ≤ 1 - α := by + have hcdf : α ≤ (P.map X).real (Iic q) := (cdf_eq_real (P.map X) q) ▸ le_cdf_quantile hα + rw [← compl_Iic, probReal_compl_eq_one_sub measurableSet_Iic] + linarith + have hab : 1 - α ≤ (P.map X).real (Ioi q) + (P.map X).real {q} := by + have hlt : (P.map X).real (Iio q) ≤ α := + ENNReal.toReal_le_of_le_ofReal hα.1.le (measure_Iio_quantile_le hα) + have hunion : Ioi q ∪ {q} = (Iio q)ᶜ := by + ext x + simp only [mem_union, mem_Ioi, mem_singleton_iff, mem_compl_iff, mem_Iio, not_lt] + constructor + · rintro (h | rfl) + exacts [h.le, le_rfl] + · intro h + rcases h.lt_or_eq with h | h + exacts [Or.inl h, Or.inr h.symm] + rw [← measureReal_union (μ := P.map X) + (show Disjoint (Ioi q) {q} from disjoint_singleton_right.2 (lt_irrefl q)) + (measurableSet_singleton q), hunion, probReal_compl_eq_one_sub measurableSet_Iio] + linarith + obtain ⟨β, hβ0, hβ1, hβb⟩ : ∃ β : ℝ, 0 ≤ β ∧ β ≤ 1 ∧ + β * (P.map X).real {q} = 1 - α - (P.map X).real (Ioi q) := by + rcases (measureReal_nonneg (μ := P.map X) (s := {q})).lt_or_eq with hb | hb + · exact ⟨(1 - α - (P.map X).real (Ioi q)) / (P.map X).real {q}, + div_nonneg (by linarith) hb.le, (div_le_one hb).2 (by linarith), + div_mul_cancel₀ _ hb.ne'⟩ + · exact ⟨0, le_rfl, zero_le_one, by rw [zero_mul]; linarith⟩ + set g : ℝ → ℝ := fun x ↦ + (1 - α)⁻¹ * ((Ioi q).indicator 1 x + β * ({q} : Set ℝ).indicator 1 x) + have hg : Measurable g := measurable_const.mul <| + (measurable_one.indicator measurableSet_Ioi).add <| + measurable_const.mul (measurable_one.indicator (measurableSet_singleton q)) + have hsum (x : ℝ) : (Ioi q).indicator (1 : ℝ → ℝ) x + β * ({q} : Set ℝ).indicator 1 x ≤ 1 := by + rcases lt_trichotomy x q with h | rfl | h + · rw [indicator_of_notMem (show x ∉ Ioi q from not_lt.2 h.le), + indicator_of_notMem (show x ∉ ({q} : Set ℝ) from h.ne)] + simp + · rw [indicator_of_notMem (show q ∉ Ioi q from lt_irrefl q), + indicator_of_mem (mem_singleton q), Pi.one_apply] + linarith + · rw [indicator_of_mem (show x ∈ Ioi q from h), + indicator_of_notMem (show x ∉ ({q} : Set ℝ) from h.ne'), Pi.one_apply] + simp + have hg0 (x : ℝ) : 0 ≤ g x := mul_nonneg (inv_nonneg.2 h1α.le) <| + add_nonneg (indicator_nonneg (fun _ _ ↦ zero_le_one) _) + (mul_nonneg hβ0 (indicator_nonneg (fun _ _ ↦ zero_le_one) _)) + have hg1 (x : ℝ) : g x ≤ (1 - α)⁻¹ := mul_le_of_le_one_right (inv_nonneg.2 h1α.le) (hsum x) + -- the density makes the stress bound exact: `g x · (x − q) = (1 − α)⁻¹ (x − q)⁺` + have hgx (x : ℝ) : g x * (x - q) = (1 - α)⁻¹ * max (x - q) 0 := by + rcases lt_trichotomy x q with h | rfl | h + · rw [max_eq_right (sub_nonpos.2 h.le)] + simp only [g, indicator_of_notMem (show x ∉ Ioi q from not_lt.2 h.le), + indicator_of_notMem (show x ∉ ({q} : Set ℝ) from h.ne)] + ring + · simp + · rw [max_eq_left (sub_nonneg.2 h.le)] + simp only [g, indicator_of_mem (show x ∈ Ioi q from h), + indicator_of_notMem (show x ∉ ({q} : Set ℝ) from h.ne'), Pi.one_apply] + ring + have hgX : Integrable (fun ω ↦ g (X ω)) P := + (integrable_const (1 - α)⁻¹).mono' (hg.comp_aemeasurable hX.aemeasurable).aestronglyMeasurable + (ae_of_all _ fun ω ↦ (Real.norm_of_nonneg (hg0 _)).trans_le (hg1 _)) + have hgint : ∫ ω, g (X ω) ∂P = 1 := by + have h1 : Integrable ((Ioi q).indicator (1 : ℝ → ℝ)) (P.map X) := + (integrable_const (1 : ℝ)).indicator measurableSet_Ioi + have h2 : Integrable (({q} : Set ℝ).indicator (1 : ℝ → ℝ)) (P.map X) := + (integrable_const (1 : ℝ)).indicator (measurableSet_singleton q) + rw [← integral_map (f := g) hX.aemeasurable hg.aestronglyMeasurable] + simp only [g] + rw [integral_const_mul, integral_add h1 (h2.const_mul β), integral_const_mul, + integral_indicator_one measurableSet_Ioi, integral_indicator_one (measurableSet_singleton q), + hβb] + field_simp + ring + have hpos : Integrable (fun ω ↦ max (X ω - q) 0) P := (hX.sub (integrable_const q)).pos_part + refine ⟨g, hg, hg0, hg1, hgint, ?_⟩ + clear_value g + calc ∫ ω, g (X ω) * X ω ∂P + = ∫ ω, (q * g (X ω) + (1 - α)⁻¹ * max (X ω - q) 0) ∂P := by + congr 1 + ext ω + rw [← hgx (X ω)] + ring + _ = q * ∫ ω, g (X ω) ∂P + (1 - α)⁻¹ * ∫ ω, max (X ω - q) 0 ∂P := by + rw [integral_add (hgX.const_mul q) (hpos.const_mul _), integral_const_mul, + integral_const_mul] + _ = rockafellarUryasev X P α q := by rw [hgint, mul_one, rockafellarUryasev] + _ = expectedShortfall X P α := rockafellarUryasev_valueAtRisk hX hα + +/-- **The dual representation of expected shortfall** (QRM Exercise 8.2): `ES_α(X)` is the +greatest value of `E[D·X]` over the stress densities `0 ≤ D ≤ (1 − α)⁻¹` with `E[D] = 1`. -/ +theorem isGreatest_integral_mul_expectedShortfall (hX : Integrable X P) (hα : α ∈ Ioo 0 1) : + IsGreatest {r | ∃ D : Ω → ℝ, AEStronglyMeasurable D P ∧ (∀ᵐ ω ∂P, 0 ≤ D ω) ∧ + (∀ᵐ ω ∂P, D ω ≤ (1 - α)⁻¹) ∧ ∫ ω, D ω ∂P = 1 ∧ r = ∫ ω, D ω * X ω ∂P} + (expectedShortfall X P α) := by + obtain ⟨g, hg, hg0, hg1, hgint, hgX⟩ := exists_density_integral_mul_eq_expectedShortfall hX hα + refine ⟨⟨fun ω ↦ g (X ω), (hg.comp_aemeasurable hX.aemeasurable).aestronglyMeasurable, + ae_of_all _ fun _ ↦ hg0 _, ae_of_all _ fun _ ↦ hg1 _, hgint, hgX.symm⟩, ?_⟩ + rintro r ⟨D, hD, hD0, hD1, hDint, rfl⟩ + exact integral_mul_le_expectedShortfall hX hα hD hD0 hD1 hDint + +/-- **ES is nondecreasing in the level** (QRM Exercise 8.2b): raising `α` relaxes the bound +`D ≤ (1 − α)⁻¹` on the stress densities, so the dual representation maximizes over a larger set. -/ +theorem expectedShortfall_mono_level (hX : Integrable X P) (hα : α ∈ Ioo 0 1) {β : ℝ} + (hβ : β ∈ Ioo 0 1) (hαβ : α ≤ β) : expectedShortfall X P α ≤ expectedShortfall X P β := by + obtain ⟨D, hD, hD0, hD1, hDint, hDX⟩ := (isGreatest_integral_mul_expectedShortfall hX hα).1 + rw [hDX] + exact integral_mul_le_expectedShortfall hX hβ hD hD0 + (hD1.mono fun _ h ↦ h.trans (inv_anti₀ (sub_pos.2 hβ.2) (by linarith))) hDint + +/-! ### Finite state spaces: ES in the ADEH framework -/ + +/-- **The representing set of expected shortfall**: on a finite probability space the ADEH +representing set of `ES_α` is exactly the set of probability vectors `q` with `qᵢ ≤ (1 − α)⁻¹ P{i}`, +that is, the probability densities `q/P` bounded by `(1 − α)⁻¹` (a state of null mass carries no +`q`-mass). `⊇` is the dual bound `integral_mul_le_expectedShortfall` for the density `q/P`; +`⊆` tests the acceptable loss `𝟙{i} − (1 − α)⁻¹ P{i}`, whose shortfall is nonpositive by the +Rockafellar–Uryasev bound at `c = 0`. -/ +theorem representingSet_expectedShortfall {ι : Type*} [Fintype ι] [MeasurableSpace ι] + [MeasurableSingletonClass ι] (P : Measure ι) [IsProbabilityMeasure P] (hα : α ∈ Ioo 0 1) : + representingSet (fun L : ι → ℝ ↦ expectedShortfall L P α) = + {q | (∀ i, 0 ≤ q i) ∧ ∑ i, q i = 1 ∧ ∀ i, q i ≤ (1 - α)⁻¹ * P.real {i}} := by + classical + have h1α : 0 < (1 - α)⁻¹ := inv_pos.2 (sub_pos.2 hα.2) + ext q + constructor + · rintro ⟨hq0, hq1, hq⟩ + refine ⟨hq0, hq1, fun i ↦ ?_⟩ + have hint : ∫ ω, max ((Pi.single i 1 : ι → ℝ) ω - 0) 0 ∂P = P.real {i} := by + have : (fun ω ↦ max ((Pi.single i 1 : ι → ℝ) ω - 0) 0) = Pi.single i 1 := by + ext ω + by_cases h : ω = i <;> simp [h] + rw [this, integral_fintype (μ := P) Integrable.of_finite] + simp [Pi.single_apply] + have hZ : expectedShortfall + (fun j ↦ (Pi.single i 1 : ι → ℝ) j + -((1 - α)⁻¹ * P.real {i})) P α ≤ 0 := by + rw [expectedShortfall_add_const Integrable.of_finite hα] + have := expectedShortfall_le_rockafellarUryasev + (Integrable.of_finite : Integrable ((Pi.single i 1 : ι → ℝ)) P) hα 0 + rw [rockafellarUryasev, hint, zero_add] at this + linarith + have h2 : ∑ j, q j * (Pi.single i 1 : ι → ℝ) j = q i := by simp [Pi.single_apply] + have h3 := hq _ hZ + rw [Finset.sum_congr rfl fun j _ ↦ mul_add (q j) _ _, Finset.sum_add_distrib, h2, + ← Finset.sum_mul, hq1, one_mul] at h3 + linarith + · rintro ⟨hq0, hq1, hqp⟩ + refine ⟨hq0, hq1, fun Z hZ ↦ ?_⟩ + set D : ι → ℝ := fun i ↦ q i / P.real {i} with hD + have hDp (i : ι) : D i * P.real {i} = q i := by + by_cases hp : P.real {i} = 0 + · have h := hqp i + rw [hp, mul_zero] at h + rw [hp, mul_zero] + exact (le_antisymm h (hq0 i)).symm + · exact div_mul_cancel₀ _ hp + have hDle (i : ι) : D i ≤ (1 - α)⁻¹ := by + by_cases hp : P.real {i} = 0 + · simpa [hD, hp] using h1α.le + · exact (div_le_iff₀ (lt_of_le_of_ne measureReal_nonneg (Ne.symm hp))).2 (hqp i) + have hDint : ∫ ω, D ω ∂P = 1 := by + rw [integral_fintype (μ := P) Integrable.of_finite] + simp only [smul_eq_mul] + rw [← hq1] + exact Finset.sum_congr rfl fun i _ ↦ by rw [mul_comm]; exact hDp i + have hle := integral_mul_le_expectedShortfall (Integrable.of_finite : Integrable Z P) hα + (Integrable.of_finite : Integrable D P).aestronglyMeasurable + (ae_of_all _ fun i ↦ div_nonneg (hq0 i) measureReal_nonneg) (ae_of_all _ hDle) hDint + rw [integral_fintype (μ := P) Integrable.of_finite] at hle + refine le_trans (le_of_eq ?_) (hle.trans hZ) + exact Finset.sum_congr rfl fun i _ ↦ by + rw [smul_eq_mul]; linear_combination (-(Z i)) * hDp i + +/-- **ES has an ADEH representation**: on a finite probability space, `ES_α(L)` is the least upper +bound of the expected losses `∑ qᵢ Lᵢ` over the representing set of `ES_α` +(`coherentRisk_isLUB` applied to `expectedShortfall_isCoherentRiskMeasure`). By +`representingSet_expectedShortfall` that set is the densities bounded by `(1 − α)⁻¹`, the set over +which `isGreatest_integral_mul_expectedShortfall` attains the same supremum. -/ +theorem expectedShortfall_isLUB_representingSet {ι : Type*} [Fintype ι] [MeasurableSpace ι] + [MeasurableSingletonClass ι] (P : Measure ι) [IsProbabilityMeasure P] (hα : α ∈ Ioo 0 1) + (L : ι → ℝ) : + IsLUB ((fun q ↦ ∑ i, q i * L i) '' representingSet fun L : ι → ℝ ↦ expectedShortfall L P α) + (expectedShortfall L P α) := + coherentRisk_isLUB (expectedShortfall_isCoherentRiskMeasure hα) L + +end MathFin diff --git a/LeanPool/MathFin/Risk/Expectile.lean b/LeanPool/MathFin/Risk/Expectile.lean new file mode 100644 index 0000000000..a7cf3353a4 --- /dev/null +++ b/LeanPool/MathFin/Risk/Expectile.lean @@ -0,0 +1,311 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.Elicitability + +/-! +# Expectiles + +The **`α`-expectile** of an integrable loss `Y` is the threshold `e` at which the +`α`-weighted expected excess above `e` balances the `(1 − α)`-weighted expected shortfall below +it: + + `α · E[(Y − e)⁺] = (1 − α) · E[(e − Y)⁺]` + +(McNeil–Frey–Embrechts, §8.2.6; QRM Exercise Book, Exercises 8.13–8.14). Write +`expectileGap α Y e = α E[(Y − e)⁺] − (1 − α) E[(e − Y)⁺]`. Because `(y − e)⁺ − (e − y)⁺ = y − e`, +the gap equals `(2α − 1)·E[(Y − e)⁺] + (1 − α)(E[Y] − e)`. The map `e ↦ E[(Y − e)⁺]` is +`1`-Lipschitz and antitone, so the gap falls with slope at most `−min(α, 1 − α)` +(`expectileGap_sub_le`). A continuous function falling at a linear rate has exactly one root. +That root is the expectile (`existsUnique_expectileGap_eq_zero`). + +Raising the level raises the gap pointwise, since `∂/∂α = E[(Y − e)⁺] + E[(e − Y)⁺] ≥ 0`, so it +moves the root to the right: **expectiles are nondecreasing in the level** +(`expectile_mono`, Exercise 8.13). At the level `1/2` the gap is `(E[Y] − e)/2`, so the +`1/2`-expectile is the mean (`expectile_half`). + +For a law with finite second moment the expectile is also the forecast that minimizes the +expected **asymmetric squared loss** `S(e, y) = α ((y − e)⁺)² + (1 − α) ((e − y)⁺)²` +(`expectileLoss`; Newey and Powell, *Asymmetric least squares estimation and testing*, +Econometrica 55 (1987), 819–847). The loss is strongly convex in the forecast with modulus +`min(α, 1 − α)`, and minus half its derivative at `e` is `g = α (y − e)⁺ − (1 − α)(e − y)⁺` +(`expectileLoss_ge`, a pointwise bound). The expectation of `g` is the gap, which vanishes at the +expectile, so integrating the bound there gives +`E[S(e, Y)] ≥ E[S(e_α, Y)] + min(α, 1 − α)(e − e_α)²`. Hence the loss strictly elicits the +expectile, in the sense of `StrictlyElicits` (`Risk/Elicitability.lean`), on the laws with +finite second moment (`strictlyElicits_expectileLoss`). The quantile is elicited by the pinball +loss (`strictlyElicits_pinballLoss`); expected shortfall is not elicitable +(`not_isElicitable_expectedShortfall`). Whether the expectile is a coherent risk measure for +`α ≥ 1/2` is not treated here. + +## Main definitions + +* `expectileGap`: the gap `α E[(Y − e)⁺] − (1 − α) E[(e − Y)⁺]`, whose root is the expectile. +* `expectile`: the `α`-expectile of `Y`, the infimum of the thresholds with a nonpositive gap. +* `expectileLoss`: the asymmetric squared loss `α ((y − e)⁺)² + (1 − α) ((e − y)⁺)²` of a + forecast `e` for an outcome `y`. + +## Main results + +* `expectileGap_sub_le`: the gap falls at rate at least `min(α, 1 − α)`. +* `existsUnique_expectileGap_eq_zero`: for integrable `Y` and `α ∈ (0, 1)`, the gap has a unique + root. +* `expectileGap_expectile`: for integrable `Y` and `α ∈ (0, 1)`, the expectile is that root. +* `expectile_mono`: expectiles are nondecreasing in the level. +* `expectile_half`: the `1/2`-expectile is the mean. +* `expectileLoss_ge`: a strong-convexity inequality for the asymmetric squared loss. +* `strictlyElicits_expectileLoss`: the asymmetric squared loss strictly elicits the expectile on + the probability laws with a finite second moment. + +## References + +* [T. Gneiting, *Making and evaluating point forecasts*][Gneiting2011] +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Section 8.2.6 +* [W. K. Newey and J. L. Powell, *Asymmetric least squares estimation and testing*][NeweyPowell1987] +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 8.13; Ex. 8.13, 8.14 + +## Tags + +expectile, asymmetric least squares, Newey-Powell, asymmetric squared loss, risk measure, +elicitability, MSC 91G70, MSC 62F10, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set Filter Topology + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + {Y : Ω → ℝ} {α : ℝ} + +/-- The **expectile gap** `α E[(Y − e)⁺] − (1 − α) E[(e − Y)⁺]`, whose root is the +`α`-expectile. -/ +noncomputable def expectileGap (α : ℝ) (Y : Ω → ℝ) (P : Measure Ω) (e : ℝ) : ℝ := + α * ∫ ω, max (Y ω - e) 0 ∂P - (1 - α) * ∫ ω, max (e - Y ω) 0 ∂P + +/-- The **`α`-expectile** of `Y`: the infimum of the thresholds with a nonpositive gap, which is +the unique root of the gap for an integrable `Y` and `α ∈ (0, 1)` (`expectileGap_expectile`). -/ +noncomputable def expectile (α : ℝ) (Y : Ω → ℝ) (P : Measure Ω) : ℝ := + sInf {e | expectileGap α Y P e ≤ 0} + +/-- The gap in terms of the upper partial moment alone: +`(2α − 1)·E[(Y − e)⁺] + (1 − α)(E[Y] − e)`, from `(e − y)⁺ = (y − e)⁺ − (y − e)`. -/ +lemma expectileGap_eq (hY : Integrable Y P) (e : ℝ) : + expectileGap α Y P e = + (2 * α - 1) * ∫ ω, max (Y ω - e) 0 ∂P + (1 - α) * ((∫ ω, Y ω ∂P) - e) := by + have hpt : (fun ω ↦ max (e - Y ω) 0) = fun ω ↦ max (Y ω - e) 0 - (Y ω - e) := by + ext ω + rcases le_total (Y ω) e with h | h + · rw [max_eq_left (sub_nonneg.2 h), max_eq_right (sub_nonpos.2 h)] + ring + · rw [max_eq_right (sub_nonpos.2 h), max_eq_left (sub_nonneg.2 h)] + ring + have hYe : Integrable (fun ω ↦ Y ω - e) P := hY.sub (integrable_const e) + have hM : Integrable (fun ω ↦ max (Y ω - e) 0) P := hYe.pos_part + rw [expectileGap, hpt, integral_sub hM hYe, + integral_sub hY (integrable_const e), integral_const, probReal_univ, one_smul] + ring + +/-- The upper partial moment `e ↦ E[(Y − e)⁺]` is antitone and falls by at most the increment. -/ +lemma upperPartialMoment_sub (hY : Integrable Y P) {e e' : ℝ} (h : e ≤ e') : + 0 ≤ (∫ ω, max (Y ω - e) 0 ∂P) - ∫ ω, max (Y ω - e') 0 ∂P ∧ + (∫ ω, max (Y ω - e) 0 ∂P) - ∫ ω, max (Y ω - e') 0 ∂P ≤ e' - e := by + have hM (e : ℝ) : Integrable (fun ω ↦ max (Y ω - e) 0) P := + (hY.sub (integrable_const e)).pos_part + rw [← integral_sub (hM e) (hM e')] + refine ⟨integral_nonneg fun ω ↦ sub_nonneg.2 (max_le_max (by linarith) le_rfl), ?_⟩ + calc ∫ ω, (max (Y ω - e) 0 - max (Y ω - e') 0) ∂P ≤ ∫ _, (e' - e) ∂P := + integral_mono ((hM e).sub (hM e')) + (integrable_const _) fun ω ↦ sub_le_iff_le_add.2 <| + max_le (by linarith [le_max_left (Y ω - e') 0]) + (by linarith [le_max_right (Y ω - e') 0]) + _ = e' - e := by simp + +/-- **The gap falls at a linear rate**: for `e ≤ e'`, +`min(α, 1 − α)·(e' − e) ≤ gap(e) − gap(e')`. -/ +theorem expectileGap_sub_le (hY : Integrable Y P) {e e' : ℝ} (h : e ≤ e') : + min α (1 - α) * (e' - e) ≤ expectileGap α Y P e - expectileGap α Y P e' := by + rw [expectileGap_eq hY, expectileGap_eq hY] + obtain ⟨h0, h1⟩ := upperPartialMoment_sub hY h + rcases le_total 0 (2 * α - 1) with hs | hs + · nlinarith [mul_nonneg hs h0, + mul_le_mul_of_nonneg_right (min_le_right α (1 - α)) (sub_nonneg.2 h)] + · nlinarith [mul_le_mul_of_nonpos_left h1 hs, + mul_le_mul_of_nonneg_right (min_le_left α (1 - α)) (sub_nonneg.2 h)] + +/-- The gap is continuous: the upper partial moment is `1`-Lipschitz. -/ +lemma continuous_expectileGap (hY : Integrable Y P) : Continuous (expectileGap α Y P) := by + have hm : Continuous fun e ↦ ∫ ω, max (Y ω - e) 0 ∂P := by + refine (LipschitzWith.of_dist_le_mul fun e e' ↦ ?_).continuous (K := 1) + simp only [Real.dist_eq, NNReal.coe_one, one_mul] + rcases le_total e e' with h | h + · obtain ⟨h0, h1⟩ := upperPartialMoment_sub hY h + rw [abs_of_nonneg h0, abs_of_nonpos (sub_nonpos.2 h)] + linarith + · obtain ⟨h0, h1⟩ := upperPartialMoment_sub hY h + rw [abs_of_nonpos (by linarith), abs_of_nonneg (sub_nonneg.2 h)] + linarith + simp_rw [funext (expectileGap_eq (α := α) hY)] + fun_prop + +/-- **The expectile exists and is unique**: the gap has exactly one root. -/ +theorem existsUnique_expectileGap_eq_zero (hY : Integrable Y P) (hα : α ∈ Ioo 0 1) : + ∃! e, expectileGap α Y P e = 0 := by + have hc : 0 < min α (1 - α) := lt_min hα.1 (sub_pos.2 hα.2) + set G := expectileGap α Y P + set t := |G 0| / min α (1 - α) + have ht : min α (1 - α) * t = |G 0| := mul_div_cancel₀ _ hc.ne' + have ht0 : 0 ≤ t := div_nonneg (abs_nonneg _) hc.le + have hlo : 0 ≤ G (-t) := by + have := expectileGap_sub_le (α := α) hY (show -t ≤ 0 by linarith) + linarith [neg_abs_le (G 0)] + have hhi : G t ≤ 0 := by + have := expectileGap_sub_le (α := α) hY ht0 + linarith [le_abs_self (G 0)] + obtain ⟨r, -, hr⟩ := intermediate_value_Icc' (by linarith : -t ≤ t) + (continuous_expectileGap hY).continuousOn ⟨hhi, hlo⟩ + refine ⟨r, hr, fun r' hr' ↦ ?_⟩ + by_contra hne + rcases lt_or_gt_of_ne hne with h | h + · nlinarith [expectileGap_sub_le (α := α) hY h.le, mul_pos hc (sub_pos.2 h)] + · nlinarith [expectileGap_sub_le (α := α) hY h.le, mul_pos hc (sub_pos.2 h)] + +/-- **The expectile is the root of the gap**: the thresholds with a nonpositive gap are exactly +`[e_α, ∞)`, so their infimum `expectile α Y P` is the root. -/ +theorem expectileGap_expectile (hY : Integrable Y P) (hα : α ∈ Ioo 0 1) : + expectileGap α Y P (expectile α Y P) = 0 := by + have hc : 0 < min α (1 - α) := lt_min hα.1 (sub_pos.2 hα.2) + obtain ⟨r, hr, -⟩ := existsUnique_expectileGap_eq_zero hY hα + have hset : {e | expectileGap α Y P e ≤ 0} = Ici r := by + ext e + refine ⟨fun he ↦ ?_, fun he ↦ ?_⟩ + · by_contra h + rw [mem_Ici, not_le] at h + have he' : expectileGap α Y P e ≤ 0 := he + nlinarith [expectileGap_sub_le (α := α) hY h.le, mul_pos hc (sub_pos.2 h)] + · have he' : r ≤ e := he + change expectileGap α Y P e ≤ 0 + nlinarith [expectileGap_sub_le (α := α) hY he', mul_nonneg hc.le (sub_nonneg.2 he')] + rw [expectile, hset, csInf_Ici, hr] + +/-- **Expectiles are nondecreasing in the level** (QRM Exercise 8.13): raising the level raises +the gap at every threshold, which moves its root to the right. -/ +theorem expectile_mono (hY : Integrable Y P) (hα : α ∈ Ioo 0 1) {β : ℝ} (hβ : β ∈ Ioo 0 1) + (hαβ : α ≤ β) : expectile α Y P ≤ expectile β Y P := by + set e := expectile α Y P + have hA : 0 ≤ ∫ ω, max (Y ω - e) 0 ∂P := integral_nonneg fun _ ↦ le_max_right _ _ + have hB : 0 ≤ ∫ ω, max (e - Y ω) 0 ∂P := integral_nonneg fun _ ↦ le_max_right _ _ + have hge : 0 ≤ expectileGap β Y P e := by + have h := expectileGap_expectile hY hα + rw [expectileGap] at h ⊢ + nlinarith [mul_nonneg (sub_nonneg.2 hαβ) hA, mul_nonneg (sub_nonneg.2 hαβ) hB] + by_contra hlt + rw [not_le] at hlt + have := expectileGap_sub_le (α := β) hY hlt.le + rw [expectileGap_expectile hY hβ] at this + nlinarith [mul_pos (lt_min hβ.1 (sub_pos.2 hβ.2)) (sub_pos.2 hlt)] + +/-- **The `1/2`-expectile is the mean**: at the level `1/2` the gap is `(E[Y] − e)/2` +(`expectileGap_eq`), whose root is `E[Y]`. -/ +theorem expectile_half (hY : Integrable Y P) : expectile (1 / 2) Y P = ∫ ω, Y ω ∂P := by + have hα : (1 / 2 : ℝ) ∈ Ioo 0 1 := ⟨by norm_num, by norm_num⟩ + obtain ⟨r, -, hr⟩ := existsUnique_expectileGap_eq_zero hY hα + have hmean : expectileGap (1 / 2) Y P (∫ ω, Y ω ∂P) = 0 := by + rw [expectileGap_eq hY] + ring + rw [hr _ (expectileGap_expectile hY hα), hr _ hmean] + +/-! ### Elicitability -/ + +/-- The **asymmetric squared loss** `S(e, y) = α ((y − e)⁺)² + (1 − α) ((e − y)⁺)²` of a forecast +`e` for an outcome `y`. -/ +noncomputable def expectileLoss (α e y : ℝ) : ℝ := + α * max (y - e) 0 ^ 2 + (1 - α) * max (e - y) 0 ^ 2 + +/-- **The asymmetric squared loss is strongly convex in the forecast**, with modulus +`min(α, 1 − α)`: moving the forecast from `e` to `e'` raises the loss by at least +`−2 (e' − e) g + min(α, 1 − α)(e' − e)²`, where `g = α (y − e)⁺ − (1 − α)(e − y)⁺` is minus half +the derivative of the loss at `e`. The four cases are the positions of `y` relative to `e` and +`e'`. -/ +lemma expectileLoss_ge (e e' y : ℝ) : + min α (1 - α) * (e' - e) ^ 2 ≤ + expectileLoss α e' y - expectileLoss α e y + + 2 * (e' - e) * (α * max (y - e) 0 - (1 - α) * max (e - y) 0) := by + have h1 := min_le_left α (1 - α) + have h2 := min_le_right α (1 - α) + unfold expectileLoss + rcases le_total e y with hy | hy <;> rcases le_total e' y with hy' | hy' + · rw [max_eq_left (sub_nonneg.2 hy), max_eq_right (sub_nonpos.2 hy), + max_eq_left (sub_nonneg.2 hy'), max_eq_right (sub_nonpos.2 hy')] + nlinarith [mul_nonneg (sub_nonneg.2 h1) (sq_nonneg (e' - e))] + · rw [max_eq_left (sub_nonneg.2 hy), max_eq_right (sub_nonpos.2 hy), + max_eq_right (sub_nonpos.2 hy'), max_eq_left (sub_nonneg.2 hy')] + nlinarith [mul_nonneg (sub_nonneg.2 h2) (sq_nonneg (e' - y)), + mul_nonneg (sub_nonneg.2 h1) (sq_nonneg (y - e)), + mul_nonneg (mul_nonneg (sub_nonneg.2 h1) (sub_nonneg.2 hy)) (sub_nonneg.2 hy')] + · rw [max_eq_right (sub_nonpos.2 hy), max_eq_left (sub_nonneg.2 hy), + max_eq_left (sub_nonneg.2 hy'), max_eq_right (sub_nonpos.2 hy')] + nlinarith [mul_nonneg (sub_nonneg.2 h1) (sq_nonneg (y - e')), + mul_nonneg (sub_nonneg.2 h2) (sq_nonneg (e - y)), + mul_nonneg (mul_nonneg (sub_nonneg.2 h2) (sub_nonneg.2 hy)) (sub_nonneg.2 hy')] + · rw [max_eq_right (sub_nonpos.2 hy), max_eq_left (sub_nonneg.2 hy), + max_eq_right (sub_nonpos.2 hy'), max_eq_left (sub_nonneg.2 hy')] + nlinarith [mul_nonneg (sub_nonneg.2 h2) (sq_nonneg (e' - e))] + +/-- **The asymmetric squared loss strictly elicits the expectile**: for `α ∈ (0, 1)` and a law +`μ` on `ℝ` with finite second moment, every expected loss `∫ S(e, y) dμ(y)` is finite and the +`α`-expectile of `μ` is its unique minimizer. Integrating `expectileLoss_ge` at the expectile, +where the gap vanishes, gives `E[S(e, Y)] − E[S(e_α, Y)] ≥ min(α, 1 − α)(e − e_α)² > 0` for +`e ≠ e_α`. -/ +theorem strictlyElicits_expectileLoss (hα : α ∈ Ioo 0 1) : + StrictlyElicits (expectileLoss α) (fun μ ↦ expectile α id μ) + {μ | IsProbabilityMeasure μ ∧ MemLp id 2 μ} := by + rintro μ ⟨hμ, h2⟩ + have hint : Integrable id μ := h2.integrable one_le_two + have hp (e : ℝ) : Integrable (fun y : ℝ ↦ max (y - e) 0) μ := + (hint.sub (integrable_const e)).pos_part + have hn (e : ℝ) : Integrable (fun y : ℝ ↦ max (e - y) 0) μ := + ((integrable_const e).sub hint).pos_part + have hp2 (e : ℝ) : Integrable (fun y : ℝ ↦ max (y - e) 0 ^ 2) μ := + (h2.sub (memLp_const e)).pos_part.integrable_sq + have hn2 (e : ℝ) : Integrable (fun y : ℝ ↦ max (e - y) 0 ^ 2) μ := + ((memLp_const e).sub h2).pos_part.integrable_sq + have hS (e : ℝ) : Integrable (expectileLoss α e) μ := + ((hp2 e).const_mul α).add ((hn2 e).const_mul (1 - α)) + refine ⟨hS, fun e he ↦ ?_⟩ + have he' : e ≠ expectile α id μ := he + change ∫ y, expectileLoss α (expectile α id μ) y ∂μ < ∫ y, expectileLoss α e y ∂μ + set r := expectile α id μ + have hgap : α * ∫ y, max (y - r) 0 ∂μ - (1 - α) * ∫ y, max (r - y) 0 ∂μ = 0 := + expectileGap_expectile hint hα + have hdiff : Integrable (fun y ↦ expectileLoss α e y - expectileLoss α r y) μ := + (hS e).sub (hS r) + have hg : Integrable (fun y ↦ α * max (y - r) 0 - (1 - α) * max (r - y) 0) μ := + ((hp r).const_mul α).sub ((hn r).const_mul (1 - α)) + have hD : ∫ y, (expectileLoss α e y - expectileLoss α r y + + 2 * (e - r) * (α * max (y - r) 0 - (1 - α) * max (r - y) 0)) ∂μ = + ∫ y, expectileLoss α e y ∂μ - ∫ y, expectileLoss α r y ∂μ := by + rw [integral_add hdiff (hg.const_mul _), integral_sub (hS e) (hS r), integral_const_mul, + integral_sub ((hp r).const_mul α) ((hn r).const_mul (1 - α)), integral_const_mul, + integral_const_mul, hgap, mul_zero, add_zero] + have hlow : min α (1 - α) * (e - r) ^ 2 ≤ + ∫ y, expectileLoss α e y ∂μ - ∫ y, expectileLoss α r y ∂μ := + calc min α (1 - α) * (e - r) ^ 2 = ∫ _, min α (1 - α) * (e - r) ^ 2 ∂μ := by simp + _ ≤ ∫ y, (expectileLoss α e y - expectileLoss α r y + + 2 * (e - r) * (α * max (y - r) 0 - (1 - α) * max (r - y) 0)) ∂μ := + integral_mono (integrable_const _) (hdiff.add (hg.const_mul _)) + fun y ↦ expectileLoss_ge r e y + _ = _ := hD + have hpos : 0 < min α (1 - α) * (e - r) ^ 2 := + mul_pos (lt_min hα.1 (sub_pos.2 hα.2)) (sq_pos_of_ne_zero (sub_ne_zero.2 he')) + linarith + +end MathFin diff --git a/LeanPool/MathFin/Risk/ExposureMeasures.lean b/LeanPool/MathFin/Risk/ExposureMeasures.lean new file mode 100644 index 0000000000..0761fe6d76 --- /dev/null +++ b/LeanPool/MathFin/Risk/ExposureMeasures.lean @@ -0,0 +1,115 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Models.Credit.CVA +public import LeanPool.MathFin.Risk.GaussianValueAtRisk + +/-! +# Potential future exposure and netting subadditivity + +Two risk measures of the CVA exposure process (`V : ℝ → Ω₁ → ℝ` an exposure process, `ν` its +measure): PFE, a quantile of the exposure (through `MathFin.valueAtRisk`), and netting +subadditivity. The expectations of the exposure that price the adjustments, EE and ENE, are with +the adjustments they price (`Models/Credit/CVA.lean`, `Models/Credit/DVA.lean`). + +* `potentialFutureExposure`: `PFE_α(s) = VaR_α(V_s⁺)`, the `α`-quantile of the exposure `V_s⁺`. + `potentialFutureExposure_eq_max` gives `PFE_α(s) = max (VaR_α(V_s)) 0`, since `x ↦ max x 0` is + monotone and continuous (`valueAtRisk_comp`). `potentialFutureExposure_of_hasLaw_gaussianReal` + is the closed form `max (m + √v Φ⁻¹(α)) 0` for `V_s ~ N(m, v)`, and + `potentialFutureExposure_gaussian` its instance at the exposure model `V_s = m + σ√s Z` of + `CVA.cva_gaussian`. +* `integral_posPart_finsetSum_le`: netting reduces exposure. For a finite family + `V : ι → Ω → ℝ` of integrable exposures on a common measure, `E[(Σᵢ Vᵢ)⁺] ≤ Σᵢ E[Vᵢ⁺]`, from + the pointwise subadditivity of `max (·) 0` (`max_add_add_le_max_add_max` with the second pair + at `0`), summed by `le_sum_of_subadditive`, then integrated. + +## Main definitions + +* `potentialFutureExposure`: `PFE_α(s)`, the `α`-level value-at-risk of the exposure `V_s⁺`. + +## Main results + +* `potentialFutureExposure_eq_max`: `PFE_α(s) = max (VaR_α(V_s)) 0` for `α ∈ (0, 1)`. +* `potentialFutureExposure_gaussian`: for `V_s = m + σ√s Z` with `Z ~ N(0, 1)`, `σ ≥ 0` and + `α ∈ (0, 1)`, `PFE_α(s) = max (gaussianVaR m (σ√s) (Φ⁻¹ α)) 0`. +* `integral_posPart_finsetSum_le`: netting reduces exposure, `E[(∑ᵢ Vᵢ)⁺] ≤ ∑ᵢ E[Vᵢ⁺]` for + integrable `Vᵢ`. + +## References + +* [J. C. Hull, *Options, Futures, and Other Derivatives*][Hull] (CVA/exposure chapter): EE, ENE, + PFE. +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management*][McNeilFreyEmbrechts] + (netting of credit exposures). + +## Tags + +expected negative exposure, potential future exposure, netting, counterparty credit risk, +CVA exposure, expected exposure, MSC 91G40, MSC 91G70, JEL G32 +-/ + +@[expose] public section + +namespace MathFin.CVA + +open MeasureTheory Real ProbabilityTheory Set +open scoped NNReal + +variable {Ω₁ : Type*} {m₁ : MeasurableSpace Ω₁} {ν : Measure Ω₁} + +/-- **Potential future exposure**: the `α`-level value-at-risk of the exposure `V_s⁺` at time +`s`, `PFE_α(s) = VaR_α(V_s⁺)`. -/ +noncomputable def potentialFutureExposure (V : ℝ → Ω₁ → ℝ) (ν : Measure Ω₁) (s α : ℝ) : ℝ := + MathFin.valueAtRisk (fun ω ↦ max (V s ω) 0) ν α + +/-- **PFE is the positive part of the VaR of `V_s`**: `VaR_α(V_s⁺) = max (VaR_α(V_s)) 0`, since +`x ↦ max x 0` is monotone and continuous (`valueAtRisk_comp`). -/ +theorem potentialFutureExposure_eq_max [IsProbabilityMeasure ν] {V : ℝ → Ω₁ → ℝ} {s α : ℝ} + (hV : AEMeasurable (V s) ν) (hα : α ∈ Ioo 0 1) : + potentialFutureExposure V ν s α = max (MathFin.valueAtRisk (V s) ν α) 0 := + MathFin.valueAtRisk_comp (h := fun x ↦ max x 0) hV (monotone_id.max monotone_const) + (continuous_id.max continuous_const).lowerSemicontinuous hα + +/-- **Gaussian PFE**: for `V_s ~ N(m, v)` and `α ∈ (0,1)`, +`PFE_α(s) = max (m + √v Φ⁻¹(α)) 0`, the positive part of the Gaussian value-at-risk. -/ +theorem potentialFutureExposure_of_hasLaw_gaussianReal {V : ℝ → Ω₁ → ℝ} {s α m : ℝ} {v : ℝ≥0} + (hV : HasLaw (V s) (gaussianReal m v) ν) (hα : α ∈ Ioo 0 1) : + potentialFutureExposure V ν s α = max (gaussianVaR m √(v : ℝ) (PhiInv α)) 0 := by + have := hV.isProbabilityMeasure_iff.2 inferInstance + rw [potentialFutureExposure_eq_max hV.aemeasurable hα, + MathFin.valueAtRisk_of_hasLaw_gaussianReal hV hα] + +/-- **Gaussian PFE in the exposure model of `CVA.cva_gaussian`**: for `Z ~ N(0,1)`, `σ ≥ 0`, +`α ∈ (0,1)` and `V_s = m + σ√s Z`, `PFE_α(s) = max (m + σ√s Φ⁻¹(α)) 0`. -/ +theorem potentialFutureExposure_gaussian {Z : Ω₁ → ℝ} + (hZ : HasLaw Z (gaussianReal 0 1) ν) (m σ s α : ℝ) (hσ : 0 ≤ σ) + (hα : α ∈ Ioo 0 1) : + potentialFutureExposure (fun s ω ↦ m + σ * √s * Z ω) ν s α + = max (gaussianVaR m (σ * √s) (PhiInv α)) 0 := by + have hL : HasLaw (fun ω ↦ m + σ * √s * Z ω) + (gaussianReal m (NNReal.mk ((σ * √s) ^ 2) (sq_nonneg _))) ν := by + simpa using gaussianReal_const_add (gaussianReal_const_mul hZ (σ * √s)) m + rw [potentialFutureExposure_of_hasLaw_gaussianReal (V := fun s ω ↦ m + σ * √s * Z ω) hL hα, + NNReal.coe_mk, Real.sqrt_sq (by positivity)] + +/-- **Netting reduces exposure**: `E[(∑ᵢ Vᵢ)⁺] ≤ ∑ᵢ E[Vᵢ⁺]` for a finite family of integrable +real-valued exposures on a common measure. Proved via pointwise subadditivity of `max (·) 0` +(`max_add_add_le_max_add_max`), summed (`le_sum_of_subadditive`), then integrated +(`integral_mono`, `integral_finsetSum`, `Integrable.pos_part`). -/ +theorem integral_posPart_finsetSum_le {ι : Type*} (s : Finset ι) {V : ι → Ω₁ → ℝ} + (hV : ∀ i ∈ s, Integrable (V i) ν) : + ∫ ω, max (∑ i ∈ s, V i ω) 0 ∂ν ≤ ∑ i ∈ s, ∫ ω, max (V i ω) 0 ∂ν := + (integral_mono (integrable_finsetSum s hV).pos_part + (integrable_finsetSum s fun i hi ↦ (hV i hi).pos_part) fun ω ↦ + Finset.le_sum_of_subadditive (fun x ↦ max x 0) (max_self (0:ℝ)).le (fun a b ↦ by + simpa using max_add_add_le_max_add_max (a := a) (b := b) (c := 0) (d := 0)) s + fun i ↦ V i ω).trans_eq + (integral_finsetSum s fun i hi ↦ (hV i hi).pos_part) + +end MathFin.CVA diff --git a/LeanPool/MathFin/Risk/Gaussian.lean b/LeanPool/MathFin/Risk/Gaussian.lean new file mode 100644 index 0000000000..753510591e --- /dev/null +++ b/LeanPool/MathFin/Risk/Gaussian.lean @@ -0,0 +1,106 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Init +public import Mathlib.Probability.Distributions.Gaussian.Real + +/-! +# Gaussian VaR and CVaR closed forms + +For a loss `L ~ N(μ, σ²)`, Value-at-Risk and Conditional Value-at-Risk at level +`α` admit the closed forms + + `VaR_α(L) = μ + σ · z`, where `z = Φ⁻¹(α)`, + `CVaR_α(L) = μ + σ · ϕ(z) / (1 − α)`. + +We parametrize on the quantile `z` rather than on `α` directly, since Mathlib +at the current pin does not ship a clean `Φ⁻¹` API. All identities below are +algebraic; the only Mathlib facts used are `gaussianPDFReal` and the field / +ring tactics. + +## Main definitions + +* `gaussianVaR`: the Gaussian VaR `μ + σ z` of a loss `L ~ N(μ, σ²)` at the quantile + `z = Φ⁻¹(α)`. +* `gaussianCVaR`: the Gaussian CVaR `μ + σ ϕ(z) / (1 − α)` at the quantile `z` and level `α`. + +## Main results + +* `gaussianVaR_affine`: `VaR(a·L + b) = a · VaR(L) + b` for `a ≥ 0`. +* `gaussianCVaR_affine`: `CVaR(a·L + b) = a · CVaR(L) + b` for `a ≥ 0`. +* `gaussianVaR_standard`: `VaR(N(0,1)) = z`. +* `gaussianCVaR_standard`: `CVaR(N(0,1)) = ϕ(z) / (1 − α)`. +* `gaussianCVaR_sub_VaR`: `CVaR − VaR = σ · (ϕ(z)/(1−α) − z)`. +* `gaussianVaR_volatility_scaling`: under iid time aggregation + (`σ_T = σ · √T`), `VaR_α(L_T) = T · μ + σ · √T · z`. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Ch 2; Ch 2.2.4; Ch 2.3 + +## Tags + +Gaussian VaR, Gaussian CVaR, normal quantile, parametric VaR, variance-covariance method, +square-root-of-time, MSC 91G70, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open ProbabilityTheory Real + +/-- Gaussian VaR at quantile `z = Φ⁻¹(α)` for a loss `L ~ N(μ, σ²)`. -/ +noncomputable def gaussianVaR (μ σ z : ℝ) : ℝ := μ + σ * z + +/-- Gaussian CVaR at quantile `z` and level `α` for a loss `L ~ N(μ, σ²)`. -/ +noncomputable def gaussianCVaR (μ σ z α : ℝ) : ℝ := + μ + σ * (gaussianPDFReal 0 1 z / (1 - α)) + +/-- **VaR affine invariance**: `VaR(a·L + b) = a · VaR(L) + b` for `a ≥ 0`. The +volatility scales by the genuine standard deviation `|a|·σ` of `a·L + b`, so the +hypothesis `0 ≤ a` is load-bearing — it discharges `|a| = a`. -/ +lemma gaussianVaR_affine (μ σ z a b : ℝ) (ha : 0 ≤ a) : + gaussianVaR (a * μ + b) (|a| * σ) z = a * gaussianVaR μ σ z + b := by + unfold gaussianVaR + rw [abs_of_nonneg ha]; ring + +/-- **CVaR affine invariance**: `CVaR(a·L + b) = a · CVaR(L) + b` for `a ≥ 0` +(volatility scales by `|a|·σ`, so `0 ≤ a` is load-bearing). -/ +lemma gaussianCVaR_affine (μ σ z α a b : ℝ) (ha : 0 ≤ a) : + gaussianCVaR (a * μ + b) (|a| * σ) z α = a * gaussianCVaR μ σ z α + b := by + unfold gaussianCVaR + rw [abs_of_nonneg ha]; ring + +/-- Standard normal VaR collapses to the quantile itself. -/ +lemma gaussianVaR_standard (z : ℝ) : gaussianVaR 0 1 z = z := by + unfold gaussianVaR; ring + +/-- Standard normal CVaR equals `ϕ(z) / (1 − α)`. -/ +lemma gaussianCVaR_standard (z α : ℝ) : + gaussianCVaR 0 1 z α = gaussianPDFReal 0 1 z / (1 - α) := by + unfold gaussianCVaR; ring + +/-- **CVaR/VaR difference**: `CVaR − VaR = σ · (ϕ(z)/(1−α) − z)`. -/ +lemma gaussianCVaR_sub_VaR (μ σ z α : ℝ) : + gaussianCVaR μ σ z α - gaussianVaR μ σ z = + σ * (gaussianPDFReal 0 1 z / (1 - α) - z) := by + unfold gaussianCVaR gaussianVaR + ring + +/-- **Volatility scaling under iid time aggregation**: for `L_T = ∑_{i=1}^T L_i` +with each `L_i ~ N(μ, σ²)` iid, `L_T ~ N(T·μ, T·σ²)`, so +`VaR_α(L_T) = T·μ + σ·√T · z`. The identity is purely algebraic. -/ +lemma gaussianVaR_volatility_scaling (μ σ z T : ℝ) : + gaussianVaR (T * μ) (σ * Real.sqrt T) z = T * μ + σ * Real.sqrt T * z := by + unfold gaussianVaR + ring + +end MathFin diff --git a/LeanPool/MathFin/Risk/GaussianExpectedShortfall.lean b/LeanPool/MathFin/Risk/GaussianExpectedShortfall.lean new file mode 100644 index 0000000000..3589926246 --- /dev/null +++ b/LeanPool/MathFin/Risk/GaussianExpectedShortfall.lean @@ -0,0 +1,108 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.ExpectedShortfall +public import LeanPool.MathFin.Risk.RockafellarUryasev +public import LeanPool.MathFin.Probability.Gaussian.NormalQuantile +public import Mathlib.Probability.Distributions.Gaussian.HasGaussianLaw.Basic + +/-! +# Expected shortfall of a Gaussian loss + +`Risk/RockafellarUryasev.lean` minimizes the Rockafellar–Uryasev objective of the Gaussian +loss `L = m + σ Z`, written against the standard normal density. It finds the closed form +`gaussianCVaR m σ z α = m + σ ϕ(z)/(1 − α)` at `Φ(z) = α`. The general Rockafellar–Uryasev theorem +(`Risk/ExpectedShortfall.lean`) shows that the minimum of the same objective, written +against the law, is the expected shortfall. + +The two objectives are the same function of the threshold +(`rockafellarUryasev_of_hasLaw_gaussianReal`), so the two minima agree. The Gaussian closed form is +therefore the expected shortfall of the normal law (`expectedShortfall_of_hasLaw_gaussianReal`). No +new integral is computed here. The Gaussian file supplies the value and the general theorem +supplies its meaning. + +## Main results + +* `rockafellarUryasev_of_hasLaw_gaussianReal`: the law-side objective equals `ruObjective`. +* `expectedShortfall_of_hasLaw_gaussianReal`: `ES_α(X) = m + σ ϕ(Φ⁻¹(α))/(1 − α)` for + `X ~ N(m, σ²)` with `σ > 0`. +* `expectedShortfall_of_hasGaussianLaw`: the same for any Gaussian `X` (degenerate included), in + terms of `E X` and `Var X`. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Example 2.14 +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 2.17 + +## Tags + +Gaussian expected shortfall, normal loss, Rockafellar-Uryasev, CVaR closed form, normal law, +MSC 91G70, MSC 60E05, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set +open scoped NNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + {X : Ω → ℝ} {α : ℝ} + +omit [IsProbabilityMeasure P] in +/-- The Rockafellar–Uryasev objective of a Gaussian loss, written against its law, is the objective +`ruObjective` of `Risk/RockafellarUryasev.lean`, written against the standard normal +density. -/ +theorem rockafellarUryasev_of_hasLaw_gaussianReal {m : ℝ} {v : ℝ≥0} + (hX : HasLaw X (gaussianReal m v) P) (c : ℝ) : + rockafellarUryasev X P α c = ruObjective m √(v : ℝ) α c := by + have hlaw : ∫ ω, max (X ω - c) 0 ∂P = + ∫ x, max (m + √(v : ℝ) * x - c) 0 * gaussianPDFReal 0 1 x := by + calc ∫ ω, max (X ω - c) 0 ∂P = ∫ y, max (y - c) 0 ∂gaussianReal m v := + hX.integral_comp (f := fun y ↦ max (y - c) 0) (by fun_prop) + _ = ∫ x, max (√(v : ℝ) * x + m - c) 0 ∂gaussianReal 0 1 := by + rw [gaussianReal_eq_map_standard, integral_map (by fun_prop) (by fun_prop)] + _ = ∫ x, max (m + √(v : ℝ) * x - c) 0 * gaussianPDFReal 0 1 x := by + rw [integral_gaussianReal_eq_integral_smul one_ne_zero] + congr with x + rw [smul_eq_mul, mul_comm, add_comm (√(v : ℝ) * x)] + rw [rockafellarUryasev, ruObjective, hlaw, div_eq_inv_mul] + +/-- **The expected shortfall of a Gaussian loss**: for `X ~ N(m, σ²)` with `σ > 0`, +`ES_α(X) = m + σ ϕ(Φ⁻¹(α))/(1 − α)`, the closed form `gaussianCVaR` of +`Risk/Gaussian.lean` at the normal quantile. -/ +theorem expectedShortfall_of_hasLaw_gaussianReal {m : ℝ} {v : ℝ≥0} (hv : v ≠ 0) + (hX : HasLaw X (gaussianReal m v) P) (hα : α ∈ Ioo 0 1) : + expectedShortfall X P α = gaussianCVaR m √(v : ℝ) (PhiInv α) α := by + have hσ : 0 < √(v : ℝ) := Real.sqrt_pos.2 (by positivity) + have h := isLeast_rockafellarUryasev hX.hasGaussianLaw.integrable hα + rw [show rockafellarUryasev X P α = ruObjective m √(v : ℝ) α from + funext (rockafellarUryasev_of_hasLaw_gaussianReal hX)] at h + exact h.unique (gaussianCVaR_isLeast_ruObjective m _ _ α hσ (Phi_PhiInv hα) hα.2) + +omit [IsProbabilityMeasure P] in +/-- **The expected shortfall of a Gaussian random variable** in terms of its mean and variance: +`ES_α(X) = E X + sd(X) ϕ(Φ⁻¹(α))/(1 − α)`. A degenerate (`Var X = 0`) Gaussian is almost surely +constant, its own expected shortfall (`expectedShortfall_const`). -/ +theorem expectedShortfall_of_hasGaussianLaw (hX : HasGaussianLaw X P) (hα : α ∈ Ioo 0 1) : + expectedShortfall X P α = gaussianCVaR P[X] √Var[X; P] (PhiInv α) α := by + have := hX.isProbabilityMeasure + rcases (variance_nonneg X P).eq_or_lt with hv | hv + · have h0 : X =ᵐ[P] fun _ ↦ P[X] := (evariance_eq_zero_iff hX.aemeasurable).1 + (by rw [← hX.memLp_two.ofReal_variance_eq, ← hv, ENNReal.ofReal_zero]) + have hc := expectedShortfall_const (P := P) P[X] hα + rw [← hv, Real.sqrt_zero, gaussianCVaR, zero_mul, add_zero, ← hc] + exact le_antisymm (expectedShortfall_mono hX.integrable (integrable_const _) h0.le hα) + (expectedShortfall_mono (integrable_const _) hX.integrable h0.symm.le hα) + · rw [expectedShortfall_of_hasLaw_gaussianReal (Real.toNNReal_pos.2 hv).ne' + ⟨hX.aemeasurable, hX.map_eq_gaussianReal⟩ hα, Real.coe_toNNReal _ (variance_nonneg X P)] + +end MathFin diff --git a/LeanPool/MathFin/Risk/GaussianRiskMarkowitz.lean b/LeanPool/MathFin/Risk/GaussianRiskMarkowitz.lean new file mode 100644 index 0000000000..6bde2c7f0a --- /dev/null +++ b/LeanPool/MathFin/Risk/GaussianRiskMarkowitz.lean @@ -0,0 +1,328 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.VaRSuperadditivity +public import LeanPool.MathFin.Choice.Portfolio.Equicorrelation +public import Mathlib.Probability.Distributions.Gaussian.Fernique + +/-! +# For Gaussian risk factors, VaR and ES rank portfolios as Markowitz does + +Value-at-risk and expected shortfall are translation invariant, positively homogeneous and law +invariant (`Risk/ValueAtRisk.lean`). Those three properties alone already give the +**location–scale principle**: a loss whose law is that of `m + s Z` (`s ≥ 0`) has + + `VaR_α = m + s · VaR_α(Z)` and `ES_α = m + s · ES_α(Z)` + +(`valueAtRisk_of_map_eq_affine`, `expectedShortfall_of_map_eq_affine`). So within a location–scale +family the risk measures order losses of equal mean by their scale, as soon as the standardized +risk is positive (`valueAtRisk_le_iff_of_map_eq_affine`, +`expectedShortfall_le_iff_of_map_eq_affine`). + +A Gaussian vector of risk-factor changes `X = (X₁, …, X_d)` makes every linear portfolio loss +`⟨w, X⟩ = ∑ wᵢ Xᵢ` a member of one such family. The loss is Gaussian (`HasGaussianLaw.map_fun`), +its mean is `∑ wᵢ E Xᵢ`, and its variance is the Markowitz double sum `wᵀ Σ w` of the covariance +kernel (`hasLaw_portfolio_gaussianReal`). The variance identification is the self-dot identity of +`Choice/Portfolio/CovariancePSD.lean`. Hence + + `VaR_α(⟨w, X⟩) = ∑ wᵢ E Xᵢ + √(wᵀ Σ w) · Φ⁻¹(α)` (`valueAtRisk_portfolio_gaussian`). + +**The bridge** (McNeil–Frey–Embrechts (2015), Chapter 8; QRM Exercise 8.6). Among portfolios +with the same expected loss, VaR at any level `α > 1/2` and ES at any such level order portfolios +exactly as the portfolio variance does (`valueAtRisk_portfolio_le_iff`, +`expectedShortfall_portfolio_le_iff`). Consequently a portfolio minimizes VaR, or ES, over any +admissible set of weights with a common expected loss exactly when it is a Markowitz +minimum-variance portfolio there (`isMinOn_valueAtRisk_iff_isMinOn_portfolioVarN`, +`isMinOn_expectedShortfall_iff_isMinOn_portfolioVarN`). This is a certified unification of two +known textbook facts, not new finance. + +On the linear space of portfolio losses VaR is also **subadditive** at every level `α ≥ 1/2` +(`valueAtRisk_portfolio_add_le`, QRM Exercise 8.4). Two portfolio losses of a Gaussian vector +are a jointly Gaussian pair (`hasGaussianLaw_portfolio_pair`), so this is the pair theorem +`valueAtRisk_add_le_of_hasGaussianLaw`, which rests on the subadditivity of the standard deviation +(`sqrt_variance_add_le`). Outside the Gaussian world subadditivity fails (`Risk/` +superadditivity examples). + +The general elliptical case of Exercise 8.6 is covered by the location–scale theorems once the +family hypothesis (every portfolio loss is `m + s Z` in law for one standardized `Z`) is +supplied. Elliptical distributions themselves are not formalized here; the Gaussian family is +the instance proved. + +## Main results + +* `valueAtRisk_of_map_eq_affine`, `expectedShortfall_of_map_eq_affine`: the location–scale + principle. +* `valueAtRisk_le_iff_of_map_eq_affine`, `expectedShortfall_le_iff_of_map_eq_affine`: within a + location–scale family and at equal means, the risk measures order losses by scale. +* `hasGaussianLaw_portfolio_pair`: two portfolio losses of a Gaussian vector are jointly Gaussian. +* `hasLaw_portfolio_gaussianReal`: `⟨w, X⟩ ~ N(∑ wᵢ E Xᵢ, wᵀ Σ w)` for a Gaussian vector `X`. +* `valueAtRisk_portfolio_gaussian`, `expectedShortfall_portfolio_gaussian`: the closed forms. +* `valueAtRisk_portfolio_le_iff`, `expectedShortfall_portfolio_le_iff`: VaR, ES and variance order + equal-mean portfolios identically (`α > 1/2`). +* `isMinOn_valueAtRisk_iff_isMinOn_portfolioVarN`, + `isMinOn_expectedShortfall_iff_isMinOn_portfolioVarN`: VaR- and ES-optimal portfolios are the + Markowitz portfolios (QRM Ex. 8.6). +* `valueAtRisk_portfolio_add_le`: VaR is subadditive on Gaussian portfolio losses for `α ≥ 1/2` + (QRM Ex. 8.4). +* `valueAtRisk_equal_weight_equicorrelated`: the VaR of an equally weighted equicorrelated + Gaussian portfolio, `m + σ √(ρ + (1 − ρ)/d) Φ⁻¹(α)` (QRM Ex. 6.16). + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Section 8.2 +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 8.4; Ex. 8.6 + +## Tags + +value-at-risk, expected shortfall, location–scale family, Markowitz, subadditivity, +elliptical distributions, MSC 91G70, MSC 91G10, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set +open scoped NNReal + +/-! ### The location–scale principle -/ + +section LocationScale + +variable {Ω Ω' : Type*} {mΩ : MeasurableSpace Ω} {mΩ' : MeasurableSpace Ω'} {P : Measure Ω} + {Q : Measure Ω'} {L L' : Ω → ℝ} {Z : Ω' → ℝ} {α m s s' : ℝ} + +/-- VaR depends on a loss only through its law, across probability spaces. -/ +lemma valueAtRisk_congr_map (h : P.map L = Q.map Z) (α : ℝ) : + valueAtRisk L P α = valueAtRisk Z Q α := by + rw [valueAtRisk, valueAtRisk, h] + +/-- ES depends on a loss only through its law, across probability spaces. -/ +lemma expectedShortfall_congr_map (h : P.map L = Q.map Z) (α : ℝ) : + expectedShortfall L P α = expectedShortfall Z Q α := by + simp only [expectedShortfall, valueAtRisk_congr_map h] + +variable [IsProbabilityMeasure Q] + +/-- **Location–scale principle for VaR**: a loss with the law of `m + s Z` (`s ≥ 0`) has +`VaR_α = m + s VaR_α(Z)`. -/ +theorem valueAtRisk_of_map_eq_affine (hZ : AEMeasurable Z Q) (hs : 0 ≤ s) + (h : P.map L = Q.map fun ω ↦ m + s * Z ω) (hα : α ∈ Ioo 0 1) : + valueAtRisk L P α = m + s * valueAtRisk Z Q α := by + rw [valueAtRisk_congr_map h, valueAtRisk_comp (h := fun z ↦ m + s * z) hZ + (monotone_const.add (monotone_id.const_mul hs)) + (by fun_prop : Continuous fun z : ℝ ↦ m + s * z).lowerSemicontinuous hα] + +/-- **Location–scale principle for ES**: a loss with the law of `m + s Z` (`s ≥ 0`, `Z` +integrable) has `ES_α = m + s ES_α(Z)`. Translation invariance and positive homogeneity of ES, +transported along the law. -/ +theorem expectedShortfall_of_map_eq_affine (hZ : Integrable Z Q) (hs : 0 ≤ s) + (h : P.map L = Q.map fun ω ↦ m + s * Z ω) (hα : α ∈ Ioo 0 1) : + expectedShortfall L P α = m + s * expectedShortfall Z Q α := + calc expectedShortfall L P α = expectedShortfall (fun ω ↦ s * Z ω + m) Q α := by + rw [expectedShortfall_congr_map h]; simp_rw [add_comm m] + _ = expectedShortfall (fun ω ↦ s * Z ω) Q α + m := + expectedShortfall_add_const (hZ.const_mul s) hα m + _ = m + s * expectedShortfall Z Q α := by + rw [expectedShortfall_const_mul hZ hα hs, add_comm] + +/-- **At equal means, VaR orders a location–scale family by scale**: if `L`, `L'` have the laws +of `m + s Z` and `m + s' Z` and `VaR_α(Z) > 0`, then `VaR_α(L) ≤ VaR_α(L') ↔ s ≤ s'`. -/ +theorem valueAtRisk_le_iff_of_map_eq_affine (hZ : AEMeasurable Z Q) (hs : 0 ≤ s) (hs' : 0 ≤ s') + (h : P.map L = Q.map fun ω ↦ m + s * Z ω) (h' : P.map L' = Q.map fun ω ↦ m + s' * Z ω) + (hα : α ∈ Ioo 0 1) (hpos : 0 < valueAtRisk Z Q α) : + valueAtRisk L P α ≤ valueAtRisk L' P α ↔ s ≤ s' := by + rw [valueAtRisk_of_map_eq_affine hZ hs h hα, valueAtRisk_of_map_eq_affine hZ hs' h' hα, + add_le_add_iff_left, mul_le_mul_iff_left₀ hpos] + +/-- **At equal means, ES orders a location–scale family by scale**: if `L`, `L'` have the laws +of `m + s Z` and `m + s' Z` and `ES_α(Z) > 0`, then `ES_α(L) ≤ ES_α(L') ↔ s ≤ s'`. -/ +theorem expectedShortfall_le_iff_of_map_eq_affine (hZ : Integrable Z Q) (hs : 0 ≤ s) + (hs' : 0 ≤ s') (h : P.map L = Q.map fun ω ↦ m + s * Z ω) + (h' : P.map L' = Q.map fun ω ↦ m + s' * Z ω) (hα : α ∈ Ioo 0 1) + (hpos : 0 < expectedShortfall Z Q α) : + expectedShortfall L P α ≤ expectedShortfall L' P α ↔ s ≤ s' := by + rw [expectedShortfall_of_map_eq_affine hZ hs h hα, + expectedShortfall_of_map_eq_affine hZ hs' h' hα, add_le_add_iff_left, + mul_le_mul_iff_left₀ hpos] + +end LocationScale + +/-! ### Gaussian portfolios -/ + +section Portfolio + +variable {ι : Type*} [Fintype ι] {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} + {X : ι → Ω → ℝ} {α : ℝ} + +/-- **Two portfolio losses of a Gaussian vector are jointly Gaussian**: `(∑ wᵢ Xᵢ, ∑ w'ᵢ Xᵢ)` is +the image of the Gaussian vector `X` under a linear map. -/ +theorem hasGaussianLaw_portfolio_pair (hX : HasGaussianLaw (fun ω ↦ (X · ω)) P) (w w' : ι → ℝ) : + HasGaussianLaw (fun ω ↦ (∑ i, w i * X i ω, ∑ i, w' i * X i ω)) P := by + simpa using hX.map_fun + ((∑ i, w i • ContinuousLinearMap.proj (R := ℝ) (φ := fun _ : ι ↦ ℝ) i).prod + (∑ i, w' i • ContinuousLinearMap.proj (R := ℝ) (φ := fun _ : ι ↦ ℝ) i)) + +/-- **A Gaussian portfolio loss**: if the risk-factor vector `X` is Gaussian, the portfolio loss +`∑ wᵢ Xᵢ` has law `N(∑ wᵢ E Xᵢ, wᵀ Σ w)`, with `Σ` the covariance kernel of `X`. -/ +theorem hasLaw_portfolio_gaussianReal (hX : HasGaussianLaw (fun ω ↦ (X · ω)) P) (w : ι → ℝ) : + HasLaw (fun ω ↦ ∑ i, w i * X i ω) + (gaussianReal (∑ i, w i * P[X i]) + (portfolioVarN Finset.univ w fun i j ↦ cov[X i, X j; P]).toNNReal) P := by + have := hX.isProbabilityMeasure + have hL := (hasGaussianLaw_portfolio_pair hX w w).fst + refine ⟨hL.aemeasurable, ?_⟩ + rw [hL.map_eq_gaussianReal, + portfolioVarN_covariance_eq_variance Finset.univ w X fun i _ ↦ (hX.eval i).memLp_two] + congr 1 + · rw [integral_finsetSum _ fun i _ ↦ (hX.eval i).integrable.const_mul (w i)] + simp_rw [integral_const_mul] + · congr 2 + ext ω + simp + +/-- The Markowitz variance of a Gaussian portfolio is nonnegative. -/ +lemma portfolioVarN_gaussian_nonneg (hX : HasGaussianLaw (fun ω ↦ (X · ω)) P) (w : ι → ℝ) : + 0 ≤ portfolioVarN Finset.univ w fun i j ↦ cov[X i, X j; P] := + have := hX.isProbabilityMeasure + portfolioVarN_covariance_nonneg Finset.univ w X fun i _ ↦ (hX.eval i).memLp_two + +/-- A Gaussian portfolio loss is `mean + (standard deviation) · Z` in law, `Z ~ N(0, 1)`. -/ +lemma map_portfolio_eq_affine (hX : HasGaussianLaw (fun ω ↦ (X · ω)) P) (w : ι → ℝ) : + P.map (fun ω ↦ ∑ i, w i * X i ω) = + (gaussianReal 0 1).map fun z ↦ + ∑ i, w i * P[X i] + √(portfolioVarN Finset.univ w fun i j ↦ cov[X i, X j; P]) * z := by + rw [(hasLaw_portfolio_gaussianReal hX w).map_eq, + gaussianReal_eq_map_standard (∑ i, w i * P[X i]), + Real.coe_toNNReal _ (portfolioVarN_gaussian_nonneg hX w)] + congr 1 + ext z + ring + +/-- **VaR of a Gaussian portfolio**: `VaR_α(∑ wᵢ Xᵢ) = ∑ wᵢ E Xᵢ + √(wᵀ Σ w) · Φ⁻¹(α)`. -/ +theorem valueAtRisk_portfolio_gaussian (hX : HasGaussianLaw (fun ω ↦ (X · ω)) P) (w : ι → ℝ) + (hα : α ∈ Ioo 0 1) : + valueAtRisk (fun ω ↦ ∑ i, w i * X i ω) P α = + ∑ i, w i * P[X i] + √(portfolioVarN Finset.univ w fun i j ↦ cov[X i, X j; P]) * PhiInv α := by + have := hX.isProbabilityMeasure + rw [valueAtRisk_eq_quantile (hasLaw_portfolio_gaussianReal hX w), quantile_gaussianReal _ _ hα, + Real.coe_toNNReal _ (portfolioVarN_gaussian_nonneg hX w)] + +/-- The VaR of the standard normal law is `Φ⁻¹(α)`. -/ +lemma valueAtRisk_id_gaussianReal (α : ℝ) : + valueAtRisk id (gaussianReal 0 1) α = PhiInv α := by + rw [valueAtRisk, Measure.map_id, PhiInv] + +/-- **ES of a Gaussian portfolio**: `ES_α(∑ wᵢ Xᵢ) = ∑ wᵢ E Xᵢ + √(wᵀ Σ w) · ES_α(N(0, 1))`. -/ +theorem expectedShortfall_portfolio_gaussian (hX : HasGaussianLaw (fun ω ↦ (X · ω)) P) + (w : ι → ℝ) (hα : α ∈ Ioo 0 1) : + expectedShortfall (fun ω ↦ ∑ i, w i * X i ω) P α = + ∑ i, w i * P[X i] + √(portfolioVarN Finset.univ w fun i j ↦ cov[X i, X j; P]) * + expectedShortfall id (gaussianReal 0 1) α := + expectedShortfall_of_map_eq_affine IsGaussian.integrable_id (Real.sqrt_nonneg _) + (map_portfolio_eq_affine hX w) hα + +/-- Above the median the standard normal VaR is positive. -/ +lemma zero_lt_valueAtRisk_id_gaussianReal (hα : α ∈ Ioo (1 / 2) 1) : + 0 < valueAtRisk id (gaussianReal 0 1) α := by + have hα' : α ∈ Ioo 0 1 := ⟨by linarith [hα.1], hα.2⟩ + rw [valueAtRisk_id_gaussianReal, PhiInv_pos_iff hα'] + exact hα.1 + +/-- **The bridge for VaR** (QRM Exercise 8.6): among Gaussian portfolios with the same expected +loss, VaR at a level `α > 1/2` orders portfolios exactly as the Markowitz variance does. -/ +theorem valueAtRisk_portfolio_le_iff (hX : HasGaussianLaw (fun ω ↦ (X · ω)) P) + (hα : α ∈ Ioo (1 / 2) 1) {w w' : ι → ℝ} + (hmean : ∑ i, w i * P[X i] = ∑ i, w' i * P[X i]) : + valueAtRisk (fun ω ↦ ∑ i, w i * X i ω) P α ≤ valueAtRisk (fun ω ↦ ∑ i, w' i * X i ω) P α ↔ + portfolioVarN Finset.univ w (fun i j ↦ cov[X i, X j; P]) ≤ + portfolioVarN Finset.univ w' fun i j ↦ cov[X i, X j; P] := by + have h' := map_portfolio_eq_affine hX w' + rw [← hmean] at h' + rw [valueAtRisk_le_iff_of_map_eq_affine IsGaussian.integrable_id.aemeasurable + (Real.sqrt_nonneg _) (Real.sqrt_nonneg _) (map_portfolio_eq_affine hX w) h' + ⟨by linarith [hα.1], hα.2⟩ (zero_lt_valueAtRisk_id_gaussianReal hα), + Real.sqrt_le_sqrt_iff (portfolioVarN_gaussian_nonneg hX w')] + +/-- **The bridge for ES** (QRM Exercise 8.6): among Gaussian portfolios with the same expected +loss, ES at a level `α > 1/2` orders portfolios exactly as the Markowitz variance does. -/ +theorem expectedShortfall_portfolio_le_iff (hX : HasGaussianLaw (fun ω ↦ (X · ω)) P) + (hα : α ∈ Ioo (1 / 2) 1) {w w' : ι → ℝ} + (hmean : ∑ i, w i * P[X i] = ∑ i, w' i * P[X i]) : + expectedShortfall (fun ω ↦ ∑ i, w i * X i ω) P α ≤ + expectedShortfall (fun ω ↦ ∑ i, w' i * X i ω) P α ↔ + portfolioVarN Finset.univ w (fun i j ↦ cov[X i, X j; P]) ≤ + portfolioVarN Finset.univ w' fun i j ↦ cov[X i, X j; P] := by + have hα' : α ∈ Ioo 0 1 := ⟨by linarith [hα.1], hα.2⟩ + have h' := map_portfolio_eq_affine hX w' + rw [← hmean] at h' + rw [expectedShortfall_le_iff_of_map_eq_affine IsGaussian.integrable_id (Real.sqrt_nonneg _) + (Real.sqrt_nonneg _) (map_portfolio_eq_affine hX w) h' hα' + ((zero_lt_valueAtRisk_id_gaussianReal hα).trans_le + (valueAtRisk_le_expectedShortfall IsGaussian.integrable_id hα')), + Real.sqrt_le_sqrt_iff (portfolioVarN_gaussian_nonneg hX w')] + +/-- **VaR-optimal portfolios are Markowitz portfolios** (QRM Exercise 8.6): on any set of +admissible weights sharing a common expected loss, a portfolio minimizes VaR at a level +`α > 1/2` exactly when it minimizes the Markowitz variance. -/ +theorem isMinOn_valueAtRisk_iff_isMinOn_portfolioVarN (hX : HasGaussianLaw (fun ω ↦ (X · ω)) P) + (hα : α ∈ Ioo (1 / 2) 1) {S : Set (ι → ℝ)} {c : ℝ} (hS : ∀ w ∈ S, ∑ i, w i * P[X i] = c) + {w₀ : ι → ℝ} (hw₀ : w₀ ∈ S) : + IsMinOn (fun w ↦ valueAtRisk (fun ω ↦ ∑ i, w i * X i ω) P α) S w₀ ↔ + IsMinOn (fun w ↦ portfolioVarN Finset.univ w fun i j ↦ cov[X i, X j; P]) S w₀ := by + simp only [isMinOn_iff] + exact forall₂_congr fun w hw ↦ + valueAtRisk_portfolio_le_iff hX hα ((hS w₀ hw₀).trans (hS w hw).symm) + +/-- **ES-optimal portfolios are Markowitz portfolios** (QRM Exercise 8.6): on any set of +admissible weights sharing a common expected loss, a portfolio minimizes ES at a level +`α > 1/2` exactly when it minimizes the Markowitz variance. -/ +theorem isMinOn_expectedShortfall_iff_isMinOn_portfolioVarN + (hX : HasGaussianLaw (fun ω ↦ (X · ω)) P) (hα : α ∈ Ioo (1 / 2) 1) {S : Set (ι → ℝ)} {c : ℝ} + (hS : ∀ w ∈ S, ∑ i, w i * P[X i] = c) {w₀ : ι → ℝ} (hw₀ : w₀ ∈ S) : + IsMinOn (fun w ↦ expectedShortfall (fun ω ↦ ∑ i, w i * X i ω) P α) S w₀ ↔ + IsMinOn (fun w ↦ portfolioVarN Finset.univ w fun i j ↦ cov[X i, X j; P]) S w₀ := by + simp only [isMinOn_iff] + exact forall₂_congr fun w hw ↦ + expectedShortfall_portfolio_le_iff hX hα ((hS w₀ hw₀).trans (hS w hw).symm) + +/-- **VaR is subadditive on Gaussian portfolio losses** (QRM Exercise 8.4): on the linear space +`{∑ wᵢ Xᵢ}` of a Gaussian vector, `VaR_α(L + L') ≤ VaR_α(L) + VaR_α(L')` at every level +`α ∈ [1/2, 1)`. -/ +theorem valueAtRisk_portfolio_add_le (hX : HasGaussianLaw (fun ω ↦ (X · ω)) P) + (hα : α ∈ Ico (1 / 2) 1) (w w' : ι → ℝ) : + valueAtRisk (fun ω ↦ ∑ i, w i * X i ω + ∑ i, w' i * X i ω) P α ≤ + valueAtRisk (fun ω ↦ ∑ i, w i * X i ω) P α + + valueAtRisk (fun ω ↦ ∑ i, w' i * X i ω) P α := + valueAtRisk_add_le_of_hasGaussianLaw (hasGaussianLaw_portfolio_pair hX w w') + ⟨by linarith [hα.1], hα.2⟩ hα.1 + +/-- **The diversification floor for VaR** (QRM Exercise 6.16): if `d` jointly Gaussian losses have +a common mean `m`, a common standard deviation `σ` and a common correlation `ρ`, their average +has `VaR_α = m + σ √(ρ + (1 − ρ)/d) Φ⁻¹(α)`. As `d` grows the idiosyncratic term `(1 − ρ)/d` +vanishes, but the common term `ρ` does not. -/ +theorem valueAtRisk_equal_weight_equicorrelated [Nonempty ι] + (hX : HasGaussianLaw (fun ω ↦ (X · ω)) P) {m σ ρ : ℝ} (hσ : 0 ≤ σ) + (hmean : ∀ i, P[X i] = m) (hvar : ∀ i, Var[X i; P] = σ ^ 2) + (hcov : ∀ i j, i ≠ j → cov[X i, X j; P] = ρ * σ ^ 2) (hα : α ∈ Ioo 0 1) : + valueAtRisk (fun ω ↦ ∑ i, (Fintype.card ι : ℝ)⁻¹ * X i ω) P α = + m + σ * √(ρ + (1 - ρ) / Fintype.card ι) * PhiInv α := by + classical + have hd : (Fintype.card ι : ℝ) ≠ 0 := Nat.cast_ne_zero.2 Fintype.card_ne_zero + rw [valueAtRisk_portfolio_gaussian hX _ hα, + portfolioVarN_covariance_eq_mul_equicorrelation X (fun i ↦ (hX.eval i).aemeasurable) hvar + hcov, portfolioVarN_equicorrelation_equal_weights, Real.sqrt_mul (sq_nonneg σ), + Real.sqrt_sq hσ] + simp only [hmean, ← Finset.sum_mul, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, + mul_inv_cancel₀ hd, one_mul] + +end Portfolio + +end MathFin diff --git a/LeanPool/MathFin/Risk/GaussianValueAtRisk.lean b/LeanPool/MathFin/Risk/GaussianValueAtRisk.lean new file mode 100644 index 0000000000..89b3ce5685 --- /dev/null +++ b/LeanPool/MathFin/Risk/GaussianValueAtRisk.lean @@ -0,0 +1,73 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.ValueAtRisk +public import LeanPool.MathFin.Risk.Gaussian +public import LeanPool.MathFin.Probability.Gaussian.NormalQuantile +public import Mathlib.Probability.Distributions.Gaussian.HasGaussianLaw.Basic + +/-! +# Value-at-risk of a Gaussian loss + +`Risk/Gaussian.lean` records the closed form `gaussianVaR μ σ z = μ + σ z` in a quantile +parameter `z` with `Φ(z) = α`, because the library had no `Φ⁻¹`. This file proves that the closed +form is the value-at-risk of the law: for a loss `X ~ N(m, σ²)`, + + `VaR_α(X) = m + σ Φ⁻¹(α) = gaussianVaR m σ (Φ⁻¹ α)` + +(`valueAtRisk_of_hasLaw_gaussianReal`). The parameter `z` of the closed-form lemmas is forced: +`Φ z = α` holds exactly when `z = Φ⁻¹(α)` (`Phi_eq_iff`). + +## Main results + +* `Phi_eq_iff`: `Φ z = α ↔ z = Φ⁻¹ α` for `α ∈ (0, 1)`. +* `valueAtRisk_of_hasLaw_gaussianReal`: `VaR_α(X) = gaussianVaR m σ (Φ⁻¹ α)` for `X ~ N(m, σ²)`. +* `valueAtRisk_of_hasGaussianLaw`: the same for any Gaussian `X`, in terms of `E X` and `Var X`. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Example 2.11 + +## Tags + +Gaussian VaR, normal quantile, inverse normal CDF, value at risk closed form, normal loss, +MSC 91G70, MSC 60E05, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set +open scoped NNReal + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} {X : Ω → ℝ} {α : ℝ} + +/-- The quantile parameter of the Gaussian closed forms is determined by the level: +`Φ z = α ↔ z = Φ⁻¹ α`. -/ +theorem Phi_eq_iff (hα : α ∈ Ioo 0 1) {z : ℝ} : Phi z = α ↔ z = PhiInv α := + ⟨fun h ↦ h ▸ (PhiInv_Phi z).symm, fun h ↦ h ▸ Phi_PhiInv hα⟩ + +/-- **The value-at-risk of a Gaussian loss** is the closed form of `Risk/Gaussian.lean` +at the normal quantile: `VaR_α(X) = m + σ Φ⁻¹(α)` for `X ~ N(m, σ²)`. -/ +theorem valueAtRisk_of_hasLaw_gaussianReal {m : ℝ} {v : ℝ≥0} + (hX : HasLaw X (gaussianReal m v) P) (hα : α ∈ Ioo 0 1) : + valueAtRisk X P α = gaussianVaR m √(v : ℝ) (PhiInv α) := by + rw [valueAtRisk_eq_quantile hX, quantile_gaussianReal m v hα, gaussianVaR] + +/-- **The value-at-risk of a Gaussian random variable** in terms of its mean and variance: +`VaR_α(X) = E X + sd(X) Φ⁻¹(α)`. -/ +theorem valueAtRisk_of_hasGaussianLaw (hX : HasGaussianLaw X P) (hα : α ∈ Ioo 0 1) : + valueAtRisk X P α = P[X] + √Var[X; P] * PhiInv α := by + have := hX.isProbabilityMeasure + rw [valueAtRisk_of_hasLaw_gaussianReal ⟨hX.aemeasurable, hX.map_eq_gaussianReal⟩ hα, gaussianVaR, + Real.coe_toNNReal _ (variance_nonneg X P)] + +end MathFin diff --git a/LeanPool/MathFin/Risk/JointElicitability.lean b/LeanPool/MathFin/Risk/JointElicitability.lean new file mode 100644 index 0000000000..08583959ca --- /dev/null +++ b/LeanPool/MathFin/Risk/JointElicitability.lean @@ -0,0 +1,278 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.Elicitability + +/-! +# Joint elicitability of (VaR, ES): a Fissler–Ziegel score + +Expected shortfall alone is not elicitable (`not_isElicitable_expectedShortfall`, for this +library's upper-tail `expectedShortfall`), but in the profit sign convention the pair (lower +`α`-quantile, lower-tail expected shortfall) is jointly elicitable: Fissler and Ziegel (2016), +*Higher order elicitability and Osband's principle*, Ann. Statist. 44(4), Corollary 5.5. This file +transcribes their scoring function (5.5) and proves strict consistency of its simplest strictly +consistent member. The loss-convention pair (`valueAtRisk`, `expectedShortfall`) is not treated +here. + +## The source formula + +Transcribed from the LaTeX source of arXiv:1503.08123v3, Corollary 5.5, equation (5.5). On the +action domain `{x ∈ ℝ² : x₁ ≥ x₂}`, + +`S(x₁, x₂, y) = (𝟙{y ≤ x₁} − α) G₁(x₁) − 𝟙{y ≤ x₁} G₁(y)` +` + G₂(x₂) (x₂ − x₁ + α⁻¹ 𝟙{y ≤ x₁} (x₁ − y)) − 𝒢₂(x₂) + a(y)`, + +with `𝒢₂' = G₂`. It is strictly consistent for `(VaR_α, ES_α)` if `G₁` is increasing and `𝒢₂` is +strictly increasing and strictly convex; the paper remarks after Corollary 5.5 that `G₁ = 0` is +allowed. The paper uses the **profit** sign convention: `VaR_α(F) = F⁻¹(α)` is the lower +`α`-quantile and `ES_α(F) = α⁻¹ ∫₀^α VaR_u(F) du` (its (5.1)) averages the *lower* tail, so +`ES_α ≤ VaR_α`. That lower-tail functional is `lowerExpectedShortfall` here. It is the reflection of +the loss-convention `expectedShortfall` of `Risk/ValueAtRisk.lean`, which averages the upper +tail: `lowerExpectedShortfall_eq_neg_expectedShortfall`. + +## The member proved + +`G₁ = 0`, `a = 0`, `𝒢₂ = G₂ = exp`. With `G₁ = 0` the monotonicity condition linking the two +coordinates disappears, so strict consistency holds on all of `ℝ²`, not only on `x₁ ≥ x₂`. The +proof reduces to the pinball loss: `α⁻¹ 𝟙{y ≤ v}(v − y) − v = α⁻¹ S_α(v, y) − y`, so the expected +score is `exp e · (e − E[Y] + α⁻¹ E[S_α(v, Y)]) − exp e`. The `v`-part is minimized only at the +quantile (`strictlyElicits_pinballLoss`), with minimum value `−ES_α`; what remains, +`exp e · (e − ES_α − 1)`, is minimized only at `e = ES_α` by `1 + t < exp t`. + +## Main definitions + +* `fisslerZiegelScore`: the Fissler–Ziegel score for `(VaR_α, ES_α)` in the profit convention, + equation (5.5) of Fissler–Ziegel (2016), for functions `G₁, G₂, 𝒢₂, a`. +* `fisslerZiegelExpScore`: its member with `G₁ = 0`, `𝒢₂ = G₂ = exp` and `a = 0`. +* `lowerExpectedShortfall`: the lower-tail expected shortfall `α⁻¹ ∫₀^α VaR_u(μ) du`, the mean of + the worst `α`-fraction of outcomes in the profit convention. + +## Main results + +* `lowerExpectedShortfall_eq_neg_expectedShortfall`: `ES^{lower}_α(μ) = −ES_{1−α}(−Y)` for + `Y ~ μ`, bridging to the loss-convention `expectedShortfall`. +* `strictlyElicits_fisslerZiegelExpScore`: for `α ∈ (0, 1)` the member strictly elicits, in the + sense of `StrictlyElicits` at value type `ℝ × ℝ`, the profit-convention pair + `(quantile μ α, lowerExpectedShortfall μ α)`, over all of `ℝ²`, on probability laws with finite + mean and unique `α`-quantile. +* `isElicitable_quantile_lowerExpectedShortfall`: the pair is jointly elicitable. Joint + elicitability is elicitability at value type `ℝ × ℝ`, so `IsElicitable.apply_mixture` gives + the convexity of the joint level sets (Fissler–Ziegel 2016, Proposition 2.14). + +## References + +* [T. Fissler and J. F. Ziegel, *Higher order elicitability and Osband's + principle*][FisslerZiegel2016], Corollary 5.5 + +## Tags + +joint elicitability, Fissler-Ziegel, VaR and ES, scoring function, backtesting expected shortfall, +Osband's principle, MSC 91G70, MSC 62F10, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set + +variable {α : ℝ} + +/-! ### The Fissler–Ziegel scoring family -/ + +/-- The **Fissler–Ziegel score** for `(VaR_α, ES_α)`, equation (5.5) of Fissler–Ziegel (2016), in +their profit sign convention, for a forecast pair `x = (x₁, x₂)` of VaR and ES and an outcome `y`: +``` +(𝟙{y ≤ x₁} − α) G₁(x₁) − 𝟙{y ≤ x₁} G₁(y) + + G₂(x₂)(x₂ − x₁ + α⁻¹ 𝟙{y ≤ x₁}(x₁ − y)) − 𝒢₂(x₂) + a(y). +``` +Their Corollary 5.5 requires `𝒢₂' = G₂`. -/ +noncomputable def fisslerZiegelScore (G₁ G₂ 𝒢₂ a : ℝ → ℝ) (α : ℝ) (x : ℝ × ℝ) (y : ℝ) : ℝ := + ((if y ≤ x.1 then 1 else 0) - α) * G₁ x.1 - (if y ≤ x.1 then 1 else 0) * G₁ y + + G₂ x.2 * (x.2 - x.1 + α⁻¹ * (if y ≤ x.1 then 1 else 0) * (x.1 - y)) - 𝒢₂ x.2 + a y + +/-- The member of the Fissler–Ziegel family with `G₁ = 0`, `𝒢₂ = G₂ = exp` and `a = 0`. -/ +noncomputable def fisslerZiegelExpScore (α : ℝ) : ℝ × ℝ → ℝ → ℝ := + fisslerZiegelScore 0 Real.exp Real.exp 0 α + +/-- The exponential member through the pinball loss, for `α ≠ 0`: +`S((v, e), y) = exp e · (e − y + α⁻¹ S_α(v, y)) − exp e`. -/ +lemma fisslerZiegelExpScore_eq (hα : α ≠ 0) (x : ℝ × ℝ) (y : ℝ) : + fisslerZiegelExpScore α x y = + Real.exp x.2 * (x.2 - y + α⁻¹ * pinballLoss α x.1 y) - Real.exp x.2 := by + rw [fisslerZiegelExpScore, fisslerZiegelScore, pinballLoss_eq_ite] + simp only [Pi.zero_apply, mul_zero, sub_zero, add_zero] + congr 2 + field_simp + split_ifs <;> ring + +/-- The **lower-tail expected shortfall** `ES_α(μ) = α⁻¹ ∫₀^α VaR_u(μ) du`, equation (5.1) of +Fissler–Ziegel (2016): the mean of the worst `α`-fraction of outcomes in the profit convention. -/ +noncomputable def lowerExpectedShortfall (μ : Measure ℝ) (α : ℝ) : ℝ := + α⁻¹ * ∫ u in Ioc 0 α, quantile μ u + +/-- At the lower `α`-quantile, the `v`-part of the expected score is minus the lower-tail expected +shortfall: `E[Y] − α⁻¹ E[S_α(VaR_α, Y)] = ES_α`, for `α ∈ (0, 1)` and a law with finite mean. That +this value is the minimum over `v` is `strictlyElicits_pinballLoss`, stated for laws whose +`α`-quantile is unique. -/ +lemma integral_sub_inv_mul_integral_pinballLoss {μ : Measure ℝ} [IsProbabilityMeasure μ] + (hint : Integrable id μ) (hα : α ∈ Ioo 0 1) : + ∫ y, y ∂μ - α⁻¹ * ∫ y, pinballLoss α (quantile μ α) y ∂μ = lowerExpectedShortfall μ α := by + have hvar (u : ℝ) : valueAtRisk id μ u = quantile μ u := by rw [valueAtRisk, Measure.map_id] + have h := integral_pinballLoss (P := μ) (X := id) hint hα (quantile μ α) + simp only [id] at h + rw [h, ← hvar, rockafellarUryasev_valueAtRisk hint hα, expectedShortfall] + simp_rw [hvar] + have hq := integrableOn_valueAtRisk (P := μ) hint + simp_rw [hvar] at hq + have hmean : ∫ y, y ∂μ = (∫ u in Ioc 0 α, quantile μ u) + ∫ u in Ioo α 1, quantile μ u := by + rw [integral_eq_setIntegral_quantile (f := fun y : ℝ ↦ y) (by fun_prop), + ← Ioc_union_Ioo_eq_Ioo hα.1.le hα.2, setIntegral_union + (Ioc_disjoint_Ioi_same.mono_right Ioo_subset_Ioi_self) measurableSet_Ioo + (hq.mono_set fun u hu ↦ ⟨hu.1, hu.2.trans_lt hα.2⟩) + (hq.mono_set (Ioo_subset_Ioo_left hα.1.le))] + rw [hmean, lowerExpectedShortfall] + have h1α : 1 - α ≠ 0 := (sub_pos.2 hα.2).ne' + have hα0 : α ≠ 0 := hα.1.ne' + field_simp + ring + +/-- Reflecting both the forecast and the outcome swaps the two sides of the pinball loss, and the +level `α` with `1 − α`. -/ +lemma pinballLoss_neg_neg (α v y : ℝ) : pinballLoss (1 - α) (-v) (-y) = pinballLoss α v y := by + simp only [pinballLoss, sub_sub_cancel, neg_sub_neg] + ring + +/-- **The lower-tail expected shortfall is the reflected expected shortfall**: for a probability +law `μ` with finite mean and `α ∈ (0, 1)`, + + `ES^{lower}_α(μ) = −ES_{1−α}(−Y)`, `Y ~ μ`, + +the profit-convention functional of Fissler–Ziegel is the loss-convention `expectedShortfall` of +the loss `−Y` at level `1 − α`, with its sign flipped. Both sides are the Rockafellar–Uryasev +extremum of the same expected pinball loss (`pinballLoss_neg_neg`): the reflected objective at +`−v` is `α⁻¹ E[S_α(v, Y)] − E[Y]`, minimized at the reflected quantile (`expectedShortfall` at +level `1 − α`) and by `v = quantile μ α` (`integral_pinballLoss_valueAtRisk_le`). -/ +theorem lowerExpectedShortfall_eq_neg_expectedShortfall {μ : Measure ℝ} [IsProbabilityMeasure μ] + (hint : Integrable id μ) (hα : α ∈ Ioo 0 1) : + lowerExpectedShortfall μ α = -expectedShortfall (fun y : ℝ ↦ -y) μ (1 - α) := by + have hβ : 1 - α ∈ Ioo (0 : ℝ) 1 := ⟨sub_pos.2 hα.2, sub_lt_self _ hα.1⟩ + have hα0 : α ≠ 0 := hα.1.ne' + have hX : Integrable (fun y : ℝ ↦ -y) μ := hint.neg + have hvar : valueAtRisk id μ α = quantile μ α := by rw [valueAtRisk, Measure.map_id] + -- the reflected objective at `-v` is `g v`, built from the expected pinball loss + have hRU (v : ℝ) : rockafellarUryasev (fun y : ℝ ↦ -y) μ (1 - α) (-v) + = α⁻¹ * ∫ y, pinballLoss α v y ∂μ - ∫ y, y ∂μ := by + have h := integral_pinballLoss (P := μ) (X := fun y : ℝ ↦ -y) hX hβ (-v) + simp only [pinballLoss_neg_neg, sub_sub_cancel] at h + rw [integral_neg] at h + rw [h] + field_simp + ring + have hr := integral_sub_inv_mul_integral_pinballLoss hint hα + have hle := expectedShortfall_le_rockafellarUryasev hX hβ (-quantile μ α) + rw [hRU] at hle + -- the reflected VaR is a competitor `-v*` for the pinball minimization + have hge := rockafellarUryasev_valueAtRisk hX hβ + have hmin := integral_pinballLoss_valueAtRisk_le (P := μ) (X := id) hint hα + (-valueAtRisk (fun y : ℝ ↦ -y) μ (1 - α)) + rw [hvar] at hmin + have := hRU (-valueAtRisk (fun y : ℝ ↦ -y) μ (1 - α)) + rw [neg_neg] at this + rw [this] at hge + have hαi : 0 < α⁻¹ := inv_pos.2 hα.1 + have := mul_le_mul_of_nonneg_left hmin hαi.le + simp only [id] at this + linarith + +/-- **The exponential Fissler–Ziegel score strictly elicits the profit-convention +`(VaR_α, ES_α)`** (Fissler–Ziegel 2016, Corollary 5.5, with `G₁ = 0` and `𝒢₂ = exp`) on the laws +with finite mean whose `α`-quantile is unique: the true pair (lower `α`-quantile, lower-tail +expected shortfall) is the unique minimizer of the expected score over all of `ℝ²`. The paper's +own domain is `A₀ = {x₁ ≥ x₂}`; the extension to all of `ℝ²` is this file's own observation (see +the module docstring), not the paper's claim — `G₁ = 0` removes the term that ties the two +coordinates together. -/ +theorem strictlyElicits_fisslerZiegelExpScore (hα : α ∈ Ioo 0 1) : + StrictlyElicits (fisslerZiegelExpScore α) + (fun μ ↦ (quantile μ α, lowerExpectedShortfall μ α)) + {μ | IsProbabilityMeasure μ ∧ Integrable id μ ∧ ∀ x, quantile μ α < x → α < cdf μ x} := by + intro μ hμC + obtain ⟨hpi, hplt⟩ := strictlyElicits_pinballLoss hα μ hμC + obtain ⟨hμ, hint, -⟩ := hμC + have hα0 : α ≠ 0 := hα.1.ne' + have hint' : Integrable (fun y : ℝ ↦ y) μ := hint + have hS (v e : ℝ) : fisslerZiegelExpScore α (v, e) = fun y ↦ + Real.exp e * (e - y + α⁻¹ * pinballLoss α v y) - Real.exp e := + funext (fisslerZiegelExpScore_eq hα0 (v, e)) + have hA (e : ℝ) : Integrable (fun y : ℝ ↦ e - y) μ := (integrable_const e).sub hint' + have hB (v : ℝ) : Integrable (fun y ↦ α⁻¹ * pinballLoss α v y) μ := (hpi v).const_mul _ + have hi (v e : ℝ) : Integrable (fun y ↦ e - y + α⁻¹ * pinballLoss α v y) μ := + (hA e).add (hB v) + -- the expected score, in terms of the expected pinball loss + have hE (v e : ℝ) : ∫ y, fisslerZiegelExpScore α (v, e) y ∂μ = + Real.exp e * (e - ∫ y, y ∂μ + α⁻¹ * ∫ y, pinballLoss α v y ∂μ) - Real.exp e := by + rw [hS, integral_sub ((hi v e).const_mul _) (integrable_const _), integral_const_mul, + integral_add (hA e) (hB v), integral_sub (integrable_const e) hint', integral_const, + integral_const, integral_const_mul] + simp + refine ⟨fun ⟨v, e⟩ ↦ hS v e ▸ ((hi v e).const_mul _).sub (integrable_const _), + fun ⟨v, e⟩ hne ↦ ?_⟩ + dsimp only at hne ⊢ + have hr := integral_sub_inv_mul_integral_pinballLoss hint hα + set q := quantile μ α + set r := lowerExpectedShortfall μ α + rw [hE, hE] + -- `D ≥ 0` is the pinball excess, strictly positive off the quantile + set D := ∫ y, pinballLoss α v y ∂μ - ∫ y, pinballLoss α q y ∂μ + have hD : 0 ≤ D := by + rcases eq_or_ne v q with rfl | hv + · simp [D] + · exact (sub_pos.2 (hplt v hv)).le + have hαi : 0 < α⁻¹ := inv_pos.2 hα.1 + -- the strict convexity of `exp`: `1 + t < exp t` off `0` makes `exp t · (t − 1) + 1` strictly + -- positive, since `exp t · (t − 1) + 1 = exp t · (exp (−t) − (1 − t))` + have hexp (t : ℝ) (ht : t ≠ 0) : 0 < Real.exp t * (t - 1) + 1 := by + have hm : Real.exp t * (t - 1) + 1 = Real.exp t * (Real.exp (-t) - (1 - t)) := by + have h1 : Real.exp t * Real.exp (-t) = 1 := by + rw [← Real.exp_add, add_neg_cancel, Real.exp_zero] + linear_combination (-1 : ℝ) * h1 + rw [hm] + exact mul_pos (Real.exp_pos t) (by linarith [Real.add_one_lt_exp (neg_ne_zero.2 ht)]) + -- rewrite both sides through `r` and `D` + have hLHS : Real.exp r * (r - ∫ y, y ∂μ + α⁻¹ * ∫ y, pinballLoss α q y ∂μ) - Real.exp r = + -Real.exp r := by + linear_combination (-Real.exp r) * hr + have hRHS : Real.exp e * (e - ∫ y, y ∂μ + α⁻¹ * ∫ y, pinballLoss α v y ∂μ) - Real.exp e = + Real.exp e * (e - r - 1) + Real.exp e * (α⁻¹ * D) := by + simp only [D]; linear_combination (-Real.exp e) * hr + rw [hLHS, hRHS] + have hsplit : Real.exp e * (e - r - 1) + Real.exp r = + Real.exp r * (Real.exp (e - r) * (e - r - 1) + 1) := by + rw [mul_add, ← mul_assoc, ← Real.exp_add, add_sub_cancel]; ring + have hED : 0 ≤ Real.exp e * (α⁻¹ * D) := mul_nonneg (Real.exp_pos e).le (mul_nonneg hαi.le hD) + rcases eq_or_ne e r with he | he + · have hv : v ≠ q := fun hv ↦ hne (by rw [hv, he]) + have hDpos : 0 < D := sub_pos.2 (hplt v hv) + have : 0 < Real.exp e * (α⁻¹ * D) := mul_pos (Real.exp_pos e) (mul_pos hαi hDpos) + rw [he] at this ⊢ + linarith + · have h1 := hexp (e - r) (sub_ne_zero.2 he) + have h2 := mul_pos (Real.exp_pos r) h1 + linarith [hsplit] + +/-- **The profit-convention pair (lower `α`-quantile, `lowerExpectedShortfall`) is jointly +elicitable** (Fissler–Ziegel 2016, Corollary 5.5) on the laws with finite mean and unique +`α`-quantile, although the (upper-tail, loss-convention) `expectedShortfall` alone is not +(`not_isElicitable_expectedShortfall`). -/ +theorem isElicitable_quantile_lowerExpectedShortfall (hα : α ∈ Ioo 0 1) : + IsElicitable (fun μ ↦ (quantile μ α, lowerExpectedShortfall μ α)) + {μ | IsProbabilityMeasure μ ∧ Integrable id μ ∧ ∀ x, quantile μ α < x → α < cdf μ x} := + ⟨_, strictlyElicits_fisslerZiegelExpScore hα⟩ + +end MathFin diff --git a/LeanPool/MathFin/Risk/LawInvariance.lean b/LeanPool/MathFin/Risk/LawInvariance.lean new file mode 100644 index 0000000000..c7dcaaf7cb --- /dev/null +++ b/LeanPool/MathFin/Risk/LawInvariance.lean @@ -0,0 +1,114 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.Expectile +public import LeanPool.MathFin.Risk.Spectral + +/-! +# Law invariance of risk functionals + +A risk functional `ρ : (Ω → ℝ) → ℝ` of losses on a probability space `(Ω, P)` is **law invariant** +when two losses with the same law have the same risk (`IsLawInvariant`). This is the formal home of +the sentence "value-at-risk is a quantile of a law": a cell of the library that stands alone, +because its objects depend on a loss only through its distribution, is a law-invariant functional. +The library's four are instances: + +* value-at-risk `valueAtRisk` and expected shortfall `expectedShortfall` are defined from the + quantile function of `P.map X`, so law invariance is the definition unfolded; +* the spectral risk measures `spectralRiskMeasure φ` integrate the value-at-risk curve; +* the expectile `expectile α` is the root of a gap built from the integrals + `∫ (Y − e)⁺ dP = ∫ (y − e)⁺ d(P.map Y)`. + +## Main definitions + +* `IsLawInvariant`: `P.map X = P.map Y` implies `ρ X = ρ Y`, for measurable losses. + +## Main results + +* `isLawInvariant_valueAtRisk`, `isLawInvariant_expectedShortfall`, + `isLawInvariant_spectralRiskMeasure`, `isLawInvariant_expectile`. +* `expectedShortfall_isCoherentRiskMeasure_and_isLawInvariant`: expected shortfall is a + law-invariant coherent risk measure. +* `IsLawInvariant.eq_of_hasLaw`: two losses with the law `μ` have the same risk. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Definitions 2.8 and 2.12 +* [H. Föllmer and A. Schied, *Convex measures of risk and trading constraints*][FollmerSchied2002] + +## Tags + +law invariance, distribution-based risk measure, value at risk, expected shortfall, spectral risk +measure, expectile, MSC 91G70, MSC 60E05, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} + +/-- A risk functional `ρ` of losses on `(Ω, P)` is **law invariant** if measurable losses with the +same law have the same risk. -/ +def IsLawInvariant (P : Measure Ω) (ρ : (Ω → ℝ) → ℝ) : Prop := + ∀ ⦃X Y : Ω → ℝ⦄, AEMeasurable X P → AEMeasurable Y P → P.map X = P.map Y → ρ X = ρ Y + +variable {P : Measure Ω} {ρ : (Ω → ℝ) → ℝ} + +/-- A law-invariant functional gives equal risk to two losses with a common law. -/ +lemma IsLawInvariant.eq_of_hasLaw (hρ : IsLawInvariant P ρ) {X Y : Ω → ℝ} {μ : Measure ℝ} + (hX : ProbabilityTheory.HasLaw X μ P) (hY : ProbabilityTheory.HasLaw Y μ P) : ρ X = ρ Y := + hρ hX.aemeasurable hY.aemeasurable (hX.map_eq.trans hY.map_eq.symm) + +/-- **Value-at-risk is law invariant**: it is the quantile of the law. -/ +theorem isLawInvariant_valueAtRisk (α : ℝ) : IsLawInvariant P fun X ↦ valueAtRisk X P α := + fun _ _ _ _ h ↦ by simp only [valueAtRisk, h] + +/-- **Expected shortfall is law invariant**: it averages the value-at-risk curve. -/ +theorem isLawInvariant_expectedShortfall (α : ℝ) : + IsLawInvariant P fun X ↦ expectedShortfall X P α := + fun _ _ _ _ h ↦ by simp only [expectedShortfall, valueAtRisk, h] + +/-- **Expected shortfall is a law-invariant coherent risk measure** on the integrable losses, for +every level `α ∈ (0, 1)`. Kusuoka's theorem is the converse direction, the representation of +law-invariant coherent risk measures through expected shortfalls; it is not proved here. -/ +theorem expectedShortfall_isCoherentRiskMeasure_and_isLawInvariant [IsProbabilityMeasure P] + {α : ℝ} (hα : α ∈ Set.Ioo 0 1) : + IsCoherentRiskMeasure P (fun X ↦ expectedShortfall X P α) ∧ + IsLawInvariant P fun X ↦ expectedShortfall X P α := + ⟨expectedShortfall_isCoherentRiskMeasure hα, isLawInvariant_expectedShortfall α⟩ + +/-- **Spectral risk measures are law invariant**: they integrate the value-at-risk curve against +the spectrum. -/ +theorem isLawInvariant_spectralRiskMeasure (φ : ℝ → ℝ) : + IsLawInvariant P fun X ↦ spectralRiskMeasure φ X P := + fun _ _ _ _ h ↦ by simp only [spectralRiskMeasure, valueAtRisk, h] + +/-- **Expectiles are law invariant**: the expectile gap at a threshold `e` is a function of the +law, through `∫ (Y − e)⁺ dP = ∫ (y − e)⁺ d(P.map Y)`. -/ +theorem isLawInvariant_expectile (α : ℝ) : + IsLawInvariant P fun Y ↦ expectile α Y P := by + have key {Y : Ω → ℝ} (hY : AEMeasurable Y P) (e : ℝ) : + expectileGap α Y P e = α * ∫ y, max (y - e) 0 ∂(P.map Y) - + (1 - α) * ∫ y, max (e - y) 0 ∂(P.map Y) := by + have h1 : ∫ ω, max (Y ω - e) 0 ∂P = ∫ y, max (y - e) 0 ∂(P.map Y) := + (integral_map (f := fun y ↦ max (y - e) 0) hY + (Continuous.aestronglyMeasurable (by fun_prop))).symm + have h2 : ∫ ω, max (e - Y ω) 0 ∂P = ∫ y, max (e - y) 0 ∂(P.map Y) := + (integral_map (f := fun y ↦ max (e - y) 0) hY + (Continuous.aestronglyMeasurable (by fun_prop))).symm + rw [expectileGap, h1, h2] + intro X Y hX hY h + have : expectileGap α X P = expectileGap α Y P := funext fun e ↦ by rw [key hX, key hY, h] + simp only [expectile, this] + +end MathFin diff --git a/LeanPool/MathFin/Risk/PositionsConvention.lean b/LeanPool/MathFin/Risk/PositionsConvention.lean new file mode 100644 index 0000000000..5c4fead5ff --- /dev/null +++ b/LeanPool/MathFin/Risk/PositionsConvention.lean @@ -0,0 +1,122 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.Coherent + +/-! +# Coherent risk measures of positions are coherent risk measures of losses + +Artzner, Delbaen, Eber and Heath state coherence for **positions**: a position `X` is a gain, so +a risk measure `ρ` *decreases* in `X` (`X ≤ Y → ρ Y ≤ ρ X`) and adding cash `m` lowers the capital +requirement (`ρ (X + m) = ρ X − m`). The library's single coherence structure is stated for +**losses** (`IsCoherentRiskMeasure`, McNeil–Frey–Embrechts' convention), where `ρ` increases and +`ρ (L + m) = ρ L + m`. The two are one object seen through the sign flip `L = −X`. + +`isCoherentRiskMeasure_neg_iff` makes that precise on a finite state space `ι` with a finite +measure that charges every state (counting measure is the model case), where almost-sure order is +pointwise order and every function is integrable: `ρ` satisfies +the four ADEH axioms for positions exactly when `L ↦ ρ (−L)` is an `IsCoherentRiskMeasure`. +The axioms of positions are written out rather than bundled in a second structure: bundling them +would be the duplicate that this module exists to remove. `Solution.lean` uses the statement to +discharge the positions-convention declarations of `Challenge.lean`, which may not import the +library. + +## Main results + +* `isCoherentRiskMeasure_neg_iff`: the four ADEH axioms for positions, written out, are + equivalent to `IsCoherentRiskMeasure P (fun L ↦ ρ (-L))`, for any finite measure `P` with + `P {i} ≠ 0` for every state `i`. + +## References + +* [P. Artzner et al., *Coherent measures of risk*][ArtznerDelbaenEberHeath1999] +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Definition 2.18 + +## Tags + +coherent risk measure, positions convention, Artzner-Delbaen-Eber-Heath, sign convention, +gains and losses, MSC 91G70, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory + +/-- **Positions from losses.** On a finite state space, for any finite measure `P`, if +`L ↦ ρ (−L)` is a coherent risk measure of losses then `ρ` satisfies the four +Artzner–Delbaen–Eber–Heath axioms for positions (monotone decreasing, `ρ (X + m) = ρ X − m`, +positively homogeneous, subadditive). No support assumption: the converse is where the order on +almost-sure classes must be pointwise (`isCoherentRiskMeasure_neg_iff`). -/ +theorem IsCoherentRiskMeasure.positions_of_neg {ι : Type*} [Finite ι] [MeasurableSpace ι] + [MeasurableSingletonClass ι] {P : Measure ι} [IsFiniteMeasure P] {ρ : (ι → ℝ) → ℝ} + (hρ : IsCoherentRiskMeasure P (fun L ↦ ρ (-L))) : + (∀ X Y : ι → ℝ, (∀ i, X i ≤ Y i) → ρ Y ≤ ρ X) ∧ + (∀ (X : ι → ℝ) (m : ℝ), ρ (fun i ↦ X i + m) = ρ X - m) ∧ + (∀ l : ℝ, 0 ≤ l → ∀ X : ι → ℝ, ρ (l • X) = l * ρ X) ∧ + ∀ X Y : ι → ℝ, ρ (X + Y) ≤ ρ X + ρ Y := by + refine ⟨fun X Y h ↦ ?_, fun X m ↦ ?_, fun l hl X ↦ ?_, fun X Y ↦ ?_⟩ + · simpa only [neg_neg] using + hρ.mono_of_le (X := -Y) (Y := -X) fun i ↦ neg_le_neg (h i) + · have h := hρ.add_const (X := -fun i ↦ X i + m) .of_finite m + have e : (-fun ω ↦ (-fun i ↦ X i + m) ω + m) = X := by + ext i; simp only [Pi.neg_apply]; ring + change ρ (-fun ω ↦ (-fun i ↦ X i + m) ω + m) = ρ (-(-fun i ↦ X i + m)) + m at h + rw [e, neg_neg] at h + linarith + · have h := hρ.const_mul (X := -X) .of_finite hl + have e : (-fun ω ↦ l * (-X) ω) = l • X := by + ext i; simp only [Pi.neg_apply, Pi.smul_apply, smul_eq_mul]; ring + change ρ (-fun ω ↦ l * (-X) ω) = l * ρ (-(-X)) at h + rwa [e, neg_neg] at h + · have h := hρ.add_le (X := -X) (Y := -Y) .of_finite .of_finite + have e : (-fun ω ↦ (-X) ω + (-Y) ω) = X + Y := by + ext i; simp only [Pi.neg_apply, Pi.add_apply]; ring + change ρ (-fun ω ↦ (-X) ω + (-Y) ω) ≤ ρ (-(-X)) + ρ (-(-Y)) at h + rwa [e, neg_neg, neg_neg] at h + +/-- **Positions versus losses.** On a finite state space with a finite measure `P` charging every +state (`P {i} ≠ 0`, so almost-sure order is the pointwise order), a functional +`ρ : (ι → ℝ) → ℝ` satisfies the four Artzner–Delbaen–Eber–Heath axioms for positions +(monotone decreasing, `ρ (X + m) = ρ X − m`, positively homogeneous, subadditive) if and only if +`L ↦ ρ (−L)` is a coherent risk measure of losses. -/ +theorem isCoherentRiskMeasure_neg_iff {ι : Type*} [Finite ι] [MeasurableSpace ι] + [MeasurableSingletonClass ι] {P : Measure ι} [IsFiniteMeasure P] (hP : ∀ i, P {i} ≠ 0) + {ρ : (ι → ℝ) → ℝ} : + IsCoherentRiskMeasure P (fun L ↦ ρ (-L)) ↔ + (∀ X Y : ι → ℝ, (∀ i, X i ≤ Y i) → ρ Y ≤ ρ X) ∧ + (∀ (X : ι → ℝ) (m : ℝ), ρ (fun i ↦ X i + m) = ρ X - m) ∧ + (∀ l : ℝ, 0 ≤ l → ∀ X : ι → ℝ, ρ (l • X) = l * ρ X) ∧ + ∀ X Y : ι → ℝ, ρ (X + Y) ≤ ρ X + ρ Y := by + refine ⟨IsCoherentRiskMeasure.positions_of_neg, ?_⟩ + rintro ⟨hm, hc, hh, hs⟩ + refine + { mono := fun X Y _ _ h ↦ ?_ + add_const := fun X _ m ↦ ?_ + const_mul := fun X _ c hc' ↦ ?_ + add_le := fun X Y _ _ ↦ ?_ } + · exact hm (-Y) (-X) fun i ↦ neg_le_neg ((ae_iff_forall_of_singleton_ne_zero hP).1 h i) + · have e : (-fun ω ↦ X ω + m) = fun i ↦ (-X) i + -m := by + ext i; simp only [Pi.neg_apply]; ring + change ρ (-fun ω ↦ X ω + m) = ρ (-X) + m + rw [e, hc (-X) (-m)] + ring + · have e : (-fun ω ↦ c * X ω) = c • -X := by + ext i; simp only [Pi.neg_apply, Pi.smul_apply, smul_eq_mul]; ring + change ρ (-fun ω ↦ c * X ω) = c * ρ (-X) + rw [e, hh c hc' (-X)] + · have e : (-fun ω ↦ X ω + Y ω) = -X + -Y := by + ext i; simp only [Pi.neg_apply, Pi.add_apply]; ring + change ρ (-fun ω ↦ X ω + Y ω) ≤ ρ (-X) + ρ (-Y) + rw [e] + exact hs (-X) (-Y) + +end MathFin diff --git a/LeanPool/MathFin/Risk/RiskClosedForms.lean b/LeanPool/MathFin/Risk/RiskClosedForms.lean new file mode 100644 index 0000000000..e03f91a9ca --- /dev/null +++ b/LeanPool/MathFin/Risk/RiskClosedForms.lean @@ -0,0 +1,393 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.ValueAtRisk +public import Mathlib.Probability.Distributions.Pareto + +/-! +# Closed forms for value-at-risk and expected shortfall: exponential and Pareto losses + +The general value-at-risk and expected shortfall of `Risk/ValueAtRisk.lean` evaluated on +two textbook laws (McNeil–Frey–Embrechts, *Quantitative Risk Management*, Example 2.14; QRM +Exercise Book, Exercises 2.12 and 2.23): + +* the **exponential** law `Exp(λ)` (Mathlib's `expMeasure`), a light tail: + `VaR_α = −log(1 − α)/λ` and `ES_α = (1 − log(1 − α))/λ`; +* the **Pareto** law of Mathlib's `paretoMeasure t r` (type I, `F(x) = 1 − (t/x)^r` on `[t, ∞)`) + and its shift to the origin, the **Lomax** (Pareto type II) law `Pa(θ, κ)` with + `F(x) = 1 − (κ/(κ + x))^θ` on `[0, ∞)` (`lomaxMeasure`), heavy tails: + `VaR_α = κ((1 − α)^{−1/θ} − 1)` and `ES_α = κ(θ/(θ − 1)·(1 − α)^{−1/θ} − 1)` for `θ > 1`. + +The two tails separate in the **shortfall-to-quantile ratio** `ES_α/VaR_α` as `α → 1`: it tends +to `1` for the exponential law and to `θ/(θ − 1) > 1` for the Lomax law. For the type-I Pareto law +the ratio is `r/(r − 1)` at every level. A heavy tail makes the average loss beyond VaR a fixed +multiple of VaR, however far into the tail one looks. + +The **median shortfall**, the median of the loss conditional on exceeding `VaR_α`, is itself a +value-at-risk, `MS_α = VaR_{(1+α)/2}`, whenever the distribution function is continuous +(`medianShortfall_eq_valueAtRisk`, QRM Exercise Book, Exercise 2.29 b)). + +Every quantile below is read off the CDF through `quantile_eq_iff`: `quantile μ p = a` exactly +when `p ≤ F(a)` and `F(x) < p` for `x < a`. Mathlib records the Pareto CDF only as an integral of +its density; `cdf_paretoMeasure_of_le` evaluates it. + +## Main definitions + +* `lomaxMeasure`: the Lomax (Pareto type II) law `Pa(θ, κ)`, the type-I Pareto law of scale `κ` + and shape `θ` shifted to the origin, with `F(x) = 1 − (κ/(κ + x))^θ` on `[0, ∞)`. +* `medianShortfall`: the median of the law of a loss `X` conditioned on exceeding its + value-at-risk, `F⁻¹_{X | X > VaR_α(X)}(1/2)`. + +## Main results + +* `valueAtRisk_eq_iff`: a VaR is characterised by the CDF (from `quantile_eq_iff` in + `Probability/Laws/Quantile.lean`). +* `valueAtRisk_of_hasLaw_expMeasure` (via `quantile_expMeasure` in + `Probability/Laws/Quantile.lean`), + `expectedShortfall_of_hasLaw_expMeasure`: the exponential closed forms. +* `tendsto_expectedShortfall_div_valueAtRisk_expMeasure`: `ES_α/VaR_α → 1` (light tail). +* `cdf_paretoMeasure_of_le`, `cdf_paretoMeasure_of_lt`, `quantile_paretoMeasure`: the type-I + Pareto CDF and quantile. +* `expectedShortfall_of_hasLaw_paretoMeasure`: `ES_α = r/(r − 1)·VaR_α` for type-I Pareto with + `r > 1`. +* `cdf_lomaxMeasure`, `valueAtRisk_of_hasLaw_lomaxMeasure`, + `expectedShortfall_of_hasLaw_lomaxMeasure`: the Lomax CDF and closed forms. +* `tendsto_expectedShortfall_div_valueAtRisk_lomaxMeasure`: for `θ > 1`, `ES_α/VaR_α → θ/(θ − 1)` + as `α → 1` (heavy tail). +* `medianShortfall_eq_valueAtRisk`: the median of the loss beyond `VaR_α` is `VaR_{(1+α)/2}` for a + continuous distribution function. + +## References + +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 2.12(a); Ex. 2.12(d); Ex. 2.23(a); Ex. 2.23(c); Ex. + 2.29(b) + +## Tags + +VaR closed form, exponential loss, Pareto loss, Lomax distribution, heavy tails, median shortfall, +light tail, tail risk, MSC 91G70, MSC 60E05, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set Filter Topology Real + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} {X : Ω → ℝ} {μ : Measure ℝ} + {p α : ℝ} + +/-! ### Reading a quantile off the CDF -/ + +/-- A VaR is pinned down by the distribution function of the loss: +`VaR_α(X) = a ↔ α ≤ P(X ≤ a) ∧ ∀ x < a, P(X ≤ x) < α`. -/ +theorem valueAtRisk_eq_iff [IsProbabilityMeasure P] (hX : AEMeasurable X P) (hα : α ∈ Ioo 0 1) + {a : ℝ} : + valueAtRisk X P α = a ↔ α ≤ P.real {ω | X ω ≤ a} ∧ ∀ x < a, P.real {ω | X ω ≤ x} < α := by + refine ⟨?_, fun ⟨ha, hlt⟩ ↦ le_antisymm ((valueAtRisk_le_iff hX hα).2 ha) + (le_of_forall_lt fun x hx ↦ (lt_valueAtRisk_iff hX hα).2 (hlt x hx))⟩ + rintro rfl + exact ⟨le_measureReal_le_valueAtRisk hX hα, fun _ hx ↦ (lt_valueAtRisk_iff hX hα).1 hx⟩ + +/-- The VaR curve is the quantile curve on `(α, 1)`, so ES is the average of any closed form for +it. -/ +lemma expectedShortfall_eq_of_valueAtRisk_eq {f : ℝ → ℝ} + (hf : ∀ u ∈ Ioo α 1, valueAtRisk X P u = f u) : + expectedShortfall X P α = (1 - α)⁻¹ * ∫ u in Ioo α 1, f u := by + rw [expectedShortfall, setIntegral_congr_fun measurableSet_Ioo hf] + +/-! ### The exponential law -/ + +/-- **VaR of an exponential loss**: `VaR_α(X) = −log(1 − α)/λ` for `X ~ Exp(λ)`. -/ +theorem valueAtRisk_of_hasLaw_expMeasure {r : ℝ} (hr : 0 < r) (hX : HasLaw X (expMeasure r) P) + (hα : α ∈ Ioo 0 1) : valueAtRisk X P α = -log (1 - α) / r := by + rw [valueAtRisk_eq_quantile hX, quantile_expMeasure hr hα] + +/-- **ES of an exponential loss**: `ES_α(X) = (1 − log(1 − α))/λ` for `X ~ Exp(λ)`. -/ +theorem expectedShortfall_of_hasLaw_expMeasure {r : ℝ} (hr : 0 < r) + (hX : HasLaw X (expMeasure r) P) (hα : α ∈ Ioo 0 1) : + expectedShortfall X P α = (1 - log (1 - α)) / r := by + have h1α : 1 - α ≠ 0 := (sub_pos.2 hα.2).ne' + have hr' : r ≠ 0 := hr.ne' + rw [expectedShortfall_eq_of_valueAtRisk_eq fun u hu ↦ + valueAtRisk_of_hasLaw_expMeasure hr hX ⟨hα.1.trans hu.1, hu.2⟩, + ← integral_Ioc_eq_integral_Ioo, ← intervalIntegral.integral_of_le hα.2.le, + intervalIntegral.integral_div, + intervalIntegral.integral_neg, intervalIntegral.integral_comp_sub_left log 1, + sub_self, integral_log] + field_simp + ring + +/-- As the level `α` rises to `1`, the tail mass `1 − α` falls to `0` from above. -/ +lemma tendsto_one_sub_nhdsLT_one : Tendsto (fun α : ℝ ↦ 1 - α) (𝓝[<] 1) (𝓝[>] 0) := by + refine tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ?_ + (eventually_nhdsWithin_of_forall fun _ hα ↦ show (0 : ℝ) < _ from sub_pos.2 hα) + have h : Tendsto (fun α : ℝ ↦ 1 - α) (𝓝 1) (𝓝 (1 - 1)) := + (continuous_const.sub continuous_id).tendsto 1 + rw [sub_self] at h + exact h.mono_left nhdsWithin_le_nhds + +/-- **Light tail**: for an exponential loss the shortfall-to-quantile ratio tends to `1`, +`ES_α/VaR_α → 1` as `α → 1⁻` (QRM Exercise Book, Exercise 2.23 a)). -/ +theorem tendsto_expectedShortfall_div_valueAtRisk_expMeasure {r : ℝ} (hr : 0 < r) + (hX : HasLaw X (expMeasure r) P) : + Tendsto (fun α ↦ expectedShortfall X P α / valueAtRisk X P α) (𝓝[<] 1) (𝓝 1) := by + have hlim : Tendsto (fun α ↦ 1 + (-log (1 - α))⁻¹) (𝓝[<] 1) (𝓝 1) := by + have h : Tendsto (fun α ↦ -log (1 - α)) (𝓝[<] 1) atTop := + tendsto_neg_atBot_atTop.comp (tendsto_log_nhdsGT_zero.comp tendsto_one_sub_nhdsLT_one) + simpa using h.inv_tendsto_atTop.const_add 1 + refine hlim.congr' ?_ + filter_upwards [Ioo_mem_nhdsLT (zero_lt_one' ℝ)] with α hα + have hlog : log (1 - α) ≠ 0 := (log_neg (sub_pos.2 hα.2) (by linarith [hα.1])).ne + have hr' : r ≠ 0 := hr.ne' + rw [expectedShortfall_of_hasLaw_expMeasure hr hX hα, valueAtRisk_of_hasLaw_expMeasure hr hX hα] + field_simp + ring + +/-! ### The type-I Pareto law -/ + +section Pareto + +variable {t r x : ℝ} + +/-- Below its scale `t` the Pareto law puts no mass: `F(x) = 0` for `x < t`. -/ +theorem cdf_paretoMeasure_of_lt (ht : 0 < t) (hr : 0 < r) (hx : x < t) : + cdf (paretoMeasure t r) x = 0 := by + have := isProbabilityMeasure_paretoMeasure ht hr + rw [cdf_eq_real, paretoMeasure, measureReal_def, withDensity_apply _ measurableSet_Iic, + setLIntegral_congr_fun measurableSet_Iic fun _ hy ↦ paretoPDF_of_lt (lt_of_le_of_lt hy hx), + lintegral_zero, ENNReal.toReal_zero] + +/-- **The Pareto CDF**: `F(x) = 1 − (t/x)^r` for `x ≥ t`. Mathlib states the CDF only as the +integral of the density; the tail integral `∫_x^∞ r t^r y^{−(r+1)} dy = (t/x)^r` evaluates it. -/ +theorem cdf_paretoMeasure_of_le (ht : 0 < t) (hr : 0 < r) (hx : t ≤ x) : + cdf (paretoMeasure t r) x = 1 - (t / x) ^ r := by + have := isProbabilityMeasure_paretoMeasure ht hr + have hx0 : 0 < x := ht.trans_le hx + have hint : IntegrableOn (fun y ↦ r * t ^ r * y ^ (-(r + 1))) (Ioi x) := + (integrableOn_Ioi_rpow_of_lt (by linarith) hx0).const_mul _ + have hnn : 0 ≤ᵐ[volume.restrict (Ioi x)] fun y ↦ r * t ^ r * y ^ (-(r + 1)) := + (ae_restrict_mem measurableSet_Ioi).mono fun y hy ↦ by + have : 0 < y := hx0.trans hy + positivity + rw [cdf_eq_real, ← compl_Ioi, probReal_compl_eq_one_sub measurableSet_Ioi, paretoMeasure, + measureReal_def, withDensity_apply _ measurableSet_Ioi, + setLIntegral_congr_fun measurableSet_Ioi fun _ hy ↦ paretoPDF_of_le (hx.trans (le_of_lt hy)), + ← ofReal_integral_eq_lintegral_ofReal hint hnn, + ENNReal.toReal_ofReal (integral_nonneg_of_ae hnn), + integral_const_mul, integral_Ioi_rpow_of_lt (by linarith) hx0, + div_rpow ht.le hx0.le, show -(r + 1) + 1 = -r by ring, rpow_neg hx0.le] + field_simp + +/-- **The Pareto quantile**: `F⁻¹(p) = t (1 − p)^{−1/r}`. -/ +theorem quantile_paretoMeasure (ht : 0 < t) (hr : 0 < r) (hp : p ∈ Ioo 0 1) : + quantile (paretoMeasure t r) p = t * (1 - p) ^ (-r⁻¹) := by + have h1p : 0 < 1 - p := sub_pos.2 hp.2 + have hs : 1 ≤ (1 - p) ^ (-r⁻¹) := + one_le_rpow_of_pos_of_le_one_of_nonpos h1p (by linarith [hp.1]) (by simp [hr.le]) + have ha : t ≤ t * (1 - p) ^ (-r⁻¹) := le_mul_of_one_le_right ht.le hs + -- the tail ratio at the candidate quantile is `(1 - p)^{1/r}` + have hratio : t / (t * (1 - p) ^ (-r⁻¹)) = (1 - p) ^ r⁻¹ := by + rw [rpow_neg h1p.le, div_mul_eq_div_div, div_self ht.ne', one_div, inv_inv] + have hpow : ((1 - p) ^ r⁻¹) ^ r = 1 - p := by + rw [← rpow_mul h1p.le, inv_mul_cancel₀ hr.ne', rpow_one] + refine (quantile_eq_iff hp).2 ⟨?_, fun y hy ↦ ?_⟩ + · rw [cdf_paretoMeasure_of_le ht hr ha, hratio, hpow, sub_sub_cancel] + · rcases lt_or_ge y t with hyt | hyt + · rw [cdf_paretoMeasure_of_lt ht hr hyt] + exact hp.1 + · have hy0 : 0 < y := ht.trans_le hyt + rw [cdf_paretoMeasure_of_le ht hr hyt] + have hlt : (1 - p) ^ r⁻¹ < t / y := by + rw [← hratio] + exact div_lt_div_of_pos_left ht hy0 hy + have := rpow_lt_rpow (rpow_nonneg h1p.le _) hlt hr + rw [hpow] at this + linarith + +/-- `∫_α^1 (1 − u)^{−1/r} du = r/(r − 1)·(1 − α)^{1 − 1/r}` for `r > 1`: the Pareto quantile is +integrable up to level `1` exactly when the mean is finite. -/ +lemma integral_one_sub_rpow (hα : α < 1) (hr : 1 < r) : + ∫ u in Ioo α 1, (1 - u) ^ (-r⁻¹) = r / (r - 1) * (1 - α) ^ (1 - r⁻¹) := by + have hr0 : r ≠ 0 := (zero_lt_one.trans hr).ne' + have hexp : -1 < -r⁻¹ := neg_lt_neg (inv_lt_one_of_one_lt₀ hr) + have hne : -r⁻¹ + 1 ≠ 0 := by linarith + rw [← integral_Ioc_eq_integral_Ioo, ← intervalIntegral.integral_of_le hα.le, + intervalIntegral.integral_comp_sub_left (fun x ↦ x ^ (-r⁻¹)) 1, sub_self, + integral_rpow (Or.inl hexp), zero_rpow hne, sub_zero, show -r⁻¹ + 1 = 1 - r⁻¹ by ring] + have hr1 : r - 1 ≠ 0 := by linarith + field_simp + +/-- **ES of a Pareto loss** (`r > 1`): `ES_α(X) = r/(r − 1)·VaR_α(X)`, a constant multiple of +`VaR_α` at every level. -/ +theorem expectedShortfall_of_hasLaw_paretoMeasure (ht : 0 < t) (hr : 1 < r) + (hX : HasLaw X (paretoMeasure t r) P) (hα : α ∈ Ioo 0 1) : + expectedShortfall X P α = r / (r - 1) * (t * (1 - α) ^ (-r⁻¹)) := by + have hr0 : 0 < r := zero_lt_one.trans hr + have h1α : 0 < 1 - α := sub_pos.2 hα.2 + have h1α' : 1 - α ≠ 0 := h1α.ne' + have hr1 : r - 1 ≠ 0 := by linarith + rw [expectedShortfall_eq_of_valueAtRisk_eq fun u hu ↦ by + rw [valueAtRisk_eq_quantile hX, quantile_paretoMeasure ht hr0 ⟨hα.1.trans hu.1, hu.2⟩], + integral_const_mul, integral_one_sub_rpow hα.2 hr, sub_eq_add_neg (1 : ℝ) r⁻¹, + rpow_add h1α, rpow_one] + field_simp + +end Pareto + +/-! ### The Lomax (Pareto type II) law -/ + +section Lomax + +variable {θ κ : ℝ} + +/-- The **Lomax** (Pareto type II) law `Pa(θ, κ)`: the type-I Pareto law of scale `κ` and shape +`θ`, shifted to start at `0`. Its CDF is `F(x) = 1 − (κ/(κ + x))^θ` on `[0, ∞)` +(`cdf_lomaxMeasure`); `Pa(θ, 1)` is the Pareto law of the QRM Exercise Book, Exercise 2.12 d). -/ +noncomputable def lomaxMeasure (θ κ : ℝ) : Measure ℝ := + (paretoMeasure κ θ).map fun y ↦ y - κ + +lemma isProbabilityMeasure_lomaxMeasure (hθ : 0 < θ) (hκ : 0 < κ) : + IsProbabilityMeasure (lomaxMeasure θ κ) := + have := isProbabilityMeasure_paretoMeasure hκ hθ + inferInstanceAs (IsProbabilityMeasure ((paretoMeasure κ θ).map (· - κ))) + +/-- **The Lomax CDF**: `F(x) = 1 − (κ/(κ + x))^θ` for `x ≥ 0`. -/ +theorem cdf_lomaxMeasure (hθ : 0 < θ) (hκ : 0 < κ) {x : ℝ} (hx : 0 ≤ x) : + cdf (lomaxMeasure θ κ) x = 1 - (κ / (κ + x)) ^ θ := by + have := isProbabilityMeasure_lomaxMeasure hθ hκ + have := isProbabilityMeasure_paretoMeasure hκ hθ + rw [cdf_eq_real, lomaxMeasure, map_measureReal_apply (measurable_sub_const κ) measurableSet_Iic, + show (fun y ↦ y - κ) ⁻¹' Iic x = Iic (κ + x) by ext y; simp [add_comm], + ← cdf_eq_real, cdf_paretoMeasure_of_le hκ hθ (le_add_of_nonneg_right hx)] + +/-- **The Lomax quantile**: `F⁻¹(p) = κ((1 − p)^{−1/θ} − 1)`. -/ +theorem quantile_lomaxMeasure (hθ : 0 < θ) (hκ : 0 < κ) (hp : p ∈ Ioo 0 1) : + quantile (lomaxMeasure θ κ) p = κ * ((1 - p) ^ (-θ⁻¹) - 1) := by + have := isProbabilityMeasure_paretoMeasure hκ hθ + rw [lomaxMeasure, quantile_map (h := fun y ↦ y - κ) (fun _ _ h ↦ sub_le_sub_right h κ) + (by fun_prop : Continuous fun y : ℝ ↦ y - κ).lowerSemicontinuous hp, + quantile_paretoMeasure hκ hθ hp] + ring + +/-- **VaR of a Lomax loss**: `VaR_α(X) = κ((1 − α)^{−1/θ} − 1)` for `X ~ Pa(θ, κ)` +(QRM Exercise Book, Exercise 2.12 d)). -/ +theorem valueAtRisk_of_hasLaw_lomaxMeasure (hθ : 0 < θ) (hκ : 0 < κ) + (hX : HasLaw X (lomaxMeasure θ κ) P) (hα : α ∈ Ioo 0 1) : + valueAtRisk X P α = κ * ((1 - α) ^ (-θ⁻¹) - 1) := by + rw [valueAtRisk_eq_quantile hX, quantile_lomaxMeasure hθ hκ hα] + +/-- **ES of a Lomax loss** (`θ > 1`, finite mean): `ES_α(X) = κ(θ/(θ − 1)·(1 − α)^{−1/θ} − 1)` +for `X ~ Pa(θ, κ)` (QRM Exercise Book, Exercise 2.12 d)). -/ +theorem expectedShortfall_of_hasLaw_lomaxMeasure (hθ : 1 < θ) (hκ : 0 < κ) + (hX : HasLaw X (lomaxMeasure θ κ) P) (hα : α ∈ Ioo 0 1) : + expectedShortfall X P α = κ * (θ / (θ - 1) * (1 - α) ^ (-θ⁻¹) - 1) := by + have hθ0 : 0 < θ := zero_lt_one.trans hθ + have h1α : 0 < 1 - α := sub_pos.2 hα.2 + have h1α' : 1 - α ≠ 0 := h1α.ne' + have hθ1 : θ - 1 ≠ 0 := by linarith + have hint : IntegrableOn (fun u ↦ (1 - u) ^ (-θ⁻¹)) (Ioo α 1) := by + by_contra h + have h0 := integral_one_sub_rpow hα.2 hθ + rw [integral_undef h] at h0 + have : 0 < θ - 1 := by linarith + have : 0 < θ / (θ - 1) * (1 - α) ^ (1 - θ⁻¹) := by positivity + linarith + rw [expectedShortfall_eq_of_valueAtRisk_eq fun u hu ↦ + valueAtRisk_of_hasLaw_lomaxMeasure hθ0 hκ hX ⟨hα.1.trans hu.1, hu.2⟩, + integral_const_mul, integral_sub hint (integrableOn_const (by simp)), setIntegral_const, + Real.volume_real_Ioo_of_le hα.2.le, smul_eq_mul, mul_one, integral_one_sub_rpow hα.2 hθ, + sub_eq_add_neg (1 : ℝ) θ⁻¹, rpow_add h1α, rpow_one] + field_simp + +/-- **Heavy tail**: for a Lomax loss with `θ > 1` the shortfall-to-quantile ratio tends to +`θ/(θ − 1) > 1`, `ES_α/VaR_α → θ/(θ − 1)` as `α → 1⁻` (QRM Exercise Book, Exercise 2.23 c)). -/ +theorem tendsto_expectedShortfall_div_valueAtRisk_lomaxMeasure (hθ : 1 < θ) (hκ : 0 < κ) + (hX : HasLaw X (lomaxMeasure θ κ) P) : + Tendsto (fun α ↦ expectedShortfall X P α / valueAtRisk X P α) (𝓝[<] 1) + (𝓝 (θ / (θ - 1))) := by + have hθ0 : 0 < θ := zero_lt_one.trans hθ + -- `s = (1 − α)^{−1/θ} → ∞`, and the ratio is `(θ/(θ − 1)·s − 1)/(s − 1)` + have hs : Tendsto (fun α : ℝ ↦ (1 - α) ^ (-θ⁻¹)) (𝓝[<] 1) atTop := + (tendsto_rpow_neg_nhdsGT_zero (neg_neg_of_pos (inv_pos.2 hθ0))).comp + tendsto_one_sub_nhdsLT_one + have hinv := hs.inv_tendsto_atTop + have hlim : Tendsto (fun α ↦ (θ / (θ - 1) - ((1 - α) ^ (-θ⁻¹))⁻¹) / (1 - ((1 - α) ^ (-θ⁻¹))⁻¹)) + (𝓝[<] 1) (𝓝 (θ / (θ - 1))) := by + have h := ((tendsto_const_nhds (x := θ / (θ - 1))).sub hinv).div + ((tendsto_const_nhds (x := (1 : ℝ))).sub hinv) (by norm_num) + rw [sub_zero, sub_zero, div_one] at h + exact h + refine hlim.congr' ?_ + filter_upwards [Ioo_mem_nhdsLT (zero_lt_one' ℝ)] with α hα + have h1α : 0 < 1 - α := sub_pos.2 hα.2 + have hs1 : 1 < (1 - α) ^ (-θ⁻¹) := + one_lt_rpow_of_pos_of_lt_one_of_neg h1α (by linarith [hα.1]) (neg_neg_of_pos (inv_pos.2 hθ0)) + have hne : (1 - α) ^ (-θ⁻¹) - 1 ≠ 0 := (sub_pos.2 hs1).ne' + have hs0 : (1 - α) ^ (-θ⁻¹) ≠ 0 := (zero_lt_one.trans hs1).ne' + have hθ1 : θ - 1 ≠ 0 := by linarith + have hκ' : κ ≠ 0 := hκ.ne' + rw [expectedShortfall_of_hasLaw_lomaxMeasure hθ hκ hX hα, + valueAtRisk_of_hasLaw_lomaxMeasure hθ0 hκ hX hα] + field_simp + +end Lomax + +/-! ### Median shortfall -/ + +section MedianShortfall + +/-- The **median shortfall** of a loss `X` at level `α`: the median of the law of `X` +conditioned on exceeding its value-at-risk, `MS_α(X) = F⁻¹_{X | X > VaR_α(X)}(1/2)`. -/ +noncomputable def medianShortfall (X : Ω → ℝ) (P : Measure Ω) (α : ℝ) : ℝ := + quantile ((P.map X)[|Ioi (valueAtRisk X P α)]) (1 / 2) + +/-- **Median shortfall is a value-at-risk** (QRM Exercise Book, Exercise 2.29 b)): for a loss +with a continuous distribution function, `MS_α(X) = VaR_{(1+α)/2}(X)`. Given that the loss +exceeds `VaR_α`, its conditional CDF is `(F − α)/(1 − α)`, which crosses `1/2` exactly where `F` +crosses `(1 + α)/2`. -/ +theorem medianShortfall_eq_valueAtRisk [IsProbabilityMeasure P] + (hF : Continuous (cdf (P.map X))) (hα : α ∈ Ioo 0 1) : + medianShortfall X P α = valueAtRisk X P ((1 + α) / 2) := by + have h1α : 0 < 1 - α := sub_pos.2 hα.2 + have hv : cdf (P.map X) (valueAtRisk X P α) = α := cdf_quantile hF hα + -- the tail beyond `VaR_α` carries mass `1 − α` + have hmass : (P.map X) (Ioi (valueAtRisk X P α)) = ENNReal.ofReal (1 - α) := by + rw [← compl_Iic, prob_compl_eq_one_sub measurableSet_Iic, ← ofReal_cdf, hv, + ENNReal.ofReal_sub _ hα.1.le, ENNReal.ofReal_one] + have hne : (P.map X) (Ioi (valueAtRisk X P α)) ≠ 0 := by + rw [hmass] + exact (ENNReal.ofReal_pos.2 h1α).ne' + have := cond_isProbabilityMeasure (μ := P.map X) hne + -- the distribution function of the tail law is `(F − α)/(1 − α)` beyond `VaR_α` + have hcdf (x : ℝ) : cdf ((P.map X)[|Ioi (valueAtRisk X P α)]) x = + if valueAtRisk X P α ≤ x then (cdf (P.map X) x - α) / (1 - α) else 0 := by + rw [cdf_eq_real, measureReal_def, cond_apply measurableSet_Ioi, hmass, Ioi_inter_Iic] + split_ifs with hvx + · have hIoc := (cdf (P.map X)).measure_Ioc (valueAtRisk X P α) x + rw [measure_cdf] at hIoc + rw [hIoc, hv, ENNReal.toReal_mul, ENNReal.toReal_inv, ENNReal.toReal_ofReal h1α.le, + ENNReal.toReal_ofReal (sub_nonneg.2 (hv ▸ monotone_cdf (P.map X) hvx))] + ring + · rw [Ioc_eq_empty_of_le (not_le.1 hvx).le, measure_empty, mul_zero, ENNReal.toReal_zero] + change quantile _ (1 / 2) = quantile (P.map X) ((1 + α) / 2) + unfold quantile + congr 1 + ext x + simp only [mem_ofPred_eq] + rw [hcdf x] + split_ifs with hvx + · rw [le_div_iff₀ h1α] + constructor <;> intro h <;> linarith + · have hFx : cdf (P.map X) x ≤ α := hv ▸ monotone_cdf (P.map X) (not_le.1 hvx).le + constructor <;> intro h <;> linarith [hα.2] + +end MedianShortfall + +end MathFin diff --git a/LeanPool/MathFin/Risk/RockafellarUryasev.lean b/LeanPool/MathFin/Risk/RockafellarUryasev.lean new file mode 100644 index 0000000000..59ae83a304 --- /dev/null +++ b/LeanPool/MathFin/Risk/RockafellarUryasev.lean @@ -0,0 +1,231 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.Gaussian +public import LeanPool.MathFin.Probability.Gaussian.StandardNormal +public import LeanPool.MathFin.Probability.Gaussian.GaussianPartialMoments +public import Mathlib.Algebra.Order.Star.Real + +/-! +# The Rockafellar–Uryasev variational characterization of Gaussian CVaR + +For a Gaussian loss `L = μ + σ·Z`, `Z ~ N(0,1)`, the Rockafellar–Uryasev (2000) +theorem characterizes CVaR as the *minimum* of the one-parameter objective + + `g(c) = c + E[(L − c)⁺] / (1 − α)`, + +attained at `c = VaR_α(L)`. This file proves the full variational statement +(`gaussianCVaR_isLeast_ruObjective`) for the quantile-parametrized Gaussian +closed forms of `Risk/Gaussian.lean` (`z` with `Φ(z) = α`; the repo +carries no `Φ⁻¹` API because Mathlib has none at the pin). The file previously +recorded only the algebraic additive decomposition +(`gaussianCVaR_eq_VaR_plus_tail_term`, kept below) and explicitly deferred the +variational theorem; that debt is now discharged. + +The minimality proof is the *pointwise certificate* argument, not calculus: +for every threshold `c`, + + `(L − c)⁺ ≥ (L − c) · 𝟙_{Z > z}` pointwise, + +and integrating against the Gaussian density turns the right side into +`(μ − c)(1 − α) + σ·ϕ(z)`, whence `g(c) ≥ μ + σ·ϕ(z)/(1−α) = CVaR_α`. At +`c = VaR_α` the certificate is *exact* — the positive part vanishes precisely +off the tail event — which is **why** the R-U minimum is attained at VaR: the +`α`-tail event itself certifies optimality. + +The expected-shortfall integral is the standard-normal stop-loss transform +`E[(Z − z)⁺] = ϕ(z) − z(1 − Φ(z))` (`integral_max_sub_mul_gaussianPDFReal`), built in +`Probability/Gaussian/GaussianPartialMoments` from the truncated first moment and the tail mass. + +## Main definitions + +* `ruObjective`: the Rockafellar–Uryasev objective `g(c) = c + E[(L − c)⁺] / (1 − α)` of a + Gaussian loss `L = μ + σ Z`. + +## Main results + +* `integral_shortfall_gaussian`: for `σ > 0`, the closed form of `E[(μ + σ Z − c)⁺]`. +* `ruObjective_at_gaussianVaR`: `g(VaR_α) = CVaR_α` (the minimum value). +* `gaussianCVaR_le_ruObjective`: `g(c) ≥ CVaR_α` for every `c` (minimality). +* `gaussianCVaR_isLeast_ruObjective`: the packaged R-U theorem — + `CVaR_α = min_c g(c)`, attained at `VaR_α`. +* `gaussianCVaR_eq_VaR_plus_tail_term`: the algebraic additive decomposition + `CVaR = VaR + σ·(ϕ(z)/(1−α) − z)` (the original scope of this file). + +## References + +* [Rockafellar and Uryasev (2000)][RockafellarUryasev2000] + +## Tags + +Rockafellar-Uryasev, CVaR minimization, variational characterization, Gaussian CVaR, +stop-loss transform, expected shortfall, MSC 91G70, MSC 90C25, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Real + +/-- The **Rockafellar–Uryasev objective** for a Gaussian loss `L = μ + σ·Z`: +`g(c) = c + E[(L − c)⁺]/(1 − α)`, the expectation written against the +standard-normal density. -/ +noncomputable def ruObjective (μ σ α c : ℝ) : ℝ := + c + (∫ x, max (μ + σ * x - c) 0 * gaussianPDFReal 0 1 x) / (1 - α) + +/-- Integrability of the shortfall integrand `x ↦ max(μ + σx − c, 0)·ϕ(x)`: +dominated by `(|μ − c| + |σ|·|x|)·ϕ(x)`, whose pieces are the Gaussian mass and +the (absolute) first moment. -/ +lemma integrable_shortfall (μ σ c : ℝ) : + Integrable (fun x ↦ max (μ + σ * x - c) 0 * gaussianPDFReal 0 1 x) volume := by + have h_meas : AEStronglyMeasurable + (fun x ↦ max (μ + σ * x - c) 0 * gaussianPDFReal 0 1 x) volume := + ((((measurable_const.add (measurable_const.mul measurable_id)).sub + measurable_const).max measurable_const).mul + (measurable_gaussianPDFReal 0 1)).aestronglyMeasurable + have h_dom : Integrable + (fun x ↦ |μ - c| * gaussianPDFReal 0 1 x + |σ| * |x * gaussianPDFReal 0 1 x|) + volume := + ((integrable_gaussianPDFReal 0 1).const_mul _).add + (integrable_id_mul_gaussianPDFReal_volume.abs.const_mul _) + refine h_dom.mono' h_meas (Filter.Eventually.of_forall fun x ↦ ?_) + have h_pdf_nn : 0 ≤ gaussianPDFReal 0 1 x := gaussianPDFReal_nonneg 0 1 x + have h_max_nn : 0 ≤ max (μ + σ * x - c) 0 := le_max_right _ _ + rw [Real.norm_eq_abs, abs_of_nonneg (mul_nonneg h_max_nn h_pdf_nn)] + have h_max_le : max (μ + σ * x - c) 0 ≤ |μ - c| + |σ| * |x| := by + rcases max_cases (μ + σ * x - c) 0 with ⟨h_eq, _⟩ | ⟨h_eq, _⟩ + · rw [h_eq] + calc μ + σ * x - c = (μ - c) + σ * x := by ring + _ ≤ |μ - c| + |σ * x| := add_le_add (le_abs_self _) (le_abs_self _) + _ = |μ - c| + |σ| * |x| := by rw [abs_mul] + · rw [h_eq]; positivity + calc max (μ + σ * x - c) 0 * gaussianPDFReal 0 1 x + ≤ (|μ - c| + |σ| * |x|) * gaussianPDFReal 0 1 x := + mul_le_mul_of_nonneg_right h_max_le h_pdf_nn + _ = |μ - c| * gaussianPDFReal 0 1 x + |σ| * (|x| * gaussianPDFReal 0 1 x) := by + ring + _ = |μ - c| * gaussianPDFReal 0 1 x + |σ| * |x * gaussianPDFReal 0 1 x| := by + rw [abs_mul, abs_of_nonneg h_pdf_nn] + +/-- **Affine-loss expected shortfall closed form**: for `L = μ + σ·Z` with +`σ > 0` and `z_c = (c − μ)/σ`, + + `E[(L − c)⁺] = σ·(ϕ(z_c) − z_c·(1 − Φ(z_c)))`. -/ +lemma integral_shortfall_gaussian (μ σ c : ℝ) (hσ : 0 < σ) : + ∫ x, max (μ + σ * x - c) 0 * gaussianPDFReal 0 1 x + = σ * (gaussianPDFReal 0 1 ((c - μ) / σ) + - (c - μ) / σ * (1 - Phi ((c - μ) / σ))) := by + have h_eq : (fun x ↦ max (μ + σ * x - c) 0 * gaussianPDFReal 0 1 x) + = fun x ↦ σ * (max (x - (c - μ) / σ) 0 * gaussianPDFReal 0 1 x) := by + funext x + have h_arg : μ + σ * x - c = σ * (x - (c - μ) / σ) := by field_simp; ring + have h_scale : max (σ * (x - (c - μ) / σ)) 0 = σ * max (x - (c - μ) / σ) 0 := by + rw [mul_max_of_nonneg _ _ hσ.le, mul_zero] + rw [h_arg, h_scale, mul_assoc] + rw [h_eq, integral_const_mul, integral_max_sub_mul_gaussianPDFReal] + +/-- **The R-U objective attains CVaR at VaR**: `g(VaR_α) = CVaR_α` when +`Φ(z) = α < 1`. At `c = VaR = μ + σz` the shortfall threshold is exactly the +quantile, so the certificate is tight and the `z·(1 − Φ(z))` terms cancel. -/ +theorem ruObjective_at_gaussianVaR (μ σ z α : ℝ) (hσ : 0 < σ) + (hzα : Phi z = α) (hα1 : α < 1) : + ruObjective μ σ α (gaussianVaR μ σ z) = gaussianCVaR μ σ z α := by + unfold ruObjective gaussianVaR gaussianCVaR + rw [integral_shortfall_gaussian _ _ _ hσ, + show (μ + σ * z - μ) / σ = z from by field_simp; ring, hzα] + have h1α : (1 : ℝ) - α ≠ 0 := sub_ne_zero.2 hα1.ne' + field_simp + ring + +/-- **The R-U inequality** — minimality of CVaR over the whole objective: for +every threshold `c`, `CVaR_α ≤ g(c)`. + +The proof is the pointwise certificate `(L − c)⁺ ≥ (L − c)·𝟙_{Z > z}`: +integrating against `ϕ` gives `E[(L − c)⁺] ≥ (μ − c)(1 − α) + σ·ϕ(z)`, and the +right side reassembles to `CVaR` after dividing by `1 − α`. No calculus, no +convexity machinery — the `α`-tail event itself certifies the minimum. -/ +theorem gaussianCVaR_le_ruObjective (μ σ z α c : ℝ) + (hzα : Phi z = α) (hα1 : α < 1) : + gaussianCVaR μ σ z α ≤ ruObjective μ σ α c := by + have h1α : 0 < 1 - α := sub_pos.2 hα1 + have h_int_const : IntegrableOn (fun x ↦ (μ - c) * gaussianPDFReal 0 1 x) + (Set.Ioi z) volume := + ((integrable_gaussianPDFReal 0 1).const_mul _).integrableOn + have h_int_lin : IntegrableOn (fun x ↦ σ * (x * gaussianPDFReal 0 1 x)) + (Set.Ioi z) volume := + (integrable_id_mul_gaussianPDFReal_volume.const_mul _).integrableOn + have h_tail_int : IntegrableOn + (fun x ↦ (μ + σ * x - c) * gaussianPDFReal 0 1 x) (Set.Ioi z) volume := + (h_int_const.add h_int_lin).congr_fun + (fun x _ ↦ by simp only [Pi.add_apply]; ring) measurableSet_Ioi + -- the certificate, integrated: ∫_{Ioi z} (μ + σx − c)·ϕ ≤ E[(L−c)⁺] + have h_cert : ∫ x in Set.Ioi z, (μ + σ * x - c) * gaussianPDFReal 0 1 x + ≤ ∫ x, max (μ + σ * x - c) 0 * gaussianPDFReal 0 1 x := by + rw [← integral_indicator measurableSet_Ioi] + refine integral_mono (h_tail_int.integrable_indicator measurableSet_Ioi) + (integrable_shortfall μ σ c) (fun x ↦ ?_) + have h_pdf_nn : 0 ≤ gaussianPDFReal 0 1 x := gaussianPDFReal_nonneg 0 1 x + by_cases hx : x ∈ Set.Ioi z + · rw [Set.indicator_of_mem hx] + exact mul_le_mul_of_nonneg_right (le_max_left _ _) h_pdf_nn + · rw [Set.indicator_of_notMem hx] + exact mul_nonneg (le_max_right _ _) h_pdf_nn + -- the certificate's value: (μ − c)·(1 − α) + σ·ϕ(z) + have h_tail_val : ∫ x in Set.Ioi z, (μ + σ * x - c) * gaussianPDFReal 0 1 x + = (μ - c) * (1 - α) + σ * gaussianPDFReal 0 1 z := by + calc ∫ x in Set.Ioi z, (μ + σ * x - c) * gaussianPDFReal 0 1 x + = ∫ x in Set.Ioi z, ((μ - c) * gaussianPDFReal 0 1 x + + σ * (x * gaussianPDFReal 0 1 x)) := by + congr 1; funext x; ring + _ = (∫ x in Set.Ioi z, (μ - c) * gaussianPDFReal 0 1 x) + + ∫ x in Set.Ioi z, σ * (x * gaussianPDFReal 0 1 x) := + integral_add h_int_const h_int_lin + _ = (μ - c) * (1 - α) + σ * gaussianPDFReal 0 1 z := by + rw [integral_const_mul, integral_const_mul, + integral_gaussianPDFReal_Ioi, integral_id_mul_gaussianPDFReal_Ioi, hzα] + -- reassemble: c + E[(L−c)⁺]/(1−α) ≥ c + ((μ−c)(1−α) + σϕ(z))/(1−α) = CVaR + unfold ruObjective gaussianCVaR + have h_num : (μ - c) * (1 - α) + σ * gaussianPDFReal 0 1 z + ≤ ∫ x, max (μ + σ * x - c) 0 * gaussianPDFReal 0 1 x := + h_tail_val ▸ h_cert + have h_div : ((μ - c) * (1 - α) + σ * gaussianPDFReal 0 1 z) / (1 - α) + ≤ (∫ x, max (μ + σ * x - c) 0 * gaussianPDFReal 0 1 x) / (1 - α) := by + gcongr + have h_id : μ + σ * (gaussianPDFReal 0 1 z / (1 - α)) + = c + ((μ - c) * (1 - α) + σ * gaussianPDFReal 0 1 z) / (1 - α) := by + rw [add_div, mul_div_cancel_right₀ _ h1α.ne'] + ring + linarith + +/-- **The Rockafellar–Uryasev theorem for the Gaussian loss** (packaged): +`CVaR_α` is the *least value* of the objective `g(c) = c + E[(L − c)⁺]/(1−α)` +over all thresholds `c`, and the minimum is attained at `c = VaR_α`. -/ +theorem gaussianCVaR_isLeast_ruObjective (μ σ z α : ℝ) (hσ : 0 < σ) + (hzα : Phi z = α) (hα1 : α < 1) : + IsLeast (Set.range (ruObjective μ σ α)) (gaussianCVaR μ σ z α) := + ⟨⟨gaussianVaR μ σ z, ruObjective_at_gaussianVaR μ σ z α hσ hzα hα1⟩, + by rintro y ⟨c, rfl⟩; exact gaussianCVaR_le_ruObjective μ σ z α c hzα hα1⟩ + +/-- **Gaussian CVaR additive decomposition** (the original, purely algebraic +content of this file): rearranging the gaussian closed forms, + +`CVaR_α = VaR_α + σ · [ϕ(z)/(1 − α) − z]`. + +Pure `ring` rearrangement of the definitions — the same content as +`gaussianCVaR_sub_VaR`, in additive form. The variational theorem it used to +defer is now `gaussianCVaR_isLeast_ruObjective` above. -/ +lemma gaussianCVaR_eq_VaR_plus_tail_term (μ σ z α : ℝ) : + gaussianCVaR μ σ z α = + gaussianVaR μ σ z + + σ * (gaussianPDFReal 0 1 z / (1 - α) - z) := by + unfold gaussianCVaR gaussianVaR + ring + +end MathFin diff --git a/LeanPool/MathFin/Risk/SACCRExposure.lean b/LeanPool/MathFin/Risk/SACCRExposure.lean new file mode 100644 index 0000000000..27f19c1a82 --- /dev/null +++ b/LeanPool/MathFin/Risk/SACCRExposure.lean @@ -0,0 +1,319 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye, Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Portfolio.CovariancePSD + +/-! +# Basel SA-CCR: exposure at default and effective notional aggregation + +The Basel III **Standardised Approach for Counterparty Credit Risk** (SA-CCR, BCBS 279) +computes the exposure at default of a derivatives netting set as + + `EAD = α · (RC + PFE)`, + +where `RC` is the replacement cost, `PFE` is the potential future exposure add-on, and the +regulator fixes `α = 1.4`. Here `RC` and `PFE` enter as free real numbers: their construction +from supervisory factors (the replacement cost, the PFE multiplier, the asset-class add-ons) is not +formalized, apart from the two-bucket interest-rate effective notional below. We record the +formula and its one structural fact: `EAD` is nondecreasing in `RC` and in `PFE`, jointly, for any +fixed `α ≥ 0`, so netting or hedging that lowers one component without raising the other can only +lower (never raise) the capital exposure. + +The other SA-CCR building block with algebraic content is the **effective notional** of an +interest-rate hedging set. SA-CCR splits the trades of one currency into three maturity buckets +(under one year, one to five years, over five years) with signed bucket effective notionals +`D₁, D₂, D₃`, and aggregates them as + + `EffectiveNotional = √(D₁² + D₂² + D₃² + 1.4·D₁·D₂ + 1.4·D₂·D₃ + 0.6·D₁·D₃)`, + +that is, with correlation `0.7` between adjacent buckets and `0.3` between the first and the third +(Basel Framework CRE52.57). This is `effNotionalIR`, and it never exceeds `|D₁| + |D₂| + |D₃|` +(`effNotionalIR_le_abs_add`). With one bucket empty it is + + `effNotionalPair ρ d₁ d₂ = √(d₁² + d₂² + 2ρ·d₁·d₂)` + +at `ρ = 0.7` (third bucket empty, `effNotionalIR_third_zero`) or `ρ = 0.3` (middle bucket empty, +`effNotionalIR_second_zero`). The two-bucket form is the same quadratic form +as the standard deviation of a sum of two correlated risks. It is not the single-factor +aggregation that SA-CCR uses for the credit, equity and commodity classes, +`√((Σₖ ρₖ·Aₖ)² + Σₖ (1 − ρₖ²)·Aₖ²)` over entity-level add-ons `Aₖ`, whose two-entity cross term +with equal `ρ` is `2ρ²·A₁·A₂`. We prove that `effNotionalPair` collapses to `|d₁ + d₂|` at `ρ = 1` +(full correlation, no diversification benefit) and to `√(d₁² + d₂²)` at `ρ = 0`, that it never +exceeds `|d₁| + |d₂|` for `ρ ∈ [-1, 1]` (no *negative* diversification: recognising offset across +buckets never gives more than adding the absolute bucket notionals), and that for `ρ ≥ 0` and both +notionals nonnegative, growing `d₁` never shrinks the aggregate (`effNotionalPair_mono_left`; the +formula is symmetric in `d₁, d₂`, so the same holds for `d₂` by relabelling; that version is not +stated). + +**The effective notional is a standard deviation.** Its radicand is the Markowitz quadratic form +`∑ᵢⱼ DᵢDⱼρᵢⱼ` (`portfolioVarN`, `Choice/Portfolio/MarkowitzNAsset.lean`) of the bucket notionals +under the +supervisory correlation matrix `saccrIRCorrelation` (`effNotionalIR_eq_sqrt_portfolioVarN`). So if +the three bucket risk factors `Zᵢ` have unit variances and the supervisory correlations as +covariances, `effNotionalIR` is the standard deviation of the hedging-set exposure `∑ Dᵢ Zᵢ` +(`effNotionalIR_eq_sqrt_variance`, through `portfolioVarN_covariance_eq_variance` of +`Choice/Portfolio/CovariancePSD.lean`). The supervisory matrix is positive semidefinite: the +radicand is a sum of squares, nonnegative for every hedging set, so the square root never truncates +(`effNotionalIR_radicand_nonneg`, `effNotionalIR_sq`). The bound "never more than adding the +absolute notionals" holds for every kernel with entries in `[-1, 1]` +(`sqrt_portfolioVarN_le_sum_abs`), and both `effNotionalIR_le_abs_add` and +`effNotionalPair_le_abs_add` are proved as its instances. The bucket risk factors themselves are +not part of the Basel formula; the theorem says which variance the formula computes. + +## Main definitions + +* `saccrEAD`: `α · (RC + PFE)`. +* `effNotionalIR`: the CRE52.57 interest-rate effective notional of three maturity buckets. +* `effNotionalPair`: the two-bucket aggregation `√(d₁² + d₂² + 2ρ·d₁·d₂)` at a general `ρ`. +* `saccrIRCorrelation`: the CRE52.57 correlation matrix of the three maturity buckets. + +## Main results + +* `saccrEAD_mono_rc`, `saccrEAD_mono_pfe`: `EAD` is monotone in `RC` and in `PFE` for `α ≥ 0`. +* `saccrEAD_mono`: `EAD` is jointly monotone in `(RC, PFE)` for `α ≥ 0`. +* `effNotionalPair_nonneg`: the aggregated notional is nonnegative. +* `effNotionalPair_eq_abs_add_of_corr_one`: at `ρ = 1`, `effNotionalPair = |d₁ + d₂|`. +* `effNotionalPair_eq_hypot_of_corr_zero`: at `ρ = 0`, `effNotionalPair = √(d₁² + d₂²)`. +* `effNotionalPair_le_abs_add`: for `ρ ∈ [-1, 1]`, the aggregation never exceeds `|d₁| + |d₂|` (no + negative diversification). +* `effNotionalPair_mono_left`: for `ρ ≥ 0` and `d₂ ≥ 0`, the aggregation is monotone in `d₁` on + `[0, ∞)`. +* `effNotionalIR_le_abs_add`: the three-bucket effective notional never exceeds + `|D₁| + |D₂| + |D₃|`. +* `effNotionalIR_third_zero`, `effNotionalIR_second_zero`: with one bucket empty it is + `effNotionalPair` at `0.7` or `0.3`. +* `sqrt_portfolioVarN_le_sum_abs`: for a kernel with entries in `[-1, 1]`, the square root of the + quadratic form never exceeds the sum of the absolute weights. +* `effNotionalIR_eq_sqrt_portfolioVarN`, `effNotionalPair_eq_sqrt_portfolioVarN`: the effective + notionals as square roots of Markowitz quadratic forms. +* `effNotionalIR_eq_sqrt_variance`: the effective notional is the standard deviation of the + hedging-set exposure under unit-variance factors with the supervisory correlations. +* `effNotionalIR_radicand_nonneg`, `effNotionalIR_sq`: the supervisory correlation matrix is + positive semidefinite, and the effective notional squares to its radicand. + +## References + +* [Basel Committee on Banking Supervision, *The standardised approach for measuring counterparty + credit risk exposures*][BCBS279] (the EAD formula and the interest-rate effective + notional). +* [Basel Committee on Banking Supervision, *The Basel Framework*, CRE52][BaselFrameworkCRE52], + CRE52.57. + +## Tags + +SA-CCR, exposure at default, counterparty credit risk, Basel III, effective notional, +replacement cost, potential future exposure, MSC 91G40, MSC 91G70, JEL G28, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open Real + +/-! ## Exposure at default -/ + +/-- The Basel SA-CCR exposure-at-default formula `EAD = α · (RC + PFE)`, where `RC` is the +replacement cost and `PFE` the potential future exposure add-on. The regulator fixes +`α = 1.4` (`saccrAlpha`), but we keep it as a parameter since the only mathematical content is +the arithmetic combination, not the specific constant. -/ +noncomputable def saccrEAD (α RC PFE : ℝ) : ℝ := α * (RC + PFE) + +/-- The regulatory value of `α` fixed by Basel SA-CCR (BCBS 279). -/ +noncomputable def saccrAlpha : ℝ := 1.4 + +/-- `saccrAlpha` is positive, so `saccrEAD saccrAlpha` inherits the monotonicity lemmas below at +the regulatory value of `α`. -/ +theorem saccrAlpha_pos : 0 < saccrAlpha := by norm_num [saccrAlpha] + +/-- `EAD` is monotone increasing in the replacement cost `RC`, for any fixed `α ≥ 0`. -/ +theorem saccrEAD_mono_rc {α : ℝ} (hα : 0 ≤ α) {PFE : ℝ} : + Monotone (fun RC ↦ saccrEAD α RC PFE) := by + intro RC₁ RC₂ h + simp only [saccrEAD] + gcongr + +/-- `EAD` is monotone increasing in the PFE add-on, for any fixed `α ≥ 0`. -/ +theorem saccrEAD_mono_pfe {α : ℝ} (hα : 0 ≤ α) {RC : ℝ} : + Monotone (fun PFE ↦ saccrEAD α RC PFE) := by + intro PFE₁ PFE₂ h + simp only [saccrEAD] + gcongr + +/-- `EAD` is jointly monotone: raising `RC` and/or `PFE` never lowers the exposure, for +`α ≥ 0`. -/ +theorem saccrEAD_mono {α : ℝ} (hα : 0 ≤ α) {RC₁ RC₂ PFE₁ PFE₂ : ℝ} + (hRC : RC₁ ≤ RC₂) (hPFE : PFE₁ ≤ PFE₂) : + saccrEAD α RC₁ PFE₁ ≤ saccrEAD α RC₂ PFE₂ := by + unfold saccrEAD + gcongr + +/-! ## Effective notional aggregation + +SA-CCR aggregates the signed maturity-bucket effective notionals of an interest-rate hedging set +with correlation `0.7` between adjacent buckets and `0.3` between the first and the third +(CRE52.57, `effNotionalIR` at the end of this section). `effNotionalPair` below is the +two-bucket quadratic form for a general correlation `ρ`; at `ρ = 0.7` or `ρ = 0.3` it is that +aggregation with one bucket empty (`effNotionalIR_third_zero`, `effNotionalIR_second_zero`). -/ + +/-- The two-bucket aggregation `√(d₁² + d₂² + 2ρ·d₁·d₂)` of signed bucket effective notionals +`d₁, d₂` at correlation `ρ`. At `ρ = 0.7` (adjacent buckets) or `ρ = 0.3` (the first and third) +it is the interest-rate effective notional `effNotionalIR` of Basel Framework CRE52.57 for a +hedging set with the remaining bucket empty (`effNotionalIR_third_zero`, +`effNotionalIR_second_zero`). -/ +noncomputable def effNotionalPair (ρ d₁ d₂ : ℝ) : ℝ := √(d₁ ^ 2 + d₂ ^ 2 + 2 * ρ * d₁ * d₂) + +theorem effNotionalPair_nonneg (ρ d₁ d₂ : ℝ) : 0 ≤ effNotionalPair ρ d₁ d₂ := + Real.sqrt_nonneg _ + +/-- At full correlation `ρ = 1` the aggregation collapses to `|d₁ + d₂|`: no diversification +benefit, the signed bucket notionals simply add. -/ +theorem effNotionalPair_eq_abs_add_of_corr_one (d₁ d₂ : ℝ) : + effNotionalPair 1 d₁ d₂ = |d₁ + d₂| := by + unfold effNotionalPair + rw [show d₁ ^ 2 + d₂ ^ 2 + 2 * 1 * d₁ * d₂ = (d₁ + d₂) ^ 2 by ring] + exact Real.sqrt_sq_eq_abs _ + +/-- At zero correlation the aggregation is the Euclidean (independent-risk) combination. -/ +theorem effNotionalPair_eq_hypot_of_corr_zero (d₁ d₂ : ℝ) : + effNotionalPair 0 d₁ d₂ = √(d₁ ^ 2 + d₂ ^ 2) := by + unfold effNotionalPair; ring_nf + +/-- `effNotionalPair` is monotone in `d₁` on `[0, ∞)`, for `ρ ≥ 0` and `d₂ ≥ 0`: increasing a +nonnegative bucket notional `d₁` never decreases the aggregate when the correlation and the other +notional are both nonnegative. -/ +theorem effNotionalPair_mono_left {ρ : ℝ} (hρ : 0 ≤ ρ) {d₂ : ℝ} (hd₂ : 0 ≤ d₂) : + MonotoneOn (fun d₁ ↦ effNotionalPair ρ d₁ d₂) (Set.Ici (0 : ℝ)) := by + intro d₁ hd₁ d₁' hd₁' h + simp only [Set.mem_Ici] at hd₁ hd₁' + unfold effNotionalPair + apply Real.sqrt_le_sqrt + nlinarith [mul_nonneg (mul_nonneg hρ hd₂) (sub_nonneg.mpr h), mul_le_mul h h hd₁ (hd₁.trans h)] + +/-- **The SA-CCR interest-rate effective notional** of a hedging set (Basel Framework CRE52.57): +`√(D₁² + D₂² + D₃² + 1.4·D₁·D₂ + 1.4·D₂·D₃ + 0.6·D₁·D₃)` for the signed effective notionals +`D₁, D₂, D₃` of its three maturity buckets (under one year, one to five years, over five years). +The bucket notionals themselves (supervisory duration, delta, maturity factor) are inputs. -/ +noncomputable def effNotionalIR (D₁ D₂ D₃ : ℝ) : ℝ := + √(D₁ ^ 2 + D₂ ^ 2 + D₃ ^ 2 + 7 / 5 * D₁ * D₂ + 7 / 5 * D₂ * D₃ + 3 / 5 * D₁ * D₃) + +/-- With the third bucket empty, the SA-CCR effective notional is `effNotionalPair` at the +adjacent-bucket correlation `0.7`. -/ +theorem effNotionalIR_third_zero (D₁ D₂ : ℝ) : + effNotionalIR D₁ D₂ 0 = effNotionalPair (7 / 10) D₁ D₂ := by + unfold effNotionalIR effNotionalPair + congr 1 + ring + +/-- With the middle bucket empty, the SA-CCR effective notional is `effNotionalPair` at the +first-to-third-bucket correlation `0.3`. -/ +theorem effNotionalIR_second_zero (D₁ D₃ : ℝ) : + effNotionalIR D₁ 0 D₃ = effNotionalPair (3 / 10) D₁ D₃ := by + unfold effNotionalIR effNotionalPair + congr 1 + ring + +/-! ## The effective notional as a standard deviation -/ + +/-- **No negative diversification for a correlation-bounded kernel**: if every entry of the kernel +`c` on `s` lies in `[-1, 1]`, the square root of the quadratic form `∑ᵢⱼ wᵢwⱼcᵢⱼ` never exceeds +`∑ᵢ |wᵢ|`, because each term is at most `|wᵢ||wⱼ|`. -/ +theorem sqrt_portfolioVarN_le_sum_abs {ι : Type*} (s : Finset ι) (w : ι → ℝ) {c : ι → ι → ℝ} + (hc : ∀ i ∈ s, ∀ j ∈ s, |c i j| ≤ 1) : + √(portfolioVarN s w c) ≤ ∑ i ∈ s, |w i| := by + unfold portfolioVarN + rw [Real.sqrt_le_left (Finset.sum_nonneg fun i _ ↦ abs_nonneg (w i)), sq, Finset.sum_mul_sum] + refine Finset.sum_le_sum fun i hi ↦ Finset.sum_le_sum fun j hj ↦ ?_ + calc w i * w j * c i j ≤ |w i * w j * c i j| := le_abs_self _ + _ = |w i| * |w j| * |c i j| := by rw [abs_mul, abs_mul] + _ ≤ |w i| * |w j| * 1 := mul_le_mul_of_nonneg_left (hc i hi j hj) (by positivity) + _ = |w i| * |w j| := mul_one _ + +/-- The supervisory correlations between the three maturity buckets of an interest-rate hedging +set (Basel Framework CRE52.57): `1` on the diagonal, `0.7` between adjacent buckets and `0.3` +between the first and the third. -/ +noncomputable def saccrIRCorrelation : Fin 3 → Fin 3 → ℝ := + ![![1, 7 / 10, 3 / 10], ![7 / 10, 1, 7 / 10], ![3 / 10, 7 / 10, 1]] + +/-- **The effective notional is the square root of a Markowitz quadratic form**: `effNotionalIR` +is `√(∑ᵢⱼ DᵢDⱼρᵢⱼ)` with the supervisory correlations `ρ = saccrIRCorrelation`. -/ +theorem effNotionalIR_eq_sqrt_portfolioVarN (D : Fin 3 → ℝ) : + effNotionalIR (D 0) (D 1) (D 2) = √(portfolioVarN Finset.univ D saccrIRCorrelation) := by + simp only [effNotionalIR, portfolioVarN, saccrIRCorrelation, Fin.sum_univ_three, + Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, Matrix.head_cons, + Matrix.tail_cons] + congr 1 + ring + +/-- The two-bucket aggregation is the square root of the quadratic form of the correlation +matrix `!![1, ρ; ρ, 1]`. -/ +theorem effNotionalPair_eq_sqrt_portfolioVarN (ρ d₁ d₂ : ℝ) : + effNotionalPair ρ d₁ d₂ = √(portfolioVarN Finset.univ ![d₁, d₂] ![![1, ρ], ![ρ, 1]]) := by + simp only [effNotionalPair, portfolioVarN, Fin.sum_univ_two, Matrix.cons_val_zero, + Matrix.cons_val_one] + congr 1 + ring + +/-- For a correlation `ρ ∈ [-1, 1]` (which contains Basel's `0.7` and `0.3`), the aggregated +notional never exceeds the sum of the absolute bucket notionals: there is no *negative* +diversification from this formula. This is `sqrt_portfolioVarN_le_sum_abs` at the kernel +`!![1, ρ; ρ, 1]`. The bound fails outside `[-1, 1]`, e.g. `ρ = -5`, `d₁ = 1`, `d₂ = -1` gives +`effNotionalPair = √12 > 2`. -/ +theorem effNotionalPair_le_abs_add {ρ : ℝ} (hρ1 : -1 ≤ ρ) (hρ2 : ρ ≤ 1) (d₁ d₂ : ℝ) : + effNotionalPair ρ d₁ d₂ ≤ |d₁| + |d₂| := by + have h := sqrt_portfolioVarN_le_sum_abs Finset.univ ![d₁, d₂] (c := ![![1, ρ], ![ρ, 1]]) + (by norm_num [Fin.forall_fin_succ, abs_le, hρ1, hρ2]) + rw [← effNotionalPair_eq_sqrt_portfolioVarN] at h + simpa only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one] using h + +/-- **No negative diversification across the three buckets**: the SA-CCR interest-rate effective +notional never exceeds the sum of the absolute bucket notionals. This is +`sqrt_portfolioVarN_le_sum_abs` at the supervisory correlations, whose entries lie in `[0, 1]`. -/ +theorem effNotionalIR_le_abs_add (D₁ D₂ D₃ : ℝ) : + effNotionalIR D₁ D₂ D₃ ≤ |D₁| + |D₂| + |D₃| := by + have h := sqrt_portfolioVarN_le_sum_abs Finset.univ ![D₁, D₂, D₃] (c := saccrIRCorrelation) + (by norm_num [Fin.forall_fin_succ, saccrIRCorrelation, Matrix.cons_val_two, abs_le]) + rw [← effNotionalIR_eq_sqrt_portfolioVarN] at h + simpa only [Fin.sum_univ_three, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val_two, + Matrix.head_cons, Matrix.tail_cons] using h + +section Variance + +open MeasureTheory ProbabilityTheory + +/-- **The effective notional is the standard deviation of the hedging-set exposure**: if the +three bucket risk factors `Zᵢ` are square-integrable with covariances equal to the supervisory +correlations (unit variances, `0.7` between adjacent buckets, `0.3` between the first and the +third), then `effNotionalIR D₀ D₁ D₂ = sd(∑ᵢ Dᵢ Zᵢ)`. This is +`portfolioVarN_covariance_eq_variance` at the supervisory kernel. -/ +theorem effNotionalIR_eq_sqrt_variance {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} + [IsFiniteMeasure μ] {Z : Fin 3 → Ω → ℝ} (hZ : ∀ i, MemLp (Z i) 2 μ) + (hcov : ∀ i j, cov[Z i, Z j; μ] = saccrIRCorrelation i j) (D : Fin 3 → ℝ) : + effNotionalIR (D 0) (D 1) (D 2) = √Var[∑ i, D i • Z i; μ] := by + have hk : (fun i j ↦ cov[Z i, Z j; μ]) = saccrIRCorrelation := funext₂ hcov + rw [effNotionalIR_eq_sqrt_portfolioVarN, ← hk, + portfolioVarN_covariance_eq_variance _ D Z fun i _ ↦ hZ i] + +end Variance + +/-- **The supervisory correlation matrix is positive semidefinite**: the radicand of +`effNotionalIR` is nonnegative for every hedging set. It is the sum of squares +`(D₁ + 0.7 D₂ + 0.3 D₃)² + (51 D₂ + 49 D₃)²/5100 + (112/255) D₃²`. -/ +theorem effNotionalIR_radicand_nonneg (D₁ D₂ D₃ : ℝ) : + 0 ≤ D₁ ^ 2 + D₂ ^ 2 + D₃ ^ 2 + 7 / 5 * D₁ * D₂ + 7 / 5 * D₂ * D₃ + 3 / 5 * D₁ * D₃ := by + nlinarith [sq_nonneg (D₁ + 7 / 10 * D₂ + 3 / 10 * D₃), sq_nonneg (51 * D₂ + 49 * D₃), + sq_nonneg D₃] + +/-- The square of the effective notional is its radicand: no truncation at zero. -/ +theorem effNotionalIR_sq (D₁ D₂ D₃ : ℝ) : + effNotionalIR D₁ D₂ D₃ ^ 2 = + D₁ ^ 2 + D₂ ^ 2 + D₃ ^ 2 + 7 / 5 * D₁ * D₂ + 7 / 5 * D₂ * D₃ + 3 / 5 * D₁ * D₃ := + Real.sq_sqrt (effNotionalIR_radicand_nonneg D₁ D₂ D₃) + +end MathFin diff --git a/LeanPool/MathFin/Risk/Spectral.lean b/LeanPool/MathFin/Risk/Spectral.lean new file mode 100644 index 0000000000..031e6eb2e6 --- /dev/null +++ b/LeanPool/MathFin/Risk/Spectral.lean @@ -0,0 +1,257 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.ExpectedShortfall + +/-! +# Spectral risk measures + +A **spectral risk measure** weights the value-at-risk curve of a loss by a spectrum `φ`: + + `ρ_φ(X) = ∫₀¹ φ(u) · VaR_u(X) du` + +(`spectralRiskMeasure`; Acerbi, *Spectral measures of risk: a coherent representation of +subjective risk aversion*, J. Banking Finance 26 (2002), 1505–1518). The VaR curve is +`valueAtRisk` of `Risk/ValueAtRisk.lean`, the quantile function of the law of the loss. +Two spectra recover measures the library already has: + +* the constant spectrum `φ ≡ 1` gives the mean, `ρ_1(X) = E[X]` (`spectralRiskMeasure_one`), + because the quantile function pushes the uniform law on `(0, 1)` forward to the law of `X`; +* the spectrum `(1 − α)⁻¹ 𝟙_{(α, 1)}` (`esSpectrum`) gives expected shortfall + (`spectralRiskMeasure_esSpectrum`). + +A convex combination `∑ₖ wₖ (1 − αₖ)⁻¹ 𝟙_{(αₖ, 1)}` of expected-shortfall spectra is a +nondecreasing step spectrum. Its spectral risk is the same convex combination of expected +shortfalls (`spectralRiskMeasure_sum_esSpectrum`), and that mixture is a coherent risk measure on +the integrable losses (`isCoherentRiskMeasure_spectralRiskFinite_expectedShortfall`, +`isCoherentRiskMeasure_spectralRiskMeasure_sum_esSpectrum`). Each coherence axiom of the mixture +is a finite-weight lemma of this file applied to the coherent expected shortfall +(`expectedShortfall_isCoherentRiskMeasure`). Acerbi's theorem (Theorem 4.1 there), that every +nonnegative nondecreasing spectrum integrating to one gives a coherent measure, is proved here only +for these step spectra. + +The finite weighted sum `spectralRiskFinite s φ Q = ∑ᵢ φᵢ Qᵢ` carries the algebra: translation +invariance, monotonicity and convex combinations in the weights. With `Qₖ = ES_{αₖ}(X)` it is the +mixture of expected shortfalls above. + +## Main definitions + +* `spectralRiskMeasure`: the spectral risk measure `ρ_φ(X) = ∫₀¹ φ(u) · VaR_u(X) du` with + spectrum `φ`. +* `esSpectrum`: the expected-shortfall spectrum `(1 − α)⁻¹ 𝟙_{(α, 1)}`, uniform weight on the + levels above `α`. +* `spectralRiskFinite`: the finite spectral sum `∑ᵢ φᵢ Qᵢ` of values `Q` with weights `φ`. + +## Main results + +* `spectralRisk_translation`, `spectralRisk_mono`, + `spectralRisk_convex_combination_normalized`, `spectralRisk_convex_combination`: the finite + weighted sum and its algebra. +* `isCoherentRiskMeasure_spectralRiskFinite_expectedShortfall`: a convex combination of expected + shortfalls is a coherent risk measure. +* `spectralRiskFinite_expectedShortfall_isLUB_representingSet`: on a finite space the mixture is + the supremum of expected loss over its representing set. +* `spectralRiskMeasure_one`: the constant spectrum gives the mean. +* `spectralRiskMeasure_esSpectrum`: the expected-shortfall spectrum gives expected shortfall. +* `spectralRiskMeasure_sum_esSpectrum`: a step spectrum gives the mixture of expected shortfalls. +* `isCoherentRiskMeasure_spectralRiskMeasure_sum_esSpectrum`: step-spectrum spectral risk + measures are coherent. + +## References + +* [C. Acerbi, *Spectral measures of risk: A coherent representation of subjective risk + aversion*][Acerbi2002], Theorem 4.1 + +## Tags + +spectral risk measure, Acerbi, risk aversion spectrum, expected shortfall mixture, +coherent risk measure, quantile weighting, MSC 91G70, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +variable {ι : Type*} + +/-! ### The finite weighted sum -/ + +/-- Finite spectral sum: the weighted sum `∑ᵢ φᵢ Qᵢ` of the values `Q` with weights `φ`. With +`Qₖ = ES_{αₖ}(X)` it is a mixture of expected shortfalls +(`spectralRiskMeasure_sum_esSpectrum`). -/ +noncomputable def spectralRiskFinite (s : Finset ι) (φ : ι → ℝ) (Q : ι → ℝ) : ℝ := + ∑ i ∈ s, φ i * Q i + +/-- **Translation invariance**: if `Σ φ = 1`, then `ρ(Q + c·𝟙) = ρ(Q) + c`. -/ +theorem spectralRisk_translation (s : Finset ι) (φ : ι → ℝ) (Q : ι → ℝ) + (c : ℝ) (h_norm : ∑ i ∈ s, φ i = 1) : + spectralRiskFinite s φ (fun i ↦ Q i + c) = + spectralRiskFinite s φ Q + c := by + unfold spectralRiskFinite + rw [show (fun i ↦ φ i * (Q i + c)) = (fun i ↦ φ i * Q i + φ i * c) from by + funext i; ring] + rw [Finset.sum_add_distrib, ← Finset.sum_mul, h_norm, one_mul] + +/-- **Monotonicity**: with nonnegative weights, pointwise dominance of the values `Q ≤ Q'` on `s` +gives `ρ_φ(Q) ≤ ρ_φ(Q')`. -/ +theorem spectralRisk_mono (s : Finset ι) (φ Q Q' : ι → ℝ) + (hφ : ∀ i ∈ s, 0 ≤ φ i) (hQ : ∀ i ∈ s, Q i ≤ Q' i) : + spectralRiskFinite s φ Q ≤ spectralRiskFinite s φ Q' := by + unfold spectralRiskFinite + exact Finset.sum_le_sum fun i hi ↦ + mul_le_mul_of_nonneg_left (hQ i hi) (hφ i hi) + +/-- The finite spectral sum depends on the values only on `s`. -/ +theorem spectralRiskFinite_congr {s : Finset ι} {φ Q Q' : ι → ℝ} (h : ∀ i ∈ s, Q i = Q' i) : + spectralRiskFinite s φ Q = spectralRiskFinite s φ Q' := + Finset.sum_congr rfl fun i hi ↦ by rw [h i hi] + +/-- **Convex combination of normalized spectra remains normalized**: +`t Σ φ + (1−t) Σ ψ = t · 1 + (1−t) · 1 = 1`. The convex-combination weight +`t·φ + (1−t)·ψ` is therefore a valid spectral weight. -/ +theorem spectralRisk_convex_combination_normalized + (s : Finset ι) (φ ψ : ι → ℝ) (t : ℝ) + (hφ : ∑ i ∈ s, φ i = 1) (hψ : ∑ i ∈ s, ψ i = 1) : + ∑ i ∈ s, (t * φ i + (1 - t) * ψ i) = 1 := by + rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum, hφ, hψ] + ring + +/-- **Convex combination of spectral sums**: a convex combination of two finite spectral sums +acts on the values through the convex combination of the weights. -/ +theorem spectralRisk_convex_combination + (s : Finset ι) (φ ψ : ι → ℝ) (Q : ι → ℝ) (t : ℝ) : + t * spectralRiskFinite s φ Q + (1 - t) * spectralRiskFinite s ψ Q = + spectralRiskFinite s (fun i ↦ t * φ i + (1 - t) * ψ i) Q := by + unfold spectralRiskFinite + rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib] + refine Finset.sum_congr rfl (fun i _ ↦ ?_) + ring + +/-! ### Mixtures of expected shortfalls -/ + +open MeasureTheory Set + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} {X : Ω → ℝ} {α : ℝ} + +/-- **A convex combination of expected shortfalls is coherent**: for weights `w ≥ 0` with +`∑ w = 1` and levels `αₖ ∈ (0, 1)`, `X ↦ ∑ₖ wₖ ES_{αₖ}(X)` satisfies the four axioms of a coherent +risk measure on the integrable losses. Each axiom is the finite-sum lemma of this file applied to +the corresponding axiom of expected shortfall (`expectedShortfall_isCoherentRiskMeasure`). -/ +theorem isCoherentRiskMeasure_spectralRiskFinite_expectedShortfall [IsProbabilityMeasure P] + (s : Finset ι) {w α : ι → ℝ} (hw : ∀ k ∈ s, 0 ≤ w k) (hw1 : ∑ k ∈ s, w k = 1) + (hα : ∀ k ∈ s, α k ∈ Ioo 0 1) : + IsCoherentRiskMeasure P fun X ↦ spectralRiskFinite s w fun k ↦ expectedShortfall X P (α k) + where + mono _ _ hX hY hXY := + spectralRisk_mono s w _ _ hw fun k hk ↦ expectedShortfall_mono hX hY hXY (hα k hk) + add_const X hX m := + (spectralRiskFinite_congr (Q' := fun k ↦ expectedShortfall X P (α k) + m) + fun k hk ↦ expectedShortfall_add_const hX (hα k hk) m).trans + (spectralRisk_translation s w (fun k ↦ expectedShortfall X P (α k)) m hw1) + const_mul X hX c hc := by + simp only [spectralRiskFinite, Finset.mul_sum] + exact Finset.sum_congr rfl fun k hk ↦ by + rw [expectedShortfall_const_mul hX (hα k hk) hc] + ring + add_le X Y hX hY := by + refine (spectralRisk_mono s w _ _ hw fun k hk ↦ + expectedShortfall_add_le hX hY (hα k hk)).trans_eq ?_ + simp only [spectralRiskFinite, mul_add, Finset.sum_add_distrib] + +/-- **Mixtures of expected shortfall in the ADEH framework**: on a finite probability space, +`L ↦ ∑ₖ wₖ ES_{αₖ}(L)` is a coherent risk measure +(`isCoherentRiskMeasure_spectralRiskFinite_expectedShortfall`), so `coherentRisk_isLUB` represents +it as a supremum of expected losses over its representing set. -/ +theorem spectralRiskFinite_expectedShortfall_isLUB_representingSet {κ : Type*} [Fintype κ] + [MeasurableSpace κ] [MeasurableSingletonClass κ] (Q : Measure κ) [IsProbabilityMeasure Q] + (s : Finset ι) {w α : ι → ℝ} (hw : ∀ k ∈ s, 0 ≤ w k) (hw1 : ∑ k ∈ s, w k = 1) + (hα : ∀ k ∈ s, α k ∈ Ioo 0 1) (L : κ → ℝ) : + IsLUB ((fun q ↦ ∑ i, q i * L i) '' + representingSet fun L : κ → ℝ ↦ spectralRiskFinite s w fun k ↦ expectedShortfall L Q (α k)) + (spectralRiskFinite s w fun k ↦ expectedShortfall L Q (α k)) := + coherentRisk_isLUB + (isCoherentRiskMeasure_spectralRiskFinite_expectedShortfall (P := Q) s hw hw1 hα) L + +/-! ### The spectral risk of a loss -/ + +/-- The **spectral risk measure** with spectrum `φ`: `ρ_φ(X) = ∫₀¹ φ(u) · VaR_u(X) du`. -/ +noncomputable def spectralRiskMeasure (φ : ℝ → ℝ) (X : Ω → ℝ) (P : Measure Ω) : ℝ := + ∫ u in Ioo 0 1, φ u * valueAtRisk X P u + +/-- The **expected-shortfall spectrum** `(1 − α)⁻¹ 𝟙_{(α, 1)}`: uniform weight on the levels +above `α`. -/ +noncomputable def esSpectrum (α : ℝ) : ℝ → ℝ := + (Ioo α 1).indicator fun _ ↦ (1 - α)⁻¹ + +/-- Weighting a function by the expected-shortfall spectrum restricts it to `(α, 1)`. -/ +lemma esSpectrum_mul (α : ℝ) (g : ℝ → ℝ) (u : ℝ) : + esSpectrum α u * g u = (Ioo α 1).indicator (fun v ↦ (1 - α)⁻¹ * g v) u := + (indicator_mul_left (Ioo α 1) (fun _ ↦ (1 - α)⁻¹) g).symm + +/-- **The constant spectrum gives the mean**: `∫₀¹ VaR_u(X) du = E[X]`. The VaR curve is the +quantile function of the law of `X`, which pushes the uniform law on `(0, 1)` forward to that +law (`integral_eq_setIntegral_quantile`). -/ +theorem spectralRiskMeasure_one [IsProbabilityMeasure P] (hX : AEMeasurable X P) : + spectralRiskMeasure 1 X P = ∫ ω, X ω ∂P := by + have hq := integral_eq_setIntegral_quantile (μ := P.map X) (f := fun x ↦ x) (by fun_prop) + rw [integral_map hX (by fun_prop)] at hq + simp only [spectralRiskMeasure, Pi.one_apply, one_mul] + exact hq.symm + +/-- **The expected-shortfall spectrum gives expected shortfall**: for `α ∈ (0, 1)`, +`∫₀¹ (1 − α)⁻¹ 𝟙_{(α, 1)}(u) VaR_u(X) du = ES_α(X)`. -/ +theorem spectralRiskMeasure_esSpectrum (hα : α ∈ Ioo 0 1) : + spectralRiskMeasure (esSpectrum α) X P = expectedShortfall X P α := by + simp_rw [spectralRiskMeasure, esSpectrum_mul α (valueAtRisk X P)] + rw [setIntegral_indicator measurableSet_Ioo, inter_eq_right.2 (Ioo_subset_Ioo_left hα.1.le), + integral_const_mul, expectedShortfall] + +/-- **A step spectrum gives a mixture of expected shortfalls**: for an integrable loss and levels +`αₖ ∈ (0, 1)`, the spectral risk of `∑ₖ wₖ (1 − αₖ)⁻¹ 𝟙_{(αₖ, 1)}` is `∑ₖ wₖ ES_{αₖ}(X)`. -/ +theorem spectralRiskMeasure_sum_esSpectrum [IsProbabilityMeasure P] (hX : Integrable X P) + (s : Finset ι) (w : ι → ℝ) {α : ι → ℝ} (hα : ∀ k ∈ s, α k ∈ Ioo 0 1) : + spectralRiskMeasure (fun u ↦ ∑ k ∈ s, w k * esSpectrum (α k) u) X P = + spectralRiskFinite s w fun k ↦ expectedShortfall X P (α k) := by + have hint (k : ι) : + IntegrableOn (fun u ↦ w k * (esSpectrum (α k) u * valueAtRisk X P u)) (Ioo 0 1) := by + simp_rw [esSpectrum_mul (α k) (valueAtRisk X P)] + exact ((Integrable.const_mul (integrableOn_valueAtRisk hX) _).indicator + measurableSet_Ioo).const_mul _ + simp_rw [spectralRiskMeasure, Finset.sum_mul, mul_assoc] + rw [integral_finsetSum s fun k _ ↦ hint k] + exact Finset.sum_congr rfl fun k hk ↦ by + rw [integral_const_mul] + exact congrArg (w k * ·) (spectralRiskMeasure_esSpectrum (hα k hk)) + +/-- **Step-spectrum spectral risk measures are coherent**: for weights `w ≥ 0` with `∑ w = 1` and +levels `αₖ ∈ (0, 1)`, the spectral risk measure of the nondecreasing step spectrum +`∑ₖ wₖ (1 − αₖ)⁻¹ 𝟙_{(αₖ, 1)}` is a coherent risk measure on the integrable losses. On those +losses it is the mixture of expected shortfalls (`spectralRiskMeasure_sum_esSpectrum`), which is +coherent (`isCoherentRiskMeasure_spectralRiskFinite_expectedShortfall`). -/ +theorem isCoherentRiskMeasure_spectralRiskMeasure_sum_esSpectrum [IsProbabilityMeasure P] + (s : Finset ι) {w α : ι → ℝ} (hw : ∀ k ∈ s, 0 ≤ w k) (hw1 : ∑ k ∈ s, w k = 1) + (hα : ∀ k ∈ s, α k ∈ Ioo 0 1) : + IsCoherentRiskMeasure P + (spectralRiskMeasure (fun u ↦ ∑ k ∈ s, w k * esSpectrum (α k) u) · P) := by + have e (X : Ω → ℝ) (hX : Integrable X P) := spectralRiskMeasure_sum_esSpectrum hX s w hα + have h := isCoherentRiskMeasure_spectralRiskFinite_expectedShortfall (P := P) s hw hw1 hα + exact + { mono := fun X Y hX hY hXY ↦ + (e X hX).trans_le ((h.mono hX hY hXY).trans_eq (e Y hY).symm) + add_const := fun X hX m ↦ + (e (fun ω ↦ X ω + m) (hX.add (integrable_const m))).trans + ((h.add_const hX m).trans (congrArg (· + m) (e X hX).symm)) + const_mul := fun X hX c hc ↦ + (e (fun ω ↦ c * X ω) (hX.const_mul c)).trans + ((h.const_mul hX hc).trans (congrArg (c * ·) (e X hX).symm)) + add_le := fun X Y hX hY ↦ + (e (fun ω ↦ X ω + Y ω) (hX.add hY)).trans_le + ((h.add_le hX hY).trans_eq (congrArg₂ (· + ·) (e X hX) (e Y hY)).symm) } + +end MathFin diff --git a/LeanPool/MathFin/Risk/StudentTValueAtRisk.lean b/LeanPool/MathFin/Risk/StudentTValueAtRisk.lean new file mode 100644 index 0000000000..569234e056 --- /dev/null +++ b/LeanPool/MathFin/Risk/StudentTValueAtRisk.lean @@ -0,0 +1,153 @@ +/- +Copyright (c) 2026 Yang Ye. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Yang Ye +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Laws.StudentT +public import LeanPool.MathFin.Risk.ExpectedShortfall + +/-! +# Value-at-risk and expected shortfall of a Student-t loss + +Let `T` have the standard Student-t law `t_ν` (`Probability/Laws/StudentT.lean`) and consider the +location-scale loss `L = μ + σ T` with `σ ≥ 0`. Through the library's own `valueAtRisk` and +`expectedShortfall` (`Risk/ValueAtRisk.lean`), this file proves the closed forms of +McNeil, Frey and Embrechts, *Quantitative Risk Management* (2015), Example 2.15: + + `VaR_α(L) = μ + σ t_ν⁻¹(α)`, + `ES_α(L) = μ + σ · g_ν(t_ν⁻¹(α))/(1 − α) · (ν + t_ν⁻¹(α)²)/(ν − 1)` (`ν > 1`), + +where `t_ν⁻¹(α) = quantile (studentTMeasure ν) α` is the quantile of the law +(`cdf_studentTMeasure_quantile`: it solves `F_ν(q) = α`) and `g_ν = studentTPDFReal ν` is its +density. The ES proof runs through the Acerbi–Tasche formula +(`expectedShortfall_eq_acerbiTasche`): the law has no atoms, so the tail probability above the +quantile is exactly `1 − α` and ES is the tail first moment `∫_q^∞ t g_ν(t) dt / (1 − α)`, which +`setIntegral_Ioi_mul_studentTPDFReal` evaluates. + +`VaR ≤ ES` is not reproved: it is the general `valueAtRisk_le_expectedShortfall`, instantiated +at the Student-t loss (`valueAtRisk_le_expectedShortfall_of_hasLaw_studentTMeasure`). + +## Main results + +* `valueAtRisk_of_hasLaw_studentTMeasure`: `VaR_α(μ + σ T) = μ + σ t_ν⁻¹(α)`. +* `expectedShortfall_of_hasLaw_studentTMeasure`: the McNeil–Frey–Embrechts closed form of + `ES_α(μ + σ T)` for `ν > 1`. +* `valueAtRisk_le_expectedShortfall_of_hasLaw_studentTMeasure`: + `VaR_α(μ + σ T) ≤ ES_α(μ + σ T)`. +* `quantile_studentTMeasure_le_expectedShortfall_closedForm`: the same inequality between the + two closed forms, `q ≤ g_ν(q)/(1 − α) · (ν + q²)/(ν − 1)`. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Example 2.15 + +## Tags + +Student-t VaR, heavy-tailed loss, t distribution, expected shortfall closed form, +McNeil-Frey-Embrechts, location-scale loss, MSC 91G70, MSC 60E05, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + {T : Ω → ℝ} {ν μ σ α : ℝ} + +/-- The Student-t law has a continuous cdf: it has a density, hence no atoms. -/ +lemma continuous_cdf_studentTMeasure (hν : 0 < ν) : Continuous (cdf (studentTMeasure ν)) := + have := isProbabilityMeasure_studentTMeasure hν + continuous_cdf + +/-- The Student-t quantile `t_ν⁻¹(α)` solves `F_ν(q) = α`. -/ +lemma cdf_studentTMeasure_quantile (hν : 0 < ν) (hα : α ∈ Ioo 0 1) : + cdf (studentTMeasure ν) (quantile (studentTMeasure ν) α) = α := + cdf_quantile (continuous_cdf_studentTMeasure hν) hα + +/-- The Student-t law with `ν > 1` has a mean: `id` is integrable. -/ +lemma integrable_id_studentTMeasure (hν : 1 < ν) : Integrable id (studentTMeasure ν) := by + have hν0 : 0 < ν := by linarith + rw [studentTMeasure, integrable_withDensity_iff (measurable_studentTPDF ν) + (ae_of_all _ fun _ ↦ ENNReal.ofReal_lt_top)] + refine (integrable_mul_studentTPDFReal hν).congr (ae_of_all _ fun x ↦ ?_) + simp [studentTPDF, ENNReal.toReal_ofReal (studentTPDFReal_pos hν0 x).le] + +/-- **Value-at-risk of a Student-t loss**: `VaR_α(μ + σ T) = μ + σ t_ν⁻¹(α)` for `T ~ t_ν` and +`σ ≥ 0`. -/ +theorem valueAtRisk_of_hasLaw_studentTMeasure (hT : HasLaw T (studentTMeasure ν) P) (hσ : 0 ≤ σ) + (hα : α ∈ Ioo 0 1) : + valueAtRisk (fun ω ↦ μ + σ * T ω) P α = μ + σ * quantile (studentTMeasure ν) α := by + rw [valueAtRisk_comp (h := fun x ↦ μ + σ * x) hT.aemeasurable + ((monotone_id.const_mul hσ).const_add μ) + (by fun_prop : Continuous fun x ↦ μ + σ * x).lowerSemicontinuous hα, + valueAtRisk_eq_quantile hT] + +/-- **Expected shortfall of a standard Student-t loss**: for `T ~ t_ν` with `ν > 1`, +`ES_α(T) = g_ν(q)/(1 − α) · (ν + q²)/(ν − 1)` at `q = t_ν⁻¹(α)`. -/ +theorem expectedShortfall_of_hasLaw_studentTMeasure_standard (hν : 1 < ν) + (hT : HasLaw T (studentTMeasure ν) P) (hα : α ∈ Ioo 0 1) : + expectedShortfall T P α = + studentTPDFReal ν (quantile (studentTMeasure ν) α) / (1 - α) * + ((ν + quantile (studentTMeasure ν) α ^ 2) / (ν - 1)) := by + have hν0 : 0 < ν := by linarith + have := isProbabilityMeasure_studentTMeasure hν0 + set q := quantile (studentTMeasure ν) α + have hVaR : valueAtRisk T P α = q := valueAtRisk_eq_quantile hT + -- the tail above the quantile carries probability exactly `1 − α` + have htail : P.real {ω | q < T ω} = 1 - α := by + rw [hT.measureReal_eq (p := fun x ↦ q < x) measurableSet_Ioi, show {x | q < x} = Ioi q from rfl, + ← compl_Iic, probReal_compl_eq_one_sub measurableSet_Iic, ← cdf_eq_real, + cdf_studentTMeasure_quantile hν0 hα] + -- and the tail first moment is the integral evaluated in `Probability/Laws/StudentT.lean` + have hmoment : ∫ ω in {ω | q < T ω}, T ω ∂P = ∫ t in Ioi q, t * studentTPDFReal ν t := by + rw [show {ω | q < T ω} = T ⁻¹' Ioi q from rfl, ← setIntegral_map (f := fun t : ℝ ↦ t) + measurableSet_Ioi (by fun_prop) hT.aemeasurable, hT.map_eq, studentTMeasure, + setIntegral_withDensity_eq_setIntegral_toReal_smul (measurable_studentTPDF ν) + (ae_of_all _ fun _ ↦ ENNReal.ofReal_lt_top) _ measurableSet_Ioi] + refine setIntegral_congr_fun measurableSet_Ioi fun t _ ↦ ?_ + simp [studentTPDF, ENNReal.toReal_ofReal (studentTPDFReal_pos hν0 t).le, mul_comm] + rw [expectedShortfall_eq_acerbiTasche (hT.integrable (integrable_id_studentTMeasure hν)) hα, hVaR, + htail, hmoment, setIntegral_Ioi_mul_studentTPDFReal hν, sub_self, mul_zero, add_zero] + ring + +/-- **Expected shortfall of a Student-t loss** (McNeil–Frey–Embrechts, Example 2.15): for +`T ~ t_ν` with `ν > 1` and `σ ≥ 0`, at `q = t_ν⁻¹(α)`, +`ES_α(μ + σ T) = μ + σ · g_ν(q)/(1 − α) · (ν + q²)/(ν − 1)`. -/ +theorem expectedShortfall_of_hasLaw_studentTMeasure (hν : 1 < ν) + (hT : HasLaw T (studentTMeasure ν) P) (hσ : 0 ≤ σ) (hα : α ∈ Ioo 0 1) : + expectedShortfall (fun ω ↦ μ + σ * T ω) P α = + μ + σ * (studentTPDFReal ν (quantile (studentTMeasure ν) α) / (1 - α) * + ((ν + quantile (studentTMeasure ν) α ^ 2) / (ν - 1))) := by + have hint := hT.integrable (integrable_id_studentTMeasure hν) + rw [show (fun ω ↦ μ + σ * T ω) = fun ω ↦ σ * T ω + μ from funext fun _ ↦ add_comm _ _, + expectedShortfall_add_const (hint.const_mul σ) hα, expectedShortfall_const_mul hint hα hσ, + expectedShortfall_of_hasLaw_studentTMeasure_standard hν hT hα, add_comm] + +/-- **VaR ≤ ES for a Student-t loss**: the general `valueAtRisk_le_expectedShortfall`, at the +law. -/ +theorem valueAtRisk_le_expectedShortfall_of_hasLaw_studentTMeasure (hν : 1 < ν) + (hT : HasLaw T (studentTMeasure ν) P) (hα : α ∈ Ioo 0 1) : + valueAtRisk (fun ω ↦ μ + σ * T ω) P α ≤ expectedShortfall (fun ω ↦ μ + σ * T ω) P α := + valueAtRisk_le_expectedShortfall + ((integrable_const μ).add ((hT.integrable (integrable_id_studentTMeasure hν)).const_mul σ)) hα + +/-- **The closed forms inherit `VaR ≤ ES`**: at `q = t_ν⁻¹(α)` with `ν > 1`, +`q ≤ g_ν(q)/(1 − α) · (ν + q²)/(ν − 1)`. An inequality about the Student-t density and quantile, +read off the general `valueAtRisk_le_expectedShortfall` for `T = id` under the law itself. -/ +theorem quantile_studentTMeasure_le_expectedShortfall_closedForm (hν : 1 < ν) (hα : α ∈ Ioo 0 1) : + quantile (studentTMeasure ν) α ≤ + studentTPDFReal ν (quantile (studentTMeasure ν) α) / (1 - α) * + ((ν + quantile (studentTMeasure ν) α ^ 2) / (ν - 1)) := by + have := isProbabilityMeasure_studentTMeasure (by linarith : 0 < ν) + have hT : HasLaw id (studentTMeasure ν) (studentTMeasure ν) := .id + rw [← expectedShortfall_of_hasLaw_studentTMeasure_standard hν hT hα, ← valueAtRisk_eq_quantile hT] + exact valueAtRisk_le_expectedShortfall (hT.integrable (integrable_id_studentTMeasure hν)) hα + +end MathFin diff --git a/LeanPool/MathFin/Risk/UtilityDerivation.lean b/LeanPool/MathFin/Risk/UtilityDerivation.lean new file mode 100644 index 0000000000..4044c9a6fd --- /dev/null +++ b/LeanPool/MathFin/Risk/UtilityDerivation.lean @@ -0,0 +1,223 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Choice.Utility.VonNeumannMorgenstern +public import LeanPool.MathFin.Risk.AcceptanceSet +public import LeanPool.MathFin.Choice.Performance.Ratios + +/-! +# Acceptance sets of an expected-utility agent: convex, not coherent + +On a finite state space with probability vector `p`, an agent with utility `u` and wealth `W` +**accepts** a position `X` when it does not lower expected utility: `u(W) ≤ E[u(W + X)]` +(`acceptableUnderUtility`). The expectation is the von Neumann–Morgenstern expected utility +`expectedUtility` of `Choice/Utility/VonNeumannMorgenstern.lean`, taken over the outcome utilities +`i ↦ u(W + X i)`. + +Two properties of the acceptance set follow from properties of `u`: + +* a **concave** `u` makes it **convex** (`acceptableUnderUtility_convex`): a mixture of two + acceptable positions is acceptable; +* an **increasing** `u` makes it closed under adding nonnegative cash + (`acceptableUnderUtility_monotone_translation`). + +A convex acceptance set gives a *convex* risk measure `ρ(X) = inf {m | X + m acceptable}` +(Föllmer and Schied, *Convex measures of risk and trading constraints*, Finance Stoch. 6 (2002), +429–447, whose case study is the shortfall risk of an expected-loss constraint). It does not give +a *coherent* one. The acceptance set of a coherent risk measure is a cone +(`IsCoherentRiskMeasure.cone`, `Risk/AcceptanceSet.lean`; a loss `L` is acceptable when +the position `−L` is), and a risk-averse utility's acceptance set need not be one: +`not_exists_isCoherentRiskMeasure_log_acceptance` exhibits a position that log utility accepts +while rejecting three times that position, so no coherent risk measure has that acceptance set. +Neither the construction of `ρ` from the acceptance set nor its convexity is formalized here. + +The von Neumann–Morgenstern layer gives two more facts about acceptance: + +* it depends on `u` only up to a positive affine map (`acceptableUnderUtility_affine_iff`, from + `expectedUtility_affine`); +* a position acceptable under each of two probability vectors is acceptable under every mixture + of them (`acceptableUnderUtility_mix`, from `expectedUtility_mix`). + +Log utility at unit wealth is the Kelly criterion: a binary bet of fraction `f` at odds `b` is +acceptable exactly when its expected log-growth `kellyGrowth p b f` +(`Choice/Performance/Ratios.lean`) is +nonnegative (`acceptableUnderUtility_log_iff_kellyGrowth`). The counterexample above is a Kelly bet +on a fair coin at odds `2`: the fraction `1/4` has positive growth, the fraction `3/4` negative. + +## Main definitions + +* `acceptableUnderUtility`: a position `X` on a finite state space with probability vector `p` + is acceptable under utility `u` at wealth `W` when `u(W) ≤ E[u(W + X)]`. + +## Main results + +* `acceptableUnderUtility_convex`, `acceptableUnderUtility_monotone_translation`, + `acceptableUnderUtility_zero`. +* `acceptableUnderUtility_affine_iff`, `acceptableUnderUtility_mix`. +* `acceptableUnderUtility_log_iff_kellyGrowth`. +* `not_exists_isCoherentRiskMeasure_log_acceptance`: the log-utility acceptance set of the fair + coin is the acceptance set of no coherent risk measure. + +## References + +* [P. Artzner et al., *Coherent measures of risk*][ArtznerDelbaenEberHeath1999] +* [H. Föllmer and A. Schied, *Convex measures of risk and trading constraints*][FollmerSchied2002] +* [J. L. Kelly, *A new interpretation of information rate*][Kelly1956] + +## Tags + +acceptance set, expected utility, convex risk measure, Föllmer-Schied, log utility, Kelly criterion, +risk aversion, MSC 91B16, MSC 91G70, JEL D81 +-/ + +@[expose] public section + +namespace MathFin + +/-- A position `X : ι → ℝ` is **acceptable under utility `u` at wealth `W`** if its expected +utility is at least that of doing nothing: `u(W) ≤ E[u(W + X)]`, the expected utility +`expectedUtility s (fun i ↦ u (W + X i)) p` of the outcome utilities under the probability +vector `p`. -/ +def acceptableUnderUtility {ι : Type*} (s : Finset ι) (p : ι → ℝ) + (u : ℝ → ℝ) (W : ℝ) (X : ι → ℝ) : Prop := + u W ≤ expectedUtility s (fun i ↦ u (W + X i)) p + +/-- **Concave utility gives a convex acceptance set**: if `u` is concave and `X`, `Y` are +acceptable, so is every convex combination `αX + (1 − α)Y`. + +Pointwise concavity gives `α u(W + X) + (1 − α) u(W + Y) ≤ u(W + αX + (1 − α)Y)` in every state. +Taking expectations with `p ≥ 0` and using `u(W) ≤ E[u(W + X)]`, `u(W) ≤ E[u(W + Y)]` gives the +claim. A convex acceptance set is the acceptance set of a convex risk measure (not formalized +here); it need not be the acceptance set of a coherent one +(`not_exists_isCoherentRiskMeasure_log_acceptance`). -/ +theorem acceptableUnderUtility_convex + {ι : Type*} (s : Finset ι) (p : ι → ℝ) (u : ℝ → ℝ) (W : ℝ) + (hp_nonneg : ∀ i ∈ s, 0 ≤ p i) + (h_concave : ∀ x y : ℝ, ∀ α : ℝ, 0 ≤ α → α ≤ 1 → + α * u x + (1 - α) * u y ≤ u (α * x + (1 - α) * y)) + {X Y : ι → ℝ} {α : ℝ} (hα : 0 ≤ α) (hα1 : α ≤ 1) + (hX : acceptableUnderUtility s p u W X) + (hY : acceptableUnderUtility s p u W Y) : + acceptableUnderUtility s p u W (fun i ↦ α * X i + (1 - α) * Y i) := by + simp only [acceptableUnderUtility, expectedUtility] at * + have h_sum : ∑ i ∈ s, p i * (α * u (W + X i) + (1 - α) * u (W + Y i)) ≤ + ∑ i ∈ s, p i * u (W + (α * X i + (1 - α) * Y i)) := + Finset.sum_le_sum fun i hi ↦ mul_le_mul_of_nonneg_left + ((h_concave (W + X i) (W + Y i) α hα hα1).trans_eq (congrArg u (by ring))) (hp_nonneg i hi) + have h_LHS : ∑ i ∈ s, p i * (α * u (W + X i) + (1 - α) * u (W + Y i)) = + α * (∑ i ∈ s, p i * u (W + X i)) + (1 - α) * (∑ i ∈ s, p i * u (W + Y i)) := by + rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib] + exact Finset.sum_congr rfl fun i _ ↦ by ring + rw [h_LHS] at h_sum + linarith [mul_le_mul_of_nonneg_left hX hα, mul_le_mul_of_nonneg_left hY (sub_nonneg.2 hα1)] + +/-- **Increasing utility: more cash stays acceptable**. If `u` is monotone and `X` is +acceptable, then `X + c` is acceptable for every `c ≥ 0`: in every state +`u(W + X) ≤ u(W + X + c)`, and expectations with `p ≥ 0` preserve the inequality. -/ +theorem acceptableUnderUtility_monotone_translation + {ι : Type*} (s : Finset ι) (p : ι → ℝ) (u : ℝ → ℝ) (W : ℝ) + (hp_nonneg : ∀ i ∈ s, 0 ≤ p i) + (h_mono : Monotone u) + {X : ι → ℝ} {c : ℝ} (hc : 0 ≤ c) + (hX : acceptableUnderUtility s p u W X) : + acceptableUnderUtility s p u W (fun i ↦ X i + c) := by + simp only [acceptableUnderUtility, expectedUtility] at * + refine hX.trans (Finset.sum_le_sum fun i hi ↦ mul_le_mul_of_nonneg_left ?_ (hp_nonneg i hi)) + exact h_mono (by linarith) + +/-- **Doing nothing is acceptable**: for a probability vector, the zero position has expected +utility `u(W)`. -/ +theorem acceptableUnderUtility_zero + {ι : Type*} (s : Finset ι) (p : ι → ℝ) (u : ℝ → ℝ) (W : ℝ) + (h_p_sum : ∑ i ∈ s, p i = 1) : + acceptableUnderUtility s p u W (fun _ ↦ 0) := by + simp only [acceptableUnderUtility, expectedUtility, add_zero] + rw [← Finset.sum_mul, h_p_sum, one_mul] + +/-- **Acceptance depends on the utility only up to a positive affine map**: for a probability +vector `p`, the utilities `u` and `a·u + b` with `a > 0` accept the same positions. This is the +cardinality of von Neumann–Morgenstern utility (`expectedUtility_affine`) read on acceptance +sets. -/ +theorem acceptableUnderUtility_affine_iff {ι : Type*} (s : Finset ι) {p : ι → ℝ} + (hp : ∑ i ∈ s, p i = 1) (u : ℝ → ℝ) {a : ℝ} (ha : 0 < a) (b W : ℝ) (X : ι → ℝ) : + acceptableUnderUtility s p (fun x ↦ a * u x + b) W X ↔ + acceptableUnderUtility s p u W X := by + simp only [acceptableUnderUtility] + rw [expectedUtility_affine s (fun i ↦ u (W + X i)) a b hp, add_le_add_iff_right, + mul_le_mul_iff_of_pos_left ha] + +/-- **Acceptance survives mixing the probability vectors**: a position acceptable under each of +the probability vectors `p` and `q` is acceptable under every mixture `mix α p q` with +`α ∈ [0, 1]`, because expected utility is affine in the mixture (`expectedUtility_mix`). -/ +theorem acceptableUnderUtility_mix {ι : Type*} (s : Finset ι) {p q : ι → ℝ} (u : ℝ → ℝ) + (W : ℝ) {X : ι → ℝ} {α : ℝ} (hα : 0 ≤ α) (hα1 : α ≤ 1) + (hp : acceptableUnderUtility s p u W X) (hq : acceptableUnderUtility s q u W X) : + acceptableUnderUtility s (mix α p q) u W X := by + unfold acceptableUnderUtility at * + rw [expectedUtility_mix] + linarith [mul_le_mul_of_nonneg_left hp hα, mul_le_mul_of_nonneg_left hq (sub_nonneg.2 hα1)] + +/-! ### Log utility and the Kelly criterion -/ + +/-- **A Kelly bet under log utility**: on two states, win (`0`, probability `p`) and lose (`1`), +betting the fraction `f` of unit wealth at odds `b` is the position `(f·b, −f)`. Under log utility +it is acceptable exactly when its expected log-growth `kellyGrowth p b f` is nonnegative. -/ +theorem acceptableUnderUtility_log_iff_kellyGrowth (p b f : ℝ) : + acceptableUnderUtility Finset.univ ![p, 1 - p] Real.log 1 ![f * b, -f] ↔ + 0 ≤ kellyGrowth p b f := by + have h : acceptableUnderUtility Finset.univ ![p, 1 - p] Real.log 1 ![f * b, -f] ↔ + 0 ≤ p * Real.log (1 + f * b) + (1 - p) * Real.log (1 + -f) := by + simp [acceptableUnderUtility, expectedUtility] + rw [h, kellyGrowth, sub_eq_add_neg 1 f] + +/-- On a fair coin at odds `2`, betting a quarter of wealth has positive expected log-growth: +`(log (3/2) + log (3/4))/2 = log (9/8)/2 > 0`. -/ +lemma kellyGrowth_half_two_quarter_pos : 0 < kellyGrowth (1 / 2) 2 (1 / 4) := by + have h := Real.log_mul (x := 3 / 2) (y := 3 / 4) (by norm_num) (by norm_num) + rw [show (3 / 2 : ℝ) * (3 / 4) = 9 / 8 by norm_num] at h + rw [kellyGrowth, show (1 : ℝ) + 1 / 4 * 2 = 3 / 2 by norm_num, + show (1 : ℝ) - 1 / 4 = 3 / 4 by norm_num] + linarith [Real.log_pos (by norm_num : (1 : ℝ) < 9 / 8)] + +/-- On a fair coin at odds `2`, betting three quarters of wealth has negative expected +log-growth: `(log (5/2) + log (1/4))/2 = log (5/8)/2 < 0`. -/ +lemma kellyGrowth_half_two_three_quarters_neg : kellyGrowth (1 / 2) 2 (3 / 4) < 0 := by + have h := Real.log_mul (x := 5 / 2) (y := 1 / 4) (by norm_num) (by norm_num) + rw [show (5 / 2 : ℝ) * (1 / 4) = 5 / 8 by norm_num] at h + rw [kellyGrowth, show (1 : ℝ) + 3 / 4 * 2 = 5 / 2 by norm_num, + show (1 : ℝ) - 3 / 4 = 1 / 4 by norm_num] + linarith [Real.log_neg (by norm_num : (0 : ℝ) < 5 / 8) (by norm_num)] + +/-- **The log-utility acceptance set is not a cone, so no coherent risk measure has it.** On a +fair coin at unit wealth, log utility accepts the Kelly bet `X = (1/2, −1/4)` (fraction `1/4` at +odds `2`, positive expected log-growth) and rejects `3X = (3/2, −3/4)` (fraction `3/4`, negative +growth). A loss `L` is acceptable when the position `−L` is. The acceptance set `{L | ρ L ≤ 0}` of +a coherent risk measure, for any finite measure on the two states, is closed under nonnegative +scaling (`IsCoherentRiskMeasure.cone`), so it is not the set of losses of acceptable positions. +Log utility is concave on positive wealth, and both positions keep wealth positive: risk aversion +makes an acceptance set convex (`acceptableUnderUtility_convex`), not a cone. -/ +theorem not_exists_isCoherentRiskMeasure_log_acceptance : + ¬∃ (P : MeasureTheory.Measure (Fin 2)) (_ : MeasureTheory.IsFiniteMeasure P) + (ρ : (Fin 2 → ℝ) → ℝ), + IsCoherentRiskMeasure P ρ ∧ + ∀ L, ρ L ≤ 0 ↔ acceptableUnderUtility Finset.univ ![1 / 2, 1 / 2] Real.log 1 (-L) := by + rintro ⟨P, _, ρ, hρ, hA⟩ + rw [show (![1 / 2, 1 / 2] : Fin 2 → ℝ) = ![1 / 2, 1 - 1 / 2] by norm_num] at hA + have hX : -(![1 / 4 * 2, -(1 / 4)] : Fin 2 → ℝ) ∈ {L : Fin 2 → ℝ | ρ L ≤ 0} := + (hA _).2 (by + rw [neg_neg] + exact (acceptableUnderUtility_log_iff_kellyGrowth _ _ _).2 + kellyGrowth_half_two_quarter_pos.le) + have h3X : ρ ((3 : ℝ) • -(![1 / 4 * 2, -(1 / 4)] : Fin 2 → ℝ)) ≤ 0 := hρ.cone hX (by norm_num) + have hv : -((3 : ℝ) • -(![1 / 4 * 2, -(1 / 4)] : Fin 2 → ℝ)) = ![3 / 4 * 2, -(3 / 4)] := by + norm_num + rw [hA, hv, acceptableUnderUtility_log_iff_kellyGrowth] at h3X + exact absurd h3X (not_le.2 kellyGrowth_half_two_three_quarters_neg) + +end MathFin diff --git a/LeanPool/MathFin/Risk/VaRSuperadditivity.lean b/LeanPool/MathFin/Risk/VaRSuperadditivity.lean new file mode 100644 index 0000000000..1b757ef7b4 --- /dev/null +++ b/LeanPool/MathFin/Risk/VaRSuperadditivity.lean @@ -0,0 +1,434 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.RiskClosedForms +public import LeanPool.MathFin.Risk.GaussianValueAtRisk +public import LeanPool.MathFin.Probability.Analysis.FiniteMeasureCauchySchwarz +public import Mathlib.Analysis.SpecialFunctions.Sqrt +public import Mathlib.Topology.UniformSpace.Uniformizable + +/-! +# Value-at-risk is not subadditive + +Subadditivity, `ρ(X + Y) ≤ ρ(X) + ρ(Y)`, is the coherence axiom that expresses diversification: +merging two positions should not create risk. Value-at-risk fails it. This file proves three +situations from McNeil–Frey–Embrechts, *Quantitative Risk Management* (2015), Section 2.3.5, and +the QRM Exercise Book, in which VaR is **superadditive**, `VaR_α(X + Y) > VaR_α(X) + VaR_α(Y)`, +and one law family in which it is subadditive at the levels used in practice, for every correlation. + +* **Independent defaults** (Exercises 2.20 and 2.27). For `d` independent `{0, 1}`-valued losses + that each occur with probability `p`, VaR is superadditive exactly when + `(1 − p)^d < α ≤ 1 − p` (`valueAtRisk_sum_bernoulli_superadditive_iff`). At such a level every + single loan is riskless at the `α`-quantile while the portfolio is not. For two loans the + portfolio VaR is exactly `1` against a sum of `0` (`valueAtRisk_sum_bernoulli_of_card_two`). +* **Infinite-mean Pareto losses** (Exercise 2.28). For independent losses with + `F(x) = 1 − x^{−1/2}` on `[1, ∞)` (Mathlib's `paretoMeasure 1 (1/2)`), the law of the sum has + CDF `1 − 2√(x − 1)/x` for `x ≥ 2` (`cdf_conv_paretoMeasure_half`), and VaR is superadditive at + **every** level (`valueAtRisk_add_gt_of_paretoHalf`). With a tail this heavy diversification + increases risk at every confidence level. +* **Jointly Gaussian losses** (Exercise 2.22). For a Gaussian pair with correlation below one, + VaR is subadditive exactly when `α ≥ 1/2` (`valueAtRisk_add_le_iff_of_hasGaussianLaw`): on a + Gaussian pair it holds at the levels used in practice, whatever the correlation + (`valueAtRisk_add_le_of_hasGaussianLaw`, from the subadditivity of the standard deviation, + `sqrt_variance_add_le`), and fails below the median when the correlation is below one. + +Expected shortfall is subadditive for every pair of integrable losses +(`Risk/ExpectedShortfall.lean`); the contrast is the reason the Basel III market-risk +framework replaced VaR by ES. + +## Main results + +* `valueAtRisk_of_bernoulli`: `VaR_α` of a `{0, 1}` loss is `0` or `1` according to + `α ≤ 1 − p`. +* `valueAtRisk_sum_bernoulli_superadditive_iff`: the exact superadditivity region for `d` + independent Bernoulli losses. +* `valueAtRisk_sum_bernoulli_of_card_two`: two loans, for `(1 − p)² < α ≤ 1 − p`: portfolio VaR + `1`, single-loan VaR `0`. +* `cdf_conv`: the CDF of a convolution is `∫ F_ν(x − a) dμ(a)`. +* `cdf_conv_paretoMeasure_half`: the sum of two independent `Pareto(1, 1/2)` losses has CDF + `1 − 2√(x − 1)/x` on `[2, ∞)`. +* `valueAtRisk_add_gt_of_paretoHalf`: VaR is superadditive at every level for them. +* `valueAtRisk_add_le_of_hasGaussianLaw`: for a jointly Gaussian pair, VaR is subadditive at every + level `α ≥ 1/2`, for every correlation. +* `valueAtRisk_add_le_iff_of_hasGaussianLaw`: for a Gaussian pair with correlation `< 1`, + subadditivity holds iff `α ≥ 1/2`. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Ch 2.3; Example 2.25 +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 2.20, 2.27; Ex. 2.22; Ex. 2.28 + +## Tags + +VaR not subadditive, superadditivity, diversification paradox, independent defaults, +infinite-mean Pareto, Gaussian VaR subadditivity, Basel III, MSC 91G70, MSC 60E15, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set Real + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} {α : ℝ} + +/-! ### Independent Bernoulli losses -/ + +section Bernoulli + +variable [IsProbabilityMeasure P] {ι : Type*} [Fintype ι] {Y : ι → Ω → ℝ} {p : ℝ} + +/-- A `{0, 1}`-valued loss that occurs with probability `p` is absent with probability `1 − p`. -/ +lemma measureReal_eq_zero_of_bernoulli {Z : Ω → ℝ} (hZ : Measurable Z) + (h01 : ∀ ω, Z ω = 0 ∨ Z ω = 1) (hp : P.real {ω | Z ω = 1} = p) : + P.real {ω | Z ω = 0} = 1 - p := by + have hs : MeasurableSet {ω | Z ω = 1} := hZ (measurableSet_singleton 1) + rw [← hp, ← probReal_compl_eq_one_sub hs] + congr 1 + ext ω + rcases h01 ω with h | h <;> simp [h] + +/-- **VaR of a Bernoulli loss**: a `{0, 1}`-valued loss that occurs with probability `p` has +`VaR_α = 0` when `α ≤ 1 − p` and `VaR_α = 1` otherwise. -/ +theorem valueAtRisk_of_bernoulli {Z : Ω → ℝ} (hZ : Measurable Z) (h01 : ∀ ω, Z ω = 0 ∨ Z ω = 1) + (hp : P.real {ω | Z ω = 1} = p) (hα : α ∈ Ioo 0 1) : + valueAtRisk Z P α = if α ≤ 1 - p then 0 else 1 := by + have hzero := measureReal_eq_zero_of_bernoulli hZ h01 hp + have hneg (x : ℝ) (hx : x < 0) : P.real {ω | Z ω ≤ x} = 0 := by + rw [show {ω | Z ω ≤ x} = ∅ from eq_empty_of_forall_notMem fun ω hω ↦ by + rcases h01 ω with h | h <;> simp only [mem_ofPred_eq, h] at hω <;> linarith] + simp + have hsub (x : ℝ) (hx : x < 1) : {ω | Z ω ≤ x} ⊆ {ω | Z ω = 0} := fun ω hω ↦ + (h01 ω).resolve_right fun h ↦ by simp only [mem_ofPred_eq, h] at hω; linarith + split_ifs with h + · refine (valueAtRisk_eq_iff hZ.aemeasurable hα).2 ⟨?_, fun x hx ↦ by rw [hneg x hx]; exact hα.1⟩ + rwa [show {ω | Z ω ≤ 0} = {ω | Z ω = 0} from + (hsub 0 zero_lt_one).antisymm fun ω hω ↦ hω.le, hzero] + · refine (valueAtRisk_eq_iff hZ.aemeasurable hα).2 ⟨?_, fun x hx ↦ ?_⟩ + · rw [show {ω | Z ω ≤ 1} = univ from eq_univ_of_forall fun ω ↦ by + rcases h01 ω with h | h <;> simp [h], probReal_univ] + exact hα.2.le + · calc P.real {ω | Z ω ≤ x} ≤ P.real {ω | Z ω = 0} := measureReal_mono (hsub x hx) + _ = 1 - p := hzero + _ < α := not_le.1 h + +/-- Below level `1` the portfolio loss vanishes exactly when no loss occurs. -/ +lemma setOf_sum_le_eq_iInter (h01 : ∀ i ω, Y i ω = 0 ∨ Y i ω = 1) {x : ℝ} + (hx0 : 0 ≤ x) (hx1 : x < 1) : + {ω | ∑ i, Y i ω ≤ x} = ⋂ i, {ω | Y i ω = 0} := by + ext ω + simp only [mem_ofPred_eq, mem_iInter] + refine ⟨fun h i ↦ (h01 i ω).resolve_right fun hi ↦ ?_, fun h ↦ by simp [h, hx0]⟩ + have : Y i ω ≤ ∑ j, Y j ω := + Finset.single_le_sum (f := fun j ↦ Y j ω) + (fun j _ ↦ by rcases h01 j ω with h | h <;> simp [h]) (Finset.mem_univ i) + linarith + +/-- With independent losses, no default occurs with probability `(1 − p)^d`. -/ +lemma measureReal_iInter_setOf_eq_zero_eq_pow (hmeas : ∀ i, Measurable (Y i)) + (h01 : ∀ i ω, Y i ω = 0 ∨ Y i ω = 1) (hp : ∀ i, P.real {ω | Y i ω = 1} = p) + (hind : iIndepFun Y P) : + P.real (⋂ i, {ω | Y i ω = 0}) = (1 - p) ^ Fintype.card ι := by + rw [measureReal_def, hind.meas_iInter (s := fun i ↦ {ω | Y i ω = 0}) + fun i ↦ ⟨{0}, measurableSet_singleton 0, rfl⟩, ENNReal.toReal_prod] + simp_rw [← measureReal_def, measureReal_eq_zero_of_bernoulli (hmeas _) (h01 _) (hp _), + Finset.prod_const, Finset.card_univ] + +/-- If defaults are rarer than `1 − α` jointly, the portfolio VaR is at least one default. -/ +private lemma one_le_valueAtRisk_sum (hmeas : ∀ i, Measurable (Y i)) + (h01 : ∀ i ω, Y i ω = 0 ∨ Y i ω = 1) (hp : ∀ i, P.real {ω | Y i ω = 1} = p) + (hind : iIndepFun Y P) (hα : α ∈ Ioo 0 1) (h : (1 - p) ^ Fintype.card ι < α) : + 1 ≤ valueAtRisk (fun ω ↦ ∑ i, Y i ω) P α := by + have hS : AEMeasurable (fun ω ↦ ∑ i, Y i ω) P := + (Finset.measurable_sum _ fun i _ ↦ hmeas i).aemeasurable + have hnn (ω : Ω) : 0 ≤ ∑ i, Y i ω := + Finset.sum_nonneg fun i _ ↦ by rcases h01 i ω with h | h <;> simp [h] + refine le_of_forall_lt fun x hx ↦ (lt_valueAtRisk_iff hS hα).2 ?_ + rcases lt_or_ge x 0 with hx0 | hx0 + · rw [show {ω | ∑ i, Y i ω ≤ x} = ∅ from eq_empty_of_forall_notMem fun ω hω ↦ + (hx0.trans_le (hnn ω)).not_ge hω, measureReal_empty] + exact hα.1 + · rwa [setOf_sum_le_eq_iInter h01 hx0 hx, + measureReal_iInter_setOf_eq_zero_eq_pow hmeas h01 hp hind] + +/-- **VaR is superadditive for independent defaults exactly on `((1 − p)^d, 1 − p]`** +(QRM Exercise Book, Exercises 2.20 and 2.27). For `d` independent `{0, 1}`-valued losses that +each occur with probability `p`, +`VaR_α(Y₁ + ⋯ + Y_d) > VaR_α(Y₁) + ⋯ + VaR_α(Y_d) ↔ (1 − p)^d < α ≤ 1 − p`. -/ +theorem valueAtRisk_sum_bernoulli_superadditive_iff (hmeas : ∀ i, Measurable (Y i)) + (h01 : ∀ i ω, Y i ω = 0 ∨ Y i ω = 1) (hp : ∀ i, P.real {ω | Y i ω = 1} = p) + (hind : iIndepFun Y P) (hα : α ∈ Ioo 0 1) : + ∑ i, valueAtRisk (Y i) P α < valueAtRisk (fun ω ↦ ∑ i, Y i ω) P α ↔ + (1 - p) ^ Fintype.card ι < α ∧ α ≤ 1 - p := by + have hS : AEMeasurable (fun ω ↦ ∑ i, Y i ω) P := + (Finset.measurable_sum _ fun i _ ↦ hmeas i).aemeasurable + simp_rw [valueAtRisk_of_bernoulli (hmeas _) (h01 _) (hp _) hα] + by_cases h1p : α ≤ 1 - p + · simp only [h1p, ↓reduceIte, Finset.sum_const_zero, and_true] + refine ⟨fun hlt ↦ lt_of_not_ge fun hle ↦ hlt.not_ge ?_, fun h ↦ + zero_lt_one.trans_le (one_le_valueAtRisk_sum hmeas h01 hp hind hα h)⟩ + -- at `α ≤ (1 − p)^d` the portfolio VaR is `0` + refine (valueAtRisk_le_iff hS hα).2 ?_ + rw [setOf_sum_le_eq_iInter h01 le_rfl zero_lt_one, + measureReal_iInter_setOf_eq_zero_eq_pow hmeas h01 hp hind] + exact hle + · simp only [h1p, ↓reduceIte, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_one, + and_false, iff_false, not_lt] + -- the portfolio loss never exceeds `d` + refine (valueAtRisk_le_iff hS hα).2 ?_ + rw [show {ω | ∑ i, Y i ω ≤ Fintype.card ι} = univ from eq_univ_of_forall fun ω ↦ + (Finset.sum_le_sum fun i _ ↦ show Y i ω ≤ 1 by rcases h01 i ω with h | h <;> simp [h]).trans + (by simp), probReal_univ] + exact hα.2.le + +/-- **Two defaultable loans** (QRM Exercise Book, Exercise 2.20): for two independent +`{0, 1}`-valued losses with default probability `p` and a level `(1 − p)² < α ≤ 1 − p`, each loan +has `VaR_α = 0` while the portfolio has `VaR_α = 1`. -/ +theorem valueAtRisk_sum_bernoulli_of_card_two (hcard : Fintype.card ι = 2) + (hmeas : ∀ i, Measurable (Y i)) (h01 : ∀ i ω, Y i ω = 0 ∨ Y i ω = 1) + (hp : ∀ i, P.real {ω | Y i ω = 1} = p) (hind : iIndepFun Y P) (hα : α ∈ Ioo 0 1) + (hlo : (1 - p) ^ 2 < α) (hhi : α ≤ 1 - p) : + valueAtRisk (fun ω ↦ ∑ i, Y i ω) P α = 1 ∧ ∀ i, valueAtRisk (Y i) P α = 0 := by + have hS : AEMeasurable (fun ω ↦ ∑ i, Y i ω) P := + (Finset.measurable_sum _ fun i _ ↦ hmeas i).aemeasurable + refine ⟨le_antisymm ((valueAtRisk_le_iff hS hα).2 ?_) + (one_le_valueAtRisk_sum hmeas h01 hp hind hα (by rwa [hcard])), + fun i ↦ by rw [valueAtRisk_of_bernoulli (hmeas i) (h01 i) (hp i) hα, ite_eq_left hhi]⟩ + -- the portfolio loss exceeds `1` only if both loans default, with probability `p²` + obtain ⟨i₀⟩ : Nonempty ι := Fintype.card_pos_iff.1 (by omega) + have hp01 : 0 ≤ p ∧ p ≤ 1 := by + rw [← hp i₀] + exact ⟨measureReal_nonneg, measureReal_le_one⟩ + have hsub : (⋂ i, {ω | Y i ω = 1})ᶜ ⊆ {ω | ∑ i, Y i ω ≤ 1} := by + classical + intro ω hω + obtain ⟨j, hj⟩ : ∃ j, Y j ω ≠ 1 := by simpa using hω + have hj0 : Y j ω = 0 := (h01 j ω).resolve_right hj + have hle : ∑ i ∈ Finset.univ.erase j, Y i ω ≤ ∑ _i ∈ Finset.univ.erase j, (1 : ℝ) := + Finset.sum_le_sum fun i _ ↦ by rcases h01 i ω with h | h <;> simp [h] + rw [Finset.sum_const, Finset.card_erase_of_mem (Finset.mem_univ j), Finset.card_univ, + hcard] at hle + rw [mem_ofPred_eq, ← Finset.add_sum_erase _ _ (Finset.mem_univ j), hj0, zero_add] + simpa using hle + have hall : P.real (⋂ i, {ω | Y i ω = 1}) = p ^ 2 := by + rw [measureReal_def, hind.meas_iInter (s := fun i ↦ {ω | Y i ω = 1}) + fun i ↦ ⟨{1}, measurableSet_singleton 1, rfl⟩, ENNReal.toReal_prod] + simp_rw [← measureReal_def, hp, Finset.prod_const, Finset.card_univ, hcard] + calc α ≤ 1 - p := hhi + _ ≤ 1 - p ^ 2 := by nlinarith [hp01.1, hp01.2] + _ = P.real (⋂ i, {ω | Y i ω = 1})ᶜ := by + have hm : MeasurableSet (⋂ i, {ω | Y i ω = 1}) := + MeasurableSet.iInter fun i ↦ hmeas i (measurableSet_singleton 1) + rw [probReal_compl_eq_one_sub hm, hall] + _ ≤ P.real {ω | ∑ i, Y i ω ≤ 1} := measureReal_mono hsub + +end Bernoulli + +/-! ### Infinite-mean Pareto losses -/ + +section Pareto + +/-- **The CDF of a convolution**: `F_{μ ∗ ν}(x) = ∫ F_ν(x − a) dμ(a)`. -/ +theorem cdf_conv (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] (x : ℝ) : + cdf (μ ∗ ν) x = ∫ a, cdf ν (x - a) ∂μ := by + have hmeas : Measurable fun a ↦ cdf ν (x - a) := + (monotone_cdf ν).measurable.comp (measurable_const.sub measurable_id) + have hint : Integrable (fun a ↦ cdf ν (x - a)) μ := + (integrable_const (1 : ℝ)).mono' hmeas.aestronglyMeasurable + (ae_of_all _ fun a ↦ by rw [Real.norm_of_nonneg (cdf_nonneg ν _)]; exact cdf_le_one ν _) + have hin (a : ℝ) : + ∫⁻ b, (Iic x).indicator 1 (a + b) ∂ν = ENNReal.ofReal (cdf ν (x - a)) := by + rw [ofReal_cdf, ← lintegral_indicator_one measurableSet_Iic] + congr 1 + ext b + simp only [indicator_apply, mem_Iic, le_sub_iff_add_le', Pi.one_apply] + rw [cdf_eq_real, measureReal_def, ← lintegral_indicator_one measurableSet_Iic, + Measure.lintegral_conv (measurable_one.indicator measurableSet_Iic)] + simp_rw [hin] + rw [← ofReal_integral_eq_lintegral_ofReal hint (ae_of_all _ fun _ ↦ cdf_nonneg ν _), + ENNReal.toReal_ofReal (integral_nonneg fun _ ↦ cdf_nonneg ν _)] + +/-- Integrals against the Pareto law are integrals against its density. -/ +lemma integral_paretoMeasure {t r : ℝ} (ht : 0 ≤ t) (hr : 0 ≤ r) (f : ℝ → ℝ) : + ∫ a, f a ∂paretoMeasure t r = ∫ a, paretoPDFReal t r a * f a := by + have hm : Measurable (paretoPDF t r) := (measurable_paretoPDFReal t r).ennreal_ofReal + rw [paretoMeasure, integral_withDensity_eq_integral_toReal_smul hm + (ae_of_all _ fun _ ↦ ENNReal.ofReal_lt_top)] + congr 1 + ext a + rw [paretoPDF, ENNReal.toReal_ofReal (paretoPDFReal_nonneg ht hr a), smul_eq_mul] + +/-- The antiderivative of the convolution integrand of `cdf_conv_paretoMeasure_half`. -/ +lemma hasDerivAt_convAntideriv {x a : ℝ} (ha : 0 < a) (hxa : 0 < x - a) : + HasDerivAt (fun a ↦ -(√a)⁻¹ + √(x - a) / (x * √a)) + ((1 - (√(x - a))⁻¹) / (2 * a * √a)) a := by + have hu : 0 < √a := sqrt_pos.2 ha + have hw : 0 < √(x - a) := sqrt_pos.2 hxa + have hx : 0 < x := by linarith + have hA : HasDerivAt (fun a ↦ √a) (1 / (2 * √a)) a := hasDerivAt_sqrt ha.ne' + have hB : HasDerivAt (fun a ↦ √(x - a)) (-1 / (2 * √(x - a))) a := + ((hasDerivAt_id' a).const_sub x).sqrt hxa.ne' + have hD := (hA.inv hu.ne').neg.add (hB.div (hA.const_mul x) (by positivity)) + refine hD.congr_deriv ?_ + have ha2 : √a ^ 2 = a := sq_sqrt ha.le + have hw2 : √(x - a) ^ 2 = x - a := sq_sqrt hxa.le + generalize √a = u at * + generalize √(x - a) = w at * + subst ha2 + obtain rfl : x = w ^ 2 + u ^ 2 := by linarith + have hu' : u ≠ 0 := hu.ne' + have hw' : w ≠ 0 := hw.ne' + have hx' : w ^ 2 + u ^ 2 ≠ 0 := by positivity + field_simp + ring + +/-- **The convolution CDF of two infinite-mean Pareto laws** (QRM Exercise Book, +Exercise 2.28): for `F(x) = 1 − x^{−1/2}` on `[1, ∞)`, the law of the sum of two independent +copies has CDF `(F ∗ F)(x) = 1 − 2√(x − 1)/x` for `x ≥ 2`. -/ +theorem cdf_conv_paretoMeasure_half {x : ℝ} (hx : 2 ≤ x) : + cdf (paretoMeasure 1 (1 / 2) ∗ paretoMeasure 1 (1 / 2)) x = 1 - 2 * √(x - 1) / x := by + have := isProbabilityMeasure_paretoMeasure (t := 1) (r := 1 / 2) one_pos (by norm_num) + have hx1 : (1 : ℝ) ≤ x - 1 := by linarith + -- the integrand `a ↦ f(a) F(x − a)` lives on `[1, x − 1]` + have hsupp (a : ℝ) (ha : a ∉ Icc 1 (x - 1)) : + paretoPDFReal 1 (1 / 2) a * cdf (paretoMeasure 1 (1 / 2)) (x - a) = 0 := by + rcases not_and_or.1 ha with ha1 | ha1 + · rw [paretoPDFReal, ite_eq_right ha1, zero_mul] + · rw [cdf_paretoMeasure_of_lt one_pos (by norm_num : (0 : ℝ) < 1 / 2) + (by linarith [not_le.1 ha1] : x - a < 1), mul_zero] + -- on `[1, x − 1]` it is `(1 − 1/√(x − a))/(2a√a)` + have heq : EqOn (fun a ↦ paretoPDFReal 1 (1 / 2) a * cdf (paretoMeasure 1 (1 / 2)) (x - a)) + (fun a ↦ (1 - (√(x - a))⁻¹) / (2 * a * √a)) (uIcc 1 (x - 1)) := by + intro a ha + rw [uIcc_of_le hx1] at ha + have ha0 : 0 < a := zero_lt_one.trans_le ha.1 + have hxa : 1 ≤ x - a := by linarith [ha.2] + have hu : 0 < √a := sqrt_pos.2 ha0 + have hw : 0 < √(x - a) := sqrt_pos.2 (by linarith) + have e1 : a ^ (-(1 / 2 + 1) : ℝ) = (a * √a)⁻¹ := by + rw [rpow_neg ha0.le, show (1 / 2 + 1 : ℝ) = 1 + 1 / 2 by norm_num, rpow_add ha0, rpow_one, + ← sqrt_eq_rpow] + have e2 : (1 / (x - a)) ^ (1 / 2 : ℝ) = (√(x - a))⁻¹ := by + rw [← sqrt_eq_rpow, one_div, sqrt_inv] + simp only [paretoPDFReal, ite_eq_left ha.1, one_rpow, mul_one, + cdf_paretoMeasure_of_le one_pos (by norm_num : (0 : ℝ) < 1 / 2) hxa] + rw [e1, e2] + field_simp + have hint : IntervalIntegrable (fun a ↦ (1 - (√(x - a))⁻¹) / (2 * a * √a)) volume 1 (x - 1) := by + refine ContinuousOn.intervalIntegrable fun a ha ↦ ?_ + rw [uIcc_of_le hx1] at ha + have ha0 : 0 < a := zero_lt_one.trans_le ha.1 + have hw : √(x - a) ≠ 0 := (sqrt_pos.2 (by linarith [ha.2])).ne' + exact ContinuousAt.continuousWithinAt (by fun_prop (disch := first | assumption | positivity)) + rw [cdf_conv, integral_paretoMeasure (r := 1 / 2) zero_le_one (by norm_num), + ← setIntegral_eq_integral_of_forall_compl_eq_zero hsupp, integral_Icc_eq_integral_Ioc, + ← intervalIntegral.integral_of_le hx1, intervalIntegral.integral_congr heq, + intervalIntegral.integral_eq_sub_of_hasDerivAt + (f := fun a ↦ -(√a)⁻¹ + √(x - a) / (x * √a)) (fun a ha ↦ ?_) hint] + · simp only [sub_sub_cancel, sqrt_one, inv_one, mul_one] + have hv : 0 < √(x - 1) := sqrt_pos.2 (by linarith) + have hv2 : √(x - 1) ^ 2 = x - 1 := sq_sqrt (by linarith) + generalize √(x - 1) = v at * + obtain rfl : x = v ^ 2 + 1 := by linarith + have hv' : v ≠ 0 := hv.ne' + have hx' : v ^ 2 + 1 ≠ 0 := by positivity + field_simp + ring + · rw [uIcc_of_le hx1] at ha + exact hasDerivAt_convAntideriv (zero_lt_one.trans_le ha.1) (by linarith [ha.2]) + +/-- **VaR is superadditive at every level for infinite-mean Pareto losses** (QRM Exercise Book, +Exercise 2.28): if `L₁, L₂` are independent with `F(x) = 1 − x^{−1/2}` on `[1, ∞)`, then +`VaR_α(L₁ + L₂) > VaR_α(L₁) + VaR_α(L₂)` for every `α ∈ (0, 1)`. -/ +theorem valueAtRisk_add_gt_of_paretoHalf {L₁ L₂ : Ω → ℝ} + (h₁ : HasLaw L₁ (paretoMeasure 1 (1 / 2)) P) (h₂ : HasLaw L₂ (paretoMeasure 1 (1 / 2)) P) + (hind : IndepFun L₁ L₂ P) (hα : α ∈ Ioo 0 1) : + valueAtRisk L₁ P α + valueAtRisk L₂ P α < valueAtRisk (fun ω ↦ L₁ ω + L₂ ω) P α := by + have := isProbabilityMeasure_paretoMeasure (t := 1) (r := 1 / 2) one_pos (by norm_num) + have hS : HasLaw (fun ω ↦ L₁ ω + L₂ ω) + (paretoMeasure 1 (1 / 2) ∗ paretoMeasure 1 (1 / 2)) P := + hind.hasLaw_fun_add h₁ h₂ + have hs0 : 0 < 1 - α := sub_pos.2 hα.2 + have hs1 : 1 - α < 1 := by linarith [hα.1] + -- each marginal VaR is `(1 − α)^{−2}` + have hVaR : quantile (paretoMeasure 1 (1 / 2)) α = ((1 - α) ^ 2)⁻¹ := by + rw [quantile_paretoMeasure (r := 1 / 2) one_pos (by norm_num) hα, one_mul, + show -(1 / 2 : ℝ)⁻¹ = -2 by norm_num, rpow_neg hs0.le, rpow_two] + rw [valueAtRisk_eq_quantile h₁, valueAtRisk_eq_quantile h₂, valueAtRisk_eq_quantile hS, hVaR, + lt_quantile_iff hα] + have hsq : (1 - α) ^ 2 < 1 := by nlinarith + have htwo : 2 ≤ ((1 - α) ^ 2)⁻¹ + ((1 - α) ^ 2)⁻¹ := by + have : 1 < ((1 - α) ^ 2)⁻¹ := (one_lt_inv₀ (by positivity)).2 hsq + linarith + rw [cdf_conv_paretoMeasure_half htwo] + -- `2t − 1 > t` for `t = (1 − α)^{−2} > 1` + set s := 1 - α with hs + have hv : 0 < √((s ^ 2)⁻¹ + (s ^ 2)⁻¹ - 1) := sqrt_pos.2 (by linarith) + have hv2 : √((s ^ 2)⁻¹ + (s ^ 2)⁻¹ - 1) ^ 2 = (s ^ 2)⁻¹ + (s ^ 2)⁻¹ - 1 := + sq_sqrt (by linarith) + generalize √((s ^ 2)⁻¹ + (s ^ 2)⁻¹ - 1) = v at * + have hα' : α = 1 - s := by rw [hs]; ring + rw [hα'] + have hs0' : s ≠ 0 := hs0.ne' + have hvs : (v * s) ^ 2 = 2 - s ^ 2 := by + rw [mul_pow, hv2] + field_simp + ring + have hvs1 : 1 < v * s := by nlinarith [mul_pos hv hs0] + rw [show 2 * v / ((s ^ 2)⁻¹ + (s ^ 2)⁻¹) = v * s ^ 2 by field_simp; ring] + nlinarith + +end Pareto + +/-! ### Jointly Gaussian losses -/ + +section Gaussian + +/-- **Gaussian VaR is subadditive at levels above the median**: for a jointly Gaussian pair, +`VaR_α(X + Y) ≤ VaR_α(X) + VaR_α(Y)` when `α ≥ 1/2`. `VaR = E + sd Φ⁻¹(α)` and the standard +deviation is subadditive, so no hypothesis on the correlation is needed. -/ +theorem valueAtRisk_add_le_of_hasGaussianLaw {X Y : Ω → ℝ} + (h : HasGaussianLaw (fun ω ↦ (X ω, Y ω)) P) (hα : α ∈ Ioo 0 1) (hα₂ : 1 / 2 ≤ α) : + valueAtRisk (fun ω ↦ X ω + Y ω) P α ≤ valueAtRisk X P α + valueAtRisk Y P α := by + have := h.isProbabilityMeasure + rw [valueAtRisk_of_hasGaussianLaw h.fun_add hα, valueAtRisk_of_hasGaussianLaw h.fst hα, + valueAtRisk_of_hasGaussianLaw h.snd hα, integral_add h.fst.integrable h.snd.integrable] + nlinarith [mul_le_mul_of_nonneg_right (sqrt_variance_add_le h.fst.memLp_two h.snd.memLp_two) + ((PhiInv_nonneg_iff hα).2 hα₂)] + +/-- **Gaussian VaR is subadditive exactly above the median** (QRM Exercise Book, Exercise 2.22): +for a jointly Gaussian pair `(X₁, X₂)` with correlation below one +(`cov[X₁, X₂] < σ₁σ₂`), `VaR_α(X₁ + X₂) ≤ VaR_α(X₁) + VaR_α(X₂) ↔ α ≥ 1/2`. -/ +theorem valueAtRisk_add_le_iff_of_hasGaussianLaw {X₁ X₂ : Ω → ℝ} + (h : HasGaussianLaw (fun ω ↦ (X₁ ω, X₂ ω)) P) + (hcorr : cov[X₁, X₂; P] < √Var[X₁; P] * √Var[X₂; P]) (hα : α ∈ Ioo 0 1) : + valueAtRisk (fun ω ↦ X₁ ω + X₂ ω) P α ≤ valueAtRisk X₁ P α + valueAtRisk X₂ P α ↔ + 1 / 2 ≤ α := by + refine ⟨fun hle ↦ ?_, valueAtRisk_add_le_of_hasGaussianLaw h hα⟩ + have := h.isProbabilityMeasure + have h₁ := h.fst + have h₂ := h.snd + have hσ : √Var[fun ω ↦ X₁ ω + X₂ ω; P] < √Var[X₁; P] + √Var[X₂; P] := by + have hvar : Var[fun ω ↦ X₁ ω + X₂ ω; P] = Var[X₁; P] + 2 * cov[X₁, X₂; P] + Var[X₂; P] := + variance_add h₁.memLp_two h₂.memLp_two + have hs₁ := sq_sqrt (variance_nonneg X₁ P) + have hs₂ := sq_sqrt (variance_nonneg X₂ P) + calc √Var[fun ω ↦ X₁ ω + X₂ ω; P] < √((√Var[X₁; P] + √Var[X₂; P]) ^ 2) := + sqrt_lt_sqrt (variance_nonneg _ P) (by rw [hvar]; nlinarith) + _ = √Var[X₁; P] + √Var[X₂; P] := sqrt_sq (by positivity) + rw [valueAtRisk_of_hasGaussianLaw h.fun_add hα, valueAtRisk_of_hasGaussianLaw h₁ hα, + valueAtRisk_of_hasGaussianLaw h₂ hα, integral_add h₁.integrable h₂.integrable] at hle + rw [← PhiInv_nonneg_iff hα] + by_contra! hz + nlinarith [mul_lt_mul_of_neg_right hσ hz] + +end Gaussian + +end MathFin diff --git a/LeanPool/MathFin/Risk/ValueAtRisk.lean b/LeanPool/MathFin/Risk/ValueAtRisk.lean new file mode 100644 index 0000000000..6f3f6a5c64 --- /dev/null +++ b/LeanPool/MathFin/Risk/ValueAtRisk.lean @@ -0,0 +1,234 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Probability.Laws.Quantile +public import Mathlib.Algebra.Order.Star.Real + +/-! +# Value-at-risk and expected shortfall of a general loss + +For a loss `X` on a probability space `(Ω, P)` and a confidence level `α ∈ (0, 1)`: + +* **value-at-risk** is the `α`-quantile of the law of `X`, + `VaR_α(X) = inf {x | α ≤ P(X ≤ x)}` (`valueAtRisk`); +* **expected shortfall** is the average of the value-at-risk over the levels above `α`, + `ES_α(X) = (1 − α)⁻¹ ∫_α^1 VaR_u(X) du` (`expectedShortfall`). + +These are the definitions of McNeil, Frey and Embrechts, *Quantitative Risk Management* (2015), +Definitions 2.8 and 2.12. They apply to every law, including laws with atoms. The closed forms of +`Risk/Gaussian.lean`, written in a quantile parameter `z`, are the Gaussian instances +(`Risk/GaussianValueAtRisk.lean`). + +Both functionals depend on `X` only through its law, so every property is a property of the +quantile function (`Probability/Laws/Quantile.lean`). In particular VaR commutes with monotone +lower-semicontinuous maps (`valueAtRisk_comp`). Translation invariance, positive homogeneity and +comonotone additivity are the three instances of that one fact. + +Subadditivity of expected shortfall, the one coherence axiom that value-at-risk lacks, is in +`Risk/ExpectedShortfall.lean`. + +## Main definitions + +* `valueAtRisk`: the value-at-risk `VaR_α(X) = inf {x | α ≤ P(X ≤ x)}`, the `α`-quantile of the + law of the loss `X`. +* `expectedShortfall`: the expected shortfall `ES_α(X) = (1 − α)⁻¹ ∫_α^1 VaR_u(X) du`, the + average of the value-at-risk over the levels above `α`. + +## Main results + +* `valueAtRisk_le_iff`: `VaR_α(X) ≤ x ↔ α ≤ P(X ≤ x)`. +* `valueAtRisk_mono`: a loss that is almost surely larger has a larger VaR. +* `valueAtRisk_comp`: `VaR_α(h ∘ X) = h (VaR_α(X))` for monotone lower-semicontinuous `h`. +* `valueAtRisk_add_const`, `valueAtRisk_const_mul`: translation invariance and positive + homogeneity. +* `valueAtRisk_add_of_comonotone`: VaR is additive for comonotone losses. +* `integrableOn_valueAtRisk`: an integrable loss has an integrable VaR curve. +* `valueAtRisk_le_expectedShortfall`: `VaR_α ≤ ES_α`. +* `expectedShortfall_add_const`, `expectedShortfall_const_mul`, `expectedShortfall_mono`. +* `valueAtRisk_const`, `expectedShortfall_const`: a constant loss is its own VaR and ES. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Proposition 7.20 +* [*QRM Exercise Book*][QRMExerciseBook], Ex. 2.8 + +## Tags + +value at risk, expected shortfall, quantile function, VaR, confidence level, comonotone additivity, +tail risk, MSC 91G70, MSC 60E05, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory ProbabilityTheory Set + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} {X Y : Ω → ℝ} {α x : ℝ} + +/-- **Value-at-risk** of a loss `X` at confidence level `α`: the `α`-quantile of the law of `X`, +`VaR_α(X) = inf {x | α ≤ P(X ≤ x)}`. -/ +noncomputable def valueAtRisk (X : Ω → ℝ) (P : Measure Ω) (α : ℝ) : ℝ := + quantile (P.map X) α + +/-- **Expected shortfall** of a loss `X` at confidence level `α`: the average value-at-risk over +the levels above `α`, `ES_α(X) = (1 − α)⁻¹ ∫_α^1 VaR_u(X) du`. -/ +noncomputable def expectedShortfall (X : Ω → ℝ) (P : Measure Ω) (α : ℝ) : ℝ := + (1 - α)⁻¹ * ∫ u in Ioo α 1, valueAtRisk X P u + +/-- VaR depends on a loss only through its law. -/ +lemma valueAtRisk_eq_quantile {μ : Measure ℝ} (hX : HasLaw X μ P) : + valueAtRisk X P α = quantile μ α := by + rw [valueAtRisk, hX.map_eq] + +variable [IsProbabilityMeasure P] + +/-! ### Value-at-risk -/ + +/-- The Galois connection for VaR: `VaR_α(X) ≤ x ↔ α ≤ P(X ≤ x)`. -/ +theorem valueAtRisk_le_iff (hX : AEMeasurable X P) (hα : α ∈ Ioo 0 1) : + valueAtRisk X P α ≤ x ↔ α ≤ P.real {ω | X ω ≤ x} := by + rw [valueAtRisk, quantile_le_iff hα, cdf_eq_real, + map_measureReal_apply_of_aemeasurable hX measurableSet_Iic] + rfl + +/-- `x < VaR_α(X) ↔ P(X ≤ x) < α`. -/ +theorem lt_valueAtRisk_iff (hX : AEMeasurable X P) (hα : α ∈ Ioo 0 1) : + x < valueAtRisk X P α ↔ P.real {ω | X ω ≤ x} < α := by + simpa only [not_le] using (valueAtRisk_le_iff hX hα).not + +/-- The loss stays at or below its VaR with probability at least `α`. -/ +lemma le_measureReal_le_valueAtRisk (hX : AEMeasurable X P) (hα : α ∈ Ioo 0 1) : + α ≤ P.real {ω | X ω ≤ valueAtRisk X P α} := + (valueAtRisk_le_iff hX hα).1 le_rfl + +/-- **Monotonicity**: a loss that is almost surely larger has a larger VaR. -/ +theorem valueAtRisk_mono (hX : AEMeasurable X P) (hY : AEMeasurable Y P) (hXY : X ≤ᵐ[P] Y) + (hα : α ∈ Ioo 0 1) : valueAtRisk X P α ≤ valueAtRisk Y P α := + (valueAtRisk_le_iff hX hα).2 <| (le_measureReal_le_valueAtRisk hY hα).trans <| + ENNReal.toReal_mono (measure_ne_top _ _) <| measure_mono_ae <| + hXY.mono fun _ h hy ↦ h.trans hy + +/-- **VaR commutes with monotone lower-semicontinuous maps**: `VaR_α(h ∘ X) = h (VaR_α(X))` +(McNeil–Frey–Embrechts, Proposition A.3). -/ +theorem valueAtRisk_comp (hX : AEMeasurable X P) {h : ℝ → ℝ} (hmono : Monotone h) + (hlsc : LowerSemicontinuous h) (hα : α ∈ Ioo 0 1) : + valueAtRisk (fun ω ↦ h (X ω)) P α = h (valueAtRisk X P α) := by + rw [valueAtRisk, valueAtRisk, ← quantile_map hmono hlsc hα, + AEMeasurable.map_map_of_aemeasurable hmono.measurable.aemeasurable hX] + rfl + +/-- **Translation invariance**: `VaR_α(X + m) = VaR_α(X) + m`. -/ +theorem valueAtRisk_add_const (hX : AEMeasurable X P) (hα : α ∈ Ioo 0 1) (m : ℝ) : + valueAtRisk (fun ω ↦ X ω + m) P α = valueAtRisk X P α + m := + valueAtRisk_comp (h := fun x ↦ x + m) hX (monotone_id.add_const m) + (continuous_add_const m).lowerSemicontinuous hα + +/-- **Positive homogeneity**: `VaR_α(c X) = c VaR_α(X)` for `c ≥ 0`. -/ +theorem valueAtRisk_const_mul (hX : AEMeasurable X P) (hα : α ∈ Ioo 0 1) {c : ℝ} (hc : 0 ≤ c) : + valueAtRisk (fun ω ↦ c * X ω) P α = c * valueAtRisk X P α := + valueAtRisk_comp (h := fun x ↦ c * x) hX (fun _ _ h ↦ mul_le_mul_of_nonneg_left h hc) + (continuous_const_mul c).lowerSemicontinuous hα + +/-- **VaR is comonotone additive**: losses that are monotone lower-semicontinuous functions of a +common risk factor `Z` have additive VaR. -/ +theorem valueAtRisk_add_of_comonotone {Z : Ω → ℝ} (hZ : AEMeasurable Z P) {f g : ℝ → ℝ} + (hf : Monotone f) (hf' : LowerSemicontinuous f) (hg : Monotone g) + (hg' : LowerSemicontinuous g) (hα : α ∈ Ioo 0 1) : + valueAtRisk (fun ω ↦ f (Z ω) + g (Z ω)) P α = + valueAtRisk (fun ω ↦ f (Z ω)) P α + valueAtRisk (fun ω ↦ g (Z ω)) P α := by + rw [valueAtRisk_comp hZ (hf.add hg) (hf'.add hg') hα, valueAtRisk_comp hZ hf hf' hα, + valueAtRisk_comp hZ hg hg' hα] + +/-- VaR is additive over a loss and an increasing affine image of it, +`VaR_α(X + (aX + b)) = VaR_α(X) + VaR_α(aX + b)` for `a ≥ 0` (MFE Exercise 2.8). -/ +theorem valueAtRisk_add_affine (hX : AEMeasurable X P) (hα : α ∈ Ioo 0 1) {a : ℝ} (ha : 0 ≤ a) + (b : ℝ) : + valueAtRisk (fun ω ↦ X ω + (a * X ω + b)) P α = + valueAtRisk X P α + valueAtRisk (fun ω ↦ a * X ω + b) P α := + valueAtRisk_add_of_comonotone (f := fun x ↦ x) (g := fun x ↦ a * x + b) hX monotone_id + continuous_id.lowerSemicontinuous + ((monotone_id.const_mul ha).add_const b) + (by fun_prop : Continuous fun x ↦ a * x + b).lowerSemicontinuous hα + +/-! ### Expected shortfall -/ + +/-- An integrable loss has an integrable VaR curve on `(0, 1)`. -/ +theorem integrableOn_valueAtRisk (hX : Integrable X P) : + IntegrableOn (fun u ↦ valueAtRisk X P u) (Ioo 0 1) := by + exact (integrableOn_comp_quantile_iff (f := id) aestronglyMeasurable_id).2 <| + (integrable_map_measure aestronglyMeasurable_id hX.aemeasurable).2 hX + +omit [IsProbabilityMeasure P] in +/-- The VaR curve is monotone in the confidence level. -/ +lemma valueAtRisk_mono_level (hα : α ∈ Ioo 0 1) {β : ℝ} (hβ : β ∈ Ioo 0 1) (hαβ : α ≤ β) : + valueAtRisk X P α ≤ valueAtRisk X P β := + monotoneOn_quantile hα hβ hαβ + +/-- **ES dominates VaR**: `VaR_α(X) ≤ ES_α(X)`, since the average is taken over the levels where +the VaR curve is at least `VaR_α(X)`. -/ +theorem valueAtRisk_le_expectedShortfall (hX : Integrable X P) (hα : α ∈ Ioo 0 1) : + valueAtRisk X P α ≤ expectedShortfall X P α := by + have h1α : 0 < 1 - α := sub_pos.2 hα.2 + rw [expectedShortfall, le_inv_mul_iff₀ h1α] + calc (1 - α) * valueAtRisk X P α = ∫ _ in Ioo α 1, valueAtRisk X P α := by + rw [setIntegral_const, Real.volume_real_Ioo_of_le hα.2.le, smul_eq_mul] + _ ≤ ∫ u in Ioo α 1, valueAtRisk X P u := + setIntegral_mono_on (integrableOn_const (by simp)) + ((integrableOn_valueAtRisk hX).mono_set (Ioo_subset_Ioo_left hα.1.le)) + measurableSet_Ioo fun u hu ↦ + valueAtRisk_mono_level hα ⟨hα.1.trans hu.1, hu.2⟩ hu.1.le + +/-- **Translation invariance** of ES: `ES_α(X + m) = ES_α(X) + m`. -/ +theorem expectedShortfall_add_const (hX : Integrable X P) (hα : α ∈ Ioo 0 1) (m : ℝ) : + expectedShortfall (fun ω ↦ X ω + m) P α = expectedShortfall X P α + m := by + have h1α : 0 < 1 - α := sub_pos.2 hα.2 + have hint : IntegrableOn (fun u ↦ valueAtRisk X P u) (Ioo α 1) := + (integrableOn_valueAtRisk hX).mono_set (Ioo_subset_Ioo_left hα.1.le) + rw [expectedShortfall, expectedShortfall, + setIntegral_congr_fun measurableSet_Ioo fun u hu ↦ + valueAtRisk_add_const hX.aemeasurable ⟨hα.1.trans hu.1, hu.2⟩ m, + integral_add hint (integrableOn_const (by simp)), setIntegral_const, + Real.volume_real_Ioo_of_le hα.2.le, smul_eq_mul] + field_simp + +/-- **Positive homogeneity** of ES: `ES_α(c X) = c ES_α(X)` for `c ≥ 0`. -/ +theorem expectedShortfall_const_mul (hX : Integrable X P) (hα : α ∈ Ioo 0 1) {c : ℝ} + (hc : 0 ≤ c) : expectedShortfall (fun ω ↦ c * X ω) P α = c * expectedShortfall X P α := by + rw [expectedShortfall, expectedShortfall, + setIntegral_congr_fun measurableSet_Ioo fun u hu ↦ + valueAtRisk_const_mul hX.aemeasurable ⟨hα.1.trans hu.1, hu.2⟩ hc, + integral_const_mul] + ring + +/-- **Monotonicity** of ES: a loss that is almost surely larger has a larger ES. -/ +theorem expectedShortfall_mono (hX : Integrable X P) (hY : Integrable Y P) (hXY : X ≤ᵐ[P] Y) + (hα : α ∈ Ioo 0 1) : expectedShortfall X P α ≤ expectedShortfall Y P α := by + have h1α : 0 < 1 - α := sub_pos.2 hα.2 + refine mul_le_mul_of_nonneg_left (setIntegral_mono_on + ((integrableOn_valueAtRisk hX).mono_set (Ioo_subset_Ioo_left hα.1.le)) + ((integrableOn_valueAtRisk hY).mono_set (Ioo_subset_Ioo_left hα.1.le)) measurableSet_Ioo + fun u hu ↦ valueAtRisk_mono hX.aemeasurable hY.aemeasurable hXY ⟨hα.1.trans hu.1, hu.2⟩) + (inv_nonneg.2 h1α.le) + +/-- The value-at-risk of a constant loss is the constant. -/ +theorem valueAtRisk_const (c : ℝ) (hα : α ∈ Ioo 0 1) : + valueAtRisk (fun _ ↦ c) P α = c := by + rw [valueAtRisk, Measure.map_const, measure_univ, one_smul, quantile_dirac c hα] + +/-- The expected shortfall of a constant loss is the constant. -/ +theorem expectedShortfall_const (c : ℝ) (hα : α ∈ Ioo 0 1) : + expectedShortfall (fun _ ↦ c) P α = c := by + have h1α : (1 - α) ≠ 0 := (sub_pos.2 hα.2).ne' + rw [expectedShortfall, setIntegral_congr_fun measurableSet_Ioo + fun u hu ↦ valueAtRisk_const (P := P) c ⟨hα.1.trans hu.1, hu.2⟩, setIntegral_const, + Real.volume_real_Ioo_of_le hα.2.le, smul_eq_mul, ← mul_assoc, inv_mul_cancel₀ h1α, one_mul] + +end MathFin diff --git a/LeanPool/MathFin/Risk/ValueAtRiskBisection.lean b/LeanPool/MathFin/Risk/ValueAtRiskBisection.lean new file mode 100644 index 0000000000..d8f5570f03 --- /dev/null +++ b/LeanPool/MathFin/Risk/ValueAtRiskBisection.lean @@ -0,0 +1,78 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.ValueAtRisk +public import LeanPool.MathFin.Probability.Analysis.Bisection + +/-! +# Value-at-risk by bisection + +`Probability/Analysis/Bisection.lean` proves that bisection for `f x = C` converges to the +*threshold* of +`f` against `C`: the point `σ` with `f x < C ↔ x < σ` on the bracket. It needs no continuity or +strict monotonicity of `f`. The Galois connection of the quantile function (`lt_valueAtRisk_iff`) +says that `VaR_α(X)` is exactly the threshold of the distribution function `x ↦ P(X ≤ x)` against +`α`. So bisection on the distribution function computes value-at-risk for every law, including +atoms and flat stretches, and after `n` steps the midpoint is within `(hi − lo)/2^{n+1}`. + +This is the consumer the bisection file was generalized for: a right-continuous CDF at its +quantile, where neither continuity nor strictness holds in general. + +## Main results + +* `valueAtRisk_mem_Icc_of_bracket`: a CDF bracket `P(X ≤ lo) < α ≤ P(X ≤ hi)` brackets VaR. +* `abs_bisectMid_sub_valueAtRisk_le`: the `n`-th estimate is within `(hi − lo)/2^{n+1}` of VaR. +* `tendsto_bisectMid_valueAtRisk`: bisection on the distribution function converges to VaR. + +## References + +* [A. J. McNeil, R. Frey and P. Embrechts, *Quantitative Risk Management: Concepts, Techniques and + Tools*][McNeilFreyEmbrechts], Chapter 9 + +## Tags + +VaR computation, bisection method, quantile numerical, distribution function threshold, +root finding, MSC 91G60, MSC 91G70, JEL C63 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory Set Filter Topology + +variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {P : Measure Ω} [IsProbabilityMeasure P] + {X : Ω → ℝ} {α lo hi : ℝ} + +/-- A bracket of the distribution function brackets VaR: if `P(X ≤ lo) < α ≤ P(X ≤ hi)` then +`VaR_α(X) ∈ [lo, hi]`. Both conditions can be checked by evaluating the CDF. -/ +lemma valueAtRisk_mem_Icc_of_bracket (hX : AEMeasurable X P) (hα : α ∈ Ioo 0 1) + (hlo : P.real {ω | X ω ≤ lo} < α) (hhi : α ≤ P.real {ω | X ω ≤ hi}) : + valueAtRisk X P α ∈ Icc lo hi := + ⟨((lt_valueAtRisk_iff hX hα).2 hlo).le, (valueAtRisk_le_iff hX hα).2 hhi⟩ + +/-- **The a-priori error of VaR by bisection**: the `n`-th midpoint of bisection on the +distribution function is within `(hi − lo)/2^{n+1}` of `VaR_α(X)`. -/ +theorem abs_bisectMid_sub_valueAtRisk_le (hX : AEMeasurable X P) (hα : α ∈ Ioo 0 1) + (hlo : P.real {ω | X ω ≤ lo} < α) (hhi : α ≤ P.real {ω | X ω ≤ hi}) (n : ℕ) : + |bisectMid (fun x ↦ P.real {ω | X ω ≤ x}) α lo hi n - valueAtRisk X P α| ≤ + (hi - lo) / 2 ^ (n + 1) := + abs_bisectMid_sub_le (fun _ _ ↦ (lt_valueAtRisk_iff hX hα).symm) + (valueAtRisk_mem_Icc_of_bracket hX hα hlo hhi) n + +/-- **VaR by bisection**: bisection on the distribution function `x ↦ P(X ≤ x)` against the level +`α` converges to `VaR_α(X)`, for every law. -/ +theorem tendsto_bisectMid_valueAtRisk (hX : AEMeasurable X P) (hα : α ∈ Ioo 0 1) + (hlo : P.real {ω | X ω ≤ lo} < α) (hhi : α ≤ P.real {ω | X ω ≤ hi}) : + Tendsto (bisectMid (fun x ↦ P.real {ω | X ω ≤ x}) α lo hi) atTop + (𝓝 (valueAtRisk X P α)) := + tendsto_bisectMid (fun _ _ ↦ (lt_valueAtRisk_iff hX hα).symm) + (valueAtRisk_mem_Icc_of_bracket hX hα hlo hhi) + +end MathFin diff --git a/LeanPool/MathFin/Risk/WorstCaseRisk.lean b/LeanPool/MathFin/Risk/WorstCaseRisk.lean new file mode 100644 index 0000000000..1acbeb5171 --- /dev/null +++ b/LeanPool/MathFin/Risk/WorstCaseRisk.lean @@ -0,0 +1,108 @@ +/- +Copyright (c) 2026 Raphael Coelho. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Raphael Coelho +-/ +module + +-- Ported from Formal MathFin v2.0.0 for Lean Pool. + +public import LeanPool.MathFin.Risk.AcceptanceSet + +/-! +# Worst-case loss: a concrete coherent risk measure + +The most conservative coherent risk measure of losses, `worstCase L = maxᵢ Lᵢ`, is a concrete +instance of `IsCoherentRiskMeasure` on a finite state space under any measure that charges every +state (so almost-sure order is the pointwise order); counting measure is the model case. Its +Artzner–Delbaen–Eber–Heath representation (from `coherentRisk_isLUB`) specialises to the supremum of +expected loss over the *entire* probability simplex — making the abstract representation tangible: +the worst case over states equals the worst case over all mixtures of states. + +## Main definitions + +* `worstCase`: the worst-case loss `maxᵢ Lᵢ` over a finite nonempty state space. + +## Main results + +* `MathFin.worstCase_isCoherent` — under a measure charging every state, worst-case loss + satisfies the four ADEH axioms +* `MathFin.worstCase_isLUB` — its representation is the sup over the probability simplex + +## References + +* [P. Artzner et al., *Coherent measures of risk*][ArtznerDelbaenEberHeath1999] + +## Tags + +worst-case loss, maximum loss, coherent risk measure, scenario-based risk, +representation over simplex, MSC 91G70, JEL G32 +-/ + +@[expose] public section + +namespace MathFin + +open MeasureTheory + +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +/-- Worst-case loss: the most conservative coherent risk measure. -/ +noncomputable def worstCase (L : ι → ℝ) : ℝ := + Finset.univ.sup' Finset.univ_nonempty L + +/-- Each `Lᵢ` lower-bounds the worst-case loss `worstCase L`. -/ +lemma le_worstCase (L : ι → ℝ) (i : ι) : L i ≤ worstCase L := + Finset.le_sup' L (Finset.mem_univ i) + +/-- Any uniform upper bound on the `Lᵢ` bounds `worstCase L` above. -/ +lemma worstCase_le {L : ι → ℝ} {a : ℝ} (h : ∀ i, L i ≤ a) : worstCase L ≤ a := + Finset.sup'_le Finset.univ_nonempty L fun i _ ↦ h i + +/-- Worst-case loss satisfies the four ADEH coherent-risk axioms for any measure on the states +that charges every state: the maximum does not see the weights, only which states are possible. -/ +lemma worstCase_isCoherent [MeasurableSpace ι] {P : Measure ι} + (hP : ∀ i, P {i} ≠ 0) : IsCoherentRiskMeasure P worstCase where + mono X Y _ _ hXY := + worstCase_le fun i ↦ ((ae_iff_forall_of_singleton_ne_zero hP).1 hXY i).trans + (le_worstCase Y i) + add_const X _ m := by + refine le_antisymm (worstCase_le fun i ↦ ?_) ?_ + · have := le_worstCase X i + change X i + m ≤ worstCase X + m + linarith + obtain ⟨i, -, hi⟩ := Finset.exists_mem_eq_sup' Finset.univ_nonempty X + have hwx : worstCase X = X i := hi + rw [hwx] + exact le_worstCase (fun i ↦ X i + m) i + const_mul X _ c hc := by + refine le_antisymm (worstCase_le fun i ↦ mul_le_mul_of_nonneg_left (le_worstCase X i) hc) ?_ + obtain ⟨i, -, hi⟩ := Finset.exists_mem_eq_sup' Finset.univ_nonempty X + have hwx : worstCase X = X i := hi + rw [hwx] + exact le_worstCase (fun i ↦ c * X i) i + add_le X Y _ _ := + worstCase_le fun i ↦ add_le_add (le_worstCase X i) (le_worstCase Y i) + +/-- The representing set of worst-case loss is the entire probability simplex: the weight vectors +of the points of `Convexity.StdSimplex ℝ ι`. -/ +lemma representingSet_worstCase : + representingSet (worstCase (ι := ι)) + = Set.range fun w : Convexity.StdSimplex ℝ ι ↦ ⇑w.weights := by + rw [Convexity.StdSimplex.range_toFun_comp_weights] + ext q + refine ⟨fun ⟨hnn, hsum, _⟩ ↦ ⟨Set.mem_iInter.2 hnn, hsum⟩, + fun ⟨hnn, hsum⟩ ↦ ⟨Set.mem_iInter.1 hnn, hsum, fun Z hZ ↦ ?_⟩⟩ + exact Finset.sum_nonpos fun i _ ↦ + mul_nonpos_of_nonneg_of_nonpos (Set.mem_iInter.1 hnn i) ((le_worstCase Z i).trans hZ) + +/-- **Worst-case loss is the supremum of expected loss over the entire probability simplex** — +the concrete instance of the ADEH representation. -/ +theorem worstCase_isLUB (L : ι → ℝ) : + IsLUB (Set.range fun w : Convexity.StdSimplex ℝ ι ↦ ∑ i, w.weights i * L i) (worstCase L) := by + let : MeasurableSpace ι := ⊤ + have : MeasurableSingletonClass ι := ⟨fun _ ↦ trivial⟩ + have h := coherentRisk_isLUB (worstCase_isCoherent (P := Measure.count) fun i ↦ by simp) L + rwa [representingSet_worstCase, ← Set.range_comp] at h + +end MathFin diff --git a/LeanPool/projects/formal-mathfin.yaml b/LeanPool/projects/formal-mathfin.yaml new file mode 100644 index 0000000000..192271a934 --- /dev/null +++ b/LeanPool/projects/formal-mathfin.yaml @@ -0,0 +1,79 @@ +slug: formal-mathfin +title: Pricing measures, market models and coherent risk +summary: >- + A common market and contract framework for finite-state asset pricing, + binomial pricing, fixed-maturity call price realization, and coherent risk. + The library develops filtered probability and martingale tools, a contract + language with measurable payoffs, and pricing and risk results for several + model families. +branch: mathematical finance and probability +entry_module: LeanPool.MathFin +authors: +- Raphael Coelho +- Robert Martin +- Yang Ye +- Alfredo Garcia +- Aleksey Salkutsan +source: + title: A Formally Verified Library of Mathematical Finance in Lean 4 + authors: + - Raphael Coelho + arxiv: '2606.01356' + url: https://github.com/formal-applied-math/formal-mathfin/tree/55e29a93e75f10b40f61f45c78a6058b2938045f + github_repo: formal-applied-math/formal-mathfin + commit: 55e29a93e75f10b40f61f45c78a6058b2938045f + announcement_url: https://github.com/formal-applied-math/formal-mathfin/releases/tag/v2.0.0 + announcement_date: '2026-11-11T23:35:05Z' +license: Apache-2.0 +status: verified +provenance: mix +provenance_evidence: >- + The upstream formalization.yaml documents human proof authoring with Claude + Code assistance, agent-authored contributions, and manually authored proofs. +main_declarations: +- MathFin.Market.noArbitrage_iff_exists_isPricingMeasure_of_finite +- MathFin.Contracts.Binomial.price_pay_eq_binomialPrice_of_isPricingMeasure +- MathFin.exists_market_of_isNormalizedCallPrice +- MathFin.Rates.price_pay_vasicekMarket +- MathFin.coherentRisk_isLUB +main_results: +- declaration: MathFin.Market.noArbitrage_iff_exists_isPricingMeasure_of_finite + informal: >- + On a nonempty finite sample space with measurable singletons and a finite + reference measure that charges every state, absence of arbitrage for one + asset on a finite trading grid is equivalent to the existence of a pricing + measure for the sampled deflated prices. +- declaration: MathFin.Contracts.Binomial.price_pay_eq_binomialPrice_of_isPricingMeasure + informal: >- + In the binomial model with positive initial spot and time step, + no-arbitrage parameters and maturity on the trading grid, every pricing + measure gives the binomial price to a single payment at maturity whose + contract-language payoff depends only on terminal spot on every scenario. +- declaration: MathFin.exists_market_of_isNormalizedCallPrice + informal: >- + Each normalized call price function is realized at maturity one in a + market with unit numeraire and a nonnegative terminal asset whose delivery + price is one. Its pricing measure reproduces the call price at every + positive strike. +- declaration: MathFin.Rates.price_pay_vasicekMarket + informal: >- + In the Vasicek market with measurable Brownian coordinates and a positive + mean-reversion coefficient, the stochastic bank-account numeraire is + built from the Wiener-integral representation of the integrated rate. + The reference probability measure gives the affine bond price for a unit + payment at maturity. +- declaration: MathFin.coherentRisk_isLUB + informal: >- + On a finite state space with measurable singletons and a finite reference + measure, a coherent risk measure of losses equals the least upper bound + of expected loss over the probability vectors that assign nonpositive + expectation to every acceptable loss. +tags: +- mathematical-finance +- discrete-time-martingales +- asset-pricing +- risk-measures +msc: +- 91G20 +- 91G70 +- 60G44