Strategy Configuration#
config/*.yaml
The strategy configuration contains information related specifically
to a strategy. Each strategy requires its own
configuration to be able to run. It is written either as a
.yaml file,
or passed directly to AutoTrader as a dictionary via the
add_strategy
method (.yaml
files are
read into Python as dictionaries). Note that spacing is important in
.yaml
files, with each level defined by two subsequent spaces.
Tip
A template strategy configuration file can be generated using the command
line interface! Simply run autotrader init -s config
in your home
directory, and a template file will be created in the config/
directory.
You can also find this template in the
Github repository.
Configuration Options#
The keys of the strategy configuration file are described in the table
below. Note that all PARAMETERS
defined will be accessible in
the strategy, via the parameters
argument.
Key |
Description |
Required |
Default value |
---|---|---|---|
|
A string defining the strategy name. |
Yes |
|
|
A string containing the prefix name of the strategy module, without the .py suffix. |
Yes, unless the strategy is passed directly via |
|
|
A string containing the class name within the strategy module. |
Yes |
|
|
The granularity of the data used by the strategy. |
Yes |
|
|
The number of candles to fetch when live trading (eg. a value of 300 will fetch the latest 300 candles), or a timedelta string (eg. ‘30d’). |
Yes |
|
|
A dictionary containing custom strategy parameters (see below). |
Yes |
|
|
A list containing the instruments to be traded in the strategy, in the format required by the data feed. |
Yes |
|
|
The method to use when calculating position size. Can be either ‘risk’ or an integer value corresponding to the number of units to trade. If using the ‘risk’ option, position size will be calculated based on trading account balance and the value assigned to |
No |
None |
|
The percentage of the account balance to risk when determining position risk-based size. |
No |
None |
|
A boolean flag for if the strategy is a portfolio-based strategy, requiring fata for all instrumenets in the watchlists to run. |
No |
False |
|
A boolean flag to indicate if the broker interface and broker utilities should be passed to the strategy’s |
No |
False |
|
A boolean flag to indicate if the data stream object should be passed to the strategy’s |
No |
False |
Data Interval#
The INTERVAL
key is a string used to define the granularity of the data used by
your strategy. For example, ‘1m’ for minutely data, or ‘4h’ for 4-hourly data.
This is used to infer the timestep to take when backtesting (and livetrading), but
also to convert the PERIOD
to an integer value if necessary.
If you would like to build a strategy which uses multiple timeframes, simply
specify the timeframes with comma separation in the INTERVAL
key. For example,
to have access to 15-minute and 4-hour data, you would specify something
like INTERVAL: 'M15,H1'
. In this case, the data
object passed into the
strategy will be a dictionary, with keys defined by each granularity specified
in INTERVAL
and the associated data.
Data Period#
The PERIOD
key is used to determine how many rows of data (OHLC) is
required by your strategy. This could refer to the lookback period, either
as an integer value of the number of rows, or as a string such as ‘30d’,
indicating 30 days worth of data is required. If an integer value is provided,
for example 300, then the latest 300 rows of data will be passed to your
strategy.
Strategy Parameters#
The parameters key contains any information you would like to be able to access from your strategy module. This might include things like indicator configuration parameters, such as periods, and exit parameters, such as a risk-to-reward ratio.
Example Configuration#
An example strategy configuration is provided below. Each file will look very similar to this, with the exception of the parameters key, which will be tailored to your own strategy. Feel free to look at the configuration files for the example strategies provided in the AutoTrader demo repository.
NAME: 'Strategy Name'
MODULE: 'modulename'
CLASS: 'StrategyClassName'
INTERVAL: 'M15'
PERIOD: 300
RISK_PC: 1 # 1%
SIZING: 'risk'
PARAMETERS:
ema_period: 200
rsi_period: 14
# Exit level parameters
RR: 2
stop_buffer: 10 # pips
# Define instruments to monitor
WATCHLIST: ['EUR_USD']
strategy_config = {'NAME': 'Strategy Name',
'MODULE': 'modulename',
'CLASS': 'StrategyClassName',
'INTERVAL': 'M15',
'PERIOD': 300,
'RISK_PC': 1,
'SIZING': 'risk',
'PARAMETERS': {'ema_period': 200,
'rsi_period': 14,
'RR': 2,
'stop_buffer': 10},
'WATCHLIST': ['EUR_USD',]}