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 6206859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:31:33+00:00 2026-05-24T05:31:33+00:00

The ActiveState Recipes site has a function implementing Internal Rate of Return in Python:

  • 0

The ActiveState Recipes site has a function implementing Internal Rate of Return in Python:

def irr(cashflows, iterations=100):
    """The IRR or Internal Rate of Return is the annualized effective 
       compounded return rate which can be earned on the invested 
       capital, i.e., the yield on the investment.

       >>> irr([-100.0, 60.0, 60.0, 60.0])
       0.36309653947517645
    """
    rate = 1.0
    investment = cashflows[0]
    for i in range(1, iterations+1):
        rate *= (1 - npv(rate, cashflows) / investment)
    return rate

This code returns correct values (at least for the couple of examples that I have checked against Excel), but I would like to know why.

  • It doesn’t appear to be an implementation of Newton’s Method (no derivative) or the Secant Method (only keeps track of one iteration).
  • In particular, the definition of the investment variable as the first cashflow element (and it’s subsequent use) confuses me.

Any ideas?

  • 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-05-24T05:31:36+00:00Added an answer on May 24, 2026 at 5:31 am

    The method is called fixed point iteration; see for instance the Wikipedia article http://en.wikipedia.org/wiki/Fixed_point_iteration.

    The idea is that if rate contains the correct value (that is, the IRR), then the NPV is zero, so the statement

    rate *= (1 - npv(rate, cashflows) / investment)
    

    will not change rate. Thus, once you find the IRR, the iteration will not change it. Fixed point iteration sometimes converges to the correct value and sometimes it does not. The examples of @Gareth and @unutbu show that here it does not always converge.

    The criterion for convergence is as follows. Write the update statement in the loop as

    rate = rate * (1 - npv(rate, cashflows) / investment)
    

    Now, if the derivative of the right-hand side with respect to rate is between 1 and -1, then the method converges. I cannot immediately see under what circumstances this is the case.

    You may wonder why the iteration does not do

    rate *= (1 - npv(rate, cashflows))
    

    without the weird investment variable. Indeed, I wondered the same; that would also be a fixed point method that converges to the IRR if the derivative condition is satisfied. My guess is that the derivative condition is satisfied in some circumstances for the method that you gave, and not for the method without investment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any time I use the recipe at http://code.activestate.com/recipes/134892/ I can't seem to get it
I am running 64-bit Windows 7 and the ActiveState Python 2.5 installation (64-bit version).
When I type python it displays: ActivePython 2.6.5.14 (ActiveState Software Inc.) based on Python
def primes(n): if n==2: return [2] elif n<2: return [] s=range(3,n+1,2) mroot = n
RDFLib needs C extensions to be compiled to install on ActiveState Python 2.5; as
i was going through one of the python recipes in active state and found
With ActiveState Python comes a win32api module. I need to implement something that monitors
I looked online and found some SO discussing and ActiveState recipes for running some
Is this a good practice in Python (from Active State Recipes -- Public Decorator
I am using ActiveState Perl 5.6 on a Windows 2003 Server, and am having

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.