Open shrikantad opened 10 months ago
It might be a problem with the data. I was testing my own implementation of the GK estimator on a futures dataset including the EuroBond, and I got nan results because the H / L term was smaller than the C / C term, resulting in negative values which were nan when passed through the square root. The issue also came up in the NK, Z, and G contracts. If you look at the formula, there is nothing stopping it from breaking if the H / L spread is small enough.
Implement the formula yourself and test to see if this is the problem.
Description When using the
garman_klass
function frommlfinlab
version 2.3.0 on a dataset with 31 OHLC entries, I expected to receive a non-empty series with volatility estimates (exactly 1 value to be precise). Instead, the function returned an empty series and issued aRuntimeWarning
related to an invalid value encountered in a square root operation. This unexpected behavior suggests that there may be a bug in the function's handling of the input data or within the computation itself.To Reproduce
pip install mlfinlab==2.3.0
).garman_klass
function with the DataFrame and a window size of 30.Expected behavior The
garman_klass
function should compute and return a Pandas Series with at least one volatility estimate based on the provided OHLC data.Actual Behavior The function returns an empty Pandas Series and raises the following warning:
Environment Operating System: Windows 11 (Version 23H2, OS Build 22631.3085) Python Version: 3.9.18 mlfinlab Version: 2.3.0 Pandas Version: 2.0.0
Attachments ohlc_data.csv
ohlc_data.csv (attached) containing the dataset used when encountering the issue. I have obtained this data from Quantconnect (Basic S&P500 ETF TradeBar data for 31 days in 2016)
Additional context The attached CSV file contains the OHLC data that replicates the issue. The dataset includes 31 rows of OHLCV data, which should be sufficient for the
garman_klass
function to calculate at least one value based on the window size of 30.