Opvious Python SDK
Project description
Opvious Python SDK
An optimization SDK for solving linear, mixed-integer, and quadratic models
import opvious
client = opvious.Client.from_environment()
# Solve a portfolio selection optimization model
response = await client.run_solve(
specification=opvious.InlineSpecification([
r"""
We find an allocation of assets which minimizes risk while satisfying
a minimum expected return:
+ A collection of assets: $\S^d_{asset}: A$
+ Covariances: $\S^p_{covariance}: c \in \mathbb{R}^{A \times A}$
+ Expected return: $\S^p_{expectedReturn}: m \in \mathbb{R}^A$
+ Minimum desired return: $\S^p_{desiredReturn}: r \in \mathbb{R}$
The only output is the allocation per asset
$\S^v_{allocation}: \alpha \in [0,1]^A$ chosen to minimize risk:
$\S^o_{risk}: \min \sum_{a, b \in A} c_{a,b} \alpha_a \alpha_b$.
Subject to the following constraints:
+ $\S^c_{atLeastMinimumReturn}: \sum_{a \in A} m_a \alpha_a \geq r$
+ $\S^c_{totalAllocation}: \sum_{a \in A} \alpha_a = 1$
"""
]),
parameters={
"covariance": {
("AAPL", "AAPL"): 0.08,
# ...
},
"expectedReturn": {
"AAPL": 0.07,
# ..
},
"desiredReturn": 0.05,
},
)
print(f"Problem was {response.status}.") # OPTIMAL, INFEASIBLE, ...
if response.outputs: # Present if the problem was feasible
print(response.outputs.variable("allocation"))
Refer to https://opvious.readthedocs.io for the full documentation or take a look at these notebooks to see the SDK in action.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
opvious-0.12.0rc1.tar.gz
(44.8 kB
view hashes)
Built Distribution
Close
Hashes for opvious-0.12.0rc1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7de793cb6494286b8afdf0775771ae6566c90fe4bc4f578859614cf358b090f0 |
|
MD5 | 7996d0d57097e0424cd9d81388e2f433 |
|
BLAKE2b-256 | a07301a542ff47833504ef8e3a121dbe4c61a8b815e77109628e16a2ca261b4c |