Quantcast
Viewing all articles
Browse latest Browse all 14331

Pandas resample for Monthly and Quarterly Return Calculation

I have this code:

import yfinance as yfimport numpy as npimport pandas as pddf = yf.download('TSLA', start = '2023-01-01')df = df[['Close']]df['return_per_day'] = np.log(df.div(df.shift(1)))df.dropna(inplace = True)

For the max return_per_day every month,

df.resample('MS').max()

For the max return_per_day every quarter,

df.resample('QS').max()

How do I get the max return_per_day for next 3 Months but listed on a monthly basis?Each row will be a month. The returns shown will be max return_per_day in the next 3 Months.


Viewing all articles
Browse latest Browse all 14331

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>