This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# high-low spread estimator (hlse) | |
def hlse(ohlc_df, frequency='daily'): | |
""" | |
Computes the high-low spread estimator, an estimate of bid-offer spreads, a measure of liquidity risk. | |
See Corwin & Schultz (2011) for details: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=1106193 | |
Parameters | |
---------- | |
ohlc_df: DataFrame | |
DataFrame with DatetimeIndex and Open, High, Low and Close (OHLC) prices from which to compute the high-low spread estimates. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# orthogonalization of correlated factors in a multifactor model | |
def orthogonalize_factors(factors_df, output_format='df'): | |
""" | |
As described by Klein and Chow (2013) in Orthogonalized Factors and Systematic Risk Decompositions: | |
https://www.sciencedirect.com/science/article/abs/pii/S1062976913000185 | |
They propose an optimal simultaneous orthogonal transformation of factors, following the so-called symmetric procedure | |
of Schweinler and Wigner (1970) and Löwdin (1970). The data transformation allows the identification of the underlying uncorrelated | |
components of common factors without changing their correlation with the original factors. It also facilitates the systematic risk | |
decomposition by disentangling the coefficient of determination (R²) based on factors' volatilities, which makes it easier to distinguish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This function takes observable macro factors (surprises) as inputs and creates macro factor mimicking portfolios (MFMPs) as outputs. It uses | |
a novel machine-learning approach, the Principal Components Instrumental Variables FMP Estimator, | |
described by Jurczenko and Teiletche (2020) in Macro Factor-Micking Portfolios: | |
https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3363598 | |
The methodology addresses many of the common problems associated with macro factors and multifactor risk modeling and, as they show, | |
is superior to other common FMP approaches. | |
We describe the steps of the PCIV algorithm below, as well as in our Medium post: | |
For a more detailed explanation, see the link to the paper above. | |
Note that access to macroeconomic and base assets is required to estimate macro factor-mimicking portfolios. See the macro factors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import logging | |
# initialize binance client | |
client = Client(os.environ.get('BINANCE_API_KEY'), os.environ.get('BINANCE_API_SECRET')) | |
# get metadata from binance exchange | |
def get_metadata_bin(quote='usdt', as_list=False): |