mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-02-19 02:40:58 +00:00
feat: add function to count "significant digits over time".
This commit is contained in:
@@ -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,
|
||||
|
||||
27
freqtrade/data/btanalysis/historic_precision.py
Normal file
27
freqtrade/data/btanalysis/historic_precision.py
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user