Skip to content

Project Structure

Sergey Gerasimov edited this page Oct 22, 2026 · 3 revisions

Project Structure

DerivLab/
├── app.py                       # Streamlit entry point
├── derivlab/
│   ├── config.py                # assets, scenarios, copy, version
│   ├── data_fetcher.py          # yfinance, cache, seed, fallback
│   ├── strategies.py            # plans, legs, Black-Scholes, Greeks
│   ├── backtest_engine.py       # Backtrader controller, ledger, event bridge
│   ├── game_mode.py             # scenario game state machine
│   ├── metrics.py               # performance metrics and game score
│   ├── charts.py                # Plotly figures
│   ├── theme.py                 # cyberpunk CSS and components
│   ├── ui.py                    # six screens and navigation
│   └── agents/
│       ├── llm.py               # provider settings, HTTP client, model catalog
│       ├── personas.py          # desks, context, policies, decision prompt
│       ├── bridge.py            # async Backtrader event bridge
│       ├── commentary.py        # critic report, NewsWire, fallbacks
│       ├── arena.py             # four-desk arena, scoring, triggers
│       └── parsing.py           # tolerant JSON extraction
├── tests/                       # 247 offline tests
├── .github/workflows/           # CI and CodeQL
├── .devcontainer/               # reproducible Dev Container
├── docs/
│   ├── screenshots/             # README/Wiki imagery
│   └── demo/                    # MP4, GIF, poster
├── data/
│   ├── seed/                    # committed demo snapshot
│   └── cache/                   # per-machine cache (gitignored)
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
├── requirements-dev.txt
├── CHANGELOG.md
└── README.md

Responsibilities

Path Responsibility
ui.py Screen composition, session state, live game fragment
backtest_engine.py Event loop, ledger, NAV, trade metadata, bridge events
strategies.py Position sizing, option legs, pricing, Greeks
data_fetcher.py Source precedence, Parquet I/O, retry behavior
agents/arena.py Four-desk orchestration, ranking, payload, model stack
agents/llm.py OpenAI-compatible/Anthropic calls, timeouts, fallbacks
agents/commentary.py Strict report/news contracts and local fallbacks

Adding a strategy

  1. Add the strategy key and education copy in config.py and strategies.py.
  2. Implement the plan/legs and any strategy-specific ledger logic.
  3. Add a policy branch if an AI desk should use it.
  4. Extend tests in tests/test_strategies.py, test_backtest_engine.py, and test_agents.py.
  5. Update Strategies and the README tour if it is user-facing.

Adding a model provider

  1. Add the provider label and base URL/default models in agents/llm.py.
  2. Implement the request/response shape in LLMClient.
  3. Add a mocked HTTP test.
  4. Document it in AI Model Guide.

Clone this wiki locally