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 construct prompt

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

Overview

Concrete tool for constructing live inference prompts from current market data provided by the FinGPT Forecaster Gradio app.

Description

The construct_prompt function is the end-to-end inference prompt builder. It: (1) resolves the ticker symbol via `resolve_symbol`, (2) computes weekly date boundaries, (3) fetches stock data via yfinance, (4) fetches company news via Finnhub, (5) optionally enriches with market sentiment, (6) constructs the prompt via `get_all_prompts_online`, and (7) wraps the prompt with the Llama-2 chat template (`[INST]<<SYS>>...<</SYS>>...[/INST]`).

Returns a tuple of `(info, prompt)` where `info` is the unformatted context for display and `prompt` is the Llama-2-formatted prompt for model input.

Usage

Import this function when you need to build a complete inference prompt from live data:

  • Forecaster inference: Building the prompt for the `predict` function.
  • Custom inference: Building prompts for any ticker, date, and market.

Code Reference

Source Location

  • Repository: FinGPT
  • File: fingpt/FinGPT_Forecaster/app.py
  • Lines: L248-269 (construct_prompt), L208-245 (get_all_prompts_online)

Signature

def construct_prompt(
    ticker: str,
    curday: str,
    n_weeks: int,
    use_basics: bool,
    use_market_sentiment: bool,
    market: str = "US",
) -> tuple[str, str]

Import

from app import construct_prompt

I/O Contract

Inputs

Name Type Required Description
ticker str Yes User ticker (e.g., "AAPL", "RELIANCE")
curday str Yes Current date YYYY-MM-DD
n_weeks int Yes Lookback weeks (1-4)
use_basics bool Yes Include latest quarterly financials
use_market_sentiment bool Yes Include market sentiment block
market str No Market type (default "US")

Outputs

Name Type Description
return value tuple[str, str] (info, prompt) - info for display, prompt for model

Usage Examples

Build Inference Prompt

from app import construct_prompt

info, prompt = construct_prompt(
    ticker="AAPL",
    curday="2024-01-15",
    n_weeks=3,
    use_basics=True,
    use_market_sentiment=False,
    market="US",
)
# prompt is wrapped with [INST]<<SYS>>...<</SYS>>...[/INST]

Related Pages

Implements Principle

Requires Environment

Page Connections

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