Build and backtest an index
Assemble an operation DAG, simulate it, and read the results.
This is the guide the others build on. It takes one real index — a US momentum strategy that holds the 50 strongest twelve-month performers, weighted by their momentum score — and walks the whole path: the operation graph, what each node does and why it is wired that way, and then two ways to simulate it before anything goes live.
The workflow below is not illustrative. It is a complete index payload, in the exact shape the shipped get_example workflows use, and it runs.
- A quarterly cron trigger fires, aligned to the preceding XNYS session close.
- core_securities_reference produces the eligible cross-section: US-domiciled common stock listed on NYSE or NASDAQ.
- i1_core_quote prices that list as of the run time and attaches market cap.
- filter keeps the 200 largest names — a liquidity screen, so the momentum calculation is not dominated by micro caps.
- i1_core_eod pulls the price history for those 200 ids up to the run time.
- return computes a 252-session trailing return per id and keeps one row per security at the rebalance date.
- rank orders by that return, filter takes the top 50.
- create_index_universe records what was eligible, create_index_weighting turns momentum scores into proportional weights, create_index_holdings converts weights into share counts and a divisor.
The envelope
Everything outside operations configures the index itself rather than any single node.
| Field | Meaning |
|---|---|
name | Display name. |
start_time | First point of the series. A backtest defaults its start to this. |
run_at_start | Also runs each cron trigger on the first session of start_time, so the series begins there, not at the first cron date. A start on a fire date, as here, is that one run. |
start_value | Level the index is normalised to at start_time — 1000 here. |
start_divisor | Initial divisor. The engine adjusts it from then on. |
timezone / eod_time | When a session is considered closed for valuation. |
exchange_calendar | MIC of the calendar that defines trading days — XNYS. |
default_operations | Machinery you get without wiring nodes: the EOD value series and corporate-action generation. |
operations | The DAG. |
default_operations.create_index_value_eod_default.value_series is where the published series are declared. This index publishes two: value_pr, a price-return series, and value_tr, a total-return series with dividend_policy: "pro_rata", marked default: true. Consumers who do not name a series get the TR one. create_index_corporate_actions_default: {} switches on corporate-action generation with its defaults — see Corporate actions.
Reading the graph
An operation is always the same four fields: {id, operation, parameters, input}. input declares the edges; parameters may additionally reach into an upstream result with {"$ref": "<op_id>.output#<column>"}. Both are required — a $ref inside parameters whose operation is missing from input creates no dependency, and the value will not exist when the node runs.
The trigger
{"id": "rebal_trigger","operation": "trigger","parameters": {"cron": "0 0 1 1,4,7,10 *","alignment_enabled": true,"align_time": true,"trading_calendar": "XNYS","trading_day": "preceding","session_time": "close"}}
The cron says midnight on the first of January, April, July and October. On its own that is a useless timestamp for an index — those dates are frequently holidays, and midnight is not a moment at which prices exist. The alignment parameters fix both problems: trading_calendar names the calendar, trading_day: "preceding" moves the run back to the last trading day at or before the cron date, and session_time: "close" stamps it at that session's close. The run time that every downstream context.request_context.time resolves to is the aligned one.
Selection
core_securities_reference is the cross-section of securities the platform knows about, with row filters. The four filters here are doing real work — restricting to two MICs keeps out OTC listings, security_type excludes funds and depositary receipts, and requiring both exchange_country and domicile_country to be US removes foreign issuers with a US listing. Sector and industry exclusions belong here too, as a not_in filter, not in a later step.
attributes: ["id"] projects the result down to the identifier column. Ask only for the columns you use; everything is carried through the rest of the graph.
Pricing and the liquidity screen
i1_core_quote takes a list of ids and a date and returns one row per security, shaped like an EOD row. With a past date it resolves to the last settled print at or before that date, so a backtest step that lands on a half-day or an exchange holiday still gets prices. It is the right operation for a single date; i1_core_eod is the right one for a range.
The filter that follows uses top_n on marketCap. Twelve-month momentum on a universe of several thousand names is dominated by tiny illiquid stocks with enormous percentage moves, so the screen to the largest 200 is what makes the signal investable rather than a formality.
The signal
{"id": "eod_hist","operation": "i1_core_eod","parameters": {"filters": [{ "field": "date", "operator": "lte", "value": { "$ref": "context.request_context.time" } },{ "field": "id", "operator": "in", "value": { "$ref": "liq_filter.output#id" } }],"attributes": ["date", "id", "splitAdjClose"]},"input": [{ "$ref": "liq_filter" }]},{"id": "return_12m","operation": "return","parameters": {"data": { "$ref": "eod_hist.output" },"price_column": "splitAdjClose","time_column": "date","group_by_column": "id","window": 252,"filter_time": { "$ref": "context.request_context.time" },"output_column_name": "momentum_12m"},"input": [{ "$ref": "eod_hist" }]}
Two details matter here. The price column is splitAdjClose, not close — a raw close series contains step changes at every split that a return calculation would read as a 50% loss. And filter_time collapses the long history down to one row per security as of the rebalance date; without it the operation returns every row with a return column appended, and the ranking downstream would be meaningless.
The date filter is lte the run time, never an open range. That is what keeps a backtest honest: at each historical step the graph can only see prices that existed then.
Look-ahead comes from the data, not the engine
{"$ref": "context.request_context.time"}. A missing bound produces a backtest that looks excellent and
predicts nothing.Universe, weighting, holdings
The last three nodes are the ones every index has. create_index_universe records the eligible set with identifier: "id". create_index_weighting with weighting_type: "proportional" and weight_attribute: "momentum_12m" normalises the momentum scores into weights that sum to one — that is what "weighted by momentum" means mechanically. create_index_holdings turns those target proportions into share counts and a divisor.
Note what create_index_holdings is not given: prices. It auto-fetches them, and when the index currency differs from a security's trading currency it converts through fx_converter on the way. Supplying price_data yourself disables that conversion, so omit it unless you have already converted.
Other weighting types
equal is 1/N and needs no weight column. inverse weights by 1/value (inverse volatility);
power raises the value to an exponent (power: 0.5 is the square-root-of-cap tilt); rank weights by
ordering alone. custom uses weight_attribute as-is rather than normalising it — that is what an
optimizer's output feeds into. tiered assigns fixed weights by position band.
All of them accept constraints, a list where each row picks units and bounds them. UCITS 5/10/40 is
[{scope: "security", max: 0.10}, {scope: "above", threshold: 0.05, max: 0.40}], or just
rule: "ucits_5_10_40". A QQQ-style aggregate cap is {scope: "top_n", n: 5, max: 0.40}, and a sector
cap is {scope: "group", column: "sector", max: 0.30}.Backtest it
POST /simulate launches the run over history and answers straight away with a bkt_... id — it no longer holds the response open on the computation. It persists nothing live and needs a team API key (it did not until 21 July 2026, so older examples you may have seen omit the header). Then poll GET /backtests/{backtest_id} for the result: it waits server-side for the in-flight window, so a short run is usually ready on the first poll. Add ?include_series=true to get the value series back for charting.
# 1. Launch — returns { "backtest_id": "bkt_...", "status": "running" }curl -X POST https://api.indexone.io/simulate \-H "x-api-key: YOUR_API_KEY" \-H "Content-Type: application/json" \-d @- <<'JSON'{"index_parameters": {"name": "US Momentum 50","start_time": "2019-12-31 00:00:00","run_at_start": true,"start_value": 1000,"start_divisor": 1,"timezone": "US/Eastern","eod_time": "16:00:00","exchange_calendar": "XNYS","default_operations": {"create_index_value_eod_default": {"value_series": [{ "id": "value_pr" },{ "id": "value_tr", "dividend_policy": "pro_rata", "default": true }]},"create_index_corporate_actions_default": {}},"operations": [ /* the DAG above */ ]}}JSON# 2. Poll until status is "completed" (or "failed")curl "https://api.indexone.io/backtests/bkt_9Fq2LmVt41Xe?include_series=true" \-H "x-api-key: YOUR_API_KEY"
The 29-second ceiling
API Gateway's integration timeout is 29 seconds — the reason /simulate hands back an id instead of the result. It never holds the response open on the run, so the ceiling has nothing to sever: the launch always answers in well under a second, the run continues in the background, and its result is persisted whatever happens. There are two ways to take that result, and because it is persisted a late reader still gets it:
- Poll the id.
GET /backtests/{backtest_id}over REST, orget_backtestover MCP — both read the same persisted blob and wait server-side for the in-flight window, so polling right after the launch is fine. This is the primary path. - Stream it. Additionally pass a
websocket_id(orconnection_id) alongsideindex_parametersand the worker pushes progress frames to that connection as the run computes — useful for a live UI. The frames are below.
| Frame | Meaning |
|---|---|
execution_start | The worker has picked the job up. |
execution_complete | Finished — carries the result. |
execution_error | The run failed before or outside the simulation itself. |
backtest_error | The simulation ran and failed — usually a wiring or data problem in the graph. |
import jsonimport websocket # websocket-clientimport requestsWS_URL = "wss://846dfj97pc.execute-api.eu-west-1.amazonaws.com/prod/"ws = websocket.create_connection(WS_URL)# The connection id is returned by the socket handshake; pass it on the request# so the worker knows where to push.connection_id = json.loads(ws.recv())["connection_id"]requests.post("https://api.indexone.io/simulate",headers={"x-api-key": "YOUR_API_KEY"},json={"index_parameters": index_parameters, "connection_id": connection_id},timeout=30,)while True:frame = json.loads(ws.recv())if frame.get("type") == "execution_complete":result = framebreakif frame.get("type") in ("execution_error", "backtest_error"):raise RuntimeError(frame)
Backtesting over MCP
An agent connected to the MCP server does not deal with websockets. run_backtest takes the same index_parameters as a JSON string, launches the run, and immediately returns a bkt_... id. Poll that with get_backtest, which reports the performance summary and, with include_series=true, the downsampled value series.
run_backtest
Run a historical simulation of a workflow (index_parameters JSON). Validates AND runs the workflow once in preview first (structured issues + runtime errors with hints returned on failure — no separate validate_workflow or run_workflow call needed), then launches the run and immediately returns a backtest_id — poll get_backtest until status is 'completed' or 'failed'. Never creates a live index — use deploy_index.
Arguments
| Field | Type | Description |
|---|---|---|
index_parametersrequired | string | JSON string of the full index_parameters object. |
start_time | string | Backtest start, 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS' (defaults to index_parameters.start_time). |
end_time | string | Backtest end, 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS' (defaults to now). |
verify | boolean | Default true: runs the full workflow once in preview to catch runtime problems (a column the upstream op doesn't output, filters matching nothing, runaway leverage, an empty index) and returns them as actionable issues before doing the work. Auto-skipped when this exact workflow already ran cleanly this session. Set false only to skip the preview deliberately. |
curl -X POST "https://mcp.indexone.io" \-H "content-type: application/json" \-H "accept: application/json, text/event-stream" \-H "x-api-key: YOUR_API_KEY" \-d '{"jsonrpc": "2.0","id": 1,"method": "tools/call","params": {"name": "run_backtest","arguments": {"index_parameters": "{\"name\":\"My Index\",\"start_time\":\"2019-12-28 00:00:00\",\"operations\":[]}"}}}'
get_backtest
Fetch a stored backtest result by backtest_id: performance summary and, with include_series=true, the value series evenly downsampled to max_points (default 500) for charting. Waits briefly server-side when the run is still in flight, so polling back-to-back is fine. After deploy_index, also reports the deployed live index id.
Arguments
| Field | Type | Description |
|---|---|---|
backtest_idrequired | string | Backtest id (bkt_...). |
include_series | boolean | Include the value series (downsampled). |
max_points | integer | Series point cap when include_series=true (default 500, max 2000). |
curl -X POST "https://mcp.indexone.io" \-H "content-type: application/json" \-H "accept: application/json, text/event-stream" \-H "x-api-key: YOUR_API_KEY" \-d '{"jsonrpc": "2.0","id": 1,"method": "tools/call","params": {"name": "get_backtest","arguments": {"backtest_id": "bkt_7Hs2Qa","include_series": true}}}'
A backtest never creates an index
POST /simulate and run_backtest both compute and discard. Nothing is persisted and no schedule is
registered. Going live is a separate, explicitly confirmed step — see Publish a
benchmark.Previewing a fragment
Before simulating twenty years, run the first few nodes once and look at what comes out. POST /execute takes a bare operations array — not the full envelope — runs it in preview mode against real source data, and persists nothing. It is the fastest way to find out that a column is called splitAdjClose and not split_adj_close, or that a sector filter matched zero rows.
The MCP equivalent is run_workflow, with inspect_run and get_column_values to look at the result.
curl -X POST https://api.indexone.io/execute \-H "x-api-key: YOUR_API_KEY" \-H "Content-Type: application/json" \-d '{"operations": [{"id": "t", "operation": "manual_trigger", "parameters": {}},{"id": "sec_ref", "operation": "core_securities_reference","parameters": {"filters": [{"field": "mic", "operator": "in", "value": ["XNYS", "XNAS"]}],"attributes": ["id", "sector"]},"input": [{"$ref": "t"}]}]}'
Saving the workflow
Backtesting is not deploying
POST /simulate never creates anything — it runs the graph over history and hands back the result.
To turn a graph into a live index, post it to POST /workflows, which validates it,
answers straight away with an idx_ id, and finishes the backtest and live registration in the background. The
MCP equivalents are save_workflow for a draft and deploy_index for going live.save_workflow without a workflow_id creates a draft; with one it updates that workflow in place, and if the workflow is already live its changed operations trigger a live reload. It validates first and never changes stage — a draft stays a draft until deploy_index promotes it.