Datasets:
Download tests/conftest.py from ZipLime/security-master: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/datasets/ZipLime/security-master/resolve/main/tests/conftest.py
- Command line
-
hf download hf://datasets/ZipLime/security-master/tests/conftest.py
-
curl -L -o conftest.py https://huggingface.co/datasets/ZipLime/security-master/resolve/main/tests/conftest.py
2.46 kB
| from __future__ import annotations | |
| import sys | |
| from datetime import UTC, date, datetime | |
| from pathlib import Path | |
| import polars as pl | |
| import pytest | |
| ROOT = Path(__file__).resolve().parents[1] | |
| if str(ROOT) not in sys.path: | |
| sys.path.insert(0, str(ROOT)) | |
| def observation(cik, kind, value, day, source="form4", ref="acc-1"): | |
| return {"cik": cik, "kind": kind, "value": value, "observed_on": day, | |
| "source": source, "source_ref": ref, "inserted_at": datetime.now(UTC)} | |
| def observations() -> pl.DataFrame: | |
| """A filer that renamed itself and changed ticker, plus a later reuser. | |
| `PLUM` moves from one company to another, which is the case a security | |
| master exists to get right: a backtest that resolves it by today's mapping | |
| reads the wrong company's history for the earlier years. | |
| """ | |
| rows = [ | |
| observation("0000000001", "ticker", "OLDT", date(2012, 3, 1), ref="a1"), | |
| observation("0000000001", "ticker", "OLDT", date(2015, 3, 1), ref="a2"), | |
| observation("0000000001", "ticker", "NEWT", date(2016, 3, 1), ref="a3"), | |
| observation("0000000001", "ticker", "NEWT", date(2024, 3, 1), ref="a4"), | |
| observation("0000000001", "name", "Old Name Inc", date(2012, 3, 1), ref="a1"), | |
| observation("0000000001", "name", "New Name Inc", date(2024, 3, 1), ref="a4"), | |
| observation("0000000001", "sic", "3571", date(2024, 3, 1), source="xbrl", ref="a4"), | |
| # PLUM belonged to filer 2 until 2014 and to filer 3 from 2019. | |
| observation("0000000002", "ticker", "PLUM", date(2010, 5, 1), ref="b1"), | |
| observation("0000000002", "ticker", "PLUM", date(2014, 5, 1), ref="b2"), | |
| observation("0000000003", "ticker", "PLUM", date(2019, 5, 1), ref="c1"), | |
| observation("0000000003", "ticker", "PLUM", date(2024, 5, 1), ref="c2"), | |
| ] | |
| return pl.DataFrame(rows, strict=False) | |
| def ftd() -> pl.DataFrame: | |
| return pl.DataFrame( | |
| [ | |
| {"cusip": "111111111", "ticker": "PLUM", "issuer_name": "PLUM CORP", | |
| "observed_on": date(2012, 6, 1), "source_ref": "f1"}, | |
| {"cusip": "222222222", "ticker": "PLUM", "issuer_name": "PLUM HOLDINGS", | |
| "observed_on": date(2022, 6, 1), "source_ref": "f2"}, | |
| {"cusip": "333333333", "ticker": "GHOST", "issuer_name": "GHOST INC", | |
| "observed_on": date(2020, 6, 1), "source_ref": "f3"}, | |
| ], | |
| strict=False, | |
| ) | |