bbstrader 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of bbstrader might be problematic. Click here for more details.

Files changed (33) hide show
  1. bbstrader-0.0.1/LICENSE +21 -0
  2. bbstrader-0.0.1/PKG-INFO +132 -0
  3. bbstrader-0.0.1/README.md +93 -0
  4. bbstrader-0.0.1/bbstrader/__ini__.py +17 -0
  5. bbstrader-0.0.1/bbstrader/btengine/__init__.py +50 -0
  6. bbstrader-0.0.1/bbstrader/btengine/backtest.py +900 -0
  7. bbstrader-0.0.1/bbstrader/btengine/data.py +374 -0
  8. bbstrader-0.0.1/bbstrader/btengine/event.py +201 -0
  9. bbstrader-0.0.1/bbstrader/btengine/execution.py +83 -0
  10. bbstrader-0.0.1/bbstrader/btengine/performance.py +309 -0
  11. bbstrader-0.0.1/bbstrader/btengine/portfolio.py +326 -0
  12. bbstrader-0.0.1/bbstrader/btengine/strategy.py +31 -0
  13. bbstrader-0.0.1/bbstrader/metatrader/__init__.py +6 -0
  14. bbstrader-0.0.1/bbstrader/metatrader/account.py +1038 -0
  15. bbstrader-0.0.1/bbstrader/metatrader/rates.py +226 -0
  16. bbstrader-0.0.1/bbstrader/metatrader/risk.py +626 -0
  17. bbstrader-0.0.1/bbstrader/metatrader/trade.py +1296 -0
  18. bbstrader-0.0.1/bbstrader/metatrader/utils.py +669 -0
  19. bbstrader-0.0.1/bbstrader/models/__init__.py +6 -0
  20. bbstrader-0.0.1/bbstrader/models/risk.py +349 -0
  21. bbstrader-0.0.1/bbstrader/strategies.py +681 -0
  22. bbstrader-0.0.1/bbstrader/trading/__init__.py +4 -0
  23. bbstrader-0.0.1/bbstrader/trading/execution.py +965 -0
  24. bbstrader-0.0.1/bbstrader/trading/run.py +131 -0
  25. bbstrader-0.0.1/bbstrader/trading/utils.py +153 -0
  26. bbstrader-0.0.1/bbstrader/tseries.py +592 -0
  27. bbstrader-0.0.1/bbstrader.egg-info/PKG-INFO +132 -0
  28. bbstrader-0.0.1/bbstrader.egg-info/SOURCES.txt +31 -0
  29. bbstrader-0.0.1/bbstrader.egg-info/dependency_links.txt +1 -0
  30. bbstrader-0.0.1/bbstrader.egg-info/requires.txt +17 -0
  31. bbstrader-0.0.1/bbstrader.egg-info/top_level.txt +1 -0
  32. bbstrader-0.0.1/setup.cfg +4 -0
  33. bbstrader-0.0.1/setup.py +87 -0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023-2024 Bertin Balouki SIMYELI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.1
