利用python求最小方差组合
import numpy as np
import scipy as sp
import pandas as pd
import scipy.optimize as opt #最优化的module
names=("IBM","WMT","C")
rf=0.0003 #输入的参数,无风险利率
#从雅虎财经直接下载15年至20年的股票数据
def get_logret(name): x=pd.read_csv('https://query1.finance.yahoo.com/v7/finance/download/'+name+'?period1=1420070400&period2=1577836800&interval=1d&events=history')
logret = pd.DataFrame(np.log((x["Adj Close"][:-1].values/x["Adj Close"][1:].values)),index=x<