Skip to main content
AIDevOps
  • Learn
  • Learning Paths
  • Practice
  • Open Source
  • Books
  • Engineering

    AI DevOpsThe full map of building and operating AI servicesLLMOpsLLM deployment Β· evaluation Β· observabilityHands-on ProjectsBuild AI Agent projects

    Knowledge

    DocsTechnical documentationBlogEngineering articlesPloggerDevelopment log feed

    Validate

    Certification3-level skills certification Β· coming soon
AI Models
LlamaTutorial|MistralTutorial|GemmaTutorial|DeepSeekTutorial|QwenTutorial
🧠 AI Agent Development
Finance AI AgentLLM API ServerStock Investing AgentAIOps AI AgentEducation AI AgentCoding AI Agent
πŸ€– AI Applied Development
Applied AI Intro & RoadmapHugging FaceLangChainLlamaIndexLLMOps|LangGraphMCPMulti-AgentAgent Evaluation
🧠 AI Core
AI Intro & RoadmapML FundamentalsLLM Fundamentals|Python AIC++|PyTorchTensorFlowJAX
🌱 Spring Cloud
Spring Intro & RoadmapSpring Cloud GatewaySpring BootJava|Spring AISpring SecuritySpring BatchSpring JPA
🐳 DevOps
DevOps Intro & RoadmapLinuxDockerCI/CD|Kubernetes BasicsK8s AdvancedPrometheusGrafana
🧱 Infrastructure
Infrastructure Intro & RoadmapNginxRedis
☁️ Cloud
Cloud Intro & RoadmapAWSGCPAzureNCPCloudflare
🎨 Frontend
Frontend Intro & RoadmapJavaScriptTypeScript|ReactNext.js|VueNuxt|Electron
πŸ“± Mobile
Mobile Intro & RoadmapKotlinAndroidFlutter
βš™οΈ Backend
Backend Intro & RoadmapPython BasicsFastAPIDjangoFlask|CGoGinNode.js
πŸ’Ύ Database
DB Intro & RoadmapCore SQLOracleMySQLPostgreSQL|MongoDBVector DB
πŸ§ͺ Testing
k6JMeternGrinder
AIDevOps

Engineering AI. From Code to Production.
An engineering learning platform for building and operating AI and AI Agents

Learn

  • All Guides
  • Learning Paths
  • AI Tutorial
  • Practice
  • Books

Resources

  • AI DevOps
  • LLMOps
  • Hands-on Projects
  • Docs
  • Blog
  • Plogger
  • Open Source
  • Certification (coming soon)

Start Here

  • AI Core Roadmap
  • AI Applied Development Roadmap
  • Spring Cloud Roadmap
  • DevOps Roadmap
  • Infrastructure Roadmap

Β 

  • Cloud Roadmap
  • Frontend Roadmap
  • Mobile Roadmap
  • Backend Roadmap
  • Database Roadmap
Β© 2026 AIDevOps. All rights reserved.
Terms of ServicePrivacy PolicySitemaptestforge.kr
Finance AI Agent 01

βš™οΈ Development Environment Setup Ollama + LangChain + Financial Data

Visitors

On a CPU-only machine with no CUDA (i7-12700H, 16GB RAM), run Llama 3.1 8B locally with Ollama and set up the full finance AI Agent stack through LangChain, FastAPI, yfinance, and pykrx.

← AI Agent series
βš™οΈ

Contents

0 / 10
  1. Hardware & model selection
  2. Install Ollama & pull models
  3. Python virtual environment
  4. Financial data libraries
  5. US stocks (yfinance)
  6. Korean stocks (pykrx)
  7. Getting a DART API key
  8. Connecting LangChain + Ollama
  9. FastAPI agent server
  10. Verification
Contents 10 sections
  1. Hardware & model selection
  2. Install Ollama & pull models
  3. Python virtual environment
  4. Financial data libraries
  5. US stocks (yfinance)
  6. Korean stocks (pykrx)
  7. Getting a DART API key
  8. Connecting LangChain + Ollama
  9. FastAPI agent server
  10. Verification

