XXSim 0.5.0__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.
xxsim-0.5.0/PKG-INFO ADDED
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.4
2
+ Name: XXSim
3
+ Version: 0.5.0
4
+ Summary: Exchange Execution Simulator - stock exchange single bar execution simulator
5
+ Author-email: Yanir Taflev <yanirta+xsim@gmail.com>
6
+ License: MIT
7
+ Keywords: trade,Algotrading,simulation,trading,exchange,stocks,backtesting,stock market,execution simulator,OHLCV,order simulation,finance,trading bot,quantitative,algorithmic trading,market data
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: numpy
15
+ Requires-Dist: pydantic
16
+ Provides-Extra: dev
17
+ Requires-Dist: plotly; extra == "dev"
18
+ Requires-Dist: pandas; extra == "dev"
19
+
20
+ # XSim
21
+ Stock Exchange Order Execution Simulator for developers
22
+ This package simulates order(s) execution based on provided market OHLCV data.
23
+ This is not an independent package, but its the core logic required to implement backtesting when it comes on running on candlebar data.
24
+
25
+ **This is the first drop and wasn't tested out in the wild yet, more functionality and capabilities to come**
26
+
27
+ ## disclaimer
28
+ **Own risk warning** - Execution prices are best estimations base on worst case scenarios and statistics, there will be price differences between simulations and real-world execution, using this package the user acknowledges his consent and takes full responsibility on the implications caused due to any error or misinterpetation of this package and it's results.
29
+
30
+ Trailing commands warning - Trailing commands are currently roughly estimated and carry high deviation from the real world
31
+
32
+ ## The challenge
33
+ Core Problem: Reconstructing intra-bar price movement to determine order execution.
34
+
35
+ The golden standard of market data comes in chunks of Candle-bars providing Open, High, Low, Close and Volume of predefined time range
36
+ ie. 1-minute, 5-minutes, an hour, a day, a week, a month, etc...
37
+ Within each such data-unit there is a gap of the inner price motions, unless you work with tick-by-tick data which is expensive, noisy and resource intense.
38
+ On top of that, fill prices are results of a consiquent rules and formations that are hard to simulate.
39
+
40
+ ## The solution
41
+ Output: Realistic execution fills within statistical uncertainty. or consiquent order either original or modified.
42
+
43
+ XSim relies on OHLC Data to simulate the inner motion of prices within single data-unit, and attempt to perform a set of decision to execute orders in the most authentic way.
44
+
45
+ ## Supported order types
46
+ - MarketOrder
47
+ - LimitOrder
48
+ - StopOrder
49
+ - StopLimitOrder
50
+ - TrailingStopMarket
51
+
52
+ ## Not supported order types (at the moment)
53
+ - Trailing Stop Limit Orders
54
+ - Market-on-Close (MOC) / Limit-on-Close (LOC)
55
+ - Bracket Orders (OCO - One-Cancels-Other)
56
+ - Market-if-Touched (MIT)
57
+ - Others...
58
+
59
+ ## Current Execution algorithm assumptions
60
+ - No slippage
61
+ - No partial fills
62
+ - Aggressive approach - Order will be filled if there's a possible path between order's formation and the candlebar.
63
+ - Trail orders assume the following order of the candles:
64
+ On Bullish bar: prev_extremePrice [optional] -> open -> low -> high -> close
65
+ On Bearish bar: prev_extremePrice [optional] -> open -> high -> low -> close
66
+
67
+ ## Use cases
68
+ 1. Market order - Market order executes immediately on submission time (close to open)
69
+ 1. Limit order - The algorithm will determine whether the price motion goes through the limit defined in the order, if so it will execute the order with some statistical error depends on the volatility of the candle-bar.
70
+ 1. Additional types of orders: Trailing stop, StopLimitOrder, StopOrder,
71
+ 1. Supporting buy/sell(long/short) directions
72
+ 1. Supporting Time In Force (Tif), goodAfterTime, goodTillDate
73
+ 1. Supporting ocaGroup
74
+ 1. Supporting parent/child relationships
75
+ 1. Multiple orders
76
+
77
+ * Working with fractional time of submission is Unsupported yet
78
+
79
+ ## Installation
80
+
81
+ ```bash
82
+ pip install -e .
83
+ ```
84
+
85
+ ## Running Tests
86
+
87
+ ```bash
88
+ pytest tests/ -v
89
+ ```
90
+
91
+ ## Usage
92
+ Here is a minimal example of simulating a market order execution:
93
+ ```python
94
+ from models import MarketOrder, BarData
95
+ from execution import ExecutionEngine
96
+ from decimal import Decimal
97
+ from datetime import datetime
98
+
99
+ engine = ExecutionEngine()
100
+ bar = BarData(
101
+ date=datetime(2025, 1, 1, 9, 30),
102
+ open=Decimal('100.00'),
103
+ high=Decimal('105.00'),
104
+ low=Decimal('95.00'),
105
+ close=Decimal('102.00'),
106
+ volume=1000000,
107
+ )
108
+ order = MarketOrder(action='BUY', totalQuantity=100)
109
+ result = engine.execute(order, bar)
110
+ print(result.fills)
111
+ ```
112
+
113
+ ## Visualizations
114
+ Stop-limit and Trailing test cases can be visualized
115
+ For stop-limit visualization run:
116
+
117
+ ```bash
118
+ docs/stop-limit-chart-generator.py test-data/stop-limit/<filename.csv>
119
+ ```
120
+
121
+ For trailing visualization run:
122
+
123
+ ```bash
124
+ docs/trailing-stop-chart-generator.py test-data/trailing-stop/<filename.csv>
125
+ ```
126
+
127
+ TODO: Trailing cases are not organized systemactically enough
128
+
129
+ ### Contributing
130
+ Contributions are welcome! Please see the documentation in the `docs` folder for more details and test specifications.
xxsim-0.5.0/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # XSim
2
+ Stock Exchange Order Execution Simulator for developers
3
+ This package simulates order(s) execution based on provided market OHLCV data.
4
+ This is not an independent package, but its the core logic required to implement backtesting when it comes on running on candlebar data.
5
+
6
+ **This is the first drop and wasn't tested out in the wild yet, more functionality and capabilities to come**
7
+
8
+ ## disclaimer
9
+ **Own risk warning** - Execution prices are best estimations base on worst case scenarios and statistics, there will be price differences between simulations and real-world execution, using this package the user acknowledges his consent and takes full responsibility on the implications caused due to any error or misinterpetation of this package and it's results.
10
+
11
+ Trailing commands warning - Trailing commands are currently roughly estimated and carry high deviation from the real world
12
+
13
+ ## The challenge
14
+ Core Problem: Reconstructing intra-bar price movement to determine order execution.
15
+
16
+ The golden standard of market data comes in chunks of Candle-bars providing Open, High, Low, Close and Volume of predefined time range
17
+ ie. 1-minute, 5-minutes, an hour, a day, a week, a month, etc...
18
+ Within each such data-unit there is a gap of the inner price motions, unless you work with tick-by-tick data which is expensive, noisy and resource intense.
19
+ On top of that, fill prices are results of a consiquent rules and formations that are hard to simulate.
20
+
21
+ ## The solution
22
+ Output: Realistic execution fills within statistical uncertainty. or consiquent order either original or modified.
23
+
24
+ XSim relies on OHLC Data to simulate the inner motion of prices within single data-unit, and attempt to perform a set of decision to execute orders in the most authentic way.
25
+
26
+ ## Supported order types
27
+ - MarketOrder
28
+ - LimitOrder
29
+ - StopOrder
30
+ - StopLimitOrder
31
+ - TrailingStopMarket
32
+
33
+ ## Not supported order types (at the moment)
34
+ - Trailing Stop Limit Orders
35
+ - Market-on-Close (MOC) / Limit-on-Close (LOC)
36
+ - Bracket Orders (OCO - One-Cancels-Other)
37
+ - Market-if-Touched (MIT)
38
+ - Others...
39
+
40
+ ## Current Execution algorithm assumptions
41
+ - No slippage
42
+ - No partial fills
43
+ - Aggressive approach - Order will be filled if there's a possible path between order's formation and the candlebar.
44
+ - Trail orders assume the following order of the candles:
45
+ On Bullish bar: prev_extremePrice [optional] -> open -> low -> high -> close
46
+ On Bearish bar: prev_extremePrice [optional] -> open -> high -> low -> close
47
+
48
+ ## Use cases
49
+ 1. Market order - Market order executes immediately on submission time (close to open)
50
+ 1. Limit order - The algorithm will determine whether the price motion goes through the limit defined in the order, if so it will execute the order with some statistical error depends on the volatility of the candle-bar.
51
+ 1. Additional types of orders: Trailing stop, StopLimitOrder, StopOrder,
52
+ 1. Supporting buy/sell(long/short) directions
53
+ 1. Supporting Time In Force (Tif), goodAfterTime, goodTillDate
54
+ 1. Supporting ocaGroup
55
+ 1. Supporting parent/child relationships
56
+ 1. Multiple orders
57
+
58
+ * Working with fractional time of submission is Unsupported yet
59
+
60
+ ## Installation
61
+
62
+ ```bash
63
+ pip install -e .
64
+ ```
65
+
66
+ ## Running Tests
67
+
68
+ ```bash
69
+ pytest tests/ -v
70
+ ```
71
+
72
+ ## Usage
73
+ Here is a minimal example of simulating a market order execution:
74
+ ```python
75
+ from models import MarketOrder, BarData
76
+ from execution import ExecutionEngine
77
+ from decimal import Decimal
78
+ from datetime import datetime
79
+
80
+ engine = ExecutionEngine()
81
+ bar = BarData(
82
+ date=datetime(2025, 1, 1, 9, 30),
83
+ open=Decimal('100.00'),
84
+ high=Decimal('105.00'),
85
+ low=Decimal('95.00'),
86
+ close=Decimal('102.00'),
87
+ volume=1000000,
88
+ )
89
+ order = MarketOrder(action='BUY', totalQuantity=100)
90
+ result = engine.execute(order, bar)
91
+ print(result.fills)
92
+ ```
93
+
94
+ ## Visualizations
95
+ Stop-limit and Trailing test cases can be visualized
96
+ For stop-limit visualization run:
97
+
98
+ ```bash
99
+ docs/stop-limit-chart-generator.py test-data/stop-limit/<filename.csv>
100
+ ```
101
+
102
+ For trailing visualization run:
103
+
104
+ ```bash
105
+ docs/trailing-stop-chart-generator.py test-data/trailing-stop/<filename.csv>
106
+ ```
107
+
108
+ TODO: Trailing cases are not organized systemactically enough
109
+
110
+ ### Contributing
111
+ Contributions are welcome! Please see the documentation in the `docs` folder for more details and test specifications.
@@ -0,0 +1,35 @@
1
+ [project]
2
+ name = "XXSim"
3
+ version = "0.5.0"
4
+ description = "Exchange Execution Simulator - stock exchange single bar execution simulator"
5
+ authors = [{name = "Yanir Taflev", email = "yanirta+xsim@gmail.com"}]
6
+ license = {text = "MIT"}
7
+ readme = "README.md"
8
+ classifiers = [
9
+ "Programming Language :: Python :: 3.10",
10
+ "Programming Language :: Python :: 3.11",
11
+ "License :: OSI Approved :: MIT License",
12
+ "Operating System :: OS Independent"
13
+ ]
14
+ keywords = ["trade", "Algotrading", "simulation", "trading", "exchange", "stocks", "backtesting", "stock market", "execution simulator", "OHLCV", "order simulation", "finance", "trading bot", "quantitative", "algorithmic trading", "market data"]
15
+ requires-python = ">=3.10"
16
+ dependencies = [
17
+ "numpy",
18
+ "pydantic"
19
+ ]
20
+
21
+ [project.optional-dependencies]
22
+ dev = [
23
+ "plotly",
24
+ "pandas"
25
+ ]
26
+
27
+ [build-system]
28
+ requires = ["setuptools", "wheel"]
29
+ build-backend = "setuptools.build_meta"
30
+
31
+ [tool.setuptools]
32
+ package-dir = {"" = "src"}
33
+
34
+ [tool.pytest.ini_options]
35
+ testpaths = ["tests"]
xxsim-0.5.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.4
2
+ Name: XXSim
3
+ Version: 0.5.0
4
+ Summary: Exchange Execution Simulator - stock exchange single bar execution simulator
5
+ Author-email: Yanir Taflev <yanirta+xsim@gmail.com>
6
+ License: MIT
7
+ Keywords: trade,Algotrading,simulation,trading,exchange,stocks,backtesting,stock market,execution simulator,OHLCV,order simulation,finance,trading bot,quantitative,algorithmic trading,market data
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: numpy
15
+ Requires-Dist: pydantic
16
+ Provides-Extra: dev
17
+ Requires-Dist: plotly; extra == "dev"
18
+ Requires-Dist: pandas; extra == "dev"
19
+
20
+ # XSim
21
+ Stock Exchange Order Execution Simulator for developers
22
+ This package simulates order(s) execution based on provided market OHLCV data.
23
+ This is not an independent package, but its the core logic required to implement backtesting when it comes on running on candlebar data.
24
+
25
+ **This is the first drop and wasn't tested out in the wild yet, more functionality and capabilities to come**
26
+
27
+ ## disclaimer
28
+ **Own risk warning** - Execution prices are best estimations base on worst case scenarios and statistics, there will be price differences between simulations and real-world execution, using this package the user acknowledges his consent and takes full responsibility on the implications caused due to any error or misinterpetation of this package and it's results.
29
+
30
+ Trailing commands warning - Trailing commands are currently roughly estimated and carry high deviation from the real world
31
+
32
+ ## The challenge
33
+ Core Problem: Reconstructing intra-bar price movement to determine order execution.
34
+
35
+ The golden standard of market data comes in chunks of Candle-bars providing Open, High, Low, Close and Volume of predefined time range
36
+ ie. 1-minute, 5-minutes, an hour, a day, a week, a month, etc...
37
+ Within each such data-unit there is a gap of the inner price motions, unless you work with tick-by-tick data which is expensive, noisy and resource intense.
38
+ On top of that, fill prices are results of a consiquent rules and formations that are hard to simulate.
39
+
40
+ ## The solution
41
+ Output: Realistic execution fills within statistical uncertainty. or consiquent order either original or modified.
42
+
43
+ XSim relies on OHLC Data to simulate the inner motion of prices within single data-unit, and attempt to perform a set of decision to execute orders in the most authentic way.
44
+
45
+ ## Supported order types
46
+ - MarketOrder
47
+ - LimitOrder
48
+ - StopOrder
49
+ - StopLimitOrder
50
+ - TrailingStopMarket
51
+
52
+ ## Not supported order types (at the moment)
53
+ - Trailing Stop Limit Orders
54
+ - Market-on-Close (MOC) / Limit-on-Close (LOC)
55
+ - Bracket Orders (OCO - One-Cancels-Other)
56
+ - Market-if-Touched (MIT)
57
+ - Others...
58
+
59
+ ## Current Execution algorithm assumptions
60
+ - No slippage
61
+ - No partial fills
62
+ - Aggressive approach - Order will be filled if there's a possible path between order's formation and the candlebar.
63
+ - Trail orders assume the following order of the candles:
64
+ On Bullish bar: prev_extremePrice [optional] -> open -> low -> high -> close
65
+ On Bearish bar: prev_extremePrice [optional] -> open -> high -> low -> close
66
+
67
+ ## Use cases
68
+ 1. Market order - Market order executes immediately on submission time (close to open)
69
+ 1. Limit order - The algorithm will determine whether the price motion goes through the limit defined in the order, if so it will execute the order with some statistical error depends on the volatility of the candle-bar.
70
+ 1. Additional types of orders: Trailing stop, StopLimitOrder, StopOrder,
71
+ 1. Supporting buy/sell(long/short) directions
72
+ 1. Supporting Time In Force (Tif), goodAfterTime, goodTillDate
73
+ 1. Supporting ocaGroup
74
+ 1. Supporting parent/child relationships
75
+ 1. Multiple orders
76
+
77
+ * Working with fractional time of submission is Unsupported yet
78
+
79
+ ## Installation
80
+
81
+ ```bash
82
+ pip install -e .
83
+ ```
84
+
85
+ ## Running Tests
86
+
87
+ ```bash
88
+ pytest tests/ -v
89
+ ```
90
+
91
+ ## Usage
92
+ Here is a minimal example of simulating a market order execution:
93
+ ```python
94
+ from models import MarketOrder, BarData
95
+ from execution import ExecutionEngine
96
+ from decimal import Decimal
97
+ from datetime import datetime
98
+
99
+ engine = ExecutionEngine()
100
+ bar = BarData(
101
+ date=datetime(2025, 1, 1, 9, 30),
102
+ open=Decimal('100.00'),
103
+ high=Decimal('105.00'),
104
+ low=Decimal('95.00'),
105
+ close=Decimal('102.00'),
106
+ volume=1000000,
107
+ )
108
+ order = MarketOrder(action='BUY', totalQuantity=100)
109
+ result = engine.execute(order, bar)
110
+ print(result.fills)
111
+ ```
112
+
113
+ ## Visualizations
114
+ Stop-limit and Trailing test cases can be visualized
115
+ For stop-limit visualization run:
116
+
117
+ ```bash
118
+ docs/stop-limit-chart-generator.py test-data/stop-limit/<filename.csv>
119
+ ```
120
+
121
+ For trailing visualization run:
122
+
123
+ ```bash
124
+ docs/trailing-stop-chart-generator.py test-data/trailing-stop/<filename.csv>
125
+ ```
126
+
127
+ TODO: Trailing cases are not organized systemactically enough
128
+
129
+ ### Contributing
130
+ Contributions are welcome! Please see the documentation in the `docs` folder for more details and test specifications.
@@ -0,0 +1,21 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/__init__.py
4
+ src/execution.py
5
+ src/XXSim.egg-info/PKG-INFO
6
+ src/XXSim.egg-info/SOURCES.txt
7
+ src/XXSim.egg-info/dependency_links.txt
8
+ src/XXSim.egg-info/requires.txt
9
+ src/XXSim.egg-info/top_level.txt
10
+ src/models/__init__.py
11
+ src/models/bar.py
12
+ src/models/execution_result.py
13
+ src/models/fill.py
14
+ src/models/order.py
15
+ tests/test_bar.py
16
+ tests/test_execution_result.py
17
+ tests/test_fill.py
18
+ tests/test_models.py
19
+ tests/test_simple_orders_execution.py
20
+ tests/test_stop_limit_orders_execution.py
21
+ tests/test_trailing_stop_market.py
@@ -0,0 +1,6 @@
1
+ numpy
2
+ pydantic
3
+
4
+ [dev]
5
+ plotly
6
+ pandas
@@ -0,0 +1,3 @@
1
+ __init__
2
+ execution
3
+ models
@@ -0,0 +1,29 @@
1
+ """XSim - Stock Exchange Execution Simulator."""
2
+ from .models import (
3
+ Order,
4
+ LimitOrder,
5
+ MarketOrder,
6
+ StopOrder,
7
+ StopLimitOrder,
8
+ BarData,
9
+ Execution,
10
+ CommissionReport,
11
+ Fill,
12
+ )
13
+ from .execution import ExecutionEngine, ExecutionConfig
14
+
15
+ __version__ = "0.1.0"
16
+
17
+ __all__ = [
18
+ "Order",
19
+ "LimitOrder",
20
+ "MarketOrder",
21
+ "StopOrder",
22
+ "StopLimitOrder",
23
+ "BarData",
24
+ "Execution",
25
+ "CommissionReport",
26
+ "Fill",
27
+ "ExecutionEngine",
28
+ "ExecutionConfig",
29
+ ]