I’m new to the forum so I’m not sure if this is the correct place to post this.
I am writing the code to the project on a local computer. I’m not sure what I’m doing wrong as my rates of return seem very off. Can anyone take a look and see what I might be doing wrong? At the moment I am trying to print the daily rate of returns for 4 different stocks.
Thanks in advance,
from utils import *
from pandas_datareader import wb
from datetime import datetime
import pandas_datareader.data as web
start = datetime(2021, 1, 30)
end = datetime(2021, 4, 29)
symbols = [‘AMD’, ‘GME’, ‘MSFT’, ‘TSLA’]
stock_data = pdr.get_data_tiingo(symbols, start, end, api_key=’#not my real api’)
stock_data[‘growth’] = stock_data[‘adjOpen’] - stock_data[‘adjOpen’].shift(1)
stock_data[‘daily_ror’] = stock_data[‘growth’]/stock_data[‘adjOpen’]
mean_daily_ror = stock_data.groupby(‘symbol’).daily_ror.mean()
print(stock_data[‘adjOpen’])
print(mean_daily_ror)
Here is the output of the program.
symbol date
AMD 2021-02-01 00:00:00+00:00 86.83
2021-02-02 00:00:00+00:00 88.49
2021-02-03 00:00:00+00:00 88.60
2021-02-04 00:00:00+00:00 88.22
2021-02-05 00:00:00+00:00 88.15
…
TSLA 2021-04-23 00:00:00+00:00 719.80
2021-04-26 00:00:00+00:00 741.00
2021-04-27 00:00:00+00:00 717.96
2021-04-28 00:00:00+00:00 696.41
2021-04-29 00:00:00+00:00 699.51
Name: adjOpen, Length: 248, dtype: float64
symbol
AMD -0.000682
GME -0.027184
MSFT 0.005284
TSLA 0.007625
Name: daily_ror, dtype: float64
The thing is, I’m sure most of you are aware that GME is up big time since the start of the year which is when my data starts. I don’t understand why my daily rate of return for GME is coming out negative…
Thanks,
Karl