test: add test for historic_tick_size with small numbers

part of #12054
This commit is contained in:
Matthias
2025-08-02 09:38:37 +02:00
parent de5dd66512
commit 690918f8d3

View File

@@ -90,3 +90,94 @@ def test_get_tick_size_over_time_real_data(testdatadir):
assert all(result <= 0.0001)
assert all(result >= 0.00000001)
def test_get_tick_size_over_time_small_numbers():
"""
Test the get_tick_size_over_time function with predefined data
"""
# Create test dataframe with different levels of precision
data = {
"date": [
Timestamp("2020-01-01 00:00:00", tz=UTC),
Timestamp("2020-01-02 00:00:00", tz=UTC),
Timestamp("2020-01-03 00:00:00", tz=UTC),
Timestamp("2020-01-15 00:00:00", tz=UTC),
Timestamp("2020-01-16 00:00:00", tz=UTC),
Timestamp("2020-01-31 00:00:00", tz=UTC),
Timestamp("2020-02-01 00:00:00", tz=UTC),
Timestamp("2020-02-15 00:00:00", tz=UTC),
Timestamp("2020-03-15 00:00:00", tz=UTC),
],
"open": [
1.23456e-07,
1.234e-07,
1.23e-07,
1.2e-07,
1.23456e-07,
1.234e-07,
2.3456e-07,
2.34e-07,
2.34e-07,
],
"high": [
1.23457e-07,
1.235e-07,
1.24e-07,
1.3e-07,
1.23456e-07,
1.235e-07,
2.3457e-07,
2.34e-07,
2.34e-07,
],
"low": [
1.23455e-07,
1.233e-07,
1.22e-07,
1.1e-07,
1.23456e-07,
1.233e-07,
2.3455e-07,
2.34e-07,
2.34e-07,
],
"close": [
1.23456e-07,
1.234e-07,
1.23e-07,
1.2e-07,
1.23456e-07,
1.234e-07,
2.3456e-07,
2.34e-07,
2.34e-07,
],
"volume": [100, 200, 300, 400, 500, 600, 700, 800, 900],
}
candles = DataFrame(data)
# Calculate significant digits
result = get_tick_size_over_time(candles)
# Check that the result is a pandas Series
assert isinstance(result, pd.Series)
# Check that we have three months of data (Jan, Feb and March 2020 )
assert len(result) == 3
# Before
assert result.asof("2019-01-01 00:00:00+00:00") is nan
# January should have 5 significant digits (based on 1.23456789 being the most precise value)
# which should be converted to 0.00001
assert result.asof("2020-01-01 00:00:00+00:00") == 0.000000000001
assert result.asof("2020-01-01 00:00:00+00:00") == 0.000000000001
assert result.asof("2020-02-25 00:00:00+00:00") == 0.00000000001
assert result.asof("2020-03-25 00:00:00+00:00") == 0.000000001
assert result.asof("2020-04-01 00:00:00+00:00") == 0.000000001
# Value far past the last date should be the last value
assert result.asof("2025-04-01 00:00:00+00:00") == 0.000000001
assert result.iloc[0] == 0.000000000001