Moonshot Backtest

We're ready to backtest. To do so, we transfer our interactive strategy code to a Moonshot strategy. The file qmom.py contains our transferred strategy code.

Install strategy file

Execute the following cell to "install" the strategy by moving the file to the /codeload/moonshot directory:

In [1]:
# make directory if doesn't exist
!mkdir -p /codeload/moonshot

!mv qmom.py /codeload/moonshot/

Run backtest

Due to the large universe size, we use the segment parameter to tell Moonshot to run the backtest in 1-year segments and concatenate the results.

We've added Jupyter's %time magic to provide a gauge of total runtime for this backtest.

TIP: open the detailed logs while running the backtest to monitor moonshot's progress through the backtest segments.

In [2]:
from quantrocket.moonshot import backtest
%time backtest("qmom", start_date="2010-01-01", end_date="2018-01-01", segment="A", filepath_or_buffer="qmom_backtest.csv")
CPU times: user 20 ms, sys: 10 ms, total: 30 ms
Wall time: 1min 6s

Performance tear sheets

We can view a performance tear sheet using Moonchart as well as with pyfolio.

Moonchart

In [3]:
from moonchart import Tearsheet
Tearsheet.from_moonshot_csv("qmom_backtest.csv")

Pyfolio

In [4]:
import pyfolio as pf
In [5]:
pf.from_moonshot_csv("qmom_backtest.csv")
Start date2010-01-04
End date2017-12-29
Total months95
Backtest
Annual return7.7%
Cumulative returns80.9%
Annual volatility23.4%
Sharpe ratio0.43
Calmar ratio0.20
Stability0.51
Max drawdown-39.0%
Omega ratio1.08
Sortino ratio0.60
Skew-0.42
Kurtosis4.81
Tail ratio0.90
Daily value at risk-2.9%
Gross leverage1.00
/opt/conda/lib/python3.6/site-packages/numpy/core/fromnumeric.py:52: FutureWarning: 'argmin' is deprecated, use 'idxmin' instead. The behavior of 'argmin'
will be corrected to return the positional minimum in the future.
Use 'series.values.argmin' to get the position of the minimum now.
  return getattr(obj, method)(*args, **kwds)
Worst drawdown periodsNet drawdown in %Peak dateValley dateRecovery dateDuration
039.052014-09-022016-02-08NaTNaN
133.512011-07-222011-10-032013-01-02379
229.182010-04-262010-07-062010-12-01158
313.662010-01-082010-01-292010-03-0842
413.322011-04-292011-06-162011-07-0750
Stress Eventsmeanminmax
US downgrade/European Debt Crisis-0.05%-10.53%8.55%
Fukushima0.31%-1.91%3.38%
EZB IR Event-0.03%-1.49%1.54%
Flash Crash-0.56%-4.32%7.33%
Apr14-0.03%-3.51%2.84%
Oct14-0.46%-5.61%3.87%
Fall2015-0.27%-4.36%3.58%
Recovery0.07%-10.53%8.55%
New Normal0.03%-8.33%4.01%
Top 10 long positions of all timemax
qmom100.00%
Top 10 short positions of all timemax
Top 10 positions of all timemax
qmom100.00%

Next Up

Part 3: Parameter Scans