11import Probability.Probability.Basic
2+ import Mathlib.Data.EReal.Basic
23
34namespace Risk
45
@@ -8,6 +9,20 @@ variable {n : ℕ}
89
910def cdf (P : Findist n) (X : FinRV n ℚ) (t : ℚ) : ℚ := ℙ[X ≤ᵣ t // P]
1011
12+ theorem cdf_monotone (P : Findist n) (X : FinRV n ℚ) (t1 t2 : ℚ)
13+ (ht : t1 ≤ t2) : cdf P X t1 ≤ cdf P X t2 := by
14+ simp [cdf]
15+ apply exp_monotone
16+ intro ω
17+ by_cases h1 : X ω ≤ t1
18+ · have h2 : X ω ≤ t2 := le_trans h1 ht
19+ simp [FinRV.leq, 𝕀, indicator, h1, h2]
20+ · simp [𝕀, indicator, FinRV.leq, h1]
21+ by_cases h2 : X ω ≤ t2
22+ · simp [h2]
23+ · simp [h2] ---these lines seem really unnecessary but idk how to fix it
24+
25+
1126/-- Finite set of values taken by a random variable X : Fin n → ℚ. -/
1227def rangeOfRV (X : FinRV n ℚ) : Finset ℚ := Finset.univ.image X
1328
@@ -18,50 +33,82 @@ def VaR (P : Findist n) (X : FinRV n ℚ) (α : ℚ) : ℚ :=
1833 if h : S.Nonempty then
1934 S.min' h
2035 else
21- 0
36+ 0 --this is illegal i know -- Keith can fix it :)
2237
23- notation "VaR[" α "," X "//" P "]" => VaR P X α
24- -- TODO (Marek): What do you think about :
25- -- notation "VaR[ X "//" P "," α "]" => VaR P X α
26- -- I think that the α goes better with the probability that the variable
38+ notation "VaR[" X "//" P ", " α "]" => VaR P X α
39+
40+ def VaR2 (P : Findist n) (X : FinRV n ℚ) (α : ℚ) : EReal :=
41+ let S : Finset ℚ := (rangeOfRV X).filter (fun t => cdf P X t ≥ α)
42+ if h : S.Nonempty then
43+ (S.min' h : ℝ)
44+ else
45+ ⊤ --Idk if I fixed it and I also saw that VaR_R does this much more nicely.
2746
2847theorem VaR_monotone (P : Findist n) (X Y : FinRV n ℚ) (α : ℚ)
2948 (hXY : ∀ ω, X ω ≤ Y ω) : VaR P X α ≤ VaR P Y α := by
30- have hcdf : ∀ t : ℚ, cdf P Y t ≤ cdf P X t := by
31- intro t
32- simp [cdf]
33- apply exp_monotone
34- intro ω
35- have h1 : Y ω ≤ t → X ω ≤ t := by
36- intro hY
37- exact le_trans (hXY ω) hY
38- by_cases hY : Y ω ≤ t
39- · have hX : X ω ≤ t := by exact h1 hY
40- simp [𝕀, indicator, FinRV.leq, hY, hX]
41- · simp [𝕀, indicator, FinRV.leq, hY]
42- by_cases hx2 : X ω ≤ t
43- · simp [hx2]
44- · simp [hx2] ---these lines seem really unnecessary but idk how to fix it
45-
49+ let Sx : Set ℚ := { t : ℚ | cdf P X t ≥ α }
50+ let Sy : Set ℚ := { t : ℚ | cdf P Y t ≥ α }
51+ have hx : VaR P X α = Sx.min := rfl
52+ have hy : VaR_R P Y α = sInf Sy := rfl
53+
54+ --(Emily) I am now thinking of just trying to keep it in Q
55+ --so I wouln't use anything between these lines!
56+ ------------------- defined over the reals to prove monotonicity ---------------------------
57+ noncomputable def cdfR (P : Findist n) (X : FinRV n ℝ) (t : ℝ) : ℝ := ℙ[X ≤ᵣ t // P]
58+
59+ theorem cdfR_monotone (P : Findist n) (X : FinRV n ℝ) (t1 t2 : ℝ)
60+ (ht : t1 ≤ t2) : cdfR P X t1 ≤ cdfR P X t2 := by
61+ simp [cdfR]
62+ apply exp_monotone
63+ intro ω
64+ by_cases h1 : X ω ≤ t1
65+ · have h2 : X ω ≤ t2 := le_trans h1 ht
66+ simp [FinRV.leq, 𝕀, indicator, h1, h2]
67+ · simp [𝕀, indicator, FinRV.leq, h1]
68+ by_cases h2 : X ω ≤ t2
69+ · simp [h2]
70+ · simp [h2]
71+
72+ /-- Value-at-Risk of X at level α: VaR_α(X) = inf {t:ℝ | P[X ≤ t] ≥ α } -/
73+ noncomputable def VaR_R (P : Findist n) (X : FinRV n ℝ) (α : ℝ) : ℝ :=
74+ sInf { t : ℝ | cdfR P X t ≥ α }
75+
76+ theorem VaR_R_monotone (P : Findist n) (X Y : FinRV n ℝ) (α : ℝ)
77+ (hXY : ∀ ω, X ω ≤ Y ω) : VaR_R P X α ≤ VaR_R P Y α := by
78+ let Sx : Set ℝ := { t : ℝ | cdfR P X t ≥ α }
79+ let Sy : Set ℝ := { t : ℝ | cdfR P Y t ≥ α }
80+ have hx : VaR_R P X α = sInf Sx := rfl
81+ have hy : VaR_R P Y α = sInf Sy := rfl
82+ have hsubset : Sy ⊆ Sx := by
83+ unfold Sy Sx
84+ intro t ht
85+ have h_cdf : ∀ t, cdfR P X t ≥ cdfR P Y t := by
86+ intro t
87+
88+ sorry
89+ sorry
90+ rw [hx, hy]
4691 sorry
4792
93+ -------------------------------------------------------------------
94+
4895theorem VaR_translation_invariant (P : Findist n) (X : FinRV n ℚ) (α c : ℚ) :
49- VaR P (fun ω => X ω + c) α = VaR P X α + c := sorry
96+ VaR_Q P (fun ω => X ω + c) α = VaR_Q P X α + c := sorry
5097
5198theorem VaR_positive_homog (P : Findist n) (X : FinRV n ℚ) (α c : ℚ)
52- (hc : c > 0 ) : VaR P (fun ω => c * X ω) α = c * VaR P X α := sorry
99+ (hc : c > 0 ) : VaR_Q P (fun ω => c * X ω) α = c * VaR_Q P X α := sorry
53100
54101
55102/-- Tail indicator: 1 if X(ω) > t, else 0. -/
56103def tailInd (X : FinRV n ℚ) (t : ℚ) : FinRV n ℚ :=
57104 fun ω => if X ω > t then 1 else 0
58105
59106/-- Conditional Value-at-Risk (CVaR) of X at level α under P.
60- CVaR = E[X * I[X > VaR] ] / P[X > VaR]
107+ CVaR_α(X) = E[X * I[X > VaR] ] / P[X > VaR]
61108If the tail probability is zero, CVaR is defined to be 0.
62109-/
63110def CVaR (P : Findist n) (X : FinRV n ℚ) (α : ℚ) : ℚ :=
64- let v := VaR P X α
111+ let v := VaR_Q P X α
65112 let B : FinRV n ℚ := tailInd X v
66113 let num := 𝔼[X * B // P]
67114 let den := ℙ[X >ᵣ v // P]
@@ -70,11 +117,11 @@ def CVaR (P : Findist n) (X : FinRV n ℚ) (α : ℚ) : ℚ :=
70117 else
71118 num / den
72119
73- -- NOTE (Marek): The CVaR, as defined above is not convex/concave.
120+ -- NOTE (Marek): The CVaR, as defined above is not convex/concave.
74121-- See Page 14 at https://www.cs.unh.edu/~mpetrik/pub/tutorials/risk2/dlrl2023.pdf
75- -- NOTE (Marek): The CVaR above is defined for costs and not rewards
122+ -- NOTE (Marek): The CVaR above is defined for costs and not rewards
76123
77- notation "CVaR[" α "," X "//" P "]" => CVaR P X α
124+ notation "CVaR[" X "//" P ", " α "]" => CVaR P X α
78125
79126--TODO: prove...
80127-- monotonicity: (∀ ω, X ω ≤ Y ω) → CVaR[α, X // P] ≤ CVaR[α, Y // P]
0 commit comments