Skip to content

Commit 41de19f

Browse files
committed
docs: add metrics reference page and link feature bullets
- Add Getting Started/metrics.md with full BacktestMetrics + BacktestSummaryMetrics field reference, conventions, and examples - Add Backtest.get_backtest_summary() getter for symmetry with the other run/metrics getters - Wire metrics page into sidebar - README: link feature bullets to docs pages, fix mojibake characters - Application setup: format folder tree, fix notebook table, rewrite MyStrategy example using declarative API - CLI init: scaffold recommended project layout (data/, backtest_results/, reports/, resources/, notebooks) and emit declarative strategy template - Templates: rewrite strategy.py / app_*.py / function_app.py / host.json for current declarative API and Azure Functions v2 model - deploy_to_azure_function: add readiness polling, --build remote --python, bump runtime to 3.11, fix CORS process await bug
1 parent 6ef9cc7 commit 41de19f

23 files changed

Lines changed: 1138 additions & 427 deletions

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,23 @@ This framework is built around the full loop: **create strategies → vector bac
7070
Features
7171
</summary> <br>
7272

73-
- 📊 **30+ Metrics** — CAGR, Sharpe, Sortino, Calmar, VaR, CVaR, Max DD, Recovery & more
73+
- 📊 **[30+ Metrics](https://coding-kitties.github.io/investing-algorithm-framework/Getting%20Started/metrics)** — CAGR, Sharpe, Sortino, Calmar, VaR, CVaR, Max DD, Recovery & more
7474
- 🧮 **[Cross-Sectional Pipelines](https://coding-kitties.github.io/investing-algorithm-framework/Advanced%20Concepts/pipelines)** — Rank, filter and score entire universes of symbols every iteration with a tidy factor table
75-
-**Vector Backtesting for Signal Analysis** — Quickly test your strategy logic on historical data to see how signals would have behaved before committing to full event-driven backtests
76-
- 🏃 **Event-Driven Backtesting** — Once promising strategies are identified via vector backtests, run full event-driven backtests to simulate realistic execution and portfolio management
77-
- 🔀 **Permutation Testing / Monte Carlo Simulations** — Assess the statistical robustness of your strategies by running them across randomized market scenarios to see how often your results could occur by chance
78-
- 🚀 **Deployment** — Once the best strategy is identified through backtesting and comparison, deploy it to production locally or in the cloud (AWS Lambda / Azure Functions) to start live trading
79-
- ⚔️ **Multi-Strategy Comparison** — Rank, filter & compare strategies in a single interactive report
80-
- 🪟 **Multi-Window Robustness** — Test across different time periods with window coverage analysis
81-
- 📈 **Equity & Drawdown Charts** — Overlay equity curves, rolling Sharpe, drawdown & return distributions
82-
- 🗓️ **Monthly Heatmaps & Yearly Returns** — Calendar heatmap per strategy with return/growth toggles
83-
- 🎯 **Return Scenario Projections** — Good, average, bad & very bad year projections from backtest data
84-
- 📉 **Benchmark Comparison** — Beat-rate analysis vs Buy & Hold, DCA, risk-free & custom benchmarks
85-
- 📄 **One-Click HTML Report** — Self-contained file, no server, dark & light theme, shareable
86-
- 📦 **Custom `.iafbt` Backtest Bundle Format** — An explicit, versioned, compressed, language-portable container (zstd + msgpack with magic-byte header) plus a separate parquet index for fast filtering without loading. ~21× smaller and ~27× fewer files than standard filebased directory layouts, with parallel I/O for fast load/save of large amounts of backtests.
87-
- 🌐 **Load External Data** — Fetch CSV, JSON, or Parquet from any URL with caching and auto-refresh
88-
- **[Record Custom Variables](https://coding-kitties.github.io/investing-algorithm-framework/Advanced%20Concepts/recording-variables)** — Track any indicator or metric during backtests with `context.record()`
89-
- 🚀 **Build → Backtest → Deploy** — Local dev, cloud deploy (AWS / Azure), or monetize on Finterion
75+
-**[Vector Backtesting for Signal Analysis](https://coding-kitties.github.io/investing-algorithm-framework/Getting%20Started/vector-backtesting)** — Quickly test your strategy logic on historical data to see how signals would have behaved before committing to full event-driven backtests
76+
- 🏃 **[Event-Driven Backtesting](https://coding-kitties.github.io/investing-algorithm-framework/Getting%20Started/event-backtesting)** — Once promising strategies are identified via vector backtests, run full event-driven backtests to simulate realistic execution and portfolio management
77+
- 🔀 **[Permutation Testing / Monte Carlo Simulations](https://coding-kitties.github.io/investing-algorithm-framework/Getting%20Started/backtest-reports)** — Assess the statistical robustness of your strategies by running them across randomized market scenarios to see how often your results could occur by chance
78+
- 🚀 **[Deployment](https://coding-kitties.github.io/investing-algorithm-framework/Getting%20Started/deployment)** — Once the best strategy is identified through backtesting and comparison, deploy it to production locally or in the cloud (AWS Lambda / Azure Functions) to start live trading
79+
- ⚔️ **[Multi-Strategy Comparison](https://coding-kitties.github.io/investing-algorithm-framework/Getting%20Started/backtest-reports)** — Rank, filter & compare strategies in a single interactive report
80+
- 🪟 **[Multi-Window Robustness](https://coding-kitties.github.io/investing-algorithm-framework/Getting%20Started/backtest-reports)** — Test across different time periods with window coverage analysis
81+
- 📈 **[Equity & Drawdown Charts](https://coding-kitties.github.io/investing-algorithm-framework/Getting%20Started/backtest-reports)** — Overlay equity curves, rolling Sharpe, drawdown & return distributions
82+
- 🗓️ **[Monthly Heatmaps & Yearly Returns](https://coding-kitties.github.io/investing-algorithm-framework/Getting%20Started/backtest-reports)** — Calendar heatmap per strategy with return/growth toggles
83+
- 🎯 **[Return Scenario Projections](https://coding-kitties.github.io/investing-algorithm-framework/Getting%20Started/backtest-reports)** — Good, average, bad & very bad year projections from backtest data
84+
- 📉 **[Benchmark Comparison](https://coding-kitties.github.io/investing-algorithm-framework/Getting%20Started/backtest-reports)** — Beat-rate analysis vs Buy & Hold, DCA, risk-free & custom benchmarks
85+
- 📄 **[One-Click HTML Report](https://coding-kitties.github.io/investing-algorithm-framework/Getting%20Started/backtest-reports)** — Self-contained file, no server, dark & light theme, shareable
86+
- 📦 **[Custom `.iafbt` Backtest Bundle Format](https://coding-kitties.github.io/investing-algorithm-framework/Data/backtest_data)** — An explicit, versioned, compressed, language-portable container (zstd + msgpack with magic-byte header) plus a separate parquet index for fast filtering without loading. ~21× smaller and ~27× fewer files than standard filebased directory layouts, with parallel I/O for fast load/save of large amounts of backtests.
87+
- 🌐 **[Load External Data](https://coding-kitties.github.io/investing-algorithm-framework/Data/external-data)** — Fetch CSV, JSON, or Parquet from any URL with caching and auto-refresh
88+
- 📝 **[Record Custom Variables](https://coding-kitties.github.io/investing-algorithm-framework/Advanced%20Concepts/recording-variables)** — Track any indicator or metric during backtests with `context.record()`
89+
- 🚀 **[Build → Backtest → Deploy](https://coding-kitties.github.io/investing-algorithm-framework/Getting%20Started/application-setup)** — Local dev, cloud deploy (AWS / Azure), or monetize on Finterion
9090

9191
</details>
9292

docusaurus/docs/Getting Started/application-setup.md

Lines changed: 208 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,125 +4,256 @@ sidebar_position: 2
44

55
# Application Setup
66

7-
Learn how to set up your first trading application using the Investing Algorithm Framework.
8-
9-
## Creating Your First App
7+
A real trading project usually has three concerns that pull in different
8+
directions:
9+
10+
1. **Research**: exploring data, designing strategies and tuning parameters
11+
in Jupyter notebooks.
12+
2. **Backtesting**: running reproducible historical simulations from a
13+
script.
14+
3. **Production**: running the strategy live, deployed somewhere stable, with
15+
secrets, logging and a single entry point.
16+
17+
The Investing Algorithm Framework is designed to support all three from the
18+
**same** strategy code. To make that work, we recommend the following
19+
project layout for any non-trivial bot.
20+
21+
## Recommended Project Structure
22+
23+
```text
24+
my_trading_bot/
25+
├── app.py # Production entry point (live trading)
26+
├── strategies/ # Strategy implementations (importable package)
27+
│ ├── __init__.py
28+
│ └── my_strategy.py
29+
├── data_providers.py # Custom data providers for your dataSource definitions in your strategies (OPTIONAL)
30+
├── notebooks/ # Research notebooks and backtest analyses
31+
│ ├── 01_data_exploration.ipynb
32+
│ ├── 02_backtest_baseline.ipynb
33+
│ ├── 03_in_sample_param_grid_search.ipynb
34+
│ ├── 04_out_of_sample_param_grid_search.ipynb
35+
│ ├── 05_overfitting_analysis.ipynb
36+
│ └── 06_event_backtests.ipynb
37+
├── data/ # Downloaded market data (OHLCV, etc.)
38+
├── backtest_results/ # Saved backtest bundles (.iafbt)
39+
├── reports/ # Generated reports (HTML, CSV, etc.)
40+
├── resources/ # Misc assets (databases, configs)
41+
├── requirements.txt
42+
├── .env.example
43+
└── README.md
44+
```
1045

11-
The framework provides a simple `create_app()` function to initialize your trading application:
46+
A working example of this layout lives in
47+
[`examples/tutorial`](https://github.com/coding-kitties/investing-algorithm-framework/tree/main/examples/tutorial).
1248

13-
```python
14-
from investing_algorithm_framework import create_app
49+
You can scaffold this structure with the framework's CLI:
1550

16-
app = create_app()
51+
```bash
52+
investing-algorithm-framework init --path ./my_trading_bot
1753
```
1854

19-
## Adding a Market
55+
This creates the above files and folders, with `app.py` and a sample strategy
56+
that you can modify. The `notebooks/` folder is left empty for you to fill with your research work.
2057

21-
Before you can trade, you need to add a market configuration:
58+
### Why this layout?
2259

23-
```python
24-
app.add_market(
25-
market="bitvavo",
26-
trading_symbol="EUR",
27-
)
28-
```
60+
- **`strategies/` is a package, not a script.** Both `app.py` (production)
61+
and `notebooks` import the same strategy class, so
62+
what you backtest is *exactly* what you deploy.
63+
- **`notebooks/` is for exploration and backtesting only.** Notebooks should `import`
64+
from `strategies/` and `data_providers.py` — never copy-paste strategy
65+
code into a cell. This keeps research and production in sync.
66+
- **`data/` and `backtest_results/` are caches.** They should usually
67+
be in `.gitignore`. The framework writes data downloads to `data/`
68+
and backtest bundles to `backtest_results/`.
69+
- **`app.py` does only what production needs** — load config, register
70+
the market and strategy, call `app.run()`. Nothing else.
71+
72+
## The Strategy (`strategies/my_strategy.py`)
2973

30-
## Adding a Strategy
74+
This is the only file that contains your trading logic. It is imported
75+
by `app.py`, `run_backtest.py` and your notebooks alike.
3176

32-
Register your trading strategy with the application:
77+
A strategy is **declarative**: you describe *what data you need* and *when
78+
to buy or sell*, and the framework takes care of order routing, position
79+
sizing, stop-losses and take-profits. The two functions you implement are
80+
`generate_buy_signals` and `generate_sell_signals` — both return a
81+
boolean `pd.Series` per symbol.
3382

3483
```python
35-
from investing_algorithm_framework import TradingStrategy, TimeUnit
84+
from typing import Any, Dict
85+
86+
import pandas as pd
87+
from pyindicators import sma, crossover, crossunder
88+
89+
from investing_algorithm_framework import (
90+
TradingStrategy,
91+
DataSource,
92+
DataType,
93+
TimeUnit,
94+
)
95+
3696

3797
class MyStrategy(TradingStrategy):
3898
time_unit = TimeUnit.HOUR
3999
interval = 2
40100
symbols = ["BTC"]
41-
42-
def run(self, algorithm):
43-
# Your trading logic here
44-
pass
45101

46-
app.add_strategy(MyStrategy())
102+
data_sources = [
103+
DataSource(
104+
identifier="btc_ohlcv_1h",
105+
data_type=DataType.OHLCV,
106+
symbol="BTC/EUR",
107+
time_frame="1h",
108+
market="BITVAVO",
109+
window_size=200,
110+
pandas=True,
111+
),
112+
]
113+
114+
def generate_buy_signals(
115+
self, data: Dict[str, Any]
116+
) -> Dict[str, pd.Series]:
117+
df = data["btc_ohlcv_1h"]
118+
df = sma(df, period=20, source_column="Close", result_column="sma_fast")
119+
df = sma(df, period=50, source_column="Close", result_column="sma_slow")
120+
df = crossover(df, "sma_fast", "sma_slow", result_column="cross_up")
121+
122+
return {"BTC": df["cross_up"].fillna(False).astype(bool)}
123+
124+
def generate_sell_signals(
125+
self, data: Dict[str, Any]
126+
) -> Dict[str, pd.Series]:
127+
df = data["btc_ohlcv_1h"]
128+
df = sma(df, period=20, source_column="Close", result_column="sma_fast")
129+
df = sma(df, period=50, source_column="Close", result_column="sma_slow")
130+
df = crossunder(df, "sma_fast", "sma_slow", result_column="cross_down")
131+
132+
return {"BTC": df["cross_down"].fillna(False).astype(bool)}
47133
```
48134

49-
## Running the Application
135+
> The framework instantiates the class for you, so pass the **class**
136+
> (not an instance) to `app.add_strategy(...)`.
50137
51-
### Live Trading
138+
The same `generate_buy_signals` / `generate_sell_signals` functions are
139+
used by **both** the vector backtest engine and the event-driven engine,
140+
which is what guarantees that what you backtest is what you deploy. For
141+
custom entry/exit logic that doesn't fit signals (e.g. rebalancing across
142+
symbols), override `run_strategy` instead see [Strategies](./strategies)
143+
for advanced patterns including position sizing, stop-loss, take-profit
144+
and scale-in rules.
52145

53-
To start live trading:
146+
## The Production Entry Point (`app.py`)
147+
148+
`app.py` is the file you run in production (locally, in a container, or as
149+
a serverless function). It should be small, declarative, and free of any
150+
research code.
54151

55152
```python
56-
app.run()
57-
```
153+
import logging.config
58154

59-
### Backtesting
155+
from dotenv import load_dotenv
60156

61-
To run a backtest:
157+
from investing_algorithm_framework import create_app, DEFAULT_LOGGING_CONFIG
62158

63-
```python
64-
from datetime import datetime, timezone
65-
from investing_algorithm_framework import BacktestDateRange
159+
from strategies.my_strategy import MyStrategy
66160

67-
backtest_range = BacktestDateRange(
68-
start_date=datetime(2023, 1, 1, tzinfo=timezone.utc),
69-
end_date=datetime(2024, 1, 1, tzinfo=timezone.utc)
70-
)
161+
load_dotenv()
162+
logging.config.dictConfig(DEFAULT_LOGGING_CONFIG)
71163

72-
backtest = app.run_backtest(
73-
backtest_date_range=backtest_range,
74-
initial_amount=1000
164+
app = create_app()
165+
app.add_market(
166+
market="bitvavo",
167+
trading_symbol="EUR",
168+
initial_balance=1000,
75169
)
170+
app.add_strategy(MyStrategy)
171+
172+
173+
if __name__ == "__main__":
174+
app.run()
76175
```
77176

78-
## Complete Example
177+
API keys belong in environment variables (`.env`), not in source. Use
178+
`.env.example` to document which variables are required.
79179

80-
Here's a complete example bringing it all together:
180+
## The Backtest Entry Point (`run_backtest.py`)
181+
182+
`run_backtest.py` mirrors `app.py` but calls `run_backtest(...)` instead
183+
of `run()`. Because both files import the same `MyStrategy`, the strategy
184+
under test is identical to the one that will run live.
81185

82186
```python
83-
from investing_algorithm_framework import (
84-
create_app,
85-
TradingStrategy,
86-
TimeUnit,
87-
BacktestDateRange
88-
)
89187
from datetime import datetime, timezone
90188

91-
# Create the application
92-
app = create_app()
189+
from investing_algorithm_framework import create_app, BacktestDateRange
93190

94-
# Define your strategy
95-
class SimpleStrategy(TradingStrategy):
96-
time_unit = TimeUnit.HOUR
97-
interval = 4
98-
symbols = ["BTC", "ETH"]
99-
100-
def run(self, algorithm):
101-
for symbol in self.symbols:
102-
# Your trading logic
103-
pass
104-
105-
# Add market and strategy
191+
from strategies.my_strategy import MyStrategy
192+
193+
app = create_app()
106194
app.add_market(market="bitvavo", trading_symbol="EUR")
107-
app.add_strategy(SimpleStrategy())
195+
app.add_strategy(MyStrategy)
108196

109-
# Run backtest
110-
backtest_range = BacktestDateRange(
111-
start_date=datetime(2023, 1, 1, tzinfo=timezone.utc),
112-
end_date=datetime(2024, 1, 1, tzinfo=timezone.utc)
113-
)
114197

115-
backtest = app.run_backtest(
116-
backtest_date_range=backtest_range,
117-
initial_amount=1000
118-
)
198+
if __name__ == "__main__":
199+
backtest_date_range = BacktestDateRange(
200+
start_date=datetime(2023, 1, 1, tzinfo=timezone.utc),
201+
end_date=datetime(2024, 1, 1, tzinfo=timezone.utc),
202+
)
203+
204+
backtest = app.run_backtest(
205+
backtest_date_range=backtest_date_range,
206+
initial_amount=1000,
207+
)
119208

120-
print(f"Total return: {backtest.get_total_return()}%")
209+
summary = backtest.backtest_summary
210+
print(f"Total return: {summary.total_growth_percentage:.2f}%")
211+
print(f"Sharpe ratio: {summary.sharpe_ratio:.2f}")
121212
```
122213

123-
## Next Steps
214+
## The Notebooks (`notebooks/`)
124215

125-
- Learn about [Portfolio Configuration](./portfolio-configuration) to manage your assets
126-
- Explore [Strategies](./strategies) for advanced strategy development
127-
- Check out [Backtesting](./backtesting) for comprehensive testing
216+
Notebooks are for research, backtesting, data exploration, signal visualisation,
217+
parameter sweeps, robustness checks, final reporting. They should
218+
**import** strategies from your `strategies/` package rather than
219+
redefining them.
220+
221+
A typical progression (mirroring `examples/tutorial/notebooks/`):
222+
223+
| Notebook | Purpose |
224+
| --- | --- |
225+
| `01_data_exploration.ipynb` | Download OHLCV, inspect coverage, detect and fill gaps |
226+
| `02_backtest_baseline.ipynb` | Single vector backtest of the strategy with default parameters + HTML report |
227+
| `03_in_sample_param_grid_search.ipynb` | Grid search across thousands of parameter combinations on the in-sample window |
228+
| `04_out_of_sample_param_grid_search.ipynb` | Re-run top in-sample candidates on the held-out out-of-sample window |
229+
| `05_overfitting_analysis.ipynb` | Compare in-sample vs out-of-sample performance, walk-forward / permutation checks |
230+
| `06_event_backtests.ipynb` | Validate the final picks with the event-driven engine (fees, slippage, fills) |
231+
232+
See the [tutorial README](https://github.com/coding-kitties/investing-algorithm-framework/tree/main/examples/tutorial)
233+
for fully worked-out versions.
234+
235+
## Running the Application
236+
237+
### Live trading
238+
239+
```bash
240+
python app.py
241+
```
242+
243+
### Research and backtesting
244+
245+
```bash
246+
jupyter lab notebooks/
247+
```
248+
249+
## Next Steps
128250

251+
- [Strategies](./strategies) — designing the `run_strategy` body, declaring
252+
data sources, position sizing, stop-losses and take-profits.
253+
- [Portfolio Configuration](./portfolio-configuration) — fees, slippage,
254+
multi-market portfolios.
255+
- [Event Backtesting](./event-backtesting) and
256+
[Vector Backtesting](./vector-backtesting) — the two backtest engines
257+
and when to use which.
258+
- [Deployment](./deployment) — packaging `app.py` for AWS Lambda, Azure
259+
Functions or a long-running container.

docusaurus/docs/Getting Started/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Install the latest stable version from PyPI:
2424
pip install investing-algorithm-framework
2525
```
2626

27-
This installs the core framework with CCXT support for crypto exchanges.
27+
This installs the core framework with [CCXT](https://github.com/ccxt/ccxt) support.
2828

2929
### Optional Data Provider Extras
3030

0 commit comments

Comments
 (0)