How to access daily returns parameter of backtestid that is passed to create_full_tear_sheet
How to access daily returns parameter of backtestid that is passed to create_full_tear_sheet
To get info about a backtest first get the backtest object using the backtest ID
bt = get_backtest('5c01756710cac949d6949c0c')
The backtest id is the last part of the URL when displaying a backtest. That is the string in parenthesis.
To specifically get the daily returns
return_series = bt.daily_performance.returns
The 'daily_performance' attribute returns a dataframe with a number of interesting columns. One of those columns is 'returns'. The above code simply fetches that column. For a lot of information on how to use the backtest object type the following in a notebook
help(bt)
This will display the docstring for the backtest object which includes the several ways to display returns.
Hope that helped.
Dan thanks a lot for answering my question. As always your insights into the Quantopian platform are very helpful.
Dan, was wondering if you could help me with something-- when I run the following it only shows a few of the dates at the beginning of the test and a few of the dates at the end of the test. The vast majority of the data is truncated out.
bt = get_backtest('xxxxxxsamplexxxxxx')
return_series = bt.daily_performance.returns
print return_series
Do you know how I can get it to not truncate the data? Thanks for any help!
@Ryan
Remember that all the data is actually there, it's just truncated for display purposes. One can always plot the data for example and see all the results.
Normally, to set how much of a pandas series or datafame to show one would use the pandas method pd.set_option('display.max_rows', xx)
(see https://pandas.pydata.org/pandas-docs/version/0.18.0/generated/pandas.set_option.html ). However, the Quantopian implementation of pandas within a notebook doesn't seem to implement this method (probably for security?). So, this straightforward way to show more rows doesn't work.
Another method is to use qgrid
import qgrid
qgrid.show_grid(return_series)
That will show all the rows in a nice interactive scrollable, sortable, filterable cell (see https://www.quantopian.com/posts/qgrid-now-available-in-research-an-interactive-grid-for-sorting-and-filtering-dataframes). While qgrid will display all the data it cannot be easily copied to 'cut and paste' the data into another app. If the goal is to show more data so one can copy it then there are some hacks. Is that part of the goal?