All Projects → quantrocket-llc → Moonshot

quantrocket-llc / Moonshot

Licence: apache-2.0
Vectorized backtester and trading engine for QuantRocket

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Moonshot

Quantdom
Python-based framework for backtesting trading strategies & analyzing financial markets [GUI ]
Stars: ✭ 449 (+410.23%)
Mutual labels:  algorithmic-trading, quantitative-finance, trading-platform
Elitequant
A list of online resources for quantitative modeling, trading, portfolio management
Stars: ✭ 1,823 (+1971.59%)
Mutual labels:  algorithmic-trading, quantitative-finance, trading-platform
Quant
Codera Quant is a Java framework for algorithmic trading strategies development, execution and backtesting via Interactive Brokers TWS API or other brokers API
Stars: ✭ 104 (+18.18%)
Mutual labels:  algorithmic-trading, quantitative-finance, trading-platform
Turingtrader
The Open-Source Backtesting Engine/ Market Simulator by Bertram Solutions.
Stars: ✭ 132 (+50%)
Mutual labels:  algorithmic-trading, quantitative-finance, trading-platform
Zvt
modular quant framework.
Stars: ✭ 1,801 (+1946.59%)
Mutual labels:  algorithmic-trading, quantitative-finance, trading-platform
AutoTrader
A Python-based development platform for automated trading systems - from backtesting to optimisation to livetrading.
Stars: ✭ 227 (+157.95%)
Mutual labels:  trading-platform, quantitative-finance, algorithmic-trading
Stocksharp
Algorithmic trading and quantitative trading open source platform to develop trading robots (stock markets, forex, crypto, bitcoins, and options).
Stars: ✭ 4,601 (+5128.41%)
Mutual labels:  quantitative-finance, trading-platform
Pandapy
PandaPy has the speed of NumPy and the usability of Pandas 10x to 50x faster (by @firmai)
Stars: ✭ 474 (+438.64%)
Mutual labels:  pandas, algorithmic-trading
Pymarketstore
Python driver for MarketStore
Stars: ✭ 74 (-15.91%)
Mutual labels:  pandas, quantitative-finance
Research
Notebooks based on financial machine learning.
Stars: ✭ 714 (+711.36%)
Mutual labels:  algorithmic-trading, quantitative-finance
Quantitative Notebooks
Educational notebooks on quantitative finance, algorithmic trading, financial modelling and investment strategy
Stars: ✭ 356 (+304.55%)
Mutual labels:  algorithmic-trading, quantitative-finance
Qlib
Qlib is an AI-oriented quantitative investment platform, which aims to realize the potential, empower the research, and create the value of AI technologies in quantitative investment. With Qlib, you can easily try your ideas to create better Quant investment strategies. An increasing number of SOTA Quant research works/papers are released in Qlib.
Stars: ✭ 7,582 (+8515.91%)
Mutual labels:  algorithmic-trading, quantitative-finance
Qtpylib
QTPyLib, Pythonic Algorithmic Trading
Stars: ✭ 1,241 (+1310.23%)
Mutual labels:  algorithmic-trading, quantitative-finance
Pandas Technical Indicators
Technical Indicators implemented in Python using Pandas
Stars: ✭ 388 (+340.91%)
Mutual labels:  pandas, quantitative-finance
Introneuralnetworks
Introducing neural networks to predict stock prices
Stars: ✭ 486 (+452.27%)
Mutual labels:  algorithmic-trading, quantitative-finance
Tickgrinder
Low-latency algorithmic trading platform written in Rust
Stars: ✭ 365 (+314.77%)
Mutual labels:  algorithmic-trading, trading-platform
Alphapy
Automated Machine Learning [AutoML] with Python, scikit-learn, Keras, XGBoost, LightGBM, and CatBoost
Stars: ✭ 564 (+540.91%)
Mutual labels:  pandas, trading-platform
Aialpha
Use unsupervised and supervised learning to predict stocks
Stars: ✭ 1,191 (+1253.41%)
Mutual labels:  algorithmic-trading, quantitative-finance
Machinelearningstocks
Using python and scikit-learn to make stock predictions
Stars: ✭ 897 (+919.32%)
Mutual labels:  algorithmic-trading, quantitative-finance
Finta
Common financial technical indicators implemented in Pandas.
Stars: ✭ 901 (+923.86%)
Mutual labels:  pandas, algorithmic-trading

