btAnalyzer
btAnalyzer copied to clipboard
Analyzers for Forex Strategy using Backtrader platform
PipsArtist - Backtrader Analyzers
This repository is a set of analyzer for backtrader that helps review a strategy. These analyzers have been made for Forex strategies is mind but may be used for other instruments.
This repository is under heay development and is not production ready
Analyzer available
ForexTrades
This is a simple Analyzer that keeps track of all trades closed. It can be used for live or backtesting. It allows to keep track of:
- Trade closed position (Buy or Sell)
- Profit in absolute value and pips
- Open and Close datetime
- Open and Close price
- Maximum drawback in pips
- Maximum profit in pips
ForexStats
This Analyzer is using the output of ForexTrades
Analyzer to give details about the strategy including:
It returns several analysis for a strategy in 4 different areas:
- Overal strategy (For full period of trading or backtesting)
- Gross Profit
- Gross Profit (pips)
- Gross Loss
- Gross Loss (pips)
- Net Profit
- Net Profit (pips)
- Profit Factor
- Expected Payoff
- Total
- Total Number of Trades
- Total Won
- Percentage of won
- Total Loss
- Percentage of loss
- Average Trade profit in absolute value
- Average Trade profit in pips
- Max Profit in absolute value
- Max Profit in pips
- Average Loss in absolute value
- Average Loss in pips
- Max Loss in absolute value
- Max Loss in pips
- Short Trades
- Same as for Total but only for short trades
- Long Trades
- Same as for Total but only for long trades
- Streak - Win and Loss Streak with the following for each:
- Max number of trades in a streak
- Average number of trades in a streak
- Max Profit/Loss in absolute value
- Max Profit/Loss in pips
- Average Profit/Loss in absolute value
- Average Profit/Loss in pips
Known Limitation
These analyzers have only been tested with Currencies and with a 4/5 digits currencies. It does not support 2/3 digits currencies such as USD/JPY
Requirements
- python 3.6+
- Backtrader
- Pandas
- pipenv
Installation
- Clone this repository
git clone [email protected]:edesmars/btAnalyzer.git
- Go into the newly created directory:
cd btAnalyzer
- Install dependencies. Pipenv is recommended:
pipenv --python 3.6 && pipenv install
or usepip install
- In your backtrader script, add a new path to be able to import these Analyzers
import sys
sys.path.append('/path/to/clone')
import bt_analyzers
- Add the analyzers into your cerebro instance
cerebro.addanalyzer(bt_analyzer.stats.ForexStats)