hudson-and-thames / mlfinlab

MlFinLab helps portfolio managers and traders who want to leverage the power of machine learning by providing reproducible, interpretable, and easy to use tools.
Other
3.91k stars 1.14k forks source link

Triple barrier events code returning IndexError 0 out of bounds #531

Open the57chambers opened 1 year ago

the57chambers commented 1 year ago

Running through the triple barrier labeling process, the code keeps getting an error

"IndexError: index 0 is out of bounds for axis 0 with size 0" - i take it this means it is trying to pull from an empty dataframe, but i have checked each of the inputs (cusum, ptsl, target,verticalbarriertimes, ES and Side) and they all have data. there are also no NaN, inf, NaT or other blank values or error in the dataframe. Any idea what could be causing this?

Code:

triple_barrier_events = ml.labeling.get_events(close=data['ES'], t_events=cusum_events, pt_sl=pt_sl, target=daily_vol, min_ret=min_ret, num_threads=3, vertical_barrier_times=vertical_barriers, side_prediction=data['side'])

Jackal08 commented 1 year ago

Have you checked for duplicates in the index?

the57chambers commented 1 year ago

Yes, i ran numerous functions to remove problematic values but am still getting the same error, see below for the adjustments i tried: data = data.dropna() cusum_events = cusum_events.dropna() vertical_barriers = vertical_barriers.dropna() daily_vol = daily_vol.dropna() data = data.drop_duplicates() cusum_events = cusum_events.drop_duplicates() daily_vol = daily_vol.drop_duplicates()