LLM Integration
"You don't have to be smart to be a good fighter. You just have to be smart about who you fight." — paraphrased from Creed (2015)
Chapters 2 through 6 built a quantitative stack from the bottom up: returns, classical forecasting, optimal decisions, latent dynamics, deep dynamic factor models. By the end of Chapter 6 we have models that can forecast, allocate, filter latent state, and interrogate the why of what is happening — all expressed as numerical operations on tensors.
The next two chapters change the substrate, not the goal. Language models do not replace the forecaster, the policy, or the dynamic factor model; they wrap around them. The right framing for the LLM-integration chapter is what does adding language to this existing stack make easier, and the answer is roughly four things:
- Search. Retrieval-augmented generation (Section 7-02) turns a pile of filings, research notes, and policy statements into a queryable corpus. The numerical layer below it is unchanged.
- Code generation. Translating "build me a TFT-quantile forecaster
on this panel" into the right
pytorch_forecastinginvocation is a language task, and modern LLMs do it well. - Glue and orchestration. Chapter 8 wraps the LLM in a graph-of-tool-calls so analyses become reproducible workflows, not ad-hoc notebook sessions.
- Time-series itself. A 2024–2025 wave of foundation forecasters (Chronos, Lag-Llama, MOIRAI, TimesFM) shows that an LLM-style backbone pretrained on time-series tokens is a strong zero-shot competitor to the specialists of Section 4-05. We covered the practical side in Section 4-08; this chapter covers the integration side.
LLMs are not a free lunch. The remainder of this chapter is about where they genuinely earn their place — and the parts of the stack where the right answer is still a small, deterministic, well-tested model.
What this chapter does
We treat LLM integration as an engineering problem, not a research problem. The output of each section is a pattern you can ship: a prompt that survives production, a fine-tuned model with an evaluation suite that catches regressions, a foundation-model choice that survives the next vendor migration. Three through-lines:
- Use LLMs upstream of decisions, not as the decision-maker. They extract, summarise, and orchestrate. Numerical answers come from tools (Chapter 8); decisions come from policies (Chapter 5).
- Reprogram before fine-tuning. Most of the value lives in well- designed prompts, retrieval, and tool calls. Fine-tuning is for the last 20% that production needs but prompting cannot deliver.
- Stay vendor-neutral by construction. A thin adapter layer over provider APIs, a portable evaluation harness, and a graph-shaped agent (Chapter 8) make migration a config change, not a refactor.
This Chapter Covers
- Business case and limits. Where LLMs add the most leverage in finance, and three categories of task they should not be doing.
- Reprogramming patterns. RAG, structured prompting, tool grounding, and the time-series-as-tokens reprogramming family (Time-LLM, Time-LlaMA).
- Fine-tuning pipelines. Parameter-efficient methods (LoRA, QLoRA, MoELoRA), preference alignment with DPO, and when RL-style fine-tuning earns its budget.
- Foundation-model strategy. Build vs. buy, hybrid deployments, cost management, and the time-series-foundation-model family (Chronos, Lag-Llama, MOIRAI).
Contents
- Why LLM — what the literature and production evidence actually support, with the compliance constraints that shape integration.
- Reprogramming Approach — RAG, prompt patterns, and reprogramming for time-series forecasting.
- Fine-Tuning Approach — SFT, PEFT, DPO, and the data pipeline that makes the loop reproducible.
- Foundation Models — model selection, hybrid deployment, and the time-series-foundation-model branch that quietly competes with the language-model branch.
- Prompt Engineering for Finance — the practical prompt-craft layer: structured outputs, grounded citations, retrieved exemplars, critic-revise, and the evaluation harness that keeps prompt edits honest.