Opvious Python SDK
Project description
Opvious Python SDK
![Pypi badge](https://pypi-camo.freetls.fastly.net/dc506e98b1d565d7461b38a4af381a403b26c1de/68747470733a2f2f62616467652e667572792e696f2f70792f6f7076696f75732e737667)
This package provides a lightweight SDK for solving optimization models with the Opvious API. Its main features are:
- Seamless data import/export via native support for
pandas
- Powerful built-in debugging capabilities: automatic infeasibility relaxation, variable pinning, and more
- Non-blocking APIs for performant parallel calls
Quickstart
First, install this package and have an API access token handy (these can be generated here).
pip install opvious[aio] # aio is recommended for improved performance
With these steps out of the way, you are ready to optimize!
import opvious
client = opvious.Client.from_token(TOKEN)
# Solve a simple 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"))
The full API reference is available here: https://opvious.readthedocs.io
Next steps
This SDK is focused on solving optimization models. For convenient access to the rest of Opvious' functionality, consider using the TypeScript SDK and CLI.
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.11.5.tar.gz
(39.0 kB
view hashes)
Built Distribution
opvious-0.11.5-py3-none-any.whl
(27.7 kB
view hashes)