Backtesting is a process used in finance to assess the effectiveness of a trading strategy. It involves testing a strategy using historical market data to see how it would have performed in the past.
Backtesting.py
is a Python library that simplifies the process of backtesting trading strategies. It provides tools and metrics to evaluate the performance of your strategies using historical data.
To get started with backtesting.py, you can follow these steps:
- Install the required dependencies.
- Clone this repository:
git clone https://github.com/Sparsh-Kumar/backtesting.py.git
cd backtesting.py
- Each chapter in this repository is suffixed by
_{{chapter_number}}
.
After running a backtest, you will receive a set of statistics. Here's a breakdown of the meaning of each stat:
- Start: The start date of the backtesting period.
- End: The end date of the backtesting period.
- Duration: The total duration of the backtesting period.
- Exposure Time [%]: The percentage of time your strategy was invested.
- Equity Final [$]: The final equity value after the backtesting period.
- Equity Peak [$]: The highest equity value during the backtesting period.
- Return [%]: The overall return percentage of your strategy.
- Buy & Hold Return [%]: The return percentage if you had bought and held the asset throughout the entire period.
- Return (Ann.) [%]: Annualized return percentage.
- Volatility (Ann.) [%]: Annualized volatility, a measure of the asset's price variability.
- Sharpe Ratio: A risk-adjusted measure of performance. It indicates the excess return per unit of risk. More Info.
- Sortino Ratio: Similar to the Sharpe Ratio but focuses only on downside risk. More Info
- Calmar Ratio: The ratio of the annualized return to the maximum drawdown. It measures the relationship between return and drawdown. More Info
- Max. Drawdown [%]: The maximum percentage drop in equity from a peak to a trough. More Info
- Avg. Drawdown [%]: The average percentage drop during drawdown periods.
- Max. Drawdown Duration: The duration of the longest drawdown period.
- Avg. Drawdown Duration: The average duration of drawdown periods.
- Trades: The total number of trades executed.
- Win Rate [%]: The percentage of trades that were profitable.
- Best Trade [%]: The highest percentage return from a single trade.
- Worst Trade [%]: The lowest percentage return from a single trade.
- Avg. Trade [%]: The average percentage return per trade.
- Max. Trade Duration: The duration of the longest single trade.
- Avg. Trade Duration: The average duration of all trades.
- Profit Factor: The ratio of gross profits to gross losses.
- Expectancy [%]: The average expected return per trade.
- SQN (System Quality Number): A measure of the quality of a trading system based on its expectancy and the statistical significance of the outcome. More Info
Contributions are welcome! Feel free to open issues or pull requests for improvements or bug fixes.
This project is licensed under the MIT License - see the LICENSE file for details