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

  • SEARCH
  • Home
  • 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 8349809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:07:15+00:00 2026-06-09T08:07:15+00:00

I have a DataFrame that represents stock returns. To split adjust the closing price,

  • 0

I have a DataFrame that represents stock returns. To split adjust the closing price, I have the following method:

def returns(ticker, start=None, end=None):
    p = historical_prices(ticker, start, end, data='d', convert=True)
    d = historical_prices(ticker, start, end, data='v', convert=True)

    p['Dividends'] = d['Dividends']
    p['Dividends'].fillna(value=0, inplace=True)
    p['DivFactor'] = 1.
    p['SAClose'] = p['Close']

    records, fields = p.shape
    for t in range(1, records):
        p['SAClose'][t] = p['Adj Close'][t] / p['DivFactor'][t-1] + \
                          p['Dividends'][t-1]
        p['DivFactor'][t] = p['DivFactor'][t-1] * \
                            (1 - p['Dividends'][t-1] / p['SAClose'][t])

    p['Lagged SAClose'] = p['SAClose'].shift(periods=-1)
    p['Cash Return'] = p['Dividends'] / p['Lagged SAClose']
    p['Price Return'] = p['SAClose'] / p['Lagged SAClose'] - 1
    return p.sort_index()

Note how SAClose (i.e. Split Adjusted Close) depends upon lagged DivFactor values. In turn, DivFactor depends on both lagged DivFactor values as well as the current SAClose value.

The method above works, but it is incredibly slow in the loop section. Is there a more efficient way for me to do this in pandas? Given the “circular” dependency (not really circular given the lags), I’m not sure how I could do either regular series math or use normal shift operations (e.g as I do with Cash Return).

  • 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-09T08:07:16+00:00Added an answer on June 9, 2026 at 8:07 am

    You can try creating a cumulative adjustment factor series in one shot then you don’t need to loop:

    (p['Dividends'].fillna(1.) + 1.).cumprod()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataframe that looks like this: person n start end 1 sam
I have a dataframe with one column that I would like to split into
I have a dataframe with a column of integers that I would like to
I have a dataframe and I would like to apply a function that takes
I have a data frame where each line represents an individual. That data frame
I have a dataframe in R that I loaded from a CSV file. One
I'd like to melt the dataframe so that in one column I have dates
I have some data in a dataframe calvarbyruno.1 with variables Nominal and PAR that
If I have the following dataframe called result > result Name CV LCB UCB
I have a dataframe that I want to reshape; my reshape code: matchedlong <-

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.