0

I am trying to build my own portfolio report that tracks the different stocks that I have been bought at different dates in the past - below is the code, but I get the following error: ValueError: time data 'AMZN_start' does not match format '%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)
r-beginners
  • 31,170
  • 3
  • 14
  • 32
jdawg
  • 11
  • 2
  • Can anybody help, please? – jdawg Nov 02 '20 at 12:03
  • `eval(ticker+'_start')`If you don't write it this way, the string retrieved from the list won't become variable rain. Also, the column to delete is wrong, so it causes an error. – r-beginners Nov 02 '20 at 12:59
  • How would you best do it then? Basically, I am trying to build my own portfolio report, where I need the start date of the different stocks and then to calculate the cumulative return for each asset – jdawg Nov 04 '20 at 06:55
  • I think it's easy to create a dictionary of stock names and acquisition start dates and store them in a loop process. Example dictionary `ticker_dict={'APPL':'2016-08-26', ...) ` – r-beginners Nov 04 '20 at 07:05
  • Could you please provide an example, my code keeps crashing... – jdawg Nov 09 '20 at 13:46
  • I have edited your question code. Since the question is closed, I think it's better to ask a new question as this kind of exchange is impossible. – r-beginners Nov 09 '20 at 14:09

0 Answers0