# Pandas: Close-to-Open return on stocks

I am trying to daily calculate the close-to-open return for j stocks for t days. Is there anyway I can calculate without using a for loop? I have one Dataframe for daily close prices and one for daily open. I am using python.

If it is close-to-close return, I am able to use the pct_change, not sure for close-to-open.

RCO(t,j) = SO(t,j)/SC(t-1,j)-1


where RCO is the returns on day t for stock j, SO is the opening price and SC is the previous days closing price.

import pandas_datareader.data as web

• @Prash It depends on how you construct the inputs. If you have one DataFrame for closing prices and one DataFrame for opening quotes with matching columns names, you can divide the two (with appropriate shifts) directly. You can also play around with higher dimensional data structures like xarray. Apr 25 '18 at 23:49