Next, we run a single-strategy variant of VMOT, which applies the momentum screen to the results of the value screen, and which sells the value/momentum portfolio during downturns rather than hedging with a short position.
The file vmot_combined.py contains the strategy code. Starting with the qval
code, we've added the relevant sections of qmom
code and vmot-trend
code. The value and momentum portfolio is constructed in prices_to_signals
. Then, in signals_to_target_weights
, we query the spy-1d
database to compute and apply our trend filters.
From the standpoint of code organization, it's recommended to first create simpler, single-factor strategies (like
qval
,qmom
, andvmot-trend
), then combine them into composite strategies as desired by copying and modifying code from the simpler variants.
Execute the following cell to "install" the strategy by moving the file to the /codeload/moonshot
directory:
# make directory if doesn't exist
!mkdir -p /codeload/moonshot
!mv vmot_combined.py /codeload/moonshot/
Now run the backtest:
from quantrocket.moonshot import backtest
backtest("vmot",
start_date="1999-01-01",
end_date="2010-01-01",
segment="A",
filepath_or_buffer="vmot_combined_backtest_results.csv")
from moonchart import Tearsheet
Tearsheet.from_moonshot_csv("vmot_combined_backtest_results.csv")