Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic Financial Library for Python

Tags:

python

finance

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?

like image 556
Robert Schmidt Avatar asked Feb 13 '10 22:02

Robert Schmidt


People also ask

Which Python library is used in finance?

numpy - NumPy is the fundamental package for scientific computing with Python. It is a first-rate library for numerical programming and is widely used in academia, finance, and industry.

Can Python be used for finance?

Python is an ideal programming language for the financial industry. Widespread across the investment banking and hedge fund industries, banks are using Python to solve quantitative problems for pricing, trade management, and risk management platforms.

Can you build financial models in Python?

Financial modeling using Python is a method of building a model using the Python programming language. The language allows coders to modify and analyze Excel spreadsheets and automate certain tasks.

What are basic libraries in Python?

The Python Standard Library contains the exact syntax, semantics, and tokens of Python. It contains built-in modules that provide access to basic system functionality like I/O and some other core modules. Most of the Python Libraries are written in the C programming language.


1 Answers

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.

like image 74
Josef Avatar answered Sep 18 '22 16:09

Josef