DEV Community

shashank ms
shashank ms

Posted on

Using LLM for Stock Prediction

Large language models have moved from chat interfaces into quantitative pipelines, where they parse earnings transcripts, SEC filings, and macro commentary to extract signals that traditional price-and-volume models miss. Stock prediction remains a high-noise domain, but LLMs excel at reasoning over unstructured text, identifying sentiment shifts, management tone changes, and hidden liabilities buried in footnotes. For developers building these pipelines, inference cost and context window size are often the limiting factors, especially when a single 10-K filing can span tens of thousands of tokens. Oxlo.ai is a relevant option here because its request-based pricing does not inflate with input length, and its model catalog includes long-context reasoning engines that can ingest entire documents in one shot.

Unstructured Data as Alpha

Most systematic strategies rely on structured data, but the majority of actionable information appears first in unstructured text. Earnings call transcripts, 8-K disclosures, and MD&A sections contain forward guidance and qualitative risk factors that do not fit neatly into a CSV. An LLM can act as a feature extractor, turning dense prose into structured signals such as sentiment scores, named entity relationships, and risk flags.

The following snippet sends a chunk of an SEC filing to an Oxlo.ai reasoning model and requests a JSON object with sentiment and rationale. Because Oxlo.ai is fully OpenAI SDK compatible, you can use the standard openai Python client with a single configuration change.

import os
import json
from openai import OpenAI

client = OpenAI(
    base_url="https://api.oxlo.ai/v1",
    api_key=os.environ["OXLO_API_KEY"]
)

filing_excerpt = """
Management's Discussion and Analysis: We experienced headwinds in Q3 due to
supply chain constraints in the APAC region. We expect margin compression to
persist through Q4.
"""

response = client.chat.completions.create(
    model="deepseek-r1-671b",  # DeepSeek R1 671B MoE
    messages=[
        {
            "role": "system",
            "content": (
                "You are a senior financial analyst. Read the excerpt and return "
                "a JSON object with keys: sentiment, confidence (0-1), rationale."
            )
        },
        {
            "role": "user",
            "content": f"SEC filing excerpt:\n{filing_excerpt}"
        }
    ],
    response_format={"type": "json_object"}
)

result = json.loads(response.choices[0].message.content)
print(json.dumps(result, indent=2))

Reasoning models such as DeepSeek R1 671B MoE or Kimi K2.6 are particularly useful for this task because they perform explicit chain-of-thought analysis before returning a conclusion, which reduces the likelihood of superficial answers on nuanced financial language.

Prompt Engineering and Structured Output

Financial NLP requires precision. A vague prompt yields vague features. To get repeatable, testable output, combine a detailed system prompt with JSON mode. Define the schema explicitly in the system message so the model returns machine-readable objects that your pipeline can ingest directly.

On token-based platforms, adding a long system prompt and a full 10-K filing as context linearly increases cost. On Oxlo.ai, the same request costs one flat fee regardless of whether you send two thousand tokens or two hundred thousand. This makes it practical to include entire documents, detailed few-shot examples, and multi-step reasoning instructions in every single call. For exact rates, see the Oxlo.ai pricing page.

system_prompt = """
You are a quantitative research assistant. Given an earnings call transcript,
return a JSON object with the following structure:
{
  "overall_sentiment": "bullish" | "bearish" | "neutral",
  "guidance_revisions": [{"metric": "revenue", "direction": "raised"}],
  "named_risks": ["regulatory scrutiny", "input cost inflation"],
  "analyst_tone": "cautiously optimistic"
}
Do not include commentary outside the JSON.
"""

transcript = """..."""  # Full transcript text

response = client.chat.completions.create(
    model="kimi-k2-6",  # Kimi K2.6
    messages=[
        {"role": "system", "content": system_prompt},
        {"role": "user", "content": f"Transcript:\n{transcript}"}
    ],
    response_format={"type": "json_object"}
)

features = json.loads(response.choices[0].message.content)

Using JSON mode enforces structure without fragile regex post-processing. If your downstream models expect categorical features, you can define enums directly in the prompt and validate the output with a lightweight JSON schema check.

Multi-Document Reasoning

Single-document sentiment is only the starting point. Alpha often appears in the delta: how does this quarter's risk disclosure compare to last quarter's? How does a supplier's 8-K read against your target's supply-chain dependency? Answering these questions requires passing multiple long documents into the context window simultaneously.

