Devlog #2 - Contango
Massive changes have been made relating to strategy creation & the capability of the framework.
Creating a strategy
An entire Bollinger Band Mean Reversion strategy now looks like this:
indicators = {"bb": BollingerBands(period=period, k=num_std)}
rules: Sequence[Rule[TradingContext, Intent]] = [
Rule(
Predicate(lambda ctx: ctx.event.close < ctx.indicators["bb"].value.lower),
Emit(EnterLongIntent(symbol=symbol))
),
Rule(
Predicate(lambda ctx: ctx.event.close > ctx.indicators["bb"].value.upper),
Emit(ExitIntent(symbol=symbol)),
)
]
super().__init__(
indicators=indicators,
rules=rules,
position_sizer=AllocationPositionSizer(size)
)
With this structure, an entire trading strategy can be expressed with a few unequivocal rules.
Further, because indicators and their parameters are major components, both can now be parameterized during optimization. That means grid searches can iterate over not only different parameter values, but entirely different indicator combinations.
In a favorable environment, this means that with enough computing power, you can automate the creation and development of strategies. However, in practice, real markets make this significantly less straightforward due to overfitting; therefore, human analysis is still essential since larger search spaces dramatically increase the risk of these biases. Nonetheless, this gives a major advantage to manually creating code for each strategy individually.
Other things
- I restructured the file tree to make the codebase easier for new future contributors (including myself) to make changes.
- I created a rule system for the backtester under the hood that doesn’t hard-code any limitations in preparation for full support of pyramiding, multiple tickers, & short selling.
Future
There are some things I want to do before shipping. I’ll list them here:
- Complete the indicator grid search mentioned above.
- Stress-test everything & create unit tests where necessary.
- Complete the documentation - especially with strategy creation, which is not definitely extensive enough as of now.
Anyway, enough technical talk for this devlog - happy coding!
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.