Coder Social home page Coder Social logo

backtrader_plotly's Introduction

backtrader_plotly

Plot backtrader's result using plotly instead of the default matplotlib

This is an experimental package, and it is done by replacing original matplotlib method calls.

Installation

$ pip install backtrader-plotly==1.5.0

Features

  • Support for Multiple Strategies Plotting (Added from 1.5.0.dev1)

  • Support for Filled Area Plotting and Toggling (Added from 1.4.0)

  • New Scheme Arguments (Added from 1.3.0)

    Additional scheme arguments are added to provide extra control

    Name of Argument Default Value Description
    decimal_places 5 It is used to control the number of decimal places of price shown on the plot. For instance, forex price usually consists of 5 decimal places.
    max_legend_text_width 16 It is used to limit the legend text width to prevent it from occupying the page.

Usage

Complete Working Example Here

# import the package after installation
from backtrader_plotly.plotter import BacktraderPlotly
from backtrader_plotly.scheme import PlotScheme
import plotly.io

# do whatever you want with `backtrader`
import backtrader as bt

# for instance
cerebro = bt.Cerebro()

# add strategies
cerebro.addstrategy(IchimokuStrategy)
cerebro.addstrategy(SMACrossStrategy)

# after adding data and strategy
cerebro.run()

# define plot scheme with new additional scheme arguments
scheme = PlotScheme(decimal_places=5, max_legend_text_width=16)

figs = cerebro.plot(BacktraderPlotly(show=False, scheme=scheme))

# directly manipulate object using methods provided by `plotly`
for i, each_run in enumerate(figs):
    for j, each_strategy_fig in enumerate(each_run):
        # open plot in browser
        each_strategy_fig.show()

        # save the html of the plot to a variable
        html = plotly.io.to_html(each_strategy_fig, full_html=False)

        # write html to disk
        plotly.io.write_html(each_strategy_fig, f'{i}_{j}.html', full_html=True)

backtrader_plotly's People

Contributors

lamkashingpaul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

backtrader_plotly's Issues

Support for multiple strategies?

Hi, friend

awesome work! Whether the following call methods are supported,
multiple strategies?

cerebro.addstrategy(IchimokuStrategy)
cerebro.addstrategy(SMAStrategy)

thanks。

_fill_gt and _fill_lt not handled properly

Hi,
awesome work! I spotted a bug when you try to plot indicators which have shadows, like in the case of Ichimoku clouds.
Plotly does not handle properly _fill_gt nor _fill_lt, causing a crash.
Here a snippet which cause the error

plotlines = dict(
        senkou_span_a=dict(_fill_gt=('senkou_span_b', 'g'),
                           _fill_lt=('senkou_span_b', 'r')),
    )

Can you fix it or suggest a solution?

Best regards
Mirco

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.