Giter VIP home page Giter VIP logo

quant-trading-strategy-backtesting-framework's Introduction

MIT License LinkedIn

Framework for backtesting quantitative trading strategies

Quantitative trading is a type of market strategy that relies on mathematical and statistical models to identify and execute opportunities and trades.

This project aims to serve as a framework for developing and backtesting trading strategies, allowing for easy data visualisation and strategy performance comparison.

Presented in the script as a demonstration, an extremely basic, and likely unprofitable, simple moving average crossover strategy is provided. Said strategy buys when the 10-day moving average crosses the 20-day moving average, and sells when the reverse occurs.

Building upon this framework, much more complex, robust, and profitable strategies can be built, tested, and optimised.

Real-World Use-Cases

๐Ÿ’ฐ Develop and backtest trading strategies

๐Ÿฆ Develop highly customised indicators

๐Ÿ’ฒ Compare and analyse quant strategies

Development-Goals

๐Ÿงฐ Develop a framework for backtesting trading strategies

โ˜‘๏ธ Deep dive into Backtrader's library and understand both it's capabilities and limitations.

๐Ÿงพ Further develop knowledge of Matplotlib

๐Ÿค– Backtest a simple moving average crossover trading strategy

Built With

Getting Started

  1. Obtain price data.

  2. Create a signal generator within the init function of the strategy class:

 # signal generator
  def __init__(self):

      ma_fast = bt.ind.SMA(period = 10)
      ma_slow = bt.ind.SMA(period = 20)

      self.crossover = bt.ind.CrossOver(ma_fast, ma_slow)
  1. Create buy and sell orders based upon the previously generate signals. For example:
 # executes order from the signals
  def next(self):
      if not self.position:         # if not already in a position
          if self.crossover > 0:    # if 10-day moving average crosses above 20-day moving average
              self.buy()            # take a long position
      elif self.crossover < 0:      # if 10-day moving average crosses below 20-day moving average
          self.close()              # close long position
  1. Initialise the backtesting engine (Cerebro). Add the price data and strategy before setting inital conditions such as account size and risk amount per trade etc.
  cerebro = bt.Cerebro()

  # adds data to engine
  cerebro.adddata(data)
  # adds strategy to engine
  cerebro.addstrategy(MaCrossStrategy)

  # sets starting capital
  cerebro.broker.setcash(1000.0)
  # sets size per trade
  cerebro.addsizer(bt.sizers.PercentSizer, percents = 10)
  1. Run the back test using:
  back = cerebro.run()

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Twitter - @TraderTDF

LinkedIn - https://www.linkedin.com/in/RAMWatson/

Project Link: https://github.com/Elisik/Quant-Trading-Strategy-Backtesting-Framework

quant-trading-strategy-backtesting-framework's People

Contributors

0xtdf avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.