One comment on “Medical Windfall Prizes

  1. import pandas as pd
    import numpy as np
    from typing import Optional
    
    class WindfallCalculator:
        def __init__(self, 
                     historical_data: pd.DataFrame,
                     threshold_percentage: float = 0.20,
                     sigma_multiplier: float = 2.0):
            """
            Initialize the windfall calculator with historical data.
            
            Args:
                historical_data: DataFrame with columns ['year', 'revenue']
                threshold_percentage: Additional threshold above expected revenue (default 20%)
                sigma_multiplier: Number of standard deviations to add to baseline (default 2)
            """
            self.data = historical_data
            self.threshold_percentage = threshold_percentage
            self.sigma_multiplier = sigma_multiplier
            
            # Calculate historical growth rates
            self.data['growth_rate'] = self.data['revenue'].pct_change()
            
            # Calculate baseline parameters
            self.baseline_growth = self.data['growth_rate'].mean()
            self.growth_std = self.data['growth_rate'].std()
            self.baseline_revenue = self.data['revenue'].iloc[-1]
            self.baseline_year = int(self.data['year'].iloc[-1][:4])
            
        def expected_revenue(self, year: int) -> float:
            """Calculate expected revenue for a given year based on baseline growth."""
            years_from_baseline = year - self.baseline_year
            simple = self.baseline_revenue * (1 + self.baseline_growth) ** years_from_baseline
            buffered = simple * (1 + self.growth_std * self.sigma_multiplier)
            return (simple, buffered)
        
        def calculate_windfall(self, year: int, actual_revenue: float) -> dict:
            """
            Calculate windfall and reward payment for a given year's actual revenue.
            
            Args:
                year: The year to calculate for
                actual_revenue: The actual tax revenue for that year
                
            Returns:
                Dictionary containing calculations and intermediate values
            """
            (simple_expected, expected) = self.expected_revenue(year)
            raw_windfall = max(0, actual_revenue - expected)
            threshold = self.threshold_percentage * expected
            rewardable_windfall = max(0, raw_windfall - threshold)
            reward_payment = 0.01 * rewardable_windfall
            
            return {
                'year': year,
                'actual_revenue': actual_revenue,
                'expected_revenue': expected,
                'raw_windfall': raw_windfall,
                'threshold': threshold,
                'rewardable_windfall': rewardable_windfall,
                'reward_payment': reward_payment
            }
        
        def print_parameters(self):
            """Print the calculated baseline parameters."""
            print(f"Historical baseline growth rate: {self.baseline_growth:.1%}")
            print(f"Growth standard deviation: {self.growth_std:.1%}")
            print(f"Growth buffer (baseline + {self.sigma_multiplier}?): {(self.baseline_growth + self.sigma_multiplier * self.growth_std):.1%}")
            print(f"Threshold percentage above expected: {self.threshold_percentage:.1%}")
            print(f"Baseline revenue (from {self.baseline_year}): ${self.baseline_revenue:.1f}B")
    
    # Example usage with the FRED data:
    def load_fred_data(csv_path: str) -> pd.DataFrame:
        """Load and preprocess the FRED tax revenue data."""
        df = pd.read_csv(csv_path)
        df.columns = ['year', 'revenue']
        return df
    
    # Example scenarios
    def run_scenarios(calculator: WindfallCalculator):
        """Run some example scenarios to demonstrate the calculator."""
        scenarios = [
            (2026, 2025, 1.12),
            (2026, 2025, 1.25),
            (2032, 2028, 1.15),
            (2032, 2028, 1.30),
        ]
        
        print(f"\nScenario Analysis")
        print("-" * 64)
        for target_year, inflection_year, growth_rate in scenarios:
            multiplier = (1 + calculator.baseline_growth) ** (inflection_year - calculator.baseline_year)
            multiplier *= growth_rate ** (target_year - inflection_year)
            (simple_expected, expected) = calculator.expected_revenue(target_year)
            actual = simple_expected * multiplier
            result = calculator.calculate_windfall(target_year, actual)
            
            print(f"\nScenario: {target_year} with growth rate {(growth_rate-1):.0%} starting in {inflection_year}; multiplier {multiplier:.1f}")
            print(f"Actual Revenue: ${result['actual_revenue']:.1f}B")
            print(f"Expected Revenue: ${simple_expected:.1f}B")
            print(f"Two Sigma Revenue: ${result['expected_revenue']:.1f}B")
            print(f"Raw Windfall: ${result['raw_windfall']:.1f}B")
            print(f"Rewardable Windfall: ${result['rewardable_windfall']:.1f}B")
            print(f"Reward Payment: ${result['reward_payment']:.1f}B")
    
    if __name__ == "__main__":
        # Load historical data, from https://fred.stlouisfed.org/series/W006RC1A027NBEA
        data = load_fred_data('/home/pcm/invest/data/econ/stls/w/W006RC1A027NBEA.csv')
        
        # Create calculator
        calculator = WindfallCalculator(data)
        
        # Print baseline parameters
        calculator.print_parameters()
        
        # Run example scenarios
        run_scenarios(calculator)
    

Leave a Reply

Your email address will not be published. Required fields are marked *