Released by: Mountasser Labchiri
N.B: Please consider changing “YourUserName” in the path with your laptop name before executing the scripts.
Amazon Stock Database that I used (Downloadable):
Microsoft Stock Database that I used (Downloadable):
#Imported libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import tqdm as tqdm
**Amazon Stock daily return**
#Table of daily $AMZN stock return creation and adding return columns based on higher price
return_quot_amzn=pd.read_csv("C:\\Users\\YourUserName\\Downloads\\AMZN.csv",index_col=0)
return_quot_amzn['daily_return'] = (return_quot_amzn['High']/ return_quot_amzn['High'].shift(1)) -1
return_quot_amzn.dropna(inplace = True)
return_quot_amzn.head(5)
**Microsoft Stock daily return**
#Table of daily $MSFT stock return creation and adding return columns based on higher price
return_quot_MSFT=pd.read_csv("C:\\Users\\YourUserName\\Downloads\\MSFT.csv",index_col=0)
return_quot_MSFT['daily_return'] = (return_quot_MSFT['High']/ return_quot_MSFT['High'].shift(1)) -1
return_quot_MSFT.dropna(inplace = True)
return_quot_MSFT.head(5)
**Comparing Tables**
#Joining the two tables making use of return values
portfolio=pd.DataFrame().assign(Return_AMZN=return_quot_amzn['daily_return'],Return_MSFT=return_quot_MSFT['daily_return'])
portfolio.head(5)
**Annual Return**