Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Span and Timestamp Error #497

Open
cl7805 opened this issue May 27, 2021 · 3 comments
Open

Span and Timestamp Error #497

cl7805 opened this issue May 27, 2021 · 3 comments
Labels
question Further information is requested

Comments

@cl7805
Copy link

cl7805 commented May 27, 2021

Hi, marvellous explanation above. The example given in the book is intraday. I'm doing swing trading amd I'm stuck on the distinction between Timedelta and span. What does span=100 mean?
2nd, I have a KeyError on Timestamp using yahoo finance, does it mean I should discard it as I assume it means it is missing data?

@PanPip PanPip self-assigned this Jun 8, 2021
@PanPip PanPip added the question Further information is requested label Jun 8, 2021
@PanPip
Copy link
Contributor

PanPip commented Jun 8, 2021

Hi @cl7805,

Thank you for reaching out. Could you please describe to which MlFinLab module/function are you referring?

Or is the question only related to the "Advances in Financial Machine Learning" book?

@cl7805
Copy link
Author

cl7805 commented Jun 23, 2021

@cl7805
Copy link
Author

cl7805 commented Jun 23, 2021

def get_horizons(prices, delta=pd.Timedelta(days=1)):
t1 = prices.index.searchsorted(prices.index + delta)
t1 = t1[t1 < prices.shape[0]]
t1 = prices.index[t1]
t1 = pd.Series(t1, index=prices.index[:t1.shape[0]])
return t1

data_ohlc = data
data_ohlc =
data_ohlc.assign(threshold=get_vol(data_ohlc.Close)).dropna()
t1=get_horizons(data_ohlc)
data_ohlc = data_ohlc.assign(t1=get_horizons(data_ohlc)).dropna()
events = data_ohlc[['t1', 'threshold']]
events = events.assign(side=pd.Series(1, events.index)) # long only <---where the problem is highlighted
touches = get_touches(data_ohlc.Close, events, [1,1])
touches = get_labels(touches)
data_ohlc = data_ohlc.assign(label=touches.label)


KeyError Traceback (most recent call last)

/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2897 try:
-> 2898 return self._engine.get_loc(casted_key)
2899 except KeyError as err:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: Timestamp('2018-04-18 00:00:00')

The above exception was the direct cause of the following exception:

KeyError Traceback (most recent call last)

3 frames

/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2898 return self._engine.get_loc(casted_key)
2899 except KeyError as err:
-> 2900 raise KeyError(key) from err
2901
2902 if tolerance is not None:

KeyError: Timestamp('2018-04-18 00:00:00')

@PanPip PanPip removed their assignment Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants