Skip to main content

Overview

A simple python tool for calculating ratios used to measure portfolio performance. Ratios include alpha, beta, sharpe, volatility, upside capture, downside capture, sortino ratio, treynor ratio, drawdown etc.

It also can be used to calculating portfolio returns like XIRR. (twirr, holding period return etc. will be added).

The tool is largely based on pandas and numpy and is capable of giving continuous (rolling) values of ratios wherever required in the form of a pandas dataframe. All data (portfolio/ navs/ market) needs to be passed in arguments based on the function getting called.

For example - XIRR can be calculated from portfolio cashflows [(date, amount)]. - Sharpe ratio will need scheme/portfolio nav [(date, nav)]. - Alpha will need both scheme nav as well as benchmark nav.

For definitions of above terms, check Investopedia. You can find the examples of few of these ratios here. https://www.valueresearchonline.com/funds/197/sbi-large-and-midcap-fund

  • Free software: BSD 2-Clause License

Installation

pip install finance-calculator

You can also install the in-development version with:

pip install https://github.com/sprksh/finance-calculator/archive/master.zip

Documentation

https://finance-calculator.readthedocs.io/

Development

To run all the tests run:

tox

Note, to combine the coverage data from all the tox environments run:

Windows

set PYTEST_ADDOPTS=--cov-append
tox

Other

PYTEST_ADDOPTS=--cov-append tox

Usage

To use finance_calculator in a project:

import finance_calculator as fc
drawdown = fc.get_drawdown(scheme_data, 250, 22)
volatility = fc.get_volatility(scheme_data, 250, 22)
sharpe = fc.get_sharpe(scheme_data, 250, 22)
sortino = fc.get_sortino(scheme_data, 250, 22)
treynor = fc.get_treynor(scheme_data, benchmark_data, 250, 22)
alpha = fc.get_alpha(scheme_data, benchmark_data, 250, 22)
beta = fc.get_beta(scheme_data, benchmark_data, 250, 22)
upside_capture = fc.get_upside_capture(scheme_data, benchmark_data, 250, 22)
downside_capture = fc.get_downside_capture(scheme_data, benchmark_data, 250, 22)

If you want only current value of a given ratio, you can use tail=True as a keyword argument in all of these functions. With tail=False it will give a pandas dataframe with values in a rolling window fashion.

The scheme data and the benchmark data can either be a pandas dataframe or list of tuples: (date, nav).

Also you can use it to calculate xirr:

>>> import finance_calculator as fc
>>> cashflow_data = [
    (datetime.date(2020, 3, 1), 10000),
    (datetime.date(2020, 4, 1), 10000),
    (datetime.date(2020, 5, 1), 10000),
    (datetime.date(2020, 6, 1), 10000),
    (datetime.date(2020, 7, 1), 10000),
    (datetime.date(2020, 8, 1), -60000),
]
>>> xirr = fc.get_xirr(cashflow_data)

Changelog

0.0.0 (2020-07-29)

  • First release on PyPI.

Metadata

Release files for finance-calculator 0.0.6

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-calculator 0.0.6
File Size Uploaded
finance-calculator-0.0.6.tar.gz 133.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for finance-calculator 0.0.6
File Interpreter ABI Platform
finance_calculator-0.0.6-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 145.7 kB

Release files / finance-calculator-0.0.6.tar.gz

Download URL finance-calculator-0.0.6.tar.gz
Size 133.1 kB
Tags Source
SHA-256 checksum
How to use checksums
14696f99fce16d9a0bfaacb551d837a1d2519c486d6b0c9acb9487139fed8aae
BLAKE2b-256 checksum
How to use checksums
ec51a71e74f84a173c16740475f5fbbdc8c0890cfc2e68f1b4140006790b6d84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.4

Release files / finance_calculator-0.0.6-py2.py3-none-any.whl

Download URL finance_calculator-0.0.6-py2.py3-none-any.whl
Size 12.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
91a1eabf38538e144b0b965cdf87341650b27daeee943b407c81d00a55a47459
BLAKE2b-256 checksum
How to use checksums
5cb2965e372ba6c4bf0a7b702ae4b6556d13c00c602cc01e4fc1e59cf838e8f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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