Hello,
i would like to create a pyfolio from alphalens results. However i'm getting an TypeError.
Is there another way to create pyfolio from alphalens? I can't find something in the documentation.
from zipline.research import run_pipeline, get_forward_returns
import pyfolio
import alphalens as al
my_pipe = make_pipeline()
pipe = run_pipeline(my_pipe, start_date="2019-04-01", end_date="2022-08-31")
forward_returns = get_forward_returns(factor=pipe['factor'], periods=[1,5])
factor_data = al.utils.get_clean_factor(
pipe['factor'],
forward_returns,
quantiles=5
)
# al.tears.create_full_tear_sheet(factor_data, group_neutral=False, by_group=False) # works
pf_returns, pf_positions, pf_benchmark = \
al.performance.create_pyfolio_input(factor_data,
period='1D',
#capital=100000,
#long_short=True,
#group_neutral=False,
#equal_weight=True,
#quantiles=[1,5],
#groups=None,
#benchmark_period='1D'
)
# TypeError: factor_weights() got an unexpected keyword argument 'group_neutral'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [48], in <cell line: 6>()
1 import pyfolio
2 import alphalens
5 pf_returns, pf_positions, pf_benchmark = \
----> 6 alphalens.performance.create_pyfolio_input(factor_data,
7 period='1D',
8 #capital=100000,
9 #long_short=True,
10 #group_neutral=False,
11 #equal_weight=True,
12 #quantiles=[1,5],
13 #groups=None,
14 #benchmark_period='1D'
15 )
File /opt/conda/lib/python3.9/site-packages/alphalens/performance.py:1196, in create_pyfolio_input(factor_data, period, capital, long_short, group_neutral, group_name, equal_weight, quantiles, groups, benchmark_period)
1189 returns = cumrets.pct_change().fillna(0)
1191 #
1192 # Build positions. As pyfolio asks for daily position we have to resample
1193 # the positions returned by 'factor_positions' at 1 day frequency and
1194 # recompute the weights so that the sum of daily weights is 1.0
1195 #
-> 1196 positions = factor_positions(
1197 factor_data,
1198 period=period,
1199 long_short=long_short,
1200 group_neutral=group_neutral,
1201 group_name=group_name,
1202 equal_weight=equal_weight,
1203 quantiles=quantiles,
1204 groups=groups)
1205 positions = positions.resample('1D').sum().fillna(method='ffill')
1206 positions = positions.div(positions.abs().sum(axis=1), axis=0).fillna(0)
File /opt/conda/lib/python3.9/site-packages/alphalens/performance.py:1063, in factor_positions(factor_data, period, long_short, group_neutral, group_name, equal_weight, quantiles, groups)
1059 if groups is not None:
1060 portfolio_data = portfolio_data[portfolio_data[group_name].isin(groups)]
1062 weights = \
-> 1063 factor_weights(
1064 portfolio_data,
1065 demeaned=long_short,
1066 group_neutral=group_neutral,
1067 group_name=group_name,
1068 equal_weight=equal_weight)
1070 return positions(weights, period)
TypeError: factor_weights() got an unexpected keyword argument 'group_neutral'