diff --git a/freqtrade/data/btanalysis/__init__.py b/freqtrade/data/btanalysis/__init__.py index 48fdcd9b5..520568558 100644 --- a/freqtrade/data/btanalysis/__init__.py +++ b/freqtrade/data/btanalysis/__init__.py @@ -25,6 +25,7 @@ from .bt_fileutils import ( trade_list_to_dataframe, update_backtest_metadata, ) +from .historic_precision import get_significant_digits_over_time from .trade_parallelism import ( analyze_trade_parallelism, evaluate_result_multi, diff --git a/freqtrade/data/btanalysis/historic_precision.py b/freqtrade/data/btanalysis/historic_precision.py new file mode 100644 index 000000000..96d12ba68 --- /dev/null +++ b/freqtrade/data/btanalysis/historic_precision.py @@ -0,0 +1,27 @@ +from pandas import DataFrame, Series + + +def get_significant_digits_over_time(candles: DataFrame) -> Series: + """ + Calculate the number of significant digits for candles over time. + It's using the Monthly maximum of the number of significant digits for each month. + :param candles: DataFrame with OHLCV data + :return: Series with the average number of significant digits for each month + """ + # count the number of significant digits for the open and close prices + for col in ["open", "high", "low", "close"]: + candles[f"{col}_count"] = ( + candles[col].round(14).astype(str).str.extract(r"\.(\d*[1-9])")[0].str.len() + ) + candles["max_count"] = candles[["open_count", "close_count", "high_count", "low_count"]].max( + axis=1 + ) + + candles1 = candles.set_index("date", drop=True) + # Group by month and calculate the average number of significant digits + monthly_count_avg1 = candles1["max_count"].resample("ME").max() + # monthly_open_count_avg + # convert monthly_open_count_avg from 5.0 to 0.00001, 4.0 to 0.0001, ... + monthly_open_count_avg = 1 / 10**monthly_count_avg1 + + return monthly_open_count_avg