Forum Discussion

giordani2000's avatar
giordani2000
Helper I
3 years ago
Solved

xIRR calculation discrepancy

Hi team, I am trying to calculate XIRR for a given set of investments and cashflows (column Total CF), which comply with all rules of XIRR function, but I still get a discrepancy between calculating...
  • AlexisOlson's avatar
    AlexisOlson
    3 years ago

    XIRR is a poorly implemented function. It's finicky and will occasionally fail if you don't give it a good enough guess to start from. For example, in your file, it will return the -69.9% value if you use -0.5 as a guess but fails with -0.01 as you have.

     

    I don't know of a good way around this. I've implemented my own versions of XIRR in SQL before but this isn't feasible in DAX as it cannot handle the recursion required for the algorithm. In my own financial models, I've written measures that give a very rough approximation that I feed into the guess parameter of my IRR measures (currently I use annualized TVPI but I hope to find something better).

     

    In a pinch, you may be able to get away with nested IFERROR functions that try XIRR with different guesses but this is ugly and inefficient:

    CALCULATE (
        IFERROR (
            XIRR ( TestCF, TestCF[Total CF], TestCF[Date], 0.1 ), /*Default guess*/
            IFERROR (
                XIRR ( TestCF, TestCF[Total CF], TestCF[Date], -0.1 ),
                IFERROR (
                    XIRR ( TestCF, TestCF[Total CF], TestCF[Date], -0.5 ),
                    BLANK ()
                )
            )
        ),
        FILTER (
            ALL ( TestCF ),
            CONTAINS ( VALUES ( TestSum_2 ), TestSum_2[Portfolio Company], TestCF[Company] )
        )
    )
    
  • AlexisOlson's avatar
    AlexisOlson
    3 years ago

    The file is updated now. The ones it's failing on don't surprise me. IRRs like that are pretty far out of the norm.

     

    Unfortunately, I don't have any further advice other than to tinker with the guesses. You could try using [Loss WE Ratio] as a guess and including as many additional guesses as you feel like. I think the following may work for this specific case but there's no guarantee it will work more broadly. I don't have any silver bullets.

    CALCULATE (
        IFERROR (
            XIRR ( TestCF, TestCF[Total CF], TestCF[Date], 0.1 ),
            IFERROR (
                XIRR ( TestCF, TestCF[Total CF], TestCF[Date], - [Loss WD Ratio] ),
                IFERROR (
                    XIRR ( TestCF, TestCF[Total CF], TestCF[Date], -0.5 ),
                    IFERROR (
                        XIRR ( TestCF, TestCF[Total CF], TestCF[Date], -0.999 ),
                        -1
                    )
                )
            )
        ),
        FILTER (
            ALL ( TestCF ),
            CONTAINS ( VALUES ( TestSum_2 ), TestSum_2[Bin], TestCF[Bin] )
        )
    )

     

  • AlexisOlson's avatar
    AlexisOlson
    3 years ago

    Most of my training has been on the job and answering thousands of questions on here and StackOverflow. SQLBI has great articles about DAX. Radacad has good articles too. My new favorite is Data Goblins.

     

    Reading articles and watching videos is nice but to really learn you need to actually solve problems yourself, whether your own or other people's.