Code Monkey home page Code Monkey logo

xirr_in_python's Introduction

XIRR calculation (in Python)

Introduction

XIRR stands for Extended Internal Rate of Return and is used to calculate return on investments made at different time periods which need not be periodic.

XIRR gives the annualized return of a portfolio that include all cash flows.

XIRR is a financial function available in Excel. The drawback with Excel's XIRR is that it will show the 0% XIRR as a default for negative returns.

For use in Python, I have written this code which calculates XIRR for both positive and negative returns. For the same XIRR calculation using R, please check my other repository: XIRR_in_R

I hope you find my xirr function useful.

Sample test Data

Data should be in a csv file and should have two columns:  
    1. Date of transaction  
        The date can be any one or a mix of these formats. I set it to consider dayfirst = True:
        23/03/1990
        19 December 1991
        1992-04-10
        27/05/92
        26.10.92
        3/9/93
        datetime.date(1990, 3, 23)
    2. Transaction amount where purchases (debit) should be a negative number and the redemptions (credit) should be a positive number.
        dates      amount
        23/03/1990  -1350
        23/07/1990    600
        31/10/1990  -1250
        13/11/1990   3550
        30/01/1991   -850
        03/05/1991   3600

Note: Please find the sample data provided in the repository

System requirements

  1. Python (version 3.8.2)
  2. Libraries: Pandas, Numpy

I am using git terminal (CLI) to execute the script.
Clone the repository onto your system from github.

Move into the cloned folder.

View the list of files and folders.

Example: Positive returns

Pass the location of Sample_Positive_Returns.csv

That is, the return of our portfolio is 17.429% per annum.

Example: Negative returns

Pass the location of Sample_Negative_Returns.csv

That is, the return of our portfolio is -79.848% per annum.

xirr_in_python's People

Contributors

sunilveeravalli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.