generated from cvxgrp/simulator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
53 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Bounds""" | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
|
||
import cvxpy as cp | ||
import numpy as np | ||
|
||
from cvx.risk import Model | ||
|
||
|
||
@dataclass | ||
class Bounds(Model): | ||
m: int = 0 | ||
|
||
def estimate(self, weights, **kwargs): | ||
"""No estimation for bounds""" | ||
raise NotImplementedError("No estimation for bounds") | ||
|
||
def __post_init__(self): | ||
self.parameter["lower"] = cp.Parameter( | ||
shape=self.m, | ||
name="lower bound", | ||
value=np.zeros(self.m), | ||
) | ||
self.parameter["upper"] = cp.Parameter( | ||
shape=self.m, | ||
name="upper bound", | ||
value=np.ones(self.m), | ||
) | ||
|
||
def update(self, **kwargs): | ||
# lower = kwargs.get("lower", np.zeros(self.m)) | ||
lower = kwargs["lower"] | ||
self.parameter["lower"].value = np.zeros(self.m) | ||
self.parameter["lower"].value[: len(lower)] = lower | ||
|
||
upper = kwargs["upper"] # .get("upper", np.ones(self.m)) | ||
self.parameter["upper"].value = np.zeros(self.m) | ||
self.parameter["upper"].value[ | ||
: len(upper) | ||
] = upper # kwargs.get("upper", np.ones(m)) | ||
|
||
def constraints(self, weights, **kwargs): | ||
return [ | ||
weights >= self.parameter["lower"], | ||
weights <= self.parameter["upper"], | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters