Strategy
Strategy builds the strategy document the engine runs. Start from a template — for
example Strategy.rsi_threshold_long() or Strategy.ma_crossover() — or compose one
from indicators with Strategy.indicator(...). The configuration dataclasses below
(Execution, Costs, Risk, Sizing) tune how a strategy is executed and are passed
to Client.backtest() as keyword arguments.
backtest360.strategy.Strategy
Strategy definition.
Build a custom strategy using boolean expression strings and indicator references, or pick a pre-built template via the classmethods.
Expressions reference indicator output columns by their ref name.
Use :meth:indicator to declare which indicators your expressions need.
.. tip:: Indicator library — names, parameter schemas, output columns: https://api.backtest360.com/docs
Or call ``client.list_indicators()`` at runtime.
**Pre-built templates** — call any ``Strategy.<name>()``
classmethod below to start from a ready-made strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Strategy identifier string (arbitrary, used for labelling). |
required |
long_entry
|
str | None
|
Boolean expression string that fires long entry.
References indicator output columns by their |
None
|
long_exit
|
str | None
|
Boolean expression string that fires long exit. |
None
|
short_entry
|
str | None
|
Boolean expression for short entry ( |
None
|
short_exit
|
str | None
|
Boolean expression for short exit. |
None
|
indicators
|
list[dict[str, Any]] | None
|
List of indicator descriptor dicts produced by
:meth: |
None
|
Example::
from backtest360 import Strategy
strat = Strategy(
name="rsi_mean_reversion",
long_entry="rsi < 30",
long_exit="rsi > 70",
indicators=[Strategy.indicator("rsi", period=14)],
)
For a crossover strategy using transform indicators::
strat = Strategy(
name="ma_crossover",
long_entry="x_above",
long_exit="x_below",
indicators=[
Strategy.indicator("sma", ref="sma_10", period=10),
Strategy.indicator("sma", ref="sma_50", period=50),
Strategy.indicator("cross_above", ref="x_above",
kind="transform", upstream=["sma_10", "sma_50"]),
Strategy.indicator("cross_below", ref="x_below",
kind="transform", upstream=["sma_10", "sma_50"]),
],
)
indicator(name, *, ref=None, kind='technical', upstream=None, **params)
staticmethod
Declare an indicator reference for use in condition expressions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Indicator name — e.g. |
required |
ref
|
str | None
|
Column name referenced in expression strings. Defaults to
|
None
|
kind
|
str
|
Indicator kind. One of |
'technical'
|
upstream
|
list[str] | None
|
Refs of upstream indicators consumed by transform
indicators (e.g. |
None
|
**params
|
Any
|
Indicator parameters (e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Indicator descriptor dict suitable for passing in |
Example::
Strategy.indicator("rsi", period=14)
Strategy.indicator("rsi", ref="rsi_fast", period=5)
Strategy.indicator("sma", ref="sma_200", period=200)
Strategy.indicator(
"cross_above", ref="x_above", kind="transform",
upstream=["sma_10", "sma_50"],
)
to_wire()
Serialise to the engine's {condition_tree, indicators} wire shape.
rsi_threshold_long()
classmethod
RSI threshold — long-only mean reversion (oversold entry, overbought exit).
Indicators: RSI(14). Long-only, daily bars.
Returns:
| Type | Description |
|---|---|
Strategy
|
Strategy with |
Example
result = Client(api_key="...").backtest( ... Strategy.rsi_threshold_long(), df ... ) print(result.stats["sharpe"])
rsi_mean_reversion()
classmethod
RSI mean reversion — enter recovery zone, exit at neutral.
Enters when RSI has bounced from oversold (30 < RSI < 50), exits when
RSI returns to neutral (>= 50). Shorter hold and tighter exit than
rsi_threshold_long, which holds from oversold all the way to overbought.
Indicators: RSI(14). Long-only, daily bars.
Returns:
| Type | Description |
|---|---|
Strategy
|
Strategy with |
Strategy
|
|
Example
result = Client(api_key="...").backtest( ... Strategy.rsi_mean_reversion(), df ... ) print(result.stats["sharpe"])
ma_crossover()
classmethod
SMA(10) / SMA(50) crossover — classic trend-following.
Indicators: SMA(10), SMA(50), CrossAbove, CrossBelow. Long-only, daily.
Returns:
| Type | Description |
|---|---|
Strategy
|
Strategy with |
Strategy
|
|
Example
result = Client(api_key="...").backtest( ... Strategy.ma_crossover(), df ... ) print(result.stats["sharpe"])
momentum_6m_long()
classmethod
Absolute 6-month momentum — long when ROC(126) > 0.
Indicators: ROC(126). Long-only, daily bars.
Returns:
| Type | Description |
|---|---|
Strategy
|
Strategy with |
Strategy
|
|
Example
result = Client(api_key="...").backtest( ... Strategy.momentum_6m_long(), df ... ) print(result.stats["sharpe"])
Execution
backtest360.strategy.Execution
dataclass
Execution timing — when signals are entered and exited.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
str
|
Bar anchor for entry fills. One of |
'open'
|
exit
|
str
|
Bar anchor for exit fills. Default |
'close'
|
signal_frequency
|
str
|
Frequency at which the strategy generates signals.
Common values: |
'daily'
|
entry_window
|
int
|
Number of bars the engine attempts to fill after the
entry anchor. Default |
0
|
exit_window
|
int
|
Same for exits. |
0
|
entry_fill
|
str
|
Fill price model for entries. One of |
'exact'
|
exit_fill
|
str
|
Fill price model for exits. Default |
'exact'
|
See also
https://api.backtest360.com/docs for the full execution reference.
Example
Execution(entry="open", exit="close", signal_frequency="daily") Execution(entry_fill="worst", exit_fill="best")
to_wire()
Serialise to the engine's flat execution dict.
Costs
backtest360.strategy.Costs
dataclass
Transaction costs — slippage and fees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slippage_bps
|
float
|
Slippage in basis points (10 = 0.1%). Applied adversely
on every fill. Default |
0.0
|
fee_pct
|
float
|
Round-trip fee as a fraction (0.001 = 0.1%). Deducted on
entry and exit events. Default |
0.0
|
vol_scaled_slippage
|
bool
|
Scale slippage by rolling realised volatility.
Default |
False
|
vol_slippage_lookback
|
int
|
Lookback bars for vol-scaled slippage.
Default |
20
|
Example
Costs(slippage_bps=2.5, fee_pct=0.001)
to_wire()
Serialise to the engine's cost dict.
Risk
backtest360.strategy.Risk
dataclass
Risk management — stops and drawdown protection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stop
|
str | None
|
Stop type. One of |
None
|
value
|
float | None
|
Stop distance — percent (e.g. |
None
|
atr_period
|
int | None
|
Lookback bars for ATR-based stops. Default |
None
|
reentry
|
str
|
Re-entry behaviour after a stop exit. One of
|
'immediate'
|
cooldown_bars
|
int
|
Bars to suppress re-entry after a stop exit. Only
used when |
0
|
max_drawdown
|
float | None
|
Circuit-breaker drawdown limit (e.g. |
None
|
Example
Risk(stop="trailing_atr", value=2.5, atr_period=14) Risk(stop="fixed", value=0.05, max_drawdown=0.20) Risk(stop="atr", value=2.0, reentry="cooldown", cooldown_bars=5)
to_wire()
Serialise to the engine's risk dict.
Sizing
backtest360.strategy.Sizing
dataclass
Position sizing configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weight
|
float
|
Fraction of capital deployed per position (1.0 = fully
invested). Default |
1.0
|
vol_target
|
float | None
|
Annualised volatility target for vol-targeting sizing.
|
None
|
vol_target_lookback
|
int
|
Lookback bars for realised vol estimate.
Default |
20
|
leverage_limit
|
float | None
|
Maximum leverage cap. |
None
|
Example
Sizing(weight=0.5) Sizing(vol_target=0.15, leverage_limit=2.0)
to_wire()
Serialise to the engine's sizing dict.