Project Documentation - README.md
FlashBackTest.py is a small, lightweight, extremely fast and accurate backtesting frame that uses two backtesting frameworks: a lower frame and a higher fram , that uses the latest Python structures and routines (Python 3.10+, Pandas, NumPy). It has a very small and simple API that is easy to remember and configure quickly to achieve meaningful results. The library does not really support stock picking, arbitrage trading strategies, or multi-asset portfolio rebalancing; Instead, it works with one tradable asset at a time and is best suited for optimizing entry and exit signal strategies for trades, decisions based on technical indicator values, and is a versatile interactive trading visualization and statistics tool.
The [FlashBackTesting] project provides a backtesting framework and strategy implementation for analyzing financial data. This documentation serves as a guide to understand the project,it enables it to show highly accurate results by using smaller frames and simulating the live test., its setup, and how to utilize its features effectively.
Before getting started with [FlashBackTesting], ensure that you have the following prerequisites installed on your machine:
- Python (version >= 10.9.1)
- pandas (version >= '1.5.3')
- numpy (version >= 1.23.5')
To install [FlashBackTesting], follow these steps:
- Clone the repository:
git clone https://github.com/almprmg/FastBackTest/.git
- Change into the project directory:
cd FastBackTest
To use [FlashBackTesting], follow these guidelines:
- Import the necessary libraries:
import pandas as pd
from flashBackTesting import FlashBackTesting
from flashBackTesting import Strategy
- Set up the required variables and data:
timeframe_high = "1h"
timeframe_low = "5m"
symbol = "AGLDUSDT"
data_low = pd.read_csv(f'........./data/{timeframe_low}/{symbol}.csv', index_col=0)
df1 = pd.read_csv(f'.....\{timeframe_high}/{symbol}.csv', index_col=0)
data_low.index = pd.to_datetime(data_low.index)
df1["Date"] = pd.to_datetime(df1["Date"], unit='ms')
df1 = df1.set_index('Date')
- Define your strategy class by extending the base
Strategy
class:
class myClass(Strategy):
def init(self) -> None:
super().init()
def next(self) -> None:
super().next()
if self.data.Signal[-1] == 1:
limit = self.data.highest_top[-1]
highest_top = self.data.highest_bot[-1]
sl = highest_top - ((self.limit - highest_top) * 3)
tp = highest_top + ((self.limit - highest_top) * 5)
self.buy(limit=self.limit, tp=self.tp, sl=self.sl)
elif self.data.Signal[-1] == 2:
limit = self.data.highest_bot[-1]
highest_top = self.data.highest_top[-1]
sl = highest_top - ((highest_top - limit) * 3)
tp = highest_top + ((highest_top - limit) * 5)
self.sell(limit=limit, tp=tp, sl=sl)
- Create an instance of the
FlashBackTesting
class and run the backtest:
bt = FlashBackTesting(df1, data_low, myClass, ratio_entry=20, cp=True)
bt.run()
- Access the backtesting results:
bt.result
Start 2022-08-26 18:00:00
End 2023-08-26 17:00:00
Duration 364 days 23:00:00
Equity Final [$] 782.198334
Equity Peak [$] 1013.011602
Return [%] -22.463471
Buy & Hold Return [%] 38.636364
Max. Drawdown [%] -25.033789
# Trades 71
Win Rate [%] 50.704225
Best Trade [%] 15.873016
Worst Trade [%] -27.142857
Avg. Trade [%] -2.049075
Max. Trade Duration 27 days 17:00:00
Avg. Trade Duration 2 days 03:00:00
Profit Factor 0.624392
Expectancy [%] -1.647243
SQN -1.609426
_trades Size ...
dtype: obj
Contributions to [FlashBackTesting] are welcome! To contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and ensure that the code passes all tests.
- Commit your changes with descriptive commit messages.
- Push your branch to your forked repository.
- Open a pull request, providing a detailed description of your changes.
- Simple, well-documented API
- Blazing fast execution
- Supports any financial instrument with candlestick data
- Detailed results
- Accuracy in results
- uses tow time frame
For any questions or feedback, please contact: