Closed hexiaoling1994 closed 5 years ago
Thank you for reporting this @hexiaoling1994.
@hexiaoling1994 Could you also make sure you are using the latest Alphalens version 3.2?
>>> import alphalens
>>> alphalens.__version__
'0.3.2'
I checked the versions and updated numpy, pandas, alphalens to the latest.
And I tried:
factor_data = alphalens.utils.get_clean_factor_and_forward_returns(
factor, prices, groupby, by_group=False,
quantiles=10, bins=None, periods=(2,5,8))
Another error happened, which also seems highly related to frequency of index:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-31-68a918e79fe3> in <module>()
1 factor_data = alphalens.utils.get_clean_factor_and_forward_returns(
2 factor, prices, groupby, by_group=False,
----> 3 quantiles=10, bins=None, periods=(2,5,8))
F:\Anaconda3\lib\site-packages\alphalens\utils.py in call_w_context(*args, **kwargs)
609 "replaced by 'binning_by_group'",
610 category=DeprecationWarning, stacklevel=3)
--> 611 return func(*args, **kwargs)
612 return call_w_context
613
F:\Anaconda3\lib\site-packages\alphalens\utils.py in get_clean_factor_and_forward_returns(factor, prices, groupby, binning_by_group, quantiles, bins, periods, filter_zscore, groupby_labels, max_loss)
762
763 forward_returns = compute_forward_returns(factor, prices, periods,
--> 764 filter_zscore)
765
766 factor_data = get_clean_factor(factor, forward_returns, groupby=groupby,
F:\Anaconda3\lib\site-packages\alphalens\utils.py in compute_forward_returns(factor, prices, periods, filter_zscore)
281 start = prices.index[p_idx]
282 end = prices.index[p_idx + period]
--> 283 period_len = diff_custom_calendar_timedeltas(start, end, freq)
284 days_diffs.append(period_len.components.days)
285
F:\Anaconda3\lib\site-packages\alphalens\utils.py in diff_custom_calendar_timedeltas(start, end, freq)
920 if weekmask is not None and holidays is not None:
921 # we prefer this method as it is faster
--> 922 actual_days = np.busday_count(start, end, weekmask, holidays)
923 else:
924 # default, it is slow
TypeError: Iterator operand 0 dtype could not be cast from dtype('<M8[us]') to dtype('<M8[D]') according to the rule 'safe'
Here's how the index looks like, I can't tell which part of it was wrong...
>>>factor.index.levels[0]
DatetimeIndex(['2016-01-04', '2016-01-05', '2016-01-06', '2016-01-07',
'2016-01-08', '2016-01-11', '2016-01-12', '2016-01-13',
'2016-01-14', '2016-01-15',
...
'2018-08-13', '2018-08-14', '2018-08-15', '2018-08-16',
'2018-08-17', '2018-08-20', '2018-08-21', '2018-08-22',
'2018-08-23', '2018-08-24'],
dtype='datetime64[ns]', name='DATES', length=690, freq='B')
the other inputs also seemed ok...
I am closing this since no answer to my questions were provided. If you still have the issue feel free to re-open this but please answer those questions:
Hi,
I'm running into same exact issue. Getting it while running the simplest example notebook.
Pandas is 0.23.4, numpy is 1.15.3.
Cheers mate.
Here's the thing, I was dealing with a problem caused by
pandas.datetimeindex.frequency
The api returned clean factor successfully, and I checked the .freq attribute, it seems in accordance with my input factor data:
when I ran:
I got the error:
Seems the problem was caused by internal attribute weights. Any way I can fix this?