Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/erfaniaa/crypto-trading-strategy-backtester
Easy-to-use cryptocurrency trading strategy simulator and backtester
https://github.com/erfaniaa/crypto-trading-strategy-backtester
backtesting backtesting-trading-strategies binance bitcoin crypto cryptocurrency data-science dataset dataset-generation machine-learning python quantitative-finance quantitative-trading simulation time-series trading trading-strategies
Last synced: 17 days ago
JSON representation
Easy-to-use cryptocurrency trading strategy simulator and backtester
- Host: GitHub
- URL: https://github.com/erfaniaa/crypto-trading-strategy-backtester
- Owner: Erfaniaa
- License: gpl-3.0
- Created: 2022-06-07T08:35:31.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-26T23:01:05.000Z (about 1 year ago)
- Last Synced: 2024-10-13T20:41:46.249Z (about 1 month ago)
- Topics: backtesting, backtesting-trading-strategies, binance, bitcoin, crypto, cryptocurrency, data-science, dataset, dataset-generation, machine-learning, python, quantitative-finance, quantitative-trading, simulation, time-series, trading, trading-strategies
- Language: Python
- Homepage:
- Size: 107 KB
- Stars: 74
- Watchers: 3
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Crypto Trading Strategy Backtester
Easy-to-use cryptocurrency trading strategy simulator
![backtester](https://user-images.githubusercontent.com/7780269/183514626-158eec2e-137b-421d-9f82-8055c72c3b1c.png)
## 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](https://github.com/matplotlib/mplfinance).
- 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` and`INDICATORS_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](https://user-images.githubusercontent.com/7780269/183297991-5bfc0537-138d-4d8b-909c-f6272538ff59.png)
- Another plot to see the opened and closed positions on [an interactive chart](https://github.com/matplotlib/mplfinance)
- 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
- [Binance Futures Trading Bot](https://github.com/erfaniaa/binance-futures-trading-bot)
- [Binance Spot Trading Bot](https://github.com/smzerehpoush/binance-spot-trading-bot)## Credits
[Erfan Alimohammadi](https://github.com/Erfaniaa) and [Amir Reza Shahmiri](https://github.com/Amirrezashahmiri)