Avalanche 是一种开放的区块链协议,它旨在实现高度可扩展、高性能和去中心化的应用程序。Avalanche 具有自己的公链,也被称为 Avalanche 公链。
import quandl
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
quandl.ApiConfig.api_key='INSERT YOUR API KEY HERE'
selected=['CNP','F','WMT','GE','TSLA']
data=quandl.get_table('WIKI/PRICES',ticker=selected,
qopts={'columns':['date','ticker','adj_close']},
date={'gte':'2011-1-1','lte':'2021-07-31'},paginate=True)
clean=data.set_index('date')
table=clean.pivot(columns='ticker')
returns_daily=table.pct_change()
returns_annual=returns_daily.mean()250
cov_daily=returns_daily.cov()
cov_annual=cov_daily250
port_returns=[]
port_volatility=[]
sharpe_ratio=[]
stock_weights=[]
num_assets=len(selected)
num_portfolios=90000
np.random.seed(101)
for single_portfolio in range(num_portfolios):
weights=np.random.random(num_assets)
weights/=np.sum(weights)
returns=np.dot(weights,returns_annual)
volatility=np.sqrt(np.dot(weights.T,np.dot(cov_annual,weights)))
sharpe=returns/volatility
sharpe_ratio.append(sharpe)
port_returns.append(returns)
port_volatility.append(volatility)
stock_weights.append(weights)