quantopian / alphalens

Performance analysis of predictive (alpha) stock factors
http://quantopian.github.io/alphalens
Apache License 2.0
3.26k stars 1.13k forks source link

Unhelpful error message if prices and signals do not match #282

Closed twiecki closed 6 years ago

twiecki commented 6 years ago

When passing in signals and prices that either don't have the same convention in terms of datetimes or symbol-names this is the error message:

/opt/virtualenv/python2/local/lib/python2.7/site-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)
    533 
    534     merged_data = compute_forward_returns(factor_dateindex, prices, periods,
--> 535                                           filter_zscore)
    536     merged_data['factor'] = factor
    537 

/opt/virtualenv/python2/local/lib/python2.7/site-packages/alphalens/utils.pyc in compute_forward_returns(factor_idx, prices, periods, filter_zscore)
    245             days_diffs.append(period_len.components.days)
    246 
--> 247         delta_days = period_len.components.days - mode(days_diffs).mode[0]
    248         period_len -= pd.Timedelta(days=delta_days)
    249 

UnboundLocalError: local variable 'period_len' referenced before assignment

Should be helpful to detect that no signals and prices can be matched and display a clear error message.