{"id":18895646,"url":"https://github.com/binance/ai-trading-prototype-backtester","last_synced_at":"2025-08-13T01:34:21.568Z","repository":{"id":191602603,"uuid":"671755596","full_name":"binance/ai-trading-prototype-backtester","owner":"binance","description":"Headline Sentiment Analysis Backtester. Backtests trading strategy from ai-trading-prototype trading bot.","archived":false,"fork":false,"pushed_at":"2025-01-07T08:47:36.000Z","size":255,"stargazers_count":45,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-17T07:46:37.807Z","etag":null,"topics":["ai","auto-trading","backtester","binance","prototype"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/binance.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-07-28T04:12:08.000Z","updated_at":"2025-06-07T12:19:37.000Z","dependencies_parsed_at":"2024-02-26T03:31:01.660Z","dependency_job_id":"d3c347b3-5dee-4349-b874-1e6a2fc5e15d","html_url":"https://github.com/binance/ai-trading-prototype-backtester","commit_stats":null,"previous_names":["binance/ai-trading-prototype-backtester"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/binance/ai-trading-prototype-backtester","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fai-trading-prototype-backtester","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fai-trading-prototype-backtester/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fai-trading-prototype-backtester/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fai-trading-prototype-backtester/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binance","download_url":"https://codeload.github.com/binance/ai-trading-prototype-backtester/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fai-trading-prototype-backtester/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270165138,"owners_count":24538428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","auto-trading","backtester","binance","prototype"],"created_at":"2024-11-08T08:29:13.460Z","updated_at":"2025-08-13T01:34:21.511Z","avatar_url":"https://github.com/binance.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AI Trading Prototype Backtester\n\nThis project is a backtester for the sentiment-analysis cryptocurrency trading strategy that pairs with the live trading bot, [ai-trading-prototype](https://github.com/binance/ai-trading-prototype/). This backtester is designed to run accurate simulations for a given date range on a chosen trading symbol.\n\n![Diagram](../assets/diagram.png?raw=true)\n\n## Disclaimer\n\nThis trading bot backtester does not provide financial advice or endorse trading strategies. Users assume all risks, as past results from historical data do not guarantee future returns; the creators bear no responsibility for losses. Please seek guidance from financial experts before trading or investing. By using this project you accept these conditions.\n\n## Features\n\n* A flexible trading strategy builder.\n* Customisable Backtesting strategy.\n* Automated data downloader using `data.binance.vision`.\n* Detailed backtest results and performance assessment, including HTML visualisations of all trades.\n\n## Installation\n\n1. Clone the repository\n```\ngit clone https://github.com/binance/ai-trading-prototype-backtester\n```\n2. Move into the cloned directory\n```\ncd ai-trading-prototype-backtester\n```\n3. Install dependencies\n```\npip install -r requirements.txt\n```\n\n## Usage\n### Configuration\n\nAll configurations are stored in `config.yaml.example`. You can specify:\n* `symbol`: The trading symbol/ pair. Example: `ETHUSDT`.\n* `kline_interval`: The interval of the candlesticks. Valid intervals are: `1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h` or `1d`\n* `start_date` and `end_date`: The range of dates to backtest on. Format: `YYYY-MM-DD`.\n* `sentiment_data`: The path to the sentiment data file. Default: `./sentiment_data/sentiment_data.csv`.\n* `start_balance`: The starting balance in quote currency (eg. USDT). Default: `100000`.\n* `order_size`: The order size in base currency (eg. BTC). Default: `0.01`.\n* `total_quantity_limit`: The maximum quantity of base currency (eg. BTC) that can be held at any given time. Default: `1`.\n* `commission`: The trading fee/commission ratio. Default: `0.002`.\n* `logging_level`: The logging detail level. Default: `INFO`.\n\nPlease also ensure that the sentiment data file `sentiment_data.csv` is present and formatted as `\"headline source\",\"headline collected timestamp (ms)\",\"headline published timestamp (ms)\",\"headline\",\"sentiment\"`.\n\n#### Strategy Configuration Profiles\n\nWithin the `strategy_configuration` directory, there are 3 extra configuration files. Each file corresponds to a different strategy/risk level (Aggressive, Conservative and Standard). These can be used to quickly test different parameters with varying degrees of risk.\n\n### Run the backtester as module\n\n```\npython -m aitradingprototypebacktester\n```\n\n#### How it works\n\n* During the backtesting process, the backtester checks `/sentiment_data/sentiment_data.csv` for a published headline at each kline/candlestick interval.\n* If a headline was published during the current time-period, it reads the sentiment of the headline.\n* By default, the backtester uses the `successive_strategy` which is defined in `aitradingprototypebacktester/strategy/successive_strategy.py`. The details of how this strategy works is as follows:\n  * If the sentiment was \"bullish\" (meaning it is expected that the price would increase) it will attempt a BUY order of size = `order_size` of base currency, so long as the `total_quantity_limit` (max. quantity that can be held at any given time) has not yet been reached.\n  * If the sentiment was \"bearish\" (meaning that a fall in price is expected), it will attempt to SELL `order_size` quantity of the base currency, so long as the current base currency balance is \u003e 0.\n* Once the backtest is complete, it will return a detailed table of results along with an HTML visualisation of all the buys and sells plotted against the trading symbol's price throughout the period.\n  * An image, `backtest_result.png`, will also be generated. This is a static view of the HTML visualisation.\n* If there is a position still open at the end of the backtest, it will be closed at the open price of the last kline in the backtesting period.\n\n## Backtest Results\n\n* As outlined in the `How it works` section above, the backtester will output several files as a result of each backtest:\n  * `output/raw/backtest_result.txt` - A summary of the backtest.\n  * `output/raw/backtest_trades.txt` - A detailed list of each individual trade executed during the backtest.\n  * `output/visualisation/dynamic_report.html` - HTML visualisation of all the buys and sells plotted against the trading symbol's price throughout the period.\n  * `output/visualisation/backtest_result.png` - A static view of the HTML visualisation (image below).\n\n![Backtest Result](../assets/backtest_result.png?raw=true)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinance%2Fai-trading-prototype-backtester","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinance%2Fai-trading-prototype-backtester","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinance%2Fai-trading-prototype-backtester/lists"}