Skip to main content

finance - long description

The purpose of this project is to deliver ease of use python code for financial risk calculations. This code is not unconsious reproduction of textbook material.

It’s about developing abstract data types as objects to ease financial calculations and code development.

At this point the code is by no means optimized for speed.

Financial and mathematical concepts are developed on the PythonHacks homepage.

Part 1 - Simple time dependent assets

Time is generic like a period such as eg 1 month and non-generic like a specific date. In part both types are implemented with a heavy use of operator overload.

This means that questions like: How many days are there between a date 2009-12-27 and 3 months ahead can be calculated like:

>>> from finance import bankdate
>>> t1 = bankdate('2009-12-27')
>>> print t1 + '3m'
2010-03-27
>>> print t1 + '3m' - t1
90

Further a vector-like structure handling future payments - a dateflow - is implemented as a class.

Through method overload it is easy to build even very complex cashflows (= dateflow)

Generators of standard dateflows is also a part of the package.

Before any calculations on a dateflow can be made dates has to be converted into times. For this the class datetotime is created.

Finally simpel calculations like present value and different sorts of duration can be made though the class timeflow

How to install

Just run setup.py install command. Or in windows use the windows installer.

Documentation, etc

Visit my homepage to see more on how to use and the research behind the code. It’s a blog like place on finance, math and scientific computing.

Changes in 0.2502:

There were still some problems with ultimo dates which now should be solved. Thank you to Johan Uys for bringing it to my attention.

Changes in 0.2501:

Problems with generating ultimo dates has been solved. Thank you to Ankush Sahai for bringing it to my attention.

Changes in 0.25:

Code has been rewritten to isolate strickt mathematical strucktures like e.g. DecimalVector in separate packages. There have been slight modifications to yieldcurves.

Changes in 0.20:

Now discount curves based on benchmark zero bonds where the rates are continous forward rates. It is possible to get standard yieldcalculations done like:

Instantiate:

>>> import finance
>>> ns = finance.yieldcurves.NelsonSiegel(0.061, -0.01, -0.0241, 0.275)

See the settings:

>>> ns
Nelson Siegel (level=0.061, slope=-0.01, curvature=-0.0241, scale=0.275)

Get the discountfactors at times 1, 2, 5, 10:

>>> times = [1, 2, 5, 10]
>>> ns(times)
DecimalVector([0.9517121708497056177816078083, 0.9072377300179418172521412527, 0.7844132592062346545344544940, 0.6008958407659500402742872859])

Get the zero coupon rate at time 5 and 7

>>> r5, r7 = ns.zero_coupon_rate([5, 7])
>>> r5, r7
(Decimal('0.049762403554685553400657196'), Decimal('0.050625188777310061599365592'))

Get the forward rate between time 5 and 7

>>> f5_7 = ns.discrete_forward_rate(5, 7)
>>> f5_7
Decimal('0.052785255470657667493924028')

As shown above yieldcurves are made using the DecimalVector concept. Especially all outputs will be Decimal or DecimalVector.

For now there are 3 different yield curve types:

  • The Nelson Siegel

  • The natural cubic spline

  • The financial cubic spline

This way the finance package covers a large part of yieldcurves in use. Since it is easy to add more yieldcurves due to the design more will come.

Yieldcurves are of course integrated into the timeflow. So now it is possible to do most fixed income calculations.

A tutorial on fixed income calculations in the finance package is on its way.

Risk calculations based on linearily decomposable discountcurves is postponed intil later.

Planned added contents

The planned development so far is:

Planned added content of version 0.3:

Currencies, implementing Markowitz etc

Planned added content of version 0.4:

Optionality though (binomial) trees

Planned added content of version 0.5:

Bootstrapping from timeflows to get a base of benchmark zero bonds

Planned added content of version 0.6:

Concept of portfolios, eg structured products

Metadata

Release files for finance 0.2502

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for finance 0.2502
File Size Uploaded
finance-0.2502.tar.gz 45.7 kB Details

Release files / finance-0.2502.tar.gz

Download URL finance-0.2502.tar.gz
Size 45.7 kB
Tags Source
SHA-256 checksum
How to use checksums
498e61ea8aa922b6aefd33b3960d0404be22e1bb47edcc910ac9723da4e715c0
BLAKE2b-256 checksum
How to use checksums
d7d31d6c3ea93e3b5383426d877be510ccd06037c8f41b47aab5c5741517bb91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2502 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page