I am looking to run weight portfolio simulations, but I would like to fix the weight of one asset and set lower/upper bound limits for the remaining assets.
I have only been using Python for a couple of months.
Below is the standard code I found to run simulated asset weights. It works great; but I want to see how I could add weight constraints. Namely, fixing the weight of one asset and setting lower/upper bounds on the rest.
The data is uploaded via excel in the usual way.
Code below:
df=pd.read_excel('data.xlsx', sheet_name='data1')
dRtns = df.pct_change()
number_of_portfolios=10000
number_of_assets=len(df.columns)
portfolio_returns = []
portfolio_risk = []
sharpe_ratio_port = []
portfolio_weights = []
for portfolio in range (number_of_portfolios):
weights = np.random.random_sample(number_of_assets)
weights=4*weights/np.sum(weights)
annualise_return=np.sum((dRtns.mean()*weights)*252)
portfolio_returns.append(annualise_return)
matrix_cov_port=(dRtns.cov())*252
portfolio_variance=np.dot(weights.T,np.dot(matrix_cov_port,weights))
portfolio_std=np.sqrt(portfolio_variance)
portfolio_risk.append(portfolio_std)
sharpe_ratio=((annualise_return)/portfolio_std)
sharpe_ratio_port.append(sharpe_ratio)
portfolio_weights.append(weights)
portfolio_risk=np.array(portfolio_risk)
portfolio_returns=np.array(portfolio_returns)
sharpe_ratio_port=np.array(sharpe_ratio_port)
Can anyone help?
Thank you, H