{
  "openapi": "3.0.1",
  "info": {
    "title": "Yahoo Finance Stock & ETF Portfolio Backtester (MCP / Quant)",
    "description": "Fast Yahoo Finance stock, ETF & crypto portfolio backtesting API & MCP server. Computes CAGR, Sharpe, Sortino, Max Drawdown, DCA, 200-day SMA shield, crisis stress tests & Monte Carlo in <2s.",
    "version": "1.0",
    "x-build-id": "s5xq32NVuBwhQnFqJ"
  },
  "servers": [
    {
      "url": "https://api.apify.com/v2"
    }
  ],
  "paths": {
    "/acts/factorlab~quant-portfolio-backtester/run-sync-get-dataset-items": {
      "post": {
        "operationId": "run-sync-get-dataset-items-factorlab-quant-portfolio-backtester",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/acts/factorlab~quant-portfolio-backtester/runs": {
      "post": {
        "operationId": "runs-sync-factorlab-quant-portfolio-backtester",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor and returns information about the initiated run in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/runsResponseSchema"
                }
              }
            }
          }
        }
      }
    },
    "/acts/factorlab~quant-portfolio-backtester/run-sync": {
      "post": {
        "operationId": "run-sync-factorlab-quant-portfolio-backtester",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "inputSchema": {
        "type": "object",
        "required": [
          "portfolio"
        ],
        "properties": {
          "portfolio": {
            "title": "Portfolio Allocation (Ticker -> Weight)",
            "type": "object",
            "description": "JSON map of Yahoo Finance tickers to weights (auto-normalized to 100%). Supports US Stocks, Leveraged ETFs, Crypto (BTC-USD), and International tickers (e.g. 005930.KS).",
            "default": {
              "TQQQ": 0.4,
              "SPY": 0.3,
              "GLD": 0.3
            }
          },
          "benchmark": {
            "title": "Benchmark Ticker",
            "type": "string",
            "description": "Reference benchmark for Alpha, Beta, and Excess Return comparisons.",
            "default": "SPY"
          },
          "startDate": {
            "title": "Start Date (YYYY-MM-DD)",
            "type": "string",
            "description": "Backtest start date (automatically aligns to earliest common trading day across all tickers).",
            "default": "2016-01-01"
          },
          "endDate": {
            "title": "End Date (YYYY-MM-DD, optional)",
            "type": "string",
            "description": "Leave blank to run through the latest completed market session.",
            "default": ""
          },
          "initialCapital": {
            "title": "Initial Capital (USD)",
            "minimum": 100,
            "maximum": 100000000,
            "type": "number",
            "description": "Starting lump-sum investment in USD.",
            "default": 10000
          },
          "monthlyDca": {
            "title": "Monthly DCA Contribution (USD)",
            "minimum": 0,
            "maximum": 1000000,
            "type": "number",
            "description": "Recurring monthly cash contribution added on the first trading day of each month (0 for lump-sum only).",
            "default": 0
          },
          "rebalance": {
            "title": "Rebalance Frequency",
            "enum": [
              "none",
              "monthly",
              "quarterly",
              "annual"
            ],
            "type": "string",
            "description": "How often portfolio weights reset to target allocations.",
            "default": "quarterly"
          },
          "strategy": {
            "title": "Risk Management Overlay",
            "enum": [
              "buy_and_hold",
              "sma200_shield",
              "vol_target"
            ],
            "type": "string",
            "description": "Apply a strictly 1-day lagged systematic overlay (zero lookahead) alongside Buy & Hold comparison.",
            "default": "sma200_shield"
          },
          "targetVolPct": {
            "title": "Target Annualized Volatility % (Only for vol_target)",
            "minimum": 5,
            "maximum": 80,
            "type": "number",
            "description": "Target annualized portfolio volatility percentage when strategy='vol_target'.",
            "default": 20
          },
          "cashYieldPct": {
            "title": "Defensive Cash / T-Bill Annual Yield (%)",
            "minimum": 0,
            "maximum": 10,
            "type": "number",
            "description": "Annualized Treasury Bill yield applied to defensive cash allocations during SMA/Vol-Target periods.",
            "default": 3.5
          },
          "transactionCostBps": {
            "title": "Transaction Cost & Slippage (bps per turnover)",
            "minimum": 0,
            "maximum": 100,
            "type": "number",
            "description": "One-way cost in basis points (10 bps = 0.10%) applied whenever positions rebalance or switch regimes.",
            "default": 10
          },
          "runMonteCarlo": {
            "title": "Run 1,000-Path Block-Bootstrap Monte Carlo Forecast",
            "type": "boolean",
            "description": "Simulates 1,000 forward multi-year paths from actual historical return blocks to estimate P10/P50/P90 ending wealth.",
            "default": true
          },
          "forecastYears": {
            "title": "Monte Carlo Horizon (Years)",
            "minimum": 1,
            "maximum": 20,
            "type": "integer",
            "description": "Number of forward years to simulate when runMonteCarlo=true.",
            "default": 5
          }
        }
      },
      "runsResponseSchema": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "actId": {
                "type": "string"
              },
              "userId": {
                "type": "string"
              },
              "startedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "finishedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "status": {
                "type": "string",
                "example": "READY"
              },
              "meta": {
                "type": "object",
                "properties": {
                  "origin": {
                    "type": "string",
                    "example": "API"
                  },
                  "userAgent": {
                    "type": "string"
                  }
                }
              },
              "stats": {
                "type": "object",
                "properties": {
                  "inputBodyLen": {
                    "type": "integer",
                    "example": 2000
                  },
                  "rebootCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "restartCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "resurrectCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "computeUnits": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "options": {
                "type": "object",
                "properties": {
                  "build": {
                    "type": "string",
                    "example": "latest"
                  },
                  "timeoutSecs": {
                    "type": "integer",
                    "example": 300
                  },
                  "memoryMbytes": {
                    "type": "integer",
                    "example": 1024
                  },
                  "diskMbytes": {
                    "type": "integer",
                    "example": 2048
                  }
                }
              },
              "buildId": {
                "type": "string"
              },
              "defaultKeyValueStoreId": {
                "type": "string"
              },
              "defaultDatasetId": {
                "type": "string"
              },
              "defaultRequestQueueId": {
                "type": "string"
              },
              "buildNumber": {
                "type": "string",
                "example": "1.0.0"
              },
              "containerUrl": {
                "type": "string"
              },
              "usage": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "integer",
                    "example": 1
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_UNBLOCKER_UNITS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "usageTotalUsd": {
                "type": "number",
                "example": 0.00005
              },
              "usageUsd": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "number",
                    "example": 0.00005
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_UNBLOCKER_UNITS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}