5. Single-instrument signal strategy
To build on your RollingFutureStrategy, add signals to take long or short positions during different time periods.
A simple signal strategy
1. Set up a single-instrument RollingFutureStrategy
again
RollingFutureStrategy
againThe first few code blocks are very close to what you already used in the previous two tutorials:
Set up environment
Define instrument, time period, and RollingFutureStrategy
RollingFutureStrategy
2. Create a DataFrame of signals
Every RollingFutureStrategy
instance has a history, in the format of a simple table of dates and values:
Note: the table is a pandas Series. Run my_rfs.history?
to see this confirmed in its docstring.
Duplicate the history Series and reset its values
The signals
series you've just created has all the same dates as the history of your RollingFutureStrategy
, but the values are now reset to 0. In the next step you will repopulate the values with signals—indicators of what position to take.
Add the signals
A signal of 1
indicates a 100% long position, while a signal of -1
indicates a 100% short position. Set a signal of -1
for the first four months of each year in the time period, and 1
for the final four months of each year, assuming there is a strategic rationale for this relating to seasonal market activity:
Convert series to DataFrame and associate with RFS instance
For future steps to work, signals
needs to be in DataFrame format and have the exact same name as your RollingFutureStrategy
instance. This name-sharing allows the SignalStrategy
instance to reference the relevant RollingFutureStrategy
instance:
3. Define SignalStrategy
SignalStrategy
4. View performance
👷Your turn: customise the strategy
Try a different set of signals.
Last updated