{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/marketheist-io/json-schema/marketheist-io-backtest-response-schema.json",
  "title": "BacktestResponse",
  "x-generated": "2026-11-18",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/_original/marketheist-io-api-openapi.json#/components/schemas/BacktestResponse",
  "type": "object",
  "required": [
    "ticker",
    "frequency",
    "indicator_id",
    "metrics",
    "equity_curve",
    "drawdown_curve",
    "bar_count",
    "validity"
  ],
  "properties": {
    "ticker": {
      "type": "string"
    },
    "frequency": {
      "$ref": "#/$defs/Frequency"
    },
    "indicator_id": {
      "type": "string"
    },
    "metrics": {
      "type": "object",
      "properties": {
        "strategy": {
          "$ref": "#/$defs/MetricsBlock"
        },
        "buyhold": {
          "$ref": "#/$defs/MetricsBlock"
        },
        "applied_leverage": {
          "type": "number",
          "description": "Actual leverage multiplier used (1.0 when mode=none)."
        },
        "leverage_mode": {
          "type": "string",
          "description": "Echo of the leverage mode used."
        },
        "n_years": {
          "type": "number",
          "description": "Number of years of data used."
        }
      }
    },
    "equity_curve": {
      "type": "array",
      "items": {
        "type": "array",
        "prefixItems": [
          {
            "type": "number"
          },
          {
            "type": "number"
          }
        ],
        "minItems": 2,
        "maxItems": 2
      },
      "description": "Strategy equity curve as [unixMs, value] pairs. Starts at 1.0."
    },
    "drawdown_curve": {
      "type": "array",
      "items": {
        "type": "array",
        "prefixItems": [
          {
            "type": "number"
          },
          {
            "type": "number"
          }
        ],
        "minItems": 2,
        "maxItems": 2
      },
      "description": "Strategy drawdown series as [unixMs, value] pairs. Values ≤ 0."
    },
    "bar_count": {
      "type": "integer",
      "description": "Number of data bars used after warm-up alignment."
    },
    "validity": {
      "$ref": "#/$defs/Validity"
    }
  },
  "$defs": {
    "Frequency": {
      "type": "string",
      "enum": [
        "1d",
        "1wk",
        "1mo"
      ],
      "description": "Data bar frequency. 1d = daily, 1wk = weekly, 1mo = monthly."
    },
    "MetricsBlock": {
      "type": "object",
      "description": "Performance metrics for one strategy (strategy or buy-and-hold).",
      "properties": {
        "sharpe": {
          "type": "number",
          "description": "Annualized Sharpe ratio."
        },
        "sortino": {
          "type": "number",
          "description": "Annualized Sortino ratio."
        },
        "cagr": {
          "type": "number",
          "description": "Compound annual growth rate (decimal, e.g. 0.12 = 12%)."
        },
        "max_dd": {
          "type": "number",
          "description": "Maximum drawdown (decimal, e.g. -0.35 = -35%)."
        },
        "calmar": {
          "type": "number",
          "description": "CAGR / |max_dd|."
        },
        "omega": {
          "type": "number",
          "description": "Omega ratio (threshold = 0)."
        },
        "profit_factor": {
          "type": "number",
          "description": "Gross profit / gross loss."
        },
        "recovery_factor": {
          "type": "number",
          "description": "Total return / |max_dd|."
        },
        "pct_invested": {
          "type": "number",
          "description": "Fraction of bars holding a long position (0–1)."
        }
      }
    },
    "Validity": {
      "type": "object",
      "description": "Trust layer: where the numbers came from, their known failure modes, and how to reproduce them. Present on every backtest result — reproducible about the past, traceable to its inputs, flagged for known failure modes.",
      "required": [
        "provenance",
        "caveats",
        "reproduce"
      ],
      "properties": {
        "provenance": {
          "type": "object",
          "required": [
            "engine_version",
            "data_source",
            "ticker",
            "frequency",
            "price_basis",
            "bar_count",
            "warmup_bars",
            "sample_start",
            "sample_end",
            "n_years"
          ],
          "properties": {
            "engine_version": {
              "type": "string",
              "description": "Pinned engine version."
            },
            "data_source": {
              "type": "string",
              "description": "Market-data source id, e.g. \"yahoo\"."
            },
            "ticker": {
              "type": "string"
            },
            "frequency": {
              "$ref": "#/$defs/Frequency"
            },
            "price_basis": {
              "type": "string",
              "enum": [
                "total-return-adjusted"
              ],
              "description": "Close is total-return adjusted (dividends reinvested, splits applied)."
            },
            "bar_count": {
              "type": "integer",
              "description": "Bars the metrics were computed on (after warm-up)."
            },
            "warmup_bars": {
              "type": "integer",
              "description": "Bars dropped to warm up indicators / align buy-and-hold."
            },
            "sample_start": {
              "type": "string",
              "format": "date",
              "description": "First bar of the measured window (UTC)."
            },
            "sample_end": {
              "type": "string",
              "format": "date",
              "description": "Last bar of the measured window (UTC)."
            },
            "n_years": {
              "type": "number",
              "description": "Length of the measured window in years."
            }
          }
        },
        "caveats": {
          "type": "array",
          "description": "Known limitations of this run. severity=warn materially affects interpretation.",
          "items": {
            "type": "object",
            "required": [
              "code",
              "severity",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "single-run-no-walkforward",
                  "no-transaction-costs",
                  "short-sample",
                  "few-trades",
                  "leverage-frictionless",
                  "sharpe-not-significant",
                  "parameter-overfit"
                ]
              },
              "severity": {
                "type": "string",
                "enum": [
                  "info",
                  "warn"
                ]
              },
              "message": {
                "type": "string"
              }
            }
          }
        },
        "reproduce": {
          "type": "object",
          "required": [
            "config_hash",
            "recipe"
          ],
          "properties": {
            "config_hash": {
              "type": "string",
              "description": "Deterministic fingerprint of the run inputs (config + measured window + engine version). Same inputs → same hash; a citation key, not a cryptographic commitment."
            },
            "recipe": {
              "type": "string",
              "description": "One-line recipe for reproducing the run."
            }
          }
        }
      }
    }
  }
}