Principle:AI4Finance Foundation FinGPT Prompt Engineering
| Knowledge Sources | |
|---|---|
| Domains | NLP, Prompt_Engineering, Finance |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
The design of structured input prompts that combine company context, historical news, financials, and task instructions to elicit targeted analytical responses from large language models.
Description
Prompt engineering for financial LLMs involves assembling multi-part prompts that provide the model with sufficient context to perform financial analysis. A well-constructed financial prompt includes: (1) a company introduction with profile data, (2) historical price movements with weekly returns, (3) sampled news headlines and summaries from a lookback window, (4) optional basic financials, (5) optional market sentiment, and (6) a task instruction specifying the expected output format.
The Llama-2 chat template wraps the prompt with `[INST]<<SYS>>system_prompt<</SYS>>user_prompt[/INST]` tags, providing role separation between system instructions and user queries. The system prompt defines the model's persona as a "seasoned stock market analyst" and specifies the required output format.
Usage
Use this principle when:
- Constructing training prompts: Building prompts from historical data with known outcomes for supervised fine-tuning.
- Constructing inference prompts: Building live prompts from current market data for real-time predictions.
- Designing context windows: Selecting how many weeks of historical news to include and how to sample within them.
The quality of the prompt directly determines the quality of the model's output—missing context or poorly structured instructions lead to degraded analysis.
Theoretical Basis
Prompt engineering leverages in-context learning, where the model uses information provided in the prompt to guide its generation without parameter updates. The effectiveness depends on:
- Context relevance: News and financials must be temporally aligned to the prediction window.
- Information density: Sampling 5 news items per week balances coverage with prompt length.
- Instruction clarity: Explicit output format specification reduces unstructured responses.
- Sliding window context: Using 1-3 weeks of past data provides trend context without overwhelming the model.
Key design decisions:
# Abstract: prompt structure for financial analysis
prompt = company_intro + "\n"
for week in lookback_window:
prompt += price_movement(week) + "\n"
prompt += sampled_news(week, k=5) + "\n"
prompt += basics_block + "\n"
prompt += instruction_block # "analyze positive developments..."
Practical Guide
- Use the Llama-2 chat template (`[INST]<<SYS>>...<</SYS>>...[/INST]`) for chat models.
- Sample at most 5 news items per week to control prompt length.
- Include the prediction target in training prompts (for teacher-forcing) but remove it for inference.
- Strip boilerplate news summaries that start with "Looking for stock market analysis..." to reduce noise.
- The `min_past_weeks` and `max_past_weeks` parameters control the lookback window size.