{
  "$defs": {
    "BacktestSettings": {
      "additionalProperties": false,
      "description": "Settings for mode=backtest.",
      "properties": {
        "benchmark_symbol": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Benchmark Symbol"
        },
        "collect_diagnostics": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Collect Diagnostics"
        },
        "detail": {
          "anyOf": [
            {
              "enum": [
                "summary",
                "full"
              ],
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Detail"
        },
        "end_date": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "End Date"
        },
        "fee_pct": {
          "anyOf": [
            {
              "exclusiveMaximum": 100,
              "maximum": 5,
              "minimum": 0,
              "type": "number",
              "unit": "percent"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Fee Pct"
        },
        "grid": {
          "anyOf": [
            {
              "$ref": "#/$defs/ResearchGrid"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "initial_cash": {
          "anyOf": [
            {
              "exclusiveMinimum": 0,
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Initial Cash"
        },
        "lookback": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Lookback"
        },
        "signal_cooldown_minutes": {
          "anyOf": [
            {
              "minimum": 0,
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Signals-only runs: minimum minutes between two signals of one entry.",
          "title": "Signal Cooldown Minutes"
        },
        "signal_when": {
          "anyOf": [
            {
              "enum": [
                "becomes_true",
                "every_bar"
              ],
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Signals-only runs: 'becomes_true' signals as an entry turns true; 'every_bar' on every bar it is true. Omitted = becomes_true.",
          "title": "Signal When"
        },
        "signals_only": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Signals only: report when each entry would fire and place no order (no fills, no positions). A run choice; the strategy is unchanged. Omitted = place orders.",
          "title": "Signals Only"
        },
        "slippage_pct": {
          "anyOf": [
            {
              "exclusiveMaximum": 100,
              "maximum": 5,
              "minimum": 0,
              "type": "number",
              "unit": "percent"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Slippage Pct"
        },
        "start_date": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Start Date"
        },
        "storage_profile": {
          "anyOf": [
            {
              "enum": [
                "backtest_diagnostic",
                "backtest_minimal"
              ],
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Storage Profile"
        },
        "wait_for_completion": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Wait For Completion"
        },
        "window": {
          "anyOf": [
            {
              "const": "holdout",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "'holdout' runs the saved strategy on its project's reserved holdout window, with the cash, costs and benchmark of its latest completed development backtest (the training run). The holdout is consumed once, at the first submission; asking again returns the current run, or runs the holdout again once that run no longer exists. It takes no other setting. Read the training-versus-holdout comparison with get_run on the returned run.",
          "title": "Window"
        }
      },
      "title": "BacktestSettings",
      "type": "object"
    },
    "ConditionTarget": {
      "additionalProperties": false,
      "properties": {
        "input": {
          "const": "condition",
          "title": "Input",
          "type": "string"
        },
        "path": {
          "title": "Path",
          "type": "string"
        }
      },
      "required": [
        "input",
        "path"
      ],
      "title": "ConditionTarget",
      "type": "object"
    },
    "ConfigurationTarget": {
      "additionalProperties": false,
      "properties": {
        "input": {
          "const": "configuration",
          "title": "Input",
          "type": "string"
        },
        "path": {
          "enum": [
            "/execution",
            "/sizing",
            "/position_policy",
            "/risk_policy",
            "/allocation"
          ],
          "title": "Path",
          "type": "string"
        }
      },
      "required": [
        "input",
        "path"
      ],
      "title": "ConfigurationTarget",
      "type": "object"
    },
    "DocumentFieldTarget": {
      "additionalProperties": false,
      "properties": {
        "input": {
          "const": "document",
          "title": "Input",
          "type": "string"
        },
        "path": {
          "title": "Path",
          "type": "string"
        }
      },
      "required": [
        "input",
        "path"
      ],
      "title": "DocumentFieldTarget",
      "type": "object"
    },
    "EventStudyRunSettings": {
      "additionalProperties": false,
      "description": "Settings for mode=event_study. study selects horizons, outcome_mode and min_occurrences. On timeout: Shorten the date window, or use fewer symbols, variants or entries per call. Splitting a universe changes results for cross-sectional entries (rank, percentile, z-score, sibling); for those, shorten the window instead.",
      "properties": {
        "end_date": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "End Date"
        },
        "fee_pct": {
          "anyOf": [
            {
              "exclusiveMaximum": 100,
              "maximum": 5,
              "minimum": 0,
              "type": "number",
              "unit": "percent"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Recorded fee percentage for experiment provenance; not deducted from event-study forward returns. Use a backtest for trading costs.",
          "title": "Fee Pct"
        },
        "grid": {
          "anyOf": [
            {
              "$ref": "#/$defs/ResearchGrid"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "initial_cash": {
          "anyOf": [
            {
              "exclusiveMinimum": 0,
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Recorded for experiment provenance; does not size positions or change event-study measurements.",
          "title": "Initial Cash"
        },
        "lookback": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Lookback"
        },
        "slippage_pct": {
          "anyOf": [
            {
              "exclusiveMaximum": 100,
              "maximum": 5,
              "minimum": 0,
              "type": "number",
              "unit": "percent"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Recorded slippage percentage for experiment provenance; not applied to event-study forward returns. Use a backtest for trading costs.",
          "title": "Slippage Pct"
        },
        "start_date": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Start Date"
        },
        "study": {
          "anyOf": [
            {
              "$ref": "#/$defs/StudyRequestSettings"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        }
      },
      "title": "EventStudyRunSettings",
      "type": "object"
    },
    "InlineStrategySource": {
      "additionalProperties": false,
      "properties": {
        "document": {
          "additionalProperties": {
            "$ref": "#/$defs/JsonValue"
          },
          "title": "Document",
          "type": "object"
        },
        "kind": {
          "const": "inline",
          "title": "Kind",
          "type": "string"
        },
        "project_id": {
          "anyOf": [
            {
              "minLength": 1,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Project Id"
        }
      },
      "required": [
        "kind",
        "document"
      ],
      "title": "InlineStrategySource",
      "type": "object"
    },
    "JsonValue": {},
    "ResearchAssignment": {
      "additionalProperties": false,
      "properties": {
        "target": {
          "discriminator": {
            "mapping": {
              "condition": "#/$defs/ConditionTarget",
              "configuration": "#/$defs/ConfigurationTarget",
              "document": "#/$defs/DocumentFieldTarget",
              "run": "#/$defs/RunSettingTarget"
            },
            "propertyName": "input"
          },
          "oneOf": [
            {
              "$ref": "#/$defs/DocumentFieldTarget"
            },
            {
              "$ref": "#/$defs/ConfigurationTarget"
            },
            {
              "$ref": "#/$defs/ConditionTarget"
            },
            {
              "$ref": "#/$defs/RunSettingTarget"
            }
          ],
          "title": "Target"
        },
        "value": {
          "$ref": "#/$defs/JsonValue"
        }
      },
      "required": [
        "target",
        "value"
      ],
      "title": "ResearchAssignment",
      "type": "object"
    },
    "ResearchAxis": {
      "additionalProperties": false,
      "properties": {
        "target": {
          "discriminator": {
            "mapping": {
              "condition": "#/$defs/ConditionTarget",
              "configuration": "#/$defs/ConfigurationTarget",
              "document": "#/$defs/DocumentFieldTarget",
              "run": "#/$defs/RunSettingTarget"
            },
            "propertyName": "input"
          },
          "oneOf": [
            {
              "$ref": "#/$defs/DocumentFieldTarget"
            },
            {
              "$ref": "#/$defs/ConfigurationTarget"
            },
            {
              "$ref": "#/$defs/ConditionTarget"
            },
            {
              "$ref": "#/$defs/RunSettingTarget"
            }
          ],
          "title": "Target"
        },
        "values": {
          "items": {
            "$ref": "#/$defs/JsonValue"
          },
          "minItems": 1,
          "title": "Values",
          "type": "array"
        }
      },
      "required": [
        "target",
        "values"
      ],
      "title": "ResearchAxis",
      "type": "object"
    },
    "ResearchGrid": {
      "additionalProperties": false,
      "properties": {
        "assignments": {
          "items": {
            "$ref": "#/$defs/ResearchAssignment"
          },
          "title": "Assignments",
          "type": "array"
        },
        "axes": {
          "items": {
            "$ref": "#/$defs/ResearchAxis"
          },
          "title": "Axes",
          "type": "array"
        },
        "max_combinations": {
          "anyOf": [
            {
              "minimum": 1,
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Max Combinations"
        },
        "mode": {
          "description": "How sweep combinations are generated. 'cartesian' runs every combination of the axes; 'zip_by_index' pairs them positionally and requires every axis to have the same length; 'random_sample' draws sample_size distinct combinations from the full grid, deterministically under seed.",
          "enum": [
            "cartesian",
            "random_sample",
            "zip_by_index"
          ],
          "title": "SweepMode",
          "type": "string"
        },
        "sample_size": {
          "anyOf": [
            {
              "minimum": 1,
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Sample Size"
        },
        "seed": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Seed"
        }
      },
      "title": "ResearchGrid",
      "type": "object"
    },
    "RevisionStrategySource": {
      "additionalProperties": false,
      "properties": {
        "kind": {
          "const": "revision",
          "title": "Kind",
          "type": "string"
        },
        "revision_id": {
          "minLength": 1,
          "title": "Revision Id",
          "type": "string"
        },
        "strategy_id": {
          "minLength": 1,
          "title": "Strategy Id",
          "type": "string"
        }
      },
      "required": [
        "kind",
        "strategy_id",
        "revision_id"
      ],
      "title": "RevisionStrategySource",
      "type": "object"
    },
    "RunSettingTarget": {
      "additionalProperties": false,
      "properties": {
        "input": {
          "const": "run",
          "title": "Input",
          "type": "string"
        },
        "path": {
          "enum": [
            "/initial_cash",
            "/fee_pct",
            "/slippage_pct",
            "/lookback",
            "/start_date",
            "/end_date"
          ],
          "title": "Path",
          "type": "string"
        }
      },
      "required": [
        "input",
        "path"
      ],
      "title": "RunSettingTarget",
      "type": "object"
    },
    "RunStrategySource": {
      "additionalProperties": false,
      "properties": {
        "kind": {
          "const": "run",
          "title": "Kind",
          "type": "string"
        },
        "run_id": {
          "minLength": 1,
          "title": "Run Id",
          "type": "string"
        },
        "run_kind": {
          "const": "backtest",
          "title": "Run Kind",
          "type": "string"
        }
      },
      "required": [
        "kind",
        "run_kind",
        "run_id"
      ],
      "title": "RunStrategySource",
      "type": "object"
    },
    "SavedStrategySource": {
      "additionalProperties": false,
      "properties": {
        "expected_version": {
          "minimum": 1,
          "title": "Expected Version",
          "type": "integer"
        },
        "kind": {
          "const": "saved",
          "title": "Kind",
          "type": "string"
        },
        "strategy_id": {
          "minLength": 1,
          "title": "Strategy Id",
          "type": "string"
        }
      },
      "required": [
        "kind",
        "strategy_id",
        "expected_version"
      ],
      "title": "SavedStrategySource",
      "type": "object"
    },
    "StudyRequestSettings": {
      "additionalProperties": false,
      "description": "Authored study options; effective stored settings resolve omissions once.",
      "properties": {
        "horizons": {
          "anyOf": [
            {
              "items": {
                "anyOf": [
                  {
                    "exclusiveMinimum": 0,
                    "type": "integer"
                  },
                  {
                    "pattern": "^[1-9]\\d*(m|h|d|w)$",
                    "type": "string"
                  }
                ]
              },
              "minItems": 1,
              "type": "array"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Horizons"
        },
        "min_occurrences": {
          "default": 0,
          "minimum": 0,
          "title": "Min Occurrences",
          "type": "integer"
        },
        "outcome_mode": {
          "default": "signed_return",
          "enum": [
            "signed_return",
            "realized_vol"
          ],
          "title": "Outcome Mode",
          "type": "string"
        }
      },
      "title": "StudyRequestSettings",
      "type": "object"
    }
  },
  "additionalProperties": false,
  "properties": {
    "events": {
      "additionalProperties": false,
      "description": "mode=event_study only. Dates to study instead of authored entries, saved as a custom event type; the source must be inline and list only instruments (and optionally name, timeframe).",
      "properties": {
        "dates": {
          "description": "ISO dates or timestamps. A date ('2024-03-15') means the end of that day's daily bar: the US market close (16:00 ET; 13:00 on an early close) for equities, 24:00 UTC for crypto. A timestamp needs an explicit offset ('2024-03-15T08:00:00-04:00'). Duplicates count once.",
          "items": {
            "type": "string"
          },
          "minItems": 1,
          "title": "Dates",
          "type": "array"
        },
        "description": {
          "anyOf": [
            {
              "maxLength": 2000,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "What the dates represent.",
          "title": "Description"
        },
        "name": {
          "description": "Name for the saved event type, e.g. 'FDA decisions'. Its id is the kebab-case form ('fda-decisions'). Reusing a name with the same dates reuses the saved type; a name already saved with other dates is refused.",
          "maxLength": 120,
          "minLength": 1,
          "title": "Name",
          "type": "string"
        },
        "sources": {
          "anyOf": [
            {
              "items": {
                "minLength": 1,
                "pattern": "^[^\\s,]+$",
                "type": "string"
              },
              "maxItems": 20,
              "type": "array"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Where the dates came from (URLs, no spaces or commas). Saved on the event type and shown on the result.",
          "title": "Sources"
        },
        "symbol": {
          "anyOf": [
            {
              "minLength": 1,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Symbol the events belong to. Omit for market-wide events, which apply to every studied instrument.",
          "title": "Symbol"
        }
      },
      "required": [
        "name",
        "dates"
      ],
      "title": "SuppliedEvents",
      "type": "object"
    },
    "idempotency_key": {
      "anyOf": [
        {
          "maxLength": 200,
          "minLength": 1,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Reuse for retries of the same request.",
      "title": "Idempotency Key"
    },
    "mode": {
      "description": "backtest simulates the full strategy with trades; event_study measures whether entries predict returns, without trades.",
      "enum": [
        "backtest",
        "event_study"
      ],
      "type": "string"
    },
    "portfolio_id": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Saved portfolio to backtest, instead of source. mode=backtest only.",
      "title": "Portfolio Id"
    },
    "settings": {
      "anyOf": [
        {
          "$ref": "#/$defs/BacktestSettings"
        },
        {
          "$ref": "#/$defs/EventStudyRunSettings"
        }
      ],
      "description": "Run options for the selected mode: BacktestSettings for backtest, EventStudyRunSettings for event_study. Omit for defaults. Backtests are limited to 50,000 total bar-rows per job, summed across symbols and including warmup. Before submitting, tell the user the limit and rough runtime guidance: 10,000 bars about 20\u201340 seconds; 25,000 about 35\u201370 seconds; 50,000 about 1\u20132 minutes. These are rough estimates, not deadlines; queue time, strategy complexity and diagnostics can add time. Shorten the window, use a coarser timeframe or fewer symbols to fit; never silently truncate a request. Backtest windows are capped per plan (as short as 1,826 days, about 5 years); a longer request is refused with the earliest allowed start date."
    },
    "source": {
      "anyOf": [
        {
          "discriminator": {
            "mapping": {
              "inline": "#/$defs/InlineStrategySource",
              "revision": "#/$defs/RevisionStrategySource",
              "run": "#/$defs/RunStrategySource",
              "saved": "#/$defs/SavedStrategySource"
            },
            "propertyName": "kind"
          },
          "oneOf": [
            {
              "$ref": "#/$defs/InlineStrategySource"
            },
            {
              "$ref": "#/$defs/SavedStrategySource"
            },
            {
              "$ref": "#/$defs/RevisionStrategySource"
            },
            {
              "$ref": "#/$defs/RunStrategySource"
            }
          ]
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Strategy to run, selected by kind. Required for event_study. A backtest takes exactly one of source or portfolio_id.",
      "title": "Source"
    }
  },
  "required": [
    "mode"
  ],
  "type": "object"
}
