Skip to content

Commit 690918f

Browse files
committed
test: add test for historic_tick_size with small numbers
part of freqtrade#12054
1 parent de5dd66 commit 690918f

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

tests/data/test_historic_precision.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,94 @@ def test_get_tick_size_over_time_real_data(testdatadir):
9090

9191
assert all(result <= 0.0001)
9292
assert all(result >= 0.00000001)
93+
94+
95+
def test_get_tick_size_over_time_small_numbers():
96+
"""
97+
Test the get_tick_size_over_time function with predefined data
98+
"""
99+
# Create test dataframe with different levels of precision
100+
data = {
101+
"date": [
102+
Timestamp("2020-01-01 00:00:00", tz=UTC),
103+
Timestamp("2020-01-02 00:00:00", tz=UTC),
104+
Timestamp("2020-01-03 00:00:00", tz=UTC),
105+
Timestamp("2020-01-15 00:00:00", tz=UTC),
106+
Timestamp("2020-01-16 00:00:00", tz=UTC),
107+
Timestamp("2020-01-31 00:00:00", tz=UTC),
108+
Timestamp("2020-02-01 00:00:00", tz=UTC),
109+
Timestamp("2020-02-15 00:00:00", tz=UTC),
110+
Timestamp("2020-03-15 00:00:00", tz=UTC),
111+
],
112+
"open": [
113+
1.23456e-07,
114+
1.234e-07,
115+
1.23e-07,
116+
1.2e-07,
117+
1.23456e-07,
118+
1.234e-07,
119+
2.3456e-07,
120+
2.34e-07,
121+
2.34e-07,
122+
],
123+
"high": [
124+
1.23457e-07,
125+
1.235e-07,
126+
1.24e-07,
127+
1.3e-07,
128+
1.23456e-07,
129+
1.235e-07,
130+
2.3457e-07,
131+
2.34e-07,
132+
2.34e-07,
133+
],
134+
"low": [
135+
1.23455e-07,
136+
1.233e-07,
137+
1.22e-07,
138+
1.1e-07,
139+
1.23456e-07,
140+
1.233e-07,
141+
2.3455e-07,
142+
2.34e-07,
143+
2.34e-07,
144+
],
145+
"close": [
146+
1.23456e-07,
147+
1.234e-07,
148+
1.23e-07,
149+
1.2e-07,
150+
1.23456e-07,
151+
1.234e-07,
152+
2.3456e-07,
153+
2.34e-07,
154+
2.34e-07,
155+
],
156+
"volume": [100, 200, 300, 400, 500, 600, 700, 800, 900],
157+
}
158+
159+
candles = DataFrame(data)
160+
161+
# Calculate significant digits
162+
result = get_tick_size_over_time(candles)
163+
164+
# Check that the result is a pandas Series
165+
assert isinstance(result, pd.Series)
166+
167+
# Check that we have three months of data (Jan, Feb and March 2020 )
168+
assert len(result) == 3
169+
170+
# Before
171+
assert result.asof("2019-01-01 00:00:00+00:00") is nan
172+
# January should have 5 significant digits (based on 1.23456789 being the most precise value)
173+
# which should be converted to 0.00001
174+
175+
assert result.asof("2020-01-01 00:00:00+00:00") == 0.000000000001
176+
assert result.asof("2020-01-01 00:00:00+00:00") == 0.000000000001
177+
assert result.asof("2020-02-25 00:00:00+00:00") == 0.00000000001
178+
assert result.asof("2020-03-25 00:00:00+00:00") == 0.000000001
179+
assert result.asof("2020-04-01 00:00:00+00:00") == 0.000000001
180+
# Value far past the last date should be the last value
181+
assert result.asof("2025-04-01 00:00:00+00:00") == 0.000000001
182+
183+
assert result.iloc[0] == 0.000000000001

0 commit comments

Comments
 (0)