Working notes for agents contributing to this repository. Keep it concise, keep it accurate, and keep the core trading/accounting invariants intact.
- Event-driven backtesting library for quantitative trading written in Julia.
- Single netted
Positionper instrument; account state lives inAccount+CashLedger(balances, equities, margin vectors, trades, positions, cashflows). - Multi-currency aware; instruments carry lifecycle, contract kind, and settlement style (
PrincipalExchangeorVariationMargin), with margining per-currency or base-currency. - Broker hooks drive commissions and financing schedules.
- Public API is centralized in
src/Fastback.jl(exports and type aliasesPrice/Quantity=Float64).
src/: core types and logicFastback.jl: module includes + public exports.enums.jl,errors.jl: enum definitions and reject/error types.cash.jl,cashflows.jl,account.jl,exchange_rates.jl: cash ledger, cashflow records, account state, FX conversion helpers.instrument.jl,order.jl,trade.jl,position.jl: instrument metadata/lifecycle and order-trade-position math (netted exposure + stable average price semantics).contract_math.jl,execution.jl,risk.jl,logic.jl: pure settlement math, fill planning, risk checks, valuation/margin pipeline (fill_order!,roll_position!,settle_expiry!).interest.jl,borrow_fees.jl,funding.jl: financing accruals and funding cashflows.events.jl: typed event driver (MarkUpdate,FundingUpdate,FXUpdate) andprocess_step!loop helpers.margin.jl,liquidation.jl,invariants.jl: base-currency margin metrics, liquidation helpers, and account consistency checks.broker/*.jl: broker fee/financing profiles (NoOp,FlatFee,IBKRProFixed,Binance).collectors.jl,tables.jl,print.jl,analytics.jl,plots.jl: collectors, Tables.jl views, pretty-printing, perf summary, plotting extension hooks.backtest_runner.jl,utils.jl: threaded batch runner (Threads.@threads) and utility helpers.
test/: uses TestItemRunner and@testitemblocks; reconciliation data lives intest/data/.ext/: optional package extension(s), currentlyFastbackPlotsExt.jlfor Plots/StatsPlots-backed plotting methods.docs/: Documenter + Literate; walkthroughs indocs/src/examplesare rendered todocs/src/examples/gen, integration examples indocs/src/integrationsare rendered todocs/src/integrations/gen, and plotting examples indocs/src/plottingare rendered todocs/src/plotting/genbydocs/make.jl.justfile: shortcuts for docs (just build-docs,just serve-docs).CHANGELOG.md: release history; update alongside version bumps inProject.toml.
- Julia 1.9+ (per
Project.tomlcompat). - Install deps:
julia --project -e 'using Pkg; Pkg.instantiate()'. - For docs:
just build-docs(installs/uses docs environment). - Note that docs has its own project environment inside the
docsfolder.
- Full suite:
julia --project -e 'using Pkg; Pkg.test()'(runs TestItemRunner). - Targeted file:
julia --project -e 'using TestItemRunner; TestItemRunner.run_tests(\"test/account.jl\")'. - Set
JULIA_NUM_THREADSwhen touching threaded code; keep tests deterministic.
- Opt for efficient algorithms and approaches; prioritize clarity where possible.
- Maintain
Price/QuantityasFloat64; keep structs concrete for performance. - Follow existing docstring style (triple quotes, short summary, brief args/returns) and liberal
@inlineon tiny helpers. - Keep settlement semantics explicit: principal-exchange vs variation-margin paths must stay separate and deterministic.
- Preserve Tables.jl schemas (
balances_table,positions_table, etc.) and PrettyTables formatting behavior. - Add new public symbols to
src/Fastback.jlexports; mirror changes in docs/examples if user-facing. - No formatter configured—match existing spacing/line breaks; prefer 4-space indent and explicit typing.
- Add/modify walkthrough examples in
docs/src/examples, integration examples indocs/src/integrations, and plotting examples indocs/src/plotting; register them indocs/make.jlso both markdown and notebooks regenerate. - Regenerate docs after user-facing changes; assets/styles live under
docs/src/assets/. - Keep README badge/version in sync when releasing.
- Add
@testitemcoverage near changed code; use deterministic fixtures. - Guard against regressions in P&L, margin, settlement math, and financing accruals; compare to existing tests for patterns (
test/account.jl,test/position.jl,test/settlement_semantics.jl,test/events.jl). - Avoid shared mutable state in threaded workflows (
batch_backtest, collectors). - If touching accounting internals, sanity-check with
check_invariants(acc)in tests. - For releases: bump
Project.tomlversion, updateCHANGELOG.md(YYYY-MM-DD), and note breaking changes explicitly. - Hot-path code of the backtesting loop must be type stable, and is ideally allocation free. Avoid costly loops if possible.