docs: add guided system and strategy walkthroughs
This commit is contained in:
parent
e4b31145da
commit
138aa047e2
5 changed files with 424 additions and 0 deletions
80
docs/guide/README.md
Normal file
80
docs/guide/README.md
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
# Understanding Stock Bot
|
||||
|
||||
Start here if you want to understand the repository before changing it. These guides describe the connected implementation as of **October 24, 2026**, with links to the code. They cover the stock platform; `apps/wcag-ada` is separate.
|
||||
|
||||
## The idea in one minute
|
||||
|
||||
You write a **TypeScript strategy** that looks at available market observations and asks for a desired position. The **Rust financial engine** decides whether that request is allowed, simulates execution, and updates money and positions. The **web application** lets you configure, run, compare and record this research.
|
||||
|
||||
The TypeScript backend connects those pieces. It saves exact inputs, dispatches jobs, supervises workers and records results. **PostgreSQL remembers what happened; Redis delivers work.** Historical prices are retained as hashed datasets so a later provider update does not silently change an old experiment.
|
||||
|
||||
In this repository, **canonical** means the supported, authoritative Rust financial path. You will also find older simulators and prototype interfaces. Their presence does not mean new web backtests use them.
|
||||
|
||||
## Read in this order
|
||||
|
||||
| Guide | Question it answers |
|
||||
| --- | --- |
|
||||
| 1. [System map](system-map.md) | What are the applications, libraries and databases, and how are they connected? |
|
||||
| 2. [Follow one backtest](backtest-walkthrough.md) | What happens between clicking Run and seeing a trade, result or failure? |
|
||||
| 3. [Understand and write a strategy](strategy-development.md) | Where does my trading logic go, what can it access, and what does it return? |
|
||||
|
||||
Read the diagrams and examples first. Follow the source links when a component becomes relevant; you do not need to understand every library before writing a strategy.
|
||||
|
||||
## A first tour through the product
|
||||
|
||||
When your local application is configured and running:
|
||||
|
||||
1. Open **Strategies**. Inspect a strategy family and an immutable version. Notice the parameters and executable identity; editing a new version must not change old runs.
|
||||
2. Open **Backtests**. A saved backtest is a reusable configuration. Its run history contains individual executions. Select an existing run before trying to configure a new one.
|
||||
3. On a run, inspect its inputs, status, provenance, equity and trades. Check whether it completed and which engine/policies produced it before interpreting its metrics. Older results retain their qualifications.
|
||||
4. Open **Experiments**. These group related trials, such as a parameter sweep. Follow a trial back to its individual run; comparison is not a separate simulator.
|
||||
5. Open **Research**. A project collects hypotheses and findings linked to evidence. An AI-written hypothesis or conclusion is still a claim; the cited runs are the inspectable evidence.
|
||||
|
||||
With an empty database, those pages may have no saved records yet. The walkthrough and test fixture below let you understand the flow without fetching market data. Creating a run requires a retained dataset and an eligible strategy version, not just a ticker symbol.
|
||||
|
||||
The standalone **Portfolio**, **Analytics** and **Settings** routes are currently placeholders. Run and experiment pages contain the implemented research analytics. See the [route map](../../apps/stock/web-app/src/app/App.tsx) for what each URL opens.
|
||||
|
||||
## Names you will see
|
||||
|
||||
| Term | Meaning here |
|
||||
| --- | --- |
|
||||
| **Strategy family / version** | A family organizes related revisions. A version pins a particular strategy definition and parameter contract. A run records the selected version and parameter values. |
|
||||
| **Backtest template** | A saved configuration you can edit and use to submit runs. Editing it does not rewrite a submitted run's inputs. |
|
||||
| **Run / attempt** | A run is one logical trial with frozen inputs. An attempt is one worker's claimed execution of it. Recovery can create another attempt without creating a different research question. |
|
||||
| **Retained dataset** | Exact validated bars and metadata, saved under a content hash. Provider storage is the mutable source; retention supplies the research snapshot. |
|
||||
| **Experiment** | A set of related runs with a saved comparison or search configuration. It can compare strategy candidates without combining their accounts. |
|
||||
| **Hypothesis / finding** | The question you propose and the conclusion you record. Findings can cite exact runs and artifacts. Neither is automatically proof of a successful strategy. |
|
||||
| **Intent / order / fill** | The strategy's desired exposure, the engine's executable instruction, and an actual simulated execution. An accepted intent is not a guaranteed fill. |
|
||||
| **Position / owner** | A held quantity and the strategy instance responsible for it. Financial attribution uses ownership rather than assuming every trade in a symbol belongs to the same strategy. |
|
||||
| **Event time / availability time** | When a market event happened versus when its information may be used. A completed bar cannot inform a decision before it becomes available. |
|
||||
| **Paper deployment** | A separately reviewed, explicitly activated paper account workflow. A completed research run does not activate it. |
|
||||
|
||||
## Learn from a small executable example
|
||||
|
||||
Start with the [SMA fixture](../../test/fixtures/canonical-sma.ts), then its [strategy](../../apps/stock/orchestrator/src/strategies/canonical-sma.ts) and [regression tests](../../test/integration/canonical-sma.test.ts). It uses seven bars and hand-checkable trades. The walkthrough explains why the final equity is `9969.30` from `10000` starting capital.
|
||||
|
||||
From the repository root, after dependencies and workspace/native builds are available:
|
||||
|
||||
```sh
|
||||
bun test test/integration/canonical-sma.test.ts
|
||||
```
|
||||
|
||||
This fixture does not need a provider connection or running databases. For initial build requirements and the broader check commands, use the [root README](../../README.md#build-and-verify).
|
||||
|
||||
## What is available, and what is still constrained
|
||||
|
||||
- New web research runs use one execution asset and one retained series, with cash-funded, long-only financial policies. Lower-level multi-asset contracts and tests do not make multi-asset web admission available.
|
||||
- TypeScript callback strategies, retained candidate packages, parameter sweeps, chronological validation, walk-forward studies and cost comparisons are connected research paths. The guides explain their boundaries rather than claiming every strategy or market model is supported.
|
||||
- Research workers can execute independent trials concurrently. That does not mean multiple workers can mutate the same account simultaneously.
|
||||
- Paper trading requires separate configuration, reviewed code and explicit human activation. Live trading is disabled; there is no connected real-broker execution adapter.
|
||||
- A large declarative strategy language and shared feature-cache framework are not required to understand or use the current callback path.
|
||||
|
||||
## Deeper references
|
||||
|
||||
- [Calculation library](../../libs/calculations/README.md): reviewed indicators and analytics, plus clearly separated preserved legacy functions.
|
||||
- [TypeScript strategy contract](../../apps/stock/orchestrator/src/contracts/canonical-strategy.ts): the actual callback context and output types.
|
||||
- [Research product reference](../development/architecture/research-product.md): API policies, provenance and paper setup. Its original design examples and later implementation notes need to be read in context.
|
||||
- [Architecture decisions](../development/architecture/decisions): why the boundaries were chosen. These record decisions and migration context, not a substitute for the current runtime map.
|
||||
- [Backlog](../development/backlog/README.md) and [roadmap](../development/ROADMAP.md): work history, completion evidence and conditional future tasks.
|
||||
|
||||
When documentation and an implementation disagree, follow the current entrypoint, contract and focused regression test. Historical plans explain the direction; these guides explain how the current pieces fit together.
|
||||
Loading…
Add table
Add a link
Reference in a new issue