Skip to content

irr() providing different results on ARM and x86 CPUs #37

Closed

Description

@millettmb

Hi all,
I've got two machines set up, my local development machine (i7-10510U), and an AWS EC2 instance (c6g.16xlarge, Arm-based AWS Graviton2). On both machines, the same version of Python (3.8.5) and numpy_financial (1.0.0) are installed. Both machines are running Ubuntu 20.04 LTS, with my local machine running kernel 5.8.0-43-generic and the AWS machine running 5.4.0-1037-aws.

I run the following code on both machines:

import numpy_financial
test_cashflow = [-20, 2, 3, 4, 5, 4, 3, 2]
numpy_financial.irr(test_cashflow)

On my local development machine (x86), the result given is 0.03603774756546363, whereas on the AWS EC2 Arm-based instance, the result given is 0.08389095415117676. I've also run the same code on an AWS EC2 t2.medium instance (x86 based) and was given the same result as my local development machine (0.036...)

If I provide the same input into the MS Excel IRR function, the result given is 3.6%, matching the x86 outputs. This leads me to believe that there's an issue occurring with the ARM package.

Activity

  1. millettmb commented on Feb 16, 2021

    @millettmb
    Author

    Bit of a further look into this, I believe it's potentially due to the _roots function, in particular the call to eigenvalues = np.linalg.eigvals(A). With the input of [ 2, 3, 4, 5, 4, 3, 2, -20] into _roots, we get the following outputs on ARM and x86:

    ARM:

    [-0.57177033, -0.20057009, -0.26713326, -0.2414787 ,  0.05233208, -1.19398174,  0.92260203]
    

    x86:

    [-1.42246365+0.5999765j , -1.42246365-0.5999765j , -0.43909567+1.43190315j, -0.43909567-1.43190315j, 0.62895142+1.24188972j,  0.62895142-1.24188972j, 0.9652158 +0.j        ]
    

    It's been a little while since I last looked at eigenvalues, but I believe that the x86 output here is correct, and the ARM output is incorrect due to the non-inclusion of complex conjugate pairs.

    Given that this now appears to be an issue with the numpy package itself, I've created an issue at the numpy repo, and am linking it here: numpy/numpy#18422. I'm not too sure on what the etiquette is on listing issues with dependent packages, so I'll leave this issue here for now in case anyone else has the same issue.

  2. millettmb commented on Feb 16, 2021

    @millettmb
    Author

    So after a bit more tinkering, I've found out a way to solve this issue. You'll need to follow along with the guide here: https://github.com/aws/aws-graviton-getting-started/blob/master/python.md.

    1. If you already have numpy installed through pip, uninstall it using pip3 uninstall numpy
    2. Run the following code:
    sudo apt update
    sudo apt-get install build-essential python3-pip python3-dev libblas-dev gfortran liblapack-dev
    python3 -m pip install --user --upgrade pip
    sudo apt -y install python3-scipy python3-numpy libopenblas-dev libblis-dev
    sudo update-alternatives --set libblas.so.3-aarch64-linux-gnu \
        /usr/lib/aarch64-linux-gnu/blis-openmp/libblas.so.3
    
    1. Install numpy_financial if you haven't already, this will use the numpy version we have just installed
    2. Open a Python interactive shell and enter the following code to test that it's been installed properly
    import numpy_financial
    numpy_financial.irr([-20, 2, 3, 4, 5, 4, 3, 2])
    

    If all has gone well, you should get a result of 0.03603774756546341. If it's been installed incorrectly, you'll get a value of 0.08389095415117676.

    I'll mark this as closed, but I'm not too sure how best to inform the ARM user base of this problem. I'll leave the issue in the numpy package open for now, and as for suggestions there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions