CodeCast: Context-Conditional Code Generation for Multimodal Time Series Forecasting
Abstract
LLM-generated code recently serves as an effective reasoning medium beyond software engineering, from solving mathematical problems to scientific discovery. We extend this paradigm to multimodal time series forecasting, where textual context (financial news, clinical notes, event reports) carries predictive signals that time series foundation models cannot access due to their purely numerical interface. We present CodeCast, a framework in which a small, open-weight LLM generates an executable program that incorporates textual context into time series predictions. Given a time series, its statistical profile, and associated text, CodeCast produces code that converts context into relevant time series or applies post-processing transformations on top of a pretrained forecaster, preserving numerical precision and providing an interpretable reasoning trace that reveals how context was grounded into numerical adjustments. We train on real time series paired with LLM-generated synthetic context that explains future trends, and optimize the code generation policy with GRPO using a ranking-based execution reward that compares program outputs against eight baseline forecasters. On three multimodal forecasting benchmarks, CodeCast consistently outperforms the base forecaster, showing that even a small open-weight model can effectively leverage textual context for scientific prediction through RL-trained code generation.