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
+13-22Lines changed: 13 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,10 +9,6 @@ This library provides a lightweight framework for backtesting trading strategies
9
9
A strategy must conform to the following structure:
10
10
11
11
```python
12
-
classDecision:
13
-
target: WeightedPortfolio
14
-
notes: UniverseMapping[Any] |None=None
15
-
16
12
classStrategy(Protocol):
17
13
def__call__(
18
14
self,
@@ -23,39 +19,38 @@ class Strategy(Protocol):
23
19
) -> Decision: ...
24
20
```
25
21
26
-
_In short, a function is called a strategy as long as it takes the universe, the current holdings, a market view, and additional context as parameters, and returns a Decision (which wraps the target portfolio)._
22
+
_In short, a function is called a strategy as long as it takes the universe, the current holdings, a market view, and additional context as parameters, and returns a Decision, which can be constructed using the functions provided in the `decision` module, re-exported at the library root for convenience._
27
23
28
24
As inputs, the strategy receives the available universe, current holdings, a view of the market, and a context object for state.
29
25
30
-
For outputs, the strategy emits a Decision specifying the new target portfolio for each decision point in the _decision schedule_
26
+
For outputs, the strategy emits a Decision for each decision point in the _decision schedule_
31
27
32
28
An toy example strategy can be written as follows, where we allocate our holdings uniformly across our universe:
33
29
34
30
```python
35
-
import backtest_lib as btl
36
-
from backtest_lib.portfolio import uniform_portfolio
31
+
from backtest_lib import target_weights
37
32
38
33
defequal_weight_strategy(
39
34
universe,
40
35
current_portfolio,
41
36
market,
42
37
ctx,
43
38
):
44
-
returnbtl.Decision(uniform_portfolio(universe))
39
+
returntarget_weights({sec: 1/len(universe)for sec in universe})
45
40
```
46
41
47
42
Or alternatively, another trivial strategy where we do nothing after creating our initial portfolio:
0 commit comments