Jupyter Untrade#

Description#

This project is an innovative platform where multiple teams collaborate and compete to develop the most profitable quantitative trading strategies. The essence of the project lies in its focus on creating algorithms capable of front-testing or front-running in trading scenarios to maximize returns.

Installation#

Execute the git clone command:

git clone https://github.com/ztuntrade/untrade-sdk.git && cd untrade-sdk

Install the package using pip3:

pip3 install .

Note: There is no need to install the package if you are using the Jupyter Untrade platform.

Adding Dependencies#

If your development introduces new Python packages as dependencies, ensure to list them in the requirements.txt file. Format each dependency on a new line, specifying the exact version to maintain consistency across environments:

flask==1.1.2
requests==2.25.1

Backtesting with Provided Data Sets#

The project includes a data folder containing CSV files with BTCUSDT trading data over various timeframes for the years 2018 through 2022, as well as separate data for 2023. These data sets are a valuable resource for developers looking to backtest their trading strategies against historical price movements and market conditions.

You can also generate a custom dataset(ohlc), look into the Download CSV Data in example section.

Untrade SDK#

Within the project, you will find an examples folder that contains sample strategies for generating buy and sell signals and performing backtests. These examples serve as a valuable resource for understanding how to effectively utilize the project’s structure and the Untrade SDK.

Project Structure and Execution#

This project is designed to allow users to develop, backtest, and live-test their trading strategies. Users should implement their trading strategies in back_test.py for historical simulation.

back_test.py#

This module is designed to simulate trading strategies using historical data to evaluate their potential profitability. It allows users to test the effectiveness of their trading signals over time.

To facilitate this simulation, back_test.py incorporates functionality for users to generate trading signals based on their strategies. These signals are then saved in a CSV file for further analysis.

CSV File Generation#

Format: CSV (Comma-Separated Values)

Content Structure: The generated CSV file is structured with the following headers, listed in the specified order:

  • datetime (datetime) : The date and time for each data point, formatted as YYYY-MM-DD HH:MM:SS.

  • open (float) : The opening price.

  • high (float) : The highest price.

  • low (float) : The lowest price.

  • close (float) : The closing price.

  • volume (float) : The trading volume.

  • TP (float) : The take profit price. –OPTIONAL

  • SL (float) : The stop loss price. –OPTIONAL

  • signals (int) : The signal for entering or exiting a trade.

Each row under these headers represents a unique time point within the dataset, detailing the market conditions and the trading signal at that moment.

Signal Representation#

The signals column uses integers to represent the trading actions:

  • 1 indicates an entry signal for a long trade, which should be exited with a -1.

  • -1 indicates an entry signal for a short trade, which should be exited with a 1.

  • 0 is used to mark timestamps where no trading signal is present. This includes moments between the entry and exit of a trade.

For clarity and examples on how to structure your CSV file, please refer to the sample.csv file located under the examples directory.

Important Note#

Ensure the signals for entering and exiting trades are accurately marked to reflect your strategy’s intent. This is crucial for the backtesting simulation to provide meaningful insights into the potential profitability of your trading strategy.

TP and SL#

  • Any strategy which involves limit orders for take profit (TP) and stop loss (SL) set at X and Y respectively, our backtesting process requires timestamped signals of 1/-1 to indicate long/short positions. Alongside these signals, TP and SL rows are provided, specifying the numerical values for TP and SL .

  • When the order is executed at the close of a timestamp, our engine initiates monitoring of price movements from the next candle onwards. It continuously checks if the market tick reaches either the TP or SL levels. Upon reaching either level, the engine calculates the profit or loss based on the difference between the entry and exit prices. This calculation is expressed as a percentage return on investment (ROI).

  • This approach ensures accurate evaluation of the strategy’s performance by simulating real market conditions and computing profits or losses based on actual price movements relative to the predefined TP and SL levels.

Script Requirements#

Fetching Historical Data#

The script must utilize the fetch_historical_data() function available in example_fronttest.py present in examples folder to retrieve the latest market data each time it runs. This function ensures that the script has access to the most recent data necessary for making informed trading decisions.