Visual Guide to Risk Calculation

This guide provides a visual and conceptual overview of how risk is calculated, adjusted, and monitored within the Riskify platform. It is designed to help users, developers, and risk managers understand the flow of risk data, the structure of risk scoring, and the integration of machine learning in risk management.

Risk Flow Diagram

The following diagram illustrates the end-to-end flow of risk calculation in Riskify, from pool events to risk monitoring and alerting. Different risk types (structured, cross, passive) are processed and adjusted before producing a final risk score.

graph TD
    A[Pool Event] --> B[Base Risk Calculation]
    B --> C{Risk Type}
    C -->|Structured| D[Tranche Risk]
    C -->|Cross| E[Network Risk]
    C -->|Passive| F[Stability Risk]
    D --> G[Risk Adjustments]
    E --> G
    F --> G
    G --> H[Final Risk Score]
    H --> I[Risk Monitoring]
    I -->|Breach| J[Risk Alerts]
    I -->|Normal| K[Regular Updates]

Diagram: The risk calculation flow, showing how different risk types are processed, adjusted, and monitored for alerts or regular updates.

Example Risk Calculations

This section provides concrete examples of how risk is calculated for different pool types and at the network level, including numerical and code-based illustrations.

1. Structured Pool Example

A structured pool is divided into tranches, each with its own risk profile. The diagram below shows how a risk event propagates through the tranches.

graph TD
    subgraph Structured Pool
        A[Senior Tranche]
        B[Mezzanine Tranche]
        C[Junior Tranche]
    end
    D[Risk Event] --> C
    C --> B
    B --> A

Diagram: Risk event flows from junior to senior tranches, with each tranche absorbing risk according to its attachment point.

Numerical Example:
This code demonstrates how risk scores are assigned to each tranche based on pool parameters and attachment points.

// Initial parameters
const poolParams = {
    baseRiskScore: 2000,  // 20%
    leverageFactor: 1500, // 15%
    correlationFactor: 500 // 5%
};

// Tranche-specific calculations
const tranches = [
    {
        name: "Senior",
        attachmentPoint: 7000,  // 70%
        riskScore: baseRiskScore * 0.5
    },
    {
        name: "Mezzanine",
        attachmentPoint: 3000,  // 30%
        riskScore: baseRiskScore * 1.2
    },
    {
        name: "Junior",
        attachmentPoint: 0,     // 0%
        riskScore: baseRiskScore * 2.5
    }
];

Example: Assigning risk scores to tranches in a structured pool based on their position and leverage.

2. Network Risk Visualization

Network risk considers the interconnections and correlations between pools. The diagram below shows a network of pools and their relationships.

graph LR
    subgraph Pool Network
        A((Pool A))
        B((Pool B))
        C((Pool C))
        D((Pool D))
        A --- B
        B --- C
        C --- D
        A --- D
        B --- D
    end
    style A fill:#f9f,stroke:#333,stroke-width:4px
    style B fill:#bbf,stroke:#333,stroke-width:2px
    style C fill:#bbf,stroke:#333,stroke-width:2px
    style D fill:#bbf,stroke:#333,stroke-width:2px

Diagram: Pools are connected in a network, with each edge representing a risk or correlation relationship.

Network Risk Calculation Example:
This code shows how to calculate network risk scores using connection weights, correlations, and individual pool risk scores.

const networkRisk = {
    // Connection weights (basis points)
    weights: {
        "A-B": 2000, // 20% connection weight
        "B-C": 1500, // 15% connection weight
        "C-D": 1000, // 10% connection weight
        "A-D": 500,  // 5% connection weight
        "B-D": 1200  // 12% connection weight
    },
    
    // Pool correlations (basis points)
    correlations: {
        "A-B": 3000, // 30% correlation
        "B-C": 2500, // 25% correlation
        "C-D": 1500, // 15% correlation
        "A-D": 1000, // 10% correlation
        "B-D": 2000  // 20% correlation
    },
    
    // Individual pool risk scores (basis points)
    riskScores: {
        "A": 2500, // 25% risk
        "B": 2000, // 20% risk
        "C": 1500, // 15% risk
        "D": 1800  // 18% risk
    }
};

// Calculate network risk score for Pool A
const poolARisk = calculateNetworkRisk("A", networkRisk);

Example: Calculating network risk by combining connection weights, correlations, and individual pool risk scores.

3. Risk Adjustment Process

Risk scores are adjusted based on time, collateral, and volume factors. The diagram and code below show how these adjustments are applied sequentially.

graph LR
    A[Base Risk] --> B[Time Adjustment]
    B --> C[Collateral Adjustment]
    C --> D[Volume Adjustment]
    D --> E[Final Risk Score]
    
    subgraph Adjustments
        B
        C
        D
    end

