File size: 3,032 Bytes
06a67ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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 statement(cik, sic, day, *, source="xbrl", ref="acc-1", dated=True):
    return {
        "cik": cik, "sic": sic, "stated_on": day,
        "knowledge_time": datetime.combine(day, datetime.min.time(), tzinfo=UTC),
        "source": source, "source_ref": ref, "is_dated": dated,
        "inserted_at": datetime.now(UTC),
    }


@pytest.fixture
def observations() -> pl.DataFrame:
    """A de-SPAC, a steady company, and a filer EDGAR only knows about today.

    Filer 1 is the case the point-in-time columns exist for: it filed as a
    blank check, merged with a car maker and was reclassified. A dataset that
    stated only today's code would put an automotive sector on its 2020
    filings, when it was an empty shell.
    """
    rows = [
        statement("0000000001", "6770", date(2020, 3, 2), ref="a1"),
        statement("0000000001", "6770", date(2020, 8, 2), ref="a2"),
        statement("0000000001", "3711", date(2021, 5, 2), ref="a3"),
        statement("0000000001", "3711", date(2024, 5, 2), ref="a4"),
        statement("0000000002", "2834", date(2012, 1, 5), ref="b1"),
        statement("0000000002", "2834", date(2023, 1, 5), ref="b2"),
        statement("0000000003", "6022", date(2026, 10, 1), source="submissions",
                  ref="CIK0000000003.json", dated=False),
    ]
    return pl.DataFrame(rows)


@pytest.fixture
def tickers() -> pl.DataFrame:
    """Ticker spans as the security master publishes them."""
    return pl.DataFrame([
        {"cik": "0000000001", "ticker": "SPAC", "valid_from": date(2020, 3, 2),
         "valid_to": date(2021, 2, 1), "is_current": False},
        {"cik": "0000000001", "ticker": "CARZ", "valid_from": date(2021, 5, 2),
         "valid_to": date(2024, 5, 2), "is_current": True},
        {"cik": "0000000002", "ticker": "PILL", "valid_from": date(2012, 1, 5),
         "valid_to": date(2023, 1, 5), "is_current": True},
        # Delisted in 2007: the only code EDGAR holds for it is today's.
        {"cik": "0000000003", "ticker": "GONE", "valid_from": date(2006, 4, 1),
         "valid_to": date(2007, 9, 1), "is_current": False},
        # A filer nothing knows a code for at all.
        {"cik": "0000000004", "ticker": "HUH", "valid_from": date(2011, 1, 1),
         "valid_to": date(2012, 1, 1), "is_current": False},
    ])


@pytest.fixture
def directory() -> pl.DataFrame:
    return pl.DataFrame([
        {"cik": f"000000000{n}", "name": name, "primary_ticker": ticker,
         "all_tickers": ticker, "exchange": "NYSE", "is_active": active,
         "first_seen": date(2006, 1, 1)}
        for n, name, ticker, active in (
            (1, "Car Co", "CARZ", True), (2, "Pill Co", "PILL", True),
            (3, "Gone Co", "GONE", False), (4, "Huh Co", "HUH", False),
        )
    ])