我正在尝试建立自己的投资组合报告,以跟踪我在过去不同日期购买的不同股票 - 以下是代码,但我收到以下错误:ValueError:时间数据'AMZN_start'与格式不匹配' %Y-%m-%d'
import pandas as pd
import yfinance as yf
import datetime as dt
import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib import style
TempDF = pd.DataFrame() # 2020-11-09
# getting stock ticker
tickers = ['AMZN','NVDA']
starts = ['2016-08-26','2020-03-24'] # update 2020-11-9
end = dt.datetime.today()
# Ticker to download update:2020-11-9
for ticker,start in zip(tickers, starts):
data = yf.download(ticker, start, end, interval="1d")
TempDF = TempDF.append(data) # update 2020-11-09
# Creating DF and adding metrics
#TempDF = pd.DataFrame(data)
TempDF.drop(TempDF.columns[[0,1,2,3,5]], axis=1, inplace=True)
TempDF['DailyReturn'] = TempDF['Adj Close'].pct_change()
TempDF.fillna(method='bfill', inplace=True)