|
quantlab5.4
试图运行bt-可转债-因子分析-KDJ.ipynb下面段落做Alphalens的数据预处理时老是报错。在ailabx.com/quant网页上运行因子分析则没有问题。
不知道是不是Alphalens的依赖库更新了不支持造成的?有人知道咋整吗?
from alphalens.utils import get_clean_factor_and_forward_returns
#将tears.py中的get_values()函数改为to_numpy()
ret = get_clean_factor_and_forward_returns(factor, data)
ret
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Cell In[7], line 3
1 from alphalens.utils import get_clean_factor_and_forward_returns
2 #将tears.py中的get_values()函数改为to_numpy()
----> 3 ret = get_clean_factor_and_forward_returns(factor, data)
4 ret
File D:\Documents\My_Python_Script\quantlib5\venv\lib\site-packages\alphalens\utils.py:834, 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)
673 def get_clean_factor_and_forward_returns(factor,
674 prices,
675 groupby=None,
(...)
683 zero_aware=False,
684 cumulative_returns=True):
685 """
686 Formats the factor data, pricing data, and group mappings into a DataFrame
687 that contains aligned MultiIndex indices of timestamp and asset. The
(...)
832 For use when forward returns are already available.
833 """
--> 834 forward_returns = compute_forward_returns(
835 factor,
836 prices,
837 periods,
838 filter_zscore,
839 cumulative_returns,
840 )
842 factor_data = get_clean_factor(factor, forward_returns, groupby=groupby,
843 groupby_labels=groupby_labels,
844 quantiles=quantiles, bins=bins,
845 binning_by_group=binning_by_group,
846 max_loss=max_loss, zero_aware=zero_aware)
848 return factor_data
File D:\Documents\My_Python_Script\quantlib5\venv\lib\site-packages\alphalens\utils.py:326, in compute_forward_returns(factor, prices, periods, filter_zscore, cumulative_returns)
324 print("days_diffs:", days_diffs)
325 print("mode_result.mode:", mode_result.mode)
--> 326 delta_days = period_len.components.days - mode(days_diffs).mode[0]
327 period_len -= pd.Timedelta(days=delta_days)
328 label = timedelta_to_string(period_len)
IndexError: invalid index to scalar variable.
|
|