# langchain-quantoracle

63 deterministic quant calculators + 10 composite workflows for LangChain agents. Options pricing, risk metrics, portfolio optimization, technical indicators, statistics, crypto/DeFi, FX/macro, strategy backtesting, rebalance planning, options strategy selection, hedging recommendations, and more.

> **Try the calculators in your browser:** the same engine powers 12 free interactive calculators at **[quantoracle.dev](https://quantoracle.dev)** — Black-Scholes, options profit, Monte Carlo, Kelly, Value at Risk, crypto liquidation, impermanent loss, CAGR, Sharpe, and more. Useful for quickly verifying outputs before wiring the API into an agent.

## Install

```bash
pip install langchain-quantoracle
```

## Usage

```python
from langchain_quantoracle import QuantOracleToolkit

# Load all tools (63 calculators + 10 composites)
tools = QuantOracleToolkit().get_tools()

# Or filter by category
tools = QuantOracleToolkit(categories=["options", "risk", "backtest"]).get_tools()

# Use with any LangChain agent
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate

llm = ChatOpenAI(model="gpt-4o")
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a quant analyst. Use QuantOracle tools for all financial math."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])

agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)
result = executor.invoke({"input": "Price a call option: spot 100, strike 105, 6 months, 20% vol"})
```

## Self-hosted

```python
tools = QuantOracleToolkit(api_url="http://localhost:8000").get_tools()
```

## Categories

`options`, `derivatives`, `risk`, `indicators`, `simulate`, `portfolio`, `fixed-income`, `fi`, `stats`, `crypto`, `fx`, `macro`, `tvm`, `trade`, `pairs`, `backtest`, `hedging`

## Paid endpoints (x402)

After 1,000 free calls/day, or for composite workflows (paid-only), payments are handled via x402 micropayments in USDC on **Base** or **Solana**. Any x402-compatible wallet (AgentCash, Coinbase AgentKit, etc.) works. The toolkit transparently forwards the `X-Source: langchain` header so traffic shows up correctly in usage metrics.

## Links

- API docs: https://api.quantoracle.dev/docs
- x402 discovery (Base + Solana): https://api.quantoracle.dev/.well-known/x402
- GitHub: https://github.com/QuantOracledev/quantoracle
- 1,000 free calls/day, no signup
