Skip to content

Commit

Permalink
feat: Use Polars instead of Pandas
Browse files Browse the repository at this point in the history
  • Loading branch information
suminb committed Nov 4, 2023
1 parent 52ba279 commit e02955b
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions finance/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ def prescreen(
partitions: int,
):
from functools import partial
from random import randint, random
import pandas as pd
import polars as pl
from finance.ext.warehouse import (
Expand All @@ -322,22 +321,22 @@ def prescreen(
calc_overall_correlation,
)

tickers = pd.read_parquet(tickers_source)
tickers = tickers[(tickers["quote_type"] == "ETF") & (tickers["region"] == region)]
tickers = pl.read_parquet(tickers_source)

tickers = tickers[tickers["market_cap"] >= 5e9]
tickers = tickers[
~tickers["name"].str.contains("2X") & ~tickers["name"].str.contains("3X")
]
# US ETFs only
tickers = tickers.filter((tickers["quote_type"] == "ETF") & (tickers["region"] == region))

# Filter by market cap
tickers = tickers.filter(tickers["market_cap"] >= 5e9)

# Temporary workaround
tickers["sector"] = ""
tickers["industry"] = ""
tickers["status"] = ""
# Exclude leveraged ETFs
tickers = tickers.filter(
~tickers["name"].str.contains("2X") & ~tickers["name"].str.contains("3X")
)

# TODO: Support 'static_symbols' option
static_symbols: List[str] = []
symbols = list(tickers["symbol"].values) + static_symbols
symbols = list(tickers["symbol"]) + static_symbols

historical = pd.read_parquet(historical_source)

Expand Down

0 comments on commit e02955b

Please sign in to comment.