I’m trying to understand the recommended architecture for combining MoonshotML and Zipline.
My goal is:
- Use MoonshotML for vectorized ML research and model training.
- Potentially train an ensemble of models, for example multiple models trained on different features, horizons, regimes, or instruments.
- Use Zipline as the event-driven execution layer.
- In Zipline, run the trained model or model ensemble only when specific intraday conditions are met.
- Use the model output as one input into custom Zipline trade logic, including sizing, order placement, exits, cooldowns, and other stateful rules.
A simplified version would be:
def handle_data(context, data):
if trading_condition_occurs(data):
features = build_features_from_recent_history(data)
scores = [
model.predict_proba(features) for model in context.models
]
ensemble_score = combine_model_scores(scores)
if ensemble_score > threshold:
# custom Zipline execution logic
pass
My main question is:
Is there a supported or recommended way to call/reuse MoonshotML strategy logic directly inside a Zipline algorithm, including one or more trained models, or should MoonshotML mainly be used for research/training while Zipline separately loads the trained models and rebuilds the needed features using data.history() / data.current()?
Relatedly, should the feature engineering/model-scoring code be factored into shared Python modules that both MoonshotML and Zipline import, rather than trying to use a MoonshotML strategy class from inside Zipline?
Thanks.