This file contains 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
import yfinance as yf | |
import pandas as pd | |
import numpy as np | |
from scipy.stats import norm | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
cryptocurrency = ['BTC-USD', 'ETH-USD', 'USDT-USD', 'XRP-USD', 'LTC-USD', 'BCH-USD', 'ADA-USD', 'BNB-USD', 'LINK-USD'] | |
data= yf.download(cryptocurrency, start="2018-01-01", end="2020-12-31")['Close'] |
This file contains 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
fig, axs = plt.subplots(5, 2, figsize=(15,15)) | |
axs[0, 0].plot(data.index, data['BTC-USD'], 'tab:blue' ) | |
axs[0, 0].set_title('BTC') | |
axs[0, 1].plot(data.index, data['ETH-USD'], 'tab:orange') | |
axs[0, 1].set_title('ETH') | |
axs[1, 0].plot(data.index, data['USDT-USD'], 'tab:green') | |
axs[1, 0].set_title('USDT') | |
axs[1, 1].plot(data.index, data['XRP-USD'], 'tab:red') | |
axs[1, 1].set_title('XRP') |
This file contains 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
return_data = data.pct_change() | |
return_data.head() |
This file contains 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
var_matrix = return_data.cov() | |
var_matrix |
This file contains 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
port_return = [] | |
# Initialize an empty list for storing the portfolio volatility | |
port_volatility = [] | |
# Initialize an empty list for storing the portfolio weights | |
port_weights = [] | |
num_assets = len(data.columns) | |
num_portfolio = 1000000 |
This file contains 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
rf = 0.02 | |
min_vol_port = portfolios_V1.iloc[portfolios_V1['Volatility'].idxmin()] | |
optimal_risky_port = portfolios_V1.iloc[((portfolios_V1['Returns']-rf)/portfolios_V1['Volatility']).idxmax()] | |
max_ret_port = portfolios_V1.iloc[portfolios_V1['Returns'].idxmax()] | |
weights_min_vol = np.array(min_vol_port[2:]) | |
#weights in a portfolio with max Sharpe Ratio | |
weights_opt_sr = np.array(optimal_risky_port[2:]) | |
#weights in a portfolio with max Returns |
This file contains 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_weights = pd.DataFrame(columns=portfolios_V1.columns) | |
df_weights = df_weights.append(min_vol_port.rename("Minimum Volatility").to_frame().T) | |
df_weights = df_weights.append(max_ret_port.rename("Maximum Returns").to_frame().T) | |
df_weights = df_weights.append(optimal_risky_port.rename("Maximum Sharpe Ratio").to_frame().T) |
This file contains 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
array_returns = np.asarray(return_data.dropna()) | |
array_cov = np.asarray(var_matrix) | |
mean_returns = np.mean(array_returns, axis = 0) | |
portfolios_V1_div = portfolios_V1.copy() | |
div_ratio = [] | |
for i in range(portfolios_V1.shape[0]): |
This file contains 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_weights |
This file contains 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_weights_circle = df_weights.drop(['Returns', 'Volatility'], axis = 1) | |
df_weights_circle |
OlderNewer