tirramind 0.1.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.
- tirramind-0.1.0/.gitignore +6 -0
- tirramind-0.1.0/LICENSE +202 -0
- tirramind-0.1.0/PKG-INFO +34 -0
- tirramind-0.1.0/README.md +11 -0
- tirramind-0.1.0/pyproject.toml +40 -0
- tirramind-0.1.0/src/tirramind/__init__.py +8 -0
- tirramind-0.1.0/src/tirramind/accuracy.py +100 -0
- tirramind-0.1.0/src/tirramind/build.py +180 -0
- tirramind-0.1.0/src/tirramind/client.py +79 -0
- tirramind-0.1.0/src/tirramind/compare.py +41 -0
- tirramind-0.1.0/src/tirramind/daily.py +38 -0
- tirramind-0.1.0/src/tirramind/diff.py +207 -0
- tirramind-0.1.0/src/tirramind/filings.py +115 -0
- tirramind-0.1.0/src/tirramind/forms.py +138 -0
- tirramind-0.1.0/src/tirramind/insiders.py +169 -0
- tirramind-0.1.0/src/tirramind/ledger.py +49 -0
- tirramind-0.1.0/src/tirramind/link.py +78 -0
- tirramind-0.1.0/src/tirramind/nasdaq.py +75 -0
- tirramind-0.1.0/src/tirramind/page.py +72 -0
- tirramind-0.1.0/src/tirramind/reconcile.py +116 -0
- tirramind-0.1.0/src/tirramind/sec.py +97 -0
- tirramind-0.1.0/src/tirramind/store.py +107 -0
- tirramind-0.1.0/src/tirramind/tickers.py +59 -0
- tirramind-0.1.0/src/tirramind/verify.py +46 -0
- tirramind-0.1.0/src/tirramind/wayback.py +95 -0
tirramind-0.1.0/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 [yyyy] [name of copyright owner]
|
|
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.
|
tirramind-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: tirramind
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Survivorship-bias-free US listing ledger with delisting causes and a Form 144 -> Form 4 insider ledger, reconciled daily from SEC public filings
|
|
5
|
+
Project-URL: Repository, https://github.com/savabs/tirramind-universe
|
|
6
|
+
Author: savabs
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: delistings,form-144,form-4,insider-trading,quant,sec,security-master,survivorship-bias
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Requires-Dist: pandas>=2.0
|
|
17
|
+
Requires-Dist: pyarrow>=14
|
|
18
|
+
Requires-Dist: requests>=2.31
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
21
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# tirramind
|
|
25
|
+
|
|
26
|
+
A survivorship-bias-free ledger of every US listed security, with the
|
|
27
|
+
**cause** of every delisting and the SEC filing that proves it — plus a
|
|
28
|
+
Form 144 → Form 4 insider ledger nobody else publishes.
|
|
29
|
+
|
|
30
|
+
Reconciled daily from SEC public filings only. Every row links to its
|
|
31
|
+
source. Where the cause cannot be determined, the row says `UNKNOWN`
|
|
32
|
+
rather than guessing.
|
|
33
|
+
|
|
34
|
+
Code Apache-2.0. Data CC-BY-4.0, derived from SEC public filings.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# tirramind
|
|
2
|
+
|
|
3
|
+
A survivorship-bias-free ledger of every US listed security, with the
|
|
4
|
+
**cause** of every delisting and the SEC filing that proves it — plus a
|
|
5
|
+
Form 144 → Form 4 insider ledger nobody else publishes.
|
|
6
|
+
|
|
7
|
+
Reconciled daily from SEC public filings only. Every row links to its
|
|
8
|
+
source. Where the cause cannot be determined, the row says `UNKNOWN`
|
|
9
|
+
rather than guessing.
|
|
10
|
+
|
|
11
|
+
Code Apache-2.0. Data CC-BY-4.0, derived from SEC public filings.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tirramind"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Survivorship-bias-free US listing ledger with delisting causes and a Form 144 -> Form 4 insider ledger, reconciled daily from SEC public filings"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "savabs" }]
|
|
14
|
+
keywords = ["sec", "delistings", "survivorship-bias", "security-master", "form-144", "form-4", "insider-trading", "quant"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Financial and Insurance Industry",
|
|
18
|
+
"Intended Audience :: Science/Research",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Topic :: Office/Business :: Financial :: Investment",
|
|
21
|
+
]
|
|
22
|
+
dependencies = ["requests>=2.31", "pandas>=2.0", "pyarrow>=14"]
|
|
23
|
+
|
|
24
|
+
[project.optional-dependencies]
|
|
25
|
+
dev = ["pytest>=8", "ruff>=0.4"]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Repository = "https://github.com/savabs/tirramind-universe"
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.targets.wheel]
|
|
31
|
+
packages = ["src/tirramind"]
|
|
32
|
+
|
|
33
|
+
[tool.hatch.build.targets.sdist]
|
|
34
|
+
only-include = ["src/tirramind", "README.md", "LICENSE", "pyproject.toml"]
|
|
35
|
+
|
|
36
|
+
[tool.pytest.ini_options]
|
|
37
|
+
testpaths = ["tests"]
|
|
38
|
+
|
|
39
|
+
[tool.ruff]
|
|
40
|
+
line-length = 100
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""tirramind — survivorship-bias-free US listing ledger from SEC filings."""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.1.0"
|
|
4
|
+
|
|
5
|
+
from .client import delistings, events, form144, load # noqa: E402
|
|
6
|
+
from .store import read_index, snapshot # noqa: E402
|
|
7
|
+
|
|
8
|
+
__all__ = ["load", "events", "delistings", "form144", "snapshot", "read_index", "__version__"]
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""C4: the accuracy table for the 144 -> 4 ledger, with honest uncertainty.
|
|
2
|
+
|
|
3
|
+
Form 144 notices are not independent observations: one insider files
|
|
4
|
+
several, several insiders at one issuer file in the same week, and a whole
|
|
5
|
+
sector sells into the same window. So every rate here carries
|
|
6
|
+
|
|
7
|
+
* ``n`` nominal count,
|
|
8
|
+
* ``n_clusters`` distinct issuer-weeks,
|
|
9
|
+
* ``n_eff`` design-effect effective sample size, n / (1 + (m-1)·ICC),
|
|
10
|
+
* a cluster-bootstrap CI: resample issuer-weeks with replacement, never rows.
|
|
11
|
+
|
|
12
|
+
The CI must widen when clusters are merged; the test asserts it.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import numpy as np
|
|
18
|
+
import pandas as pd
|
|
19
|
+
|
|
20
|
+
HORIZONS = (30, 60, 90)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def cluster_key(df: pd.DataFrame) -> pd.Series:
|
|
24
|
+
wk = pd.to_datetime(df["notice_date"]).dt.to_period("W").astype(str)
|
|
25
|
+
return df["issuer_cik"].astype(str) + ":" + wk
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def icc_binary(y: np.ndarray, g: np.ndarray) -> float:
|
|
29
|
+
"""ANOVA-style intraclass correlation for a binary outcome."""
|
|
30
|
+
df = pd.DataFrame({"y": y, "g": g})
|
|
31
|
+
grp = df.groupby("g")["y"]
|
|
32
|
+
k = grp.ngroups
|
|
33
|
+
n = len(df)
|
|
34
|
+
if k < 2 or n <= k:
|
|
35
|
+
return 0.0
|
|
36
|
+
m = grp.size().values.astype(float)
|
|
37
|
+
n0 = (n - (m ** 2).sum() / n) / (k - 1)
|
|
38
|
+
grand = df["y"].mean()
|
|
39
|
+
msb = (m * (grp.mean().values - grand) ** 2).sum() / (k - 1)
|
|
40
|
+
msw = ((df["y"] - grp.transform("mean")) ** 2).sum() / (n - k)
|
|
41
|
+
if msb + (n0 - 1) * msw <= 0:
|
|
42
|
+
return 0.0
|
|
43
|
+
return float(max(0.0, (msb - msw) / (msb + (n0 - 1) * msw)))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def effective_n(y: np.ndarray, g: np.ndarray) -> tuple[int, int, float]:
|
|
47
|
+
n = len(y)
|
|
48
|
+
k = len(set(g))
|
|
49
|
+
if n == 0:
|
|
50
|
+
return 0, 0, 0.0
|
|
51
|
+
m_bar = n / k
|
|
52
|
+
rho = icc_binary(y, g)
|
|
53
|
+
deff = 1.0 + (m_bar - 1.0) * rho
|
|
54
|
+
return n, k, float(n / deff)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def cluster_bootstrap(stat_fn, df: pd.DataFrame, g: pd.Series, *, n_boot: int = 1000,
|
|
58
|
+
conf: float = 0.9, seed: int = 7) -> tuple[float, float, float]:
|
|
59
|
+
rng = np.random.default_rng(seed)
|
|
60
|
+
groups = {k: v.index.values for k, v in df.groupby(g)}
|
|
61
|
+
keys = list(groups)
|
|
62
|
+
point = float(stat_fn(df))
|
|
63
|
+
if len(keys) < 2:
|
|
64
|
+
return point, float("nan"), float("nan")
|
|
65
|
+
boots = np.empty(n_boot)
|
|
66
|
+
for b in range(n_boot):
|
|
67
|
+
pick = rng.choice(len(keys), size=len(keys), replace=True)
|
|
68
|
+
idx = np.concatenate([groups[keys[i]] for i in pick])
|
|
69
|
+
boots[b] = stat_fn(df.loc[idx])
|
|
70
|
+
a = (1 - conf) / 2
|
|
71
|
+
return point, float(np.quantile(boots, a)), float(np.quantile(boots, 1 - a))
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def accuracy_table(links: pd.DataFrame, *, n_boot: int = 1000, seed: int = 7) -> pd.DataFrame:
|
|
75
|
+
"""Rows: (segment, horizon) -> P(any sale within horizon) with CI, plus
|
|
76
|
+
executed-fraction median, n, n_clusters, n_eff. Segments: all, by
|
|
77
|
+
relationship, by match_method."""
|
|
78
|
+
L = links.copy()
|
|
79
|
+
L = L[L["notice_date"].ne("")]
|
|
80
|
+
if "window_complete" in L:
|
|
81
|
+
L = L[L["window_complete"]]
|
|
82
|
+
L["g"] = cluster_key(L)
|
|
83
|
+
segments = [("all", L)]
|
|
84
|
+
for rel, sub in L.groupby("relationship"):
|
|
85
|
+
if len(sub) >= 20:
|
|
86
|
+
segments.append((f"relationship={rel}", sub))
|
|
87
|
+
for mm, sub in L.groupby("match_method"):
|
|
88
|
+
segments.append((f"match={mm}", sub))
|
|
89
|
+
|
|
90
|
+
rows = []
|
|
91
|
+
for name, sub in segments:
|
|
92
|
+
for h in HORIZONS:
|
|
93
|
+
hit = ((sub["days_to_first_sale"] >= 0) & (sub["days_to_first_sale"] <= h)).astype(float)
|
|
94
|
+
n, k, neff = effective_n(hit.values, sub["g"].values)
|
|
95
|
+
tmp = sub.assign(hit=hit)
|
|
96
|
+
p, lo, hi = cluster_bootstrap(lambda d: d["hit"].mean(), tmp, tmp["g"], n_boot=n_boot, seed=seed)
|
|
97
|
+
rows.append({"segment": name, "horizon_days": h, "p_executed": p, "ci_lo": lo, "ci_hi": hi,
|
|
98
|
+
"n": n, "n_clusters": k, "n_eff": round(neff, 1),
|
|
99
|
+
"median_executed_fraction": float(sub["executed_fraction"].median())})
|
|
100
|
+
return pd.DataFrame(rows)
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""B6: regenerate the published parquet outputs from snapshots and ledgers.
|
|
2
|
+
|
|
3
|
+
Everything here is derived. Delete ``data/*.parquet`` and rerun and you get
|
|
4
|
+
byte-identical files; the snapshots and ledgers are the record.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
from datetime import datetime, timezone
|
|
11
|
+
|
|
12
|
+
import pandas as pd
|
|
13
|
+
|
|
14
|
+
from . import __version__
|
|
15
|
+
from .accuracy import accuracy_table
|
|
16
|
+
from .diff import annotate, events_over_history, fill_exchange, permanent_removals
|
|
17
|
+
from .link import link
|
|
18
|
+
from .page import render_weekly
|
|
19
|
+
from .ledger import DEFAULT_ROOT as LEDGER_ROOT, read as read_ledger
|
|
20
|
+
from .reconcile import CAUSES, NOT_DELISTINGS, reconcile, summary
|
|
21
|
+
from .store import DEFAULT_ROOT as SNAP_ROOT, load_snapshot, snapshots_for
|
|
22
|
+
|
|
23
|
+
OUT = os.path.join(os.getcwd(), "data")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def build(*, snap_root: str = SNAP_ROOT, ledger_root: str = LEDGER_ROOT, out: str = OUT) -> dict:
|
|
27
|
+
os.makedirs(out, exist_ok=True)
|
|
28
|
+
snaps = snapshots_for("tickers", root=snap_root)
|
|
29
|
+
if not snaps:
|
|
30
|
+
raise RuntimeError("no ticker snapshots; run tickers.snapshot_current first")
|
|
31
|
+
latest = load_snapshot(snap_root, snaps[-1]["path"])
|
|
32
|
+
events = annotate(fill_exchange(events_over_history("tickers", root=snap_root), root=snap_root))
|
|
33
|
+
filings = read_ledger("filings", root=ledger_root)
|
|
34
|
+
if filings.empty:
|
|
35
|
+
raise RuntimeError("filings ledger is empty; run filings.backfill first")
|
|
36
|
+
delist = reconcile(permanent_removals(events), filings)
|
|
37
|
+
|
|
38
|
+
latest.to_parquet(os.path.join(out, "tickers_latest.parquet"), index=False)
|
|
39
|
+
events.to_parquet(os.path.join(out, "events.parquet"), index=False)
|
|
40
|
+
delist.to_parquet(os.path.join(out, "delistings.parquet"), index=False)
|
|
41
|
+
filings.drop(columns=[c for c in ("filed_ts",) if c in filings]).to_parquet(
|
|
42
|
+
os.path.join(out, "filings.parquet"), index=False)
|
|
43
|
+
|
|
44
|
+
# Insider ledger: optional until C2 has run at least once.
|
|
45
|
+
f144 = read_ledger("form144", root=ledger_root)
|
|
46
|
+
f4 = read_ledger("form4", root=ledger_root)
|
|
47
|
+
insider = {}
|
|
48
|
+
if not f144.empty and not f4.empty:
|
|
49
|
+
# dense coverage = bulk-dataset rows; EFTS rows after that are sparse until the fill completes
|
|
50
|
+
cov = f4[f4["source"].str.startswith("dataset")]["transaction_date"].max() if "source" in f4 else None
|
|
51
|
+
links = link(f144, f4, coverage_end=cov)
|
|
52
|
+
acc = accuracy_table(links)
|
|
53
|
+
links.to_parquet(os.path.join(out, "form144_links.parquet"), index=False)
|
|
54
|
+
acc.to_parquet(os.path.join(out, "accuracy.parquet"), index=False)
|
|
55
|
+
render_weekly(links, acc, f144, out=os.path.join(os.path.dirname(out), "docs"))
|
|
56
|
+
mm = links["match_method"].value_counts(normalize=True).to_dict()
|
|
57
|
+
insider = {"form144": int(len(f144)), "form4_rows": int(len(f4)), "form4_coverage_end": str(cov),
|
|
58
|
+
"window_complete": int(links["window_complete"].sum()),
|
|
59
|
+
"form4_sales": int((f4["code"] == "S").sum()),
|
|
60
|
+
"links": int(len(links)), "match_method_shares": {k: round(float(v), 4) for k, v in mm.items()},
|
|
61
|
+
"p_executed_90d_all": float(acc[(acc.segment == "all") & (acc.horizon_days == 90)]["p_executed"].iloc[0])}
|
|
62
|
+
|
|
63
|
+
shares = summary(delist)
|
|
64
|
+
stats = {
|
|
65
|
+
"built_at": datetime.now(timezone.utc).isoformat(timespec="seconds"),
|
|
66
|
+
"version": __version__,
|
|
67
|
+
"snapshots": len(snaps),
|
|
68
|
+
"first_snapshot": snaps[0]["captured_at"],
|
|
69
|
+
"latest_snapshot": snaps[-1]["captured_at"],
|
|
70
|
+
"tickers_latest": int(len(latest)),
|
|
71
|
+
"events": int(len(events)),
|
|
72
|
+
"events_by_type": events["event"].value_counts().to_dict(),
|
|
73
|
+
"suspect_steps": sorted(set(events.loc[events.suspect, "to_captured_at"].str[:10])),
|
|
74
|
+
"raw_removals": int(events.event.eq("DELISTED_FROM_MAP").sum()),
|
|
75
|
+
"superseded": delist.loc[delist.cause.isin(NOT_DELISTINGS), "cause"].value_counts().to_dict(),
|
|
76
|
+
"true_delistings": int((~delist.cause.isin(NOT_DELISTINGS)).sum()),
|
|
77
|
+
"cause_by_exchange_2022": pd.crosstab(delist[(delist.to_captured_at >= "2022") & ~delist.cause.isin(NOT_DELISTINGS)].exchange.replace("", "(blank)"),
|
|
78
|
+
delist[(delist.to_captured_at >= "2022") & ~delist.cause.isin(NOT_DELISTINGS)].cause).to_dict(),
|
|
79
|
+
"relisted_share": round(float((events.event.eq("DELISTED_FROM_MAP") & events.relisted_at.ne("")).sum()
|
|
80
|
+
/ max(1, events.event.eq("DELISTED_FROM_MAP").sum())), 4),
|
|
81
|
+
"delistings": int(len(delist)),
|
|
82
|
+
"cause_shares": {c: round(float(shares[c]), 4) for c in CAUSES},
|
|
83
|
+
"filings": int(len(filings)),
|
|
84
|
+
"filings_by_form": filings["form"].value_counts().to_dict(),
|
|
85
|
+
"insider": insider,
|
|
86
|
+
}
|
|
87
|
+
_write_readme(out, stats)
|
|
88
|
+
return stats
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _write_readme(out: str, s: dict) -> None:
|
|
92
|
+
ev = "\n".join(f"| {k} | {v} |" for k, v in sorted(s["events_by_type"].items()))
|
|
93
|
+
causes = "\n".join(f"| {k} | {v:.1%} |" for k, v in s["cause_shares"].items())
|
|
94
|
+
forms = "\n".join(f"| {k} | {v} |" for k, v in sorted(s["filings_by_form"].items()))
|
|
95
|
+
bx = pd.DataFrame(s["cause_by_exchange_2022"]).fillna(0).astype(int)
|
|
96
|
+
if len(bx):
|
|
97
|
+
bx["total"] = bx.sum(axis=1)
|
|
98
|
+
bx["known"] = (1 - bx.get("UNKNOWN", 0) / bx["total"]).map(lambda v: f"{v:.0%}")
|
|
99
|
+
by_ex = "| exchange | " + " | ".join(bx.columns) + " |\n|---|" + "---|" * len(bx.columns) + "\n" + \
|
|
100
|
+
"\n".join(f"| {i} | " + " | ".join(str(v) for v in r) + " |" for i, r in bx.iterrows())
|
|
101
|
+
else:
|
|
102
|
+
by_ex = "(no rows)"
|
|
103
|
+
ins = s.get("insider") or {}
|
|
104
|
+
insider = "" if not ins else f"""
|
|
105
|
+
## Form 144 → Form 4 ledger
|
|
106
|
+
| | |
|
|
107
|
+
|---|---|
|
|
108
|
+
| Form 144 notices | {ins['form144']} |
|
|
109
|
+
| Form 4 transaction rows | {ins['form4_rows']} (sales: {ins['form4_sales']}) |
|
|
110
|
+
| linked notices | {ins['links']} |
|
|
111
|
+
| match method | {', '.join(f'{k} {v:.0%}' for k, v in ins['match_method_shares'].items())} |
|
|
112
|
+
| P(sale within 90d), all | {ins['p_executed_90d_all']:.1%} |
|
|
113
|
+
|
|
114
|
+
Files: `form144_links.parquet` (one row per notice), `accuracy.parquet`
|
|
115
|
+
(rates with cluster-bootstrap CIs and effective n). Weekly page: `docs/index.html`.
|
|
116
|
+
"""
|
|
117
|
+
text = f"""# Data
|
|
118
|
+
|
|
119
|
+
Built {s['built_at']} by tirramind {s['version']}. Derived from SEC public
|
|
120
|
+
filings only (sec.gov: `company_tickers.json`, `company_tickers_exchange.json`,
|
|
121
|
+
EDGAR full-text search). Licence: CC-BY-4.0, attribution "derived from SEC
|
|
122
|
+
public filings". Nothing here is investment advice.
|
|
123
|
+
|
|
124
|
+
Snapshots before {s['first_snapshot'][:10]}'s own capture come from the
|
|
125
|
+
Wayback Machine (roughly monthly); daily resolution starts 2026-09-06.
|
|
126
|
+
|
|
127
|
+
| file | rows | what |
|
|
128
|
+
|---|---|---|
|
|
129
|
+
| `tickers_latest.parquet` | {s['tickers_latest']} | current (cik, ticker, name, exchange) |
|
|
130
|
+
| `events.parquet` | {s['events']} | every change between consecutive snapshots |
|
|
131
|
+
| `delistings.parquet` | {s['delistings']} | permanent removals (not re-listed, not from a suspect capture) with a cause and evidence accessions |
|
|
132
|
+
| `filings.parquet` | {s['filings']} | Form 25 / 15 and item-filtered 8-K filings, 2015→ |
|
|
133
|
+
|
|
134
|
+
## Events ({s['snapshots']} snapshots, {s['first_snapshot'][:10]} → {s['latest_snapshot'][:10]})
|
|
135
|
+
| event | count |
|
|
136
|
+
|---|---|
|
|
137
|
+
{ev}
|
|
138
|
+
|
|
139
|
+
## What a "removal" is
|
|
140
|
+
`events.parquet` has {s['raw_removals']} raw `DELISTED_FROM_MAP` rows. **{s['relisted_share']:.0%} of
|
|
141
|
+
them re-appear later** (`relisted_at`) — the SEC file churns for housekeeping
|
|
142
|
+
reasons. Steps that removed ≥1,500 tickers at once are partial or
|
|
143
|
+
format-shifted captures and are flagged `suspect`: {', '.join(s['suspect_steps']) or 'none'}.
|
|
144
|
+
Of the removals that are neither re-listed nor suspect ({s['delistings']}),
|
|
145
|
+
those whose CIK gained a *different* ticker within ±60 days **and** have no
|
|
146
|
+
stronger filing evidence are two-step symbol changes or exchange transfers,
|
|
147
|
+
not delistings ({', '.join(f'{k} {v}' for k, v in s['superseded'].items()) or 'none'}).
|
|
148
|
+
They stay in `delistings.parquet` with that cause; the shares below are
|
|
149
|
+
over the remaining {s['true_delistings']} true delistings. The raw rows stay in `events.parquet`; nothing is deleted.
|
|
150
|
+
|
|
151
|
+
## Delisting causes
|
|
152
|
+
`UNKNOWN` means no qualifying filing was found on that CIK within
|
|
153
|
+
−180/+30 days of the ticker's disappearance. It is reported, not guessed.
|
|
154
|
+
A ticker can also leave the SEC map for housekeeping reasons that are not a
|
|
155
|
+
delisting; that share is inside `UNKNOWN`.
|
|
156
|
+
|
|
157
|
+
| cause | share |
|
|
158
|
+
|---|---|
|
|
159
|
+
{causes}
|
|
160
|
+
|
|
161
|
+
### By exchange, removals since 2022
|
|
162
|
+
{by_ex}
|
|
163
|
+
|
|
164
|
+
Known blind spots: foreign private issuers file 6-K/20-F, not 8-K, so a
|
|
165
|
+
going-private of an ADR shows as `EXCHANGE_DELISTING` (Form 25 only) or
|
|
166
|
+
`UNKNOWN`. Dormant OTC registrants that simply stop filing are `UNKNOWN`
|
|
167
|
+
until a last-filing-date check is added.
|
|
168
|
+
|
|
169
|
+
## Filings collected
|
|
170
|
+
| form | count |
|
|
171
|
+
|---|---|
|
|
172
|
+
{forms}
|
|
173
|
+
{insider}"""
|
|
174
|
+
with open(os.path.join(out, "README.md"), "w", encoding="utf-8") as fh:
|
|
175
|
+
fh.write(text)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
if __name__ == "__main__":
|
|
179
|
+
import json
|
|
180
|
+
print(json.dumps(build(), indent=1))
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""D2: read the published ledger without cloning the repo.
|
|
2
|
+
|
|
3
|
+
import tirramind
|
|
4
|
+
tirramind.load("delistings") # DataFrame
|
|
5
|
+
tirramind.events(since="2025-01-01")
|
|
6
|
+
tirramind.form144(since="2025-06-01")
|
|
7
|
+
|
|
8
|
+
Files are fetched from the repo's raw URL and cached locally by ETag-less
|
|
9
|
+
content hash for ``ttl`` seconds. Point ``TIRRAMIND_DATA`` at a local
|
|
10
|
+
``data/`` directory to read a checkout instead.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import hashlib
|
|
16
|
+
import os
|
|
17
|
+
import time
|
|
18
|
+
|
|
19
|
+
import pandas as pd
|
|
20
|
+
|
|
21
|
+
RAW = "https://raw.githubusercontent.com/savabs/tirramind-universe/main/data/"
|
|
22
|
+
TABLES = {"tickers": "tickers_latest.parquet", "events": "events.parquet",
|
|
23
|
+
"delistings": "delistings.parquet", "filings": "filings.parquet",
|
|
24
|
+
"form144": "form144_links.parquet", "accuracy": "accuracy.parquet"}
|
|
25
|
+
CACHE = os.path.join(os.path.expanduser("~"), ".cache", "tirramind")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _local_dir() -> str | None:
|
|
29
|
+
return os.environ.get("TIRRAMIND_DATA") or None
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _fetch(name: str, ttl: int) -> str:
|
|
33
|
+
fname = TABLES[name]
|
|
34
|
+
local = _local_dir()
|
|
35
|
+
if local:
|
|
36
|
+
return os.path.join(local, fname)
|
|
37
|
+
os.makedirs(CACHE, exist_ok=True)
|
|
38
|
+
path = os.path.join(CACHE, fname)
|
|
39
|
+
if os.path.exists(path) and time.time() - os.path.getmtime(path) < ttl:
|
|
40
|
+
return path
|
|
41
|
+
import requests
|
|
42
|
+
r = requests.get(RAW + fname, timeout=120)
|
|
43
|
+
r.raise_for_status()
|
|
44
|
+
tmp = path + f".{hashlib.md5(r.content).hexdigest()[:8]}.tmp"
|
|
45
|
+
with open(tmp, "wb") as fh:
|
|
46
|
+
fh.write(r.content)
|
|
47
|
+
os.replace(tmp, path)
|
|
48
|
+
return path
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def load(name: str, *, ttl: int = 3600) -> pd.DataFrame:
|
|
52
|
+
if name not in TABLES:
|
|
53
|
+
raise KeyError(f"unknown table {name!r}; one of {sorted(TABLES)}")
|
|
54
|
+
return pd.read_parquet(_fetch(name, ttl))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def events(*, since: str | None = None, event: str | None = None, **kw) -> pd.DataFrame:
|
|
58
|
+
df = load("events", **kw)
|
|
59
|
+
if since:
|
|
60
|
+
df = df[df["to_captured_at"] >= since]
|
|
61
|
+
if event:
|
|
62
|
+
df = df[df["event"].eq(event)]
|
|
63
|
+
return df.reset_index(drop=True)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def delistings(*, since: str | None = None, cause: str | None = None, **kw) -> pd.DataFrame:
|
|
67
|
+
df = load("delistings", **kw)
|
|
68
|
+
if since:
|
|
69
|
+
df = df[df["to_captured_at"] >= since]
|
|
70
|
+
if cause:
|
|
71
|
+
df = df[df["cause"].eq(cause)]
|
|
72
|
+
return df.reset_index(drop=True)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def form144(*, since: str | None = None, **kw) -> pd.DataFrame:
|
|
76
|
+
df = load("form144", **kw)
|
|
77
|
+
if since:
|
|
78
|
+
df = df[df["notice_date"] >= since]
|
|
79
|
+
return df.reset_index(drop=True)
|