import requests
import numpy as np
# Historical returns
returns = [0.10, 0.12, 0.08, 0.15]
# Covariance matrix
cov = [
[0.04, 0.01, 0.02, 0.015],
[0.01, 0.09, 0.015, 0.02],
[0.02, 0.015, 0.06, 0.01],
[0.015, 0.02, 0.01, 0.16]
]
response = requests.post(
"https://finceptbackend.share.zrok.io/quantlib/portfolio/mean-variance",
headers={"X-API-Key": API_KEY},
json={
"expected_returns": returns,
"covariance_matrix": cov,
"objective": "max_sharpe",
"risk_free_rate": 0.02
}
)
result = response.json()
print("Optimal Weights:", result['data']['weights'])
print("Sharpe Ratio:", result['data']['sharpe_ratio'])