Closed mthelee closed 2 years ago
I'm not too sure about the vectorbt
side, but your constraints seem to be linear so you should just be able to:
price = pd.DataFrame(price, columns=symbols)
avg_returns = expected_returns.mean_historical_return(price)
cov_mat = risk_models.CovarianceShrinkage(price).ledoit_wolf()
ef = EfficientFrontier(avg_returns, cov_mat, weight_bounds=(-1,1))
weights = ef.max_sharpe()
to get the weights in each loop.
Closing due to inactivity
For clarity sake, why is yf
called but not used, and vbt
is used instead?
Not sure if it answers your question. As its just part of my codes, and it's more on the vectorbt side, I am just using the feature
vbt.YFData.fetch(['TICKER']).get('Close')
here.
What are you trying to do?
Hi I have been using PyPortfolioOpt and Vectorbt for backtesting with portfolio optimization. However, I am confused in configuring the parameter for a long short strategy. For example, I would like to long the top 5 sharpe ratio and short the lowest 5.
After I set the weight_bounds=(-1,1), and I set the short ratio in the DiscreteAllocation(clean_weights, latest_prices, total_portfolio_value=25000, short_ratio = 0.5), now I am unsure how to deal with the constraint, the min_weight and max_weight.
Here is the full version of my code:
I have tried to look for information or resources on long short strategy but no luck on the internet. Greatly appreciate any help or expert view on my code.
What data are you using? I am using vbt.YFData.download(symbols, start=start_date, end=end_date) for the data.