openbacktesting 0.2.0__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.
- openbacktesting/__init__.py +85 -0
- openbacktesting/aggregation.py +8 -0
- openbacktesting/broker/__init__.py +54 -0
- openbacktesting/broker/commission.py +57 -0
- openbacktesting/broker/core.py +1122 -0
- openbacktesting/broker/execution.py +62 -0
- openbacktesting/broker/instrument.py +106 -0
- openbacktesting/broker/ledger.py +60 -0
- openbacktesting/broker/models.py +236 -0
- openbacktesting/broker/observations.py +99 -0
- openbacktesting/broker/requests.py +192 -0
- openbacktesting/broker/sizing.py +76 -0
- openbacktesting/colors.py +175 -0
- openbacktesting/data/__init__.py +20 -0
- openbacktesting/data/aggregation.py +39 -0
- openbacktesting/data/context.py +30 -0
- openbacktesting/data/core.py +218 -0
- openbacktesting/data/generators.py +54 -0
- openbacktesting/data/strategy_data.py +103 -0
- openbacktesting/data/timeframe.py +69 -0
- openbacktesting/engine.py +34 -0
- openbacktesting/helpers.py +77 -0
- openbacktesting/indicator_api.py +10 -0
- openbacktesting/indicator_methods.py +123 -0
- openbacktesting/indicator_types.py +19 -0
- openbacktesting/indicators/__init__.py +7 -0
- openbacktesting/indicators/api.py +97 -0
- openbacktesting/indicators/calculus.py +75 -0
- openbacktesting/indicators/candles/__init__.py +0 -0
- openbacktesting/indicators/candles/cdl_doji.py +17 -0
- openbacktesting/indicators/candles/cdl_engulfing.py +14 -0
- openbacktesting/indicators/candles/cdl_eveningstar.py +15 -0
- openbacktesting/indicators/candles/cdl_hammer.py +14 -0
- openbacktesting/indicators/candles/cdl_harami.py +14 -0
- openbacktesting/indicators/candles/cdl_inside.py +14 -0
- openbacktesting/indicators/candles/cdl_marubozu.py +14 -0
- openbacktesting/indicators/candles/cdl_morningstar.py +15 -0
- openbacktesting/indicators/candles/cdl_shootingstar.py +14 -0
- openbacktesting/indicators/candles/cdl_z.py +28 -0
- openbacktesting/indicators/candles/ha.py +19 -0
- openbacktesting/indicators/catalog.json +8348 -0
- openbacktesting/indicators/common.py +94 -0
- openbacktesting/indicators/cycles/__init__.py +0 -0
- openbacktesting/indicators/cycles/dsp.py +10 -0
- openbacktesting/indicators/cycles/ebsw.py +10 -0
- openbacktesting/indicators/cycles/ht_dcperiod.py +10 -0
- openbacktesting/indicators/cycles/ht_dcphase.py +10 -0
- openbacktesting/indicators/cycles/ht_phasor.py +17 -0
- openbacktesting/indicators/cycles/ht_sine.py +17 -0
- openbacktesting/indicators/cycles/ht_trendmode.py +10 -0
- openbacktesting/indicators/cycles/msw.py +19 -0
- openbacktesting/indicators/methods.py +5762 -0
- openbacktesting/indicators/momentum/__init__.py +0 -0
- openbacktesting/indicators/momentum/ac.py +9 -0
- openbacktesting/indicators/momentum/ao.py +10 -0
- openbacktesting/indicators/momentum/apo.py +10 -0
- openbacktesting/indicators/momentum/bias.py +10 -0
- openbacktesting/indicators/momentum/bop.py +10 -0
- openbacktesting/indicators/momentum/brar.py +26 -0
- openbacktesting/indicators/momentum/cci.py +10 -0
- openbacktesting/indicators/momentum/cfo.py +10 -0
- openbacktesting/indicators/momentum/cg.py +10 -0
- openbacktesting/indicators/momentum/cmo.py +10 -0
- openbacktesting/indicators/momentum/coppock.py +10 -0
- openbacktesting/indicators/momentum/crsi.py +28 -0
- openbacktesting/indicators/momentum/cti.py +10 -0
- openbacktesting/indicators/momentum/dm.py +17 -0
- openbacktesting/indicators/momentum/er.py +10 -0
- openbacktesting/indicators/momentum/eri.py +17 -0
- openbacktesting/indicators/momentum/fisher.py +17 -0
- openbacktesting/indicators/momentum/fosc.py +10 -0
- openbacktesting/indicators/momentum/gator.py +13 -0
- openbacktesting/indicators/momentum/ibs.py +7 -0
- openbacktesting/indicators/momentum/inertia.py +22 -0
- openbacktesting/indicators/momentum/kdj.py +18 -0
- openbacktesting/indicators/momentum/kst.py +30 -0
- openbacktesting/indicators/momentum/lrsi.py +10 -0
- openbacktesting/indicators/momentum/macd.py +27 -0
- openbacktesting/indicators/momentum/macdext.py +27 -0
- openbacktesting/indicators/momentum/macdfix.py +18 -0
- openbacktesting/indicators/momentum/mom.py +10 -0
- openbacktesting/indicators/momentum/pgo.py +10 -0
- openbacktesting/indicators/momentum/pmo.py +13 -0
- openbacktesting/indicators/momentum/po.py +10 -0
- openbacktesting/indicators/momentum/ppo.py +20 -0
- openbacktesting/indicators/momentum/psl.py +12 -0
- openbacktesting/indicators/momentum/pvo.py +20 -0
- openbacktesting/indicators/momentum/qqe.py +31 -0
- openbacktesting/indicators/momentum/rci.py +20 -0
- openbacktesting/indicators/momentum/rmi.py +7 -0
- openbacktesting/indicators/momentum/roc.py +10 -0
- openbacktesting/indicators/momentum/rocp.py +10 -0
- openbacktesting/indicators/momentum/rocr.py +10 -0
- openbacktesting/indicators/momentum/rocr100.py +10 -0
- openbacktesting/indicators/momentum/rsi.py +10 -0
- openbacktesting/indicators/momentum/rsx.py +10 -0
- openbacktesting/indicators/momentum/rvgi.py +26 -0
- openbacktesting/indicators/momentum/slope.py +17 -0
- openbacktesting/indicators/momentum/smc_sweep.py +18 -0
- openbacktesting/indicators/momentum/smi.py +21 -0
- openbacktesting/indicators/momentum/smi_stochastic.py +15 -0
- openbacktesting/indicators/momentum/squeeze.py +47 -0
- openbacktesting/indicators/momentum/squeeze_pro.py +53 -0
- openbacktesting/indicators/momentum/stc.py +20 -0
- openbacktesting/indicators/momentum/stoch.py +19 -0
- openbacktesting/indicators/momentum/stochf.py +19 -0
- openbacktesting/indicators/momentum/stochrsi.py +19 -0
- openbacktesting/indicators/momentum/td_seq.py +17 -0
- openbacktesting/indicators/momentum/trix.py +19 -0
- openbacktesting/indicators/momentum/trixh.py +20 -0
- openbacktesting/indicators/momentum/tsi.py +26 -0
- openbacktesting/indicators/momentum/uo.py +22 -0
- openbacktesting/indicators/momentum/vwmacd.py +20 -0
- openbacktesting/indicators/momentum/wavetrend.py +15 -0
- openbacktesting/indicators/momentum/willr.py +10 -0
- openbacktesting/indicators/overlap/__init__.py +0 -0
- openbacktesting/indicators/overlap/alligator.py +13 -0
- openbacktesting/indicators/overlap/alma.py +33 -0
- openbacktesting/indicators/overlap/anchored_vwap.py +50 -0
- openbacktesting/indicators/overlap/anchored_vwap_bands.py +13 -0
- openbacktesting/indicators/overlap/avgprice.py +10 -0
- openbacktesting/indicators/overlap/dema.py +10 -0
- openbacktesting/indicators/overlap/ema.py +12 -0
- openbacktesting/indicators/overlap/frama.py +29 -0
- openbacktesting/indicators/overlap/fwma.py +10 -0
- openbacktesting/indicators/overlap/hilo.py +26 -0
- openbacktesting/indicators/overlap/hl2.py +10 -0
- openbacktesting/indicators/overlap/hlc3.py +10 -0
- openbacktesting/indicators/overlap/hma.py +10 -0
- openbacktesting/indicators/overlap/ht_trendline.py +10 -0
- openbacktesting/indicators/overlap/hwma.py +10 -0
- openbacktesting/indicators/overlap/ichimoku.py +44 -0
- openbacktesting/indicators/overlap/jma.py +10 -0
- openbacktesting/indicators/overlap/kama.py +10 -0
- openbacktesting/indicators/overlap/linreg.py +15 -0
- openbacktesting/indicators/overlap/linregangle.py +10 -0
- openbacktesting/indicators/overlap/linregintercept.py +10 -0
- openbacktesting/indicators/overlap/linregslope.py +10 -0
- openbacktesting/indicators/overlap/ma.py +10 -0
- openbacktesting/indicators/overlap/ma_envelopes.py +16 -0
- openbacktesting/indicators/overlap/mama.py +17 -0
- openbacktesting/indicators/overlap/mavp.py +17 -0
- openbacktesting/indicators/overlap/mcgd.py +10 -0
- openbacktesting/indicators/overlap/medprice.py +10 -0
- openbacktesting/indicators/overlap/midpoint.py +10 -0
- openbacktesting/indicators/overlap/midprice.py +10 -0
- openbacktesting/indicators/overlap/mmar.py +21 -0
- openbacktesting/indicators/overlap/ohlc4.py +10 -0
- openbacktesting/indicators/overlap/pwma.py +10 -0
- openbacktesting/indicators/overlap/rainbow.py +25 -0
- openbacktesting/indicators/overlap/rma.py +10 -0
- openbacktesting/indicators/overlap/sinwma.py +10 -0
- openbacktesting/indicators/overlap/sma.py +14 -0
- openbacktesting/indicators/overlap/ssf.py +10 -0
- openbacktesting/indicators/overlap/supertrend.py +21 -0
- openbacktesting/indicators/overlap/swma.py +10 -0
- openbacktesting/indicators/overlap/t3.py +10 -0
- openbacktesting/indicators/overlap/tema.py +10 -0
- openbacktesting/indicators/overlap/trima.py +10 -0
- openbacktesting/indicators/overlap/tsf.py +10 -0
- openbacktesting/indicators/overlap/typprice.py +10 -0
- openbacktesting/indicators/overlap/vidya.py +10 -0
- openbacktesting/indicators/overlap/vwap.py +10 -0
- openbacktesting/indicators/overlap/vwma.py +10 -0
- openbacktesting/indicators/overlap/wcp.py +10 -0
- openbacktesting/indicators/overlap/wma.py +10 -0
- openbacktesting/indicators/overlap/zlma.py +10 -0
- openbacktesting/indicators/performance/__init__.py +0 -0
- openbacktesting/indicators/performance/drawdown.py +18 -0
- openbacktesting/indicators/performance/log_return.py +10 -0
- openbacktesting/indicators/performance/percent_return.py +10 -0
- openbacktesting/indicators/predicates.py +88 -0
- openbacktesting/indicators/registry.py +571 -0
- openbacktesting/indicators/runtime.py +290 -0
- openbacktesting/indicators/statistics/__init__.py +0 -0
- openbacktesting/indicators/statistics/beta.py +10 -0
- openbacktesting/indicators/statistics/correl.py +10 -0
- openbacktesting/indicators/statistics/entropy.py +10 -0
- openbacktesting/indicators/statistics/kurtosis.py +10 -0
- openbacktesting/indicators/statistics/mad.py +10 -0
- openbacktesting/indicators/statistics/md.py +10 -0
- openbacktesting/indicators/statistics/median.py +10 -0
- openbacktesting/indicators/statistics/mode.py +48 -0
- openbacktesting/indicators/statistics/quantile.py +10 -0
- openbacktesting/indicators/statistics/skew.py +10 -0
- openbacktesting/indicators/statistics/stderr.py +10 -0
- openbacktesting/indicators/statistics/stdev.py +10 -0
- openbacktesting/indicators/statistics/variance.py +10 -0
- openbacktesting/indicators/statistics/zscore.py +10 -0
- openbacktesting/indicators/trend/__init__.py +0 -0
- openbacktesting/indicators/trend/adx.py +28 -0
- openbacktesting/indicators/trend/adxr.py +28 -0
- openbacktesting/indicators/trend/amat.py +19 -0
- openbacktesting/indicators/trend/aroon.py +18 -0
- openbacktesting/indicators/trend/atr_stop.py +33 -0
- openbacktesting/indicators/trend/chop.py +20 -0
- openbacktesting/indicators/trend/cksp.py +17 -0
- openbacktesting/indicators/trend/cpr.py +57 -0
- openbacktesting/indicators/trend/decay.py +10 -0
- openbacktesting/indicators/trend/decreasing.py +18 -0
- openbacktesting/indicators/trend/dpo.py +12 -0
- openbacktesting/indicators/trend/dx.py +19 -0
- openbacktesting/indicators/trend/edecay.py +10 -0
- openbacktesting/indicators/trend/increasing.py +18 -0
- openbacktesting/indicators/trend/long_run.py +10 -0
- openbacktesting/indicators/trend/minus_dm.py +10 -0
- openbacktesting/indicators/trend/pivot_points.py +89 -0
- openbacktesting/indicators/trend/pivothigh.py +23 -0
- openbacktesting/indicators/trend/pivotlow.py +23 -0
- openbacktesting/indicators/trend/plus_dm.py +10 -0
- openbacktesting/indicators/trend/pmax.py +18 -0
- openbacktesting/indicators/trend/psar.py +19 -0
- openbacktesting/indicators/trend/qstick.py +10 -0
- openbacktesting/indicators/trend/sarext.py +35 -0
- openbacktesting/indicators/trend/short_run.py +10 -0
- openbacktesting/indicators/trend/tsignals.py +26 -0
- openbacktesting/indicators/trend/ttm_trend.py +16 -0
- openbacktesting/indicators/trend/vhf.py +10 -0
- openbacktesting/indicators/trend/volatility_stop.py +33 -0
- openbacktesting/indicators/trend/vortex.py +17 -0
- openbacktesting/indicators/trend/xsignals.py +29 -0
- openbacktesting/indicators/types.py +344 -0
- openbacktesting/indicators/utility/__init__.py +0 -0
- openbacktesting/indicators/utility/barssince.py +21 -0
- openbacktesting/indicators/utility/change.py +7 -0
- openbacktesting/indicators/utility/cross.py +12 -0
- openbacktesting/indicators/utility/crossover.py +11 -0
- openbacktesting/indicators/utility/crossunder.py +11 -0
- openbacktesting/indicators/utility/cum.py +7 -0
- openbacktesting/indicators/utility/falling.py +10 -0
- openbacktesting/indicators/utility/highest.py +7 -0
- openbacktesting/indicators/utility/highestbars.py +29 -0
- openbacktesting/indicators/utility/lowest.py +7 -0
- openbacktesting/indicators/utility/lowestbars.py +29 -0
- openbacktesting/indicators/utility/percentile_linear_interpolation.py +12 -0
- openbacktesting/indicators/utility/percentile_nearest_rank.py +16 -0
- openbacktesting/indicators/utility/percentrank.py +7 -0
- openbacktesting/indicators/utility/range.py +8 -0
- openbacktesting/indicators/utility/rising.py +10 -0
- openbacktesting/indicators/utility/rolling_count.py +12 -0
- openbacktesting/indicators/utility/rolling_sum.py +7 -0
- openbacktesting/indicators/utility/running_max.py +7 -0
- openbacktesting/indicators/utility/running_min.py +7 -0
- openbacktesting/indicators/utility/shift.py +7 -0
- openbacktesting/indicators/utility/valuewhen.py +25 -0
- openbacktesting/indicators/volatility/__init__.py +0 -0
- openbacktesting/indicators/volatility/aberration.py +21 -0
- openbacktesting/indicators/volatility/accbands.py +20 -0
- openbacktesting/indicators/volatility/adr.py +7 -0
- openbacktesting/indicators/volatility/atr.py +12 -0
- openbacktesting/indicators/volatility/avolume.py +10 -0
- openbacktesting/indicators/volatility/bbands.py +20 -0
- openbacktesting/indicators/volatility/ce.py +25 -0
- openbacktesting/indicators/volatility/cvi.py +10 -0
- openbacktesting/indicators/volatility/donchian.py +20 -0
- openbacktesting/indicators/volatility/hvol.py +10 -0
- openbacktesting/indicators/volatility/hwc.py +27 -0
- openbacktesting/indicators/volatility/kc.py +27 -0
- openbacktesting/indicators/volatility/massi.py +10 -0
- openbacktesting/indicators/volatility/natr.py +19 -0
- openbacktesting/indicators/volatility/pdist.py +10 -0
- openbacktesting/indicators/volatility/rvi.py +21 -0
- openbacktesting/indicators/volatility/starc.py +11 -0
- openbacktesting/indicators/volatility/thermo.py +28 -0
- openbacktesting/indicators/volatility/true_range.py +31 -0
- openbacktesting/indicators/volatility/ui.py +10 -0
- openbacktesting/indicators/volume/__init__.py +0 -0
- openbacktesting/indicators/volume/ad.py +10 -0
- openbacktesting/indicators/volume/adosc.py +19 -0
- openbacktesting/indicators/volume/aobv.py +31 -0
- openbacktesting/indicators/volume/cmf.py +12 -0
- openbacktesting/indicators/volume/efi.py +12 -0
- openbacktesting/indicators/volume/emv.py +10 -0
- openbacktesting/indicators/volume/eom.py +19 -0
- openbacktesting/indicators/volume/iii.py +9 -0
- openbacktesting/indicators/volume/kvo.py +28 -0
- openbacktesting/indicators/volume/marketfi.py +10 -0
- openbacktesting/indicators/volume/mfi.py +12 -0
- openbacktesting/indicators/volume/nvi.py +26 -0
- openbacktesting/indicators/volume/obv.py +10 -0
- openbacktesting/indicators/volume/pvi.py +26 -0
- openbacktesting/indicators/volume/pvol.py +10 -0
- openbacktesting/indicators/volume/pvr.py +10 -0
- openbacktesting/indicators/volume/pvt.py +10 -0
- openbacktesting/indicators/volume/rvol.py +8 -0
- openbacktesting/indicators/volume/vfi.py +18 -0
- openbacktesting/indicators/volume/vosc.py +10 -0
- openbacktesting/indicators/volume/wad.py +10 -0
- openbacktesting/indicators/volume/wvad.py +9 -0
- openbacktesting/inputs.py +51 -0
- openbacktesting/lib.py +31 -0
- openbacktesting/logs.py +129 -0
- openbacktesting/optimization.py +8 -0
- openbacktesting/optimizer/__init__.py +25 -0
- openbacktesting/optimizer/_semantics.py +155 -0
- openbacktesting/optimizer/identity.py +45 -0
- openbacktesting/optimizer/models.py +92 -0
- openbacktesting/optimizer/plan.py +129 -0
- openbacktesting/optimizer/portfolio-result.schema.json +4984 -0
- openbacktesting/optimizer/query.py +257 -0
- openbacktesting/optimizer/runner.py +98 -0
- openbacktesting/optimizer/storage.py +261 -0
- openbacktesting/optimizer/validation.py +64 -0
- openbacktesting/parallel.py +9 -0
- openbacktesting/plotting/__init__.py +23 -0
- openbacktesting/plotting/collector.py +509 -0
- openbacktesting/plotting/encoding.py +102 -0
- openbacktesting/plotting/types.py +92 -0
- openbacktesting/portfolio/__init__.py +15 -0
- openbacktesting/portfolio/analysis.py +245 -0
- openbacktesting/portfolio/builder.py +381 -0
- openbacktesting/portfolio/catalog.json +1404 -0
- openbacktesting/portfolio/helpers.py +92 -0
- openbacktesting/portfolio/metrics.py +186 -0
- openbacktesting/portfolio/models.py +63 -0
- openbacktesting/portfolio/periods.py +164 -0
- openbacktesting/portfolio/rates.py +14 -0
- openbacktesting/portfolio/snapshot.py +111 -0
- openbacktesting/portfolio/stats.py +272 -0
- openbacktesting/portfolio/trades.py +136 -0
- openbacktesting/portfolio/trading.py +215 -0
- openbacktesting/py.typed +0 -0
- openbacktesting/runtime.py +330 -0
- openbacktesting/simulation/__init__.py +17 -0
- openbacktesting/simulation/collection.py +13 -0
- openbacktesting/simulation/config.py +241 -0
- openbacktesting/simulation/core.py +528 -0
- openbacktesting/simulation/optimization.py +326 -0
- openbacktesting/simulation/parallel.py +145 -0
- openbacktesting/simulation/variants.py +107 -0
- openbacktesting/strategy/__init__.py +19 -0
- openbacktesting/strategy/bar_state.py +14 -0
- openbacktesting/strategy/base.py +810 -0
- openbacktesting/strategy/declaration.py +90 -0
- openbacktesting/strategy/helpers.py +198 -0
- openbacktesting/strategy/inputs.py +460 -0
- openbacktesting/strategy/sizing.py +80 -0
- openbacktesting/strategy/templates.py +160 -0
- openbacktesting/strategy_data.py +10 -0
- openbacktesting/test/BTCUSD.csv +157 -0
- openbacktesting/test/EURUSD.csv +5001 -0
- openbacktesting/test/GOOG.csv +2149 -0
- openbacktesting/test/__init__.py +29 -0
- openbacktesting/test/__main__.py +11 -0
- openbacktesting/test/_test.py +1312 -0
- openbacktesting/util.py +31 -0
- openbacktesting-0.2.0.dist-info/METADATA +151 -0
- openbacktesting-0.2.0.dist-info/RECORD +350 -0
- openbacktesting-0.2.0.dist-info/WHEEL +4 -0
- openbacktesting-0.2.0.dist-info/licenses/LICENSE +202 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""OpenBacktesting native historical backtesting kernel."""
|
|
2
|
+
|
|
3
|
+
import sys as _sys
|
|
4
|
+
|
|
5
|
+
__version__ = "0.2.0"
|
|
6
|
+
|
|
7
|
+
from . import colors, indicators, inputs, lib, runtime # noqa: F401
|
|
8
|
+
from .colors import Color as Color
|
|
9
|
+
from .data.context import DataContext as DataContext
|
|
10
|
+
from .data.timeframe import Timeframe as Timeframe
|
|
11
|
+
from .data.timeframe import TimeframeUnit as TimeframeUnit
|
|
12
|
+
from .engine import Backtest as Backtest
|
|
13
|
+
from .engine import Strategy as Strategy
|
|
14
|
+
from .logs import RunLogs as RunLogs
|
|
15
|
+
from .simulation.config import CommissionType as CommissionType
|
|
16
|
+
from .simulation.config import DefaultOrderSize as DefaultOrderSize
|
|
17
|
+
from .simulation.config import EndPolicy as EndPolicy
|
|
18
|
+
from .simulation.config import ExecutionTiming as ExecutionTiming
|
|
19
|
+
from .simulation.config import QuantityType as QuantityType
|
|
20
|
+
from .simulation.config import SlippageType as SlippageType
|
|
21
|
+
from .strategy.bar_state import BarState as BarState
|
|
22
|
+
from .strategy.declaration import backtest as backtest
|
|
23
|
+
from .util import try_
|
|
24
|
+
|
|
25
|
+
# Skip Pool in pdoc3 API docs. Interested users get the warning.
|
|
26
|
+
__pdoc__ = {"openbacktesting.Pool": False}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# Add overridable openbacktesting.Pool used for parallel optimization
|
|
30
|
+
def Pool(processes=None, initializer=None, initargs=()):
|
|
31
|
+
"""Create an optimization execution pool; spawn uses a thread pool by default. Advanced callers may override this entry point; multiprocessing calls require a main guard."""
|
|
32
|
+
import multiprocessing as mp
|
|
33
|
+
import sys
|
|
34
|
+
|
|
35
|
+
# Revert performance related change in Python>=3.14
|
|
36
|
+
if sys.platform.startswith("linux") and mp.get_start_method(allow_none=True) != "fork":
|
|
37
|
+
try_(lambda: mp.set_start_method("fork"))
|
|
38
|
+
if mp.get_start_method() == "spawn":
|
|
39
|
+
import warnings
|
|
40
|
+
|
|
41
|
+
warnings.warn(
|
|
42
|
+
"If you want to use multi-process optimization with "
|
|
43
|
+
"`multiprocessing.get_start_method() == 'spawn'` (e.g. on Windows),"
|
|
44
|
+
"set `openbacktesting.Pool = multiprocessing.Pool` (or of the desired context) "
|
|
45
|
+
"and hide `bt.optimize()` call behind a `if __name__ == '__main__'` guard. "
|
|
46
|
+
"Currently using thread-based paralellism, "
|
|
47
|
+
"which might be slightly slower for non-numpy / non-GIL-releasing code. "
|
|
48
|
+
"See README.md",
|
|
49
|
+
category=RuntimeWarning,
|
|
50
|
+
stacklevel=3,
|
|
51
|
+
)
|
|
52
|
+
from multiprocessing.dummy import Pool
|
|
53
|
+
|
|
54
|
+
return Pool(processes, initializer, initargs)
|
|
55
|
+
else:
|
|
56
|
+
return mp.Pool(processes, initializer, initargs)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
from . import ( # noqa: F401
|
|
60
|
+
aggregation,
|
|
61
|
+
broker,
|
|
62
|
+
data,
|
|
63
|
+
helpers,
|
|
64
|
+
optimization,
|
|
65
|
+
parallel,
|
|
66
|
+
simulation,
|
|
67
|
+
strategy,
|
|
68
|
+
util,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# The old module path and new file share the same objects, preserving imports, patching, and pickle lookup.
|
|
72
|
+
for _module_name in (
|
|
73
|
+
"aggregation",
|
|
74
|
+
"broker",
|
|
75
|
+
"data",
|
|
76
|
+
"helpers",
|
|
77
|
+
"optimization",
|
|
78
|
+
"parallel",
|
|
79
|
+
"strategy",
|
|
80
|
+
"util",
|
|
81
|
+
):
|
|
82
|
+
_module = _sys.modules[f"{__name__}.{_module_name}"]
|
|
83
|
+
globals()[f"_{_module_name}"] = _module
|
|
84
|
+
_sys.modules[f"{__name__}._{_module_name}"] = _module
|
|
85
|
+
del _module_name, _module
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Compatibility exports for the old broker path; implemented in broker.core."""
|
|
2
|
+
|
|
3
|
+
from openbacktesting.broker.core import (
|
|
4
|
+
Order as Order,
|
|
5
|
+
)
|
|
6
|
+
from openbacktesting.broker.core import (
|
|
7
|
+
Position as Position,
|
|
8
|
+
)
|
|
9
|
+
from openbacktesting.broker.core import (
|
|
10
|
+
Trade as Trade,
|
|
11
|
+
)
|
|
12
|
+
from openbacktesting.broker.core import (
|
|
13
|
+
__pdoc__ as __pdoc__,
|
|
14
|
+
)
|
|
15
|
+
from openbacktesting.broker.core import (
|
|
16
|
+
_Broker as _Broker,
|
|
17
|
+
)
|
|
18
|
+
from openbacktesting.broker.core import (
|
|
19
|
+
_OutOfMoneyError as _OutOfMoneyError,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
from .commission import Commission as Commission
|
|
23
|
+
from .core import OrderGroup as OrderGroup
|
|
24
|
+
from .execution import Slippage as Slippage
|
|
25
|
+
from .instrument import InstrumentSpec as InstrumentSpec
|
|
26
|
+
from .models import (
|
|
27
|
+
AccountSnapshot as AccountSnapshot,
|
|
28
|
+
)
|
|
29
|
+
from .models import ClosedTradeStats as ClosedTradeStats
|
|
30
|
+
from .models import (
|
|
31
|
+
Fill as Fill,
|
|
32
|
+
)
|
|
33
|
+
from .models import (
|
|
34
|
+
OrderEvent as OrderEvent,
|
|
35
|
+
)
|
|
36
|
+
from .models import (
|
|
37
|
+
OrderSizingSnapshot as OrderSizingSnapshot,
|
|
38
|
+
)
|
|
39
|
+
from .models import (
|
|
40
|
+
OrderSnapshot as OrderSnapshot,
|
|
41
|
+
)
|
|
42
|
+
from .models import (
|
|
43
|
+
OrderStatus as OrderStatus,
|
|
44
|
+
)
|
|
45
|
+
from .models import (
|
|
46
|
+
PositionSnapshot as PositionSnapshot,
|
|
47
|
+
)
|
|
48
|
+
from .models import (
|
|
49
|
+
RunSummary as RunSummary,
|
|
50
|
+
)
|
|
51
|
+
from .models import (
|
|
52
|
+
TradeAllocation as TradeAllocation,
|
|
53
|
+
)
|
|
54
|
+
from .requests import OrderRequest as OrderRequest
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Reconstructible linear fee values without account or strategy state."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
|
|
6
|
+
from openbacktesting.broker.models import finite
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass(frozen=True)
|
|
10
|
+
class Commission:
|
|
11
|
+
"""Fixed fee per fill, notional rate, and fee per asset unit; a rate of 0.002 means 0.2%."""
|
|
12
|
+
|
|
13
|
+
fixed: float = 0.0
|
|
14
|
+
relative: float = 0.0
|
|
15
|
+
per_unit: float = 0.0
|
|
16
|
+
|
|
17
|
+
def __post_init__(self):
|
|
18
|
+
for name in ("fixed", "relative", "per_unit"):
|
|
19
|
+
object.__setattr__(self, name, finite(getattr(self, name), f"commission_{name}"))
|
|
20
|
+
if self.fixed < 0 or self.per_unit < 0 or not -0.1 <= self.relative < 0.1:
|
|
21
|
+
raise ValueError("Commission configuration is outside the allowed range")
|
|
22
|
+
|
|
23
|
+
def calculate(self, qty: float, price: float) -> float:
|
|
24
|
+
"""Calculate fees from actual fill quantity and price; the caller validates fill values."""
|
|
25
|
+
return self.fixed + abs(qty) * price * self.relative + abs(qty) * self.per_unit
|
|
26
|
+
|
|
27
|
+
def snapshot(self) -> dict:
|
|
28
|
+
"""Export independent plain values with a model version."""
|
|
29
|
+
return {
|
|
30
|
+
"kind": "linear",
|
|
31
|
+
"version": 1,
|
|
32
|
+
"fixed": self.fixed,
|
|
33
|
+
"relative": self.relative,
|
|
34
|
+
"per_unit": self.per_unit,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@classmethod
|
|
38
|
+
def from_snapshot(cls, value: Mapping) -> "Commission":
|
|
39
|
+
"""Restore a complete snapshot strictly; reject unknown versions, fields, and implicit defaults."""
|
|
40
|
+
if not isinstance(value, Mapping):
|
|
41
|
+
raise TypeError("Commission snapshot must be a mapping")
|
|
42
|
+
if set(value) != {"kind", "version", "fixed", "relative", "per_unit"}:
|
|
43
|
+
raise ValueError("Commission snapshot has missing or unknown fields")
|
|
44
|
+
if value["kind"] != "linear" or type(value["version"]) is not int or value["version"] != 1:
|
|
45
|
+
raise ValueError("Unsupported Commission snapshot model or version")
|
|
46
|
+
return cls(value["fixed"], value["relative"], value["per_unit"])
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def normalize_commission(value: float | tuple[float, float] | Commission) -> Commission:
|
|
50
|
+
"""Normalize legacy fee inputs to a plain-value model; callables are not accepted."""
|
|
51
|
+
if isinstance(value, Commission):
|
|
52
|
+
return value
|
|
53
|
+
if isinstance(value, tuple):
|
|
54
|
+
if len(value) != 2:
|
|
55
|
+
raise ValueError("commission tuple must contain a fixed fee and a rate")
|
|
56
|
+
return Commission(fixed=value[0], relative=value[1])
|
|
57
|
+
return Commission(relative=value)
|