Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def daily_return_estimator(df):
- df_daily_return = df.copy()
- # Loop through each stock (column of the dataframe except Date collumn)
- for i in df.columns[1:]:
- # Loop through each row/price belonging to the stock
- for j in range(1, len(df)):
- # Calculate the percentage of change from the previous day's close price.
- # Simple equation of percentage change.
- df_daily_return[i][j] = ((df[i][j]- df[i][j-1])/df[i][j-1]) * 100
- # set the value of first row to zero (previous value is not available)
- df_daily_return.loc[0, i] = 0
- return df_daily_return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement