Client
backtest360.client.Client
Synchronous HTTP client for the Backtest360 backtesting API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str | None
|
Your Backtest360 API key. Falls back to the
|
None
|
base_url
|
str | None
|
Engine base URL. Falls back to |
None
|
timeout
|
float
|
Request timeout in seconds. Defaults to 300 (backtests can be slow). |
_TIMEOUT_SECONDS
|
Example
import yfinance as yf from backtest360 import Client, Strategy
df = yf.download("BTC-USD", period="1y", interval="1d", ... auto_adjust=False, multi_level_index=False, progress=False) df.columns = df.columns.str.lower()
result = Client(api_key="b360_live_...").backtest( ... Strategy.rsi_threshold_long(), df ... ) print(result.stats["Sharpe"]) result.equity.plot(title="Equity curve")
version()
Return engine version info from GET /api/version.
Returns:
| Type | Description |
|---|---|
dict
|
Dict with at minimum |
dict
|
|
Raises:
| Type | Description |
|---|---|
Backtest360Error
|
On any non-2xx response. |
Example
info = client.version() print(info["version"]) 0.5.3
list_indicators()
Return the engine's indicator library from GET /api/indicators.
Each entry describes an indicator's name, parameters, kind, and output columns. Use this to discover available indicators and their parameter schemas when building custom strategies.
See also: https://api.backtest360.com/docs#tag/Reference
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of indicator descriptor dicts. |
Raises:
| Type | Description |
|---|---|
Backtest360Error
|
On any non-2xx response. |
Example
for ind in client.list_indicators(): ... print(ind["name"], ind.get("params", {}).keys())
list_strategies()
Return the engine's built-in strategy templates from GET /api/strategies.
Each entry carries the strategy's name, description,
condition_tree, and indicators.
See also: https://api.backtest360.com/docs#tag/Reference
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of strategy descriptor dicts. |
Raises:
| Type | Description |
|---|---|
Backtest360Error
|
On any non-2xx response. |
Example
for s in client.list_strategies(): ... print(s["name"], s["description"])
validate_strategy(strategy)
Validate a strategy against the engine's registry without running a backtest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy
|
Strategy
|
A :class: |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Validation result dict with |
dict
|
|
Raises:
| Type | Description |
|---|---|
Backtest360Error
|
On HTTP error. |
Example
v = client.validate_strategy(Strategy.rsi_threshold_long()) print(v["is_valid"], v.get("errors", []))
latest_signal(strategy, ohlcv, *, execution=None, costs=None, risk=None, sizing=None)
Return the latest signal for a strategy on the given data.
Uses POST /api/latest-signal. Returns only the most-recent bar's
signal and per-condition diagnostics — no P&L or statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy
|
Strategy
|
Strategy definition. |
required |
ohlcv
|
DataFrame
|
DataFrame indexed by datetime with columns
|
required |
execution
|
Execution | None
|
Execution configuration (optional). |
None
|
costs
|
Costs | None
|
Cost configuration (optional). |
None
|
risk
|
Risk | None
|
Risk / stop configuration (optional). |
None
|
sizing
|
Sizing | None
|
Position sizing configuration (optional). |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Dict with |
dict
|
related diagnostic fields. |
Raises:
| Type | Description |
|---|---|
Backtest360Error
|
On HTTP error or invalid strategy. |
Example
sig = client.latest_signal(Strategy.rsi_threshold_long(), df) print(sig["signal"]) # -1 / 0 / 1
backtest_raw(payload)
Send a raw POST /api/backtest payload, return the raw response dict.
For users who want exact control over the wire format — build the JSON payload yourself with the API docs open.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict
|
Dict matching the |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The full response dict from the engine ( |
Raises:
| Type | Description |
|---|---|
Backtest360Error
|
On any non-2xx response. |
Example
resp = client.backtest_raw({ ... "strategy": {"condition_tree": {...}, "indicators": [...]}, ... "data_source": {"ohlcv": {...}}, ... "execution": {"signal_frequency": "daily"}, ... })
backtest(strategy, ohlcv, *, benchmark=None, execution=None, costs=None, risk=None, sizing=None)
Run a historical backtest and return a :class:Result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy
|
Strategy
|
Strategy definition. Use a template (e.g.
|
required |
ohlcv
|
DataFrame
|
DataFrame indexed by datetime with lowercase columns
|
required |
benchmark
|
DataFrame | None
|
Optional benchmark DataFrame (same shape as |
None
|
execution
|
Execution | None
|
Execution timing config — |
None
|
costs
|
Costs | None
|
Transaction costs — |
None
|
risk
|
Risk | None
|
Stop-loss / drawdown protection config. |
None
|
sizing
|
Sizing | None
|
Position sizing config. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Result
|
class: |
Raises:
| Type | Description |
|---|---|
Backtest360Error
|
On any non-2xx response. |
Example
from backtest360 import Client, Strategy, Execution, Costs result = Client(api_key="...").backtest( ... Strategy.rsi_threshold_long(), df, ... execution=Execution(signal_frequency="daily"), ... costs=Costs(slippage_bps=2.5, fee_pct=0.001), ... ) print(result.stats["Sharpe"]) result.equity.plot()
Result
backtest360.client.Result
Wraps a /api/backtest response.
All properties are derived lazily from the raw response dict.
Attributes:
| Name | Type | Description |
|---|---|---|
stats |
dict
|
Full statistics dict — 120+ metrics keyed by metric name. |
trades |
list[dict]
|
List of trade dicts, each with |
equity |
Series
|
Equity curve as a |
returns |
Series
|
Net-of-cost log-return series indexed by datetime. |
signals |
Series
|
Signal series ( |
raw |
dict
|
The full |
Example
result = client.backtest(strategy, df) print(result.stats["Sharpe"]) result.equity.plot(title="Equity curve") for trade in result.trades[:5]: ... print(trade["entry_date"], trade["return_net"])
stats
property
Performance statistics dict (120+ metrics).
trades
property
Trade log — list of dicts with entry/exit date, direction, return.
equity
property
Equity curve as a pd.Series indexed by datetime.
returns
property
Net-of-cost log-return series indexed by datetime.
signals
property
Signal series ({-1, 0, 1}) indexed by datetime.
raw
property
Full engine response dict — access any field not exposed as a property.