Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AI4Finance Foundation FinGPT prepare data for symbol

From Leeroopedia
Knowledge Sources
Domains Finance, Data_Acquisition
Last Updated 2026-10-18 00:00 GMT

Overview

Concrete tool for acquiring per-symbol financial market data (prices, news, fundamentals) provided by the FinGPT Forecaster data pipeline.

Description

The prepare_data_for_symbol function is the primary entry point for building the Forecaster training dataset. It orchestrates three data acquisition steps: (1) fetching weekly stock price data with returns and bin labels via yfinance, (2) fetching company news via Finnhub, and (3) optionally fetching quarterly basic financials via Finnhub and enriching with Adanos market sentiment. The result is saved to a per-symbol CSV file.

Usage

Import this function when you need to build the raw data CSV for a single ticker symbol:

  • Forecaster training data preparation: Building the per-symbol data files before GPT-4 label distillation.
  • Custom dataset construction: Acquiring market data for any supported ticker (US stocks, crypto).

Code Reference

Source Location

  • Repository: FinGPT
  • File: fingpt/FinGPT_Forecaster/data.py
  • Lines: L119-153 (main function), L29-117 (helpers: get_returns, get_news, get_basics)

Signature

def prepare_data_for_symbol(
    symbol: str,
    data_dir: str,
    start_date: str,
    end_date: str,
    with_basics: bool = True,
    with_market_sentiment: bool = False,
) -> pd.DataFrame

Import

from data import prepare_data_for_symbol

I/O Contract

Inputs

Name Type Required Description
symbol str Yes Ticker symbol (e.g., "AAPL", "BTC-USD")
data_dir str Yes Output directory for the CSV file
start_date str Yes Start date in YYYY-MM-DD format
end_date str Yes End date in YYYY-MM-DD format
with_basics bool No Include Finnhub quarterly basic financials (default True)
with_market_sentiment bool No Enrich with Adanos market sentiment (default False)

Outputs

Name Type Description
return value pd.DataFrame Weekly data with Start Date, End Date, Start Price, End Price, Weekly Returns, Bin Label, News, Basics (+ optional MarketSentiment)
CSV file file Per-symbol CSV written to data_dir via dataset_csv_path()

Usage Examples

Basic Data Acquisition

import os
os.environ["FINNHUB_KEY"] = "your_finnhub_key"

from data import prepare_data_for_symbol

# Acquire AAPL data with basics for 2023
data = prepare_data_for_symbol(
    symbol="AAPL",
    data_dir="./data",
    start_date="2023-01-01",
    end_date="2023-12-31",
    with_basics=True,
)
print(data.columns.tolist())
# ['Start Date', 'End Date', 'Start Price', 'End Price',
#  'Weekly Returns', 'Bin Label', 'News', 'Basics']

With Market Sentiment Enrichment

from data import prepare_data_for_symbol

# Acquire data with Adanos market sentiment
data = prepare_data_for_symbol(
    symbol="AAPL",
    data_dir="./data",
    start_date="2023-01-01",
    end_date="2023-12-31",
    with_basics=True,
    with_market_sentiment=True,  # Requires ADANOS_API_KEY
)
# data now includes a 'MarketSentiment' column

Related Pages

Implements Principle

Uses Heuristic

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment