You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+98-6Lines changed: 98 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
</h1>
4
4
5
5
<palign="center">
6
-
<ialign="center">Create trading strategies. Compare them side by side. Pick the best one and Deploy 🚀</i>
6
+
<ialign="center">The full quant workflow in one framework: build strategies, vector & event-driven backtest at scale, compare in a single dashboard, and deploy the winner 🚀</i>
7
7
</p>
8
8
9
9
<h4align="center">
@@ -59,11 +59,11 @@
59
59
60
60
## Introduction
61
61
62
-
`Investing Algorithm Framework` is a Python framework for creating, backtesting, and deploying trading strategies.
62
+
`Investing Algorithm Framework` is a Python framework that covers the entire quant workflow: define a strategy once, vector-backtest thousands of parameter variants to find promising signals, narrow down with a storage layer that ranks 10k+ results in milliseconds, validate the winners in a realistic event-driven simulation, compare everything in a single interactive HTML dashboard, and deploy the best performer live, all with the same `TradingStrategy` class, no code rewrites between stages.
63
63
64
-
Most quant frameworks stop at "here's your backtest result." You get a number, maybe a chart, and then you're on your own figuring out which strategy is actually better.
64
+
Most quant frameworks stop at "here's your backtest result." You get a number, maybe a chart, and then you're on your own figuring out which strategy variant is actually better, whether the result is robust across time windows, and how to go from research to production. This framework closes that gap.
65
65
66
-
This framework is built around the full loop: **create strategies → vector backtest for signals analysis → compare them in a single report → event backtest the most promising strategies → deploy the winner.** It generates a self-contained HTML dashboard that lets you rank, filter, and visually compare every strategy you've tested — all in one view, no notebooks required.
66
+
> **Want to see this in practice?** Check out the [`examples/tutorial/`](examples/tutorial/README.md): a series of runnable notebooks that walk you through every stage: defining a strategy, visualizing its signals, sweeping parameters across rolling windows, detecting overfitting with Monte Carlo permutation tests, filtering and ranking with the storage layer, and deploying the winner.
67
67
68
68
<detailsopen>
69
69
<summary>
@@ -87,11 +87,91 @@ This framework is built around the full loop: **create strategies → vector bac
87
87
- 🗄️ **[Tiered Backtest Storage Layer](examples/storage_layer_demo/README.md)** — Manage thousands of `.iafbt` bundles with a Tier-1 SQLite index (sub-100 ms ranks/filters over 10k+ backtests), a swappable `BacktestStore` protocol (`LocalDirStore`, `LocalTieredStore`), content-addressed Tier-3 OHLCV deduplication, and a CLI (`iaf index` / `iaf list` / `iaf rank` / `iaf migrate-store`) that plugs straight into the HTML dashboard.
88
88
- 🌐 **[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
89
89
- � **[Per-Market Deposit Schedules & Portfolio Sync](https://coding-kitties.github.io/investing-algorithm-framework/Advanced%20Concepts/portfolio-sync)** — Declare recurring or one-shot external cash flows on a market with `deposit_schedule=` / `auto_sync=True`. Backtests simulate the deposits; live mode reconciles with the broker — same `context.sync_portfolio()` API in both modes.
90
-
- �📝 **[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()`
90
+
- 📝 **[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()`
91
+
- ⏱️ **Signal Cooldowns**: Throttle whipsaw with declarative `CooldownRule`s: per-symbol or portfolio-wide, side-aware (`trigger="sell"`, `blocks="buy"`), enforced identically by the vector and event-driven engines
91
92
- 🚀 **[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
92
93
93
94
</details>
94
95
96
+
<detailsopen>
97
+
<summary>
98
+
<strong>Strategy Definition</strong>
99
+
</summary> <br>
100
+
101
+
Declare **what data** your strategy needs and **when to buy or sell** as a `TradingStrategy` subclass — the framework wires up data loading, signal evaluation, order execution, position management, and reporting around it. The same class runs unchanged in vector backtests, event-driven backtests, paper trading and live.
102
+
103
+
Risk and execution behaviour are expressed as **declarative rule lists** rather than ad-hoc code paths, so the engines can enforce them identically across modes:
104
+
105
+
-**`position_sizes`**: [`PositionSize`](https://coding-kitties.github.io/investing-algorithm-framework/Risk%20Rules/position-size) per symbol (fixed amount or percentage of portfolio).
106
+
-**`stop_losses`** / **`take_profits`**: [`StopLossRule`](https://coding-kitties.github.io/investing-algorithm-framework/Risk%20Rules/stop-loss-rule) / [`TakeProfitRule`](https://coding-kitties.github.io/investing-algorithm-framework/Risk%20Rules/take-profit-rule) with fixed or trailing thresholds and partial-exit `sell_percentage`.
107
+
-**`scaling_rules`**: [`ScalingRule`](https://coding-kitties.github.io/investing-algorithm-framework/Risk%20Rules/scaling-rule) for pyramiding (`scale_in_percentage=[…]`, `max_entries`, per-symbol `cooldown_in_bars`).
108
+
-**`cooldowns`**: [`CooldownRule`](https://coding-kitties.github.io/investing-algorithm-framework/Risk%20Rules/cooldown-rule) to throttle whipsaw — per-symbol or portfolio-wide, side-aware (e.g. `trigger="sell", blocks="buy", bars=12`). Enforced bar-for-bar in both the vector and event-driven engines.
109
+
-**`trading_costs`**: [`TradingCost`](https://coding-kitties.github.io/investing-algorithm-framework/Risk%20Rules/trading-cost) per symbol (fees, slippage, fixed costs).
`CooldownRule` is a declarative, side-aware signal-throttling primitive. After a triggering order fills, the rule suppresses certain *new* signals for a configured number of bars — per symbol, or across the whole portfolio.
8
+
9
+
It is the symmetric, side-aware sibling of [`ScalingRule.cooldown_in_bars`](./scaling-rule.md), which only models a single both-sides, symbol-scoped cooldown that is restarted by *any* order. `CooldownRule` lets you say things like *"after a stop-out on BTC, don't re-enter BTC for 12 bars"* or *"after any order anywhere, throttle the whole portfolio for 2 bars"*.
10
+
11
+
```python
12
+
from investing_algorithm_framework import CooldownRule
13
+
```
14
+
15
+
## Signature
16
+
17
+
```python
18
+
CooldownRule(
19
+
*,
20
+
symbol: str|None=None,
21
+
trigger: str="any", # "buy" | "sell" | "any"
22
+
blocks: str="any", # "buy" | "sell" | "any"
23
+
bars: int=0,
24
+
)
25
+
```
26
+
27
+
| Parameter | Type | Default | Description |
28
+
|---|---|---|---|
29
+
|`symbol`|`str \| None`|`None`| Target symbol the rule applies to. `None` makes the rule **portfolio-scoped**: any qualifying order on any symbol restarts it, and any qualifying signal on any symbol is suppressed. |
30
+
|`trigger`|`str`|`"any"`| Order side that **starts** the cooldown timer. One of `"buy"`, `"sell"`, `"any"`. |
31
+
|`blocks`|`str`|`"any"`| Signal side this cooldown **suppresses**. One of `"buy"`, `"sell"`, `"any"`. |
32
+
|`bars`|`int`|`0`| Number of bars the cooldown lasts. `0` is a valid no-op (handy for tests / disabled rules). Must be `>= 0`. |
33
+
34
+
All arguments are keyword-only. Both `trigger` and `blocks` accept the strings shown above as well as `CooldownTrigger` / `CooldownBlocks` enum members.
35
+
36
+
## Window Semantics
37
+
38
+
The bar on which the order fills is treated as bar 0 of the cooldown. A rule with `bars=N` therefore **blocks the next `N` bars** and **allows the `(N+1)`th bar**:
39
+
40
+
```text
41
+
bar … fill +1 +2 +3 +4
42
+
┃ ┃ ┃ ┃
43
+
bars=3: block block block allow
44
+
```
45
+
46
+
Formally, the rule blocks signals when `bar_index − last_event < bars`.
Identical semantics in both backtest engines and live trading:
100
+
101
+
-**Vector backtest engine** — a single `CooldownTracker` is shared across symbols (so portfolio-scoped rules work). Suppressed signals are recorded in `signal_events` with `reason="in_cooldown_rule"` for inspection.
102
+
-**Event-driven backtest engine** and **live runtime** — the `TradingStrategy` increments an internal bar counter every `run_strategy()` call, gates buy / sell / scale-out at the relevant phase, and records every fill in the tracker.
103
+
104
+
## Interaction With Other Rules
105
+
106
+
-**`ScalingRule.cooldown_in_bars`** — both can coexist. `cooldown_in_bars` remains a fast both-sides per-symbol shortcut; `CooldownRule` is the way to express side- or portfolio-aware throttling. The more restrictive active rule wins.
107
+
-**`StopLossRule` / `TakeProfitRule`** — their fills count as `sell` events for cooldown bookkeeping. A typical pattern is `trigger="sell", blocks="buy"` so a stop-out doesn't immediately invite a re-entry on the next bar.
108
+
-**Scale-ins and scale-outs** — count as `buy` and `sell` events respectively for cooldown bookkeeping.
The framework lets you express risk and execution behaviour as **declarative rule lists** on a `TradingStrategy` rather than as ad-hoc code paths. The vector backtest engine, the event-driven backtest engine and the live trading runtime all read the same rule objects, so a strategy behaves identically across all three modes.
|`position_sizes`|[`PositionSize`](./position-size.md)| How much capital to allocate per symbol — fixed amount or percentage of portfolio. |
65
+
|`stop_losses`|[`StopLossRule`](./stop-loss-rule.md)| Bar-end exit when price drops a fixed or trailing percentage from entry / peak. |
66
+
|`take_profits`|[`TakeProfitRule`](./take-profit-rule.md)| Bar-end exit when price rises a fixed or trailing percentage from entry / peak. |
67
+
|`scaling_rules`|[`ScalingRule`](./scaling-rule.md)| Pyramid into winners and partially close — `max_entries`, `scale_in_percentage`, `scale_out_percentage`, optional `max_position_percentage` cap. |
68
+
|`cooldowns`|[`CooldownRule`](./cooldown-rule.md)| Side-aware, per-symbol or portfolio-wide signal throttling after fills. |
69
+
|`trading_costs`|[`TradingCost`](./trading-cost.md)| Per-symbol fees and slippage applied during fill simulation. |
0 commit comments