Search code examples
pythonfinance

Basic Financial Library for Python


I am looking for a financial library for Python that will enable me to do a discounted cash flow analysis. I have looked around and found the QuantLib, which is overkill for what I want to do. I just need a small library that I can use to input a series of cash flows and have it output a net present value and internal rate of return. Anyone have something like this or know where I can find it?


Solution

  • Just for completeness, since I'm late: numpy has some functions for (very) basic financial calculations. numpy, scipy could also be used, to do the calculations from the basic formulas as in R.

    net present value of cashflow

    >>> cashflow = 2*np.ones(6)
    >>> cashflow[-1] +=100
    >>> cashflow
    array([   2.,    2.,    2.,    2.,    2.,  102.])
    >>> np.npv(0.01, cashflow)
    105.79547647457932
    

    get internal rate or return

    >>> n = np.npv(0.01, cashflow)
    >>> np.irr(np.r_[-n, cashflow])
    0.010000000000000231
    

    just the basics:

    >>> [f for f in dir(np.lib.financial) if not f[0] == '_']
    ['fv', 'ipmt', 'irr', 'mirr', 'np', 'nper', 'npv', 'pmt', 'ppmt', 'pv', 'rate']
    

    and it's necessary to watch out what the timing is.