Coverage for src / cvx / risk / sample / __init__.py: 100%

1 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-15 12:21 +0000

1"""Sample covariance risk models for portfolio optimization. 

2 

3This subpackage provides the SampleCovariance class for risk estimation 

4based on the sample covariance matrix. 

5 

6Example: 

7 >>> import cvxpy as cp 

8 >>> import numpy as np 

9 >>> from cvx.risk.sample import SampleCovariance 

10 >>> model = SampleCovariance(num=3) 

11 >>> model.update( 

12 ... cov=np.eye(3), 

13 ... lower_assets=np.zeros(3), 

14 ... upper_assets=np.ones(3) 

15 ... ) 

16 >>> weights = cp.Variable(3) 

17 >>> risk = model.estimate(weights) 

18 >>> isinstance(risk, cp.Expression) 

19 True 

20 

21Classes: 

22 SampleCovariance: Risk model based on sample covariance matrix 

23 

24""" 

25 

26# Copyright 2023 Stanford University Convex Optimization Group 

27# 

28# Licensed under the Apache License, Version 2.0 (the "License"); 

29# you may not use this file except in compliance with the License. 

30# You may obtain a copy of the License at 

31# 

32# http://www.apache.org/licenses/LICENSE-2.0 

33# 

34# Unless required by applicable law or agreed to in writing, software 

35# distributed under the License is distributed on an "AS IS" BASIS, 

36# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

37# See the License for the specific language governing permissions and 

38# limitations under the License. 

39from .sample import SampleCovariance as SampleCovariance # noqa: F401