Created
November 5, 2020 09:15
-
-
Save ntakouris/d235c2cb48a58dcb5eb33f35404be408 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StrategyState: | |
# immutable. each new version is made through a series of recorded actions | |
# and a new copy is produced | |
@classmethod | |
def load(bytes): # or json or sth | |
pass | |
class TradingContext: | |
# provides states, action handlers | |
# behind the scenes propagates to different systems (filesystem, dbs, callbacks) via config | |
# also add: metrics to track (even custom ones supported) | |
@property | |
def state(): | |
return None # returns a copy of current state. Immutability! | |
class Strategy: | |
@property | |
def bar_requirements(): | |
return ['binance--btceur@5m:close'] # or some similar manifest for requested bars | |
@property | |
def version(): | |
return 'v1.1' | |
@classmethod #? could also be a function. This should be STATELESS | |
async def on_bars(ctx, bars, state): | |
# can also support probabilistic programming iwth dual-numbers | |
if await ctx.buy_order(...): | |
# handle failures too (optional) | |
if await ctx.sell_order(...): | |
# commits changes to the state on the end, as a transaction | |
async def main(): | |
# this is the `dataset object` | |
bar_generator = Bars.from_csv() # or Bars.from_feed(BinanceFeed) or whatever | |
# or BinanceLiveActionHandler() | |
state = #... load from some or new | |
strategy = #... | |
ctx = TradingContext(initial_state=state, strategy, action_handler, Modes.BACKTEST) | |
# sensible defaults, but also configurable: | |
# logging, saving state to files, to a db (with a callback, like the keras api) | |
# callbacks can also livestream results to any service | |
# bar generator can also be loaded given a manifest of bars needed from the strategy, | |
# there can be a registry for all the available column keys that are available on the fastquant api | |
# this should be open for extension. | |
await for bar in bar_generator: # start resume embedded in the async generator | |
await ctx.on_bars(bar) | |
# at any time you can check ctx status | |
await ctx.stats.<something> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment