backtrader和pyfolio都移除了储存图片的参数,所以要另外修改源码。
1. backtrader
img = cerebro.plot(style='line', plotdist=0.1, grid=True) img[0][0].savefig(f'data/cerebro_{sector}_{direction[0]}_{style[0]}_{date_cur}.png')
返回了plot实体,再储存。
2. pyfolio
images = [] images.append(create_returns_tear_sheet( returns, positions=positions, transactions=transactions, live_start_date=live_start_date, cone_std=cone_std, benchmark_rets=benchmark_rets, bootstrap=bootstrap, turnover_denom=turnover_denom, header_rows=header_rows, set_context=set_context, return_fig=True)) images.append(create_interesting_times_tear_sheet(returns, benchmark_rets=benchmark_rets, set_context=set_context, return_fig=True))
Lib\site-packages\pofolio\tears.py Line 201~218
Return the array of plot entities.
images = pf.create_full_tear_sheet(returns) images[0].savefig(f'data/returns_tear_sheet_{sector}_{direction[0]}_{style[0]}_{date_cur}.png') images[1].savefig(f'data/interesting_times_tear_sheet_{sector}_{direction[0]}_{style[0]}_{date_cur}.png')
返回了plot实体,再储存。