Skip to main content

Beta Adjusted Covariance estimation

Project description

Beta-Adjusted Covariance Estimation

Introduction

Exchange Traded Funds (ETFs) are often more liquid than many of their component stocks. We exploit this feature to improve pre-estimators of the integrated covariance of the stocks included in the ETF. The proposed Beta Adjusted Covariance (BAC) equals the pre-estimator plus a minimal adjustment matrix such that the covariance-implied stock-ETF beta equals a target beta.

The Authors

The package is based upon the reaserch and the results of Beta Adjusted Covariance Estimation paper by Kris Boudt, Kirill Dragun, Orimar Sauri and Steven Vanduffel. The authors of the code are Kirill Dragun, Kris Boudt and Emil Sjørup.

Package

Installation

$ pip install bacpack

submodules and classes

  • highreq: high frequency trading data representation and processing functionality. Class HF_Returns defines integrated covariance matrix estimators as member functions :
    • bacpack.highfreq.HY() : computes Hayashi-Yoshida estimator;
    • bacpack.highfreq.RCov() : computes realized covariance estimator;
    • TSCov() : computes two time scale estimator.
  • bac: defines ETF related data structure HFR_ETF and Beta Adjusted Covariance Estimation functions:
    • bacpack.bac.HFR_ETF: extends HFReturns, adds ETF and BAC related functionality:
      • bacpack.bac.HFR_ETF.generate_from(aprices, mp, shnumb, nonequity, outstanding, etf_col):
        • aprices - Pandas DataFrame with prices for assets in columns, each row for unique tick time;
        • mp - Boolean array with True for the element traded at specified moment;
        • shnumb - an array with amounts of components/assets included in the ETF;
        • nonequity - aggregated value of the additional components (like cash, money-market funds, bonds, etc.), prices for which are not included in the aprices array;
        • outstanding - ETF shares outstanding;
        • etf_col - column name for the ETF.
      • bacpack.bac.BAC_Delta_NR(b0, b), implements non-restricted BAC:
        • b0 - implied pairwise beta of the pre-estimator;
        • b - target stock-ETF beta.
      • bacpack.bac.NBAC_Delta_NR(b0, b, noise), implements non-restricted NBAC, adjusted for noise effect :
        • b0 - implied pairwise beta of the pre-estimator;
        • b - target stock-ETF beta;
        • noise, cumulative noise variance of diagonal elements.
    • bacpack.bac.Sim_BN: extends HFR_ETF adding data generations functionality for the simulation purposes:
    • bacpack.bac.Sim_BN.generate(): generates data;
    • bacpack.bac.Sim_BN.gen_jmp(self, jumps_per_period, jump_magnitude): generates jumps
    • bacpack.bac.Sim_BN.noise(kappa): generates and adds microstructure noise with size given by kappa parameter.

toy example

import numpy as np
from bacpack.bac import Sim_BN

csim=Sim_BN(3,10000) # creating an instance of the simulation class for 3 assets and 10000 time points
csim.frequencies(10,0.2) #setting the frequencies of trades according to the simulation model
csim.generate() #generating trading data
### by now csim object of Sim_BN class contains fields with a simulated dataset 

mt=np.dot(csim.comps.T,csim.comps) #integrated covarinace matrix at highest precision to compare with
csim.noise(0.1) #generating microstructre noise
na_diag=csim.noise_var() # estimating noise variance           
m0_RC,b0_RC=csim.RCov() #returns RCov and implied beta                  
mweights=csim.meanw() #average weights
b0_RC_nf=b0_RC-na_diag*mweights   #beta adjusted for noise variance               
bHY=csim.beta_HY() # stock-ETF beta using Hayashi-Yoshida estimator
SBAC=m0_RC-csim.NBAC_Delta_NR(b0_RC_nf,bHY,na_diag) #BAC adjustment
print(csim.HY()[0]) #HY estimate of the integrated covariance matrix       
print(np.linalg.norm(mt-m0_RC)**2,np.linalg.norm(mt-SBAC)**2) # squared errors of the pre-estimator and BAC

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

bacpack-0.0.25.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

bacpack-0.0.25-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file bacpack-0.0.25.tar.gz.

File metadata

  • Download URL: bacpack-0.0.25.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.1 keyring/23.1.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for bacpack-0.0.25.tar.gz
Algorithm Hash digest
SHA256 6e155322a34f8c48df8ac5b13db6584c01bb77e8032941a97a49f13fd687f884
MD5 3dda20870d9ae48cd6d51922b899d541
BLAKE2b-256 53923178544c9c4cc1e138a935c02ef9344ad81309fecc3c6a8d420099db6c29

See more details on using hashes here.

File details

Details for the file bacpack-0.0.25-py3-none-any.whl.

File metadata

  • Download URL: bacpack-0.0.25-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.1 keyring/23.1.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for bacpack-0.0.25-py3-none-any.whl
Algorithm Hash digest
SHA256 9b7d9713d2297429455ec0be25e62857080a4c10c0acf3bd97837946629d9ca5
MD5 616d7b8c466836412a256f3eeff4d179
BLAKE2b-256 ac7baf54c721cb78a9fa87123c84b7be0639eaa4f6a203d7edf915fb36fb1ddc

See more details on using hashes here.

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