Giter VIP home page Giter VIP logo

frds's Introduction

frds

FRDS - Financial Research Data Services

LICENSE DOWNLOADS Test Code style: black

frds is a Python library to simplify the complexities often encountered in financial research. It provides a collection of ready-to-use methods for computing a wide array of measures in the literature.

It is developed by Dr. Mingze Gao from the Macquarie University, initially started as as a personal project during his postdoctoral research fellowship at the University of Sydney.

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 [email protected]

Supported measures and algorithms

For a complete list of supported built-in measures, please check frds.io/measures/ and frds.io/algorithms.

Supported Measures

  • Absorption Ratio
  • Contingent Claim Analysis
  • Distress Insurance Premium
  • Lerner Index (Banks)
  • Long-Run Marginal Expected Shortfall (LRMES)
  • Marginal Expected Shortfall
  • Option Prices
  • SRISK
  • Systemic Expected Shortfall
  • Z-score

Algorithms

  • GARCH(1,1)
  • GARCH(1,1) - CCC
  • GARCH(1,1) - DCC
  • GJR-GARCH(1,1)
  • GJR-GARCH(1,1) - DCC

Examples

Some simple examples.

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 AbsorptionRatio
>>> 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],
...             ]
...         )
ar = AbsorptionRatio(data)
ar.estimate()
0.7746543307660252

Bivariate GARCH-CCC

Use frds.algorithms.GARCHModel_CCC to estimate a bivariate Constant Conditional Correlation (CCC) GARCH model. The results are as good as those obtained in Stata, marginally better based on log-likelihood.

>>> import pandas as pd
>>> from pprint import pprint
>>> from frds.algorithms import GARCHModel_CCC
>>> data_url = "https://www.stata-press.com/data/r18/stocks.dta"
>>> df = pd.read_stata(data_url, convert_dates=["date"])
>>> nissan = df["nissan"].to_numpy() * 100
>>> toyota = df["toyota"].to_numpy() * 100
>>> model_ccc = GARCHModel_CCC(toyota, nissan)
>>> res = model_ccc.fit()
>>> pprint(res)
Parameters(mu1=0.02745814255283541,
           omega1=0.03401400758840226,
           alpha1=0.06593379740524756,
           beta1=0.9219575443861723,
           mu2=0.009390068254041505,
           omega2=0.058694325049554734,
           alpha2=0.0830561828957614,
           beta2=0.9040961791372522,
           rho=0.6506770477876749,
           loglikelihood=-7281.321453218112)

frds's People

Contributors

mgao6767 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

frds's Issues

unsupported operand type(s) for |: 'type' and 'type'

Describe the bug
unsupported operand type(s) for |: 'type' and 'type'

To reproduce
This is an example provided by https://frds.io/measures/srisk/#frds.measures.srisk.estimate

from frds.measures.srisk import estimate as srisk
import yfinance as yf
import numpy as np
df = yf.download(tickers="SPY JPM GS", start="2017-01-01", end="2022-12-31",
progress=False, rounding=True)
df = df[['Adj Close']]
df.columns = df.columns.droplevel(0)
df

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [Windows]
  • Python version [Python3.9.13]

Additional context
Add any other context about the problem here.
SRISK-error

Import error when trying to import CCA [BUG]

Hi,
I'm using your awesome library in a financial engineering course.
In Colab, when I run the line:

from frds.measures import cca

I get the following import error related to the statistics library dependency:

ImportError                               Traceback (most recent call last)
[<ipython-input-23-f3b52035cd61>](https://localhost:8080/#) in <module>
----> 1 from frds.measures import cca
      2 

2 frames
[/usr/local/lib/python3.7/dist-packages/frds/measures/__init__.py](https://localhost:8080/#) in <module>
      2 
      3 """
----> 4 from .bank import *
      5 from .corporate import *
      6 from .general import *

[/usr/local/lib/python3.7/dist-packages/frds/measures/bank.py](https://localhost:8080/#) in <module>
      1 from .func_absorption_ratio import absorption_ratio
----> 2 from .func_dip import distress_insurance_premium
      3 from .func_mes import marginal_expected_shortfall
      4 from .func_ses import systemic_expected_shortfall
      5 from .func_cca import cca

[/usr/local/lib/python3.7/dist-packages/frds/measures/func_dip.py](https://localhost:8080/#) in <module>
      1 import math
----> 2 from statistics import NormalDist
      3 import numpy as np
      4 from numpy.random import RandomState
      5 

ImportError: cannot import name 'NormalDist' from 'statistics' (/usr/lib/python3.7/statistics.py)

Your help is much appreciated!
Many thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.