upticks 0.1.5__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.
- upticks-0.1.5/LICENSE +202 -0
- upticks-0.1.5/PKG-INFO +230 -0
- upticks-0.1.5/README.md +196 -0
- upticks-0.1.5/pyproject.toml +72 -0
- upticks-0.1.5/setup.cfg +4 -0
- upticks-0.1.5/tests/test_adjust.py +1215 -0
- upticks-0.1.5/tests/test_api_surface.py +409 -0
- upticks-0.1.5/tests/test_banner.py +412 -0
- upticks-0.1.5/tests/test_bars.py +843 -0
- upticks-0.1.5/tests/test_config.py +808 -0
- upticks-0.1.5/tests/test_contract.py +2411 -0
- upticks-0.1.5/tests/test_errors.py +405 -0
- upticks-0.1.5/tests/test_fingerprint.py +357 -0
- upticks-0.1.5/tests/test_freq.py +873 -0
- upticks-0.1.5/tests/test_golden.py +487 -0
- upticks-0.1.5/tests/test_golden_a2.py +1132 -0
- upticks-0.1.5/tests/test_holidays.py +822 -0
- upticks-0.1.5/tests/test_hygiene_checks.py +770 -0
- upticks-0.1.5/tests/test_hygiene_report.py +946 -0
- upticks-0.1.5/tests/test_ingest_columns.py +559 -0
- upticks-0.1.5/tests/test_ingest_sources.py +882 -0
- upticks-0.1.5/tests/test_ingest_time.py +969 -0
- upticks-0.1.5/tests/test_io_parquet.py +1023 -0
- upticks-0.1.5/tests/test_meta.py +684 -0
- upticks-0.1.5/tests/test_no_mutation.py +411 -0
- upticks-0.1.5/tests/test_packaging.py +923 -0
- upticks-0.1.5/tests/test_parts.py +936 -0
- upticks-0.1.5/tests/test_perf.py +109 -0
- upticks-0.1.5/tests/test_perf_a2.py +155 -0
- upticks-0.1.5/tests/test_resample.py +1921 -0
- upticks-0.1.5/tests/test_resample_anchors.py +724 -0
- upticks-0.1.5/tests/test_resample_calendar.py +469 -0
- upticks-0.1.5/tests/test_result.py +381 -0
- upticks-0.1.5/tests/test_sessions.py +744 -0
- upticks-0.1.5/tests/test_sessions_shape.py +657 -0
- upticks-0.1.5/tests/test_tickgrid.py +468 -0
- upticks-0.1.5/tests/test_warnings.py +386 -0
- upticks-0.1.5/upticks/__init__.py +213 -0
- upticks-0.1.5/upticks/_banner.py +110 -0
- upticks-0.1.5/upticks/_logging.py +40 -0
- upticks-0.1.5/upticks/_result.py +343 -0
- upticks-0.1.5/upticks/config.py +1063 -0
- upticks-0.1.5/upticks/core/__init__.py +2 -0
- upticks-0.1.5/upticks/core/_time.py +329 -0
- upticks-0.1.5/upticks/core/adjust.py +998 -0
- upticks-0.1.5/upticks/core/bars.py +1100 -0
- upticks-0.1.5/upticks/core/fingerprint.py +119 -0
- upticks-0.1.5/upticks/core/freq.py +457 -0
- upticks-0.1.5/upticks/core/holidays.py +645 -0
- upticks-0.1.5/upticks/core/hygiene.py +1280 -0
- upticks-0.1.5/upticks/core/ingest.py +1916 -0
- upticks-0.1.5/upticks/core/meta.py +380 -0
- upticks-0.1.5/upticks/core/parts.py +477 -0
- upticks-0.1.5/upticks/core/resample.py +1945 -0
- upticks-0.1.5/upticks/core/sessions.py +1131 -0
- upticks-0.1.5/upticks/core/tickgrid.py +392 -0
- upticks-0.1.5/upticks/errors.py +604 -0
- upticks-0.1.5/upticks/io/__init__.py +2 -0
- upticks-0.1.5/upticks/io/parquet.py +661 -0
- upticks-0.1.5/upticks.egg-info/PKG-INFO +230 -0
- upticks-0.1.5/upticks.egg-info/SOURCES.txt +62 -0
- upticks-0.1.5/upticks.egg-info/dependency_links.txt +1 -0
- upticks-0.1.5/upticks.egg-info/requires.txt +16 -0
- upticks-0.1.5/upticks.egg-info/top_level.txt +1 -0
upticks-0.1.5/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Nashit Babber
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
upticks-0.1.5/PKG-INFO
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: upticks
|
|
3
|
+
Version: 0.1.5
|
|
4
|
+
Summary: Price action, honestly — a causality-first price-action research library.
|
|
5
|
+
Author-email: Nashit Babber <nashit.babber@gmail.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Keywords: price action,ohlcv,market structure,pandas,backtesting
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: <3.14,>=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: pandas<4,>=2.2
|
|
22
|
+
Requires-Dist: numpy<3,>=1.24
|
|
23
|
+
Requires-Dist: scipy>=1.10
|
|
24
|
+
Provides-Extra: fast
|
|
25
|
+
Requires-Dist: numba; extra == "fast"
|
|
26
|
+
Provides-Extra: plot
|
|
27
|
+
Requires-Dist: matplotlib; extra == "plot"
|
|
28
|
+
Provides-Extra: cache
|
|
29
|
+
Requires-Dist: pyarrow; extra == "cache"
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest; extra == "dev"
|
|
32
|
+
Requires-Dist: hypothesis; extra == "dev"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# upticks
|
|
36
|
+
|
|
37
|
+
**Price action, honestly.** A causality-first price-action research library for Python.
|
|
38
|
+
Plain pandas in, plain pandas out.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install upticks
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Most technical-analysis libraries will happily hand you a number that could not have been
|
|
45
|
+
known at the time it is stamped. `upticks` is built so that the leak is structurally
|
|
46
|
+
unavailable: every bar carries the instant it became knowable, and that is the only key a
|
|
47
|
+
join is allowed to use.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Status: alpha — the foundation, not the whole library
|
|
52
|
+
|
|
53
|
+
**v0.1.5 is the bar engine.** It loads and validates data, infers sessions, and resamples
|
|
54
|
+
them correctly. That is genuinely useful on its own, and it is deliberately all that is
|
|
55
|
+
here.
|
|
56
|
+
|
|
57
|
+
| shipping now | not here yet |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `load` / `scan` — ingest, aliasing, dtype coercion, timezone discipline | indicators (moving averages, momentum, volatility, …) |
|
|
60
|
+
| 16 hygiene checks as a tidy report; `repair()` as a separate explicit call | candlestick and chart patterns |
|
|
61
|
+
| gap-based session inference — no exchange calendar, anywhere | pivots and market structure |
|
|
62
|
+
| the session-anchored resampler, `1min` → `YE` | the event-study and backtest engines |
|
|
63
|
+
| session parts: opening range, initial balance, closing range | plotting |
|
|
64
|
+
| corporate actions and the three adjustment modes | |
|
|
65
|
+
|
|
66
|
+
If you install this expecting RSI, you will be disappointed. Indicators arrive in the next
|
|
67
|
+
stage. What is here is the layer all of that has to be a pure function of, and it is the
|
|
68
|
+
part that is usually wrong.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Why session anchoring
|
|
73
|
+
|
|
74
|
+
Resample a 09:15-opening equity session to hourly bars with pandas and you get this:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
df.resample("1h").agg(AGG) # [45, 60, 60, 60, 60, 60, 30] ← a 45-minute first bar
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The grid is anchored to midnight, so the session's first bucket is a stub and every
|
|
81
|
+
subsequent boundary is offset from the open. `upticks` anchors each bucket to the session's
|
|
82
|
+
own first bar:
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
up.resample(bars, "1h") # [60, 60, 60, 60, 60, 60, 15] ← anchored to 09:15
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The difference compounds. A `75min` or `125min` frame under a global origin drifts to a
|
|
89
|
+
different time of day on every subsequent session; anchored per session it lands on the same
|
|
90
|
+
five (or three) boundaries every trading day. A special evening session — NSE's Muhurat
|
|
91
|
+
trading, 18:00–18:59 — becomes exactly one hourly bar instead of being shredded or dropped.
|
|
92
|
+
|
|
93
|
+
Both behaviours remain reachable: `anchor="midnight"` is the correct choice for a 24-hour
|
|
94
|
+
instrument, and it is the only way to obtain the naive grid. You cannot get it by accident.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Causality, concretely
|
|
99
|
+
|
|
100
|
+
Every resampled bar carries an **18-column bar contract** beside the frame, and the column
|
|
101
|
+
that matters is `avail_ts` — the instant the bar became knowable:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
bars.contract[["bar_open_ts", "bar_close_ts", "avail_ts", "is_complete", "is_forming"]]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
- **`bar_close_ts` is the actual last constituent plus one interval**, never the nominal
|
|
108
|
+
period end. On a truncated or special session those differ, and the nominal answer is
|
|
109
|
+
wrong.
|
|
110
|
+
- **`avail_ts` is the only legal join key.** Joining on a bar's label is what leaks, so
|
|
111
|
+
labels are not offered as join keys anywhere.
|
|
112
|
+
- **`is_forming` marks a bar that can still change.** By default the still-open final bucket
|
|
113
|
+
is withheld entirely (`forming="drop"`), so nothing knowable-early reaches a backtest. A
|
|
114
|
+
daily bar for a session the feed has not finished publishing is not handed to you as
|
|
115
|
+
settled.
|
|
116
|
+
- **Resampling to a finer frequency is refused** with a typed error. There is no public
|
|
117
|
+
forward-fill-to-finer verb, because that is the leak.
|
|
118
|
+
- **Resample first, compute second.** `RSI(14)` on hourly bars is a different quantity from
|
|
119
|
+
`RSI(14)` computed on minutes and aggregated; no public path produces the latter.
|
|
120
|
+
|
|
121
|
+
Tested as named properties, not asserted as design intent: volume conservation, extreme
|
|
122
|
+
preservation, `1min→1h→1D` bitwise identical to `1min→1D`, idempotence, no bucket spanning
|
|
123
|
+
two sessions, and `avail_ts > bar_open_ts` on every emitted bar.
|
|
124
|
+
|
|
125
|
+
**On look-ahead itself the claim is bounded, deliberately: _no detectable look-ahead under
|
|
126
|
+
these tests_ — never _provably none_.** This release ships the structural layers — schema
|
|
127
|
+
assertions at construction, the availability contract, and the refusals above — and the
|
|
128
|
+
causality harness that makes "these tests" an enumerable, named list arrives in the next
|
|
129
|
+
stage. Until it does, read the claim as exactly what it says: these tests did not detect a
|
|
130
|
+
leak, which is not the same as there being none.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Sessions without a calendar
|
|
135
|
+
|
|
136
|
+
There is no exchange-calendar dependency anywhere in this library, and there never will be.
|
|
137
|
+
Sessions are inferred from the multiplicative structure of the data's own gaps; the holiday
|
|
138
|
+
table is the complement of the observed trading days.
|
|
139
|
+
|
|
140
|
+
This handles, on real data:
|
|
141
|
+
|
|
142
|
+
- **special sessions** — an evening or afternoon session that matches no modal shape is kept
|
|
143
|
+
as a first-class session, never merged into a neighbour
|
|
144
|
+
- **half-days and truncated feeds** — flagged `is_short`, and `is_provisional` when they sit
|
|
145
|
+
at the data tail and the vendor may still revise them
|
|
146
|
+
- **lunch-break markets** — a mid-session gap is absorbed as a *break*, not a boundary, so
|
|
147
|
+
Tokyo's 11:30–12:30 does not split the day in two
|
|
148
|
+
- **midnight-crossing sessions** — a CME Globex 23:30 bar belongs to the next calendar day's
|
|
149
|
+
trade date, and the session is one session
|
|
150
|
+
- **trading halts** — a 90-minute hole is a shape deviation, not a session split
|
|
151
|
+
- **DST transitions** — boundaries are computed in integer nanoseconds from the session open,
|
|
152
|
+
so a spring-forward week does not shift them
|
|
153
|
+
|
|
154
|
+
A declared `SessionShape` bypasses inference entirely where the heuristic is unsafe.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Quick start
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
import upticks as up
|
|
162
|
+
|
|
163
|
+
bars = up.load("NIFTY_1min.csv", tz="Asia/Kolkata", exchange="NSE", preset="nse_intraday")
|
|
164
|
+
|
|
165
|
+
print(bars.report())
|
|
166
|
+
# 500 sessions | 8 short | 2 off-hours (Muhurat) | tick 0.05 | 186747 bars | 2024-08-07 → 2026-08-12
|
|
167
|
+
|
|
168
|
+
bars.quality # the 16 hygiene checks, one row each
|
|
169
|
+
bars.sessions.table # one row per session, with its flags
|
|
170
|
+
|
|
171
|
+
hourly = up.resample(bars, "1h")
|
|
172
|
+
daily = up.resample(bars, "1D") # one bar per SESSION, never a midnight resample
|
|
173
|
+
weekly = up.resample(bars, "W-FRI") # restamped to the last actual session of the week
|
|
174
|
+
|
|
175
|
+
orb = up.opening_range(bars, 15) # one bar per session, first 15 minutes
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Nothing is repaired behind your back. `load()` reports; `repair()` is a separate call that
|
|
179
|
+
takes an explicit policy and records it in `Meta`.
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Design commitments
|
|
184
|
+
|
|
185
|
+
**Three runtime dependencies: pandas, numpy, scipy.** Nothing else, ever. `pyarrow`,
|
|
186
|
+
`matplotlib` and `numba` are optional extras, imported lazily inside the one function that
|
|
187
|
+
needs them, and their absence raises an error naming the extra.
|
|
188
|
+
|
|
189
|
+
**`bars.df` is a plain DataFrame** and never a subclass, so anything that consumes pandas can
|
|
190
|
+
consume it. Metadata that pandas drops — timezone, tick grid, session table, fingerprint,
|
|
191
|
+
adjustment lineage — lives on the handle instead.
|
|
192
|
+
|
|
193
|
+
**Refusals name the missing data.** Every error carries a remedy that says what to pass.
|
|
194
|
+
An ambiguous frequency alias is refused rather than guessed: `60m` means sixty minutes in
|
|
195
|
+
MetaTrader and sixty month-ends in pandas, so `upticks` refuses it and names both.
|
|
196
|
+
|
|
197
|
+
**Defaults are documented, not folklore.** `up.defaults_provenance()` returns every numeric
|
|
198
|
+
default with its origin and citation.
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Supported versions
|
|
203
|
+
|
|
204
|
+
Python 3.11–3.13. pandas 2.2 through 3.x, and the test suite is run under **both** majors —
|
|
205
|
+
pandas 3 changed the default datetime resolution from nanoseconds to microseconds, which
|
|
206
|
+
silently breaks naive integer-time arithmetic, so this is verified rather than assumed.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Honest limitations
|
|
211
|
+
|
|
212
|
+
- **Alpha.** The public surface of this stage is stable and tested, but later stages will add
|
|
213
|
+
to it. Pin the version.
|
|
214
|
+
- **Session inference is a heuristic.** It is validated against every session of a
|
|
215
|
+
two-year 1-minute reference file and against synthetic fixtures for four other market
|
|
216
|
+
shapes, but a genuinely novel session structure may need a declared `SessionShape`.
|
|
217
|
+
- **Corporate-action detection is candidate-only.** Splits and bonuses are matched against a
|
|
218
|
+
small set of rational overnight ratios. An ex-dividend drop is observationally identical to
|
|
219
|
+
an ordinary news gap without a dividend feed, and is reported as a candidate, never a fact.
|
|
220
|
+
- **Back-adjustment is non-causal by construction** and says so: rescaling pre-ex-date bars
|
|
221
|
+
uses information from the ex-date. It is available, registered as non-causal, and refused
|
|
222
|
+
by default where causality matters.
|
|
223
|
+
- **No exchange calendar means no forward-looking holidays.** The data is the calendar, so a
|
|
224
|
+
holiday after the last bar is unknowable; supply one explicitly if you need it.
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## License
|
|
229
|
+
|
|
230
|
+
Apache-2.0. Copyright (c) Nashit Babber.
|
upticks-0.1.5/README.md
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# upticks
|
|
2
|
+
|
|
3
|
+
**Price action, honestly.** A causality-first price-action research library for Python.
|
|
4
|
+
Plain pandas in, plain pandas out.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pip install upticks
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Most technical-analysis libraries will happily hand you a number that could not have been
|
|
11
|
+
known at the time it is stamped. `upticks` is built so that the leak is structurally
|
|
12
|
+
unavailable: every bar carries the instant it became knowable, and that is the only key a
|
|
13
|
+
join is allowed to use.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Status: alpha — the foundation, not the whole library
|
|
18
|
+
|
|
19
|
+
**v0.1.5 is the bar engine.** It loads and validates data, infers sessions, and resamples
|
|
20
|
+
them correctly. That is genuinely useful on its own, and it is deliberately all that is
|
|
21
|
+
here.
|
|
22
|
+
|
|
23
|
+
| shipping now | not here yet |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `load` / `scan` — ingest, aliasing, dtype coercion, timezone discipline | indicators (moving averages, momentum, volatility, …) |
|
|
26
|
+
| 16 hygiene checks as a tidy report; `repair()` as a separate explicit call | candlestick and chart patterns |
|
|
27
|
+
| gap-based session inference — no exchange calendar, anywhere | pivots and market structure |
|
|
28
|
+
| the session-anchored resampler, `1min` → `YE` | the event-study and backtest engines |
|
|
29
|
+
| session parts: opening range, initial balance, closing range | plotting |
|
|
30
|
+
| corporate actions and the three adjustment modes | |
|
|
31
|
+
|
|
32
|
+
If you install this expecting RSI, you will be disappointed. Indicators arrive in the next
|
|
33
|
+
stage. What is here is the layer all of that has to be a pure function of, and it is the
|
|
34
|
+
part that is usually wrong.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Why session anchoring
|
|
39
|
+
|
|
40
|
+
Resample a 09:15-opening equity session to hourly bars with pandas and you get this:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
df.resample("1h").agg(AGG) # [45, 60, 60, 60, 60, 60, 30] ← a 45-minute first bar
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The grid is anchored to midnight, so the session's first bucket is a stub and every
|
|
47
|
+
subsequent boundary is offset from the open. `upticks` anchors each bucket to the session's
|
|
48
|
+
own first bar:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
up.resample(bars, "1h") # [60, 60, 60, 60, 60, 60, 15] ← anchored to 09:15
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The difference compounds. A `75min` or `125min` frame under a global origin drifts to a
|
|
55
|
+
different time of day on every subsequent session; anchored per session it lands on the same
|
|
56
|
+
five (or three) boundaries every trading day. A special evening session — NSE's Muhurat
|
|
57
|
+
trading, 18:00–18:59 — becomes exactly one hourly bar instead of being shredded or dropped.
|
|
58
|
+
|
|
59
|
+
Both behaviours remain reachable: `anchor="midnight"` is the correct choice for a 24-hour
|
|
60
|
+
instrument, and it is the only way to obtain the naive grid. You cannot get it by accident.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Causality, concretely
|
|
65
|
+
|
|
66
|
+
Every resampled bar carries an **18-column bar contract** beside the frame, and the column
|
|
67
|
+
that matters is `avail_ts` — the instant the bar became knowable:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
bars.contract[["bar_open_ts", "bar_close_ts", "avail_ts", "is_complete", "is_forming"]]
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
- **`bar_close_ts` is the actual last constituent plus one interval**, never the nominal
|
|
74
|
+
period end. On a truncated or special session those differ, and the nominal answer is
|
|
75
|
+
wrong.
|
|
76
|
+
- **`avail_ts` is the only legal join key.** Joining on a bar's label is what leaks, so
|
|
77
|
+
labels are not offered as join keys anywhere.
|
|
78
|
+
- **`is_forming` marks a bar that can still change.** By default the still-open final bucket
|
|
79
|
+
is withheld entirely (`forming="drop"`), so nothing knowable-early reaches a backtest. A
|
|
80
|
+
daily bar for a session the feed has not finished publishing is not handed to you as
|
|
81
|
+
settled.
|
|
82
|
+
- **Resampling to a finer frequency is refused** with a typed error. There is no public
|
|
83
|
+
forward-fill-to-finer verb, because that is the leak.
|
|
84
|
+
- **Resample first, compute second.** `RSI(14)` on hourly bars is a different quantity from
|
|
85
|
+
`RSI(14)` computed on minutes and aggregated; no public path produces the latter.
|
|
86
|
+
|
|
87
|
+
Tested as named properties, not asserted as design intent: volume conservation, extreme
|
|
88
|
+
preservation, `1min→1h→1D` bitwise identical to `1min→1D`, idempotence, no bucket spanning
|
|
89
|
+
two sessions, and `avail_ts > bar_open_ts` on every emitted bar.
|
|
90
|
+
|
|
91
|
+
**On look-ahead itself the claim is bounded, deliberately: _no detectable look-ahead under
|
|
92
|
+
these tests_ — never _provably none_.** This release ships the structural layers — schema
|
|
93
|
+
assertions at construction, the availability contract, and the refusals above — and the
|
|
94
|
+
causality harness that makes "these tests" an enumerable, named list arrives in the next
|
|
95
|
+
stage. Until it does, read the claim as exactly what it says: these tests did not detect a
|
|
96
|
+
leak, which is not the same as there being none.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Sessions without a calendar
|
|
101
|
+
|
|
102
|
+
There is no exchange-calendar dependency anywhere in this library, and there never will be.
|
|
103
|
+
Sessions are inferred from the multiplicative structure of the data's own gaps; the holiday
|
|
104
|
+
table is the complement of the observed trading days.
|
|
105
|
+
|
|
106
|
+
This handles, on real data:
|
|
107
|
+
|
|
108
|
+
- **special sessions** — an evening or afternoon session that matches no modal shape is kept
|
|
109
|
+
as a first-class session, never merged into a neighbour
|
|
110
|
+
- **half-days and truncated feeds** — flagged `is_short`, and `is_provisional` when they sit
|
|
111
|
+
at the data tail and the vendor may still revise them
|
|
112
|
+
- **lunch-break markets** — a mid-session gap is absorbed as a *break*, not a boundary, so
|
|
113
|
+
Tokyo's 11:30–12:30 does not split the day in two
|
|
114
|
+
- **midnight-crossing sessions** — a CME Globex 23:30 bar belongs to the next calendar day's
|
|
115
|
+
trade date, and the session is one session
|
|
116
|
+
- **trading halts** — a 90-minute hole is a shape deviation, not a session split
|
|
117
|
+
- **DST transitions** — boundaries are computed in integer nanoseconds from the session open,
|
|
118
|
+
so a spring-forward week does not shift them
|
|
119
|
+
|
|
120
|
+
A declared `SessionShape` bypasses inference entirely where the heuristic is unsafe.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Quick start
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
import upticks as up
|
|
128
|
+
|
|
129
|
+
bars = up.load("NIFTY_1min.csv", tz="Asia/Kolkata", exchange="NSE", preset="nse_intraday")
|
|
130
|
+
|
|
131
|
+
print(bars.report())
|
|
132
|
+
# 500 sessions | 8 short | 2 off-hours (Muhurat) | tick 0.05 | 186747 bars | 2024-08-07 → 2026-08-12
|
|
133
|
+
|
|
134
|
+
bars.quality # the 16 hygiene checks, one row each
|
|
135
|
+
bars.sessions.table # one row per session, with its flags
|
|
136
|
+
|
|
137
|
+
hourly = up.resample(bars, "1h")
|
|
138
|
+
daily = up.resample(bars, "1D") # one bar per SESSION, never a midnight resample
|
|
139
|
+
weekly = up.resample(bars, "W-FRI") # restamped to the last actual session of the week
|
|
140
|
+
|
|
141
|
+
orb = up.opening_range(bars, 15) # one bar per session, first 15 minutes
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Nothing is repaired behind your back. `load()` reports; `repair()` is a separate call that
|
|
145
|
+
takes an explicit policy and records it in `Meta`.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Design commitments
|
|
150
|
+
|
|
151
|
+
**Three runtime dependencies: pandas, numpy, scipy.** Nothing else, ever. `pyarrow`,
|
|
152
|
+
`matplotlib` and `numba` are optional extras, imported lazily inside the one function that
|
|
153
|
+
needs them, and their absence raises an error naming the extra.
|
|
154
|
+
|
|
155
|
+
**`bars.df` is a plain DataFrame** and never a subclass, so anything that consumes pandas can
|
|
156
|
+
consume it. Metadata that pandas drops — timezone, tick grid, session table, fingerprint,
|
|
157
|
+
adjustment lineage — lives on the handle instead.
|
|
158
|
+
|
|
159
|
+
**Refusals name the missing data.** Every error carries a remedy that says what to pass.
|
|
160
|
+
An ambiguous frequency alias is refused rather than guessed: `60m` means sixty minutes in
|
|
161
|
+
MetaTrader and sixty month-ends in pandas, so `upticks` refuses it and names both.
|
|
162
|
+
|
|
163
|
+
**Defaults are documented, not folklore.** `up.defaults_provenance()` returns every numeric
|
|
164
|
+
default with its origin and citation.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Supported versions
|
|
169
|
+
|
|
170
|
+
Python 3.11–3.13. pandas 2.2 through 3.x, and the test suite is run under **both** majors —
|
|
171
|
+
pandas 3 changed the default datetime resolution from nanoseconds to microseconds, which
|
|
172
|
+
silently breaks naive integer-time arithmetic, so this is verified rather than assumed.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Honest limitations
|
|
177
|
+
|
|
178
|
+
- **Alpha.** The public surface of this stage is stable and tested, but later stages will add
|
|
179
|
+
to it. Pin the version.
|
|
180
|
+
- **Session inference is a heuristic.** It is validated against every session of a
|
|
181
|
+
two-year 1-minute reference file and against synthetic fixtures for four other market
|
|
182
|
+
shapes, but a genuinely novel session structure may need a declared `SessionShape`.
|
|
183
|
+
- **Corporate-action detection is candidate-only.** Splits and bonuses are matched against a
|
|
184
|
+
small set of rational overnight ratios. An ex-dividend drop is observationally identical to
|
|
185
|
+
an ordinary news gap without a dividend feed, and is reported as a candidate, never a fact.
|
|
186
|
+
- **Back-adjustment is non-causal by construction** and says so: rescaling pre-ex-date bars
|
|
187
|
+
uses information from the ex-date. It is available, registered as non-causal, and refused
|
|
188
|
+
by default where causality matters.
|
|
189
|
+
- **No exchange calendar means no forward-looking holidays.** The data is the calendar, so a
|
|
190
|
+
holiday after the last bar is unknowable; supply one explicitly if you need it.
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
|
|
196
|
+
Apache-2.0. Copyright (c) Nashit Babber.
|