quantopian / alphalens

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

When I use "bins" instead of "quantiles", it went wrong #387

Open Ryan17wow opened 3 years ago

Ryan17wow commented 3 years ago

Problem Description

Please provide a minimal, self-contained, and reproducible example:

[factor_data = alphalens.utils.get_clean_factor_and_forward_returns(convpre,close,bins=[-10,-5,-1,0,10],periods=[1,5,10,20])]

Please provide the full traceback:

[ValueError                                Traceback (most recent call last)
<ipython-input-37-bcea1a6e8ef9> in <module>
----> 1 factor_data = alphalens.utils.get_clean_factor_and_forward_returns(convpre,close,bins=[-10,-5,-1,0,10],periods=[1,5,10,20])
      2 alphalens.tears.create_full_tear_sheet(factor_data)

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/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, zero_aware, cumulative_returns)
    837                                    quantiles=quantiles, bins=bins,
    838                                    binning_by_group=binning_by_group,
--> 839                                    max_loss=max_loss, zero_aware=zero_aware)
    840 
    841     return factor_data

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/alphalens/utils.py in get_clean_factor(factor, forward_returns, groupby, binning_by_group, quantiles, bins, groupby_labels, max_loss, zero_aware)
    636         binning_by_group,
    637         no_raise,
--> 638         zero_aware
    639     )
    640 

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/alphalens/utils.py in dec(*args, **kwargs)
     74     def dec(*args, **kwargs):
     75         try:
---> 76             return func(*args, **kwargs)
     77         except ValueError as e:
     78             if 'Bin edges must be unique' in str(e):

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/alphalens/utils.py in quantize_factor(factor_data, quantiles, bins, by_group, no_raise, zero_aware)
    129     if not ((quantiles is not None and bins is None) or
    130             (quantiles is None and bins is not None)):
--> 131         raise ValueError('Either quantiles or bins should be provided')
    132 
    133     if zero_aware and not (isinstance(quantiles, int)

ValueError: Either quantiles or bins should be provided]

Please provide any additional information below:

Versions