Oxlo.ai carries models such as DeepSeek V4 Flash, which supports a 1 million token context, and Kimi K2.6, which supports 131K tokens. With request-based pricing, comparing two full quarterly reports in one prompt does not trigger a proportional cost spike. The following example passes two filings to a long-context model and asks for a differential risk assessment.

q2_filing = "..."  # tens of thousands of tokens
q3_filing = "..."  # tens of thousands of tokens

diff_response = client.chat.completions.create(
    model="deepseek-v4-flash",  # DeepSeek V4 Flash
    messages=[
        {
            "role": "system",
            "content": (
                "Compare the two quarterly filings below. Identify new risks, "
                "removed risks, and any material change in tone. Return JSON."
            )
        },
        {
            "role": "user",
            "content": f"Q2 Filing:\n{q2_filing}\n\nQ3 Filing:\n{q3_filing}"
        }
    ],
    response_format={"type": "json_object"}
)

delta = json.loads(diff_response.choices[0].message.content)

This pattern is difficult to replicate with small-context models because it forces you to chunk, embed, and retrieve segments, which introduces synchronization errors and misses cross-document references that only appear when the full text is visible to the model.

Pipeline Architecture

A production financial inference pipeline typically follows three stages: ingestion, feature extraction, and signal persistence. Because Oxlo.ai offers no cold starts on popular models, you can run this pipeline on a schedule or in response to market events without latency penalties.

import json
from openai import OpenAI

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key=os.environ["OXLO_API_KEY"])

def extract_signal(headline: str, body: str, model: str = "deepseek-v3-2") -> dict:
    resp = client.chat.completions.create(
        model=model,  # DeepSeek V3.2
        messages=[{
            "role": "user",
            "content": (
                f"Headline: {headline}\n\nBody: {body}\n\n"
                "Classify the likely short-term market impact as Bullish, Bearish, or Neutral. "
                "Return JSON with keys: signal, confidence, entities_mentioned."
            )
        }],
        response_format={"type": "json_object"}
    )
    return json.loads(resp.choices[0].message.content)

# Scheduled or event-driven loop
for article in news_feed_stream():
    signal = extract_signal(article["headline"], article["body"])
    database.insert_signal(
        ticker=resolve_entities(signal["entities_mentioned"]),
        timestamp=article["published_at"],
        raw_feature=signal
    )

By keeping the client configuration identical to the OpenAI SDK spec, you can prototype locally and point the same code at Oxlo.ai in production without rewriting wrappers or custom authentication handlers.

Risks and Sanity Checks

LLMs are not predictive oracles. They are pattern completion engines trained on historical text, which means they can hallucinate statistics, misinterpret forward-looking statements as facts, and overweight recent training data. In financial time-series, regime changes render historical patterns useless, and lookahead bias can contaminate labels if you are not careful about publication timestamps versus market timestamps.

Treat LLM output as alpha-generating features, not trading decisions. Always backtest with point-in-time data, use out-of-sample validation, and overlay LLM signals with traditional risk controls. If you are comparing filings, verify that the model is not inventing section numbers or citing non-existent page references. A lightweight validation layer, such as forcing JSON mode and checking keys against a strict schema, catches a large class of formatting errors before they reach your portfolio construction logic.

Why Oxlo.ai for Financial Workloads

Finance is a long-context problem. A single earnings transcript, 10-K, or competitor analysis can dwarf the token budgets of typical chat use cases. Oxlo.ai's flat per-request pricing removes the penalty for sending full documents, which makes it significantly cheaper than token-based providers for this workload. You can run multi-document reasoning, chain-of-thought extraction, and few-shot classification without watching input tokens drive up your bill.

The platform offers 45-plus models across seven categories, including DeepSeek R1 671B MoE for deep reasoning, Kimi K2.6 for advanced coding and vision, and GLM 5 for long-horizon agentic tasks. All endpoints are OpenAI SDK compatible, so your existing Python or Node.js code works with a one-line base URL change. For teams evaluating cost, the Oxlo.ai pricing page breaks down the free, pro, and premium tiers, and the Enterprise plan offers dedicated GPUs with a guaranteed 30% savings over your current provider.

Conclusion

Using LLMs for stock prediction is less about asking for a price target and more about systematically extracting structured features from the deluge of unstructured financial text. The developers who build durable pipelines focus on context length, reasoning quality, and inference economics. Oxlo.ai fits naturally into this stack because its request-based pricing and long-context model catalog align with the demands of financial document analysis. Start with a free-tier prototype, enforce JSON output schemas, and always validate signals against out-of-sample market data before deploying capital.

Top comments (0)