budget-variance-analyzer
Analyze budget vs actual cost variances. Identify overruns, forecast final costs, and generate variance reports.
git clone --depth 1 https://github.com/datadrivenconstruction/DDC_Skills_for_AI_Agents_in_Construction /tmp/budget-variance-analyzer && cp -r /tmp/budget-variance-analyzer/1_DDC_Toolkit/Cost-Management/budget-variance-analyzer ~/.claude/skills/budget-variance-analyzerSKILL.md
# Budget Variance Analyzer
## Business Case
### Problem Statement
Cost overruns surprise project teams:
- Late detection of budget issues
- No systematic variance analysis
- Difficult to forecast final costs
- Unclear root causes
### Solution
Systematic budget variance analysis that tracks costs against budget, identifies trends, and forecasts final project costs.
### Business Value
- **Early warning** - Detect overruns early
- **Forecasting** - Predict final costs
- **Accountability** - Track variance causes
- **Decision support** - Informed cost decisions
## Technical Implementation
```python
import pandas as pd
from datetime import datetime, date
from typing import Dict, Any, List, Optional, Tuple
from dataclasses import dataclass, field
from enum import Enum
class VarianceStatus(Enum):
"""Variance status."""
UNDER_BUDGET = "under_budget"
ON_BUDGET = "on_budget"
OVER_BUDGET = "over_budget"
CRITICAL = "critical"
class CostCategory(Enum):
"""Cost categories."""
LABOR = "labor"
MATERIAL = "material"
EQUIPMENT = "equipment"
SUBCONTRACTOR = "subcontractor"
OVERHEAD = "overhead"
CONTINGENCY = "contingency"
OTHER = "other"
class VarianceCause(Enum):
"""Common variance causes."""
SCOPE_CHANGE = "scope_change"
QUANTITY_CHANGE = "quantity_change"
PRICE_ESCALATION = "price_escalation"
PRODUCTIVITY = "productivity"
REWORK = "rework"
DELAY = "delay"
UNFORESEEN = "unforeseen"
ESTIMATE_ERROR = "estimate_error"
OTHER = "other"
@dataclass
class BudgetItem:
"""Single budget line item."""
item_code: str
description: str
category: CostCategory
original_budget: float
current_budget: float # After approved changes
committed_cost: float # Contracts, POs
actual_cost: float # Paid/invoiced
forecast_cost: float # Estimate at completion
percent_complete: float
notes: str = ""
@property
def variance_amount(self) -> float:
"""Budget variance (negative = over budget)."""
return self.current_budget - self.forecast_cost
@property
def variance_percent(self) -> float:
"""Variance as percentage."""
if self.current_budget == 0:
return 0
return (self.variance_amount / self.current_budget) * 100
@property
def status(self) -> VarianceStatus:
"""Determine variance status."""
pct = self.variance_percent
if pct > 5:
return VarianceStatus.UNDER_BUDGET
elif pct >= -5:
return VarianceStatus.ON_BUDGET
elif pct >= -15:
return VarianceStatus.OVER_BUDGET
else:
return VarianceStatus.CRITICAL
@dataclass
class VarianceRecord:
"""Record of budget variance."""
record_id: str
item_code: str
variance_amount: float
cause: VarianceCause
explanation: str
recorded_date: date
recorded_by: str
approved: bool = False
approval_date: Optional[date] = None
@dataclass
class ForecastScenario:
"""Cost forecast scenario."""
name: str
description: str
adjustments: Dict[str, float] # item_code: adjustment amount
total_forecast: float
variance_from_budget: float
class BudgetVarianceAnalyzer:
"""Analyze budget vs actual cost variances."""
VARIANCE_THRESHOLD_WARNING = -0.05 # -5%
VARIANCE_THRESHOLD_CRITICAL = -0.15 # -15%
def __init__(self, project_name: str, original_budget: float, currency: str = "USD"):
self.project_name = project_name
self.original_budget = original_budget
self.currency = currency
self.items: Dict[str, BudgetItem] = {}
self.variance_records: List[VarianceRecord] = []
self.history: List[Dict[str, Any]] = []
def add_budget_item(self,
item_code: str,
description: str,
category: CostCategory,
budget: float,
committed: float = 0,
actual: float = 0,
percent_complete: float = 0) -> BudgetItem:
"""Add budget line item."""
forecast = max(committed, actual / percent_complete * 100) if percent_complete > 0 else budget
item = BudgetItem(
item_code=item_code,
description=description,
category=category,
original_budget=budget,
current_budget=budget,
committed_cost=committed,
actual_cost=actual,
forecast_cost=forecast,
percent_complete=percent_complete
)
self.items[item_code] = item
return item
def update_costs(self, item_code: str,
committed: float = None,
actual: float = None,
percent_complete: float = None,
forecast: float = None):
"""Update item costs."""
if item_code not in self.items:
raise ValueError(f"Item {item_code} not found")
item = self.items[item_code]
if committed is not None:
item.committed_cost = committed
if actual is not None:
item.actual_cost = actual
if percent_complete is not None:
item.percent_complete = percent_complete
if forecast is not None:
item.forecast_cost = forecast
else:
# Auto-calculate forecast
if item.percent_complete > 0:
item.forecast_cost = item.actual_cost / item.percent_complete * 100
else:
item.forecast_cost = max(item.committed_cost, item.current_budget)
self._record_history()
def adjust_budget(self, item_code: str, amount: float, reason: str):
"""Adjust current budget (approved change)."""
if item_code not in self.items:
raise ValueError(f"Item {item_code} not found")
self.items[item_code].current_budgetGenerate automated daily progress reports from site data. Track work completed, labor hours, equipment usage, and weather conditions.
Analyze labor productivity from site data. Compare planned vs actual, identify trends, benchmark against industry standards.
Create interactive KPI dashboards for construction projects. Track schedule, cost, quality, and safety metrics in real-time.
Detect and analyze geometric clashes in BIM models. Identify MEP, structural, and architectural conflicts before construction.
Classify BIM elements using AI and standard classification systems. Map elements to UniFormat, MasterFormat, OmniClass, and CWICR codes.
Generate comprehensive BIM model validation reports. Check data quality, completeness, and compliance with standards.
Calculate CO2 emissions and carbon footprint from BIM model data. Analyze embodied carbon by material, element, and building system.
Extract quantities from IFC/Revit models for quantity takeoff. Uses DDC converters to get element counts, areas, volumes, lengths with grouping and reporting.