2 回答

TA貢獻1836條經(jīng)驗 獲得超13個贊
很可能不是圖形或代碼搞砸了 - 而是您的輸入。嘗試使用資產(chǎn)。可能是您包含在優(yōu)化算法中的資產(chǎn)高度正相關(guān) - 導(dǎo)致多樣化的影響可以忽略不計。反過來,這會影響您的有效邊界的形狀。
編輯:
如果這不是問題的根源。也許使用以下代碼行重試該程序:
def monteCarlo_Simulation(returns):
noa = len(tickers)
random_returns = []
random_volatility = []
for i in range (10000):
weights = np.random.random(noa)
weights = weights / np.sum(weights)
random_returns.append(np.sum(returns.mean()*weights)*252)
random_volatility.append(np.sqrt(np.dot(weights.T, np.dot(returns.cov()*252, weights))))
random_returns = np.array(random_returns)
random_volatility = np.array(random_volatility)
fig_random = plt.figure(figsize = [6,4])
plt.scatter(random_volatility, random_returns,
c= random_returns / random_volatility, marker = '.')
plt.grid(True)
plt.xlabel('Expected volatility')
plt.ylabel('Expected return')
plt.colorbar(label='Sharpe ratio')
plt.title('Mean Variance Analysis Plot')
plt.show()

TA貢獻1943條經(jīng)驗 獲得超7個贊
我遇到了類似的問題,我通過查看 NaN 值解決了這個問題,有些公司的 IPO 很晚,有些是在同一年。因此,您需要收集與您的股票投資組合中最新 IPO 相同的數(shù)據(jù)?;蛘咛蕹谀鷻z索數(shù)據(jù)之日之前未 IPO 的所有股票。
添加回答
舉報