Path: blob/master/17_deep_learning/05_backtesting_with_zipline.ipynb
2923 views
Kernel: Python 3
Backtesting with zipline - Pipeline API with Custom Data
This notebook requires the
conda
environmentbacktest
. Please see the installation instructions for running the latest Docker image or alternative ways to set up your environment.
Imports & Settings
In [1]:
In [2]:
In [3]:
In [4]:
Alphalens Analysis
In [5]:
In [6]:
In [7]:
In [8]:
In [9]:
In [10]:
Out[10]:
Dropped 3.6% entries from factor data: 3.6% in forward returns computation and 0.0% in binning phase (set max_loss=0 to see potentially suppressed Exceptions).
max_loss is 30.0%, not exceeded: OK!
<class 'pandas.core.frame.DataFrame'>
MultiIndex: 721920 entries, (2015-01-02 00:00:00+00:00, A) to (2017-11-29 00:00:00+00:00, ZION)
Data columns (total 6 columns):
1D 721920 non-null float64
5D 721920 non-null float64
10D 721920 non-null float64
21D 721920 non-null float64
factor 721920 non-null float32
factor_quantile 721920 non-null int64
dtypes: float32(1), float64(4), int64(1)
memory usage: 33.1+ MB
In [11]:
Out[11]:
Quantiles Statistics
Returns Analysis
Information Analysis
Turnover Analysis
<Figure size 432x288 with 0 Axes>
Load zipline extensions
Only need this in notebook to find bundle.
In [12]:
In [13]:
Algo Params
In [14]:
Load Data
Quandl Wiki Bundel
In [15]:
ML Predictions
In [16]:
In [17]:
In [18]:
Out[18]:
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 756 entries, 2014-11-28 to 2017-11-29
Columns: 995 entries, 0 to 3188
dtypes: float32(995)
memory usage: 2.9 MB
Define Custom Dataset
In [19]:
Define Pipeline Loaders
In [20]:
Pipeline Setup
Custom ML Factor
In [21]:
Create Pipeline
In [22]:
Initialize Algorithm
In [23]:
Get daily Pipeline results
In [24]:
Define Rebalancing Logic
In [25]:
Record Data Points
In [26]:
Run Algorithm
In [27]:
In [28]:
Out[28]:
Start: 2014-11-28
End: 2017-11-29
In [29]:
Out[29]:
[2020-06-22 14:59:13.911299]: WARNING: _load_cached_data: Refusing to download new benchmark data because a download succeeded at 2020-06-22 14:53:37.126521+00:00.
Duration: 48.13s
PyFolio Analysis
In [30]:
In [31]:
Custom Plots
In [32]:
In [36]:
Out[36]:
Tear Sheets
In [37]:
Out[37]:
In [ ]: