quantstats icon indicating copy to clipboard operation
quantstats copied to clipboard

stats.py drawdown_details len(starts)>len(ends)

Open normanlmfung opened this issue 7 months ago • 0 comments

hi team,

I tracked it down: File "D:\prop\myscript.py", line 33, in qs.reports.basic( File "C:\Users\norman\AppData\Roaming\Python\Python39\site-packages\quantstats\reports.py", line 691, in basic metrics( File "C:\Users\norman\AppData\Roaming\Python\Python39\site-packages\quantstats\reports.py", line 820, in metrics dd = _calc_dd( File "C:\Users\norman\AppData\Roaming\Python\Python39\site-packages\quantstats\reports.py", line 1475, in _calc_dd dd_info = _stats.drawdown_details(dd) File "C:\Users\norman\AppData\Roaming\Python\Python39\site-packages\quantstats\stats.py", line 865, in drawdown_details _dfs[col] = _drawdown_details(drawdown[col]) File "C:\Users\norman\AppData\Roaming\Python\Python39\site-packages\quantstats\stats.py", line 828, in _drawdown_details dd = drawdown[starts[i] : ends[i]] IndexError: list index out of range

I suspect there's a bug in drawdown_details

def drawdown_details(drawdown):
	...
	 for i, _ in enumerate(starts):
        dd = drawdown[starts[i] : ends[i]]
        clean_dd = -remove_outliers(-dd, 0.99)
        data.append(
            (
                starts[i],
                dd.idxmin(),
                ends[i],
                (ends[i] - starts[i]).days + 1,
                dd.min() * 100,
                clean_dd.min() * 100,
            )
        )

It below up when i = 17, this is when I found out len(starts) > len(ends) len(list(starts)): 19 len(list(ends)): 17

The temporary local fix I have for this is: min_len = min(len(list(starts)), len(list(ends))) for i in range(min_len): dd = drawdown[starts[i] : ends[i]]

Thanks

normanlmfung avatar May 02 '25 01:05 normanlmfung