Przejdź do treści
Biblioteka skilli
Finanse i księgowość · Planowanie

ml4t-define-universe

/ml4t-define-universe

Definiuje uniwersa handlowe na dany moment z filtrami płynności, żeby zbiór inwestycyjny unikał obciążenia przeżywalnością i płynnością.

Repozytorium
skills ↗
Licencja
Apache-2.0
Ostatnia zmiana repozytorium
23.10.2026

Ocena i bezpieczeństwo

95/ 100Klasa: dobry
Format20 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 23.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.

Co robi i kiedy

Definiuje uniwersa handlowe na dany moment z filtrami płynności, żeby zbiór inwestycyjny unikał obciążenia przeżywalnością i płynnością.

Oryginalny opis (EN)

Define point-in-time tradeable universes with liquidity filters. Use when constructing the investable asset set that avoids survivorship and liquidity bias.

Jak działa

  1. The Problem
  2. The Pattern
  3. Handling Delistings
  4. Guardrails
  5. Production Implementation
  6. Checklist
Sekcje z nagłówków SKILL.md, w oryginale · 110 linii, 377 słów
Podgląd SKILL.md
---
name: ml4t-define-universe
description: "Define point-in-time tradeable universes with liquidity filters. Use when constructing the investable asset set that avoids survivorship and liquidity bias."
when_to_use: "Use when specifying which assets a strategy can trade at each historical date"
dependencies: []
metadata:
  book_chapters: "2, 6"
  library: "ml4t-data"
paths: ["**/*data*.py", "**/*fetch*.py", "**/*bars*.py", "**/*universe*.py", "**/*calendar*.py", "**/*futures*.py", "**/*export*.py", "**/*synthetic*.py"]
---
# Define Universe

Using today's index constituents for a historical backtest introduces survivorship bias - you only trade winners that stayed in the index, inflating returns by 1-2% per year.

## The Problem

The S&P 500 today contains companies that survived and grew. The 2010 index
contained firms since acquired, delisted, or bankrupt. A backtest on current
members never sees these failures and overstates performance.

## The Pattern

### WRONG
```python
import polars as pl

# Current constituents applied to historical backtest
sp500_today = ["AAPL", "MSFT", "GOOGL", ...]  # 2024 list
prices = pl.read_parquet("prices.parquet").filter(
    pl.col("symbol").is_in(sp500_today)
)
# Backtest from 2010 - but these are 2024 survivors
```

### CORRECT
```python
import polars as pl

def get_universe(
    prices: pl.DataFrame,
    as_of: str,
    min_price: float = 5.0,
    min_avg_dollar_volume: float = 5_000_000,
    min_history_days: int = 252,
    lookback_days: int = 63,
) -> list[str]:
    """Point-in-time universe: only assets tradeable on as_of date."""
    cutoff = pl.lit(as_of).str.to_date()

    candidates = (
        prices.filter(pl.col("timestamp") <= cutoff)
        .group_by("symbol")
        .agg(
            last_price=pl.col("close").last(),
            avg_dollar_vol=(pl.col("close") * pl.col("volume"))
                .tail(lookback_days).mean(),
            n_days=pl.col("timestamp").n_unique(),
            last_trade=pl.col("timestamp").max(),
        )
        .filter(
            (pl.col("last_price") >= min_price)
            & (pl.col("avg_dollar_vol") >= min_avg_dollar_volume)
            & (pl.col("n_days") >= min_history_days)
            & (pl.col("last_trade") == cutoff)  # Must be actively trading
        )
    )
    return candidates["symbol"].to_list()

universe_2015 = get_universe(all_prices, as_of="2015-01-02")
universe_2020 = get_universe(all_prices, as_of="2020-01-02")
```

## Handling Delistings

```python
DELISTING_RETURNS = {
    "bankruptcy": -1.0,
    "acquisition": 0.0,     # Use actual tender premium if available
    "going_private": 0.0,
}

def apply_delisting_returns(returns: pl.DataFrame, delistings: pl.DataFrame):
    """Replace last return with delisting return for removed assets."""
    return returns.join(delistings, on=["symbol", "timestamp"], how="left").with_columns(
        pl.when(pl.col("delist_type").is_not_null())
        .then(pl.col("delist_return"))
        .otherwise(pl.col("ret"))
        .alias("ret")
    )
```

## Guardrails

- Free data sources (Yahoo Finance, etc.) almost always have survivorship bias - they only cover current tickers
- CRSP is the gold standard for survivorship-free US equities (includes delisting returns)
- A universe that never changes is a red flag - real indices reconstitute quarterly
- Penny stocks and micro-caps pass through if you skip liquidity filters, dominating signals with noise

## Production Implementation

```python
from ml4t.data import DataManager

dm = DataManager()
panel = dm.batch_load_universe(
    "sp500",
    start="2015-01-01",
    end="2024-12-31",
    provider="yahoo",
)
```

## Checklist

- [ ] Universe is point-in-time (no future constituents)
- [ ] Liquidity filter applied (price, volume, history)
- [ ] Delistings handled with terminal returns
- [ ] Rebalance schedule defined (quarterly typical)
- [ ] Data source is survivorship-free or bias is documented

Wersje

W bazie nie ma innych skilli o nazwie ml4t-define-universe.

Migawka bazy z 28.10.2026 · wersja paczki b6acd142c565 (skrót SHA-256 całej paczki)

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 95liquidity-planner
    Generuje linki do tworzenia pozycji płynności w interfejsie Uniswap, w tym pozycji v3 i v4 z koncentrowaną płynnością i wybranym zakresem cen.
  • 95ml4t-survivorship-bias
    Uwzględnia spółki wycofane z obrotu i usunięte z indeksów w analizach historycznych, żeby przy budowie uniwersów i cech przekrojowych uniknąć zawyżenia wyników przez przetrwałych.
  • 90liquidity-planner
    Planuje dostarczanie płynności na PancakeSwap: dodawanie płynności, LP i farming, bez pisania kodu.
  • 90survivorship-bias-free-universe-construction
    Buduje uniwersum instrumentów handlowalnych w każdej historycznej dacie, zachowując spółki wycofane z obrotu i rozliczając ich wartość końcową w testach wstecznych.
  • 100nixtla-liquidity-forecaster
    Prognozuje głębokość księgi zleceń i spready, aby zoptymalizować moment realizacji transakcji, przy szacowaniu płynności rynku dla dużych zleceń.
  • 100universe-builder
    Buduje przefiltrowane i uszeregowane uniwersum akcji w tabeli w stylu screenera Bloomberg EQS i FactSet: predykaty, ranking z-score, koncentracja sektorowa i survivorship.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.