Moonshot

Moonshot is a backtester designed for data scientists, created by and for QuantRocket.

Key features

Pandas-based: Moonshot is based on Pandas, the centerpiece of the Python data science stack. If you love Pandas you'll love Moonshot. Moonshot can be thought of as a set of conventions for organizing Pandas code for the purpose of running backtests.

Lightweight: Moonshot is simple and lightweight because it relies on the power and flexibility of Pandas and doesn't attempt to re-create functionality that Pandas can already do. No bloated codebase full of countless indicators and models to import and learn. Most of Moonshot's code is contained in a single Moonshot class.

Fast: Moonshot is fast because Pandas is fast. No event-driven backtester can match Moonshot's speed. Speed promotes alpha discovery by facilitating rapid experimentation and research iteration.

Multi-asset class, multi-time frame: Moonshot supports end-of-day and intraday strategies using equities, futures, and FX.

Machine learning support: Moonshot supports machine learning and deep learning strategies using scikit-learn or Keras.

Live trading: Live trading with Moonshot can be thought of as running a backtest on up-to-date historical data and generating a batch of orders based on the latest signals produced by the backtest.

No black boxes, no magic: Moonshot provides many conveniences to make backtesting easier, but it eschews hidden behaviors and complex, under-the-hood simulation rules that are hard to understand or audit. What you see is what you get.

Example

A basic Moonshot strategy is shown below:

from moonshot import Moonshot

class DualMovingAverageStrategy(Moonshot):

    CODE = "dma-tech"
    DB = "tech-giants-1d"
    LMAVG_WINDOW = 300
    SMAVG_WINDOW = 100

    def prices_to_signals(self, prices):
        closes = prices.loc["Close"]

        # Compute long and short moving averages
        lmavgs = closes.rolling(self.LMAVG_WINDOW).mean()
        smavgs = closes.rolling(self.SMAVG_WINDOW).mean()

        # Go long when short moving average is above long moving average
        signals = smavgs > lmavgs

        return signals.astype(int)

    def signals_to_target_weights(self, signals, prices):
        # spread our capital equally among our trades on any given day
        daily_signal_counts = signals.abs().sum(axis=1)
        weights = signals.div(daily_signal_counts, axis=0).fillna(0)
        return weights

    def target_weights_to_positions(self, weights, prices):
        # we'll enter in the period after the signal
        positions = weights.shift()
        return positions

    def positions_to_gross_returns(self, positions, prices):
        # Our return is the security's close-to-close return, multiplied by
        # the size of our position
        closes = prices.loc["Close"]
        gross_returns = closes.pct_change() * positions.shift()
        return gross_returns

See the QuantRocket docs for a fuller discussion.

Machine Learning Example

Moonshot supports machine learning strategies using scikit-learn or Keras. The model must be trained outside of Moonshot, either using QuantRocket or by training the model manually and persisting it to disk:

from sklearn.tree import DecisionTreeClassifier
import pickle

model = DecisionTreeClassifier()
X = np.array([[1,1],[0,0]])
Y = np.array([1,0])
model.fit(X, Y)

with open("my_ml_model.pkl", "wb") as f:
    pickle.dump(model, f)

A basic machine learning strategy is shown below:

from moonshot import MoonshotML

class DemoMLStrategy(MoonshotML):

    CODE = "demo-ml"
    DB = "demo-stk-1d"
    MODEL = "my_ml_model.pkl"

    def prices_to_features(self, prices):
        closes = prices.loc["Close"]
        # create a dict of DataFrame features
        features = {}
        features["returns_1d"]= closes.pct_change()
        features["returns_2d"] = (closes - closes.shift(2)) / closes.shift(2)
        # targets is used by QuantRocket for training model, can be None if using
        # an already trained model
        targets = closes.pct_change().shift(-1)
        return features, targets

    def predictions_to_signals(self, predictions, prices):
        signals = predictions > 0
        return signals.astype(int)

See the QuantRocket docs for a fuller discussion.

FAQ

Can I use Moonshot without QuantRocket?

Moonshot depends on QuantRocket for querying historical data in backtesting and for live trading. In the future we hope to add support for running Moonshot on a CSV of data to allow backtesting outside of QuantRocket.

See also

Moonchart is a companion library for creating performance tear sheets from a Moonshot backtest.

License

Moonshot is distributed under the Apache 2.0 License. See the LICENSE file in the release for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].