Code Monkey home page Code Monkey logo

backtrader-with-brent-futures's Introduction

Backtrader Framework for Brent Crude Oil Futures

The following is a simple backtesting framework for Brent Crude Oil Futures written with the backtrader library.

App Screenshot

Description

This project queries historical data for Brent Crude Oil futures from Quandl and backtests several algorithmic trading strategies using the backtrader library. It currently ships with three strategies: SmaCrossoverStrategy, RSIMeanReversionSystem and ThreeSoldiersAndCrows, which were variously inspired by examples from the backtrader documentation series, backtest-rookies.com, as well as my own experiences in technical analysis.

The current implementation of this project is separated into two main functionalities: visualize_bt.py and optimize_bt.py.

Backtest Visualization

To perform a simple analysis using one of the pre-packaged strategies, simply edit in visualize_bt.py:

import extensions.strategies as st

cerebro.addstrategy(st.RSIMeanReversionSystem)

Then, in Terminal, run:

python visualize_bt.py

This returns a terminal output of P&L generated over a stipulated timeframe alongside the packaged backtrader plot.

Backtest Optimization

To optimize parameters within an existing strategy, first edit in optimize_bt.py:

cerebro.optstrategy(
        st.SmaCrossoverStrategy,
        sma1_period=range(10, 21),
        opt_mode=True
    )

Then run the following in Terminal:

python optimize_bt.py

This prints a series of simulations for the parameter(s) under analysis alongside their corresponding final portfolio values.

Future Plans (Ordered By Priority)

  • Add to the set of strategies based on new ideas from fundamental research
  • Include a plotting functionality for optimizations runs (i.e. Plotting Parameter Values against P&L)
  • Analyze the potential of implementing the framework for live trading with OANDA or Interactive Brokers
  • Tinker with 'extensions.sizers' to execute based on various risk portfolios
  • Tinker with 'extensions.queries' to experiment with more unconvential commodity datasets

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.