← Back to all products

Portfolio Analytics

$10

Analyze index portfolio metrics — volatility, correlation, Sharpe ratio, and sector exposure.

📁 17 files
TOMLPythonMarkdownYAML

📁 File Structure 17 files

portfolio-analytics/ ├── LICENSE ├── README.md ├── config/ │ ├── default.yaml │ └── sample_portfolio.yaml ├── examples/ │ └── basic_usage.py ├── pyproject.toml ├── requirements.txt ├── security-notes.md ├── src/ │ ├── __init__.py │ ├── attribution.py │ ├── data_fetcher.py │ ├── engine.py │ ├── metrics.py │ └── report.py └── tests/ ├── __init__.py ├── test_engine.py └── test_metrics.py

📖 Documentation Preview README excerpt

portfolio-analytics

Performance attribution, risk metrics, and reporting for tokenized index portfolios.

Part of the CryptoForge Index Lab toolkit.

Features

  • Risk Metrics: Sharpe ratio, Sortino ratio, max drawdown, Calmar ratio, VaR, information ratio
  • Performance Attribution: Brinson-Fachler decomposition (allocation, selection, interaction effects)
  • Report Generation: HTML, JSON, and CSV output with CryptoForge dark theme
  • Mock Data: Deterministic GBM price simulation for 15+ tokens (no API key needed)
  • Extensible: Plug in CoinGecko or DeFi Llama for live data

Quick Start


from src.engine import PortfolioConfig, PortfolioEngine

config = PortfolioConfig(
    name="DeFi Blue Chip",
    components={
        "WETH": 0.30,
        "WBTC": 0.20,
        "LINK": 0.15,
        "AAVE": 0.15,
        "UNI": 0.10,
        "MKR": 0.10,
    },
    start_date="2025-01-01",
    end_date="2026-01-01",
    initial_investment=10_000.0,
)

engine = PortfolioEngine(config)
result = engine.run()

# Print key metrics
print(f"Total Return: {result.metrics['total_return']:.2%}")
print(f"Sharpe Ratio: {result.metrics['sharpe_ratio']:.4f}")
print(f"Max Drawdown: {result.metrics['max_drawdown']:.2%}")

# Export reports
engine.export_report(result, "report.html", fmt="html")
engine.export_report(result, "report.json", fmt="json")

Metrics

MetricDescription
Total ReturnCumulative compounded return
Annualized ReturnGeometric annualized return
Annualized VolatilityStandard deviation * sqrt(365)
Sharpe RatioRisk-adjusted return vs risk-free rate
Sortino RatioDownside-risk-adjusted return
Max DrawdownLargest peak-to-trough decline
Calmar RatioAnnualized return / max drawdown
Information RatioExcess return / tracking error vs benchmark
Value at Risk (95%)Historical VaR at 95% confidence

... continues with setup instructions, usage examples, and more.

📄 Code Sample .py preview

src/attribution.py """ Performance attribution analysis for tokenized index portfolios. Decomposes portfolio returns into component contributions, sector allocations, and selection effects. """ from __future__ import annotations from dataclasses import dataclass from typing import Dict, List from .data_fetcher import PriceData @dataclass class ComponentContribution: """Contribution of a single component to portfolio performance.""" symbol: str weight: float component_return: float contribution: float # weight * return allocation_effect: float selection_effect: float class PerformanceAttribution: """ Brinson-Fachler style performance attribution. Decomposes total portfolio return into: - Asset allocation effect - Security selection effect - Interaction effect """ def analyze( self, price_data: Dict[str, List[PriceData]], weights: Dict[str, float], daily_returns: List[float], ) -> Dict[str, Dict[str, float]]: """ Run attribution analysis. Returns: Dict mapping symbol to attribution breakdown: { "WETH": { # ... 64 more lines ...
Buy Now — $10 Back to Products