Hardware & model selection

This series is written against a laptop with the specs below.

ItemSpecImpact on AI inference
CPUIntel i7-12700H (14 cores/20 threads)Ideal for llama.cpp, parallel token generation
RAM16GB LPDDR5 6400MHzCan fully load an 8B Q4 model
GPUIntel Arc A370M 4GBNo CUDA β†’ CPU inference is used
StorageD: 519GB freePlenty of room for model files
ModelSize (Q4_K_M)RAM useSpeedUse
llama3.1:8b~5.0GB7GB~5 tok/sMain agent reasoning
phi3.5:mini~2.7GB4GB~15 tok/sFast classification and routing
qwen2.5:7b~4.8GB7GB~5 tok/sAnalysis of Korean-language filings
ℹ️

Claude API as backup: complex portfolio analysis and multi-agent orchestration call claude-sonnet-4-6 through the API. Local models and the API are mixed according to the task.

Install Ollama & pull models

Ollama is the simplest way to run GGUF quantized models on a CPU. After installing on Windows, run it from PowerShell.

BASH
# 1. Install Ollama (Windows)
# Download from https://ollama.com/download and install

# 2. Verify the install
ollama --version

# 3. Pull the main model (about 5GB β€” stored on the D drive)
ollama pull llama3.1:8b

# 4. Model that is strong at Korean, for DART filings (optional)
ollama pull qwen2.5:7b

# 5. Small model for fast routing
ollama pull phi3.5:mini

# 6. List installed models
ollama list
BASH
# Start the Ollama server (separate terminal)
ollama serve
# β†’ serves an OpenAI-compatible API at http://localhost:11434

# Smoke test
curl http://localhost:11434/api/generate -d '{
  "model": "llama3.1:8b",
  "prompt": "Give three reasons why the Samsung Electronics share price is rising.",
  "stream": false
}'
πŸ’‘

Changing where models are stored: the default path is C:\Users\[user]\.ollama. To move it to the D drive, set the environment variable OLLAMA_MODELS=D:\ollama-models.

Python virtual environment

BASH
# Create the project folder
mkdir D:\ai-agent-finance
cd D:\ai-agent-finance

# Create the virtual environment (Python 3.13)
python -m venv venv
.\venv\Scripts\activate

# Install packages
pip install --upgrade pip
requirements.txtTEXT
# LangChain core
langchain==0.3.25
langchain-community==0.3.25
langchain-ollama==0.3.3
langchain-anthropic==0.3.15
langgraph==0.4.8

# Web server
fastapi==0.115.12
uvicorn[standard]==0.34.3
python-dotenv==1.1.0
pydantic==2.11.5

# Financial data
yfinance==0.2.61
pykrx==1.0.48
pandas==2.2.3
pandas-ta==0.3.14b0

# RAG / vector DB
chromadb==1.0.12
sentence-transformers==3.4.1

# Utilities
requests==2.32.3
beautifulsoup4==4.13.4
httpx==0.28.1
BASH
pip install -r requirements.txt

# Anthropic SDK (Claude API)
pip install anthropic

Financial data libraries

US stocks β€” yfinance

A library wrapping the Yahoo Finance API that fetches US stock, ETF, and index data for free.

test_yfinance.pyPYTHON
import yfinance as yf
import pandas as pd

# Single ticker
ticker = yf.Ticker("AAPL")

# Basic info
info = ticker.info
print(f"Company: {info.get('longName')}")
print(f"Price: ${info.get('currentPrice')}")
print(f"Market cap: ${info.get('marketCap'):,}")
print(f"PER: {info.get('trailingPE'):.2f}")

# 6 months of daily bars
hist = ticker.history(period="6mo")
print(hist[['Open', 'High', 'Low', 'Close', 'Volume']].tail())

# Several tickers at once
tickers = yf.download(["AAPL", "MSFT", "NVDA", "GOOGL"], period="1mo")
print(tickers['Close'].tail())

# Indexes
sp500 = yf.Ticker("^GSPC")   # S&P 500
nasdaq = yf.Ticker("^IXIC")  # NASDAQ
print(f"S&P500: ${sp500.info.get('regularMarketPrice')}")

