Skip to content

bhanukaranwal/AgroFuturesSim

Repository files navigation

📈 AgroFuturesSim

AgroFuturesSim is a production-grade financial simulation platform for Argentina’s soybean futures market.
It integrates Hyperledger Fabric blockchain data with advanced stochastic volatility modeling (Heston model) to run large-scale Monte Carlo simulations, produce risk analytics (VaR, CVaR, stress tests), and generate publication-ready reports with Matplotlib-powered charts.


🌟 Features

  • 🔐 Blockchain Integration (Hyperledger Fabric)

    • Securely fetches verified soybean futures trades
    • Ensures traceability & auditability with on-chain data validation
  • 🧠 Financial Modeling

    • Implements Heston stochastic volatility model
    • Calibrated against historical / implied volatilities
  • Simulation Engine

    • Monte Carlo (local + distributed with Ray/Dask)
    • Checkpointing for long simulations
  • 📊 Risk Analytics

    • Value at Risk (VaR)
    • Conditional VaR (CVaR)
    • Extreme stress testing scenarios
  • 📑 Automated Reporting

    • Multi-page PDF reports (tables, charts, logs)
    • Excel summary sheets
    • Blockchain provenance metadata for compliance
  • 🌐 API + CLI

    • FastAPI RESTful endpoints for programmatic workflows
    • Click-based CLI for command-line interaction
  • 🛡️ Monitoring & Logging

    • Centralized logging with rotation
    • Prometheus metrics for calibration & simulation progress

🏗️ Architecture Overview

          ┌───────────────────────┐
          │   Blockchain Layer    │ 🔐 Hyperledger Fabric
          └──────────┬────────────┘
                     │
          ┌──────────▼────────────┐
          │   Data Processing     │ ✨ Cleaning, Transform, Cache
          └──────────┬────────────┘
                     │
          ┌──────────▼────────────┐
          │    Modeling Layer     │ 📈 Heston Model + Calibration
          └──────────┬────────────┘
                     │
          ┌──────────▼────────────┐
          │   Monte Carlo Engine  │ 🎲 Local & Distributed
          └──────────┬────────────┘
                     │
          ┌──────────▼────────────┐
          │   Risk Analytics      │ 📊 VaR, CVaR, Stress Testing
          └──────────┬────────────┘
                     │
          ┌──────────▼────────────┐
          │ Visualization/Reports │ 📑 Matplotlib + PDF
          └───────────────────────┘

📊 Example Visualization (Matplotlib)

Simulated price paths under calibrated Heston model:

import matplotlib.pyplot as plt
import numpy as np

time = np.linspace(0, 1, 252)
plt.figure(figsize=(10,6))
for i in range(10):
    plt.plot(time, np.cumprod(1 + 0.01*np.random.randn(len(time))), lw=1.2)
plt.title("Simulated Soybean Futures Price Paths")
plt.xlabel("Time (Years)")
plt.ylabel("Price")
plt.grid(True)
plt.show()

📌 Example output:

Price Paths


🚀 Quick Start

🔧 Installation

git clone https://github.com/your-org/AgroFuturesSim.git
cd AgroFuturesSim
pip install -r requirements.txt

🖥️ CLI Usage

Fetch blockchain data:

python -m AgroFuturesSim.cli.main fetch-blockchain

Calibrate the Heston model:

python -m AgroFuturesSim.cli.main calibrate-model --config config/default.yaml

Run Monte Carlo simulations:

python -m AgroFuturesSim.cli.main simulate --config config/default.yaml

Generate PDF report:

python -m AgroFuturesSim.cli.main report --output soybean_report.pdf

🌐 API Usage

Start FastAPI server:

uvicorn AgroFuturesSim.api.server:app --reload --host 0.0.0.0 --port 8000

Check system health:

curl http://localhost:8000/health

Calibrate, simulate, and fetch reports via REST endpoints.


📈 Risk Analytics Example

Histogram of simulated futures prices:

import matplotlib.pyplot as plt
import numpy as np

plt.figure(figsize=(8,5))
prices = np.random.normal(100, 20, 10000)
plt.hist(prices, bins=50, density=True, alpha=0.7, color="steelblue")
plt.axvline(np.percentile(prices, 5), color="red", linestyle="--", label="VaR (5%)")
plt.title("Monte Carlo Distribution of Soybean Futures")
plt.xlabel("Final Price")
plt.ylabel("Density")
plt.legend()
plt.show()

🐳 Docker

Build and run:

docker build -t agrofuturessim .
docker run -p 8000:8000 agrofuturessim

✅ Testing

Run unit + integration tests:

pytest -v --maxfail=1 --disable-warnings

🔮 Roadmap

  • Multi-asset Heston model (soybean + corn futures)
  • Advanced portfolio optimization under Monte Carlo scenarios
  • Real-time ML-based volatility calibration
  • Interactive analytics dashboard (Plotly Dash / Streamlit)

👨‍💻 Authors

Developed by Bhanu Karnwal 🚀


📜 License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.


About

AgroFuturesSim is a Python platform that uses blockchain data and Heston modeling to simulate soybean futures, run Monte Carlo analyses, and deliver risk insights with visual reports.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages