Replies: 4 comments
-
Hello, |
Beta Was this translation helpful? Give feedback.
-
Yes, I know it's non-convex. I just wonder if there exists a transformation which could reformulate it to a convex problem. |
Beta Was this translation helpful? Give feedback.
-
Not to my knowledge. Also, even if such constraints may seem too restrictive, in practice, they tend to be beneficial due to their regularization effect (reducing overfitting and out-of-sample stability, especially in long-short portfolios). |
Beta Was this translation helpful? Give feedback.
-
Thanks. I do not use bonds. Only stocks, the universe is 1000 stocks. I want to build a long-short market-neutral portfolio with sum(abs(w))=1. Could we use group constraints to avoid this problem? |
Beta Was this translation helpful? Give feedback.
-
when maximizing sharpe ratio, I want sum(w)=0 and sum(abs(x))=1, how to do it?
I tried the follollowing code, but get error:
raise DCPError(
cvxpy.error.DCPError: Problem does not follow DCP rules. Specifically:
The following constraints are not DCP:
0.5 <= Sum(maximum(var1, 0.0), None, False) , because the following subexpressions are not:
|-- 0.5 <= Sum(maximum(var1, 0.0), None, False)
0.5 <= Sum(-minimum(var1, 0.0), None, False) , because the following subexpressions are not:
|-- 0.5 <= Sum(-minimum(var1, 0.0), None, False)
###########################################################
I tried the following code:
prices = load_sp500_dataset()
X = prices_to_returns(prices)
X_train, X_test = train_test_split(X, test_size=0.33, shuffle=False)
def custom_constraints(w):
return [cp.sum(cp.pos(w))>=0.5,cp.sum(cp.neg(w))>=0.5]
model = MeanRisk(
risk_measure=RiskMeasure.VARIANCE,
objective_function=ObjectiveFunction.MAXIMIZE_RATIO,
portfolio_params=dict(name="Max Sharpe"),
budget = 0, # market neutral portfolio.
min_weights= -1,
max_short = 0.5,
max_long= 0.5,
add_constraints=custom_constraints
)
model.fit(X_train)
print(model.weights_)
print('sum weight',sum(model.weights_),'sumabs',sum([abs(w) for w in model.weights_]))
Beta Was this translation helpful? Give feedback.
All reactions