Skip to main content

A robust wrapper around yfinance for market-aware financial data fetching.

Project description

FinFetcher

PyPI version Documentation Python Tests License

Quick Summary: A robust Python library for fetching clean, market-aware historical financial data. It acts as a smart wrapper around yfinance, automatically handling asset-specific market hours and timezones to ensure data integrity for quantitative modeling and backtesting.

📖 Read the Full Documentation


📊 The Problem it Solves

When fetching daily data during active market hours, standard tools often return an "unfinished" candle for the current day. Using this incomplete data point can introduce significant look-ahead bias or noise in statistical models.

FinFetcher solves this by:

  1. Identifying the asset's exchange timezone (e.g., NYSE vs. Tokyo SE vs. Crypto).
  2. Checking the exact market status relative to the server time.
  3. Automatically filtering out the current day's row if the market hasn't closed yet.
  4. Calculating the valid target_date (next trading day) for forecasting targets. It is usable for production (live deplyoment) needs when predicting for the upcoming day (with fetched training data till today).

🏆 Key Capabilities

Component Feature Details
Smart Ingestion Market-aware cleaning. Removes incomplete daily candles based on precise closing times (e.g., 16:20 ET for US Equities to account for delay).
Multi-Asset Native handling for various types. EQUITY (Stocks/ETFs), CRYPTOCURRENCY (24/7), FUTURES, FOREX, INDEX.
Forecasting Prep Target Date Calculation. Automatically computes the next valid business day (or calendar day for Crypto) for predictive labeling.
Resiliency Robust Error Handling. Wraps yfinance with retry logic and custom exceptions for better pipeline stability.

📦 Installation

pip install finfetcher

🚀 Usage

Basic Example

from finfetcher import DataFetcher

# Initialize for an asset (Equity)
fetcher = DataFetcher("AAPL")

# Fetch data (default: period="4y", interval="1d")
# This returns a pandas DataFrame with Date index
df = fetcher.get_data(period="1mo")

print(f"Data shape: {df.shape}")
print(f"Last available close: {df.index[-1]}")

# Access the calculated target date (next trading day)
print(f"Prediction Target Date: {fetcher.target_date}")

Handling Cryptocurrencies

Crypto markets never close, so the logic adjusts to use a 23:59 UTC cutoff.

crypto_fetcher = DataFetcher("BTC-USD")
df = crypto_fetcher.get_data(period="5d")

# Target date will be tomorrow (calendar day), not business day
print(f"Next Target: {crypto_fetcher.target_date}")

Custom Market Configuration

You can override default market hours or add new asset types by passing a custom_cutoffs dictionary.

from finfetcher import DataFetcher

# Example: Change US Equity close to 13:00 (e.g. half-day)
custom_config = {
    "EQUITY": {
        "timezones": {
            "America/New_York": {"hour": 13, "minute": 0}
        }
    }
}

fetcher = DataFetcher("AAPL", custom_cutoffs=custom_config)
df = fetcher.get_data()

🛠️ Logic Details

The library contains a set of configuration of market closing times (src/finfetcher/config.py) to handle timezone conversions accurately.

  • US Equities: Closes at 16:00 ET (buffered to 16:20 to handle API delays).
  • European Markets: Handled via specific timezones (London, Paris, Frankfurt, etc.).
  • Asian Markets: Tokyo, Hong Kong, Singapore, etc.
  • Crypto: UTC based cutoff.

💻 Tech Stack

  • Python 3.10+
  • Pandas & NumPy
  • yfinance
  • pytz

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

finfetcher-0.1.1.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

finfetcher-0.1.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file finfetcher-0.1.1.tar.gz.

File metadata

  • Download URL: finfetcher-0.1.1.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for finfetcher-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9f5579da2d6c1515824328434187754b90dd210a5129dd3c61ff654ac352c581
MD5 75414a1884766eac27a59b2ae3413c13
BLAKE2b-256 f7eb3f102050a1458c3710edf3b00d963c7bc981db0760084396be2c24027f23

See more details on using hashes here.

Provenance

The following attestation bundles were made for finfetcher-0.1.1.tar.gz:

Publisher: python-package.yml on eolybq/finfetcher

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file finfetcher-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: finfetcher-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for finfetcher-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 88ae2ff9f0ffef344da38f4086310275fff078cdc224b04b60465993fcdb3af9
MD5 fa0e8469dab286651e2b1ca14544b5c7
BLAKE2b-256 ba678f12040c471455f74a74afc0565c69020c042151c6b17d36fdaf66b5415a

See more details on using hashes here.

Provenance

The following attestation bundles were made for finfetcher-0.1.1-py3-none-any.whl:

Publisher: python-package.yml on eolybq/finfetcher

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page