While working with stock market data, sometime we would like to change our time window of reference. Generally daily prices are available at stock exchenges. Let us see how to conert daily prices into weekly and monthly prices.
You can download daily prices from NSE from this link. We will downoad daily prices for last 24 months. Here is the sample file with which we will work
Please refer to below program to convert daily prices into weekly. Comments in the program will help you understand the logic behind each line.
Once you understand daily to weekly, only small modification is needed to convert this into monthly OHLC data. Here is the script
Here are the output files for your reference.
I wasted some time to find ‘Open Price’ for weekly and monthly data. I tried some complex pandas queries and then realized same can be achieved by simply using aggregate function and ‘Open Price‘:‘first.
Please do let me know your feedback.