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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:48:12+00:00 2026-05-20T09:48:12+00:00

How do I calculate Excel’s XIRR function using C#?

  • 0

How do I calculate Excel’s XIRR function using C#?

  • 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-20T09:48:13+00:00Added an answer on May 20, 2026 at 9:48 am

    According to XIRR function openoffice documentation (formula is same as in excel) you need to solve for XIRR variable in the following f(xirr) equation:
    enter image description here

    You can calculate xirr value by:

    1. calculating derivative of above function -> f ‘(xirr)
    2. after having f(xirr) and f'(xirr) you can solve for xirr value by using iterative Newton’s method – famous formula->
      enter image description here

    EDIT
    I’ve got a bit of time so, here it is – complete C# code for XIRR calculation:

    class xirr
        {
            public const double tol = 0.001;
            public delegate double fx(double x);
    
            public static fx composeFunctions(fx f1, fx f2) {
                return (double x) => f1(x) + f2(x);
            }
    
            public static fx f_xirr(double p, double dt, double dt0) {
                return (double x) => p*Math.Pow((1.0+x),((dt0-dt)/365.0));
            }
    
            public static fx df_xirr(double p, double dt, double dt0) {
                return (double x) => (1.0/365.0)*(dt0-dt)*p*Math.Pow((x+1.0),(((dt0-dt)/365.0)-1.0));
            }
    
            public static fx total_f_xirr(double[] payments, double[] days) {
                fx resf = (double x) => 0.0;
    
                for (int i = 0; i < payments.Length; i++) {
                    resf = composeFunctions(resf,f_xirr(payments[i],days[i],days[0]));
                }
    
                return resf;
            }
    
            public static fx total_df_xirr(double[] payments, double[] days) {
                fx resf = (double x) => 0.0;
    
                for (int i = 0; i < payments.Length; i++) {
                    resf = composeFunctions(resf,df_xirr(payments[i],days[i],days[0]));
                }
    
                return resf;
            }
    
            public static double Newtons_method(double guess, fx f, fx df) {
                double x0 = guess;
                double x1 = 0.0;
                double err = 1e+100;
    
                while (err > tol) {
                    x1 = x0 - f(x0)/df(x0);
                    err = Math.Abs(x1-x0);
                    x0 = x1;
                }
    
                return x0;
            }
    
            public static void Main (string[] args)
            {
                double[] payments = {-6800,1000,2000,4000}; // payments
                double[] days = {01,08,16,25}; // days of payment (as day of year)
                double xirr = Newtons_method(0.1,
                                             total_f_xirr(payments,days),
                                             total_df_xirr(payments,days));
    
                Console.WriteLine("XIRR value is {0}", xirr);
            }
        }
    

    BTW, keep in mind that not all payments will result in valid XIRR because of restrictions of formula and/or Newton method!

    cheers!

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

Sidebar

Related Questions

I am using Excel to create some formuals to calculate a total dollar ammount
How can I calculate the value of PI using C#? I was thinking it
I am trying to calculate the pixel width of Excel columns, as described in
Hai i have an excel sheet, in that i need to calculate some values
I'm trying to calculate the sunset / rise times using python based on the
I have an excel spreadsheet that contains some formulas to calculate ROI for an
I've been trying to get this Excel function working correctly, and I've hit a
Can you use calculated fields in Excel 2007 pivot tables when the data source
To calculate a top position for an element of variable height, I was thinking
How do I calculate the distance between two points specified by latitude and longitude?

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.