Coder Social home page Coder Social logo

erfaniaa / crypto-trading-strategy-backtester Goto Github PK

View Code? Open in Web Editor NEW
85.0 4.0 18.0 110 KB

Easy-to-use cryptocurrency trading strategy simulator and backtester

License: GNU General Public License v3.0

Python 100.00%
bitcoin crypto cryptocurrency backtesting backtesting-trading-strategies binance data-science machine-learning python quantitative-finance quantitative-trading trading trading-strategies dataset dataset-generation simulation time-series

crypto-trading-strategy-backtester's Introduction

Crypto Trading Strategy Backtester

Easy-to-use cryptocurrency trading strategy simulator

backtester

Features

  • You can run it fast, and it is easy to use.
  • There are no complexities and no database usage in this project. Even dependencies are a few.
  • It is easy to modify and customize.
  • It generates many different statistical parameters in a complete report.
  • This project saves the downloaded data for offline usage, so no unnecessary downloads are required.
  • This project generates practical datasets for data scientists.
  • After backtesting, you can see the opened and closed positions on an interactive chart.
  • You can read the code for educational purposes.

Run

  1. Clone the repository.
  2. Run pip3 install -r requirements.txt.
  3. Run python3 main.py.

This will backtest an example strategy for trading Bitcoin.

Config

To define the strategy, you can:

  • Change config.py constants.
  • Define new indicators in indicators.py.
  • Change _is_it_time_to_open_long_position and _is_it_time_to_open_short_position methods.
  • Change _check_conditions_to_close_long_position and _check_conditions_to_close_short_position methods.

Config.py Description

  • COINS_SYMBOL: The trading pair
  • START_DEPOSIT: How much money do we have to start trading with?
  • LEVERAGE: Futures trading leverage
  • OPEN_POSITION_FEE_PERCENT and CLOSE_POSITION_FEE_PERCENT: Exchange fees
  • USE_LONG_POSITIONS and USE_SHORT_POSITIONS: Are we trading in the futures market?
  • TAKE_PROFIT_PERCENTS_LIST and STOP_LOSS_PERCENTS_LIST: Set multiple take profit and stop losses for your positions
  • MOVING_AVERAGE_SIZE andINDICATORS_TIMEFRAME: If use some indicators, you can set them up here.
  • START_YEAR, START_MONTH, START_DAY, START_HOUR, START_MINUTE , and START_SECOND: Starting time for trading
  • END_YEAR, END_MONTH, END_DAY, END_HOUR, END_MINUTE , and END_SECOND: Starting time for trading
  • TIMEFRAME: The main time frame used for iterating candles and checking the take profits and stop losses
  • IMPORTANT_RECENT_CANDLES_TIMEFRAME: Generated output dataset candles timeframe
  • IMPORTANT_RECENT_CANDLES_COUNT: Number of candles in the generated output dataset
  • OPEN_POSITION_TIMEFRAME: We want to open the position at some exact rounded times
  • REPORT_PERCENTILES_COUNT: Number of percentiles used in the statistical analysis report
  • TEST_SET_SIZE_RATIO: How big is the final generated test set of our dataset?
  • MINIMUM_NUMBER_OF_CANDLES_TO_START_TRADING: Do not start trading soon!

Output

  • A plot in plot.png, for example:

plot

  • Another plot to see the opened and closed positions on an interactive chart
  • A complete report on candle statistics (as the program text output)
  • A complete report on opened and closed positions (as the program text output)
  • A complete report on the strategy (in deposit_changes.csv)
  • A spreadsheet containing opened and closed positions (in positions.csv)
  • Two datasets for data science and machine learning purposes (test.csv and train.csv)

To Do

  • Use 5m, 15m, 1h, etc. instead of m5, m15, h1, etc.
  • Use Python private methods in some cases

See Also

Credits

Erfan Alimohammadi and Amir Reza Shahmiri

crypto-trading-strategy-backtester's People

Contributors

erfaniaa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar zionfuo avatar david hwang avatar  avatar  avatar Zilberg avatar  avatar BQdev avatar Ahmad maulana yusuf avatar G_will avatar  avatar  avatar  avatar Artin Mohammadi avatar Vasco Lameiras avatar SpyManxD avatar Rossi Meacham avatar  avatar Robert Valentak avatar İbrahim Dinç avatar  avatar Himanshu Yadav avatar  avatar  avatar  avatar Per von Rosen avatar what? avatar  avatar Vishnu Kumar K avatar Saleh Abednezhad avatar Nguyễn Văn Tụ avatar  avatar Shaygan Hooshyari avatar  avatar Moha Movahedmanesh avatar Richard Lora avatar djwatt3 avatar frash avatar pittss avatar  avatar Le Van Long avatar  avatar  avatar Eureka avatar  avatar Ali Rajabi avatar NevvDevv avatar hvahora avatar Nagy Janos Mate avatar Hudson Newey avatar Mohammad Mahdi Shokri avatar  avatar Amir M Pirhosseinloo avatar Zu-Cheng Chen avatar  avatar Sepehr Asgarian avatar Shayan Hosseini avatar Nina Rafieifar avatar Lee Penkman avatar  avatar Dillon Chan avatar Zubin avatar Akzhol I. avatar Sepehr Razmyar avatar Debasis Das avatar Farzad Sharbafian avatar  avatar  avatar Shayan Azizi avatar  avatar Meysam Kazemi avatar  avatar Rashi Abramson avatar Sina Rahimzade avatar  avatar Erfan Abedi avatar  avatar Anatoly Moskovsky avatar Marciano avatar Cinna avatar Hossein Dindar avatar

Watchers

 avatar Ali Falahati avatar  avatar  avatar

crypto-trading-strategy-backtester's Issues

Running Error

Hi, I get this error when I run python3 main.py

ModuleNotFoundError: No module named 'pandas'

Error downloading candles data

Getting this error after running main.py in colab

ERROR in download_or_load_candles m1 Downloading m1 candles... 0 / 264 ERROR in download_or_load_candles m1 Downloading m1 candles... 0 / 264

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.