.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/interactive_html_report.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_interactive_html_report.py: Interactive HTML Backtest Report ================================ Create a portable Plotly report containing interactive equity, drawdown, trade markers, performance metrics, and the complete ledger. Install the optional reporting extra first: ``pip install 'TradeTide[reporting]'``. .. GENERATED FROM PYTHON SOURCE LINES 9-38 .. rst-class:: sphx-glr-script-out .. code-block:: none Interactive report written to reports/bollinger_backtest.html | .. code-block:: Python from TradeTide import BacktestResult, Market, Portfolio, PositionCollection from TradeTide import Strategy, Currency, BollingerBands, capital_management, exit_strategy from TradeTide.times import hours market = Market() market.load_from_database(Currency.CAD, Currency.USD, 4 * hours) strategy = Strategy() strategy.add_indicator(BollingerBands(window=20, multiplier=2.0)) signals = strategy.get_trade_signal(market) positions = PositionCollection(market, signals) positions.open_positions(exit_strategy.Static(stop_loss=4, take_profit=4)) positions.propagate_positions() portfolio = Portfolio(positions) portfolio.simulate( capital_management.FixedLot( capital=100_000, fixed_lot_size=1.0, max_capital_at_risk=5_000, max_concurrent_positions=3, ) ) result = BacktestResult.from_portfolio(portfolio) report = result.to_html("reports/bollinger_backtest.html", open_browser=False) print(f"Interactive report written to {report}") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.221 seconds) .. _sphx_glr_download_gallery_interactive_html_report.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: interactive_html_report.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: interactive_html_report.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: interactive_html_report.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_