---
name: pymc-markets-836d87604c59
description: "Bayesian inference for financial markets using PyMC. Stochastic volatility models, regime-switching, Bayesian portfolio optimization, factor models, and Markov chain Monte Carlo for risk estimation."
tags: [bayesian, pymc, stochastic-volatility, portfolio-optimization, risk, markets, zorai]
---
## Overview

PyMC provides Bayesian inference for financial modeling: stochastic volatility, regime-switching, Bayesian portfolio optimization, factor models, and MCMC risk estimation using the NUTS sampler. ArviZ provides diagnostics and visualization.

## Installation

```bash
uv pip install pymc arviz
```

## Stochastic Volatility Model

```python
import pymc as pm
import numpy as np
import arviz as az

# Simulated daily returns
returns = np.random.randn(500) * 0.02

with pm.Model() as sv_model:
    sigma = pm.InverseGamma("sigma", alpha=2, beta=1)
    log_vol = pm.GaussianRandomWalk("log_vol", sigma=sigma, shape=len(returns))
    obs = pm.Normal("returns", mu=0, sigma=pm.math.exp(log_vol / 2), observed=returns)
    trace = pm.sample(1000, tune=1000, chains=4)

print(az.summary(trace, var_names=["sigma"]))
az.plot_trace(trace)
```

## References
- [PyMC docs](https://www.pymc.io/)
- [Bayesian Methods for Hackers](https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers)

---
Source attribution: mkurman
Original project: https://github.com/mkurman/zorai/blob/d06ee7597049567dab92db22d41b2764cf89094a/skills/scientific-skills/pymc-markets/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 zorai contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: mkurman
Original project: https://github.com/mkurman/zorai/blob/d06ee7597049567dab92db22d41b2764cf89094a/skills/scientific-skills/pymc-markets/SKILL.md
Attribution basis: Source repository record

Fields of work: Data & Analytics, Development & Engineering, Finance & Accounting, Marketing, Product Management
Roles: Data Scientist, Financial Analyst, Growth Marketer, ML / AI Engineer, Product Manager
Specialties: API, Backend
Tools: Arviz, Pymc
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: b75060787854fdfd0710a60d59b971101595116fe41bc72f55c222f2c804e640