Korean stocks β€” pykrx

Query Korea Exchange (KRX) data from Python. No API key is required.

test_pykrx.pyPYTHON
from pykrx import stock
from pykrx import bond
import pandas as pd
from datetime import datetime, timedelta

today = datetime.today().strftime("%Y%m%d")
yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y%m%d")

# Look up the stock name by code
name = stock.get_market_ticker_name("005930")
print(f"005930 = {name}")  # Samsung Electronics

# Samsung Electronics OHLCV for the last 30 days
df = stock.get_market_ohlcv_by_date("20250101", today, "005930")
print(df.tail())

# Quotes for every KOSPI stock
kospi = stock.get_market_ohlcv_by_ticker(today, market="KOSPI")
print(f"KOSPI stocks: {len(kospi)}")
print(kospi.sort_values("κ±°λž˜λŸ‰", ascending=False).head(5))

# Market index
index_df = stock.get_index_ohlcv_by_date("20250101", today, "1001")  # KOSPI
print(index_df.tail())

# Top stocks by foreign net buying
foreigner = stock.get_market_net_purchases_of_equities_by_ticker(
    today, today, "KOSPI", "외ꡭ인"
)
print(foreigner.head(10))
⚠️

pykrx caveat: the data for the day is updated after the market close (after 4 PM KST). It provides closing-price data, not real-time trade prices. Its DataFrame columns and some arguments are Korean strings, so they are kept as-is in the code.

Getting a DART API key (Korean filings)

Get a free API key from DART, run by the Korean Financial Supervisory Service, to collect filing data.

BASH
# 1. Sign up at https://opendart.fss.or.kr
# 2. Apply for the API β†’ the key is issued immediately
# 3. Save it in the .env file
.envBASH
DART_API_KEY=your_dart_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here
OLLAMA_BASE_URL=http://localhost:11434
test_dart.pyPYTHON
import requests
import os
from dotenv import load_dotenv

load_dotenv()
DART_KEY = os.getenv("DART_API_KEY")

def get_company_info(corp_name: str) -> dict:
    """Look up the DART corp code by company name"""
    url = "https://opendart.fss.or.kr/api/company.json"
    params = {"crtfc_key": DART_KEY, "corp_name": corp_name}
    res = requests.get(url, params=params)
    return res.json()

def get_disclosures(corp_code: str, days: int = 30) -> list:
    """List recent filings"""
    from datetime import datetime, timedelta
    bgn = (datetime.today() - timedelta(days=days)).strftime("%Y%m%d")
    url = "https://opendart.fss.or.kr/api/list.json"
    params = {
        "crtfc_key": DART_KEY,
        "corp_code": corp_code,
        "bgn_de": bgn,
        "sort": "date",
        "sort_mth": "desc",
    }
    return requests.get(url, params=params).json().get("list", [])

# Test
company = get_company_info("μ‚Όμ„±μ „μž")  # Samsung Electronics β€” DART is searched by Korean company name
print(company)

Connecting LangChain + Ollama

llm_setup.pyPYTHON
from langchain_ollama import ChatOllama
from langchain_anthropic import ChatAnthropic
from langchain_core.messages import HumanMessage, SystemMessage
import os
from dotenv import load_dotenv

load_dotenv()

# Local Ollama model (free, CPU inference)
local_llm = ChatOllama(
    model="llama3.1:8b",
    base_url="http://localhost:11434",
    temperature=0,          # financial analysis: reproducibility first
    num_predict=2048,       # maximum output tokens
)

# Claude API (for complex analysis)
claude_llm = ChatAnthropic(
    model="claude-sonnet-4-6",
    api_key=os.getenv("ANTHROPIC_API_KEY"),
    temperature=0,
    max_tokens=4096,
)

def ask_local(question: str, system: str = "") -> str:
    messages = []
    if system:
        messages.append(SystemMessage(content=system))
    messages.append(HumanMessage(content=question))
    return local_llm.invoke(messages).content

