🛠️ToolsShed

Cost-Benefit Analysis

Calculate NPV, ROI, and benefit-cost ratio for project evaluation.

Costs

Benefits

$127,006
Net Present Value
1.88
Benefit-Cost Ratio
87.50%
ROI
1.82 years
Payback Period
YearCostsBenefitsNet Cash Flow
1$120,000$75,000$-45,000
2$20,000$75,000$55,000
3$20,000$75,000$55,000
4$20,000$75,000$55,000
5$20,000$75,000$55,000

Questions Fréquentes

Implémentation du Code

def cost_benefit_analysis(costs, benefits, years: int, discount_rate: float):
    """
    costs/benefits: list of {'name': str, 'amount': float, 'type': 'one-time'|'annual'}
    discount_rate: as decimal (0.08 for 8%)
    """
    cash_flows = []
    cumulative_pv = 0.0
    cumulative_net = 0.0
    payback_year = None

    for year in range(1, years + 1):
        year_costs = sum(
            c['amount'] for c in costs
            if c['type'] == 'annual' or (c['type'] == 'one-time' and year == 1)
        )
        year_benefits = sum(
            b['amount'] for b in benefits
            if b['type'] == 'annual' or (b['type'] == 'one-time' and year == 1)
        )
        net = year_benefits - year_costs
        df = 1 / (1 + discount_rate) ** year if discount_rate > 0 else 1
        pv = net * df
        cumulative_pv += pv
        cumulative_net += net
        if payback_year is None and cumulative_net >= 0:
            payback_year = year
        cash_flows.append({'year': year, 'costs': year_costs, 'benefits': year_benefits, 'net': net, 'pv': pv, 'cumulative_pv': cumulative_pv})

    total_costs = sum(cf['costs'] for cf in cash_flows)
    total_benefits = sum(cf['benefits'] for cf in cash_flows)
    npv = cumulative_pv
    bcr = total_benefits / total_costs if total_costs > 0 else 0
    roi = (total_benefits - total_costs) / total_costs * 100 if total_costs > 0 else 0

    return {'npv': npv, 'bcr': bcr, 'roi': roi, 'payback_year': payback_year, 'cash_flows': cash_flows}

# Example
costs = [
    {'name': 'Initial Investment', 'amount': 100000, 'type': 'one-time'},
    {'name': 'Annual Operating',   'amount': 20000,  'type': 'annual'},
]
benefits = [
    {'name': 'Revenue',      'amount': 60000, 'type': 'annual'},
    {'name': 'Cost Savings', 'amount': 15000, 'type': 'annual'},
]
result = cost_benefit_analysis(costs, benefits, years=5, discount_rate=0.08)
print(f"NPV: ${result['npv']:,.0f}")
print(f"BCR: {result['bcr']:.2f}")
print(f"ROI: {result['roi']:.1f}%")
print(f"Payback: Year {result['payback_year']}")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.