Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9172101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:15:56+00:00 2026-06-17T16:15:56+00:00

I have a DataFrame with daily OHLCV data. I can calculate the range with:

  • 0

I have a DataFrame with daily OHLCV data.

I can calculate the range with:

s['Range'] = s['High'] - s['Low']

Simple. Now I would like to calculate a new column which I’ve called s['OIR'] (OIR = Open-In-Range)

The ['OIR'] column checks to see if we opened in range and it does this by testing if we opened above yesterdays low and below yesterday’s high. I need to reference the previous rows and I’m not quite sure how to do it. The return values would be True/False.

Thanks.


edit: I’m new to StackExchange and Python. Not sure where to drop sample data. Here’s an image of the dataframe.

http://i47.tinypic.com/142eb2a.png


Sample Data: Dictionary convert to DataFrame

{'High': {<Timestamp: 2007-03-02 00:00:00>: 1384.5,
  <Timestamp: 2007-03-05 00:00:00>: 1373.0},
 'Last': {<Timestamp: 2007-03-02 00:00:00>: 1365.0,
  <Timestamp: 2007-03-05 00:00:00>: 1351.5},
 'Low': {<Timestamp: 2007-03-02 00:00:00>: 1364.25,
  <Timestamp: 2007-03-05 00:00:00>: 1350.5},
 'OIR': {<Timestamp: 2007-03-02 00:00:00>: False,
  <Timestamp: 2007-03-05 00:00:00>: False},
 'Open': {<Timestamp: 2007-03-02 00:00:00>: 1378.5,
  <Timestamp: 2007-03-05 00:00:00>: 1356.75},
 'Range': {<Timestamp: 2007-03-02 00:00:00>: 20.25,
 <Timestamp: 2007-03-05 00:00:00>: 22.5},
 'Volume': {<Timestamp: 2007-03-02 00:00:00>: 1706906,
 <Timestamp: 2007-03-05 00:00:00>: 1984041}}

Answer:

s['OIR'] = ((s['Open'] < s['High'].shift(1)) & (s['Open'] > s['Low'].shift(1)))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:15:57+00:00Added an answer on June 17, 2026 at 4:15 pm

    Referencing previous rows in the manner you suggest is best accomplished with the Series.shift() function:

    In [1]: df = DataFrame(randn(10,3),columns=['O','L','H'])
    
    In [2]: df
    Out[2]:
              O         L         H
    0  0.605412  0.739866 -0.280222
    1 -0.707852  0.785651  0.855183
    2 -0.087119  0.518924  0.932167
    3 -0.913352  0.369825  1.277771
    4  0.434593 -2.942903  0.802413
    5  0.075669 -0.135914  1.374454
    6  1.112062  0.314946  0.882468
    7 -0.706078 -0.202243  0.838088
    8 -1.668152  0.414585  0.809932
    9  1.452937 -0.048245  0.635499
    
    In [3]: df['OIR'] = ((df.L.shift() <= df.O) & (df.O <= df.H.shift()))
    
    In [4]: df
    Out[4]:
              O         L         H    OIR
    0  0.605412  0.739866 -0.280222  False
    1 -0.707852  0.785651  0.855183  False
    2 -0.087119  0.518924  0.932167  False
    3 -0.913352  0.369825  1.277771  False
    4  0.434593 -2.942903  0.802413   True
    5  0.075669 -0.135914  1.374454   True
    6  1.112062  0.314946  0.882468   True
    7 -0.706078 -0.202243  0.838088  False
    8 -1.668152  0.414585  0.809932  False
    9  1.452937 -0.048245  0.635499  False
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataframe and would like to calculate the correlation (with Spearman, data
I have a dataframe with numeric entries like this one test <- data.frame(x =
I have a dataframe with a column of integers that I would like to
I have a dataframe where some of the values are NA. I would like
I have a dataframe in R like this: dat = data.frame(Sample = c(1,1,2,2,3), Start
I have a dataframe of values and I would like to explore the rows
I have a dataframe capturing several measures over time that I would like to
I have a data frame of daily data: df with four columns: Date, A,
I have a dataframe with distances df<-data.frame(site.x=c(A,A,A,B,B,C), site.y=c(B,C,D,C,D,D),Distance=c(67,57,64,60,67,60)) I need to convert this to
I have a dataframe called split2_data (actually a drop-leveled subset of a bigger data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.