The problem in 30 seconds
# What you hope happens
response = llm.invoke("Price a European call: spot=100, strike=105, 6 months, 20% vol, 5% rate")
# "$4.58" ✓
# What actually happens in production
# - Price may land close, but drifts run-to-run
# - Delta/gamma/vega often reasonable; vanna, charm, speed, color frequently wrong
# - Anything that needs chained reasoning (IV solver, barrier options) degrades furtherThe math is deterministic. The model isn't. For anything agent-driven — backtests, risk management, paper trading, analysis pipelines — you need same-input-same-output calculations.
The fix: QuantOracle
QuantOracle is a REST API with 63 pure quant calculators plus 10 composite workflows (strategy backtests, portfolio rebalance plans, options strategy optimizers, hedging recommendations, full risk tearsheets). Every formula is citation-verified against Hull, Wilmott, and Bailey & López de Prado.
- 1,000 free calls/IP/day, no API key
- Paid tier uses x402 micropayments in USDC on Base or Solana ($0.002–$0.10/call)
- Deterministic: same inputs always produce the same outputs
- MCP server, LangChain toolkit, OpenAI GPT, and plain REST all supported
Hook it into LangChain in one line
pip install langchain-quantoracle langchain-openai langchainfrom langchain_quantoracle import QuantOracleToolkit
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate
# Load every QuantOracle tool — all 73 endpoints become LangChain tools
tools = QuantOracleToolkit().get_tools()
llm = ChatOpenAI(model="gpt-4o")
prompt = ChatPromptTemplate.from_messages([
("system", "You are a quant analyst. Use QuantOracle tools for all financial "
"math — never compute in-context."),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])
agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)That's it. Your agent now has Black-Scholes, 22 portfolio risk metrics, Kelly sizing, 13 technical indicators, Monte Carlo, strategy backtests, and 60+ others.
Example 1: price an option with Greeks
result = executor.invoke({
"input": "Price a European call with spot=100, strike=105, 6 months to expiry, "
"20% annualized vol, 5% risk-free. I want price, delta, gamma, vega, theta."
})The agent picks the right tool (options_price), calls it, and returns:
Price: $4.58
Greeks:
Delta: 0.4612
Gamma: 0.0281
Theta: -0.0211 (daily)
Vega: 0.2808These are the exact Black-Scholes values. Reproducible across runs.
Example 2: full risk analysis from a returns series
result = executor.invoke({
"input": "Here are daily returns: [0.01, -0.02, 0.03, 0.005, -0.01, 0.02, -0.015, "
"0.025, 0.01, -0.005, 0.015]. Give me a complete risk breakdown."
})The agent calls the risk_full-analysis composite (one API call that replaces seven individual ones) and returns:
Risk Tearsheet (11 periods):
Sharpe: 2.83
Sortino: 4.59
VaR (95%): -0.03
Max Drawdown: -0.03
Kelly leverage: 10.65x
Hurst: 0.50 (neutral — random walk)
CAGR: 122.98%Same inputs always produce the same output. No drift, no flaky Sharpe calculations.
Example 3: backtest a strategy
result = executor.invoke({
"input": "Backtest a 20/50 SMA crossover on this price series: [100, 101, 102, ...]. "
"Initial capital $10000, 5 bps commission."
})The agent calls backtest_strategy (a composite that replaces ~10 individual calls) and gets back Sharpe, Calmar, max drawdown, win rate, the trade list, the equity curve, and a buy-and-hold benchmark comparison.
Composites vs individual calculators vs batch
The toolkit exposes three tiers, each for a different situation:
- Individual calculators (
options_price,risk_portfolio,stats_hurst-exponent…) — fine-grained control, one concept per call. Free tier. - Composite workflows (
backtest_strategy,portfolio_rebalance-plan,hedging_recommend,risk_full-analysis…) — bundle 5–15 calculator calls into one round trip with a purpose-built output. Paid-only ($0.015–$0.10), but far cheaper and faster than hand-chaining the pieces. - Batch endpoint (
POST /v1/batch) — run up to 100 calculator calls in a single HTTP request. Ideal for parameter sweeps and walk-forward backtests. Price is the sum of the individual prices, no markup. See the batch deep-dive.
Rule of thumb: one calculation → individual calculator; a named workflow → composite; many small calculations at once → batch. A backtest run that would be 200 calls one at a time becomes 2 batch calls.
Filter by category to keep tool lists small
A common LangChain pitfall: 73 tools in the prompt confuses smaller models. Filter by category:
# Options-only agent
tools = QuantOracleToolkit(categories=["options", "derivatives"]).get_tools()
# Risk/portfolio-only agent
tools = QuantOracleToolkit(categories=["risk", "portfolio", "stats"]).get_tools()
# Crypto-focused agent
tools = QuantOracleToolkit(categories=["crypto", "simulate"]).get_tools()Past the free tier
After 1,000 calls/day per IP, the API returns HTTP 402 with x402 payment requirements. If you're using an x402-capable client (AgentCash, Coinbase AgentKit), payment is automatic — USDC on Base or Solana, $0.002–$0.10/call. Otherwise the toolkit raises an exception and you add a payment layer yourself.
Why this matters for agentic systems
When an agent makes 50 tool calls during a backtest, every calculation has to be right. An LLM that's 85% accurate on Black-Scholes doesn't produce a backtest — it produces noise. Moving all math to a deterministic calculator makes results reproducible, cacheable (memoize by input hash), auditable (replay any step), fast, and far cheaper than the equivalent LLM tokens.
This pattern — LLM for reasoning + deterministic APIs for compute — is the one thing that actually works for production agent systems. Pick it up before your agent starts taking real actions, not after.
Links
- API docs · overview
- langchain-quantoracle on PyPI
- MCP server:
npx quantoracle-mcp - GitHub
Free tier is generous, no signup, MIT licensed. If you're building an agent that touches financial math, try it before rolling your own.