def ask_claude(question: str, system: str = "") -> str:
    messages = []
    if system:
        messages.append(SystemMessage(content=system))
    messages.append(HumanMessage(content=question))
    return claude_llm.invoke(messages).content

# Test
if __name__ == "__main__":
    print("=== Ollama (local) ===")
    print(ask_local("What are the three key factors that move the NVIDIA share price?"))

    print("\n=== Claude (API) ===")
    print(ask_claude("Analyze the risks of the Samsung Electronics semiconductor business."))

FastAPI agent server

main.pyPYTHON
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from llm_setup import ask_local

app = FastAPI(title="Finance AI Agent API", version="1.0.0")

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
)

class QueryRequest(BaseModel):
    question: str
    model: str = "local"   # "local" | "claude"

class QueryResponse(BaseModel):
    answer: str
    model_used: str

@app.get("/health")
async def health():
    return {"status": "ok"}

@app.post("/ask", response_model=QueryResponse)
async def ask(req: QueryRequest):
    if req.model == "claude":
        from llm_setup import ask_claude
        answer = ask_claude(req.question)
    else:
        answer = ask_local(req.question)
    return QueryResponse(answer=answer, model_used=req.model)
BASH
# Start the server
uvicorn main:app --reload --port 8000

# Test the API
curl -X POST http://localhost:8000/ask \
  -H "Content-Type: application/json" \
  -d '{"question": "What is the current P/E of Apple stock?"}'

# Swagger UI
# http://localhost:8000/docs

Verification

verify_all.pyPYTHON
"""Verification script for the whole environment"""
import sys

def check(label, fn):
    try:
        fn()
        print(f"  βœ“ {label}")
    except Exception as e:
        print(f"  βœ— {label}: {e}")
        sys.exit(1)

print("=== Finance AI Agent environment check ===\n")

# 1. Ollama
def test_ollama():
    import requests
    r = requests.get("http://localhost:11434/api/tags")
    assert r.status_code == 200
    models = [m["name"] for m in r.json().get("models", [])]
    assert any("llama3.1" in m for m in models), f"llama3.1 model missing: {models}"
check("Ollama + llama3.1:8b", test_ollama)

# 2. yfinance
def test_yfinance():
    import yfinance as yf
    t = yf.Ticker("AAPL")
    assert t.info.get("currentPrice") is not None
check("yfinance (US stocks)", test_yfinance)

# 3. pykrx
def test_pykrx():
    from pykrx import stock
    from datetime import datetime, timedelta
    d = (datetime.today() - timedelta(days=3)).strftime("%Y%m%d")
    df = stock.get_market_ohlcv_by_date(d, d, "005930")
    assert not df.empty
check("pykrx (Korean stocks)", test_pykrx)

# 4. DART API
def test_dart():
    import requests, os
    from dotenv import load_dotenv
    load_dotenv()
    key = os.getenv("DART_API_KEY", "")
    assert key, "DART_API_KEY is not set"
    r = requests.get(f"https://opendart.fss.or.kr/api/company.json",
                     params={"crtfc_key": key, "corp_name": "μ‚Όμ„±μ „μž"})
    assert r.status_code == 200
check("DART API", test_dart)

# 5. LangChain + Ollama
def test_langchain():
    from llm_setup import ask_local
    ans = ask_local("1+1=?")
    assert len(ans) > 0
check("LangChain + Ollama", test_langchain)

# 6. ChromaDB
def test_chroma():
    import chromadb
    client = chromadb.Client()
    col = client.create_collection("test")
    col.add(documents=["test doc"], ids=["1"])
    assert col.count() == 1
check("ChromaDB", test_chroma)

print("\nβœ… All checks passed. Move on to 02 Market Data Agent.")
BASH
# Run the check (the Ollama server must be running)
python verify_all.py

# Expected output:
# === Finance AI Agent environment check ===
#   βœ“ Ollama + llama3.1:8b
#   βœ“ yfinance (US stocks)
#   βœ“ pykrx (Korean stocks)
#   βœ“ DART API
#   βœ“ LangChain + Ollama
#   βœ“ ChromaDB
# βœ… All checks passed.