39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
"""Salvage value (scrap value) calculation helpers.
|
|
|
|
Most clients use straight % of cost; some use fixed dollar amounts.
|
|
"""
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Literal
|
|
|
|
|
|
SalvageMethod = Literal['percentage', 'fixed', 'zero']
|
|
|
|
|
|
@dataclass
|
|
class SalvageConfig:
|
|
method: SalvageMethod
|
|
value: float = 0.0
|
|
|
|
|
|
def compute_salvage_value(*, cost: float, config: SalvageConfig) -> float:
|
|
"""Compute end-of-life salvage value."""
|
|
if config.method == 'zero':
|
|
return 0.0
|
|
if config.method == 'percentage':
|
|
return round(cost * config.value / 100, 2)
|
|
if config.method == 'fixed':
|
|
return round(config.value, 2)
|
|
raise ValueError(f"Unknown salvage method: {config.method}")
|
|
|
|
|
|
def remaining_useful_life_value(*, current_book: float, salvage: float,
|
|
periods_used: int, total_periods: int) -> float:
|
|
"""Estimate remaining value if asset is sold/scrapped now."""
|
|
if total_periods <= 0:
|
|
return current_book
|
|
if periods_used >= total_periods:
|
|
return salvage
|
|
remaining_pct = (total_periods - periods_used) / total_periods
|
|
return round(salvage + (current_book - salvage) * remaining_pct, 2)
|