{"id":39824480,"url":"https://github.com/stepandel/backtestgpt","last_synced_at":"2026-01-18T13:03:11.406Z","repository":{"id":309228248,"uuid":"1035297387","full_name":"stepandel/backtestgpt","owner":"stepandel","description":"submission for openai gpt-5 hackathon","archived":false,"fork":false,"pushed_at":"2025-12-20T02:26:51.000Z","size":201,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-22T11:50:04.897Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://backtestgpt.vercel.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stepandel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-10T04:55:08.000Z","updated_at":"2025-12-20T02:26:50.000Z","dependencies_parsed_at":"2025-08-10T18:21:03.912Z","dependency_job_id":"b530469c-9029-40db-ad8f-4a578046c187","html_url":"https://github.com/stepandel/backtestgpt","commit_stats":null,"previous_names":["stepandel/backtestgpt"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stepandel/backtestgpt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepandel%2Fbacktestgpt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepandel%2Fbacktestgpt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepandel%2Fbacktestgpt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepandel%2Fbacktestgpt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stepandel","download_url":"https://codeload.github.com/stepandel/backtestgpt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepandel%2Fbacktestgpt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28536686,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T10:13:46.436Z","status":"ssl_error","status_checked_at":"2026-01-18T10:13:11.045Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-18T13:03:11.347Z","updated_at":"2026-01-18T13:03:11.399Z","avatar_url":"https://github.com/stepandel.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## BacktestGPT (Prototype)\n\nAn experimental Next.js + TypeScript app for LLM-assisted market event research and deterministic backtesting. The UI features a chat-driven planner, streaming reasoning and web search indicators, and a Wall Street–themed dashboard with an interactive equity curve.\n\n### Key Features\n\n- **Two‑stage planner**\n  - Stage 1: Interactive research chat with GPT‑5 + web search, streams responses and live status\n  - Stage 2: Structures the transcript into a strict `Plan[]` via a tool function\n- **Deterministic backtest** on daily OHLCV (Polygon SDK or mock), with per‑ticker stats\n- **Dashboard UI** with stats cards, a draggable‑handles equity curve, per‑ticker table, and a live ticker tape\n- **Streaming UX** with ephemeral “Reasoning …” and “Web search — status — query” indicators\n- **LocalStorage** persistence for chat, readiness flag, results, and price cache\n\n### Tech Stack\n\n- Next.js (App Router) + TypeScript\n- Tailwind CSS + shadcn/ui\n- OpenAI `responses` API (GPT‑5) with `web_search_preview`\n- `@polygon.io/client-js` for historical prices\n- SVG charting (custom) + `ResizeObserver`\n\n## Requirements\n\n- Node.js 18+\n- `pnpm` package manager\n- Optional env vars:\n  - `OPENAI_API_KEY` (to enable Stage 1 chat + Stage 2 structuring)\n  - `POLYGON_API_KEY` (for real price data; otherwise mock)\n\n## Quickstart\n\n1. Install dependencies\n\n```bash\npnpm install\n```\n\n2. Create an `.env.local` in the repo root (optional but recommended):\n\n```bash\nOPENAI_API_KEY=sk-...\nPOLYGON_API_KEY=...\n```\n\n3. Run the dev server\n\n```bash\npnpm dev\n```\n\nOpen `http://localhost:3000`.\n\n## Project Structure (selected)\n\n- `app/`\n  - `page.tsx`: main layout (chat left, dashboard right)\n  - `api/chat/route.ts`: Stage 1 research chat (streaming)\n  - `api/plan/route.ts`: Stage 2 plan structuring\n  - `api/run/route.ts`: backtest execution\n  - `api/quotes/route.ts`: mock quotes for ticker tape\n- `components/`\n  - `Chat.tsx`: chat UI, markdown rendering, streaming indicators\n  - `Results.tsx` + `ResultsView.tsx`: results container + view\n  - `Charts/EquityCurve.tsx`: interactive curve (draggable entry/exit)\n  - `TickerTape.tsx`, `Shell.tsx`, `StatsCards.tsx`, `Table.tsx`\n- `engine/`: strategy execution and compute\n- `lib/`: env, prices provider, and `mockCurve.ts`\n\n## Environment\n\n- `lib/env.ts` treats `OPENAI_API_KEY` and `POLYGON_API_KEY` as optional.\n  - Without `OPENAI_API_KEY`: `/api/chat` returns a message explaining chat is disabled.\n  - Without `POLYGON_API_KEY`: the backtest uses mock prices; the equity curve is always mock for demo.\n\n## Planner Flow\n\n- **Stage 1 (Chat)**: `POST /api/chat`\n  - Model: `gpt-5` + `web_search_preview` tool\n  - System prompt enforces: official sources only, ET timezone, max 5 tickers, markdown output, and to end with “Ready to finalize plan”.\n  - Streaming response:\n    - Answer deltas are sent as plain text\n    - Reasoning deltas are tagged as `[[R]]...`, with lifecycle markers `[[R:BEGIN]]` and `[[R:END]]`\n    - Web search status uses:\n      - `[[S:BEGIN]]`, `[[S:END]]`\n      - `[[S:STATUS:in_progress|searching|completed]]`\n      - `[[S:QUERY]]\u003cquery\u003e` (when available from the event)\n- **Stage 2 (Structuring)**: `POST /api/plan`\n  - Parses the Stage 1 transcript and calls GPT‑5 with the `officialEventExtractor` function tool\n  - Enforces max 5 tickers; returns `Plan[]`\n\n## Backtesting\n\n- `engine/compute.ts` runs a deterministic backtest on daily bars\n- `lib/prices.ts` fetches aggregates using `@polygon.io/client-js`\n- Stats: mean P\u0026L, median P\u0026L, hit rate with fraction, per‑ticker results\n- Equity curve: always uses `lib/mockCurve.ts` for demo visuals\n\n## UI/UX Notes\n\n- Chat renders assistant messages as Markdown (`react-markdown` + `remark-gfm` + `remark-breaks`)\n- Streaming indicators at the top of the chat area:\n  - “Reasoning: \u003clive text\u003e” (ephemeral)\n  - “Web search — \u003cstatus\u003e — \u003cquery\u003e” (ephemeral; briefly persists on completion)\n- Chat panel is resizable (collapsed / 1/3 / full) via `Shell.tsx`\n- Ticker tape in the header uses `/api/quotes` (mock)\n\n## Persistence (localStorage)\n\n- `chat:messages`: full chat history\n- `chat:ready`: whether Stage 1 ended with “Ready to finalize plan”\n- `backtest:data`: `{ plan, results }` from `/api/run`\n- `prices:cache`: cached price series (when available)\n- Reset via the “Reset” button in the chat footer\n\n## API Endpoints\n\n- `POST /api/chat` — body: `{ messages: { role, content }[] }` — streams `text/plain`\n- `POST /api/plan` — body: `{ transcript }` — returns `Plan[]`\n- `POST /api/run` — body: `{ plan }` — returns `{ results }`\n- `GET /api/quotes?tickers=...` — returns mock quotes for ticker tape\n\n## Troubleshooting\n\n- Polygon aggregates date format must be `YYYY-MM-DD` for `from`/`to`\n- If chat streaming stops unexpectedly, ensure `OPENAI_API_KEY` is set and the model is `gpt-5`\n- The app intentionally uses a mock equity curve for demo consistency\n\n## Scripts\n\nTypical Next.js scripts:\n\n```bash\npnpm dev         # start dev server\npnpm build       # build for production\npnpm start       # start production server\n```\n\n## License\n\nPrototype – not for production use.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstepandel%2Fbacktestgpt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstepandel%2Fbacktestgpt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstepandel%2Fbacktestgpt/lists"}