Backtesting with pd.Timestamp works but pyfolio fails using the same

95 views
Skip to first unread message

Tanul Shankushal

unread,
Jul 8, 2022, 4:57:39 AM7/8/22
to Zipline Python Opensource Backtester
Hello
When using the pd.Timestamp, backtesting is working well... 
why is it throwing the error in analysing the performance??

For example:

I have fetched the data from 

yfinance as follows

import yfinance as yf 
start = pd.Timestamp('2020-4-1',tz ='utc') 
 end =pd.Timestamp('2022-4-1',tz ='utc') 
 bench['Index_return'] = bench['Adj Close'].pct_change(1) 
bench['cum_returns'] = bench['Index_return'].cumsum() 
bench.index = bench.index.tz_localize('UTC') 

returns, positions, transactions = pf.utils.extract_rets_pos_txn_from_zipline(perf) pf.create_returns_tear_sheet(returns, benchmark_rets=bench['Index_return'])

It is throwing an error as: 
ERROR: KeyError: "[Timestamp('2020-07-03 00:00:00+0000', tz='UTC'), Timestamp('2020-09-07 00:00:00+0000', tz='UTC'), Timestamp('2020-11-26 00:00:00+0000', tz='UTC'), Timestamp('2021-01-01 00:00:00+0000', tz='UTC'), Timestamp('2021-01-18 00:00:00+0000', tz='UTC'), Timestamp('2021-02-15 00:00:00+0000', tz='UTC'), Timestamp('2021-05-31 00:00:00+0000', tz='UTC'), Timestamp('2021-07-05 00:00:00+0000', tz='UTC'), Timestamp('2021-09-06 00:00:00+0000', tz='UTC'), Timestamp('2021-11-25 00:00:00+0000', tz='UTC'), Timestamp('2021-12-24 00:00:00+0000', tz='UTC'), Timestamp('2022-01-17 00:00:00+0000', tz='UTC'), Timestamp('2022-02-21 00:00:00+0000', tz='UTC')] not in index"

Nam Mai

unread,
Aug 10, 2022, 4:43:44 AM8/10/22
to Zipline Python Opensource Backtester
the data at that time point is missing I guess. 

Vào lúc 09:57:39 UTC+1 ngày Thứ Sáu, 8 tháng 7, 2022, tanu...@gmail.com đã viết:
Reply all
Reply to author
Forward
0 new messages