vectorbt 1.1.1__tar.gz → 1.1.2__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.
- {vectorbt-1.1.1/vectorbt.egg-info → vectorbt-1.1.2}/PKG-INFO +7 -7
- {vectorbt-1.1.1 → vectorbt-1.1.2}/README.md +5 -5
- {vectorbt-1.1.1 → vectorbt-1.1.2}/pyproject.toml +1 -1
- {vectorbt-1.1.1 → vectorbt-1.1.2}/tests/test_plotting.py +40 -1
- {vectorbt-1.1.1 → vectorbt-1.1.2}/tests/test_portfolio.py +131 -7
- {vectorbt-1.1.1 → vectorbt-1.1.2}/tests/test_returns.py +49 -1
- {vectorbt-1.1.1 → vectorbt-1.1.2}/tests/test_utils.py +72 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/_version.py +1 -1
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/base/indexing.py +2 -2
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/base/reshape_fns.py +2 -2
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/data/base.py +2 -2
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/data/custom.py +3 -3
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/data/updater.py +2 -2
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/generic/accessors.py +1 -1
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/generic/ranges.py +2 -2
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/generic/splitters.py +3 -3
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/indicators/basic.py +3 -3
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/indicators/factory.py +3 -3
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/portfolio/base.py +9 -6
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/portfolio/trades.py +19 -20
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/returns/accessors.py +1 -1
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/returns/nb.py +4 -1
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/signals/accessors.py +2 -2
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/array_.py +1 -1
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/config.py +2 -2
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/datetime_.py +24 -2
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/decorators.py +2 -2
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/params.py +2 -2
- {vectorbt-1.1.1 → vectorbt-1.1.2/vectorbt.egg-info}/PKG-INFO +7 -7
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt.egg-info/requires.txt +1 -1
- {vectorbt-1.1.1 → vectorbt-1.1.2}/LICENSE.md +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/MANIFEST.in +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/setup.cfg +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/setup.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/tests/test_base.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/tests/test_data.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/tests/test_engine.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/tests/test_generic.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/tests/test_indicators.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/tests/test_labels.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/tests/test_records.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/tests/test_settings.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/tests/test_signals.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/__init__.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/_engine.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/_settings.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/_typing.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/base/__init__.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/base/accessors.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/base/array_wrapper.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/base/column_grouper.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/base/combine_fns.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/base/index_fns.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/data/__init__.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/generic/__init__.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/generic/decorators.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/generic/dispatch.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/generic/drawdowns.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/generic/enums.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/generic/nb.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/generic/plots_builder.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/generic/plotting.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/generic/stats_builder.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/indicators/__init__.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/indicators/configs.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/indicators/dispatch.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/indicators/nb.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/labels/__init__.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/labels/dispatch.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/labels/enums.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/labels/generators.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/labels/nb.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/messaging/__init__.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/messaging/telegram.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/ohlcv_accessors.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/portfolio/__init__.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/portfolio/decorators.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/portfolio/dispatch.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/portfolio/enums.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/portfolio/logs.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/portfolio/nb.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/portfolio/orders.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/px_accessors.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/records/__init__.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/records/base.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/records/col_mapper.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/records/decorators.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/records/dispatch.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/records/mapped_array.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/records/nb.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/returns/__init__.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/returns/dispatch.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/returns/metrics.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/returns/qs_adapter.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/root_accessors.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/signals/__init__.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/signals/dispatch.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/signals/enums.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/signals/factory.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/signals/generators.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/signals/nb.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/templates/dark.json +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/templates/light.json +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/templates/seaborn.json +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/__init__.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/attr_.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/checks.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/colors.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/docs.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/enum_.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/figure.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/image_.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/mapping.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/math_.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/module_.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/random_.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/requests_.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/schedule_.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/tags.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt/utils/template.py +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt.egg-info/SOURCES.txt +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt.egg-info/dependency_links.txt +0 -0
- {vectorbt-1.1.1 → vectorbt-1.1.2}/vectorbt.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vectorbt
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.2
|
|
4
4
|
Summary: Python library for backtesting and analyzing trading strategies at scale
|
|
5
5
|
Author-email: Oleg Polakow <olegpolakow@vectorbt.pro>
|
|
6
6
|
Project-URL: Homepage, https://github.com/polakowo/vectorbt
|
|
@@ -37,7 +37,7 @@ Requires-Dist: requests
|
|
|
37
37
|
Requires-Dist: pytz
|
|
38
38
|
Requires-Dist: mypy_extensions
|
|
39
39
|
Provides-Extra: rust
|
|
40
|
-
Requires-Dist: vectorbt-rust==1.1.
|
|
40
|
+
Requires-Dist: vectorbt-rust==1.1.2; extra == "rust"
|
|
41
41
|
Provides-Extra: full
|
|
42
42
|
Requires-Dist: TA-Lib; extra == "full"
|
|
43
43
|
Requires-Dist: yfinance>=0.2.22; extra == "full"
|
|
@@ -206,9 +206,9 @@ print(pf.total_profit())
|
|
|
206
206
|
> [!TIP]
|
|
207
207
|
> **VectorBT PRO**
|
|
208
208
|
>
|
|
209
|
-
> Simulate [limit orders](https://vectorbt.pro/features/
|
|
210
|
-
> use [leverage](https://vectorbt.pro/features/
|
|
211
|
-
> [contract multipliers](https://vectorbt.pro/features/
|
|
209
|
+
> Simulate [limit orders](https://vectorbt.pro/features/backtesting/orders-and-execution/#limit-orders),
|
|
210
|
+
> use [leverage](https://vectorbt.pro/features/backtesting/fees-slippage-and-leverage/#leverage), and model futures with
|
|
211
|
+
> [contract multipliers](https://vectorbt.pro/features/backtesting/fees-slippage-and-leverage/#contract-multiplier).
|
|
212
212
|
|
|
213
213
|
### Generate 1,000 random strategies
|
|
214
214
|
|
|
@@ -254,8 +254,8 @@ fig.show()
|
|
|
254
254
|
> [!TIP]
|
|
255
255
|
> **VectorBT PRO**
|
|
256
256
|
>
|
|
257
|
-
> Use [random search](https://vectorbt.pro/features/optimization/#random-search) to sample a large
|
|
258
|
-
> parameter grid, or [conditional parameters](https://vectorbt.pro/features/optimization/#conditional-parameters)
|
|
257
|
+
> Use [random search](https://vectorbt.pro/features/optimization/strategy-optimization/#random-search) to sample a large
|
|
258
|
+
> parameter grid, or [conditional parameters](https://vectorbt.pro/features/optimization/strategy-optimization/#conditional-parameters)
|
|
259
259
|
> to exclude combinations such as a fast MA window longer than the slow MA window. The
|
|
260
260
|
> [cross-validation tutorial](https://vectorbt.pro/tutorials/cross-validation/)
|
|
261
261
|
> shows how to select parameters on training data and evaluate them on later periods.
|
|
@@ -136,9 +136,9 @@ print(pf.total_profit())
|
|
|
136
136
|
> [!TIP]
|
|
137
137
|
> **VectorBT PRO**
|
|
138
138
|
>
|
|
139
|
-
> Simulate [limit orders](https://vectorbt.pro/features/
|
|
140
|
-
> use [leverage](https://vectorbt.pro/features/
|
|
141
|
-
> [contract multipliers](https://vectorbt.pro/features/
|
|
139
|
+
> Simulate [limit orders](https://vectorbt.pro/features/backtesting/orders-and-execution/#limit-orders),
|
|
140
|
+
> use [leverage](https://vectorbt.pro/features/backtesting/fees-slippage-and-leverage/#leverage), and model futures with
|
|
141
|
+
> [contract multipliers](https://vectorbt.pro/features/backtesting/fees-slippage-and-leverage/#contract-multiplier).
|
|
142
142
|
|
|
143
143
|
### Generate 1,000 random strategies
|
|
144
144
|
|
|
@@ -184,8 +184,8 @@ fig.show()
|
|
|
184
184
|
> [!TIP]
|
|
185
185
|
> **VectorBT PRO**
|
|
186
186
|
>
|
|
187
|
-
> Use [random search](https://vectorbt.pro/features/optimization/#random-search) to sample a large
|
|
188
|
-
> parameter grid, or [conditional parameters](https://vectorbt.pro/features/optimization/#conditional-parameters)
|
|
187
|
+
> Use [random search](https://vectorbt.pro/features/optimization/strategy-optimization/#random-search) to sample a large
|
|
188
|
+
> parameter grid, or [conditional parameters](https://vectorbt.pro/features/optimization/strategy-optimization/#conditional-parameters)
|
|
189
189
|
> to exclude combinations such as a fast MA window longer than the slow MA window. The
|
|
190
190
|
> [cross-validation tutorial](https://vectorbt.pro/tutorials/cross-validation/)
|
|
191
191
|
> shows how to select parameters on training data and evaluate them on later periods.
|
|
@@ -22,9 +22,9 @@ from plotly.basedatatypes import BaseFigure
|
|
|
22
22
|
|
|
23
23
|
import vectorbt as vbt
|
|
24
24
|
from vectorbt.generic.plotting import Scatter, Bar, Histogram, Heatmap, Gauge, Box, Volume, TraceUpdater
|
|
25
|
+
from vectorbt.portfolio.base import Portfolio
|
|
25
26
|
from vectorbt.utils.figure import make_figure, make_subplots, Figure, FigureWidget
|
|
26
27
|
|
|
27
|
-
|
|
28
28
|
# ############# Fixtures ############# #
|
|
29
29
|
|
|
30
30
|
index_5 = pd.DatetimeIndex([datetime(2020, 1, d) for d in range(1, 6)])
|
|
@@ -625,6 +625,45 @@ class TestTradesPlotPnl:
|
|
|
625
625
|
# pct_scale=False: y-values are absolute PnL
|
|
626
626
|
np.testing.assert_array_almost_equal(fig_abs.data[0].y, [1.78, 2.77])
|
|
627
627
|
|
|
628
|
+
def test_trades_plot_pnl_non_finite_returns(self):
|
|
629
|
+
"""Non-finite returns should not invalidate Plotly marker metadata."""
|
|
630
|
+
# Cover the issue's exact case where no finite return is available for scaling.
|
|
631
|
+
open_pf = Portfolio.from_orders(
|
|
632
|
+
pd.Series([1.0, np.nan]),
|
|
633
|
+
pd.Series([1.0, 0.0]),
|
|
634
|
+
ffill_val_price=False,
|
|
635
|
+
)
|
|
636
|
+
|
|
637
|
+
# Exercise both the direct records API and its Portfolio convenience delegate.
|
|
638
|
+
for fig in (open_pf.get_trades().plot_pnl(), open_pf.plot_trade_pnl()):
|
|
639
|
+
assert isinstance(fig, BaseFigure)
|
|
640
|
+
nt = named_traces(fig)
|
|
641
|
+
|
|
642
|
+
# Without a finite reference, the open marker should use both lower bounds.
|
|
643
|
+
np.testing.assert_array_equal(nt["Open"].marker.size, [7.0])
|
|
644
|
+
np.testing.assert_array_equal(nt["Open"].marker.opacity, [0.75])
|
|
645
|
+
|
|
646
|
+
# One unknown open trade must not alter the scaling of finite closed trades.
|
|
647
|
+
close = pd.Series([1.0, 2.0, 1.0, 3.0, 1.0, np.nan])
|
|
648
|
+
size = pd.Series([1.0, -1.0, 1.0, -1.0, 1.0, 0.0])
|
|
649
|
+
pf = Portfolio.from_orders(close, size, ffill_val_price=False)
|
|
650
|
+
|
|
651
|
+
# Require identical marker behavior from the direct and delegated plotting paths.
|
|
652
|
+
for fig in (pf.get_trades().plot_pnl(), pf.plot_trade_pnl()):
|
|
653
|
+
assert isinstance(fig, BaseFigure)
|
|
654
|
+
nt = named_traces(fig)
|
|
655
|
+
|
|
656
|
+
# Finite trades keep their relative endpoints while the unknown trade uses the minima.
|
|
657
|
+
np.testing.assert_array_equal(nt["Closed - Profit"].marker.size, [7.0, 14.0])
|
|
658
|
+
np.testing.assert_array_equal(nt["Closed - Profit"].marker.opacity, [0.75, 0.9])
|
|
659
|
+
np.testing.assert_array_equal(nt["Open"].marker.size, [7.0])
|
|
660
|
+
np.testing.assert_array_equal(nt["Open"].marker.opacity, [0.75])
|
|
661
|
+
|
|
662
|
+
# Guard every emitted trace against metadata that Plotly would reject.
|
|
663
|
+
for trace in fig.data:
|
|
664
|
+
assert np.all(np.isfinite(trace.marker.size))
|
|
665
|
+
assert np.all(np.isfinite(trace.marker.opacity))
|
|
666
|
+
|
|
628
667
|
|
|
629
668
|
class TestDrawdownsPlot:
|
|
630
669
|
def test_drawdowns_plot_with_zones(self):
|
|
@@ -84,17 +84,51 @@ def test_order_func_init_records(test_row_wise, test_flexible):
|
|
|
84
84
|
assert pf.orders.count() == 0
|
|
85
85
|
record_arrays_close(
|
|
86
86
|
seen["order_records"],
|
|
87
|
-
np.array([(
|
|
87
|
+
np.array([(-1, -1, -1, np.nan, np.nan, np.nan, -1)], dtype=order_dt),
|
|
88
88
|
)
|
|
89
89
|
record_arrays_close(
|
|
90
90
|
seen["log_records"],
|
|
91
91
|
np.array(
|
|
92
92
|
[
|
|
93
93
|
(
|
|
94
|
-
-1,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
-1,
|
|
95
|
+
-1,
|
|
96
|
+
-1,
|
|
97
|
+
-1,
|
|
98
|
+
np.nan,
|
|
99
|
+
np.nan,
|
|
100
|
+
np.nan,
|
|
101
|
+
np.nan,
|
|
102
|
+
np.nan,
|
|
103
|
+
np.nan,
|
|
104
|
+
np.nan,
|
|
105
|
+
np.nan,
|
|
106
|
+
-1,
|
|
107
|
+
-1,
|
|
108
|
+
np.nan,
|
|
109
|
+
np.nan,
|
|
110
|
+
np.nan,
|
|
111
|
+
np.nan,
|
|
112
|
+
np.nan,
|
|
113
|
+
np.nan,
|
|
114
|
+
np.nan,
|
|
115
|
+
False,
|
|
116
|
+
False,
|
|
117
|
+
False,
|
|
118
|
+
False,
|
|
119
|
+
np.nan,
|
|
120
|
+
np.nan,
|
|
121
|
+
np.nan,
|
|
122
|
+
np.nan,
|
|
123
|
+
np.nan,
|
|
124
|
+
np.nan,
|
|
125
|
+
np.nan,
|
|
126
|
+
np.nan,
|
|
127
|
+
np.nan,
|
|
128
|
+
-1,
|
|
129
|
+
-1,
|
|
130
|
+
-1,
|
|
131
|
+
-1,
|
|
98
132
|
)
|
|
99
133
|
],
|
|
100
134
|
dtype=log_dt,
|
|
@@ -102,12 +136,16 @@ def test_order_func_init_records(test_row_wise, test_flexible):
|
|
|
102
136
|
)
|
|
103
137
|
record_arrays_close(
|
|
104
138
|
seen["last_pos_record"],
|
|
105
|
-
np.array(
|
|
139
|
+
np.array(
|
|
140
|
+
[(-1, -1, np.nan, -1, np.nan, np.nan, -1, np.nan, np.nan, np.nan, np.nan, -1, -1, -1)], dtype=trade_dt
|
|
141
|
+
),
|
|
106
142
|
)
|
|
107
143
|
if not test_flexible:
|
|
108
144
|
record_arrays_close(
|
|
109
145
|
seen["pos_record_now"],
|
|
110
|
-
np.array(
|
|
146
|
+
np.array(
|
|
147
|
+
(-1, -1, np.nan, -1, np.nan, np.nan, -1, np.nan, np.nan, np.nan, np.nan, -1, -1, -1), dtype=trade_dt
|
|
148
|
+
),
|
|
111
149
|
)
|
|
112
150
|
|
|
113
151
|
|
|
@@ -10829,3 +10867,89 @@ class TestPortfolio:
|
|
|
10829
10867
|
_ = pf.plot(subplots="all")
|
|
10830
10868
|
with pytest.raises(Exception):
|
|
10831
10869
|
_ = pf_grouped.plot(subplots="all")
|
|
10870
|
+
|
|
10871
|
+
|
|
10872
|
+
# ############# Issue #810: Best Trade [%] definition ############# #
|
|
10873
|
+
|
|
10874
|
+
|
|
10875
|
+
def test_best_trade_pct_definition():
|
|
10876
|
+
"""Regression test for issue #810.
|
|
10877
|
+
|
|
10878
|
+
Best Trade [%] is the maximum individual trade return, net of fees, relative
|
|
10879
|
+
to gross entry notional (NOT portfolio initial cash). By default, only closed
|
|
10880
|
+
trades are included; incl_open=True also includes open trades.
|
|
10881
|
+
"""
|
|
10882
|
+
# Two short trades: B has larger PnL, A has higher return
|
|
10883
|
+
# Trade A: entry=100, exit=90, size=10 -> PnL=100, Return=10%
|
|
10884
|
+
# Trade B: entry=200, exit=190, size=100 -> PnL=1000, Return=5%
|
|
10885
|
+
price = pd.Series(
|
|
10886
|
+
[100.0, 90.0, 200.0, 190.0],
|
|
10887
|
+
index=pd.date_range("2020-01-01", periods=4, freq="D"),
|
|
10888
|
+
)
|
|
10889
|
+
# Entries at 0 and 2, exits at 1 and 3
|
|
10890
|
+
entries = pd.Series([True, False, True, False], index=price.index)
|
|
10891
|
+
exits = pd.Series([False, True, False, True], index=price.index)
|
|
10892
|
+
size = pd.Series([10.0, np.nan, 100.0, np.nan], index=price.index)
|
|
10893
|
+
|
|
10894
|
+
pf = vbt.Portfolio.from_signals(price, entries, exits, size=size, direction="shortonly", init_cash=1000000)
|
|
10895
|
+
|
|
10896
|
+
# B has the larger PnL
|
|
10897
|
+
assert pf.trades.pnl.max() == 1000.0
|
|
10898
|
+
# But A has the higher return -> Best Trade [%] must be 10.0, not 5.0
|
|
10899
|
+
np.testing.assert_allclose(pf.trades.returns.max(), 0.10)
|
|
10900
|
+
np.testing.assert_allclose(pf.stats()["Best Trade [%]"], 10.0)
|
|
10901
|
+
|
|
10902
|
+
# Definition consistency: stats value == max trade return * 100
|
|
10903
|
+
expected = pf.trades.closed.returns.max() * 100
|
|
10904
|
+
np.testing.assert_allclose(pf.stats()["Best Trade [%]"], expected)
|
|
10905
|
+
|
|
10906
|
+
|
|
10907
|
+
@pytest.mark.parametrize("fees", [0.0, 0.001])
|
|
10908
|
+
def test_short_trade_return_math(fees):
|
|
10909
|
+
"""Short trade return is net of fees, relative to gross entry notional."""
|
|
10910
|
+
price = pd.Series(
|
|
10911
|
+
[100.0, 90.0],
|
|
10912
|
+
index=pd.date_range("2020-01-01", periods=2, freq="D"),
|
|
10913
|
+
)
|
|
10914
|
+
entries = pd.Series([True, False], index=price.index)
|
|
10915
|
+
exits = pd.Series([False, True], index=price.index)
|
|
10916
|
+
|
|
10917
|
+
pf = vbt.Portfolio.from_signals(price, entries, exits, size=10.0, direction="shortonly", fees=fees)
|
|
10918
|
+
trade = pf.trades.records_readable.iloc[0]
|
|
10919
|
+
# Short: profit when price falls. entry=100, exit=90, size=10
|
|
10920
|
+
# Both entry and exit fees reduce PnL; the denominator excludes fees.
|
|
10921
|
+
expected_pnl = 10.0 * (100.0 - 90.0) - fees * 10.0 * (100.0 + 90.0)
|
|
10922
|
+
np.testing.assert_allclose(trade["PnL"], expected_pnl)
|
|
10923
|
+
np.testing.assert_allclose(trade["Return"], trade["PnL"] / (trade["Size"] * trade["Avg Entry Price"]))
|
|
10924
|
+
np.testing.assert_allclose(trade["Return"], expected_pnl / 1000.0)
|
|
10925
|
+
|
|
10926
|
+
|
|
10927
|
+
@pytest.mark.parametrize("incl_open", [False, True])
|
|
10928
|
+
def test_best_worst_trade_pct_incl_open(incl_open):
|
|
10929
|
+
"""Best/Worst Trade [%] use closed trades unless incl_open=True."""
|
|
10930
|
+
price = pd.DataFrame(
|
|
10931
|
+
{"best": [100.0, 90.0, 100.0, 80.0, 80.0, 80.0], "worst": [100.0, 90.0, 100.0, 80.0, 100.0, 110.0]},
|
|
10932
|
+
index=pd.date_range("2020-01-01", periods=6, freq="D"),
|
|
10933
|
+
)
|
|
10934
|
+
entries = pd.DataFrame(
|
|
10935
|
+
{
|
|
10936
|
+
"best": [True, False, True, False, False, False],
|
|
10937
|
+
"worst": [True, False, False, False, True, False],
|
|
10938
|
+
},
|
|
10939
|
+
index=price.index,
|
|
10940
|
+
)
|
|
10941
|
+
exits = pd.Series([False, True, False, False, False, False], index=price.index)
|
|
10942
|
+
pf = vbt.Portfolio.from_signals(price, entries, exits, size=10.0, direction="shortonly", fees=0.001)
|
|
10943
|
+
for column, metric, reducer in [
|
|
10944
|
+
("best", "Best Trade [%]", "max"),
|
|
10945
|
+
("worst", "Worst Trade [%]", "min"),
|
|
10946
|
+
]:
|
|
10947
|
+
trades = pf[column].trades
|
|
10948
|
+
assert trades.closed.count() == 1
|
|
10949
|
+
assert trades.open.count() == 1
|
|
10950
|
+
selected = trades if incl_open else trades.closed
|
|
10951
|
+
expected = getattr(selected.returns, reducer)() * 100
|
|
10952
|
+
actual = pf.stats(column=column, settings=dict(incl_open=incl_open))[metric]
|
|
10953
|
+
np.testing.assert_allclose(actual, expected)
|
|
10954
|
+
if incl_open:
|
|
10955
|
+
assert not np.isclose(actual, getattr(trades.closed.returns, reducer)() * 100)
|
|
@@ -6,6 +6,7 @@ import pytest
|
|
|
6
6
|
from scipy.stats import kurtosis, norm, skew
|
|
7
7
|
|
|
8
8
|
import vectorbt as vbt
|
|
9
|
+
from vectorbt import _engine
|
|
9
10
|
from tests.utils import isclose
|
|
10
11
|
from vectorbt.returns.metrics import approx_exp_max_sharpe
|
|
11
12
|
|
|
@@ -517,6 +518,51 @@ class TestAccessors:
|
|
|
517
518
|
),
|
|
518
519
|
)
|
|
519
520
|
|
|
521
|
+
def test_cond_value_at_risk_nan(self):
|
|
522
|
+
arr = np.array(
|
|
523
|
+
[-0.05, 0.01, np.nan, -0.02, 0.03, 0.02, -0.01, 0.04, -0.03, 0.0]
|
|
524
|
+
+ [0.01, 0.02, -0.04, 0.01, 0.02, 0.03, -0.02, 0.01, 0.0, 0.02, 0.01]
|
|
525
|
+
).reshape(-1, 1)
|
|
526
|
+
clean = arr[~np.isnan(arr[:, 0])]
|
|
527
|
+
result = vbt.returns.nb.cond_value_at_risk_nb(arr, 0.1)
|
|
528
|
+
np.testing.assert_allclose(result, vbt.returns.nb.cond_value_at_risk_nb(clean, 0.1))
|
|
529
|
+
np.testing.assert_allclose(result, [np.mean([-0.05, -0.04])])
|
|
530
|
+
assert np.isnan(vbt.returns.nb.cond_value_at_risk_nb(np.full((3, 1), np.nan), 0.1)[0])
|
|
531
|
+
assert np.isnan(vbt.returns.nb.cond_value_at_risk_nb(np.empty((0, 1)), 0.1)[0])
|
|
532
|
+
|
|
533
|
+
def test_rolling_cond_value_at_risk_nan(self):
|
|
534
|
+
arr = np.array([-0.05, 0.01, np.nan, -0.02, 0.03, 0.02, -0.01, 0.04, -0.03, 0.0, 0.01, np.nan, -0.04]).reshape(
|
|
535
|
+
-1, 1
|
|
536
|
+
)
|
|
537
|
+
window = 6
|
|
538
|
+
result = vbt.returns.nb.rolling_cond_value_at_risk_nb(arr, window, 1, 0.2)
|
|
539
|
+
expected = np.full(len(arr), np.nan)
|
|
540
|
+
for i in range(len(arr)):
|
|
541
|
+
chunk = arr[max(0, i - window + 1) : i + 1, 0]
|
|
542
|
+
chunk = chunk[~np.isnan(chunk)]
|
|
543
|
+
if len(chunk) > 0:
|
|
544
|
+
k = int((len(chunk) - 1) * 0.2)
|
|
545
|
+
expected[i] = np.sort(chunk)[: k + 1].mean()
|
|
546
|
+
np.testing.assert_allclose(result[:, 0], expected)
|
|
547
|
+
|
|
548
|
+
@pytest.mark.skipif(not _engine.is_rust_available(), reason="vectorbt-rust is not installed or version-compatible")
|
|
549
|
+
def test_cond_value_at_risk_nan_rust(self):
|
|
550
|
+
arr = np.array(
|
|
551
|
+
[-0.05, 0.01, np.nan, -0.02, 0.03, 0.02, -0.01, 0.04, -0.03, 0.0]
|
|
552
|
+
+ [0.01, 0.02, -0.04, 0.01, 0.02, 0.03, -0.02, 0.01, 0.0, 0.02, 0.01]
|
|
553
|
+
).reshape(-1, 1)
|
|
554
|
+
np.testing.assert_allclose(
|
|
555
|
+
vbt.returns.dispatch.cond_value_at_risk(arr, 0.1, engine="rust"),
|
|
556
|
+
vbt.returns.nb.cond_value_at_risk_nb(arr, 0.1),
|
|
557
|
+
)
|
|
558
|
+
all_nan = np.full((3, 1), np.nan)
|
|
559
|
+
assert np.isnan(vbt.returns.dispatch.cond_value_at_risk(all_nan, 0.1, engine="rust")[0])
|
|
560
|
+
np.testing.assert_allclose(
|
|
561
|
+
vbt.returns.dispatch.rolling_cond_value_at_risk(arr, 6, 1, 0.2, engine="rust"),
|
|
562
|
+
vbt.returns.nb.rolling_cond_value_at_risk_nb(arr, 6, 1, 0.2),
|
|
563
|
+
equal_nan=True,
|
|
564
|
+
)
|
|
565
|
+
|
|
520
566
|
def test_capture(self):
|
|
521
567
|
assert isclose(rets["a"].vbt.returns.capture(benchmark_rets["a"]), 0.0007435597416888084)
|
|
522
568
|
pd.testing.assert_series_equal(
|
|
@@ -633,7 +679,9 @@ class TestAccessors:
|
|
|
633
679
|
assert rets["a"].vbt.returns.drawdowns.wrapper.freq == rets["a"].vbt.wrapper.freq
|
|
634
680
|
assert rets["a"].vbt.returns.drawdowns.wrapper.ndim == rets["a"].ndim
|
|
635
681
|
assert rets.vbt.returns.drawdowns.wrapper.ndim == rets.ndim
|
|
636
|
-
assert isclose(
|
|
682
|
+
assert isclose(
|
|
683
|
+
rets["a"].vbt.returns.drawdowns.max_drawdown(fill_value=0.0), rets["a"].vbt.returns.max_drawdown()
|
|
684
|
+
)
|
|
637
685
|
pd.testing.assert_series_equal(
|
|
638
686
|
rets.vbt.returns.drawdowns.max_drawdown(fill_value=0.0), rets.vbt.returns.max_drawdown()
|
|
639
687
|
)
|
|
@@ -2021,12 +2021,14 @@ class TestArray:
|
|
|
2021
2021
|
assert array_.is_sorted(np.array([0]))
|
|
2022
2022
|
assert not array_.is_sorted(np.array([1, 0]))
|
|
2023
2023
|
assert not array_.is_sorted(np.array([0, 1, 2, 4, 3]))
|
|
2024
|
+
assert not array_.is_sorted(np.array([0.0, np.nan, 1.0]))
|
|
2024
2025
|
# nb
|
|
2025
2026
|
assert array_.is_sorted_nb(np.array([0, 1, 2, 3, 4]))
|
|
2026
2027
|
assert array_.is_sorted_nb(np.array([0, 1]))
|
|
2027
2028
|
assert array_.is_sorted_nb(np.array([0]))
|
|
2028
2029
|
assert not array_.is_sorted_nb(np.array([1, 0]))
|
|
2029
2030
|
assert not array_.is_sorted_nb(np.array([0, 1, 2, 4, 3]))
|
|
2031
|
+
assert not array_.is_sorted_nb(np.array([0.0, np.nan, 1.0]))
|
|
2030
2032
|
|
|
2031
2033
|
def test_insert_argsort_nb(self):
|
|
2032
2034
|
a = np.random.uniform(size=1000)
|
|
@@ -2362,6 +2364,76 @@ class TestDatetime:
|
|
|
2362
2364
|
with pytest.raises(Exception):
|
|
2363
2365
|
_ = datetime_.to_tzaware_datetime("2020-01-001")
|
|
2364
2366
|
|
|
2367
|
+
@pytest.mark.parametrize(
|
|
2368
|
+
"value, expected",
|
|
2369
|
+
[
|
|
2370
|
+
(np.datetime64("2020", "Y"), _datetime(2020, 1, 1)),
|
|
2371
|
+
(np.datetime64("2020-02", "M"), _datetime(2020, 2, 1)),
|
|
2372
|
+
(np.datetime64("2020-01-02", "W"), _datetime(2020, 1, 2)),
|
|
2373
|
+
(np.datetime64("2020-01-02", "D"), _datetime(2020, 1, 2)),
|
|
2374
|
+
(np.datetime64("2020-01-02T13", "h"), _datetime(2020, 1, 2, 13)),
|
|
2375
|
+
(np.datetime64("2020-01-02T13:14", "m"), _datetime(2020, 1, 2, 13, 14)),
|
|
2376
|
+
(np.datetime64("2020-01-02T13:14:15", "s"), _datetime(2020, 1, 2, 13, 14, 15)),
|
|
2377
|
+
(np.datetime64("2020-01-02T13:14:15.123", "ms"), _datetime(2020, 1, 2, 13, 14, 15, 123000)),
|
|
2378
|
+
(np.datetime64("2020-01-02T13:14:15.123456", "us"), _datetime(2020, 1, 2, 13, 14, 15, 123456)),
|
|
2379
|
+
(np.datetime64("2020-01-02T13:14:15.123456789", "ns"), _datetime(2020, 1, 2, 13, 14, 15, 123456)),
|
|
2380
|
+
(np.datetime64("1969-12-31T23:59:59.999999999", "ns"), _datetime(1969, 12, 31, 23, 59, 59, 999999)),
|
|
2381
|
+
(np.datetime64("1970-01-01T00:00:00.123456789012", "ps"), _datetime(1970, 1, 1, 0, 0, 0, 123456)),
|
|
2382
|
+
(np.datetime64("1970-01-01T00:00:00.123456789012345", "fs"), _datetime(1970, 1, 1, 0, 0, 0, 123456)),
|
|
2383
|
+
(np.datetime64("1970-01-01T00:00:00.123456789012345678", "as"), _datetime(1970, 1, 1, 0, 0, 0, 123456)),
|
|
2384
|
+
(np.datetime64(2**63 - 1, "2ns"), _datetime(2554, 7, 21, 23, 34, 33, 709551)),
|
|
2385
|
+
(np.datetime64(-(2**63) + 1, "ns"), _datetime(1677, 9, 21, 0, 12, 43, 145224)),
|
|
2386
|
+
(np.datetime64(-(2**63) + 1, "ps"), _datetime(1969, 9, 16, 5, 57, 7, 963145)),
|
|
2387
|
+
(np.datetime64(-(2**63) + 1, "fs"), _datetime(1969, 12, 31, 21, 26, 16, 627963)),
|
|
2388
|
+
(np.datetime64(-(2**63) + 1, "as"), _datetime(1969, 12, 31, 23, 59, 50, 776627)),
|
|
2389
|
+
(np.datetime64(-(2**63) + 1, "2ns"), _datetime(1385, 6, 12, 0, 25, 26, 290448)),
|
|
2390
|
+
],
|
|
2391
|
+
)
|
|
2392
|
+
@pytest.mark.parametrize("tz", [None, "UTC"])
|
|
2393
|
+
def test_to_tzaware_datetime_numpy(self, value, expected, tz):
|
|
2394
|
+
source_tz = _timezone(_timedelta(hours=2))
|
|
2395
|
+
expected = expected.replace(tzinfo=source_tz)
|
|
2396
|
+
if tz is not None:
|
|
2397
|
+
expected = expected.astimezone(_timezone.utc)
|
|
2398
|
+
assert datetime_.to_tzaware_datetime(value, naive_tz=source_tz, tz=tz) == expected
|
|
2399
|
+
|
|
2400
|
+
@pytest.mark.parametrize(
|
|
2401
|
+
"value, expected",
|
|
2402
|
+
[
|
|
2403
|
+
(np.datetime64("0001-01-01", "us"), _datetime.min),
|
|
2404
|
+
(np.datetime64("9999-12-31T23:59:59.999999", "us"), _datetime.max),
|
|
2405
|
+
(np.datetime64(-6213559680000000, "10000ns"), _datetime.min),
|
|
2406
|
+
(np.datetime64(25340230079999999, "10000ns"), _datetime(9999, 12, 31, 23, 59, 59, 999990)),
|
|
2407
|
+
],
|
|
2408
|
+
)
|
|
2409
|
+
def test_to_tzaware_datetime_numpy_boundaries(self, value, expected):
|
|
2410
|
+
assert datetime_.to_tzaware_datetime(value, naive_tz="UTC") == expected.replace(tzinfo=_timezone.utc)
|
|
2411
|
+
|
|
2412
|
+
@pytest.mark.parametrize(
|
|
2413
|
+
"value",
|
|
2414
|
+
[
|
|
2415
|
+
np.datetime64("NaT"),
|
|
2416
|
+
np.datetime64("NaT", "us"),
|
|
2417
|
+
np.datetime64("NaT", "ns"),
|
|
2418
|
+
np.datetime64("0000-12-31", "D"),
|
|
2419
|
+
np.datetime64("10000-01-01", "D"),
|
|
2420
|
+
np.datetime64("12000-01-01", "us"),
|
|
2421
|
+
np.datetime64("586554-01-18", "D"),
|
|
2422
|
+
np.datetime64("-582556-12-14", "D"),
|
|
2423
|
+
np.datetime64("586554", "Y"),
|
|
2424
|
+
np.datetime64("-582556", "Y"),
|
|
2425
|
+
np.datetime64("586554-01", "M"),
|
|
2426
|
+
np.datetime64("-582556-12", "M"),
|
|
2427
|
+
np.datetime64(2**63 - 1, "2Y"),
|
|
2428
|
+
np.datetime64(-(2**63) + 1, "2Y"),
|
|
2429
|
+
np.datetime64(2**63 - 1, "10000ns"),
|
|
2430
|
+
np.datetime64(-(2**63) + 1, "10000ns"),
|
|
2431
|
+
],
|
|
2432
|
+
)
|
|
2433
|
+
def test_to_tzaware_datetime_numpy_invalid(self, value):
|
|
2434
|
+
with pytest.raises(ValueError, match="Couldn't parse the datetime"):
|
|
2435
|
+
datetime_.to_tzaware_datetime(value, naive_tz="UTC")
|
|
2436
|
+
|
|
2365
2437
|
def test_datetime_to_ms(self):
|
|
2366
2438
|
assert (
|
|
2367
2439
|
datetime_.datetime_to_ms(_datetime(2020, 1, 1))
|
|
@@ -10,8 +10,8 @@ one can manipulate complex classes with dozens of pandas objects using a single
|
|
|
10
10
|
|
|
11
11
|
!!! tip "VectorBT PRO"
|
|
12
12
|
|
|
13
|
-
[Slice rows of portfolio and indicator objects](https://vectorbt.pro/features/
|
|
14
|
-
to analyze a date range, or [stack objects along columns](https://vectorbt.pro/features/
|
|
13
|
+
[Slice rows of portfolio and indicator objects](https://vectorbt.pro/features/tooling/multidimensional-research/#slicing)
|
|
14
|
+
to analyze a date range, or [stack objects along columns](https://vectorbt.pro/features/tooling/multidimensional-research/#column-stacking)
|
|
15
15
|
to combine results from different assets or strategies.
|
|
16
16
|
|
|
17
17
|
"""
|
|
@@ -8,9 +8,9 @@ and unstacking.
|
|
|
8
8
|
|
|
9
9
|
!!! tip "VectorBT PRO"
|
|
10
10
|
|
|
11
|
-
[Array-like parameters](https://vectorbt.pro/features/optimization/#array-like-parameters)
|
|
11
|
+
[Array-like parameters](https://vectorbt.pro/features/optimization/strategy-optimization/#array-like-parameters)
|
|
12
12
|
automatically broadcast combinations of values, such as stop distances, alongside time series.
|
|
13
|
-
[Align arrays with different indexes](https://vectorbt.pro/features/
|
|
13
|
+
[Align arrays with different indexes](https://vectorbt.pro/features/tooling/multidimensional-research/#index-alignment)
|
|
14
14
|
before broadcasting.
|
|
15
15
|
|
|
16
16
|
"""
|
|
@@ -9,8 +9,8 @@ all pandas objects have the same index and columns by aligning them.
|
|
|
9
9
|
|
|
10
10
|
!!! tip "VectorBT PRO"
|
|
11
11
|
|
|
12
|
-
Read and write [Parquet files](https://vectorbt.pro/features/data/#pyarrow
|
|
13
|
-
and [SQL databases](https://vectorbt.pro/features/data/#sqlalchemy).
|
|
12
|
+
Read and write [Parquet files](https://vectorbt.pro/features/data/data-storage-and-databases/#pyarrow-and-fastparquet)
|
|
13
|
+
and [SQL databases](https://vectorbt.pro/features/data/data-storage-and-databases/#sqlalchemy).
|
|
14
14
|
|
|
15
15
|
## Downloading
|
|
16
16
|
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
!!! tip "VectorBT PRO"
|
|
7
7
|
|
|
8
|
-
Additional providers include [Databento](https://vectorbt.pro/features/data/#databento) and
|
|
9
|
-
[TradingView](https://vectorbt.pro/features/data/#trading-view).
|
|
10
|
-
[Symbol search](https://vectorbt.pro/features/data/#symbol-search) retrieves available symbols
|
|
8
|
+
Additional providers include [Databento](https://vectorbt.pro/features/data/market-data-sources/#databento) and
|
|
9
|
+
[TradingView](https://vectorbt.pro/features/data/tradingview-data/#trading-view).
|
|
10
|
+
[Symbol search](https://vectorbt.pro/features/data/market-data-sources/#symbol-search) retrieves available symbols
|
|
11
11
|
and filters them by name.
|
|
12
12
|
|
|
13
13
|
"""
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
!!! tip "VectorBT PRO"
|
|
7
7
|
|
|
8
|
-
[Data savers](https://vectorbt.pro/features/data/#data-saver) periodically fetch new data
|
|
9
|
-
and write it to CSV or HDF5. [Parallel data updates](https://vectorbt.pro/features/data/#parallel-data)
|
|
8
|
+
[Data savers](https://vectorbt.pro/features/data/data-storage-and-databases/#data-saver) periodically fetch new data
|
|
9
|
+
and write it to CSV or HDF5. [Parallel data updates](https://vectorbt.pro/features/data/financial-data-pipelines/#parallel-data)
|
|
10
10
|
process multiple symbols concurrently.
|
|
11
11
|
|
|
12
12
|
"""
|
|
@@ -650,7 +650,7 @@ class GenericAccessor(BaseAccessor, StatsBuilderMixin, PlotsBuilderMixin, metacl
|
|
|
650
650
|
!!! tip "VectorBT PRO"
|
|
651
651
|
|
|
652
652
|
For aligning bars by when their price information becomes available, see the
|
|
653
|
-
[resampling examples](https://vectorbt.pro/features/
|
|
653
|
+
[resampling examples](https://vectorbt.pro/features/data/multi-timeframe-analysis/#safe-resampling).
|
|
654
654
|
|
|
655
655
|
Usage:
|
|
656
656
|
```pycon
|
|
@@ -45,8 +45,8 @@ Timedelta('74 days 00:00:00')
|
|
|
45
45
|
|
|
46
46
|
!!! tip "VectorBT PRO"
|
|
47
47
|
|
|
48
|
-
[Pattern ranges](https://vectorbt.pro/features/
|
|
49
|
-
a price pattern. [Projections](https://vectorbt.pro/features/
|
|
48
|
+
[Pattern ranges](https://vectorbt.pro/features/analytics/patterns-and-event-studies/#patterns) locate windows that match
|
|
49
|
+
a price pattern. [Projections](https://vectorbt.pro/features/analytics/patterns-and-event-studies/#projections) collect
|
|
50
50
|
price paths after events and calculate their distributions.
|
|
51
51
|
|
|
52
52
|
## From accessors
|
|
@@ -7,9 +7,9 @@ Defines splitter classes similar (but may not compatible) to `sklearn.model_sele
|
|
|
7
7
|
|
|
8
8
|
!!! tip "VectorBT PRO"
|
|
9
9
|
|
|
10
|
-
Apply [purging and embargoing](https://vectorbt.pro/features/optimization/#purged-cv)
|
|
11
|
-
to cross-validation splits, [run a function on each split](https://vectorbt.pro/features/optimization/#split-decorator),
|
|
12
|
-
and inspect [rolling, expanding, and time-anchored splits](https://vectorbt.pro/features/optimization/#splitter).
|
|
10
|
+
Apply [purging and embargoing](https://vectorbt.pro/features/optimization/time-series-cross-validation/#purged-cv)
|
|
11
|
+
to cross-validation splits, [run a function on each split](https://vectorbt.pro/features/optimization/time-series-cross-validation/#split-decorator),
|
|
12
|
+
and inspect [rolling, expanding, and time-anchored splits](https://vectorbt.pro/features/optimization/time-series-cross-validation/#splitter).
|
|
13
13
|
|
|
14
14
|
"""
|
|
15
15
|
|
|
@@ -7,9 +7,9 @@ You can access all the indicators either by `vbt.*` or `vbt.indicators.*`.
|
|
|
7
7
|
|
|
8
8
|
!!! tip "VectorBT PRO"
|
|
9
9
|
|
|
10
|
-
Additional indicators include the [Hurst exponent](https://vectorbt.pro/features/indicators/#hurst-exponent)
|
|
11
|
-
and [Smart Money Concepts](https://vectorbt.pro/features/indicators/#smart-money-concepts).
|
|
12
|
-
[Streaming indicators](https://vectorbt.pro/features/indicators/#streaming-indicators)
|
|
10
|
+
Additional indicators include the [Hurst exponent](https://vectorbt.pro/features/indicators/technical-indicators/#hurst-exponent)
|
|
11
|
+
and [Smart Money Concepts](https://vectorbt.pro/features/indicators/technical-indicators/#smart-money-concepts).
|
|
12
|
+
[Streaming indicators](https://vectorbt.pro/features/indicators/streaming-indicators/#streaming-indicators)
|
|
13
13
|
update their values one observation at a time.
|
|
14
14
|
|
|
15
15
|
```pycon
|
|
@@ -33,9 +33,9 @@ Each generated class includes the following features:
|
|
|
33
33
|
|
|
34
34
|
!!! tip "VectorBT PRO"
|
|
35
35
|
|
|
36
|
-
Wrap functions that accept [one-dimensional inputs](https://vectorbt.pro/features/indicators/#1d-native-indicators),
|
|
37
|
-
[run parameter combinations in parallel](https://vectorbt.pro/features/indicators/#parallelizable-indicators),
|
|
38
|
-
or [run all indicators from a package](https://vectorbt.pro/features/indicators/#indicators-for-ml)
|
|
36
|
+
Wrap functions that accept [one-dimensional inputs](https://vectorbt.pro/features/indicators/indicator-development/#1d-native-indicators),
|
|
37
|
+
[run parameter combinations in parallel](https://vectorbt.pro/features/indicators/indicator-development/#parallelizable-indicators),
|
|
38
|
+
or [run all indicators from a package](https://vectorbt.pro/features/indicators/indicator-development/#indicators-for-ml)
|
|
39
39
|
to generate features for a machine-learning model.
|
|
40
40
|
|
|
41
41
|
Consider the following price DataFrame composed of two columns, one per asset:
|
|
@@ -63,9 +63,9 @@ Run for the examples below:
|
|
|
63
63
|
|
|
64
64
|
!!! tip "VectorBT PRO"
|
|
65
65
|
|
|
66
|
-
[Create portfolios from execution records](https://vectorbt.pro/features/
|
|
67
|
-
model futures with [contract multipliers](https://vectorbt.pro/features/
|
|
68
|
-
[continue simulations as new data arrives](https://vectorbt.pro/features/
|
|
66
|
+
[Create portfolios from execution records](https://vectorbt.pro/features/backtesting/orders-and-execution/#portfolio-from-fills),
|
|
67
|
+
model futures with [contract multipliers](https://vectorbt.pro/features/backtesting/fees-slippage-and-leverage/#contract-multiplier), or
|
|
68
|
+
[continue simulations as new data arrives](https://vectorbt.pro/features/backtesting/live-simulation/#portfolio-continuation).
|
|
69
69
|
The [portfolio documentation preview](https://vectorbt.pro/documentation/portfolio/)
|
|
70
70
|
shows the available simulation methods and analysis topics.
|
|
71
71
|
|
|
@@ -1418,6 +1418,7 @@ You can also replace templates across all subplots by using the global template
|
|
|
1418
1418
|
|
|
1419
1419
|

|
|
1420
1420
|
"""
|
|
1421
|
+
|
|
1421
1422
|
import warnings
|
|
1422
1423
|
|
|
1423
1424
|
import numpy as np
|
|
@@ -1486,9 +1487,7 @@ returns_acc_config = Config(
|
|
|
1486
1487
|
)
|
|
1487
1488
|
"""_"""
|
|
1488
1489
|
|
|
1489
|
-
__pdoc__[
|
|
1490
|
-
"returns_acc_config"
|
|
1491
|
-
] = f"""Config of returns accessor methods to be added to `Portfolio`.
|
|
1490
|
+
__pdoc__["returns_acc_config"] = f"""Config of returns accessor methods to be added to `Portfolio`.
|
|
1492
1491
|
|
|
1493
1492
|
```json
|
|
1494
1493
|
{returns_acc_config.to_doc()}
|
|
@@ -4924,6 +4923,10 @@ class Portfolio(Wrapping, StatsBuilderMixin, PlotsBuilderMixin, metaclass=MetaPo
|
|
|
4924
4923
|
post_calc_func=lambda self, out, settings: out * 100,
|
|
4925
4924
|
tags=RepEval("['portfolio', 'trades', *incl_open_tags]"),
|
|
4926
4925
|
),
|
|
4926
|
+
# NOTE: Best/Worst Trade [%] is the maximum/minimum individual trade return,
|
|
4927
|
+
# net of fees, relative to gross entry notional: PnL / (size * entry_price)
|
|
4928
|
+
# (NOT PnL / portfolio initial cash). See issue #810.
|
|
4929
|
+
# Closed trades are used by default; incl_open=True also includes open trades.
|
|
4927
4930
|
best_trade=dict(
|
|
4928
4931
|
title="Best Trade [%]",
|
|
4929
4932
|
calc_func="trades.returns.max",
|