Logo
FrontierNews.ai

How One Developer Built a Stock Analyst AI That Never Sends Data to the Cloud

A software engineer has demonstrated that building sophisticated AI investment tools no longer requires expensive cloud services or third-party APIs. Using Ollama, a local large language model (LLM) framework, combined with open-source models and financial data sources, the developer created a complete stock analysis system that runs entirely on a laptop, generating detailed five-year investment theses without sending sensitive portfolio data anywhere.

The project addresses a real pain point in AI-powered investing. Most commercial investment tools charge per query, route portfolio data to external servers, and provide conclusions without transparency about how they arrived at their recommendations. This approach creates three problems: recurring costs that add up quickly, privacy concerns about sensitive financial information, and a black-box experience that makes it hard to trust the analysis.

Why Local AI for Financial Analysis Matters?

The shift toward local AI models is reshaping how developers approach sensitive applications. Traditional cloud-based AI services charge per token, meaning complex multi-step reasoning tasks become expensive fast. A typical investment analysis might involve dozens of tool calls, each adding to the bill. By running everything locally, the developer eliminated per-token billing entirely while keeping complete control over data.

The system uses LangChain, an open-source framework for building AI agents, paired with Qwen3, a 14-billion-parameter open-source model optimized for reasoning tasks. The developer noted that "the entire analysis pipeline runs locally using open-source models. No per-token billing. No rate limits. No data leaving your machine". For users with less powerful hardware, alternatives like Llama 3 and Mistral work equally well.

How to Build a Local Investment Research Agent

  • Gather Deterministic Financial Data: Start with APIs like yfinance to pull hard numbers on revenue growth, free cash flow, operating margins, return on equity, and debt-to-equity ratios. These metrics form the factual foundation that prevents the AI from hallucinating financial claims.
  • Break Complex Reasoning Into Stages: Instead of asking the model to analyze everything at once, split the problem into smaller tasks. The developer separated financial analysis, news sentiment evaluation, industry outlook assessment, and valuation modeling into distinct reasoning steps, which dramatically improved output quality and reduced errors.
  • Integrate Real-Time News and Context: Use a search API like Tavily to pull recent earnings reports, product launches, competitive threats, and regulatory developments. This enriches the analysis beyond historical fundamentals and captures what's actually happening in the market.
  • Generate Multiple Scenarios Instead of Single Predictions: Rather than producing one price target, the system explores bull, base, and bear cases with different revenue growth assumptions, margin expectations, and valuation multiples. This probabilistic approach acknowledges uncertainty instead of pretending false certainty exists.
  • Validate All Calculations Outside the LLM: Never ask the model to do arithmetic. If the analysis references a specific number, that value must come from an API call or calculation function. The LLM's job is reasoning and synthesis, not math.

The architecture consists of five layers working together. A user query like "Analyze Apple" triggers a LangChain agent that decides which tools to call, what information is still missing, and how to combine retrieved data. The agent pulls financial metrics from yfinance, news sentiment from Tavily, macroeconomic context from FRED (the Federal Reserve's data service), and industry analysis from its own reasoning layer. All of this feeds into the local LLM, which synthesizes everything into a structured investment thesis.

The most critical insight from this project is how to prevent hallucinations in financial AI. The developer explained that "the LLM's job is reasoning and synthesis, not arithmetic." By anchoring every factual claim to an external data source, the system avoids the common problem where language models confidently state false numbers. If the model references a company's revenue growth, that figure comes from an actual API call, not from the model's training data.

What Does a Real Output Look Like?

When asked to analyze a company like NVIDIA, the system produces a structured report that includes an overall rating, bull case and base case revenue growth projections, key catalysts that could drive the thesis, and primary risks that could derail it. The report shows specific percentages, identifies concrete catalysts like AI infrastructure growth and data center expansion, and acknowledges real risks like export restrictions and AMD competition.

The valuation component uses a discounted cash flow model that runs across all three scenarios, producing a valuation band rather than a misleading single price target. This approach reflects how professional investors actually think about uncertainty. A company might be worth $150 to $250 per share depending on which scenario plays out, and the analysis shows the reasoning behind each range.

The developer's next planned improvements include building a supervisor agent that can combine multiple single-stock analyses into a portfolio-level thesis, and adding retrieval capabilities over primary sources like SEC filings, annual reports, and earnings transcripts. This would let the agent reason directly from company disclosures rather than relying only on APIs and news summaries.

The broader significance is that institutional-quality financial analysis is no longer locked behind expensive subscriptions or proprietary systems. Wall Street has used algorithmic research systems for decades, but today a laptop running open-source models can synthesize financial statements, industry trends, news sentiment, and valuation frameworks into coherent investment theses. The complete project uses LangChain, Ollama, local open-source LLMs, financial APIs, and scenario-based valuation techniques, all running on commodity hardware without sending a single token outside the machine.