Skip to main content

Financial Research Data Services

Project description

frds

FRDS - Financial Research Data Services

LICENSE DOWNLOADS Test Code style: black

frds is an open-sourced Python package for computing a collection of major academic measures used in the finance literature in a simple and straightforward way.

Installation

pip install frds

Note

This library is still under development and breaking changes may be expected.

If there's any issue (likely), please contact me at mingze.gao@sydney.edu.au

Supported measures

More to be added. For a complete list of supported built-in measures, please check frds.io/measures/.

Examples

The primary purpose of frds is to offer ready-to-use functions.

Absorption Ratio

For example, Kritzman, Li, Page, and Rigobon (2010) propose an Absorption Ratio that measures the fraction of the total variance of a set of asset returns explained or absorbed by a fixed number of eigenvectors. It captures the extent to which markets are unified or tightly coupled.

>>> import numpy as np
>>> from frds.measures import absorption_ratio
>>> data = np.array( # Hypothetical 6 daily returns of 3 assets.
...             [
...                 [0.015, 0.031, 0.007, 0.034, 0.014, 0.011],
...                 [0.012, 0.063, 0.027, 0.023, 0.073, 0.055],
...                 [0.072, 0.043, 0.097, 0.078, 0.036, 0.083],
...             ]
...         )
>>> absorption_ratio.estimate(data, fraction_eigenvectors=0.2)
0.7746543307660252

Distress Insurance Premium

Another example, Distress Insurance Premium (DIP) proposed by Huang, Zhou, and Zhu (2009) as a systemic risk measure of a hypothetical insurance premium against a systemic financial distress, defined as total losses that exceed a given threshold, say 15%, of total bank liabilities.

>>> from frds.measures import distress_insurance_premium
>>> # hypothetical implied default probabilities of 6 banks
>>> default_probabilities = np.array([0.02, 0.10, 0.03, 0.20, 0.50, 0.15] 
>>> correlations = np.array(
...     [
...         [ 1.000, -0.126, -0.637, 0.174,  0.469,  0.283],
...         [-0.126,  1.000,  0.294, 0.674,  0.150,  0.053],
...         [-0.637,  0.294,  1.000, 0.073, -0.658, -0.085],
...         [ 0.174,  0.674,  0.073, 1.000,  0.248,  0.508],
...         [ 0.469,  0.150, -0.658, 0.248,  1.000, -0.370],
...         [ 0.283,  0.053, -0.085, 0.508, -0.370,  1.000],
...     ]
... )
>>> distress_insurance_premium.estimate(default_probabilities, correlations)       
0.28661995758

Modified Default Probability (bank)

More examples. Nagel and Purnanandam (2020) introduce the Modified Default Probability for banks. Banks' assets are contingent claims on borrowers' collateral assets, hence banks' equity and debt are contingent claims on these contingent claims. While borrowers' assets value may follow a lognormal distribution, banks' assets do not.

Below is a one-liner replication of the simulations.

>>> from frds.measures.modified_merton import mod_merton_simulation
>>> mod_merton_simulation.simulate()
----------------------------------------------------------------------------
                                        Borrower asset value
                                    ----------------------------------------
                                    No shock        +ve shock       -ve shock
----------------------------------------------------------------------------
A. True properties
Agg. Borrower Asset Value           1.06            1.33            0.85
Bank Asset Value                    0.74            0.79            0.67
Bank Market Equity/Market Assets    0.12            0.16            0.07
Bank 5Y RN Default Prob.            0.23            0.11            0.49
Bank Credit Spread (%)              0.50            0.19            1.37
----------------------------------------------------------------------------
B. Misspecified estimates based on standard Merton model
Merton 5Y RN Default Prob.          0.13            0.01            0.58
Merton Credit Spread (%)            0.12            0.00            1.54
----------------------------------------------------------------------------

These results are largely the same as Table 1 in Nagel and Purnanandam (2020). Additionally, several plots will be saved in the working directory, e.g., Figure 2:

figure2

And another sample output, Figure 4:

figure4

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

frds-2.0.0rc4.tar.gz (177.8 kB view hashes)

Uploaded Source

Built Distributions

frds-2.0.0rc4-cp311-cp311-win_amd64.whl (202.9 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

frds-2.0.0rc4-cp311-cp311-win32.whl (201.6 kB view hashes)

Uploaded CPython 3.11 Windows x86

frds-2.0.0rc4-cp311-cp311-musllinux_1_1_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

frds-2.0.0rc4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (493.8 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

frds-2.0.0rc4-cp311-cp311-macosx_10_9_x86_64.whl (201.0 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

frds-2.0.0rc4-cp310-cp310-win_amd64.whl (202.9 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

frds-2.0.0rc4-cp310-cp310-win32.whl (201.6 kB view hashes)

Uploaded CPython 3.10 Windows x86

frds-2.0.0rc4-cp310-cp310-musllinux_1_1_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

frds-2.0.0rc4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (492.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

frds-2.0.0rc4-cp310-cp310-macosx_10_9_x86_64.whl (201.0 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

frds-2.0.0rc4-cp39-cp39-win_amd64.whl (202.8 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

frds-2.0.0rc4-cp39-cp39-win32.whl (201.6 kB view hashes)

Uploaded CPython 3.9 Windows x86

frds-2.0.0rc4-cp39-cp39-musllinux_1_1_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

frds-2.0.0rc4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (492.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

frds-2.0.0rc4-cp39-cp39-macosx_10_9_x86_64.whl (201.0 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

frds-2.0.0rc4-cp38-cp38-win_amd64.whl (202.8 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

frds-2.0.0rc4-cp38-cp38-win32.whl (201.6 kB view hashes)

Uploaded CPython 3.8 Windows x86

frds-2.0.0rc4-cp38-cp38-musllinux_1_1_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

frds-2.0.0rc4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (493.0 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

frds-2.0.0rc4-cp38-cp38-macosx_10_9_x86_64.whl (201.0 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page