Skip to content

almprmg/FlashBackTest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Documentation - README.md

FlashBackTesting

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.

Table of Contents

Introduction

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.

Prerequisites

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')

Installation

To install [FlashBackTesting], follow these steps:

  1. Clone the repository: git clone https://github.com/almprmg/FastBackTest/.git
  2. Change into the project directory: cd FastBackTest

Usage

To use [FlashBackTesting], follow these guidelines:

  1. Import the necessary libraries:
import pandas as pd
from flashBackTesting import FlashBackTesting
from flashBackTesting import Strategy
  1. 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')
  1. 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)
  1. Create an instance of the FlashBackTesting class and run the backtest:
bt = FlashBackTesting(df1, data_low, myClass, ratio_entry=20, cp=True)
bt.run()
  1. 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

Contributing

Contributions to [FlashBackTesting] are welcome! To contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and ensure that the code passes all tests.
  4. Commit your changes with descriptive commit messages.
  5. Push your branch to your forked repository.
  6. Open a pull request, providing a detailed description of your changes.

Features

  1. Simple, well-documented API
  2. Blazing fast execution
  3. Supports any financial instrument with candlestick data
  4. Detailed results
  5. Accuracy in results
  6. uses tow time frame

License

(AGPL-3.0 License

Contact

For any questions or feedback, please contact: