@@ -99,11 +99,23 @@ def _maybe_resample_data(resample_rule, df, indicators, equity_data, trades):
99
99
if resample_rule is False or len (df ) <= _MAX_CANDLES :
100
100
return df , indicators , equity_data , trades
101
101
102
- from_index = dict (day = - 2 , hour = - 6 , minute = 1 , second = 0 , millisecond = 0 ,
103
- microsecond = 0 , nanosecond = 0 )[df .index .resolution ]
104
- FREQS = ('1T' , '5T' , '10T' , '15T' , '30T' , '1H' , '2H' , '4H' , '8H' , '1D' , '1W' , '1M' )
105
- freq = next ((f for f in FREQS [from_index :]
106
- if len (df .resample (f )) <= _MAX_CANDLES ), FREQS [- 1 ])
102
+ freq_minutes = pd .Series ({
103
+ "1T" : 1 ,
104
+ "5T" : 5 ,
105
+ "10T" : 10 ,
106
+ "15T" : 15 ,
107
+ "30T" : 30 ,
108
+ "1H" : 60 ,
109
+ "2H" : 60 * 2 ,
110
+ "4H" : 60 * 4 ,
111
+ "8H" : 60 * 8 ,
112
+ "1D" : 60 * 24 ,
113
+ "1W" : 60 * 24 * 7 ,
114
+ "1M" : np .inf ,
115
+ })
116
+ timespan = df .index [- 1 ] - df .index [0 ]
117
+ require_minutes = (timespan / _MAX_CANDLES ).total_seconds () // 60
118
+ freq = freq_minutes .where (freq_minutes >= require_minutes ).first_valid_index ()
107
119
warnings .warn (f"Data contains too many candlesticks to plot; downsampling to { freq !r} . "
108
120
"See `Backtest.plot(resample=...)`" )
109
121
0 commit comments