Skip to content

Commit

Permalink
Remove nonneg cash constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
phschiele committed Oct 25, 2023
1 parent 502b0e8 commit b5f1d69
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions experiments/taming.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import os
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -29,21 +28,11 @@ def unconstrained_markowitz(
cp.sum(w) + c == 1,
cp.norm2(chol.T @ w) <= inputs.risk_target,
]
if not long_only:
constraints.append(c == 0)

problem = cp.Problem(cp.Maximize(objective), constraints)
problem.solve(get_solver())
if problem.status in {cp.OPTIMAL, cp.OPTIMAL_INACCURATE}:
return w.value, c.value
else:
cash = inputs.cash
quantities = inputs.quantities
portfolio_value = cash + quantities @ inputs.prices.iloc[-1]
valuations = quantities * inputs.prices.iloc[-1]
w, c = valuations / portfolio_value, cash / portfolio_value
logging.warning(f"Problem status: {problem.status}, returning previous weights")
return w, c
assert problem.status in {cp.OPTIMAL, cp.OPTIMAL_INACCURATE}, problem.status
return w.value, c.value


def long_only_markowitz(inputs: OptimizationInput) -> np.ndarray:
Expand Down

0 comments on commit b5f1d69

Please sign in to comment.