This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def selection_to_picks(num_assets, selection): | |
| purchase = [] | |
| for i in range(num_assets): | |
| if selection[i] == 1: | |
| purchase.append(stock_list[i]) | |
| return purchase |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def index_to_selection(i, num_assets): | |
| s = "{0:b}".format(i).rjust(num_assets) | |
| x = np.array([1 if s[i]=='1' else 0 for i in reversed(range(num_assets))]) | |
| return x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Retrieve Hamiltonian | |
| qubitOp, offset = portfolio.get_operator(mu, sigma, risk_factor, budget, penalty) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sns.pairplot(df) | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Correlation Matrix | |
| corr = df.corr() | |
| f, ax = plt.subplots(figsize=(10, 8)) | |
| sns.heatmap(corr, mask=np.zeros_like(corr, dtype=np.bool), annot=True, square=True, ax=ax, xticklabels=stock_list, yticklabels=stock_list) | |
| plt.title("Correlation between Equities") | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Covariance Matrix | |
| sigma = data.get_period_return_covariance_matrix() | |
| f, ax = plt.subplots(figsize=(10, 8)) | |
| sns.heatmap(sigma, mask=np.zeros_like(sigma, dtype=np.bool), annot=True, square=True, ax=ax, xticklabels=stock_list, yticklabels=stock_list) | |
| plt.title("Covariance between Equities") | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Mean value of each assets | |
| mu = data.get_period_return_mean_vector() | |
| sns.barplot(y=mu, x = stock_list) | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Closing Price History | |
| fig, ax = plt.subplots(figsize=(15, 8)) | |
| ax.plot(df) | |
| plt.title('Close Price History') | |
| plt.xlabel('Date',fontsize =20) | |
| plt.ylabel('Price in USD',fontsize = 20) | |
| ax.legend(df.columns.values) | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| df.describe() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data = EikonDataProvider(stocks_list = stock_list, start_date=start_date, end_date=end_date) | |
| data.run() | |
| # Top 5 rows of data | |
| df = data.stock_data | |
| df.head() |