2
+ Name: bbstrader
3
+ Version: 0.0.1
4
+ Summary: Simplified Investment & Trading Toolkit
5
+ Home-page: https://github.com/bbalouki/bbstrade
6
+ Author: Bertin Balouki SIMYELI
7
+ Author-email: <bbalouki@outlook.com>
8
+ Maintainer: Bertin Balouki SIMYELI
9
+ License: The MIT License (MIT)
10
+ Keywords: Finance,Toolkit,Financial,Analysis,Fundamental,Quantitative,Database,Equities,Currencies,Economics,ETFs,Funds,Indices,Moneymarkets,Commodities,Futures,CFDs,Derivatives,Trading,Investing,Portfolio,Optimization,Performance
11
+ Classifier: Development Status :: 1 - Planning
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Financial and Insurance Industry
14
+ Classifier: Topic :: Office/Business :: Financial :: Investment
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Operating System :: Microsoft :: Windows
19
+ Classifier: License :: OSI Approved :: MIT License
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: pandas
23
+ Requires-Dist: numpy==1.26.4
24
+ Requires-Dist: yfinance
25
+ Requires-Dist: scipy
26
+ Requires-Dist: hmmlearn
27
+ Requires-Dist: pmdarima
28
+ Requires-Dist: arch
29
+ Requires-Dist: hurst
30
+ Requires-Dist: seaborn
31
+ Requires-Dist: statsmodels
32
+ Requires-Dist: matplotlib
33
+ Requires-Dist: filterpy
34
+ Requires-Dist: pytest
35
+ Requires-Dist: sphinx
36
+ Requires-Dist: sphinx-rtd-theme
37
+ Requires-Dist: CurrencyConverter
38
+ Requires-Dist: Metatrader5
39
+
40
+ # Simplified Investment & Trading Toolkit
41
+ ![bbstrader](https://github.com/bbalouki/bbstrader/blob/main/assets/bbstrader_logo.png?raw=true)
42
+
43
+
44
+ ## Overview
45
+
46
+ BBSTrader is a trading system suite developed for MetaTrader 5 (MT5) and IBKR platforms (comming soon), designed to offer a comprehensive set of tools for developping, backtesting, executing, and managing a wide array of trading strategies. With an emphasis on algorithmic and quantitative trading to provide traders with a robust platform for exploring and deploying sophisticated trading strategies.
47
+
48
+ `bbstrader` is comprised of several key modules, each focus on specific aspects of trading strategy development and execution:
49
+
50
+ - **Backtesting Module (btengine)** : Enables traders to rigorously test their trading strategies using historical data to evaluate performance before live deployment.
51
+ - **Trading Strategies Module**: A collection of predefined trading strategies, including ARIMA+GARCH models, Kalman Filters, Ornstein-Uhlenbeck processes, and Simple Moving Averages, equipped with risk management through Hidden Markov Models.
52
+ - **MetaTrader5 Module (metatrader)**: Facilitates the direct execution of trading strategies on the MetaTrader 5 platform, supporting real-time trading across multiple financial instruments.
53
+ - **Modles Module**: Serves as a framework for implementing various types of financial models (risk managment models, Machine learing models etc).
54
+ - **Time serie Module (tseries)** designed for conducting advanced time series analysis in financial markets.
55
+ It leverages statistical models and algorithms to perform tasks such as cointegration testing, volatility modeling, and filter-based estimation to assist in trading strategy development, market analysis, and financial data exploration.
56
+
57
+ ## Features
58
+
59
+ - **Comprehensive Backtesting**: Assess the performance of trading strategies with historical market data to optimize parameters and strategies for live trading environments.
60
+ - **Integrated Risk Management**: Leverage advanced risk management techniques to adapt to changing market conditions and maintain control over risk exposure.
61
+ - **Automated Trading**: Execute trades automatically on the MT5 platform, with support for managing orders, positions, and risk in real-time.
62
+ - **Flexible Framework**: Customize existing strategies or develop new ones with the flexible, modular architecture designed to accommodate traders' evolving needs.
63
+
64
+ ## Getting Started
65
+
66
+ Before you can use the bbstrader and the metratrader, you need to have MetaTrader 5 (MT5) installed on your computer and an active MT5 trading account.
67
+ This Module currenlty support three brokers, [Admirals Group AS](https://cabinet.a-partnership.com/visit/?bta=35537&brand=admiralmarkets), [Just Global Markets Ltd.](https://one.justmarkets.link/a/tufvj0xugm/registration/trader), and [FTMO](https://trader.ftmo.com/?affiliates=JGmeuQqepAZLMcdOEQRp), so you need to create a demo or live account with one of them.
68
+ * If you want to trade `Stocks`, `ETFs`, `Indices`, `Commodities`, `Futures`, and `Forex`, See [click here](https://cabinet.a-partnership.com/visit/?bta=35537&brand=admiralmarkets)
69
+ * If you want to trade `Stocks`, `Crypto`, `indices`, `Commodities`, and `Forex`, See [click here](https://one.justmarkets.link/a/tufvj0xugm/registration/trader)
70
+ * If you are looking for a prop firm, [click here](https://trader.ftmo.com/?affiliates=JGmeuQqepAZLMcdOEQRp)
71
+
72
+ Then, you can install `bbstrader` using pip:
73
+ ```bash
74
+ pip install bbstrader
75
+ ```
76
+
77
+
78
+ ## Examples
79
+ ### Backtesting Module
80
+ ```python
81
+ from bbstrader.btengine.backtest import run_backtest
82
+
83
+ if __name__ == '__main__':
84
+ # KLF IEI TLT Event Driven backtest using Kalman Filter pairs trading strategy integrating with # Hidden Markov Model (HMM) for risk management on `IEI` and `TLT`.
85
+ run_backtest(test_strategy='klf')
86
+ ```
87
+ ### Backtesting Results
88
+ ![Backtesting Results](https://github.com/bbalouki/bbstrader/blob/main/assets/backtest_results.jpg)
89
+
90
+ ## Customization and Contribution
91
+
92
+ `bbstrader`'s modular design allows for easy customization and extension. Traders and developers are encouraged to modify existing strategies, add new ones, or enhance the system's capabilities. Contributions to the `bbstrader` project are welcome.
93
+
94
+ ## Contributing to BBSTrader
95
+
96
+ We warmly welcome contributions from the trading and development community! Whether you're interested in fixing bugs, adding new features, or improving documentation, your help is invaluable to making `bbstrader` more robust and versatile. Here's how you can contribute:
97
+
98
+ ### Ways to Contribute
99
+
100
+ - **Develop New Strategies**: Implement and share your unique trading strategies or models.
101
+ - **Enhance Existing Modules**: Optimize the performance, extend the functionality, or improve the usability of existing modules.
102
+ - **Report Bugs**: Identify and report bugs to help us improve the system's stability and performance.
103
+ - **Improve Documentation**: Contribute to the project's documentation for clearer guidance and better usability.
104
+ - **Share Insights and Best Practices**: Provide examples, tutorials, or best practices on utilizing `bbstrader` effectively.
105
+
106
+ ### How to Get Started
107
+
108
+ 1. **Fork the Repository**: Start by forking the `bbstrader` repository to your GitHub account.
109
+ 2. **Clone Your Fork**: Clone your forked repository to your local machine to start making changes.
110
+ 3. **Set Up Your Development Environment**: Ensure you have the necessary development environment set up, including Python, MetaTrader 5, and any dependencies.
111
+ 4. **Create a New Branch**: Make your changes in a new git branch, branching off from the main branch.
112
+ 5. **Implement Your Changes**: Work on bug fixes, features, or documentation improvements.
113
+ 6. **Test Your Changes**: Ensure your changes do not introduce new issues and that they work as intended.
114
+ 7. **Submit a Pull Request**: Once you're ready, submit a pull request (PR) against the main `bbstrader` repository. Include a clear description of the changes and any other relevant information.
115
+
116
+ ### Contribution Guidelines
117
+
118
+ Please adhere to the following guidelines to ensure a smooth contribution process:
119
+
120
+ - **Follow the Coding Standards**: Write clean, readable code and follow the coding conventions used throughout the project.
121
+ - **Document Your Changes**: Add comments and update the README.md files as necessary to explain your changes or additions.
122
+ - **Respect the License**: All contributions are subject to the MIT License under which `bbstrader` is distributed.
123
+
124
+ We're excited to see your contributions and to welcome you to the `bbstrader` community. Together, we can build a powerful tool that serves the needs of traders around the world.
125
+
126
+
127
+ ## Disclaimer
128
+
129
+ Trading financial instruments involves a high level of risk and may not be suitable for all investors. The developers of `bbstrader` are not responsible for any financial losses incurred from the use of this software. Trade responsibly and at your own risk.
130
+
131
+ ## License
132
+ `bbstrader` is open source and available under the MIT License.
@@ -0,0 +1,93 @@
1
+ # Simplified Investment & Trading Toolkit
2
+ ![bbstrader](https://github.com/bbalouki/bbstrader/blob/main/assets/bbstrader_logo.png?raw=true)
3
+
4
+
5
+ ## Overview
6
+
7
+ BBSTrader is a trading system suite developed for MetaTrader 5 (MT5) and IBKR platforms (comming soon), designed to offer a comprehensive set of tools for developping, backtesting, executing, and managing a wide array of trading strategies. With an emphasis on algorithmic and quantitative trading to provide traders with a robust platform for exploring and deploying sophisticated trading strategies.
8
+
9
+ `bbstrader` is comprised of several key modules, each focus on specific aspects of trading strategy development and execution:
10
+
11
+ - **Backtesting Module (btengine)** : Enables traders to rigorously test their trading strategies using historical data to evaluate performance before live deployment.
12
+ - **Trading Strategies Module**: A collection of predefined trading strategies, including ARIMA+GARCH models, Kalman Filters, Ornstein-Uhlenbeck processes, and Simple Moving Averages, equipped with risk management through Hidden Markov Models.
13
+ - **MetaTrader5 Module (metatrader)**: Facilitates the direct execution of trading strategies on the MetaTrader 5 platform, supporting real-time trading across multiple financial instruments.
14
+ - **Modles Module**: Serves as a framework for implementing various types of financial models (risk managment models, Machine learing models etc).
15
+ - **Time serie Module (tseries)** designed for conducting advanced time series analysis in financial markets.
16
+ It leverages statistical models and algorithms to perform tasks such as cointegration testing, volatility modeling, and filter-based estimation to assist in trading strategy development, market analysis, and financial data exploration.
17
+
18
+ ## Features
19
+
20
+ - **Comprehensive Backtesting**: Assess the performance of trading strategies with historical market data to optimize parameters and strategies for live trading environments.
21
+ - **Integrated Risk Management**: Leverage advanced risk management techniques to adapt to changing market conditions and maintain control over risk exposure.
22
+ - **Automated Trading**: Execute trades automatically on the MT5 platform, with support for managing orders, positions, and risk in real-time.
23
+ - **Flexible Framework**: Customize existing strategies or develop new ones with the flexible, modular architecture designed to accommodate traders' evolving needs.
24
+
25
+ ## Getting Started
26
+
27
+ Before you can use the bbstrader and the metratrader, you need to have MetaTrader 5 (MT5) installed on your computer and an active MT5 trading account.
28
+ This Module currenlty support three brokers, [Admirals Group AS](https://cabinet.a-partnership.com/visit/?bta=35537&brand=admiralmarkets), [Just Global Markets Ltd.](https://one.justmarkets.link/a/tufvj0xugm/registration/trader), and [FTMO](https://trader.ftmo.com/?affiliates=JGmeuQqepAZLMcdOEQRp), so you need to create a demo or live account with one of them.
29
+ * If you want to trade `Stocks`, `ETFs`, `Indices`, `Commodities`, `Futures`, and `Forex`, See [click here](https://cabinet.a-partnership.com/visit/?bta=35537&brand=admiralmarkets)
30
+ * If you want to trade `Stocks`, `Crypto`, `indices`, `Commodities`, and `Forex`, See [click here](https://one.justmarkets.link/a/tufvj0xugm/registration/trader)
31
+ * If you are looking for a prop firm, [click here](https://trader.ftmo.com/?affiliates=JGmeuQqepAZLMcdOEQRp)
32
+
33
+ Then, you can install `bbstrader` using pip:
34
+ ```bash
35
+ pip install bbstrader
36
+ ```
37
+
38
+
39
+ ## Examples
40
+ ### Backtesting Module
41
+ ```python
42
+ from bbstrader.btengine.backtest import run_backtest
43
+
44
+ if __name__ == '__main__':
45
+ # KLF IEI TLT Event Driven backtest using Kalman Filter pairs trading strategy integrating with # Hidden Markov Model (HMM) for risk management on `IEI` and `TLT`.
46
+ run_backtest(test_strategy='klf')
47
+ ```
48
+ ### Backtesting Results
49
+ ![Backtesting Results](https://github.com/bbalouki/bbstrader/blob/main/assets/backtest_results.jpg)
50
+
51
+ ## Customization and Contribution
52
+
53
+ `bbstrader`'s modular design allows for easy customization and extension. Traders and developers are encouraged to modify existing strategies, add new ones, or enhance the system's capabilities. Contributions to the `bbstrader` project are welcome.
54
+
55
+ ## Contributing to BBSTrader
56
+
57
+ We warmly welcome contributions from the trading and development community! Whether you're interested in fixing bugs, adding new features, or improving documentation, your help is invaluable to making `bbstrader` more robust and versatile. Here's how you can contribute:
58
+
59
+ ### Ways to Contribute
60
+
61
+ - **Develop New Strategies**: Implement and share your unique trading strategies or models.
62
+ - **Enhance Existing Modules**: Optimize the performance, extend the functionality, or improve the usability of existing modules.
63
+ - **Report Bugs**: Identify and report bugs to help us improve the system's stability and performance.
64
+ - **Improve Documentation**: Contribute to the project's documentation for clearer guidance and better usability.
65
+ - **Share Insights and Best Practices**: Provide examples, tutorials, or best practices on utilizing `bbstrader` effectively.
66
+
67
+ ### How to Get Started
68
+
69
+ 1. **Fork the Repository**: Start by forking the `bbstrader` repository to your GitHub account.
70
+ 2. **Clone Your Fork**: Clone your forked repository to your local machine to start making changes.
71
+ 3. **Set Up Your Development Environment**: Ensure you have the necessary development environment set up, including Python, MetaTrader 5, and any dependencies.
72
+ 4. **Create a New Branch**: Make your changes in a new git branch, branching off from the main branch.
73
+ 5. **Implement Your Changes**: Work on bug fixes, features, or documentation improvements.
74
+ 6. **Test Your Changes**: Ensure your changes do not introduce new issues and that they work as intended.
75
+ 7. **Submit a Pull Request**: Once you're ready, submit a pull request (PR) against the main `bbstrader` repository. Include a clear description of the changes and any other relevant information.
76
+
77
+ ### Contribution Guidelines
78
+
79
+ Please adhere to the following guidelines to ensure a smooth contribution process:
80
+
81
+ - **Follow the Coding Standards**: Write clean, readable code and follow the coding conventions used throughout the project.
82
+ - **Document Your Changes**: Add comments and update the README.md files as necessary to explain your changes or additions.
83
+ - **Respect the License**: All contributions are subject to the MIT License under which `bbstrader` is distributed.
84
+
85
+ We're excited to see your contributions and to welcome you to the `bbstrader` community. Together, we can build a powerful tool that serves the needs of traders around the world.
86
+
87
+
88
+ ## Disclaimer
89
+
90
+ Trading financial instruments involves a high level of risk and may not be suitable for all investors. The developers of `bbstrader` are not responsible for any financial losses incurred from the use of this software. Trade responsibly and at your own risk.
91
+
92
+ ## License
93
+ `bbstrader` is open source and available under the MIT License.
@@ -0,0 +1,17 @@
1
+ """
2
+ Simplified Investment & Trading Toolkit
3
+ =======================================
4
+
5
+ """
6
+ __author__ = "Bertin Balouki SIMYELI"
7
+ __copyright__ = "2023-2024 Bertin Balouki SIMYELI"
8
+ __email__ = "bbalouki@outlook.com"
9
+ __license__ = "MIT"
10
+ __version__ = "1.0.0"
11
+
12
+ from bbstrader import btengine
13
+ from bbstrader import metatrader
14
+ from bbstrader import models
15
+ from bbstrader import trading
16
+ from bbstrader import strategies
17
+ from bbstrader import tseries
@@ -0,0 +1,50 @@
1
+ """
2
+ Overview
3
+ ========
4
+
5
+ This Backtesting Module provides a comprehensive suite of tools to test trading strategies in an event-driven system.
6
+ It simulates the execution of trades in historical market conditions to evaluate the performance of trading strategies
7
+ before applying them in live trading environments. Designed with modularity and extensibility in mind, it caters to
8
+ both novices and experts in algorithmic trading.
9
+
10
+ Features
11
+ ========
12
+
13
+ - **Event-Driven Architecture**: Processes market data, generates signals, executes orders, and manages portfolio updates in response to events, closely mimicking live trading environments.
14
+ - **Historical Market Data Support**: Utilizes historical OHLCV data from CSV files, Yahoo finance and MT5 terminal allowing for the testing of strategies over various market conditions and time frames.
15
+ - **Strategy Implementation Flexibility**: Abstract base classes for strategies and other components enable users to define custom trading logic and data handling processes.
16
+ - **Performance Metrics Calculation**: Includes tools for calculating key performance indicators, such as `Sharpe Ratio`, `Sortino Ratio`, and `drawdowns`, to evaluate the effectiveness of trading strategies.
17
+ - **Visualization**: Generates plots of the `equity curve`, `returns`, `drawdowns`, and other metrics for comprehensive strategy `performance analysis`.
18
+
19
+ Components
20
+ ==========
21
+
22
+ - **Backtest**: Orchestrates the backtesting process, managing events and invoking components.
23
+ - **Event**: Abstract class for events, with implementations for market data, signals, fill and order events.
24
+ - **DataHandler**: Abstract class for market data handling, with an implementation for `HistoricalCSVHandler`, `MT5HistoricDataHandler`, `YFHistoricDataHandler`. We will add another data handling in the future such as MacroEconomic Data, Fundamental Data, TICK Data and Real-time Data.
25
+ - **Strategy**: Abstract class for trading strategies, allowing for custom signal generation logic.
26
+ - **Portfolio**: Manages positions and calculates performance metrics, responding to market data and signals.
27
+ - **ExecutionHandler**: Abstract class for order execution, with a simulated execution handler provided with an implementation for `SimulatedExecutionHandler`.
28
+ - **Performance**: Utility functions for calculating performance metrics and visualizing strategy performance.
29
+
30
+ Examples:
31
+ >>> from bbstrader.btengine import run_backtest
32
+ >>> run_backtest(test_mode=True, test_strategy='ou', test_quantity=2000)
33
+
34
+ >>> run_backtest(
35
+ ... symbol_list=['AAPL', 'GOOG'],
36
+ ... start_date=datetime(2020, 1, 1),
37
+ ... data_handler=CustomDataHandler(),
38
+ ... strategy=MovingAverageStrategy(),
39
+ ... exc_handler=CustomExecutionHandler(),
40
+ ... initial_capital=500000.0,
41
+ ... heartbeat=1.0
42
+ ... )
43
+ """
44
+ from bbstrader.btengine.data import *
45
+ from bbstrader.btengine.event import *
46
+ from bbstrader.btengine.execution import *
47
+ from bbstrader.btengine.performance import *
48
+ from bbstrader.btengine.backtest import *
49
+ from bbstrader.btengine.portfolio import Portfolio
50
+ from bbstrader.btengine.strategy import Strategy