Skip to content

Instantly share code, notes, and snippets.

View lf2foce's full-sized avatar

Anh Bui lf2foce

  • Hanoi
View GitHub Profile
data_index = data_index[(data_index['Ticker'].isin(stock_list)) & (data_index['Date'] >= '2020-04-03') ]
data_index_pivot = data_index.pivot(columns='Ticker', index='Date', values='Adj_Close')
#calculate the log returns
log_ret = np.log(data_index_pivot/data_index_pivot.shift(1))
#covariance matrix.
cov_matrix = log_ret.cov() * 252
print(cov_matrix)
# Simulating 5000 portfolios
num_port = 5000
recent_data = data_index_pivot.copy()
corr_matrix = recent_data.corr()
f, ax = plt.subplots(figsize =(18, 15))
sns.heatmap(corr_matrix, ax = ax, cmap ="coolwarm", linewidths = 0.1, square=True, vmin=-1, vmax=1, center= 0)
@lf2foce
lf2foce / git_cheat-sheet.md
Created November 8, 2016 21:53 — forked from davfre/git_cheat-sheet.md
git commandline cheat-sheet