bbstrader 0.2.91__py3-none-any.whl → 0.2.93__py3-none-any.whl
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.
- bbstrader/__main__.py +50 -0
- bbstrader/btengine/data.py +12 -9
- bbstrader/btengine/execution.py +13 -2
- bbstrader/btengine/performance.py +50 -1
- bbstrader/btengine/scripts.py +157 -0
- bbstrader/btengine/strategy.py +12 -2
- bbstrader/compat.py +2 -2
- bbstrader/config.py +2 -4
- bbstrader/core/utils.py +90 -1
- bbstrader/metatrader/__init__.py +2 -1
- bbstrader/metatrader/account.py +29 -39
- bbstrader/metatrader/copier.py +745 -0
- bbstrader/metatrader/rates.py +6 -3
- bbstrader/metatrader/risk.py +19 -8
- bbstrader/metatrader/scripts.py +81 -0
- bbstrader/metatrader/trade.py +178 -66
- bbstrader/metatrader/utils.py +5 -2
- bbstrader/models/ml.py +20 -12
- bbstrader/trading/execution.py +150 -33
- bbstrader/trading/script.py +155 -0
- bbstrader/trading/scripts.py +2 -0
- bbstrader/tseries.py +33 -7
- {bbstrader-0.2.91.dist-info → bbstrader-0.2.93.dist-info}/METADATA +6 -2
- bbstrader-0.2.93.dist-info/RECORD +44 -0
- {bbstrader-0.2.91.dist-info → bbstrader-0.2.93.dist-info}/WHEEL +1 -1
- bbstrader-0.2.93.dist-info/entry_points.txt +2 -0
- bbstrader-0.2.91.dist-info/RECORD +0 -38
- {bbstrader-0.2.91.dist-info → bbstrader-0.2.93.dist-info}/LICENSE +0 -0
- {bbstrader-0.2.91.dist-info → bbstrader-0.2.93.dist-info}/top_level.txt +0 -0
bbstrader/tseries.py
CHANGED
|
@@ -598,7 +598,9 @@ def plot_residuals(df: pd.DataFrame):
|
|
|
598
598
|
|
|
599
599
|
|
|
600
600
|
def run_cadf_test(
|
|
601
|
-
pair: Union[List[str], Tuple[str, ...]],
|
|
601
|
+
pair: Union[List[str], Tuple[str, ...]],
|
|
602
|
+
start: str,
|
|
603
|
+
end: str,
|
|
602
604
|
) -> None:
|
|
603
605
|
"""
|
|
604
606
|
Performs the Cointegration Augmented Dickey-Fuller (CADF) test on a pair of stock tickers
|
|
@@ -666,8 +668,22 @@ def run_cadf_test(
|
|
|
666
668
|
"""
|
|
667
669
|
# Download historical data for required stocks
|
|
668
670
|
p0, p1 = pair[0], pair[1]
|
|
669
|
-
_p0 = yf.download(
|
|
670
|
-
|
|
671
|
+
_p0 = yf.download(
|
|
672
|
+
p0,
|
|
673
|
+
start=start,
|
|
674
|
+
end=end,
|
|
675
|
+
progress=False,
|
|
676
|
+
multi_level_index=False,
|
|
677
|
+
auto_adjust=True,
|
|
678
|
+
)
|
|
679
|
+
_p1 = yf.download(
|
|
680
|
+
p1,
|
|
681
|
+
start=start,
|
|
682
|
+
end=end,
|
|
683
|
+
progress=False,
|
|
684
|
+
multi_level_index=False,
|
|
685
|
+
auto_adjust=True,
|
|
686
|
+
)
|
|
671
687
|
df = pd.DataFrame(index=_p0.index)
|
|
672
688
|
df[p0] = _p0["Adj Close"]
|
|
673
689
|
df[p1] = _p1["Adj Close"]
|
|
@@ -751,7 +767,12 @@ def run_hurst_test(symbol: str, start: str, end: str):
|
|
|
751
767
|
>>> run_hurst_test('AAPL', '2023-01-01', '2023-12-31')
|
|
752
768
|
"""
|
|
753
769
|
data = yf.download(
|
|
754
|
-
symbol,
|
|
770
|
+
symbol,
|
|
771
|
+
start=start,
|
|
772
|
+
end=end,
|
|
773
|
+
progress=False,
|
|
774
|
+
multi_level_index=False,
|
|
775
|
+
auto_adjust=True,
|
|
755
776
|
)
|
|
756
777
|
|
|
757
778
|
# Create a Geometric Brownian Motion, Mean-Reverting, and Trending Series
|
|
@@ -774,6 +795,7 @@ def test_cointegration(ticker1, ticker2, start, end):
|
|
|
774
795
|
end=end,
|
|
775
796
|
progress=False,
|
|
776
797
|
multi_level_index=False,
|
|
798
|
+
auto_adjust=True,
|
|
777
799
|
)["Adj Close"].dropna()
|
|
778
800
|
|
|
779
801
|
# Perform Johansen cointegration test
|
|
@@ -917,8 +939,12 @@ def run_kalman_filter(
|
|
|
917
939
|
|
|
918
940
|
>>> run_kalman_filter(['SPY', 'QQQ'], '2023-01-01', '2023-12-31')
|
|
919
941
|
"""
|
|
920
|
-
etf_df1 = yf.download(
|
|
921
|
-
|
|
942
|
+
etf_df1 = yf.download(
|
|
943
|
+
etfs[0], start, end, progress=False, multi_level_index=False, auto_adjust=True
|
|
944
|
+
)
|
|
945
|
+
etf_df2 = yf.download(
|
|
946
|
+
etfs[1], start, end, progress=False, multi_level_index=False, auto_adjust=True
|
|
947
|
+
)
|
|
922
948
|
|
|
923
949
|
prices = pd.DataFrame(index=etf_df1.index)
|
|
924
950
|
prices[etfs[0]] = etf_df1["Adj Close"]
|
|
@@ -1674,7 +1700,7 @@ def analyze_cointegrated_pairs(
|
|
|
1674
1700
|
y = spreads.coint
|
|
1675
1701
|
X = spreads[["drift", "vol", "corr", "corr_ret"]]
|
|
1676
1702
|
decision_tree.fit(X, y)
|
|
1677
|
-
res = f
|
|
1703
|
+
res = f"{decision_tree.best_score_:.2%}, Depth: {decision_tree.best_params_['max_depth']}"
|
|
1678
1704
|
print(res)
|
|
1679
1705
|
|
|
1680
1706
|
if crosstab:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: bbstrader
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.93
|
|
4
4
|
Summary: Simplified Investment & Trading Toolkit
|
|
5
5
|
Home-page: https://github.com/bbalouki/bbstrader
|
|
6
6
|
Download-URL: https://pypi.org/project/bbstrader/
|
|
@@ -55,6 +55,8 @@ Requires-Dist: financetoolkit
|
|
|
55
55
|
Requires-Dist: tables
|
|
56
56
|
Requires-Dist: lightgbm
|
|
57
57
|
Requires-Dist: alphalens-reloaded
|
|
58
|
+
Requires-Dist: pyfiglet
|
|
59
|
+
Requires-Dist: colorama
|
|
58
60
|
Provides-Extra: mt5
|
|
59
61
|
Requires-Dist: MetaTrader5; extra == "mt5"
|
|
60
62
|
Dynamic: author
|
|
@@ -104,6 +106,7 @@ It leverages statistical models and algorithms to perform tasks such as cointegr
|
|
|
104
106
|
- **Comprehensive Backtesting**: Assess the performance of trading strategies with historical market data to optimize parameters and strategies for live trading environments.
|
|
105
107
|
- **Integrated Risk Management**: Leverage advanced risk management techniques to adapt to changing market conditions and maintain control over risk exposure.
|
|
106
108
|
- **Automated Trading**: Execute trades automatically on the MT5 platform, with support for managing orders, positions, and risk in real-time.
|
|
109
|
+
- **Trade Copier**: Copy trades from one account to another or multiple accounts.
|
|
107
110
|
- **Flexible Framework**: Customize existing strategies or develop new ones with the flexible, modular architecture designed to accommodate traders' evolving needs.
|
|
108
111
|
- **Advanced Time Series Analysis**: Conduct in-depth analysis of financial time series data to identify patterns, trends, and relationships that can inform trading strategies.
|
|
109
112
|
You can read the full documentation [here](https://bbstrader.readthedocs.io/en/latest/index.html)
|
|
@@ -118,7 +121,8 @@ This Module currenlty support three brokers, [Admirals Group AS](https://cabinet
|
|
|
118
121
|
|
|
119
122
|
Then, you can install `bbstrader` using pip:
|
|
120
123
|
```bash
|
|
121
|
-
pip install bbstrader
|
|
124
|
+
pip install bbstrader # Mac and Linux
|
|
125
|
+
pip install bbstrader[MT5] # Windows
|
|
122
126
|
```
|
|
123
127
|
|
|
124
128
|
## Examples
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
bbstrader/__ini__.py,sha256=ahTl0_LzPsSMLr0Ae_hV78IuMFvMFDwPOBQh4kQltes,641
|
|
2
|
+
bbstrader/__main__.py,sha256=JvWLoIN03J1VKwmrJN0Z8m7uFfAL3F-6c_Yij_CUAgM,1534
|
|
3
|
+
bbstrader/compat.py,sha256=YYubimfqHj8yPFhfqCDvz9eddMK9JJUYvxQDle6-tNU,506
|
|
4
|
+
bbstrader/config.py,sha256=YMH9O_b0eJdfTwlw6GNbjRo0ieQMTH893crgwbbW5fQ,4110
|
|
5
|
+
bbstrader/tseries.py,sha256=lbsbEl7jNyKHqkHdzX_DqAlZ7z46dGOJWB6kG2Y60qg,70181
|
|
6
|
+
bbstrader/btengine/__init__.py,sha256=FL0kC0NcsnlTH-yuTv4lu6AexY1wZKN1AQ9rv9MZagQ,3009
|
|
7
|
+
bbstrader/btengine/backtest.py,sha256=ZzGhoN-_g0cF-OCyk173imze2OXEhykHTUiJ9MowDO8,14582
|
|
8
|
+
bbstrader/btengine/data.py,sha256=UpHW27o7cb9ibQJ6JYovfG_zyxA9SCwR0-Zv7zUQxSM,27296
|
|
9
|
+
bbstrader/btengine/event.py,sha256=38mhZH9d53C4x7bZER2B0O6M18txzS4u7zveKyxeP5Y,8603
|
|
10
|
+
bbstrader/btengine/execution.py,sha256=Ij5dLc9mGgtWp2dKAH5oURplA3RS_ZtwTwSrp9IYfpk,10644
|
|
11
|
+
bbstrader/btengine/performance.py,sha256=1ecWrTzHBQbk4ORvbTEKxwCzlL1brcXOEUwgbnjAwx4,12470
|
|
12
|
+
bbstrader/btengine/portfolio.py,sha256=mh2_zNJDmKzb0lo55PXhbXYxXMmXRA4YLkgzwxRMuZE,16110
|
|
13
|
+
bbstrader/btengine/scripts.py,sha256=Dff0cMvaZBynczVagY91XvHxQR7v53lMXyHMF69n3DY,4994
|
|
14
|
+
bbstrader/btengine/strategy.py,sha256=c-wvotJdhHu5FWAlPkv33LfjoW-7ID2G0Di_hc7CYMM,33217
|
|
15
|
+
bbstrader/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
+
bbstrader/core/data.py,sha256=3_odj9jxokyKU15j1aHTlgLQDjW75tKqGpCUfkpYq2Q,452
|
|
17
|
+
bbstrader/core/utils.py,sha256=yC4_BqymZ4_t5J6y3bRY5J8hCT_0ooSPD8rqwj_aYdM,4225
|
|
18
|
+
bbstrader/ibkr/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
|
+
bbstrader/ibkr/utils.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
+
bbstrader/metatrader/__init__.py,sha256=_vDoSBDTQ9JVhN6HsSYmTBx8womTvbJ222aqTRG5rmE,339
|
|
21
|
+
bbstrader/metatrader/account.py,sha256=As2LtWUbVnobM5I1WPNAYv5_w_7mMm5xF31jaOtI8IU,58009
|
|
22
|
+
bbstrader/metatrader/copier.py,sha256=eoztbIlzBAJ-zjNpcq4NN7QnFkGJ3VSRqVmr6oGhUtA,32412
|
|
23
|
+
bbstrader/metatrader/rates.py,sha256=DzjObLlas38TnprPsw4xPxTupCRwy_jZzLezCU_4p0I,21169
|
|
24
|
+
bbstrader/metatrader/risk.py,sha256=jLrLiQWb_v8Dl480jXaUbA-yV4ck8ES4PArTRAWILE0,27680
|
|
25
|
+
bbstrader/metatrader/scripts.py,sha256=zgY94YGL7l_tzVnbkZWlj5YRRogM1jHY9i3Vxxmh6qQ,2196
|
|
26
|
+
bbstrader/metatrader/trade.py,sha256=f1fETc83bmLru0hXtu5VpV73lB3dGMVJrHf8cdsirdI,78616
|
|
27
|
+
bbstrader/metatrader/utils.py,sha256=1d7A8XhUmiLGpG4ImcBhCgs7xHrmYe_YJhynWIdLr30,17748
|
|
28
|
+
bbstrader/models/__init__.py,sha256=SnGBMQ-zcUIpms3oNeqg7EVDFpg-7OPjNAD8kvi_Q84,508
|
|
29
|
+
bbstrader/models/factors.py,sha256=dWuXh83hLkwxUp3XwjgUl-r3_cjVcV_s0aFRlSLIfo8,13332
|
|
30
|
+
bbstrader/models/ml.py,sha256=dSoKL409RPEKUc0lQkzMh66--x7JsiB69BZKF1RzGoU,48791
|
|
31
|
+
bbstrader/models/optimization.py,sha256=gp0n9a9vwbUldaNiZUYry_4RP2NW0VFZ2k5NoOkz30c,6581
|
|
32
|
+
bbstrader/models/portfolio.py,sha256=-Zq9cmzyOZUlGq9RWfAxClpX0KJZqYZYpc5EGNTcPGI,8302
|
|
33
|
+
bbstrader/models/risk.py,sha256=IFQoHXxpBwJiifANRgwyAUOp7EgTWBAhfJFCO1sGR3g,15405
|
|
34
|
+
bbstrader/trading/__init__.py,sha256=2VoxbzfP1XBLVuxJtjRhjEBCtnv9HqwQzfMV4B5mM7M,468
|
|
35
|
+
bbstrader/trading/execution.py,sha256=kRkvrX2HjGvIWgtGR3ar8FSkJmqPDFAWExYOaQMUrZQ,35495
|
|
36
|
+
bbstrader/trading/script.py,sha256=No6XW_Cz4vc28CtfcMhCDokb_ctXK-D4sGiOjxwMCXg,5875
|
|
37
|
+
bbstrader/trading/scripts.py,sha256=rYK-LF2rmiHwpImfJ3P2HTMUcVU372Fxqj5UP6ypTJ0,1926
|
|
38
|
+
bbstrader/trading/strategies.py,sha256=rMvLIhX_8MQg7_Lbo127UqdTRxBUof2m3jgRQTm55p0,37019
|
|
39
|
+
bbstrader-0.2.93.dist-info/LICENSE,sha256=P3PBO9RuYPzl6-PkjysTNnwmwMB64ph36Bz9DBj8MS4,1115
|
|
40
|
+
bbstrader-0.2.93.dist-info/METADATA,sha256=IUHCIzp-HO_VPJPubFU_IWVhaoeHMM41_ytwOcSBM4M,11546
|
|
41
|
+
bbstrader-0.2.93.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
|
42
|
+
bbstrader-0.2.93.dist-info/entry_points.txt,sha256=0yDCbhbgHswOzJnY5wRSM_FjjyMHGvY7lJpSSVh0xtI,54
|
|
43
|
+
bbstrader-0.2.93.dist-info/top_level.txt,sha256=Wwj322jZmxGZ6gD_TdaPiPLjED5ReObm5omerwlmZIg,10
|
|
44
|
+
bbstrader-0.2.93.dist-info/RECORD,,
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
bbstrader/__ini__.py,sha256=ahTl0_LzPsSMLr0Ae_hV78IuMFvMFDwPOBQh4kQltes,641
|
|
2
|
-
bbstrader/compat.py,sha256=xx7ZW6Tx_wuCedKxkzt2dQQRsVNwamqszr6LJ88qnPg,494
|
|
3
|
-
bbstrader/config.py,sha256=USwdS5qaGbc1Wp5rF0ckP3R1HEZJ8tY0tkZX4CkgNoc,4204
|
|
4
|
-
bbstrader/tseries.py,sha256=GYNDo03dYEnYHwcQYKpclNDGCwvZ_qAPyou0vhQndS0,69851
|
|
5
|
-
bbstrader/btengine/__init__.py,sha256=FL0kC0NcsnlTH-yuTv4lu6AexY1wZKN1AQ9rv9MZagQ,3009
|
|
6
|
-
bbstrader/btengine/backtest.py,sha256=ZzGhoN-_g0cF-OCyk173imze2OXEhykHTUiJ9MowDO8,14582
|
|
7
|
-
bbstrader/btengine/data.py,sha256=Ycd0rXTT8h_WZBdMKJe_O3EiN5GGA1m-zECRxoU_40w,27172
|
|
8
|
-
bbstrader/btengine/event.py,sha256=38mhZH9d53C4x7bZER2B0O6M18txzS4u7zveKyxeP5Y,8603
|
|
9
|
-
bbstrader/btengine/execution.py,sha256=6YfErbqJx2DTy6r4cfZLU8F1YsJG-p8jEhNepdb9Sxc,10376
|
|
10
|
-
bbstrader/btengine/performance.py,sha256=0meGbMFYzzI9n_09qf4RFpdyqQmCa6C_iu6PvE2POIE,10787
|
|
11
|
-
bbstrader/btengine/portfolio.py,sha256=mh2_zNJDmKzb0lo55PXhbXYxXMmXRA4YLkgzwxRMuZE,16110
|
|
12
|
-
bbstrader/btengine/strategy.py,sha256=EiE1P_V0wlFIsA-2U5POQ7qtRMkr1OTH1pQia4jBcGY,32937
|
|
13
|
-
bbstrader/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
-
bbstrader/core/data.py,sha256=3_odj9jxokyKU15j1aHTlgLQDjW75tKqGpCUfkpYq2Q,452
|
|
15
|
-
bbstrader/core/utils.py,sha256=oB4OC0tQDJ1FIaJCuNWUlTzOccHoACSJsP_f7ELrqXQ,1448
|
|
16
|
-
bbstrader/ibkr/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
-
bbstrader/ibkr/utils.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
-
bbstrader/metatrader/__init__.py,sha256=rrL_EtecsOCD2Cwhmpgta5CjSGT0K6vzSBiQoyCLe3M,283
|
|
19
|
-
bbstrader/metatrader/account.py,sha256=o-5Jbn_z3mc0xkffHz0AfOkASxyLCWz_6D714vKpLTk,58265
|
|
20
|
-
bbstrader/metatrader/rates.py,sha256=XyJlNhKrBp4MSMh-mM3-WZaYVMniMe1V4OT7RszbQqs,21137
|
|
21
|
-
bbstrader/metatrader/risk.py,sha256=9cBclFZzzXxHXIlBQlwXo9SZx_8PTDn0TDPG5kAUyZ4,27623
|
|
22
|
-
bbstrader/metatrader/trade.py,sha256=yUrvGg7NxjhSfLpJ2UWALfEokkObLcFe7xbBYb5DOfI,74790
|
|
23
|
-
bbstrader/metatrader/utils.py,sha256=sR6C9jm_JFNU1uxuSaQuYLqwbgz19c1tqKwvW0ByAtA,17716
|
|
24
|
-
bbstrader/models/__init__.py,sha256=SnGBMQ-zcUIpms3oNeqg7EVDFpg-7OPjNAD8kvi_Q84,508
|
|
25
|
-
bbstrader/models/factors.py,sha256=dWuXh83hLkwxUp3XwjgUl-r3_cjVcV_s0aFRlSLIfo8,13332
|
|
26
|
-
bbstrader/models/ml.py,sha256=ipnrjcjigp1OgKd0XmoiNu_6s1gfzwqe8BiClymS4vs,48483
|
|
27
|
-
bbstrader/models/optimization.py,sha256=gp0n9a9vwbUldaNiZUYry_4RP2NW0VFZ2k5NoOkz30c,6581
|
|
28
|
-
bbstrader/models/portfolio.py,sha256=-Zq9cmzyOZUlGq9RWfAxClpX0KJZqYZYpc5EGNTcPGI,8302
|
|
29
|
-
bbstrader/models/risk.py,sha256=IFQoHXxpBwJiifANRgwyAUOp7EgTWBAhfJFCO1sGR3g,15405
|
|
30
|
-
bbstrader/trading/__init__.py,sha256=2VoxbzfP1XBLVuxJtjRhjEBCtnv9HqwQzfMV4B5mM7M,468
|
|
31
|
-
bbstrader/trading/execution.py,sha256=ap5HEm7u8vi3vcTQCca87a5Bsfr7ne1hyefAwxuE4pY,30995
|
|
32
|
-
bbstrader/trading/scripts.py,sha256=pNwHr-3mW87G5fyIMd93wS43NkzOZn4npt4fLNnSUyk,1922
|
|
33
|
-
bbstrader/trading/strategies.py,sha256=rMvLIhX_8MQg7_Lbo127UqdTRxBUof2m3jgRQTm55p0,37019
|
|
34
|
-
bbstrader-0.2.91.dist-info/LICENSE,sha256=P3PBO9RuYPzl6-PkjysTNnwmwMB64ph36Bz9DBj8MS4,1115
|
|
35
|
-
bbstrader-0.2.91.dist-info/METADATA,sha256=p7lknhoGBQ4jx8GoWH3icJW5U0NhhpXNGySr-ll2LY8,11359
|
|
36
|
-
bbstrader-0.2.91.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
37
|
-
bbstrader-0.2.91.dist-info/top_level.txt,sha256=Wwj322jZmxGZ6gD_TdaPiPLjED5ReObm5omerwlmZIg,10
|
|
38
|
-
bbstrader-0.2.91.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|