Skip to content
All library documents

Calculating Close-to-Open Stock Returns with a Price Shift

Article Quant Q&A · Author: Prash

Summary

The document defines the close-to-open return for each stock on day t as that day’s opening price divided by the prior day’s close, minus one. The question asks how to calculate this daily across multiple stocks without a loop, using separate data frames for opening and closing prices.

The answer points to a pandas example that divides adjusted close prices by adjusted opening prices shifted by five trading days, then subtracts one. This illustrates how a shift aligns prices from different dates for a multi-day return calculation. However, the example calculates a different interval and direction from the requested prior-close-to-current-open return. The document offers no direct implementation for that formula, nor discussion of missing data, corporate actions, or return validation.

Key ideas

  • Close-to-open return compares the current session’s open with the previous session’s close.
  • The return is expressed as the price ratio minus one.
  • Shifting a price series aligns observations from different trading dates.
  • The example uses adjusted prices and a five-day shift, so it does not directly implement the question’s one-day close-to-open calculation.

Tags

Full text
# Pandas: Close-to-Open return on stocks


# 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.

## Answer by Helin (score 4)

https://quant.stackexchange.com/a/39433

Please refer to this code example, which calculates open-to-close returns over the past five trading days.

```
import pandas_datareader.data as web
symbol = 'WIKI/AAPL'
df = web.DataReader(symbol, 'quandl', '2018-01-01', '2018-03-31')
df['AdjClose'] / df['AdjOpen'].shift(5) - 1  # change 5 to the desired interval
```

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.