Back to Community
Error using get_clean_factor_and_forward_returns

Hi,

I'm trying to use the get_clean_factor_and_forward_returns function but have an error that I can't fix. I tried to look up the doc but was unsuccessful in finding the answer.

Thanks in advance.

Here is the error:

AttributeErrorTraceback (most recent call last)
in ()
7 prices=asset_prices,
8 quantiles=2,
----> 9 periods=(1,5,10),
10
11 )

/usr/local/lib/python2.7/dist-packages/alphalens/utils.pyc in get_clean_factor_and_forward_returns(factor, prices, groupby, binning_by_group, quantiles, bins, periods, filter_zscore, groupby_labels, max_loss, zero_aware, cumulative_returns) 791 forward_returns = compute_forward_returns(factor, prices, periods,
792 filter_zscore,
--> 793 cumulative_returns)
794
795 factor_data = get_clean_factor(factor, forward_returns, groupby=groupby,

/usr/local/lib/python2.7/dist-packages/alphalens/utils.pyc in compute_forward_returns(factor, prices, periods, filter_zscore, cumulative_returns) 318 days_diffs.append(period_len.components.days)
319
--> 320 delta_days = period_len.components.days - mode(days_diffs).mode[0]
321 period_len -= pd.Timedelta(days=delta_days)
322 label = timedelta_to_string(period_len)

AttributeError: 'tuple' object has no attribute 'mode'

Loading notebook preview...
Notebook previews are currently unavailable.
1 response

You have specified periods of 1,3,10 but do not have enough data for the function to look that many days in the future.
You need to ensure the data in 'assets_prices' include enough future dates for the prediction to work.

Try changing the start and end dates to a date in the past, then in Asset prices, use an end date at least 10 days after your end date.