security-master / tests /conftest.py
ZipLime's picture
Update the security master
2df88dc verified
Raw History Blame Contribute Delete
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)}
@pytest.fixture
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)
@pytest.fixture
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,
)