Diagram: Risk adjustment process, where base risk is modified by time, collateral, and volume factors to produce a final score.

Risk Adjustment Example:
This code demonstrates how to apply time, collateral, and volume adjustments to a base risk score.

// Initial risk score: 2000 (20%)
const baseRisk = 2000;

// Time adjustment
const timelock = 180 days;
const maxLock = 365 days;
const timeFactor = 500; // 5%
const timeAdjustedRisk = baseRisk * (1 - (min(timelock, maxLock) / maxLock) * timeFactor);
// Result: 1900 (19%)

// Collateral adjustment
const collateralRatio = 12000; // 120%
const targetRatio = 10000;     // 100%
const collateralFactor = 500;  // 5%
const collateralAdjustedRisk = timeAdjustedRisk * 
    (1 - (collateralRatio / targetRatio) * collateralFactor);
// Result: 1805 (18.05%)

// Volume adjustment
const volume = 500000;        // $500,000
const targetVolume = 1000000; // $1,000,000
const volumeFactor = 300;     // 3%
const finalRisk = collateralAdjustedRisk * 
    (1 + (volume / targetVolume) * volumeFactor);
// Result: 1850 (18.5%)

Example: Adjusting risk scores for time, collateral, and volume to reflect real-world risk dynamics.

Risk Monitoring Dashboard

Riskify provides a monitoring system to track risk metrics and generate alerts. The diagram below shows how risk data is collected, processed, and used to trigger warnings or emergency responses.

graph TD
    subgraph Risk Monitoring System
        A[Risk Data Collection]
        B[Risk Processing]
        C[Alert Generation]
        
        subgraph Metrics
            D[Base Risk]
            E[Network Risk]
            F[Systemic Risk]
        end
        
        subgraph Thresholds
            G[Warning Level]
            H[Critical Level]
            I[Emergency Level]
        end
        
        A --> B
        B --> D
        B --> E
        B --> F
        D --> G
        E --> H
        F --> I
        G --> C
        H --> C
        I --> C
    end

Diagram: Risk monitoring dashboard, showing how risk metrics are processed and alerts are generated at different threshold levels.

Machine Learning Integration

Machine learning models are used to enhance risk prediction and scoring. The following diagram shows the ML pipeline and how different data sources feed into feature engineering and model inference.

graph TD
    subgraph ML Pipeline
        A[Data Collection] --> B[Feature Engineering]
        B --> C[Model Training]
        C --> D[Validation]
        D --> E[Deployment]
        E --> F[Inference]
        F --> G[Risk Score]
    end
    
    subgraph Features
        H[Historical Data]
        I[Market Data]
        J[Network Data]
        K[Protocol Metrics]
    end
    
    H --> B
    I --> B
    J --> B
    K --> B

Diagram: ML pipeline for risk scoring, showing how data is processed and used for model inference.

ML Model Integration Example:
This code shows how a risk model processes pool data, generates a risk score, and outputs component scores and confidence.

class RiskModel:
    def __init__(self):
        self.feature_processor = FeatureProcessor()
        self.model = GNNRiskModel()
        
    def predict_risk(self, pool_data: PoolData) -> RiskPrediction:
        # Process features
        features = self.feature_processor.process(pool_data)
        
        # Generate prediction
        prediction = self.model.predict(features)
        
        # Calculate confidence
        confidence = self.calculate_confidence(prediction)
        
        return RiskPrediction(
            risk_score=prediction.risk_score,
            confidence=confidence,
            components=prediction.component_scores
        )

# Example usage
risk_model = RiskModel()
pool_data = collect_pool_data(pool_id)
risk_prediction = risk_model.predict_risk(pool_data)

print(f"Risk Score: {risk_prediction.risk_score}")
print(f"Confidence: {risk_prediction.confidence}")
for component, score in risk_prediction.components.items():
    print(f"{component}: {score}")

Example: Using a machine learning model to predict risk scores and component breakdowns for a pool.

Emergency Response Flow

Riskify includes emergency response mechanisms for risk events. The diagram below shows how alerts trigger different levels of response, from increased monitoring to crisis management and recovery.

graph TD
    A[Risk Alert] -->|Threshold Breach| B{Risk Level}
    B -->|Warning| C[Increase Monitoring]
    B -->|Critical| D[Risk Mitigation]
    B -->|Emergency| E[Emergency Shutdown]
    
    C --> F[Normal Operations]
    D --> G[Review & Adjust]
    E --> H[Crisis Management]
    
    G --> F
    H --> I[Recovery Plan]
    I --> F

Diagram: Emergency response flow, showing how different risk levels trigger monitoring, mitigation, or crisis management actions.


Navigation

← Back to Risk Management Back to Risk Risk Scoring Methodology →