Skip to content

Instantly share code, notes, and snippets.

View kavehtehrani's full-sized avatar
🦀

Kaveh kavehtehrani

🦀
View GitHub Profile
@kavehtehrani
kavehtehrani / var_cvar_example.py
Last active December 4, 2025 04:20
var vs cvar - coherence of risk measures
import numpy as np
import pandas as pd
A = np.array([1.0] * 18 + [-100.0, 0.0, -30.0])
B = np.array([1.0] * 18 + [0.0, -100.0, -30.0])
P = 0.5 * A + 0.5 * B
def var(r, alpha=0.90):
return np.percentile(r, 100 * (1 - alpha))