Coverage for src / cvx / risk / cvar / __init__.py: 100%
1 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-13 06:46 +0000
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-13 06:46 +0000
1"""Conditional Value at Risk (CVaR) models for portfolio optimization.
3This subpackage provides the CVar class for CVaR-based risk estimation.
4CVaR, also known as Expected Shortfall, measures the expected loss in the
5tail of the return distribution.
7Example:
8 >>> import numpy as np
9 >>> from cvx.risk.cvar import CVar
10 >>> # Create CVaR model
11 >>> model = CVar(alpha=0.95, n=100, m=5)
12 >>> # Update with historical returns
13 >>> np.random.seed(42)
14 >>> returns = np.random.randn(100, 5)
15 >>> model.update(
16 ... returns=returns,
17 ... lower_assets=np.zeros(5),
18 ... upper_assets=np.ones(5)
19 ... )
20 >>> w = np.ones(5) / 5
21 >>> cvar = model.estimate(w)
22 >>> isinstance(cvar, float)
23 True
25"""
27# Copyright 2023 Stanford University Convex Optimization Group
28#
29# Licensed under the Apache License, Version 2.0 (the "License");
30# you may not use this file except in compliance with the License.
31# You may obtain a copy of the License at
32#
33# http://www.apache.org/licenses/LICENSE-2.0
34#
35# Unless required by applicable law or agreed to in writing, software
36# distributed under the License is distributed on an "AS IS" BASIS,
37# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38# See the License for the specific language governing permissions and
39# limitations under the License.
40from .cvar import CVar as CVar